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