RE: copy text the to the clipboard



On Fri, 2003-04-04 at 02:34, Murray Cumming Comneon com wrote:
> It depends on the widget.  For simple text, gtk_editable_copy_clipboard()
> might be what you need. Or there's something similar for GtkTextView.
> 
> For custom data you'll need to understand the concepts. Here are some C++
> examples:
> http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ch16.html

Since that's pretty complicated, let me point out, to copy a string to
the clipboard, all you need is:

 GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 gtk_clipboard_set_text (clipboard, "My Text", -1);

Getting the text on the clipboard can be as simple as:

 char *my_text = gtk_clipboard_wait_for_text (clipboard);
  /* use text */
 g_free (my_text);

[ Note, gtk_clipboard_wait_for_text() runs a recursive main loop,
  so any of your applications callbacks could be invoked while
  it is running ]

Regards,
                                            Owen





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