2006-10-06 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
[hildon] / hildon-widgets / hildon-program.c
index 5f6aed4..0aae6fc 100644 (file)
@@ -1,14 +1,14 @@
 /*
  * This file is part of hildon-libs
  *
- * Copyright (C) 2006 Nokia Corporation.
+ * Copyright (C) 2006 Nokia Corporation, all rights reserved.
  *
- * Contact: Luc Pionchon <luc.pionchon@nokia.com>
+ * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@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
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License.
  *
  * This library is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -114,6 +114,7 @@ hildon_program_init (HildonProgram *self)
     priv->is_topmost = FALSE;
     priv->window_group = GDK_WINDOW_XID (gdk_display_get_default_group
                                   (gdk_display_get_default()));
+    priv->common_toolbar = NULL;
     priv->name = NULL;
 }
 
@@ -249,26 +250,28 @@ hildon_program_update_top_most (HildonProgram *program)
     
     active_window = hildon_window_get_active_window();
 
-    wm_hints = XGetWMHints (GDK_DISPLAY (), active_window);
-
-    if (wm_hints)
+    if (active_window)
     {
-
-        if (wm_hints->window_group == priv->window_group)
-        {
-            if (!priv->is_topmost)
-            {
-                priv->is_topmost = TRUE;
-                g_object_notify (G_OBJECT (program), "is-topmost");
-            }
-        }
-        else if (priv->is_topmost)
-        {
+      wm_hints = XGetWMHints (GDK_DISPLAY (), active_window);
+
+      if (wm_hints)
+      {
+
+          if (wm_hints->window_group == priv->window_group)
+          {
+              if (!priv->is_topmost)
+              {
+                  priv->is_topmost = TRUE;
+                  g_object_notify (G_OBJECT (program), "is-topmost");
+              }
+          }
+          else if (priv->is_topmost)
+          {
             priv->is_topmost = FALSE;
             g_object_notify (G_OBJECT (program), "is-topmost");
-        }
-
-        XFree (wm_hints);
+          }
+      }
+      XFree (wm_hints);
     }
 
     /* Check each window if it was is_topmost */
@@ -308,6 +311,24 @@ hildon_program_root_window_event_filter (GdkXEvent *xevent,
 }
     
 
+/**
+ * hildon_program_common_toolbar_topmost_window:
+ * @window: A @HildonWindow to be informed about its new common toolbar
+ * @data: Not used, it is here just to respect the API
+ *
+ * Checks if the window is the topmost window of the program and in
+ * that case forces the window to take the common toolbar.
+ **/
+static void
+hildon_program_common_toolbar_topmost_window (gpointer window, gpointer data)
+{
+    if (HILDON_IS_WINDOW (window) && 
+            hildon_window_get_is_topmost (HILDON_WINDOW (window)))
+    {
+        hildon_window_take_common_toolbar (HILDON_WINDOW (window));
+    }
+}
+
 /* Public methods */
 
 /**
@@ -544,7 +565,8 @@ hildon_program_set_common_toolbar (HildonProgram *self, GtkToolbar *toolbar)
     {
         if (priv->common_toolbar->parent)
         {
-            gtk_widget_unparent(priv->common_toolbar->parent);
+            gtk_container_remove (GTK_CONTAINER (priv->common_toolbar->parent), 
+                                  priv->common_toolbar);
         }
         
         g_object_unref (priv->common_toolbar);
@@ -557,6 +579,14 @@ hildon_program_set_common_toolbar (HildonProgram *self, GtkToolbar *toolbar)
         g_object_ref (priv->common_toolbar);
         gtk_object_sink (GTK_OBJECT (priv->common_toolbar) );
     }
+
+    /* if the program is the topmost we have to update the common
+       toolbar right now for the topmost window */
+    if (priv->is_topmost)
+      {
+        g_slist_foreach (priv->windows, 
+                         (GFunc) hildon_program_common_toolbar_topmost_window, NULL);
+      }
 }
 
 /**