]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: reseditr.cpp | |
3 | // Purpose: Resource editor class | |
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 "reseditr.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 | ||
26 | #include "wx/checkbox.h" | |
27 | #include "wx/button.h" | |
28 | #include "wx/choice.h" | |
29 | #include "wx/listbox.h" | |
30 | #include "wx/radiobox.h" | |
31 | #include "wx/statbox.h" | |
32 | #include "wx/gauge.h" | |
33 | #include "wx/slider.h" | |
34 | #include "wx/textctrl.h" | |
b127f301 RR |
35 | #include "wx/menu.h" |
36 | #include "wx/toolbar.h" | |
457814b5 JS |
37 | #endif |
38 | ||
39 | #include "wx/scrolbar.h" | |
560b92f5 | 40 | #include "wx/config.h" |
f6bcfd97 BP |
41 | #include "wx/dir.h" |
42 | #include "wx/progdlg.h" | |
457814b5 JS |
43 | |
44 | #include <ctype.h> | |
45 | #include <stdlib.h> | |
46 | #include <math.h> | |
47 | #include <string.h> | |
48 | ||
d0fff5cb | 49 | #ifdef __WXMSW__ |
457814b5 | 50 | #include "wx/help.h" |
b127f301 | 51 | #endif |
457814b5 JS |
52 | |
53 | #include "reseditr.h" | |
54 | #include "winprop.h" | |
457814b5 | 55 | #include "dlghndlr.h" |
ae8351fc JS |
56 | #include "edtree.h" |
57 | #include "edlist.h" | |
457814b5 | 58 | |
ae8351fc | 59 | wxResourceManager *wxResourceManager::sm_currentResourceManager = NULL; |
457814b5 | 60 | |
5e998a33 | 61 | #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) |
b127f301 RR |
62 | #include "bitmaps/load.xpm" |
63 | #include "bitmaps/save.xpm" | |
64 | #include "bitmaps/new.xpm" | |
d5c462fd RR |
65 | #include "bitmaps/vert.xpm" |
66 | #include "bitmaps/alignt.xpm" | |
67 | #include "bitmaps/alignb.xpm" | |
68 | #include "bitmaps/horiz.xpm" | |
69 | #include "bitmaps/alignl.xpm" | |
70 | #include "bitmaps/alignr.xpm" | |
71 | #include "bitmaps/copysize.xpm" | |
72 | #include "bitmaps/tofront.xpm" | |
73 | #include "bitmaps/toback.xpm" | |
74 | #include "bitmaps/help.xpm" | |
75 | #include "bitmaps/wxwin.xpm" | |
f6bcfd97 BP |
76 | #include "bitmaps/distvert.xpm" |
77 | #include "bitmaps/disthor.xpm" | |
78 | #include "bitmaps/copywdth.xpm" | |
79 | #include "bitmaps/copyhght.xpm" | |
b46e8696 RR |
80 | |
81 | #include "bitmaps/dialog.xpm" | |
82 | #include "bitmaps/folder1.xpm" | |
83 | #include "bitmaps/folder2.xpm" | |
84 | #include "bitmaps/buttonsm.xpm" | |
457814b5 JS |
85 | #endif |
86 | ||
87 | /* | |
f6bcfd97 BP |
88 | * Resource manager |
89 | */ | |
457814b5 | 90 | |
ae8351fc | 91 | wxResourceManager::wxResourceManager(): |
f6bcfd97 BP |
92 | m_imageList(16, 16, TRUE) |
93 | { | |
94 | sm_currentResourceManager = this; | |
95 | m_editorFrame = NULL; | |
96 | m_editorPanel = NULL; | |
97 | m_popupMenu = NULL; | |
98 | m_editorResourceTree = NULL; | |
99 | m_editorControlList = NULL; | |
100 | m_nameCounter = 1; | |
101 | m_symbolIdCounter = 99; | |
102 | m_modified = FALSE; | |
103 | m_currentFilename = ""; | |
104 | m_symbolFilename = ""; | |
105 | m_editorToolBar = NULL; | |
106 | ||
107 | // Default window positions | |
108 | m_resourceEditorWindowSize.width = 500; | |
109 | m_resourceEditorWindowSize.height = 450; | |
110 | ||
111 | m_resourceEditorWindowSize.x = 0; | |
112 | m_resourceEditorWindowSize.y = 0; | |
113 | ||
114 | m_propertyWindowSize.width = 300; | |
115 | m_propertyWindowSize.height = 300; | |
116 | ||
d0fff5cb | 117 | #ifdef __WXMSW__ |
f6bcfd97 | 118 | m_helpController = NULL; |
b127f301 | 119 | #endif |
f6bcfd97 BP |
120 | |
121 | m_bitmapImage = NULL; | |
122 | m_rootDialogItem = 0; | |
457814b5 JS |
123 | } |
124 | ||
ae8351fc | 125 | wxResourceManager::~wxResourceManager() |
457814b5 | 126 | { |
f6bcfd97 BP |
127 | sm_currentResourceManager = NULL; |
128 | SaveOptions(); | |
129 | ||
d0fff5cb | 130 | #ifdef __WXMSW__ |
f6bcfd97 BP |
131 | if (m_helpController) |
132 | { | |
133 | m_helpController->Quit(); | |
134 | delete m_helpController; | |
135 | m_helpController = NULL; | |
136 | } | |
b127f301 | 137 | #endif |
f6bcfd97 BP |
138 | |
139 | delete m_bitmapImage; | |
140 | delete m_popupMenu; | |
457814b5 JS |
141 | } |
142 | ||
ae8351fc | 143 | bool wxResourceManager::Initialize() |
457814b5 | 144 | { |
f6bcfd97 BP |
145 | // Set up the resource filename for each platform. |
146 | // TODO: This shold be replaced by wxConfig usage. | |
2049ba38 | 147 | #ifdef __WXMSW__ |
f6bcfd97 BP |
148 | // dialoged.ini in the Windows directory |
149 | wxString windowsDir = wxGetOSDirectory(); | |
150 | windowsDir += "\\dialoged.ini" ; | |
151 | ||
152 | m_optionsResourceFilename = windowsDir; | |
a132a1c8 | 153 | #elif defined(__WXGTK__) || defined(__WXMOTIF__) || (defined(__WXMAC__) && defined(__DARWIN__)) |
f6bcfd97 BP |
154 | wxGetHomeDir( &m_optionsResourceFilename ); |
155 | m_optionsResourceFilename += "/.dialogedrc"; | |
457814b5 JS |
156 | #else |
157 | #error "Unsupported platform." | |
158 | #endif | |
f6bcfd97 BP |
159 | |
160 | LoadOptions(); | |
161 | ||
d0fff5cb | 162 | #ifdef __WXMSW__ |
f6bcfd97 BP |
163 | m_helpController = new wxHelpController; |
164 | m_helpController->Initialize("dialoged"); | |
b127f301 | 165 | #endif |
f6bcfd97 BP |
166 | |
167 | m_popupMenu = new wxMenu; | |
58d5bf3a GT |
168 | m_popupMenu->Append(OBJECT_MENU_TITLE, "WIDGET TYPE"); |
169 | m_popupMenu->AppendSeparator(); | |
f6bcfd97 BP |
170 | m_popupMenu->Append(OBJECT_MENU_EDIT, "Edit properties"); |
171 | m_popupMenu->Append(OBJECT_MENU_DELETE, "Delete object"); | |
172 | ||
173 | if (!m_bitmapImage) | |
174 | { | |
2049ba38 | 175 | #ifdef __WXMSW__ |
f6bcfd97 | 176 | m_bitmapImage = new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE); |
457814b5 | 177 | #endif |
5aa5c1e4 | 178 | #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) |
f6bcfd97 | 179 | m_bitmapImage = new wxBitmap( wxwin_xpm ); |
457814b5 | 180 | #endif |
f6bcfd97 BP |
181 | } |
182 | ||
183 | // Initialize the image list icons | |
2049ba38 | 184 | #ifdef __WXMSW__ |
f6bcfd97 BP |
185 | wxIcon icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16); |
186 | wxIcon icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16); | |
187 | wxIcon icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16); | |
188 | wxIcon icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16); | |
b46e8696 | 189 | #else |
f6bcfd97 BP |
190 | wxIcon icon1( dialog_xpm ); |
191 | wxIcon icon2( folder1_xpm ); | |
192 | wxIcon icon3( folder2_xpm ); | |
193 | wxIcon icon4( buttonsm_xpm ); | |
b46e8696 | 194 | #endif |
f6bcfd97 BP |
195 | m_imageList.Add(icon1); |
196 | m_imageList.Add(icon2); | |
197 | m_imageList.Add(icon3); | |
198 | m_imageList.Add(icon4); | |
199 | ||
200 | m_symbolTable.AddStandardSymbols(); | |
201 | ||
202 | return TRUE; | |
457814b5 JS |
203 | } |
204 | ||
ae8351fc | 205 | bool wxResourceManager::LoadOptions() |
457814b5 | 206 | { |
f6bcfd97 BP |
207 | wxConfig config("DialogEd", "wxWindows"); |
208 | ||
209 | config.Read("editorWindowX", &m_resourceEditorWindowSize.x); | |
210 | config.Read("editorWindowY", &m_resourceEditorWindowSize.y); | |
211 | config.Read("editorWindowWidth", &m_resourceEditorWindowSize.width); | |
212 | config.Read("editorWindowHeight", &m_resourceEditorWindowSize.height); | |
213 | config.Read("propertyWindowX", &m_propertyWindowSize.x); | |
214 | config.Read("propertyWindowY", &m_propertyWindowSize.y); | |
215 | config.Read("propertyWindowWidth", &m_propertyWindowSize.width); | |
216 | config.Read("propertyWindowHeight", &m_propertyWindowSize.height); | |
217 | ||
218 | return TRUE; | |
457814b5 JS |
219 | } |
220 | ||
ae8351fc | 221 | bool wxResourceManager::SaveOptions() |
457814b5 | 222 | { |
f6bcfd97 BP |
223 | wxConfig config("DialogEd", "wxWindows"); |
224 | ||
225 | config.Write("editorWindowX", (long) m_resourceEditorWindowSize.x); | |
226 | config.Write("editorWindowY", (long) m_resourceEditorWindowSize.y); | |
227 | config.Write("editorWindowWidth", (long) m_resourceEditorWindowSize.width); | |
228 | config.Write("editorWindowHeight", (long) m_resourceEditorWindowSize.height); | |
229 | config.Write("propertyWindowX", (long) m_propertyWindowSize.x); | |
230 | config.Write("propertyWindowY", (long) m_propertyWindowSize.y); | |
231 | config.Write("propertyWindowWidth", (long) m_propertyWindowSize.width); | |
232 | config.Write("propertyWindowHeight", (long) m_propertyWindowSize.height); | |
233 | ||
234 | return TRUE; | |
457814b5 JS |
235 | } |
236 | ||
237 | // Show or hide the resource editor frame, which displays a list | |
238 | // of resources with ability to edit them. | |
b127f301 | 239 | bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *WXUNUSED(parent), const char *title) |
457814b5 | 240 | { |
f6bcfd97 | 241 | if (show) |
457814b5 | 242 | { |
f6bcfd97 BP |
243 | if (m_editorFrame) |
244 | { | |
245 | m_editorFrame->Iconize(FALSE); | |
246 | m_editorFrame->Show(TRUE); | |
247 | return TRUE; | |
248 | } | |
249 | m_editorFrame = OnCreateEditorFrame(title); | |
250 | SetFrameTitle(""); | |
251 | wxMenuBar *menuBar = OnCreateEditorMenuBar(m_editorFrame); | |
252 | m_editorFrame->SetMenuBar(menuBar); | |
253 | ||
254 | m_editorToolBar = (EditorToolBar *)OnCreateToolBar(m_editorFrame); | |
255 | m_editorControlList = new wxResourceEditorControlList(m_editorFrame, IDC_LISTCTRL, wxPoint(0, 0), wxSize(-1, -1)); | |
256 | m_editorResourceTree = new wxResourceEditorProjectTree(m_editorFrame, IDC_TREECTRL, wxPoint(0, 0), wxSize(-1, -1), | |
257 | wxTR_HAS_BUTTONS); | |
258 | m_editorPanel = OnCreateEditorPanel(m_editorFrame); | |
259 | ||
260 | m_editorResourceTree->SetImageList(& m_imageList); | |
261 | ||
262 | // Constraints for toolbar | |
263 | wxLayoutConstraints *c = new wxLayoutConstraints; | |
264 | c->left.SameAs (m_editorFrame, wxLeft, 0); | |
265 | c->top.SameAs (m_editorFrame, wxTop, 0); | |
266 | c->right.SameAs (m_editorFrame, wxRight, 0); | |
267 | c->bottom.Unconstrained(); | |
268 | c->width.Unconstrained(); | |
269 | c->height.Absolute(28); | |
270 | m_editorToolBar->SetConstraints(c); | |
271 | ||
272 | // Constraints for listbox | |
273 | c = new wxLayoutConstraints; | |
274 | c->left.SameAs (m_editorFrame, wxLeft, 0); | |
275 | c->top.SameAs (m_editorToolBar, wxBottom, 0); | |
276 | c->right.Absolute (150); | |
277 | c->bottom.SameAs (m_editorControlList, wxTop, 0); | |
278 | c->width.Unconstrained(); | |
279 | c->height.Unconstrained(); | |
280 | m_editorResourceTree->SetConstraints(c); | |
281 | ||
282 | // Constraints for panel | |
283 | c = new wxLayoutConstraints; | |
284 | c->left.SameAs (m_editorResourceTree, wxRight, 0); | |
285 | c->top.SameAs (m_editorToolBar, wxBottom, 0); | |
286 | c->right.SameAs (m_editorFrame, wxRight, 0); | |
287 | c->bottom.SameAs (m_editorControlList, wxTop, 0); | |
288 | c->width.Unconstrained(); | |
289 | c->height.Unconstrained(); | |
290 | m_editorPanel->SetConstraints(c); | |
291 | ||
292 | // Constraints for control list (bottom window) | |
293 | c = new wxLayoutConstraints; | |
294 | c->left.SameAs (m_editorFrame, wxLeft, 0); | |
295 | c->right.SameAs (m_editorFrame, wxRight, 0); | |
296 | c->bottom.SameAs (m_editorFrame, wxBottom, 0); | |
297 | c->width.Unconstrained(); | |
15d5ab67 | 298 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
f6bcfd97 | 299 | c->height.Absolute(120); |
b127f301 | 300 | #else |
f6bcfd97 | 301 | c->height.Absolute(60); |
b127f301 | 302 | #endif |
f6bcfd97 BP |
303 | |
304 | m_editorControlList->SetConstraints(c); | |
305 | ||
306 | m_editorFrame->SetAutoLayout(TRUE); | |
307 | ||
308 | UpdateResourceList(); | |
309 | ||
310 | m_editorFrame->Show(TRUE); | |
311 | return TRUE; | |
312 | } | |
313 | else | |
457814b5 | 314 | { |
f6bcfd97 BP |
315 | if (m_editorFrame->Close()) |
316 | { | |
317 | m_editorFrame = NULL; | |
318 | m_editorPanel = NULL; | |
319 | } | |
457814b5 | 320 | } |
f6bcfd97 | 321 | return TRUE; |
457814b5 JS |
322 | } |
323 | ||
324 | void wxResourceManager::SetFrameTitle(const wxString& filename) | |
325 | { | |
f6bcfd97 | 326 | if (m_editorFrame) |
457814b5 | 327 | { |
f6bcfd97 BP |
328 | if (filename == wxString("")) |
329 | m_editorFrame->SetTitle("wxWindows Dialog Editor - untitled"); | |
330 | else | |
331 | { | |
332 | wxString str("wxWindows Dialog Editor - "); | |
333 | wxString str2(wxFileNameFromPath(WXSTRINGCAST filename)); | |
334 | str += str2; | |
335 | m_editorFrame->SetTitle(str); | |
336 | } | |
457814b5 | 337 | } |
457814b5 JS |
338 | } |
339 | ||
ae8351fc | 340 | bool wxResourceManager::Save() |
457814b5 | 341 | { |
f6bcfd97 BP |
342 | if (m_currentFilename == wxString("")) |
343 | return SaveAs(); | |
344 | else | |
345 | return Save(m_currentFilename); | |
457814b5 JS |
346 | } |
347 | ||
348 | bool wxResourceManager::Save(const wxString& filename) | |
349 | { | |
f6bcfd97 BP |
350 | // Ensure all visible windows are saved to their resources |
351 | m_currentFilename = filename; | |
352 | SetFrameTitle(m_currentFilename); | |
353 | InstantiateAllResourcesFromWindows(); | |
354 | if (m_resourceTable.Save(filename)) | |
355 | { | |
356 | m_symbolTable.WriteIncludeFile(m_symbolFilename); | |
357 | Modify(FALSE); | |
358 | return TRUE; | |
359 | } | |
360 | else | |
361 | return FALSE; | |
457814b5 JS |
362 | } |
363 | ||
ae8351fc | 364 | bool wxResourceManager::SaveAs() |
457814b5 | 365 | { |
f6bcfd97 BP |
366 | wxString s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename), wxFileNameFromPath(WXSTRINGCAST m_currentFilename), |
367 | "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT, wxTheApp->GetTopWindow())); | |
457814b5 | 368 | |
f6bcfd97 BP |
369 | if (s.IsNull() || s == "") |
370 | return FALSE; | |
457814b5 | 371 | |
f6bcfd97 BP |
372 | m_currentFilename = s; |
373 | wxStripExtension(m_currentFilename); | |
374 | m_currentFilename += ".wxr"; | |
375 | ||
376 | // Construct include filename from this file | |
377 | m_symbolFilename = m_currentFilename; | |
378 | ||
379 | wxStripExtension(m_symbolFilename); | |
380 | m_symbolFilename += ".h"; | |
381 | ||
382 | Save(m_currentFilename); | |
383 | return TRUE; | |
457814b5 JS |
384 | } |
385 | ||
ae8351fc | 386 | bool wxResourceManager::SaveIfModified() |
457814b5 | 387 | { |
f6bcfd97 BP |
388 | if (Modified()) |
389 | return Save(); | |
390 | else return TRUE; | |
457814b5 JS |
391 | } |
392 | ||
393 | bool wxResourceManager::Load(const wxString& filename) | |
394 | { | |
f6bcfd97 | 395 | return New(TRUE, filename); |
457814b5 JS |
396 | } |
397 | ||
398 | bool wxResourceManager::New(bool loadFromFile, const wxString& filename) | |
399 | { | |
f6bcfd97 | 400 | if (!Clear(TRUE, FALSE)) |
457814b5 | 401 | return FALSE; |
457814b5 | 402 | |
f6bcfd97 BP |
403 | m_symbolTable.AddStandardSymbols(); |
404 | ||
405 | if (loadFromFile) | |
03f68f12 | 406 | { |
f6bcfd97 BP |
407 | wxString str = filename; |
408 | if (str == wxString("")) | |
409 | { | |
410 | wxString f(wxFileSelector("Open resource file", wxGetCwd(), wxEmptyString, "wxr", "*.wxr", 0, wxTheApp->GetTopWindow())); | |
411 | if (!f.IsNull() && f != "") | |
412 | str = f; | |
413 | else | |
414 | return FALSE; | |
415 | } | |
416 | ||
417 | if (!m_resourceTable.ParseResourceFile(str)) | |
418 | { | |
419 | wxMessageBox("Could not read file.", "Resource file load error", wxOK | wxICON_EXCLAMATION); | |
420 | return FALSE; | |
421 | } | |
422 | m_currentFilename = str; | |
423 | ||
424 | SetFrameTitle(m_currentFilename); | |
425 | ||
426 | UpdateResourceList(); | |
427 | ||
428 | // Construct include filename from this file | |
429 | m_symbolFilename = m_currentFilename; | |
430 | ||
431 | wxStripExtension(m_symbolFilename); | |
432 | m_symbolFilename += ".h"; | |
433 | ||
434 | if (!m_symbolTable.ReadIncludeFile(m_symbolFilename)) | |
435 | { | |
436 | wxString str("Could not find include file "); | |
437 | str += m_symbolFilename; | |
438 | str += ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n"; | |
439 | str += "The next time this .wxr file is saved, a header file will be saved also."; | |
440 | wxMessageBox(str, "Dialog Editor Warning", wxOK ); | |
441 | ||
442 | m_symbolIdCounter = 99; | |
443 | } | |
444 | else | |
445 | { | |
446 | // Set the id counter to the last known id | |
447 | m_symbolIdCounter = m_symbolTable.FindHighestId(); | |
448 | } | |
449 | ||
450 | // Now check in case some (or all) resources don't have resource ids, or they | |
451 | // don't match the .h file, or something of that nature. | |
452 | bool altered = RepairResourceIds(); | |
453 | if (altered) | |
454 | { | |
455 | wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.", | |
456 | "Dialog Editor Warning", wxOK ); | |
457 | Modify(TRUE); | |
458 | } | |
459 | else | |
460 | Modify(FALSE); | |
461 | ||
462 | return TRUE; | |
5de76427 JS |
463 | } |
464 | else | |
465 | { | |
f6bcfd97 BP |
466 | SetFrameTitle(""); |
467 | m_currentFilename = ""; | |
bbcdf8bc | 468 | } |
f6bcfd97 BP |
469 | Modify(FALSE); |
470 | ||
bbcdf8bc | 471 | return TRUE; |
457814b5 JS |
472 | } |
473 | ||
b127f301 | 474 | bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows), bool force) |
457814b5 | 475 | { |
f6bcfd97 BP |
476 | wxPropertyInfo::CloseWindow(); |
477 | ||
478 | if (!force && Modified()) | |
479 | { | |
480 | int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL); | |
481 | if (ans == wxCANCEL) | |
482 | return FALSE; | |
483 | if (ans == wxYES) | |
484 | if (!SaveIfModified()) | |
485 | return FALSE; | |
486 | if (ans == wxNO) | |
487 | Modify(FALSE); | |
488 | } | |
489 | ||
490 | ClearCurrentDialog(); | |
491 | DisassociateWindows(); | |
492 | ||
493 | m_symbolTable.Clear(); | |
494 | m_resourceTable.ClearTable(); | |
495 | UpdateResourceList(); | |
496 | ||
497 | return TRUE; | |
457814b5 JS |
498 | } |
499 | ||
ae8351fc | 500 | bool wxResourceManager::DisassociateWindows() |
457814b5 | 501 | { |
f6bcfd97 BP |
502 | m_resourceTable.BeginFind(); |
503 | wxNode *node; | |
504 | while ((node = m_resourceTable.Next())) | |
505 | { | |
506 | wxItemResource *res = (wxItemResource *)node->Data(); | |
507 | DisassociateResource(res); | |
508 | } | |
509 | ||
510 | return TRUE; | |
457814b5 JS |
511 | } |
512 | ||
513 | void wxResourceManager::AssociateResource(wxItemResource *resource, wxWindow *win) | |
514 | { | |
f6bcfd97 BP |
515 | if (!m_resourceAssociations.Get((long)resource)) |
516 | m_resourceAssociations.Put((long)resource, win); | |
517 | ||
518 | wxNode *node = resource->GetChildren().First(); | |
519 | wxNode* node2 = win->GetChildren().First(); | |
520 | while (node && node2) | |
8caa4ed1 | 521 | { |
f6bcfd97 BP |
522 | wxItemResource *child = (wxItemResource *)node->Data(); |
523 | wxWindow* childWindow = (wxWindow*) node2->Data(); | |
524 | ||
525 | if (child->GetId() != childWindow->GetId()) | |
526 | { | |
527 | wxString msg; | |
528 | msg.Printf("AssociateResource: error when associating child window %ld with resource %ld", child->GetId(), childWindow->GetId()); | |
529 | wxMessageBox(msg, "Dialog Editor problem", wxOK); | |
530 | } | |
531 | else if (childWindow->GetName() != child->GetName()) | |
532 | { | |
533 | wxString msg; | |
534 | msg.Printf("AssociateResource: error when associating child window with resource %s", child->GetName() ? (const char*) child->GetName() : "(unnamed)"); | |
535 | wxMessageBox(msg, "Dialog Editor problem", wxOK); | |
536 | } | |
537 | else | |
538 | { | |
539 | AssociateResource(child, childWindow); | |
540 | } | |
541 | ||
542 | // New code to avoid the problem of duplicate ids and names. We simply | |
543 | // traverse the child windows and child resources in parallel, | |
544 | // checking for any mismatch. | |
8caa4ed1 | 545 | #if 0 |
f6bcfd97 BP |
546 | wxWindow *childWindow = (wxWindow *)m_resourceAssociations.Get((long)child); |
547 | if (!childWindow) | |
548 | // childWindow = win->FindWindow(child->GetName()); | |
549 | childWindow = win->FindWindow(child->GetId()); | |
550 | if (childWindow) | |
551 | AssociateResource(child, childWindow); | |
552 | else | |
553 | { | |
554 | wxString msg; | |
555 | msg.Printf("AssociateResource: cannot find child window %s", child->GetName() ? (const char*) child->GetName() : "(unnamed)"); | |
556 | wxMessageBox(msg, "Dialog Editor problem", wxOK); | |
557 | } | |
8caa4ed1 | 558 | #endif |
f6bcfd97 BP |
559 | node = node->Next(); |
560 | node2 = node2->Next(); | |
561 | } | |
457814b5 JS |
562 | } |
563 | ||
ae8351fc | 564 | bool wxResourceManager::DisassociateResource(wxItemResource *resource) |
457814b5 | 565 | { |
f6bcfd97 BP |
566 | wxWindow *win = FindWindowForResource(resource); |
567 | if (!win) | |
568 | return FALSE; | |
569 | ||
570 | // Disassociate children of window | |
571 | wxNode *node = win->GetChildren().First(); | |
572 | while (node) | |
573 | { | |
574 | wxWindow *child = (wxWindow *)node->Data(); | |
575 | if (child->IsKindOf(CLASSINFO(wxControl))) | |
576 | DisassociateResource(child); | |
577 | node = node->Next(); | |
578 | } | |
579 | ||
580 | RemoveSelection(win); | |
581 | m_resourceAssociations.Delete((long)resource); | |
582 | return TRUE; | |
457814b5 JS |
583 | } |
584 | ||
ae8351fc | 585 | bool wxResourceManager::DisassociateResource(wxWindow *win) |
457814b5 | 586 | { |
f6bcfd97 BP |
587 | wxItemResource *res = FindResourceForWindow(win); |
588 | if (res) | |
589 | return DisassociateResource(res); | |
590 | else | |
591 | return FALSE; | |
ae8351fc JS |
592 | } |
593 | ||
594 | // Saves the window info into the resource, and deletes the | |
595 | // handler. Doesn't actually disassociate the window from | |
596 | // the resources. Replaces OnClose. | |
597 | bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow* win) | |
598 | { | |
599 | wxItemResource *res = FindResourceForWindow(win); | |
f6bcfd97 | 600 | |
ae8351fc JS |
601 | if (win->IsKindOf(CLASSINFO(wxPanel))) |
602 | { | |
603 | wxResourceEditorDialogHandler* handler = (wxResourceEditorDialogHandler*) win->GetEventHandler(); | |
604 | win->PopEventHandler(); | |
f6bcfd97 | 605 | |
ae8351fc | 606 | // Now reset all child event handlers |
c030b70f | 607 | wxNode *node = win->GetChildren().First(); |
ae8351fc JS |
608 | while ( node ) |
609 | { | |
f6bcfd97 BP |
610 | wxWindow *child = (wxWindow *)node->Data(); |
611 | wxEvtHandler *childHandler = child->GetEventHandler(); | |
612 | if ( child->IsKindOf(CLASSINFO(wxControl)) && childHandler != child ) | |
613 | { | |
614 | child->PopEventHandler(TRUE); | |
615 | } | |
616 | node = node->Next(); | |
ae8351fc JS |
617 | } |
618 | delete handler; | |
619 | } | |
620 | else | |
621 | { | |
622 | win->PopEventHandler(TRUE); | |
623 | } | |
f6bcfd97 | 624 | |
ae8351fc JS |
625 | // Save the information |
626 | InstantiateResourceFromWindow(res, win, TRUE); | |
f6bcfd97 BP |
627 | |
628 | // DisassociateResource(win); | |
629 | ||
ae8351fc JS |
630 | return TRUE; |
631 | } | |
632 | ||
633 | // Destroys the window. If this is the 'current' panel, NULLs the | |
634 | // variable. | |
635 | bool wxResourceManager::DeleteWindow(wxWindow* win) | |
636 | { | |
03f68f12 | 637 | bool clearDisplay = FALSE; |
ae8351fc | 638 | if (m_editorPanel->m_childWindow == win) |
03f68f12 | 639 | { |
ae8351fc | 640 | m_editorPanel->m_childWindow = NULL; |
03f68f12 JS |
641 | clearDisplay = TRUE; |
642 | } | |
f6bcfd97 | 643 | |
ae8351fc | 644 | win->Destroy(); |
f6bcfd97 | 645 | |
03f68f12 JS |
646 | if (clearDisplay) |
647 | m_editorPanel->Clear(); | |
f6bcfd97 | 648 | |
ae8351fc | 649 | return TRUE; |
457814b5 JS |
650 | } |
651 | ||
652 | wxItemResource *wxResourceManager::FindResourceForWindow(wxWindow *win) | |
653 | { | |
f6bcfd97 BP |
654 | m_resourceAssociations.BeginFind(); |
655 | wxNode *node; | |
656 | while ((node = m_resourceAssociations.Next())) | |
457814b5 | 657 | { |
f6bcfd97 BP |
658 | wxWindow *w = (wxWindow *)node->Data(); |
659 | if (w == win) | |
660 | { | |
661 | return (wxItemResource *)node->GetKeyInteger(); | |
662 | } | |
457814b5 | 663 | } |
f6bcfd97 | 664 | return NULL; |
457814b5 JS |
665 | } |
666 | ||
667 | wxWindow *wxResourceManager::FindWindowForResource(wxItemResource *resource) | |
668 | { | |
f6bcfd97 | 669 | return (wxWindow *)m_resourceAssociations.Get((long)resource); |
457814b5 JS |
670 | } |
671 | ||
672 | ||
673 | void wxResourceManager::MakeUniqueName(char *prefix, char *buf) | |
674 | { | |
f6bcfd97 BP |
675 | while (TRUE) |
676 | { | |
677 | sprintf(buf, "%s%d", prefix, m_nameCounter); | |
678 | m_nameCounter ++; | |
679 | ||
680 | if (!m_resourceTable.FindResource(buf)) | |
681 | return; | |
682 | } | |
457814b5 JS |
683 | } |
684 | ||
685 | wxFrame *wxResourceManager::OnCreateEditorFrame(const char *title) | |
686 | { | |
f6bcfd97 BP |
687 | wxResourceEditorFrame *frame = new wxResourceEditorFrame(this, NULL, title, |
688 | wxPoint(m_resourceEditorWindowSize.x, m_resourceEditorWindowSize.y), | |
689 | wxSize(m_resourceEditorWindowSize.width, m_resourceEditorWindowSize.height), | |
690 | wxDEFAULT_FRAME_STYLE); | |
691 | ||
692 | frame->CreateStatusBar(1); | |
693 | ||
694 | frame->SetAutoLayout(TRUE); | |
2049ba38 | 695 | #ifdef __WXMSW__ |
f6bcfd97 | 696 | frame->SetIcon(wxIcon("DIALOGEDICON")); |
457814b5 | 697 | #endif |
f6bcfd97 | 698 | return frame; |
457814b5 JS |
699 | } |
700 | ||
b127f301 | 701 | wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *WXUNUSED(parent)) |
457814b5 | 702 | { |
f6bcfd97 BP |
703 | wxMenuBar *menuBar = new wxMenuBar; |
704 | ||
705 | wxMenu *fileMenu = new wxMenu; | |
706 | fileMenu->Append(RESED_NEW_DIALOG, "New &Dialog", "Create a new dialog"); | |
707 | fileMenu->AppendSeparator(); | |
708 | fileMenu->Append(wxID_NEW, "&New Project", "Clear the current project"); | |
709 | fileMenu->Append(wxID_OPEN, "&Open...", "Load a resource file"); | |
710 | fileMenu->Append(wxID_SAVE, "&Save", "Save a resource file"); | |
711 | fileMenu->Append(wxID_SAVEAS, "Save &As...", "Save a resource file as..."); | |
712 | fileMenu->Append(RESED_CLEAR, "&Clear", "Clear current resources"); | |
713 | fileMenu->AppendSeparator(); | |
714 | fileMenu->Append(RESED_CONVERT_WXRS, "Convert Old &Resources...", "Convert old resources to new"); | |
715 | fileMenu->AppendSeparator(); | |
716 | fileMenu->Append(wxID_EXIT, "E&xit", "Exit resource editor"); | |
717 | ||
718 | wxMenu *editMenu = new wxMenu; | |
719 | editMenu->Append(RESED_TEST, "&Test Dialog", "Test dialog"); | |
720 | editMenu->Append(RESED_RECREATE, "&Recreate", "Recreate the selected resource(s)"); | |
721 | editMenu->Append(RESED_DELETE, "&Delete", "Delete the selected resource(s)"); | |
722 | ||
723 | wxMenu *helpMenu = new wxMenu; | |
724 | helpMenu->Append(RESED_CONTENTS, "&Help Topics", "Invokes the on-line help"); | |
725 | helpMenu->AppendSeparator(); | |
726 | helpMenu->Append(wxID_ABOUT, "&About", "About wxWindows Dialog Editor"); | |
727 | ||
728 | menuBar->Append(fileMenu, "&File"); | |
729 | menuBar->Append(editMenu, "&Edit"); | |
730 | menuBar->Append(helpMenu, "&Help"); | |
731 | ||
732 | return menuBar; | |
457814b5 JS |
733 | } |
734 | ||
ae8351fc | 735 | wxResourceEditorScrolledWindow *wxResourceManager::OnCreateEditorPanel(wxFrame *parent) |
457814b5 | 736 | { |
f6bcfd97 BP |
737 | wxResourceEditorScrolledWindow *panel = new wxResourceEditorScrolledWindow(parent, wxDefaultPosition, wxDefaultSize, |
738 | // wxSUNKEN_BORDER|wxCLIP_CHILDREN); | |
15d5ab67 | 739 | #ifdef __WXMOTIF__ |
f6bcfd97 | 740 | wxBORDER); |
15d5ab67 | 741 | #else |
ae8351fc | 742 | wxSUNKEN_BORDER); |
15d5ab67 | 743 | #endif |
f6bcfd97 BP |
744 | |
745 | panel->SetScrollbars(10, 10, 100, 100); | |
746 | ||
747 | return panel; | |
748 | } | |
457814b5 | 749 | |
163f0dbe | 750 | wxToolBar *wxResourceManager::OnCreateToolBar(wxFrame *parent) |
457814b5 | 751 | { |
f6bcfd97 | 752 | // Load palette bitmaps |
2049ba38 | 753 | #ifdef __WXMSW__ |
f6bcfd97 BP |
754 | wxBitmap ToolbarLoadBitmap("LOADTOOL"); |
755 | wxBitmap ToolbarSaveBitmap("SAVETOOL"); | |
756 | wxBitmap ToolbarNewBitmap("NEWTOOL"); | |
757 | wxBitmap ToolbarVertBitmap("VERTTOOL"); | |
758 | wxBitmap ToolbarAlignTBitmap("ALIGNTTOOL"); | |
759 | wxBitmap ToolbarAlignBBitmap("ALIGNBTOOL"); | |
760 | wxBitmap ToolbarHorizBitmap("HORIZTOOL"); | |
761 | wxBitmap ToolbarAlignLBitmap("ALIGNLTOOL"); | |
762 | wxBitmap ToolbarAlignRBitmap("ALIGNRTOOL"); | |
763 | wxBitmap ToolbarCopySizeBitmap("COPYSIZETOOL"); | |
764 | wxBitmap ToolbarToBackBitmap("TOBACKTOOL"); | |
765 | wxBitmap ToolbarToFrontBitmap("TOFRONTTOOL"); | |
766 | wxBitmap ToolbarHelpBitmap("HELPTOOL"); | |
767 | wxBitmap ToolbarCopyWidthBitmap("COPYWIDTHTOOL"); | |
768 | wxBitmap ToolbarCopyHeightBitmap("COPYHEIGHTTOOL"); | |
769 | wxBitmap ToolbarDistributeHorizBitmap("DISTHORIZTOOL"); | |
770 | wxBitmap ToolbarDistributeVertBitmap("DISTVERTTOOL"); | |
457814b5 | 771 | #endif |
5e998a33 | 772 | #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) |
f6bcfd97 BP |
773 | wxBitmap ToolbarLoadBitmap( load_xpm ); |
774 | wxBitmap ToolbarSaveBitmap( save_xpm); | |
775 | wxBitmap ToolbarNewBitmap( new_xpm ); | |
776 | wxBitmap ToolbarVertBitmap( vert_xpm ); | |
777 | wxBitmap ToolbarAlignTBitmap( alignt_xpm ); | |
778 | wxBitmap ToolbarAlignBBitmap( alignb_xpm ); | |
779 | wxBitmap ToolbarHorizBitmap( horiz_xpm ); | |
780 | wxBitmap ToolbarAlignLBitmap( alignl_xpm ); | |
781 | wxBitmap ToolbarAlignRBitmap( alignr_xpm ); | |
782 | wxBitmap ToolbarCopySizeBitmap( copysize_xpm ); | |
783 | wxBitmap ToolbarToBackBitmap( toback_xpm ); | |
784 | wxBitmap ToolbarToFrontBitmap( tofront_xpm ); | |
785 | wxBitmap ToolbarHelpBitmap( help_xpm ); | |
786 | wxBitmap ToolbarCopyWidthBitmap(copywdth_xpm); | |
787 | wxBitmap ToolbarCopyHeightBitmap(copyhght_xpm); | |
788 | wxBitmap ToolbarDistributeHorizBitmap(disthor_xpm); | |
789 | wxBitmap ToolbarDistributeVertBitmap(distvert_xpm); | |
457814b5 | 790 | #endif |
f6bcfd97 BP |
791 | |
792 | // Create the toolbar | |
793 | EditorToolBar *toolbar = new EditorToolBar(parent, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER|wxTB_HORIZONTAL|wxTB_FLAT); | |
794 | toolbar->SetMargins(2, 2); | |
795 | ||
2049ba38 | 796 | #ifdef __WXMSW__ |
f6bcfd97 BP |
797 | int width = 24; |
798 | int dx = 2; | |
799 | int gap = 6; | |
457814b5 | 800 | #else |
f6bcfd97 BP |
801 | int width = 24; // ToolbarLoadBitmap->GetWidth(); ??? |
802 | int dx = 2; | |
803 | int gap = 6; | |
457814b5 | 804 | #endif |
f6bcfd97 BP |
805 | int currentX = gap; |
806 | //toolbar->AddSeparator(); | |
807 | toolbar->AddTool(TOOLBAR_NEW, ToolbarNewBitmap, wxNullBitmap, | |
808 | FALSE, currentX, -1, NULL, "New dialog"); | |
809 | currentX += width + dx; | |
810 | toolbar->AddTool(TOOLBAR_LOAD_FILE, ToolbarLoadBitmap, wxNullBitmap, | |
811 | FALSE, currentX, -1, NULL, "Load"); | |
812 | currentX += width + dx; | |
813 | toolbar->AddTool(TOOLBAR_SAVE_FILE, ToolbarSaveBitmap, wxNullBitmap, | |
814 | FALSE, currentX, -1, NULL, "Save"); | |
815 | currentX += width + dx + gap; | |
816 | toolbar->AddSeparator(); | |
817 | toolbar->AddTool(TOOLBAR_FORMAT_HORIZ, ToolbarVertBitmap, wxNullBitmap, | |
818 | FALSE, currentX, -1, NULL, "Horizontal align"); | |
819 | currentX += width + dx; | |
820 | toolbar->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN, ToolbarAlignTBitmap, wxNullBitmap, | |
821 | FALSE, currentX, -1, NULL, "Top align"); | |
822 | currentX += width + dx; | |
823 | toolbar->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN, ToolbarAlignBBitmap, wxNullBitmap, | |
824 | FALSE, currentX, -1, NULL, "Bottom align"); | |
825 | currentX += width + dx; | |
826 | toolbar->AddTool(TOOLBAR_FORMAT_VERT, ToolbarHorizBitmap, wxNullBitmap, | |
827 | FALSE, currentX, -1, NULL, "Vertical align"); | |
828 | currentX += width + dx; | |
829 | toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN, ToolbarAlignLBitmap, wxNullBitmap, | |
830 | FALSE, currentX, -1, NULL, "Left align"); | |
831 | currentX += width + dx; | |
832 | toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN, ToolbarAlignRBitmap, wxNullBitmap, | |
833 | FALSE, currentX, -1, NULL, "Right align"); | |
834 | currentX += width + dx + gap; | |
835 | toolbar->AddSeparator(); | |
836 | toolbar->AddTool(TOOLBAR_COPY_SIZE, ToolbarCopySizeBitmap, wxNullBitmap, | |
837 | FALSE, currentX, -1, NULL, "Copy size"); | |
838 | currentX += width + dx; | |
839 | toolbar->AddTool(TOOLBAR_COPY_WIDTH, ToolbarCopyWidthBitmap, wxNullBitmap, | |
840 | FALSE, currentX, -1, NULL, "Copy width"); | |
841 | currentX += width + dx; | |
842 | toolbar->AddTool(TOOLBAR_COPY_HEIGHT, ToolbarCopyHeightBitmap, wxNullBitmap, | |
843 | FALSE, currentX, -1, NULL, "Copy height"); | |
844 | currentX += width + dx; | |
845 | toolbar->AddTool(TOOLBAR_DISTRIBUTE_HORIZ, ToolbarDistributeHorizBitmap, wxNullBitmap, | |
846 | FALSE, currentX, -1, NULL, "Distribute horizontally"); | |
847 | currentX += width + dx; | |
848 | toolbar->AddTool(TOOLBAR_DISTRIBUTE_VERT, ToolbarDistributeVertBitmap, wxNullBitmap, | |
849 | FALSE, currentX, -1, NULL, "Distribute vertically"); | |
850 | currentX += width + dx + gap; | |
851 | toolbar->AddSeparator(); | |
852 | toolbar->AddTool(TOOLBAR_TO_FRONT, ToolbarToFrontBitmap, wxNullBitmap, | |
853 | FALSE, currentX, -1, NULL, "To front"); | |
854 | currentX += width + dx; | |
855 | toolbar->AddTool(TOOLBAR_TO_BACK, ToolbarToBackBitmap, wxNullBitmap, | |
856 | FALSE, currentX, -1, NULL, "To back"); | |
857 | currentX += width + dx + gap; | |
858 | ||
859 | toolbar->AddSeparator(); | |
860 | toolbar->AddTool(TOOLBAR_HELP, ToolbarHelpBitmap, wxNullBitmap, | |
861 | FALSE, currentX, -1, NULL, "Help"); | |
862 | currentX += width + dx; | |
863 | ||
864 | toolbar->Realize(); | |
865 | ||
866 | return toolbar; | |
457814b5 JS |
867 | } |
868 | ||
ae8351fc | 869 | void wxResourceManager::UpdateResourceList() |
457814b5 | 870 | { |
f6bcfd97 BP |
871 | if (!m_editorResourceTree) |
872 | return; | |
873 | ||
874 | m_editorResourceTree->SetInvalid(TRUE); | |
875 | m_editorResourceTree->DeleteAllItems(); | |
876 | ||
877 | long id = m_editorResourceTree->AddRoot("Dialogs", 1, 2); | |
878 | ||
879 | m_resourceTable.BeginFind(); | |
880 | wxNode *node; | |
881 | while ((node = m_resourceTable.Next())) | |
457814b5 | 882 | { |
f6bcfd97 BP |
883 | wxItemResource *res = (wxItemResource *)node->Data(); |
884 | wxString resType(res->GetType()); | |
885 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel" || resType == "wxBitmap") | |
886 | { | |
887 | AddItemsRecursively(id, res); | |
888 | } | |
457814b5 | 889 | } |
f6bcfd97 BP |
890 | m_editorResourceTree->Expand(id); |
891 | m_editorResourceTree->SetInvalid(FALSE); | |
457814b5 JS |
892 | } |
893 | ||
ae8351fc | 894 | void wxResourceManager::AddItemsRecursively(long parent, wxItemResource *resource) |
457814b5 | 895 | { |
f6bcfd97 BP |
896 | wxString theString(""); |
897 | theString = resource->GetName(); | |
898 | ||
899 | int imageId = 0; | |
900 | wxString resType(resource->GetType()); | |
901 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
902 | imageId = 0; | |
903 | else | |
904 | imageId = 3; | |
905 | ||
906 | long id = m_editorResourceTree->AppendItem(parent, theString, imageId ); | |
907 | ||
908 | m_editorResourceTree->SetItemData(id, new wxResourceTreeData(resource)); | |
909 | ||
910 | if (strcmp(resource->GetType(), "wxBitmap") != 0) | |
457814b5 | 911 | { |
f6bcfd97 BP |
912 | wxNode *node = resource->GetChildren().First(); |
913 | while (node) | |
914 | { | |
915 | wxItemResource *res = (wxItemResource *)node->Data(); | |
916 | AddItemsRecursively(id, res); | |
917 | node = node->Next(); | |
918 | } | |
457814b5 | 919 | } |
f6bcfd97 | 920 | // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND); |
457814b5 JS |
921 | } |
922 | ||
ae8351fc | 923 | bool wxResourceManager::EditSelectedResource() |
457814b5 | 924 | { |
f6bcfd97 BP |
925 | int sel = m_editorResourceTree->GetSelection(); |
926 | if (sel != 0) | |
927 | { | |
928 | wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel); | |
929 | wxItemResource *res = data->GetResource(); | |
930 | return Edit(res); | |
931 | } | |
932 | return FALSE; | |
457814b5 JS |
933 | } |
934 | ||
935 | bool wxResourceManager::Edit(wxItemResource *res) | |
936 | { | |
f6bcfd97 BP |
937 | wxPropertyInfo::CloseWindow(); |
938 | ||
939 | ClearCurrentDialog(); | |
940 | ||
941 | wxString resType(res->GetType()); | |
942 | wxPanel *panel = (wxPanel *)FindWindowForResource(res); | |
943 | ||
944 | if (panel) | |
945 | { | |
946 | wxMessageBox("Should not find panel in wxResourceManager::Edit"); | |
947 | return FALSE; | |
948 | } | |
949 | else | |
950 | { | |
951 | // long style = res->GetStyle(); | |
952 | // res->SetStyle(style|wxRAISED_BORDER); | |
457814b5 JS |
953 | panel = new wxPanel; |
954 | wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, res, panel->GetEventHandler(), | |
f6bcfd97 BP |
955 | this); |
956 | ||
ae8351fc | 957 | panel->LoadFromResource(m_editorPanel, res->GetName(), &m_resourceTable); |
f6bcfd97 | 958 | |
ae8351fc | 959 | panel->PushEventHandler(handler); |
f6bcfd97 BP |
960 | |
961 | // res->SetStyle(style); | |
962 | handler->AddChildHandlers(); // Add event handlers for all controls | |
ae8351fc | 963 | AssociateResource(res, panel); |
f6bcfd97 | 964 | |
ae8351fc JS |
965 | m_editorPanel->m_childWindow = panel; |
966 | panel->Move(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()); | |
967 | panel->Show(TRUE); | |
968 | panel->Refresh(); | |
f6bcfd97 | 969 | |
ae8351fc JS |
970 | wxClientDC dc(m_editorPanel); |
971 | m_editorPanel->DrawTitle(dc); | |
f6bcfd97 BP |
972 | } |
973 | return FALSE; | |
457814b5 JS |
974 | } |
975 | ||
ae8351fc | 976 | bool wxResourceManager::CreateNewPanel() |
457814b5 | 977 | { |
f6bcfd97 BP |
978 | wxPropertyInfo::CloseWindow(); |
979 | ||
980 | ClearCurrentDialog(); | |
981 | ||
982 | char buf[256]; | |
983 | MakeUniqueName("dialog", buf); | |
984 | ||
985 | wxItemResource *resource = new wxItemResource; | |
986 | resource->SetType("wxDialog"); | |
987 | resource->SetName(buf); | |
988 | resource->SetTitle(buf); | |
989 | resource->SetResourceStyle(wxRESOURCE_USE_DEFAULTS); | |
990 | resource->SetResourceStyle(wxRESOURCE_DIALOG_UNITS); | |
991 | ||
992 | wxString newIdName; | |
993 | int id = GenerateWindowId("ID_DIALOG", newIdName); | |
994 | resource->SetId(id); | |
995 | ||
996 | // This is now guaranteed to be unique, so just add to symbol table | |
997 | m_symbolTable.AddSymbol(newIdName, id); | |
998 | ||
999 | m_resourceTable.AddResource(resource); | |
1000 | ||
1001 | wxSize size(400, 300); | |
1002 | ||
1003 | wxPanel *panel = new wxPanel(m_editorPanel, -1, | |
1004 | wxPoint(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()), | |
1005 | size, wxRAISED_BORDER|wxDEFAULT_DIALOG_STYLE, buf); | |
1006 | m_editorPanel->m_childWindow = panel; | |
1007 | ||
1008 | resource->SetStyle(panel->GetWindowStyleFlag()); | |
1009 | ||
1010 | // Store dialog units in resource | |
1011 | size = panel->ConvertPixelsToDialog(size); | |
1012 | ||
1013 | resource->SetSize(10, 10, size.x, size.y); | |
1014 | ||
1015 | // For editing in situ we will need to use the hash table to ensure | |
1016 | // we don't dereference invalid pointers. | |
1017 | // resourceWindowTable.Put((long)resource, panel); | |
1018 | ||
1019 | wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, resource, panel->GetEventHandler(), | |
1020 | this); | |
1021 | panel->PushEventHandler(handler); | |
1022 | ||
1023 | AssociateResource(resource, panel); | |
1024 | UpdateResourceList(); | |
1025 | ||
1026 | Modify(TRUE); | |
1027 | m_editorPanel->m_childWindow->Refresh(); | |
1028 | ||
1029 | // panel->Refresh(); | |
1030 | ||
1031 | wxClientDC dc(m_editorPanel); | |
1032 | m_editorPanel->DrawTitle(dc); | |
1033 | ||
1034 | return TRUE; | |
457814b5 JS |
1035 | } |
1036 | ||
1037 | bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *panel, char *iType, int x, int y, bool isBitmap) | |
1038 | { | |
f6bcfd97 BP |
1039 | char buf[256]; |
1040 | if (!panel->IsKindOf(CLASSINFO(wxPanel)) && !panel->IsKindOf(CLASSINFO(wxDialog))) | |
1041 | return FALSE; | |
1042 | ||
1043 | Modify(TRUE); | |
1044 | ||
1045 | wxItemResource *res = new wxItemResource; | |
1046 | wxControl *newItem = NULL; | |
1047 | ||
1048 | if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) | |
1049 | { | |
1050 | wxPoint pt = panel->ConvertPixelsToDialog(wxPoint(x, y)); | |
1051 | res->SetSize(pt.x, pt.y, -1, -1); | |
1052 | } | |
1053 | else res->SetSize(x, y, -1, -1); | |
1054 | ||
1055 | res->SetType(iType); | |
1056 | ||
1057 | wxString prefix; | |
1058 | ||
1059 | wxString itemType(iType); | |
1060 | ||
1061 | if (itemType == "wxButton") | |
1062 | { | |
1063 | prefix = "ID_BUTTON"; | |
1064 | MakeUniqueName("button", buf); | |
1065 | res->SetName(buf); | |
1066 | if (isBitmap) | |
1067 | newItem = new wxBitmapButton(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), wxBU_AUTODRAW, wxDefaultValidator, buf); | |
1068 | else | |
1069 | newItem = new wxButton(panel, -1, "Button", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); | |
1070 | } | |
1071 | if (itemType == "wxBitmapButton") | |
457814b5 | 1072 | { |
f6bcfd97 BP |
1073 | prefix = "ID_BITMAPBUTTON"; |
1074 | MakeUniqueName("button", buf); | |
1075 | res->SetName(buf); | |
d0b223a1 | 1076 | newItem = new wxBitmapButton(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), wxBU_AUTODRAW, wxDefaultValidator, buf); |
457814b5 | 1077 | } |
f6bcfd97 | 1078 | else if (itemType == "wxMessage" || itemType == "wxStaticText") |
457814b5 | 1079 | { |
f6bcfd97 BP |
1080 | prefix = "ID_STATIC"; |
1081 | MakeUniqueName("statictext", buf); | |
1082 | res->SetName(buf); | |
1083 | if (isBitmap) | |
1084 | newItem = new wxStaticBitmap(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(0, 0), 0, buf); | |
1085 | else | |
1086 | newItem = new wxStaticText(panel, -1, "Static", wxPoint(x, y), wxSize(-1, -1), 0, buf); | |
457814b5 | 1087 | } |
f6bcfd97 | 1088 | else if (itemType == "wxStaticBitmap") |
457814b5 | 1089 | { |
f6bcfd97 BP |
1090 | prefix = "ID_STATICBITMAP"; |
1091 | MakeUniqueName("static", buf); | |
1092 | res->SetName(buf); | |
1093 | newItem = new wxStaticBitmap(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, buf); | |
457814b5 | 1094 | } |
f6bcfd97 | 1095 | else if (itemType == "wxCheckBox") |
457814b5 | 1096 | { |
f6bcfd97 BP |
1097 | prefix = "ID_CHECKBOX"; |
1098 | MakeUniqueName("checkbox", buf); | |
1099 | res->SetName(buf); | |
1100 | newItem = new wxCheckBox(panel, -1, "Checkbox", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); | |
457814b5 | 1101 | } |
f6bcfd97 | 1102 | else if (itemType == "wxListBox") |
457814b5 | 1103 | { |
f6bcfd97 BP |
1104 | prefix = "ID_LISTBOX"; |
1105 | MakeUniqueName("listbox", buf); | |
1106 | res->SetName(buf); | |
1107 | newItem = new wxListBox(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf); | |
457814b5 | 1108 | } |
f6bcfd97 | 1109 | else if (itemType == "wxRadioBox") |
457814b5 | 1110 | { |
f6bcfd97 BP |
1111 | prefix = "ID_RADIOBOX"; |
1112 | MakeUniqueName("radiobox", buf); | |
1113 | res->SetName(buf); | |
1114 | wxString names[] = { "One", "Two" }; | |
1115 | newItem = new wxRadioBox(panel, -1, "Radiobox", wxPoint(x, y), wxSize(-1, -1), 2, names, 2, | |
1116 | wxHORIZONTAL, wxDefaultValidator, buf); | |
1117 | res->SetStringValues(wxStringList("One", "Two", NULL)); | |
457814b5 | 1118 | } |
f6bcfd97 | 1119 | else if (itemType == "wxRadioButton") |
457814b5 | 1120 | { |
f6bcfd97 BP |
1121 | prefix = "ID_RADIOBUTTON"; |
1122 | MakeUniqueName("radiobutton", buf); | |
1123 | res->SetName(buf); | |
1124 | wxString names[] = { "One", "Two" }; | |
1125 | newItem = new wxRadioButton(panel, -1, "Radiobutton", wxPoint(x, y), wxSize(-1, -1), | |
1126 | 0, wxDefaultValidator, buf); | |
457814b5 | 1127 | } |
f6bcfd97 | 1128 | else if (itemType == "wxChoice") |
03f68f12 | 1129 | { |
f6bcfd97 BP |
1130 | prefix = "ID_CHOICE"; |
1131 | MakeUniqueName("choice", buf); | |
1132 | res->SetName(buf); | |
1133 | newItem = new wxChoice(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf); | |
03f68f12 | 1134 | } |
f6bcfd97 | 1135 | else if (itemType == "wxComboBox") |
457814b5 | 1136 | { |
f6bcfd97 BP |
1137 | prefix = "ID_COMBOBOX"; |
1138 | MakeUniqueName("combobox", buf); | |
1139 | res->SetName(buf); | |
1140 | newItem = new wxComboBox(panel, -1, "", wxPoint(x, y), wxSize(-1, -1), 0, NULL, wxCB_DROPDOWN, wxDefaultValidator, buf); | |
457814b5 | 1141 | } |
f6bcfd97 | 1142 | else if (itemType == "wxGroupBox" || itemType == "wxStaticBox") |
9c331ded | 1143 | { |
f6bcfd97 BP |
1144 | prefix = "ID_STATICBOX"; |
1145 | MakeUniqueName("staticbox", buf); | |
1146 | res->SetName(buf); | |
1147 | newItem = new wxStaticBox(panel, -1, "Static", wxPoint(x, y), wxSize(200, 200), 0, buf); | |
9c331ded | 1148 | } |
f6bcfd97 | 1149 | else if (itemType == "wxGauge") |
457814b5 | 1150 | { |
f6bcfd97 BP |
1151 | prefix = "ID_GAUGE"; |
1152 | MakeUniqueName("gauge", buf); | |
1153 | res->SetName(buf); | |
1154 | newItem = new wxGauge(panel, -1, 10, wxPoint(x, y), wxSize(80, 30), wxHORIZONTAL, wxDefaultValidator, buf); | |
457814b5 | 1155 | } |
f6bcfd97 | 1156 | else if (itemType == "wxSlider") |
457814b5 | 1157 | { |
f6bcfd97 BP |
1158 | prefix = "ID_SLIDER"; |
1159 | MakeUniqueName("slider", buf); | |
1160 | res->SetName(buf); | |
1161 | newItem = new wxSlider(panel, -1, 1, 1, 10, wxPoint(x, y), wxSize(120, -1), wxHORIZONTAL, wxDefaultValidator, buf); | |
457814b5 | 1162 | } |
f6bcfd97 | 1163 | else if (itemType == "wxText" || itemType == "wxTextCtrl (single-line)") |
457814b5 | 1164 | { |
f6bcfd97 BP |
1165 | prefix = "ID_TEXTCTRL"; |
1166 | MakeUniqueName("textctrl", buf); | |
1167 | res->SetName(buf); | |
1168 | res->SetType("wxTextCtrl"); | |
1169 | newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, -1), 0, wxDefaultValidator, buf); | |
457814b5 | 1170 | } |
f6bcfd97 | 1171 | else if (itemType == "wxMultiText" || itemType == "wxTextCtrl (multi-line)") |
457814b5 | 1172 | { |
f6bcfd97 BP |
1173 | prefix = "ID_TEXTCTRL"; |
1174 | MakeUniqueName("textctrl", buf); | |
1175 | res->SetName(buf); | |
1176 | res->SetType("wxTextCtrl"); | |
1177 | newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, 100), wxTE_MULTILINE, wxDefaultValidator, buf); | |
457814b5 | 1178 | } |
f6bcfd97 | 1179 | else if (itemType == "wxScrollBar") |
457814b5 | 1180 | { |
f6bcfd97 BP |
1181 | prefix = "ID_SCROLLBAR"; |
1182 | MakeUniqueName("scrollbar", buf); | |
1183 | res->SetName(buf); | |
1184 | newItem = new wxScrollBar(panel, -1, wxPoint(x, y), wxSize(140, -1), wxHORIZONTAL, wxDefaultValidator, buf); | |
457814b5 | 1185 | } |
f6bcfd97 BP |
1186 | if (!newItem) |
1187 | return FALSE; | |
1188 | ||
1189 | int actualW, actualH; | |
1190 | newItem->GetSize(&actualW, &actualH); | |
1191 | wxSize actualSize(actualW, actualH); | |
1192 | ||
1193 | if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) | |
457814b5 | 1194 | { |
f6bcfd97 | 1195 | actualSize = panel->ConvertPixelsToDialog(actualSize); |
457814b5 | 1196 | } |
f6bcfd97 BP |
1197 | res->SetSize(res->GetX(), res->GetY(), actualSize.x, actualSize.y); |
1198 | ||
1199 | wxString newIdName; | |
1200 | int id = GenerateWindowId(prefix, newIdName); | |
1201 | res->SetId(id); | |
1202 | ||
1203 | // This is now guaranteed to be unique, so just add to symbol table | |
1204 | m_symbolTable.AddSymbol(newIdName, id); | |
1205 | ||
1206 | newItem->PushEventHandler(new wxResourceEditorControlHandler(newItem, newItem)); | |
1207 | ||
1208 | res->SetStyle(newItem->GetWindowStyleFlag()); | |
1209 | AssociateResource(res, newItem); | |
1210 | panelResource->GetChildren().Append(res); | |
1211 | ||
1212 | UpdateResourceList(); | |
1213 | ||
1214 | return TRUE; | |
457814b5 JS |
1215 | } |
1216 | ||
ae8351fc JS |
1217 | void wxResourceManager::ClearCurrentDialog() |
1218 | { | |
f6bcfd97 BP |
1219 | if (m_editorPanel->m_childWindow) |
1220 | { | |
1221 | SaveInfoAndDeleteHandler(m_editorPanel->m_childWindow); | |
1222 | DisassociateResource(m_editorPanel->m_childWindow); | |
1223 | DeleteWindow(m_editorPanel->m_childWindow); | |
1224 | m_editorPanel->m_childWindow = NULL; | |
1225 | m_editorPanel->Clear(); | |
1226 | } | |
ae8351fc JS |
1227 | } |
1228 | ||
03f68f12 JS |
1229 | bool wxResourceManager::TestCurrentDialog(wxWindow* parent) |
1230 | { | |
f6bcfd97 | 1231 | if (m_editorPanel->m_childWindow) |
03f68f12 | 1232 | { |
f6bcfd97 BP |
1233 | wxItemResource* item = FindResourceForWindow(m_editorPanel->m_childWindow); |
1234 | if (!item) | |
1235 | return FALSE; | |
1236 | ||
1237 | // Make sure the resources are up-to-date w.r.t. the window | |
1238 | InstantiateResourceFromWindow(item, m_editorPanel->m_childWindow, TRUE); | |
1239 | ||
1240 | ResourceEditorDialogTester* dialog = new ResourceEditorDialogTester; | |
1241 | bool success = FALSE; | |
1242 | if (dialog->LoadFromResource(parent, item->GetName(), & m_resourceTable)) | |
1243 | { | |
1244 | dialog->Centre(); | |
1245 | dialog->ShowModal(); | |
1246 | success = TRUE; | |
1247 | } | |
1248 | return success; | |
03f68f12 | 1249 | } |
f6bcfd97 | 1250 | return FALSE; |
03f68f12 JS |
1251 | } |
1252 | ||
457814b5 JS |
1253 | // Find the first dialog or panel for which |
1254 | // there is a selected panel item. | |
ae8351fc | 1255 | wxWindow *wxResourceManager::FindParentOfSelection() |
457814b5 | 1256 | { |
f6bcfd97 BP |
1257 | m_resourceTable.BeginFind(); |
1258 | wxNode *node; | |
1259 | while ((node = m_resourceTable.Next())) | |
457814b5 | 1260 | { |
f6bcfd97 BP |
1261 | wxItemResource *res = (wxItemResource *)node->Data(); |
1262 | wxWindow *win = FindWindowForResource(res); | |
1263 | if (win) | |
1264 | { | |
1265 | wxNode *node1 = win->GetChildren().First(); | |
1266 | while (node1) | |
1267 | { | |
1268 | wxControl *item = (wxControl *)node1->Data(); | |
1269 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
1270 | if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected()) | |
1271 | return win; | |
1272 | node1 = node1->Next(); | |
1273 | } | |
1274 | } | |
457814b5 | 1275 | } |
f6bcfd97 | 1276 | return NULL; |
457814b5 JS |
1277 | } |
1278 | ||
1279 | // Format the panel items according to 'flag' | |
1280 | void wxResourceManager::AlignItems(int flag) | |
1281 | { | |
f6bcfd97 BP |
1282 | wxWindow *win = FindParentOfSelection(); |
1283 | if (!win) | |
1284 | return; | |
457814b5 | 1285 | |
f6bcfd97 BP |
1286 | wxNode *node = GetSelections().First(); |
1287 | if (!node) | |
1288 | return; | |
457814b5 | 1289 | |
f6bcfd97 BP |
1290 | wxControl *firstSelection = (wxControl *)node->Data(); |
1291 | if (firstSelection->GetParent() != win) | |
1292 | return; | |
1293 | ||
1294 | int firstX, firstY; | |
1295 | int firstW, firstH; | |
1296 | firstSelection->GetPosition(&firstX, &firstY); | |
1297 | firstSelection->GetSize(&firstW, &firstH); | |
1298 | int centreX = (int)(firstX + (firstW / 2)); | |
1299 | int centreY = (int)(firstY + (firstH / 2)); | |
1300 | ||
1301 | while ((node = node->Next())) | |
457814b5 | 1302 | { |
f6bcfd97 BP |
1303 | wxControl *item = (wxControl *)node->Data(); |
1304 | if (item->GetParent() == win) | |
457814b5 | 1305 | { |
f6bcfd97 BP |
1306 | int x, y, w, h; |
1307 | item->GetPosition(&x, &y); | |
1308 | item->GetSize(&w, &h); | |
1309 | ||
1310 | int newX, newY; | |
1311 | ||
1312 | switch (flag) | |
1313 | { | |
1314 | case TOOLBAR_FORMAT_HORIZ: | |
1315 | { | |
1316 | newX = x; | |
1317 | newY = (int)(centreY - (h/2.0)); | |
1318 | break; | |
1319 | } | |
1320 | case TOOLBAR_FORMAT_VERT: | |
1321 | { | |
1322 | newX = (int)(centreX - (w/2.0)); | |
1323 | newY = y; | |
1324 | break; | |
1325 | } | |
1326 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: | |
1327 | { | |
1328 | newX = firstX; | |
1329 | newY = y; | |
1330 | break; | |
1331 | } | |
1332 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: | |
1333 | { | |
1334 | newX = x; | |
1335 | newY = firstY; | |
1336 | break; | |
1337 | } | |
1338 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: | |
1339 | { | |
1340 | newX = firstX + firstW - w; | |
1341 | newY = y; | |
1342 | break; | |
1343 | } | |
1344 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: | |
1345 | { | |
1346 | newX = x; | |
1347 | newY = firstY + firstH - h; | |
1348 | break; | |
1349 | } | |
1350 | default: | |
1351 | newX = x; newY = y; | |
1352 | break; | |
1353 | } | |
1354 | ||
1355 | wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item); | |
1356 | wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent()); | |
1357 | ||
1358 | item->SetSize(newX, newY, w, h); | |
1359 | ||
1360 | // Also update the associated resource | |
1361 | // We need to convert to dialog units if this is not a dialog or panel, but | |
1362 | // the parent resource specifies dialog units. | |
1363 | if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) | |
1364 | { | |
1365 | wxPoint pt = item->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY)); | |
1366 | newX = pt.x; newY = pt.y; | |
1367 | wxSize sz = item->GetParent()->ConvertPixelsToDialog(wxSize(w, h)); | |
1368 | w = sz.x; h = sz.y; | |
1369 | } | |
1370 | resource->SetSize(newX, newY, w, h); | |
457814b5 | 1371 | } |
f6bcfd97 BP |
1372 | } |
1373 | win->Refresh(); | |
1374 | } | |
1375 | ||
1376 | // Copy the first image's size to subsequent images | |
1377 | void wxResourceManager::CopySize(int command) | |
1378 | { | |
1379 | bool copyWidth = (command == TOOLBAR_COPY_SIZE || command == TOOLBAR_COPY_WIDTH) ; | |
1380 | bool copyHeight = (command == TOOLBAR_COPY_SIZE || command == TOOLBAR_COPY_HEIGHT) ; | |
1381 | ||
1382 | wxWindow *win = FindParentOfSelection(); | |
1383 | if (!win) | |
1384 | return; | |
1385 | ||
1386 | wxNode *node = GetSelections().First(); | |
1387 | if (!node) | |
1388 | return; | |
1389 | ||
1390 | wxControl *firstSelection = (wxControl *)node->Data(); | |
1391 | if (firstSelection->GetParent() != win) | |
1392 | return; | |
1393 | ||
1394 | int firstX, firstY; | |
1395 | int firstW, firstH; | |
1396 | firstSelection->GetPosition(&firstX, &firstY); | |
1397 | firstSelection->GetSize(&firstW, &firstH); | |
1398 | ||
1399 | while ((node = node->Next())) | |
1400 | { | |
1401 | wxControl *item = (wxControl *)node->Data(); | |
1402 | if (item->GetParent() == win) | |
457814b5 | 1403 | { |
f6bcfd97 BP |
1404 | wxSize sz = item->GetSize(); |
1405 | int widthToSet = (copyWidth ? firstW : sz.x); | |
1406 | int heightToSet = (copyHeight ? firstH : sz.y); | |
1407 | ||
1408 | item->SetSize(-1, -1, widthToSet, heightToSet); | |
1409 | ||
1410 | wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item); | |
1411 | wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent()); | |
1412 | ||
1413 | widthToSet = resource->GetWidth(); | |
1414 | heightToSet = resource->GetHeight(); | |
1415 | ||
1416 | // Also update the associated resource | |
1417 | // We need to convert to dialog units if this is not a dialog or panel, but | |
1418 | // the parent resource specifies dialog units. | |
1419 | if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) | |
1420 | { | |
1421 | wxSize convertedSize = item->GetParent()->ConvertPixelsToDialog(wxSize(firstW, firstH)); | |
1422 | if (copyWidth) | |
1423 | widthToSet = convertedSize.x; | |
1424 | if (copyHeight) | |
1425 | heightToSet = convertedSize.y; | |
1426 | } | |
1427 | resource->SetSize(resource->GetX(), resource->GetY(), widthToSet, heightToSet); | |
457814b5 | 1428 | } |
f6bcfd97 BP |
1429 | } |
1430 | win->Refresh(); | |
1431 | } | |
1432 | ||
1433 | void wxResourceManager::ToBackOrFront(bool toBack) | |
1434 | { | |
1435 | wxWindow *win = FindParentOfSelection(); | |
1436 | if (!win) | |
1437 | return; | |
1438 | wxItemResource *winResource = FindResourceForWindow(win); | |
1439 | ||
1440 | wxNode *node = GetSelections().First(); | |
1441 | while (node) | |
1442 | { | |
1443 | wxControl *item = (wxControl *)node->Data(); | |
1444 | wxItemResource *itemResource = FindResourceForWindow(item); | |
1445 | if (item->GetParent() == win) | |
457814b5 | 1446 | { |
f6bcfd97 BP |
1447 | win->GetChildren().DeleteObject(item); |
1448 | if (winResource) | |
1449 | winResource->GetChildren().DeleteObject(itemResource); | |
1450 | if (toBack) | |
1451 | { | |
1452 | win->GetChildren().Insert(item); | |
1453 | if (winResource) | |
1454 | winResource->GetChildren().Insert(itemResource); | |
1455 | } | |
1456 | else | |
1457 | { | |
1458 | win->GetChildren().Append(item); | |
1459 | if (winResource) | |
1460 | winResource->GetChildren().Append(itemResource); | |
1461 | } | |
457814b5 | 1462 | } |
f6bcfd97 | 1463 | node = node->Next(); |
457814b5 | 1464 | } |
f6bcfd97 | 1465 | // win->Refresh(); |
457814b5 JS |
1466 | } |
1467 | ||
f6bcfd97 BP |
1468 | // Distribute controls evenly between first and last |
1469 | void wxResourceManager::DistributePositions(int command) | |
457814b5 | 1470 | { |
f6bcfd97 | 1471 | bool horizontal = (command == TOOLBAR_DISTRIBUTE_HORIZ) ; |
457814b5 | 1472 | |
f6bcfd97 BP |
1473 | wxWindow *win = FindParentOfSelection(); |
1474 | if (!win) | |
1475 | return; | |
457814b5 | 1476 | |
f6bcfd97 BP |
1477 | if (GetSelections().Number() < 3) |
1478 | { | |
1479 | wxMessageBox(wxT("Sorry, distributing less than three controls does not make sense.")); | |
1480 | return; | |
1481 | } | |
457814b5 | 1482 | |
f6bcfd97 BP |
1483 | wxControl *firstSelection = (wxControl*) GetSelections().First()->Data(); |
1484 | wxControl *lastSelection = (wxControl*) GetSelections().Last()->Data(); | |
457814b5 | 1485 | |
f6bcfd97 BP |
1486 | // For now, assume the ordering is correct (the user selected the controls in order). |
1487 | // TODO: explicitly order the selections in terms of increading x or y position. | |
3013b6f4 | 1488 | |
f6bcfd97 BP |
1489 | // Find the total amount of space between all controls |
1490 | int totalControlSpace = 0; // How much space the controls take up | |
8caa4ed1 | 1491 | |
f6bcfd97 BP |
1492 | wxNode* node = GetSelections().First(); |
1493 | while (node) | |
1494 | { | |
1495 | wxControl* control = (wxControl*) node->Data(); | |
3013b6f4 | 1496 | |
f6bcfd97 BP |
1497 | int x, y; |
1498 | int w, h; | |
1499 | control->GetPosition(&x, &y); | |
1500 | control->GetSize(&w, &h); | |
3013b6f4 | 1501 | |
f6bcfd97 BP |
1502 | // Don't include the space taken up by the first and last controls. |
1503 | if (control != firstSelection && control != lastSelection) | |
1504 | { | |
1505 | if (horizontal) | |
1506 | totalControlSpace += w; | |
1507 | else | |
1508 | totalControlSpace += h; | |
1509 | } | |
457814b5 | 1510 | |
f6bcfd97 BP |
1511 | node = node->Next(); |
1512 | } | |
1513 | ||
1514 | ||
1515 | int firstX, firstY, lastX, lastY; | |
1516 | int firstW, firstH, lastW, lastH; | |
1517 | firstSelection->GetPosition(&firstX, &firstY); | |
1518 | firstSelection->GetSize(&firstW, &firstH); | |
1519 | ||
1520 | lastSelection->GetPosition(&lastX, &lastY); | |
1521 | lastSelection->GetSize(&lastW, &lastH); | |
1522 | ||
1523 | /* | |
1524 | ||
1525 | firstX lastX | |
1526 | |===| |====| |======| |==| | |
1527 | ||
1528 | */ | |
1529 | ||
1530 | int spacing, currentPos; | |
1531 | if (horizontal) | |
1532 | { | |
1533 | spacing = ((lastX - (firstX + firstW)) - totalControlSpace) / (GetSelections().Number() - 1); | |
1534 | currentPos = firstX + firstW + spacing; | |
1535 | } | |
1536 | else | |
1537 | { | |
1538 | spacing = ((lastY - (firstY + firstH)) - totalControlSpace) / (GetSelections().Number() - 1); | |
1539 | currentPos = firstY + firstH + spacing; | |
1540 | } | |
1541 | ||
1542 | node = GetSelections().First(); | |
1543 | ||
1544 | while ((node = node->Next())) | |
1545 | { | |
1546 | wxControl *item = (wxControl *)node->Data(); | |
1547 | wxSize sz = item->GetSize(); | |
1548 | wxPoint pos = item->GetPosition(); | |
1549 | wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item); | |
1550 | wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent()); | |
1551 | ||
1552 | int controlX = (horizontal ? currentPos : pos.x); | |
1553 | int controlY = (horizontal ? pos.y : currentPos); | |
1554 | ||
1555 | item->Move(controlX, controlY); | |
1556 | ||
1557 | int resX = controlX; | |
1558 | int resY = controlY; | |
1559 | ||
1560 | // Also update the associated resource | |
1561 | // We need to convert to dialog units if this is not a dialog or panel, but | |
1562 | // the parent resource specifies dialog units. | |
1563 | if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) | |
1564 | { | |
1565 | wxPoint convertedPos = item->GetParent()->ConvertPixelsToDialog(wxPoint(resX, resY)); | |
1566 | resX = convertedPos.x; | |
1567 | resY = convertedPos.y; | |
1568 | } | |
1569 | resource->SetSize(resX, resY, resource->GetWidth(), resource->GetHeight()); | |
1570 | ||
1571 | currentPos += (horizontal ? (sz.x + spacing) : (sz.y + spacing)); | |
1572 | } | |
1573 | win->Refresh(); | |
457814b5 JS |
1574 | } |
1575 | ||
1576 | void wxResourceManager::AddSelection(wxWindow *win) | |
1577 | { | |
f6bcfd97 BP |
1578 | if (!m_selections.Member(win)) |
1579 | m_selections.Append(win); | |
457814b5 JS |
1580 | } |
1581 | ||
1582 | void wxResourceManager::RemoveSelection(wxWindow *win) | |
1583 | { | |
f6bcfd97 | 1584 | m_selections.DeleteObject(win); |
457814b5 JS |
1585 | } |
1586 | ||
30b5fc11 JS |
1587 | void wxResourceManager::DeselectItemIfNecessary(wxWindow *win) |
1588 | { | |
1589 | if (win->IsKindOf(CLASSINFO(wxControl)) && (win->GetEventHandler() != win)) | |
1590 | { | |
1591 | // Deselect and refresh window in case we leave selection | |
1592 | // handles behind | |
1593 | wxControl *item = (wxControl *)win; | |
1594 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
1595 | if (childHandler->IsSelected()) | |
1596 | { | |
1597 | wxResourceManager::GetCurrentResourceManager()->RemoveSelection(item); | |
1598 | childHandler->SelectItem(FALSE); | |
1599 | #ifndef __WXGTK__ | |
1600 | item->GetParent()->Refresh(); | |
1601 | #endif | |
1602 | } | |
1603 | } | |
1604 | } | |
1605 | ||
457814b5 JS |
1606 | // Need to search through resource table removing this from |
1607 | // any resource which has this as a parent. | |
1608 | bool wxResourceManager::RemoveResourceFromParent(wxItemResource *res) | |
1609 | { | |
f6bcfd97 BP |
1610 | m_resourceTable.BeginFind(); |
1611 | wxNode *node; | |
1612 | while ((node = m_resourceTable.Next())) | |
457814b5 | 1613 | { |
f6bcfd97 BP |
1614 | wxItemResource *thisRes = (wxItemResource *)node->Data(); |
1615 | if (thisRes->GetChildren().Member(res)) | |
1616 | { | |
1617 | thisRes->GetChildren().DeleteObject(res); | |
1618 | return TRUE; | |
1619 | } | |
457814b5 | 1620 | } |
f6bcfd97 | 1621 | return FALSE; |
457814b5 JS |
1622 | } |
1623 | ||
1624 | bool wxResourceManager::DeleteResource(wxItemResource *res) | |
1625 | { | |
f6bcfd97 BP |
1626 | if (!res) |
1627 | return FALSE; | |
1628 | ||
1629 | RemoveResourceFromParent(res); | |
1630 | ||
1631 | wxNode *node = res->GetChildren().First(); | |
1632 | while (node) | |
1633 | { | |
1634 | wxNode *next = node->Next(); | |
1635 | wxItemResource *child = (wxItemResource *)node->Data(); | |
1636 | DeleteResource(child); | |
1637 | node = next; | |
1638 | } | |
1639 | ||
1640 | // If this is a button or message resource, delete the | |
1641 | // associate bitmap resource if not being used. | |
1642 | wxString resType(res->GetType()); | |
1643 | ||
1644 | /* shouldn't have to do this now bitmaps are ref-counted | |
1645 | if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4()) | |
1646 | { | |
457814b5 | 1647 | PossiblyDeleteBitmapResource(res->GetValue4()); |
f6bcfd97 BP |
1648 | } |
1649 | */ | |
1650 | ||
1651 | // Remove symbol from table if appropriate | |
1652 | if (!IsSymbolUsed(res, res->GetId())) | |
1653 | { | |
1654 | m_symbolTable.RemoveSymbol(res->GetId()); | |
1655 | } | |
1656 | ||
1657 | m_resourceTable.Delete(res->GetName()); | |
1658 | delete res; | |
1659 | Modify(TRUE); | |
1660 | return TRUE; | |
457814b5 JS |
1661 | } |
1662 | ||
ae8351fc | 1663 | bool wxResourceManager::DeleteResource(wxWindow *win) |
457814b5 | 1664 | { |
f6bcfd97 BP |
1665 | DeselectItemIfNecessary(win); |
1666 | ||
1667 | wxItemResource *res = FindResourceForWindow(win); | |
1668 | ||
1669 | DisassociateResource(res); | |
1670 | DeleteResource(res); | |
1671 | UpdateResourceList(); | |
1672 | ||
1673 | return TRUE; | |
457814b5 JS |
1674 | } |
1675 | ||
1676 | // Will eventually have bitmap type information, for different | |
1677 | // kinds of bitmap. | |
fd71308f | 1678 | wxString wxResourceManager::AddBitmapResource(const wxString& filename) |
457814b5 | 1679 | { |
f6bcfd97 BP |
1680 | wxItemResource *resource = FindBitmapResourceByFilename(filename); |
1681 | if (!resource) | |
1682 | { | |
1683 | char buf[256]; | |
1684 | MakeUniqueName("bitmap", buf); | |
1685 | resource = new wxItemResource; | |
1686 | resource->SetType("wxBitmap"); | |
1687 | resource->SetName(buf); | |
1688 | ||
1689 | // A bitmap resource has one or more children, specifying | |
1690 | // alternative bitmaps. | |
1691 | wxItemResource *child = new wxItemResource; | |
1692 | child->SetType("wxBitmap"); | |
1693 | child->SetName(filename); | |
1694 | child->SetValue1(wxBITMAP_TYPE_BMP); | |
1695 | child->SetValue2(RESOURCE_PLATFORM_ANY); | |
1696 | child->SetValue3(0); // Depth | |
1697 | child->SetSize(0,0,0,0); | |
1698 | resource->GetChildren().Append(child); | |
1699 | ||
1700 | m_resourceTable.AddResource(resource); | |
1701 | ||
1702 | UpdateResourceList(); | |
1703 | } | |
1704 | if (resource) | |
1705 | return resource->GetName(); | |
1706 | else | |
1707 | return wxEmptyString; | |
457814b5 JS |
1708 | } |
1709 | ||
f6bcfd97 | 1710 | // Delete the bitmap resource if it isn't being used by another resource. |
fd71308f | 1711 | void wxResourceManager::PossiblyDeleteBitmapResource(const wxString& resourceName) |
457814b5 | 1712 | { |
f6bcfd97 BP |
1713 | if (!IsBitmapResourceUsed(resourceName)) |
1714 | { | |
1715 | wxItemResource *res = m_resourceTable.FindResource(resourceName); | |
1716 | DeleteResource(res); | |
1717 | UpdateResourceList(); | |
1718 | } | |
457814b5 JS |
1719 | } |
1720 | ||
fd71308f | 1721 | bool wxResourceManager::IsBitmapResourceUsed(const wxString& resourceName) |
457814b5 | 1722 | { |
f6bcfd97 BP |
1723 | m_resourceTable.BeginFind(); |
1724 | wxNode *node; | |
1725 | while ((node = m_resourceTable.Next())) | |
457814b5 | 1726 | { |
f6bcfd97 BP |
1727 | wxItemResource *res = (wxItemResource *)node->Data(); |
1728 | wxString resType(res->GetType()); | |
1729 | if (resType == "wxDialog") | |
1730 | { | |
1731 | wxNode *node1 = res->GetChildren().First(); | |
1732 | while (node1) | |
1733 | { | |
1734 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1735 | wxString childResType(child->GetType()); | |
1736 | ||
1737 | if ((childResType == "wxMessage" || childResType == "wxButton") && | |
1738 | child->GetValue4() && | |
1739 | (strcmp(child->GetValue4(), resourceName) == 0)) | |
1740 | return TRUE; | |
1741 | node1 = node1->Next(); | |
1742 | } | |
1743 | } | |
457814b5 | 1744 | } |
f6bcfd97 | 1745 | return FALSE; |
457814b5 JS |
1746 | } |
1747 | ||
1748 | // Given a wxButton or wxMessage, find the corresponding bitmap filename. | |
fd71308f | 1749 | wxString wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource) |
457814b5 | 1750 | { |
f6bcfd97 BP |
1751 | if (!resource || (resource->GetValue4() == "")) |
1752 | return wxEmptyString; | |
1753 | wxItemResource *bitmapResource = m_resourceTable.FindResource(resource->GetValue4()); | |
1754 | if (!bitmapResource) | |
1755 | return wxEmptyString; | |
457814b5 | 1756 | |
f6bcfd97 BP |
1757 | wxNode *node = bitmapResource->GetChildren().First(); |
1758 | while (node) | |
1759 | { | |
1760 | // Eventually augment this to return a bitmap of the right kind or something... | |
1761 | // Maybe the root of the filename remains the same, so it doesn't matter which we | |
1762 | // pick up. Otherwise how do we specify multiple filenames... too boring... | |
1763 | wxItemResource *child = (wxItemResource *)node->Data(); | |
1764 | return child->GetName(); | |
1765 | ||
1766 | //node = node->Next(); | |
1767 | } | |
1768 | return wxEmptyString; | |
457814b5 JS |
1769 | } |
1770 | ||
fd71308f | 1771 | wxItemResource *wxResourceManager::FindBitmapResourceByFilename(const wxString& filename) |
457814b5 | 1772 | { |
f6bcfd97 BP |
1773 | m_resourceTable.BeginFind(); |
1774 | wxNode *node; | |
1775 | while ((node = m_resourceTable.Next())) | |
457814b5 | 1776 | { |
f6bcfd97 BP |
1777 | wxItemResource *res = (wxItemResource *)node->Data(); |
1778 | wxString resType(res->GetType()); | |
1779 | if (resType == "wxBitmap") | |
1780 | { | |
1781 | wxNode *node1 = res->GetChildren().First(); | |
1782 | while (node1) | |
1783 | { | |
1784 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1785 | if (child->GetName() && (strcmp(child->GetName(), filename) == 0)) | |
1786 | return res; | |
1787 | node1 = node1->Next(); | |
1788 | } | |
1789 | } | |
457814b5 | 1790 | } |
f6bcfd97 | 1791 | return NULL; |
457814b5 JS |
1792 | } |
1793 | ||
5de76427 JS |
1794 | // Is this window identifier symbol in use? |
1795 | // Let's assume that we can't have 2 names for the same integer id. | |
1796 | // Therefore we can tell by the integer id whether the symbol is | |
1797 | // in use. | |
1798 | bool wxResourceManager::IsSymbolUsed(wxItemResource* thisResource, wxWindowID id) | |
1799 | { | |
f6bcfd97 BP |
1800 | m_resourceTable.BeginFind(); |
1801 | wxNode *node; | |
1802 | while ((node = m_resourceTable.Next())) | |
5de76427 | 1803 | { |
f6bcfd97 BP |
1804 | wxItemResource *res = (wxItemResource *)node->Data(); |
1805 | ||
1806 | wxString resType(res->GetType()); | |
1807 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
1808 | { | |
1809 | if ((res != thisResource) && (res->GetId() == id)) | |
1810 | return TRUE; | |
1811 | ||
1812 | wxNode *node1 = res->GetChildren().First(); | |
1813 | while (node1) | |
1814 | { | |
1815 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1816 | if ((child != thisResource) && (child->GetId() == id)) | |
1817 | return TRUE; | |
1818 | node1 = node1->Next(); | |
1819 | } | |
1820 | } | |
5de76427 | 1821 | } |
f6bcfd97 | 1822 | return FALSE; |
5de76427 JS |
1823 | } |
1824 | ||
1825 | // Is this window identifier compatible with the given name? (i.e. | |
1826 | // does it already exist under a different name) | |
1827 | bool wxResourceManager::IsIdentifierOK(const wxString& name, wxWindowID id) | |
1828 | { | |
1829 | if (m_symbolTable.SymbolExists(name)) | |
1830 | { | |
1831 | int foundId = m_symbolTable.GetIdForSymbol(name); | |
1832 | if (foundId != id) | |
1833 | return FALSE; | |
1834 | } | |
1835 | return TRUE; | |
1836 | } | |
1837 | ||
1838 | // Change all integer ids that match oldId, to newId. | |
1839 | // This is necessary if an id is changed for one resource - all resources | |
1840 | // must be changed. | |
1841 | void wxResourceManager::ChangeIds(int oldId, int newId) | |
1842 | { | |
f6bcfd97 BP |
1843 | m_resourceTable.BeginFind(); |
1844 | wxNode *node; | |
1845 | while ((node = m_resourceTable.Next())) | |
5de76427 | 1846 | { |
f6bcfd97 BP |
1847 | wxItemResource *res = (wxItemResource *)node->Data(); |
1848 | ||
1849 | wxString resType(res->GetType()); | |
1850 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
1851 | { | |
1852 | if (res->GetId() == oldId) | |
1853 | res->SetId(newId); | |
1854 | ||
1855 | wxNode *node1 = res->GetChildren().First(); | |
1856 | while (node1) | |
1857 | { | |
1858 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1859 | if (child->GetId() == oldId) | |
1860 | child->SetId(newId); | |
1861 | ||
1862 | node1 = node1->Next(); | |
1863 | } | |
1864 | } | |
5de76427 | 1865 | } |
5de76427 JS |
1866 | } |
1867 | ||
bbcdf8bc JS |
1868 | // If any resource ids were missing (or their symbol was missing), |
1869 | // repair them i.e. give them new ids. Returns TRUE if any resource | |
1870 | // needed repairing. | |
1871 | bool wxResourceManager::RepairResourceIds() | |
1872 | { | |
f6bcfd97 BP |
1873 | bool repaired = FALSE; |
1874 | ||
1875 | m_resourceTable.BeginFind(); | |
1876 | wxNode *node; | |
1877 | while ((node = m_resourceTable.Next())) | |
bbcdf8bc | 1878 | { |
f6bcfd97 BP |
1879 | wxItemResource *res = (wxItemResource *)node->Data(); |
1880 | wxString resType(res->GetType()); | |
1881 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
bbcdf8bc | 1882 | { |
f6bcfd97 BP |
1883 | |
1884 | if ( (res->GetId() == 0) || ((res->GetId() > 0) && !m_symbolTable.IdExists(res->GetId())) ) | |
bbcdf8bc | 1885 | { |
f6bcfd97 BP |
1886 | wxString newSymbolName; |
1887 | int newId = GenerateWindowId("ID_DIALOG", newSymbolName) ; | |
1888 | ||
1889 | if (res->GetId() == 0) | |
1890 | { | |
1891 | res->SetId(newId); | |
1892 | m_symbolTable.AddSymbol(newSymbolName, newId); | |
1893 | } | |
1894 | else | |
1895 | { | |
1896 | m_symbolTable.AddSymbol(newSymbolName, res->GetId()); | |
1897 | } | |
1898 | ||
1899 | repaired = TRUE; | |
bbcdf8bc | 1900 | } |
f6bcfd97 BP |
1901 | |
1902 | wxNode *node1 = res->GetChildren().First(); | |
1903 | while (node1) | |
bbcdf8bc | 1904 | { |
f6bcfd97 BP |
1905 | wxItemResource *child = (wxItemResource *)node1->Data(); |
1906 | ||
1907 | if ( (child->GetId() == 0) || ((child->GetId() > 0) && !m_symbolTable.IdExists(child->GetId())) ) | |
1908 | { | |
1909 | wxString newSymbolName; | |
1910 | int newId = GenerateWindowId("ID_CONTROL", newSymbolName) ; | |
1911 | ||
1912 | if (child->GetId() == 0) | |
1913 | { | |
1914 | child->SetId(newId); | |
1915 | m_symbolTable.AddSymbol(newSymbolName, newId); | |
1916 | } | |
1917 | else | |
1918 | { | |
1919 | m_symbolTable.AddSymbol(newSymbolName, child->GetId()); | |
1920 | } | |
1921 | ||
1922 | repaired = TRUE; | |
1923 | } | |
1924 | ||
1925 | node1 = node1->Next(); | |
bbcdf8bc | 1926 | } |
bbcdf8bc | 1927 | } |
bbcdf8bc | 1928 | } |
f6bcfd97 | 1929 | return repaired; |
bbcdf8bc JS |
1930 | } |
1931 | ||
1932 | ||
f6bcfd97 BP |
1933 | // Deletes 'win' and creates a new window from the resource that |
1934 | // was associated with it. E.g. if you can't change properties on the | |
1935 | // fly, you'll need to delete the window and create it again. | |
30b5fc11 | 1936 | wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info, bool instantiateFirst) |
457814b5 | 1937 | { |
f6bcfd97 | 1938 | wxItemResource *resource = FindResourceForWindow(win); |
457814b5 | 1939 | |
f6bcfd97 BP |
1940 | // Put the current window properties into the wxItemResource object |
1941 | ||
1942 | wxWindowPropertyInfo *newInfo = NULL; | |
1943 | if (!info) | |
1944 | { | |
1945 | newInfo = CreatePropertyInfoForWindow(win); | |
1946 | info = newInfo; | |
1947 | } | |
1948 | ||
1949 | // May not always want to copy values back from the resource | |
1950 | if (instantiateFirst) | |
1951 | info->InstantiateResource(resource); | |
1952 | ||
1953 | wxWindow *newWin = NULL; | |
1954 | wxWindow *parent = win->GetParent(); | |
1955 | wxItemResource* parentResource = NULL; | |
1956 | if (parent) | |
1957 | parentResource = FindResourceForWindow(parent); | |
1958 | ||
1959 | if (win->IsKindOf(CLASSINFO(wxPanel))) | |
1960 | { | |
1961 | Edit(resource); | |
1962 | newWin = FindWindowForResource(resource); | |
1963 | } | |
1964 | else | |
1965 | { | |
1966 | DisassociateResource(resource); | |
1967 | if (win->GetEventHandler() != win) | |
1968 | win->PopEventHandler(TRUE); | |
1969 | ||
1970 | DeleteWindow(win); | |
1971 | newWin = m_resourceTable.CreateItem((wxPanel *)parent, resource, parentResource); | |
1972 | newWin->PushEventHandler(new wxResourceEditorControlHandler((wxControl*) newWin, (wxControl*) newWin)); | |
1973 | AssociateResource(resource, newWin); | |
1974 | UpdateResourceList(); | |
1975 | } | |
1976 | ||
1977 | if (info) | |
1978 | info->SetPropertyWindow(newWin); | |
1979 | ||
1980 | if (newInfo) | |
1981 | delete newInfo; | |
1982 | ||
1983 | return newWin; | |
457814b5 JS |
1984 | } |
1985 | ||
1986 | // Delete resource highlighted in the listbox | |
ae8351fc | 1987 | bool wxResourceManager::DeleteSelection() |
457814b5 | 1988 | { |
f6bcfd97 BP |
1989 | int sel = m_editorResourceTree->GetSelection(); |
1990 | if (sel != 0) | |
457814b5 | 1991 | { |
f6bcfd97 BP |
1992 | wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel); |
1993 | wxItemResource *res = data->GetResource(); | |
1994 | wxWindow *win = FindWindowForResource(res); | |
1995 | if (win) | |
1996 | { | |
1997 | DeleteResource(win); | |
1998 | DeleteWindow(win); | |
1999 | UpdateResourceList(); | |
2000 | Modify(TRUE); | |
2001 | } | |
2002 | return TRUE; | |
457814b5 | 2003 | } |
f6bcfd97 BP |
2004 | |
2005 | return FALSE; | |
457814b5 JS |
2006 | } |
2007 | ||
2008 | // Delete resource highlighted in the listbox | |
ae8351fc | 2009 | bool wxResourceManager::RecreateSelection() |
457814b5 | 2010 | { |
f6bcfd97 BP |
2011 | wxNode *node = GetSelections().First(); |
2012 | while (node) | |
2013 | { | |
2014 | wxControl *item = (wxControl *)node->Data(); | |
2015 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
2016 | wxNode *next = node->Next(); | |
2017 | childHandler->SelectItem(FALSE); | |
2018 | ||
2019 | RemoveSelection(item); | |
2020 | ||
2021 | RecreateWindowFromResource(item); | |
2022 | ||
2023 | node = next; | |
2024 | } | |
2025 | return TRUE; | |
457814b5 JS |
2026 | } |
2027 | ||
fd71308f | 2028 | bool wxResourceManager::EditDialog(wxDialog *WXUNUSED(dialog), wxWindow *WXUNUSED(parent)) |
457814b5 | 2029 | { |
f6bcfd97 | 2030 | return FALSE; |
457814b5 JS |
2031 | } |
2032 | ||
457814b5 JS |
2033 | // Ensures that all currently shown windows are saved to resources, |
2034 | // e.g. just before writing to a .wxr file. | |
ae8351fc | 2035 | bool wxResourceManager::InstantiateAllResourcesFromWindows() |
457814b5 | 2036 | { |
f6bcfd97 BP |
2037 | m_resourceTable.BeginFind(); |
2038 | wxNode *node; | |
2039 | while ((node = m_resourceTable.Next())) | |
457814b5 | 2040 | { |
f6bcfd97 BP |
2041 | wxItemResource *res = (wxItemResource *)node->Data(); |
2042 | wxString resType(res->GetType()); | |
2043 | ||
2044 | if (resType == "wxDialog") | |
2045 | { | |
2046 | wxWindow *win = (wxWindow *)FindWindowForResource(res); | |
2047 | if (win) | |
2048 | InstantiateResourceFromWindow(res, win, TRUE); | |
2049 | } | |
2050 | else if (resType == "wxPanel") | |
2051 | { | |
2052 | wxWindow *win = (wxWindow *)FindWindowForResource(res); | |
2053 | if (win) | |
2054 | InstantiateResourceFromWindow(res, win, TRUE); | |
2055 | } | |
457814b5 | 2056 | } |
f6bcfd97 | 2057 | return TRUE; |
457814b5 JS |
2058 | } |
2059 | ||
2060 | bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse) | |
2061 | { | |
f6bcfd97 BP |
2062 | wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(window); |
2063 | info->SetResource(resource); | |
2064 | info->InstantiateResource(resource); | |
2065 | delete info; | |
2066 | ||
2067 | if (recurse) | |
457814b5 | 2068 | { |
f6bcfd97 BP |
2069 | wxNode *node = resource->GetChildren().First(); |
2070 | while (node) | |
2071 | { | |
2072 | wxItemResource *child = (wxItemResource *)node->Data(); | |
2073 | wxWindow *childWindow = FindWindowForResource(child); | |
2074 | ||
2075 | if (!childWindow) | |
2076 | { | |
2077 | char buf[200]; | |
2078 | sprintf(buf, "Could not find window %s", (const char*) child->GetName()); | |
2079 | wxMessageBox(buf, "Dialog Editor problem", wxOK); | |
2080 | } | |
2081 | else | |
2082 | InstantiateResourceFromWindow(child, childWindow, recurse); | |
2083 | node = node->Next(); | |
2084 | } | |
2085 | } | |
2086 | ||
2087 | return TRUE; | |
457814b5 JS |
2088 | } |
2089 | ||
ae8351fc JS |
2090 | // Create a window information object for the give window |
2091 | wxWindowPropertyInfo *wxResourceManager::CreatePropertyInfoForWindow(wxWindow *win) | |
2092 | { | |
f6bcfd97 BP |
2093 | wxWindowPropertyInfo *info = NULL; |
2094 | if (win->IsKindOf(CLASSINFO(wxScrollBar))) | |
2095 | { | |
2096 | info = new wxScrollBarPropertyInfo(win); | |
2097 | } | |
2098 | else if (win->IsKindOf(CLASSINFO(wxStaticBox))) | |
2099 | { | |
2100 | info = new wxGroupBoxPropertyInfo(win); | |
2101 | } | |
2102 | else if (win->IsKindOf(CLASSINFO(wxCheckBox))) | |
2103 | { | |
2104 | info = new wxCheckBoxPropertyInfo(win); | |
2105 | } | |
2106 | else if (win->IsKindOf(CLASSINFO(wxSlider))) | |
2107 | { | |
2108 | info = new wxSliderPropertyInfo(win); | |
2109 | } | |
2110 | else if (win->IsKindOf(CLASSINFO(wxGauge))) | |
2111 | { | |
2112 | info = new wxGaugePropertyInfo(win); | |
2113 | } | |
2114 | else if (win->IsKindOf(CLASSINFO(wxListBox))) | |
2115 | { | |
2116 | info = new wxListBoxPropertyInfo(win); | |
2117 | } | |
2118 | else if (win->IsKindOf(CLASSINFO(wxRadioBox))) | |
2119 | { | |
2120 | info = new wxRadioBoxPropertyInfo(win); | |
2121 | } | |
2122 | else if (win->IsKindOf(CLASSINFO(wxRadioButton))) | |
2123 | { | |
2124 | info = new wxRadioButtonPropertyInfo(win); | |
2125 | } | |
2126 | else if (win->IsKindOf(CLASSINFO(wxComboBox))) | |
2127 | { | |
2128 | info = new wxComboBoxPropertyInfo(win); | |
2129 | } | |
2130 | else if (win->IsKindOf(CLASSINFO(wxChoice))) | |
2131 | { | |
2132 | info = new wxChoicePropertyInfo(win); | |
2133 | } | |
2134 | else if (win->IsKindOf(CLASSINFO(wxBitmapButton))) | |
2135 | { | |
2136 | info = new wxBitmapButtonPropertyInfo(win); | |
2137 | } | |
2138 | else if (win->IsKindOf(CLASSINFO(wxButton))) | |
2139 | { | |
2140 | info = new wxButtonPropertyInfo(win); | |
2141 | } | |
2142 | else if (win->IsKindOf(CLASSINFO(wxStaticBitmap))) | |
2143 | { | |
2144 | info = new wxStaticBitmapPropertyInfo(win); | |
2145 | } | |
2146 | else if (win->IsKindOf(CLASSINFO(wxStaticText))) | |
2147 | { | |
2148 | info = new wxStaticTextPropertyInfo(win); | |
2149 | } | |
2150 | else if (win->IsKindOf(CLASSINFO(wxTextCtrl))) | |
2151 | { | |
2152 | info = new wxTextPropertyInfo(win); | |
2153 | } | |
2154 | else if (win->IsKindOf(CLASSINFO(wxPanel))) | |
2155 | { | |
2156 | info = new wxPanelPropertyInfo(win); | |
2157 | } | |
2158 | else | |
2159 | { | |
2160 | info = new wxWindowPropertyInfo(win); | |
2161 | } | |
2162 | return info; | |
ae8351fc JS |
2163 | } |
2164 | ||
2165 | // Edit the given window | |
2166 | void wxResourceManager::EditWindow(wxWindow *win) | |
2167 | { | |
f6bcfd97 BP |
2168 | wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(win); |
2169 | if (info) | |
2170 | { | |
2171 | info->SetResource(FindResourceForWindow(win)); | |
2172 | wxString str("Editing "); | |
2173 | str += win->GetClassInfo()->GetClassName(); | |
2174 | str += ": "; | |
2175 | if (win->GetName() != "") | |
2176 | str += win->GetName(); | |
2177 | else | |
2178 | str += "properties"; | |
2179 | info->Edit(NULL, str); | |
2180 | } | |
ae8351fc JS |
2181 | } |
2182 | ||
5de76427 JS |
2183 | // Generate a window id and a first stab at a name |
2184 | int wxResourceManager::GenerateWindowId(const wxString& prefix, wxString& idName) | |
2185 | { | |
2186 | m_symbolIdCounter ++; | |
2187 | while (m_symbolTable.IdExists(m_symbolIdCounter)) | |
2188 | m_symbolIdCounter ++; | |
f6bcfd97 | 2189 | |
5de76427 | 2190 | int nameId = m_symbolIdCounter; |
f6bcfd97 | 2191 | |
5de76427 JS |
2192 | wxString str; |
2193 | str.Printf("%d", nameId); | |
2194 | idName = prefix + str; | |
f6bcfd97 | 2195 | |
5de76427 JS |
2196 | while (m_symbolTable.SymbolExists(idName)) |
2197 | { | |
2198 | nameId ++; | |
2199 | str.Printf("%d", nameId); | |
2200 | idName = prefix + str; | |
2201 | } | |
f6bcfd97 | 2202 | |
5de76427 JS |
2203 | return m_symbolIdCounter; |
2204 | } | |
2205 | ||
457814b5 JS |
2206 | |
2207 | /* | |
f6bcfd97 BP |
2208 | * Resource editor frame |
2209 | */ | |
ae8351fc JS |
2210 | |
2211 | IMPLEMENT_CLASS(wxResourceEditorFrame, wxFrame) | |
2212 | ||
2213 | BEGIN_EVENT_TABLE(wxResourceEditorFrame, wxFrame) | |
f6bcfd97 BP |
2214 | EVT_MENU(wxID_NEW, wxResourceEditorFrame::OnNew) |
2215 | EVT_MENU(RESED_NEW_DIALOG, wxResourceEditorFrame::OnNewDialog) | |
2216 | EVT_MENU(wxID_OPEN, wxResourceEditorFrame::OnOpen) | |
2217 | EVT_MENU(RESED_CLEAR, wxResourceEditorFrame::OnClear) | |
2218 | EVT_MENU(wxID_SAVE, wxResourceEditorFrame::OnSave) | |
2219 | EVT_MENU(wxID_SAVEAS, wxResourceEditorFrame::OnSaveAs) | |
2220 | EVT_MENU(wxID_EXIT, wxResourceEditorFrame::OnExit) | |
2221 | EVT_MENU(wxID_ABOUT, wxResourceEditorFrame::OnAbout) | |
2222 | EVT_MENU(RESED_CONTENTS, wxResourceEditorFrame::OnContents) | |
2223 | EVT_MENU(RESED_DELETE, wxResourceEditorFrame::OnDeleteSelection) | |
2224 | EVT_MENU(RESED_RECREATE, wxResourceEditorFrame::OnRecreateSelection) | |
2225 | EVT_MENU(RESED_TEST, wxResourceEditorFrame::OnTest) | |
2226 | EVT_MENU(RESED_CONVERT_WXRS, wxResourceEditorFrame::OnConvertWXRs) | |
2227 | EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow) | |
ae8351fc JS |
2228 | END_EVENT_TABLE() |
2229 | ||
2230 | wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title, | |
f6bcfd97 BP |
2231 | const wxPoint& pos, const wxSize& size, long style, const wxString& name): |
2232 | wxFrame(parent, -1, title, pos, size, style, name) | |
457814b5 | 2233 | { |
f6bcfd97 | 2234 | manager = resMan; |
457814b5 JS |
2235 | } |
2236 | ||
ae8351fc | 2237 | wxResourceEditorFrame::~wxResourceEditorFrame() |
457814b5 JS |
2238 | { |
2239 | } | |
2240 | ||
f6bcfd97 BP |
2241 | void wxResourceEditorFrame::OnConvertWXRs(wxCommandEvent& WXUNUSED(event)) |
2242 | { | |
2243 | manager->ConvertWXRs(); | |
2244 | } | |
2245 | ||
b127f301 | 2246 | void wxResourceEditorFrame::OnNew(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 2247 | { |
f6bcfd97 | 2248 | manager->New(FALSE); |
ae8351fc JS |
2249 | } |
2250 | ||
b127f301 | 2251 | void wxResourceEditorFrame::OnNewDialog(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2252 | { |
f6bcfd97 | 2253 | manager->CreateNewPanel(); |
ae8351fc JS |
2254 | } |
2255 | ||
b127f301 | 2256 | void wxResourceEditorFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2257 | { |
f6bcfd97 | 2258 | manager->New(TRUE); |
ae8351fc JS |
2259 | } |
2260 | ||
b127f301 | 2261 | void wxResourceEditorFrame::OnClear(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2262 | { |
f6bcfd97 | 2263 | manager->Clear(TRUE, FALSE); |
ae8351fc JS |
2264 | } |
2265 | ||
b127f301 | 2266 | void wxResourceEditorFrame::OnSave(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2267 | { |
f6bcfd97 | 2268 | manager->Save(); |
ae8351fc JS |
2269 | } |
2270 | ||
b127f301 | 2271 | void wxResourceEditorFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2272 | { |
f6bcfd97 | 2273 | manager->SaveAs(); |
ae8351fc JS |
2274 | } |
2275 | ||
b127f301 | 2276 | void wxResourceEditorFrame::OnExit(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2277 | { |
f6bcfd97 BP |
2278 | manager->Clear(TRUE, FALSE) ; |
2279 | this->Destroy(); | |
ae8351fc JS |
2280 | } |
2281 | ||
b127f301 | 2282 | void wxResourceEditorFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2283 | { |
f6bcfd97 BP |
2284 | char buf[300]; |
2285 | sprintf(buf, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart <julian.smart@ukonline.co.uk>\nJulian Smart (c) 1996-1999", wxDIALOG_EDITOR_VERSION); | |
2286 | wxMessageBox(buf, "About Dialog Editor", wxOK|wxCENTRE); | |
ae8351fc JS |
2287 | } |
2288 | ||
b127f301 | 2289 | void wxResourceEditorFrame::OnTest(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2290 | { |
03f68f12 | 2291 | manager->TestCurrentDialog(this); |
ae8351fc JS |
2292 | } |
2293 | ||
b127f301 | 2294 | void wxResourceEditorFrame::OnContents(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2295 | { |
d0fff5cb | 2296 | #ifdef __WXMSW__ |
f6bcfd97 BP |
2297 | wxBeginBusyCursor(); |
2298 | manager->GetHelpController()->LoadFile(); | |
2299 | manager->GetHelpController()->DisplayContents(); | |
2300 | wxEndBusyCursor(); | |
b127f301 | 2301 | #endif |
ae8351fc JS |
2302 | } |
2303 | ||
b127f301 | 2304 | void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2305 | { |
f6bcfd97 | 2306 | manager->DeleteSelection(); |
ae8351fc JS |
2307 | } |
2308 | ||
b127f301 | 2309 | void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2310 | { |
f6bcfd97 | 2311 | manager->RecreateSelection(); |
457814b5 JS |
2312 | } |
2313 | ||
e3065973 | 2314 | void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent& event) |
457814b5 | 2315 | { |
f6bcfd97 BP |
2316 | wxPropertyInfo::CloseWindow(); |
2317 | manager->ClearCurrentDialog(); | |
2318 | if (manager->Modified()) | |
2319 | { | |
2320 | if (!manager->Clear(TRUE, FALSE)) | |
2321 | { | |
2322 | event.Veto(); | |
2323 | return; | |
2324 | } | |
e3065973 | 2325 | } |
457814b5 | 2326 | |
f6bcfd97 BP |
2327 | if (!IsIconized()) |
2328 | { | |
2329 | int w, h; | |
2330 | GetSize(&w, &h); | |
2331 | manager->m_resourceEditorWindowSize.width = w; | |
2332 | manager->m_resourceEditorWindowSize.height = h; | |
2333 | ||
2334 | int x, y; | |
2335 | GetPosition(&x, &y); | |
2336 | ||
2337 | manager->m_resourceEditorWindowSize.x = x; | |
2338 | manager->m_resourceEditorWindowSize.y = y; | |
2339 | } | |
2340 | manager->SetEditorFrame(NULL); | |
2341 | manager->SetEditorToolBar(NULL); | |
2342 | ||
2343 | this->Destroy(); | |
457814b5 JS |
2344 | } |
2345 | ||
2346 | /* | |
f6bcfd97 BP |
2347 | * Resource editor window that contains the dialog/panel being edited |
2348 | */ | |
ae8351fc JS |
2349 | |
2350 | BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow, wxScrolledWindow) | |
f6bcfd97 | 2351 | EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint) |
ae8351fc JS |
2352 | END_EVENT_TABLE() |
2353 | ||
2354 | wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow *parent, const wxPoint& pos, const wxSize& size, | |
f6bcfd97 BP |
2355 | long style): |
2356 | wxScrolledWindow(parent, -1, pos, size, style) | |
457814b5 | 2357 | { |
ae8351fc JS |
2358 | m_marginX = 10; |
2359 | m_marginY = 40; | |
2360 | m_childWindow = NULL; | |
f6bcfd97 | 2361 | |
15d5ab67 | 2362 | SetBackgroundColour(* wxWHITE); |
457814b5 JS |
2363 | } |
2364 | ||
ae8351fc | 2365 | wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow() |
457814b5 JS |
2366 | { |
2367 | } | |
2368 | ||
b127f301 | 2369 | void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) |
ae8351fc JS |
2370 | { |
2371 | wxPaintDC dc(this); | |
f6bcfd97 | 2372 | |
ae8351fc JS |
2373 | DrawTitle(dc); |
2374 | } | |
2375 | ||
2376 | void wxResourceEditorScrolledWindow::DrawTitle(wxDC& dc) | |
2377 | { | |
2378 | if (m_childWindow) | |
2379 | { | |
2380 | wxItemResource* res = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow); | |
2381 | if (res) | |
2382 | { | |
2383 | wxString str(res->GetTitle()); | |
2384 | int x, y; | |
5e998a33 | 2385 | GetViewStart(& x, & y); |
f6bcfd97 | 2386 | |
ae8351fc JS |
2387 | wxFont font(10, wxSWISS, wxNORMAL, wxBOLD); |
2388 | dc.SetFont(font); | |
2389 | dc.SetBackgroundMode(wxTRANSPARENT); | |
2390 | dc.SetTextForeground(wxColour(0, 0, 0)); | |
f6bcfd97 | 2391 | |
ae8351fc JS |
2392 | long w, h; |
2393 | dc.GetTextExtent(str, & w, & h); | |
f6bcfd97 | 2394 | |
ae8351fc JS |
2395 | dc.DrawText(str, m_marginX + (- x * 10), m_marginY + (- y * 10) - h - 5); |
2396 | } | |
2397 | } | |
457814b5 JS |
2398 | } |
2399 | ||
2400 | // Popup menu callback | |
7bf07d26 | 2401 | void ObjectMenuProc(wxMenu *menu, wxCommandEvent& event) |
457814b5 | 2402 | { |
f6bcfd97 BP |
2403 | wxWindow *data = (wxWindow *)menu->GetClientData(); |
2404 | if (!data) | |
2405 | return; | |
2406 | ||
1378f260 | 2407 | switch (event.GetId()) |
457814b5 | 2408 | { |
58d5bf3a GT |
2409 | case OBJECT_MENU_TITLE: |
2410 | { | |
2411 | event.Skip(); | |
2412 | break; | |
2413 | } | |
f6bcfd97 BP |
2414 | case OBJECT_MENU_EDIT: |
2415 | { | |
2416 | wxResourceManager::GetCurrentResourceManager()->EditWindow(data); | |
2417 | break; | |
2418 | } | |
457814b5 | 2419 | case OBJECT_MENU_DELETE: |
f6bcfd97 | 2420 | { |
58d5bf3a GT |
2421 | // Before deleting a dialog, give the user a last chance |
2422 | // change their mind, in case they accidentally right | |
2423 | // clicked the dialog rather than the widget they were | |
2424 | // aiming for. | |
4f8fccd1 GT |
2425 | if (data->IsKindOf(CLASSINFO(wxPanel))) |
2426 | { | |
58d5bf3a GT |
2427 | wxString str(wxT("Deleting dialog : ")); |
2428 | str += data->GetName(); | |
2429 | if (wxMessageBox(wxT("Are you sure?"), str, wxYES_NO | wxCENTRE) == wxNO) | |
4f8fccd1 GT |
2430 | return; |
2431 | } | |
2432 | ||
f6bcfd97 | 2433 | wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data); |
4f8fccd1 | 2434 | |
f6bcfd97 BP |
2435 | wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data); |
2436 | wxResourceManager::GetCurrentResourceManager()->DeleteResource(data); | |
2437 | wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data); | |
2438 | break; | |
2439 | } | |
457814b5 | 2440 | default: |
f6bcfd97 BP |
2441 | break; |
2442 | } | |
457814b5 JS |
2443 | } |
2444 | ||
457814b5 | 2445 | /* |
f6bcfd97 BP |
2446 | * Main toolbar |
2447 | * | |
2448 | */ | |
457814b5 | 2449 | |
9d3221ab | 2450 | BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar) |
33961d59 | 2451 | // EVT_PAINT(EditorToolBar::OnPaint) |
9d3221ab RR |
2452 | END_EVENT_TABLE() |
2453 | ||
ae8351fc | 2454 | EditorToolBar::EditorToolBar(wxFrame *frame, const wxPoint& pos, const wxSize& size, |
f6bcfd97 BP |
2455 | long style): |
2456 | wxToolBar(frame, -1, pos, size, style) | |
457814b5 JS |
2457 | { |
2458 | } | |
2459 | ||
fd71308f | 2460 | bool EditorToolBar::OnLeftClick(int toolIndex, bool WXUNUSED(toggled)) |
457814b5 | 2461 | { |
f6bcfd97 BP |
2462 | wxResourceManager *manager = wxResourceManager::GetCurrentResourceManager(); |
2463 | ||
2464 | switch (toolIndex) | |
457814b5 | 2465 | { |
f6bcfd97 BP |
2466 | case TOOLBAR_LOAD_FILE: |
2467 | { | |
2468 | manager->New(TRUE); | |
2469 | break; | |
2470 | } | |
457814b5 | 2471 | case TOOLBAR_NEW: |
f6bcfd97 BP |
2472 | { |
2473 | manager->CreateNewPanel(); | |
2474 | break; | |
2475 | } | |
457814b5 | 2476 | case TOOLBAR_SAVE_FILE: |
f6bcfd97 BP |
2477 | { |
2478 | manager->Save(); | |
2479 | break; | |
2480 | } | |
457814b5 | 2481 | case TOOLBAR_HELP: |
f6bcfd97 | 2482 | { |
d0fff5cb | 2483 | #ifdef __WXMSW__ |
f6bcfd97 BP |
2484 | wxBeginBusyCursor(); |
2485 | manager->GetHelpController()->DisplayContents(); | |
2486 | wxEndBusyCursor(); | |
b127f301 | 2487 | #endif |
f6bcfd97 BP |
2488 | break; |
2489 | } | |
457814b5 | 2490 | case TOOLBAR_FORMAT_HORIZ: |
f6bcfd97 BP |
2491 | { |
2492 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ); | |
2493 | break; | |
2494 | } | |
457814b5 | 2495 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: |
f6bcfd97 BP |
2496 | { |
2497 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN); | |
2498 | break; | |
2499 | } | |
457814b5 | 2500 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: |
f6bcfd97 BP |
2501 | { |
2502 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN); | |
2503 | break; | |
2504 | } | |
457814b5 | 2505 | case TOOLBAR_FORMAT_VERT: |
f6bcfd97 BP |
2506 | { |
2507 | manager->AlignItems(TOOLBAR_FORMAT_VERT); | |
2508 | break; | |
2509 | } | |
457814b5 | 2510 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: |
f6bcfd97 BP |
2511 | { |
2512 | manager->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN); | |
2513 | break; | |
2514 | } | |
457814b5 | 2515 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: |
f6bcfd97 BP |
2516 | { |
2517 | manager->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN); | |
2518 | break; | |
2519 | } | |
457814b5 | 2520 | case TOOLBAR_COPY_SIZE: |
f6bcfd97 BP |
2521 | { |
2522 | manager->CopySize(TOOLBAR_COPY_SIZE); | |
2523 | break; | |
2524 | } | |
2525 | case TOOLBAR_COPY_WIDTH: | |
2526 | { | |
2527 | manager->CopySize(TOOLBAR_COPY_WIDTH); | |
2528 | break; | |
2529 | } | |
2530 | case TOOLBAR_COPY_HEIGHT: | |
2531 | { | |
2532 | manager->CopySize(TOOLBAR_COPY_HEIGHT); | |
2533 | break; | |
2534 | } | |
2535 | case TOOLBAR_DISTRIBUTE_HORIZ: | |
2536 | { | |
2537 | manager->DistributePositions(TOOLBAR_DISTRIBUTE_HORIZ); | |
2538 | break; | |
2539 | } | |
2540 | case TOOLBAR_DISTRIBUTE_VERT: | |
2541 | { | |
2542 | manager->DistributePositions(TOOLBAR_DISTRIBUTE_VERT); | |
2543 | break; | |
2544 | } | |
457814b5 | 2545 | case TOOLBAR_TO_BACK: |
f6bcfd97 BP |
2546 | { |
2547 | manager->ToBackOrFront(TRUE); | |
2548 | break; | |
2549 | } | |
457814b5 | 2550 | case TOOLBAR_TO_FRONT: |
f6bcfd97 BP |
2551 | { |
2552 | manager->ToBackOrFront(FALSE); | |
2553 | break; | |
2554 | } | |
457814b5 | 2555 | default: |
f6bcfd97 BP |
2556 | break; |
2557 | } | |
2558 | return TRUE; | |
457814b5 JS |
2559 | } |
2560 | ||
2561 | void EditorToolBar::OnMouseEnter(int toolIndex) | |
2562 | { | |
f6bcfd97 BP |
2563 | wxFrame *frame = (wxFrame *)GetParent(); |
2564 | ||
2565 | if (!frame) return; | |
2566 | ||
2567 | if (toolIndex > -1) | |
2568 | { | |
2569 | switch (toolIndex) | |
2570 | { | |
457814b5 | 2571 | case TOOLBAR_LOAD_FILE: |
f6bcfd97 BP |
2572 | frame->SetStatusText("Load project file"); |
2573 | break; | |
457814b5 | 2574 | case TOOLBAR_SAVE_FILE: |
f6bcfd97 BP |
2575 | frame->SetStatusText("Save project file"); |
2576 | break; | |
457814b5 | 2577 | case TOOLBAR_NEW: |
f6bcfd97 BP |
2578 | frame->SetStatusText("Create a new resource"); |
2579 | break; | |
457814b5 | 2580 | case TOOLBAR_FORMAT_HORIZ: |
f6bcfd97 BP |
2581 | frame->SetStatusText("Align items horizontally"); |
2582 | break; | |
457814b5 | 2583 | case TOOLBAR_FORMAT_VERT: |
f6bcfd97 BP |
2584 | frame->SetStatusText("Align items vertically"); |
2585 | break; | |
457814b5 | 2586 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: |
f6bcfd97 BP |
2587 | frame->SetStatusText("Left-align items"); |
2588 | break; | |
457814b5 | 2589 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: |
f6bcfd97 BP |
2590 | frame->SetStatusText("Right-align items"); |
2591 | break; | |
457814b5 | 2592 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: |
f6bcfd97 BP |
2593 | frame->SetStatusText("Top-align items"); |
2594 | break; | |
457814b5 | 2595 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: |
f6bcfd97 BP |
2596 | frame->SetStatusText("Bottom-align items"); |
2597 | break; | |
457814b5 | 2598 | case TOOLBAR_COPY_SIZE: |
f6bcfd97 BP |
2599 | frame->SetStatusText("Copy size from first selection"); |
2600 | break; | |
457814b5 | 2601 | case TOOLBAR_TO_FRONT: |
f6bcfd97 BP |
2602 | frame->SetStatusText("Put image to front"); |
2603 | break; | |
457814b5 | 2604 | case TOOLBAR_TO_BACK: |
f6bcfd97 BP |
2605 | frame->SetStatusText("Put image to back"); |
2606 | break; | |
457814b5 | 2607 | case TOOLBAR_HELP: |
f6bcfd97 BP |
2608 | frame->SetStatusText("Display help contents"); |
2609 | break; | |
457814b5 | 2610 | default: |
f6bcfd97 BP |
2611 | break; |
2612 | } | |
2613 | } | |
2614 | else frame->SetStatusText(""); | |
457814b5 JS |
2615 | } |
2616 | ||
f6bcfd97 BP |
2617 | bool ResourceEditorDialogTester::ProcessEvent(wxEvent& event) |
2618 | { | |
2619 | if (event.IsCommandEvent() && event.GetId() != wxID_OK && event.GetId() != wxID_CANCEL) | |
2620 | { | |
2621 | // Do nothing | |
2622 | return TRUE; | |
2623 | } | |
2624 | else | |
2625 | return wxDialog::ProcessEvent(event); | |
2626 | } | |
2627 | ||
2628 | static int gs_LabelInsertionCount = 0; | |
2629 | ||
2630 | // Convert old WXRs to new | |
2631 | bool wxResourceManager::ConvertWXRs() | |
2632 | { | |
2633 | gs_LabelInsertionCount = 0; | |
2634 | m_symbolIdCounter = 20000; | |
2635 | ||
2636 | wxString currentPath = wxGetCwd(); | |
2637 | wxString oldWXRPath, newWXRPath; | |
2638 | ||
2639 | wxDirDialog dialog(NULL, wxT("Choose directory for old WXRs"), currentPath); | |
2640 | ||
2641 | if (dialog.ShowModal() == wxID_OK) | |
2642 | { | |
2643 | oldWXRPath = dialog.GetPath(); | |
2644 | } | |
2645 | else | |
2646 | return FALSE; | |
2647 | ||
2648 | wxDirDialog dialog2(NULL, wxT("Choose directory for new WXRs"), oldWXRPath); | |
2649 | ||
2650 | if (dialog2.ShowModal() == wxID_OK) | |
2651 | { | |
2652 | newWXRPath = dialog2.GetPath(); | |
2653 | } | |
2654 | else | |
2655 | return FALSE; | |
2656 | ||
2657 | if (newWXRPath == oldWXRPath) | |
2658 | { | |
2659 | wxMessageBox(wxT("Sorry, the directories must be different.")); | |
2660 | return FALSE; | |
2661 | } | |
2662 | ||
2663 | wxDir dir(oldWXRPath); | |
2664 | if (!dir.IsOpened()) | |
2665 | return FALSE; | |
2666 | ||
2667 | wxArrayString stringArray; | |
2668 | ||
2669 | wxString filename; | |
2670 | bool ok = dir.GetFirst(& filename, wxT("*.wxr")); | |
2671 | while (ok) | |
2672 | { | |
2673 | stringArray.Add(filename); | |
2674 | ||
2675 | ok = dir.GetNext(& filename); | |
2676 | } | |
2677 | ||
2678 | // Pop up a progress dialog | |
2679 | wxProgressDialog progressDialog(wxT("Converting WXR files"), wxT("Converting files...")); | |
2680 | ||
2681 | size_t i; | |
2682 | for (i = 0; i < stringArray.Count(); i++) | |
2683 | { | |
2684 | progressDialog.Update((int) (100.0 * ((double) i / (double) stringArray.Count()))); | |
2685 | ||
2686 | filename = stringArray[i]; | |
2687 | wxString oldPath = oldWXRPath + wxString(wxFILE_SEP_PATH) + filename; | |
2688 | wxString newPath = newWXRPath + wxString(wxFILE_SEP_PATH) + filename; | |
2689 | ||
2690 | DoConvertWXR(oldPath, newPath); | |
2691 | } | |
2692 | ||
2693 | wxString msg; | |
2694 | msg.Printf(wxT("Dialog Editor inserted %d labels."), gs_LabelInsertionCount); | |
2695 | wxMessageBox(msg); | |
2696 | ||
2697 | return TRUE; | |
2698 | } | |
2699 | ||
2700 | bool wxResourceManager::DoConvertWXR(const wxString& oldPath, const wxString& newPath) | |
2701 | { | |
2702 | ||
2703 | if (!Clear(TRUE, FALSE)) | |
2704 | return FALSE; | |
2705 | ||
2706 | m_symbolTable.AddStandardSymbols(); | |
2707 | ||
2708 | if (!m_resourceTable.ParseResourceFile(oldPath)) | |
2709 | { | |
2710 | wxString msg; | |
2711 | msg.Printf(wxT("Could not read file %s"), (const char*) oldPath); | |
2712 | wxMessageBox(msg, "Resource file load error", wxOK | wxICON_EXCLAMATION); | |
2713 | return FALSE; | |
2714 | } | |
2715 | m_currentFilename = oldPath; | |
2716 | ||
2717 | //SetFrameTitle(m_currentFilename); | |
2718 | ||
2719 | //UpdateResourceList(); | |
2720 | ||
2721 | // Construct include filename from this file | |
2722 | m_symbolFilename = m_currentFilename; | |
2723 | ||
2724 | wxStripExtension(m_symbolFilename); | |
2725 | m_symbolFilename += wxT(".h"); | |
2726 | ||
2727 | if (!m_symbolTable.ReadIncludeFile(m_symbolFilename)) | |
2728 | { | |
2729 | } | |
2730 | else | |
2731 | { | |
2732 | // Set the id counter to the last known id | |
2733 | m_symbolIdCounter = m_symbolTable.FindHighestId(); | |
2734 | } | |
2735 | ||
2736 | // Now check in case some (or all) resources don't have resource ids, or they | |
2737 | // don't match the .h file, or something of that nature. | |
2738 | bool altered = RepairResourceIds(); | |
2739 | ||
2740 | // Do any necessary changes to the resources | |
2741 | m_resourceTable.BeginFind(); | |
2742 | wxNode *node; | |
2743 | while ((node = m_resourceTable.Next())) | |
2744 | { | |
2745 | wxItemResource *res = (wxItemResource *)node->Data(); | |
2746 | ChangeOldToNewResource(NULL, res); | |
2747 | } | |
2748 | ||
2749 | // Change the filename before saving | |
2750 | ||
2751 | m_currentFilename = newPath; | |
2752 | m_symbolFilename = m_currentFilename; | |
2753 | wxStripExtension(m_symbolFilename); | |
2754 | m_symbolFilename += wxT(".h"); | |
2755 | ||
2756 | Modify(TRUE); | |
2757 | ||
2758 | Save(); | |
2759 | ||
2760 | Clear(TRUE, TRUE); | |
2761 | ||
2762 | return TRUE; | |
2763 | ||
2764 | } | |
2765 | ||
2766 | bool wxResourceManager::ChangeOldToNewResource(wxItemResource* parent, wxItemResource* res) | |
2767 | { | |
2768 | // Change these according to your needs | |
2769 | ||
2770 | // Change all fonts to use system defaults for fonts, colours etc. | |
2771 | static bool s_useSystemDefaultsAlways = FALSE; // TRUE; | |
2772 | ||
2773 | // Increase dialog height by this amount (wxWin 2 uses dialog client size now) | |
2774 | static int s_increaseDialogSize = -18; | |
2775 | ||
2776 | // How many points to decrease the font sizes by, since | |
2777 | // wxWin 2 fonts are larger in Windows | |
2778 | static int s_decreaseFontSize = 3; | |
2779 | ||
2780 | wxString itemType(res->GetType()); | |
2781 | ||
2782 | wxFont font = res->GetFont(); | |
2783 | ||
2784 | if ((s_decreaseFontSize) > 0 && font.Ok()) | |
2785 | { | |
2786 | wxFont newFont = wxFont(font.GetPointSize() - s_decreaseFontSize, | |
2787 | font.GetFamily(), font.GetStyle(), font.GetWeight(), | |
2788 | font.GetUnderlined(), font.GetFaceName()); | |
2789 | res->SetFont(newFont); | |
2790 | } | |
2791 | ||
2792 | if (itemType == wxT("wxDialogBox") || itemType == wxT("wxDialog") || itemType == wxT("wxPanel")) | |
2793 | { | |
2794 | if (itemType == wxT("wxDialogBox")) | |
2795 | res->SetType(wxT("wxDialog")); | |
2796 | ||
2797 | if (itemType == wxT("wxDialogBox") || itemType == wxT("wxDialog")) | |
2798 | { | |
2799 | // Only change the height if it has a caption, i.e. it's going to be | |
2800 | // used as a proper dialog and not a panel | |
2801 | if (res->GetStyle() & wxCAPTION) | |
2802 | res->SetSize(res->GetX(), res->GetY(), res->GetWidth(), res->GetHeight() + s_increaseDialogSize ); | |
2803 | } | |
2804 | ||
2805 | if (s_useSystemDefaultsAlways) | |
2806 | res->SetResourceStyle(res->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS); | |
2807 | ||
2808 | if (res->GetValue1()) | |
2809 | res->SetStyle(res->GetStyle() | wxDIALOG_MODAL); | |
2810 | ||
2811 | wxNode *node = res->GetChildren().First(); | |
2812 | while (node) | |
2813 | { | |
2814 | wxItemResource *child = (wxItemResource *)node->Data(); | |
2815 | ||
2816 | ChangeOldToNewResource(res, child); | |
2817 | node = node->Next(); | |
2818 | } | |
2819 | } | |
2820 | else if (itemType == wxT("wxMessage")) | |
2821 | { | |
2822 | // Figure out if this is a bitmap or text message | |
2823 | if (res->GetValue4().IsEmpty()) | |
2824 | res->SetType(wxT("wxStaticText")); | |
2825 | else | |
2826 | res->SetType(wxT("wxStaticBitmap")); | |
2827 | } | |
2828 | else if (itemType == wxT("wxButton")) | |
2829 | { | |
2830 | // Figure out if this is a bitmap or text message | |
2831 | if (res->GetValue4().IsEmpty()) | |
2832 | { | |
2833 | } | |
2834 | else | |
2835 | res->SetType(wxT("wxBitmapButton")); | |
2836 | } | |
2837 | else if (itemType == wxT("wxGroupBox")) | |
2838 | { | |
2839 | res->SetType(wxT("wxStaticBox")); | |
2840 | } | |
2841 | else if (itemType == wxT("wxText")) | |
2842 | { | |
2843 | res->SetType(wxT("wxTextCtrl")); | |
2844 | } | |
2845 | else if (itemType == wxT("wxMultiText")) | |
2846 | { | |
2847 | res->SetType(wxT("wxTextCtrl")); | |
2848 | res->SetStyle(res->GetStyle() | wxTE_MULTILINE); | |
2849 | } | |
2850 | ||
2851 | itemType = res->GetType(); | |
2852 | ||
2853 | if (!res->GetTitle().IsEmpty() && | |
2854 | (itemType == wxT("wxTextCtrl") || itemType == wxT("wxChoice") || | |
2855 | itemType == wxT("wxComboBox") || itemType == wxT("wxGauge") || | |
2856 | itemType == wxT("wxListBox"))) | |
2857 | { | |
2858 | // Insert a label control resource, adjusting the size of this | |
2859 | // resource accordingly. | |
2860 | InsertLabelResource(parent, res); | |
2861 | } | |
2862 | ||
2863 | return TRUE; | |
2864 | } | |
2865 | ||
2866 | // Insert a label control resource, adjusting the size of this | |
2867 | // resource accordingly. | |
2868 | bool wxResourceManager::InsertLabelResource(wxItemResource* parent, wxItemResource* res) | |
2869 | { | |
2870 | gs_LabelInsertionCount ++; | |
2871 | ||
2872 | bool isHorizontal = TRUE; | |
2873 | ||
2874 | // Determine panel orientation | |
2875 | if (parent->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL) | |
2876 | { | |
2877 | isHorizontal = FALSE; | |
2878 | } | |
2879 | else if (parent->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL) | |
2880 | { | |
2881 | isHorizontal = TRUE; | |
2882 | } | |
2883 | ||
2884 | // Now override | |
2885 | if (res->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL) | |
2886 | { | |
2887 | isHorizontal = FALSE; | |
2888 | } | |
2889 | else if (res->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL) | |
2890 | { | |
2891 | isHorizontal = TRUE; | |
2892 | } | |
2893 | ||
2894 | int x = res->GetX(); | |
2895 | int y = res->GetY(); | |
2896 | int width = res->GetWidth(); | |
2897 | int height = res->GetHeight(); | |
2898 | ||
2899 | // Find the font specified | |
2900 | wxFont font; | |
2901 | if (res->GetFont().Ok()) | |
2902 | font = res->GetFont(); | |
2903 | else | |
2904 | font = parent->GetFont(); | |
2905 | ||
2906 | if (!font.Ok() || (parent->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS)) | |
2907 | font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); | |
2908 | ||
2909 | int labelX, labelY; | |
2910 | wxCoord labelWidth, labelHeight; | |
2911 | wxScreenDC dc; | |
2912 | dc.SetFont(font); | |
2913 | dc.GetTextExtent(res->GetTitle(), & labelWidth, & labelHeight); | |
2914 | ||
2915 | // Vert/horizontal margin between controls | |
2916 | int margin = 3; | |
2917 | ||
2918 | labelX = x; | |
2919 | labelY = y; | |
2920 | //labelWidth += 1; | |
2921 | //labelHeight += 1; | |
2922 | ||
2923 | if (isHorizontal) | |
2924 | { | |
2925 | x += labelWidth + margin; | |
2926 | width -= (labelWidth + margin); | |
2927 | } | |
2928 | else | |
2929 | { | |
2930 | y += labelHeight + margin; | |
2931 | height -= (labelHeight + margin); | |
2932 | ||
2933 | // Fudge factors | |
2934 | if (res->GetType() == wxT("wxTextCtrl")) | |
2935 | { | |
2936 | height += 3; | |
2937 | } | |
2938 | else if (res->GetType() == wxT("wxChoice") || res->GetType() == wxT("wxComboBox")) | |
2939 | { | |
2940 | height -= 4; | |
2941 | } | |
2942 | } | |
2943 | ||
2944 | res->SetSize(x, y, width, height); | |
2945 | ||
2946 | wxItemResource* staticItem = new wxItemResource; | |
2947 | staticItem->SetSize(labelX, labelY, labelWidth, labelHeight); | |
2948 | staticItem->SetTitle(res->GetTitle()); | |
2949 | staticItem->SetFont(font); | |
2950 | staticItem->SetStyle(0); | |
2951 | staticItem->SetType(wxT("wxStaticText")); | |
2952 | ||
2953 | wxString newSymbolName; | |
2954 | int newId = GenerateWindowId(wxT("ID_STATICTEXT"), newSymbolName) ; | |
2955 | staticItem->SetId(newId); | |
2956 | ||
2957 | newSymbolName = res->GetName() + wxT("_Label"); | |
2958 | staticItem->SetName(newSymbolName); | |
2959 | m_symbolTable.AddSymbol(newSymbolName, newId); | |
2960 | ||
2961 | wxNode* node = parent->GetChildren().Member(res); | |
2962 | ||
2963 | wxASSERT( (node != NULL) ); | |
2964 | ||
2965 | parent->GetChildren().Insert(node, staticItem); | |
2966 | ||
2967 | // Remove the title from this resource since we've replaced it | |
2968 | // with a static text control | |
2969 | res->SetTitle(wxEmptyString); | |
2970 | ||
2971 | return TRUE; | |
2972 | } |