Re: gtk+ entry patch



Patches for GTK+ need to go to gtk-devel-list, not here. But,
that being said, I don't think adding this patch to GTK+-1.2
is possible - people have already added popup menus to entries
themselves, so with a patch like this, they would suddenly 
get double menus, stuck grabs, etc. 

People will just have to be patient for GTK+-2.0.

Thanks for the patch,
                                        Owen 


Justin Maurer <justin helixcode com> writes:

> 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,

For future reference, a function like this should be static.

> +	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);

You leak a menu every time the user right clicks!

_______________________________________________
gnome-hackers mailing list
gnome-hackers gnome org
http://mail.gnome.org/mailman/listinfo/gnome-hackers




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