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),
139 store = gtk_list_store_new (1, G_TYPE_STRING);
140 combo = g_object_new (GTK_TYPE_COMBO_BOX,
143 "entry-text-column", 0,
145 g_object_unref (store);
147 gtk_combo_box_append_text (combo, "item0");
148 gtk_combo_box_append_text (combo, "item1 item1");
149 gtk_combo_box_append_text (combo, "item2 item2 item2");
150 gtk_combo_box_append_text (combo, "item3 item3 item3 item3");
151 gtk_combo_box_append_text (combo, "item4 item4 item4 item4 item4");
152 gtk_combo_box_append_text (combo, "item5 item5 item5 item5 item5 item5");
153 gtk_combo_box_append_text (combo, "item6 item6 item6 item6 item6");
154 gtk_combo_box_append_text (combo, "item7 item7 item7 item7");
155 gtk_combo_box_append_text (combo, "item8 item8 item8");
156 gtk_combo_box_append_text (combo, "item9 item9");
158 entry = gtk_bin_get_child (GTK_BIN (combo));
159 gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
160 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
162 return GTK_WIDGET (combo);
166 create_menubar (GtkWindow *window)
168 GtkAccelGroup *accel_group=NULL;
173 accel_group = gtk_accel_group_new ();
174 gtk_window_add_accel_group (window, accel_group);
176 menubar = gtk_menu_bar_new ();
178 menuitem = gtk_menu_item_new_with_mnemonic ("_File");
179 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
180 menu = gtk_menu_new ();
181 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
182 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_NEW, NULL);
183 g_signal_connect (menuitem, "activate", G_CALLBACK (print_hello), window);
184 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
185 menuitem = gtk_separator_menu_item_new ();
186 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
187 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT, NULL);
188 g_signal_connect (menuitem, "activate", G_CALLBACK (gtk_main_quit), window);
189 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
191 menuitem = gtk_menu_item_new_with_mnemonic ("O_K");
192 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
194 menuitem = gtk_menu_item_new_with_mnemonic ("_Help");
195 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
196 menu = gtk_menu_new ();
197 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
198 menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
199 g_signal_connect (menuitem, "activate", G_CALLBACK (print_hello), window);
200 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
206 create_combo_box (void)
208 GtkComboBox *combo_box = GTK_COMBO_BOX (gtk_combo_box_new_text ());
210 gtk_combo_box_append_text (combo_box, "This");
211 gtk_combo_box_append_text (combo_box, "Is");
212 gtk_combo_box_append_text (combo_box, "A");
213 gtk_combo_box_append_text (combo_box, "ComboBox");
215 return GTK_WIDGET (combo_box);
219 create_content (GtkWindow *window, gboolean local)
225 frame = gtk_frame_new (local? "Local" : "Remote");
226 gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
227 vbox = gtk_vbox_new (TRUE, 0);
228 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
230 gtk_container_add (GTK_CONTAINER (frame), vbox);
233 gtk_box_pack_start (GTK_BOX (vbox), create_combo(), TRUE, TRUE, 0);
236 gtk_box_pack_start (GTK_BOX (vbox), gtk_entry_new(), TRUE, TRUE, 0);
239 button = gtk_button_new_with_mnemonic ("_Close");
240 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
241 g_signal_connect_swapped (button, "clicked",
242 G_CALLBACK (gtk_widget_destroy), window);
245 button = gtk_button_new_with_mnemonic ("_Blink");
246 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
247 g_signal_connect (button, "clicked",
252 gtk_box_pack_start (GTK_BOX (vbox), create_menubar (GTK_WINDOW (window)),
256 gtk_box_pack_start (GTK_BOX (vbox), create_combo_box (), TRUE, TRUE, 0);
258 add_buttons (NULL, vbox);
264 create_child_plug (guint32 xid,
270 window = gtk_plug_new (xid);
272 g_signal_connect (window, "destroy",
273 local ? G_CALLBACK (local_destroy)
274 : G_CALLBACK (remote_destroy),
276 gtk_container_set_border_width (GTK_CONTAINER (window), 0);
278 content = create_content (GTK_WINDOW (window), local);
280 gtk_container_add (GTK_CONTAINER (window), content);
282 gtk_widget_show_all (window);
284 if (gtk_widget_get_realized (window))
285 #if defined (GDK_WINDOWING_X11)
286 return GDK_WINDOW_XID (gtk_widget_get_window (window));
287 #elif defined (GDK_WINDOWING_WIN32)
288 return (guint32) GDK_WINDOW_HWND (gtk_widget_get_window (window));