-
Notifications
You must be signed in to change notification settings - Fork 35
/
radio.h
81 lines (67 loc) · 2.21 KB
/
radio.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Part of WinLamb - Win32 API Lambda Library
* https://github.com/rodrigocfd/winlamb
* Copyright 2017-present Rodrigo Cesar de Freitas Dias
* This library is released under the MIT License
*/
#pragma once
#include "internals/base_focus_pubm.h"
#include "internals/base_text_pubm.h"
#include "internals/base_native_ctrl_pubm.h"
#include "internals/styler.h"
#include "wnd.h"
namespace wl {
// Wrapper to native radio button control.
class radio final :
public wnd,
public _wli::base_native_ctrl_pubm<radio>,
public _wli::base_focus_pubm<radio>,
public _wli::base_text_pubm<radio>
{
private:
class _styler final : public _wli::styler<radio> {
public:
explicit _styler(radio* pRadio) noexcept : styler(pRadio) { }
radio& first_in_group(bool doSet) noexcept {
return this->set_style(doSet, WS_GROUP);
}
};
HWND _hWnd = nullptr;
_wli::base_native_ctrl _baseNativeCtrl{_hWnd};
public:
// Wraps window style changes done by Get/SetWindowLongPtr.
_styler style{this};
radio() noexcept :
wnd(_hWnd), base_native_ctrl_pubm(_baseNativeCtrl),
base_focus_pubm(_hWnd), base_text_pubm(_hWnd) { }
radio(radio&&) = default;
radio& operator=(radio&&) = default; // movable only
radio& create(HWND hParent, int ctrlId,
const wchar_t* caption, POINT pos, SIZE size)
{
this->_baseNativeCtrl.create(hParent, ctrlId, caption, pos, size,
L"Button", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTORADIOBUTTON);
return *this;
}
radio& create(const wnd* parent, int ctrlId,
const wchar_t* caption, POINT pos, SIZE size)
{
return this->create(parent->hwnd(), ctrlId, caption, pos, size);
}
bool is_checked() const noexcept {
return SendMessageW(this->_hWnd, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
radio& set_check(bool checked) noexcept {
SendMessageW(this->_hWnd, BM_SETCHECK,
checked ? BST_CHECKED : BST_UNCHECKED, 0);
return *this;
}
radio& set_check_and_trigger(bool checked) noexcept {
this->set_check(checked);
SendMessageW(GetParent(this->_hWnd), WM_COMMAND,
MAKEWPARAM(GetDlgCtrlID(this->_hWnd), 0),
reinterpret_cast<LPARAM>(this->_hWnd) ); // emulate user click
return *this;
}
};
}//namespace wl