Grabbed the focus in the HildonTextView button press callback
[hildon] / examples / hildon-picker-button-multicolumn-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 #include                                        <hildon/hildon.h>
20
21 static GtkWidget *
22 create_touch_selector (void)
23 {
24   GtkWidget *selector;
25   GtkListStore *model;
26   GtkTreeIter iter;
27   HildonTouchSelectorColumn *column = NULL;
28
29   selector = hildon_touch_selector_new ();
30
31   model = gtk_list_store_new (1, G_TYPE_STRING);
32
33   gtk_list_store_append (model, &iter);
34   gtk_list_store_set (model, &iter, 0, "IMAP", -1);
35
36   gtk_list_store_append (model, &iter);
37   gtk_list_store_set (model, &iter, 0, "IMAP4", -1);
38
39   gtk_list_store_append (model, &iter);
40   gtk_list_store_set (model, &iter, 0, "POP3", -1);
41
42   gtk_list_store_append (model, &iter);
43   gtk_list_store_set (model, &iter, 0, "Mailbox", -1);
44
45   column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
46                                                      GTK_TREE_MODEL (model), TRUE);
47   hildon_touch_selector_column_set_text_column (column, 0);
48
49   model = gtk_list_store_new (1, G_TYPE_STRING);
50
51   gtk_list_store_append (model, &iter);
52   gtk_list_store_set (model, &iter, 0, "SMTP", -1);
53
54   gtk_list_store_append (model, &iter);
55   gtk_list_store_set (model, &iter, 0, "SMTPS", -1);
56
57   gtk_list_store_append (model, &iter);
58   gtk_list_store_set (model, &iter, 0, "Smoke signals", -1);
59
60   column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
61                                                      GTK_TREE_MODEL (model), TRUE);
62   hildon_touch_selector_column_set_text_column (column, 0);
63   
64   return selector;
65 }
66
67 static void
68 on_picker_value_changed (HildonPickerButton * button, gpointer data)
69 {
70   g_print ("Newly selected value: %s\n",
71            hildon_button_get_value (HILDON_BUTTON (button)));
72 }
73
74 int
75 main (int argc, char **argv)
76 {
77   HildonProgram *program = NULL;
78   GtkWidget *window = NULL;
79   GtkWidget *button;
80   GtkWidget *selector;
81
82   hildon_gtk_init (&argc, &argv);
83
84   program = hildon_program_get_instance ();
85   g_set_application_name ("hildon-picker-button-example");
86
87   window = hildon_stackable_window_new ();
88   gtk_window_set_default_size (GTK_WINDOW (window), 300, 200);
89   hildon_program_add_window (program, HILDON_WINDOW (window));
90   selector = create_touch_selector ();
91
92   button = hildon_picker_button_new (HILDON_SIZE_AUTO, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
93   hildon_picker_button_set_done_button_text (HILDON_PICKER_BUTTON (button),
94                                              "We are done");
95
96   hildon_button_set_title (HILDON_BUTTON (button), "Protocol");
97   hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
98                                      HILDON_TOUCH_SELECTOR (selector));
99   g_signal_connect (G_OBJECT (button), "value-changed",
100                     G_CALLBACK (on_picker_value_changed), NULL);
101
102   gtk_container_add (GTK_CONTAINER (window), button);
103
104   gtk_widget_show_all (window);
105
106   g_signal_connect (G_OBJECT (window), "destroy",
107                     G_CALLBACK (gtk_main_quit), NULL);
108   gtk_widget_show_all (GTK_WIDGET (window));
109
110   gtk_main ();
111
112   return 0;
113 }