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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#include "stdafx.h"
#include "optionsctrlimpl.h"
#include "main.h"
/*
* OptionsCtrlImpl::Edit
*/
ext::string OptionsCtrlImpl::Edit::getEditText()
{
int nLen = GetWindowTextLength(m_hEditWnd);
wchar_t* szBuf = new wchar_t[nLen + 1];
GetWindowText(m_hEditWnd, szBuf, nLen + 1);
ext::string strTemp = szBuf;
delete[] szBuf;
return strTemp;
}
ext::string OptionsCtrlImpl::Edit::getCombinedText()
{
if (m_strEdit.empty())
{
return m_strLabel;
}
else
{
ext::string strTemp = m_strLabel;
strTemp += L": ";
strTemp += m_strEdit;
return strTemp;
}
}
OptionsCtrlImpl::Edit::Edit(OptionsCtrlImpl* pCtrl, Item* pParent, const wchar_t* szLabel, const wchar_t* szEdit, uint32_t dwFlags, INT_PTR dwData)
: Item(pCtrl, itEdit, szLabel, dwFlags, dwData), m_hEditWnd(nullptr)
{
m_strEdit = szEdit;
m_bNumber = bool_(dwFlags & OCF_NUMBER);
m_pCtrl->insertItem(pParent, this, getCombinedText().c_str(), dwFlags, m_bEnabled ? siEdit : siEditG);
if (pParent)
{
pParent->childAdded(this);
}
}
void OptionsCtrlImpl::Edit::onSelect()
{
if (!m_bEnabled || m_hEditWnd)
{
return;
}
m_pCtrl->setNodeText(m_hItem, m_strLabel.c_str());
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 | ES_LEFT | ES_AUTOHSCROLL;
if (m_bNumber)
{
dwStyle |= ES_NUMBER | ES_RIGHT;
}
if (hTempWnd = CreateWindowEx(
WS_EX_CLIENTEDGE, WC_EDIT, m_strEdit.c_str(), dwStyle,
r.left, r.top, r.right - r.left, r.bottom - r.top,
m_pCtrl->m_hTree, reinterpret_cast<HMENU>(ccEdit), g_plugin.getInst(), nullptr))
{
SendMessage(hTempWnd, WM_SETFONT, reinterpret_cast<WPARAM>(hTreeFront), MAKELPARAM(TRUE, 0));
m_hEditWnd = hTempWnd;
}
}
}
void OptionsCtrlImpl::Edit::onDeselect()
{
if (m_hEditWnd)
{
RECT rToInvalidate;
bool bValidRect = false;
if (GetWindowRect(m_hEditWnd, &rToInvalidate))
{
ScreenToClient(m_pCtrl->m_hTree, reinterpret_cast<POINT*>(&rToInvalidate) + 0);
ScreenToClient(m_pCtrl->m_hTree, reinterpret_cast<POINT*>(&rToInvalidate) + 1);
bValidRect = true;
}
m_strEdit = getEditText();
m_pCtrl->setNodeText(m_hItem, getCombinedText().c_str());
DestroyWindow(m_hEditWnd);
m_hEditWnd = nullptr;
InvalidateRect(m_pCtrl->m_hTree, bValidRect ? &rToInvalidate : nullptr, TRUE);
}
}
void OptionsCtrlImpl::Edit::onActivate()
{
if (!m_hEditWnd)
{
onSelect();
}
if (m_hEditWnd)
{
SetFocus(m_hEditWnd);
SendMessage(m_hEditWnd, EM_SETSEL, 0, -1);
}
}
void OptionsCtrlImpl::Edit::setEnabled(bool bEnable)
{
m_bEnabled = bEnable;
m_pCtrl->setStateImage(m_hItem, bEnable ? siEdit : siEditG);
if (m_bDisableChilds)
{
enableChilds(m_bEnabled);
}
}
void OptionsCtrlImpl::Edit::childAdded(Item* pChild)
{
if (m_bDisableChilds)
{
pChild->setEnabled(m_bEnabled);
}
}
const wchar_t* OptionsCtrlImpl::Edit::getString()
{
if (m_hEditWnd)
{
m_strEdit = getEditText();
}
return m_strEdit.c_str();
}
void OptionsCtrlImpl::Edit::setString(const wchar_t* szString)
{
m_strEdit = szString;
if (m_hEditWnd)
{
SetWindowText(m_hEditWnd, m_strEdit.c_str());
}
else
{
m_pCtrl->setNodeText(m_hItem, getCombinedText().c_str());
}
}
void OptionsCtrlImpl::Edit::setLabel(const wchar_t* szLabel)
{
m_strLabel = szLabel;
// only if not editing (otherwise update when user finishes editing)
if (!m_hEditWnd)
{
m_pCtrl->setNodeText(m_hItem, getCombinedText().c_str());
}
}
|