]> Pileus Git - ~andy/gtk/blobdiff - tests/testselection.c
Really create a native window when getting xid
[~andy/gtk] / tests / testselection.c
index a13fb5ad442107d06ea0013670f3a2188be920dc..cd1817369768fd13c326e1f4de647b85c3877e5c 100644 (file)
@@ -2,31 +2,35 @@
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
 /*
- * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#undef GTK_DISABLE_DEPRECATED
+
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
-#include "gtk.h"
+#define GTK_ENABLE_BROKEN
+#include "gtk/gtk.h"
 
 typedef enum {
   SEL_TYPE_NONE,
@@ -61,49 +65,50 @@ typedef struct _Target {
    in the ICCCM */
 
 static Target targets[] = {
-  { "ADOBE_PORTABLE_DOCUMENT_FORMAT",      STRING,        0, 8 },
-  { "APPLE_PICT",                          APPLE_PICT,    0, 8 },
-  { "BACKGROUND",                          PIXEL,         0, 32 },
-  { "BITMAP",                              BITMAP,        0, 32 },
-  { "CHARACTER_POSITION",                   SPAN,         0, 32 },
-  { "CLASS",                               TEXT,          0, 8 },
-  { "CLIENT_WINDOW",                       WINDOW,        0, 32 },
-  { "COLORMAP",                            COLORMAP,      0, 32 },
-  { "COLUMN_NUMBER",                       SPAN,          0, 32 },
-  { "COMPOUND_TEXT",                       COMPOUND_TEXT, 0, 8 },
+  { "ADOBE_PORTABLE_DOCUMENT_FORMAT",      STRING,        NULL, 8 },
+  { "APPLE_PICT",                          APPLE_PICT,    NULL, 8 },
+  { "BACKGROUND",                          PIXEL,         NULL, 32 },
+  { "BITMAP",                              BITMAP,        NULL, 32 },
+  { "CHARACTER_POSITION",                   SPAN,         NULL, 32 },
+  { "CLASS",                               TEXT,          NULL, 8 },
+  { "CLIENT_WINDOW",                       WINDOW,        NULL, 32 },
+  { "COLORMAP",                            COLORMAP,      NULL, 32 },
+  { "COLUMN_NUMBER",                       SPAN,          NULL, 32 },
+  { "COMPOUND_TEXT",                       COMPOUND_TEXT, NULL, 8 },
   /*  { "DELETE", "NULL", 0, ? }, */
-  { "DRAWABLE",                            DRAWABLE,      0, 32 },
-  { "ENCAPSULATED_POSTSCRIPT",                     STRING,        0, 8 },
-  { "ENCAPSULATED_POSTSCRIPT_INTERCHANGE",  STRING,       0, 8 },
-  { "FILE_NAME",                           TEXT,          0, 8 },
-  { "FOREGROUND",                          PIXEL,         0, 32 },
-  { "HOST_NAME",                           TEXT,          0, 8 },
+  { "DRAWABLE",                            DRAWABLE,      NULL, 32 },
+  { "ENCAPSULATED_POSTSCRIPT",                     STRING,        NULL, 8 },
+  { "ENCAPSULATED_POSTSCRIPT_INTERCHANGE",  STRING,       NULL, 8 },
+  { "FILE_NAME",                           TEXT,          NULL, 8 },
+  { "FOREGROUND",                          PIXEL,         NULL, 32 },
+  { "HOST_NAME",                           TEXT,          NULL, 8 },
   /*  { "INSERT_PROPERTY", "NULL", 0, ? NULL }, */
   /*  { "INSERT_SELECTION", "NULL", 0, ? NULL }, */
-  { "LENGTH",                              INTEGER,       0, 32 },
-  { "LINE_NUMBER",                         SPAN,          0, 32 },
-  { "LIST_LENGTH",                         INTEGER,       0, 32 },
-  { "MODULE",                              TEXT,          0, 8 },
+  { "LENGTH",                              INTEGER,       NULL, 32 },
+  { "LINE_NUMBER",                         SPAN,          NULL, 32 },
+  { "LIST_LENGTH",                         INTEGER,       NULL, 32 },
+  { "MODULE",                              TEXT,          NULL, 8 },
   /*  { "MULTIPLE", "ATOM_PAIR", 0, 32 }, */
-  { "NAME",                                TEXT,          0, 8 },
-  { "ODIF",                                TEXT,          0, 8 },
-  { "OWNER_OS",                            TEXT,          0, 8 },
-  { "PIXMAP",                              PIXMAP,        0, 32 },
-  { "POSTSCRIPT",                          STRING,        0, 8 },
-  { "PROCEDURE",                           TEXT,          0, 8 },
-  { "PROCESS",                             INTEGER,       0, 32 },
-  { "STRING",                              STRING,        0, 8 },
-  { "TARGETS",                                     ATOM,          0, 32 },
-  { "TASK",                                INTEGER,       0, 32 },
-  { "TEXT",                                TEXT,          0, 8  },
-  { "TIMESTAMP",                           INTEGER,       0, 32 },
-  { "USER",                                TEXT,          0, 8 },
+  { "NAME",                                TEXT,          NULL, 8 },
+  { "ODIF",                                TEXT,          NULL, 8 },
+  { "OWNER_OS",                            TEXT,          NULL, 8 },
+  { "PIXMAP",                              PIXMAP,        NULL, 32 },
+  { "POSTSCRIPT",                          STRING,        NULL, 8 },
+  { "PROCEDURE",                           TEXT,          NULL, 8 },
+  { "PROCESS",                             INTEGER,       NULL, 32 },
+  { "STRING",                              STRING,        NULL, 8 },
+  { "TARGETS",                                     ATOM,          NULL, 32 },
+  { "TASK",                                INTEGER,       NULL, 32 },
+  { "TEXT",                                TEXT,          NULL, 8  },
+  { "TIMESTAMP",                           INTEGER,       NULL, 32 },
+  { "USER",                                TEXT,          NULL, 8 },
 };
 
 static int num_targets = sizeof(targets)/sizeof(Target);
 
 static int have_selection = FALSE;
 
