2009-04-01 Alberto Garcia <agarcia@igalia.com>
[hildon] / src / hildon-window.c
index 43d68c5..73ef13f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2006 Nokia Corporation, all rights reserved.
  *
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+ * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
 /**
  * SECTION:hildon-window
  * @short_description: Widget representing a top-level window in the Hildon framework.
+ * @see_also: #HildonProgram, #HildonStackableWindow
  *
- * The HildonWindow is a GTK widget which represents a top-level
- * window in the Hildon framework. It is derived from the GtkWindow
+ * #HildonWindow is a GTK widget which represents a top-level
+ * window in the Hildon framework. It is derived from #GtkWindow
  * and provides additional commodities specific to the Hildon
  * framework.
-
- * Among these windows in the Hildon framework can have a single menu
- * attached, which is toggled with a hardware key or by tapping
- * a custom button in the window frame. This menu can be set
- * by providing a GtkMenu to the hildon_window_set_menu() method.
-
- * Similarly a window in the Hildon framework can have several toolbars
- * attached. These can be added to the HildonWindow with
- * hildon_window_add_toolbar()..
- * 
+ *
+ * #HildonWindow<!-- -->s can have a menu attached, which is toggled
+ * with a hardware key or by tapping on the window frame. This menu
+ * can be either a #GtkMenu or a #HildonAppMenu (set with
+ * hildon_window_set_main_menu() and hildon_window_set_app_menu()
+ * respectively). Only one type of menu can be used at the same time.
+ * In Hildon 2.2, #HildonAppMenu is the recommended menu to use.
+ *
+ * Similarly, a #HildonWindow can have several toolbars
+ * attached. These can be added with hildon_window_add_toolbar(). In
+ * addition to those, a #HildonWindow can also have a
+ * #HildonEditToolbar. To add it to the window use
+ * hildon_window_set_edit_toolbar().
+ *
  * <example>
  * <title>Creating a HildonWindow</title>
  * <programlisting>
  * HildonWindow *window;
  * GtkToolbar *toolbar;
- * GtkMenu *menu;
+ * HildonAppMenu *menu;
  * GdkPixbuf *icon_pixbuf;
  * <!-- -->
  * window = HILDON_WINDOW (hildon_window_new());
@@ -56,7 +61,7 @@
  * <!-- -->
  * icon_pixbuf = create_icon();
  * <!-- -->
- * hildon_window_set_menu (window, menu);
+ * hildon_window_set_app_menu (window, menu);
  * <!-- -->
  * hildon_window_add_toolbar (window, toolbar);
  * <!-- -->
  * gtk_window_set_icon (GTK_WINDOW (window), icon_pixbuf);
  * </programlisting>
  * </example>
- *
  */
 
-#include                                        "hildon-window.h"
+#undef                                          HILDON_DISABLE_DEPRECATED
+
 #include                                        <memory.h>
 #include                                        <string.h>
 #include                                        <strings.h>
 #include                                        <stdio.h>
-#include                                        "hildon-program.h"
-#include                                        "hildon-window-private.h"
-#include                                        "hildon-find-toolbar.h"
-
-#include                                        <gtk/gtkmenu.h>
-#include                                        <gtk/gtkimcontext.h>
-#include                                        <gtk/gtkmenuitem.h>
-#include                                        <gtk/gtkcheckmenuitem.h>
-#include                                        <gtk/gtkmenushell.h>
-#include                                        <gtk/gtkwindow.h>
-#include                                        <gtk/gtkwidget.h>
-#include                                        <gtk/gtkvbox.h>
-#include                                        <gtk/gtklabel.h>
-#include                                        <gtk/gtkentry.h>
-#include                                        <gtk/gtktextview.h>
-#include                                        <gtk/gtkscrolledwindow.h>
-#include                                        <gtk/gtkmain.h>
-#include                                        <gdk/gdkkeysyms.h>
-#include                                        <gdk/gdk.h>
-#include                                        <gtk/gtkprivate.h>
+#include                                        <libintl.h>
 #include                                        <X11/X.h>
-#include                                        <X11/Xlib.h>
 #include                                        <X11/Xatom.h>
-#include                                        <libintl.h>
+#include                                        <gdk/gdkkeysyms.h>
+#include                                        <gdk/gdkx.h>
+#include                                        <gtk/gtkprivate.h>
+
+#include                                        "hildon-window.h"
+#include                                        "hildon-window-private.h"
+#include                                        "hildon-app-menu-private.h"
+#include                                        "hildon-find-toolbar.h"
+#include                                        "hildon-defines.h"
 
 #define                                         _(String) gettext(String)
 
-#define                                         TOOLBAR_HEIGHT 40
+#define                                         TOOLBAR_HEIGHT 70
 
-#define                                         TOOLBAR_MIDDLE 10
+#define                                         TOOLBAR_MIDDLE 0
 
 /*FIXME*/
 #define                                         CAN_HIBERNATE "CANKILL"
@@ -236,6 +229,12 @@ paint_toolbar                                   (GtkWidget *widget,
                                                  GdkEventExpose * event, 
                                                  gboolean fullscreen);
 
