2 * This file is a part of hildon
4 * Copyright (C) 2006 Nokia Corporation, all rights reserved.
6 * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-window
27 * @short_description: Widget representing a top-level window in the Hildon framework.
29 * The HildonWindow is a GTK widget which represents a top-level
30 * window in the Hildon framework. It is derived from the GtkWindow
31 * and provides additional commodities specific to the Hildon
34 * Among these windows in the Hildon framework can have a single menu
35 * attached, which is toggled with a hardware key or by tapping
36 * a custom button in the window frame. This menu can be set
37 * by providing a GtkMenu to the hildon_window_set_main_menu() method.
39 * Similarly, a window in the Hildon framework can have several toolbars
40 * attached. These can be added to the HildonWindow with
41 * hildon_window_add_toolbar().
43 * A #HildonWindow can also have a #HildonEditToolbar. To add it to
44 * the window use hildon_window_set_edit_toolbar().
47 * <title>Creating a HildonWindow</title>
49 * HildonWindow *window;
50 * GtkToolbar *toolbar;
52 * GdkPixbuf *icon_pixbuf;
54 * window = HILDON_WINDOW (hildon_window_new());
56 * toolbar = create_toolbar();
58 * menu = create_menu();
60 * icon_pixbuf = create_icon();
62 * hildon_window_set_main_menu (window, menu);
64 * hildon_window_add_toolbar (window, toolbar);
66 * // Can be used to set the window fullscreen
67 * gtk_window_fullscreen (GTK_WINDOW (window));
69 * // Used to trigger the blinking of the window's icon in the task navigator
70 * gtk_window_set_urgency_hint (GTK_WINDOW (window), TRUE);
72 * // Change the window's icon in the task navigator
73 * gtk_window_set_icon (GTK_WINDOW (window), icon_pixbuf);
78 #undef HILDON_DISABLE_DEPRECATED
86 #include <X11/Xatom.h>
87 #include <gdk/gdkkeysyms.h>
89 #include <gtk/gtkprivate.h>
91 #include "hildon-window.h"
92 #include "hildon-window-private.h"
93 #include "hildon-find-toolbar.h"
94 #include "hildon-defines.h"
96 #define _(String) gettext(String)
98 #define TOOLBAR_HEIGHT 70
100 #define TOOLBAR_MIDDLE 0
103 #define CAN_HIBERNATE "CANKILL"
105 #define CAN_HIBERNATE_LENGTH 7
107 #define CAN_HIBERNATE_PROPERTY "_HILDON_ABLE_TO_HIBERNATE"
109 #define TITLE_SEPARATOR " - "
111 typedef void (*HildonWindowSignal) (HildonWindow *, gint, gpointer);
114 hildon_window_init (HildonWindow * self);
117 hildon_window_class_init (HildonWindowClass * window_class);
120 hildon_window_menu_popup_func (GtkMenu *menu,
126 hildon_window_menu_popup_func_full (GtkMenu *menu,
132 hildon_window_expose (GtkWidget *widget,
133 GdkEventExpose *event);
135 hildon_window_forall (GtkContainer *container,
136 gboolean include_internals,
137 GtkCallback callback,
138 gpointer callback_data);
140 hildon_window_show_all (GtkWidget *widget);
143 hildon_window_size_allocate (GtkWidget * widget,
144 GtkAllocation *allocation);
146 hildon_window_size_request (GtkWidget * widget,
147 GtkRequisition *requisition);
149 hildon_window_finalize (GObject *obj_self);
152 hildon_window_get_property (GObject *object,
158 hildon_window_destroy (GtkObject *obj);
161 hildon_window_realize (GtkWidget *widget);
164 hildon_window_unrealize (GtkWidget *widget);
167 hildon_window_map (GtkWidget *widget);
170 hildon_window_unmap (GtkWidget *widget);
173 hildon_window_key_press_event (GtkWidget *widget,
177 hildon_window_key_release_event (GtkWidget *widget,
180 hildon_window_window_state_event (GtkWidget *widget,
181 GdkEventWindowState *event);
183 hildon_window_focus_out_event (GtkWidget *widget,
184 GdkEventFocus *event);
187 hildon_window_notify (GObject *gobject,
191 hildon_window_is_topmost_notify (HildonWindow *window);
194 hildon_window_toggle_menu (HildonWindow * self,
199 hildon_window_toggle_menu_real (HildonWindow * self,
204 hildon_window_escape_timeout (gpointer data);
206 static GdkFilterReturn
207 hildon_window_event_filter (GdkXEvent *xevent,
211 static GdkFilterReturn
212 hildon_window_root_window_event_filter (GdkXEvent *xevent,
217 hildon_window_get_borders (HildonWindow *window);
220 visible_toolbar (gpointer data,
224 paint_toolbar (GtkWidget *widget,
226 GdkEventExpose * event,
227 gboolean fullscreen);
230 paint_edit_toolbar (GtkWidget *widget,
232 GdkEventExpose *event,
233 gboolean fullscreen);
248 G_DEFINE_TYPE (HildonWindow, hildon_window, GTK_TYPE_WINDOW);
251 hildon_window_class_init (HildonWindowClass * window_class)
253 /* Get convenience variables */
254 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (window_class);
255 GObjectClass *object_class = G_OBJECT_CLASS (window_class);
256 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (window_class);
258 object_class->get_property = hildon_window_get_property;
259 object_class->notify = hildon_window_notify;
260 widget_class->size_allocate = hildon_window_size_allocate;
261 widget_class->size_request = hildon_window_size_request;
262 widget_class->expose_event = hildon_window_expose;
263 widget_class->show_all = hildon_window_show_all;
264 widget_class->realize = hildon_window_realize;
265 widget_class->unrealize = hildon_window_unrealize;
266 widget_class->key_press_event = hildon_window_key_press_event;
267 widget_class->key_release_event = hildon_window_key_release_event;
268 widget_class->window_state_event = hildon_window_window_state_event;
269 widget_class->focus_out_event = hildon_window_focus_out_event;
270 widget_class->map = hildon_window_map;
271 widget_class->unmap = hildon_window_unmap;
273 /* now the object stuff */
274 object_class->finalize = hildon_window_finalize;
276 /* To the container */
277 container_class->forall = hildon_window_forall;
280 window_class->toggle_menu = hildon_window_toggle_menu_real;
283 GTK_OBJECT_CLASS (window_class)->destroy = hildon_window_destroy;
285 g_type_class_add_private (window_class,
286 sizeof (struct _HildonWindowPrivate));
288 /* Install properties */
290 g_object_class_install_property (object_class, PROP_IS_TOPMOST,
291 g_param_spec_boolean ("is-topmost",
293 "Whether the window is currently activated by the window "
298 gtk_widget_class_install_style_property (widget_class,
299 g_param_spec_boxed ("borders",
301 "Size of graphical window borders",
305 gtk_widget_class_install_style_property (widget_class,
306 g_param_spec_boxed ("toolbar-borders",
307 "Graphical toolbar borders",
308 "Size of graphical toolbar borders",
312 /* opera hack, install clip operation signal */
313 g_signal_new ("clipboard_operation",
314 G_OBJECT_CLASS_TYPE (object_class),
316 G_STRUCT_OFFSET (HildonWindowClass, clipboard_operation),
318 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1,
323 hildon_window_init (HildonWindow *self)
325 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
326 g_assert (priv != NULL);
328 priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
329 gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
331 priv->edit_toolbar = NULL;
332 priv->visible_toolbars = 0;
333 priv->is_topmost = FALSE;
334 priv->borders = NULL;
335 priv->toolbar_borders = NULL;
336 priv->escape_timeout = 0;
338 priv->fullscreen = FALSE;
340 priv->program = NULL;
342 /* We need to track the root window _MB_CURRENT_APP_WINDOW property */
343 gdk_window_set_events (gdk_get_default_root_window (),
344 gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK);
346 gdk_window_add_filter (gdk_get_default_root_window (),
347 hildon_window_root_window_event_filter, self);
351 hildon_window_finalize (GObject * obj_self)
353 HildonWindowPrivate *priv;
355 g_return_if_fail (HILDON_WINDOW (obj_self));
357 priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
358 g_assert (priv != NULL);
360 if (priv->escape_timeout) {
361 g_source_remove (priv->escape_timeout);
362 priv->escape_timeout = 0;
366 gtk_border_free (priv->borders);
368 if (priv->toolbar_borders)
369 gtk_border_free (priv->toolbar_borders);
371 if (G_OBJECT_CLASS (hildon_window_parent_class)->finalize)
372 G_OBJECT_CLASS (hildon_window_parent_class)->finalize (obj_self);
377 hildon_window_realize (GtkWidget *widget)
379 Atom *old_atoms, *new_atoms;
383 Window active_window;
384 HildonWindowPrivate *priv;
386 GTK_WIDGET_CLASS (hildon_window_parent_class)->realize (widget);
388 priv = HILDON_WINDOW_GET_PRIVATE (widget);
389 g_assert (priv != NULL);
391 gtk_widget_realize (GTK_WIDGET (priv->vbox));
393 if (priv->edit_toolbar != NULL)
394 gtk_widget_realize (priv->edit_toolbar);
396 /* catch the custom button signal from mb to display the menu */
397 gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
399 window = GDK_WINDOW_XID (widget->window);
400 disp = GDK_WINDOW_XDISPLAY (widget->window);
402 /* Enable custom button that is used for menu */
403 XGetWMProtocols (disp, window, &old_atoms, &atom_count);
404 new_atoms = g_new (Atom, atom_count + 1);
406 memcpy (new_atoms, old_atoms, sizeof(Atom) * atom_count);
408 new_atoms[atom_count++] =
409 XInternAtom (disp, "_NET_WM_CONTEXT_CUSTOM", False);
411 XSetWMProtocols (disp, window, new_atoms, atom_count);
416 /* rely on GDK to set the window group to its default */
417 gdk_window_set_group (widget->window, NULL);
420 gboolean can_hibernate = hildon_program_get_can_hibernate (priv->program);
422 hildon_window_set_can_hibernate_property (HILDON_WINDOW (widget),
426 /* Update the topmost status */
427 active_window = hildon_window_get_active_window();
428 hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
432 hildon_window_unrealize (GtkWidget *widget)
434 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
435 g_assert (priv != NULL);
437 gdk_window_remove_filter (widget->window, hildon_window_event_filter,
440 gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
442 if (priv->edit_toolbar != NULL)
443 gtk_widget_unrealize (priv->edit_toolbar);
445 GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
449 hildon_window_map (GtkWidget *widget)
451 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
452 g_assert (priv != NULL);
454 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->map)
455 GTK_WIDGET_CLASS (hildon_window_parent_class)->map (widget);
457 if (GTK_WIDGET_VISIBLE (priv->vbox))
458 gtk_widget_map (priv->vbox);
460 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
461 gtk_widget_map (priv->edit_toolbar);
465 hildon_window_unmap (GtkWidget *widget)
467 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
468 g_assert (priv != NULL);
470 gtk_widget_unmap (priv->vbox);
472 if (priv->edit_toolbar != NULL)
473 gtk_widget_unmap (priv->edit_toolbar);
475 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
476 GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
480 hildon_window_get_property (GObject *object,
485 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (object);
486 g_assert (priv != NULL);
488 switch (property_id) {
490 case PROP_IS_TOPMOST:
491 g_value_set_boolean (value, priv->is_topmost);
495 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
501 * Retrieve the graphical borders size used by the themes
504 hildon_window_get_borders (HildonWindow *window)
506 GtkBorder zero = {0, 0, 0, 0};
507 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
510 GtkBorder *borders = NULL;
511 GtkBorder *toolbar_borders = NULL;
514 gtk_border_free (priv->borders);
515 if (priv->toolbar_borders)
516 gtk_border_free (priv->toolbar_borders);
518 priv->borders = NULL;
519 priv->toolbar_borders = NULL;
521 gtk_widget_style_get (GTK_WIDGET (window), "borders",&borders,
522 "toolbar-borders", &toolbar_borders,
525 // We're doing a copy here instead of reusing the pointer,
526 // as we don't know where it comes from (has it been allocated using
527 // malloc or slices... and we want to free it sanely. Blowing on
531 priv->borders = gtk_border_copy (borders);
532 gtk_border_free (borders);
534 priv->borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
536 if (toolbar_borders) {
537 priv->toolbar_borders = gtk_border_copy (toolbar_borders);
538 gtk_border_free (toolbar_borders);
540 priv->toolbar_borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
544 hildon_window_expose (GtkWidget *widget,
545 GdkEventExpose * event)
547 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
550 GtkWidget *bx = priv->vbox;
551 GtkBox *box = GTK_BOX(bx);
552 GtkBorder *b = priv->borders;
553 GtkBorder *tb = priv->toolbar_borders;
556 if (! priv->borders) {
557 hildon_window_get_borders (HILDON_WINDOW (widget));
559 tb = priv->toolbar_borders;
562 tb_height = bx->allocation.height + tb->top + tb->bottom;
564 paint_toolbar (widget, box,
565 event, priv->fullscreen);
567 if (priv->edit_toolbar != NULL)
569 paint_edit_toolbar (widget, priv->edit_toolbar,
570 event, priv->fullscreen);
573 if (! priv->fullscreen) {
575 /* Draw the left and right window border */
576 gint side_borders_height = widget->allocation.height - b->top;
578 if (priv->visible_toolbars)
579 side_borders_height -= tb_height;
581 side_borders_height -= b->bottom;
585 gtk_paint_box (widget->style, widget->window,
586 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
587 &event->area, widget, "left-border",
588 widget->allocation.x, widget->allocation.y +
589 b->top, b->left, side_borders_height);
594 gtk_paint_box (widget->style, widget->window,
595 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
596 &event->area, widget, "right-border",
597 widget->allocation.x + widget->allocation.width -
598 b->right, widget->allocation.y + b->top,
599 b->right, side_borders_height);
602 /* If no toolbar, draw the bottom window border */
603 if (! priv->visible_toolbars && b->bottom > 0)
605 gtk_paint_box (widget->style, widget->window,
606 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
607 &event->area, widget, "bottom-border",
608 widget->allocation.x, widget->allocation.y +
609 (widget->allocation.height - b->bottom),
610 widget->allocation.width, b->bottom);
613 /* Draw the top border */
616 gtk_paint_box (widget->style, widget->window,
617 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
618 &event->area, widget, "top-border",
619 widget->allocation.x, widget->allocation.y,
620 widget->allocation.width, b->top);
626 /* don't draw the window stuff as it overwrites our borders with a blank
627 * rectangle. Instead start with the drawing of the GtkBin */
628 GTK_WIDGET_CLASS (g_type_class_peek_parent (hildon_window_parent_class))->expose_event (widget, event);
630 /* FIXME Not sure why this is commented out
631 * GTK_WIDGET_CLASS (hildon_window_parent_class))->
632 * expose_event (widget, event);
639 hildon_window_size_request (GtkWidget *widget,
640 GtkRequisition *requisition)
642 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
645 GtkWidget *child = GTK_BIN (widget)->child;
646 GtkRequisition req2 = { 0 };
647 gint border_width = GTK_CONTAINER(widget)->border_width;
651 hildon_window_get_borders (HILDON_WINDOW (widget));
655 gtk_widget_size_request (child, requisition);
657 if (priv->vbox != NULL)
658 gtk_widget_size_request (priv->vbox, &req2);
660 requisition->height += req2.height;
661 requisition->width = MAX (requisition->width, req2.width);
663 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
666 gtk_widget_size_request (priv->edit_toolbar, &req);
667 requisition->height += req.height;
668 requisition->width = MAX (requisition->width, req.width);
671 requisition->width += 2 * border_width;
672 requisition->height += 2 * border_width;
674 if (! priv->fullscreen)
676 requisition->height += priv->borders->top;
677 if (req2.height == 0)
678 requisition->height += priv->borders->bottom;
679 requisition->width += priv->borders->left + priv->borders->right;
684 hildon_window_size_allocate (GtkWidget *widget,
685 GtkAllocation *allocation)
687 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
690 GtkAllocation box_alloc = { 0 };
691 GtkAllocation edittb_alloc = { 0 };
692 GtkAllocation alloc = *allocation;
694 GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
698 hildon_window_get_borders (HILDON_WINDOW (widget));
700 tb = priv->toolbar_borders;
702 widget->allocation = *allocation;
704 /* Calculate allocation of edit toolbar */
705 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
708 gtk_widget_get_child_requisition (priv->edit_toolbar, &req);
709 edittb_alloc.width = alloc.width - tb->left - tb->right;
710 edittb_alloc.height = MIN (req.height, alloc.height);
711 edittb_alloc.x = alloc.x + tb->left;
712 edittb_alloc.y = alloc.y + tb->top;
714 if (edittb_alloc.height > 0)
716 alloc.y += tb->top + tb->bottom + edittb_alloc.height;
717 alloc.height -= tb->top + tb->bottom + edittb_alloc.height;
718 gtk_widget_size_allocate (priv->edit_toolbar, &edittb_alloc);
722 /* Calculate allocation of normal toolbars */
723 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
726 gtk_widget_get_child_requisition (priv->vbox, &req);
727 box_alloc.width = alloc.width - tb->left - tb->right;
728 box_alloc.height = MIN (req.height, alloc.height);
729 box_alloc.x = alloc.x + tb->left;
730 box_alloc.y = alloc.y + alloc.height - box_alloc.height - tb->bottom;
732 if (box_alloc.height > 0)
734 alloc.height -= tb->top + tb->bottom + box_alloc.height;
735 gtk_widget_size_allocate (priv->vbox, &box_alloc);
739 /* Calculate allocation of the child widget */
740 if (child != NULL && GTK_WIDGET_VISIBLE (child))
742 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
743 alloc.x += border_width;
744 alloc.y += border_width;
745 alloc.width -= (border_width * 2);
746 alloc.height -= (border_width * 2);
748 if (! priv->fullscreen)
750 GtkBorder *b = priv->borders;
752 alloc.width -= (b->left + b->right);
754 /* Use the top border if there's no edit toolbar */
755 if (edittb_alloc.height <= 0)
758 alloc.height -= b->top;
761 /* Use the top border if there are no standard toolbars */
762 if (box_alloc.height <= 0)
763 alloc.height -= b->bottom;
766 gtk_widget_size_allocate (child, &alloc);
769 if (priv->previous_vbox_y != box_alloc.y)
771 /* The size of the VBox has changed, we need to redraw part
772 * of the window borders */
773 gint draw_from_y = MIN (priv->previous_vbox_y, box_alloc.y) - tb->top;
775 gtk_widget_queue_draw_area (widget, 0, draw_from_y,
776 widget->allocation.width,
777 widget->allocation.height - draw_from_y);
779 priv->previous_vbox_y = box_alloc.y;
785 hildon_window_forall (GtkContainer *container,
786 gboolean include_internals,
787 GtkCallback callback,
788 gpointer callback_data)
790 HildonWindow *self = HILDON_WINDOW (container);
791 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
793 g_return_if_fail (callback != NULL);
796 GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
797 callback, callback_data);
799 if (include_internals && priv->vbox != NULL)
800 (* callback)(GTK_WIDGET (priv->vbox), callback_data);
802 if (include_internals && priv->edit_toolbar != NULL)
803 (* callback)(GTK_WIDGET (priv->edit_toolbar), callback_data);
807 hildon_window_show_all (GtkWidget *widget)
809 HildonWindow *self = HILDON_WINDOW (widget);
810 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
812 g_assert (priv != NULL);
814 GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
816 gtk_widget_show_all (priv->vbox);
818 if (priv->edit_toolbar)
819 gtk_widget_show_all (priv->edit_toolbar);
823 hildon_window_destroy (GtkObject *obj)
825 HildonWindow *self = HILDON_WINDOW (obj);
826 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (obj);
827 GList *menu_list = NULL;
828 GList *menu_node = NULL;
830 g_assert (priv != NULL);
832 if (priv->vbox != NULL)
836 GtkWidget * common_toolbar =
837 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
838 if (common_toolbar && common_toolbar->parent == priv->vbox)
840 gtk_container_remove (GTK_CONTAINER (priv->vbox),
845 gtk_widget_unparent (priv->vbox);
850 if (priv->edit_toolbar != NULL)
852 gtk_widget_unparent (priv->edit_toolbar);
853 priv->edit_toolbar = NULL;
856 menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
857 menu_node = menu_list;
861 if (GTK_IS_MENU (menu_node->data))
863 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_node->data)))
865 gtk_menu_popdown (GTK_MENU (menu_node->data));
866 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_node->data));
868 gtk_menu_detach (GTK_MENU (menu_node->data));
870 /* Destroy it, but only if it's not a common menu */
872 hildon_program_get_common_menu (priv->program) != menu_node->data) {
873 gtk_object_destroy (GTK_OBJECT (menu_node->data));
874 g_object_unref (menu_node->data);
877 menu_node = menu_node->next;
880 g_list_free (menu_list);
885 hildon_program_remove_window (priv->program, self);
888 gdk_window_remove_filter (gdk_get_default_root_window(),
889 hildon_window_root_window_event_filter,
892 gtk_widget_set_events (GTK_WIDGET(obj), 0);
894 GTK_OBJECT_CLASS (hildon_window_parent_class)->destroy (obj);
898 hildon_window_notify (GObject *gobject,
901 HildonWindow *window = HILDON_WINDOW (gobject);
903 if (g_str_equal (param->name, "is-topmost"))
905 hildon_window_is_topmost_notify (window);
908 if (G_OBJECT_CLASS(hildon_window_parent_class)->notify)
909 G_OBJECT_CLASS(hildon_window_parent_class)->notify (gobject, param);
914 visible_toolbar (gpointer data,
917 if (GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
918 (*((gint *)user_data))++;
922 paint_toolbar (GtkWidget *widget,
924 GdkEventExpose * event,
927 gint toolbar_num = 0;
930 /* collect info to help on painting the boxes */
931 g_list_foreach (box->children, visible_toolbar,
932 (gpointer) &toolbar_num);
937 /*top most toolbar painting*/
938 gtk_paint_box (widget->style, widget->window,
939 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
940 &event->area, widget, "toolbar-primary",
941 widget->allocation.x,
942 GTK_WIDGET(box)->allocation.y,
943 widget->allocation.width,
946 /*multi toolbar painting*/
947 for (count = 0; count < toolbar_num - 1; count++)
949 gtk_paint_box (widget->style, widget->window,
950 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
951 &event->area, widget, "toolbar-secondary",
952 widget->allocation.x,
953 GTK_WIDGET(box)->allocation.y +
954 (1 + count) * (TOOLBAR_HEIGHT),
955 widget->allocation.width,
961 paint_edit_toolbar (GtkWidget *widget,
963 GdkEventExpose *event,
966 if (!GTK_WIDGET_VISIBLE (toolbar))
969 gtk_paint_box (widget->style, widget->window,
970 GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
971 &event->area, widget, "toolbar-edit-mode",
972 toolbar->allocation.x,
973 toolbar->allocation.y,
974 toolbar->allocation.width,
975 toolbar->allocation.height);
979 * Checks the root window to know which is the topped window
982 hildon_window_get_active_window (void)
994 unsigned char *char_pointer;
996 Atom active_app_atom =
997 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1001 gdk_error_trap_push ();
1002 status = XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1003 active_app_atom, 0L, 16L,
1004 0, XA_WINDOW, &realtype, &format,
1005 &n, &extra, &win.char_pointer);
1006 xerror = gdk_error_trap_pop ();
1007 if (xerror || !(status == Success && realtype == XA_WINDOW && format == 32
1008 && n == 1 && win.win != NULL))
1010 if (win.win != NULL)
1011 XFree (win.char_pointer);
1017 if (win.win != NULL)
1018 XFree(win.char_pointer);
1024 xclient_message_type_check (XClientMessageEvent *cm,
1027 return cm->message_type == XInternAtom(GDK_DISPLAY(), name, FALSE);
1031 * Handle the window border custom button, which toggles the menu,
1032 * and the Hildon input method copy paste messages
1034 static GdkFilterReturn
1035 hildon_window_event_filter (GdkXEvent *xevent,
1039 XAnyEvent *eventti = xevent;
1041 if (eventti->type == ClientMessage)
1043 XClientMessageEvent *cm = xevent;
1045 if (xclient_message_type_check (cm, "_MB_GRAB_TRANSFER"))
1047 hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]);
1048 return GDK_FILTER_REMOVE;
1050 /* opera hack clipboard client message */
1051 else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY"))
1053 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1054 HILDON_WINDOW_CO_COPY);
1055 return GDK_FILTER_REMOVE;
1057 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT"))
1059 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1060 HILDON_WINDOW_CO_CUT);
1061 return GDK_FILTER_REMOVE;
1063 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE"))
1065 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1066 HILDON_WINDOW_CO_PASTE);
1067 return GDK_FILTER_REMOVE;
1071 return GDK_FILTER_CONTINUE;
1075 * Here we keep track of changes in the _MB_CURRENT_APP_WINDOW,
1076 * to know when we acquire/lose topmost status
1078 static GdkFilterReturn
1079 hildon_window_root_window_event_filter (GdkXEvent *xevent,
1083 XAnyEvent *eventti = xevent;
1084 HildonWindow *hwindow = HILDON_WINDOW (data);
1086 if (eventti->type == PropertyNotify)
1088 XPropertyEvent *pevent = xevent;
1089 Atom active_app_atom =
1090 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1092 if (pevent->atom == active_app_atom)
1094 Window active_window = hildon_window_get_active_window();
1096 hildon_window_update_topmost (hwindow, active_window);
1100 return GDK_FILTER_CONTINUE;
1104 * Handle the menu hardware key here
1107 hildon_window_key_press_event (GtkWidget *widget,
1110 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1112 g_return_val_if_fail (HILDON_IS_WINDOW (widget),FALSE);
1115 switch (event->keyval)
1117 case HILDON_HARDKEY_MENU:
1118 if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME))
1121 case HILDON_HARDKEY_ESC:
1122 if (!priv->escape_timeout)
1124 priv->escape_timeout = g_timeout_add
1125 (HILDON_WINDOW_LONG_PRESS_TIME,
1126 hildon_window_escape_timeout, widget);
1131 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event);
1135 hildon_window_key_release_event (GtkWidget *widget,
1138 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1140 g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE);
1143 switch (event->keyval)
1145 case HILDON_HARDKEY_ESC:
1146 if (priv->escape_timeout)
1148 g_source_remove (priv->escape_timeout);
1149 priv->escape_timeout = 0;
1154 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event);
1159 * We keep track of the window state changes, because the drawing
1160 * (borders) differs whether we are in fullscreen mode or not
1163 hildon_window_window_state_event (GtkWidget *widget,
1164 GdkEventWindowState *event)
1166 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1167 g_assert (priv != NULL);
1169 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1170 priv->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1172 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event)
1174 return GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event (
1185 * If the window lost focus while the user started to press the ESC key, we
1186 * won't get the release event. We need to stop the timeout.
1189 hildon_window_focus_out_event (GtkWidget *widget,
1190 GdkEventFocus *event)
1192 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1194 if (priv->escape_timeout)
1196 g_source_remove (priv->escape_timeout);
1197 priv->escape_timeout = 0;
1200 return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event);
1204 * The menu popuping needs a menu popup-function
1207 hildon_window_menu_popup_func (GtkMenu *menu,
1215 GdkWindow *window = GTK_WIDGET(widget)->window;
1219 gdk_window_get_origin (window, &window_x, &window_y);
1222 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1223 "vertical-offset", y, NULL);
1225 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1227 *x = GTK_WIDGET (widget)->allocation.width + window_x - GTK_WIDGET (menu)->allocation.width - *x;
1237 hildon_window_menu_popup_func_full (GtkMenu *menu,
1243 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1244 "vertical-offset", y, NULL);
1246 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1247 *x = GTK_WIDGET (widget)->allocation.width - GTK_WIDGET (menu)->allocation.width - *x;
1256 * Takes the common toolbar when we acquire the top-most status
1259 hildon_window_is_topmost_notify (HildonWindow *window)
1261 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1265 if (priv->is_topmost)
1267 hildon_window_take_common_toolbar (window);
1272 * Sets the program to which the window belongs. This should only be called
1273 * by hildon_program_add_window
1275 void G_GNUC_INTERNAL
1276 hildon_window_set_program (HildonWindow *self,
1279 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1281 g_return_if_fail (HILDON_IS_WINDOW (self));
1282 g_assert (priv != NULL);
1286 g_object_unref (priv->program);
1289 /* Now that we are bound to a program, we can rely on it to track the
1291 gdk_window_remove_filter (gdk_get_default_root_window(),
1292 hildon_window_root_window_event_filter,
1295 priv->program = HILDON_PROGRAM (program);
1296 g_object_ref (program);
1300 * Unsets the program to which the window belongs. This should only be called
1301 * by hildon_program_remove_window
1303 void G_GNUC_INTERNAL
1304 hildon_window_unset_program (HildonWindow *self)
1306 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1308 g_return_if_fail(HILDON_IS_WINDOW (self));
1309 g_assert (priv != NULL);
1313 g_object_unref (priv->program);
1314 priv->program = NULL;
1316 /* We need to start tacking the root window again */
1317 gdk_window_set_events (gdk_get_default_root_window (),
1318 gdk_window_get_events (gdk_get_default_root_window ())
1319 | GDK_PROPERTY_CHANGE_MASK);
1321 gdk_window_add_filter (gdk_get_default_root_window (),
1322 hildon_window_root_window_event_filter, self );
1325 priv->program = NULL;
1329 * Sets whether or not the program to which this window belongs is
1330 * killable. This is used by the HildonProgram to signify to the
1331 * Task Navigator whether or not it can hibernate in memory-low situations
1333 void G_GNUC_INTERNAL
1334 hildon_window_set_can_hibernate_property (HildonWindow *self,
1335 gpointer _can_hibernate)
1337 GdkAtom killable_atom;
1338 gboolean can_hibernate;
1340 g_return_if_fail(self && HILDON_IS_WINDOW (self));
1342 if (!GTK_WIDGET_REALIZED ((GTK_WIDGET (self))))
1347 can_hibernate = * ((gboolean *)_can_hibernate);
1349 killable_atom = gdk_atom_intern (CAN_HIBERNATE_PROPERTY, FALSE);
1353 gdk_property_change (GTK_WIDGET (self)->window, killable_atom,
1354 (GdkAtom)31/* XA_STRING */, 8,
1355 GDK_PROP_MODE_REPLACE, (const guchar *)CAN_HIBERNATE,
1356 CAN_HIBERNATE_LENGTH);
1360 gdk_property_delete (GTK_WIDGET (self)->window, killable_atom);
1366 * If a common toolbar was set to the program, reparent it to
1369 void G_GNUC_INTERNAL
1370 hildon_window_take_common_toolbar (HildonWindow *self)
1372 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1374 g_return_if_fail(HILDON_IS_WINDOW (self));
1379 GtkWidget *common_toolbar =
1380 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
1382 if (common_toolbar && common_toolbar->parent != priv->vbox)
1384 g_object_ref (common_toolbar);
1385 if (common_toolbar->parent)
1387 gtk_container_remove (GTK_CONTAINER (common_toolbar->parent),
1391 gtk_box_pack_end (GTK_BOX(priv->vbox), common_toolbar,
1393 g_object_unref (common_toolbar);
1395 gtk_widget_set_size_request (common_toolbar, -1, TOOLBAR_HEIGHT);
1397 gtk_widget_show (priv->vbox);
1404 * Compare the window that was last topped, and act consequently
1407 hildon_window_update_topmost (HildonWindow *self,
1410 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1412 GdkWindow *my_window;
1414 g_return_if_fail (HILDON_IS_WINDOW (self));
1417 my_window = GTK_WIDGET (self)->window;
1419 if (my_window && window_id == GDK_WINDOW_XID (my_window))
1421 if (! priv->is_topmost)
1423 priv->is_topmost = TRUE;
1424 hildon_window_is_topmost_notify (self);
1425 g_object_notify (G_OBJECT (self), "is-topmost");
1428 else if (priv->is_topmost)
1430 /* Should this go in the signal handler? */
1431 GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (self));
1433 if (GTK_IS_ENTRY (focus))
1434 gtk_im_context_focus_out (GTK_ENTRY (focus)->im_context);
1435 if (GTK_IS_TEXT_VIEW (focus))
1436 gtk_im_context_focus_out (GTK_TEXT_VIEW (focus)->im_context);
1438 priv->is_topmost = FALSE;
1439 hildon_window_is_topmost_notify (self);
1440 g_object_notify (G_OBJECT (self), "is-topmost");
1445 detach_menu_func (GtkWidget *attach_widget,
1448 /* FIXME Why is this even needed here? */
1452 hildon_window_toggle_menu (HildonWindow *self,
1456 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1458 if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
1460 return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
1470 * Toggles the display of the HildonWindow menu.
1471 * Returns whether or not something was done (whether or not we had a menu
1475 hildon_window_toggle_menu_real (HildonWindow * self,
1479 GtkMenu *menu_to_use = NULL;
1480 GList *menu_children = NULL;
1481 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1483 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1484 g_assert (priv != NULL);
1486 /* Select which menu to use, Window specific has highest priority,
1487 * then program specific */
1490 menu_to_use = GTK_MENU (priv->menu);
1492 else if (priv->program)
1494 menu_to_use = hildon_program_get_common_menu (priv->program);
1495 if (menu_to_use && gtk_menu_get_attach_widget (menu_to_use) !=
1498 g_object_ref (menu_to_use);
1499 if (gtk_menu_get_attach_widget (menu_to_use))
1501 gtk_menu_detach (menu_to_use);
1504 gtk_menu_attach_to_widget (menu_to_use, GTK_WIDGET (self),
1506 g_object_unref (menu_to_use);
1516 if (GTK_WIDGET_MAPPED (GTK_WIDGET (menu_to_use)))
1518 gtk_menu_popdown (menu_to_use);
1519 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_to_use));
1523 /* Check if the menu has items */
1524 menu_children = gtk_container_get_children (GTK_CONTAINER (menu_to_use));
1528 g_list_free (menu_children);
1530 /* Apply right theming */
1531 gtk_widget_set_name (GTK_WIDGET (menu_to_use),
1532 "menu_force_with_corners");
1534 if (priv->fullscreen)
1536 gtk_menu_popup (menu_to_use, NULL, NULL,
1537 (GtkMenuPositionFunc)
1538 hildon_window_menu_popup_func_full,
1539 self, button, time);
1543 gtk_menu_popup (menu_to_use, NULL, NULL,
1544 (GtkMenuPositionFunc)
1545 hildon_window_menu_popup_func,
1546 self, button, time);
1548 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_to_use), TRUE);
1556 * If the ESC key was not released when the timeout expires,
1560 hildon_window_escape_timeout (gpointer data)
1562 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data);
1567 GDK_THREADS_ENTER ();
1569 /* Send fake event, simulation a situation that user
1570 pressed 'x' from the corner */
1571 event = gdk_event_new(GDK_DELETE);
1572 ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window));
1573 gtk_main_do_event(event);
1575 /* That unrefs the window, so we're reffing it above */
1576 gdk_event_free(event);
1578 priv->escape_timeout = 0;
1580 GDK_THREADS_LEAVE ();
1586 * hildon_window_new:
1588 * Creates a new HildonWindow.
1590 * Return value: A @HildonWindow.
1593 hildon_window_new (void)
1595 HildonWindow *newwindow = g_object_new (HILDON_TYPE_WINDOW, NULL);
1597 return GTK_WIDGET (newwindow);
1601 * hildon_window_add_with_scrollbar
1602 * @self : A @HildonWindow
1603 * @child : A @GtkWidget
1605 * Adds the @child to the HildonWindow and creates a scrollbar
1606 * for it. Similar as adding first a @GtkScrolledWindow and then the
1610 hildon_window_add_with_scrollbar (HildonWindow *self,
1613 GtkScrolledWindow *scrolledw;
1615 g_return_if_fail (HILDON_IS_WINDOW (self));
1616 g_return_if_fail (GTK_IS_WIDGET (child));
1617 g_return_if_fail (child->parent == NULL);
1619 scrolledw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1620 gtk_scrolled_window_set_policy (scrolledw, GTK_POLICY_NEVER,
1621 GTK_POLICY_AUTOMATIC);
1622 gtk_scrolled_window_set_shadow_type (scrolledw, GTK_SHADOW_NONE);
1624 if (GTK_IS_VIEWPORT (child))
1625 gtk_container_add (GTK_CONTAINER (scrolledw), child);
1628 if (GTK_IS_CONTAINER (child) )
1629 gtk_container_set_focus_vadjustment (GTK_CONTAINER(child),
1630 gtk_scrolled_window_get_vadjustment (scrolledw) );
1631 gtk_scrolled_window_add_with_viewport (scrolledw, child);
1634 gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (scrolledw));
1638 calculate_visible_toolbars (gpointer data,
1641 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (((GtkBoxChild *)data)->widget)))
1642 (*((gint *)user_data)) ++;
1646 toolbar_visible_notify (GtkWidget *toolbar, GParamSpec *pspec,
1647 HildonWindow *window)
1649 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1653 /* Recalculate from scratch the value just in case */
1654 priv->visible_toolbars = 0;
1656 g_list_foreach (GTK_BOX (priv->vbox)->children, calculate_visible_toolbars,
1657 &priv->visible_toolbars);
1659 if (priv->visible_toolbars == 0)
1660 gtk_widget_hide (priv->vbox);
1662 gtk_widget_show (priv->vbox);
1666 * hildon_window_add_toolbar:
1667 * @self: A @HildonWindow
1668 * @toolbar: A #GtkToolbar to add to the HildonWindow
1670 * Adds a toolbar to the window. Note that the toolbar is not automatically
1671 * shown. You need to call #gtk_widget_show_all on it to make it visible.
1672 * It's also possible to hide the toolbar (without removing it) by calling
1676 hildon_window_add_toolbar (HildonWindow *self,
1677 GtkToolbar *toolbar)
1680 HildonWindowPrivate *priv;
1682 g_return_if_fail (HILDON_IS_WINDOW (self));
1683 g_return_if_fail (toolbar && GTK_IS_TOOLBAR (toolbar));
1685 priv = HILDON_WINDOW_GET_PRIVATE (self);
1687 vbox = GTK_BOX (priv->vbox);
1689 gtk_box_pack_start (vbox, GTK_WIDGET (toolbar), TRUE, TRUE, 0);
1690 gtk_box_reorder_child (vbox, GTK_WIDGET (toolbar), 0);
1691 gtk_widget_set_size_request (GTK_WIDGET (toolbar), -1, TOOLBAR_HEIGHT);
1693 g_signal_connect (G_OBJECT (toolbar), "notify::visible",
1694 G_CALLBACK (toolbar_visible_notify), self);
1696 if (GTK_WIDGET_VISIBLE (toolbar))
1698 priv->visible_toolbars++;
1699 gtk_widget_show (priv->vbox);
1702 gtk_widget_queue_resize (GTK_WIDGET (self));
1706 * hildon_window_remove_toolbar:
1707 * @self: A @HildonWindow
1708 * @toolbar: A #GtkToolbar to remove from the HildonWindow
1710 * Removes a toolbar from the window. Note that this decreases the refference
1711 * count on the widget. If you want to keep the toolbar alive call #g_object_ref
1712 * before calling this function.
1715 hildon_window_remove_toolbar (HildonWindow *self,
1716 GtkToolbar *toolbar)
1718 HildonWindowPrivate *priv;
1720 g_return_if_fail (HILDON_IS_WINDOW (self));
1722 priv = HILDON_WINDOW_GET_PRIVATE (self);
1724 if (GTK_WIDGET_VISIBLE (toolbar))
1726 if (--(priv->visible_toolbars) == 0)
1727 gtk_widget_hide (priv->vbox);
1730 g_signal_handlers_disconnect_by_func (toolbar, toolbar_visible_notify, self);
1732 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (toolbar));
1736 * hildon_window_set_edit_toolbar:
1737 * @self: A #HildonWindow
1738 * @toolbar: A #HildonEditToolbar, or %NULL to remove the current one.
1740 * Adds a #HildonEditToolbar to the window. Note that the toolbar is
1741 * not automatically shown. You need to call gtk_widget_show() on it
1742 * to make it visible. It's also possible to hide the toolbar (without
1743 * removing it) by calling gtk_widget_hide().
1745 * A window can only have at most one edit toolbar at a time, so the
1746 * previous toolbar (if any) is replaced after calling this function.
1749 hildon_window_set_edit_toolbar (HildonWindow *self,
1750 HildonEditToolbar *toolbar)
1752 HildonWindowPrivate *priv;
1754 g_return_if_fail (HILDON_IS_WINDOW (self));
1755 g_return_if_fail (toolbar == NULL || HILDON_IS_EDIT_TOOLBAR (toolbar));
1757 priv = HILDON_WINDOW_GET_PRIVATE (self);
1759 if (priv->edit_toolbar != GTK_WIDGET (toolbar))
1761 GtkWidget *old_toolbar = priv->edit_toolbar;
1762 priv->edit_toolbar = GTK_WIDGET (toolbar);
1764 if (priv->edit_toolbar)
1765 gtk_widget_set_parent (priv->edit_toolbar, GTK_WIDGET (self));
1768 gtk_widget_unparent (old_toolbar);
1773 * hildon_window_get_menu:
1774 * @self : #HildonWindow
1776 * Gets the #GtMenu assigned to the #HildonAppview. Note that the
1777 * window is still the owner of the menu.
1779 * Return value: The #GtkMenu assigned to this application view.
1782 hildon_window_get_menu (HildonWindow * self)
1784 HildonWindowPrivate *priv;
1786 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
1788 priv = HILDON_WINDOW_GET_PRIVATE (self);
1790 return GTK_MENU (priv->menu);
1793 /* Since we've been asking developers to call gtk_window_add_accel_group()
1794 * themselves, do not trigger criticals by trying it again.
1797 hildon_window_add_accel_group (HildonWindow *self,
1798 GtkAccelGroup *accel_group)
1802 groups = gtk_accel_groups_from_object (G_OBJECT (self));
1803 for (l = groups; l != NULL; l = l->next)
1804 if (l->data == (gpointer)accel_group)
1805 /* Maybe print a warning here? */
1808 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
1812 * hildon_window_set_main_menu:
1813 * @self: A #HildonWindow
1814 * @menu: The #GtkMenu to be used for this #HildonWindow
1816 * Sets the menu to be used for this window. This menu overrides
1817 * a program-wide menu that may have been set with
1818 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1819 * menu. #HildonWindow takes ownership of the passed menu and you're
1820 * not supposed to free it yourself anymore.
1822 * Note that if you're using a #HildonStackableWindow (and not just a
1823 * standard #HildonWindow) you should use
1824 * hildon_stackable_window_set_main_menu()
1825 * instead. #HildonStackableWindow uses #HildonAppMenu rather than
1831 hildon_window_set_main_menu (HildonWindow* self,
1834 HildonWindowPrivate *priv;
1835 GtkAccelGroup *accel_group;
1837 g_return_if_fail (HILDON_IS_WINDOW (self));
1839 priv = HILDON_WINDOW_GET_PRIVATE (self);
1841 if (priv->menu != NULL)
1843 accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
1844 if (accel_group != NULL)
1845 gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
1847 gtk_menu_detach (GTK_MENU (priv->menu));
1848 g_object_unref (priv->menu);
1851 priv->menu = (menu != NULL) ? GTK_WIDGET (menu) : NULL;
1852 if (priv->menu != NULL)
1854 gtk_widget_set_name (priv->menu, "menu_force_with_corners");
1855 gtk_menu_attach_to_widget (GTK_MENU (priv->menu), GTK_WIDGET (self), &detach_menu_func);
1856 g_object_ref (GTK_MENU (priv->menu));
1858 accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
1859 if (accel_group != NULL)
1860 hildon_window_add_accel_group (self, accel_group);
1865 * hildon_window_set_menu:
1866 * @self: A #HildonWindow
1867 * @menu: The #GtkMenu to be used for this #HildonWindow
1869 * Sets the menu to be used for this window. This menu overrides
1870 * a program-wide menu that may have been set with
1871 * hildon_program_set_common_menu. Pass NULL to remove the current
1872 * menu. HildonWindow takes ownership of the passed menu and you're
1873 * not supposed to free it yourself anymore.
1875 * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the
1876 * #GtkMenu. To pass control about visibility to the application
1877 * developer, hildon_window_set_main_menu() was introduced, which
1880 * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
1883 hildon_window_set_menu (HildonWindow *self,
1886 HildonWindowPrivate *priv;
1888 g_return_if_fail (HILDON_IS_WINDOW (self));
1890 hildon_window_set_main_menu (self, menu);
1892 priv = HILDON_WINDOW_GET_PRIVATE (self);
1894 if (priv->menu != NULL)
1895 gtk_widget_show_all (GTK_WIDGET (priv->menu));
1899 * hildon_window_get_is_topmost:
1900 * @self: A #HildonWindow
1902 * Returns whether the #HildonWindow is currenty activated by the
1905 * Return value: %TRUE if @self is currently activated, %FALSE otherwise.
1908 hildon_window_get_is_topmost (HildonWindow *self)
1910 HildonWindowPrivate *priv;
1912 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1914 priv = HILDON_WINDOW_GET_PRIVATE (self);
1915 return priv->is_topmost;