2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser Public License as published by
10 * the Free Software Foundation; version 2 of the license.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser Public License for more details.
20 * SECTION:hildon-app-menu
21 * @short_description: Widget representing the application menu in the Hildon framework.
23 * The #HildonAppMenu is a GTK widget which represents an application
24 * menu in the Hildon framework.
26 * This menu opens from the top of the screen and contains a number of
27 * entries (#GtkButton) organized in one or two columns, depending on
28 * the size of the screen (the number of columns changes automatically
29 * if the screen is resized). Entries are added left to right and top
32 * Besides that, the #HildonAppMenu can contain a group of filter buttons
33 * (#GtkToggleButton or #GtkRadioButton).
35 * To use a #HildonAppMenu, add it to a #HildonStackableWindow using
36 * hildon_stackable_window_set_main_menu(). The menu will appear when
37 * the user presses the window title bar. Alternatively, you can show
38 * it by hand using gtk_widget_show().
40 * The menu will be automatically hidden when one of its buttons is
41 * clicked. Use g_signal_connect_after() when connecting callbacks to
42 * buttons to make sure that they're called after the menu
43 * disappears. Alternatively, you can add the button to the menu
44 * before connecting any callback.
46 * Although implemented with a #GtkWindow, #HildonAppMenu behaves like
47 * a normal ref-counted widget, so g_object_ref(), g_object_unref(),
48 * g_object_ref_sink() and friends will behave just like with any
49 * other non-toplevel widget.
52 * <title>Creating a HildonAppMenu</title>
54 * HildonStackableWindow *win;
55 * HildonAppMenu *menu;
59 * win = HILDON_STACKABLE_WINDOW (hildon_stackable_window_new ());
60 * menu = HILDON_APP_MENU (hildon_app_menu_new ());
62 * // Create a button and add it to the menu
63 * button = gtk_button_new_with_label ("Menu command one");
64 * g_signal_connect_after (button, "clicked", G_CALLBACK (button_one_clicked), userdata);
65 * hildon_app_menu_append (menu, GTK_BUTTON (button));
66 * gtk_widget_show (button);
69 * button = gtk_button_new_with_label ("Menu command two");
70 * g_signal_connect_after (button, "clicked", G_CALLBACK (button_two_clicked), userdata);
71 * hildon_app_menu_append (menu, GTK_BUTTON (button));
72 * gtk_widget_show (button);
74 * // Create a filter and add it to the menu
75 * filter = gtk_radio_button_new_with_label (NULL, "Filter one");
76 * gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (filter), FALSE);
77 * g_signal_connect_after (filter, "clicked", G_CALLBACK (filter_one_clicked), userdata);
78 * hildon_app_menu_add_filter (menu, GTK_BUTTON (filter));
79 * gtk_widget_show (filter);
82 * filter = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (filter), "Filter two");
83 * gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (filter), FALSE);
84 * g_signal_connect_after (filter, "clicked", G_CALLBACK (filter_two_clicked), userdata);
85 * hildon_app_menu_add_filter (menu, GTK_BUTTON (filter));
86 * gtk_widget_show (filter);
88 * // Add the menu to the window
89 * hildon_stackable_window_set_main_menu (win, menu);
96 #include <X11/Xatom.h>
99 #include "hildon-gtk.h"
100 #include "hildon-app-menu.h"
101 #include "hildon-app-menu-private.h"
104 grab_transfer_window_get (GtkWidget *widget);
107 hildon_app_menu_repack_items (HildonAppMenu *menu,
111 hildon_app_menu_repack_filters (HildonAppMenu *menu);
114 can_activate_accel (GtkWidget *widget,
119 item_visibility_changed (GtkWidget *item,
121 HildonAppMenu *menu);
124 filter_visibility_changed (GtkWidget *item,
126 HildonAppMenu *menu);
129 remove_item_from_list (GList **list,
133 hildon_app_menu_apply_style (GtkWidget *widget);
135 G_DEFINE_TYPE (HildonAppMenu, hildon_app_menu, GTK_TYPE_WINDOW);
138 * hildon_app_menu_new:
140 * Creates a new #HildonAppMenu.
142 * Return value: A #HildonAppMenu.
147 hildon_app_menu_new (void)
149 GtkWidget *menu = g_object_new (HILDON_TYPE_APP_MENU, NULL);
154 * hildon_app_menu_insert:
155 * @menu : A #HildonAppMenu
156 * @item : A #GtkButton to add to the #HildonAppMenu
157 * @position : The position in the item list where @item is added (from 0 to n-1).
159 * Adds @item to @menu at the position indicated by @position.
164 hildon_app_menu_insert (HildonAppMenu *menu,
168 HildonAppMenuPrivate *priv;
170 g_return_if_fail (HILDON_IS_APP_MENU (menu));
171 g_return_if_fail (GTK_IS_BUTTON (item));
173 priv = HILDON_APP_MENU_GET_PRIVATE(menu);
175 /* Force widget size */
176 hildon_gtk_widget_set_theme_size (GTK_WIDGET (item),
177 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
179 /* Add the item to the menu */
180 gtk_widget_show (GTK_WIDGET (item));
181 g_object_ref_sink (item);
182 priv->buttons = g_list_insert (priv->buttons, item, position);
183 hildon_app_menu_repack_items (menu, position);
185 /* Enable accelerators */
186 gtk_widget_realize (GTK_WIDGET (item));
187 g_signal_connect (item, "can-activate-accel", G_CALLBACK (can_activate_accel), NULL);
189 /* Close the menu when the button is clicked */
190 g_signal_connect_swapped (item, "clicked", G_CALLBACK (gtk_widget_hide), menu);
191 g_signal_connect (item, "notify::visible", G_CALLBACK (item_visibility_changed), menu);
193 /* Remove item from list when it is destroyed */
194 g_object_weak_ref (G_OBJECT (item), (GWeakNotify) remove_item_from_list, &(priv->buttons));
198 * hildon_app_menu_append:
199 * @menu : A #HildonAppMenu
200 * @item : A #GtkButton to add to the #HildonAppMenu
202 * Adds @item to the end of the menu's item list.
207 hildon_app_menu_append (HildonAppMenu *menu,
210 hildon_app_menu_insert (menu, item, -1);
214 * hildon_app_menu_prepend:
215 * @menu : A #HildonAppMenu
216 * @item : A #GtkButton to add to the #HildonAppMenu
218 * Adds @item to the beginning of the menu's item list.
223 hildon_app_menu_prepend (HildonAppMenu *menu,
226 hildon_app_menu_insert (menu, item, 0);
230 * hildon_app_menu_reorder_child:
231 * @menu : A #HildonAppMenu
232 * @item : A #GtkButton to move
233 * @position : The new position to place @item (from 0 to n-1).
235 * Moves a #GtkButton to a new position within #HildonAppMenu.
240 hildon_app_menu_reorder_child (HildonAppMenu *menu,
244 HildonAppMenuPrivate *priv;
247 g_return_if_fail (HILDON_IS_APP_MENU (menu));
248 g_return_if_fail (GTK_IS_BUTTON (item));
249 g_return_if_fail (position >= 0);
251 priv = HILDON_APP_MENU_GET_PRIVATE (menu);
252 old_position = g_list_index (priv->buttons, item);
254 g_return_if_fail (old_position >= 0);
257 priv->buttons = g_list_remove (priv->buttons, item);
258 priv->buttons = g_list_insert (priv->buttons, item, position);
260 hildon_app_menu_repack_items (menu, MIN (old_position, position));
264 * hildon_app_menu_add_filter:
265 * @menu : A #HildonAppMenu
266 * @filter : A #GtkButton to add to the #HildonAppMenu.
268 * Adds the @filter to @menu.
273 hildon_app_menu_add_filter (HildonAppMenu *menu,
276 HildonAppMenuPrivate *priv;
278 g_return_if_fail (HILDON_IS_APP_MENU (menu));
279 g_return_if_fail (GTK_IS_BUTTON (filter));
281 priv = HILDON_APP_MENU_GET_PRIVATE(menu);
283 /* Force widget size */
284 hildon_gtk_widget_set_theme_size (GTK_WIDGET (filter),
285 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
287 /* Add the filter to the menu */
288 gtk_widget_show (GTK_WIDGET (filter));
289 g_object_ref_sink (filter);
290 priv->filters = g_list_append (priv->filters, filter);
291 hildon_app_menu_repack_filters (menu);
293 /* Enable accelerators */
294 gtk_widget_realize (GTK_WIDGET (filter));
295 g_signal_connect (filter, "can-activate-accel", G_CALLBACK (can_activate_accel), NULL);
297 /* Close the menu when the button is clicked */
298 g_signal_connect_swapped (filter, "clicked", G_CALLBACK (gtk_widget_hide), menu);
299 g_signal_connect (filter, "notify::visible", G_CALLBACK (filter_visibility_changed), menu);
301 /* Remove filter from list when it is destroyed */
302 g_object_weak_ref (G_OBJECT (filter), (GWeakNotify) remove_item_from_list, &(priv->filters));
306 hildon_app_menu_set_columns (HildonAppMenu *menu,
309 HildonAppMenuPrivate *priv;
311 g_return_if_fail (HILDON_IS_APP_MENU (menu));
312 g_return_if_fail (columns > 0);
314 priv = HILDON_APP_MENU_GET_PRIVATE (menu);
316 if (columns != priv->columns) {
317 priv->columns = columns;
318 hildon_app_menu_repack_items (menu, 0);
323 hildon_app_menu_set_parent_window (HildonAppMenu *self,
324 GtkWindow *parent_window)
326 HildonAppMenuPrivate *priv;
328 g_return_if_fail (HILDON_IS_APP_MENU (self));
329 g_return_if_fail (parent_window == NULL || GTK_IS_WINDOW (parent_window));
331 priv = HILDON_APP_MENU_GET_PRIVATE(self);
333 priv->parent_window = parent_window;
335 if (parent_window == NULL && GTK_WIDGET_VISIBLE (self))
336 gtk_widget_hide (GTK_WIDGET (self));
339 gpointer G_GNUC_INTERNAL
340 hildon_app_menu_get_parent_window (HildonAppMenu *self)
342 HildonAppMenuPrivate *priv;
344 g_return_val_if_fail (HILDON_IS_APP_MENU (self), NULL);
346 priv = HILDON_APP_MENU_GET_PRIVATE (self);
348 return priv->parent_window;
352 screen_size_changed (GdkScreen *screen,
355 hildon_app_menu_apply_style (GTK_WIDGET (menu));
357 if (gdk_screen_get_width (screen) > gdk_screen_get_height (screen)) {
358 hildon_app_menu_set_columns (menu, 2);
360 hildon_app_menu_set_columns (menu, 1);
365 can_activate_accel (GtkWidget *widget,
369 return GTK_WIDGET_VISIBLE (widget);
373 item_visibility_changed (GtkWidget *item,
377 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE (menu);
379 hildon_app_menu_repack_items (menu, g_list_index (priv->buttons, item));
383 filter_visibility_changed (GtkWidget *item,
387 hildon_app_menu_repack_filters (menu);
391 remove_item_from_list (GList **list,
394 *list = g_list_remove (*list, item);
398 hildon_app_menu_show (GtkWidget *widget)
400 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(widget);
402 /* Show the menu only if it's not empty */
403 if (priv->buttons || priv->filters) {
404 GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->show (widget);
409 hildon_app_menu_map (GtkWidget *widget)
411 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(widget);
413 GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->map (widget);
415 /* Grab pointer and keyboard */
416 if (priv->transfer_window == NULL) {
417 gboolean has_grab = FALSE;
419 priv->transfer_window = grab_transfer_window_get (widget);
421 if (gdk_pointer_grab (priv->transfer_window, TRUE,
422 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
423 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
424 GDK_POINTER_MOTION_MASK, NULL, NULL,
425 GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS) {
426 if (gdk_keyboard_grab (priv->transfer_window, TRUE,
427 GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS) {
430 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
436 gtk_grab_add (widget);
438 gdk_window_destroy (priv->transfer_window);
439 priv->transfer_window = NULL;
445 hildon_app_menu_unmap (GtkWidget *widget)
447 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(widget);
449 /* Remove the grab */
450 if (priv->transfer_window != NULL) {
451 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
453 gtk_grab_remove (widget);
455 gdk_window_destroy (priv->transfer_window);
456 priv->transfer_window = NULL;
459 GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->unmap (widget);
463 hildon_app_menu_hide_idle (gpointer widget)
465 gtk_widget_hide (GTK_WIDGET (widget));
469 /* Send keyboard accelerators to the parent window, if necessary.
470 * This code is heavily based on gtk_menu_key_press ()
473 hildon_app_menu_key_press (GtkWidget *widget,
476 GtkWindow *parent_window;
477 HildonAppMenuPrivate *priv;
479 g_return_val_if_fail (HILDON_IS_APP_MENU (widget), FALSE);
480 g_return_val_if_fail (event != NULL, FALSE);
482 if (GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->key_press_event (widget, event))
485 priv = HILDON_APP_MENU_GET_PRIVATE (widget);
486 parent_window = priv->parent_window;
489 guint accel_key, accel_mods;
490 GdkModifierType consumed_modifiers;
492 GSList *accel_groups;
495 display = gtk_widget_get_display (widget);
497 /* Figure out what modifiers went into determining the key symbol */
498 gdk_keymap_translate_keyboard_state (gdk_keymap_get_for_display (display),
499 event->hardware_keycode, event->state, event->group,
500 NULL, NULL, NULL, &consumed_modifiers);
502 accel_key = gdk_keyval_to_lower (event->keyval);
503 accel_mods = event->state & gtk_accelerator_get_default_mod_mask () & ~consumed_modifiers;
505 /* If lowercasing affects the keysym, then we need to include SHIFT in the modifiers,
506 * We re-upper case when we match against the keyval, but display and save in caseless form.
508 if (accel_key != event->keyval)
509 accel_mods |= GDK_SHIFT_MASK;
511 accel_groups = gtk_accel_groups_from_object (G_OBJECT (parent_window));
513 for (list = accel_groups; list; list = list->next) {
514 GtkAccelGroup *accel_group = list->data;
516 if (gtk_accel_group_query (accel_group, accel_key, accel_mods, NULL)) {
517 gtk_window_activate_key (parent_window, event);
518 gdk_threads_add_idle (hildon_app_menu_hide_idle, widget);
528 hildon_app_menu_button_press (GtkWidget *widget,
529 GdkEventButton *event)
532 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(widget);
534 gdk_window_get_position (widget->window, &x, &y);
536 /* Whether the button has been pressed outside the widget */
537 priv->pressed_outside = (event->x_root < x || event->x_root > x + widget->allocation.width ||
538 event->y_root < y || event->y_root > y + widget->allocation.height);
540 if (GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->button_press_event) {
541 return GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->button_press_event (widget, event);
548 hildon_app_menu_button_release (GtkWidget *widget,
549 GdkEventButton *event)
551 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(widget);
553 if (priv->pressed_outside) {
555 gboolean released_outside;
557 gdk_window_get_position (widget->window, &x, &y);
559 /* Whether the button has been released outside the widget */
560 released_outside = (event->x_root < x || event->x_root > x + widget->allocation.width ||
561 event->y_root < y || event->y_root > y + widget->allocation.height);
563 if (released_outside) {
564 gtk_widget_hide (widget);
567 priv->pressed_outside = FALSE; /* Always reset pressed_outside to FALSE */
570 if (GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->button_release_event) {
571 return GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->button_release_event (widget, event);
577 /* Grab transfer window (based on the one from GtkMenu) */
579 grab_transfer_window_get (GtkWidget *widget)
582 GdkWindowAttr attributes;
583 gint attributes_mask;
587 attributes.width = 10;
588 attributes.height = 10;
589 attributes.window_type = GDK_WINDOW_TEMP;
590 attributes.wclass = GDK_INPUT_ONLY;
591 attributes.override_redirect = TRUE;
592 attributes.event_mask = 0;
594 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
596 window = gdk_window_new (gtk_widget_get_root_window (widget),
597 &attributes, attributes_mask);
598 gdk_window_set_user_data (window, widget);
600 gdk_window_show (window);
606 hildon_app_menu_realize (GtkWidget *widget)
608 Atom property, window_type;
610 GdkDisplay *gdkdisplay;
613 GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->realize (widget);
615 gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
617 gdkdisplay = gdk_drawable_get_display (widget->window);
618 xdisplay = GDK_WINDOW_XDISPLAY (widget->window);
620 property = gdk_x11_get_xatom_by_name_for_display (gdkdisplay, "_NET_WM_WINDOW_TYPE");
621 window_type = XInternAtom (xdisplay, "_HILDON_WM_WINDOW_TYPE_APP_MENU", False);
622 XChangeProperty (xdisplay, GDK_WINDOW_XID (widget->window), property,
623 XA_ATOM, 32, PropModeReplace, (guchar *) &window_type, 1);
625 /* Detect any screen changes */
626 screen = gtk_widget_get_screen (widget);
627 g_signal_connect (screen, "size-changed", G_CALLBACK (screen_size_changed), widget);
629 /* Force menu to set the initial layout */
630 screen_size_changed (screen, HILDON_APP_MENU (widget));
634 hildon_app_menu_unrealize (GtkWidget *widget)
636 GdkScreen *screen = gtk_widget_get_screen (widget);
637 /* Disconnect "size-changed" signal handler */
638 g_signal_handlers_disconnect_by_func (screen, G_CALLBACK (screen_size_changed), widget);
640 GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->unrealize (widget);
644 hildon_app_menu_apply_style (GtkWidget *widget)
648 guint horizontal_spacing, vertical_spacing, inner_border, external_border;
649 HildonAppMenuPrivate *priv;
651 priv = HILDON_APP_MENU_GET_PRIVATE (widget);
653 gtk_widget_style_get (widget,
654 "horizontal-spacing", &horizontal_spacing,
655 "vertical-spacing", &vertical_spacing,
656 "inner-border", &inner_border,
657 "external-border", &external_border,
661 gtk_table_set_row_spacings (priv->table, vertical_spacing);
662 gtk_table_set_col_spacings (priv->table, horizontal_spacing);
663 gtk_box_set_spacing (priv->vbox, vertical_spacing);
665 /* Set inner border */
666 gtk_container_set_border_width (GTK_CONTAINER (widget), inner_border);
668 /* Set default size */
669 screen = gtk_widget_get_screen (widget);
670 width = gdk_screen_get_width (screen) - external_border * 2;
671 gtk_window_set_default_size (GTK_WINDOW (widget), width, -1);
675 hildon_app_menu_style_set (GtkWidget *widget,
676 GtkStyle *previous_style)
678 if (GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->style_set)
679 GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->style_set (widget, previous_style);
681 hildon_app_menu_apply_style (widget);
685 hildon_app_menu_repack_filters (HildonAppMenu *menu)
687 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(menu);
690 for (iter = priv->filters; iter != NULL; iter = iter->next) {
691 GtkWidget *filter = GTK_WIDGET (iter->data);
692 GtkWidget *parent = gtk_widget_get_parent (filter);
694 g_object_ref (filter);
695 gtk_container_remove (GTK_CONTAINER (parent), filter);
699 for (iter = priv->filters; iter != NULL; iter = iter->next) {
700 GtkWidget *filter = GTK_WIDGET (iter->data);
701 if (GTK_WIDGET_VISIBLE (filter)) {
702 gtk_box_pack_start (GTK_BOX (priv->filters_hbox), filter, TRUE, TRUE, 0);
703 g_object_unref (filter);
709 * When items displayed in the menu change (e.g, a new item is added,
710 * an item is hidden or the list is reordered), the layout must be
711 * updated. To do this we repack all items starting from a given one.
714 hildon_app_menu_repack_items (HildonAppMenu *menu,
717 HildonAppMenuPrivate *priv;
721 priv = HILDON_APP_MENU_GET_PRIVATE(menu);
723 /* Remove buttons from their parent */
724 if (start_from != -1) {
725 for (iter = g_list_nth (priv->buttons, start_from); iter != NULL; iter = iter->next) {
726 GtkWidget *item = GTK_WIDGET (iter->data);
727 GtkWidget *parent = gtk_widget_get_parent (item);
730 gtk_container_remove (GTK_CONTAINER (parent), item);
734 /* If items have been removed, recalculate the size of the menu */
735 gtk_window_resize (GTK_WINDOW (menu), 1, 1);
740 for (iter = priv->buttons; iter != NULL; iter = iter->next) {
741 GtkWidget *item = GTK_WIDGET (iter->data);
742 if (GTK_WIDGET_VISIBLE (item)) {
743 /* Don't add an item to the table if it's already there */
744 if (gtk_widget_get_parent (item) == NULL) {
745 gtk_table_attach_defaults (priv->table, item, col, col + 1, row, row + 1);
746 g_object_unref (item);
748 if (++col == priv->columns) {
755 /* The number of rows/columns might have changed, so we have to
756 * resize the table */
758 gtk_table_resize (priv->table, MAX (row, 1), priv->columns);
760 gtk_table_resize (priv->table, row + 1, priv->columns);
763 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu))) {
764 gtk_window_reshow_with_initial_size (GTK_WINDOW (menu));
769 hildon_app_menu_init (HildonAppMenu *menu)
771 GtkWidget *alignment;
772 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(menu);
774 /* Initialize private variables */
775 priv->parent_window = NULL;
776 priv->transfer_window = NULL;
777 priv->pressed_outside = FALSE;
778 priv->buttons = NULL;
779 priv->filters = NULL;
782 /* Create boxes and tables */
783 priv->filters_hbox = GTK_BOX (gtk_hbox_new (TRUE, 0));
784 priv->vbox = GTK_BOX (gtk_vbox_new (FALSE, 0));
785 priv->table = GTK_TABLE (gtk_table_new (1, priv->columns, TRUE));
787 /* Align the filters to the center */
788 alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
789 gtk_container_add (GTK_CONTAINER (alignment), GTK_WIDGET (priv->filters_hbox));
791 /* Pack everything */
792 gtk_container_add (GTK_CONTAINER (menu), GTK_WIDGET (priv->vbox));
793 gtk_box_pack_start (priv->vbox, alignment, TRUE, TRUE, 0);
794 gtk_box_pack_start (priv->vbox, GTK_WIDGET (priv->table), TRUE, TRUE, 0);
796 /* Make menu a modal window */
797 gtk_window_set_modal (GTK_WINDOW (menu), TRUE);
799 /* This should be treated like a normal, ref-counted widget */
800 g_object_force_floating (G_OBJECT (menu));
801 GTK_WINDOW (menu)->has_user_ref_count = FALSE;
803 gtk_widget_show_all (GTK_WIDGET (priv->vbox));
807 hildon_app_menu_finalize (GObject *object)
809 HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(object);
811 if (priv->transfer_window)
812 gdk_window_destroy (priv->transfer_window);
814 g_list_foreach (priv->buttons, (GFunc) g_object_unref, NULL);
815 g_list_foreach (priv->filters, (GFunc) g_object_unref, NULL);
817 g_list_free (priv->buttons);
818 g_list_free (priv->filters);
820 g_signal_handlers_destroy (object);
821 G_OBJECT_CLASS (hildon_app_menu_parent_class)->finalize (object);
825 hildon_app_menu_class_init (HildonAppMenuClass *klass)
827 GObjectClass *gobject_class = (GObjectClass *)klass;
828 GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
830 gobject_class->finalize = hildon_app_menu_finalize;
831 widget_class->show = hildon_app_menu_show;
832 widget_class->map = hildon_app_menu_map;
833 widget_class->unmap = hildon_app_menu_unmap;
834 widget_class->realize = hildon_app_menu_realize;
835 widget_class->unrealize = hildon_app_menu_unrealize;
836 widget_class->key_press_event = hildon_app_menu_key_press;
837 widget_class->button_press_event = hildon_app_menu_button_press;
838 widget_class->button_release_event = hildon_app_menu_button_release;
839 widget_class->style_set = hildon_app_menu_style_set;
841 g_type_class_add_private (klass, sizeof (HildonAppMenuPrivate));
843 gtk_widget_class_install_style_property (
846 "horizontal-spacing",
847 "Horizontal spacing on menu items",
848 "Horizontal spacing between each menu item. Does not apply to filter buttons.",
852 gtk_widget_class_install_style_property (
856 "Vertical spacing on menu items",
857 "Vertical spacing between each menu item. Does not apply to filter buttons.",
861 gtk_widget_class_install_style_property (
865 "Border between menu edges and buttons",
866 "Border between menu edges and buttons",
870 gtk_widget_class_install_style_property (
874 "Border between menu and screen edges",
875 "Border between the right and left edges of the menu and the screen edges",