2 * This file is a part of hildon examples
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 HildonTextView *textview;
26 GtkTextBuffer *buffer;
29 set_text_button_clicked (GtkButton *button,
32 gtk_text_buffer_set_text (buffer, hildon_entry_get_text (entry), -1);
36 set_placeholder_button_clicked (GtkButton *button,
39 hildon_text_view_set_placeholder (textview, hildon_entry_get_text (entry));
43 text_changed (GtkTextBuffer *buffer,
47 GtkTextIter start, end;
49 gtk_text_buffer_get_start_iter (buffer, &start);
50 gtk_text_buffer_get_end_iter (buffer, &end);
52 text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
54 if (text != NULL && *text != '\0') {
55 gtk_label_set_text (label, text);
57 gtk_label_set_text (label, "(empty)");
67 GtkWidget *textentry, *textbutton, *texthbox;
68 GtkWidget *placeholderentry, *placeholderbutton, *placeholderhbox;
69 GtkWidget *textviewframe;
72 gtk_init (&argc, &argv);
74 /* Style to paint the placeholder text in red */
75 gtk_rc_parse_string ("style \"placeholder\" {\n"
76 "text[NORMAL] = \"#C03030\""
78 "widget \"*.hildon-text-view-placeholder\" style \"placeholder\"\n");
80 /* Window and vbox to pack everything */
81 win = hildon_stackable_window_new ();
82 vbox = GTK_BOX (gtk_vbox_new (FALSE, 10));
84 /* Entry to modify the text of the main HildonEntry */
85 textentry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
86 textbutton = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
87 gtk_button_set_label (GTK_BUTTON (textbutton), "Set text view text");
88 texthbox = gtk_hbox_new (FALSE, 10);
90 /* Entry to modify the placeholder of the main HildonEntry */
91 placeholderentry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
92 placeholderbutton = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
93 gtk_button_set_label (GTK_BUTTON (placeholderbutton), "Set text view placeholder");
94 placeholderhbox = gtk_hbox_new (FALSE, 10);
97 textview = HILDON_TEXT_VIEW (hildon_text_view_new ());
98 buffer = hildon_text_view_get_buffer (textview);
99 hildon_text_view_set_placeholder (textview, "This is a placeholder - change using the buttons above");
100 textviewframe = gtk_frame_new (NULL);
102 /* This label is used to show the contents -not the placeholder- of the HildonTextView */
103 label = gtk_label_new (NULL);
105 /* Pack all widgets */
106 gtk_box_pack_start (GTK_BOX (texthbox), textentry, TRUE, TRUE, 0);
107 gtk_box_pack_start (GTK_BOX (texthbox), textbutton, FALSE, FALSE, 0);
109 gtk_box_pack_start (GTK_BOX (placeholderhbox), placeholderentry, TRUE, TRUE, 0);
110 gtk_box_pack_start (GTK_BOX (placeholderhbox), placeholderbutton, FALSE, FALSE, 0);
112 gtk_container_add (GTK_CONTAINER (textviewframe), GTK_WIDGET (textview));
114 gtk_box_pack_start (vbox, texthbox, FALSE, FALSE, 0);
115 gtk_box_pack_start (vbox, placeholderhbox, FALSE, FALSE, 0);
116 gtk_box_pack_start (vbox, textviewframe, TRUE, TRUE, 0);
117 gtk_box_pack_start (vbox, gtk_label_new ("Contents of the text view:"), TRUE, TRUE, 0);
118 gtk_box_pack_start (vbox, label, TRUE, TRUE, 0);
120 gtk_container_set_border_width (GTK_CONTAINER (win), 20);
121 gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
123 /* Connect signals */
124 g_signal_connect (win, "destroy", G_CALLBACK (gtk_main_quit), NULL);
125 g_signal_connect (buffer, "changed", G_CALLBACK (text_changed), label);
126 g_signal_connect (textbutton, "clicked",
127 G_CALLBACK (set_text_button_clicked), textentry);
128 g_signal_connect (placeholderbutton, "clicked",
129 G_CALLBACK (set_placeholder_button_clicked), placeholderentry);
131 /* Set the initial state of the label */
132 text_changed (buffer, GTK_LABEL (label));
135 gtk_widget_show_all (win);