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