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