]>
Commit | Line | Data |
---|---|---|
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 | ||
32 | #if wxUSE_IOSTREAMH | |
33 | #if defined(__WXMSW__) && !defined(__GNUWIN32__) | |
34 | #include <strstrea.h> | |
35 | #else | |
36 | #include <strstream.h> | |
37 | #endif | |
38 | #else | |
39 | #include <strstream> | |
40 | #endif | |
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 | { | |
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; | |
57 | } | |
58 | ||
59 | wxPropertyValue::wxPropertyValue(const wxPropertyValue& copyFrom) | |
60 | { | |
61 | m_modifiedFlag = FALSE; | |
62 | Copy((wxPropertyValue& )copyFrom); | |
63 | } | |
64 | ||
65 | wxPropertyValue::wxPropertyValue(const char *val) | |
66 | { | |
67 | m_modifiedFlag = FALSE; | |
68 | m_type = wxPropertyValueString; | |
69 | ||
70 | m_value.string = copystring(val); | |
71 | m_clientData = NULL; | |
72 | m_next = NULL; | |
73 | m_last = NULL; | |
74 | } | |
75 | ||
76 | wxPropertyValue::wxPropertyValue(const wxString& val) | |
77 | { | |
78 | m_modifiedFlag = FALSE; | |
79 | m_type = wxPropertyValueString; | |
80 | ||
81 | m_value.string = copystring((const char *)val); | |
82 | m_clientData = NULL; | |
83 | m_next = NULL; | |
84 | m_last = NULL; | |
85 | } | |
86 | ||
87 | wxPropertyValue::wxPropertyValue(long the_integer) | |
88 | { | |
89 | m_modifiedFlag = FALSE; | |
90 | m_type = wxPropertyValueInteger; | |
91 | m_value.integer = the_integer; | |
92 | m_clientData = NULL; | |
93 | m_next = NULL; | |
94 | } | |
95 | ||
96 | wxPropertyValue::wxPropertyValue(bool val) | |
97 | { | |
98 | m_modifiedFlag = FALSE; | |
99 | m_type = wxPropertyValuebool; | |
100 | m_value.integer = val; | |
101 | m_clientData = NULL; | |
102 | m_next = NULL; | |
103 | } | |
104 | ||
105 | wxPropertyValue::wxPropertyValue(float the_real) | |
106 | { | |
107 | m_modifiedFlag = FALSE; | |
108 | m_type = wxPropertyValueReal; | |
109 | m_value.real = the_real; | |
110 | m_clientData = NULL; | |
111 | m_next = NULL; | |
112 | } | |
113 | ||
114 | wxPropertyValue::wxPropertyValue(double the_real) | |
115 | { | |
116 | m_modifiedFlag = FALSE; | |
117 | m_type = wxPropertyValueReal; | |
118 | m_value.real = (float)the_real; | |
119 | m_clientData = NULL; | |
120 | m_next = NULL; | |
121 | } | |
122 | ||
123 | // Pointer versions: we have a pointer to the real C++ value. | |
124 | wxPropertyValue::wxPropertyValue(char **val) | |
125 | { | |
126 | m_modifiedFlag = FALSE; | |
127 | m_type = wxPropertyValueStringPtr; | |
128 | ||
129 | m_value.stringPtr = val; | |
130 | m_clientData = NULL; | |
131 | m_next = NULL; | |
132 | m_last = NULL; | |
133 | } | |
134 | ||
135 | wxPropertyValue::wxPropertyValue(long *val) | |
136 | { | |
137 | m_modifiedFlag = FALSE; | |
138 | m_type = wxPropertyValueIntegerPtr; | |
139 | m_value.integerPtr = val; | |
140 | m_clientData = NULL; | |
141 | m_next = NULL; | |
142 | } | |
143 | ||
144 | wxPropertyValue::wxPropertyValue(bool *val) | |
145 | { | |
146 | m_modifiedFlag = FALSE; | |
147 | m_type = wxPropertyValueboolPtr; | |
148 | m_value.boolPtr = val; | |
149 | m_clientData = NULL; | |
150 | m_next = NULL; | |
151 | } | |
152 | ||
153 | wxPropertyValue::wxPropertyValue(float *val) | |
154 | { | |
155 | m_modifiedFlag = FALSE; | |
156 | m_type = wxPropertyValueRealPtr; | |
157 | m_value.realPtr = val; | |
158 | m_clientData = NULL; | |
159 | m_next = NULL; | |
160 | } | |
161 | ||
162 | wxPropertyValue::wxPropertyValue(wxList *the_list) | |
163 | { | |
164 | m_modifiedFlag = FALSE; | |
165 | m_type = wxPropertyValueList; | |
166 | m_clientData = NULL; | |
167 | m_last = NULL; | |
168 | m_value.first = NULL; | |
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 | { | |
183 | m_modifiedFlag = FALSE; | |
184 | m_type = wxPropertyValueList; | |
185 | m_clientData = NULL; | |
186 | m_last = NULL; | |
187 | m_value.first = NULL; | |
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 | { | |
201 | switch (m_type) | |
202 | { | |
203 | case wxPropertyValueInteger: | |
204 | case wxPropertyValuebool: | |
205 | case wxPropertyValueReal: | |
206 | { | |
207 | break; | |
208 | } | |
209 | case wxPropertyValueString: | |
210 | { | |
211 | delete[] m_value.string; | |
212 | break; | |
213 | } | |
214 | case wxPropertyValueList: | |
215 | { | |
216 | wxPropertyValue *expr = m_value.first; | |
217 | while (expr) | |
218 | { | |
219 | wxPropertyValue *expr1 = expr->m_next; | |
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 | { | |
233 | m_modifiedFlag = TRUE; | |
234 | if (!m_value.first) | |
235 | m_value.first = expr; | |
236 | ||
237 | if (m_last) | |
238 | m_last->m_next = expr; | |
239 | m_last = expr; | |
240 | } | |
241 | ||
242 | void wxPropertyValue::Insert(wxPropertyValue *expr) | |
243 | { | |
244 | m_modifiedFlag = TRUE; | |
245 | expr->m_next = m_value.first; | |
246 | m_value.first = expr; | |
247 | ||
248 | if (!m_last) | |
249 | m_last = expr; | |
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) | |
267 | previous->m_next = expr->m_next; | |
268 | ||
269 | // If node was the first in the list, | |
270 | // make the list point to the NEXT one. | |
271 | if (GetFirst() == expr) | |
272 | { | |
273 | m_value.first = expr->m_next; | |
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) | |
281 | m_last = previous; | |
282 | else | |
283 | m_last = NULL; | |
284 | } | |
285 | m_modifiedFlag = TRUE; | |
286 | delete expr; | |
287 | } | |
288 | ||
289 | } | |
290 | ||
291 | void wxPropertyValue::ClearList(void) | |
292 | { | |
293 | wxPropertyValue *val = GetFirst(); | |
294 | if (val) | |
295 | m_modifiedFlag = TRUE; | |
296 | ||
297 | while (val) | |
298 | { | |
299 | wxPropertyValue *next = val->GetNext(); | |
300 | delete val; | |
301 | val = next; | |
302 | } | |
303 | m_value.first = NULL; | |
304 | m_last = NULL; | |
305 | } | |
306 | ||
307 | wxPropertyValue *wxPropertyValue::NewCopy(void) const | |
308 | { | |
309 | switch (m_type) | |
310 | { | |
311 | case wxPropertyValueInteger: | |
312 | return new wxPropertyValue(m_value.integer); | |
313 | case wxPropertyValuebool: | |
314 | return new wxPropertyValue((bool) (m_value.integer != 0)); | |
315 | case wxPropertyValueReal: | |
316 | return new wxPropertyValue(m_value.real); | |
317 | case wxPropertyValueString: | |
318 | return new wxPropertyValue(m_value.string); | |
319 | case wxPropertyValueList: | |
320 | { | |
321 | wxPropertyValue *expr = m_value.first; | |
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); | |
328 | expr = expr->m_next; | |
329 | } | |
330 | return new_list; | |
331 | } | |
332 | case wxPropertyValueIntegerPtr: | |
333 | return new wxPropertyValue(m_value.integerPtr); | |
334 | case wxPropertyValueRealPtr: | |
335 | return new wxPropertyValue(m_value.realPtr); | |
336 | case wxPropertyValueboolPtr: | |
337 | return new wxPropertyValue(m_value.boolPtr); | |
338 | case wxPropertyValueStringPtr: | |
339 | return new wxPropertyValue(m_value.stringPtr); | |
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 | { | |
352 | m_type = copyFrom.Type(); | |
353 | ||
354 | switch (m_type) | |
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: | |
383 | { | |
384 | char** s = copyFrom.StringValuePtr(); | |
385 | (*this) = s != 0; | |
386 | return ; | |
387 | } | |
388 | ||
389 | case wxPropertyValueList: | |
390 | { | |
391 | m_value.first = NULL; | |
392 | m_next = NULL; | |
393 | m_last = NULL; | |
394 | wxPropertyValue *expr = copyFrom.m_value.first; | |
395 | while (expr) | |
396 | { | |
397 | wxPropertyValue *expr2 = expr->NewCopy(); | |
398 | Append(expr2); | |
399 | expr = expr->m_next; | |
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) | |
412 | wxPropertyValue *wxPropertyValue::Arg(wxPropertyValueType type, int arg) const | |
413 | { | |
414 | wxPropertyValue *expr = m_value.first; | |
415 | for (int i = 1; i < arg; i++) | |
416 | if (expr) | |
417 | expr = expr->m_next; | |
418 | ||
419 | if (expr && (expr->m_type == type)) | |
420 | return expr; | |
421 | else | |
422 | return NULL; | |
423 | } | |
424 | ||
425 | // Return nth argument of a list expression (starting from zero) | |
426 | wxPropertyValue *wxPropertyValue::Nth(int arg) const | |
427 | { | |
428 | if (m_type != wxPropertyValueList) | |
429 | return NULL; | |
430 | ||
431 | wxPropertyValue *expr = m_value.first; | |
432 | for (int i = 0; i < arg; i++) | |
433 | if (expr) | |
434 | expr = expr->m_next; | |
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 | |
444 | int wxPropertyValue::Number(void) const | |
445 | { | |
446 | if (m_type != wxPropertyValueList) | |
447 | return 0; | |
448 | ||
449 | int i = 0; | |
450 | wxPropertyValue *expr = m_value.first; | |
451 | while (expr) | |
452 | { | |
453 | expr = expr->m_next; | |
454 | i ++; | |
455 | } | |
456 | return i; | |
457 | } | |
458 | ||
459 | void wxPropertyValue::WritePropertyClause(ostream& stream) // Write this expression as a top-level clause | |
460 | { | |
461 | if (m_type != wxPropertyValueList) | |
462 | return; | |
463 | ||
464 | wxPropertyValue *node = m_value.first; | |
465 | if (node) | |
466 | { | |
467 | node->WritePropertyType(stream); | |
468 | stream << "("; | |
469 | node = node->m_next; | |
470 | bool first = TRUE; | |
471 | while (node) | |
472 | { | |
473 | if (!first) | |
474 | stream << " "; | |
475 | node->WritePropertyType(stream); | |
476 | node = node->m_next; | |
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 | { | |
486 | switch (m_type) | |
487 | { | |
488 | case wxPropertyValueInteger: | |
489 | { | |
490 | stream << m_value.integer; | |
491 | break; | |
492 | } | |
493 | case wxPropertyValueIntegerPtr: | |
494 | { | |
495 | stream << *m_value.integerPtr; | |
496 | break; | |
497 | } | |
498 | case wxPropertyValuebool: | |
499 | { | |
500 | if (m_value.integer) | |
501 | stream << "True"; | |
502 | else | |
503 | stream << "False"; | |
504 | break; | |
505 | } | |
506 | case wxPropertyValueboolPtr: | |
507 | { | |
508 | if (*m_value.integerPtr) | |
509 | stream << "True"; | |
510 | else | |
511 | stream << "False"; | |
512 | break; | |
513 | } | |
514 | case wxPropertyValueReal: | |
515 | { | |
516 | float f = m_value.real; | |
517 | sprintf(wxBuffer, "%.6g", (double)f); | |
518 | stream << wxBuffer; | |
519 | break; | |
520 | } | |
521 | case wxPropertyValueRealPtr: | |
522 | { | |
523 | float f = *m_value.realPtr; | |
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; | |
537 | int len = strlen(m_value.string); | |
538 | for (i = 0; i < len; i++) | |
539 | { | |
540 | char ch = m_value.string[i]; | |
541 | // if (ch == '"' || ch == '\\') | |
542 | // stream << "\\"; | |
543 | stream << ch; | |
544 | } | |
545 | ||
546 | // stream << "\""; | |
547 | break; | |
548 | } | |
549 | case wxPropertyValueStringPtr: | |
550 | { | |
551 | int i; | |
552 | int len = strlen(*(m_value.stringPtr)); | |
553 | for (i = 0; i < len; i++) | |
554 | { | |
555 | char ch = *(m_value.stringPtr)[i]; | |
556 | ||
557 | } | |
558 | break; | |
559 | } | |
560 | case wxPropertyValueList: | |
561 | { | |
562 | if (!m_value.first) | |
563 | stream << "[]"; | |
564 | else | |
565 | { | |
566 | wxPropertyValue *expr = m_value.first; | |
567 | ||
568 | stream << "["; | |
569 | while (expr) | |
570 | { | |
571 | expr->WritePropertyType(stream); | |
572 | expr = expr->m_next; | |
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 | { | |
599 | m_modifiedFlag = TRUE; | |
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 | ||
608 | m_modifiedFlag = TRUE; | |
609 | if (m_type == wxPropertyValueNull) | |
610 | m_type = wxPropertyValueString; | |
611 | ||
612 | if (m_type == wxPropertyValueString) | |
613 | { | |
614 | if (val) | |
615 | m_value.string = copystring(val); | |
616 | else | |
617 | m_value.string = NULL; | |
618 | } | |
619 | else if (m_type == wxPropertyValueStringPtr) | |
620 | { | |
621 | if (*m_value.stringPtr) | |
622 | delete[] *m_value.stringPtr; | |
623 | if (val) | |
624 | *m_value.stringPtr = copystring(val); | |
625 | else | |
626 | *m_value.stringPtr = NULL; | |
627 | } | |
628 | ||
629 | m_clientData = NULL; | |
630 | m_next = NULL; | |
631 | m_last = NULL; | |
632 | ||
633 | } | |
634 | ||
635 | void wxPropertyValue::operator=(const long val) | |
636 | { | |
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; | |
652 | } | |
653 | ||
654 | void wxPropertyValue::operator=(const bool val) | |
655 | { | |
656 | m_modifiedFlag = TRUE; | |
657 | if (m_type == wxPropertyValueNull) | |
658 | m_type = wxPropertyValuebool; | |
659 | ||
660 | if (m_type == wxPropertyValuebool) | |
661 | m_value.integer = (long)val; | |
662 | else if (m_type == wxPropertyValueboolPtr) | |
663 | *m_value.boolPtr = val; | |
664 | ||
665 | m_clientData = NULL; | |
666 | m_next = NULL; | |
667 | } | |
668 | ||
669 | void wxPropertyValue::operator=(const float val) | |
670 | { | |
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; | |
686 | } | |
687 | ||
688 | void wxPropertyValue::operator=(const char **val) | |
689 | { | |
690 | m_modifiedFlag = TRUE; | |
691 | m_type = wxPropertyValueStringPtr; | |
692 | ||
693 | if (val) | |
694 | m_value.stringPtr = (char **)val; | |
695 | else | |
696 | m_value.stringPtr = NULL; | |
697 | m_clientData = NULL; | |
698 | m_next = NULL; | |
699 | m_last = NULL; | |
700 | ||
701 | } | |
702 | ||
703 | void wxPropertyValue::operator=(const long *val) | |
704 | { | |
705 | m_modifiedFlag = TRUE; | |
706 | m_type = wxPropertyValueIntegerPtr; | |
707 | m_value.integerPtr = (long *)val; | |
708 | m_clientData = NULL; | |
709 | m_next = NULL; | |
710 | } | |
711 | ||
712 | void wxPropertyValue::operator=(const bool *val) | |
713 | { | |
714 | m_modifiedFlag = TRUE; | |
715 | m_type = wxPropertyValueboolPtr; | |
716 | m_value.boolPtr = (bool *)val; | |
717 | m_clientData = NULL; | |
718 | m_next = NULL; | |
719 | } | |
720 | ||
721 | void wxPropertyValue::operator=(const float *val) | |
722 | { | |
723 | m_modifiedFlag = TRUE; | |
724 | m_type = wxPropertyValueRealPtr; | |
725 | m_value.realPtr = (float *)val; | |
726 | m_clientData = NULL; | |
727 | m_next = NULL; | |
728 | } | |
729 | ||
730 | long wxPropertyValue::IntegerValue(void) const | |
731 | { | |
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); | |
740 | else return 0; | |
741 | } | |
742 | ||
743 | long *wxPropertyValue::IntegerValuePtr(void) const | |
744 | { | |
745 | return m_value.integerPtr; | |
746 | } | |
747 | ||
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); | |
757 | else return 0.0; | |
758 | } | |
759 | ||
760 | float *wxPropertyValue::RealValuePtr(void) const | |
761 | { | |
762 | return m_value.realPtr; | |
763 | } | |
764 | ||
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); | |
778 | else return FALSE; | |
779 | } | |
780 | ||
781 | bool *wxPropertyValue::BoolValuePtr(void) const | |
782 | { | |
783 | return m_value.boolPtr; | |
784 | } | |
785 | ||
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); | |
791 | else return NULL; | |
792 | } | |
793 | ||
794 | char **wxPropertyValue::StringValuePtr(void) const | |
795 | { | |
796 | return m_value.stringPtr; | |
797 | } | |
798 | ||
799 | /* | |
800 | * A property (name plus value) | |
801 | */ | |
802 | ||
803 | IMPLEMENT_DYNAMIC_CLASS(wxProperty, wxObject) | |
804 | ||
805 | wxProperty::wxProperty(void) | |
806 | { | |
807 | m_propertyRole = (char *)NULL; | |
808 | m_propertyValidator = NULL; | |
809 | m_propertyWindow = NULL; | |
810 | m_enabled = TRUE; | |
811 | } | |
812 | ||
813 | wxProperty::wxProperty(wxProperty& copyFrom) | |
814 | { | |
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; | |
821 | } | |
822 | ||
823 | wxProperty::wxProperty(wxString nm, wxString role, wxPropertyValidator *ed):m_name(nm), m_propertyRole(role) | |
824 | { | |
825 | m_propertyValidator = ed; | |
826 | m_propertyWindow = NULL; | |
827 | m_enabled = TRUE; | |
828 | } | |
829 | ||
830 | wxProperty::wxProperty(wxString nm, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed): | |
831 | m_name(nm), m_value(val), m_propertyRole(role) | |
832 | { | |
833 | m_propertyValidator = ed; | |
834 | m_propertyWindow = NULL; | |
835 | m_enabled = TRUE; | |
836 | } | |
837 | ||
838 | wxProperty::~wxProperty(void) | |
839 | { | |
840 | if (m_propertyValidator) | |
841 | delete m_propertyValidator; | |
842 | } | |
843 | ||
844 | wxPropertyValue& wxProperty::GetValue(void) const | |
845 | { | |
846 | return (wxPropertyValue&) m_value; | |
847 | } | |
848 | ||
849 | wxPropertyValidator *wxProperty::GetValidator(void) const | |
850 | { | |
851 | return m_propertyValidator; | |
852 | } | |
853 | ||
854 | wxString& wxProperty::GetName(void) const | |
855 | { | |
856 | return (wxString&) m_name; | |
857 | } | |
858 | ||
859 | wxString& wxProperty::GetRole(void) const | |
860 | { | |
861 | return (wxString&) m_propertyRole; | |
862 | } | |
863 | ||
864 | void wxProperty::SetValue(const wxPropertyValue& val) | |
865 | { | |
866 | m_value = val; | |
867 | } | |
868 | ||
869 | void wxProperty::SetValidator(wxPropertyValidator *ed) | |
870 | { | |
871 | m_propertyValidator = ed; | |
872 | } | |
873 | ||
874 | void wxProperty::SetRole(wxString& role) | |
875 | { | |
876 | m_propertyRole = role; | |
877 | } | |
878 | ||
879 | void wxProperty::SetName(wxString& nm) | |
880 | { | |
881 | m_name = nm; | |
882 | } | |
883 | ||
884 | void wxProperty::operator=(const wxPropertyValue& val) | |
885 | { | |
886 | m_value = val; | |
887 | } | |
888 | ||
889 | /* | |
890 | * Base property view class | |
891 | */ | |
892 | ||
893 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyView, wxEvtHandler) | |
894 | ||
895 | wxPropertyView::wxPropertyView(long flags) | |
896 | { | |
897 | m_buttonFlags = flags; | |
898 | m_propertySheet = NULL; | |
899 | m_currentValidator = NULL; | |
900 | m_currentProperty = NULL; | |
901 | } | |
902 | ||
903 | wxPropertyView::~wxPropertyView(void) | |
904 | { | |
905 | } | |
906 | ||
907 | void wxPropertyView::AddRegistry(wxPropertyValidatorRegistry *registry) | |
908 | { | |
909 | m_validatorRegistryList.Append(registry); | |
910 | } | |
911 | ||
912 | wxPropertyValidator *wxPropertyView::FindPropertyValidator(wxProperty *property) | |
913 | { | |
914 | if (property->GetValidator()) | |
915 | return property->GetValidator(); | |
916 | ||
917 | wxNode *node = m_validatorRegistryList.First(); | |
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 | ||
940 | wxPropertySheet::wxPropertySheet(void):m_properties(wxKEY_STRING) | |
941 | { | |
942 | } | |
943 | ||
944 | wxPropertySheet::~wxPropertySheet(void) | |
945 | { | |
946 | Clear(); | |
947 | } | |
948 | ||
949 | bool wxPropertySheet::Save( ostream& WXUNUSED(str) ) | |
950 | { | |
951 | return FALSE; | |
952 | } | |
953 | ||
954 | bool wxPropertySheet::Load( ostream& WXUNUSED(str) ) | |
955 | { | |
956 | return FALSE; | |
957 | } | |
958 | ||
959 | void wxPropertySheet::UpdateAllViews( wxPropertyView *WXUNUSED(thisView) ) | |
960 | { | |
961 | } | |
962 | ||
963 | // Add a property | |
964 | void wxPropertySheet::AddProperty(wxProperty *property) | |
965 | { | |
966 | m_properties.Append((const char*) property->GetName(), property); | |
967 | } | |
968 | ||
969 | // Get property by name | |
970 | wxProperty *wxPropertySheet::GetProperty(wxString name) | |
971 | { | |
972 | wxNode *node = m_properties.Find((const char*) name); | |
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 | { | |
982 | wxNode *node = m_properties.First(); | |
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 | { | |
996 | wxNode *node = m_properties.First(); | |
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(const wxString& typeName, wxPropertyValidator *validator) | |
1022 | { | |
1023 | Put((const char*) typeName, validator); | |
1024 | } | |
1025 | ||
1026 | wxPropertyValidator *wxPropertyValidatorRegistry::GetValidator(const wxString& typeName) | |
1027 | { | |
1028 | return (wxPropertyValidator *)Get((const char*) typeName); | |
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 | { | |
1050 | m_validatorFlags = flags; | |
1051 | m_validatorProperty = NULL; | |
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 |