Debian Codegraph @

phoenix/windows/widget/radio-button.cpp

raw
1 namespace phoenix {
2
3 Size pRadioButton::minimumSize() {
4 Size size = pFont::size(hfont, radioButton.state.text);
5
6 if(radioButton.state.orientation == Orientation::Horizontal) {
7 size.width += radioButton.state.image.width;
8 size.height = max(radioButton.state.image.height, size.height);
9 }
10
11 if(radioButton.state.orientation == Orientation::Vertical) {
12 size.width = max(radioButton.state.image.width, size.width);
13 size.height += radioButton.state.image.height;
14 }
15
16 return {size.width + 20, size.height + 10};
17 }
18
19 void pRadioButton::setChecked() {
20 for(auto& item : radioButton.state.group) {
21 SendMessage(item.p.hwnd, BM_SETCHECK, (WPARAM)(&item == &radioButton), 0);
22 }
23 }
24
25 void pRadioButton::setGroup(const group<RadioButton>& group) {
26 }
27
28 void pRadioButton::setImage(const image& image, Orientation orientation) {
29 nall::image nallImage = image;
30 nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0);
31
32 if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; }
33 if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; }
34
35 if(OsVersion() < WindowsVista) nallImage.alphaBlend(GetSysColor(COLOR_BTNFACE));
36 hbitmap = CreateBitmap(nallImage);
37 himagelist = ImageList_Create(nallImage.width, nallImage.height, ILC_COLOR32, 1, 0);
38 ImageList_Add(himagelist, hbitmap, NULL);
39 BUTTON_IMAGELIST list;
40 list.himl = himagelist;
41 switch(orientation) {
42 case Orientation::Horizontal: SetRect(&list.margin, 5, 0, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_LEFT; break;
43 case Orientation::Vertical: SetRect(&list.margin, 0, 5, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_TOP; break;
44 }
45 Button_SetImageList(hwnd, &list);
46
47 setText(radioButton.state.text);
48 }
49
50 void pRadioButton::setText(string text) {
51 if(text.empty()) {
52 SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_BITMAP);
53 } else {
54 SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~BS_BITMAP);
55 }
56
57 SetWindowText(hwnd, utf16_t(text));
58 }
59
60 void pRadioButton::constructor() {
61 hwnd = CreateWindow(L"BUTTON", L"",
62 WS_CHILD | WS_TABSTOP | BS_CHECKBOX | BS_PUSHLIKE,
63 0, 0, 0, 0, parentHwnd, (HMENU)id, GetModuleHandle(0), 0);
64 SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&radioButton);
65 setDefaultFont();
66 if(radioButton.state.checked) setChecked();
67 setImage(radioButton.state.image, radioButton.state.orientation);
68 //setText(radioButton.state.text);
69 synchronize();
70 }
71
72 void pRadioButton::destructor() {
73 if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; }
74 if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; }
75 DestroyWindow(hwnd);
76 }
77
78 void pRadioButton::orphan() {
79 destructor();
80 constructor();
81 }
82
83 void pRadioButton::onActivate() {
84 if(radioButton.state.checked) return;
85 radioButton.setChecked();
86 if(radioButton.onActivate) radioButton.onActivate();
87 }
88
89 }