+static void
+paint_edit_toolbar                              (GtkWidget *widget,
+                                                 GtkWidget *toolbar,
+                                                 GdkEventExpose *event,
+                                                 gboolean fullscreen);
+
 enum
 {
     PROP_0,
@@ -290,12 +289,7 @@ hildon_window_class_init                        (HildonWindowClass * window_clas
             sizeof (struct _HildonWindowPrivate));
 
     /* Install properties */
-    
-    /**
-     * HildonWindow:is-topmost:
-     *
-     * Whether the window is currently activated by the window manager.
-     */
+
     g_object_class_install_property (object_class, PROP_IS_TOPMOST,
             g_param_spec_boolean ("is-topmost",
                 "Is top-most",
@@ -337,6 +331,8 @@ hildon_window_init                              (HildonWindow *self)
     priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
     gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
     priv->menu = NULL;
+    priv->app_menu = NULL;
+    priv->edit_toolbar = NULL;
     priv->visible_toolbars = 0;
     priv->is_topmost = FALSE;
     priv->borders = NULL;
@@ -358,7 +354,6 @@ hildon_window_init                              (HildonWindow *self)
 static void
 hildon_window_finalize                          (GObject * obj_self)
 {
-    HildonWindow *self;
     HildonWindowPrivate *priv; 
       
     g_return_if_fail (HILDON_WINDOW (obj_self));
@@ -366,8 +361,6 @@ hildon_window_finalize                          (GObject * obj_self)
     priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
     g_assert (priv != NULL);
     
-    self = HILDON_WINDOW (obj_self);
-
     if (priv->escape_timeout) {
       g_source_remove (priv->escape_timeout);
       priv->escape_timeout = 0;
@@ -401,6 +394,9 @@ hildon_window_realize                           (GtkWidget *widget)
 
     gtk_widget_realize (GTK_WIDGET (priv->vbox));
 
+    if (priv->edit_toolbar != NULL)
+        gtk_widget_realize (priv->edit_toolbar);
+
     /* catch the custom button signal from mb to display the menu */
     gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
 
@@ -434,9 +430,6 @@ hildon_window_realize                           (GtkWidget *widget)
     /* Update the topmost status */
     active_window = hildon_window_get_active_window();
     hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
-
-    /* Update the window title */
-    hildon_window_update_title(HILDON_WINDOW (widget));
 }
 
 static void
@@ -449,6 +442,10 @@ hildon_window_unrealize                         (GtkWidget *widget)
             widget);
 
     gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
+
+    if (priv->edit_toolbar != NULL)
+        gtk_widget_unrealize (priv->edit_toolbar);
+
     GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
 }
 
@@ -463,6 +460,9 @@ hildon_window_map                             (GtkWidget *widget)
 
   if (GTK_WIDGET_VISIBLE (priv->vbox))
     gtk_widget_map (priv->vbox);
+
+  if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
+    gtk_widget_map (priv->edit_toolbar);
 }
 
 static void
@@ -473,6 +473,9 @@ hildon_window_unmap                             (GtkWidget *widget)
 
   gtk_widget_unmap (priv->vbox);
 
+  if (priv->edit_toolbar != NULL)
+    gtk_widget_unmap (priv->edit_toolbar);
+
   if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
     GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
 }
