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
|
#include <precomp.h>
#include "checkbox.h"
#include <api/service/svcs/svc_action.h>
#include <api/script/objects/c_script/c_text.h>
#include <api/script/objects/c_script/c_button.h>
#include <api/script/objects/guiobject.h>
#include <api/script/scriptguid.h>
#include <api/script/api_maki.h>
// -----------------------------------------------------------------------
CheckBox::CheckBox(const wchar_t *_text, const wchar_t *_radioid) :
textclicks(NULL), toggleclicks(NULL), text(_text), radioid(_radioid),
buttonGuiObj(NULL), use_radioval(0),
CHECKBOX_PARENT() { }
CheckBox::~CheckBox() {
delete textclicks;
delete toggleclicks;
}
int CheckBox::onInit() {
int r = CHECKBOX_PARENT::onInit();
if (radioid.len()) {
abstract_setContent(L"wasabi.radiobutton.group");
// After we set the content for radio, we should register ourselves
// as a radio button under the radio group we are assigned.
GuiObject *radioGuiObj = abstract_findObject(radioid); // this will actually go down a level
if (radioGuiObj != NULL) {
ifc_window *radioRootWnd = *radioGuiObj; // explicit cast operator :)
// Now, once we have the rootwnd, we can send our radio group object a message, it will turn off other items as we turn on specific ones
if (radioRootWnd != NULL) {
sendAction(radioRootWnd, L"REGISTER", NULL, -1, -1, 0, 0, (void *)getGuiObject(), 4);
}
}
} else {
abstract_setContent(L"wasabi.checkbox.group");
}
return r;
}
void CheckBox::onNewContent() {
// remove all previous hooks because our content changed
delete toggleclicks;
toggleclicks = NULL;
delete textclicks;
textclicks = NULL;
// Capture the clicks on the button
buttonGuiObj = abstract_findObject(L"checkbox.toggle");
if (buttonGuiObj != NULL) {
toggleclicks = new ToggleClicks(*buttonGuiObj, this);
}
// Capture the clicks on the text
GuiObject *textGuiObj = abstract_findObject(L"checkbox.text");
if (textGuiObj != NULL) {
textclicks = new TextClicks(*textGuiObj, this);
}
// Set the text object to display the requested text.
updateText();
}
int CheckBox::getPreferences(int what) {
ifc_window *w = abstract_getContentRootWnd();
if (w != NULL)
return w->getPreferences(what);
return CHECKBOX_PARENT::getPreferences(what);
}
void CheckBox::setActivated(int activated, int writetocfg) {
// this is usually called as a response to onReloadConfig, but could also be called
// directly by a 3rd party, so if we can, we read the current value and do nothing if
// it hasn't changed.
GuiObject *toggleGuiObj = abstract_findObject(L"checkbox.toggle");
if (toggleGuiObj != NULL) {
C_Button buttonObj(*toggleGuiObj);
int act = buttonObj.getActivated();
if (!!act == !!activated) return;
buttonObj.setActivatedNoCallback(!!activated);
}
if (writetocfg) {
if (use_radioval) {
if (activated) {
#ifdef WASABI_COMPILE_CONFIG
getGuiObject()->guiobject_setCfgString(radioval);
#endif
if (radioval != 0) doAction();
}
} else {
#ifdef WASABI_COMPILE_CONFIG
getGuiObject()->guiobject_setCfgInt(activated);
#endif
if (activated) doAction();
}
}
}
// This is called by the click catchers
void CheckBox::toggle(int self_switch) {
if (!buttonGuiObj) return;
int activated = !!isActivated();
if (self_switch) activated = !activated;
/* int no_setactive = self_switch;
if (radioid.len() > 0 && activated) { // but if we're a radiobox, do not toggle if we're already activated
no_setactive = 1;
}
if (self_switch) activated = !!!activated;
*/
if (!(activated && !radioid.isempty()))
activated = !activated;
if (!use_radioval || activated) {
C_Button b(*buttonGuiObj);
b.setActivatedNoCallback(activated);
}
if (activated) {
if (use_radioval) {
#ifdef WASABI_COMPILE_CONFIG
getGuiObject()->guiobject_setCfgString(radioval);
#endif
if (radioval != 0) doAction();
} else {
#ifdef WASABI_COMPILE_CONFIG
getGuiObject()->guiobject_setCfgInt(activated);
#endif
if (activated) doAction();
}
} else
#ifdef WASABI_COMPILE_CONFIG
if (radioid.len() == 0) getGuiObject()->guiobject_setCfgInt(0); // if we're a radioid being turned off, we shouldn't write our value, as we'll prolly be sharing the same cfgattr with other radioboxes, todo: make that optional
#endif
if (radioid.len() > 0 && activated) {
GuiObject *radioGuiObj = abstract_findObject(radioid);
ifc_window *radioRootWnd = *radioGuiObj;
if (radioRootWnd != NULL)
sendAction(radioRootWnd, L"TOGGLE", NULL, -1, -1, 0, 0, (void *)getGuiObject(), 4);
}
onToggle();
}
void CheckBox::onToggle() {
}
void CheckBox::setText(const wchar_t *_text)
{
text = _text;
setName(text);
if (isInited()) {
updateText();
}
}
const wchar_t *CheckBox::getText() {
return text;
}
void CheckBox::setRadioid(const wchar_t *_radioid)
{
radioid = _radioid;
}
void CheckBox::setRadioVal(const wchar_t *val, int _use_radioval)
{
radioval = val;
use_radioval = _use_radioval;
}
#ifdef WASABI_COMPILE_CONFIG
int CheckBox::onReloadConfig()
{
StringW newVal = getGuiObject()->guiobject_getCfgString();
int checkit = use_radioval ? (newVal == radioval) : WTOI(newVal);
setActivated(checkit, 0);
return CHECKBOX_PARENT::onReloadConfig();
}
#endif
void CheckBox::updateText() {
GuiObject *textGuiObj = abstract_findObject(L"checkbox.text");
if (textGuiObj != NULL) {
textGuiObj->guiobject_setXmlParam(L"text", text);
}
}
int CheckBox::isActivated() {
if (!buttonGuiObj) return 0;
C_Button b(*buttonGuiObj);
return b.getActivated();
}
int CheckBox::onChar(unsigned int c) {
switch (c) {
#ifdef _WIN32
case VK_SPACE:
toggle(0);
break;
#else
#warning port me
#endif
default:
return CHECKBOX_PARENT::onChar(c);
}
return 1;
}
void CheckBox::setAction(const wchar_t *str)
{
action = str;
}
void CheckBox::setActionTarget(const wchar_t *target) {
action_target = target;
}
void CheckBox::setActionParam(const wchar_t *param) {
action_param = param;
}
const wchar_t *CheckBox::getActionParam()
{
return action_param;
}
void CheckBox::doAction()
{
if (!action_target.isempty())
{
GuiObject *go = getGuiObject()->guiobject_findObject(action_target);
if (!go) {
ScriptObject *so = WASABI_API_MAKI->maki_findObject(action_target);
if (so != NULL)
go = static_cast<GuiObject *>(so->vcpu_getInterface(guiObjectGuid));
}
if (go) {
ifc_window *w = go->guiobject_getRootWnd();
if (w) {
RECT cr;
getClientRect(&cr);
int _x = cr.left;
int _y = cr.top;
clientToScreen(&_x, &_y);
sendAction(w, action, action_target, _x, _y);
}
}
} else {
svc_action *act = ActionEnum(action).getNext();
if (act) {
act->onAction(action, getActionParam());
SvcEnum::release(act);
}
}
}
|