ui/winui/text.cpp

Tue, 12 Nov 2024 14:58:03 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 12 Nov 2024 14:58:03 +0100
branch
newapi
changeset 379
958bae372271
parent 374
eae5d6623fd3
permissions
-rw-r--r--

implement ui_dialog_window (WINUI)

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);
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
65
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
66 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
67 if (var) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
68 UiText* value = (UiText*)var->value;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
69 value->obj = widget;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
70 value->undomgr = NULL;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
71 value->set = ui_textarea_set;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
72 value->get = ui_textarea_get;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
73 value->getsubstr = ui_textarea_getsubstr;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
74 value->insert = ui_textarea_insert;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
75 value->setposition = ui_textarea_setposition;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
76 value->position = ui_textarea_position;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
77 value->selection = ui_textarea_selection;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
78 value->length = ui_textarea_length;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
79 value->remove = ui_textarea_remove;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
80 }
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 // add textarea to current container
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
83 UI_APPLY_LAYOUT1(current, args);
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
84
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
85 current->container->Add(textarea, true);
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
86
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
87 return widget;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
88 }
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 UIEXPORT UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
91 return textarea;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
92 }
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 UIEXPORT void ui_text_undo(UiText *value) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
95
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 UIEXPORT void ui_text_redo(UiText *value) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
99
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
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
102 // -------------------------- getter/setter for textarea UiText --------------------------
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
103
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
104 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
105 if (text->value.ptr) {
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
106 text->value.free(text->value.ptr);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
107 }
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 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
110 text->value.free = free;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
111
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
112 return text->value.ptr;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
113 }
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 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
116 if (text->value.ptr) {
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
117 text->value.free(text->value.ptr);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
118 }
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 text->value.ptr = _strdup(value);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
121 text->value.free = free;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
122
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
123 int len;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
124 wchar_t* wstr = str2wstr(value, &len);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
125 std::wstring s(wstr);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
126 free(wstr);
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
127
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
128 return s;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
129 }
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
130
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
131 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
132 UiWidget* widget = (UiWidget*)text->obj;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
133 TextBox box = widget->uielement.as<TextBox>();
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
134 std::wstring wstr(box.Text());
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
135 return ui_wtext_get(text, wstr);
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
136 }
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 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
139 UiWidget* widget = (UiWidget*)text->obj;
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
140 TextBox box = widget->uielement.as<TextBox>();
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
141 box.Text(ui_wtext_set(text, newvalue));
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
142 }
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 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
145 return NULL;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
146 }
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 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
149
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 extern "C" void ui_textarea_setposition(UiText *text, int pos) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
153
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 extern "C" int ui_textarea_position(UiText *text) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
157 return 0;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
158 }
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 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
161
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 extern "C" int ui_textarea_length(UiText *text) {
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
165 return 0;
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
166 }
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 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
169
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
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 UIWIDGET ui_textfield_create(UiObject* obj, UiTextFieldArgs args) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 UiObject* current = uic_current_obj(obj);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 // create textbox and toolkit wrapper
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 TextBox textfield = TextBox();
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 UIElement elm = textfield;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 UiWidget* widget = new UiWidget(elm);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 ui_context_add_widget_destructor(current->ctx, widget);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 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
185 if (var) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 UiString* value = (UiString*)var->value;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 value->obj = widget;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 value->get = ui_textfield_get;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 value->set = ui_textfield_set;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 // listener for notifying observers
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 // TODO:
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
195 // add textfield to current container
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 UI_APPLY_LAYOUT1(current, args);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 current->container->Add(textfield, false);
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 return widget;
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
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs args) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 return ui_textfield_create(obj, args);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 UiObject* current = uic_current_obj(obj);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 // create textbox and toolkit wrapper
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 PasswordBox textfield = PasswordBox();
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 UIElement elm = textfield;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 UiWidget* widget = new UiWidget(elm);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 ui_context_add_widget_destructor(current->ctx, widget);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 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
217 if (var) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 UiString* value = (UiString*)var->value;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 value->obj = widget;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 value->get = ui_passwordfield_get;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 value->set = ui_passwordfield_set;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 // listener for notifying observers
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 // TODO:
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
374
eae5d6623fd3 add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 240
diff changeset
227 // add textfield to current container
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 UI_APPLY_LAYOUT1(current, args);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 current->container->Add(textfield, false);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 return widget;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 }
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
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 // -------------------------- getter/setter for textfield UiString --------------------------
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
238 char* ui_wstring_get(UiString* str, std::wstring &value) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 if (str->value.ptr) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 str->value.free(str->value.ptr);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 str->value.ptr = wchar2utf8(value.c_str(), value.length());
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 str->value.free = free;
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 return str->value.ptr;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
249 std::wstring ui_wstring_set(UiString* str, const char* value) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 if (str->value.ptr) {
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 str->value.free(str->value.ptr);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 str->value.ptr = _strdup(value);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 str->value.free = free;
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 int len;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 wchar_t* wstr = str2wstr(value, &len);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 std::wstring s(wstr);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 free(wstr);
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 return s;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
265 char* ui_textfield_get(UiString * str) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 UiWidget* widget = (UiWidget*)str->obj;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 TextBox box = widget->uielement.as<TextBox>();
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 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
269 return ui_wstring_get(str, wstr);
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
272 void ui_textfield_set(UiString * str, const char* newvalue) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 UiWidget* widget = (UiWidget*)str->obj;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 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
275 box.Text(ui_wstring_set(str, newvalue));
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
279 char* ui_passwordfield_get(UiString * str) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 UiWidget* widget = (UiWidget*)str->obj;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 PasswordBox box = widget->uielement.as<PasswordBox>();
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 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
283 return ui_wstring_get(str, wstr);
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 }
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 205
diff changeset
286 void ui_passwordfield_set(UiString * str, const char* newvalue) {
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 UiWidget* widget = (UiWidget*)str->obj;
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 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
289 box.Password(ui_wstring_set(str, newvalue));
192
bcacd00ea955 implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 }
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
291
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
292
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
293 // ------------------------ path textfield --------------------------------------
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 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
296 UiPathTextField* pb = (UiPathTextField*)ptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
297 delete pb;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
298 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
299
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
300 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
301 cxMempoolRegister(ctx->mp, pb, destroy_ui_pathtextfield);
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
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
304 static void ui_pathtextfield_clear(StackPanel& buttons) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
305 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
306 buttons.Children().RemoveAt(i);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
307 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
308 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
309
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
310 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
311 if (!elms) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
312 return;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
313 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
314 for (int i = 0; i < nelm; i++) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
315 UiPathElm e = elms[i];
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
316 free(e.name);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
317 free(e.path);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
318 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
319 free(elms);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
320 }
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 UiPathTextField::~UiPathTextField() {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
323 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
324 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
325
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
326 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
327 cxstring *pathelms;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
328 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
329
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
330 if (nelm == 0) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
331 *ret_nelm = 0;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
332 return nullptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
333 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
334
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
335 UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
336 size_t n = nelm;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
337 int j = 0;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
338 for (int i = 0; i < nelm; i++) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
339 cxstring c = pathelms[i];
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
340 if (c.length == 0) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
341 if (i == 0) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
342 c.length = 1;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
343 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
344 else {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
345 n--;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
346 continue;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
347 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
348 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
349
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
350 cxmutstr m = cx_strdup(c);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
351 elms[j].name = m.ptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
352 elms[j].name_len = m.length;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
353
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
354 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
355 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
356 elms[j].path = elm_path.ptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
357 elms[j].path_len = elm_path.length;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
358
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
359 j++;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
360 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
361 *ret_nelm = n;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
362
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
363 return elms;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
364 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
365
240
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
366 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
367 Grid grid = pb->grid;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
368
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
369 ui_pathelm_func getpathelm = pb->getpathelm;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
370 void* getpathelmdata = pb->getpathelmdata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
371
240
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
372 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
373
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
374 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
375 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
376 if (!path_elm) {
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
377 return 1;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
378 }
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
379
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
380 // hide textbox, show button panel
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
381 pb->textbox.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
382 pb->buttons.Visibility(Visibility::Visible);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
383
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
384 // 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
385 ui_pathtextfield_clear(pb->buttons);
225
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 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
388 pb->current_path = path_elm;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
389 pb->current_path_nelms = nelm;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
390
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
391 // add new buttons
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
392 int j = 0;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
393 for (int i = 0; i < nelm;i++) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
394 UiPathElm elm = path_elm[i];
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
395 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
396 Button button = Button();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
397 button.Content(box_value(wstr));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
398 free(wstr);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
399
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
400 if (pb->onactivate) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
401 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
402 // 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
403 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
404
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
405 UiEvent evt;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
406 evt.obj = pb->obj;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
407 evt.window = evt.obj->window;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
408 evt.document = evt.obj->ctx->document;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
409 evt.eventdata = elmpath.ptr;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
410 evt.intval = j;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
411 pb->onactivate(&evt, pb->onactivatedata);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
412
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
413 free(elmpath.ptr);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
414 });
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
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
417 Thickness t = { 0, 0, 1, 0 };
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
418 CornerRadius c = { 0 ,0, 0, 0 };
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
419 button.BorderThickness(t);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
420 button.CornerRadius(c);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
421
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
422 pb->buttons.Children().Append(button);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
423
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
424 j++;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
425 }
240
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
426
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
427 return 0;
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
428 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
429
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
430 char* ui_path_textfield_get(UiString * str) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
431 UiPathTextField* widget = (UiPathTextField*)str->obj;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
432 TextBox box = widget->textbox;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
433 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
434 return ui_wstring_get(str, wstr);
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
435 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
436
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
437 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
438 UiPathTextField* widget = (UiPathTextField*)str->obj;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
439 TextBox box = widget->textbox;
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
440 box.Text(ui_wstring_set(str, newvalue));
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
441 ui_pathtextfield_update(widget, newvalue);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
442 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
443
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
444 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
445 UiObject* current = uic_current_obj(obj);
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 // create view and toolkit wrapper
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
448 Border pathbar = Border();
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 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
451 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
452 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
453 // 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
454
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
455 Brush bgBrush = unbox_value<Brush>(bgRes);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
456 Thickness border = unbox_value<Thickness>(borderThicknessRes);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
457 Brush borderBrush = unbox_value<Brush>(borderBrushRes);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
458 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
459
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
460 pathbar.Background(bgBrush);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
461 pathbar.BorderBrush(borderBrush);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
462 pathbar.BorderThickness(border);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
463 pathbar.CornerRadius(cornerRadius);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
464
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
465 Grid content = Grid();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
466 pathbar.Child(content);
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 GridLength gl;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
469 gl.Value = 0;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
470 gl.GridUnitType = GridUnitType::Auto;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
471
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
472 ColumnDefinition coldef = ColumnDefinition();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
473 coldef.Width(gl);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
474 content.ColumnDefinitions().Append(coldef);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
475
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
476 gl.Value = 1;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
477 gl.GridUnitType = GridUnitType::Star;
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 ColumnDefinition coldef2 = ColumnDefinition();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
480 coldef2.Width(gl);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
481 content.ColumnDefinitions().Append(coldef2);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
482
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
483 TextBox pathTextBox = TextBox();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
484 Thickness t = { 0, 0, 0, 0 };
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
485 CornerRadius c = { 0 ,0, 0, 0 };
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
486 pathTextBox.BorderThickness(t);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
487 //pathTextBox.CornerRadius(c);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
488
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
489
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
490 pathTextBox.HorizontalAlignment(HorizontalAlignment::Stretch);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
491 content.SetColumn(pathTextBox, 0);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
492 content.SetColumnSpan(pathTextBox, 2);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
493
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
494 content.Children().Append(pathTextBox);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
495
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
496 // stackpanel for buttons
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
497 StackPanel buttons = StackPanel();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
498 buttons.Orientation(Orientation::Horizontal);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
499 buttons.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
500 content.SetColumn(buttons, 0);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
501 content.Children().Append(buttons);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
502
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
503 TextBlock filler = TextBlock();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
504 filler.VerticalAlignment(VerticalAlignment::Stretch);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
505 //filler.Text(winrt::hstring(L"hello filler"));
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
506
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
507 filler.HorizontalAlignment(HorizontalAlignment::Stretch);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
508 filler.VerticalAlignment(VerticalAlignment::Stretch);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
509 content.SetColumn(filler, 1);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
510 content.Children().Append(filler);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
511
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
512 filler.PointerPressed(
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
513 winrt::Microsoft::UI::Xaml::Input::PointerEventHandler(
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
514 [=](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
515 pathTextBox.Visibility(Visibility::Visible);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
516 buttons.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
517 filler.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
518 pathTextBox.SelectionStart(pathTextBox.Text().size());
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
519 pathTextBox.SelectionLength(0);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
520 pathTextBox.Focus(FocusState::Keyboard);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
521 })
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
522 );
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
523
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
524 //pathTextBox.Visibility(Visibility::Collapsed);
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 UiPathTextField* uipathbar = new UiPathTextField;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
527 ui_context_add_pathtextfield_destructor(current->ctx, uipathbar);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
528 uipathbar->grid = content;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
529 uipathbar->buttons = buttons;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
530 uipathbar->textbox = pathTextBox;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
531 uipathbar->filler = filler;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
532 uipathbar->obj = obj;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
533 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
534 uipathbar->getpathelmdata = args.getpathelmdata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
535 uipathbar->onactivate = args.onactivate;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
536 uipathbar->onactivatedata = args.onactivatedata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
537 uipathbar->ondragstart = args.ondragstart;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
538 uipathbar->ondragstartdata = args.ondragstartdata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
539 uipathbar->ondragcomplete = args.ondragcomplete;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
540 uipathbar->ondragcompletedata = args.ondragcompletedata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
541 uipathbar->ondrop = args.ondrop;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
542 uipathbar->ondropdata = args.ondropsdata;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
543
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
544
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
545 pathTextBox.KeyDown(
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
546 winrt::Microsoft::UI::Xaml::Input::KeyEventHandler(
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
547 [=](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
548 auto key = e.Key();
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
549 bool showButtons = false;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
550 bool update = false;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
551 if (key == Windows::System::VirtualKey::Escape) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
552 showButtons = true;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
553 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
554 else if (key == Windows::System::VirtualKey::Enter) {
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 update = true;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
557 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
558
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
559 if (showButtons) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
560 pathTextBox.Visibility(Visibility::Collapsed);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
561 buttons.Visibility(Visibility::Visible);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
562 filler.Visibility(Visibility::Visible);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
563 if (update) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
564 std::wstring value(pathTextBox.Text());
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
565 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
566
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
567 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
568 UiEvent evt;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
569 evt.obj = obj;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
570 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
571 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
572 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
573 evt.intval = -1;
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
574 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
575 }
9335e9bbc167 call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 239
diff changeset
576
225
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
577 free(full_path);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
578 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
579
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
580 //buttons.Focus(FocusState::Keyboard);
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 );
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 UIElement elm = pathbar;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
587 UiWidget* widget = new UiWidget(elm);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
588 widget->data1 = uipathbar;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
589 ui_context_add_widget_destructor(current->ctx, widget);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
590
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
591 // bind var
239
5dd24929f9f6 fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
592 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
593 if (var) {
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
594 UiString* value = (UiString*)var->value;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
595 value->obj = uipathbar;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
596 value->get = ui_path_textfield_get;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
597 value->set = ui_path_textfield_set;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
598 }
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
599
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
600 // add listview to current container
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
601 UI_APPLY_LAYOUT1(current, args);
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 current->container->Add(pathbar, false);
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
604
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
605 return widget;
097f45f9c1fa add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
606 }

mercurial