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