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