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