+GtkWidget *selection_widget;
 GtkWidget *selection_text;
 GtkWidget *selection_button;
 GString *selection_string = NULL;
@@ -139,7 +144,7 @@ selection_toggled (GtkWidget *widget)
 {
   if (GTK_TOGGLE_BUTTON(widget)->active)
     {
-      have_selection = gtk_selection_owner_set (widget,
+      have_selection = gtk_selection_owner_set (selection_widget,
                                                GDK_SELECTION_PRIMARY,
                                                GDK_CURRENT_TIME);
       if (!have_selection)
@@ -195,7 +200,7 @@ gint
 selection_clear (GtkWidget *widget, GdkEventSelection *event)
 {
   have_selection = FALSE;
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), FALSE);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(selection_button), FALSE);
 
   return TRUE;
 }
@@ -288,9 +293,8 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
   if (seltype == SEL_TYPE_NONE)
     {
       char *name = gdk_atom_name (data->type);
-      g_print("Don't know how to handle type: %s (%ld)\n",
-             name?name:"<unknown>",
-             data->type);
+      g_print("Don't know how to handle type: %s\n",
+             name?name:"<unknown>");
       return;
     }
 
@@ -334,9 +338,8 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
        default:
          {
            char *name = gdk_atom_name (data->type);
-           g_print("Can't convert type %s (%ld) to string\n",
-                   name?name:"<unknown>",
-                   data->type);
+           g_print("Can't convert type %s to string\n",
+                   name?name:"<unknown>");
            position = data->length;
            continue;
          }
@@ -356,7 +359,7 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
 void
 paste (GtkWidget *widget, GtkWidget *entry)
 {
-  char *name;
+  const char *name;
   GdkAtom atom;
 
   name = gtk_entry_get_text (GTK_ENTRY(entry));
@@ -368,7 +371,7 @@ paste (GtkWidget *widget, GtkWidget *entry)
       return;
     }
 
-  gtk_selection_convert (selection_button, GDK_SELECTION_PRIMARY, atom, 
+  gtk_selection_convert (selection_widget, GDK_SELECTION_PRIMARY, atom, 
                         GDK_CURRENT_TIME);
 }
 
@@ -401,12 +404,14 @@ main (int argc, char *argv[])
 
   init_atoms();
 
+  selection_widget = gtk_invisible_new ();
+
   dialog = gtk_dialog_new ();
   gtk_widget_set_name (dialog, "Test Input");
   gtk_container_set_border_width (GTK_CONTAINER(dialog), 0);
 
-  gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
-                     GTK_SIGNAL_FUNC (quit), NULL);
+  g_signal_connect (dialog, "destroy",
+                   G_CALLBACK (quit), NULL);
 
   table = gtk_table_new (4, 2, FALSE);
   gtk_container_set_border_width (GTK_CONTAINER(table), 10);
@@ -424,18 +429,18 @@ main (int argc, char *argv[])
                    GTK_EXPAND | GTK_FILL, 0, 0, 0);
   gtk_widget_show (selection_button);
 
-  gtk_signal_connect (GTK_OBJECT(selection_button), "toggled",
-                     GTK_SIGNAL_FUNC (selection_toggled), NULL);
-  gtk_signal_connect (GTK_OBJECT(selection_button), "selection_clear_event",
-                     GTK_SIGNAL_FUNC (selection_clear), NULL);
-  gtk_signal_connect (GTK_OBJECT(selection_button), "selection_received",
-                     GTK_SIGNAL_FUNC (selection_received), NULL);
+  g_signal_connect (selection_button, "toggled",
+                   G_CALLBACK (selection_toggled), NULL);
+  g_signal_connect (selection_widget, "selection_clear_event",
+                   G_CALLBACK (selection_clear), NULL);
+  g_signal_connect (selection_widget, "selection_received",
+                   G_CALLBACK (selection_received), NULL);
 
-  gtk_selection_add_targets (selection_button, GDK_SELECTION_PRIMARY,
+  gtk_selection_add_targets (selection_widget, GDK_SELECTION_PRIMARY,
                             targetlist, ntargets);
 
-  gtk_signal_connect (GTK_OBJECT(selection_button), "selection_get",
-                     GTK_SIGNAL_FUNC (selection_get), NULL);
+  g_signal_connect (selection_widget, "selection_get",
+                   G_CALLBACK (selection_get), NULL);
 
   selection_text = gtk_text_new (NULL, NULL);
   gtk_table_attach_defaults (GTK_TABLE (table), selection_text, 0, 1, 1, 2);
@@ -468,17 +473,16 @@ main (int argc, char *argv[])
   button = gtk_button_new_with_label ("Paste");
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->action_area), 
                      button, TRUE, TRUE, 0);
-  gtk_signal_connect (GTK_OBJECT (button), "clicked",
-                     GTK_SIGNAL_FUNC (paste), entry);
+  g_signal_connect (button, "clicked",
+                   G_CALLBACK (paste), entry);
   gtk_widget_show (button);
 
   button = gtk_button_new_with_label ("Quit");
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->action_area), 
                      button, TRUE, TRUE, 0);
 
-  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
-                            GTK_SIGNAL_FUNC (gtk_widget_destroy), 
-                            GTK_OBJECT (dialog));
+  g_signal_connect_swapped (button, "clicked",
+                           G_CALLBACK (gtk_widget_destroy), dialog);
   gtk_widget_show (button);
 
   gtk_widget_show (dialog);