Set the window menu flag for application-common menus
authorClaudio Saavedra <csaavedra@igalia.com>
Wed, 9 Sep 2009 08:22:53 +0000 (11:22 +0300)
committerClaudio Saavedra <csaavedra@igalia.com>
Thu, 10 Sep 2009 09:07:33 +0000 (12:07 +0300)
* hildon/hildon-program.c:
(+hildon_program_window_set_common_menu_flag): Set or remove the
menu flag from a window only this doesn't have its own menu.
(+hildon_program_set_common_menu_flag): adjust menu flag for
all windows in the program.
(hildon_program_add_window),
(hildon_program_remove_window): add/remove the menu flag when
a window is added to the program.

Fixes: NB#137814 (Indicator for view menu in app title area)

ChangeLog
hildon/hildon-program.c

index 4c5879f..642248f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2009-09-09  Claudio Saavedra  <csaavedra@igalia.com>
+
+       Set the window menu flag for application-common menus
+
+       * hildon/hildon-program.c:
+       (+hildon_program_window_set_common_menu_flag): Set or remove the
+       menu flag from a window only this doesn't have its own menu.
+       (+hildon_program_set_common_menu_flag): adjust menu flag for
+       all windows in the program.
+       (hildon_program_add_window),
+       (hildon_program_remove_window): add/remove the menu flag when
+       a window is added to the program.
+
+       Fixes: NB#137814 (Indicator for view menu in app title area)
+
 2009-09-08  Claudio Saavedra  <csaavedra@igalia.com>
 
        Set a special window property for windows with menus
index 86e866c..0174e16 100644 (file)
@@ -411,6 +411,32 @@ hildon_program_root_window_event_filter         (GdkXEvent *xevent,
     return GDK_FILTER_CONTINUE;
 }
 
+static void
+hildon_program_window_set_common_menu_flag (HildonWindow *window,
+                                            gboolean common_menu)
+{
+    if (HILDON_IS_WINDOW (window))
+    {
+        gboolean has_menu = hildon_window_get_app_menu (window) ||
+            hildon_window_get_main_menu (window);
+
+        if (!has_menu) {
+            hildon_window_set_menu_flag (window, common_menu);
+        }
+    }
+}
+
+static void
+hildon_program_set_common_menu_flag (HildonProgram *self,
+                                     gboolean common_menu)
+{
+    HildonProgramPrivate *priv = HILDON_PROGRAM_GET_PRIVATE (self);
+
+    g_slist_foreach (priv->windows,
+                     (GFunc) hildon_program_window_set_common_menu_flag,
+                     GINT_TO_POINTER (common_menu));
+}
+
 /* 
  * Checks if the window is the topmost window of the program and in
  * that case forces the window to take the common toolbar.
@@ -491,6 +517,9 @@ hildon_program_add_window                       (HildonProgram *self,
 
     hildon_window_set_program (window, G_OBJECT (self));
 
+    if (priv->common_menu || priv->common_app_menu)
+        hildon_program_window_set_common_menu_flag (window, TRUE);
+
     priv->windows = g_slist_append (priv->windows, window);
     priv->window_count ++;
 }
@@ -528,6 +557,9 @@ hildon_program_remove_window                    (HildonProgram *self,
         gdk_window_remove_filter (gdk_get_default_root_window(),
                 hildon_program_root_window_event_filter,
                 self);
+
+    if (priv->common_menu || priv->common_app_menu)
+        hildon_program_window_set_common_menu_flag (window, FALSE);
 }
 
 /**
@@ -623,6 +655,15 @@ hildon_program_set_common_menu                  (HildonProgram *self,
         }
     }
 
+    /* Only set the menu flag if there was no common menu and
+       we are setting one. If we are unsetting the current common menu,
+       remove the commmon menu flag. Otherwise, nothing to do. */
+    if (!priv->common_menu && menu) {
+        hildon_program_set_common_menu_flag (self, TRUE);
+    } else if (priv->common_menu && !menu) {
+        hildon_program_set_common_menu_flag (self, FALSE);
+    }
+
     priv->common_menu = menu;
 
     if (priv->common_menu)
@@ -686,6 +727,15 @@ hildon_program_set_common_app_menu              (HildonProgram *self,
 
     old_menu = priv->common_app_menu;
 
+    /* Only set the menu flag if there was no common menu and
+       we are setting one. If we are unsetting the current common menu,
+       remove the commmon menu flag. Otherwise, nothing to do. */
+    if (!priv->common_app_menu && menu) {
+        hildon_program_set_common_menu_flag (self, TRUE);
+    } else if (priv->common_app_menu && !menu) {
+        hildon_program_set_common_menu_flag (self, FALSE);
+    }
+
     /* Set new menu */
     priv->common_app_menu = menu;
     if (menu)