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