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