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.
28 * @see_also: #HildonProgram, #HildonStackableWindow
30 * #HildonWindow is a GTK widget which represents 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"
99 #define _(String) gettext(String)
101 #define TOOLBAR_HEIGHT 70
103 #define TOOLBAR_MIDDLE 0
106 #define CAN_HIBERNATE "CANKILL"
108 #define CAN_HIBERNATE_LENGTH 7
110 #define CAN_HIBERNATE_PROPERTY "_HILDON_ABLE_TO_HIBERNATE"
112 #define TITLE_SEPARATOR " - "
114 typedef void (*HildonWindowSignal) (HildonWindow *, gint, gpointer);
117 hildon_window_init (HildonWindow * self);
120 hildon_window_class_init (HildonWindowClass * window_class);
123 hildon_window_menu_popup_func (GtkMenu *menu,
129 hildon_window_menu_popup_func_full (GtkMenu *menu,
135 hildon_window_expose (GtkWidget *widget,
136 GdkEventExpose *event);
138 hildon_window_forall (GtkContainer *container,
139 gboolean include_internals,
140 GtkCallback callback,
141 gpointer callback_data);
143 hildon_window_show_all (GtkWidget *widget);
146 hildon_window_size_allocate (GtkWidget * widget,
147 GtkAllocation *allocation);
149 hildon_window_size_request (GtkWidget * widget,
150 GtkRequisition *requisition);
152 hildon_window_finalize (GObject *obj_self);
155 hildon_window_get_property (GObject *object,
161 hildon_window_set_property (GObject *object,
167 hildon_window_update_markup (HildonWindow *window);
170 hildon_window_destroy (GtkObject *obj);
173 hildon_window_realize (GtkWidget *widget);
176 hildon_window_unrealize (GtkWidget *widget);
179 hildon_window_map (GtkWidget *widget);
182 hildon_window_unmap (GtkWidget *widget);
185 hildon_window_key_press_event (GtkWidget *widget,
189 hildon_window_key_release_event (GtkWidget *widget,
192 hildon_window_window_state_event (GtkWidget *widget,
193 GdkEventWindowState *event);
195 hildon_window_focus_out_event (GtkWidget *widget,
196 GdkEventFocus *event);
199 hildon_window_notify (GObject *gobject,
203 hildon_window_is_topmost_notify (HildonWindow *window);
206 hildon_window_toggle_menu (HildonWindow * self,
211 hildon_window_toggle_menu_real (HildonWindow * self,
216 hildon_window_escape_timeout (gpointer data);
218 static GdkFilterReturn
219 hildon_window_event_filter (GdkXEvent *xevent,
223 static GdkFilterReturn
224 hildon_window_root_window_event_filter (GdkXEvent *xevent,
229 hildon_window_get_borders (HildonWindow *window);
232 visible_toolbar (gpointer data,
236 paint_toolbar (GtkWidget *widget,
238 GdkEventExpose * event,
239 gboolean fullscreen);
242 paint_edit_toolbar (GtkWidget *widget,
244 GdkEventExpose *event,
245 gboolean fullscreen);
261 G_DEFINE_TYPE (HildonWindow, hildon_window, GTK_TYPE_WINDOW);
264 hildon_window_class_init (HildonWindowClass * window_class)
266 /* Get convenience variables */
267 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (window_class);
268 GObjectClass *object_class = G_OBJECT_CLASS (window_class);
269 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (window_class);
271 object_class->get_property = hildon_window_get_property;
272 object_class->set_property = hildon_window_set_property;
273 object_class->notify = hildon_window_notify;
274 widget_class->size_allocate = hildon_window_size_allocate;
275 widget_class->size_request = hildon_window_size_request;
276 widget_class->expose_event = hildon_window_expose;
277 widget_class->show_all = hildon_window_show_all;
278 widget_class->realize = hildon_window_realize;
279 widget_class->unrealize = hildon_window_unrealize;
280 widget_class->key_press_event = hildon_window_key_press_event;
281 widget_class->key_release_event = hildon_window_key_release_event;
282 widget_class->window_state_event = hildon_window_window_state_event;
283 widget_class->focus_out_event = hildon_window_focus_out_event;
284 widget_class->map = hildon_window_map;
285 widget_class->unmap = hildon_window_unmap;
287 /* now the object stuff */
288 object_class->finalize = hildon_window_finalize;
290 /* To the container */
291 container_class->forall = hildon_window_forall;
294 window_class->toggle_menu = hildon_window_toggle_menu_real;
297 GTK_OBJECT_CLASS (window_class)->destroy = hildon_window_destroy;
299 g_type_class_add_private (window_class,
300 sizeof (struct _HildonWindowPrivate));
302 /* Install properties */
304 g_object_class_install_property (object_class, PROP_IS_TOPMOST,
305 g_param_spec_boolean ("is-topmost",
307 "Whether the window is currently activated by the window "
312 g_object_class_install_property (object_class, PROP_MARKUP,
313 g_param_spec_string ("markup",
314 "Marked up text for the window title",
315 "Marked up text for the window title",
319 gtk_widget_class_install_style_property (widget_class,
320 g_param_spec_boxed ("borders",
322 "Size of graphical window borders",
326 gtk_widget_class_install_style_property (widget_class,
327 g_param_spec_boxed ("toolbar-borders",
328 "Graphical toolbar borders",
329 "Size of graphical toolbar borders",
333 /* opera hack, install clip operation signal */
334 g_signal_new ("clipboard_operation",
335 G_OBJECT_CLASS_TYPE (object_class),
337 G_STRUCT_OFFSET (HildonWindowClass, clipboard_operation),
339 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1,
344 hildon_window_init (HildonWindow *self)
346 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
347 g_assert (priv != NULL);
349 priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
350 gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
352 priv->app_menu = NULL;
353 priv->edit_toolbar = NULL;
354 priv->visible_toolbars = 0;
355 priv->is_topmost = FALSE;
356 priv->borders = NULL;
357 priv->toolbar_borders = NULL;
358 priv->escape_timeout = 0;
361 priv->fullscreen = FALSE;
363 priv->program = NULL;
365 /* We need to track the root window _MB_CURRENT_APP_WINDOW property */
366 gdk_window_set_events (gdk_get_default_root_window (),
367 gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK);
369 gdk_window_add_filter (gdk_get_default_root_window (),
370 hildon_window_root_window_event_filter, self);
374 hildon_window_finalize (GObject * obj_self)
376 HildonWindowPrivate *priv;
378 g_return_if_fail (HILDON_WINDOW (obj_self));
380 priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
381 g_assert (priv != NULL);
383 g_free (priv->markup);
385 if (priv->escape_timeout) {
386 g_source_remove (priv->escape_timeout);
387 priv->escape_timeout = 0;
391 gtk_border_free (priv->borders);
393 if (priv->toolbar_borders)
394 gtk_border_free (priv->toolbar_borders);
396 if (G_OBJECT_CLASS (hildon_window_parent_class)->finalize)
397 G_OBJECT_CLASS (hildon_window_parent_class)->finalize (obj_self);
402 hildon_window_realize (GtkWidget *widget)
404 Atom *old_atoms, *new_atoms;
408 Window active_window;
409 HildonWindowPrivate *priv;
411 GTK_WIDGET_CLASS (hildon_window_parent_class)->realize (widget);
413 priv = HILDON_WINDOW_GET_PRIVATE (widget);
414 g_assert (priv != NULL);
416 gtk_widget_realize (GTK_WIDGET (priv->vbox));
418 if (priv->edit_toolbar != NULL)
419 gtk_widget_realize (priv->edit_toolbar);
421 /* catch the custom button signal from mb to display the menu */
422 gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
424 window = GDK_WINDOW_XID (widget->window);
425 disp = GDK_WINDOW_XDISPLAY (widget->window);
427 /* Enable custom button that is used for menu */
428 XGetWMProtocols (disp, window, &old_atoms, &atom_count);
429 new_atoms = g_new (Atom, atom_count + 1);
431 memcpy (new_atoms, old_atoms, sizeof(Atom) * atom_count);
433 new_atoms[atom_count++] =
434 XInternAtom (disp, "_NET_WM_CONTEXT_CUSTOM", False);
436 XSetWMProtocols (disp, window, new_atoms, atom_count);
441 /* rely on GDK to set the window group to its default */
442 gdk_window_set_group (widget->window, NULL);
445 gboolean can_hibernate = hildon_program_get_can_hibernate (priv->program);
447 hildon_window_set_can_hibernate_property (HILDON_WINDOW (widget),
452 hildon_window_update_markup (HILDON_WINDOW (widget));
454 /* Update the topmost status */
455 active_window = hildon_window_get_active_window();
456 hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
460 hildon_window_unrealize (GtkWidget *widget)
462 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
463 g_assert (priv != NULL);
465 gdk_window_remove_filter (widget->window, hildon_window_event_filter,
468 gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
470 if (priv->edit_toolbar != NULL)
471 gtk_widget_unrealize (priv->edit_toolbar);
473 GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
477 hildon_window_map (GtkWidget *widget)
479 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
480 g_assert (priv != NULL);
482 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->map)
483 GTK_WIDGET_CLASS (hildon_window_parent_class)->map (widget);
485 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
486 gtk_widget_map (priv->vbox);
488 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
489 gtk_widget_map (priv->edit_toolbar);
493 hildon_window_unmap (GtkWidget *widget)
495 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
496 g_assert (priv != NULL);
498 gtk_widget_unmap (priv->vbox);
500 if (priv->edit_toolbar != NULL)
501 gtk_widget_unmap (priv->edit_toolbar);
503 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
504 GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
508 hildon_window_get_property (GObject *object,
513 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (object);
514 g_assert (priv != NULL);
516 switch (property_id) {
518 case PROP_IS_TOPMOST:
519 g_value_set_boolean (value, priv->is_topmost);
523 g_value_set_string (value, priv->markup);
527 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
533 hildon_window_set_property (GObject *object,
538 switch (property_id) {
541 hildon_window_set_markup (HILDON_WINDOW (object), g_value_get_string (value));
545 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
551 * Retrieve the graphical borders size used by the themes
554 hildon_window_get_borders (HildonWindow *window)
556 GtkBorder zero = {0, 0, 0, 0};
557 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
560 GtkBorder *borders = NULL;
561 GtkBorder *toolbar_borders = NULL;
564 gtk_border_free (priv->borders);
565 if (priv->toolbar_borders)
566 gtk_border_free (priv->toolbar_borders);
568 priv->borders = NULL;
569 priv->toolbar_borders = NULL;
571 gtk_widget_style_get (GTK_WIDGET (window), "borders",&borders,
572 "toolbar-borders", &toolbar_borders,
575 // We're doing a copy here instead of reusing the pointer,
576 // as we don't know where it comes from (has it been allocated using
577 // malloc or slices... and we want to free it sanely. Blowing on
581 priv->borders = gtk_border_copy (borders);
582 gtk_border_free (borders);
584 priv->borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
586 if (toolbar_borders) {
587 priv->toolbar_borders = gtk_border_copy (toolbar_borders);
588 gtk_border_free (toolbar_borders);
590 priv->toolbar_borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
594 hildon_window_expose (GtkWidget *widget,
595 GdkEventExpose * event)
597 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
600 GtkWidget *bx = priv->vbox;
601 GtkBox *box = GTK_BOX(bx);
602 GtkBorder *b = priv->borders;
603 GtkBorder *tb = priv->toolbar_borders;
606 if (! priv->borders) {
607 hildon_window_get_borders (HILDON_WINDOW (widget));
609 tb = priv->toolbar_borders;
612 tb_height = bx->allocation.height + tb->top + tb->bottom;
614 paint_toolbar (widget, box,
615 event, priv->fullscreen);
617 if (priv->edit_toolbar != NULL)
619 paint_edit_toolbar (widget, priv->edit_toolbar,
620 event, priv->fullscreen);
623 if (! priv->fullscreen) {
625 /* Draw the left and right window border */
626 gint side_borders_height = widget->allocation.height - b->top;
628 if (priv->visible_toolbars)
629 side_borders_height -= tb_height;
631 side_borders_height -= b->bottom;
635 gtk_paint_box (widget->style, widget->window,
636 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
637 &event->area, widget, "left-border",
638 widget->allocation.x, widget->allocation.y +
639 b->top, b->left, side_borders_height);
644 gtk_paint_box (widget->style, widget->window,
645 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
646 &event->area, widget, "right-border",
647 widget->allocation.x + widget->allocation.width -
648 b->right, widget->allocation.y + b->top,
649 b->right, side_borders_height);
652 /* If no toolbar, draw the bottom window border */
653 if (! priv->visible_toolbars && b->bottom > 0)
655 gtk_paint_box (widget->style, widget->window,
656 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
657 &event->area, widget, "bottom-border",
658 widget->allocation.x, widget->allocation.y +
659 (widget->allocation.height - b->bottom),
660 widget->allocation.width, b->bottom);
663 /* Draw the top border */
666 gtk_paint_box (widget->style, widget->window,
667 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
668 &event->area, widget, "top-border",
669 widget->allocation.x, widget->allocation.y,
670 widget->allocation.width, b->top);
676 /* don't draw the window stuff as it overwrites our borders with a blank
677 * rectangle. Instead start with the drawing of the GtkBin */
678 GTK_WIDGET_CLASS (g_type_class_peek_parent (hildon_window_parent_class))->expose_event (widget, event);
680 /* FIXME Not sure why this is commented out
681 * GTK_WIDGET_CLASS (hildon_window_parent_class))->
682 * expose_event (widget, event);
689 hildon_window_size_request (GtkWidget *widget,
690 GtkRequisition *requisition)
692 GdkScreen *screen = gtk_widget_get_screen (widget);
693 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
698 child = gtk_bin_get_child (GTK_BIN (widget));
700 if (child != NULL && GTK_WIDGET_VISIBLE (child))
701 gtk_widget_size_request (child, &req);
703 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
704 gtk_widget_size_request (priv->vbox, &req);
706 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
707 gtk_widget_size_request (priv->edit_toolbar, &req);
709 /* Request the full size of the screen */
710 requisition->width = gdk_screen_get_width (screen);
711 requisition->height = gdk_screen_get_height (screen);
713 if (! priv->fullscreen)
714 requisition->height -= HILDON_WINDOW_TITLEBAR_HEIGHT;
718 hildon_window_size_allocate (GtkWidget *widget,
719 GtkAllocation *allocation)
721 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
724 GtkAllocation box_alloc = { 0 };
725 GtkAllocation edittb_alloc = { 0 };
726 GtkAllocation alloc = *allocation;
728 GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
732 hildon_window_get_borders (HILDON_WINDOW (widget));
734 tb = priv->toolbar_borders;
736 widget->allocation = *allocation;
738 /* Calculate allocation of edit toolbar */
739 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
742 gtk_widget_get_child_requisition (priv->edit_toolbar, &req);
743 edittb_alloc.width = alloc.width - tb->left - tb->right;
744 edittb_alloc.height = MIN (req.height, alloc.height);
745 edittb_alloc.x = alloc.x + tb->left;
746 edittb_alloc.y = alloc.y + tb->top;
748 if (edittb_alloc.height > 0)
750 alloc.y += tb->top + tb->bottom + edittb_alloc.height;
751 alloc.height -= tb->top + tb->bottom + edittb_alloc.height;
752 gtk_widget_size_allocate (priv->edit_toolbar, &edittb_alloc);
756 /* Calculate allocation of normal toolbars */
757 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
760 gtk_widget_get_child_requisition (priv->vbox, &req);
761 box_alloc.width = alloc.width - tb->left - tb->right;
762 box_alloc.height = MIN (req.height, alloc.height);
763 box_alloc.x = alloc.x + tb->left;
764 box_alloc.y = alloc.y + alloc.height - box_alloc.height - tb->bottom;
766 if (box_alloc.height > 0)
768 alloc.height -= tb->top + tb->bottom + box_alloc.height;
769 gtk_widget_size_allocate (priv->vbox, &box_alloc);
773 /* Calculate allocation of the child widget */
774 if (child != NULL && GTK_WIDGET_VISIBLE (child))
776 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
777 alloc.x += border_width;
778 alloc.y += border_width;
779 alloc.width -= (border_width * 2);
780 alloc.height -= (border_width * 2);
782 if (! priv->fullscreen)
784 GtkBorder *b = priv->borders;
786 alloc.width -= (b->left + b->right);
788 /* Use the top border if there's no edit toolbar */
789 if (edittb_alloc.height <= 0)
792 alloc.height -= b->top;
795 /* Use the top border if there are no standard toolbars */
796 if (box_alloc.height <= 0)
797 alloc.height -= b->bottom;
800 gtk_widget_size_allocate (child, &alloc);
803 if (priv->previous_vbox_y != box_alloc.y)
805 /* The size of the VBox has changed, we need to redraw part
806 * of the window borders */
807 gint draw_from_y = MIN (priv->previous_vbox_y, box_alloc.y) - tb->top;
809 gtk_widget_queue_draw_area (widget, 0, draw_from_y,
810 widget->allocation.width,
811 widget->allocation.height - draw_from_y);
813 priv->previous_vbox_y = box_alloc.y;
819 hildon_window_forall (GtkContainer *container,
820 gboolean include_internals,
821 GtkCallback callback,
822 gpointer callback_data)
824 HildonWindow *self = HILDON_WINDOW (container);
825 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
827 g_return_if_fail (callback != NULL);
830 GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
831 callback, callback_data);
833 if (include_internals && priv->vbox != NULL)
834 (* callback)(GTK_WIDGET (priv->vbox), callback_data);
836 if (include_internals && priv->edit_toolbar != NULL)
837 (* callback)(GTK_WIDGET (priv->edit_toolbar), callback_data);
841 hildon_window_show_all (GtkWidget *widget)
843 HildonWindow *self = HILDON_WINDOW (widget);
844 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
846 g_assert (priv != NULL);
848 GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
850 gtk_widget_show_all (priv->vbox);
852 if (priv->edit_toolbar)
853 gtk_widget_show_all (priv->edit_toolbar);
857 hildon_window_destroy (GtkObject *obj)
859 HildonWindow *self = HILDON_WINDOW (obj);
860 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (obj);
861 GList *menu_list = NULL;
862 GList *menu_node = NULL;
864 g_assert (priv != NULL);
866 if (priv->vbox != NULL)
870 GtkWidget * common_toolbar =
871 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
872 if (common_toolbar && common_toolbar->parent == priv->vbox)
874 gtk_container_remove (GTK_CONTAINER (priv->vbox),
879 gtk_widget_unparent (priv->vbox);
884 if (priv->edit_toolbar != NULL)
886 gtk_widget_unparent (priv->edit_toolbar);
887 priv->edit_toolbar = NULL;
892 hildon_app_menu_set_parent_window (priv->app_menu, NULL);
893 g_object_unref (priv->app_menu);
894 priv->app_menu = NULL;
897 menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
898 menu_node = menu_list;
902 if (GTK_IS_MENU (menu_node->data))
904 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_node->data)))
906 gtk_menu_popdown (GTK_MENU (menu_node->data));
907 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_node->data));
909 gtk_menu_detach (GTK_MENU (menu_node->data));
911 /* Destroy it, but only if it's not a common menu */
913 hildon_program_get_common_menu (priv->program) != menu_node->data) {
914 gtk_object_destroy (GTK_OBJECT (menu_node->data));
915 g_object_unref (menu_node->data);
918 menu_node = menu_node->next;
921 g_list_free (menu_list);
926 hildon_program_remove_window (priv->program, self);
929 gdk_window_remove_filter (gdk_get_default_root_window(),
930 hildon_window_root_window_event_filter,
933 gtk_widget_set_events (GTK_WIDGET(obj), 0);
935 GTK_OBJECT_CLASS (hildon_window_parent_class)->destroy (obj);
939 hildon_window_notify (GObject *gobject,
942 HildonWindow *window = HILDON_WINDOW (gobject);
944 if (g_str_equal (param->name, "is-topmost"))
946 hildon_window_is_topmost_notify (window);
949 if (G_OBJECT_CLASS(hildon_window_parent_class)->notify)
950 G_OBJECT_CLASS(hildon_window_parent_class)->notify (gobject, param);
955 visible_toolbar (gpointer data,
958 if (GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
959 (*((gint *)user_data))++;
963 paint_toolbar (GtkWidget *widget,
965 GdkEventExpose * event,
968 gint toolbar_num = 0;
971 /* collect info to help on painting the boxes */
972 g_list_foreach (box->children, visible_toolbar,
973 (gpointer) &toolbar_num);
978 /*top most toolbar painting*/
979 gtk_paint_box (widget->style, widget->window,
980 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
981 &event->area, widget, "toolbar-primary",
982 widget->allocation.x,
983 GTK_WIDGET(box)->allocation.y,
984 widget->allocation.width,
987 /*multi toolbar painting*/
988 for (count = 0; count < toolbar_num - 1; count++)
990 gtk_paint_box (widget->style, widget->window,
991 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
992 &event->area, widget, "toolbar-secondary",
993 widget->allocation.x,
994 GTK_WIDGET(box)->allocation.y +
995 (1 + count) * (TOOLBAR_HEIGHT),
996 widget->allocation.width,
1002 paint_edit_toolbar (GtkWidget *widget,
1004 GdkEventExpose *event,
1005 gboolean fullscreen)
1007 if (!GTK_WIDGET_VISIBLE (toolbar))
1010 gtk_paint_box (widget->style, widget->window,
1011 GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
1012 &event->area, widget, "toolbar-edit-mode",
1013 toolbar->allocation.x,
1014 toolbar->allocation.y,
1015 toolbar->allocation.width,
1016 toolbar->allocation.height);
1020 * Checks the root window to know which is the topped window
1023 hildon_window_get_active_window (void)
1031 unsigned long extra;
1035 unsigned char *char_pointer;
1037 Atom active_app_atom =
1038 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1042 gdk_error_trap_push ();
1043 status = XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1044 active_app_atom, 0L, 16L,
1045 0, XA_WINDOW, &realtype, &format,
1046 &n, &extra, &win.char_pointer);
1047 xerror = gdk_error_trap_pop ();
1048 if (xerror || !(status == Success && realtype == XA_WINDOW && format == 32
1049 && n == 1 && win.win != NULL))
1051 if (win.win != NULL)
1052 XFree (win.char_pointer);
1058 if (win.win != NULL)
1059 XFree(win.char_pointer);
1065 xclient_message_type_check (XClientMessageEvent *cm,
1068 return cm->message_type == XInternAtom(GDK_DISPLAY(), name, FALSE);
1072 * Handle the window border custom button, which toggles the menu,
1073 * and the Hildon input method copy paste messages
1075 static GdkFilterReturn
1076 hildon_window_event_filter (GdkXEvent *xevent,
1080 XAnyEvent *eventti = xevent;
1082 if (eventti->type == ClientMessage)
1084 XClientMessageEvent *cm = xevent;
1086 if (xclient_message_type_check (cm, "_MB_GRAB_TRANSFER"))
1088 hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]);
1089 return GDK_FILTER_REMOVE;
1091 /* opera hack clipboard client message */
1092 else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY"))
1094 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1095 HILDON_WINDOW_CO_COPY);
1096 return GDK_FILTER_REMOVE;
1098 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT"))
1100 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1101 HILDON_WINDOW_CO_CUT);
1102 return GDK_FILTER_REMOVE;
1104 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE"))
1106 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1107 HILDON_WINDOW_CO_PASTE);
1108 return GDK_FILTER_REMOVE;
1112 return GDK_FILTER_CONTINUE;
1116 * Here we keep track of changes in the _MB_CURRENT_APP_WINDOW,
1117 * to know when we acquire/lose topmost status
1119 static GdkFilterReturn
1120 hildon_window_root_window_event_filter (GdkXEvent *xevent,
1124 XAnyEvent *eventti = xevent;
1125 HildonWindow *hwindow = HILDON_WINDOW (data);
1127 if (eventti->type == PropertyNotify)
1129 XPropertyEvent *pevent = xevent;
1130 Atom active_app_atom =
1131 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1133 if (pevent->atom == active_app_atom)
1135 Window active_window = hildon_window_get_active_window();
1137 hildon_window_update_topmost (hwindow, active_window);
1141 return GDK_FILTER_CONTINUE;
1145 * Handle the menu hardware key here
1148 hildon_window_key_press_event (GtkWidget *widget,
1151 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1153 g_return_val_if_fail (HILDON_IS_WINDOW (widget),FALSE);
1156 switch (event->keyval)
1158 case HILDON_HARDKEY_MENU:
1159 if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME))
1162 case HILDON_HARDKEY_ESC:
1163 if (!priv->escape_timeout)
1165 priv->escape_timeout = g_timeout_add
1166 (HILDON_WINDOW_LONG_PRESS_TIME,
1167 hildon_window_escape_timeout, widget);
1172 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event);
1176 hildon_window_key_release_event (GtkWidget *widget,
1179 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1181 g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE);
1184 switch (event->keyval)
1186 case HILDON_HARDKEY_ESC:
1187 if (priv->escape_timeout)
1189 g_source_remove (priv->escape_timeout);
1190 priv->escape_timeout = 0;
1195 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event);
1200 * We keep track of the window state changes, because the drawing
1201 * (borders) differs whether we are in fullscreen mode or not
1204 hildon_window_window_state_event (GtkWidget *widget,
1205 GdkEventWindowState *event)
1207 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1208 g_assert (priv != NULL);
1210 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1211 priv->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1213 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event)
1215 return GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event (
1226 * If the window lost focus while the user started to press the ESC key, we
1227 * won't get the release event. We need to stop the timeout.
1230 hildon_window_focus_out_event (GtkWidget *widget,
1231 GdkEventFocus *event)
1233 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1235 if (priv->escape_timeout)
1237 g_source_remove (priv->escape_timeout);
1238 priv->escape_timeout = 0;
1241 return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event);
1245 * The menu popuping needs a menu popup-function
1248 hildon_window_menu_popup_func (GtkMenu *menu,
1256 GdkWindow *window = GTK_WIDGET(widget)->window;
1260 gdk_window_get_origin (window, &window_x, &window_y);
1263 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1264 "vertical-offset", y, NULL);
1266 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1268 *x = GTK_WIDGET (widget)->allocation.width + window_x - GTK_WIDGET (menu)->allocation.width - *x;
1278 hildon_window_menu_popup_func_full (GtkMenu *menu,
1284 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1285 "vertical-offset", y, NULL);
1287 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1288 *x = GTK_WIDGET (widget)->allocation.width - GTK_WIDGET (menu)->allocation.width - *x;
1297 * Takes the common toolbar when we acquire the top-most status
1300 hildon_window_is_topmost_notify (HildonWindow *window)
1302 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1306 if (priv->is_topmost)
1308 hildon_window_take_common_toolbar (window);
1313 * Sets the program to which the window belongs. This should only be called
1314 * by hildon_program_add_window
1316 void G_GNUC_INTERNAL
1317 hildon_window_set_program (HildonWindow *self,
1320 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1322 g_return_if_fail (HILDON_IS_WINDOW (self));
1323 g_assert (priv != NULL);
1327 g_object_unref (priv->program);
1330 /* Now that we are bound to a program, we can rely on it to track the
1332 gdk_window_remove_filter (gdk_get_default_root_window(),
1333 hildon_window_root_window_event_filter,
1336 priv->program = HILDON_PROGRAM (program);
1337 g_object_ref (program);
1341 * Unsets the program to which the window belongs. This should only be called
1342 * by hildon_program_remove_window
1344 void G_GNUC_INTERNAL
1345 hildon_window_unset_program (HildonWindow *self)
1347 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1349 g_return_if_fail(HILDON_IS_WINDOW (self));
1350 g_assert (priv != NULL);
1354 g_object_unref (priv->program);
1355 priv->program = NULL;
1357 /* We need to start tacking the root window again */
1358 gdk_window_set_events (gdk_get_default_root_window (),
1359 gdk_window_get_events (gdk_get_default_root_window ())
1360 | GDK_PROPERTY_CHANGE_MASK);
1362 gdk_window_add_filter (gdk_get_default_root_window (),
1363 hildon_window_root_window_event_filter, self );
1366 priv->program = NULL;
1370 * Sets whether or not the program to which this window belongs is
1371 * killable. This is used by the HildonProgram to signify to the
1372 * Task Navigator whether or not it can hibernate in memory-low situations
1374 void G_GNUC_INTERNAL
1375 hildon_window_set_can_hibernate_property (HildonWindow *self,
1376 gpointer _can_hibernate)
1378 GdkAtom killable_atom;
1379 gboolean can_hibernate;
1381 g_return_if_fail(self && HILDON_IS_WINDOW (self));
1383 if (!GTK_WIDGET_REALIZED ((GTK_WIDGET (self))))
1388 can_hibernate = * ((gboolean *)_can_hibernate);
1390 killable_atom = gdk_atom_intern (CAN_HIBERNATE_PROPERTY, FALSE);
1394 gdk_property_change (GTK_WIDGET (self)->window, killable_atom,
1395 (GdkAtom)31/* XA_STRING */, 8,
1396 GDK_PROP_MODE_REPLACE, (const guchar *)CAN_HIBERNATE,
1397 CAN_HIBERNATE_LENGTH);
1401 gdk_property_delete (GTK_WIDGET (self)->window, killable_atom);
1407 * If a common toolbar was set to the program, reparent it to
1410 void G_GNUC_INTERNAL
1411 hildon_window_take_common_toolbar (HildonWindow *self)
1413 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1415 g_return_if_fail(HILDON_IS_WINDOW (self));
1420 GtkWidget *common_toolbar =
1421 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
1423 if (common_toolbar && common_toolbar->parent != priv->vbox)
1425 g_object_ref (common_toolbar);
1426 if (common_toolbar->parent)
1428 gtk_container_remove (GTK_CONTAINER (common_toolbar->parent),
1432 gtk_box_pack_end (GTK_BOX(priv->vbox), common_toolbar,
1434 g_object_unref (common_toolbar);
1436 gtk_widget_set_size_request (common_toolbar, -1, TOOLBAR_HEIGHT);
1438 gtk_widget_show (priv->vbox);
1445 * Compare the window that was last topped, and act consequently
1448 hildon_window_update_topmost (HildonWindow *self,
1451 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1453 GdkWindow *my_window;
1455 g_return_if_fail (HILDON_IS_WINDOW (self));
1458 my_window = GTK_WIDGET (self)->window;
1460 if (my_window && window_id == GDK_WINDOW_XID (my_window))
1462 if (! priv->is_topmost)
1464 priv->is_topmost = TRUE;
1465 hildon_window_is_topmost_notify (self);
1466 g_object_notify (G_OBJECT (self), "is-topmost");
1469 else if (priv->is_topmost)
1471 /* Should this go in the signal handler? */
1472 GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (self));
1474 if (GTK_IS_ENTRY (focus))
1475 gtk_im_context_focus_out (GTK_ENTRY (focus)->im_context);
1476 if (GTK_IS_TEXT_VIEW (focus))
1477 gtk_im_context_focus_out (GTK_TEXT_VIEW (focus)->im_context);
1479 priv->is_topmost = FALSE;
1480 hildon_window_is_topmost_notify (self);
1481 g_object_notify (G_OBJECT (self), "is-topmost");
1486 detach_menu_func (GtkWidget *attach_widget,
1489 /* FIXME Why is this even needed here? */
1493 hildon_window_toggle_menu (HildonWindow *self,
1497 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1499 if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
1501 return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
1511 hildon_window_toggle_gtk_menu (HildonWindow *self,
1516 gboolean retvalue = FALSE;
1518 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1519 g_return_val_if_fail (GTK_IS_MENU (menu), FALSE);
1521 if (gtk_menu_get_attach_widget (menu) != GTK_WIDGET (self))
1523 g_object_ref (menu);
1524 if (gtk_menu_get_attach_widget (menu))
1526 gtk_menu_detach (menu);
1528 gtk_menu_attach_to_widget (menu, GTK_WIDGET (self), &detach_menu_func);
1529 g_object_unref (menu);
1532 if (GTK_WIDGET_MAPPED (menu))
1534 gtk_menu_popdown (menu);
1535 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu));
1540 /* Check if the menu has items */
1541 GList *menu_children = gtk_container_get_children (GTK_CONTAINER (menu));
1545 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1546 g_list_free (menu_children);
1548 /* Apply right theming */
1549 gtk_widget_set_name (GTK_WIDGET (menu), "menu_force_with_corners");
1551 if (priv->fullscreen)
1553 gtk_menu_popup (menu, NULL, NULL,
1554 (GtkMenuPositionFunc)
1555 hildon_window_menu_popup_func_full,
1556 self, button, time);
1560 gtk_menu_popup (menu, NULL, NULL,
1561 (GtkMenuPositionFunc)
1562 hildon_window_menu_popup_func,
1563 self, button, time);
1565 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE);
1574 hildon_window_toggle_app_menu (HildonWindow *self,
1575 HildonAppMenu *menu)
1577 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1578 g_return_val_if_fail (HILDON_IS_APP_MENU (menu), FALSE);
1580 if (self != hildon_app_menu_get_parent_window (menu))
1582 gtk_widget_hide (GTK_WIDGET (menu));
1585 if (GTK_WIDGET_MAPPED (menu))
1587 gtk_widget_hide (GTK_WIDGET (menu));
1591 hildon_app_menu_popup (menu, GTK_WINDOW (self));
1598 * Toggles the display of the HildonWindow menu.
1599 * Returns whether or not something was done (whether or not we had a menu
1603 hildon_window_toggle_menu_real (HildonWindow * self,
1607 gboolean retvalue = FALSE;
1608 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1610 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1612 /* Select which menu to use, Window specific has highest priority,
1613 * then program specific */
1616 retvalue = hildon_window_toggle_gtk_menu (self, priv->menu, button, time);
1618 else if (priv->app_menu)
1620 retvalue = hildon_window_toggle_app_menu (self, priv->app_menu);
1622 else if (priv->program)
1624 GtkMenu *gtkmenu = hildon_program_get_common_menu (priv->program);
1625 HildonAppMenu *appmenu = hildon_program_get_common_app_menu (priv->program);
1629 retvalue = hildon_window_toggle_gtk_menu (self, gtkmenu, button, time);
1633 retvalue = hildon_window_toggle_app_menu (self, appmenu);
1641 * If the ESC key was not released when the timeout expires,
1645 hildon_window_escape_timeout (gpointer data)
1647 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data);
1652 GDK_THREADS_ENTER ();
1654 /* Send fake event, simulation a situation that user
1655 pressed 'x' from the corner */
1656 event = gdk_event_new(GDK_DELETE);
1657 ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window));
1658 gtk_main_do_event(event);
1660 /* That unrefs the window, so we're reffing it above */
1661 gdk_event_free(event);
1663 priv->escape_timeout = 0;
1665 GDK_THREADS_LEAVE ();
1671 * hildon_window_new:
1673 * Creates a new #HildonWindow.
1675 * Return value: A #HildonWindow.
1678 hildon_window_new (void)
1680 HildonWindow *newwindow = g_object_new (HILDON_TYPE_WINDOW, NULL);
1682 return GTK_WIDGET (newwindow);
1686 * hildon_window_add_with_scrollbar:
1687 * @self: A #HildonWindow
1688 * @child: A #GtkWidget
1690 * Adds @child to the #HildonWindow and creates a scrollbar for
1691 * it. Similar to adding first a #GtkScrolledWindow and then @child to
1695 hildon_window_add_with_scrollbar (HildonWindow *self,
1698 GtkScrolledWindow *scrolledw;
1700 g_return_if_fail (HILDON_IS_WINDOW (self));
1701 g_return_if_fail (GTK_IS_WIDGET (child));
1702 g_return_if_fail (child->parent == NULL);
1704 scrolledw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1705 gtk_scrolled_window_set_policy (scrolledw, GTK_POLICY_NEVER,
1706 GTK_POLICY_AUTOMATIC);
1707 gtk_scrolled_window_set_shadow_type (scrolledw, GTK_SHADOW_NONE);
1709 if (GTK_IS_VIEWPORT (child))
1710 gtk_container_add (GTK_CONTAINER (scrolledw), child);
1713 if (GTK_IS_CONTAINER (child) )
1714 gtk_container_set_focus_vadjustment (GTK_CONTAINER(child),
1715 gtk_scrolled_window_get_vadjustment (scrolledw) );
1716 gtk_scrolled_window_add_with_viewport (scrolledw, child);
1719 gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (scrolledw));
1723 calculate_visible_toolbars (gpointer data,
1726 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (((GtkBoxChild *)data)->widget)))
1727 (*((gint *)user_data)) ++;
1731 toolbar_visible_notify (GtkWidget *toolbar, GParamSpec *pspec,
1732 HildonWindow *window)
1734 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1738 /* Recalculate from scratch the value just in case */
1739 priv->visible_toolbars = 0;
1741 g_list_foreach (GTK_BOX (priv->vbox)->children, calculate_visible_toolbars,
1742 &priv->visible_toolbars);
1744 if (priv->visible_toolbars == 0)
1745 gtk_widget_hide (priv->vbox);
1747 gtk_widget_show (priv->vbox);
1751 * hildon_window_add_toolbar:
1752 * @self: A #HildonWindow
1753 * @toolbar: A #GtkToolbar to add to the #HildonWindow
1755 * Adds a toolbar to the window. Note that the toolbar is not automatically
1756 * shown. You need to call gtk_widget_show_all() on it to make it visible.
1757 * It's also possible to hide the toolbar (without removing it) by calling
1761 hildon_window_add_toolbar (HildonWindow *self,
1762 GtkToolbar *toolbar)
1765 HildonWindowPrivate *priv;
1767 g_return_if_fail (HILDON_IS_WINDOW (self));
1768 g_return_if_fail (toolbar && GTK_IS_TOOLBAR (toolbar));
1770 priv = HILDON_WINDOW_GET_PRIVATE (self);
1772 vbox = GTK_BOX (priv->vbox);
1774 gtk_box_pack_start (vbox, GTK_WIDGET (toolbar), TRUE, TRUE, 0);
1775 gtk_box_reorder_child (vbox, GTK_WIDGET (toolbar), 0);
1776 gtk_widget_set_size_request (GTK_WIDGET (toolbar), -1, TOOLBAR_HEIGHT);
1778 g_signal_connect (G_OBJECT (toolbar), "notify::visible",
1779 G_CALLBACK (toolbar_visible_notify), self);
1781 if (GTK_WIDGET_VISIBLE (toolbar))
1783 priv->visible_toolbars++;
1784 gtk_widget_show (priv->vbox);
1787 gtk_widget_queue_resize (GTK_WIDGET (self));
1791 * hildon_window_remove_toolbar:
1792 * @self: A #HildonWindow
1793 * @toolbar: A #GtkToolbar to remove from the #HildonWindow
1795 * Removes a toolbar from the window. Note that this decreases the refference
1796 * count on the widget. If you want to keep the toolbar alive call g_object_ref()
1797 * before calling this function.
1800 hildon_window_remove_toolbar (HildonWindow *self,
1801 GtkToolbar *toolbar)
1803 HildonWindowPrivate *priv;
1805 g_return_if_fail (HILDON_IS_WINDOW (self));
1807 priv = HILDON_WINDOW_GET_PRIVATE (self);
1809 if (GTK_WIDGET_VISIBLE (toolbar))
1811 if (--(priv->visible_toolbars) == 0)
1812 gtk_widget_hide (priv->vbox);
1815 g_signal_handlers_disconnect_by_func (toolbar, toolbar_visible_notify, self);
1817 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (toolbar));
1821 * hildon_window_set_edit_toolbar:
1822 * @self: A #HildonWindow
1823 * @toolbar: A #HildonEditToolbar, or %NULL to remove the current one.
1825 * Adds a #HildonEditToolbar to the window. Note that the toolbar is
1826 * not automatically shown. You need to call gtk_widget_show() on it
1827 * to make it visible. It's also possible to hide the toolbar (without
1828 * removing it) by calling gtk_widget_hide().
1830 * A window can only have at most one edit toolbar at a time, so the
1831 * previous toolbar (if any) is replaced after calling this function.
1836 hildon_window_set_edit_toolbar (HildonWindow *self,
1837 HildonEditToolbar *toolbar)
1839 HildonWindowPrivate *priv;
1841 g_return_if_fail (HILDON_IS_WINDOW (self));
1842 g_return_if_fail (toolbar == NULL || HILDON_IS_EDIT_TOOLBAR (toolbar));
1844 priv = HILDON_WINDOW_GET_PRIVATE (self);
1846 if (priv->edit_toolbar != GTK_WIDGET (toolbar))
1848 GtkWidget *old_toolbar = priv->edit_toolbar;
1849 priv->edit_toolbar = GTK_WIDGET (toolbar);
1851 if (priv->edit_toolbar)
1852 gtk_widget_set_parent (priv->edit_toolbar, GTK_WIDGET (self));
1855 gtk_widget_unparent (old_toolbar);
1860 * hildon_window_get_main_menu:
1861 * @self: a #HildonWindow
1863 * Gets the #GtkMenu assigned to the #HildonAppview. Note that the
1864 * window is still the owner of the menu.
1866 * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
1867 * you should use hildon_window_get_app_menu() instead.
1869 * Return value: The #GtkMenu assigned to this application view.
1874 hildon_window_get_main_menu (HildonWindow * self)
1876 HildonWindowPrivate *priv;
1878 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
1880 priv = HILDON_WINDOW_GET_PRIVATE (self);
1886 * hildon_window_get_menu:
1887 * @self: a #HildonWindow
1889 * Return value: a #GtkMenu
1891 * Deprecated: In Hildon 2.2 this function has been renamed to
1892 * hildon_window_get_main_menu() for consistency
1895 hildon_window_get_menu (HildonWindow * self)
1897 return hildon_window_get_main_menu (self);
1900 /* Since we've been asking developers to call gtk_window_add_accel_group()
1901 * themselves, do not trigger criticals by trying it again.
1904 hildon_window_add_accel_group (HildonWindow *self,
1905 GtkAccelGroup *accel_group)
1909 groups = gtk_accel_groups_from_object (G_OBJECT (self));
1910 for (l = groups; l != NULL; l = l->next)
1911 if (l->data == (gpointer)accel_group)
1912 /* Maybe print a warning here? */
1915 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
1919 * hildon_window_set_main_menu:
1920 * @self: A #HildonWindow
1921 * @menu: The #GtkMenu to be used for this #HildonWindow
1923 * Sets the menu to be used for this window. This menu overrides
1924 * a program-wide menu that may have been set with
1925 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1926 * menu. #HildonWindow takes ownership of the passed menu and you're
1927 * not supposed to free it yourself anymore.
1929 * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
1930 * you should use hildon_window_set_app_menu() instead.
1933 hildon_window_set_main_menu (HildonWindow* self,
1936 HildonWindowPrivate *priv;
1937 GtkAccelGroup *accel_group;
1939 g_return_if_fail (HILDON_IS_WINDOW (self));
1941 priv = HILDON_WINDOW_GET_PRIVATE (self);
1943 if (priv->menu != NULL)
1945 accel_group = gtk_menu_get_accel_group (priv->menu);
1946 if (accel_group != NULL)
1947 gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
1949 gtk_menu_detach (priv->menu);
1950 g_object_unref (priv->menu);
1954 if (priv->menu != NULL)
1956 gtk_widget_set_name (GTK_WIDGET (priv->menu), "menu_force_with_corners");
1957 gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (self), &detach_menu_func);
1958 g_object_ref (priv->menu);
1960 accel_group = gtk_menu_get_accel_group (priv->menu);
1961 if (accel_group != NULL)
1962 hildon_window_add_accel_group (self, accel_group);
1967 * hildon_window_set_menu:
1968 * @self: A #HildonWindow
1969 * @menu: The #GtkMenu to be used for this #HildonWindow
1971 * Sets the menu to be used for this window. This menu overrides
1972 * a program-wide menu that may have been set with
1973 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1974 * menu. HildonWindow takes ownership of the passed menu and you're
1975 * not supposed to free it yourself anymore.
1977 * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the
1978 * #GtkMenu. To pass control about visibility to the application
1979 * developer, hildon_window_set_main_menu() was introduced, which
1982 * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
1985 hildon_window_set_menu (HildonWindow *self,
1988 HildonWindowPrivate *priv;
1990 g_return_if_fail (HILDON_IS_WINDOW (self));
1992 hildon_window_set_main_menu (self, menu);
1994 priv = HILDON_WINDOW_GET_PRIVATE (self);
1996 if (priv->menu != NULL)
1997 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2001 * hildon_window_get_is_topmost:
2002 * @self: A #HildonWindow
2004 * Returns whether the #HildonWindow is currenty activated by the
2007 * Return value: %TRUE if @self is currently activated, %FALSE otherwise.
2010 hildon_window_get_is_topmost (HildonWindow *self)
2012 HildonWindowPrivate *priv;
2014 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
2016 priv = HILDON_WINDOW_GET_PRIVATE (self);
2017 return priv->is_topmost;
2021 * hildon_window_set_app_menu:
2022 * @self: a #HildonWindow
2023 * @menu: a #HildonAppMenu to be used for this window
2025 * Sets the menu to be used for this window. Pass %NULL to remove the
2026 * current menu. Any reference to a previous menu will be dropped.
2027 * #HildonWindow takes ownership of the passed menu and
2028 * you're not supposed to free it yourself anymore.
2030 * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
2031 * you should use hildon_window_set_main_menu() instead.
2036 hildon_window_set_app_menu (HildonWindow *self,
2037 HildonAppMenu *menu)
2039 HildonWindowPrivate *priv;
2040 HildonAppMenu *old_menu;
2042 g_return_if_fail (HILDON_IS_WINDOW (self));
2043 g_return_if_fail (!menu || HILDON_IS_APP_MENU (menu));
2044 priv = HILDON_WINDOW_GET_PRIVATE (self);
2046 old_menu = priv->app_menu;
2049 priv->app_menu = menu;
2051 g_object_ref_sink (menu);
2053 /* Unref old menu */
2055 g_object_unref (old_menu);
2059 * hildon_window_get_app_menu:
2060 * @self: a #HildonWindow
2062 * Returns the #HildonAppMenu assigned to @self, or %NULL if it's
2063 * unset. Note that the window is still the owner of the menu.
2065 * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
2066 * you should use hildon_window_get_main_menu() instead.
2068 * Returns: a #HildonAppMenu
2073 hildon_window_get_app_menu (HildonWindow *self)
2075 HildonWindowPrivate *priv;
2077 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
2079 priv = HILDON_WINDOW_GET_PRIVATE (self);
2081 return priv->app_menu;
2085 hildon_window_update_markup (HildonWindow *window)
2087 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
2088 GdkAtom markup_atom = gdk_atom_intern ("_HILDON_WM_NAME", FALSE);
2089 GdkAtom utf8_atom = gdk_atom_intern ("UTF8_STRING", FALSE);
2090 GdkWindow *gdkwin = GTK_WIDGET (window)->window;
2093 gdk_property_change (gdkwin, markup_atom, utf8_atom, 8,
2094 GDK_PROP_MODE_REPLACE, (const guchar *) priv->markup,
2095 strlen (priv->markup));
2097 gdk_property_delete (gdkwin, markup_atom);
2102 * hildon_window_get_markup:
2103 * @window: a #HildonWindow
2105 * Gets the marked up title of the window title. See hildon_window_set_markup()
2107 * Returns: the marked up title of the window, or %NULL if none has
2108 * been set explicitely. The returned string is owned by the widget
2109 * and must not be modified or freed.
2114 hildon_window_get_markup (HildonWindow *window)
2116 HildonWindowPrivate *priv;
2118 g_return_val_if_fail (HILDON_IS_WINDOW (window), NULL);
2120 priv = HILDON_WINDOW_GET_PRIVATE (window);
2122 return priv->markup;
2126 * hildon_window_set_markup:
2127 * @window: a #HildonWindow
2128 * @markup: the marked up title of the window, or %NULL to unset the
2131 * Sets the marked up title of @window. The accepted format is the one
2132 * used in Pango (see #PangoMarkupFormat) with the exception of
2135 * Note that you need support from the window manager for this title
2136 * to be used. See gtk_window_set_title() for the standard way of
2137 * setting the title of a window.
2142 hildon_window_set_markup (HildonWindow *window,
2143 const gchar *markup)
2145 HildonWindowPrivate *priv;
2148 g_return_if_fail (HILDON_IS_WINDOW (window));
2150 priv = HILDON_WINDOW_GET_PRIVATE (window);
2152 new_markup = g_strdup (markup);
2153 g_free (priv->markup);
2154 priv->markup = new_markup;
2156 if (GTK_WIDGET_REALIZED (window))
2157 hildon_window_update_markup (window);
2159 g_object_notify (G_OBJECT (window), "markup");