1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource editor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "reseditr.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/checkbox.h"
27 #include "wx/button.h"
28 #include "wx/choice.h"
29 #include "wx/listbox.h"
30 #include "wx/radiobox.h"
31 #include "wx/statbox.h"
33 #include "wx/slider.h"
34 #include "wx/textctrl.h"
36 #include "wx/toolbar.h"
39 #include "wx/scrolbar.h"
40 #include "wx/config.h"
48 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
51 #include <strstream.h>
71 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
72 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
74 #if defined(__WXGTK__) || defined(__WXMOTIF__)
75 #include "bitmaps/load.xpm"
76 #include "bitmaps/save.xpm"
77 #include "bitmaps/new.xpm"
78 #include "bitmaps/vert.xpm"
79 #include "bitmaps/alignt.xpm"
80 #include "bitmaps/alignb.xpm"
81 #include "bitmaps/horiz.xpm"
82 #include "bitmaps/alignl.xpm"
83 #include "bitmaps/alignr.xpm"
84 #include "bitmaps/copysize.xpm"
85 #include "bitmaps/tofront.xpm"
86 #include "bitmaps/toback.xpm"
87 #include "bitmaps/help.xpm"
88 #include "bitmaps/wxwin.xpm"
90 #include "bitmaps/dialog.xpm"
91 #include "bitmaps/folder1.xpm"
92 #include "bitmaps/folder2.xpm"
93 #include "bitmaps/buttonsm.xpm"
100 wxResourceManager::wxResourceManager():
101 m_imageList(16, 16, TRUE
)
103 sm_currentResourceManager
= this;
104 m_editorFrame
= NULL
;
105 m_editorPanel
= NULL
;
107 m_editorResourceTree
= NULL
;
108 m_editorControlList
= NULL
;
110 m_symbolIdCounter
= 99;
112 m_currentFilename
= "";
113 m_symbolFilename
= "";
114 m_editorToolBar
= NULL
;
116 // Default window positions
117 m_resourceEditorWindowSize
.width
= 500;
118 m_resourceEditorWindowSize
.height
= 450;
120 m_resourceEditorWindowSize
.x
= 0;
121 m_resourceEditorWindowSize
.y
= 0;
123 m_propertyWindowSize
.width
= 300;
124 m_propertyWindowSize
.height
= 300;
127 m_helpController
= NULL
;
130 m_bitmapImage
= NULL
;
131 m_rootDialogItem
= 0;
134 wxResourceManager::~wxResourceManager()
136 sm_currentResourceManager
= NULL
;
140 if (m_helpController
)
142 m_helpController
->Quit();
143 delete m_helpController
;
144 m_helpController
= NULL
;
148 delete m_bitmapImage
;
152 bool wxResourceManager::Initialize()
154 // Set up the resource filename for each platform.
156 // dialoged.ini in the Windows directory
158 GetWindowsDirectory(buf
, 256);
159 strcat(buf
, "\\dialoged.ini");
160 m_optionsResourceFilename
= buf
;
161 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
162 wxGetHomeDir( &m_optionsResourceFilename
);
163 m_optionsResourceFilename
+= "/.dialogedrc";
165 #error "Unsupported platform."
171 m_helpController
= new wxHelpController
;
172 m_helpController
->Initialize("dialoged");
175 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
176 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
177 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
182 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
184 #if defined(__WXGTK__) || defined(__WXMOTIF__)
185 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
189 // Initialize the image list icons
191 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
192 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
193 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
194 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
196 wxIcon
icon1( dialog_xpm
);
197 wxIcon
icon2( folder1_xpm
);
198 wxIcon
icon3( folder2_xpm
);
199 wxIcon
icon4( buttonsm_xpm
);
201 m_imageList
.Add(icon1
);
202 m_imageList
.Add(icon2
);
203 m_imageList
.Add(icon3
);
204 m_imageList
.Add(icon4
);
206 m_symbolTable
.AddStandardSymbols();
211 bool wxResourceManager::LoadOptions()
213 wxConfig
config("DialogEd", "wxWindows");
215 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
216 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
217 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
218 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
219 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
220 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
221 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
222 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
225 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
226 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
227 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
228 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
229 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
230 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
231 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
232 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
237 bool wxResourceManager::SaveOptions()
239 wxConfig
config("DialogEd", "wxWindows");
241 config
.Write("editorWindowX", m_resourceEditorWindowSize
.x
);
242 config
.Write("editorWindowY", m_resourceEditorWindowSize
.y
);
243 config
.Write("editorWindowWidth", m_resourceEditorWindowSize
.width
);
244 config
.Write("editorWindowHeight", m_resourceEditorWindowSize
.height
);
245 config
.Write("propertyWindowX", m_propertyWindowSize
.x
);
246 config
.Write("propertyWindowY", m_propertyWindowSize
.y
);
247 config
.Write("propertyWindowWidth", m_propertyWindowSize
.width
);
248 config
.Write("propertyWindowHeight", m_propertyWindowSize
.height
);
250 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
251 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
252 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
253 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
255 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
256 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
257 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
258 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
264 // Show or hide the resource editor frame, which displays a list
265 // of resources with ability to edit them.
266 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
272 m_editorFrame
->Iconize(FALSE
);
273 m_editorFrame
->Show(TRUE
);
276 m_editorFrame
= OnCreateEditorFrame(title
);
278 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
279 m_editorFrame
->SetMenuBar(menuBar
);
281 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
282 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
283 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
285 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
287 m_editorResourceTree
->SetImageList(& m_imageList
);
289 // Constraints for toolbar
290 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
291 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
292 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
293 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
294 c
->bottom
.Unconstrained();
295 c
->width
.Unconstrained();
296 c
->height
.Absolute(28);
297 m_editorToolBar
->SetConstraints(c
);
299 // Constraints for listbox
300 c
= new wxLayoutConstraints
;
301 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
302 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
303 c
->right
.Absolute (150);
304 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
305 c
->width
.Unconstrained();
306 c
->height
.Unconstrained();
307 m_editorResourceTree
->SetConstraints(c
);
309 // Constraints for panel
310 c
= new wxLayoutConstraints
;
311 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
312 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
313 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
314 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
315 c
->width
.Unconstrained();
316 c
->height
.Unconstrained();
317 m_editorPanel
->SetConstraints(c
);
319 // Constraints for control list (bottom window)
320 c
= new wxLayoutConstraints
;
321 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
322 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
323 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
324 c
->width
.Unconstrained();
325 #if defined(__WXGTK__) || defined(__WXMOTIF__)
326 c
->height
.Absolute(120);
328 c
->height
.Absolute(60);
331 m_editorControlList
->SetConstraints(c
);
333 m_editorFrame
->SetAutoLayout(TRUE
);
335 UpdateResourceList();
337 m_editorFrame
->Show(TRUE
);
342 wxFrame
*fr
= m_editorFrame
;
343 if (m_editorFrame
->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);
750 panel
->SetScrollbars(10, 10, 100, 100);
755 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
757 // Load palette bitmaps
759 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
760 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
761 wxBitmap
ToolbarNewBitmap("NEWTOOL");
762 wxBitmap
ToolbarVertBitmap("VERTTOOL");
763 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
764 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
765 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
766 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
767 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
768 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
769 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
770 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
771 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
773 #if defined(__WXGTK__) || defined(__WXMOTIF__)
774 wxBitmap
ToolbarLoadBitmap( load_xpm
);
775 wxBitmap
ToolbarSaveBitmap( save_xpm
);
776 wxBitmap
ToolbarNewBitmap( new_xpm
);
777 wxBitmap
ToolbarVertBitmap( vert_xpm
);
778 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
779 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
780 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
781 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
782 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
783 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
784 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
785 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
786 wxBitmap
ToolbarHelpBitmap( help_xpm
);
789 // Create the toolbar
790 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
791 toolbar
->SetMargins(2, 2);
798 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
803 toolbar
->AddSeparator();
804 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
805 FALSE
, currentX
, -1, NULL
, "New dialog");
806 currentX
+= width
+ dx
;
807 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
808 FALSE
, currentX
, -1, NULL
, "Load");
809 currentX
+= width
+ dx
;
810 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
811 FALSE
, currentX
, -1, NULL
, "Save");
812 currentX
+= width
+ dx
+ gap
;
813 toolbar
->AddSeparator();
814 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
815 FALSE
, currentX
, -1, NULL
, "Horizontal align");
816 currentX
+= width
+ dx
;
817 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
818 FALSE
, currentX
, -1, NULL
, "Top align");
819 currentX
+= width
+ dx
;
820 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
821 FALSE
, currentX
, -1, NULL
, "Bottom align");
822 currentX
+= width
+ dx
;
823 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
824 FALSE
, currentX
, -1, NULL
, "Vertical align");
825 currentX
+= width
+ dx
;
826 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
827 FALSE
, currentX
, -1, NULL
, "Left align");
828 currentX
+= width
+ dx
;
829 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
830 FALSE
, currentX
, -1, NULL
, "Right align");
831 currentX
+= width
+ dx
;
832 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
833 FALSE
, currentX
, -1, NULL
, "Copy size");
834 currentX
+= width
+ dx
+ gap
;
835 toolbar
->AddSeparator();
836 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
837 FALSE
, currentX
, -1, NULL
, "To front");
838 currentX
+= width
+ dx
;
839 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
840 FALSE
, currentX
, -1, NULL
, "To back");
841 currentX
+= width
+ dx
+ gap
;
843 toolbar
->AddSeparator();
844 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
845 FALSE
, currentX
, -1, NULL
, "Help");
846 currentX
+= width
+ dx
;
853 void wxResourceManager::UpdateResourceList()
855 if (!m_editorResourceTree
)
858 m_editorResourceTree
->SetInvalid(TRUE
);
859 m_editorResourceTree
->DeleteAllItems();
861 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
863 m_resourceTable
.BeginFind();
865 while ((node
= m_resourceTable
.Next()))
867 wxItemResource
*res
= (wxItemResource
*)node
->Data();
868 wxString
resType(res
->GetType());
869 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
871 AddItemsRecursively(id
, res
);
874 m_editorResourceTree
->Expand(id
);
875 m_editorResourceTree
->SetInvalid(FALSE
);
878 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
880 wxString
theString("");
881 theString
= resource
->GetName();
884 wxString
resType(resource
->GetType());
885 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
890 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
892 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
894 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
896 wxNode
*node
= resource
->GetChildren().First();
899 wxItemResource
*res
= (wxItemResource
*)node
->Data();
900 AddItemsRecursively(id
, res
);
904 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
907 bool wxResourceManager::EditSelectedResource()
909 int sel
= m_editorResourceTree
->GetSelection();
912 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
913 wxItemResource
*res
= data
->GetResource();
919 bool wxResourceManager::Edit(wxItemResource
*res
)
921 ClearCurrentDialog();
923 wxString
resType(res
->GetType());
924 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
928 wxMessageBox("Should not find panel in wxResourceManager::Edit");
933 // long style = res->GetStyle();
934 // res->SetStyle(style|wxRAISED_BORDER);
936 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
939 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
941 panel
->PushEventHandler(handler
);
943 // res->SetStyle(style);
944 handler
->AddChildHandlers(); // Add event handlers for all controls
945 AssociateResource(res
, panel
);
947 m_editorPanel
->m_childWindow
= panel
;
948 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
952 wxClientDC
dc(m_editorPanel
);
953 m_editorPanel
->DrawTitle(dc
);
958 bool wxResourceManager::CreateNewPanel()
960 ClearCurrentDialog();
963 MakeUniqueName("dialog", buf
);
965 wxItemResource
*resource
= new wxItemResource
;
966 resource
->SetType("wxDialog");
967 resource
->SetName(buf
);
968 resource
->SetTitle(buf
);
969 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
970 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
973 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
976 // This is now guaranteed to be unique, so just add to symbol table
977 m_symbolTable
.AddSymbol(newIdName
, id
);
979 m_resourceTable
.AddResource(resource
);
981 wxSize
size(400, 300);
983 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
984 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
985 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
986 m_editorPanel
->m_childWindow
= panel
;
988 resource
->SetStyle(panel
->GetWindowStyleFlag());
990 // Store dialog units in resource
991 size
= panel
->ConvertPixelsToDialog(size
);
993 resource
->SetSize(10, 10, size
.x
, size
.y
);
995 // For editing in situ we will need to use the hash table to ensure
996 // we don't dereference invalid pointers.
997 // resourceWindowTable.Put((long)resource, panel);
999 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
1001 panel
->PushEventHandler(handler
);
1003 AssociateResource(resource
, panel
);
1004 UpdateResourceList();
1007 m_editorPanel
->m_childWindow
->Refresh();
1009 // panel->Refresh();
1011 wxClientDC
dc(m_editorPanel
);
1012 m_editorPanel
->DrawTitle(dc
);
1017 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1020 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1025 wxItemResource
*res
= new wxItemResource
;
1026 wxControl
*newItem
= NULL
;
1028 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1030 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1031 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1033 else res
->SetSize(x
, y
, -1, -1);
1035 res
->SetType(iType
);
1039 wxString
itemType(iType
);
1041 if (itemType
== "wxButton")
1043 prefix
= "ID_BUTTON";
1044 MakeUniqueName("button", buf
);
1047 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1049 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1051 if (itemType
== "wxBitmapButton")
1053 prefix
= "ID_BITMAPBUTTON";
1054 MakeUniqueName("button", buf
);
1056 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1058 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1060 prefix
= "ID_STATIC";
1061 MakeUniqueName("statictext", buf
);
1064 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1066 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1068 else if (itemType
== "wxStaticBitmap")
1070 prefix
= "ID_STATICBITMAP";
1071 MakeUniqueName("static", buf
);
1073 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1075 else if (itemType
== "wxCheckBox")
1077 prefix
= "ID_CHECKBOX";
1078 MakeUniqueName("checkbox", buf
);
1080 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1082 else if (itemType
== "wxListBox")
1084 prefix
= "ID_LISTBOX";
1085 MakeUniqueName("listbox", buf
);
1087 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1089 else if (itemType
== "wxRadioBox")
1091 prefix
= "ID_RADIOBOX";
1092 MakeUniqueName("radiobox", buf
);
1094 wxString names
[] = { "One", "Two" };
1095 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1096 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1097 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1099 else if (itemType
== "wxRadioButton")
1101 prefix
= "ID_RADIOBUTTON";
1102 MakeUniqueName("radiobutton", buf
);
1104 wxString names
[] = { "One", "Two" };
1105 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1106 0, wxDefaultValidator
, buf
);
1108 else if (itemType
== "wxChoice")
1110 prefix
= "ID_CHOICE";
1111 MakeUniqueName("choice", buf
);
1113 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1115 else if (itemType
== "wxComboBox")
1117 prefix
= "ID_COMBOBOX";
1118 MakeUniqueName("combobox", buf
);
1120 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1122 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1124 prefix
= "ID_STATICBOX";
1125 MakeUniqueName("staticbox", buf
);
1127 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1129 else if (itemType
== "wxGauge")
1131 prefix
= "ID_GAUGE";
1132 MakeUniqueName("gauge", buf
);
1134 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1136 else if (itemType
== "wxSlider")
1138 prefix
= "ID_SLIDER";
1139 MakeUniqueName("slider", buf
);
1141 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1143 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1145 prefix
= "ID_TEXTCTRL";
1146 MakeUniqueName("textctrl", buf
);
1148 res
->SetType("wxTextCtrl");
1149 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1151 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1153 prefix
= "ID_TEXTCTRL";
1154 MakeUniqueName("textctrl", buf
);
1156 res
->SetType("wxTextCtrl");
1157 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1159 else if (itemType
== "wxScrollBar")
1161 prefix
= "ID_SCROLLBAR";
1162 MakeUniqueName("scrollbar", buf
);
1164 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1169 int actualW
, actualH
;
1170 newItem
->GetSize(&actualW
, &actualH
);
1171 wxSize
actualSize(actualW
, actualH
);
1173 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1175 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1177 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1180 int id
= GenerateWindowId(prefix
, newIdName
);
1183 // This is now guaranteed to be unique, so just add to symbol table
1184 m_symbolTable
.AddSymbol(newIdName
, id
);
1186 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1188 res
->SetStyle(newItem
->GetWindowStyleFlag());
1189 AssociateResource(res
, newItem
);
1190 panelResource
->GetChildren().Append(res
);
1192 UpdateResourceList();
1197 void wxResourceManager::ClearCurrentDialog()
1199 if (m_editorPanel
->m_childWindow
)
1201 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1202 DisassociateResource(m_editorPanel
->m_childWindow
);
1203 DeleteWindow(m_editorPanel
->m_childWindow
);
1204 m_editorPanel
->m_childWindow
= NULL
;
1205 m_editorPanel
->Clear();
1209 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1211 if (m_editorPanel
->m_childWindow
)
1213 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1217 // Make sure the resources are up-to-date w.r.t. the window
1218 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1220 wxDialog
* dialog
= new wxDialog
;
1221 bool success
= FALSE
;
1222 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1225 dialog
->ShowModal();
1233 // Find the first dialog or panel for which
1234 // there is a selected panel item.
1235 wxWindow
*wxResourceManager::FindParentOfSelection()
1237 m_resourceTable
.BeginFind();
1239 while ((node
= m_resourceTable
.Next()))
1241 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1242 wxWindow
*win
= FindWindowForResource(res
);
1245 wxNode
*node1
= win
->GetChildren().First();
1248 wxControl
*item
= (wxControl
*)node1
->Data();
1249 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1250 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1252 node1
= node1
->Next();
1259 // Format the panel items according to 'flag'
1260 void wxResourceManager::AlignItems(int flag
)
1262 wxWindow
*win
= FindParentOfSelection();
1266 wxNode
*node
= GetSelections().First();
1270 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1271 if (firstSelection
->GetParent() != win
)
1276 firstSelection
->GetPosition(&firstX
, &firstY
);
1277 firstSelection
->GetSize(&firstW
, &firstH
);
1278 int centreX
= (int)(firstX
+ (firstW
/ 2));
1279 int centreY
= (int)(firstY
+ (firstH
/ 2));
1281 while ((node
= node
->Next()))
1283 wxControl
*item
= (wxControl
*)node
->Data();
1284 if (item
->GetParent() == win
)
1287 item
->GetPosition(&x
, &y
);
1288 item
->GetSize(&w
, &h
);
1294 case TOOLBAR_FORMAT_HORIZ
:
1297 newY
= (int)(centreY
- (h
/2.0));
1300 case TOOLBAR_FORMAT_VERT
:
1302 newX
= (int)(centreX
- (w
/2.0));
1306 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1312 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1318 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1320 newX
= firstX
+ firstW
- w
;
1324 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1327 newY
= firstY
+ firstH
- h
;
1335 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1336 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1338 item
->SetSize(newX
, newY
, w
, h
);
1340 // Also update the associated resource
1341 // We need to convert to dialog units if this is not a dialog or panel, but
1342 // the parent resource specifies dialog units.
1343 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1345 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1346 newX
= pt
.x
; newY
= pt
.y
;
1347 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1350 resource
->SetSize(newX
, newY
, w
, h
);
1356 // Copy the first image's size to subsequent images
1357 void wxResourceManager::CopySize()
1359 wxWindow
*win
= FindParentOfSelection();
1363 wxNode
*node
= GetSelections().First();
1367 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1368 if (firstSelection
->GetParent() != win
)
1373 firstSelection
->GetPosition(&firstX
, &firstY
);
1374 firstSelection
->GetSize(&firstW
, &firstH
);
1376 while ((node
= node
->Next()))
1378 wxControl
*item
= (wxControl
*)node
->Data();
1379 if (item
->GetParent() == win
)
1381 item
->SetSize(-1, -1, firstW
, firstH
);
1383 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1384 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1386 // Also update the associated resource
1387 // We need to convert to dialog units if this is not a dialog or panel, but
1388 // the parent resource specifies dialog units.
1389 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1391 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1392 firstW
= sz
.x
; firstH
= sz
.y
;
1394 resource
->SetSize(resource
->GetX(), resource
->GetY(), firstW
, firstH
);
1401 void wxResourceManager::ToBackOrFront(bool toBack
)
1403 wxWindow
*win
= FindParentOfSelection();
1406 wxItemResource
*winResource
= FindResourceForWindow(win
);
1408 wxNode
*node
= GetSelections().First();
1411 wxControl
*item
= (wxControl
*)node
->Data();
1412 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1413 if (item
->GetParent() == win
)
1415 win
->GetChildren().DeleteObject(item
);
1417 winResource
->GetChildren().DeleteObject(itemResource
);
1420 win
->GetChildren().Insert(item
);
1422 winResource
->GetChildren().Insert(itemResource
);
1426 win
->GetChildren().Append(item
);
1428 winResource
->GetChildren().Append(itemResource
);
1431 node
= node
->Next();
1436 void wxResourceManager::AddSelection(wxWindow
*win
)
1438 if (!m_selections
.Member(win
))
1439 m_selections
.Append(win
);
1442 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1444 m_selections
.DeleteObject(win
);
1447 // Need to search through resource table removing this from
1448 // any resource which has this as a parent.
1449 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1451 m_resourceTable
.BeginFind();
1453 while ((node
= m_resourceTable
.Next()))
1455 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1456 if (thisRes
->GetChildren().Member(res
))
1458 thisRes
->GetChildren().DeleteObject(res
);
1465 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1470 RemoveResourceFromParent(res
);
1472 wxNode
*node
= res
->GetChildren().First();
1475 wxNode
*next
= node
->Next();
1476 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1477 DeleteResource(child
);
1481 // If this is a button or message resource, delete the
1482 // associate bitmap resource if not being used.
1483 wxString
resType(res
->GetType());
1485 /* shouldn't have to do this now bitmaps are ref-counted
1486 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1488 PossiblyDeleteBitmapResource(res->GetValue4());
1492 // Remove symbol from table if appropriate
1493 if (!IsSymbolUsed(res
, res
->GetId()))
1495 m_symbolTable
.RemoveSymbol(res
->GetId());
1498 m_resourceTable
.Delete(res
->GetName());
1504 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1506 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1508 // Deselect and refresh window in case we leave selection
1510 wxControl
*item
= (wxControl
*)win
;
1511 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1512 if (childHandler
->IsSelected())
1514 RemoveSelection(item
);
1515 childHandler
->SelectItem(FALSE
);
1517 item
->GetParent()->Refresh();
1522 wxItemResource
*res
= FindResourceForWindow(win
);
1524 DisassociateResource(res
);
1525 DeleteResource(res
);
1526 UpdateResourceList();
1531 // Will eventually have bitmap type information, for different
1533 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1535 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1539 MakeUniqueName("bitmap", buf
);
1540 resource
= new wxItemResource
;
1541 resource
->SetType("wxBitmap");
1542 resource
->SetName(buf
);
1544 // A bitmap resource has one or more children, specifying
1545 // alternative bitmaps.
1546 wxItemResource
*child
= new wxItemResource
;
1547 child
->SetType("wxBitmap");
1548 child
->SetName(filename
);
1549 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1550 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1551 child
->SetValue3(0); // Depth
1552 child
->SetSize(0,0,0,0);
1553 resource
->GetChildren().Append(child
);
1555 m_resourceTable
.AddResource(resource
);
1557 UpdateResourceList();
1560 return resource
->GetName();
1562 return wxEmptyString
;
1565 // Delete the bitmap resource if it isn't being used by another resource.
1566 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1568 if (!IsBitmapResourceUsed(resourceName
))
1570 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1571 DeleteResource(res
);
1572 UpdateResourceList();
1576 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1578 m_resourceTable
.BeginFind();
1580 while ((node
= m_resourceTable
.Next()))
1582 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1583 wxString
resType(res
->GetType());
1584 if (resType
== "wxDialog")
1586 wxNode
*node1
= res
->GetChildren().First();
1589 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1590 wxString
childResType(child
->GetType());
1592 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1593 child
->GetValue4() &&
1594 (strcmp(child
->GetValue4(), resourceName
) == 0))
1596 node1
= node1
->Next();
1603 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1604 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1606 if (!resource
|| (resource
->GetValue4() == ""))
1607 return wxEmptyString
;
1608 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1609 if (!bitmapResource
)
1610 return wxEmptyString
;
1612 wxNode
*node
= bitmapResource
->GetChildren().First();
1615 // Eventually augment this to return a bitmap of the right kind or something...
1616 // Maybe the root of the filename remains the same, so it doesn't matter which we
1617 // pick up. Otherwise how do we specify multiple filenames... too boring...
1618 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1619 return child
->GetName();
1621 node
= node
->Next();
1623 return wxEmptyString
;
1626 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1628 m_resourceTable
.BeginFind();
1630 while ((node
= m_resourceTable
.Next()))
1632 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1633 wxString
resType(res
->GetType());
1634 if (resType
== "wxBitmap")
1636 wxNode
*node1
= res
->GetChildren().First();
1639 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1640 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1642 node1
= node1
->Next();
1649 // Is this window identifier symbol in use?
1650 // Let's assume that we can't have 2 names for the same integer id.
1651 // Therefore we can tell by the integer id whether the symbol is
1653 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1655 m_resourceTable
.BeginFind();
1657 while ((node
= m_resourceTable
.Next()))
1659 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1661 wxString
resType(res
->GetType());
1662 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1664 if ((res
!= thisResource
) && (res
->GetId() == id
))
1667 wxNode
*node1
= res
->GetChildren().First();
1670 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1671 if ((child
!= thisResource
) && (child
->GetId() == id
))
1673 node1
= node1
->Next();
1680 // Is this window identifier compatible with the given name? (i.e.
1681 // does it already exist under a different name)
1682 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1684 if (m_symbolTable
.SymbolExists(name
))
1686 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1693 // Change all integer ids that match oldId, to newId.
1694 // This is necessary if an id is changed for one resource - all resources
1696 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1698 m_resourceTable
.BeginFind();
1700 while ((node
= m_resourceTable
.Next()))
1702 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1704 wxString
resType(res
->GetType());
1705 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1707 if (res
->GetId() == oldId
)
1710 wxNode
*node1
= res
->GetChildren().First();
1713 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1714 if (child
->GetId() == oldId
)
1715 child
->SetId(newId
);
1717 node1
= node1
->Next();
1723 // If any resource ids were missing (or their symbol was missing),
1724 // repair them i.e. give them new ids. Returns TRUE if any resource
1725 // needed repairing.
1726 bool wxResourceManager::RepairResourceIds()
1728 bool repaired
= FALSE
;
1730 m_resourceTable
.BeginFind();
1732 while ((node
= m_resourceTable
.Next()))
1734 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1735 wxString
resType(res
->GetType());
1736 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1739 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1741 wxString newSymbolName
;
1742 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1744 if (res
->GetId() == 0)
1747 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1751 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1757 wxNode
*node1
= res
->GetChildren().First();
1760 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1762 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1764 wxString newSymbolName
;
1765 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1767 if (child
->GetId() == 0)
1769 child
->SetId(newId
);
1770 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1774 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1780 node1
= node1
->Next();
1788 // Deletes 'win' and creates a new window from the resource that
1789 // was associated with it. E.g. if you can't change properties on the
1790 // fly, you'll need to delete the window and create it again.
1791 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1793 wxItemResource
*resource
= FindResourceForWindow(win
);
1795 // Put the current window properties into the wxItemResource object
1797 wxWindowPropertyInfo
*newInfo
= NULL
;
1800 newInfo
= CreatePropertyInfoForWindow(win
);
1804 info
->InstantiateResource(resource
);
1806 wxWindow
*newWin
= NULL
;
1807 wxWindow
*parent
= win
->GetParent();
1808 wxItemResource
* parentResource
= NULL
;
1810 parentResource
= FindResourceForWindow(parent
);
1812 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1815 newWin
= FindWindowForResource(resource
);
1819 DisassociateResource(resource
);
1820 if (win
->GetEventHandler() != win
)
1821 win
->PopEventHandler(TRUE
);
1824 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1825 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1826 AssociateResource(resource
, newWin
);
1827 UpdateResourceList();
1831 info
->SetPropertyWindow(newWin
);
1839 // Delete resource highlighted in the listbox
1840 bool wxResourceManager::DeleteSelection()
1842 int sel
= m_editorResourceTree
->GetSelection();
1845 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1846 wxItemResource
*res
= data
->GetResource();
1847 wxWindow
*win
= FindWindowForResource(res
);
1850 DeleteResource(win
);
1852 UpdateResourceList();
1861 // Delete resource highlighted in the listbox
1862 bool wxResourceManager::RecreateSelection()
1864 wxNode
*node
= GetSelections().First();
1867 wxControl
*item
= (wxControl
*)node
->Data();
1868 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1869 wxNode
*next
= node
->Next();
1870 childHandler
->SelectItem(FALSE
);
1872 RemoveSelection(item
);
1874 RecreateWindowFromResource(item
);
1881 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
1886 // Ensures that all currently shown windows are saved to resources,
1887 // e.g. just before writing to a .wxr file.
1888 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1890 m_resourceTable
.BeginFind();
1892 while ((node
= m_resourceTable
.Next()))
1894 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1895 wxString
resType(res
->GetType());
1897 if (resType
== "wxDialog")
1899 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1901 InstantiateResourceFromWindow(res
, win
, TRUE
);
1903 else if (resType
== "wxPanel")
1905 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1907 InstantiateResourceFromWindow(res
, win
, TRUE
);
1913 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1915 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1916 info
->SetResource(resource
);
1917 info
->InstantiateResource(resource
);
1922 wxNode
*node
= resource
->GetChildren().First();
1925 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1926 wxWindow
*childWindow
= FindWindowForResource(child
);
1931 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
1932 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1935 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1936 node
= node
->Next();
1943 // Create a window information object for the give window
1944 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1946 wxWindowPropertyInfo
*info
= NULL
;
1947 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1949 info
= new wxScrollBarPropertyInfo(win
);
1951 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1953 info
= new wxGroupBoxPropertyInfo(win
);
1955 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1957 info
= new wxCheckBoxPropertyInfo(win
);
1959 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1961 info
= new wxSliderPropertyInfo(win
);
1963 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1965 info
= new wxGaugePropertyInfo(win
);
1967 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1969 info
= new wxListBoxPropertyInfo(win
);
1971 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1973 info
= new wxRadioBoxPropertyInfo(win
);
1975 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1977 info
= new wxRadioButtonPropertyInfo(win
);
1979 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
1981 info
= new wxComboBoxPropertyInfo(win
);
1983 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1985 info
= new wxChoicePropertyInfo(win
);
1987 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1989 info
= new wxBitmapButtonPropertyInfo(win
);
1991 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1993 info
= new wxButtonPropertyInfo(win
);
1995 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1997 info
= new wxStaticBitmapPropertyInfo(win
);
1999 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
2001 info
= new wxStaticTextPropertyInfo(win
);
2003 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
2005 info
= new wxTextPropertyInfo(win
);
2007 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
2009 info
= new wxPanelPropertyInfo(win
);
2013 info
= new wxWindowPropertyInfo(win
);
2018 // Edit the given window
2019 void wxResourceManager::EditWindow(wxWindow
*win
)
2021 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2024 info
->SetResource(FindResourceForWindow(win
));
2025 wxString
str("Editing ");
2026 str
+= win
->GetClassInfo()->GetClassName();
2028 if (win
->GetName() != "")
2029 str
+= win
->GetName();
2031 str
+= "properties";
2032 info
->Edit(NULL
, str
);
2036 // Generate a window id and a first stab at a name
2037 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2039 m_symbolIdCounter
++;
2040 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2041 m_symbolIdCounter
++;
2043 int nameId
= m_symbolIdCounter
;
2046 str
.Printf("%d", nameId
);
2047 idName
= prefix
+ str
;
2049 while (m_symbolTable
.SymbolExists(idName
))
2052 str
.Printf("%d", nameId
);
2053 idName
= prefix
+ str
;
2056 return m_symbolIdCounter
;
2061 * Resource editor frame
2064 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2066 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2067 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2068 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2069 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2070 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2071 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2072 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2073 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2074 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2075 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2076 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2077 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2078 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2081 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2082 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2083 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2088 wxResourceEditorFrame::~wxResourceEditorFrame()
2092 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2094 manager
->New(FALSE
);
2097 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2099 manager
->CreateNewPanel();
2102 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2107 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2109 manager
->Clear(TRUE
, FALSE
);
2112 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2117 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2122 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2124 manager
->Clear(TRUE
, FALSE
) ;
2128 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2131 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
2132 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2135 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2137 manager
->TestCurrentDialog(this);
2140 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2143 wxBeginBusyCursor();
2144 manager
->GetHelpController()->LoadFile();
2145 manager
->GetHelpController()->DisplayContents();
2150 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2152 manager
->DeleteSelection();
2155 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2157 manager
->RecreateSelection();
2160 bool wxResourceEditorFrame::OnClose()
2162 if (manager
->Modified())
2164 if (!manager
->Clear(TRUE
, FALSE
))
2172 manager
->m_resourceEditorWindowSize
.width
= w
;
2173 manager
->m_resourceEditorWindowSize
.height
= h
;
2176 GetPosition(&x
, &y
);
2178 manager
->m_resourceEditorWindowSize
.x
= x
;
2179 manager
->m_resourceEditorWindowSize
.y
= y
;
2181 manager
->SetEditorFrame(NULL
);
2182 manager
->SetEditorToolBar(NULL
);
2188 * Resource editor window that contains the dialog/panel being edited
2191 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2192 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
2193 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2196 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2198 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2202 m_childWindow
= NULL
;
2204 SetBackgroundColour(* wxWHITE
);
2207 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2211 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
2213 wxScrolledWindow::OnScroll(event
);
2216 ViewStart(& x
, & y
);
2219 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
2222 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2229 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2233 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2236 wxString
str(res
->GetTitle());
2238 ViewStart(& x
, & y
);
2240 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2242 dc
.SetBackgroundMode(wxTRANSPARENT
);
2243 dc
.SetTextForeground(wxColour(0, 0, 0));
2246 dc
.GetTextExtent(str
, & w
, & h
);
2248 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2253 // Popup menu callback
2254 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2256 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2260 switch (event
.GetInt())
2262 case OBJECT_MENU_EDIT
:
2264 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2267 case OBJECT_MENU_DELETE
:
2269 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2270 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2271 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2284 #if defined(__WXGTK__) || defined(__WXMOTIF__) // I don't dare to delete it...
2286 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2291 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2292 EVT_PAINT(EditorToolBar::OnPaint
)
2297 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2299 wxToolBar(frame
, -1, pos
, size
, style
)
2303 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2305 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2309 case TOOLBAR_LOAD_FILE
:
2316 manager
->CreateNewPanel();
2319 case TOOLBAR_SAVE_FILE
:
2327 wxBeginBusyCursor();
2328 manager
->GetHelpController()->LoadFile();
2329 manager
->GetHelpController()->DisplayContents();
2334 case TOOLBAR_FORMAT_HORIZ
:
2336 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2339 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2341 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2344 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2346 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2349 case TOOLBAR_FORMAT_VERT
:
2351 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2354 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2356 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2359 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2361 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2364 case TOOLBAR_COPY_SIZE
:
2366 manager
->CopySize();
2369 case TOOLBAR_TO_BACK
:
2371 manager
->ToBackOrFront(TRUE
);
2374 case TOOLBAR_TO_FRONT
:
2376 manager
->ToBackOrFront(FALSE
);
2385 void EditorToolBar::OnMouseEnter(int toolIndex
)
2387 wxFrame
*frame
= (wxFrame
*)GetParent();
2395 case TOOLBAR_LOAD_FILE
:
2396 frame
->SetStatusText("Load project file");
2398 case TOOLBAR_SAVE_FILE
:
2399 frame
->SetStatusText("Save project file");
2402 frame
->SetStatusText("Create a new resource");
2404 case TOOLBAR_FORMAT_HORIZ
:
2405 frame
->SetStatusText("Align items horizontally");
2407 case TOOLBAR_FORMAT_VERT
:
2408 frame
->SetStatusText("Align items vertically");
2410 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2411 frame
->SetStatusText("Left-align items");
2413 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2414 frame
->SetStatusText("Right-align items");
2416 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2417 frame
->SetStatusText("Top-align items");
2419 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2420 frame
->SetStatusText("Bottom-align items");
2422 case TOOLBAR_COPY_SIZE
:
2423 frame
->SetStatusText("Copy size from first selection");
2425 case TOOLBAR_TO_FRONT
:
2426 frame
->SetStatusText("Put image to front");
2428 case TOOLBAR_TO_BACK
:
2429 frame
->SetStatusText("Put image to back");
2432 frame
->SetStatusText("Display help contents");
2438 else frame
->SetStatusText("");