RadioButtonProperties.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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: RadioButtonProperties.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: RadioButtonProperties.cpp
  36. //
  37. // Created: Colin Day, August 2001
  38. //
  39. // Desc: Radio button properties
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. // USER INCLUDES //////////////////////////////////////////////////////////////
  47. #include "Common/NameKeyGenerator.h"
  48. #include "GameClient/GameWindowManager.h"
  49. #include "GUIEdit.h"
  50. #include "Properties.h"
  51. #include "Resource.h"
  52. #include "GameClient/GadgetRadioButton.h"
  53. #include "GameClient/Gadget.h"
  54. // DEFINES ////////////////////////////////////////////////////////////////////
  55. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  58. ///////////////////////////////////////////////////////////////////////////////
  59. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  60. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  63. ///////////////////////////////////////////////////////////////////////////////
  64. // radioButtonPropertiesCallback ==============================================
  65. /** Dialog callback for properties */
  66. //=============================================================================
  67. static LRESULT CALLBACK radioButtonPropertiesCallback( HWND hWndDialog,
  68. UINT message,
  69. WPARAM wParam,
  70. LPARAM lParam )
  71. {
  72. Int returnCode;
  73. //
  74. // handle any common messages between all property dialogs cause they
  75. // are designed to have controls doing the same functionality
  76. // and names
  77. //
  78. if( HandleCommonDialogMessages( hWndDialog, message,
  79. wParam, lParam, &returnCode ) == TRUE )
  80. return returnCode;
  81. switch( message )
  82. {
  83. // ------------------------------------------------------------------------
  84. case WM_COMMAND:
  85. {
  86. // Int notifyCode = HIWORD( wParam ); // notification code
  87. Int controlID = LOWORD( wParam ); // control ID
  88. // HWND hWndControl = (HWND)lParam; // control window handle
  89. switch( controlID )
  90. {
  91. // --------------------------------------------------------------------
  92. case BUTTON_CLEAR_GROUP:
  93. {
  94. SetDlgItemInt( hWndDialog, COMBO_GROUP, 0, FALSE );
  95. break;
  96. } // end clear group
  97. // --------------------------------------------------------------------
  98. case IDOK:
  99. {
  100. GameWindow *window = TheEditor->getPropertyTarget();
  101. // sanity
  102. if( window )
  103. {
  104. ImageAndColorInfo *info;
  105. // save the common properties
  106. if( SaveCommonDialogProperties( hWndDialog, window ) == FALSE )
  107. break;
  108. // save the image and color data
  109. // ----------------------------------------------------------------
  110. info = GetStateInfo( RADIO_ENABLED );
  111. GadgetRadioSetEnabledImage( window, info->image );
  112. GadgetRadioSetEnabledColor( window, info->color );
  113. GadgetRadioSetEnabledBorderColor( window, info->borderColor );
  114. info = GetStateInfo( RADIO_ENABLED_UNCHECKED_BOX );
  115. GadgetRadioSetEnabledUncheckedBoxImage( window, info->image );
  116. GadgetRadioSetEnabledUncheckedBoxColor( window, info->color );
  117. GadgetRadioSetEnabledUncheckedBoxBorderColor( window, info->borderColor );
  118. info = GetStateInfo( RADIO_ENABLED_CHECKED_BOX );
  119. GadgetRadioSetEnabledCheckedBoxImage( window, info->image );
  120. GadgetRadioSetEnabledCheckedBoxColor( window, info->color );
  121. GadgetRadioSetEnabledCheckedBoxBorderColor( window, info->borderColor );
  122. // ----------------------------------------------------------------
  123. info = GetStateInfo( RADIO_DISABLED );
  124. GadgetRadioSetDisabledImage( window, info->image );
  125. GadgetRadioSetDisabledColor( window, info->color );
  126. GadgetRadioSetDisabledBorderColor( window, info->borderColor );
  127. info = GetStateInfo( RADIO_DISABLED_UNCHECKED_BOX );
  128. GadgetRadioSetDisabledUncheckedBoxImage( window, info->image );
  129. GadgetRadioSetDisabledUncheckedBoxColor( window, info->color );
  130. GadgetRadioSetDisabledUncheckedBoxBorderColor( window, info->borderColor );
  131. info = GetStateInfo( RADIO_DISABLED_CHECKED_BOX );
  132. GadgetRadioSetDisabledCheckedBoxImage( window, info->image );
  133. GadgetRadioSetDisabledCheckedBoxColor( window, info->color );
  134. GadgetRadioSetDisabledCheckedBoxBorderColor( window, info->borderColor );
  135. // ----------------------------------------------------------------
  136. info = GetStateInfo( RADIO_HILITE );
  137. GadgetRadioSetHiliteImage( window, info->image );
  138. GadgetRadioSetHiliteColor( window, info->color );
  139. GadgetRadioSetHiliteBorderColor( window, info->borderColor );
  140. info = GetStateInfo( RADIO_HILITE_UNCHECKED_BOX );
  141. GadgetRadioSetHiliteUncheckedBoxImage( window, info->image );
  142. GadgetRadioSetHiliteUncheckedBoxColor( window, info->color );
  143. GadgetRadioSetHiliteUncheckedBoxBorderColor( window, info->borderColor );
  144. info = GetStateInfo( RADIO_HILITE_CHECKED_BOX );
  145. GadgetRadioSetHiliteCheckedBoxImage( window, info->image );
  146. GadgetRadioSetHiliteCheckedBoxColor( window, info->color );
  147. GadgetRadioSetHiliteCheckedBoxBorderColor( window, info->borderColor );
  148. // save group
  149. Int group = GetDlgItemInt( hWndDialog, COMBO_GROUP, NULL, FALSE );
  150. Int screen = TheNameKeyGenerator->nameToKey( AsciiString(TheEditor->getSaveFilename()) );
  151. GadgetRadioSetGroup( window, group, screen );
  152. } // end if
  153. DestroyWindow( hWndDialog );
  154. break;
  155. } // end OK
  156. // --------------------------------------------------------------------
  157. case IDCANCEL:
  158. {
  159. DestroyWindow( hWndDialog );
  160. break;
  161. } // end cancel
  162. } // end switch( LOWORD( wParam ) )
  163. return 0;
  164. } // end of WM_COMMAND
  165. // ------------------------------------------------------------------------
  166. case WM_CLOSE:
  167. {
  168. DestroyWindow( hWndDialog );
  169. return 0;
  170. } // end close
  171. // ------------------------------------------------------------------------
  172. default:
  173. return 0;
  174. } // end of switch
  175. } // end radioButtonPropertiesCallback
  176. ///////////////////////////////////////////////////////////////////////////////
  177. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  178. ///////////////////////////////////////////////////////////////////////////////
  179. // loadExistingGroupsCombo ====================================================
  180. /** fill the group combo box with all the other groups in the screen */
  181. //=============================================================================
  182. static void loadExistingGroupsCombo( HWND combo, GameWindow *window )
  183. {
  184. // sanity
  185. if( combo == NULL )
  186. return;
  187. // end of recursion
  188. if( window == NULL )
  189. return;
  190. // if this is a radio button get the group
  191. if( BitTest( window->winGetStyle(), GWS_RADIO_BUTTON ) )
  192. {
  193. RadioButtonData *radioData = (RadioButtonData *)window->winGetUserData();
  194. char buffer[ 64 ];
  195. // convert to string
  196. sprintf( buffer, "%d", radioData->group );
  197. // only add it not already there
  198. if( SendMessage( combo, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer ) == CB_ERR )
  199. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)buffer );
  200. } // end if
  201. // search our children
  202. GameWindow *child;
  203. for( child = window->winGetChild(); child; child = child->winGetNext() )
  204. loadExistingGroupsCombo( combo, child );
  205. // search the next in line
  206. loadExistingGroupsCombo( combo, window->winGetNext() );
  207. } // end loadExistingGroupsCombo
  208. // InitRadioButtonPropertiesDialog ============================================
  209. /** Bring up the radio button properties dialog */
  210. //=============================================================================
  211. HWND InitRadioButtonPropertiesDialog( GameWindow *window )
  212. {
  213. HWND dialog;
  214. // create the dialog box
  215. dialog = CreateDialog( TheEditor->getInstance(),
  216. (LPCTSTR)RADIO_BUTTON_PROPERTIES_DIALOG,
  217. TheEditor->getWindowHandle(),
  218. (DLGPROC)radioButtonPropertiesCallback );
  219. if( dialog == NULL )
  220. return NULL;
  221. // do the common initialization
  222. CommonDialogInitialize( window, dialog );
  223. //
  224. // store in the image and color table the values for this putton
  225. //
  226. const Image *image;
  227. Color color, borderColor;
  228. // --------------------------------------------------------------------------
  229. image = GadgetRadioGetEnabledImage( window );
  230. color = GadgetRadioGetEnabledColor( window );
  231. borderColor = GadgetRadioGetEnabledBorderColor( window );
  232. StoreImageAndColor( RADIO_ENABLED, image, color, borderColor );
  233. image = GadgetRadioGetEnabledUncheckedBoxImage( window );
  234. color = GadgetRadioGetEnabledUncheckedBoxColor( window );
  235. borderColor = GadgetRadioGetEnabledUncheckedBoxBorderColor( window );
  236. StoreImageAndColor( RADIO_ENABLED_UNCHECKED_BOX, image, color, borderColor );
  237. image = GadgetRadioGetEnabledCheckedBoxImage( window );
  238. color = GadgetRadioGetEnabledCheckedBoxColor( window );
  239. borderColor = GadgetRadioGetEnabledCheckedBoxBorderColor( window );
  240. StoreImageAndColor( RADIO_ENABLED_CHECKED_BOX, image, color, borderColor );
  241. // --------------------------------------------------------------------------
  242. image = GadgetRadioGetDisabledImage( window );
  243. color = GadgetRadioGetDisabledColor( window );
  244. borderColor = GadgetRadioGetDisabledBorderColor( window );
  245. StoreImageAndColor( RADIO_DISABLED, image, color, borderColor );
  246. image = GadgetRadioGetDisabledUncheckedBoxImage( window );
  247. color = GadgetRadioGetDisabledUncheckedBoxColor( window );
  248. borderColor = GadgetRadioGetDisabledUncheckedBoxBorderColor( window );
  249. StoreImageAndColor( RADIO_DISABLED_UNCHECKED_BOX, image, color, borderColor );
  250. image = GadgetRadioGetDisabledCheckedBoxImage( window );
  251. color = GadgetRadioGetDisabledCheckedBoxColor( window );
  252. borderColor = GadgetRadioGetDisabledCheckedBoxBorderColor( window );
  253. StoreImageAndColor( RADIO_DISABLED_CHECKED_BOX, image, color, borderColor );
  254. // --------------------------------------------------------------------------
  255. image = GadgetRadioGetHiliteImage( window );
  256. color = GadgetRadioGetHiliteColor( window );
  257. borderColor = GadgetRadioGetHiliteBorderColor( window );
  258. StoreImageAndColor( RADIO_HILITE, image, color, borderColor );
  259. image = GadgetRadioGetHiliteUncheckedBoxImage( window );
  260. color = GadgetRadioGetHiliteUncheckedBoxColor( window );
  261. borderColor = GadgetRadioGetHiliteUncheckedBoxBorderColor( window );
  262. StoreImageAndColor( RADIO_HILITE_UNCHECKED_BOX, image, color, borderColor );
  263. image = GadgetRadioGetHiliteCheckedBoxImage( window );
  264. color = GadgetRadioGetHiliteCheckedBoxColor( window );
  265. borderColor = GadgetRadioGetHiliteCheckedBoxBorderColor( window );
  266. StoreImageAndColor( RADIO_HILITE_CHECKED_BOX, image, color, borderColor );
  267. // radio data
  268. RadioButtonData *radioData = (RadioButtonData *)window->winGetUserData();
  269. // fill the group combo box with all the other groups in the screen
  270. loadExistingGroupsCombo( GetDlgItem( dialog, COMBO_GROUP ),
  271. TheWindowManager->winGetWindowList() );
  272. // set the group for this radio button
  273. SetDlgItemInt( dialog, COMBO_GROUP, radioData->group, FALSE );
  274. // select the button enabled state for display
  275. SwitchToState( RADIO_ENABLED, dialog );
  276. //
  277. // initialize the dialog with values from the window
  278. //
  279. return dialog;
  280. } // end InitRadioButtonPropertiesDialog