1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource editor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "reseditr.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/checkbox.h"
27 #include "wx/button.h"
28 #include "wx/choice.h"
29 #include "wx/listbox.h"
30 #include "wx/radiobox.h"
31 #include "wx/statbox.h"
33 #include "wx/slider.h"
34 #include "wx/textctrl.h"
36 #include "wx/toolbar.h"
39 #include "wx/scrolbar.h"
40 #include "wx/config.h"
42 #include "wx/progdlg.h"
59 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
61 #if defined(__WXGTK__) || defined(__WXMOTIF__)
62 #include "bitmaps/load.xpm"
63 #include "bitmaps/save.xpm"
64 #include "bitmaps/new.xpm"
65 #include "bitmaps/vert.xpm"
66 #include "bitmaps/alignt.xpm"
67 #include "bitmaps/alignb.xpm"
68 #include "bitmaps/horiz.xpm"
69 #include "bitmaps/alignl.xpm"
70 #include "bitmaps/alignr.xpm"
71 #include "bitmaps/copysize.xpm"
72 #include "bitmaps/tofront.xpm"
73 #include "bitmaps/toback.xpm"
74 #include "bitmaps/help.xpm"
75 #include "bitmaps/wxwin.xpm"
76 #include "bitmaps/distvert.xpm"
77 #include "bitmaps/disthor.xpm"
78 #include "bitmaps/copywdth.xpm"
79 #include "bitmaps/copyhght.xpm"
81 #include "bitmaps/dialog.xpm"
82 #include "bitmaps/folder1.xpm"
83 #include "bitmaps/folder2.xpm"
84 #include "bitmaps/buttonsm.xpm"
91 wxResourceManager::wxResourceManager():
92 m_imageList(16, 16, TRUE
)
94 sm_currentResourceManager
= this;
98 m_editorResourceTree
= NULL
;
99 m_editorControlList
= NULL
;
101 m_symbolIdCounter
= 99;
103 m_currentFilename
= "";
104 m_symbolFilename
= "";
105 m_editorToolBar
= NULL
;
107 // Default window positions
108 m_resourceEditorWindowSize
.width
= 500;
109 m_resourceEditorWindowSize
.height
= 450;
111 m_resourceEditorWindowSize
.x
= 0;
112 m_resourceEditorWindowSize
.y
= 0;
114 m_propertyWindowSize
.width
= 300;
115 m_propertyWindowSize
.height
= 300;
118 m_helpController
= NULL
;
121 m_bitmapImage
= NULL
;
122 m_rootDialogItem
= 0;
125 wxResourceManager::~wxResourceManager()
127 sm_currentResourceManager
= NULL
;
131 if (m_helpController
)
133 m_helpController
->Quit();
134 delete m_helpController
;
135 m_helpController
= NULL
;
139 delete m_bitmapImage
;
143 bool wxResourceManager::Initialize()
145 // Set up the resource filename for each platform.
146 // TODO: This shold be replaced by wxConfig usage.
148 // dialoged.ini in the Windows directory
149 wxString windowsDir
= wxGetOSDirectory();
150 windowsDir
+= "\\dialoged.ini" ;
152 m_optionsResourceFilename
= windowsDir
;
153 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
154 wxGetHomeDir( &m_optionsResourceFilename
);
155 m_optionsResourceFilename
+= "/.dialogedrc";
157 #error "Unsupported platform."
163 m_helpController
= new wxHelpController
;
164 m_helpController
->Initialize("dialoged");
167 m_popupMenu
= new wxMenu
;
168 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
169 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
174 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
176 #if defined(__WXGTK__) || defined(__WXMOTIF__)
177 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
181 // Initialize the image list icons
183 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
184 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
185 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
186 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
188 wxIcon
icon1( dialog_xpm
);
189 wxIcon
icon2( folder1_xpm
);
190 wxIcon
icon3( folder2_xpm
);
191 wxIcon
icon4( buttonsm_xpm
);
193 m_imageList
.Add(icon1
);
194 m_imageList
.Add(icon2
);
195 m_imageList
.Add(icon3
);
196 m_imageList
.Add(icon4
);
198 m_symbolTable
.AddStandardSymbols();
203 bool wxResourceManager::LoadOptions()
205 wxConfig
config("DialogEd", "wxWindows");
207 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
208 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
209 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
210 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
211 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
212 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
213 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
214 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
219 bool wxResourceManager::SaveOptions()
221 wxConfig
config("DialogEd", "wxWindows");
223 config
.Write("editorWindowX", (long) m_resourceEditorWindowSize
.x
);
224 config
.Write("editorWindowY", (long) m_resourceEditorWindowSize
.y
);
225 config
.Write("editorWindowWidth", (long) m_resourceEditorWindowSize
.width
);
226 config
.Write("editorWindowHeight", (long) m_resourceEditorWindowSize
.height
);
227 config
.Write("propertyWindowX", (long) m_propertyWindowSize
.x
);
228 config
.Write("propertyWindowY", (long) m_propertyWindowSize
.y
);
229 config
.Write("propertyWindowWidth", (long) m_propertyWindowSize
.width
);
230 config
.Write("propertyWindowHeight", (long) m_propertyWindowSize
.height
);
235 // Show or hide the resource editor frame, which displays a list
236 // of resources with ability to edit them.
237 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
243 m_editorFrame
->Iconize(FALSE
);
244 m_editorFrame
->Show(TRUE
);
247 m_editorFrame
= OnCreateEditorFrame(title
);
249 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
250 m_editorFrame
->SetMenuBar(menuBar
);
252 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
253 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
254 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
256 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
258 m_editorResourceTree
->SetImageList(& m_imageList
);
260 // Constraints for toolbar
261 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
262 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
263 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
264 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
265 c
->bottom
.Unconstrained();
266 c
->width
.Unconstrained();
267 c
->height
.Absolute(28);
268 m_editorToolBar
->SetConstraints(c
);
270 // Constraints for listbox
271 c
= new wxLayoutConstraints
;
272 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
273 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
274 c
->right
.Absolute (150);
275 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
276 c
->width
.Unconstrained();
277 c
->height
.Unconstrained();
278 m_editorResourceTree
->SetConstraints(c
);
280 // Constraints for panel
281 c
= new wxLayoutConstraints
;
282 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
283 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
284 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
285 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
286 c
->width
.Unconstrained();
287 c
->height
.Unconstrained();
288 m_editorPanel
->SetConstraints(c
);
290 // Constraints for control list (bottom window)
291 c
= new wxLayoutConstraints
;
292 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
293 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
294 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
295 c
->width
.Unconstrained();
296 #if defined(__WXGTK__) || defined(__WXMOTIF__)
297 c
->height
.Absolute(120);
299 c
->height
.Absolute(60);
302 m_editorControlList
->SetConstraints(c
);
304 m_editorFrame
->SetAutoLayout(TRUE
);
306 UpdateResourceList();
308 m_editorFrame
->Show(TRUE
);
313 if (m_editorFrame
->Close())
315 m_editorFrame
= NULL
;
316 m_editorPanel
= NULL
;
322 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
326 if (filename
== wxString(""))
327 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
330 wxString
str("wxWindows Dialog Editor - ");
331 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
333 m_editorFrame
->SetTitle(str
);
338 bool wxResourceManager::Save()
340 if (m_currentFilename
== wxString(""))
343 return Save(m_currentFilename
);
346 bool wxResourceManager::Save(const wxString
& filename
)
348 // Ensure all visible windows are saved to their resources
349 m_currentFilename
= filename
;
350 SetFrameTitle(m_currentFilename
);
351 InstantiateAllResourcesFromWindows();
352 if (m_resourceTable
.Save(filename
))
354 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
362 bool wxResourceManager::SaveAs()
364 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
365 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
, wxTheApp
->GetTopWindow()));
367 if (s
.IsNull() || s
== "")
370 m_currentFilename
= s
;
371 wxStripExtension(m_currentFilename
);
372 m_currentFilename
+= ".wxr";
374 // Construct include filename from this file
375 m_symbolFilename
= m_currentFilename
;
377 wxStripExtension(m_symbolFilename
);
378 m_symbolFilename
+= ".h";
380 Save(m_currentFilename
);
384 bool wxResourceManager::SaveIfModified()
391 bool wxResourceManager::Load(const wxString
& filename
)
393 return New(TRUE
, filename
);
396 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
398 if (!Clear(TRUE
, FALSE
))
401 m_symbolTable
.AddStandardSymbols();
405 wxString str
= filename
;
406 if (str
== wxString(""))
408 wxString
f(wxFileSelector("Open resource file", wxGetCwd(), wxEmptyString
, "wxr", "*.wxr", 0, wxTheApp
->GetTopWindow()));
409 if (!f
.IsNull() && f
!= "")
415 if (!m_resourceTable
.ParseResourceFile(str
))
417 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
420 m_currentFilename
= str
;
422 SetFrameTitle(m_currentFilename
);
424 UpdateResourceList();
426 // Construct include filename from this file
427 m_symbolFilename
= m_currentFilename
;
429 wxStripExtension(m_symbolFilename
);
430 m_symbolFilename
+= ".h";
432 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
434 wxString
str("Could not find include file ");
435 str
+= m_symbolFilename
;
436 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
437 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
438 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
440 m_symbolIdCounter
= 99;
444 // Set the id counter to the last known id
445 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
448 // Now check in case some (or all) resources don't have resource ids, or they
449 // don't match the .h file, or something of that nature.
450 bool altered
= RepairResourceIds();
453 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
454 "Dialog Editor Warning", wxOK
);
465 m_currentFilename
= "";
472 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
474 wxPropertyInfo::CloseWindow();
476 if (!force
&& Modified())
478 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
482 if (!SaveIfModified())
488 ClearCurrentDialog();
489 DisassociateWindows();
491 m_symbolTable
.Clear();
492 m_resourceTable
.ClearTable();
493 UpdateResourceList();
498 bool wxResourceManager::DisassociateWindows()
500 m_resourceTable
.BeginFind();
502 while ((node
= m_resourceTable
.Next()))
504 wxItemResource
*res
= (wxItemResource
*)node
->Data();
505 DisassociateResource(res
);
511 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
513 if (!m_resourceAssociations
.Get((long)resource
))
514 m_resourceAssociations
.Put((long)resource
, win
);
516 wxNode
*node
= resource
->GetChildren().First();
517 wxNode
* node2
= win
->GetChildren().First();
518 while (node
&& node2
)
520 wxItemResource
*child
= (wxItemResource
*)node
->Data();
521 wxWindow
* childWindow
= (wxWindow
*) node2
->Data();
523 if (child
->GetId() != childWindow
->GetId())
526 msg
.Printf("AssociateResource: error when associating child window %ld with resource %ld", child
->GetId(), childWindow
->GetId());
527 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
529 else if (childWindow
->GetName() != child
->GetName())
532 msg
.Printf("AssociateResource: error when associating child window with resource %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
533 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
537 AssociateResource(child
, childWindow
);
540 // New code to avoid the problem of duplicate ids and names. We simply
541 // traverse the child windows and child resources in parallel,
542 // checking for any mismatch.
544 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
546 // childWindow = win->FindWindow(child->GetName());
547 childWindow
= win
->FindWindow(child
->GetId());
549 AssociateResource(child
, childWindow
);
553 msg
.Printf("AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
554 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
558 node2
= node2
->Next();
562 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
564 wxWindow
*win
= FindWindowForResource(resource
);
568 // Disassociate children of window
569 wxNode
*node
= win
->GetChildren().First();
572 wxWindow
*child
= (wxWindow
*)node
->Data();
573 if (child
->IsKindOf(CLASSINFO(wxControl
)))
574 DisassociateResource(child
);
578 RemoveSelection(win
);
579 m_resourceAssociations
.Delete((long)resource
);
583 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
585 wxItemResource
*res
= FindResourceForWindow(win
);
587 return DisassociateResource(res
);
592 // Saves the window info into the resource, and deletes the
593 // handler. Doesn't actually disassociate the window from
594 // the resources. Replaces OnClose.
595 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
597 wxItemResource
*res
= FindResourceForWindow(win
);
599 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
601 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
602 win
->PopEventHandler();
604 // Now reset all child event handlers
605 wxNode
*node
= win
->GetChildren().First();
608 wxWindow
*child
= (wxWindow
*)node
->Data();
609 wxEvtHandler
*childHandler
= child
->GetEventHandler();
610 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
612 child
->PopEventHandler(TRUE
);
620 win
->PopEventHandler(TRUE
);
623 // Save the information
624 InstantiateResourceFromWindow(res
, win
, TRUE
);
626 // DisassociateResource(win);
631 // Destroys the window. If this is the 'current' panel, NULLs the
633 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
635 bool clearDisplay
= FALSE
;
636 if (m_editorPanel
->m_childWindow
== win
)
638 m_editorPanel
->m_childWindow
= NULL
;
645 m_editorPanel
->Clear();
650 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
652 m_resourceAssociations
.BeginFind();
654 while ((node
= m_resourceAssociations
.Next()))
656 wxWindow
*w
= (wxWindow
*)node
->Data();
659 return (wxItemResource
*)node
->GetKeyInteger();
665 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
667 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
671 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
675 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
678 if (!m_resourceTable
.FindResource(buf
))
683 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
685 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
686 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
687 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
688 wxDEFAULT_FRAME_STYLE
);
690 frame
->CreateStatusBar(1);
692 frame
->SetAutoLayout(TRUE
);
694 frame
->SetIcon(wxIcon("DIALOGEDICON"));
699 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
701 wxMenuBar
*menuBar
= new wxMenuBar
;
703 wxMenu
*fileMenu
= new wxMenu
;
704 fileMenu
->Append(RESED_NEW_DIALOG
, "New &Dialog", "Create a new dialog");
705 fileMenu
->AppendSeparator();
706 fileMenu
->Append(wxID_NEW
, "&New Project", "Clear the current project");
707 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
708 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
709 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
710 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
711 fileMenu
->AppendSeparator();
712 fileMenu
->Append(RESED_CONVERT_WXRS
, "Convert Old &Resources...", "Convert old resources to new");
713 fileMenu
->AppendSeparator();
714 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
716 wxMenu
*editMenu
= new wxMenu
;
717 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
718 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
719 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
721 wxMenu
*helpMenu
= new wxMenu
;
722 helpMenu
->Append(RESED_CONTENTS
, "&Help Topics", "Invokes the on-line help");
723 helpMenu
->AppendSeparator();
724 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
726 menuBar
->Append(fileMenu
, "&File");
727 menuBar
->Append(editMenu
, "&Edit");
728 menuBar
->Append(helpMenu
, "&Help");
733 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
735 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
736 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
743 panel
->SetScrollbars(10, 10, 100, 100);
748 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
750 // Load palette bitmaps
752 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
753 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
754 wxBitmap
ToolbarNewBitmap("NEWTOOL");
755 wxBitmap
ToolbarVertBitmap("VERTTOOL");
756 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
757 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
758 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
759 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
760 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
761 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
762 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
763 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
764 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
765 wxBitmap
ToolbarCopyWidthBitmap("COPYWIDTHTOOL");
766 wxBitmap
ToolbarCopyHeightBitmap("COPYHEIGHTTOOL");
767 wxBitmap
ToolbarDistributeHorizBitmap("DISTHORIZTOOL");
768 wxBitmap
ToolbarDistributeVertBitmap("DISTVERTTOOL");
770 #if defined(__WXGTK__) || defined(__WXMOTIF__)
771 wxBitmap
ToolbarLoadBitmap( load_xpm
);
772 wxBitmap
ToolbarSaveBitmap( save_xpm
);
773 wxBitmap
ToolbarNewBitmap( new_xpm
);
774 wxBitmap
ToolbarVertBitmap( vert_xpm
);
775 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
776 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
777 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
778 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
779 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
780 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
781 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
782 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
783 wxBitmap
ToolbarHelpBitmap( help_xpm
);
784 wxBitmap
ToolbarCopyWidthBitmap(copywdth_xpm
);
785 wxBitmap
ToolbarCopyHeightBitmap(copyhght_xpm
);
786 wxBitmap
ToolbarDistributeHorizBitmap(disthor_xpm
);
787 wxBitmap
ToolbarDistributeVertBitmap(distvert_xpm
);
790 // Create the toolbar
791 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
|wxTB_FLAT
);
792 toolbar
->SetMargins(2, 2);
799 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
804 //toolbar->AddSeparator();
805 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
806 FALSE
, currentX
, -1, NULL
, "New dialog");
807 currentX
+= width
+ dx
;
808 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
809 FALSE
, currentX
, -1, NULL
, "Load");
810 currentX
+= width
+ dx
;
811 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
812 FALSE
, currentX
, -1, NULL
, "Save");
813 currentX
+= width
+ dx
+ gap
;
814 toolbar
->AddSeparator();
815 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
816 FALSE
, currentX
, -1, NULL
, "Horizontal align");
817 currentX
+= width
+ dx
;
818 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
819 FALSE
, currentX
, -1, NULL
, "Top align");
820 currentX
+= width
+ dx
;
821 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
822 FALSE
, currentX
, -1, NULL
, "Bottom align");
823 currentX
+= width
+ dx
;
824 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
825 FALSE
, currentX
, -1, NULL
, "Vertical align");
826 currentX
+= width
+ dx
;
827 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
828 FALSE
, currentX
, -1, NULL
, "Left align");
829 currentX
+= width
+ dx
;
830 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
831 FALSE
, currentX
, -1, NULL
, "Right align");
832 currentX
+= width
+ dx
+ gap
;
833 toolbar
->AddSeparator();
834 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
835 FALSE
, currentX
, -1, NULL
, "Copy size");
836 currentX
+= width
+ dx
;
837 toolbar
->AddTool(TOOLBAR_COPY_WIDTH
, ToolbarCopyWidthBitmap
, wxNullBitmap
,
838 FALSE
, currentX
, -1, NULL
, "Copy width");
839 currentX
+= width
+ dx
;
840 toolbar
->AddTool(TOOLBAR_COPY_HEIGHT
, ToolbarCopyHeightBitmap
, wxNullBitmap
,
841 FALSE
, currentX
, -1, NULL
, "Copy height");
842 currentX
+= width
+ dx
;
843 toolbar
->AddTool(TOOLBAR_DISTRIBUTE_HORIZ
, ToolbarDistributeHorizBitmap
, wxNullBitmap
,
844 FALSE
, currentX
, -1, NULL
, "Distribute horizontally");
845 currentX
+= width
+ dx
;
846 toolbar
->AddTool(TOOLBAR_DISTRIBUTE_VERT
, ToolbarDistributeVertBitmap
, wxNullBitmap
,
847 FALSE
, currentX
, -1, NULL
, "Distribute vertically");
848 currentX
+= width
+ dx
+ gap
;
849 toolbar
->AddSeparator();
850 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
851 FALSE
, currentX
, -1, NULL
, "To front");
852 currentX
+= width
+ dx
;
853 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
854 FALSE
, currentX
, -1, NULL
, "To back");
855 currentX
+= width
+ dx
+ gap
;
857 toolbar
->AddSeparator();
858 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
859 FALSE
, currentX
, -1, NULL
, "Help");
860 currentX
+= width
+ dx
;
867 void wxResourceManager::UpdateResourceList()
869 if (!m_editorResourceTree
)
872 m_editorResourceTree
->SetInvalid(TRUE
);
873 m_editorResourceTree
->DeleteAllItems();
875 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
877 m_resourceTable
.BeginFind();
879 while ((node
= m_resourceTable
.Next()))
881 wxItemResource
*res
= (wxItemResource
*)node
->Data();
882 wxString
resType(res
->GetType());
883 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
885 AddItemsRecursively(id
, res
);
888 m_editorResourceTree
->Expand(id
);
889 m_editorResourceTree
->SetInvalid(FALSE
);
892 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
894 wxString
theString("");
895 theString
= resource
->GetName();
898 wxString
resType(resource
->GetType());
899 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
904 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
906 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
908 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
910 wxNode
*node
= resource
->GetChildren().First();
913 wxItemResource
*res
= (wxItemResource
*)node
->Data();
914 AddItemsRecursively(id
, res
);
918 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
921 bool wxResourceManager::EditSelectedResource()
923 int sel
= m_editorResourceTree
->GetSelection();
926 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
927 wxItemResource
*res
= data
->GetResource();
933 bool wxResourceManager::Edit(wxItemResource
*res
)
935 wxPropertyInfo::CloseWindow();
937 ClearCurrentDialog();
939 wxString
resType(res
->GetType());
940 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
944 wxMessageBox("Should not find panel in wxResourceManager::Edit");
949 // long style = res->GetStyle();
950 // res->SetStyle(style|wxRAISED_BORDER);
952 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
955 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
957 panel
->PushEventHandler(handler
);
959 // res->SetStyle(style);
960 handler
->AddChildHandlers(); // Add event handlers for all controls
961 AssociateResource(res
, panel
);
963 m_editorPanel
->m_childWindow
= panel
;
964 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
968 wxClientDC
dc(m_editorPanel
);
969 m_editorPanel
->DrawTitle(dc
);
974 bool wxResourceManager::CreateNewPanel()
976 wxPropertyInfo::CloseWindow();
978 ClearCurrentDialog();
981 MakeUniqueName("dialog", buf
);
983 wxItemResource
*resource
= new wxItemResource
;
984 resource
->SetType("wxDialog");
985 resource
->SetName(buf
);
986 resource
->SetTitle(buf
);
987 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
988 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
991 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
994 // This is now guaranteed to be unique, so just add to symbol table
995 m_symbolTable
.AddSymbol(newIdName
, id
);
997 m_resourceTable
.AddResource(resource
);
999 wxSize
size(400, 300);
1001 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
1002 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
1003 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
1004 m_editorPanel
->m_childWindow
= panel
;
1006 resource
->SetStyle(panel
->GetWindowStyleFlag());
1008 // Store dialog units in resource
1009 size
= panel
->ConvertPixelsToDialog(size
);
1011 resource
->SetSize(10, 10, size
.x
, size
.y
);
1013 // For editing in situ we will need to use the hash table to ensure
1014 // we don't dereference invalid pointers.
1015 // resourceWindowTable.Put((long)resource, panel);
1017 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
1019 panel
->PushEventHandler(handler
);
1021 AssociateResource(resource
, panel
);
1022 UpdateResourceList();
1025 m_editorPanel
->m_childWindow
->Refresh();
1027 // panel->Refresh();
1029 wxClientDC
dc(m_editorPanel
);
1030 m_editorPanel
->DrawTitle(dc
);
1035 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1038 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1043 wxItemResource
*res
= new wxItemResource
;
1044 wxControl
*newItem
= NULL
;
1046 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1048 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1049 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1051 else res
->SetSize(x
, y
, -1, -1);
1053 res
->SetType(iType
);
1057 wxString
itemType(iType
);
1059 if (itemType
== "wxButton")
1061 prefix
= "ID_BUTTON";
1062 MakeUniqueName("button", buf
);
1065 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), wxBU_AUTODRAW
, wxDefaultValidator
, buf
);
1067 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1069 if (itemType
== "wxBitmapButton")
1071 prefix
= "ID_BITMAPBUTTON";
1072 MakeUniqueName("button", buf
);
1074 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), wxBU_AUTODRAW
, wxDefaultValidator
, buf
);
1076 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1078 prefix
= "ID_STATIC";
1079 MakeUniqueName("statictext", buf
);
1082 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1084 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1086 else if (itemType
== "wxStaticBitmap")
1088 prefix
= "ID_STATICBITMAP";
1089 MakeUniqueName("static", buf
);
1091 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1093 else if (itemType
== "wxCheckBox")
1095 prefix
= "ID_CHECKBOX";
1096 MakeUniqueName("checkbox", buf
);
1098 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1100 else if (itemType
== "wxListBox")
1102 prefix
= "ID_LISTBOX";
1103 MakeUniqueName("listbox", buf
);
1105 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1107 else if (itemType
== "wxRadioBox")
1109 prefix
= "ID_RADIOBOX";
1110 MakeUniqueName("radiobox", buf
);
1112 wxString names
[] = { "One", "Two" };
1113 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1114 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1115 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1117 else if (itemType
== "wxRadioButton")
1119 prefix
= "ID_RADIOBUTTON";
1120 MakeUniqueName("radiobutton", buf
);
1122 wxString names
[] = { "One", "Two" };
1123 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1124 0, wxDefaultValidator
, buf
);
1126 else if (itemType
== "wxChoice")
1128 prefix
= "ID_CHOICE";
1129 MakeUniqueName("choice", buf
);
1131 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1133 else if (itemType
== "wxComboBox")
1135 prefix
= "ID_COMBOBOX";
1136 MakeUniqueName("combobox", buf
);
1138 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1140 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1142 prefix
= "ID_STATICBOX";
1143 MakeUniqueName("staticbox", buf
);
1145 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1147 else if (itemType
== "wxGauge")
1149 prefix
= "ID_GAUGE";
1150 MakeUniqueName("gauge", buf
);
1152 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1154 else if (itemType
== "wxSlider")
1156 prefix
= "ID_SLIDER";
1157 MakeUniqueName("slider", buf
);
1159 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1161 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1163 prefix
= "ID_TEXTCTRL";
1164 MakeUniqueName("textctrl", buf
);
1166 res
->SetType("wxTextCtrl");
1167 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1169 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1171 prefix
= "ID_TEXTCTRL";
1172 MakeUniqueName("textctrl", buf
);
1174 res
->SetType("wxTextCtrl");
1175 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1177 else if (itemType
== "wxScrollBar")
1179 prefix
= "ID_SCROLLBAR";
1180 MakeUniqueName("scrollbar", buf
);
1182 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1187 int actualW
, actualH
;
1188 newItem
->GetSize(&actualW
, &actualH
);
1189 wxSize
actualSize(actualW
, actualH
);
1191 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1193 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1195 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1198 int id
= GenerateWindowId(prefix
, newIdName
);
1201 // This is now guaranteed to be unique, so just add to symbol table
1202 m_symbolTable
.AddSymbol(newIdName
, id
);
1204 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1206 res
->SetStyle(newItem
->GetWindowStyleFlag());
1207 AssociateResource(res
, newItem
);
1208 panelResource
->GetChildren().Append(res
);
1210 UpdateResourceList();
1215 void wxResourceManager::ClearCurrentDialog()
1217 if (m_editorPanel
->m_childWindow
)
1219 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1220 DisassociateResource(m_editorPanel
->m_childWindow
);
1221 DeleteWindow(m_editorPanel
->m_childWindow
);
1222 m_editorPanel
->m_childWindow
= NULL
;
1223 m_editorPanel
->Clear();
1227 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1229 if (m_editorPanel
->m_childWindow
)
1231 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1235 // Make sure the resources are up-to-date w.r.t. the window
1236 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1238 ResourceEditorDialogTester
* dialog
= new ResourceEditorDialogTester
;
1239 bool success
= FALSE
;
1240 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1243 dialog
->ShowModal();
1251 // Find the first dialog or panel for which
1252 // there is a selected panel item.
1253 wxWindow
*wxResourceManager::FindParentOfSelection()
1255 m_resourceTable
.BeginFind();
1257 while ((node
= m_resourceTable
.Next()))
1259 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1260 wxWindow
*win
= FindWindowForResource(res
);
1263 wxNode
*node1
= win
->GetChildren().First();
1266 wxControl
*item
= (wxControl
*)node1
->Data();
1267 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1268 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1270 node1
= node1
->Next();
1277 // Format the panel items according to 'flag'
1278 void wxResourceManager::AlignItems(int flag
)
1280 wxWindow
*win
= FindParentOfSelection();
1284 wxNode
*node
= GetSelections().First();
1288 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1289 if (firstSelection
->GetParent() != win
)
1294 firstSelection
->GetPosition(&firstX
, &firstY
);
1295 firstSelection
->GetSize(&firstW
, &firstH
);
1296 int centreX
= (int)(firstX
+ (firstW
/ 2));
1297 int centreY
= (int)(firstY
+ (firstH
/ 2));
1299 while ((node
= node
->Next()))
1301 wxControl
*item
= (wxControl
*)node
->Data();
1302 if (item
->GetParent() == win
)
1305 item
->GetPosition(&x
, &y
);
1306 item
->GetSize(&w
, &h
);
1312 case TOOLBAR_FORMAT_HORIZ
:
1315 newY
= (int)(centreY
- (h
/2.0));
1318 case TOOLBAR_FORMAT_VERT
:
1320 newX
= (int)(centreX
- (w
/2.0));
1324 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1330 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1336 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1338 newX
= firstX
+ firstW
- w
;
1342 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1345 newY
= firstY
+ firstH
- h
;
1353 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1354 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1356 item
->SetSize(newX
, newY
, w
, h
);
1358 // Also update the associated resource
1359 // We need to convert to dialog units if this is not a dialog or panel, but
1360 // the parent resource specifies dialog units.
1361 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1363 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1364 newX
= pt
.x
; newY
= pt
.y
;
1365 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1368 resource
->SetSize(newX
, newY
, w
, h
);
1374 // Copy the first image's size to subsequent images
1375 void wxResourceManager::CopySize(int command
)
1377 bool copyWidth
= (command
== TOOLBAR_COPY_SIZE
|| command
== TOOLBAR_COPY_WIDTH
) ;
1378 bool copyHeight
= (command
== TOOLBAR_COPY_SIZE
|| command
== TOOLBAR_COPY_HEIGHT
) ;
1380 wxWindow
*win
= FindParentOfSelection();
1384 wxNode
*node
= GetSelections().First();
1388 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1389 if (firstSelection
->GetParent() != win
)
1394 firstSelection
->GetPosition(&firstX
, &firstY
);
1395 firstSelection
->GetSize(&firstW
, &firstH
);
1397 while ((node
= node
->Next()))
1399 wxControl
*item
= (wxControl
*)node
->Data();
1400 if (item
->GetParent() == win
)
1402 wxSize sz
= item
->GetSize();
1403 int widthToSet
= (copyWidth
? firstW
: sz
.x
);
1404 int heightToSet
= (copyHeight
? firstH
: sz
.y
);
1406 item
->SetSize(-1, -1, widthToSet
, heightToSet
);
1408 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1409 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1411 widthToSet
= resource
->GetWidth();
1412 heightToSet
= resource
->GetHeight();
1414 // Also update the associated resource
1415 // We need to convert to dialog units if this is not a dialog or panel, but
1416 // the parent resource specifies dialog units.
1417 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1419 wxSize convertedSize
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1421 widthToSet
= convertedSize
.x
;
1423 heightToSet
= convertedSize
.y
;
1425 resource
->SetSize(resource
->GetX(), resource
->GetY(), widthToSet
, heightToSet
);
1431 void wxResourceManager::ToBackOrFront(bool toBack
)
1433 wxWindow
*win
= FindParentOfSelection();
1436 wxItemResource
*winResource
= FindResourceForWindow(win
);
1438 wxNode
*node
= GetSelections().First();
1441 wxControl
*item
= (wxControl
*)node
->Data();
1442 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1443 if (item
->GetParent() == win
)
1445 win
->GetChildren().DeleteObject(item
);
1447 winResource
->GetChildren().DeleteObject(itemResource
);
1450 win
->GetChildren().Insert(item
);
1452 winResource
->GetChildren().Insert(itemResource
);
1456 win
->GetChildren().Append(item
);
1458 winResource
->GetChildren().Append(itemResource
);
1461 node
= node
->Next();
1466 // Distribute controls evenly between first and last
1467 void wxResourceManager::DistributePositions(int command
)
1469 bool horizontal
= (command
== TOOLBAR_DISTRIBUTE_HORIZ
) ;
1471 wxWindow
*win
= FindParentOfSelection();
1475 if (GetSelections().Number() < 3)
1477 wxMessageBox(wxT("Sorry, distributing less than three controls does not make sense."));
1481 wxControl
*firstSelection
= (wxControl
*) GetSelections().First()->Data();
1482 wxControl
*lastSelection
= (wxControl
*) GetSelections().Last()->Data();
1484 // For now, assume the ordering is correct (the user selected the controls in order).
1485 // TODO: explicitly order the selections in terms of increading x or y position.
1487 // Find the total amount of space between all controls
1488 int totalControlSpace
= 0; // How much space the controls take up
1490 wxNode
* node
= GetSelections().First();
1493 wxControl
* control
= (wxControl
*) node
->Data();
1497 control
->GetPosition(&x
, &y
);
1498 control
->GetSize(&w
, &h
);
1500 // Don't include the space taken up by the first and last controls.
1501 if (control
!= firstSelection
&& control
!= lastSelection
)
1504 totalControlSpace
+= w
;
1506 totalControlSpace
+= h
;
1509 node
= node
->Next();
1513 int firstX
, firstY
, lastX
, lastY
;
1514 int firstW
, firstH
, lastW
, lastH
;
1515 firstSelection
->GetPosition(&firstX
, &firstY
);
1516 firstSelection
->GetSize(&firstW
, &firstH
);
1518 lastSelection
->GetPosition(&lastX
, &lastY
);
1519 lastSelection
->GetSize(&lastW
, &lastH
);
1524 |===| |====| |======| |==|
1528 int spacing
, currentPos
;
1531 spacing
= ((lastX
- (firstX
+ firstW
)) - totalControlSpace
) / (GetSelections().Number() - 1);
1532 currentPos
= firstX
+ firstW
+ spacing
;
1536 spacing
= ((lastY
- (firstY
+ firstH
)) - totalControlSpace
) / (GetSelections().Number() - 1);
1537 currentPos
= firstY
+ firstH
+ spacing
;
1540 node
= GetSelections().First();
1542 while ((node
= node
->Next()))
1544 wxControl
*item
= (wxControl
*)node
->Data();
1545 wxSize sz
= item
->GetSize();
1546 wxPoint pos
= item
->GetPosition();
1547 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1548 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1550 int controlX
= (horizontal
? currentPos
: pos
.x
);
1551 int controlY
= (horizontal
? pos
.y
: currentPos
);
1553 item
->Move(controlX
, controlY
);
1555 int resX
= controlX
;
1556 int resY
= controlY
;
1558 // Also update the associated resource
1559 // We need to convert to dialog units if this is not a dialog or panel, but
1560 // the parent resource specifies dialog units.
1561 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1563 wxPoint convertedPos
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(resX
, resY
));
1564 resX
= convertedPos
.x
;
1565 resY
= convertedPos
.y
;
1567 resource
->SetSize(resX
, resY
, resource
->GetWidth(), resource
->GetHeight());
1569 currentPos
+= (horizontal
? (sz
.x
+ spacing
) : (sz
.y
+ spacing
));
1574 void wxResourceManager::AddSelection(wxWindow
*win
)
1576 if (!m_selections
.Member(win
))
1577 m_selections
.Append(win
);
1580 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1582 m_selections
.DeleteObject(win
);
1585 void wxResourceManager::DeselectItemIfNecessary(wxWindow
*win
)
1587 if (win
->IsKindOf(CLASSINFO(wxControl
)) && (win
->GetEventHandler() != win
))
1589 // Deselect and refresh window in case we leave selection
1591 wxControl
*item
= (wxControl
*)win
;
1592 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1593 if (childHandler
->IsSelected())
1595 wxResourceManager::GetCurrentResourceManager()->RemoveSelection(item
);
1596 childHandler
->SelectItem(FALSE
);
1598 item
->GetParent()->Refresh();
1604 // Need to search through resource table removing this from
1605 // any resource which has this as a parent.
1606 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1608 m_resourceTable
.BeginFind();
1610 while ((node
= m_resourceTable
.Next()))
1612 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1613 if (thisRes
->GetChildren().Member(res
))
1615 thisRes
->GetChildren().DeleteObject(res
);
1622 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1627 RemoveResourceFromParent(res
);
1629 wxNode
*node
= res
->GetChildren().First();
1632 wxNode
*next
= node
->Next();
1633 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1634 DeleteResource(child
);
1638 // If this is a button or message resource, delete the
1639 // associate bitmap resource if not being used.
1640 wxString
resType(res
->GetType());
1642 /* shouldn't have to do this now bitmaps are ref-counted
1643 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1645 PossiblyDeleteBitmapResource(res->GetValue4());
1649 // Remove symbol from table if appropriate
1650 if (!IsSymbolUsed(res
, res
->GetId()))
1652 m_symbolTable
.RemoveSymbol(res
->GetId());
1655 m_resourceTable
.Delete(res
->GetName());
1661 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1663 DeselectItemIfNecessary(win
);
1665 wxItemResource
*res
= FindResourceForWindow(win
);
1667 DisassociateResource(res
);
1668 DeleteResource(res
);
1669 UpdateResourceList();
1674 // Will eventually have bitmap type information, for different
1676 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1678 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1682 MakeUniqueName("bitmap", buf
);
1683 resource
= new wxItemResource
;
1684 resource
->SetType("wxBitmap");
1685 resource
->SetName(buf
);
1687 // A bitmap resource has one or more children, specifying
1688 // alternative bitmaps.
1689 wxItemResource
*child
= new wxItemResource
;
1690 child
->SetType("wxBitmap");
1691 child
->SetName(filename
);
1692 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1693 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1694 child
->SetValue3(0); // Depth
1695 child
->SetSize(0,0,0,0);
1696 resource
->GetChildren().Append(child
);
1698 m_resourceTable
.AddResource(resource
);
1700 UpdateResourceList();
1703 return resource
->GetName();
1705 return wxEmptyString
;
1708 // Delete the bitmap resource if it isn't being used by another resource.
1709 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1711 if (!IsBitmapResourceUsed(resourceName
))
1713 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1714 DeleteResource(res
);
1715 UpdateResourceList();
1719 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1721 m_resourceTable
.BeginFind();
1723 while ((node
= m_resourceTable
.Next()))
1725 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1726 wxString
resType(res
->GetType());
1727 if (resType
== "wxDialog")
1729 wxNode
*node1
= res
->GetChildren().First();
1732 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1733 wxString
childResType(child
->GetType());
1735 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1736 child
->GetValue4() &&
1737 (strcmp(child
->GetValue4(), resourceName
) == 0))
1739 node1
= node1
->Next();
1746 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1747 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1749 if (!resource
|| (resource
->GetValue4() == ""))
1750 return wxEmptyString
;
1751 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1752 if (!bitmapResource
)
1753 return wxEmptyString
;
1755 wxNode
*node
= bitmapResource
->GetChildren().First();
1758 // Eventually augment this to return a bitmap of the right kind or something...
1759 // Maybe the root of the filename remains the same, so it doesn't matter which we
1760 // pick up. Otherwise how do we specify multiple filenames... too boring...
1761 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1762 return child
->GetName();
1764 //node = node->Next();
1766 return wxEmptyString
;
1769 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1771 m_resourceTable
.BeginFind();
1773 while ((node
= m_resourceTable
.Next()))
1775 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1776 wxString
resType(res
->GetType());
1777 if (resType
== "wxBitmap")
1779 wxNode
*node1
= res
->GetChildren().First();
1782 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1783 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1785 node1
= node1
->Next();
1792 // Is this window identifier symbol in use?
1793 // Let's assume that we can't have 2 names for the same integer id.
1794 // Therefore we can tell by the integer id whether the symbol is
1796 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1798 m_resourceTable
.BeginFind();
1800 while ((node
= m_resourceTable
.Next()))
1802 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1804 wxString
resType(res
->GetType());
1805 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1807 if ((res
!= thisResource
) && (res
->GetId() == id
))
1810 wxNode
*node1
= res
->GetChildren().First();
1813 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1814 if ((child
!= thisResource
) && (child
->GetId() == id
))
1816 node1
= node1
->Next();
1823 // Is this window identifier compatible with the given name? (i.e.
1824 // does it already exist under a different name)
1825 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1827 if (m_symbolTable
.SymbolExists(name
))
1829 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1836 // Change all integer ids that match oldId, to newId.
1837 // This is necessary if an id is changed for one resource - all resources
1839 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1841 m_resourceTable
.BeginFind();
1843 while ((node
= m_resourceTable
.Next()))
1845 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1847 wxString
resType(res
->GetType());
1848 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1850 if (res
->GetId() == oldId
)
1853 wxNode
*node1
= res
->GetChildren().First();
1856 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1857 if (child
->GetId() == oldId
)
1858 child
->SetId(newId
);
1860 node1
= node1
->Next();
1866 // If any resource ids were missing (or their symbol was missing),
1867 // repair them i.e. give them new ids. Returns TRUE if any resource
1868 // needed repairing.
1869 bool wxResourceManager::RepairResourceIds()
1871 bool repaired
= FALSE
;
1873 m_resourceTable
.BeginFind();
1875 while ((node
= m_resourceTable
.Next()))
1877 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1878 wxString
resType(res
->GetType());
1879 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1882 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1884 wxString newSymbolName
;
1885 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1887 if (res
->GetId() == 0)
1890 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1894 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1900 wxNode
*node1
= res
->GetChildren().First();
1903 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1905 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1907 wxString newSymbolName
;
1908 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1910 if (child
->GetId() == 0)
1912 child
->SetId(newId
);
1913 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1917 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1923 node1
= node1
->Next();
1931 // Deletes 'win' and creates a new window from the resource that
1932 // was associated with it. E.g. if you can't change properties on the
1933 // fly, you'll need to delete the window and create it again.
1934 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
, bool instantiateFirst
)
1936 wxItemResource
*resource
= FindResourceForWindow(win
);
1938 // Put the current window properties into the wxItemResource object
1940 wxWindowPropertyInfo
*newInfo
= NULL
;
1943 newInfo
= CreatePropertyInfoForWindow(win
);
1947 // May not always want to copy values back from the resource
1948 if (instantiateFirst
)
1949 info
->InstantiateResource(resource
);
1951 wxWindow
*newWin
= NULL
;
1952 wxWindow
*parent
= win
->GetParent();
1953 wxItemResource
* parentResource
= NULL
;
1955 parentResource
= FindResourceForWindow(parent
);
1957 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1960 newWin
= FindWindowForResource(resource
);
1964 DisassociateResource(resource
);
1965 if (win
->GetEventHandler() != win
)
1966 win
->PopEventHandler(TRUE
);
1969 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1970 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1971 AssociateResource(resource
, newWin
);
1972 UpdateResourceList();
1976 info
->SetPropertyWindow(newWin
);
1984 // Delete resource highlighted in the listbox
1985 bool wxResourceManager::DeleteSelection()
1987 int sel
= m_editorResourceTree
->GetSelection();
1990 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1991 wxItemResource
*res
= data
->GetResource();
1992 wxWindow
*win
= FindWindowForResource(res
);
1995 DeleteResource(win
);
1997 UpdateResourceList();
2006 // Delete resource highlighted in the listbox
2007 bool wxResourceManager::RecreateSelection()
2009 wxNode
*node
= GetSelections().First();
2012 wxControl
*item
= (wxControl
*)node
->Data();
2013 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
2014 wxNode
*next
= node
->Next();
2015 childHandler
->SelectItem(FALSE
);
2017 RemoveSelection(item
);
2019 RecreateWindowFromResource(item
);
2026 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
2031 // Ensures that all currently shown windows are saved to resources,
2032 // e.g. just before writing to a .wxr file.
2033 bool wxResourceManager::InstantiateAllResourcesFromWindows()
2035 m_resourceTable
.BeginFind();
2037 while ((node
= m_resourceTable
.Next()))
2039 wxItemResource
*res
= (wxItemResource
*)node
->Data();
2040 wxString
resType(res
->GetType());
2042 if (resType
== "wxDialog")
2044 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
2046 InstantiateResourceFromWindow(res
, win
, TRUE
);
2048 else if (resType
== "wxPanel")
2050 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
2052 InstantiateResourceFromWindow(res
, win
, TRUE
);
2058 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
2060 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
2061 info
->SetResource(resource
);
2062 info
->InstantiateResource(resource
);
2067 wxNode
*node
= resource
->GetChildren().First();
2070 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2071 wxWindow
*childWindow
= FindWindowForResource(child
);
2076 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
2077 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
2080 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
2081 node
= node
->Next();
2088 // Create a window information object for the give window
2089 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
2091 wxWindowPropertyInfo
*info
= NULL
;
2092 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
2094 info
= new wxScrollBarPropertyInfo(win
);
2096 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
2098 info
= new wxGroupBoxPropertyInfo(win
);
2100 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
2102 info
= new wxCheckBoxPropertyInfo(win
);
2104 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
2106 info
= new wxSliderPropertyInfo(win
);
2108 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
2110 info
= new wxGaugePropertyInfo(win
);
2112 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
2114 info
= new wxListBoxPropertyInfo(win
);
2116 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
2118 info
= new wxRadioBoxPropertyInfo(win
);
2120 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
2122 info
= new wxRadioButtonPropertyInfo(win
);
2124 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
2126 info
= new wxComboBoxPropertyInfo(win
);
2128 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
2130 info
= new wxChoicePropertyInfo(win
);
2132 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
2134 info
= new wxBitmapButtonPropertyInfo(win
);
2136 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
2138 info
= new wxButtonPropertyInfo(win
);
2140 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
2142 info
= new wxStaticBitmapPropertyInfo(win
);
2144 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
2146 info
= new wxStaticTextPropertyInfo(win
);
2148 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
2150 info
= new wxTextPropertyInfo(win
);
2152 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
2154 info
= new wxPanelPropertyInfo(win
);
2158 info
= new wxWindowPropertyInfo(win
);
2163 // Edit the given window
2164 void wxResourceManager::EditWindow(wxWindow
*win
)
2166 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2169 info
->SetResource(FindResourceForWindow(win
));
2170 wxString
str("Editing ");
2171 str
+= win
->GetClassInfo()->GetClassName();
2173 if (win
->GetName() != "")
2174 str
+= win
->GetName();
2176 str
+= "properties";
2177 info
->Edit(NULL
, str
);
2181 // Generate a window id and a first stab at a name
2182 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2184 m_symbolIdCounter
++;
2185 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2186 m_symbolIdCounter
++;
2188 int nameId
= m_symbolIdCounter
;
2191 str
.Printf("%d", nameId
);
2192 idName
= prefix
+ str
;
2194 while (m_symbolTable
.SymbolExists(idName
))
2197 str
.Printf("%d", nameId
);
2198 idName
= prefix
+ str
;
2201 return m_symbolIdCounter
;
2206 * Resource editor frame
2209 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2211 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2212 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2213 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2214 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2215 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2216 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2217 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2218 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2219 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2220 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2221 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2222 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2223 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2224 EVT_MENU(RESED_CONVERT_WXRS
, wxResourceEditorFrame::OnConvertWXRs
)
2225 EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow
)
2228 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2229 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2230 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2235 wxResourceEditorFrame::~wxResourceEditorFrame()
2239 void wxResourceEditorFrame::OnConvertWXRs(wxCommandEvent
& WXUNUSED(event
))
2241 manager
->ConvertWXRs();
2244 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2246 manager
->New(FALSE
);
2249 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2251 manager
->CreateNewPanel();
2254 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2259 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2261 manager
->Clear(TRUE
, FALSE
);
2264 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2269 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2274 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2276 manager
->Clear(TRUE
, FALSE
) ;
2280 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2283 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart <julian.smart@ukonline.co.uk>\nJulian Smart (c) 1996-1999", wxDIALOG_EDITOR_VERSION
);
2284 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2287 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2289 manager
->TestCurrentDialog(this);
2292 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2295 wxBeginBusyCursor();
2296 manager
->GetHelpController()->LoadFile();
2297 manager
->GetHelpController()->DisplayContents();
2302 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2304 manager
->DeleteSelection();
2307 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2309 manager
->RecreateSelection();
2312 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent
& event
)
2314 wxPropertyInfo::CloseWindow();
2315 manager
->ClearCurrentDialog();
2316 if (manager
->Modified())
2318 if (!manager
->Clear(TRUE
, FALSE
))
2329 manager
->m_resourceEditorWindowSize
.width
= w
;
2330 manager
->m_resourceEditorWindowSize
.height
= h
;
2333 GetPosition(&x
, &y
);
2335 manager
->m_resourceEditorWindowSize
.x
= x
;
2336 manager
->m_resourceEditorWindowSize
.y
= y
;
2338 manager
->SetEditorFrame(NULL
);
2339 manager
->SetEditorToolBar(NULL
);
2345 * Resource editor window that contains the dialog/panel being edited
2348 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2349 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2352 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2354 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2358 m_childWindow
= NULL
;
2360 SetBackgroundColour(* wxWHITE
);
2363 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2367 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2374 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2378 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2381 wxString
str(res
->GetTitle());
2383 ViewStart(& x
, & y
);
2385 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2387 dc
.SetBackgroundMode(wxTRANSPARENT
);
2388 dc
.SetTextForeground(wxColour(0, 0, 0));
2391 dc
.GetTextExtent(str
, & w
, & h
);
2393 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2398 // Popup menu callback
2399 void ObjectMenuProc(wxMenu
*menu
, wxCommandEvent
& event
)
2401 wxWindow
*data
= (wxWindow
*)menu
->GetClientData();
2405 switch (event
.GetInt())
2407 case OBJECT_MENU_EDIT
:
2409 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2412 case OBJECT_MENU_DELETE
:
2414 wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data
);
2416 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2417 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2418 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2431 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2432 // EVT_PAINT(EditorToolBar::OnPaint)
2435 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2437 wxToolBar(frame
, -1, pos
, size
, style
)
2441 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2443 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2447 case TOOLBAR_LOAD_FILE
:
2454 manager
->CreateNewPanel();
2457 case TOOLBAR_SAVE_FILE
:
2465 wxBeginBusyCursor();
2466 manager
->GetHelpController()->DisplayContents();
2471 case TOOLBAR_FORMAT_HORIZ
:
2473 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2476 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2478 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2481 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2483 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2486 case TOOLBAR_FORMAT_VERT
:
2488 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2491 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2493 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2496 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2498 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2501 case TOOLBAR_COPY_SIZE
:
2503 manager
->CopySize(TOOLBAR_COPY_SIZE
);
2506 case TOOLBAR_COPY_WIDTH
:
2508 manager
->CopySize(TOOLBAR_COPY_WIDTH
);
2511 case TOOLBAR_COPY_HEIGHT
:
2513 manager
->CopySize(TOOLBAR_COPY_HEIGHT
);
2516 case TOOLBAR_DISTRIBUTE_HORIZ
:
2518 manager
->DistributePositions(TOOLBAR_DISTRIBUTE_HORIZ
);
2521 case TOOLBAR_DISTRIBUTE_VERT
:
2523 manager
->DistributePositions(TOOLBAR_DISTRIBUTE_VERT
);
2526 case TOOLBAR_TO_BACK
:
2528 manager
->ToBackOrFront(TRUE
);
2531 case TOOLBAR_TO_FRONT
:
2533 manager
->ToBackOrFront(FALSE
);
2542 void EditorToolBar::OnMouseEnter(int toolIndex
)
2544 wxFrame
*frame
= (wxFrame
*)GetParent();
2552 case TOOLBAR_LOAD_FILE
:
2553 frame
->SetStatusText("Load project file");
2555 case TOOLBAR_SAVE_FILE
:
2556 frame
->SetStatusText("Save project file");
2559 frame
->SetStatusText("Create a new resource");
2561 case TOOLBAR_FORMAT_HORIZ
:
2562 frame
->SetStatusText("Align items horizontally");
2564 case TOOLBAR_FORMAT_VERT
:
2565 frame
->SetStatusText("Align items vertically");
2567 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2568 frame
->SetStatusText("Left-align items");
2570 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2571 frame
->SetStatusText("Right-align items");
2573 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2574 frame
->SetStatusText("Top-align items");
2576 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2577 frame
->SetStatusText("Bottom-align items");
2579 case TOOLBAR_COPY_SIZE
:
2580 frame
->SetStatusText("Copy size from first selection");
2582 case TOOLBAR_TO_FRONT
:
2583 frame
->SetStatusText("Put image to front");
2585 case TOOLBAR_TO_BACK
:
2586 frame
->SetStatusText("Put image to back");
2589 frame
->SetStatusText("Display help contents");
2595 else frame
->SetStatusText("");
2598 bool ResourceEditorDialogTester::ProcessEvent(wxEvent
& event
)
2600 if (event
.IsCommandEvent() && event
.GetId() != wxID_OK
&& event
.GetId() != wxID_CANCEL
)
2606 return wxDialog::ProcessEvent(event
);
2609 static int gs_LabelInsertionCount
= 0;
2611 // Convert old WXRs to new
2612 bool wxResourceManager::ConvertWXRs()
2614 gs_LabelInsertionCount
= 0;
2615 m_symbolIdCounter
= 20000;
2617 wxString currentPath
= wxGetCwd();
2618 wxString oldWXRPath
, newWXRPath
;
2620 wxDirDialog
dialog(NULL
, wxT("Choose directory for old WXRs"), currentPath
);
2622 if (dialog
.ShowModal() == wxID_OK
)
2624 oldWXRPath
= dialog
.GetPath();
2629 wxDirDialog
dialog2(NULL
, wxT("Choose directory for new WXRs"), oldWXRPath
);
2631 if (dialog2
.ShowModal() == wxID_OK
)
2633 newWXRPath
= dialog2
.GetPath();
2638 if (newWXRPath
== oldWXRPath
)
2640 wxMessageBox(wxT("Sorry, the directories must be different."));
2644 wxDir
dir(oldWXRPath
);
2645 if (!dir
.IsOpened())
2648 wxArrayString stringArray
;
2651 bool ok
= dir
.GetFirst(& filename
, wxT("*.wxr"));
2654 stringArray
.Add(filename
);
2656 ok
= dir
.GetNext(& filename
);
2659 // Pop up a progress dialog
2660 wxProgressDialog
progressDialog(wxT("Converting WXR files"), wxT("Converting files..."));
2663 for (i
= 0; i
< stringArray
.Count(); i
++)
2665 progressDialog
.Update((int) (100.0 * ((double) i
/ (double) stringArray
.Count())));
2667 filename
= stringArray
[i
];
2668 wxString oldPath
= oldWXRPath
+ wxString(wxFILE_SEP_PATH
) + filename
;
2669 wxString newPath
= newWXRPath
+ wxString(wxFILE_SEP_PATH
) + filename
;
2671 DoConvertWXR(oldPath
, newPath
);
2675 msg
.Printf(wxT("Dialog Editor inserted %d labels."), gs_LabelInsertionCount
);
2681 bool wxResourceManager::DoConvertWXR(const wxString
& oldPath
, const wxString
& newPath
)
2684 if (!Clear(TRUE
, FALSE
))
2687 m_symbolTable
.AddStandardSymbols();
2689 if (!m_resourceTable
.ParseResourceFile(oldPath
))
2692 msg
.Printf(wxT("Could not read file %s"), (const char*) oldPath
);
2693 wxMessageBox(msg
, "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
2696 m_currentFilename
= oldPath
;
2698 //SetFrameTitle(m_currentFilename);
2700 //UpdateResourceList();
2702 // Construct include filename from this file
2703 m_symbolFilename
= m_currentFilename
;
2705 wxStripExtension(m_symbolFilename
);
2706 m_symbolFilename
+= wxT(".h");
2708 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
2713 // Set the id counter to the last known id
2714 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
2717 // Now check in case some (or all) resources don't have resource ids, or they
2718 // don't match the .h file, or something of that nature.
2719 bool altered
= RepairResourceIds();
2721 // Do any necessary changes to the resources
2722 m_resourceTable
.BeginFind();
2724 while ((node
= m_resourceTable
.Next()))
2726 wxItemResource
*res
= (wxItemResource
*)node
->Data();
2727 ChangeOldToNewResource(NULL
, res
);
2730 // Change the filename before saving
2732 m_currentFilename
= newPath
;
2733 m_symbolFilename
= m_currentFilename
;
2734 wxStripExtension(m_symbolFilename
);
2735 m_symbolFilename
+= wxT(".h");
2747 bool wxResourceManager::ChangeOldToNewResource(wxItemResource
* parent
, wxItemResource
* res
)
2749 // Change these according to your needs
2751 // Change all fonts to use system defaults for fonts, colours etc.
2752 static bool s_useSystemDefaultsAlways
= FALSE
; // TRUE;
2754 // Increase dialog height by this amount (wxWin 2 uses dialog client size now)
2755 static int s_increaseDialogSize
= -18;
2757 // How many points to decrease the font sizes by, since
2758 // wxWin 2 fonts are larger in Windows
2759 static int s_decreaseFontSize
= 3;
2761 wxString
itemType(res
->GetType());
2763 wxFont font
= res
->GetFont();
2765 if ((s_decreaseFontSize
) > 0 && font
.Ok())
2767 wxFont newFont
= wxFont(font
.GetPointSize() - s_decreaseFontSize
,
2768 font
.GetFamily(), font
.GetStyle(), font
.GetWeight(),
2769 font
.GetUnderlined(), font
.GetFaceName());
2770 res
->SetFont(newFont
);
2773 if (itemType
== wxT("wxDialogBox") || itemType
== wxT("wxDialog") || itemType
== wxT("wxPanel"))
2775 if (itemType
== wxT("wxDialogBox"))
2776 res
->SetType(wxT("wxDialog"));
2778 if (itemType
== wxT("wxDialogBox") || itemType
== wxT("wxDialog"))
2780 // Only change the height if it has a caption, i.e. it's going to be
2781 // used as a proper dialog and not a panel
2782 if (res
->GetStyle() & wxCAPTION
)
2783 res
->SetSize(res
->GetX(), res
->GetY(), res
->GetWidth(), res
->GetHeight() + s_increaseDialogSize
);
2786 if (s_useSystemDefaultsAlways
)
2787 res
->SetResourceStyle(res
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
2789 if (res
->GetValue1())
2790 res
->SetStyle(res
->GetStyle() | wxDIALOG_MODAL
);
2792 wxNode
*node
= res
->GetChildren().First();
2795 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2797 ChangeOldToNewResource(res
, child
);
2798 node
= node
->Next();
2801 else if (itemType
== wxT("wxMessage"))
2803 // Figure out if this is a bitmap or text message
2804 if (res
->GetValue4().IsEmpty())
2805 res
->SetType(wxT("wxStaticText"));
2807 res
->SetType(wxT("wxStaticBitmap"));
2809 else if (itemType
== wxT("wxButton"))
2811 // Figure out if this is a bitmap or text message
2812 if (res
->GetValue4().IsEmpty())
2816 res
->SetType(wxT("wxBitmapButton"));
2818 else if (itemType
== wxT("wxGroupBox"))
2820 res
->SetType(wxT("wxStaticBox"));
2822 else if (itemType
== wxT("wxText"))
2824 res
->SetType(wxT("wxTextCtrl"));
2826 else if (itemType
== wxT("wxMultiText"))
2828 res
->SetType(wxT("wxTextCtrl"));
2829 res
->SetStyle(res
->GetStyle() | wxTE_MULTILINE
);
2832 itemType
= res
->GetType();
2834 if (!res
->GetTitle().IsEmpty() &&
2835 (itemType
== wxT("wxTextCtrl") || itemType
== wxT("wxChoice") ||
2836 itemType
== wxT("wxComboBox") || itemType
== wxT("wxGauge") ||
2837 itemType
== wxT("wxListBox")))
2839 // Insert a label control resource, adjusting the size of this
2840 // resource accordingly.
2841 InsertLabelResource(parent
, res
);
2847 // Insert a label control resource, adjusting the size of this
2848 // resource accordingly.
2849 bool wxResourceManager::InsertLabelResource(wxItemResource
* parent
, wxItemResource
* res
)
2851 gs_LabelInsertionCount
++;
2853 bool isHorizontal
= TRUE
;
2855 // Determine panel orientation
2856 if (parent
->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL
)
2858 isHorizontal
= FALSE
;
2860 else if (parent
->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL
)
2862 isHorizontal
= TRUE
;
2866 if (res
->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL
)
2868 isHorizontal
= FALSE
;
2870 else if (res
->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL
)
2872 isHorizontal
= TRUE
;
2875 int x
= res
->GetX();
2876 int y
= res
->GetY();
2877 int width
= res
->GetWidth();
2878 int height
= res
->GetHeight();
2880 // Find the font specified
2882 if (res
->GetFont().Ok())
2883 font
= res
->GetFont();
2885 font
= parent
->GetFont();
2887 if (!font
.Ok() || (parent
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
))
2888 font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
2891 wxCoord labelWidth
, labelHeight
;
2894 dc
.GetTextExtent(res
->GetTitle(), & labelWidth
, & labelHeight
);
2896 // Vert/horizontal margin between controls
2906 x
+= labelWidth
+ margin
;
2907 width
-= (labelWidth
+ margin
);
2911 y
+= labelHeight
+ margin
;
2912 height
-= (labelHeight
+ margin
);
2915 if (res
->GetType() == wxT("wxTextCtrl"))
2919 else if (res
->GetType() == wxT("wxChoice") || res
->GetType() == wxT("wxComboBox"))
2925 res
->SetSize(x
, y
, width
, height
);
2927 wxItemResource
* staticItem
= new wxItemResource
;
2928 staticItem
->SetSize(labelX
, labelY
, labelWidth
, labelHeight
);
2929 staticItem
->SetTitle(res
->GetTitle());
2930 staticItem
->SetFont(font
);
2931 staticItem
->SetStyle(0);
2932 staticItem
->SetType(wxT("wxStaticText"));
2934 wxString newSymbolName
;
2935 int newId
= GenerateWindowId(wxT("ID_STATICTEXT"), newSymbolName
) ;
2936 staticItem
->SetId(newId
);
2938 newSymbolName
= res
->GetName() + wxT("_Label");
2939 staticItem
->SetName(newSymbolName
);
2940 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
2942 wxNode
* node
= parent
->GetChildren().Member(res
);
2944 wxASSERT( (node
!= NULL
) );
2946 parent
->GetChildren().Insert(node
, staticItem
);
2948 // Remove the title from this resource since we've replaced it
2949 // with a static text control
2950 res
->SetTitle(wxEmptyString
);