DROP.CPP 6.1 KB

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