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 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
59 #if defined(__WXGTK__) || defined(__WXMOTIF__)
60 #include "bitmaps/load.xpm"
61 #include "bitmaps/save.xpm"
62 #include "bitmaps/new.xpm"
63 #include "bitmaps/vert.xpm"
64 #include "bitmaps/alignt.xpm"
65 #include "bitmaps/alignb.xpm"
66 #include "bitmaps/horiz.xpm"
67 #include "bitmaps/alignl.xpm"
68 #include "bitmaps/alignr.xpm"
69 #include "bitmaps/copysize.xpm"
70 #include "bitmaps/tofront.xpm"
71 #include "bitmaps/toback.xpm"
72 #include "bitmaps/help.xpm"
73 #include "bitmaps/wxwin.xpm"
75 #include "bitmaps/dialog.xpm"
76 #include "bitmaps/folder1.xpm"
77 #include "bitmaps/folder2.xpm"
78 #include "bitmaps/buttonsm.xpm"
85 wxResourceManager::wxResourceManager():
86 m_imageList(16, 16, TRUE
)
88 sm_currentResourceManager
= this;
92 m_editorResourceTree
= NULL
;
93 m_editorControlList
= NULL
;
95 m_symbolIdCounter
= 99;
97 m_currentFilename
= "";
98 m_symbolFilename
= "";
99 m_editorToolBar
= NULL
;
101 // Default window positions
102 m_resourceEditorWindowSize
.width
= 500;
103 m_resourceEditorWindowSize
.height
= 450;
105 m_resourceEditorWindowSize
.x
= 0;
106 m_resourceEditorWindowSize
.y
= 0;
108 m_propertyWindowSize
.width
= 300;
109 m_propertyWindowSize
.height
= 300;
112 m_helpController
= NULL
;
115 m_bitmapImage
= NULL
;
116 m_rootDialogItem
= 0;
119 wxResourceManager::~wxResourceManager()
121 sm_currentResourceManager
= NULL
;
125 if (m_helpController
)
127 m_helpController
->Quit();
128 delete m_helpController
;
129 m_helpController
= NULL
;
133 delete m_bitmapImage
;
137 bool wxResourceManager::Initialize()
139 // Set up the resource filename for each platform.
140 // TODO: This shold be replaced by wxConfig usage.
142 // dialoged.ini in the Windows directory
143 wxString windowsDir
= wxGetOSDirectory();
144 windowsDir
+= "\\dialoged.ini" ;
146 m_optionsResourceFilename
= windowsDir
;
147 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
148 wxGetHomeDir( &m_optionsResourceFilename
);
149 m_optionsResourceFilename
+= "/.dialogedrc";
151 #error "Unsupported platform."
157 m_helpController
= new wxHelpController
;
158 m_helpController
->Initialize("dialoged");
161 m_popupMenu
= new wxMenu
;
162 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
163 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
168 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
170 #if defined(__WXGTK__) || defined(__WXMOTIF__)
171 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
175 // Initialize the image list icons
177 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
178 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
179 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
180 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
182 wxIcon
icon1( dialog_xpm
);
183 wxIcon
icon2( folder1_xpm
);
184 wxIcon
icon3( folder2_xpm
);
185 wxIcon
icon4( buttonsm_xpm
);
187 m_imageList
.Add(icon1
);
188 m_imageList
.Add(icon2
);
189 m_imageList
.Add(icon3
);
190 m_imageList
.Add(icon4
);
192 m_symbolTable
.AddStandardSymbols();
197 bool wxResourceManager::LoadOptions()
199 wxConfig
config("DialogEd", "wxWindows");
201 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
202 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
203 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
204 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
205 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
206 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
207 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
208 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
211 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
212 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
213 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
214 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
215 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
216 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
217 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
218 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
223 bool wxResourceManager::SaveOptions()
225 wxConfig
config("DialogEd", "wxWindows");
227 config
.Write("editorWindowX", (long) m_resourceEditorWindowSize
.x
);
228 config
.Write("editorWindowY", (long) m_resourceEditorWindowSize
.y
);
229 config
.Write("editorWindowWidth", (long) m_resourceEditorWindowSize
.width
);
230 config
.Write("editorWindowHeight", (long) m_resourceEditorWindowSize
.height
);
231 config
.Write("propertyWindowX", (long) m_propertyWindowSize
.x
);
232 config
.Write("propertyWindowY", (long) m_propertyWindowSize
.y
);
233 config
.Write("propertyWindowWidth", (long) m_propertyWindowSize
.width
);
234 config
.Write("propertyWindowHeight", (long) m_propertyWindowSize
.height
);
236 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
237 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
238 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
239 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
241 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
242 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
243 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
244 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
250 // Show or hide the resource editor frame, which displays a list
251 // of resources with ability to edit them.
252 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
258 m_editorFrame
->Iconize(FALSE
);
259 m_editorFrame
->Show(TRUE
);
262 m_editorFrame
= OnCreateEditorFrame(title
);
264 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
265 m_editorFrame
->SetMenuBar(menuBar
);
267 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
268 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
269 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
271 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
273 m_editorResourceTree
->SetImageList(& m_imageList
);
275 // Constraints for toolbar
276 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
277 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
278 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
279 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
280 c
->bottom
.Unconstrained();
281 c
->width
.Unconstrained();
282 c
->height
.Absolute(28);
283 m_editorToolBar
->SetConstraints(c
);
285 // Constraints for listbox
286 c
= new wxLayoutConstraints
;
287 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
288 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
289 c
->right
.Absolute (150);
290 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
291 c
->width
.Unconstrained();
292 c
->height
.Unconstrained();
293 m_editorResourceTree
->SetConstraints(c
);
295 // Constraints for panel
296 c
= new wxLayoutConstraints
;
297 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
298 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
299 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
300 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
301 c
->width
.Unconstrained();
302 c
->height
.Unconstrained();
303 m_editorPanel
->SetConstraints(c
);
305 // Constraints for control list (bottom window)
306 c
= new wxLayoutConstraints
;
307 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
308 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
309 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
310 c
->width
.Unconstrained();
311 #if defined(__WXGTK__) || defined(__WXMOTIF__)
312 c
->height
.Absolute(120);
314 c
->height
.Absolute(60);
317 m_editorControlList
->SetConstraints(c
);
319 m_editorFrame
->SetAutoLayout(TRUE
);
321 UpdateResourceList();
323 m_editorFrame
->Show(TRUE
);
328 if (m_editorFrame
->Close())
330 m_editorFrame
= NULL
;
331 m_editorPanel
= NULL
;
337 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
341 if (filename
== wxString(""))
342 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
345 wxString
str("wxWindows Dialog Editor - ");
346 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
348 m_editorFrame
->SetTitle(str
);
353 bool wxResourceManager::Save()
355 if (m_currentFilename
== wxString(""))
358 return Save(m_currentFilename
);
361 bool wxResourceManager::Save(const wxString
& filename
)
363 // Ensure all visible windows are saved to their resources
364 m_currentFilename
= filename
;
365 SetFrameTitle(m_currentFilename
);
366 InstantiateAllResourcesFromWindows();
367 if (m_resourceTable
.Save(filename
))
369 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
377 bool wxResourceManager::SaveAs()
379 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
380 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
, wxTheApp
->GetTopWindow()));
382 if (s
.IsNull() || s
== "")
385 m_currentFilename
= s
;
386 wxStripExtension(m_currentFilename
);
387 m_currentFilename
+= ".wxr";
389 // Construct include filename from this file
390 m_symbolFilename
= m_currentFilename
;
392 wxStripExtension(m_symbolFilename
);
393 m_symbolFilename
+= ".h";
395 Save(m_currentFilename
);
399 bool wxResourceManager::SaveIfModified()
406 bool wxResourceManager::Load(const wxString
& filename
)
408 return New(TRUE
, filename
);
411 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
413 if (!Clear(TRUE
, FALSE
))
416 m_symbolTable
.AddStandardSymbols();
420 wxString str
= filename
;
421 if (str
== wxString(""))
423 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, wxTheApp
->GetTopWindow()));
424 if (!f
.IsNull() && f
!= "")
430 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
432 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
435 m_currentFilename
= str
;
437 SetFrameTitle(m_currentFilename
);
439 UpdateResourceList();
441 // Construct include filename from this file
442 m_symbolFilename
= m_currentFilename
;
444 wxStripExtension(m_symbolFilename
);
445 m_symbolFilename
+= ".h";
447 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
449 wxString
str("Could not find include file ");
450 str
+= m_symbolFilename
;
451 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
452 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
453 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
455 m_symbolIdCounter
= 99;
459 // Set the id counter to the last known id
460 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
463 // Now check in case some (or all) resources don't have resource ids, or they
464 // don't match the .h file, or something of that nature.
465 bool altered
= RepairResourceIds();
468 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
469 "Dialog Editor Warning", wxOK
);
480 m_currentFilename
= "";
487 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
489 if (!force
&& Modified())
491 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
495 if (!SaveIfModified())
501 ClearCurrentDialog();
502 DisassociateWindows();
504 m_symbolTable
.Clear();
505 m_resourceTable
.ClearTable();
506 UpdateResourceList();
511 bool wxResourceManager::DisassociateWindows()
513 m_resourceTable
.BeginFind();
515 while ((node
= m_resourceTable
.Next()))
517 wxItemResource
*res
= (wxItemResource
*)node
->Data();
518 DisassociateResource(res
);
524 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
526 if (!m_resourceAssociations
.Get((long)resource
))
527 m_resourceAssociations
.Put((long)resource
, win
);
529 wxNode
*node
= resource
->GetChildren().First();
532 wxItemResource
*child
= (wxItemResource
*)node
->Data();
533 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
535 childWindow
= win
->FindWindow(child
->GetName());
537 AssociateResource(child
, childWindow
);
541 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
542 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
549 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
551 wxWindow
*win
= FindWindowForResource(resource
);
555 // Disassociate children of window
556 wxNode
*node
= win
->GetChildren().First();
559 wxWindow
*child
= (wxWindow
*)node
->Data();
560 if (child
->IsKindOf(CLASSINFO(wxControl
)))
561 DisassociateResource(child
);
565 RemoveSelection(win
);
566 m_resourceAssociations
.Delete((long)resource
);
570 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
572 wxItemResource
*res
= FindResourceForWindow(win
);
574 return DisassociateResource(res
);
579 // Saves the window info into the resource, and deletes the
580 // handler. Doesn't actually disassociate the window from
581 // the resources. Replaces OnClose.
582 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
584 wxItemResource
*res
= FindResourceForWindow(win
);
586 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
588 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
589 win
->PopEventHandler();
591 // Now reset all child event handlers
592 wxNode
*node
= win
->GetChildren().First();
595 wxWindow
*child
= (wxWindow
*)node
->Data();
596 wxEvtHandler
*childHandler
= child
->GetEventHandler();
597 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
599 child
->PopEventHandler(TRUE
);
607 win
->PopEventHandler(TRUE
);
610 // Save the information
611 InstantiateResourceFromWindow(res
, win
, TRUE
);
613 // DisassociateResource(win);
618 // Destroys the window. If this is the 'current' panel, NULLs the
620 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
622 bool clearDisplay
= FALSE
;
623 if (m_editorPanel
->m_childWindow
== win
)
625 m_editorPanel
->m_childWindow
= NULL
;
632 m_editorPanel
->Clear();
637 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
639 m_resourceAssociations
.BeginFind();
641 while ((node
= m_resourceAssociations
.Next()))
643 wxWindow
*w
= (wxWindow
*)node
->Data();
646 return (wxItemResource
*)node
->GetKeyInteger();
652 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
654 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
658 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
662 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
665 if (!m_resourceTable
.FindResource(buf
))
670 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
673 int frameWidth = 420;
674 int frameHeight = 300;
677 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
678 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
679 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
680 wxDEFAULT_FRAME_STYLE
);
682 frame
->CreateStatusBar(1);
684 frame
->SetAutoLayout(TRUE
);
686 frame
->SetIcon(wxIcon("DIALOGEDICON"));
691 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
693 wxMenuBar
*menuBar
= new wxMenuBar
;
695 wxMenu
*fileMenu
= new wxMenu
;
696 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
697 fileMenu
->AppendSeparator();
698 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
699 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
700 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
701 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
702 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
703 fileMenu
->AppendSeparator();
704 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
706 wxMenu
*editMenu
= new wxMenu
;
707 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
708 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
709 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
711 wxMenu
*helpMenu
= new wxMenu
;
712 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
713 helpMenu
->AppendSeparator();
714 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
716 menuBar
->Append(fileMenu
, "&File");
717 menuBar
->Append(editMenu
, "&Edit");
718 menuBar
->Append(helpMenu
, "&Help");
723 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
725 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
726 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
733 panel
->SetScrollbars(10, 10, 100, 100);
738 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
740 // Load palette bitmaps
742 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
743 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
744 wxBitmap
ToolbarNewBitmap("NEWTOOL");
745 wxBitmap
ToolbarVertBitmap("VERTTOOL");
746 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
747 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
748 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
749 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
750 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
751 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
752 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
753 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
754 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
756 #if defined(__WXGTK__) || defined(__WXMOTIF__)
757 wxBitmap
ToolbarLoadBitmap( load_xpm
);
758 wxBitmap
ToolbarSaveBitmap( save_xpm
);
759 wxBitmap
ToolbarNewBitmap( new_xpm
);
760 wxBitmap
ToolbarVertBitmap( vert_xpm
);
761 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
762 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
763 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
764 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
765 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
766 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
767 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
768 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
769 wxBitmap
ToolbarHelpBitmap( help_xpm
);
772 // Create the toolbar
773 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
774 toolbar
->SetMargins(2, 2);
781 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
786 toolbar
->AddSeparator();
787 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
788 FALSE
, currentX
, -1, NULL
, "New dialog");
789 currentX
+= width
+ dx
;
790 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
791 FALSE
, currentX
, -1, NULL
, "Load");
792 currentX
+= width
+ dx
;
793 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
794 FALSE
, currentX
, -1, NULL
, "Save");
795 currentX
+= width
+ dx
+ gap
;
796 toolbar
->AddSeparator();
797 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
798 FALSE
, currentX
, -1, NULL
, "Horizontal align");
799 currentX
+= width
+ dx
;
800 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
801 FALSE
, currentX
, -1, NULL
, "Top align");
802 currentX
+= width
+ dx
;
803 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
804 FALSE
, currentX
, -1, NULL
, "Bottom align");
805 currentX
+= width
+ dx
;
806 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
807 FALSE
, currentX
, -1, NULL
, "Vertical align");
808 currentX
+= width
+ dx
;
809 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
810 FALSE
, currentX
, -1, NULL
, "Left align");
811 currentX
+= width
+ dx
;
812 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
813 FALSE
, currentX
, -1, NULL
, "Right align");
814 currentX
+= width
+ dx
;
815 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
816 FALSE
, currentX
, -1, NULL
, "Copy size");
817 currentX
+= width
+ dx
+ gap
;
818 toolbar
->AddSeparator();
819 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
820 FALSE
, currentX
, -1, NULL
, "To front");
821 currentX
+= width
+ dx
;
822 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
823 FALSE
, currentX
, -1, NULL
, "To back");
824 currentX
+= width
+ dx
+ gap
;
826 toolbar
->AddSeparator();
827 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
828 FALSE
, currentX
, -1, NULL
, "Help");
829 currentX
+= width
+ dx
;
836 void wxResourceManager::UpdateResourceList()
838 if (!m_editorResourceTree
)
841 m_editorResourceTree
->SetInvalid(TRUE
);
842 m_editorResourceTree
->DeleteAllItems();
844 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
846 m_resourceTable
.BeginFind();
848 while ((node
= m_resourceTable
.Next()))
850 wxItemResource
*res
= (wxItemResource
*)node
->Data();
851 wxString
resType(res
->GetType());
852 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
854 AddItemsRecursively(id
, res
);
857 m_editorResourceTree
->Expand(id
);
858 m_editorResourceTree
->SetInvalid(FALSE
);
861 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
863 wxString
theString("");
864 theString
= resource
->GetName();
867 wxString
resType(resource
->GetType());
868 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
873 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
875 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
877 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
879 wxNode
*node
= resource
->GetChildren().First();
882 wxItemResource
*res
= (wxItemResource
*)node
->Data();
883 AddItemsRecursively(id
, res
);
887 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
890 bool wxResourceManager::EditSelectedResource()
892 int sel
= m_editorResourceTree
->GetSelection();
895 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
896 wxItemResource
*res
= data
->GetResource();
902 bool wxResourceManager::Edit(wxItemResource
*res
)
904 ClearCurrentDialog();
906 wxString
resType(res
->GetType());
907 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
911 wxMessageBox("Should not find panel in wxResourceManager::Edit");
916 // long style = res->GetStyle();
917 // res->SetStyle(style|wxRAISED_BORDER);
919 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
922 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
924 panel
->PushEventHandler(handler
);
926 // res->SetStyle(style);
927 handler
->AddChildHandlers(); // Add event handlers for all controls
928 AssociateResource(res
, panel
);
930 m_editorPanel
->m_childWindow
= panel
;
931 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
935 wxClientDC
dc(m_editorPanel
);
936 m_editorPanel
->DrawTitle(dc
);
941 bool wxResourceManager::CreateNewPanel()
943 ClearCurrentDialog();
946 MakeUniqueName("dialog", buf
);
948 wxItemResource
*resource
= new wxItemResource
;
949 resource
->SetType("wxDialog");
950 resource
->SetName(buf
);
951 resource
->SetTitle(buf
);
952 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
953 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
956 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
959 // This is now guaranteed to be unique, so just add to symbol table
960 m_symbolTable
.AddSymbol(newIdName
, id
);
962 m_resourceTable
.AddResource(resource
);
964 wxSize
size(400, 300);
966 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
967 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
968 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
969 m_editorPanel
->m_childWindow
= panel
;
971 resource
->SetStyle(panel
->GetWindowStyleFlag());
973 // Store dialog units in resource
974 size
= panel
->ConvertPixelsToDialog(size
);
976 resource
->SetSize(10, 10, size
.x
, size
.y
);
978 // For editing in situ we will need to use the hash table to ensure
979 // we don't dereference invalid pointers.
980 // resourceWindowTable.Put((long)resource, panel);
982 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
984 panel
->PushEventHandler(handler
);
986 AssociateResource(resource
, panel
);
987 UpdateResourceList();
990 m_editorPanel
->m_childWindow
->Refresh();
994 wxClientDC
dc(m_editorPanel
);
995 m_editorPanel
->DrawTitle(dc
);
1000 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1003 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1008 wxItemResource
*res
= new wxItemResource
;
1009 wxControl
*newItem
= NULL
;
1011 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1013 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1014 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1016 else res
->SetSize(x
, y
, -1, -1);
1018 res
->SetType(iType
);
1022 wxString
itemType(iType
);
1024 if (itemType
== "wxButton")
1026 prefix
= "ID_BUTTON";
1027 MakeUniqueName("button", buf
);
1030 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1032 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1034 if (itemType
== "wxBitmapButton")
1036 prefix
= "ID_BITMAPBUTTON";
1037 MakeUniqueName("button", buf
);
1039 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1041 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1043 prefix
= "ID_STATIC";
1044 MakeUniqueName("statictext", buf
);
1047 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1049 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1051 else if (itemType
== "wxStaticBitmap")
1053 prefix
= "ID_STATICBITMAP";
1054 MakeUniqueName("static", buf
);
1056 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1058 else if (itemType
== "wxCheckBox")
1060 prefix
= "ID_CHECKBOX";
1061 MakeUniqueName("checkbox", buf
);
1063 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1065 else if (itemType
== "wxListBox")
1067 prefix
= "ID_LISTBOX";
1068 MakeUniqueName("listbox", buf
);
1070 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1072 else if (itemType
== "wxRadioBox")
1074 prefix
= "ID_RADIOBOX";
1075 MakeUniqueName("radiobox", buf
);
1077 wxString names
[] = { "One", "Two" };
1078 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1079 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1080 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1082 else if (itemType
== "wxRadioButton")
1084 prefix
= "ID_RADIOBUTTON";
1085 MakeUniqueName("radiobutton", buf
);
1087 wxString names
[] = { "One", "Two" };
1088 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1089 0, wxDefaultValidator
, buf
);
1091 else if (itemType
== "wxChoice")
1093 prefix
= "ID_CHOICE";
1094 MakeUniqueName("choice", buf
);
1096 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1098 else if (itemType
== "wxComboBox")
1100 prefix
= "ID_COMBOBOX";
1101 MakeUniqueName("combobox", buf
);
1103 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1105 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1107 prefix
= "ID_STATICBOX";
1108 MakeUniqueName("staticbox", buf
);
1110 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1112 else if (itemType
== "wxGauge")
1114 prefix
= "ID_GAUGE";
1115 MakeUniqueName("gauge", buf
);
1117 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1119 else if (itemType
== "wxSlider")
1121 prefix
= "ID_SLIDER";
1122 MakeUniqueName("slider", buf
);
1124 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1126 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1128 prefix
= "ID_TEXTCTRL";
1129 MakeUniqueName("textctrl", buf
);
1131 res
->SetType("wxTextCtrl");
1132 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1134 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1136 prefix
= "ID_TEXTCTRL";
1137 MakeUniqueName("textctrl", buf
);
1139 res
->SetType("wxTextCtrl");
1140 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1142 else if (itemType
== "wxScrollBar")
1144 prefix
= "ID_SCROLLBAR";
1145 MakeUniqueName("scrollbar", buf
);
1147 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1152 int actualW
, actualH
;
1153 newItem
->GetSize(&actualW
, &actualH
);
1154 wxSize
actualSize(actualW
, actualH
);
1156 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1158 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1160 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1163 int id
= GenerateWindowId(prefix
, newIdName
);
1166 // This is now guaranteed to be unique, so just add to symbol table
1167 m_symbolTable
.AddSymbol(newIdName
, id
);
1169 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1171 res
->SetStyle(newItem
->GetWindowStyleFlag());
1172 AssociateResource(res
, newItem
);
1173 panelResource
->GetChildren().Append(res
);
1175 UpdateResourceList();
1180 void wxResourceManager::ClearCurrentDialog()
1182 if (m_editorPanel
->m_childWindow
)
1184 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1185 DisassociateResource(m_editorPanel
->m_childWindow
);
1186 DeleteWindow(m_editorPanel
->m_childWindow
);
1187 m_editorPanel
->m_childWindow
= NULL
;
1188 m_editorPanel
->Clear();
1192 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1194 if (m_editorPanel
->m_childWindow
)
1196 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1200 // Make sure the resources are up-to-date w.r.t. the window
1201 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1203 wxDialog
* dialog
= new wxDialog
;
1204 bool success
= FALSE
;
1205 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1208 dialog
->ShowModal();
1216 // Find the first dialog or panel for which
1217 // there is a selected panel item.
1218 wxWindow
*wxResourceManager::FindParentOfSelection()
1220 m_resourceTable
.BeginFind();
1222 while ((node
= m_resourceTable
.Next()))
1224 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1225 wxWindow
*win
= FindWindowForResource(res
);
1228 wxNode
*node1
= win
->GetChildren().First();
1231 wxControl
*item
= (wxControl
*)node1
->Data();
1232 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1233 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1235 node1
= node1
->Next();
1242 // Format the panel items according to 'flag'
1243 void wxResourceManager::AlignItems(int flag
)
1245 wxWindow
*win
= FindParentOfSelection();
1249 wxNode
*node
= GetSelections().First();
1253 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1254 if (firstSelection
->GetParent() != win
)
1259 firstSelection
->GetPosition(&firstX
, &firstY
);
1260 firstSelection
->GetSize(&firstW
, &firstH
);
1261 int centreX
= (int)(firstX
+ (firstW
/ 2));
1262 int centreY
= (int)(firstY
+ (firstH
/ 2));
1264 while ((node
= node
->Next()))
1266 wxControl
*item
= (wxControl
*)node
->Data();
1267 if (item
->GetParent() == win
)
1270 item
->GetPosition(&x
, &y
);
1271 item
->GetSize(&w
, &h
);
1277 case TOOLBAR_FORMAT_HORIZ
:
1280 newY
= (int)(centreY
- (h
/2.0));
1283 case TOOLBAR_FORMAT_VERT
:
1285 newX
= (int)(centreX
- (w
/2.0));
1289 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1295 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1301 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1303 newX
= firstX
+ firstW
- w
;
1307 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1310 newY
= firstY
+ firstH
- h
;
1318 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1319 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1321 item
->SetSize(newX
, newY
, w
, h
);
1323 // Also update the associated resource
1324 // We need to convert to dialog units if this is not a dialog or panel, but
1325 // the parent resource specifies dialog units.
1326 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1328 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1329 newX
= pt
.x
; newY
= pt
.y
;
1330 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1333 resource
->SetSize(newX
, newY
, w
, h
);
1339 // Copy the first image's size to subsequent images
1340 void wxResourceManager::CopySize()
1342 wxWindow
*win
= FindParentOfSelection();
1346 wxNode
*node
= GetSelections().First();
1350 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1351 if (firstSelection
->GetParent() != win
)
1356 firstSelection
->GetPosition(&firstX
, &firstY
);
1357 firstSelection
->GetSize(&firstW
, &firstH
);
1359 while ((node
= node
->Next()))
1361 wxControl
*item
= (wxControl
*)node
->Data();
1362 if (item
->GetParent() == win
)
1364 item
->SetSize(-1, -1, firstW
, firstH
);
1366 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1367 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1369 // Also update the associated resource
1370 // We need to convert to dialog units if this is not a dialog or panel, but
1371 // the parent resource specifies dialog units.
1372 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1374 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1375 firstW
= sz
.x
; firstH
= sz
.y
;
1377 resource
->SetSize(resource
->GetX(), resource
->GetY(), firstW
, firstH
);
1384 void wxResourceManager::ToBackOrFront(bool toBack
)
1386 wxWindow
*win
= FindParentOfSelection();
1389 wxItemResource
*winResource
= FindResourceForWindow(win
);
1391 wxNode
*node
= GetSelections().First();
1394 wxControl
*item
= (wxControl
*)node
->Data();
1395 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1396 if (item
->GetParent() == win
)
1398 win
->GetChildren().DeleteObject(item
);
1400 winResource
->GetChildren().DeleteObject(itemResource
);
1403 win
->GetChildren().Insert(item
);
1405 winResource
->GetChildren().Insert(itemResource
);
1409 win
->GetChildren().Append(item
);
1411 winResource
->GetChildren().Append(itemResource
);
1414 node
= node
->Next();
1419 void wxResourceManager::AddSelection(wxWindow
*win
)
1421 if (!m_selections
.Member(win
))
1422 m_selections
.Append(win
);
1425 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1427 m_selections
.DeleteObject(win
);
1430 // Need to search through resource table removing this from
1431 // any resource which has this as a parent.
1432 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1434 m_resourceTable
.BeginFind();
1436 while ((node
= m_resourceTable
.Next()))
1438 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1439 if (thisRes
->GetChildren().Member(res
))
1441 thisRes
->GetChildren().DeleteObject(res
);
1448 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1453 RemoveResourceFromParent(res
);
1455 wxNode
*node
= res
->GetChildren().First();
1458 wxNode
*next
= node
->Next();
1459 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1460 DeleteResource(child
);
1464 // If this is a button or message resource, delete the
1465 // associate bitmap resource if not being used.
1466 wxString
resType(res
->GetType());
1468 /* shouldn't have to do this now bitmaps are ref-counted
1469 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1471 PossiblyDeleteBitmapResource(res->GetValue4());
1475 // Remove symbol from table if appropriate
1476 if (!IsSymbolUsed(res
, res
->GetId()))
1478 m_symbolTable
.RemoveSymbol(res
->GetId());
1481 m_resourceTable
.Delete(res
->GetName());
1487 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1489 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1491 // Deselect and refresh window in case we leave selection
1493 wxControl
*item
= (wxControl
*)win
;
1494 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1495 if (childHandler
->IsSelected())
1497 RemoveSelection(item
);
1498 childHandler
->SelectItem(FALSE
);
1500 item
->GetParent()->Refresh();
1505 wxItemResource
*res
= FindResourceForWindow(win
);
1507 DisassociateResource(res
);
1508 DeleteResource(res
);
1509 UpdateResourceList();
1514 // Will eventually have bitmap type information, for different
1516 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1518 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1522 MakeUniqueName("bitmap", buf
);
1523 resource
= new wxItemResource
;
1524 resource
->SetType("wxBitmap");
1525 resource
->SetName(buf
);
1527 // A bitmap resource has one or more children, specifying
1528 // alternative bitmaps.
1529 wxItemResource
*child
= new wxItemResource
;
1530 child
->SetType("wxBitmap");
1531 child
->SetName(filename
);
1532 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1533 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1534 child
->SetValue3(0); // Depth
1535 child
->SetSize(0,0,0,0);
1536 resource
->GetChildren().Append(child
);
1538 m_resourceTable
.AddResource(resource
);
1540 UpdateResourceList();
1543 return resource
->GetName();
1545 return wxEmptyString
;
1548 // Delete the bitmap resource if it isn't being used by another resource.
1549 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1551 if (!IsBitmapResourceUsed(resourceName
))
1553 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1554 DeleteResource(res
);
1555 UpdateResourceList();
1559 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1561 m_resourceTable
.BeginFind();
1563 while ((node
= m_resourceTable
.Next()))
1565 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1566 wxString
resType(res
->GetType());
1567 if (resType
== "wxDialog")
1569 wxNode
*node1
= res
->GetChildren().First();
1572 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1573 wxString
childResType(child
->GetType());
1575 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1576 child
->GetValue4() &&
1577 (strcmp(child
->GetValue4(), resourceName
) == 0))
1579 node1
= node1
->Next();
1586 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1587 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1589 if (!resource
|| (resource
->GetValue4() == ""))
1590 return wxEmptyString
;
1591 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1592 if (!bitmapResource
)
1593 return wxEmptyString
;
1595 wxNode
*node
= bitmapResource
->GetChildren().First();
1598 // Eventually augment this to return a bitmap of the right kind or something...
1599 // Maybe the root of the filename remains the same, so it doesn't matter which we
1600 // pick up. Otherwise how do we specify multiple filenames... too boring...
1601 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1602 return child
->GetName();
1604 node
= node
->Next();
1606 return wxEmptyString
;
1609 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1611 m_resourceTable
.BeginFind();
1613 while ((node
= m_resourceTable
.Next()))
1615 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1616 wxString
resType(res
->GetType());
1617 if (resType
== "wxBitmap")
1619 wxNode
*node1
= res
->GetChildren().First();
1622 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1623 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1625 node1
= node1
->Next();
1632 // Is this window identifier symbol in use?
1633 // Let's assume that we can't have 2 names for the same integer id.
1634 // Therefore we can tell by the integer id whether the symbol is
1636 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1638 m_resourceTable
.BeginFind();
1640 while ((node
= m_resourceTable
.Next()))
1642 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1644 wxString
resType(res
->GetType());
1645 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1647 if ((res
!= thisResource
) && (res
->GetId() == id
))
1650 wxNode
*node1
= res
->GetChildren().First();
1653 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1654 if ((child
!= thisResource
) && (child
->GetId() == id
))
1656 node1
= node1
->Next();
1663 // Is this window identifier compatible with the given name? (i.e.
1664 // does it already exist under a different name)
1665 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1667 if (m_symbolTable
.SymbolExists(name
))
1669 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1676 // Change all integer ids that match oldId, to newId.
1677 // This is necessary if an id is changed for one resource - all resources
1679 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1681 m_resourceTable
.BeginFind();
1683 while ((node
= m_resourceTable
.Next()))
1685 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1687 wxString
resType(res
->GetType());
1688 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1690 if (res
->GetId() == oldId
)
1693 wxNode
*node1
= res
->GetChildren().First();
1696 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1697 if (child
->GetId() == oldId
)
1698 child
->SetId(newId
);
1700 node1
= node1
->Next();
1706 // If any resource ids were missing (or their symbol was missing),
1707 // repair them i.e. give them new ids. Returns TRUE if any resource
1708 // needed repairing.
1709 bool wxResourceManager::RepairResourceIds()
1711 bool repaired
= FALSE
;
1713 m_resourceTable
.BeginFind();
1715 while ((node
= m_resourceTable
.Next()))
1717 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1718 wxString
resType(res
->GetType());
1719 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1722 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1724 wxString newSymbolName
;
1725 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1727 if (res
->GetId() == 0)
1730 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1734 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1740 wxNode
*node1
= res
->GetChildren().First();
1743 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1745 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1747 wxString newSymbolName
;
1748 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1750 if (child
->GetId() == 0)
1752 child
->SetId(newId
);
1753 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1757 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1763 node1
= node1
->Next();
1771 // Deletes 'win' and creates a new window from the resource that
1772 // was associated with it. E.g. if you can't change properties on the
1773 // fly, you'll need to delete the window and create it again.
1774 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1776 wxItemResource
*resource
= FindResourceForWindow(win
);
1778 // Put the current window properties into the wxItemResource object
1780 wxWindowPropertyInfo
*newInfo
= NULL
;
1783 newInfo
= CreatePropertyInfoForWindow(win
);
1787 info
->InstantiateResource(resource
);
1789 wxWindow
*newWin
= NULL
;
1790 wxWindow
*parent
= win
->GetParent();
1791 wxItemResource
* parentResource
= NULL
;
1793 parentResource
= FindResourceForWindow(parent
);
1795 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1798 newWin
= FindWindowForResource(resource
);
1802 DisassociateResource(resource
);
1803 if (win
->GetEventHandler() != win
)
1804 win
->PopEventHandler(TRUE
);
1807 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1808 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1809 AssociateResource(resource
, newWin
);
1810 UpdateResourceList();
1814 info
->SetPropertyWindow(newWin
);
1822 // Delete resource highlighted in the listbox
1823 bool wxResourceManager::DeleteSelection()
1825 int sel
= m_editorResourceTree
->GetSelection();
1828 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1829 wxItemResource
*res
= data
->GetResource();
1830 wxWindow
*win
= FindWindowForResource(res
);
1833 DeleteResource(win
);
1835 UpdateResourceList();
1844 // Delete resource highlighted in the listbox
1845 bool wxResourceManager::RecreateSelection()
1847 wxNode
*node
= GetSelections().First();
1850 wxControl
*item
= (wxControl
*)node
->Data();
1851 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1852 wxNode
*next
= node
->Next();
1853 childHandler
->SelectItem(FALSE
);
1855 RemoveSelection(item
);
1857 RecreateWindowFromResource(item
);
1864 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
1869 // Ensures that all currently shown windows are saved to resources,
1870 // e.g. just before writing to a .wxr file.
1871 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1873 m_resourceTable
.BeginFind();
1875 while ((node
= m_resourceTable
.Next()))
1877 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1878 wxString
resType(res
->GetType());
1880 if (resType
== "wxDialog")
1882 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1884 InstantiateResourceFromWindow(res
, win
, TRUE
);
1886 else if (resType
== "wxPanel")
1888 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1890 InstantiateResourceFromWindow(res
, win
, TRUE
);
1896 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1898 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1899 info
->SetResource(resource
);
1900 info
->InstantiateResource(resource
);
1905 wxNode
*node
= resource
->GetChildren().First();
1908 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1909 wxWindow
*childWindow
= FindWindowForResource(child
);
1914 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
1915 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1918 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1919 node
= node
->Next();
1926 // Create a window information object for the give window
1927 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1929 wxWindowPropertyInfo
*info
= NULL
;
1930 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1932 info
= new wxScrollBarPropertyInfo(win
);
1934 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1936 info
= new wxGroupBoxPropertyInfo(win
);
1938 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1940 info
= new wxCheckBoxPropertyInfo(win
);
1942 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1944 info
= new wxSliderPropertyInfo(win
);
1946 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1948 info
= new wxGaugePropertyInfo(win
);
1950 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1952 info
= new wxListBoxPropertyInfo(win
);
1954 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1956 info
= new wxRadioBoxPropertyInfo(win
);
1958 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1960 info
= new wxRadioButtonPropertyInfo(win
);
1962 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
1964 info
= new wxComboBoxPropertyInfo(win
);
1966 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1968 info
= new wxChoicePropertyInfo(win
);
1970 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1972 info
= new wxBitmapButtonPropertyInfo(win
);
1974 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1976 info
= new wxButtonPropertyInfo(win
);
1978 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1980 info
= new wxStaticBitmapPropertyInfo(win
);
1982 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1984 info
= new wxStaticTextPropertyInfo(win
);
1986 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1988 info
= new wxTextPropertyInfo(win
);
1990 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1992 info
= new wxPanelPropertyInfo(win
);
1996 info
= new wxWindowPropertyInfo(win
);
2001 // Edit the given window
2002 void wxResourceManager::EditWindow(wxWindow
*win
)
2004 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2007 info
->SetResource(FindResourceForWindow(win
));
2008 wxString
str("Editing ");
2009 str
+= win
->GetClassInfo()->GetClassName();
2011 if (win
->GetName() != "")
2012 str
+= win
->GetName();
2014 str
+= "properties";
2015 info
->Edit(NULL
, str
);
2019 // Generate a window id and a first stab at a name
2020 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2022 m_symbolIdCounter
++;
2023 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2024 m_symbolIdCounter
++;
2026 int nameId
= m_symbolIdCounter
;
2029 str
.Printf("%d", nameId
);
2030 idName
= prefix
+ str
;
2032 while (m_symbolTable
.SymbolExists(idName
))
2035 str
.Printf("%d", nameId
);
2036 idName
= prefix
+ str
;
2039 return m_symbolIdCounter
;
2044 * Resource editor frame
2047 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2049 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2050 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2051 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2052 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2053 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2054 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2055 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2056 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2057 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2058 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2059 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2060 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2061 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2062 EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow
)
2065 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2066 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2067 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2072 wxResourceEditorFrame::~wxResourceEditorFrame()
2076 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2078 manager
->New(FALSE
);
2081 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2083 manager
->CreateNewPanel();
2086 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2091 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2093 manager
->Clear(TRUE
, FALSE
);
2096 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2101 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2106 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2108 manager
->Clear(TRUE
, FALSE
) ;
2112 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2115 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart <julian.smart@ukonline.co.uk>\nJulian Smart (c) 1996-1999", wxDIALOG_EDITOR_VERSION
);
2116 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2119 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2121 manager
->TestCurrentDialog(this);
2124 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2127 wxBeginBusyCursor();
2128 manager
->GetHelpController()->LoadFile();
2129 manager
->GetHelpController()->DisplayContents();
2134 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2136 manager
->DeleteSelection();
2139 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2141 manager
->RecreateSelection();
2144 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent
& event
)
2146 if (manager
->Modified())
2148 if (!manager
->Clear(TRUE
, FALSE
))
2159 manager
->m_resourceEditorWindowSize
.width
= w
;
2160 manager
->m_resourceEditorWindowSize
.height
= h
;
2163 GetPosition(&x
, &y
);
2165 manager
->m_resourceEditorWindowSize
.x
= x
;
2166 manager
->m_resourceEditorWindowSize
.y
= y
;
2168 manager
->SetEditorFrame(NULL
);
2169 manager
->SetEditorToolBar(NULL
);
2175 * Resource editor window that contains the dialog/panel being edited
2178 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2179 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2182 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2184 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2188 m_childWindow
= NULL
;
2190 SetBackgroundColour(* wxWHITE
);
2193 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2197 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2204 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2208 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2211 wxString
str(res
->GetTitle());
2213 ViewStart(& x
, & y
);
2215 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2217 dc
.SetBackgroundMode(wxTRANSPARENT
);
2218 dc
.SetTextForeground(wxColour(0, 0, 0));
2221 dc
.GetTextExtent(str
, & w
, & h
);
2223 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2228 // Popup menu callback
2229 void ObjectMenuProc(wxMenu
*menu
, wxCommandEvent
& event
)
2231 wxWindow
*data
= (wxWindow
*)menu
->GetClientData();
2235 switch (event
.GetInt())
2237 case OBJECT_MENU_EDIT
:
2239 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2242 case OBJECT_MENU_DELETE
:
2244 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2245 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2246 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2259 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2260 // EVT_PAINT(EditorToolBar::OnPaint)
2263 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2265 wxToolBar(frame
, -1, pos
, size
, style
)
2269 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2271 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2275 case TOOLBAR_LOAD_FILE
:
2282 manager
->CreateNewPanel();
2285 case TOOLBAR_SAVE_FILE
:
2293 wxBeginBusyCursor();
2294 manager
->GetHelpController()->LoadFile();
2295 manager
->GetHelpController()->DisplayContents();
2300 case TOOLBAR_FORMAT_HORIZ
:
2302 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2305 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2307 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2310 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2312 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2315 case TOOLBAR_FORMAT_VERT
:
2317 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2320 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2322 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2325 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2327 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2330 case TOOLBAR_COPY_SIZE
:
2332 manager
->CopySize();
2335 case TOOLBAR_TO_BACK
:
2337 manager
->ToBackOrFront(TRUE
);
2340 case TOOLBAR_TO_FRONT
:
2342 manager
->ToBackOrFront(FALSE
);
2351 void EditorToolBar::OnMouseEnter(int toolIndex
)
2353 wxFrame
*frame
= (wxFrame
*)GetParent();
2361 case TOOLBAR_LOAD_FILE
:
2362 frame
->SetStatusText("Load project file");
2364 case TOOLBAR_SAVE_FILE
:
2365 frame
->SetStatusText("Save project file");
2368 frame
->SetStatusText("Create a new resource");
2370 case TOOLBAR_FORMAT_HORIZ
:
2371 frame
->SetStatusText("Align items horizontally");
2373 case TOOLBAR_FORMAT_VERT
:
2374 frame
->SetStatusText("Align items vertically");
2376 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2377 frame
->SetStatusText("Left-align items");
2379 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2380 frame
->SetStatusText("Right-align items");
2382 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2383 frame
->SetStatusText("Top-align items");
2385 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2386 frame
->SetStatusText("Bottom-align items");
2388 case TOOLBAR_COPY_SIZE
:
2389 frame
->SetStatusText("Copy size from first selection");
2391 case TOOLBAR_TO_FRONT
:
2392 frame
->SetStatusText("Put image to front");
2394 case TOOLBAR_TO_BACK
:
2395 frame
->SetStatusText("Put image to back");
2398 frame
->SetStatusText("Display help contents");
2404 else frame
->SetStatusText("");