ui/winui/text.cpp

Sat, 30 Nov 2024 20:33:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 30 Nov 2024 20:33:16 +0100
branch
newapi
changeset 403
b59935b2de79
parent 382
de653b07050b
permissions
-rw-r--r--

fix radiobutton destroy callback (GTK)

192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
205
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
29 #include "pch.h"
b1ac0dd1d38b new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
30
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "text.h"
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../common/context.h"
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/object.h"
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
36 #include <cx/string.h>
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
37 #include <cx/allocator.h>
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
38
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "util.h"
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "container.h"
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
42
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
43
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 using namespace winrt;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 using namespace Microsoft::UI::Xaml;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 using namespace Microsoft::UI::Xaml::Controls;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 using namespace Windows::UI::Xaml::Interop;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 using namespace winrt::Windows::Foundation;
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
49 using namespace Microsoft::UI::Xaml::Markup;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
50 using namespace Microsoft::UI::Xaml::Media;
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives;
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
52 using namespace winrt::Windows::UI::Xaml::Input;
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
54
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
55 UIEXPORT UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
56 UiObject* current = uic_current_obj(obj);
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
57
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
58 // create textarea and toolkit wrapper
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
59 TextBox textarea = TextBox();
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
60 textarea.AcceptsReturn(true);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
61 ScrollViewer::SetVerticalScrollBarVisibility(textarea, ScrollBarVisibility::Auto);
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
62 UIElement elm = textarea;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
63 UiWidget* widget = new UiWidget(elm);
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
64 ui_context_add_widget_destructor(current->ctx, widget);
382
de653b07050b implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
65 ui_set_widget_groups(current->ctx, widget, args.groups);
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
66
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
67 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_TEXT);
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
68 if (var) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
69 UiText* value = (UiText*)var->value;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
70 value->obj = widget;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
71 value->undomgr = NULL;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
72 value->set = ui_textarea_set;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
73 value->get = ui_textarea_get;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
74 value->getsubstr = ui_textarea_getsubstr;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
75 value->insert = ui_textarea_insert;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
76 value->setposition = ui_textarea_setposition;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
77 value->position = ui_textarea_position;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
78 value->selection = ui_textarea_selection;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
79 value->length = ui_textarea_length;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
80 value->remove = ui_textarea_remove;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
81 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
82
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
83 // add textarea to current container
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
84 UI_APPLY_LAYOUT1(current, args);
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
85
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
86 current->container->Add(textarea, true);
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
87
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
88 return widget;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
89 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
90
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
91 UIEXPORT UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
92 return textarea;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
93 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
94
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
95 UIEXPORT void ui_text_undo(UiText *value) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
96
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
97 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
98
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
99 UIEXPORT void ui_text_redo(UiText *value) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
100
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
101 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
102
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
103 // -------------------------- getter/setter for textarea UiText --------------------------
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
104
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
105 char* ui_wtext_get(UiText *text, std::wstring &value) {
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
106 if (text->value.ptr) {
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
107 text->value.free(text->value.ptr);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
108 }
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
109
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
110 text->value.ptr = wchar2utf8(value.c_str(), value.length());
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
111 text->value.free = free;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
112
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
113 return text->value.ptr;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
114 }
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
115
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
116 std::wstring ui_wtext_set(UiText *text, const char* value) {
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
117 if (text->value.ptr) {
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
118 text->value.free(text->value.ptr);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
119 }
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
120
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
121 text->value.ptr = _strdup(value);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
122 text->value.free = free;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
123
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
124 int len;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
125 wchar_t* wstr = str2wstr(value, &len);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
126 std::wstring s(wstr);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
127 free(wstr);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
128
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
129 return s;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
130 }
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
131
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
132 extern "C" char* ui_textarea_get(UiText *text) {
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
133 UiWidget* widget = (UiWidget*)text->obj;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
134 TextBox box = widget->uielement.as<TextBox>();
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
135 std::wstring wstr(box.Text());
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
136 return ui_wtext_get(text, wstr);
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
137 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
138
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
139 extern "C" void ui_textarea_set(UiText *text, const char *newvalue) {
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
140 UiWidget* widget = (UiWidget*)text->obj;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
141 TextBox box = widget->uielement.as<TextBox>();
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
142 box.Text(ui_wtext_set(text, newvalue));
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
143 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
144
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
145 extern "C" char* ui_textarea_getsubstr(UiText *text, int begin, int end) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
146 return NULL;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
147 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
148
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
149 extern "C" void ui_textarea_insert(UiText *text, int pos, char *str) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
150
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
151 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
152
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
153 extern "C" void ui_textarea_setposition(UiText *text, int pos) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
154
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
155 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
156
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
157 extern "C" int ui_textarea_position(UiText *text) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
158 return 0;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
159 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
160
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
161 extern "C" void ui_textarea_selection(UiText *text, int *begin, int *end) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
162
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
163 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
164
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
165 extern "C" int ui_textarea_length(UiText *text) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
166 return 0;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
167 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
168
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
169 extern "C" void ui_textarea_remove(UiText *text, int begin, int end) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
170
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
171 }
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
172
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
173
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
174
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
175
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 UIWIDGET ui_textfield_create(UiObject* obj, UiTextFieldArgs args) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 UiObject* current = uic_current_obj(obj);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 // create textbox and toolkit wrapper
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 TextBox textfield = TextBox();
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 UIElement elm = textfield;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 UiWidget* widget = new UiWidget(elm);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 ui_context_add_widget_destructor(current->ctx, widget);
382
de653b07050b implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
184 ui_set_widget_groups(current->ctx, widget, args.groups);
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 if (var) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 UiString* value = (UiString*)var->value;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 value->obj = widget;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 value->get = ui_textfield_get;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 value->set = ui_textfield_set;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 // listener for notifying observers
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 // TODO:
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
197 // add textfield to current container
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 UI_APPLY_LAYOUT1(current, args);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 current->container->Add(textfield, false);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 return widget;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs args) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 return ui_textfield_create(obj, args);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 UiObject* current = uic_current_obj(obj);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 // create textbox and toolkit wrapper
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 PasswordBox textfield = PasswordBox();
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 UIElement elm = textfield;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 UiWidget* widget = new UiWidget(elm);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 ui_context_add_widget_destructor(current->ctx, widget);
382
de653b07050b implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
217 ui_set_widget_groups(current->ctx, widget, args.groups);
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 if (var) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 UiString* value = (UiString*)var->value;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 value->obj = widget;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 value->get = ui_passwordfield_get;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 value->set = ui_passwordfield_set;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 // listener for notifying observers
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 // TODO:
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
230 // add textfield to current container
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 UI_APPLY_LAYOUT1(current, args);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 current->container->Add(textfield, false);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 return widget;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 // -------------------------- getter/setter for textfield UiString --------------------------
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
241 char* ui_wstring_get(UiString* str, std::wstring &value) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 if (str->value.ptr) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 str->value.free(str->value.ptr);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 str->value.ptr = wchar2utf8(value.c_str(), value.length());
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 str->value.free = free;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 return str->value.ptr;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
252 std::wstring ui_wstring_set(UiString* str, const char* value) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 if (str->value.ptr) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 str->value.free(str->value.ptr);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 str->value.ptr = _strdup(value);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 str->value.free = free;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 int len;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 wchar_t* wstr = str2wstr(value, &len);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 std::wstring s(wstr);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 free(wstr);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 return s;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
268 char* ui_textfield_get(UiString * str) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 UiWidget* widget = (UiWidget*)str->obj;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 TextBox box = widget->uielement.as<TextBox>();
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 std::wstring wstr(box.Text());
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
272 return ui_wstring_get(str, wstr);
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
275 void ui_textfield_set(UiString * str, const char* newvalue) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 UiWidget* widget = (UiWidget*)str->obj;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 TextBox box = widget->uielement.as<TextBox>();
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
278 box.Text(ui_wstring_set(str, newvalue));
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
282 char* ui_passwordfield_get(UiString * str) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 UiWidget* widget = (UiWidget*)str->obj;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 PasswordBox box = widget->uielement.as<PasswordBox>();
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 std::wstring wstr(box.Password());
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
286 return ui_wstring_get(str, wstr);
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
289 void ui_passwordfield_set(UiString * str, const char* newvalue) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 UiWidget* widget = (UiWidget*)str->obj;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 PasswordBox box = widget->uielement.as<PasswordBox>();
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
292 box.Password(ui_wstring_set(str, newvalue));
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 }
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
294
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
295
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
296 // ------------------------ path textfield --------------------------------------
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
297
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
298 extern "C" static void destroy_ui_pathtextfield(void* ptr) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
299 UiPathTextField* pb = (UiPathTextField*)ptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
300 delete pb;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
301 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
302
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
303 static void ui_context_add_pathtextfield_destructor(UiContext* ctx, UiPathTextField* pb) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
304 cxMempoolRegister(ctx->mp, pb, destroy_ui_pathtextfield);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
305 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
306
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
307 static void ui_pathtextfield_clear(StackPanel& buttons) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
308 for (int i = buttons.Children().Size() - 1; i >= 0; i--) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
309 buttons.Children().RemoveAt(i);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
310 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
311 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
312
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
313 static void ui_pathfield_free_pathelms(UiPathElm* elms, size_t nelm) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
314 if (!elms) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
315 return;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
316 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
317 for (int i = 0; i < nelm; i++) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
318 UiPathElm e = elms[i];
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
319 free(e.name);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
320 free(e.path);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
321 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
322 free(elms);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
323 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
324
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
325 UiPathTextField::~UiPathTextField() {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
326 ui_pathfield_free_pathelms(this->current_path, this->current_path_nelms);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
327 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
328
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
329 static UiPathElm* default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
330 cxstring *pathelms;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
331 size_t nelm = cx_strsplit_a(cxDefaultAllocator, cx_strn(full_path, len), CX_STR("/"), 4096, &pathelms);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
332
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
333 if (nelm == 0) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
334 *ret_nelm = 0;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
335 return nullptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
336 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
337
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
338 UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
339 size_t n = nelm;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
340 int j = 0;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
341 for (int i = 0; i < nelm; i++) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
342 cxstring c = pathelms[i];
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
343 if (c.length == 0) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
344 if (i == 0) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
345 c.length = 1;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
346 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
347 else {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
348 n--;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
349 continue;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
350 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
351 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
352
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
353 cxmutstr m = cx_strdup(c);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
354 elms[j].name = m.ptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
355 elms[j].name_len = m.length;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
356
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
357 size_t elm_path_len = c.ptr + c.length - full_path;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
358 cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
359 elms[j].path = elm_path.ptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
360 elms[j].path_len = elm_path.length;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
361
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
362 j++;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
363 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
364 *ret_nelm = n;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
365
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
366 return elms;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
367 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
368
240
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
369 int ui_pathtextfield_update(UiPathTextField* pb, const char *full_path) {
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
370 Grid grid = pb->grid;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
371
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
372 ui_pathelm_func getpathelm = pb->getpathelm;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
373 void* getpathelmdata = pb->getpathelmdata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
374
240
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
375 size_t full_path_len = full_path ? strlen(full_path) : 0;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
376
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
377 size_t nelm = 0;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
378 UiPathElm* path_elm = getpathelm(full_path, full_path_len, &nelm, getpathelmdata);
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
379 if (!path_elm) {
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
380 return 1;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
381 }
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
382
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
383 // hide textbox, show button panel
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
384 pb->textbox.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
385 pb->buttons.Visibility(Visibility::Visible);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
386
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
387 // clear old buttons
240
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
388 ui_pathtextfield_clear(pb->buttons);
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
389
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
390 ui_pathfield_free_pathelms(pb->current_path, pb->current_path_nelms);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
391 pb->current_path = path_elm;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
392 pb->current_path_nelms = nelm;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
393
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
394 // add new buttons
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
395 int j = 0;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
396 for (int i = 0; i < nelm;i++) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
397 UiPathElm elm = path_elm[i];
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
398 wchar_t* wstr = str2wstr_len(elm.name, elm.name_len, nullptr);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
399 Button button = Button();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
400 button.Content(box_value(wstr));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
401 free(wstr);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
402
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
403 if (pb->onactivate) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
404 button.Click([pb, j, elm](IInspectable const& sender, RoutedEventArgs) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
405 // copy elm.path because it could be a non-terminated string
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
406 cxmutstr elmpath = cx_strdup(cx_strn(elm.path, elm.path_len));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
407
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
408 UiEvent evt;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
409 evt.obj = pb->obj;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
410 evt.window = evt.obj->window;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
411 evt.document = evt.obj->ctx->document;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
412 evt.eventdata = elmpath.ptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
413 evt.intval = j;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
414 pb->onactivate(&evt, pb->onactivatedata);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
415
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
416 free(elmpath.ptr);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
417 });
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
418 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
419
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
420 Thickness t = { 0, 0, 1, 0 };
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
421 CornerRadius c = { 0 ,0, 0, 0 };
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
422 button.BorderThickness(t);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
423 button.CornerRadius(c);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
424
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
425 pb->buttons.Children().Append(button);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
426
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
427 j++;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
428 }
240
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
429
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
430 return 0;
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
431 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
432
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
433 char* ui_path_textfield_get(UiString * str) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
434 UiPathTextField* widget = (UiPathTextField*)str->obj;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
435 TextBox box = widget->textbox;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
436 std::wstring wstr(box.Text());
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
437 return ui_wstring_get(str, wstr);
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
438 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
439
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
440 void ui_path_textfield_set(UiString* str, const char* newvalue) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
441 UiPathTextField* widget = (UiPathTextField*)str->obj;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
442 TextBox box = widget->textbox;
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
443 box.Text(ui_wstring_set(str, newvalue));
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
444 ui_pathtextfield_update(widget, newvalue);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
445 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
446
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
447 UIEXPORT UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs args) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
448 UiObject* current = uic_current_obj(obj);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
449
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
450 // create view and toolkit wrapper
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
451 Border pathbar = Border();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
452
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
453 IInspectable bgRes = Application::Current().Resources().Lookup(box_value(L"TextControlBackground"));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
454 IInspectable borderThicknessRes = Application::Current().Resources().Lookup(box_value(L"TextControlBorderThemeThickness"));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
455 IInspectable borderBrushRes = Application::Current().Resources().Lookup(box_value(L"TextControlBorderBrush"));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
456 // IInspectable cornerRes = Application::Current().Resources().Lookup(box_value(L"TextControlCornerRadius"));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
457
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
458 Brush bgBrush = unbox_value<Brush>(bgRes);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
459 Thickness border = unbox_value<Thickness>(borderThicknessRes);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
460 Brush borderBrush = unbox_value<Brush>(borderBrushRes);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
461 CornerRadius cornerRadius = { 4, 4, 4, 4 }; //unbox_value<CornerRadius>(cornerRes);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
462
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
463 pathbar.Background(bgBrush);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
464 pathbar.BorderBrush(borderBrush);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
465 pathbar.BorderThickness(border);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
466 pathbar.CornerRadius(cornerRadius);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
467
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
468 Grid content = Grid();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
469 pathbar.Child(content);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
470
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
471 GridLength gl;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
472 gl.Value = 0;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
473 gl.GridUnitType = GridUnitType::Auto;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
474
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
475 ColumnDefinition coldef = ColumnDefinition();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
476 coldef.Width(gl);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
477 content.ColumnDefinitions().Append(coldef);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
478
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
479 gl.Value = 1;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
480 gl.GridUnitType = GridUnitType::Star;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
481
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
482 ColumnDefinition coldef2 = ColumnDefinition();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
483 coldef2.Width(gl);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
484 content.ColumnDefinitions().Append(coldef2);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
485
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
486 TextBox pathTextBox = TextBox();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
487 Thickness t = { 0, 0, 0, 0 };
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
488 CornerRadius c = { 0 ,0, 0, 0 };
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
489 pathTextBox.BorderThickness(t);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
490 //pathTextBox.CornerRadius(c);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
491
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
492
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
493 pathTextBox.HorizontalAlignment(HorizontalAlignment::Stretch);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
494 content.SetColumn(pathTextBox, 0);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
495 content.SetColumnSpan(pathTextBox, 2);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
496
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
497 content.Children().Append(pathTextBox);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
498
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
499 // stackpanel for buttons
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
500 StackPanel buttons = StackPanel();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
501 buttons.Orientation(Orientation::Horizontal);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
502 buttons.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
503 content.SetColumn(buttons, 0);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
504 content.Children().Append(buttons);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
505
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
506 TextBlock filler = TextBlock();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
507 filler.VerticalAlignment(VerticalAlignment::Stretch);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
508 //filler.Text(winrt::hstring(L"hello filler"));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
509
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
510 filler.HorizontalAlignment(HorizontalAlignment::Stretch);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
511 filler.VerticalAlignment(VerticalAlignment::Stretch);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
512 content.SetColumn(filler, 1);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
513 content.Children().Append(filler);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
514
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
515 filler.PointerPressed(
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
516 winrt::Microsoft::UI::Xaml::Input::PointerEventHandler(
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
517 [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
518 pathTextBox.Visibility(Visibility::Visible);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
519 buttons.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
520 filler.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
521 pathTextBox.SelectionStart(pathTextBox.Text().size());
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
522 pathTextBox.SelectionLength(0);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
523 pathTextBox.Focus(FocusState::Keyboard);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
524 })
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
525 );
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
526
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
527 //pathTextBox.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
528
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
529 UiPathTextField* uipathbar = new UiPathTextField;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
530 ui_context_add_pathtextfield_destructor(current->ctx, uipathbar);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
531 uipathbar->grid = content;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
532 uipathbar->buttons = buttons;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
533 uipathbar->textbox = pathTextBox;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
534 uipathbar->filler = filler;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
535 uipathbar->obj = obj;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
536 uipathbar->getpathelm = args.getpathelm ? args.getpathelm : default_pathelm_func;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
537 uipathbar->getpathelmdata = args.getpathelmdata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
538 uipathbar->onactivate = args.onactivate;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
539 uipathbar->onactivatedata = args.onactivatedata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
540 uipathbar->ondragstart = args.ondragstart;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
541 uipathbar->ondragstartdata = args.ondragstartdata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
542 uipathbar->ondragcomplete = args.ondragcomplete;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
543 uipathbar->ondragcompletedata = args.ondragcompletedata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
544 uipathbar->ondrop = args.ondrop;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
545 uipathbar->ondropdata = args.ondropsdata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
546
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
547
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
548 pathTextBox.KeyDown(
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
549 winrt::Microsoft::UI::Xaml::Input::KeyEventHandler(
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
550 [=](winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::KeyRoutedEventArgs const& e) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
551 auto key = e.Key();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
552 bool showButtons = false;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
553 bool update = false;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
554 if (key == Windows::System::VirtualKey::Escape) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
555 showButtons = true;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
556 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
557 else if (key == Windows::System::VirtualKey::Enter) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
558 showButtons = true;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
559 update = true;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
560 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
561
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
562 if (showButtons) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
563 pathTextBox.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
564 buttons.Visibility(Visibility::Visible);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
565 filler.Visibility(Visibility::Visible);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
566 if (update) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
567 std::wstring value(pathTextBox.Text());
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
568 char* full_path = wchar2utf8(value.c_str(), value.length());
240
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
569
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
570 if (!ui_pathtextfield_update(uipathbar, full_path)) {
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
571 UiEvent evt;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
572 evt.obj = obj;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
573 evt.window = obj->window;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
574 evt.document = obj->ctx->document;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
575 evt.eventdata = full_path;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
576 evt.intval = -1;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
577 args.onactivate(&evt, args.onactivatedata);
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
578 }
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
579
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
580 free(full_path);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
581 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
582
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
583 //buttons.Focus(FocusState::Keyboard);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
584 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
585 })
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
586 );
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
587
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
588
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
589 UIElement elm = pathbar;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
590 UiWidget* widget = new UiWidget(elm);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
591 widget->data1 = uipathbar;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
592 ui_context_add_widget_destructor(current->ctx, widget);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
593
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
594 // bind var
239
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
595 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING);
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
596 if (var) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
597 UiString* value = (UiString*)var->value;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
598 value->obj = uipathbar;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
599 value->get = ui_path_textfield_get;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
600 value->set = ui_path_textfield_set;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
601 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
602
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
603 // add listview to current container
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
604 UI_APPLY_LAYOUT1(current, args);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
605
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
606 current->container->Add(pathbar, false);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
607
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
608 return widget;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
609 }

mercurial