LIST.CPP 50 KB

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