CHEKLIST.CPP (8950B)
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 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: F:\projects\c&c\vcs\code\cheklist.cpv 2.18 16 Oct 1995 16:48:36 JOE_BOSTIC $ */ 17 /*************************************************************************** 18 ** 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 ** 19 *************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : CHEKLIST.CPP * 24 * * 25 * Programmer : Bill Randolph * 26 * * 27 * Start Date : February 16, 1995 * 28 * * 29 * Last Update : February 16, 1995 [BR] * 30 * * 31 *-------------------------------------------------------------------------* 32 * Functions: * 33 * CheckListClass::Action -- action function for this class * 34 * CheckListClass::CheckListClass -- constructor * 35 * CheckListClass::Check_Item -- [un]checks an items * 36 * CheckListClass::~CheckListClass -- destructor * 37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 38 39 #include "function.h" 40 41 42 /*************************************************************************** 43 * CheckListClass::CheckListClass -- constructor * 44 * * 45 * INPUT: * 46 * id control ID for this list box * 47 * x x-coord * 48 * y y-coord * 49 * w width * 50 * h height * 51 * flags mouse event flags * 52 * up ptr to Up-arrow shape * 53 * down ptr to Down-arrow shape * 54 * * 55 * OUTPUT: * 56 * none. * 57 * * 58 * WARNINGS: * 59 * none. * 60 * * 61 * HISTORY: * 62 * 02/16/1995 BR : Created. * 63 *=========================================================================*/ 64 CheckListClass::CheckListClass(int id, int x, int y, int w, int h, TextPrintType flags, 65 void const * up, void const * down) : 66 ListClass (id, x, y, w, h, flags, up, down) 67 { 68 IsReadOnly = false; 69 } 70 71 72 /*************************************************************************** 73 * CheckListClass::Check_Item -- [un]checks an items * 74 * * 75 * INPUT: * 76 * index index of item to check or uncheck * 77 * checked 0 = uncheck, non-zero = check * 78 * * 79 * OUTPUT: * 80 * none. * 81 * * 82 * WARNINGS: * 83 * none. * 84 * * 85 * HISTORY: * 86 * 02/16/1995 BR : Created. * 87 *=========================================================================*/ 88 void CheckListClass::Check_Item(int index, int checked) 89 { 90 if (List[index]) { 91 ((char &)List[index][0]) = checked ? CHECK_CHAR : UNCHECK_CHAR; 92 } 93 } 94 95 96 /*************************************************************************** 97 * CheckListClass::Is_Checked -- returns checked state of an item * 98 * * 99 * INPUT: * 100 * index index of item to query * 101 * * 102 * OUTPUT: * 103 * 0 = item is unchecked, 1 = item is checked * 104 * * 105 * WARNINGS: * 106 * none. * 107 * * 108 * HISTORY: * 109 * 02/16/1995 BR : Created. * 110 *=========================================================================*/ 111 int CheckListClass::Is_Checked(int index) const 112 { 113 if (List[index]) { 114 return(List[index][0] == CHECK_CHAR); 115 } 116 return(false); 117 } 118 119 120 /*************************************************************************** 121 * CheckListClass::Action -- action function for this class * 122 * * 123 * INPUT: * 124 * flags the reason we're being called * 125 * key the KN_number that was pressed * 126 * * 127 * OUTPUT: * 128 * true = event was processed, false = event not processed * 129 * * 130 * WARNINGS: * 131 * none. * 132 * * 133 * HISTORY: * 134 * 02/16/1995 BR : Created. * 135 *=========================================================================*/ 136 int CheckListClass::Action(unsigned flags, KeyNumType &key) 137 { 138 int rc; 139 140 /* 141 ** If this is a read-only list, it's a display-only device 142 */ 143 if (IsReadOnly) { 144 return(false); 145 } 146 147 /* 148 ** Invoke parents Action first, so it can set the SelectedIndex if needed. 149 */ 150 rc = ListClass::Action(flags, key); 151 152 /* 153 ** Now, if this event was a left-press, toggle the checked state of the 154 ** current item. 155 */ 156 if (flags & LEFTPRESS) { 157 if (Is_Checked(SelectedIndex)) { 158 Check_Item(SelectedIndex,0); 159 } else { 160 Check_Item(SelectedIndex,1); 161 } 162 } 163 164 return(rc); 165 }