gtk+ entry patch



hey guys,

    miguel asked me to write a patch to have gtk+ entries give popup
menus for cut/copy/paste when a user right-clicks them (apparently,
this is in gtk+ 2.0). i have attached the patch against gtk+ 1.2; i
hope you find it useful. the only thing obviously wrong to me is the
fact that cut/copy/paste_cb() don't really fit the function naming
schema :) this patch works for me, and afaik, does not break binary
compatibility.

best wishes,
justin

--- original-gtkentry.c	Mon Dec 11 18:14:58 2000
+++ gtkentry.c	Thu Dec 14 17:24:41 2000
@@ -29,7 +29,10 @@
 #include "gdk/gdkkeysyms.h"
 #include "gdk/gdki18n.h"
 #include "gtkentry.h"
+#include "gtkintl.h"
 #include "gtkmain.h"
+#include "gtkmenu.h"
+#include "gtkmenuitem.h"
 #include "gtkselection.h"
 #include "gtksignal.h"
 #include "gtkstyle.h"
@@ -857,11 +860,32 @@
   return FALSE;
 }
 
+void
+cut_cb (GtkWidget *widget,
+	gpointer  data)
+{
+	gtk_editable_cut_clipboard (GTK_EDITABLE(data));
+}
+
+void
+copy_cb (GtkWidget *widget,
+         gpointer  data)
+{
+        gtk_editable_copy_clipboard (GTK_EDITABLE(data));
+}
+void
+paste_cb (GtkWidget *widget,
+          gpointer  data)
+{
+        gtk_editable_paste_clipboard (GTK_EDITABLE(data));
+}
+
 static gint
 gtk_entry_button_press (GtkWidget      *widget,
 			GdkEventButton *event)
 {
   GtkEntry *entry;
+  GtkWidget *menu, *cut_item, *copy_item, *paste_item;
   GtkEditable *editable;
   gint tmp_pos;
 
@@ -922,6 +946,29 @@
 	  gtk_selection_convert (widget, GDK_SELECTION_PRIMARY,
 				 ctext_atom, event->time);
 	}
+
+      else if (event->button == 3)
+        {
+	  menu = gtk_menu_new ();
+          cut_item = gtk_menu_item_new_with_label(_("Cut"));
+	  copy_item = gtk_menu_item_new_with_label(_("Copy"));
+	  paste_item = gtk_menu_item_new_with_label(_("Paste"));
+	  gtk_menu_append (GTK_MENU (menu), cut_item);
+	  gtk_menu_append (GTK_MENU (menu), copy_item);
+	  gtk_menu_append (GTK_MENU (menu), paste_item);
+          gtk_signal_connect (GTK_OBJECT (cut_item), "activate", 
+                              GTK_SIGNAL_FUNC (cut_cb), editable);
+          gtk_signal_connect (GTK_OBJECT (copy_item), "activate", 
+                              GTK_SIGNAL_FUNC (copy_cb), editable);
+	  gtk_signal_connect (GTK_OBJECT (paste_item), "activate",
+			      GTK_SIGNAL_FUNC (paste_cb), editable);
+	  gtk_widget_show (cut_item);
+	  gtk_widget_show (copy_item);
+	  gtk_widget_show (paste_item);
+          gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 3, 
+			  event->time); 
+	}
+
       else
 	{
 	  gtk_grab_add (widget);


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