Re: Having problems with gtk_editable_copy_clipboard
- From: "Bradley F. Hartman" <hartman mcci-arl-va com>
- To: gtk-list gnome org
- Cc: otaylor redhat com
- Subject: Re: Having problems with gtk_editable_copy_clipboard
- Date: Wed, 27 Mar 2002 15:25:59 -0500 (EST)
> copy_clipboard signal is emitted when you call
> gtk_editable_copy_clipboard(), and you call
> gtk_editable_copy_clipboard() from the signal handler.
Whew... The documentation indicates that this function "Causes the
characters in the current selection to be copied to the clipboard." This
is why I used it. I guess it implements this functionality by emitting
the signal, copy-clipboard. Because, in my case, I'm already in the
handler for this signal, infinite recursion occurs. This might be
something that could be added to the docs (just a suggestion - if it
is already in the docs somewhere, please let me know!).
I found docs on the GtkClipboard class. I believe I can manually copy
text onto the clipboard via something like the following:
/* Get the selected region. */
if ( gtk_editable_get_selection_bounds( GTK_EDITABLE( widget ),
&start, &end ) )
{
entry_text = gtk_editable_get_chars( GTK_EDITABLE( widget ), start, end );
if ( entry_text )
{
/* Get the default clipboard. */
clipboard = gtk_clipboard_get( GDK_NONE );
/* Put the contents of the text entry onto the clipboard. */
/* -1 for parameter #3 indicates that strlen( entry_text ) + 1
* should be used.
*/
gtk_clipboard_set_text( clipboard, entry_text, -1 );
g_free( (gchar *)entry_text );
entry_text = NULL;
}
}
I've tested this and it seems to work. What is not clear to me is how
to get the contents of the clipboard. The clipboard class is
characterized by several functions. For my first attempt, I selected what
I believed to be the easiest function, gtk_clipboard_request_text(), as
shown below:
void paste_clipboard( GtkWidget *widget,
GtkWidget *entry)
{
GtkClipboard *clipboard;
if ( gtk_editable_get_editable( GTK_EDITABLE( widget ) ) == TRUE )
{
/* Get the default clipboard. */
clipboard = gtk_clipboard_get( GDK_NONE );
g_print( "paste_clipboard: Registering request for clipboard data.\n" );
gtk_clipboard_request_text(
clipboard,
(GtkClipboardTextReceivedFunc)my_paste_function,
(gpointer)widget
);
}
g_print( "Paste Clipboard executed.\n" );
}
When I run my program, while I have verified that gtk_clipboard_request_text()
is executed, the function, my_paste_function(), is never called. At the
same time, the text I pasted *does* appear in the text entry field of the GUI
(I am assuming via the default handlers).
I have several questions for the experts.
1. Why isn't my_paste_function(), in the above example, called?
2. Is gtk_clipboard_request_text() the easiest way to manually
get the contents of the clipboard via the GtkClipboard class?
3. The GtkClipboard class is characterized by a type with which I am not
familiar (GtkTargetEntry) and the documentation on this type is a little
sparse (for a newbie, anyway). Does anyone have a small code sample that
shows how this type is used?
4. There is a function to directly add text to a clipboard. Why is there
no corresponding function to extract text from the clipboard? One must
register a function via the GtkClipboard interface to extract data. I'm
asking this question because I believe it will help me to understand what
is really going on with the clipboard.
Thanks!
Brad
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]