termio: wrap selection_get api

This commit is contained in:
Boris Faure 2023-08-21 16:15:08 +02:00
parent 1f59d6cb35
commit 4a39744ad7
Signed by: borisfaure
GPG Key ID: EAA9CD729F522998
3 changed files with 50 additions and 8 deletions

View File

@ -1011,6 +1011,15 @@ _lost_selection(void *data, Elm_Sel_Type selection)
}
}
void termio_selection_buffer_get_cb(Evas_Object *obj,
Elm_Sel_Type type,
Elm_Sel_Format format,
Elm_Drop_Cb cb,
void *data)
{
elm_cnp_selection_get(obj, type, format, cb, data);
}
/* Set the @type selection to @text.
* This does not modify the widget itself */
void

View File

@ -18,6 +18,11 @@ void termio_win_set(Evas_Object *obj, Evas_Object *win);
void termio_theme_set(Evas_Object *obj, Evas_Object *theme);
Eina_Bool termio_selection_exists(const Evas_Object *obj);
void termio_set_selection_text(Evas_Object *obj, Elm_Sel_Type type, const char *text);
void termio_selection_buffer_get_cb(Evas_Object *obj,
Elm_Sel_Type type,
Elm_Sel_Format format,
Elm_Drop_Cb cb,
void *data);
void termio_scroll_top_backlog(Evas_Object *obj);
void termio_scroll_delta(Evas_Object *obj, int delta, int by_page);
void termio_scroll_set(Evas_Object *obj, int scroll);

View File

@ -360,9 +360,38 @@ termio_bg_get(const Evas_Object *obj EINA_UNUSED)
}
static char *_sel_primary = NULL;
static char *_sel_secondary = NULL;
static char *_sel_clipboard = NULL;
void termio_selection_buffer_get_cb(Evas_Object *obj,
Elm_Sel_Type type,
Elm_Sel_Format format EINA_UNUSED,
Elm_Drop_Cb cb,
void *data)
{
Elm_Selection_Data ev = {};
switch (type)
{
case ELM_SEL_TYPE_PRIMARY:
ev.data = _sel_primary;
if (_sel_primary)
ev.len = strlen(_sel_primary) + 1;
else
ev.len = 0;
cb(data, obj, &ev);
break;
case ELM_SEL_TYPE_CLIPBOARD:
ev.data = _sel_clipboard;
if (_sel_clipboard)
ev.len = strlen(_sel_clipboard) + 1;
else
ev.len = 0;
cb(data, obj, &ev);
break;
default:
break;
}
}
void
termio_set_selection_text(Evas_Object *obj EINA_UNUSED,
Elm_Sel_Type type, const char *text)
@ -371,18 +400,17 @@ termio_set_selection_text(Evas_Object *obj EINA_UNUSED,
{
case ELM_SEL_TYPE_PRIMARY:
free(_sel_primary);
if (text)
if (text[0])
_sel_primary = strdup(text);
break;
case ELM_SEL_TYPE_SECONDARY:
free(_sel_secondary);
if (text)
_sel_secondary = strdup(text);
else
_sel_primary = NULL;
break;
case ELM_SEL_TYPE_CLIPBOARD:
free(_sel_clipboard);
if (text)
if (text[0])
_sel_clipboard = strdup(text);
else
_sel_clipboard = NULL;
break;
default:
break;