2008-10-13 Alberto Garcia <agarcia@igalia.com>
[hildon] / src / hildon-app-menu.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Karl Lattimer <karl.lattimer@nokia.com>
7  *
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.
11  *
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.
16  *
17  */
18
19 /**
20  * SECTION:hildon-app-menu
21  * @short_description: Widget representing the application menu in the Hildon framework.
22  *
23  * The #HildonAppMenu is a GTK widget which represents an application
24  * menu in the Hildon framework.
25  *
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
30  * to bottom.
31  *
32  * Besides that, the #HildonAppMenu can contain a group of filter buttons
33  * (#GtkToggleButton or #GtkRadioButton).
34  *
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().
39  *
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.
45  *
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.
50  *
51  * <example>
52  * <title>Creating a HildonAppMenu</title>
53  * <programlisting>
54  * HildonStackableWindow *win;
55  * HildonAppMenu *menu;
56  * GtkWidget *button;
57  * GtkWidget *filter;
58  * <!-- -->
59  * win = HILDON_STACKABLE_WINDOW (hildon_stackable_window_new ());
60  * menu = HILDON_APP_MENU (hildon_app_menu_new ());
61  * <!-- -->
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  * <!-- -->
67  * // Another button
68  * button = gtk_button_new_with_label ("Menu command two");
69  * g_signal_connect_after (button, "clicked", G_CALLBACK (button_two_clicked), userdata);
70  * hildon_app_menu_append (menu, GTK_BUTTON (button));
71  * <!-- -->
72  * // Create a filter and add it to the menu
73  * filter = gtk_radio_button_new_with_label (NULL, "Filter one");
74  * gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (filter), FALSE);
75  * g_signal_connect_after (filter, "clicked", G_CALLBACK (filter_one_clicked), userdata);
76  * hildon_app_menu_add_filter (menu, GTK_BUTTON (filter));
77  * <!-- -->
78  * // Add a new filter
79  * filter = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (filter), "Filter two");
80  * gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (filter), FALSE);
81  * g_signal_connect_after (filter, "clicked", G_CALLBACK (filter_two_clicked), userdata);
82  * hildon_app_menu_add_filter (menu, GTK_BUTTON (filter));
83  * <!-- -->
84  * // Add the menu to the window
85  * hildon_stackable_window_set_main_menu (win, menu);
86  * </programlisting>
87  * </example>
88  *
89  */
90
91 #include                                        <string.h>
92 #include                                        <X11/Xatom.h>
93 #include                                        <gdk/gdkx.h>
94
95 #include                                        "hildon-app-menu.h"
96 #include                                        "hildon-app-menu-private.h"
97
98 static GdkWindow *
99 grab_transfer_window_get                        (GtkWidget *widget);
100
101 static void
102 hildon_app_menu_repack_items                    (HildonAppMenu *menu,
103                                                  gint           start_from);
104
105 static void
106 hildon_app_menu_repack_filters                  (HildonAppMenu *menu);
107
108 static void
109 item_visibility_changed                         (GtkWidget     *item,
110                                                  GParamSpec    *arg1,
111                                                  HildonAppMenu *menu);
112
113 static void
114 filter_visibility_changed                       (GtkWidget     *item,
115                                                  GParamSpec    *arg1,
116                                                  HildonAppMenu *menu);
117
118 static void
119 remove_item_from_list                           (GList    **list,
120                                                  gpointer   item);
121
122 static void
123 hildon_app_menu_apply_style                     (GtkWidget *widget);
124
125 G_DEFINE_TYPE (HildonAppMenu, hildon_app_menu, GTK_TYPE_WINDOW);
126
127 /**
128  * hildon_app_menu_new:
129  *
130  * Creates a new #HildonAppMenu.
131  *
132  * Return value: A #HildonAppMenu.
133  **/
134 GtkWidget *
135 hildon_app_menu_new                             (void)
136 {
137     GtkWidget *menu = g_object_new (HILDON_TYPE_APP_MENU, NULL);
138     return menu;
139 }
140
141 /**
142  * hildon_app_menu_insert:
143  * @menu : A #HildonAppMenu
144  * @item : A #GtkButton to add to the #HildonAppMenu
145  * @position : The position in the item list where @item is added (from 0 to n-1).
146  *
147  * Adds @item to @menu at the position indicated by @position.
148  */
149 void
150 hildon_app_menu_insert                          (HildonAppMenu *menu,
151                                                  GtkButton     *item,
152                                                  gint           position)
153 {
154     HildonAppMenuPrivate *priv;
155
156     g_return_if_fail (HILDON_IS_APP_MENU (menu));
157     g_return_if_fail (GTK_IS_BUTTON (item));
158
159     priv = menu->priv;
160
161     /* Add the item to the menu */
162     gtk_widget_show (GTK_WIDGET (item));
163     g_object_ref_sink (item);
164     priv->buttons = g_list_insert (priv->buttons, item, position);
165     hildon_app_menu_repack_items (menu, position);
166
167     /* Close the menu when the button is clicked */
168     g_signal_connect_swapped (item, "clicked", G_CALLBACK (gtk_widget_hide), menu);
169     g_signal_connect (item, "notify::visible", G_CALLBACK (item_visibility_changed), menu);
170
171     /* Remove item from list when it is destroyed */
172     g_object_weak_ref (G_OBJECT (item), (GWeakNotify) remove_item_from_list, &(priv->buttons));
173 }
174
175 /**
176  * hildon_app_menu_append:
177  * @menu : A #HildonAppMenu
178  * @item : A #GtkButton to add to the #HildonAppMenu
179  *
180  * Adds @item to the end of the menu's item list.
181  */
182 void
183 hildon_app_menu_append                          (HildonAppMenu *menu,
184                                                  GtkButton     *item)
185 {
186     hildon_app_menu_insert (menu, item, -1);
187 }
188
189 /**
190  * hildon_app_menu_prepend:
191  * @menu : A #HildonAppMenu
192  * @item : A #GtkButton to add to the #HildonAppMenu
193  *
194  * Adds @item to the beginning of the menu's item list.
195  */
196 void
197 hildon_app_menu_prepend                         (HildonAppMenu *menu,
198                                                  GtkButton     *item)
199 {
200     hildon_app_menu_insert (menu, item, 0);
201 }
202
203 /**
204  * hildon_app_menu_reorder_child:
205  * @menu : A #HildonAppMenu
206  * @item : A #GtkButton to move
207  * @position : The new position to place @item (from 0 to n-1).
208  *
209  * Moves a #GtkButton to a new position within #HildonAppMenu.
210  */
211 void
212 hildon_app_menu_reorder_child                   (HildonAppMenu *menu,
213                                                  GtkButton     *item,
214                                                  gint           position)
215 {
216     HildonAppMenuPrivate *priv;
217     gint old_position;
218
219     g_return_if_fail (HILDON_IS_APP_MENU (menu));
220     g_return_if_fail (GTK_IS_BUTTON (item));
221     g_return_if_fail (position >= 0);
222
223     priv = menu->priv;
224     old_position = g_list_index (priv->buttons, item);
225
226     g_return_if_fail (old_position >= 0);
227
228     /* Move the item */
229     priv->buttons = g_list_remove (priv->buttons, item);
230     priv->buttons = g_list_insert (priv->buttons, item, position);
231
232     hildon_app_menu_repack_items (menu, MIN (old_position, position));
233 }
234
235 /**
236  * hildon_app_menu_add_filter:
237  * @menu : A #HildonAppMenu
238  * @filter : A #GtkButton to add to the #HildonAppMenu.
239  *
240  * Adds the @filter to @menu.
241  */
242 void
243 hildon_app_menu_add_filter                      (HildonAppMenu *menu,
244                                                  GtkButton *filter)
245 {
246     HildonAppMenuPrivate *priv;
247
248     g_return_if_fail (HILDON_IS_APP_MENU (menu));
249     g_return_if_fail (GTK_IS_BUTTON (filter));
250
251     priv = menu->priv;
252
253     /* Add the filter to the menu */
254     gtk_widget_show (GTK_WIDGET (filter));
255     g_object_ref_sink (filter);
256     priv->filters = g_list_append (priv->filters, filter);
257     hildon_app_menu_repack_filters (menu);
258
259     /* Close the menu when the button is clicked */
260     g_signal_connect_swapped (filter, "clicked", G_CALLBACK (gtk_widget_hide), menu);
261     g_signal_connect (filter, "notify::visible", G_CALLBACK (filter_visibility_changed), menu);
262
263     /* Remove filter from list when it is destroyed */
264     g_object_weak_ref (G_OBJECT (filter), (GWeakNotify) remove_item_from_list, &(priv->filters));
265 }
266
267 static void
268 hildon_app_menu_set_columns                     (HildonAppMenu *menu,
269                                                  guint          columns)
270 {
271     HildonAppMenuPrivate *priv;
272
273     g_return_if_fail (HILDON_IS_APP_MENU (menu));
274     g_return_if_fail (columns > 0);
275
276     priv = menu->priv;
277
278     if (columns != priv->columns) {
279         priv->columns = columns;
280         hildon_app_menu_repack_items (menu, 0);
281     }
282 }
283
284 static void
285 screen_size_changed                            (GdkScreen     *screen,
286                                                 HildonAppMenu *menu)
287 {
288     hildon_app_menu_apply_style (GTK_WIDGET (menu));
289
290     if (gdk_screen_get_width (screen) > gdk_screen_get_height (screen)) {
291         hildon_app_menu_set_columns (menu, 2);
292     } else {
293         hildon_app_menu_set_columns (menu, 1);
294     }
295 }
296
297 static void
298 item_visibility_changed                         (GtkWidget     *item,
299                                                  GParamSpec    *arg1,
300                                                  HildonAppMenu *menu)
301 {
302     hildon_app_menu_repack_items (menu, g_list_index (menu->priv->buttons, item));
303 }
304
305 static void
306 filter_visibility_changed                       (GtkWidget     *item,
307                                                  GParamSpec    *arg1,
308                                                  HildonAppMenu *menu)
309 {
310     hildon_app_menu_repack_filters (menu);
311 }
312
313 static void
314 remove_item_from_list                           (GList    **list,
315                                                  gpointer   item)
316 {
317     *list = g_list_remove (*list, item);
318 }
319
320 static void
321 hildon_app_menu_map                             (GtkWidget *widget)
322 {
323     HildonAppMenuPrivate *priv = HILDON_APP_MENU (widget)->priv;
324
325     GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->map (widget);
326
327     /* Grab pointer and keyboard */
328     if (priv->transfer_window == NULL) {
329         gboolean has_grab = FALSE;
330
331         priv->transfer_window = grab_transfer_window_get (widget);
332
333         if (gdk_pointer_grab (priv->transfer_window, TRUE,
334                               GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
335                               GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
336                               GDK_POINTER_MOTION_MASK, NULL, NULL,
337                               GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS) {
338             if (gdk_keyboard_grab (priv->transfer_window, TRUE,
339                                    GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS) {
340                 has_grab = TRUE;
341             } else {
342                 gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
343                                             GDK_CURRENT_TIME);
344             }
345         }
346
347         if (has_grab) {
348             gtk_grab_add (widget);
349         } else {
350             gdk_window_destroy (priv->transfer_window);
351             priv->transfer_window = NULL;
352         }
353     }
354 }
355
356 static void
357 hildon_app_menu_unmap                           (GtkWidget *widget)
358 {
359     HildonAppMenuPrivate *priv = HILDON_APP_MENU (widget)->priv;
360
361     /* Remove the grab */
362     if (priv->transfer_window != NULL) {
363         gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
364                                     GDK_CURRENT_TIME);
365         gtk_grab_remove (widget);
366
367         gdk_window_destroy (priv->transfer_window);
368         priv->transfer_window = NULL;
369     }
370
371     GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->unmap (widget);
372 }
373
374 static gboolean
375 hildon_app_menu_button_press                    (GtkWidget *widget,
376                                                  GdkEventButton *event)
377 {
378     int x, y;
379     HildonAppMenuPrivate *priv = HILDON_APP_MENU (widget)->priv;
380
381     gdk_window_get_position (widget->window, &x, &y);
382
383     /* Whether the button has been pressed outside the widget */
384     priv->pressed_outside = (event->x_root < x || event->x_root > x + widget->allocation.width ||
385                              event->y_root < y || event->y_root > y + widget->allocation.height);
386
387     if (GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->button_press_event) {
388         return GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->button_press_event (widget, event);
389     } else {
390         return FALSE;
391     }
392 }
393
394 static gboolean
395 hildon_app_menu_button_release                  (GtkWidget *widget,
396                                                  GdkEventButton *event)
397 {
398     HildonAppMenuPrivate *priv = HILDON_APP_MENU (widget)->priv;
399
400     if (priv->pressed_outside) {
401         int x, y;
402         gboolean released_outside;
403
404         gdk_window_get_position (widget->window, &x, &y);
405
406         /* Whether the button has been released outside the widget */
407         released_outside = (event->x_root < x || event->x_root > x + widget->allocation.width ||
408                             event->y_root < y || event->y_root > y + widget->allocation.height);
409
410         if (released_outside) {
411             gtk_widget_hide (widget);
412         }
413
414         priv->pressed_outside = FALSE; /* Always reset pressed_outside to FALSE */
415     }
416
417     if (GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->button_release_event) {
418         return GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->button_release_event (widget, event);
419     } else {
420         return FALSE;
421     }
422 }
423
424 /* Grab transfer window (based on the one from GtkMenu) */
425 static GdkWindow *
426 grab_transfer_window_get                        (GtkWidget *widget)
427 {
428     GdkWindow *window;
429     GdkWindowAttr attributes;
430     gint attributes_mask;
431
432     attributes.x = 0;
433     attributes.y = 0;
434     attributes.width = 10;
435     attributes.height = 10;
436     attributes.window_type = GDK_WINDOW_TEMP;
437     attributes.wclass = GDK_INPUT_ONLY;
438     attributes.override_redirect = TRUE;
439     attributes.event_mask = 0;
440
441     attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
442
443     window = gdk_window_new (gtk_widget_get_root_window (widget),
444                                  &attributes, attributes_mask);
445     gdk_window_set_user_data (window, widget);
446
447     gdk_window_show (window);
448
449     return window;
450 }
451
452 static void
453 hildon_app_menu_realize                         (GtkWidget *widget)
454 {
455     GdkDisplay *display;
456     GdkScreen *screen;
457     Atom atom;
458     const gchar *notification_type = "_HILDON_WM_WINDOW_TYPE_APP_MENU";
459
460     GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->realize (widget);
461
462     gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER);
463
464     display = gdk_drawable_get_display (widget->window);
465     atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE");
466     XChangeProperty (GDK_WINDOW_XDISPLAY (widget->window), GDK_WINDOW_XID (widget->window),
467                      atom, XA_STRING, 8, PropModeReplace, (guchar *) notification_type,
468                      strlen (notification_type));
469
470     /* Detect any screen changes */
471     screen = gtk_widget_get_screen (widget);
472     g_signal_connect (screen, "size-changed", G_CALLBACK (screen_size_changed), widget);
473
474     /* Force menu to set the initial layout */
475     screen_size_changed (screen, HILDON_APP_MENU (widget));
476 }
477
478 static void
479 hildon_app_menu_unrealize                       (GtkWidget *widget)
480 {
481     GdkScreen *screen = gtk_widget_get_screen (widget);
482     /* Disconnect "size-changed" signal handler */
483     g_signal_handlers_disconnect_by_func (screen, G_CALLBACK (screen_size_changed), widget);
484
485     GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->unrealize (widget);
486 }
487
488 static void
489 hildon_app_menu_apply_style                     (GtkWidget *widget)
490 {
491     GdkScreen *screen;
492     gint width;
493     guint horizontal_spacing, vertical_spacing, inner_border, external_border;
494     HildonAppMenuPrivate *priv = HILDON_APP_MENU (widget)->priv;
495
496     gtk_widget_style_get (widget,
497                           "horizontal-spacing", &horizontal_spacing,
498                           "vertical-spacing", &vertical_spacing,
499                           "inner-border", &inner_border,
500                           "external-border", &external_border,
501                           NULL);
502
503     /* Set spacings */
504     gtk_table_set_row_spacings (priv->table, vertical_spacing);
505     gtk_table_set_col_spacings (priv->table, horizontal_spacing);
506     gtk_box_set_spacing (priv->vbox, vertical_spacing);
507
508     /* Set inner border */
509     gtk_container_set_border_width (GTK_CONTAINER (widget), inner_border);
510
511     /* Set default size */
512     screen = gtk_widget_get_screen (widget);
513     width = gdk_screen_get_width (screen) - external_border * 2;
514     gtk_window_set_default_size (GTK_WINDOW (widget), width, -1);
515 }
516
517 static void
518 hildon_app_menu_style_set                       (GtkWidget *widget,
519                                                  GtkStyle  *previous_style)
520 {
521     if (GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->style_set)
522         GTK_WIDGET_CLASS (hildon_app_menu_parent_class)->style_set (widget, previous_style);
523
524     hildon_app_menu_apply_style (widget);
525 }
526
527 static void
528 hildon_app_menu_repack_filters                  (HildonAppMenu *menu)
529 {
530     HildonAppMenuPrivate *priv = menu->priv;
531     GList *iter;
532
533     for (iter = priv->filters; iter != NULL; iter = iter->next) {
534         GtkWidget *filter = GTK_WIDGET (iter->data);
535         GtkWidget *parent = gtk_widget_get_parent (filter);
536         if (parent) {
537             g_object_ref (filter);
538             gtk_container_remove (GTK_CONTAINER (parent), filter);
539         }
540     }
541
542     for (iter = priv->filters; iter != NULL; iter = iter->next) {
543         GtkWidget *filter = GTK_WIDGET (iter->data);
544         if (GTK_WIDGET_VISIBLE (filter)) {
545             gtk_box_pack_start (GTK_BOX (priv->filters_hbox), filter, TRUE, TRUE, 0);
546             g_object_unref (filter);
547         }
548     }
549 }
550
551 /*
552  * When items displayed in the menu change (e.g, a new item is added,
553  * an item is hidden or the list is reordered), the layout must be
554  * updated. To do this we repack all items starting from a given one.
555  */
556 static void
557 hildon_app_menu_repack_items                    (HildonAppMenu *menu,
558                                                  gint           start_from)
559 {
560     HildonAppMenuPrivate *priv = menu->priv;
561     gint row, col;
562     GList *iter;
563
564     /* Remove buttons from their parent */
565     if (start_from != -1) {
566         for (iter = g_list_nth (priv->buttons, start_from); iter != NULL; iter = iter->next) {
567             GtkWidget *item = GTK_WIDGET (iter->data);
568             GtkWidget *parent = gtk_widget_get_parent (item);
569             if (parent) {
570                 g_object_ref (item);
571                 gtk_container_remove (GTK_CONTAINER (parent), item);
572             }
573         }
574
575         /* If items have been removed, recalculate the size of the menu */
576         gtk_window_resize (GTK_WINDOW (menu), 1, 1);
577     }
578
579     /* Add buttons */
580     row = col = 0;
581     for (iter = priv->buttons; iter != NULL; iter = iter->next) {
582         GtkWidget *item = GTK_WIDGET (iter->data);
583         if (GTK_WIDGET_VISIBLE (item)) {
584             /* Don't add an item to the table if it's already there */
585             if (gtk_widget_get_parent (item) == NULL) {
586                 gtk_table_attach_defaults (priv->table, item, col, col + 1, row, row + 1);
587                 g_object_unref (item);
588             }
589             if (++col == priv->columns) {
590                 col = 0;
591                 row++;
592             }
593         }
594     }
595
596     /* The number of rows/columns might have changed, so we have to
597      * resize the table */
598     if (col == 0) {
599         gtk_table_resize (priv->table, row, priv->columns);
600     } else {
601         gtk_table_resize (priv->table, row + 1, priv->columns);
602     }
603
604     if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu))) {
605         gtk_window_reshow_with_initial_size (GTK_WINDOW (menu));
606     }
607 }
608
609 static void
610 hildon_app_menu_init                            (HildonAppMenu *menu)
611 {
612     GtkWidget *alignment;
613     HildonAppMenuPrivate *priv = HILDON_APP_MENU_GET_PRIVATE(menu);
614
615     menu->priv = priv;
616
617     /* Initialize private variables */
618     priv->transfer_window = NULL;
619     priv->pressed_outside = FALSE;
620     priv->buttons = NULL;
621     priv->filters = NULL;
622     priv->columns = 2;
623
624     /* Create boxes and tables */
625     priv->filters_hbox = GTK_BOX (gtk_hbox_new (TRUE, 0));
626     priv->vbox = GTK_BOX (gtk_vbox_new (FALSE, 0));
627     priv->table = GTK_TABLE (gtk_table_new (1, priv->columns, TRUE));
628
629     /* Align the filters to the center */
630     alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
631     gtk_container_add (GTK_CONTAINER (alignment), GTK_WIDGET (priv->filters_hbox));
632
633     /* Pack everything */
634     gtk_container_add (GTK_CONTAINER (menu), GTK_WIDGET (priv->vbox));
635     gtk_box_pack_start (priv->vbox, alignment, TRUE, TRUE, 0);
636     gtk_box_pack_start (priv->vbox, GTK_WIDGET (priv->table), TRUE, TRUE, 0);
637
638     /* Make menu a modal window */
639     gtk_window_set_modal (GTK_WINDOW (menu), TRUE);
640
641     /* This should be treated like a normal, ref-counted widget */
642     g_object_force_floating (G_OBJECT (menu));
643     GTK_WINDOW (menu)->has_user_ref_count = FALSE;
644
645     gtk_widget_show_all (GTK_WIDGET (priv->vbox));
646 }
647
648 static void
649 hildon_app_menu_finalize                        (GObject *object)
650 {
651     HildonAppMenuPrivate *priv = HILDON_APP_MENU (object)->priv;
652
653     if (priv->transfer_window)
654         gdk_window_destroy (priv->transfer_window);
655
656     g_list_foreach (priv->buttons, (GFunc) g_object_unref, NULL);
657     g_list_foreach (priv->filters, (GFunc) g_object_unref, NULL);
658
659     g_list_free (priv->buttons);
660     g_list_free (priv->filters);
661
662     g_signal_handlers_destroy (object);
663     G_OBJECT_CLASS (hildon_app_menu_parent_class)->finalize (object);
664 }
665
666 static void
667 hildon_app_menu_class_init                      (HildonAppMenuClass *klass)
668 {
669     GObjectClass *gobject_class = (GObjectClass *)klass;
670     GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
671
672     gobject_class->finalize = hildon_app_menu_finalize;
673     widget_class->map = hildon_app_menu_map;
674     widget_class->unmap = hildon_app_menu_unmap;
675     widget_class->realize = hildon_app_menu_realize;
676     widget_class->unrealize = hildon_app_menu_unrealize;
677     widget_class->button_press_event = hildon_app_menu_button_press;
678     widget_class->button_release_event = hildon_app_menu_button_release;
679     widget_class->style_set = hildon_app_menu_style_set;
680
681     g_type_class_add_private (klass, sizeof (HildonAppMenuPrivate));
682
683     gtk_widget_class_install_style_property (
684         widget_class,
685         g_param_spec_uint (
686             "horizontal-spacing",
687             "Horizontal spacing on menu items",
688             "Horizontal spacing between each menu item. Does not apply to filter buttons.",
689             0, G_MAXUINT, 16,
690             G_PARAM_READABLE));
691
692     gtk_widget_class_install_style_property (
693         widget_class,
694         g_param_spec_uint (
695             "vertical-spacing",
696             "Vertical spacing on menu items",
697             "Vertical spacing between each menu item. Does not apply to filter buttons.",
698             0, G_MAXUINT, 16,
699             G_PARAM_READABLE));
700
701     gtk_widget_class_install_style_property (
702         widget_class,
703         g_param_spec_uint (
704             "inner-border",
705             "Border between menu edges and buttons",
706             "Border between menu edges and buttons",
707             0, G_MAXUINT, 16,
708             G_PARAM_READABLE));
709
710     gtk_widget_class_install_style_property (
711         widget_class,
712         g_param_spec_uint (
713             "external-border",
714             "Border between menu and screen edges",
715             "Border between the right and left edges of the menu and the screen edges",
716             0, G_MAXUINT, 40,
717             G_PARAM_READABLE));
718 }