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
25 #if defined (GDK_WINDOWING_X11)
27 #elif defined (GDK_WINDOWING_WIN32)
28 #include "win32/gdkwin32.h"
40 print_hello (GtkWidget
*w
,
46 g_message ("File New activated");
48 case ACTION_FILE_OPEN
:
49 g_message ("File Open activated");
52 g_message ("OK activated");
54 case ACTION_HELP_ABOUT
:
55 g_message ("Help About activated ");
58 g_assert_not_reached ();
63 static GtkItemFactoryEntry menu_items
[] = {
64 { "/_File", NULL
, NULL
, 0, "<Branch>" },
65 { "/File/_New", "<control>N", print_hello
, ACTION_FILE_NEW
, "<Item>" },
66 { "/File/_Open", "<control>O", print_hello
, ACTION_FILE_OPEN
, "<Item>" },
67 { "/File/sep1", NULL
, NULL
, 0, "<Separator>" },
68 { "/File/Quit", "<control>Q", gtk_main_quit
, 0, "<Item>" },
69 { "/O_K", "<control>K",print_hello
, ACTION_OK
, "<Item>" },
70 { "/_Help", NULL
, NULL
, 0, "<LastBranch>" },
71 { "/_Help/About", NULL
, print_hello
, ACTION_HELP_ABOUT
, "<Item>" },
75 remove_buttons (GtkWidget
*widget
, GtkWidget
*other_button
)
77 gtk_widget_destroy (other_button
);
78 gtk_widget_destroy (widget
);
82 blink_cb (gpointer data
)
84 GtkWidget
*widget
= data
;
86 gtk_widget_show (widget
);
87 g_object_set_data (G_OBJECT (widget
), "blink", NULL
);
93 blink (GtkWidget
*widget
,
96 guint blink_timeout
= GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window
), "blink"));
100 blink_timeout
= gdk_threads_add_timeout (1000, blink_cb
, window
);
101 gtk_widget_hide (window
);
103 g_object_set_data (G_OBJECT (window
), "blink", GUINT_TO_POINTER (blink_timeout
));
108 local_destroy (GtkWidget
*window
)
110 guint blink_timeout
= GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window
), "blink"));
112 g_source_remove (blink_timeout
);
116 remote_destroy (GtkWidget
*window
)
118 local_destroy (window
);
123 add_buttons (GtkWidget
*widget
, GtkWidget
*box
)
125 GtkWidget
*add_button
;
126 GtkWidget
*remove_button
;
128 add_button
= gtk_button_new_with_mnemonic ("_Add");
129 gtk_box_pack_start (GTK_BOX (box
), add_button
, TRUE
, TRUE
, 0);
130 gtk_widget_show (add_button
);
132 g_signal_connect (add_button
, "clicked",
133 G_CALLBACK (add_buttons
),
136 remove_button
= gtk_button_new_with_mnemonic ("_Remove");
137 gtk_box_pack_start (GTK_BOX (box
), remove_button
, TRUE
, TRUE
, 0);
138 gtk_widget_show (remove_button
);
140 g_signal_connect (remove_button
, "clicked",
141 G_CALLBACK (remove_buttons
),
152 cbitems
= g_list_append (cbitems
, "item0");
153 cbitems
= g_list_append (cbitems
, "item1 item1");
154 cbitems
= g_list_append (cbitems
, "item2 item2 item2");
155 cbitems
= g_list_append (cbitems
, "item3 item3 item3 item3");
156 cbitems
= g_list_append (cbitems
, "item4 item4 item4 item4 item4");
157 cbitems
= g_list_append (cbitems
, "item5 item5 item5 item5 item5 item5");
158 cbitems
= g_list_append (cbitems
, "item6 item6 item6 item6 item6");
159 cbitems
= g_list_append (cbitems
, "item7 item7 item7 item7");
160 cbitems
= g_list_append (cbitems
, "item8 item8 item8");
161 cbitems
= g_list_append (cbitems
, "item9 item9");
163 combo
= GTK_COMBO (gtk_combo_new ());
164 gtk_combo_set_popdown_strings (combo
, cbitems
);
165 gtk_entry_set_text (GTK_ENTRY (combo
->entry
), "hello world");
166 gtk_editable_select_region (GTK_EDITABLE (combo
->entry
), 0, -1);
168 return GTK_WIDGET (combo
);
172 create_menubar (GtkWindow
*window
)
174 GtkItemFactory
*item_factory
;
175 GtkAccelGroup
*accel_group
=NULL
;
178 accel_group
= gtk_accel_group_new ();
179 item_factory
= gtk_item_factory_new (GTK_TYPE_MENU_BAR
, "<main>",
181 gtk_item_factory_create_items (item_factory
,
182 G_N_ELEMENTS (menu_items
),
185 gtk_window_add_accel_group (window
, accel_group
);
186 menubar
= gtk_item_factory_get_widget (item_factory
, "<main>");
192 create_combo_box (void)
194 GtkComboBox
*combo_box
= GTK_COMBO_BOX (gtk_combo_box_new_text ());
196 gtk_combo_box_append_text (combo_box
, "This");
197 gtk_combo_box_append_text (combo_box
, "Is");
198 gtk_combo_box_append_text (combo_box
, "A");
199 gtk_combo_box_append_text (combo_box
, "ComboBox");
201 return GTK_WIDGET (combo_box
);
205 create_content (GtkWindow
*window
, gboolean local
)
211 frame
= gtk_frame_new (local
? "Local" : "Remote");
212 gtk_container_set_border_width (GTK_CONTAINER (frame
), 3);
213 vbox
= gtk_vbox_new (TRUE
, 0);
214 gtk_container_set_border_width (GTK_CONTAINER (vbox
), 3);
216 gtk_container_add (GTK_CONTAINER (frame
), vbox
);
219 gtk_box_pack_start (GTK_BOX (vbox
), create_combo(), TRUE
, TRUE
, 0);
222 gtk_box_pack_start (GTK_BOX (vbox
), gtk_entry_new(), TRUE
, TRUE
, 0);
225 button
= gtk_button_new_with_mnemonic ("_Close");
226 gtk_box_pack_start (GTK_BOX (vbox
), button
, TRUE
, TRUE
, 0);
227 g_signal_connect_swapped (button
, "clicked",
228 G_CALLBACK (gtk_widget_destroy
), window
);
231 button
= gtk_button_new_with_mnemonic ("_Blink");
232 gtk_box_pack_start (GTK_BOX (vbox
), button
, TRUE
, TRUE
, 0);
233 g_signal_connect (button
, "clicked",
238 gtk_box_pack_start (GTK_BOX (vbox
), create_menubar (GTK_WINDOW (window
)),
242 gtk_box_pack_start (GTK_BOX (vbox
), create_combo_box (), TRUE
, TRUE
, 0);
244 add_buttons (NULL
, vbox
);
250 create_child_plug (guint32 xid
,
256 window
= gtk_plug_new (xid
);
258 g_signal_connect (window
, "destroy",
259 local
? G_CALLBACK (local_destroy
)
260 : G_CALLBACK (remote_destroy
),
262 gtk_container_set_border_width (GTK_CONTAINER (window
), 0);
264 content
= create_content (GTK_WINDOW (window
), local
);
266 gtk_container_add (GTK_CONTAINER (window
), content
);
268 gtk_widget_show_all (window
);
270 if (GTK_WIDGET_REALIZED (window
))
271 #if defined (GDK_WINDOWING_X11)
272 return GDK_WINDOW_XID (window
->window
);
273 #elif defined (GDK_WINDOWING_WIN32)
274 return (guint32
) GDK_WINDOW_HWND (window
->window
);