2 * Copyright (C) 2001 Red Hat, Inc
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #undef GTK_DISABLE_DEPRECATED
36 print_hello (GtkWidget *w,
42 g_message ("File New activated");
44 case ACTION_FILE_OPEN:
45 g_message ("File Open activated");
48 g_message ("OK activated");
50 case ACTION_HELP_ABOUT:
51 g_message ("Help About activated ");
54 g_assert_not_reached ();
59 static GtkItemFactoryEntry menu_items[] = {
60 { "/_File", NULL, NULL, 0, "<Branch>" },
61 { "/File/_New", "<control>N", print_hello, ACTION_FILE_NEW, "<Item>" },
62 { "/File/_Open", "<control>O", print_hello, ACTION_FILE_OPEN, "<Item>" },
63 { "/File/sep1", NULL, NULL, 0, "<Separator>" },
64 { "/File/Quit", "<control>Q", gtk_main_quit, 0, "<Item>" },
65 { "/O_K", "<control>K",print_hello, ACTION_OK, "<Item>" },
66 { "/_Help", NULL, NULL, 0, "<LastBranch>" },
67 { "/_Help/About", NULL, print_hello, ACTION_HELP_ABOUT, "<Item>" },
71 remove_buttons (GtkWidget *widget, GtkWidget *other_button)
73 gtk_widget_destroy (other_button);
74 gtk_widget_destroy (widget);
78 blink_cb (gpointer data)
80 GtkWidget *widget = data;
82 gtk_widget_show (widget);
83 g_object_set_data (G_OBJECT (widget), "blink", NULL);
89 blink (GtkWidget *widget,
92 guint blink_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window), "blink"));
96 blink_timeout = g_timeout_add (1000, blink_cb, window);
97 gtk_widget_hide (window);
99 g_object_set_data (G_OBJECT (window), "blink", GUINT_TO_POINTER (blink_timeout));
104 local_destroy (GtkWidget *window)
106 guint blink_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window), "blink"));
108 g_source_remove (blink_timeout);
112 remote_destroy (GtkWidget *window)
114 local_destroy (window);
119 add_buttons (GtkWidget *widget, GtkWidget *box)
121 GtkWidget *add_button;
122 GtkWidget *remove_button;
124 add_button = gtk_button_new_with_mnemonic ("_Add");
125 gtk_box_pack_start (GTK_BOX (box), add_button, TRUE, TRUE, 0);
126 gtk_widget_show (add_button);
128 g_signal_connect (add_button, "clicked",
129 G_CALLBACK (add_buttons),
132 remove_button = gtk_button_new_with_mnemonic ("_Remove");
133 gtk_box_pack_start (GTK_BOX (box), remove_button, TRUE, TRUE, 0);
134 gtk_widget_show (remove_button);
136 g_signal_connect (remove_button, "clicked",
137 G_CALLBACK (remove_buttons),
148 cbitems = g_list_append (cbitems, "item0");
149 cbitems = g_list_append (cbitems, "item1 item1");
150 cbitems = g_list_append (cbitems, "item2 item2 item2");
151 cbitems = g_list_append (cbitems, "item3 item3 item3 item3");
152 cbitems = g_list_append (cbitems, "item4 item4 item4 item4 item4");
153 cbitems = g_list_append (cbitems, "item5 item5 item5 item5 item5 item5");
154 cbitems = g_list_append (cbitems, "item6 item6 item6 item6 item6");
155 cbitems = g_list_append (cbitems, "item7 item7 item7 item7");
156 cbitems = g_list_append (cbitems, "item8 item8 item8");
157 cbitems = g_list_append (cbitems, "item9 item9");
159 combo = GTK_COMBO (gtk_combo_new ());
160 gtk_combo_set_popdown_strings (combo, cbitems);
161 gtk_entry_set_text (GTK_ENTRY (combo->entry), "hello world");
162 gtk_editable_select_region (GTK_EDITABLE (combo->entry), 0, -1);
164 return GTK_WIDGET (combo);
168 create_menubar (GtkWindow *window)
170 GtkItemFactory *item_factory;
171 GtkAccelGroup *accel_group=NULL;
174 accel_group = gtk_accel_group_new ();
175 item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
177 gtk_item_factory_create_items (item_factory,
178 G_N_ELEMENTS (menu_items),
181 gtk_window_add_accel_group (window, accel_group);
182 menubar = gtk_item_factory_get_widget (item_factory, "<main>");
188 create_combo_box (void)
190 GtkComboBox *combo_box = GTK_COMBO_BOX (gtk_combo_box_new_text ());
192 gtk_combo_box_append_text (combo_box, "This");
193 gtk_combo_box_append_text (combo_box, "Is");
194 gtk_combo_box_append_text (combo_box, "A");
195 gtk_combo_box_append_text (combo_box, "ComboBox");
197 return GTK_WIDGET (combo_box);
201 create_content (GtkWindow *window, gboolean local)
207 frame = gtk_frame_new (local? "Local" : "Remote");
208 gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
209 vbox = gtk_vbox_new (TRUE, 0);
210 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
212 gtk_container_add (GTK_CONTAINER (frame), vbox);
215 gtk_box_pack_start (GTK_BOX (vbox), create_combo(), TRUE, TRUE, 0);
218 gtk_box_pack_start (GTK_BOX (vbox), gtk_entry_new(), TRUE, TRUE, 0);
221 button = gtk_button_new_with_mnemonic ("_Close");
222 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
223 g_signal_connect_swapped (button, "clicked",
224 G_CALLBACK (gtk_widget_destroy), window);
227 button = gtk_button_new_with_mnemonic ("_Blink");
228 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
229 g_signal_connect (button, "clicked",
234 gtk_box_pack_start (GTK_BOX (vbox), create_menubar (GTK_WINDOW (window)),
238 gtk_box_pack_start (GTK_BOX (vbox), create_combo_box (), TRUE, TRUE, 0);
240 add_buttons (NULL, vbox);
246 create_child_plug (guint32 xid,
252 window = gtk_plug_new (xid);
254 g_signal_connect (window, "destroy",
255 local ? G_CALLBACK (local_destroy)
256 : G_CALLBACK (remote_destroy),
258 gtk_container_set_border_width (GTK_CONTAINER (window), 0);
260 content = create_content (GTK_WINDOW (window), local);
262 gtk_container_add (GTK_CONTAINER (window), content);
264 gtk_widget_show_all (window);
266 if (GTK_WIDGET_REALIZED (window))
267 return GDK_WINDOW_XID (window->window);