LIST.CPP 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/LIST.CPP 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : LIST.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 01/15/95 *
  26. * *
  27. * Last Update : January 23, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * ListClass::Add -- This object adds itself to the given list *
  32. * ListClass::Add_Head -- This gadget makes itself the head of the given list. *
  33. * ListClass::Add_Item -- Adds a text item (as number) to the list box. *
  34. * ListClass::Add_Item -- Adds an item to the list box. *
  35. * ListClass::Add_Scroll_Bar -- Adds a scroll bar to the list box. *
  36. * ListClass::Add_Tail -- Add myself to the end of the given list. *
  37. * ListClass::Bump -- Bumps the list box up/down one "page". *
  38. * ListClass::Current_Index -- Fetches the current selected index. *
  39. * ListClass::Current_Item -- Fetches pointer to current item string. *
  40. * ListClass::Draw_Entry -- Draws a list box text line as indicated. *
  41. * ListClass::Draw_Me -- Draws the listbox. *
  42. * ListClass::Get_Item -- Fetches an arbitrary item string. *
  43. * ListClass::Peer_To_Peer -- A peer gadget was touched -- make adjustments. *
  44. * ListClass::Remove -- Removes the specified object from the list. *
  45. * ListClass::Remove_Item -- Remove specified text from list box. *
  46. * ListClass::Remove_Scroll_Bar -- Removes the scroll bar if present *
  47. * ListClass::Set_Selected_Index -- Set the top of the listbox to index specified. *
  48. * ListClass::Set_Tabs -- Sets the tab stop list to be used for text printing. *
  49. * ListClass::Set_View_Index -- Sets the top line for the current list view. *
  50. * ListClass::Step -- Moves the list view one line in direction specified. *
  51. * ListClass::Step_Selected_Index -- Change the listbox top line in direction specified. *
  52. * ListClass::~ListClass -- Destructor for list class objects. *
  53. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  54. #include "function.h"
  55. /***************************************************************************
  56. * ListClass::ListClass -- class constructor *
  57. * *
  58. * INPUT: id button ID *
  59. * *
  60. * x,y upper-left corner, in pixels *
  61. * *
  62. * w,h width, height, in pixels *
  63. * *
  64. * list ptr to array of char strings to list*
  65. * *
  66. * flags, style flags for mouse, style of listbox *
  67. * *
  68. * OUTPUT: none. *
  69. * *
  70. * WARNINGS: none. *
  71. * *
  72. * HISTORY: 01/05/1995 MML : Created. *
  73. *=========================================================================*/
  74. ListClass::ListClass (int id, int x, int y, int w, int h, TextPrintType flags, void const * up, void const * down) :
  75. ControlClass(id, x, y, w, h, LEFTPRESS | LEFTRELEASE | KEYBOARD, false),
  76. UpGadget(0, up, x+w, y),
  77. DownGadget(0, down, x+w, y+h),
  78. ScrollGadget(0, x+w, y, 0, h, true)
  79. {
  80. /*
  81. ** Set preliminary values for the slider related gadgets. They don't automatically
  82. ** appear at this time, but there are some values that can be pre-filled in.
  83. */
  84. UpGadget.X -= UpGadget.Width;
  85. DownGadget.X -= DownGadget.Width;
  86. DownGadget.Y -= DownGadget.Height;
  87. ScrollGadget.X -= max(UpGadget.Width, DownGadget.Width);
  88. ScrollGadget.Y = Y+UpGadget.Height;
  89. ScrollGadget.Height -= UpGadget.Height + DownGadget.Height;
  90. ScrollGadget.Width = max(UpGadget.Width, DownGadget.Width);
  91. /*
  92. ** Set the list box to a default state.
  93. */
  94. TextFlags = flags;
  95. IsScrollActive = false;
  96. Tabs = 0;
  97. SelectedIndex = 0;
  98. CurrentTopIndex = 0;
  99. //PG_TO_FIX
  100. //Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TextFlags);
  101. LineHeight = FontHeight+FontYSpacing-1;
  102. LineCount = (h-1) / LineHeight;
  103. }
  104. ListClass::ListClass(ListClass const & list) :
  105. ControlClass(list),
  106. TextFlags(list.TextFlags),
  107. Tabs(list.Tabs),
  108. List(list.List),
  109. LineHeight(list.LineHeight),
  110. LineCount(list.LineCount),
  111. IsScrollActive(list.IsScrollActive),
  112. UpGadget(list.UpGadget),
  113. DownGadget(list.DownGadget),
  114. ScrollGadget(list.ScrollGadget),
  115. SelectedIndex(list.SelectedIndex),
  116. CurrentTopIndex(list.CurrentTopIndex)
  117. {
  118. UpGadget.Make_Peer(*this);
  119. DownGadget.Make_Peer(*this);
  120. ScrollGadget.Make_Peer(*this);
  121. }
  122. void ListClass::Set_Position(int x, int y)
  123. {
  124. UpGadget.X = x + Width - UpGadget.Width;
  125. UpGadget.Y = y;
  126. DownGadget.X = x + Width - DownGadget.Width;
  127. DownGadget.Y = y + Height - DownGadget.Height;
  128. ScrollGadget.X = x + Width - max(UpGadget.Width, DownGadget.Width);
  129. ScrollGadget.Y = y + UpGadget.Height;
  130. ScrollGadget.Height = Height - (UpGadget.Height + DownGadget.Height);
  131. ScrollGadget.Width = max(UpGadget.Width, DownGadget.Width);
  132. }
  133. /***********************************************************************************************
  134. * ListClass::~ListClass -- Destructor for list class objects. *
  135. * *
  136. * This is the destructor for list objects. It handles removing anything it might have *
  137. * allocated. This is typically the scroll bar. *
  138. * *
  139. * INPUT: none *
  140. * OUTPUT: none *
  141. * WARNINGS: none *
  142. * HISTORY: 01/16/1995 JLB : Created. *
  143. *=============================================================================================*/
  144. ListClass::~ListClass(void)
  145. {
  146. Remove_Scroll_Bar();
  147. }
  148. /***********************************************************************************************
  149. * ListClass::Add_Item -- Adds an item to the list box. *
  150. * *
  151. * This will add the specified string to the list box. The string is added to the end *
  152. * of the list. *
  153. * *
  154. * INPUT: text -- Pointer to the string to add to the list box. *
  155. * OUTPUT: none *
  156. * WARNINGS: none *
  157. * HISTORY: 01/15/1995 JLB : Created. *
  158. *=============================================================================================*/
  159. int ListClass::Add_Item(char const * text)
  160. {
  161. if (text) {
  162. List.Add(text);
  163. Flag_To_Redraw();
  164. /*
  165. ** Add scroll gadget if the list gets too large to display all of the items
  166. ** at the same time.
  167. */
  168. if (List.Count() > LineCount) {
  169. Add_Scroll_Bar();
  170. }
  171. /*
  172. ** Tell the slider that there is one more entry in the list.
  173. */
  174. if (IsScrollActive) {
  175. ScrollGadget.Set_Maximum(List.Count());
  176. }
  177. }
  178. return(List.Count() - 1);
  179. }
  180. /***********************************************************************************************
  181. * ListClass::Add_Item -- Adds a text item (as number) to the list box. *
  182. * *
  183. * This will add the text as specified by the text number provided, to the list box. *
  184. * The string is added to the end of the list. *
  185. * *
  186. * INPUT: text -- The text number for the string to add to the list box. *
  187. * OUTPUT: none *
  188. * WARNINGS: Once a string is added to the list box in this fashion, there is no method of *
  189. * retrieving the text number as it relates to any particular index in the list. *
  190. * HISTORY: *
  191. * 01/15/1995 JLB : Created. *
  192. *=============================================================================================*/
  193. int ListClass::Add_Item(int text)
  194. {
  195. if (text != TXT_NONE) {
  196. Add_Item(Text_String(text));
  197. }
  198. return(List.Count() - 1);
  199. }
  200. void ListClass::Remove_Item(int index)
  201. {
  202. if (index < List.Count()) {
  203. List.Delete(index);
  204. /*
  205. ** If the list is now small enough to display completely within the list box region,
  206. ** then delete the slider gadget (if they are present).
  207. */
  208. if (List.Count() <= LineCount) {
  209. Remove_Scroll_Bar();
  210. }
  211. /*
  212. ** Tell the slider that there is one less entry in the list.
  213. */
  214. if (IsScrollActive) {
  215. ScrollGadget.Set_Maximum(List.Count());
  216. }
  217. /*
  218. ** If we just removed the selected entry, select the previous one
  219. */
  220. if (SelectedIndex >= List.Count()) {
  221. SelectedIndex--;
  222. if (SelectedIndex < 0) {
  223. SelectedIndex = 0;
  224. }
  225. }
  226. /*
  227. ** If we just removed the top-displayed entry, step up one item
  228. */
  229. if (CurrentTopIndex >= List.Count()) {
  230. CurrentTopIndex--;
  231. if (CurrentTopIndex < 0)
  232. CurrentTopIndex = 0;
  233. if (IsScrollActive)
  234. ScrollGadget.Step(1);
  235. }
  236. }
  237. }
  238. /***********************************************************************************************
  239. * ListClass::Remove_Item -- Remove specified text from list box. *
  240. * *
  241. * This routine will remove the specified text string from the list box. *
  242. * *
  243. * INPUT: text -- Pointer to the string to remove. *
  244. * *
  245. * OUTPUT: none *
  246. * *
  247. * WARNINGS: The text pointer passed into this routine MUST be the same text pointer that *
  248. * was used to add the string to the list. *
  249. * *
  250. * HISTORY: *
  251. * 01/15/1995 JLB : Created. *
  252. *=============================================================================================*/
  253. void ListClass::Remove_Item(char const * text)
  254. {
  255. if (text) {
  256. Remove_Item(List.ID(text));
  257. }
  258. }
  259. /***************************************************************************
  260. * ListClass::Action -- If clicked on, do this! *
  261. * *
  262. * INPUT: int flags -- combination of mouse flags indicating *
  263. * what action to take. *
  264. * *
  265. * OUTPUT: bool result. *
  266. * *
  267. * WARNINGS: none. *
  268. * *
  269. * HISTORY: 01/05/1995 MML : Created. *
  270. *=========================================================================*/
  271. int ListClass::Action(unsigned flags, KeyNumType & key)
  272. {
  273. if (flags & LEFTRELEASE) {
  274. key = KN_NONE;
  275. flags &= (~LEFTRELEASE);
  276. ControlClass::Action(flags, key);
  277. return(true);
  278. } else {
  279. /*
  280. ** Handle keyboard events here.
  281. */
  282. if (flags & KEYBOARD) {
  283. /*
  284. ** Process the keyboard character. If indicated, consume this keyboard event
  285. ** so that the edit gadget ID number is not returned.
  286. */
  287. if (key == KN_UP) {
  288. Step_Selected_Index(-1);
  289. key = KN_NONE;
  290. } else if (key == KN_DOWN) {
  291. Step_Selected_Index(1);
  292. key = KN_NONE;
  293. } else {
  294. flags &= ~KEYBOARD;
  295. }
  296. } else {
  297. int index = Get_Mouse_Y() - (Y+1);
  298. index = index / LineHeight;
  299. SelectedIndex = CurrentTopIndex + index;
  300. SelectedIndex = min(SelectedIndex, List.Count()-1);
  301. if (SelectedIndex == -1) SelectedIndex = 0;
  302. }
  303. }
  304. return(ControlClass::Action(flags, key));
  305. }
  306. /***********************************************************************************************
  307. * ListClass::Draw_Me -- Draws the listbox. *
  308. * *
  309. * This routine will render the listbox. *
  310. * *
  311. * INPUT: forced -- Should the listbox be redrawn even if it already thinks it doesn't *
  312. * need to be? This is true when something outside of the gadget system *
  313. * has trashed the screen. *
  314. * *
  315. * OUTPUT: Was the listbox redrawn? *
  316. * *
  317. * WARNINGS: none *
  318. * *
  319. * HISTORY: *
  320. * 06/25/1995 JLB : Created. *
  321. *=============================================================================================*/
  322. int ListClass::Draw_Me(int forced)
  323. {
  324. if (GadgetClass::Draw_Me(forced)) {
  325. /*
  326. ** Turn off the mouse.
  327. */
  328. if (LogicPage == &SeenBuff) {
  329. Conditional_Hide_Mouse(X, Y, X+Width, Y+Height);
  330. }
  331. Draw_Box (X, Y, Width, Height, BOXSTYLE_BOX, true);
  332. /*
  333. ** Draw List.
  334. */
  335. if (List.Count()) {
  336. for (int index = 0; index < LineCount; index++) {
  337. int line = CurrentTopIndex + index;
  338. if (List.Count() > line) {
  339. /*
  340. ** Prints the text and handles right edge clipping and tabs.
  341. */
  342. Draw_Entry(line, X+1, Y+(LineHeight*index)+1, Width-2, (line == SelectedIndex));
  343. }
  344. }
  345. }
  346. /*
  347. ** Turn on the mouse.
  348. */
  349. if (LogicPage == &SeenBuff) {
  350. Conditional_Show_Mouse();
  351. }
  352. return(true);
  353. }
  354. return(false);
  355. }
  356. /***********************************************************************************************
  357. * ListClass::Bump -- Bumps the list box up/down one "page". *
  358. * *
  359. * Use this routine to adjust the "page" that is being viewed in the list box. The view *
  360. * will move up or down (as specified) one page (screen full) of text strings. *
  361. * *
  362. * INPUT: up -- Should the adjustment be up? *
  363. * *
  364. * OUTPUT: none *
  365. * *
  366. * WARNINGS: none *
  367. * *
  368. * HISTORY: *
  369. * 01/15/1995 JLB : Created. *
  370. *=============================================================================================*/
  371. void ListClass::Bump(int up)
  372. {
  373. if (IsScrollActive) {
  374. if (ScrollGadget.Step(up)) {
  375. CurrentTopIndex = ScrollGadget.Get_Value();
  376. Flag_To_Redraw();
  377. }
  378. }
  379. }
  380. /***********************************************************************************************
  381. * ListClass::Step -- Moves the list view one line in direction specified. *
  382. * *
  383. * This routine will move the current view "page" one line in the direction specified. *
  384. * *
  385. * INPUT: up -- Should the view be moved upward? *
  386. * *
  387. * OUTPUT: none *
  388. * *
  389. * WARNINGS: none *
  390. * *
  391. * HISTORY: *
  392. * 01/15/1995 JLB : Created. *
  393. *=============================================================================================*/
  394. void ListClass::Step(int up)
  395. {
  396. if (IsScrollActive) {
  397. if (ScrollGadget.Step(up)) {
  398. CurrentTopIndex = ScrollGadget.Get_Value();
  399. Flag_To_Redraw();
  400. }
  401. }
  402. }
  403. /***********************************************************************************************
  404. * ListClass::Get_Item -- Fetches an arbitrary item string. *
  405. * *
  406. * This routine will fetch an item string from the list box. The item fetched can be any *
  407. * one of the ones in the list. *
  408. * *
  409. * INPUT: index -- The index to examine and return the text pointer from. *
  410. * *
  411. * OUTPUT: Returns with the text pointer to the string at the index position specified. *
  412. * *
  413. * WARNINGS: none *
  414. * *
  415. * HISTORY: *
  416. * 01/16/1995 JLB : Created. *
  417. *=============================================================================================*/
  418. char const * ListClass::Get_Item(int index) const
  419. {
  420. if (List.Count() == 0) {
  421. return NULL;
  422. }
  423. index = min(index, List.Count()-1);
  424. return(List[index]);
  425. }
  426. /***********************************************************************************************
  427. * ListClass::Current_Item -- Fetches pointer to current item string. *
  428. * *
  429. * This routine will fetch a pointer to the currently selected item's text. *
  430. * *
  431. * INPUT: none *
  432. * *
  433. * OUTPUT: Return with pointer to currently selected text. *
  434. * *
  435. * WARNINGS: none *
  436. * *
  437. * HISTORY: *
  438. * 01/16/1995 JLB : Created. *
  439. *=============================================================================================*/
  440. char const * ListClass::Current_Item(void) const
  441. {
  442. if (List.Count() <= SelectedIndex) {
  443. return(0);
  444. }
  445. return(List[SelectedIndex]);
  446. }
  447. /***********************************************************************************************
  448. * ListClass::Current_Index -- Fetches the current selected index. *
  449. * *
  450. * This routine will fetch the index number for the currently selected line. *
  451. * *
  452. * INPUT: none *
  453. * *
  454. * OUTPUT: Returns with the index of the currently selected line. This ranges from zero to *
  455. * the number of items in the list minus one. *
  456. * *
  457. * WARNINGS: none *
  458. * *
  459. * HISTORY: *
  460. * 01/16/1995 JLB : Created. *
  461. *=============================================================================================*/
  462. int ListClass::Current_Index(void) const
  463. {
  464. return(SelectedIndex);
  465. }
  466. /***********************************************************************************************
  467. * ListClass::Peer_To_Peer -- A peer gadget was touched -- make adjustments. *
  468. * *
  469. * This routine is called when one of the peer gadgets (the scroll arrows or the slider) *
  470. * was touched in some fashion. This routine will sort out whom and why and then make *
  471. * any necessary adjustments to the list box. *
  472. * *
  473. * INPUT: flags -- The event flags that affected the peer gadget. *
  474. * *
  475. * key -- The key value at the time of the event. *
  476. * *
  477. * whom -- Which gadget is being touched. *
  478. * *
  479. * OUTPUT: none *
  480. * *
  481. * WARNINGS: none *
  482. * *
  483. * HISTORY: *
  484. * 01/16/1995 JLB : Created. *
  485. *=============================================================================================*/
  486. void ListClass::Peer_To_Peer(unsigned flags, KeyNumType &, ControlClass & whom)
  487. {
  488. if (flags & LEFTRELEASE) {
  489. if (&whom == &UpGadget) {
  490. Step(true);
  491. }
  492. if (&whom == &DownGadget) {
  493. Step(false);
  494. }
  495. }
  496. /*
  497. ** The slider has changed, so reflect the current list position
  498. ** according to the slider setting.
  499. */
  500. if (&whom == &ScrollGadget) {
  501. Set_View_Index(ScrollGadget.Get_Value());
  502. }
  503. }
  504. /***********************************************************************************************
  505. * ListClass::Set_View_Index -- Sets the top line for the current list view. *
  506. * *
  507. * This routine is used to set the line that will be at the top of the list view. This is *
  508. * how the view can be scrolled up and down. This does not affect the currently selected *
  509. * item. *
  510. * *
  511. * INPUT: index -- The line (index) to move to the top of the list view. *
  512. * *
  513. * OUTPUT: bool; Was the view actually changed? *
  514. * *
  515. * WARNINGS: none *
  516. * *
  517. * HISTORY: *
  518. * 01/16/1995 JLB : Created. *
  519. *=============================================================================================*/
  520. int ListClass::Set_View_Index(int index)
  521. {
  522. index = Bound(index, 0, max(0, List.Count() - LineCount));
  523. if (index != CurrentTopIndex) {
  524. CurrentTopIndex = index;
  525. Flag_To_Redraw();
  526. if (IsScrollActive) {
  527. ScrollGadget.Set_Value(CurrentTopIndex);
  528. }
  529. return(true);
  530. }
  531. return(false);
  532. }
  533. /***********************************************************************************************
  534. * ListClass::Add_Scroll_Bar -- Adds a scroll bar to the list box. *
  535. * *
  536. * This routine will add a scroll bar (with matching arrows) to the list box. They are *
  537. * added to the right edge and cause the interior of the list box to become narrower. *
  538. * *
  539. * INPUT: none *
  540. * *
  541. * OUTPUT: bool; Was the scroll bar added? *
  542. * *
  543. * WARNINGS: The list box becomes narrower when the scroll bar is added. *
  544. * *
  545. * HISTORY: *
  546. * 01/16/1995 JLB : Created. *
  547. *=============================================================================================*/
  548. int ListClass::Add_Scroll_Bar(void)
  549. {
  550. if (!IsScrollActive) {
  551. IsScrollActive = true;
  552. /*
  553. ** Everything has been created successfully. Flag the list box to be
  554. ** redrawn because it now must be made narrower to accomodate the new
  555. ** slider gadgets.
  556. */
  557. Flag_To_Redraw();
  558. Width -= ScrollGadget.Width;
  559. /*
  560. ** Tell the newly created gadgets that they should inform this list box
  561. ** whenever they get touched. In this way, the list box will automatically
  562. ** be updated under control of the slider buttons.
  563. */
  564. UpGadget.Make_Peer(*this);
  565. DownGadget.Make_Peer(*this);
  566. ScrollGadget.Make_Peer(*this);
  567. /*
  568. ** Add these newly created gadgets to the same gadget list that the
  569. ** list box is part of.
  570. */
  571. UpGadget.Add(*this);
  572. DownGadget.Add(*this);
  573. ScrollGadget.Add(*this);
  574. /*
  575. ** Make sure these added gadgets get redrawn at the next opportunity.
  576. */
  577. UpGadget.Flag_To_Redraw();
  578. DownGadget.Flag_To_Redraw();
  579. ScrollGadget.Flag_To_Redraw();
  580. /*
  581. ** Inform the slider of the size of the window and the current view position.
  582. */
  583. ScrollGadget.Set_Maximum(List.Count());
  584. ScrollGadget.Set_Thumb_Size(LineCount);
  585. ScrollGadget.Set_Value(CurrentTopIndex);
  586. /*
  587. ** Return with success flag.
  588. */
  589. return(true);
  590. }
  591. return(false);
  592. }
  593. /***********************************************************************************************
  594. * ListClass::Remove_Scroll_Bar -- Removes the scroll bar if present *
  595. * *
  596. * Use this routine to remove any attached scroll bar to this list box. If the scroll bar *
  597. * is not present, then no action occurs. *
  598. * *
  599. * INPUT: none *
  600. * *
  601. * OUTPUT: bool; Was the scroll bar removed? *
  602. * *
  603. * WARNINGS: none *
  604. * *
  605. * HISTORY: *
  606. * 01/16/1995 JLB : Created. *
  607. *=============================================================================================*/
  608. int ListClass::Remove_Scroll_Bar(void)
  609. {
  610. if (IsScrollActive) {
  611. IsScrollActive = false;
  612. Width += ScrollGadget.Width;
  613. ScrollGadget.Remove();
  614. UpGadget.Remove();
  615. DownGadget.Remove();
  616. Flag_To_Redraw();
  617. return(true);
  618. }
  619. return(false);
  620. }
  621. /***********************************************************************************************
  622. * ListClass::Set_Tabs -- Sets the tab stop list to be used for text printing. *
  623. * *
  624. * This sets the tab stop list to be used for text printing. It specifies a series of *
  625. * pixel offsets for each tab stop. The offsets are from the starting pixel position that *
  626. * the text begins at. *
  627. * *
  628. * INPUT: tabs -- Pointer to a list of tab pixel offsets. *
  629. * *
  630. * OUTPUT: none *
  631. * *
  632. * WARNINGS: Only a pointer to the tabs is recorded by the ListClass object. Make sure that *
  633. * the list remains intact for the duration of the existence of this object. *
  634. * *
  635. * HISTORY: *
  636. * 01/16/1995 JLB : Created. *
  637. *=============================================================================================*/
  638. void ListClass::Set_Tabs(int const * tabs)
  639. {
  640. Tabs = tabs;
  641. }
  642. /***********************************************************************************************
  643. * ListClass::Draw_Entry -- Draws a list box text line as indicated. *
  644. * *
  645. * This routine is called by the Draw_Me function when it desired to redraw a particular *
  646. * text line in the list box. *
  647. * *
  648. * INPUT: index -- The index of the list entry to draw. This index is based on the *
  649. * total list and NOT the current visible view page. *
  650. * *
  651. * x,y -- Pixel coordinates for the upper left corner of the text entry. *
  652. * *
  653. * width -- The maximum width that the text may draw over. It is expected that *
  654. * this drawing routine entirely fills this length. *
  655. * *
  656. * selected -- bool; Is this a selected (highlighted) listbox entry? *
  657. * *
  658. * OUTPUT: none *
  659. * WARNINGS: none *
  660. * HISTORY: *
  661. * 01/16/1995 JLB : Created. *
  662. *=============================================================================================*/
  663. void ListClass::Draw_Entry(int index, int x, int y, int width, int selected)
  664. {
  665. TextPrintType flags = TextFlags;
  666. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  667. if (selected) {
  668. flags = flags | TPF_BRIGHT_COLOR;
  669. LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, scheme->Shadow);
  670. } else {
  671. if (!(flags & TPF_USE_GRAD_PAL)) {
  672. flags = flags | TPF_MEDIUM_COLOR;
  673. }
  674. }
  675. Conquer_Clip_Text_Print(List[index], x, y, scheme, TBLACK, flags, width, Tabs);
  676. }
  677. /***********************************************************************************************
  678. * ListClass::Add -- Adds myself to list immediately after given object *
  679. * *
  680. * Adds the list box to the chain, immediately after the given object. The order will be: *
  681. * - Listbox *
  682. * - Up arrow (if active) *
  683. * - Down arrow (if active) *
  684. * - Scroll gadget (if active) *
  685. * * *
  686. * INPUT: object -- Pointer to the object to be added right after this one. *
  687. * *
  688. * OUTPUT: Returns with a pointer to the head of the list. *
  689. * *
  690. * WARNINGS: none *
  691. * *
  692. * HISTORY: *
  693. * 01/19/1995 JLB : Created. *
  694. *=============================================================================================*/
  695. LinkClass & ListClass::Add(LinkClass & list)
  696. {
  697. /*
  698. ** Add the scroll bar gadgets if they're active.
  699. */
  700. if (IsScrollActive) {
  701. ScrollGadget.Add(list);
  702. DownGadget.Add(list);
  703. UpGadget.Add(list);
  704. }
  705. /*
  706. ** Add myself to the list, then return.
  707. */
  708. return(ControlClass::Add(list));
  709. }
  710. /***********************************************************************************************
  711. * ListClass::Add_Head -- Adds myself to head of the given list *
  712. * *
  713. * INPUT: list -- list to add myself to *
  714. * *
  715. * OUTPUT: Returns with a reference to the object at the head of the list. This should be *
  716. * the same object that is passed in. *
  717. * *
  718. * WARNINGS: none *
  719. * *
  720. * HISTORY: *
  721. * 01/19/1995 JLB : Created. *
  722. *=============================================================================================*/
  723. LinkClass & ListClass::Add_Head(LinkClass & list)
  724. {
  725. /*
  726. ** Add the scroll bar gadgets if they're active.
  727. */
  728. if (IsScrollActive) {
  729. ScrollGadget.Add_Head(list);
  730. DownGadget.Add_Head(list);
  731. UpGadget.Add_Head(list);
  732. }
  733. /*
  734. ** Add myself to the list, then return.
  735. */
  736. return(ControlClass::Add_Head(list));
  737. }
  738. /***********************************************************************************************
  739. * ListClass::Add_Tail -- Adds myself to tail of given list *
  740. * *
  741. * Adds the list box to the tail of the give chain. The order will be: *
  742. * - Listbox *
  743. * - Up arrow (if active) *
  744. * - Down arrow (if active) *
  745. * - Scroll gadget (if active) *
  746. * *
  747. * INPUT: list -- list to add myself to *
  748. * *
  749. * OUTPUT: none *
  750. * *
  751. * WARNINGS: The previous and next pointers for the added object MUST have been properly *
  752. * initialized for this routine to work correctly. *
  753. * *
  754. * HISTORY: *
  755. * 01/15/1995 JLB : Created. *
  756. *=============================================================================================*/
  757. LinkClass & ListClass::Add_Tail(LinkClass & list)
  758. {
  759. /*
  760. ** Add myself to the list.
  761. */
  762. ControlClass::Add_Tail(list);
  763. /*
  764. ** Add the scroll bar gadgets if they're active.
  765. */
  766. if (IsScrollActive) {
  767. UpGadget.Add_Tail(list);
  768. DownGadget.Add_Tail(list);
  769. ScrollGadget.Add_Tail(list);
  770. }
  771. return(Head_Of_List());
  772. }
  773. /***********************************************************************************************
  774. * ListClass::Remove -- Removes the specified object from the list. *
  775. * *
  776. * This routine will remove the specified object from the list of objects. Because of the *
  777. * previous and next pointers, it is possible to remove an object from the list without *
  778. * knowing the head of the list. To do this, just call Remove() with the parameter of *
  779. * "this". *
  780. * *
  781. * INPUT: none *
  782. * *
  783. * OUTPUT: Returns with the new head of list. *
  784. * *
  785. * WARNINGS: none *
  786. * *
  787. * HISTORY: *
  788. * 01/15/1995 JLB : Created. *
  789. *=============================================================================================*/
  790. GadgetClass * ListClass::Remove(void)
  791. {
  792. /*
  793. ** Remove the scroll bar if it's active
  794. */
  795. if (IsScrollActive) {
  796. ScrollGadget.Remove();
  797. DownGadget.Remove();
  798. UpGadget.Remove();
  799. }
  800. /*
  801. ** Remove myself & return
  802. */
  803. return(ControlClass::Remove());
  804. }
  805. /***********************************************************************************************
  806. * ListClass::Set_Selected_Index -- Set the top of the listbox to index specified. *
  807. * *
  808. * This routine will set the top line of the listbox to the index value specified. *
  809. * *
  810. * INPUT: index -- The index to set the top of the listbox to. *
  811. * *
  812. * OUTPUT: none *
  813. * *
  814. * WARNINGS: The requested index may be adjusted to fit within legal parameters. *
  815. * *
  816. * HISTORY: *
  817. * 06/25/1995 JLB : Created. *
  818. * 01/23/1996 JLB : Forces selected index to always be zero for a null list. *
  819. *=============================================================================================*/
  820. void ListClass::Set_Selected_Index(int index)
  821. {
  822. if (index < List.Count()) {
  823. SelectedIndex = index;
  824. Flag_To_Redraw();
  825. if (SelectedIndex < CurrentTopIndex) {
  826. Set_View_Index(SelectedIndex);
  827. }
  828. if (SelectedIndex >= CurrentTopIndex+LineCount) {
  829. Set_View_Index(SelectedIndex-(LineCount-1));
  830. }
  831. } else {
  832. SelectedIndex = 0;
  833. }
  834. }
  835. /***********************************************************************************************
  836. * ListClass::Step_Selected_Index -- Change the listbox top line in direction specified. *
  837. * *
  838. * This routine will scroll the top line of the listbox in the direction specified. *
  839. * *
  840. * INPUT: step -- The direction (and amount) to adjust the listbox. If negative value, then *
  841. * the top line is scrolled upward. *
  842. * *
  843. * OUTPUT: Returns with the original top line index number. *
  844. * *
  845. * WARNINGS: none *
  846. * *
  847. * HISTORY: *
  848. * 06/25/1995 JLB : Created. *
  849. *=============================================================================================*/
  850. int ListClass::Step_Selected_Index(int step)
  851. {
  852. int old = SelectedIndex;
  853. Set_Selected_Index(old + step);
  854. return(old);
  855. }
  856. void ListClass::Flag_To_Redraw(void)
  857. {
  858. if (IsScrollActive) {
  859. UpGadget.Flag_To_Redraw();
  860. DownGadget.Flag_To_Redraw();
  861. ScrollGadget.Flag_To_Redraw();
  862. }
  863. ControlClass::Flag_To_Redraw();
  864. }
  865. void ListClass::Set_Selected_Index(char const * text)
  866. {
  867. if (text && List.Count() > 0) {
  868. for (int index = 0; index < List.Count(); index++) {
  869. if (stricmp(List[index], text) == 0) {
  870. Set_Selected_Index(index);
  871. break;
  872. }
  873. }
  874. }
  875. }