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, see <http://www.gnu.org/licenses/>.
21 #if defined (GDK_WINDOWING_X11)
23 #elif defined (GDK_WINDOWING_WIN32)
24 #include "win32/gdkwin32.h"
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 ();
60 remove_buttons (GtkWidget *widget, GtkWidget *other_button)
62 gtk_widget_destroy (other_button);
63 gtk_widget_destroy (widget);
67 blink_cb (gpointer data)
69 GtkWidget *widget = data;
71 gtk_widget_show (widget);
72 g_object_set_data (G_OBJECT (widget), "blink", NULL);
78 blink (GtkWidget *widget,
81 guint blink_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window), "blink"));
85 blink_timeout = gdk_threads_add_timeout (1000, blink_cb, window);
86 gtk_widget_hide (window);
88 g_object_set_data (G_OBJECT (window), "blink", GUINT_TO_POINTER (blink_timeout));
93 local_destroy (GtkWidget *window)
95 guint blink_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window), "blink"));
97 g_source_remove (blink_timeout);
101 remote_destroy (GtkWidget *window)
103 local_destroy (window);
108 add_buttons (GtkWidget *widget, GtkWidget *box)
110 GtkWidget *add_button;
111 GtkWidget *remove_button;
113 add_button = gtk_button_new_with_mnemonic ("_Add");
114 gtk_box_pack_start (GTK_BOX (box), add_button, TRUE, TRUE, 0);
115 gtk_widget_show (add_button);
117 g_signal_connect (add_button, "clicked",
118 G_CALLBACK (add_buttons),
121 remove_button = gtk_button_new_with_mnemonic ("_Remove");
122 gtk_box_pack_start (GTK_BOX (box), remove_button, TRUE, TRUE, 0);
123 gtk_widget_show (remove_button);
125 g_signal_connect (remove_button, "clicked",
126 G_CALLBACK (remove_buttons),
133 GtkComboBoxText *combo;
136 combo = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
138 gtk_combo_box_text_append_text (combo, "item0");
139 gtk_combo_box_text_append_text (combo, "item1 item1");
140 gtk_combo_box_text_append_text (combo, "item2 item2 item2");
141 gtk_combo_box_text_append_text (combo, "item3 item3 item3 item3");
142 gtk_combo_box_text_append_text (combo, "item4 item4 item4 item4 item4");
143 gtk_combo_box_text_append_text (combo, "item5 item5 item5 item5 item5 item5");
144 gtk_combo_box_text_append_text (combo, "item6 item6 item6 item6 item6");
145 gtk_combo_box_text_append_text (combo, "item7 item7 item7 item7");
146 gtk_combo_box_text_append_text (combo, "item8 item8 item8");
147 gtk_combo_box_text_append_text (combo, "item9 item9");
149 entry = gtk_bin_get_child (GTK_BIN (combo));
150 gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
151 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
153 return GTK_WIDGET (combo);
157 create_menubar (GtkWindow *window)
159 GtkAccelGroup *accel_group=NULL;
164 accel_group = gtk_accel_group_new ();
165 gtk_window_add_accel_group (window, accel_group);
167 menubar = gtk_menu_bar_new ();
169 menuitem = gtk_menu_item_new_with_mnemonic ("_File");
170 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
171 menu = gtk_menu_new ();
172 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
173 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_NEW, NULL);
174 g_signal_connect (menuitem, "activate", G_CALLBACK (print_hello), window);
175 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
176 menuitem = gtk_separator_menu_item_new ();
177 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
178 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT, NULL);
179 g_signal_connect (menuitem, "activate", G_CALLBACK (gtk_main_quit), window);
180 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
182 menuitem = gtk_menu_item_new_with_mnemonic ("O_K");
183 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
185 menuitem = gtk_menu_item_new_with_mnemonic ("_Help");
186 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
187 menu = gtk_menu_new ();
188 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
189 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
190 g_signal_connect (menuitem, "activate", G_CALLBACK (print_hello), window);
191 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
197 create_combo_box (void)
199 GtkComboBoxText *combo_box = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new ());
201 gtk_combo_box_text_append_text (combo_box, "This");
202 gtk_combo_box_text_append_text (combo_box, "Is");
203 gtk_combo_box_text_append_text (combo_box, "A");
204 gtk_combo_box_text_append_text (combo_box, "ComboBox");
206 return GTK_WIDGET (combo_box);
210 create_content (GtkWindow *window, gboolean local)
216 frame = gtk_frame_new (local? "Local" : "Remote");
217 gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
218 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
219 gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
220 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
222 gtk_container_add (GTK_CONTAINER (frame), vbox);
225 gtk_box_pack_start (GTK_BOX (vbox), create_combo(), TRUE, TRUE, 0);
228 gtk_box_pack_start (GTK_BOX (vbox), gtk_entry_new(), TRUE, TRUE, 0);
231 button = gtk_button_new_with_mnemonic ("_Close");
232 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
233 g_signal_connect_swapped (button, "clicked",
234 G_CALLBACK (gtk_widget_destroy), window);
237 button = gtk_button_new_with_mnemonic ("_Blink");
238 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
239 g_signal_connect (button, "clicked",
244 gtk_box_pack_start (GTK_BOX (vbox), create_menubar (GTK_WINDOW (window)),
248 gtk_box_pack_start (GTK_BOX (vbox), create_combo_box (), TRUE, TRUE, 0);
250 add_buttons (NULL, vbox);
256 create_child_plug (guint32 xid,
262 window = gtk_plug_new (xid);
264 g_signal_connect (window, "destroy",
265 local ? G_CALLBACK (local_destroy)
266 : G_CALLBACK (remote_destroy),
268 gtk_container_set_border_width (GTK_CONTAINER (window), 0);
270 content = create_content (GTK_WINDOW (window), local);
272 gtk_container_add (GTK_CONTAINER (window), content);
274 gtk_widget_show_all (window);
276 if (gtk_widget_get_realized (window))
277 #if defined (GDK_WINDOWING_X11)
278 return GDK_WINDOW_XID (gtk_widget_get_window (window));
279 #elif defined (GDK_WINDOWING_WIN32)
280 return (guint32) GDK_WINDOW_HWND (gtk_widget_get_window (window));
281 #elif defined (GDK_WINDOWING_BROADWAY)
282 return (guint32) 0; /* Child windows not supported */