summaryrefslogtreecommitdiff
path: root/plugins/!NotAdopted/HistoryStats/optionsctrl.cpp
blob: dd0d077f262e31e37d266949c471dc1f534dac9f (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include "_globals.h"
#include "optionsctrl.h"

#include "utils.h"

/*
 * OptionsCtrl
 */

HANDLE OptionsCtrl::insertGroup(HANDLE hParent, const mu_text* szLabel, DWORD dwFlags /* = 0 */, DWORD dwData /* = 0 */)
{
	OCGROUP ocg;

	ocg.dwFlags = dwFlags;
	ocg.szLabel = const_cast<mu_text*>(szLabel);
	ocg.dwData = dwData;

	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_INSERTGROUP, reinterpret_cast<WPARAM>(hParent), reinterpret_cast<LPARAM>(&ocg)));
}

HANDLE OptionsCtrl::insertCheck(HANDLE hParent, const mu_text* szLabel, DWORD dwFlags /* = 0 */, DWORD dwData /* = 0 */)
{
	OCCHECK occ;

	occ.dwFlags = dwFlags;
	occ.szLabel = const_cast<mu_text*>(szLabel);
	occ.dwData = dwData;

	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_INSERTCHECK, reinterpret_cast<WPARAM>(hParent), reinterpret_cast<LPARAM>(&occ)));
}

HANDLE OptionsCtrl::insertRadio(HANDLE hParent, HANDLE hSibling, const mu_text* szLabel, DWORD dwFlags /* = 0 */, DWORD dwData /* = 0 */)
{
	OCRADIO ocr;

	ocr.dwFlags = dwFlags;
	ocr.szLabel = const_cast<mu_text*>(szLabel);
	ocr.dwData = dwData;
	ocr.hSibling = hSibling;

	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_INSERTRADIO, reinterpret_cast<WPARAM>(hParent), reinterpret_cast<LPARAM>(&ocr)));
}

HANDLE OptionsCtrl::insertEdit(HANDLE hParent, const mu_text* szLabel, const mu_text* szEdit /* = muT("") */, DWORD dwFlags /* = 0 */, DWORD dwData /* = 0 */)
{
	OCEDIT oce;

	oce.dwFlags = dwFlags;
	oce.szLabel = const_cast<mu_text*>(szLabel);
	oce.dwData = dwData;
	oce.szEdit = const_cast<mu_text*>(szEdit);

	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_INSERTEDIT, reinterpret_cast<WPARAM>(hParent), reinterpret_cast<LPARAM>(&oce)));
}

HANDLE OptionsCtrl::insertCombo(HANDLE hParent, const mu_text* szLabel, DWORD dwFlags /* = 0 */, DWORD dwData /* = 0 */)
{
	OCCOMBO occ;

	occ.dwFlags = dwFlags;
	occ.szLabel = const_cast<mu_text*>(szLabel);
	occ.dwData = dwData;

	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_INSERTCOMBO, reinterpret_cast<WPARAM>(hParent), reinterpret_cast<LPARAM>(&occ)));
}

HANDLE OptionsCtrl::insertButton(HANDLE hParent, const mu_text* szLabel, const mu_text* szButton, DWORD dwFlags /* = 0 */, DWORD dwData /* = 0 */)
{
	OCBUTTON ocb;

	ocb.dwFlags = dwFlags;
	ocb.szLabel = const_cast<mu_text*>(szLabel);
	ocb.dwData = dwData;
	ocb.szButton = const_cast<mu_text*>(szButton);

	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_INSERTBUTTON, reinterpret_cast<WPARAM>(hParent), reinterpret_cast<LPARAM>(&ocb)));
}

HANDLE OptionsCtrl::insertDateTime(HANDLE hParent, const mu_text* szLabel, DWORD dwDateTime, const mu_text* szFormat /* = muT("%Y-%m-%d") */, DWORD dwFlags /* = 0 */, DWORD dwData /* = 0 */)
{
	OCDATETIME ocdt;

	ocdt.dwFlags = dwFlags;
	ocdt.szLabel = const_cast<mu_text*>(szLabel);
	ocdt.dwData = dwData;
	ocdt.szFormat = const_cast<mu_text*>(szFormat);
	ocdt.dwDateTime = dwDateTime;

	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_INSERTDATETIME, reinterpret_cast<WPARAM>(hParent), reinterpret_cast<LPARAM>(&ocdt)));
}

