DROP.H 9.3 KB

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