GadgetStaticText.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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: StaticText.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: StaticText.cpp
  36. //
  37. // Created: Colin Day, June 2001
  38. //
  39. // Desc: Static text 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/DisplayStringManager.h"
  48. #include "GameClient/GameWindow.h"
  49. #include "GameClient/Gadget.h"
  50. #include "GameClient/GameWindowManager.h"
  51. // DEFINES ////////////////////////////////////////////////////////////////////
  52. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  53. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  54. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  55. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  56. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////
  60. // GadgetStaticTextInput ======================================================
  61. /** Handle input for text field */
  62. //=============================================================================
  63. WindowMsgHandledType GadgetStaticTextInput( GameWindow *window, UnsignedInt msg,
  64. WindowMsgData mData1, WindowMsgData mData2 )
  65. {
  66. switch( msg )
  67. {
  68. // ------------------------------------------------------------------------
  69. case GWM_CHAR:
  70. switch (mData1)
  71. {
  72. case KEY_DOWN:
  73. case KEY_RIGHT:
  74. case KEY_TAB:
  75. // Just in case some fool sets static text as a tab stop
  76. if( BitTest( mData2, KEY_STATE_DOWN ) )
  77. window->winNextTab();
  78. break;
  79. case KEY_UP:
  80. case KEY_LEFT:
  81. if( BitTest( mData2, KEY_STATE_DOWN ) )
  82. window->winPrevTab();
  83. break;
  84. default:
  85. return MSG_IGNORED;
  86. }
  87. break;
  88. default:
  89. return MSG_IGNORED;
  90. }
  91. return MSG_HANDLED;
  92. } // end GadgetStaticTextInput
  93. // GadgetStaticTextSystem =====================================================
  94. /** Handle system messages for text field */
  95. //=============================================================================
  96. WindowMsgHandledType GadgetStaticTextSystem( GameWindow *window, UnsignedInt msg,
  97. WindowMsgData mData1, WindowMsgData mData2 )
  98. {
  99. // WinInstanceData *instData = window->winGetInstanceData();
  100. switch( msg )
  101. {
  102. // ------------------------------------------------------------------------
  103. case GGM_GET_LABEL:
  104. {
  105. TextData *tData = (TextData *)window->winGetUserData();
  106. if (tData && tData->text)
  107. *(UnicodeString*)mData2 = tData->text->getText();
  108. break;
  109. } // end get label
  110. // ------------------------------------------------------------------------
  111. case GGM_SET_LABEL:
  112. {
  113. if( mData1 )
  114. {
  115. TextData *tData = (TextData *)window->winGetUserData();
  116. if (tData && tData->text)
  117. tData->text->setText( *(UnicodeString*)mData1 );
  118. }
  119. break;
  120. } // end set label
  121. // ------------------------------------------------------------------------
  122. case GWM_CREATE:
  123. break;
  124. // ------------------------------------------------------------------------
  125. case GWM_DESTROY:
  126. {
  127. TextData *data = (TextData *)window->winGetUserData();
  128. // free the display string
  129. TheDisplayStringManager->freeDisplayString( data->text );
  130. // free text data
  131. delete( data );
  132. break;
  133. } // end destroy
  134. default:
  135. return MSG_IGNORED;
  136. } // end switch( msg )
  137. return MSG_HANDLED;
  138. } // end GadgetStaticTextSystem
  139. // GadgetStaticTextSetText ====================================================
  140. /** Set the text for a static text control */
  141. //=============================================================================
  142. void GadgetStaticTextSetText( GameWindow *window, UnicodeString text )
  143. {
  144. if(!window)
  145. return;
  146. TheWindowManager->winSendSystemMsg( window, GGM_SET_LABEL, (WindowMsgData)&text, 0 );
  147. } // end GadgetStaticTextSetText
  148. UnicodeString GadgetStaticTextGetText( GameWindow *window )
  149. {
  150. if(!window)
  151. return UnicodeString::TheEmptyString;
  152. TextData *tData = (TextData *)window->winGetUserData();
  153. if(!tData)
  154. return UnicodeString::TheEmptyString;
  155. return tData->text->getText();
  156. }
  157. // GadgetStaticTextSetFont ====================================================
  158. /** Set the font for a text control, we need to set the window
  159. * text font, the tooltip font, and the static text display strings for
  160. * the text data itself */
  161. //=============================================================================
  162. void GadgetStaticTextSetFont( GameWindow *g, GameFont *font )
  163. {
  164. TextData *textData = (TextData *)g->winGetUserData();
  165. DisplayString *dString;
  166. // set the font for the display strings all windows have
  167. dString = g->winGetInstanceData()->getTextDisplayString();
  168. if( dString )
  169. dString->setFont( font );
  170. dString = g->winGetInstanceData()->getTooltipDisplayString();
  171. if( dString )
  172. dString->setFont( font );
  173. // static text specific
  174. if( textData )
  175. {
  176. dString = textData->text;
  177. if( dString )
  178. dString->setFont( font );
  179. } // end if
  180. } // end GadgetStaticTextSetFont