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