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);
76 #include "hildon-window.h"
81 #include "hildon-program.h"
82 #include "hildon-window-private.h"
83 #include "hildon-find-toolbar.h"
85 #include <gtk/gtkmenu.h>
86 #include <gtk/gtkimcontext.h>
87 #include <gtk/gtkmenuitem.h>
88 #include <gtk/gtkcheckmenuitem.h>
89 #include <gtk/gtkmenushell.h>
90 #include <gtk/gtkwindow.h>
91 #include <gtk/gtkwidget.h>
92 #include <gtk/gtkvbox.h>
93 #include <gtk/gtklabel.h>
94 #include <gtk/gtkentry.h>
95 #include <gtk/gtktextview.h>
96 #include <gtk/gtkscrolledwindow.h>
97 #include <gtk/gtkmain.h>
98 #include <gdk/gdkkeysyms.h>
100 #include <gtk/gtkprivate.h>
102 #include <X11/Xlib.h>
103 #include <X11/Xatom.h>
106 #define _(String) gettext(String)
108 #define TOOLBAR_HEIGHT 40
110 #define TOOLBAR_MIDDLE 10
113 #define CAN_HIBERNATE "CANKILL"
115 #define CAN_HIBERNATE_LENGTH 7
117 #define CAN_HIBERNATE_PROPERTY "_HILDON_ABLE_TO_HIBERNATE"
119 #define TITLE_SEPARATOR " - "
121 typedef void (*HildonWindowSignal) (HildonWindow *, gint, gpointer);
124 hildon_window_init (HildonWindow * self);
127 hildon_window_class_init (HildonWindowClass * window_class);
130 hildon_window_menu_popup_func (GtkMenu *menu,
136 hildon_window_menu_popup_func_full (GtkMenu *menu,
142 hildon_window_expose (GtkWidget *widget,
143 GdkEventExpose *event);
145 hildon_window_forall (GtkContainer *container,
146 gboolean include_internals,
147 GtkCallback callback,
148 gpointer callback_data);
150 hildon_window_show_all (GtkWidget *widget);
153 hildon_window_size_allocate (GtkWidget * widget,
154 GtkAllocation *allocation);
156 hildon_window_size_request (GtkWidget * widget,
157 GtkRequisition *requisition);
159 hildon_window_finalize (GObject *obj_self);
162 hildon_window_get_property (GObject *object,
168 hildon_window_destroy (GtkObject *obj);
171 hildon_window_realize (GtkWidget *widget);
174 hildon_window_unrealize (GtkWidget *widget);
177 hildon_window_map (GtkWidget *widget);
180 hildon_window_unmap (GtkWidget *widget);
183 hildon_window_key_press_event (GtkWidget *widget,
187 hildon_window_key_release_event (GtkWidget *widget,
190 hildon_window_window_state_event (GtkWidget *widget,
191 GdkEventWindowState *event);
193 hildon_window_focus_out_event (GtkWidget *widget,
194 GdkEventFocus *event);
197 hildon_window_notify (GObject *gobject,
201 hildon_window_is_topmost_notify (HildonWindow *window);
204 hildon_window_toggle_menu (HildonWindow * self,
209 hildon_window_escape_timeout (gpointer data);
211 static GdkFilterReturn
212 hildon_window_event_filter (GdkXEvent *xevent,
216 static GdkFilterReturn
217 hildon_window_root_window_event_filter (GdkXEvent *xevent,
222 hildon_window_get_borders (HildonWindow *window);
225 visible_toolbar (gpointer data,
229 paint_toolbar (GtkWidget *widget,
231 GdkEventExpose * event,
232 gboolean fullscreen);
235 hildon_window_unset_program_real (HildonWindow *self);
250 G_DEFINE_TYPE (HildonWindow, hildon_window, GTK_TYPE_WINDOW);
253 hildon_window_class_init (HildonWindowClass * window_class)
255 /* Get convenience variables */
256 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (window_class);
257 GObjectClass *object_class = G_OBJECT_CLASS (window_class);
258 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (window_class);
260 object_class->get_property = hildon_window_get_property;
261 object_class->notify = hildon_window_notify;
262 widget_class->size_allocate = hildon_window_size_allocate;
263 widget_class->size_request = hildon_window_size_request;
264 widget_class->expose_event = hildon_window_expose;
265 widget_class->show_all = hildon_window_show_all;
266 widget_class->realize = hildon_window_realize;
267 widget_class->unrealize = hildon_window_unrealize;
268 widget_class->key_press_event = hildon_window_key_press_event;
269 widget_class->key_release_event = hildon_window_key_release_event;
270 widget_class->window_state_event = hildon_window_window_state_event;
271 widget_class->focus_out_event = hildon_window_focus_out_event;
272 widget_class->map = hildon_window_map;
273 widget_class->unmap = hildon_window_unmap;
275 /* now the object stuff */
276 object_class->finalize = hildon_window_finalize;
278 /* To the container */
279 container_class->forall = hildon_window_forall;
282 window_class->unset_program = hildon_window_unset_program_real;
285 GTK_OBJECT_CLASS (window_class)->destroy = hildon_window_destroy;
287 g_type_class_add_private (window_class,
288 sizeof (struct _HildonWindowPrivate));
290 /* Install properties */
293 * HildonWindow:is-topmost:
295 * Whether the window is currently activated by the window manager.
297 g_object_class_install_property (object_class, PROP_IS_TOPMOST,
298 g_param_spec_boolean ("is-topmost",
300 "Whether the window is currently activated by the window "
305 gtk_widget_class_install_style_property (widget_class,
306 g_param_spec_boxed ("borders",
308 "Size of graphical window borders",
312 gtk_widget_class_install_style_property (widget_class,
313 g_param_spec_boxed ("toolbar-borders",
314 "Graphical toolbar borders",
315 "Size of graphical toolbar borders",
319 /* opera hack, install clip operation signal */
320 g_signal_new ("clipboard_operation",
321 G_OBJECT_CLASS_TYPE (object_class),
323 G_STRUCT_OFFSET (HildonWindowClass, clipboard_operation),
325 g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1,
330 hildon_window_init (HildonWindow *self)
332 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
333 g_assert (priv != NULL);
335 priv->vbox = gtk_vbox_new (TRUE, TOOLBAR_MIDDLE);
336 gtk_widget_set_parent (priv->vbox, GTK_WIDGET(self));
338 priv->visible_toolbars = 0;
339 priv->is_topmost = FALSE;
340 priv->borders = NULL;
341 priv->toolbar_borders = NULL;
342 priv->escape_timeout = 0;
344 priv->fullscreen = FALSE;
346 priv->program = NULL;
348 /* We need to track the root window _MB_CURRENT_APP_WINDOW property */
349 gdk_window_set_events (gdk_get_default_root_window (),
350 gdk_window_get_events (gdk_get_default_root_window ()) | GDK_PROPERTY_CHANGE_MASK);
352 gdk_window_add_filter (gdk_get_default_root_window (),
353 hildon_window_root_window_event_filter, self);
357 hildon_window_finalize (GObject * obj_self)
360 HildonWindowPrivate *priv;
362 g_return_if_fail (HILDON_WINDOW (obj_self));
364 priv = HILDON_WINDOW_GET_PRIVATE (obj_self);
365 g_assert (priv != NULL);
367 self = HILDON_WINDOW (obj_self);
369 if (priv->escape_timeout) {
370 g_source_remove (priv->escape_timeout);
371 priv->escape_timeout = 0;
375 gtk_border_free (priv->borders);
377 if (priv->toolbar_borders)
378 gtk_border_free (priv->toolbar_borders);
380 if (G_OBJECT_CLASS (hildon_window_parent_class)->finalize)
381 G_OBJECT_CLASS (hildon_window_parent_class)->finalize (obj_self);
386 hildon_window_realize (GtkWidget *widget)
388 Atom *old_atoms, *new_atoms;
392 Window active_window;
393 HildonWindowPrivate *priv;
395 GTK_WIDGET_CLASS (hildon_window_parent_class)->realize (widget);
397 priv = HILDON_WINDOW_GET_PRIVATE (widget);
398 g_assert (priv != NULL);
400 gtk_widget_realize (GTK_WIDGET (priv->vbox));
402 /* catch the custom button signal from mb to display the menu */
403 gdk_window_add_filter (widget->window, hildon_window_event_filter, widget);
405 window = GDK_WINDOW_XID (widget->window);
406 disp = GDK_WINDOW_XDISPLAY (widget->window);
408 /* Enable custom button that is used for menu */
409 XGetWMProtocols (disp, window, &old_atoms, &atom_count);
410 new_atoms = g_new (Atom, atom_count + 1);
412 memcpy (new_atoms, old_atoms, sizeof(Atom) * atom_count);
414 new_atoms[atom_count++] =
415 XInternAtom (disp, "_NET_WM_CONTEXT_CUSTOM", False);
417 XSetWMProtocols (disp, window, new_atoms, atom_count);
422 /* rely on GDK to set the window group to its default */
423 gdk_window_set_group (widget->window, NULL);
426 gboolean can_hibernate = hildon_program_get_can_hibernate (priv->program);
428 hildon_window_set_can_hibernate_property (HILDON_WINDOW (widget),
432 /* Update the topmost status */
433 active_window = hildon_window_get_active_window();
434 hildon_window_update_topmost (HILDON_WINDOW (widget), active_window);
436 /* Update the window title */
437 hildon_window_update_title(HILDON_WINDOW (widget));
441 hildon_window_unrealize (GtkWidget *widget)
443 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
444 g_assert (priv != NULL);
446 gdk_window_remove_filter (widget->window, hildon_window_event_filter,
449 gtk_widget_unrealize (GTK_WIDGET (priv->vbox));
450 GTK_WIDGET_CLASS(hildon_window_parent_class)->unrealize(widget);
454 hildon_window_map (GtkWidget *widget)
456 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
457 g_assert (priv != NULL);
459 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->map)
460 GTK_WIDGET_CLASS (hildon_window_parent_class)->map (widget);
462 if (GTK_WIDGET_VISIBLE (priv->vbox))
463 gtk_widget_map (priv->vbox);
467 hildon_window_unmap (GtkWidget *widget)
469 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
470 g_assert (priv != NULL);
472 gtk_widget_unmap (priv->vbox);
474 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap)
475 GTK_WIDGET_CLASS (hildon_window_parent_class)->unmap (widget);
479 hildon_window_get_property (GObject *object,
484 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (object);
485 g_assert (priv != NULL);
487 switch (property_id) {
489 case PROP_IS_TOPMOST:
490 g_value_set_boolean (value, priv->is_topmost);
494 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
500 * Retrieve the graphical borders size used by the themes
503 hildon_window_get_borders (HildonWindow *window)
505 GtkBorder zero = {0, 0, 0, 0};
506 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
509 GtkBorder *borders = NULL;
510 GtkBorder *toolbar_borders = NULL;
513 gtk_border_free (priv->borders);
514 if (priv->toolbar_borders)
515 gtk_border_free (priv->toolbar_borders);
517 priv->borders = NULL;
518 priv->toolbar_borders = NULL;
520 gtk_widget_style_get (GTK_WIDGET (window), "borders",&borders,
521 "toolbar-borders", &toolbar_borders,
524 // We're doing a copy here instead of reusing the pointer,
525 // as we don't know where it comes from (has it been allocated using
526 // malloc or slices... and we want to free it sanely. Blowing on
530 priv->borders = gtk_border_copy (borders);
531 gtk_border_free (borders);
533 priv->borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
535 if (toolbar_borders) {
536 priv->toolbar_borders = gtk_border_copy (toolbar_borders);
537 gtk_border_free (toolbar_borders);
539 priv->toolbar_borders = g_boxed_copy (GTK_TYPE_BORDER, &zero);
543 hildon_window_expose (GtkWidget *widget,
544 GdkEventExpose * event)
546 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
549 GtkWidget *bx = priv->vbox;
550 GtkBox *box = GTK_BOX(bx);
551 GtkBorder *b = priv->borders;
552 GtkBorder *tb = priv->toolbar_borders;
555 if (! priv->borders) {
556 hildon_window_get_borders (HILDON_WINDOW (widget));
558 tb = priv->toolbar_borders;
561 tb_height = bx->allocation.height + tb->top + tb->bottom;
563 paint_toolbar (widget, box,
564 event, priv->fullscreen);
566 if (! priv->fullscreen) {
568 /* Draw the left and right window border */
569 gint side_borders_height = widget->allocation.height - b->top;
571 if (priv->visible_toolbars)
572 side_borders_height -= tb_height;
574 side_borders_height -= b->bottom;
578 gtk_paint_box (widget->style, widget->window,
579 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
580 &event->area, widget, "left-border",
581 widget->allocation.x, widget->allocation.y +
582 b->top, b->left, side_borders_height);
587 gtk_paint_box (widget->style, widget->window,
588 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
589 &event->area, widget, "right-border",
590 widget->allocation.x + widget->allocation.width -
591 b->right, widget->allocation.y + b->top,
592 b->right, side_borders_height);
595 /* If no toolbar, draw the bottom window border */
596 if (! priv->visible_toolbars && b->bottom > 0)
598 gtk_paint_box (widget->style, widget->window,
599 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
600 &event->area, widget, "bottom-border",
601 widget->allocation.x, widget->allocation.y +
602 (widget->allocation.height - b->bottom),
603 widget->allocation.width, b->bottom);
606 /* Draw the top border */
609 gtk_paint_box (widget->style, widget->window,
610 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
611 &event->area, widget, "top-border",
612 widget->allocation.x, widget->allocation.y,
613 widget->allocation.width, b->top);
619 /* don't draw the window stuff as it overwrites our borders with a blank
620 * rectangle. Instead start with the drawing of the GtkBin */
621 GTK_WIDGET_CLASS (g_type_class_peek_parent (hildon_window_parent_class))->expose_event (widget, event);
623 /* FIXME Not sure why this is commented out
624 * GTK_WIDGET_CLASS (hildon_window_parent_class))->
625 * expose_event (widget, event);
632 hildon_window_size_request (GtkWidget *widget,
633 GtkRequisition *requisition)
635 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
638 GtkWidget *child = GTK_BIN (widget)->child;
640 gint border_width = GTK_CONTAINER(widget)->border_width;
644 hildon_window_get_borders (HILDON_WINDOW (widget));
648 gtk_widget_size_request (child, requisition);
650 if (priv->vbox != NULL)
651 gtk_widget_size_request (priv->vbox, &req2);
653 requisition->height += req2.height;
654 requisition->width = (requisition->width < req2.width) ?
655 req2.width : requisition->width;
657 requisition->width += 2 * border_width;
658 requisition->height += 2 * border_width;
660 if (! priv->fullscreen)
662 requisition->height += priv->borders->top;
663 if (req2.height == 0)
664 requisition->height += priv->borders->bottom;
665 requisition->width += priv->borders->left + priv->borders->right;
670 hildon_window_size_allocate (GtkWidget *widget,
671 GtkAllocation *allocation)
673 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
676 GtkAllocation box_alloc;
677 GtkAllocation alloc = *allocation;
679 gint border_width = GTK_CONTAINER(widget)->border_width;
681 GtkWidget *box = priv->vbox;
682 GtkBin *bin = GTK_BIN(widget);
683 GtkBorder *b = priv->borders;
684 GtkBorder *tb = priv->toolbar_borders;
688 hildon_window_get_borders (HILDON_WINDOW (widget));
690 tb = priv->toolbar_borders;
693 widget->allocation = *allocation;
695 gtk_widget_get_child_requisition (box, &req);
697 box_alloc.width = allocation->width - tb->left - tb->right;
698 box_alloc.height = ( (req.height < allocation->height) ?
699 req.height : allocation->height );
700 box_alloc.x = allocation->x + tb->left;
701 box_alloc.y = allocation->y + allocation->height - box_alloc.height - tb->bottom;
703 if (bin->child != NULL && GTK_IS_WIDGET (bin->child)
704 && GTK_WIDGET_VISIBLE (bin->child))
706 alloc.x += border_width;
707 alloc.y += border_width;
708 alloc.width -= (border_width * 2);
709 alloc.height -= (border_width * 2) + box_alloc.height;
711 if (! priv->fullscreen)
714 alloc.width -= (b->left + b->right);
717 alloc.height -= b->top;
719 if (box_alloc.height <= 0)
720 alloc.height -= b->bottom;
722 alloc.height -= (tb->top + tb->bottom);
726 if (!(box_alloc.height <= 0))
727 alloc.height -= (tb->top + tb->bottom);
730 gtk_widget_size_allocate (bin->child, &alloc);
733 gtk_widget_size_allocate (box, &box_alloc);
735 if (priv->previous_vbox_y != box_alloc.y)
737 /* The size of the VBox has changed, we need to redraw part
738 * of the window borders */
739 gint draw_from_y = priv->previous_vbox_y < box_alloc.y?
740 priv->previous_vbox_y - tb->top:
741 box_alloc.y - tb->top;
743 gtk_widget_queue_draw_area (widget, 0, draw_from_y,
744 widget->allocation.width,
745 widget->allocation.height - draw_from_y);
747 priv->previous_vbox_y = box_alloc.y;
753 hildon_window_forall (GtkContainer *container,
754 gboolean include_internals,
755 GtkCallback callback,
756 gpointer callback_data)
758 HildonWindow *self = HILDON_WINDOW (container);
759 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
761 g_return_if_fail (callback != NULL);
764 GTK_CONTAINER_CLASS (hildon_window_parent_class)->forall (container, include_internals,
765 callback, callback_data);
766 if (include_internals && priv->vbox != NULL)
767 (* callback)(GTK_WIDGET (priv->vbox), callback_data);
771 hildon_window_show_all (GtkWidget *widget)
773 HildonWindow *self = HILDON_WINDOW (widget);
774 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
776 g_assert (priv != NULL);
778 GTK_WIDGET_CLASS (hildon_window_parent_class)->show_all (widget);
779 gtk_widget_show_all (priv->vbox);
783 hildon_window_destroy (GtkObject *obj)
785 HildonWindow *self = HILDON_WINDOW (obj);
786 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (obj);
787 GList *menu_list = NULL;
788 GList *menu_node = NULL;
790 g_assert (priv != NULL);
792 if (priv->vbox != NULL)
796 GtkWidget * common_toolbar =
797 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
798 if (common_toolbar && common_toolbar->parent == priv->vbox)
800 gtk_container_remove (GTK_CONTAINER (priv->vbox),
805 gtk_widget_unparent (priv->vbox);
810 menu_list = g_list_copy (gtk_menu_get_for_attach_widget (GTK_WIDGET (obj)));
811 menu_node = menu_list;
815 if (GTK_IS_MENU (menu_node->data))
817 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_node->data)))
819 gtk_menu_popdown (GTK_MENU (menu_node->data));
820 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_node->data));
822 gtk_menu_detach (GTK_MENU (menu_node->data));
824 /* Destroy it, but only if it's not a common menu */
826 hildon_program_get_common_menu (priv->program) != menu_node->data) {
827 gtk_object_destroy (GTK_OBJECT (menu_node->data));
828 g_object_unref (menu_node->data);
831 menu_node = menu_node->next;
834 g_list_free (menu_list);
839 hildon_program_remove_window (priv->program, self);
842 gdk_window_remove_filter (gdk_get_default_root_window(),
843 hildon_window_root_window_event_filter,
846 gtk_widget_set_events (GTK_WIDGET(obj), 0);
848 GTK_OBJECT_CLASS (hildon_window_parent_class)->destroy (obj);
852 hildon_window_notify (GObject *gobject,
855 HildonWindow *window = HILDON_WINDOW (gobject);
857 if (g_str_equal (param->name, "title"))
860 hildon_window_update_title (window);
862 else if (g_str_equal (param->name, "is-topmost"))
864 hildon_window_is_topmost_notify (window);
867 if (G_OBJECT_CLASS(hildon_window_parent_class)->notify)
868 G_OBJECT_CLASS(hildon_window_parent_class)->notify (gobject, param);
873 visible_toolbar (gpointer data,
876 if (GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
877 (*((gint *)user_data))++;
881 find_findtoolbar_index (gpointer data,
884 gint *pass_bundle = (gint *)user_data;
886 if(((GtkBoxChild *)data)->widget->allocation.y < pass_bundle[0]
887 && GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
892 find_findtoolbar (gpointer data,
895 if(HILDON_IS_FIND_TOOLBAR (((GtkBoxChild *)data)->widget)
896 && GTK_WIDGET_VISIBLE (((GtkBoxChild *)data)->widget))
897 (*((GtkWidget **)user_data)) = ((GtkBoxChild *)data)->widget;
901 paint_toolbar (GtkWidget *widget,
903 GdkEventExpose * event,
906 gint toolbar_num = 0;
909 GtkWidget *findtoolbar = NULL;
910 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
911 gchar toolbar_mode[40];
912 GtkBorder *tb = priv->toolbar_borders;
914 g_assert (priv != NULL);
916 /* collect info to help on painting the boxes */
917 g_list_foreach (box->children, visible_toolbar,
918 (gpointer) &toolbar_num);
923 g_list_foreach (box->children, find_findtoolbar, (gpointer) &findtoolbar);
925 if (findtoolbar != NULL)
927 gint pass_bundle[2];/* an array for convient data passing
928 the first member contains the y allocation
929 of the find toolbar, and the second allocation
930 contains the index(how many toolbars are above
932 pass_bundle[0] = findtoolbar->allocation.y;
933 pass_bundle[1] = ftb_index;
934 g_list_foreach(box->children, find_findtoolbar_index,
935 (gpointer) pass_bundle);
936 ftb_index = pass_bundle[1];
940 sprintf (toolbar_mode, "toolbar%sframe-top",
941 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 - tb->top,
947 widget->allocation.width, tb->top);
949 /*top most toolbar painting*/
950 if (findtoolbar != NULL && ftb_index == 0 )
952 sprintf (toolbar_mode, "findtoolbar%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,
965 sprintf (toolbar_mode, "toolbar%s",
966 fullscreen ? "-fullscreen" : "");
968 gtk_paint_box (widget->style, widget->window,
969 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
970 &event->area, widget, toolbar_mode,
971 widget->allocation.x,
972 GTK_WIDGET(box)->allocation.y,
973 widget->allocation.width,
976 /*multi toolbar painting*/
977 for (count = 0; count < toolbar_num - 1; count++)
979 sprintf (toolbar_mode, "toolbar%sframe-middle",
980 fullscreen ? "-fullscreen-" : "-");
982 gtk_paint_box (widget->style, widget->window,
983 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
984 &event->area, widget, toolbar_mode,
985 widget->allocation.x,
986 GTK_WIDGET(box)->allocation.y +
987 (1 + count) * TOOLBAR_HEIGHT +
988 count * TOOLBAR_MIDDLE,
989 widget->allocation.width,
992 if (findtoolbar != NULL && count + 1 == ftb_index)
995 sprintf (toolbar_mode, "findtoolbar%s",
996 fullscreen ? "-fullscreen" : "");
998 gtk_paint_box (widget->style, widget->window,
999 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
1000 &event->area, widget, toolbar_mode,
1001 widget->allocation.x,
1002 GTK_WIDGET(box)->allocation.y +
1003 (1 + count) * (TOOLBAR_HEIGHT + TOOLBAR_MIDDLE),
1004 widget->allocation.width,
1009 sprintf (toolbar_mode, "toolbar%s",
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 (1 + count) * (TOOLBAR_HEIGHT + TOOLBAR_MIDDLE),
1018 widget->allocation.width,
1022 sprintf (toolbar_mode, "toolbar%sframe-bottom",
1023 fullscreen ? "-fullscreen-" : "-");
1025 gtk_paint_box (widget->style, widget->window,
1026 GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT,
1027 &event->area, widget, toolbar_mode,
1028 widget->allocation.x,
1029 GTK_WIDGET(box)->allocation.y +
1030 GTK_WIDGET(box)->allocation.height,
1031 widget->allocation.width, tb->bottom);
1035 * Checks the root window to know which is the topped window
1038 hildon_window_get_active_window (void)
1046 unsigned long extra;
1050 unsigned char *char_pointer;
1052 Atom active_app_atom =
1053 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1057 gdk_error_trap_push ();
1058 status = XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1059 active_app_atom, 0L, 16L,
1060 0, XA_WINDOW, &realtype, &format,
1061 &n, &extra, &win.char_pointer);
1062 xerror = gdk_error_trap_pop ();
1063 if (xerror || !(status == Success && realtype == XA_WINDOW && format == 32
1064 && n == 1 && win.win != NULL))
1066 if (win.win != NULL)
1067 XFree (win.char_pointer);
1073 if (win.win != NULL)
1074 XFree(win.char_pointer);
1080 xclient_message_type_check (XClientMessageEvent *cm,
1083 return cm->message_type == XInternAtom(GDK_DISPLAY(), name, FALSE);
1087 * Handle the window border custom button, which toggles the menu,
1088 * and the Hildon input method copy paste messages
1090 static GdkFilterReturn
1091 hildon_window_event_filter (GdkXEvent *xevent,
1095 XAnyEvent *eventti = xevent;
1097 if (eventti->type == ClientMessage)
1099 XClientMessageEvent *cm = xevent;
1101 if (xclient_message_type_check (cm, "_MB_GRAB_TRANSFER"))
1103 hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]);
1104 return GDK_FILTER_REMOVE;
1106 /* opera hack clipboard client message */
1107 else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY"))
1109 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1110 HILDON_WINDOW_CO_COPY);
1111 return GDK_FILTER_REMOVE;
1113 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT"))
1115 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1116 HILDON_WINDOW_CO_CUT);
1117 return GDK_FILTER_REMOVE;
1119 else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE"))
1121 g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation",
1122 HILDON_WINDOW_CO_PASTE);
1123 return GDK_FILTER_REMOVE;
1127 return GDK_FILTER_CONTINUE;
1131 * Here we keep track of changes in the _MB_CURRENT_APP_WINDOW,
1132 * to know when we acquire/lose topmost status
1134 static GdkFilterReturn
1135 hildon_window_root_window_event_filter (GdkXEvent *xevent,
1139 XAnyEvent *eventti = xevent;
1140 HildonWindow *hwindow = HILDON_WINDOW (data);
1142 if (eventti->type == PropertyNotify)
1144 XPropertyEvent *pevent = xevent;
1145 Atom active_app_atom =
1146 XInternAtom (GDK_DISPLAY (), "_MB_CURRENT_APP_WINDOW", False);
1148 if (pevent->atom == active_app_atom)
1150 Window active_window = hildon_window_get_active_window();
1152 hildon_window_update_topmost (hwindow, active_window);
1156 return GDK_FILTER_CONTINUE;
1160 * Handle the menu hardware key here
1163 hildon_window_key_press_event (GtkWidget *widget,
1166 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1168 g_return_val_if_fail (HILDON_IS_WINDOW (widget),FALSE);
1171 switch (event->keyval)
1173 case HILDON_HARDKEY_MENU:
1174 if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME))
1177 case HILDON_HARDKEY_ESC:
1178 if (!priv->escape_timeout)
1180 priv->escape_timeout = g_timeout_add
1181 (HILDON_WINDOW_LONG_PRESS_TIME,
1182 hildon_window_escape_timeout, widget);
1187 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event);
1191 hildon_window_key_release_event (GtkWidget *widget,
1194 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1196 g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE);
1199 switch (event->keyval)
1201 case HILDON_HARDKEY_ESC:
1202 if (priv->escape_timeout)
1204 g_source_remove (priv->escape_timeout);
1205 priv->escape_timeout = 0;
1210 return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event);
1215 * We keep track of the window state changes, because the drawing
1216 * (borders) differs whether we are in fullscreen mode or not
1219 hildon_window_window_state_event (GtkWidget *widget,
1220 GdkEventWindowState *event)
1222 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1223 g_assert (priv != NULL);
1225 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1226 priv->fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
1228 if (GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event)
1230 return GTK_WIDGET_CLASS (hildon_window_parent_class)->window_state_event (
1241 * If the window lost focus while the user started to press the ESC key, we
1242 * won't get the release event. We need to stop the timeout.
1245 hildon_window_focus_out_event (GtkWidget *widget,
1246 GdkEventFocus *event)
1248 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget);
1250 if (priv->escape_timeout)
1252 g_source_remove (priv->escape_timeout);
1253 priv->escape_timeout = 0;
1256 return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event);
1260 * The menu popuping needs a menu popup-function
1263 hildon_window_menu_popup_func (GtkMenu *menu,
1271 GdkWindow *window = GTK_WIDGET(widget)->window;
1275 gdk_window_get_origin (window, &window_x, &window_y);
1278 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1279 "vertical-offset", y, NULL);
1281 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1283 *x = GTK_WIDGET (widget)->allocation.width + window_x - GTK_WIDGET (menu)->allocation.width - *x;
1293 hildon_window_menu_popup_func_full (GtkMenu *menu,
1299 gtk_widget_style_get (GTK_WIDGET (menu), "horizontal-offset", x,
1300 "vertical-offset", y, NULL);
1302 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1303 *x = GTK_WIDGET (widget)->allocation.width - GTK_WIDGET (menu)->allocation.width - *x;
1312 * Takes the common toolbar when we acquire the top-most status
1315 hildon_window_is_topmost_notify (HildonWindow *window)
1317 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1321 if (priv->is_topmost)
1323 hildon_window_take_common_toolbar (window);
1328 * Sets the program to which the window belongs. This should only be called
1329 * by hildon_program_add_window
1331 void G_GNUC_INTERNAL
1332 hildon_window_set_program (HildonWindow *self,
1335 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1337 g_return_if_fail (HILDON_IS_WINDOW (self));
1338 g_assert (priv != NULL);
1342 g_object_unref (priv->program);
1345 /* Now that we are bound to a program, we can rely on it to track the
1347 gdk_window_remove_filter (gdk_get_default_root_window(),
1348 hildon_window_root_window_event_filter,
1351 priv->program = HILDON_PROGRAM (program);
1352 g_object_ref (program);
1356 * Unsets the program to which the window belongs. This should only be called
1357 * by hildon_program_remove_window
1360 hildon_window_unset_program_real (HildonWindow *self)
1362 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1364 g_return_if_fail(HILDON_IS_WINDOW (self));
1365 g_assert (priv != NULL);
1369 g_object_unref (priv->program);
1370 priv->program = NULL;
1372 /* We need to start tacking the root window again */
1373 gdk_window_set_events (gdk_get_default_root_window (),
1374 gdk_window_get_events (gdk_get_default_root_window ())
1375 | GDK_PROPERTY_CHANGE_MASK);
1377 gdk_window_add_filter (gdk_get_default_root_window (),
1378 hildon_window_root_window_event_filter, self );
1381 priv->program = NULL;
1384 void G_GNUC_INTERNAL
1385 hildon_window_unset_program (HildonWindow *self)
1387 g_return_if_fail (HILDON_IS_WINDOW (self));
1389 if (HILDON_WINDOW_GET_CLASS (self)->unset_program != NULL)
1390 HILDON_WINDOW_GET_CLASS (self)->unset_program (self);
1394 * Sets whether or not the program to which this window belongs is
1395 * killable. This is used by the HildonProgram to signify to the
1396 * Task Navigator whether or not it can hibernate in memory-low situations
1398 void G_GNUC_INTERNAL
1399 hildon_window_set_can_hibernate_property (HildonWindow *self,
1400 gpointer _can_hibernate)
1402 GdkAtom killable_atom;
1403 gboolean can_hibernate;
1405 g_return_if_fail(self && HILDON_IS_WINDOW (self));
1407 if (!GTK_WIDGET_REALIZED ((GTK_WIDGET (self))))
1412 can_hibernate = * ((gboolean *)_can_hibernate);
1414 killable_atom = gdk_atom_intern (CAN_HIBERNATE_PROPERTY, FALSE);
1418 gdk_property_change (GTK_WIDGET (self)->window, killable_atom,
1419 (GdkAtom)31/* XA_STRING */, 8,
1420 GDK_PROP_MODE_REPLACE, (const guchar *)CAN_HIBERNATE,
1421 CAN_HIBERNATE_LENGTH);
1425 gdk_property_delete (GTK_WIDGET (self)->window, killable_atom);
1431 * If a common toolbar was set to the program, reparent it to
1434 void G_GNUC_INTERNAL
1435 hildon_window_take_common_toolbar (HildonWindow *self)
1437 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1439 g_return_if_fail(HILDON_IS_WINDOW (self));
1444 GtkWidget *common_toolbar =
1445 GTK_WIDGET (hildon_program_get_common_toolbar (priv->program));
1447 if (common_toolbar && common_toolbar->parent != priv->vbox)
1449 g_object_ref (common_toolbar);
1450 if (common_toolbar->parent)
1452 gtk_container_remove (GTK_CONTAINER (common_toolbar->parent),
1456 gtk_box_pack_end (GTK_BOX(priv->vbox), common_toolbar,
1458 g_object_unref (common_toolbar);
1460 gtk_widget_set_size_request (common_toolbar, -1, TOOLBAR_HEIGHT);
1462 gtk_widget_show (priv->vbox);
1469 * Compare the window that was last topped, and act consequently
1472 hildon_window_update_topmost (HildonWindow *self,
1475 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1479 g_return_if_fail (HILDON_IS_WINDOW (self));
1482 my_window = GDK_WINDOW_XID (GTK_WIDGET (self)->window);
1484 if (window_id == my_window)
1486 if (! priv->is_topmost)
1488 priv->is_topmost = TRUE;
1489 hildon_window_is_topmost_notify (self);
1490 g_object_notify (G_OBJECT (self), "is-topmost");
1493 else if (priv->is_topmost)
1495 /* Should this go in the signal handler? */
1496 GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (self));
1498 if (GTK_IS_ENTRY (focus))
1499 gtk_im_context_focus_out (GTK_ENTRY (focus)->im_context);
1500 if (GTK_IS_TEXT_VIEW (focus))
1501 gtk_im_context_focus_out (GTK_TEXT_VIEW (focus)->im_context);
1503 priv->is_topmost = FALSE;
1504 hildon_window_is_topmost_notify (self);
1505 g_object_notify (G_OBJECT (self), "is-topmost");
1510 * If the application
1511 * was given a name (with g_set_application_name(), set
1512 * "ProgramName - WindowTitle" as the displayed
1515 void G_GNUC_INTERNAL
1516 hildon_window_update_title (HildonWindow *window)
1518 const gchar * application_name;
1520 g_return_if_fail (HILDON_IS_WINDOW (window));
1522 if (!GTK_WIDGET_REALIZED (window))
1527 application_name = g_get_application_name ();
1529 if (application_name && application_name[0])
1531 const gchar *old_title = gtk_window_get_title (GTK_WINDOW (window));
1535 gchar *title = NULL;
1537 if (strlen (old_title) == 0)
1538 title = g_strdup (application_name);
1540 title = g_strjoin (TITLE_SEPARATOR, application_name,
1543 gdk_window_set_title (GTK_WIDGET (window)->window, title);
1552 detach_menu_func (GtkWidget *attach_widget,
1555 /* FIXME Why is this even needed here? */
1559 * Toggles the display of the HildonWindow menu.
1560 * Returns whether or not something was done (whether or not we had a menu
1564 hildon_window_toggle_menu (HildonWindow * self,
1568 GtkMenu *menu_to_use = NULL;
1569 GList *menu_children = NULL;
1570 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (self);
1572 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1573 g_assert (priv != NULL);
1575 /* Select which menu to use, Window specific has highest priority,
1576 * then program specific */
1579 menu_to_use = GTK_MENU (priv->menu);
1581 else if (priv->program)
1583 menu_to_use = hildon_program_get_common_menu (priv->program);
1584 if (menu_to_use && gtk_menu_get_attach_widget (menu_to_use) !=
1587 g_object_ref (menu_to_use);
1588 if (gtk_menu_get_attach_widget (menu_to_use))
1590 gtk_menu_detach (menu_to_use);
1593 gtk_menu_attach_to_widget (menu_to_use, GTK_WIDGET (self),
1595 g_object_unref (menu_to_use);
1605 if (GTK_WIDGET_MAPPED (GTK_WIDGET (menu_to_use)))
1607 gtk_menu_popdown (menu_to_use);
1608 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_to_use));
1612 /* Check if the menu has items */
1613 menu_children = gtk_container_get_children (GTK_CONTAINER (menu_to_use));
1617 g_list_free (menu_children);
1619 /* Apply right theming */
1620 gtk_widget_set_name (GTK_WIDGET (menu_to_use),
1621 "menu_force_with_corners");
1623 if (priv->fullscreen)
1625 gtk_menu_popup (menu_to_use, NULL, NULL,
1626 (GtkMenuPositionFunc)
1627 hildon_window_menu_popup_func_full,
1628 self, button, time);
1632 gtk_menu_popup (menu_to_use, NULL, NULL,
1633 (GtkMenuPositionFunc)
1634 hildon_window_menu_popup_func,
1635 self, button, time);
1637 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_to_use), TRUE);
1645 * If the ESC key was not released when the timeout expires,
1649 hildon_window_escape_timeout (gpointer data)
1651 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data);
1656 GDK_THREADS_ENTER ();
1658 /* Send fake event, simulation a situation that user
1659 pressed 'x' from the corner */
1660 event = gdk_event_new(GDK_DELETE);
1661 ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window));
1662 gtk_main_do_event(event);
1664 /* That unrefs the window, so we're reffing it above */
1665 gdk_event_free(event);
1667 priv->escape_timeout = 0;
1669 GDK_THREADS_LEAVE ();
1675 * hildon_window_new:
1677 * Creates a new HildonWindow.
1679 * Return value: A @HildonWindow.
1682 hildon_window_new (void)
1684 HildonWindow *newwindow = g_object_new (HILDON_TYPE_WINDOW, NULL);
1686 return GTK_WIDGET (newwindow);
1690 * hildon_window_add_with_scrollbar
1691 * @self : A @HildonWindow
1692 * @child : A @GtkWidget
1694 * Adds the @child to the HildonWindow and creates a scrollbar
1695 * for it. Similar as adding first a @GtkScrolledWindow and then the
1699 hildon_window_add_with_scrollbar (HildonWindow *self,
1702 GtkScrolledWindow *scrolledw;
1704 g_return_if_fail (HILDON_IS_WINDOW (self));
1705 g_return_if_fail (GTK_IS_WIDGET (child));
1706 g_return_if_fail (child->parent == NULL);
1708 scrolledw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1709 gtk_scrolled_window_set_policy (scrolledw, GTK_POLICY_NEVER,
1710 GTK_POLICY_AUTOMATIC);
1711 gtk_scrolled_window_set_shadow_type (scrolledw, GTK_SHADOW_NONE);
1713 if (GTK_IS_VIEWPORT (child))
1714 gtk_container_add (GTK_CONTAINER (scrolledw), child);
1717 if (GTK_IS_CONTAINER (child) )
1718 gtk_container_set_focus_vadjustment (GTK_CONTAINER(child),
1719 gtk_scrolled_window_get_vadjustment (scrolledw) );
1720 gtk_scrolled_window_add_with_viewport (scrolledw, child);
1723 gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (scrolledw));
1727 calculate_visible_toolbars (gpointer data,
1730 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (((GtkBoxChild *)data)->widget)))
1731 (*((gint *)user_data)) ++;
1735 toolbar_visible_notify (GtkWidget *toolbar, GParamSpec *pspec,
1736 HildonWindow *window)
1738 HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
1742 /* Recalculate from scratch the value just in case */
1743 priv->visible_toolbars = 0;
1745 g_list_foreach (GTK_BOX (priv->vbox)->children, calculate_visible_toolbars,
1746 &priv->visible_toolbars);
1748 if (priv->visible_toolbars == 0)
1749 gtk_widget_hide (priv->vbox);
1751 gtk_widget_show (priv->vbox);
1755 * hildon_window_add_toolbar:
1756 * @self: A @HildonWindow
1757 * @toolbar: A #GtkToolbar to add to the HildonWindow
1759 * Adds a toolbar to the window. Note that the toolbar is not automatically
1760 * shown. You need to call #gtk_widget_show_all on it to make it visible.
1761 * It's also possible to hide the toolbar (without removing it) by calling
1765 hildon_window_add_toolbar (HildonWindow *self,
1766 GtkToolbar *toolbar)
1769 HildonWindowPrivate *priv;
1771 g_return_if_fail (HILDON_IS_WINDOW (self));
1772 g_return_if_fail (toolbar && GTK_IS_TOOLBAR (toolbar));
1774 priv = HILDON_WINDOW_GET_PRIVATE (self);
1776 vbox = GTK_BOX (priv->vbox);
1778 gtk_box_pack_start (vbox, GTK_WIDGET (toolbar), TRUE, TRUE, 0);
1779 gtk_box_reorder_child (vbox, GTK_WIDGET (toolbar), 0);
1780 gtk_widget_set_size_request (GTK_WIDGET (toolbar), -1, TOOLBAR_HEIGHT);
1782 g_signal_connect (G_OBJECT (toolbar), "notify::visible",
1783 G_CALLBACK (toolbar_visible_notify), self);
1785 if (GTK_WIDGET_VISIBLE (toolbar))
1787 priv->visible_toolbars++;
1788 gtk_widget_show (priv->vbox);
1791 gtk_widget_queue_resize (GTK_WIDGET (self));
1795 * hildon_window_remove_toolbar:
1796 * @self: A @HildonWindow
1797 * @toolbar: A #GtkToolbar to remove from the HildonWindow
1799 * Removes a toolbar from the window. Note that this decreases the refference
1800 * count on the widget. If you want to keep the toolbar alive call #g_object_ref
1801 * before calling this function.
1804 hildon_window_remove_toolbar (HildonWindow *self,
1805 GtkToolbar *toolbar)
1807 HildonWindowPrivate *priv;
1809 g_return_if_fail (HILDON_IS_WINDOW (self));
1811 priv = HILDON_WINDOW_GET_PRIVATE (self);
1813 if (GTK_WIDGET_VISIBLE (toolbar))
1815 if (--(priv->visible_toolbars) == 0)
1816 gtk_widget_hide (priv->vbox);
1819 g_signal_handlers_disconnect_by_func (toolbar, toolbar_visible_notify, self);
1821 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (toolbar));
1825 * hildon_window_get_menu:
1826 * @self : #HildonWindow
1828 * Gets the #GtMenu assigned to the #HildonAppview. Note that the
1829 * window is still the owner of the menu.
1831 * Return value: The #GtkMenu assigned to this application view.
1834 hildon_window_get_menu (HildonWindow * self)
1836 HildonWindowPrivate *priv;
1838 g_return_val_if_fail (HILDON_IS_WINDOW (self), NULL);
1840 priv = HILDON_WINDOW_GET_PRIVATE (self);
1842 return GTK_MENU (priv->menu);
1845 /* Since we've been asking developers to call gtk_window_add_accel_group()
1846 * themselves, do not trigger criticals by trying it again.
1849 hildon_window_add_accel_group (HildonWindow *self,
1850 GtkAccelGroup *accel_group)
1854 groups = gtk_accel_groups_from_object (G_OBJECT (self));
1855 for (l = groups; l != NULL; l = l->next)
1856 if (l->data == (gpointer)accel_group)
1857 /* Maybe print a warning here? */
1860 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
1864 * hildon_window_set_main_menu:
1865 * @self: A #HildonWindow
1866 * @menu: The #GtkMenu to be used for this #HildonWindow
1868 * Sets the menu to be used for this window. This menu overrides
1869 * a program-wide menu that may have been set with
1870 * hildon_program_set_common_menu(). Pass %NULL to remove the current
1871 * menu. #HildonWindow takes ownership of the passed menu and you're
1872 * not supposed to free it yourself anymore.
1877 hildon_window_set_main_menu (HildonWindow* self,
1880 HildonWindowPrivate *priv;
1881 GtkAccelGroup *accel_group;
1883 g_return_if_fail (HILDON_IS_WINDOW (self));
1885 priv = HILDON_WINDOW_GET_PRIVATE (self);
1887 if (priv->menu != NULL)
1889 accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
1890 if (accel_group != NULL)
1891 gtk_window_remove_accel_group (GTK_WINDOW (self), accel_group);
1893 gtk_menu_detach (GTK_MENU (priv->menu));
1894 g_object_unref (priv->menu);
1897 priv->menu = (menu != NULL) ? GTK_WIDGET (menu) : NULL;
1898 if (priv->menu != NULL)
1900 gtk_widget_set_name (priv->menu, "menu_force_with_corners");
1901 gtk_menu_attach_to_widget (GTK_MENU (priv->menu), GTK_WIDGET (self), &detach_menu_func);
1902 g_object_ref (GTK_MENU (priv->menu));
1904 accel_group = gtk_menu_get_accel_group (GTK_MENU (priv->menu));
1905 if (accel_group != NULL)
1906 hildon_window_add_accel_group (self, accel_group);
1911 * hildon_window_set_menu:
1912 * @self: A #HildonWindow
1913 * @menu: The #GtkMenu to be used for this #HildonWindow
1915 * Sets the menu to be used for this window. This menu overrides
1916 * a program-wide menu that may have been set with
1917 * hildon_program_set_common_menu. Pass NULL to remove the current
1918 * menu. HildonWindow takes ownership of the passed menu and you're
1919 * not supposed to free it yourself anymore.
1921 * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the
1922 * #GtkMenu. To pass control about visibility to the application
1923 * developer, hildon_window_set_main_menu() was introduced, which
1926 * Deprecated: Hildon 2.2: use hildon_window_set_main_menu()
1929 hildon_window_set_menu (HildonWindow *self,
1932 HildonWindowPrivate *priv;
1934 g_return_if_fail (HILDON_IS_WINDOW (self));
1936 hildon_window_set_main_menu (self, menu);
1938 priv = HILDON_WINDOW_GET_PRIVATE (self);
1940 if (priv->menu != NULL)
1941 gtk_widget_show_all (GTK_WIDGET (priv->menu));
1945 * hildon_window_get_is_topmost:
1946 * @self: A #HildonWindow
1948 * Return value: Whether or not the #HildonWindow is currenltly activated
1949 * by the window manager.
1952 hildon_window_get_is_topmost (HildonWindow *self)
1954 HildonWindowPrivate *priv;
1956 g_return_val_if_fail (HILDON_IS_WINDOW (self), FALSE);
1958 priv = HILDON_WINDOW_GET_PRIVATE (self);
1959 return priv->is_topmost;