# HG changeset patch # User Olaf Wintermann # Date 1769022779 -3600 # Node ID 0db713dc859051239c9e12d6ce7d808640864e4a # Parent dee2ca687a14ab2e3ec077c310f781f3274b4a76 extend textfield API (QT) diff -r dee2ca687a14 -r 0db713dc8590 ucx/cx/string.h --- a/ucx/cx/string.h Fri Jan 16 11:56:17 2026 +0100 +++ b/ucx/cx/string.h Wed Jan 21 20:12:59 2026 +0100 @@ -1335,10 +1335,10 @@ bool cx_strtok_next_(CxStrtokCtx *ctx, cxstring *token); #ifdef __cplusplus -CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxstring *token) { +CX_CPPDECL bool cx_strtok_next(CxStrtokCtx *ctx, cxstring *token) { return cx_strtok_next_(ctx, token); } -CX_CPPDECL cx_strtok_next(CxStrtokCtx *ctx, cxmutstr *token) { +CX_CPPDECL bool cx_strtok_next(CxStrtokCtx *ctx, cxmutstr *token) { // Note: this is actually UB - fixed with start_lifetime_as() in C++23 // but it works on all supported platforms return cx_strtok_next_(ctx, reinterpret_cast(token)); diff -r dee2ca687a14 -r 0db713dc8590 ui/qt/text.cpp --- a/ui/qt/text.cpp Fri Jan 16 11:56:17 2026 +0100 +++ b/ui/qt/text.cpp Wed Jan 21 20:12:59 2026 +0100 @@ -278,3 +278,50 @@ } str->value.ptr = NULL; } + +void ui_textfield_focus(UIWIDGET textfield) { + QLineEdit *edit = static_cast(textfield); + edit->setFocus(); + edit->selectAll(); +} + +void ui_textfield_focus_without_selecting(UIWIDGET textfield) { + QLineEdit *edit = static_cast(textfield); + edit->setFocus(); +} + +void ui_textfield_set_selection(UIWIDGET textfield, int begin, int end) { + QLineEdit *edit = static_cast(textfield); + if (begin < 0) { + begin = 0; + } + if (end < begin) { + end = begin; + } + edit->setSelection(begin, end - begin); +} + +void ui_textfield_select_all(UIWIDGET textfield) { + QLineEdit *edit = static_cast(textfield); + edit->selectAll(); +} + +void ui_textfield_set_editable(UIWIDGET textfield, UiBool editable) { + QLineEdit *edit = static_cast(textfield); + edit->setReadOnly(!editable); +} + +UiBool ui_textfield_is_editable(UIWIDGET textfield) { + QLineEdit *edit = static_cast(textfield); + return !edit->isReadOnly(); +} + +void ui_textfield_set_position(UIWIDGET textfield, int pos) { + QLineEdit *edit = static_cast(textfield); + edit->setCursorPosition(pos); +} + +int ui_textfield_get_position(UIWIDGET textfield) { + QLineEdit *edit = static_cast(textfield); + return edit->cursorPosition(); +}