]> git.saurik.com Git - wxWidgets.git/blame - src/generic/prop.cpp
Applied a modification of Patch #704995 which changes how the lines
[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 25#ifndef WX_PRECOMP
e3a43801
JS
26#endif
27
c693edf3
RR
28#include "wx/debug.h"
29#include "wx/prop.h"
30
e3a43801
JS
31#include <ctype.h>
32#include <stdlib.h>
33#include <math.h>
34#include <string.h>
35
e3a43801
JS
36
37IMPLEMENT_DYNAMIC_CLASS(wxPropertyValue, wxObject)
38
39wxPropertyValue::wxPropertyValue(void)
40{
41 m_type = wxPropertyValueNull;
42 m_next = NULL;
43 m_last = NULL;
44 m_value.first = NULL;
45 m_clientData = NULL;
46 m_modifiedFlag = FALSE;
47}
48
49wxPropertyValue::wxPropertyValue(const wxPropertyValue& copyFrom)
9f081f02 50 : wxObject()
e3a43801 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
b1d4dd7a 162 wxNode *node = the_list->GetFirst();
e3a43801
JS
163 while (node)
164 {
b1d4dd7a 165 wxPropertyValue *expr = (wxPropertyValue *)node->GetData();
e3a43801 166 Append(expr);
b1d4dd7a 167 node = node->GetNext();
e3a43801
JS
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
b1d4dd7a 181 wxStringList::Node *node = the_list->GetFirst();
e3a43801
JS
182 while (node)
183 {
b1d4dd7a 184 wxChar *s = node->GetData();
e3a43801 185 Append(new wxPropertyValue(s));
b1d4dd7a 186 node = node->GetNext();
e3a43801
JS
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)
9f081f02 838 : wxObject()
e3a43801
JS
839{
840 m_value = copyFrom.GetValue();
841 m_name = copyFrom.GetName();
842 m_propertyRole = copyFrom.GetRole();
843 m_propertyValidator = copyFrom.GetValidator();
844 m_enabled = copyFrom.IsEnabled();
845 m_propertyWindow = NULL;
846}
847
848wxProperty::wxProperty(wxString nm, wxString role, wxPropertyValidator *ed):m_name(nm), m_propertyRole(role)
849{
850 m_propertyValidator = ed;
851 m_propertyWindow = NULL;
852 m_enabled = TRUE;
853}
854
855wxProperty::wxProperty(wxString nm, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed):
8710cf5c 856 m_value(val), m_name(nm), m_propertyRole(role)
e3a43801
JS
857{
858 m_propertyValidator = ed;
859 m_propertyWindow = NULL;
860 m_enabled = TRUE;
861}
862
863wxProperty::~wxProperty(void)
864{
865 if (m_propertyValidator)
866 delete m_propertyValidator;
867}
868
869wxPropertyValue& wxProperty::GetValue(void) const
870{
871 return (wxPropertyValue&) m_value;
872}
873
874wxPropertyValidator *wxProperty::GetValidator(void) const
875{
876 return m_propertyValidator;
877}
878
879wxString& wxProperty::GetName(void) const
880{
881 return (wxString&) m_name;
882}
883
884wxString& wxProperty::GetRole(void) const
885{
886 return (wxString&) m_propertyRole;
887}
888
889void wxProperty::SetValue(const wxPropertyValue& val)
890{
891 m_value = val;
892}
893
894void wxProperty::SetValidator(wxPropertyValidator *ed)
895{
896 m_propertyValidator = ed;
897}
898
899void wxProperty::SetRole(wxString& role)
900{
901 m_propertyRole = role;
902}
903
904void wxProperty::SetName(wxString& nm)
905{
906 m_name = nm;
907}
908
909void wxProperty::operator=(const wxPropertyValue& val)
910{
911 m_value = val;
912}
913
914/*
915 * Base property view class
916 */
2179d579 917
e3a43801
JS
918IMPLEMENT_DYNAMIC_CLASS(wxPropertyView, wxEvtHandler)
919
920wxPropertyView::wxPropertyView(long flags)
921{
922 m_buttonFlags = flags;
923 m_propertySheet = NULL;
924 m_currentValidator = NULL;
925 m_currentProperty = NULL;
926}
927
928wxPropertyView::~wxPropertyView(void)
929{
930}
931
932void wxPropertyView::AddRegistry(wxPropertyValidatorRegistry *registry)
933{
934 m_validatorRegistryList.Append(registry);
935}
936
937wxPropertyValidator *wxPropertyView::FindPropertyValidator(wxProperty *property)
938{
939 if (property->GetValidator())
940 return property->GetValidator();
2179d579 941
b1d4dd7a 942 wxNode *node = m_validatorRegistryList.GetFirst();
e3a43801
JS
943 while (node)
944 {
b1d4dd7a 945 wxPropertyValidatorRegistry *registry = (wxPropertyValidatorRegistry *)node->GetData();
e3a43801
JS
946 wxPropertyValidator *validator = registry->GetValidator(property->GetRole());
947 if (validator)
948 return validator;
b1d4dd7a 949 node = node->GetNext();
e3a43801
JS
950 }
951 return NULL;
952/*
953 if (!wxDefaultPropertyValidator)
954 wxDefaultPropertyValidator = new wxPropertyListValidator;
955 return wxDefaultPropertyValidator;
956*/
957}
958
959/*
960 * Property sheet
961 */
962
963IMPLEMENT_DYNAMIC_CLASS(wxPropertySheet, wxObject)
964
cba2db0c 965wxPropertySheet::wxPropertySheet(const wxString& name)
f3a65071 966:m_properties(wxKEY_STRING),m_name(name)
e3a43801
JS
967{
968}
969
970wxPropertySheet::~wxPropertySheet(void)
971{
972 Clear();
973}
974
e3a43801
JS
975void wxPropertySheet::UpdateAllViews( wxPropertyView *WXUNUSED(thisView) )
976{
977}
978
979// Add a property
980void wxPropertySheet::AddProperty(wxProperty *property)
981{
87138c52 982 m_properties.Append((const wxChar*) property->GetName(), property);
e3a43801
JS
983}
984
985// Get property by name
cba2db0c 986wxProperty *wxPropertySheet::GetProperty(const wxString& name) const
e3a43801 987{
87138c52 988 wxNode *node = m_properties.Find((const wxChar*) name);
e3a43801
JS
989 if (!node)
990 return NULL;
991 else
b1d4dd7a 992 return (wxProperty *)node->GetData();
e3a43801 993}
cba2db0c
JS
994
995bool wxPropertySheet::SetProperty(const wxString& name, const wxPropertyValue& value)
f3a65071
JS
996{
997 wxProperty* prop = GetProperty(name);
998 if(prop){
999 prop->SetValue(value);
0a240683 1000 return TRUE;
f3a65071 1001 }else{
0a240683 1002 return FALSE;
f3a65071
JS
1003 }
1004}
cba2db0c
JS
1005
1006void wxPropertySheet::RemoveProperty(const wxString& name)
f3a65071
JS
1007{
1008 wxNode *node = m_properties.Find(name);
1009 if(node)
1010 {
b1d4dd7a 1011 wxProperty *prop = (wxProperty *)node->GetData();
1e6feb95 1012 delete prop;
f3a65071
JS
1013 m_properties.DeleteNode(node);
1014 }
1e6feb95 1015}
cba2db0c
JS
1016
1017bool wxPropertySheet::HasProperty(const wxString& name) const
2179d579 1018{
1e6feb95 1019 return (GetProperty(name)?TRUE:FALSE);
f3a65071 1020}
cba2db0c 1021
e3a43801
JS
1022// Clear all properties
1023void wxPropertySheet::Clear(void)
1024{
b1d4dd7a 1025 wxNode *node = m_properties.GetFirst();
e3a43801
JS
1026 while (node)
1027 {
b1d4dd7a
RL
1028 wxProperty *prop = (wxProperty *)node->GetData();
1029 wxNode *next = node->GetNext();
e3a43801
JS
1030 delete prop;
1031 delete node;
1032 node = next;
1033 }
1034}
1035
1036// Sets/clears the modified flag for each property value
1037void wxPropertySheet::SetAllModified(bool flag)
1038{
b1d4dd7a 1039 wxNode *node = m_properties.GetFirst();
e3a43801
JS
1040 while (node)
1041 {
b1d4dd7a 1042 wxProperty *prop = (wxProperty *)node->GetData();
e3a43801 1043 prop->GetValue().SetModified(flag);
b1d4dd7a 1044 node = node->GetNext();
2179d579 1045 }
e3a43801
JS
1046}
1047
1048/*
1049 * Property validator registry
1050 *
1051 */
1052
1053IMPLEMENT_DYNAMIC_CLASS(wxPropertyValidatorRegistry, wxHashTable)
1054
1055wxPropertyValidatorRegistry::wxPropertyValidatorRegistry(void):wxHashTable(wxKEY_STRING)
1056{
1057}
1058
1059wxPropertyValidatorRegistry::~wxPropertyValidatorRegistry(void)
1060{
1061 ClearRegistry();
1062}
1063
1064void wxPropertyValidatorRegistry::RegisterValidator(const wxString& typeName, wxPropertyValidator *validator)
1065{
87138c52 1066 Put((const wxChar*) typeName, validator);
e3a43801
JS
1067}
1068
1069wxPropertyValidator *wxPropertyValidatorRegistry::GetValidator(const wxString& typeName)
1070{
87138c52 1071 return (wxPropertyValidator *)Get((const wxChar*) typeName);
e3a43801
JS
1072}
1073
1074void wxPropertyValidatorRegistry::ClearRegistry(void)
1075{
1076 BeginFind();
1077 wxNode *node;
b21624e7 1078 while ((node = Next()) != NULL)
e3a43801 1079 {
b1d4dd7a 1080 delete (wxPropertyValidator *)node->GetData();
e3a43801
JS
1081 }
1082}
1083
1084 /*
1085 * Property validator
1086 */
1087
1088
1089IMPLEMENT_ABSTRACT_CLASS(wxPropertyValidator, wxEvtHandler)
1090
1091wxPropertyValidator::wxPropertyValidator(long flags)
1092{
1093 m_validatorFlags = flags;
1094 m_validatorProperty = NULL;
1095}
1096
1097wxPropertyValidator::~wxPropertyValidator(void)
1098{}
1099
87138c52 1100bool wxPropertyValidator::StringToFloat (wxChar *s, float *number) {
1e6feb95
VZ
1101 double num;
1102 bool ok = StringToDouble (s, &num);
1103 *number = (float) num;
1104 return ok;
e3a43801
JS
1105}
1106
87138c52 1107bool wxPropertyValidator::StringToDouble (wxChar *s, double *number) {
e3a43801 1108 bool ok = TRUE;
87138c52
OK
1109 wxChar *value_ptr;
1110 *number = wxStrtod (s, &value_ptr);
e3a43801 1111 if (value_ptr) {
1e6feb95
VZ
1112 int len = wxStrlen (value_ptr);
1113 for (int i = 0; i < len; i++) {
1114 ok = (wxIsspace (value_ptr[i]) != 0);
1115 if (!ok) return FALSE;
1116 }
e3a43801
JS
1117 }
1118 return ok;
1119}
1120
87138c52 1121bool wxPropertyValidator::StringToInt (wxChar *s, int *number) {
1e6feb95
VZ
1122 long num;
1123 bool ok = StringToLong (s, &num);
1124 *number = (int) num;
1125 return ok;
e3a43801
JS
1126}
1127
87138c52 1128bool wxPropertyValidator::StringToLong (wxChar *s, long *number) {
e3a43801 1129 bool ok = TRUE;
87138c52
OK
1130 wxChar *value_ptr;
1131 *number = wxStrtol (s, &value_ptr, 10);
e3a43801 1132 if (value_ptr) {
1e6feb95
VZ
1133 int len = wxStrlen (value_ptr);
1134 for (int i = 0; i < len; i++) {
1135 ok = (wxIsspace (value_ptr[i]) != 0);
1136 if (!ok) return FALSE;
1137 }
e3a43801
JS
1138 }
1139 return ok;
1140}
1141
87138c52 1142wxChar *wxPropertyValidator::FloatToString (float number) {
1e6feb95 1143 static wxChar buf[20];
9ac71bef 1144 wxSnprintf (buf, 20, wxT("%.6g"), number);
1e6feb95 1145 return buf;
e3a43801
JS
1146}
1147
87138c52 1148wxChar *wxPropertyValidator::DoubleToString (double number) {
1e6feb95 1149 static wxChar buf[20];
9ac71bef 1150 wxSnprintf (buf, 20, wxT("%.6g"), number);
1e6feb95 1151 return buf;
e3a43801
JS
1152}
1153
87138c52 1154wxChar *wxPropertyValidator::IntToString (int number) {
1e6feb95 1155 return ::IntToString (number);
e3a43801
JS
1156}
1157
87138c52 1158wxChar *wxPropertyValidator::LongToString (long number) {
1e6feb95 1159 return ::LongToString (number);
e3a43801 1160 }
1e6feb95
VZ
1161
1162#endif // wxUSE_PROPSHEET