@@ -565,6 +568,12 @@ hildon_window_expose                            (GtkWidget *widget,
     paint_toolbar (widget, box,
             event, priv->fullscreen);
 
+    if (priv->edit_toolbar != NULL)
+    {
+        paint_edit_toolbar (widget, priv->edit_toolbar,
+                            event, priv->fullscreen);
+    }
+
     if (! priv->fullscreen) {
 
         /* Draw the left and right window border */
@@ -638,7 +647,7 @@ hildon_window_size_request                      (GtkWidget *widget,
     g_assert (priv);
 
     GtkWidget *child = GTK_BIN (widget)->child;
-    GtkRequisition req2;
+    GtkRequisition req2 = { 0 };
     gint border_width = GTK_CONTAINER(widget)->border_width;
 
     if (! priv->borders)
@@ -653,8 +662,15 @@ hildon_window_size_request                      (GtkWidget *widget,
         gtk_widget_size_request (priv->vbox, &req2);
 
     requisition->height += req2.height;
-    requisition->width = (requisition->width < req2.width) ? 
-        req2.width : requisition->width;
+    requisition->width = MAX (requisition->width, req2.width);
+
+    if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
+    {
+        GtkRequisition req;
+        gtk_widget_size_request (priv->edit_toolbar, &req);
+        requisition->height += req.height;
+        requisition->width = MAX (requisition->width, req.width);
+    }
 
     requisition->width  += 2 * border_width;
     requisition->height += 2 * border_width;
@@ -675,72 +691,90 @@ hildon_window_size_allocate                     (GtkWidget *widget,
     HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
     g_assert (priv);
 
-    GtkAllocation box_alloc;
+    GtkAllocation box_alloc = { 0 };
+    GtkAllocation edittb_alloc = { 0 };
     GtkAllocation alloc = *allocation;
-    GtkRequisition req;
-    gint border_width = GTK_CONTAINER(widget)->border_width;
 
-    GtkWidget *box = priv->vbox;
-    GtkBin *bin = GTK_BIN(widget);
-    GtkBorder *b = priv->borders;
-    GtkBorder *tb = priv->toolbar_borders;
+    GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
+    GtkBorder *tb;
 
     if (!priv->borders)
-    {
         hildon_window_get_borders (HILDON_WINDOW (widget));
-        b = priv->borders;
-        tb = priv->toolbar_borders;
-    }
+
+    tb = priv->toolbar_borders;
 
     widget->allocation = *allocation;
 
-    gtk_widget_get_child_requisition (box, &req);
+    /* Calculate allocation of edit toolbar */
+    if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
+    {
+        GtkRequisition req;
+        gtk_widget_get_child_requisition (priv->edit_toolbar, &req);
+        edittb_alloc.width = alloc.width - tb->left - tb->right;
+        edittb_alloc.height = MIN (req.height, alloc.height);
+        edittb_alloc.x = alloc.x + tb->left;
+        edittb_alloc.y = alloc.y + tb->top;
+
+        if (edittb_alloc.height > 0)
+        {
+            alloc.y += tb->top + tb->bottom + edittb_alloc.height;
+            alloc.height -= tb->top + tb->bottom + edittb_alloc.height;
+            gtk_widget_size_allocate (priv->edit_toolbar, &edittb_alloc);
+        }
+    }
 
-    box_alloc.width = allocation->width - tb->left - tb->right;
-    box_alloc.height = ( (req.height < allocation->height) ?
-            req.height : allocation->height );
-    box_alloc.x = allocation->x + tb->left;
-    box_alloc.y = allocation->y + allocation->height - box_alloc.height - tb->bottom;
+    /* Calculate allocation of normal toolbars */
+    if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
+    {
+        GtkRequisition req;
+        gtk_widget_get_child_requisition (priv->vbox, &req);
+        box_alloc.width = alloc.width - tb->left - tb->right;
+        box_alloc.height = MIN (req.height, alloc.height);
+        box_alloc.x = alloc.x + tb->left;
+        box_alloc.y = alloc.y + alloc.height - box_alloc.height - tb->bottom;
+
+        if (box_alloc.height > 0)
+        {
+            alloc.height -= tb->top + tb->bottom + box_alloc.height;
+            gtk_widget_size_allocate (priv->vbox, &box_alloc);
+        }
+    }
 
-    if (bin->child != NULL && GTK_IS_WIDGET (bin->child)
-            && GTK_WIDGET_VISIBLE (bin->child))
+    /* Calculate allocation of the child widget */
+    if (child != NULL && GTK_WIDGET_VISIBLE (child))
     {
+        guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
         alloc.x += border_width;
         alloc.y += border_width;
         alloc.width -= (border_width * 2);
-        alloc.height -= (border_width * 2) + box_alloc.height;
+        alloc.height -= (border_width * 2);
 
         if (! priv->fullscreen)
         {
+            GtkBorder *b = priv->borders;
             alloc.x += b->left;
             alloc.width -= (b->left + b->right);
-            alloc.y += b->top;
 
-            alloc.height -= b->top;
+            /* Use the top border if there's no edit toolbar */
+            if (edittb_alloc.height <= 0)
+            {
+                alloc.y += b->top;
+                alloc.height -= b->top;
+            }
 
+            /* Use the top border if there are no standard toolbars */
             if (box_alloc.height <= 0)
                 alloc.height -= b->bottom;
-            else
-                alloc.height -= (tb->top + tb->bottom);            
-        }
-        else
-        {
-            if (!(box_alloc.height <= 0))
-                alloc.height -= (tb->top + tb->bottom);              
         }
 
-        gtk_widget_size_allocate (bin->child, &alloc);
+        gtk_widget_size_allocate (child, &alloc);
     }
 
-    gtk_widget_size_allocate (box, &box_alloc);
-
     if (priv->previous_vbox_y != box_alloc.y)
     {
         /* The size of the VBox has changed, we need to redraw part
          * of the window borders */
-        gint draw_from_y = priv->previous_vbox_y < box_alloc.y?
-            priv->previous_vbox_y - tb->top:
-            box_alloc.y - tb->top;
+        gint draw_from_y = MIN (priv->previous_vbox_y, box_alloc.y) - tb->top;
 
         gtk_widget_queue_draw_area (widget, 0, draw_from_y, 
                 widget->allocation.width,
@@ -765,8 +799,12 @@ hildon_window_forall                            (GtkContainer *container,
 
     GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
             callback, callback_data);
+
     if (include_internals && priv->vbox != NULL)
         (* callback)(GTK_WIDGET (priv->vbox), callback_data);
+
+    if (include_internals && priv->edit_toolbar != NULL)
+        (* callback)(GTK_WIDGET (priv->edit_toolbar), callback_data);
 }
 
 static void
@@ -778,7 +816,11 @@ hildon_window_show_all                          (GtkWidget *widget)
     g_assert (priv != NULL);
 
     GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
+
     gtk_widget_show_all (priv->vbox);
+
+    if (priv->edit_toolbar)
+        gtk_widget_show_all (priv->edit_toolbar);
 }
 
 static void
@@ -809,6 +851,19 @@ hildon_window_destroy                           (GtkObject *obj)
 
     }
 
+    if (priv->edit_toolbar != NULL)
+    {
+        gtk_widget_unparent (priv->edit_toolbar);
+        priv->edit_toolbar = NULL;
+    }
+
+    if (priv->app_menu)
+    {
+        hildon_app_menu_set_parent_window (priv->app_menu, NULL);
+        g_object_unref (priv->app_menu);
+        priv->app_menu = NULL;
+    }
+
     menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
     menu_node = menu_list;
 
@@ -856,12 +911,7 @@ hildon_window_notify                            (GObject *gobject,
 {
     HildonWindow *window = HILDON_WINDOW (gobject);
 
-    if (g_str_equal (param->name, "title"))
-    {
-
-        hildon_window_update_title (window);
-    }
-    else if (g_str_equal (param->name, "is-topmost"))
+    if (g_str_equal (param->name, "is-topmost"))
     {
         hildon_window_is_topmost_notify (window);
     }
@@ -879,26 +929,6 @@ visible_toolbar                                 (gpointer data,
         (*((gint *)user_data))++;
 }
 
-static void 
-find_findtoolbar_index                          (gpointer data, 
-                                                 gpointer user_data)
-{
-    gint *pass_bundle = (gint *)user_data;
-
-    if(((GtkBoxChild *)data)->widget->allocation.y < pass_bundle[0]
-            && GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
-        pass_bundle[1]++;
-}
-
-static void
-find_findtoolbar                                (gpointer data, 
-                                                 gpointer user_data)
-{
-    if(HILDON_IS_FIND_TOOLBAR (((GtkBoxChild *)data)->widget)
-            && GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
-        (*((GtkWidget **)user_data)) = ((GtkBoxChild *)data)->widget;
-}
-
 static void
 paint_toolbar                                   (GtkWidget *widget, 
                                                  GtkBox *box, 
@@ -906,14 +936,7 @@ paint_toolbar                                   (GtkWidget *widget,
                                                  gboolean fullscreen)
 {
     gint toolbar_num = 0; 
-    gint ftb_index = 0;
     gint count;
-    GtkWidget *findtoolbar = NULL;
-    HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
-    gchar toolbar_mode[40];
-    GtkBorder *tb = priv->toolbar_borders;
-
-    g_assert (priv != NULL);
 
     /* collect info to help on painting the boxes */
     g_list_foreach (box->children, visible_toolbar, 
@@ -922,115 +945,45 @@ paint_toolbar                                   (GtkWidget *widget,
     if(toolbar_num <= 0)
         return;
 
-    g_list_foreach (box->children, find_findtoolbar, (gpointer) &findtoolbar);
-
-    if (findtoolbar != NULL)
-    {
-        gint pass_bundle[2];/* an array for convient data passing
-                               the first member contains the y allocation
-                               of the find toolbar, and the second allocation
-                               contains the index(how many toolbars are above
-                               find toolbar) */
-        pass_bundle[0] = findtoolbar->allocation.y;
-        pass_bundle[1] = ftb_index;
-        g_list_foreach(box->children, find_findtoolbar_index,
-                (gpointer) pass_bundle);
-        ftb_index = pass_bundle[1];
-    }
-
-    /*upper border*/
-    sprintf (toolbar_mode, "toolbar%sframe-top", 
-            fullscreen ? "-fullscreen-" : "-");
+    /*top most toolbar painting*/
     gtk_paint_box (widget->style, widget->window,
-            GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
-            &event->area, widget, toolbar_mode,
+            GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
+            &event->area, widget, "toolbar-primary",
             widget->allocation.x,
-            GTK_WIDGET (box)->allocation.y - tb->top,
-            widget->allocation.width, tb->top);
+            GTK_WIDGET(box)->allocation.y,
+            widget->allocation.width,
+            TOOLBAR_HEIGHT);
 
-    /*top most toolbar painting*/
-    if (findtoolbar != NULL && ftb_index == 0 )
-    {
-        sprintf (toolbar_mode, "findtoolbar%s", 
-                fullscreen ? "-fullscreen" : "");
-
-        gtk_paint_box (widget->style, widget->window,
-                GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
-                &event->area, widget, toolbar_mode,
-                widget->allocation.x,
-                GTK_WIDGET(box)->allocation.y,
-                widget->allocation.width,
-                TOOLBAR_HEIGHT);
-    }
-    else
-    {
-        sprintf (toolbar_mode, "toolbar%s", 
-                fullscreen ? "-fullscreen" : "");
-
-        gtk_paint_box (widget->style, widget->window,
-                GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
-                &event->area, widget, toolbar_mode,
-                widget->allocation.x,
-                GTK_WIDGET(box)->allocation.y,
-                widget->allocation.width,
-                TOOLBAR_HEIGHT);
-    }
     /*multi toolbar painting*/
     for (count = 0; count < toolbar_num - 1; count++)
     {
-        sprintf (toolbar_mode, "toolbar%sframe-middle", 
-                fullscreen ? "-fullscreen-" : "-");
-
-        gtk_paint_box (widget->style, widget->window,
-                GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
-                &event->area, widget, toolbar_mode,
-                widget->allocation.x,
-                GTK_WIDGET(box)->allocation.y + 
-                (1 + count) * TOOLBAR_HEIGHT + 
-                count * TOOLBAR_MIDDLE,
-                widget->allocation.width,
-                TOOLBAR_MIDDLE);
-
-        if (findtoolbar != NULL && count + 1 == ftb_index)
-        {
-
-            sprintf (toolbar_mode, "findtoolbar%s", 
-                    fullscreen ? "-fullscreen" : "");
-
-            gtk_paint_box (widget->style, widget->window,
-                    GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
-                    &event->area, widget, toolbar_mode,
-                    widget->allocation.x,
-                    GTK_WIDGET(box)->allocation.y + 
-                    (1 + count) * (TOOLBAR_HEIGHT + TOOLBAR_MIDDLE),
-                    widget->allocation.width,
-                    TOOLBAR_HEIGHT);
-        }
-        else
-        {
-            sprintf (toolbar_mode, "toolbar%s", 
-                    fullscreen ? "-fullscreen" : "");
-
             gtk_paint_box (widget->style, widget->window,
-                    GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
-                    &event->area, widget, toolbar_mode,
-                    widget->allocation.x,
-                    GTK_WIDGET(box)->allocation.y + 
-                    (1 + count) * (TOOLBAR_HEIGHT + TOOLBAR_MIDDLE),
-                    widget->allocation.width,
-                    TOOLBAR_HEIGHT);
-        }
+                           GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
+                           &event->area, widget, "toolbar-secondary",
+                           widget->allocation.x,
+                           GTK_WIDGET(box)->allocation.y +
+                           (1 + count) * (TOOLBAR_HEIGHT),
+                           widget->allocation.width,
+                           TOOLBAR_HEIGHT);
     }
-    sprintf (toolbar_mode, "toolbar%sframe-bottom", 
-            fullscreen ? "-fullscreen-" : "-");
+}
+
+static void
+paint_edit_toolbar                              (GtkWidget *widget,
+                                                 GtkWidget *toolbar,
+                                                 GdkEventExpose *event,
+                                                 gboolean fullscreen)
+{
+    if (!GTK_WIDGET_VISIBLE (toolbar))
+        return;
 
     gtk_paint_box (widget->style, widget->window,
-            GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
-            &event->area, widget, toolbar_mode,
-            widget->allocation.x,
-            GTK_WIDGET(box)->allocation.y + 
-            GTK_WIDGET(box)->allocation.height,
-            widget->allocation.width, tb->bottom);
+                   GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
+                   &event->area, widget, "toolbar-edit-mode",
+                   toolbar->allocation.x,
+                   toolbar->allocation.y,
+                   toolbar->allocation.width,
+                   toolbar->allocation.height);
 }
 
 /*
@@ -1467,14 +1420,14 @@ hildon_window_update_topmost                    (HildonWindow *self,
 {
     HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
 
-    Window my_window;
+    GdkWindow *my_window;
 
     g_return_if_fail (HILDON_IS_WINDOW (self));
     g_assert (priv);
 
-    my_window = GDK_WINDOW_XID (GTK_WIDGET (self)->window);
+    my_window = GTK_WIDGET (self)->window;
 
-    if (window_id == my_window)
+    if (my_window && window_id == GDK_WINDOW_XID (my_window))
     {
         if (! priv->is_topmost)
         {
@@ -1499,72 +1452,117 @@ hildon_window_update_topmost                    (HildonWindow *self,
     }
 }
 
-/*
- * If the application
- * was given a name (with g_set_application_name(), set 
- * "ProgramName - WindowTitle" as the displayed
- * title
- */
-void G_GNUC_INTERNAL
-hildon_window_update_title                      (HildonWindow *window)
+static void
+detach_menu_func                                (GtkWidget *attach_widget, 
+                                                 GtkMenu *menu)
 {
-    const gchar * application_name;
+    /* FIXME Why is this even needed here? */
+}
 
-    g_return_if_fail (HILDON_IS_WINDOW (window));
+static gboolean
+hildon_window_toggle_menu                       (HildonWindow *self,
+                                                guint button,
+                                                guint32 time)
+{
+    g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
 
-    if (!GTK_WIDGET_REALIZED (window))
+    if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
     {
-        return;
+        return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
+    }
+    else
+    {
+        return FALSE;
     }
+}
+
+
+static gboolean
+hildon_window_toggle_gtk_menu                   (HildonWindow *self,
+                                                GtkMenu      *menu,
+                                                guint         button,
+                                                guint32       time)
+{
+    gboolean retvalue = FALSE;
 
-    application_name = g_get_application_name ();
+    g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
+    g_return_val_if_fail (GTK_IS_MENU (menu), FALSE);
 
-    if (application_name && application_name[0])
+    if (gtk_menu_get_attach_widget (menu) != GTK_WIDGET (self))
+    {
+        g_object_ref (menu);
+        if (gtk_menu_get_attach_widget (menu))
+        {
+            gtk_menu_detach (menu);
+        }
+        gtk_menu_attach_to_widget (menu, GTK_WIDGET (self), &detach_menu_func);
+        g_object_unref (menu);
+    }
+
+    if (GTK_WIDGET_MAPPED (menu))
+    {
+        gtk_menu_popdown (menu);
+        gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu));
+        retvalue = TRUE;
+    }
+    else
     {
-        const gchar *old_title = gtk_window_get_title (GTK_WINDOW (window));
+        /* Check if the menu has items */
+        GList *menu_children = gtk_container_get_children (GTK_CONTAINER (menu));
 
-        if (old_title)
+        if (menu_children)
         {
-            gchar *title = NULL;
-                
-            if (strlen (old_title) == 0) 
-                title = g_strdup (application_name);
-            else
-                title = g_strjoin (TITLE_SEPARATOR, application_name,
-                                   old_title, NULL);
+            HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
+            g_list_free (menu_children);
 
-            gdk_window_set_title (GTK_WIDGET (window)->window, title);
+            /* Apply right theming */
+            gtk_widget_set_name (GTK_WIDGET (menu), "menu_force_with_corners");
 
-            g_free (title);
+            if (priv->fullscreen)
+            {
+                gtk_menu_popup (menu, NULL, NULL,
+                                (GtkMenuPositionFunc)
+                                hildon_window_menu_popup_func_full,
+                                self, button, time);
+            }
+            else
+            {
+                gtk_menu_popup (menu, NULL, NULL,
+                                (GtkMenuPositionFunc)
+                                hildon_window_menu_popup_func,
+                                self, button, time);
+            }
+            gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE);
+            retvalue = TRUE;
         }
-
     }
-}
 
-static void
-detach_menu_func                                (GtkWidget *attach_widget, 
-                                                 GtkMenu *menu)
-{
-    /* FIXME Why is this even needed here? */
+    return retvalue;
 }
 
 static gboolean
-hildon_window_toggle_menu                       (HildonWindow *self,
-                                                guint button,
-                                                guint32 time)
+hildon_window_toggle_app_menu                   (HildonWindow  *self,
+                                                HildonAppMenu *menu)
 {
     g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
+    g_return_val_if_fail (HILDON_IS_APP_MENU (menu), FALSE);
 
-    if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
+    if (self != hildon_app_menu_get_parent_window (menu))
     {
-        return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
+        gtk_widget_hide (GTK_WIDGET (menu));
+    }
+
+    if (GTK_WIDGET_MAPPED (menu))
+    {
+        gtk_widget_hide (GTK_WIDGET (menu));
     }
     else
     {
-        return FALSE;
+        hildon_app_menu_popup (menu, GTK_WINDOW (self));
     }
-}
 
+    return TRUE;
+}
 
 /*
  * Toggles the display of the HildonWindow menu.
@@ -1576,80 +1574,37 @@ hildon_window_toggle_menu_real                  (HildonWindow * self,
                                                 guint button,
                                                 guint32 time)
 {
-    GtkMenu *menu_to_use = NULL;
-    GList *menu_children = NULL;
+    gboolean retvalue = FALSE;
     HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
 
     g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
-    g_assert (priv != NULL);
 
     /* Select which menu to use, Window specific has highest priority,
      * then program specific */
     if (priv->menu)
     {
-        menu_to_use = GTK_MENU (priv->menu);
-    }
-    else if (priv->program)
-    {
-        menu_to_use = hildon_program_get_common_menu (priv->program);
-        if (menu_to_use && gtk_menu_get_attach_widget (menu_to_use) != 
-                GTK_WIDGET (self))
-        {
-            g_object_ref (menu_to_use);
-            if (gtk_menu_get_attach_widget (menu_to_use))
-            {
-                gtk_menu_detach (menu_to_use);
-            }
-
-            gtk_menu_attach_to_widget (menu_to_use, GTK_WIDGET (self), 
-                    &detach_menu_func);
-            g_object_unref (menu_to_use);
-        }
-    }
-
-    if (! menu_to_use)
-    {
-        return FALSE;
+        retvalue = hildon_window_toggle_gtk_menu (self, priv->menu, button, time);
     }
-
-
-    if (GTK_WIDGET_MAPPED (GTK_WIDGET (menu_to_use)))
+    else if (priv->app_menu)
     {
-        gtk_menu_popdown (menu_to_use);
-        gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_to_use));
-        return TRUE;
+        retvalue = hildon_window_toggle_app_menu (self, priv->app_menu);
     }
-
-    /* Check if the menu has items */
-    menu_children = gtk_container_get_children (GTK_CONTAINER (menu_to_use));
-
-    if (menu_children)
+    else if (priv->program)
     {
-        g_list_free (menu_children);
+        GtkMenu *gtkmenu = hildon_program_get_common_menu (priv->program);
+        HildonAppMenu *appmenu = hildon_program_get_common_app_menu (priv->program);
 
-        /* Apply right theming */
-        gtk_widget_set_name (GTK_WIDGET (menu_to_use),
-                "menu_force_with_corners");
-
-        if (priv->fullscreen) 
+        if (gtkmenu)
         {
-            gtk_menu_popup (menu_to_use, NULL, NULL,
-                    (GtkMenuPositionFunc)
-                    hildon_window_menu_popup_func_full,
-                    self, button, time);
+            retvalue = hildon_window_toggle_gtk_menu (self, gtkmenu, button, time);
         }
-        else
+        else if (appmenu)
         {
-            gtk_menu_popup (menu_to_use, NULL, NULL,
-                    (GtkMenuPositionFunc)
-                    hildon_window_menu_popup_func,
-                    self, button, time);
+            retvalue = hildon_window_toggle_app_menu (self, appmenu);
         }
-        gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_to_use), TRUE);
-        return TRUE;
     }
 
