ui/win32/button.c

changeset 112
c3f2f16fa4b8
parent 108
77254bd6dccb
child 113
dde28a806552
equal deleted inserted replaced
111:81c4f73236a4 112:c3f2f16fa4b8
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "button.h" 29 #include "button.h"
30 #include "widget.h"
31
32 #include <stdio.h>
33 #include <stdlib.h>
34
35 #include <commctrl.h>
36
37 static W32WidgetClass button_widget_class = {
38 .eventproc = ui_button_eventproc,
39 .enable = w32_widget_default_enable,
40 .show = w32_widget_default_show,
41 .get_preferred_size = ui_button_get_preferred_size,
42 .destroy = w32_widget_default_destroy
43 };
30 44
31 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) { 45 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) {
32 return NULL; 46 HINSTANCE hInstance = GetModuleHandle(NULL);
47 UiContainerPrivate *container = ui_obj_container(obj);
48 HWND parent = ui_container_get_parent(container);
49 UiLayout layout = UI_ARGS2LAYOUT(args);
50
51 HWND hwnd = CreateWindow(
52 "BUTTON",
53 args->label,
54 WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
55 0, 0, 100, 30,
56 parent,
57 (HMENU)0,
58 hInstance,
59 NULL);
60 ui_win32_set_ui_font(hwnd);
61
62 W32Widget *widget = w32_widget_create(&button_widget_class, hwnd, sizeof(UiWidget));
63 ui_container_add(container, widget, &layout);
64
65 UiWidget *btn = (UiWidget*)widget;
66 btn->obj = obj;
67 btn->callback = args->onclick;
68 btn->callbackdata = args->onclickdata;
69
70 return widget;
33 } 71 }
72
73 W32Size ui_button_get_preferred_size(W32Widget *widget) {
74 W32Size size;
75 size.width = 100;
76 size.height = 30;
77 SIZE sz;
78 if (Button_GetIdealSize(widget->hwnd, &sz)) {
79 size.width = sz.cx;
80 size.height = sz.cy;
81 }
82 return size;
83 }
84
85 void ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
86 UiWidget *w = (UiWidget*)widget;
87
88 UiEvent e;
89 e.obj = w->obj;
90 e.document = e.obj->ctx->document;
91 e.window = e.obj->window;
92 e.eventdata = NULL;
93 e.eventdatatype = 0;
94 e.intval = 0;
95 e.set = ui_get_setop();
96
97 if (w->callback) {
98 w->callback(&e, w->callbackdata);
99 }
100 }

mercurial