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