HANDLE OptionsCtrl::insertColor(HANDLE hParent, const mu_text* szLabel, COLORREF crColor /* = 0 */, DWORD dwFlags /* = 0 */, DWORD dwData /* = 0 */)
{
	OCCOLOR occ;

	occ.dwFlags = dwFlags;
	occ.szLabel = const_cast<mu_text*>(szLabel);
	occ.dwData = dwData;
	occ.crColor = crColor;

	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_INSERTCOLOR, reinterpret_cast<WPARAM>(hParent), reinterpret_cast<LPARAM>(&occ)));
}

const mu_text* OptionsCtrl::getItemLabel(HANDLE hItem)
{
	return reinterpret_cast<const mu_text*>(SendMessage(m_hOptWnd, OCM_GETITEMLABEL, reinterpret_cast<WPARAM>(hItem), 0));
}

void OptionsCtrl::setItemLabel(HANDLE hItem, const mu_text* szLabel)
{
	SendMessage(m_hOptWnd, OCM_SETITEMLABEL, reinterpret_cast<WPARAM>(hItem), reinterpret_cast<LPARAM>(szLabel));
}

bool OptionsCtrl::isItemEnabled(HANDLE hItem)
{
	return bool_(SendMessage(m_hOptWnd, OCM_ISITEMENABLED, reinterpret_cast<WPARAM>(hItem), 0));
}

void OptionsCtrl::enableItem(HANDLE hItem, bool bEnable)
{
	SendMessage(m_hOptWnd, OCM_ENABLEITEM, reinterpret_cast<WPARAM>(hItem), BOOL_(bEnable));
}

DWORD OptionsCtrl::getItemData(HANDLE hItem)
{
	return SendMessage(m_hOptWnd, OCM_GETITEMDATA, reinterpret_cast<WPARAM>(hItem), 0);
}

void OptionsCtrl::setItemData(HANDLE hItem, DWORD dwData)
{
	SendMessage(m_hOptWnd, OCM_SETITEMDATA, reinterpret_cast<WPARAM>(hItem), dwData);
}

bool OptionsCtrl::isItemChecked(HANDLE hItem)
{
	return bool_(SendMessage(m_hOptWnd, OCM_ISITEMCHECKED, reinterpret_cast<WPARAM>(hItem), 0));
}

void OptionsCtrl::checkItem(HANDLE hItem, bool bCheck)
{
	SendMessage(m_hOptWnd, OCM_CHECKITEM, reinterpret_cast<WPARAM>(hItem), BOOL_(bCheck));
}

int OptionsCtrl::getRadioChecked(HANDLE hRadio)
{
	return SendMessage(m_hOptWnd, OCM_GETRADIOCHECKED, reinterpret_cast<WPARAM>(hRadio), 0);
}

void OptionsCtrl::setRadioChecked(HANDLE hRadio, int nCheck)
{
	SendMessage(m_hOptWnd, OCM_SETRADIOCHECKED, reinterpret_cast<WPARAM>(hRadio), nCheck);
}

int OptionsCtrl::getEditNumber(HANDLE hEdit)
{
	return SendMessage(m_hOptWnd, OCM_GETEDITNUMBER, reinterpret_cast<WPARAM>(hEdit), 0);
}

void OptionsCtrl::setEditNumber(HANDLE hEdit, int nNumber)
{
	SendMessage(m_hOptWnd, OCM_SETEDITNUMBER, reinterpret_cast<WPARAM>(hEdit), nNumber);
}

const mu_text* OptionsCtrl::getEditString(HANDLE hEdit)
{
	return reinterpret_cast<const mu_text*>(SendMessage(m_hOptWnd, OCM_GETEDITSTRING, reinterpret_cast<WPARAM>(hEdit), 0));
}

void OptionsCtrl::setEditString(HANDLE hEdit, const mu_text* szString)
{
	SendMessage(m_hOptWnd, OCM_SETEDITSTRING, reinterpret_cast<WPARAM>(hEdit), reinterpret_cast<LPARAM>(szString));
}

void OptionsCtrl::addComboItem(HANDLE hCombo, const mu_text* szItem)
{
	SendMessage(m_hOptWnd, OCM_ADDCOMBOITEM, reinterpret_cast<WPARAM>(hCombo), reinterpret_cast<LPARAM>(szItem));
}

int OptionsCtrl::getComboSelected(HANDLE hCombo)
{
	return SendMessage(m_hOptWnd, OCM_GETCOMBOSELECTED, reinterpret_cast<WPARAM>(hCombo), 0);
}

void OptionsCtrl::setComboSelected(HANDLE hCombo, int nSelect)
{
	SendMessage(m_hOptWnd, OCM_SETCOMBOSELECTED, reinterpret_cast<WPARAM>(hCombo), nSelect);
}

