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