forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathGameWindowManagerScript.cpp
More file actions
2885 lines (2286 loc) · 80.7 KB
/
Copy pathGameWindowManagerScript.cpp
File metadata and controls
2885 lines (2286 loc) · 80.7 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** 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: GameWindowManagerScript.cpp //////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Westwood Studios Pacific.
//
// Confidential Information
// Copyright (C) 2001 - All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Project: RTS3
//
// File name: GameWindowManagerScript.cpp
//
// Created: Colin Day, June 2001
// Dean Iverson, May 1998
//
// Desc: Reading window definition files from disk for the window manager
//
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
// USER INCLUDES //////////////////////////////////////////////////////////////
#include "Lib/BaseType.h"
#include "Common/Debug.h"
#include "Common/file.h"
#include "Common/FileSystem.h"
#include "Common/GameMemory.h"
#include "Common/NameKeyGenerator.h"
#include "Common/FunctionLexicon.h"
#include "GameClient/Display.h"
#include "GameClient/WindowLayout.h"
#include "GameClient/Gadget.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GameWindowGlobal.h"
#include "GameClient/GadgetStaticText.h"
#include "GameClient/GadgetTabControl.h"
#include "GameClient/GadgetTextEntry.h"
#include "GameClient/GadgetPushButton.h"
#include "GameClient/GadgetRadioButton.h"
#include "GameClient/GadgetCheckBox.h"
#include "GameClient/GadgetListBox.h"
#include "GameClient/GadgetComboBox.h"
#include "GameClient/GadgetSlider.h"
#include "GameClient/GameText.h"
#include "GameClient/HeaderTemplate.h"
// DEFINES ////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// PRIVATE TYPES //////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
enum
{
WIN_BUFFER_LENGTH = 2048,
WIN_STACK_DEPTH = 10,
};
//-------------------------------------------------------------------------------------------------
/** Layout parse structure ... these data items apply to the window file itself,
* they are not associated with any window, but rather just a block of data in
* every file */
//-------------------------------------------------------------------------------------------------
struct LayoutScriptParse
{
const char *name;
Bool (*parse)( const char *token, char *buffer, UnsignedInt version, WindowLayoutInfo *info );
};
// GameWindowParse ------------------------------------------------------------
/** used to match database fields to parsing functions */
//-----------------------------------------------------------------------------
struct GameWindowParse
{
const char *name;
Bool (*parse)( const char *token, WinInstanceData *, char *, void * );
};
///////////////////////////////////////////////////////////////////////////////
// PRIVATE DATA ///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// window methods and their string representations
static GameWinSystemFunc systemFunc = nullptr;
static GameWinInputFunc inputFunc = nullptr;
static GameWinTooltipFunc tooltipFunc = nullptr;
static GameWinDrawFunc drawFunc = nullptr;
static AsciiString theSystemString;
static AsciiString theInputString;
static AsciiString theTooltipString;
static AsciiString theDrawString;
// default visual properties
static Color defEnabledColor = 0;
static Color defDisabledColor = 0;
static Color defBackgroundColor = 0;
static Color defHiliteColor = 0;
static Color defSelectedColor = 0;
static Color defTextColor = 0;
static GameFont *defFont = nullptr;
//
// These strings must be in the same order as they are in their definitions
// (see WIN_STATUS_* enums and GWS_* enums).
//
const char *const WindowStatusNames[] = { "ACTIVE", "TOGGLE", "DRAGABLE", "ENABLED", "HIDDEN",
"ABOVE", "BELOW", "IMAGE", "TABSTOP", "NOINPUT",
"NOFOCUS", "DESTROYED", "BORDER",
"SMOOTH_TEXT", "ONE_LINE", "NO_FLUSH", "SEE_THRU",
"RIGHT_CLICK", "WRAP_CENTERED", "CHECK_LIKE","HOTKEY_TEXT",
"USE_OVERLAY_STATES", "NOT_READY", "FLASHING", "ALWAYS_COLOR",
"ON_MOUSE_DOWN", /*"SHORTCUT_BUTTON",*/
nullptr };
const char *const WindowStyleNames[] = { "PUSHBUTTON", "RADIOBUTTON", "CHECKBOX",
"VERTSLIDER", "HORZSLIDER", "SCROLLLISTBOX",
"ENTRYFIELD", "STATICTEXT", "PROGRESSBAR",
"USER", "MOUSETRACK", "ANIMATED",
"TABSTOP", "TABCONTROL", "TABPANE",
"COMBOBOX",
nullptr };
// Implement a stack to keep track of parent/child nested window descriptions.
static GameWindow *windowStack[ WIN_STACK_DEPTH ];
static GameWindow **stackPtr;
// for parsing
static const char *seps = " =;\n\r\t";
WinDrawData enabledDropDownButtonDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData disabledDropDownButtonDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData hiliteDropDownButtonDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData enabledEditBoxDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData disabledEditBoxDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData hiliteEditBoxDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData enabledListBoxDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData disabledListBoxDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData hiliteListBoxDrawData[ MAX_DRAW_DATA ]; ///< for combo boxes
WinDrawData enabledUpButtonDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData disabledUpButtonDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData hiliteUpButtonDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData enabledDownButtonDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData disabledDownButtonDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData hiliteDownButtonDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData enabledSliderDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData disabledSliderDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData hiliteSliderDrawData[ MAX_DRAW_DATA ]; ///< for list boxes and combo boxes
WinDrawData enabledSliderThumbDrawData[ MAX_DRAW_DATA ]; ///< for sliders and list boxes and combo boxes
WinDrawData disabledSliderThumbDrawData[ MAX_DRAW_DATA ]; ///< for sliders and list boxes and combo boxes
WinDrawData hiliteSliderThumbDrawData[ MAX_DRAW_DATA ]; ///< for sliders and list boxes and combo boxes
// PUBLIC DATA ////////////////////////////////////////////////////////////////
// PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
static GameWindow *parseWindow( File *inFile, char *buffer );
///////////////////////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// parseBitFlag ===============================================================
/** Parse one of the "flags" referred to below in the header comment
* for ParseBitString(). Sets the appropriate bit in the 'bits' arg,
* if successful. Returns TRUE on success, else FALSE. */
//=============================================================================
static Bool parseBitFlag( const char *flagString, UnsignedInt *bits,
ConstCharPtrArray flagList )
{
ConstCharPtrArray c;
int i;
for( i = 0, c = flagList; *c; i++, c++ )
{
if( stricmp( *c, flagString ) == 0 )
{
*bits |= (1 << i);
return TRUE;
}
}
return FALSE;
}
// parseBitString =============================================================
/** Given a character string of the form 'A+B+C+D', parse the
* flags separated by the '+' symbols into a bitfield stored in the 'bits'
* argument.
* Note that this routine does not clear any bits, only sets them. */
//=============================================================================
static void parseBitString( const char *inBuffer, UnsignedInt *bits, ConstCharPtrArray flagList )
{
char buffer[256];
char *tok;
// do not modify the inBuffer argument
strlcpy(buffer, inBuffer, ARRAY_SIZE(buffer));
if( strncmp( buffer, "NULL", 4 ) != 0 )
{
for( tok = strtok( buffer, "+" ); tok; tok = strtok( nullptr, "+" ) )
{
if ( !parseBitFlag( tok, bits, flagList ) )
{
DEBUG_LOG(( "ParseBitString: Invalid flag '%s'.", tok ));
}
}
}
}
// readUntilSemicolon =========================================================
//=============================================================================
static void readUntilSemicolon( File *fp, char *buffer, int maxBufLen )
{
int i = 0;
Bool start = TRUE;
while( i < maxBufLen )
{
// get next character
fp->read(buffer + i, 1);
// make all whitespace characters spaces
if( isspace( buffer[ i ] ) )
{
if( start == FALSE )
buffer[ i++ ] = ' ';
}
else
{
start = FALSE;
if( buffer[ i ] == ';' )
{
// found end of data chunk
buffer[ i ] = '\000';
return;
}
i++;
}
}
DEBUG_LOG(( "ReadUntilSemicolon: ERROR - Read buffer overflow - input truncated." ));
buffer[ maxBufLen - 1 ] = '\000';
}
// scanBool ===================================================================
//=============================================================================
static Int scanBool( const char *source, Bool& val )
{
Int temp = 0;
Int ret = sscanf( source, "%d", &temp );
val = (Bool)temp;
return ret;
}
// scanShort ==================================================================
//=============================================================================
static Int scanShort( const char *source, Short& val )
{
Int temp = 0;
Int ret = sscanf( source, "%d", &temp );
val = (Short)temp;
return ret;
}
// scanInt ====================================================================
//=============================================================================
static Int scanInt( const char *source, Int& val )
{
Int ret = sscanf( source, "%d", &val ); // not strictly necessary to wrap this, but it's more consistent
return ret;
}
// scanUnsignedInt ============================================================
//=============================================================================
static Int scanUnsignedInt( const char *source, UnsignedInt& val )
{
Int ret = sscanf( source, "%d", &val ); // not strictly necessary to wrap this, but it's more consistent
return ret;
}
// resetWindowStack ===========================================================
//=============================================================================
static void resetWindowStack()
{
memset( windowStack, 0, sizeof( windowStack ) );
stackPtr = windowStack;
}
// resetWindowDefaults ========================================================
//=============================================================================
static void resetWindowDefaults()
{
defEnabledColor = 0;
defDisabledColor = 0;
defBackgroundColor = 0;
defHiliteColor = 0;
defSelectedColor = 0;
defTextColor = 0;
defFont = nullptr;
}
// peekWindow =================================================================
//=============================================================================
static GameWindow *peekWindow()
{
if (stackPtr == windowStack)
return nullptr;
return *(stackPtr - 1);
}
// popWindow ==================================================================
//=============================================================================
static GameWindow *popWindow()
{
if( stackPtr == windowStack )
return nullptr;
stackPtr--;
return *stackPtr;
}
// pushWindow =================================================================
//=============================================================================
static void pushWindow( GameWindow *window )
{
if( stackPtr == &windowStack[ WIN_STACK_DEPTH - 1 ] )
{
DEBUG_LOG(( "pushWindow: Warning, stack overflow" ));
return;
}
*stackPtr++ = window;
}
// parseColor =================================================================
/** Parse a color entry and store it in the value pointed to by the
* 'color' parm. */
//=============================================================================
static Bool parseColor( Color *color, char *buffer )
{
char *c;
Byte red, green, blue;
c = strtok( buffer, " \t\n\r" );
red = atoi(c);
c = strtok( nullptr, " \t\n\r" );
green = atoi(c);
c = strtok( nullptr, " \t\n\r" );
blue = atoi(c);
*color = TheWindowManager->winMakeColor( red, green, blue, 255 );
return TRUE;
}
// parseDefaultColor ==========================================================
/** Parse a default color entry and store it in the value pointed to by
* the 'color' parm. */
//=============================================================================
static Bool parseDefaultColor( Color *color, File *inFile, char *buffer )
{
// eat '='
// fscanf( inFile, "%*s" );
AsciiString str;
inFile->scanString(str);
// Read the rest of the color definition
readUntilSemicolon( inFile, buffer, WIN_BUFFER_LENGTH );
if (strcmp( buffer, "TRANSPARENT" ) == 0)
{
*color = WIN_COLOR_UNDEFINED;
}
else
parseColor( color, buffer );
return TRUE;
}
// parseDefaultFont ===========================================================
/** Parse the default font */
//=============================================================================
static Bool parseDefaultFont( GameFont *font, File *inFile, char *buffer )
{
// eat '='
// fscanf( inFile, "%*s" );
AsciiString str;
inFile->scanString(str);
// Read the rest of the color definition
readUntilSemicolon( inFile, buffer, WIN_BUFFER_LENGTH );
/// @todo font parsing for window files work needed here
// *font = GetFont( buffer );
// if( *font == nullptr )
// return FALSE;
return TRUE;
}
// parseTooltip ===============================================================
/** Parse the tooltip field */
//=============================================================================
static Bool parseTooltip( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
UnicodeString tooltip;
tooltip.set(L"Need tooltip translation");
/// @todo need to parse the tooltip in multibyte here
instData->setTooltipText( tooltip );
return TRUE;
}
// parseScreenRect ============================================================
/** Parse the screen rect entry which tells us the position and size
* of window. Note we scale for the current resolution if needed
* and adjust to make the screen rect coords relative to any parent
* if present */
//=============================================================================
static Bool parseScreenRect( const char *token, char *buffer,
Int *x, Int *y, Int *width, Int *height )
{
GameWindow *parent = peekWindow();
IRegion2D screenRegion;
ICoord2D createRes; // creation resolution
const char *seps = " ,:=\n\r\t";
char *c;
c = strtok( nullptr, seps ); // UPPERLEFT token
c = strtok( nullptr, seps ); // x position
scanInt( c, screenRegion.lo.x );
c = strtok( nullptr, seps ); // y posotion
scanInt( c, screenRegion.lo.y );
c = strtok( nullptr, seps ); // BOTTOMRIGHT token
c = strtok( nullptr, seps ); // x position
scanInt( c, screenRegion.hi.x );
c = strtok( nullptr, seps ); // y posotion
scanInt( c, screenRegion.hi.y );
c = strtok( nullptr, seps ); // CREATIONRESOLUTION token
c = strtok( nullptr, seps ); // x creation resolution
scanInt( c, createRes.x );
c = strtok( nullptr, seps ); // y creation resolution
scanInt( c, createRes.y );
//
// shrink or expand the screen region by the ratio of the current
// resolution divided by the creation resolution
//
Real xScale = (Real)TheDisplay->getWidth() / (Real)createRes.x;
Real yScale = (Real)TheDisplay->getHeight() / (Real)createRes.y;
screenRegion.lo.x = (Int)((Real)screenRegion.lo.x * xScale);
screenRegion.lo.y = (Int)((Real)screenRegion.lo.y * yScale);
screenRegion.hi.x = (Int)((Real)screenRegion.hi.x * xScale);
screenRegion.hi.y = (Int)((Real)screenRegion.hi.y * yScale);
//
// given the screen region upper left compute the upper left that we
// will give this window, if we have a parent note that the position
// is relative to the parent client area, if no parent is present
// we're talking about the screen
//
if( parent )
{
ICoord2D parentScreenPos;
// get parent position on screen
parent->winGetScreenPosition( &parentScreenPos.x, &parentScreenPos.y );
// save x and y with parent position as relative (0,0) location
*x = screenRegion.lo.x - parentScreenPos.x;
*y = screenRegion.lo.y - parentScreenPos.y;
}
else
{
*x = screenRegion.lo.x;
*y = screenRegion.lo.y;
}
// save our width and height from the adjusted screen region locations
*width = screenRegion.hi.x - screenRegion.lo.x;
*height = screenRegion.hi.y - screenRegion.lo.y;
return TRUE;
}
// parseImageOffset ===========================================================
/** Parse the image draw offset */
//=============================================================================
static Bool parseImageOffset( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *c;
c = strtok( buffer, " \t\n\r" );
instData->m_imageOffset.x = atoi( c );
c = strtok( nullptr, " \t\n\r" );
instData->m_imageOffset.y = atoi( c );
return TRUE;
}
// parseFont ==================================================================
/** Parse the font field */
//=============================================================================
static Bool parseFont( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *c, *ptr;
const char *seps = " ,\n\r\t";
const char *stringSeps = ":,\n\r\t\"";
char fontName[ 256 ];
Int fontSize;
Int fontBold;
// "NAME"
c = strtok( buffer, seps ); // label
// scan to the first " mark
ptr = buffer;
while( *ptr != '"' )
ptr++;
ptr++; // skip the "
c = strtok( ptr, stringSeps ); // value
strlcpy(fontName, c, ARRAY_SIZE(fontName));
// "SIZE"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanInt( c, fontSize );
// "BOLD"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanInt( c, fontBold );
if( TheFontLibrary )
{
GameFont *font = TheFontLibrary->getFont( AsciiString(fontName), fontSize, fontBold );
if( font )
instData->m_font = font;
}
return TRUE;
}
// parseName =================================================================
/** Parse the NAME field */
//=============================================================================
static Bool parseName( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *c, *ptr;
// const char *seps = " ,\n\r\t";
const char *stringSeps = "\"";
// scan to the first " mark
ptr = buffer;
while( *ptr != '"' )
ptr++;
ptr++; // skip the first "
c = strtok( ptr, stringSeps ); // name value
instData->m_decoratedNameString = c;
// given the name assign a window ID from the
assert( TheNameKeyGenerator );
if( TheNameKeyGenerator )
instData->m_id = (Int)TheNameKeyGenerator->nameToKey( instData->m_decoratedNameString );
return TRUE;
}
// parseStatus ================================================================
/** Parse the STATUS field */
//=============================================================================
static Bool parseStatus( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
instData->m_status = 0;
parseBitString( buffer, &instData->m_status, WindowStatusNames );
return TRUE;
}
// parseStyle =================================================================
/** Parse the STYLE field */
//=============================================================================
static Bool parseStyle( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
instData->m_style = 0;
parseBitString( buffer, &instData->m_style, WindowStyleNames );
return TRUE;
}
// parseSystemCallback ========================================================
/** Parse the system method callback for a window */
//=============================================================================
static Bool parseSystemCallback( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *c, *ptr;
// const char *seps = " ,\n\r\t";
const char *stringSeps = "\"";
// scan to the first " mark
ptr = buffer;
while( *ptr != '"' )
ptr++;
ptr++; // skip the first "
c = strtok( ptr, stringSeps ); // name value
// save a pointer of the function address
DEBUG_ASSERTCRASH( TheNameKeyGenerator && TheFunctionLexicon, ("Invalid singletons") );
theSystemString = c;
NameKeyType key = TheNameKeyGenerator->nameToKey( theSystemString );
systemFunc = TheFunctionLexicon->gameWinSystemFunc( key );
return TRUE;
}
// parseInputCallback =========================================================
/** Parse the Input method callback for a window */
//=============================================================================
static Bool parseInputCallback( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *c, *ptr;
// const char *seps = " ,\n\r\t";
const char *stringSeps = "\"";
// scan to the first " mark
ptr = buffer;
while( *ptr != '"' )
ptr++;
ptr++; // skip the first "
c = strtok( ptr, stringSeps ); // name value
// save a pointer of the function address
DEBUG_ASSERTCRASH( TheNameKeyGenerator && TheFunctionLexicon, ("Invalid singletons") );
theInputString = c;
NameKeyType key = TheNameKeyGenerator->nameToKey( theInputString );
inputFunc = TheFunctionLexicon->gameWinInputFunc( key );
return TRUE;
}
// parseTooltipCallback =======================================================
/** Parse the Tooltip method callback for a window */
//=============================================================================
static Bool parseTooltipCallback( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *c, *ptr;
// const char *seps = " ,\n\r\t";
const char *stringSeps = "\"";
// scan to the first " mark
ptr = buffer;
while( *ptr != '"' )
ptr++;
ptr++; // skip the first "
c = strtok( ptr, stringSeps ); // name value
// save a pointer of the function address
DEBUG_ASSERTCRASH( TheNameKeyGenerator && TheFunctionLexicon, ("Invalid singletons") );
theTooltipString = c;
NameKeyType key = TheNameKeyGenerator->nameToKey( theTooltipString );
tooltipFunc = TheFunctionLexicon->gameWinTooltipFunc( key );
return TRUE;
}
// parseDrawCallback ==========================================================
/** Parse the Draw method callback for a window */
//=============================================================================
static Bool parseDrawCallback( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *c, *ptr;
// const char *seps = " ,\n\r\t";
const char *stringSeps = "\"";
// scan to the first " mark
ptr = buffer;
while( *ptr != '"' )
ptr++;
ptr++; // skip the first "
c = strtok( ptr, stringSeps ); // name value
// save a pointer of the function address
DEBUG_ASSERTCRASH( TheNameKeyGenerator && TheFunctionLexicon, ("Invalid singletons") );
theDrawString = c;
NameKeyType key = TheNameKeyGenerator->nameToKey( theDrawString );
drawFunc = TheFunctionLexicon->gameWinDrawFunc( key );
return TRUE;
}
// parseHeaderTemplate ==========================================================
/** Parse the Draw method callback for a window */
//=============================================================================
static Bool parseHeaderTemplate( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *c, *ptr;
// const char *seps = " ,\n\r\t";
const char *stringSeps = "\"";
// scan to the first " mark
ptr = buffer;
while( *ptr != '"' )
ptr++;
ptr++; // skip the first "
c = strtok( ptr, stringSeps ); // name value
// save a pointer of the function address
DEBUG_ASSERTCRASH( TheNameKeyGenerator && TheFunctionLexicon, ("Invalid singletons") );
instData->m_headerTemplateName = c;
return TRUE;
}
// parseListboxData ===========================================================
/** Parse listbox data entry */
//=============================================================================
static Bool parseListboxData( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
ListboxData *listData = (ListboxData *)data;
char *c;
const char *seps = " :,\n\r\t";
// "LENGTH"
c = strtok( buffer, seps ); // label
c = strtok( nullptr, seps );
scanShort( c, listData->listLength );
// "AUTOSCROLL"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanBool( c, listData->autoScroll );
// "SCROLLIFATEND" (optional)
c = strtok( nullptr, seps ); // label
if ( stricmp(c, "ScrollIfAtEnd") == 0 )
{
c = strtok( nullptr, seps ); // value
scanBool( c, listData->scrollIfAtEnd );
c = strtok( nullptr, seps ); // label
}
else
{
listData->scrollIfAtEnd = FALSE;
}
// "AUTOPURGE"
c = strtok( nullptr, seps ); // value
scanBool( c, listData->autoPurge );
// "SCROLLBAR"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanBool( c, listData->scrollBar );
// "MULTISELECT"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanBool( c, listData->multiSelect );
// "COLUMNS"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanShort( c, listData->columns );
if(listData->columns > 1)
{
listData->columnWidthPercentage = NEW Int[listData->columns];
for(Int i = 0; i < listData->columns; i++ )
{
// "COLUMNS"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanInt( c, listData->columnWidthPercentage[i] );
}
}
else
listData->columnWidthPercentage = nullptr;
listData->columnWidth = nullptr;
// "FORCESELECT"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanBool( c, listData->forceSelect );
// "
return TRUE;
}
// parseComboBoxData ===========================================================
/** Parse Combo Box data entry */
//=============================================================================
static Bool parseComboBoxData( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
ComboBoxData *comboData = (ComboBoxData *)data;
char *c;
const char *seps = " :,\n\r\t";
c = strtok( buffer, seps ); // label
c = strtok( nullptr, seps ); // value
scanBool( c, comboData->isEditable );
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanInt( c, comboData->maxChars );
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanInt( c, comboData->maxDisplay );
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanBool( c, comboData->asciiOnly );
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanBool( c, comboData->lettersAndNumbersOnly );
return TRUE;
}
// parseSliderData ============================================================
/** Parse slider data entry */
//=============================================================================
static Bool parseSliderData( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
SliderData *sliderData = (SliderData *)data;
char *c;
const char *seps = " :,\n\r\t";
// "MINVALUE"
c = strtok( buffer, seps ); // label
c = strtok( nullptr, seps ); // value
scanInt( c, sliderData->minVal );
// "MAXVALUE"
c = strtok( nullptr, seps ); // label
c = strtok( nullptr, seps ); // value
scanInt( c, sliderData->maxVal );
return TRUE;
}
// parseRadioButtonData =======================================================
/** Parse radio button data entry */
//=============================================================================
static Bool parseRadioButtonData( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
RadioButtonData *radioData = (RadioButtonData *)data;
char *c;
const char *seps = " :,\n\r\t";
// "GROUP"
c = strtok( buffer, seps ); // label
c = strtok( nullptr, seps ); // value
scanInt( c, radioData->group );
return TRUE;
}
// parseTooltipText ===========================================================
/** Parse the TOOLTIPTEXT field */
//=============================================================================
static Bool parseTooltipText( const char *token, WinInstanceData *instData,
char *buffer, void *data )
{
char *ptr = buffer;
char *c;
const char *stringSeps = "\n\r\t\"";
// scan to the first " mark
while( *ptr != '"' )
ptr++;
ptr++; // skip the "
if(strlen( ptr ) == 1 )
return TRUE;
c = strtok( ptr, stringSeps ); // value
if( strlen( c ) >= MAX_TEXT_LABEL )
{
DEBUG_LOG(( "TextTooltip label '%s' is too long, max is '%d'", c, MAX_TEXT_LABEL ));
assert( 0 );
return FALSE;
}
instData->m_tooltipString.set(c);
instData->setTooltipText(TheGameText->fetch(c));