DlgPasswordPrompt.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. * FILE
  21. * $Archive: /Commando/Code/Commando/DlgPasswordPrompt.cpp $
  22. *
  23. * DESCRIPTION
  24. * General purpose password entry dialog for joining a game.
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 3 $
  32. * $Modtime: 11/29/01 9:19p $
  33. *
  34. ******************************************************************************/
  35. #include "DlgPasswordPrompt.h"
  36. #include <WWUI\EditCtrl.h>
  37. /******************************************************************************
  38. *
  39. * NAME
  40. * DlgPasswordPrompt::DoDialog
  41. *
  42. * DESCRIPTION
  43. * Create a dialog to prompt the user to enter a password.
  44. *
  45. * INPUTS
  46. * Target - Target to receive signal that a password was entered.
  47. *
  48. * RESULT
  49. * True if dialog created successfully.
  50. *
  51. ******************************************************************************/
  52. bool DlgPasswordPrompt::DoDialog(Signaler<DlgPasswordPrompt>* target)
  53. {
  54. DlgPasswordPrompt* dialog = new DlgPasswordPrompt;
  55. if (dialog)
  56. {
  57. dialog->Start_Dialog();
  58. if (target)
  59. {
  60. dialog->SignalMe(*target);
  61. }
  62. dialog->Release_Ref();
  63. }
  64. return (dialog != NULL);
  65. }
  66. /******************************************************************************
  67. *
  68. * NAME
  69. * DlgPasswordPrompt::DlgPasswordPrompt
  70. *
  71. * DESCRIPTION
  72. * Constructor
  73. *
  74. * INPUTS
  75. * NONE
  76. *
  77. * RESULT
  78. * NONE
  79. *
  80. ******************************************************************************/
  81. DlgPasswordPrompt::DlgPasswordPrompt() :
  82. PopupDialogClass(IDD_MP_JOIN_PASSWORD)
  83. {
  84. WWDEBUG_SAY(("DlgPasswordPrompt Instantiated\n"));
  85. }
  86. /******************************************************************************
  87. *
  88. * NAME
  89. * DlgPasswordPrompt::~DlgPasswordPrompt
  90. *
  91. * DESCRIPTION
  92. * Destructor
  93. *
  94. * INPUTS
  95. * NONE
  96. *
  97. * RESULT
  98. * NONE
  99. *
  100. ******************************************************************************/
  101. DlgPasswordPrompt::~DlgPasswordPrompt()
  102. {
  103. WWDEBUG_SAY(("DlgPasswordPrompt Destroyed\n"));
  104. }
  105. /******************************************************************************
  106. *
  107. * NAME
  108. * DlgPasswordPrompt::GetPassword
  109. *
  110. * DESCRIPTION
  111. * Retrieve the password entered by the user.
  112. *
  113. * INPUTS
  114. * NONE
  115. *
  116. * RESULT
  117. * Password - Pointer to password string.
  118. *
  119. ******************************************************************************/
  120. const WCHAR* DlgPasswordPrompt::GetPassword(void) const
  121. {
  122. return Get_Dlg_Item_Text(IDC_PASSWORD_EDIT);
  123. }
  124. /******************************************************************************
  125. *
  126. * NAME
  127. * DlgPasswordPrompt::On_Init_Dialog
  128. *
  129. * DESCRIPTION
  130. * One time dialog initialization.
  131. *
  132. * INPUTS
  133. * NONE
  134. *
  135. * RESULT
  136. * NONE
  137. *
  138. ******************************************************************************/
  139. void DlgPasswordPrompt::On_Init_Dialog(void)
  140. {
  141. // Disable the join button until the user enters text.
  142. Enable_Dlg_Item(IDC_JOIN_GAME_BUTTON, false);
  143. EditCtrlClass* edit = (EditCtrlClass*)Get_Dlg_Item(IDC_PASSWORD_EDIT);
  144. if (edit)
  145. {
  146. edit->Set_Focus();
  147. }
  148. PopupDialogClass::On_Init_Dialog();
  149. }
  150. /******************************************************************************
  151. *
  152. * NAME
  153. * DlgPasswordPrompt::On_Command
  154. *
  155. * DESCRIPTION
  156. * Handle command messages from dialog controls.
  157. *
  158. * INPUTS
  159. * CtrlID - ID of control sending command.
  160. * Message - Message identifier.
  161. * Param - Message parameter
  162. *
  163. * RESULT
  164. * NONE
  165. *
  166. ******************************************************************************/
  167. void DlgPasswordPrompt::On_Command(int ctrlID, int message, DWORD param)
  168. {
  169. if (IDC_JOIN_GAME_BUTTON == ctrlID)
  170. {
  171. Signaler<DlgPasswordPrompt>::SendSignal(*this);
  172. End_Dialog();
  173. }
  174. PopupDialogClass::On_Command(ctrlID, message, param);
  175. }
  176. /******************************************************************************
  177. *
  178. * NAME
  179. * DlgPasswordPrompt::On_EditCtrl_Change
  180. *
  181. * DESCRIPTION
  182. * Handle notification that the contents of the edit control has changed.
  183. *
  184. * INPUTS
  185. * Edit - Pointer to edit control whose contents has changed.
  186. * ID - Identifier of control.
  187. *
  188. * RESULT
  189. * NONE
  190. *
  191. ******************************************************************************/
  192. void DlgPasswordPrompt::On_EditCtrl_Change(EditCtrlClass* edit, int id)
  193. {
  194. if (IDC_PASSWORD_EDIT == id)
  195. {
  196. const WCHAR* text = edit->Get_Text();
  197. bool enableJoin = (text && (wcslen(text) > 0));
  198. Enable_Dlg_Item(IDC_JOIN_GAME_BUTTON, enableJoin);
  199. }
  200. }
  201. /******************************************************************************
  202. *
  203. * NAME
  204. * DlgPasswordPrompt::On_EditCtrl_Enter_Pressed
  205. *
  206. * DESCRIPTION
  207. * Handle notification that the enter key was pressed in an edit control.
  208. *
  209. * INPUTS
  210. * Edit - Pointer to edit control whose contents has changed.
  211. * ID - Identifier of control.
  212. *
  213. * RESULT
  214. * NONE
  215. *
  216. ******************************************************************************/
  217. void DlgPasswordPrompt::On_EditCtrl_Enter_Pressed(EditCtrlClass* edit, int id)
  218. {
  219. if ((IDC_PASSWORD_EDIT == id) && Is_Dlg_Item_Enabled(IDC_JOIN_GAME_BUTTON))
  220. {
  221. On_Command(IDC_JOIN_GAME_BUTTON, 0, 0);
  222. }
  223. }