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