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(__WXMSW__)
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
;
154 wxGetHomeDir( &m_optionsResourceFilename
);
155 m_optionsResourceFilename
+= "/.dialogedrc";
161 m_helpController
= new wxHelpController
;
162 m_helpController
->Initialize("dialoged");
165 m_popupMenu
= new wxMenu
;
166 m_popupMenu
->Append(OBJECT_MENU_TITLE
, "WIDGET TYPE");
167 m_popupMenu
->AppendSeparator();
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 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
180 // Initialize the image list icons
182 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
183 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
184 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
185 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
187 wxIcon
icon1( dialog_xpm
);
188 wxIcon
icon2( folder1_xpm
);
189 wxIcon
icon3( folder2_xpm
);
190 wxIcon
icon4( buttonsm_xpm
);
192 m_imageList
.Add(icon1
);
193 m_imageList
.Add(icon2
);
194 m_imageList
.Add(icon3
);
195 m_imageList
.Add(icon4
);
197 m_symbolTable
.AddStandardSymbols();
202 bool wxResourceManager::LoadOptions()
204 wxConfig
config("DialogEd", "wxWindows");
206 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
207 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
208 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
209 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
210 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
211 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
212 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
213 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
218 bool wxResourceManager::SaveOptions()
220 wxConfig
config("DialogEd", "wxWindows");
222 config
.Write("editorWindowX", (long) m_resourceEditorWindowSize
.x
);
223 config
.Write("editorWindowY", (long) m_resourceEditorWindowSize
.y
);
224 config
.Write("editorWindowWidth", (long) m_resourceEditorWindowSize
.width
);
225 config
.Write("editorWindowHeight", (long) m_resourceEditorWindowSize
.height
);
226 config
.Write("propertyWindowX", (long) m_propertyWindowSize
.x
);
227 config
.Write("propertyWindowY", (long) m_propertyWindowSize
.y
);
228 config
.Write("propertyWindowWidth", (long) m_propertyWindowSize
.width
);
229 config
.Write("propertyWindowHeight", (long) m_propertyWindowSize
.height
);
234 // Show or hide the resource editor frame, which displays a list
235 // of resources with ability to edit them.
236 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
242 m_editorFrame
->Iconize(FALSE
);
243 m_editorFrame
->Show(TRUE
);
246 m_editorFrame
= OnCreateEditorFrame(title
);
248 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
249 m_editorFrame
->SetMenuBar(menuBar
);
251 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
252 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
253 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
255 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
257 m_editorResourceTree
->SetImageList(& m_imageList
);
259 // Constraints for toolbar
260 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
261 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
262 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
263 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
264 c
->bottom
.Unconstrained();
265 c
->width
.Unconstrained();
266 c
->height
.Absolute(28);
267 m_editorToolBar
->SetConstraints(c
);
269 // Constraints for listbox
270 c
= new wxLayoutConstraints
;
271 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
272 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
273 c
->right
.Absolute (150);
274 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
275 c
->width
.Unconstrained();
276 c
->height
.Unconstrained();
277 m_editorResourceTree
->SetConstraints(c
);
279 // Constraints for panel
280 c
= new wxLayoutConstraints
;
281 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
282 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
283 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
284 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
285 c
->width
.Unconstrained();
286 c
->height
.Unconstrained();
287 m_editorPanel
->SetConstraints(c
);
289 // Constraints for control list (bottom window)
290 c
= new wxLayoutConstraints
;
291 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
292 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
293 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
294 c
->width
.Unconstrained();
295 #if defined(__WXGTK__) || defined(__WXMOTIF__)
296 c
->height
.Absolute(120);
298 c
->height
.Absolute(60);
301 m_editorControlList
->SetConstraints(c
);
303 m_editorFrame
->SetAutoLayout(TRUE
);
305 UpdateResourceList();
307 m_editorFrame
->Show(TRUE
);
312 if (m_editorFrame
->Close())
314 m_editorFrame
= NULL
;
315 m_editorPanel
= NULL
;
321 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
325 if (filename
== wxString(""))
326 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
329 wxString
str("wxWindows Dialog Editor - ");
330 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
332 m_editorFrame
->SetTitle(str
);
337 bool wxResourceManager::Save()
339 if (m_currentFilename
== wxString(""))
342 return Save(m_currentFilename
);
345 bool wxResourceManager::Save(const wxString
& filename
)
347 // Ensure all visible windows are saved to their resources
348 m_currentFilename
= filename
;
349 SetFrameTitle(m_currentFilename
);
350 InstantiateAllResourcesFromWindows();
351 if (m_resourceTable
.Save(filename
))
353 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
361 bool wxResourceManager::SaveAs()
363 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
364 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
, wxTheApp
->GetTopWindow()));
366 if (s
.IsNull() || s
== "")
369 m_currentFilename
= s
;
370 wxStripExtension(m_currentFilename
);
371 m_currentFilename
+= ".wxr";
373 // Construct include filename from this file
374 m_symbolFilename
= m_currentFilename
;
376 wxStripExtension(m_symbolFilename
);
377 m_symbolFilename
+= ".h";
379 Save(m_currentFilename
);
383 bool wxResourceManager::SaveIfModified()
390 bool wxResourceManager::Load(const wxString
& filename
)
392 return New(TRUE
, filename
);
395 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
397 if (!Clear(TRUE
, FALSE
))
400 m_symbolTable
.AddStandardSymbols();
404 wxString str
= filename
;
405 if (str
== wxString(""))
407 wxString
f(wxFileSelector("Open resource file", wxGetCwd(), wxEmptyString
, "wxr", "*.wxr", 0, wxTheApp
->GetTopWindow()));
408 if (!f
.IsNull() && f
!= "")
414 if (!m_resourceTable
.ParseResourceFile(str
))
416 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
419 m_currentFilename
= str
;
421 SetFrameTitle(m_currentFilename
);
423 UpdateResourceList();
425 // Construct include filename from this file
426 m_symbolFilename
= m_currentFilename
;
428 wxStripExtension(m_symbolFilename
);
429 m_symbolFilename
+= ".h";
431 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
433 wxString
str("Could not find include file ");
434 str
+= m_symbolFilename
;
435 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
436 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
437 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
439 m_symbolIdCounter
= 99;
443 // Set the id counter to the last known id
444 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
447 // Now check in case some (or all) resources don't have resource ids, or they
448 // don't match the .h file, or something of that nature.
449 bool altered
= RepairResourceIds();
452 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
453 "Dialog Editor Warning", wxOK
);
464 m_currentFilename
= "";
471 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
473 wxPropertyInfo::CloseWindow();
475 if (!force
&& Modified())
477 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
481 if (!SaveIfModified())
487 ClearCurrentDialog();
488 DisassociateWindows();
490 m_symbolTable
.Clear();
491 m_resourceTable
.ClearTable();
492 UpdateResourceList();
497 bool wxResourceManager::DisassociateWindows()
499 m_resourceTable
.BeginFind();
501 while ((node
= m_resourceTable
.Next()))
503 wxItemResource
*res
= (wxItemResource
*)node
->Data();
504 DisassociateResource(res
);
510 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
512 if (!m_resourceAssociations
.Get((long)resource
))
513 m_resourceAssociations
.Put((long)resource
, win
);
515 wxNode
*node
= resource
->GetChildren().First();
516 wxNode
* node2
= win
->GetChildren().First();
517 while (node
&& node2
)
519 wxItemResource
*child
= (wxItemResource
*)node
->Data();
520 wxWindow
* childWindow
= (wxWindow
*) node2
->Data();
522 if (child
->GetId() != childWindow
->GetId())
525 msg
.Printf("AssociateResource: error when associating child window %ld with resource %ld", child
->GetId(), childWindow
->GetId());
526 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
528 else if (childWindow
->GetName() != child
->GetName())
531 msg
.Printf("AssociateResource: error when associating child window with resource %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
532 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
536 AssociateResource(child
, childWindow
);
539 // New code to avoid the problem of duplicate ids and names. We simply
540 // traverse the child windows and child resources in parallel,
541 // checking for any mismatch.
543 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
545 // childWindow = win->FindWindow(child->GetName());
546 childWindow
= win
->FindWindow(child
->GetId());
548 AssociateResource(child
, childWindow
);
552 msg
.Printf("AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
553 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
557 node2
= node2
->Next();
561 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
563 wxWindow
*win
= FindWindowForResource(resource
);
567 // Disassociate children of window
568 wxNode
*node
= win
->GetChildren().First();
571 wxWindow
*child
= (wxWindow
*)node
->Data();
572 if (child
->IsKindOf(CLASSINFO(wxControl
)))
573 DisassociateResource(child
);
577 RemoveSelection(win
);
578 m_resourceAssociations
.Delete((long)resource
);
582 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
584 wxItemResource
*res
= FindResourceForWindow(win
);
586 return DisassociateResource(res
);
591 // Saves the window info into the resource, and deletes the
592 // handler. Doesn't actually disassociate the window from
593 // the resources. Replaces OnClose.
594 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
596 wxItemResource
*res
= FindResourceForWindow(win
);
598 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
600 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
601 win
->PopEventHandler();
603 // Now reset all child event handlers
604 wxNode
*node
= win
->GetChildren().First();
607 wxWindow
*child
= (wxWindow
*)node
->Data();
608 wxEvtHandler
*childHandler
= child
->GetEventHandler();
609 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
611 child
->PopEventHandler(TRUE
);
619 win
->PopEventHandler(TRUE
);
622 // Save the information
623 InstantiateResourceFromWindow(res
, win
, TRUE
);
625 // DisassociateResource(win);
630 // Destroys the window. If this is the 'current' panel, NULLs the
632 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
634 bool clearDisplay
= FALSE
;
635 if (m_editorPanel
->m_childWindow
== win
)
637 m_editorPanel
->m_childWindow
= NULL
;
644 m_editorPanel
->Clear();
649 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
651 m_resourceAssociations
.BeginFind();
653 while ((node
= m_resourceAssociations
.Next()))
655 wxWindow
*w
= (wxWindow
*)node
->Data();
658 return (wxItemResource
*)node
->GetKeyInteger();
664 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
666 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
670 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
674 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
677 if (!m_resourceTable
.FindResource(buf
))
682 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
684 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
685 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
686 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
687 wxDEFAULT_FRAME_STYLE
);
689 frame
->CreateStatusBar(1);
691 frame
->SetAutoLayout(TRUE
);
693 frame
->SetIcon(wxIcon("DIALOGEDICON"));
698 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
700 wxMenuBar
*menuBar
= new wxMenuBar
;
702 wxMenu
*fileMenu
= new wxMenu
;
703 fileMenu
->Append(RESED_NEW_DIALOG
, "New &Dialog", "Create a new dialog");
704 fileMenu
->AppendSeparator();
705 fileMenu
->Append(wxID_NEW
, "&New Project", "Clear the current project");
706 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
707 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
708 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
709 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
710 fileMenu
->AppendSeparator();
711 fileMenu
->Append(RESED_CONVERT_WXRS
, "Convert Old &Resources...", "Convert old resources to new");
712 fileMenu
->AppendSeparator();
713 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
715 wxMenu
*editMenu
= new wxMenu
;
716 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
717 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
718 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
720 wxMenu
*helpMenu
= new wxMenu
;
721 helpMenu
->Append(RESED_CONTENTS
, "&Help Topics", "Invokes the on-line help");
722 helpMenu
->AppendSeparator();
723 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
725 menuBar
->Append(fileMenu
, "&File");
726 menuBar
->Append(editMenu
, "&Edit");
727 menuBar
->Append(helpMenu
, "&Help");
732 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
734 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
735 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
742 panel
->SetScrollbars(10, 10, 100, 100);
747 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
749 // Load palette bitmaps
751 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
752 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
753 wxBitmap
ToolbarNewBitmap("NEWTOOL");
754 wxBitmap
ToolbarVertBitmap("VERTTOOL");
755 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
756 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
757 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
758 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
759 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
760 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
761 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
762 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
763 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
764 wxBitmap
ToolbarCopyWidthBitmap("COPYWIDTHTOOL");
765 wxBitmap
ToolbarCopyHeightBitmap("COPYHEIGHTTOOL");
766 wxBitmap
ToolbarDistributeHorizBitmap("DISTHORIZTOOL");
767 wxBitmap
ToolbarDistributeVertBitmap("DISTVERTTOOL");
769 wxBitmap
ToolbarLoadBitmap( load_xpm
);
770 wxBitmap
ToolbarSaveBitmap( save_xpm
);
771 wxBitmap
ToolbarNewBitmap( new_xpm
);
772 wxBitmap
ToolbarVertBitmap( vert_xpm
);
773 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
774 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
775 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
776 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
777 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
778 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
779 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
780 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
781 wxBitmap
ToolbarHelpBitmap( help_xpm
);
782 wxBitmap
ToolbarCopyWidthBitmap(copywdth_xpm
);
783 wxBitmap
ToolbarCopyHeightBitmap(copyhght_xpm
);
784 wxBitmap
ToolbarDistributeHorizBitmap(disthor_xpm
);
785 wxBitmap
ToolbarDistributeVertBitmap(distvert_xpm
);
788 // Create the toolbar
789 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
|wxTB_FLAT
);
790 toolbar
->SetMargins(2, 2);
797 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
802 //toolbar->AddSeparator();
803 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
804 FALSE
, currentX
, -1, NULL
, "New dialog");
805 currentX
+= width
+ dx
;
806 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
807 FALSE
, currentX
, -1, NULL
, "Load");
808 currentX
+= width
+ dx
;
809 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
810 FALSE
, currentX
, -1, NULL
, "Save");
811 currentX
+= width
+ dx
+ gap
;
812 toolbar
->AddSeparator();
813 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
814 FALSE
, currentX
, -1, NULL
, "Horizontal align");
815 currentX
+= width
+ dx
;
816 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
817 FALSE
, currentX
, -1, NULL
, "Top align");
818 currentX
+= width
+ dx
;
819 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
820 FALSE
, currentX
, -1, NULL
, "Bottom align");
821 currentX
+= width
+ dx
;
822 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
823 FALSE
, currentX
, -1, NULL
, "Vertical align");
824 currentX
+= width
+ dx
;
825 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
826 FALSE
, currentX
, -1, NULL
, "Left align");
827 currentX
+= width
+ dx
;
828 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
829 FALSE
, currentX
, -1, NULL
, "Right align");
830 currentX
+= width
+ dx
+ gap
;
831 toolbar
->AddSeparator();
832 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
833 FALSE
, currentX
, -1, NULL
, "Copy size");
834 currentX
+= width
+ dx
;
835 toolbar
->AddTool(TOOLBAR_COPY_WIDTH
, ToolbarCopyWidthBitmap
, wxNullBitmap
,
836 FALSE
, currentX
, -1, NULL
, "Copy width");
837 currentX
+= width
+ dx
;
838 toolbar
->AddTool(TOOLBAR_COPY_HEIGHT
, ToolbarCopyHeightBitmap
, wxNullBitmap
,
839 FALSE
, currentX
, -1, NULL
, "Copy height");
840 currentX
+= width
+ dx
;
841 toolbar
->AddTool(TOOLBAR_DISTRIBUTE_HORIZ
, ToolbarDistributeHorizBitmap
, wxNullBitmap
,
842 FALSE
, currentX
, -1, NULL
, "Distribute horizontally");
843 currentX
+= width
+ dx
;
844 toolbar
->AddTool(TOOLBAR_DISTRIBUTE_VERT
, ToolbarDistributeVertBitmap
, wxNullBitmap
,
845 FALSE
, currentX
, -1, NULL
, "Distribute vertically");
846 currentX
+= width
+ dx
+ gap
;
847 toolbar
->AddSeparator();
848 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
849 FALSE
, currentX
, -1, NULL
, "To front");
850 currentX
+= width
+ dx
;
851 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
852 FALSE
, currentX
, -1, NULL
, "To back");
853 currentX
+= width
+ dx
+ gap
;
855 toolbar
->AddSeparator();
856 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
857 FALSE
, currentX
, -1, NULL
, "Help");
858 currentX
+= width
+ dx
;
865 void wxResourceManager::UpdateResourceList()
867 if (!m_editorResourceTree
)
870 m_editorResourceTree
->SetInvalid(TRUE
);
871 m_editorResourceTree
->DeleteAllItems();
873 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
875 m_resourceTable
.BeginFind();
877 while ((node
= m_resourceTable
.Next()))
879 wxItemResource
*res
= (wxItemResource
*)node
->Data();
880 wxString
resType(res
->GetType());
881 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
883 AddItemsRecursively(id
, res
);
886 m_editorResourceTree
->Expand(id
);
887 m_editorResourceTree
->SetInvalid(FALSE
);
890 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
892 wxString
theString("");
893 theString
= resource
->GetName();
896 wxString
resType(resource
->GetType());
897 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
902 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
904 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
906 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
908 wxNode
*node
= resource
->GetChildren().First();
911 wxItemResource
*res
= (wxItemResource
*)node
->Data();
912 AddItemsRecursively(id
, res
);
916 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
919 bool wxResourceManager::EditSelectedResource()
921 int sel
= m_editorResourceTree
->GetSelection();
924 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
925 wxItemResource
*res
= data
->GetResource();
931 bool wxResourceManager::Edit(wxItemResource
*res
)
933 wxPropertyInfo::CloseWindow();
935 ClearCurrentDialog();
937 wxString
resType(res
->GetType());
938 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
942 wxMessageBox("Should not find panel in wxResourceManager::Edit");
947 // long style = res->GetStyle();
948 // res->SetStyle(style|wxRAISED_BORDER);
950 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
953 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
955 panel
->PushEventHandler(handler
);
957 // res->SetStyle(style);
958 handler
->AddChildHandlers(); // Add event handlers for all controls
959 AssociateResource(res
, panel
);
961 m_editorPanel
->m_childWindow
= panel
;
962 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
966 wxClientDC
dc(m_editorPanel
);
967 m_editorPanel
->DrawTitle(dc
);
972 bool wxResourceManager::CreateNewPanel()
974 wxPropertyInfo::CloseWindow();
976 ClearCurrentDialog();
979 MakeUniqueName("dialog", buf
);
981 wxItemResource
*resource
= new wxItemResource
;
982 resource
->SetType("wxDialog");
983 resource
->SetName(buf
);
984 resource
->SetTitle(buf
);
985 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
986 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
989 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
992 // This is now guaranteed to be unique, so just add to symbol table
993 m_symbolTable
.AddSymbol(newIdName
, id
);
995 m_resourceTable
.AddResource(resource
);
997 wxSize
size(400, 300);
999 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
1000 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
1001 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
1002 m_editorPanel
->m_childWindow
= panel
;
1004 resource
->SetStyle(panel
->GetWindowStyleFlag());
1006 // Store dialog units in resource
1007 size
= panel
->ConvertPixelsToDialog(size
);
1009 resource
->SetSize(10, 10, size
.x
, size
.y
);
1011 // For editing in situ we will need to use the hash table to ensure
1012 // we don't dereference invalid pointers.
1013 // resourceWindowTable.Put((long)resource, panel);
1015 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
1017 panel
->PushEventHandler(handler
);
1019 AssociateResource(resource
, panel
);
1020 UpdateResourceList();
1023 m_editorPanel
->m_childWindow
->Refresh();
1025 // panel->Refresh();
1027 wxClientDC
dc(m_editorPanel
);
1028 m_editorPanel
->DrawTitle(dc
);
1033 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1036 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1041 wxItemResource
*res
= new wxItemResource
;
1042 wxControl
*newItem
= NULL
;
1044 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1046 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1047 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1049 else res
->SetSize(x
, y
, -1, -1);
1051 res
->SetType(iType
);
1055 wxString
itemType(iType
);
1057 if (itemType
== "wxButton")
1059 prefix
= "ID_BUTTON";
1060 MakeUniqueName("button", buf
);
1063 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), wxBU_AUTODRAW
, wxDefaultValidator
, buf
);
1065 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1067 if (itemType
== "wxBitmapButton")
1069 prefix
= "ID_BITMAPBUTTON";
1070 MakeUniqueName("button", buf
);
1072 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), wxBU_AUTODRAW
, wxDefaultValidator
, buf
);
1074 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1076 prefix
= "ID_STATIC";
1077 MakeUniqueName("statictext", buf
);
1080 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1082 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1084 else if (itemType
== "wxStaticBitmap")
1086 prefix
= "ID_STATICBITMAP";
1087 MakeUniqueName("static", buf
);
1089 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1091 else if (itemType
== "wxCheckBox")
1093 prefix
= "ID_CHECKBOX";
1094 MakeUniqueName("checkbox", buf
);
1096 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1098 else if (itemType
== "wxListBox")
1100 prefix
= "ID_LISTBOX";
1101 MakeUniqueName("listbox", buf
);
1103 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1105 else if (itemType
== "wxRadioBox")
1107 prefix
= "ID_RADIOBOX";
1108 MakeUniqueName("radiobox", buf
);
1110 wxString names
[] = { "One", "Two" };
1111 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1112 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1113 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1115 else if (itemType
== "wxRadioButton")
1117 prefix
= "ID_RADIOBUTTON";
1118 MakeUniqueName("radiobutton", buf
);
1120 wxString names
[] = { "One", "Two" };
1121 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1122 0, wxDefaultValidator
, buf
);
1124 else if (itemType
== "wxChoice")
1126 prefix
= "ID_CHOICE";
1127 MakeUniqueName("choice", buf
);
1129 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1131 else if (itemType
== "wxComboBox")
1133 prefix
= "ID_COMBOBOX";
1134 MakeUniqueName("combobox", buf
);
1136 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1138 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1140 prefix
= "ID_STATICBOX";
1141 MakeUniqueName("staticbox", buf
);
1143 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1145 else if (itemType
== "wxGauge")
1147 prefix
= "ID_GAUGE";
1148 MakeUniqueName("gauge", buf
);
1150 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1152 else if (itemType
== "wxSlider")
1154 prefix
= "ID_SLIDER";
1155 MakeUniqueName("slider", buf
);
1157 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1159 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1161 prefix
= "ID_TEXTCTRL";
1162 MakeUniqueName("textctrl", buf
);
1164 res
->SetType("wxTextCtrl");
1165 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1167 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1169 prefix
= "ID_TEXTCTRL";
1170 MakeUniqueName("textctrl", buf
);
1172 res
->SetType("wxTextCtrl");
1173 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1175 else if (itemType
== "wxScrollBar")
1177 prefix
= "ID_SCROLLBAR";
1178 MakeUniqueName("scrollbar", buf
);
1180 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1185 int actualW
, actualH
;
1186 newItem
->GetSize(&actualW
, &actualH
);
1187 wxSize
actualSize(actualW
, actualH
);
1189 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1191 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1193 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1196 int id
= GenerateWindowId(prefix
, newIdName
);
1199 // This is now guaranteed to be unique, so just add to symbol table
1200 m_symbolTable
.AddSymbol(newIdName
, id
);
1202 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1204 res
->SetStyle(newItem
->GetWindowStyleFlag());
1205 AssociateResource(res
, newItem
);
1206 panelResource
->GetChildren().Append(res
);
1208 UpdateResourceList();
1213 void wxResourceManager::ClearCurrentDialog()
1215 if (m_editorPanel
->m_childWindow
)
1217 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1218 DisassociateResource(m_editorPanel
->m_childWindow
);
1219 DeleteWindow(m_editorPanel
->m_childWindow
);
1220 m_editorPanel
->m_childWindow
= NULL
;
1221 m_editorPanel
->Clear();
1225 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1227 if (m_editorPanel
->m_childWindow
)
1229 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1233 // Make sure the resources are up-to-date w.r.t. the window
1234 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1236 ResourceEditorDialogTester
* dialog
= new ResourceEditorDialogTester
;
1237 bool success
= FALSE
;
1238 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1241 dialog
->ShowModal();
1249 // Find the first dialog or panel for which
1250 // there is a selected panel item.
1251 wxWindow
*wxResourceManager::FindParentOfSelection()
1253 m_resourceTable
.BeginFind();
1255 while ((node
= m_resourceTable
.Next()))
1257 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1258 wxWindow
*win
= FindWindowForResource(res
);
1261 wxNode
*node1
= win
->GetChildren().First();
1264 wxControl
*item
= (wxControl
*)node1
->Data();
1265 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1266 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1268 node1
= node1
->Next();
1275 // Format the panel items according to 'flag'
1276 void wxResourceManager::AlignItems(int flag
)
1278 wxWindow
*win
= FindParentOfSelection();
1282 wxNode
*node
= GetSelections().First();
1286 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1287 if (firstSelection
->GetParent() != win
)
1292 firstSelection
->GetPosition(&firstX
, &firstY
);
1293 firstSelection
->GetSize(&firstW
, &firstH
);
1294 int centreX
= (int)(firstX
+ (firstW
/ 2));
1295 int centreY
= (int)(firstY
+ (firstH
/ 2));
1297 while ((node
= node
->Next()))
1299 wxControl
*item
= (wxControl
*)node
->Data();
1300 if (item
->GetParent() == win
)
1303 item
->GetPosition(&x
, &y
);
1304 item
->GetSize(&w
, &h
);
1310 case TOOLBAR_FORMAT_HORIZ
:
1313 newY
= (int)(centreY
- (h
/2.0));
1316 case TOOLBAR_FORMAT_VERT
:
1318 newX
= (int)(centreX
- (w
/2.0));
1322 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1328 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1334 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1336 newX
= firstX
+ firstW
- w
;
1340 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1343 newY
= firstY
+ firstH
- h
;
1351 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1352 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1354 item
->SetSize(newX
, newY
, w
, h
);
1356 // Also update the associated resource
1357 // We need to convert to dialog units if this is not a dialog or panel, but
1358 // the parent resource specifies dialog units.
1359 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1361 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1362 newX
= pt
.x
; newY
= pt
.y
;
1363 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1366 resource
->SetSize(newX
, newY
, w
, h
);
1372 // Copy the first image's size to subsequent images
1373 void wxResourceManager::CopySize(int command
)
1375 bool copyWidth
= (command
== TOOLBAR_COPY_SIZE
|| command
== TOOLBAR_COPY_WIDTH
) ;
1376 bool copyHeight
= (command
== TOOLBAR_COPY_SIZE
|| command
== TOOLBAR_COPY_HEIGHT
) ;
1378 wxWindow
*win
= FindParentOfSelection();
1382 wxNode
*node
= GetSelections().First();
1386 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1387 if (firstSelection
->GetParent() != win
)
1392 firstSelection
->GetPosition(&firstX
, &firstY
);
1393 firstSelection
->GetSize(&firstW
, &firstH
);
1395 while ((node
= node
->Next()))
1397 wxControl
*item
= (wxControl
*)node
->Data();
1398 if (item
->GetParent() == win
)
1400 wxSize sz
= item
->GetSize();
1401 int widthToSet
= (copyWidth
? firstW
: sz
.x
);
1402 int heightToSet
= (copyHeight
? firstH
: sz
.y
);
1404 item
->SetSize(-1, -1, widthToSet
, heightToSet
);
1406 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1407 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1409 widthToSet
= resource
->GetWidth();
1410 heightToSet
= resource
->GetHeight();
1412 // Also update the associated resource
1413 // We need to convert to dialog units if this is not a dialog or panel, but
1414 // the parent resource specifies dialog units.
1415 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1417 wxSize convertedSize
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1419 widthToSet
= convertedSize
.x
;
1421 heightToSet
= convertedSize
.y
;
1423 resource
->SetSize(resource
->GetX(), resource
->GetY(), widthToSet
, heightToSet
);
1429 void wxResourceManager::ToBackOrFront(bool toBack
)
1431 wxWindow
*win
= FindParentOfSelection();
1434 wxItemResource
*winResource
= FindResourceForWindow(win
);
1436 wxNode
*node
= GetSelections().First();
1439 wxControl
*item
= (wxControl
*)node
->Data();
1440 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1441 if (item
->GetParent() == win
)
1443 win
->GetChildren().DeleteObject(item
);
1445 winResource
->GetChildren().DeleteObject(itemResource
);
1448 win
->GetChildren().Insert(item
);
1450 winResource
->GetChildren().Insert(itemResource
);
1454 win
->GetChildren().Append(item
);
1456 winResource
->GetChildren().Append(itemResource
);
1459 node
= node
->Next();
1464 // Distribute controls evenly between first and last
1465 void wxResourceManager::DistributePositions(int command
)
1467 bool horizontal
= (command
== TOOLBAR_DISTRIBUTE_HORIZ
) ;
1469 wxWindow
*win
= FindParentOfSelection();
1473 if (GetSelections().Number() < 3)
1475 wxMessageBox(wxT("Sorry, distributing less than three controls does not make sense."));
1479 wxControl
*firstSelection
= (wxControl
*) GetSelections().First()->Data();
1480 wxControl
*lastSelection
= (wxControl
*) GetSelections().Last()->Data();
1482 // For now, assume the ordering is correct (the user selected the controls in order).
1483 // TODO: explicitly order the selections in terms of increading x or y position.
1485 // Find the total amount of space between all controls
1486 int totalControlSpace
= 0; // How much space the controls take up
1488 wxNode
* node
= GetSelections().First();
1491 wxControl
* control
= (wxControl
*) node
->Data();
1495 control
->GetPosition(&x
, &y
);
1496 control
->GetSize(&w
, &h
);
1498 // Don't include the space taken up by the first and last controls.
1499 if (control
!= firstSelection
&& control
!= lastSelection
)
1502 totalControlSpace
+= w
;
1504 totalControlSpace
+= h
;
1507 node
= node
->Next();
1511 int firstX
, firstY
, lastX
, lastY
;
1512 int firstW
, firstH
, lastW
, lastH
;
1513 firstSelection
->GetPosition(&firstX
, &firstY
);
1514 firstSelection
->GetSize(&firstW
, &firstH
);
1516 lastSelection
->GetPosition(&lastX
, &lastY
);
1517 lastSelection
->GetSize(&lastW
, &lastH
);
1522 |===| |====| |======| |==|
1526 int spacing
, currentPos
;
1529 spacing
= ((lastX
- (firstX
+ firstW
)) - totalControlSpace
) / (GetSelections().Number() - 1);
1530 currentPos
= firstX
+ firstW
+ spacing
;
1534 spacing
= ((lastY
- (firstY
+ firstH
)) - totalControlSpace
) / (GetSelections().Number() - 1);
1535 currentPos
= firstY
+ firstH
+ spacing
;
1538 node
= GetSelections().First();
1540 while ((node
= node
->Next()))
1542 wxControl
*item
= (wxControl
*)node
->Data();
1543 wxSize sz
= item
->GetSize();
1544 wxPoint pos
= item
->GetPosition();
1545 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1546 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1548 int controlX
= (horizontal
? currentPos
: pos
.x
);
1549 int controlY
= (horizontal
? pos
.y
: currentPos
);
1551 item
->Move(controlX
, controlY
);
1553 int resX
= controlX
;
1554 int resY
= controlY
;
1556 // Also update the associated resource
1557 // We need to convert to dialog units if this is not a dialog or panel, but
1558 // the parent resource specifies dialog units.
1559 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1561 wxPoint convertedPos
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(resX
, resY
));
1562 resX
= convertedPos
.x
;
1563 resY
= convertedPos
.y
;
1565 resource
->SetSize(resX
, resY
, resource
->GetWidth(), resource
->GetHeight());
1567 currentPos
+= (horizontal
? (sz
.x
+ spacing
) : (sz
.y
+ spacing
));
1572 void wxResourceManager::AddSelection(wxWindow
*win
)
1574 if (!m_selections
.Member(win
))
1575 m_selections
.Append(win
);
1578 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1580 m_selections
.DeleteObject(win
);
1583 void wxResourceManager::DeselectItemIfNecessary(wxWindow
*win
)
1585 if (win
->IsKindOf(CLASSINFO(wxControl
)) && (win
->GetEventHandler() != win
))
1587 // Deselect and refresh window in case we leave selection
1589 wxControl
*item
= (wxControl
*)win
;
1590 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1591 if (childHandler
->IsSelected())
1593 wxResourceManager::GetCurrentResourceManager()->RemoveSelection(item
);
1594 childHandler
->SelectItem(FALSE
);
1596 item
->GetParent()->Refresh();
1602 // Need to search through resource table removing this from
1603 // any resource which has this as a parent.
1604 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1606 m_resourceTable
.BeginFind();
1608 while ((node
= m_resourceTable
.Next()))
1610 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1611 if (thisRes
->GetChildren().Member(res
))
1613 thisRes
->GetChildren().DeleteObject(res
);
1620 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1625 RemoveResourceFromParent(res
);
1627 wxNode
*node
= res
->GetChildren().First();
1630 wxNode
*next
= node
->Next();
1631 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1632 DeleteResource(child
);
1636 // If this is a button or message resource, delete the
1637 // associate bitmap resource if not being used.
1638 wxString
resType(res
->GetType());
1640 /* shouldn't have to do this now bitmaps are ref-counted
1641 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1643 PossiblyDeleteBitmapResource(res->GetValue4());
1647 // Remove symbol from table if appropriate
1648 if (!IsSymbolUsed(res
, res
->GetId()))
1650 m_symbolTable
.RemoveSymbol(res
->GetId());
1653 m_resourceTable
.Delete(res
->GetName());
1659 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1661 DeselectItemIfNecessary(win
);
1663 wxItemResource
*res
= FindResourceForWindow(win
);
1665 DisassociateResource(res
);
1666 DeleteResource(res
);
1667 UpdateResourceList();
1672 // Will eventually have bitmap type information, for different
1674 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1676 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1680 MakeUniqueName("bitmap", buf
);
1681 resource
= new wxItemResource
;
1682 resource
->SetType("wxBitmap");
1683 resource
->SetName(buf
);
1685 // A bitmap resource has one or more children, specifying
1686 // alternative bitmaps.
1687 wxItemResource
*child
= new wxItemResource
;
1688 child
->SetType("wxBitmap");
1689 child
->SetName(filename
);
1690 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1691 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1692 child
->SetValue3(0); // Depth
1693 child
->SetSize(0,0,0,0);
1694 resource
->GetChildren().Append(child
);
1696 m_resourceTable
.AddResource(resource
);
1698 UpdateResourceList();
1701 return resource
->GetName();
1703 return wxEmptyString
;
1706 // Delete the bitmap resource if it isn't being used by another resource.
1707 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1709 if (!IsBitmapResourceUsed(resourceName
))
1711 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1712 DeleteResource(res
);
1713 UpdateResourceList();
1717 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1719 m_resourceTable
.BeginFind();
1721 while ((node
= m_resourceTable
.Next()))
1723 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1724 wxString
resType(res
->GetType());
1725 if (resType
== "wxDialog")
1727 wxNode
*node1
= res
->GetChildren().First();
1730 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1731 wxString
childResType(child
->GetType());
1733 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1734 child
->GetValue4() &&
1735 (strcmp(child
->GetValue4(), resourceName
) == 0))
1737 node1
= node1
->Next();
1744 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1745 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1747 if (!resource
|| (resource
->GetValue4() == ""))
1748 return wxEmptyString
;
1749 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1750 if (!bitmapResource
)
1751 return wxEmptyString
;
1753 wxNode
*node
= bitmapResource
->GetChildren().First();
1756 // Eventually augment this to return a bitmap of the right kind or something...
1757 // Maybe the root of the filename remains the same, so it doesn't matter which we
1758 // pick up. Otherwise how do we specify multiple filenames... too boring...
1759 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1760 return child
->GetName();
1762 //node = node->Next();
1764 return wxEmptyString
;
1767 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1769 m_resourceTable
.BeginFind();
1771 while ((node
= m_resourceTable
.Next()))
1773 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1774 wxString
resType(res
->GetType());
1775 if (resType
== "wxBitmap")
1777 wxNode
*node1
= res
->GetChildren().First();
1780 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1781 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1783 node1
= node1
->Next();
1790 // Is this window identifier symbol in use?
1791 // Let's assume that we can't have 2 names for the same integer id.
1792 // Therefore we can tell by the integer id whether the symbol is
1794 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1796 m_resourceTable
.BeginFind();
1798 while ((node
= m_resourceTable
.Next()))
1800 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1802 wxString
resType(res
->GetType());
1803 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1805 if ((res
!= thisResource
) && (res
->GetId() == id
))
1808 wxNode
*node1
= res
->GetChildren().First();
1811 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1812 if ((child
!= thisResource
) && (child
->GetId() == id
))
1814 node1
= node1
->Next();
1821 // Is this window identifier compatible with the given name? (i.e.
1822 // does it already exist under a different name)
1823 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1825 if (m_symbolTable
.SymbolExists(name
))
1827 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1834 // Change all integer ids that match oldId, to newId.
1835 // This is necessary if an id is changed for one resource - all resources
1837 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1839 m_resourceTable
.BeginFind();
1841 while ((node
= m_resourceTable
.Next()))
1843 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1845 wxString
resType(res
->GetType());
1846 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1848 if (res
->GetId() == oldId
)
1851 wxNode
*node1
= res
->GetChildren().First();
1854 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1855 if (child
->GetId() == oldId
)
1856 child
->SetId(newId
);
1858 node1
= node1
->Next();
1864 // If any resource ids were missing (or their symbol was missing),
1865 // repair them i.e. give them new ids. Returns TRUE if any resource
1866 // needed repairing.
1867 bool wxResourceManager::RepairResourceIds()
1869 bool repaired
= FALSE
;
1871 m_resourceTable
.BeginFind();
1873 while ((node
= m_resourceTable
.Next()))
1875 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1876 wxString
resType(res
->GetType());
1877 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1880 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1882 wxString newSymbolName
;
1883 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1885 if (res
->GetId() == 0)
1888 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1892 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1898 wxNode
*node1
= res
->GetChildren().First();
1901 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1903 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1905 wxString newSymbolName
;
1906 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1908 if (child
->GetId() == 0)
1910 child
->SetId(newId
);
1911 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1915 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1921 node1
= node1
->Next();
1929 // Deletes 'win' and creates a new window from the resource that
1930 // was associated with it. E.g. if you can't change properties on the
1931 // fly, you'll need to delete the window and create it again.
1932 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
, bool instantiateFirst
)
1934 wxItemResource
*resource
= FindResourceForWindow(win
);
1936 // Put the current window properties into the wxItemResource object
1938 wxWindowPropertyInfo
*newInfo
= NULL
;
1941 newInfo
= CreatePropertyInfoForWindow(win
);
1945 // May not always want to copy values back from the resource
1946 if (instantiateFirst
)
1947 info
->InstantiateResource(resource
);
1949 wxWindow
*newWin
= NULL
;
1950 wxWindow
*parent
= win
->GetParent();
1951 wxItemResource
* parentResource
= NULL
;
1953 parentResource
= FindResourceForWindow(parent
);
1955 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1958 newWin
= FindWindowForResource(resource
);
1962 DisassociateResource(resource
);
1963 if (win
->GetEventHandler() != win
)
1964 win
->PopEventHandler(TRUE
);
1967 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1968 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1969 AssociateResource(resource
, newWin
);
1970 UpdateResourceList();
1974 info
->SetPropertyWindow(newWin
);
1982 // Delete resource highlighted in the listbox
1983 bool wxResourceManager::DeleteSelection()
1985 int sel
= m_editorResourceTree
->GetSelection();
1988 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1989 wxItemResource
*res
= data
->GetResource();
1990 wxWindow
*win
= FindWindowForResource(res
);
1993 DeleteResource(win
);
1995 UpdateResourceList();
2004 // Delete resource highlighted in the listbox
2005 bool wxResourceManager::RecreateSelection()
2007 wxNode
*node
= GetSelections().First();
2010 wxControl
*item
= (wxControl
*)node
->Data();
2011 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
2012 wxNode
*next
= node
->Next();
2013 childHandler
->SelectItem(FALSE
);
2015 RemoveSelection(item
);
2017 RecreateWindowFromResource(item
);
2024 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
2029 // Ensures that all currently shown windows are saved to resources,
2030 // e.g. just before writing to a .wxr file.
2031 bool wxResourceManager::InstantiateAllResourcesFromWindows()
2033 m_resourceTable
.BeginFind();
2035 while ((node
= m_resourceTable
.Next()))
2037 wxItemResource
*res
= (wxItemResource
*)node
->Data();
2038 wxString
resType(res
->GetType());
2040 if (resType
== "wxDialog")
2042 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
2044 InstantiateResourceFromWindow(res
, win
, TRUE
);
2046 else if (resType
== "wxPanel")
2048 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
2050 InstantiateResourceFromWindow(res
, win
, TRUE
);
2056 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
2058 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
2059 info
->SetResource(resource
);
2060 info
->InstantiateResource(resource
);
2065 wxNode
*node
= resource
->GetChildren().First();
2068 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2069 wxWindow
*childWindow
= FindWindowForResource(child
);
2074 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
2075 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
2078 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
2079 node
= node
->Next();
2086 // Create a window information object for the give window
2087 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
2089 wxWindowPropertyInfo
*info
= NULL
;
2090 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
2092 info
= new wxScrollBarPropertyInfo(win
);
2094 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
2096 info
= new wxGroupBoxPropertyInfo(win
);
2098 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
2100 info
= new wxCheckBoxPropertyInfo(win
);
2102 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
2104 info
= new wxSliderPropertyInfo(win
);
2106 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
2108 info
= new wxGaugePropertyInfo(win
);
2110 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
2112 info
= new wxListBoxPropertyInfo(win
);
2114 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
2116 info
= new wxRadioBoxPropertyInfo(win
);
2118 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
2120 info
= new wxRadioButtonPropertyInfo(win
);
2122 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
2124 info
= new wxComboBoxPropertyInfo(win
);
2126 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
2128 info
= new wxChoicePropertyInfo(win
);
2130 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
2132 info
= new wxBitmapButtonPropertyInfo(win
);
2134 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
2136 info
= new wxButtonPropertyInfo(win
);
2138 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
2140 info
= new wxStaticBitmapPropertyInfo(win
);
2142 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
2144 info
= new wxStaticTextPropertyInfo(win
);
2146 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
2148 info
= new wxTextPropertyInfo(win
);
2150 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
2152 info
= new wxPanelPropertyInfo(win
);
2156 info
= new wxWindowPropertyInfo(win
);
2161 // Edit the given window
2162 void wxResourceManager::EditWindow(wxWindow
*win
)
2164 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2167 info
->SetResource(FindResourceForWindow(win
));
2168 wxString
str("Editing ");
2169 str
+= win
->GetClassInfo()->GetClassName();
2171 if (win
->GetName() != "")
2172 str
+= win
->GetName();
2174 str
+= "properties";
2175 info
->Edit(NULL
, str
);
2179 // Generate a window id and a first stab at a name
2180 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2182 m_symbolIdCounter
++;
2183 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2184 m_symbolIdCounter
++;
2186 int nameId
= m_symbolIdCounter
;
2189 str
.Printf("%d", nameId
);
2190 idName
= prefix
+ str
;
2192 while (m_symbolTable
.SymbolExists(idName
))
2195 str
.Printf("%d", nameId
);
2196 idName
= prefix
+ str
;
2199 return m_symbolIdCounter
;
2204 * Resource editor frame
2207 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2209 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2210 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2211 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2212 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2213 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2214 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2215 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2216 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2217 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2218 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2219 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2220 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2221 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2222 EVT_MENU(RESED_CONVERT_WXRS
, wxResourceEditorFrame::OnConvertWXRs
)
2223 EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow
)
2226 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2227 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2228 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2233 wxResourceEditorFrame::~wxResourceEditorFrame()
2237 void wxResourceEditorFrame::OnConvertWXRs(wxCommandEvent
& WXUNUSED(event
))
2239 manager
->ConvertWXRs();
2242 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2244 manager
->New(FALSE
);
2247 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2249 manager
->CreateNewPanel();
2252 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2257 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2259 manager
->Clear(TRUE
, FALSE
);
2262 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2267 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2272 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2274 manager
->Clear(TRUE
, FALSE
) ;
2278 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2281 sprintf(buf
, "wxWindows Dialog Editor %.1f\n(c) Julian Smart 1996-1999", wxDIALOG_EDITOR_VERSION
);
2282 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2285 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2287 manager
->TestCurrentDialog(this);
2290 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2293 wxBeginBusyCursor();
2294 manager
->GetHelpController()->LoadFile();
2295 manager
->GetHelpController()->DisplayContents();
2300 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2302 manager
->DeleteSelection();
2305 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2307 manager
->RecreateSelection();
2310 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent
& event
)
2312 wxPropertyInfo::CloseWindow();
2313 manager
->ClearCurrentDialog();
2314 if (manager
->Modified())
2316 if (!manager
->Clear(TRUE
, FALSE
))
2327 manager
->m_resourceEditorWindowSize
.width
= w
;
2328 manager
->m_resourceEditorWindowSize
.height
= h
;
2331 GetPosition(&x
, &y
);
2333 manager
->m_resourceEditorWindowSize
.x
= x
;
2334 manager
->m_resourceEditorWindowSize
.y
= y
;
2336 manager
->SetEditorFrame(NULL
);
2337 manager
->SetEditorToolBar(NULL
);
2343 * Resource editor window that contains the dialog/panel being edited
2346 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2347 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2350 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2352 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2356 m_childWindow
= NULL
;
2358 SetBackgroundColour(* wxWHITE
);
2361 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2365 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2372 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2376 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2379 wxString
str(res
->GetTitle());
2381 GetViewStart(& x
, & y
);
2383 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2385 dc
.SetBackgroundMode(wxTRANSPARENT
);
2386 dc
.SetTextForeground(wxColour(0, 0, 0));
2389 dc
.GetTextExtent(str
, & w
, & h
);
2391 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2401 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2402 // EVT_PAINT(EditorToolBar::OnPaint)
2405 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2407 wxToolBar(frame
, -1, pos
, size
, style
)
2411 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2413 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2417 case TOOLBAR_LOAD_FILE
:
2424 manager
->CreateNewPanel();
2427 case TOOLBAR_SAVE_FILE
:
2435 wxBeginBusyCursor();
2436 manager
->GetHelpController()->DisplayContents();
2441 case TOOLBAR_FORMAT_HORIZ
:
2443 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2446 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2448 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2451 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2453 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2456 case TOOLBAR_FORMAT_VERT
:
2458 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2461 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2463 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2466 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2468 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2471 case TOOLBAR_COPY_SIZE
:
2473 manager
->CopySize(TOOLBAR_COPY_SIZE
);
2476 case TOOLBAR_COPY_WIDTH
:
2478 manager
->CopySize(TOOLBAR_COPY_WIDTH
);
2481 case TOOLBAR_COPY_HEIGHT
:
2483 manager
->CopySize(TOOLBAR_COPY_HEIGHT
);
2486 case TOOLBAR_DISTRIBUTE_HORIZ
:
2488 manager
->DistributePositions(TOOLBAR_DISTRIBUTE_HORIZ
);
2491 case TOOLBAR_DISTRIBUTE_VERT
:
2493 manager
->DistributePositions(TOOLBAR_DISTRIBUTE_VERT
);
2496 case TOOLBAR_TO_BACK
:
2498 manager
->ToBackOrFront(TRUE
);
2501 case TOOLBAR_TO_FRONT
:
2503 manager
->ToBackOrFront(FALSE
);
2512 void EditorToolBar::OnMouseEnter(int toolIndex
)
2514 wxFrame
*frame
= (wxFrame
*)GetParent();
2522 case TOOLBAR_LOAD_FILE
:
2523 frame
->SetStatusText("Load project file");
2525 case TOOLBAR_SAVE_FILE
:
2526 frame
->SetStatusText("Save project file");
2529 frame
->SetStatusText("Create a new resource");
2531 case TOOLBAR_FORMAT_HORIZ
:
2532 frame
->SetStatusText("Align items horizontally");
2534 case TOOLBAR_FORMAT_VERT
:
2535 frame
->SetStatusText("Align items vertically");
2537 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2538 frame
->SetStatusText("Left-align items");
2540 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2541 frame
->SetStatusText("Right-align items");
2543 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2544 frame
->SetStatusText("Top-align items");
2546 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2547 frame
->SetStatusText("Bottom-align items");
2549 case TOOLBAR_COPY_SIZE
:
2550 frame
->SetStatusText("Copy size from first selection");
2552 case TOOLBAR_TO_FRONT
:
2553 frame
->SetStatusText("Put image to front");
2555 case TOOLBAR_TO_BACK
:
2556 frame
->SetStatusText("Put image to back");
2559 frame
->SetStatusText("Display help contents");
2565 else frame
->SetStatusText("");
2568 bool ResourceEditorDialogTester::ProcessEvent(wxEvent
& event
)
2570 if (event
.IsCommandEvent() && event
.GetId() != wxID_OK
&& event
.GetId() != wxID_CANCEL
)
2576 return wxDialog::ProcessEvent(event
);
2579 static int gs_LabelInsertionCount
= 0;
2581 // Convert old WXRs to new
2582 bool wxResourceManager::ConvertWXRs()
2584 gs_LabelInsertionCount
= 0;
2585 m_symbolIdCounter
= 20000;
2587 wxString currentPath
= wxGetCwd();
2588 wxString oldWXRPath
, newWXRPath
;
2590 wxDirDialog
dialog(NULL
, wxT("Choose directory for old WXRs"), currentPath
);
2592 if (dialog
.ShowModal() == wxID_OK
)
2594 oldWXRPath
= dialog
.GetPath();
2599 wxDirDialog
dialog2(NULL
, wxT("Choose directory for new WXRs"), oldWXRPath
);
2601 if (dialog2
.ShowModal() == wxID_OK
)
2603 newWXRPath
= dialog2
.GetPath();
2608 if (newWXRPath
== oldWXRPath
)
2610 wxMessageBox(wxT("Sorry, the directories must be different."));
2614 wxDir
dir(oldWXRPath
);
2615 if (!dir
.IsOpened())
2618 wxArrayString stringArray
;
2621 bool ok
= dir
.GetFirst(& filename
, wxT("*.wxr"));
2624 stringArray
.Add(filename
);
2626 ok
= dir
.GetNext(& filename
);
2629 // Pop up a progress dialog
2630 wxProgressDialog
progressDialog(wxT("Converting WXR files"), wxT("Converting files..."));
2633 for (i
= 0; i
< stringArray
.Count(); i
++)
2635 progressDialog
.Update((int) (100.0 * ((double) i
/ (double) stringArray
.Count())));
2637 filename
= stringArray
[i
];
2638 wxString oldPath
= oldWXRPath
+ wxString(wxFILE_SEP_PATH
) + filename
;
2639 wxString newPath
= newWXRPath
+ wxString(wxFILE_SEP_PATH
) + filename
;
2641 DoConvertWXR(oldPath
, newPath
);
2645 msg
.Printf(wxT("Dialog Editor inserted %d labels."), gs_LabelInsertionCount
);
2651 bool wxResourceManager::DoConvertWXR(const wxString
& oldPath
, const wxString
& newPath
)
2654 if (!Clear(TRUE
, FALSE
))
2657 m_symbolTable
.AddStandardSymbols();
2659 if (!m_resourceTable
.ParseResourceFile(oldPath
))
2662 msg
.Printf(wxT("Could not read file %s"), (const char*) oldPath
);
2663 wxMessageBox(msg
, "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
2666 m_currentFilename
= oldPath
;
2668 //SetFrameTitle(m_currentFilename);
2670 //UpdateResourceList();
2672 // Construct include filename from this file
2673 m_symbolFilename
= m_currentFilename
;
2675 wxStripExtension(m_symbolFilename
);
2676 m_symbolFilename
+= wxT(".h");
2678 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
2683 // Set the id counter to the last known id
2684 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
2687 // Now check in case some (or all) resources don't have resource ids, or they
2688 // don't match the .h file, or something of that nature.
2689 bool altered
= RepairResourceIds();
2691 // Do any necessary changes to the resources
2692 m_resourceTable
.BeginFind();
2694 while ((node
= m_resourceTable
.Next()))
2696 wxItemResource
*res
= (wxItemResource
*)node
->Data();
2697 ChangeOldToNewResource(NULL
, res
);
2700 // Change the filename before saving
2702 m_currentFilename
= newPath
;
2703 m_symbolFilename
= m_currentFilename
;
2704 wxStripExtension(m_symbolFilename
);
2705 m_symbolFilename
+= wxT(".h");
2717 bool wxResourceManager::ChangeOldToNewResource(wxItemResource
* parent
, wxItemResource
* res
)
2719 // Change these according to your needs
2721 // Change all fonts to use system defaults for fonts, colours etc.
2722 static bool s_useSystemDefaultsAlways
= FALSE
; // TRUE;
2724 // Increase dialog height by this amount (wxWin 2 uses dialog client size now)
2725 static int s_increaseDialogSize
= -18;
2727 // How many points to decrease the font sizes by, since
2728 // wxWin 2 fonts are larger in Windows
2729 static int s_decreaseFontSize
= 3;
2731 wxString
itemType(res
->GetType());
2733 wxFont font
= res
->GetFont();
2735 if ((s_decreaseFontSize
) > 0 && font
.Ok())
2737 wxFont newFont
= wxFont(font
.GetPointSize() - s_decreaseFontSize
,
2738 font
.GetFamily(), font
.GetStyle(), font
.GetWeight(),
2739 font
.GetUnderlined(), font
.GetFaceName());
2740 res
->SetFont(newFont
);
2743 if (itemType
== wxT("wxDialogBox") || itemType
== wxT("wxDialog") || itemType
== wxT("wxPanel"))
2745 if (itemType
== wxT("wxDialogBox"))
2746 res
->SetType(wxT("wxDialog"));
2748 if (itemType
== wxT("wxDialogBox") || itemType
== wxT("wxDialog"))
2750 // Only change the height if it has a caption, i.e. it's going to be
2751 // used as a proper dialog and not a panel
2752 if (res
->GetStyle() & wxCAPTION
)
2753 res
->SetSize(res
->GetX(), res
->GetY(), res
->GetWidth(), res
->GetHeight() + s_increaseDialogSize
);
2756 if (s_useSystemDefaultsAlways
)
2757 res
->SetResourceStyle(res
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
2759 if (res
->GetValue1())
2760 res
->SetStyle(res
->GetStyle() | wxDIALOG_MODAL
);
2762 wxNode
*node
= res
->GetChildren().First();
2765 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2767 ChangeOldToNewResource(res
, child
);
2768 node
= node
->Next();
2771 else if (itemType
== wxT("wxMessage"))
2773 // Figure out if this is a bitmap or text message
2774 if (res
->GetValue4().IsEmpty())
2775 res
->SetType(wxT("wxStaticText"));
2777 res
->SetType(wxT("wxStaticBitmap"));
2779 else if (itemType
== wxT("wxButton"))
2781 // Figure out if this is a bitmap or text message
2782 if (res
->GetValue4().IsEmpty())
2786 res
->SetType(wxT("wxBitmapButton"));
2788 else if (itemType
== wxT("wxGroupBox"))
2790 res
->SetType(wxT("wxStaticBox"));
2792 else if (itemType
== wxT("wxText"))
2794 res
->SetType(wxT("wxTextCtrl"));
2796 else if (itemType
== wxT("wxMultiText"))
2798 res
->SetType(wxT("wxTextCtrl"));
2799 res
->SetStyle(res
->GetStyle() | wxTE_MULTILINE
);
2802 itemType
= res
->GetType();
2804 if (!res
->GetTitle().IsEmpty() &&
2805 (itemType
== wxT("wxTextCtrl") || itemType
== wxT("wxChoice") ||
2806 itemType
== wxT("wxComboBox") || itemType
== wxT("wxGauge") ||
2807 itemType
== wxT("wxListBox")))
2809 // Insert a label control resource, adjusting the size of this
2810 // resource accordingly.
2811 InsertLabelResource(parent
, res
);
2817 // Insert a label control resource, adjusting the size of this
2818 // resource accordingly.
2819 bool wxResourceManager::InsertLabelResource(wxItemResource
* parent
, wxItemResource
* res
)
2821 gs_LabelInsertionCount
++;
2823 bool isHorizontal
= TRUE
;
2825 // Determine panel orientation
2826 if (parent
->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL
)
2828 isHorizontal
= FALSE
;
2830 else if (parent
->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL
)
2832 isHorizontal
= TRUE
;
2836 if (res
->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL
)
2838 isHorizontal
= FALSE
;
2840 else if (res
->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL
)
2842 isHorizontal
= TRUE
;
2845 int x
= res
->GetX();
2846 int y
= res
->GetY();
2847 int width
= res
->GetWidth();
2848 int height
= res
->GetHeight();
2850 // Find the font specified
2852 if (res
->GetFont().Ok())
2853 font
= res
->GetFont();
2855 font
= parent
->GetFont();
2857 if (!font
.Ok() || (parent
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
))
2858 font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
2861 wxCoord labelWidth
, labelHeight
;
2864 dc
.GetTextExtent(res
->GetTitle(), & labelWidth
, & labelHeight
);
2866 // Vert/horizontal margin between controls
2876 x
+= labelWidth
+ margin
;
2877 width
-= (labelWidth
+ margin
);
2881 y
+= labelHeight
+ margin
;
2882 height
-= (labelHeight
+ margin
);
2885 if (res
->GetType() == wxT("wxTextCtrl"))
2889 else if (res
->GetType() == wxT("wxChoice") || res
->GetType() == wxT("wxComboBox"))
2895 res
->SetSize(x
, y
, width
, height
);
2897 wxItemResource
* staticItem
= new wxItemResource
;
2898 staticItem
->SetSize(labelX
, labelY
, labelWidth
, labelHeight
);
2899 staticItem
->SetTitle(res
->GetTitle());
2900 staticItem
->SetFont(font
);
2901 staticItem
->SetStyle(0);
2902 staticItem
->SetType(wxT("wxStaticText"));
2904 wxString newSymbolName
;
2905 int newId
= GenerateWindowId(wxT("ID_STATICTEXT"), newSymbolName
) ;
2906 staticItem
->SetId(newId
);
2908 newSymbolName
= res
->GetName() + wxT("_Label");
2909 staticItem
->SetName(newSymbolName
);
2910 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
2912 wxNode
* node
= parent
->GetChildren().Member(res
);
2914 wxASSERT( (node
!= NULL
) );
2916 parent
->GetChildren().Insert(node
, staticItem
);
2918 // Remove the title from this resource since we've replaced it
2919 // with a static text control
2920 res
->SetTitle(wxEmptyString
);