DROP.CPP 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.CPP 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.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 01/24/96 *
  30. * *
  31. * Last Update : January 24, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #include "function.h"
  37. #include "drop.h"
  38. DropListClass::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. EditClass(id, text, max_len, flags, x, y, w, 9*RESFACTOR, ALPHANUMERIC),
  40. IsDropped(false),
  41. ListHeight(h),
  42. DropButton(0, down, x+w, y),
  43. List(0, x, y+Get_Build_Frame_Height(down), w+Get_Build_Frame_Width(down), h, flags, up, down)
  44. {
  45. Fancy_Text_Print("", 0, 0, 0, 0, flags);
  46. EditClass::Height = FontHeight+1;
  47. List.Make_Peer(*this);
  48. DropButton.Make_Peer(*this);
  49. }
  50. void DropListClass::Zap(void)
  51. {
  52. Collapse();
  53. List.Zap();
  54. DropButton.Zap();
  55. EditClass::Zap();
  56. }
  57. DropListClass & DropListClass::Add(LinkClass & object)
  58. {
  59. DropButton.Add(object);
  60. return((DropListClass &)EditClass::Add(object));
  61. }
  62. DropListClass & DropListClass::Add_Tail(LinkClass & object)
  63. {
  64. DropButton.Add_Tail(object);
  65. return((DropListClass &)EditClass::Add_Tail(object));
  66. }
  67. DropListClass & DropListClass::Add_Head(LinkClass & object)
  68. {
  69. DropButton.Add_Head(object);
  70. return((DropListClass &)EditClass::Add_Head(object));
  71. }
  72. DropListClass * DropListClass::Remove(void)
  73. {
  74. if (IsDropped) {
  75. Collapse();
  76. }
  77. DropButton.Remove();
  78. return((DropListClass *)EditClass::Remove());
  79. }
  80. int DropListClass::Add_Item(char const * text)
  81. {
  82. strncpy(String, text, MaxLength);
  83. Flag_To_Redraw();
  84. return(List.Add_Item(text));
  85. }
  86. char const * DropListClass::Current_Item(void)
  87. {
  88. return(List.Current_Item());
  89. }
  90. int DropListClass::Current_Index(void)
  91. {
  92. return(List.Current_Index());
  93. }
  94. void DropListClass::Set_Selected_Index(int index)
  95. {
  96. if ((unsigned)index < List.Count()) {
  97. List.Set_Selected_Index(index);
  98. strcpy(String, List.Get_Item(Current_Index()));
  99. } else {
  100. String[0] = '\0';
  101. }
  102. }
  103. void DropListClass::Clear_Focus(void)
  104. {
  105. Collapse();
  106. }
  107. void DropListClass::Peer_To_Peer(unsigned flags, KeyNumType & key, ControlClass & whom)
  108. {
  109. if (&whom == &DropButton) {
  110. if (flags & LEFTRELEASE) {
  111. if (IsDropped) {
  112. Collapse();
  113. key = (KeyNumType)(ID | KN_BUTTON);
  114. } else {
  115. Expand();
  116. }
  117. }
  118. }
  119. if (&whom == &List) {
  120. strncpy(String, List.Current_Item(), MaxLength);
  121. Flag_To_Redraw();
  122. key = (KeyNumType)(ID | KN_BUTTON);
  123. }
  124. }
  125. void DropListClass::Expand(void)
  126. {
  127. if (!IsDropped) {
  128. List.X = X;
  129. List.Y = Y+9*RESFACTOR;
  130. List.Width = Width;
  131. List.Height = ListHeight;
  132. List.Add(Head_Of_List());
  133. List.Flag_To_Redraw();
  134. IsDropped = true;
  135. }
  136. }
  137. void DropListClass::Collapse(void)
  138. {
  139. if (IsDropped) {
  140. List.Remove();
  141. IsDropped = false;
  142. }
  143. }
  144. DropListClass & DropListClass::operator = (DropListClass const & list)
  145. {
  146. if (this == &list) return(*this);
  147. EditClass::operator =(list);
  148. List = list.List;
  149. IsDropped = list.IsDropped;
  150. ListHeight = list.ListHeight;
  151. DropButton = list.DropButton;
  152. List.Make_Peer(*this);
  153. DropButton.Make_Peer(*this);
  154. return(*this);
  155. }
  156. DropListClass::DropListClass(DropListClass const & list) :
  157. EditClass(list),
  158. IsDropped(list.IsDropped),
  159. ListHeight(list.ListHeight),
  160. DropButton(list.DropButton),
  161. List(list.List)
  162. {
  163. List.Make_Peer(*this);
  164. DropButton.Make_Peer(*this);
  165. }
  166. void DropListClass::Set_Position(int x, int y)
  167. {
  168. EditClass::Set_Position(x, y);
  169. List.Set_Position(x, y + Get_Build_Frame_Height(DropButton.Get_Shape_Data()));
  170. DropButton.Set_Position(x + Width, y);
  171. }
  172. void DropListClass::Set_Selected_Index(char const * text)
  173. {
  174. if (text) {
  175. for (int index = 0; index < Count(); index++) {
  176. if (stricmp(text, List.Get_Item(index)) == 0) {
  177. Set_Selected_Index(index);
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. #ifdef WOLAPI_INTEGRATION
  184. void DropListClass::Flag_To_Redraw(void)
  185. {
  186. if( IsDropped )
  187. List.Flag_To_Redraw();
  188. EditClass::Flag_To_Redraw();
  189. }
  190. #endif