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