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"
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 LEGACY_MENU_PROPERTY_NAME "_HILDON_WM_WINDOW_TYPE"
113 #define LEGACY_MENU_PROPERTY_VALUE "_HILDON_WM_WINDOW_TYPE_LEGACY_MENU"
115 #define TITLE_SEPARATOR " - "
117 typedef void (*HildonWindowSignal) (HildonWindow *, gint, gpointer);
120 hildon_window_init (HildonWindow * self);
123 hildon_window_class_init (HildonWindowClass * window_class);
126 hildon_window_menu_popup_func (GtkMenu *menu,
132 hildon_window_menu_popup_func_full (GtkMenu *menu,
138 hildon_window_expose (GtkWidget *widget,
139 GdkEventExpose *event);
141 hildon_window_forall (GtkContainer *container,
142 gboolean include_internals,
143 GtkCallback callback,
144 gpointer callback_data);
146 hildon_window_show_all (GtkWidget *widget);
149 hildon_window_size_allocate (GtkWidget * widget,
150 GtkAllocation *allocation);
152 hildon_window_size_request (GtkWidget * widget,
153 GtkRequisition *requisition);
155 hildon_window_finalize (GObject *obj_self);
158 hildon_window_get_property (GObject *object,
164 hildon_window_set_property (GObject *object,
170 hildon_window_update_markup (HildonWindow *window);
173 hildon_window_destroy (GtkObject *obj);
176 hildon_window_realize (GtkWidget *widget);
179 hildon_window_unrealize (GtkWidget *widget);
182 hildon_window_map (GtkWidget *widget);
185 hildon_window_unmap (GtkWidget *widget);
188 hildon_window_key_press_event (GtkWidget *widget,
192 hildon_window_key_release_event (GtkWidget *widget,
195 hildon_window_window_state_event (GtkWidget *widget,
196 GdkEventWindowState *event);
198 hildon_window_focus_out_event (GtkWidget *widget,
199 GdkEventFocus *event);
202 hildon_window_notify (GObject *gobject,
206 hildon_window_is_topmost_notify (HildonWindow *window);
209 hildon_window_toggle_menu (HildonWindow * self,
214 hildon_window_toggle_menu_real (HildonWindow * self,
219 hildon_window_escape_timeout (gpointer data);
221 static GdkFilterReturn
222 hildon_window_event_filter (GdkXEvent *xevent,
226 static GdkFilterReturn
227 hildon_window_root_window_event_filter (GdkXEvent *xevent,
232 hildon_window_get_borders (HildonWindow *window);
235 visible_toolbar (gpointer data,
239 paint_toolbar (GtkWidget *widget,
241 GdkEventExpose * event,
242 gboolean fullscreen);
245 paint_edit_toolbar (GtkWidget *widget,
247 GdkEventExpose *event,
248 gboolean fullscreen);
264 G_DEFINE_TYPE (HildonWindow, hildon_window, GTK_TYPE_WINDOW);
267 hildon_window_class_init (HildonWindowClass * window_class)
269 /* Get convenience variables */
270 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (window_class);
271 GObjectClass *object_class = G_OBJECT_CLASS (window_class);
272 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (window_class);
274 object_class->get_property = hildon_window_get_property;
275 object_class->set_property = hildon_window_set_property;
276 object_class->notify = hildon_window_notify;
277 widget_class->size_allocate = hildon_window_size_allocate;
278 widget_class->size_request = hildon_window_size_request;
279 widget_class->expose_event = hildon_window_expose;
280 widget_class->show_all = hildon_window_show_all;
281 widget_class->realize = hildon_window_realize;
282 widget_class->unrealize = hildon_window_unrealize;
283 widget_class->key_press_event = hildon_window_key_press_event;
284 widget_class->key_release_event = hildon_window_key_release_event;
285 widget_class->window_state_event = hildon_window_window_state_event;
286 widget_class->focus_out_event = hildon_window_focus_out_event;
287 widget_class->map = hildon_window_map;
288 widget_class->unmap = hildon_window_unmap;
290 /* now the object stuff */
291 object_class->finalize = hildon_window_finalize;
293 /* To the container */
294 container_class->forall = hildon_window_forall;
297 window_class->toggle_menu = hildon_window_toggle_menu_real;
300 GTK_OBJECT_CLASS (window_class)->destroy = hildon_window_destroy;
302 g_type_class_add_private (window_class,
303 sizeof (struct _HildonWindowPrivate));
305 /* Install properties */
307 g_object_class_install_property (object_class, PROP_IS_TOPMOST,
308 g_param_spec_boolean ("is-topmost",
310 "Whether the window is currently activated by the window "
315 g_object_class_install_property (object_class, PROP_MARKUP,
316 g_param_spec_string ("markup",
317 "Marked up text for the window title",
318 "Marked up text for the window title",
322 gtk_widget_class_install_style_property (widget_class,
323 g_param_spec_boxed ("borders",
325 "Size of graphical window borders",
329 gtk_widget_class_install_style_property (widget_class,
330 g_param_spec_boxed ("toolbar-borders",
331 "Graphical toolbar borders",
332 "Size of graphical toolbar borders",
336 /* opera hack, install clip operation signal */
337 g_signal_new ("clipboard_operation",
338 G_OBJECT_CLASS_TYPE (object_class),
340 G_STRUCT_OFFSET (HildonWindowClass, clipboard_operation),
342 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1,
347 hildon_window_init (HildonWindow *self)
349 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
350 g_assert (priv != NULL);
352 priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
353 gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
355 priv->app_menu = NULL;
356 priv->edit_toolbar = NULL;
357 priv->visible_toolbars = 0;
358 priv->is_topmost = FALSE;
359 priv->borders = NULL;
360 priv->toolbar_borders = NULL;
361 priv->escape_timeout = 0;
364 priv->fullscreen = FALSE;
366 priv->program = NULL;
368 /* We need to track the root window _MB_CURRENT_APP_WINDOW property */
369 gdk_window_set_events (gdk_get_default_root_window (),
370 gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK);
372 gdk_window_add_filter (gdk_get_default_root_window (),
373 hildon_window_root_window_event_filter, self);
377 hildon_window_finalize (GObject * obj_self)
379 HildonWindowPrivate *priv;
381 g_return_if_fail (HILDON_WINDOW (obj_self));
383 priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
384 g_assert (priv != NULL);
386 g_free (priv->markup);
388 if (priv->escape_timeout) {
389 g_source_remove (priv->escape_timeout);
390 priv->escape_timeout = 0;
394 gtk_border_free (priv->borders);
396 if (priv->toolbar_borders)
397 gtk_border_free (priv->toolbar_borders);
399 if (G_OBJECT_CLASS (hildon_window_parent_class)->finalize)
400 G_OBJECT_CLASS (hildon_window_parent_class)->finalize (obj_self);
405 hildon_window_realize (GtkWidget *widget)
407 Atom *old_atoms, *new_atoms;
411 Window active_window;
412 HildonWindowPrivate *priv;
414 GTK_WIDGET_CLASS (hildon_window_parent_class)->realize (widget);
416 priv = HILDON_WINDOW_GET_PRIVATE (widget);
417 g_assert (priv != NULL);
419 gtk_widget_realize (GTK_WIDGET (priv->vbox));
421 if (priv->edit_toolbar != NULL)
422 gtk_widget_realize (priv->edit_toolbar);
424 /* catch the custom button signal from mb to display the menu */
425 gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
427 window = GDK_WINDOW_XID (widget->window);
428 disp = GDK_WINDOW_XDISPLAY (widget->window);
430 /* Enable custom button that is used for menu */
431 XGetWMProtocols (disp, window, &old_atoms, &atom_count);
432 new_atoms = g_new (Atom, atom_count + 1);
434 memcpy (new_atoms, old_atoms, sizeof(Atom) * atom_count);
436 new_atoms[atom_count++] =
437 XInternAtom (disp, "_NET_WM_CONTEXT_CUSTOM", False);
439 XSetWMProtocols (disp, window, new_atoms, atom_count);
444 /* rely on GDK to set the window group to its default */
445 gdk_window_set_group (widget->window, NULL);
448 gboolean can_hibernate = hildon_program_get_can_hibernate (priv->program);
450 hildon_window_set_can_hibernate_property (HILDON_WINDOW (widget),
455 hildon_window_update_markup (HILDON_WINDOW (widget));
457 /* Update the topmost status */
458 active_window = hildon_window_get_active_window();
459 hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
463 hildon_window_unrealize (GtkWidget *widget)
465 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
466 g_assert (priv != NULL);
468 gdk_window_remove_filter (widget->window, hildon_window_event_filter,
471 gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
473 if (priv->edit_toolbar != NULL)
474 gtk_widget_unrealize (priv->edit_toolbar);
476 GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
480 hildon_window_map (GtkWidget *widget)
482 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
483 g_assert (priv != NULL);
485 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->map)
486 GTK_WIDGET_CLASS (hildon_window_parent_class)->map (widget);
488 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
489 gtk_widget_map (priv->vbox);
491 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
492 gtk_widget_map (priv->edit_toolbar);
496 hildon_window_unmap (GtkWidget *widget)
498 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
499 g_assert (priv != NULL);
501 gtk_widget_unmap (priv->vbox);
503 if (priv->edit_toolbar != NULL)
504 gtk_widget_unmap (priv->edit_toolbar);
506 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
507 GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
511 hildon_window_get_property (GObject *object,
516 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (object);
517 g_assert (priv != NULL);
519 switch (property_id) {
521 case PROP_IS_TOPMOST:
522 g_value_set_boolean (value, priv->is_topmost);
526 g_value_set_string (value, priv->markup);
530 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
536 hildon_window_set_property (GObject *object,
541 switch (property_id) {
544 hildon_window_set_markup (HILDON_WINDOW (object), g_value_get_string (value));
548 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
554 * Retrieve the graphical borders size used by the themes
557 hildon_window_get_borders (HildonWindow *window)
559 GtkBorder zero = {0, 0, 0, 0};
560 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
563 GtkBorder *borders = NULL;
564 GtkBorder *toolbar_borders = NULL;
567 gtk_border_free (priv->borders);
568 if (priv->toolbar_borders)
569 gtk_border_free (priv->toolbar_borders);
571 priv->borders = NULL;
572 priv->toolbar_borders = NULL;
574 gtk_widget_style_get (GTK_WIDGET (window), "borders",&borders,
575 "toolbar-borders", &toolbar_borders,
578 // We're doing a copy here instead of reusing the pointer,
579 // as we don't know where it comes from (has it been allocated using
580 // malloc or slices... and we want to free it sanely. Blowing on
584 priv->borders = gtk_border_copy (borders);
585 gtk_border_free (borders);
587 priv->borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
589 if (toolbar_borders) {
590 priv->toolbar_borders = gtk_border_copy (toolbar_borders);
591 gtk_border_free (toolbar_borders);
593 priv->toolbar_borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
597 hildon_window_expose (GtkWidget *widget,
598 GdkEventExpose * event)
600 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
603 GtkWidget *bx = priv->vbox;
604 GtkBox *box = GTK_BOX(bx);
605 GtkBorder *b = priv->borders;
606 GtkBorder *tb = priv->toolbar_borders;
609 if (! priv->borders) {
610 hildon_window_get_borders (HILDON_WINDOW (widget));
612 tb = priv->toolbar_borders;
615 tb_height = bx->allocation.height + tb->top + tb->bottom;
617 paint_toolbar (widget, box,
618 event, priv->fullscreen);
620 if (priv->edit_toolbar != NULL)
622 paint_edit_toolbar (widget, priv->edit_toolbar,
623 event, priv->fullscreen);
626 if (! priv->fullscreen) {
628 /* Draw the left and right window border */
629 gint side_borders_height = widget->allocation.height - b->top;
631 if (priv->visible_toolbars)
632 side_borders_height -= tb_height;
634 side_borders_height -= b->bottom;
638 gtk_paint_box (widget->style, widget->window,
639 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
640 &event->area, widget, "left-border",
641 widget->allocation.x, widget->allocation.y +
642 b->top, b->left, side_borders_height);
647 gtk_paint_box (widget->style, widget->window,
648 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
649 &event->area, widget, "right-border",
650 widget->allocation.x + widget->allocation.width -
651 b->right, widget->allocation.y + b->top,
652 b->right, side_borders_height);
655 /* If no toolbar, draw the bottom window border */
656 if (! priv->visible_toolbars && b->bottom > 0)
658 gtk_paint_box (widget->style, widget->window,
659 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
660 &event->area, widget, "bottom-border",
661 widget->allocation.x, widget->allocation.y +
662 (widget->allocation.height - b->bottom),
663 widget->allocation.width, b->bottom);
666 /* Draw the top border */
669 gtk_paint_box (widget->style, widget->window,
670 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
671 &event->area, widget, "top-border",
672 widget->allocation.x, widget->allocation.y,
673 widget->allocation.width, b->top);
679 /* don't draw the window stuff as it overwrites our borders with a blank
680 * rectangle. Instead start with the drawing of the GtkBin */
681 GTK_WIDGET_CLASS (g_type_class_peek_parent (hildon_window_parent_class))->expose_event (widget, event);
683 /* FIXME Not sure why this is commented out
684 * GTK_WIDGET_CLASS (hildon_window_parent_class))->
685 * expose_event (widget, event);
692 hildon_window_size_request (GtkWidget *widget,
693 GtkRequisition *requisition)
695 GdkScreen *screen = gtk_widget_get_screen (widget);
696 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
701 child = gtk_bin_get_child (GTK_BIN (widget));
703 if (child != NULL && GTK_WIDGET_VISIBLE (child))
704 gtk_widget_size_request (child, &req);
706 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
707 gtk_widget_size_request (priv->vbox, &req);
709 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
710 gtk_widget_size_request (priv->edit_toolbar, &req);
712 /* Request the full size of the screen */
713 requisition->width = gdk_screen_get_width (screen);
714 requisition->height = gdk_screen_get_height (screen);
716 if (! priv->fullscreen)
717 requisition->height -= HILDON_WINDOW_TITLEBAR_HEIGHT;
721 hildon_window_size_allocate (GtkWidget *widget,
722 GtkAllocation *allocation)
724 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
727 GtkAllocation box_alloc = { 0 };
728 GtkAllocation edittb_alloc = { 0 };
729 GtkAllocation alloc = *allocation;
731 GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
735 hildon_window_get_borders (HILDON_WINDOW (widget));
737 tb = priv->toolbar_borders;
739 widget->allocation = *allocation;
741 /* Calculate allocation of edit toolbar */
742 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
745 gtk_widget_get_child_requisition (priv->edit_toolbar, &req);
746 edittb_alloc.width = alloc.width - tb->left - tb->right;
747 edittb_alloc.height = MIN (req.height, alloc.height);
748 edittb_alloc.x = alloc.x + tb->left;
749 edittb_alloc.y = alloc.y + tb->top;
751 if (edittb_alloc.height > 0)
753 alloc.y += tb->top + tb->bottom + edittb_alloc.height;
754 alloc.height -= tb->top + tb->bottom + edittb_alloc.height;
755 gtk_widget_size_allocate (priv->edit_toolbar, &edittb_alloc);
759 /* Calculate allocation of normal toolbars */
760 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
763 gtk_widget_get_child_requisition (priv->vbox, &req);
764 box_alloc.width = alloc.width - tb->left - tb->right;
765 box_alloc.height = MIN (req.height, alloc.height);
766 box_alloc.x = alloc.x + tb->left;
767 box_alloc.y = alloc.y + alloc.height - box_alloc.height - tb->bottom;
769 if (box_alloc.height > 0)
771 alloc.height -= tb->top + tb->bottom + box_alloc.height;
772 gtk_widget_size_allocate (priv->vbox, &box_alloc);
776 /* Calculate allocation of the child widget */
777 if (child != NULL && GTK_WIDGET_VISIBLE (child))
779 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
780 alloc.x += border_width;
781 alloc.y += border_width;
782 alloc.width -= (border_width * 2);
783 alloc.height -= (border_width * 2);
785 if (! priv->fullscreen)
787 GtkBorder *b = priv->borders;
789 alloc.width -= (b->left + b->right);
791 /* Use the top border if there's no edit toolbar */
792 if (edittb_alloc.height <= 0)
795 alloc.height -= b->top;
798 /* Use the top border if there are no standard toolbars */
799 if (box_alloc.height <= 0)
800 alloc.height -= b->bottom;
803 gtk_widget_size_allocate (child, &alloc);
806 if (priv->previous_vbox_y != box_alloc.y)
808 /* The size of the VBox has changed, we need to redraw part
809 * of the window borders */
810 gint draw_from_y = MIN (priv->previous_vbox_y, box_alloc.y) - tb->top;
812 gtk_widget_queue_draw_area (widget, 0, draw_from_y,
813 widget->allocation.width,
814 widget->allocation.height - draw_from_y);
816 priv->previous_vbox_y = box_alloc.y;
822 hildon_window_forall (GtkContainer *container,
823 gboolean include_internals,
824 GtkCallback callback,
825 gpointer callback_data)
827 HildonWindow *self = HILDON_WINDOW (container);
828 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
830 g_return_if_fail (callback != NULL);
833 GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
834 callback, callback_data);
836 if (include_internals && priv->vbox != NULL)
837 (* callback)(GTK_WIDGET (priv->vbox), callback_data);
839 if (include_internals && priv->edit_toolbar != NULL)
840 (* callback)(GTK_WIDGET (priv->edit_toolbar), callback_data);
844 hildon_window_show_all (GtkWidget *widget)
846 HildonWindow *self = HILDON_WINDOW (widget);
847 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
849 g_assert (priv != NULL);
851 GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
853 gtk_widget_show_all (priv->vbox);
855 if (priv->edit_toolbar)
856 gtk_widget_show_all (priv->edit_toolbar);
860 hildon_window_destroy (GtkObject *obj)
862 HildonWindow *self = HILDON_WINDOW (obj);
863 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (obj);
864 GList *menu_list = NULL;
865 GList *menu_node = NULL;
867 g_assert (priv != NULL);
869 if (priv->vbox != NULL)
873 GtkWidget * common_toolbar =
874 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
875 if (common_toolbar && common_toolbar->parent == priv->vbox)
877 gtk_container_remove (GTK_CONTAINER (priv->vbox),
882 gtk_widget_unparent (priv->vbox);
887 if (priv->edit_toolbar != NULL)
889 gtk_widget_unparent (priv->edit_toolbar);
890 priv->edit_toolbar = NULL;
895 hildon_app_menu_set_parent_window (priv->app_menu, NULL);
896 g_object_unref (priv->app_menu);
897 priv->app_menu = NULL;
900 menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
901 menu_node = menu_list;
905 if (GTK_IS_MENU (menu_node->data))
907 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_node->data)))
909 gtk_menu_popdown (GTK_MENU (menu_node->data));
910 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_node->data));
912 gtk_menu_detach (GTK_MENU (menu_node->data));
914 /* Destroy it, but only if it's not a common menu */
916 hildon_program_get_common_menu (priv->program) != menu_node->data) {
917 gtk_object_destroy (GTK_OBJECT (menu_node->data));
918 g_object_unref (menu_node->data);
921 menu_node = menu_node->next;
924 g_list_free (menu_list);
929 hildon_program_remove_window (priv->program, self);
932 gdk_window_remove_filter (gdk_get_default_root_window(),
933 hildon_window_root_window_event_filter,
936 gtk_widget_set_events (GTK_WIDGET(obj), 0);
938 GTK_OBJECT_CLASS (hildon_window_parent_class)->destroy (obj);
942 hildon_window_notify (GObject *gobject,
945 HildonWindow *window = HILDON_WINDOW (gobject);
947 if (g_str_equal (param->name, "is-topmost"))
949 hildon_window_is_topmost_notify (window);
952 if (G_OBJECT_CLASS(hildon_window_parent_class)->notify)
953 G_OBJECT_CLASS(hildon_window_parent_class)->notify (gobject, param);
958 visible_toolbar (gpointer data,
961 if (GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
962 (*((gint *)user_data))++;
966 paint_toolbar (GtkWidget *widget,
968 GdkEventExpose * event,
971 gint toolbar_num = 0;
974 /* collect info to help on painting the boxes */
975 g_list_foreach (box->children, visible_toolbar,
976 (gpointer) &toolbar_num);
981 /*top most toolbar painting*/
982 gtk_paint_box (widget->style, widget->window,
983 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
984 &event->area, widget, "toolbar-primary",
985 widget->allocation.x,
986 GTK_WIDGET(box)->allocation.y,
987 widget->allocation.width,
990 /*multi toolbar painting*/
991 for (count = 0; count < toolbar_num - 1; count++)
993 gtk_paint_box (widget->style, widget->window,
994 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
995 &event->area, widget, "toolbar-secondary",
996 widget->allocation.x,
997 GTK_WIDGET(box)->allocation.y +
998 (1 + count) * (TOOLBAR_HEIGHT),
999 widget->allocation.width,
1005 paint_edit_toolbar (GtkWidget *widget,
1007 GdkEventExpose *event,
1008 gboolean fullscreen)
1010 if (!GTK_WIDGET_VISIBLE (toolbar))
1013 gtk_paint_box (widget->style, widget->window,
1014 GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
1015 &event->area, widget, "toolbar-edit-mode",
1016 toolbar->allocation.x,
1017 toolbar->allocation.y,
1018 toolbar->allocation.width,
1019 toolbar->allocation.height);
1023 * Checks the root window to know which is the topped window
1026 hildon_window_get_active_window (void)
1034 unsigned long extra;
1038 unsigned char *char_pointer;
1040 Atom active_app_atom =
1041 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1045 gdk_error_trap_push ();
1046 status = XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1047 active_app_atom, 0L, 16L,
1048 0, XA_WINDOW, &realtype, &format,
1049 &n, &extra, &win.char_pointer);
1050 xerror = gdk_error_trap_pop ();
1051 if (xerror || !(status == Success && realtype == XA_WINDOW && format == 32
1052 && n == 1 && win.win != NULL))
1054 if (win.win != NULL)
1055 XFree (win.char_pointer);
1061 if (win.win != NULL)
1062 XFree(win.char_pointer);
1068 xclient_message_type_check (XClientMessageEvent *cm,
1071 return cm->message_type == XInternAtom(GDK_DISPLAY(), name, FALSE);
1075 * Handle the window border custom button, which toggles the menu,
1076 * and the Hildon input method copy paste messages
1078 static GdkFilterReturn
1079 hildon_window_event_filter (GdkXEvent *xevent,
1083 XAnyEvent *eventti = xevent;
1085 if (eventti->type == ClientMessage)
1087 XClientMessageEvent *cm = xevent;
1089 if (xclient_message_type_check (cm, "_MB_GRAB_TRANSFER"))
1091 hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]);
1092 return GDK_FILTER_REMOVE;
1094 /* opera hack clipboard client message */
1095 else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY"))
1097 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1098 HILDON_WINDOW_CO_COPY);
1099 return GDK_FILTER_REMOVE;
1101 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT"))
1103 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1104 HILDON_WINDOW_CO_CUT);
1105 return GDK_FILTER_REMOVE;
1107 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE"))
1109 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1110 HILDON_WINDOW_CO_PASTE);
1111 return GDK_FILTER_REMOVE;
1115 return GDK_FILTER_CONTINUE;
1119 * Here we keep track of changes in the _MB_CURRENT_APP_WINDOW,
1120 * to know when we acquire/lose topmost status
1122 static GdkFilterReturn
1123 hildon_window_root_window_event_filter (GdkXEvent *xevent,
1127 XAnyEvent *eventti = xevent;
1128 HildonWindow *hwindow = HILDON_WINDOW (data);
1130 if (eventti->type == PropertyNotify)
1132 XPropertyEvent *pevent = xevent;
1133 Atom active_app_atom =
1134 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1136 if (pevent->atom == active_app_atom)
1138 Window active_window = hildon_window_get_active_window();
1140 hildon_window_update_topmost (hwindow, active_window);
1144 return GDK_FILTER_CONTINUE;
1148 * Handle the menu hardware key here
1151 hildon_window_key_press_event (GtkWidget *widget,
1154 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1156 g_return_val_if_fail (HILDON_IS_WINDOW (widget),FALSE);
1159 switch (event->keyval)
1161 case HILDON_HARDKEY_MENU:
1162 if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME))
1165 case HILDON_HARDKEY_ESC:
1166 if (!priv->escape_timeout)
1168 priv->escape_timeout = g_timeout_add
1169 (HILDON_WINDOW_LONG_PRESS_TIME,
1170 hildon_window_escape_timeout, widget);
1175 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event);
1179 hildon_window_key_release_event (GtkWidget *widget,
1182 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1184 g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE);
1187 switch (event->keyval)
1189 case HILDON_HARDKEY_ESC:
1190 if (priv->escape_timeout)
1192 g_source_remove (priv->escape_timeout);
1193 priv->escape_timeout = 0;
1198 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event);
1203 * We keep track of the window state changes, because the drawing
1204 * (borders) differs whether we are in fullscreen mode or not
1207 hildon_window_window_state_event (GtkWidget *widget,
1208 GdkEventWindowState *event)
1210 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1211 g_assert (priv != NULL);
1213 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1214 priv->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1216 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event)
1218 return GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event (
1229 * If the window lost focus while the user started to press the ESC key, we
1230 * won't get the release event. We need to stop the timeout.
1233 hildon_window_focus_out_event (GtkWidget *widget,
1234 GdkEventFocus *event)
1236 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1238 if (priv->escape_timeout)
1240 g_source_remove (priv->escape_timeout);
1241 priv->escape_timeout = 0;
1244 return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event);
1248 set_legacy_menu_type (GtkMenu *menu,
1251 GdkWindow *gdkwin = GTK_WIDGET (menu->toplevel)->window;
1252 GdkAtom property = gdk_atom_intern_static_string (LEGACY_MENU_PROPERTY_NAME);
1254 GdkAtom type = gdk_x11_xatom_to_atom (XA_ATOM);
1255 GdkAtom value = gdk_atom_intern_static_string (LEGACY_MENU_PROPERTY_VALUE);
1256 gdk_property_change (gdkwin, property, type, 32,
1257 GDK_PROP_MODE_REPLACE, (const guchar *) &value, 1);
1259 gdk_property_delete (gdkwin, property);
1264 legacy_menu_realized (GtkMenu *menu)
1266 set_legacy_menu_type (menu, TRUE);
1267 g_signal_handlers_disconnect_by_func (menu, legacy_menu_realized, NULL);
1271 legacy_menu_unmapped (GtkMenu *menu)
1273 set_legacy_menu_type (menu, FALSE);
1274 g_signal_handlers_disconnect_by_func (menu, legacy_menu_unmapped, NULL);
1278 * The menu popuping needs a menu popup-function
1281 hildon_window_menu_popup_func (GtkMenu *menu,
1289 GdkWindow *window = GTK_WIDGET(widget)->window;
1293 gdk_window_get_origin (window, &window_x, &window_y);
1296 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1297 "vertical-offset", y, NULL);
1299 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1301 *x = GTK_WIDGET (widget)->allocation.width + window_x - GTK_WIDGET (menu)->allocation.width - *x;
1311 hildon_window_menu_popup_func_full (GtkMenu *menu,
1317 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1318 "vertical-offset", y, NULL);
1320 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1321 *x = GTK_WIDGET (widget)->allocation.width - GTK_WIDGET (menu)->allocation.width - *x;
1330 * Takes the common toolbar when we acquire the top-most status
1333 hildon_window_is_topmost_notify (HildonWindow *window)
1335 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1339 if (priv->is_topmost)
1341 hildon_window_take_common_toolbar (window);
1346 * Sets the program to which the window belongs. This should only be called
1347 * by hildon_program_add_window
1349 void G_GNUC_INTERNAL
1350 hildon_window_set_program (HildonWindow *self,
1353 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1355 g_return_if_fail (HILDON_IS_WINDOW (self));
1356 g_assert (priv != NULL);
1360 g_object_unref (priv->program);
1363 /* Now that we are bound to a program, we can rely on it to track the
1365 gdk_window_remove_filter (gdk_get_default_root_window(),
1366 hildon_window_root_window_event_filter,
1369 priv->program = HILDON_PROGRAM (program);
1370 g_object_ref (program);
1374 * Unsets the program to which the window belongs. This should only be called
1375 * by hildon_program_remove_window
1377 void G_GNUC_INTERNAL
1378 hildon_window_unset_program (HildonWindow *self)
1380 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1382 g_return_if_fail(HILDON_IS_WINDOW (self));
1383 g_assert (priv != NULL);
1387 g_object_unref (priv->program);
1388 priv->program = NULL;
1390 /* We need to start tacking the root window again */
1391 gdk_window_set_events (gdk_get_default_root_window (),
1392 gdk_window_get_events (gdk_get_default_root_window ())
1393 | GDK_PROPERTY_CHANGE_MASK);
1395 gdk_window_add_filter (gdk_get_default_root_window (),
1396 hildon_window_root_window_event_filter, self );
1399 priv->program = NULL;
1403 * Sets whether or not the program to which this window belongs is
1404 * killable. This is used by the HildonProgram to signify to the
1405 * Task Navigator whether or not it can hibernate in memory-low situations
1407 void G_GNUC_INTERNAL
1408 hildon_window_set_can_hibernate_property (HildonWindow *self,
1409 gpointer _can_hibernate)
1411 GdkAtom killable_atom;
1412 gboolean can_hibernate;
1414 g_return_if_fail(self && HILDON_IS_WINDOW (self));
1416 if (!GTK_WIDGET_REALIZED ((GTK_WIDGET (self))))
1421 can_hibernate = * ((gboolean *)_can_hibernate);
1423 killable_atom = gdk_atom_intern (CAN_HIBERNATE_PROPERTY, FALSE);
1427 gdk_property_change (GTK_WIDGET (self)->window, killable_atom,
1428 (GdkAtom)31/* XA_STRING */, 8,
1429 GDK_PROP_MODE_REPLACE, (const guchar *)CAN_HIBERNATE,
1430 CAN_HIBERNATE_LENGTH);
1434 gdk_property_delete (GTK_WIDGET (self)->window, killable_atom);
1440 * If a common toolbar was set to the program, reparent it to
1443 void G_GNUC_INTERNAL
1444 hildon_window_take_common_toolbar (HildonWindow *self)
1446 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1448 g_return_if_fail(HILDON_IS_WINDOW (self));
1453 GtkWidget *common_toolbar =
1454 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
1456 if (common_toolbar && common_toolbar->parent != priv->vbox)
1458 g_object_ref (common_toolbar);
1459 if (common_toolbar->parent)
1461 gtk_container_remove (GTK_CONTAINER (common_toolbar->parent),
1465 gtk_box_pack_end (GTK_BOX(priv->vbox), common_toolbar,
1467 g_object_unref (common_toolbar);
1469 gtk_widget_set_size_request (common_toolbar, -1, TOOLBAR_HEIGHT);
1471 gtk_widget_show (priv->vbox);
1478 * Compare the window that was last topped, and act consequently
1481 hildon_window_update_topmost (HildonWindow *self,
1484 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1486 GdkWindow *my_window;
1488 g_return_if_fail (HILDON_IS_WINDOW (self));
1491 my_window = GTK_WIDGET (self)->window;
1493 if (my_window && window_id == GDK_WINDOW_XID (my_window))
1495 if (! priv->is_topmost)
1497 priv->is_topmost = TRUE;
1498 hildon_window_is_topmost_notify (self);
1499 g_object_notify (G_OBJECT (self), "is-topmost");
1502 else if (priv->is_topmost)
1504 /* Should this go in the signal handler? */
1505 GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (self));
1507 if (GTK_IS_ENTRY (focus))
1508 gtk_im_context_focus_out (GTK_ENTRY (focus)->im_context);
1509 if (GTK_IS_TEXT_VIEW (focus))
1510 gtk_im_context_focus_out (GTK_TEXT_VIEW (focus)->im_context);
1512 priv->is_topmost = FALSE;
1513 hildon_window_is_topmost_notify (self);
1514 g_object_notify (G_OBJECT (self), "is-topmost");
1519 detach_menu_func (GtkWidget *attach_widget,
1522 /* FIXME Why is this even needed here? */
1526 hildon_window_toggle_menu (HildonWindow *self,
1530 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1532 if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
1534 return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
1544 hildon_window_toggle_gtk_menu (HildonWindow *self,
1549 gboolean retvalue = FALSE;
1551 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1552 g_return_val_if_fail (GTK_IS_MENU (menu), FALSE);
1554 if (gtk_menu_get_attach_widget (menu) != GTK_WIDGET (self))
1556 g_object_ref (menu);
1557 if (gtk_menu_get_attach_widget (menu))
1559 gtk_menu_detach (menu);
1561 gtk_menu_attach_to_widget (menu, GTK_WIDGET (self), &detach_menu_func);
1562 g_object_unref (menu);
1565 if (GTK_WIDGET_MAPPED (menu))
1567 gtk_menu_popdown (menu);
1568 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu));
1573 /* Check if the menu has items */
1574 GList *menu_children = gtk_container_get_children (GTK_CONTAINER (menu));
1578 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1579 g_list_free (menu_children);
1581 /* Set the 'legacy app menu' property when the widget is realized */
1582 if (GTK_WIDGET_REALIZED (menu)) {
1583 set_legacy_menu_type (menu, TRUE);
1585 g_signal_connect (menu, "realize",
1586 G_CALLBACK (legacy_menu_realized), NULL);
1589 /* Remove it when it's unmapped */
1590 g_signal_connect (menu, "unmap",
1591 G_CALLBACK (legacy_menu_unmapped), NULL);
1593 /* Apply right theming */
1594 gtk_widget_set_name (GTK_WIDGET (menu), "menu_force_with_corners");
1596 if (priv->fullscreen)
1598 gtk_menu_popup (menu, NULL, NULL,
1599 (GtkMenuPositionFunc)
1600 hildon_window_menu_popup_func_full,
1601 self, button, time);
1605 gtk_menu_popup (menu, NULL, NULL,
1606 (GtkMenuPositionFunc)
1607 hildon_window_menu_popup_func,
1608 self, button, time);
1610 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE);
1619 hildon_window_toggle_app_menu (HildonWindow *self,
1620 HildonAppMenu *menu)
1622 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1623 g_return_val_if_fail (HILDON_IS_APP_MENU (menu), FALSE);
1625 if (self != hildon_app_menu_get_parent_window (menu))
1627 gtk_widget_hide (GTK_WIDGET (menu));
1630 if (GTK_WIDGET_MAPPED (menu))
1632 gtk_widget_hide (GTK_WIDGET (menu));
1636 hildon_app_menu_popup (menu, GTK_WINDOW (self));
1643 * Toggles the display of the HildonWindow menu.
1644 * Returns whether or not something was done (whether or not we had a menu
1648 hildon_window_toggle_menu_real (HildonWindow * self,
1652 gboolean retvalue = FALSE;
1653 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1655 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1657 /* Select which menu to use, Window specific has highest priority,
1658 * then program specific */
1661 retvalue = hildon_window_toggle_gtk_menu (self, priv->menu, button, time);
1663 else if (priv->app_menu)
1665 retvalue = hildon_window_toggle_app_menu (self, priv->app_menu);
1667 else if (priv->program)
1669 GtkMenu *gtkmenu = hildon_program_get_common_menu (priv->program);
1670 HildonAppMenu *appmenu = hildon_program_get_common_app_menu (priv->program);
1674 retvalue = hildon_window_toggle_gtk_menu (self, gtkmenu, button, time);
1678 retvalue = hildon_window_toggle_app_menu (self, appmenu);
1686 * If the ESC key was not released when the timeout expires,
1690 hildon_window_escape_timeout (gpointer data)
1692 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data);
1697 GDK_THREADS_ENTER ();
1699 /* Send fake event, simulation a situation that user
1700 pressed 'x' from the corner */
1701 event = gdk_event_new(GDK_DELETE);
1702 ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window));
1703 gtk_main_do_event(event);
1705 /* That unrefs the window, so we're reffing it above */
1706 gdk_event_free(event);
1708 priv->escape_timeout = 0;
1710 GDK_THREADS_LEAVE ();
1716 * hildon_window_new:
1718 * Creates a new #HildonWindow.
1720 * Return value: A #HildonWindow.
1723 hildon_window_new (void)
1725 HildonWindow *newwindow = g_object_new (HILDON_TYPE_WINDOW, NULL);
1727 return GTK_WIDGET (newwindow);
1731 * hildon_window_add_with_scrollbar:
1732 * @self: A #HildonWindow
1733 * @child: A #GtkWidget
1735 * Adds @child to the #HildonWindow and creates a scrollbar for
1736 * it. Similar to adding first a #GtkScrolledWindow and then @child to
1740 hildon_window_add_with_scrollbar (HildonWindow *self,
1743 GtkScrolledWindow *scrolledw;
1745 g_return_if_fail (HILDON_IS_WINDOW (self));
1746 g_return_if_fail (GTK_IS_WIDGET (child));
1747 g_return_if_fail (child->parent == NULL);
1749 scrolledw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1750 gtk_scrolled_window_set_policy (scrolledw, GTK_POLICY_NEVER,
1751 GTK_POLICY_AUTOMATIC);
1752 gtk_scrolled_window_set_shadow_type (scrolledw, GTK_SHADOW_NONE);
1754 if (GTK_IS_VIEWPORT (child))
1755 gtk_container_add (GTK_CONTAINER (scrolledw), child);
1758 if (GTK_IS_CONTAINER (child) )
1759 gtk_container_set_focus_vadjustment (GTK_CONTAINER(child),
1760 gtk_scrolled_window_get_vadjustment (scrolledw) );
1761 gtk_scrolled_window_add_with_viewport (scrolledw, child);
1764 gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (scrolledw));
1768 calculate_visible_toolbars (gpointer data,
1771 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (((GtkBoxChild *)data)->widget)))
1772 (*((gint *)user_data)) ++;
1776 toolbar_visible_notify (GtkWidget *toolbar, GParamSpec *pspec,
1777 HildonWindow *window)
1779 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1783 /* Recalculate from scratch the value just in case */
1784 priv->visible_toolbars = 0;
1786 g_list_foreach (GTK_BOX (priv->vbox)->children, calculate_visible_toolbars,
1787 &priv->visible_toolbars);
1789 if (priv->visible_toolbars == 0)
1790 gtk_widget_hide (priv->vbox);
1792 gtk_widget_show (priv->vbox);
1796 * hildon_window_add_toolbar:
1797 * @self: A #HildonWindow
1798 * @toolbar: A #GtkToolbar to add to the #HildonWindow
1800 * Adds a toolbar to the window. Note that the toolbar is not automatically
1801 * shown. You need to call gtk_widget_show_all() on it to make it visible.
1802 * It's also possible to hide the toolbar (without removing it) by calling
1806 hildon_window_add_toolbar (HildonWindow *self,
1807 GtkToolbar *toolbar)
1810 HildonWindowPrivate *priv;
1812 g_return_if_fail (HILDON_IS_WINDOW (self));
1813 g_return_if_fail (toolbar && GTK_IS_TOOLBAR (toolbar));
1815 priv = HILDON_WINDOW_GET_PRIVATE (self);
1817 vbox = GTK_BOX (priv->vbox);
1819 gtk_box_pack_start (vbox, GTK_WIDGET (toolbar), TRUE, TRUE, 0);
1820 gtk_box_reorder_child (vbox, GTK_WIDGET (toolbar), 0);
1821 gtk_widget_set_size_request (GTK_WIDGET (toolbar), -1, TOOLBAR_HEIGHT);
1823 g_signal_connect (G_OBJECT (toolbar), "notify::visible",
1824 G_CALLBACK (toolbar_visible_notify), self);
1826 if (GTK_WIDGET_VISIBLE (toolbar))
1828 priv->visible_toolbars++;
1829 gtk_widget_show (priv->vbox);
1832 gtk_widget_queue_resize (GTK_WIDGET (self));
1836 * hildon_window_remove_toolbar:
1837 * @self: A #HildonWindow
1838 * @toolbar: A #GtkToolbar to remove from the #HildonWindow
1840 * Removes a toolbar from the window. Note that this decreases the refference
1841 * count on the widget. If you want to keep the toolbar alive call g_object_ref()
1842 * before calling this function.
1845 hildon_window_remove_toolbar (HildonWindow *self,
1846 GtkToolbar *toolbar)
1848 HildonWindowPrivate *priv;
1850 g_return_if_fail (HILDON_IS_WINDOW (self));
1852 priv = HILDON_WINDOW_GET_PRIVATE (self);
1854 if (GTK_WIDGET_VISIBLE (toolbar))
1856 if (--(priv->visible_toolbars) == 0)
1857 gtk_widget_hide (priv->vbox);
1860 g_signal_handlers_disconnect_by_func (toolbar, toolbar_visible_notify, self);
1862 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (toolbar));
1866 * hildon_window_set_edit_toolbar:
1867 * @self: A #HildonWindow
1868 * @toolbar: A #HildonEditToolbar, or %NULL to remove the current one.
1870 * Adds a #HildonEditToolbar to the window. Note that the toolbar is
1871 * not automatically shown. You need to call gtk_widget_show() on it
1872 * to make it visible. It's also possible to hide the toolbar (without
1873 * removing it) by calling gtk_widget_hide().
1875 * A window can only have at most one edit toolbar at a time, so the
1876 * previous toolbar (if any) is replaced after calling this function.
1881 hildon_window_set_edit_toolbar (HildonWindow *self,
1882 HildonEditToolbar *toolbar)
1884 HildonWindowPrivate *priv;
1886 g_return_if_fail (HILDON_IS_WINDOW (self));
1887 g_return_if_fail (toolbar == NULL || HILDON_IS_EDIT_TOOLBAR (toolbar));
1889 priv = HILDON_WINDOW_GET_PRIVATE (self);
1891 if (priv->edit_toolbar != GTK_WIDGET (toolbar))
1893 GtkWidget *old_toolbar = priv->edit_toolbar;
1894 priv->edit_toolbar = GTK_WIDGET (toolbar);
1896 if (priv->edit_toolbar)
1897 gtk_widget_set_parent (priv->edit_toolbar, GTK_WIDGET (self));
1900 gtk_widget_unparent (old_toolbar);
1905 * hildon_window_get_main_menu:
1906 * @self: a #HildonWindow
1908 * Gets the #GtkMenu assigned to the #HildonWindow. Note that the
1909 * window is still the owner of the menu.
1911 * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
1912 * you should use hildon_window_get_app_menu() instead.
1914 * Return value: The #GtkMenu assigned to this application view.
1919 hildon_window_get_main_menu (HildonWindow * self)
1921 HildonWindowPrivate *priv;
1923 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
1925 priv = HILDON_WINDOW_GET_PRIVATE (self);
1931 * hildon_window_get_menu:
1932 * @self: a #HildonWindow
1934 * Gets the #GtkMenu assigned to @self
1936 * Return value: a #GtkMenu
1938 * Deprecated: In Hildon 2.2 this function has been renamed to
1939 * hildon_window_get_main_menu() for consistency
1942 hildon_window_get_menu (HildonWindow * self)
1944 return hildon_window_get_main_menu (self);
1947 /* Since we've been asking developers to call gtk_window_add_accel_group()
1948 * themselves, do not trigger criticals by trying it again.
1951 hildon_window_add_accel_group (HildonWindow *self,
1952 GtkAccelGroup *accel_group)
1956 groups = gtk_accel_groups_from_object (G_OBJECT (self));
1957 for (l = groups; l != NULL; l = l->next)
1958 if (l->data == (gpointer)accel_group)
1959 /* Maybe print a warning here? */
1962 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
1966 * hildon_window_set_main_menu:
1967 * @self: A #HildonWindow
1968 * @menu: The #GtkMenu to be used for this #HildonWindow
1970 * Sets the menu to be used for this window. This menu overrides
1971 * a program-wide menu that may have been set with
1972 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1973 * menu. #HildonWindow takes ownership of the passed menu and you're
1974 * not supposed to free it yourself anymore.
1976 * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
1977 * you should use hildon_window_set_app_menu() instead.
1980 hildon_window_set_main_menu (HildonWindow* self,
1983 HildonWindowPrivate *priv;
1984 GtkAccelGroup *accel_group;
1986 g_return_if_fail (HILDON_IS_WINDOW (self));
1988 priv = HILDON_WINDOW_GET_PRIVATE (self);
1990 if (priv->menu != NULL)
1992 accel_group = gtk_menu_get_accel_group (priv->menu);
1993 if (accel_group != NULL)
1994 gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
1996 gtk_menu_detach (priv->menu);
1997 g_object_unref (priv->menu);
2001 if (priv->menu != NULL)
2003 gtk_widget_set_name (GTK_WIDGET (priv->menu), "menu_force_with_corners");
2004 gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (self), &detach_menu_func);
2005 g_object_ref (priv->menu);
2007 accel_group = gtk_menu_get_accel_group (priv->menu);
2008 if (accel_group != NULL)
2009 hildon_window_add_accel_group (self, accel_group);
2014 * hildon_window_set_menu:
2015 * @self: A #HildonWindow
2016 * @menu: The #GtkMenu to be used for this #HildonWindow
2018 * Sets the menu to be used for this window. This menu overrides
2019 * a program-wide menu that may have been set with
2020 * hildon_program_set_common_menu(). Pass %NULL to remove the current
2021 * menu. HildonWindow takes ownership of the passed menu and you're
2022 * not supposed to free it yourself anymore.
2024 * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the
2025 * #GtkMenu. To pass control about visibility to the application
2026 * developer, hildon_window_set_main_menu() was introduced, which
2029 * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
2032 hildon_window_set_menu (HildonWindow *self,
2035 HildonWindowPrivate *priv;
2037 g_return_if_fail (HILDON_IS_WINDOW (self));
2039 hildon_window_set_main_menu (self, menu);
2041 priv = HILDON_WINDOW_GET_PRIVATE (self);
2043 if (priv->menu != NULL)
2044 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2048 * hildon_window_get_is_topmost:
2049 * @self: A #HildonWindow
2051 * Returns whether the #HildonWindow is currenty activated by the
2054 * Return value: %TRUE if @self is currently activated, %FALSE otherwise.
2057 hildon_window_get_is_topmost (HildonWindow *self)
2059 HildonWindowPrivate *priv;
2061 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
2063 priv = HILDON_WINDOW_GET_PRIVATE (self);
2064 return priv->is_topmost;
2068 * hildon_window_set_app_menu:
2069 * @self: a #HildonWindow
2070 * @menu: a #HildonAppMenu to be used for this window
2072 * Sets the menu to be used for this window. Pass %NULL to remove the
2073 * current menu. Any reference to a previous menu will be dropped.
2074 * #HildonWindow takes ownership of the passed menu and
2075 * you're not supposed to free it yourself anymore.
2077 * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
2078 * you should use hildon_window_set_main_menu() instead.
2083 hildon_window_set_app_menu (HildonWindow *self,
2084 HildonAppMenu *menu)
2086 HildonWindowPrivate *priv;
2087 HildonAppMenu *old_menu;
2089 g_return_if_fail (HILDON_IS_WINDOW (self));
2090 g_return_if_fail (!menu || HILDON_IS_APP_MENU (menu));
2091 priv = HILDON_WINDOW_GET_PRIVATE (self);
2093 old_menu = priv->app_menu;
2096 priv->app_menu = menu;
2098 g_object_ref_sink (menu);
2100 /* Unref old menu */
2102 g_object_unref (old_menu);
2106 * hildon_window_get_app_menu:
2107 * @self: a #HildonWindow
2109 * Returns the #HildonAppMenu assigned to @self, or %NULL if it's
2110 * unset. Note that the window is still the owner of the menu.
2112 * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
2113 * you should use hildon_window_get_main_menu() instead.
2115 * Returns: a #HildonAppMenu
2120 hildon_window_get_app_menu (HildonWindow *self)
2122 HildonWindowPrivate *priv;
2124 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
2126 priv = HILDON_WINDOW_GET_PRIVATE (self);
2128 return priv->app_menu;
2132 hildon_window_update_markup (HildonWindow *window)
2134 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
2135 GdkAtom markup_atom = gdk_atom_intern ("_HILDON_WM_NAME", FALSE);
2136 GdkAtom utf8_atom = gdk_atom_intern ("UTF8_STRING", FALSE);
2137 GdkWindow *gdkwin = GTK_WIDGET (window)->window;
2140 gdk_property_change (gdkwin, markup_atom, utf8_atom, 8,
2141 GDK_PROP_MODE_REPLACE, (const guchar *) priv->markup,
2142 strlen (priv->markup));
2144 gdk_property_delete (gdkwin, markup_atom);
2149 * hildon_window_get_markup:
2150 * @window: a #HildonWindow
2152 * Gets the marked up title of the window title. See hildon_window_set_markup()
2154 * Returns: the marked up title of the window, or %NULL if none has
2155 * been set explicitely. The returned string is owned by the widget
2156 * and must not be modified or freed.
2161 hildon_window_get_markup (HildonWindow *window)
2163 HildonWindowPrivate *priv;
2165 g_return_val_if_fail (HILDON_IS_WINDOW (window), NULL);
2167 priv = HILDON_WINDOW_GET_PRIVATE (window);
2169 return priv->markup;
2173 * hildon_window_set_markup:
2174 * @window: a #HildonWindow
2175 * @markup: the marked up title of the window, or %NULL to unset the
2178 * Sets the marked up title of @window. The accepted format is the one
2179 * used in Pango (see #PangoMarkupFormat) with the exception of
2182 * Note that you need support from the window manager for this title
2183 * to be used. See gtk_window_set_title() for the standard way of
2184 * setting the title of a window.
2189 hildon_window_set_markup (HildonWindow *window,
2190 const gchar *markup)
2192 HildonWindowPrivate *priv;
2195 g_return_if_fail (HILDON_IS_WINDOW (window));
2197 priv = HILDON_WINDOW_GET_PRIVATE (window);
2199 new_markup = g_strdup (markup);
2200 g_free (priv->markup);
2201 priv->markup = new_markup;
2203 if (GTK_WIDGET_REALIZED (window))
2204 hildon_window_update_markup (window);
2206 g_object_notify (G_OBJECT (window), "markup");