Wed, 30 Oct 2024 12:23:52 +0100
add textarea (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 |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
59 | RichEditBox textarea = RichEditBox(); |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
60 | UIElement elm = textarea; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
61 | UiWidget* widget = new UiWidget(elm); |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
62 | ui_context_add_widget_destructor(current->ctx, widget); |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
63 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
64 | 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
|
65 | if (var) { |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
66 | UiText* value = (UiText*)var->value; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
67 | value->obj = widget; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
68 | value->undomgr = NULL; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
69 | value->set = ui_textarea_set; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
70 | value->get = ui_textarea_get; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
71 | value->getsubstr = ui_textarea_getsubstr; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
72 | value->insert = ui_textarea_insert; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
73 | value->setposition = ui_textarea_setposition; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
74 | value->position = ui_textarea_position; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
75 | value->selection = ui_textarea_selection; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
76 | value->length = ui_textarea_length; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
77 | value->remove = ui_textarea_remove; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
78 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
79 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
80 | // add textarea to current container |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
81 | UI_APPLY_LAYOUT1(current, args); |
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 | current->container->Add(textarea, true); |
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 | return widget; |
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 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
88 | UIEXPORT UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
89 | return textarea; |
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 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
92 | UIEXPORT void ui_text_undo(UiText *value) { |
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 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
96 | UIEXPORT void ui_text_redo(UiText *value) { |
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 | |
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 | extern "C" char* ui_textarea_get(UiText *text) { |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
103 | return NULL; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
104 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
105 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
106 | extern "C" void ui_textarea_set(UiText *text, const char *newvalue) { |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
107 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
108 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
109 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
110 | 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
|
111 | return NULL; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
112 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
113 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
114 | 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
|
115 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
116 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
117 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
118 | extern "C" void ui_textarea_setposition(UiText *text, int pos) { |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
119 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
120 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
121 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
122 | extern "C" int ui_textarea_position(UiText *text) { |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
123 | return 0; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
124 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
125 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
126 | 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
|
127 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
128 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
129 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
130 | extern "C" int ui_textarea_length(UiText *text) { |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
131 | return 0; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
132 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
133 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
134 | 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
|
135 | |
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 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
139 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
140 | |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | UIWIDGET ui_textfield_create(UiObject* obj, UiTextFieldArgs args) { |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | UiObject* current = uic_current_obj(obj); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | // create textbox and toolkit wrapper |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | TextBox textfield = TextBox(); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | UIElement elm = textfield; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | UiWidget* widget = new UiWidget(elm); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | ui_context_add_widget_destructor(current->ctx, widget); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | 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
|
151 | if (var) { |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | UiString* value = (UiString*)var->value; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | value->obj = widget; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | value->get = ui_textfield_get; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | value->set = ui_textfield_set; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | // listener for notifying observers |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | // TODO: |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | } |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
374
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
161 | // add textfield to current container |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | UI_APPLY_LAYOUT1(current, args); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | current->container->Add(textfield, false); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | return widget; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | } |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs args) { |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | return ui_textfield_create(obj, args); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | } |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) { |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | UiObject* current = uic_current_obj(obj); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | // create textbox and toolkit wrapper |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | PasswordBox textfield = PasswordBox(); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | UIElement elm = textfield; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | UiWidget* widget = new UiWidget(elm); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | ui_context_add_widget_destructor(current->ctx, widget); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | 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
|
183 | if (var) { |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | UiString* value = (UiString*)var->value; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | value->obj = widget; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | value->get = ui_passwordfield_get; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | value->set = ui_passwordfield_set; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | // listener for notifying observers |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | // TODO: |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | } |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | |
374
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
240
diff
changeset
|
193 | // add textfield to current container |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | UI_APPLY_LAYOUT1(current, args); |
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 | current->container->Add(textfield, false); |
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 | return widget; |
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 | |
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 | // -------------------------- getter/setter for textfield UiString -------------------------- |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | |
231
e160bb392148
add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
204 | char* ui_wstring_get(UiString* str, std::wstring &value) { |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | if (str->value.ptr) { |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | str->value.free(str->value.ptr); |
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 | str->value.ptr = wchar2utf8(value.c_str(), value.length()); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | str->value.free = free; |
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 | return str->value.ptr; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | } |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | |
231
e160bb392148
add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
215 | std::wstring ui_wstring_set(UiString* str, const char* value) { |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | if (str->value.ptr) { |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | str->value.free(str->value.ptr); |
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 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | str->value.ptr = _strdup(value); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | str->value.free = free; |
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 | int len; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | wchar_t* wstr = str2wstr(value, &len); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | std::wstring s(wstr); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | free(wstr); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | return s; |
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 | |
219
527a66c0afb2
add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
231 | char* ui_textfield_get(UiString * str) { |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | UiWidget* widget = (UiWidget*)str->obj; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | TextBox box = widget->uielement.as<TextBox>(); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | 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
|
235 | return ui_wstring_get(str, wstr); |
192
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 | |
219
527a66c0afb2
add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
238 | void ui_textfield_set(UiString * str, const char* newvalue) { |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | UiWidget* widget = (UiWidget*)str->obj; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | 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
|
241 | box.Text(ui_wstring_set(str, newvalue)); |
192
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 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | |
219
527a66c0afb2
add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
245 | char* ui_passwordfield_get(UiString * str) { |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | UiWidget* widget = (UiWidget*)str->obj; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | PasswordBox box = widget->uielement.as<PasswordBox>(); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | 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
|
249 | return ui_wstring_get(str, wstr); |
192
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 | |
219
527a66c0afb2
add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
252 | void ui_passwordfield_set(UiString * str, const char* newvalue) { |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | UiWidget* widget = (UiWidget*)str->obj; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | 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
|
255 | box.Password(ui_wstring_set(str, newvalue)); |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | } |
225
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
257 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
258 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
259 | // ------------------------ path textfield -------------------------------------- |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
260 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
261 | 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
|
262 | UiPathTextField* pb = (UiPathTextField*)ptr; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
263 | delete pb; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
264 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
265 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
266 | 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
|
267 | cxMempoolRegister(ctx->mp, pb, destroy_ui_pathtextfield); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
268 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
269 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
270 | static void ui_pathtextfield_clear(StackPanel& buttons) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
271 | 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
|
272 | buttons.Children().RemoveAt(i); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
273 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
274 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
275 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
276 | 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
|
277 | if (!elms) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
278 | return; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
279 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
280 | for (int i = 0; i < nelm; i++) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
281 | UiPathElm e = elms[i]; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
282 | free(e.name); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
283 | free(e.path); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
284 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
285 | free(elms); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
286 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
287 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
288 | UiPathTextField::~UiPathTextField() { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
289 | 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
|
290 | } |
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 | 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
|
293 | cxstring *pathelms; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
294 | 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
|
295 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
296 | if (nelm == 0) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
297 | *ret_nelm = 0; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
298 | return nullptr; |
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 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
301 | UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm)); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
302 | size_t n = nelm; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
303 | int j = 0; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
304 | for (int i = 0; i < nelm; i++) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
305 | cxstring c = pathelms[i]; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
306 | if (c.length == 0) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
307 | if (i == 0) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
308 | c.length = 1; |
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 | else { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
311 | n--; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
312 | continue; |
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 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
315 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
316 | cxmutstr m = cx_strdup(c); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
317 | elms[j].name = m.ptr; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
318 | elms[j].name_len = m.length; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
319 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
320 | 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
|
321 | 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
|
322 | elms[j].path = elm_path.ptr; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
323 | elms[j].path_len = elm_path.length; |
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 | j++; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
326 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
327 | *ret_nelm = n; |
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 | return elms; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
330 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
331 | |
240
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
332 | 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
|
333 | Grid grid = pb->grid; |
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 | ui_pathelm_func getpathelm = pb->getpathelm; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
336 | void* getpathelmdata = pb->getpathelmdata; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
337 | |
240
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
338 | 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
|
339 | |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
340 | 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
|
341 | 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
|
342 | if (!path_elm) { |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
343 | return 1; |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
344 | } |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
345 | |
225
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
346 | // hide textbox, show button panel |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
347 | pb->textbox.Visibility(Visibility::Collapsed); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
348 | pb->buttons.Visibility(Visibility::Visible); |
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 | // 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
|
351 | ui_pathtextfield_clear(pb->buttons); |
225
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 | 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
|
354 | pb->current_path = path_elm; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
355 | pb->current_path_nelms = nelm; |
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 | // add new buttons |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
358 | int j = 0; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
359 | for (int i = 0; i < nelm;i++) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
360 | UiPathElm elm = path_elm[i]; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
361 | 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
|
362 | Button button = Button(); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
363 | button.Content(box_value(wstr)); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
364 | free(wstr); |
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 | if (pb->onactivate) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
367 | 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
|
368 | // 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
|
369 | 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
|
370 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
371 | UiEvent evt; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
372 | evt.obj = pb->obj; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
373 | evt.window = evt.obj->window; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
374 | evt.document = evt.obj->ctx->document; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
375 | evt.eventdata = elmpath.ptr; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
376 | evt.intval = j; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
377 | pb->onactivate(&evt, pb->onactivatedata); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
378 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
379 | free(elmpath.ptr); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
380 | }); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
381 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
382 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
383 | Thickness t = { 0, 0, 1, 0 }; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
384 | CornerRadius c = { 0 ,0, 0, 0 }; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
385 | button.BorderThickness(t); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
386 | button.CornerRadius(c); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
387 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
388 | pb->buttons.Children().Append(button); |
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 | j++; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
391 | } |
240
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
392 | |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
393 | return 0; |
225
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
394 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
395 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
396 | char* ui_path_textfield_get(UiString * str) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
397 | UiPathTextField* widget = (UiPathTextField*)str->obj; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
398 | TextBox box = widget->textbox; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
399 | 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
|
400 | return ui_wstring_get(str, wstr); |
225
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
401 | } |
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 | 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
|
404 | UiPathTextField* widget = (UiPathTextField*)str->obj; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
405 | TextBox box = widget->textbox; |
231
e160bb392148
add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
406 | box.Text(ui_wstring_set(str, newvalue)); |
225
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
407 | ui_pathtextfield_update(widget, newvalue); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
408 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
409 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
410 | 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
|
411 | UiObject* current = uic_current_obj(obj); |
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 | // create view and toolkit wrapper |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
414 | Border pathbar = Border(); |
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 | 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
|
417 | 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
|
418 | 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
|
419 | // 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
|
420 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
421 | Brush bgBrush = unbox_value<Brush>(bgRes); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
422 | Thickness border = unbox_value<Thickness>(borderThicknessRes); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
423 | Brush borderBrush = unbox_value<Brush>(borderBrushRes); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
424 | 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
|
425 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
426 | pathbar.Background(bgBrush); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
427 | pathbar.BorderBrush(borderBrush); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
428 | pathbar.BorderThickness(border); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
429 | pathbar.CornerRadius(cornerRadius); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
430 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
431 | Grid content = Grid(); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
432 | pathbar.Child(content); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
433 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
434 | GridLength gl; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
435 | gl.Value = 0; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
436 | gl.GridUnitType = GridUnitType::Auto; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
437 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
438 | ColumnDefinition coldef = ColumnDefinition(); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
439 | coldef.Width(gl); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
440 | content.ColumnDefinitions().Append(coldef); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
441 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
442 | gl.Value = 1; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
443 | gl.GridUnitType = GridUnitType::Star; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
444 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
445 | ColumnDefinition coldef2 = ColumnDefinition(); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
446 | coldef2.Width(gl); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
447 | content.ColumnDefinitions().Append(coldef2); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
448 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
449 | TextBox pathTextBox = TextBox(); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
450 | Thickness t = { 0, 0, 0, 0 }; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
451 | CornerRadius c = { 0 ,0, 0, 0 }; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
452 | pathTextBox.BorderThickness(t); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
453 | //pathTextBox.CornerRadius(c); |
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 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
456 | pathTextBox.HorizontalAlignment(HorizontalAlignment::Stretch); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
457 | content.SetColumn(pathTextBox, 0); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
458 | content.SetColumnSpan(pathTextBox, 2); |
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 | content.Children().Append(pathTextBox); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
461 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
462 | // stackpanel for buttons |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
463 | StackPanel buttons = StackPanel(); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
464 | buttons.Orientation(Orientation::Horizontal); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
465 | buttons.Visibility(Visibility::Collapsed); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
466 | content.SetColumn(buttons, 0); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
467 | content.Children().Append(buttons); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
468 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
469 | TextBlock filler = TextBlock(); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
470 | filler.VerticalAlignment(VerticalAlignment::Stretch); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
471 | //filler.Text(winrt::hstring(L"hello filler")); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
472 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
473 | filler.HorizontalAlignment(HorizontalAlignment::Stretch); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
474 | filler.VerticalAlignment(VerticalAlignment::Stretch); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
475 | content.SetColumn(filler, 1); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
476 | content.Children().Append(filler); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
477 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
478 | filler.PointerPressed( |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
479 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
480 | [=](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
|
481 | pathTextBox.Visibility(Visibility::Visible); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
482 | buttons.Visibility(Visibility::Collapsed); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
483 | filler.Visibility(Visibility::Collapsed); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
484 | pathTextBox.SelectionStart(pathTextBox.Text().size()); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
485 | pathTextBox.SelectionLength(0); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
486 | pathTextBox.Focus(FocusState::Keyboard); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
487 | }) |
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.Visibility(Visibility::Collapsed); |
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 | UiPathTextField* uipathbar = new UiPathTextField; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
493 | ui_context_add_pathtextfield_destructor(current->ctx, uipathbar); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
494 | uipathbar->grid = content; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
495 | uipathbar->buttons = buttons; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
496 | uipathbar->textbox = pathTextBox; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
497 | uipathbar->filler = filler; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
498 | uipathbar->obj = obj; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
499 | 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
|
500 | uipathbar->getpathelmdata = args.getpathelmdata; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
501 | uipathbar->onactivate = args.onactivate; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
502 | uipathbar->onactivatedata = args.onactivatedata; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
503 | uipathbar->ondragstart = args.ondragstart; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
504 | uipathbar->ondragstartdata = args.ondragstartdata; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
505 | uipathbar->ondragcomplete = args.ondragcomplete; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
506 | uipathbar->ondragcompletedata = args.ondragcompletedata; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
507 | uipathbar->ondrop = args.ondrop; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
508 | uipathbar->ondropdata = args.ondropsdata; |
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 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
511 | pathTextBox.KeyDown( |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
512 | winrt::Microsoft::UI::Xaml::Input::KeyEventHandler( |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
513 | [=](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
|
514 | auto key = e.Key(); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
515 | bool showButtons = false; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
516 | bool update = false; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
517 | if (key == Windows::System::VirtualKey::Escape) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
518 | showButtons = true; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
519 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
520 | else if (key == Windows::System::VirtualKey::Enter) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
521 | showButtons = true; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
522 | update = true; |
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 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
525 | if (showButtons) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
526 | pathTextBox.Visibility(Visibility::Collapsed); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
527 | buttons.Visibility(Visibility::Visible); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
528 | filler.Visibility(Visibility::Visible); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
529 | if (update) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
530 | std::wstring value(pathTextBox.Text()); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
531 | 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
|
532 | |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
533 | 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
|
534 | UiEvent evt; |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
535 | evt.obj = obj; |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
536 | 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
|
537 | 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
|
538 | 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
|
539 | evt.intval = -1; |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
540 | 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
|
541 | } |
9335e9bbc167
call event handler after text input in the path textfield
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
239
diff
changeset
|
542 | |
225
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
543 | free(full_path); |
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 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
546 | //buttons.Focus(FocusState::Keyboard); |
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 | }) |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
549 | ); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
550 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
551 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
552 | UIElement elm = pathbar; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
553 | UiWidget* widget = new UiWidget(elm); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
554 | widget->data1 = uipathbar; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
555 | ui_context_add_widget_destructor(current->ctx, widget); |
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 | // bind var |
239
5dd24929f9f6
fix list binding copy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
231
diff
changeset
|
558 | 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
|
559 | if (var) { |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
560 | UiString* value = (UiString*)var->value; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
561 | value->obj = uipathbar; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
562 | value->get = ui_path_textfield_get; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
563 | value->set = ui_path_textfield_set; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
564 | } |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
565 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
566 | // add listview to current container |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
567 | UI_APPLY_LAYOUT1(current, args); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
568 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
569 | current->container->Add(pathbar, false); |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
570 | |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
571 | return widget; |
097f45f9c1fa
add new path textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
572 | } |