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(__WINDOWS__) && !defined(__GNUWIN32__)
47 #include <strstream.h>
63 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
64 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
67 #include "bitmaps/load.xbm"
68 #include "bitmaps/save.xbm"
69 #include "bitmaps/new.xbm"
70 #include "bitmaps/vert.xbm"
71 #include "bitmaps/alignt.xbm"
72 #include "bitmaps/alignb.xbm"
73 #include "bitmaps/horiz.xbm"
74 #include "bitmaps/alignl.xbm"
75 #include "bitmaps/alignr.xbm"
76 #include "bitmaps/copysize.xbm"
77 #include "bitmaps/tofront.xbm"
78 #include "bitmaps/toback.xbm"
79 #include "bitmaps/help.xbm"
80 #include "bitmaps/wxwin.xbm"
87 wxResourceManager::wxResourceManager():
88 m_imageList(16, 16, TRUE
)
90 sm_currentResourceManager
= this;
94 m_editorResourceTree
= NULL
;
95 m_editorControlList
= NULL
;
96 m_editorPalette
= NULL
;
99 m_currentFilename
= "";
100 m_editorToolBar
= NULL
;
102 // Default window positions
103 m_resourceEditorWindowSize
.width
= 470;
104 m_resourceEditorWindowSize
.height
= 300;
106 m_resourceEditorWindowSize
.x
= 0;
107 m_resourceEditorWindowSize
.y
= 0;
109 m_propertyWindowSize
.width
= 300;
110 m_propertyWindowSize
.height
= 300;
112 m_helpController
= NULL
;
114 m_bitmapImage
= NULL
;
115 m_rootDialogItem
= 0;
118 wxResourceManager::~wxResourceManager()
120 sm_currentResourceManager
= NULL
;
123 if (m_helpController
)
125 m_helpController
->Quit();
126 delete m_helpController
;
127 m_helpController
= NULL
;
129 delete m_bitmapImage
;
133 bool wxResourceManager::Initialize()
135 // Set up the resource filename for each platform.
137 // dialoged.ini in the Windows directory
139 GetWindowsDirectory(buf
, 256);
140 strcat(buf
, "\\dialoged.ini");
141 m_optionsResourceFilename
= buf
;
145 strcat(buf
, "/.dialogedrc");
146 m_optionsResourceFilename
= buf
;
148 #error "Unsupported platform."
153 m_helpController
= new wxHelpController
;
154 m_helpController
->Initialize("dialoged");
156 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
157 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
158 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
163 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
166 m_bitmapImage
= new wxBitmap(wxwin_bits
, wxwin_width
, wxwin_height
);
170 // Initialize the image list icons
172 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
173 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
174 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
175 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
176 m_imageList
.Add(icon1
);
177 m_imageList
.Add(icon2
);
178 m_imageList
.Add(icon3
);
179 m_imageList
.Add(icon4
);
185 bool wxResourceManager::LoadOptions()
187 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize
.x
, m_optionsResourceFilename
.GetData());
188 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize
.y
, m_optionsResourceFilename
.GetData());
189 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize
.width
, m_optionsResourceFilename
.GetData());
190 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize
.height
, m_optionsResourceFilename
.GetData());
191 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize
.x
, m_optionsResourceFilename
.GetData());
192 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize
.y
, m_optionsResourceFilename
.GetData());
193 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize
.width
, m_optionsResourceFilename
.GetData());
194 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize
.height
, m_optionsResourceFilename
.GetData());
198 bool wxResourceManager::SaveOptions()
200 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize
.x
, m_optionsResourceFilename
.GetData());
201 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize
.y
, m_optionsResourceFilename
.GetData());
202 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize
.width
, m_optionsResourceFilename
.GetData());
203 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize
.height
, m_optionsResourceFilename
.GetData());
205 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize
.x
, m_optionsResourceFilename
.GetData());
206 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize
.y
, m_optionsResourceFilename
.GetData());
207 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize
.width
, m_optionsResourceFilename
.GetData());
208 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize
.height
, m_optionsResourceFilename
.GetData());
213 // Show or hide the resource editor frame, which displays a list
214 // of resources with ability to edit them.
215 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*parent
, const char *title
)
221 m_editorFrame
->Iconize(FALSE
);
222 m_editorFrame
->Show(TRUE
);
225 m_editorFrame
= OnCreateEditorFrame(title
);
227 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
228 m_editorFrame
->SetMenuBar(menuBar
);
230 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
231 // m_editorPalette = OnCreatePalette(m_editorFrame);
232 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
233 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
235 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
237 m_editorResourceTree
->SetImageList(& m_imageList
);
239 // Constraints for toolbar
240 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
241 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
242 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
243 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
244 c
->bottom
.Unconstrained();
245 c
->width
.Unconstrained();
246 c
->height
.Absolute(28);
247 m_editorToolBar
->SetConstraints(c
);
249 // Constraints for palette
250 c = new wxLayoutConstraints;
251 c->left.SameAs (m_editorFrame, wxLeft, 0);
252 c->top.SameAs (m_editorToolBar, wxBottom, 0);
253 c->right.SameAs (m_editorFrame, wxRight, 0);
254 c->bottom.Unconstrained();
255 c->width.Unconstrained();
256 c->height.Absolute(34);
257 m_editorPalette->SetConstraints(c);
259 // Constraints for listbox
260 c
= new wxLayoutConstraints
;
261 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
262 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
263 c
->right
.Absolute (150);
264 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
265 c
->width
.Unconstrained();
266 c
->height
.Unconstrained();
267 m_editorResourceTree
->SetConstraints(c
);
269 // Constraints for panel
270 c
= new wxLayoutConstraints
;
271 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
272 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
273 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
274 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
275 c
->width
.Unconstrained();
276 c
->height
.Unconstrained();
277 m_editorPanel
->SetConstraints(c
);
279 // Constraints for control list (bottom window)
280 c
= new wxLayoutConstraints
;
281 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
282 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
283 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
284 c
->width
.Unconstrained();
285 c
->height
.Absolute(60);
286 m_editorControlList
->SetConstraints(c
);
288 m_editorFrame
->SetAutoLayout(TRUE
);
290 UpdateResourceList();
292 m_editorFrame
->Show(TRUE
);
297 wxFrame
*fr
= m_editorFrame
;
298 if (m_editorFrame
->OnClose())
302 m_editorFrame
= NULL
;
303 m_editorPanel
= NULL
;
309 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
313 if (filename
== wxString(""))
314 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
317 wxString
str("wxWindows Dialog Editor - ");
318 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
320 m_editorFrame
->SetTitle(str
);
325 bool wxResourceManager::Save()
327 if (m_currentFilename
== wxString(""))
330 return Save(m_currentFilename
);
333 bool wxResourceManager::Save(const wxString
& filename
)
335 // Ensure all visible windows are saved to their resources
336 m_currentFilename
= filename
;
337 SetFrameTitle(m_currentFilename
);
338 InstantiateAllResourcesFromWindows();
339 if (m_resourceTable
.Save(filename
))
348 bool wxResourceManager::SaveAs()
350 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
351 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
));
353 if (s
.IsNull() || s
== "")
356 m_currentFilename
= s
;
357 Save(m_currentFilename
);
361 bool wxResourceManager::SaveIfModified()
368 bool wxResourceManager::Load(const wxString
& filename
)
370 return New(TRUE
, filename
);
373 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
375 if (!Clear(TRUE
, FALSE
))
380 wxString str
= filename
;
381 if (str
== wxString(""))
383 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, NULL
));
384 if (!f
.IsNull() && f
!= "")
390 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
392 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
395 m_currentFilename
= str
;
397 SetFrameTitle(m_currentFilename
);
399 UpdateResourceList();
404 m_currentFilename
= "";
411 bool wxResourceManager::Clear(bool deleteWindows
, bool force
)
413 if (!force
&& Modified())
415 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
419 if (!SaveIfModified())
425 ClearCurrentDialog();
426 DisassociateWindows();
428 m_resourceTable
.ClearTable();
429 UpdateResourceList();
434 bool wxResourceManager::DisassociateWindows()
436 m_resourceTable
.BeginFind();
438 while (node
= m_resourceTable
.Next())
440 wxItemResource
*res
= (wxItemResource
*)node
->Data();
441 DisassociateResource(res
);
447 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
449 if (!m_resourceAssociations
.Get((long)resource
))
450 m_resourceAssociations
.Put((long)resource
, win
);
452 wxNode
*node
= resource
->GetChildren().First();
455 wxItemResource
*child
= (wxItemResource
*)node
->Data();
456 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
458 childWindow
= win
->FindWindow(child
->GetName());
460 AssociateResource(child
, childWindow
);
464 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? child
->GetName() : "(unnamed)");
465 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
472 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
474 wxWindow
*win
= FindWindowForResource(resource
);
478 // Disassociate children of window
479 if (win
->GetChildren())
481 wxNode
*node
= win
->GetChildren()->First();
484 wxWindow
*child
= (wxWindow
*)node
->Data();
485 if (child
->IsKindOf(CLASSINFO(wxControl
)))
486 DisassociateResource(child
);
491 RemoveSelection(win
);
492 m_resourceAssociations
.Delete((long)resource
);
496 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
498 wxItemResource
*res
= FindResourceForWindow(win
);
500 return DisassociateResource(res
);
505 // Saves the window info into the resource, and deletes the
506 // handler. Doesn't actually disassociate the window from
507 // the resources. Replaces OnClose.
508 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
510 wxItemResource
*res
= FindResourceForWindow(win
);
512 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
514 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
515 win
->PopEventHandler();
517 // Now reset all child event handlers
518 wxNode
*node
= win
->GetChildren()->First();
521 wxWindow
*child
= (wxWindow
*)node
->Data();
522 wxEvtHandler
*childHandler
= child
->GetEventHandler();
523 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
525 child
->PopEventHandler(TRUE
);
533 win
->PopEventHandler(TRUE
);
536 // Save the information
537 InstantiateResourceFromWindow(res
, win
, TRUE
);
539 // DisassociateResource(win);
544 // Destroys the window. If this is the 'current' panel, NULLs the
546 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
548 if (m_editorPanel
->m_childWindow
== win
)
549 m_editorPanel
->m_childWindow
= NULL
;
555 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
557 m_resourceAssociations
.BeginFind();
559 while (node
= m_resourceAssociations
.Next())
561 wxWindow
*w
= (wxWindow
*)node
->Data();
564 return (wxItemResource
*)node
->key
.integer
;
570 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
572 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
576 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
580 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
583 if (!m_resourceTable
.FindResource(buf
))
588 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
590 int frameWidth
= 420;
591 int frameHeight
= 300;
593 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
594 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
595 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
596 wxDEFAULT_FRAME_STYLE
);
598 frame
->CreateStatusBar(1);
600 frame
->SetAutoLayout(TRUE
);
602 wxIcon
*icon
= new wxIcon("DIALOGEDICON");
603 frame
->SetIcon(icon
);
608 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*parent
)
610 wxMenuBar
*menuBar
= new wxMenuBar
;
612 wxMenu
*fileMenu
= new wxMenu
;
613 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
614 fileMenu
->AppendSeparator();
615 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
616 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
617 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
618 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
619 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
620 fileMenu
->AppendSeparator();
621 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
623 wxMenu
*editMenu
= new wxMenu
;
624 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
625 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
626 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
628 wxMenu
*helpMenu
= new wxMenu
;
629 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
630 helpMenu
->AppendSeparator();
631 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
633 menuBar
->Append(fileMenu
, "&File");
634 menuBar
->Append(editMenu
, "&Edit");
635 menuBar
->Append(helpMenu
, "&Help");
640 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
642 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
643 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
646 panel
->SetScrollbars(10, 10, 100, 100);
651 wxToolBarBase
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
653 // Load palette bitmaps
655 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
656 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
657 wxBitmap
ToolbarNewBitmap("NEWTOOL");
658 wxBitmap
ToolbarVertBitmap("VERTTOOL");
659 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
660 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
661 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
662 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
663 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
664 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
665 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
666 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
667 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
670 wxBitmap
ToolbarLoadBitmap(load_bits
, load_width
, load_height
);
671 wxBitmap
ToolbarSaveBitmap(save_bits
, save_width
, save_height
);
672 wxBitmap
ToolbarNewBitmap(new_bits
, save_width
, save_height
);
673 wxBitmap
ToolbarVertBitmap(vert_bits
, vert_width
, vert_height
);
674 wxBitmap
ToolbarAlignTBitmap(alignt_bits
, alignt_width
, alignt_height
);
675 wxBitmap
ToolbarAlignBBitmap(alignb_bits
, alignb_width
, alignb_height
);
676 wxBitmap
ToolbarHorizBitmap(horiz_bits
, horiz_width
, horiz_height
);
677 wxBitmap
ToolbarAlignLBitmap(alignl_bits
, alignl_width
, alignl_height
);
678 wxBitmap
ToolbarAlignRBitmap(alignr_bits
, alignr_width
, alignr_height
);
679 wxBitmap
ToolbarCopySizeBitmap(copysize_bits
, copysize_width
, copysize_height
);
680 wxBitmap
ToolbarToBackBitmap(toback_bits
, toback_width
, toback_height
);
681 wxBitmap
ToolbarToFrontBitmap(tofront_bits
, tofront_width
, tofront_height
);
682 wxBitmap
ToolbarHelpBitmap(help_bits
, help_width
, help_height
);
685 // Create the toolbar
686 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
,
688 toolbar
->SetMargins(2, 2);
689 // toolbar->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH);
696 int width
= ToolbarLoadBitmap
->GetWidth();
701 toolbar
->AddSeparator();
702 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, (wxBitmap
*)NULL
,
703 FALSE
, (float)currentX
, -1, NULL
, "New dialog");
704 currentX
+= width
+ dx
;
705 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, (wxBitmap
*)NULL
,
706 FALSE
, (float)currentX
, -1, NULL
, "Load");
707 currentX
+= width
+ dx
;
708 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, (wxBitmap
*)NULL
,
709 FALSE
, (float)currentX
, -1, NULL
, "Save");
710 currentX
+= width
+ dx
+ gap
;
711 toolbar
->AddSeparator();
712 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, (wxBitmap
*)NULL
,
713 FALSE
, (float)currentX
, -1, NULL
, "Horizontal align");
714 currentX
+= width
+ dx
;
715 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, (wxBitmap
*)NULL
,
716 FALSE
, (float)currentX
, -1, NULL
, "Top align");
717 currentX
+= width
+ dx
;
718 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, (wxBitmap
*)NULL
,
719 FALSE
, (float)currentX
, -1, NULL
, "Bottom align");
720 currentX
+= width
+ dx
;
721 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, (wxBitmap
*)NULL
,
722 FALSE
, (float)currentX
, -1, NULL
, "Vertical align");
723 currentX
+= width
+ dx
;
724 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, (wxBitmap
*)NULL
,
725 FALSE
, (float)currentX
, -1, NULL
, "Left align");
726 currentX
+= width
+ dx
;
727 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, (wxBitmap
*)NULL
,
728 FALSE
, (float)currentX
, -1, NULL
, "Right align");
729 currentX
+= width
+ dx
;
730 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, (wxBitmap
*)NULL
,
731 FALSE
, (float)currentX
, -1, NULL
, "Copy size");
732 currentX
+= width
+ dx
+ gap
;
733 toolbar
->AddSeparator();
734 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, (wxBitmap
*)NULL
,
735 FALSE
, (float)currentX
, -1, NULL
, "To front");
736 currentX
+= width
+ dx
;
737 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, (wxBitmap
*)NULL
,
738 FALSE
, (float)currentX
, -1, NULL
, "To back");
739 currentX
+= width
+ dx
+ gap
;
741 toolbar
->AddSeparator();
742 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, (wxBitmap
*)NULL
,
743 FALSE
, (float)currentX
, -1, NULL
, "Help");
744 currentX
+= width
+ dx
;
746 toolbar
->CreateTools();
750 // parent->OnSize(-1, -1);
753 void wxResourceManager::UpdateResourceList()
755 if (!m_editorResourceTree
)
758 m_editorResourceTree
->SetInvalid(TRUE
);
759 m_editorResourceTree
->DeleteAllItems();
761 long id
= m_editorResourceTree
->InsertItem(0, "Dialogs"
767 m_resourceTable
.BeginFind();
769 while (node
= m_resourceTable
.Next())
771 wxItemResource
*res
= (wxItemResource
*)node
->Data();
772 wxString
resType(res
->GetType());
773 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
775 AddItemsRecursively(id
, res
);
778 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
779 m_editorResourceTree
->SetInvalid(FALSE
);
782 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
784 wxString
theString("");
785 theString
= resource
->GetName();
788 wxString
resType(resource
->GetType());
789 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
794 long id
= m_editorResourceTree
->InsertItem(parent
, theString
800 m_editorResourceTree
->SetItemData(id
, (long) resource
);
802 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
804 wxNode
*node
= resource
->GetChildren().First();
807 wxItemResource
*res
= (wxItemResource
*)node
->Data();
808 AddItemsRecursively(id
, res
);
812 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
815 bool wxResourceManager::EditSelectedResource()
817 int sel
= m_editorResourceTree
->GetSelection();
820 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
826 bool wxResourceManager::Edit(wxItemResource
*res
)
828 ClearCurrentDialog();
830 wxString
resType(res
->GetType());
831 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
835 wxMessageBox("Should not find panel in wxResourceManager::Edit");
840 long style
= res
->GetStyle();
841 res
->SetStyle(style
|wxRAISED_BORDER
);
843 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
846 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
848 panel
->PushEventHandler(handler
);
850 res
->SetStyle(style
);
851 handler
->AddChildHandlers(); // Add event handlers for all controls
852 AssociateResource(res
, panel
);
854 m_editorPanel
->m_childWindow
= panel
;
855 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
859 wxClientDC
dc(m_editorPanel
);
860 m_editorPanel
->DrawTitle(dc
);
865 bool wxResourceManager::CreateNewPanel()
867 ClearCurrentDialog();
870 MakeUniqueName("panel", buf
);
872 wxItemResource
*resource
= new wxItemResource
;
873 // resource->SetType(wxTYPE_PANEL);
874 resource
->SetType("wxPanel");
875 resource
->SetName(buf
);
876 resource
->SetTitle(buf
);
877 m_resourceTable
.AddResource(resource
);
879 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
880 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
881 wxSize(400, 300), wxRAISED_BORDER
, buf
);
882 m_editorPanel
->m_childWindow
= panel
;
884 resource
->SetStyle(0); // panel->GetWindowStyleFlag());
885 resource
->SetSize(10, 10, 400, 300);
887 // For editing in situ we will need to use the hash table to ensure
888 // we don't dereference invalid pointers.
889 // resourceWindowTable.Put((long)resource, panel);
891 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
893 panel
->PushEventHandler(handler
);
895 AssociateResource(resource
, panel
);
896 UpdateResourceList();
899 m_editorPanel
->m_childWindow
->Refresh();
903 wxClientDC
dc(m_editorPanel
);
904 m_editorPanel
->DrawTitle(dc
);
909 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
912 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
917 wxItemResource
*res
= new wxItemResource
;
918 wxControl
*newItem
= NULL
;
919 res
->SetSize(x
, y
, -1, -1);
922 wxString
itemType(iType
);
924 if (itemType
== "wxButton")
926 MakeUniqueName("button", buf
);
929 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
931 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
933 if (itemType
== "wxBitmapButton")
935 MakeUniqueName("button", buf
);
937 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
939 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
941 MakeUniqueName("message", buf
);
944 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
946 newItem
= new wxStaticText(panel
, -1, "Message", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
948 else if (itemType
== "wxStaticBitmap")
950 MakeUniqueName("message", buf
);
952 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
954 else if (itemType
== "wxCheckBox")
956 MakeUniqueName("checkbox", buf
);
958 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
960 else if (itemType
== "wxListBox")
962 MakeUniqueName("listbox", buf
);
964 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
966 else if (itemType
== "wxRadioBox")
968 MakeUniqueName("radiobox", buf
);
970 wxString names
[] = { "One", "Two" };
971 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
972 wxHORIZONTAL
, wxDefaultValidator
, buf
);
973 res
->SetStringValues(new wxStringList("One", "Two", NULL
));
975 else if (itemType
== "wxChoice")
977 MakeUniqueName("choice", buf
);
979 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
981 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
983 MakeUniqueName("group", buf
);
985 newItem
= new wxStaticBox(panel
, -1, "Groupbox", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
987 else if (itemType
== "wxGauge")
989 MakeUniqueName("gauge", buf
);
991 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
993 else if (itemType
== "wxSlider")
995 MakeUniqueName("slider", buf
);
997 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
999 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1001 MakeUniqueName("textctrl", buf
);
1003 res
->SetType("wxTextCtrl");
1004 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1006 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1008 MakeUniqueName("textctrl", buf
);
1010 res
->SetType("wxTextCtrl");
1011 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1013 else if (itemType
== "wxScrollBar")
1015 MakeUniqueName("scrollbar", buf
);
1017 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1022 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1024 res
->SetStyle(newItem
->GetWindowStyleFlag());
1025 AssociateResource(res
, newItem
);
1026 panelResource
->GetChildren().Append(res
);
1028 UpdateResourceList();
1033 void wxResourceManager::ClearCurrentDialog()
1035 if (m_editorPanel
->m_childWindow
)
1037 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1038 DisassociateResource(m_editorPanel
->m_childWindow
);
1039 DeleteWindow(m_editorPanel
->m_childWindow
);
1040 m_editorPanel
->m_childWindow
= NULL
;
1041 m_editorPanel
->Clear();
1045 // Find the first dialog or panel for which
1046 // there is a selected panel item.
1047 wxWindow
*wxResourceManager::FindParentOfSelection()
1049 m_resourceTable
.BeginFind();
1051 while (node
= m_resourceTable
.Next())
1053 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1054 wxWindow
*win
= FindWindowForResource(res
);
1057 wxNode
*node1
= win
->GetChildren()->First();
1060 wxControl
*item
= (wxControl
*)node1
->Data();
1061 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1062 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1064 node1
= node1
->Next();
1071 // Format the panel items according to 'flag'
1072 void wxResourceManager::AlignItems(int flag
)
1074 wxWindow
*win
= FindParentOfSelection();
1078 wxNode
*node
= GetSelections().First();
1082 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1083 if (firstSelection
->GetParent() != win
)
1088 firstSelection
->GetPosition(&firstX
, &firstY
);
1089 firstSelection
->GetSize(&firstW
, &firstH
);
1090 int centreX
= (int)(firstX
+ (firstW
/ 2));
1091 int centreY
= (int)(firstY
+ (firstH
/ 2));
1093 while (node
= node
->Next())
1095 wxControl
*item
= (wxControl
*)node
->Data();
1096 if (item
->GetParent() == win
)
1099 item
->GetPosition(&x
, &y
);
1100 item
->GetSize(&w
, &h
);
1106 case TOOLBAR_FORMAT_HORIZ
:
1109 newY
= (int)(centreY
- (h
/2.0));
1112 case TOOLBAR_FORMAT_VERT
:
1114 newX
= (int)(centreX
- (w
/2.0));
1118 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1124 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1130 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1132 newX
= firstX
+ firstW
- w
;
1136 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1139 newY
= firstY
+ firstH
- h
;
1147 item
->SetSize(newX
, newY
, w
, h
);
1153 // Copy the first image's size to subsequent images
1154 void wxResourceManager::CopySize()
1156 wxWindow
*win
= FindParentOfSelection();
1160 wxNode
*node
= GetSelections().First();
1164 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1165 if (firstSelection
->GetParent() != win
)
1170 firstSelection
->GetPosition(&firstX
, &firstY
);
1171 firstSelection
->GetSize(&firstW
, &firstH
);
1172 int centreX
= (int)(firstX
+ (firstW
/ 2));
1173 int centreY
= (int)(firstY
+ (firstH
/ 2));
1175 while (node
= node
->Next())
1177 wxControl
*item
= (wxControl
*)node
->Data();
1178 if (item
->GetParent() == win
)
1179 item
->SetSize(-1, -1, firstW
, firstH
);
1184 void wxResourceManager::ToBackOrFront(bool toBack
)
1186 wxWindow
*win
= FindParentOfSelection();
1189 wxItemResource
*winResource
= FindResourceForWindow(win
);
1191 wxNode
*node
= GetSelections().First();
1194 wxControl
*item
= (wxControl
*)node
->Data();
1195 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1196 if (item
->GetParent() == win
)
1198 win
->GetChildren()->DeleteObject(item
);
1200 winResource
->GetChildren().DeleteObject(itemResource
);
1203 win
->GetChildren()->Insert(item
);
1205 winResource
->GetChildren().Insert(itemResource
);
1209 win
->GetChildren()->Append(item
);
1211 winResource
->GetChildren().Append(itemResource
);
1214 node
= node
->Next();
1219 void wxResourceManager::AddSelection(wxWindow
*win
)
1221 if (!m_selections
.Member(win
))
1222 m_selections
.Append(win
);
1225 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1227 m_selections
.DeleteObject(win
);
1230 // Need to search through resource table removing this from
1231 // any resource which has this as a parent.
1232 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1234 m_resourceTable
.BeginFind();
1236 while (node
= m_resourceTable
.Next())
1238 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1239 if (thisRes
->GetChildren().Member(res
))
1241 thisRes
->GetChildren().DeleteObject(res
);
1248 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1253 RemoveResourceFromParent(res
);
1255 wxNode
*node
= res
->GetChildren().First();
1258 wxNode
*next
= node
->Next();
1259 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1260 DeleteResource(child
);
1264 // If this is a button or message resource, delete the
1265 // associate bitmap resource if not being used.
1266 wxString
resType(res
->GetType());
1268 if ((resType
== "wxMessage" || resType
== "wxStaticBitmap" || resType
== "wxButton" || resType
== "wxBitmapButton") && res
->GetValue4())
1270 PossiblyDeleteBitmapResource(res
->GetValue4());
1273 m_resourceTable
.Delete(res
->GetName());
1279 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1281 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1283 // Deselect and refresh window in case we leave selection
1285 wxControl
*item
= (wxControl
*)win
;
1286 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1287 if (childHandler
->IsSelected())
1289 RemoveSelection(item
);
1290 childHandler
->SelectItem(FALSE
);
1291 item
->GetParent()->Refresh();
1295 wxItemResource
*res
= FindResourceForWindow(win
);
1297 DisassociateResource(res
);
1298 DeleteResource(res
);
1299 UpdateResourceList();
1304 // Will eventually have bitmap type information, for different
1306 char *wxResourceManager::AddBitmapResource(char *filename
)
1308 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1312 MakeUniqueName("bitmap", buf
);
1313 resource
= new wxItemResource
;
1314 resource
->SetType("wxBitmap");
1315 resource
->SetName(buf
);
1317 // A bitmap resource has one or more children, specifying
1318 // alternative bitmaps.
1319 wxItemResource
*child
= new wxItemResource
;
1320 child
->SetType("wxBitmap");
1321 child
->SetName(filename
);
1322 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1323 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1324 child
->SetValue3(0); // Depth
1325 child
->SetSize(0,0,0,0);
1326 resource
->GetChildren().Append(child
);
1328 m_resourceTable
.AddResource(resource
);
1330 UpdateResourceList();
1333 return resource
->GetName();
1338 // Delete the bitmap resource if it isn't being used by another resource.
1339 void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName
)
1341 if (!IsBitmapResourceUsed(resourceName
))
1343 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1344 DeleteResource(res
);
1345 UpdateResourceList();
1349 bool wxResourceManager::IsBitmapResourceUsed(char *resourceName
)
1351 m_resourceTable
.BeginFind();
1353 while (node
= m_resourceTable
.Next())
1355 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1356 wxString
resType(res
->GetType());
1357 if (resType
== "wxDialog")
1359 wxNode
*node1
= res
->GetChildren().First();
1362 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1363 wxString
childResType(child
->GetType());
1365 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1366 child
->GetValue4() &&
1367 (strcmp(child
->GetValue4(), resourceName
) == 0))
1369 node1
= node1
->Next();
1376 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1377 char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1379 if (!resource
|| !resource
->GetValue4())
1381 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1382 if (!bitmapResource
)
1385 wxNode
*node
= bitmapResource
->GetChildren().First();
1388 // Eventually augment this to return a bitmap of the right kind or something...
1389 // Maybe the root of the filename remains the same, so it doesn't matter which we
1390 // pick up. Otherwise how do we specify multiple filenames... too boring...
1391 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1392 return child
->GetName();
1394 node
= node
->Next();
1399 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(char *filename
)
1401 m_resourceTable
.BeginFind();
1403 while (node
= m_resourceTable
.Next())
1405 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1406 wxString
resType(res
->GetType());
1407 if (resType
== "wxBitmap")
1409 wxNode
*node1
= res
->GetChildren().First();
1412 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1413 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1415 node1
= node1
->Next();
1422 // Deletes 'win' and creates a new window from the resource that
1423 // was associated with it. E.g. if you can't change properties on the
1424 // fly, you'll need to delete the window and create it again.
1425 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1427 wxItemResource
*resource
= FindResourceForWindow(win
);
1429 // Put the current window properties into the wxItemResource object
1431 wxWindowPropertyInfo
*newInfo
= NULL
;
1434 newInfo
= CreatePropertyInfoForWindow(win
);
1438 info
->InstantiateResource(resource
);
1440 wxWindow
*newWin
= NULL
;
1441 wxWindow
*parent
= win
->GetParent();
1443 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1446 newWin
= FindWindowForResource(resource
);
1450 DisassociateResource(resource
);
1452 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
);
1453 AssociateResource(resource
, newWin
);
1454 UpdateResourceList();
1458 info
->SetPropertyWindow(newWin
);
1466 // Delete resource highlighted in the listbox
1467 bool wxResourceManager::DeleteSelection()
1469 int sel
= m_editorResourceTree
->GetSelection();
1472 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
1473 wxWindow
*win
= FindWindowForResource(res
);
1476 DeleteResource(win
);
1478 UpdateResourceList();
1487 // Delete resource highlighted in the listbox
1488 bool wxResourceManager::RecreateSelection()
1490 wxNode
*node
= GetSelections().First();
1493 wxControl
*item
= (wxControl
*)node
->Data();
1494 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1495 wxNode
*next
= node
->Next();
1496 childHandler
->SelectItem(FALSE
);
1498 RemoveSelection(item
);
1500 RecreateWindowFromResource(item
);
1507 bool wxResourceManager::EditDialog(wxDialog
*dialog
, wxWindow
*parent
)
1512 // Ensures that all currently shown windows are saved to resources,
1513 // e.g. just before writing to a .wxr file.
1514 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1516 m_resourceTable
.BeginFind();
1518 while (node
= m_resourceTable
.Next())
1520 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1521 wxString
resType(res
->GetType());
1523 if (resType
== "wxDialog")
1525 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1527 InstantiateResourceFromWindow(res
, win
, TRUE
);
1529 else if (resType
== "wxPanel")
1531 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1533 InstantiateResourceFromWindow(res
, win
, TRUE
);
1539 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1541 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1542 info
->SetResource(resource
);
1543 info
->InstantiateResource(resource
);
1548 wxNode
*node
= resource
->GetChildren().First();
1551 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1552 wxWindow
*childWindow
= FindWindowForResource(child
);
1557 sprintf(buf
, "Could not find window %s", child
->GetName());
1558 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1561 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1562 node
= node
->Next();
1569 // Create a window information object for the give window
1570 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1572 wxWindowPropertyInfo
*info
= NULL
;
1573 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1575 info
= new wxScrollBarPropertyInfo(win
);
1577 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1579 info
= new wxGroupBoxPropertyInfo(win
);
1581 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1583 info
= new wxCheckBoxPropertyInfo(win
);
1585 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1587 info
= new wxSliderPropertyInfo(win
);
1589 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1591 info
= new wxGaugePropertyInfo(win
);
1593 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1595 info
= new wxListBoxPropertyInfo(win
);
1597 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1599 info
= new wxRadioBoxPropertyInfo(win
);
1601 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1603 info
= new wxChoicePropertyInfo(win
);
1605 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1607 info
= new wxButtonPropertyInfo(win
);
1609 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1611 info
= new wxBitmapButtonPropertyInfo(win
);
1613 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1615 info
= new wxStaticTextPropertyInfo(win
);
1617 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1619 info
= new wxStaticBitmapPropertyInfo(win
);
1621 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1623 info
= new wxTextPropertyInfo(win
);
1625 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1627 info
= new wxPanelPropertyInfo(win
);
1631 info
= new wxWindowPropertyInfo(win
);
1636 // Edit the given window
1637 void wxResourceManager::EditWindow(wxWindow
*win
)
1639 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
1642 info
->SetResource(FindResourceForWindow(win
));
1643 wxString
str("Editing ");
1644 str
+= win
->GetClassInfo()->GetClassName();
1646 if (win
->GetName() != "")
1647 str
+= win
->GetName();
1649 str
+= "properties";
1650 info
->Edit(NULL
, str
);
1656 * Resource editor frame
1659 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
1661 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
1662 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
1663 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
1664 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
1665 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
1666 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
1667 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
1668 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
1669 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
1670 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
1671 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
1672 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
1673 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
1676 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
1677 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
1678 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
1683 wxResourceEditorFrame::~wxResourceEditorFrame()
1687 void wxResourceEditorFrame::OnNew(wxCommandEvent
& event
)
1689 manager
->New(FALSE
);
1692 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& event
)
1694 manager
->CreateNewPanel();
1697 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& event
)
1702 void wxResourceEditorFrame::OnClear(wxCommandEvent
& event
)
1704 manager
->Clear(TRUE
, FALSE
);
1707 void wxResourceEditorFrame::OnSave(wxCommandEvent
& event
)
1712 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& event
)
1717 void wxResourceEditorFrame::OnExit(wxCommandEvent
& event
)
1719 manager
->Clear(TRUE
, FALSE
) ;
1723 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& event
)
1726 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
1727 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
1730 void wxResourceEditorFrame::OnTest(wxCommandEvent
& event
)
1732 // TODO should show the current dialog
1735 void wxResourceEditorFrame::OnContents(wxCommandEvent
& event
)
1737 wxBeginBusyCursor();
1738 manager
->GetHelpController()->LoadFile();
1739 manager
->GetHelpController()->DisplayContents();
1743 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& event
)
1745 manager
->DeleteSelection();
1748 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& event
)
1750 manager
->RecreateSelection();
1753 bool wxResourceEditorFrame::OnClose()
1755 if (manager
->Modified())
1757 if (!manager
->Clear(TRUE
, FALSE
))
1765 manager
->m_resourceEditorWindowSize
.width
= w
;
1766 manager
->m_resourceEditorWindowSize
.height
= h
;
1769 GetPosition(&x
, &y
);
1771 manager
->m_resourceEditorWindowSize
.x
= x
;
1772 manager
->m_resourceEditorWindowSize
.y
= y
;
1774 manager
->SetEditorFrame(NULL
);
1775 manager
->SetEditorToolBar(NULL
);
1776 manager
->SetEditorPalette(NULL
);
1782 * Resource editor window that contains the dialog/panel being edited
1785 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
1786 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
1787 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
1790 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
1792 wxScrolledWindow(parent
, -1, pos
, size
, style
)
1796 m_childWindow
= NULL
;
1799 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
1803 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
1805 wxScrolledWindow::OnScroll(event
);
1808 ViewStart(& x
, & y
);
1811 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
1814 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& event
)
1821 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
1825 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
1828 wxString
str(res
->GetTitle());
1830 ViewStart(& x
, & y
);
1832 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
1834 dc
.SetBackgroundMode(wxTRANSPARENT
);
1835 dc
.SetTextForeground(wxColour(0, 0, 0));
1838 dc
.GetTextExtent(str
, & w
, & h
);
1840 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
1845 // Popup menu callback
1846 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
1848 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
1852 switch (event
.GetInt())
1854 case OBJECT_MENU_EDIT
:
1856 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
1859 case OBJECT_MENU_DELETE
:
1861 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
1862 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
1863 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
1876 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
1877 EVT_PAINT(EditorToolBar::OnPaint
)
1880 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
1881 long style
, int direction
, int RowsOrColumns
):
1882 wxToolBar(frame
, -1, pos
, size
, style
, direction
, RowsOrColumns
)
1886 bool EditorToolBar::OnLeftClick(int toolIndex
, bool toggled
)
1888 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
1892 case TOOLBAR_LOAD_FILE
:
1899 manager
->CreateNewPanel();
1902 case TOOLBAR_SAVE_FILE
:
1909 wxBeginBusyCursor();
1910 manager
->GetHelpController()->LoadFile();
1911 manager
->GetHelpController()->DisplayContents();
1915 case TOOLBAR_FORMAT_HORIZ
:
1917 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
1920 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1922 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
1925 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1927 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
1930 case TOOLBAR_FORMAT_VERT
:
1932 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
1935 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1937 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
1940 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1942 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
1945 case TOOLBAR_COPY_SIZE
:
1947 manager
->CopySize();
1950 case TOOLBAR_TO_BACK
:
1952 manager
->ToBackOrFront(TRUE
);
1955 case TOOLBAR_TO_FRONT
:
1957 manager
->ToBackOrFront(FALSE
);
1966 void EditorToolBar::OnMouseEnter(int toolIndex
)
1968 wxFrame
*frame
= (wxFrame
*)GetParent();
1976 case TOOLBAR_LOAD_FILE
:
1977 frame
->SetStatusText("Load project file");
1979 case TOOLBAR_SAVE_FILE
:
1980 frame
->SetStatusText("Save project file");
1983 frame
->SetStatusText("Create a new resource");
1985 case TOOLBAR_FORMAT_HORIZ
:
1986 frame
->SetStatusText("Align items horizontally");
1988 case TOOLBAR_FORMAT_VERT
:
1989 frame
->SetStatusText("Align items vertically");
1991 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1992 frame
->SetStatusText("Left-align items");
1994 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1995 frame
->SetStatusText("Right-align items");
1997 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1998 frame
->SetStatusText("Top-align items");
2000 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2001 frame
->SetStatusText("Bottom-align items");
2003 case TOOLBAR_COPY_SIZE
:
2004 frame
->SetStatusText("Copy size from first selection");
2006 case TOOLBAR_TO_FRONT
:
2007 frame
->SetStatusText("Put image to front");
2009 case TOOLBAR_TO_BACK
:
2010 frame
->SetStatusText("Put image to back");
2013 frame
->SetStatusText("Display help contents");
2019 else frame
->SetStatusText("");
2022 void EditorToolBar::OnPaint(wxPaintEvent
& event
)
2024 wxToolBar::OnPaint(event
);
2029 dc
.SetPen(wxBLACK_PEN
);
2030 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
2031 dc
.DrawLine(0, h
-1, w
, h
-1);