Skip to content

Commit

Permalink
macOS support for textview_select, textview_copy, textview_paste, tex…
Browse files Browse the repository at this point in the history
…tview_cut, textview_OnFilter.
  • Loading branch information
frang75 committed Jul 6, 2024
1 parent 96f6fc2 commit f6f7ca5
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 42 deletions.
6 changes: 5 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

* macOS support for `edit_select()`. [Commit](https://github.com/frang75/nappgui_src/commit/d54bdc23f73800817975a840d3d927f00b720452).
* macOs support for `edit_copy()`, `edit_paste()` and `edit_cut()`. [Commit](https://github.com/frang75/nappgui_src/commit/63e667c951ff4850b25de073643c9bdda7069e5e).
* New demo on text selection and clipboard. [Doc](https://nappgui.com/en/howto/guihello.html#h5)
* New demo on text selection and clipboard. [Doc](https://nappgui.com/en/howto/guihello.html#h5).
* macOS support for `textview_select()`.
* macOS support for `textview_copy()`, `textview_paste()` and `textview_cut()`.
* macOS support for `textview_OnFilter()`.
* `unicode_move()`.

## v1.4.2 - Jun 30, 2024 (r5177)

Expand Down
24 changes: 12 additions & 12 deletions demo/guihello/seltext.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ static void i_OnEditFilter(SelData *data, Event *e)
cassert_no_null(data);

/*
* Convert the inserted text in caps
* p->text the control current text (const)
* r->text the new filterd text
* p->cpos current caret position
* Convert the inserted text in caps.
* p->text the control current text (const).
* r->text the new filterd text.
* p->cpos current caret position.
* r->apply = TRUE means the editbox text has to be updated.
* p->len number of chars inserted at left of caret (those to be converted to caps)
* We are working with UTF8-Strings. No 1-byte/1-char parity. Sequential access.
* p->len number of chars inserted at left of caret (to caps).
* We are working with UTF8-Strings. Sequential access.
*/
if (button_get_state(data->caps) == ekGUI_ON && p->len > 0)
{
Expand Down Expand Up @@ -147,13 +147,13 @@ static void i_OnTextViewFilter(SelData *data, Event *e)
cassert_no_null(data);

/*
* Convert the inserted text in caps
* p->text the control current text (const)
* r->text the new filterd text
* p->cpos current caret position
* Convert the inserted text in caps.
* p->text the inserted text only (const).
* r->text the new filterd text.
* p->cpos current caret position.
* r->apply = TRUE means the editbox text has to be updated.
* p->len number of chars inserted at left of caret (those to be converted to caps)
* We are working with UTF8-Strings. No 1-byte/1-char parity. Sequential access.
* p->len number of chars inserted at left of caret (to caps).
* We are working with UTF8-Strings. Sequential access.
*/
if (button_get_state(data->caps) == ekGUI_ON && p->len > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion prj/build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5232
5242
5 changes: 4 additions & 1 deletion src/gui/textview.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ TextView *textview_create(void)
context->func_text_set_prop(ositem, (enum_t)ekGUI_TEXT_AFPARSPACE, (void *)&afpspace);
_component_init(&view->component, context, PARAM(type, ekGUI_TYPE_TEXTVIEW), &ositem);
context->func_text_OnFocus(view->component.ositem, obj_listener(view, i_OnFocus, TextView));
context->func_text_OnFilter(view->component.ositem, obj_listener(view, i_OnFilter, TextView));
font_destroy(&font);
return view;
}
Expand All @@ -101,6 +100,10 @@ void textview_OnFilter(TextView *view, Listener *listener)
{
cassert_no_null(view);
listener_update(&view->OnFilter, listener);
if (listener != NULL)
view->component.context->func_text_OnFilter(view->component.ositem, obj_listener(view, i_OnFilter, TextView));
else
view->component.context->func_text_OnFilter(view->component.ositem, NULL);
}

/*---------------------------------------------------------------------------*/
Expand Down
18 changes: 18 additions & 0 deletions src/osgui/gtk/ostext.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,24 @@ void ostext_focus(OSText *view, const bool_t focus)
else
_oscontrol_widget_remove_provider(view->control.widget, view->border_color);
}

if (focus == TRUE)
{
/* Select */
g_idle_add((GSourceFunc)i_select, view);
}
else
{
/* Cache the current selection and deselect */
GtkTextIter start, end;
GtkTextBuffer *tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view->tview));
GtkTextIter iter;
gtk_text_buffer_get_selection_bounds(tbuf, &start, &end);
view->select_start = (int32_t)gtk_text_iter_get_offset(&start);
view->select_end = (int32_t)gtk_text_iter_get_offset(&end);
gtk_text_buffer_get_start_iter(tbuf, &iter);
gtk_text_buffer_select_range(tbuf, &iter, &iter);
}
}

/*---------------------------------------------------------------------------*/
Expand Down
7 changes: 3 additions & 4 deletions src/osgui/osx/osedit.m
Original file line number Diff line number Diff line change
Expand Up @@ -692,17 +692,16 @@ void osedit_clipboard(OSEdit *edit, const clipboard_t clipboard)
cassert_no_null(ledit);
if (ledit->editor != nil)
{
NSRange r = [ledit->editor selectedRange];
switch (clipboard)
{
case ekCLIPBOARD_COPY:
[ledit->editor copy:nil];
[ledit->editor copy:ledit->editor];
break;
case ekCLIPBOARD_CUT:
[ledit->editor cut:ledit->field];
[ledit->editor cut:ledit->editor];
break;
case ekCLIPBOARD_PASTE:
[ledit->editor paste:ledit->field];
[ledit->editor paste:ledit->editor];
break;
}
}
Expand Down
Loading

0 comments on commit f6f7ca5

Please sign in to comment.