-    return FALSE;
+    return retvalue;
 }
 
 /*
@@ -1685,9 +1640,9 @@ hildon_window_escape_timeout                    (gpointer data)
 /**
  * hildon_window_new: 
  * 
- * Creates a new HildonWindow.
+ * Creates a new #HildonWindow.
  * 
- * Return value: A @HildonWindow.
+ * Return value: A #HildonWindow.
  **/
 GtkWidget*
 hildon_window_new                               (void)
@@ -1698,13 +1653,13 @@ hildon_window_new                               (void)
 }
 
 /**
- * hildon_window_add_with_scrollbar
- * @self : A @HildonWindow
- * @child : A @GtkWidget
+ * hildon_window_add_with_scrollbar:
+ * @self: A #HildonWindow
+ * @child: A #GtkWidget
  *
- * Adds the @child to the HildonWindow and creates a scrollbar
- * for it. Similar as adding first a @GtkScrolledWindow and then the
- * @child to it.
+ * Adds @child to the #HildonWindow and creates a scrollbar for
+ * it. Similar to adding first a #GtkScrolledWindow and then @child to
+ * it.
  */
 void
 hildon_window_add_with_scrollbar                (HildonWindow *self,
@@ -1764,13 +1719,13 @@ toolbar_visible_notify                          (GtkWidget *toolbar, GParamSpec
 
 /**
  * hildon_window_add_toolbar:
- * @self: A @HildonWindow
- * @toolbar: A #GtkToolbar to add to the HildonWindow
+ * @self: A #HildonWindow
+ * @toolbar: A #GtkToolbar to add to the #HildonWindow
  *
  * Adds a toolbar to the window. Note that the toolbar is not automatically
- * shown. You need to call #gtk_widget_show_all on it to make it visible. 
+ * shown. You need to call gtk_widget_show_all() on it to make it visible.
  * It's also possible to hide the toolbar (without removing it) by calling
- * #gtk_widget_hide.
+ * gtk_widget_hide()
  **/
 void 
 hildon_window_add_toolbar                       (HildonWindow *self, 
@@ -1804,11 +1759,11 @@ hildon_window_add_toolbar                       (HildonWindow *self,
 
 /**
  * hildon_window_remove_toolbar:
- * @self: A @HildonWindow
- * @toolbar: A #GtkToolbar to remove from the HildonWindow
+ * @self: A #HildonWindow
+ * @toolbar: A #GtkToolbar to remove from the #HildonWindow
  *
  * Removes a toolbar from the window. Note that this decreases the refference
- * count on the widget. If you want to keep the toolbar alive call #g_object_ref 
+ * count on the widget. If you want to keep the toolbar alive call g_object_ref()
  * before calling this function.
  **/
 void
@@ -1833,16 +1788,56 @@ hildon_window_remove_toolbar                    (HildonWindow *self,
 }
 
 /**
- * hildon_window_get_menu:
- * @self : #HildonWindow
- * 
- * Gets the #GtMenu assigned to the #HildonAppview. Note that the 
+ * hildon_window_set_edit_toolbar:
+ * @self: A #HildonWindow
+ * @toolbar: A #HildonEditToolbar, or %NULL to remove the current one.
+ *
+ * Adds a #HildonEditToolbar to the window. Note that the toolbar is
+ * not automatically shown. You need to call gtk_widget_show() on it
+ * to make it visible. It's also possible to hide the toolbar (without
+ * removing it) by calling gtk_widget_hide().
+ *
+ * A window can only have at most one edit toolbar at a time, so the
+ * previous toolbar (if any) is replaced after calling this function.
+ **/
+void
+hildon_window_set_edit_toolbar                  (HildonWindow      *self,
+                                                 HildonEditToolbar *toolbar)
+{
+    HildonWindowPrivate *priv;
+
+    g_return_if_fail (HILDON_IS_WINDOW (self));
+    g_return_if_fail (toolbar == NULL || HILDON_IS_EDIT_TOOLBAR (toolbar));
+
+    priv = HILDON_WINDOW_GET_PRIVATE (self);
+
+    if (priv->edit_toolbar != GTK_WIDGET (toolbar))
+    {
+        GtkWidget *old_toolbar = priv->edit_toolbar;
+        priv->edit_toolbar = GTK_WIDGET (toolbar);
+
+        if (priv->edit_toolbar)
+            gtk_widget_set_parent (priv->edit_toolbar, GTK_WIDGET (self));
+
+        if (old_toolbar)
+            gtk_widget_unparent (old_toolbar);
+    }
+}
+
+/**
+ * hildon_window_get_main_menu:
+ * @self: a #HildonWindow
+ *
+ * Gets the #GtkMenu assigned to the #HildonAppview. Note that the
  * window is still the owner of the menu.
- * 
+ *
+ * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
+ * you should use hildon_window_get_app_menu() instead.
+ *
  * Return value: The #GtkMenu assigned to this application view. 
  **/
 GtkMenu*
-hildon_window_get_menu                          (HildonWindow * self)
+hildon_window_get_main_menu                     (HildonWindow * self)
 {
     HildonWindowPrivate *priv;
 
@@ -1850,7 +1845,22 @@ hildon_window_get_menu                          (HildonWindow * self)
 
     priv = HILDON_WINDOW_GET_PRIVATE (self);
 
-    return GTK_MENU (priv->menu);
+    return priv->menu;
+}
+
+/**
+ * hildon_window_get_menu:
+ * @self: a #HildonWindow
+ *
+ * Return value: a #GtkMenu
+ *
+ * Deprecated: In Hildon 2.2 this function has been renamed to
+ * hildon_window_get_main_menu() for consistency
+ **/
+GtkMenu*
+hildon_window_get_menu                          (HildonWindow * self)
+{
+    return hildon_window_get_main_menu (self);
 }
 
 /* Since we've been asking developers to call gtk_window_add_accel_group()
@@ -1875,15 +1885,16 @@ hildon_window_add_accel_group (HildonWindow *self,
  * hildon_window_set_main_menu:
  * @self: A #HildonWindow
  * @menu: The #GtkMenu to be used for this #HildonWindow
- * 
+ *
  * Sets the menu to be used for this window. This menu overrides
  * a program-wide menu that may have been set with
  * hildon_program_set_common_menu(). Pass %NULL to remove the current
  * menu. #HildonWindow takes ownership of the passed menu and you're
  * not supposed to free it yourself anymore.
  *
- * Since: Hildon 2.2
- **/ 
+ * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
+ * you should use hildon_window_set_app_menu() instead.
+ **/
 void
 hildon_window_set_main_menu (HildonWindow* self,
                             GtkMenu     * menu)
@@ -1897,22 +1908,22 @@ hildon_window_set_main_menu (HildonWindow* self,
 
     if (priv->menu != NULL)
     {
-       accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
+       accel_group = gtk_menu_get_accel_group (priv->menu);
        if (accel_group != NULL)
            gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
 
-        gtk_menu_detach (GTK_MENU (priv->menu));
+        gtk_menu_detach (priv->menu);
         g_object_unref (priv->menu);
     }
 
-    priv->menu = (menu != NULL) ? GTK_WIDGET (menu) : NULL;
+    priv->menu = menu;
     if (priv->menu != NULL)
     {
-        gtk_widget_set_name (priv->menu, "menu_force_with_corners");
-        gtk_menu_attach_to_widget (GTK_MENU (priv->menu), GTK_WIDGET (self), &detach_menu_func);
-        g_object_ref (GTK_MENU (priv->menu));
+        gtk_widget_set_name (GTK_WIDGET (priv->menu), "menu_force_with_corners");
+        gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (self), &detach_menu_func);
+        g_object_ref (priv->menu);
 
-       accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
+       accel_group = gtk_menu_get_accel_group (priv->menu);
        if (accel_group != NULL)
            hildon_window_add_accel_group (self, accel_group);
     }
@@ -1922,10 +1933,10 @@ hildon_window_set_main_menu (HildonWindow* self,
  * hildon_window_set_menu:
  * @self: A #HildonWindow
  * @menu: The #GtkMenu to be used for this #HildonWindow
- * 
+ *
  * Sets the menu to be used for this window. This menu overrides
  * a program-wide menu that may have been set with
- * hildon_program_set_common_menu. Pass NULL to remove the current
+ * hildon_program_set_common_menu(). Pass %NULL to remove the current
  * menu. HildonWindow takes ownership of the passed menu and you're
  * not supposed to free it yourself anymore.
  *
@@ -1935,7 +1946,7 @@ hildon_window_set_main_menu (HildonWindow* self,
  * doesn't do this.
  *
  * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
- **/ 
+ **/
 void
 hildon_window_set_menu                          (HildonWindow *self, 
                                                  GtkMenu *menu)
@@ -1955,9 +1966,11 @@ hildon_window_set_menu                          (HildonWindow *self,
 /**
  * hildon_window_get_is_topmost:
  * @self: A #HildonWindow
- * 
- * Return value: Whether or not the #HildonWindow is currenltly activated
- * by the window manager.
+ *
+ * Returns whether the #HildonWindow is currenty activated by the
+ * window manager.
+ *
+ * Return value: %TRUE if @self is currently activated, %FALSE otherwise.
  **/
 gboolean
 hildon_window_get_is_topmost                    (HildonWindow *self)
@@ -1970,3 +1983,66 @@ hildon_window_get_is_topmost                    (HildonWindow *self)
     return priv->is_topmost;
 }
 
+/**
+ * hildon_window_set_app_menu:
+ * @self: a #HildonWindow
+ * @menu: a #HildonAppMenu to be used for this window
+ *
+ * Sets the menu to be used for this window. Pass %NULL to remove the
+ * current menu. Any reference to a previous menu will be dropped.
+ * #HildonWindow takes ownership of the passed menu and
+ * you're not supposed to free it yourself anymore.
+ *
+ * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
+ * you should use hildon_window_set_main_menu() instead.
+ *
+ * Since: 2.2
+ **/
+void
+hildon_window_set_app_menu                      (HildonWindow  *self,
+                                                 HildonAppMenu *menu)
+{
+    HildonWindowPrivate *priv;
+    HildonAppMenu *old_menu;
+
+    g_return_if_fail (HILDON_IS_WINDOW (self));
+    g_return_if_fail (!menu || HILDON_IS_APP_MENU (menu));
+    priv = HILDON_WINDOW_GET_PRIVATE (self);
+
+    old_menu = priv->app_menu;
+
+    /* Add new menu */
+    priv->app_menu = menu;
+    if (menu)
+        g_object_ref_sink (menu);
+
+    /* Unref old menu */
+    if (old_menu)
+        g_object_unref (old_menu);
+}
+
+/**
+ * hildon_window_get_app_menu:
+ * @self: a #HildonWindow
+ *
+ * Returns the #HildonAppMenu assigned to @self, or %NULL if it's
+ * unset. Note that the window is still the owner of the menu.
+ *
+ * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
+ * you should use hildon_window_get_main_menu() instead.
+ *
+ * Returns: a #HildonAppMenu
+ *
+ * Since: 2.2
+ **/
+HildonAppMenu *
+hildon_window_get_app_menu                      (HildonWindow *self)
+{
+    HildonWindowPrivate *priv;
+
+    g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
+
+    priv = HILDON_WINDOW_GET_PRIVATE (self);
+
+    return priv->app_menu;
+}