GadgetComboBox.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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: GadgetComboBox.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: ListBox.cpp
  36. //
  37. // Created: Dean Iverson, March 1998
  38. // Colin Day, June 2001
  39. //
  40. // Desc: ListBox GUI control
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  46. // USER INCLUDES //////////////////////////////////////////////////////////////
  47. #include "Common/Language.h"
  48. #include "Common/AudioEventRTS.h"
  49. #include "Common/GameAudio.h"
  50. #include "Common/Debug.h"
  51. #include "GameClient/DisplayStringManager.h"
  52. #include "GameClient/GameWindow.h"
  53. #include "GameClient/Gadget.h"
  54. #include "GameClient/GameWindowManager.h"
  55. #include "GameClient/GadgetListBox.h"
  56. #include "GameClient/GadgetComboBox.h"
  57. #include "GameClient/GadgetTextEntry.h"
  58. #include "GameClient/GadgetPushButton.h"
  59. #include "GameClient/GadgetSlider.h"
  60. #include "GameClient/GameWindowGlobal.h"
  61. // DEFINES ////////////////////////////////////////////////////////////////////
  62. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  63. ///////////////////////////////////////////////////////////////////////////////
  64. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  65. ///////////////////////////////////////////////////////////////////////////////
  66. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  67. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  68. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  69. ///////////////////////////////////////////////////////////////////////////////
  70. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  71. ///////////////////////////////////////////////////////////////////////////////
  72. void HideListBox(GameWindow * window);
  73. // GadgetComboBoxInput =========================================================
  74. /** Handle input for Combo box */
  75. //=============================================================================
  76. WindowMsgHandledType GadgetComboBoxInput( GameWindow *window, UnsignedInt msg,
  77. WindowMsgData mData1, WindowMsgData mData2 )
  78. {
  79. // ComboBoxData *combo = (ComboBoxData *)window->winGetUserData();
  80. WinInstanceData *instData = window->winGetInstanceData();
  81. GameWindow *editBox = GadgetComboBoxGetEditBox(window);
  82. switch (msg)
  83. {
  84. // ------------------------------------------------------------------------
  85. case GWM_CHAR:
  86. {
  87. switch (mData1)
  88. {
  89. // --------------------------------------------------------------------
  90. case KEY_DOWN:
  91. case KEY_RIGHT:
  92. case KEY_TAB:
  93. if( BitTest( mData2, KEY_STATE_DOWN ) )
  94. TheWindowManager->winNextTab(window);
  95. break;
  96. // --------------------------------------------------------------------
  97. case KEY_UP:
  98. case KEY_LEFT:
  99. if( BitTest( mData2, KEY_STATE_DOWN ) )
  100. TheWindowManager->winPrevTab(window);
  101. break;
  102. // --------------------------------------------------------------------
  103. default:
  104. return TheWindowManager->winSendInputMsg( editBox, GWM_CHAR, mData1, mData2 );
  105. } // end switch( mData1 )
  106. break;
  107. } // end case char
  108. // ------------------------------------------------------------------------
  109. case GWM_WHEEL_DOWN:
  110. {
  111. break;
  112. } // end wheel down
  113. // ------------------------------------------------------------------------
  114. case GWM_WHEEL_UP:
  115. {
  116. break;
  117. } // end wheel up
  118. // ------------------------------------------------------------------------
  119. case GWM_LEFT_UP:
  120. {
  121. ComboBoxData *comboData = (ComboBoxData *)window->winGetUserData();
  122. ICoord2D winSize;
  123. //ICoord2D winPosition;
  124. ICoord2D newSize;
  125. Int listX =0;
  126. Int multiplier;
  127. comboData->dontHide = FALSE;
  128. AudioEventRTS buttonClick("GUIClick");
  129. if( TheAudio )
  130. {
  131. TheAudio->addAudioEvent( &buttonClick );
  132. } // end if
  133. GameWindow *listBox = GadgetComboBoxGetListBox(window);
  134. if (listBox)
  135. {
  136. TheWindowManager->winSetLoneWindow(window);
  137. // If the Listbox isn't showing, Show it.
  138. if(listBox->winIsHidden())
  139. {
  140. listBox->winHide(FALSE);
  141. window->winGetSize(&winSize.x, &winSize.y);
  142. WinInstanceData *listInstData = listBox->winGetInstanceData();
  143. ListboxData *listData = (ListboxData *)listBox->winGetUserData();
  144. // If we have less entries then our max display is set to, only show
  145. // those entries and not additional blank lines. Also, just so it looks
  146. // pretty, hide the list box's sliders if we don't need to scroll.
  147. if(comboData->entryCount <= comboData->maxDisplay)
  148. {
  149. multiplier = comboData->entryCount;
  150. listX = winSize.x;// + 16;
  151. if(listData->upButton)
  152. listData->upButton->winHide(TRUE);
  153. if(listData->downButton)
  154. listData->downButton->winHide(TRUE);
  155. if(listData->slider)
  156. listData->slider->winHide(TRUE);
  157. }
  158. else
  159. {
  160. multiplier = comboData->maxDisplay;
  161. listX = winSize.x;
  162. if(listData->upButton)
  163. listData->upButton->winHide(FALSE);
  164. if(listData->downButton)
  165. listData->downButton->winHide(FALSE);
  166. if(listData->slider)
  167. listData->slider->winHide(FALSE);
  168. }
  169. newSize.y = ((TheWindowManager->winFontHeight( listInstData->getFont() ) ) * multiplier) + multiplier * 2 + 4;
  170. window->winSetSize(winSize.x , winSize.y + newSize.y );
  171. listBox->winSetPosition(0, winSize.y);
  172. listBox->winSetSize(listX , newSize.y);
  173. }
  174. // if the Listbox was showing, hide it.
  175. else
  176. {
  177. HideListBox(window);
  178. }
  179. } break;
  180. } // end left click, left up
  181. // ------------------------------------------------------------------------
  182. case GWM_RIGHT_UP:
  183. {
  184. break;
  185. } // end right up, right click
  186. /*
  187. // ------------------------------------------------------------------------
  188. case GWM_MOUSE_ENTERING:
  189. {
  190. if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
  191. {
  192. BitSet( instData->m_state, WIN_STATE_HILITED );
  193. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  194. GBM_MOUSE_ENTERING,
  195. (WindowMsgData)window,
  196. 0 );
  197. TheWindowManager->winSetFocus( window );
  198. } // end if
  199. break;
  200. } // end mouse entering
  201. // ------------------------------------------------------------------------
  202. case GWM_MOUSE_LEAVING:
  203. {
  204. if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ))
  205. {
  206. BitClear( instData->m_state, WIN_STATE_HILITED );
  207. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  208. GBM_MOUSE_LEAVING,
  209. (WindowMsgData)window,
  210. 0 );
  211. } // end if
  212. break;
  213. } // end mouse leaving
  214. */
  215. // ------------------------------------------------------------------------
  216. case GWM_LEFT_DRAG:
  217. if (BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
  218. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  219. GGM_LEFT_DRAG,
  220. (WindowMsgData)window,
  221. 0 );
  222. break;
  223. // ------------------------------------------------------------------------
  224. // case GWM_LEFT_DOWN:
  225. // we want to eat the down... so we may receive the up.
  226. // return MSG_HANDLED;
  227. //-------------------------------------------------------------------------
  228. default:
  229. return MSG_IGNORED;
  230. } // end switch msg
  231. return MSG_HANDLED;
  232. } // end GadgetComboBoxInput
  233. // HideListBox ================================================================
  234. /** Called to close the listbox if it is opened */
  235. //=============================================================================
  236. void HideListBox(GameWindow * window)
  237. {
  238. ICoord2D winSize;
  239. ICoord2D newSize;
  240. GameWindow *listBox = GadgetComboBoxGetListBox(window);
  241. if (!listBox)
  242. return;
  243. if(!listBox->winIsHidden())
  244. {
  245. listBox->winHide(TRUE);
  246. GameWindow *editBox = GadgetComboBoxGetEditBox(window);
  247. editBox->winGetSize(&winSize.x, &winSize.y);
  248. window->winGetSize(&newSize.x, &newSize.y);
  249. window->winSetSize(newSize.x, winSize.y );
  250. }
  251. }
  252. // GadgetListBoxSystem ========================================================
  253. /** Handle system messages for list box */
  254. //=============================================================================
  255. WindowMsgHandledType GadgetComboBoxSystem( GameWindow *window, UnsignedInt msg,
  256. WindowMsgData mData1, WindowMsgData mData2 )
  257. {
  258. // ListboxData *list = (ListboxData *)window->winGetUserData();
  259. WinInstanceData *instData = window->winGetInstanceData();
  260. ComboBoxData *comboData = (ComboBoxData *)window->winGetUserData();
  261. switch( msg )
  262. {
  263. // ------------------------------------------------------------------------
  264. case GGM_SET_LABEL:
  265. {
  266. instData->setText(*(UnicodeString*)mData1);
  267. break;
  268. } // end set lavel
  269. // ------------------------------------------------------------------------
  270. case GCM_GET_TEXT:
  271. {
  272. if(comboData->editBox)
  273. *(UnicodeString*)mData2 = GadgetTextEntryGetText(comboData->editBox);
  274. break;
  275. } // end Get text
  276. // ------------------------------------------------------------------------
  277. case GCM_SET_TEXT:
  278. {
  279. if (comboData->editBox)
  280. GadgetTextEntrySetText(comboData->editBox,*(const UnicodeString*)mData1);
  281. break;
  282. } // end set text
  283. case GEM_UPDATE_TEXT:
  284. {
  285. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  286. GCM_UPDATE_TEXT,
  287. (WindowMsgData)window,
  288. 0 );
  289. if (comboData->listBox)
  290. {
  291. GadgetListBoxSetSelected(comboData->listBox, -1);
  292. HideListBox(window);
  293. }
  294. break;
  295. }
  296. // ------------------------------------------------------------------------
  297. // if we get sent an edit done message from the text box, lets notify the parent
  298. case GEM_EDIT_DONE:
  299. {
  300. if ((GameWindow *)mData1 == comboData->editBox)
  301. {
  302. HideListBox(window);
  303. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  304. GCM_SELECTED,
  305. (WindowMsgData)window,
  306. 0 );
  307. }
  308. break;
  309. }
  310. // ------------------------------------------------------------------------
  311. // Set the selection in the listbox, this will trigger the listbox selected message
  312. // which will set the edit box.
  313. case GCM_SET_SELECTION:
  314. {
  315. GameWindow *listBox = GadgetComboBoxGetListBox(window);
  316. if(listBox)
  317. {
  318. if( !listBox->winIsHidden() && mData2 == TRUE )
  319. comboData->dontHide = TRUE;
  320. GadgetListBoxSetSelected(listBox, (Int)mData1);
  321. }
  322. break;
  323. }
  324. // ------------------------------------------------------------------------
  325. // Get what the listbox has selected.
  326. case GCM_GET_SELECTION:
  327. {
  328. if(comboData->listBox)
  329. GadgetListBoxGetSelected(comboData->listBox, (Int *)mData2);
  330. else
  331. {
  332. DEBUG_ASSERTCRASH(0,("We don't have a listbox as part of the combo box"));
  333. *(Int *)mData2 = -1;
  334. }
  335. break;
  336. } //case GCM_GET_SELECTION:
  337. // ------------------------------------------------------------------------
  338. // Set the User Data for the specified listbox element
  339. case GCM_SET_ITEM_DATA:
  340. {
  341. if(comboData->listBox)
  342. {
  343. GadgetListBoxSetItemData(comboData->listBox, (void *)mData2, (Int)mData1 );
  344. }
  345. break;
  346. }
  347. // ------------------------------------------------------------------------
  348. // Get the user Data for the specified listbox element
  349. case GCM_GET_ITEM_DATA:
  350. {
  351. if(comboData->listBox)
  352. {
  353. *(void **)mData2 = GadgetListBoxGetItemData(comboData->listBox, (Int) mData1, 0);
  354. }
  355. break;
  356. }
  357. // ------------------------------------------------------------------------
  358. // Pass onto the parent window the selection the listbox just made
  359. case GLM_SELECTED:
  360. {
  361. if((GameWindow *) mData1 == comboData->listBox)
  362. {
  363. if( comboData->dontHide == TRUE )
  364. {
  365. comboData->dontHide = FALSE;
  366. }
  367. else
  368. HideListBox(window);
  369. // Nothing was actually selected, so we just want to
  370. if( mData2 == -1)
  371. {
  372. break;
  373. }
  374. //Grab the text that was selected
  375. UnicodeString tempUString;
  376. Color color;
  377. tempUString = GadgetListBoxGetTextAndColor( comboData->listBox, &color, mData2, 0 );
  378. GadgetTextEntrySetTextColor(comboData->editBox, color);
  379. GadgetTextEntrySetText(comboData->editBox, tempUString);
  380. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  381. GCM_SELECTED,
  382. (WindowMsgData)window,
  383. 0 );
  384. }
  385. break;
  386. }
  387. // ------------------------------------------------------------------------
  388. case GGM_LEFT_DRAG:
  389. {
  390. break;
  391. } // end left drag
  392. // ------------------------------------------------------------------------
  393. case GCM_DEL_ALL:
  394. {
  395. if ( comboData->listBox )
  396. GadgetListBoxReset(comboData->listBox);
  397. if ( comboData->editBox )
  398. GadgetTextEntrySetText(comboData->editBox, UnicodeString.TheEmptyString );
  399. comboData->entryCount = 0;
  400. //HideListBox(window);
  401. break;
  402. } // end delete all
  403. // ------------------------------------------------------------------------
  404. case GCM_DEL_ENTRY:
  405. {
  406. break;
  407. } // end delete entry
  408. // ------------------------------------------------------------------------
  409. case GGM_CLOSE:
  410. {
  411. HideListBox(window);
  412. break;
  413. } // end delete entry
  414. // ------------------------------------------------------------------------
  415. case GCM_ADD_ENTRY:
  416. {
  417. GameWindow *listBox = GadgetComboBoxGetListBox(window);
  418. ListboxData *listData = (ListboxData *)listBox->winGetUserData();
  419. Int addedIndex = -1;
  420. if( listBox )
  421. {
  422. //Increase our internal entry count
  423. comboData->entryCount++;
  424. //If we've exceeded the set listlength, resize it to twice the size
  425. if(comboData->entryCount >= listData->listLength)
  426. GadgetListBoxSetListLength(listBox,listData->listLength * 2);
  427. //Add the entry to the Listbox
  428. addedIndex = GadgetListBoxAddEntryText( listBox, *(UnicodeString*)mData1, mData2, -1, 0 );
  429. // Now resize the list box
  430. ICoord2D winSize;
  431. ICoord2D newSize;
  432. ICoord2D editBoxSize;
  433. Int listX;
  434. Int multiplier;
  435. WinInstanceData *listInstData = listBox->winGetInstanceData();
  436. GameWindow *editBox = GadgetComboBoxGetEditBox(window);
  437. window->winGetSize(&winSize.x, &winSize.y);
  438. editBox->winGetSize(&editBoxSize.x, &editBoxSize.y);
  439. // If the listbox has less entries then the MaxDisplay, size it smaller
  440. if(comboData->entryCount <= comboData->maxDisplay)
  441. {
  442. multiplier = comboData->entryCount;
  443. listX = winSize.x + 16;
  444. if(listData->upButton)
  445. listData->upButton->winHide(TRUE);
  446. if(listData->downButton)
  447. listData->downButton->winHide(TRUE);
  448. if(listData->slider)
  449. listData->slider->winHide(TRUE);
  450. }
  451. else
  452. {
  453. //Else size it to the MaxDisplay Size
  454. multiplier = comboData->maxDisplay;
  455. listX = winSize.x;
  456. if(listData->upButton)
  457. listData->upButton->winHide(FALSE);
  458. if(listData->downButton)
  459. listData->downButton->winHide(FALSE);
  460. if(listData->slider)
  461. listData->slider->winHide(FALSE);
  462. }
  463. newSize.y = ((TheWindowManager->winFontHeight( listInstData->getFont() ) ) * multiplier) + multiplier * 2 + 4;
  464. listBox->winSetPosition(0, editBoxSize.y);
  465. listBox->winSetSize(listX , newSize.y);
  466. }
  467. return( (WindowMsgHandledType) addedIndex );
  468. } // end add entry
  469. // ------------------------------------------------------------------------
  470. case GWM_CREATE:
  471. break;
  472. // ------------------------------------------------------------------------
  473. case GGM_RESIZED:
  474. {
  475. Int width = (Int)mData1;
  476. Int height = (Int)mData2;
  477. ICoord2D dropDownSize;
  478. // get needed window sizes
  479. comboData->dropDownButton->winGetSize( &dropDownSize.x, &dropDownSize.y );
  480. GameWindow *listBox = GadgetComboBoxGetListBox(window);
  481. if (listBox->winIsHidden())
  482. {
  483. if (listBox)
  484. listBox->winSetSize(width,height);
  485. if( comboData->dropDownButton )
  486. {
  487. comboData->dropDownButton->winSetPosition( width - dropDownSize.x, 0 );
  488. }
  489. if( comboData->editBox )
  490. {
  491. comboData->editBox->winSetPosition( 0, 0 );
  492. comboData->editBox->winSetSize( width - dropDownSize.x, height );
  493. }
  494. }
  495. break;
  496. } // end resized
  497. // ------------------------------------------------------------------------
  498. // ------------------------------------------------------------------------
  499. case GWM_DESTROY:
  500. {
  501. TheWindowManager->winSetLoneWindow(NULL); // if we are transitioning screens, close all combo boxes
  502. if (comboData)
  503. {
  504. delete(comboData);
  505. comboData = NULL;
  506. }
  507. break;
  508. } // end destroy
  509. // ------------------------------------------------------------------------
  510. case GWM_INPUT_FOCUS:
  511. {
  512. // If we're losing focus
  513. if( mData1 == FALSE )
  514. {
  515. BitClear( instData->m_state, WIN_STATE_HILITED );
  516. }
  517. else
  518. {
  519. BitSet( instData->m_state, WIN_STATE_HILITED );
  520. }
  521. TheWindowManager->winSendSystemMsg( window->winGetOwner(),
  522. GGM_FOCUS_CHANGE,
  523. mData1,
  524. window->winGetWindowId() );
  525. Bool wantsFocus = FALSE;
  526. GameWindow *editBox = GadgetComboBoxGetEditBox(window);
  527. // we need to tell the text entry box to take the focus.
  528. TheWindowManager->winSendSystemMsg( editBox, GWM_INPUT_FOCUS, mData1, (WindowMsgData)&wantsFocus );
  529. *(Bool*)mData2 = TRUE;
  530. break;
  531. } // end input focus
  532. case GBM_SELECTED:
  533. {
  534. // See if the drop down button was selected
  535. if( (GameWindow *)mData1 == comboData->dropDownButton )
  536. {
  537. ICoord2D winSize;
  538. //ICoord2D winPosition;
  539. ICoord2D newSize;
  540. Int listX =0;
  541. Int multiplier;
  542. comboData->dontHide = FALSE;
  543. GameWindow *listBox = GadgetComboBoxGetListBox(window);
  544. if (listBox)
  545. {
  546. TheWindowManager->winSetLoneWindow(window);
  547. // If the Listbox isn't showing, Show it.
  548. if(listBox->winIsHidden())
  549. {
  550. listBox->winHide(FALSE);
  551. window->winGetSize(&winSize.x, &winSize.y);
  552. WinInstanceData *listInstData = listBox->winGetInstanceData();
  553. ListboxData *listData = (ListboxData *)listBox->winGetUserData();
  554. // If we have less entries then our max display is set to, only show
  555. // those entries and not additional blank lines. Also, just so it looks
  556. // pretty, hide the list box's sliders if we don't need to scroll.
  557. if(comboData->entryCount <= comboData->maxDisplay)
  558. {
  559. multiplier = comboData->entryCount;
  560. listX = winSize.x;// + 16;
  561. if(listData->upButton)
  562. listData->upButton->winHide(TRUE);
  563. if(listData->downButton)
  564. listData->downButton->winHide(TRUE);
  565. if(listData->slider)
  566. listData->slider->winHide(TRUE);
  567. }
  568. else
  569. {
  570. multiplier = comboData->maxDisplay;
  571. listX = winSize.x;
  572. if(listData->upButton)
  573. listData->upButton->winHide(FALSE);
  574. if(listData->downButton)
  575. listData->downButton->winHide(FALSE);
  576. if(listData->slider)
  577. listData->slider->winHide(FALSE);
  578. }
  579. newSize.y = ((TheWindowManager->winFontHeight( listInstData->getFont() ) ) * multiplier) + multiplier * 2 + 4;
  580. window->winSetSize(winSize.x , winSize.y + newSize.y );
  581. listBox->winSetPosition(0, winSize.y);
  582. listBox->winSetSize(listX , newSize.y);
  583. }
  584. // if the Listbox was showing, hide it.
  585. else
  586. {
  587. HideListBox(window);
  588. }
  589. }
  590. }
  591. break;
  592. }
  593. default:
  594. return MSG_IGNORED;
  595. } // end switch( msg )
  596. return MSG_HANDLED;
  597. } // end GadgetListBoxSystem
  598. // GadgetComboBoxSetColors ====================================================
  599. /** Set the colors for a Combo box, note that this will also automatically
  600. * change the colors of any attached slider, slider thumb, and slider
  601. * buttons */
  602. //=============================================================================
  603. void GadgetComboBoxSetColors( GameWindow *comboBox,
  604. Color enabledColor,
  605. Color enabledBorderColor,
  606. Color enabledSelectedItemColor,
  607. Color enabledSelectedItemBorderColor,
  608. Color disabledColor,
  609. Color disabledBorderColor,
  610. Color disabledSelectedItemColor,
  611. Color disabledSelectedItemBorderColor,
  612. Color hiliteColor,
  613. Color hiliteBorderColor,
  614. Color hiliteSelectedItemColor,
  615. Color hiliteSelectedItemBorderColor )
  616. {
  617. // ComboBoxData *comboBoxData = (ComboBoxData *)comboBox->winGetUserData();
  618. // enabled
  619. // enabled
  620. GadgetComboBoxSetEnabledColor( comboBox, enabledColor);
  621. GadgetComboBoxSetEnabledBorderColor( comboBox, enabledBorderColor );
  622. GadgetComboBoxSetEnabledSelectedItemColor( comboBox, enabledSelectedItemColor );
  623. GadgetComboBoxSetEnabledSelectedItemBorderColor( comboBox, enabledSelectedItemBorderColor );
  624. // disabled
  625. GadgetComboBoxSetDisabledColor( comboBox, disabledColor );
  626. GadgetComboBoxSetDisabledBorderColor( comboBox, disabledBorderColor );
  627. GadgetComboBoxSetDisabledSelectedItemColor( comboBox, disabledSelectedItemColor );
  628. GadgetComboBoxSetDisabledSelectedItemBorderColor( comboBox, disabledSelectedItemBorderColor );
  629. // hilite
  630. GadgetComboBoxSetHiliteColor( comboBox, hiliteColor );
  631. GadgetComboBoxSetHiliteBorderColor( comboBox,hiliteBorderColor );
  632. GadgetComboBoxSetHiliteSelectedItemColor( comboBox, hiliteSelectedItemColor );
  633. GadgetComboBoxSetHiliteSelectedItemBorderColor( comboBox, hiliteSelectedItemBorderColor );
  634. GameWindow *editBox = GadgetComboBoxGetEditBox(comboBox);
  635. if (editBox)
  636. {
  637. // enabled
  638. GadgetButtonSetEnabledColor( editBox, enabledColor );
  639. GadgetButtonSetEnabledBorderColor( editBox, enabledBorderColor );
  640. GadgetButtonSetEnabledSelectedColor( editBox, enabledSelectedItemColor );
  641. GadgetButtonSetEnabledSelectedBorderColor( editBox, enabledSelectedItemBorderColor );
  642. // disabled
  643. GadgetButtonSetDisabledColor( editBox, disabledColor );
  644. GadgetButtonSetDisabledBorderColor( editBox, disabledBorderColor );
  645. GadgetButtonSetDisabledSelectedColor( editBox, disabledSelectedItemColor );
  646. GadgetButtonSetDisabledSelectedBorderColor( editBox, disabledSelectedItemBorderColor );
  647. // hilite
  648. GadgetButtonSetHiliteColor( editBox,hiliteColor );
  649. GadgetButtonSetHiliteBorderColor( editBox, hiliteBorderColor );
  650. GadgetButtonSetHiliteSelectedColor( editBox, hiliteSelectedItemColor );
  651. GadgetButtonSetHiliteSelectedBorderColor( editBox, hiliteSelectedItemBorderColor );
  652. }
  653. GameWindow *dropDownButton = GadgetComboBoxGetDropDownButton(comboBox);
  654. if (dropDownButton)
  655. {
  656. // enabled
  657. GadgetButtonSetEnabledColor( dropDownButton, enabledColor );
  658. GadgetButtonSetEnabledBorderColor( dropDownButton, enabledBorderColor );
  659. GadgetButtonSetEnabledSelectedColor( dropDownButton, enabledSelectedItemColor );
  660. GadgetButtonSetEnabledSelectedBorderColor( dropDownButton, enabledSelectedItemBorderColor );
  661. // disabled
  662. GadgetButtonSetDisabledColor( dropDownButton, disabledColor );
  663. GadgetButtonSetDisabledBorderColor( dropDownButton, disabledBorderColor );
  664. GadgetButtonSetDisabledSelectedColor( dropDownButton, disabledSelectedItemColor );
  665. GadgetButtonSetDisabledSelectedBorderColor( dropDownButton, disabledSelectedItemBorderColor );
  666. // hilite
  667. GadgetButtonSetHiliteColor( dropDownButton,hiliteColor );
  668. GadgetButtonSetHiliteBorderColor( dropDownButton, hiliteBorderColor );
  669. GadgetButtonSetHiliteSelectedColor( dropDownButton, hiliteSelectedItemColor );
  670. GadgetButtonSetHiliteSelectedBorderColor( dropDownButton, hiliteSelectedItemBorderColor );
  671. }
  672. GameWindow * listBox = GadgetComboBoxGetListBox( comboBox );
  673. if ( listBox )
  674. {
  675. GadgetListBoxSetColors(listBox,
  676. enabledColor,
  677. enabledBorderColor,
  678. enabledSelectedItemColor,
  679. enabledSelectedItemBorderColor,
  680. disabledColor,
  681. disabledBorderColor,
  682. disabledSelectedItemColor,
  683. disabledSelectedItemBorderColor,
  684. hiliteColor,
  685. hiliteBorderColor,
  686. hiliteSelectedItemColor,
  687. hiliteSelectedItemBorderColor );
  688. }
  689. } // end GadgetComboBoxSetColors
  690. // GadgetComboBoxSetIsEditable ================================================
  691. /** Sets up the Text Entry gadget as editable or not */
  692. //=============================================================================
  693. void GadgetComboBoxSetIsEditable(GameWindow *comboBox, Bool isEditable )
  694. {
  695. ComboBoxData *comboData = (ComboBoxData *)comboBox->winGetUserData();
  696. GameWindow *editBox = GadgetComboBoxGetEditBox(comboBox);
  697. UnsignedInt status ;
  698. if(!editBox)
  699. return;
  700. comboData->isEditable = isEditable;
  701. if (isEditable)
  702. {
  703. status = editBox->winGetStatus();
  704. BitClear(status, WIN_STATUS_NO_INPUT);
  705. // BitClear(status, WIN_STATUS_NO_FOCUS);
  706. editBox->winSetStatus(status);
  707. }
  708. else
  709. {
  710. status = editBox->winGetStatus();
  711. BitSet(status, WIN_STATUS_NO_INPUT);
  712. // BitSet(status, WIN_STATUS_NO_FOCUS);
  713. editBox->winSetStatus(status);
  714. }
  715. }//void GadgetComboBoxSetIsEditable(GameWindow *comboBox, Int maxChars )
  716. // GadgetComboBoxSetIsAsciiOnly ==================================================
  717. /** Get the text the Combo Box */
  718. //=============================================================================
  719. void GadgetComboBoxSetLettersAndNumbersOnly(GameWindow *comboBox, Bool isLettersAndNumbersOnly)
  720. {
  721. //sanity
  722. if(comboBox == NULL)
  723. return;
  724. ComboBoxData *comboData = (ComboBoxData *)comboBox->winGetUserData();
  725. comboData->lettersAndNumbersOnly = isLettersAndNumbersOnly;
  726. if(comboData->entryData)
  727. comboData->entryData->alphaNumericalOnly = isLettersAndNumbersOnly;
  728. }
  729. // GadgetComboBoxSetAsciiOnly ==================================================
  730. /** Get the text the Combo Box */
  731. //=============================================================================
  732. void GadgetComboBoxSetAsciiOnly(GameWindow *comboBox, Bool isAsciiOnly )
  733. {
  734. //sanity
  735. if(comboBox == NULL)
  736. return;
  737. ComboBoxData *comboData = (ComboBoxData *)comboBox->winGetUserData();
  738. comboData->asciiOnly = isAsciiOnly;
  739. if(comboData->entryData)
  740. comboData->entryData->aSCIIOnly = isAsciiOnly;
  741. }
  742. // GadgetComboBoxSetMaxChars ==================================================
  743. /** Get the text the Combo Box */
  744. //=============================================================================
  745. void GadgetComboBoxSetMaxChars( GameWindow *comboBox, Int maxChars )
  746. {
  747. //sanity
  748. if(comboBox == NULL)
  749. return;
  750. ComboBoxData *comboData = (ComboBoxData *)comboBox->winGetUserData();
  751. comboData->maxChars = maxChars;
  752. comboData->entryData->maxTextLen = maxChars;
  753. }//void GadgetComboBoxSetMaxChars( GameWindow *comboBox, Int maxChars )
  754. // GadgetComboBoxSetMaxDisplay ================================================
  755. /** Sets the MaxDisplay variable to the new Max Display */
  756. //=============================================================================
  757. void GadgetComboBoxSetMaxDisplay( GameWindow *comboBox, Int maxDisplay )
  758. {
  759. ComboBoxData *comboData = (ComboBoxData *)comboBox->winGetUserData();
  760. comboData->maxDisplay = maxDisplay;
  761. }//void GadgetComboBoxSetMaxDisplay( GameWindow *comboBox, Int maxDisplay );
  762. // GadgetComboBoxGetText =======================================================
  763. /** Get the text the Combo Box */
  764. //=============================================================================
  765. UnicodeString GadgetComboBoxGetText( GameWindow *comboBox )
  766. {
  767. // sanity
  768. if( comboBox == NULL )
  769. return UnicodeString::TheEmptyString;
  770. // verify that this is a combo box
  771. if( BitTest( comboBox->winGetStyle(), GWS_COMBO_BOX ) == FALSE )
  772. return UnicodeString::TheEmptyString;
  773. return GadgetTextEntryGetText( GadgetComboBoxGetEditBox(comboBox) );
  774. }
  775. // GadgetComboBoxSetText =======================================================
  776. /** Set the text the Combo Box */
  777. //=============================================================================
  778. void GadgetComboBoxSetText( GameWindow *comboBox, UnicodeString text )
  779. {
  780. if( comboBox == NULL )
  781. return;
  782. GadgetTextEntrySetText(GadgetComboBoxGetEditBox(comboBox), text);
  783. }
  784. // GadgetComboBoxAddEntry =======================================================
  785. /** Convenience wrapper function for adding an entry */
  786. //=============================================================================
  787. Int GadgetComboBoxAddEntry( GameWindow *comboBox, UnicodeString text, Color color )
  788. {
  789. // sanity
  790. if( comboBox == NULL )
  791. return -1;
  792. return (Int)TheWindowManager->winSendSystemMsg( comboBox, GCM_ADD_ENTRY, (WindowMsgData)&text, color );
  793. }
  794. // GadgetComboBoxReset =======================================================
  795. /** Convenience wrapper function for resetting the Combo Box entries */
  796. //=============================================================================
  797. void GadgetComboBoxReset( GameWindow *comboBox )
  798. {
  799. // sanity
  800. if( comboBox == NULL )
  801. return;
  802. // reset via system message
  803. TheWindowManager->winSendSystemMsg( comboBox, GCM_DEL_ALL, 0, 0 );
  804. }
  805. // GadgetComboBoxHideList =======================================================
  806. /** Convenience wrapper function hiding the list */
  807. //=============================================================================
  808. void GadgetComboBoxHideList( GameWindow *comboBox )
  809. {
  810. // sanity
  811. if( comboBox == NULL )
  812. return;
  813. // reset via system message
  814. TheWindowManager->winSendSystemMsg( comboBox, GGM_CLOSE, 0, 0 );
  815. }
  816. // GadgetComboBoxSetFont =======================================================
  817. /** Function used to set the Font of the combo box and all sub gadgets */
  818. //=============================================================================
  819. void GadgetComboBoxSetFont( GameWindow *comboBox, GameFont *font )
  820. {
  821. // sanity
  822. if( comboBox == NULL )
  823. return;
  824. // set the ListBox gadget's font
  825. GameWindow *listBox = GadgetComboBoxGetListBox(comboBox);
  826. if(listBox)
  827. listBox->winSetFont( font);
  828. // set the Text Entry gadget's font
  829. GameWindow *editBox = GadgetComboBoxGetEditBox(comboBox);
  830. if(editBox)
  831. editBox->winSetFont(font);
  832. //Need to setup the default window font
  833. DisplayString *dString;
  834. // set the font for the display strings all windows have
  835. dString = comboBox->winGetInstanceData()->getTextDisplayString();
  836. if( dString )
  837. dString->setFont( font );
  838. dString = comboBox->winGetInstanceData()->getTooltipDisplayString();
  839. if( dString )
  840. dString->setFont( font );
  841. }
  842. // GadgetComboBoxSetEnabledTextColors =========================================
  843. /** Set the Enabled Text Colors for the Sub Gadgets*/
  844. //=============================================================================
  845. void GadgetComboBoxSetEnabledTextColors(GameWindow *comboBox, Color color, Color borderColor )
  846. {
  847. // sanity
  848. if( comboBox == NULL )
  849. return;
  850. ComboBoxData *comboBoxData = (ComboBoxData *)comboBox->winGetUserData();
  851. if(comboBoxData->listBox)
  852. comboBoxData->listBox->winSetEnabledTextColors( color,borderColor);
  853. if(comboBoxData->editBox)
  854. comboBoxData->editBox->winSetEnabledTextColors(color,borderColor);
  855. }
  856. // GadgetComboBoxSetDisabledTextColors ========================================
  857. /** Set the Disabled Text Colors for the Sub Gadgets */
  858. //=============================================================================
  859. void GadgetComboBoxSetDisabledTextColors(GameWindow *comboBox, Color color, Color borderColor )
  860. {
  861. ComboBoxData *comboBoxData = (ComboBoxData *)comboBox->winGetUserData();
  862. // sanity
  863. if( comboBox == NULL )
  864. return;
  865. if(comboBoxData->listBox)
  866. comboBoxData->listBox->winSetDisabledTextColors( color,borderColor);
  867. if(comboBoxData->editBox)
  868. comboBoxData->editBox->winSetDisabledTextColors(color,borderColor);
  869. }
  870. // GadgetComboBoxSetHiliteTextColors ==========================================
  871. /** Set the Hilite Text Colors for the Sub Gadgets */
  872. //=============================================================================
  873. void GadgetComboBoxSetHiliteTextColors( GameWindow *comboBox,Color color, Color borderColor )
  874. {
  875. // sanity
  876. if( comboBox == NULL )
  877. return;
  878. ComboBoxData *comboBoxData = (ComboBoxData *)comboBox->winGetUserData();
  879. if(comboBoxData->listBox)
  880. comboBoxData->listBox->winSetHiliteTextColors( color,borderColor);
  881. if(comboBoxData->editBox)
  882. comboBoxData->editBox->winSetHiliteTextColors(color,borderColor);
  883. }
  884. // GadgetComboBoxSetIMECompositeTextColors ====================================
  885. /** Set the IME Composite Text Colors Text Colors for the Sub Gadgets */
  886. //=============================================================================
  887. void GadgetComboBoxSetIMECompositeTextColors(GameWindow *comboBox, Color color, Color borderColor )
  888. {
  889. // sanity
  890. if( comboBox == NULL )
  891. return;
  892. ComboBoxData *comboBoxData = (ComboBoxData *)comboBox->winGetUserData();
  893. if(comboBoxData->listBox)
  894. comboBoxData->listBox->winSetIMECompositeTextColors( color,borderColor);
  895. if(comboBoxData->editBox)
  896. comboBoxData->editBox->winSetIMECompositeTextColors(color,borderColor);
  897. }
  898. // GadgetComboBoxGetSelectedPos ===============================================
  899. /** Convenience wrapper function for getting the selected Position */
  900. //=============================================================================
  901. void GadgetComboBoxGetSelectedPos( GameWindow *comboBox, Int *selectedIndex )
  902. {
  903. // sanity
  904. if( comboBox == NULL )
  905. return;
  906. // get selected indeces via system message
  907. TheWindowManager->winSendSystemMsg( comboBox, GCM_GET_SELECTION, 0, (WindowMsgData)selectedIndex );
  908. }
  909. // GadgetComboBoxSetSelectedPos ===============================================
  910. /** Convenience wrapper function for setting the selected Position, if don't hide
  911. is set to true, the listbox won't be forced to hide when the Selected call is
  912. passed back */
  913. //=============================================================================
  914. void GadgetComboBoxSetSelectedPos( GameWindow *comboBox, Int selectedIndex, Bool dontHide )
  915. {
  916. // sanity
  917. if( comboBox == NULL )
  918. return;
  919. // get selected indeces via system message
  920. TheWindowManager->winSendSystemMsg( comboBox, GCM_SET_SELECTION, selectedIndex, dontHide );
  921. }
  922. // GadgetComboBoxSetItemData ==================================================
  923. /** Convenience wrapper function for setting the Item data for the listbox under the combo box */
  924. //=============================================================================
  925. void GadgetComboBoxSetItemData( GameWindow *comboBox, Int index, void *data )
  926. {
  927. if (comboBox)
  928. TheWindowManager->winSendSystemMsg( comboBox, GCM_SET_ITEM_DATA, index, (WindowMsgData)data);
  929. }
  930. // GadgetComboBoxGetItemData ==================================================
  931. /** Convenience wrapper function for getting the Item data from the listbox under the combo Box */
  932. //=============================================================================
  933. void *GadgetComboBoxGetItemData( GameWindow *comboBox, Int index )
  934. {
  935. void *data = NULL;
  936. if (comboBox)
  937. {
  938. TheWindowManager->winSendSystemMsg( comboBox, GCM_GET_ITEM_DATA, index, (WindowMsgData)&data);
  939. }
  940. return (data);
  941. }
  942. // GadgetComboBoxGetLength =================================================
  943. /** Get the list length data contained in the listboxData
  944. * parameter. */
  945. //=============================================================================
  946. Int GadgetComboBoxGetLength( GameWindow *combobox )
  947. {
  948. ComboBoxData *comboboxData = (ComboBoxData *)combobox->winGetUserData();
  949. if (comboboxData)
  950. return comboboxData->entryCount;
  951. return 0;
  952. } // end GadgetListBoxGetListLength