2009-04-01 Alberto Garcia <agarcia@igalia.com>
[hildon] / src / hildon-program.c
index d5230f0..79639a3 100644 (file)
  * @short_description: An object that represents an application running in the Hildon framework.
  * @see_also: #HildonWindow, #HildonStackableWindow
  *
- * The #HildonProgram is an object used to represent an application running
+ * #HildonProgram is an object used to represent an application running
  * in the Hildon framework.
  *
- * Such an application is thought to have one or more #HildonWindow. These
- * shall be registered to the #HildonProgram with hildon_program_add_window(),
+ * Applications can have one or more #HildonWindow<!-- -->s. These
+ * can be registered in the #HildonProgram with hildon_program_add_window(),
  * and can be unregistered similarly with hildon_program_remove_window().
  *
- * The #HildonProgram provides the programmer with commodities such
- * as applying a common toolbar and menu to all the #HildonWindow
- * registered to it. This is done with hildon_program_set_common_menu()
- * and hildon_program_set_common_toolbar().
+ * #HildonProgram provides the programmer with commodities such
+ * as applying a common toolbar and menu to all registered
+ * #HildonWindow<!-- -->s. This is done with hildon_program_set_common_menu(),
+ * hildon_program_set_common_app_menu() and hildon_program_set_common_toolbar().
  *
- * The #HildonProgram is also used to apply program-wide properties that
+ * #HildonProgram is also used to apply program-wide properties that
  * are specific to the Hildon framework. For instance
  * hildon_program_set_can_hibernate() sets whether or not an application
  * can be set to hibernate by the Hildon task navigator, in situations of
@@ -51,7 +51,7 @@
  * HildonWindow *window1;
  * HildonWindow *window2;
  * GtkToolbar *common_toolbar, *window_specific_toolbar;
- * GtkMenu *menu;
+ * HildonAppMenu *menu;
  * <!-- -->
  * program = HILDON_PROGRAM (hildon_program_get_instance ());
  * <!-- -->
@@ -66,7 +66,7 @@
  * hildon_program_add_window (program, window1);
  * hildon_program_add_window (program, window2);
  * <!-- -->
- * hildon_program_set_common_menu (program, menu);
+ * hildon_program_set_common_app_menu (program, menu);
  * <!-- -->
  * hildon_program_set_common_toolbar (program, common_toolbar);
  * hildon_window_add_toolbar (window1, window_specific_toolbar);
