GadgetCheckBox.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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: CheckBox.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: CheckBox.cpp
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: Checkbox 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/Gadget.h"
  48. #include "GameClient/GameWindowManager.h"
  49. #include "GameClient/Keyboard.h"
  50. // DEFINES ////////////////////////////////////////////////////////////////////
  51. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  52. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  53. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  54. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  55. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  58. ///////////////////////////////////////////////////////////////////////////////
  59. // GadgetCheckBoxInput ========================================================
  60. /** Handle input for check box */
  61. //=============================================================================
  62. WindowMsgHandledType GadgetCheckBoxInput( GameWindow *window, UnsignedInt msg,
  63. WindowMsgData mData1, WindowMsgData mData2 )
  64. {
  65. WinInstanceData *instData = window->winGetInstanceData();
  66. switch( msg )
  67. {
  68. // ------------------------------------------------------------------------
  69. case GWM_MOUSE_ENTERING:
  70. {
  71. if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
  72. {
  73. BitSet( instData->m_state, WIN_STATE_HILITED );
  74. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  75. GBM_MOUSE_ENTERING,
  76. (WindowMsgData)window,
  77. mData1 );
  78. //TheWindowManager->winSetFocus( window );
  79. } // end if
  80. break;
  81. } // end mouse entering
  82. // ------------------------------------------------------------------------
  83. case GWM_MOUSE_LEAVING:
  84. {
  85. if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
  86. {
  87. BitClear( instData->m_state, WIN_STATE_HILITED );
  88. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  89. GBM_MOUSE_LEAVING,
  90. (WindowMsgData)window,
  91. mData1 );
  92. } // end if
  93. break;
  94. } // end mouse leaving
  95. // ------------------------------------------------------------------------
  96. case GWM_LEFT_DRAG:
  97. {
  98. TheWindowManager->winSendSystemMsg( window->winGetOwner(), GGM_LEFT_DRAG,
  99. (WindowMsgData)window, mData1 );
  100. break;
  101. } // end left drag
  102. // ------------------------------------------------------------------------
  103. case GWM_LEFT_DOWN:
  104. {
  105. break;
  106. } // end left down
  107. // ------------------------------------------------------------------------
  108. case GWM_LEFT_UP:
  109. {
  110. if( BitTest( instData->getState(), WIN_STATE_HILITED ) == FALSE )
  111. {
  112. // this up click was not meant for this button
  113. return MSG_IGNORED;
  114. }
  115. // Toggle the check state
  116. instData->m_state ^= WIN_STATE_SELECTED;
  117. TheWindowManager->winSendSystemMsg( window->winGetOwner(), GBM_SELECTED,
  118. (WindowMsgData)window, mData1 );
  119. break;
  120. } // end left up and left click
  121. // ------------------------------------------------------------------------
  122. case GWM_RIGHT_DOWN:
  123. {
  124. break;
  125. } // end right down
  126. //-------------------------------------------------------------------------
  127. case GWM_RIGHT_UP:
  128. {
  129. // Need to be specially marked to care about right mouse events
  130. if( BitTest( instData->getState(), WIN_STATE_SELECTED ) )
  131. {
  132. TheWindowManager->winSendSystemMsg( instData->getOwner(), GBM_SELECTED_RIGHT,
  133. (WindowMsgData)window, mData1 );
  134. BitClear( instData->m_state, WIN_STATE_SELECTED );
  135. }
  136. else
  137. {
  138. // this up click was not meant for this button
  139. return MSG_IGNORED;
  140. }
  141. break;
  142. } // end right up or right click
  143. // ------------------------------------------------------------------------
  144. case GWM_CHAR:
  145. {
  146. switch( mData1 )
  147. {
  148. // --------------------------------------------------------------------
  149. case KEY_ENTER:
  150. case KEY_SPACE:
  151. {
  152. if( BitTest( mData2, KEY_STATE_DOWN ) )
  153. {
  154. // Toggle the check state
  155. instData->m_state ^= WIN_STATE_SELECTED;
  156. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  157. GBM_SELECTED,
  158. (WindowMsgData)window,
  159. 0 );
  160. } //end if
  161. break;
  162. } // end enter/space
  163. // --------------------------------------------------------------------
  164. case KEY_DOWN:
  165. case KEY_RIGHT:
  166. case KEY_TAB:
  167. {
  168. if( BitTest( mData2, KEY_STATE_DOWN ) )
  169. TheWindowManager->winNextTab(window);
  170. break;
  171. } // end down, right, tab
  172. // --------------------------------------------------------------------
  173. case KEY_UP:
  174. case KEY_LEFT:
  175. {
  176. if( BitTest( mData2, KEY_STATE_DOWN ) )
  177. TheWindowManager->winPrevTab(window);
  178. break;
  179. } // end up, left
  180. // --------------------------------------------------------------------
  181. default:
  182. {
  183. return MSG_IGNORED;
  184. } // end default
  185. } // end switch
  186. break;
  187. } // end char msg
  188. // ------------------------------------------------------------------------
  189. default:
  190. {
  191. return MSG_IGNORED;
  192. } // end default
  193. } // end switch( msg )
  194. return MSG_HANDLED;
  195. } // end GadgetCheckBoxInput
  196. // GadgetCheckBoxSystem =======================================================
  197. /** Handle system messages for check box */
  198. //=============================================================================
  199. WindowMsgHandledType GadgetCheckBoxSystem( GameWindow *window, UnsignedInt msg,
  200. WindowMsgData mData1, WindowMsgData mData2 )
  201. {
  202. WinInstanceData *instData = window->winGetInstanceData();
  203. switch( msg )
  204. {
  205. // ------------------------------------------------------------------------
  206. case GGM_SET_LABEL:
  207. {
  208. window->winSetText( *(UnicodeString*)mData1 );
  209. break;
  210. }
  211. // ------------------------------------------------------------------------
  212. case GWM_CREATE:
  213. break;
  214. // ------------------------------------------------------------------------
  215. case GWM_DESTROY:
  216. break;
  217. // ------------------------------------------------------------------------
  218. case GWM_INPUT_FOCUS:
  219. if( mData1 == FALSE )
  220. BitClear( instData->m_state, WIN_STATE_HILITED );
  221. else
  222. BitSet( instData->m_state, WIN_STATE_HILITED );
  223. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  224. GGM_FOCUS_CHANGE,
  225. mData1,
  226. window->winGetWindowId() );
  227. if( mData1 == FALSE )
  228. *(Bool*)mData2 = FALSE;
  229. else
  230. *(Bool*)mData2 = TRUE;
  231. break;
  232. default:
  233. return MSG_IGNORED;
  234. } // end switch msg
  235. return MSG_HANDLED;
  236. } // end GadgetCheckBoxSystem
  237. // GadgetCheckBoxSetText ======================================================
  238. /** Set the text for the control */
  239. //=============================================================================
  240. void GadgetCheckBoxSetText( GameWindow *g, UnicodeString text )
  241. {
  242. // sanity
  243. if( g == NULL )
  244. return;
  245. TheWindowManager->winSendSystemMsg( g, GGM_SET_LABEL, (WindowMsgData)&text, 0 );
  246. } // end GadgetCheckBoxSetText
  247. // GadgetCheckBoxSetChecked ============================================
  248. //=============================================================================
  249. /** Set the check state for the check box */
  250. //=============================================================================
  251. void GadgetCheckBoxSetChecked( GameWindow *g, Bool isChecked)
  252. {
  253. WinInstanceData *instData = g->winGetInstanceData();
  254. if (isChecked)
  255. {
  256. BitSet(instData->m_state, WIN_STATE_SELECTED);
  257. }
  258. else
  259. {
  260. BitClear(instData->m_state, WIN_STATE_SELECTED);
  261. }
  262. TheWindowManager->winSendSystemMsg( g->winGetOwner(), GBM_SELECTED,
  263. (WindowMsgData)g, 0 );
  264. }
  265. // GadgetCheckBoxToggle ============================================
  266. //=============================================================================
  267. /** Toggle the check state for the check box */
  268. //=============================================================================
  269. void GadgetCheckBoxToggle( GameWindow *g)
  270. {
  271. WinInstanceData *instData = g->winGetInstanceData();
  272. Bool isChecked = BitTest(instData->m_state, WIN_STATE_SELECTED);
  273. if (isChecked)
  274. {
  275. BitClear(instData->m_state, WIN_STATE_SELECTED);
  276. }
  277. else
  278. {
  279. BitSet(instData->m_state, WIN_STATE_SELECTED);
  280. }
  281. TheWindowManager->winSendSystemMsg( g->winGetOwner(), GBM_SELECTED,
  282. (WindowMsgData)g, 0 );
  283. }
  284. // GadgetCheckBoxIsChecked ======================================================
  285. /** Check the check state */
  286. //=============================================================================
  287. Bool GadgetCheckBoxIsChecked( GameWindow *g )
  288. {
  289. WinInstanceData *instData = g->winGetInstanceData();
  290. return (BitTest(instData->m_state, WIN_STATE_SELECTED));
  291. }