add -DGTK_DISABLE_DEPRECATED. #undef it at the top of gtktypebuiltins.c.
Tue Nov 19 17:05:51 2002 Manish Singh <yosh@gimp.org>
* gtk/Makefile.am: add -DGTK_DISABLE_DEPRECATED. #undef it at the
top of gtktypebuiltins.c.
* gtk/gtkclist.c
* gtk/gtkcombo.c
* gtk/gtkctree.c
* gtk/gtklist.c
* gtk/gtklistitem.c
* gtk/gtkoldeditable.c
* gtk/gtkpixmap.c
* gtk/gtkpreview.c
* gtk/gtksignal.c
* gtk/gtktext.c
* gtk/gtktipsquery.c
* gtk/gtktree.c
* gtk/gtktreeitem.c
* gtk/gtktypeutils.c: #undef GTK_DISABLE_DEPRECATED, deprecated widgets
and compat code.
* gtk/gtkcolorsel.c: move gtk_color_selection_set_color implementation
to set_color_internal, and use that. The deprecated function now
merely wraps it.
* gtk/gtkfontsel.c: same as above, except with
gtk_font_selection_get_font.
* gtk/gtknotebook.c: same as above, except with
gtk_notebook_set_homogeneous, and gtk_notebook_set_tab_{border,
hborder,vborder}.
* gtk/gtkprogressbar.c: same as above, except with
gtk_progress_bar_set_{bar_stype,discrete_blocks,activity_step,
activity_blocks}.
* gtk/gtkstyle.c: same as above, except with gtk_style_get_font.
* gtk/gtkwidget.c: same as above, except with gtk_widget_set_usize.
* gtk/gtkitemfactory.h: declare compatibility functions for deprecated
GtkMenuFactory stuff if GTK_COMPILATION, since they are used
internally by the compat code.
* gtk/gtkitemfactory.c (gtk_item_factory_create_item): remove
use of deprecated gtk_check_menu_item_set_show_toggle (it is a noop
now).
* gtk/gtkmain.c: replaced deprecated GTK_TYPE_* with G_TYPE_*.
* gtk/gtkobject.c: replaced various deprecated functions. In set and
get_property, use g_object_{set,get}_data with "user_data" instead
of gtk_object_{set,get}_user_data.
* gtk/gtkprogress.h: API declared if GTK_COMPILATION
* gtk/gtkprogress.c: port get_type to GObject API.
* gtk/gtktypeutils.h: declare GtkArg stuff and gtk_type_init,
if GTK_COMPILATION.
* gtk/gtkwidget.c: define gtk_widget_queue_clear in terms of
gtk_widget_queue_draw instead of the other way around.
* tests/Makefile.am: define -DGTK_DISABLE_DEPRECATED
* tests/testgtk.c
* tests/testselection.c
* tests/testsocket.c: #undef GTK_DISABLE_DEPRECATED, makes use of
deprecated stuff.
2002-11-20 01:07:33 +00:00
|
|
|
#undef GTK_DISABLE_DEPRECATED
|
|
|
|
|
2001-03-03 18:23:21 +00:00
|
|
|
#include <gtk/gtk.h>
|
2001-05-25 15:43:53 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2001-03-03 18:23:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2001-07-03 14:14:30 +00:00
|
|
|
|
|
|
|
int n_children = 0;
|
2001-03-03 18:23:21 +00:00
|
|
|
|
2001-07-05 02:58:34 +00:00
|
|
|
GSList *sockets = NULL;
|
|
|
|
|
2001-03-03 18:23:21 +00:00
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *vbox;
|
2001-07-05 02:58:34 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *socket;
|
|
|
|
} Socket;
|
2001-03-03 18:23:21 +00:00
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
extern guint32 create_child_plug (guint32 xid,
|
|
|
|
gboolean local);
|
|
|
|
|
2001-03-03 18:23:21 +00:00
|
|
|
static void
|
|
|
|
quit_cb (gpointer callback_data,
|
|
|
|
guint callback_action,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkWidget *message_dialog = gtk_message_dialog_new (GTK_WINDOW (window), 0,
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_YES_NO,
|
|
|
|
"Really Quit?");
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (message_dialog), GTK_RESPONSE_NO);
|
|
|
|
|
|
|
|
if (gtk_dialog_run (GTK_DIALOG (message_dialog)) == GTK_RESPONSE_YES)
|
|
|
|
gtk_widget_destroy (window);
|
|
|
|
|
|
|
|
gtk_widget_destroy (message_dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkItemFactoryEntry menu_items[] =
|
|
|
|
{
|
|
|
|
{ "/_File", NULL, 0, 0, "<Branch>" },
|
|
|
|
{ "/File/_Quit", "<control>Q", quit_cb, 0 },
|
|
|
|
};
|
|
|
|
|
2001-07-05 02:58:34 +00:00
|
|
|
static void
|
|
|
|
socket_destroyed (GtkWidget *widget,
|
|
|
|
Socket *socket)
|
|
|
|
{
|
|
|
|
sockets = g_slist_remove (sockets, socket);
|
|
|
|
g_free (socket);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
plug_added (GtkWidget *widget,
|
|
|
|
Socket *socket)
|
|
|
|
{
|
|
|
|
g_print ("Plug added to socket\n");
|
|
|
|
|
|
|
|
gtk_widget_show (socket->socket);
|
|
|
|
gtk_widget_hide (socket->frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plug_removed (GtkWidget *widget,
|
|
|
|
Socket *socket)
|
|
|
|
{
|
|
|
|
g_print ("Plug removed from socket\n");
|
|
|
|
|
|
|
|
gtk_widget_hide (socket->socket);
|
|
|
|
gtk_widget_show (socket->frame);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Socket *
|
|
|
|
create_socket (void)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
Socket *socket = g_new (Socket, 1);
|
|
|
|
|
|
|
|
socket->box = gtk_vbox_new (FALSE, 0);
|
|
|
|
|
|
|
|
socket->socket = gtk_socket_new ();
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (socket->box), socket->socket, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
socket->frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (socket->frame), GTK_SHADOW_IN);
|
|
|
|
gtk_box_pack_start (GTK_BOX (socket->box), socket->frame, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (socket->frame);
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label), "<span color=\"red\">Empty</span>");
|
|
|
|
gtk_container_add (GTK_CONTAINER (socket->frame), label);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
sockets = g_slist_prepend (sockets, socket);
|
|
|
|
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (socket->socket, "destroy",
|
2001-07-05 02:58:34 +00:00
|
|
|
G_CALLBACK (socket_destroyed), socket);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (socket->socket, "plug_added",
|
2001-07-05 02:58:34 +00:00
|
|
|
G_CALLBACK (plug_added), socket);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (socket->socket, "plug_removed",
|
2001-07-05 02:58:34 +00:00
|
|
|
G_CALLBACK (plug_removed), socket);
|
|
|
|
|
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
2001-03-03 18:23:21 +00:00
|
|
|
void
|
|
|
|
steal (GtkWidget *window, GtkEntry *entry)
|
|
|
|
{
|
|
|
|
guint32 xid;
|
2001-03-08 06:14:43 +00:00
|
|
|
const gchar *text;
|
2001-07-05 02:58:34 +00:00
|
|
|
Socket *socket;
|
2001-03-03 18:23:21 +00:00
|
|
|
|
|
|
|
text = gtk_entry_get_text (entry);
|
|
|
|
|
|
|
|
xid = strtol (text, NULL, 0);
|
|
|
|
if (xid == 0)
|
|
|
|
{
|
|
|
|
g_warning ("Invalid window id '%s'\n", text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-05 02:58:34 +00:00
|
|
|
socket = create_socket ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), socket->box, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (socket->box);
|
2001-03-03 18:23:21 +00:00
|
|
|
|
2001-10-19 17:03:14 +00:00
|
|
|
gtk_socket_steal (GTK_SOCKET (socket->socket), xid);
|
2001-03-03 18:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
remove_child (GtkWidget *window)
|
|
|
|
{
|
2001-07-05 02:58:34 +00:00
|
|
|
if (sockets)
|
|
|
|
{
|
|
|
|
Socket *socket = sockets->data;
|
|
|
|
gtk_widget_destroy (socket->box);
|
|
|
|
}
|
2001-03-03 18:23:21 +00:00
|
|
|
}
|
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
static gboolean
|
|
|
|
child_read_watch (GIOChannel *channel, GIOCondition cond, gpointer data)
|
|
|
|
{
|
|
|
|
GIOStatus status;
|
|
|
|
GError *error = NULL;
|
|
|
|
char *line;
|
|
|
|
gsize term;
|
|
|
|
int xid;
|
|
|
|
|
|
|
|
status = g_io_channel_read_line (channel, &line, NULL, &term, &error);
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case G_IO_STATUS_NORMAL:
|
|
|
|
line[term] = '\0';
|
|
|
|
xid = strtol (line, NULL, 0);
|
|
|
|
if (xid == 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Invalid window id '%s'\n", line);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-05 02:58:34 +00:00
|
|
|
Socket *socket = create_socket ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), socket->box, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (socket->box);
|
2001-07-03 14:14:30 +00:00
|
|
|
|
2001-07-05 02:58:34 +00:00
|
|
|
gtk_socket_add_id (GTK_SOCKET (socket->socket), xid);
|
2001-07-03 14:14:30 +00:00
|
|
|
}
|
|
|
|
g_free (line);
|
|
|
|
return TRUE;
|
|
|
|
case G_IO_STATUS_AGAIN:
|
|
|
|
return TRUE;
|
|
|
|
case G_IO_STATUS_EOF:
|
|
|
|
n_children--;
|
2002-10-13 23:22:33 +00:00
|
|
|
g_io_channel_unref (channel);
|
2001-07-03 14:14:30 +00:00
|
|
|
return FALSE;
|
|
|
|
case G_IO_STATUS_ERROR:
|
|
|
|
fprintf (stderr, "Error reading fd from child: %s\n", error->message);
|
|
|
|
exit (1);
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-03-03 18:23:21 +00:00
|
|
|
void
|
2001-07-03 14:14:30 +00:00
|
|
|
add_child (GtkWidget *window,
|
|
|
|
gboolean active)
|
2001-03-03 18:23:21 +00:00
|
|
|
{
|
2001-07-05 02:58:34 +00:00
|
|
|
Socket *socket;
|
2001-03-03 18:23:21 +00:00
|
|
|
char *argv[3] = { "./testsocket_child", NULL, NULL };
|
|
|
|
char buffer[20];
|
2001-07-03 14:14:30 +00:00
|
|
|
int out_fd;
|
|
|
|
GIOChannel *channel;
|
2001-03-03 18:23:21 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
if (active)
|
|
|
|
{
|
2001-07-05 02:58:34 +00:00
|
|
|
socket = create_socket ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), socket->box, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (socket->box);
|
2001-07-18 04:31:11 +00:00
|
|
|
sprintf(buffer, "%#lx", (gulong) gtk_socket_get_id (GTK_SOCKET (socket->socket)));
|
2001-07-03 14:14:30 +00:00
|
|
|
argv[1] = buffer;
|
|
|
|
}
|
2001-03-03 18:23:21 +00:00
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
if (!g_spawn_async_with_pipes (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, &out_fd, NULL, &error))
|
2001-03-03 18:23:21 +00:00
|
|
|
{
|
|
|
|
fprintf (stderr, "Can't exec testsocket_child: %s\n", error->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
2001-07-03 14:14:30 +00:00
|
|
|
|
|
|
|
n_children++;
|
|
|
|
channel = g_io_channel_unix_new (out_fd);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_io_channel_set_close_on_unref (channel, TRUE);
|
2001-07-03 14:14:30 +00:00
|
|
|
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, &error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Error making channel non-blocking: %s\n", error->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_io_add_watch (channel, G_IO_IN | G_IO_HUP, child_read_watch, NULL);
|
2002-05-17 18:15:26 +00:00
|
|
|
g_io_channel_unref (channel);
|
2001-03-03 18:23:21 +00:00
|
|
|
}
|
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
void
|
|
|
|
add_active_child (GtkWidget *window)
|
|
|
|
{
|
|
|
|
add_child (window, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_passive_child (GtkWidget *window)
|
|
|
|
{
|
|
|
|
add_child (window, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-15 17:58:35 +00:00
|
|
|
add_local_active_child (GtkWidget *window)
|
2001-07-03 14:14:30 +00:00
|
|
|
{
|
2001-07-05 02:58:34 +00:00
|
|
|
Socket *socket;
|
2001-07-03 14:14:30 +00:00
|
|
|
|
2001-07-05 02:58:34 +00:00
|
|
|
socket = create_socket ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), socket->box, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (socket->box);
|
2001-07-03 14:14:30 +00:00
|
|
|
|
2001-07-05 02:58:34 +00:00
|
|
|
create_child_plug (gtk_socket_get_id (GTK_SOCKET (socket->socket)), TRUE);
|
2001-07-03 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
2001-11-15 17:58:35 +00:00
|
|
|
void
|
|
|
|
add_local_passive_child (GtkWidget *window)
|
|
|
|
{
|
|
|
|
Socket *socket;
|
|
|
|
GdkNativeWindow xid;
|
|
|
|
|
|
|
|
socket = create_socket ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), socket->box, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (socket->box);
|
|
|
|
|
|
|
|
xid = create_child_plug (0, TRUE);
|
|
|
|
gtk_socket_add_id (GTK_SOCKET (socket->socket), xid);
|
|
|
|
}
|
|
|
|
|
2001-03-03 18:23:21 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *entry;
|
2001-04-18 18:28:19 +00:00
|
|
|
GtkAccelGroup *accel_group;
|
2001-03-03 18:23:21 +00:00
|
|
|
GtkItemFactory *item_factory;
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
2001-03-03 18:23:21 +00:00
|
|
|
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Socket Test");
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
|
2001-04-18 18:28:19 +00:00
|
|
|
accel_group = gtk_accel_group_new ();
|
|
|
|
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
|
|
|
|
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group);
|
|
|
|
|
|
|
|
|
2001-03-03 18:23:21 +00:00
|
|
|
gtk_item_factory_create_items (item_factory,
|
|
|
|
G_N_ELEMENTS (menu_items), menu_items,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox),
|
|
|
|
gtk_item_factory_get_widget (item_factory, "<main>"),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
button = gtk_button_new_with_label ("Add Active Child");
|
2001-03-03 18:23:21 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (add_active_child), vbox);
|
2001-07-03 14:14:30 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Add Passive Child");
|
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (add_passive_child), vbox);
|
2001-07-03 14:14:30 +00:00
|
|
|
|
2001-11-15 17:58:35 +00:00
|
|
|
button = gtk_button_new_with_label ("Add Local Active Child");
|
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (add_local_active_child), vbox);
|
2001-11-15 17:58:35 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Add Local Passive Child");
|
2001-07-03 14:14:30 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (add_local_passive_child), vbox);
|
2001-03-03 18:23:21 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Remove Last Child");
|
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (remove_child), vbox);
|
2001-03-03 18:23:21 +00:00
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), entry, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Steal");
|
|
|
|
gtk_box_pack_start (GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (steal),
|
|
|
|
entry);
|
2001-03-03 18:23:21 +00:00
|
|
|
|
|
|
|
gtk_widget_show_all (window);
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
if (n_children)
|
|
|
|
{
|
|
|
|
g_print ("Waiting for children to exit\n");
|
2001-03-03 18:23:21 +00:00
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
while (n_children)
|
2002-10-13 23:22:33 +00:00
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2001-07-03 14:14:30 +00:00
|
|
|
}
|
2001-03-03 18:23:21 +00:00
|
|
|
|
2001-07-03 14:14:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|