forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtendedMessageBox.cpp
More file actions
308 lines (253 loc) · 11.8 KB
/
ExtendedMessageBox.cpp
File metadata and controls
308 lines (253 loc) · 11.8 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
/*
** 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: ExtendedMessageBox.cpp ///////////////////////////////////////////////////////////////////
// Author: Matt Campbell, January 2003
// Description: We go quiet in 1 day, gold in 15. Poor time to rewrite message boxes, so
// we get this file instead. Phooey.
///////////////////////////////////////////////////////////////////////////////////////////////////
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////
// USER INCLUDES //////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/GameEngine.h"
#include "Common/NameKeyGenerator.h"
#include "GameClient/WindowLayout.h"
#include "GameClient/Gadget.h"
#include "GameClient/Shell.h"
#include "GameClient/KeyDefs.h"
#include "GameClient/GadgetStaticText.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/ExtendedMessageBox.h"
WindowMsgHandledType ExtendedMessageBoxSystem( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 );
//-------------------------------------------------------------------------------------------------
/** Create an extended Modal Message Box */
//-------------------------------------------------------------------------------------------------
static GameWindow *gogoExMessageBox(Int x, Int y, Int width, Int height, UnsignedShort buttonFlags,
UnicodeString titleString, UnicodeString bodyString, void *userData,
MessageBoxFunc yesCallback,
MessageBoxFunc noCallback,
MessageBoxFunc okCallback,
MessageBoxFunc cancelCallback )
{
// first check to make sure we have some buttons to display
if(buttonFlags == 0 )
{
return nullptr;
}
GameWindow *parent = TheWindowManager->winCreateFromScript( "Menus/MessageBox.wnd" );
TheWindowManager->winSetModal( parent );
TheWindowManager->winSetFocus( nullptr ); // make sure we lose focus from other windows even if we refuse focus ourselves
TheWindowManager->winSetFocus( parent );
// If the user wants the size to be different then the default
float ratioX, ratioY = 1;
if( width > 0 && height > 0 )
{
ICoord2D temp;
//First grab the percent increase/decrease compared to the default size
parent->winGetSize( &temp.x, &temp.y);
ratioX = (float)width / (float)temp.x;
ratioY = (float)height / (float)temp.y;
//Set the window's new size
parent->winSetSize( width, height);
//Resize/reposition all the children windows based off the ratio
GameWindow *child;
for( child = parent->winGetChild(); child; child = child->winGetNext() )
{
child->winGetSize(&temp.x, &temp.y);
temp.x =Int(temp.x * ratioX);
temp.y =Int(temp.y * ratioY);
child->winSetSize(temp.x, temp.y);
child->winGetPosition(&temp.x, &temp.y);
temp.x =Int(temp.x * ratioX);
temp.y =Int(temp.y * ratioY);
child->winSetPosition(temp.x, temp.y);
}
}
// If the user wants to position the message box somewhere other then default
if( x >= 0 && y >= 0)
parent->winSetPosition(x, y);
// Reposition the buttons
Int buttonX[3], buttonY[3];
//In the layout, buttonOk will be in the first button position
NameKeyType buttonOkID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:ButtonOk" );
GameWindow *buttonOk = TheWindowManager->winGetWindowFromId(parent, buttonOkID);
buttonOk->winGetPosition(&buttonX[0], &buttonY[0]);
NameKeyType buttonYesID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:ButtonYes" );
GameWindow *buttonYes = TheWindowManager->winGetWindowFromId(parent, buttonYesID);
//buttonNo in the second position
NameKeyType buttonNoID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:ButtonNo" );
GameWindow *buttonNo = TheWindowManager->winGetWindowFromId(parent, buttonNoID);
buttonNo->winGetPosition(&buttonX[1], &buttonY[1]);
//and buttonCancel in the third
NameKeyType buttonCancelID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:ButtonCancel" );
GameWindow *buttonCancel = TheWindowManager->winGetWindowFromId(parent, buttonCancelID);
buttonCancel->winGetPosition(&buttonX[2], &buttonY[2]);
//we shouldn't have button OK and Yes on the same dialog
if((buttonFlags & (MSG_BOX_OK | MSG_BOX_YES)) == (MSG_BOX_OK | MSG_BOX_YES) )
{
DEBUG_CRASH(("Passed in MSG_BOX_OK and MSG_BOX_YES. Big No No."));
}
//Position the OK button if we have one
if( (buttonFlags & MSG_BOX_OK) == MSG_BOX_OK)
{
buttonOk->winSetPosition(buttonX[0], buttonY[0]);
buttonOk->winHide(FALSE);
}
else if( (buttonFlags & MSG_BOX_YES) == MSG_BOX_YES)
{
//Position the Yes if we have one
buttonYes->winSetPosition(buttonX[0], buttonY[0]);
buttonYes->winHide(FALSE);
}
if((buttonFlags & (MSG_BOX_NO | MSG_BOX_CANCEL)) == (MSG_BOX_NO | MSG_BOX_CANCEL) )
{
//If we have both the No and Cancel button, then the no should go in the middle position
buttonNo->winSetPosition(buttonX[1], buttonY[1]);
buttonCancel->winSetPosition(buttonX[2], buttonY[2]);
buttonNo->winHide(FALSE);
buttonCancel->winHide(FALSE);
}
else if( (buttonFlags & MSG_BOX_NO) == MSG_BOX_NO)
{
//if we just have the no button, then position it in the right most spot
buttonNo->winSetPosition(buttonX[2], buttonY[2]);
buttonNo->winHide(FALSE);
}
else if( (buttonFlags & MSG_BOX_CANCEL) == MSG_BOX_CANCEL)
{
//else if we just have the Cancel button, well, it should always go in the right spot
buttonCancel->winSetPosition(buttonX[2], buttonY[2]);
buttonCancel->winHide(FALSE);
}
// Fill the text into the text boxes
NameKeyType staticTextTitleID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:StaticTextTitle" );
GameWindow *staticTextTitle = TheWindowManager->winGetWindowFromId(parent, staticTextTitleID);
GadgetStaticTextSetText(staticTextTitle,titleString);
NameKeyType staticTextMessageID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:StaticTextMessage" );
GameWindow *staticTextMessage = TheWindowManager->winGetWindowFromId(parent, staticTextMessageID);
GadgetStaticTextSetText(staticTextMessage,bodyString);
// create a structure that will pass the functions to
WindowExMessageBoxData *MsgBoxCallbacks = NEW WindowExMessageBoxData;
MsgBoxCallbacks->cancelCallback = cancelCallback;
MsgBoxCallbacks->noCallback = noCallback;
MsgBoxCallbacks->okCallback = okCallback;
MsgBoxCallbacks->yesCallback = yesCallback;
MsgBoxCallbacks->userData = userData;
//pass the structure to the dialog
parent->winSetUserData( MsgBoxCallbacks );
parent->winSetSystemFunc(ExtendedMessageBoxSystem);
//make sure the dialog is showing and bring it to the top
parent->winHide(FALSE);
parent->winBringToTop();
return parent;
}
GameWindow *ExMessageBoxYesNo (UnicodeString titleString,UnicodeString bodyString, void *userData,
MessageBoxFunc yesCallback, MessageBoxFunc noCallback)
{
return gogoExMessageBox(-1,-1,-1,-1,MSG_BOX_NO | MSG_BOX_YES , titleString, bodyString, userData, yesCallback, noCallback, nullptr, nullptr);
}
GameWindow *ExMessageBoxYesNoCancel (UnicodeString titleString,UnicodeString bodyString, void *userData,
MessageBoxFunc yesCallback, MessageBoxFunc noCallback, MessageBoxFunc cancelCallback)
{
return gogoExMessageBox(-1,-1,-1,-1,MSG_BOX_NO | MSG_BOX_YES | MSG_BOX_CANCEL , titleString, bodyString, userData, yesCallback, noCallback, nullptr, cancelCallback);
}
GameWindow *ExMessageBoxOkCancel (UnicodeString titleString,UnicodeString bodyString, void *userData,
MessageBoxFunc okCallback, MessageBoxFunc cancelCallback)
{
return gogoExMessageBox(-1,-1,-1,-1,MSG_BOX_OK | MSG_BOX_CANCEL , titleString, bodyString, userData, nullptr, nullptr, okCallback, cancelCallback);
}
GameWindow *ExMessageBoxOk (UnicodeString titleString,UnicodeString bodyString, void *userData,
MessageBoxFunc okCallback)
{
return gogoExMessageBox(-1,-1,-1,-1,MSG_BOX_OK, titleString, bodyString, userData, nullptr, nullptr, okCallback, nullptr);
}
GameWindow *ExMessageBoxCancel (UnicodeString titleString,UnicodeString bodyString, void *userData,
MessageBoxFunc cancelCallback)
{
return gogoExMessageBox(-1,-1,-1,-1, MSG_BOX_CANCEL, titleString, bodyString, userData, nullptr, nullptr, nullptr, cancelCallback);
}
// PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
/** Message Box window system callback */
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType ExtendedMessageBoxSystem( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
switch( msg )
{
//---------------------------------------------------------------------------------------------
case GWM_DESTROY:
{
delete (WindowExMessageBoxData *)window->winGetUserData();
window->winSetUserData( nullptr );
break;
}
// --------------------------------------------------------------------------------------------
case GWM_INPUT_FOCUS:
{
// if we're givin the opportunity to take the keyboard focus we must say we want it
if( mData1 == TRUE )
*(Bool *)mData2 = TRUE;
break;
}
//---------------------------------------------------------------------------------------------
case GBM_SELECTED:
{
GameWindow *control = (GameWindow *)mData1;
Int controlID = control->winGetWindowId();
static NameKeyType buttonOkID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:ButtonOk" );
static NameKeyType buttonYesID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:ButtonYes" );
static NameKeyType buttonNoID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:ButtonNo" );
static NameKeyType buttonCancelID = TheNameKeyGenerator->nameToKey( "MessageBox.wnd:ButtonCancel" );
WindowExMessageBoxData *MsgBoxCallbacks = (WindowExMessageBoxData *)window->winGetUserData();
MessageBoxReturnType ret = MB_RETURN_CLOSE;
if( controlID == buttonOkID )
{
if (MsgBoxCallbacks->okCallback)
ret = MsgBoxCallbacks->okCallback(MsgBoxCallbacks->userData);
}
else if( controlID == buttonYesID )
{
if (MsgBoxCallbacks->yesCallback)
ret = MsgBoxCallbacks->yesCallback(MsgBoxCallbacks->userData);
}
else if( controlID == buttonNoID )
{
if (MsgBoxCallbacks->noCallback)
ret = MsgBoxCallbacks->noCallback(MsgBoxCallbacks->userData);
}
else if( controlID == buttonCancelID )
{
if (MsgBoxCallbacks->cancelCallback)
ret = MsgBoxCallbacks->cancelCallback(MsgBoxCallbacks->userData);
}
if (ret == MB_RETURN_CLOSE)
TheWindowManager->winDestroy(window);
break;
}
//---------------------------------------------------------------------------------------------
default:
return MSG_IGNORED;
}
return MSG_HANDLED;
}