*
* 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
* @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
* low memory.
*
- * The #HildonProgram also contains a stack of
- * #HildonStackableWindow. Such windows will be automatically added to
- * the stack when shown, and removed when destroyed. The developer can
- * use the stack with hildon_program_pop_window_stack(),
- * hildon_program_peek_window_stack() and hildon_program_go_to_root_window().
- *
* <example>
* <programlisting>
* HildonProgram *program;
* 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 (window1, window_specific_toolbar);
* </example>
*/
+#undef HILDON_DISABLE_DEPRECATED
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "hildon-program.h"
#include "hildon-program-private.h"
#include "hildon-window-private.h"
-#include "hildon-stackable-window-private.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;
- priv->window_stack = 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
*
- * The #HildonProgram object maintains a list of stackable
- * windows. Each time a #HildonStackableWindow is shown, it is
- * automatically added to the top of the stack. Windows are removed
- * from the stack when they are destroyed.
+ * Pops a window from the stack.
*
- * This function removes the #HildonStackableWindow from the top of
- * the stack and returns it. If the stack is empty, %NULL is returned.
+ * Deprecated: Use hildon_window_stack_pop() instead
*
- * If the window was visible then it will be hidden. The next window
- * from the stack (if any) will be shown automatically.
- *
- * If the window was not visible then all other windows will remain
- * hidden.
- *
- * No window is destroyed in any case.
- *
- * Returns: A #HildonStackableWindow, or %NULL.
+ * Returns: A #HildonStackableWindow, or %NULL
*/
HildonStackableWindow *
hildon_program_pop_window_stack (HildonProgram *self)
{
- HildonStackableWindow *top;
-
- top = hildon_program_peek_window_stack (self);
-
- if (top)
- {
- HildonStackableWindow *next;
-
- /* Remove the window from the stack and get the next one */
- _hildon_program_remove_from_stack (self, top);
- next = hildon_program_peek_window_stack (self);
-
- /* Hide the window just removed and show the next one if necessary */
- if (GTK_WIDGET_VISIBLE (GTK_WIDGET (top)) && next != NULL);
- gtk_widget_show (GTK_WIDGET (next));
-
- gtk_widget_hide (GTK_WIDGET (top));
- }
-
- return top;
+ 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
*
- * The #HildonProgram object maintains a list of stackable
- * windows. Each time a #HildonStackableWindow is shown, it is
- * automatically added to the top of the stack. Windows are removed
- * from the stack when they are destroyed.
+ * Deprecated: Use hildon_window_stack_peek() instead
*
- * This function returns the #HildonStackableWindow from the top of
- * the stack, or %NULL if the stack is empty. The stack is never modified.
- *
- * Returns: A #HildonStackableWindow, or %NULL.
+ * Returns: A #HildonStackableWindow, or %NULL
*/
HildonStackableWindow *
hildon_program_peek_window_stack (HildonProgram *self)
{
- HildonStackableWindow *top = NULL;
- HildonProgramPrivate *priv;
-
- g_return_val_if_fail (HILDON_IS_PROGRAM (self), NULL);
-
- priv = HILDON_PROGRAM_GET_PRIVATE (self);
- g_assert (priv);
-
- if (priv->window_stack != NULL)
- top = HILDON_STACKABLE_WINDOW (priv->window_stack->data);
-
- return top;
-}
-
-void G_GNUC_INTERNAL
-_hildon_program_add_to_stack (HildonProgram *self,
- HildonStackableWindow *win)
-{
- HildonProgramPrivate *priv;
-
- g_return_if_fail (HILDON_IS_PROGRAM (self));
- g_return_if_fail (HILDON_IS_STACKABLE_WINDOW (win));
-
- priv = HILDON_PROGRAM_GET_PRIVATE (self);
- g_assert (priv);
-
- if (g_slist_find (priv->window_stack, win) == NULL)
- {
- priv->window_stack = g_slist_prepend (priv->window_stack, win);
- }
- else
- {
- g_critical ("%s: window already in the stack!", __FUNCTION__);
- }
-
-}
-
-gboolean G_GNUC_INTERNAL
-_hildon_program_remove_from_stack (HildonProgram *self,
- HildonStackableWindow *win)
-{
- GSList *pos;
- HildonProgramPrivate *priv;
-
- g_return_val_if_fail (HILDON_IS_PROGRAM (self), FALSE);
- g_return_val_if_fail (HILDON_IS_STACKABLE_WINDOW (win), FALSE);
-
- priv = HILDON_PROGRAM_GET_PRIVATE (self);
- g_assert (priv);
-
- pos = g_slist_find (priv->window_stack, win);
-
- if (pos != NULL)
- priv->window_stack = g_slist_delete_link (priv->window_stack, pos);
-
- return (pos != NULL);
+ 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 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)
*
* 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 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 it's 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 does not support #HildonAppMenu objects.
+ * This method does not support #HildonAppMenu<!-- -->s. See
+ * hildon_program_set_common_app_menu() for that.
+ *
+ * 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_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
* 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)
* hildon_program_go_to_root_window:
* @self: A #HildonProgram
*
- * Will close all windows in the #HildonProgram but the first one (the
- * root window) by sending them a delete event. If any of the windows
- * refuses to close (by capturing the event) no further events will be
- * sent. Only windows of type #HildonStackableWindow will be affected
- * by this.
+ * Goes to the root window of the stack.
+ *
+ * Deprecated: See #HildonWindowStack
*/
void
hildon_program_go_to_root_window (HildonProgram *self)
{
- HildonProgramPrivate *priv;
- GSList *windows, *iter;
- gboolean windows_left;
-
- g_return_if_fail (HILDON_IS_PROGRAM (self));
- priv = HILDON_PROGRAM_GET_PRIVATE (self);
- g_assert (priv);
-
- /* List of stacked windows (starting from the topmost one) */
- windows = g_slist_copy (priv->window_stack);
- iter = windows;
-
- /* Destroy all the windows but the last one (which is the root
- * window, as the list is reversed) */
- windows_left = (iter != NULL && iter->next != NULL);
- while (windows_left)
- {
- if (HILDON_IS_STACKABLE_WINDOW (iter->data))
- {
- GdkEvent *event;
- HildonStackableWindow *win;
-
- /* Mark the window as "going home" */
- win = HILDON_STACKABLE_WINDOW (iter->data);
- hildon_stackable_window_set_going_home (win, TRUE);
-
- /* Set win pointer to NULL if the window is destroyed */
- g_object_add_weak_pointer (G_OBJECT (win), (gpointer) &win);
-
- /* Send a delete event */
- event = gdk_event_new (GDK_DELETE);
- event->any.window = g_object_ref (GTK_WIDGET (win)->window);
- gtk_main_do_event (event);
- gdk_event_free (event);
-
- /* Continue sending delete events if the window has been destroyed */
- if (win == NULL)
- {
- iter = iter->next;
- windows_left = (iter != NULL && iter->next != NULL);
- }
- else
- {
- g_object_remove_weak_pointer (G_OBJECT (win), (gpointer) &win);
- hildon_stackable_window_set_going_home (win, FALSE);
- windows_left = FALSE;
- }
- }
- else
- {
- g_critical ("Window list contains a non-stackable window");
- windows_left = FALSE;
- }
+ 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);
}
-
- /* Show the last window that hasn't been destroyed */
- if (iter != NULL && GTK_IS_WIDGET (iter->data))
- {
- gtk_widget_show (GTK_WIDGET (iter->data));
- }
-
- g_slist_free (windows);
}