]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: prop.cpp | |
3 | // Purpose: Propert sheet classes implementation | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "prop.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx/wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
27 | #include <ctype.h> | |
28 | #include <stdlib.h> | |
29 | #include <math.h> | |
30 | #include <string.h> | |
31 | ||
48df9992 | 32 | #if wxUSE_IOSTREAMH |
2049ba38 | 33 | #if defined(__WXMSW__) && !defined(__GNUWIN32__) |
457814b5 JS |
34 | #include <strstrea.h> |
35 | #else | |
36 | #include <strstream.h> | |
37 | #endif | |
48df9992 UU |
38 | #else |
39 | #include <strstream> | |
40 | #endif | |
457814b5 JS |
41 | |
42 | #include "wx/window.h" | |
43 | #include "wx/utils.h" | |
44 | #include "wx/list.h" | |
45 | #include "prop.h" | |
46 | ||
47 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyValue, wxObject) | |
48 | ||
49 | wxPropertyValue::wxPropertyValue(void) | |
50 | { | |
fd71308f JS |
51 | m_type = wxPropertyValueNull; |
52 | m_next = NULL; | |
53 | m_last = NULL; | |
54 | m_value.first = NULL; | |
55 | m_clientData = NULL; | |
56 | m_modifiedFlag = FALSE; | |
457814b5 JS |
57 | } |
58 | ||
59 | wxPropertyValue::wxPropertyValue(const wxPropertyValue& copyFrom) | |
60 | { | |
fd71308f | 61 | m_modifiedFlag = FALSE; |
457814b5 JS |
62 | Copy((wxPropertyValue& )copyFrom); |
63 | } | |
64 | ||
65 | wxPropertyValue::wxPropertyValue(const char *val) | |
66 | { | |
fd71308f JS |
67 | m_modifiedFlag = FALSE; |
68 | m_type = wxPropertyValueString; | |
457814b5 | 69 | |
fd71308f JS |
70 | m_value.string = copystring(val); |
71 | m_clientData = NULL; | |
72 | m_next = NULL; | |
73 | m_last = NULL; | |
457814b5 JS |
74 | } |
75 | ||
76 | wxPropertyValue::wxPropertyValue(const wxString& val) | |
77 | { | |
fd71308f JS |
78 | m_modifiedFlag = FALSE; |
79 | m_type = wxPropertyValueString; | |
457814b5 | 80 | |
fd71308f JS |
81 | m_value.string = copystring((const char *)val); |
82 | m_clientData = NULL; | |
83 | m_next = NULL; | |
84 | m_last = NULL; | |
457814b5 JS |
85 | } |
86 | ||
87 | wxPropertyValue::wxPropertyValue(long the_integer) | |
88 | { | |
fd71308f JS |
89 | m_modifiedFlag = FALSE; |
90 | m_type = wxPropertyValueInteger; | |
91 | m_value.integer = the_integer; | |
92 | m_clientData = NULL; | |
93 | m_next = NULL; | |
457814b5 JS |
94 | } |
95 | ||
96 | wxPropertyValue::wxPropertyValue(bool val) | |
97 | { | |
fd71308f JS |
98 | m_modifiedFlag = FALSE; |
99 | m_type = wxPropertyValuebool; | |
100 | m_value.integer = val; | |
101 | m_clientData = NULL; | |
102 | m_next = NULL; | |
457814b5 JS |
103 | } |
104 | ||
105 | wxPropertyValue::wxPropertyValue(float the_real) | |
106 | { | |
fd71308f JS |
107 | m_modifiedFlag = FALSE; |
108 | m_type = wxPropertyValueReal; | |
109 | m_value.real = the_real; | |
110 | m_clientData = NULL; | |
111 | m_next = NULL; | |
457814b5 JS |
112 | } |
113 | ||
114 | wxPropertyValue::wxPropertyValue(double the_real) | |
115 | { | |
fd71308f JS |
116 | m_modifiedFlag = FALSE; |
117 | m_type = wxPropertyValueReal; | |
118 | m_value.real = (float)the_real; | |
119 | m_clientData = NULL; | |
120 | m_next = NULL; | |
457814b5 JS |
121 | } |
122 | ||
123 | // Pointer versions: we have a pointer to the real C++ value. | |
124 | wxPropertyValue::wxPropertyValue(char **val) | |
125 | { | |
fd71308f JS |
126 | m_modifiedFlag = FALSE; |
127 | m_type = wxPropertyValueStringPtr; | |
457814b5 | 128 | |
fd71308f JS |
129 | m_value.stringPtr = val; |
130 | m_clientData = NULL; | |
131 | m_next = NULL; | |
132 | m_last = NULL; | |
457814b5 JS |
133 | } |
134 | ||
135 | wxPropertyValue::wxPropertyValue(long *val) | |
136 | { | |
fd71308f JS |
137 | m_modifiedFlag = FALSE; |
138 | m_type = wxPropertyValueIntegerPtr; | |
139 | m_value.integerPtr = val; | |
140 | m_clientData = NULL; | |
141 | m_next = NULL; | |
457814b5 JS |
142 | } |
143 | ||
144 | wxPropertyValue::wxPropertyValue(bool *val) | |
145 | { | |
fd71308f JS |
146 | m_modifiedFlag = FALSE; |
147 | m_type = wxPropertyValueboolPtr; | |
148 | m_value.boolPtr = val; | |
149 | m_clientData = NULL; | |
150 | m_next = NULL; | |
457814b5 JS |
151 | } |
152 | ||
153 | wxPropertyValue::wxPropertyValue(float *val) | |
154 | { | |
fd71308f JS |
155 | m_modifiedFlag = FALSE; |
156 | m_type = wxPropertyValueRealPtr; | |
157 | m_value.realPtr = val; | |
158 | m_clientData = NULL; | |
159 | m_next = NULL; | |
457814b5 JS |
160 | } |
161 | ||
162 | wxPropertyValue::wxPropertyValue(wxList *the_list) | |
163 | { | |
fd71308f JS |
164 | m_modifiedFlag = FALSE; |
165 | m_type = wxPropertyValueList; | |
166 | m_clientData = NULL; | |
167 | m_last = NULL; | |
168 | m_value.first = NULL; | |
457814b5 JS |
169 | |
170 | wxNode *node = the_list->First(); | |
171 | while (node) | |
172 | { | |
173 | wxPropertyValue *expr = (wxPropertyValue *)node->Data(); | |
174 | Append(expr); | |
175 | node = node->Next(); | |
176 | } | |
177 | ||
178 | delete the_list; | |
179 | } | |
180 | ||
181 | wxPropertyValue::wxPropertyValue(wxStringList *the_list) | |
182 | { | |
fd71308f JS |
183 | m_modifiedFlag = FALSE; |
184 | m_type = wxPropertyValueList; | |
185 | m_clientData = NULL; | |
186 | m_last = NULL; | |
187 | m_value.first = NULL; | |
457814b5 JS |
188 | |
189 | wxNode *node = the_list->First(); | |
190 | while (node) | |
191 | { | |
192 | char *s = (char *)node->Data(); | |
193 | Append(new wxPropertyValue(s)); | |
194 | node = node->Next(); | |
195 | } | |
196 | delete the_list; | |
197 | } | |
198 | ||
199 | wxPropertyValue::~wxPropertyValue(void) | |
200 | { | |
fd71308f | 201 | switch (m_type) |
457814b5 JS |
202 | { |
203 | case wxPropertyValueInteger: | |
204 | case wxPropertyValuebool: | |
205 | case wxPropertyValueReal: | |
206 | { | |
207 | break; | |
208 | } | |
209 | case wxPropertyValueString: | |
210 | { | |
fd71308f | 211 | delete m_value.string; |
457814b5 JS |
212 | break; |
213 | } | |
214 | case wxPropertyValueList: | |
215 | { | |
fd71308f | 216 | wxPropertyValue *expr = m_value.first; |
457814b5 JS |
217 | while (expr) |
218 | { | |
fd71308f | 219 | wxPropertyValue *expr1 = expr->m_next; |
457814b5 JS |
220 | |
221 | delete expr; | |
222 | expr = expr1; | |
223 | } | |
224 | break; | |
225 | } | |
226 | default: | |
227 | case wxPropertyValueNull: break; | |
228 | } | |
229 | } | |
230 | ||
231 | void wxPropertyValue::Append(wxPropertyValue *expr) | |
232 | { | |
fd71308f JS |
233 | m_modifiedFlag = TRUE; |
234 | if (!m_value.first) | |
235 | m_value.first = expr; | |
457814b5 | 236 | |
fd71308f JS |
237 | if (m_last) |
238 | m_last->m_next = expr; | |
239 | m_last = expr; | |
457814b5 JS |
240 | } |
241 | ||
242 | void wxPropertyValue::Insert(wxPropertyValue *expr) | |
243 | { | |
fd71308f JS |
244 | m_modifiedFlag = TRUE; |
245 | expr->m_next = m_value.first; | |
246 | m_value.first = expr; | |
457814b5 | 247 | |
fd71308f JS |
248 | if (!m_last) |
249 | m_last = expr; | |
457814b5 JS |
250 | } |
251 | ||
252 | // Delete from list | |
253 | void wxPropertyValue::Delete(wxPropertyValue *node) | |
254 | { | |
255 | wxPropertyValue *expr = GetFirst(); | |
256 | ||
257 | wxPropertyValue *previous = NULL; | |
258 | while (expr && (expr != node)) | |
259 | { | |
260 | previous = expr; | |
261 | expr = expr->GetNext(); | |
262 | } | |
263 | ||
264 | if (expr) | |
265 | { | |
266 | if (previous) | |
fd71308f | 267 | previous->m_next = expr->m_next; |
457814b5 JS |
268 | |
269 | // If node was the first in the list, | |
270 | // make the list point to the NEXT one. | |
271 | if (GetFirst() == expr) | |
272 | { | |
fd71308f | 273 | m_value.first = expr->m_next; |
457814b5 JS |
274 | } |
275 | ||
276 | // If node was the last in the list, | |
277 | // make the list 'last' pointer point to the PREVIOUS one. | |
278 | if (GetLast() == expr) | |
279 | { | |
280 | if (previous) | |
fd71308f | 281 | m_last = previous; |
457814b5 | 282 | else |
fd71308f | 283 | m_last = NULL; |
457814b5 | 284 | } |
fd71308f | 285 | m_modifiedFlag = TRUE; |
457814b5 JS |
286 | delete expr; |
287 | } | |
288 | ||
289 | } | |
290 | ||
291 | void wxPropertyValue::ClearList(void) | |
292 | { | |
293 | wxPropertyValue *val = GetFirst(); | |
294 | if (val) | |
fd71308f JS |
295 | m_modifiedFlag = TRUE; |
296 | ||
457814b5 JS |
297 | while (val) |
298 | { | |
299 | wxPropertyValue *next = val->GetNext(); | |
300 | delete val; | |
301 | val = next; | |
302 | } | |
fd71308f JS |
303 | m_value.first = NULL; |
304 | m_last = NULL; | |
457814b5 JS |
305 | } |
306 | ||
fd71308f | 307 | wxPropertyValue *wxPropertyValue::NewCopy(void) const |
457814b5 | 308 | { |
fd71308f | 309 | switch (m_type) |
457814b5 JS |
310 | { |
311 | case wxPropertyValueInteger: | |
fd71308f | 312 | return new wxPropertyValue(m_value.integer); |
457814b5 | 313 | case wxPropertyValuebool: |
fd71308f | 314 | return new wxPropertyValue((bool) (m_value.integer != 0)); |
457814b5 | 315 | case wxPropertyValueReal: |
fd71308f | 316 | return new wxPropertyValue(m_value.real); |
457814b5 | 317 | case wxPropertyValueString: |
fd71308f | 318 | return new wxPropertyValue(m_value.string); |
457814b5 JS |
319 | case wxPropertyValueList: |
320 | { | |
fd71308f | 321 | wxPropertyValue *expr = m_value.first; |
457814b5 JS |
322 | wxPropertyValue *new_list = new wxPropertyValue; |
323 | new_list->SetType(wxPropertyValueList); | |
324 | while (expr) | |
325 | { | |
326 | wxPropertyValue *expr2 = expr->NewCopy(); | |
327 | new_list->Append(expr2); | |
fd71308f | 328 | expr = expr->m_next; |
457814b5 JS |
329 | } |
330 | return new_list; | |
331 | } | |
332 | case wxPropertyValueIntegerPtr: | |
fd71308f | 333 | return new wxPropertyValue(m_value.integerPtr); |
457814b5 | 334 | case wxPropertyValueRealPtr: |
fd71308f | 335 | return new wxPropertyValue(m_value.realPtr); |
457814b5 | 336 | case wxPropertyValueboolPtr: |
fd71308f | 337 | return new wxPropertyValue(m_value.boolPtr); |
457814b5 | 338 | case wxPropertyValueStringPtr: |
fd71308f | 339 | return new wxPropertyValue(m_value.stringPtr); |
457814b5 JS |
340 | |
341 | case wxPropertyValueNull: | |
342 | #ifdef __X__ | |
343 | cerr << "Should never get here!\n"; | |
344 | #endif | |
345 | break; | |
346 | } | |
347 | return NULL; | |
348 | } | |
349 | ||
350 | void wxPropertyValue::Copy(wxPropertyValue& copyFrom) | |
351 | { | |
fd71308f JS |
352 | m_type = copyFrom.Type(); |
353 | ||
354 | switch (m_type) | |
457814b5 JS |
355 | { |
356 | case wxPropertyValueInteger: | |
357 | (*this) = copyFrom.IntegerValue(); | |
358 | return ; | |
359 | ||
360 | case wxPropertyValueReal: | |
361 | (*this) = copyFrom.RealValue(); | |
362 | return ; | |
363 | ||
364 | case wxPropertyValueString: | |
365 | (*this) = wxString(copyFrom.StringValue()); | |
366 | return ; | |
367 | ||
368 | case wxPropertyValuebool: | |
369 | (*this) = copyFrom.BoolValue(); | |
370 | return ; | |
371 | ||
372 | // Pointers | |
373 | case wxPropertyValueboolPtr: | |
374 | (*this) = copyFrom.BoolValuePtr(); | |
375 | return ; | |
376 | case wxPropertyValueRealPtr: | |
377 | (*this) = copyFrom.RealValuePtr(); | |
378 | return ; | |
379 | case wxPropertyValueIntegerPtr: | |
380 | (*this) = copyFrom.IntegerValuePtr(); | |
381 | return ; | |
382 | case wxPropertyValueStringPtr: | |
cc79e53c JS |
383 | { |
384 | char** s = copyFrom.StringValuePtr(); | |
385 | (*this) = s; | |
457814b5 | 386 | return ; |
cc79e53c | 387 | } |
457814b5 JS |
388 | |
389 | case wxPropertyValueList: | |
390 | { | |
fd71308f JS |
391 | m_value.first = NULL; |
392 | m_next = NULL; | |
393 | m_last = NULL; | |
394 | wxPropertyValue *expr = copyFrom.m_value.first; | |
457814b5 JS |
395 | while (expr) |
396 | { | |
397 | wxPropertyValue *expr2 = expr->NewCopy(); | |
398 | Append(expr2); | |
fd71308f | 399 | expr = expr->m_next; |
457814b5 JS |
400 | } |
401 | return; | |
402 | } | |
403 | case wxPropertyValueNull: | |
404 | #ifdef __X__ | |
405 | cerr << "Should never get here!\n"; | |
406 | #endif | |
407 | break; | |
408 | } | |
409 | } | |
410 | ||
411 | // Return nth argument of a clause (starting from 1) | |
fd71308f | 412 | wxPropertyValue *wxPropertyValue::Arg(wxPropertyValueType type, int arg) const |
457814b5 | 413 | { |
fd71308f | 414 | wxPropertyValue *expr = m_value.first; |
457814b5 JS |
415 | for (int i = 1; i < arg; i++) |
416 | if (expr) | |
fd71308f | 417 | expr = expr->m_next; |
457814b5 | 418 | |
fd71308f | 419 | if (expr && (expr->m_type == type)) |
457814b5 JS |
420 | return expr; |
421 | else | |
422 | return NULL; | |
423 | } | |
424 | ||
425 | // Return nth argument of a list expression (starting from zero) | |
fd71308f | 426 | wxPropertyValue *wxPropertyValue::Nth(int arg) const |
457814b5 | 427 | { |
fd71308f | 428 | if (m_type != wxPropertyValueList) |
457814b5 JS |
429 | return NULL; |
430 | ||
fd71308f | 431 | wxPropertyValue *expr = m_value.first; |
457814b5 JS |
432 | for (int i = 0; i < arg; i++) |
433 | if (expr) | |
fd71308f | 434 | expr = expr->m_next; |
457814b5 JS |
435 | else return NULL; |
436 | ||
437 | if (expr) | |
438 | return expr; | |
439 | else | |
440 | return NULL; | |
441 | } | |
442 | ||
443 | // Returns the number of elements in a list expression | |
fd71308f | 444 | int wxPropertyValue::Number(void) const |
457814b5 | 445 | { |
fd71308f | 446 | if (m_type != wxPropertyValueList) |
457814b5 JS |
447 | return 0; |
448 | ||
449 | int i = 0; | |
fd71308f | 450 | wxPropertyValue *expr = m_value.first; |
457814b5 JS |
451 | while (expr) |
452 | { | |
fd71308f | 453 | expr = expr->m_next; |
457814b5 JS |
454 | i ++; |
455 | } | |
456 | return i; | |
457 | } | |
458 | ||
459 | void wxPropertyValue::WritePropertyClause(ostream& stream) // Write this expression as a top-level clause | |
460 | { | |
fd71308f | 461 | if (m_type != wxPropertyValueList) |
457814b5 JS |
462 | return; |
463 | ||
fd71308f | 464 | wxPropertyValue *node = m_value.first; |
457814b5 JS |
465 | if (node) |
466 | { | |
467 | node->WritePropertyType(stream); | |
468 | stream << "("; | |
fd71308f | 469 | node = node->m_next; |
457814b5 JS |
470 | bool first = TRUE; |
471 | while (node) | |
472 | { | |
473 | if (!first) | |
474 | stream << " "; | |
475 | node->WritePropertyType(stream); | |
fd71308f | 476 | node = node->m_next; |
457814b5 JS |
477 | if (node) stream << ",\n"; |
478 | first = FALSE; | |
479 | } | |
480 | stream << ").\n\n"; | |
481 | } | |
482 | } | |
483 | ||
484 | void wxPropertyValue::WritePropertyType(ostream& stream) // Write as any other subexpression | |
485 | { | |
fd71308f | 486 | switch (m_type) |
457814b5 JS |
487 | { |
488 | case wxPropertyValueInteger: | |
489 | { | |
fd71308f | 490 | stream << m_value.integer; |
457814b5 JS |
491 | break; |
492 | } | |
493 | case wxPropertyValueIntegerPtr: | |
494 | { | |
fd71308f | 495 | stream << *m_value.integerPtr; |
457814b5 JS |
496 | break; |
497 | } | |
498 | case wxPropertyValuebool: | |
499 | { | |
fd71308f | 500 | if (m_value.integer) |
457814b5 JS |
501 | stream << "True"; |
502 | else | |
503 | stream << "False"; | |
504 | break; | |
505 | } | |
506 | case wxPropertyValueboolPtr: | |
507 | { | |
fd71308f | 508 | if (*m_value.integerPtr) |
457814b5 JS |
509 | stream << "True"; |
510 | else | |
511 | stream << "False"; | |
512 | break; | |
513 | } | |
514 | case wxPropertyValueReal: | |
515 | { | |
fd71308f | 516 | float f = m_value.real; |
457814b5 JS |
517 | sprintf(wxBuffer, "%.6g", (double)f); |
518 | stream << wxBuffer; | |
519 | break; | |
520 | } | |
521 | case wxPropertyValueRealPtr: | |
522 | { | |
fd71308f | 523 | float f = *m_value.realPtr; |
457814b5 JS |
524 | /* Now the parser can cope with this. |
525 | // Prevent printing in 'e' notation. Any better way? | |
526 | if (fabs(f) < 0.00001) | |
527 | f = 0.0; | |
528 | */ | |
529 | sprintf(wxBuffer, "%.6g", f); | |
530 | stream << wxBuffer; | |
531 | break; | |
532 | } | |
533 | case wxPropertyValueString: | |
534 | { | |
535 | // stream << "\""; | |
536 | int i; | |
fd71308f | 537 | int len = strlen(m_value.string); |
457814b5 JS |
538 | for (i = 0; i < len; i++) |
539 | { | |
fd71308f | 540 | char ch = m_value.string[i]; |
457814b5 JS |
541 | // if (ch == '"' || ch == '\\') |
542 | // stream << "\\"; | |
543 | stream << ch; | |
544 | } | |
545 | ||
546 | // stream << "\""; | |
547 | break; | |
548 | } | |
549 | case wxPropertyValueStringPtr: | |
550 | { | |
551 | int i; | |
fd71308f | 552 | int len = strlen(*(m_value.stringPtr)); |
457814b5 JS |
553 | for (i = 0; i < len; i++) |
554 | { | |
fd71308f | 555 | char ch = *(m_value.stringPtr)[i]; |
457814b5 JS |
556 | |
557 | } | |
558 | break; | |
559 | } | |
560 | case wxPropertyValueList: | |
561 | { | |
fd71308f | 562 | if (!m_value.first) |
457814b5 JS |
563 | stream << "[]"; |
564 | else | |
565 | { | |
fd71308f | 566 | wxPropertyValue *expr = m_value.first; |
457814b5 JS |
567 | |
568 | stream << "["; | |
569 | while (expr) | |
570 | { | |
571 | expr->WritePropertyType(stream); | |
fd71308f | 572 | expr = expr->m_next; |
457814b5 JS |
573 | if (expr) stream << ", "; |
574 | } | |
575 | stream << "]"; | |
576 | } | |
577 | break; | |
578 | } | |
579 | case wxPropertyValueNull: break; | |
580 | } | |
581 | } | |
582 | ||
583 | wxString wxPropertyValue::GetStringRepresentation(void) | |
584 | { | |
585 | char buf[500]; | |
586 | buf[0] = 0; | |
587 | ||
588 | ostrstream str((char *)buf, (int)500, ios::out); | |
589 | WritePropertyType(str); | |
590 | str << '\0'; | |
591 | str.flush(); | |
592 | ||
593 | wxString theString(buf); | |
594 | return theString; | |
595 | } | |
596 | ||
597 | void wxPropertyValue::operator=(const wxPropertyValue& val) | |
598 | { | |
fd71308f | 599 | m_modifiedFlag = TRUE; |
457814b5 JS |
600 | Copy((wxPropertyValue&)val); |
601 | } | |
602 | ||
603 | // void wxPropertyValue::operator=(const char *val) | |
604 | void wxPropertyValue::operator=(const wxString& val1) | |
605 | { | |
606 | const char *val = (const char *)val1; | |
607 | ||
fd71308f JS |
608 | m_modifiedFlag = TRUE; |
609 | if (m_type == wxPropertyValueNull) | |
610 | m_type = wxPropertyValueString; | |
457814b5 | 611 | |
fd71308f | 612 | if (m_type == wxPropertyValueString) |
457814b5 JS |
613 | { |
614 | if (val) | |
fd71308f | 615 | m_value.string = copystring(val); |
457814b5 | 616 | else |
fd71308f | 617 | m_value.string = NULL; |
457814b5 | 618 | } |
fd71308f | 619 | else if (m_type == wxPropertyValueStringPtr) |
457814b5 | 620 | { |
fd71308f JS |
621 | if (*m_value.stringPtr) |
622 | delete[] *m_value.stringPtr; | |
457814b5 | 623 | if (val) |
fd71308f | 624 | *m_value.stringPtr = copystring(val); |
457814b5 | 625 | else |
fd71308f | 626 | *m_value.stringPtr = NULL; |
457814b5 JS |
627 | } |
628 | ||
fd71308f JS |
629 | m_clientData = NULL; |
630 | m_next = NULL; | |
631 | m_last = NULL; | |
457814b5 JS |
632 | |
633 | } | |
634 | ||
635 | void wxPropertyValue::operator=(const long val) | |
636 | { | |
fd71308f JS |
637 | m_modifiedFlag = TRUE; |
638 | if (m_type == wxPropertyValueNull) | |
639 | m_type = wxPropertyValueInteger; | |
640 | ||
641 | if (m_type == wxPropertyValueInteger) | |
642 | m_value.integer = val; | |
643 | else if (m_type == wxPropertyValueIntegerPtr) | |
644 | *m_value.integerPtr = val; | |
645 | else if (m_type == wxPropertyValueReal) | |
646 | m_value.real = (float)val; | |
647 | else if (m_type == wxPropertyValueRealPtr) | |
648 | *m_value.realPtr = (float)val; | |
649 | ||
650 | m_clientData = NULL; | |
651 | m_next = NULL; | |
457814b5 JS |
652 | } |
653 | ||
654 | void wxPropertyValue::operator=(const bool val) | |
655 | { | |
fd71308f JS |
656 | m_modifiedFlag = TRUE; |
657 | if (m_type == wxPropertyValueNull) | |
658 | m_type = wxPropertyValuebool; | |
457814b5 | 659 | |
fd71308f JS |
660 | if (m_type == wxPropertyValuebool) |
661 | m_value.integer = (long)val; | |
662 | else if (m_type == wxPropertyValueboolPtr) | |
663 | *m_value.boolPtr = val; | |
457814b5 | 664 | |
fd71308f JS |
665 | m_clientData = NULL; |
666 | m_next = NULL; | |
457814b5 JS |
667 | } |
668 | ||
669 | void wxPropertyValue::operator=(const float val) | |
670 | { | |
fd71308f JS |
671 | m_modifiedFlag = TRUE; |
672 | if (m_type == wxPropertyValueNull) | |
673 | m_type = wxPropertyValueReal; | |
674 | ||
675 | if (m_type == wxPropertyValueInteger) | |
676 | m_value.integer = (long)val; | |
677 | else if (m_type == wxPropertyValueIntegerPtr) | |
678 | *m_value.integerPtr = (long)val; | |
679 | else if (m_type == wxPropertyValueReal) | |
680 | m_value.real = val; | |
681 | else if (m_type == wxPropertyValueRealPtr) | |
682 | *m_value.realPtr = val; | |
683 | ||
684 | m_clientData = NULL; | |
685 | m_next = NULL; | |
457814b5 JS |
686 | } |
687 | ||
688 | void wxPropertyValue::operator=(const char **val) | |
689 | { | |
fd71308f JS |
690 | m_modifiedFlag = TRUE; |
691 | m_type = wxPropertyValueStringPtr; | |
457814b5 JS |
692 | |
693 | if (val) | |
fd71308f | 694 | m_value.stringPtr = (char **)val; |
457814b5 | 695 | else |
fd71308f JS |
696 | m_value.stringPtr = NULL; |
697 | m_clientData = NULL; | |
698 | m_next = NULL; | |
699 | m_last = NULL; | |
457814b5 JS |
700 | |
701 | } | |
702 | ||
703 | void wxPropertyValue::operator=(const long *val) | |
704 | { | |
fd71308f JS |
705 | m_modifiedFlag = TRUE; |
706 | m_type = wxPropertyValueIntegerPtr; | |
707 | m_value.integerPtr = (long *)val; | |
708 | m_clientData = NULL; | |
709 | m_next = NULL; | |
457814b5 JS |
710 | } |
711 | ||
712 | void wxPropertyValue::operator=(const bool *val) | |
713 | { | |
fd71308f JS |
714 | m_modifiedFlag = TRUE; |
715 | m_type = wxPropertyValueboolPtr; | |
716 | m_value.boolPtr = (bool *)val; | |
717 | m_clientData = NULL; | |
718 | m_next = NULL; | |
457814b5 JS |
719 | } |
720 | ||
721 | void wxPropertyValue::operator=(const float *val) | |
722 | { | |
fd71308f JS |
723 | m_modifiedFlag = TRUE; |
724 | m_type = wxPropertyValueRealPtr; | |
725 | m_value.realPtr = (float *)val; | |
726 | m_clientData = NULL; | |
727 | m_next = NULL; | |
457814b5 JS |
728 | } |
729 | ||
fd71308f | 730 | long wxPropertyValue::IntegerValue(void) const |
457814b5 | 731 | { |
fd71308f JS |
732 | if (m_type == wxPropertyValueInteger) |
733 | return m_value.integer; | |
734 | else if (m_type == wxPropertyValueReal) | |
735 | return (long)m_value.real; | |
736 | else if (m_type == wxPropertyValueIntegerPtr) | |
737 | return *m_value.integerPtr; | |
738 | else if (m_type == wxPropertyValueRealPtr) | |
739 | return (long)(*m_value.realPtr); | |
457814b5 JS |
740 | else return 0; |
741 | } | |
742 | ||
fd71308f | 743 | long *wxPropertyValue::IntegerValuePtr(void) const |
457814b5 | 744 | { |
fd71308f | 745 | return m_value.integerPtr; |
457814b5 JS |
746 | } |
747 | ||
fd71308f JS |
748 | float wxPropertyValue::RealValue(void) const { |
749 | if (m_type == wxPropertyValueReal) | |
750 | return m_value.real; | |
751 | else if (m_type == wxPropertyValueRealPtr) | |
752 | return *m_value.realPtr; | |
753 | else if (m_type == wxPropertyValueInteger) | |
754 | return (float)m_value.integer; | |
755 | else if (m_type == wxPropertyValueIntegerPtr) | |
756 | return (float)*(m_value.integerPtr); | |
457814b5 JS |
757 | else return 0.0; |
758 | } | |
759 | ||
fd71308f | 760 | float *wxPropertyValue::RealValuePtr(void) const |
457814b5 | 761 | { |
fd71308f | 762 | return m_value.realPtr; |
457814b5 JS |
763 | } |
764 | ||
fd71308f JS |
765 | bool wxPropertyValue::BoolValue(void) const { |
766 | if (m_type == wxPropertyValueReal) | |
767 | return (m_value.real != 0.0); | |
768 | if (m_type == wxPropertyValueRealPtr) | |
769 | return (*(m_value.realPtr) != 0.0); | |
770 | else if (m_type == wxPropertyValueInteger) | |
771 | return (m_value.integer != 0); | |
772 | else if (m_type == wxPropertyValueIntegerPtr) | |
773 | return (*(m_value.integerPtr) != 0); | |
774 | else if (m_type == wxPropertyValuebool) | |
775 | return (m_value.integer != 0); | |
776 | else if (m_type == wxPropertyValueboolPtr) | |
777 | return (*(m_value.boolPtr) != 0); | |
457814b5 JS |
778 | else return FALSE; |
779 | } | |
780 | ||
fd71308f | 781 | bool *wxPropertyValue::BoolValuePtr(void) const |
457814b5 | 782 | { |
fd71308f | 783 | return m_value.boolPtr; |
457814b5 JS |
784 | } |
785 | ||
fd71308f JS |
786 | char *wxPropertyValue::StringValue(void) const { |
787 | if (m_type == wxPropertyValueString) | |
788 | return m_value.string; | |
789 | else if (m_type == wxPropertyValueStringPtr) | |
790 | return *(m_value.stringPtr); | |
457814b5 JS |
791 | else return NULL; |
792 | } | |
793 | ||
fd71308f | 794 | char **wxPropertyValue::StringValuePtr(void) const |
457814b5 | 795 | { |
fd71308f | 796 | return m_value.stringPtr; |
457814b5 JS |
797 | } |
798 | ||
799 | /* | |
800 | * A property (name plus value) | |
801 | */ | |
802 | ||
803 | IMPLEMENT_DYNAMIC_CLASS(wxProperty, wxObject) | |
804 | ||
805 | wxProperty::wxProperty(void) | |
806 | { | |
fd71308f JS |
807 | m_propertyRole = (char *)NULL; |
808 | m_propertyValidator = NULL; | |
809 | m_propertyWindow = NULL; | |
810 | m_enabled = TRUE; | |
457814b5 JS |
811 | } |
812 | ||
813 | wxProperty::wxProperty(wxProperty& copyFrom) | |
814 | { | |
fd71308f JS |
815 | m_value = copyFrom.GetValue(); |
816 | m_name = copyFrom.GetName(); | |
817 | m_propertyRole = copyFrom.GetRole(); | |
818 | m_propertyValidator = copyFrom.GetValidator(); | |
819 | m_enabled = copyFrom.IsEnabled(); | |
820 | m_propertyWindow = NULL; | |
457814b5 JS |
821 | } |
822 | ||
fd71308f | 823 | wxProperty::wxProperty(wxString nm, wxString role, wxPropertyValidator *ed):m_name(nm), m_propertyRole(role) |
457814b5 | 824 | { |
fd71308f JS |
825 | m_propertyValidator = ed; |
826 | m_propertyWindow = NULL; | |
827 | m_enabled = TRUE; | |
457814b5 JS |
828 | } |
829 | ||
830 | wxProperty::wxProperty(wxString nm, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed): | |
fd71308f | 831 | m_name(nm), m_value(val), m_propertyRole(role) |
457814b5 | 832 | { |
fd71308f JS |
833 | m_propertyValidator = ed; |
834 | m_propertyWindow = NULL; | |
835 | m_enabled = TRUE; | |
457814b5 JS |
836 | } |
837 | ||
838 | wxProperty::~wxProperty(void) | |
839 | { | |
fd71308f JS |
840 | if (m_propertyValidator) |
841 | delete m_propertyValidator; | |
457814b5 JS |
842 | } |
843 | ||
fd71308f | 844 | wxPropertyValue& wxProperty::GetValue(void) const |
457814b5 | 845 | { |
fd71308f | 846 | return (wxPropertyValue&) m_value; |
457814b5 JS |
847 | } |
848 | ||
fd71308f | 849 | wxPropertyValidator *wxProperty::GetValidator(void) const |
457814b5 | 850 | { |
fd71308f | 851 | return m_propertyValidator; |
457814b5 JS |
852 | } |
853 | ||
fd71308f | 854 | wxString& wxProperty::GetName(void) const |
457814b5 | 855 | { |
fd71308f | 856 | return (wxString&) m_name; |
457814b5 JS |
857 | } |
858 | ||
fd71308f | 859 | wxString& wxProperty::GetRole(void) const |
457814b5 | 860 | { |
fd71308f | 861 | return (wxString&) m_propertyRole; |
457814b5 JS |
862 | } |
863 | ||
864 | void wxProperty::SetValue(const wxPropertyValue& val) | |
865 | { | |
fd71308f | 866 | m_value = val; |
457814b5 JS |
867 | } |
868 | ||
869 | void wxProperty::SetValidator(wxPropertyValidator *ed) | |
870 | { | |
fd71308f | 871 | m_propertyValidator = ed; |
457814b5 JS |
872 | } |
873 | ||
874 | void wxProperty::SetRole(wxString& role) | |
875 | { | |
fd71308f | 876 | m_propertyRole = role; |
457814b5 JS |
877 | } |
878 | ||
879 | void wxProperty::SetName(wxString& nm) | |
880 | { | |
fd71308f | 881 | m_name = nm; |
457814b5 JS |
882 | } |
883 | ||
884 | void wxProperty::operator=(const wxPropertyValue& val) | |
885 | { | |
fd71308f | 886 | m_value = val; |
457814b5 JS |
887 | } |
888 | ||
889 | /* | |
890 | * Base property view class | |
891 | */ | |
892 | ||
893 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyView, wxEvtHandler) | |
894 | ||
895 | wxPropertyView::wxPropertyView(long flags) | |
896 | { | |
fd71308f JS |
897 | m_buttonFlags = flags; |
898 | m_propertySheet = NULL; | |
899 | m_currentValidator = NULL; | |
900 | m_currentProperty = NULL; | |
457814b5 JS |
901 | } |
902 | ||
903 | wxPropertyView::~wxPropertyView(void) | |
904 | { | |
905 | } | |
906 | ||
907 | void wxPropertyView::AddRegistry(wxPropertyValidatorRegistry *registry) | |
908 | { | |
fd71308f | 909 | m_validatorRegistryList.Append(registry); |
457814b5 JS |
910 | } |
911 | ||
912 | wxPropertyValidator *wxPropertyView::FindPropertyValidator(wxProperty *property) | |
913 | { | |
914 | if (property->GetValidator()) | |
915 | return property->GetValidator(); | |
916 | ||
fd71308f | 917 | wxNode *node = m_validatorRegistryList.First(); |
457814b5 JS |
918 | while (node) |
919 | { | |
920 | wxPropertyValidatorRegistry *registry = (wxPropertyValidatorRegistry *)node->Data(); | |
921 | wxPropertyValidator *validator = registry->GetValidator(property->GetRole()); | |
922 | if (validator) | |
923 | return validator; | |
924 | node = node->Next(); | |
925 | } | |
926 | return NULL; | |
927 | /* | |
928 | if (!wxDefaultPropertyValidator) | |
929 | wxDefaultPropertyValidator = new wxPropertyListValidator; | |
930 | return wxDefaultPropertyValidator; | |
931 | */ | |
932 | } | |
933 | ||
934 | /* | |
935 | * Property sheet | |
936 | */ | |
937 | ||
938 | IMPLEMENT_DYNAMIC_CLASS(wxPropertySheet, wxObject) | |
939 | ||
fd71308f | 940 | wxPropertySheet::wxPropertySheet(void):m_properties(wxKEY_STRING) |
457814b5 JS |
941 | { |
942 | } | |
943 | ||
944 | wxPropertySheet::~wxPropertySheet(void) | |
945 | { | |
946 | Clear(); | |
947 | } | |
948 | ||
8656024d | 949 | bool wxPropertySheet::Save( ostream& WXUNUSED(str) ) |
457814b5 JS |
950 | { |
951 | return FALSE; | |
952 | } | |
953 | ||
8656024d | 954 | bool wxPropertySheet::Load( ostream& WXUNUSED(str) ) |
457814b5 JS |
955 | { |
956 | return FALSE; | |
957 | } | |
958 | ||
8656024d | 959 | void wxPropertySheet::UpdateAllViews( wxPropertyView *WXUNUSED(thisView) ) |
457814b5 JS |
960 | { |
961 | } | |
962 | ||
963 | // Add a property | |
964 | void wxPropertySheet::AddProperty(wxProperty *property) | |
965 | { | |
fd71308f | 966 | m_properties.Append(property->GetName().GetData(), property); |
457814b5 JS |
967 | } |
968 | ||
969 | // Get property by name | |
970 | wxProperty *wxPropertySheet::GetProperty(wxString name) | |
971 | { | |
fd71308f | 972 | wxNode *node = m_properties.Find(name.GetData()); |
457814b5 JS |
973 | if (!node) |
974 | return NULL; | |
975 | else | |
976 | return (wxProperty *)node->Data(); | |
977 | } | |
978 | ||
979 | // Clear all properties | |
980 | void wxPropertySheet::Clear(void) | |
981 | { | |
fd71308f | 982 | wxNode *node = m_properties.First(); |
457814b5 JS |
983 | while (node) |
984 | { | |
985 | wxProperty *prop = (wxProperty *)node->Data(); | |
986 | wxNode *next = node->Next(); | |
987 | delete prop; | |
988 | delete node; | |
989 | node = next; | |
990 | } | |
991 | } | |
992 | ||
993 | // Sets/clears the modified flag for each property value | |
994 | void wxPropertySheet::SetAllModified(bool flag) | |
995 | { | |
fd71308f | 996 | wxNode *node = m_properties.First(); |
457814b5 JS |
997 | while (node) |
998 | { | |
999 | wxProperty *prop = (wxProperty *)node->Data(); | |
1000 | prop->GetValue().SetModified(flag); | |
1001 | node = node->Next(); | |
1002 | } | |
1003 | } | |
1004 | ||
1005 | /* | |
1006 | * Property validator registry | |
1007 | * | |
1008 | */ | |
1009 | ||
1010 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyValidatorRegistry, wxHashTable) | |
1011 | ||
1012 | wxPropertyValidatorRegistry::wxPropertyValidatorRegistry(void):wxHashTable(wxKEY_STRING) | |
1013 | { | |
1014 | } | |
1015 | ||
1016 | wxPropertyValidatorRegistry::~wxPropertyValidatorRegistry(void) | |
1017 | { | |
1018 | ClearRegistry(); | |
1019 | } | |
1020 | ||
1021 | void wxPropertyValidatorRegistry::RegisterValidator(wxString& typeName, wxPropertyValidator *validator) | |
1022 | { | |
1023 | Put(typeName.GetData(), validator); | |
1024 | } | |
1025 | ||
1026 | wxPropertyValidator *wxPropertyValidatorRegistry::GetValidator(wxString& typeName) | |
1027 | { | |
1028 | return (wxPropertyValidator *)Get(typeName.GetData()); | |
1029 | } | |
1030 | ||
1031 | void wxPropertyValidatorRegistry::ClearRegistry(void) | |
1032 | { | |
1033 | BeginFind(); | |
1034 | wxNode *node; | |
1035 | while (node = Next()) | |
1036 | { | |
1037 | delete (wxPropertyValidator *)node->Data(); | |
1038 | } | |
1039 | } | |
1040 | ||
1041 | /* | |
1042 | * Property validator | |
1043 | */ | |
1044 | ||
1045 | ||
1046 | IMPLEMENT_ABSTRACT_CLASS(wxPropertyValidator, wxEvtHandler) | |
1047 | ||
1048 | wxPropertyValidator::wxPropertyValidator(long flags) | |
1049 | { | |
fd71308f JS |
1050 | m_validatorFlags = flags; |
1051 | m_validatorProperty = NULL; | |
457814b5 JS |
1052 | } |
1053 | ||
1054 | wxPropertyValidator::~wxPropertyValidator(void) | |
1055 | {} | |
1056 | ||
1057 | bool wxPropertyValidator::StringToFloat (char *s, float *number) { | |
1058 | double num; | |
1059 | bool ok = StringToDouble (s, &num); | |
1060 | *number = (float) num; | |
1061 | return ok; | |
1062 | } | |
1063 | ||
1064 | bool wxPropertyValidator::StringToDouble (char *s, double *number) { | |
1065 | bool ok = TRUE; | |
1066 | char *value_ptr; | |
1067 | *number = strtod (s, &value_ptr); | |
1068 | if (value_ptr) { | |
1069 | int len = strlen (value_ptr); | |
1070 | for (int i = 0; i < len; i++) { | |
1071 | ok = (isspace (value_ptr[i]) != 0); | |
1072 | if (!ok) return FALSE; | |
1073 | } | |
1074 | } | |
1075 | return ok; | |
1076 | } | |
1077 | ||
1078 | bool wxPropertyValidator::StringToInt (char *s, int *number) { | |
1079 | long num; | |
1080 | bool ok = StringToLong (s, &num); | |
1081 | *number = (int) num; | |
1082 | return ok; | |
1083 | } | |
1084 | ||
1085 | bool wxPropertyValidator::StringToLong (char *s, long *number) { | |
1086 | bool ok = TRUE; | |
1087 | char *value_ptr; | |
1088 | *number = strtol (s, &value_ptr, 10); | |
1089 | if (value_ptr) { | |
1090 | int len = strlen (value_ptr); | |
1091 | for (int i = 0; i < len; i++) { | |
1092 | ok = (isspace (value_ptr[i]) != 0); | |
1093 | if (!ok) return FALSE; | |
1094 | } | |
1095 | } | |
1096 | return ok; | |
1097 | } | |
1098 | ||
1099 | char *wxPropertyValidator::FloatToString (float number) { | |
1100 | static char buf[20]; | |
1101 | sprintf (buf, "%.6g", number); | |
1102 | return buf; | |
1103 | } | |
1104 | ||
1105 | char *wxPropertyValidator::DoubleToString (double number) { | |
1106 | static char buf[20]; | |
1107 | sprintf (buf, "%.6g", number); | |
1108 | return buf; | |
1109 | } | |
1110 | ||
1111 | char *wxPropertyValidator::IntToString (int number) { | |
1112 | return ::IntToString (number); | |
1113 | } | |
1114 | ||
1115 | char *wxPropertyValidator::LongToString (long number) { | |
1116 | return ::LongToString (number); | |
1117 | } | |
1118 | ||
1119 |