CnC_Remastered_Collection

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

DROP.H (9513B)


      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/DROP.H 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 : DROP.H                                                       *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 07/05/96                                                     *
     28  *                                                                                             *
     29  *                  Last Update : July 5, 1996 [JLB]                                           *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 
     35 #ifndef DROP_H
     36 #define DROP_H
     37 
     38 #include	"list.h"
     39 #include	"edit.h"
     40 
     41 class DropListClass : public EditClass {
     42 	public:
     43 		DropListClass(int id, char * text, int max_len, TextPrintType flags, int x, int y, int w, int h, void const * up, void const * down);
     44 		virtual ~DropListClass(void) {};
     45 
     46 		virtual DropListClass & Add(LinkClass & object);
     47 		virtual DropListClass & Add_Tail(LinkClass & object);
     48 		virtual DropListClass & Add_Head(LinkClass & object);
     49 		virtual DropListClass * Remove(void);
     50 		virtual void Zap(void);
     51 
     52 		virtual int Add_Item(char const * text);
     53 		virtual char const * Current_Item(void);
     54 		virtual int Current_Index(void);
     55 		virtual void Set_Selected_Index(int index);
     56 		virtual void Set_Selected_Index(char const * text);
     57 		virtual void Peer_To_Peer(unsigned flags, KeyNumType &, ControlClass & whom);
     58 		virtual void Clear_Focus(void);
     59 		virtual int Count(void) const {return(List.Count());};
     60 		virtual char const * Get_Item(int index) const {return(List.Get_Item(index));};
     61 
     62 #ifdef WOLAPI_INTEGRATION
     63 		virtual void Flag_To_Redraw(void);
     64 #endif
     65 
     66 		void Expand(void);
     67 		void Collapse(void);
     68 
     69 		virtual void Set_Position(int x, int y);
     70 
     71 		DropListClass & operator = (DropListClass const & list);
     72 		DropListClass(DropListClass const & list);
     73 
     74 		/*
     75 		**	Indicates whether the list box has dropped down or not.
     76 		*/
     77 		unsigned IsDropped:1;
     78 
     79 		/*
     80 		**	Height of list box when it is expanded.
     81 		*/
     82 		int ListHeight;
     83 
     84 		/*
     85 		**	Drop down button.
     86 		*/
     87 		ShapeButtonClass DropButton;
     88 
     89 		/*
     90 		**	List object when it is expanded.
     91 		*/
     92 		ListClass List;
     93 };
     94 
     95 
     96 
     97 
     98 template<class T>
     99 class TDropListClass : public EditClass {
    100 	public:
    101 		TDropListClass(int id, char * text, int max_len, TextPrintType flags, int x, int y, int w, int h, void const * up, void const * down);
    102 		TDropListClass(TDropListClass<T> const & list);
    103 		virtual ~TDropListClass(void) {};
    104 
    105 		T operator [] (int index) const {return(List[index]);};
    106 		T & operator [] (int index) {return(List[index]);};
    107 
    108 		virtual TDropListClass<T> & Add(LinkClass & object);
    109 		virtual TDropListClass<T> & Add_Tail(LinkClass & object);
    110 		virtual TDropListClass<T> & Add_Head(LinkClass & object);
    111 		virtual TDropListClass<T> * Remove(void);
    112 		void Zap(void);
    113 
    114 		virtual int Add_Item(T text);
    115 		virtual T Current_Item(void);
    116 		virtual int Current_Index(void);
    117 		virtual void Set_Selected_Index(int index);
    118 		virtual void Set_Selected_Index(T item);
    119 		virtual void Peer_To_Peer(unsigned flags, KeyNumType &, ControlClass & whom);
    120 		virtual void Clear_Focus(void);
    121 		virtual int Count(void) const {return(List.Count());};
    122 		virtual T Get_Item(int index) const {return(List.Get_Item(index));};
    123 
    124 
    125 		void Expand(void);
    126 		void Collapse(void);
    127 
    128 		virtual void Set_Position(int x, int y);
    129 
    130 		TDropListClass<T> & operator = (TDropListClass<T> const & list);
    131 
    132 		/*
    133 		**	Indicates whether the list box has dropped down or not.
    134 		*/
    135 		unsigned IsDropped:1;
    136 
    137 		/*
    138 		**	Height of list box when it is expanded.
    139 		*/
    140 		int ListHeight;
    141 
    142 		/*
    143 		**	Drop down button.
    144 		*/
    145 		ShapeButtonClass DropButton;
    146 
    147 		/*
    148 		**	List object when it is expanded.
    149 		*/
    150 		TListClass<T> List;
    151 };
    152 
    153 
    154 template<class T>
    155 TDropListClass<T>::TDropListClass(int id, char * text, int max_len, TextPrintType flags, int x, int y, int w, int h, void const * up, void const * down) :
    156 	EditClass(id, text, max_len, flags, x, y, w, 9, ALPHANUMERIC),
    157 	IsDropped(false),
    158 	ListHeight(h),
    159 	DropButton(0, down, x+w, y),
    160 	List(0, x, y+Get_Build_Frame_Height(down), w+Get_Build_Frame_Width(down), h, flags, up, down)
    161 {
    162 	List.Make_Peer(*this);
    163 	DropButton.Make_Peer(*this);
    164 }
    165 
    166 
    167 template<class T>
    168 void TDropListClass<T>::Zap(void)
    169 {
    170 	Collapse();
    171 	List.Zap();
    172 	DropButton.Zap();
    173 	EditClass::Zap();
    174 }
    175 
    176 
    177 template<class T>
    178 TDropListClass<T> & TDropListClass<T>::Add(LinkClass & object)
    179 {
    180 	DropButton.Add(object);
    181 	return((TDropListClass &)EditClass::Add(object));
    182 }
    183 
    184 
    185 template<class T>
    186 TDropListClass<T> & TDropListClass<T>::Add_Tail(LinkClass & object)
    187 {
    188 	DropButton.Add_Tail(object);
    189 	return((TDropListClass &)EditClass::Add_Tail(object));
    190 }
    191 
    192 
    193 template<class T>
    194 TDropListClass<T> & TDropListClass<T>::Add_Head(LinkClass & object)
    195 {
    196 	DropButton.Add_Head(object);
    197 	return((TDropListClass &)EditClass::Add_Head(object));
    198 }
    199 
    200 
    201 template<class T>
    202 TDropListClass<T> * TDropListClass<T>::Remove(void)
    203 {
    204 	if (IsDropped) {
    205 		Collapse();
    206 	}
    207 	DropButton.Remove();
    208 	return((TDropListClass *)EditClass::Remove());
    209 }
    210 
    211 
    212 template<class T>
    213 int TDropListClass<T>::Add_Item(T item)
    214 {
    215 	strncpy(String, item->Description(), MaxLength);
    216 	Flag_To_Redraw();
    217 	return(List.Add_Item(item));
    218 }
    219 
    220 
    221 template<class T>
    222 T TDropListClass<T>::Current_Item(void)
    223 {
    224 	return(List.Current_Item());
    225 }
    226 
    227 
    228 template<class T>
    229 int TDropListClass<T>::Current_Index(void)
    230 {
    231 	return(List.Current_Index());
    232 }
    233 
    234 
    235 template<class T>
    236 void TDropListClass<T>::Set_Selected_Index(int index)
    237 {
    238 	if ((unsigned)index < List.Count()) {
    239 		List.Set_Selected_Index(index);
    240 		strncpy(String, List.Get_Item(Current_Index())->Description(), MaxLength);
    241 	} else {
    242 		String[0] = '\0';
    243 	}
    244 }
    245 
    246 
    247 template<class T>
    248 void TDropListClass<T>::Clear_Focus(void)
    249 {
    250 	Collapse();
    251 }
    252 
    253 
    254 template<class T>
    255 void TDropListClass<T>::Peer_To_Peer(unsigned flags, KeyNumType & key, ControlClass & whom)
    256 {
    257 	if (&whom == &DropButton) {
    258 		if (flags & LEFTRELEASE) {
    259 			if (IsDropped) {
    260 				Collapse();
    261 				key = (KeyNumType)(ID | KN_BUTTON);
    262 			} else {
    263 				Expand();
    264 			}
    265 		}
    266 	}
    267 
    268 	if (&whom == &List) {
    269 		strncpy(String, List.Current_Item()->Description(), MaxLength);
    270 		Flag_To_Redraw();
    271 		key = (KeyNumType)(ID | KN_BUTTON);
    272 	}
    273 }
    274 
    275 
    276 template<class T>
    277 void TDropListClass<T>::Expand(void)
    278 {
    279 	if (!IsDropped) {
    280 		List.X = X;
    281 		List.Y = Y+9;
    282 		List.Width = Width;
    283 		List.Height = ListHeight;
    284 		List.Add(Head_Of_List());
    285 		List.Flag_To_Redraw();
    286 		IsDropped = true;
    287 	}
    288 }
    289 
    290 
    291 template<class T>
    292 void TDropListClass<T>::Collapse(void)
    293 {
    294 	if (IsDropped) {
    295 		List.Remove();
    296 		IsDropped = false;
    297 	}
    298 }
    299 
    300 
    301 template<class T>
    302 TDropListClass<T> & TDropListClass<T>::operator = (TDropListClass<T> const & list)
    303 {
    304 	if (this == &list) return(*this);
    305 	EditClass::operator =(list);
    306 	List = list.List;
    307 	IsDropped = list.IsDropped;
    308 	ListHeight = list.ListHeight;
    309 	DropButton = list.DropButton;
    310 	List.Make_Peer(*this);
    311 	DropButton.Make_Peer(*this);
    312 	return(*this);
    313 }
    314 
    315 
    316 template<class T>
    317 TDropListClass<T>::TDropListClass(TDropListClass<T> const & list) :
    318 	EditClass(list),
    319 	IsDropped(list.IsDropped),
    320 	ListHeight(list.ListHeight),
    321 	DropButton(list.DropButton),
    322 	List(list.List)
    323 {
    324 	List.Make_Peer(*this);
    325 	DropButton.Make_Peer(*this);
    326 }
    327 
    328 
    329 template<class T>
    330 void TDropListClass<T>::Set_Position(int x, int y)
    331 {
    332 	EditClass::Set_Position(x, y);
    333 	List.Set_Position(x, y + Get_Build_Frame_Height(DropButton.Get_Shape_Data()));
    334 	DropButton.Set_Position(x + Width, y);
    335 }
    336 
    337 
    338 template<class T>
    339 void TDropListClass<T>::Set_Selected_Index(T text)
    340 {
    341 	for (int index = 0; index < Count(); index++) {
    342 		if (text == List.Get_Item(index)) {
    343 			Set_Selected_Index(index);
    344 			break;
    345 		}
    346 	}
    347 }
    348 
    349 
    350 #endif