#59803: patch



Hi,

Appended patch fixes #59803 (GtkEditable needs signals) with option 1)
from the possibilities in my previous mail. ChangeLog:

Sun Sep 23 18:35:39 2001  Kristian Rietveld  <kristian planet nl>

        * gtk/gtkeditable.[ch]: move insert_text and delete_text virtual
        functions to do_insert_text and do_delete_text, add signals
        insert_text, delete_text and changed

        * gtk/gtkentry.[ch]: remove signals insert_text, delete_text
        and changed. Updates to match new situation.

        * gtk/gtkspinbutton.c: updates to match new situation

        Fixes bug #59803

Ok to commit?

regards,


	Kris


Index: gtkeditable.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkeditable.c,v
retrieving revision 1.40
diff -u -r1.40 gtkeditable.c
--- gtkeditable.c	2001/07/18 23:39:22	1.40
+++ gtkeditable.c	2001/09/23 16:30:53
@@ -29,6 +29,10 @@
 #include "gtkeditable.h"
 #include "gtksignal.h"

+
+static void   gtk_editable_base_init             (gpointer g_class);
+
+
 GtkType
 gtk_editable_get_type (void)
 {
@@ -39,7 +43,7 @@
       static const GTypeInfo editable_info =
       {
 	sizeof (GtkEditableClass),  /* class_size */
-	NULL,			    /* base_init */
+	gtk_editable_base_init,	    /* base_init */
 	NULL,			    /* base_finalize */
       };

@@ -49,6 +53,44 @@
   return editable_type;
 }

+static void
+gtk_editable_base_init (gpointer g_class)
+{
+  static gboolean initialized = FALSE;
+
+  if (! initialized)
+    {
+      g_signal_new ("insert_text",
+		    GTK_TYPE_EDITABLE,
+		    G_SIGNAL_RUN_LAST,
+		    G_STRUCT_OFFSET (GtkEditableClass, insert_text),
+		    NULL, NULL,
+		    gtk_marshal_VOID__STRING_INT_POINTER,
+		    G_TYPE_NONE, 3,
+		    GTK_TYPE_STRING,
+		    GTK_TYPE_INT,
+		    GTK_TYPE_POINTER);
+      g_signal_new ("delete_text",
+		    GTK_TYPE_EDITABLE,
+		    G_SIGNAL_RUN_LAST,
+		    G_STRUCT_OFFSET (GtkEditableClass, delete_text),
+		    NULL, NULL,
+		    gtk_marshal_VOID__INT_INT,
+		    GTK_TYPE_NONE, 2,
+		    GTK_TYPE_INT,
+		    GTK_TYPE_INT);
+      g_signal_new ("changed",
+		    GTK_TYPE_EDITABLE,
+		    G_SIGNAL_RUN_LAST,
+		    G_STRUCT_OFFSET (GtkEditableClass, changed),
+		    NULL, NULL,
+		    gtk_marshal_VOID__VOID,
+		    GTK_TYPE_NONE, 0);
+
+      initialized = TRUE;
+    }
+}
+
 void
 gtk_editable_insert_text (GtkEditable *editable,
 			  const gchar *new_text,
@@ -61,7 +103,7 @@
   if (new_text_length < 0)
     new_text_length = strlen (new_text);

-  GTK_EDITABLE_GET_CLASS (editable)->insert_text (editable, new_text, new_text_length, position);
+  GTK_EDITABLE_GET_CLASS (editable)->do_insert_text (editable, new_text, new_text_length, position);
 }

 void
@@ -71,7 +113,7 @@
 {
   g_return_if_fail (GTK_IS_EDITABLE (editable));

-  GTK_EDITABLE_GET_CLASS (editable)->delete_text (editable, start_pos, end_pos);
+  GTK_EDITABLE_GET_CLASS (editable)->do_delete_text (editable, start_pos, end_pos);
 }

 gchar *
