CHEKLIST.CPP 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/CHEKLIST.CPP 1 3/03/97 10:24a 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 : CHEKLIST.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 07/05/96 *
  26. * *
  27. * Last Update : July 6, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * CheckListClass::Action -- action function for this class *
  32. * CheckListClass::Add_Item -- Adds specifies text to check list box. *
  33. * CheckListClass::CheckListClass -- constructor *
  34. * CheckListClass::Check_Item -- [un]checks an items *
  35. * CheckListClass::Draw_Entry -- draws a list box entry *
  36. * CheckListClass::Get_Item -- Fetches a pointer to the text associated with the index. *
  37. * CheckListClass::Remove_Item -- Remove the item that matches the text pointer specified. *
  38. * CheckListClass::Set_Selected_Index -- Set the selected index to match the text pointer spe*
  39. * CheckListClass::~CheckListClass -- Destructor for check list object. *
  40. * CheckListClass::~CheckListClass -- destructor *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "function.h"
  43. /***************************************************************************
  44. * CheckListClass::CheckListClass -- constructor *
  45. * *
  46. * INPUT: *
  47. * id control ID for this list box *
  48. * x x-coord *
  49. * y y-coord *
  50. * w width *
  51. * h height *
  52. * flags mouse event flags *
  53. * up ptr to Up-arrow shape *
  54. * down ptr to Down-arrow shape *
  55. * *
  56. * OUTPUT: *
  57. * none. *
  58. * *
  59. * WARNINGS: *
  60. * none. *
  61. * *
  62. * HISTORY: *
  63. * 02/16/1995 BR : Created. *
  64. *=========================================================================*/
  65. CheckListClass::CheckListClass(int id, int x, int y, int w, int h, TextPrintType flags,
  66. void const * up, void const * down) :
  67. ListClass (id, x, y, w, h, flags, up, down),
  68. IsReadOnly(false)
  69. {
  70. }
  71. /***********************************************************************************************
  72. * CheckListClass::~CheckListClass -- Destructor for check list object. *
  73. * *
  74. * This destructor will delete all entries attached to it. *
  75. * *
  76. * INPUT: none *
  77. * *
  78. * OUTPUT: none *
  79. * *
  80. * WARNINGS: none *
  81. * *
  82. * HISTORY: *
  83. * 07/06/1996 JLB : Created. *
  84. *=============================================================================================*/
  85. CheckListClass::~CheckListClass(void)
  86. {
  87. while (CheckListClass::Count()) {
  88. CheckObject * obj = (CheckObject *)ListClass::Get_Item(0);
  89. ListClass::Remove_Item(0);
  90. delete obj;
  91. }
  92. }
  93. /***********************************************************************************************
  94. * CheckListClass::Add_Item -- Adds specifies text to check list box. *
  95. * *
  96. * This routine will add the specified text string to the check list. *
  97. * *
  98. * INPUT: text -- Pointer to the text string to add to the list box. *
  99. * *
  100. * OUTPUT: Returns the index number where the text object was added. *
  101. * *
  102. * WARNINGS: none *
  103. * *
  104. * HISTORY: *
  105. * 02/14/1996 JLB : Created. *
  106. *=============================================================================================*/
  107. int CheckListClass::Add_Item(char const * text)
  108. {
  109. CheckObject * obj = new CheckObject(text, false);
  110. return(ListClass::Add_Item((char const *)obj));
  111. }
  112. char const * CheckListClass::Current_Item(void) const
  113. {
  114. CheckObject * obj = (CheckObject *)ListClass::Current_Item();
  115. if (obj) {
  116. return(obj->Text);
  117. }
  118. return(0);
  119. }
  120. /***********************************************************************************************
  121. * CheckListClass::Get_Item -- Fetches a pointer to the text associated with the index. *
  122. * *
  123. * This routine will find the text associated with the entry specified and return a pointer *
  124. * to that text. *
  125. * *
  126. * INPUT: index -- The entry (index) to fetch a pointer to. *
  127. * *
  128. * OUTPUT: Returns with the text pointer associated with the index specified. *
  129. * *
  130. * WARNINGS: If the index is out of range, then NULL is returned. *
  131. * *
  132. * HISTORY: *
  133. * 07/06/1996 JLB : Created. *
  134. *=============================================================================================*/
  135. char const * CheckListClass::Get_Item(int index) const
  136. {
  137. CheckObject * obj = (CheckObject *)ListClass::Get_Item(index);
  138. if (obj) {
  139. return(obj->Text);
  140. }
  141. return(0);
  142. }
  143. /***********************************************************************************************
  144. * CheckListClass::Remove_Item -- Remove the item that matches the text pointer specified. *
  145. * *
  146. * This routine will find the entry that matches the text pointer specified and then *
  147. * delete that entry. *
  148. * *
  149. * INPUT: text -- The text pointer to use to find the exact match in the list. *
  150. * *
  151. * OUTPUT: none *
  152. * *
  153. * WARNINGS: none *
  154. * *
  155. * HISTORY: *
  156. * 07/06/1996 JLB : Created. *
  157. *=============================================================================================*/
  158. void CheckListClass::Remove_Item(char const * text)
  159. {
  160. for (int index = 0; index < Count(); index++) {
  161. CheckObject * obj = (CheckObject *)ListClass::Get_Item(index);
  162. if (obj && stricmp(obj->Text, text) == 0) {
  163. ListClass::Remove_Item(index);
  164. delete obj;
  165. break;
  166. }
  167. }
  168. }
  169. /***********************************************************************************************
  170. * CheckListClass::Set_Selected_Index -- Set the selected index to match the text pointer spec *
  171. * *
  172. * This routine will find the entry that exactly matches the text pointer specified. If *
  173. * found, then that entry will be set as the currently selected index. *
  174. * *
  175. * INPUT: text -- Pointer to the text string to find the match for. *
  176. * *
  177. * OUTPUT: none *
  178. * *
  179. * WARNINGS: If an exact match to the specified text string could not be found, then the *
  180. * currently selected index is not changed. *
  181. * *
  182. * HISTORY: *
  183. * 07/06/1996 JLB : Created. *
  184. *=============================================================================================*/
  185. void CheckListClass::Set_Selected_Index(char const * text)
  186. {
  187. for (int index = 0; index < Count(); index++) {
  188. CheckObject * obj = (CheckObject *)ListClass::Get_Item(index);
  189. if (obj && stricmp(obj->Text, text) == 0) {
  190. Set_Selected_Index(index);
  191. break;
  192. }
  193. }
  194. }
  195. /***************************************************************************
  196. * CheckListClass::Check_Item -- [un]checks an items *
  197. * *
  198. * INPUT: *
  199. * index index of item to check or uncheck *
  200. * checked 0 = uncheck, non-zero = check *
  201. * *
  202. * OUTPUT: *
  203. * none. *
  204. * *
  205. * WARNINGS: *
  206. * none. *
  207. * *
  208. * HISTORY: *
  209. * 02/16/1995 BR : Created. *
  210. * 02/14/1996 JLB : Revamped. *
  211. *=========================================================================*/
  212. void CheckListClass::Check_Item(int index, bool checked)
  213. {
  214. CheckObject * obj = (CheckObject *)ListClass::Get_Item(index);
  215. if (obj && obj->IsChecked != checked) {
  216. obj->IsChecked = checked;
  217. Flag_To_Redraw();
  218. }
  219. }
  220. /***************************************************************************
  221. * CheckListClass::Is_Checked -- returns checked state of an item *
  222. * *
  223. * INPUT: *
  224. * index index of item to query *
  225. * *
  226. * OUTPUT: *
  227. * 0 = item is unchecked, 1 = item is checked *
  228. * *
  229. * WARNINGS: *
  230. * none. *
  231. * *
  232. * HISTORY: *
  233. * 02/16/1995 BR : Created. *
  234. * 02/14/1996 JLB : Revamped. *
  235. *=========================================================================*/
  236. bool CheckListClass::Is_Checked(int index) const
  237. {
  238. CheckObject * obj = (CheckObject *)ListClass::Get_Item(index);
  239. if (obj) {
  240. return(obj->IsChecked);
  241. }
  242. return(false);
  243. }
  244. /***************************************************************************
  245. * CheckListClass::Action -- action function for this class *
  246. * *
  247. * INPUT: *
  248. * flags the reason we're being called *
  249. * key the KN_number that was pressed *
  250. * *
  251. * OUTPUT: *
  252. * true = event was processed, false = event not processed *
  253. * *
  254. * WARNINGS: *
  255. * none. *
  256. * *
  257. * HISTORY: *
  258. * 02/16/1995 BR : Created. *
  259. *=========================================================================*/
  260. int CheckListClass::Action(unsigned flags, KeyNumType &key)
  261. {
  262. int rc;
  263. /*
  264. ** If this is a read-only list, it's a display-only device
  265. */
  266. if (IsReadOnly) {
  267. return(false);
  268. }
  269. /*
  270. ** Invoke parents Action first, so it can set the SelectedIndex if needed.
  271. */
  272. rc = ListClass::Action(flags, key);
  273. /*
  274. ** Now, if this event was a left-press, toggle the checked state of the
  275. ** current item.
  276. */
  277. if (flags & LEFTPRESS) {
  278. Check_Item(SelectedIndex, !Is_Checked(SelectedIndex));
  279. }
  280. return(rc);
  281. }
  282. /***************************************************************************
  283. * CheckListClass::Draw_Entry -- draws a list box entry *
  284. * *
  285. * INPUT: *
  286. * index index into List of item to draw *
  287. * x,y x,y coords to draw at *
  288. * width maximum width allowed for text *
  289. * selected true = this item is selected *
  290. * *
  291. * OUTPUT: *
  292. * none. *
  293. * *
  294. * WARNINGS: *
  295. * none. *
  296. * *
  297. * HISTORY: *
  298. * 12/14/1995 BRR : Created. *
  299. *=========================================================================*/
  300. void CheckListClass::Draw_Entry(int index, int x, int y, int width, int selected)
  301. {
  302. if (index >= Count()) return;
  303. CheckObject * obj = (CheckObject *)ListClass::Get_Item(index);
  304. if (obj) {
  305. char buffer[100] = "";
  306. if (obj->IsChecked) {
  307. buffer[0] = CHECK_CHAR;
  308. } else {
  309. buffer[0] = UNCHECK_CHAR;
  310. }
  311. buffer[1] = ' ';
  312. sprintf(&buffer[2], obj->Text);
  313. TextPrintType flags = TextFlags;
  314. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  315. if (selected) {
  316. flags = flags | TPF_BRIGHT_COLOR;
  317. LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, scheme->Shadow);
  318. } else {
  319. if (!(flags & TPF_USE_GRAD_PAL)) {
  320. flags = flags | TPF_MEDIUM_COLOR;
  321. }
  322. }
  323. Conquer_Clip_Text_Print(buffer, x, y, scheme, TBLACK, flags, width, Tabs);
  324. }
  325. }