]> git.saurik.com Git - wxWidgets.git/blame - utils/dialoged/src/winprop.cpp
several fixes
[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
ae8351fc
JS
77wxDialogEditorPropertyListDialog::wxDialogEditorPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title,
78 const wxPoint& pos, const wxSize& size,
79 long style, const wxString& name):
80 wxPropertyListDialog(v, parent, title, pos, size, style, name)
81{
82 m_propSheet = NULL;
83 m_propInfo = NULL;
84}
85
86wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog()
87{
88 delete m_propSheet;
89 delete m_propInfo;
90 wxPropertyInfo::sm_propertyWindow = NULL;
91}
92
93/*
94 * wxPropertyInfo
95 */
457814b5
JS
96
97// Edit the information represented by this object, whatever that
98// might be.
ae8351fc 99bool wxPropertyInfo::Edit(wxWindow *parent, const wxString& title)
457814b5 100{
ae8351fc
JS
101 if (sm_propertyWindow)
102 return FALSE;
103
104 int width = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width;
105 int height = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height;
106 int x = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x;
107 int y = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y;
108
457814b5
JS
109 wxPropertySheet *propSheet = new wxPropertySheet;
110
111 wxStringList propNames;
112 GetPropertyNames(propNames);
113
114 wxNode *node = propNames.First();
115 while (node)
116 {
117 wxString name((char *)node->Data());
118 wxProperty *prop = GetProperty(name);
119 if (prop)
120 {
121 propSheet->AddProperty(prop);
122 }
123 node = node->Next();
124 }
125
126 // Reset 'modified' flags for all property values
127 propSheet->SetAllModified(FALSE);
128
457814b5
JS
129 wxResourcePropertyListView *view = new wxResourcePropertyListView(this, NULL,
130#ifdef __XVIEW__
131 wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL |
132#endif
133 wxPROP_BUTTON_CHECK_CROSS|wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES);
134
ae8351fc
JS
135 wxDialogEditorPropertyListDialog *propDialog = new wxDialogEditorPropertyListDialog(view,
136 wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title, wxPoint(x, y),
137 wxSize(width, height), wxDEFAULT_DIALOG_STYLE);
457814b5 138 sm_propertyWindow = propDialog;
ae8351fc
JS
139
140 propDialog->m_registry.RegisterValidator((wxString)"real", new wxRealListValidator);
141 propDialog->m_registry.RegisterValidator((wxString)"string", new wxStringListValidator);
142 propDialog->m_registry.RegisterValidator((wxString)"integer", new wxIntegerListValidator);
143 propDialog->m_registry.RegisterValidator((wxString)"bool", new wxBoolListValidator);
144 propDialog->m_registry.RegisterValidator((wxString)"filename", new wxFilenameListValidator);
145 propDialog->m_registry.RegisterValidator((wxString)"stringlist", new wxListOfStringsListValidator);
03f68f12 146 propDialog->m_registry.RegisterValidator((wxString)"window_id", new wxResourceSymbolValidator);
ae8351fc
JS
147
148 propDialog->m_propInfo = this;
149 propDialog->m_propSheet = propSheet;
457814b5
JS
150
151// view->propertyWindow = propDialog;
ae8351fc 152 view->AddRegistry(&(propDialog->m_registry));
457814b5
JS
153 view->ShowView(propSheet, propDialog);
154
ae8351fc
JS
155 propDialog->Show(TRUE);
156 return TRUE;
457814b5
JS
157}
158
159/*
160 * wxWindowPropertyInfo
161 */
162
163wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow *win, wxItemResource *res)
164{
165 propertyWindow = win;
166 propertyResource = res;
167}
168
169wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
170{
171}
172
173wxProperty *wxWindowPropertyInfo::GetFontProperty(wxString& name, wxFont *font)
174{
175 if (!font)
176 return NULL;
177
178 if (name.Contains("Points"))
179 return new wxProperty(name, (long)font->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
180 else if (name.Contains("Family"))
181 return new wxProperty(name, font->GetFamilyString(), "string",
182 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
183 NULL)));
184 else if (name.Contains("Style"))
185 return new wxProperty(name, font->GetStyleString(), "string",
186 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL)));
187 else if (name.Contains("Weight"))
188 return new wxProperty(name, font->GetWeightString(), "string",
189 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL)));
190 else if (name.Contains("Underlined"))
191 return new wxProperty(name, (bool)font->GetUnderlined(), "bool");
192 else
193 return NULL;
194}
195
196wxFont *wxWindowPropertyInfo::SetFontProperty(wxString& name, wxProperty *property, wxFont *font)
197{
198 int pointSize = 12;
199 int fontFamily = wxMODERN;
200 int fontStyle = wxNORMAL;
201 int fontWeight = wxNORMAL;
202 bool fontUnderlined = FALSE;
203
204 if (name.Contains("Points"))
205 {
206 pointSize = (int)property->GetValue().IntegerValue();
207 if (font && (pointSize == font->GetPointSize()))
208 return NULL; // No change
209 }
210 else if (font) pointSize = font->GetPointSize();
211
212 if (name.Contains("Family"))
213 {
214 wxString val = property->GetValue().StringValue();
215 fontFamily = wxStringToFontFamily(val);
216
217 if (font && (fontFamily == font->GetFamily()))
218 return NULL; // No change
219 }
220 else if (font) fontFamily = font->GetFamily();
221
222 if (name.Contains("Style"))
223 {
224 wxString val = property->GetValue().StringValue();
225 fontStyle = wxStringToFontStyle(val);
226
227 if (font && (fontStyle == font->GetStyle()))
228 return NULL; // No change
229 }
230 else if (font) fontStyle = font->GetStyle();
231 if (name.Contains("Weight"))
232 {
233 wxString val = property->GetValue().StringValue();
234 fontWeight = wxStringToFontWeight(val);
235
236 if (font && (fontWeight == font->GetWeight()))
237 return NULL; // No change
238 }
239 else if (font) fontWeight = font->GetWeight();
240
241 if (name.Contains("Underlined"))
242 {
243 fontUnderlined = property->GetValue().BoolValue();
244
245 if (font && (fontUnderlined == font->GetUnderlined()))
246 return NULL; // No change
247 }
248 else if (font) fontUnderlined = font->GetUnderlined();
249
250 wxFont *newFont = wxTheFontList->FindOrCreateFont(pointSize, fontFamily, fontStyle, fontWeight, fontUnderlined);
251 if (newFont)
252 {
253 return newFont;
254 }
255 else
256 return NULL;
257}
258
259wxProperty *wxWindowPropertyInfo::GetProperty(wxString& name)
260{
261 wxFont *font = propertyWindow->GetFont();
262 if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" ||
263 name == "fontUnderlined")
264 return GetFontProperty(name, font);
265 else if (name == "name")
266 return new wxProperty("name", propertyWindow->GetName(), "string");
267 else if (name == "title")
268 return new wxProperty("title", propertyWindow->GetTitle(), "string");
269 else if (name == "x")
270 {
271 int x, y;
272 propertyWindow->GetPosition(&x, &y);
273 return new wxProperty("x", (long)x, "integer");
274 }
275 else if (name == "y")
276 {
277 int x, y;
278 propertyWindow->GetPosition(&x, &y);
279 return new wxProperty("y", (long)y, "integer");
280 }
281 else if (name == "width")
282 {
283 int width, height;
284 propertyWindow->GetSize(&width, &height);
285 return new wxProperty("width", (long)width, "integer");
286 }
287 else if (name == "height")
288 {
289 int width, height;
290 propertyWindow->GetSize(&width, &height);
291 return new wxProperty("height", (long)height, "integer");
292 }
03f68f12
JS
293 else if (name == "id")
294 {
295 wxString symbolName("TODO");
296 return new wxProperty("id", symbolName, "window_id");
297 }
457814b5
JS
298 else
299 return NULL;
300}
301
302bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property)
303{
304 wxFont *font = propertyWindow->GetFont();
305 if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ))
306 {
307 wxFont *newFont = SetFontProperty(name, property, font);
308 if (newFont)
309 propertyWindow->SetFont(newFont);
310 return TRUE;
311 }
312 else if (name == "name")
313 {
314 // Remove old name from resource table, if it's there.
ae8351fc 315 wxItemResource *oldResource = (wxItemResource *)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(propertyWindow->GetName());
457814b5
JS
316 if (oldResource)
317 {
318 // It's a top-level resource
319 propertyWindow->SetName(property->GetValue().StringValue());
320 oldResource->SetName(property->GetValue().StringValue());
ae8351fc 321 wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(propertyWindow->GetName(), oldResource);
457814b5
JS
322 }
323 else
324 {
325 // It's a child of something; just set the name of the resource and the window.
326 propertyWindow->SetName(property->GetValue().StringValue());
327 propertyResource->SetName(property->GetValue().StringValue());
328 }
329 // Refresh the resource manager list, because the name changed.
ae8351fc 330 wxResourceManager::GetCurrentResourceManager()->UpdateResourceList();
457814b5
JS
331 return TRUE;
332 }
333 else if (name == "title")
334 {
335 propertyWindow->SetTitle(property->GetValue().StringValue());
336 return TRUE;
337 }
338 else if (name == "x")
339 {
340 int x, y;
341 propertyWindow->GetPosition(&x, &y);
342 int newX = (int)property->GetValue().IntegerValue();
343 if (x != newX)
344 propertyWindow->Move(newX, y);
345 return TRUE;
346 }
347 else if (name == "y")
348 {
349 int x, y;
350 propertyWindow->GetPosition(&x, &y);
351 int newY = (int)property->GetValue().IntegerValue();
352 if (y != newY)
353 propertyWindow->Move(x, newY);
354 return TRUE;
355 }
356 else if (name == "width")
357 {
358 int width, height;
359 propertyWindow->GetSize(&width, &height);
360 int newWidth = (int)property->GetValue().IntegerValue();
361 if (width != newWidth)
362 {
363 propertyWindow->SetSize(newWidth, height);
ae8351fc 364/*
457814b5
JS
365 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
366 {
367 propertyWindow->GetParent()->SetClientSize(newWidth, height);
368 }
ae8351fc 369*/
457814b5
JS
370 }
371 return TRUE;
372 }
373 else if (name == "height")
374 {
375 int width, height;
376 propertyWindow->GetSize(&width, &height);
377 int newHeight = (int)property->GetValue().IntegerValue();
378 if (height != newHeight)
379 {
380 propertyWindow->SetSize(width, newHeight);
ae8351fc 381/*
457814b5
JS
382 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
383 {
384 propertyWindow->GetParent()->SetClientSize(width, newHeight);
385 }
ae8351fc 386*/
457814b5
JS
387 }
388 return TRUE;
389 }
03f68f12
JS
390 else if (name == "id")
391 {
392 // TODO
393 return TRUE;
394 }
457814b5
JS
395 else
396 return FALSE;
397}
398
399void wxWindowPropertyInfo::GetPropertyNames(wxStringList& names)
400{
03f68f12 401 names.Add("id");
457814b5
JS
402 names.Add("name");
403 names.Add("x");
404 names.Add("y");
405 names.Add("width");
406 names.Add("height");
407 if (!propertyWindow->IsKindOf(CLASSINFO(wxControl)))
408 {
409 names.Add("fontPoints");
410 names.Add("fontFamily");
411 names.Add("fontStyle");
412 names.Add("fontWeight");
413 names.Add("fontUnderlined");
414 }
415}
416
417// Fill in the wxItemResource members to mirror the current window settings
418bool wxWindowPropertyInfo::InstantiateResource(wxItemResource *resource)
419{
420 resource->SetType(propertyWindow->GetClassInfo()->GetClassName());
421
422// resource->SetStyle(propertyWindow->GetWindowStyleFlag());
423 wxString str(propertyWindow->GetName());
424 resource->SetName(WXSTRINGCAST str);
425 int x, y, w, h;
426 propertyWindow->GetSize(&w, &h);
427
428 propertyWindow->GetPosition(&x, &y);
429 resource->SetSize(x, y, w, h);
430 return TRUE;
431}
432
433
434/*
ae8351fc 435 * Controls
457814b5
JS
436 */
437
438wxProperty *wxItemPropertyInfo::GetProperty(wxString& name)
439{
440 wxControl *itemWindow = (wxControl *)propertyWindow;
441 wxFont *font = itemWindow->GetFont();
442
443 if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" ||
444 name == "fontUnderlined")
445 return GetFontProperty(name, font);
446 else if (name == "label" && itemWindow->GetLabel())
447 return new wxProperty("label", propertyWindow->GetLabel(), "string");
448 else
449 return wxWindowPropertyInfo::GetProperty(name);
450}
451
452bool wxItemPropertyInfo::SetProperty(wxString& name, wxProperty *property)
453{
454 wxControl *itemWindow = (wxControl *)propertyWindow;
455 wxFont *font = itemWindow->GetFont();
456
457 if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ))
458 {
459 wxFont *newFont = SetFontProperty(name, property, font);
460 if (newFont)
461 itemWindow->SetLabelFont(newFont);
462 return TRUE;
463 }
464 else if (name == "label")
465 {
466 itemWindow->SetLabel(property->GetValue().StringValue());
467 return TRUE;
468 }
469 else
470 return wxWindowPropertyInfo::SetProperty(name, property);
471}
472
473void wxItemPropertyInfo::GetPropertyNames(wxStringList& names)
474{
475 wxWindowPropertyInfo::GetPropertyNames(names);
476
477 names.Add("fontPoints");
478 names.Add("fontFamily");
479 names.Add("fontStyle");
480 names.Add("fontWeight");
481 names.Add("fontUnderlined");
482}
483
484bool wxItemPropertyInfo::InstantiateResource(wxItemResource *resource)
485{
486 wxWindowPropertyInfo::InstantiateResource(resource);
487
488 wxControl *item = (wxControl *)propertyWindow;
489 wxString str(item->GetLabel());
490 resource->SetTitle(WXSTRINGCAST str);
ae8351fc 491 if (item->GetFont() && item->GetFont()->Ok())
457814b5
JS
492 resource->SetFont(wxTheFontList->FindOrCreateFont(item->GetFont()->GetPointSize(),
493 item->GetFont()->GetFamily(), item->GetFont()->GetStyle(), item->GetFont()->GetWeight(),
494 item->GetFont()->GetUnderlined(), item->GetFont()->GetFaceName()));
495 return TRUE;
496}
497
498/*
499 * Button
500 */
501
502wxProperty *wxButtonPropertyInfo::GetProperty(wxString& name)
503{
504 wxButton *button = (wxButton *)propertyWindow;
ae8351fc
JS
505 return wxItemPropertyInfo::GetProperty(name);
506}
507
508bool wxButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
509{
510 wxButton *button = (wxButton *)propertyWindow;
511 return wxItemPropertyInfo::SetProperty(name, property);
512}
513
514void wxButtonPropertyInfo::GetPropertyNames(wxStringList& names)
515{
516 names.Add("label");
517 wxItemPropertyInfo::GetPropertyNames(names);
518}
519
520bool wxButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
521{
522 return wxItemPropertyInfo::InstantiateResource(resource);
523}
524
457814b5 525/*
ae8351fc
JS
526 * wxBitmapButton
527 */
528
529wxProperty *wxBitmapButtonPropertyInfo::GetProperty(wxString& name)
530{
531 wxBitmapButton *button = (wxBitmapButton *)propertyWindow;
532 if (name == "label")
457814b5 533 {
ae8351fc 534 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button);
457814b5
JS
535 wxString str("none.bmp");
536
537 if (resource)
538 {
ae8351fc 539 char *filename = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource);
457814b5
JS
540 if (filename)
541 str = filename;
542 }
543 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
544 }
545 else
ae8351fc 546 return wxButtonPropertyInfo::GetProperty(name);
457814b5
JS
547}
548
ae8351fc 549bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
457814b5 550{
ae8351fc
JS
551 wxBitmapButton *button = (wxBitmapButton *)propertyWindow;
552 if (name == "label")
457814b5
JS
553 {
554 char *s = property->GetValue().StringValue();
555 if (s && wxFileExists(s))
556 {
557 s = copystring(s);
558 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
559 if (!bitmap->Ok())
560 {
561 delete bitmap;
562 delete[] s;
563 return FALSE;
564 }
565 else
566 {
ae8351fc 567 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button);
457814b5
JS
568 if (resource)
569 {
570 wxString oldResource(resource->GetValue4());
ae8351fc 571 char *resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s);
457814b5
JS
572 resource->SetValue4(resName);
573
574 if (!oldResource.IsNull())
ae8351fc 575 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
457814b5
JS
576 }
577
578 button->SetLabel(bitmap);
579 delete[] s;
580 return TRUE;
581 }
582 }
583 return FALSE;
584 }
585 else
ae8351fc 586 return wxButtonPropertyInfo::SetProperty(name, property);
457814b5
JS
587}
588
ae8351fc 589void wxBitmapButtonPropertyInfo::GetPropertyNames(wxStringList& names)
457814b5 590{
ae8351fc
JS
591// names.Add("label");
592 wxButtonPropertyInfo::GetPropertyNames(names);
457814b5
JS
593}
594
ae8351fc 595bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
457814b5
JS
596{
597 return wxItemPropertyInfo::InstantiateResource(resource);
598}
599
600/*
ae8351fc 601 * wxStaticText
457814b5
JS
602 */
603
604wxProperty *wxStaticTextPropertyInfo::GetProperty(wxString& name)
605{
606 wxStaticText *message = (wxStaticText *)propertyWindow;
ae8351fc
JS
607 return wxItemPropertyInfo::GetProperty(name);
608}
609
610bool wxStaticTextPropertyInfo::SetProperty(wxString& name, wxProperty *property)
611{
612 wxStaticText *message = (wxStaticText *)propertyWindow;
613 return wxItemPropertyInfo::SetProperty(name, property);
614}
615
616void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList& names)
617{
618 names.Add("label");
619 wxItemPropertyInfo::GetPropertyNames(names);
620}
621
622bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource *resource)
623{
624 return wxItemPropertyInfo::InstantiateResource(resource);
625}
626
457814b5 627/*
ae8351fc
JS
628 * wxStaticBitmap
629 */
630
631wxProperty *wxStaticBitmapPropertyInfo::GetProperty(wxString& name)
632{
633 wxStaticBitmap *message = (wxStaticBitmap *)propertyWindow;
634 if (name == "label")
457814b5 635 {
ae8351fc 636 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message);
457814b5
JS
637 wxString str("none.bmp");
638
639 if (resource)
640 {
ae8351fc 641 char *filename = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource);
457814b5
JS
642 if (filename)
643 str = filename;
644 }
645 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
646 }
647 else
457814b5
JS
648 return wxItemPropertyInfo::GetProperty(name);
649}
650
ae8351fc 651bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *property)
457814b5 652{
ae8351fc
JS
653 wxStaticBitmap *message = (wxStaticBitmap *)propertyWindow;
654 if (name == "label")
457814b5
JS
655 {
656 char *s = property->GetValue().StringValue();
657 if (s && wxFileExists(s))
658 {
659 s = copystring(s);
660
661 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
662 if (!bitmap->Ok())
663 {
664 delete bitmap;
665 delete[] s;
666 return FALSE;
667 }
668 else
669 {
ae8351fc 670 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message);
457814b5
JS
671 if (resource)
672 {
673 wxString oldResource(resource->GetValue4());
ae8351fc 674 char *resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s);
457814b5
JS
675 resource->SetValue4(resName);
676
677 if (!oldResource.IsNull())
ae8351fc 678 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
457814b5
JS
679 }
680
ae8351fc 681 message->SetBitmap(bitmap);
457814b5
JS
682 delete[] s;
683 return TRUE;
684 }
685 }
686 return FALSE;
687 }
688 else
457814b5
JS
689 return wxItemPropertyInfo::SetProperty(name, property);
690}
691
ae8351fc 692void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList& names)
457814b5
JS
693{
694 names.Add("label");
695 wxItemPropertyInfo::GetPropertyNames(names);
696}
697
ae8351fc 698bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource *resource)
457814b5
JS
699{
700 return wxItemPropertyInfo::InstantiateResource(resource);
701}
702
703/*
704 * Text item
705 */
706
707wxProperty *wxTextPropertyInfo::GetProperty(wxString& name)
708{
709 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
710 if (name == "value")
711 return new wxProperty("value", text->GetValue(), "string");
712 else if (name == "password")
713 {
714 bool isPassword = ((text->GetWindowStyleFlag() & wxTE_PASSWORD) == wxTE_PASSWORD);
715 return new wxProperty("password", isPassword, "bool");
716 }
717 else if (name == "readonly")
718 {
719 bool isReadOnly = ((text->GetWindowStyleFlag() & wxTE_READONLY) == wxTE_READONLY);
720 return new wxProperty("readonly", isReadOnly, "bool");
721 }
722 else
723 return wxItemPropertyInfo::GetProperty(name);
724}
725
726bool wxTextPropertyInfo::SetProperty(wxString& name, wxProperty *property)
727{
728 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
729 if (name == "value")
730 {
731 text->SetValue(property->GetValue().StringValue());
732 return TRUE;
733 }
734 else if (name == "password")
735 {
736 long flag = text->GetWindowStyleFlag();
737 if (property->GetValue().BoolValue())
738 {
739 if ((flag & wxTE_PASSWORD) != wxTE_PASSWORD)
740 flag |= wxTE_PASSWORD;
741 }
742 else
743 {
744 if ((flag & wxTE_PASSWORD) == wxTE_PASSWORD)
745 flag -= wxTE_PASSWORD;
746 }
ae8351fc 747 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text);
457814b5
JS
748 resource->SetStyle(flag);
749
ae8351fc 750 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this);
457814b5
JS
751 return TRUE;
752 }
753 else if (name == "readonly")
754 {
755 long flag = text->GetWindowStyleFlag();
756 if (property->GetValue().BoolValue())
757 {
758 if ((flag & wxTE_READONLY) != wxTE_READONLY)
759 flag |= wxTE_READONLY;
760 }
761 else
762 {
763 if ((flag & wxTE_READONLY) == wxTE_READONLY)
764 flag -= wxTE_READONLY;
765 }
ae8351fc 766 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text);
457814b5
JS
767 resource->SetStyle(flag);
768
ae8351fc 769 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this);
457814b5
JS
770 return TRUE;
771 }
772 else
773 return wxItemPropertyInfo::SetProperty(name, property);
774}
775
776void wxTextPropertyInfo::GetPropertyNames(wxStringList& names)
777{
778 names.Add("value");
779 names.Add("readonly");
780 names.Add("password");
781 wxItemPropertyInfo::GetPropertyNames(names);
782}
783
784bool wxTextPropertyInfo::InstantiateResource(wxItemResource *resource)
785{
786 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
787 wxString str(text->GetValue());
788 resource->SetValue4(WXSTRINGCAST str);
789
790 return wxItemPropertyInfo::InstantiateResource(resource);
791}
792
793/*
794 * Listbox item
795 */
796
797wxProperty *wxListBoxPropertyInfo::GetProperty(wxString& name)
798{
799 wxListBox *listBox = (wxListBox *)propertyWindow;
800 if (name == "values")
801 {
802 wxStringList *stringList = new wxStringList;
803 int i;
804 for (i = 0; i < listBox->Number(); i++)
805 stringList->Add(listBox->GetString(i));
806
807 return new wxProperty(name, stringList, "stringlist");
808 }
809 else if (name == "multiple")
810 {
811 char *pos = NULL;
ae8351fc 812 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox);
457814b5
JS
813 if (!resource)
814 return NULL;
815
816 char *mult = "wxSINGLE";
817
818 switch (resource->GetValue1())
819 {
820 case wxLB_MULTIPLE:
821 mult = "wxLB_MULTIPLE";
822 break;
823 case wxLB_EXTENDED:
824 mult = "wxLB_EXTENDED";
825 break;
826 default:
827 case wxLB_SINGLE:
828 mult = "wxLB_SINGLE";
829 break;
830 }
831 return new wxProperty("multiple", mult, "string",
832 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
833 NULL)));
834 }
835 else
836 return wxItemPropertyInfo::GetProperty(name);
837}
838
839bool wxListBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
840{
841 wxListBox *listBox = (wxListBox *)propertyWindow;
842 if (name == "values")
843 {
844 listBox->Clear();
845 wxPropertyValue *expr = property->GetValue().GetFirst();
846 while (expr)
847 {
848 char *s = expr->StringValue();
849 if (s)
850 listBox->Append(s);
851 expr = expr->GetNext();
852 }
853 return TRUE;
854 }
855 else if (name == "multiple")
856 {
857 int mult = wxLB_SINGLE;
858 wxString str(property->GetValue().StringValue());
859 if (str == "wxLB_MULTIPLE")
860 mult = wxLB_MULTIPLE;
861 else if (str == "wxLB_EXTENDED")
862 mult = wxLB_EXTENDED;
863 else
864 mult = wxLB_SINGLE;
ae8351fc 865 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox);
457814b5
JS
866 if (resource)
867 resource->SetValue1(mult);
ae8351fc 868 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox, this);
457814b5
JS
869 return TRUE;
870 }
871 else
872 return wxItemPropertyInfo::SetProperty(name, property);
873}
874
875void wxListBoxPropertyInfo::GetPropertyNames(wxStringList& names)
876{
877 names.Add("values");
878 names.Add("multiple");
879 wxItemPropertyInfo::GetPropertyNames(names);
880}
881
882bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
883{
884 wxListBox *lbox = (wxListBox *)propertyWindow;
885 // This will be set for the wxItemResource on reading or in SetProperty
886// resource->SetValue1(lbox->GetSelectionMode());
887 int i;
888 if (lbox->Number() == 0)
889 resource->SetStringValues(NULL);
890 else
891 {
892 wxStringList *slist = new wxStringList;
893
894 for (i = 0; i < lbox->Number(); i++)
895 slist->Add(lbox->GetString(i));
896
897 resource->SetStringValues(slist);
898 }
899 return wxItemPropertyInfo::InstantiateResource(resource);
900}
901
902/*
903 * Choice item
904 */
905
906wxProperty *wxChoicePropertyInfo::GetProperty(wxString& name)
907{
908 wxChoice *choice = (wxChoice *)propertyWindow;
909 if (name == "values")
910 {
911 wxStringList *stringList = new wxStringList;
912 int i;
913 for (i = 0; i < choice->Number(); i++)
914 stringList->Add(choice->GetString(i));
915
916 return new wxProperty(name, stringList, "stringlist");
917 }
918 else
919 return wxItemPropertyInfo::GetProperty(name);
920}
921
922bool wxChoicePropertyInfo::SetProperty(wxString& name, wxProperty *property)
923{
924 wxChoice *choice = (wxChoice *)propertyWindow;
925 if (name == "values")
926 {
927 choice->Clear();
928 wxPropertyValue *expr = property->GetValue().GetFirst();
929 while (expr)
930 {
931 char *s = expr->StringValue();
932 if (s)
933 choice->Append(s);
934 expr = expr->GetNext();
935 }
936 if (choice->Number() > 0)
937 choice->SetSelection(0);
938 return TRUE;
939 }
940 else
941 return wxItemPropertyInfo::SetProperty(name, property);
942}
943
944void wxChoicePropertyInfo::GetPropertyNames(wxStringList& names)
945{
946 names.Add("values");
947 wxItemPropertyInfo::GetPropertyNames(names);
948}
949
950bool wxChoicePropertyInfo::InstantiateResource(wxItemResource *resource)
951{
952 wxChoice *choice = (wxChoice *)propertyWindow;
953 int i;
954 if (choice->Number() == 0)
955 resource->SetStringValues(NULL);
956 else
957 {
958 wxStringList *slist = new wxStringList;
959
960 for (i = 0; i < choice->Number(); i++)
961 slist->Add(choice->GetString(i));
962
963 resource->SetStringValues(slist);
964 }
965 return wxItemPropertyInfo::InstantiateResource(resource);
966}
967
968/*
969 * Radiobox item
970 */
971
972wxProperty *wxRadioBoxPropertyInfo::GetProperty(wxString& name)
973{
974 wxRadioBox *radioBox = (wxRadioBox *)propertyWindow;
975 if (name == "numberRowsOrCols")
976 {
977 return new wxProperty("numberRowsOrCols", (long)radioBox->GetNumberOfRowsOrCols(), "integer");
978 }
979 if (name == "orientation")
980 {
981 char *pos = NULL;
982 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
983 pos = "wxHORIZONTAL";
984 else
985 pos = "wxVERTICAL";
986
987 return new wxProperty("orientation", pos, "string",
988 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
989 NULL)));
990 }
991 else if (name == "values")
992 {
993 wxStringList *stringList = new wxStringList;
994 int i;
995 for (i = 0; i < radioBox->Number(); i++)
996 stringList->Add(radioBox->GetString(i));
997
998 return new wxProperty(name, stringList, "stringlist");
999 }
1000 return wxItemPropertyInfo::GetProperty(name);
1001}
1002
1003bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1004{
1005 wxRadioBox *radioBox = (wxRadioBox *)propertyWindow;
1006 if (name == "numberRowsOrCols")
1007 {
1008 radioBox->SetNumberOfRowsOrCols((int)property->GetValue().IntegerValue());
ae8351fc 1009 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
457814b5
JS
1010 return TRUE;
1011 }
1012 else if (name == "orientation")
1013 {
1014 long windowStyle = radioBox->GetWindowStyleFlag();
1015 wxString val(property->GetValue().StringValue());
1016 if (val == "wxHORIZONTAL")
1017 {
1018 if (windowStyle & wxVERTICAL)
1019 windowStyle -= wxVERTICAL;
1020 windowStyle |= wxHORIZONTAL;
1021 }
1022 else
1023 {
1024 if (windowStyle & wxHORIZONTAL)
1025 windowStyle -= wxHORIZONTAL;
1026 windowStyle |= wxVERTICAL;
1027 }
1028 radioBox->SetWindowStyleFlag(windowStyle);
1029
ae8351fc 1030 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
457814b5
JS
1031 return TRUE;
1032 }
1033 else if (name == "values")
1034 {
1035 // Set property into *resource*, not wxRadioBox, and then recreate
1036 // the wxRadioBox. This is because we can't dynamically set the strings
1037 // of a wxRadioBox.
ae8351fc 1038 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
457814b5
JS
1039 if (!resource)
1040 return FALSE;
1041
1042 wxStringList *stringList = resource->GetStringValues();
1043 if (!stringList)
1044 {
1045 stringList = new wxStringList;
1046 resource->SetStringValues(stringList);
1047 }
1048 stringList->Clear();
1049
1050 wxPropertyValue *expr = property->GetValue().GetFirst();
1051 while (expr)
1052 {
1053 char *s = expr->StringValue();
1054 if (s)
1055 stringList->Add(s);
1056 expr = expr->GetNext();
1057 }
ae8351fc 1058 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
457814b5
JS
1059 return TRUE;
1060 }
1061 return wxItemPropertyInfo::SetProperty(name, property);
1062}
1063
1064void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1065{
1066 names.Add("label");
1067 names.Add("values");
1068 names.Add("orientation");
1069 names.Add("numberRowsOrCols");
1070 wxItemPropertyInfo::GetPropertyNames(names);
1071}
1072
1073bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1074{
1075 wxRadioBox *rbox = (wxRadioBox *)propertyWindow;
1076 // Take strings from resource instead
1077/*
1078 int i;
1079 if (rbox->Number() == 0)
1080 resource->SetStringValues(NULL);
1081 else
1082 {
1083 wxStringList *slist = new wxStringList;
1084
1085 for (i = 0; i < rbox->Number(); i++)
1086 slist->Add(rbox->GetString(i));
1087
1088 resource->SetStringValues(slist);
1089 }
1090*/
1091 resource->SetValue1(rbox->GetNumberOfRowsOrCols());
1092 return wxItemPropertyInfo::InstantiateResource(resource);
1093}
1094
1095/*
1096 * Groupbox item
1097 */
1098
1099wxProperty *wxGroupBoxPropertyInfo::GetProperty(wxString& name)
1100{
1101 wxStaticBox *groupBox = (wxStaticBox *)propertyWindow;
1102 return wxItemPropertyInfo::GetProperty(name);
1103}
1104
1105bool wxGroupBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1106{
1107 return wxItemPropertyInfo::SetProperty(name, property);
1108}
1109
1110void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1111{
1112 names.Add("label");
1113 wxItemPropertyInfo::GetPropertyNames(names);
1114}
1115
1116bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1117{
1118 wxStaticBox *gbox = (wxStaticBox *)propertyWindow;
1119 return wxItemPropertyInfo::InstantiateResource(resource);
1120}
1121
1122/*
1123 * Checkbox item
1124 */
1125
1126wxProperty *wxCheckBoxPropertyInfo::GetProperty(wxString& name)
1127{
1128 wxCheckBox *checkBox = (wxCheckBox *)propertyWindow;
1129 if (name == "value")
1130 return new wxProperty("value", checkBox->GetValue(), "bool");
1131 else
1132 return wxItemPropertyInfo::GetProperty(name);
1133}
1134
1135bool wxCheckBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1136{
1137 wxCheckBox *checkBox = (wxCheckBox *)propertyWindow;
1138 if (name == "value")
1139 {
1140 checkBox->SetValue((bool)property->GetValue().BoolValue());
1141 return TRUE;
1142 }
1143 else
1144 return wxItemPropertyInfo::SetProperty(name, property);
1145}
1146
1147void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1148{
1149 names.Add("label");
1150 names.Add("value");
1151 wxItemPropertyInfo::GetPropertyNames(names);
1152}
1153
1154bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1155{
1156 wxCheckBox *cbox = (wxCheckBox *)propertyWindow;
1157 resource->SetValue1(cbox->GetValue());
1158 return wxItemPropertyInfo::InstantiateResource(resource);
1159}
1160
03f68f12
JS
1161/*
1162 * Radiobutton item
1163 */
1164
1165wxProperty *wxRadioButtonPropertyInfo::GetProperty(wxString& name)
1166{
1167 wxRadioButton *checkBox = (wxRadioButton *)propertyWindow;
1168 if (name == "value")
1169 return new wxProperty("value", checkBox->GetValue(), "bool");
1170 else
1171 return wxItemPropertyInfo::GetProperty(name);
1172}
1173
1174bool wxRadioButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1175{
1176 wxRadioButton *checkBox = (wxRadioButton *)propertyWindow;
1177 if (name == "value")
1178 {
1179 checkBox->SetValue((bool)property->GetValue().BoolValue());
1180 return TRUE;
1181 }
1182 else
1183 return wxItemPropertyInfo::SetProperty(name, property);
1184}
1185
1186void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList& names)
1187{
1188 names.Add("label");
1189 names.Add("value");
1190 wxItemPropertyInfo::GetPropertyNames(names);
1191}
1192
1193bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
1194{
1195 wxRadioButton *cbox = (wxRadioButton *)propertyWindow;
1196 resource->SetValue1(cbox->GetValue());
1197 return wxItemPropertyInfo::InstantiateResource(resource);
1198}
1199
457814b5
JS
1200/*
1201 * Slider item
1202 */
1203
1204wxProperty *wxSliderPropertyInfo::GetProperty(wxString& name)
1205{
1206 wxSlider *slider = (wxSlider *)propertyWindow;
1207 if (name == "value")
1208 return new wxProperty("value", (long)slider->GetValue(), "integer");
1209 else if (name == "orientation")
1210 {
1211 char *pos = NULL;
1212 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1213 pos = "wxHORIZONTAL";
1214 else
1215 pos = "wxVERTICAL";
1216
1217 return new wxProperty("orientation", pos, "string",
1218 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1219 NULL)));
1220 }
1221 else if (name == "min_value")
1222 return new wxProperty("min_value", (long)slider->GetMin(), "integer");
1223 else if (name == "max_value")
1224 return new wxProperty("max_value", (long)slider->GetMax(), "integer");
1225 else
1226 return wxItemPropertyInfo::GetProperty(name);
1227}
1228
1229bool wxSliderPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1230{
1231 wxSlider *slider = (wxSlider *)propertyWindow;
1232 if (name == "value")
1233 {
1234 slider->SetValue((int)property->GetValue().IntegerValue());
1235 return TRUE;
1236 }
1237 else if (name == "orientation")
1238 {
1239 long windowStyle = slider->GetWindowStyleFlag();
1240 long oldWindowStyle = windowStyle;
1241 wxString val(property->GetValue().StringValue());
1242 if (val == "wxHORIZONTAL")
1243 {
1244 if (windowStyle & wxVERTICAL)
1245 windowStyle -= wxVERTICAL;
1246 windowStyle |= wxHORIZONTAL;
1247 }
1248 else
1249 {
1250 if (windowStyle & wxHORIZONTAL)
1251 windowStyle -= wxHORIZONTAL;
1252 windowStyle |= wxVERTICAL;
1253 }
1254
1255 if (oldWindowStyle == windowStyle)
1256 return TRUE;
1257
1258 slider->SetWindowStyleFlag(windowStyle);
1259
1260 // If the window style has changed, we swap the width and height parameters.
1261 int w, h;
1262 slider->GetSize(&w, &h);
1263
ae8351fc 1264 slider = (wxSlider *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider, this);
457814b5
JS
1265 slider->SetSize(-1, -1, h, w);
1266
1267 return TRUE;
1268 }
1269 else if (name == "min_value")
1270 {
1271 slider->SetRange((int)property->GetValue().IntegerValue(), slider->GetMax());
1272 return TRUE;
1273 }
1274 else if (name == "max_value")
1275 {
1276 slider->SetRange(slider->GetMin(), (int)property->GetValue().IntegerValue());
1277 return TRUE;
1278 }
1279 else
1280 return wxItemPropertyInfo::SetProperty(name, property);
1281}
1282
1283void wxSliderPropertyInfo::GetPropertyNames(wxStringList& names)
1284{
1285 names.Add("value");
1286 names.Add("orientation");
1287 names.Add("min_value");
1288 names.Add("max_value");
1289 wxItemPropertyInfo::GetPropertyNames(names);
1290}
1291
1292bool wxSliderPropertyInfo::InstantiateResource(wxItemResource *resource)
1293{
1294 wxSlider *slider = (wxSlider *)propertyWindow;
1295 resource->SetValue1(slider->GetValue());
1296 resource->SetValue2(slider->GetMin());
1297 resource->SetValue3(slider->GetMax());
1298 return wxItemPropertyInfo::InstantiateResource(resource);
1299}
1300
1301/*
1302 * Gauge item
1303 */
1304
1305wxProperty *wxGaugePropertyInfo::GetProperty(wxString& name)
1306{
1307 wxGauge *gauge = (wxGauge *)propertyWindow;
1308 if (name == "value")
1309 return new wxProperty("value", (long)gauge->GetValue(), "integer");
1310 else if (name == "max_value")
1311 return new wxProperty("max_value", (long)gauge->GetRange(), "integer");
1312 else
1313 return wxItemPropertyInfo::GetProperty(name);
1314}
1315
1316bool wxGaugePropertyInfo::SetProperty(wxString& name, wxProperty *property)
1317{
1318 wxGauge *gauge = (wxGauge *)propertyWindow;
1319 if (name == "value")
1320 {
1321 gauge->SetValue((int)property->GetValue().IntegerValue());
1322 return TRUE;
1323 }
1324 else if (name == "max_value")
1325 {
1326 gauge->SetRange((int)property->GetValue().IntegerValue());
1327 return TRUE;
1328 }
1329 else
1330 return wxItemPropertyInfo::SetProperty(name, property);
1331}
1332
1333void wxGaugePropertyInfo::GetPropertyNames(wxStringList& names)
1334{
1335 names.Add("value");
1336 names.Add("max_value");
1337 wxItemPropertyInfo::GetPropertyNames(names);
1338}
1339
1340bool wxGaugePropertyInfo::InstantiateResource(wxItemResource *resource)
1341{
1342 wxGauge *gauge = (wxGauge *)propertyWindow;
1343 resource->SetValue1(gauge->GetValue());
1344 resource->SetValue2(gauge->GetRange());
1345 return wxItemPropertyInfo::InstantiateResource(resource);
1346}
1347
1348/*
1349 * Scrollbar item
1350 */
1351
1352wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name)
1353{
1354 wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow;
1355 if (name == "value")
1356 return new wxProperty("value", (long)scrollBar->GetValue(), "integer");
1357 else if (name == "orientation")
1358 {
1359 char *pos = NULL;
1360 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1361 pos = "wxHORIZONTAL";
1362 else
1363 pos = "wxVERTICAL";
1364
1365 return new wxProperty("orientation", pos, "string",
1366 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1367 NULL)));
1368 }
1369 else if (name == "pageSize")
1370 {
1371 int viewStart, pageLength, objectLength, viewLength;
1372 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1373
1374 return new wxProperty("pageSize", (long)pageLength, "integer");
1375 }
1376 else if (name == "viewLength")
1377 {
1378 int viewStart, pageLength, objectLength, viewLength;
1379 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1380
1381 return new wxProperty("viewLength", (long)viewLength, "integer");
1382 }
1383 else if (name == "objectLength")
1384 {
1385 int viewStart, pageLength, objectLength, viewLength;
1386 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1387
1388 return new wxProperty("objectLength", (long)objectLength, "integer");
1389 }
1390 else
1391 return wxItemPropertyInfo::GetProperty(name);
1392}
1393
1394bool wxScrollBarPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1395{
1396 wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow;
1397 if (name == "value")
1398 {
1399 scrollBar->SetValue((int)property->GetValue().IntegerValue());
1400 return TRUE;
1401 }
1402 else if (name == "orientation")
1403 {
1404 long windowStyle = scrollBar->GetWindowStyleFlag();
1405 long oldWindowStyle = windowStyle;
1406 wxString val(property->GetValue().StringValue());
1407 if (val == "wxHORIZONTAL")
1408 {
1409 if (windowStyle & wxVERTICAL)
1410 windowStyle -= wxVERTICAL;
1411 windowStyle |= wxHORIZONTAL;
1412 }
1413 else
1414 {
1415 if (windowStyle & wxHORIZONTAL)
1416 windowStyle -= wxHORIZONTAL;
1417 windowStyle |= wxVERTICAL;
1418 }
1419
1420 if (oldWindowStyle == windowStyle)
1421 return TRUE;
1422
1423 scrollBar->SetWindowStyleFlag(windowStyle);
1424
1425 // If the window style has changed, we swap the width and height parameters.
1426 int w, h;
1427 scrollBar->GetSize(&w, &h);
1428
ae8351fc 1429 scrollBar = (wxScrollBar *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar, this);
457814b5
JS
1430 scrollBar->SetSize(-1, -1, h, w);
1431
1432 return TRUE;
1433 }
1434 else if (name == "pageSize")
1435 {
1436 scrollBar->SetPageSize((int)property->GetValue().IntegerValue());
1437 return TRUE;
1438 }
1439 else if (name == "viewLength")
1440 {
1441 scrollBar->SetViewLength((int)property->GetValue().IntegerValue());
1442 return TRUE;
1443 }
1444 else if (name == "objectLength")
1445 {
1446 scrollBar->SetObjectLength((int)property->GetValue().IntegerValue());
1447 return TRUE;
1448 }
1449 else
1450 return wxItemPropertyInfo::SetProperty(name, property);
1451}
1452
1453void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList& names)
1454{
1455 names.Add("orientation");
1456 names.Add("value");
1457 names.Add("pageSize");
1458 names.Add("viewLength");
1459 names.Add("objectLength");
1460 wxItemPropertyInfo::GetPropertyNames(names);
1461
1462 // Remove some properties we don't inherit
1463 names.Delete("fontPoints");
1464 names.Delete("fontFamily");
1465 names.Delete("fontStyle");
1466 names.Delete("fontWeight");
1467 names.Delete("fontUnderlined");
1468}
1469
1470bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource *resource)
1471{
1472 wxScrollBar *sbar = (wxScrollBar *)propertyWindow;
1473
1474 resource->SetValue1(sbar->GetValue());
1475
1476 int viewStart, pageLength, objectLength, viewLength;
1477 sbar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1478
1479 resource->SetValue2(pageLength);
1480 resource->SetValue3(objectLength);
1481 resource->SetValue5(viewLength);
1482
1483 return wxItemPropertyInfo::InstantiateResource(resource);
1484}
1485
1486/*
1487 * Panels
1488 */
1489
1490wxProperty *wxPanelPropertyInfo::GetProperty(wxString& name)
1491{
1492 wxPanel *panelWindow = (wxPanel *)propertyWindow;
1493 wxFont *labelFont = panelWindow->GetLabelFont();
1494 wxFont *buttonFont = panelWindow->GetButtonFont();
1495
1496 if (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" ||
1497 name == "labelFontUnderlined")
1498 return GetFontProperty(name, labelFont);
1499 else if (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" ||
1500 name == "buttonFontUnderlined")
1501 return GetFontProperty(name, buttonFont);
ae8351fc 1502 else if (name == "no3D")
457814b5
JS
1503 {
1504 bool userColours;
ae8351fc 1505 if (panelWindow->GetWindowStyleFlag() & wxNO_3D)
457814b5
JS
1506 userColours = TRUE;
1507 else
1508 userColours = FALSE;
1509
1510 return new wxProperty(name, (bool)userColours, "bool");
1511 }
1512 else if (name == "backgroundColour")
1513 {
1514 wxColour col(panelWindow->GetBackgroundColour());
1515 char buf[7];
1516 wxDecToHex(col.Red(), buf);
1517 wxDecToHex(col.Green(), buf+2);
1518 wxDecToHex(col.Blue(), buf+4);
1519
1520 return new wxProperty(name, buf, "string", new wxColourListValidator);
1521 }
ae8351fc
JS
1522 else if (name == "title")
1523 {
1524 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1525 if (resource)
1526 return new wxProperty(name, resource->GetTitle(), "string");
1527 else
1528 return new wxProperty(name, "Could not get title", "string");
1529 }
457814b5
JS
1530 else
1531 return wxWindowPropertyInfo::GetProperty(name);
1532}
1533
1534bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1535{
1536 wxPanel *panelWindow = (wxPanel *)propertyWindow;
1537 wxFont *labelFont = panelWindow->GetLabelFont();
1538 wxFont *buttonFont = panelWindow->GetButtonFont();
1539
1540 if (labelFont && (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" || name == "labelFontUnderlined" ))
1541 {
1542 wxFont *newFont = SetFontProperty(name, property, labelFont);
1543 if (newFont)
1544 panelWindow->SetLabelFont(newFont);
1545 return TRUE;
1546 }
1547 else if (buttonFont && (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" || name == "buttonFontUnderlined" ))
1548 {
1549 wxFont *newFont = SetFontProperty(name, property, buttonFont);
1550 if (newFont)
1551 panelWindow->SetButtonFont(newFont);
1552 return TRUE;
1553 }
ae8351fc 1554 else if (name == "no3D")
457814b5
JS
1555 {
1556 bool userColours = property->GetValue().BoolValue();
1557 long flag = panelWindow->GetWindowStyleFlag();
1558
1559 if (userColours)
1560 {
ae8351fc
JS
1561 if ((panelWindow->GetWindowStyleFlag() & wxNO_3D) != wxNO_3D)
1562 panelWindow->SetWindowStyleFlag(panelWindow->GetWindowStyleFlag() | wxNO_3D);
457814b5
JS
1563 }
1564 else
1565 {
ae8351fc
JS
1566 if ((panelWindow->GetWindowStyleFlag() & wxNO_3D) == wxNO_3D)
1567 panelWindow->SetWindowStyleFlag(panelWindow->GetWindowStyleFlag() - wxNO_3D);
457814b5 1568 }
ae8351fc 1569 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
457814b5
JS
1570 resource->SetStyle(panelWindow->GetWindowStyleFlag());
1571
ae8351fc 1572 panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this);
457814b5
JS
1573 return TRUE;
1574 }
1575 else if (name == "backgroundColour")
1576 {
1577 char *hex = property->GetValue().StringValue();
1578 int r = wxHexToDec(hex);
1579 int g = wxHexToDec(hex+2);
1580 int b = wxHexToDec(hex+4);
1581
1582 wxColour col(r,g,b);
1583 panelWindow->SetBackgroundColour(col);
ae8351fc 1584 panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this);
457814b5
JS
1585 return TRUE;
1586 }
ae8351fc
JS
1587 else if (name == "title")
1588 {
1589 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1590 if (resource)
1591 {
1592 resource->SetTitle(property->GetValue().StringValue());
1593 return TRUE;
1594 }
1595 else
1596 return FALSE;
1597 }
457814b5
JS
1598 else
1599 return wxWindowPropertyInfo::SetProperty(name, property);
1600}
1601
1602void wxPanelPropertyInfo::GetPropertyNames(wxStringList& names)
1603{
1604 wxWindowPropertyInfo::GetPropertyNames(names);
1605
ae8351fc
JS
1606 names.Add("title");
1607 names.Add("no3D");
457814b5
JS
1608 names.Add("backgroundColour");
1609}
1610
1611bool wxPanelPropertyInfo::InstantiateResource(wxItemResource *resource)
1612{
1613 wxPanel *panel = (wxPanel *)propertyWindow;
1614 if (panel->GetFont())
1615 resource->SetFont(wxTheFontList->FindOrCreateFont(panel->GetFont()->GetPointSize(),
1616 panel->GetFont()->GetFamily(), panel->GetFont()->GetStyle(), panel->GetFont()->GetWeight(),
1617 panel->GetFont()->GetUnderlined(), panel->GetFont()->GetFaceName()));
1618
1619 resource->SetBackgroundColour(new wxColour(panel->GetBackgroundColour()));
1620
1621 return wxWindowPropertyInfo::InstantiateResource(resource);
1622}
1623
ae8351fc 1624#if 0
457814b5
JS
1625/*
1626 * Dialog boxes
1627 */
1628
1629wxProperty *wxDialogPropertyInfo::GetProperty(wxString& name)
1630{
1631 wxDialog *dialogWindow = (wxDialog *)propertyWindow;
1632 if (name == "modal")
1633 {
ae8351fc 1634 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow);
457814b5
JS
1635 if (!resource)
1636 return NULL;
1637
1638 bool modal = (resource->GetValue1() != 0);
1639 return new wxProperty(name, modal, "bool");
1640 }
1641 else
1642 return wxPanelPropertyInfo::GetProperty(name);
1643}
1644
1645bool wxDialogPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1646{
1647 wxDialog *dialogWindow = (wxDialog *)propertyWindow;
1648
1649 if (name == "modal")
1650 {
ae8351fc 1651 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow);
457814b5
JS
1652 if (!resource)
1653 return FALSE;
1654
1655 resource->SetValue1(property->GetValue().BoolValue());
1656 return TRUE;
1657 }
1658 else
1659 return wxPanelPropertyInfo::SetProperty(name, property);
1660}
1661
1662void wxDialogPropertyInfo::GetPropertyNames(wxStringList& names)
1663{
1664 names.Add("title");
1665 names.Add("modal");
1666
1667 wxPanelPropertyInfo::GetPropertyNames(names);
1668}
1669
1670bool wxDialogPropertyInfo::InstantiateResource(wxItemResource *resource)
1671{
1672 wxDialog *dialog = (wxDialog *)propertyWindow;
1673 wxString str(dialog->GetTitle());
1674 resource->SetTitle(WXSTRINGCAST str);
1675
1676 return wxPanelPropertyInfo::InstantiateResource(resource);
1677}
ae8351fc 1678#endif
457814b5
JS
1679
1680/*
1681 * Utilities
1682 */
1683
1684int wxStringToFontWeight(wxString& val)
1685{
1686 if (val == "wxBOLD") return wxBOLD;
1687 else if (val == "wxLIGHT") return wxLIGHT;
1688 else return wxNORMAL;
1689}
1690
1691int wxStringToFontStyle(wxString& val)
1692{
1693 if (val == "wxITALIC") return wxITALIC;
1694 else if (val == "wxSLANT") return wxSLANT;
1695 else return wxNORMAL;
1696}
1697
1698int wxStringToFontFamily(wxString& val)
1699{
1700 if (val == "wxDECORATIVE") return wxDECORATIVE;
1701 else if (val == "wxROMAN") return wxROMAN;
1702 else if (val == "wxSCRIPT") return wxSCRIPT;
1703 else if (val == "wxMODERN") return wxMODERN;
1704 else if (val == "wxTELETYPE") return wxTELETYPE;
1705 else return wxSWISS;
1706}
03f68f12
JS
1707
1708///
1709/// Resource symbol validator
1710///
1711IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator, wxPropertyListValidator)
1712
1713wxResourceSymbolValidator::wxResourceSymbolValidator(long flags):
1714 wxPropertyListValidator(flags)
1715{
1716}
1717
1718wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
1719{
1720}
1721
1722bool wxResourceSymbolValidator::OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1723{
1724 return TRUE;
1725}
1726
1727// Called when TICK is pressed or focus is lost or view wants to update
1728// the property list.
1729// Does the transferance from the property editing area to the property itself
1730bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1731{
1732 if (!view->GetValueText())
1733 return FALSE;
1734 wxString value(view->GetValueText()->GetValue());
1735 property->GetValue() = value ;
1736 return TRUE;
1737}
1738
1739// Called when TICK is pressed or focus is lost or view wants to update
1740// the property list.
1741// Does the transferance from the property editing area to the property itself
1742bool wxResourceSymbolValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1743{
1744 if (!view->GetValueText())
1745 return FALSE;
1746 wxString str(property->GetValue().GetStringRepresentation());
1747 view->GetValueText()->SetValue(str);
1748 return TRUE;
1749}
1750
1751// Called when the property is double clicked. Extra functionality can be provided,
1752// cycling through possible values.
1753bool wxResourceSymbolValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1754{
1755 if (!view->GetValueText())
1756 return FALSE;
1757 OnEdit(property, view, parentWindow);
1758 return TRUE;
1759}
1760
1761bool wxResourceSymbolValidator::OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1762{
1763 if (view->GetConfirmButton())
1764 view->GetConfirmButton()->Enable(TRUE);
1765 if (view->GetCancelButton())
1766 view->GetCancelButton()->Enable(TRUE);
1767 if (view->GetEditButton())
1768 view->GetEditButton()->Enable(TRUE);
1769 if (view->GetValueText())
1770 view->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == wxPROP_ALLOW_TEXT_EDITING);
1771 return TRUE;
1772}
1773
1774void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1775{
1776 if (!view->GetValueText())
1777 return;
1778
1779 wxResourceSymbolDialog* dialog = new wxResourceSymbolDialog(parentWindow, -1, "Edit Symbol");
1780
1781 dialog->SetSymbol(property->GetValue().StringValue());
1782
1783 // TODO: split name/id pair e.g. "IDC_TEXT=123" or get from symbol table - which?
1784 dialog->SetId(1234);
1785
1786 dialog->Init();
1787
1788 if (dialog->ShowModal())
1789 {
1790 wxString symbolName(dialog->GetSymbol());
1791 long id = dialog->GetId();
1792 dialog->Destroy();
1793
1794 // TODO: set id somewhere
1795 property->GetValue() = wxString(symbolName);
1796
1797 view->DisplayProperty(property);
1798 view->UpdatePropertyDisplayInList(property);
1799 view->OnPropertyChanged(property);
1800 }
1801
1802#if 0
1803 char *s = wxFileSelector(
1804 filenameMessage.GetData(),
1805 wxPathOnly(property->GetValue().StringValue()),
1806 wxFileNameFromPath(property->GetValue().StringValue()),
1807 NULL,
1808 filenameWildCard.GetData(),
1809 0,
1810 parentWindow);
1811 if (s)
1812 {
1813 property->GetValue() = wxString(s);
1814 view->DisplayProperty(property);
1815 view->UpdatePropertyDisplayInList(property);
1816 view->OnPropertyChanged(property);
1817 }
1818#endif
1819}
1820
1821BEGIN_EVENT_TABLE(wxResourceSymbolDialog, wxDialog)
1822 EVT_BUTTON(wxID_OK, wxResourceSymbolDialog::OnOK)
1823END_EVENT_TABLE()
1824
1825wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow* parent, const wxWindowID id, const wxString& title, const wxPoint& pos,
1826 const wxSize& size, long style):
1827 wxDialog(parent, id, title, pos, size, style)
1828{
1829 int x = 5;
1830 int y = 5;
1831
1832 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x, y));
1833
1834 x += 80;
1835
1836 m_nameCtrl = new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX, "",
1837 wxPoint(x, y), wxSize(200, -1), 0, NULL, wxCB_DROPDOWN);
1838
1839 y += 30;
1840 x = 5;
1841
1842 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x, y));
1843
1844 x += 80;
1845
1846 m_idCtrl = new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL, "",
1847 wxPoint(x, y), wxSize(200, -1));
1848
1849 y += 30;
1850 x = 5;
1851 (void) new wxButton(this, wxID_OK, "OK", wxPoint(x, y), wxSize(90, -1));
1852
1853 x += 120;
1854 (void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(x, y), wxSize(90, -1));
1855
1856 Fit();
1857 Centre();
1858}
1859
1860void wxResourceSymbolDialog::Init()
1861{
1862 wxString defaultId;
1863 defaultId.Printf("%ld", m_symbolId);
1864
1865 m_nameCtrl->SetValue(m_symbolName);
1866 m_idCtrl->SetValue(defaultId);
1867}
1868
1869void wxResourceSymbolDialog::OnOK(wxCommandEvent& event)
1870{
1871 if (CheckValues())
1872 {
1873 wxDialog::OnOK(event);
1874 }
1875}
1876
1877bool wxResourceSymbolDialog::CheckValues()
1878{
1879 return TRUE;
1880}
1881