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