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>
67 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
68 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
70 #if defined(__WXGTK__) || defined(__WXMOTIF__)
71 #include "bitmaps/load.xpm"
72 #include "bitmaps/save.xpm"
73 #include "bitmaps/new.xpm"
74 #include "bitmaps/vert.xpm"
75 #include "bitmaps/alignt.xpm"
76 #include "bitmaps/alignb.xpm"
77 #include "bitmaps/horiz.xpm"
78 #include "bitmaps/alignl.xpm"
79 #include "bitmaps/alignr.xpm"
80 #include "bitmaps/copysize.xpm"
81 #include "bitmaps/tofront.xpm"
82 #include "bitmaps/toback.xpm"
83 #include "bitmaps/help.xpm"
84 #include "bitmaps/wxwin.xpm"
86 #include "bitmaps/dialog.xpm"
87 #include "bitmaps/folder1.xpm"
88 #include "bitmaps/folder2.xpm"
89 #include "bitmaps/buttonsm.xpm"
96 wxResourceManager::wxResourceManager():
97 m_imageList(16, 16, TRUE
)
99 sm_currentResourceManager
= this;
100 m_editorFrame
= NULL
;
101 m_editorPanel
= NULL
;
103 m_editorResourceTree
= NULL
;
104 m_editorControlList
= NULL
;
106 m_symbolIdCounter
= 99;
108 m_currentFilename
= "";
109 m_symbolFilename
= "";
110 m_editorToolBar
= NULL
;
112 // Default window positions
113 m_resourceEditorWindowSize
.width
= 500;
114 m_resourceEditorWindowSize
.height
= 450;
116 m_resourceEditorWindowSize
.x
= 0;
117 m_resourceEditorWindowSize
.y
= 0;
119 m_propertyWindowSize
.width
= 300;
120 m_propertyWindowSize
.height
= 300;
123 m_helpController
= NULL
;
126 m_bitmapImage
= NULL
;
127 m_rootDialogItem
= 0;
130 wxResourceManager::~wxResourceManager()
132 sm_currentResourceManager
= NULL
;
136 if (m_helpController
)
138 m_helpController
->Quit();
139 delete m_helpController
;
140 m_helpController
= NULL
;
144 delete m_bitmapImage
;
148 bool wxResourceManager::Initialize()
150 // Set up the resource filename for each platform.
151 // TODO: This shold be replaced by wxConfig usage.
153 // dialoged.ini in the Windows directory
154 wxString windowsDir
= wxGetOSDirectory();
155 windowsDir
+= "\\dialoged.ini" ;
157 m_optionsResourceFilename
= windowsDir
;
158 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
159 wxGetHomeDir( &m_optionsResourceFilename
);
160 m_optionsResourceFilename
+= "/.dialogedrc";
162 #error "Unsupported platform."
168 m_helpController
= new wxHelpController
;
169 m_helpController
->Initialize("dialoged");
172 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
173 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
174 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
179 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
181 #if defined(__WXGTK__) || defined(__WXMOTIF__)
182 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
186 // Initialize the image list icons
188 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
189 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
190 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
191 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
193 wxIcon
icon1( dialog_xpm
);
194 wxIcon
icon2( folder1_xpm
);
195 wxIcon
icon3( folder2_xpm
);
196 wxIcon
icon4( buttonsm_xpm
);
198 m_imageList
.Add(icon1
);
199 m_imageList
.Add(icon2
);
200 m_imageList
.Add(icon3
);
201 m_imageList
.Add(icon4
);
203 m_symbolTable
.AddStandardSymbols();
208 bool wxResourceManager::LoadOptions()
210 wxConfig
config("DialogEd", "wxWindows");
212 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
213 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
214 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
215 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
216 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
217 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
218 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
219 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
222 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
223 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
224 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
225 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
226 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
227 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
228 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
229 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
234 bool wxResourceManager::SaveOptions()
236 wxConfig
config("DialogEd", "wxWindows");
238 config
.Write("editorWindowX", m_resourceEditorWindowSize
.x
);
239 config
.Write("editorWindowY", m_resourceEditorWindowSize
.y
);
240 config
.Write("editorWindowWidth", m_resourceEditorWindowSize
.width
);
241 config
.Write("editorWindowHeight", m_resourceEditorWindowSize
.height
);
242 config
.Write("propertyWindowX", m_propertyWindowSize
.x
);
243 config
.Write("propertyWindowY", m_propertyWindowSize
.y
);
244 config
.Write("propertyWindowWidth", m_propertyWindowSize
.width
);
245 config
.Write("propertyWindowHeight", m_propertyWindowSize
.height
);
247 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
248 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
249 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
250 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
252 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
253 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
254 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
255 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
261 // Show or hide the resource editor frame, which displays a list
262 // of resources with ability to edit them.
263 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
269 m_editorFrame
->Iconize(FALSE
);
270 m_editorFrame
->Show(TRUE
);
273 m_editorFrame
= OnCreateEditorFrame(title
);
275 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
276 m_editorFrame
->SetMenuBar(menuBar
);
278 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
279 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
280 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
282 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
284 m_editorResourceTree
->SetImageList(& m_imageList
);
286 // Constraints for toolbar
287 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
288 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
289 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
290 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
291 c
->bottom
.Unconstrained();
292 c
->width
.Unconstrained();
293 c
->height
.Absolute(28);
294 m_editorToolBar
->SetConstraints(c
);
296 // Constraints for listbox
297 c
= new wxLayoutConstraints
;
298 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
299 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
300 c
->right
.Absolute (150);
301 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
302 c
->width
.Unconstrained();
303 c
->height
.Unconstrained();
304 m_editorResourceTree
->SetConstraints(c
);
306 // Constraints for panel
307 c
= new wxLayoutConstraints
;
308 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
309 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
310 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
311 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
312 c
->width
.Unconstrained();
313 c
->height
.Unconstrained();
314 m_editorPanel
->SetConstraints(c
);
316 // Constraints for control list (bottom window)
317 c
= new wxLayoutConstraints
;
318 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
319 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
320 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
321 c
->width
.Unconstrained();
322 #if defined(__WXGTK__) || defined(__WXMOTIF__)
323 c
->height
.Absolute(120);
325 c
->height
.Absolute(60);
328 m_editorControlList
->SetConstraints(c
);
330 m_editorFrame
->SetAutoLayout(TRUE
);
332 UpdateResourceList();
334 m_editorFrame
->Show(TRUE
);
339 wxFrame
*fr
= m_editorFrame
;
340 if (m_editorFrame
->Close())
342 m_editorFrame
= NULL
;
343 m_editorPanel
= NULL
;
349 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
353 if (filename
== wxString(""))
354 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
357 wxString
str("wxWindows Dialog Editor - ");
358 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
360 m_editorFrame
->SetTitle(str
);
365 bool wxResourceManager::Save()
367 if (m_currentFilename
== wxString(""))
370 return Save(m_currentFilename
);
373 bool wxResourceManager::Save(const wxString
& filename
)
375 // Ensure all visible windows are saved to their resources
376 m_currentFilename
= filename
;
377 SetFrameTitle(m_currentFilename
);
378 InstantiateAllResourcesFromWindows();
379 if (m_resourceTable
.Save(filename
))
381 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
389 bool wxResourceManager::SaveAs()
391 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
392 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
, wxTheApp
->GetTopWindow()));
394 if (s
.IsNull() || s
== "")
397 m_currentFilename
= s
;
398 wxStripExtension(m_currentFilename
);
399 m_currentFilename
+= ".wxr";
401 // Construct include filename from this file
402 m_symbolFilename
= m_currentFilename
;
404 wxStripExtension(m_symbolFilename
);
405 m_symbolFilename
+= ".h";
407 Save(m_currentFilename
);
411 bool wxResourceManager::SaveIfModified()
418 bool wxResourceManager::Load(const wxString
& filename
)
420 return New(TRUE
, filename
);
423 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
425 if (!Clear(TRUE
, FALSE
))
428 m_symbolTable
.AddStandardSymbols();
432 wxString str
= filename
;
433 if (str
== wxString(""))
435 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, wxTheApp
->GetTopWindow()));
436 if (!f
.IsNull() && f
!= "")
442 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
444 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
447 m_currentFilename
= str
;
449 SetFrameTitle(m_currentFilename
);
451 UpdateResourceList();
453 // Construct include filename from this file
454 m_symbolFilename
= m_currentFilename
;
456 wxStripExtension(m_symbolFilename
);
457 m_symbolFilename
+= ".h";
459 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
461 wxString
str("Could not find include file ");
462 str
+= m_symbolFilename
;
463 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
464 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
465 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
467 m_symbolIdCounter
= 99;
471 // Set the id counter to the last known id
472 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
475 // Now check in case some (or all) resources don't have resource ids, or they
476 // don't match the .h file, or something of that nature.
477 bool altered
= RepairResourceIds();
480 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
481 "Dialog Editor Warning", wxOK
);
492 m_currentFilename
= "";
499 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
501 if (!force
&& Modified())
503 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
507 if (!SaveIfModified())
513 ClearCurrentDialog();
514 DisassociateWindows();
516 m_symbolTable
.Clear();
517 m_resourceTable
.ClearTable();
518 UpdateResourceList();
523 bool wxResourceManager::DisassociateWindows()
525 m_resourceTable
.BeginFind();
527 while ((node
= m_resourceTable
.Next()))
529 wxItemResource
*res
= (wxItemResource
*)node
->Data();
530 DisassociateResource(res
);
536 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
538 if (!m_resourceAssociations
.Get((long)resource
))
539 m_resourceAssociations
.Put((long)resource
, win
);
541 wxNode
*node
= resource
->GetChildren().First();
544 wxItemResource
*child
= (wxItemResource
*)node
->Data();
545 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
547 childWindow
= win
->FindWindow(child
->GetName());
549 AssociateResource(child
, childWindow
);
553 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
554 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
561 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
563 wxWindow
*win
= FindWindowForResource(resource
);
567 // Disassociate children of window
568 wxNode
*node
= win
->GetChildren().First();
571 wxWindow
*child
= (wxWindow
*)node
->Data();
572 if (child
->IsKindOf(CLASSINFO(wxControl
)))
573 DisassociateResource(child
);
577 RemoveSelection(win
);
578 m_resourceAssociations
.Delete((long)resource
);
582 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
584 wxItemResource
*res
= FindResourceForWindow(win
);
586 return DisassociateResource(res
);
591 // Saves the window info into the resource, and deletes the
592 // handler. Doesn't actually disassociate the window from
593 // the resources. Replaces OnClose.
594 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
596 wxItemResource
*res
= FindResourceForWindow(win
);
598 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
600 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
601 win
->PopEventHandler();
603 // Now reset all child event handlers
604 wxNode
*node
= win
->GetChildren().First();
607 wxWindow
*child
= (wxWindow
*)node
->Data();
608 wxEvtHandler
*childHandler
= child
->GetEventHandler();
609 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
611 child
->PopEventHandler(TRUE
);
619 win
->PopEventHandler(TRUE
);
622 // Save the information
623 InstantiateResourceFromWindow(res
, win
, TRUE
);
625 // DisassociateResource(win);
630 // Destroys the window. If this is the 'current' panel, NULLs the
632 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
634 bool clearDisplay
= FALSE
;
635 if (m_editorPanel
->m_childWindow
== win
)
637 m_editorPanel
->m_childWindow
= NULL
;
644 m_editorPanel
->Clear();
649 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
651 m_resourceAssociations
.BeginFind();
653 while ((node
= m_resourceAssociations
.Next()))
655 wxWindow
*w
= (wxWindow
*)node
->Data();
658 return (wxItemResource
*)node
->GetKeyInteger();
664 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
666 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
670 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
674 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
677 if (!m_resourceTable
.FindResource(buf
))
682 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
685 int frameWidth = 420;
686 int frameHeight = 300;
689 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
690 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
691 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
692 wxDEFAULT_FRAME_STYLE
);
694 frame
->CreateStatusBar(1);
696 frame
->SetAutoLayout(TRUE
);
698 frame
->SetIcon(wxIcon("DIALOGEDICON"));
703 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
705 wxMenuBar
*menuBar
= new wxMenuBar
;
707 wxMenu
*fileMenu
= new wxMenu
;
708 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
709 fileMenu
->AppendSeparator();
710 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
711 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
712 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
713 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
714 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
715 fileMenu
->AppendSeparator();
716 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
718 wxMenu
*editMenu
= new wxMenu
;
719 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
720 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
721 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
723 wxMenu
*helpMenu
= new wxMenu
;
724 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
725 helpMenu
->AppendSeparator();
726 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
728 menuBar
->Append(fileMenu
, "&File");
729 menuBar
->Append(editMenu
, "&Edit");
730 menuBar
->Append(helpMenu
, "&Help");
735 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
737 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
738 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
745 panel
->SetScrollbars(10, 10, 100, 100);
750 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
752 // Load palette bitmaps
754 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
755 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
756 wxBitmap
ToolbarNewBitmap("NEWTOOL");
757 wxBitmap
ToolbarVertBitmap("VERTTOOL");
758 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
759 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
760 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
761 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
762 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
763 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
764 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
765 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
766 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
768 #if defined(__WXGTK__) || defined(__WXMOTIF__)
769 wxBitmap
ToolbarLoadBitmap( load_xpm
);
770 wxBitmap
ToolbarSaveBitmap( save_xpm
);
771 wxBitmap
ToolbarNewBitmap( new_xpm
);
772 wxBitmap
ToolbarVertBitmap( vert_xpm
);
773 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
774 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
775 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
776 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
777 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
778 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
779 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
780 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
781 wxBitmap
ToolbarHelpBitmap( help_xpm
);
784 // Create the toolbar
785 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
786 toolbar
->SetMargins(2, 2);
793 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
798 toolbar
->AddSeparator();
799 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
800 FALSE
, currentX
, -1, NULL
, "New dialog");
801 currentX
+= width
+ dx
;
802 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
803 FALSE
, currentX
, -1, NULL
, "Load");
804 currentX
+= width
+ dx
;
805 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
806 FALSE
, currentX
, -1, NULL
, "Save");
807 currentX
+= width
+ dx
+ gap
;
808 toolbar
->AddSeparator();
809 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
810 FALSE
, currentX
, -1, NULL
, "Horizontal align");
811 currentX
+= width
+ dx
;
812 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
813 FALSE
, currentX
, -1, NULL
, "Top align");
814 currentX
+= width
+ dx
;
815 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
816 FALSE
, currentX
, -1, NULL
, "Bottom align");
817 currentX
+= width
+ dx
;
818 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
819 FALSE
, currentX
, -1, NULL
, "Vertical align");
820 currentX
+= width
+ dx
;
821 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
822 FALSE
, currentX
, -1, NULL
, "Left align");
823 currentX
+= width
+ dx
;
824 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
825 FALSE
, currentX
, -1, NULL
, "Right align");
826 currentX
+= width
+ dx
;
827 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
828 FALSE
, currentX
, -1, NULL
, "Copy size");
829 currentX
+= width
+ dx
+ gap
;
830 toolbar
->AddSeparator();
831 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
832 FALSE
, currentX
, -1, NULL
, "To front");
833 currentX
+= width
+ dx
;
834 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
835 FALSE
, currentX
, -1, NULL
, "To back");
836 currentX
+= width
+ dx
+ gap
;
838 toolbar
->AddSeparator();
839 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
840 FALSE
, currentX
, -1, NULL
, "Help");
841 currentX
+= width
+ dx
;
848 void wxResourceManager::UpdateResourceList()
850 if (!m_editorResourceTree
)
853 m_editorResourceTree
->SetInvalid(TRUE
);
854 m_editorResourceTree
->DeleteAllItems();
856 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
858 m_resourceTable
.BeginFind();
860 while ((node
= m_resourceTable
.Next()))
862 wxItemResource
*res
= (wxItemResource
*)node
->Data();
863 wxString
resType(res
->GetType());
864 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
866 AddItemsRecursively(id
, res
);
869 m_editorResourceTree
->Expand(id
);
870 m_editorResourceTree
->SetInvalid(FALSE
);
873 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
875 wxString
theString("");
876 theString
= resource
->GetName();
879 wxString
resType(resource
->GetType());
880 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
885 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
887 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
889 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
891 wxNode
*node
= resource
->GetChildren().First();
894 wxItemResource
*res
= (wxItemResource
*)node
->Data();
895 AddItemsRecursively(id
, res
);
899 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
902 bool wxResourceManager::EditSelectedResource()
904 int sel
= m_editorResourceTree
->GetSelection();
907 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
908 wxItemResource
*res
= data
->GetResource();
914 bool wxResourceManager::Edit(wxItemResource
*res
)
916 ClearCurrentDialog();
918 wxString
resType(res
->GetType());
919 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
923 wxMessageBox("Should not find panel in wxResourceManager::Edit");
928 // long style = res->GetStyle();
929 // res->SetStyle(style|wxRAISED_BORDER);
931 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
934 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
936 panel
->PushEventHandler(handler
);
938 // res->SetStyle(style);
939 handler
->AddChildHandlers(); // Add event handlers for all controls
940 AssociateResource(res
, panel
);
942 m_editorPanel
->m_childWindow
= panel
;
943 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
947 wxClientDC
dc(m_editorPanel
);
948 m_editorPanel
->DrawTitle(dc
);
953 bool wxResourceManager::CreateNewPanel()
955 ClearCurrentDialog();
958 MakeUniqueName("dialog", buf
);
960 wxItemResource
*resource
= new wxItemResource
;
961 resource
->SetType("wxDialog");
962 resource
->SetName(buf
);
963 resource
->SetTitle(buf
);
964 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
965 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
968 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
971 // This is now guaranteed to be unique, so just add to symbol table
972 m_symbolTable
.AddSymbol(newIdName
, id
);
974 m_resourceTable
.AddResource(resource
);
976 wxSize
size(400, 300);
978 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
979 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
980 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
981 m_editorPanel
->m_childWindow
= panel
;
983 resource
->SetStyle(panel
->GetWindowStyleFlag());
985 // Store dialog units in resource
986 size
= panel
->ConvertPixelsToDialog(size
);
988 resource
->SetSize(10, 10, size
.x
, size
.y
);
990 // For editing in situ we will need to use the hash table to ensure
991 // we don't dereference invalid pointers.
992 // resourceWindowTable.Put((long)resource, panel);
994 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
996 panel
->PushEventHandler(handler
);
998 AssociateResource(resource
, panel
);
999 UpdateResourceList();
1002 m_editorPanel
->m_childWindow
->Refresh();
1004 // panel->Refresh();
1006 wxClientDC
dc(m_editorPanel
);
1007 m_editorPanel
->DrawTitle(dc
);
1012 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1015 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1020 wxItemResource
*res
= new wxItemResource
;
1021 wxControl
*newItem
= NULL
;
1023 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1025 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1026 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1028 else res
->SetSize(x
, y
, -1, -1);
1030 res
->SetType(iType
);
1034 wxString
itemType(iType
);
1036 if (itemType
== "wxButton")
1038 prefix
= "ID_BUTTON";
1039 MakeUniqueName("button", buf
);
1042 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1044 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1046 if (itemType
== "wxBitmapButton")
1048 prefix
= "ID_BITMAPBUTTON";
1049 MakeUniqueName("button", buf
);
1051 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1053 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1055 prefix
= "ID_STATIC";
1056 MakeUniqueName("statictext", buf
);
1059 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1061 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1063 else if (itemType
== "wxStaticBitmap")
1065 prefix
= "ID_STATICBITMAP";
1066 MakeUniqueName("static", buf
);
1068 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1070 else if (itemType
== "wxCheckBox")
1072 prefix
= "ID_CHECKBOX";
1073 MakeUniqueName("checkbox", buf
);
1075 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1077 else if (itemType
== "wxListBox")
1079 prefix
= "ID_LISTBOX";
1080 MakeUniqueName("listbox", buf
);
1082 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1084 else if (itemType
== "wxRadioBox")
1086 prefix
= "ID_RADIOBOX";
1087 MakeUniqueName("radiobox", buf
);
1089 wxString names
[] = { "One", "Two" };
1090 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1091 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1092 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1094 else if (itemType
== "wxRadioButton")
1096 prefix
= "ID_RADIOBUTTON";
1097 MakeUniqueName("radiobutton", buf
);
1099 wxString names
[] = { "One", "Two" };
1100 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1101 0, wxDefaultValidator
, buf
);
1103 else if (itemType
== "wxChoice")
1105 prefix
= "ID_CHOICE";
1106 MakeUniqueName("choice", buf
);
1108 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1110 else if (itemType
== "wxComboBox")
1112 prefix
= "ID_COMBOBOX";
1113 MakeUniqueName("combobox", buf
);
1115 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1117 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1119 prefix
= "ID_STATICBOX";
1120 MakeUniqueName("staticbox", buf
);
1122 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1124 else if (itemType
== "wxGauge")
1126 prefix
= "ID_GAUGE";
1127 MakeUniqueName("gauge", buf
);
1129 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1131 else if (itemType
== "wxSlider")
1133 prefix
= "ID_SLIDER";
1134 MakeUniqueName("slider", buf
);
1136 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1138 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1140 prefix
= "ID_TEXTCTRL";
1141 MakeUniqueName("textctrl", buf
);
1143 res
->SetType("wxTextCtrl");
1144 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1146 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1148 prefix
= "ID_TEXTCTRL";
1149 MakeUniqueName("textctrl", buf
);
1151 res
->SetType("wxTextCtrl");
1152 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1154 else if (itemType
== "wxScrollBar")
1156 prefix
= "ID_SCROLLBAR";
1157 MakeUniqueName("scrollbar", buf
);
1159 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1164 int actualW
, actualH
;
1165 newItem
->GetSize(&actualW
, &actualH
);
1166 wxSize
actualSize(actualW
, actualH
);
1168 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1170 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1172 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1175 int id
= GenerateWindowId(prefix
, newIdName
);
1178 // This is now guaranteed to be unique, so just add to symbol table
1179 m_symbolTable
.AddSymbol(newIdName
, id
);
1181 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1183 res
->SetStyle(newItem
->GetWindowStyleFlag());
1184 AssociateResource(res
, newItem
);
1185 panelResource
->GetChildren().Append(res
);
1187 UpdateResourceList();
1192 void wxResourceManager::ClearCurrentDialog()
1194 if (m_editorPanel
->m_childWindow
)
1196 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1197 DisassociateResource(m_editorPanel
->m_childWindow
);
1198 DeleteWindow(m_editorPanel
->m_childWindow
);
1199 m_editorPanel
->m_childWindow
= NULL
;
1200 m_editorPanel
->Clear();
1204 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1206 if (m_editorPanel
->m_childWindow
)
1208 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1212 // Make sure the resources are up-to-date w.r.t. the window
1213 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1215 wxDialog
* dialog
= new wxDialog
;
1216 bool success
= FALSE
;
1217 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1220 dialog
->ShowModal();
1228 // Find the first dialog or panel for which
1229 // there is a selected panel item.
1230 wxWindow
*wxResourceManager::FindParentOfSelection()
1232 m_resourceTable
.BeginFind();
1234 while ((node
= m_resourceTable
.Next()))
1236 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1237 wxWindow
*win
= FindWindowForResource(res
);
1240 wxNode
*node1
= win
->GetChildren().First();
1243 wxControl
*item
= (wxControl
*)node1
->Data();
1244 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1245 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1247 node1
= node1
->Next();
1254 // Format the panel items according to 'flag'
1255 void wxResourceManager::AlignItems(int flag
)
1257 wxWindow
*win
= FindParentOfSelection();
1261 wxNode
*node
= GetSelections().First();
1265 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1266 if (firstSelection
->GetParent() != win
)
1271 firstSelection
->GetPosition(&firstX
, &firstY
);
1272 firstSelection
->GetSize(&firstW
, &firstH
);
1273 int centreX
= (int)(firstX
+ (firstW
/ 2));
1274 int centreY
= (int)(firstY
+ (firstH
/ 2));
1276 while ((node
= node
->Next()))
1278 wxControl
*item
= (wxControl
*)node
->Data();
1279 if (item
->GetParent() == win
)
1282 item
->GetPosition(&x
, &y
);
1283 item
->GetSize(&w
, &h
);
1289 case TOOLBAR_FORMAT_HORIZ
:
1292 newY
= (int)(centreY
- (h
/2.0));
1295 case TOOLBAR_FORMAT_VERT
:
1297 newX
= (int)(centreX
- (w
/2.0));
1301 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1307 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1313 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1315 newX
= firstX
+ firstW
- w
;
1319 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1322 newY
= firstY
+ firstH
- h
;
1330 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1331 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1333 item
->SetSize(newX
, newY
, w
, h
);
1335 // Also update the associated resource
1336 // We need to convert to dialog units if this is not a dialog or panel, but
1337 // the parent resource specifies dialog units.
1338 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1340 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1341 newX
= pt
.x
; newY
= pt
.y
;
1342 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1345 resource
->SetSize(newX
, newY
, w
, h
);
1351 // Copy the first image's size to subsequent images
1352 void wxResourceManager::CopySize()
1354 wxWindow
*win
= FindParentOfSelection();
1358 wxNode
*node
= GetSelections().First();
1362 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1363 if (firstSelection
->GetParent() != win
)
1368 firstSelection
->GetPosition(&firstX
, &firstY
);
1369 firstSelection
->GetSize(&firstW
, &firstH
);
1371 while ((node
= node
->Next()))
1373 wxControl
*item
= (wxControl
*)node
->Data();
1374 if (item
->GetParent() == win
)
1376 item
->SetSize(-1, -1, firstW
, firstH
);
1378 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1379 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1381 // Also update the associated resource
1382 // We need to convert to dialog units if this is not a dialog or panel, but
1383 // the parent resource specifies dialog units.
1384 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1386 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1387 firstW
= sz
.x
; firstH
= sz
.y
;
1389 resource
->SetSize(resource
->GetX(), resource
->GetY(), firstW
, firstH
);
1396 void wxResourceManager::ToBackOrFront(bool toBack
)
1398 wxWindow
*win
= FindParentOfSelection();
1401 wxItemResource
*winResource
= FindResourceForWindow(win
);
1403 wxNode
*node
= GetSelections().First();
1406 wxControl
*item
= (wxControl
*)node
->Data();
1407 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1408 if (item
->GetParent() == win
)
1410 win
->GetChildren().DeleteObject(item
);
1412 winResource
->GetChildren().DeleteObject(itemResource
);
1415 win
->GetChildren().Insert(item
);
1417 winResource
->GetChildren().Insert(itemResource
);
1421 win
->GetChildren().Append(item
);
1423 winResource
->GetChildren().Append(itemResource
);
1426 node
= node
->Next();
1431 void wxResourceManager::AddSelection(wxWindow
*win
)
1433 if (!m_selections
.Member(win
))
1434 m_selections
.Append(win
);
1437 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1439 m_selections
.DeleteObject(win
);
1442 // Need to search through resource table removing this from
1443 // any resource which has this as a parent.
1444 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1446 m_resourceTable
.BeginFind();
1448 while ((node
= m_resourceTable
.Next()))
1450 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1451 if (thisRes
->GetChildren().Member(res
))
1453 thisRes
->GetChildren().DeleteObject(res
);
1460 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1465 RemoveResourceFromParent(res
);
1467 wxNode
*node
= res
->GetChildren().First();
1470 wxNode
*next
= node
->Next();
1471 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1472 DeleteResource(child
);
1476 // If this is a button or message resource, delete the
1477 // associate bitmap resource if not being used.
1478 wxString
resType(res
->GetType());
1480 /* shouldn't have to do this now bitmaps are ref-counted
1481 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1483 PossiblyDeleteBitmapResource(res->GetValue4());
1487 // Remove symbol from table if appropriate
1488 if (!IsSymbolUsed(res
, res
->GetId()))
1490 m_symbolTable
.RemoveSymbol(res
->GetId());
1493 m_resourceTable
.Delete(res
->GetName());
1499 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1501 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1503 // Deselect and refresh window in case we leave selection
1505 wxControl
*item
= (wxControl
*)win
;
1506 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1507 if (childHandler
->IsSelected())
1509 RemoveSelection(item
);
1510 childHandler
->SelectItem(FALSE
);
1512 item
->GetParent()->Refresh();
1517 wxItemResource
*res
= FindResourceForWindow(win
);
1519 DisassociateResource(res
);
1520 DeleteResource(res
);
1521 UpdateResourceList();
1526 // Will eventually have bitmap type information, for different
1528 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1530 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1534 MakeUniqueName("bitmap", buf
);
1535 resource
= new wxItemResource
;
1536 resource
->SetType("wxBitmap");
1537 resource
->SetName(buf
);
1539 // A bitmap resource has one or more children, specifying
1540 // alternative bitmaps.
1541 wxItemResource
*child
= new wxItemResource
;
1542 child
->SetType("wxBitmap");
1543 child
->SetName(filename
);
1544 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1545 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1546 child
->SetValue3(0); // Depth
1547 child
->SetSize(0,0,0,0);
1548 resource
->GetChildren().Append(child
);
1550 m_resourceTable
.AddResource(resource
);
1552 UpdateResourceList();
1555 return resource
->GetName();
1557 return wxEmptyString
;
1560 // Delete the bitmap resource if it isn't being used by another resource.
1561 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1563 if (!IsBitmapResourceUsed(resourceName
))
1565 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1566 DeleteResource(res
);
1567 UpdateResourceList();
1571 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1573 m_resourceTable
.BeginFind();
1575 while ((node
= m_resourceTable
.Next()))
1577 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1578 wxString
resType(res
->GetType());
1579 if (resType
== "wxDialog")
1581 wxNode
*node1
= res
->GetChildren().First();
1584 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1585 wxString
childResType(child
->GetType());
1587 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1588 child
->GetValue4() &&
1589 (strcmp(child
->GetValue4(), resourceName
) == 0))
1591 node1
= node1
->Next();
1598 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1599 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1601 if (!resource
|| (resource
->GetValue4() == ""))
1602 return wxEmptyString
;
1603 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1604 if (!bitmapResource
)
1605 return wxEmptyString
;
1607 wxNode
*node
= bitmapResource
->GetChildren().First();
1610 // Eventually augment this to return a bitmap of the right kind or something...
1611 // Maybe the root of the filename remains the same, so it doesn't matter which we
1612 // pick up. Otherwise how do we specify multiple filenames... too boring...
1613 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1614 return child
->GetName();
1616 node
= node
->Next();
1618 return wxEmptyString
;
1621 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1623 m_resourceTable
.BeginFind();
1625 while ((node
= m_resourceTable
.Next()))
1627 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1628 wxString
resType(res
->GetType());
1629 if (resType
== "wxBitmap")
1631 wxNode
*node1
= res
->GetChildren().First();
1634 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1635 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1637 node1
= node1
->Next();
1644 // Is this window identifier symbol in use?
1645 // Let's assume that we can't have 2 names for the same integer id.
1646 // Therefore we can tell by the integer id whether the symbol is
1648 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1650 m_resourceTable
.BeginFind();
1652 while ((node
= m_resourceTable
.Next()))
1654 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1656 wxString
resType(res
->GetType());
1657 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1659 if ((res
!= thisResource
) && (res
->GetId() == id
))
1662 wxNode
*node1
= res
->GetChildren().First();
1665 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1666 if ((child
!= thisResource
) && (child
->GetId() == id
))
1668 node1
= node1
->Next();
1675 // Is this window identifier compatible with the given name? (i.e.
1676 // does it already exist under a different name)
1677 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1679 if (m_symbolTable
.SymbolExists(name
))
1681 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1688 // Change all integer ids that match oldId, to newId.
1689 // This is necessary if an id is changed for one resource - all resources
1691 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1693 m_resourceTable
.BeginFind();
1695 while ((node
= m_resourceTable
.Next()))
1697 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1699 wxString
resType(res
->GetType());
1700 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1702 if (res
->GetId() == oldId
)
1705 wxNode
*node1
= res
->GetChildren().First();
1708 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1709 if (child
->GetId() == oldId
)
1710 child
->SetId(newId
);
1712 node1
= node1
->Next();
1718 // If any resource ids were missing (or their symbol was missing),
1719 // repair them i.e. give them new ids. Returns TRUE if any resource
1720 // needed repairing.
1721 bool wxResourceManager::RepairResourceIds()
1723 bool repaired
= FALSE
;
1725 m_resourceTable
.BeginFind();
1727 while ((node
= m_resourceTable
.Next()))
1729 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1730 wxString
resType(res
->GetType());
1731 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1734 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1736 wxString newSymbolName
;
1737 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1739 if (res
->GetId() == 0)
1742 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1746 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1752 wxNode
*node1
= res
->GetChildren().First();
1755 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1757 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1759 wxString newSymbolName
;
1760 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1762 if (child
->GetId() == 0)
1764 child
->SetId(newId
);
1765 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1769 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1775 node1
= node1
->Next();
1783 // Deletes 'win' and creates a new window from the resource that
1784 // was associated with it. E.g. if you can't change properties on the
1785 // fly, you'll need to delete the window and create it again.
1786 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1788 wxItemResource
*resource
= FindResourceForWindow(win
);
1790 // Put the current window properties into the wxItemResource object
1792 wxWindowPropertyInfo
*newInfo
= NULL
;
1795 newInfo
= CreatePropertyInfoForWindow(win
);
1799 info
->InstantiateResource(resource
);
1801 wxWindow
*newWin
= NULL
;
1802 wxWindow
*parent
= win
->GetParent();
1803 wxItemResource
* parentResource
= NULL
;
1805 parentResource
= FindResourceForWindow(parent
);
1807 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1810 newWin
= FindWindowForResource(resource
);
1814 DisassociateResource(resource
);
1815 if (win
->GetEventHandler() != win
)
1816 win
->PopEventHandler(TRUE
);
1819 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1820 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1821 AssociateResource(resource
, newWin
);
1822 UpdateResourceList();
1826 info
->SetPropertyWindow(newWin
);
1834 // Delete resource highlighted in the listbox
1835 bool wxResourceManager::DeleteSelection()
1837 int sel
= m_editorResourceTree
->GetSelection();
1840 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1841 wxItemResource
*res
= data
->GetResource();
1842 wxWindow
*win
= FindWindowForResource(res
);
1845 DeleteResource(win
);
1847 UpdateResourceList();
1856 // Delete resource highlighted in the listbox
1857 bool wxResourceManager::RecreateSelection()
1859 wxNode
*node
= GetSelections().First();
1862 wxControl
*item
= (wxControl
*)node
->Data();
1863 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1864 wxNode
*next
= node
->Next();
1865 childHandler
->SelectItem(FALSE
);
1867 RemoveSelection(item
);
1869 RecreateWindowFromResource(item
);
1876 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
1881 // Ensures that all currently shown windows are saved to resources,
1882 // e.g. just before writing to a .wxr file.
1883 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1885 m_resourceTable
.BeginFind();
1887 while ((node
= m_resourceTable
.Next()))
1889 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1890 wxString
resType(res
->GetType());
1892 if (resType
== "wxDialog")
1894 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1896 InstantiateResourceFromWindow(res
, win
, TRUE
);
1898 else if (resType
== "wxPanel")
1900 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1902 InstantiateResourceFromWindow(res
, win
, TRUE
);
1908 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1910 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1911 info
->SetResource(resource
);
1912 info
->InstantiateResource(resource
);
1917 wxNode
*node
= resource
->GetChildren().First();
1920 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1921 wxWindow
*childWindow
= FindWindowForResource(child
);
1926 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
1927 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1930 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1931 node
= node
->Next();
1938 // Create a window information object for the give window
1939 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1941 wxWindowPropertyInfo
*info
= NULL
;
1942 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1944 info
= new wxScrollBarPropertyInfo(win
);
1946 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1948 info
= new wxGroupBoxPropertyInfo(win
);
1950 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1952 info
= new wxCheckBoxPropertyInfo(win
);
1954 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1956 info
= new wxSliderPropertyInfo(win
);
1958 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1960 info
= new wxGaugePropertyInfo(win
);
1962 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1964 info
= new wxListBoxPropertyInfo(win
);
1966 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1968 info
= new wxRadioBoxPropertyInfo(win
);
1970 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1972 info
= new wxRadioButtonPropertyInfo(win
);
1974 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
1976 info
= new wxComboBoxPropertyInfo(win
);
1978 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1980 info
= new wxChoicePropertyInfo(win
);
1982 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1984 info
= new wxBitmapButtonPropertyInfo(win
);
1986 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1988 info
= new wxButtonPropertyInfo(win
);
1990 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1992 info
= new wxStaticBitmapPropertyInfo(win
);
1994 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1996 info
= new wxStaticTextPropertyInfo(win
);
1998 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
2000 info
= new wxTextPropertyInfo(win
);
2002 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
2004 info
= new wxPanelPropertyInfo(win
);
2008 info
= new wxWindowPropertyInfo(win
);
2013 // Edit the given window
2014 void wxResourceManager::EditWindow(wxWindow
*win
)
2016 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2019 info
->SetResource(FindResourceForWindow(win
));
2020 wxString
str("Editing ");
2021 str
+= win
->GetClassInfo()->GetClassName();
2023 if (win
->GetName() != "")
2024 str
+= win
->GetName();
2026 str
+= "properties";
2027 info
->Edit(NULL
, str
);
2031 // Generate a window id and a first stab at a name
2032 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2034 m_symbolIdCounter
++;
2035 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2036 m_symbolIdCounter
++;
2038 int nameId
= m_symbolIdCounter
;
2041 str
.Printf("%d", nameId
);
2042 idName
= prefix
+ str
;
2044 while (m_symbolTable
.SymbolExists(idName
))
2047 str
.Printf("%d", nameId
);
2048 idName
= prefix
+ str
;
2051 return m_symbolIdCounter
;
2056 * Resource editor frame
2059 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2061 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2062 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2063 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2064 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2065 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2066 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2067 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2068 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2069 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2070 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2071 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2072 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2073 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2074 EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow
)
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 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent
& event
)
2158 if (manager
->Modified())
2160 if (!manager
->Clear(TRUE
, FALSE
))
2171 manager
->m_resourceEditorWindowSize
.width
= w
;
2172 manager
->m_resourceEditorWindowSize
.height
= h
;
2175 GetPosition(&x
, &y
);
2177 manager
->m_resourceEditorWindowSize
.x
= x
;
2178 manager
->m_resourceEditorWindowSize
.y
= y
;
2180 manager
->SetEditorFrame(NULL
);
2181 manager
->SetEditorToolBar(NULL
);
2187 * Resource editor window that contains the dialog/panel being edited
2190 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2191 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
2192 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2195 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2197 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2201 m_childWindow
= NULL
;
2203 SetBackgroundColour(* wxWHITE
);
2206 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2210 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
2212 wxScrolledWindow::OnScroll(event
);
2215 ViewStart(& x
, & y
);
2218 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
2221 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2228 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2232 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2235 wxString
str(res
->GetTitle());
2237 ViewStart(& x
, & y
);
2239 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2241 dc
.SetBackgroundMode(wxTRANSPARENT
);
2242 dc
.SetTextForeground(wxColour(0, 0, 0));
2245 dc
.GetTextExtent(str
, & w
, & h
);
2247 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2252 // Popup menu callback
2253 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2255 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2259 switch (event
.GetInt())
2261 case OBJECT_MENU_EDIT
:
2263 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2266 case OBJECT_MENU_DELETE
:
2268 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2269 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2270 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2283 #if defined(__WXGTK__) || defined(__WXMOTIF__) // I don't dare to delete it...
2285 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2290 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2291 EVT_PAINT(EditorToolBar::OnPaint
)
2296 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2298 wxToolBar(frame
, -1, pos
, size
, style
)
2302 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2304 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2308 case TOOLBAR_LOAD_FILE
:
2315 manager
->CreateNewPanel();
2318 case TOOLBAR_SAVE_FILE
:
2326 wxBeginBusyCursor();
2327 manager
->GetHelpController()->LoadFile();
2328 manager
->GetHelpController()->DisplayContents();
2333 case TOOLBAR_FORMAT_HORIZ
:
2335 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2338 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2340 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2343 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2345 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2348 case TOOLBAR_FORMAT_VERT
:
2350 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2353 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2355 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2358 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2360 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2363 case TOOLBAR_COPY_SIZE
:
2365 manager
->CopySize();
2368 case TOOLBAR_TO_BACK
:
2370 manager
->ToBackOrFront(TRUE
);
2373 case TOOLBAR_TO_FRONT
:
2375 manager
->ToBackOrFront(FALSE
);
2384 void EditorToolBar::OnMouseEnter(int toolIndex
)
2386 wxFrame
*frame
= (wxFrame
*)GetParent();
2394 case TOOLBAR_LOAD_FILE
:
2395 frame
->SetStatusText("Load project file");
2397 case TOOLBAR_SAVE_FILE
:
2398 frame
->SetStatusText("Save project file");
2401 frame
->SetStatusText("Create a new resource");
2403 case TOOLBAR_FORMAT_HORIZ
:
2404 frame
->SetStatusText("Align items horizontally");
2406 case TOOLBAR_FORMAT_VERT
:
2407 frame
->SetStatusText("Align items vertically");
2409 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2410 frame
->SetStatusText("Left-align items");
2412 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2413 frame
->SetStatusText("Right-align items");
2415 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2416 frame
->SetStatusText("Top-align items");
2418 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2419 frame
->SetStatusText("Bottom-align items");
2421 case TOOLBAR_COPY_SIZE
:
2422 frame
->SetStatusText("Copy size from first selection");
2424 case TOOLBAR_TO_FRONT
:
2425 frame
->SetStatusText("Put image to front");
2427 case TOOLBAR_TO_BACK
:
2428 frame
->SetStatusText("Put image to back");
2431 frame
->SetStatusText("Display help contents");
2437 else frame
->SetStatusText("");