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