LIST.CPP 48 KB

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