summaryrefslogtreecommitdiff
path: root/new/button_windows.c
blob: a66490d23f5193b756c5a98a416df47a4b48e269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 7 april 2015
#include "uipriv_windows.h"

struct button {
	uiControl *c;
	void (*onClicked)(uiControl *, void *);
	void *onClickedData;
};

#define B(x) ((struct button *) (x))

static BOOL onWM_COMMAND(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult)
{
	if (HIWORD(wParam) != BN_CLICKED)
		return FALSE;
	(*(B(data)->onClicked))(c, B(data)->onClickedData);
	*lResult = 0;
	return TRUE;
}

static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult)
{
	return FALSE;
}

static void preferredSize(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height)
{
	// TODO
}

static void defaultOnClicked(uiControl *c, void *data)
{
	// do nothing
}

uiControl *uiNewButton(const char *text)
{
	struct button *b;
	uiWindowsNewControlParams p;
	WCHAR *wtext;

	b = uiNew(struct button);

	p.dwExStyle = 0;
	p.lpClassName = L"button";
	p.dwStyle = BS_PUSHBUTTON;
	p.hInstance = hInstance;
	p.onWM_COMMAND = onWM_COMMAND;
	p.onWM_NOTIFY = onWM_NOTIFY;
	p.onCommandNotifyData = b;
	p.preferredSize = preferredSize;
	p.data = b;
	b->c = uiWindowsNewControl(&p);

	wtext = toUTF16(text);
	// TODO set text
	uiFree(wtext);

	b->onClicked = defaultOnClicked;

	return b->c;
}

// TODO text

void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
{
	struct button *b;

	b = (struct button *) uiWindowsControlData(c);
	b->onClicked = f;
	b->onClickedData = data;
}