ui/win32/text.c

changeset 873
78853bfc47cf
child 879
d3acaa5fc3d8
equal deleted inserted replaced
872:1e34a27e016d 873:78853bfc47cf
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
31 static W32WidgetClass button_widget_class = {
32 .eventproc = ui_textfield_eventproc,
33 .enable = w32_widget_default_enable,
34 .show = w32_widget_default_show,
35 .get_preferred_size = ui_textfield_get_preferred_size,
36 .destroy = w32_widget_default_destroy
37 };
38
39 UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs *args) {
40 HINSTANCE hInstance = GetModuleHandle(NULL);
41 UiContainerPrivate *container = ui_obj_container(obj);
42 HWND parent = ui_container_get_parent(container);
43 UiLayout layout = UI_ARGS2LAYOUT(args);
44
45 int width = args->width >= 0 ? args->width : 100;
46
47 HWND hwnd = CreateWindow(
48 "EDIT",
49 "",
50 WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL,
51 0, 0, width, 25,
52 parent,
53 (HMENU)0,
54 hInstance,
55 NULL);
56 ui_win32_set_ui_font(hwnd);
57
58 W32Widget *widget = w32_widget_create(&button_widget_class, hwnd, sizeof(UiTextField));
59 ui_container_add(container, widget, &layout);
60
61 UiTextField *textfield = (UiTextField*)widget;
62 textfield->width = width;
63 textfield->widget.var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING);
64 textfield->widget.callback = args->onchange;
65 textfield->widget.callbackdata = args->onchangedata;
66
67 if (textfield->widget.var) {
68 UiString *s = textfield->widget.var->value;
69
70 if (s->value.ptr) {
71 // TODO: set textfield string
72 }
73 s->obj = widget;
74 s->get = ui_textfield_get;
75 s->set = ui_textfield_set;
76 }
77
78 return widget;
79 }
80
81 W32Size ui_textfield_get_preferred_size(W32Widget *widget) {
82 UiTextField *textfield = (UiTextField *)widget;
83 return (W32Size){ .width = textfield->width, .height = 32};
84 }
85
86 void ui_textfield_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
87
88 }
89
90 char* ui_textfield_get(UiString *s) {
91 return NULL; // TODO
92 }
93
94 void ui_textfield_set(UiString *s, const char *value) {
95 // TODO
96 }

mercurial