CHEKLIST.CPP 20 KB

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