]> Pileus Git - ~andy/gtk/blob - tests/testsocket_common.c
Extended to test different type of adding plugs to sockets
[~andy/gtk] / tests / testsocket_common.c
1 #include "x11/gdkx.h"
2 #include <gtk/gtk.h>
3
4 static void
5 remove_buttons (GtkWidget *widget, GtkWidget *other_button)
6 {
7   gtk_widget_destroy (other_button);
8   gtk_widget_destroy (widget);
9 }
10
11 static gboolean
12 blink_cb (gpointer data)
13 {
14   GtkWidget *widget = data;
15
16   gtk_widget_show (widget);
17   g_object_set_data (G_OBJECT (widget), "blink", GPOINTER_TO_UINT (0));
18
19   return FALSE;
20 }
21
22 static void
23 blink (GtkWidget *widget,
24        GtkWidget *window)
25 {
26   guint blink_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window), "blink"));
27   
28   if (!blink_timeout)
29     {
30       blink_timeout = g_timeout_add (1000, blink_cb, window);
31       gtk_widget_hide (window);
32
33       g_object_set_data (G_OBJECT (window), "blink", GUINT_TO_POINTER (blink_timeout));
34     }
35 }
36
37 static void
38 local_destroy (GtkWidget *window)
39 {
40   guint blink_timeout = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (window), "blink"));
41   if (blink_timeout)
42     g_source_remove (blink_timeout);
43 }
44
45 static void
46 remote_destroy (GtkWidget *window)
47 {
48   local_destroy (window);
49   gtk_main_quit ();
50 }
51
52 static void
53 add_buttons (GtkWidget *widget, GtkWidget *box)
54 {
55   GtkWidget *add_button;
56   GtkWidget *remove_button;
57
58   add_button = gtk_button_new_with_mnemonic ("_Add");
59   gtk_box_pack_start (GTK_BOX (box), add_button, TRUE, TRUE, 0);
60   gtk_widget_show (add_button);
61
62   gtk_signal_connect (GTK_OBJECT (add_button), "clicked",
63                       GTK_SIGNAL_FUNC (add_buttons),
64                       box);
65
66   remove_button = gtk_button_new_with_mnemonic ("_Remove");
67   gtk_box_pack_start (GTK_BOX (box), remove_button, TRUE, TRUE, 0);
68   gtk_widget_show (remove_button);
69
70   gtk_signal_connect (GTK_OBJECT (remove_button), "clicked",
71                       GTK_SIGNAL_FUNC (remove_buttons),
72                       add_button);
73 }
74
75 guint32
76 create_child_plug (guint32  xid,
77                    gboolean local)
78 {
79   GtkWidget *window;
80   GtkWidget *hbox;
81   GtkWidget *entry;
82   GtkWidget *button;
83   GtkWidget *label;
84
85   window = gtk_plug_new (xid);
86
87   gtk_signal_connect (GTK_OBJECT (window), "destroy",
88                       local ? GTK_SIGNAL_FUNC (local_destroy) : GTK_SIGNAL_FUNC (remote_destroy),
89                       NULL);
90   gtk_container_set_border_width (GTK_CONTAINER (window), 0);
91
92   hbox = gtk_hbox_new (FALSE, 0);
93   gtk_container_add (GTK_CONTAINER (window), hbox);
94
95   label = gtk_label_new (local ? "Local:" : "Remote:");
96   gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
97   
98   entry = gtk_entry_new ();
99   gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
100
101   button = gtk_button_new_with_mnemonic ("_Close");
102   gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
103
104   gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
105                              GTK_SIGNAL_FUNC (gtk_widget_destroy),
106                              GTK_OBJECT (window));
107
108   button = gtk_button_new_with_mnemonic ("_Blink");
109   gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
110
111   gtk_signal_connect (GTK_OBJECT (button), "clicked",
112                       GTK_SIGNAL_FUNC (blink),
113                       GTK_OBJECT (window));
114
115   add_buttons (NULL, hbox);
116   
117   gtk_widget_show_all (window);
118
119   if (GTK_WIDGET_REALIZED (window))
120     return GDK_WINDOW_XID (window->window);
121   else
122     return 0;
123 }