*
* 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-window
* @short_description: Widget representing a top-level window in the Hildon framework.
+ * @see_also: #HildonProgram, #HildonStackableWindow
*
- * The HildonWindow is a GTK widget which represents a top-level
- * window in the Hildon framework. It is derived from the GtkWindow
+ * #HildonWindow is a GTK widget which represents a top-level
+ * window in the Hildon framework. It is derived from #GtkWindow
* and provides additional commodities specific to the Hildon
* framework.
*
- * Among these windows in the Hildon framework can have a single menu
- * attached, which is toggled with a hardware key or by tapping
- * a custom button in the window frame. This menu can be set
- * by providing a GtkMenu to the hildon_window_set_menu() method.
+ * #HildonWindow<!-- -->s can have a menu attached, which is toggled
+ * with a hardware key or by tapping on the window frame. This menu
+ * can be either a #GtkMenu or a #HildonAppMenu (set with
+ * hildon_window_set_main_menu() and hildon_window_set_app_menu()
+ * respectively). Only one type of menu can be used at the same time.
+ * In Hildon 2.2, #HildonAppMenu is the recommended menu to use.
*
- * Similarly a window in the Hildon framework can have several toolbars
- * attached. These can be added to the HildonWindow with
- * hildon_window_add_toolbar().
+ * Similarly, a #HildonWindow can have several toolbars
+ * attached. These can be added with hildon_window_add_toolbar(). In
+ * addition to those, a #HildonWindow can also have a
+ * #HildonEditToolbar. To add it to the window use
+ * hildon_window_set_edit_toolbar().
*
* <example>
* <title>Creating a HildonWindow</title>
* <programlisting>
* HildonWindow *window;
* GtkToolbar *toolbar;
- * GtkMenu *menu;
+ * HildonAppMenu *menu;
* GdkPixbuf *icon_pixbuf;
* <!-- -->
* window = HILDON_WINDOW (hildon_window_new());
* <!-- -->
* icon_pixbuf = create_icon();
* <!-- -->
- * hildon_window_set_menu (window, menu);
+ * hildon_window_set_app_menu (window, menu);
* <!-- -->
* hildon_window_add_toolbar (window, toolbar);
* <!-- -->
#include "hildon-window.h"
#include "hildon-window-private.h"
+#include "hildon-app-menu-private.h"
#include "hildon-find-toolbar.h"
#include "hildon-defines.h"
GdkEventExpose * event,
gboolean fullscreen);
+static void
+paint_edit_toolbar (GtkWidget *widget,
+ GtkWidget *toolbar,
+ GdkEventExpose *event,
+ gboolean fullscreen);
+
enum
{
PROP_0,
priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
priv->menu = NULL;
+ priv->app_menu = NULL;
+ priv->edit_toolbar = NULL;
priv->visible_toolbars = 0;
priv->is_topmost = FALSE;
priv->borders = NULL;
static void
hildon_window_finalize (GObject * obj_self)
{
- HildonWindow *self;
HildonWindowPrivate *priv;
g_return_if_fail (HILDON_WINDOW (obj_self));
priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
g_assert (priv != NULL);
- self = HILDON_WINDOW (obj_self);
-
if (priv->escape_timeout) {
g_source_remove (priv->escape_timeout);
priv->escape_timeout = 0;
gtk_widget_realize (GTK_WIDGET (priv->vbox));
+ if (priv->edit_toolbar != NULL)
+ gtk_widget_realize (priv->edit_toolbar);
+
/* catch the custom button signal from mb to display the menu */
gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
/* Update the topmost status */
active_window = hildon_window_get_active_window();
hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
-
- /* Update the window title */
- hildon_window_update_title(HILDON_WINDOW (widget));
}
static void
widget);
gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
+
+ if (priv->edit_toolbar != NULL)
+ gtk_widget_unrealize (priv->edit_toolbar);
+
GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
}
if (GTK_WIDGET_VISIBLE (priv->vbox))
gtk_widget_map (priv->vbox);
+
+ if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
+ gtk_widget_map (priv->edit_toolbar);
}
static void
gtk_widget_unmap (priv->vbox);
+ if (priv->edit_toolbar != NULL)
+ gtk_widget_unmap (priv->edit_toolbar);
+
if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
}
paint_toolbar (widget, box,
event, priv->fullscreen);
+ if (priv->edit_toolbar != NULL)
+ {
+ paint_edit_toolbar (widget, priv->edit_toolbar,
+ event, priv->fullscreen);
+ }
+
if (! priv->fullscreen) {
/* Draw the left and right window border */
g_assert (priv);
GtkWidget *child = GTK_BIN (widget)->child;
- GtkRequisition req2;
+ GtkRequisition req2 = { 0 };
gint border_width = GTK_CONTAINER(widget)->border_width;
if (! priv->borders)
gtk_widget_size_request (priv->vbox, &req2);
requisition->height += req2.height;
- requisition->width = (requisition->width < req2.width) ?
- req2.width : requisition->width;
+ requisition->width = MAX (requisition->width, req2.width);
+
+ if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
+ {
+ GtkRequisition req;
+ gtk_widget_size_request (priv->edit_toolbar, &req);
+ requisition->height += req.height;
+ requisition->width = MAX (requisition->width, req.width);
+ }
requisition->width += 2 * border_width;
requisition->height += 2 * border_width;
HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
g_assert (priv);
- GtkAllocation box_alloc;
+ GtkAllocation box_alloc = { 0 };
+ GtkAllocation edittb_alloc = { 0 };
GtkAllocation alloc = *allocation;
- GtkRequisition req;
- gint border_width = GTK_CONTAINER(widget)->border_width;
- GtkWidget *box = priv->vbox;
- GtkBin *bin = GTK_BIN(widget);
- GtkBorder *b = priv->borders;
- GtkBorder *tb = priv->toolbar_borders;
+ GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
+ GtkBorder *tb;
if (!priv->borders)
- {
hildon_window_get_borders (HILDON_WINDOW (widget));
- b = priv->borders;
- tb = priv->toolbar_borders;
- }
+
+ tb = priv->toolbar_borders;
widget->allocation = *allocation;
- gtk_widget_get_child_requisition (box, &req);
+ /* Calculate allocation of edit toolbar */
+ if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
+ {
+ GtkRequisition req;
+ gtk_widget_get_child_requisition (priv->edit_toolbar, &req);
+ edittb_alloc.width = alloc.width - tb->left - tb->right;
+ edittb_alloc.height = MIN (req.height, alloc.height);
+ edittb_alloc.x = alloc.x + tb->left;
+ edittb_alloc.y = alloc.y + tb->top;
+
+ if (edittb_alloc.height > 0)
+ {
+ alloc.y += tb->top + tb->bottom + edittb_alloc.height;
+ alloc.height -= tb->top + tb->bottom + edittb_alloc.height;
+ gtk_widget_size_allocate (priv->edit_toolbar, &edittb_alloc);
+ }
+ }
- box_alloc.width = allocation->width - tb->left - tb->right;
- box_alloc.height = ( (req.height < allocation->height) ?
- req.height : allocation->height );
- box_alloc.x = allocation->x + tb->left;
- box_alloc.y = allocation->y + allocation->height - box_alloc.height - tb->bottom;
+ /* Calculate allocation of normal toolbars */
+ if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
+ {
+ GtkRequisition req;
+ gtk_widget_get_child_requisition (priv->vbox, &req);
+ box_alloc.width = alloc.width - tb->left - tb->right;
+ box_alloc.height = MIN (req.height, alloc.height);
+ box_alloc.x = alloc.x + tb->left;
+ box_alloc.y = alloc.y + alloc.height - box_alloc.height - tb->bottom;
+
+ if (box_alloc.height > 0)
+ {
+ alloc.height -= tb->top + tb->bottom + box_alloc.height;
+ gtk_widget_size_allocate (priv->vbox, &box_alloc);
+ }
+ }
- if (bin->child != NULL && GTK_IS_WIDGET (bin->child)
- && GTK_WIDGET_VISIBLE (bin->child))
+ /* Calculate allocation of the child widget */
+ if (child != NULL && GTK_WIDGET_VISIBLE (child))
{
+ guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
alloc.x += border_width;
alloc.y += border_width;
alloc.width -= (border_width * 2);
- alloc.height -= (border_width * 2) + box_alloc.height;
+ alloc.height -= (border_width * 2);
if (! priv->fullscreen)
{
+ GtkBorder *b = priv->borders;
alloc.x += b->left;
alloc.width -= (b->left + b->right);
- alloc.y += b->top;
- alloc.height -= b->top;
+ /* Use the top border if there's no edit toolbar */
+ if (edittb_alloc.height <= 0)
+ {
+ alloc.y += b->top;
+ alloc.height -= b->top;
+ }
+ /* Use the top border if there are no standard toolbars */
if (box_alloc.height <= 0)
alloc.height -= b->bottom;
- else
- alloc.height -= (tb->top + tb->bottom);
- }
- else
- {
- if (!(box_alloc.height <= 0))
- alloc.height -= (tb->top + tb->bottom);
}
- gtk_widget_size_allocate (bin->child, &alloc);
+ gtk_widget_size_allocate (child, &alloc);
}
- gtk_widget_size_allocate (box, &box_alloc);
-
if (priv->previous_vbox_y != box_alloc.y)
{
/* The size of the VBox has changed, we need to redraw part
* of the window borders */
- gint draw_from_y = priv->previous_vbox_y < box_alloc.y?
- priv->previous_vbox_y - tb->top:
- box_alloc.y - tb->top;
+ gint draw_from_y = MIN (priv->previous_vbox_y, box_alloc.y) - tb->top;
gtk_widget_queue_draw_area (widget, 0, draw_from_y,
widget->allocation.width,
GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
callback, callback_data);
+
if (include_internals && priv->vbox != NULL)
(* callback)(GTK_WIDGET (priv->vbox), callback_data);
+
+ if (include_internals && priv->edit_toolbar != NULL)
+ (* callback)(GTK_WIDGET (priv->edit_toolbar), callback_data);
}
static void
g_assert (priv != NULL);
GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
+
gtk_widget_show_all (priv->vbox);
+
+ if (priv->edit_toolbar)
+ gtk_widget_show_all (priv->edit_toolbar);
}
static void
}
+ if (priv->edit_toolbar != NULL)
+ {
+ gtk_widget_unparent (priv->edit_toolbar);
+ priv->edit_toolbar = NULL;
+ }
+
+ if (priv->app_menu)
+ {
+ hildon_app_menu_set_parent_window (priv->app_menu, NULL);
+ g_object_unref (priv->app_menu);
+ priv->app_menu = NULL;
+ }
+
menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
menu_node = menu_list;
{
HildonWindow *window = HILDON_WINDOW (gobject);
- if (g_str_equal (param->name, "title"))
- {
-
- hildon_window_update_title (window);
- }
- else if (g_str_equal (param->name, "is-topmost"))
+ if (g_str_equal (param->name, "is-topmost"))
{
hildon_window_is_topmost_notify (window);
}
}
}
+static void
+paint_edit_toolbar (GtkWidget *widget,
+ GtkWidget *toolbar,
+ GdkEventExpose *event,
+ gboolean fullscreen)
+{
+ if (!GTK_WIDGET_VISIBLE (toolbar))
+ return;
+
+ gtk_paint_box (widget->style, widget->window,
+ GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
+ &event->area, widget, "toolbar-edit-mode",
+ toolbar->allocation.x,
+ toolbar->allocation.y,
+ toolbar->allocation.width,
+ toolbar->allocation.height);
+}
+
/*
* Checks the root window to know which is the topped window
*/
{
HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
- Window my_window;
+ GdkWindow *my_window;
g_return_if_fail (HILDON_IS_WINDOW (self));
g_assert (priv);
- my_window = GDK_WINDOW_XID (GTK_WIDGET (self)->window);
+ my_window = GTK_WIDGET (self)->window;
- if (window_id == my_window)
+ if (my_window && window_id == GDK_WINDOW_XID (my_window))
{
if (! priv->is_topmost)
{
}
}
-/*
- * If the application
- * was given a name (with g_set_application_name(), set
- * "ProgramName - WindowTitle" as the displayed
- * title
- */
-void G_GNUC_INTERNAL
-hildon_window_update_title (HildonWindow *window)
+static void
+detach_menu_func (GtkWidget *attach_widget,
+ GtkMenu *menu)
{
- const gchar * application_name;
+ /* FIXME Why is this even needed here? */
+}
- g_return_if_fail (HILDON_IS_WINDOW (window));
+static gboolean
+hildon_window_toggle_menu (HildonWindow *self,
+ guint button,
+ guint32 time)
+{
+ g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
- if (!GTK_WIDGET_REALIZED (window))
+ if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
{
- return;
+ return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
}
+ else
+ {
+ return FALSE;
+ }
+}
- application_name = g_get_application_name ();
- if (application_name && application_name[0])
+static gboolean
+hildon_window_toggle_gtk_menu (HildonWindow *self,
+ GtkMenu *menu,
+ guint button,
+ guint32 time)
+{
+ gboolean retvalue = FALSE;
+
+ g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
+ g_return_val_if_fail (GTK_IS_MENU (menu), FALSE);
+
+ if (gtk_menu_get_attach_widget (menu) != GTK_WIDGET (self))
+ {
+ g_object_ref (menu);
+ if (gtk_menu_get_attach_widget (menu))
+ {
+ gtk_menu_detach (menu);
+ }
+ gtk_menu_attach_to_widget (menu, GTK_WIDGET (self), &detach_menu_func);
+ g_object_unref (menu);
+ }
+
+ if (GTK_WIDGET_MAPPED (menu))
{
- const gchar *old_title = gtk_window_get_title (GTK_WINDOW (window));
+ gtk_menu_popdown (menu);
+ gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu));
+ retvalue = TRUE;
+ }
+ else
+ {
+ /* Check if the menu has items */
+ GList *menu_children = gtk_container_get_children (GTK_CONTAINER (menu));
- if (old_title)
+ if (menu_children)
{
- gchar *title = NULL;
-
- if (strlen (old_title) == 0)
- title = g_strdup (application_name);
- else
- title = g_strjoin (TITLE_SEPARATOR, application_name,
- old_title, NULL);
+ HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
+ g_list_free (menu_children);
- gdk_window_set_title (GTK_WIDGET (window)->window, title);
+ /* Apply right theming */
+ gtk_widget_set_name (GTK_WIDGET (menu), "menu_force_with_corners");
- g_free (title);
+ if (priv->fullscreen)
+ {
+ gtk_menu_popup (menu, NULL, NULL,
+ (GtkMenuPositionFunc)
+ hildon_window_menu_popup_func_full,
+ self, button, time);
+ }
+ else
+ {
+ gtk_menu_popup (menu, NULL, NULL,
+ (GtkMenuPositionFunc)
+ hildon_window_menu_popup_func,
+ self, button, time);
+ }
+ gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE);
+ retvalue = TRUE;
}
-
}
-}
-static void
-detach_menu_func (GtkWidget *attach_widget,
- GtkMenu *menu)
-{
- /* FIXME Why is this even needed here? */
+ return retvalue;
}
static gboolean
-hildon_window_toggle_menu (HildonWindow *self,
- guint button,
- guint32 time)
+hildon_window_toggle_app_menu (HildonWindow *self,
+ HildonAppMenu *menu)
{
g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
+ g_return_val_if_fail (HILDON_IS_APP_MENU (menu), FALSE);
- if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
+ if (self != hildon_app_menu_get_parent_window (menu))
{
- return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
+ gtk_widget_hide (GTK_WIDGET (menu));
+ }
+
+ if (GTK_WIDGET_MAPPED (menu))
+ {
+ gtk_widget_hide (GTK_WIDGET (menu));
}
else
{
- return FALSE;
+ hildon_app_menu_popup (menu, GTK_WINDOW (self));
}
-}
+ return TRUE;
+}
/*
* Toggles the display of the HildonWindow menu.
guint button,
guint32 time)
{
- GtkMenu *menu_to_use = NULL;
- GList *menu_children = NULL;
+ gboolean retvalue = FALSE;
HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
- g_assert (priv != NULL);
/* Select which menu to use, Window specific has highest priority,
* then program specific */
if (priv->menu)
{
- menu_to_use = GTK_MENU (priv->menu);
- }
- else if (priv->program)
- {
- menu_to_use = hildon_program_get_common_menu (priv->program);
- if (menu_to_use && gtk_menu_get_attach_widget (menu_to_use) !=
- GTK_WIDGET (self))
- {
- g_object_ref (menu_to_use);
- if (gtk_menu_get_attach_widget (menu_to_use))
- {
- gtk_menu_detach (menu_to_use);
- }
-
- gtk_menu_attach_to_widget (menu_to_use, GTK_WIDGET (self),
- &detach_menu_func);
- g_object_unref (menu_to_use);
- }
- }
-
- if (! menu_to_use)
- {
- return FALSE;
+ retvalue = hildon_window_toggle_gtk_menu (self, priv->menu, button, time);
}
-
-
- if (GTK_WIDGET_MAPPED (GTK_WIDGET (menu_to_use)))
+ else if (priv->app_menu)
{
- gtk_menu_popdown (menu_to_use);
- gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_to_use));
- return TRUE;
+ retvalue = hildon_window_toggle_app_menu (self, priv->app_menu);
}
-
- /* Check if the menu has items */
- menu_children = gtk_container_get_children (GTK_CONTAINER (menu_to_use));
-
- if (menu_children)
+ else if (priv->program)
{
- g_list_free (menu_children);
-
- /* Apply right theming */
- gtk_widget_set_name (GTK_WIDGET (menu_to_use),
- "menu_force_with_corners");
+ GtkMenu *gtkmenu = hildon_program_get_common_menu (priv->program);
+ HildonAppMenu *appmenu = hildon_program_get_common_app_menu (priv->program);
- if (priv->fullscreen)
+ if (gtkmenu)
{
- gtk_menu_popup (menu_to_use, NULL, NULL,
- (GtkMenuPositionFunc)
- hildon_window_menu_popup_func_full,
- self, button, time);
+ retvalue = hildon_window_toggle_gtk_menu (self, gtkmenu, button, time);
}
- else
+ else if (appmenu)
{
- gtk_menu_popup (menu_to_use, NULL, NULL,
- (GtkMenuPositionFunc)
- hildon_window_menu_popup_func,
- self, button, time);
+ retvalue = hildon_window_toggle_app_menu (self, appmenu);
}
- gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_to_use), TRUE);
- return TRUE;
}
- return FALSE;
+ return retvalue;
}
/*
/**
* hildon_window_new:
*
- * Creates a new HildonWindow.
+ * Creates a new #HildonWindow.
*
- * Return value: A @HildonWindow.
+ * Return value: A #HildonWindow.
**/
GtkWidget*
hildon_window_new (void)
}
/**
- * hildon_window_add_with_scrollbar
- * @self : A @HildonWindow
- * @child : A @GtkWidget
+ * hildon_window_add_with_scrollbar:
+ * @self: A #HildonWindow
+ * @child: A #GtkWidget
*
- * Adds the @child to the HildonWindow and creates a scrollbar
- * for it. Similar as adding first a @GtkScrolledWindow and then the
- * @child to it.
+ * Adds @child to the #HildonWindow and creates a scrollbar for
+ * it. Similar to adding first a #GtkScrolledWindow and then @child to
+ * it.
*/
void
hildon_window_add_with_scrollbar (HildonWindow *self,
/**
* hildon_window_add_toolbar:
- * @self: A @HildonWindow
- * @toolbar: A #GtkToolbar to add to the HildonWindow
+ * @self: A #HildonWindow
+ * @toolbar: A #GtkToolbar to add to the #HildonWindow
*
* Adds a toolbar to the window. Note that the toolbar is not automatically
- * shown. You need to call #gtk_widget_show_all on it to make it visible.
+ * shown. You need to call gtk_widget_show_all() on it to make it visible.
* It's also possible to hide the toolbar (without removing it) by calling
- * #gtk_widget_hide.
+ * gtk_widget_hide()
**/
void
hildon_window_add_toolbar (HildonWindow *self,
/**
* hildon_window_remove_toolbar:
- * @self: A @HildonWindow
- * @toolbar: A #GtkToolbar to remove from the HildonWindow
+ * @self: A #HildonWindow
+ * @toolbar: A #GtkToolbar to remove from the #HildonWindow
*
* Removes a toolbar from the window. Note that this decreases the refference
- * count on the widget. If you want to keep the toolbar alive call #g_object_ref
+ * count on the widget. If you want to keep the toolbar alive call g_object_ref()
* before calling this function.
**/
void
}
/**
- * hildon_window_get_menu:
- * @self : #HildonWindow
- *
- * Gets the #GtMenu assigned to the #HildonAppview. Note that the
+ * hildon_window_set_edit_toolbar:
+ * @self: A #HildonWindow
+ * @toolbar: A #HildonEditToolbar, or %NULL to remove the current one.
+ *
+ * Adds a #HildonEditToolbar to the window. Note that the toolbar is
+ * not automatically shown. You need to call gtk_widget_show() on it
+ * to make it visible. It's also possible to hide the toolbar (without
+ * removing it) by calling gtk_widget_hide().
+ *
+ * A window can only have at most one edit toolbar at a time, so the
+ * previous toolbar (if any) is replaced after calling this function.
+ **/
+void
+hildon_window_set_edit_toolbar (HildonWindow *self,
+ HildonEditToolbar *toolbar)
+{
+ HildonWindowPrivate *priv;
+
+ g_return_if_fail (HILDON_IS_WINDOW (self));
+ g_return_if_fail (toolbar == NULL || HILDON_IS_EDIT_TOOLBAR (toolbar));
+
+ priv = HILDON_WINDOW_GET_PRIVATE (self);
+
+ if (priv->edit_toolbar != GTK_WIDGET (toolbar))
+ {
+ GtkWidget *old_toolbar = priv->edit_toolbar;
+ priv->edit_toolbar = GTK_WIDGET (toolbar);
+
+ if (priv->edit_toolbar)
+ gtk_widget_set_parent (priv->edit_toolbar, GTK_WIDGET (self));
+
+ if (old_toolbar)
+ gtk_widget_unparent (old_toolbar);
+ }
+}
+
+/**
+ * hildon_window_get_main_menu:
+ * @self: a #HildonWindow
+ *
+ * Gets the #GtkMenu assigned to the #HildonAppview. Note that the
* window is still the owner of the menu.
- *
+ *
+ * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
+ * you should use hildon_window_get_app_menu() instead.
+ *
* Return value: The #GtkMenu assigned to this application view.
**/
GtkMenu*
-hildon_window_get_menu (HildonWindow * self)
+hildon_window_get_main_menu (HildonWindow * self)
{
HildonWindowPrivate *priv;
priv = HILDON_WINDOW_GET_PRIVATE (self);
- return GTK_MENU (priv->menu);
+ return priv->menu;
+}
+
+/**
+ * hildon_window_get_menu:
+ * @self: a #HildonWindow
+ *
+ * Return value: a #GtkMenu
+ *
+ * Deprecated: In Hildon 2.2 this function has been renamed to
+ * hildon_window_get_main_menu() for consistency
+ **/
+GtkMenu*
+hildon_window_get_menu (HildonWindow * self)
+{
+ return hildon_window_get_main_menu (self);
}
/* Since we've been asking developers to call gtk_window_add_accel_group()
* hildon_window_set_main_menu:
* @self: A #HildonWindow
* @menu: The #GtkMenu to be used for this #HildonWindow
- *
+ *
* Sets the menu to be used for this window. This menu overrides
* a program-wide menu that may have been set with
* hildon_program_set_common_menu(). Pass %NULL to remove the current
* menu. #HildonWindow takes ownership of the passed menu and you're
* not supposed to free it yourself anymore.
*
- * Note that if you're using a #HildonStackableWindow (and not just a
- * standard #HildonWindow) you should use
- * hildon_stackable_window_set_main_menu()
- * instead. #HildonStackableWindow uses #HildonAppMenu rather than
- * #GtkMenu.
- *
- * Since: Hildon 2.2
- **/
+ * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
+ * you should use hildon_window_set_app_menu() instead.
+ **/
void
hildon_window_set_main_menu (HildonWindow* self,
GtkMenu * menu)
if (priv->menu != NULL)
{
- accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
+ accel_group = gtk_menu_get_accel_group (priv->menu);
if (accel_group != NULL)
gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
- gtk_menu_detach (GTK_MENU (priv->menu));
+ gtk_menu_detach (priv->menu);
g_object_unref (priv->menu);
}
- priv->menu = (menu != NULL) ? GTK_WIDGET (menu) : NULL;
+ priv->menu = menu;
if (priv->menu != NULL)
{
- gtk_widget_set_name (priv->menu, "menu_force_with_corners");
- gtk_menu_attach_to_widget (GTK_MENU (priv->menu), GTK_WIDGET (self), &detach_menu_func);
- g_object_ref (GTK_MENU (priv->menu));
+ gtk_widget_set_name (GTK_WIDGET (priv->menu), "menu_force_with_corners");
+ gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (self), &detach_menu_func);
+ g_object_ref (priv->menu);
- accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
+ accel_group = gtk_menu_get_accel_group (priv->menu);
if (accel_group != NULL)
hildon_window_add_accel_group (self, accel_group);
}
* hildon_window_set_menu:
* @self: A #HildonWindow
* @menu: The #GtkMenu to be used for this #HildonWindow
- *
+ *
* Sets the menu to be used for this window. This menu overrides
* a program-wide menu that may have been set with
- * hildon_program_set_common_menu. Pass NULL to remove the current
+ * hildon_program_set_common_menu(). Pass %NULL to remove the current
* menu. HildonWindow takes ownership of the passed menu and you're
* not supposed to free it yourself anymore.
*
* doesn't do this.
*
* Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
- **/
+ **/
void
hildon_window_set_menu (HildonWindow *self,
GtkMenu *menu)
/**
* hildon_window_get_is_topmost:
* @self: A #HildonWindow
- *
- * Return value: Whether or not the #HildonWindow is currenltly activated
- * by the window manager.
+ *
+ * Returns whether the #HildonWindow is currenty activated by the
+ * window manager.
+ *
+ * Return value: %TRUE if @self is currently activated, %FALSE otherwise.
**/
gboolean
hildon_window_get_is_topmost (HildonWindow *self)
return priv->is_topmost;
}
+/**
+ * hildon_window_set_app_menu:
+ * @self: a #HildonWindow
+ * @menu: a #HildonAppMenu to be used for this window
+ *
+ * Sets the menu to be used for this window. Pass %NULL to remove the
+ * current menu. Any reference to a previous menu will be dropped.
+ * #HildonWindow takes ownership of the passed menu and
+ * you're not supposed to free it yourself anymore.
+ *
+ * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
+ * you should use hildon_window_set_main_menu() instead.
+ *
+ * Since: 2.2
+ **/
+void
+hildon_window_set_app_menu (HildonWindow *self,
+ HildonAppMenu *menu)
+{
+ HildonWindowPrivate *priv;
+ HildonAppMenu *old_menu;
+
+ g_return_if_fail (HILDON_IS_WINDOW (self));
+ g_return_if_fail (!menu || HILDON_IS_APP_MENU (menu));
+ priv = HILDON_WINDOW_GET_PRIVATE (self);
+
+ old_menu = priv->app_menu;
+
+ /* Add new menu */
+ priv->app_menu = menu;
+ if (menu)
+ g_object_ref_sink (menu);
+
+ /* Unref old menu */
+ if (old_menu)
+ g_object_unref (old_menu);
+}
+
+/**
+ * hildon_window_get_app_menu:
+ * @self: a #HildonWindow
+ *
+ * Returns the #HildonAppMenu assigned to @self, or %NULL if it's
+ * unset. Note that the window is still the owner of the menu.
+ *
+ * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
+ * you should use hildon_window_get_main_menu() instead.
+ *
+ * Returns: a #HildonAppMenu
+ *
+ * Since: 2.2
+ **/
+HildonAppMenu *
+hildon_window_get_app_menu (HildonWindow *self)
+{
+ HildonWindowPrivate *priv;
+
+ g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
+
+ priv = HILDON_WINDOW_GET_PRIVATE (self);
+
+ return priv->app_menu;
+}