ui/win32/button.c

changeset 827
eae5b817aa47
parent 825
1bac7e45712b
child 841
651cf2c59dd9
equal deleted inserted replaced
826:e596cfc1ca46 827:eae5b817aa47
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 static W32WidgetClass button_widget_class = {
36 .eventproc = ui_button_eventproc,
37 .enable = w32_widget_default_enable,
38 .show = w32_widget_default_show,
39 .get_preferred_size = ui_button_get_preferred_size,
40 .destroy = w32_widget_default_destroy
41 };
30 42
31 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) { 43 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) {
32 return NULL; 44 HINSTANCE hInstance = GetModuleHandle(NULL);
45 UiContainerPrivate *container = ui_obj_container(obj);
46 HWND parent = ui_container_get_parent(container);
47 UiLayout layout = UI_ARGS2LAYOUT(args);
48
49 HWND hwnd = CreateWindow(
50 "BUTTON",
51 args->label,
52 WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
53 0, 0, 100, 30,
54 parent,
55 (HMENU)0,
56 hInstance,
57 NULL);
58 ui_win32_set_ui_font(hwnd);
59
60 W32Widget *widget = w32_widget_create(&button_widget_class, hwnd, sizeof(UiWidget));
61 ui_container_add(container, widget, &layout);
62
63 UiWidget *btn = (UiWidget*)widget;
64 btn->obj = obj;
65 btn->callback = args->onclick;
66 btn->callbackdata = args->onclickdata;
67
68 return widget;
33 } 69 }
70
71 W32Size ui_button_get_preferred_size(W32Widget *widget) {
72 W32Size size;
73 size.width = 100;
74 size.height = 30;
75 return size;
76 }
77
78 void ui_button_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
79 UiWidget *w = (UiWidget*)widget;
80
81 UiEvent e;
82 e.obj = w->obj;
83 e.document = e.obj->ctx->document;
84 e.window = e.obj->window;
85 e.eventdata = NULL;
86 e.eventdatatype = 0;
87 e.intval = 0;
88 e.set = ui_get_setop();
89
90 if (w->callback) {
91 w->callback(&e, w->callbackdata);
92 }
93 }

mercurial