2 * This file is a part of hildon examples
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Author: Karl Lattimer <karl.lattimer@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
29 menu_button_clicked (GtkButton *button,
32 const char *buttontext = gtk_button_get_label (button);
33 char *text = g_strdup_printf("Last option selected:\n%s", buttontext);
34 gtk_label_set_text (label, text);
36 g_debug ("Button clicked: %s", buttontext);
39 static HildonAppMenu *
40 create_menu (GtkWidget *label,
44 HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ());
47 button = gtk_button_new_with_label ("Menu command one");
48 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
49 hildon_app_menu_append (menu, GTK_BUTTON (button));
51 gtk_widget_add_accelerator (button, "activate", accel, GDK_r, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
53 button = gtk_button_new_with_label ("Menu command two");
54 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
55 hildon_app_menu_append (menu, GTK_BUTTON (button));
57 button = gtk_button_new_with_label ("Menu command three");
58 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
59 hildon_app_menu_append (menu, GTK_BUTTON (button));
61 button = gtk_button_new_with_label ("Menu command four");
62 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
63 hildon_app_menu_append (menu, GTK_BUTTON (button));
65 button = gtk_button_new_with_label ("Menu command five");
66 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
67 hildon_app_menu_append (menu, GTK_BUTTON (button));
70 button = gtk_radio_button_new_with_label (NULL, "filter one");
71 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
72 hildon_app_menu_add_filter (menu, GTK_BUTTON (button));
73 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
75 button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (button), "filter two");
76 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
77 hildon_app_menu_add_filter (menu, GTK_BUTTON (button));
78 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
94 gtk_init (&argc, &argv);
96 label = gtk_label_new ("This is an example of the\nHildonAppMenu widget.\n\n"
97 "Click on the titlebar\nto pop up the menu.");
98 label2 = gtk_label_new ("No menu option has been selected yet.");
100 accel = gtk_accel_group_new ();
102 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
103 gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_CENTER);
105 vbox = GTK_BOX (gtk_vbox_new (FALSE, 10));
106 win = hildon_stackable_window_new ();
108 menu = create_menu (label2, accel);
110 hildon_stackable_window_set_main_menu (HILDON_STACKABLE_WINDOW (win), menu);
112 gtk_window_add_accel_group (GTK_WINDOW (win), accel);
113 g_object_unref (accel);
115 gtk_box_pack_start (vbox, label, TRUE, TRUE, 0);
116 gtk_box_pack_start (vbox, label2, TRUE, TRUE, 0);
118 gtk_container_set_border_width (GTK_CONTAINER (win), 20);
119 gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
121 g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
123 gtk_widget_show_all (win);