Index: gtkeditable.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkeditable.h,v
retrieving revision 1.18
diff -u -r1.18 gtkeditable.h
--- gtkeditable.h	2001/06/24 15:34:47	1.18
+++ gtkeditable.h	2001/09/23 16:30:53
@@ -50,7 +50,7 @@
 {
   GTypeInterface		   base_iface;

-  /* Signals for notification/filtering of changes */
+  /* signals */
   void (* insert_text)              (GtkEditable    *editable,
 				     const gchar    *text,
 				     gint            length,
@@ -58,6 +58,17 @@
   void (* delete_text)              (GtkEditable    *editable,
 				     gint            start_pos,
 				     gint            end_pos);
+  void (* changed)                  (GtkEditable    *editable);
+
+  /* vtable */
+  void (* do_insert_text)           (GtkEditable    *editable,
+				     const gchar    *text,
+				     gint            length,
+				     gint           *position);
+  void (* do_delete_text)           (GtkEditable    *editable,
+				     gint            start_pos,
+				     gint            end_pos);
+
   gchar* (* get_chars)              (GtkEditable    *editable,
 				     gint            start_pos,
 				     gint            end_pos);
Index: gtkentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.c,v
retrieving revision 1.149
diff -u -r1.149 gtkentry.c
--- gtkentry.c	2001/09/19 00:49:51	1.149
+++ gtkentry.c	2001/09/23 16:30:57
@@ -55,9 +55,6 @@
 #define MAX_SIZE G_MAXUSHORT

 enum {
-  INSERT_TEXT,
-  DELETE_TEXT,
-  CHANGED,
   ACTIVATE,
   POPULATE_POPUP,
   MOVE_CURSOR,
@@ -191,11 +188,11 @@

 /* Default signal handlers
  */
-static void gtk_entry_real_insert_text   (GtkEntry        *entry,
+static void gtk_entry_real_insert_text   (GtkEditable     *editable,
 					  const gchar     *new_text,
 					  gint             new_text_length,
 					  gint            *position);
-static void gtk_entry_real_delete_text   (GtkEntry        *entry,
+static void gtk_entry_real_delete_text   (GtkEditable     *editable,
 					  gint             start_pos,
 					  gint             end_pos);
 static void gtk_entry_move_cursor        (GtkEntry        *entry,
@@ -370,9 +367,7 @@
   widget_class->drag_data_delete = gtk_entry_drag_data_delete;

   widget_class->popup_menu = gtk_entry_popup_menu;
-
-  class->insert_text = gtk_entry_real_insert_text;
-  class->delete_text = gtk_entry_real_delete_text;
+
   class->move_cursor = gtk_entry_move_cursor;
   class->insert_at_cursor = gtk_entry_insert_at_cursor;
   class->delete_from_cursor = gtk_entry_delete_from_cursor;
@@ -469,37 +464,6 @@
 							       GDK_TYPE_COLOR,
 							       G_PARAM_READABLE));

-  signals[INSERT_TEXT] =
-    gtk_signal_new ("insert_text",
-		    GTK_RUN_LAST,
-		    GTK_CLASS_TYPE (object_class),
-		    GTK_SIGNAL_OFFSET (GtkEntryClass, insert_text),
-		    gtk_marshal_VOID__STRING_INT_POINTER,
-		    GTK_TYPE_NONE,
-		    3,
-		    GTK_TYPE_STRING,
-		    GTK_TYPE_INT,
-		    GTK_TYPE_POINTER);
-
-  signals[DELETE_TEXT] =
-    gtk_signal_new ("delete_text",
-		    GTK_RUN_LAST,
-		    GTK_CLASS_TYPE (object_class),
-		    GTK_SIGNAL_OFFSET (GtkEntryClass, delete_text),
-		    gtk_marshal_VOID__INT_INT,
-		    GTK_TYPE_NONE,
-		    2,
-		    GTK_TYPE_INT,
-		    GTK_TYPE_INT);
-
-  signals[CHANGED] =
-    gtk_signal_new ("changed",
-		    GTK_RUN_LAST,
-		    GTK_CLASS_TYPE (object_class),
-		    GTK_SIGNAL_OFFSET (GtkEntryClass, changed),
-		    gtk_marshal_VOID__VOID,
-		    GTK_TYPE_NONE, 0);
-
   signals[POPULATE_POPUP] =
     gtk_signal_new ("populate_popup",
 		    GTK_RUN_LAST,
@@ -754,8 +718,10 @@
 static void
 gtk_entry_editable_init (GtkEditableClass *iface)
 {
-  iface->insert_text = gtk_entry_insert_text;
-  iface->delete_text = gtk_entry_delete_text;
+  iface->do_insert_text = gtk_entry_insert_text;
+  iface->do_delete_text = gtk_entry_delete_text;
+  iface->insert_text = gtk_entry_real_insert_text;
+  iface->delete_text = gtk_entry_real_delete_text;
   iface->get_chars = gtk_entry_get_chars;
   iface->set_selection_bounds = gtk_entry_set_selection_bounds;
   iface->get_selection_bounds = gtk_entry_get_selection_bounds;
@@ -1648,8 +1614,8 @@
   text[new_text_length] = '\0';
   strncpy (text, new_text, new_text_length);

-  gtk_signal_emit (GTK_OBJECT (editable), signals[INSERT_TEXT], text, new_text_length, position);
-  gtk_signal_emit (GTK_OBJECT (editable), signals[CHANGED]);
+  g_signal_emit_by_name (editable, "insert_text", text, new_text_length, position);
+  g_signal_emit_by_name (editable, "changed");

   if (new_text_length > 63)
     g_free (text);
@@ -1673,8 +1639,8 @@

   g_object_ref (G_OBJECT (editable));

-  gtk_signal_emit (GTK_OBJECT (editable), signals[DELETE_TEXT], start_pos, end_pos);
-  gtk_signal_emit (GTK_OBJECT (editable), signals[CHANGED]);
+  g_signal_emit_by_name (editable, "delete_text", start_pos, end_pos);
+  g_signal_emit_by_name (editable, "changed");

   g_object_unref (G_OBJECT (editable));
 }
@@ -1780,7 +1746,7 @@
 /* Default signal handlers
  */
 static void
-gtk_entry_real_insert_text (GtkEntry    *entry,
+gtk_entry_real_insert_text (GtkEditable *editable,
 			    const gchar *new_text,
 			    gint         new_text_length,
 			    gint        *position)
@@ -1788,6 +1754,8 @@
   gint index;
   gint n_chars;

+  GtkEntry *entry = GTK_ENTRY (editable);
+
   if (new_text_length < 0)
     new_text_length = strlen (new_text);

@@ -1845,10 +1813,12 @@
 }

 static void
-gtk_entry_real_delete_text (GtkEntry *entry,
-			    gint      start_pos,
-			    gint      end_pos)
+gtk_entry_real_delete_text (GtkEditable *editable,
+			    gint         start_pos,
+			    gint         end_pos)
 {
+  GtkEntry *entry = GTK_ENTRY (editable);
+
   if (start_pos < 0)
     start_pos = 0;
   if (end_pos < 0 || end_pos > entry->text_length)
Index: gtkentry.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.h,v
retrieving revision 1.48
diff -u -r1.48 gtkentry.h
--- gtkentry.h	2001/07/19 18:47:03	1.48
+++ gtkentry.h	2001/09/23 16:30:57
@@ -113,17 +113,6 @@
 struct _GtkEntryClass
 {
   GtkWidgetClass parent_class;
-
-  /* Notification of changes
-   */
-  void (* changed)          (GtkEntry       *entry);
-  void (* insert_text)      (GtkEntry       *entry,
-			     const gchar    *text,
-			     gint            length,
-			     gint           *position);
-  void (* delete_text)      (GtkEntry       *entry,
-		    	     gint            start_pos,
-			     gint            end_pos);

   /* Hook to customize right-click popup */
   void (* populate_popup)   (GtkEntry       *entry,
Index: gtkspinbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkspinbutton.c,v
retrieving revision 1.74
diff -u -r1.74 gtkspinbutton.c
--- gtkspinbutton.c	2001/09/19 00:58:09	1.74
+++ gtkspinbutton.c	2001/09/23 16:30:59
@@ -69,6 +69,7 @@
 };

 static void gtk_spin_button_class_init     (GtkSpinButtonClass *klass);
+static void gtk_spin_button_editable_init  (GtkEditableClass   *iface);
 static void gtk_spin_button_init           (GtkSpinButton      *spin_button);
 static void gtk_spin_button_finalize       (GObject            *object);
 static void gtk_spin_button_set_property   (GObject         *object,
@@ -115,7 +116,7 @@
 static void gtk_spin_button_activate       (GtkEntry           *entry);
 static void gtk_spin_button_snap           (GtkSpinButton      *spin_button,
 					    gdouble             val);
-static void gtk_spin_button_insert_text    (GtkEntry           *entry,
+static void gtk_spin_button_insert_text    (GtkEditable        *editable,
 					    const gchar        *new_text,
 					    gint                new_text_length,
 					    gint               *position);
@@ -150,7 +151,17 @@
         (GtkClassInitFunc) NULL,
       };

+      static const GInterfaceInfo editable_info =
+      {
+	(GInterfaceInitFunc) gtk_spin_button_editable_init, /* interface_init */
+	NULL, /* interface_finalize */
+	NULL  /* interface_data */
+      };
+
       spin_button_type = gtk_type_unique (GTK_TYPE_ENTRY, &spin_button_info);
+      g_type_add_interface_static (spin_button_type,
+				   GTK_TYPE_EDITABLE,
+				   &editable_info);
     }
   return spin_button_type;
 }
@@ -165,7 +176,7 @@

   object_class   = (GtkObjectClass*)   class;
   widget_class   = (GtkWidgetClass*)   class;
-  entry_class    = (GtkEntryClass*)    class;
+  entry_class    = (GtkEntryClass*)    class;

   parent_class = gtk_type_class (GTK_TYPE_ENTRY);

@@ -191,7 +202,6 @@
   widget_class->leave_notify_event = gtk_spin_button_leave_notify;
   widget_class->focus_out_event = gtk_spin_button_focus_out;

-  entry_class->insert_text = gtk_spin_button_insert_text;
   entry_class->activate = gtk_spin_button_activate;

   class->input = NULL;
@@ -301,6 +311,12 @@
 }

 static void
+gtk_spin_button_editable_init (GtkEditableClass *iface)
+{
+  iface->insert_text = gtk_spin_button_insert_text;
+}
+
+static void
 gtk_spin_button_set_property (GObject      *object,
 			      guint         prop_id,
 			      const GValue *value,
@@ -1309,13 +1325,14 @@
 }

 static void
-gtk_spin_button_insert_text (GtkEntry    *entry,
+gtk_spin_button_insert_text (GtkEditable *editable,
 			     const gchar *new_text,
 			     gint         new_text_length,
 			     gint        *position)
 {
-  GtkEditable *editable = GTK_EDITABLE (entry);
+  GtkEntry *entry = GTK_ENTRY (editable);
   GtkSpinButton *spin = GTK_SPIN_BUTTON (editable);
+  GtkEditableClass *parent_editable_iface = g_type_interface_peek (parent_class, GTK_TYPE_EDITABLE);

   if (spin->numeric)
     {
@@ -1385,8 +1402,8 @@
 	}
     }

-  GTK_ENTRY_CLASS (parent_class)->insert_text (entry, new_text,
-					       new_text_length, position);
+  parent_editable_iface->insert_text (editable, new_text,
+				      new_text_length, position);
 }

 static void





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]