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 */
279 g_object_class_install_property (object_class, PROP_IS_TOPMOST,
280 g_param_spec_boolean ("is-topmost",
282 "Whether the window is currently activated by the window "
287 gtk_widget_class_install_style_property (widget_class,
288 g_param_spec_boxed ("borders",
290 "Size of graphical window borders",
294 gtk_widget_class_install_style_property (widget_class,
295 g_param_spec_boxed ("toolbar-borders",
296 "Graphical toolbar borders",
297 "Size of graphical toolbar borders",
301 /* opera hack, install clip operation signal */
302 g_signal_new ("clipboard_operation",
303 G_OBJECT_CLASS_TYPE (object_class),
305 G_STRUCT_OFFSET (HildonWindowClass, clipboard_operation),
307 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1,
312 hildon_window_init (HildonWindow *self)
314 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
315 g_assert (priv != NULL);
317 priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
318 gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
320 priv->visible_toolbars = 0;
321 priv->is_topmost = FALSE;
322 priv->borders = NULL;
323 priv->toolbar_borders = NULL;
324 priv->escape_timeout = 0;
326 priv->fullscreen = FALSE;
328 priv->program = NULL;
330 /* We need to track the root window _MB_CURRENT_APP_WINDOW property */
331 gdk_window_set_events (gdk_get_default_root_window (),
332 gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK);
334 gdk_window_add_filter (gdk_get_default_root_window (),
335 hildon_window_root_window_event_filter, self);
339 hildon_window_finalize (GObject * obj_self)
342 HildonWindowPrivate *priv;
344 g_return_if_fail (HILDON_WINDOW (obj_self));
346 priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
347 g_assert (priv != NULL);
349 self = HILDON_WINDOW (obj_self);
351 if (priv->escape_timeout) {
352 g_source_remove (priv->escape_timeout);
353 priv->escape_timeout = 0;
357 gtk_border_free (priv->borders);
359 if (priv->toolbar_borders)
360 gtk_border_free (priv->toolbar_borders);
362 if (G_OBJECT_CLASS (hildon_window_parent_class)->finalize)
363 G_OBJECT_CLASS (hildon_window_parent_class)->finalize (obj_self);
368 hildon_window_realize (GtkWidget *widget)
370 Atom *old_atoms, *new_atoms;
374 Window active_window;
375 HildonWindowPrivate *priv;
377 GTK_WIDGET_CLASS (hildon_window_parent_class)->realize (widget);
379 priv = HILDON_WINDOW_GET_PRIVATE (widget);
380 g_assert (priv != NULL);
382 gtk_widget_realize (GTK_WIDGET (priv->vbox));
384 /* catch the custom button signal from mb to display the menu */
385 gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
387 window = GDK_WINDOW_XID (widget->window);
388 disp = GDK_WINDOW_XDISPLAY (widget->window);
390 /* Enable custom button that is used for menu */
391 XGetWMProtocols (disp, window, &old_atoms, &atom_count);
392 new_atoms = g_new (Atom, atom_count + 1);
394 memcpy (new_atoms, old_atoms, sizeof(Atom) * atom_count);
396 new_atoms[atom_count++] =
397 XInternAtom (disp, "_NET_WM_CONTEXT_CUSTOM", False);
399 XSetWMProtocols (disp, window, new_atoms, atom_count);
404 /* rely on GDK to set the window group to its default */
405 gdk_window_set_group (widget->window, NULL);
408 gboolean can_hibernate = hildon_program_get_can_hibernate (priv->program);
410 hildon_window_set_can_hibernate_property (HILDON_WINDOW (widget),
414 /* Update the topmost status */
415 active_window = hildon_window_get_active_window();
416 hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
418 /* Update the window title */
419 hildon_window_update_title(HILDON_WINDOW (widget));
423 hildon_window_unrealize (GtkWidget *widget)
425 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
426 g_assert (priv != NULL);
428 gdk_window_remove_filter (widget->window, hildon_window_event_filter,
431 gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
432 GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
436 hildon_window_map (GtkWidget *widget)
438 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
439 g_assert (priv != NULL);
441 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->map)
442 GTK_WIDGET_CLASS (hildon_window_parent_class)->map (widget);
444 if (GTK_WIDGET_VISIBLE (priv->vbox))
445 gtk_widget_map (priv->vbox);
449 hildon_window_unmap (GtkWidget *widget)
451 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
452 g_assert (priv != NULL);
454 gtk_widget_unmap (priv->vbox);
456 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
457 GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
461 hildon_window_get_property (GObject *object,
466 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (object);
467 g_assert (priv != NULL);
469 switch (property_id) {
471 case PROP_IS_TOPMOST:
472 g_value_set_boolean (value, priv->is_topmost);
476 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
482 * Retrieve the graphical borders size used by the themes
485 hildon_window_get_borders (HildonWindow *window)
487 GtkBorder zero = {0, 0, 0, 0};
488 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
491 GtkBorder *borders = NULL;
492 GtkBorder *toolbar_borders = NULL;
495 gtk_border_free (priv->borders);
496 if (priv->toolbar_borders)
497 gtk_border_free (priv->toolbar_borders);
499 priv->borders = NULL;
500 priv->toolbar_borders = NULL;
502 gtk_widget_style_get (GTK_WIDGET (window), "borders",&borders,
503 "toolbar-borders", &toolbar_borders,
506 // We're doing a copy here instead of reusing the pointer,
507 // as we don't know where it comes from (has it been allocated using
508 // malloc or slices... and we want to free it sanely. Blowing on
512 priv->borders = gtk_border_copy (borders);
513 gtk_border_free (borders);
515 priv->borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
517 if (toolbar_borders) {
518 priv->toolbar_borders = gtk_border_copy (toolbar_borders);
519 gtk_border_free (toolbar_borders);
521 priv->toolbar_borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
525 hildon_window_expose (GtkWidget *widget,
526 GdkEventExpose * event)
528 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
531 GtkWidget *bx = priv->vbox;
532 GtkBox *box = GTK_BOX(bx);
533 GtkBorder *b = priv->borders;
534 GtkBorder *tb = priv->toolbar_borders;
537 if (! priv->borders) {
538 hildon_window_get_borders (HILDON_WINDOW (widget));
540 tb = priv->toolbar_borders;
543 tb_height = bx->allocation.height + tb->top + tb->bottom;
545 paint_toolbar (widget, box,
546 event, priv->fullscreen);
548 if (! priv->fullscreen) {
550 /* Draw the left and right window border */
551 gint side_borders_height = widget->allocation.height - b->top;
553 if (priv->visible_toolbars)
554 side_borders_height -= tb_height;
556 side_borders_height -= b->bottom;
560 gtk_paint_box (widget->style, widget->window,
561 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
562 &event->area, widget, "left-border",
563 widget->allocation.x, widget->allocation.y +
564 b->top, b->left, side_borders_height);
569 gtk_paint_box (widget->style, widget->window,
570 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
571 &event->area, widget, "right-border",
572 widget->allocation.x + widget->allocation.width -
573 b->right, widget->allocation.y + b->top,
574 b->right, side_borders_height);
577 /* If no toolbar, draw the bottom window border */
578 if (! priv->visible_toolbars && b->bottom > 0)
580 gtk_paint_box (widget->style, widget->window,
581 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
582 &event->area, widget, "bottom-border",
583 widget->allocation.x, widget->allocation.y +
584 (widget->allocation.height - b->bottom),
585 widget->allocation.width, b->bottom);
588 /* Draw the top border */
591 gtk_paint_box (widget->style, widget->window,
592 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
593 &event->area, widget, "top-border",
594 widget->allocation.x, widget->allocation.y,
595 widget->allocation.width, b->top);
601 /* don't draw the window stuff as it overwrites our borders with a blank
602 * rectangle. Instead start with the drawing of the GtkBin */
603 GTK_WIDGET_CLASS (g_type_class_peek_parent (hildon_window_parent_class))->expose_event (widget, event);
605 /* FIXME Not sure why this is commented out
606 * GTK_WIDGET_CLASS (hildon_window_parent_class))->
607 * expose_event (widget, event);
614 hildon_window_size_request (GtkWidget *widget,
615 GtkRequisition *requisition)
617 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
620 GtkWidget *child = GTK_BIN (widget)->child;
622 gint border_width = GTK_CONTAINER(widget)->border_width;
626 hildon_window_get_borders (HILDON_WINDOW (widget));
630 gtk_widget_size_request (child, requisition);
632 if (priv->vbox != NULL)
633 gtk_widget_size_request (priv->vbox, &req2);
635 requisition->height += req2.height;
636 requisition->width = (requisition->width < req2.width) ?
637 req2.width : requisition->width;
639 requisition->width += 2 * border_width;
640 requisition->height += 2 * border_width;
642 if (! priv->fullscreen)
644 requisition->height += priv->borders->top;
645 if (req2.height == 0)
646 requisition->height += priv->borders->bottom;
647 requisition->width += priv->borders->left + priv->borders->right;
652 hildon_window_size_allocate (GtkWidget *widget,
653 GtkAllocation *allocation)
655 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
658 GtkAllocation box_alloc;
659 GtkAllocation alloc = *allocation;
661 gint border_width = GTK_CONTAINER(widget)->border_width;
663 GtkWidget *box = priv->vbox;
664 GtkBin *bin = GTK_BIN(widget);
665 GtkBorder *b = priv->borders;
666 GtkBorder *tb = priv->toolbar_borders;
670 hildon_window_get_borders (HILDON_WINDOW (widget));
672 tb = priv->toolbar_borders;
675 widget->allocation = *allocation;
677 gtk_widget_get_child_requisition (box, &req);
679 box_alloc.width = allocation->width - tb->left - tb->right;
680 box_alloc.height = ( (req.height < allocation->height) ?
681 req.height : allocation->height );
682 box_alloc.x = allocation->x + tb->left;
683 box_alloc.y = allocation->y + allocation->height - box_alloc.height - tb->bottom;
685 if (bin->child != NULL && GTK_IS_WIDGET (bin->child)
686 && GTK_WIDGET_VISIBLE (bin->child))
688 alloc.x += border_width;
689 alloc.y += border_width;
690 alloc.width -= (border_width * 2);
691 alloc.height -= (border_width * 2) + box_alloc.height;
693 if (! priv->fullscreen)
696 alloc.width -= (b->left + b->right);
699 alloc.height -= b->top;
701 if (box_alloc.height <= 0)
702 alloc.height -= b->bottom;
704 alloc.height -= (tb->top + tb->bottom);
708 if (!(box_alloc.height <= 0))
709 alloc.height -= (tb->top + tb->bottom);
712 gtk_widget_size_allocate (bin->child, &alloc);
715 gtk_widget_size_allocate (box, &box_alloc);
717 if (priv->previous_vbox_y != box_alloc.y)
719 /* The size of the VBox has changed, we need to redraw part
720 * of the window borders */
721 gint draw_from_y = priv->previous_vbox_y < box_alloc.y?
722 priv->previous_vbox_y - tb->top:
723 box_alloc.y - tb->top;
725 gtk_widget_queue_draw_area (widget, 0, draw_from_y,
726 widget->allocation.width,
727 widget->allocation.height - draw_from_y);
729 priv->previous_vbox_y = box_alloc.y;
735 hildon_window_forall (GtkContainer *container,
736 gboolean include_internals,
737 GtkCallback callback,
738 gpointer callback_data)
740 HildonWindow *self = HILDON_WINDOW (container);
741 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
743 g_return_if_fail (callback != NULL);
746 GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
747 callback, callback_data);
748 if (include_internals && priv->vbox != NULL)
749 (* callback)(GTK_WIDGET (priv->vbox), callback_data);
753 hildon_window_show_all (GtkWidget *widget)
755 HildonWindow *self = HILDON_WINDOW (widget);
756 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
758 g_assert (priv != NULL);
760 GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
761 gtk_widget_show_all (priv->vbox);
765 hildon_window_destroy (GtkObject *obj)
767 HildonWindow *self = HILDON_WINDOW (obj);
768 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (obj);
769 GList *menu_list = NULL;
770 GList *menu_node = NULL;
772 g_assert (priv != NULL);
774 if (priv->vbox != NULL)
778 GtkWidget * common_toolbar =
779 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
780 if (common_toolbar && common_toolbar->parent == priv->vbox)
782 gtk_container_remove (GTK_CONTAINER (priv->vbox),
787 gtk_widget_unparent (priv->vbox);
792 menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
793 menu_node = menu_list;
797 if (GTK_IS_MENU (menu_node->data))
799 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_node->data)))
801 gtk_menu_popdown (GTK_MENU (menu_node->data));
802 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_node->data));
804 gtk_menu_detach (GTK_MENU (menu_node->data));
806 /* Destroy it, but only if it's not a common menu */
808 hildon_program_get_common_menu (priv->program) != menu_node->data) {
809 gtk_object_destroy (GTK_OBJECT (menu_node->data));
810 g_object_unref (menu_node->data);
813 menu_node = menu_node->next;
816 g_list_free (menu_list);
821 hildon_program_remove_window (priv->program, self);
824 gdk_window_remove_filter (gdk_get_default_root_window(),
825 hildon_window_root_window_event_filter,
828 gtk_widget_set_events (GTK_WIDGET(obj), 0);
830 GTK_OBJECT_CLASS (hildon_window_parent_class)->destroy (obj);
834 hildon_window_notify (GObject *gobject,
837 HildonWindow *window = HILDON_WINDOW (gobject);
839 if (g_str_equal (param->name, "title"))
842 hildon_window_update_title (window);
844 else if (g_str_equal (param->name, "is-topmost"))
846 hildon_window_is_topmost_notify (window);
849 if (G_OBJECT_CLASS(hildon_window_parent_class)->notify)
850 G_OBJECT_CLASS(hildon_window_parent_class)->notify (gobject, param);
855 visible_toolbar (gpointer data,
858 if (GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
859 (*((gint *)user_data))++;
863 find_findtoolbar_index (gpointer data,
866 gint *pass_bundle = (gint *)user_data;
868 if(((GtkBoxChild *)data)->widget->allocation.y < pass_bundle[0]
869 && GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
874 find_findtoolbar (gpointer data,
877 if(HILDON_IS_FIND_TOOLBAR (((GtkBoxChild *)data)->widget)
878 && GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
879 (*((GtkWidget **)user_data)) = ((GtkBoxChild *)data)->widget;
883 paint_toolbar (GtkWidget *widget,
885 GdkEventExpose * event,
888 gint toolbar_num = 0;
891 GtkWidget *findtoolbar = NULL;
892 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
893 gchar toolbar_mode[40];
894 GtkBorder *tb = priv->toolbar_borders;
896 g_assert (priv != NULL);
898 /* collect info to help on painting the boxes */
899 g_list_foreach (box->children, visible_toolbar,
900 (gpointer) &toolbar_num);
905 g_list_foreach (box->children, find_findtoolbar, (gpointer) &findtoolbar);
907 if (findtoolbar != NULL)
909 gint pass_bundle[2];/* an array for convient data passing
910 the first member contains the y allocation
911 of the find toolbar, and the second allocation
912 contains the index(how many toolbars are above
914 pass_bundle[0] = findtoolbar->allocation.y;
915 pass_bundle[1] = ftb_index;
916 g_list_foreach(box->children, find_findtoolbar_index,
917 (gpointer) pass_bundle);
918 ftb_index = pass_bundle[1];
922 sprintf (toolbar_mode, "toolbar%sframe-top",
923 fullscreen ? "-fullscreen-" : "-");
924 gtk_paint_box (widget->style, widget->window,
925 GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
926 &event->area, widget, toolbar_mode,
927 widget->allocation.x,
928 GTK_WIDGET (box)->allocation.y - tb->top,
929 widget->allocation.width, tb->top);
931 /*top most toolbar painting*/
932 if (findtoolbar != NULL && ftb_index == 0 )
934 sprintf (toolbar_mode, "findtoolbar%s",
935 fullscreen ? "-fullscreen" : "");
937 gtk_paint_box (widget->style, widget->window,
938 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
939 &event->area, widget, toolbar_mode,
940 widget->allocation.x,
941 GTK_WIDGET(box)->allocation.y,
942 widget->allocation.width,
947 sprintf (toolbar_mode, "toolbar%s",
948 fullscreen ? "-fullscreen" : "");
950 gtk_paint_box (widget->style, widget->window,
951 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
952 &event->area, widget, toolbar_mode,
953 widget->allocation.x,
954 GTK_WIDGET(box)->allocation.y,
955 widget->allocation.width,
958 /*multi toolbar painting*/
959 for (count = 0; count < toolbar_num - 1; count++)
961 sprintf (toolbar_mode, "toolbar%sframe-middle",
962 fullscreen ? "-fullscreen-" : "-");
964 gtk_paint_box (widget->style, widget->window,
965 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
966 &event->area, widget, toolbar_mode,
967 widget->allocation.x,
968 GTK_WIDGET(box)->allocation.y +
969 (1 + count) * TOOLBAR_HEIGHT +
970 count * TOOLBAR_MIDDLE,
971 widget->allocation.width,
974 if (findtoolbar != NULL && count + 1 == ftb_index)
977 sprintf (toolbar_mode, "findtoolbar%s",
978 fullscreen ? "-fullscreen" : "");
980 gtk_paint_box (widget->style, widget->window,
981 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
982 &event->area, widget, toolbar_mode,
983 widget->allocation.x,
984 GTK_WIDGET(box)->allocation.y +
985 (1 + count) * (TOOLBAR_HEIGHT + TOOLBAR_MIDDLE),
986 widget->allocation.width,
991 sprintf (toolbar_mode, "toolbar%s",
992 fullscreen ? "-fullscreen" : "");
994 gtk_paint_box (widget->style, widget->window,
995 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
996 &event->area, widget, toolbar_mode,
997 widget->allocation.x,
998 GTK_WIDGET(box)->allocation.y +
999 (1 + count) * (TOOLBAR_HEIGHT + TOOLBAR_MIDDLE),
1000 widget->allocation.width,
1004 sprintf (toolbar_mode, "toolbar%sframe-bottom",
1005 fullscreen ? "-fullscreen-" : "-");
1007 gtk_paint_box (widget->style, widget->window,
1008 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
1009 &event->area, widget, toolbar_mode,
1010 widget->allocation.x,
1011 GTK_WIDGET(box)->allocation.y +
1012 GTK_WIDGET(box)->allocation.height,
1013 widget->allocation.width, tb->bottom);
1017 * Checks the root window to know which is the topped window
1020 hildon_window_get_active_window (void)
1028 unsigned long extra;
1032 unsigned char *char_pointer;
1034 Atom active_app_atom =
1035 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1039 gdk_error_trap_push ();
1040 status = XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1041 active_app_atom, 0L, 16L,
1042 0, XA_WINDOW, &realtype, &format,
1043 &n, &extra, &win.char_pointer);
1044 xerror = gdk_error_trap_pop ();
1045 if (xerror || !(status == Success && realtype == XA_WINDOW && format == 32
1046 && n == 1 && win.win != NULL))
1048 if (win.win != NULL)
1049 XFree (win.char_pointer);
1055 if (win.win != NULL)
1056 XFree(win.char_pointer);
1062 xclient_message_type_check (XClientMessageEvent *cm,
1065 return cm->message_type == XInternAtom(GDK_DISPLAY(), name, FALSE);
1069 * Handle the window border custom button, which toggles the menu,
1070 * and the Hildon input method copy paste messages
1072 static GdkFilterReturn
1073 hildon_window_event_filter (GdkXEvent *xevent,
1077 XAnyEvent *eventti = xevent;
1079 if (eventti->type == ClientMessage)
1081 XClientMessageEvent *cm = xevent;
1083 if (xclient_message_type_check (cm, "_MB_GRAB_TRANSFER"))
1085 hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]);
1086 return GDK_FILTER_REMOVE;
1088 /* opera hack clipboard client message */
1089 else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY"))
1091 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1092 HILDON_WINDOW_CO_COPY);
1093 return GDK_FILTER_REMOVE;
1095 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT"))
1097 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1098 HILDON_WINDOW_CO_CUT);
1099 return GDK_FILTER_REMOVE;
1101 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE"))
1103 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1104 HILDON_WINDOW_CO_PASTE);
1105 return GDK_FILTER_REMOVE;
1109 return GDK_FILTER_CONTINUE;
1113 * Here we keep track of changes in the _MB_CURRENT_APP_WINDOW,
1114 * to know when we acquire/lose topmost status
1116 static GdkFilterReturn
1117 hildon_window_root_window_event_filter (GdkXEvent *xevent,
1121 XAnyEvent *eventti = xevent;
1122 HildonWindow *hwindow = HILDON_WINDOW (data);
1124 if (eventti->type == PropertyNotify)
1126 XPropertyEvent *pevent = xevent;
1127 Atom active_app_atom =
1128 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1130 if (pevent->atom == active_app_atom)
1132 Window active_window = hildon_window_get_active_window();
1134 hildon_window_update_topmost (hwindow, active_window);
1138 return GDK_FILTER_CONTINUE;
1142 * Handle the menu hardware key here
1145 hildon_window_key_press_event (GtkWidget *widget,
1148 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1150 g_return_val_if_fail (HILDON_IS_WINDOW (widget),FALSE);
1153 switch (event->keyval)
1155 case HILDON_HARDKEY_MENU:
1156 if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME))
1159 case HILDON_HARDKEY_ESC:
1160 if (!priv->escape_timeout)
1162 priv->escape_timeout = g_timeout_add
1163 (HILDON_WINDOW_LONG_PRESS_TIME,
1164 hildon_window_escape_timeout, widget);
1169 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event);
1173 hildon_window_key_release_event (GtkWidget *widget,
1176 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1178 g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE);
1181 switch (event->keyval)
1183 case HILDON_HARDKEY_ESC:
1184 if (priv->escape_timeout)
1186 g_source_remove (priv->escape_timeout);
1187 priv->escape_timeout = 0;
1192 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event);
1197 * We keep track of the window state changes, because the drawing
1198 * (borders) differs whether we are in fullscreen mode or not
1201 hildon_window_window_state_event (GtkWidget *widget,
1202 GdkEventWindowState *event)
1204 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1205 g_assert (priv != NULL);
1207 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1208 priv->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1210 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event)
1212 return GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event (
1223 * If the window lost focus while the user started to press the ESC key, we
1224 * won't get the release event. We need to stop the timeout.
1227 hildon_window_focus_out_event (GtkWidget *widget,
1228 GdkEventFocus *event)
1230 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1232 if (priv->escape_timeout)
1234 g_source_remove (priv->escape_timeout);
1235 priv->escape_timeout = 0;
1238 return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event);
1242 * The menu popuping needs a menu popup-function
1245 hildon_window_menu_popup_func (GtkMenu *menu,
1253 GdkWindow *window = GTK_WIDGET(widget)->window;
1257 gdk_window_get_origin (window, &window_x, &window_y);
1260 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1261 "vertical-offset", y, NULL);
1263 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1265 *x = GTK_WIDGET (widget)->allocation.width + window_x - GTK_WIDGET (menu)->allocation.width - *x;
1275 hildon_window_menu_popup_func_full (GtkMenu *menu,
1281 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1282 "vertical-offset", y, NULL);
1284 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1285 *x = GTK_WIDGET (widget)->allocation.width - GTK_WIDGET (menu)->allocation.width - *x;
1294 * Takes the common toolbar when we acquire the top-most status
1297 hildon_window_is_topmost_notify (HildonWindow *window)
1299 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1303 if (priv->is_topmost)
1305 hildon_window_take_common_toolbar (window);
1310 * Sets the program to which the window belongs. This should only be called
1311 * by hildon_program_add_window
1313 void G_GNUC_INTERNAL
1314 hildon_window_set_program (HildonWindow *self,
1317 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1319 g_return_if_fail (HILDON_IS_WINDOW (self));
1320 g_assert (priv != NULL);
1324 g_object_unref (priv->program);
1327 /* Now that we are bound to a program, we can rely on it to track the
1329 gdk_window_remove_filter (gdk_get_default_root_window(),
1330 hildon_window_root_window_event_filter,
1333 priv->program = HILDON_PROGRAM (program);
1334 g_object_ref (program);
1338 * Unsets the program to which the window belongs. This should only be called
1339 * by hildon_program_remove_window
1341 void G_GNUC_INTERNAL
1342 hildon_window_unset_program (HildonWindow *self)
1344 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1346 g_return_if_fail(HILDON_IS_WINDOW (self));
1347 g_assert (priv != NULL);
1351 g_object_unref (priv->program);
1352 priv->program = NULL;
1354 /* We need to start tacking the root window again */
1355 gdk_window_set_events (gdk_get_default_root_window (),
1356 gdk_window_get_events (gdk_get_default_root_window ())
1357 | GDK_PROPERTY_CHANGE_MASK);
1359 gdk_window_add_filter (gdk_get_default_root_window (),
1360 hildon_window_root_window_event_filter, self );
1363 priv->program = NULL;
1367 * Sets whether or not the program to which this window belongs is
1368 * killable. This is used by the HildonProgram to signify to the
1369 * Task Navigator whether or not it can hibernate in memory-low situations
1371 void G_GNUC_INTERNAL
1372 hildon_window_set_can_hibernate_property (HildonWindow *self,
1373 gpointer _can_hibernate)
1375 GdkAtom killable_atom;
1376 gboolean can_hibernate;
1378 g_return_if_fail(self && HILDON_IS_WINDOW (self));
1380 if (!GTK_WIDGET_REALIZED ((GTK_WIDGET (self))))
1385 can_hibernate = * ((gboolean *)_can_hibernate);
1387 killable_atom = gdk_atom_intern (CAN_HIBERNATE_PROPERTY, FALSE);
1391 gdk_property_change (GTK_WIDGET (self)->window, killable_atom,
1392 (GdkAtom)31/* XA_STRING */, 8,
1393 GDK_PROP_MODE_REPLACE, (const guchar *)CAN_HIBERNATE,
1394 CAN_HIBERNATE_LENGTH);
1398 gdk_property_delete (GTK_WIDGET (self)->window, killable_atom);
1404 * If a common toolbar was set to the program, reparent it to
1407 void G_GNUC_INTERNAL
1408 hildon_window_take_common_toolbar (HildonWindow *self)
1410 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1412 g_return_if_fail(HILDON_IS_WINDOW (self));
1417 GtkWidget *common_toolbar =
1418 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
1420 if (common_toolbar && common_toolbar->parent != priv->vbox)
1422 g_object_ref (common_toolbar);
1423 if (common_toolbar->parent)
1425 gtk_container_remove (GTK_CONTAINER (common_toolbar->parent),
1429 gtk_box_pack_end (GTK_BOX(priv->vbox), common_toolbar,
1431 g_object_unref (common_toolbar);
1433 gtk_widget_set_size_request (common_toolbar, -1, TOOLBAR_HEIGHT);
1435 gtk_widget_show (priv->vbox);
1442 * Compare the window that was last topped, and act consequently
1445 hildon_window_update_topmost (HildonWindow *self,
1448 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1452 g_return_if_fail (HILDON_IS_WINDOW (self));
1455 my_window = GDK_WINDOW_XID (GTK_WIDGET (self)->window);
1457 if (window_id == my_window)
1459 if (! priv->is_topmost)
1461 priv->is_topmost = TRUE;
1462 hildon_window_is_topmost_notify (self);
1463 g_object_notify (G_OBJECT (self), "is-topmost");
1466 else if (priv->is_topmost)
1468 /* Should this go in the signal handler? */
1469 GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (self));
1471 if (GTK_IS_ENTRY (focus))
1472 gtk_im_context_focus_out (GTK_ENTRY (focus)->im_context);
1473 if (GTK_IS_TEXT_VIEW (focus))
1474 gtk_im_context_focus_out (GTK_TEXT_VIEW (focus)->im_context);
1476 priv->is_topmost = FALSE;
1477 hildon_window_is_topmost_notify (self);
1478 g_object_notify (G_OBJECT (self), "is-topmost");
1483 * If the application
1484 * was given a name (with g_set_application_name(), set
1485 * "ProgramName - WindowTitle" as the displayed
1488 void G_GNUC_INTERNAL
1489 hildon_window_update_title (HildonWindow *window)
1491 const gchar * application_name;
1493 g_return_if_fail (HILDON_IS_WINDOW (window));
1495 if (!GTK_WIDGET_REALIZED (window))
1500 application_name = g_get_application_name ();
1502 if (application_name && application_name[0])
1504 const gchar *old_title = gtk_window_get_title (GTK_WINDOW (window));
1508 gchar *title = NULL;
1510 if (strlen (old_title) == 0)
1511 title = g_strdup (application_name);
1513 title = g_strjoin (TITLE_SEPARATOR, application_name,
1516 gdk_window_set_title (GTK_WIDGET (window)->window, title);
1525 detach_menu_func (GtkWidget *attach_widget,
1528 /* FIXME Why is this even needed here? */
1532 hildon_window_toggle_menu (HildonWindow *self,
1536 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1538 if (HILDON_WINDOW_GET_CLASS (self)->toggle_menu != NULL)
1540 return HILDON_WINDOW_GET_CLASS (self)->toggle_menu (self, button, time);
1550 * Toggles the display of the HildonWindow menu.
1551 * Returns whether or not something was done (whether or not we had a menu
1555 hildon_window_toggle_menu_real (HildonWindow * self,
1559 GtkMenu *menu_to_use = NULL;
1560 GList *menu_children = NULL;
1561 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1563 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1564 g_assert (priv != NULL);
1566 /* Select which menu to use, Window specific has highest priority,
1567 * then program specific */
1570 menu_to_use = GTK_MENU (priv->menu);
1572 else if (priv->program)
1574 menu_to_use = hildon_program_get_common_menu (priv->program);
1575 if (menu_to_use && gtk_menu_get_attach_widget (menu_to_use) !=
1578 g_object_ref (menu_to_use);
1579 if (gtk_menu_get_attach_widget (menu_to_use))
1581 gtk_menu_detach (menu_to_use);
1584 gtk_menu_attach_to_widget (menu_to_use, GTK_WIDGET (self),
1586 g_object_unref (menu_to_use);
1596 if (GTK_WIDGET_MAPPED (GTK_WIDGET (menu_to_use)))
1598 gtk_menu_popdown (menu_to_use);
1599 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_to_use));
1603 /* Check if the menu has items */
1604 menu_children = gtk_container_get_children (GTK_CONTAINER (menu_to_use));
1608 g_list_free (menu_children);
1610 /* Apply right theming */
1611 gtk_widget_set_name (GTK_WIDGET (menu_to_use),
1612 "menu_force_with_corners");
1614 if (priv->fullscreen)
1616 gtk_menu_popup (menu_to_use, NULL, NULL,
1617 (GtkMenuPositionFunc)
1618 hildon_window_menu_popup_func_full,
1619 self, button, time);
1623 gtk_menu_popup (menu_to_use, NULL, NULL,
1624 (GtkMenuPositionFunc)
1625 hildon_window_menu_popup_func,
1626 self, button, time);
1628 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_to_use), TRUE);
1636 * If the ESC key was not released when the timeout expires,
1640 hildon_window_escape_timeout (gpointer data)
1642 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data);
1647 GDK_THREADS_ENTER ();
1649 /* Send fake event, simulation a situation that user
1650 pressed 'x' from the corner */
1651 event = gdk_event_new(GDK_DELETE);
1652 ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window));
1653 gtk_main_do_event(event);
1655 /* That unrefs the window, so we're reffing it above */
1656 gdk_event_free(event);
1658 priv->escape_timeout = 0;
1660 GDK_THREADS_LEAVE ();
1666 * hildon_window_new:
1668 * Creates a new HildonWindow.
1670 * Return value: A @HildonWindow.
1673 hildon_window_new (void)
1675 HildonWindow *newwindow = g_object_new (HILDON_TYPE_WINDOW, NULL);
1677 return GTK_WIDGET (newwindow);
1681 * hildon_window_add_with_scrollbar
1682 * @self : A @HildonWindow
1683 * @child : A @GtkWidget
1685 * Adds the @child to the HildonWindow and creates a scrollbar
1686 * for it. Similar as adding first a @GtkScrolledWindow and then the
1690 hildon_window_add_with_scrollbar (HildonWindow *self,
1693 GtkScrolledWindow *scrolledw;
1695 g_return_if_fail (HILDON_IS_WINDOW (self));
1696 g_return_if_fail (GTK_IS_WIDGET (child));
1697 g_return_if_fail (child->parent == NULL);
1699 scrolledw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1700 gtk_scrolled_window_set_policy (scrolledw, GTK_POLICY_NEVER,
1701 GTK_POLICY_AUTOMATIC);
1702 gtk_scrolled_window_set_shadow_type (scrolledw, GTK_SHADOW_NONE);
1704 if (GTK_IS_VIEWPORT (child))
1705 gtk_container_add (GTK_CONTAINER (scrolledw), child);
1708 if (GTK_IS_CONTAINER (child) )
1709 gtk_container_set_focus_vadjustment (GTK_CONTAINER(child),
1710 gtk_scrolled_window_get_vadjustment (scrolledw) );
1711 gtk_scrolled_window_add_with_viewport (scrolledw, child);
1714 gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (scrolledw));
1718 calculate_visible_toolbars (gpointer data,
1721 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (((GtkBoxChild *)data)->widget)))
1722 (*((gint *)user_data)) ++;
1726 toolbar_visible_notify (GtkWidget *toolbar, GParamSpec *pspec,
1727 HildonWindow *window)
1729 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1733 /* Recalculate from scratch the value just in case */
1734 priv->visible_toolbars = 0;
1736 g_list_foreach (GTK_BOX (priv->vbox)->children, calculate_visible_toolbars,
1737 &priv->visible_toolbars);
1739 if (priv->visible_toolbars == 0)
1740 gtk_widget_hide (priv->vbox);
1742 gtk_widget_show (priv->vbox);
1746 * hildon_window_add_toolbar:
1747 * @self: A @HildonWindow
1748 * @toolbar: A #GtkToolbar to add to the HildonWindow
1750 * Adds a toolbar to the window. Note that the toolbar is not automatically
1751 * shown. You need to call #gtk_widget_show_all on it to make it visible.
1752 * It's also possible to hide the toolbar (without removing it) by calling
1756 hildon_window_add_toolbar (HildonWindow *self,
1757 GtkToolbar *toolbar)
1760 HildonWindowPrivate *priv;
1762 g_return_if_fail (HILDON_IS_WINDOW (self));
1763 g_return_if_fail (toolbar && GTK_IS_TOOLBAR (toolbar));
1765 priv = HILDON_WINDOW_GET_PRIVATE (self);
1767 vbox = GTK_BOX (priv->vbox);
1769 gtk_box_pack_start (vbox, GTK_WIDGET (toolbar), TRUE, TRUE, 0);
1770 gtk_box_reorder_child (vbox, GTK_WIDGET (toolbar), 0);
1771 gtk_widget_set_size_request (GTK_WIDGET (toolbar), -1, TOOLBAR_HEIGHT);
1773 g_signal_connect (G_OBJECT (toolbar), "notify::visible",
1774 G_CALLBACK (toolbar_visible_notify), self);
1776 if (GTK_WIDGET_VISIBLE (toolbar))
1778 priv->visible_toolbars++;
1779 gtk_widget_show (priv->vbox);
1782 gtk_widget_queue_resize (GTK_WIDGET (self));
1786 * hildon_window_remove_toolbar:
1787 * @self: A @HildonWindow
1788 * @toolbar: A #GtkToolbar to remove from the HildonWindow
1790 * Removes a toolbar from the window. Note that this decreases the refference
1791 * count on the widget. If you want to keep the toolbar alive call #g_object_ref
1792 * before calling this function.
1795 hildon_window_remove_toolbar (HildonWindow *self,
1796 GtkToolbar *toolbar)
1798 HildonWindowPrivate *priv;
1800 g_return_if_fail (HILDON_IS_WINDOW (self));
1802 priv = HILDON_WINDOW_GET_PRIVATE (self);
1804 if (GTK_WIDGET_VISIBLE (toolbar))
1806 if (--(priv->visible_toolbars) == 0)
1807 gtk_widget_hide (priv->vbox);
1810 g_signal_handlers_disconnect_by_func (toolbar, toolbar_visible_notify, self);
1812 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (toolbar));
1816 * hildon_window_get_menu:
1817 * @self : #HildonWindow
1819 * Gets the #GtMenu assigned to the #HildonAppview. Note that the
1820 * window is still the owner of the menu.
1822 * Return value: The #GtkMenu assigned to this application view.
1825 hildon_window_get_menu (HildonWindow * self)
1827 HildonWindowPrivate *priv;
1829 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
1831 priv = HILDON_WINDOW_GET_PRIVATE (self);
1833 return GTK_MENU (priv->menu);
1836 /* Since we've been asking developers to call gtk_window_add_accel_group()
1837 * themselves, do not trigger criticals by trying it again.
1840 hildon_window_add_accel_group (HildonWindow *self,
1841 GtkAccelGroup *accel_group)
1845 groups = gtk_accel_groups_from_object (G_OBJECT (self));
1846 for (l = groups; l != NULL; l = l->next)
1847 if (l->data == (gpointer)accel_group)
1848 /* Maybe print a warning here? */
1851 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
1855 * hildon_window_set_main_menu:
1856 * @self: A #HildonWindow
1857 * @menu: The #GtkMenu to be used for this #HildonWindow
1859 * Sets the menu to be used for this window. This menu overrides
1860 * a program-wide menu that may have been set with
1861 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1862 * menu. #HildonWindow takes ownership of the passed menu and you're
1863 * not supposed to free it yourself anymore.
1865 * Note that if you're using a #HildonStackableWindow (and not just a
1866 * standard #HildonWindow) you should use
1867 * hildon_stackable_window_set_main_menu()
1868 * instead. #HildonStackableWindow uses #HildonAppMenu rather than
1874 hildon_window_set_main_menu (HildonWindow* self,
1877 HildonWindowPrivate *priv;
1878 GtkAccelGroup *accel_group;
1880 g_return_if_fail (HILDON_IS_WINDOW (self));
1882 priv = HILDON_WINDOW_GET_PRIVATE (self);
1884 if (priv->menu != NULL)
1886 accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
1887 if (accel_group != NULL)
1888 gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
1890 gtk_menu_detach (GTK_MENU (priv->menu));
1891 g_object_unref (priv->menu);
1894 priv->menu = (menu != NULL) ? GTK_WIDGET (menu) : NULL;
1895 if (priv->menu != NULL)
1897 gtk_widget_set_name (priv->menu, "menu_force_with_corners");
1898 gtk_menu_attach_to_widget (GTK_MENU (priv->menu), GTK_WIDGET (self), &detach_menu_func);
1899 g_object_ref (GTK_MENU (priv->menu));
1901 accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
1902 if (accel_group != NULL)
1903 hildon_window_add_accel_group (self, accel_group);
1908 * hildon_window_set_menu:
1909 * @self: A #HildonWindow
1910 * @menu: The #GtkMenu to be used for this #HildonWindow
1912 * Sets the menu to be used for this window. This menu overrides
1913 * a program-wide menu that may have been set with
1914 * hildon_program_set_common_menu. Pass NULL to remove the current
1915 * menu. HildonWindow takes ownership of the passed menu and you're
1916 * not supposed to free it yourself anymore.
1918 * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the
1919 * #GtkMenu. To pass control about visibility to the application
1920 * developer, hildon_window_set_main_menu() was introduced, which
1923 * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
1926 hildon_window_set_menu (HildonWindow *self,
1929 HildonWindowPrivate *priv;
1931 g_return_if_fail (HILDON_IS_WINDOW (self));
1933 hildon_window_set_main_menu (self, menu);
1935 priv = HILDON_WINDOW_GET_PRIVATE (self);
1937 if (priv->menu != NULL)
1938 gtk_widget_show_all (GTK_WIDGET (priv->menu));
1942 * hildon_window_get_is_topmost:
1943 * @self: A #HildonWindow
1945 * Return value: Whether or not the #HildonWindow is currenltly activated
1946 * by the window manager.
1949 hildon_window_get_is_topmost (HildonWindow *self)
1951 HildonWindowPrivate *priv;
1953 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1955 priv = HILDON_WINDOW_GET_PRIVATE (self);
1956 return priv->is_topmost;