1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource editor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "reseditr.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/checkbox.h"
27 #include "wx/button.h"
28 #include "wx/choice.h"
29 #include "wx/listbox.h"
30 #include "wx/radiobox.h"
31 #include "wx/statbox.h"
33 #include "wx/slider.h"
34 #include "wx/textctrl.h"
36 #include "wx/toolbar.h"
39 #include "wx/scrolbar.h"
40 #include "wx/config.h"
48 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
51 #include <strstream.h>
71 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
72 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
75 #include "bitmaps/load.xpm"
76 #include "bitmaps/save.xpm"
77 #include "bitmaps/new.xpm"
78 #include "bitmaps/vert.xpm"
79 #include "bitmaps/alignt.xpm"
80 #include "bitmaps/alignb.xpm"
81 #include "bitmaps/horiz.xpm"
82 #include "bitmaps/alignl.xpm"
83 #include "bitmaps/alignr.xpm"
84 #include "bitmaps/copysize.xpm"
85 #include "bitmaps/tofront.xpm"
86 #include "bitmaps/toback.xpm"
87 #include "bitmaps/help.xpm"
88 #include "bitmaps/wxwin.xpm"
90 #include "bitmaps/dialog.xpm"
91 #include "bitmaps/folder1.xpm"
92 #include "bitmaps/folder2.xpm"
93 #include "bitmaps/buttonsm.xpm"
100 wxResourceManager::wxResourceManager():
101 m_imageList(16, 16, TRUE
)
103 sm_currentResourceManager
= this;
104 m_editorFrame
= NULL
;
105 m_editorPanel
= NULL
;
107 m_editorResourceTree
= NULL
;
108 m_editorControlList
= NULL
;
110 m_symbolIdCounter
= 99;
112 m_currentFilename
= "";
113 m_symbolFilename
= "";
114 m_editorToolBar
= NULL
;
116 // Default window positions
117 m_resourceEditorWindowSize
.width
= 500;
118 m_resourceEditorWindowSize
.height
= 450;
120 m_resourceEditorWindowSize
.x
= 0;
121 m_resourceEditorWindowSize
.y
= 0;
123 m_propertyWindowSize
.width
= 300;
124 m_propertyWindowSize
.height
= 300;
127 m_helpController
= NULL
;
130 m_bitmapImage
= NULL
;
131 m_rootDialogItem
= 0;
134 wxResourceManager::~wxResourceManager()
136 sm_currentResourceManager
= NULL
;
140 if (m_helpController
)
142 m_helpController
->Quit();
143 delete m_helpController
;
144 m_helpController
= NULL
;
148 delete m_bitmapImage
;
152 bool wxResourceManager::Initialize()
154 // Set up the resource filename for each platform.
156 // dialoged.ini in the Windows directory
158 GetWindowsDirectory(buf
, 256);
159 strcat(buf
, "\\dialoged.ini");
160 m_optionsResourceFilename
= buf
;
161 #elif defined(__WXGTK__)
162 wxGetHomeDir( &m_optionsResourceFilename
);
163 m_optionsResourceFilename
+= "/.dialogedrc";
165 #error "Unsupported platform."
171 m_helpController
= new wxHelpController
;
172 m_helpController
->Initialize("dialoged");
175 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
176 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
177 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
182 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
185 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
189 // Initialize the image list icons
191 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
192 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
193 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
194 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
196 wxIcon
icon1( dialog_xpm
);
197 wxIcon
icon2( folder1_xpm
);
198 wxIcon
icon3( folder2_xpm
);
199 wxIcon
icon4( buttonsm_xpm
);
201 m_imageList
.Add(icon1
);
202 m_imageList
.Add(icon2
);
203 m_imageList
.Add(icon3
);
204 m_imageList
.Add(icon4
);
206 m_symbolTable
.AddStandardSymbols();
211 bool wxResourceManager::LoadOptions()
213 wxConfig
config("DialogEd", "wxWindows");
215 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
216 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
217 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
218 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
219 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
220 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
221 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
222 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
225 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
226 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
227 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
228 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
229 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
230 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
231 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
232 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
237 bool wxResourceManager::SaveOptions()
239 wxConfig
config("DialogEd", "wxWindows");
241 config
.Write("editorWindowX", m_resourceEditorWindowSize
.x
);
242 config
.Write("editorWindowY", m_resourceEditorWindowSize
.y
);
243 config
.Write("editorWindowWidth", m_resourceEditorWindowSize
.width
);
244 config
.Write("editorWindowHeight", m_resourceEditorWindowSize
.height
);
245 config
.Write("propertyWindowX", m_propertyWindowSize
.x
);
246 config
.Write("propertyWindowY", m_propertyWindowSize
.y
);
247 config
.Write("propertyWindowWidth", m_propertyWindowSize
.width
);
248 config
.Write("propertyWindowHeight", m_propertyWindowSize
.height
);
250 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
251 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
252 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
253 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
255 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
256 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
257 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
258 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
264 // Show or hide the resource editor frame, which displays a list
265 // of resources with ability to edit them.
266 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
272 m_editorFrame
->Iconize(FALSE
);
273 m_editorFrame
->Show(TRUE
);
276 m_editorFrame
= OnCreateEditorFrame(title
);
278 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
279 m_editorFrame
->SetMenuBar(menuBar
);
281 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
282 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
283 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
285 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
287 m_editorResourceTree
->SetImageList(& m_imageList
);
289 // Constraints for toolbar
290 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
291 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
292 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
293 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
294 c
->bottom
.Unconstrained();
295 c
->width
.Unconstrained();
296 c
->height
.Absolute(28);
297 m_editorToolBar
->SetConstraints(c
);
299 // Constraints for listbox
300 c
= new wxLayoutConstraints
;
301 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
302 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
303 c
->right
.Absolute (150);
304 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
305 c
->width
.Unconstrained();
306 c
->height
.Unconstrained();
307 m_editorResourceTree
->SetConstraints(c
);
309 // Constraints for panel
310 c
= new wxLayoutConstraints
;
311 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
312 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
313 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
314 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
315 c
->width
.Unconstrained();
316 c
->height
.Unconstrained();
317 m_editorPanel
->SetConstraints(c
);
319 // Constraints for control list (bottom window)
320 c
= new wxLayoutConstraints
;
321 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
322 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
323 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
324 c
->width
.Unconstrained();
326 c
->height
.Absolute(105);
328 c
->height
.Absolute(60);
331 m_editorControlList
->SetConstraints(c
);
333 m_editorFrame
->SetAutoLayout(TRUE
);
335 UpdateResourceList();
337 m_editorFrame
->Show(TRUE
);
342 wxFrame
*fr
= m_editorFrame
;
343 if (m_editorFrame
->OnClose())
347 m_editorFrame
= NULL
;
348 m_editorPanel
= NULL
;
354 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
358 if (filename
== wxString(""))
359 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
362 wxString
str("wxWindows Dialog Editor - ");
363 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
365 m_editorFrame
->SetTitle(str
);
370 bool wxResourceManager::Save()
372 if (m_currentFilename
== wxString(""))
375 return Save(m_currentFilename
);
378 bool wxResourceManager::Save(const wxString
& filename
)
380 // Ensure all visible windows are saved to their resources
381 m_currentFilename
= filename
;
382 SetFrameTitle(m_currentFilename
);
383 InstantiateAllResourcesFromWindows();
384 if (m_resourceTable
.Save(filename
))
386 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
394 bool wxResourceManager::SaveAs()
396 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
397 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
));
399 if (s
.IsNull() || s
== "")
402 m_currentFilename
= s
;
403 wxStripExtension(m_currentFilename
);
404 m_currentFilename
+= ".wxr";
406 // Construct include filename from this file
407 m_symbolFilename
= m_currentFilename
;
409 wxStripExtension(m_symbolFilename
);
410 m_symbolFilename
+= ".h";
412 Save(m_currentFilename
);
416 bool wxResourceManager::SaveIfModified()
423 bool wxResourceManager::Load(const wxString
& filename
)
425 return New(TRUE
, filename
);
428 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
430 if (!Clear(TRUE
, FALSE
))
433 m_symbolTable
.AddStandardSymbols();
437 wxString str
= filename
;
438 if (str
== wxString(""))
440 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, NULL
));
441 if (!f
.IsNull() && f
!= "")
447 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
449 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
452 m_currentFilename
= str
;
454 SetFrameTitle(m_currentFilename
);
456 UpdateResourceList();
458 // Construct include filename from this file
459 m_symbolFilename
= m_currentFilename
;
461 wxStripExtension(m_symbolFilename
);
462 m_symbolFilename
+= ".h";
464 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
466 wxString
str("Could not find include file ");
467 str
+= m_symbolFilename
;
468 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
469 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
470 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
472 m_symbolIdCounter
= 99;
476 // Set the id counter to the last known id
477 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
480 // Now check in case some (or all) resources don't have resource ids, or they
481 // don't match the .h file, or something of that nature.
482 bool altered
= RepairResourceIds();
485 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
486 "Dialog Editor Warning", wxOK
);
497 m_currentFilename
= "";
504 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
506 if (!force
&& Modified())
508 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
512 if (!SaveIfModified())
518 ClearCurrentDialog();
519 DisassociateWindows();
521 m_symbolTable
.Clear();
522 m_resourceTable
.ClearTable();
523 UpdateResourceList();
528 bool wxResourceManager::DisassociateWindows()
530 m_resourceTable
.BeginFind();
532 while ((node
= m_resourceTable
.Next()))
534 wxItemResource
*res
= (wxItemResource
*)node
->Data();
535 DisassociateResource(res
);
541 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
543 if (!m_resourceAssociations
.Get((long)resource
))
544 m_resourceAssociations
.Put((long)resource
, win
);
546 wxNode
*node
= resource
->GetChildren().First();
549 wxItemResource
*child
= (wxItemResource
*)node
->Data();
550 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
552 childWindow
= win
->FindWindow(child
->GetName());
554 AssociateResource(child
, childWindow
);
558 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
559 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
566 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
568 wxWindow
*win
= FindWindowForResource(resource
);
572 // Disassociate children of window
573 wxNode
*node
= win
->GetChildren().First();
576 wxWindow
*child
= (wxWindow
*)node
->Data();
577 if (child
->IsKindOf(CLASSINFO(wxControl
)))
578 DisassociateResource(child
);
582 RemoveSelection(win
);
583 m_resourceAssociations
.Delete((long)resource
);
587 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
589 wxItemResource
*res
= FindResourceForWindow(win
);
591 return DisassociateResource(res
);
596 // Saves the window info into the resource, and deletes the
597 // handler. Doesn't actually disassociate the window from
598 // the resources. Replaces OnClose.
599 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
601 wxItemResource
*res
= FindResourceForWindow(win
);
603 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
605 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
606 win
->PopEventHandler();
608 // Now reset all child event handlers
609 wxNode
*node
= win
->GetChildren().First();
612 wxWindow
*child
= (wxWindow
*)node
->Data();
613 wxEvtHandler
*childHandler
= child
->GetEventHandler();
614 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
616 child
->PopEventHandler(TRUE
);
624 win
->PopEventHandler(TRUE
);
627 // Save the information
628 InstantiateResourceFromWindow(res
, win
, TRUE
);
630 // DisassociateResource(win);
635 // Destroys the window. If this is the 'current' panel, NULLs the
637 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
639 bool clearDisplay
= FALSE
;
640 if (m_editorPanel
->m_childWindow
== win
)
642 m_editorPanel
->m_childWindow
= NULL
;
649 m_editorPanel
->Clear();
654 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
656 m_resourceAssociations
.BeginFind();
658 while ((node
= m_resourceAssociations
.Next()))
660 wxWindow
*w
= (wxWindow
*)node
->Data();
663 return (wxItemResource
*)node
->GetKeyInteger();
669 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
671 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
675 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
679 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
682 if (!m_resourceTable
.FindResource(buf
))
687 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
690 int frameWidth = 420;
691 int frameHeight = 300;
694 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
695 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
696 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
697 wxDEFAULT_FRAME_STYLE
);
699 frame
->CreateStatusBar(1);
701 frame
->SetAutoLayout(TRUE
);
703 frame
->SetIcon(wxIcon("DIALOGEDICON"));
708 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
710 wxMenuBar
*menuBar
= new wxMenuBar
;
712 wxMenu
*fileMenu
= new wxMenu
;
713 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
714 fileMenu
->AppendSeparator();
715 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
716 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
717 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
718 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
719 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
720 fileMenu
->AppendSeparator();
721 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
723 wxMenu
*editMenu
= new wxMenu
;
724 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
725 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
726 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
728 wxMenu
*helpMenu
= new wxMenu
;
729 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
730 helpMenu
->AppendSeparator();
731 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
733 menuBar
->Append(fileMenu
, "&File");
734 menuBar
->Append(editMenu
, "&Edit");
735 menuBar
->Append(helpMenu
, "&Help");
740 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
742 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
743 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
746 panel
->SetScrollbars(10, 10, 100, 100);
751 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
753 // Load palette bitmaps
755 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
756 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
757 wxBitmap
ToolbarNewBitmap("NEWTOOL");
758 wxBitmap
ToolbarVertBitmap("VERTTOOL");
759 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
760 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
761 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
762 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
763 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
764 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
765 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
766 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
767 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
770 wxBitmap
ToolbarLoadBitmap( load_xpm
);
771 wxBitmap
ToolbarSaveBitmap( save_xpm
);
772 wxBitmap
ToolbarNewBitmap( new_xpm
);
773 wxBitmap
ToolbarVertBitmap( vert_xpm
);
774 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
775 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
776 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
777 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
778 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
779 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
780 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
781 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
782 wxBitmap
ToolbarHelpBitmap( help_xpm
);
785 // Create the toolbar
786 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
787 toolbar
->SetMargins(2, 2);
794 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
799 toolbar
->AddSeparator();
800 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
801 FALSE
, (float)currentX
, -1, NULL
, "New dialog");
802 currentX
+= width
+ dx
;
803 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
804 FALSE
, (float)currentX
, -1, NULL
, "Load");
805 currentX
+= width
+ dx
;
806 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
807 FALSE
, (float)currentX
, -1, NULL
, "Save");
808 currentX
+= width
+ dx
+ gap
;
809 toolbar
->AddSeparator();
810 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
811 FALSE
, (float)currentX
, -1, NULL
, "Horizontal align");
812 currentX
+= width
+ dx
;
813 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
814 FALSE
, (float)currentX
, -1, NULL
, "Top align");
815 currentX
+= width
+ dx
;
816 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
817 FALSE
, (float)currentX
, -1, NULL
, "Bottom align");
818 currentX
+= width
+ dx
;
819 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
820 FALSE
, (float)currentX
, -1, NULL
, "Vertical align");
821 currentX
+= width
+ dx
;
822 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
823 FALSE
, (float)currentX
, -1, NULL
, "Left align");
824 currentX
+= width
+ dx
;
825 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
826 FALSE
, (float)currentX
, -1, NULL
, "Right align");
827 currentX
+= width
+ dx
;
828 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
829 FALSE
, (float)currentX
, -1, NULL
, "Copy size");
830 currentX
+= width
+ dx
+ gap
;
831 toolbar
->AddSeparator();
832 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
833 FALSE
, (float)currentX
, -1, NULL
, "To front");
834 currentX
+= width
+ dx
;
835 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
836 FALSE
, (float)currentX
, -1, NULL
, "To back");
837 currentX
+= width
+ dx
+ gap
;
839 toolbar
->AddSeparator();
840 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
841 FALSE
, (float)currentX
, -1, NULL
, "Help");
842 currentX
+= width
+ dx
;
849 void wxResourceManager::UpdateResourceList()
851 if (!m_editorResourceTree
)
854 m_editorResourceTree
->SetInvalid(TRUE
);
855 m_editorResourceTree
->DeleteAllItems();
857 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
859 m_resourceTable
.BeginFind();
861 while ((node
= m_resourceTable
.Next()))
863 wxItemResource
*res
= (wxItemResource
*)node
->Data();
864 wxString
resType(res
->GetType());
865 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
867 AddItemsRecursively(id
, res
);
870 m_editorResourceTree
->Expand(id
);
871 m_editorResourceTree
->SetInvalid(FALSE
);
874 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
876 wxString
theString("");
877 theString
= resource
->GetName();
880 wxString
resType(resource
->GetType());
881 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
886 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
888 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
890 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
892 wxNode
*node
= resource
->GetChildren().First();
895 wxItemResource
*res
= (wxItemResource
*)node
->Data();
896 AddItemsRecursively(id
, res
);
900 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
903 bool wxResourceManager::EditSelectedResource()
905 int sel
= m_editorResourceTree
->GetSelection();
908 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
909 wxItemResource
*res
= data
->GetResource();
915 bool wxResourceManager::Edit(wxItemResource
*res
)
917 ClearCurrentDialog();
919 wxString
resType(res
->GetType());
920 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
924 wxMessageBox("Should not find panel in wxResourceManager::Edit");
929 // long style = res->GetStyle();
930 // res->SetStyle(style|wxRAISED_BORDER);
932 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
935 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
937 panel
->PushEventHandler(handler
);
939 // res->SetStyle(style);
940 handler
->AddChildHandlers(); // Add event handlers for all controls
941 AssociateResource(res
, panel
);
943 m_editorPanel
->m_childWindow
= panel
;
944 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
948 wxClientDC
dc(m_editorPanel
);
949 m_editorPanel
->DrawTitle(dc
);
954 bool wxResourceManager::CreateNewPanel()
956 ClearCurrentDialog();
959 MakeUniqueName("dialog", buf
);
961 wxItemResource
*resource
= new wxItemResource
;
962 resource
->SetType("wxDialog");
963 resource
->SetName(buf
);
964 resource
->SetTitle(buf
);
965 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
966 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
969 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
972 // This is now guaranteed to be unique, so just add to symbol table
973 m_symbolTable
.AddSymbol(newIdName
, id
);
975 m_resourceTable
.AddResource(resource
);
977 wxSize
size(400, 300);
979 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
980 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
981 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
982 m_editorPanel
->m_childWindow
= panel
;
984 resource
->SetStyle(panel
->GetWindowStyleFlag());
986 // Store dialog units in resource
987 size
= panel
->ConvertPixelsToDialog(size
);
989 resource
->SetSize(10, 10, size
.x
, size
.y
);
991 // For editing in situ we will need to use the hash table to ensure
992 // we don't dereference invalid pointers.
993 // resourceWindowTable.Put((long)resource, panel);
995 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
997 panel
->PushEventHandler(handler
);
999 AssociateResource(resource
, panel
);
1000 UpdateResourceList();
1003 m_editorPanel
->m_childWindow
->Refresh();
1005 // panel->Refresh();
1007 wxClientDC
dc(m_editorPanel
);
1008 m_editorPanel
->DrawTitle(dc
);
1013 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1016 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1021 wxItemResource
*res
= new wxItemResource
;
1022 wxControl
*newItem
= NULL
;
1024 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1026 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1027 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1029 else res
->SetSize(x
, y
, -1, -1);
1031 res
->SetType(iType
);
1035 wxString
itemType(iType
);
1037 if (itemType
== "wxButton")
1039 prefix
= "ID_BUTTON";
1040 MakeUniqueName("button", buf
);
1043 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1045 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1047 if (itemType
== "wxBitmapButton")
1049 prefix
= "ID_BITMAPBUTTON";
1050 MakeUniqueName("button", buf
);
1052 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1054 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1056 prefix
= "ID_STATIC";
1057 MakeUniqueName("statictext", buf
);
1060 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1062 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1064 else if (itemType
== "wxStaticBitmap")
1066 prefix
= "ID_STATICBITMAP";
1067 MakeUniqueName("static", buf
);
1069 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1071 else if (itemType
== "wxCheckBox")
1073 prefix
= "ID_CHECKBOX";
1074 MakeUniqueName("checkbox", buf
);
1076 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1078 else if (itemType
== "wxListBox")
1080 prefix
= "ID_LISTBOX";
1081 MakeUniqueName("listbox", buf
);
1083 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1085 else if (itemType
== "wxRadioBox")
1087 prefix
= "ID_RADIOBOX";
1088 MakeUniqueName("radiobox", buf
);
1090 wxString names
[] = { "One", "Two" };
1091 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1092 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1093 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1095 else if (itemType
== "wxRadioButton")
1097 prefix
= "ID_RADIOBUTTON";
1098 MakeUniqueName("radiobutton", buf
);
1100 wxString names
[] = { "One", "Two" };
1101 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1102 0, wxDefaultValidator
, buf
);
1104 else if (itemType
== "wxChoice")
1106 prefix
= "ID_CHOICE";
1107 MakeUniqueName("choice", buf
);
1109 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1111 else if (itemType
== "wxComboBox")
1113 prefix
= "ID_COMBOBOX";
1114 MakeUniqueName("combobox", buf
);
1116 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1118 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1120 prefix
= "ID_STATICBOX";
1121 MakeUniqueName("staticbox", buf
);
1123 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1125 else if (itemType
== "wxGauge")
1127 prefix
= "ID_GAUGE";
1128 MakeUniqueName("gauge", buf
);
1130 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1132 else if (itemType
== "wxSlider")
1134 prefix
= "ID_SLIDER";
1135 MakeUniqueName("slider", buf
);
1137 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1139 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1141 prefix
= "ID_TEXTCTRL";
1142 MakeUniqueName("textctrl", buf
);
1144 res
->SetType("wxTextCtrl");
1145 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1147 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1149 prefix
= "ID_TEXTCTRL";
1150 MakeUniqueName("textctrl", buf
);
1152 res
->SetType("wxTextCtrl");
1153 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1155 else if (itemType
== "wxScrollBar")
1157 prefix
= "ID_SCROLLBAR";
1158 MakeUniqueName("scrollbar", buf
);
1160 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1165 int actualW
, actualH
;
1166 newItem
->GetSize(&actualW
, &actualH
);
1167 wxSize
actualSize(actualW
, actualH
);
1169 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1171 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1173 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1176 int id
= GenerateWindowId(prefix
, newIdName
);
1179 // This is now guaranteed to be unique, so just add to symbol table
1180 m_symbolTable
.AddSymbol(newIdName
, id
);
1182 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1184 res
->SetStyle(newItem
->GetWindowStyleFlag());
1185 AssociateResource(res
, newItem
);
1186 panelResource
->GetChildren().Append(res
);
1188 UpdateResourceList();
1193 void wxResourceManager::ClearCurrentDialog()
1195 if (m_editorPanel
->m_childWindow
)
1197 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1198 DisassociateResource(m_editorPanel
->m_childWindow
);
1199 DeleteWindow(m_editorPanel
->m_childWindow
);
1200 m_editorPanel
->m_childWindow
= NULL
;
1201 m_editorPanel
->Clear();
1205 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1207 if (m_editorPanel
->m_childWindow
)
1209 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1213 // Make sure the resources are up-to-date w.r.t. the window
1214 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1216 wxDialog
* dialog
= new wxDialog
;
1217 bool success
= FALSE
;
1218 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1221 dialog
->ShowModal();
1229 // Find the first dialog or panel for which
1230 // there is a selected panel item.
1231 wxWindow
*wxResourceManager::FindParentOfSelection()
1233 m_resourceTable
.BeginFind();
1235 while ((node
= m_resourceTable
.Next()))
1237 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1238 wxWindow
*win
= FindWindowForResource(res
);
1241 wxNode
*node1
= win
->GetChildren().First();
1244 wxControl
*item
= (wxControl
*)node1
->Data();
1245 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1246 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1248 node1
= node1
->Next();
1255 // Format the panel items according to 'flag'
1256 void wxResourceManager::AlignItems(int flag
)
1258 wxWindow
*win
= FindParentOfSelection();
1262 wxNode
*node
= GetSelections().First();
1266 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1267 if (firstSelection
->GetParent() != win
)
1272 firstSelection
->GetPosition(&firstX
, &firstY
);
1273 firstSelection
->GetSize(&firstW
, &firstH
);
1274 int centreX
= (int)(firstX
+ (firstW
/ 2));
1275 int centreY
= (int)(firstY
+ (firstH
/ 2));
1277 while ((node
= node
->Next()))
1279 wxControl
*item
= (wxControl
*)node
->Data();
1280 if (item
->GetParent() == win
)
1283 item
->GetPosition(&x
, &y
);
1284 item
->GetSize(&w
, &h
);
1290 case TOOLBAR_FORMAT_HORIZ
:
1293 newY
= (int)(centreY
- (h
/2.0));
1296 case TOOLBAR_FORMAT_VERT
:
1298 newX
= (int)(centreX
- (w
/2.0));
1302 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1308 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1314 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1316 newX
= firstX
+ firstW
- w
;
1320 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1323 newY
= firstY
+ firstH
- h
;
1331 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1332 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1334 item
->SetSize(newX
, newY
, w
, h
);
1336 // Also update the associated resource
1337 // We need to convert to dialog units if this is not a dialog or panel, but
1338 // the parent resource specifies dialog units.
1339 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1341 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1342 newX
= pt
.x
; newY
= pt
.y
;
1343 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1346 resource
->SetSize(newX
, newY
, w
, h
);
1352 // Copy the first image's size to subsequent images
1353 void wxResourceManager::CopySize()
1355 wxWindow
*win
= FindParentOfSelection();
1359 wxNode
*node
= GetSelections().First();
1363 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1364 if (firstSelection
->GetParent() != win
)
1369 firstSelection
->GetPosition(&firstX
, &firstY
);
1370 firstSelection
->GetSize(&firstW
, &firstH
);
1372 while ((node
= node
->Next()))
1374 wxControl
*item
= (wxControl
*)node
->Data();
1375 if (item
->GetParent() == win
)
1377 item
->SetSize(-1, -1, firstW
, firstH
);
1379 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1380 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1382 // Also update the associated resource
1383 // We need to convert to dialog units if this is not a dialog or panel, but
1384 // the parent resource specifies dialog units.
1385 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1387 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1388 firstW
= sz
.x
; firstH
= sz
.y
;
1390 resource
->SetSize(resource
->GetX(), resource
->GetY(), firstW
, firstH
);
1397 void wxResourceManager::ToBackOrFront(bool toBack
)
1399 wxWindow
*win
= FindParentOfSelection();
1402 wxItemResource
*winResource
= FindResourceForWindow(win
);
1404 wxNode
*node
= GetSelections().First();
1407 wxControl
*item
= (wxControl
*)node
->Data();
1408 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1409 if (item
->GetParent() == win
)
1411 win
->GetChildren().DeleteObject(item
);
1413 winResource
->GetChildren().DeleteObject(itemResource
);
1416 win
->GetChildren().Insert(item
);
1418 winResource
->GetChildren().Insert(itemResource
);
1422 win
->GetChildren().Append(item
);
1424 winResource
->GetChildren().Append(itemResource
);
1427 node
= node
->Next();
1432 void wxResourceManager::AddSelection(wxWindow
*win
)
1434 if (!m_selections
.Member(win
))
1435 m_selections
.Append(win
);
1438 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1440 m_selections
.DeleteObject(win
);
1443 // Need to search through resource table removing this from
1444 // any resource which has this as a parent.
1445 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1447 m_resourceTable
.BeginFind();
1449 while ((node
= m_resourceTable
.Next()))
1451 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1452 if (thisRes
->GetChildren().Member(res
))
1454 thisRes
->GetChildren().DeleteObject(res
);
1461 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1466 RemoveResourceFromParent(res
);
1468 wxNode
*node
= res
->GetChildren().First();
1471 wxNode
*next
= node
->Next();
1472 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1473 DeleteResource(child
);
1477 // If this is a button or message resource, delete the
1478 // associate bitmap resource if not being used.
1479 wxString
resType(res
->GetType());
1481 /* shouldn't have to do this now bitmaps are ref-counted
1482 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1484 PossiblyDeleteBitmapResource(res->GetValue4());
1488 // Remove symbol from table if appropriate
1489 if (!IsSymbolUsed(res
, res
->GetId()))
1491 m_symbolTable
.RemoveSymbol(res
->GetId());
1494 m_resourceTable
.Delete(res
->GetName());
1500 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1502 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1504 // Deselect and refresh window in case we leave selection
1506 wxControl
*item
= (wxControl
*)win
;
1507 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1508 if (childHandler
->IsSelected())
1510 RemoveSelection(item
);
1511 childHandler
->SelectItem(FALSE
);
1513 item
->GetParent()->Refresh();
1518 wxItemResource
*res
= FindResourceForWindow(win
);
1520 DisassociateResource(res
);
1521 DeleteResource(res
);
1522 UpdateResourceList();
1527 // Will eventually have bitmap type information, for different
1529 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1531 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1535 MakeUniqueName("bitmap", buf
);
1536 resource
= new wxItemResource
;
1537 resource
->SetType("wxBitmap");
1538 resource
->SetName(buf
);
1540 // A bitmap resource has one or more children, specifying
1541 // alternative bitmaps.
1542 wxItemResource
*child
= new wxItemResource
;
1543 child
->SetType("wxBitmap");
1544 child
->SetName(filename
);
1545 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1546 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1547 child
->SetValue3(0); // Depth
1548 child
->SetSize(0,0,0,0);
1549 resource
->GetChildren().Append(child
);
1551 m_resourceTable
.AddResource(resource
);
1553 UpdateResourceList();
1556 return resource
->GetName();
1558 return wxEmptyString
;
1561 // Delete the bitmap resource if it isn't being used by another resource.
1562 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1564 if (!IsBitmapResourceUsed(resourceName
))
1566 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1567 DeleteResource(res
);
1568 UpdateResourceList();
1572 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1574 m_resourceTable
.BeginFind();
1576 while ((node
= m_resourceTable
.Next()))
1578 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1579 wxString
resType(res
->GetType());
1580 if (resType
== "wxDialog")
1582 wxNode
*node1
= res
->GetChildren().First();
1585 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1586 wxString
childResType(child
->GetType());
1588 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1589 child
->GetValue4() &&
1590 (strcmp(child
->GetValue4(), resourceName
) == 0))
1592 node1
= node1
->Next();
1599 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1600 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1602 if (!resource
|| (resource
->GetValue4() == ""))
1603 return wxEmptyString
;
1604 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1605 if (!bitmapResource
)
1606 return wxEmptyString
;
1608 wxNode
*node
= bitmapResource
->GetChildren().First();
1611 // Eventually augment this to return a bitmap of the right kind or something...
1612 // Maybe the root of the filename remains the same, so it doesn't matter which we
1613 // pick up. Otherwise how do we specify multiple filenames... too boring...
1614 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1615 return child
->GetName();
1617 node
= node
->Next();
1619 return wxEmptyString
;
1622 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1624 m_resourceTable
.BeginFind();
1626 while ((node
= m_resourceTable
.Next()))
1628 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1629 wxString
resType(res
->GetType());
1630 if (resType
== "wxBitmap")
1632 wxNode
*node1
= res
->GetChildren().First();
1635 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1636 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1638 node1
= node1
->Next();
1645 // Is this window identifier symbol in use?
1646 // Let's assume that we can't have 2 names for the same integer id.
1647 // Therefore we can tell by the integer id whether the symbol is
1649 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1651 m_resourceTable
.BeginFind();
1653 while ((node
= m_resourceTable
.Next()))
1655 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1657 wxString
resType(res
->GetType());
1658 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1660 if ((res
!= thisResource
) && (res
->GetId() == id
))
1663 wxNode
*node1
= res
->GetChildren().First();
1666 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1667 if ((child
!= thisResource
) && (child
->GetId() == id
))
1669 node1
= node1
->Next();
1676 // Is this window identifier compatible with the given name? (i.e.
1677 // does it already exist under a different name)
1678 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1680 if (m_symbolTable
.SymbolExists(name
))
1682 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1689 // Change all integer ids that match oldId, to newId.
1690 // This is necessary if an id is changed for one resource - all resources
1692 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1694 m_resourceTable
.BeginFind();
1696 while ((node
= m_resourceTable
.Next()))
1698 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1700 wxString
resType(res
->GetType());
1701 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1703 if (res
->GetId() == oldId
)
1706 wxNode
*node1
= res
->GetChildren().First();
1709 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1710 if (child
->GetId() == oldId
)
1711 child
->SetId(newId
);
1713 node1
= node1
->Next();
1719 // If any resource ids were missing (or their symbol was missing),
1720 // repair them i.e. give them new ids. Returns TRUE if any resource
1721 // needed repairing.
1722 bool wxResourceManager::RepairResourceIds()
1724 bool repaired
= FALSE
;
1726 m_resourceTable
.BeginFind();
1728 while ((node
= m_resourceTable
.Next()))
1730 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1731 wxString
resType(res
->GetType());
1732 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1735 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1737 wxString newSymbolName
;
1738 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1740 if (res
->GetId() == 0)
1743 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1747 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1753 wxNode
*node1
= res
->GetChildren().First();
1756 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1758 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1760 wxString newSymbolName
;
1761 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1763 if (child
->GetId() == 0)
1765 child
->SetId(newId
);
1766 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1770 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1776 node1
= node1
->Next();
1784 // Deletes 'win' and creates a new window from the resource that
1785 // was associated with it. E.g. if you can't change properties on the
1786 // fly, you'll need to delete the window and create it again.
1787 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1789 wxItemResource
*resource
= FindResourceForWindow(win
);
1791 // Put the current window properties into the wxItemResource object
1793 wxWindowPropertyInfo
*newInfo
= NULL
;
1796 newInfo
= CreatePropertyInfoForWindow(win
);
1800 info
->InstantiateResource(resource
);
1802 wxWindow
*newWin
= NULL
;
1803 wxWindow
*parent
= win
->GetParent();
1804 wxItemResource
* parentResource
= NULL
;
1806 parentResource
= FindResourceForWindow(parent
);
1808 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1811 newWin
= FindWindowForResource(resource
);
1815 DisassociateResource(resource
);
1816 if (win
->GetEventHandler() != win
)
1817 win
->PopEventHandler(TRUE
);
1820 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1821 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1822 AssociateResource(resource
, newWin
);
1823 UpdateResourceList();
1827 info
->SetPropertyWindow(newWin
);
1835 // Delete resource highlighted in the listbox
1836 bool wxResourceManager::DeleteSelection()
1838 int sel
= m_editorResourceTree
->GetSelection();
1841 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1842 wxItemResource
*res
= data
->GetResource();
1843 wxWindow
*win
= FindWindowForResource(res
);
1846 DeleteResource(win
);
1848 UpdateResourceList();
1857 // Delete resource highlighted in the listbox
1858 bool wxResourceManager::RecreateSelection()
1860 wxNode
*node
= GetSelections().First();
1863 wxControl
*item
= (wxControl
*)node
->Data();
1864 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1865 wxNode
*next
= node
->Next();
1866 childHandler
->SelectItem(FALSE
);
1868 RemoveSelection(item
);
1870 RecreateWindowFromResource(item
);
1877 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
1882 // Ensures that all currently shown windows are saved to resources,
1883 // e.g. just before writing to a .wxr file.
1884 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1886 m_resourceTable
.BeginFind();
1888 while ((node
= m_resourceTable
.Next()))
1890 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1891 wxString
resType(res
->GetType());
1893 if (resType
== "wxDialog")
1895 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1897 InstantiateResourceFromWindow(res
, win
, TRUE
);
1899 else if (resType
== "wxPanel")
1901 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1903 InstantiateResourceFromWindow(res
, win
, TRUE
);
1909 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1911 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1912 info
->SetResource(resource
);
1913 info
->InstantiateResource(resource
);
1918 wxNode
*node
= resource
->GetChildren().First();
1921 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1922 wxWindow
*childWindow
= FindWindowForResource(child
);
1927 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
1928 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1931 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1932 node
= node
->Next();
1939 // Create a window information object for the give window
1940 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1942 wxWindowPropertyInfo
*info
= NULL
;
1943 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1945 info
= new wxScrollBarPropertyInfo(win
);
1947 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1949 info
= new wxGroupBoxPropertyInfo(win
);
1951 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1953 info
= new wxCheckBoxPropertyInfo(win
);
1955 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1957 info
= new wxSliderPropertyInfo(win
);
1959 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1961 info
= new wxGaugePropertyInfo(win
);
1963 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1965 info
= new wxListBoxPropertyInfo(win
);
1967 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1969 info
= new wxRadioBoxPropertyInfo(win
);
1971 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1973 info
= new wxRadioButtonPropertyInfo(win
);
1975 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
1977 info
= new wxComboBoxPropertyInfo(win
);
1979 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1981 info
= new wxChoicePropertyInfo(win
);
1983 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1985 info
= new wxBitmapButtonPropertyInfo(win
);
1987 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1989 info
= new wxButtonPropertyInfo(win
);
1991 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1993 info
= new wxStaticBitmapPropertyInfo(win
);
1995 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1997 info
= new wxStaticTextPropertyInfo(win
);
1999 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
2001 info
= new wxTextPropertyInfo(win
);
2003 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
2005 info
= new wxPanelPropertyInfo(win
);
2009 info
= new wxWindowPropertyInfo(win
);
2014 // Edit the given window
2015 void wxResourceManager::EditWindow(wxWindow
*win
)
2017 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2020 info
->SetResource(FindResourceForWindow(win
));
2021 wxString
str("Editing ");
2022 str
+= win
->GetClassInfo()->GetClassName();
2024 if (win
->GetName() != "")
2025 str
+= win
->GetName();
2027 str
+= "properties";
2028 info
->Edit(NULL
, str
);
2032 // Generate a window id and a first stab at a name
2033 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2035 m_symbolIdCounter
++;
2036 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2037 m_symbolIdCounter
++;
2039 int nameId
= m_symbolIdCounter
;
2042 str
.Printf("%d", nameId
);
2043 idName
= prefix
+ str
;
2045 while (m_symbolTable
.SymbolExists(idName
))
2048 str
.Printf("%d", nameId
);
2049 idName
= prefix
+ str
;
2052 return m_symbolIdCounter
;
2057 * Resource editor frame
2060 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2062 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2063 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2064 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2065 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2066 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2067 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2068 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2069 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2070 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2071 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2072 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2073 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2074 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2077 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2078 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2079 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2084 wxResourceEditorFrame::~wxResourceEditorFrame()
2088 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2090 manager
->New(FALSE
);
2093 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2095 manager
->CreateNewPanel();
2098 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2103 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2105 manager
->Clear(TRUE
, FALSE
);
2108 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2113 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2118 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2120 manager
->Clear(TRUE
, FALSE
) ;
2124 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2127 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
2128 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2131 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2133 manager
->TestCurrentDialog(this);
2136 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2139 wxBeginBusyCursor();
2140 manager
->GetHelpController()->LoadFile();
2141 manager
->GetHelpController()->DisplayContents();
2146 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2148 manager
->DeleteSelection();
2151 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2153 manager
->RecreateSelection();
2156 bool wxResourceEditorFrame::OnClose()
2158 if (manager
->Modified())
2160 if (!manager
->Clear(TRUE
, FALSE
))
2168 manager
->m_resourceEditorWindowSize
.width
= w
;
2169 manager
->m_resourceEditorWindowSize
.height
= h
;
2172 GetPosition(&x
, &y
);
2174 manager
->m_resourceEditorWindowSize
.x
= x
;
2175 manager
->m_resourceEditorWindowSize
.y
= y
;
2177 manager
->SetEditorFrame(NULL
);
2178 manager
->SetEditorToolBar(NULL
);
2184 * Resource editor window that contains the dialog/panel being edited
2187 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2188 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
2189 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2192 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2194 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2198 m_childWindow
= NULL
;
2201 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2205 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
2207 wxScrolledWindow::OnScroll(event
);
2210 ViewStart(& x
, & y
);
2213 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
2216 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2223 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2227 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2230 wxString
str(res
->GetTitle());
2232 ViewStart(& x
, & y
);
2234 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2236 dc
.SetBackgroundMode(wxTRANSPARENT
);
2237 dc
.SetTextForeground(wxColour(0, 0, 0));
2240 dc
.GetTextExtent(str
, & w
, & h
);
2242 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2247 // Popup menu callback
2248 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2250 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2254 switch (event
.GetInt())
2256 case OBJECT_MENU_EDIT
:
2258 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2261 case OBJECT_MENU_DELETE
:
2263 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2264 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2265 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2278 #ifdef __WXGTK__ // I don't dare to delete it...
2280 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2285 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2286 EVT_PAINT(EditorToolBar::OnPaint
)
2291 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2293 wxToolBar(frame
, -1, pos
, size
, style
)
2297 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2299 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2303 case TOOLBAR_LOAD_FILE
:
2310 manager
->CreateNewPanel();
2313 case TOOLBAR_SAVE_FILE
:
2321 wxBeginBusyCursor();
2322 manager
->GetHelpController()->LoadFile();
2323 manager
->GetHelpController()->DisplayContents();
2328 case TOOLBAR_FORMAT_HORIZ
:
2330 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2333 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2335 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2338 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2340 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2343 case TOOLBAR_FORMAT_VERT
:
2345 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2348 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2350 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2353 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2355 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2358 case TOOLBAR_COPY_SIZE
:
2360 manager
->CopySize();
2363 case TOOLBAR_TO_BACK
:
2365 manager
->ToBackOrFront(TRUE
);
2368 case TOOLBAR_TO_FRONT
:
2370 manager
->ToBackOrFront(FALSE
);
2379 void EditorToolBar::OnMouseEnter(int toolIndex
)
2381 wxFrame
*frame
= (wxFrame
*)GetParent();
2389 case TOOLBAR_LOAD_FILE
:
2390 frame
->SetStatusText("Load project file");
2392 case TOOLBAR_SAVE_FILE
:
2393 frame
->SetStatusText("Save project file");
2396 frame
->SetStatusText("Create a new resource");
2398 case TOOLBAR_FORMAT_HORIZ
:
2399 frame
->SetStatusText("Align items horizontally");
2401 case TOOLBAR_FORMAT_VERT
:
2402 frame
->SetStatusText("Align items vertically");
2404 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2405 frame
->SetStatusText("Left-align items");
2407 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2408 frame
->SetStatusText("Right-align items");
2410 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2411 frame
->SetStatusText("Top-align items");
2413 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2414 frame
->SetStatusText("Bottom-align items");
2416 case TOOLBAR_COPY_SIZE
:
2417 frame
->SetStatusText("Copy size from first selection");
2419 case TOOLBAR_TO_FRONT
:
2420 frame
->SetStatusText("Put image to front");
2422 case TOOLBAR_TO_BACK
:
2423 frame
->SetStatusText("Put image to back");
2426 frame
->SetStatusText("Display help contents");
2432 else frame
->SetStatusText("");