]> Pileus Git - ~andy/gtk/blobdiff - tests/testselection.c
Make color selection and selection examples work.
[~andy/gtk] / tests / testselection.c
index a13fb5ad442107d06ea0013670f3a2188be920dc..303075235e6bde04c029b083bdda898c3817e382 100644 (file)
@@ -2,23 +2,23 @@
  * 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/. 
@@ -26,7 +26,8 @@
 
 #include <stdio.h>
 #include <string.h>
-#include "gtk.h"
+#define GTK_ENABLE_BROKEN
+#include "gtk/gtk.h"
 
 typedef enum {
   SEL_TYPE_NONE,
@@ -104,6 +105,7 @@ 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 +141,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 +197,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 +290,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 +335,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 +356,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 +368,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,6 +401,8 @@ 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);
@@ -426,15 +428,15 @@ main (int argc, char *argv[])
 
   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_connect (GTK_OBJECT(selection_widget), "selection_clear_event",
                      GTK_SIGNAL_FUNC (selection_clear), NULL);
-  gtk_signal_connect (GTK_OBJECT(selection_button), "selection_received",
+  gtk_signal_connect (GTK_OBJECT(selection_widget), "selection_received",
                      GTK_SIGNAL_FUNC (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_connect (GTK_OBJECT(selection_widget), "selection_get",
                      GTK_SIGNAL_FUNC (selection_get), NULL);
 
   selection_text = gtk_text_new (NULL, NULL);