* examples/hildon-app-menu-example.c (create_menu): * examples/hildon-hvolumebar...
[hildon] / examples / hildon-app-menu-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
6  * Author: Karl Lattimer <karl.lattimer@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 #include                                        <gtk/gtk.h>
26 #include                                        <hildon-app-menu.h>
27
28 static void
29 menu_button_clicked                             (GtkButton *button,
30                                                  GtkLabel *label)
31 {
32     const char *buttontext = gtk_button_get_label (button);
33     char *text = g_strdup_printf("Last button clicked:\n%s", buttontext);
34     gtk_label_set_text (label, text);
35     g_free (text);
36 }
37
38 static HildonAppMenu *
39 create_menu                                     (GtkWidget *label)
40 {
41     GtkWidget *button;
42     HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ());
43
44     /* Options */
45     button = gtk_button_new_with_label ("Menu command one");
46     g_signal_connect (button, "clicked", G_CALLBACK (menu_button_clicked), label);
47     hildon_app_menu_append (menu, GTK_BUTTON (button));
48
49     button = gtk_button_new_with_label ("Menu command two");
50     g_signal_connect (button, "clicked", G_CALLBACK (menu_button_clicked), label);
51     hildon_app_menu_append (menu, GTK_BUTTON (button));
52
53     button = gtk_button_new_with_label ("Menu command three");
54     g_signal_connect (button, "clicked", G_CALLBACK (menu_button_clicked), label);
55     hildon_app_menu_append (menu, GTK_BUTTON (button));
56
57     button = gtk_button_new_with_label ("Menu command four");
58     g_signal_connect (button, "clicked", G_CALLBACK (menu_button_clicked), label);
59     hildon_app_menu_append (menu, GTK_BUTTON (button));
60
61     button = gtk_button_new_with_label ("Menu command five");
62     g_signal_connect (button, "clicked", G_CALLBACK (menu_button_clicked), label);
63     hildon_app_menu_append (menu, GTK_BUTTON (button));
64
65     /* Filters */
66     button = gtk_radio_button_new_with_label (NULL, "filter one");
67     g_signal_connect (button, "clicked", G_CALLBACK (menu_button_clicked), label);
68     hildon_app_menu_add_filter (menu, GTK_BUTTON (button));
69     gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
70
71     button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (button), "filter two");
72     g_signal_connect (button, "clicked", G_CALLBACK (menu_button_clicked), label);
73     hildon_app_menu_add_filter (menu, GTK_BUTTON (button));
74     gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
75
76     return menu;
77 }
78
79 static void
80 button_clicked                                  (GtkButton *button,
81                                                  HildonAppMenu *menu)
82 {
83     gtk_widget_show (GTK_WIDGET (menu));
84 }
85
86 static void
87 close_app                                       (GtkWidget *widget,
88                                                  GdkEvent  *event,
89                                                  GtkWidget *menu)
90 {
91     gtk_widget_destroy (GTK_WIDGET (menu));
92     gtk_main_quit ();
93 }
94
95 int
96 main                                            (int argc,
97                                                  char **argv)
98 {
99     GtkWidget *win;
100     GtkWidget *button;
101     GtkWidget *label;
102     GtkWidget *label2;
103     GtkBox *vbox;
104     HildonAppMenu *menu;
105
106     gtk_init (&argc, &argv);
107
108     gtk_rc_parse_string ("style \"default\" {\n"
109                          "bg[NORMAL] = \"#505050\""
110                          "}\n"
111                          "class \"HildonAppMenu\" style \"default\"\n");
112
113     button = gtk_button_new_with_label ("Press me");
114     label = gtk_label_new ("This is an example of the\nHildonAppMenu widget");
115     label2 = gtk_label_new ("No button has been clicked");
116     vbox = GTK_BOX (gtk_vbox_new (FALSE, 10));
117     win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
118
119     menu = create_menu (label2);
120
121     gtk_box_pack_start (vbox, label, TRUE, TRUE, 0);
122     gtk_box_pack_start (vbox, button, TRUE, TRUE, 0);
123     gtk_box_pack_start (vbox, label2, TRUE, TRUE, 0);
124
125     gtk_container_set_border_width (GTK_CONTAINER (win), 20);
126     gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
127
128     g_signal_connect (button, "clicked", G_CALLBACK(button_clicked), menu);
129     g_signal_connect (win, "delete_event", G_CALLBACK(close_app), menu);
130
131     gtk_widget_show_all (win);
132
133     gtk_main ();
134
135     return 0;
136 }