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 HildonSizeType buttonsize = HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH;
45 HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ());
48 button = hildon_gtk_button_new (buttonsize);
49 gtk_button_set_label (GTK_BUTTON (button), "Menu command one");
50 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
51 hildon_app_menu_append (menu, GTK_BUTTON (button));
53 gtk_widget_add_accelerator (button, "activate", accel, GDK_r, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
55 button = hildon_gtk_button_new (buttonsize);
56 gtk_button_set_label (GTK_BUTTON (button), "Menu command two");
57 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
58 hildon_app_menu_append (menu, GTK_BUTTON (button));
60 button = hildon_gtk_button_new (buttonsize);
61 gtk_button_set_label (GTK_BUTTON (button), "Menu command three");
62 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
63 hildon_app_menu_append (menu, GTK_BUTTON (button));
65 button = hildon_gtk_button_new (buttonsize);
66 gtk_button_set_label (GTK_BUTTON (button), "Menu command four");
67 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
68 hildon_app_menu_append (menu, GTK_BUTTON (button));
70 button = hildon_gtk_button_new (buttonsize);
71 gtk_button_set_label (GTK_BUTTON (button), "Menu command five");
72 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
73 hildon_app_menu_append (menu, GTK_BUTTON (button));
76 button = hildon_gtk_radio_button_new (buttonsize, NULL);
77 gtk_button_set_label (GTK_BUTTON (button), "filter one");
78 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
79 hildon_app_menu_add_filter (menu, GTK_BUTTON (button));
80 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
82 button = hildon_gtk_radio_button_new_from_widget (buttonsize, GTK_RADIO_BUTTON (button));
83 gtk_button_set_label (GTK_BUTTON (button), "filter two");
84 g_signal_connect_after (button, "clicked", G_CALLBACK (menu_button_clicked), label);
85 hildon_app_menu_add_filter (menu, GTK_BUTTON (button));
86 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
88 gtk_widget_show_all (GTK_WIDGET (menu));
102 GtkAccelGroup *accel;
104 hildon_gtk_init (&argc, &argv);
106 label = gtk_label_new ("This is an example of the\nHildonAppMenu widget.\n\n"
107 "Click on the titlebar\nto pop up the menu.");
108 label2 = gtk_label_new ("No menu option has been selected yet.");
110 accel = gtk_accel_group_new ();
112 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
113 gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_CENTER);
115 vbox = GTK_BOX (gtk_vbox_new (FALSE, 10));
116 win = hildon_stackable_window_new ();
118 menu = create_menu (label2, accel);
120 hildon_window_set_app_menu (HILDON_WINDOW (win), menu);
122 gtk_window_add_accel_group (GTK_WINDOW (win), accel);
123 g_object_unref (accel);
125 gtk_box_pack_start (vbox, label, TRUE, TRUE, 0);
126 gtk_box_pack_start (vbox, label2, TRUE, TRUE, 0);
128 gtk_container_set_border_width (GTK_CONTAINER (win), 20);
129 gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
131 g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
133 gtk_widget_show_all (win);