*
* 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-program
* @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,
- * 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().
- *
- * The HildonProgram is also used to apply program-wide properties that
+ *
+ * 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().
+ *
+ * #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().
+ *
+ * #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
* low memory.
- *
+ *
* <example>
* <programlisting>
* HildonProgram *program;
- * HildonWindow *first_window;
- * HildonWindow *second_window;
+ * HildonWindow *window1;
+ * HildonWindow *window2;
* GtkToolbar *common_toolbar, *window_specific_toolbar;
- * GtkMenu *menu;
+ * HildonAppMenu *menu;
* <!-- -->
* program = HILDON_PROGRAM (hildon_program_get_instance ());
* <!-- -->
* 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 (first_window, window_specific_toolbar);
+ * hildon_window_add_toolbar (window1, window_specific_toolbar);
* <!-- -->
* hildon_program_set_can_hibernate (program, TRUE);
* </programlisting>
* </example>
*/
+#undef HILDON_DISABLE_DEPRECATED
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <X11/Xatom.h>
+
#include "hildon-program.h"
#include "hildon-program-private.h"
#include "hildon-window-private.h"
-#include <X11/Xatom.h>
+#include "hildon-window-stack.h"
+#include "hildon-app-menu-private.h"
static void
hildon_program_init (HildonProgram *self);
priv->window_count = 0;
priv->is_topmost = FALSE;
priv->window_group = GDK_WINDOW_XID (gdk_display_get_default_group (gdk_display_get_default()));
+ priv->common_menu = NULL;
+ priv->common_app_menu = NULL;
priv->common_toolbar = NULL;
- priv->name = NULL;
+ priv->windows = NULL;
}
static void
g_object_unref (priv->common_menu);
priv->common_menu = NULL;
}
-
- g_free (priv->name);
}
static void
}
}
+/**
+ * hildon_program_pop_window_stack:
+ * @self: A #HildonProgram
+ *
+ * Pops a window from the stack.
+ *
+ * Deprecated: Use hildon_window_stack_pop() instead
+ *
+ * Returns: A #HildonStackableWindow, or %NULL
+ */
+HildonStackableWindow *
+hildon_program_pop_window_stack (HildonProgram *self)
+{
+ HildonWindowStack *stack = hildon_window_stack_get_default ();
+ GtkWidget *win = hildon_window_stack_pop_1 (stack);
+ g_warning ("%s: this function is deprecated. Use hildon_window_stack_pop() instead", __FUNCTION__);
+ return win ? HILDON_STACKABLE_WINDOW (win) : NULL;
+}
+
+/**
+ * hildon_program_peek_window_stack:
+ * @self: A #HildonProgram
+ *
+ * Deprecated: Use hildon_window_stack_peek() instead
+ *
+ * Returns: A #HildonStackableWindow, or %NULL
+ */
+HildonStackableWindow *
+hildon_program_peek_window_stack (HildonProgram *self)
+{
+ HildonWindowStack *stack = hildon_window_stack_get_default ();
+ GtkWidget *win = hildon_window_stack_peek (stack);
+ g_warning ("%s: this function is deprecated. Use hildon_window_stack_peek() instead", __FUNCTION__);
+ return win ? HILDON_STACKABLE_WINDOW (win) : NULL;
+}
+
/* Utilities */
static gint
hildon_program_window_list_compare (gconstpointer window_a,
static void
hildon_program_update_top_most (HildonProgram *program)
{
- XWMHints *wm_hints;
+ gboolean is_topmost;
Window active_window;
HildonProgramPrivate *priv;
g_assert (priv);
active_window = hildon_window_get_active_window();
+ is_topmost = FALSE;
if (active_window)
{
gint xerror;
+ 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)
{
-
- 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");
- }
+ is_topmost = (wm_hints->window_group == priv->window_group);
+ XFree (wm_hints);
}
- 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");
}
/* Check each window if it was is_topmost */
/**
* hildon_program_get_instance:
*
- * Return value: Returns the #HildonProgram for the current process.
- * The object is created on the first call. Note that you're not supposed
- * to unref the returned object since it's not reffed in the first place.
+ * Returns the #HildonProgram for the current process. The object is
+ * created on the first call. Note that you're not supposed to unref
+ * the returned object since it's not reffed in the first place.
+ *
+ * Return value: the #HildonProgram.
**/
HildonProgram*
hildon_program_get_instance (void)
/**
* hildon_program_add_window:
- * @self: The @HildonProgram to which the window should be registered
- * @window: A @HildonWindow to be added
+ * @self: The #HildonProgram to which the window should be registered
+ * @window: A #HildonWindow to be added
*
- * Registers a @HildonWindow as belonging to a given @HildonProgram. This
+ * 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,
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);
/**
* 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,
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);
/**
* hildon_program_get_can_hibernate:
* @self: The #HildonProgram which can hibernate or not
- *
- * Return value: Whether or not this #HildonProgram is set to be
- * support hibernation from the Hildon task navigator
+ *
+ * Returns whether the #HildonProgram is set to be support hibernation
+ * from the Hildon task navigator
+ *
+ * Return value: %TRUE if the program can hibernate, %FALSE otherwise.
**/
gboolean
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 #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 does not support #HildonAppMenu<!-- -->s. See
+ * hildon_program_set_common_app_menu() for that.
*
- * Sets a GtkMenu that will appear in all the @HildonWindow registered
- * to the #HildonProgram. Only one common GtkMenu can be set, further
- * call will detach the previous common GtkMenu. A @HildonWindow
- * can use it's own GtkMenu with @hildon_window_set_menu
+ * Since: 2.2
**/
void
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
{
}
}
- priv->common_menu = GTK_WIDGET (menu);
+ priv->common_menu = menu;
if (priv->common_menu)
{
* hildon_program_get_common_menu:
* @self: The #HildonProgram from which to retrieve the common menu
*
- * Return value: the GtkMenu that was set as common menu for this
- * #HildonProgram, or NULL of no common menu was set.
+ * Returns the #GtkMenu that was set as common menu for this
+ * #HildonProgram.
+ *
+ * Return value: the #GtkMenu or %NULL of no common menu was set.
**/
GtkMenu*
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;
+}
+
+/**
+ * hildon_program_set_common_app_menu:
+ * @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
+ * #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 does not support #GtkMenu<!-- -->s. See
+ * hildon_program_set_common_menu() for that.
+ *
+ * Since: 2.2
+ **/
+void
+hildon_program_set_common_app_menu (HildonProgram *self,
+ HildonAppMenu *menu)
+{
+ HildonProgramPrivate *priv;
+ HildonAppMenu *old_menu;
+
+ g_return_if_fail (HILDON_IS_PROGRAM (self));
+ g_return_if_fail (menu == NULL || HILDON_IS_APP_MENU (menu));
+
+ priv = HILDON_PROGRAM_GET_PRIVATE (self);
+ g_assert (priv);
+
+ old_menu = priv->common_app_menu;
+
+ /* Set new 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 (old_menu, NULL);
+ g_object_unref (old_menu);
+ }
+}
+
+/**
+ * hildon_program_get_common_app_menu:
+ * @self: The #HildonProgram from which to retrieve the common app menu
+ *
+ * Returns the #HildonAppMenu that was set as common menu for this
+ * #HildonProgram.
+ *
+ * Return value: the #HildonAppMenu or %NULL of no common app menu was
+ * set.
+ *
+ * Since: 2.2
+ **/
+HildonAppMenu*
+hildon_program_get_common_app_menu (HildonProgram *self)
+{
+ HildonProgramPrivate *priv;
+
+ g_return_val_if_fail (HILDON_IS_PROGRAM (self), NULL);
+
+ priv = HILDON_PROGRAM_GET_PRIVATE (self);
+ g_assert (priv);
+
+ 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_set_toolbar. Both
- * #HildonProgram and @HildonWindow specific toolbars will be shown
+ * 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
hildon_program_set_common_toolbar (HildonProgram *self,
* hildon_program_get_common_toolbar:
* @self: The #HildonProgram from which to retrieve the common toolbar
*
- * Return value: the GtkToolbar that was set as common toolbar for this
- * #HildonProgram, or NULL of no common menu was set.
+ * Returns the #GtkToolbar that was set as common toolbar for this
+ * #HildonProgram.
+ *
+ * Return value: the #GtkToolbar or %NULL of no common toolbar was
+ * set.
**/
GtkToolbar*
hildon_program_get_common_toolbar (HildonProgram *self)
* hildon_program_get_is_topmost:
* @self: A #HildonWindow
*
- * Return value: Whether or not one of the program's window or dialog is
- * currenltly activated by the window manager.
+ * Returns whether one of the program's windows or dialogs is
+ * currently activated by the window manager.
+ *
+ * Return value: %TRUE if a window or dialog is topmost, %FALSE
+ * otherwise.
**/
gboolean
hildon_program_get_is_topmost (HildonProgram *self)
return priv->is_topmost;
}
+
+/**
+ * hildon_program_go_to_root_window:
+ * @self: A #HildonProgram
+ *
+ * Goes to the root window of the stack.
+ *
+ * Deprecated: See #HildonWindowStack
+ */
+void
+hildon_program_go_to_root_window (HildonProgram *self)
+{
+ HildonWindowStack *stack = hildon_window_stack_get_default ();
+ gint n = hildon_window_stack_size (stack);
+ g_warning ("%s: this function is deprecated. Use hildon_window_stack_pop() instead.", __FUNCTION__);
+ if (n > 1) {
+ hildon_window_stack_pop (stack, n-1, NULL);
+ }
+}