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