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