TextEntryProperties.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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: TextEntryProperties.cpp //////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: GUIEdit
  34. //
  35. // File name: TextEntryProperties.cpp
  36. //
  37. // Created: Colin Day, August 2001
  38. //
  39. // Desc: Text entry properties
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. // USER INCLUDES //////////////////////////////////////////////////////////////
  45. #include "GUIEdit.h"
  46. #include "Properties.h"
  47. #include "Resource.h"
  48. #include "GameClient/GadgetTextEntry.h"
  49. // DEFINES ////////////////////////////////////////////////////////////////////
  50. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  51. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  52. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  53. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  54. ///////////////////////////////////////////////////////////////////////////////
  55. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // textEntryPropertiesCallback ================================================
  58. /** Dialog callback for properties */
  59. //=============================================================================
  60. static LRESULT CALLBACK textEntryPropertiesCallback( HWND hWndDialog,
  61. UINT message,
  62. WPARAM wParam,
  63. LPARAM lParam )
  64. {
  65. Int returnCode;
  66. //
  67. // handle any common messages between all property dialogs cause they
  68. // are designed to have controls doing the same functionality
  69. // and names
  70. //
  71. if( HandleCommonDialogMessages( hWndDialog, message,
  72. wParam, lParam, &returnCode ) == TRUE )
  73. return returnCode;
  74. switch( message )
  75. {
  76. // ------------------------------------------------------------------------
  77. case WM_COMMAND:
  78. {
  79. // Int notifyCode = HIWORD( wParam ); // notification code
  80. Int controlID = LOWORD( wParam ); // control ID
  81. // HWND hWndControl = (HWND)lParam; // control window handle
  82. switch( controlID )
  83. {
  84. // --------------------------------------------------------------------
  85. case IDOK:
  86. {
  87. GameWindow *window = TheEditor->getPropertyTarget();
  88. // sanity
  89. if( window )
  90. {
  91. ImageAndColorInfo *info;
  92. // save the common properties
  93. if( SaveCommonDialogProperties( hWndDialog, window ) == FALSE )
  94. break;
  95. // save the image and color data
  96. // ----------------------------------------------------------------
  97. info = GetStateInfo( TEXT_ENTRY_ENABLED_LEFT );
  98. GadgetTextEntrySetEnabledImageLeft( window, info->image );
  99. GadgetTextEntrySetEnabledColor( window, info->color );
  100. GadgetTextEntrySetEnabledBorderColor( window, info->borderColor );
  101. info = GetStateInfo( TEXT_ENTRY_ENABLED_RIGHT );
  102. GadgetTextEntrySetEnabledImageRight( window, info->image );
  103. info = GetStateInfo( TEXT_ENTRY_ENABLED_CENTER );
  104. GadgetTextEntrySetEnabledImageCenter( window, info->image );
  105. info = GetStateInfo( TEXT_ENTRY_ENABLED_SMALL_CENTER );
  106. GadgetTextEntrySetEnabledImageSmallCenter( window, info->image );
  107. // ----------------------------------------------------------------
  108. info = GetStateInfo( TEXT_ENTRY_DISABLED_LEFT );
  109. GadgetTextEntrySetDisabledImageLeft( window, info->image );
  110. GadgetTextEntrySetDisabledColor( window, info->color );
  111. GadgetTextEntrySetDisabledBorderColor( window, info->borderColor );
  112. info = GetStateInfo( TEXT_ENTRY_DISABLED_RIGHT );
  113. GadgetTextEntrySetDisabledImageRight( window, info->image );
  114. info = GetStateInfo( TEXT_ENTRY_DISABLED_CENTER );
  115. GadgetTextEntrySetDisabledImageCenter( window, info->image );
  116. info = GetStateInfo( TEXT_ENTRY_DISABLED_SMALL_CENTER );
  117. GadgetTextEntrySetDisabledImageSmallCenter( window, info->image );
  118. // ----------------------------------------------------------------
  119. info = GetStateInfo( TEXT_ENTRY_HILITE_LEFT );
  120. GadgetTextEntrySetHiliteImageLeft( window, info->image );
  121. GadgetTextEntrySetHiliteColor( window, info->color );
  122. GadgetTextEntrySetHiliteBorderColor( window, info->borderColor );
  123. info = GetStateInfo( TEXT_ENTRY_HILITE_RIGHT );
  124. GadgetTextEntrySetHiliteImageRight( window, info->image );
  125. info = GetStateInfo( TEXT_ENTRY_HILITE_CENTER );
  126. GadgetTextEntrySetHiliteImageCenter( window, info->image );
  127. info = GetStateInfo( TEXT_ENTRY_HILITE_SMALL_CENTER );
  128. GadgetTextEntrySetHiliteImageSmallCenter( window, info->image );
  129. // text entry props
  130. EntryData *entryData = (EntryData *)window->winGetUserData();
  131. entryData->maxTextLen = GetDlgItemInt( hWndDialog, EDIT_MAX_CHARS, NULL, TRUE );
  132. entryData->secretText = IsDlgButtonChecked( hWndDialog, CHECK_SECRET_TEXT );
  133. entryData->aSCIIOnly = IsDlgButtonChecked( hWndDialog, CHECK_ASCII_TEXT );
  134. if( IsDlgButtonChecked( hWndDialog, RADIO_LETTERS_AND_NUMBERS ) )
  135. {
  136. entryData->alphaNumericalOnly = TRUE;
  137. entryData->numericalOnly = FALSE;
  138. } // end if
  139. else if( IsDlgButtonChecked( hWndDialog, RADIO_NUMBERS ) )
  140. {
  141. entryData->alphaNumericalOnly = FALSE;
  142. entryData->numericalOnly = TRUE;
  143. } // end else if
  144. else
  145. {
  146. entryData->alphaNumericalOnly = FALSE;
  147. entryData->numericalOnly = FALSE;
  148. } // end else
  149. } // end if
  150. DestroyWindow( hWndDialog );
  151. break;
  152. } // end OK
  153. // --------------------------------------------------------------------
  154. case IDCANCEL:
  155. {
  156. DestroyWindow( hWndDialog );
  157. break;
  158. } // end cancel
  159. } // end switch( LOWORD( wParam ) )
  160. return 0;
  161. } // end of WM_COMMAND
  162. // ------------------------------------------------------------------------
  163. case WM_CLOSE:
  164. {
  165. DestroyWindow( hWndDialog );
  166. return 0;
  167. } // end close
  168. // ------------------------------------------------------------------------
  169. default:
  170. return 0;
  171. } // end of switch
  172. } // end textEntryPropertiesCallback
  173. ///////////////////////////////////////////////////////////////////////////////
  174. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  175. ///////////////////////////////////////////////////////////////////////////////
  176. // InitTextEntryPropertiesDialog ==============================================
  177. /** Bring up the text entry properties dialog */
  178. //=============================================================================
  179. HWND InitTextEntryPropertiesDialog( GameWindow *window )
  180. {
  181. HWND dialog;
  182. // create the dialog box
  183. dialog = CreateDialog( TheEditor->getInstance(),
  184. (LPCTSTR)TEXT_ENTRY_PROPERTIES_DIALOG,
  185. TheEditor->getWindowHandle(),
  186. (DLGPROC)textEntryPropertiesCallback );
  187. if( dialog == NULL )
  188. return NULL;
  189. // do the common initialization
  190. CommonDialogInitialize( window, dialog );
  191. //
  192. // store in the image and color table the values for this putton
  193. //
  194. const Image *image;
  195. Color color, borderColor;
  196. // --------------------------------------------------------------------------
  197. image = GadgetTextEntryGetEnabledImageLeft( window );
  198. color = GadgetTextEntryGetEnabledColor( window );
  199. borderColor = GadgetTextEntryGetEnabledBorderColor( window );
  200. StoreImageAndColor( TEXT_ENTRY_ENABLED_LEFT, image, color, borderColor );
  201. image = GadgetTextEntryGetEnabledImageRight( window );
  202. StoreImageAndColor( TEXT_ENTRY_ENABLED_RIGHT, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  203. image = GadgetTextEntryGetEnabledImageCenter( window );
  204. StoreImageAndColor( TEXT_ENTRY_ENABLED_CENTER, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  205. image = GadgetTextEntryGetEnabledImageSmallCenter( window );
  206. StoreImageAndColor( TEXT_ENTRY_ENABLED_SMALL_CENTER, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  207. // --------------------------------------------------------------------------
  208. image = GadgetTextEntryGetDisabledImageLeft( window );
  209. color = GadgetTextEntryGetDisabledColor( window );
  210. borderColor = GadgetTextEntryGetDisabledBorderColor( window );
  211. StoreImageAndColor( TEXT_ENTRY_DISABLED_LEFT, image, color, borderColor );
  212. image = GadgetTextEntryGetDisabledImageRight( window );
  213. StoreImageAndColor( TEXT_ENTRY_DISABLED_RIGHT, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  214. image = GadgetTextEntryGetDisabledImageCenter( window );
  215. StoreImageAndColor( TEXT_ENTRY_DISABLED_CENTER, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  216. image = GadgetTextEntryGetDisabledImageSmallCenter( window );
  217. StoreImageAndColor( TEXT_ENTRY_DISABLED_SMALL_CENTER, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  218. // --------------------------------------------------------------------------
  219. image = GadgetTextEntryGetHiliteImageLeft( window );
  220. color = GadgetTextEntryGetHiliteColor( window );
  221. borderColor = GadgetTextEntryGetHiliteBorderColor( window );
  222. StoreImageAndColor( TEXT_ENTRY_HILITE_LEFT, image, color, borderColor );
  223. image = GadgetTextEntryGetHiliteImageRight( window );
  224. StoreImageAndColor( TEXT_ENTRY_HILITE_RIGHT, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  225. image = GadgetTextEntryGetHiliteImageCenter( window );
  226. StoreImageAndColor( TEXT_ENTRY_HILITE_CENTER, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  227. image = GadgetTextEntryGetHiliteImageSmallCenter( window );
  228. StoreImageAndColor( TEXT_ENTRY_HILITE_SMALL_CENTER, image, WIN_COLOR_UNDEFINED, WIN_COLOR_UNDEFINED );
  229. // fill out text entry properties
  230. EntryData *entryData = (EntryData *)window->winGetUserData();
  231. SetDlgItemInt( dialog, EDIT_MAX_CHARS, entryData->maxTextLen, TRUE );
  232. if( entryData->secretText )
  233. CheckDlgButton( dialog, CHECK_SECRET_TEXT, BST_CHECKED );
  234. if( entryData->aSCIIOnly )
  235. CheckDlgButton( dialog, CHECK_ASCII_TEXT, BST_CHECKED );
  236. if( entryData->numericalOnly )
  237. CheckDlgButton( dialog, RADIO_NUMBERS, BST_CHECKED );
  238. else if( entryData->alphaNumericalOnly )
  239. CheckDlgButton( dialog, RADIO_LETTERS_AND_NUMBERS, BST_CHECKED );
  240. else
  241. CheckDlgButton( dialog, RADIO_ANY_TEXT, BST_CHECKED );
  242. // select the button enabled state for display
  243. SwitchToState( TEXT_ENTRY_ENABLED_LEFT, dialog );
  244. //
  245. // initialize the dialog with values from the window
  246. //
  247. return dialog;
  248. } // end InitTextEntryPropertiesDialog