2 * This file is a part of hildon
4 * Copyright (C) 2006 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-window
27 * @short_description: Widget representing a top-level window in the Hildon framework.
29 * The HildonWindow is a GTK widget which represents a top-level
30 * window in the Hildon framework. It is derived from the GtkWindow
31 * and provides additional commodities specific to the Hildon
34 * Among these windows in the Hildon framework can have a single menu
35 * attached, which is toggled with a hardware key or by tapping
36 * a custom button in the window frame. This menu can be set
37 * by providing a GtkMenu to the hildon_window_set_menu() method.
39 * Similarly a window in the Hildon framework can have several toolbars
40 * attached. These can be added to the HildonWindow with
41 * hildon_window_add_toolbar().
44 * <title>Creating a HildonWindow</title>
46 * HildonWindow *window;
47 * GtkToolbar *toolbar;
49 * GdkPixbuf *icon_pixbuf;
51 * window = HILDON_WINDOW (hildon_window_new());
53 * toolbar = create_toolbar();
55 * menu = create_menu();
57 * icon_pixbuf = create_icon();
59 * hildon_window_set_menu (window, menu);
61 * hildon_window_add_toolbar (window, toolbar);
63 * // Can be used to set the window fullscreen
64 * gtk_window_fullscreen (GTK_WINDOW (window));
66 * // Used to trigger the blinking of the window's icon in the task navigator
67 * gtk_window_set_urgency_hint (GTK_WINDOW (window), TRUE);
69 * // Change the window's icon in the task navigator
70 * gtk_window_set_icon (GTK_WINDOW (window), icon_pixbuf);
81 #include <X11/Xatom.h>
82 #include <gdk/gdkkeysyms.h>
84 #include <gtk/gtkprivate.h>
86 #include "hildon-window.h"
87 #include "hildon-window-private.h"
88 #include "hildon-find-toolbar.h"
89 #include "hildon-defines.h"
91 #define _(String) gettext(String)
93 #define TOOLBAR_HEIGHT 40
95 #define TOOLBAR_MIDDLE 10
98 #define CAN_HIBERNATE "CANKILL"
100 #define CAN_HIBERNATE_LENGTH 7
102 #define CAN_HIBERNATE_PROPERTY "_HILDON_ABLE_TO_HIBERNATE"
104 #define TITLE_SEPARATOR " - "
106 typedef void (*HildonWindowSignal) (HildonWindow *, gint, gpointer);
109 hildon_window_init (HildonWindow * self);
112 hildon_window_class_init (HildonWindowClass * window_class);
115 hildon_window_menu_popup_func (GtkMenu *menu,
121 hildon_window_menu_popup_func_full (GtkMenu *menu,
127 hildon_window_expose (GtkWidget *widget,
128 GdkEventExpose *event);
130 hildon_window_forall (GtkContainer *container,
131 gboolean include_internals,
132 GtkCallback callback,
133 gpointer callback_data);
135 hildon_window_show_all (GtkWidget *widget);
138 hildon_window_size_allocate (GtkWidget * widget,
139 GtkAllocation *allocation);
141 hildon_window_size_request (GtkWidget * widget,
142 GtkRequisition *requisition);
144 hildon_window_finalize (GObject *obj_self);
147 hildon_window_get_property (GObject *object,
153 hildon_window_destroy (GtkObject *obj);
156 hildon_window_realize (GtkWidget *widget);
159 hildon_window_unrealize (GtkWidget *widget);
162 hildon_window_map (GtkWidget *widget);
165 hildon_window_unmap (GtkWidget *widget);
168 hildon_window_key_press_event (GtkWidget *widget,
172 hildon_window_key_release_event (GtkWidget *widget,
175 hildon_window_window_state_event (GtkWidget *widget,
176 GdkEventWindowState *event);
178 hildon_window_focus_out_event (GtkWidget *widget,
179 GdkEventFocus *event);
182 hildon_window_notify (GObject *gobject,
186 hildon_window_is_topmost_notify (HildonWindow *window);
189 hildon_window_toggle_menu (HildonWindow * self,
194 hildon_window_toggle_menu_real (HildonWindow * self,
199 hildon_window_escape_timeout (gpointer data);
201 static GdkFilterReturn
202 hildon_window_event_filter (GdkXEvent *xevent,
206 static GdkFilterReturn
207 hildon_window_root_window_event_filter (GdkXEvent *xevent,
212 hildon_window_get_borders (HildonWindow *window);
215 visible_toolbar (gpointer data,
219 paint_toolbar (GtkWidget *widget,
221 GdkEventExpose * event,
222 gboolean fullscreen);
237 G_DEFINE_TYPE (HildonWindow, hildon_window, GTK_TYPE_WINDOW);
240 hildon_window_class_init (HildonWindowClass * window_class)
242 /* Get convenience variables */
243 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (window_class);
244 GObjectClass *object_class = G_OBJECT_CLASS (window_class);
245 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (window_class);
247 object_class->get_property = hildon_window_get_property;
248 object_class->notify = hildon_window_notify;
249 widget_class->size_allocate = hildon_window_size_allocate;
250 widget_class->size_request = hildon_window_size_request;
251 widget_class->expose_event = hildon_window_expose;
252 widget_class->show_all = hildon_window_show_all;
253 widget_class->realize = hildon_window_realize;
254 widget_class->unrealize = hildon_window_unrealize;
255 widget_class->key_press_event = hildon_window_key_press_event;
256 widget_class->key_release_event = hildon_window_key_release_event;
257 widget_class->window_state_event = hildon_window_window_state_event;
258 widget_class->focus_out_event = hildon_window_focus_out_event;
259 widget_class->map = hildon_window_map;
260 widget_class->unmap = hildon_window_unmap;
262 /* now the object stuff */
263 object_class->finalize = hildon_window_finalize;
265 /* To the container */
266 container_class->forall = hildon_window_forall;
269 window_class->toggle_menu = hildon_window_toggle_menu_real;
272 GTK_OBJECT_CLASS (window_class)->destroy = hildon_window_destroy;
274 g_type_class_add_private (window_class,
275 sizeof (struct _HildonWindowPrivate));
277 /* Install properties */
280 * HildonWindow:is-topmost:
282 * Whether the window is currently activated by the window manager.
284 g_object_class_install_property (object_class, PROP_IS_TOPMOST,
285 g_param_spec_boolean ("is-topmost",
287 "Whether the window is currently activated by the window "
292 gtk_widget_class_install_style_property (widget_class,
293 g_param_spec_boxed ("borders",
295 "Size of graphical window borders",
299 gtk_widget_class_install_style_property (widget_class,
300 g_param_spec_boxed ("toolbar-borders",
301 "Graphical toolbar borders",
302 "Size of graphical toolbar borders",
306 /* opera hack, install clip operation signal */
307 g_signal_new ("clipboard_operation",
308 G_OBJECT_CLASS_TYPE (object_class),
310 G_STRUCT_OFFSET (HildonWindowClass, clipboard_operation),
312 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1,
317 hildon_window_init (HildonWindow *self)
319 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
320 g_assert (priv != NULL);
322 priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
323 gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
325 priv->visible_toolbars = 0;
326 priv->is_topmost = FALSE;
327 priv->borders = NULL;
328 priv->toolbar_borders = NULL;
329 priv->escape_timeout = 0;
331 priv->fullscreen = FALSE;
333 priv->program = NULL;
335 /* We need to track the root window _MB_CURRENT_APP_WINDOW property */
336 gdk_window_set_events (gdk_get_default_root_window (),
337 gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK);
339 gdk_window_add_filter (gdk_get_default_root_window (),
340 hildon_window_root_window_event_filter, self);
344 hildon_window_finalize (GObject * obj_self)
347 HildonWindowPrivate *priv;
349 g_return_if_fail (HILDON_WINDOW (obj_self));
351 priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
352 g_assert (priv != NULL);
354 self = HILDON_WINDOW (obj_self);
356 if (priv->escape_timeout) {
357 g_source_remove (priv->escape_timeout);
358 priv->escape_timeout = 0;
362 gtk_border_free (priv->borders);
364 if (priv->toolbar_borders)
365 gtk_border_free (priv->toolbar_borders);
367 if (G_OBJECT_CLASS (hildon_window_parent_class)->finalize)
368 G_OBJECT_CLASS (hildon_window_parent_class)->finalize (obj_self);
373 hildon_window_realize (GtkWidget *widget)
375 Atom *old_atoms, *new_atoms;
379 Window active_window;
380 HildonWindowPrivate *priv;
382 GTK_WIDGET_CLASS (hildon_window_parent_class)->realize (widget);
384 priv = HILDON_WINDOW_GET_PRIVATE (widget);
385 g_assert (priv != NULL);
387 gtk_widget_realize (GTK_WIDGET (priv->vbox));
389 /* catch the custom button signal from mb to display the menu */
390 gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
392 window = GDK_WINDOW_XID (widget->window);
393 disp = GDK_WINDOW_XDISPLAY (widget->window);
395 /* Enable custom button that is used for menu */
396 XGetWMProtocols (disp, window, &old_atoms, &atom_count);
397 new_atoms = g_new (Atom, atom_count + 1);
399 memcpy (new_atoms, old_atoms, sizeof(Atom) * atom_count);
401 new_atoms[atom_count++] =
402 XInternAtom (disp, "_NET_WM_CONTEXT_CUSTOM", False);
404 XSetWMProtocols (disp, window, new_atoms, atom_count);
409 /* rely on GDK to set the window group to its default */
410 gdk_window_set_group (widget->window, NULL);
413 gboolean can_hibernate = hildon_program_get_can_hibernate (priv->program);
415 hildon_window_set_can_hibernate_property (HILDON_WINDOW (widget),
419 /* Update the topmost status */
420 active_window = hildon_window_get_active_window();
421 hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
423 /* Update the window title */
424 hildon_window_update_title(HILDON_WINDOW (widget));
428 hildon_window_unrealize (GtkWidget *widget)
430 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
431 g_assert (priv != NULL);
433 gdk_window_remove_filter (widget->window, hildon_window_event_filter,
436 gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
437 GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
441 hildon_window_map (GtkWidget *widget)
443 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
444 g_assert (priv != NULL);
446 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->map)
447 GTK_WIDGET_CLASS (hildon_window_parent_class)->map (widget);
449 if (GTK_WIDGET_VISIBLE (priv->vbox))
450 gtk_widget_map (priv->vbox);
454 hildon_window_unmap (GtkWidget *widget)
456 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
457 g_assert (priv != NULL);
459 gtk_widget_unmap (priv->vbox);
461 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
462 GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
466 hildon_window_get_property (GObject *object,
471 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (object);
472 g_assert (priv != NULL);
474 switch (property_id) {
476 case PROP_IS_TOPMOST:
477 g_value_set_boolean (value, priv->is_topmost);
481 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
487 * Retrieve the graphical borders size used by the themes
490 hildon_window_get_borders (HildonWindow *window)
492 GtkBorder zero = {0, 0, 0, 0};
493 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
496 GtkBorder *borders = NULL;
497 GtkBorder *toolbar_borders = NULL;
500 gtk_border_free (priv->borders);
501 if (priv->toolbar_borders)
502 gtk_border_free (priv->toolbar_borders);
504 priv->borders = NULL;
505 priv->toolbar_borders = NULL;
507 gtk_widget_style_get (GTK_WIDGET (window), "borders",&borders,
508 "toolbar-borders", &toolbar_borders,
511 // We're doing a copy here instead of reusing the pointer,
512 // as we don't know where it comes from (has it been allocated using
513 // malloc or slices... and we want to free it sanely. Blowing on
517 priv->borders = gtk_border_copy (borders);
518 gtk_border_free (borders);
520 priv->borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
522 if (toolbar_borders) {
523 priv->toolbar_borders = gtk_border_copy (toolbar_borders);
524 gtk_border_free (toolbar_borders);
526 priv->toolbar_borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
530 hildon_window_expose (GtkWidget *widget,
531 GdkEventExpose * event)
533 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
536 GtkWidget *bx = priv->vbox;
537 GtkBox *box = GTK_BOX(bx);
538 GtkBorder *b = priv->borders;
539 GtkBorder *tb = priv->toolbar_borders;
542 if (! priv->borders) {
543 hildon_window_get_borders (HILDON_WINDOW (widget));
545 tb = priv->toolbar_borders;
548 tb_height = bx->allocation.height + tb->top + tb->bottom;
550 paint_toolbar (widget, box,
551 event, priv->fullscreen);
553 if (! priv->fullscreen) {
555 /* Draw the left and right window border */
556 gint side_borders_height = widget->allocation.height - b->top;
558 if (priv->visible_toolbars)
559 side_borders_height -= tb_height;
561 side_borders_height -= b->bottom;
565 gtk_paint_box (widget->style, widget->window,
566 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
567 &event->area, widget, "left-border",
568 widget->allocation.x, widget->allocation.y +
569 b->top, b->left, side_borders_height);
574 gtk_paint_box (widget->style, widget->window,
575 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
576 &event->area, widget, "right-border",
577 widget->allocation.x + widget->allocation.width -
578 b->right, widget->allocation.y + b->top,
579 b->right, side_borders_height);
582 /* If no toolbar, draw the bottom window border */
583 if (! priv->visible_toolbars && b->bottom > 0)
585 gtk_paint_box (widget->style, widget->window,
586 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
587 &event->area, widget, "bottom-border",
588 widget->allocation.x, widget->allocation.y +
589 (widget->allocation.height - b->bottom),
590 widget->allocation.width, b->bottom);
593 /* Draw the top border */
596 gtk_paint_box (widget->style, widget->window,
597 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
598 &event->area, widget, "top-border",
599 widget->allocation.x, widget->allocation.y,
600 widget->allocation.width, b->top);
606 /* don't draw the window stuff as it overwrites our borders with a blank
607 * rectangle. Instead start with the drawing of the GtkBin */
608 GTK_WIDGET_CLASS (g_type_class_peek_parent (hildon_window_parent_class))->expose_event (widget, event);
610 /* FIXME Not sure why this is commented out
611 * GTK_WIDGET_CLASS (hildon_window_parent_class))->
612 * expose_event (widget, event);
619 hildon_window_size_request (GtkWidget *widget,
620 GtkRequisition *requisition)
622 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
625 GtkWidget *child = GTK_BIN (widget)->child;
627 gint border_width = GTK_CONTAINER(widget)->border_width;
631 hildon_window_get_borders (HILDON_WINDOW (widget));
635 gtk_widget_size_request (child, requisition);
637 if (priv->vbox != NULL)
638 gtk_widget_size_request (priv->vbox, &req2);
640 requisition->height += req2.height;
641 requisition->width = (requisition->width < req2.width) ?
642 req2.width : requisition->width;
644 requisition->width += 2 * border_width;
645 requisition->height += 2 * border_width;
647 if (! priv->fullscreen)
649 requisition->height += priv->borders->top;
650 if (req2.height == 0)
651 requisition->height += priv->borders->bottom;
652 requisition->width += priv->borders->left + priv->borders->right;
657 hildon_window_size_allocate (GtkWidget *widget,
658 GtkAllocation *allocation)
660 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
663 GtkAllocation box_alloc;
664 GtkAllocation alloc = *allocation;
666 gint border_width = GTK_CONTAINER(widget)->border_width;
668 GtkWidget *box = priv->vbox;
669 GtkBin *bin = GTK_BIN(widget);
670 GtkBorder *b = priv->borders;
671 GtkBorder *tb = priv->toolbar_borders;
675 hildon_window_get_borders (HILDON_WINDOW (widget));
677 tb = priv->toolbar_borders;
680 widget->allocation = *allocation;
682 gtk_widget_get_child_requisition (box, &req);
684 box_alloc.width = allocation->width - tb->left - tb->right;
685 box_alloc.height = ( (req.height < allocation->height) ?
686 req.height : allocation->height );
687 box_alloc.x = allocation->x + tb->left;
688 box_alloc.y = allocation->y + allocation->height - box_alloc.height - tb->bottom;
690 if (bin->child != NULL && GTK_IS_WIDGET (bin->child)
691 && GTK_WIDGET_VISIBLE (bin->child))
693 alloc.x += border_width;
694 alloc.y += border_width;
695 alloc.width -= (border_width * 2);
696 alloc.height -= (border_width * 2) + box_alloc.height;
698 if (! priv->fullscreen)
701 alloc.width -= (b->left + b->right);
704 alloc.height -= b->top;
706 if (box_alloc.height <= 0)
707 alloc.height -= b->bottom;
709 alloc.height -= (tb->top + tb->bottom);
713 if (!(box_alloc.height <= 0))
714 alloc.height -= (tb->top + tb->bottom);
717 gtk_widget_size_allocate (bin->child, &alloc);
720 gtk_widget_size_allocate (box, &box_alloc);
722 if (priv->previous_vbox_y != box_alloc.y)
724 /* The size of the VBox has changed, we need to redraw part
725 * of the window borders */
726 gint draw_from_y = priv->previous_vbox_y < box_alloc.y?
727 priv->previous_vbox_y - tb->top:
728 box_alloc.y - tb->top;
730 gtk_widget_queue_draw_area (widget, 0, draw_from_y,
731 widget->allocation.width,
732 widget->allocation.height - draw_from_y);
734 priv->previous_vbox_y = box_alloc.y;
740 hildon_window_forall (GtkContainer *container,
741 gboolean include_internals,
742 GtkCallback callback,
743 gpointer callback_data)
745 HildonWindow *self = HILDON_WINDOW (container);
746 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
748 g_return_if_fail (callback != NULL);
751 GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
752 callback, callback_data);
753 if (include_internals && priv->vbox != NULL)
754 (* callback)(GTK_WIDGET (priv->vbox), callback_data);
758 hildon_window_show_all (GtkWidget *widget)
760 HildonWindow *self = HILDON_WINDOW (widget);
761 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
763 g_assert (priv != NULL);
765 GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
766 gtk_widget_show_all (priv->vbox);
770 hildon_window_destroy (GtkObject *obj)
772 HildonWindow *self = HILDON_WINDOW (obj);
773 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (obj);
774 GList *menu_list = NULL;
775 GList *menu_node = NULL;
777 g_assert (priv != NULL);
779 if (priv->vbox != NULL)
783 GtkWidget * common_toolbar =
784 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
785 if (common_toolbar && common_toolbar->parent == priv->vbox)
787 gtk_container_remove (GTK_CONTAINER (priv->vbox),
792 gtk_widget_unparent (priv->vbox);
797 menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
798 menu_node = menu_list;
802 if (GTK_IS_MENU (menu_node->data))
804 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_node->data)))
806 gtk_menu_popdown (GTK_MENU (menu_node->data));
807 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_node->data));
809 gtk_menu_detach (GTK_MENU (menu_node->data));
811 /* Destroy it, but only if it's not a common menu */
813 hildon_program_get_common_menu (priv->program) != menu_node->data) {
814 gtk_object_destroy (GTK_OBJECT (menu_node->data));
815 g_object_unref (menu_node->data);
818 menu_node = menu_node->next;
821 g_list_free (menu_list);
826 hildon_program_remove_window (priv->program, self);
829 gdk_window_remove_filter (gdk_get_default_root_window(),
830 hildon_window_root_window_event_filter,
833 gtk_widget_set_events (GTK_WIDGET(obj), 0);
835 GTK_OBJECT_CLASS (hildon_window_parent_class)->destroy (obj);
839 hildon_window_notify (GObject *gobject,
842 HildonWindow *window = HILDON_WINDOW (gobject);
844 if (g_str_equal (param->name, "title"))
847 hildon_window_update_title (window);
849 else if (g_str_equal (param->name, "is-topmost"))
851 hildon_window_is_topmost_notify (window);
854 if (G_OBJECT_CLASS(hildon_window_parent_class)->notify)
855 G_OBJECT_CLASS(hildon_window_parent_class)->notify (gobject, param);
860 visible_toolbar (gpointer data,
863 if (GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
864 (*((gint *)user_data))++;
868 find_findtoolbar_index (gpointer data,
871 gint *pass_bundle = (gint *)user_data;
873 if(((GtkBoxChild *)data)->widget->allocation.y < pass_bundle[0]
874 && GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
879 find_findtoolbar (gpointer data,
882 if(HILDON_IS_FIND_TOOLBAR (((GtkBoxChild *)data)->widget)
883 && GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
884 (*((GtkWidget **)user_data)) = ((GtkBoxChild *)data)->widget;
888 paint_toolbar (GtkWidget *widget,
890 GdkEventExpose * event,
893 gint toolbar_num = 0;
896 GtkWidget *findtoolbar = NULL;
897 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
898 gchar toolbar_mode[40];
899 GtkBorder *tb = priv->toolbar_borders;
901 g_assert (priv != NULL);
903 /* collect info to help on painting the boxes */
904 g_list_foreach (box->children, visible_toolbar,
905 (gpointer) &toolbar_num);
910 g_list_foreach (box->children, find_findtoolbar, (gpointer) &findtoolbar);
912 if (findtoolbar != NULL)
914 gint pass_bundle[2];/* an array for convient data passing
915 the first member contains the y allocation
916 of the find toolbar, and the second allocation
917 contains the index(how many toolbars are above
919 pass_bundle[0] = findtoolbar->allocation.y;
920 pass_bundle[1] = ftb_index;
921 g_list_foreach(box->children, find_findtoolbar_index,
922 (gpointer) pass_bundle);
923 ftb_index = pass_bundle[1];
927 sprintf (toolbar_mode, "toolbar%sframe-top",
928 fullscreen ? "-fullscreen-" : "-");
929 gtk_paint_box (widget->style, widget->window,
930 GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
931 &event->area, widget, toolbar_mode,
932 widget->allocation.x,
933 GTK_WIDGET (box)->allocation.y - tb->top,
934 widget->allocation.width, tb->top);
936 /*top most toolbar painting*/
937 if (findtoolbar != NULL && ftb_index == 0 )
939 sprintf (toolbar_mode, "findtoolbar%s",
940 fullscreen ? "-fullscreen" : "");
942 gtk_paint_box (widget->style, widget->window,
943 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
944 &event->area, widget, toolbar_mode,
945 widget->allocation.x,
946 GTK_WIDGET(box)->allocation.y,
947 widget->allocation.width,
952 sprintf (toolbar_mode, "toolbar%s",
953 fullscreen ? "-fullscreen" : "");
955 gtk_paint_box (widget->style, widget->window,
956 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
957 &event->area, widget, toolbar_mode,
958 widget->allocation.x,
959 GTK_WIDGET(box)->allocation.y,
960 widget->allocation.width,
963 /*multi toolbar painting*/
964 for (count = 0; count < toolbar_num - 1; count++)
966 sprintf (toolbar_mode, "toolbar%sframe-middle",
967 fullscreen ? "-fullscreen-" : "-");
969 gtk_paint_box (widget->style, widget->window,
970 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
971 &event->area, widget, toolbar_mode,
972 widget->allocation.x,
973 GTK_WIDGET(box)->allocation.y +
974 (1 + count) * TOOLBAR_HEIGHT +
975 count * TOOLBAR_MIDDLE,
976 widget->allocation.width,
979 if (findtoolbar != NULL && count + 1 == ftb_index)
982 sprintf (toolbar_mode, "findtoolbar%s",
983 fullscreen ? "-fullscreen" : "");
985 gtk_paint_box (widget->style, widget->window,
986 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
987 &event->area, widget, toolbar_mode,
988 widget->allocation.x,
989 GTK_WIDGET(box)->allocation.y +
990 (1 + count) * (TOOLBAR_HEIGHT + TOOLBAR_MIDDLE),
991 widget->allocation.width,
996 sprintf (toolbar_mode, "toolbar%s",
997 fullscreen ? "-fullscreen" : "");
999 gtk_paint_box (widget->style, widget->window,
1000 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
1001 &event->area, widget, toolbar_mode,
1002 widget->allocation.x,
1003 GTK_WIDGET(box)->allocation.y +
1004 (1 + count) * (TOOLBAR_HEIGHT + TOOLBAR_MIDDLE),
1005 widget->allocation.width,
1009 sprintf (toolbar_mode, "toolbar%sframe-bottom",
1010 fullscreen ? "-fullscreen-" : "-");
1012 gtk_paint_box (widget->style, widget->window,
1013 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
1014 &event->area, widget, toolbar_mode,
1015 widget->allocation.x,
1016 GTK_WIDGET(box)->allocation.y +
1017 GTK_WIDGET(box)->allocation.height,
1018 widget->allocation.width, tb->bottom);
1022 * Checks the root window to know which is the topped window
1025 hildon_window_get_active_window (void)
1033 unsigned long extra;
1037 unsigned char *char_pointer;
1039 Atom active_app_atom =
1040 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1044 gdk_error_trap_push ();
1045 status = XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1046 active_app_atom, 0L, 16L,
1047 0, XA_WINDOW, &realtype, &format,
1048 &n, &extra, &win.char_pointer);
1049 xerror = gdk_error_trap_pop ();
1050 if (xerror || !(status == Success && realtype == XA_WINDOW && format == 32
1051 && n == 1 && win.win != NULL))
1053 if (win.win != NULL)
1054 XFree (win.char_pointer);
1060 if (win.win != NULL)
1061 XFree(win.char_pointer);
1067 xclient_message_type_check (XClientMessageEvent *cm,
1070 return cm->message_type == XInternAtom(GDK_DISPLAY(), name, FALSE);
1074 * Handle the window border custom button, which toggles the menu,
1075 * and the Hildon input method copy paste messages
1077 static GdkFilterReturn
1078 hildon_window_event_filter (GdkXEvent *xevent,
1082 XAnyEvent *eventti = xevent;
1084 if (eventti->type == ClientMessage)
1086 XClientMessageEvent *cm = xevent;
1088 if (xclient_message_type_check (cm, "_MB_GRAB_TRANSFER"))
1090 hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]);
1091 return GDK_FILTER_REMOVE;
1093 /* opera hack clipboard client message */
1094 else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY"))
1096 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1097 HILDON_WINDOW_CO_COPY);
1098 return GDK_FILTER_REMOVE;
1100 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT"))
1102 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1103 HILDON_WINDOW_CO_CUT);
1104 return GDK_FILTER_REMOVE;
1106 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE"))
1108 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1109 HILDON_WINDOW_CO_PASTE);
1110 return GDK_FILTER_REMOVE;
1114 return GDK_FILTER_CONTINUE;
1118 * Here we keep track of changes in the _MB_CURRENT_APP_WINDOW,
1119 * to know when we acquire/lose topmost status
1121 static GdkFilterReturn
1122 hildon_window_root_window_event_filter (GdkXEvent *xevent,
1126 XAnyEvent *eventti = xevent;
1127 HildonWindow *hwindow = HILDON_WINDOW (data);
1129 if (eventti->type == PropertyNotify)
1131 XPropertyEvent *pevent = xevent;
1132 Atom active_app_atom =
1133 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1135 if (pevent->atom == active_app_atom)
1137 Window active_window = hildon_window_get_active_window();
1139 hildon_window_update_topmost (hwindow, active_window);
1143 return GDK_FILTER_CONTINUE;
1147 * Handle the menu hardware key here
1150 hildon_window_key_press_event (GtkWidget *widget,
1153 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1155 g_return_val_if_fail (HILDON_IS_WINDOW (widget),FALSE);
1158 switch (event->keyval)
1160 case HILDON_HARDKEY_MENU:
1161 if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME))
1164 case HILDON_HARDKEY_ESC:
1165 if (!priv->escape_timeout)
1167 priv->escape_timeout = g_timeout_add
1168 (HILDON_WINDOW_LONG_PRESS_TIME,
1169 hildon_window_escape_timeout, widget);
1174 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event);
1178 hildon_window_key_release_event (GtkWidget *widget,
1181 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1183 g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE);
1186 switch (event->keyval)
1188 case HILDON_HARDKEY_ESC:
1189 if (priv->escape_timeout)
1191 g_source_remove (priv->escape_timeout);
1192 priv->escape_timeout = 0;
1197 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event);
1202 * We keep track of the window state changes, because the drawing
1203 * (borders) differs whether we are in fullscreen mode or not
1206 hildon_window_window_state_event (GtkWidget *widget,
1207 GdkEventWindowState *event)
1209 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1210 g_assert (priv != NULL);
1212 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1213 priv->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1215 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event)
1217 return GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event (
1228 * If the window lost focus while the user started to press the ESC key, we
1229 * won't get the release event. We need to stop the timeout.
1232 hildon_window_focus_out_event (GtkWidget *widget,
1233 GdkEventFocus *event)
1235 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1237 if (priv->escape_timeout)
1239 g_source_remove (priv->escape_timeout);
1240 priv->escape_timeout = 0;
1243 return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event);
1247 * The menu popuping needs a menu popup-function
1250 hildon_window_menu_popup_func (GtkMenu *menu,
1258 GdkWindow *window = GTK_WIDGET(widget)->window;
1262 gdk_window_get_origin (window, &window_x, &window_y);
1265 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1266 "vertical-offset", y, NULL);
1268 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1270 *x = GTK_WIDGET (widget)->allocation.width + window_x - GTK_WIDGET (menu)->allocation.width - *x;
1280 hildon_window_menu_popup_func_full (GtkMenu *menu,
1286 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1287 "vertical-offset", y, NULL);
1289 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1290 *x = GTK_WIDGET (widget)->allocation.width - GTK_WIDGET (menu)->allocation.width - *x;
1299 * Takes the common toolbar when we acquire the top-most status
1302 hildon_window_is_topmost_notify (HildonWindow *window)
1304 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1308 if (priv->is_topmost)
1310 hildon_window_take_common_toolbar (window);
1315 * Sets the program to which the window belongs. This should only be called
1316 * by hildon_program_add_window
1318 void G_GNUC_INTERNAL
1319 hildon_window_set_program (HildonWindow *self,
1322 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1324 g_return_if_fail (HILDON_IS_WINDOW (self));
1325 g_assert (priv != NULL);
1329 g_object_unref (priv->program);
1332 /* Now that we are bound to a program, we can rely on it to track the
1334 gdk_window_remove_filter (gdk_get_default_root_window(),
1335 hildon_window_root_window_event_filter,
1338 priv->program = HILDON_PROGRAM (program);
1339 g_object_ref (program);
1343 * Unsets the program to which the window belongs. This should only be called
1344 * by hildon_program_remove_window
1346 void G_GNUC_INTERNAL
1347 hildon_window_unset_program (HildonWindow *self)
1349 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1351 g_return_if_fail(HILDON_IS_WINDOW (self));
1352 g_assert (priv != NULL);
1356 g_object_unref (priv->program);
1357 priv->program = NULL;
1359 /* We need to start tacking the root window again */
1360 gdk_window_set_events (gdk_get_default_root_window (),
1361 gdk_window_get_events (gdk_get_default_root_window ())
1362 | GDK_PROPERTY_CHANGE_MASK);
1364 gdk_window_add_filter (gdk_get_default_root_window (),
1365 hildon_window_root_window_event_filter, self );
1368 priv->program = NULL;
1372 * Sets whether or not the program to which this window belongs is
1373 * killable. This is used by the HildonProgram to signify to the
1374 * Task Navigator whether or not it can hibernate in memory-low situations
1376 void G_GNUC_INTERNAL
1377 hildon_window_set_can_hibernate_property (HildonWindow *self,
1378 gpointer _can_hibernate)
1380 GdkAtom killable_atom;
1381 gboolean can_hibernate;
1383 g_return_if_fail(self && HILDON_IS_WINDOW (self));
1385 if (!GTK_WIDGET_REALIZED ((GTK_WIDGET (self))))
1390 can_hibernate = * ((gboolean *)_can_hibernate);
1392 killable_atom = gdk_atom_intern (CAN_HIBERNATE_PROPERTY, FALSE);
1396 gdk_property_change (GTK_WIDGET (self)->window, killable_atom,
1397 (GdkAtom)31/* XA_STRING */, 8,
1398 GDK_PROP_MODE_REPLACE, (const guchar *)CAN_HIBERNATE,
1399 CAN_HIBERNATE_LENGTH);
1403 gdk_property_delete (GTK_WIDGET (self)->window, killable_atom);
1409 * If a common toolbar was set to the program, reparent it to
1412 void G_GNUC_INTERNAL
1413 hildon_window_take_common_toolbar (HildonWindow *self)
1415 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1417 g_return_if_fail(HILDON_IS_WINDOW (self));
1422 GtkWidget *common_toolbar =
1423 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
1425 if (common_toolbar && common_toolbar->parent != priv->vbox)
1427 g_object_ref (common_toolbar);
1428 if (common_toolbar->parent)
1430 gtk_container_remove (GTK_CONTAINER (common_toolbar->parent),
1434 gtk_box_pack_end (GTK_BOX(priv->vbox), common_toolbar,
1436 g_object_unref (common_toolbar);
1438 gtk_widget_set_size_request (common_toolbar, -1, TOOLBAR_HEIGHT);
1440 gtk_widget_show (priv->vbox);
1447 * Compare the window that was last topped, and act consequently
1450 hildon_window_update_topmost (HildonWindow *self,
1453 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1457 g_return_if_fail (HILDON_IS_WINDOW (self));
1460 my_window = GDK_WINDOW_XID (GTK_WIDGET (self)->window);
1462 if (window_id == my_window)
1464 if (! priv->is_topmost)
1466 priv->is_topmost = TRUE;
1467 hildon_window_is_topmost_notify (self);
1468 g_object_notify (G_OBJECT (self), "is-topmost");
1471 else if (priv->is_topmost)
1473 /* Should this go in the signal handler? */
1474 GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (self));
1476 if (GTK_IS_ENTRY (focus))
1477 gtk_im_context_focus_out (GTK_ENTRY (focus)->im_context);
1478 if (GTK_IS_TEXT_VIEW (focus))
1479 gtk_im_context_focus_out (GTK_TEXT_VIEW (focus)->im_context);
1481 priv->is_topmost = FALSE;
1482 hildon_window_is_topmost_notify (self);
1483 g_object_notify (G_OBJECT (self), "is-topmost");
1488 * If the application
1489 * was given a name (with g_set_application_name(), set
1490 * "ProgramName - WindowTitle" as the displayed
1493 void G_GNUC_INTERNAL
1494 hildon_window_update_title (HildonWindow *window)
1496 const gchar * application_name;
1498 g_return_if_fail (HILDON_IS_WINDOW (window));
1500 if (!GTK_WIDGET_REALIZED (window))
1505 application_name = g_get_application_name ();
1507 if (application_name && application_name[0])
1509 const gchar *old_title = gtk_window_get_title (GTK_WINDOW (window));
1513 gchar *title = NULL;
1515 if (strlen (old_title) == 0)
1516 title = g_strdup (application_name);
1518 title = g_strjoin (TITLE_SEPARATOR, application_name,
1521 gdk_window_set_title (GTK_WIDGET (window)->window, title);
1530 detach_menu_func (GtkWidget *attach_widget,
1533 /* FIXME Why is this even needed here? */
1537 hildon_window_toggle_menu (HildonWindow *self,
1541 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1543 if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
1545 return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
1555 * Toggles the display of the HildonWindow menu.
1556 * Returns whether or not something was done (whether or not we had a menu
1560 hildon_window_toggle_menu_real (HildonWindow * self,
1564 GtkMenu *menu_to_use = NULL;
1565 GList *menu_children = NULL;
1566 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1568 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1569 g_assert (priv != NULL);
1571 /* Select which menu to use, Window specific has highest priority,
1572 * then program specific */
1575 menu_to_use = GTK_MENU (priv->menu);
1577 else if (priv->program)
1579 menu_to_use = hildon_program_get_common_menu (priv->program);
1580 if (menu_to_use && gtk_menu_get_attach_widget (menu_to_use) !=
1583 g_object_ref (menu_to_use);
1584 if (gtk_menu_get_attach_widget (menu_to_use))
1586 gtk_menu_detach (menu_to_use);
1589 gtk_menu_attach_to_widget (menu_to_use, GTK_WIDGET (self),
1591 g_object_unref (menu_to_use);
1601 if (GTK_WIDGET_MAPPED (GTK_WIDGET (menu_to_use)))
1603 gtk_menu_popdown (menu_to_use);
1604 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_to_use));
1608 /* Check if the menu has items */
1609 menu_children = gtk_container_get_children (GTK_CONTAINER (menu_to_use));
1613 g_list_free (menu_children);
1615 /* Apply right theming */
1616 gtk_widget_set_name (GTK_WIDGET (menu_to_use),
1617 "menu_force_with_corners");
1619 if (priv->fullscreen)
1621 gtk_menu_popup (menu_to_use, NULL, NULL,
1622 (GtkMenuPositionFunc)
1623 hildon_window_menu_popup_func_full,
1624 self, button, time);
1628 gtk_menu_popup (menu_to_use, NULL, NULL,
1629 (GtkMenuPositionFunc)
1630 hildon_window_menu_popup_func,
1631 self, button, time);
1633 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_to_use), TRUE);
1641 * If the ESC key was not released when the timeout expires,
1645 hildon_window_escape_timeout (gpointer data)
1647 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data);
1652 GDK_THREADS_ENTER ();
1654 /* Send fake event, simulation a situation that user
1655 pressed 'x' from the corner */
1656 event = gdk_event_new(GDK_DELETE);
1657 ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window));
1658 gtk_main_do_event(event);
1660 /* That unrefs the window, so we're reffing it above */
1661 gdk_event_free(event);
1663 priv->escape_timeout = 0;
1665 GDK_THREADS_LEAVE ();
1671 * hildon_window_new:
1673 * Creates a new HildonWindow.
1675 * Return value: A @HildonWindow.
1678 hildon_window_new (void)
1680 HildonWindow *newwindow = g_object_new (HILDON_TYPE_WINDOW, NULL);
1682 return GTK_WIDGET (newwindow);
1686 * hildon_window_add_with_scrollbar
1687 * @self : A @HildonWindow
1688 * @child : A @GtkWidget
1690 * Adds the @child to the HildonWindow and creates a scrollbar
1691 * for it. Similar as adding first a @GtkScrolledWindow and then the
1695 hildon_window_add_with_scrollbar (HildonWindow *self,
1698 GtkScrolledWindow *scrolledw;
1700 g_return_if_fail (HILDON_IS_WINDOW (self));
1701 g_return_if_fail (GTK_IS_WIDGET (child));
1702 g_return_if_fail (child->parent == NULL);
1704 scrolledw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1705 gtk_scrolled_window_set_policy (scrolledw, GTK_POLICY_NEVER,
1706 GTK_POLICY_AUTOMATIC);
1707 gtk_scrolled_window_set_shadow_type (scrolledw, GTK_SHADOW_NONE);
1709 if (GTK_IS_VIEWPORT (child))
1710 gtk_container_add (GTK_CONTAINER (scrolledw), child);
1713 if (GTK_IS_CONTAINER (child) )
1714 gtk_container_set_focus_vadjustment (GTK_CONTAINER(child),
1715 gtk_scrolled_window_get_vadjustment (scrolledw) );
1716 gtk_scrolled_window_add_with_viewport (scrolledw, child);
1719 gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (scrolledw));
1723 calculate_visible_toolbars (gpointer data,
1726 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (((GtkBoxChild *)data)->widget)))
1727 (*((gint *)user_data)) ++;
1731 toolbar_visible_notify (GtkWidget *toolbar, GParamSpec *pspec,
1732 HildonWindow *window)
1734 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1738 /* Recalculate from scratch the value just in case */
1739 priv->visible_toolbars = 0;
1741 g_list_foreach (GTK_BOX (priv->vbox)->children, calculate_visible_toolbars,
1742 &priv->visible_toolbars);
1744 if (priv->visible_toolbars == 0)
1745 gtk_widget_hide (priv->vbox);
1747 gtk_widget_show (priv->vbox);
1751 * hildon_window_add_toolbar:
1752 * @self: A @HildonWindow
1753 * @toolbar: A #GtkToolbar to add to the HildonWindow
1755 * Adds a toolbar to the window. Note that the toolbar is not automatically
1756 * shown. You need to call #gtk_widget_show_all on it to make it visible.
1757 * It's also possible to hide the toolbar (without removing it) by calling
1761 hildon_window_add_toolbar (HildonWindow *self,
1762 GtkToolbar *toolbar)
1765 HildonWindowPrivate *priv;
1767 g_return_if_fail (HILDON_IS_WINDOW (self));
1768 g_return_if_fail (toolbar && GTK_IS_TOOLBAR (toolbar));
1770 priv = HILDON_WINDOW_GET_PRIVATE (self);
1772 vbox = GTK_BOX (priv->vbox);
1774 gtk_box_pack_start (vbox, GTK_WIDGET (toolbar), TRUE, TRUE, 0);
1775 gtk_box_reorder_child (vbox, GTK_WIDGET (toolbar), 0);
1776 gtk_widget_set_size_request (GTK_WIDGET (toolbar), -1, TOOLBAR_HEIGHT);
1778 g_signal_connect (G_OBJECT (toolbar), "notify::visible",
1779 G_CALLBACK (toolbar_visible_notify), self);
1781 if (GTK_WIDGET_VISIBLE (toolbar))
1783 priv->visible_toolbars++;
1784 gtk_widget_show (priv->vbox);
1787 gtk_widget_queue_resize (GTK_WIDGET (self));
1791 * hildon_window_remove_toolbar:
1792 * @self: A @HildonWindow
1793 * @toolbar: A #GtkToolbar to remove from the HildonWindow
1795 * Removes a toolbar from the window. Note that this decreases the refference
1796 * count on the widget. If you want to keep the toolbar alive call #g_object_ref
1797 * before calling this function.
1800 hildon_window_remove_toolbar (HildonWindow *self,
1801 GtkToolbar *toolbar)
1803 HildonWindowPrivate *priv;
1805 g_return_if_fail (HILDON_IS_WINDOW (self));
1807 priv = HILDON_WINDOW_GET_PRIVATE (self);
1809 if (GTK_WIDGET_VISIBLE (toolbar))
1811 if (--(priv->visible_toolbars) == 0)
1812 gtk_widget_hide (priv->vbox);
1815 g_signal_handlers_disconnect_by_func (toolbar, toolbar_visible_notify, self);
1817 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (toolbar));
1821 * hildon_window_get_menu:
1822 * @self : #HildonWindow
1824 * Gets the #GtMenu assigned to the #HildonAppview. Note that the
1825 * window is still the owner of the menu.
1827 * Return value: The #GtkMenu assigned to this application view.
1830 hildon_window_get_menu (HildonWindow * self)
1832 HildonWindowPrivate *priv;
1834 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
1836 priv = HILDON_WINDOW_GET_PRIVATE (self);
1838 return GTK_MENU (priv->menu);
1841 /* Since we've been asking developers to call gtk_window_add_accel_group()
1842 * themselves, do not trigger criticals by trying it again.
1845 hildon_window_add_accel_group (HildonWindow *self,
1846 GtkAccelGroup *accel_group)
1850 groups = gtk_accel_groups_from_object (G_OBJECT (self));
1851 for (l = groups; l != NULL; l = l->next)
1852 if (l->data == (gpointer)accel_group)
1853 /* Maybe print a warning here? */
1856 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
1860 * hildon_window_set_main_menu:
1861 * @self: A #HildonWindow
1862 * @menu: The #GtkMenu to be used for this #HildonWindow
1864 * Sets the menu to be used for this window. This menu overrides
1865 * a program-wide menu that may have been set with
1866 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1867 * menu. #HildonWindow takes ownership of the passed menu and you're
1868 * not supposed to free it yourself anymore.
1873 hildon_window_set_main_menu (HildonWindow* self,
1876 HildonWindowPrivate *priv;
1877 GtkAccelGroup *accel_group;
1879 g_return_if_fail (HILDON_IS_WINDOW (self));
1881 priv = HILDON_WINDOW_GET_PRIVATE (self);
1883 if (priv->menu != NULL)
1885 accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
1886 if (accel_group != NULL)
1887 gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
1889 gtk_menu_detach (GTK_MENU (priv->menu));
1890 g_object_unref (priv->menu);
1893 priv->menu = (menu != NULL) ? GTK_WIDGET (menu) : NULL;
1894 if (priv->menu != NULL)
1896 gtk_widget_set_name (priv->menu, "menu_force_with_corners");
1897 gtk_menu_attach_to_widget (GTK_MENU (priv->menu), GTK_WIDGET (self), &detach_menu_func);
1898 g_object_ref (GTK_MENU (priv->menu));
1900 accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
1901 if (accel_group != NULL)
1902 hildon_window_add_accel_group (self, accel_group);
1907 * hildon_window_set_menu:
1908 * @self: A #HildonWindow
1909 * @menu: The #GtkMenu to be used for this #HildonWindow
1911 * Sets the menu to be used for this window. This menu overrides
1912 * a program-wide menu that may have been set with
1913 * hildon_program_set_common_menu. Pass NULL to remove the current
1914 * menu. HildonWindow takes ownership of the passed menu and you're
1915 * not supposed to free it yourself anymore.
1917 * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the
1918 * #GtkMenu. To pass control about visibility to the application
1919 * developer, hildon_window_set_main_menu() was introduced, which
1922 * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
1925 hildon_window_set_menu (HildonWindow *self,
1928 HildonWindowPrivate *priv;
1930 g_return_if_fail (HILDON_IS_WINDOW (self));
1932 hildon_window_set_main_menu (self, menu);
1934 priv = HILDON_WINDOW_GET_PRIVATE (self);
1936 if (priv->menu != NULL)
1937 gtk_widget_show_all (GTK_WIDGET (priv->menu));
1941 * hildon_window_get_is_topmost:
1942 * @self: A #HildonWindow
1944 * Return value: Whether or not the #HildonWindow is currenltly activated
1945 * by the window manager.
1948 hildon_window_get_is_topmost (HildonWindow *self)
1950 HildonWindowPrivate *priv;
1952 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1954 priv = HILDON_WINDOW_GET_PRIVATE (self);
1955 return priv->is_topmost;