1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource editor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "reseditr.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/checkbox.h"
27 #include "wx/button.h"
28 #include "wx/choice.h"
29 #include "wx/listbox.h"
30 #include "wx/radiobox.h"
31 #include "wx/statbox.h"
33 #include "wx/slider.h"
34 #include "wx/textctrl.h"
36 #include "wx/toolbar.h"
39 #include "wx/scrolbar.h"
40 #include "wx/config.h"
57 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
59 #if defined(__WXGTK__) || defined(__WXMOTIF__)
60 #include "bitmaps/load.xpm"
61 #include "bitmaps/save.xpm"
62 #include "bitmaps/new.xpm"
63 #include "bitmaps/vert.xpm"
64 #include "bitmaps/alignt.xpm"
65 #include "bitmaps/alignb.xpm"
66 #include "bitmaps/horiz.xpm"
67 #include "bitmaps/alignl.xpm"
68 #include "bitmaps/alignr.xpm"
69 #include "bitmaps/copysize.xpm"
70 #include "bitmaps/tofront.xpm"
71 #include "bitmaps/toback.xpm"
72 #include "bitmaps/help.xpm"
73 #include "bitmaps/wxwin.xpm"
75 #include "bitmaps/dialog.xpm"
76 #include "bitmaps/folder1.xpm"
77 #include "bitmaps/folder2.xpm"
78 #include "bitmaps/buttonsm.xpm"
85 wxResourceManager::wxResourceManager():
86 m_imageList(16, 16, TRUE
)
88 sm_currentResourceManager
= this;
92 m_editorResourceTree
= NULL
;
93 m_editorControlList
= NULL
;
95 m_symbolIdCounter
= 99;
97 m_currentFilename
= "";
98 m_symbolFilename
= "";
99 m_editorToolBar
= NULL
;
101 // Default window positions
102 m_resourceEditorWindowSize
.width
= 500;
103 m_resourceEditorWindowSize
.height
= 450;
105 m_resourceEditorWindowSize
.x
= 0;
106 m_resourceEditorWindowSize
.y
= 0;
108 m_propertyWindowSize
.width
= 300;
109 m_propertyWindowSize
.height
= 300;
112 m_helpController
= NULL
;
115 m_bitmapImage
= NULL
;
116 m_rootDialogItem
= 0;
119 wxResourceManager::~wxResourceManager()
121 sm_currentResourceManager
= NULL
;
125 if (m_helpController
)
127 m_helpController
->Quit();
128 delete m_helpController
;
129 m_helpController
= NULL
;
133 delete m_bitmapImage
;
137 bool wxResourceManager::Initialize()
139 // Set up the resource filename for each platform.
140 // TODO: This shold be replaced by wxConfig usage.
142 // dialoged.ini in the Windows directory
143 wxString windowsDir
= wxGetOSDirectory();
144 windowsDir
+= "\\dialoged.ini" ;
146 m_optionsResourceFilename
= windowsDir
;
147 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
148 wxGetHomeDir( &m_optionsResourceFilename
);
149 m_optionsResourceFilename
+= "/.dialogedrc";
151 #error "Unsupported platform."
157 m_helpController
= new wxHelpController
;
158 m_helpController
->Initialize("dialoged");
161 m_popupMenu
= new wxMenu
;
162 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
163 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
168 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
170 #if defined(__WXGTK__) || defined(__WXMOTIF__)
171 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
175 // Initialize the image list icons
177 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
178 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
179 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
180 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
182 wxIcon
icon1( dialog_xpm
);
183 wxIcon
icon2( folder1_xpm
);
184 wxIcon
icon3( folder2_xpm
);
185 wxIcon
icon4( buttonsm_xpm
);
187 m_imageList
.Add(icon1
);
188 m_imageList
.Add(icon2
);
189 m_imageList
.Add(icon3
);
190 m_imageList
.Add(icon4
);
192 m_symbolTable
.AddStandardSymbols();
197 bool wxResourceManager::LoadOptions()
199 wxConfig
config("DialogEd", "wxWindows");
201 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
202 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
203 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
204 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
205 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
206 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
207 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
208 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
211 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
212 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
213 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
214 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
215 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
216 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
217 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
218 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
223 bool wxResourceManager::SaveOptions()
225 wxConfig
config("DialogEd", "wxWindows");
227 config
.Write("editorWindowX", (long) m_resourceEditorWindowSize
.x
);
228 config
.Write("editorWindowY", (long) m_resourceEditorWindowSize
.y
);
229 config
.Write("editorWindowWidth", (long) m_resourceEditorWindowSize
.width
);
230 config
.Write("editorWindowHeight", (long) m_resourceEditorWindowSize
.height
);
231 config
.Write("propertyWindowX", (long) m_propertyWindowSize
.x
);
232 config
.Write("propertyWindowY", (long) m_propertyWindowSize
.y
);
233 config
.Write("propertyWindowWidth", (long) m_propertyWindowSize
.width
);
234 config
.Write("propertyWindowHeight", (long) m_propertyWindowSize
.height
);
236 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
237 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
238 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
239 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
241 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
242 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
243 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
244 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
250 // Show or hide the resource editor frame, which displays a list
251 // of resources with ability to edit them.
252 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
258 m_editorFrame
->Iconize(FALSE
);
259 m_editorFrame
->Show(TRUE
);
262 m_editorFrame
= OnCreateEditorFrame(title
);
264 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
265 m_editorFrame
->SetMenuBar(menuBar
);
267 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
268 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
269 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
271 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
273 m_editorResourceTree
->SetImageList(& m_imageList
);
275 // Constraints for toolbar
276 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
277 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
278 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
279 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
280 c
->bottom
.Unconstrained();
281 c
->width
.Unconstrained();
282 c
->height
.Absolute(28);
283 m_editorToolBar
->SetConstraints(c
);
285 // Constraints for listbox
286 c
= new wxLayoutConstraints
;
287 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
288 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
289 c
->right
.Absolute (150);
290 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
291 c
->width
.Unconstrained();
292 c
->height
.Unconstrained();
293 m_editorResourceTree
->SetConstraints(c
);
295 // Constraints for panel
296 c
= new wxLayoutConstraints
;
297 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
298 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
299 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
300 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
301 c
->width
.Unconstrained();
302 c
->height
.Unconstrained();
303 m_editorPanel
->SetConstraints(c
);
305 // Constraints for control list (bottom window)
306 c
= new wxLayoutConstraints
;
307 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
308 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
309 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
310 c
->width
.Unconstrained();
311 #if defined(__WXGTK__) || defined(__WXMOTIF__)
312 c
->height
.Absolute(120);
314 c
->height
.Absolute(60);
317 m_editorControlList
->SetConstraints(c
);
319 m_editorFrame
->SetAutoLayout(TRUE
);
321 UpdateResourceList();
323 m_editorFrame
->Show(TRUE
);
328 if (m_editorFrame
->Close())
330 m_editorFrame
= NULL
;
331 m_editorPanel
= NULL
;
337 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
341 if (filename
== wxString(""))
342 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
345 wxString
str("wxWindows Dialog Editor - ");
346 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
348 m_editorFrame
->SetTitle(str
);
353 bool wxResourceManager::Save()
355 if (m_currentFilename
== wxString(""))
358 return Save(m_currentFilename
);
361 bool wxResourceManager::Save(const wxString
& filename
)
363 // Ensure all visible windows are saved to their resources
364 m_currentFilename
= filename
;
365 SetFrameTitle(m_currentFilename
);
366 InstantiateAllResourcesFromWindows();
367 if (m_resourceTable
.Save(filename
))
369 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
377 bool wxResourceManager::SaveAs()
379 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
380 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
, wxTheApp
->GetTopWindow()));
382 if (s
.IsNull() || s
== "")
385 m_currentFilename
= s
;
386 wxStripExtension(m_currentFilename
);
387 m_currentFilename
+= ".wxr";
389 // Construct include filename from this file
390 m_symbolFilename
= m_currentFilename
;
392 wxStripExtension(m_symbolFilename
);
393 m_symbolFilename
+= ".h";
395 Save(m_currentFilename
);
399 bool wxResourceManager::SaveIfModified()
406 bool wxResourceManager::Load(const wxString
& filename
)
408 return New(TRUE
, filename
);
411 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
413 if (!Clear(TRUE
, FALSE
))
416 m_symbolTable
.AddStandardSymbols();
420 wxString str
= filename
;
421 if (str
== wxString(""))
423 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, wxTheApp
->GetTopWindow()));
424 if (!f
.IsNull() && f
!= "")
430 if (!m_resourceTable
.ParseResourceFile(str
))
432 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
435 m_currentFilename
= str
;
437 SetFrameTitle(m_currentFilename
);
439 UpdateResourceList();
441 // Construct include filename from this file
442 m_symbolFilename
= m_currentFilename
;
444 wxStripExtension(m_symbolFilename
);
445 m_symbolFilename
+= ".h";
447 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
449 wxString
str("Could not find include file ");
450 str
+= m_symbolFilename
;
451 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
452 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
453 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
455 m_symbolIdCounter
= 99;
459 // Set the id counter to the last known id
460 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
463 // Now check in case some (or all) resources don't have resource ids, or they
464 // don't match the .h file, or something of that nature.
465 bool altered
= RepairResourceIds();
468 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
469 "Dialog Editor Warning", wxOK
);
480 m_currentFilename
= "";
487 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
489 wxPropertyInfo::CloseWindow();
491 if (!force
&& Modified())
493 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
497 if (!SaveIfModified())
503 ClearCurrentDialog();
504 DisassociateWindows();
506 m_symbolTable
.Clear();
507 m_resourceTable
.ClearTable();
508 UpdateResourceList();
513 bool wxResourceManager::DisassociateWindows()
515 m_resourceTable
.BeginFind();
517 while ((node
= m_resourceTable
.Next()))
519 wxItemResource
*res
= (wxItemResource
*)node
->Data();
520 DisassociateResource(res
);
526 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
528 if (!m_resourceAssociations
.Get((long)resource
))
529 m_resourceAssociations
.Put((long)resource
, win
);
531 wxNode
*node
= resource
->GetChildren().First();
532 wxNode
* node2
= win
->GetChildren().First();
533 while (node
&& node2
)
535 wxItemResource
*child
= (wxItemResource
*)node
->Data();
536 wxWindow
* childWindow
= (wxWindow
*) node2
->Data();
538 if (child
->GetId() != childWindow
->GetId())
541 msg
.Printf("AssociateResource: error when associating child window %ld with resource %ld", child
->GetId(), childWindow
->GetId());
542 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
544 else if (childWindow
->GetName() != child
->GetName())
547 msg
.Printf("AssociateResource: error when associating child window with resource %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
548 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
552 AssociateResource(child
, childWindow
);
555 // New code to avoid the problem of duplicate ids and names. We simply
556 // traverse the child windows and child resources in parallel,
557 // checking for any mismatch.
559 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
561 // childWindow = win->FindWindow(child->GetName());
562 childWindow
= win
->FindWindow(child
->GetId());
564 AssociateResource(child
, childWindow
);
568 msg
.Printf("AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
569 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
573 node2
= node2
->Next();
577 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
579 wxWindow
*win
= FindWindowForResource(resource
);
583 // Disassociate children of window
584 wxNode
*node
= win
->GetChildren().First();
587 wxWindow
*child
= (wxWindow
*)node
->Data();
588 if (child
->IsKindOf(CLASSINFO(wxControl
)))
589 DisassociateResource(child
);
593 RemoveSelection(win
);
594 m_resourceAssociations
.Delete((long)resource
);
598 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
600 wxItemResource
*res
= FindResourceForWindow(win
);
602 return DisassociateResource(res
);
607 // Saves the window info into the resource, and deletes the
608 // handler. Doesn't actually disassociate the window from
609 // the resources. Replaces OnClose.
610 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
612 wxItemResource
*res
= FindResourceForWindow(win
);
614 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
616 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
617 win
->PopEventHandler();
619 // Now reset all child event handlers
620 wxNode
*node
= win
->GetChildren().First();
623 wxWindow
*child
= (wxWindow
*)node
->Data();
624 wxEvtHandler
*childHandler
= child
->GetEventHandler();
625 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
627 child
->PopEventHandler(TRUE
);
635 win
->PopEventHandler(TRUE
);
638 // Save the information
639 InstantiateResourceFromWindow(res
, win
, TRUE
);
641 // DisassociateResource(win);
646 // Destroys the window. If this is the 'current' panel, NULLs the
648 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
650 bool clearDisplay
= FALSE
;
651 if (m_editorPanel
->m_childWindow
== win
)
653 m_editorPanel
->m_childWindow
= NULL
;
660 m_editorPanel
->Clear();
665 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
667 m_resourceAssociations
.BeginFind();
669 while ((node
= m_resourceAssociations
.Next()))
671 wxWindow
*w
= (wxWindow
*)node
->Data();
674 return (wxItemResource
*)node
->GetKeyInteger();
680 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
682 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
686 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
690 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
693 if (!m_resourceTable
.FindResource(buf
))
698 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
701 int frameWidth = 420;
702 int frameHeight = 300;
705 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
706 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
707 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
708 wxDEFAULT_FRAME_STYLE
);
710 frame
->CreateStatusBar(1);
712 frame
->SetAutoLayout(TRUE
);
714 frame
->SetIcon(wxIcon("DIALOGEDICON"));
719 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
721 wxMenuBar
*menuBar
= new wxMenuBar
;
723 wxMenu
*fileMenu
= new wxMenu
;
724 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
725 fileMenu
->AppendSeparator();
726 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
727 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
728 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
729 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
730 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
731 fileMenu
->AppendSeparator();
732 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
734 wxMenu
*editMenu
= new wxMenu
;
735 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
736 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
737 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
739 wxMenu
*helpMenu
= new wxMenu
;
740 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
741 helpMenu
->AppendSeparator();
742 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
744 menuBar
->Append(fileMenu
, "&File");
745 menuBar
->Append(editMenu
, "&Edit");
746 menuBar
->Append(helpMenu
, "&Help");
751 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
753 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
754 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
761 panel
->SetScrollbars(10, 10, 100, 100);
766 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
768 // Load palette bitmaps
770 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
771 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
772 wxBitmap
ToolbarNewBitmap("NEWTOOL");
773 wxBitmap
ToolbarVertBitmap("VERTTOOL");
774 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
775 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
776 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
777 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
778 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
779 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
780 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
781 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
782 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
784 #if defined(__WXGTK__) || defined(__WXMOTIF__)
785 wxBitmap
ToolbarLoadBitmap( load_xpm
);
786 wxBitmap
ToolbarSaveBitmap( save_xpm
);
787 wxBitmap
ToolbarNewBitmap( new_xpm
);
788 wxBitmap
ToolbarVertBitmap( vert_xpm
);
789 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
790 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
791 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
792 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
793 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
794 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
795 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
796 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
797 wxBitmap
ToolbarHelpBitmap( help_xpm
);
800 // Create the toolbar
801 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
802 toolbar
->SetMargins(2, 2);
809 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
814 toolbar
->AddSeparator();
815 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
816 FALSE
, currentX
, -1, NULL
, "New dialog");
817 currentX
+= width
+ dx
;
818 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
819 FALSE
, currentX
, -1, NULL
, "Load");
820 currentX
+= width
+ dx
;
821 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
822 FALSE
, currentX
, -1, NULL
, "Save");
823 currentX
+= width
+ dx
+ gap
;
824 toolbar
->AddSeparator();
825 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
826 FALSE
, currentX
, -1, NULL
, "Horizontal align");
827 currentX
+= width
+ dx
;
828 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
829 FALSE
, currentX
, -1, NULL
, "Top align");
830 currentX
+= width
+ dx
;
831 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
832 FALSE
, currentX
, -1, NULL
, "Bottom align");
833 currentX
+= width
+ dx
;
834 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
835 FALSE
, currentX
, -1, NULL
, "Vertical align");
836 currentX
+= width
+ dx
;
837 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
838 FALSE
, currentX
, -1, NULL
, "Left align");
839 currentX
+= width
+ dx
;
840 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
841 FALSE
, currentX
, -1, NULL
, "Right align");
842 currentX
+= width
+ dx
;
843 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
844 FALSE
, currentX
, -1, NULL
, "Copy size");
845 currentX
+= width
+ dx
+ gap
;
846 toolbar
->AddSeparator();
847 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
848 FALSE
, currentX
, -1, NULL
, "To front");
849 currentX
+= width
+ dx
;
850 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
851 FALSE
, currentX
, -1, NULL
, "To back");
852 currentX
+= width
+ dx
+ gap
;
854 toolbar
->AddSeparator();
855 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
856 FALSE
, currentX
, -1, NULL
, "Help");
857 currentX
+= width
+ dx
;
864 void wxResourceManager::UpdateResourceList()
866 if (!m_editorResourceTree
)
869 m_editorResourceTree
->SetInvalid(TRUE
);
870 m_editorResourceTree
->DeleteAllItems();
872 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
874 m_resourceTable
.BeginFind();
876 while ((node
= m_resourceTable
.Next()))
878 wxItemResource
*res
= (wxItemResource
*)node
->Data();
879 wxString
resType(res
->GetType());
880 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
882 AddItemsRecursively(id
, res
);
885 m_editorResourceTree
->Expand(id
);
886 m_editorResourceTree
->SetInvalid(FALSE
);
889 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
891 wxString
theString("");
892 theString
= resource
->GetName();
895 wxString
resType(resource
->GetType());
896 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
901 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
903 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
905 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
907 wxNode
*node
= resource
->GetChildren().First();
910 wxItemResource
*res
= (wxItemResource
*)node
->Data();
911 AddItemsRecursively(id
, res
);
915 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
918 bool wxResourceManager::EditSelectedResource()
920 int sel
= m_editorResourceTree
->GetSelection();
923 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
924 wxItemResource
*res
= data
->GetResource();
930 bool wxResourceManager::Edit(wxItemResource
*res
)
932 wxPropertyInfo::CloseWindow();
934 ClearCurrentDialog();
936 wxString
resType(res
->GetType());
937 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
941 wxMessageBox("Should not find panel in wxResourceManager::Edit");
946 // long style = res->GetStyle();
947 // res->SetStyle(style|wxRAISED_BORDER);
949 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
952 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
954 panel
->PushEventHandler(handler
);
956 // res->SetStyle(style);
957 handler
->AddChildHandlers(); // Add event handlers for all controls
958 AssociateResource(res
, panel
);
960 m_editorPanel
->m_childWindow
= panel
;
961 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
965 wxClientDC
dc(m_editorPanel
);
966 m_editorPanel
->DrawTitle(dc
);
971 bool wxResourceManager::CreateNewPanel()
973 wxPropertyInfo::CloseWindow();
975 ClearCurrentDialog();
978 MakeUniqueName("dialog", buf
);
980 wxItemResource
*resource
= new wxItemResource
;
981 resource
->SetType("wxDialog");
982 resource
->SetName(buf
);
983 resource
->SetTitle(buf
);
984 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
985 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
988 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
991 // This is now guaranteed to be unique, so just add to symbol table
992 m_symbolTable
.AddSymbol(newIdName
, id
);
994 m_resourceTable
.AddResource(resource
);
996 wxSize
size(400, 300);
998 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
999 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
1000 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
1001 m_editorPanel
->m_childWindow
= panel
;
1003 resource
->SetStyle(panel
->GetWindowStyleFlag());
1005 // Store dialog units in resource
1006 size
= panel
->ConvertPixelsToDialog(size
);
1008 resource
->SetSize(10, 10, size
.x
, size
.y
);
1010 // For editing in situ we will need to use the hash table to ensure
1011 // we don't dereference invalid pointers.
1012 // resourceWindowTable.Put((long)resource, panel);
1014 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
1016 panel
->PushEventHandler(handler
);
1018 AssociateResource(resource
, panel
);
1019 UpdateResourceList();
1022 m_editorPanel
->m_childWindow
->Refresh();
1024 // panel->Refresh();
1026 wxClientDC
dc(m_editorPanel
);
1027 m_editorPanel
->DrawTitle(dc
);
1032 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1035 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1040 wxItemResource
*res
= new wxItemResource
;
1041 wxControl
*newItem
= NULL
;
1043 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1045 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1046 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1048 else res
->SetSize(x
, y
, -1, -1);
1050 res
->SetType(iType
);
1054 wxString
itemType(iType
);
1056 if (itemType
== "wxButton")
1058 prefix
= "ID_BUTTON";
1059 MakeUniqueName("button", buf
);
1062 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), wxBU_AUTODRAW
, wxDefaultValidator
, buf
);
1064 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1066 if (itemType
== "wxBitmapButton")
1068 prefix
= "ID_BITMAPBUTTON";
1069 MakeUniqueName("button", buf
);
1071 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), wxBU_AUTODRAW
, wxDefaultValidator
, buf
);
1073 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1075 prefix
= "ID_STATIC";
1076 MakeUniqueName("statictext", buf
);
1079 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1081 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1083 else if (itemType
== "wxStaticBitmap")
1085 prefix
= "ID_STATICBITMAP";
1086 MakeUniqueName("static", buf
);
1088 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1090 else if (itemType
== "wxCheckBox")
1092 prefix
= "ID_CHECKBOX";
1093 MakeUniqueName("checkbox", buf
);
1095 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1097 else if (itemType
== "wxListBox")
1099 prefix
= "ID_LISTBOX";
1100 MakeUniqueName("listbox", buf
);
1102 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1104 else if (itemType
== "wxRadioBox")
1106 prefix
= "ID_RADIOBOX";
1107 MakeUniqueName("radiobox", buf
);
1109 wxString names
[] = { "One", "Two" };
1110 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1111 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1112 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1114 else if (itemType
== "wxRadioButton")
1116 prefix
= "ID_RADIOBUTTON";
1117 MakeUniqueName("radiobutton", buf
);
1119 wxString names
[] = { "One", "Two" };
1120 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1121 0, wxDefaultValidator
, buf
);
1123 else if (itemType
== "wxChoice")
1125 prefix
= "ID_CHOICE";
1126 MakeUniqueName("choice", buf
);
1128 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1130 else if (itemType
== "wxComboBox")
1132 prefix
= "ID_COMBOBOX";
1133 MakeUniqueName("combobox", buf
);
1135 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1137 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1139 prefix
= "ID_STATICBOX";
1140 MakeUniqueName("staticbox", buf
);
1142 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1144 else if (itemType
== "wxGauge")
1146 prefix
= "ID_GAUGE";
1147 MakeUniqueName("gauge", buf
);
1149 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1151 else if (itemType
== "wxSlider")
1153 prefix
= "ID_SLIDER";
1154 MakeUniqueName("slider", buf
);
1156 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1158 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1160 prefix
= "ID_TEXTCTRL";
1161 MakeUniqueName("textctrl", buf
);
1163 res
->SetType("wxTextCtrl");
1164 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1166 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1168 prefix
= "ID_TEXTCTRL";
1169 MakeUniqueName("textctrl", buf
);
1171 res
->SetType("wxTextCtrl");
1172 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1174 else if (itemType
== "wxScrollBar")
1176 prefix
= "ID_SCROLLBAR";
1177 MakeUniqueName("scrollbar", buf
);
1179 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1184 int actualW
, actualH
;
1185 newItem
->GetSize(&actualW
, &actualH
);
1186 wxSize
actualSize(actualW
, actualH
);
1188 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1190 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1192 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1195 int id
= GenerateWindowId(prefix
, newIdName
);
1198 // This is now guaranteed to be unique, so just add to symbol table
1199 m_symbolTable
.AddSymbol(newIdName
, id
);
1201 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1203 res
->SetStyle(newItem
->GetWindowStyleFlag());
1204 AssociateResource(res
, newItem
);
1205 panelResource
->GetChildren().Append(res
);
1207 UpdateResourceList();
1212 void wxResourceManager::ClearCurrentDialog()
1214 if (m_editorPanel
->m_childWindow
)
1216 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1217 DisassociateResource(m_editorPanel
->m_childWindow
);
1218 DeleteWindow(m_editorPanel
->m_childWindow
);
1219 m_editorPanel
->m_childWindow
= NULL
;
1220 m_editorPanel
->Clear();
1224 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1226 if (m_editorPanel
->m_childWindow
)
1228 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1232 // Make sure the resources are up-to-date w.r.t. the window
1233 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1235 wxDialog
* dialog
= new wxDialog
;
1236 bool success
= FALSE
;
1237 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1240 dialog
->ShowModal();
1248 // Find the first dialog or panel for which
1249 // there is a selected panel item.
1250 wxWindow
*wxResourceManager::FindParentOfSelection()
1252 m_resourceTable
.BeginFind();
1254 while ((node
= m_resourceTable
.Next()))
1256 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1257 wxWindow
*win
= FindWindowForResource(res
);
1260 wxNode
*node1
= win
->GetChildren().First();
1263 wxControl
*item
= (wxControl
*)node1
->Data();
1264 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1265 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1267 node1
= node1
->Next();
1274 // Format the panel items according to 'flag'
1275 void wxResourceManager::AlignItems(int flag
)
1277 wxWindow
*win
= FindParentOfSelection();
1281 wxNode
*node
= GetSelections().First();
1285 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1286 if (firstSelection
->GetParent() != win
)
1291 firstSelection
->GetPosition(&firstX
, &firstY
);
1292 firstSelection
->GetSize(&firstW
, &firstH
);
1293 int centreX
= (int)(firstX
+ (firstW
/ 2));
1294 int centreY
= (int)(firstY
+ (firstH
/ 2));
1296 while ((node
= node
->Next()))
1298 wxControl
*item
= (wxControl
*)node
->Data();
1299 if (item
->GetParent() == win
)
1302 item
->GetPosition(&x
, &y
);
1303 item
->GetSize(&w
, &h
);
1309 case TOOLBAR_FORMAT_HORIZ
:
1312 newY
= (int)(centreY
- (h
/2.0));
1315 case TOOLBAR_FORMAT_VERT
:
1317 newX
= (int)(centreX
- (w
/2.0));
1321 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1327 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1333 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1335 newX
= firstX
+ firstW
- w
;
1339 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1342 newY
= firstY
+ firstH
- h
;
1350 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1351 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1353 item
->SetSize(newX
, newY
, w
, h
);
1355 // Also update the associated resource
1356 // We need to convert to dialog units if this is not a dialog or panel, but
1357 // the parent resource specifies dialog units.
1358 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1360 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1361 newX
= pt
.x
; newY
= pt
.y
;
1362 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1365 resource
->SetSize(newX
, newY
, w
, h
);
1371 // Copy the first image's size to subsequent images
1372 void wxResourceManager::CopySize()
1374 wxWindow
*win
= FindParentOfSelection();
1378 wxNode
*node
= GetSelections().First();
1382 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1383 if (firstSelection
->GetParent() != win
)
1388 firstSelection
->GetPosition(&firstX
, &firstY
);
1389 firstSelection
->GetSize(&firstW
, &firstH
);
1391 while ((node
= node
->Next()))
1393 wxControl
*item
= (wxControl
*)node
->Data();
1394 if (item
->GetParent() == win
)
1396 item
->SetSize(-1, -1, firstW
, firstH
);
1401 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1402 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1404 // Also update the associated resource
1405 // We need to convert to dialog units if this is not a dialog or panel, but
1406 // the parent resource specifies dialog units.
1407 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1409 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1410 fw
= sz
.x
; fh
= sz
.y
;
1412 resource
->SetSize(resource
->GetX(), resource
->GetY(), fw
, fh
);
1419 void wxResourceManager::ToBackOrFront(bool toBack
)
1421 wxWindow
*win
= FindParentOfSelection();
1424 wxItemResource
*winResource
= FindResourceForWindow(win
);
1426 wxNode
*node
= GetSelections().First();
1429 wxControl
*item
= (wxControl
*)node
->Data();
1430 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1431 if (item
->GetParent() == win
)
1433 win
->GetChildren().DeleteObject(item
);
1435 winResource
->GetChildren().DeleteObject(itemResource
);
1438 win
->GetChildren().Insert(item
);
1440 winResource
->GetChildren().Insert(itemResource
);
1444 win
->GetChildren().Append(item
);
1446 winResource
->GetChildren().Append(itemResource
);
1449 node
= node
->Next();
1454 void wxResourceManager::AddSelection(wxWindow
*win
)
1456 if (!m_selections
.Member(win
))
1457 m_selections
.Append(win
);
1460 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1462 m_selections
.DeleteObject(win
);
1465 void wxResourceManager::DeselectItemIfNecessary(wxWindow
*win
)
1467 if (win
->IsKindOf(CLASSINFO(wxControl
)) && (win
->GetEventHandler() != win
))
1469 // Deselect and refresh window in case we leave selection
1471 wxControl
*item
= (wxControl
*)win
;
1472 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1473 if (childHandler
->IsSelected())
1475 wxResourceManager::GetCurrentResourceManager()->RemoveSelection(item
);
1476 childHandler
->SelectItem(FALSE
);
1478 item
->GetParent()->Refresh();
1484 // Need to search through resource table removing this from
1485 // any resource which has this as a parent.
1486 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1488 m_resourceTable
.BeginFind();
1490 while ((node
= m_resourceTable
.Next()))
1492 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1493 if (thisRes
->GetChildren().Member(res
))
1495 thisRes
->GetChildren().DeleteObject(res
);
1502 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1507 RemoveResourceFromParent(res
);
1509 wxNode
*node
= res
->GetChildren().First();
1512 wxNode
*next
= node
->Next();
1513 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1514 DeleteResource(child
);
1518 // If this is a button or message resource, delete the
1519 // associate bitmap resource if not being used.
1520 wxString
resType(res
->GetType());
1522 /* shouldn't have to do this now bitmaps are ref-counted
1523 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1525 PossiblyDeleteBitmapResource(res->GetValue4());
1529 // Remove symbol from table if appropriate
1530 if (!IsSymbolUsed(res
, res
->GetId()))
1532 m_symbolTable
.RemoveSymbol(res
->GetId());
1535 m_resourceTable
.Delete(res
->GetName());
1541 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1543 DeselectItemIfNecessary(win
);
1545 wxItemResource
*res
= FindResourceForWindow(win
);
1547 DisassociateResource(res
);
1548 DeleteResource(res
);
1549 UpdateResourceList();
1554 // Will eventually have bitmap type information, for different
1556 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1558 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1562 MakeUniqueName("bitmap", buf
);
1563 resource
= new wxItemResource
;
1564 resource
->SetType("wxBitmap");
1565 resource
->SetName(buf
);
1567 // A bitmap resource has one or more children, specifying
1568 // alternative bitmaps.
1569 wxItemResource
*child
= new wxItemResource
;
1570 child
->SetType("wxBitmap");
1571 child
->SetName(filename
);
1572 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1573 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1574 child
->SetValue3(0); // Depth
1575 child
->SetSize(0,0,0,0);
1576 resource
->GetChildren().Append(child
);
1578 m_resourceTable
.AddResource(resource
);
1580 UpdateResourceList();
1583 return resource
->GetName();
1585 return wxEmptyString
;
1588 // Delete the bitmap resource if it isn't being used by another resource.
1589 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1591 if (!IsBitmapResourceUsed(resourceName
))
1593 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1594 DeleteResource(res
);
1595 UpdateResourceList();
1599 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1601 m_resourceTable
.BeginFind();
1603 while ((node
= m_resourceTable
.Next()))
1605 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1606 wxString
resType(res
->GetType());
1607 if (resType
== "wxDialog")
1609 wxNode
*node1
= res
->GetChildren().First();
1612 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1613 wxString
childResType(child
->GetType());
1615 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1616 child
->GetValue4() &&
1617 (strcmp(child
->GetValue4(), resourceName
) == 0))
1619 node1
= node1
->Next();
1626 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1627 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1629 if (!resource
|| (resource
->GetValue4() == ""))
1630 return wxEmptyString
;
1631 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1632 if (!bitmapResource
)
1633 return wxEmptyString
;
1635 wxNode
*node
= bitmapResource
->GetChildren().First();
1638 // Eventually augment this to return a bitmap of the right kind or something...
1639 // Maybe the root of the filename remains the same, so it doesn't matter which we
1640 // pick up. Otherwise how do we specify multiple filenames... too boring...
1641 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1642 return child
->GetName();
1644 //node = node->Next();
1646 return wxEmptyString
;
1649 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1651 m_resourceTable
.BeginFind();
1653 while ((node
= m_resourceTable
.Next()))
1655 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1656 wxString
resType(res
->GetType());
1657 if (resType
== "wxBitmap")
1659 wxNode
*node1
= res
->GetChildren().First();
1662 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1663 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1665 node1
= node1
->Next();
1672 // Is this window identifier symbol in use?
1673 // Let's assume that we can't have 2 names for the same integer id.
1674 // Therefore we can tell by the integer id whether the symbol is
1676 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1678 m_resourceTable
.BeginFind();
1680 while ((node
= m_resourceTable
.Next()))
1682 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1684 wxString
resType(res
->GetType());
1685 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1687 if ((res
!= thisResource
) && (res
->GetId() == id
))
1690 wxNode
*node1
= res
->GetChildren().First();
1693 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1694 if ((child
!= thisResource
) && (child
->GetId() == id
))
1696 node1
= node1
->Next();
1703 // Is this window identifier compatible with the given name? (i.e.
1704 // does it already exist under a different name)
1705 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1707 if (m_symbolTable
.SymbolExists(name
))
1709 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1716 // Change all integer ids that match oldId, to newId.
1717 // This is necessary if an id is changed for one resource - all resources
1719 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1721 m_resourceTable
.BeginFind();
1723 while ((node
= m_resourceTable
.Next()))
1725 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1727 wxString
resType(res
->GetType());
1728 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1730 if (res
->GetId() == oldId
)
1733 wxNode
*node1
= res
->GetChildren().First();
1736 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1737 if (child
->GetId() == oldId
)
1738 child
->SetId(newId
);
1740 node1
= node1
->Next();
1746 // If any resource ids were missing (or their symbol was missing),
1747 // repair them i.e. give them new ids. Returns TRUE if any resource
1748 // needed repairing.
1749 bool wxResourceManager::RepairResourceIds()
1751 bool repaired
= FALSE
;
1753 m_resourceTable
.BeginFind();
1755 while ((node
= m_resourceTable
.Next()))
1757 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1758 wxString
resType(res
->GetType());
1759 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1762 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1764 wxString newSymbolName
;
1765 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1767 if (res
->GetId() == 0)
1770 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1774 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1780 wxNode
*node1
= res
->GetChildren().First();
1783 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1785 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1787 wxString newSymbolName
;
1788 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1790 if (child
->GetId() == 0)
1792 child
->SetId(newId
);
1793 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1797 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1803 node1
= node1
->Next();
1811 // Deletes 'win' and creates a new window from the resource that
1812 // was associated with it. E.g. if you can't change properties on the
1813 // fly, you'll need to delete the window and create it again.
1814 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
, bool instantiateFirst
)
1816 wxItemResource
*resource
= FindResourceForWindow(win
);
1818 // Put the current window properties into the wxItemResource object
1820 wxWindowPropertyInfo
*newInfo
= NULL
;
1823 newInfo
= CreatePropertyInfoForWindow(win
);
1827 // May not always want to copy values back from the resource
1828 if (instantiateFirst
)
1829 info
->InstantiateResource(resource
);
1831 wxWindow
*newWin
= NULL
;
1832 wxWindow
*parent
= win
->GetParent();
1833 wxItemResource
* parentResource
= NULL
;
1835 parentResource
= FindResourceForWindow(parent
);
1837 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1840 newWin
= FindWindowForResource(resource
);
1844 DisassociateResource(resource
);
1845 if (win
->GetEventHandler() != win
)
1846 win
->PopEventHandler(TRUE
);
1849 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1850 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1851 AssociateResource(resource
, newWin
);
1852 UpdateResourceList();
1856 info
->SetPropertyWindow(newWin
);
1864 // Delete resource highlighted in the listbox
1865 bool wxResourceManager::DeleteSelection()
1867 int sel
= m_editorResourceTree
->GetSelection();
1870 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1871 wxItemResource
*res
= data
->GetResource();
1872 wxWindow
*win
= FindWindowForResource(res
);
1875 DeleteResource(win
);
1877 UpdateResourceList();
1886 // Delete resource highlighted in the listbox
1887 bool wxResourceManager::RecreateSelection()
1889 wxNode
*node
= GetSelections().First();
1892 wxControl
*item
= (wxControl
*)node
->Data();
1893 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1894 wxNode
*next
= node
->Next();
1895 childHandler
->SelectItem(FALSE
);
1897 RemoveSelection(item
);
1899 RecreateWindowFromResource(item
);
1906 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
1911 // Ensures that all currently shown windows are saved to resources,
1912 // e.g. just before writing to a .wxr file.
1913 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1915 m_resourceTable
.BeginFind();
1917 while ((node
= m_resourceTable
.Next()))
1919 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1920 wxString
resType(res
->GetType());
1922 if (resType
== "wxDialog")
1924 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1926 InstantiateResourceFromWindow(res
, win
, TRUE
);
1928 else if (resType
== "wxPanel")
1930 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1932 InstantiateResourceFromWindow(res
, win
, TRUE
);
1938 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1940 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1941 info
->SetResource(resource
);
1942 info
->InstantiateResource(resource
);
1947 wxNode
*node
= resource
->GetChildren().First();
1950 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1951 wxWindow
*childWindow
= FindWindowForResource(child
);
1956 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
1957 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1960 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1961 node
= node
->Next();
1968 // Create a window information object for the give window
1969 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1971 wxWindowPropertyInfo
*info
= NULL
;
1972 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1974 info
= new wxScrollBarPropertyInfo(win
);
1976 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1978 info
= new wxGroupBoxPropertyInfo(win
);
1980 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1982 info
= new wxCheckBoxPropertyInfo(win
);
1984 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1986 info
= new wxSliderPropertyInfo(win
);
1988 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1990 info
= new wxGaugePropertyInfo(win
);
1992 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1994 info
= new wxListBoxPropertyInfo(win
);
1996 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1998 info
= new wxRadioBoxPropertyInfo(win
);
2000 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
2002 info
= new wxRadioButtonPropertyInfo(win
);
2004 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
2006 info
= new wxComboBoxPropertyInfo(win
);
2008 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
2010 info
= new wxChoicePropertyInfo(win
);
2012 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
2014 info
= new wxBitmapButtonPropertyInfo(win
);
2016 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
2018 info
= new wxButtonPropertyInfo(win
);
2020 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
2022 info
= new wxStaticBitmapPropertyInfo(win
);
2024 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
2026 info
= new wxStaticTextPropertyInfo(win
);
2028 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
2030 info
= new wxTextPropertyInfo(win
);
2032 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
2034 info
= new wxPanelPropertyInfo(win
);
2038 info
= new wxWindowPropertyInfo(win
);
2043 // Edit the given window
2044 void wxResourceManager::EditWindow(wxWindow
*win
)
2046 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2049 info
->SetResource(FindResourceForWindow(win
));
2050 wxString
str("Editing ");
2051 str
+= win
->GetClassInfo()->GetClassName();
2053 if (win
->GetName() != "")
2054 str
+= win
->GetName();
2056 str
+= "properties";
2057 info
->Edit(NULL
, str
);
2061 // Generate a window id and a first stab at a name
2062 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2064 m_symbolIdCounter
++;
2065 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2066 m_symbolIdCounter
++;
2068 int nameId
= m_symbolIdCounter
;
2071 str
.Printf("%d", nameId
);
2072 idName
= prefix
+ str
;
2074 while (m_symbolTable
.SymbolExists(idName
))
2077 str
.Printf("%d", nameId
);
2078 idName
= prefix
+ str
;
2081 return m_symbolIdCounter
;
2086 * Resource editor frame
2089 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2091 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2092 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2093 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2094 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2095 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2096 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2097 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2098 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2099 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2100 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2101 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2102 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2103 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2104 EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow
)
2107 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2108 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2109 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2114 wxResourceEditorFrame::~wxResourceEditorFrame()
2118 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2120 manager
->New(FALSE
);
2123 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2125 manager
->CreateNewPanel();
2128 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2133 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2135 manager
->Clear(TRUE
, FALSE
);
2138 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2143 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2148 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2150 manager
->Clear(TRUE
, FALSE
) ;
2154 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2157 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart <julian.smart@ukonline.co.uk>\nJulian Smart (c) 1996-1999", wxDIALOG_EDITOR_VERSION
);
2158 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2161 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2163 manager
->TestCurrentDialog(this);
2166 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2169 wxBeginBusyCursor();
2170 manager
->GetHelpController()->LoadFile();
2171 manager
->GetHelpController()->DisplayContents();
2176 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2178 manager
->DeleteSelection();
2181 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2183 manager
->RecreateSelection();
2186 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent
& event
)
2188 wxPropertyInfo::CloseWindow();
2189 if (manager
->Modified())
2191 if (!manager
->Clear(TRUE
, FALSE
))
2202 manager
->m_resourceEditorWindowSize
.width
= w
;
2203 manager
->m_resourceEditorWindowSize
.height
= h
;
2206 GetPosition(&x
, &y
);
2208 manager
->m_resourceEditorWindowSize
.x
= x
;
2209 manager
->m_resourceEditorWindowSize
.y
= y
;
2211 manager
->SetEditorFrame(NULL
);
2212 manager
->SetEditorToolBar(NULL
);
2218 * Resource editor window that contains the dialog/panel being edited
2221 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2222 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2225 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2227 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2231 m_childWindow
= NULL
;
2233 SetBackgroundColour(* wxWHITE
);
2236 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2240 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2247 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2251 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2254 wxString
str(res
->GetTitle());
2256 ViewStart(& x
, & y
);
2258 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2260 dc
.SetBackgroundMode(wxTRANSPARENT
);
2261 dc
.SetTextForeground(wxColour(0, 0, 0));
2264 dc
.GetTextExtent(str
, & w
, & h
);
2266 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2271 // Popup menu callback
2272 void ObjectMenuProc(wxMenu
*menu
, wxCommandEvent
& event
)
2274 wxWindow
*data
= (wxWindow
*)menu
->GetClientData();
2278 switch (event
.GetInt())
2280 case OBJECT_MENU_EDIT
:
2282 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2285 case OBJECT_MENU_DELETE
:
2287 wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data
);
2289 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2290 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2291 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2304 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2305 // EVT_PAINT(EditorToolBar::OnPaint)
2308 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2310 wxToolBar(frame
, -1, pos
, size
, style
)
2314 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2316 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2320 case TOOLBAR_LOAD_FILE
:
2327 manager
->CreateNewPanel();
2330 case TOOLBAR_SAVE_FILE
:
2338 wxBeginBusyCursor();
2339 manager
->GetHelpController()->LoadFile();
2340 manager
->GetHelpController()->DisplayContents();
2345 case TOOLBAR_FORMAT_HORIZ
:
2347 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2350 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2352 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2355 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2357 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2360 case TOOLBAR_FORMAT_VERT
:
2362 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2365 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2367 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2370 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2372 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2375 case TOOLBAR_COPY_SIZE
:
2377 manager
->CopySize();
2380 case TOOLBAR_TO_BACK
:
2382 manager
->ToBackOrFront(TRUE
);
2385 case TOOLBAR_TO_FRONT
:
2387 manager
->ToBackOrFront(FALSE
);
2396 void EditorToolBar::OnMouseEnter(int toolIndex
)
2398 wxFrame
*frame
= (wxFrame
*)GetParent();
2406 case TOOLBAR_LOAD_FILE
:
2407 frame
->SetStatusText("Load project file");
2409 case TOOLBAR_SAVE_FILE
:
2410 frame
->SetStatusText("Save project file");
2413 frame
->SetStatusText("Create a new resource");
2415 case TOOLBAR_FORMAT_HORIZ
:
2416 frame
->SetStatusText("Align items horizontally");
2418 case TOOLBAR_FORMAT_VERT
:
2419 frame
->SetStatusText("Align items vertically");
2421 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2422 frame
->SetStatusText("Left-align items");
2424 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2425 frame
->SetStatusText("Right-align items");
2427 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2428 frame
->SetStatusText("Top-align items");
2430 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2431 frame
->SetStatusText("Bottom-align items");
2433 case TOOLBAR_COPY_SIZE
:
2434 frame
->SetStatusText("Copy size from first selection");
2436 case TOOLBAR_TO_FRONT
:
2437 frame
->SetStatusText("Put image to front");
2439 case TOOLBAR_TO_BACK
:
2440 frame
->SetStatusText("Put image to back");
2443 frame
->SetStatusText("Display help contents");
2449 else frame
->SetStatusText("");