Sat, 13 Dec 2025 15:58:58 +0100
fix build with newest toolkit version
| 113 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
| 4 | * Copyright 2025 Olaf Wintermann. All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | ||
| 29 | #include "text.h" | |
| 30 | ||
|
115
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
31 | static W32WidgetClass textarea_widget_class = { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
32 | .eventproc = ui_textarea_eventproc, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
33 | .enable = w32_widget_default_enable, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
34 | .show = w32_widget_default_show, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
35 | .get_preferred_size = ui_textarea_get_preferred_size, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
36 | .destroy = w32_widget_default_destroy |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
37 | }; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
38 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
39 | UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs *args) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
40 | HINSTANCE hInstance = GetModuleHandle(NULL); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
41 | UiContainerPrivate *container = ui_obj_container(obj); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
42 | HWND parent = ui_container_get_parent(container); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
43 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
44 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
45 | int width = args->width >= 0 ? args->width : 100; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
46 | int height = args->height >= 0 ? args->height : 100; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
47 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
48 | HWND hwnd = CreateWindowEx( |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
49 | 0, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
50 | "EDIT", |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
51 | "", |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
52 | WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
53 | 0, 0, width, height, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
54 | parent, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
55 | (HMENU)0, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
56 | hInstance, |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
57 | NULL); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
58 | ui_win32_set_ui_font(hwnd); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
59 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
60 | W32Widget *widget = w32_widget_create(&textarea_widget_class, hwnd, sizeof(UiTextArea)); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
61 | ui_container_add(container, widget, &layout); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
62 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
63 | UiTextArea *textarea = (UiTextArea*)widget; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
64 | textarea->width = width; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
65 | textarea->widget.var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_TEXT); |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
66 | textarea->widget.callback = args->onchange; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
67 | textarea->widget.callbackdata = args->onchangedata; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
68 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
69 | if (textarea->widget.var) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
70 | UiText *t = textarea->widget.var->value; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
71 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
72 | if (t->value.ptr) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
73 | // TODO: set textarea string |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
74 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
75 | t->obj = widget; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
76 | t->save = ui_textarea_save; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
77 | t->destroy = ui_textarea_destroy; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
78 | t->restore = ui_textarea_restore; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
79 | t->get = ui_textarea_get; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
80 | t->set = ui_textarea_set; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
81 | t->getsubstr = ui_textarea_getsubstr; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
82 | t->insert = ui_textarea_insert; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
83 | t->setposition = ui_textarea_setposition; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
84 | t->position = ui_textarea_position; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
85 | t->setselection = ui_textarea_setselection; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
86 | t->selection = ui_textarea_selection; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
87 | t->length = ui_textarea_length; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
88 | t->remove = ui_textarea_remove; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
89 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
90 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
91 | return widget; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
92 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
93 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
94 | W32Size ui_textarea_get_preferred_size(W32Widget *widget) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
95 | W32Size size; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
96 | UiTextArea *textarea = (UiTextArea*)widget; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
97 | size.width = textarea->width; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
98 | size.height = textarea->height; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
99 | return size; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
100 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
101 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
102 | int ui_textarea_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
103 | return 0; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
104 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
105 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
106 | void ui_textarea_save(UiText *text) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
107 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
108 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
109 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
110 | void ui_textarea_destroy(UiText *text) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
111 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
112 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
113 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
114 | void ui_textarea_restore(UiText *text) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
115 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
116 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
117 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
118 | void ui_textarea_set(UiText *text, const char *str) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
119 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
120 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
121 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
122 | char* ui_textarea_get(UiText *text) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
123 | return NULL; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
124 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
125 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
126 | char* ui_textarea_getsubstr(UiText *text, int begin, int end) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
127 | return NULL; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
128 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
129 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
130 | void ui_textarea_insert(UiText *text, int pos, char *str) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
131 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
132 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
133 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
134 | void ui_textarea_setposition(UiText *text, int pos) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
135 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
136 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
137 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
138 | int ui_textarea_position(UiText *text) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
139 | return 0; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
140 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
141 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
142 | void ui_textarea_setselection(UiText *text, int begin, int end) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
143 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
144 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
145 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
146 | void ui_textarea_selection(UiText *text, int *begin, int *end) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
147 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
148 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
149 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
150 | int ui_textarea_length(UiText *text) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
151 | return 0; |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
152 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
153 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
154 | void ui_textarea_remove(UiText *text, int begin, int end) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
155 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
156 | } |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
157 | |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
158 | /* ----------------------------- TextField ----------------------------- */ |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
159 | |
| 113 | 160 | static W32WidgetClass textfield_widget_class = { |
| 161 | .eventproc = ui_textfield_eventproc, | |
| 162 | .enable = w32_widget_default_enable, | |
| 163 | .show = w32_widget_default_show, | |
| 164 | .get_preferred_size = ui_textfield_get_preferred_size, | |
| 165 | .destroy = w32_widget_default_destroy | |
| 166 | }; | |
| 167 | ||
| 168 | UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs *args) { | |
| 169 | HINSTANCE hInstance = GetModuleHandle(NULL); | |
| 170 | UiContainerPrivate *container = ui_obj_container(obj); | |
| 171 | HWND parent = ui_container_get_parent(container); | |
| 172 | UiLayout layout = UI_ARGS2LAYOUT(args); | |
| 173 | ||
| 174 | int width = args->width >= 0 ? args->width : 100; | |
| 175 | ||
| 176 | HWND hwnd = CreateWindowEx( | |
| 177 | WS_EX_CLIENTEDGE, | |
| 178 | "EDIT", | |
| 179 | "", | |
| 180 | WS_VISIBLE | WS_CHILD | ES_LEFT | ES_AUTOHSCROLL, | |
| 181 | 0, 0, width, 25, | |
| 182 | parent, | |
| 183 | (HMENU)0, | |
| 184 | hInstance, | |
| 185 | NULL); | |
| 186 | ui_win32_set_ui_font(hwnd); | |
| 187 | ||
| 188 | W32Widget *widget = w32_widget_create(&textfield_widget_class, hwnd, sizeof(UiTextField)); | |
| 189 | ui_container_add(container, widget, &layout); | |
| 190 | ||
| 191 | UiTextField *textfield = (UiTextField*)widget; | |
| 192 | textfield->width = width; | |
| 193 | textfield->widget.var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING); | |
| 194 | textfield->widget.callback = args->onchange; | |
| 195 | textfield->widget.callbackdata = args->onchangedata; | |
| 196 | ||
| 197 | if (textfield->widget.var) { | |
| 198 | UiString *s = textfield->widget.var->value; | |
| 199 | ||
| 200 | if (s->value.ptr) { | |
| 201 | // TODO: set textfield string | |
| 202 | } | |
| 203 | s->obj = widget; | |
| 204 | s->get = ui_textfield_get; | |
| 205 | s->set = ui_textfield_set; | |
| 206 | } | |
| 207 | ||
| 208 | return widget; | |
| 209 | } | |
| 210 | ||
| 211 | W32Size ui_textfield_get_preferred_size(W32Widget *widget) { | |
| 212 | UiTextField *textfield = (UiTextField *)widget; | |
| 213 | return (W32Size){ .width = textfield->width, .height = 32}; | |
| 214 | } | |
| 215 | ||
|
115
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
216 | int ui_textfield_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
|
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
217 | return 0; |
| 113 | 218 | } |
| 219 | ||
| 220 | char* ui_textfield_get(UiString *s) { | |
| 221 | UiTextField *textfield = s->obj; | |
| 222 | ||
| 223 | if (s->value.free) { | |
| 224 | s->value.free(s->value.ptr); | |
| 225 | } | |
| 226 | ||
| 227 | int len = GetWindowTextLength(textfield->widget.widget.hwnd); | |
| 228 | s->value.ptr = calloc(len+1, 1); | |
| 229 | GetWindowText(textfield->widget.widget.hwnd, s->value.ptr, len+1); | |
| 230 | ||
| 231 | return s->value.ptr; | |
| 232 | } | |
| 233 | ||
| 234 | void ui_textfield_set(UiString *s, const char *value) { | |
| 235 | UiTextField *textfield = s->obj; | |
| 236 | if (s->value.free) { | |
| 237 | s->value.free(s->value.ptr); | |
| 238 | } | |
| 239 | s->value.ptr = NULL; | |
| 240 | SetWindowText(textfield->widget.widget.hwnd, value); | |
| 241 | } |