LIST.CPP 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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: F:\projects\c&c\vcs\code\list.cpv 2.17 16 Oct 1995 16:51:36 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 : June 25, 1995 [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. Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TextFlags);
  100. LineHeight = FontHeight+FontYSpacing-1;
  101. LineCount = (h-1) / LineHeight;
  102. }
  103. /***********************************************************************************************
  104. * ListClass::~ListClass -- Destructor for list class objects. *
  105. * *
  106. * This is the destructor for list objects. It handles removing anything it might have *
  107. * allocated. This is typically the scroll bar. *
  108. * *
  109. * INPUT: none *
  110. * OUTPUT: none *
  111. * WARNINGS: none *
  112. * HISTORY: 01/16/1995 JLB : Created. *
  113. *=============================================================================================*/
  114. ListClass::~ListClass(void)
  115. {
  116. Remove_Scroll_Bar();
  117. }
  118. /***********************************************************************************************
  119. * ListClass::Add_Item -- Adds an item to the list box. *
  120. * *
  121. * This will add the specified string to the list box. The string is added to the end *
  122. * of the list. *
  123. * *
  124. * INPUT: text -- Pointer to the string to add to the list box. *
  125. * OUTPUT: none *
  126. * WARNINGS: none *
  127. * HISTORY: 01/15/1995 JLB : Created. *
  128. *=============================================================================================*/
  129. int ListClass::Add_Item(char const * text)
  130. {
  131. if (text) {
  132. List.Add(text);
  133. Flag_To_Redraw();
  134. /*
  135. ** Add scroll gadget if the list gets too large to display all of the items
  136. ** at the same time.
  137. */
  138. if (List.Count() > LineCount) {
  139. Add_Scroll_Bar();
  140. }
  141. /*
  142. ** Tell the slider that there is one more entry in the list.
  143. */
  144. if (IsScrollActive) {
  145. ScrollGadget.Set_Maximum(List.Count());
  146. }
  147. }
  148. return(List.Count() - 1);
  149. }
  150. /***********************************************************************************************
  151. * ListClass::Add_Item -- Adds a text item (as number) to the list box. *
  152. * *
  153. * This will add the text as specified by the text number provided, to the list box. *
  154. * The string is added to the end of the list. *
  155. * *
  156. * INPUT: text -- The text number for the string to add to the list box. *
  157. * OUTPUT: none *
  158. * WARNINGS: Once a string is added to the list box in this fashion, there is no method of *
  159. * retrieving the text number as it relates to any particular index in the list. *
  160. * HISTORY: *
  161. * 01/15/1995 JLB : Created. *
  162. *=============================================================================================*/
  163. int ListClass::Add_Item(int text)
  164. {
  165. if (text != TXT_NONE) {
  166. Add_Item(Text_String(text));
  167. }
  168. return(List.Count() - 1);
  169. }
  170. /***********************************************************************************************
  171. * ListClass::Remove_Item -- Remove specified text from list box. *
  172. * *
  173. * This routine will remove the specified text string from the list box. *
  174. * *
  175. * INPUT: text -- Pointer to the string to remove. *
  176. * OUTPUT: none *
  177. * WARNINGS: The text pointer passed into this routine MUST be the same text pointer that *
  178. * was used to add the string to the list. *
  179. * HISTORY: *
  180. * 01/15/1995 JLB : Created. *
  181. *=============================================================================================*/
  182. void ListClass::Remove_Item(char const * text)
  183. {
  184. if (text) {
  185. List.Delete(text);
  186. /*
  187. ** If the list is now small enough to display completely within the list box region,
  188. ** then delete the slider gadget (if they are present).
  189. */
  190. if (List.Count() <= LineCount) {
  191. Remove_Scroll_Bar();
  192. }
  193. /*
  194. ** Tell the slider that there is one less entry in the list.
  195. */
  196. if (IsScrollActive) {
  197. ScrollGadget.Set_Maximum(List.Count());
  198. }
  199. /*
  200. ** If we just removed the selected entry, select the previous one
  201. */
  202. if (SelectedIndex >= List.Count()) {
  203. SelectedIndex--;
  204. if (SelectedIndex < 0)
  205. SelectedIndex = 0;
  206. }
  207. /*
  208. ** If we just removed the top-displayed entry, step up one item
  209. */
  210. if (CurrentTopIndex >= List.Count()) {
  211. CurrentTopIndex--;
  212. if (CurrentTopIndex < 0)
  213. CurrentTopIndex = 0;
  214. if (IsScrollActive)
  215. ScrollGadget.Step(1);
  216. }
  217. }
  218. }
  219. /***************************************************************************
  220. * ListClass::Action -- If clicked on, do this! *
  221. * *
  222. * INPUT: int flags -- combination of mouse flags indicating *
  223. * what action to take. *
  224. * *
  225. * OUTPUT: bool result. *
  226. * *
  227. * WARNINGS: none. *
  228. * *
  229. * HISTORY: 01/05/1995 MML : Created. *
  230. *=========================================================================*/
  231. int ListClass::Action(unsigned flags, KeyNumType & key)
  232. {
  233. if (flags & LEFTRELEASE) {
  234. key = KN_NONE;
  235. flags &= (~LEFTRELEASE);
  236. ControlClass::Action(flags, key);
  237. return(true);
  238. } else {
  239. /* --------------------------------------------------
  240. ** Handle keyboard events here.
  241. */
  242. if (flags & KEYBOARD) {
  243. /*
  244. ** Process the keyboard character. If indicated, consume this keyboard event
  245. ** so that the edit gadget ID number is not returned.
  246. */
  247. if (key == KN_UP) {
  248. Step_Selected_Index(-1);
  249. key = KN_NONE;
  250. } else if (key == KN_DOWN) {
  251. Step_Selected_Index(1);
  252. key = KN_NONE;
  253. } else {
  254. flags &= ~KEYBOARD;
  255. }
  256. } else {
  257. int index = Get_Mouse_Y() - (Y+1);
  258. index = index / LineHeight;
  259. SelectedIndex = CurrentTopIndex + index;
  260. SelectedIndex = MIN(SelectedIndex, List.Count()-1);
  261. }
  262. }
  263. return(ControlClass::Action(flags, key));
  264. }
  265. /***********************************************************************************************
  266. * ListClass::Draw_Me -- Draws the listbox. *
  267. * *
  268. * This routine will render the listbox. *
  269. * *
  270. * INPUT: forced -- Should the listbox be redrawn even if it already thinks it doesn't *
  271. * need to be? This is true when something outside of the gadget system *
  272. * has trashed the screen. *
  273. * *
  274. * OUTPUT: Was the listbox redrawn? *
  275. * *
  276. * WARNINGS: none *
  277. * *
  278. * HISTORY: *
  279. * 06/25/1995 JLB : Created. *
  280. *=============================================================================================*/
  281. int ListClass::Draw_Me(int forced)
  282. {
  283. if (GadgetClass::Draw_Me(forced)) {
  284. /*
  285. ** Turn off the mouse.
  286. */
  287. if (LogicPage == &SeenBuff) {
  288. Conditional_Hide_Mouse(X, Y, X+Width, Y+Height);
  289. }
  290. Draw_Box (X, Y, Width, Height, BOXSTYLE_GREEN_BOX, true);
  291. /*
  292. ** Draw List.
  293. */
  294. if (List.Count()) {
  295. for (int index = 0; index < LineCount; index++) {
  296. int line = CurrentTopIndex + index;
  297. if (List.Count() > line) {
  298. /*
  299. ** Prints the text and handles right edge clipping and tabs.
  300. */
  301. Draw_Entry(line, X+1, Y+(LineHeight*index)+1, Width-2, (line == SelectedIndex));
  302. }
  303. }
  304. }
  305. /*
  306. ** Turn on the mouse.
  307. */
  308. if (LogicPage == &SeenBuff) {
  309. Conditional_Show_Mouse();
  310. }
  311. return(true);
  312. }
  313. return(false);
  314. }
  315. /***********************************************************************************************
  316. * ListClass::Bump -- Bumps the list box up/down one "page". *
  317. * *
  318. * Use this routine to adjust the "page" that is being viewed in the list box. The view *
  319. * will move up or down (as specified) one page (screen full) of text strings. *
  320. * *
  321. * INPUT: up -- Should the adjustment be up? *
  322. * *
  323. * OUTPUT: none *
  324. * *
  325. * WARNINGS: none *
  326. * *
  327. * HISTORY: *
  328. * 01/15/1995 JLB : Created. *
  329. *=============================================================================================*/
  330. void ListClass::Bump(int up)
  331. {
  332. if (IsScrollActive) {
  333. if (ScrollGadget.Step(up)) {
  334. CurrentTopIndex = ScrollGadget.Get_Value();
  335. Flag_To_Redraw();
  336. }
  337. }
  338. }
  339. /***********************************************************************************************
  340. * ListClass::Step -- Moves the list view one line in direction specified. *
  341. * *
  342. * This routine will move the current view "page" one line in the direction specified. *
  343. * *
  344. * INPUT: up -- Should the view be moved upward? *
  345. * *
  346. * OUTPUT: none *
  347. * *
  348. * WARNINGS: none *
  349. * *
  350. * HISTORY: *
  351. * 01/15/1995 JLB : Created. *
  352. *=============================================================================================*/
  353. void ListClass::Step(int up)
  354. {
  355. if (IsScrollActive) {
  356. if (ScrollGadget.Step(up)) {
  357. CurrentTopIndex = ScrollGadget.Get_Value();
  358. Flag_To_Redraw();
  359. }
  360. }
  361. }
  362. /***********************************************************************************************
  363. * ListClass::Get_Item -- Fetches an arbitrary item string. *
  364. * *
  365. * This routine will fetch an item string from the list box. The item fetched can be any *
  366. * one of the ones in the list. *
  367. * *
  368. * INPUT: index -- The index to examine and return the text pointer from. *
  369. * *
  370. * OUTPUT: Returns with the text pointer to the string at the index position specified. *
  371. * *
  372. * WARNINGS: none *
  373. * *
  374. * HISTORY: *
  375. * 01/16/1995 JLB : Created. *
  376. *=============================================================================================*/
  377. char const * ListClass::Get_Item(int index) const
  378. {
  379. if (List.Count() == 0) return (NULL);
  380. index = MIN(index, List.Count()-1 );
  381. return(List[index]);
  382. }
  383. /***********************************************************************************************
  384. * ListClass::Current_Item -- Fetches pointer to current item string. *
  385. * *
  386. * This routine will fetch a pointer to the currently selected item's text. *
  387. * *
  388. * INPUT: none *
  389. * *
  390. * OUTPUT: Return with pointer to currently selected text. *
  391. * *
  392. * WARNINGS: none *
  393. * *
  394. * HISTORY: *
  395. * 01/16/1995 JLB : Created. *
  396. *=============================================================================================*/
  397. char const * ListClass::Current_Item(void)
  398. {
  399. return(List[SelectedIndex]);
  400. }
  401. /***********************************************************************************************
  402. * ListClass::Current_Index -- Fetches the current selected index. *
  403. * *
  404. * This routine will fetch the index number for the currently selected line. *
  405. * *
  406. * INPUT: none *
  407. * *
  408. * OUTPUT: Returns with the index of the currently selected line. This ranges from zero to *
  409. * the number of items in the list minus one. *
  410. * *
  411. * WARNINGS: none *
  412. * *
  413. * HISTORY: *
  414. * 01/16/1995 JLB : Created. *
  415. *=============================================================================================*/
  416. int ListClass::Current_Index(void)
  417. {
  418. return(SelectedIndex);
  419. }
  420. /***********************************************************************************************
  421. * ListClass::Peer_To_Peer -- A peer gadget was touched -- make adjustments. *
  422. * *
  423. * This routine is called when one of the peer gadgets (the scroll arrows or the slider) *
  424. * was touched in some fashion. This routine will sort out whom and why and then make *
  425. * any necessary adjustments to the list box. *
  426. * *
  427. * INPUT: flags -- The event flags that affected the peer gadget. *
  428. * *
  429. * key -- The key value at the time of the event. *
  430. * *
  431. * whom -- Which gadget is being touched. *
  432. * *
  433. * OUTPUT: none *
  434. * *
  435. * WARNINGS: none *
  436. * *
  437. * HISTORY: *
  438. * 01/16/1995 JLB : Created. *
  439. *=============================================================================================*/
  440. void ListClass::Peer_To_Peer(unsigned flags, KeyNumType &, ControlClass & whom)
  441. {
  442. if (flags & LEFTRELEASE) {
  443. if (&whom == &UpGadget) {
  444. Step(true);
  445. }
  446. if (&whom == &DownGadget) {
  447. Step(false);
  448. }
  449. }
  450. /*
  451. ** The slider has changed, so reflect the current list position
  452. ** according to the slider setting.
  453. */
  454. if (&whom == &ScrollGadget) {
  455. Set_View_Index(ScrollGadget.Get_Value());
  456. }
  457. }
  458. /***********************************************************************************************
  459. * ListClass::Set_View_Index -- Sets the top line for the current list view. *
  460. * *
  461. * This routine is used to set the line that will be at the top of the list view. This is *
  462. * how the view can be scrolled up and down. This does not affect the currently selected *
  463. * item. *
  464. * *
  465. * INPUT: index -- The line (index) to move to the top of the list view. *
  466. * *
  467. * OUTPUT: bool; Was the view actually changed? *
  468. * *
  469. * WARNINGS: none *
  470. * *
  471. * HISTORY: *
  472. * 01/16/1995 JLB : Created. *
  473. *=============================================================================================*/
  474. int ListClass::Set_View_Index(int index)
  475. {
  476. index = Bound(index, 0, List.Count() - LineCount);
  477. if (index != CurrentTopIndex) {
  478. CurrentTopIndex = index;
  479. Flag_To_Redraw();
  480. if (IsScrollActive) {
  481. ScrollGadget.Set_Value(CurrentTopIndex);
  482. }
  483. return(true);
  484. }
  485. return(false);
  486. }
  487. /***********************************************************************************************
  488. * ListClass::Add_Scroll_Bar -- Adds a scroll bar to the list box. *
  489. * *
  490. * This routine will add a scroll bar (with matching arrows) to the list box. They are *
  491. * added to the right edge and cause the interior of the list box to become narrower. *
  492. * *
  493. * INPUT: none *
  494. * *
  495. * OUTPUT: bool; Was the scroll bar added? *
  496. * *
  497. * WARNINGS: The list box becomes narrower when the scroll bar is added. *
  498. * *
  499. * HISTORY: *
  500. * 01/16/1995 JLB : Created. *
  501. *=============================================================================================*/
  502. int ListClass::Add_Scroll_Bar(void)
  503. {
  504. if (!IsScrollActive) {
  505. IsScrollActive = true;
  506. /*
  507. ** Everything has been created successfully. Flag the list box to be
  508. ** redrawn because it now must be made narrower to accomodate the new
  509. ** slider gadgets.
  510. */
  511. Flag_To_Redraw();
  512. Width -= ScrollGadget.Width;
  513. /*
  514. ** Tell the newly created gadgets that they should inform this list box
  515. ** whenever they get touched. In this way, the list box will automatically
  516. ** be updated under control of the slider buttons.
  517. */
  518. UpGadget.Make_Peer(*this);
  519. DownGadget.Make_Peer(*this);
  520. ScrollGadget.Make_Peer(*this);
  521. /*
  522. ** Add these newly created gadgets to the same gadget list that the
  523. ** list box is part of.
  524. */
  525. UpGadget.Add(*this);
  526. DownGadget.Add(*this);
  527. ScrollGadget.Add(*this);
  528. /*
  529. ** Make sure these added gadgets get redrawn at the next opportunity.
  530. */
  531. UpGadget.Flag_To_Redraw();
  532. DownGadget.Flag_To_Redraw();
  533. ScrollGadget.Flag_To_Redraw();
  534. /*
  535. ** Inform the slider of the size of the window and the current view position.
  536. */
  537. ScrollGadget.Set_Maximum(List.Count());
  538. ScrollGadget.Set_Thumb_Size(LineCount);
  539. ScrollGadget.Set_Value(CurrentTopIndex);
  540. /*
  541. ** Return with success flag.
  542. */
  543. return(true);
  544. }
  545. return(false);
  546. }
  547. /***********************************************************************************************
  548. * ListClass::Remove_Scroll_Bar -- Removes the scroll bar if present *
  549. * *
  550. * Use this routine to remove any attached scroll bar to this list box. If the scroll bar *
  551. * is not present, then no action occurs. *
  552. * *
  553. * INPUT: none *
  554. * *
  555. * OUTPUT: bool; Was the scroll bar removed? *
  556. * *
  557. * WARNINGS: none *
  558. * *
  559. * HISTORY: *
  560. * 01/16/1995 JLB : Created. *
  561. *=============================================================================================*/
  562. int ListClass::Remove_Scroll_Bar(void)
  563. {
  564. if (IsScrollActive) {
  565. IsScrollActive = false;
  566. Width += ScrollGadget.Width;
  567. ScrollGadget.Remove();
  568. UpGadget.Remove();
  569. DownGadget.Remove();
  570. Flag_To_Redraw();
  571. return(true);
  572. }
  573. return(false);
  574. }
  575. /***********************************************************************************************
  576. * ListClass::Set_Tabs -- Sets the tab stop list to be used for text printing. *
  577. * *
  578. * This sets the tab stop list to be used for text printing. It specifies a series of *
  579. * pixel offsets for each tab stop. The offsets are from the starting pixel position that *
  580. * the text begins at. *
  581. * *
  582. * INPUT: tabs -- Pointer to a list of tab pixel offsets. *
  583. * *
  584. * OUTPUT: none *
  585. * *
  586. * WARNINGS: Only a pointer to the tabs is recorded by the ListClass object. Make sure that *
  587. * the list remains intact for the duration of the existence of this object. *
  588. * *
  589. * HISTORY: *
  590. * 01/16/1995 JLB : Created. *
  591. *=============================================================================================*/
  592. void ListClass::Set_Tabs(int const * tabs)
  593. {
  594. Tabs = tabs;
  595. }
  596. /***********************************************************************************************
  597. * ListClass::Draw_Entry -- Draws a list box text line as indicated. *
  598. * *
  599. * This routine is called by the Draw_Me function when it desired to redraw a particular *
  600. * text line in the list box. *
  601. * *
  602. * INPUT: index -- The index of the list entry to draw. This index is based on the *
  603. * total list and NOT the current visible view page. *
  604. * *
  605. * x,y -- Pixel coordinates for the upper left corner of the text entry. *
  606. * *
  607. * width -- The maximum width that the text may draw over. It is expected that *
  608. * this drawing routine entirely fills this length. *
  609. * *
  610. * selected -- bool; Is this a selected (highlighted) listbox entry? *
  611. * *
  612. * OUTPUT: none *
  613. * WARNINGS: none *
  614. * HISTORY: *
  615. * 01/16/1995 JLB : Created. *
  616. *=============================================================================================*/
  617. void ListClass::Draw_Entry(int index, int x, int y, int width, int selected)
  618. {
  619. if (TextFlags & TPF_6PT_GRAD) {
  620. TextPrintType flags = TextFlags;
  621. if (selected) {
  622. flags = flags | TPF_BRIGHT_COLOR;
  623. LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, CC_GREEN_SHADOW);
  624. } else {
  625. if (!(flags & TPF_USE_GRAD_PAL)) {
  626. flags = flags | TPF_MEDIUM_COLOR;
  627. }
  628. }
  629. Conquer_Clip_Text_Print(List[index], x, y, CC_GREEN, TBLACK, flags, width, Tabs);
  630. } else {
  631. Conquer_Clip_Text_Print(List[index], x, y, (selected ? BLUE : WHITE), TBLACK, TextFlags, width, Tabs);
  632. }
  633. }
  634. /***********************************************************************************************
  635. * ListClass::Add -- Adds myself to list immediately after given object *
  636. * *
  637. * Adds the list box to the chain, immemdiately after the given object. The order will be: *
  638. * - Listbox *
  639. * - Up arrow (if active) *
  640. * - Down arrow (if active) *
  641. * - Scroll gadget (if active) *
  642. * * *
  643. * INPUT: object -- Pointer to the object to be added right after this one. *
  644. * *
  645. * OUTPUT: Returns with a pointer to the head of the list. *
  646. * *
  647. * WARNINGS: none *
  648. * *
  649. * HISTORY: *
  650. * 01/19/1995 JLB : Created. *
  651. *=============================================================================================*/
  652. LinkClass & ListClass::Add(LinkClass & list)
  653. {
  654. /*
  655. ** Add the scroll bar gadgets if they're active.
  656. */
  657. if (IsScrollActive) {
  658. ScrollGadget.Add(list);
  659. DownGadget.Add(list);
  660. UpGadget.Add(list);
  661. }
  662. /*
  663. ** Add myself to the list, then return.
  664. */
  665. return(ControlClass::Add(list));
  666. }
  667. /***********************************************************************************************
  668. * ListClass::Add_Head -- Adds myself to head of the given list *
  669. * *
  670. * INPUT: list -- list to add myself to *
  671. * *
  672. * OUTPUT: Returns with a reference to the object at the head of the list. This should be *
  673. * the same object that is passed in. *
  674. * *
  675. * WARNINGS: none *
  676. * *
  677. * HISTORY: *
  678. * 01/19/1995 JLB : Created. *
  679. *=============================================================================================*/
  680. LinkClass & ListClass::Add_Head(LinkClass & list)
  681. {
  682. /*
  683. ** Add the scroll bar gadgets if they're active.
  684. */
  685. if (IsScrollActive) {
  686. ScrollGadget.Add_Head(list);
  687. DownGadget.Add_Head(list);
  688. UpGadget.Add_Head(list);
  689. }
  690. /*
  691. ** Add myself to the list, then return.
  692. */
  693. return(ControlClass::Add_Head(list));
  694. }
  695. /***********************************************************************************************
  696. * ListClass::Add_Tail -- Adds myself to tail of given list *
  697. * *
  698. * Adds the list box to the tail of the give chain. The order will be: *
  699. * - Listbox *
  700. * - Up arrow (if active) *
  701. * - Down arrow (if active) *
  702. * - Scroll gadget (if active) *
  703. * *
  704. * INPUT: list -- list to add myself to *
  705. * *
  706. * OUTPUT: none *
  707. * *
  708. * WARNINGS: The previous and next pointers for the added object MUST have been properly *
  709. * initialized for this routine to work correctly. *
  710. * *
  711. * HISTORY: *
  712. * 01/15/1995 JLB : Created. *
  713. *=============================================================================================*/
  714. LinkClass & ListClass::Add_Tail(LinkClass & list)
  715. {
  716. /*
  717. ** Add myself to the list.
  718. */
  719. ControlClass::Add_Tail(list);
  720. /*
  721. ** Add the scroll bar gadgets if they're active.
  722. */
  723. if (IsScrollActive) {
  724. UpGadget.Add_Tail(list);
  725. DownGadget.Add_Tail(list);
  726. ScrollGadget.Add_Tail(list);
  727. }
  728. return(Head_Of_List());
  729. }
  730. /***********************************************************************************************
  731. * ListClass::Remove -- Removes the specified object from the list. *
  732. * *
  733. * This routine will remove the specified object from the list of objects. Because of the *
  734. * previous and next pointers, it is possible to remove an object from the list without *
  735. * knowing the head of the list. To do this, just call Remove() with the parameter of *
  736. * "this". *
  737. * *
  738. * INPUT: none *
  739. * *
  740. * OUTPUT: Returns with the new head of list. *
  741. * *
  742. * WARNINGS: none *
  743. * *
  744. * HISTORY: *
  745. * 01/15/1995 JLB : Created. *
  746. *=============================================================================================*/
  747. GadgetClass * ListClass::Remove(void)
  748. {
  749. /*
  750. ** Remove the scroll bar if it's active
  751. */
  752. if (IsScrollActive) {
  753. ScrollGadget.Remove();
  754. DownGadget.Remove();
  755. UpGadget.Remove();
  756. }
  757. /*
  758. ** Remove myself & return
  759. */
  760. return(ControlClass::Remove());
  761. }
  762. /***********************************************************************************************
  763. * ListClass::Set_Selected_Index -- Set the top of the listbox to index specified. *
  764. * *
  765. * This routine will set the top line of the listbox to the index value specified. *
  766. * *
  767. * INPUT: index -- The index to set the top of the listbox to. *
  768. * *
  769. * OUTPUT: none *
  770. * *
  771. * WARNINGS: The requested index may be adjusted to fit within legal parameters. *
  772. * *
  773. * HISTORY: *
  774. * 06/25/1995 JLB : Created. *
  775. *=============================================================================================*/
  776. void ListClass::Set_Selected_Index(int index)
  777. {
  778. if (index < List.Count()) {
  779. SelectedIndex = index;
  780. Flag_To_Redraw();
  781. if (SelectedIndex < CurrentTopIndex) {
  782. Set_View_Index(SelectedIndex);
  783. }
  784. if (SelectedIndex >= CurrentTopIndex+LineCount) {
  785. Set_View_Index(SelectedIndex-(LineCount-1));
  786. }
  787. }
  788. }
  789. /***********************************************************************************************
  790. * ListClass::Step_Selected_Index -- Change the listbox top line in direction specified. *
  791. * *
  792. * This routine will scroll the top line of the listbox in the direction specified. *
  793. * *
  794. * INPUT: step -- The direction (and amount) to adjust the listbox. If negative value, then *
  795. * the top line is scrolled upward. *
  796. * *
  797. * OUTPUT: Returns with the original top line index number. *
  798. * *
  799. * WARNINGS: none *
  800. * *
  801. * HISTORY: *
  802. * 06/25/1995 JLB : Created. *
  803. *=============================================================================================*/
  804. int ListClass::Step_Selected_Index(int step)
  805. {
  806. int old = SelectedIndex;
  807. Set_Selected_Index(old + step);
  808. return(old);
  809. }