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