ui/win32/button.c

Sat, 13 Dec 2025 15:58:58 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 13 Dec 2025 15:58:58 +0100
changeset 115
e57ca2747782
parent 113
dde28a806552
permissions
-rw-r--r--

fix build with newest toolkit version

108
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2025 Olaf Wintermann. All rights reserved.
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
77254bd6dccb update toolkit, adjust UI code
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
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "button.h"
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
30 #include "widget.h"
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
31
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
32 #include <stdio.h>
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
33 #include <stdlib.h>
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
34
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
35 #include <cx/array_list.h>
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
36
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
37 #include <commctrl.h>
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
38
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
39 static W32WidgetClass button_widget_class = {
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
40 .eventproc = ui_button_eventproc,
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
41 .enable = w32_widget_default_enable,
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
42 .show = w32_widget_default_show,
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
43 .get_preferred_size = ui_button_get_preferred_size,
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
44 .destroy = w32_widget_default_destroy
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
45 };
108
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
47 static W32WidgetClass togglebutton_widget_class = {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
48 .eventproc = ui_togglebutton_eventproc,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
49 .enable = w32_widget_default_enable,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
50 .show = w32_widget_default_show,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
51 .get_preferred_size = ui_button_get_preferred_size,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
52 .destroy = w32_widget_default_destroy
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
53 };
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
54
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
55 static W32WidgetClass radiobutton_widget_class = {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
56 .eventproc = ui_radiobutton_eventproc,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
57 .enable = w32_widget_default_enable,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
58 .show = w32_widget_default_show,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
59 .get_preferred_size = ui_button_get_preferred_size,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
60 .destroy = w32_widget_default_destroy
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
61 };
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
62
108
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) {
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
64 HINSTANCE hInstance = GetModuleHandle(NULL);
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
65 UiContainerPrivate *container = ui_obj_container(obj);
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
66 HWND parent = ui_container_get_parent(container);
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
67 UiLayout layout = UI_ARGS2LAYOUT(args);
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
68
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
69 HWND hwnd = CreateWindow(
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
70 "BUTTON",
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
71 args->label,
113
dde28a806552 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 112
diff changeset
72 WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
73 0, 0, 100, 30,
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
74 parent,
113
dde28a806552 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 112
diff changeset
75 (HMENU)1,
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
76 hInstance,
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
77 NULL);
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
78 ui_win32_set_ui_font(hwnd);
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
79
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
80 W32Widget *widget = w32_widget_create(&button_widget_class, hwnd, sizeof(UiWidget));
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
81 ui_container_add(container, widget, &layout);
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
82
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
83 UiWidget *btn = (UiWidget*)widget;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
84 btn->obj = obj;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
85 btn->callback = args->onclick;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
86 btn->callbackdata = args->onclickdata;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
87
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
88 return widget;
108
77254bd6dccb update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 }
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
90
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
91 W32Size ui_button_get_preferred_size(W32Widget *widget) {
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
92 W32Size size;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
93 size.width = 100;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
94 size.height = 30;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
95 SIZE sz;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
96 if (Button_GetIdealSize(widget->hwnd, &sz)) {
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
97 size.width = sz.cx;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
98 size.height = sz.cy;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
99 }
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
100 return size;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
101 }
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
102
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
103 int ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
104 UiWidget *w = (UiWidget*)widget;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
105
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
106 if (uMsg != WM_COMMAND) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
107 return 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
108 }
113
dde28a806552 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 112
diff changeset
109
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
110 UiEvent e;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
111 e.obj = w->obj;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
112 e.document = e.obj->ctx->document;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
113 e.window = e.obj->window;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
114 e.eventdata = NULL;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
115 e.eventdatatype = 0;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
116 e.intval = 0;
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
117 e.set = ui_get_setop();
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
118
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
119 if (w->callback) {
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
120 w->callback(&e, w->callbackdata);
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
121 }
115
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
122
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
123 return 0;
112
c3f2f16fa4b8 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
124 }
115
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 static UIWIDGET create_togglebutton(UiObject *obj, UiToggleArgs *args, unsigned long type) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
127 HINSTANCE hInstance = GetModuleHandle(NULL);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
128 UiContainerPrivate *container = ui_obj_container(obj);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
129 HWND parent = ui_container_get_parent(container);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
130 UiLayout layout = UI_ARGS2LAYOUT(args);
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 HWND hwnd = CreateWindow(
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
133 "BUTTON",
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
134 args->label,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
135 WS_VISIBLE | WS_CHILD | type,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
136 0, 0, 100, 30,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
137 parent,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
138 (HMENU)1,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
139 hInstance,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
140 NULL);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
141 ui_win32_set_ui_font(hwnd);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
142
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
143 W32Widget *widget = w32_widget_create(&togglebutton_widget_class, hwnd, sizeof(UiWidget));
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
144 ui_container_add(container, widget, &layout);
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 UiVar *var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
147 if (var) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
148 UiInteger *i = var->value;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
149 i->obj = widget;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
150 i->get = ui_togglebutton_get;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
151 i->set = ui_togglebutton_set;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
152 if (i->value != 0) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
153 SendMessage(hwnd, BM_SETCHECK, BST_CHECKED, 0);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
154 }
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 UiWidget *btn = (UiWidget*)widget;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
158 btn->obj = obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
159 btn->var = var;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
160 btn->callback = args->onchange;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
161 btn->callbackdata = args->onchangedata;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
162
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
163 return widget;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
164 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
165
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
166 UIWIDGET ui_togglebutton_create(UiObject *obj, UiToggleArgs *args) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
167 return create_togglebutton(obj, args, BS_AUTOCHECKBOX | BS_PUSHLIKE);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
168 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
169
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
170 UIWIDGET ui_checkbox_create(UiObject *obj, UiToggleArgs *args) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
171 return create_togglebutton(obj, args, BS_AUTOCHECKBOX);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
172 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
173
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
174 UIWIDGET ui_switch_create(UiObject *obj, UiToggleArgs *args) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
175 return create_togglebutton(obj, args, BS_AUTOCHECKBOX);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
176 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
177
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
178 int64_t ui_togglebutton_get(UiInteger *i) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
179 UiWidget *btn = (UiWidget*)i->obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
180 LRESULT state = SendMessage(btn->widget.hwnd, BM_GETCHECK, 0, 0);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
181 i->value = state;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
182 return state;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
183 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
184
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
185 void ui_togglebutton_set(UiInteger *i, int64_t v) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
186 UiWidget *btn = (UiWidget*)i->obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
187 WPARAM state = v ? BST_CHECKED : BST_UNCHECKED;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
188 SendMessage(btn->widget.hwnd, BM_SETCHECK, state, 0);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
189 i->value = v;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
190 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
191
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
192 int ui_togglebutton_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
193 if (uMsg != WM_COMMAND) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
194 return 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
195 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
196 UiWidget *w = (UiWidget*)widget;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
197
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
198 UiEvent e;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
199 e.obj = w->obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
200 e.document = e.obj->ctx->document;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
201 e.window = e.obj->window;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
202 e.eventdata = NULL;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
203 e.eventdatatype = 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
204 e.intval = SendMessage(w->widget.hwnd, BM_GETCHECK, 0, 0);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
205 e.set = ui_get_setop();
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
206
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
207 if (w->callback) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
208 w->callback(&e, w->callbackdata);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
209 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
210
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
211 return 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
212 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
213
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
214
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
215 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs *args) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
216 HINSTANCE hInstance = GetModuleHandle(NULL);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
217 UiContainerPrivate *container = ui_obj_container(obj);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
218 HWND parent = ui_container_get_parent(container);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
219 UiLayout layout = UI_ARGS2LAYOUT(args);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
220
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
221 HWND hwnd = CreateWindow(
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
222 "BUTTON",
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
223 args->label,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
224 WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_GROUP ,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
225 0, 0, 100, 30,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
226 parent,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
227 (HMENU)1,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
228 hInstance,
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
229 NULL);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
230 ui_win32_set_ui_font(hwnd);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
231
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
232 W32Widget *widget = w32_widget_create(&radiobutton_widget_class, hwnd, sizeof(UiWidget));
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
233 ui_container_add(container, widget, &layout);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
234 UiWidget *btn = (UiWidget*)widget;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
235
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
236 UiVar *var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_INTEGER);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
237 if (var) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
238 UiInteger *i = var->value;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
239 // Use a CxList as binding object (i->obj) and add all radiobuttons to it
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
240 // The first radiobutton, which binds to this var, creates the CxList
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
241 CxList *group = NULL;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
242 if (i->obj) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
243 group = i->obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
244 } else {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
245 group = cxArrayListCreate(obj->ctx->allocator, NULL, CX_STORE_POINTERS, 8);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
246 i->obj = group;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
247 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
248
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
249 cxListAdd(group, btn);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
250 if (i->value == cxListSize(group)) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
251 // TODO: select
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
252 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
253 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
254
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
255 btn->obj = obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
256 btn->var = var;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
257 btn->callback = args->onchange;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
258 btn->callbackdata = args->onchangedata;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
259
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
260 return widget;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
261 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
262
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
263 int ui_radiobutton_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
264 if (uMsg != WM_COMMAND) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
265 return 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
266 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
267 UiWidget *w = (UiWidget*)widget;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
268
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
269 int checked = SendMessage(w->widget.hwnd, BM_GETCHECK, 0, 0);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
270 if (!checked) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
271 return 0; // ignore uncheck events
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
272 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
273
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
274 int b = 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
275 if (w->var) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
276 UiInteger *i = w->var->value;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
277 CxList *group = i->obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
278 // Find selected index and uncheck all radiobuttons in this group
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
279 // that are not this event widget
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
280 CxIterator iter = cxListIterator(group);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
281 cx_foreach(UiWidget *, radiobutton, iter) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
282 if (radiobutton == w) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
283 i->value = iter.index+1;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
284 b = i->value;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
285 } else {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
286 SendMessage(radiobutton->widget.hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
287 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
288 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
289 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
290
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
291 UiEvent e;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
292 e.obj = w->obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
293 e.document = e.obj->ctx->document;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
294 e.window = e.obj->window;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
295 e.eventdata = NULL;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
296 e.eventdatatype = 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
297 e.intval = b;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
298 e.set = ui_get_setop();
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
299
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
300 if (w->callback) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
301 w->callback(&e, w->callbackdata);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
302 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
303
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
304 return 0;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
305 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
306
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
307 int64_t ui_radiobutton_get(UiInteger *i) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
308 return i->value;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
309 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
310
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
311 void ui_radiobutton_set(UiInteger *i, int64_t v) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
312 CxList *group = i->obj;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
313 CxIterator iter = cxListIterator(group);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
314 cx_foreach(UiWidget *, radiobutton, iter) {
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
315 SendMessage(radiobutton->widget.hwnd, BM_SETCHECK, iter.index+1 == v ? BST_CHECKED : BST_UNCHECKED, 0);
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
316 }
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
317 i->value = v;
e57ca2747782 fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 113
diff changeset
318 }

mercurial