HildonTouchSelector documentation updates
[hildon] / examples / hildon-toolbar-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
5  *
6  * Author: Michael Dominic Kostrzewa <michael.kostrzewa@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                                        <stdio.h>
26 #include                                        <stdlib.h>
27 #include                                        <glib.h>
28 #include                                        <gtk/gtk.h>
29 #include                                        <hildon/hildon.h>
30
31 gboolean                                        has_toolbar = FALSE;
32
33 HildonWindow*                                   window = NULL;
34
35 GtkToolbar*                                     toolbar = NULL;
36
37 static gboolean
38 on_add_clicked                                  (GtkWidget *widget)
39 {
40     if (has_toolbar) 
41         hildon_banner_show_information (widget, NULL, "Toolbar already added"); 
42     else {
43         hildon_window_add_toolbar (window, toolbar);
44         has_toolbar = TRUE;
45     }
46
47     return TRUE;
48 }
49
50 static gboolean
51 on_remove_clicked                               (GtkWidget *widget)
52 {
53     if (! has_toolbar) 
54         hildon_banner_show_information (widget, NULL, "No toolbar added"); 
55     else {
56         g_object_ref (toolbar);
57         hildon_window_remove_toolbar (window, toolbar);
58         has_toolbar = FALSE;
59     }
60
61     return TRUE;
62 }
63
64 static gboolean
65 on_show_clicked                                 (GtkWidget *widget)
66 {
67     if (! has_toolbar) 
68         hildon_banner_show_information (widget, NULL, "No toolbar added"); 
69     else
70         gtk_widget_show_all (GTK_WIDGET (toolbar));
71
72     return TRUE;
73 }
74
75 static gboolean
76 on_hide_clicked                                 (GtkWidget *widget)
77 {
78     if (! has_toolbar) 
79         hildon_banner_show_information (widget, NULL, "No toolbar added"); 
80     else 
81         gtk_widget_hide_all (GTK_WIDGET (toolbar));
82
83     return TRUE;
84 }
85
86 int
87 main                                            (int argc,
88                                                  char **argv)
89 {
90     hildon_gtk_init (&argc, &argv);
91
92     HildonProgram *program = hildon_program_get_instance ();
93
94     window = HILDON_WINDOW (hildon_window_new ());
95     hildon_program_add_window (program, window);    
96     toolbar = GTK_TOOLBAR (hildon_find_toolbar_new ("Find"));
97
98     gtk_container_set_border_width (GTK_CONTAINER (window), 6);
99
100     GtkVBox *vbox = GTK_VBOX (gtk_vbox_new (6, FALSE));
101     
102     GtkButton *button1 = GTK_BUTTON (gtk_button_new_with_label ("Add toolbar"));
103     g_signal_connect (G_OBJECT (button1), "clicked", G_CALLBACK (on_add_clicked), NULL);
104
105     GtkButton *button2 = GTK_BUTTON (gtk_button_new_with_label ("Remove toolbar"));
106     g_signal_connect (G_OBJECT (button2), "clicked", G_CALLBACK (on_remove_clicked), NULL);
107
108     GtkButton *button3 = GTK_BUTTON (gtk_button_new_with_label ("Show toolbar"));
109     g_signal_connect (G_OBJECT (button3), "clicked", G_CALLBACK (on_show_clicked), NULL);
110
111     GtkButton *button4 = GTK_BUTTON (gtk_button_new_with_label ("Hide toolbar"));
112     g_signal_connect (G_OBJECT (button4), "clicked", G_CALLBACK (on_hide_clicked), NULL);
113
114     g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
115
116     gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button1), TRUE, TRUE, 0);
117     gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button2), TRUE, TRUE, 0);
118     gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button3), TRUE, TRUE, 0);
119     gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button4), TRUE, TRUE, 0);
120     gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox));
121
122     gtk_widget_show_all (GTK_WIDGET (window));
123     
124     gtk_main ();
125     return 0;
126 }
127
128