2008-08-01 Claudio Saavedra <csaavedra@igalia.com>
[hildon] / examples / hildon-picker-button-example.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser Public License as published by
8  * the Free Software Foundation; version 2 of the license.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser Public License for more details.
14  *
15  */
16
17 #include <glib.h>
18 #include <gtk/gtk.h>
19
20 #include "hildon-program.h"
21 #include "hildon-stackable-window.h"
22
23 #include "hildon-picker-button.h"
24 #include "hildon-touch-selector.h"
25
26 static void
27 on_picker_value_changed (HildonPickerButton * button, gpointer data)
28 {
29   g_print ("Newly selected value: %s\n",
30            hildon_button_get_value (HILDON_BUTTON (button)));
31 }
32
33 int
34 main (int argc, char **args)
35 {
36   HildonProgram *program = NULL;
37   GtkWidget *window = NULL;
38   GtkWidget *button;
39   GtkWidget *selector;
40
41   gtk_init (&argc, &args);
42
43   program = hildon_program_get_instance ();
44   g_set_application_name ("hildon-picker-button-example");
45
46   window = hildon_stackable_window_new ();
47   gtk_window_set_default_size (GTK_WINDOW (window), 300, 200);
48   hildon_program_add_window (program, HILDON_WINDOW (window));
49
50   button = hildon_picker_button_new (HILDON_BUTTON_WITH_VERTICAL_VALUE);
51   selector = hildon_touch_selector_new_text ();
52   hildon_button_set_title (HILDON_BUTTON (button), "Continent");
53
54   hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "America");
55   hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Europe");
56   hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Asia");
57   hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), "Africa");
58   hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
59                                      "Australia");
60
61   hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
62                                      HILDON_TOUCH_SELECTOR (selector));
63
64   g_signal_connect (G_OBJECT (button), "value-changed",
65                     G_CALLBACK (on_picker_value_changed), NULL);
66
67   gtk_container_add (GTK_CONTAINER (window), button);
68
69   g_signal_connect (G_OBJECT (window), "delete-event", 
70                     G_CALLBACK (gtk_main_quit), NULL);
71
72   gtk_widget_show_all (window);
73
74   gtk_main ();
75
76   return 0;
77 }