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"
57 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
58 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
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"
76 #include "bitmaps/dialog.xpm"
77 #include "bitmaps/folder1.xpm"
78 #include "bitmaps/folder2.xpm"
79 #include "bitmaps/buttonsm.xpm"
86 wxResourceManager::wxResourceManager():
87 m_imageList(16, 16, TRUE
)
89 sm_currentResourceManager
= this;
93 m_editorResourceTree
= NULL
;
94 m_editorControlList
= NULL
;
96 m_symbolIdCounter
= 99;
98 m_currentFilename
= "";
99 m_symbolFilename
= "";
100 m_editorToolBar
= NULL
;
102 // Default window positions
103 m_resourceEditorWindowSize
.width
= 500;
104 m_resourceEditorWindowSize
.height
= 450;
106 m_resourceEditorWindowSize
.x
= 0;
107 m_resourceEditorWindowSize
.y
= 0;
109 m_propertyWindowSize
.width
= 300;
110 m_propertyWindowSize
.height
= 300;
113 m_helpController
= NULL
;
116 m_bitmapImage
= NULL
;
117 m_rootDialogItem
= 0;
120 wxResourceManager::~wxResourceManager()
122 sm_currentResourceManager
= NULL
;
126 if (m_helpController
)
128 m_helpController
->Quit();
129 delete m_helpController
;
130 m_helpController
= NULL
;
134 delete m_bitmapImage
;
138 bool wxResourceManager::Initialize()
140 // Set up the resource filename for each platform.
141 // TODO: This shold be replaced by wxConfig usage.
143 // dialoged.ini in the Windows directory
144 wxString windowsDir
= wxGetOSDirectory();
145 windowsDir
+= "\\dialoged.ini" ;
147 m_optionsResourceFilename
= windowsDir
;
148 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
149 wxGetHomeDir( &m_optionsResourceFilename
);
150 m_optionsResourceFilename
+= "/.dialogedrc";
152 #error "Unsupported platform."
158 m_helpController
= new wxHelpController
;
159 m_helpController
->Initialize("dialoged");
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");
169 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
171 #if defined(__WXGTK__) || defined(__WXMOTIF__)
172 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
176 // Initialize the image list icons
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);
183 wxIcon
icon1( dialog_xpm
);
184 wxIcon
icon2( folder1_xpm
);
185 wxIcon
icon3( folder2_xpm
);
186 wxIcon
icon4( buttonsm_xpm
);
188 m_imageList
.Add(icon1
);
189 m_imageList
.Add(icon2
);
190 m_imageList
.Add(icon3
);
191 m_imageList
.Add(icon4
);
193 m_symbolTable
.AddStandardSymbols();
198 bool wxResourceManager::LoadOptions()
200 wxConfig
config("DialogEd", "wxWindows");
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
);
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());
224 bool wxResourceManager::SaveOptions()
226 wxConfig
config("DialogEd", "wxWindows");
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
);
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());
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());
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
)
259 m_editorFrame
->Iconize(FALSE
);
260 m_editorFrame
->Show(TRUE
);
263 m_editorFrame
= OnCreateEditorFrame(title
);
265 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
266 m_editorFrame
->SetMenuBar(menuBar
);
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),
272 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
274 m_editorResourceTree
->SetImageList(& m_imageList
);
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
);
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
);
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
);
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);
315 c
->height
.Absolute(60);
318 m_editorControlList
->SetConstraints(c
);
320 m_editorFrame
->SetAutoLayout(TRUE
);
322 UpdateResourceList();
324 m_editorFrame
->Show(TRUE
);
329 wxFrame
*fr
= m_editorFrame
;
330 if (m_editorFrame
->Close())
332 m_editorFrame
= NULL
;
333 m_editorPanel
= NULL
;
339 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
343 if (filename
== wxString(""))
344 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
347 wxString
str("wxWindows Dialog Editor - ");
348 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
350 m_editorFrame
->SetTitle(str
);
355 bool wxResourceManager::Save()
357 if (m_currentFilename
== wxString(""))
360 return Save(m_currentFilename
);
363 bool wxResourceManager::Save(const wxString
& filename
)
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
))
371 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
379 bool wxResourceManager::SaveAs()
381 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
382 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
, wxTheApp
->GetTopWindow()));
384 if (s
.IsNull() || s
== "")
387 m_currentFilename
= s
;
388 wxStripExtension(m_currentFilename
);
389 m_currentFilename
+= ".wxr";
391 // Construct include filename from this file
392 m_symbolFilename
= m_currentFilename
;
394 wxStripExtension(m_symbolFilename
);
395 m_symbolFilename
+= ".h";
397 Save(m_currentFilename
);
401 bool wxResourceManager::SaveIfModified()
408 bool wxResourceManager::Load(const wxString
& filename
)
410 return New(TRUE
, filename
);
413 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
415 if (!Clear(TRUE
, FALSE
))
418 m_symbolTable
.AddStandardSymbols();
422 wxString str
= filename
;
423 if (str
== wxString(""))
425 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, wxTheApp
->GetTopWindow()));
426 if (!f
.IsNull() && f
!= "")
432 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
434 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
437 m_currentFilename
= str
;
439 SetFrameTitle(m_currentFilename
);
441 UpdateResourceList();
443 // Construct include filename from this file
444 m_symbolFilename
= m_currentFilename
;
446 wxStripExtension(m_symbolFilename
);
447 m_symbolFilename
+= ".h";
449 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
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
);
457 m_symbolIdCounter
= 99;
461 // Set the id counter to the last known id
462 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
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();
470 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
471 "Dialog Editor Warning", wxOK
);
482 m_currentFilename
= "";
489 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
491 if (!force
&& Modified())
493 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
497 if (!SaveIfModified())
503 ClearCurrentDialog();
504 DisassociateWindows();
506 m_symbolTable
.Clear();
507 m_resourceTable
.ClearTable();
508 UpdateResourceList();
513 bool wxResourceManager::DisassociateWindows()
515 m_resourceTable
.BeginFind();
517 while ((node
= m_resourceTable
.Next()))
519 wxItemResource
*res
= (wxItemResource
*)node
->Data();
520 DisassociateResource(res
);
526 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
528 if (!m_resourceAssociations
.Get((long)resource
))
529 m_resourceAssociations
.Put((long)resource
, win
);
531 wxNode
*node
= resource
->GetChildren().First();
534 wxItemResource
*child
= (wxItemResource
*)node
->Data();
535 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
537 childWindow
= win
->FindWindow(child
->GetName());
539 AssociateResource(child
, childWindow
);
543 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
544 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
551 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
553 wxWindow
*win
= FindWindowForResource(resource
);
557 // Disassociate children of window
558 wxNode
*node
= win
->GetChildren().First();
561 wxWindow
*child
= (wxWindow
*)node
->Data();
562 if (child
->IsKindOf(CLASSINFO(wxControl
)))
563 DisassociateResource(child
);
567 RemoveSelection(win
);
568 m_resourceAssociations
.Delete((long)resource
);
572 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
574 wxItemResource
*res
= FindResourceForWindow(win
);
576 return DisassociateResource(res
);
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
)
586 wxItemResource
*res
= FindResourceForWindow(win
);
588 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
590 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
591 win
->PopEventHandler();
593 // Now reset all child event handlers
594 wxNode
*node
= win
->GetChildren().First();
597 wxWindow
*child
= (wxWindow
*)node
->Data();
598 wxEvtHandler
*childHandler
= child
->GetEventHandler();
599 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
601 child
->PopEventHandler(TRUE
);
609 win
->PopEventHandler(TRUE
);
612 // Save the information
613 InstantiateResourceFromWindow(res
, win
, TRUE
);
615 // DisassociateResource(win);
620 // Destroys the window. If this is the 'current' panel, NULLs the
622 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
624 bool clearDisplay
= FALSE
;
625 if (m_editorPanel
->m_childWindow
== win
)
627 m_editorPanel
->m_childWindow
= NULL
;
634 m_editorPanel
->Clear();
639 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
641 m_resourceAssociations
.BeginFind();
643 while ((node
= m_resourceAssociations
.Next()))
645 wxWindow
*w
= (wxWindow
*)node
->Data();
648 return (wxItemResource
*)node
->GetKeyInteger();
654 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
656 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
660 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
664 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
667 if (!m_resourceTable
.FindResource(buf
))
672 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
675 int frameWidth = 420;
676 int frameHeight = 300;
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
);
684 frame
->CreateStatusBar(1);
686 frame
->SetAutoLayout(TRUE
);
688 frame
->SetIcon(wxIcon("DIALOGEDICON"));
693 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
695 wxMenuBar
*menuBar
= new wxMenuBar
;
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");
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)");
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");
718 menuBar
->Append(fileMenu
, "&File");
719 menuBar
->Append(editMenu
, "&Edit");
720 menuBar
->Append(helpMenu
, "&Help");
725 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
727 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
728 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
735 panel
->SetScrollbars(10, 10, 100, 100);
740 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
742 // Load palette bitmaps
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");
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
);
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);
783 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
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
;
828 toolbar
->AddSeparator();
829 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
830 FALSE
, currentX
, -1, NULL
, "Help");
831 currentX
+= width
+ dx
;
838 void wxResourceManager::UpdateResourceList()
840 if (!m_editorResourceTree
)
843 m_editorResourceTree
->SetInvalid(TRUE
);
844 m_editorResourceTree
->DeleteAllItems();
846 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
848 m_resourceTable
.BeginFind();
850 while ((node
= m_resourceTable
.Next()))
852 wxItemResource
*res
= (wxItemResource
*)node
->Data();
853 wxString
resType(res
->GetType());
854 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
856 AddItemsRecursively(id
, res
);
859 m_editorResourceTree
->Expand(id
);
860 m_editorResourceTree
->SetInvalid(FALSE
);
863 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
865 wxString
theString("");
866 theString
= resource
->GetName();
869 wxString
resType(resource
->GetType());
870 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
875 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
877 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
879 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
881 wxNode
*node
= resource
->GetChildren().First();
884 wxItemResource
*res
= (wxItemResource
*)node
->Data();
885 AddItemsRecursively(id
, res
);
889 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
892 bool wxResourceManager::EditSelectedResource()
894 int sel
= m_editorResourceTree
->GetSelection();
897 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
898 wxItemResource
*res
= data
->GetResource();
904 bool wxResourceManager::Edit(wxItemResource
*res
)
906 ClearCurrentDialog();
908 wxString
resType(res
->GetType());
909 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
913 wxMessageBox("Should not find panel in wxResourceManager::Edit");
918 // long style = res->GetStyle();
919 // res->SetStyle(style|wxRAISED_BORDER);
921 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
924 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
926 panel
->PushEventHandler(handler
);
928 // res->SetStyle(style);
929 handler
->AddChildHandlers(); // Add event handlers for all controls
930 AssociateResource(res
, panel
);
932 m_editorPanel
->m_childWindow
= panel
;
933 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
937 wxClientDC
dc(m_editorPanel
);
938 m_editorPanel
->DrawTitle(dc
);
943 bool wxResourceManager::CreateNewPanel()
945 ClearCurrentDialog();
948 MakeUniqueName("dialog", buf
);
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
);
958 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
961 // This is now guaranteed to be unique, so just add to symbol table
962 m_symbolTable
.AddSymbol(newIdName
, id
);
964 m_resourceTable
.AddResource(resource
);
966 wxSize
size(400, 300);
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
;
973 resource
->SetStyle(panel
->GetWindowStyleFlag());
975 // Store dialog units in resource
976 size
= panel
->ConvertPixelsToDialog(size
);
978 resource
->SetSize(10, 10, size
.x
, size
.y
);
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);
984 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
986 panel
->PushEventHandler(handler
);
988 AssociateResource(resource
, panel
);
989 UpdateResourceList();
992 m_editorPanel
->m_childWindow
->Refresh();
996 wxClientDC
dc(m_editorPanel
);
997 m_editorPanel
->DrawTitle(dc
);
1002 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1005 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1010 wxItemResource
*res
= new wxItemResource
;
1011 wxControl
*newItem
= NULL
;
1013 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1015 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1016 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1018 else res
->SetSize(x
, y
, -1, -1);
1020 res
->SetType(iType
);
1024 wxString
itemType(iType
);
1026 if (itemType
== "wxButton")
1028 prefix
= "ID_BUTTON";
1029 MakeUniqueName("button", buf
);
1032 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1034 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1036 if (itemType
== "wxBitmapButton")
1038 prefix
= "ID_BITMAPBUTTON";
1039 MakeUniqueName("button", buf
);
1041 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1043 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1045 prefix
= "ID_STATIC";
1046 MakeUniqueName("statictext", buf
);
1049 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1051 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1053 else if (itemType
== "wxStaticBitmap")
1055 prefix
= "ID_STATICBITMAP";
1056 MakeUniqueName("static", buf
);
1058 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1060 else if (itemType
== "wxCheckBox")
1062 prefix
= "ID_CHECKBOX";
1063 MakeUniqueName("checkbox", buf
);
1065 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1067 else if (itemType
== "wxListBox")
1069 prefix
= "ID_LISTBOX";
1070 MakeUniqueName("listbox", buf
);
1072 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1074 else if (itemType
== "wxRadioBox")
1076 prefix
= "ID_RADIOBOX";
1077 MakeUniqueName("radiobox", 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
));
1084 else if (itemType
== "wxRadioButton")
1086 prefix
= "ID_RADIOBUTTON";
1087 MakeUniqueName("radiobutton", buf
);
1089 wxString names
[] = { "One", "Two" };
1090 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1091 0, wxDefaultValidator
, buf
);
1093 else if (itemType
== "wxChoice")
1095 prefix
= "ID_CHOICE";
1096 MakeUniqueName("choice", buf
);
1098 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1100 else if (itemType
== "wxComboBox")
1102 prefix
= "ID_COMBOBOX";
1103 MakeUniqueName("combobox", buf
);
1105 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1107 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1109 prefix
= "ID_STATICBOX";
1110 MakeUniqueName("staticbox", buf
);
1112 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1114 else if (itemType
== "wxGauge")
1116 prefix
= "ID_GAUGE";
1117 MakeUniqueName("gauge", buf
);
1119 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1121 else if (itemType
== "wxSlider")
1123 prefix
= "ID_SLIDER";
1124 MakeUniqueName("slider", buf
);
1126 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1128 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1130 prefix
= "ID_TEXTCTRL";
1131 MakeUniqueName("textctrl", buf
);
1133 res
->SetType("wxTextCtrl");
1134 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1136 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1138 prefix
= "ID_TEXTCTRL";
1139 MakeUniqueName("textctrl", buf
);
1141 res
->SetType("wxTextCtrl");
1142 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1144 else if (itemType
== "wxScrollBar")
1146 prefix
= "ID_SCROLLBAR";
1147 MakeUniqueName("scrollbar", buf
);
1149 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1154 int actualW
, actualH
;
1155 newItem
->GetSize(&actualW
, &actualH
);
1156 wxSize
actualSize(actualW
, actualH
);
1158 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1160 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1162 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1165 int id
= GenerateWindowId(prefix
, newIdName
);
1168 // This is now guaranteed to be unique, so just add to symbol table
1169 m_symbolTable
.AddSymbol(newIdName
, id
);
1171 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1173 res
->SetStyle(newItem
->GetWindowStyleFlag());
1174 AssociateResource(res
, newItem
);
1175 panelResource
->GetChildren().Append(res
);
1177 UpdateResourceList();
1182 void wxResourceManager::ClearCurrentDialog()
1184 if (m_editorPanel
->m_childWindow
)
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();
1194 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1196 if (m_editorPanel
->m_childWindow
)
1198 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1202 // Make sure the resources are up-to-date w.r.t. the window
1203 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1205 wxDialog
* dialog
= new wxDialog
;
1206 bool success
= FALSE
;
1207 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1210 dialog
->ShowModal();
1218 // Find the first dialog or panel for which
1219 // there is a selected panel item.
1220 wxWindow
*wxResourceManager::FindParentOfSelection()
1222 m_resourceTable
.BeginFind();
1224 while ((node
= m_resourceTable
.Next()))
1226 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1227 wxWindow
*win
= FindWindowForResource(res
);
1230 wxNode
*node1
= win
->GetChildren().First();
1233 wxControl
*item
= (wxControl
*)node1
->Data();
1234 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1235 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1237 node1
= node1
->Next();
1244 // Format the panel items according to 'flag'
1245 void wxResourceManager::AlignItems(int flag
)
1247 wxWindow
*win
= FindParentOfSelection();
1251 wxNode
*node
= GetSelections().First();
1255 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1256 if (firstSelection
->GetParent() != win
)
1261 firstSelection
->GetPosition(&firstX
, &firstY
);
1262 firstSelection
->GetSize(&firstW
, &firstH
);
1263 int centreX
= (int)(firstX
+ (firstW
/ 2));
1264 int centreY
= (int)(firstY
+ (firstH
/ 2));
1266 while ((node
= node
->Next()))
1268 wxControl
*item
= (wxControl
*)node
->Data();
1269 if (item
->GetParent() == win
)
1272 item
->GetPosition(&x
, &y
);
1273 item
->GetSize(&w
, &h
);
1279 case TOOLBAR_FORMAT_HORIZ
:
1282 newY
= (int)(centreY
- (h
/2.0));
1285 case TOOLBAR_FORMAT_VERT
:
1287 newX
= (int)(centreX
- (w
/2.0));
1291 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1297 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1303 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1305 newX
= firstX
+ firstW
- w
;
1309 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1312 newY
= firstY
+ firstH
- h
;
1320 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1321 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1323 item
->SetSize(newX
, newY
, w
, h
);
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
)
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
));
1335 resource
->SetSize(newX
, newY
, w
, h
);
1341 // Copy the first image's size to subsequent images
1342 void wxResourceManager::CopySize()
1344 wxWindow
*win
= FindParentOfSelection();
1348 wxNode
*node
= GetSelections().First();
1352 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1353 if (firstSelection
->GetParent() != win
)
1358 firstSelection
->GetPosition(&firstX
, &firstY
);
1359 firstSelection
->GetSize(&firstW
, &firstH
);
1361 while ((node
= node
->Next()))
1363 wxControl
*item
= (wxControl
*)node
->Data();
1364 if (item
->GetParent() == win
)
1366 item
->SetSize(-1, -1, firstW
, firstH
);
1368 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1369 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
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
)
1376 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1377 firstW
= sz
.x
; firstH
= sz
.y
;
1379 resource
->SetSize(resource
->GetX(), resource
->GetY(), firstW
, firstH
);
1386 void wxResourceManager::ToBackOrFront(bool toBack
)
1388 wxWindow
*win
= FindParentOfSelection();
1391 wxItemResource
*winResource
= FindResourceForWindow(win
);
1393 wxNode
*node
= GetSelections().First();
1396 wxControl
*item
= (wxControl
*)node
->Data();
1397 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1398 if (item
->GetParent() == win
)
1400 win
->GetChildren().DeleteObject(item
);
1402 winResource
->GetChildren().DeleteObject(itemResource
);
1405 win
->GetChildren().Insert(item
);
1407 winResource
->GetChildren().Insert(itemResource
);
1411 win
->GetChildren().Append(item
);
1413 winResource
->GetChildren().Append(itemResource
);
1416 node
= node
->Next();
1421 void wxResourceManager::AddSelection(wxWindow
*win
)
1423 if (!m_selections
.Member(win
))
1424 m_selections
.Append(win
);
1427 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1429 m_selections
.DeleteObject(win
);
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
)
1436 m_resourceTable
.BeginFind();
1438 while ((node
= m_resourceTable
.Next()))
1440 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1441 if (thisRes
->GetChildren().Member(res
))
1443 thisRes
->GetChildren().DeleteObject(res
);
1450 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1455 RemoveResourceFromParent(res
);
1457 wxNode
*node
= res
->GetChildren().First();
1460 wxNode
*next
= node
->Next();
1461 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1462 DeleteResource(child
);
1466 // If this is a button or message resource, delete the
1467 // associate bitmap resource if not being used.
1468 wxString
resType(res
->GetType());
1470 /* shouldn't have to do this now bitmaps are ref-counted
1471 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1473 PossiblyDeleteBitmapResource(res->GetValue4());
1477 // Remove symbol from table if appropriate
1478 if (!IsSymbolUsed(res
, res
->GetId()))
1480 m_symbolTable
.RemoveSymbol(res
->GetId());
1483 m_resourceTable
.Delete(res
->GetName());
1489 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1491 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1493 // Deselect and refresh window in case we leave selection
1495 wxControl
*item
= (wxControl
*)win
;
1496 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1497 if (childHandler
->IsSelected())
1499 RemoveSelection(item
);
1500 childHandler
->SelectItem(FALSE
);
1502 item
->GetParent()->Refresh();
1507 wxItemResource
*res
= FindResourceForWindow(win
);
1509 DisassociateResource(res
);
1510 DeleteResource(res
);
1511 UpdateResourceList();
1516 // Will eventually have bitmap type information, for different
1518 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1520 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1524 MakeUniqueName("bitmap", buf
);
1525 resource
= new wxItemResource
;
1526 resource
->SetType("wxBitmap");
1527 resource
->SetName(buf
);
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
);
1540 m_resourceTable
.AddResource(resource
);
1542 UpdateResourceList();
1545 return resource
->GetName();
1547 return wxEmptyString
;
1550 // Delete the bitmap resource if it isn't being used by another resource.
1551 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1553 if (!IsBitmapResourceUsed(resourceName
))
1555 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1556 DeleteResource(res
);
1557 UpdateResourceList();
1561 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1563 m_resourceTable
.BeginFind();
1565 while ((node
= m_resourceTable
.Next()))
1567 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1568 wxString
resType(res
->GetType());
1569 if (resType
== "wxDialog")
1571 wxNode
*node1
= res
->GetChildren().First();
1574 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1575 wxString
childResType(child
->GetType());
1577 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1578 child
->GetValue4() &&
1579 (strcmp(child
->GetValue4(), resourceName
) == 0))
1581 node1
= node1
->Next();
1588 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1589 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1591 if (!resource
|| (resource
->GetValue4() == ""))
1592 return wxEmptyString
;
1593 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1594 if (!bitmapResource
)
1595 return wxEmptyString
;
1597 wxNode
*node
= bitmapResource
->GetChildren().First();
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();
1606 node
= node
->Next();
1608 return wxEmptyString
;
1611 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1613 m_resourceTable
.BeginFind();
1615 while ((node
= m_resourceTable
.Next()))
1617 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1618 wxString
resType(res
->GetType());
1619 if (resType
== "wxBitmap")
1621 wxNode
*node1
= res
->GetChildren().First();
1624 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1625 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1627 node1
= node1
->Next();
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
1638 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1640 m_resourceTable
.BeginFind();
1642 while ((node
= m_resourceTable
.Next()))
1644 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1646 wxString
resType(res
->GetType());
1647 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1649 if ((res
!= thisResource
) && (res
->GetId() == id
))
1652 wxNode
*node1
= res
->GetChildren().First();
1655 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1656 if ((child
!= thisResource
) && (child
->GetId() == id
))
1658 node1
= node1
->Next();
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
)
1669 if (m_symbolTable
.SymbolExists(name
))
1671 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1678 // Change all integer ids that match oldId, to newId.
1679 // This is necessary if an id is changed for one resource - all resources
1681 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1683 m_resourceTable
.BeginFind();
1685 while ((node
= m_resourceTable
.Next()))
1687 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1689 wxString
resType(res
->GetType());
1690 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1692 if (res
->GetId() == oldId
)
1695 wxNode
*node1
= res
->GetChildren().First();
1698 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1699 if (child
->GetId() == oldId
)
1700 child
->SetId(newId
);
1702 node1
= node1
->Next();
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()
1713 bool repaired
= FALSE
;
1715 m_resourceTable
.BeginFind();
1717 while ((node
= m_resourceTable
.Next()))
1719 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1720 wxString
resType(res
->GetType());
1721 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1724 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1726 wxString newSymbolName
;
1727 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1729 if (res
->GetId() == 0)
1732 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1736 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1742 wxNode
*node1
= res
->GetChildren().First();
1745 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1747 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1749 wxString newSymbolName
;
1750 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1752 if (child
->GetId() == 0)
1754 child
->SetId(newId
);
1755 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1759 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1765 node1
= node1
->Next();
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
)
1778 wxItemResource
*resource
= FindResourceForWindow(win
);
1780 // Put the current window properties into the wxItemResource object
1782 wxWindowPropertyInfo
*newInfo
= NULL
;
1785 newInfo
= CreatePropertyInfoForWindow(win
);
1789 info
->InstantiateResource(resource
);
1791 wxWindow
*newWin
= NULL
;
1792 wxWindow
*parent
= win
->GetParent();
1793 wxItemResource
* parentResource
= NULL
;
1795 parentResource
= FindResourceForWindow(parent
);
1797 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1800 newWin
= FindWindowForResource(resource
);
1804 DisassociateResource(resource
);
1805 if (win
->GetEventHandler() != win
)
1806 win
->PopEventHandler(TRUE
);
1809 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1810 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1811 AssociateResource(resource
, newWin
);
1812 UpdateResourceList();
1816 info
->SetPropertyWindow(newWin
);
1824 // Delete resource highlighted in the listbox
1825 bool wxResourceManager::DeleteSelection()
1827 int sel
= m_editorResourceTree
->GetSelection();
1830 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1831 wxItemResource
*res
= data
->GetResource();
1832 wxWindow
*win
= FindWindowForResource(res
);
1835 DeleteResource(win
);
1837 UpdateResourceList();
1846 // Delete resource highlighted in the listbox
1847 bool wxResourceManager::RecreateSelection()
1849 wxNode
*node
= GetSelections().First();
1852 wxControl
*item
= (wxControl
*)node
->Data();
1853 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1854 wxNode
*next
= node
->Next();
1855 childHandler
->SelectItem(FALSE
);
1857 RemoveSelection(item
);
1859 RecreateWindowFromResource(item
);
1866 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
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()
1875 m_resourceTable
.BeginFind();
1877 while ((node
= m_resourceTable
.Next()))
1879 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1880 wxString
resType(res
->GetType());
1882 if (resType
== "wxDialog")
1884 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1886 InstantiateResourceFromWindow(res
, win
, TRUE
);
1888 else if (resType
== "wxPanel")
1890 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1892 InstantiateResourceFromWindow(res
, win
, TRUE
);
1898 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1900 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1901 info
->SetResource(resource
);
1902 info
->InstantiateResource(resource
);
1907 wxNode
*node
= resource
->GetChildren().First();
1910 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1911 wxWindow
*childWindow
= FindWindowForResource(child
);
1916 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
1917 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1920 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1921 node
= node
->Next();
1928 // Create a window information object for the give window
1929 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1931 wxWindowPropertyInfo
*info
= NULL
;
1932 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1934 info
= new wxScrollBarPropertyInfo(win
);
1936 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1938 info
= new wxGroupBoxPropertyInfo(win
);
1940 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1942 info
= new wxCheckBoxPropertyInfo(win
);
1944 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1946 info
= new wxSliderPropertyInfo(win
);
1948 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1950 info
= new wxGaugePropertyInfo(win
);
1952 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1954 info
= new wxListBoxPropertyInfo(win
);
1956 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1958 info
= new wxRadioBoxPropertyInfo(win
);
1960 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1962 info
= new wxRadioButtonPropertyInfo(win
);
1964 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
1966 info
= new wxComboBoxPropertyInfo(win
);
1968 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1970 info
= new wxChoicePropertyInfo(win
);
1972 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1974 info
= new wxBitmapButtonPropertyInfo(win
);
1976 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1978 info
= new wxButtonPropertyInfo(win
);
1980 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1982 info
= new wxStaticBitmapPropertyInfo(win
);
1984 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1986 info
= new wxStaticTextPropertyInfo(win
);
1988 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1990 info
= new wxTextPropertyInfo(win
);
1992 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1994 info
= new wxPanelPropertyInfo(win
);
1998 info
= new wxWindowPropertyInfo(win
);
2003 // Edit the given window
2004 void wxResourceManager::EditWindow(wxWindow
*win
)
2006 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2009 info
->SetResource(FindResourceForWindow(win
));
2010 wxString
str("Editing ");
2011 str
+= win
->GetClassInfo()->GetClassName();
2013 if (win
->GetName() != "")
2014 str
+= win
->GetName();
2016 str
+= "properties";
2017 info
->Edit(NULL
, str
);
2021 // Generate a window id and a first stab at a name
2022 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2024 m_symbolIdCounter
++;
2025 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2026 m_symbolIdCounter
++;
2028 int nameId
= m_symbolIdCounter
;
2031 str
.Printf("%d", nameId
);
2032 idName
= prefix
+ str
;
2034 while (m_symbolTable
.SymbolExists(idName
))
2037 str
.Printf("%d", nameId
);
2038 idName
= prefix
+ str
;
2041 return m_symbolIdCounter
;
2046 * Resource editor frame
2049 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
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
)
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
)
2074 wxResourceEditorFrame::~wxResourceEditorFrame()
2078 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2080 manager
->New(FALSE
);
2083 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2085 manager
->CreateNewPanel();
2088 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2093 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2095 manager
->Clear(TRUE
, FALSE
);
2098 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2103 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2108 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2110 manager
->Clear(TRUE
, FALSE
) ;
2114 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
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
);
2121 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2123 manager
->TestCurrentDialog(this);
2126 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2129 wxBeginBusyCursor();
2130 manager
->GetHelpController()->LoadFile();
2131 manager
->GetHelpController()->DisplayContents();
2136 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2138 manager
->DeleteSelection();
2141 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2143 manager
->RecreateSelection();
2146 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent
& event
)
2148 if (manager
->Modified())
2150 if (!manager
->Clear(TRUE
, FALSE
))
2161 manager
->m_resourceEditorWindowSize
.width
= w
;
2162 manager
->m_resourceEditorWindowSize
.height
= h
;
2165 GetPosition(&x
, &y
);
2167 manager
->m_resourceEditorWindowSize
.x
= x
;
2168 manager
->m_resourceEditorWindowSize
.y
= y
;
2170 manager
->SetEditorFrame(NULL
);
2171 manager
->SetEditorToolBar(NULL
);
2177 * Resource editor window that contains the dialog/panel being edited
2180 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2181 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2184 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2186 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2190 m_childWindow
= NULL
;
2192 SetBackgroundColour(* wxWHITE
);
2195 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2199 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2206 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2210 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2213 wxString
str(res
->GetTitle());
2215 ViewStart(& x
, & y
);
2217 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2219 dc
.SetBackgroundMode(wxTRANSPARENT
);
2220 dc
.SetTextForeground(wxColour(0, 0, 0));
2223 dc
.GetTextExtent(str
, & w
, & h
);
2225 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2230 // Popup menu callback
2231 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2233 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2237 switch (event
.GetInt())
2239 case OBJECT_MENU_EDIT
:
2241 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2244 case OBJECT_MENU_DELETE
:
2246 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2247 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2248 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2261 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2262 // EVT_PAINT(EditorToolBar::OnPaint)
2265 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2267 wxToolBar(frame
, -1, pos
, size
, style
)
2271 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2273 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2277 case TOOLBAR_LOAD_FILE
:
2284 manager
->CreateNewPanel();
2287 case TOOLBAR_SAVE_FILE
:
2295 wxBeginBusyCursor();
2296 manager
->GetHelpController()->LoadFile();
2297 manager
->GetHelpController()->DisplayContents();
2302 case TOOLBAR_FORMAT_HORIZ
:
2304 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2307 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2309 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2312 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2314 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2317 case TOOLBAR_FORMAT_VERT
:
2319 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2322 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2324 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2327 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2329 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2332 case TOOLBAR_COPY_SIZE
:
2334 manager
->CopySize();
2337 case TOOLBAR_TO_BACK
:
2339 manager
->ToBackOrFront(TRUE
);
2342 case TOOLBAR_TO_FRONT
:
2344 manager
->ToBackOrFront(FALSE
);
2353 void EditorToolBar::OnMouseEnter(int toolIndex
)
2355 wxFrame
*frame
= (wxFrame
*)GetParent();
2363 case TOOLBAR_LOAD_FILE
:
2364 frame
->SetStatusText("Load project file");
2366 case TOOLBAR_SAVE_FILE
:
2367 frame
->SetStatusText("Save project file");
2370 frame
->SetStatusText("Create a new resource");
2372 case TOOLBAR_FORMAT_HORIZ
:
2373 frame
->SetStatusText("Align items horizontally");
2375 case TOOLBAR_FORMAT_VERT
:
2376 frame
->SetStatusText("Align items vertically");
2378 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2379 frame
->SetStatusText("Left-align items");
2381 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2382 frame
->SetStatusText("Right-align items");
2384 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2385 frame
->SetStatusText("Top-align items");
2387 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2388 frame
->SetStatusText("Bottom-align items");
2390 case TOOLBAR_COPY_SIZE
:
2391 frame
->SetStatusText("Copy size from first selection");
2393 case TOOLBAR_TO_FRONT
:
2394 frame
->SetStatusText("Put image to front");
2396 case TOOLBAR_TO_BACK
:
2397 frame
->SetStatusText("Put image to back");
2400 frame
->SetStatusText("Display help contents");
2406 else frame
->SetStatusText("");