MessageBox.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: MessageBox.cpp /////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: MessageBox.cpp
  36. //
  37. // Created: Chris Huybregts, June 2001
  38. //
  39. // Desc: the Message Box control
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. // USER INCLUDES //////////////////////////////////////////////////////////////
  45. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  46. #include "Common/GameEngine.h"
  47. #include "Common/NameKeyGenerator.h"
  48. #include "GameClient/WindowLayout.h"
  49. #include "GameClient/Gadget.h"
  50. #include "GameClient/Shell.h"
  51. #include "GameClient/KeyDefs.h"
  52. #include "GameClient/GameWindowManager.h"
  53. #include "GameClient/MessageBox.h"
  54. GameWindow *MessageBoxYesNo(UnicodeString titleString,UnicodeString bodyString,GameWinMsgBoxFunc yesCallback,GameWinMsgBoxFunc noCallback) ///< convenience function for displaying a Message box with Yes and No buttons
  55. {
  56. return TheWindowManager->gogoMessageBox(-1,-1,-1,-1,MSG_BOX_NO | MSG_BOX_YES , titleString, bodyString, yesCallback, noCallback, NULL, NULL);
  57. }
  58. GameWindow *QuitMessageBoxYesNo(UnicodeString titleString,UnicodeString bodyString,GameWinMsgBoxFunc yesCallback,GameWinMsgBoxFunc noCallback) ///< convenience function for displaying a Message box with Yes and No buttons
  59. {
  60. return TheWindowManager->gogoMessageBox(-1,-1,-1,-1,MSG_BOX_NO | MSG_BOX_YES , titleString, bodyString, yesCallback, noCallback, NULL, NULL, TRUE);
  61. }
  62. GameWindow *MessageBoxYesNoCancel(UnicodeString titleString,UnicodeString bodyString, GameWinMsgBoxFunc yesCallback, GameWinMsgBoxFunc noCallback, GameWinMsgBoxFunc cancelCallback)///< convenience function for displaying a Message box with Yes,No and Cancel buttons
  63. {
  64. return TheWindowManager->gogoMessageBox(-1,-1,-1,-1,MSG_BOX_NO | MSG_BOX_YES | MSG_BOX_CANCEL , titleString, bodyString, yesCallback, noCallback, NULL, cancelCallback);
  65. }
  66. GameWindow *MessageBoxOkCancel(UnicodeString titleString,UnicodeString bodyString,GameWinMsgBoxFunc okCallback,GameWinMsgBoxFunc cancelCallback)///< convenience function for displaying a Message box with Ok and Cancel buttons
  67. {
  68. return TheWindowManager->gogoMessageBox(-1,-1,-1,-1,MSG_BOX_OK | MSG_BOX_CANCEL , titleString, bodyString, NULL, NULL, okCallback, cancelCallback);
  69. }
  70. GameWindow *MessageBoxOk(UnicodeString titleString,UnicodeString bodyString,GameWinMsgBoxFunc okCallback)///< convenience function for displaying a Message box with Ok button
  71. {
  72. return TheWindowManager->gogoMessageBox(-1,-1,-1,-1,MSG_BOX_OK, titleString, bodyString, NULL, NULL, okCallback, NULL);
  73. }
  74. GameWindow *MessageBoxCancel(UnicodeString titleString,UnicodeString bodyString,GameWinMsgBoxFunc cancelCallback)///< convenience function for displaying a Message box with Cancel button
  75. {
  76. return TheWindowManager->gogoMessageBox(-1,-1,-1,-1, MSG_BOX_CANCEL, titleString, bodyString, NULL, NULL, NULL, cancelCallback);
  77. }
  78. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  79. //-------------------------------------------------------------------------------------------------
  80. /** Message Box window system callback */
  81. //-------------------------------------------------------------------------------------------------
  82. WindowMsgHandledType MessageBoxSystem( GameWindow *window, UnsignedInt msg,
  83. WindowMsgData mData1, WindowMsgData mData2 )
  84. {
  85. switch( msg )
  86. {
  87. //---------------------------------------------------------------------------------------------
  88. case GWM_DESTROY:
  89. {
  90. delete (WindowMessageBoxData *)window->winGetUserData();
  91. window->winSetUserData( NULL );
  92. break;
  93. } // end case
  94. // --------------------------------------------------------------------------------------------
  95. case GWM_INPUT_FOCUS:
  96. {
  97. // if we're givin the opportunity to take the keyboard focus we must say we want it
  98. if( mData1 == TRUE )
  99. *(Bool *)mData2 = TRUE;
  100. break;
  101. } // end input
  102. //---------------------------------------------------------------------------------------------
  103. case GBM_SELECTED:
  104. {
  105. GameWindow *control = (GameWindow *)mData1;
  106. Int controlID = control->winGetWindowId();
  107. static NameKeyType buttonOkID = TheNameKeyGenerator->nameToKey( AsciiString( "MessageBox.wnd:ButtonOk" ) );
  108. static NameKeyType buttonYesID = TheNameKeyGenerator->nameToKey( AsciiString( "MessageBox.wnd:ButtonYes" ) );
  109. static NameKeyType buttonNoID = TheNameKeyGenerator->nameToKey( AsciiString( "MessageBox.wnd:ButtonNo" ) );
  110. static NameKeyType buttonCancelID = TheNameKeyGenerator->nameToKey( AsciiString( "MessageBox.wnd:ButtonCancel" ) );
  111. WindowMessageBoxData *MsgBoxCallbacks = (WindowMessageBoxData *)window->winGetUserData();
  112. if( controlID == buttonOkID )
  113. {
  114. //simple enough,if we have a callback, call it, if not, then just destroy the window
  115. if (MsgBoxCallbacks->okCallback)
  116. MsgBoxCallbacks->okCallback();
  117. TheWindowManager->winDestroy(window);
  118. } // end if
  119. else if( controlID == buttonYesID )
  120. {
  121. if (MsgBoxCallbacks->yesCallback)
  122. MsgBoxCallbacks->yesCallback();
  123. TheWindowManager->winDestroy(window);
  124. } // end else if
  125. else if( controlID == buttonNoID )
  126. {
  127. if (MsgBoxCallbacks->noCallback)
  128. MsgBoxCallbacks->noCallback();
  129. TheWindowManager->winDestroy(window);
  130. } // end else if
  131. else if( controlID == buttonCancelID )
  132. {
  133. if (MsgBoxCallbacks->cancelCallback)
  134. MsgBoxCallbacks->cancelCallback();
  135. TheWindowManager->winDestroy(window);
  136. } // end else if
  137. break;
  138. } // end selected
  139. //---------------------------------------------------------------------------------------------
  140. default:
  141. return MSG_IGNORED;
  142. } // end switch
  143. return MSG_HANDLED;
  144. } // end MessageBoxSystem
  145. //-------------------------------------------------------------------------------------------------
  146. /** Message Box window system callback */
  147. //-------------------------------------------------------------------------------------------------
  148. WindowMsgHandledType QuitMessageBoxSystem( GameWindow *window, UnsignedInt msg,
  149. WindowMsgData mData1, WindowMsgData mData2 )
  150. {
  151. switch( msg )
  152. {
  153. //---------------------------------------------------------------------------------------------
  154. case GWM_DESTROY:
  155. {
  156. delete (WindowMessageBoxData *)window->winGetUserData();
  157. window->winSetUserData( NULL );
  158. break;
  159. } // end case
  160. // --------------------------------------------------------------------------------------------
  161. case GWM_INPUT_FOCUS:
  162. {
  163. // if we're givin the opportunity to take the keyboard focus we must say we want it
  164. if( mData1 == TRUE )
  165. *(Bool *)mData2 = TRUE;
  166. break;
  167. } // end input
  168. //---------------------------------------------------------------------------------------------
  169. case GBM_SELECTED:
  170. {
  171. GameWindow *control = (GameWindow *)mData1;
  172. Int controlID = control->winGetWindowId();
  173. static NameKeyType buttonOkID = TheNameKeyGenerator->nameToKey( AsciiString( "QuitMessageBox.wnd:ButtonOk" ) );
  174. static NameKeyType buttonYesID = TheNameKeyGenerator->nameToKey( AsciiString( "QuitMessageBox.wnd:ButtonYes" ) );
  175. static NameKeyType buttonNoID = TheNameKeyGenerator->nameToKey( AsciiString( "QuitMessageBox.wnd:ButtonNo" ) );
  176. static NameKeyType buttonCancelID = TheNameKeyGenerator->nameToKey( AsciiString( "QuitMessageBox.wnd:ButtonCancel" ) );
  177. WindowMessageBoxData *MsgBoxCallbacks = (WindowMessageBoxData *)window->winGetUserData();
  178. if( controlID == buttonOkID )
  179. {
  180. //simple enough,if we have a callback, call it, if not, then just destroy the window
  181. if (MsgBoxCallbacks->okCallback)
  182. MsgBoxCallbacks->okCallback();
  183. TheWindowManager->winDestroy(window);
  184. } // end if
  185. else if( controlID == buttonYesID )
  186. {
  187. if (MsgBoxCallbacks->yesCallback)
  188. MsgBoxCallbacks->yesCallback();
  189. TheWindowManager->winDestroy(window);
  190. } // end else if
  191. else if( controlID == buttonNoID )
  192. {
  193. if (MsgBoxCallbacks->noCallback)
  194. MsgBoxCallbacks->noCallback();
  195. TheWindowManager->winDestroy(window);
  196. } // end else if
  197. else if( controlID == buttonCancelID )
  198. {
  199. if (MsgBoxCallbacks->cancelCallback)
  200. MsgBoxCallbacks->cancelCallback();
  201. TheWindowManager->winDestroy(window);
  202. } // end else if
  203. break;
  204. } // end selected
  205. //---------------------------------------------------------------------------------------------
  206. default:
  207. return MSG_IGNORED;
  208. } // end switch
  209. return MSG_HANDLED;
  210. } // end MessageBoxSystem