Etk
Main Page Object Hierarchy Data Structures Related Pages
Etk

The selection and clipboard system of Etk


Detailed Description

Some functions to manipulate the clipboard and the selections.

The selection system is used to add copy/paste support to Etk widgets.
There are mainly two types of selections:

  • The primary selection that is used to copy text when some text is selected, and to paste it when the middle-button of the mouse is clicked
  • The clipboard selection that is the traditional copy/paste, used when the user presses CTRL+X/C/V

There is a third selection type called "secondary selection", but it is almost never used.

You will almost never have to use directly the etk_selection_*() functions, they are already used in existing widgets. However, you may have to use them if you are creating a new widget to add copy/paste support to it.
The following example shows how to add clipboard support to a widget:

 //Called when the content of the clipboard is received (after we called etk_selection_text_request())
 static void _selection_received_cb(Etk_Widget *your_widget, Etk_Selection_Event *event, void *data)
 {
    if (event->type == ETK_SELECTION_TEXT)
    {
       printf("Pasted text: %s\n", event->data->text);
       //Here, you can do whatever you want with the pasted text
    }
 }

 //Connect the widget to the signal "selection-received" to be notified
 //when the content of the clipboard is received, after a paste (you only need to call this line once)
 etk_signal_connect("selection-received", ETK_OBJECT(your_widget), ETK_CALLBACK(_selection_received_cb), NULL);

 //To paste the content of the clipboard into your widget (on CTRL+V for example)
 //It will emit the signal "selection-received" when the content of the clipboard is received
 etk_selection_text_request(ETK_SELECTION_CLIPBOARD, your_widget);

 //To set the text of the clipboard (on CTRL+C for example)
 etk_selection_text_set(ETK_SELECTION_CLIPBOARD, "the text to set");


Data Structures

struct  Etk_Selection_Event
 The event structure sent to the target widget when the content of a selection is received after a request (through the signal "selection_received"). More...

Enumerations

enum  Etk_Selection_Type {
  ETK_SELECTION_PRIMARY,
  ETK_SELECTION_SECONDARY,
  ETK_SELECTION_CLIPBOARD
}
 The different types of selection. More...
enum  Etk_Selection_Content_Type { ETK_SELECTION_TEXT }
 The different types of content of a selection. More...

Functions

void etk_selection_text_set (Etk_Selection_Type selection, const char *text)
 Sets the text of the given selection.
void etk_selection_text_request (Etk_Selection_Type selection, Etk_Widget *target)
 Requests the text from a selection.
void etk_selection_clear (Etk_Selection_Type selection)
 Clears the given selection.


Enumeration Type Documentation

enum Etk_Selection_Type

The different types of selection.

Enumerator:
ETK_SELECTION_PRIMARY  The primary selection: used when a text is selected. Its content is traditionally pasted when the middle button of the mouse is pressed
ETK_SELECTION_SECONDARY  The secondary selection: almost never used
ETK_SELECTION_CLIPBOARD  The clipboard: used when Ctrl+X/C/V is pressed (traditional copy/paste)

enum Etk_Selection_Content_Type

The different types of content of a selection.

Enumerator:
ETK_SELECTION_TEXT  The content of the selection is a text


Function Documentation

void etk_selection_text_set ( Etk_Selection_Type  selection,
const char *  text 
)

Sets the text of the given selection.

Parameters:
selection the selection type whose text should be set
text the text to set

References etk_engine_selection_text_set().

void etk_selection_text_request ( Etk_Selection_Type  selection,
Etk_Widget *  target 
)

Requests the text from a selection.

Parameters:
selection the selection you want to request the text from
target the widget that will receive the selection. When Etk receives the requested text from the selection, it will emit the signal "selection-received" to the widget target

References etk_engine_selection_text_request().

void etk_selection_clear ( Etk_Selection_Type  selection  ) 

Clears the given selection.

Parameters:
selection the selection to clear

References etk_engine_selection_clear().