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: Top-level window in the Hildon framework.
28 * @see_also: #HildonProgram, #HildonStackableWindow
30 * #HildonWindow is a top-level
31 * window in the Hildon framework. It is derived from #GtkWindow
32 * and provides additional commodities specific to the Hildon
35 * #HildonWindow<!-- -->s can have a menu attached, which is toggled
36 * with a hardware key or by tapping on the window frame. This menu
37 * can be either a #GtkMenu or a #HildonAppMenu (set with
38 * hildon_window_set_main_menu() and hildon_window_set_app_menu()
39 * respectively). Only one type of menu can be used at the same time.
40 * In Hildon 2.2, #HildonAppMenu is the recommended menu to use.
42 * Similarly, a #HildonWindow can have several toolbars
43 * attached. These can be added with hildon_window_add_toolbar(). In
44 * addition to those, a #HildonWindow can also have a
45 * #HildonEditToolbar. To add it to the window use
46 * hildon_window_set_edit_toolbar().
49 * <title>Creating a HildonWindow</title>
51 * HildonWindow *window;
52 * GtkToolbar *toolbar;
53 * HildonAppMenu *menu;
54 * GdkPixbuf *icon_pixbuf;
56 * window = HILDON_WINDOW (hildon_window_new());
58 * toolbar = create_toolbar();
60 * menu = create_menu();
62 * icon_pixbuf = create_icon();
64 * hildon_window_set_app_menu (window, menu);
66 * hildon_window_add_toolbar (window, toolbar);
68 * // Can be used to set the window fullscreen
69 * gtk_window_fullscreen (GTK_WINDOW (window));
71 * // Used to trigger the blinking of the window's icon in the task navigator
72 * gtk_window_set_urgency_hint (GTK_WINDOW (window), TRUE);
74 * // Change the window's icon in the task navigator
75 * gtk_window_set_icon (GTK_WINDOW (window), icon_pixbuf);
80 #undef HILDON_DISABLE_DEPRECATED
88 #include <X11/Xatom.h>
89 #include <gdk/gdkkeysyms.h>
91 #include <gtk/gtkprivate.h>
93 #include "hildon-window.h"
94 #include "hildon-window-private.h"
95 #include "hildon-app-menu-private.h"
96 #include "hildon-find-toolbar.h"
97 #include "hildon-defines.h"
98 #include "hildon-private.h"
100 #define _(String) gettext(String)
102 #define TOOLBAR_HEIGHT 70
104 #define TOOLBAR_MIDDLE 0
107 #define CAN_HIBERNATE "CANKILL"
109 #define CAN_HIBERNATE_LENGTH 7
111 #define CAN_HIBERNATE_PROPERTY "_HILDON_ABLE_TO_HIBERNATE"
113 #define LEGACY_MENU_PROPERTY_NAME "_HILDON_WM_WINDOW_TYPE"
114 #define LEGACY_MENU_PROPERTY_VALUE "_HILDON_WM_WINDOW_TYPE_LEGACY_MENU"
116 #define TITLE_SEPARATOR " - "
118 typedef void (*HildonWindowSignal) (HildonWindow *, gint, gpointer);
121 hildon_window_init (HildonWindow * self);
124 hildon_window_class_init (HildonWindowClass * window_class);
127 hildon_window_menu_popup_func (GtkMenu *menu,
133 hildon_window_menu_popup_func_full (GtkMenu *menu,
139 hildon_window_expose (GtkWidget *widget,
140 GdkEventExpose *event);
142 hildon_window_forall (GtkContainer *container,
143 gboolean include_internals,
144 GtkCallback callback,
145 gpointer callback_data);
147 hildon_window_show_all (GtkWidget *widget);
150 hildon_window_size_allocate (GtkWidget * widget,
151 GtkAllocation *allocation);
153 hildon_window_size_request (GtkWidget * widget,
154 GtkRequisition *requisition);
156 hildon_window_finalize (GObject *obj_self);
159 hildon_window_get_property (GObject *object,
165 hildon_window_set_property (GObject *object,
171 hildon_window_update_markup (HildonWindow *window);
174 hildon_window_destroy (GtkObject *obj);
177 hildon_window_realize (GtkWidget *widget);
180 hildon_window_unrealize (GtkWidget *widget);
183 hildon_window_map (GtkWidget *widget);
186 hildon_window_unmap (GtkWidget *widget);
189 hildon_window_key_press_event (GtkWidget *widget,
193 hildon_window_key_release_event (GtkWidget *widget,
196 hildon_window_window_state_event (GtkWidget *widget,
197 GdkEventWindowState *event);
199 hildon_window_focus_out_event (GtkWidget *widget,
200 GdkEventFocus *event);
203 hildon_window_notify (GObject *gobject,
207 hildon_window_is_topmost_notify (HildonWindow *window);
210 hildon_window_toggle_menu (HildonWindow * self,
215 hildon_window_toggle_menu_real (HildonWindow * self,
220 hildon_window_escape_timeout (gpointer data);
222 static GdkFilterReturn
223 hildon_window_event_filter (GdkXEvent *xevent,
227 static GdkFilterReturn
228 hildon_window_root_window_event_filter (GdkXEvent *xevent,
233 hildon_window_get_borders (HildonWindow *window);
236 visible_toolbar (gpointer data,
240 paint_toolbar (GtkWidget *widget,
242 GdkEventExpose * event,
243 gboolean fullscreen);
246 paint_edit_toolbar (GtkWidget *widget,
248 GdkEventExpose *event,
249 gboolean fullscreen);
265 G_DEFINE_TYPE (HildonWindow, hildon_window, GTK_TYPE_WINDOW);
268 hildon_window_class_init (HildonWindowClass * window_class)
270 /* Get convenience variables */
271 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (window_class);
272 GObjectClass *object_class = G_OBJECT_CLASS (window_class);
273 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (window_class);
275 object_class->get_property = hildon_window_get_property;
276 object_class->set_property = hildon_window_set_property;
277 object_class->notify = hildon_window_notify;
278 widget_class->size_allocate = hildon_window_size_allocate;
279 widget_class->size_request = hildon_window_size_request;
280 widget_class->expose_event = hildon_window_expose;
281 widget_class->show_all = hildon_window_show_all;
282 widget_class->realize = hildon_window_realize;
283 widget_class->unrealize = hildon_window_unrealize;
284 widget_class->key_press_event = hildon_window_key_press_event;
285 widget_class->key_release_event = hildon_window_key_release_event;
286 widget_class->window_state_event = hildon_window_window_state_event;
287 widget_class->focus_out_event = hildon_window_focus_out_event;
288 widget_class->map = hildon_window_map;
289 widget_class->unmap = hildon_window_unmap;
291 /* now the object stuff */
292 object_class->finalize = hildon_window_finalize;
294 /* To the container */
295 container_class->forall = hildon_window_forall;
298 window_class->toggle_menu = hildon_window_toggle_menu_real;
301 GTK_OBJECT_CLASS (window_class)->destroy = hildon_window_destroy;
303 g_type_class_add_private (window_class,
304 sizeof (struct _HildonWindowPrivate));
306 /* Install properties */
308 g_object_class_install_property (object_class, PROP_IS_TOPMOST,
309 g_param_spec_boolean ("is-topmost",
311 "Whether the window is currently activated by the window "
316 g_object_class_install_property (object_class, PROP_MARKUP,
317 g_param_spec_string ("markup",
318 "Marked up text for the window title",
319 "Marked up text for the window title",
323 gtk_widget_class_install_style_property (widget_class,
324 g_param_spec_boxed ("borders",
326 "Size of graphical window borders",
330 gtk_widget_class_install_style_property (widget_class,
331 g_param_spec_boxed ("toolbar-borders",
332 "Graphical toolbar borders",
333 "Size of graphical toolbar borders",
337 /* opera hack, install clip operation signal */
338 g_signal_new ("clipboard_operation",
339 G_OBJECT_CLASS_TYPE (object_class),
341 G_STRUCT_OFFSET (HildonWindowClass, clipboard_operation),
343 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1,
348 hildon_window_init (HildonWindow *self)
350 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
351 g_assert (priv != NULL);
353 priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
354 gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
356 priv->app_menu = NULL;
357 priv->edit_toolbar = NULL;
358 priv->visible_toolbars = 0;
359 priv->is_topmost = FALSE;
360 priv->borders = NULL;
361 priv->toolbar_borders = NULL;
362 priv->escape_timeout = 0;
365 priv->fullscreen = FALSE;
367 priv->program = NULL;
369 /* We need to track the root window _MB_CURRENT_APP_WINDOW property */
370 gdk_window_set_events (gdk_get_default_root_window (),
371 gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK);
373 gdk_window_add_filter (gdk_get_default_root_window (),
374 hildon_window_root_window_event_filter, self);
378 hildon_window_finalize (GObject * obj_self)
380 HildonWindowPrivate *priv;
382 g_return_if_fail (HILDON_WINDOW (obj_self));
384 priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
385 g_assert (priv != NULL);
387 g_free (priv->markup);
389 if (priv->escape_timeout) {
390 g_source_remove (priv->escape_timeout);
391 priv->escape_timeout = 0;
395 gtk_border_free (priv->borders);
397 if (priv->toolbar_borders)
398 gtk_border_free (priv->toolbar_borders);
400 if (G_OBJECT_CLASS (hildon_window_parent_class)->finalize)
401 G_OBJECT_CLASS (hildon_window_parent_class)->finalize (obj_self);
406 hildon_window_realize (GtkWidget *widget)
408 Atom *old_atoms, *new_atoms;
412 Window active_window;
413 HildonWindowPrivate *priv;
415 GTK_WIDGET_CLASS (hildon_window_parent_class)->realize (widget);
417 priv = HILDON_WINDOW_GET_PRIVATE (widget);
418 g_assert (priv != NULL);
420 gtk_widget_realize (GTK_WIDGET (priv->vbox));
422 if (priv->edit_toolbar != NULL)
423 gtk_widget_realize (priv->edit_toolbar);
425 /* catch the custom button signal from mb to display the menu */
426 gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
428 window = GDK_WINDOW_XID (widget->window);
429 disp = GDK_WINDOW_XDISPLAY (widget->window);
431 /* Enable custom button that is used for menu */
432 XGetWMProtocols (disp, window, &old_atoms, &atom_count);
433 new_atoms = g_new (Atom, atom_count + 1);
435 memcpy (new_atoms, old_atoms, sizeof(Atom) * atom_count);
437 new_atoms[atom_count++] =
438 XInternAtom (disp, "_NET_WM_CONTEXT_CUSTOM", False);
440 XSetWMProtocols (disp, window, new_atoms, atom_count);
445 /* rely on GDK to set the window group to its default */
446 gdk_window_set_group (widget->window, NULL);
449 gboolean can_hibernate = hildon_program_get_can_hibernate (priv->program);
451 hildon_window_set_can_hibernate_property (HILDON_WINDOW (widget),
456 hildon_window_update_markup (HILDON_WINDOW (widget));
458 /* Update the topmost status */
459 active_window = hildon_window_get_active_window();
460 hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
464 hildon_window_unrealize (GtkWidget *widget)
466 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
467 g_assert (priv != NULL);
469 gdk_window_remove_filter (widget->window, hildon_window_event_filter,
472 gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
474 if (priv->edit_toolbar != NULL)
475 gtk_widget_unrealize (priv->edit_toolbar);
477 GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
481 hildon_window_map (GtkWidget *widget)
483 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
484 g_assert (priv != NULL);
486 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->map)
487 GTK_WIDGET_CLASS (hildon_window_parent_class)->map (widget);
489 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
490 gtk_widget_map (priv->vbox);
492 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
493 gtk_widget_map (priv->edit_toolbar);
497 hildon_window_unmap (GtkWidget *widget)
499 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
500 g_assert (priv != NULL);
502 gtk_widget_unmap (priv->vbox);
504 if (priv->edit_toolbar != NULL)
505 gtk_widget_unmap (priv->edit_toolbar);
507 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
508 GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
512 hildon_window_get_property (GObject *object,
517 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (object);
518 g_assert (priv != NULL);
520 switch (property_id) {
522 case PROP_IS_TOPMOST:
523 g_value_set_boolean (value, priv->is_topmost);
527 g_value_set_string (value, priv->markup);
531 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
537 hildon_window_set_property (GObject *object,
542 switch (property_id) {
545 hildon_window_set_markup (HILDON_WINDOW (object), g_value_get_string (value));
549 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
555 * Retrieve the graphical borders size used by the themes
558 hildon_window_get_borders (HildonWindow *window)
560 GtkBorder zero = {0, 0, 0, 0};
561 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
564 GtkBorder *borders = NULL;
565 GtkBorder *toolbar_borders = NULL;
568 gtk_border_free (priv->borders);
569 if (priv->toolbar_borders)
570 gtk_border_free (priv->toolbar_borders);
572 priv->borders = NULL;
573 priv->toolbar_borders = NULL;
575 gtk_widget_style_get (GTK_WIDGET (window), "borders",&borders,
576 "toolbar-borders", &toolbar_borders,
579 // We're doing a copy here instead of reusing the pointer,
580 // as we don't know where it comes from (has it been allocated using
581 // malloc or slices... and we want to free it sanely. Blowing on
585 priv->borders = gtk_border_copy (borders);
586 gtk_border_free (borders);
588 priv->borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
590 if (toolbar_borders) {
591 priv->toolbar_borders = gtk_border_copy (toolbar_borders);
592 gtk_border_free (toolbar_borders);
594 priv->toolbar_borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
598 hildon_window_expose (GtkWidget *widget,
599 GdkEventExpose * event)
601 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
604 GtkWidget *bx = priv->vbox;
605 GtkBox *box = GTK_BOX(bx);
606 GtkBorder *b = priv->borders;
607 GtkBorder *tb = priv->toolbar_borders;
610 if (! priv->borders) {
611 hildon_window_get_borders (HILDON_WINDOW (widget));
613 tb = priv->toolbar_borders;
616 tb_height = bx->allocation.height + tb->top + tb->bottom;
618 paint_toolbar (widget, box,
619 event, priv->fullscreen);
621 if (priv->edit_toolbar != NULL)
623 paint_edit_toolbar (widget, priv->edit_toolbar,
624 event, priv->fullscreen);
627 if (! priv->fullscreen) {
629 /* Draw the left and right window border */
630 gint side_borders_height = widget->allocation.height - b->top;
632 if (priv->visible_toolbars)
633 side_borders_height -= tb_height;
635 side_borders_height -= b->bottom;
639 gtk_paint_box (widget->style, widget->window,
640 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
641 &event->area, widget, "left-border",
642 widget->allocation.x, widget->allocation.y +
643 b->top, b->left, side_borders_height);
648 gtk_paint_box (widget->style, widget->window,
649 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
650 &event->area, widget, "right-border",
651 widget->allocation.x + widget->allocation.width -
652 b->right, widget->allocation.y + b->top,
653 b->right, side_borders_height);
656 /* If no toolbar, draw the bottom window border */
657 if (! priv->visible_toolbars && b->bottom > 0)
659 gtk_paint_box (widget->style, widget->window,
660 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
661 &event->area, widget, "bottom-border",
662 widget->allocation.x, widget->allocation.y +
663 (widget->allocation.height - b->bottom),
664 widget->allocation.width, b->bottom);
667 /* Draw the top border */
670 gtk_paint_box (widget->style, widget->window,
671 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
672 &event->area, widget, "top-border",
673 widget->allocation.x, widget->allocation.y,
674 widget->allocation.width, b->top);
680 /* don't draw the window stuff as it overwrites our borders with a blank
681 * rectangle. Instead start with the drawing of the GtkBin */
682 GTK_WIDGET_CLASS (g_type_class_peek_parent (hildon_window_parent_class))->expose_event (widget, event);
684 /* FIXME Not sure why this is commented out
685 * GTK_WIDGET_CLASS (hildon_window_parent_class))->
686 * expose_event (widget, event);
693 hildon_window_size_request (GtkWidget *widget,
694 GtkRequisition *requisition)
696 GdkScreen *screen = gtk_widget_get_screen (widget);
697 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
702 child = gtk_bin_get_child (GTK_BIN (widget));
704 if (child != NULL && GTK_WIDGET_VISIBLE (child))
705 gtk_widget_size_request (child, &req);
707 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
708 gtk_widget_size_request (priv->vbox, &req);
710 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
711 gtk_widget_size_request (priv->edit_toolbar, &req);
713 /* Request the full size of the screen */
714 requisition->width = gdk_screen_get_width (screen);
715 requisition->height = gdk_screen_get_height (screen);
717 if (! priv->fullscreen)
718 requisition->height -= HILDON_WINDOW_TITLEBAR_HEIGHT;
722 hildon_window_size_allocate (GtkWidget *widget,
723 GtkAllocation *allocation)
725 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
728 GtkAllocation box_alloc = { 0 };
729 GtkAllocation edittb_alloc = { 0 };
730 GtkAllocation alloc = *allocation;
732 GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
736 hildon_window_get_borders (HILDON_WINDOW (widget));
738 tb = priv->toolbar_borders;
740 widget->allocation = *allocation;
742 /* Calculate allocation of edit toolbar */
743 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
746 gtk_widget_get_child_requisition (priv->edit_toolbar, &req);
747 edittb_alloc.width = alloc.width - tb->left - tb->right;
748 edittb_alloc.height = MIN (req.height, alloc.height);
749 edittb_alloc.x = alloc.x + tb->left;
750 edittb_alloc.y = alloc.y + tb->top;
752 if (edittb_alloc.height > 0)
754 alloc.y += tb->top + tb->bottom + edittb_alloc.height;
755 alloc.height -= tb->top + tb->bottom + edittb_alloc.height;
756 gtk_widget_size_allocate (priv->edit_toolbar, &edittb_alloc);
760 /* Calculate allocation of normal toolbars */
761 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
764 gtk_widget_get_child_requisition (priv->vbox, &req);
765 box_alloc.width = alloc.width - tb->left - tb->right;
766 box_alloc.height = MIN (req.height, alloc.height);
767 box_alloc.x = alloc.x + tb->left;
768 box_alloc.y = alloc.y + alloc.height - box_alloc.height - tb->bottom;
770 if (box_alloc.height > 0)
772 alloc.height -= tb->top + tb->bottom + box_alloc.height;
773 gtk_widget_size_allocate (priv->vbox, &box_alloc);
777 /* Calculate allocation of the child widget */
778 if (child != NULL && GTK_WIDGET_VISIBLE (child))
780 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
781 alloc.x += border_width;
782 alloc.y += border_width;
783 alloc.width -= (border_width * 2);
784 alloc.height -= (border_width * 2);
786 if (! priv->fullscreen)
788 GtkBorder *b = priv->borders;
790 alloc.width -= (b->left + b->right);
792 /* Use the top border if there's no edit toolbar */
793 if (edittb_alloc.height <= 0)
796 alloc.height -= b->top;
799 /* Use the top border if there are no standard toolbars */
800 if (box_alloc.height <= 0)
801 alloc.height -= b->bottom;
804 gtk_widget_size_allocate (child, &alloc);
807 if (priv->previous_vbox_y != box_alloc.y)
809 /* The size of the VBox has changed, we need to redraw part
810 * of the window borders */
811 gint draw_from_y = MIN (priv->previous_vbox_y, box_alloc.y) - tb->top;
813 gtk_widget_queue_draw_area (widget, 0, draw_from_y,
814 widget->allocation.width,
815 widget->allocation.height - draw_from_y);
817 priv->previous_vbox_y = box_alloc.y;
823 hildon_window_forall (GtkContainer *container,
824 gboolean include_internals,
825 GtkCallback callback,
826 gpointer callback_data)
828 HildonWindow *self = HILDON_WINDOW (container);
829 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
831 g_return_if_fail (callback != NULL);
834 GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
835 callback, callback_data);
837 if (include_internals && priv->vbox != NULL)
838 (* callback)(GTK_WIDGET (priv->vbox), callback_data);
840 if (include_internals && priv->edit_toolbar != NULL)
841 (* callback)(GTK_WIDGET (priv->edit_toolbar), callback_data);
845 hildon_window_show_all (GtkWidget *widget)
847 HildonWindow *self = HILDON_WINDOW (widget);
848 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
850 g_assert (priv != NULL);
852 GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
854 gtk_widget_show_all (priv->vbox);
856 if (priv->edit_toolbar)
857 gtk_widget_show_all (priv->edit_toolbar);
861 hildon_window_destroy (GtkObject *obj)
863 HildonWindow *self = HILDON_WINDOW (obj);
864 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (obj);
865 GList *menu_list = NULL;
866 GList *menu_node = NULL;
868 g_assert (priv != NULL);
870 if (priv->vbox != NULL)
874 GtkWidget * common_toolbar =
875 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
876 if (common_toolbar && common_toolbar->parent == priv->vbox)
878 gtk_container_remove (GTK_CONTAINER (priv->vbox),
883 gtk_widget_unparent (priv->vbox);
888 if (priv->edit_toolbar != NULL)
890 gtk_widget_unparent (priv->edit_toolbar);
891 priv->edit_toolbar = NULL;
896 hildon_app_menu_set_parent_window (priv->app_menu, NULL);
897 g_object_unref (priv->app_menu);
898 priv->app_menu = NULL;
901 menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
902 menu_node = menu_list;
906 if (GTK_IS_MENU (menu_node->data))
908 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_node->data)))
910 gtk_menu_popdown (GTK_MENU (menu_node->data));
911 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_node->data));
913 gtk_menu_detach (GTK_MENU (menu_node->data));
915 /* Destroy it, but only if it's not a common menu */
917 hildon_program_get_common_menu (priv->program) != menu_node->data) {
918 gtk_object_destroy (GTK_OBJECT (menu_node->data));
919 g_object_unref (menu_node->data);
922 menu_node = menu_node->next;
925 g_list_free (menu_list);
930 hildon_program_remove_window (priv->program, self);
933 gdk_window_remove_filter (gdk_get_default_root_window(),
934 hildon_window_root_window_event_filter,
937 gtk_widget_set_events (GTK_WIDGET(obj), 0);
939 GTK_OBJECT_CLASS (hildon_window_parent_class)->destroy (obj);
943 hildon_window_notify (GObject *gobject,
946 HildonWindow *window = HILDON_WINDOW (gobject);
948 if (g_str_equal (param->name, "is-topmost"))
950 hildon_window_is_topmost_notify (window);
953 if (G_OBJECT_CLASS(hildon_window_parent_class)->notify)
954 G_OBJECT_CLASS(hildon_window_parent_class)->notify (gobject, param);
959 visible_toolbar (gpointer data,
962 if (GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
963 (*((gint *)user_data))++;
967 paint_toolbar (GtkWidget *widget,
969 GdkEventExpose * event,
972 gint toolbar_num = 0;
975 /* collect info to help on painting the boxes */
976 g_list_foreach (box->children, visible_toolbar,
977 (gpointer) &toolbar_num);
982 /*top most toolbar painting*/
983 gtk_paint_box (widget->style, widget->window,
984 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
985 &event->area, widget, "toolbar-primary",
986 widget->allocation.x,
987 GTK_WIDGET(box)->allocation.y,
988 widget->allocation.width,
991 /*multi toolbar painting*/
992 for (count = 0; count < toolbar_num - 1; count++)
994 gtk_paint_box (widget->style, widget->window,
995 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
996 &event->area, widget, "toolbar-secondary",
997 widget->allocation.x,
998 GTK_WIDGET(box)->allocation.y +
999 (1 + count) * (TOOLBAR_HEIGHT),
1000 widget->allocation.width,
1006 paint_edit_toolbar (GtkWidget *widget,
1008 GdkEventExpose *event,
1009 gboolean fullscreen)
1011 if (!GTK_WIDGET_VISIBLE (toolbar))
1014 gtk_paint_box (widget->style, widget->window,
1015 GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
1016 &event->area, widget, "toolbar-edit-mode",
1017 toolbar->allocation.x,
1018 toolbar->allocation.y,
1019 toolbar->allocation.width,
1020 toolbar->allocation.height);
1024 * Checks the root window to know which is the topped window
1027 hildon_window_get_active_window (void)
1035 unsigned long extra;
1039 unsigned char *char_pointer;
1041 Atom active_app_atom =
1042 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1046 gdk_error_trap_push ();
1047 status = XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1048 active_app_atom, 0L, 16L,
1049 0, XA_WINDOW, &realtype, &format,
1050 &n, &extra, &win.char_pointer);
1051 xerror = gdk_error_trap_pop ();
1052 if (xerror || !(status == Success && realtype == XA_WINDOW && format == 32
1053 && n == 1 && win.win != NULL))
1055 if (win.win != NULL)
1056 XFree (win.char_pointer);
1062 if (win.win != NULL)
1063 XFree(win.char_pointer);
1069 xclient_message_type_check (XClientMessageEvent *cm,
1072 return cm->message_type == XInternAtom(GDK_DISPLAY(), name, FALSE);
1076 * Handle the window border custom button, which toggles the menu,
1077 * and the Hildon input method copy paste messages
1079 static GdkFilterReturn
1080 hildon_window_event_filter (GdkXEvent *xevent,
1084 XAnyEvent *eventti = xevent;
1086 if (eventti->type == ClientMessage)
1088 XClientMessageEvent *cm = xevent;
1090 if (xclient_message_type_check (cm, "_MB_GRAB_TRANSFER"))
1092 hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]);
1093 return GDK_FILTER_REMOVE;
1095 /* opera hack clipboard client message */
1096 else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY"))
1098 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1099 HILDON_WINDOW_CO_COPY);
1100 return GDK_FILTER_REMOVE;
1102 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT"))
1104 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1105 HILDON_WINDOW_CO_CUT);
1106 return GDK_FILTER_REMOVE;
1108 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE"))
1110 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1111 HILDON_WINDOW_CO_PASTE);
1112 return GDK_FILTER_REMOVE;
1116 return GDK_FILTER_CONTINUE;
1120 * Here we keep track of changes in the _MB_CURRENT_APP_WINDOW,
1121 * to know when we acquire/lose topmost status
1123 static GdkFilterReturn
1124 hildon_window_root_window_event_filter (GdkXEvent *xevent,
1128 XAnyEvent *eventti = xevent;
1129 HildonWindow *hwindow = HILDON_WINDOW (data);
1131 if (eventti->type == PropertyNotify)
1133 XPropertyEvent *pevent = xevent;
1134 Atom active_app_atom =
1135 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1137 if (pevent->atom == active_app_atom)
1139 Window active_window = hildon_window_get_active_window();
1141 hildon_window_update_topmost (hwindow, active_window);
1145 return GDK_FILTER_CONTINUE;
1149 * Handle the menu hardware key here
1152 hildon_window_key_press_event (GtkWidget *widget,
1155 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1157 g_return_val_if_fail (HILDON_IS_WINDOW (widget),FALSE);
1160 switch (event->keyval)
1162 case HILDON_HARDKEY_MENU:
1163 if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME))
1166 case HILDON_HARDKEY_ESC:
1167 if (!priv->escape_timeout)
1169 priv->escape_timeout = gdk_threads_add_timeout
1170 (HILDON_WINDOW_LONG_PRESS_TIME,
1171 hildon_window_escape_timeout, widget);
1176 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event);
1180 hildon_window_key_release_event (GtkWidget *widget,
1183 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1185 g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE);
1188 switch (event->keyval)
1190 case HILDON_HARDKEY_ESC:
1191 if (priv->escape_timeout)
1193 g_source_remove (priv->escape_timeout);
1194 priv->escape_timeout = 0;
1199 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event);
1204 * We keep track of the window state changes, because the drawing
1205 * (borders) differs whether we are in fullscreen mode or not
1208 hildon_window_window_state_event (GtkWidget *widget,
1209 GdkEventWindowState *event)
1211 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1212 g_assert (priv != NULL);
1214 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1215 priv->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1217 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event)
1219 return GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event (
1230 * If the window lost focus while the user started to press the ESC key, we
1231 * won't get the release event. We need to stop the timeout.
1234 hildon_window_focus_out_event (GtkWidget *widget,
1235 GdkEventFocus *event)
1237 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1239 if (priv->escape_timeout)
1241 g_source_remove (priv->escape_timeout);
1242 priv->escape_timeout = 0;
1245 return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event);
1249 set_legacy_menu_type (GtkMenu *menu,
1252 GdkWindow *gdkwin = GTK_WIDGET (menu->toplevel)->window;
1253 GdkAtom property = gdk_atom_intern_static_string (LEGACY_MENU_PROPERTY_NAME);
1255 GdkAtom type = gdk_x11_xatom_to_atom (XA_ATOM);
1256 GdkAtom value = gdk_atom_intern_static_string (LEGACY_MENU_PROPERTY_VALUE);
1257 gdk_property_change (gdkwin, property, type, 32,
1258 GDK_PROP_MODE_REPLACE, (const guchar *) &value, 1);
1260 gdk_property_delete (gdkwin, property);
1265 legacy_menu_realized (GtkMenu *menu)
1267 set_legacy_menu_type (menu, TRUE);
1268 g_signal_handlers_disconnect_by_func (menu, legacy_menu_realized, NULL);
1272 legacy_menu_unmapped (GtkMenu *menu)
1274 set_legacy_menu_type (menu, FALSE);
1275 g_signal_handlers_disconnect_by_func (menu, legacy_menu_unmapped, NULL);
1279 * The menu popuping needs a menu popup-function
1282 hildon_window_menu_popup_func (GtkMenu *menu,
1290 GdkWindow *window = GTK_WIDGET(widget)->window;
1294 gdk_window_get_origin (window, &window_x, &window_y);
1297 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1298 "vertical-offset", y, NULL);
1300 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1302 *x = GTK_WIDGET (widget)->allocation.width + window_x - GTK_WIDGET (menu)->allocation.width - *x;
1312 hildon_window_menu_popup_func_full (GtkMenu *menu,
1318 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1319 "vertical-offset", y, NULL);
1321 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1322 *x = GTK_WIDGET (widget)->allocation.width - GTK_WIDGET (menu)->allocation.width - *x;
1331 * Takes the common toolbar when we acquire the top-most status
1334 hildon_window_is_topmost_notify (HildonWindow *window)
1336 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1340 if (priv->is_topmost)
1342 hildon_window_take_common_toolbar (window);
1347 hildon_window_update_menu_flag (HildonWindow *self,
1348 gboolean is_app_menu)
1350 HildonWindowPrivate *priv;
1352 priv = HILDON_WINDOW_GET_PRIVATE (self);
1356 /* Change the menu flag only if there is no program or common
1357 application menu. */
1358 if (!priv->program ||
1359 !hildon_program_get_common_app_menu (priv->program))
1361 hildon_window_set_menu_flag (self, priv->app_menu != NULL &&
1362 hildon_app_menu_has_visible_children (priv->app_menu));
1365 if (!priv->program || !hildon_program_get_common_menu (priv->program))
1367 hildon_window_set_menu_flag (self, priv->menu != NULL
1368 && gtk_container_get_children (GTK_CONTAINER (priv->menu)));
1374 on_menu_changed (HildonAppMenu *menu,
1375 HildonWindow *window)
1377 hildon_window_update_menu_flag (window, TRUE);
1381 * Sets the program to which the window belongs. This should only be called
1382 * by hildon_program_add_window
1384 void G_GNUC_INTERNAL
1385 hildon_window_set_program (HildonWindow *self,
1388 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1390 g_return_if_fail (HILDON_IS_WINDOW (self));
1391 g_assert (priv != NULL);
1395 g_object_unref (priv->program);
1398 /* Now that we are bound to a program, we can rely on it to track the
1400 gdk_window_remove_filter (gdk_get_default_root_window(),
1401 hildon_window_root_window_event_filter,
1404 priv->program = HILDON_PROGRAM (program);
1405 g_object_ref (program);
1409 * Unsets the program to which the window belongs. This should only be called
1410 * by hildon_program_remove_window
1412 void G_GNUC_INTERNAL
1413 hildon_window_unset_program (HildonWindow *self)
1415 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1417 g_return_if_fail(HILDON_IS_WINDOW (self));
1418 g_assert (priv != NULL);
1422 g_object_unref (priv->program);
1423 priv->program = NULL;
1425 /* We need to start tacking the root window again */
1426 gdk_window_set_events (gdk_get_default_root_window (),
1427 gdk_window_get_events (gdk_get_default_root_window ())
1428 | GDK_PROPERTY_CHANGE_MASK);
1430 gdk_window_add_filter (gdk_get_default_root_window (),
1431 hildon_window_root_window_event_filter, self );
1434 priv->program = NULL;
1438 * Sets whether or not the program to which this window belongs is
1439 * killable. This is used by the HildonProgram to signify to the
1440 * Task Navigator whether or not it can hibernate in memory-low situations
1442 void G_GNUC_INTERNAL
1443 hildon_window_set_can_hibernate_property (HildonWindow *self,
1444 gpointer _can_hibernate)
1446 GdkAtom killable_atom;
1447 gboolean can_hibernate;
1449 g_return_if_fail(self && HILDON_IS_WINDOW (self));
1451 if (!GTK_WIDGET_REALIZED ((GTK_WIDGET (self))))
1456 can_hibernate = * ((gboolean *)_can_hibernate);
1458 killable_atom = gdk_atom_intern (CAN_HIBERNATE_PROPERTY, FALSE);
1462 gdk_property_change (GTK_WIDGET (self)->window, killable_atom,
1463 (GdkAtom)31/* XA_STRING */, 8,
1464 GDK_PROP_MODE_REPLACE, (const guchar *)CAN_HIBERNATE,
1465 CAN_HIBERNATE_LENGTH);
1469 gdk_property_delete (GTK_WIDGET (self)->window, killable_atom);
1475 * If a common toolbar was set to the program, reparent it to
1478 void G_GNUC_INTERNAL
1479 hildon_window_take_common_toolbar (HildonWindow *self)
1481 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1483 g_return_if_fail(HILDON_IS_WINDOW (self));
1488 GtkWidget *common_toolbar =
1489 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
1491 if (common_toolbar && common_toolbar->parent != priv->vbox)
1493 g_object_ref (common_toolbar);
1494 if (common_toolbar->parent)
1496 gtk_container_remove (GTK_CONTAINER (common_toolbar->parent),
1500 gtk_box_pack_end (GTK_BOX(priv->vbox), common_toolbar,
1502 g_object_unref (common_toolbar);
1504 gtk_widget_set_size_request (common_toolbar, -1, TOOLBAR_HEIGHT);
1506 gtk_widget_show (priv->vbox);
1513 * Compare the window that was last topped, and act consequently
1516 hildon_window_update_topmost (HildonWindow *self,
1519 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1521 GdkWindow *my_window;
1523 g_return_if_fail (HILDON_IS_WINDOW (self));
1526 my_window = GTK_WIDGET (self)->window;
1528 if (my_window && window_id == GDK_WINDOW_XID (my_window))
1530 if (! priv->is_topmost)
1532 priv->is_topmost = TRUE;
1533 hildon_window_is_topmost_notify (self);
1534 g_object_notify (G_OBJECT (self), "is-topmost");
1537 else if (priv->is_topmost)
1539 /* Should this go in the signal handler? */
1540 GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (self));
1542 if (GTK_IS_ENTRY (focus))
1543 gtk_im_context_focus_out (GTK_ENTRY (focus)->im_context);
1544 if (GTK_IS_TEXT_VIEW (focus))
1545 gtk_im_context_focus_out (GTK_TEXT_VIEW (focus)->im_context);
1547 priv->is_topmost = FALSE;
1548 hildon_window_is_topmost_notify (self);
1549 g_object_notify (G_OBJECT (self), "is-topmost");
1554 detach_menu_func (GtkWidget *attach_widget,
1557 /* FIXME Why is this even needed here? */
1561 hildon_window_toggle_menu (HildonWindow *self,
1565 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1567 if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
1569 return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
1579 hildon_window_toggle_gtk_menu (HildonWindow *self,
1584 gboolean retvalue = FALSE;
1586 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1587 g_return_val_if_fail (GTK_IS_MENU (menu), FALSE);
1589 if (gtk_menu_get_attach_widget (menu) != GTK_WIDGET (self))
1591 g_object_ref (menu);
1592 if (gtk_menu_get_attach_widget (menu))
1594 gtk_menu_detach (menu);
1596 gtk_menu_attach_to_widget (menu, GTK_WIDGET (self), &detach_menu_func);
1597 g_object_unref (menu);
1600 if (GTK_WIDGET_MAPPED (menu))
1602 gtk_menu_popdown (menu);
1603 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu));
1608 /* Check if the menu has items */
1609 GList *menu_children = gtk_container_get_children (GTK_CONTAINER (menu));
1613 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1614 g_list_free (menu_children);
1616 /* Set the 'legacy app menu' property when the widget is realized */
1617 if (GTK_WIDGET_REALIZED (menu)) {
1618 set_legacy_menu_type (menu, TRUE);
1620 g_signal_connect (menu, "realize",
1621 G_CALLBACK (legacy_menu_realized), NULL);
1624 /* Remove it when it's unmapped */
1625 g_signal_connect (menu, "unmap",
1626 G_CALLBACK (legacy_menu_unmapped), NULL);
1628 /* Apply right theming */
1629 gtk_widget_set_name (GTK_WIDGET (menu), "menu_force_with_corners");
1631 if (priv->fullscreen)
1633 gtk_menu_popup (menu, NULL, NULL,
1634 (GtkMenuPositionFunc)
1635 hildon_window_menu_popup_func_full,
1636 self, button, time);
1640 gtk_menu_popup (menu, NULL, NULL,
1641 (GtkMenuPositionFunc)
1642 hildon_window_menu_popup_func,
1643 self, button, time);
1645 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE);
1654 hildon_window_toggle_app_menu (HildonWindow *self,
1655 HildonAppMenu *menu)
1657 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1658 g_return_val_if_fail (HILDON_IS_APP_MENU (menu), FALSE);
1660 if (self != hildon_app_menu_get_parent_window (menu))
1662 gtk_widget_hide (GTK_WIDGET (menu));
1665 if (GTK_WIDGET_MAPPED (menu))
1667 gtk_widget_hide (GTK_WIDGET (menu));
1671 hildon_app_menu_popup (menu, GTK_WINDOW (self));
1678 * Toggles the display of the HildonWindow menu.
1679 * Returns whether or not something was done (whether or not we had a menu
1683 hildon_window_toggle_menu_real (HildonWindow * self,
1687 gboolean retvalue = FALSE;
1688 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1690 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1692 /* Select which menu to use, Window specific has highest priority,
1693 * then program specific */
1696 retvalue = hildon_window_toggle_gtk_menu (self, priv->menu, button, time);
1698 else if (priv->app_menu)
1700 retvalue = hildon_window_toggle_app_menu (self, priv->app_menu);
1702 else if (priv->program)
1704 GtkMenu *gtkmenu = hildon_program_get_common_menu (priv->program);
1705 HildonAppMenu *appmenu = hildon_program_get_common_app_menu (priv->program);
1709 retvalue = hildon_window_toggle_gtk_menu (self, gtkmenu, button, time);
1713 retvalue = hildon_window_toggle_app_menu (self, appmenu);
1721 * If the ESC key was not released when the timeout expires,
1725 hildon_window_escape_timeout (gpointer data)
1727 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data);
1732 /* Send fake event, simulation a situation that user
1733 pressed 'x' from the corner */
1734 event = gdk_event_new(GDK_DELETE);
1735 ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window));
1736 gtk_main_do_event(event);
1738 /* That unrefs the window, so we're reffing it above */
1739 gdk_event_free(event);
1741 priv->escape_timeout = 0;
1747 * hildon_window_new:
1749 * Creates a new #HildonWindow.
1751 * Return value: A #HildonWindow.
1754 hildon_window_new (void)
1756 HildonWindow *newwindow = g_object_new (HILDON_TYPE_WINDOW, NULL);
1758 return GTK_WIDGET (newwindow);
1762 * hildon_window_add_with_scrollbar:
1763 * @self: A #HildonWindow
1764 * @child: A #GtkWidget
1766 * Adds @child to the #HildonWindow and creates a scrollbar for
1767 * it. Similar to adding first a #GtkScrolledWindow and then @child to
1771 hildon_window_add_with_scrollbar (HildonWindow *self,
1774 GtkScrolledWindow *scrolledw;
1776 g_return_if_fail (HILDON_IS_WINDOW (self));
1777 g_return_if_fail (GTK_IS_WIDGET (child));
1778 g_return_if_fail (child->parent == NULL);
1780 scrolledw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1781 gtk_scrolled_window_set_policy (scrolledw, GTK_POLICY_NEVER,
1782 GTK_POLICY_AUTOMATIC);
1783 gtk_scrolled_window_set_shadow_type (scrolledw, GTK_SHADOW_NONE);
1785 if (GTK_IS_VIEWPORT (child))
1786 gtk_container_add (GTK_CONTAINER (scrolledw), child);
1789 if (GTK_IS_CONTAINER (child) )
1790 gtk_container_set_focus_vadjustment (GTK_CONTAINER(child),
1791 gtk_scrolled_window_get_vadjustment (scrolledw) );
1792 gtk_scrolled_window_add_with_viewport (scrolledw, child);
1795 gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (scrolledw));
1799 calculate_visible_toolbars (gpointer data,
1802 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (((GtkBoxChild *)data)->widget)))
1803 (*((gint *)user_data)) ++;
1807 toolbar_visible_notify (GtkWidget *toolbar, GParamSpec *pspec,
1808 HildonWindow *window)
1810 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1814 /* Recalculate from scratch the value just in case */
1815 priv->visible_toolbars = 0;
1817 g_list_foreach (GTK_BOX (priv->vbox)->children, calculate_visible_toolbars,
1818 &priv->visible_toolbars);
1820 if (priv->visible_toolbars == 0)
1821 gtk_widget_hide (priv->vbox);
1823 gtk_widget_show (priv->vbox);
1827 * hildon_window_add_toolbar:
1828 * @self: A #HildonWindow
1829 * @toolbar: A #GtkToolbar to add to the #HildonWindow
1831 * Adds a toolbar to the window. Note that the toolbar is not automatically
1832 * shown. You need to call gtk_widget_show_all() on it to make it visible.
1833 * It's also possible to hide the toolbar (without removing it) by calling
1837 hildon_window_add_toolbar (HildonWindow *self,
1838 GtkToolbar *toolbar)
1841 HildonWindowPrivate *priv;
1843 g_return_if_fail (HILDON_IS_WINDOW (self));
1844 g_return_if_fail (toolbar && GTK_IS_TOOLBAR (toolbar));
1846 priv = HILDON_WINDOW_GET_PRIVATE (self);
1848 vbox = GTK_BOX (priv->vbox);
1850 gtk_box_pack_start (vbox, GTK_WIDGET (toolbar), TRUE, TRUE, 0);
1851 gtk_box_reorder_child (vbox, GTK_WIDGET (toolbar), 0);
1852 gtk_widget_set_size_request (GTK_WIDGET (toolbar), -1, TOOLBAR_HEIGHT);
1854 g_signal_connect (G_OBJECT (toolbar), "notify::visible",
1855 G_CALLBACK (toolbar_visible_notify), self);
1857 if (GTK_WIDGET_VISIBLE (toolbar))
1859 priv->visible_toolbars++;
1860 gtk_widget_show (priv->vbox);
1863 gtk_widget_queue_resize (GTK_WIDGET (self));
1867 * hildon_window_remove_toolbar:
1868 * @self: A #HildonWindow
1869 * @toolbar: A #GtkToolbar to remove from the #HildonWindow
1871 * Removes a toolbar from the window. Note that this decreases the refference
1872 * count on the widget. If you want to keep the toolbar alive call g_object_ref()
1873 * before calling this function.
1876 hildon_window_remove_toolbar (HildonWindow *self,
1877 GtkToolbar *toolbar)
1879 HildonWindowPrivate *priv;
1881 g_return_if_fail (HILDON_IS_WINDOW (self));
1883 priv = HILDON_WINDOW_GET_PRIVATE (self);
1885 if (GTK_WIDGET_VISIBLE (toolbar))
1887 if (--(priv->visible_toolbars) == 0)
1888 gtk_widget_hide (priv->vbox);
1891 g_signal_handlers_disconnect_by_func (toolbar, toolbar_visible_notify, self);
1893 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (toolbar));
1897 * hildon_window_set_edit_toolbar:
1898 * @self: A #HildonWindow
1899 * @toolbar: A #HildonEditToolbar, or %NULL to remove the current one.
1901 * Adds a #HildonEditToolbar to the window. Note that the toolbar is
1902 * not automatically shown. You need to call gtk_widget_show() on it
1903 * to make it visible. It's also possible to hide the toolbar (without
1904 * removing it) by calling gtk_widget_hide().
1906 * A window can only have at most one edit toolbar at a time, so the
1907 * previous toolbar (if any) is replaced after calling this function.
1912 hildon_window_set_edit_toolbar (HildonWindow *self,
1913 HildonEditToolbar *toolbar)
1915 HildonWindowPrivate *priv;
1917 g_return_if_fail (HILDON_IS_WINDOW (self));
1918 g_return_if_fail (toolbar == NULL || HILDON_IS_EDIT_TOOLBAR (toolbar));
1920 priv = HILDON_WINDOW_GET_PRIVATE (self);
1922 if (priv->edit_toolbar != GTK_WIDGET (toolbar))
1924 GtkWidget *old_toolbar = priv->edit_toolbar;
1925 priv->edit_toolbar = GTK_WIDGET (toolbar);
1927 if (priv->edit_toolbar)
1928 gtk_widget_set_parent (priv->edit_toolbar, GTK_WIDGET (self));
1931 gtk_widget_unparent (old_toolbar);
1936 * hildon_window_get_main_menu:
1937 * @self: a #HildonWindow
1939 * Gets the #GtkMenu assigned to the #HildonWindow. Note that the
1940 * window is still the owner of the menu.
1942 * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
1943 * you should use hildon_window_get_app_menu() instead.
1945 * Return value: The #GtkMenu assigned to this application view.
1950 hildon_window_get_main_menu (HildonWindow * self)
1952 HildonWindowPrivate *priv;
1954 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
1956 priv = HILDON_WINDOW_GET_PRIVATE (self);
1962 * hildon_window_get_menu:
1963 * @self: a #HildonWindow
1965 * Gets the #GtkMenu assigned to @self
1967 * Return value: a #GtkMenu
1969 * Deprecated: In Hildon 2.2 this function has been renamed to
1970 * hildon_window_get_main_menu() for consistency
1973 hildon_window_get_menu (HildonWindow * self)
1975 return hildon_window_get_main_menu (self);
1978 /* Since we've been asking developers to call gtk_window_add_accel_group()
1979 * themselves, do not trigger criticals by trying it again.
1982 hildon_window_add_accel_group (HildonWindow *self,
1983 GtkAccelGroup *accel_group)
1987 groups = gtk_accel_groups_from_object (G_OBJECT (self));
1988 for (l = groups; l != NULL; l = l->next)
1989 if (l->data == (gpointer)accel_group)
1990 /* Maybe print a warning here? */
1993 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
1997 do_set_has_menu (GtkWindow *window,
2000 gboolean has_menu = GPOINTER_TO_INT (boolptr);
2001 hildon_gtk_window_set_clear_window_flag (window, "_HILDON_WM_WINDOW_MENU_INDICATOR",
2002 XA_INTEGER, has_menu);
2003 g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_FUNC,
2004 0, 0, NULL, do_set_has_menu, NULL);
2008 hildon_window_set_menu_flag (HildonWindow *window,
2011 hildon_gtk_window_set_flag (GTK_WINDOW (window), (HildonFlagFunc) do_set_has_menu,
2012 GUINT_TO_POINTER (has_menu));
2016 * hildon_window_set_main_menu:
2017 * @self: A #HildonWindow
2018 * @menu: The #GtkMenu to be used for this #HildonWindow
2020 * Sets the menu to be used for this window. This menu overrides
2021 * a program-wide menu that may have been set with
2022 * hildon_program_set_common_menu(). Pass %NULL to remove the current
2023 * menu. #HildonWindow takes ownership of the passed menu and you're
2024 * not supposed to free it yourself anymore.
2026 * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
2027 * you should use hildon_window_set_app_menu() instead.
2030 hildon_window_set_main_menu (HildonWindow* self,
2033 HildonWindowPrivate *priv;
2034 GtkAccelGroup *accel_group;
2036 g_return_if_fail (HILDON_IS_WINDOW (self));
2038 priv = HILDON_WINDOW_GET_PRIVATE (self);
2040 if (priv->menu != NULL)
2042 accel_group = gtk_menu_get_accel_group (priv->menu);
2043 if (accel_group != NULL)
2044 gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
2046 gtk_menu_detach (priv->menu);
2047 g_object_unref (priv->menu);
2051 if (priv->menu != NULL)
2053 gtk_widget_set_name (GTK_WIDGET (priv->menu), "menu_force_with_corners");
2054 gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (self), &detach_menu_func);
2055 g_object_ref (priv->menu);
2057 accel_group = gtk_menu_get_accel_group (priv->menu);
2058 if (accel_group != NULL)
2059 hildon_window_add_accel_group (self, accel_group);
2062 hildon_window_update_menu_flag (self, FALSE);
2066 * hildon_window_set_menu:
2067 * @self: A #HildonWindow
2068 * @menu: The #GtkMenu to be used for this #HildonWindow
2070 * Sets the menu to be used for this window. This menu overrides
2071 * a program-wide menu that may have been set with
2072 * hildon_program_set_common_menu(). Pass %NULL to remove the current
2073 * menu. HildonWindow takes ownership of the passed menu and you're
2074 * not supposed to free it yourself anymore.
2076 * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the
2077 * #GtkMenu. To pass control about visibility to the application
2078 * developer, hildon_window_set_main_menu() was introduced, which
2081 * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
2084 hildon_window_set_menu (HildonWindow *self,
2087 HildonWindowPrivate *priv;
2089 g_return_if_fail (HILDON_IS_WINDOW (self));
2091 hildon_window_set_main_menu (self, menu);
2093 priv = HILDON_WINDOW_GET_PRIVATE (self);
2095 if (priv->menu != NULL)
2096 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2100 * hildon_window_get_is_topmost:
2101 * @self: A #HildonWindow
2103 * Returns whether the #HildonWindow is currenty activated by the
2106 * Return value: %TRUE if @self is currently activated, %FALSE otherwise.
2109 hildon_window_get_is_topmost (HildonWindow *self)
2111 HildonWindowPrivate *priv;
2113 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
2115 priv = HILDON_WINDOW_GET_PRIVATE (self);
2116 return priv->is_topmost;
2120 * hildon_window_set_app_menu:
2121 * @self: a #HildonWindow
2122 * @menu: a #HildonAppMenu to be used for this window
2124 * Sets the menu to be used for this window. Pass %NULL to remove the
2125 * current menu. Any reference to a previous menu will be dropped.
2126 * #HildonWindow takes ownership of the passed menu and
2127 * you're not supposed to free it yourself anymore.
2129 * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
2130 * you should use hildon_window_set_main_menu() instead.
2135 hildon_window_set_app_menu (HildonWindow *self,
2136 HildonAppMenu *menu)
2138 HildonWindowPrivate *priv;
2139 HildonAppMenu *old_menu;
2141 g_return_if_fail (HILDON_IS_WINDOW (self));
2142 g_return_if_fail (!menu || HILDON_IS_APP_MENU (menu));
2143 priv = HILDON_WINDOW_GET_PRIVATE (self);
2145 old_menu = priv->app_menu;
2148 priv->app_menu = menu;
2151 g_object_ref_sink (menu);
2152 g_signal_connect (menu, "changed", G_CALLBACK (on_menu_changed), self);
2155 /* Unref old menu */
2158 g_signal_handlers_disconnect_by_func (old_menu, on_menu_changed, self);
2159 g_object_unref (old_menu);
2162 hildon_window_update_menu_flag (self, TRUE);
2166 * hildon_window_get_app_menu:
2167 * @self: a #HildonWindow
2169 * Returns the #HildonAppMenu assigned to @self, or %NULL if it's
2170 * unset. Note that the window is still the owner of the menu.
2172 * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
2173 * you should use hildon_window_get_main_menu() instead.
2175 * Returns: a #HildonAppMenu
2180 hildon_window_get_app_menu (HildonWindow *self)
2182 HildonWindowPrivate *priv;
2184 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
2186 priv = HILDON_WINDOW_GET_PRIVATE (self);
2188 return priv->app_menu;
2192 hildon_window_update_markup (HildonWindow *window)
2194 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
2195 GdkAtom markup_atom = gdk_atom_intern ("_HILDON_WM_NAME", FALSE);
2196 GdkAtom utf8_atom = gdk_atom_intern ("UTF8_STRING", FALSE);
2197 GdkWindow *gdkwin = GTK_WIDGET (window)->window;
2200 gdk_property_change (gdkwin, markup_atom, utf8_atom, 8,
2201 GDK_PROP_MODE_REPLACE, (const guchar *) priv->markup,
2202 strlen (priv->markup));
2204 gdk_property_delete (gdkwin, markup_atom);
2209 * hildon_window_get_markup:
2210 * @window: a #HildonWindow
2212 * Gets the marked up title of the window title. See hildon_window_set_markup()
2214 * Returns: the marked up title of the window, or %NULL if none has
2215 * been set explicitely. The returned string is owned by the widget
2216 * and must not be modified or freed.
2221 hildon_window_get_markup (HildonWindow *window)
2223 HildonWindowPrivate *priv;
2225 g_return_val_if_fail (HILDON_IS_WINDOW (window), NULL);
2227 priv = HILDON_WINDOW_GET_PRIVATE (window);
2229 return priv->markup;
2233 * hildon_window_set_markup:
2234 * @window: a #HildonWindow
2235 * @markup: the marked up title of the window, or %NULL to unset the
2238 * Sets the marked up title of @window. The accepted format is the one
2239 * used in Pango (see #PangoMarkupFormat) with the exception of
2242 * Note that you need support from the window manager for this title
2243 * to be used. See gtk_window_set_title() for the standard way of
2244 * setting the title of a window.
2249 hildon_window_set_markup (HildonWindow *window,
2250 const gchar *markup)
2252 HildonWindowPrivate *priv;
2255 g_return_if_fail (HILDON_IS_WINDOW (window));
2257 priv = HILDON_WINDOW_GET_PRIVATE (window);
2259 new_markup = g_strdup (markup);
2260 g_free (priv->markup);
2261 priv->markup = new_markup;
2263 if (GTK_WIDGET_REALIZED (window))
2264 hildon_window_update_markup (window);
2266 g_object_notify (G_OBJECT (window), "markup");