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