2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
|
|
|
Size pCheckButton::minimumSize() {
|
|
|
|
Size size = pFont::size(hfont, checkButton.state.text);
|
2013-11-28 10:29:01 +00:00
|
|
|
|
|
|
|
if(checkButton.state.orientation == Orientation::Horizontal) {
|
|
|
|
size.width += checkButton.state.image.width;
|
|
|
|
size.height = max(checkButton.state.image.height, size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(checkButton.state.orientation == Orientation::Vertical) {
|
|
|
|
size.width = max(checkButton.state.image.width, size.width);
|
|
|
|
size.height += checkButton.state.image.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {size.width + 20, size.height + 10};
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::setChecked(bool checked) {
|
|
|
|
SendMessage(hwnd, BM_SETCHECK, (WPARAM)checked, 0);
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pCheckButton::setImage(const image& image, Orientation orientation) {
|
|
|
|
nall::image nallImage = image;
|
|
|
|
nallImage.transform(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0);
|
|
|
|
|
|
|
|
if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; }
|
|
|
|
if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; }
|
|
|
|
|
|
|
|
if(OsVersion() < WindowsVista) nallImage.alphaBlend(GetSysColor(COLOR_BTNFACE));
|
|
|
|
hbitmap = CreateBitmap(nallImage);
|
|
|
|
himagelist = ImageList_Create(nallImage.width, nallImage.height, ILC_COLOR32, 1, 0);
|
|
|
|
ImageList_Add(himagelist, hbitmap, NULL);
|
|
|
|
BUTTON_IMAGELIST list;
|
|
|
|
list.himl = himagelist;
|
|
|
|
switch(orientation) {
|
|
|
|
case Orientation::Horizontal: SetRect(&list.margin, 5, 0, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_LEFT; break;
|
|
|
|
case Orientation::Vertical: SetRect(&list.margin, 0, 5, 0, 0); list.uAlign = BUTTON_IMAGELIST_ALIGN_TOP; break;
|
|
|
|
}
|
|
|
|
Button_SetImageList(hwnd, &list);
|
|
|
|
|
|
|
|
setText(checkButton.state.text);
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
void pCheckButton::setText(string text) {
|
2013-11-28 10:29:01 +00:00
|
|
|
if(text.empty()) {
|
|
|
|
SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_BITMAP);
|
|
|
|
} else {
|
|
|
|
SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~BS_BITMAP);
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
SetWindowText(hwnd, utf16_t(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::constructor() {
|
2013-11-28 10:29:01 +00:00
|
|
|
hwnd = CreateWindow(L"BUTTON", L"",
|
|
|
|
WS_CHILD | WS_TABSTOP | BS_CHECKBOX | BS_PUSHLIKE,
|
|
|
|
0, 0, 0, 0, parentHwnd, (HMENU)id, GetModuleHandle(0), 0);
|
2013-03-15 13:11:33 +00:00
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&checkButton);
|
|
|
|
setDefaultFont();
|
2013-11-28 10:29:01 +00:00
|
|
|
setChecked(checkButton.state.checked);
|
|
|
|
setImage(checkButton.state.image, checkButton.state.orientation);
|
|
|
|
//setText(checkButton.state.text);
|
2013-03-15 13:11:33 +00:00
|
|
|
synchronize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::destructor() {
|
2013-11-28 10:29:01 +00:00
|
|
|
if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; }
|
|
|
|
if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; }
|
2013-03-15 13:11:33 +00:00
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pCheckButton::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:29:01 +00:00
|
|
|
void pCheckButton::onToggle() {
|
|
|
|
checkButton.state.checked = !checkButton.state.checked;
|
|
|
|
setChecked(checkButton.state.checked);
|
|
|
|
if(checkButton.onToggle) checkButton.onToggle();
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|