GadgetRadioButton.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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: RadioButton.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: RadioButton.cpp
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: Radio button GUI control
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  45. // USER INCLUDES //////////////////////////////////////////////////////////////
  46. #include "Common/Language.h"
  47. #include "Gameclient/GameWindowManager.h"
  48. #include "GameClient/Gadget.h"
  49. // DEFINES ////////////////////////////////////////////////////////////////////
  50. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  51. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  52. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  53. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  54. ///////////////////////////////////////////////////////////////////////////////
  55. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // doRadioUnselect ============================================================
  58. /** Do the unselect of matching group not including exception window */
  59. //=============================================================================
  60. static void doRadioUnselect( GameWindow *window, Int group, Int screen,
  61. GameWindow *except )
  62. {
  63. //
  64. // if this is a radio button we have something to consider, but we
  65. // will ignore the except window
  66. //
  67. if( window != except && BitTest( window->winGetStyle(), GWS_RADIO_BUTTON ) )
  68. {
  69. RadioButtonData *radioData = (RadioButtonData *)window->winGetUserData();
  70. if( radioData->group == group && radioData->screen == screen )
  71. {
  72. WinInstanceData *instData = window->winGetInstanceData();
  73. BitClear( instData->m_state, WIN_STATE_SELECTED );
  74. } // end if
  75. } // end if
  76. // recursively call on all my children
  77. GameWindow *child;
  78. for( child = window->winGetChild(); child; child = child->winGetNext() )
  79. doRadioUnselect( child, group, screen, except );
  80. } // end doRadioUnselect
  81. // unselectOtherRadioOfGroup ==================================================
  82. /** Go through the entire window system, including child windows and
  83. * unselect any radio buttons of the specified group, but not the
  84. * window specified */
  85. //=============================================================================
  86. static void unselectOtherRadioOfGroup( Int group, Int screen,
  87. GameWindow *except )
  88. {
  89. GameWindow *window = TheWindowManager->winGetWindowList();
  90. for( window = TheWindowManager->winGetWindowList();
  91. window;
  92. window = window->winGetNext() )
  93. doRadioUnselect( window, group, screen, except );
  94. } // end unselectOtherRadioOfGroup
  95. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  96. // GadgetRadioButtonInput =====================================================
  97. /** Handle input for radio button */
  98. //=============================================================================
  99. WindowMsgHandledType GadgetRadioButtonInput( GameWindow *window, UnsignedInt msg,
  100. WindowMsgData mData1, WindowMsgData mData2 )
  101. {
  102. WinInstanceData *instData = window->winGetInstanceData();
  103. switch( msg )
  104. {
  105. // ------------------------------------------------------------------------
  106. case GWM_MOUSE_ENTERING:
  107. {
  108. if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
  109. {
  110. BitSet( instData->m_state, WIN_STATE_HILITED );
  111. TheWindowManager->winSendSystemMsg( instData->getOwner(),
  112. GBM_MOUSE_ENTERING,
  113. (WindowMsgData)window,
  114. mData1 );
  115. //TheWindowManager->winSetFocus( window );
  116. } // end if
  117. break;
  118. } // end mouse enter
  119. // ------------------------------------------------------------------------
  120. case GWM_MOUSE_LEAVING:
  121. {
  122. if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
  123. {
  124. BitClear( instData->m_state, WIN_STATE_HILITED );
  125. TheWindowManager->winSendSystemMsg( instData->getOwner(),
  126. GBM_MOUSE_LEAVING,
  127. (WindowMsgData)window,
  128. mData1 );
  129. } // end if
  130. break;
  131. } // end mouse leaving
  132. // ------------------------------------------------------------------------
  133. case GWM_LEFT_DRAG:
  134. {
  135. TheWindowManager->winSendSystemMsg( instData->getOwner(), GGM_LEFT_DRAG,
  136. (WindowMsgData)window, mData1 );
  137. break;
  138. } // end left drag
  139. // ------------------------------------------------------------------------
  140. case GWM_LEFT_DOWN:
  141. {
  142. break;
  143. } // end down
  144. // ------------------------------------------------------------------------
  145. case GWM_LEFT_UP:
  146. {
  147. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) == FALSE )
  148. {
  149. RadioButtonData *radioData = (RadioButtonData *)window->winGetUserData();
  150. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  151. GBM_SELECTED,
  152. (WindowMsgData)window,
  153. mData1 );
  154. //
  155. // unselect any windows in the system (including children) that
  156. // are radio buttons with this same group and screen ID
  157. //
  158. if( radioData->group != 0 )
  159. unselectOtherRadioOfGroup(radioData->group, radioData->screen, window );
  160. // this button is now selected
  161. BitSet( instData->m_state, WIN_STATE_SELECTED );
  162. } // end if, not selected
  163. else if( BitTest( instData->getState(), WIN_STATE_HILITED ) == FALSE )
  164. {
  165. // this up click was not meant for this button
  166. return MSG_IGNORED;
  167. } // end else if
  168. break;
  169. } // end left up or click
  170. // ------------------------------------------------------------------------
  171. case GWM_CHAR:
  172. {
  173. switch( mData1 )
  174. {
  175. // --------------------------------------------------------------------
  176. case KEY_ENTER:
  177. case KEY_SPACE:
  178. if( BitTest( mData2, KEY_STATE_DOWN ) )
  179. {
  180. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) == FALSE )
  181. {
  182. RadioButtonData *radioData = (RadioButtonData *)window->winGetUserData();
  183. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  184. GBM_SELECTED,
  185. (WindowMsgData)window,
  186. mData1 );
  187. //
  188. // unselect any windows in the system (including children) that
  189. // are radio buttons with this same group and screen ID
  190. //
  191. if( radioData->group != 0 )
  192. unselectOtherRadioOfGroup(radioData->group, radioData->screen, window );
  193. // this button is now selected
  194. BitSet( instData->m_state, WIN_STATE_SELECTED );
  195. } // end if, not selected
  196. } // end key down
  197. break;
  198. // --------------------------------------------------------------------
  199. case KEY_DOWN:
  200. case KEY_RIGHT:
  201. case KEY_TAB:
  202. {
  203. if( BitTest( mData2, KEY_STATE_DOWN ) )
  204. window->winNextTab();
  205. break;
  206. } // end down, right, or tab
  207. // --------------------------------------------------------------------
  208. case KEY_UP:
  209. case KEY_LEFT:
  210. {
  211. if( BitTest( mData2, KEY_STATE_DOWN ) )
  212. window->winPrevTab();
  213. break;
  214. } // end up, left
  215. // --------------------------------------------------------------------
  216. default:
  217. {
  218. return MSG_IGNORED;
  219. } // end default
  220. } // end switch( mData1 )
  221. break;
  222. } // end char messsage
  223. // ------------------------------------------------------------------------
  224. default:
  225. {
  226. return MSG_IGNORED;
  227. } // end default
  228. } // end switch( msg )
  229. return MSG_HANDLED;
  230. } // end GadgetRadioButtonInput
  231. // GadgetRadioButtonSystem ====================================================
  232. /** Handle system messages for radio button */
  233. //=============================================================================
  234. WindowMsgHandledType GadgetRadioButtonSystem( GameWindow *window, UnsignedInt msg,
  235. WindowMsgData mData1, WindowMsgData mData2 )
  236. {
  237. WinInstanceData *instData = window->winGetInstanceData();
  238. switch( msg )
  239. {
  240. // ------------------------------------------------------------------------
  241. case GBM_SET_SELECTION:
  242. {
  243. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) == FALSE )
  244. {
  245. // do we want to send a selected message?
  246. if( (Bool)mData1 == TRUE )
  247. {
  248. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  249. GBM_SELECTED,
  250. (WindowMsgData)window,
  251. 0 );
  252. } // end if
  253. //
  254. // unselect any windows in the system (including children) that
  255. // are radio buttons with this same group and screen ID
  256. //
  257. RadioButtonData *radioData = (RadioButtonData *)window->winGetUserData();
  258. if( radioData->group != 0 )
  259. unselectOtherRadioOfGroup(radioData->group, radioData->screen, window );
  260. // this button is now selected
  261. BitSet( instData->m_state, WIN_STATE_SELECTED );
  262. } // end if
  263. break;
  264. } // end set selection
  265. // ------------------------------------------------------------------------
  266. case GGM_SET_LABEL:
  267. {
  268. window->winSetText( *(UnicodeString*)mData1 );
  269. break;
  270. } // end set label
  271. // ------------------------------------------------------------------------
  272. case GWM_CREATE:
  273. break;
  274. // ------------------------------------------------------------------------
  275. case GWM_DESTROY:
  276. {
  277. RadioButtonData *radioData = (RadioButtonData *)window->winGetUserData();
  278. // free radio button user data
  279. delete radioData;
  280. break;
  281. } // end destroy
  282. // ------------------------------------------------------------------------
  283. case GWM_INPUT_FOCUS:
  284. {
  285. if( mData1 == FALSE )
  286. BitClear( instData->m_state, WIN_STATE_HILITED );
  287. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  288. GGM_FOCUS_CHANGE,
  289. mData1,
  290. window->winGetWindowId() );
  291. *(Bool*)mData2 = TRUE;
  292. break;
  293. } // end focus
  294. default:
  295. return MSG_IGNORED;
  296. } // end switch( msg )
  297. return MSG_HANDLED;
  298. } // end GadgetRadioButtonSystem
  299. // GadgetRadioSetText =========================================================
  300. /** Set the text for the control */
  301. //=============================================================================
  302. void GadgetRadioSetText( GameWindow *g, UnicodeString text )
  303. {
  304. // sanity
  305. if( g == NULL )
  306. return;
  307. TheWindowManager->winSendSystemMsg( g, GGM_SET_LABEL, (WindowMsgData)&text, 0 );
  308. } // end GadgetRadioSetText
  309. // GadgetRadioSetGroup ========================================================
  310. /** Set the group number for a radio button, only one radio button of
  311. * a group can be selected at any given time */
  312. //=============================================================================
  313. void GadgetRadioSetGroup( GameWindow *g, Int group, Int screen )
  314. {
  315. RadioButtonData *radioData = (RadioButtonData *)g->winGetUserData();
  316. radioData->group = group;
  317. radioData->screen = screen;
  318. } // end GadgetRadioSetGroup
  319. // GadgetRadioSetText =========================================================
  320. /** Set the text for the control */
  321. //=============================================================================
  322. void GadgetRadioSetSelection( GameWindow *g, Bool sendMsg )
  323. {
  324. // sanity
  325. if( g == NULL )
  326. return;
  327. TheWindowManager->winSendSystemMsg( g, GBM_SET_SELECTION, (WindowMsgData)&sendMsg, 0 );
  328. } // end GadgetRadioSetText