]> git.saurik.com Git - wxWidgets.git/blob - src/generic/prop.cpp
declared (not implemented yet) wxMimeTypesManager::AddFallbacks()
[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 #ifdef __X__
332 cerr << "Should never get here!\n";
333 #endif
334 break;
335 }
336 return NULL;
337 }
338
339 void wxPropertyValue::Copy(wxPropertyValue& copyFrom)
340 {
341 m_type = copyFrom.Type();
342
343 switch (m_type)
344 {
345 case wxPropertyValueInteger:
346 (*this) = copyFrom.IntegerValue();
347 return ;
348
349 case wxPropertyValueReal:
350 (*this) = copyFrom.RealValue();
351 return ;
352
353 case wxPropertyValueString:
354 (*this) = wxString(copyFrom.StringValue());
355 return ;
356
357 case wxPropertyValuebool:
358 (*this) = copyFrom.BoolValue();
359 return ;
360
361 // Pointers
362 case wxPropertyValueboolPtr:
363 (*this) = copyFrom.BoolValuePtr();
364 return ;
365 case wxPropertyValueRealPtr:
366 (*this) = copyFrom.RealValuePtr();
367 return ;
368 case wxPropertyValueIntegerPtr:
369 (*this) = copyFrom.IntegerValuePtr();
370 return ;
371 case wxPropertyValueStringPtr:
372 {
373 wxChar** s = copyFrom.StringValuePtr();
374 // what is this? are you trying to assign a bool or a string? VA can't figure it out..
375 #if defined(__VISAGECPP__)
376 (*this) = s;
377 #else
378 (*this) = s != 0;
379 #endif
380 return ;
381 }
382
383 case wxPropertyValueList:
384 {
385 m_value.first = NULL;
386 m_next = NULL;
387 m_last = NULL;
388 wxPropertyValue *expr = copyFrom.m_value.first;
389 while (expr)
390 {
391 wxPropertyValue *expr2 = expr->NewCopy();
392 Append(expr2);
393 expr = expr->m_next;
394 }
395 return;
396 }
397 case wxPropertyValueNull:
398 #ifdef __X__
399 cerr << "Should never get here!\n";
400 #endif
401 break;
402 }
403 }
404
405 // Return nth argument of a clause (starting from 1)
406 wxPropertyValue *wxPropertyValue::Arg(wxPropertyValueType type, int arg) const
407 {
408 wxPropertyValue *expr = m_value.first;
409 for (int i = 1; i < arg; i++)
410 if (expr)
411 expr = expr->m_next;
412
413 if (expr && (expr->m_type == type))
414 return expr;
415 else
416 return NULL;
417 }
418
419 // Return nth argument of a list expression (starting from zero)
420 wxPropertyValue *wxPropertyValue::Nth(int arg) const
421 {
422 if (m_type != wxPropertyValueList)
423 return NULL;
424
425 wxPropertyValue *expr = m_value.first;
426 for (int i = 0; i < arg; i++)
427 if (expr)
428 expr = expr->m_next;
429 else return NULL;
430
431 if (expr)
432 return expr;
433 else
434 return NULL;
435 }
436
437 // Returns the number of elements in a list expression
438 int wxPropertyValue::Number(void) const
439 {
440 if (m_type != wxPropertyValueList)
441 return 0;
442
443 int i = 0;
444 wxPropertyValue *expr = m_value.first;
445 while (expr)
446 {
447 expr = expr->m_next;
448 i ++;
449 }
450 return i;
451 }
452
453 void wxPropertyValue::WritePropertyClause(wxString& stream) // Write this expression as a top-level clause
454 {
455 if (m_type != wxPropertyValueList)
456 return;
457
458 wxPropertyValue *node = m_value.first;
459 if (node)
460 {
461 node->WritePropertyType(stream);
462 stream.Append( _T("(") );
463 node = node->m_next;
464 bool first = TRUE;
465 while (node)
466 {
467 if (!first)
468 stream.Append( _T(" ") );
469 node->WritePropertyType(stream);
470 node = node->m_next;
471 if (node)
472 stream.Append( _T(",\n" ) );
473 first = FALSE;
474 }
475 stream.Append( _T(").\n\n") );
476 }
477 }
478
479 void wxPropertyValue::WritePropertyType(wxString& stream) // Write as any other subexpression
480 {
481 wxString tmp;
482 switch (m_type)
483 {
484 case wxPropertyValueInteger:
485 {
486 tmp.Printf( _T("%ld"), m_value.integer );
487 stream.Append( tmp );
488 break;
489 }
490 case wxPropertyValueIntegerPtr:
491 {
492 tmp.Printf( _T("%ld"), *m_value.integerPtr );
493 stream.Append( tmp );
494 break;
495 }
496 case wxPropertyValuebool:
497 {
498 if (m_value.integer)
499 stream.Append( _T("True") );
500 else
501 stream.Append( _T("False") );
502 break;
503 }
504 case wxPropertyValueboolPtr:
505 {
506 if (*m_value.integerPtr)
507 stream.Append( _T("True") );
508 else
509 stream.Append( _T("False") );
510 break;
511 }
512 case wxPropertyValueReal:
513 {
514 double d = m_value.real;
515 tmp.Printf( _T("%.6g"), d );
516 stream.Append( tmp );
517 break;
518 }
519 case wxPropertyValueRealPtr:
520 {
521 double d = *m_value.realPtr;
522 tmp.Printf( _T("%.6g"), d );
523 stream.Append( tmp );
524 break;
525 }
526 case wxPropertyValueString:
527 {
528 stream.Append( m_value.string );
529 break;
530 }
531 case wxPropertyValueStringPtr:
532 {
533 wxFAIL_MSG( _T("wxPropertyValue::WritePropertyType( wxPropertyValueStringPtr ) not implemented") );
534 /*
535 int i;
536 int len = strlen(*(m_value.stringPtr));
537 for (i = 0; i < len; i++)
538 {
539 char ch = *(m_value.stringPtr)[i];
540
541 }
542 */
543 break;
544 }
545 case wxPropertyValueList:
546 {
547 if (!m_value.first)
548 stream.Append( _T("[]") );
549 else
550 {
551 wxPropertyValue *expr = m_value.first;
552
553 stream.Append( _T("[") );
554 while (expr)
555 {
556 expr->WritePropertyType(stream);
557 expr = expr->m_next;
558 if (expr)
559 stream.Append( _T(", ") );
560 }
561 stream.Append( _T("]") );
562 }
563 break;
564 }
565 case wxPropertyValueNull: break;
566 }
567 }
568
569 wxString wxPropertyValue::GetStringRepresentation(void)
570 {
571 wxString str;
572 WritePropertyType(str);
573 return str;
574 }
575
576 void wxPropertyValue::operator=(const wxPropertyValue& val)
577 {
578 m_modifiedFlag = TRUE;
579 Copy((wxPropertyValue&)val);
580 }
581
582 // void wxPropertyValue::operator=(const char *val)
583 void wxPropertyValue::operator=(const wxString& val1)
584 {
585 const wxChar *val = (const wxChar *)val1;
586
587 m_modifiedFlag = TRUE;
588 if (m_type == wxPropertyValueNull)
589 m_type = wxPropertyValueString;
590
591 if (m_type == wxPropertyValueString)
592 {
593 if (val)
594 m_value.string = copystring(val);
595 else
596 m_value.string = NULL;
597 }
598 else if (m_type == wxPropertyValueStringPtr)
599 {
600 if (*m_value.stringPtr)
601 delete[] *m_value.stringPtr;
602 if (val)
603 *m_value.stringPtr = copystring(val);
604 else
605 *m_value.stringPtr = NULL;
606 }
607
608 m_clientData = NULL;
609 m_next = NULL;
610 m_last = NULL;
611
612 }
613
614 void wxPropertyValue::operator=(const long val)
615 {
616 m_modifiedFlag = TRUE;
617 if (m_type == wxPropertyValueNull)
618 m_type = wxPropertyValueInteger;
619
620 if (m_type == wxPropertyValueInteger)
621 m_value.integer = val;
622 else if (m_type == wxPropertyValueIntegerPtr)
623 *m_value.integerPtr = val;
624 else if (m_type == wxPropertyValueReal)
625 m_value.real = (float)val;
626 else if (m_type == wxPropertyValueRealPtr)
627 *m_value.realPtr = (float)val;
628
629 m_clientData = NULL;
630 m_next = NULL;
631 }
632
633 void wxPropertyValue::operator=(const bool val)
634 {
635 m_modifiedFlag = TRUE;
636 if (m_type == wxPropertyValueNull)
637 m_type = wxPropertyValuebool;
638
639 if (m_type == wxPropertyValuebool)
640 m_value.integer = (long)val;
641 else if (m_type == wxPropertyValueboolPtr)
642 *m_value.boolPtr = val;
643
644 m_clientData = NULL;
645 m_next = NULL;
646 }
647
648 void wxPropertyValue::operator=(const float val)
649 {
650 m_modifiedFlag = TRUE;
651 if (m_type == wxPropertyValueNull)
652 m_type = wxPropertyValueReal;
653
654 if (m_type == wxPropertyValueInteger)
655 m_value.integer = (long)val;
656 else if (m_type == wxPropertyValueIntegerPtr)
657 *m_value.integerPtr = (long)val;
658 else if (m_type == wxPropertyValueReal)
659 m_value.real = val;
660 else if (m_type == wxPropertyValueRealPtr)
661 *m_value.realPtr = val;
662
663 m_clientData = NULL;
664 m_next = NULL;
665 }
666
667 void wxPropertyValue::operator=(const wxChar **val)
668 {
669 m_modifiedFlag = TRUE;
670 m_type = wxPropertyValueStringPtr;
671
672 if (val)
673 m_value.stringPtr = (wxChar **)val;
674 else
675 m_value.stringPtr = NULL;
676 m_clientData = NULL;
677 m_next = NULL;
678 m_last = NULL;
679
680 }
681
682 void wxPropertyValue::operator=(const long *val)
683 {
684 m_modifiedFlag = TRUE;
685 m_type = wxPropertyValueIntegerPtr;
686 m_value.integerPtr = (long *)val;
687 m_clientData = NULL;
688 m_next = NULL;
689 }
690
691 void wxPropertyValue::operator=(const bool *val)
692 {
693 m_modifiedFlag = TRUE;
694 m_type = wxPropertyValueboolPtr;
695 m_value.boolPtr = (bool *)val;
696 m_clientData = NULL;
697 m_next = NULL;
698 }
699
700 void wxPropertyValue::operator=(const float *val)
701 {
702 m_modifiedFlag = TRUE;
703 m_type = wxPropertyValueRealPtr;
704 m_value.realPtr = (float *)val;
705 m_clientData = NULL;
706 m_next = NULL;
707 }
708
709 long wxPropertyValue::IntegerValue(void) const
710 {
711 if (m_type == wxPropertyValueInteger)
712 return m_value.integer;
713 else if (m_type == wxPropertyValueReal)
714 return (long)m_value.real;
715 else if (m_type == wxPropertyValueIntegerPtr)
716 return *m_value.integerPtr;
717 else if (m_type == wxPropertyValueRealPtr)
718 return (long)(*m_value.realPtr);
719 else return 0;
720 }
721
722 long *wxPropertyValue::IntegerValuePtr(void) const
723 {
724 return m_value.integerPtr;
725 }
726
727 float wxPropertyValue::RealValue(void) const {
728 if (m_type == wxPropertyValueReal)
729 return m_value.real;
730 else if (m_type == wxPropertyValueRealPtr)
731 return *m_value.realPtr;
732 else if (m_type == wxPropertyValueInteger)
733 return (float)m_value.integer;
734 else if (m_type == wxPropertyValueIntegerPtr)
735 return (float)*(m_value.integerPtr);
736 else return 0.0;
737 }
738
739 float *wxPropertyValue::RealValuePtr(void) const
740 {
741 return m_value.realPtr;
742 }
743
744 bool wxPropertyValue::BoolValue(void) const {
745 if (m_type == wxPropertyValueReal)
746 return (m_value.real != 0.0);
747 if (m_type == wxPropertyValueRealPtr)
748 return (*(m_value.realPtr) != 0.0);
749 else if (m_type == wxPropertyValueInteger)
750 return (m_value.integer != 0);
751 else if (m_type == wxPropertyValueIntegerPtr)
752 return (*(m_value.integerPtr) != 0);
753 else if (m_type == wxPropertyValuebool)
754 return (m_value.integer != 0);
755 else if (m_type == wxPropertyValueboolPtr)
756 return (*(m_value.boolPtr) != 0);
757 else return FALSE;
758 }
759
760 bool *wxPropertyValue::BoolValuePtr(void) const
761 {
762 return m_value.boolPtr;
763 }
764
765 wxChar *wxPropertyValue::StringValue(void) const {
766 if (m_type == wxPropertyValueString)
767 return m_value.string;
768 else if (m_type == wxPropertyValueStringPtr)
769 return *(m_value.stringPtr);
770 else return NULL;
771 }
772
773 wxChar **wxPropertyValue::StringValuePtr(void) const
774 {
775 return m_value.stringPtr;
776 }
777
778 /*
779 * A property (name plus value)
780 */
781
782 IMPLEMENT_DYNAMIC_CLASS(wxProperty, wxObject)
783
784 wxProperty::wxProperty(void)
785 {
786 m_propertyRole = wxEmptyString;
787 m_propertyValidator = NULL;
788 m_propertyWindow = NULL;
789 m_enabled = TRUE;
790 }
791
792 wxProperty::wxProperty(wxProperty& copyFrom)
793 {
794 m_value = copyFrom.GetValue();
795 m_name = copyFrom.GetName();
796 m_propertyRole = copyFrom.GetRole();
797 m_propertyValidator = copyFrom.GetValidator();
798 m_enabled = copyFrom.IsEnabled();
799 m_propertyWindow = NULL;
800 }
801
802 wxProperty::wxProperty(wxString nm, wxString role, wxPropertyValidator *ed):m_name(nm), m_propertyRole(role)
803 {
804 m_propertyValidator = ed;
805 m_propertyWindow = NULL;
806 m_enabled = TRUE;
807 }
808
809 wxProperty::wxProperty(wxString nm, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed):
810 m_value(val), m_name(nm), m_propertyRole(role)
811 {
812 m_propertyValidator = ed;
813 m_propertyWindow = NULL;
814 m_enabled = TRUE;
815 }
816
817 wxProperty::~wxProperty(void)
818 {
819 if (m_propertyValidator)
820 delete m_propertyValidator;
821 }
822
823 wxPropertyValue& wxProperty::GetValue(void) const
824 {
825 return (wxPropertyValue&) m_value;
826 }
827
828 wxPropertyValidator *wxProperty::GetValidator(void) const
829 {
830 return m_propertyValidator;
831 }
832
833 wxString& wxProperty::GetName(void) const
834 {
835 return (wxString&) m_name;
836 }
837
838 wxString& wxProperty::GetRole(void) const
839 {
840 return (wxString&) m_propertyRole;
841 }
842
843 void wxProperty::SetValue(const wxPropertyValue& val)
844 {
845 m_value = val;
846 }
847
848 void wxProperty::SetValidator(wxPropertyValidator *ed)
849 {
850 m_propertyValidator = ed;
851 }
852
853 void wxProperty::SetRole(wxString& role)
854 {
855 m_propertyRole = role;
856 }
857
858 void wxProperty::SetName(wxString& nm)
859 {
860 m_name = nm;
861 }
862
863 void wxProperty::operator=(const wxPropertyValue& val)
864 {
865 m_value = val;
866 }
867
868 /*
869 * Base property view class
870 */
871
872 IMPLEMENT_DYNAMIC_CLASS(wxPropertyView, wxEvtHandler)
873
874 wxPropertyView::wxPropertyView(long flags)
875 {
876 m_buttonFlags = flags;
877 m_propertySheet = NULL;
878 m_currentValidator = NULL;
879 m_currentProperty = NULL;
880 }
881
882 wxPropertyView::~wxPropertyView(void)
883 {
884 }
885
886 void wxPropertyView::AddRegistry(wxPropertyValidatorRegistry *registry)
887 {
888 m_validatorRegistryList.Append(registry);
889 }
890
891 wxPropertyValidator *wxPropertyView::FindPropertyValidator(wxProperty *property)
892 {
893 if (property->GetValidator())
894 return property->GetValidator();
895
896 wxNode *node = m_validatorRegistryList.First();
897 while (node)
898 {
899 wxPropertyValidatorRegistry *registry = (wxPropertyValidatorRegistry *)node->Data();
900 wxPropertyValidator *validator = registry->GetValidator(property->GetRole());
901 if (validator)
902 return validator;
903 node = node->Next();
904 }
905 return NULL;
906 /*
907 if (!wxDefaultPropertyValidator)
908 wxDefaultPropertyValidator = new wxPropertyListValidator;
909 return wxDefaultPropertyValidator;
910 */
911 }
912
913 /*
914 * Property sheet
915 */
916
917 IMPLEMENT_DYNAMIC_CLASS(wxPropertySheet, wxObject)
918
919 wxPropertySheet::wxPropertySheet(const wxString& name)
920 :m_properties(wxKEY_STRING),m_name(name)
921 {
922 }
923
924 wxPropertySheet::~wxPropertySheet(void)
925 {
926 Clear();
927 }
928
929 void wxPropertySheet::UpdateAllViews( wxPropertyView *WXUNUSED(thisView) )
930 {
931 }
932
933 // Add a property
934 void wxPropertySheet::AddProperty(wxProperty *property)
935 {
936 m_properties.Append((const wxChar*) property->GetName(), property);
937 }
938
939 // Get property by name
940 wxProperty *wxPropertySheet::GetProperty(const wxString& name) const
941 {
942 wxNode *node = m_properties.Find((const wxChar*) name);
943 if (!node)
944 return NULL;
945 else
946 return (wxProperty *)node->Data();
947 }
948
949 bool wxPropertySheet::SetProperty(const wxString& name, const wxPropertyValue& value)
950 {
951 wxProperty* prop = GetProperty(name);
952 if(prop){
953 prop->SetValue(value);
954 return TRUE;
955 }else{
956 return FALSE;
957 }
958 }
959
960 void wxPropertySheet::RemoveProperty(const wxString& name)
961 {
962 wxNode *node = m_properties.Find(name);
963 if(node)
964 {
965 wxProperty *prop = (wxProperty *)node->Data();
966 delete prop;
967 m_properties.DeleteNode(node);
968 }
969 }
970
971 bool wxPropertySheet::HasProperty(const wxString& name) const
972 {
973 return (GetProperty(name)?TRUE:FALSE);
974 }
975
976 // Clear all properties
977 void wxPropertySheet::Clear(void)
978 {
979 wxNode *node = m_properties.First();
980 while (node)
981 {
982 wxProperty *prop = (wxProperty *)node->Data();
983 wxNode *next = node->Next();
984 delete prop;
985 delete node;
986 node = next;
987 }
988 }
989
990 // Sets/clears the modified flag for each property value
991 void wxPropertySheet::SetAllModified(bool flag)
992 {
993 wxNode *node = m_properties.First();
994 while (node)
995 {
996 wxProperty *prop = (wxProperty *)node->Data();
997 prop->GetValue().SetModified(flag);
998 node = node->Next();
999 }
1000 }
1001
1002 /*
1003 * Property validator registry
1004 *
1005 */
1006
1007 IMPLEMENT_DYNAMIC_CLASS(wxPropertyValidatorRegistry, wxHashTable)
1008
1009 wxPropertyValidatorRegistry::wxPropertyValidatorRegistry(void):wxHashTable(wxKEY_STRING)
1010 {
1011 }
1012
1013 wxPropertyValidatorRegistry::~wxPropertyValidatorRegistry(void)
1014 {
1015 ClearRegistry();
1016 }
1017
1018 void wxPropertyValidatorRegistry::RegisterValidator(const wxString& typeName, wxPropertyValidator *validator)
1019 {
1020 Put((const wxChar*) typeName, validator);
1021 }
1022
1023 wxPropertyValidator *wxPropertyValidatorRegistry::GetValidator(const wxString& typeName)
1024 {
1025 return (wxPropertyValidator *)Get((const wxChar*) typeName);
1026 }
1027
1028 void wxPropertyValidatorRegistry::ClearRegistry(void)
1029 {
1030 BeginFind();
1031 wxNode *node;
1032 while ((node = Next()) != NULL)
1033 {
1034 delete (wxPropertyValidator *)node->Data();
1035 }
1036 }
1037
1038 /*
1039 * Property validator
1040 */
1041
1042
1043 IMPLEMENT_ABSTRACT_CLASS(wxPropertyValidator, wxEvtHandler)
1044
1045 wxPropertyValidator::wxPropertyValidator(long flags)
1046 {
1047 m_validatorFlags = flags;
1048 m_validatorProperty = NULL;
1049 }
1050
1051 wxPropertyValidator::~wxPropertyValidator(void)
1052 {}
1053
1054 bool wxPropertyValidator::StringToFloat (wxChar *s, float *number) {
1055 double num;
1056 bool ok = StringToDouble (s, &num);
1057 *number = (float) num;
1058 return ok;
1059 }
1060
1061 bool wxPropertyValidator::StringToDouble (wxChar *s, double *number) {
1062 bool ok = TRUE;
1063 wxChar *value_ptr;
1064 *number = wxStrtod (s, &value_ptr);
1065 if (value_ptr) {
1066 int len = wxStrlen (value_ptr);
1067 for (int i = 0; i < len; i++) {
1068 ok = (wxIsspace (value_ptr[i]) != 0);
1069 if (!ok) return FALSE;
1070 }
1071 }
1072 return ok;
1073 }
1074
1075 bool wxPropertyValidator::StringToInt (wxChar *s, int *number) {
1076 long num;
1077 bool ok = StringToLong (s, &num);
1078 *number = (int) num;
1079 return ok;
1080 }
1081
1082 bool wxPropertyValidator::StringToLong (wxChar *s, long *number) {
1083 bool ok = TRUE;
1084 wxChar *value_ptr;
1085 *number = wxStrtol (s, &value_ptr, 10);
1086 if (value_ptr) {
1087 int len = wxStrlen (value_ptr);
1088 for (int i = 0; i < len; i++) {
1089 ok = (wxIsspace (value_ptr[i]) != 0);
1090 if (!ok) return FALSE;
1091 }
1092 }
1093 return ok;
1094 }
1095
1096 wxChar *wxPropertyValidator::FloatToString (float number) {
1097 static wxChar buf[20];
1098 wxSprintf (buf, _T("%.6g"), number);
1099 return buf;
1100 }
1101
1102 wxChar *wxPropertyValidator::DoubleToString (double number) {
1103 static wxChar buf[20];
1104 wxSprintf (buf, _T("%.6g"), number);
1105 return buf;
1106 }
1107
1108 wxChar *wxPropertyValidator::IntToString (int number) {
1109 return ::IntToString (number);
1110 }
1111
1112 wxChar *wxPropertyValidator::LongToString (long number) {
1113 return ::LongToString (number);
1114 }