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 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
695 GtkWidget *child = GTK_BIN (widget)->child;
696 GtkRequisition req2 = { 0 };
697 gint border_width = GTK_CONTAINER(widget)->border_width;
701 hildon_window_get_borders (HILDON_WINDOW (widget));
705 gtk_widget_size_request (child, requisition);
707 if (priv->vbox != NULL)
708 gtk_widget_size_request (priv->vbox, &req2);
710 requisition->height += req2.height;
711 requisition->width = MAX (requisition->width, req2.width);
713 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
716 gtk_widget_size_request (priv->edit_toolbar, &req);
717 requisition->height += req.height;
718 requisition->width = MAX (requisition->width, req.width);
721 requisition->width += 2 * border_width;
722 requisition->height += 2 * border_width;
724 if (! priv->fullscreen)
726 requisition->height += priv->borders->top;
727 if (req2.height == 0)
728 requisition->height += priv->borders->bottom;
729 requisition->width += priv->borders->left + priv->borders->right;
734 hildon_window_size_allocate (GtkWidget *widget,
735 GtkAllocation *allocation)
737 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
740 GtkAllocation box_alloc = { 0 };
741 GtkAllocation edittb_alloc = { 0 };
742 GtkAllocation alloc = *allocation;
744 GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
748 hildon_window_get_borders (HILDON_WINDOW (widget));
750 tb = priv->toolbar_borders;
752 widget->allocation = *allocation;
754 /* Calculate allocation of edit toolbar */
755 if (priv->edit_toolbar != NULL && GTK_WIDGET_VISIBLE (priv->edit_toolbar))
758 gtk_widget_get_child_requisition (priv->edit_toolbar, &req);
759 edittb_alloc.width = alloc.width - tb->left - tb->right;
760 edittb_alloc.height = MIN (req.height, alloc.height);
761 edittb_alloc.x = alloc.x + tb->left;
762 edittb_alloc.y = alloc.y + tb->top;
764 if (edittb_alloc.height > 0)
766 alloc.y += tb->top + tb->bottom + edittb_alloc.height;
767 alloc.height -= tb->top + tb->bottom + edittb_alloc.height;
768 gtk_widget_size_allocate (priv->edit_toolbar, &edittb_alloc);
772 /* Calculate allocation of normal toolbars */
773 if (priv->vbox != NULL && GTK_WIDGET_VISIBLE (priv->vbox))
776 gtk_widget_get_child_requisition (priv->vbox, &req);
777 box_alloc.width = alloc.width - tb->left - tb->right;
778 box_alloc.height = MIN (req.height, alloc.height);
779 box_alloc.x = alloc.x + tb->left;
780 box_alloc.y = alloc.y + alloc.height - box_alloc.height - tb->bottom;
782 if (box_alloc.height > 0)
784 alloc.height -= tb->top + tb->bottom + box_alloc.height;
785 gtk_widget_size_allocate (priv->vbox, &box_alloc);
789 /* Calculate allocation of the child widget */
790 if (child != NULL && GTK_WIDGET_VISIBLE (child))
792 guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
793 alloc.x += border_width;
794 alloc.y += border_width;
795 alloc.width -= (border_width * 2);
796 alloc.height -= (border_width * 2);
798 if (! priv->fullscreen)
800 GtkBorder *b = priv->borders;
802 alloc.width -= (b->left + b->right);
804 /* Use the top border if there's no edit toolbar */
805 if (edittb_alloc.height <= 0)
808 alloc.height -= b->top;
811 /* Use the top border if there are no standard toolbars */
812 if (box_alloc.height <= 0)
813 alloc.height -= b->bottom;
816 gtk_widget_size_allocate (child, &alloc);
819 if (priv->previous_vbox_y != box_alloc.y)
821 /* The size of the VBox has changed, we need to redraw part
822 * of the window borders */
823 gint draw_from_y = MIN (priv->previous_vbox_y, box_alloc.y) - tb->top;
825 gtk_widget_queue_draw_area (widget, 0, draw_from_y,
826 widget->allocation.width,
827 widget->allocation.height - draw_from_y);
829 priv->previous_vbox_y = box_alloc.y;
835 hildon_window_forall (GtkContainer *container,
836 gboolean include_internals,
837 GtkCallback callback,
838 gpointer callback_data)
840 HildonWindow *self = HILDON_WINDOW (container);
841 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
843 g_return_if_fail (callback != NULL);
846 GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
847 callback, callback_data);
849 if (include_internals && priv->vbox != NULL)
850 (* callback)(GTK_WIDGET (priv->vbox), callback_data);
852 if (include_internals && priv->edit_toolbar != NULL)
853 (* callback)(GTK_WIDGET (priv->edit_toolbar), callback_data);
857 hildon_window_show_all (GtkWidget *widget)
859 HildonWindow *self = HILDON_WINDOW (widget);
860 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
862 g_assert (priv != NULL);
864 GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
866 gtk_widget_show_all (priv->vbox);
868 if (priv->edit_toolbar)
869 gtk_widget_show_all (priv->edit_toolbar);
873 hildon_window_destroy (GtkObject *obj)
875 HildonWindow *self = HILDON_WINDOW (obj);
876 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (obj);
877 GList *menu_list = NULL;
878 GList *menu_node = NULL;
880 g_assert (priv != NULL);
882 if (priv->vbox != NULL)
886 GtkWidget * common_toolbar =
887 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
888 if (common_toolbar && common_toolbar->parent == priv->vbox)
890 gtk_container_remove (GTK_CONTAINER (priv->vbox),
895 gtk_widget_unparent (priv->vbox);
900 if (priv->edit_toolbar != NULL)
902 gtk_widget_unparent (priv->edit_toolbar);
903 priv->edit_toolbar = NULL;
908 hildon_app_menu_set_parent_window (priv->app_menu, NULL);
909 g_object_unref (priv->app_menu);
910 priv->app_menu = NULL;
913 menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
914 menu_node = menu_list;
918 if (GTK_IS_MENU (menu_node->data))
920 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_node->data)))
922 gtk_menu_popdown (GTK_MENU (menu_node->data));
923 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_node->data));
925 gtk_menu_detach (GTK_MENU (menu_node->data));
927 /* Destroy it, but only if it's not a common menu */
929 hildon_program_get_common_menu (priv->program) != menu_node->data) {
930 gtk_object_destroy (GTK_OBJECT (menu_node->data));
931 g_object_unref (menu_node->data);
934 menu_node = menu_node->next;
937 g_list_free (menu_list);
942 hildon_program_remove_window (priv->program, self);
945 gdk_window_remove_filter (gdk_get_default_root_window(),
946 hildon_window_root_window_event_filter,
949 gtk_widget_set_events (GTK_WIDGET(obj), 0);
951 GTK_OBJECT_CLASS (hildon_window_parent_class)->destroy (obj);
955 hildon_window_notify (GObject *gobject,
958 HildonWindow *window = HILDON_WINDOW (gobject);
960 if (g_str_equal (param->name, "is-topmost"))
962 hildon_window_is_topmost_notify (window);
965 if (G_OBJECT_CLASS(hildon_window_parent_class)->notify)
966 G_OBJECT_CLASS(hildon_window_parent_class)->notify (gobject, param);
971 visible_toolbar (gpointer data,
974 if (GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
975 (*((gint *)user_data))++;
979 paint_toolbar (GtkWidget *widget,
981 GdkEventExpose * event,
984 gint toolbar_num = 0;
987 /* collect info to help on painting the boxes */
988 g_list_foreach (box->children, visible_toolbar,
989 (gpointer) &toolbar_num);
994 /*top most toolbar painting*/
995 gtk_paint_box (widget->style, widget->window,
996 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
997 &event->area, widget, "toolbar-primary",
998 widget->allocation.x,
999 GTK_WIDGET(box)->allocation.y,
1000 widget->allocation.width,
1003 /*multi toolbar painting*/
1004 for (count = 0; count < toolbar_num - 1; count++)
1006 gtk_paint_box (widget->style, widget->window,
1007 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
1008 &event->area, widget, "toolbar-secondary",
1009 widget->allocation.x,
1010 GTK_WIDGET(box)->allocation.y +
1011 (1 + count) * (TOOLBAR_HEIGHT),
1012 widget->allocation.width,
1018 paint_edit_toolbar (GtkWidget *widget,
1020 GdkEventExpose *event,
1021 gboolean fullscreen)
1023 if (!GTK_WIDGET_VISIBLE (toolbar))
1026 gtk_paint_box (widget->style, widget->window,
1027 GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
1028 &event->area, widget, "toolbar-edit-mode",
1029 toolbar->allocation.x,
1030 toolbar->allocation.y,
1031 toolbar->allocation.width,
1032 toolbar->allocation.height);
1036 * Checks the root window to know which is the topped window
1039 hildon_window_get_active_window (void)
1047 unsigned long extra;
1051 unsigned char *char_pointer;
1053 Atom active_app_atom =
1054 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1058 gdk_error_trap_push ();
1059 status = XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1060 active_app_atom, 0L, 16L,
1061 0, XA_WINDOW, &realtype, &format,
1062 &n, &extra, &win.char_pointer);
1063 xerror = gdk_error_trap_pop ();
1064 if (xerror || !(status == Success && realtype == XA_WINDOW && format == 32
1065 && n == 1 && win.win != NULL))
1067 if (win.win != NULL)
1068 XFree (win.char_pointer);
1074 if (win.win != NULL)
1075 XFree(win.char_pointer);
1081 xclient_message_type_check (XClientMessageEvent *cm,
1084 return cm->message_type == XInternAtom(GDK_DISPLAY(), name, FALSE);
1088 * Handle the window border custom button, which toggles the menu,
1089 * and the Hildon input method copy paste messages
1091 static GdkFilterReturn
1092 hildon_window_event_filter (GdkXEvent *xevent,
1096 XAnyEvent *eventti = xevent;
1098 if (eventti->type == ClientMessage)
1100 XClientMessageEvent *cm = xevent;
1102 if (xclient_message_type_check (cm, "_MB_GRAB_TRANSFER"))
1104 hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]);
1105 return GDK_FILTER_REMOVE;
1107 /* opera hack clipboard client message */
1108 else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY"))
1110 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1111 HILDON_WINDOW_CO_COPY);
1112 return GDK_FILTER_REMOVE;
1114 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT"))
1116 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1117 HILDON_WINDOW_CO_CUT);
1118 return GDK_FILTER_REMOVE;
1120 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE"))
1122 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1123 HILDON_WINDOW_CO_PASTE);
1124 return GDK_FILTER_REMOVE;
1128 return GDK_FILTER_CONTINUE;
1132 * Here we keep track of changes in the _MB_CURRENT_APP_WINDOW,
1133 * to know when we acquire/lose topmost status
1135 static GdkFilterReturn
1136 hildon_window_root_window_event_filter (GdkXEvent *xevent,
1140 XAnyEvent *eventti = xevent;
1141 HildonWindow *hwindow = HILDON_WINDOW (data);
1143 if (eventti->type == PropertyNotify)
1145 XPropertyEvent *pevent = xevent;
1146 Atom active_app_atom =
1147 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1149 if (pevent->atom == active_app_atom)
1151 Window active_window = hildon_window_get_active_window();
1153 hildon_window_update_topmost (hwindow, active_window);
1157 return GDK_FILTER_CONTINUE;
1161 * Handle the menu hardware key here
1164 hildon_window_key_press_event (GtkWidget *widget,
1167 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1169 g_return_val_if_fail (HILDON_IS_WINDOW (widget),FALSE);
1172 switch (event->keyval)
1174 case HILDON_HARDKEY_MENU:
1175 if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME))
1178 case HILDON_HARDKEY_ESC:
1179 if (!priv->escape_timeout)
1181 priv->escape_timeout = g_timeout_add
1182 (HILDON_WINDOW_LONG_PRESS_TIME,
1183 hildon_window_escape_timeout, widget);
1188 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event);
1192 hildon_window_key_release_event (GtkWidget *widget,
1195 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1197 g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE);
1200 switch (event->keyval)
1202 case HILDON_HARDKEY_ESC:
1203 if (priv->escape_timeout)
1205 g_source_remove (priv->escape_timeout);
1206 priv->escape_timeout = 0;
1211 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event);
1216 * We keep track of the window state changes, because the drawing
1217 * (borders) differs whether we are in fullscreen mode or not
1220 hildon_window_window_state_event (GtkWidget *widget,
1221 GdkEventWindowState *event)
1223 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1224 g_assert (priv != NULL);
1226 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1227 priv->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1229 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event)
1231 return GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event (
1242 * If the window lost focus while the user started to press the ESC key, we
1243 * won't get the release event. We need to stop the timeout.
1246 hildon_window_focus_out_event (GtkWidget *widget,
1247 GdkEventFocus *event)
1249 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1251 if (priv->escape_timeout)
1253 g_source_remove (priv->escape_timeout);
1254 priv->escape_timeout = 0;
1257 return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event);
1261 * The menu popuping needs a menu popup-function
1264 hildon_window_menu_popup_func (GtkMenu *menu,
1272 GdkWindow *window = GTK_WIDGET(widget)->window;
1276 gdk_window_get_origin (window, &window_x, &window_y);
1279 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1280 "vertical-offset", y, NULL);
1282 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1284 *x = GTK_WIDGET (widget)->allocation.width + window_x - GTK_WIDGET (menu)->allocation.width - *x;
1294 hildon_window_menu_popup_func_full (GtkMenu *menu,
1300 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1301 "vertical-offset", y, NULL);
1303 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1304 *x = GTK_WIDGET (widget)->allocation.width - GTK_WIDGET (menu)->allocation.width - *x;
1313 * Takes the common toolbar when we acquire the top-most status
1316 hildon_window_is_topmost_notify (HildonWindow *window)
1318 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1322 if (priv->is_topmost)
1324 hildon_window_take_common_toolbar (window);
1329 * Sets the program to which the window belongs. This should only be called
1330 * by hildon_program_add_window
1332 void G_GNUC_INTERNAL
1333 hildon_window_set_program (HildonWindow *self,
1336 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1338 g_return_if_fail (HILDON_IS_WINDOW (self));
1339 g_assert (priv != NULL);
1343 g_object_unref (priv->program);
1346 /* Now that we are bound to a program, we can rely on it to track the
1348 gdk_window_remove_filter (gdk_get_default_root_window(),
1349 hildon_window_root_window_event_filter,
1352 priv->program = HILDON_PROGRAM (program);
1353 g_object_ref (program);
1357 * Unsets the program to which the window belongs. This should only be called
1358 * by hildon_program_remove_window
1360 void G_GNUC_INTERNAL
1361 hildon_window_unset_program (HildonWindow *self)
1363 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1365 g_return_if_fail(HILDON_IS_WINDOW (self));
1366 g_assert (priv != NULL);
1370 g_object_unref (priv->program);
1371 priv->program = NULL;
1373 /* We need to start tacking the root window again */
1374 gdk_window_set_events (gdk_get_default_root_window (),
1375 gdk_window_get_events (gdk_get_default_root_window ())
1376 | GDK_PROPERTY_CHANGE_MASK);
1378 gdk_window_add_filter (gdk_get_default_root_window (),
1379 hildon_window_root_window_event_filter, self );
1382 priv->program = NULL;
1386 * Sets whether or not the program to which this window belongs is
1387 * killable. This is used by the HildonProgram to signify to the
1388 * Task Navigator whether or not it can hibernate in memory-low situations
1390 void G_GNUC_INTERNAL
1391 hildon_window_set_can_hibernate_property (HildonWindow *self,
1392 gpointer _can_hibernate)
1394 GdkAtom killable_atom;
1395 gboolean can_hibernate;
1397 g_return_if_fail(self && HILDON_IS_WINDOW (self));
1399 if (!GTK_WIDGET_REALIZED ((GTK_WIDGET (self))))
1404 can_hibernate = * ((gboolean *)_can_hibernate);
1406 killable_atom = gdk_atom_intern (CAN_HIBERNATE_PROPERTY, FALSE);
1410 gdk_property_change (GTK_WIDGET (self)->window, killable_atom,
1411 (GdkAtom)31/* XA_STRING */, 8,
1412 GDK_PROP_MODE_REPLACE, (const guchar *)CAN_HIBERNATE,
1413 CAN_HIBERNATE_LENGTH);
1417 gdk_property_delete (GTK_WIDGET (self)->window, killable_atom);
1423 * If a common toolbar was set to the program, reparent it to
1426 void G_GNUC_INTERNAL
1427 hildon_window_take_common_toolbar (HildonWindow *self)
1429 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1431 g_return_if_fail(HILDON_IS_WINDOW (self));
1436 GtkWidget *common_toolbar =
1437 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
1439 if (common_toolbar && common_toolbar->parent != priv->vbox)
1441 g_object_ref (common_toolbar);
1442 if (common_toolbar->parent)
1444 gtk_container_remove (GTK_CONTAINER (common_toolbar->parent),
1448 gtk_box_pack_end (GTK_BOX(priv->vbox), common_toolbar,
1450 g_object_unref (common_toolbar);
1452 gtk_widget_set_size_request (common_toolbar, -1, TOOLBAR_HEIGHT);
1454 gtk_widget_show (priv->vbox);
1461 * Compare the window that was last topped, and act consequently
1464 hildon_window_update_topmost (HildonWindow *self,
1467 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1469 GdkWindow *my_window;
1471 g_return_if_fail (HILDON_IS_WINDOW (self));
1474 my_window = GTK_WIDGET (self)->window;
1476 if (my_window && window_id == GDK_WINDOW_XID (my_window))
1478 if (! priv->is_topmost)
1480 priv->is_topmost = TRUE;
1481 hildon_window_is_topmost_notify (self);
1482 g_object_notify (G_OBJECT (self), "is-topmost");
1485 else if (priv->is_topmost)
1487 /* Should this go in the signal handler? */
1488 GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (self));
1490 if (GTK_IS_ENTRY (focus))
1491 gtk_im_context_focus_out (GTK_ENTRY (focus)->im_context);
1492 if (GTK_IS_TEXT_VIEW (focus))
1493 gtk_im_context_focus_out (GTK_TEXT_VIEW (focus)->im_context);
1495 priv->is_topmost = FALSE;
1496 hildon_window_is_topmost_notify (self);
1497 g_object_notify (G_OBJECT (self), "is-topmost");
1502 detach_menu_func (GtkWidget *attach_widget,
1505 /* FIXME Why is this even needed here? */
1509 hildon_window_toggle_menu (HildonWindow *self,
1513 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1515 if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
1517 return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
1527 hildon_window_toggle_gtk_menu (HildonWindow *self,
1532 gboolean retvalue = FALSE;
1534 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1535 g_return_val_if_fail (GTK_IS_MENU (menu), FALSE);
1537 if (gtk_menu_get_attach_widget (menu) != GTK_WIDGET (self))
1539 g_object_ref (menu);
1540 if (gtk_menu_get_attach_widget (menu))
1542 gtk_menu_detach (menu);
1544 gtk_menu_attach_to_widget (menu, GTK_WIDGET (self), &detach_menu_func);
1545 g_object_unref (menu);
1548 if (GTK_WIDGET_MAPPED (menu))
1550 gtk_menu_popdown (menu);
1551 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu));
1556 /* Check if the menu has items */
1557 GList *menu_children = gtk_container_get_children (GTK_CONTAINER (menu));
1561 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1562 g_list_free (menu_children);
1564 /* Apply right theming */
1565 gtk_widget_set_name (GTK_WIDGET (menu), "menu_force_with_corners");
1567 if (priv->fullscreen)
1569 gtk_menu_popup (menu, NULL, NULL,
1570 (GtkMenuPositionFunc)
1571 hildon_window_menu_popup_func_full,
1572 self, button, time);
1576 gtk_menu_popup (menu, NULL, NULL,
1577 (GtkMenuPositionFunc)
1578 hildon_window_menu_popup_func,
1579 self, button, time);
1581 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE);
1590 hildon_window_toggle_app_menu (HildonWindow *self,
1591 HildonAppMenu *menu)
1593 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1594 g_return_val_if_fail (HILDON_IS_APP_MENU (menu), FALSE);
1596 if (self != hildon_app_menu_get_parent_window (menu))
1598 gtk_widget_hide (GTK_WIDGET (menu));
1601 if (GTK_WIDGET_MAPPED (menu))
1603 gtk_widget_hide (GTK_WIDGET (menu));
1607 hildon_app_menu_popup (menu, GTK_WINDOW (self));
1614 * Toggles the display of the HildonWindow menu.
1615 * Returns whether or not something was done (whether or not we had a menu
1619 hildon_window_toggle_menu_real (HildonWindow * self,
1623 gboolean retvalue = FALSE;
1624 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1626 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1628 /* Select which menu to use, Window specific has highest priority,
1629 * then program specific */
1632 retvalue = hildon_window_toggle_gtk_menu (self, priv->menu, button, time);
1634 else if (priv->app_menu)
1636 retvalue = hildon_window_toggle_app_menu (self, priv->app_menu);
1638 else if (priv->program)
1640 GtkMenu *gtkmenu = hildon_program_get_common_menu (priv->program);
1641 HildonAppMenu *appmenu = hildon_program_get_common_app_menu (priv->program);
1645 retvalue = hildon_window_toggle_gtk_menu (self, gtkmenu, button, time);
1649 retvalue = hildon_window_toggle_app_menu (self, appmenu);
1657 * If the ESC key was not released when the timeout expires,
1661 hildon_window_escape_timeout (gpointer data)
1663 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data);
1668 GDK_THREADS_ENTER ();
1670 /* Send fake event, simulation a situation that user
1671 pressed 'x' from the corner */
1672 event = gdk_event_new(GDK_DELETE);
1673 ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window));
1674 gtk_main_do_event(event);
1676 /* That unrefs the window, so we're reffing it above */
1677 gdk_event_free(event);
1679 priv->escape_timeout = 0;
1681 GDK_THREADS_LEAVE ();
1687 * hildon_window_new:
1689 * Creates a new #HildonWindow.
1691 * Return value: A #HildonWindow.
1694 hildon_window_new (void)
1696 HildonWindow *newwindow = g_object_new (HILDON_TYPE_WINDOW, NULL);
1698 return GTK_WIDGET (newwindow);
1702 * hildon_window_add_with_scrollbar:
1703 * @self: A #HildonWindow
1704 * @child: A #GtkWidget
1706 * Adds @child to the #HildonWindow and creates a scrollbar for
1707 * it. Similar to adding first a #GtkScrolledWindow and then @child to
1711 hildon_window_add_with_scrollbar (HildonWindow *self,
1714 GtkScrolledWindow *scrolledw;
1716 g_return_if_fail (HILDON_IS_WINDOW (self));
1717 g_return_if_fail (GTK_IS_WIDGET (child));
1718 g_return_if_fail (child->parent == NULL);
1720 scrolledw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1721 gtk_scrolled_window_set_policy (scrolledw, GTK_POLICY_NEVER,
1722 GTK_POLICY_AUTOMATIC);
1723 gtk_scrolled_window_set_shadow_type (scrolledw, GTK_SHADOW_NONE);
1725 if (GTK_IS_VIEWPORT (child))
1726 gtk_container_add (GTK_CONTAINER (scrolledw), child);
1729 if (GTK_IS_CONTAINER (child) )
1730 gtk_container_set_focus_vadjustment (GTK_CONTAINER(child),
1731 gtk_scrolled_window_get_vadjustment (scrolledw) );
1732 gtk_scrolled_window_add_with_viewport (scrolledw, child);
1735 gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (scrolledw));
1739 calculate_visible_toolbars (gpointer data,
1742 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (((GtkBoxChild *)data)->widget)))
1743 (*((gint *)user_data)) ++;
1747 toolbar_visible_notify (GtkWidget *toolbar, GParamSpec *pspec,
1748 HildonWindow *window)
1750 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1754 /* Recalculate from scratch the value just in case */
1755 priv->visible_toolbars = 0;
1757 g_list_foreach (GTK_BOX (priv->vbox)->children, calculate_visible_toolbars,
1758 &priv->visible_toolbars);
1760 if (priv->visible_toolbars == 0)
1761 gtk_widget_hide (priv->vbox);
1763 gtk_widget_show (priv->vbox);
1767 * hildon_window_add_toolbar:
1768 * @self: A #HildonWindow
1769 * @toolbar: A #GtkToolbar to add to the #HildonWindow
1771 * Adds a toolbar to the window. Note that the toolbar is not automatically
1772 * shown. You need to call gtk_widget_show_all() on it to make it visible.
1773 * It's also possible to hide the toolbar (without removing it) by calling
1777 hildon_window_add_toolbar (HildonWindow *self,
1778 GtkToolbar *toolbar)
1781 HildonWindowPrivate *priv;
1783 g_return_if_fail (HILDON_IS_WINDOW (self));
1784 g_return_if_fail (toolbar && GTK_IS_TOOLBAR (toolbar));
1786 priv = HILDON_WINDOW_GET_PRIVATE (self);
1788 vbox = GTK_BOX (priv->vbox);
1790 gtk_box_pack_start (vbox, GTK_WIDGET (toolbar), TRUE, TRUE, 0);
1791 gtk_box_reorder_child (vbox, GTK_WIDGET (toolbar), 0);
1792 gtk_widget_set_size_request (GTK_WIDGET (toolbar), -1, TOOLBAR_HEIGHT);
1794 g_signal_connect (G_OBJECT (toolbar), "notify::visible",
1795 G_CALLBACK (toolbar_visible_notify), self);
1797 if (GTK_WIDGET_VISIBLE (toolbar))
1799 priv->visible_toolbars++;
1800 gtk_widget_show (priv->vbox);
1803 gtk_widget_queue_resize (GTK_WIDGET (self));
1807 * hildon_window_remove_toolbar:
1808 * @self: A #HildonWindow
1809 * @toolbar: A #GtkToolbar to remove from the #HildonWindow
1811 * Removes a toolbar from the window. Note that this decreases the refference
1812 * count on the widget. If you want to keep the toolbar alive call g_object_ref()
1813 * before calling this function.
1816 hildon_window_remove_toolbar (HildonWindow *self,
1817 GtkToolbar *toolbar)
1819 HildonWindowPrivate *priv;
1821 g_return_if_fail (HILDON_IS_WINDOW (self));
1823 priv = HILDON_WINDOW_GET_PRIVATE (self);
1825 if (GTK_WIDGET_VISIBLE (toolbar))
1827 if (--(priv->visible_toolbars) == 0)
1828 gtk_widget_hide (priv->vbox);
1831 g_signal_handlers_disconnect_by_func (toolbar, toolbar_visible_notify, self);
1833 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (toolbar));
1837 * hildon_window_set_edit_toolbar:
1838 * @self: A #HildonWindow
1839 * @toolbar: A #HildonEditToolbar, or %NULL to remove the current one.
1841 * Adds a #HildonEditToolbar to the window. Note that the toolbar is
1842 * not automatically shown. You need to call gtk_widget_show() on it
1843 * to make it visible. It's also possible to hide the toolbar (without
1844 * removing it) by calling gtk_widget_hide().
1846 * A window can only have at most one edit toolbar at a time, so the
1847 * previous toolbar (if any) is replaced after calling this function.
1852 hildon_window_set_edit_toolbar (HildonWindow *self,
1853 HildonEditToolbar *toolbar)
1855 HildonWindowPrivate *priv;
1857 g_return_if_fail (HILDON_IS_WINDOW (self));
1858 g_return_if_fail (toolbar == NULL || HILDON_IS_EDIT_TOOLBAR (toolbar));
1860 priv = HILDON_WINDOW_GET_PRIVATE (self);
1862 if (priv->edit_toolbar != GTK_WIDGET (toolbar))
1864 GtkWidget *old_toolbar = priv->edit_toolbar;
1865 priv->edit_toolbar = GTK_WIDGET (toolbar);
1867 if (priv->edit_toolbar)
1868 gtk_widget_set_parent (priv->edit_toolbar, GTK_WIDGET (self));
1871 gtk_widget_unparent (old_toolbar);
1876 * hildon_window_get_main_menu:
1877 * @self: a #HildonWindow
1879 * Gets the #GtkMenu assigned to the #HildonAppview. Note that the
1880 * window is still the owner of the menu.
1882 * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
1883 * you should use hildon_window_get_app_menu() instead.
1885 * Return value: The #GtkMenu assigned to this application view.
1890 hildon_window_get_main_menu (HildonWindow * self)
1892 HildonWindowPrivate *priv;
1894 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
1896 priv = HILDON_WINDOW_GET_PRIVATE (self);
1902 * hildon_window_get_menu:
1903 * @self: a #HildonWindow
1905 * Return value: a #GtkMenu
1907 * Deprecated: In Hildon 2.2 this function has been renamed to
1908 * hildon_window_get_main_menu() for consistency
1911 hildon_window_get_menu (HildonWindow * self)
1913 return hildon_window_get_main_menu (self);
1916 /* Since we've been asking developers to call gtk_window_add_accel_group()
1917 * themselves, do not trigger criticals by trying it again.
1920 hildon_window_add_accel_group (HildonWindow *self,
1921 GtkAccelGroup *accel_group)
1925 groups = gtk_accel_groups_from_object (G_OBJECT (self));
1926 for (l = groups; l != NULL; l = l->next)
1927 if (l->data == (gpointer)accel_group)
1928 /* Maybe print a warning here? */
1931 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
1935 * hildon_window_set_main_menu:
1936 * @self: A #HildonWindow
1937 * @menu: The #GtkMenu to be used for this #HildonWindow
1939 * Sets the menu to be used for this window. This menu overrides
1940 * a program-wide menu that may have been set with
1941 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1942 * menu. #HildonWindow takes ownership of the passed menu and you're
1943 * not supposed to free it yourself anymore.
1945 * Note that if you're using a #HildonAppMenu rather than a #GtkMenu
1946 * you should use hildon_window_set_app_menu() instead.
1949 hildon_window_set_main_menu (HildonWindow* self,
1952 HildonWindowPrivate *priv;
1953 GtkAccelGroup *accel_group;
1955 g_return_if_fail (HILDON_IS_WINDOW (self));
1957 priv = HILDON_WINDOW_GET_PRIVATE (self);
1959 if (priv->menu != NULL)
1961 accel_group = gtk_menu_get_accel_group (priv->menu);
1962 if (accel_group != NULL)
1963 gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
1965 gtk_menu_detach (priv->menu);
1966 g_object_unref (priv->menu);
1970 if (priv->menu != NULL)
1972 gtk_widget_set_name (GTK_WIDGET (priv->menu), "menu_force_with_corners");
1973 gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (self), &detach_menu_func);
1974 g_object_ref (priv->menu);
1976 accel_group = gtk_menu_get_accel_group (priv->menu);
1977 if (accel_group != NULL)
1978 hildon_window_add_accel_group (self, accel_group);
1983 * hildon_window_set_menu:
1984 * @self: A #HildonWindow
1985 * @menu: The #GtkMenu to be used for this #HildonWindow
1987 * Sets the menu to be used for this window. This menu overrides
1988 * a program-wide menu that may have been set with
1989 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1990 * menu. HildonWindow takes ownership of the passed menu and you're
1991 * not supposed to free it yourself anymore.
1993 * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the
1994 * #GtkMenu. To pass control about visibility to the application
1995 * developer, hildon_window_set_main_menu() was introduced, which
1998 * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
2001 hildon_window_set_menu (HildonWindow *self,
2004 HildonWindowPrivate *priv;
2006 g_return_if_fail (HILDON_IS_WINDOW (self));
2008 hildon_window_set_main_menu (self, menu);
2010 priv = HILDON_WINDOW_GET_PRIVATE (self);
2012 if (priv->menu != NULL)
2013 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2017 * hildon_window_get_is_topmost:
2018 * @self: A #HildonWindow
2020 * Returns whether the #HildonWindow is currenty activated by the
2023 * Return value: %TRUE if @self is currently activated, %FALSE otherwise.
2026 hildon_window_get_is_topmost (HildonWindow *self)
2028 HildonWindowPrivate *priv;
2030 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
2032 priv = HILDON_WINDOW_GET_PRIVATE (self);
2033 return priv->is_topmost;
2037 * hildon_window_set_app_menu:
2038 * @self: a #HildonWindow
2039 * @menu: a #HildonAppMenu to be used for this window
2041 * Sets the menu to be used for this window. Pass %NULL to remove the
2042 * current menu. Any reference to a previous menu will be dropped.
2043 * #HildonWindow takes ownership of the passed menu and
2044 * you're not supposed to free it yourself anymore.
2046 * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
2047 * you should use hildon_window_set_main_menu() instead.
2052 hildon_window_set_app_menu (HildonWindow *self,
2053 HildonAppMenu *menu)
2055 HildonWindowPrivate *priv;
2056 HildonAppMenu *old_menu;
2058 g_return_if_fail (HILDON_IS_WINDOW (self));
2059 g_return_if_fail (!menu || HILDON_IS_APP_MENU (menu));
2060 priv = HILDON_WINDOW_GET_PRIVATE (self);
2062 old_menu = priv->app_menu;
2065 priv->app_menu = menu;
2067 g_object_ref_sink (menu);
2069 /* Unref old menu */
2071 g_object_unref (old_menu);
2075 * hildon_window_get_app_menu:
2076 * @self: a #HildonWindow
2078 * Returns the #HildonAppMenu assigned to @self, or %NULL if it's
2079 * unset. Note that the window is still the owner of the menu.
2081 * Note that if you're using a #GtkMenu rather than a #HildonAppMenu
2082 * you should use hildon_window_get_main_menu() instead.
2084 * Returns: a #HildonAppMenu
2089 hildon_window_get_app_menu (HildonWindow *self)
2091 HildonWindowPrivate *priv;
2093 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
2095 priv = HILDON_WINDOW_GET_PRIVATE (self);
2097 return priv->app_menu;
2101 hildon_window_update_markup (HildonWindow *window)
2103 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
2104 GdkAtom markup_atom = gdk_atom_intern ("_HILDON_WM_NAME", FALSE);
2105 GdkAtom utf8_atom = gdk_atom_intern ("UTF8_STRING", FALSE);
2106 GdkWindow *gdkwin = GTK_WIDGET (window)->window;
2109 gdk_property_change (gdkwin, markup_atom, utf8_atom, 8,
2110 GDK_PROP_MODE_REPLACE, (const guchar *) priv->markup,
2111 strlen (priv->markup));
2113 gdk_property_delete (gdkwin, markup_atom);
2118 * hildon_window_get_markup:
2119 * @window: a #HildonWindow
2121 * Gets the marked up title of the window title. See hildon_window_set_markup()
2123 * Returns: the marked up title of the window, or %NULL if none has
2124 * been set explicitely. The returned string is owned by the widget
2125 * and must not be modified or freed.
2130 hildon_window_get_markup (HildonWindow *window)
2132 HildonWindowPrivate *priv;
2134 g_return_val_if_fail (HILDON_IS_WINDOW (window), NULL);
2136 priv = HILDON_WINDOW_GET_PRIVATE (window);
2138 return priv->markup;
2142 * hildon_window_set_markup:
2143 * @window: a #HildonWindow
2144 * @markup: the marked up title of the window, or %NULL to unset the
2147 * Sets the marked up title of @window. The accepted format is the one
2148 * used in Pango (see #PangoMarkupFormat) with the exception of
2151 * Note that you need support from the window manager for this title
2152 * to be used. See gtk_window_set_title() for the standard way of
2153 * setting the title of a window.
2158 hildon_window_set_markup (HildonWindow *window,
2159 const gchar *markup)
2161 HildonWindowPrivate *priv;
2164 g_return_if_fail (HILDON_IS_WINDOW (window));
2166 priv = HILDON_WINDOW_GET_PRIVATE (window);
2168 new_markup = g_strdup (markup);
2169 g_free (priv->markup);
2170 priv->markup = new_markup;
2172 if (GTK_WIDGET_REALIZED (window))
2173 hildon_window_update_markup (window);
2175 g_object_notify (G_OBJECT (window), "markup");