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