-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcheckbox.h
72 lines (60 loc) · 2.03 KB
/
checkbox.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
/**
* 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_native_ctrl_pubm.h"
#include "internals/base_text_pubm.h"
#include "internals/styler.h"
#include "wnd.h"
namespace wl {
// Wrapper to native checkbox control.
class checkbox final :
public wnd,
public _wli::base_native_ctrl_pubm<checkbox>,
public _wli::base_focus_pubm<checkbox>,
public _wli::base_text_pubm<checkbox>
{
private:
HWND _hWnd = nullptr;
_wli::base_native_ctrl _baseNativeCtrl{_hWnd};
public:
// Wraps window style changes done by Get/SetWindowLongPtr.
_wli::styler<checkbox> style{this};
checkbox() noexcept :
wnd(_hWnd), base_native_ctrl_pubm(_baseNativeCtrl),
base_focus_pubm(_hWnd), base_text_pubm(_hWnd) { }
checkbox(checkbox&&) = default;
checkbox& operator=(checkbox&&) = default; // movable only
checkbox& 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_AUTOCHECKBOX);
return *this;
}
checkbox& 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;
}
checkbox& set_check(bool checked) noexcept {
SendMessageW(this->_hWnd, BM_SETCHECK,
checked ? BST_CHECKED : BST_UNCHECKED, 0);
return *this;
}
checkbox& 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