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