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