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