]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/winprop.cpp
Added sys/types.h needed for Solaris.
[wxWidgets.git] / utils / dialoged / src / winprop.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: winprop.cpp
3 // Purpose: Window properties
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "winprop.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
27 #include <ctype.h>
28 #include <stdlib.h>
29 #include <math.h>
30 #include <string.h>
31
32 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
33 #include <strstrea.h>
34 #else
35 #include <strstream.h>
36 #endif
37
38 #ifdef __WXMSW__
39 #include <windows.h>
40 #endif
41
42 #include "reseditr.h"
43 #include "winprop.h"
44
45 // Causes immediate feedback.
46 void wxResourcePropertyListView::OnPropertyChanged(wxProperty *property)
47 {
48 // Sets the value of the property back into the actual object,
49 // IF the property value was modified.
50 if (property->GetValue().GetModified())
51 {
52 propertyInfo->SetProperty(property->GetName(), property);
53 property->GetValue().SetModified(FALSE);
54 }
55 }
56
57 bool wxResourcePropertyListView::OnClose(void)
58 {
59 int w, h, x, y;
60 GetManagedWindow()->GetSize(& w, & h);
61 GetManagedWindow()->GetPosition(& x, & y);
62
63 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width = w;
64 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height = h;
65 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x = x;
66 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y = y;
67
68 return wxPropertyListView::OnClose();
69 }
70
71 wxWindow *wxPropertyInfo::sm_propertyWindow;
72
73 /*
74 * wxDialogEditorPropertyListDialog
75 */
76
77 /*
78 wxDialogEditorPropertyListDialog::wxDialogEditorPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title,
79 const wxPoint& pos, const wxSize& size,
80 long style, const wxString& name):
81 wxPropertyListDialog(v, parent, title, pos, size, style, name)
82 {
83 m_propSheet = NULL;
84 m_propInfo = NULL;
85 }
86
87 wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog()
88 {
89 delete m_propSheet;
90 delete m_propInfo;
91 wxPropertyInfo::sm_propertyWindow = NULL;
92 }
93 */
94
95 wxDialogEditorPropertyListFrame::wxDialogEditorPropertyListFrame(wxPropertyListView *v, wxFrame *parent, const wxString& title,
96 const wxPoint& pos, const wxSize& size,
97 long style, const wxString& name):
98 wxPropertyListFrame(v, parent, title, pos, size, style, name)
99 {
100 m_propSheet = NULL;
101 m_propInfo = NULL;
102 }
103
104 wxDialogEditorPropertyListFrame::~wxDialogEditorPropertyListFrame()
105 {
106 delete m_propSheet;
107 delete m_propInfo;
108 wxPropertyInfo::sm_propertyWindow = NULL;
109 }
110
111 /*
112 * wxPropertyInfo
113 */
114
115 // Edit the information represented by this object, whatever that
116 // might be.
117 bool wxPropertyInfo::Edit(wxWindow *parent, const wxString& title)
118 {
119 if (sm_propertyWindow)
120 return FALSE;
121
122 int width = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width;
123 int height = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height;
124 int x = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x;
125 int y = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y;
126
127 wxPropertySheet *propSheet = new wxPropertySheet;
128
129 wxStringList propNames;
130 GetPropertyNames(propNames);
131
132 wxNode *node = propNames.First();
133 while (node)
134 {
135 wxString name((char *)node->Data());
136 wxProperty *prop = GetProperty(name);
137 if (prop)
138 {
139 propSheet->AddProperty(prop);
140 }
141 node = node->Next();
142 }
143
144 // Reset 'modified' flags for all property values
145 propSheet->SetAllModified(FALSE);
146
147 wxResourcePropertyListView *view = new wxResourcePropertyListView(this, NULL,
148 wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL |
149 wxPROP_BUTTON_CHECK_CROSS|wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES);
150
151 wxDialogEditorPropertyListFrame *propWin = new wxDialogEditorPropertyListFrame(view,
152 wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title, wxPoint(x, y),
153 wxSize(width, height), wxDEFAULT_FRAME_STYLE);
154 sm_propertyWindow = propWin;
155
156 propWin->m_registry.RegisterValidator((wxString)"real", new wxRealListValidator);
157 propWin->m_registry.RegisterValidator((wxString)"string", new wxStringListValidator);
158 propWin->m_registry.RegisterValidator((wxString)"integer", new wxIntegerListValidator);
159 propWin->m_registry.RegisterValidator((wxString)"bool", new wxBoolListValidator);
160 propWin->m_registry.RegisterValidator((wxString)"filename", new wxFilenameListValidator);
161 propWin->m_registry.RegisterValidator((wxString)"stringlist", new wxListOfStringsListValidator);
162 propWin->m_registry.RegisterValidator((wxString)"window_id", new wxResourceSymbolValidator);
163
164 propWin->m_propInfo = this;
165 propWin->m_propSheet = propSheet;
166
167 // view->propertyWindow = propWin;
168 view->AddRegistry(&(propWin->m_registry));
169
170 propWin->Initialize();
171 view->ShowView(propSheet, propWin->GetPropertyPanel());
172
173 propWin->Show(TRUE);
174 return TRUE;
175 }
176
177 /*
178 * wxWindowPropertyInfo
179 */
180
181 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow *win, wxItemResource *res)
182 {
183 propertyWindow = win;
184 propertyResource = res;
185 }
186
187 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
188 {
189 }
190
191 wxProperty *wxWindowPropertyInfo::GetFontProperty(wxString& name, wxFont *font)
192 {
193 if (!font)
194 return NULL;
195
196 if (name.Contains("Points"))
197 return new wxProperty(name, (long)font->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
198 else if (name.Contains("Family"))
199 return new wxProperty(name, font->GetFamilyString(), "string",
200 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
201 NULL)));
202 else if (name.Contains("Style"))
203 return new wxProperty(name, font->GetStyleString(), "string",
204 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL)));
205 else if (name.Contains("Weight"))
206 return new wxProperty(name, font->GetWeightString(), "string",
207 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL)));
208 else if (name.Contains("Underlined"))
209 return new wxProperty(name, (bool)font->GetUnderlined(), "bool");
210 else
211 return NULL;
212 }
213
214 wxFont *wxWindowPropertyInfo::SetFontProperty(wxString& name, wxProperty *property, wxFont *font)
215 {
216 int pointSize = 12;
217 int fontFamily = wxMODERN;
218 int fontStyle = wxNORMAL;
219 int fontWeight = wxNORMAL;
220 bool fontUnderlined = FALSE;
221
222 if (name.Contains("Points"))
223 {
224 pointSize = (int)property->GetValue().IntegerValue();
225 if (font && (pointSize == font->GetPointSize()))
226 return NULL; // No change
227 }
228 else if (font) pointSize = font->GetPointSize();
229
230 if (name.Contains("Family"))
231 {
232 wxString val = property->GetValue().StringValue();
233 fontFamily = wxStringToFontFamily(val);
234
235 if (font && (fontFamily == font->GetFamily()))
236 return NULL; // No change
237 }
238 else if (font) fontFamily = font->GetFamily();
239
240 if (name.Contains("Style"))
241 {
242 wxString val = property->GetValue().StringValue();
243 fontStyle = wxStringToFontStyle(val);
244
245 if (font && (fontStyle == font->GetStyle()))
246 return NULL; // No change
247 }
248 else if (font) fontStyle = font->GetStyle();
249 if (name.Contains("Weight"))
250 {
251 wxString val = property->GetValue().StringValue();
252 fontWeight = wxStringToFontWeight(val);
253
254 if (font && (fontWeight == font->GetWeight()))
255 return NULL; // No change
256 }
257 else if (font) fontWeight = font->GetWeight();
258
259 if (name.Contains("Underlined"))
260 {
261 fontUnderlined = property->GetValue().BoolValue();
262
263 if (font && (fontUnderlined == font->GetUnderlined()))
264 return NULL; // No change
265 }
266 else if (font) fontUnderlined = font->GetUnderlined();
267
268 wxFont *newFont = wxTheFontList->FindOrCreateFont(pointSize, fontFamily, fontStyle, fontWeight, fontUnderlined);
269 if (newFont)
270 {
271 return newFont;
272 }
273 else
274 return NULL;
275 }
276
277 wxProperty *wxWindowPropertyInfo::GetProperty(wxString& name)
278 {
279 wxFont *font = propertyWindow->GetFont();
280 if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" ||
281 name == "fontUnderlined")
282 return GetFontProperty(name, font);
283 else if (name == "name")
284 return new wxProperty("name", propertyWindow->GetName(), "string");
285 else if (name == "title")
286 return new wxProperty("title", propertyWindow->GetTitle(), "string");
287 else if (name == "x")
288 {
289 int x, y;
290 propertyWindow->GetPosition(&x, &y);
291 return new wxProperty("x", (long)x, "integer");
292 }
293 else if (name == "y")
294 {
295 int x, y;
296 propertyWindow->GetPosition(&x, &y);
297 return new wxProperty("y", (long)y, "integer");
298 }
299 else if (name == "width")
300 {
301 int width, height;
302 propertyWindow->GetSize(&width, &height);
303 return new wxProperty("width", (long)width, "integer");
304 }
305 else if (name == "height")
306 {
307 int width, height;
308 propertyWindow->GetSize(&width, &height);
309 return new wxProperty("height", (long)height, "integer");
310 }
311 else if (name == "id")
312 {
313 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
314 if (resource)
315 {
316 int id = resource->GetId();
317 wxString idStr;
318 idStr.Printf("%d", id);
319 wxString symbolName = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id);
320 symbolName += "=";
321 symbolName += idStr;
322 // symbolName is now e.g. "ID_PANEL21=105"
323 return new wxProperty("id", symbolName, "window_id");
324 }
325 else
326 return NULL;
327 }
328 else
329 return NULL;
330 }
331
332 bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property)
333 {
334 wxFont *font = propertyWindow->GetFont();
335 if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ))
336 {
337 wxFont *newFont = SetFontProperty(name, property, font);
338 if (newFont)
339 propertyWindow->SetFont(newFont);
340 return TRUE;
341 }
342 else if (name == "name")
343 {
344 // Remove old name from resource table, if it's there.
345 wxItemResource *oldResource = (wxItemResource *)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(propertyWindow->GetName());
346 if (oldResource)
347 {
348 // It's a top-level resource
349 propertyWindow->SetName(property->GetValue().StringValue());
350 oldResource->SetName(property->GetValue().StringValue());
351 wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(propertyWindow->GetName(), oldResource);
352 }
353 else
354 {
355 // It's a child of something; just set the name of the resource and the window.
356 propertyWindow->SetName(property->GetValue().StringValue());
357 propertyResource->SetName(property->GetValue().StringValue());
358 }
359 // Refresh the resource manager list, because the name changed.
360 wxResourceManager::GetCurrentResourceManager()->UpdateResourceList();
361 return TRUE;
362 }
363 else if (name == "title")
364 {
365 propertyWindow->SetTitle(property->GetValue().StringValue());
366 return TRUE;
367 }
368 else if (name == "x")
369 {
370 int x, y;
371 propertyWindow->GetPosition(&x, &y);
372 int newX = (int)property->GetValue().IntegerValue();
373 if (x != newX)
374 propertyWindow->Move(newX, y);
375 return TRUE;
376 }
377 else if (name == "y")
378 {
379 int x, y;
380 propertyWindow->GetPosition(&x, &y);
381 int newY = (int)property->GetValue().IntegerValue();
382 if (y != newY)
383 propertyWindow->Move(x, newY);
384 return TRUE;
385 }
386 else if (name == "width")
387 {
388 int width, height;
389 propertyWindow->GetSize(&width, &height);
390 int newWidth = (int)property->GetValue().IntegerValue();
391 if (width != newWidth)
392 {
393 propertyWindow->SetSize(newWidth, height);
394 /*
395 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
396 {
397 propertyWindow->GetParent()->SetClientSize(newWidth, height);
398 }
399 */
400 }
401 return TRUE;
402 }
403 else if (name == "height")
404 {
405 int width, height;
406 propertyWindow->GetSize(&width, &height);
407 int newHeight = (int)property->GetValue().IntegerValue();
408 if (height != newHeight)
409 {
410 propertyWindow->SetSize(width, newHeight);
411 /*
412 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
413 {
414 propertyWindow->GetParent()->SetClientSize(width, newHeight);
415 }
416 */
417 }
418 return TRUE;
419 }
420 else if (name == "id")
421 {
422 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
423 if (resource)
424 {
425 wxString value = property->GetValue().StringValue();
426
427 wxString strName = value.Before('=');
428 wxString strId = value.After('=');
429 int id = atoi(strId);
430
431 wxString oldSymbolName = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource->GetId());
432 int oldSymbolId = resource->GetId();
433
434 if (strName != "")
435 {
436 // If we change the id for an existing symbol, we need to:
437 // 1) Check if there are any other resources currently using the original id.
438 // If so, will need to change their id to the new id.
439 // 2) Remove the old symbol, add the new symbol.
440 // In this check, we don't have to do this, but we need to do it in SetProperty.
441
442 if (strName == oldSymbolName && id != oldSymbolId)
443 {
444 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) );
445
446 // It's OK to change just the id. But we'll need to change all matching ids in all resources,
447 // because ids are unique and changing one resource's id must change all identical ones.
448 wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId, id);
449
450 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
451 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
452 }
453
454 // If we change the name but not the id, we'll just need to remove and
455 // re-add the symbol/id pair.
456 if (strName != oldSymbolName && id == oldSymbolId)
457 {
458 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) );
459
460 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
461
462 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName))
463 {
464 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
465 }
466 }
467
468 // What if we're changing both the name and the id?
469 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
470 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
471
472 if (strName != oldSymbolName && id != oldSymbolId)
473 {
474 // Remove old symbol if it's not being used
475 if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource, oldSymbolId) &&
476 !wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName))
477 {
478 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
479 }
480
481 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName))
482 {
483 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
484 }
485 }
486 resource->SetId(id);
487 }
488
489 return TRUE;
490 }
491 else
492 return FALSE;
493 }
494 else
495 return FALSE;
496 }
497
498 void wxWindowPropertyInfo::GetPropertyNames(wxStringList& names)
499 {
500 names.Add("id");
501 names.Add("name");
502 names.Add("x");
503 names.Add("y");
504 names.Add("width");
505 names.Add("height");
506 if (!propertyWindow->IsKindOf(CLASSINFO(wxControl)))
507 {
508 names.Add("fontPoints");
509 names.Add("fontFamily");
510 names.Add("fontStyle");
511 names.Add("fontWeight");
512 names.Add("fontUnderlined");
513 }
514 }
515
516 // Fill in the wxItemResource members to mirror the current window settings
517 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource *resource)
518 {
519 // resource->SetType(propertyWindow->GetClassInfo()->GetClassName());
520
521 // resource->SetStyle(propertyWindow->GetWindowStyleFlag());
522 wxString str(propertyWindow->GetName());
523 resource->SetName(WXSTRINGCAST str);
524 int x, y, w, h;
525 propertyWindow->GetSize(&w, &h);
526
527 propertyWindow->GetPosition(&x, &y);
528 resource->SetSize(x, y, w, h);
529 return TRUE;
530 }
531
532 // Set the window style
533 void wxWindowPropertyInfo::SetWindowStyle(wxWindow* win, long style, bool set)
534 {
535 if (style == 0)
536 return;
537
538 if ((win->GetWindowStyleFlag() & style) == style)
539 {
540 if (!set)
541 {
542 win->SetWindowStyleFlag(win->GetWindowStyleFlag() - style);
543 }
544 }
545 else
546 {
547 if (set)
548 {
549 win->SetWindowStyleFlag(win->GetWindowStyleFlag() | style);
550 }
551 }
552 }
553
554 /*
555 * Controls
556 */
557
558 wxProperty *wxItemPropertyInfo::GetProperty(wxString& name)
559 {
560 wxControl *itemWindow = (wxControl *)propertyWindow;
561 wxFont *font = itemWindow->GetFont();
562
563 if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" ||
564 name == "fontUnderlined")
565 return GetFontProperty(name, font);
566 else if (name == "label" && itemWindow->GetLabel())
567 return new wxProperty("label", propertyWindow->GetLabel(), "string");
568 else
569 return wxWindowPropertyInfo::GetProperty(name);
570 }
571
572 bool wxItemPropertyInfo::SetProperty(wxString& name, wxProperty *property)
573 {
574 wxControl *itemWindow = (wxControl *)propertyWindow;
575 wxFont *font = itemWindow->GetFont();
576
577 if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ))
578 {
579 wxFont *newFont = SetFontProperty(name, property, font);
580 if (newFont)
581 itemWindow->SetLabelFont(newFont);
582 return TRUE;
583 }
584 else if (name == "label")
585 {
586 itemWindow->SetLabel(property->GetValue().StringValue());
587 return TRUE;
588 }
589 else
590 return wxWindowPropertyInfo::SetProperty(name, property);
591 }
592
593 void wxItemPropertyInfo::GetPropertyNames(wxStringList& names)
594 {
595 wxWindowPropertyInfo::GetPropertyNames(names);
596
597 names.Add("fontPoints");
598 names.Add("fontFamily");
599 names.Add("fontStyle");
600 names.Add("fontWeight");
601 names.Add("fontUnderlined");
602 }
603
604 bool wxItemPropertyInfo::InstantiateResource(wxItemResource *resource)
605 {
606 wxWindowPropertyInfo::InstantiateResource(resource);
607
608 wxControl *item = (wxControl *)propertyWindow;
609 wxString str(item->GetLabel());
610 resource->SetTitle(WXSTRINGCAST str);
611 if (item->GetFont() && item->GetFont()->Ok())
612 resource->SetFont(wxTheFontList->FindOrCreateFont(item->GetFont()->GetPointSize(),
613 item->GetFont()->GetFamily(), item->GetFont()->GetStyle(), item->GetFont()->GetWeight(),
614 item->GetFont()->GetUnderlined(), item->GetFont()->GetFaceName()));
615 return TRUE;
616 }
617
618 /*
619 * Button
620 */
621
622 wxProperty *wxButtonPropertyInfo::GetProperty(wxString& name)
623 {
624 wxButton *button = (wxButton *)propertyWindow;
625 return wxItemPropertyInfo::GetProperty(name);
626 }
627
628 bool wxButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
629 {
630 wxButton *button = (wxButton *)propertyWindow;
631 return wxItemPropertyInfo::SetProperty(name, property);
632 }
633
634 void wxButtonPropertyInfo::GetPropertyNames(wxStringList& names)
635 {
636 wxItemPropertyInfo::GetPropertyNames(names);
637 names.Add("label");
638 }
639
640 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
641 {
642 return wxItemPropertyInfo::InstantiateResource(resource);
643 }
644
645 /*
646 * wxBitmapButton
647 */
648
649 wxProperty *wxBitmapButtonPropertyInfo::GetProperty(wxString& name)
650 {
651 wxBitmapButton *button = (wxBitmapButton *)propertyWindow;
652 if (name == "label")
653 {
654 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button);
655 wxString str("none.bmp");
656
657 if (resource)
658 {
659 char *filename = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource);
660 if (filename)
661 str = filename;
662 }
663 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
664 }
665 else
666 return wxButtonPropertyInfo::GetProperty(name);
667 }
668
669 bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
670 {
671 wxBitmapButton *button = (wxBitmapButton *)propertyWindow;
672 if (name == "label")
673 {
674 char *s = property->GetValue().StringValue();
675 if (s && wxFileExists(s))
676 {
677 s = copystring(s);
678 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
679 if (!bitmap->Ok())
680 {
681 delete bitmap;
682 delete[] s;
683 return FALSE;
684 }
685 else
686 {
687 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button);
688 if (resource)
689 {
690 wxString oldResource(resource->GetValue4());
691 char *resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s);
692 resource->SetValue4(resName);
693
694 if (!oldResource.IsNull())
695 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
696 }
697
698 button->SetLabel(bitmap);
699 delete[] s;
700 return TRUE;
701 }
702 }
703 return FALSE;
704 }
705 else
706 return wxButtonPropertyInfo::SetProperty(name, property);
707 }
708
709 void wxBitmapButtonPropertyInfo::GetPropertyNames(wxStringList& names)
710 {
711 // names.Add("label");
712 wxButtonPropertyInfo::GetPropertyNames(names);
713 }
714
715 bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
716 {
717 return wxItemPropertyInfo::InstantiateResource(resource);
718 }
719
720 /*
721 * wxStaticText
722 */
723
724 wxProperty *wxStaticTextPropertyInfo::GetProperty(wxString& name)
725 {
726 wxStaticText *message = (wxStaticText *)propertyWindow;
727 return wxItemPropertyInfo::GetProperty(name);
728 }
729
730 bool wxStaticTextPropertyInfo::SetProperty(wxString& name, wxProperty *property)
731 {
732 wxStaticText *message = (wxStaticText *)propertyWindow;
733 return wxItemPropertyInfo::SetProperty(name, property);
734 }
735
736 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList& names)
737 {
738 wxItemPropertyInfo::GetPropertyNames(names);
739 names.Add("label");
740 }
741
742 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource *resource)
743 {
744 return wxItemPropertyInfo::InstantiateResource(resource);
745 }
746
747 /*
748 * wxStaticBitmap
749 */
750
751 wxProperty *wxStaticBitmapPropertyInfo::GetProperty(wxString& name)
752 {
753 wxStaticBitmap *message = (wxStaticBitmap *)propertyWindow;
754 if (name == "label")
755 {
756 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message);
757 wxString str("none.bmp");
758
759 if (resource)
760 {
761 char *filename = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource);
762 if (filename)
763 str = filename;
764 }
765 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
766 }
767 else
768 return wxItemPropertyInfo::GetProperty(name);
769 }
770
771 bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *property)
772 {
773 wxStaticBitmap *message = (wxStaticBitmap *)propertyWindow;
774 if (name == "label")
775 {
776 char *s = property->GetValue().StringValue();
777 if (s && wxFileExists(s))
778 {
779 s = copystring(s);
780
781 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
782 if (!bitmap->Ok())
783 {
784 delete bitmap;
785 delete[] s;
786 return FALSE;
787 }
788 else
789 {
790 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message);
791 if (resource)
792 {
793 wxString oldResource(resource->GetValue4());
794 char *resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s);
795 resource->SetValue4(resName);
796
797 if (!oldResource.IsNull())
798 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
799 }
800
801 message->SetBitmap(bitmap);
802 delete[] s;
803 return TRUE;
804 }
805 }
806 return FALSE;
807 }
808 else
809 return wxItemPropertyInfo::SetProperty(name, property);
810 }
811
812 void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList& names)
813 {
814 wxItemPropertyInfo::GetPropertyNames(names);
815 names.Add("label");
816 }
817
818 bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource *resource)
819 {
820 return wxItemPropertyInfo::InstantiateResource(resource);
821 }
822
823 /*
824 * Text item
825 */
826
827 wxProperty *wxTextPropertyInfo::GetProperty(wxString& name)
828 {
829 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
830 if (name == "value")
831 return new wxProperty("value", text->GetValue(), "string");
832 else if (name == "password")
833 {
834 bool isPassword = ((text->GetWindowStyleFlag() & wxTE_PASSWORD) == wxTE_PASSWORD);
835 return new wxProperty("password", isPassword, "bool");
836 }
837 else if (name == "readonly")
838 {
839 bool isReadOnly = ((text->GetWindowStyleFlag() & wxTE_READONLY) == wxTE_READONLY);
840 return new wxProperty("readonly", isReadOnly, "bool");
841 }
842 else
843 return wxItemPropertyInfo::GetProperty(name);
844 }
845
846 bool wxTextPropertyInfo::SetProperty(wxString& name, wxProperty *property)
847 {
848 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
849 if (name == "value")
850 {
851 text->SetValue(property->GetValue().StringValue());
852 return TRUE;
853 }
854 else if (name == "password")
855 {
856 long flag = text->GetWindowStyleFlag();
857 if (property->GetValue().BoolValue())
858 {
859 if ((flag & wxTE_PASSWORD) != wxTE_PASSWORD)
860 flag |= wxTE_PASSWORD;
861 }
862 else
863 {
864 if ((flag & wxTE_PASSWORD) == wxTE_PASSWORD)
865 flag -= wxTE_PASSWORD;
866 }
867 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text);
868 resource->SetStyle(flag);
869
870 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this);
871 return TRUE;
872 }
873 else if (name == "readonly")
874 {
875 long flag = text->GetWindowStyleFlag();
876 if (property->GetValue().BoolValue())
877 {
878 if ((flag & wxTE_READONLY) != wxTE_READONLY)
879 flag |= wxTE_READONLY;
880 }
881 else
882 {
883 if ((flag & wxTE_READONLY) == wxTE_READONLY)
884 flag -= wxTE_READONLY;
885 }
886 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text);
887 resource->SetStyle(flag);
888
889 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this);
890 return TRUE;
891 }
892 else
893 return wxItemPropertyInfo::SetProperty(name, property);
894 }
895
896 void wxTextPropertyInfo::GetPropertyNames(wxStringList& names)
897 {
898 wxItemPropertyInfo::GetPropertyNames(names);
899 names.Add("value");
900 names.Add("readonly");
901 names.Add("password");
902 }
903
904 bool wxTextPropertyInfo::InstantiateResource(wxItemResource *resource)
905 {
906 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
907 wxString str(text->GetValue());
908 resource->SetValue4(WXSTRINGCAST str);
909
910 return wxItemPropertyInfo::InstantiateResource(resource);
911 }
912
913 /*
914 * Listbox item
915 */
916
917 wxProperty *wxListBoxPropertyInfo::GetProperty(wxString& name)
918 {
919 wxListBox *listBox = (wxListBox *)propertyWindow;
920 if (name == "values")
921 {
922 wxStringList *stringList = new wxStringList;
923 int i;
924 for (i = 0; i < listBox->Number(); i++)
925 stringList->Add(listBox->GetString(i));
926
927 return new wxProperty(name, stringList, "stringlist");
928 }
929 else if (name == "multiple")
930 {
931 char *pos = NULL;
932 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox);
933 if (!resource)
934 return NULL;
935
936 char *mult = "wxSINGLE";
937
938 switch (resource->GetValue1())
939 {
940 case wxLB_MULTIPLE:
941 mult = "wxLB_MULTIPLE";
942 break;
943 case wxLB_EXTENDED:
944 mult = "wxLB_EXTENDED";
945 break;
946 default:
947 case wxLB_SINGLE:
948 mult = "wxLB_SINGLE";
949 break;
950 }
951 return new wxProperty("multiple", mult, "string",
952 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
953 NULL)));
954 }
955 else
956 return wxItemPropertyInfo::GetProperty(name);
957 }
958
959 bool wxListBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
960 {
961 wxListBox *listBox = (wxListBox *)propertyWindow;
962 if (name == "values")
963 {
964 listBox->Clear();
965 wxPropertyValue *expr = property->GetValue().GetFirst();
966 while (expr)
967 {
968 char *s = expr->StringValue();
969 if (s)
970 listBox->Append(s);
971 expr = expr->GetNext();
972 }
973 return TRUE;
974 }
975 else if (name == "multiple")
976 {
977 int mult = wxLB_SINGLE;
978 wxString str(property->GetValue().StringValue());
979 if (str == "wxLB_MULTIPLE")
980 mult = wxLB_MULTIPLE;
981 else if (str == "wxLB_EXTENDED")
982 mult = wxLB_EXTENDED;
983 else
984 mult = wxLB_SINGLE;
985 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox);
986 if (resource)
987 resource->SetValue1(mult);
988 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox, this);
989 return TRUE;
990 }
991 else
992 return wxItemPropertyInfo::SetProperty(name, property);
993 }
994
995 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList& names)
996 {
997 wxItemPropertyInfo::GetPropertyNames(names);
998 names.Add("values");
999 names.Add("multiple");
1000 }
1001
1002 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1003 {
1004 wxListBox *lbox = (wxListBox *)propertyWindow;
1005 // This will be set for the wxItemResource on reading or in SetProperty
1006 // resource->SetValue1(lbox->GetSelectionMode());
1007 int i;
1008 if (lbox->Number() == 0)
1009 resource->SetStringValues(NULL);
1010 else
1011 {
1012 wxStringList *slist = new wxStringList;
1013
1014 for (i = 0; i < lbox->Number(); i++)
1015 slist->Add(lbox->GetString(i));
1016
1017 resource->SetStringValues(slist);
1018 }
1019 return wxItemPropertyInfo::InstantiateResource(resource);
1020 }
1021
1022 /*
1023 * Choice item
1024 */
1025
1026 wxProperty *wxChoicePropertyInfo::GetProperty(wxString& name)
1027 {
1028 wxChoice *choice = (wxChoice *)propertyWindow;
1029 if (name == "values")
1030 {
1031 wxStringList *stringList = new wxStringList;
1032 int i;
1033 for (i = 0; i < choice->Number(); i++)
1034 stringList->Add(choice->GetString(i));
1035
1036 return new wxProperty(name, stringList, "stringlist");
1037 }
1038 else
1039 return wxItemPropertyInfo::GetProperty(name);
1040 }
1041
1042 bool wxChoicePropertyInfo::SetProperty(wxString& name, wxProperty *property)
1043 {
1044 wxChoice *choice = (wxChoice *)propertyWindow;
1045 if (name == "values")
1046 {
1047 choice->Clear();
1048 wxPropertyValue *expr = property->GetValue().GetFirst();
1049 while (expr)
1050 {
1051 char *s = expr->StringValue();
1052 if (s)
1053 choice->Append(s);
1054 expr = expr->GetNext();
1055 }
1056 if (choice->Number() > 0)
1057 choice->SetSelection(0);
1058 return TRUE;
1059 }
1060 else
1061 return wxItemPropertyInfo::SetProperty(name, property);
1062 }
1063
1064 void wxChoicePropertyInfo::GetPropertyNames(wxStringList& names)
1065 {
1066 wxItemPropertyInfo::GetPropertyNames(names);
1067 names.Add("values");
1068 }
1069
1070 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource *resource)
1071 {
1072 wxChoice *choice = (wxChoice *)propertyWindow;
1073 int i;
1074 if (choice->Number() == 0)
1075 resource->SetStringValues(NULL);
1076 else
1077 {
1078 wxStringList *slist = new wxStringList;
1079
1080 for (i = 0; i < choice->Number(); i++)
1081 slist->Add(choice->GetString(i));
1082
1083 resource->SetStringValues(slist);
1084 }
1085 return wxItemPropertyInfo::InstantiateResource(resource);
1086 }
1087
1088 /*
1089 * Choice item
1090 */
1091
1092 wxProperty *wxComboBoxPropertyInfo::GetProperty(wxString& name)
1093 {
1094 wxComboBox *choice = (wxComboBox *)propertyWindow;
1095 if (name == "values")
1096 {
1097 wxStringList *stringList = new wxStringList;
1098 int i;
1099 for (i = 0; i < choice->Number(); i++)
1100 stringList->Add(choice->GetString(i));
1101
1102 return new wxProperty(name, stringList, "stringlist");
1103 }
1104 else if (name == "sort")
1105 {
1106 bool sort = ((propertyWindow->GetWindowStyleFlag() & wxCB_SORT) == wxCB_SORT);
1107 return new wxProperty(name, sort, "bool");
1108 }
1109 else if (name == "style")
1110 {
1111 wxString styleStr("dropdown");
1112 if (propertyWindow->GetWindowStyleFlag() & wxCB_SIMPLE)
1113 styleStr = "simple";
1114 else if (propertyWindow->GetWindowStyleFlag() & wxCB_READONLY)
1115 styleStr = "readonly";
1116 else
1117 styleStr = "dropdown";
1118
1119 return new wxProperty(name, styleStr, "string",
1120 new wxStringListValidator(new wxStringList("simple", "dropdown", "readonly",
1121 NULL)));
1122 }
1123 else
1124 return wxItemPropertyInfo::GetProperty(name);
1125 }
1126
1127 bool wxComboBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1128 {
1129 wxComboBox *choice = (wxComboBox *)propertyWindow;
1130 if (name == "values")
1131 {
1132 choice->Clear();
1133 wxPropertyValue *expr = property->GetValue().GetFirst();
1134 while (expr)
1135 {
1136 char *s = expr->StringValue();
1137 if (s)
1138 choice->Append(s);
1139 expr = expr->GetNext();
1140 }
1141 if (choice->Number() > 0)
1142 choice->SetSelection(0);
1143 return TRUE;
1144 }
1145 else if (name == "sort")
1146 {
1147 SetWindowStyle(propertyWindow, wxCB_SORT, property->GetValue().BoolValue());
1148
1149 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
1150 resource->SetStyle(propertyWindow->GetWindowStyleFlag());
1151
1152 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(propertyWindow, this);
1153 return TRUE;
1154 }
1155 else if (name == "style")
1156 {
1157 SetWindowStyle(propertyWindow, wxCB_SIMPLE, FALSE);
1158 SetWindowStyle(propertyWindow, wxCB_DROPDOWN, FALSE);
1159 SetWindowStyle(propertyWindow, wxCB_READONLY, FALSE);
1160
1161 wxString styleStr(property->GetValue().StringValue());
1162 if (styleStr == "simple")
1163 SetWindowStyle(propertyWindow, wxCB_SIMPLE, TRUE);
1164 else if (styleStr == "dropdown")
1165 SetWindowStyle(propertyWindow, wxCB_DROPDOWN, TRUE);
1166 else if (styleStr == "readonly")
1167 SetWindowStyle(propertyWindow, wxCB_READONLY, TRUE);
1168
1169 // Necesary?
1170 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
1171 resource->SetStyle(propertyWindow->GetWindowStyleFlag());
1172
1173 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(propertyWindow, this);
1174
1175 return TRUE;
1176 }
1177 else
1178 return wxItemPropertyInfo::SetProperty(name, property);
1179 }
1180
1181 void wxComboBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1182 {
1183 wxItemPropertyInfo::GetPropertyNames(names);
1184 names.Add("values");
1185 names.Add("style");
1186 names.Add("sort");
1187 }
1188
1189 bool wxComboBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1190 {
1191 wxComboBox *choice = (wxComboBox *)propertyWindow;
1192 int i;
1193 if (choice->Number() == 0)
1194 resource->SetStringValues(NULL);
1195 else
1196 {
1197 wxStringList *slist = new wxStringList;
1198
1199 for (i = 0; i < choice->Number(); i++)
1200 slist->Add(choice->GetString(i));
1201
1202 resource->SetStringValues(slist);
1203 }
1204 return wxItemPropertyInfo::InstantiateResource(resource);
1205 }
1206
1207 /*
1208 * Radiobox item
1209 */
1210
1211 wxProperty *wxRadioBoxPropertyInfo::GetProperty(wxString& name)
1212 {
1213 wxRadioBox *radioBox = (wxRadioBox *)propertyWindow;
1214 if (name == "numberRowsOrCols")
1215 {
1216 return new wxProperty("numberRowsOrCols", (long)radioBox->GetNumberOfRowsOrCols(), "integer");
1217 }
1218 if (name == "orientation")
1219 {
1220 char *pos = NULL;
1221 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1222 pos = "wxHORIZONTAL";
1223 else
1224 pos = "wxVERTICAL";
1225
1226 return new wxProperty("orientation", pos, "string",
1227 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1228 NULL)));
1229 }
1230 else if (name == "values")
1231 {
1232 wxStringList *stringList = new wxStringList;
1233 int i;
1234 for (i = 0; i < radioBox->Number(); i++)
1235 stringList->Add(radioBox->GetString(i));
1236
1237 return new wxProperty(name, stringList, "stringlist");
1238 }
1239 return wxItemPropertyInfo::GetProperty(name);
1240 }
1241
1242 bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1243 {
1244 wxRadioBox *radioBox = (wxRadioBox *)propertyWindow;
1245 if (name == "numberRowsOrCols")
1246 {
1247 radioBox->SetNumberOfRowsOrCols((int)property->GetValue().IntegerValue());
1248 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
1249 return TRUE;
1250 }
1251 else if (name == "orientation")
1252 {
1253 long windowStyle = radioBox->GetWindowStyleFlag();
1254 wxString val(property->GetValue().StringValue());
1255 if (val == "wxHORIZONTAL")
1256 {
1257 if (windowStyle & wxVERTICAL)
1258 windowStyle -= wxVERTICAL;
1259 windowStyle |= wxHORIZONTAL;
1260 }
1261 else
1262 {
1263 if (windowStyle & wxHORIZONTAL)
1264 windowStyle -= wxHORIZONTAL;
1265 windowStyle |= wxVERTICAL;
1266 }
1267 radioBox->SetWindowStyleFlag(windowStyle);
1268
1269 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
1270 return TRUE;
1271 }
1272 else if (name == "values")
1273 {
1274 // Set property into *resource*, not wxRadioBox, and then recreate
1275 // the wxRadioBox. This is because we can't dynamically set the strings
1276 // of a wxRadioBox.
1277 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
1278 if (!resource)
1279 return FALSE;
1280
1281 wxStringList *stringList = resource->GetStringValues();
1282 if (!stringList)
1283 {
1284 stringList = new wxStringList;
1285 resource->SetStringValues(stringList);
1286 }
1287 stringList->Clear();
1288
1289 wxPropertyValue *expr = property->GetValue().GetFirst();
1290 while (expr)
1291 {
1292 char *s = expr->StringValue();
1293 if (s)
1294 stringList->Add(s);
1295 expr = expr->GetNext();
1296 }
1297 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
1298 return TRUE;
1299 }
1300 return wxItemPropertyInfo::SetProperty(name, property);
1301 }
1302
1303 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1304 {
1305 wxItemPropertyInfo::GetPropertyNames(names);
1306 names.Add("label");
1307 names.Add("values");
1308 names.Add("orientation");
1309 names.Add("numberRowsOrCols");
1310 }
1311
1312 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1313 {
1314 wxRadioBox *rbox = (wxRadioBox *)propertyWindow;
1315 // Take strings from resource instead
1316 /*
1317 int i;
1318 if (rbox->Number() == 0)
1319 resource->SetStringValues(NULL);
1320 else
1321 {
1322 wxStringList *slist = new wxStringList;
1323
1324 for (i = 0; i < rbox->Number(); i++)
1325 slist->Add(rbox->GetString(i));
1326
1327 resource->SetStringValues(slist);
1328 }
1329 */
1330 resource->SetValue1(rbox->GetNumberOfRowsOrCols());
1331 return wxItemPropertyInfo::InstantiateResource(resource);
1332 }
1333
1334 /*
1335 * Groupbox item
1336 */
1337
1338 wxProperty *wxGroupBoxPropertyInfo::GetProperty(wxString& name)
1339 {
1340 wxStaticBox *groupBox = (wxStaticBox *)propertyWindow;
1341 return wxItemPropertyInfo::GetProperty(name);
1342 }
1343
1344 bool wxGroupBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1345 {
1346 return wxItemPropertyInfo::SetProperty(name, property);
1347 }
1348
1349 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1350 {
1351 wxItemPropertyInfo::GetPropertyNames(names);
1352 names.Add("label");
1353 }
1354
1355 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1356 {
1357 wxStaticBox *gbox = (wxStaticBox *)propertyWindow;
1358 return wxItemPropertyInfo::InstantiateResource(resource);
1359 }
1360
1361 /*
1362 * Checkbox item
1363 */
1364
1365 wxProperty *wxCheckBoxPropertyInfo::GetProperty(wxString& name)
1366 {
1367 wxCheckBox *checkBox = (wxCheckBox *)propertyWindow;
1368 if (name == "value")
1369 return new wxProperty("value", checkBox->GetValue(), "bool");
1370 else
1371 return wxItemPropertyInfo::GetProperty(name);
1372 }
1373
1374 bool wxCheckBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1375 {
1376 wxCheckBox *checkBox = (wxCheckBox *)propertyWindow;
1377 if (name == "value")
1378 {
1379 checkBox->SetValue((bool)property->GetValue().BoolValue());
1380 return TRUE;
1381 }
1382 else
1383 return wxItemPropertyInfo::SetProperty(name, property);
1384 }
1385
1386 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1387 {
1388 wxItemPropertyInfo::GetPropertyNames(names);
1389 names.Add("label");
1390 names.Add("value");
1391 }
1392
1393 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1394 {
1395 wxCheckBox *cbox = (wxCheckBox *)propertyWindow;
1396 resource->SetValue1(cbox->GetValue());
1397 return wxItemPropertyInfo::InstantiateResource(resource);
1398 }
1399
1400 /*
1401 * Radiobutton item
1402 */
1403
1404 wxProperty *wxRadioButtonPropertyInfo::GetProperty(wxString& name)
1405 {
1406 wxRadioButton *checkBox = (wxRadioButton *)propertyWindow;
1407 if (name == "value")
1408 return new wxProperty("value", checkBox->GetValue(), "bool");
1409 else
1410 return wxItemPropertyInfo::GetProperty(name);
1411 }
1412
1413 bool wxRadioButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1414 {
1415 wxRadioButton *checkBox = (wxRadioButton *)propertyWindow;
1416 if (name == "value")
1417 {
1418 checkBox->SetValue((bool)property->GetValue().BoolValue());
1419 return TRUE;
1420 }
1421 else
1422 return wxItemPropertyInfo::SetProperty(name, property);
1423 }
1424
1425 void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList& names)
1426 {
1427 wxItemPropertyInfo::GetPropertyNames(names);
1428 names.Add("label");
1429 names.Add("value");
1430 }
1431
1432 bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
1433 {
1434 wxRadioButton *cbox = (wxRadioButton *)propertyWindow;
1435 resource->SetValue1(cbox->GetValue());
1436 return wxItemPropertyInfo::InstantiateResource(resource);
1437 }
1438
1439 /*
1440 * Slider item
1441 */
1442
1443 wxProperty *wxSliderPropertyInfo::GetProperty(wxString& name)
1444 {
1445 wxSlider *slider = (wxSlider *)propertyWindow;
1446 if (name == "value")
1447 return new wxProperty("value", (long)slider->GetValue(), "integer");
1448 else if (name == "orientation")
1449 {
1450 char *pos = NULL;
1451 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1452 pos = "wxHORIZONTAL";
1453 else
1454 pos = "wxVERTICAL";
1455
1456 return new wxProperty("orientation", pos, "string",
1457 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1458 NULL)));
1459 }
1460 else if (name == "minValue")
1461 return new wxProperty("minValue", (long)slider->GetMin(), "integer");
1462 else if (name == "maxValue")
1463 return new wxProperty("maxValue", (long)slider->GetMax(), "integer");
1464 else
1465 return wxItemPropertyInfo::GetProperty(name);
1466 }
1467
1468 bool wxSliderPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1469 {
1470 wxSlider *slider = (wxSlider *)propertyWindow;
1471 if (name == "value")
1472 {
1473 slider->SetValue((int)property->GetValue().IntegerValue());
1474 return TRUE;
1475 }
1476 else if (name == "orientation")
1477 {
1478 long windowStyle = slider->GetWindowStyleFlag();
1479 long oldWindowStyle = windowStyle;
1480 wxString val(property->GetValue().StringValue());
1481 if (val == "wxHORIZONTAL")
1482 {
1483 if (windowStyle & wxVERTICAL)
1484 windowStyle -= wxVERTICAL;
1485 windowStyle |= wxHORIZONTAL;
1486 }
1487 else
1488 {
1489 if (windowStyle & wxHORIZONTAL)
1490 windowStyle -= wxHORIZONTAL;
1491 windowStyle |= wxVERTICAL;
1492 }
1493
1494 if (oldWindowStyle == windowStyle)
1495 return TRUE;
1496
1497 slider->SetWindowStyleFlag(windowStyle);
1498
1499 // If the window style has changed, we swap the width and height parameters.
1500 int w, h;
1501 slider->GetSize(&w, &h);
1502
1503 slider = (wxSlider *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider, this);
1504 slider->SetSize(-1, -1, h, w);
1505
1506 return TRUE;
1507 }
1508 else if (name == "minValue")
1509 {
1510 slider->SetRange((int)property->GetValue().IntegerValue(), slider->GetMax());
1511 return TRUE;
1512 }
1513 else if (name == "maxValue")
1514 {
1515 slider->SetRange(slider->GetMin(), (int)property->GetValue().IntegerValue());
1516 return TRUE;
1517 }
1518 else
1519 return wxItemPropertyInfo::SetProperty(name, property);
1520 }
1521
1522 void wxSliderPropertyInfo::GetPropertyNames(wxStringList& names)
1523 {
1524 wxItemPropertyInfo::GetPropertyNames(names);
1525 names.Add("value");
1526 names.Add("orientation");
1527 names.Add("minValue");
1528 names.Add("maxValue");
1529 }
1530
1531 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource *resource)
1532 {
1533 wxSlider *slider = (wxSlider *)propertyWindow;
1534 resource->SetValue1(slider->GetValue());
1535 resource->SetValue2(slider->GetMin());
1536 resource->SetValue3(slider->GetMax());
1537 return wxItemPropertyInfo::InstantiateResource(resource);
1538 }
1539
1540 /*
1541 * Gauge item
1542 */
1543
1544 wxProperty *wxGaugePropertyInfo::GetProperty(wxString& name)
1545 {
1546 wxGauge *gauge = (wxGauge *)propertyWindow;
1547 if (name == "value")
1548 return new wxProperty("value", (long)gauge->GetValue(), "integer");
1549 else if (name == "maxValue")
1550 return new wxProperty("maxValue", (long)gauge->GetRange(), "integer");
1551 else
1552 return wxItemPropertyInfo::GetProperty(name);
1553 }
1554
1555 bool wxGaugePropertyInfo::SetProperty(wxString& name, wxProperty *property)
1556 {
1557 wxGauge *gauge = (wxGauge *)propertyWindow;
1558 if (name == "value")
1559 {
1560 gauge->SetValue((int)property->GetValue().IntegerValue());
1561 return TRUE;
1562 }
1563 else if (name == "maxValue")
1564 {
1565 gauge->SetRange((int)property->GetValue().IntegerValue());
1566 return TRUE;
1567 }
1568 else
1569 return wxItemPropertyInfo::SetProperty(name, property);
1570 }
1571
1572 void wxGaugePropertyInfo::GetPropertyNames(wxStringList& names)
1573 {
1574 wxItemPropertyInfo::GetPropertyNames(names);
1575 names.Add("value");
1576 names.Add("maxValue");
1577 }
1578
1579 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource *resource)
1580 {
1581 wxGauge *gauge = (wxGauge *)propertyWindow;
1582 resource->SetValue1(gauge->GetValue());
1583 resource->SetValue2(gauge->GetRange());
1584 return wxItemPropertyInfo::InstantiateResource(resource);
1585 }
1586
1587 /*
1588 * Scrollbar item
1589 */
1590
1591 wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name)
1592 {
1593 wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow;
1594 if (name == "value")
1595 return new wxProperty("value", (long)scrollBar->GetValue(), "integer");
1596 else if (name == "orientation")
1597 {
1598 char *pos = NULL;
1599 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1600 pos = "wxHORIZONTAL";
1601 else
1602 pos = "wxVERTICAL";
1603
1604 return new wxProperty("orientation", pos, "string",
1605 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1606 NULL)));
1607 }
1608 else if (name == "pageSize")
1609 {
1610 int viewStart, pageLength, objectLength, viewLength;
1611 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1612
1613 return new wxProperty("pageSize", (long)pageLength, "integer");
1614 }
1615 else if (name == "viewLength")
1616 {
1617 int viewStart, pageLength, objectLength, viewLength;
1618 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1619
1620 return new wxProperty("viewLength", (long)viewLength, "integer");
1621 }
1622 else if (name == "objectLength")
1623 {
1624 int viewStart, pageLength, objectLength, viewLength;
1625 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1626
1627 return new wxProperty("objectLength", (long)objectLength, "integer");
1628 }
1629 else
1630 return wxItemPropertyInfo::GetProperty(name);
1631 }
1632
1633 bool wxScrollBarPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1634 {
1635 wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow;
1636 if (name == "value")
1637 {
1638 scrollBar->SetValue((int)property->GetValue().IntegerValue());
1639 return TRUE;
1640 }
1641 else if (name == "orientation")
1642 {
1643 long windowStyle = scrollBar->GetWindowStyleFlag();
1644 long oldWindowStyle = windowStyle;
1645 wxString val(property->GetValue().StringValue());
1646 if (val == "wxHORIZONTAL")
1647 {
1648 if (windowStyle & wxVERTICAL)
1649 windowStyle -= wxVERTICAL;
1650 windowStyle |= wxHORIZONTAL;
1651 }
1652 else
1653 {
1654 if (windowStyle & wxHORIZONTAL)
1655 windowStyle -= wxHORIZONTAL;
1656 windowStyle |= wxVERTICAL;
1657 }
1658
1659 if (oldWindowStyle == windowStyle)
1660 return TRUE;
1661
1662 scrollBar->SetWindowStyleFlag(windowStyle);
1663
1664 // If the window style has changed, we swap the width and height parameters.
1665 int w, h;
1666 scrollBar->GetSize(&w, &h);
1667
1668 scrollBar = (wxScrollBar *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar, this);
1669 scrollBar->SetSize(-1, -1, h, w);
1670
1671 return TRUE;
1672 }
1673 else if (name == "pageSize")
1674 {
1675 scrollBar->SetPageSize((int)property->GetValue().IntegerValue());
1676 return TRUE;
1677 }
1678 else if (name == "viewLength")
1679 {
1680 scrollBar->SetViewLength((int)property->GetValue().IntegerValue());
1681 return TRUE;
1682 }
1683 else if (name == "objectLength")
1684 {
1685 scrollBar->SetObjectLength((int)property->GetValue().IntegerValue());
1686 return TRUE;
1687 }
1688 else
1689 return wxItemPropertyInfo::SetProperty(name, property);
1690 }
1691
1692 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList& names)
1693 {
1694 wxItemPropertyInfo::GetPropertyNames(names);
1695 names.Add("orientation");
1696 names.Add("value");
1697 names.Add("pageSize");
1698 names.Add("viewLength");
1699 names.Add("objectLength");
1700
1701 // Remove some properties we don't inherit
1702 names.Delete("fontPoints");
1703 names.Delete("fontFamily");
1704 names.Delete("fontStyle");
1705 names.Delete("fontWeight");
1706 names.Delete("fontUnderlined");
1707 }
1708
1709 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource *resource)
1710 {
1711 wxScrollBar *sbar = (wxScrollBar *)propertyWindow;
1712
1713 resource->SetValue1(sbar->GetValue());
1714
1715 int viewStart, pageLength, objectLength, viewLength;
1716 sbar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1717
1718 resource->SetValue2(pageLength);
1719 resource->SetValue3(objectLength);
1720 resource->SetValue5(viewLength);
1721
1722 return wxItemPropertyInfo::InstantiateResource(resource);
1723 }
1724
1725 /*
1726 * Panels
1727 */
1728
1729 wxProperty *wxPanelPropertyInfo::GetProperty(wxString& name)
1730 {
1731 wxPanel *panelWindow = (wxPanel *)propertyWindow;
1732 wxFont *labelFont = panelWindow->GetLabelFont();
1733 wxFont *buttonFont = panelWindow->GetButtonFont();
1734
1735 if (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" ||
1736 name == "labelFontUnderlined")
1737 return GetFontProperty(name, labelFont);
1738 else if (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" ||
1739 name == "buttonFontUnderlined")
1740 return GetFontProperty(name, buttonFont);
1741 else if (name == "no3D")
1742 {
1743 bool userColours;
1744 if (panelWindow->GetWindowStyleFlag() & wxNO_3D)
1745 userColours = TRUE;
1746 else
1747 userColours = FALSE;
1748
1749 return new wxProperty(name, (bool)userColours, "bool");
1750 }
1751 else if (name == "backgroundColour")
1752 {
1753 wxColour col(panelWindow->GetBackgroundColour());
1754 char buf[7];
1755 wxDecToHex(col.Red(), buf);
1756 wxDecToHex(col.Green(), buf+2);
1757 wxDecToHex(col.Blue(), buf+4);
1758
1759 return new wxProperty(name, buf, "string", new wxColourListValidator);
1760 }
1761 else if (name == "title")
1762 {
1763 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1764 if (resource)
1765 return new wxProperty(name, resource->GetTitle(), "string");
1766 else
1767 return new wxProperty(name, "Could not get title", "string");
1768 }
1769 else if (name == "caption")
1770 {
1771 return new wxProperty(name, ((panelWindow->GetWindowStyleFlag() & wxCAPTION) == wxCAPTION),
1772 "bool");
1773 }
1774 else if (name == "systemMenu")
1775 {
1776 return new wxProperty(name, ((panelWindow->GetWindowStyleFlag() & wxSYSTEM_MENU) == wxSYSTEM_MENU),
1777 "bool");
1778 }
1779 else if (name == "thickFrame")
1780 {
1781 return new wxProperty(name, ((panelWindow->GetWindowStyleFlag() & wxTHICK_FRAME) == wxTHICK_FRAME),
1782 "bool");
1783 }
1784 else
1785 return wxWindowPropertyInfo::GetProperty(name);
1786 }
1787
1788 bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1789 {
1790 wxPanel *panelWindow = (wxPanel *)propertyWindow;
1791 wxFont *labelFont = panelWindow->GetLabelFont();
1792 wxFont *buttonFont = panelWindow->GetButtonFont();
1793
1794 if (labelFont && (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" || name == "labelFontUnderlined" ))
1795 {
1796 wxFont *newFont = SetFontProperty(name, property, labelFont);
1797 if (newFont)
1798 panelWindow->SetLabelFont(newFont);
1799 return TRUE;
1800 }
1801 else if (buttonFont && (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" || name == "buttonFontUnderlined" ))
1802 {
1803 wxFont *newFont = SetFontProperty(name, property, buttonFont);
1804 if (newFont)
1805 panelWindow->SetButtonFont(newFont);
1806 return TRUE;
1807 }
1808 else if (name == "no3D")
1809 {
1810 bool userColours = property->GetValue().BoolValue();
1811 long flag = panelWindow->GetWindowStyleFlag();
1812
1813 if (userColours)
1814 {
1815 if ((panelWindow->GetWindowStyleFlag() & wxNO_3D) != wxNO_3D)
1816 panelWindow->SetWindowStyleFlag(panelWindow->GetWindowStyleFlag() | wxNO_3D);
1817 }
1818 else
1819 {
1820 if ((panelWindow->GetWindowStyleFlag() & wxNO_3D) == wxNO_3D)
1821 panelWindow->SetWindowStyleFlag(panelWindow->GetWindowStyleFlag() - wxNO_3D);
1822 }
1823 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1824 resource->SetStyle(panelWindow->GetWindowStyleFlag());
1825
1826 panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this);
1827 return TRUE;
1828 }
1829 else if (name == "backgroundColour")
1830 {
1831 char *hex = property->GetValue().StringValue();
1832 int r = wxHexToDec(hex);
1833 int g = wxHexToDec(hex+2);
1834 int b = wxHexToDec(hex+4);
1835
1836 wxColour col(r,g,b);
1837 panelWindow->SetBackgroundColour(col);
1838 panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this);
1839 return TRUE;
1840 }
1841 else if (name == "title")
1842 {
1843 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1844 if (resource)
1845 {
1846 resource->SetTitle(property->GetValue().StringValue());
1847 return TRUE;
1848 }
1849 else
1850 return FALSE;
1851 }
1852 else if (name == "caption")
1853 {
1854 SetWindowStyle(panelWindow, wxCAPTION, property->GetValue().BoolValue());
1855
1856 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1857 resource->SetStyle(panelWindow->GetWindowStyleFlag());
1858 return TRUE;
1859 }
1860 else if (name == "thickFrame")
1861 {
1862 SetWindowStyle(panelWindow, wxTHICK_FRAME, property->GetValue().BoolValue());
1863
1864 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1865 resource->SetStyle(panelWindow->GetWindowStyleFlag());
1866 return TRUE;
1867 }
1868 else if (name == "systemMenu")
1869 {
1870 SetWindowStyle(panelWindow, wxSYSTEM_MENU, property->GetValue().BoolValue());
1871
1872 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1873 resource->SetStyle(panelWindow->GetWindowStyleFlag());
1874 return TRUE;
1875 }
1876 else
1877 return wxWindowPropertyInfo::SetProperty(name, property);
1878 }
1879
1880 void wxPanelPropertyInfo::GetPropertyNames(wxStringList& names)
1881 {
1882 wxWindowPropertyInfo::GetPropertyNames(names);
1883
1884 names.Add("title");
1885 names.Add("no3D");
1886 names.Add("backgroundColour");
1887 names.Add("caption");
1888 names.Add("systemMenu");
1889 names.Add("thickFrame");
1890 }
1891
1892 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource *resource)
1893 {
1894 wxPanel *panel = (wxPanel *)propertyWindow;
1895 if (panel->GetFont())
1896 resource->SetFont(wxTheFontList->FindOrCreateFont(panel->GetFont()->GetPointSize(),
1897 panel->GetFont()->GetFamily(), panel->GetFont()->GetStyle(), panel->GetFont()->GetWeight(),
1898 panel->GetFont()->GetUnderlined(), panel->GetFont()->GetFaceName()));
1899
1900 resource->SetBackgroundColour(new wxColour(panel->GetBackgroundColour()));
1901
1902 return wxWindowPropertyInfo::InstantiateResource(resource);
1903 }
1904
1905 #if 0
1906 /*
1907 * Dialog boxes
1908 */
1909
1910 wxProperty *wxDialogPropertyInfo::GetProperty(wxString& name)
1911 {
1912 wxDialog *dialogWindow = (wxDialog *)propertyWindow;
1913 if (name == "modal")
1914 {
1915 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow);
1916 if (!resource)
1917 return NULL;
1918
1919 bool modal = (resource->GetValue1() != 0);
1920 return new wxProperty(name, modal, "bool");
1921 }
1922 else
1923 return wxPanelPropertyInfo::GetProperty(name);
1924 }
1925
1926 bool wxDialogPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1927 {
1928 wxDialog *dialogWindow = (wxDialog *)propertyWindow;
1929
1930 if (name == "modal")
1931 {
1932 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow);
1933 if (!resource)
1934 return FALSE;
1935
1936 resource->SetValue1(property->GetValue().BoolValue());
1937 return TRUE;
1938 }
1939 else
1940 return wxPanelPropertyInfo::SetProperty(name, property);
1941 }
1942
1943 void wxDialogPropertyInfo::GetPropertyNames(wxStringList& names)
1944 {
1945 wxPanelPropertyInfo::GetPropertyNames(names);
1946 names.Add("title");
1947 names.Add("modal");
1948 }
1949
1950 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource *resource)
1951 {
1952 wxDialog *dialog = (wxDialog *)propertyWindow;
1953 wxString str(dialog->GetTitle());
1954 resource->SetTitle(WXSTRINGCAST str);
1955
1956 return wxPanelPropertyInfo::InstantiateResource(resource);
1957 }
1958 #endif
1959
1960 /*
1961 * Utilities
1962 */
1963
1964 int wxStringToFontWeight(wxString& val)
1965 {
1966 if (val == "wxBOLD") return wxBOLD;
1967 else if (val == "wxLIGHT") return wxLIGHT;
1968 else return wxNORMAL;
1969 }
1970
1971 int wxStringToFontStyle(wxString& val)
1972 {
1973 if (val == "wxITALIC") return wxITALIC;
1974 else if (val == "wxSLANT") return wxSLANT;
1975 else return wxNORMAL;
1976 }
1977
1978 int wxStringToFontFamily(wxString& val)
1979 {
1980 if (val == "wxDECORATIVE") return wxDECORATIVE;
1981 else if (val == "wxROMAN") return wxROMAN;
1982 else if (val == "wxSCRIPT") return wxSCRIPT;
1983 else if (val == "wxMODERN") return wxMODERN;
1984 else if (val == "wxTELETYPE") return wxTELETYPE;
1985 else return wxSWISS;
1986 }
1987
1988 ///
1989 /// Resource symbol validator
1990 ///
1991 IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator, wxPropertyListValidator)
1992
1993 wxResourceSymbolValidator::wxResourceSymbolValidator(long flags):
1994 wxPropertyListValidator(flags)
1995 {
1996 }
1997
1998 wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
1999 {
2000 }
2001
2002 bool wxResourceSymbolValidator::OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
2003 {
2004 return TRUE;
2005 }
2006
2007 // Called when TICK is pressed or focus is lost or view wants to update
2008 // the property list.
2009 // Does the transferance from the property editing area to the property itself
2010 bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
2011 {
2012 if (!view->GetValueText())
2013 return FALSE;
2014 wxString value(view->GetValueText()->GetValue());
2015 property->GetValue() = value ;
2016 return TRUE;
2017 }
2018
2019 // Called when TICK is pressed or focus is lost or view wants to update
2020 // the property list.
2021 // Does the transferance from the property editing area to the property itself
2022 bool wxResourceSymbolValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
2023 {
2024 if (!view->GetValueText())
2025 return FALSE;
2026 wxString str(property->GetValue().GetStringRepresentation());
2027 view->GetValueText()->SetValue(str);
2028 return TRUE;
2029 }
2030
2031 // Called when the property is double clicked. Extra functionality can be provided,
2032 // cycling through possible values.
2033 bool wxResourceSymbolValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
2034 {
2035 if (!view->GetValueText())
2036 return FALSE;
2037 OnEdit(property, view, parentWindow);
2038 return TRUE;
2039 }
2040
2041 bool wxResourceSymbolValidator::OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
2042 {
2043 if (view->GetConfirmButton())
2044 view->GetConfirmButton()->Enable(TRUE);
2045 if (view->GetCancelButton())
2046 view->GetCancelButton()->Enable(TRUE);
2047 if (view->GetEditButton())
2048 view->GetEditButton()->Enable(TRUE);
2049 if (view->GetValueText())
2050 view->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == wxPROP_ALLOW_TEXT_EDITING);
2051 return TRUE;
2052 }
2053
2054 void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
2055 {
2056 if (!view->GetValueText())
2057 return;
2058
2059 wxResourceSymbolDialog* dialog = new wxResourceSymbolDialog(parentWindow, -1, "Edit Symbol");
2060
2061 // Split name/id pair e.g. "IDC_TEXT=123"
2062 wxString value(property->GetValue().StringValue());
2063
2064 wxString strName = value.Before('=');
2065 wxString strId = value.After('=');
2066
2067 dialog->SetSymbol(strName);
2068 dialog->SetId(atoi(strId));
2069
2070 dialog->Init();
2071
2072 if (dialog->ShowModal() == wxID_OK)
2073 {
2074 wxString symbolName(dialog->GetSymbol());
2075 long id = dialog->GetId();
2076 dialog->Destroy();
2077
2078 wxString str;
2079 str.Printf("%d", id);
2080 property->GetValue() = symbolName + wxString("=") + str;
2081
2082 view->DisplayProperty(property);
2083 view->UpdatePropertyDisplayInList(property);
2084 view->OnPropertyChanged(property);
2085 }
2086 }
2087
2088 BEGIN_EVENT_TABLE(wxResourceSymbolDialog, wxDialog)
2089 EVT_BUTTON(wxID_OK, wxResourceSymbolDialog::OnOK)
2090 EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX, wxResourceSymbolDialog::OnComboBoxSelect)
2091 EVT_TEXT(ID_SYMBOLNAME_COMBOBOX, wxResourceSymbolDialog::OnSymbolNameUpdate)
2092 END_EVENT_TABLE()
2093
2094 wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow* parent, const wxWindowID id, const wxString& title, const wxPoint& pos,
2095 const wxSize& size, long style):
2096 wxDialog(parent, id, title, pos, size, style)
2097 {
2098 int x = 5;
2099 int y = 5;
2100
2101 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x, y));
2102
2103 x += 80;
2104
2105 m_nameCtrl = new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX, "",
2106 wxPoint(x, y), wxSize(200, -1), 0, NULL, wxCB_DROPDOWN|wxCB_SORT);
2107
2108 y += 30;
2109 x = 5;
2110
2111 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x, y));
2112
2113 x += 80;
2114
2115 m_idCtrl = new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL, "",
2116 wxPoint(x, y), wxSize(200, -1));
2117
2118 y += 30;
2119 x = 5;
2120 (void) new wxButton(this, wxID_OK, "OK", wxPoint(x, y), wxSize(80, -1));
2121
2122 x += 100;
2123 (void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(x, y), wxSize(80, -1));
2124
2125 Fit();
2126 Centre();
2127 }
2128
2129 void wxResourceSymbolDialog::Init()
2130 {
2131 wxString defaultId;
2132 defaultId.Printf("%ld", m_symbolId);
2133
2134 m_nameCtrl->SetValue(m_symbolName);
2135 m_idCtrl->SetValue(defaultId);
2136
2137 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl);
2138 }
2139
2140 void wxResourceSymbolDialog::OnOK(wxCommandEvent& event)
2141 {
2142 if (CheckValues())
2143 {
2144 wxDialog::OnOK(event);
2145 }
2146 }
2147
2148 bool wxResourceSymbolDialog::CheckValues()
2149 {
2150 wxString nameStr(m_nameCtrl->GetValue());
2151 wxString idStr(m_idCtrl->GetValue());
2152 int id = atoi(idStr);
2153
2154 if (id <= 0 )
2155 {
2156 wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
2157 return FALSE;
2158 }
2159 if (nameStr == "")
2160 {
2161 wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
2162 return FALSE;
2163 }
2164 if (nameStr.Contains(" "))
2165 {
2166 wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
2167 return FALSE;
2168 }
2169 if (nameStr.Contains("="))
2170 {
2171 wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
2172 return FALSE;
2173 }
2174 if (nameStr.IsNumber())
2175 {
2176 wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
2177 return FALSE;
2178 }
2179 // TODO: other checks on the name syntax.
2180
2181 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr))
2182 {
2183 // If we change the id for an existing symbol, we need to:
2184 // 1) Check if there are any other resources currently using the original id.
2185 // If so, will need to change their id to the new id, in SetProperty.
2186 // 2) Remove the old symbol, add the new symbol.
2187 // In this check, we don't have to do this, but we need to do it in SetProperty.
2188
2189 if (nameStr == GetSymbol() && id != GetId())
2190 {
2191 // It's OK to change the id. But we'll need to change all matching ids in all resources,
2192 // in SetProperty.
2193 }
2194
2195 // If we change the name but not the id... we'll just need to remove and
2196 // re-add the symbol/id pair, in SetProperty.
2197 if (nameStr != GetSymbol() && id == GetId())
2198 {
2199 }
2200
2201 // What if we're changing both the name and the id?
2202 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
2203 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
2204
2205 if (nameStr != GetSymbol() && id != GetId())
2206 {
2207 if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr, id))
2208 {
2209 wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
2210 "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
2211 return FALSE;
2212 }
2213 }
2214
2215 }
2216
2217 SetSymbol(nameStr);
2218 SetId(id);
2219
2220 return TRUE;
2221 }
2222
2223 void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent& event)
2224 {
2225 wxString str(m_nameCtrl->GetStringSelection());
2226 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str))
2227 {
2228 int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
2229 wxString str2;
2230 str2.Printf("%d", id);
2231 m_idCtrl->SetValue(str2);
2232 m_idCtrl->Enable(FALSE);
2233 }
2234 else
2235 {
2236 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str))
2237 {
2238 int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
2239 wxString str2;
2240 str2.Printf("%d", id);
2241 m_idCtrl->SetValue(str2);
2242 }
2243 m_idCtrl->Enable(TRUE);
2244 }
2245 }
2246
2247 void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent& event)
2248 {
2249 wxString str(m_nameCtrl->GetValue());
2250 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str))
2251 {
2252 int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
2253 wxString str2;
2254 str2.Printf("%d", id);
2255 m_idCtrl->SetValue(str2);
2256 m_idCtrl->Enable(FALSE);
2257 }
2258 else
2259 {
2260 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str))
2261 {
2262 int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
2263 wxString str2;
2264 str2.Printf("%d", id);
2265 m_idCtrl->SetValue(str2);
2266 }
2267 m_idCtrl->Enable(TRUE);
2268 }
2269 }
2270