1 /*****************************************************************************/
2 /* */
3 /* RESUTIL.CC */
4 /* */
5 /* (C) 1993-95 Ullrich von Bassewitz */
6 /* Wacholderweg 14 */
7 /* D-70597 Stuttgart */
8 /* EMail: uz@ibb.schwaben.com */
9 /* */
10 /*****************************************************************************/
11
12
13
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19
20
21
22 #include "resed.h"
23
24
25
26 /*****************************************************************************/
27 /* class ResEditApp */
28 /*****************************************************************************/
29
30
31
DeleteRes()32 void ResEditApp::DeleteRes ()
33 {
34 delete Res;
35 Res = 0;
36 ResID = 0;
37 ResChanged = 0;
38
39 // Change menue entries
40 MainMenue->GrayItem (miWindow);
41 MainMenue->GrayItem (miItems);
42 MainMenue->GrayItem (miEditActions);
43 MainMenue->GrayItem (miPrint);
44 MainMenue->GrayItem (miWrite);
45
46 }
47
48
49
AssignRes(Streamable * NewRes)50 void ResEditApp::AssignRes (Streamable *NewRes)
51 {
52 GenericMenue* M;
53
54 // Delete the old resource, assign the new one
55 DeleteRes ();
56 Res = NewRes;
57 ResID = NewRes->StreamableID ();
58
59 // Change menue entries according to the resource type
60 switch (ResID) {
61
62 case ID_TopMenueBar:
63 // Move the TopMenueBar into the visible area
64 ((TopMenueBar*)Res)->MoveAbs (Point (0, 1));
65 case ID_Menue:
66 M = (GenericMenue*) Res;
67 MainMenue->SetToggleValue (miCanMove, M->CanMove ());
68 MainMenue->SetToggleValue (miCanResize, M->CanResize ());
69 MainMenue->SetToggleValue (miModal, M->IsModal ());
70 MainMenue->SetToggleValue (miLRLink, M->HasLRLink ());
71 MainMenue->SetToggleValue (miIgnoreAccept, M->IgnoreAccept ());
72 MainMenue->SetToggleValue (miVisible, M->SaveVisible ());
73 MainMenue->ActivateItem (miWindow);
74 MainMenue->ActivateItem (miItems);
75 MainMenue->ActivateItem (miPrint);
76 if (ResFile) {
77 MainMenue->ActivateItem (miWrite);
78 }
79 M->Show ();
80 break;
81
82 case ID_MsgCollection:
83 MainMenue->ActivateItem (miEditActions);
84 MainMenue->ActivateItem (miPrint);
85 if (ResFile) {
86 MainMenue->ActivateItem (miWrite);
87 }
88 break;
89
90 default:
91 DeleteRes ();
92 ErrorMsg ("Unknown resource type, deleting");
93 break;
94
95 }
96
97 }
98
99
100
101
NamePrompt(const String & Name,String & Val,int & Abort)102 void ResEditApp::NamePrompt (const String &Name, String &Val, int &Abort)
103 {
104 // Calculate the size of the window
105 const Rect& Screen = Background->OuterBounds ();
106 Rect Bounds;
107 Bounds.A.X = 2;
108 Bounds.A.Y = Screen.YSize () / 2;
109 Bounds.B.X = Screen.XSize () - 2;
110 Bounds.B.Y = Bounds.A.Y + 3;
111
112 // Create a window with an edit item
113 int Length = Name.Len ();
114 EditLine* E = new EditLine (Name, 1, 1024, Bounds.XSize () - Length - 6, NULL);
115 ItemWindow* Win = new ItemWindow (Bounds, wfFramed, paGray, 0, E);
116
117 // Set the default
118 E->SetValue (Val);
119
120 // Edit the string
121 E->Edit (Abort);
122 if (!Abort) {
123 Val = E->GetValue ();
124 }
125
126 // Delete the window including the edit item
127 delete Win;
128 }
129
130
131
FloatPrompt(const String & Text,double & Val,double Min,double Max,int & Abort)132 void ResEditApp::FloatPrompt (const String& Text, double& Val,
133 double Min, double Max, int& Abort)
134 {
135 // Create a new edit item
136 FloatEdit *F = new FloatEdit (Text, 1, 10, 3, NULL);
137
138 // Calculate the size of the window
139 Rect ScreenSize (Background->OuterBounds ());
140 Rect Bounds (0, 0, F->MinWidth () + 2, 3);
141 Bounds.Center (ScreenSize, cfCenterAll);
142
143 // Create a window and insert the edit item
144 F->SetMinMax (Min, Max);
145 ItemWindow *Win = new ItemWindow (Bounds, wfFramed, paGray, 0, F);
146
147 // Set the default
148 F->SetValue (Val);
149
150 // Edit the string
151 F->Edit (Abort);
152 if (!Abort) {
153 Val = F->GetValue ();
154 }
155
156 // Delete the window including the edit item
157 delete Win;
158 }
159
160
161
LongPrompt(const String & Text,i32 & Val,i32 Min,i32 Max,int & Abort)162 void ResEditApp::LongPrompt (const String & Text, i32 &Val, i32 Min, i32 Max, int &Abort)
163 {
164 // Create a new edit item
165 LongEdit *L = new LongEdit (Text, 1, 8, NULL);
166
167 // Calculate the size of the window
168 Rect ScreenSize (Background->OuterBounds ());
169 Rect Bounds (0, 0, L->MinWidth () + 2, 3);
170 Bounds.Center (ScreenSize, cfCenterAll);
171
172 // Create a window and insert the edit item
173 L->SetMinMax (Min, Max);
174 ItemWindow *Win = new ItemWindow (Bounds, wfFramed, paGray, 0, L);
175
176 // Set the default
177 L->SetValue (Val);
178
179 // Edit the string
180 L->Edit (Abort);
181 if (!Abort) {
182 Val = L->GetValue ();
183 }
184
185 // Delete the window including the edit item
186 delete Win;
187 }
188
189
190
IDPrompt(i16 & ID,int & Abort)191 void ResEditApp::IDPrompt (i16& ID, int& Abort)
192 {
193 // Use a 32 bit int for temp val
194 i32 ID32 = ID;
195
196 // Get the id
197 LongPrompt (" ID", ID32, 1, 32000, Abort);
198 ID = (i16) ID32;
199 }
200
201
202
EditIDPrompt(i16 & ID,int & Abort)203 void ResEditApp::EditIDPrompt (i16 &ID, int &Abort)
204 {
205 // Use a 32 bit int for temp val
206 i32 ID32 = ID;
207
208 // Get the id
209 LongPrompt (" Edit ID", ID32, 0, 32000, Abort);
210 ID = (i16) ID32;
211 }
212
213
214
MinMaxPrompt(i32 & Min,i32 & Max,i32 MinVal,i32 MaxVal,int & Abort)215 void ResEditApp::MinMaxPrompt (i32 &Min, i32 &Max, i32 MinVal, i32 MaxVal, int &Abort)
216 {
217 if (Min < MinVal) {
218 Min = MinVal;
219 }
220 LongPrompt (" Minimum value", Min, MinVal, MaxVal, Abort);
221 if (Abort) {
222 return;
223 }
224 if (Max < Min) {
225 Max = Min;
226 }
227 if (Max > MaxVal) {
228 Max = MaxVal;
229 }
230 LongPrompt (" Maximum value", Max, Min, MaxVal, Abort);
231 if (Abort) {
232 return;
233 }
234 }
235
236
237
FMinMaxPrompt(double & Min,double & Max,double MinVal,double MaxVal,int & Abort)238 void ResEditApp::FMinMaxPrompt (double& Min, double& Max, double MinVal,
239 double MaxVal, int &Abort)
240 {
241 if (Min < MinVal) {
242 Min = MinVal;
243 }
244 FloatPrompt (" Minimum value", Min, MinVal, MaxVal, Abort);
245 if (Abort) {
246 return;
247 }
248 if (Max < Min) {
249 Max = Min;
250 }
251 if (Max > MaxVal) {
252 Max = MaxVal;
253 }
254 FloatPrompt (" Maximum value", Max, Min, MaxVal, Abort);
255 if (Abort) {
256 return;
257 }
258 }
259
260
261
TextIDPrompt(String & Text,i16 & ID,int & Abort)262 void ResEditApp::TextIDPrompt (String &Text, i16 &ID, int &Abort)
263 {
264 // Choose the next possible ID
265 ID = NextID ();
266
267 // Edit the ID
268 IDPrompt (ID, Abort);
269 if (Abort) {
270 return;
271 }
272
273 // Edit the text
274 NamePrompt (" Text", Text, Abort);
275 }
276
277
278
SaveResource()279 int ResEditApp::SaveResource ()
280 //
281 {
282 if (Res && ResChanged) {
283
284 switch (AskSaveChanges ()) {
285
286 case 0:
287 //Abort
288 return 0;
289
290 case 1:
291 // No
292 return 1;
293
294 case 2:
295 // Yes
296 if (ResFile == NULL) {
297 ErrorMsg ("^!!! No resource file !!!|^"
298 "Choose ~No~ the next time,^"
299 "or open a resource file first!|");
300 return 0; // Abort;
301 } else {
302 Write ();
303 // Return true only if the save has been successful
304 return (ResChanged == 0);
305 }
306
307 }
308
309 }
310
311 // No change, always successful
312 return 1;
313 }
314
315
316
317