3. Cut, Copy and Paste

In this section you will learn how to do common clipboard related activities like cut, copy and paste. First, you will have to get hold of a clipboard object using


GtkClipboard *gtk_clipboard_get( GdkAtom selection );
Usually, a value of GDK_NONE is passed to selection, which gives the default clipboard. A value of GDK_SELECTION_PRIMARY identifies the primary X selection.

Selected text can be then copied to the clipboard using


void gtk_text_buffer_copy_clipboard( GtkTextBuffer *buffer,
                                     GtkClipboard *clipboard );
The clipboard is a clipboard object obtained from gtk_clipboard_get.

Selected text can be cut to the clipboard using


void gtk_text_buffer_cut_clipboard( GtkTextBuffer *buffer,
                                    GtkClipboard *clipboard, 
                                    gboolean default_editable );
For portions of the selected text that do not have the editable tag applied, the edit-ability is assumed from default_editable.

Text can be pasted from the clipboard using


void gtk_text_buffer_paste_clipboard( GtkTextBuffer *buffer,
                                      GtkClipboard *clipboard,
                                      GtkTextIter *override_location,
                                      gboolean default_editable );
If override_location is not NULL, text is inserted at the iter specified by override_location. Else, text is inserted at the current cursor location.