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