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
|
#if defined(Hiro_RadioLabel)
namespace hiro {
auto pRadioLabel::construct() -> void {
hwnd = CreateWindow(
L"BUTTON", L"", WS_CHILD | WS_TABSTOP | BS_RADIOBUTTON,
0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0
);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
pWidget::_setState();
setGroup(state().group);
setText(state().text);
}
auto pRadioLabel::destruct() -> void {
DestroyWindow(hwnd);
}
auto pRadioLabel::minimumSize() const -> Size {
auto size = pFont::size(self().font(true), state().text ? state().text : " ");
return {size.width() + 20, size.height() + 4};
}
auto pRadioLabel::setChecked() -> void {
if(auto& group = state().group) {
for(auto& weak : group->state.objects) {
if(auto object = weak.acquire()) {
if(auto radioLabel = dynamic_cast<mRadioLabel*>(object.data())) {
if(auto self = radioLabel->self()) {
SendMessage(self->hwnd, BM_SETCHECK, (WPARAM)(&self->reference == &reference), 0);
}
}
}
}
}
}
auto pRadioLabel::setGroup(sGroup group) -> void {
bool first = true;
if(auto& group = state().group) {
for(auto& weak : group->state.objects) {
if(auto object = weak.acquire()) {
if(auto radioLabel = dynamic_cast<mRadioLabel*>(object.data())) {
if(auto self = radioLabel->self()) {
SendMessage(self->hwnd, BM_SETCHECK, (WPARAM)(radioLabel->state.checked = first), 0);
first = false;
}
}
}
}
}
}
auto pRadioLabel::setText(const string& text) -> void {
SetWindowText(hwnd, utf16_t(text));
}
auto pRadioLabel::onActivate() -> void {
if(state().checked) return;
self().setChecked();
self().doActivate();
}
}
#endif
|