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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#include "stdafx.h"
#include "optionsctrlimpl.h"
#include "main.h"
/*
* OptionsCtrlImpl::Button
*/
OptionsCtrlImpl::Button::Button(OptionsCtrlImpl* pCtrl, Item* pParent, const wchar_t* szLabel, const wchar_t* szButton, uint32_t dwFlags, INT_PTR dwData)
: Item(pCtrl, itButton, szLabel, dwFlags, dwData)
, m_hButtonWnd(nullptr)
, m_strButton(szButton)
{
m_pCtrl->insertItem(pParent, this, m_strLabel.c_str(), dwFlags, m_bEnabled ? siButton : siButtonG);
if (pParent)
{
pParent->childAdded(this);
}
}
void OptionsCtrlImpl::Button::onSelect()
{
if (!m_bEnabled || m_hButtonWnd)
{
return;
}
HFONT hTreeFront = reinterpret_cast<HFONT>(SendMessage(m_pCtrl->m_hTree, WM_GETFONT, 0, 0));
RECT r;
if (m_pCtrl->getItemFreeRect(m_hItem, r))
{
r.top -= 2;
r.bottom += 2;
if (r.left + 50 > r.right)
{
r.left = r.right - 50;
}
HWND hTempWnd;
uint32_t dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_TEXT | BS_CENTER | BS_VCENTER;
if (hTempWnd = CreateWindowEx(
0, WC_BUTTON, m_strButton.c_str(), dwStyle,
r.left, r.top, r.right - r.left, r.bottom - r.top,
m_pCtrl->m_hTree, reinterpret_cast<HMENU>(ccButton), g_plugin.getInst(), nullptr))
{
SendMessage(hTempWnd, WM_SETFONT, reinterpret_cast<WPARAM>(hTreeFront), MAKELPARAM(TRUE, 0));
m_hButtonWnd = hTempWnd;
}
}
}
void OptionsCtrlImpl::Button::onDeselect()
{
if (m_hButtonWnd)
{
RECT rToInvalidate;
bool bValidRect = false;
if (GetWindowRect(m_hButtonWnd, &rToInvalidate))
{
ScreenToClient(m_pCtrl->m_hTree, reinterpret_cast<POINT*>(&rToInvalidate) + 0);
ScreenToClient(m_pCtrl->m_hTree, reinterpret_cast<POINT*>(&rToInvalidate) + 1);
bValidRect = true;
}
m_pCtrl->setNodeText(m_hItem, m_strLabel.c_str());
DestroyWindow(m_hButtonWnd);
m_hButtonWnd = nullptr;
InvalidateRect(m_pCtrl->m_hTree, bValidRect ? &rToInvalidate : nullptr, TRUE);
}
}
void OptionsCtrlImpl::Button::onActivate()
{
if (!m_hButtonWnd)
{
onSelect();
}
if (m_hButtonWnd)
{
SetFocus(m_hButtonWnd);
}
}
void OptionsCtrlImpl::Button::setEnabled(bool bEnable)
{
m_bEnabled = bEnable;
m_pCtrl->setStateImage(m_hItem, bEnable ? siButton : siButtonG);
if (m_bDisableChilds)
{
enableChilds(m_bEnabled);
}
}
void OptionsCtrlImpl::Button::childAdded(Item* pChild)
{
if (m_bDisableChilds)
{
pChild->setEnabled(m_bEnabled);
}
}
void OptionsCtrlImpl::Button::setLabel(const wchar_t* szLabel)
{
m_strLabel = szLabel;
// only if not showing button (otherwise update when button disappears)
if (!m_hButtonWnd)
{
m_pCtrl->setNodeText(m_hItem, m_strLabel.c_str());
}
}
|