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