]>
Commit | Line | Data |
---|---|---|
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" | |
35 | #include "wx/menu.h" | |
36 | #include "wx/toolbar.h" | |
37 | #endif | |
38 | ||
39 | #include "wx/scrolbar.h" | |
40 | #include "wx/config.h" | |
41 | ||
42 | #include <ctype.h> | |
43 | #include <stdlib.h> | |
44 | #include <math.h> | |
45 | #include <string.h> | |
46 | ||
47 | #if wxUSE_IOSTREAMH | |
48 | #if defined(__WXMSW__) && !defined(__GNUWIN32__) | |
49 | #include <strstrea.h> | |
50 | #else | |
51 | #include <strstream.h> | |
52 | #endif | |
53 | #else | |
54 | #include <strstream> | |
55 | #endif | |
56 | ||
57 | #ifdef __WXMSW__ | |
58 | #include "wx/help.h" | |
59 | #endif | |
60 | ||
61 | #include "reseditr.h" | |
62 | #include "winprop.h" | |
63 | #include "dlghndlr.h" | |
64 | #include "edtree.h" | |
65 | #include "edlist.h" | |
66 | ||
67 | static void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event); | |
68 | wxResourceManager *wxResourceManager::sm_currentResourceManager = NULL; | |
69 | ||
70 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
71 | #include "bitmaps/load.xpm" | |
72 | #include "bitmaps/save.xpm" | |
73 | #include "bitmaps/new.xpm" | |
74 | #include "bitmaps/vert.xpm" | |
75 | #include "bitmaps/alignt.xpm" | |
76 | #include "bitmaps/alignb.xpm" | |
77 | #include "bitmaps/horiz.xpm" | |
78 | #include "bitmaps/alignl.xpm" | |
79 | #include "bitmaps/alignr.xpm" | |
80 | #include "bitmaps/copysize.xpm" | |
81 | #include "bitmaps/tofront.xpm" | |
82 | #include "bitmaps/toback.xpm" | |
83 | #include "bitmaps/help.xpm" | |
84 | #include "bitmaps/wxwin.xpm" | |
85 | ||
86 | #include "bitmaps/dialog.xpm" | |
87 | #include "bitmaps/folder1.xpm" | |
88 | #include "bitmaps/folder2.xpm" | |
89 | #include "bitmaps/buttonsm.xpm" | |
90 | #endif | |
91 | ||
92 | /* | |
93 | * Resource manager | |
94 | */ | |
95 | ||
96 | wxResourceManager::wxResourceManager(): | |
97 | m_imageList(16, 16, TRUE) | |
98 | { | |
99 | sm_currentResourceManager = this; | |
100 | m_editorFrame = NULL; | |
101 | m_editorPanel = NULL; | |
102 | m_popupMenu = NULL; | |
103 | m_editorResourceTree = NULL; | |
104 | m_editorControlList = NULL; | |
105 | m_nameCounter = 1; | |
106 | m_symbolIdCounter = 99; | |
107 | m_modified = FALSE; | |
108 | m_currentFilename = ""; | |
109 | m_symbolFilename = ""; | |
110 | m_editorToolBar = NULL; | |
111 | ||
112 | // Default window positions | |
113 | m_resourceEditorWindowSize.width = 500; | |
114 | m_resourceEditorWindowSize.height = 450; | |
115 | ||
116 | m_resourceEditorWindowSize.x = 0; | |
117 | m_resourceEditorWindowSize.y = 0; | |
118 | ||
119 | m_propertyWindowSize.width = 300; | |
120 | m_propertyWindowSize.height = 300; | |
121 | ||
122 | #ifdef __WXMSW__ | |
123 | m_helpController = NULL; | |
124 | #endif | |
125 | ||
126 | m_bitmapImage = NULL; | |
127 | m_rootDialogItem = 0; | |
128 | } | |
129 | ||
130 | wxResourceManager::~wxResourceManager() | |
131 | { | |
132 | sm_currentResourceManager = NULL; | |
133 | SaveOptions(); | |
134 | ||
135 | #ifdef __WXMSW__ | |
136 | if (m_helpController) | |
137 | { | |
138 | m_helpController->Quit(); | |
139 | delete m_helpController; | |
140 | m_helpController = NULL; | |
141 | } | |
142 | #endif | |
143 | ||
144 | delete m_bitmapImage; | |
145 | delete m_popupMenu; | |
146 | } | |
147 | ||
148 | bool wxResourceManager::Initialize() | |
149 | { | |
150 | // Set up the resource filename for each platform. | |
151 | // TODO: This shold be replaced by wxConfig usage. | |
152 | #ifdef __WXMSW__ | |
153 | // dialoged.ini in the Windows directory | |
154 | wxString windowsDir = wxGetOSDirectory(); | |
155 | windowsDir += "\\dialoged.ini" ; | |
156 | ||
157 | m_optionsResourceFilename = windowsDir; | |
158 | #elif defined(__WXGTK__) || defined(__WXMOTIF__) | |
159 | wxGetHomeDir( &m_optionsResourceFilename ); | |
160 | m_optionsResourceFilename += "/.dialogedrc"; | |
161 | #else | |
162 | #error "Unsupported platform." | |
163 | #endif | |
164 | ||
165 | LoadOptions(); | |
166 | ||
167 | #ifdef __WXMSW__ | |
168 | m_helpController = new wxHelpController; | |
169 | m_helpController->Initialize("dialoged"); | |
170 | #endif | |
171 | ||
172 | m_popupMenu = new wxMenu("", (wxFunction)ObjectMenuProc); | |
173 | m_popupMenu->Append(OBJECT_MENU_EDIT, "Edit properties"); | |
174 | m_popupMenu->Append(OBJECT_MENU_DELETE, "Delete object"); | |
175 | ||
176 | if (!m_bitmapImage) | |
177 | { | |
178 | #ifdef __WXMSW__ | |
179 | m_bitmapImage = new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE); | |
180 | #endif | |
181 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
182 | m_bitmapImage = new wxBitmap( wxwin_xpm ); | |
183 | #endif | |
184 | } | |
185 | ||
186 | // Initialize the image list icons | |
187 | #ifdef __WXMSW__ | |
188 | wxIcon icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16); | |
189 | wxIcon icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16); | |
190 | wxIcon icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16); | |
191 | wxIcon icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE, 16, 16); | |
192 | #else | |
193 | wxIcon icon1( dialog_xpm ); | |
194 | wxIcon icon2( folder1_xpm ); | |
195 | wxIcon icon3( folder2_xpm ); | |
196 | wxIcon icon4( buttonsm_xpm ); | |
197 | #endif | |
198 | m_imageList.Add(icon1); | |
199 | m_imageList.Add(icon2); | |
200 | m_imageList.Add(icon3); | |
201 | m_imageList.Add(icon4); | |
202 | ||
203 | m_symbolTable.AddStandardSymbols(); | |
204 | ||
205 | return TRUE; | |
206 | } | |
207 | ||
208 | bool wxResourceManager::LoadOptions() | |
209 | { | |
210 | wxConfig config("DialogEd", "wxWindows"); | |
211 | ||
212 | config.Read("editorWindowX", &m_resourceEditorWindowSize.x); | |
213 | config.Read("editorWindowY", &m_resourceEditorWindowSize.y); | |
214 | config.Read("editorWindowWidth", &m_resourceEditorWindowSize.width); | |
215 | config.Read("editorWindowHeight", &m_resourceEditorWindowSize.height); | |
216 | config.Read("propertyWindowX", &m_propertyWindowSize.x); | |
217 | config.Read("propertyWindowY", &m_propertyWindowSize.y); | |
218 | config.Read("propertyWindowWidth", &m_propertyWindowSize.width); | |
219 | config.Read("propertyWindowHeight", &m_propertyWindowSize.height); | |
220 | ||
221 | /* | |
222 | wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData()); | |
223 | wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData()); | |
224 | wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData()); | |
225 | wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData()); | |
226 | wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData()); | |
227 | wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData()); | |
228 | wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData()); | |
229 | wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData()); | |
230 | */ | |
231 | return TRUE; | |
232 | } | |
233 | ||
234 | bool wxResourceManager::SaveOptions() | |
235 | { | |
236 | wxConfig config("DialogEd", "wxWindows"); | |
237 | ||
238 | config.Write("editorWindowX", m_resourceEditorWindowSize.x); | |
239 | config.Write("editorWindowY", m_resourceEditorWindowSize.y); | |
240 | config.Write("editorWindowWidth", m_resourceEditorWindowSize.width); | |
241 | config.Write("editorWindowHeight", m_resourceEditorWindowSize.height); | |
242 | config.Write("propertyWindowX", m_propertyWindowSize.x); | |
243 | config.Write("propertyWindowY", m_propertyWindowSize.y); | |
244 | config.Write("propertyWindowWidth", m_propertyWindowSize.width); | |
245 | config.Write("propertyWindowHeight", m_propertyWindowSize.height); | |
246 | /* | |
247 | wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData()); | |
248 | wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData()); | |
249 | wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData()); | |
250 | wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData()); | |
251 | ||
252 | wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData()); | |
253 | wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData()); | |
254 | wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData()); | |
255 | wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData()); | |
256 | */ | |
257 | ||
258 | return TRUE; | |
259 | } | |
260 | ||
261 | // Show or hide the resource editor frame, which displays a list | |
262 | // of resources with ability to edit them. | |
263 | bool wxResourceManager::ShowResourceEditor(bool show, wxWindow *WXUNUSED(parent), const char *title) | |
264 | { | |
265 | if (show) | |
266 | { | |
267 | if (m_editorFrame) | |
268 | { | |
269 | m_editorFrame->Iconize(FALSE); | |
270 | m_editorFrame->Show(TRUE); | |
271 | return TRUE; | |
272 | } | |
273 | m_editorFrame = OnCreateEditorFrame(title); | |
274 | SetFrameTitle(""); | |
275 | wxMenuBar *menuBar = OnCreateEditorMenuBar(m_editorFrame); | |
276 | m_editorFrame->SetMenuBar(menuBar); | |
277 | ||
278 | m_editorToolBar = (EditorToolBar *)OnCreateToolBar(m_editorFrame); | |
279 | m_editorControlList = new wxResourceEditorControlList(m_editorFrame, IDC_LISTCTRL, wxPoint(0, 0), wxSize(-1, -1)); | |
280 | m_editorResourceTree = new wxResourceEditorProjectTree(m_editorFrame, IDC_TREECTRL, wxPoint(0, 0), wxSize(-1, -1), | |
281 | wxTR_HAS_BUTTONS); | |
282 | m_editorPanel = OnCreateEditorPanel(m_editorFrame); | |
283 | ||
284 | m_editorResourceTree->SetImageList(& m_imageList); | |
285 | ||
286 | // Constraints for toolbar | |
287 | wxLayoutConstraints *c = new wxLayoutConstraints; | |
288 | c->left.SameAs (m_editorFrame, wxLeft, 0); | |
289 | c->top.SameAs (m_editorFrame, wxTop, 0); | |
290 | c->right.SameAs (m_editorFrame, wxRight, 0); | |
291 | c->bottom.Unconstrained(); | |
292 | c->width.Unconstrained(); | |
293 | c->height.Absolute(28); | |
294 | m_editorToolBar->SetConstraints(c); | |
295 | ||
296 | // Constraints for listbox | |
297 | c = new wxLayoutConstraints; | |
298 | c->left.SameAs (m_editorFrame, wxLeft, 0); | |
299 | c->top.SameAs (m_editorToolBar, wxBottom, 0); | |
300 | c->right.Absolute (150); | |
301 | c->bottom.SameAs (m_editorControlList, wxTop, 0); | |
302 | c->width.Unconstrained(); | |
303 | c->height.Unconstrained(); | |
304 | m_editorResourceTree->SetConstraints(c); | |
305 | ||
306 | // Constraints for panel | |
307 | c = new wxLayoutConstraints; | |
308 | c->left.SameAs (m_editorResourceTree, wxRight, 0); | |
309 | c->top.SameAs (m_editorToolBar, wxBottom, 0); | |
310 | c->right.SameAs (m_editorFrame, wxRight, 0); | |
311 | c->bottom.SameAs (m_editorControlList, wxTop, 0); | |
312 | c->width.Unconstrained(); | |
313 | c->height.Unconstrained(); | |
314 | m_editorPanel->SetConstraints(c); | |
315 | ||
316 | // Constraints for control list (bottom window) | |
317 | c = new wxLayoutConstraints; | |
318 | c->left.SameAs (m_editorFrame, wxLeft, 0); | |
319 | c->right.SameAs (m_editorFrame, wxRight, 0); | |
320 | c->bottom.SameAs (m_editorFrame, wxBottom, 0); | |
321 | c->width.Unconstrained(); | |
322 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
323 | c->height.Absolute(120); | |
324 | #else | |
325 | c->height.Absolute(60); | |
326 | #endif | |
327 | ||
328 | m_editorControlList->SetConstraints(c); | |
329 | ||
330 | m_editorFrame->SetAutoLayout(TRUE); | |
331 | ||
332 | UpdateResourceList(); | |
333 | ||
334 | m_editorFrame->Show(TRUE); | |
335 | return TRUE; | |
336 | } | |
337 | else | |
338 | { | |
339 | wxFrame *fr = m_editorFrame; | |
340 | if (m_editorFrame->Close()) | |
341 | { | |
342 | m_editorFrame = NULL; | |
343 | m_editorPanel = NULL; | |
344 | } | |
345 | } | |
346 | return TRUE; | |
347 | } | |
348 | ||
349 | void wxResourceManager::SetFrameTitle(const wxString& filename) | |
350 | { | |
351 | if (m_editorFrame) | |
352 | { | |
353 | if (filename == wxString("")) | |
354 | m_editorFrame->SetTitle("wxWindows Dialog Editor - untitled"); | |
355 | else | |
356 | { | |
357 | wxString str("wxWindows Dialog Editor - "); | |
358 | wxString str2(wxFileNameFromPath(WXSTRINGCAST filename)); | |
359 | str += str2; | |
360 | m_editorFrame->SetTitle(str); | |
361 | } | |
362 | } | |
363 | } | |
364 | ||
365 | bool wxResourceManager::Save() | |
366 | { | |
367 | if (m_currentFilename == wxString("")) | |
368 | return SaveAs(); | |
369 | else | |
370 | return Save(m_currentFilename); | |
371 | } | |
372 | ||
373 | bool wxResourceManager::Save(const wxString& filename) | |
374 | { | |
375 | // Ensure all visible windows are saved to their resources | |
376 | m_currentFilename = filename; | |
377 | SetFrameTitle(m_currentFilename); | |
378 | InstantiateAllResourcesFromWindows(); | |
379 | if (m_resourceTable.Save(filename)) | |
380 | { | |
381 | m_symbolTable.WriteIncludeFile(m_symbolFilename); | |
382 | Modify(FALSE); | |
383 | return TRUE; | |
384 | } | |
385 | else | |
386 | return FALSE; | |
387 | } | |
388 | ||
389 | bool wxResourceManager::SaveAs() | |
390 | { | |
391 | wxString s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename), wxFileNameFromPath(WXSTRINGCAST m_currentFilename), | |
392 | "wxr", "*.wxr", wxSAVE | wxOVERWRITE_PROMPT, wxTheApp->GetTopWindow())); | |
393 | ||
394 | if (s.IsNull() || s == "") | |
395 | return FALSE; | |
396 | ||
397 | m_currentFilename = s; | |
398 | wxStripExtension(m_currentFilename); | |
399 | m_currentFilename += ".wxr"; | |
400 | ||
401 | // Construct include filename from this file | |
402 | m_symbolFilename = m_currentFilename; | |
403 | ||
404 | wxStripExtension(m_symbolFilename); | |
405 | m_symbolFilename += ".h"; | |
406 | ||
407 | Save(m_currentFilename); | |
408 | return TRUE; | |
409 | } | |
410 | ||
411 | bool wxResourceManager::SaveIfModified() | |
412 | { | |
413 | if (Modified()) | |
414 | return Save(); | |
415 | else return TRUE; | |
416 | } | |
417 | ||
418 | bool wxResourceManager::Load(const wxString& filename) | |
419 | { | |
420 | return New(TRUE, filename); | |
421 | } | |
422 | ||
423 | bool wxResourceManager::New(bool loadFromFile, const wxString& filename) | |
424 | { | |
425 | if (!Clear(TRUE, FALSE)) | |
426 | return FALSE; | |
427 | ||
428 | m_symbolTable.AddStandardSymbols(); | |
429 | ||
430 | if (loadFromFile) | |
431 | { | |
432 | wxString str = filename; | |
433 | if (str == wxString("")) | |
434 | { | |
435 | wxString f(wxFileSelector("Open resource file", NULL, NULL, "wxr", "*.wxr", 0, wxTheApp->GetTopWindow())); | |
436 | if (!f.IsNull() && f != "") | |
437 | str = f; | |
438 | else | |
439 | return FALSE; | |
440 | } | |
441 | ||
442 | if (!m_resourceTable.ParseResourceFile(WXSTRINGCAST str)) | |
443 | { | |
444 | wxMessageBox("Could not read file.", "Resource file load error", wxOK | wxICON_EXCLAMATION); | |
445 | return FALSE; | |
446 | } | |
447 | m_currentFilename = str; | |
448 | ||
449 | SetFrameTitle(m_currentFilename); | |
450 | ||
451 | UpdateResourceList(); | |
452 | ||
453 | // Construct include filename from this file | |
454 | m_symbolFilename = m_currentFilename; | |
455 | ||
456 | wxStripExtension(m_symbolFilename); | |
457 | m_symbolFilename += ".h"; | |
458 | ||
459 | if (!m_symbolTable.ReadIncludeFile(m_symbolFilename)) | |
460 | { | |
461 | wxString str("Could not find include file "); | |
462 | str += m_symbolFilename; | |
463 | str += ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n"; | |
464 | str += "The next time this .wxr file is saved, a header file will be saved also."; | |
465 | wxMessageBox(str, "Dialog Editor Warning", wxOK ); | |
466 | ||
467 | m_symbolIdCounter = 99; | |
468 | } | |
469 | else | |
470 | { | |
471 | // Set the id counter to the last known id | |
472 | m_symbolIdCounter = m_symbolTable.FindHighestId(); | |
473 | } | |
474 | ||
475 | // Now check in case some (or all) resources don't have resource ids, or they | |
476 | // don't match the .h file, or something of that nature. | |
477 | bool altered = RepairResourceIds(); | |
478 | if (altered) | |
479 | { | |
480 | wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.", | |
481 | "Dialog Editor Warning", wxOK ); | |
482 | Modify(TRUE); | |
483 | } | |
484 | else | |
485 | Modify(FALSE); | |
486 | ||
487 | return TRUE; | |
488 | } | |
489 | else | |
490 | { | |
491 | SetFrameTitle(""); | |
492 | m_currentFilename = ""; | |
493 | } | |
494 | Modify(FALSE); | |
495 | ||
496 | return TRUE; | |
497 | } | |
498 | ||
499 | bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows), bool force) | |
500 | { | |
501 | if (!force && Modified()) | |
502 | { | |
503 | int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL); | |
504 | if (ans == wxCANCEL) | |
505 | return FALSE; | |
506 | if (ans == wxYES) | |
507 | if (!SaveIfModified()) | |
508 | return FALSE; | |
509 | if (ans == wxNO) | |
510 | Modify(FALSE); | |
511 | } | |
512 | ||
513 | ClearCurrentDialog(); | |
514 | DisassociateWindows(); | |
515 | ||
516 | m_symbolTable.Clear(); | |
517 | m_resourceTable.ClearTable(); | |
518 | UpdateResourceList(); | |
519 | ||
520 | return TRUE; | |
521 | } | |
522 | ||
523 | bool wxResourceManager::DisassociateWindows() | |
524 | { | |
525 | m_resourceTable.BeginFind(); | |
526 | wxNode *node; | |
527 | while ((node = m_resourceTable.Next())) | |
528 | { | |
529 | wxItemResource *res = (wxItemResource *)node->Data(); | |
530 | DisassociateResource(res); | |
531 | } | |
532 | ||
533 | return TRUE; | |
534 | } | |
535 | ||
536 | void wxResourceManager::AssociateResource(wxItemResource *resource, wxWindow *win) | |
537 | { | |
538 | if (!m_resourceAssociations.Get((long)resource)) | |
539 | m_resourceAssociations.Put((long)resource, win); | |
540 | ||
541 | wxNode *node = resource->GetChildren().First(); | |
542 | while (node) | |
543 | { | |
544 | wxItemResource *child = (wxItemResource *)node->Data(); | |
545 | wxWindow *childWindow = (wxWindow *)m_resourceAssociations.Get((long)child); | |
546 | if (!childWindow) | |
547 | childWindow = win->FindWindow(child->GetName()); | |
548 | if (childWindow) | |
549 | AssociateResource(child, childWindow); | |
550 | else | |
551 | { | |
552 | char buf[200]; | |
553 | sprintf(buf, "AssociateResource: cannot find child window %s", child->GetName() ? (const char*) child->GetName() : "(unnamed)"); | |
554 | wxMessageBox(buf, "Dialog Editor problem", wxOK); | |
555 | } | |
556 | ||
557 | node = node->Next(); | |
558 | } | |
559 | } | |
560 | ||
561 | bool wxResourceManager::DisassociateResource(wxItemResource *resource) | |
562 | { | |
563 | wxWindow *win = FindWindowForResource(resource); | |
564 | if (!win) | |
565 | return FALSE; | |
566 | ||
567 | // Disassociate children of window | |
568 | wxNode *node = win->GetChildren().First(); | |
569 | while (node) | |
570 | { | |
571 | wxWindow *child = (wxWindow *)node->Data(); | |
572 | if (child->IsKindOf(CLASSINFO(wxControl))) | |
573 | DisassociateResource(child); | |
574 | node = node->Next(); | |
575 | } | |
576 | ||
577 | RemoveSelection(win); | |
578 | m_resourceAssociations.Delete((long)resource); | |
579 | return TRUE; | |
580 | } | |
581 | ||
582 | bool wxResourceManager::DisassociateResource(wxWindow *win) | |
583 | { | |
584 | wxItemResource *res = FindResourceForWindow(win); | |
585 | if (res) | |
586 | return DisassociateResource(res); | |
587 | else | |
588 | return FALSE; | |
589 | } | |
590 | ||
591 | // Saves the window info into the resource, and deletes the | |
592 | // handler. Doesn't actually disassociate the window from | |
593 | // the resources. Replaces OnClose. | |
594 | bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow* win) | |
595 | { | |
596 | wxItemResource *res = FindResourceForWindow(win); | |
597 | ||
598 | if (win->IsKindOf(CLASSINFO(wxPanel))) | |
599 | { | |
600 | wxResourceEditorDialogHandler* handler = (wxResourceEditorDialogHandler*) win->GetEventHandler(); | |
601 | win->PopEventHandler(); | |
602 | ||
603 | // Now reset all child event handlers | |
604 | wxNode *node = win->GetChildren().First(); | |
605 | while ( node ) | |
606 | { | |
607 | wxWindow *child = (wxWindow *)node->Data(); | |
608 | wxEvtHandler *childHandler = child->GetEventHandler(); | |
609 | if ( child->IsKindOf(CLASSINFO(wxControl)) && childHandler != child ) | |
610 | { | |
611 | child->PopEventHandler(TRUE); | |
612 | } | |
613 | node = node->Next(); | |
614 | } | |
615 | delete handler; | |
616 | } | |
617 | else | |
618 | { | |
619 | win->PopEventHandler(TRUE); | |
620 | } | |
621 | ||
622 | // Save the information | |
623 | InstantiateResourceFromWindow(res, win, TRUE); | |
624 | ||
625 | // DisassociateResource(win); | |
626 | ||
627 | return TRUE; | |
628 | } | |
629 | ||
630 | // Destroys the window. If this is the 'current' panel, NULLs the | |
631 | // variable. | |
632 | bool wxResourceManager::DeleteWindow(wxWindow* win) | |
633 | { | |
634 | bool clearDisplay = FALSE; | |
635 | if (m_editorPanel->m_childWindow == win) | |
636 | { | |
637 | m_editorPanel->m_childWindow = NULL; | |
638 | clearDisplay = TRUE; | |
639 | } | |
640 | ||
641 | win->Destroy(); | |
642 | ||
643 | if (clearDisplay) | |
644 | m_editorPanel->Clear(); | |
645 | ||
646 | return TRUE; | |
647 | } | |
648 | ||
649 | wxItemResource *wxResourceManager::FindResourceForWindow(wxWindow *win) | |
650 | { | |
651 | m_resourceAssociations.BeginFind(); | |
652 | wxNode *node; | |
653 | while ((node = m_resourceAssociations.Next())) | |
654 | { | |
655 | wxWindow *w = (wxWindow *)node->Data(); | |
656 | if (w == win) | |
657 | { | |
658 | return (wxItemResource *)node->GetKeyInteger(); | |
659 | } | |
660 | } | |
661 | return NULL; | |
662 | } | |
663 | ||
664 | wxWindow *wxResourceManager::FindWindowForResource(wxItemResource *resource) | |
665 | { | |
666 | return (wxWindow *)m_resourceAssociations.Get((long)resource); | |
667 | } | |
668 | ||
669 | ||
670 | void wxResourceManager::MakeUniqueName(char *prefix, char *buf) | |
671 | { | |
672 | while (TRUE) | |
673 | { | |
674 | sprintf(buf, "%s%d", prefix, m_nameCounter); | |
675 | m_nameCounter ++; | |
676 | ||
677 | if (!m_resourceTable.FindResource(buf)) | |
678 | return; | |
679 | } | |
680 | } | |
681 | ||
682 | wxFrame *wxResourceManager::OnCreateEditorFrame(const char *title) | |
683 | { | |
684 | /* | |
685 | int frameWidth = 420; | |
686 | int frameHeight = 300; | |
687 | */ | |
688 | ||
689 | wxResourceEditorFrame *frame = new wxResourceEditorFrame(this, NULL, title, | |
690 | wxPoint(m_resourceEditorWindowSize.x, m_resourceEditorWindowSize.y), | |
691 | wxSize(m_resourceEditorWindowSize.width, m_resourceEditorWindowSize.height), | |
692 | wxDEFAULT_FRAME_STYLE); | |
693 | ||
694 | frame->CreateStatusBar(1); | |
695 | ||
696 | frame->SetAutoLayout(TRUE); | |
697 | #ifdef __WXMSW__ | |
698 | frame->SetIcon(wxIcon("DIALOGEDICON")); | |
699 | #endif | |
700 | return frame; | |
701 | } | |
702 | ||
703 | wxMenuBar *wxResourceManager::OnCreateEditorMenuBar(wxFrame *WXUNUSED(parent)) | |
704 | { | |
705 | wxMenuBar *menuBar = new wxMenuBar; | |
706 | ||
707 | wxMenu *fileMenu = new wxMenu; | |
708 | fileMenu->Append(RESED_NEW_DIALOG, "New &dialog", "Create a new dialog"); | |
709 | fileMenu->AppendSeparator(); | |
710 | fileMenu->Append(wxID_NEW, "&New project", "Clear the current project"); | |
711 | fileMenu->Append(wxID_OPEN, "&Open...", "Load a resource file"); | |
712 | fileMenu->Append(wxID_SAVE, "&Save", "Save a resource file"); | |
713 | fileMenu->Append(wxID_SAVEAS, "Save &As...", "Save a resource file as..."); | |
714 | fileMenu->Append(RESED_CLEAR, "&Clear", "Clear current resources"); | |
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; | |
733 | } | |
734 | ||
735 | wxResourceEditorScrolledWindow *wxResourceManager::OnCreateEditorPanel(wxFrame *parent) | |
736 | { | |
737 | wxResourceEditorScrolledWindow *panel = new wxResourceEditorScrolledWindow(parent, wxDefaultPosition, wxDefaultSize, | |
738 | // wxSUNKEN_BORDER|wxCLIP_CHILDREN); | |
739 | #ifdef __WXMOTIF__ | |
740 | wxBORDER); | |
741 | #else | |
742 | wxSUNKEN_BORDER); | |
743 | #endif | |
744 | ||
745 | panel->SetScrollbars(10, 10, 100, 100); | |
746 | ||
747 | return panel; | |
748 | } | |
749 | ||
750 | wxToolBar *wxResourceManager::OnCreateToolBar(wxFrame *parent) | |
751 | { | |
752 | // Load palette bitmaps | |
753 | #ifdef __WXMSW__ | |
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 | #endif | |
768 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
769 | wxBitmap ToolbarLoadBitmap( load_xpm ); | |
770 | wxBitmap ToolbarSaveBitmap( save_xpm); | |
771 | wxBitmap ToolbarNewBitmap( new_xpm ); | |
772 | wxBitmap ToolbarVertBitmap( vert_xpm ); | |
773 | wxBitmap ToolbarAlignTBitmap( alignt_xpm ); | |
774 | wxBitmap ToolbarAlignBBitmap( alignb_xpm ); | |
775 | wxBitmap ToolbarHorizBitmap( horiz_xpm ); | |
776 | wxBitmap ToolbarAlignLBitmap( alignl_xpm ); | |
777 | wxBitmap ToolbarAlignRBitmap( alignr_xpm ); | |
778 | wxBitmap ToolbarCopySizeBitmap( copysize_xpm ); | |
779 | wxBitmap ToolbarToBackBitmap( toback_xpm ); | |
780 | wxBitmap ToolbarToFrontBitmap( tofront_xpm ); | |
781 | wxBitmap ToolbarHelpBitmap( help_xpm ); | |
782 | #endif | |
783 | ||
784 | // Create the toolbar | |
785 | EditorToolBar *toolbar = new EditorToolBar(parent, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER|wxTB_HORIZONTAL); | |
786 | toolbar->SetMargins(2, 2); | |
787 | ||
788 | #ifdef __WXMSW__ | |
789 | int width = 24; | |
790 | int dx = 2; | |
791 | int gap = 6; | |
792 | #else | |
793 | int width = 24; // ToolbarLoadBitmap->GetWidth(); ??? | |
794 | int dx = 2; | |
795 | int gap = 6; | |
796 | #endif | |
797 | int currentX = gap; | |
798 | toolbar->AddSeparator(); | |
799 | toolbar->AddTool(TOOLBAR_NEW, ToolbarNewBitmap, wxNullBitmap, | |
800 | FALSE, currentX, -1, NULL, "New dialog"); | |
801 | currentX += width + dx; | |
802 | toolbar->AddTool(TOOLBAR_LOAD_FILE, ToolbarLoadBitmap, wxNullBitmap, | |
803 | FALSE, currentX, -1, NULL, "Load"); | |
804 | currentX += width + dx; | |
805 | toolbar->AddTool(TOOLBAR_SAVE_FILE, ToolbarSaveBitmap, wxNullBitmap, | |
806 | FALSE, currentX, -1, NULL, "Save"); | |
807 | currentX += width + dx + gap; | |
808 | toolbar->AddSeparator(); | |
809 | toolbar->AddTool(TOOLBAR_FORMAT_HORIZ, ToolbarVertBitmap, wxNullBitmap, | |
810 | FALSE, currentX, -1, NULL, "Horizontal align"); | |
811 | currentX += width + dx; | |
812 | toolbar->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN, ToolbarAlignTBitmap, wxNullBitmap, | |
813 | FALSE, currentX, -1, NULL, "Top align"); | |
814 | currentX += width + dx; | |
815 | toolbar->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN, ToolbarAlignBBitmap, wxNullBitmap, | |
816 | FALSE, currentX, -1, NULL, "Bottom align"); | |
817 | currentX += width + dx; | |
818 | toolbar->AddTool(TOOLBAR_FORMAT_VERT, ToolbarHorizBitmap, wxNullBitmap, | |
819 | FALSE, currentX, -1, NULL, "Vertical align"); | |
820 | currentX += width + dx; | |
821 | toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN, ToolbarAlignLBitmap, wxNullBitmap, | |
822 | FALSE, currentX, -1, NULL, "Left align"); | |
823 | currentX += width + dx; | |
824 | toolbar->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN, ToolbarAlignRBitmap, wxNullBitmap, | |
825 | FALSE, currentX, -1, NULL, "Right align"); | |
826 | currentX += width + dx; | |
827 | toolbar->AddTool(TOOLBAR_COPY_SIZE, ToolbarCopySizeBitmap, wxNullBitmap, | |
828 | FALSE, currentX, -1, NULL, "Copy size"); | |
829 | currentX += width + dx + gap; | |
830 | toolbar->AddSeparator(); | |
831 | toolbar->AddTool(TOOLBAR_TO_FRONT, ToolbarToFrontBitmap, wxNullBitmap, | |
832 | FALSE, currentX, -1, NULL, "To front"); | |
833 | currentX += width + dx; | |
834 | toolbar->AddTool(TOOLBAR_TO_BACK, ToolbarToBackBitmap, wxNullBitmap, | |
835 | FALSE, currentX, -1, NULL, "To back"); | |
836 | currentX += width + dx + gap; | |
837 | ||
838 | toolbar->AddSeparator(); | |
839 | toolbar->AddTool(TOOLBAR_HELP, ToolbarHelpBitmap, wxNullBitmap, | |
840 | FALSE, currentX, -1, NULL, "Help"); | |
841 | currentX += width + dx; | |
842 | ||
843 | toolbar->Realize(); | |
844 | ||
845 | return toolbar; | |
846 | } | |
847 | ||
848 | void wxResourceManager::UpdateResourceList() | |
849 | { | |
850 | if (!m_editorResourceTree) | |
851 | return; | |
852 | ||
853 | m_editorResourceTree->SetInvalid(TRUE); | |
854 | m_editorResourceTree->DeleteAllItems(); | |
855 | ||
856 | long id = m_editorResourceTree->AddRoot("Dialogs", 1, 2); | |
857 | ||
858 | m_resourceTable.BeginFind(); | |
859 | wxNode *node; | |
860 | while ((node = m_resourceTable.Next())) | |
861 | { | |
862 | wxItemResource *res = (wxItemResource *)node->Data(); | |
863 | wxString resType(res->GetType()); | |
864 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel" || resType == "wxBitmap") | |
865 | { | |
866 | AddItemsRecursively(id, res); | |
867 | } | |
868 | } | |
869 | m_editorResourceTree->Expand(id); | |
870 | m_editorResourceTree->SetInvalid(FALSE); | |
871 | } | |
872 | ||
873 | void wxResourceManager::AddItemsRecursively(long parent, wxItemResource *resource) | |
874 | { | |
875 | wxString theString(""); | |
876 | theString = resource->GetName(); | |
877 | ||
878 | int imageId = 0; | |
879 | wxString resType(resource->GetType()); | |
880 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
881 | imageId = 0; | |
882 | else | |
883 | imageId = 3; | |
884 | ||
885 | long id = m_editorResourceTree->AppendItem(parent, theString, imageId ); | |
886 | ||
887 | m_editorResourceTree->SetItemData(id, new wxResourceTreeData(resource)); | |
888 | ||
889 | if (strcmp(resource->GetType(), "wxBitmap") != 0) | |
890 | { | |
891 | wxNode *node = resource->GetChildren().First(); | |
892 | while (node) | |
893 | { | |
894 | wxItemResource *res = (wxItemResource *)node->Data(); | |
895 | AddItemsRecursively(id, res); | |
896 | node = node->Next(); | |
897 | } | |
898 | } | |
899 | // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND); | |
900 | } | |
901 | ||
902 | bool wxResourceManager::EditSelectedResource() | |
903 | { | |
904 | int sel = m_editorResourceTree->GetSelection(); | |
905 | if (sel != 0) | |
906 | { | |
907 | wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel); | |
908 | wxItemResource *res = data->GetResource(); | |
909 | return Edit(res); | |
910 | } | |
911 | return FALSE; | |
912 | } | |
913 | ||
914 | bool wxResourceManager::Edit(wxItemResource *res) | |
915 | { | |
916 | ClearCurrentDialog(); | |
917 | ||
918 | wxString resType(res->GetType()); | |
919 | wxPanel *panel = (wxPanel *)FindWindowForResource(res); | |
920 | ||
921 | if (panel) | |
922 | { | |
923 | wxMessageBox("Should not find panel in wxResourceManager::Edit"); | |
924 | return FALSE; | |
925 | } | |
926 | else | |
927 | { | |
928 | // long style = res->GetStyle(); | |
929 | // res->SetStyle(style|wxRAISED_BORDER); | |
930 | panel = new wxPanel; | |
931 | wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, res, panel->GetEventHandler(), | |
932 | this); | |
933 | ||
934 | panel->LoadFromResource(m_editorPanel, res->GetName(), &m_resourceTable); | |
935 | ||
936 | panel->PushEventHandler(handler); | |
937 | ||
938 | // res->SetStyle(style); | |
939 | handler->AddChildHandlers(); // Add event handlers for all controls | |
940 | AssociateResource(res, panel); | |
941 | ||
942 | m_editorPanel->m_childWindow = panel; | |
943 | panel->Move(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()); | |
944 | panel->Show(TRUE); | |
945 | panel->Refresh(); | |
946 | ||
947 | wxClientDC dc(m_editorPanel); | |
948 | m_editorPanel->DrawTitle(dc); | |
949 | } | |
950 | return FALSE; | |
951 | } | |
952 | ||
953 | bool wxResourceManager::CreateNewPanel() | |
954 | { | |
955 | ClearCurrentDialog(); | |
956 | ||
957 | char buf[256]; | |
958 | MakeUniqueName("dialog", buf); | |
959 | ||
960 | wxItemResource *resource = new wxItemResource; | |
961 | resource->SetType("wxDialog"); | |
962 | resource->SetName(buf); | |
963 | resource->SetTitle(buf); | |
964 | resource->SetResourceStyle(wxRESOURCE_USE_DEFAULTS); | |
965 | resource->SetResourceStyle(wxRESOURCE_DIALOG_UNITS); | |
966 | ||
967 | wxString newIdName; | |
968 | int id = GenerateWindowId("ID_DIALOG", newIdName); | |
969 | resource->SetId(id); | |
970 | ||
971 | // This is now guaranteed to be unique, so just add to symbol table | |
972 | m_symbolTable.AddSymbol(newIdName, id); | |
973 | ||
974 | m_resourceTable.AddResource(resource); | |
975 | ||
976 | wxSize size(400, 300); | |
977 | ||
978 | wxPanel *panel = new wxPanel(m_editorPanel, -1, | |
979 | wxPoint(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()), | |
980 | size, wxRAISED_BORDER|wxDEFAULT_DIALOG_STYLE, buf); | |
981 | m_editorPanel->m_childWindow = panel; | |
982 | ||
983 | resource->SetStyle(panel->GetWindowStyleFlag()); | |
984 | ||
985 | // Store dialog units in resource | |
986 | size = panel->ConvertPixelsToDialog(size); | |
987 | ||
988 | resource->SetSize(10, 10, size.x, size.y); | |
989 | ||
990 | // For editing in situ we will need to use the hash table to ensure | |
991 | // we don't dereference invalid pointers. | |
992 | // resourceWindowTable.Put((long)resource, panel); | |
993 | ||
994 | wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, resource, panel->GetEventHandler(), | |
995 | this); | |
996 | panel->PushEventHandler(handler); | |
997 | ||
998 | AssociateResource(resource, panel); | |
999 | UpdateResourceList(); | |
1000 | ||
1001 | Modify(TRUE); | |
1002 | m_editorPanel->m_childWindow->Refresh(); | |
1003 | ||
1004 | // panel->Refresh(); | |
1005 | ||
1006 | wxClientDC dc(m_editorPanel); | |
1007 | m_editorPanel->DrawTitle(dc); | |
1008 | ||
1009 | return TRUE; | |
1010 | } | |
1011 | ||
1012 | bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *panel, char *iType, int x, int y, bool isBitmap) | |
1013 | { | |
1014 | char buf[256]; | |
1015 | if (!panel->IsKindOf(CLASSINFO(wxPanel)) && !panel->IsKindOf(CLASSINFO(wxDialog))) | |
1016 | return FALSE; | |
1017 | ||
1018 | Modify(TRUE); | |
1019 | ||
1020 | wxItemResource *res = new wxItemResource; | |
1021 | wxControl *newItem = NULL; | |
1022 | ||
1023 | if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) | |
1024 | { | |
1025 | wxPoint pt = panel->ConvertPixelsToDialog(wxPoint(x, y)); | |
1026 | res->SetSize(pt.x, pt.y, -1, -1); | |
1027 | } | |
1028 | else res->SetSize(x, y, -1, -1); | |
1029 | ||
1030 | res->SetType(iType); | |
1031 | ||
1032 | wxString prefix; | |
1033 | ||
1034 | wxString itemType(iType); | |
1035 | ||
1036 | if (itemType == "wxButton") | |
1037 | { | |
1038 | prefix = "ID_BUTTON"; | |
1039 | MakeUniqueName("button", buf); | |
1040 | res->SetName(buf); | |
1041 | if (isBitmap) | |
1042 | newItem = new wxBitmapButton(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); | |
1043 | else | |
1044 | newItem = new wxButton(panel, -1, "Button", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); | |
1045 | } | |
1046 | if (itemType == "wxBitmapButton") | |
1047 | { | |
1048 | prefix = "ID_BITMAPBUTTON"; | |
1049 | MakeUniqueName("button", buf); | |
1050 | res->SetName(buf); | |
1051 | newItem = new wxBitmapButton(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); | |
1052 | } | |
1053 | else if (itemType == "wxMessage" || itemType == "wxStaticText") | |
1054 | { | |
1055 | prefix = "ID_STATIC"; | |
1056 | MakeUniqueName("statictext", buf); | |
1057 | res->SetName(buf); | |
1058 | if (isBitmap) | |
1059 | newItem = new wxStaticBitmap(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(0, 0), 0, buf); | |
1060 | else | |
1061 | newItem = new wxStaticText(panel, -1, "Static", wxPoint(x, y), wxSize(-1, -1), 0, buf); | |
1062 | } | |
1063 | else if (itemType == "wxStaticBitmap") | |
1064 | { | |
1065 | prefix = "ID_STATICBITMAP"; | |
1066 | MakeUniqueName("static", buf); | |
1067 | res->SetName(buf); | |
1068 | newItem = new wxStaticBitmap(panel, -1, * m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, buf); | |
1069 | } | |
1070 | else if (itemType == "wxCheckBox") | |
1071 | { | |
1072 | prefix = "ID_CHECKBOX"; | |
1073 | MakeUniqueName("checkbox", buf); | |
1074 | res->SetName(buf); | |
1075 | newItem = new wxCheckBox(panel, -1, "Checkbox", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); | |
1076 | } | |
1077 | else if (itemType == "wxListBox") | |
1078 | { | |
1079 | prefix = "ID_LISTBOX"; | |
1080 | MakeUniqueName("listbox", buf); | |
1081 | res->SetName(buf); | |
1082 | newItem = new wxListBox(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf); | |
1083 | } | |
1084 | else if (itemType == "wxRadioBox") | |
1085 | { | |
1086 | prefix = "ID_RADIOBOX"; | |
1087 | MakeUniqueName("radiobox", buf); | |
1088 | res->SetName(buf); | |
1089 | wxString names[] = { "One", "Two" }; | |
1090 | newItem = new wxRadioBox(panel, -1, "Radiobox", wxPoint(x, y), wxSize(-1, -1), 2, names, 2, | |
1091 | wxHORIZONTAL, wxDefaultValidator, buf); | |
1092 | res->SetStringValues(wxStringList("One", "Two", NULL)); | |
1093 | } | |
1094 | else if (itemType == "wxRadioButton") | |
1095 | { | |
1096 | prefix = "ID_RADIOBUTTON"; | |
1097 | MakeUniqueName("radiobutton", buf); | |
1098 | res->SetName(buf); | |
1099 | wxString names[] = { "One", "Two" }; | |
1100 | newItem = new wxRadioButton(panel, -1, "Radiobutton", wxPoint(x, y), wxSize(-1, -1), | |
1101 | 0, wxDefaultValidator, buf); | |
1102 | } | |
1103 | else if (itemType == "wxChoice") | |
1104 | { | |
1105 | prefix = "ID_CHOICE"; | |
1106 | MakeUniqueName("choice", buf); | |
1107 | res->SetName(buf); | |
1108 | newItem = new wxChoice(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf); | |
1109 | } | |
1110 | else if (itemType == "wxComboBox") | |
1111 | { | |
1112 | prefix = "ID_COMBOBOX"; | |
1113 | MakeUniqueName("combobox", buf); | |
1114 | res->SetName(buf); | |
1115 | newItem = new wxComboBox(panel, -1, "", wxPoint(x, y), wxSize(-1, -1), 0, NULL, wxCB_DROPDOWN, wxDefaultValidator, buf); | |
1116 | } | |
1117 | else if (itemType == "wxGroupBox" || itemType == "wxStaticBox") | |
1118 | { | |
1119 | prefix = "ID_STATICBOX"; | |
1120 | MakeUniqueName("staticbox", buf); | |
1121 | res->SetName(buf); | |
1122 | newItem = new wxStaticBox(panel, -1, "Static", wxPoint(x, y), wxSize(200, 200), 0, buf); | |
1123 | } | |
1124 | else if (itemType == "wxGauge") | |
1125 | { | |
1126 | prefix = "ID_GAUGE"; | |
1127 | MakeUniqueName("gauge", buf); | |
1128 | res->SetName(buf); | |
1129 | newItem = new wxGauge(panel, -1, 10, wxPoint(x, y), wxSize(80, 30), wxHORIZONTAL, wxDefaultValidator, buf); | |
1130 | } | |
1131 | else if (itemType == "wxSlider") | |
1132 | { | |
1133 | prefix = "ID_SLIDER"; | |
1134 | MakeUniqueName("slider", buf); | |
1135 | res->SetName(buf); | |
1136 | newItem = new wxSlider(panel, -1, 1, 1, 10, wxPoint(x, y), wxSize(120, -1), wxHORIZONTAL, wxDefaultValidator, buf); | |
1137 | } | |
1138 | else if (itemType == "wxText" || itemType == "wxTextCtrl (single-line)") | |
1139 | { | |
1140 | prefix = "ID_TEXTCTRL"; | |
1141 | MakeUniqueName("textctrl", buf); | |
1142 | res->SetName(buf); | |
1143 | res->SetType("wxTextCtrl"); | |
1144 | newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, -1), 0, wxDefaultValidator, buf); | |
1145 | } | |
1146 | else if (itemType == "wxMultiText" || itemType == "wxTextCtrl (multi-line)") | |
1147 | { | |
1148 | prefix = "ID_TEXTCTRL"; | |
1149 | MakeUniqueName("textctrl", buf); | |
1150 | res->SetName(buf); | |
1151 | res->SetType("wxTextCtrl"); | |
1152 | newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, 100), wxTE_MULTILINE, wxDefaultValidator, buf); | |
1153 | } | |
1154 | else if (itemType == "wxScrollBar") | |
1155 | { | |
1156 | prefix = "ID_SCROLLBAR"; | |
1157 | MakeUniqueName("scrollbar", buf); | |
1158 | res->SetName(buf); | |
1159 | newItem = new wxScrollBar(panel, -1, wxPoint(x, y), wxSize(140, -1), wxHORIZONTAL, wxDefaultValidator, buf); | |
1160 | } | |
1161 | if (!newItem) | |
1162 | return FALSE; | |
1163 | ||
1164 | int actualW, actualH; | |
1165 | newItem->GetSize(&actualW, &actualH); | |
1166 | wxSize actualSize(actualW, actualH); | |
1167 | ||
1168 | if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) | |
1169 | { | |
1170 | actualSize = panel->ConvertPixelsToDialog(actualSize); | |
1171 | } | |
1172 | res->SetSize(res->GetX(), res->GetY(), actualSize.x, actualSize.y); | |
1173 | ||
1174 | wxString newIdName; | |
1175 | int id = GenerateWindowId(prefix, newIdName); | |
1176 | res->SetId(id); | |
1177 | ||
1178 | // This is now guaranteed to be unique, so just add to symbol table | |
1179 | m_symbolTable.AddSymbol(newIdName, id); | |
1180 | ||
1181 | newItem->PushEventHandler(new wxResourceEditorControlHandler(newItem, newItem)); | |
1182 | ||
1183 | res->SetStyle(newItem->GetWindowStyleFlag()); | |
1184 | AssociateResource(res, newItem); | |
1185 | panelResource->GetChildren().Append(res); | |
1186 | ||
1187 | UpdateResourceList(); | |
1188 | ||
1189 | return TRUE; | |
1190 | } | |
1191 | ||
1192 | void wxResourceManager::ClearCurrentDialog() | |
1193 | { | |
1194 | if (m_editorPanel->m_childWindow) | |
1195 | { | |
1196 | SaveInfoAndDeleteHandler(m_editorPanel->m_childWindow); | |
1197 | DisassociateResource(m_editorPanel->m_childWindow); | |
1198 | DeleteWindow(m_editorPanel->m_childWindow); | |
1199 | m_editorPanel->m_childWindow = NULL; | |
1200 | m_editorPanel->Clear(); | |
1201 | } | |
1202 | } | |
1203 | ||
1204 | bool wxResourceManager::TestCurrentDialog(wxWindow* parent) | |
1205 | { | |
1206 | if (m_editorPanel->m_childWindow) | |
1207 | { | |
1208 | wxItemResource* item = FindResourceForWindow(m_editorPanel->m_childWindow); | |
1209 | if (!item) | |
1210 | return FALSE; | |
1211 | ||
1212 | // Make sure the resources are up-to-date w.r.t. the window | |
1213 | InstantiateResourceFromWindow(item, m_editorPanel->m_childWindow, TRUE); | |
1214 | ||
1215 | wxDialog* dialog = new wxDialog; | |
1216 | bool success = FALSE; | |
1217 | if (dialog->LoadFromResource(parent, item->GetName(), & m_resourceTable)) | |
1218 | { | |
1219 | dialog->Centre(); | |
1220 | dialog->ShowModal(); | |
1221 | success = TRUE; | |
1222 | } | |
1223 | return success; | |
1224 | } | |
1225 | return FALSE; | |
1226 | } | |
1227 | ||
1228 | // Find the first dialog or panel for which | |
1229 | // there is a selected panel item. | |
1230 | wxWindow *wxResourceManager::FindParentOfSelection() | |
1231 | { | |
1232 | m_resourceTable.BeginFind(); | |
1233 | wxNode *node; | |
1234 | while ((node = m_resourceTable.Next())) | |
1235 | { | |
1236 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1237 | wxWindow *win = FindWindowForResource(res); | |
1238 | if (win) | |
1239 | { | |
1240 | wxNode *node1 = win->GetChildren().First(); | |
1241 | while (node1) | |
1242 | { | |
1243 | wxControl *item = (wxControl *)node1->Data(); | |
1244 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
1245 | if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected()) | |
1246 | return win; | |
1247 | node1 = node1->Next(); | |
1248 | } | |
1249 | } | |
1250 | } | |
1251 | return NULL; | |
1252 | } | |
1253 | ||
1254 | // Format the panel items according to 'flag' | |
1255 | void wxResourceManager::AlignItems(int flag) | |
1256 | { | |
1257 | wxWindow *win = FindParentOfSelection(); | |
1258 | if (!win) | |
1259 | return; | |
1260 | ||
1261 | wxNode *node = GetSelections().First(); | |
1262 | if (!node) | |
1263 | return; | |
1264 | ||
1265 | wxControl *firstSelection = (wxControl *)node->Data(); | |
1266 | if (firstSelection->GetParent() != win) | |
1267 | return; | |
1268 | ||
1269 | int firstX, firstY; | |
1270 | int firstW, firstH; | |
1271 | firstSelection->GetPosition(&firstX, &firstY); | |
1272 | firstSelection->GetSize(&firstW, &firstH); | |
1273 | int centreX = (int)(firstX + (firstW / 2)); | |
1274 | int centreY = (int)(firstY + (firstH / 2)); | |
1275 | ||
1276 | while ((node = node->Next())) | |
1277 | { | |
1278 | wxControl *item = (wxControl *)node->Data(); | |
1279 | if (item->GetParent() == win) | |
1280 | { | |
1281 | int x, y, w, h; | |
1282 | item->GetPosition(&x, &y); | |
1283 | item->GetSize(&w, &h); | |
1284 | ||
1285 | int newX, newY; | |
1286 | ||
1287 | switch (flag) | |
1288 | { | |
1289 | case TOOLBAR_FORMAT_HORIZ: | |
1290 | { | |
1291 | newX = x; | |
1292 | newY = (int)(centreY - (h/2.0)); | |
1293 | break; | |
1294 | } | |
1295 | case TOOLBAR_FORMAT_VERT: | |
1296 | { | |
1297 | newX = (int)(centreX - (w/2.0)); | |
1298 | newY = y; | |
1299 | break; | |
1300 | } | |
1301 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: | |
1302 | { | |
1303 | newX = firstX; | |
1304 | newY = y; | |
1305 | break; | |
1306 | } | |
1307 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: | |
1308 | { | |
1309 | newX = x; | |
1310 | newY = firstY; | |
1311 | break; | |
1312 | } | |
1313 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: | |
1314 | { | |
1315 | newX = firstX + firstW - w; | |
1316 | newY = y; | |
1317 | break; | |
1318 | } | |
1319 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: | |
1320 | { | |
1321 | newX = x; | |
1322 | newY = firstY + firstH - h; | |
1323 | break; | |
1324 | } | |
1325 | default: | |
1326 | newX = x; newY = y; | |
1327 | break; | |
1328 | } | |
1329 | ||
1330 | wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item); | |
1331 | wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent()); | |
1332 | ||
1333 | item->SetSize(newX, newY, w, h); | |
1334 | ||
1335 | // Also update the associated resource | |
1336 | // We need to convert to dialog units if this is not a dialog or panel, but | |
1337 | // the parent resource specifies dialog units. | |
1338 | if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) | |
1339 | { | |
1340 | wxPoint pt = item->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY)); | |
1341 | newX = pt.x; newY = pt.y; | |
1342 | wxSize sz = item->GetParent()->ConvertPixelsToDialog(wxSize(w, h)); | |
1343 | w = sz.x; h = sz.y; | |
1344 | } | |
1345 | resource->SetSize(newX, newY, w, h); | |
1346 | } | |
1347 | } | |
1348 | win->Refresh(); | |
1349 | } | |
1350 | ||
1351 | // Copy the first image's size to subsequent images | |
1352 | void wxResourceManager::CopySize() | |
1353 | { | |
1354 | wxWindow *win = FindParentOfSelection(); | |
1355 | if (!win) | |
1356 | return; | |
1357 | ||
1358 | wxNode *node = GetSelections().First(); | |
1359 | if (!node) | |
1360 | return; | |
1361 | ||
1362 | wxControl *firstSelection = (wxControl *)node->Data(); | |
1363 | if (firstSelection->GetParent() != win) | |
1364 | return; | |
1365 | ||
1366 | int firstX, firstY; | |
1367 | int firstW, firstH; | |
1368 | firstSelection->GetPosition(&firstX, &firstY); | |
1369 | firstSelection->GetSize(&firstW, &firstH); | |
1370 | ||
1371 | while ((node = node->Next())) | |
1372 | { | |
1373 | wxControl *item = (wxControl *)node->Data(); | |
1374 | if (item->GetParent() == win) | |
1375 | { | |
1376 | item->SetSize(-1, -1, firstW, firstH); | |
1377 | ||
1378 | wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item); | |
1379 | wxItemResource* parentResource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item->GetParent()); | |
1380 | ||
1381 | // Also update the associated resource | |
1382 | // We need to convert to dialog units if this is not a dialog or panel, but | |
1383 | // the parent resource specifies dialog units. | |
1384 | if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) | |
1385 | { | |
1386 | wxSize sz = item->GetParent()->ConvertPixelsToDialog(wxSize(firstW, firstH)); | |
1387 | firstW = sz.x; firstH = sz.y; | |
1388 | } | |
1389 | resource->SetSize(resource->GetX(), resource->GetY(), firstW, firstH); | |
1390 | ||
1391 | } | |
1392 | } | |
1393 | win->Refresh(); | |
1394 | } | |
1395 | ||
1396 | void wxResourceManager::ToBackOrFront(bool toBack) | |
1397 | { | |
1398 | wxWindow *win = FindParentOfSelection(); | |
1399 | if (!win) | |
1400 | return; | |
1401 | wxItemResource *winResource = FindResourceForWindow(win); | |
1402 | ||
1403 | wxNode *node = GetSelections().First(); | |
1404 | while (node) | |
1405 | { | |
1406 | wxControl *item = (wxControl *)node->Data(); | |
1407 | wxItemResource *itemResource = FindResourceForWindow(item); | |
1408 | if (item->GetParent() == win) | |
1409 | { | |
1410 | win->GetChildren().DeleteObject(item); | |
1411 | if (winResource) | |
1412 | winResource->GetChildren().DeleteObject(itemResource); | |
1413 | if (toBack) | |
1414 | { | |
1415 | win->GetChildren().Insert(item); | |
1416 | if (winResource) | |
1417 | winResource->GetChildren().Insert(itemResource); | |
1418 | } | |
1419 | else | |
1420 | { | |
1421 | win->GetChildren().Append(item); | |
1422 | if (winResource) | |
1423 | winResource->GetChildren().Append(itemResource); | |
1424 | } | |
1425 | } | |
1426 | node = node->Next(); | |
1427 | } | |
1428 | // win->Refresh(); | |
1429 | } | |
1430 | ||
1431 | void wxResourceManager::AddSelection(wxWindow *win) | |
1432 | { | |
1433 | if (!m_selections.Member(win)) | |
1434 | m_selections.Append(win); | |
1435 | } | |
1436 | ||
1437 | void wxResourceManager::RemoveSelection(wxWindow *win) | |
1438 | { | |
1439 | m_selections.DeleteObject(win); | |
1440 | } | |
1441 | ||
1442 | // Need to search through resource table removing this from | |
1443 | // any resource which has this as a parent. | |
1444 | bool wxResourceManager::RemoveResourceFromParent(wxItemResource *res) | |
1445 | { | |
1446 | m_resourceTable.BeginFind(); | |
1447 | wxNode *node; | |
1448 | while ((node = m_resourceTable.Next())) | |
1449 | { | |
1450 | wxItemResource *thisRes = (wxItemResource *)node->Data(); | |
1451 | if (thisRes->GetChildren().Member(res)) | |
1452 | { | |
1453 | thisRes->GetChildren().DeleteObject(res); | |
1454 | return TRUE; | |
1455 | } | |
1456 | } | |
1457 | return FALSE; | |
1458 | } | |
1459 | ||
1460 | bool wxResourceManager::DeleteResource(wxItemResource *res) | |
1461 | { | |
1462 | if (!res) | |
1463 | return FALSE; | |
1464 | ||
1465 | RemoveResourceFromParent(res); | |
1466 | ||
1467 | wxNode *node = res->GetChildren().First(); | |
1468 | while (node) | |
1469 | { | |
1470 | wxNode *next = node->Next(); | |
1471 | wxItemResource *child = (wxItemResource *)node->Data(); | |
1472 | DeleteResource(child); | |
1473 | node = next; | |
1474 | } | |
1475 | ||
1476 | // If this is a button or message resource, delete the | |
1477 | // associate bitmap resource if not being used. | |
1478 | wxString resType(res->GetType()); | |
1479 | ||
1480 | /* shouldn't have to do this now bitmaps are ref-counted | |
1481 | if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4()) | |
1482 | { | |
1483 | PossiblyDeleteBitmapResource(res->GetValue4()); | |
1484 | } | |
1485 | */ | |
1486 | ||
1487 | // Remove symbol from table if appropriate | |
1488 | if (!IsSymbolUsed(res, res->GetId())) | |
1489 | { | |
1490 | m_symbolTable.RemoveSymbol(res->GetId()); | |
1491 | } | |
1492 | ||
1493 | m_resourceTable.Delete(res->GetName()); | |
1494 | delete res; | |
1495 | Modify(TRUE); | |
1496 | return TRUE; | |
1497 | } | |
1498 | ||
1499 | bool wxResourceManager::DeleteResource(wxWindow *win) | |
1500 | { | |
1501 | if (win->IsKindOf(CLASSINFO(wxControl))) | |
1502 | { | |
1503 | // Deselect and refresh window in case we leave selection | |
1504 | // handles behind | |
1505 | wxControl *item = (wxControl *)win; | |
1506 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
1507 | if (childHandler->IsSelected()) | |
1508 | { | |
1509 | RemoveSelection(item); | |
1510 | childHandler->SelectItem(FALSE); | |
1511 | #ifndef __WXGTK__ | |
1512 | item->GetParent()->Refresh(); | |
1513 | #endif | |
1514 | } | |
1515 | } | |
1516 | ||
1517 | wxItemResource *res = FindResourceForWindow(win); | |
1518 | ||
1519 | DisassociateResource(res); | |
1520 | DeleteResource(res); | |
1521 | UpdateResourceList(); | |
1522 | ||
1523 | return TRUE; | |
1524 | } | |
1525 | ||
1526 | // Will eventually have bitmap type information, for different | |
1527 | // kinds of bitmap. | |
1528 | wxString wxResourceManager::AddBitmapResource(const wxString& filename) | |
1529 | { | |
1530 | wxItemResource *resource = FindBitmapResourceByFilename(filename); | |
1531 | if (!resource) | |
1532 | { | |
1533 | char buf[256]; | |
1534 | MakeUniqueName("bitmap", buf); | |
1535 | resource = new wxItemResource; | |
1536 | resource->SetType("wxBitmap"); | |
1537 | resource->SetName(buf); | |
1538 | ||
1539 | // A bitmap resource has one or more children, specifying | |
1540 | // alternative bitmaps. | |
1541 | wxItemResource *child = new wxItemResource; | |
1542 | child->SetType("wxBitmap"); | |
1543 | child->SetName(filename); | |
1544 | child->SetValue1(wxBITMAP_TYPE_BMP); | |
1545 | child->SetValue2(RESOURCE_PLATFORM_ANY); | |
1546 | child->SetValue3(0); // Depth | |
1547 | child->SetSize(0,0,0,0); | |
1548 | resource->GetChildren().Append(child); | |
1549 | ||
1550 | m_resourceTable.AddResource(resource); | |
1551 | ||
1552 | UpdateResourceList(); | |
1553 | } | |
1554 | if (resource) | |
1555 | return resource->GetName(); | |
1556 | else | |
1557 | return wxEmptyString; | |
1558 | } | |
1559 | ||
1560 | // Delete the bitmap resource if it isn't being used by another resource. | |
1561 | void wxResourceManager::PossiblyDeleteBitmapResource(const wxString& resourceName) | |
1562 | { | |
1563 | if (!IsBitmapResourceUsed(resourceName)) | |
1564 | { | |
1565 | wxItemResource *res = m_resourceTable.FindResource(resourceName); | |
1566 | DeleteResource(res); | |
1567 | UpdateResourceList(); | |
1568 | } | |
1569 | } | |
1570 | ||
1571 | bool wxResourceManager::IsBitmapResourceUsed(const wxString& resourceName) | |
1572 | { | |
1573 | m_resourceTable.BeginFind(); | |
1574 | wxNode *node; | |
1575 | while ((node = m_resourceTable.Next())) | |
1576 | { | |
1577 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1578 | wxString resType(res->GetType()); | |
1579 | if (resType == "wxDialog") | |
1580 | { | |
1581 | wxNode *node1 = res->GetChildren().First(); | |
1582 | while (node1) | |
1583 | { | |
1584 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1585 | wxString childResType(child->GetType()); | |
1586 | ||
1587 | if ((childResType == "wxMessage" || childResType == "wxButton") && | |
1588 | child->GetValue4() && | |
1589 | (strcmp(child->GetValue4(), resourceName) == 0)) | |
1590 | return TRUE; | |
1591 | node1 = node1->Next(); | |
1592 | } | |
1593 | } | |
1594 | } | |
1595 | return FALSE; | |
1596 | } | |
1597 | ||
1598 | // Given a wxButton or wxMessage, find the corresponding bitmap filename. | |
1599 | wxString wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource) | |
1600 | { | |
1601 | if (!resource || (resource->GetValue4() == "")) | |
1602 | return wxEmptyString; | |
1603 | wxItemResource *bitmapResource = m_resourceTable.FindResource(resource->GetValue4()); | |
1604 | if (!bitmapResource) | |
1605 | return wxEmptyString; | |
1606 | ||
1607 | wxNode *node = bitmapResource->GetChildren().First(); | |
1608 | while (node) | |
1609 | { | |
1610 | // Eventually augment this to return a bitmap of the right kind or something... | |
1611 | // Maybe the root of the filename remains the same, so it doesn't matter which we | |
1612 | // pick up. Otherwise how do we specify multiple filenames... too boring... | |
1613 | wxItemResource *child = (wxItemResource *)node->Data(); | |
1614 | return child->GetName(); | |
1615 | ||
1616 | node = node->Next(); | |
1617 | } | |
1618 | return wxEmptyString; | |
1619 | } | |
1620 | ||
1621 | wxItemResource *wxResourceManager::FindBitmapResourceByFilename(const wxString& filename) | |
1622 | { | |
1623 | m_resourceTable.BeginFind(); | |
1624 | wxNode *node; | |
1625 | while ((node = m_resourceTable.Next())) | |
1626 | { | |
1627 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1628 | wxString resType(res->GetType()); | |
1629 | if (resType == "wxBitmap") | |
1630 | { | |
1631 | wxNode *node1 = res->GetChildren().First(); | |
1632 | while (node1) | |
1633 | { | |
1634 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1635 | if (child->GetName() && (strcmp(child->GetName(), filename) == 0)) | |
1636 | return res; | |
1637 | node1 = node1->Next(); | |
1638 | } | |
1639 | } | |
1640 | } | |
1641 | return NULL; | |
1642 | } | |
1643 | ||
1644 | // Is this window identifier symbol in use? | |
1645 | // Let's assume that we can't have 2 names for the same integer id. | |
1646 | // Therefore we can tell by the integer id whether the symbol is | |
1647 | // in use. | |
1648 | bool wxResourceManager::IsSymbolUsed(wxItemResource* thisResource, wxWindowID id) | |
1649 | { | |
1650 | m_resourceTable.BeginFind(); | |
1651 | wxNode *node; | |
1652 | while ((node = m_resourceTable.Next())) | |
1653 | { | |
1654 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1655 | ||
1656 | wxString resType(res->GetType()); | |
1657 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
1658 | { | |
1659 | if ((res != thisResource) && (res->GetId() == id)) | |
1660 | return TRUE; | |
1661 | ||
1662 | wxNode *node1 = res->GetChildren().First(); | |
1663 | while (node1) | |
1664 | { | |
1665 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1666 | if ((child != thisResource) && (child->GetId() == id)) | |
1667 | return TRUE; | |
1668 | node1 = node1->Next(); | |
1669 | } | |
1670 | } | |
1671 | } | |
1672 | return FALSE; | |
1673 | } | |
1674 | ||
1675 | // Is this window identifier compatible with the given name? (i.e. | |
1676 | // does it already exist under a different name) | |
1677 | bool wxResourceManager::IsIdentifierOK(const wxString& name, wxWindowID id) | |
1678 | { | |
1679 | if (m_symbolTable.SymbolExists(name)) | |
1680 | { | |
1681 | int foundId = m_symbolTable.GetIdForSymbol(name); | |
1682 | if (foundId != id) | |
1683 | return FALSE; | |
1684 | } | |
1685 | return TRUE; | |
1686 | } | |
1687 | ||
1688 | // Change all integer ids that match oldId, to newId. | |
1689 | // This is necessary if an id is changed for one resource - all resources | |
1690 | // must be changed. | |
1691 | void wxResourceManager::ChangeIds(int oldId, int newId) | |
1692 | { | |
1693 | m_resourceTable.BeginFind(); | |
1694 | wxNode *node; | |
1695 | while ((node = m_resourceTable.Next())) | |
1696 | { | |
1697 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1698 | ||
1699 | wxString resType(res->GetType()); | |
1700 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
1701 | { | |
1702 | if (res->GetId() == oldId) | |
1703 | res->SetId(newId); | |
1704 | ||
1705 | wxNode *node1 = res->GetChildren().First(); | |
1706 | while (node1) | |
1707 | { | |
1708 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1709 | if (child->GetId() == oldId) | |
1710 | child->SetId(newId); | |
1711 | ||
1712 | node1 = node1->Next(); | |
1713 | } | |
1714 | } | |
1715 | } | |
1716 | } | |
1717 | ||
1718 | // If any resource ids were missing (or their symbol was missing), | |
1719 | // repair them i.e. give them new ids. Returns TRUE if any resource | |
1720 | // needed repairing. | |
1721 | bool wxResourceManager::RepairResourceIds() | |
1722 | { | |
1723 | bool repaired = FALSE; | |
1724 | ||
1725 | m_resourceTable.BeginFind(); | |
1726 | wxNode *node; | |
1727 | while ((node = m_resourceTable.Next())) | |
1728 | { | |
1729 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1730 | wxString resType(res->GetType()); | |
1731 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
1732 | { | |
1733 | ||
1734 | if ( (res->GetId() == 0) || ((res->GetId() > 0) && !m_symbolTable.IdExists(res->GetId())) ) | |
1735 | { | |
1736 | wxString newSymbolName; | |
1737 | int newId = GenerateWindowId("ID_DIALOG", newSymbolName) ; | |
1738 | ||
1739 | if (res->GetId() == 0) | |
1740 | { | |
1741 | res->SetId(newId); | |
1742 | m_symbolTable.AddSymbol(newSymbolName, newId); | |
1743 | } | |
1744 | else | |
1745 | { | |
1746 | m_symbolTable.AddSymbol(newSymbolName, res->GetId()); | |
1747 | } | |
1748 | ||
1749 | repaired = TRUE; | |
1750 | } | |
1751 | ||
1752 | wxNode *node1 = res->GetChildren().First(); | |
1753 | while (node1) | |
1754 | { | |
1755 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1756 | ||
1757 | if ( (child->GetId() == 0) || ((child->GetId() > 0) && !m_symbolTable.IdExists(child->GetId())) ) | |
1758 | { | |
1759 | wxString newSymbolName; | |
1760 | int newId = GenerateWindowId("ID_CONTROL", newSymbolName) ; | |
1761 | ||
1762 | if (child->GetId() == 0) | |
1763 | { | |
1764 | child->SetId(newId); | |
1765 | m_symbolTable.AddSymbol(newSymbolName, newId); | |
1766 | } | |
1767 | else | |
1768 | { | |
1769 | m_symbolTable.AddSymbol(newSymbolName, child->GetId()); | |
1770 | } | |
1771 | ||
1772 | repaired = TRUE; | |
1773 | } | |
1774 | ||
1775 | node1 = node1->Next(); | |
1776 | } | |
1777 | } | |
1778 | } | |
1779 | return repaired; | |
1780 | } | |
1781 | ||
1782 | ||
1783 | // Deletes 'win' and creates a new window from the resource that | |
1784 | // was associated with it. E.g. if you can't change properties on the | |
1785 | // fly, you'll need to delete the window and create it again. | |
1786 | wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info) | |
1787 | { | |
1788 | wxItemResource *resource = FindResourceForWindow(win); | |
1789 | ||
1790 | // Put the current window properties into the wxItemResource object | |
1791 | ||
1792 | wxWindowPropertyInfo *newInfo = NULL; | |
1793 | if (!info) | |
1794 | { | |
1795 | newInfo = CreatePropertyInfoForWindow(win); | |
1796 | info = newInfo; | |
1797 | } | |
1798 | ||
1799 | info->InstantiateResource(resource); | |
1800 | ||
1801 | wxWindow *newWin = NULL; | |
1802 | wxWindow *parent = win->GetParent(); | |
1803 | wxItemResource* parentResource = NULL; | |
1804 | if (parent) | |
1805 | parentResource = FindResourceForWindow(parent); | |
1806 | ||
1807 | if (win->IsKindOf(CLASSINFO(wxPanel))) | |
1808 | { | |
1809 | Edit(resource); | |
1810 | newWin = FindWindowForResource(resource); | |
1811 | } | |
1812 | else | |
1813 | { | |
1814 | DisassociateResource(resource); | |
1815 | if (win->GetEventHandler() != win) | |
1816 | win->PopEventHandler(TRUE); | |
1817 | ||
1818 | DeleteWindow(win); | |
1819 | newWin = m_resourceTable.CreateItem((wxPanel *)parent, resource, parentResource); | |
1820 | newWin->PushEventHandler(new wxResourceEditorControlHandler((wxControl*) newWin, (wxControl*) newWin)); | |
1821 | AssociateResource(resource, newWin); | |
1822 | UpdateResourceList(); | |
1823 | } | |
1824 | ||
1825 | if (info) | |
1826 | info->SetPropertyWindow(newWin); | |
1827 | ||
1828 | if (newInfo) | |
1829 | delete newInfo; | |
1830 | ||
1831 | return newWin; | |
1832 | } | |
1833 | ||
1834 | // Delete resource highlighted in the listbox | |
1835 | bool wxResourceManager::DeleteSelection() | |
1836 | { | |
1837 | int sel = m_editorResourceTree->GetSelection(); | |
1838 | if (sel != 0) | |
1839 | { | |
1840 | wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel); | |
1841 | wxItemResource *res = data->GetResource(); | |
1842 | wxWindow *win = FindWindowForResource(res); | |
1843 | if (win) | |
1844 | { | |
1845 | DeleteResource(win); | |
1846 | DeleteWindow(win); | |
1847 | UpdateResourceList(); | |
1848 | Modify(TRUE); | |
1849 | } | |
1850 | return TRUE; | |
1851 | } | |
1852 | ||
1853 | return FALSE; | |
1854 | } | |
1855 | ||
1856 | // Delete resource highlighted in the listbox | |
1857 | bool wxResourceManager::RecreateSelection() | |
1858 | { | |
1859 | wxNode *node = GetSelections().First(); | |
1860 | while (node) | |
1861 | { | |
1862 | wxControl *item = (wxControl *)node->Data(); | |
1863 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
1864 | wxNode *next = node->Next(); | |
1865 | childHandler->SelectItem(FALSE); | |
1866 | ||
1867 | RemoveSelection(item); | |
1868 | ||
1869 | RecreateWindowFromResource(item); | |
1870 | ||
1871 | node = next; | |
1872 | } | |
1873 | return TRUE; | |
1874 | } | |
1875 | ||
1876 | bool wxResourceManager::EditDialog(wxDialog *WXUNUSED(dialog), wxWindow *WXUNUSED(parent)) | |
1877 | { | |
1878 | return FALSE; | |
1879 | } | |
1880 | ||
1881 | // Ensures that all currently shown windows are saved to resources, | |
1882 | // e.g. just before writing to a .wxr file. | |
1883 | bool wxResourceManager::InstantiateAllResourcesFromWindows() | |
1884 | { | |
1885 | m_resourceTable.BeginFind(); | |
1886 | wxNode *node; | |
1887 | while ((node = m_resourceTable.Next())) | |
1888 | { | |
1889 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1890 | wxString resType(res->GetType()); | |
1891 | ||
1892 | if (resType == "wxDialog") | |
1893 | { | |
1894 | wxWindow *win = (wxWindow *)FindWindowForResource(res); | |
1895 | if (win) | |
1896 | InstantiateResourceFromWindow(res, win, TRUE); | |
1897 | } | |
1898 | else if (resType == "wxPanel") | |
1899 | { | |
1900 | wxWindow *win = (wxWindow *)FindWindowForResource(res); | |
1901 | if (win) | |
1902 | InstantiateResourceFromWindow(res, win, TRUE); | |
1903 | } | |
1904 | } | |
1905 | return TRUE; | |
1906 | } | |
1907 | ||
1908 | bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse) | |
1909 | { | |
1910 | wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(window); | |
1911 | info->SetResource(resource); | |
1912 | info->InstantiateResource(resource); | |
1913 | delete info; | |
1914 | ||
1915 | if (recurse) | |
1916 | { | |
1917 | wxNode *node = resource->GetChildren().First(); | |
1918 | while (node) | |
1919 | { | |
1920 | wxItemResource *child = (wxItemResource *)node->Data(); | |
1921 | wxWindow *childWindow = FindWindowForResource(child); | |
1922 | ||
1923 | if (!childWindow) | |
1924 | { | |
1925 | char buf[200]; | |
1926 | sprintf(buf, "Could not find window %s", (const char*) child->GetName()); | |
1927 | wxMessageBox(buf, "Dialog Editor problem", wxOK); | |
1928 | } | |
1929 | else | |
1930 | InstantiateResourceFromWindow(child, childWindow, recurse); | |
1931 | node = node->Next(); | |
1932 | } | |
1933 | } | |
1934 | ||
1935 | return TRUE; | |
1936 | } | |
1937 | ||
1938 | // Create a window information object for the give window | |
1939 | wxWindowPropertyInfo *wxResourceManager::CreatePropertyInfoForWindow(wxWindow *win) | |
1940 | { | |
1941 | wxWindowPropertyInfo *info = NULL; | |
1942 | if (win->IsKindOf(CLASSINFO(wxScrollBar))) | |
1943 | { | |
1944 | info = new wxScrollBarPropertyInfo(win); | |
1945 | } | |
1946 | else if (win->IsKindOf(CLASSINFO(wxStaticBox))) | |
1947 | { | |
1948 | info = new wxGroupBoxPropertyInfo(win); | |
1949 | } | |
1950 | else if (win->IsKindOf(CLASSINFO(wxCheckBox))) | |
1951 | { | |
1952 | info = new wxCheckBoxPropertyInfo(win); | |
1953 | } | |
1954 | else if (win->IsKindOf(CLASSINFO(wxSlider))) | |
1955 | { | |
1956 | info = new wxSliderPropertyInfo(win); | |
1957 | } | |
1958 | else if (win->IsKindOf(CLASSINFO(wxGauge))) | |
1959 | { | |
1960 | info = new wxGaugePropertyInfo(win); | |
1961 | } | |
1962 | else if (win->IsKindOf(CLASSINFO(wxListBox))) | |
1963 | { | |
1964 | info = new wxListBoxPropertyInfo(win); | |
1965 | } | |
1966 | else if (win->IsKindOf(CLASSINFO(wxRadioBox))) | |
1967 | { | |
1968 | info = new wxRadioBoxPropertyInfo(win); | |
1969 | } | |
1970 | else if (win->IsKindOf(CLASSINFO(wxRadioButton))) | |
1971 | { | |
1972 | info = new wxRadioButtonPropertyInfo(win); | |
1973 | } | |
1974 | else if (win->IsKindOf(CLASSINFO(wxComboBox))) | |
1975 | { | |
1976 | info = new wxComboBoxPropertyInfo(win); | |
1977 | } | |
1978 | else if (win->IsKindOf(CLASSINFO(wxChoice))) | |
1979 | { | |
1980 | info = new wxChoicePropertyInfo(win); | |
1981 | } | |
1982 | else if (win->IsKindOf(CLASSINFO(wxBitmapButton))) | |
1983 | { | |
1984 | info = new wxBitmapButtonPropertyInfo(win); | |
1985 | } | |
1986 | else if (win->IsKindOf(CLASSINFO(wxButton))) | |
1987 | { | |
1988 | info = new wxButtonPropertyInfo(win); | |
1989 | } | |
1990 | else if (win->IsKindOf(CLASSINFO(wxStaticBitmap))) | |
1991 | { | |
1992 | info = new wxStaticBitmapPropertyInfo(win); | |
1993 | } | |
1994 | else if (win->IsKindOf(CLASSINFO(wxStaticText))) | |
1995 | { | |
1996 | info = new wxStaticTextPropertyInfo(win); | |
1997 | } | |
1998 | else if (win->IsKindOf(CLASSINFO(wxTextCtrl))) | |
1999 | { | |
2000 | info = new wxTextPropertyInfo(win); | |
2001 | } | |
2002 | else if (win->IsKindOf(CLASSINFO(wxPanel))) | |
2003 | { | |
2004 | info = new wxPanelPropertyInfo(win); | |
2005 | } | |
2006 | else | |
2007 | { | |
2008 | info = new wxWindowPropertyInfo(win); | |
2009 | } | |
2010 | return info; | |
2011 | } | |
2012 | ||
2013 | // Edit the given window | |
2014 | void wxResourceManager::EditWindow(wxWindow *win) | |
2015 | { | |
2016 | wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(win); | |
2017 | if (info) | |
2018 | { | |
2019 | info->SetResource(FindResourceForWindow(win)); | |
2020 | wxString str("Editing "); | |
2021 | str += win->GetClassInfo()->GetClassName(); | |
2022 | str += ": "; | |
2023 | if (win->GetName() != "") | |
2024 | str += win->GetName(); | |
2025 | else | |
2026 | str += "properties"; | |
2027 | info->Edit(NULL, str); | |
2028 | } | |
2029 | } | |
2030 | ||
2031 | // Generate a window id and a first stab at a name | |
2032 | int wxResourceManager::GenerateWindowId(const wxString& prefix, wxString& idName) | |
2033 | { | |
2034 | m_symbolIdCounter ++; | |
2035 | while (m_symbolTable.IdExists(m_symbolIdCounter)) | |
2036 | m_symbolIdCounter ++; | |
2037 | ||
2038 | int nameId = m_symbolIdCounter; | |
2039 | ||
2040 | wxString str; | |
2041 | str.Printf("%d", nameId); | |
2042 | idName = prefix + str; | |
2043 | ||
2044 | while (m_symbolTable.SymbolExists(idName)) | |
2045 | { | |
2046 | nameId ++; | |
2047 | str.Printf("%d", nameId); | |
2048 | idName = prefix + str; | |
2049 | } | |
2050 | ||
2051 | return m_symbolIdCounter; | |
2052 | } | |
2053 | ||
2054 | ||
2055 | /* | |
2056 | * Resource editor frame | |
2057 | */ | |
2058 | ||
2059 | IMPLEMENT_CLASS(wxResourceEditorFrame, wxFrame) | |
2060 | ||
2061 | BEGIN_EVENT_TABLE(wxResourceEditorFrame, wxFrame) | |
2062 | EVT_MENU(wxID_NEW, wxResourceEditorFrame::OnNew) | |
2063 | EVT_MENU(RESED_NEW_DIALOG, wxResourceEditorFrame::OnNewDialog) | |
2064 | EVT_MENU(wxID_OPEN, wxResourceEditorFrame::OnOpen) | |
2065 | EVT_MENU(RESED_CLEAR, wxResourceEditorFrame::OnClear) | |
2066 | EVT_MENU(wxID_SAVE, wxResourceEditorFrame::OnSave) | |
2067 | EVT_MENU(wxID_SAVEAS, wxResourceEditorFrame::OnSaveAs) | |
2068 | EVT_MENU(wxID_EXIT, wxResourceEditorFrame::OnExit) | |
2069 | EVT_MENU(wxID_ABOUT, wxResourceEditorFrame::OnAbout) | |
2070 | EVT_MENU(RESED_CONTENTS, wxResourceEditorFrame::OnContents) | |
2071 | EVT_MENU(RESED_DELETE, wxResourceEditorFrame::OnDeleteSelection) | |
2072 | EVT_MENU(RESED_RECREATE, wxResourceEditorFrame::OnRecreateSelection) | |
2073 | EVT_MENU(RESED_TEST, wxResourceEditorFrame::OnTest) | |
2074 | EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow) | |
2075 | END_EVENT_TABLE() | |
2076 | ||
2077 | wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title, | |
2078 | const wxPoint& pos, const wxSize& size, long style, const wxString& name): | |
2079 | wxFrame(parent, -1, title, pos, size, style, name) | |
2080 | { | |
2081 | manager = resMan; | |
2082 | } | |
2083 | ||
2084 | wxResourceEditorFrame::~wxResourceEditorFrame() | |
2085 | { | |
2086 | } | |
2087 | ||
2088 | void wxResourceEditorFrame::OnNew(wxCommandEvent& WXUNUSED(event)) | |
2089 | { | |
2090 | manager->New(FALSE); | |
2091 | } | |
2092 | ||
2093 | void wxResourceEditorFrame::OnNewDialog(wxCommandEvent& WXUNUSED(event)) | |
2094 | { | |
2095 | manager->CreateNewPanel(); | |
2096 | } | |
2097 | ||
2098 | void wxResourceEditorFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) | |
2099 | { | |
2100 | manager->New(TRUE); | |
2101 | } | |
2102 | ||
2103 | void wxResourceEditorFrame::OnClear(wxCommandEvent& WXUNUSED(event)) | |
2104 | { | |
2105 | manager->Clear(TRUE, FALSE); | |
2106 | } | |
2107 | ||
2108 | void wxResourceEditorFrame::OnSave(wxCommandEvent& WXUNUSED(event)) | |
2109 | { | |
2110 | manager->Save(); | |
2111 | } | |
2112 | ||
2113 | void wxResourceEditorFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event)) | |
2114 | { | |
2115 | manager->SaveAs(); | |
2116 | } | |
2117 | ||
2118 | void wxResourceEditorFrame::OnExit(wxCommandEvent& WXUNUSED(event)) | |
2119 | { | |
2120 | manager->Clear(TRUE, FALSE) ; | |
2121 | this->Destroy(); | |
2122 | } | |
2123 | ||
2124 | void wxResourceEditorFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
2125 | { | |
2126 | char buf[300]; | |
2127 | sprintf(buf, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION); | |
2128 | wxMessageBox(buf, "About Dialog Editor", wxOK|wxCENTRE); | |
2129 | } | |
2130 | ||
2131 | void wxResourceEditorFrame::OnTest(wxCommandEvent& WXUNUSED(event)) | |
2132 | { | |
2133 | manager->TestCurrentDialog(this); | |
2134 | } | |
2135 | ||
2136 | void wxResourceEditorFrame::OnContents(wxCommandEvent& WXUNUSED(event)) | |
2137 | { | |
2138 | #ifdef __WXMSW__ | |
2139 | wxBeginBusyCursor(); | |
2140 | manager->GetHelpController()->LoadFile(); | |
2141 | manager->GetHelpController()->DisplayContents(); | |
2142 | wxEndBusyCursor(); | |
2143 | #endif | |
2144 | } | |
2145 | ||
2146 | void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent& WXUNUSED(event)) | |
2147 | { | |
2148 | manager->DeleteSelection(); | |
2149 | } | |
2150 | ||
2151 | void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& WXUNUSED(event)) | |
2152 | { | |
2153 | manager->RecreateSelection(); | |
2154 | } | |
2155 | ||
2156 | void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent& event) | |
2157 | { | |
2158 | if (manager->Modified()) | |
2159 | { | |
2160 | if (!manager->Clear(TRUE, FALSE)) | |
2161 | { | |
2162 | event.Veto(); | |
2163 | return; | |
2164 | } | |
2165 | } | |
2166 | ||
2167 | if (!Iconized()) | |
2168 | { | |
2169 | int w, h; | |
2170 | GetSize(&w, &h); | |
2171 | manager->m_resourceEditorWindowSize.width = w; | |
2172 | manager->m_resourceEditorWindowSize.height = h; | |
2173 | ||
2174 | int x, y; | |
2175 | GetPosition(&x, &y); | |
2176 | ||
2177 | manager->m_resourceEditorWindowSize.x = x; | |
2178 | manager->m_resourceEditorWindowSize.y = y; | |
2179 | } | |
2180 | manager->SetEditorFrame(NULL); | |
2181 | manager->SetEditorToolBar(NULL); | |
2182 | ||
2183 | this->Destroy(); | |
2184 | } | |
2185 | ||
2186 | /* | |
2187 | * Resource editor window that contains the dialog/panel being edited | |
2188 | */ | |
2189 | ||
2190 | BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow, wxScrolledWindow) | |
2191 | EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll) | |
2192 | EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint) | |
2193 | END_EVENT_TABLE() | |
2194 | ||
2195 | wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow *parent, const wxPoint& pos, const wxSize& size, | |
2196 | long style): | |
2197 | wxScrolledWindow(parent, -1, pos, size, style) | |
2198 | { | |
2199 | m_marginX = 10; | |
2200 | m_marginY = 40; | |
2201 | m_childWindow = NULL; | |
2202 | ||
2203 | SetBackgroundColour(* wxWHITE); | |
2204 | } | |
2205 | ||
2206 | wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow() | |
2207 | { | |
2208 | } | |
2209 | ||
2210 | void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent& event) | |
2211 | { | |
2212 | wxScrolledWindow::OnScroll(event); | |
2213 | ||
2214 | int x, y; | |
2215 | ViewStart(& x, & y); | |
2216 | ||
2217 | if (m_childWindow) | |
2218 | m_childWindow->Move(m_marginX + (- x * 10), m_marginY + (- y * 10)); | |
2219 | } | |
2220 | ||
2221 | void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
2222 | { | |
2223 | wxPaintDC dc(this); | |
2224 | ||
2225 | DrawTitle(dc); | |
2226 | } | |
2227 | ||
2228 | void wxResourceEditorScrolledWindow::DrawTitle(wxDC& dc) | |
2229 | { | |
2230 | if (m_childWindow) | |
2231 | { | |
2232 | wxItemResource* res = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow); | |
2233 | if (res) | |
2234 | { | |
2235 | wxString str(res->GetTitle()); | |
2236 | int x, y; | |
2237 | ViewStart(& x, & y); | |
2238 | ||
2239 | wxFont font(10, wxSWISS, wxNORMAL, wxBOLD); | |
2240 | dc.SetFont(font); | |
2241 | dc.SetBackgroundMode(wxTRANSPARENT); | |
2242 | dc.SetTextForeground(wxColour(0, 0, 0)); | |
2243 | ||
2244 | long w, h; | |
2245 | dc.GetTextExtent(str, & w, & h); | |
2246 | ||
2247 | dc.DrawText(str, m_marginX + (- x * 10), m_marginY + (- y * 10) - h - 5); | |
2248 | } | |
2249 | } | |
2250 | } | |
2251 | ||
2252 | // Popup menu callback | |
2253 | void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event) | |
2254 | { | |
2255 | wxWindow *data = (wxWindow *)menu.GetClientData(); | |
2256 | if (!data) | |
2257 | return; | |
2258 | ||
2259 | switch (event.GetInt()) | |
2260 | { | |
2261 | case OBJECT_MENU_EDIT: | |
2262 | { | |
2263 | wxResourceManager::GetCurrentResourceManager()->EditWindow(data); | |
2264 | break; | |
2265 | } | |
2266 | case OBJECT_MENU_DELETE: | |
2267 | { | |
2268 | wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data); | |
2269 | wxResourceManager::GetCurrentResourceManager()->DeleteResource(data); | |
2270 | wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data); | |
2271 | break; | |
2272 | } | |
2273 | default: | |
2274 | break; | |
2275 | } | |
2276 | } | |
2277 | ||
2278 | /* | |
2279 | * Main toolbar | |
2280 | * | |
2281 | */ | |
2282 | ||
2283 | #if defined(__WXGTK__) || defined(__WXMOTIF__) // I don't dare to delete it... | |
2284 | ||
2285 | BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar) | |
2286 | END_EVENT_TABLE() | |
2287 | ||
2288 | #else | |
2289 | ||
2290 | BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar) | |
2291 | EVT_PAINT(EditorToolBar::OnPaint) | |
2292 | END_EVENT_TABLE() | |
2293 | ||
2294 | #endif | |
2295 | ||
2296 | EditorToolBar::EditorToolBar(wxFrame *frame, const wxPoint& pos, const wxSize& size, | |
2297 | long style): | |
2298 | wxToolBar(frame, -1, pos, size, style) | |
2299 | { | |
2300 | } | |
2301 | ||
2302 | bool EditorToolBar::OnLeftClick(int toolIndex, bool WXUNUSED(toggled)) | |
2303 | { | |
2304 | wxResourceManager *manager = wxResourceManager::GetCurrentResourceManager(); | |
2305 | ||
2306 | switch (toolIndex) | |
2307 | { | |
2308 | case TOOLBAR_LOAD_FILE: | |
2309 | { | |
2310 | manager->New(TRUE); | |
2311 | break; | |
2312 | } | |
2313 | case TOOLBAR_NEW: | |
2314 | { | |
2315 | manager->CreateNewPanel(); | |
2316 | break; | |
2317 | } | |
2318 | case TOOLBAR_SAVE_FILE: | |
2319 | { | |
2320 | manager->Save(); | |
2321 | break; | |
2322 | } | |
2323 | case TOOLBAR_HELP: | |
2324 | { | |
2325 | #ifdef __WXMSW__ | |
2326 | wxBeginBusyCursor(); | |
2327 | manager->GetHelpController()->LoadFile(); | |
2328 | manager->GetHelpController()->DisplayContents(); | |
2329 | wxEndBusyCursor(); | |
2330 | #endif | |
2331 | break; | |
2332 | } | |
2333 | case TOOLBAR_FORMAT_HORIZ: | |
2334 | { | |
2335 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ); | |
2336 | break; | |
2337 | } | |
2338 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: | |
2339 | { | |
2340 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN); | |
2341 | break; | |
2342 | } | |
2343 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: | |
2344 | { | |
2345 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN); | |
2346 | break; | |
2347 | } | |
2348 | case TOOLBAR_FORMAT_VERT: | |
2349 | { | |
2350 | manager->AlignItems(TOOLBAR_FORMAT_VERT); | |
2351 | break; | |
2352 | } | |
2353 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: | |
2354 | { | |
2355 | manager->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN); | |
2356 | break; | |
2357 | } | |
2358 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: | |
2359 | { | |
2360 | manager->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN); | |
2361 | break; | |
2362 | } | |
2363 | case TOOLBAR_COPY_SIZE: | |
2364 | { | |
2365 | manager->CopySize(); | |
2366 | break; | |
2367 | } | |
2368 | case TOOLBAR_TO_BACK: | |
2369 | { | |
2370 | manager->ToBackOrFront(TRUE); | |
2371 | break; | |
2372 | } | |
2373 | case TOOLBAR_TO_FRONT: | |
2374 | { | |
2375 | manager->ToBackOrFront(FALSE); | |
2376 | break; | |
2377 | } | |
2378 | default: | |
2379 | break; | |
2380 | } | |
2381 | return TRUE; | |
2382 | } | |
2383 | ||
2384 | void EditorToolBar::OnMouseEnter(int toolIndex) | |
2385 | { | |
2386 | wxFrame *frame = (wxFrame *)GetParent(); | |
2387 | ||
2388 | if (!frame) return; | |
2389 | ||
2390 | if (toolIndex > -1) | |
2391 | { | |
2392 | switch (toolIndex) | |
2393 | { | |
2394 | case TOOLBAR_LOAD_FILE: | |
2395 | frame->SetStatusText("Load project file"); | |
2396 | break; | |
2397 | case TOOLBAR_SAVE_FILE: | |
2398 | frame->SetStatusText("Save project file"); | |
2399 | break; | |
2400 | case TOOLBAR_NEW: | |
2401 | frame->SetStatusText("Create a new resource"); | |
2402 | break; | |
2403 | case TOOLBAR_FORMAT_HORIZ: | |
2404 | frame->SetStatusText("Align items horizontally"); | |
2405 | break; | |
2406 | case TOOLBAR_FORMAT_VERT: | |
2407 | frame->SetStatusText("Align items vertically"); | |
2408 | break; | |
2409 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: | |
2410 | frame->SetStatusText("Left-align items"); | |
2411 | break; | |
2412 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: | |
2413 | frame->SetStatusText("Right-align items"); | |
2414 | break; | |
2415 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: | |
2416 | frame->SetStatusText("Top-align items"); | |
2417 | break; | |
2418 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: | |
2419 | frame->SetStatusText("Bottom-align items"); | |
2420 | break; | |
2421 | case TOOLBAR_COPY_SIZE: | |
2422 | frame->SetStatusText("Copy size from first selection"); | |
2423 | break; | |
2424 | case TOOLBAR_TO_FRONT: | |
2425 | frame->SetStatusText("Put image to front"); | |
2426 | break; | |
2427 | case TOOLBAR_TO_BACK: | |
2428 | frame->SetStatusText("Put image to back"); | |
2429 | break; | |
2430 | case TOOLBAR_HELP: | |
2431 | frame->SetStatusText("Display help contents"); | |
2432 | break; | |
2433 | default: | |
2434 | break; | |
2435 | } | |
2436 | } | |
2437 | else frame->SetStatusText(""); | |
2438 | } | |
2439 |