1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource editor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "reseditr.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
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"
33 #include "wx/slider.h"
34 #include "wx/textctrl.h"
36 #include "wx/toolbar.h"
39 #include "wx/scrolbar.h"
40 #include "wx/config.h"
48 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
51 #include <strstream.h>
71 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
72 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
74 #if defined(__WXGTK__) || defined(__WXMOTIF__)
75 #include "bitmaps/load.xpm"
76 #include "bitmaps/save.xpm"
77 #include "bitmaps/new.xpm"
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"
90 #include "bitmaps/dialog.xpm"
91 #include "bitmaps/folder1.xpm"
92 #include "bitmaps/folder2.xpm"
93 #include "bitmaps/buttonsm.xpm"
100 wxResourceManager::wxResourceManager():
101 m_imageList(16, 16, TRUE
)
103 sm_currentResourceManager
= this;
104 m_editorFrame
= NULL
;
105 m_editorPanel
= NULL
;
107 m_editorResourceTree
= NULL
;
108 m_editorControlList
= NULL
;
110 m_symbolIdCounter
= 99;
112 m_currentFilename
= "";
113 m_symbolFilename
= "";
114 m_editorToolBar
= NULL
;
116 // Default window positions
117 m_resourceEditorWindowSize
.width
= 500;
118 m_resourceEditorWindowSize
.height
= 450;
120 m_resourceEditorWindowSize
.x
= 0;
121 m_resourceEditorWindowSize
.y
= 0;
123 m_propertyWindowSize
.width
= 300;
124 m_propertyWindowSize
.height
= 300;
127 m_helpController
= NULL
;
130 m_bitmapImage
= NULL
;
131 m_rootDialogItem
= 0;
134 wxResourceManager::~wxResourceManager()
136 sm_currentResourceManager
= NULL
;
140 if (m_helpController
)
142 m_helpController
->Quit();
143 delete m_helpController
;
144 m_helpController
= NULL
;
148 delete m_bitmapImage
;
152 bool wxResourceManager::Initialize()
154 // Set up the resource filename for each platform.
156 // dialoged.ini in the Windows directory
158 GetWindowsDirectory(buf
, 256);
159 strcat(buf
, "\\dialoged.ini");
160 m_optionsResourceFilename
= buf
;
161 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
162 wxGetHomeDir( &m_optionsResourceFilename
);
163 m_optionsResourceFilename
+= "/.dialogedrc";
165 #error "Unsupported platform."
171 m_helpController
= new wxHelpController
;
172 m_helpController
->Initialize("dialoged");
175 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
176 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
177 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
182 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
184 #if defined(__WXGTK__) || defined(__WXMOTIF__)
185 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
189 // Initialize the image list icons
191 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
192 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
193 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
194 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
196 wxIcon
icon1( dialog_xpm
);
197 wxIcon
icon2( folder1_xpm
);
198 wxIcon
icon3( folder2_xpm
);
199 wxIcon
icon4( buttonsm_xpm
);
201 m_imageList
.Add(icon1
);
202 m_imageList
.Add(icon2
);
203 m_imageList
.Add(icon3
);
204 m_imageList
.Add(icon4
);
206 m_symbolTable
.AddStandardSymbols();
211 bool wxResourceManager::LoadOptions()
213 wxConfig
config("DialogEd", "wxWindows");
215 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
216 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
217 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
218 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
219 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
220 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
221 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
222 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
225 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
226 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
227 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
228 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
229 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
230 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
231 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
232 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
237 bool wxResourceManager::SaveOptions()
239 wxConfig
config("DialogEd", "wxWindows");
241 config
.Write("editorWindowX", m_resourceEditorWindowSize
.x
);
242 config
.Write("editorWindowY", m_resourceEditorWindowSize
.y
);
243 config
.Write("editorWindowWidth", m_resourceEditorWindowSize
.width
);
244 config
.Write("editorWindowHeight", m_resourceEditorWindowSize
.height
);
245 config
.Write("propertyWindowX", m_propertyWindowSize
.x
);
246 config
.Write("propertyWindowY", m_propertyWindowSize
.y
);
247 config
.Write("propertyWindowWidth", m_propertyWindowSize
.width
);
248 config
.Write("propertyWindowHeight", m_propertyWindowSize
.height
);
250 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
251 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
252 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
253 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
255 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
256 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
257 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
258 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
264 // Show or hide the resource editor frame, which displays a list
265 // of resources with ability to edit them.
266 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
272 m_editorFrame
->Iconize(FALSE
);
273 m_editorFrame
->Show(TRUE
);
276 m_editorFrame
= OnCreateEditorFrame(title
);
278 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
279 m_editorFrame
->SetMenuBar(menuBar
);
281 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
282 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
283 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
285 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
287 m_editorResourceTree
->SetImageList(& m_imageList
);
289 // Constraints for toolbar
290 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
291 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
292 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
293 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
294 c
->bottom
.Unconstrained();
295 c
->width
.Unconstrained();
296 c
->height
.Absolute(28);
297 m_editorToolBar
->SetConstraints(c
);
299 // Constraints for listbox
300 c
= new wxLayoutConstraints
;
301 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
302 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
303 c
->right
.Absolute (150);
304 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
305 c
->width
.Unconstrained();
306 c
->height
.Unconstrained();
307 m_editorResourceTree
->SetConstraints(c
);
309 // Constraints for panel
310 c
= new wxLayoutConstraints
;
311 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
312 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
313 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
314 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
315 c
->width
.Unconstrained();
316 c
->height
.Unconstrained();
317 m_editorPanel
->SetConstraints(c
);
319 // Constraints for control list (bottom window)
320 c
= new wxLayoutConstraints
;
321 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
322 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
323 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
324 c
->width
.Unconstrained();
325 #if defined(__WXGTK__) || defined(__WXMOTIF__)
326 c
->height
.Absolute(120);
328 c
->height
.Absolute(60);
331 m_editorControlList
->SetConstraints(c
);
333 m_editorFrame
->SetAutoLayout(TRUE
);
335 UpdateResourceList();
337 m_editorFrame
->Show(TRUE
);
342 wxFrame
*fr
= m_editorFrame
;
343 if (m_editorFrame
->Close())
345 m_editorFrame
= NULL
;
346 m_editorPanel
= NULL
;
352 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
356 if (filename
== wxString(""))
357 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
360 wxString
str("wxWindows Dialog Editor - ");
361 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
363 m_editorFrame
->SetTitle(str
);
368 bool wxResourceManager::Save()
370 if (m_currentFilename
== wxString(""))
373 return Save(m_currentFilename
);
376 bool wxResourceManager::Save(const wxString
& filename
)
378 // Ensure all visible windows are saved to their resources
379 m_currentFilename
= filename
;
380 SetFrameTitle(m_currentFilename
);
381 InstantiateAllResourcesFromWindows();
382 if (m_resourceTable
.Save(filename
))
384 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
392 bool wxResourceManager::SaveAs()
394 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
395 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
, wxTheApp
->GetTopWindow()));
397 if (s
.IsNull() || s
== "")
400 m_currentFilename
= s
;
401 wxStripExtension(m_currentFilename
);
402 m_currentFilename
+= ".wxr";
404 // Construct include filename from this file
405 m_symbolFilename
= m_currentFilename
;
407 wxStripExtension(m_symbolFilename
);
408 m_symbolFilename
+= ".h";
410 Save(m_currentFilename
);
414 bool wxResourceManager::SaveIfModified()
421 bool wxResourceManager::Load(const wxString
& filename
)
423 return New(TRUE
, filename
);
426 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
428 if (!Clear(TRUE
, FALSE
))
431 m_symbolTable
.AddStandardSymbols();
435 wxString str
= filename
;
436 if (str
== wxString(""))
438 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, wxTheApp
->GetTopWindow()));
439 if (!f
.IsNull() && f
!= "")
445 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
447 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
450 m_currentFilename
= str
;
452 SetFrameTitle(m_currentFilename
);
454 UpdateResourceList();
456 // Construct include filename from this file
457 m_symbolFilename
= m_currentFilename
;
459 wxStripExtension(m_symbolFilename
);
460 m_symbolFilename
+= ".h";
462 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
464 wxString
str("Could not find include file ");
465 str
+= m_symbolFilename
;
466 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
467 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
468 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
470 m_symbolIdCounter
= 99;
474 // Set the id counter to the last known id
475 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
478 // Now check in case some (or all) resources don't have resource ids, or they
479 // don't match the .h file, or something of that nature.
480 bool altered
= RepairResourceIds();
483 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
484 "Dialog Editor Warning", wxOK
);
495 m_currentFilename
= "";
502 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
504 if (!force
&& Modified())
506 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
510 if (!SaveIfModified())
516 ClearCurrentDialog();
517 DisassociateWindows();
519 m_symbolTable
.Clear();
520 m_resourceTable
.ClearTable();
521 UpdateResourceList();
526 bool wxResourceManager::DisassociateWindows()
528 m_resourceTable
.BeginFind();
530 while ((node
= m_resourceTable
.Next()))
532 wxItemResource
*res
= (wxItemResource
*)node
->Data();
533 DisassociateResource(res
);
539 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
541 if (!m_resourceAssociations
.Get((long)resource
))
542 m_resourceAssociations
.Put((long)resource
, win
);
544 wxNode
*node
= resource
->GetChildren().First();
547 wxItemResource
*child
= (wxItemResource
*)node
->Data();
548 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
550 childWindow
= win
->FindWindow(child
->GetName());
552 AssociateResource(child
, childWindow
);
556 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
557 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
564 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
566 wxWindow
*win
= FindWindowForResource(resource
);
570 // Disassociate children of window
571 wxNode
*node
= win
->GetChildren().First();
574 wxWindow
*child
= (wxWindow
*)node
->Data();
575 if (child
->IsKindOf(CLASSINFO(wxControl
)))
576 DisassociateResource(child
);
580 RemoveSelection(win
);
581 m_resourceAssociations
.Delete((long)resource
);
585 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
587 wxItemResource
*res
= FindResourceForWindow(win
);
589 return DisassociateResource(res
);
594 // Saves the window info into the resource, and deletes the
595 // handler. Doesn't actually disassociate the window from
596 // the resources. Replaces OnClose.
597 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
599 wxItemResource
*res
= FindResourceForWindow(win
);
601 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
603 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
604 win
->PopEventHandler();
606 // Now reset all child event handlers
607 wxNode
*node
= win
->GetChildren().First();
610 wxWindow
*child
= (wxWindow
*)node
->Data();
611 wxEvtHandler
*childHandler
= child
->GetEventHandler();
612 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
614 child
->PopEventHandler(TRUE
);
622 win
->PopEventHandler(TRUE
);
625 // Save the information
626 InstantiateResourceFromWindow(res
, win
, TRUE
);
628 // DisassociateResource(win);
633 // Destroys the window. If this is the 'current' panel, NULLs the
635 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
637 bool clearDisplay
= FALSE
;
638 if (m_editorPanel
->m_childWindow
== win
)
640 m_editorPanel
->m_childWindow
= NULL
;
647 m_editorPanel
->Clear();
652 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
654 m_resourceAssociations
.BeginFind();
656 while ((node
= m_resourceAssociations
.Next()))
658 wxWindow
*w
= (wxWindow
*)node
->Data();
661 return (wxItemResource
*)node
->GetKeyInteger();
667 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
669 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
673 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
677 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
680 if (!m_resourceTable
.FindResource(buf
))
685 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
688 int frameWidth = 420;
689 int frameHeight = 300;
692 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
693 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
694 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
695 wxDEFAULT_FRAME_STYLE
);
697 frame
->CreateStatusBar(1);
699 frame
->SetAutoLayout(TRUE
);
701 frame
->SetIcon(wxIcon("DIALOGEDICON"));
706 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
708 wxMenuBar
*menuBar
= new wxMenuBar
;
710 wxMenu
*fileMenu
= new wxMenu
;
711 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
712 fileMenu
->AppendSeparator();
713 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
714 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
715 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
716 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
717 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
718 fileMenu
->AppendSeparator();
719 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
721 wxMenu
*editMenu
= new wxMenu
;
722 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
723 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
724 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
726 wxMenu
*helpMenu
= new wxMenu
;
727 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
728 helpMenu
->AppendSeparator();
729 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
731 menuBar
->Append(fileMenu
, "&File");
732 menuBar
->Append(editMenu
, "&Edit");
733 menuBar
->Append(helpMenu
, "&Help");
738 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
740 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
741 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
748 panel
->SetScrollbars(10, 10, 100, 100);
753 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
755 // Load palette bitmaps
757 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
758 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
759 wxBitmap
ToolbarNewBitmap("NEWTOOL");
760 wxBitmap
ToolbarVertBitmap("VERTTOOL");
761 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
762 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
763 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
764 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
765 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
766 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
767 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
768 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
769 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
771 #if defined(__WXGTK__) || defined(__WXMOTIF__)
772 wxBitmap
ToolbarLoadBitmap( load_xpm
);
773 wxBitmap
ToolbarSaveBitmap( save_xpm
);
774 wxBitmap
ToolbarNewBitmap( new_xpm
);
775 wxBitmap
ToolbarVertBitmap( vert_xpm
);
776 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
777 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
778 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
779 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
780 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
781 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
782 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
783 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
784 wxBitmap
ToolbarHelpBitmap( help_xpm
);
787 // Create the toolbar
788 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
789 toolbar
->SetMargins(2, 2);
796 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
801 toolbar
->AddSeparator();
802 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
803 FALSE
, currentX
, -1, NULL
, "New dialog");
804 currentX
+= width
+ dx
;
805 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
806 FALSE
, currentX
, -1, NULL
, "Load");
807 currentX
+= width
+ dx
;
808 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
809 FALSE
, currentX
, -1, NULL
, "Save");
810 currentX
+= width
+ dx
+ gap
;
811 toolbar
->AddSeparator();
812 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
813 FALSE
, currentX
, -1, NULL
, "Horizontal align");
814 currentX
+= width
+ dx
;
815 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
816 FALSE
, currentX
, -1, NULL
, "Top align");
817 currentX
+= width
+ dx
;
818 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
819 FALSE
, currentX
, -1, NULL
, "Bottom align");
820 currentX
+= width
+ dx
;
821 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
822 FALSE
, currentX
, -1, NULL
, "Vertical align");
823 currentX
+= width
+ dx
;
824 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
825 FALSE
, currentX
, -1, NULL
, "Left align");
826 currentX
+= width
+ dx
;
827 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
828 FALSE
, currentX
, -1, NULL
, "Right align");
829 currentX
+= width
+ dx
;
830 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
831 FALSE
, currentX
, -1, NULL
, "Copy size");
832 currentX
+= width
+ dx
+ gap
;
833 toolbar
->AddSeparator();
834 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
835 FALSE
, currentX
, -1, NULL
, "To front");
836 currentX
+= width
+ dx
;
837 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
838 FALSE
, currentX
, -1, NULL
, "To back");
839 currentX
+= width
+ dx
+ gap
;
841 toolbar
->AddSeparator();
842 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
843 FALSE
, currentX
, -1, NULL
, "Help");
844 currentX
+= width
+ dx
;
851 void wxResourceManager::UpdateResourceList()
853 if (!m_editorResourceTree
)
856 m_editorResourceTree
->SetInvalid(TRUE
);
857 m_editorResourceTree
->DeleteAllItems();
859 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
861 m_resourceTable
.BeginFind();
863 while ((node
= m_resourceTable
.Next()))
865 wxItemResource
*res
= (wxItemResource
*)node
->Data();
866 wxString
resType(res
->GetType());
867 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
869 AddItemsRecursively(id
, res
);
872 m_editorResourceTree
->Expand(id
);
873 m_editorResourceTree
->SetInvalid(FALSE
);
876 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
878 wxString
theString("");
879 theString
= resource
->GetName();
882 wxString
resType(resource
->GetType());
883 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
888 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
890 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
892 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
894 wxNode
*node
= resource
->GetChildren().First();
897 wxItemResource
*res
= (wxItemResource
*)node
->Data();
898 AddItemsRecursively(id
, res
);
902 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
905 bool wxResourceManager::EditSelectedResource()
907 int sel
= m_editorResourceTree
->GetSelection();
910 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
911 wxItemResource
*res
= data
->GetResource();
917 bool wxResourceManager::Edit(wxItemResource
*res
)
919 ClearCurrentDialog();
921 wxString
resType(res
->GetType());
922 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
926 wxMessageBox("Should not find panel in wxResourceManager::Edit");
931 // long style = res->GetStyle();
932 // res->SetStyle(style|wxRAISED_BORDER);
934 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
937 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
939 panel
->PushEventHandler(handler
);
941 // res->SetStyle(style);
942 handler
->AddChildHandlers(); // Add event handlers for all controls
943 AssociateResource(res
, panel
);
945 m_editorPanel
->m_childWindow
= panel
;
946 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
950 wxClientDC
dc(m_editorPanel
);
951 m_editorPanel
->DrawTitle(dc
);
956 bool wxResourceManager::CreateNewPanel()
958 ClearCurrentDialog();
961 MakeUniqueName("dialog", buf
);
963 wxItemResource
*resource
= new wxItemResource
;
964 resource
->SetType("wxDialog");
965 resource
->SetName(buf
);
966 resource
->SetTitle(buf
);
967 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
968 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
971 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
974 // This is now guaranteed to be unique, so just add to symbol table
975 m_symbolTable
.AddSymbol(newIdName
, id
);
977 m_resourceTable
.AddResource(resource
);
979 wxSize
size(400, 300);
981 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
982 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
983 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
984 m_editorPanel
->m_childWindow
= panel
;
986 resource
->SetStyle(panel
->GetWindowStyleFlag());
988 // Store dialog units in resource
989 size
= panel
->ConvertPixelsToDialog(size
);
991 resource
->SetSize(10, 10, size
.x
, size
.y
);
993 // For editing in situ we will need to use the hash table to ensure
994 // we don't dereference invalid pointers.
995 // resourceWindowTable.Put((long)resource, panel);
997 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
999 panel
->PushEventHandler(handler
);
1001 AssociateResource(resource
, panel
);
1002 UpdateResourceList();
1005 m_editorPanel
->m_childWindow
->Refresh();
1007 // panel->Refresh();
1009 wxClientDC
dc(m_editorPanel
);
1010 m_editorPanel
->DrawTitle(dc
);
1015 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1018 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1023 wxItemResource
*res
= new wxItemResource
;
1024 wxControl
*newItem
= NULL
;
1026 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1028 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1029 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1031 else res
->SetSize(x
, y
, -1, -1);
1033 res
->SetType(iType
);
1037 wxString
itemType(iType
);
1039 if (itemType
== "wxButton")
1041 prefix
= "ID_BUTTON";
1042 MakeUniqueName("button", buf
);
1045 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1047 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1049 if (itemType
== "wxBitmapButton")
1051 prefix
= "ID_BITMAPBUTTON";
1052 MakeUniqueName("button", buf
);
1054 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1056 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1058 prefix
= "ID_STATIC";
1059 MakeUniqueName("statictext", buf
);
1062 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1064 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1066 else if (itemType
== "wxStaticBitmap")
1068 prefix
= "ID_STATICBITMAP";
1069 MakeUniqueName("static", buf
);
1071 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1073 else if (itemType
== "wxCheckBox")
1075 prefix
= "ID_CHECKBOX";
1076 MakeUniqueName("checkbox", buf
);
1078 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1080 else if (itemType
== "wxListBox")
1082 prefix
= "ID_LISTBOX";
1083 MakeUniqueName("listbox", buf
);
1085 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1087 else if (itemType
== "wxRadioBox")
1089 prefix
= "ID_RADIOBOX";
1090 MakeUniqueName("radiobox", buf
);
1092 wxString names
[] = { "One", "Two" };
1093 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1094 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1095 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1097 else if (itemType
== "wxRadioButton")
1099 prefix
= "ID_RADIOBUTTON";
1100 MakeUniqueName("radiobutton", buf
);
1102 wxString names
[] = { "One", "Two" };
1103 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1104 0, wxDefaultValidator
, buf
);
1106 else if (itemType
== "wxChoice")
1108 prefix
= "ID_CHOICE";
1109 MakeUniqueName("choice", buf
);
1111 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1113 else if (itemType
== "wxComboBox")
1115 prefix
= "ID_COMBOBOX";
1116 MakeUniqueName("combobox", buf
);
1118 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1120 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1122 prefix
= "ID_STATICBOX";
1123 MakeUniqueName("staticbox", buf
);
1125 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1127 else if (itemType
== "wxGauge")
1129 prefix
= "ID_GAUGE";
1130 MakeUniqueName("gauge", buf
);
1132 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1134 else if (itemType
== "wxSlider")
1136 prefix
= "ID_SLIDER";
1137 MakeUniqueName("slider", buf
);
1139 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1141 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1143 prefix
= "ID_TEXTCTRL";
1144 MakeUniqueName("textctrl", buf
);
1146 res
->SetType("wxTextCtrl");
1147 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1149 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1151 prefix
= "ID_TEXTCTRL";
1152 MakeUniqueName("textctrl", buf
);
1154 res
->SetType("wxTextCtrl");
1155 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1157 else if (itemType
== "wxScrollBar")
1159 prefix
= "ID_SCROLLBAR";
1160 MakeUniqueName("scrollbar", buf
);
1162 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1167 int actualW
, actualH
;
1168 newItem
->GetSize(&actualW
, &actualH
);
1169 wxSize
actualSize(actualW
, actualH
);
1171 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1173 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1175 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1178 int id
= GenerateWindowId(prefix
, newIdName
);
1181 // This is now guaranteed to be unique, so just add to symbol table
1182 m_symbolTable
.AddSymbol(newIdName
, id
);
1184 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1186 res
->SetStyle(newItem
->GetWindowStyleFlag());
1187 AssociateResource(res
, newItem
);
1188 panelResource
->GetChildren().Append(res
);
1190 UpdateResourceList();
1195 void wxResourceManager::ClearCurrentDialog()
1197 if (m_editorPanel
->m_childWindow
)
1199 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1200 DisassociateResource(m_editorPanel
->m_childWindow
);
1201 DeleteWindow(m_editorPanel
->m_childWindow
);
1202 m_editorPanel
->m_childWindow
= NULL
;
1203 m_editorPanel
->Clear();
1207 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1209 if (m_editorPanel
->m_childWindow
)
1211 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1215 // Make sure the resources are up-to-date w.r.t. the window
1216 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1218 wxDialog
* dialog
= new wxDialog
;
1219 bool success
= FALSE
;
1220 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1223 dialog
->ShowModal();
1231 // Find the first dialog or panel for which
1232 // there is a selected panel item.
1233 wxWindow
*wxResourceManager::FindParentOfSelection()
1235 m_resourceTable
.BeginFind();
1237 while ((node
= m_resourceTable
.Next()))
1239 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1240 wxWindow
*win
= FindWindowForResource(res
);
1243 wxNode
*node1
= win
->GetChildren().First();
1246 wxControl
*item
= (wxControl
*)node1
->Data();
1247 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1248 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1250 node1
= node1
->Next();
1257 // Format the panel items according to 'flag'
1258 void wxResourceManager::AlignItems(int flag
)
1260 wxWindow
*win
= FindParentOfSelection();
1264 wxNode
*node
= GetSelections().First();
1268 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1269 if (firstSelection
->GetParent() != win
)
1274 firstSelection
->GetPosition(&firstX
, &firstY
);
1275 firstSelection
->GetSize(&firstW
, &firstH
);
1276 int centreX
= (int)(firstX
+ (firstW
/ 2));
1277 int centreY
= (int)(firstY
+ (firstH
/ 2));
1279 while ((node
= node
->Next()))
1281 wxControl
*item
= (wxControl
*)node
->Data();
1282 if (item
->GetParent() == win
)
1285 item
->GetPosition(&x
, &y
);
1286 item
->GetSize(&w
, &h
);
1292 case TOOLBAR_FORMAT_HORIZ
:
1295 newY
= (int)(centreY
- (h
/2.0));
1298 case TOOLBAR_FORMAT_VERT
:
1300 newX
= (int)(centreX
- (w
/2.0));
1304 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1310 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1316 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1318 newX
= firstX
+ firstW
- w
;
1322 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1325 newY
= firstY
+ firstH
- h
;
1333 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1334 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1336 item
->SetSize(newX
, newY
, w
, h
);
1338 // Also update the associated resource
1339 // We need to convert to dialog units if this is not a dialog or panel, but
1340 // the parent resource specifies dialog units.
1341 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1343 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1344 newX
= pt
.x
; newY
= pt
.y
;
1345 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1348 resource
->SetSize(newX
, newY
, w
, h
);
1354 // Copy the first image's size to subsequent images
1355 void wxResourceManager::CopySize()
1357 wxWindow
*win
= FindParentOfSelection();
1361 wxNode
*node
= GetSelections().First();
1365 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1366 if (firstSelection
->GetParent() != win
)
1371 firstSelection
->GetPosition(&firstX
, &firstY
);
1372 firstSelection
->GetSize(&firstW
, &firstH
);
1374 while ((node
= node
->Next()))
1376 wxControl
*item
= (wxControl
*)node
->Data();
1377 if (item
->GetParent() == win
)
1379 item
->SetSize(-1, -1, firstW
, firstH
);
1381 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1382 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1384 // Also update the associated resource
1385 // We need to convert to dialog units if this is not a dialog or panel, but
1386 // the parent resource specifies dialog units.
1387 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1389 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1390 firstW
= sz
.x
; firstH
= sz
.y
;
1392 resource
->SetSize(resource
->GetX(), resource
->GetY(), firstW
, firstH
);
1399 void wxResourceManager::ToBackOrFront(bool toBack
)
1401 wxWindow
*win
= FindParentOfSelection();
1404 wxItemResource
*winResource
= FindResourceForWindow(win
);
1406 wxNode
*node
= GetSelections().First();
1409 wxControl
*item
= (wxControl
*)node
->Data();
1410 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1411 if (item
->GetParent() == win
)
1413 win
->GetChildren().DeleteObject(item
);
1415 winResource
->GetChildren().DeleteObject(itemResource
);
1418 win
->GetChildren().Insert(item
);
1420 winResource
->GetChildren().Insert(itemResource
);
1424 win
->GetChildren().Append(item
);
1426 winResource
->GetChildren().Append(itemResource
);
1429 node
= node
->Next();
1434 void wxResourceManager::AddSelection(wxWindow
*win
)
1436 if (!m_selections
.Member(win
))
1437 m_selections
.Append(win
);
1440 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1442 m_selections
.DeleteObject(win
);
1445 // Need to search through resource table removing this from
1446 // any resource which has this as a parent.
1447 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1449 m_resourceTable
.BeginFind();
1451 while ((node
= m_resourceTable
.Next()))
1453 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1454 if (thisRes
->GetChildren().Member(res
))
1456 thisRes
->GetChildren().DeleteObject(res
);
1463 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1468 RemoveResourceFromParent(res
);
1470 wxNode
*node
= res
->GetChildren().First();
1473 wxNode
*next
= node
->Next();
1474 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1475 DeleteResource(child
);
1479 // If this is a button or message resource, delete the
1480 // associate bitmap resource if not being used.
1481 wxString
resType(res
->GetType());
1483 /* shouldn't have to do this now bitmaps are ref-counted
1484 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1486 PossiblyDeleteBitmapResource(res->GetValue4());
1490 // Remove symbol from table if appropriate
1491 if (!IsSymbolUsed(res
, res
->GetId()))
1493 m_symbolTable
.RemoveSymbol(res
->GetId());
1496 m_resourceTable
.Delete(res
->GetName());
1502 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1504 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1506 // Deselect and refresh window in case we leave selection
1508 wxControl
*item
= (wxControl
*)win
;
1509 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1510 if (childHandler
->IsSelected())
1512 RemoveSelection(item
);
1513 childHandler
->SelectItem(FALSE
);
1515 item
->GetParent()->Refresh();
1520 wxItemResource
*res
= FindResourceForWindow(win
);
1522 DisassociateResource(res
);
1523 DeleteResource(res
);
1524 UpdateResourceList();
1529 // Will eventually have bitmap type information, for different
1531 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1533 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1537 MakeUniqueName("bitmap", buf
);
1538 resource
= new wxItemResource
;
1539 resource
->SetType("wxBitmap");
1540 resource
->SetName(buf
);
1542 // A bitmap resource has one or more children, specifying
1543 // alternative bitmaps.
1544 wxItemResource
*child
= new wxItemResource
;
1545 child
->SetType("wxBitmap");
1546 child
->SetName(filename
);
1547 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1548 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1549 child
->SetValue3(0); // Depth
1550 child
->SetSize(0,0,0,0);
1551 resource
->GetChildren().Append(child
);
1553 m_resourceTable
.AddResource(resource
);
1555 UpdateResourceList();
1558 return resource
->GetName();
1560 return wxEmptyString
;
1563 // Delete the bitmap resource if it isn't being used by another resource.
1564 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1566 if (!IsBitmapResourceUsed(resourceName
))
1568 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1569 DeleteResource(res
);
1570 UpdateResourceList();
1574 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1576 m_resourceTable
.BeginFind();
1578 while ((node
= m_resourceTable
.Next()))
1580 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1581 wxString
resType(res
->GetType());
1582 if (resType
== "wxDialog")
1584 wxNode
*node1
= res
->GetChildren().First();
1587 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1588 wxString
childResType(child
->GetType());
1590 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1591 child
->GetValue4() &&
1592 (strcmp(child
->GetValue4(), resourceName
) == 0))
1594 node1
= node1
->Next();
1601 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1602 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1604 if (!resource
|| (resource
->GetValue4() == ""))
1605 return wxEmptyString
;
1606 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1607 if (!bitmapResource
)
1608 return wxEmptyString
;
1610 wxNode
*node
= bitmapResource
->GetChildren().First();
1613 // Eventually augment this to return a bitmap of the right kind or something...
1614 // Maybe the root of the filename remains the same, so it doesn't matter which we
1615 // pick up. Otherwise how do we specify multiple filenames... too boring...
1616 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1617 return child
->GetName();
1619 node
= node
->Next();
1621 return wxEmptyString
;
1624 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1626 m_resourceTable
.BeginFind();
1628 while ((node
= m_resourceTable
.Next()))
1630 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1631 wxString
resType(res
->GetType());
1632 if (resType
== "wxBitmap")
1634 wxNode
*node1
= res
->GetChildren().First();
1637 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1638 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1640 node1
= node1
->Next();
1647 // Is this window identifier symbol in use?
1648 // Let's assume that we can't have 2 names for the same integer id.
1649 // Therefore we can tell by the integer id whether the symbol is
1651 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1653 m_resourceTable
.BeginFind();
1655 while ((node
= m_resourceTable
.Next()))
1657 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1659 wxString
resType(res
->GetType());
1660 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1662 if ((res
!= thisResource
) && (res
->GetId() == id
))
1665 wxNode
*node1
= res
->GetChildren().First();
1668 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1669 if ((child
!= thisResource
) && (child
->GetId() == id
))
1671 node1
= node1
->Next();
1678 // Is this window identifier compatible with the given name? (i.e.
1679 // does it already exist under a different name)
1680 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1682 if (m_symbolTable
.SymbolExists(name
))
1684 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1691 // Change all integer ids that match oldId, to newId.
1692 // This is necessary if an id is changed for one resource - all resources
1694 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1696 m_resourceTable
.BeginFind();
1698 while ((node
= m_resourceTable
.Next()))
1700 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1702 wxString
resType(res
->GetType());
1703 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1705 if (res
->GetId() == oldId
)
1708 wxNode
*node1
= res
->GetChildren().First();
1711 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1712 if (child
->GetId() == oldId
)
1713 child
->SetId(newId
);
1715 node1
= node1
->Next();
1721 // If any resource ids were missing (or their symbol was missing),
1722 // repair them i.e. give them new ids. Returns TRUE if any resource
1723 // needed repairing.
1724 bool wxResourceManager::RepairResourceIds()
1726 bool repaired
= FALSE
;
1728 m_resourceTable
.BeginFind();
1730 while ((node
= m_resourceTable
.Next()))
1732 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1733 wxString
resType(res
->GetType());
1734 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1737 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1739 wxString newSymbolName
;
1740 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1742 if (res
->GetId() == 0)
1745 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1749 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1755 wxNode
*node1
= res
->GetChildren().First();
1758 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1760 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1762 wxString newSymbolName
;
1763 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1765 if (child
->GetId() == 0)
1767 child
->SetId(newId
);
1768 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1772 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1778 node1
= node1
->Next();
1786 // Deletes 'win' and creates a new window from the resource that
1787 // was associated with it. E.g. if you can't change properties on the
1788 // fly, you'll need to delete the window and create it again.
1789 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1791 wxItemResource
*resource
= FindResourceForWindow(win
);
1793 // Put the current window properties into the wxItemResource object
1795 wxWindowPropertyInfo
*newInfo
= NULL
;
1798 newInfo
= CreatePropertyInfoForWindow(win
);
1802 info
->InstantiateResource(resource
);
1804 wxWindow
*newWin
= NULL
;
1805 wxWindow
*parent
= win
->GetParent();
1806 wxItemResource
* parentResource
= NULL
;
1808 parentResource
= FindResourceForWindow(parent
);
1810 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1813 newWin
= FindWindowForResource(resource
);
1817 DisassociateResource(resource
);
1818 if (win
->GetEventHandler() != win
)
1819 win
->PopEventHandler(TRUE
);
1822 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1823 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1824 AssociateResource(resource
, newWin
);
1825 UpdateResourceList();
1829 info
->SetPropertyWindow(newWin
);
1837 // Delete resource highlighted in the listbox
1838 bool wxResourceManager::DeleteSelection()
1840 int sel
= m_editorResourceTree
->GetSelection();
1843 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1844 wxItemResource
*res
= data
->GetResource();
1845 wxWindow
*win
= FindWindowForResource(res
);
1848 DeleteResource(win
);
1850 UpdateResourceList();
1859 // Delete resource highlighted in the listbox
1860 bool wxResourceManager::RecreateSelection()
1862 wxNode
*node
= GetSelections().First();
1865 wxControl
*item
= (wxControl
*)node
->Data();
1866 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1867 wxNode
*next
= node
->Next();
1868 childHandler
->SelectItem(FALSE
);
1870 RemoveSelection(item
);
1872 RecreateWindowFromResource(item
);
1879 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
1884 // Ensures that all currently shown windows are saved to resources,
1885 // e.g. just before writing to a .wxr file.
1886 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1888 m_resourceTable
.BeginFind();
1890 while ((node
= m_resourceTable
.Next()))
1892 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1893 wxString
resType(res
->GetType());
1895 if (resType
== "wxDialog")
1897 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1899 InstantiateResourceFromWindow(res
, win
, TRUE
);
1901 else if (resType
== "wxPanel")
1903 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1905 InstantiateResourceFromWindow(res
, win
, TRUE
);
1911 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1913 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1914 info
->SetResource(resource
);
1915 info
->InstantiateResource(resource
);
1920 wxNode
*node
= resource
->GetChildren().First();
1923 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1924 wxWindow
*childWindow
= FindWindowForResource(child
);
1929 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
1930 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1933 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1934 node
= node
->Next();
1941 // Create a window information object for the give window
1942 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1944 wxWindowPropertyInfo
*info
= NULL
;
1945 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1947 info
= new wxScrollBarPropertyInfo(win
);
1949 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1951 info
= new wxGroupBoxPropertyInfo(win
);
1953 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1955 info
= new wxCheckBoxPropertyInfo(win
);
1957 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1959 info
= new wxSliderPropertyInfo(win
);
1961 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1963 info
= new wxGaugePropertyInfo(win
);
1965 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1967 info
= new wxListBoxPropertyInfo(win
);
1969 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1971 info
= new wxRadioBoxPropertyInfo(win
);
1973 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1975 info
= new wxRadioButtonPropertyInfo(win
);
1977 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
1979 info
= new wxComboBoxPropertyInfo(win
);
1981 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1983 info
= new wxChoicePropertyInfo(win
);
1985 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1987 info
= new wxBitmapButtonPropertyInfo(win
);
1989 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1991 info
= new wxButtonPropertyInfo(win
);
1993 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1995 info
= new wxStaticBitmapPropertyInfo(win
);
1997 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1999 info
= new wxStaticTextPropertyInfo(win
);
2001 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
2003 info
= new wxTextPropertyInfo(win
);
2005 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
2007 info
= new wxPanelPropertyInfo(win
);
2011 info
= new wxWindowPropertyInfo(win
);
2016 // Edit the given window
2017 void wxResourceManager::EditWindow(wxWindow
*win
)
2019 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2022 info
->SetResource(FindResourceForWindow(win
));
2023 wxString
str("Editing ");
2024 str
+= win
->GetClassInfo()->GetClassName();
2026 if (win
->GetName() != "")
2027 str
+= win
->GetName();
2029 str
+= "properties";
2030 info
->Edit(NULL
, str
);
2034 // Generate a window id and a first stab at a name
2035 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2037 m_symbolIdCounter
++;
2038 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2039 m_symbolIdCounter
++;
2041 int nameId
= m_symbolIdCounter
;
2044 str
.Printf("%d", nameId
);
2045 idName
= prefix
+ str
;
2047 while (m_symbolTable
.SymbolExists(idName
))
2050 str
.Printf("%d", nameId
);
2051 idName
= prefix
+ str
;
2054 return m_symbolIdCounter
;
2059 * Resource editor frame
2062 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2064 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2065 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2066 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2067 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2068 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2069 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2070 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2071 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2072 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2073 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2074 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2075 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2076 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2077 EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow
)
2080 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2081 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2082 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2087 wxResourceEditorFrame::~wxResourceEditorFrame()
2091 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2093 manager
->New(FALSE
);
2096 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2098 manager
->CreateNewPanel();
2101 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2106 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2108 manager
->Clear(TRUE
, FALSE
);
2111 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2116 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2121 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2123 manager
->Clear(TRUE
, FALSE
) ;
2127 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2130 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
2131 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2134 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2136 manager
->TestCurrentDialog(this);
2139 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2142 wxBeginBusyCursor();
2143 manager
->GetHelpController()->LoadFile();
2144 manager
->GetHelpController()->DisplayContents();
2149 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2151 manager
->DeleteSelection();
2154 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2156 manager
->RecreateSelection();
2159 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent
& event
)
2161 if (manager
->Modified())
2163 if (!manager
->Clear(TRUE
, FALSE
))
2174 manager
->m_resourceEditorWindowSize
.width
= w
;
2175 manager
->m_resourceEditorWindowSize
.height
= h
;
2178 GetPosition(&x
, &y
);
2180 manager
->m_resourceEditorWindowSize
.x
= x
;
2181 manager
->m_resourceEditorWindowSize
.y
= y
;
2183 manager
->SetEditorFrame(NULL
);
2184 manager
->SetEditorToolBar(NULL
);
2190 * Resource editor window that contains the dialog/panel being edited
2193 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2194 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
2195 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2198 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2200 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2204 m_childWindow
= NULL
;
2206 SetBackgroundColour(* wxWHITE
);
2209 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2213 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
2215 wxScrolledWindow::OnScroll(event
);
2218 ViewStart(& x
, & y
);
2221 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
2224 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2231 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2235 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2238 wxString
str(res
->GetTitle());
2240 ViewStart(& x
, & y
);
2242 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2244 dc
.SetBackgroundMode(wxTRANSPARENT
);
2245 dc
.SetTextForeground(wxColour(0, 0, 0));
2248 dc
.GetTextExtent(str
, & w
, & h
);
2250 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2255 // Popup menu callback
2256 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2258 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2262 switch (event
.GetInt())
2264 case OBJECT_MENU_EDIT
:
2266 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2269 case OBJECT_MENU_DELETE
:
2271 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2272 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2273 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2286 #if defined(__WXGTK__) || defined(__WXMOTIF__) // I don't dare to delete it...
2288 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2293 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2294 EVT_PAINT(EditorToolBar::OnPaint
)
2299 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2301 wxToolBar(frame
, -1, pos
, size
, style
)
2305 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2307 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2311 case TOOLBAR_LOAD_FILE
:
2318 manager
->CreateNewPanel();
2321 case TOOLBAR_SAVE_FILE
:
2329 wxBeginBusyCursor();
2330 manager
->GetHelpController()->LoadFile();
2331 manager
->GetHelpController()->DisplayContents();
2336 case TOOLBAR_FORMAT_HORIZ
:
2338 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2341 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2343 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2346 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2348 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2351 case TOOLBAR_FORMAT_VERT
:
2353 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2356 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2358 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2361 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2363 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2366 case TOOLBAR_COPY_SIZE
:
2368 manager
->CopySize();
2371 case TOOLBAR_TO_BACK
:
2373 manager
->ToBackOrFront(TRUE
);
2376 case TOOLBAR_TO_FRONT
:
2378 manager
->ToBackOrFront(FALSE
);
2387 void EditorToolBar::OnMouseEnter(int toolIndex
)
2389 wxFrame
*frame
= (wxFrame
*)GetParent();
2397 case TOOLBAR_LOAD_FILE
:
2398 frame
->SetStatusText("Load project file");
2400 case TOOLBAR_SAVE_FILE
:
2401 frame
->SetStatusText("Save project file");
2404 frame
->SetStatusText("Create a new resource");
2406 case TOOLBAR_FORMAT_HORIZ
:
2407 frame
->SetStatusText("Align items horizontally");
2409 case TOOLBAR_FORMAT_VERT
:
2410 frame
->SetStatusText("Align items vertically");
2412 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2413 frame
->SetStatusText("Left-align items");
2415 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2416 frame
->SetStatusText("Right-align items");
2418 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2419 frame
->SetStatusText("Top-align items");
2421 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2422 frame
->SetStatusText("Bottom-align items");
2424 case TOOLBAR_COPY_SIZE
:
2425 frame
->SetStatusText("Copy size from first selection");
2427 case TOOLBAR_TO_FRONT
:
2428 frame
->SetStatusText("Put image to front");
2430 case TOOLBAR_TO_BACK
:
2431 frame
->SetStatusText("Put image to back");
2434 frame
->SetStatusText("Display help contents");
2440 else frame
->SetStatusText("");