]>
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 | { | |
e47d37d0 | 656 | return (wxItemResource *)node->key.integer; |
457814b5 JS |
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 | |
e47d37d0 | 879 | long id = m_editorResourceTree->AppendItem(parent, theString, imageId ); |
ae8351fc | 880 | |
1195ec42 | 881 | m_editorResourceTree->SetItemData(id, new wxResourceTreeData(resource)); |
457814b5 JS |
882 | |
883 | if (strcmp(resource->GetType(), "wxBitmap") != 0) | |
884 | { | |
885 | wxNode *node = resource->GetChildren().First(); | |
886 | while (node) | |
887 | { | |
888 | wxItemResource *res = (wxItemResource *)node->Data(); | |
ae8351fc | 889 | AddItemsRecursively(id, res); |
457814b5 JS |
890 | node = node->Next(); |
891 | } | |
892 | } | |
dfad0599 | 893 | // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND); |
457814b5 JS |
894 | } |
895 | ||
ae8351fc | 896 | bool wxResourceManager::EditSelectedResource() |
457814b5 | 897 | { |
ae8351fc | 898 | int sel = m_editorResourceTree->GetSelection(); |
03f68f12 | 899 | if (sel != 0) |
457814b5 | 900 | { |
1195ec42 VZ |
901 | wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel); |
902 | wxItemResource *res = data->GetResource(); | |
457814b5 JS |
903 | return Edit(res); |
904 | } | |
905 | return FALSE; | |
906 | } | |
907 | ||
908 | bool wxResourceManager::Edit(wxItemResource *res) | |
909 | { | |
ae8351fc JS |
910 | ClearCurrentDialog(); |
911 | ||
457814b5 | 912 | wxString resType(res->GetType()); |
ae8351fc | 913 | wxPanel *panel = (wxPanel *)FindWindowForResource(res); |
457814b5 | 914 | |
ae8351fc JS |
915 | if (panel) |
916 | { | |
917 | wxMessageBox("Should not find panel in wxResourceManager::Edit"); | |
918 | return FALSE; | |
919 | } | |
920 | else | |
921 | { | |
dfad0599 JS |
922 | // long style = res->GetStyle(); |
923 | // res->SetStyle(style|wxRAISED_BORDER); | |
457814b5 JS |
924 | panel = new wxPanel; |
925 | wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, res, panel->GetEventHandler(), | |
926 | this); | |
457814b5 | 927 | |
ae8351fc | 928 | panel->LoadFromResource(m_editorPanel, res->GetName(), &m_resourceTable); |
457814b5 | 929 | |
ae8351fc | 930 | panel->PushEventHandler(handler); |
457814b5 | 931 | |
dfad0599 | 932 | // res->SetStyle(style); |
ae8351fc JS |
933 | handler->AddChildHandlers(); // Add event handlers for all controls |
934 | AssociateResource(res, panel); | |
457814b5 | 935 | |
ae8351fc JS |
936 | m_editorPanel->m_childWindow = panel; |
937 | panel->Move(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()); | |
938 | panel->Show(TRUE); | |
939 | panel->Refresh(); | |
457814b5 | 940 | |
ae8351fc JS |
941 | wxClientDC dc(m_editorPanel); |
942 | m_editorPanel->DrawTitle(dc); | |
943 | } | |
944 | return FALSE; | |
457814b5 JS |
945 | } |
946 | ||
ae8351fc | 947 | bool wxResourceManager::CreateNewPanel() |
457814b5 | 948 | { |
ae8351fc JS |
949 | ClearCurrentDialog(); |
950 | ||
457814b5 | 951 | char buf[256]; |
bbcdf8bc | 952 | MakeUniqueName("dialog", buf); |
457814b5 JS |
953 | |
954 | wxItemResource *resource = new wxItemResource; | |
bbcdf8bc | 955 | resource->SetType("wxDialog"); |
457814b5 JS |
956 | resource->SetName(buf); |
957 | resource->SetTitle(buf); | |
fd71308f JS |
958 | resource->SetResourceStyle(wxRESOURCE_USE_DEFAULTS); |
959 | resource->SetResourceStyle(wxRESOURCE_DIALOG_UNITS); | |
5de76427 JS |
960 | |
961 | wxString newIdName; | |
962 | int id = GenerateWindowId("ID_DIALOG", newIdName); | |
963 | resource->SetId(id); | |
964 | ||
965 | // This is now guaranteed to be unique, so just add to symbol table | |
966 | m_symbolTable.AddSymbol(newIdName, id); | |
967 | ||
ae8351fc | 968 | m_resourceTable.AddResource(resource); |
457814b5 | 969 | |
fd71308f JS |
970 | wxSize size(400, 300); |
971 | ||
ae8351fc JS |
972 | wxPanel *panel = new wxPanel(m_editorPanel, -1, |
973 | wxPoint(m_editorPanel->GetMarginX(), m_editorPanel->GetMarginY()), | |
fd71308f | 974 | size, wxRAISED_BORDER|wxDEFAULT_DIALOG_STYLE, buf); |
ae8351fc | 975 | m_editorPanel->m_childWindow = panel; |
457814b5 | 976 | |
bbcdf8bc | 977 | resource->SetStyle(panel->GetWindowStyleFlag()); |
fd71308f JS |
978 | |
979 | // Store dialog units in resource | |
980 | size = panel->ConvertPixelsToDialog(size); | |
981 | ||
982 | resource->SetSize(10, 10, size.x, size.y); | |
457814b5 JS |
983 | |
984 | // For editing in situ we will need to use the hash table to ensure | |
985 | // we don't dereference invalid pointers. | |
986 | // resourceWindowTable.Put((long)resource, panel); | |
987 | ||
988 | wxResourceEditorDialogHandler *handler = new wxResourceEditorDialogHandler(panel, resource, panel->GetEventHandler(), | |
989 | this); | |
990 | panel->PushEventHandler(handler); | |
991 | ||
457814b5 | 992 | AssociateResource(resource, panel); |
457814b5 JS |
993 | UpdateResourceList(); |
994 | ||
995 | Modify(TRUE); | |
ae8351fc JS |
996 | m_editorPanel->m_childWindow->Refresh(); |
997 | ||
998 | // panel->Refresh(); | |
999 | ||
1000 | wxClientDC dc(m_editorPanel); | |
1001 | m_editorPanel->DrawTitle(dc); | |
1002 | ||
457814b5 JS |
1003 | return TRUE; |
1004 | } | |
1005 | ||
1006 | bool wxResourceManager::CreatePanelItem(wxItemResource *panelResource, wxPanel *panel, char *iType, int x, int y, bool isBitmap) | |
1007 | { | |
1008 | char buf[256]; | |
1009 | if (!panel->IsKindOf(CLASSINFO(wxPanel)) && !panel->IsKindOf(CLASSINFO(wxDialog))) | |
1010 | return FALSE; | |
1011 | ||
1012 | Modify(TRUE); | |
1013 | ||
1014 | wxItemResource *res = new wxItemResource; | |
1015 | wxControl *newItem = NULL; | |
fd71308f JS |
1016 | |
1017 | if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) | |
1018 | { | |
386af6a2 | 1019 | wxPoint pt = panel->ConvertPixelsToDialog(wxPoint(x, y)); |
fd71308f JS |
1020 | res->SetSize(pt.x, pt.y, -1, -1); |
1021 | } | |
1022 | else res->SetSize(x, y, -1, -1); | |
1023 | ||
457814b5 | 1024 | res->SetType(iType); |
5de76427 JS |
1025 | |
1026 | wxString prefix; | |
457814b5 JS |
1027 | |
1028 | wxString itemType(iType); | |
1029 | ||
1030 | if (itemType == "wxButton") | |
1031 | { | |
5de76427 | 1032 | prefix = "ID_BUTTON"; |
457814b5 JS |
1033 | MakeUniqueName("button", buf); |
1034 | res->SetName(buf); | |
1035 | if (isBitmap) | |
ae8351fc | 1036 | newItem = new wxBitmapButton(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); |
457814b5 JS |
1037 | else |
1038 | newItem = new wxButton(panel, -1, "Button", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); | |
1039 | } | |
1040 | if (itemType == "wxBitmapButton") | |
1041 | { | |
5de76427 | 1042 | prefix = "ID_BITMAPBUTTON"; |
457814b5 JS |
1043 | MakeUniqueName("button", buf); |
1044 | res->SetName(buf); | |
ae8351fc | 1045 | newItem = new wxBitmapButton(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); |
457814b5 JS |
1046 | } |
1047 | else if (itemType == "wxMessage" || itemType == "wxStaticText") | |
1048 | { | |
5de76427 | 1049 | prefix = "ID_STATIC"; |
9c331ded | 1050 | MakeUniqueName("statictext", buf); |
457814b5 JS |
1051 | res->SetName(buf); |
1052 | if (isBitmap) | |
ae8351fc | 1053 | newItem = new wxStaticBitmap(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(0, 0), 0, buf); |
457814b5 | 1054 | else |
9c331ded | 1055 | newItem = new wxStaticText(panel, -1, "Static", wxPoint(x, y), wxSize(-1, -1), 0, buf); |
457814b5 JS |
1056 | } |
1057 | else if (itemType == "wxStaticBitmap") | |
1058 | { | |
5de76427 | 1059 | prefix = "ID_STATICBITMAP"; |
9c331ded | 1060 | MakeUniqueName("static", buf); |
457814b5 | 1061 | res->SetName(buf); |
ae8351fc | 1062 | newItem = new wxStaticBitmap(panel, -1, m_bitmapImage, wxPoint(x, y), wxSize(-1, -1), 0, buf); |
457814b5 JS |
1063 | } |
1064 | else if (itemType == "wxCheckBox") | |
1065 | { | |
5de76427 | 1066 | prefix = "ID_CHECKBOX"; |
457814b5 JS |
1067 | MakeUniqueName("checkbox", buf); |
1068 | res->SetName(buf); | |
1069 | newItem = new wxCheckBox(panel, -1, "Checkbox", wxPoint(x, y), wxSize(-1, -1), 0, wxDefaultValidator, buf); | |
1070 | } | |
1071 | else if (itemType == "wxListBox") | |
1072 | { | |
bbcdf8bc | 1073 | prefix = "ID_LISTBOX"; |
457814b5 JS |
1074 | MakeUniqueName("listbox", buf); |
1075 | res->SetName(buf); | |
1076 | newItem = new wxListBox(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf); | |
1077 | } | |
1078 | else if (itemType == "wxRadioBox") | |
1079 | { | |
5de76427 | 1080 | prefix = "ID_RADIOBOX"; |
457814b5 JS |
1081 | MakeUniqueName("radiobox", buf); |
1082 | res->SetName(buf); | |
1083 | wxString names[] = { "One", "Two" }; | |
1084 | newItem = new wxRadioBox(panel, -1, "Radiobox", wxPoint(x, y), wxSize(-1, -1), 2, names, 2, | |
1085 | wxHORIZONTAL, wxDefaultValidator, buf); | |
fd71308f | 1086 | res->SetStringValues(wxStringList("One", "Two", NULL)); |
457814b5 | 1087 | } |
03f68f12 JS |
1088 | else if (itemType == "wxRadioButton") |
1089 | { | |
5de76427 | 1090 | prefix = "ID_RADIOBUTTON"; |
03f68f12 JS |
1091 | MakeUniqueName("radiobutton", buf); |
1092 | res->SetName(buf); | |
1093 | wxString names[] = { "One", "Two" }; | |
1094 | newItem = new wxRadioButton(panel, -1, "Radiobutton", wxPoint(x, y), wxSize(-1, -1), | |
1095 | 0, wxDefaultValidator, buf); | |
1096 | } | |
457814b5 JS |
1097 | else if (itemType == "wxChoice") |
1098 | { | |
5de76427 | 1099 | prefix = "ID_CHOICE"; |
457814b5 JS |
1100 | MakeUniqueName("choice", buf); |
1101 | res->SetName(buf); | |
1102 | newItem = new wxChoice(panel, -1, wxPoint(x, y), wxSize(-1, -1), 0, NULL, 0, wxDefaultValidator, buf); | |
1103 | } | |
9c331ded JS |
1104 | else if (itemType == "wxComboBox") |
1105 | { | |
1106 | prefix = "ID_COMBOBOX"; | |
1107 | MakeUniqueName("combobox", buf); | |
1108 | res->SetName(buf); | |
1109 | newItem = new wxComboBox(panel, -1, "", wxPoint(x, y), wxSize(-1, -1), 0, NULL, wxCB_DROPDOWN, wxDefaultValidator, buf); | |
1110 | } | |
457814b5 JS |
1111 | else if (itemType == "wxGroupBox" || itemType == "wxStaticBox") |
1112 | { | |
5de76427 | 1113 | prefix = "ID_STATICBOX"; |
9c331ded | 1114 | MakeUniqueName("staticbox", buf); |
457814b5 | 1115 | res->SetName(buf); |
9c331ded | 1116 | newItem = new wxStaticBox(panel, -1, "Static", wxPoint(x, y), wxSize(200, 200), 0, buf); |
457814b5 JS |
1117 | } |
1118 | else if (itemType == "wxGauge") | |
1119 | { | |
5de76427 | 1120 | prefix = "ID_GAUGE"; |
457814b5 JS |
1121 | MakeUniqueName("gauge", buf); |
1122 | res->SetName(buf); | |
1123 | newItem = new wxGauge(panel, -1, 10, wxPoint(x, y), wxSize(80, 30), wxHORIZONTAL, wxDefaultValidator, buf); | |
1124 | } | |
1125 | else if (itemType == "wxSlider") | |
1126 | { | |
5de76427 | 1127 | prefix = "ID_SLIDER"; |
457814b5 JS |
1128 | MakeUniqueName("slider", buf); |
1129 | res->SetName(buf); | |
1130 | newItem = new wxSlider(panel, -1, 1, 1, 10, wxPoint(x, y), wxSize(120, -1), wxHORIZONTAL, wxDefaultValidator, buf); | |
1131 | } | |
ae8351fc | 1132 | else if (itemType == "wxText" || itemType == "wxTextCtrl (single-line)") |
457814b5 | 1133 | { |
5de76427 | 1134 | prefix = "ID_TEXTCTRL"; |
ae8351fc | 1135 | MakeUniqueName("textctrl", buf); |
457814b5 | 1136 | res->SetName(buf); |
ae8351fc | 1137 | res->SetType("wxTextCtrl"); |
457814b5 JS |
1138 | newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, -1), 0, wxDefaultValidator, buf); |
1139 | } | |
ae8351fc | 1140 | else if (itemType == "wxMultiText" || itemType == "wxTextCtrl (multi-line)") |
457814b5 | 1141 | { |
5de76427 | 1142 | prefix = "ID_TEXTCTRL"; |
ae8351fc | 1143 | MakeUniqueName("textctrl", buf); |
457814b5 | 1144 | res->SetName(buf); |
ae8351fc JS |
1145 | res->SetType("wxTextCtrl"); |
1146 | newItem = new wxTextCtrl(panel, -1, "", wxPoint(x, y), wxSize(120, 100), wxTE_MULTILINE, wxDefaultValidator, buf); | |
457814b5 | 1147 | } |
457814b5 JS |
1148 | else if (itemType == "wxScrollBar") |
1149 | { | |
5de76427 | 1150 | prefix = "ID_SCROLLBAR"; |
457814b5 JS |
1151 | MakeUniqueName("scrollbar", buf); |
1152 | res->SetName(buf); | |
1153 | newItem = new wxScrollBar(panel, -1, wxPoint(x, y), wxSize(140, -1), wxHORIZONTAL, wxDefaultValidator, buf); | |
1154 | } | |
1155 | if (!newItem) | |
1156 | return FALSE; | |
1157 | ||
386af6a2 JS |
1158 | int actualW, actualH; |
1159 | newItem->GetSize(&actualW, &actualH); | |
1160 | wxSize actualSize(actualW, actualH); | |
1161 | ||
1162 | if ((panelResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) | |
1163 | { | |
1164 | actualSize = panel->ConvertPixelsToDialog(actualSize); | |
1165 | } | |
1166 | res->SetSize(res->GetX(), res->GetY(), actualSize.x, actualSize.y); | |
1167 | ||
5de76427 JS |
1168 | wxString newIdName; |
1169 | int id = GenerateWindowId(prefix, newIdName); | |
1170 | res->SetId(id); | |
1171 | ||
1172 | // This is now guaranteed to be unique, so just add to symbol table | |
1173 | m_symbolTable.AddSymbol(newIdName, id); | |
1174 | ||
457814b5 JS |
1175 | newItem->PushEventHandler(new wxResourceEditorControlHandler(newItem, newItem)); |
1176 | ||
1177 | res->SetStyle(newItem->GetWindowStyleFlag()); | |
1178 | AssociateResource(res, newItem); | |
1179 | panelResource->GetChildren().Append(res); | |
1180 | ||
1181 | UpdateResourceList(); | |
1182 | ||
1183 | return TRUE; | |
1184 | } | |
1185 | ||
ae8351fc JS |
1186 | void wxResourceManager::ClearCurrentDialog() |
1187 | { | |
1188 | if (m_editorPanel->m_childWindow) | |
1189 | { | |
1190 | SaveInfoAndDeleteHandler(m_editorPanel->m_childWindow); | |
1191 | DisassociateResource(m_editorPanel->m_childWindow); | |
1192 | DeleteWindow(m_editorPanel->m_childWindow); | |
1193 | m_editorPanel->m_childWindow = NULL; | |
1194 | m_editorPanel->Clear(); | |
1195 | } | |
1196 | } | |
1197 | ||
03f68f12 JS |
1198 | bool wxResourceManager::TestCurrentDialog(wxWindow* parent) |
1199 | { | |
1200 | if (m_editorPanel->m_childWindow) | |
1201 | { | |
1202 | wxItemResource* item = FindResourceForWindow(m_editorPanel->m_childWindow); | |
1203 | if (!item) | |
1204 | return FALSE; | |
1205 | ||
1206 | // Make sure the resources are up-to-date w.r.t. the window | |
1207 | InstantiateResourceFromWindow(item, m_editorPanel->m_childWindow, TRUE); | |
1208 | ||
1209 | wxDialog* dialog = new wxDialog; | |
03f68f12 | 1210 | bool success = FALSE; |
03f68f12 JS |
1211 | if (dialog->LoadFromResource(parent, item->GetName(), & m_resourceTable)) |
1212 | { | |
1213 | dialog->Centre(); | |
1214 | dialog->ShowModal(); | |
1215 | success = TRUE; | |
1216 | } | |
03f68f12 JS |
1217 | return success; |
1218 | } | |
1219 | return FALSE; | |
1220 | } | |
1221 | ||
457814b5 JS |
1222 | // Find the first dialog or panel for which |
1223 | // there is a selected panel item. | |
ae8351fc | 1224 | wxWindow *wxResourceManager::FindParentOfSelection() |
457814b5 | 1225 | { |
ae8351fc | 1226 | m_resourceTable.BeginFind(); |
457814b5 | 1227 | wxNode *node; |
fd71308f | 1228 | while ((node = m_resourceTable.Next())) |
457814b5 JS |
1229 | { |
1230 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1231 | wxWindow *win = FindWindowForResource(res); | |
1232 | if (win) | |
1233 | { | |
1234 | wxNode *node1 = win->GetChildren()->First(); | |
1235 | while (node1) | |
1236 | { | |
1237 | wxControl *item = (wxControl *)node1->Data(); | |
1238 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
1239 | if (item->IsKindOf(CLASSINFO(wxControl)) && childHandler->IsSelected()) | |
1240 | return win; | |
1241 | node1 = node1->Next(); | |
1242 | } | |
1243 | } | |
1244 | } | |
1245 | return NULL; | |
1246 | } | |
1247 | ||
1248 | // Format the panel items according to 'flag' | |
1249 | void wxResourceManager::AlignItems(int flag) | |
1250 | { | |
1251 | wxWindow *win = FindParentOfSelection(); | |
1252 | if (!win) | |
1253 | return; | |
1254 | ||
1255 | wxNode *node = GetSelections().First(); | |
1256 | if (!node) | |
1257 | return; | |
1258 | ||
1259 | wxControl *firstSelection = (wxControl *)node->Data(); | |
1260 | if (firstSelection->GetParent() != win) | |
1261 | return; | |
1262 | ||
1263 | int firstX, firstY; | |
1264 | int firstW, firstH; | |
1265 | firstSelection->GetPosition(&firstX, &firstY); | |
1266 | firstSelection->GetSize(&firstW, &firstH); | |
1267 | int centreX = (int)(firstX + (firstW / 2)); | |
1268 | int centreY = (int)(firstY + (firstH / 2)); | |
1269 | ||
fd71308f | 1270 | while ((node = node->Next())) |
457814b5 JS |
1271 | { |
1272 | wxControl *item = (wxControl *)node->Data(); | |
1273 | if (item->GetParent() == win) | |
1274 | { | |
1275 | int x, y, w, h; | |
1276 | item->GetPosition(&x, &y); | |
1277 | item->GetSize(&w, &h); | |
1278 | ||
1279 | int newX, newY; | |
1280 | ||
1281 | switch (flag) | |
1282 | { | |
1283 | case TOOLBAR_FORMAT_HORIZ: | |
1284 | { | |
1285 | newX = x; | |
1286 | newY = (int)(centreY - (h/2.0)); | |
1287 | break; | |
1288 | } | |
1289 | case TOOLBAR_FORMAT_VERT: | |
1290 | { | |
1291 | newX = (int)(centreX - (w/2.0)); | |
1292 | newY = y; | |
1293 | break; | |
1294 | } | |
1295 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: | |
1296 | { | |
1297 | newX = firstX; | |
1298 | newY = y; | |
1299 | break; | |
1300 | } | |
1301 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: | |
1302 | { | |
1303 | newX = x; | |
1304 | newY = firstY; | |
1305 | break; | |
1306 | } | |
1307 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: | |
1308 | { | |
1309 | newX = firstX + firstW - w; | |
1310 | newY = y; | |
1311 | break; | |
1312 | } | |
1313 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: | |
1314 | { | |
1315 | newX = x; | |
1316 | newY = firstY + firstH - h; | |
1317 | break; | |
1318 | } | |
1319 | default: | |
1320 | newX = x; newY = y; | |
1321 | break; | |
1322 | } | |
1323 | ||
1324 | item->SetSize(newX, newY, w, h); | |
1325 | } | |
1326 | } | |
1327 | win->Refresh(); | |
1328 | } | |
1329 | ||
1330 | // Copy the first image's size to subsequent images | |
ae8351fc | 1331 | void wxResourceManager::CopySize() |
457814b5 JS |
1332 | { |
1333 | wxWindow *win = FindParentOfSelection(); | |
1334 | if (!win) | |
1335 | return; | |
1336 | ||
1337 | wxNode *node = GetSelections().First(); | |
1338 | if (!node) | |
1339 | return; | |
1340 | ||
1341 | wxControl *firstSelection = (wxControl *)node->Data(); | |
1342 | if (firstSelection->GetParent() != win) | |
1343 | return; | |
1344 | ||
1345 | int firstX, firstY; | |
1346 | int firstW, firstH; | |
1347 | firstSelection->GetPosition(&firstX, &firstY); | |
1348 | firstSelection->GetSize(&firstW, &firstH); | |
457814b5 | 1349 | |
fd71308f | 1350 | while ((node = node->Next())) |
457814b5 JS |
1351 | { |
1352 | wxControl *item = (wxControl *)node->Data(); | |
1353 | if (item->GetParent() == win) | |
1354 | item->SetSize(-1, -1, firstW, firstH); | |
1355 | } | |
1356 | win->Refresh(); | |
1357 | } | |
1358 | ||
1359 | void wxResourceManager::ToBackOrFront(bool toBack) | |
1360 | { | |
1361 | wxWindow *win = FindParentOfSelection(); | |
1362 | if (!win) | |
1363 | return; | |
1364 | wxItemResource *winResource = FindResourceForWindow(win); | |
1365 | ||
1366 | wxNode *node = GetSelections().First(); | |
1367 | while (node) | |
1368 | { | |
1369 | wxControl *item = (wxControl *)node->Data(); | |
1370 | wxItemResource *itemResource = FindResourceForWindow(item); | |
1371 | if (item->GetParent() == win) | |
1372 | { | |
1373 | win->GetChildren()->DeleteObject(item); | |
1374 | if (winResource) | |
1375 | winResource->GetChildren().DeleteObject(itemResource); | |
1376 | if (toBack) | |
1377 | { | |
1378 | win->GetChildren()->Insert(item); | |
1379 | if (winResource) | |
1380 | winResource->GetChildren().Insert(itemResource); | |
1381 | } | |
1382 | else | |
1383 | { | |
1384 | win->GetChildren()->Append(item); | |
1385 | if (winResource) | |
1386 | winResource->GetChildren().Append(itemResource); | |
1387 | } | |
1388 | } | |
1389 | node = node->Next(); | |
1390 | } | |
1391 | // win->Refresh(); | |
1392 | } | |
1393 | ||
1394 | void wxResourceManager::AddSelection(wxWindow *win) | |
1395 | { | |
ae8351fc JS |
1396 | if (!m_selections.Member(win)) |
1397 | m_selections.Append(win); | |
457814b5 JS |
1398 | } |
1399 | ||
1400 | void wxResourceManager::RemoveSelection(wxWindow *win) | |
1401 | { | |
ae8351fc | 1402 | m_selections.DeleteObject(win); |
457814b5 JS |
1403 | } |
1404 | ||
1405 | // Need to search through resource table removing this from | |
1406 | // any resource which has this as a parent. | |
1407 | bool wxResourceManager::RemoveResourceFromParent(wxItemResource *res) | |
1408 | { | |
ae8351fc | 1409 | m_resourceTable.BeginFind(); |
457814b5 | 1410 | wxNode *node; |
fd71308f | 1411 | while ((node = m_resourceTable.Next())) |
457814b5 JS |
1412 | { |
1413 | wxItemResource *thisRes = (wxItemResource *)node->Data(); | |
1414 | if (thisRes->GetChildren().Member(res)) | |
1415 | { | |
1416 | thisRes->GetChildren().DeleteObject(res); | |
1417 | return TRUE; | |
1418 | } | |
1419 | } | |
1420 | return FALSE; | |
1421 | } | |
1422 | ||
1423 | bool wxResourceManager::DeleteResource(wxItemResource *res) | |
1424 | { | |
1425 | if (!res) | |
1426 | return FALSE; | |
1427 | ||
1428 | RemoveResourceFromParent(res); | |
1429 | ||
1430 | wxNode *node = res->GetChildren().First(); | |
1431 | while (node) | |
1432 | { | |
1433 | wxNode *next = node->Next(); | |
1434 | wxItemResource *child = (wxItemResource *)node->Data(); | |
1435 | DeleteResource(child); | |
1436 | node = next; | |
1437 | } | |
1438 | ||
1439 | // If this is a button or message resource, delete the | |
1440 | // associate bitmap resource if not being used. | |
1441 | wxString resType(res->GetType()); | |
fd71308f JS |
1442 | |
1443 | /* shouldn't have to do this now bitmaps are ref-counted | |
ae8351fc | 1444 | if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4()) |
457814b5 JS |
1445 | { |
1446 | PossiblyDeleteBitmapResource(res->GetValue4()); | |
1447 | } | |
fd71308f | 1448 | */ |
457814b5 | 1449 | |
5de76427 JS |
1450 | // Remove symbol from table if appropriate |
1451 | if (!IsSymbolUsed(res, res->GetId())) | |
1452 | { | |
1453 | m_symbolTable.RemoveSymbol(res->GetId()); | |
1454 | } | |
1455 | ||
ae8351fc | 1456 | m_resourceTable.Delete(res->GetName()); |
457814b5 JS |
1457 | delete res; |
1458 | Modify(TRUE); | |
1459 | return TRUE; | |
1460 | } | |
1461 | ||
ae8351fc | 1462 | bool wxResourceManager::DeleteResource(wxWindow *win) |
457814b5 JS |
1463 | { |
1464 | if (win->IsKindOf(CLASSINFO(wxControl))) | |
1465 | { | |
1466 | // Deselect and refresh window in case we leave selection | |
1467 | // handles behind | |
1468 | wxControl *item = (wxControl *)win; | |
1469 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
1470 | if (childHandler->IsSelected()) | |
1471 | { | |
1472 | RemoveSelection(item); | |
1473 | childHandler->SelectItem(FALSE); | |
c058d771 | 1474 | #ifndef __WXGTK__ |
457814b5 | 1475 | item->GetParent()->Refresh(); |
c058d771 | 1476 | #endif |
457814b5 JS |
1477 | } |
1478 | } | |
1479 | ||
1480 | wxItemResource *res = FindResourceForWindow(win); | |
1481 | ||
ae8351fc | 1482 | DisassociateResource(res); |
457814b5 JS |
1483 | DeleteResource(res); |
1484 | UpdateResourceList(); | |
1485 | ||
457814b5 JS |
1486 | return TRUE; |
1487 | } | |
1488 | ||
1489 | // Will eventually have bitmap type information, for different | |
1490 | // kinds of bitmap. | |
fd71308f | 1491 | wxString wxResourceManager::AddBitmapResource(const wxString& filename) |
457814b5 JS |
1492 | { |
1493 | wxItemResource *resource = FindBitmapResourceByFilename(filename); | |
1494 | if (!resource) | |
1495 | { | |
1496 | char buf[256]; | |
1497 | MakeUniqueName("bitmap", buf); | |
1498 | resource = new wxItemResource; | |
1499 | resource->SetType("wxBitmap"); | |
1500 | resource->SetName(buf); | |
1501 | ||
1502 | // A bitmap resource has one or more children, specifying | |
1503 | // alternative bitmaps. | |
1504 | wxItemResource *child = new wxItemResource; | |
1505 | child->SetType("wxBitmap"); | |
1506 | child->SetName(filename); | |
1507 | child->SetValue1(wxBITMAP_TYPE_BMP); | |
1508 | child->SetValue2(RESOURCE_PLATFORM_ANY); | |
1509 | child->SetValue3(0); // Depth | |
1510 | child->SetSize(0,0,0,0); | |
1511 | resource->GetChildren().Append(child); | |
1512 | ||
ae8351fc | 1513 | m_resourceTable.AddResource(resource); |
457814b5 JS |
1514 | |
1515 | UpdateResourceList(); | |
1516 | } | |
1517 | if (resource) | |
1518 | return resource->GetName(); | |
1519 | else | |
fd71308f | 1520 | return wxEmptyString; |
457814b5 JS |
1521 | } |
1522 | ||
1523 | // Delete the bitmap resource if it isn't being used by another resource. | |
fd71308f | 1524 | void wxResourceManager::PossiblyDeleteBitmapResource(const wxString& resourceName) |
457814b5 JS |
1525 | { |
1526 | if (!IsBitmapResourceUsed(resourceName)) | |
1527 | { | |
ae8351fc | 1528 | wxItemResource *res = m_resourceTable.FindResource(resourceName); |
457814b5 JS |
1529 | DeleteResource(res); |
1530 | UpdateResourceList(); | |
1531 | } | |
1532 | } | |
1533 | ||
fd71308f | 1534 | bool wxResourceManager::IsBitmapResourceUsed(const wxString& resourceName) |
457814b5 | 1535 | { |
ae8351fc | 1536 | m_resourceTable.BeginFind(); |
457814b5 | 1537 | wxNode *node; |
fd71308f | 1538 | while ((node = m_resourceTable.Next())) |
457814b5 JS |
1539 | { |
1540 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1541 | wxString resType(res->GetType()); | |
1542 | if (resType == "wxDialog") | |
1543 | { | |
1544 | wxNode *node1 = res->GetChildren().First(); | |
1545 | while (node1) | |
1546 | { | |
1547 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1548 | wxString childResType(child->GetType()); | |
1549 | ||
1550 | if ((childResType == "wxMessage" || childResType == "wxButton") && | |
1551 | child->GetValue4() && | |
1552 | (strcmp(child->GetValue4(), resourceName) == 0)) | |
1553 | return TRUE; | |
1554 | node1 = node1->Next(); | |
1555 | } | |
1556 | } | |
1557 | } | |
1558 | return FALSE; | |
1559 | } | |
1560 | ||
1561 | // Given a wxButton or wxMessage, find the corresponding bitmap filename. | |
fd71308f | 1562 | wxString wxResourceManager::FindBitmapFilenameForResource(wxItemResource *resource) |
457814b5 | 1563 | { |
fd71308f JS |
1564 | if (!resource || (resource->GetValue4() == "")) |
1565 | return wxEmptyString; | |
ae8351fc | 1566 | wxItemResource *bitmapResource = m_resourceTable.FindResource(resource->GetValue4()); |
457814b5 | 1567 | if (!bitmapResource) |
fd71308f | 1568 | return wxEmptyString; |
457814b5 JS |
1569 | |
1570 | wxNode *node = bitmapResource->GetChildren().First(); | |
1571 | while (node) | |
1572 | { | |
1573 | // Eventually augment this to return a bitmap of the right kind or something... | |
1574 | // Maybe the root of the filename remains the same, so it doesn't matter which we | |
1575 | // pick up. Otherwise how do we specify multiple filenames... too boring... | |
1576 | wxItemResource *child = (wxItemResource *)node->Data(); | |
1577 | return child->GetName(); | |
1578 | ||
1579 | node = node->Next(); | |
1580 | } | |
fd71308f | 1581 | return wxEmptyString; |
457814b5 JS |
1582 | } |
1583 | ||
fd71308f | 1584 | wxItemResource *wxResourceManager::FindBitmapResourceByFilename(const wxString& filename) |
457814b5 | 1585 | { |
ae8351fc | 1586 | m_resourceTable.BeginFind(); |
457814b5 | 1587 | wxNode *node; |
fd71308f | 1588 | while ((node = m_resourceTable.Next())) |
457814b5 JS |
1589 | { |
1590 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1591 | wxString resType(res->GetType()); | |
1592 | if (resType == "wxBitmap") | |
1593 | { | |
1594 | wxNode *node1 = res->GetChildren().First(); | |
1595 | while (node1) | |
1596 | { | |
1597 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1598 | if (child->GetName() && (strcmp(child->GetName(), filename) == 0)) | |
1599 | return res; | |
1600 | node1 = node1->Next(); | |
1601 | } | |
1602 | } | |
1603 | } | |
1604 | return NULL; | |
1605 | } | |
1606 | ||
5de76427 JS |
1607 | // Is this window identifier symbol in use? |
1608 | // Let's assume that we can't have 2 names for the same integer id. | |
1609 | // Therefore we can tell by the integer id whether the symbol is | |
1610 | // in use. | |
1611 | bool wxResourceManager::IsSymbolUsed(wxItemResource* thisResource, wxWindowID id) | |
1612 | { | |
1613 | m_resourceTable.BeginFind(); | |
1614 | wxNode *node; | |
fd71308f | 1615 | while ((node = m_resourceTable.Next())) |
5de76427 JS |
1616 | { |
1617 | wxItemResource *res = (wxItemResource *)node->Data(); | |
5de76427 JS |
1618 | |
1619 | wxString resType(res->GetType()); | |
1620 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
1621 | { | |
bbcdf8bc JS |
1622 | if ((res != thisResource) && (res->GetId() == id)) |
1623 | return TRUE; | |
1624 | ||
5de76427 JS |
1625 | wxNode *node1 = res->GetChildren().First(); |
1626 | while (node1) | |
1627 | { | |
1628 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1629 | if ((child != thisResource) && (child->GetId() == id)) | |
1630 | return TRUE; | |
1631 | node1 = node1->Next(); | |
1632 | } | |
1633 | } | |
1634 | } | |
1635 | return FALSE; | |
1636 | } | |
1637 | ||
1638 | // Is this window identifier compatible with the given name? (i.e. | |
1639 | // does it already exist under a different name) | |
1640 | bool wxResourceManager::IsIdentifierOK(const wxString& name, wxWindowID id) | |
1641 | { | |
1642 | if (m_symbolTable.SymbolExists(name)) | |
1643 | { | |
1644 | int foundId = m_symbolTable.GetIdForSymbol(name); | |
1645 | if (foundId != id) | |
1646 | return FALSE; | |
1647 | } | |
1648 | return TRUE; | |
1649 | } | |
1650 | ||
1651 | // Change all integer ids that match oldId, to newId. | |
1652 | // This is necessary if an id is changed for one resource - all resources | |
1653 | // must be changed. | |
1654 | void wxResourceManager::ChangeIds(int oldId, int newId) | |
1655 | { | |
1656 | m_resourceTable.BeginFind(); | |
1657 | wxNode *node; | |
fd71308f | 1658 | while ((node = m_resourceTable.Next())) |
5de76427 JS |
1659 | { |
1660 | wxItemResource *res = (wxItemResource *)node->Data(); | |
5de76427 JS |
1661 | |
1662 | wxString resType(res->GetType()); | |
1663 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
1664 | { | |
bbcdf8bc JS |
1665 | if (res->GetId() == oldId) |
1666 | res->SetId(newId); | |
1667 | ||
5de76427 JS |
1668 | wxNode *node1 = res->GetChildren().First(); |
1669 | while (node1) | |
1670 | { | |
1671 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1672 | if (child->GetId() == oldId) | |
1673 | child->SetId(newId); | |
1674 | ||
1675 | node1 = node1->Next(); | |
1676 | } | |
1677 | } | |
1678 | } | |
1679 | } | |
1680 | ||
bbcdf8bc JS |
1681 | // If any resource ids were missing (or their symbol was missing), |
1682 | // repair them i.e. give them new ids. Returns TRUE if any resource | |
1683 | // needed repairing. | |
1684 | bool wxResourceManager::RepairResourceIds() | |
1685 | { | |
1686 | bool repaired = FALSE; | |
1687 | ||
1688 | m_resourceTable.BeginFind(); | |
1689 | wxNode *node; | |
fd71308f | 1690 | while ((node = m_resourceTable.Next())) |
bbcdf8bc JS |
1691 | { |
1692 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1693 | wxString resType(res->GetType()); | |
1694 | if (resType == "wxDialog" || resType == "wxDialogBox" || resType == "wxPanel") | |
1695 | { | |
1696 | ||
1697 | if ( (res->GetId() == 0) || ((res->GetId() > 0) && !m_symbolTable.IdExists(res->GetId())) ) | |
1698 | { | |
1699 | wxString newSymbolName; | |
1700 | int newId = GenerateWindowId("ID_DIALOG", newSymbolName) ; | |
1701 | ||
1702 | if (res->GetId() == 0) | |
1703 | { | |
1704 | res->SetId(newId); | |
1705 | m_symbolTable.AddSymbol(newSymbolName, newId); | |
1706 | } | |
1707 | else | |
1708 | { | |
1709 | m_symbolTable.AddSymbol(newSymbolName, res->GetId()); | |
1710 | } | |
1711 | ||
1712 | repaired = TRUE; | |
1713 | } | |
1714 | ||
1715 | wxNode *node1 = res->GetChildren().First(); | |
1716 | while (node1) | |
1717 | { | |
1718 | wxItemResource *child = (wxItemResource *)node1->Data(); | |
1719 | ||
1720 | if ( (child->GetId() == 0) || ((child->GetId() > 0) && !m_symbolTable.IdExists(child->GetId())) ) | |
1721 | { | |
1722 | wxString newSymbolName; | |
1723 | int newId = GenerateWindowId("ID_CONTROL", newSymbolName) ; | |
1724 | ||
1725 | if (child->GetId() == 0) | |
1726 | { | |
1727 | child->SetId(newId); | |
1728 | m_symbolTable.AddSymbol(newSymbolName, newId); | |
1729 | } | |
1730 | else | |
1731 | { | |
1732 | m_symbolTable.AddSymbol(newSymbolName, child->GetId()); | |
1733 | } | |
1734 | ||
1735 | repaired = TRUE; | |
1736 | } | |
1737 | ||
1738 | node1 = node1->Next(); | |
1739 | } | |
1740 | } | |
1741 | } | |
1742 | return repaired; | |
1743 | } | |
1744 | ||
1745 | ||
457814b5 JS |
1746 | // Deletes 'win' and creates a new window from the resource that |
1747 | // was associated with it. E.g. if you can't change properties on the | |
1748 | // fly, you'll need to delete the window and create it again. | |
1749 | wxWindow *wxResourceManager::RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info) | |
1750 | { | |
1751 | wxItemResource *resource = FindResourceForWindow(win); | |
1752 | ||
1753 | // Put the current window properties into the wxItemResource object | |
1754 | ||
1755 | wxWindowPropertyInfo *newInfo = NULL; | |
1756 | if (!info) | |
1757 | { | |
ae8351fc | 1758 | newInfo = CreatePropertyInfoForWindow(win); |
457814b5 JS |
1759 | info = newInfo; |
1760 | } | |
1761 | ||
1762 | info->InstantiateResource(resource); | |
1763 | ||
1764 | wxWindow *newWin = NULL; | |
1765 | wxWindow *parent = win->GetParent(); | |
fd71308f JS |
1766 | wxItemResource* parentResource = NULL; |
1767 | if (parent) | |
386af6a2 | 1768 | parentResource = FindResourceForWindow(parent); |
457814b5 JS |
1769 | |
1770 | if (win->IsKindOf(CLASSINFO(wxPanel))) | |
1771 | { | |
457814b5 JS |
1772 | Edit(resource); |
1773 | newWin = FindWindowForResource(resource); | |
1774 | } | |
1775 | else | |
1776 | { | |
ae8351fc | 1777 | DisassociateResource(resource); |
9c331ded JS |
1778 | if (win->GetEventHandler() != win) |
1779 | win->PopEventHandler(TRUE); | |
1780 | ||
ae8351fc | 1781 | DeleteWindow(win); |
fd71308f | 1782 | newWin = m_resourceTable.CreateItem((wxPanel *)parent, resource, parentResource); |
9c331ded | 1783 | newWin->PushEventHandler(new wxResourceEditorControlHandler((wxControl*) newWin, (wxControl*) newWin)); |
457814b5 JS |
1784 | AssociateResource(resource, newWin); |
1785 | UpdateResourceList(); | |
1786 | } | |
1787 | ||
1788 | if (info) | |
1789 | info->SetPropertyWindow(newWin); | |
1790 | ||
1791 | if (newInfo) | |
1792 | delete newInfo; | |
1793 | ||
1794 | return newWin; | |
1795 | } | |
1796 | ||
1797 | // Delete resource highlighted in the listbox | |
ae8351fc | 1798 | bool wxResourceManager::DeleteSelection() |
457814b5 | 1799 | { |
ae8351fc | 1800 | int sel = m_editorResourceTree->GetSelection(); |
03f68f12 | 1801 | if (sel != 0) |
457814b5 | 1802 | { |
1195ec42 VZ |
1803 | wxResourceTreeData *data = (wxResourceTreeData *)m_editorResourceTree->GetItemData(sel); |
1804 | wxItemResource *res = data->GetResource(); | |
457814b5 | 1805 | wxWindow *win = FindWindowForResource(res); |
ae8351fc | 1806 | if (win) |
457814b5 | 1807 | { |
ae8351fc JS |
1808 | DeleteResource(win); |
1809 | DeleteWindow(win); | |
1810 | UpdateResourceList(); | |
1811 | Modify(TRUE); | |
457814b5 | 1812 | } |
ae8351fc | 1813 | return TRUE; |
457814b5 JS |
1814 | } |
1815 | ||
1816 | return FALSE; | |
1817 | } | |
1818 | ||
1819 | // Delete resource highlighted in the listbox | |
ae8351fc | 1820 | bool wxResourceManager::RecreateSelection() |
457814b5 JS |
1821 | { |
1822 | wxNode *node = GetSelections().First(); | |
1823 | while (node) | |
1824 | { | |
1825 | wxControl *item = (wxControl *)node->Data(); | |
1826 | wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); | |
1827 | wxNode *next = node->Next(); | |
1828 | childHandler->SelectItem(FALSE); | |
1829 | ||
1830 | RemoveSelection(item); | |
1831 | ||
1832 | RecreateWindowFromResource(item); | |
1833 | ||
1834 | node = next; | |
1835 | } | |
1836 | return TRUE; | |
1837 | } | |
1838 | ||
fd71308f | 1839 | bool wxResourceManager::EditDialog(wxDialog *WXUNUSED(dialog), wxWindow *WXUNUSED(parent)) |
457814b5 JS |
1840 | { |
1841 | return FALSE; | |
1842 | } | |
1843 | ||
457814b5 JS |
1844 | // Ensures that all currently shown windows are saved to resources, |
1845 | // e.g. just before writing to a .wxr file. | |
ae8351fc | 1846 | bool wxResourceManager::InstantiateAllResourcesFromWindows() |
457814b5 | 1847 | { |
ae8351fc | 1848 | m_resourceTable.BeginFind(); |
457814b5 | 1849 | wxNode *node; |
fd71308f | 1850 | while ((node = m_resourceTable.Next())) |
457814b5 JS |
1851 | { |
1852 | wxItemResource *res = (wxItemResource *)node->Data(); | |
1853 | wxString resType(res->GetType()); | |
1854 | ||
1855 | if (resType == "wxDialog") | |
1856 | { | |
1857 | wxWindow *win = (wxWindow *)FindWindowForResource(res); | |
1858 | if (win) | |
1859 | InstantiateResourceFromWindow(res, win, TRUE); | |
1860 | } | |
1861 | else if (resType == "wxPanel") | |
1862 | { | |
1863 | wxWindow *win = (wxWindow *)FindWindowForResource(res); | |
1864 | if (win) | |
1865 | InstantiateResourceFromWindow(res, win, TRUE); | |
1866 | } | |
1867 | } | |
1868 | return TRUE; | |
1869 | } | |
1870 | ||
1871 | bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse) | |
1872 | { | |
ae8351fc | 1873 | wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(window); |
457814b5 JS |
1874 | info->SetResource(resource); |
1875 | info->InstantiateResource(resource); | |
1876 | delete info; | |
1877 | ||
1878 | if (recurse) | |
1879 | { | |
1880 | wxNode *node = resource->GetChildren().First(); | |
1881 | while (node) | |
1882 | { | |
1883 | wxItemResource *child = (wxItemResource *)node->Data(); | |
1884 | wxWindow *childWindow = FindWindowForResource(child); | |
1885 | ||
1886 | if (!childWindow) | |
1887 | { | |
1888 | char buf[200]; | |
fd71308f | 1889 | sprintf(buf, "Could not find window %s", (const char*) child->GetName()); |
457814b5 JS |
1890 | wxMessageBox(buf, "Dialog Editor problem", wxOK); |
1891 | } | |
1892 | else | |
1893 | InstantiateResourceFromWindow(child, childWindow, recurse); | |
1894 | node = node->Next(); | |
1895 | } | |
1896 | } | |
1897 | ||
1898 | return TRUE; | |
1899 | } | |
1900 | ||
ae8351fc JS |
1901 | // Create a window information object for the give window |
1902 | wxWindowPropertyInfo *wxResourceManager::CreatePropertyInfoForWindow(wxWindow *win) | |
1903 | { | |
1904 | wxWindowPropertyInfo *info = NULL; | |
1905 | if (win->IsKindOf(CLASSINFO(wxScrollBar))) | |
1906 | { | |
1907 | info = new wxScrollBarPropertyInfo(win); | |
1908 | } | |
1909 | else if (win->IsKindOf(CLASSINFO(wxStaticBox))) | |
1910 | { | |
1911 | info = new wxGroupBoxPropertyInfo(win); | |
1912 | } | |
1913 | else if (win->IsKindOf(CLASSINFO(wxCheckBox))) | |
1914 | { | |
1915 | info = new wxCheckBoxPropertyInfo(win); | |
1916 | } | |
1917 | else if (win->IsKindOf(CLASSINFO(wxSlider))) | |
1918 | { | |
1919 | info = new wxSliderPropertyInfo(win); | |
1920 | } | |
1921 | else if (win->IsKindOf(CLASSINFO(wxGauge))) | |
1922 | { | |
1923 | info = new wxGaugePropertyInfo(win); | |
1924 | } | |
1925 | else if (win->IsKindOf(CLASSINFO(wxListBox))) | |
1926 | { | |
1927 | info = new wxListBoxPropertyInfo(win); | |
1928 | } | |
1929 | else if (win->IsKindOf(CLASSINFO(wxRadioBox))) | |
1930 | { | |
1931 | info = new wxRadioBoxPropertyInfo(win); | |
1932 | } | |
03f68f12 JS |
1933 | else if (win->IsKindOf(CLASSINFO(wxRadioButton))) |
1934 | { | |
1935 | info = new wxRadioButtonPropertyInfo(win); | |
1936 | } | |
ae8351fc JS |
1937 | else if (win->IsKindOf(CLASSINFO(wxChoice))) |
1938 | { | |
1939 | info = new wxChoicePropertyInfo(win); | |
1940 | } | |
9c331ded JS |
1941 | else if (win->IsKindOf(CLASSINFO(wxComboBox))) |
1942 | { | |
1943 | info = new wxComboBoxPropertyInfo(win); | |
1944 | } | |
ae8351fc JS |
1945 | else if (win->IsKindOf(CLASSINFO(wxButton))) |
1946 | { | |
1947 | info = new wxButtonPropertyInfo(win); | |
1948 | } | |
1949 | else if (win->IsKindOf(CLASSINFO(wxBitmapButton))) | |
1950 | { | |
1951 | info = new wxBitmapButtonPropertyInfo(win); | |
1952 | } | |
1953 | else if (win->IsKindOf(CLASSINFO(wxStaticText))) | |
1954 | { | |
1955 | info = new wxStaticTextPropertyInfo(win); | |
1956 | } | |
1957 | else if (win->IsKindOf(CLASSINFO(wxStaticBitmap))) | |
1958 | { | |
1959 | info = new wxStaticBitmapPropertyInfo(win); | |
1960 | } | |
1961 | else if (win->IsKindOf(CLASSINFO(wxTextCtrl))) | |
1962 | { | |
1963 | info = new wxTextPropertyInfo(win); | |
1964 | } | |
1965 | else if (win->IsKindOf(CLASSINFO(wxPanel))) | |
1966 | { | |
1967 | info = new wxPanelPropertyInfo(win); | |
1968 | } | |
1969 | else | |
1970 | { | |
1971 | info = new wxWindowPropertyInfo(win); | |
1972 | } | |
1973 | return info; | |
1974 | } | |
1975 | ||
1976 | // Edit the given window | |
1977 | void wxResourceManager::EditWindow(wxWindow *win) | |
1978 | { | |
1979 | wxWindowPropertyInfo *info = CreatePropertyInfoForWindow(win); | |
1980 | if (info) | |
1981 | { | |
1982 | info->SetResource(FindResourceForWindow(win)); | |
1983 | wxString str("Editing "); | |
1984 | str += win->GetClassInfo()->GetClassName(); | |
1985 | str += ": "; | |
1986 | if (win->GetName() != "") | |
1987 | str += win->GetName(); | |
1988 | else | |
1989 | str += "properties"; | |
1990 | info->Edit(NULL, str); | |
1991 | } | |
1992 | } | |
1993 | ||
5de76427 JS |
1994 | // Generate a window id and a first stab at a name |
1995 | int wxResourceManager::GenerateWindowId(const wxString& prefix, wxString& idName) | |
1996 | { | |
1997 | m_symbolIdCounter ++; | |
1998 | while (m_symbolTable.IdExists(m_symbolIdCounter)) | |
1999 | m_symbolIdCounter ++; | |
2000 | ||
2001 | int nameId = m_symbolIdCounter; | |
2002 | ||
2003 | wxString str; | |
2004 | str.Printf("%d", nameId); | |
2005 | idName = prefix + str; | |
2006 | ||
2007 | while (m_symbolTable.SymbolExists(idName)) | |
2008 | { | |
2009 | nameId ++; | |
2010 | str.Printf("%d", nameId); | |
2011 | idName = prefix + str; | |
2012 | } | |
2013 | ||
2014 | return m_symbolIdCounter; | |
2015 | } | |
2016 | ||
457814b5 JS |
2017 | |
2018 | /* | |
2019 | * Resource editor frame | |
2020 | */ | |
ae8351fc JS |
2021 | |
2022 | IMPLEMENT_CLASS(wxResourceEditorFrame, wxFrame) | |
2023 | ||
2024 | BEGIN_EVENT_TABLE(wxResourceEditorFrame, wxFrame) | |
2025 | EVT_MENU(wxID_NEW, wxResourceEditorFrame::OnNew) | |
2026 | EVT_MENU(RESED_NEW_DIALOG, wxResourceEditorFrame::OnNewDialog) | |
2027 | EVT_MENU(wxID_OPEN, wxResourceEditorFrame::OnOpen) | |
2028 | EVT_MENU(RESED_CLEAR, wxResourceEditorFrame::OnClear) | |
2029 | EVT_MENU(wxID_SAVE, wxResourceEditorFrame::OnSave) | |
2030 | EVT_MENU(wxID_SAVEAS, wxResourceEditorFrame::OnSaveAs) | |
2031 | EVT_MENU(wxID_EXIT, wxResourceEditorFrame::OnExit) | |
2032 | EVT_MENU(wxID_ABOUT, wxResourceEditorFrame::OnAbout) | |
2033 | EVT_MENU(RESED_CONTENTS, wxResourceEditorFrame::OnContents) | |
2034 | EVT_MENU(RESED_DELETE, wxResourceEditorFrame::OnDeleteSelection) | |
2035 | EVT_MENU(RESED_RECREATE, wxResourceEditorFrame::OnRecreateSelection) | |
2036 | EVT_MENU(RESED_TEST, wxResourceEditorFrame::OnTest) | |
2037 | END_EVENT_TABLE() | |
2038 | ||
2039 | wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title, | |
2040 | const wxPoint& pos, const wxSize& size, long style, const wxString& name): | |
2041 | wxFrame(parent, -1, title, pos, size, style, name) | |
457814b5 JS |
2042 | { |
2043 | manager = resMan; | |
2044 | } | |
2045 | ||
ae8351fc | 2046 | wxResourceEditorFrame::~wxResourceEditorFrame() |
457814b5 JS |
2047 | { |
2048 | } | |
2049 | ||
b127f301 | 2050 | void wxResourceEditorFrame::OnNew(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 2051 | { |
457814b5 | 2052 | manager->New(FALSE); |
ae8351fc JS |
2053 | } |
2054 | ||
b127f301 | 2055 | void wxResourceEditorFrame::OnNewDialog(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2056 | { |
457814b5 | 2057 | manager->CreateNewPanel(); |
ae8351fc JS |
2058 | } |
2059 | ||
b127f301 | 2060 | void wxResourceEditorFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2061 | { |
457814b5 | 2062 | manager->New(TRUE); |
ae8351fc JS |
2063 | } |
2064 | ||
b127f301 | 2065 | void wxResourceEditorFrame::OnClear(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2066 | { |
457814b5 | 2067 | manager->Clear(TRUE, FALSE); |
ae8351fc JS |
2068 | } |
2069 | ||
b127f301 | 2070 | void wxResourceEditorFrame::OnSave(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2071 | { |
457814b5 | 2072 | manager->Save(); |
ae8351fc JS |
2073 | } |
2074 | ||
b127f301 | 2075 | void wxResourceEditorFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2076 | { |
457814b5 | 2077 | manager->SaveAs(); |
ae8351fc JS |
2078 | } |
2079 | ||
b127f301 | 2080 | void wxResourceEditorFrame::OnExit(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2081 | { |
457814b5 JS |
2082 | manager->Clear(TRUE, FALSE) ; |
2083 | this->Close(); | |
ae8351fc JS |
2084 | } |
2085 | ||
b127f301 | 2086 | void wxResourceEditorFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2087 | { |
457814b5 JS |
2088 | char buf[300]; |
2089 | sprintf(buf, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION); | |
ae8351fc JS |
2090 | wxMessageBox(buf, "About Dialog Editor", wxOK|wxCENTRE); |
2091 | } | |
2092 | ||
b127f301 | 2093 | void wxResourceEditorFrame::OnTest(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2094 | { |
03f68f12 | 2095 | manager->TestCurrentDialog(this); |
ae8351fc JS |
2096 | } |
2097 | ||
b127f301 | 2098 | void wxResourceEditorFrame::OnContents(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2099 | { |
d0fff5cb | 2100 | #ifdef __WXMSW__ |
457814b5 | 2101 | wxBeginBusyCursor(); |
ae8351fc JS |
2102 | manager->GetHelpController()->LoadFile(); |
2103 | manager->GetHelpController()->DisplayContents(); | |
457814b5 | 2104 | wxEndBusyCursor(); |
b127f301 | 2105 | #endif |
ae8351fc JS |
2106 | } |
2107 | ||
b127f301 | 2108 | void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2109 | { |
457814b5 | 2110 | manager->DeleteSelection(); |
ae8351fc JS |
2111 | } |
2112 | ||
b127f301 | 2113 | void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent& WXUNUSED(event)) |
ae8351fc | 2114 | { |
457814b5 | 2115 | manager->RecreateSelection(); |
457814b5 JS |
2116 | } |
2117 | ||
ae8351fc | 2118 | bool wxResourceEditorFrame::OnClose() |
457814b5 JS |
2119 | { |
2120 | if (manager->Modified()) | |
2121 | { | |
457814b5 JS |
2122 | if (!manager->Clear(TRUE, FALSE)) |
2123 | return FALSE; | |
2124 | } | |
2125 | ||
2126 | if (!Iconized()) | |
2127 | { | |
2128 | int w, h; | |
2129 | GetSize(&w, &h); | |
ae8351fc JS |
2130 | manager->m_resourceEditorWindowSize.width = w; |
2131 | manager->m_resourceEditorWindowSize.height = h; | |
457814b5 JS |
2132 | |
2133 | int x, y; | |
2134 | GetPosition(&x, &y); | |
2135 | ||
ae8351fc JS |
2136 | manager->m_resourceEditorWindowSize.x = x; |
2137 | manager->m_resourceEditorWindowSize.y = y; | |
457814b5 JS |
2138 | } |
2139 | manager->SetEditorFrame(NULL); | |
2140 | manager->SetEditorToolBar(NULL); | |
457814b5 JS |
2141 | |
2142 | return TRUE; | |
2143 | } | |
2144 | ||
2145 | /* | |
ae8351fc | 2146 | * Resource editor window that contains the dialog/panel being edited |
457814b5 | 2147 | */ |
ae8351fc JS |
2148 | |
2149 | BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow, wxScrolledWindow) | |
2150 | EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll) | |
2151 | EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint) | |
2152 | END_EVENT_TABLE() | |
2153 | ||
2154 | wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow *parent, const wxPoint& pos, const wxSize& size, | |
2155 | long style): | |
2156 | wxScrolledWindow(parent, -1, pos, size, style) | |
457814b5 | 2157 | { |
ae8351fc JS |
2158 | m_marginX = 10; |
2159 | m_marginY = 40; | |
2160 | m_childWindow = NULL; | |
457814b5 JS |
2161 | } |
2162 | ||
ae8351fc | 2163 | wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow() |
457814b5 JS |
2164 | { |
2165 | } | |
2166 | ||
ae8351fc | 2167 | void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent& event) |
457814b5 | 2168 | { |
ae8351fc | 2169 | wxScrolledWindow::OnScroll(event); |
457814b5 | 2170 | |
ae8351fc JS |
2171 | int x, y; |
2172 | ViewStart(& x, & y); | |
2173 | ||
2174 | if (m_childWindow) | |
2175 | m_childWindow->Move(m_marginX + (- x * 10), m_marginY + (- y * 10)); | |
2176 | } | |
2177 | ||
b127f301 | 2178 | void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) |
ae8351fc JS |
2179 | { |
2180 | wxPaintDC dc(this); | |
2181 | ||
2182 | DrawTitle(dc); | |
2183 | } | |
2184 | ||
2185 | void wxResourceEditorScrolledWindow::DrawTitle(wxDC& dc) | |
2186 | { | |
2187 | if (m_childWindow) | |
2188 | { | |
2189 | wxItemResource* res = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow); | |
2190 | if (res) | |
2191 | { | |
2192 | wxString str(res->GetTitle()); | |
2193 | int x, y; | |
2194 | ViewStart(& x, & y); | |
2195 | ||
2196 | wxFont font(10, wxSWISS, wxNORMAL, wxBOLD); | |
2197 | dc.SetFont(font); | |
2198 | dc.SetBackgroundMode(wxTRANSPARENT); | |
2199 | dc.SetTextForeground(wxColour(0, 0, 0)); | |
2200 | ||
2201 | long w, h; | |
2202 | dc.GetTextExtent(str, & w, & h); | |
2203 | ||
2204 | dc.DrawText(str, m_marginX + (- x * 10), m_marginY + (- y * 10) - h - 5); | |
2205 | } | |
2206 | } | |
457814b5 JS |
2207 | } |
2208 | ||
2209 | // Popup menu callback | |
2210 | void ObjectMenuProc(wxMenu& menu, wxCommandEvent& event) | |
2211 | { | |
2212 | wxWindow *data = (wxWindow *)menu.GetClientData(); | |
2213 | if (!data) | |
2214 | return; | |
2215 | ||
2216 | switch (event.GetInt()) | |
2217 | { | |
2218 | case OBJECT_MENU_EDIT: | |
2219 | { | |
ae8351fc | 2220 | wxResourceManager::GetCurrentResourceManager()->EditWindow(data); |
457814b5 JS |
2221 | break; |
2222 | } | |
2223 | case OBJECT_MENU_DELETE: | |
2224 | { | |
ae8351fc JS |
2225 | wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data); |
2226 | wxResourceManager::GetCurrentResourceManager()->DeleteResource(data); | |
2227 | wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data); | |
457814b5 JS |
2228 | break; |
2229 | } | |
2230 | default: | |
2231 | break; | |
2232 | } | |
2233 | } | |
2234 | ||
457814b5 JS |
2235 | /* |
2236 | * Main toolbar | |
2237 | * | |
2238 | */ | |
2239 | ||
9d3221ab RR |
2240 | #ifdef __WXGTK__ // I don't dare to delete it... |
2241 | ||
2242 | BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar) | |
2243 | END_EVENT_TABLE() | |
2244 | ||
2245 | #else | |
2246 | ||
ae8351fc | 2247 | BEGIN_EVENT_TABLE(EditorToolBar, wxToolBar) |
457814b5 JS |
2248 | EVT_PAINT(EditorToolBar::OnPaint) |
2249 | END_EVENT_TABLE() | |
2250 | ||
9d3221ab RR |
2251 | #endif |
2252 | ||
ae8351fc | 2253 | EditorToolBar::EditorToolBar(wxFrame *frame, const wxPoint& pos, const wxSize& size, |
f449ef69 JS |
2254 | long style): |
2255 | wxToolBar(frame, -1, pos, size, style) | |
457814b5 JS |
2256 | { |
2257 | } | |
2258 | ||
fd71308f | 2259 | bool EditorToolBar::OnLeftClick(int toolIndex, bool WXUNUSED(toggled)) |
457814b5 | 2260 | { |
ae8351fc JS |
2261 | wxResourceManager *manager = wxResourceManager::GetCurrentResourceManager(); |
2262 | ||
457814b5 JS |
2263 | switch (toolIndex) |
2264 | { | |
2265 | case TOOLBAR_LOAD_FILE: | |
2266 | { | |
2267 | manager->New(TRUE); | |
2268 | break; | |
2269 | } | |
2270 | case TOOLBAR_NEW: | |
2271 | { | |
ae8351fc | 2272 | manager->CreateNewPanel(); |
457814b5 JS |
2273 | break; |
2274 | } | |
2275 | case TOOLBAR_SAVE_FILE: | |
2276 | { | |
2277 | manager->Save(); | |
2278 | break; | |
2279 | } | |
2280 | case TOOLBAR_HELP: | |
2281 | { | |
d0fff5cb | 2282 | #ifdef __WXMSW__ |
457814b5 | 2283 | wxBeginBusyCursor(); |
ae8351fc JS |
2284 | manager->GetHelpController()->LoadFile(); |
2285 | manager->GetHelpController()->DisplayContents(); | |
457814b5 | 2286 | wxEndBusyCursor(); |
b127f301 | 2287 | #endif |
457814b5 JS |
2288 | break; |
2289 | } | |
2290 | case TOOLBAR_FORMAT_HORIZ: | |
2291 | { | |
2292 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ); | |
2293 | break; | |
2294 | } | |
2295 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: | |
2296 | { | |
2297 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN); | |
2298 | break; | |
2299 | } | |
2300 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: | |
2301 | { | |
2302 | manager->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN); | |
2303 | break; | |
2304 | } | |
2305 | case TOOLBAR_FORMAT_VERT: | |
2306 | { | |
2307 | manager->AlignItems(TOOLBAR_FORMAT_VERT); | |
2308 | break; | |
2309 | } | |
2310 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: | |
2311 | { | |
2312 | manager->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN); | |
2313 | break; | |
2314 | } | |
2315 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: | |
2316 | { | |
2317 | manager->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN); | |
2318 | break; | |
2319 | } | |
2320 | case TOOLBAR_COPY_SIZE: | |
2321 | { | |
2322 | manager->CopySize(); | |
2323 | break; | |
2324 | } | |
2325 | case TOOLBAR_TO_BACK: | |
2326 | { | |
2327 | manager->ToBackOrFront(TRUE); | |
2328 | break; | |
2329 | } | |
2330 | case TOOLBAR_TO_FRONT: | |
2331 | { | |
2332 | manager->ToBackOrFront(FALSE); | |
2333 | break; | |
2334 | } | |
2335 | default: | |
2336 | break; | |
2337 | } | |
2338 | return TRUE; | |
2339 | } | |
2340 | ||
2341 | void EditorToolBar::OnMouseEnter(int toolIndex) | |
2342 | { | |
2343 | wxFrame *frame = (wxFrame *)GetParent(); | |
2344 | ||
2345 | if (!frame) return; | |
2346 | ||
2347 | if (toolIndex > -1) | |
2348 | { | |
2349 | switch (toolIndex) | |
2350 | { | |
2351 | case TOOLBAR_LOAD_FILE: | |
2352 | frame->SetStatusText("Load project file"); | |
2353 | break; | |
2354 | case TOOLBAR_SAVE_FILE: | |
2355 | frame->SetStatusText("Save project file"); | |
2356 | break; | |
2357 | case TOOLBAR_NEW: | |
2358 | frame->SetStatusText("Create a new resource"); | |
2359 | break; | |
2360 | case TOOLBAR_FORMAT_HORIZ: | |
2361 | frame->SetStatusText("Align items horizontally"); | |
2362 | break; | |
2363 | case TOOLBAR_FORMAT_VERT: | |
2364 | frame->SetStatusText("Align items vertically"); | |
2365 | break; | |
2366 | case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN: | |
2367 | frame->SetStatusText("Left-align items"); | |
2368 | break; | |
2369 | case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN: | |
2370 | frame->SetStatusText("Right-align items"); | |
2371 | break; | |
2372 | case TOOLBAR_FORMAT_VERT_TOP_ALIGN: | |
2373 | frame->SetStatusText("Top-align items"); | |
2374 | break; | |
2375 | case TOOLBAR_FORMAT_VERT_BOT_ALIGN: | |
2376 | frame->SetStatusText("Bottom-align items"); | |
2377 | break; | |
2378 | case TOOLBAR_COPY_SIZE: | |
2379 | frame->SetStatusText("Copy size from first selection"); | |
2380 | break; | |
2381 | case TOOLBAR_TO_FRONT: | |
2382 | frame->SetStatusText("Put image to front"); | |
2383 | break; | |
2384 | case TOOLBAR_TO_BACK: | |
2385 | frame->SetStatusText("Put image to back"); | |
2386 | break; | |
2387 | case TOOLBAR_HELP: | |
2388 | frame->SetStatusText("Display help contents"); | |
2389 | break; | |
2390 | default: | |
2391 | break; | |
2392 | } | |
2393 | } | |
2394 | else frame->SetStatusText(""); | |
2395 | } | |
2396 |