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