CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

CHEKLIST.CPP (20614B)


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