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