DlgMessageBox.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. ** Command & Conquer Renegade(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. * NAME
  21. * $Archive: /Commando/Code/Commando/DlgMessageBox.cpp $
  22. *
  23. * DESCRIPTION
  24. * Popup message dialog.
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 7 $
  32. * $Modtime: 10/02/01 2:42p $
  33. *
  34. ******************************************************************************/
  35. #include "DlgMessageBox.h"
  36. #include "Resource.h"
  37. #include <WWTranslateDB\TranslateDB.h>
  38. #include "WWDebug.h"
  39. //
  40. // Class statics
  41. //
  42. int DlgMsgBox::CurrentCount = 0;
  43. /******************************************************************************
  44. *
  45. * NAME
  46. * DlgMsgBox::DoDialog
  47. *
  48. * DESCRIPTION
  49. * Create a Popup message box dialog.
  50. *
  51. * INPUTS
  52. * Title - Message box title
  53. * Text - Message content
  54. *
  55. * RESULT
  56. * Object - Instance of message box
  57. *
  58. ******************************************************************************/
  59. bool DlgMsgBox::DoDialog(const WCHAR* title, const WCHAR* text,
  60. DlgMsgBox::Type type, Observer<DlgMsgBoxEvent>* observer, unsigned long user_data)
  61. {
  62. DlgMsgBox* popup = new DlgMsgBox;
  63. if (popup)
  64. {
  65. popup->SetResourceType(type);
  66. popup->Start_Dialog();
  67. popup->Set_Title(title);
  68. popup->Set_Dlg_Item_Text(IDC_MESSAGE, text);
  69. popup->Set_User_Data(user_data);
  70. if (observer)
  71. {
  72. popup->AddObserver(*observer);
  73. }
  74. popup->Release_Ref();
  75. }
  76. return (popup != NULL);
  77. }
  78. /******************************************************************************
  79. *
  80. * NAME
  81. * DlgMsgBox::DoDialog
  82. *
  83. * DESCRIPTION
  84. * Create a Popup message box dialog.
  85. *
  86. * INPUTS
  87. * TitleID - ID of message box title
  88. * TextID - ID of message content
  89. *
  90. * RESULT
  91. * Object - Instance of message box
  92. *
  93. ******************************************************************************/
  94. bool DlgMsgBox::DoDialog(int titleID, int textID,
  95. DlgMsgBox::Type type, Observer<DlgMsgBoxEvent>* observer, unsigned long user_data)
  96. {
  97. const WCHAR* title = TranslateDBClass::Get_String(titleID);
  98. const WCHAR* text = TranslateDBClass::Get_String(textID);
  99. return DoDialog(title, text, type, observer, user_data);
  100. }
  101. /******************************************************************************
  102. *
  103. * NAME
  104. * DlgMsgBox::DlgMsgBox
  105. *
  106. * DESCRIPTION
  107. * Constructor
  108. *
  109. * INPUTS
  110. * NONE
  111. *
  112. * RESULT
  113. * NONE
  114. *
  115. ******************************************************************************/
  116. DlgMsgBox::DlgMsgBox() :
  117. mUserData(0),
  118. PopupDialogClass(IDD_MESSAGEBOX_OK)
  119. {
  120. CurrentCount++;
  121. }
  122. /******************************************************************************
  123. *
  124. * NAME
  125. * DlgMsgBox::~DlgMsgBox
  126. *
  127. * DESCRIPTION
  128. * Destructor
  129. *
  130. * INPUTS
  131. * NONE
  132. *
  133. * RESULT
  134. * NONE
  135. *
  136. ******************************************************************************/
  137. DlgMsgBox::~DlgMsgBox()
  138. {
  139. CurrentCount--;
  140. WWASSERT(CurrentCount >= 0);
  141. }
  142. /******************************************************************************
  143. *
  144. * NAME
  145. * DlgMsgBox::SetResourceType
  146. *
  147. * DESCRIPTION
  148. * Set the type of dialog box to use.
  149. *
  150. * INPUTS
  151. *
  152. * RESULT
  153. *
  154. ******************************************************************************/
  155. void DlgMsgBox::SetResourceType(DlgMsgBox::Type type)
  156. {
  157. static UINT _types[] =
  158. {
  159. IDD_MESSAGEBOX_OK,
  160. IDD_MESSAGEBOX_YESNO
  161. };
  162. DialogResID = _types[type];
  163. }
  164. /******************************************************************************
  165. *
  166. * NAME
  167. * DlgMsgBox::End_Dialog
  168. *
  169. * DESCRIPTION
  170. *
  171. * INPUTS
  172. * NONE
  173. *
  174. * RESULT
  175. * NONE
  176. *
  177. ******************************************************************************/
  178. void DlgMsgBox::End_Dialog(void)
  179. {
  180. Add_Ref();
  181. DlgMsgBoxEvent event(DlgMsgBoxEvent::Quitting, this, mUserData);
  182. NotifyObservers(event);
  183. Release_Ref();
  184. PopupDialogClass::End_Dialog();
  185. }
  186. /******************************************************************************
  187. *
  188. * NAME
  189. * DlgMsgBox::On_Command
  190. *
  191. * DESCRIPTION
  192. * Process command message
  193. *
  194. * INPUTS
  195. * Ctrl - ID of control
  196. * Message -
  197. * Param -
  198. *
  199. * RESULT
  200. * NONE
  201. *
  202. ******************************************************************************/
  203. void DlgMsgBox::On_Command(int ctrl, int message, DWORD param)
  204. {
  205. switch (ctrl)
  206. {
  207. case IDOK:
  208. {
  209. Add_Ref();
  210. DlgMsgBoxEvent event(DlgMsgBoxEvent::Okay, this, mUserData);
  211. NotifyObservers(event);
  212. Release_Ref();
  213. End_Dialog();
  214. }
  215. break;
  216. case IDYES:
  217. {
  218. Add_Ref();
  219. DlgMsgBoxEvent event(DlgMsgBoxEvent::Yes, this, mUserData);
  220. NotifyObservers(event);
  221. Release_Ref();
  222. End_Dialog();
  223. }
  224. break;
  225. case IDNO:
  226. {
  227. Add_Ref();
  228. DlgMsgBoxEvent event(DlgMsgBoxEvent::No, this, mUserData);
  229. NotifyObservers(event);
  230. Release_Ref();
  231. End_Dialog();
  232. }
  233. break;
  234. default:
  235. PopupDialogClass::On_Command(ctrl, message, param);
  236. break;
  237. }
  238. }