2015-06-12 13:14:38 +00:00
|
|
|
#if defined(Hiro_RadioButton)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
namespace hiro {
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pRadioButton::construct() -> void {
|
|
|
|
hwnd = CreateWindow(L"BUTTON", L"",
|
|
|
|
WS_CHILD | WS_TABSTOP | BS_CHECKBOX | BS_PUSHLIKE,
|
|
|
|
0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0);
|
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
|
|
|
|
pWidget::_setState();
|
|
|
|
_setState();
|
|
|
|
setBordered(state().bordered);
|
|
|
|
if(state().checked) setChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pRadioButton::destruct() -> void {
|
|
|
|
if(hbitmap) { DeleteObject(hbitmap); hbitmap = 0; }
|
|
|
|
if(himagelist) { ImageList_Destroy(himagelist); himagelist = 0; }
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pRadioButton::minimumSize() -> Size {
|
|
|
|
auto size = pFont::size(hfont, state().text);
|
|
|
|
|
|
|
|
if(state().orientation == Orientation::Horizontal) {
|
2015-06-18 10:48:53 +00:00
|
|
|
size.setWidth(size.width() + state().icon.width());
|
|
|
|
size.setHeight(max(size.height(), state().icon.height()));
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
if(state().orientation == Orientation::Vertical) {
|
2015-06-18 10:48:53 +00:00
|
|
|
size.setWidth(max(size.width(), state().icon.width()));
|
|
|
|
size.setHeight(size.height() + state().icon.height());
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
return {size.width() + (state().text ? 20 : 10), size.height() + 10};
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pRadioButton::setBordered(bool bordered) -> void {
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pRadioButton::setChecked() -> void {
|
|
|
|
if(auto group = self().group()) {
|
|
|
|
for(auto& weak : group->state.objects) {
|
|
|
|
if(auto object = weak.acquire()) {
|
|
|
|
if(auto radioButton = dynamic_cast<mRadioButton*>(object.data())) {
|
|
|
|
if(auto self = radioButton->self()) {
|
|
|
|
SendMessage(self->hwnd, BM_SETCHECK, (WPARAM)(&self->reference == &reference), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pRadioButton::setGroup(sGroup group) -> void {
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pRadioButton::setIcon(const image& icon) -> void {
|
|
|
|
_setState();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pRadioButton::setOrientation(Orientation orientation) -> void {
|
|
|
|
_setState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::setText(const string& text) {
|
|
|
|
_setState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pRadioButton::onActivate() {
|
|
|
|
if(state().checked) return;
|
|
|
|
self().setChecked();
|
|
|
|
self().doActivate();
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pRadioButton::_setState() -> void {
|
|
|
|
image icon = state().icon;
|
2015-06-18 10:48:53 +00:00
|
|
|
icon.transform();
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-06-18 10:48:53 +00:00
|
|
|
if(hbitmap) { DeleteObject(hbitmap); hbitmap = nullptr; }
|
|
|
|
if(himagelist) { ImageList_Destroy(himagelist); himagelist = nullptr; }
|
2013-11-28 10:29:01 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
if(OsVersion() < WindowsVista) icon.alphaBlend(GetSysColor(COLOR_BTNFACE));
|
|
|
|
|
|
|
|
hbitmap = CreateBitmap(icon);
|
2015-06-18 10:48:53 +00:00
|
|
|
himagelist = ImageList_Create(icon.width(), icon.height(), ILC_COLOR32, 1, 0);
|
|
|
|
ImageList_Add(himagelist, hbitmap, nullptr);
|
2013-11-28 10:29:01 +00:00
|
|
|
BUTTON_IMAGELIST list;
|
|
|
|
list.himl = himagelist;
|
2015-06-12 13:14:38 +00:00
|
|
|
switch(state().orientation) {
|
2013-11-28 10:29:01 +00:00
|
|
|
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);
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
if(auto text = state().text) {
|
|
|
|
SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) &~ BS_BITMAP);
|
|
|
|
SetWindowText(hwnd, utf16_t(text));
|
2013-11-28 10:29:01 +00:00
|
|
|
} else {
|
2015-06-12 13:14:38 +00:00
|
|
|
SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | BS_BITMAP);
|
|
|
|
SetWindowText(hwnd, L"");
|
2013-11-28 10:29:01 +00:00
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
#endif
|