RE: Sun Cut/Copy/Paste keys



Using Gtk+1.2.10, I connect the following function to the "key_press_event" and
then call the edit function associated with the key pressed (Note: this also
works with Gtk+1.2.8).

/* Function to catch keyboard shortcuts (i.e. sun keyboard "copy", "paste",
etc.) */
gboolean filter_edit_shortcuts(GtkWidget *calling_widget, GdkEventKey
*key_press_event, GtkWidget *window)
{
	/* Sun keyboard "Copy" button */
	if ( key_press_event->keyval == GDK_F16 )
	{
		copy_to_clipboard(calling_widget, window);

		/* Do not propogate event */
		return(TRUE);
	}
	/* Sun keyboard "Paste" button */
	else if ( key_press_event->keyval == GDK_F18 )
	{
		paste_from_clipboard(calling_widget, window);

		/* Do not propogate event */
		return(TRUE);
	}
	/* Sun keyboard "Cut" button */
	else if ( key_press_event->keyval == GDK_F20 )
	{
		cut_to_clipboard(calling_widget, window);

		/* Do not propogate event */
		return(TRUE);
	}


	/* Propogate event */
	return(FALSE);
}
/* End of filter_edit_shortcuts() */



/* Function to copy selected focus widget text to the clipboard */
void copy_to_clipboard(GtkWidget *calling_widget, GtkWidget *window)
{
	/* Declaring local variables */
	GtkWidget *widget;


	/* Getting the focus widget of window emitting the copy request */
	if ( GTK_WINDOW(window)->focus_widget )
		widget = GTK_WIDGET(GTK_WINDOW(window)->focus_widget);
	else
		return;


	/* Checking that focus widget is capable of copy request */
	if ( GTK_WIDGET_HAS_FOCUS(GTK_WIDGET(widget)) &&
GTK_IS_EDITABLE(GTK_WIDGET(widget)) )
		gtk_editable_copy_clipboard(GTK_EDITABLE(widget));
}
/* End of copy_to_clipboard() */



/* Function to cut selected focus widget text to the clipboard */
void cut_to_clipboard(GtkWidget *calling_widget, GtkWidget *window)
{
	/* Declaring local variables */
	GtkWidget *widget;


	/* Getting the focus widget of window emitting the cut request */
	if ( GTK_WINDOW(window)->focus_widget )
		widget = GTK_WIDGET(GTK_WINDOW(window)->focus_widget);
	else
		return;


	/* Checking that focus widget is capable of cut request */
	if ( GTK_WIDGET_HAS_FOCUS(GTK_WIDGET(widget)) &&
GTK_IS_EDITABLE(GTK_WIDGET(widget)) )
		gtk_editable_cut_clipboard(GTK_EDITABLE(widget));
}
/* End of cut_to_clipboard() */



/* Function to paste text from the clipboard */
void paste_from_clipboard(GtkWidget *calling_widget, GtkWidget *window)
{
	/* Declaring local variables */
	GtkWidget *widget;


	/* Getting the focus widget of window emitting the paste request */
	if ( GTK_WINDOW(window)->focus_widget )
		widget = GTK_WIDGET(GTK_WINDOW(window)->focus_widget);
	else
		return;


	/* Checking that focus widget is capable of paste request */
	if ( GTK_WIDGET_HAS_FOCUS(GTK_WIDGET(widget)) &&
GTK_IS_EDITABLE(GTK_WIDGET(widget)) )
		gtk_editable_paste_clipboard(GTK_EDITABLE(widget));
}
/* End of paste_from_clipboard() */

Hope this helps.



				-- Stupid Genius

> ----------
> From: 	Havoc Pennington[SMTP:hp redhat com]
> Sent: 	Wednesday, May 23, 2001 6:30 PM
> To: 	Spear, Don H. Jr.
> Cc: 	'gtk-list gnome org'
> Subject: 	Re: Sun Cut/Copy/Paste keys
> 
> 
> "Spear, Don H. Jr." <spear pwfl com> writes:
> > I've seen posts on this subject in the archives but no solutions so I'll
> > post once more in hopes someone smarter than me has found the answer. In a
> > text window I want to associate the Cut/Copy/Paste keys on a Sun keyboard
> > with the text functions. Can this be done?
> > 
> 
> In Gtk 2 it's something like this:
> 
>    binding "foo" {
>      bind "<ctrl>F1" {
>         cut-clipboard 
>      }
>    }
> 
>    widget "GtkTextView" binding "foo"
>    widget "GtkEditable" binding "foo"
> 
> Replacing "<ctrl>F1" with whatever the Sun keys send (the name of the
> keyval and modifiers, use 'xev' to figure it out).
> 
> But it doesn't work in stable GTK.
> 
> Havoc
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
> 




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