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