DROP.H 9.2 KB

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