@@ -335,7 +335,7 @@ hildon_program_window_list_is_is_topmost        (gpointer data,
 static void
 hildon_program_update_top_most                  (HildonProgram *program)
 {
-    XWMHints *wm_hints;
+    gboolean is_topmost;
     Window active_window;
     HildonProgramPrivate *priv;
 
@@ -343,30 +343,35 @@ hildon_program_update_top_most                  (HildonProgram *program)
     g_assert (priv);
     
     active_window = hildon_window_get_active_window();
+    is_topmost = FALSE;
 
     if (active_window)
     {
       gint xerror;
-      gboolean is_topmost = FALSE;
+      XWMHints *wm_hints;
       
       gdk_error_trap_push ();
       wm_hints = XGetWMHints (GDK_DISPLAY (), active_window);
       xerror = gdk_error_trap_pop ();
       if (xerror)
+      {
+        if (wm_hints)
+          XFree (wm_hints);
         return;
+      }
 
       if (wm_hints)
       {
         is_topmost = (wm_hints->window_group == priv->window_group);
         XFree (wm_hints);
       }
+    }
 
-      /* Send notification if is_topmost has changed */
-      if (!priv->is_topmost != !is_topmost)
-      {
-        priv->is_topmost = is_topmost;
-        g_object_notify (G_OBJECT (program), "is-topmost");
-      }
+    /* Send notification if is_topmost has changed */
+    if (!priv->is_topmost != !is_topmost)
+    {
+      priv->is_topmost = is_topmost;
+      g_object_notify (G_OBJECT (program), "is-topmost");
     }
 
     /* Check each window if it was is_topmost */
@@ -443,8 +448,8 @@ hildon_program_get_instance                     (void)
  *
  * Registers a #HildonWindow as belonging to a given #HildonProgram. This
  * allows to apply program-wide settings as all the registered windows,
- * such as hildon_program_set_common_menu() and
- * hildon_pogram_set_common_toolbar()
+ * such as hildon_program_set_common_menu(), hildon_program_set_common_app_menu()
+ * and hildon_program_set_common_toolbar().
  **/
 void
 hildon_program_add_window                       (HildonProgram *self, 
@@ -453,6 +458,7 @@ hildon_program_add_window                       (HildonProgram *self,
     HildonProgramPrivate *priv;
     
     g_return_if_fail (HILDON_IS_PROGRAM (self));
+    g_return_if_fail (HILDON_IS_WINDOW (window));
     
     priv = HILDON_PROGRAM_GET_PRIVATE (self);
     g_assert (priv);
@@ -488,11 +494,11 @@ hildon_program_add_window                       (HildonProgram *self,
 /**
  * hildon_program_remove_window:
  * @self: The #HildonProgram to which the window should be unregistered
- * @window: The @HildonWindow to unregister
+ * @window: The #HildonWindow to unregister
  *
  * Used to unregister a window from the program. Subsequent calls to
- * hildon_program_set_common_menu() and hildon_pogram_set_common_toolbar()
- * will not affect the window
+ * hildon_program_set_common_menu(), hildon_program_set_common_app_menu()
+ * and hildon_program_set_common_toolbar() will not affect the window.
  **/
 void
 hildon_program_remove_window                    (HildonProgram *self, 
@@ -501,10 +507,13 @@ hildon_program_remove_window                    (HildonProgram *self,
     HildonProgramPrivate *priv;
     
     g_return_if_fail (HILDON_IS_PROGRAM (self));
+    g_return_if_fail (HILDON_IS_WINDOW (window));
     
     priv = HILDON_PROGRAM_GET_PRIVATE (self);
     g_assert (priv);
     
+    g_return_if_fail (g_slist_find (priv->windows, window));
+
     hildon_window_unset_program (window);
 
     priv->windows = g_slist_remove (priv->windows, window);
@@ -570,15 +579,15 @@ hildon_program_get_can_hibernate                (HildonProgram *self)
 /**
  * hildon_program_set_common_menu:
  * @self: The #HildonProgram in which the common menu should be used
- * @menu: A GtkMenu to use as common menu for the program
+ * @menu: A #GtkMenu to use as common menu for the program
  *
- * Sets a GtkMenu that will appear in all the #HildonWindow registered
- * with the #HildonProgram. Only one common GtkMenu can be set, further
- * calls will detach the previous common GtkMenu. A #HildonWindow
- * can use its own GtkMenu with hildon_window_set_menu()
+ * Sets a #GtkMenu that will appear in all #HildonWindow<!-- -->s
+ * registered with the #HildonProgram. Only one common #GtkMenu can be
+ * set, further calls will detach the previous common #GtkMenu. A
+ * #HildonWindow can use its own #GtkMenu with
+ * hildon_window_set_menu()
  *
- * This method is not intented for #HildonStackableWindow<!-- -->s and
- * does not support #HildonAppMenu objects. See
+ * This method does not support #HildonAppMenu<!-- -->s. See
  * hildon_program_set_common_app_menu() for that.
  *
  * Since: 2.2
@@ -598,13 +607,13 @@ hildon_program_set_common_menu                  (HildonProgram *self,
     {
         if (GTK_WIDGET_VISIBLE (priv->common_menu))
         {
-            gtk_menu_popdown (GTK_MENU (priv->common_menu));
+            gtk_menu_popdown (priv->common_menu);
             gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->common_menu));
         }
 
-        if (gtk_menu_get_attach_widget (GTK_MENU (priv->common_menu)))
+        if (gtk_menu_get_attach_widget (priv->common_menu))
         {
-            gtk_menu_detach (GTK_MENU (priv->common_menu));
+            gtk_menu_detach (priv->common_menu);
         }
         else
         {
@@ -612,7 +621,7 @@ hildon_program_set_common_menu                  (HildonProgram *self,
         }
     }
 
-    priv->common_menu = GTK_WIDGET (menu);
+    priv->common_menu = menu;
 
     if (priv->common_menu)
     {
@@ -641,7 +650,7 @@ hildon_program_get_common_menu                  (HildonProgram *self)
     priv = HILDON_PROGRAM_GET_PRIVATE (self);
     g_assert (priv);
 
-    return GTK_MENU (priv->common_menu);
+    return priv->common_menu;
 }
 
 /**
@@ -649,15 +658,13 @@ hildon_program_get_common_menu                  (HildonProgram *self)
  * @self: The #HildonProgram in which the common menu should be used
  * @menu: A #HildonAppMenu to use as common menu for the program
  *
- * Sets a #HildonAppMenu that will appear in all the
- * #HildonStackableWindow<!-- -->s registered with the
- * #HildonProgram. Only one common #HildonAppMenu can be set, further
- * calls will detach the previous common #HildonAppMenu. A
- * #HildonStackableWindow can use its own #HildonAppMenu with
- * hildon_stackable_window_set_app_menu()
+ * Sets a #HildonAppMenu that will appear in all
+ * #HildonWindow<!-- -->s registered with the #HildonProgram. Only
+ * one common #HildonAppMenu can be set, further calls will detach the
+ * previous common #HildonAppMenu. A #HildonWindow can use its own
+ * #HildonAppMenu with hildon_window_set_app_menu()
  *
- * This method is not intented for standard #HildonWindow<!-- -->s and
- * does not support #GtkMenu objects. See
+ * This method does not support #GtkMenu<!-- -->s. See
  * hildon_program_set_common_menu() for that.
  *
  * Since: 2.2
@@ -667,7 +674,7 @@ hildon_program_set_common_app_menu              (HildonProgram *self,
                                                  HildonAppMenu *menu)
 {
     HildonProgramPrivate *priv;
-    GtkWidget *old_menu;
+    HildonAppMenu *old_menu;
 
     g_return_if_fail (HILDON_IS_PROGRAM (self));
     g_return_if_fail (menu == NULL || HILDON_IS_APP_MENU (menu));
@@ -678,13 +685,13 @@ hildon_program_set_common_app_menu              (HildonProgram *self,
     old_menu = priv->common_app_menu;
 
     /* Set new menu */
-    priv->common_app_menu = GTK_WIDGET (menu);
+    priv->common_app_menu = menu;
     if (menu)
         g_object_ref_sink (menu);
 
     /* Hide and unref old menu */
     if (old_menu) {
-        hildon_app_menu_set_parent_window (HILDON_APP_MENU (old_menu), NULL);
+        hildon_app_menu_set_parent_window (old_menu, NULL);
         g_object_unref (old_menu);
     }
 }
@@ -711,18 +718,18 @@ hildon_program_get_common_app_menu              (HildonProgram *self)
     priv = HILDON_PROGRAM_GET_PRIVATE (self);
     g_assert (priv);
 
-    return HILDON_APP_MENU (priv->common_app_menu);
+    return priv->common_app_menu;
 }
 
 /**
  * hildon_program_set_common_toolbar:
  * @self: The #HildonProgram in which the common toolbar should be used
- * @toolbar: A GtkToolbar to use as common toolbar for the program
+ * @toolbar: A #GtkToolbar to use as common toolbar for the program
  *
- * Sets a GtkToolbar that will appear in all the #HildonWindow registered
- * to the #HildonProgram. Only one common GtkToolbar can be set, further
- * call will detach the previous common GtkToolbar. A #HildonWindow
- * can use its own GtkToolbar with hildon_window_add_toolbar(). Both
+ * Sets a #GtkToolbar that will appear in all the #HildonWindow registered
+ * to the #HildonProgram. Only one common #GtkToolbar can be set, further
+ * call will detach the previous common #GtkToolbar. A #HildonWindow
+ * can use its own #GtkToolbar with hildon_window_add_toolbar(). Both
  * #HildonProgram and #HildonWindow specific toolbars will be shown
  **/
 void