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