forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGadgetCheckBox.cpp
More file actions
376 lines (291 loc) · 10.3 KB
/
GadgetCheckBox.cpp
File metadata and controls
376 lines (291 loc) · 10.3 KB
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: CheckBox.cpp /////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Westwood Studios Pacific.
//
// Confidential Information
// Copyright (C) 2001 - All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Project: RTS3
//
// File name: CheckBox.cpp
//
// Created: Colin Day, June 2001
//
// Desc: Checkbox GUI control
//
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
// USER INCLUDES //////////////////////////////////////////////////////////////
#include "Common/Language.h"
#include "GameClient/Gadget.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/Keyboard.h"
// DEFINES ////////////////////////////////////////////////////////////////////
// PRIVATE TYPES //////////////////////////////////////////////////////////////
// PRIVATE DATA ///////////////////////////////////////////////////////////////
// PUBLIC DATA ////////////////////////////////////////////////////////////////
// PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// GadgetCheckBoxInput ========================================================
/** Handle input for check box */
//=============================================================================
WindowMsgHandledType GadgetCheckBoxInput( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
WinInstanceData *instData = window->winGetInstanceData();
switch( msg )
{
// ------------------------------------------------------------------------
case GWM_MOUSE_ENTERING:
{
if( BitIsSet( instData->getStyle(), GWS_MOUSE_TRACK ) )
{
BitSet( instData->m_state, WIN_STATE_HILITED );
TheWindowManager->winSendSystemMsg( window->winGetOwner(),
GBM_MOUSE_ENTERING,
(WindowMsgData)window,
mData1 );
//TheWindowManager->winSetFocus( window );
}
break;
}
// ------------------------------------------------------------------------
case GWM_MOUSE_LEAVING:
{
if( BitIsSet( instData->getStyle(), GWS_MOUSE_TRACK ) )
{
BitClear( instData->m_state, WIN_STATE_HILITED );
TheWindowManager->winSendSystemMsg( window->winGetOwner(),
GBM_MOUSE_LEAVING,
(WindowMsgData)window,
mData1 );
}
break;
}
// ------------------------------------------------------------------------
case GWM_LEFT_DRAG:
{
TheWindowManager->winSendSystemMsg( window->winGetOwner(), GGM_LEFT_DRAG,
(WindowMsgData)window, mData1 );
break;
}
// ------------------------------------------------------------------------
case GWM_LEFT_DOWN:
{
break;
}
// ------------------------------------------------------------------------
case GWM_LEFT_UP:
{
if( BitIsSet( instData->getState(), WIN_STATE_HILITED ) == FALSE )
{
// this up click was not meant for this button
return MSG_IGNORED;
}
// Toggle the check state
instData->m_state ^= WIN_STATE_SELECTED;
TheWindowManager->winSendSystemMsg( window->winGetOwner(), GBM_SELECTED,
(WindowMsgData)window, mData1 );
break;
}
// ------------------------------------------------------------------------
case GWM_RIGHT_DOWN:
{
break;
}
//-------------------------------------------------------------------------
case GWM_RIGHT_UP:
{
// Need to be specially marked to care about right mouse events
if( BitIsSet( instData->getState(), WIN_STATE_SELECTED ) )
{
TheWindowManager->winSendSystemMsg( instData->getOwner(), GBM_SELECTED_RIGHT,
(WindowMsgData)window, mData1 );
BitClear( instData->m_state, WIN_STATE_SELECTED );
}
else
{
// this up click was not meant for this button
return MSG_IGNORED;
}
break;
}
// ------------------------------------------------------------------------
case GWM_CHAR:
{
switch( mData1 )
{
// --------------------------------------------------------------------
case KEY_ENTER:
case KEY_SPACE:
{
if( BitIsSet( mData2, KEY_STATE_DOWN ) )
{
// Toggle the check state
instData->m_state ^= WIN_STATE_SELECTED;
TheWindowManager->winSendSystemMsg( window->winGetOwner(),
GBM_SELECTED,
(WindowMsgData)window,
0 );
}
break;
}
// --------------------------------------------------------------------
case KEY_DOWN:
case KEY_RIGHT:
case KEY_TAB:
{
if( BitIsSet( mData2, KEY_STATE_DOWN ) )
TheWindowManager->winNextTab(window);
break;
}
// --------------------------------------------------------------------
case KEY_UP:
case KEY_LEFT:
{
if( BitIsSet( mData2, KEY_STATE_DOWN ) )
TheWindowManager->winPrevTab(window);
break;
}
// --------------------------------------------------------------------
default:
{
return MSG_IGNORED;
}
}
break;
}
// ------------------------------------------------------------------------
default:
{
return MSG_IGNORED;
}
}
return MSG_HANDLED;
}
// GadgetCheckBoxSystem =======================================================
/** Handle system messages for check box */
//=============================================================================
WindowMsgHandledType GadgetCheckBoxSystem( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
WinInstanceData *instData = window->winGetInstanceData();
switch( msg )
{
// ------------------------------------------------------------------------
case GGM_SET_LABEL:
{
window->winSetText( *(UnicodeString*)mData1 );
break;
}
// ------------------------------------------------------------------------
case GWM_CREATE:
break;
// ------------------------------------------------------------------------
case GWM_DESTROY:
break;
// ------------------------------------------------------------------------
case GWM_INPUT_FOCUS:
if( mData1 == FALSE )
BitClear( instData->m_state, WIN_STATE_HILITED );
else
BitSet( instData->m_state, WIN_STATE_HILITED );
TheWindowManager->winSendSystemMsg( window->winGetOwner(),
GGM_FOCUS_CHANGE,
mData1,
window->winGetWindowId() );
if( mData1 == FALSE )
*(Bool*)mData2 = FALSE;
else
*(Bool*)mData2 = TRUE;
break;
default:
return MSG_IGNORED;
}
return MSG_HANDLED;
}
// GadgetCheckBoxSetText ======================================================
/** Set the text for the control */
//=============================================================================
void GadgetCheckBoxSetText( GameWindow *g, UnicodeString text )
{
// sanity
if( g == nullptr )
return;
TheWindowManager->winSendSystemMsg( g, GGM_SET_LABEL, (WindowMsgData)&text, 0 );
}
// GadgetCheckBoxSetChecked ============================================
//=============================================================================
/** Set the check state for the check box */
//=============================================================================
void GadgetCheckBoxSetChecked( GameWindow *g, Bool isChecked)
{
WinInstanceData *instData = g->winGetInstanceData();
if (isChecked)
{
BitSet(instData->m_state, WIN_STATE_SELECTED);
}
else
{
BitClear(instData->m_state, WIN_STATE_SELECTED);
}
TheWindowManager->winSendSystemMsg( g->winGetOwner(), GBM_SELECTED,
(WindowMsgData)g, 0 );
}
// GadgetCheckBoxToggle ============================================
//=============================================================================
/** Toggle the check state for the check box */
//=============================================================================
void GadgetCheckBoxToggle( GameWindow *g)
{
WinInstanceData *instData = g->winGetInstanceData();
Bool isChecked = BitIsSet(instData->m_state, WIN_STATE_SELECTED);
if (isChecked)
{
BitClear(instData->m_state, WIN_STATE_SELECTED);
}
else
{
BitSet(instData->m_state, WIN_STATE_SELECTED);
}
TheWindowManager->winSendSystemMsg( g->winGetOwner(), GBM_SELECTED,
(WindowMsgData)g, 0 );
}
// GadgetCheckBoxIsChecked ======================================================
/** Check the check state */
//=============================================================================
Bool GadgetCheckBoxIsChecked( GameWindow *g )
{
WinInstanceData *instData = g->winGetInstanceData();
return (BitIsSet(instData->m_state, WIN_STATE_SELECTED));
}