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.
23 #if defined (GDK_WINDOWING_X11)
25 #elif defined (GDK_WINDOWING_WIN32)
26 #include "win32/gdkwin32.h"
38 print_hello (GtkWidget *w,
44 g_message ("File New activated");
46 case ACTION_FILE_OPEN:
47 g_message ("File Open activated");
50 g_message ("OK activated");
52 case ACTION_HELP_ABOUT:
53 g_message ("Help About activated ");
56 g_assert_not_reached ();
62 remove_buttons (GtkWidget *widget, GtkWidget *other_button)
64 gtk_widget_destroy (other_button);
65 gtk_widget_destroy (widget);
69 blink_cb (gpointer data)
71 GtkWidget *widget = data;
73 gtk_widget_show (widget);
74 g_object_set_data (G_OBJECT (widget), "blink", NULL);
80 blink (GtkWidget *widget,
83 guint blink_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window), "blink"));
87 blink_timeout = gdk_threads_add_timeout (1000, blink_cb, window);
88 gtk_widget_hide (window);
90 g_object_set_data (G_OBJECT (window), "blink", GUINT_TO_POINTER (blink_timeout));
95 local_destroy (GtkWidget *window)
97 guint blink_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window), "blink"));
99 g_source_remove (blink_timeout);
103 remote_destroy (GtkWidget *window)
105 local_destroy (window);
110 add_buttons (GtkWidget *widget, GtkWidget *box)
112 GtkWidget *add_button;
113 GtkWidget *remove_button;
115 add_button = gtk_button_new_with_mnemonic ("_Add");
116 gtk_box_pack_start (GTK_BOX (box), add_button, TRUE, TRUE, 0);
117 gtk_widget_show (add_button);
119 g_signal_connect (add_button, "clicked",
120 G_CALLBACK (add_buttons),
123 remove_button = gtk_button_new_with_mnemonic ("_Remove");
124 gtk_box_pack_start (GTK_BOX (box), remove_button, TRUE, TRUE, 0);
125 gtk_widget_show (remove_button);
127 g_signal_connect (remove_button, "clicked",
128 G_CALLBACK (remove_buttons),
135 GtkComboBoxText *combo;
138 combo = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
140 gtk_combo_box_text_append_text (combo, "item0");
141 gtk_combo_box_text_append_text (combo, "item1 item1");
142 gtk_combo_box_text_append_text (combo, "item2 item2 item2");
143 gtk_combo_box_text_append_text (combo, "item3 item3 item3 item3");
144 gtk_combo_box_text_append_text (combo, "item4 item4 item4 item4 item4");
145 gtk_combo_box_text_append_text (combo, "item5 item5 item5 item5 item5 item5");
146 gtk_combo_box_text_append_text (combo, "item6 item6 item6 item6 item6");
147 gtk_combo_box_text_append_text (combo, "item7 item7 item7 item7");
148 gtk_combo_box_text_append_text (combo, "item8 item8 item8");
149 gtk_combo_box_text_append_text (combo, "item9 item9");
151 entry = gtk_bin_get_child (GTK_BIN (combo));
152 gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
153 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
155 return GTK_WIDGET (combo);
159 create_menubar (GtkWindow *window)
161 GtkAccelGroup *accel_group=NULL;
166 accel_group = gtk_accel_group_new ();
167 gtk_window_add_accel_group (window, accel_group);
169 menubar = gtk_menu_bar_new ();
171 menuitem = gtk_menu_item_new_with_mnemonic ("_File");
172 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
173 menu = gtk_menu_new ();
174 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
175 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_NEW, NULL);
176 g_signal_connect (menuitem, "activate", G_CALLBACK (print_hello), window);
177 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
178 menuitem = gtk_separator_menu_item_new ();
179 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
180 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT, NULL);
181 g_signal_connect (menuitem, "activate", G_CALLBACK (gtk_main_quit), window);
182 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
184 menuitem = gtk_menu_item_new_with_mnemonic ("O_K");
185 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
187 menuitem = gtk_menu_item_new_with_mnemonic ("_Help");
188 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
189 menu = gtk_menu_new ();
190 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
191 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
192 g_signal_connect (menuitem, "activate", G_CALLBACK (print_hello), window);
193 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
199 create_combo_box (void)
201 GtkComboBoxText *combo_box = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new ());
203 gtk_combo_box_text_append_text (combo_box, "This");
204 gtk_combo_box_text_append_text (combo_box, "Is");
205 gtk_combo_box_text_append_text (combo_box, "A");
206 gtk_combo_box_text_append_text (combo_box, "ComboBox");
208 return GTK_WIDGET (combo_box);
212 create_content (GtkWindow *window, gboolean local)
218 frame = gtk_frame_new (local? "Local" : "Remote");
219 gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
220 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
221 gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
222 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
224 gtk_container_add (GTK_CONTAINER (frame), vbox);
227 gtk_box_pack_start (GTK_BOX (vbox), create_combo(), TRUE, TRUE, 0);
230 gtk_box_pack_start (GTK_BOX (vbox), gtk_entry_new(), TRUE, TRUE, 0);
233 button = gtk_button_new_with_mnemonic ("_Close");
234 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
235 g_signal_connect_swapped (button, "clicked",
236 G_CALLBACK (gtk_widget_destroy), window);
239 button = gtk_button_new_with_mnemonic ("_Blink");
240 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
241 g_signal_connect (button, "clicked",
246 gtk_box_pack_start (GTK_BOX (vbox), create_menubar (GTK_WINDOW (window)),
250 gtk_box_pack_start (GTK_BOX (vbox), create_combo_box (), TRUE, TRUE, 0);
252 add_buttons (NULL, vbox);
258 create_child_plug (guint32 xid,
264 window = gtk_plug_new (xid);
266 g_signal_connect (window, "destroy",
267 local ? G_CALLBACK (local_destroy)
268 : G_CALLBACK (remote_destroy),
270 gtk_container_set_border_width (GTK_CONTAINER (window), 0);
272 content = create_content (GTK_WINDOW (window), local);
274 gtk_container_add (GTK_CONTAINER (window), content);
276 gtk_widget_show_all (window);
278 if (gtk_widget_get_realized (window))
279 #if defined (GDK_WINDOWING_X11)
280 return GDK_WINDOW_XID (gtk_widget_get_window (window));
281 #elif defined (GDK_WINDOWING_WIN32)
282 return (guint32) GDK_WINDOW_HWND (gtk_widget_get_window (window));