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"
37 #include "wx/scrolbar.h"
44 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
47 #include <strstream.h>
62 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
63 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
66 #include "bitmaps/load.xbm"
67 #include "bitmaps/save.xbm"
68 #include "bitmaps/new.xbm"
69 #include "bitmaps/vert.xbm"
70 #include "bitmaps/alignt.xbm"
71 #include "bitmaps/alignb.xbm"
72 #include "bitmaps/horiz.xbm"
73 #include "bitmaps/alignl.xbm"
74 #include "bitmaps/alignr.xbm"
75 #include "bitmaps/copysize.xbm"
76 #include "bitmaps/tofront.xbm"
77 #include "bitmaps/toback.xbm"
78 #include "bitmaps/help.xbm"
79 #include "bitmaps/wxwin.xbm"
86 wxResourceManager::wxResourceManager():
87 m_imageList(16, 16, TRUE
)
89 sm_currentResourceManager
= this;
93 m_editorResourceTree
= NULL
;
94 m_editorControlList
= NULL
;
97 m_currentFilename
= "";
98 m_symbolFilename
= "";
99 m_editorToolBar
= NULL
;
101 // Default window positions
102 m_resourceEditorWindowSize
.width
= 470;
103 m_resourceEditorWindowSize
.height
= 300;
105 m_resourceEditorWindowSize
.x
= 0;
106 m_resourceEditorWindowSize
.y
= 0;
108 m_propertyWindowSize
.width
= 300;
109 m_propertyWindowSize
.height
= 300;
111 m_helpController
= NULL
;
113 m_bitmapImage
= NULL
;
114 m_rootDialogItem
= 0;
117 wxResourceManager::~wxResourceManager()
119 sm_currentResourceManager
= NULL
;
122 if (m_helpController
)
124 m_helpController
->Quit();
125 delete m_helpController
;
126 m_helpController
= NULL
;
128 delete m_bitmapImage
;
132 bool wxResourceManager::Initialize()
134 // Set up the resource filename for each platform.
136 // dialoged.ini in the Windows directory
138 GetWindowsDirectory(buf
, 256);
139 strcat(buf
, "\\dialoged.ini");
140 m_optionsResourceFilename
= buf
;
144 strcat(buf
, "/.dialogedrc");
145 m_optionsResourceFilename
= buf
;
147 #error "Unsupported platform."
152 m_helpController
= new wxHelpController
;
153 m_helpController
->Initialize("dialoged");
155 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
156 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
157 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
162 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
165 m_bitmapImage
= new wxBitmap(wxwin_bits
, wxwin_width
, wxwin_height
);
169 // Initialize the image list icons
171 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
172 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
173 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
174 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
175 m_imageList
.Add(icon1
);
176 m_imageList
.Add(icon2
);
177 m_imageList
.Add(icon3
);
178 m_imageList
.Add(icon4
);
184 bool wxResourceManager::LoadOptions()
186 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize
.x
, m_optionsResourceFilename
.GetData());
187 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize
.y
, m_optionsResourceFilename
.GetData());
188 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize
.width
, m_optionsResourceFilename
.GetData());
189 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize
.height
, m_optionsResourceFilename
.GetData());
190 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize
.x
, m_optionsResourceFilename
.GetData());
191 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize
.y
, m_optionsResourceFilename
.GetData());
192 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize
.width
, m_optionsResourceFilename
.GetData());
193 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize
.height
, m_optionsResourceFilename
.GetData());
197 bool wxResourceManager::SaveOptions()
199 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize
.x
, m_optionsResourceFilename
.GetData());
200 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize
.y
, m_optionsResourceFilename
.GetData());
201 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize
.width
, m_optionsResourceFilename
.GetData());
202 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize
.height
, m_optionsResourceFilename
.GetData());
204 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize
.x
, m_optionsResourceFilename
.GetData());
205 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize
.y
, m_optionsResourceFilename
.GetData());
206 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize
.width
, m_optionsResourceFilename
.GetData());
207 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize
.height
, m_optionsResourceFilename
.GetData());
212 // Show or hide the resource editor frame, which displays a list
213 // of resources with ability to edit them.
214 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*parent
, const char *title
)
220 m_editorFrame
->Iconize(FALSE
);
221 m_editorFrame
->Show(TRUE
);
224 m_editorFrame
= OnCreateEditorFrame(title
);
226 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
227 m_editorFrame
->SetMenuBar(menuBar
);
229 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
230 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
231 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
233 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
235 m_editorResourceTree
->SetImageList(& m_imageList
);
237 // Constraints for toolbar
238 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
239 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
240 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
241 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
242 c
->bottom
.Unconstrained();
243 c
->width
.Unconstrained();
244 c
->height
.Absolute(28);
245 m_editorToolBar
->SetConstraints(c
);
247 // Constraints for listbox
248 c
= new wxLayoutConstraints
;
249 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
250 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
251 c
->right
.Absolute (150);
252 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
253 c
->width
.Unconstrained();
254 c
->height
.Unconstrained();
255 m_editorResourceTree
->SetConstraints(c
);
257 // Constraints for panel
258 c
= new wxLayoutConstraints
;
259 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
260 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
261 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
262 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
263 c
->width
.Unconstrained();
264 c
->height
.Unconstrained();
265 m_editorPanel
->SetConstraints(c
);
267 // Constraints for control list (bottom window)
268 c
= new wxLayoutConstraints
;
269 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
270 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
271 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
272 c
->width
.Unconstrained();
273 c
->height
.Absolute(60);
274 m_editorControlList
->SetConstraints(c
);
276 m_editorFrame
->SetAutoLayout(TRUE
);
278 UpdateResourceList();
280 m_editorFrame
->Show(TRUE
);
285 wxFrame
*fr
= m_editorFrame
;
286 if (m_editorFrame
->OnClose())
290 m_editorFrame
= NULL
;
291 m_editorPanel
= NULL
;
297 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
301 if (filename
== wxString(""))
302 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
305 wxString
str("wxWindows Dialog Editor - ");
306 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
308 m_editorFrame
->SetTitle(str
);
313 bool wxResourceManager::Save()
315 if (m_currentFilename
== wxString(""))
318 return Save(m_currentFilename
);
321 bool wxResourceManager::Save(const wxString
& filename
)
323 // Ensure all visible windows are saved to their resources
324 m_currentFilename
= filename
;
325 SetFrameTitle(m_currentFilename
);
326 InstantiateAllResourcesFromWindows();
327 if (m_resourceTable
.Save(filename
))
336 bool wxResourceManager::SaveAs()
338 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
339 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
));
341 if (s
.IsNull() || s
== "")
344 m_currentFilename
= s
;
345 Save(m_currentFilename
);
349 bool wxResourceManager::SaveIfModified()
356 bool wxResourceManager::Load(const wxString
& filename
)
358 return New(TRUE
, filename
);
361 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
363 if (!Clear(TRUE
, FALSE
))
368 wxString str
= filename
;
369 if (str
== wxString(""))
371 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, NULL
));
372 if (!f
.IsNull() && f
!= "")
378 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
380 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
383 m_currentFilename
= str
;
385 SetFrameTitle(m_currentFilename
);
387 UpdateResourceList();
389 // Construct include filename from this file
390 m_symbolFilename
= m_currentFilename
;
392 if (m_symbolFilename
[0] == 'c')
396 wxString
stringA("123456.45");
397 wxString
stringB("");
403 size_t len
= stringB
.Length();
407 // if (buffer.GetChar(i) == '.')
408 if (stringB
[i
] == '.')
410 stringB
= stringB
.Left(i
);
418 size_t len
= m_symbolFilename
.Length();
422 // if (buffer.GetChar(i) == '.')
423 if (m_symbolFilename
[i
] == '.')
425 m_symbolFilename
= m_symbolFilename
.Left(i
);
431 // wxStripExtension(m_symbolFilename);
432 m_symbolFilename
+= ".h";
434 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
436 wxString
str("Could not find include file ");
437 str
+= m_symbolFilename
;
438 wxMessageBox(str
, "Dialog Editor Warning", MB_OK
);
444 m_currentFilename
= "";
451 bool wxResourceManager::Clear(bool deleteWindows
, bool force
)
453 if (!force
&& Modified())
455 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
459 if (!SaveIfModified())
465 ClearCurrentDialog();
466 DisassociateWindows();
468 m_symbolTable
.Clear();
469 m_resourceTable
.ClearTable();
470 UpdateResourceList();
475 bool wxResourceManager::DisassociateWindows()
477 m_resourceTable
.BeginFind();
479 while (node
= m_resourceTable
.Next())
481 wxItemResource
*res
= (wxItemResource
*)node
->Data();
482 DisassociateResource(res
);
488 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
490 if (!m_resourceAssociations
.Get((long)resource
))
491 m_resourceAssociations
.Put((long)resource
, win
);
493 wxNode
*node
= resource
->GetChildren().First();
496 wxItemResource
*child
= (wxItemResource
*)node
->Data();
497 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
499 childWindow
= win
->FindWindow(child
->GetName());
501 AssociateResource(child
, childWindow
);
505 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? child
->GetName() : "(unnamed)");
506 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
513 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
515 wxWindow
*win
= FindWindowForResource(resource
);
519 // Disassociate children of window
520 if (win
->GetChildren())
522 wxNode
*node
= win
->GetChildren()->First();
525 wxWindow
*child
= (wxWindow
*)node
->Data();
526 if (child
->IsKindOf(CLASSINFO(wxControl
)))
527 DisassociateResource(child
);
532 RemoveSelection(win
);
533 m_resourceAssociations
.Delete((long)resource
);
537 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
539 wxItemResource
*res
= FindResourceForWindow(win
);
541 return DisassociateResource(res
);
546 // Saves the window info into the resource, and deletes the
547 // handler. Doesn't actually disassociate the window from
548 // the resources. Replaces OnClose.
549 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
551 wxItemResource
*res
= FindResourceForWindow(win
);
553 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
555 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
556 win
->PopEventHandler();
558 // Now reset all child event handlers
559 wxNode
*node
= win
->GetChildren()->First();
562 wxWindow
*child
= (wxWindow
*)node
->Data();
563 wxEvtHandler
*childHandler
= child
->GetEventHandler();
564 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
566 child
->PopEventHandler(TRUE
);
574 win
->PopEventHandler(TRUE
);
577 // Save the information
578 InstantiateResourceFromWindow(res
, win
, TRUE
);
580 // DisassociateResource(win);
585 // Destroys the window. If this is the 'current' panel, NULLs the
587 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
589 bool clearDisplay
= FALSE
;
590 if (m_editorPanel
->m_childWindow
== win
)
592 m_editorPanel
->m_childWindow
= NULL
;
599 m_editorPanel
->Clear();
604 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
606 m_resourceAssociations
.BeginFind();
608 while (node
= m_resourceAssociations
.Next())
610 wxWindow
*w
= (wxWindow
*)node
->Data();
613 return (wxItemResource
*)node
->key
.integer
;
619 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
621 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
625 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
629 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
632 if (!m_resourceTable
.FindResource(buf
))
637 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
639 int frameWidth
= 420;
640 int frameHeight
= 300;
642 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
643 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
644 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
645 wxDEFAULT_FRAME_STYLE
);
647 frame
->CreateStatusBar(1);
649 frame
->SetAutoLayout(TRUE
);
651 wxIcon
*icon
= new wxIcon("DIALOGEDICON");
652 frame
->SetIcon(icon
);
657 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*parent
)
659 wxMenuBar
*menuBar
= new wxMenuBar
;
661 wxMenu
*fileMenu
= new wxMenu
;
662 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
663 fileMenu
->AppendSeparator();
664 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
665 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
666 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
667 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
668 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
669 fileMenu
->AppendSeparator();
670 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
672 wxMenu
*editMenu
= new wxMenu
;
673 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
674 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
675 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
677 wxMenu
*helpMenu
= new wxMenu
;
678 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
679 helpMenu
->AppendSeparator();
680 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
682 menuBar
->Append(fileMenu
, "&File");
683 menuBar
->Append(editMenu
, "&Edit");
684 menuBar
->Append(helpMenu
, "&Help");
689 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
691 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
692 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
695 panel
->SetScrollbars(10, 10, 100, 100);
700 wxToolBarBase
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
702 // Load palette bitmaps
704 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
705 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
706 wxBitmap
ToolbarNewBitmap("NEWTOOL");
707 wxBitmap
ToolbarVertBitmap("VERTTOOL");
708 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
709 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
710 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
711 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
712 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
713 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
714 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
715 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
716 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
719 wxBitmap
ToolbarLoadBitmap(load_bits
, load_width
, load_height
);
720 wxBitmap
ToolbarSaveBitmap(save_bits
, save_width
, save_height
);
721 wxBitmap
ToolbarNewBitmap(new_bits
, save_width
, save_height
);
722 wxBitmap
ToolbarVertBitmap(vert_bits
, vert_width
, vert_height
);
723 wxBitmap
ToolbarAlignTBitmap(alignt_bits
, alignt_width
, alignt_height
);
724 wxBitmap
ToolbarAlignBBitmap(alignb_bits
, alignb_width
, alignb_height
);
725 wxBitmap
ToolbarHorizBitmap(horiz_bits
, horiz_width
, horiz_height
);
726 wxBitmap
ToolbarAlignLBitmap(alignl_bits
, alignl_width
, alignl_height
);
727 wxBitmap
ToolbarAlignRBitmap(alignr_bits
, alignr_width
, alignr_height
);
728 wxBitmap
ToolbarCopySizeBitmap(copysize_bits
, copysize_width
, copysize_height
);
729 wxBitmap
ToolbarToBackBitmap(toback_bits
, toback_width
, toback_height
);
730 wxBitmap
ToolbarToFrontBitmap(tofront_bits
, tofront_width
, tofront_height
);
731 wxBitmap
ToolbarHelpBitmap(help_bits
, help_width
, help_height
);
734 // Create the toolbar
735 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
,
737 toolbar
->SetMargins(2, 2);
738 // toolbar->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH);
745 int width
= ToolbarLoadBitmap
->GetWidth();
750 toolbar
->AddSeparator();
751 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, (wxBitmap
*)NULL
,
752 FALSE
, (float)currentX
, -1, NULL
, "New dialog");
753 currentX
+= width
+ dx
;
754 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, (wxBitmap
*)NULL
,
755 FALSE
, (float)currentX
, -1, NULL
, "Load");
756 currentX
+= width
+ dx
;
757 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, (wxBitmap
*)NULL
,
758 FALSE
, (float)currentX
, -1, NULL
, "Save");
759 currentX
+= width
+ dx
+ gap
;
760 toolbar
->AddSeparator();
761 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, (wxBitmap
*)NULL
,
762 FALSE
, (float)currentX
, -1, NULL
, "Horizontal align");
763 currentX
+= width
+ dx
;
764 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, (wxBitmap
*)NULL
,
765 FALSE
, (float)currentX
, -1, NULL
, "Top align");
766 currentX
+= width
+ dx
;
767 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, (wxBitmap
*)NULL
,
768 FALSE
, (float)currentX
, -1, NULL
, "Bottom align");
769 currentX
+= width
+ dx
;
770 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, (wxBitmap
*)NULL
,
771 FALSE
, (float)currentX
, -1, NULL
, "Vertical align");
772 currentX
+= width
+ dx
;
773 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, (wxBitmap
*)NULL
,
774 FALSE
, (float)currentX
, -1, NULL
, "Left align");
775 currentX
+= width
+ dx
;
776 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, (wxBitmap
*)NULL
,
777 FALSE
, (float)currentX
, -1, NULL
, "Right align");
778 currentX
+= width
+ dx
;
779 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, (wxBitmap
*)NULL
,
780 FALSE
, (float)currentX
, -1, NULL
, "Copy size");
781 currentX
+= width
+ dx
+ gap
;
782 toolbar
->AddSeparator();
783 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, (wxBitmap
*)NULL
,
784 FALSE
, (float)currentX
, -1, NULL
, "To front");
785 currentX
+= width
+ dx
;
786 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, (wxBitmap
*)NULL
,
787 FALSE
, (float)currentX
, -1, NULL
, "To back");
788 currentX
+= width
+ dx
+ gap
;
790 toolbar
->AddSeparator();
791 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, (wxBitmap
*)NULL
,
792 FALSE
, (float)currentX
, -1, NULL
, "Help");
793 currentX
+= width
+ dx
;
795 toolbar
->CreateTools();
799 // parent->OnSize(-1, -1);
802 void wxResourceManager::UpdateResourceList()
804 if (!m_editorResourceTree
)
807 m_editorResourceTree
->SetInvalid(TRUE
);
808 m_editorResourceTree
->DeleteAllItems();
810 long id
= m_editorResourceTree
->InsertItem(0, "Dialogs"
816 m_resourceTable
.BeginFind();
818 while (node
= m_resourceTable
.Next())
820 wxItemResource
*res
= (wxItemResource
*)node
->Data();
821 wxString
resType(res
->GetType());
822 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
824 AddItemsRecursively(id
, res
);
827 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
828 m_editorResourceTree
->SetInvalid(FALSE
);
831 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
833 wxString
theString("");
834 theString
= resource
->GetName();
837 wxString
resType(resource
->GetType());
838 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
843 long id
= m_editorResourceTree
->InsertItem(parent
, theString
849 m_editorResourceTree
->SetItemData(id
, (long) resource
);
851 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
853 wxNode
*node
= resource
->GetChildren().First();
856 wxItemResource
*res
= (wxItemResource
*)node
->Data();
857 AddItemsRecursively(id
, res
);
861 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
864 bool wxResourceManager::EditSelectedResource()
866 int sel
= m_editorResourceTree
->GetSelection();
869 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
875 bool wxResourceManager::Edit(wxItemResource
*res
)
877 ClearCurrentDialog();
879 wxString
resType(res
->GetType());
880 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
884 wxMessageBox("Should not find panel in wxResourceManager::Edit");
889 long style
= res
->GetStyle();
890 res
->SetStyle(style
|wxRAISED_BORDER
);
892 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
895 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
897 panel
->PushEventHandler(handler
);
899 res
->SetStyle(style
);
900 handler
->AddChildHandlers(); // Add event handlers for all controls
901 AssociateResource(res
, panel
);
903 m_editorPanel
->m_childWindow
= panel
;
904 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
908 wxClientDC
dc(m_editorPanel
);
909 m_editorPanel
->DrawTitle(dc
);
914 bool wxResourceManager::CreateNewPanel()
916 ClearCurrentDialog();
919 MakeUniqueName("panel", buf
);
921 wxItemResource
*resource
= new wxItemResource
;
922 // resource->SetType(wxTYPE_PANEL);
923 resource
->SetType("wxPanel");
924 resource
->SetName(buf
);
925 resource
->SetTitle(buf
);
926 m_resourceTable
.AddResource(resource
);
928 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
929 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
930 wxSize(400, 300), wxRAISED_BORDER
, buf
);
931 m_editorPanel
->m_childWindow
= panel
;
933 resource
->SetStyle(0); // panel->GetWindowStyleFlag());
934 resource
->SetSize(10, 10, 400, 300);
936 // For editing in situ we will need to use the hash table to ensure
937 // we don't dereference invalid pointers.
938 // resourceWindowTable.Put((long)resource, panel);
940 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
942 panel
->PushEventHandler(handler
);
944 AssociateResource(resource
, panel
);
945 UpdateResourceList();
948 m_editorPanel
->m_childWindow
->Refresh();
952 wxClientDC
dc(m_editorPanel
);
953 m_editorPanel
->DrawTitle(dc
);
958 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
961 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
966 wxItemResource
*res
= new wxItemResource
;
967 wxControl
*newItem
= NULL
;
968 res
->SetSize(x
, y
, -1, -1);
971 wxString
itemType(iType
);
973 if (itemType
== "wxButton")
975 MakeUniqueName("button", buf
);
978 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
980 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
982 if (itemType
== "wxBitmapButton")
984 MakeUniqueName("button", buf
);
986 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
988 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
990 MakeUniqueName("message", buf
);
993 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
995 newItem
= new wxStaticText(panel
, -1, "Message", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
997 else if (itemType
== "wxStaticBitmap")
999 MakeUniqueName("message", buf
);
1001 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1003 else if (itemType
== "wxCheckBox")
1005 MakeUniqueName("checkbox", buf
);
1007 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1009 else if (itemType
== "wxListBox")
1011 MakeUniqueName("listbox", buf
);
1013 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1015 else if (itemType
== "wxRadioBox")
1017 MakeUniqueName("radiobox", buf
);
1019 wxString names
[] = { "One", "Two" };
1020 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1021 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1022 res
->SetStringValues(new wxStringList("One", "Two", NULL
));
1024 else if (itemType
== "wxRadioButton")
1026 MakeUniqueName("radiobutton", buf
);
1028 wxString names
[] = { "One", "Two" };
1029 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1030 0, wxDefaultValidator
, buf
);
1032 else if (itemType
== "wxChoice")
1034 MakeUniqueName("choice", buf
);
1036 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1038 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1040 MakeUniqueName("group", buf
);
1042 newItem
= new wxStaticBox(panel
, -1, "Groupbox", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1044 else if (itemType
== "wxGauge")
1046 MakeUniqueName("gauge", buf
);
1048 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1050 else if (itemType
== "wxSlider")
1052 MakeUniqueName("slider", buf
);
1054 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1056 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1058 MakeUniqueName("textctrl", buf
);
1060 res
->SetType("wxTextCtrl");
1061 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1063 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1065 MakeUniqueName("textctrl", buf
);
1067 res
->SetType("wxTextCtrl");
1068 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1070 else if (itemType
== "wxScrollBar")
1072 MakeUniqueName("scrollbar", buf
);
1074 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1079 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1081 res
->SetStyle(newItem
->GetWindowStyleFlag());
1082 AssociateResource(res
, newItem
);
1083 panelResource
->GetChildren().Append(res
);
1085 UpdateResourceList();
1090 void wxResourceManager::ClearCurrentDialog()
1092 if (m_editorPanel
->m_childWindow
)
1094 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1095 DisassociateResource(m_editorPanel
->m_childWindow
);
1096 DeleteWindow(m_editorPanel
->m_childWindow
);
1097 m_editorPanel
->m_childWindow
= NULL
;
1098 m_editorPanel
->Clear();
1102 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1104 if (m_editorPanel
->m_childWindow
)
1106 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1110 // Make sure the resources are up-to-date w.r.t. the window
1111 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1113 wxDialog
* dialog
= new wxDialog
;
1114 long oldStyle
= item
->GetStyle();
1115 bool success
= FALSE
;
1116 item
->SetStyle(wxDEFAULT_DIALOG_STYLE
);
1117 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1120 dialog
->ShowModal();
1123 item
->SetStyle(oldStyle
);
1129 // Find the first dialog or panel for which
1130 // there is a selected panel item.
1131 wxWindow
*wxResourceManager::FindParentOfSelection()
1133 m_resourceTable
.BeginFind();
1135 while (node
= m_resourceTable
.Next())
1137 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1138 wxWindow
*win
= FindWindowForResource(res
);
1141 wxNode
*node1
= win
->GetChildren()->First();
1144 wxControl
*item
= (wxControl
*)node1
->Data();
1145 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1146 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1148 node1
= node1
->Next();
1155 // Format the panel items according to 'flag'
1156 void wxResourceManager::AlignItems(int flag
)
1158 wxWindow
*win
= FindParentOfSelection();
1162 wxNode
*node
= GetSelections().First();
1166 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1167 if (firstSelection
->GetParent() != win
)
1172 firstSelection
->GetPosition(&firstX
, &firstY
);
1173 firstSelection
->GetSize(&firstW
, &firstH
);
1174 int centreX
= (int)(firstX
+ (firstW
/ 2));
1175 int centreY
= (int)(firstY
+ (firstH
/ 2));
1177 while (node
= node
->Next())
1179 wxControl
*item
= (wxControl
*)node
->Data();
1180 if (item
->GetParent() == win
)
1183 item
->GetPosition(&x
, &y
);
1184 item
->GetSize(&w
, &h
);
1190 case TOOLBAR_FORMAT_HORIZ
:
1193 newY
= (int)(centreY
- (h
/2.0));
1196 case TOOLBAR_FORMAT_VERT
:
1198 newX
= (int)(centreX
- (w
/2.0));
1202 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1208 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1214 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1216 newX
= firstX
+ firstW
- w
;
1220 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1223 newY
= firstY
+ firstH
- h
;
1231 item
->SetSize(newX
, newY
, w
, h
);
1237 // Copy the first image's size to subsequent images
1238 void wxResourceManager::CopySize()
1240 wxWindow
*win
= FindParentOfSelection();
1244 wxNode
*node
= GetSelections().First();
1248 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1249 if (firstSelection
->GetParent() != win
)
1254 firstSelection
->GetPosition(&firstX
, &firstY
);
1255 firstSelection
->GetSize(&firstW
, &firstH
);
1256 int centreX
= (int)(firstX
+ (firstW
/ 2));
1257 int centreY
= (int)(firstY
+ (firstH
/ 2));
1259 while (node
= node
->Next())
1261 wxControl
*item
= (wxControl
*)node
->Data();
1262 if (item
->GetParent() == win
)
1263 item
->SetSize(-1, -1, firstW
, firstH
);
1268 void wxResourceManager::ToBackOrFront(bool toBack
)
1270 wxWindow
*win
= FindParentOfSelection();
1273 wxItemResource
*winResource
= FindResourceForWindow(win
);
1275 wxNode
*node
= GetSelections().First();
1278 wxControl
*item
= (wxControl
*)node
->Data();
1279 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1280 if (item
->GetParent() == win
)
1282 win
->GetChildren()->DeleteObject(item
);
1284 winResource
->GetChildren().DeleteObject(itemResource
);
1287 win
->GetChildren()->Insert(item
);
1289 winResource
->GetChildren().Insert(itemResource
);
1293 win
->GetChildren()->Append(item
);
1295 winResource
->GetChildren().Append(itemResource
);
1298 node
= node
->Next();
1303 void wxResourceManager::AddSelection(wxWindow
*win
)
1305 if (!m_selections
.Member(win
))
1306 m_selections
.Append(win
);
1309 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1311 m_selections
.DeleteObject(win
);
1314 // Need to search through resource table removing this from
1315 // any resource which has this as a parent.
1316 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1318 m_resourceTable
.BeginFind();
1320 while (node
= m_resourceTable
.Next())
1322 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1323 if (thisRes
->GetChildren().Member(res
))
1325 thisRes
->GetChildren().DeleteObject(res
);
1332 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1337 RemoveResourceFromParent(res
);
1339 wxNode
*node
= res
->GetChildren().First();
1342 wxNode
*next
= node
->Next();
1343 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1344 DeleteResource(child
);
1348 // If this is a button or message resource, delete the
1349 // associate bitmap resource if not being used.
1350 wxString
resType(res
->GetType());
1352 if ((resType
== "wxMessage" || resType
== "wxStaticBitmap" || resType
== "wxButton" || resType
== "wxBitmapButton") && res
->GetValue4())
1354 PossiblyDeleteBitmapResource(res
->GetValue4());
1357 m_resourceTable
.Delete(res
->GetName());
1363 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1365 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1367 // Deselect and refresh window in case we leave selection
1369 wxControl
*item
= (wxControl
*)win
;
1370 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1371 if (childHandler
->IsSelected())
1373 RemoveSelection(item
);
1374 childHandler
->SelectItem(FALSE
);
1375 item
->GetParent()->Refresh();
1379 wxItemResource
*res
= FindResourceForWindow(win
);
1381 DisassociateResource(res
);
1382 DeleteResource(res
);
1383 UpdateResourceList();
1388 // Will eventually have bitmap type information, for different
1390 char *wxResourceManager::AddBitmapResource(char *filename
)
1392 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1396 MakeUniqueName("bitmap", buf
);
1397 resource
= new wxItemResource
;
1398 resource
->SetType("wxBitmap");
1399 resource
->SetName(buf
);
1401 // A bitmap resource has one or more children, specifying
1402 // alternative bitmaps.
1403 wxItemResource
*child
= new wxItemResource
;
1404 child
->SetType("wxBitmap");
1405 child
->SetName(filename
);
1406 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1407 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1408 child
->SetValue3(0); // Depth
1409 child
->SetSize(0,0,0,0);
1410 resource
->GetChildren().Append(child
);
1412 m_resourceTable
.AddResource(resource
);
1414 UpdateResourceList();
1417 return resource
->GetName();
1422 // Delete the bitmap resource if it isn't being used by another resource.
1423 void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName
)
1425 if (!IsBitmapResourceUsed(resourceName
))
1427 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1428 DeleteResource(res
);
1429 UpdateResourceList();
1433 bool wxResourceManager::IsBitmapResourceUsed(char *resourceName
)
1435 m_resourceTable
.BeginFind();
1437 while (node
= m_resourceTable
.Next())
1439 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1440 wxString
resType(res
->GetType());
1441 if (resType
== "wxDialog")
1443 wxNode
*node1
= res
->GetChildren().First();
1446 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1447 wxString
childResType(child
->GetType());
1449 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1450 child
->GetValue4() &&
1451 (strcmp(child
->GetValue4(), resourceName
) == 0))
1453 node1
= node1
->Next();
1460 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1461 char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1463 if (!resource
|| !resource
->GetValue4())
1465 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1466 if (!bitmapResource
)
1469 wxNode
*node
= bitmapResource
->GetChildren().First();
1472 // Eventually augment this to return a bitmap of the right kind or something...
1473 // Maybe the root of the filename remains the same, so it doesn't matter which we
1474 // pick up. Otherwise how do we specify multiple filenames... too boring...
1475 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1476 return child
->GetName();
1478 node
= node
->Next();
1483 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(char *filename
)
1485 m_resourceTable
.BeginFind();
1487 while (node
= m_resourceTable
.Next())
1489 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1490 wxString
resType(res
->GetType());
1491 if (resType
== "wxBitmap")
1493 wxNode
*node1
= res
->GetChildren().First();
1496 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1497 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1499 node1
= node1
->Next();
1506 // Deletes 'win' and creates a new window from the resource that
1507 // was associated with it. E.g. if you can't change properties on the
1508 // fly, you'll need to delete the window and create it again.
1509 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1511 wxItemResource
*resource
= FindResourceForWindow(win
);
1513 // Put the current window properties into the wxItemResource object
1515 wxWindowPropertyInfo
*newInfo
= NULL
;
1518 newInfo
= CreatePropertyInfoForWindow(win
);
1522 info
->InstantiateResource(resource
);
1524 wxWindow
*newWin
= NULL
;
1525 wxWindow
*parent
= win
->GetParent();
1527 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1530 newWin
= FindWindowForResource(resource
);
1534 DisassociateResource(resource
);
1536 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
);
1537 AssociateResource(resource
, newWin
);
1538 UpdateResourceList();
1542 info
->SetPropertyWindow(newWin
);
1550 // Delete resource highlighted in the listbox
1551 bool wxResourceManager::DeleteSelection()
1553 int sel
= m_editorResourceTree
->GetSelection();
1556 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
1557 wxWindow
*win
= FindWindowForResource(res
);
1560 DeleteResource(win
);
1562 UpdateResourceList();
1571 // Delete resource highlighted in the listbox
1572 bool wxResourceManager::RecreateSelection()
1574 wxNode
*node
= GetSelections().First();
1577 wxControl
*item
= (wxControl
*)node
->Data();
1578 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1579 wxNode
*next
= node
->Next();
1580 childHandler
->SelectItem(FALSE
);
1582 RemoveSelection(item
);
1584 RecreateWindowFromResource(item
);
1591 bool wxResourceManager::EditDialog(wxDialog
*dialog
, wxWindow
*parent
)
1596 // Ensures that all currently shown windows are saved to resources,
1597 // e.g. just before writing to a .wxr file.
1598 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1600 m_resourceTable
.BeginFind();
1602 while (node
= m_resourceTable
.Next())
1604 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1605 wxString
resType(res
->GetType());
1607 if (resType
== "wxDialog")
1609 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1611 InstantiateResourceFromWindow(res
, win
, TRUE
);
1613 else if (resType
== "wxPanel")
1615 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1617 InstantiateResourceFromWindow(res
, win
, TRUE
);
1623 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1625 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1626 info
->SetResource(resource
);
1627 info
->InstantiateResource(resource
);
1632 wxNode
*node
= resource
->GetChildren().First();
1635 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1636 wxWindow
*childWindow
= FindWindowForResource(child
);
1641 sprintf(buf
, "Could not find window %s", child
->GetName());
1642 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1645 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1646 node
= node
->Next();
1653 // Create a window information object for the give window
1654 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1656 wxWindowPropertyInfo
*info
= NULL
;
1657 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1659 info
= new wxScrollBarPropertyInfo(win
);
1661 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1663 info
= new wxGroupBoxPropertyInfo(win
);
1665 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1667 info
= new wxCheckBoxPropertyInfo(win
);
1669 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1671 info
= new wxSliderPropertyInfo(win
);
1673 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1675 info
= new wxGaugePropertyInfo(win
);
1677 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1679 info
= new wxListBoxPropertyInfo(win
);
1681 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1683 info
= new wxRadioBoxPropertyInfo(win
);
1685 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1687 info
= new wxRadioButtonPropertyInfo(win
);
1689 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1691 info
= new wxChoicePropertyInfo(win
);
1693 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1695 info
= new wxButtonPropertyInfo(win
);
1697 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1699 info
= new wxBitmapButtonPropertyInfo(win
);
1701 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1703 info
= new wxStaticTextPropertyInfo(win
);
1705 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1707 info
= new wxStaticBitmapPropertyInfo(win
);
1709 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1711 info
= new wxTextPropertyInfo(win
);
1713 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1715 info
= new wxPanelPropertyInfo(win
);
1719 info
= new wxWindowPropertyInfo(win
);
1724 // Edit the given window
1725 void wxResourceManager::EditWindow(wxWindow
*win
)
1727 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
1730 info
->SetResource(FindResourceForWindow(win
));
1731 wxString
str("Editing ");
1732 str
+= win
->GetClassInfo()->GetClassName();
1734 if (win
->GetName() != "")
1735 str
+= win
->GetName();
1737 str
+= "properties";
1738 info
->Edit(NULL
, str
);
1744 * Resource editor frame
1747 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
1749 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
1750 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
1751 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
1752 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
1753 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
1754 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
1755 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
1756 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
1757 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
1758 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
1759 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
1760 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
1761 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
1764 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
1765 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
1766 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
1771 wxResourceEditorFrame::~wxResourceEditorFrame()
1775 void wxResourceEditorFrame::OnNew(wxCommandEvent
& event
)
1777 manager
->New(FALSE
);
1780 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& event
)
1782 manager
->CreateNewPanel();
1785 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& event
)
1790 void wxResourceEditorFrame::OnClear(wxCommandEvent
& event
)
1792 manager
->Clear(TRUE
, FALSE
);
1795 void wxResourceEditorFrame::OnSave(wxCommandEvent
& event
)
1800 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& event
)
1805 void wxResourceEditorFrame::OnExit(wxCommandEvent
& event
)
1807 manager
->Clear(TRUE
, FALSE
) ;
1811 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& event
)
1814 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
1815 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
1818 void wxResourceEditorFrame::OnTest(wxCommandEvent
& event
)
1820 manager
->TestCurrentDialog(this);
1823 void wxResourceEditorFrame::OnContents(wxCommandEvent
& event
)
1825 wxBeginBusyCursor();
1826 manager
->GetHelpController()->LoadFile();
1827 manager
->GetHelpController()->DisplayContents();
1831 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& event
)
1833 manager
->DeleteSelection();
1836 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& event
)
1838 manager
->RecreateSelection();
1841 bool wxResourceEditorFrame::OnClose()
1843 if (manager
->Modified())
1845 if (!manager
->Clear(TRUE
, FALSE
))
1853 manager
->m_resourceEditorWindowSize
.width
= w
;
1854 manager
->m_resourceEditorWindowSize
.height
= h
;
1857 GetPosition(&x
, &y
);
1859 manager
->m_resourceEditorWindowSize
.x
= x
;
1860 manager
->m_resourceEditorWindowSize
.y
= y
;
1862 manager
->SetEditorFrame(NULL
);
1863 manager
->SetEditorToolBar(NULL
);
1869 * Resource editor window that contains the dialog/panel being edited
1872 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
1873 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
1874 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
1877 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
1879 wxScrolledWindow(parent
, -1, pos
, size
, style
)
1883 m_childWindow
= NULL
;
1886 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
1890 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
1892 wxScrolledWindow::OnScroll(event
);
1895 ViewStart(& x
, & y
);
1898 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
1901 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& event
)
1908 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
1912 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
1915 wxString
str(res
->GetTitle());
1917 ViewStart(& x
, & y
);
1919 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
1921 dc
.SetBackgroundMode(wxTRANSPARENT
);
1922 dc
.SetTextForeground(wxColour(0, 0, 0));
1925 dc
.GetTextExtent(str
, & w
, & h
);
1927 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
1932 // Popup menu callback
1933 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
1935 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
1939 switch (event
.GetInt())
1941 case OBJECT_MENU_EDIT
:
1943 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
1946 case OBJECT_MENU_DELETE
:
1948 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
1949 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
1950 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
1963 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
1964 EVT_PAINT(EditorToolBar::OnPaint
)
1967 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
1968 long style
, int direction
, int RowsOrColumns
):
1969 wxToolBar(frame
, -1, pos
, size
, style
, direction
, RowsOrColumns
)
1973 bool EditorToolBar::OnLeftClick(int toolIndex
, bool toggled
)
1975 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
1979 case TOOLBAR_LOAD_FILE
:
1986 manager
->CreateNewPanel();
1989 case TOOLBAR_SAVE_FILE
:
1996 wxBeginBusyCursor();
1997 manager
->GetHelpController()->LoadFile();
1998 manager
->GetHelpController()->DisplayContents();
2002 case TOOLBAR_FORMAT_HORIZ
:
2004 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2007 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2009 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2012 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2014 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2017 case TOOLBAR_FORMAT_VERT
:
2019 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2022 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2024 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2027 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2029 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2032 case TOOLBAR_COPY_SIZE
:
2034 manager
->CopySize();
2037 case TOOLBAR_TO_BACK
:
2039 manager
->ToBackOrFront(TRUE
);
2042 case TOOLBAR_TO_FRONT
:
2044 manager
->ToBackOrFront(FALSE
);
2053 void EditorToolBar::OnMouseEnter(int toolIndex
)
2055 wxFrame
*frame
= (wxFrame
*)GetParent();
2063 case TOOLBAR_LOAD_FILE
:
2064 frame
->SetStatusText("Load project file");
2066 case TOOLBAR_SAVE_FILE
:
2067 frame
->SetStatusText("Save project file");
2070 frame
->SetStatusText("Create a new resource");
2072 case TOOLBAR_FORMAT_HORIZ
:
2073 frame
->SetStatusText("Align items horizontally");
2075 case TOOLBAR_FORMAT_VERT
:
2076 frame
->SetStatusText("Align items vertically");
2078 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2079 frame
->SetStatusText("Left-align items");
2081 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2082 frame
->SetStatusText("Right-align items");
2084 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2085 frame
->SetStatusText("Top-align items");
2087 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2088 frame
->SetStatusText("Bottom-align items");
2090 case TOOLBAR_COPY_SIZE
:
2091 frame
->SetStatusText("Copy size from first selection");
2093 case TOOLBAR_TO_FRONT
:
2094 frame
->SetStatusText("Put image to front");
2096 case TOOLBAR_TO_BACK
:
2097 frame
->SetStatusText("Put image to back");
2100 frame
->SetStatusText("Display help contents");
2106 else frame
->SetStatusText("");
2109 void EditorToolBar::OnPaint(wxPaintEvent
& event
)
2111 wxToolBar::OnPaint(event
);
2116 dc
.SetPen(wxBLACK_PEN
);
2117 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
2118 dc
.DrawLine(0, h
-1, w
, h
-1);