void OptionsCtrl::ensureVisible(HANDLE hItem)
{
	SendMessage(m_hOptWnd, OCM_ENSUREVISIBLE, reinterpret_cast<WPARAM>(hItem), 0);
}

void OptionsCtrl::deleteAllItems()
{
	SendMessage(m_hOptWnd, OCM_DELETEALLITEMS, 0, 0);
}

HANDLE OptionsCtrl::getSelection()
{
	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_GETSELECTION, 0, 0));
}

void OptionsCtrl::selectItem(HANDLE hItem)
{
	SendMessage(m_hOptWnd, OCM_SELECTITEM, reinterpret_cast<WPARAM>(hItem), 0);
}

HANDLE OptionsCtrl::getFirstItem()
{
	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_GETITEM, 0, OCGI_FIRST));
}

HANDLE OptionsCtrl::getNextItem(HANDLE hItem)
{
	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_GETITEM, reinterpret_cast<WPARAM>(hItem), OCGI_NEXT));
}

HANDLE OptionsCtrl::getPrevItem(HANDLE hItem)
{
	return reinterpret_cast<HANDLE>(SendMessage(m_hOptWnd, OCM_GETITEM,reinterpret_cast<WPARAM>(hItem), OCGI_PREV));
}

void OptionsCtrl::setRedraw(bool bRedraw)
{
	SendMessage(m_hOptWnd, WM_SETREDRAW, BOOL_(bRedraw), 0);
}

void OptionsCtrl::deleteItem(HANDLE hItem)
{
	SendMessage(m_hOptWnd, OCM_DELETEITEM, reinterpret_cast<WPARAM>(hItem), 0);
}

void OptionsCtrl::moveItem(HANDLE& hItem, HANDLE hInsertAfter)
{
	SendMessage(m_hOptWnd, OCM_MOVEITEM, reinterpret_cast<WPARAM>(&hItem), reinterpret_cast<LPARAM>(hInsertAfter));
}

int OptionsCtrl::getScrollPos(int nBar)
{
	return SendMessage(m_hOptWnd, OCM_GETSCROLLPOS, nBar, 0);
}

void OptionsCtrl::setScrollPos(int nBar, int nPos)
{
	SendMessage(m_hOptWnd, OCM_SETSCROLLPOS, nBar, nPos);
}

bool OptionsCtrl::isDateTimeNone(HANDLE hDateTime)
{
	return bool_(SendMessage(m_hOptWnd, OCM_ISDATETIMENONE, reinterpret_cast<WPARAM>(hDateTime), 0));
}

void OptionsCtrl::setDateTimeNone(HANDLE hDateTime)
{
	SendMessage(m_hOptWnd, OCM_SETDATETIMENONE, reinterpret_cast<LPARAM>(hDateTime), 0);
}

DWORD OptionsCtrl::getDateTime(HANDLE hDateTime, bool* pbNone /* = NULL */)
{
	BOOL bMyNone = FALSE;
	DWORD dwResult = SendMessage(m_hOptWnd, OCM_GETDATETIME, reinterpret_cast<WPARAM>(hDateTime), reinterpret_cast<LPARAM>(&bMyNone));

	if (pbNone)
	{
		*pbNone = bool_(bMyNone);
	}

	return dwResult;
}

void OptionsCtrl::setDateTime(HANDLE hDateTime, DWORD dwDateTime)
{
	SendMessage(m_hOptWnd, OCM_SETDATETIME, reinterpret_cast<WPARAM>(hDateTime), dwDateTime);
}


ext::string OptionsCtrl::getDateTimeStr(HANDLE hDateTime)
{
	bool bNone = false;
	DWORD dwTimestamp = getDateTime(hDateTime, &bNone);

	return bNone ? muT("") : utils::formatDate(dwTimestamp);
}

void OptionsCtrl::setDateTimeStr(HANDLE hDateTime, const ext::string& strDateTime)
{
	if (strDateTime.empty())
	{
		setDateTimeNone(hDateTime);
	}
	else
	{
		setDateTime(hDateTime, utils::parseDate(strDateTime));
	}
}

COLORREF OptionsCtrl::getColor(HANDLE hColor)
{
	return SendMessage(m_hOptWnd, OCM_GETITEMCOLOR, reinterpret_cast<WPARAM>(hColor), 0);
}

void OptionsCtrl::setColor(HANDLE hColor, COLORREF crColor)
{
	SendMessage(m_hOptWnd, OCM_SETITEMCOLOR, reinterpret_cast<WPARAM>(hColor), crColor);
}