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_TITLE
, "WIDGET TYPE");
169 m_popupMenu
->AppendSeparator();
170 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
171 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
176 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
178 #if defined(__WXGTK__) || defined(__WXMOTIF__)
179 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
183 // Initialize the image list icons
185 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
186 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
187 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
188 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
190 wxIcon
icon1( dialog_xpm
);
191 wxIcon
icon2( folder1_xpm
);
192 wxIcon
icon3( folder2_xpm
);
193 wxIcon
icon4( buttonsm_xpm
);
195 m_imageList
.Add(icon1
);
196 m_imageList
.Add(icon2
);
197 m_imageList
.Add(icon3
);
198 m_imageList
.Add(icon4
);
200 m_symbolTable
.AddStandardSymbols();
205 bool wxResourceManager::LoadOptions()
207 wxConfig
config("DialogEd", "wxWindows");
209 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
210 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
211 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
212 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
213 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
214 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
215 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
216 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
221 bool wxResourceManager::SaveOptions()
223 wxConfig
config("DialogEd", "wxWindows");
225 config
.Write("editorWindowX", (long) m_resourceEditorWindowSize
.x
);
226 config
.Write("editorWindowY", (long) m_resourceEditorWindowSize
.y
);
227 config
.Write("editorWindowWidth", (long) m_resourceEditorWindowSize
.width
);
228 config
.Write("editorWindowHeight", (long) m_resourceEditorWindowSize
.height
);
229 config
.Write("propertyWindowX", (long) m_propertyWindowSize
.x
);
230 config
.Write("propertyWindowY", (long) m_propertyWindowSize
.y
);
231 config
.Write("propertyWindowWidth", (long) m_propertyWindowSize
.width
);
232 config
.Write("propertyWindowHeight", (long) m_propertyWindowSize
.height
);
237 // Show or hide the resource editor frame, which displays a list
238 // of resources with ability to edit them.
239 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
245 m_editorFrame
->Iconize(FALSE
);
246 m_editorFrame
->Show(TRUE
);
249 m_editorFrame
= OnCreateEditorFrame(title
);
251 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
252 m_editorFrame
->SetMenuBar(menuBar
);
254 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
255 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
256 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
258 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
260 m_editorResourceTree
->SetImageList(& m_imageList
);
262 // Constraints for toolbar
263 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
264 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
265 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
266 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
267 c
->bottom
.Unconstrained();
268 c
->width
.Unconstrained();
269 c
->height
.Absolute(28);
270 m_editorToolBar
->SetConstraints(c
);
272 // Constraints for listbox
273 c
= new wxLayoutConstraints
;
274 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
275 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
276 c
->right
.Absolute (150);
277 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
278 c
->width
.Unconstrained();
279 c
->height
.Unconstrained();
280 m_editorResourceTree
->SetConstraints(c
);
282 // Constraints for panel
283 c
= new wxLayoutConstraints
;
284 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
285 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
286 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
287 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
288 c
->width
.Unconstrained();
289 c
->height
.Unconstrained();
290 m_editorPanel
->SetConstraints(c
);
292 // Constraints for control list (bottom window)
293 c
= new wxLayoutConstraints
;
294 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
295 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
296 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
297 c
->width
.Unconstrained();
298 #if defined(__WXGTK__) || defined(__WXMOTIF__)
299 c
->height
.Absolute(120);
301 c
->height
.Absolute(60);
304 m_editorControlList
->SetConstraints(c
);
306 m_editorFrame
->SetAutoLayout(TRUE
);
308 UpdateResourceList();
310 m_editorFrame
->Show(TRUE
);
315 if (m_editorFrame
->Close())
317 m_editorFrame
= NULL
;
318 m_editorPanel
= NULL
;
324 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
328 if (filename
== wxString(""))
329 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
332 wxString
str("wxWindows Dialog Editor - ");
333 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
335 m_editorFrame
->SetTitle(str
);
340 bool wxResourceManager::Save()
342 if (m_currentFilename
== wxString(""))
345 return Save(m_currentFilename
);
348 bool wxResourceManager::Save(const wxString
& filename
)
350 // Ensure all visible windows are saved to their resources
351 m_currentFilename
= filename
;
352 SetFrameTitle(m_currentFilename
);
353 InstantiateAllResourcesFromWindows();
354 if (m_resourceTable
.Save(filename
))
356 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
364 bool wxResourceManager::SaveAs()
366 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
367 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
, wxTheApp
->GetTopWindow()));
369 if (s
.IsNull() || s
== "")
372 m_currentFilename
= s
;
373 wxStripExtension(m_currentFilename
);
374 m_currentFilename
+= ".wxr";
376 // Construct include filename from this file
377 m_symbolFilename
= m_currentFilename
;
379 wxStripExtension(m_symbolFilename
);
380 m_symbolFilename
+= ".h";
382 Save(m_currentFilename
);
386 bool wxResourceManager::SaveIfModified()
393 bool wxResourceManager::Load(const wxString
& filename
)
395 return New(TRUE
, filename
);
398 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
400 if (!Clear(TRUE
, FALSE
))
403 m_symbolTable
.AddStandardSymbols();
407 wxString str
= filename
;
408 if (str
== wxString(""))
410 wxString
f(wxFileSelector("Open resource file", wxGetCwd(), wxEmptyString
, "wxr", "*.wxr", 0, wxTheApp
->GetTopWindow()));
411 if (!f
.IsNull() && f
!= "")
417 if (!m_resourceTable
.ParseResourceFile(str
))
419 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
422 m_currentFilename
= str
;
424 SetFrameTitle(m_currentFilename
);
426 UpdateResourceList();
428 // Construct include filename from this file
429 m_symbolFilename
= m_currentFilename
;
431 wxStripExtension(m_symbolFilename
);
432 m_symbolFilename
+= ".h";
434 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
436 wxString
str("Could not find include file ");
437 str
+= m_symbolFilename
;
438 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
439 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
440 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
442 m_symbolIdCounter
= 99;
446 // Set the id counter to the last known id
447 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
450 // Now check in case some (or all) resources don't have resource ids, or they
451 // don't match the .h file, or something of that nature.
452 bool altered
= RepairResourceIds();
455 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
456 "Dialog Editor Warning", wxOK
);
467 m_currentFilename
= "";
474 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
476 wxPropertyInfo::CloseWindow();
478 if (!force
&& Modified())
480 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
484 if (!SaveIfModified())
490 ClearCurrentDialog();
491 DisassociateWindows();
493 m_symbolTable
.Clear();
494 m_resourceTable
.ClearTable();
495 UpdateResourceList();
500 bool wxResourceManager::DisassociateWindows()
502 m_resourceTable
.BeginFind();
504 while ((node
= m_resourceTable
.Next()))
506 wxItemResource
*res
= (wxItemResource
*)node
->Data();
507 DisassociateResource(res
);
513 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
515 if (!m_resourceAssociations
.Get((long)resource
))
516 m_resourceAssociations
.Put((long)resource
, win
);
518 wxNode
*node
= resource
->GetChildren().First();
519 wxNode
* node2
= win
->GetChildren().First();
520 while (node
&& node2
)
522 wxItemResource
*child
= (wxItemResource
*)node
->Data();
523 wxWindow
* childWindow
= (wxWindow
*) node2
->Data();
525 if (child
->GetId() != childWindow
->GetId())
528 msg
.Printf("AssociateResource: error when associating child window %ld with resource %ld", child
->GetId(), childWindow
->GetId());
529 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
531 else if (childWindow
->GetName() != child
->GetName())
534 msg
.Printf("AssociateResource: error when associating child window with resource %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
535 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
539 AssociateResource(child
, childWindow
);
542 // New code to avoid the problem of duplicate ids and names. We simply
543 // traverse the child windows and child resources in parallel,
544 // checking for any mismatch.
546 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
548 // childWindow = win->FindWindow(child->GetName());
549 childWindow
= win
->FindWindow(child
->GetId());
551 AssociateResource(child
, childWindow
);
555 msg
.Printf("AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
556 wxMessageBox(msg
, "Dialog Editor problem", wxOK
);
560 node2
= node2
->Next();
564 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
566 wxWindow
*win
= FindWindowForResource(resource
);
570 // Disassociate children of window
571 wxNode
*node
= win
->GetChildren().First();
574 wxWindow
*child
= (wxWindow
*)node
->Data();
575 if (child
->IsKindOf(CLASSINFO(wxControl
)))
576 DisassociateResource(child
);
580 RemoveSelection(win
);
581 m_resourceAssociations
.Delete((long)resource
);
585 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
587 wxItemResource
*res
= FindResourceForWindow(win
);
589 return DisassociateResource(res
);
594 // Saves the window info into the resource, and deletes the
595 // handler. Doesn't actually disassociate the window from
596 // the resources. Replaces OnClose.
597 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
599 wxItemResource
*res
= FindResourceForWindow(win
);
601 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
603 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
604 win
->PopEventHandler();
606 // Now reset all child event handlers
607 wxNode
*node
= win
->GetChildren().First();
610 wxWindow
*child
= (wxWindow
*)node
->Data();
611 wxEvtHandler
*childHandler
= child
->GetEventHandler();
612 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
614 child
->PopEventHandler(TRUE
);
622 win
->PopEventHandler(TRUE
);
625 // Save the information
626 InstantiateResourceFromWindow(res
, win
, TRUE
);
628 // DisassociateResource(win);
633 // Destroys the window. If this is the 'current' panel, NULLs the
635 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
637 bool clearDisplay
= FALSE
;
638 if (m_editorPanel
->m_childWindow
== win
)
640 m_editorPanel
->m_childWindow
= NULL
;
647 m_editorPanel
->Clear();
652 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
654 m_resourceAssociations
.BeginFind();
656 while ((node
= m_resourceAssociations
.Next()))
658 wxWindow
*w
= (wxWindow
*)node
->Data();
661 return (wxItemResource
*)node
->GetKeyInteger();
667 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
669 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
673 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
677 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
680 if (!m_resourceTable
.FindResource(buf
))
685 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
687 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
688 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
689 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
690 wxDEFAULT_FRAME_STYLE
);
692 frame
->CreateStatusBar(1);
694 frame
->SetAutoLayout(TRUE
);
696 frame
->SetIcon(wxIcon("DIALOGEDICON"));
701 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
703 wxMenuBar
*menuBar
= new wxMenuBar
;
705 wxMenu
*fileMenu
= new wxMenu
;
706 fileMenu
->Append(RESED_NEW_DIALOG
, "New &Dialog", "Create a new dialog");
707 fileMenu
->AppendSeparator();
708 fileMenu
->Append(wxID_NEW
, "&New Project", "Clear the current project");
709 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
710 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
711 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
712 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
713 fileMenu
->AppendSeparator();
714 fileMenu
->Append(RESED_CONVERT_WXRS
, "Convert Old &Resources...", "Convert old resources to new");
715 fileMenu
->AppendSeparator();
716 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
718 wxMenu
*editMenu
= new wxMenu
;
719 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
720 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
721 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
723 wxMenu
*helpMenu
= new wxMenu
;
724 helpMenu
->Append(RESED_CONTENTS
, "&Help Topics", "Invokes the on-line help");
725 helpMenu
->AppendSeparator();
726 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
728 menuBar
->Append(fileMenu
, "&File");
729 menuBar
->Append(editMenu
, "&Edit");
730 menuBar
->Append(helpMenu
, "&Help");
735 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
737 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
738 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
745 panel
->SetScrollbars(10, 10, 100, 100);
750 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
752 // Load palette bitmaps
754 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
755 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
756 wxBitmap
ToolbarNewBitmap("NEWTOOL");
757 wxBitmap
ToolbarVertBitmap("VERTTOOL");
758 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
759 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
760 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
761 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
762 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
763 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
764 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
765 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
766 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
767 wxBitmap
ToolbarCopyWidthBitmap("COPYWIDTHTOOL");
768 wxBitmap
ToolbarCopyHeightBitmap("COPYHEIGHTTOOL");
769 wxBitmap
ToolbarDistributeHorizBitmap("DISTHORIZTOOL");
770 wxBitmap
ToolbarDistributeVertBitmap("DISTVERTTOOL");
772 #if defined(__WXGTK__) || defined(__WXMOTIF__)
773 wxBitmap
ToolbarLoadBitmap( load_xpm
);
774 wxBitmap
ToolbarSaveBitmap( save_xpm
);
775 wxBitmap
ToolbarNewBitmap( new_xpm
);
776 wxBitmap
ToolbarVertBitmap( vert_xpm
);
777 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
778 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
779 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
780 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
781 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
782 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
783 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
784 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
785 wxBitmap
ToolbarHelpBitmap( help_xpm
);
786 wxBitmap
ToolbarCopyWidthBitmap(copywdth_xpm
);
787 wxBitmap
ToolbarCopyHeightBitmap(copyhght_xpm
);
788 wxBitmap
ToolbarDistributeHorizBitmap(disthor_xpm
);
789 wxBitmap
ToolbarDistributeVertBitmap(distvert_xpm
);
792 // Create the toolbar
793 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
|wxTB_FLAT
);
794 toolbar
->SetMargins(2, 2);
801 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
806 //toolbar->AddSeparator();
807 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
808 FALSE
, currentX
, -1, NULL
, "New dialog");
809 currentX
+= width
+ dx
;
810 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
811 FALSE
, currentX
, -1, NULL
, "Load");
812 currentX
+= width
+ dx
;
813 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
814 FALSE
, currentX
, -1, NULL
, "Save");
815 currentX
+= width
+ dx
+ gap
;
816 toolbar
->AddSeparator();
817 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
818 FALSE
, currentX
, -1, NULL
, "Horizontal align");
819 currentX
+= width
+ dx
;
820 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
821 FALSE
, currentX
, -1, NULL
, "Top align");
822 currentX
+= width
+ dx
;
823 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
824 FALSE
, currentX
, -1, NULL
, "Bottom align");
825 currentX
+= width
+ dx
;
826 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
827 FALSE
, currentX
, -1, NULL
, "Vertical align");
828 currentX
+= width
+ dx
;
829 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
830 FALSE
, currentX
, -1, NULL
, "Left align");
831 currentX
+= width
+ dx
;
832 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
833 FALSE
, currentX
, -1, NULL
, "Right align");
834 currentX
+= width
+ dx
+ gap
;
835 toolbar
->AddSeparator();
836 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
837 FALSE
, currentX
, -1, NULL
, "Copy size");
838 currentX
+= width
+ dx
;
839 toolbar
->AddTool(TOOLBAR_COPY_WIDTH
, ToolbarCopyWidthBitmap
, wxNullBitmap
,
840 FALSE
, currentX
, -1, NULL
, "Copy width");
841 currentX
+= width
+ dx
;
842 toolbar
->AddTool(TOOLBAR_COPY_HEIGHT
, ToolbarCopyHeightBitmap
, wxNullBitmap
,
843 FALSE
, currentX
, -1, NULL
, "Copy height");
844 currentX
+= width
+ dx
;
845 toolbar
->AddTool(TOOLBAR_DISTRIBUTE_HORIZ
, ToolbarDistributeHorizBitmap
, wxNullBitmap
,
846 FALSE
, currentX
, -1, NULL
, "Distribute horizontally");
847 currentX
+= width
+ dx
;
848 toolbar
->AddTool(TOOLBAR_DISTRIBUTE_VERT
, ToolbarDistributeVertBitmap
, wxNullBitmap
,
849 FALSE
, currentX
, -1, NULL
, "Distribute vertically");
850 currentX
+= width
+ dx
+ gap
;
851 toolbar
->AddSeparator();
852 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
853 FALSE
, currentX
, -1, NULL
, "To front");
854 currentX
+= width
+ dx
;
855 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
856 FALSE
, currentX
, -1, NULL
, "To back");
857 currentX
+= width
+ dx
+ gap
;
859 toolbar
->AddSeparator();
860 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
861 FALSE
, currentX
, -1, NULL
, "Help");
862 currentX
+= width
+ dx
;
869 void wxResourceManager::UpdateResourceList()
871 if (!m_editorResourceTree
)
874 m_editorResourceTree
->SetInvalid(TRUE
);
875 m_editorResourceTree
->DeleteAllItems();
877 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
879 m_resourceTable
.BeginFind();
881 while ((node
= m_resourceTable
.Next()))
883 wxItemResource
*res
= (wxItemResource
*)node
->Data();
884 wxString
resType(res
->GetType());
885 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
887 AddItemsRecursively(id
, res
);
890 m_editorResourceTree
->Expand(id
);
891 m_editorResourceTree
->SetInvalid(FALSE
);
894 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
896 wxString
theString("");
897 theString
= resource
->GetName();
900 wxString
resType(resource
->GetType());
901 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
906 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
908 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
910 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
912 wxNode
*node
= resource
->GetChildren().First();
915 wxItemResource
*res
= (wxItemResource
*)node
->Data();
916 AddItemsRecursively(id
, res
);
920 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
923 bool wxResourceManager::EditSelectedResource()
925 int sel
= m_editorResourceTree
->GetSelection();
928 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
929 wxItemResource
*res
= data
->GetResource();
935 bool wxResourceManager::Edit(wxItemResource
*res
)
937 wxPropertyInfo::CloseWindow();
939 ClearCurrentDialog();
941 wxString
resType(res
->GetType());
942 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
946 wxMessageBox("Should not find panel in wxResourceManager::Edit");
951 // long style = res->GetStyle();
952 // res->SetStyle(style|wxRAISED_BORDER);
954 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
957 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
959 panel
->PushEventHandler(handler
);
961 // res->SetStyle(style);
962 handler
->AddChildHandlers(); // Add event handlers for all controls
963 AssociateResource(res
, panel
);
965 m_editorPanel
->m_childWindow
= panel
;
966 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
970 wxClientDC
dc(m_editorPanel
);
971 m_editorPanel
->DrawTitle(dc
);
976 bool wxResourceManager::CreateNewPanel()
978 wxPropertyInfo::CloseWindow();
980 ClearCurrentDialog();
983 MakeUniqueName("dialog", buf
);
985 wxItemResource
*resource
= new wxItemResource
;
986 resource
->SetType("wxDialog");
987 resource
->SetName(buf
);
988 resource
->SetTitle(buf
);
989 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
990 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
993 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
996 // This is now guaranteed to be unique, so just add to symbol table
997 m_symbolTable
.AddSymbol(newIdName
, id
);
999 m_resourceTable
.AddResource(resource
);
1001 wxSize
size(400, 300);
1003 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
1004 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
1005 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
1006 m_editorPanel
->m_childWindow
= panel
;
1008 resource
->SetStyle(panel
->GetWindowStyleFlag());
1010 // Store dialog units in resource
1011 size
= panel
->ConvertPixelsToDialog(size
);
1013 resource
->SetSize(10, 10, size
.x
, size
.y
);
1015 // For editing in situ we will need to use the hash table to ensure
1016 // we don't dereference invalid pointers.
1017 // resourceWindowTable.Put((long)resource, panel);
1019 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
1021 panel
->PushEventHandler(handler
);
1023 AssociateResource(resource
, panel
);
1024 UpdateResourceList();
1027 m_editorPanel
->m_childWindow
->Refresh();
1029 // panel->Refresh();
1031 wxClientDC
dc(m_editorPanel
);
1032 m_editorPanel
->DrawTitle(dc
);
1037 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1040 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1045 wxItemResource
*res
= new wxItemResource
;
1046 wxControl
*newItem
= NULL
;
1048 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1050 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1051 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1053 else res
->SetSize(x
, y
, -1, -1);
1055 res
->SetType(iType
);
1059 wxString
itemType(iType
);
1061 if (itemType
== "wxButton")
1063 prefix
= "ID_BUTTON";
1064 MakeUniqueName("button", buf
);
1067 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), wxBU_AUTODRAW
, wxDefaultValidator
, buf
);
1069 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1071 if (itemType
== "wxBitmapButton")
1073 prefix
= "ID_BITMAPBUTTON";
1074 MakeUniqueName("button", buf
);
1076 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), wxBU_AUTODRAW
, wxDefaultValidator
, buf
);
1078 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1080 prefix
= "ID_STATIC";
1081 MakeUniqueName("statictext", buf
);
1084 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1086 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1088 else if (itemType
== "wxStaticBitmap")
1090 prefix
= "ID_STATICBITMAP";
1091 MakeUniqueName("static", buf
);
1093 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1095 else if (itemType
== "wxCheckBox")
1097 prefix
= "ID_CHECKBOX";
1098 MakeUniqueName("checkbox", buf
);
1100 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1102 else if (itemType
== "wxListBox")
1104 prefix
= "ID_LISTBOX";
1105 MakeUniqueName("listbox", buf
);
1107 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1109 else if (itemType
== "wxRadioBox")
1111 prefix
= "ID_RADIOBOX";
1112 MakeUniqueName("radiobox", buf
);
1114 wxString names
[] = { "One", "Two" };
1115 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1116 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1117 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1119 else if (itemType
== "wxRadioButton")
1121 prefix
= "ID_RADIOBUTTON";
1122 MakeUniqueName("radiobutton", buf
);
1124 wxString names
[] = { "One", "Two" };
1125 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1126 0, wxDefaultValidator
, buf
);
1128 else if (itemType
== "wxChoice")
1130 prefix
= "ID_CHOICE";
1131 MakeUniqueName("choice", buf
);
1133 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1135 else if (itemType
== "wxComboBox")
1137 prefix
= "ID_COMBOBOX";
1138 MakeUniqueName("combobox", buf
);
1140 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1142 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1144 prefix
= "ID_STATICBOX";
1145 MakeUniqueName("staticbox", buf
);
1147 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1149 else if (itemType
== "wxGauge")
1151 prefix
= "ID_GAUGE";
1152 MakeUniqueName("gauge", buf
);
1154 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1156 else if (itemType
== "wxSlider")
1158 prefix
= "ID_SLIDER";
1159 MakeUniqueName("slider", buf
);
1161 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1163 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1165 prefix
= "ID_TEXTCTRL";
1166 MakeUniqueName("textctrl", buf
);
1168 res
->SetType("wxTextCtrl");
1169 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1171 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1173 prefix
= "ID_TEXTCTRL";
1174 MakeUniqueName("textctrl", buf
);
1176 res
->SetType("wxTextCtrl");
1177 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1179 else if (itemType
== "wxScrollBar")
1181 prefix
= "ID_SCROLLBAR";
1182 MakeUniqueName("scrollbar", buf
);
1184 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1189 int actualW
, actualH
;
1190 newItem
->GetSize(&actualW
, &actualH
);
1191 wxSize
actualSize(actualW
, actualH
);
1193 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1195 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1197 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1200 int id
= GenerateWindowId(prefix
, newIdName
);
1203 // This is now guaranteed to be unique, so just add to symbol table
1204 m_symbolTable
.AddSymbol(newIdName
, id
);
1206 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1208 res
->SetStyle(newItem
->GetWindowStyleFlag());
1209 AssociateResource(res
, newItem
);
1210 panelResource
->GetChildren().Append(res
);
1212 UpdateResourceList();
1217 void wxResourceManager::ClearCurrentDialog()
1219 if (m_editorPanel
->m_childWindow
)
1221 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1222 DisassociateResource(m_editorPanel
->m_childWindow
);
1223 DeleteWindow(m_editorPanel
->m_childWindow
);
1224 m_editorPanel
->m_childWindow
= NULL
;
1225 m_editorPanel
->Clear();
1229 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1231 if (m_editorPanel
->m_childWindow
)
1233 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1237 // Make sure the resources are up-to-date w.r.t. the window
1238 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1240 ResourceEditorDialogTester
* dialog
= new ResourceEditorDialogTester
;
1241 bool success
= FALSE
;
1242 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1245 dialog
->ShowModal();
1253 // Find the first dialog or panel for which
1254 // there is a selected panel item.
1255 wxWindow
*wxResourceManager::FindParentOfSelection()
1257 m_resourceTable
.BeginFind();
1259 while ((node
= m_resourceTable
.Next()))
1261 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1262 wxWindow
*win
= FindWindowForResource(res
);
1265 wxNode
*node1
= win
->GetChildren().First();
1268 wxControl
*item
= (wxControl
*)node1
->Data();
1269 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1270 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1272 node1
= node1
->Next();
1279 // Format the panel items according to 'flag'
1280 void wxResourceManager::AlignItems(int flag
)
1282 wxWindow
*win
= FindParentOfSelection();
1286 wxNode
*node
= GetSelections().First();
1290 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1291 if (firstSelection
->GetParent() != win
)
1296 firstSelection
->GetPosition(&firstX
, &firstY
);
1297 firstSelection
->GetSize(&firstW
, &firstH
);
1298 int centreX
= (int)(firstX
+ (firstW
/ 2));
1299 int centreY
= (int)(firstY
+ (firstH
/ 2));
1301 while ((node
= node
->Next()))
1303 wxControl
*item
= (wxControl
*)node
->Data();
1304 if (item
->GetParent() == win
)
1307 item
->GetPosition(&x
, &y
);
1308 item
->GetSize(&w
, &h
);
1314 case TOOLBAR_FORMAT_HORIZ
:
1317 newY
= (int)(centreY
- (h
/2.0));
1320 case TOOLBAR_FORMAT_VERT
:
1322 newX
= (int)(centreX
- (w
/2.0));
1326 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1332 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1338 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1340 newX
= firstX
+ firstW
- w
;
1344 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1347 newY
= firstY
+ firstH
- h
;
1355 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1356 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1358 item
->SetSize(newX
, newY
, w
, h
);
1360 // Also update the associated resource
1361 // We need to convert to dialog units if this is not a dialog or panel, but
1362 // the parent resource specifies dialog units.
1363 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1365 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1366 newX
= pt
.x
; newY
= pt
.y
;
1367 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1370 resource
->SetSize(newX
, newY
, w
, h
);
1376 // Copy the first image's size to subsequent images
1377 void wxResourceManager::CopySize(int command
)
1379 bool copyWidth
= (command
== TOOLBAR_COPY_SIZE
|| command
== TOOLBAR_COPY_WIDTH
) ;
1380 bool copyHeight
= (command
== TOOLBAR_COPY_SIZE
|| command
== TOOLBAR_COPY_HEIGHT
) ;
1382 wxWindow
*win
= FindParentOfSelection();
1386 wxNode
*node
= GetSelections().First();
1390 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1391 if (firstSelection
->GetParent() != win
)
1396 firstSelection
->GetPosition(&firstX
, &firstY
);
1397 firstSelection
->GetSize(&firstW
, &firstH
);
1399 while ((node
= node
->Next()))
1401 wxControl
*item
= (wxControl
*)node
->Data();
1402 if (item
->GetParent() == win
)
1404 wxSize sz
= item
->GetSize();
1405 int widthToSet
= (copyWidth
? firstW
: sz
.x
);
1406 int heightToSet
= (copyHeight
? firstH
: sz
.y
);
1408 item
->SetSize(-1, -1, widthToSet
, heightToSet
);
1410 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1411 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1413 widthToSet
= resource
->GetWidth();
1414 heightToSet
= resource
->GetHeight();
1416 // Also update the associated resource
1417 // We need to convert to dialog units if this is not a dialog or panel, but
1418 // the parent resource specifies dialog units.
1419 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1421 wxSize convertedSize
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1423 widthToSet
= convertedSize
.x
;
1425 heightToSet
= convertedSize
.y
;
1427 resource
->SetSize(resource
->GetX(), resource
->GetY(), widthToSet
, heightToSet
);
1433 void wxResourceManager::ToBackOrFront(bool toBack
)
1435 wxWindow
*win
= FindParentOfSelection();
1438 wxItemResource
*winResource
= FindResourceForWindow(win
);
1440 wxNode
*node
= GetSelections().First();
1443 wxControl
*item
= (wxControl
*)node
->Data();
1444 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1445 if (item
->GetParent() == win
)
1447 win
->GetChildren().DeleteObject(item
);
1449 winResource
->GetChildren().DeleteObject(itemResource
);
1452 win
->GetChildren().Insert(item
);
1454 winResource
->GetChildren().Insert(itemResource
);
1458 win
->GetChildren().Append(item
);
1460 winResource
->GetChildren().Append(itemResource
);
1463 node
= node
->Next();
1468 // Distribute controls evenly between first and last
1469 void wxResourceManager::DistributePositions(int command
)
1471 bool horizontal
= (command
== TOOLBAR_DISTRIBUTE_HORIZ
) ;
1473 wxWindow
*win
= FindParentOfSelection();
1477 if (GetSelections().Number() < 3)
1479 wxMessageBox(wxT("Sorry, distributing less than three controls does not make sense."));
1483 wxControl
*firstSelection
= (wxControl
*) GetSelections().First()->Data();
1484 wxControl
*lastSelection
= (wxControl
*) GetSelections().Last()->Data();
1486 // For now, assume the ordering is correct (the user selected the controls in order).
1487 // TODO: explicitly order the selections in terms of increading x or y position.
1489 // Find the total amount of space between all controls
1490 int totalControlSpace
= 0; // How much space the controls take up
1492 wxNode
* node
= GetSelections().First();
1495 wxControl
* control
= (wxControl
*) node
->Data();
1499 control
->GetPosition(&x
, &y
);
1500 control
->GetSize(&w
, &h
);
1502 // Don't include the space taken up by the first and last controls.
1503 if (control
!= firstSelection
&& control
!= lastSelection
)
1506 totalControlSpace
+= w
;
1508 totalControlSpace
+= h
;
1511 node
= node
->Next();
1515 int firstX
, firstY
, lastX
, lastY
;
1516 int firstW
, firstH
, lastW
, lastH
;
1517 firstSelection
->GetPosition(&firstX
, &firstY
);
1518 firstSelection
->GetSize(&firstW
, &firstH
);
1520 lastSelection
->GetPosition(&lastX
, &lastY
);
1521 lastSelection
->GetSize(&lastW
, &lastH
);
1526 |===| |====| |======| |==|
1530 int spacing
, currentPos
;
1533 spacing
= ((lastX
- (firstX
+ firstW
)) - totalControlSpace
) / (GetSelections().Number() - 1);
1534 currentPos
= firstX
+ firstW
+ spacing
;
1538 spacing
= ((lastY
- (firstY
+ firstH
)) - totalControlSpace
) / (GetSelections().Number() - 1);
1539 currentPos
= firstY
+ firstH
+ spacing
;
1542 node
= GetSelections().First();
1544 while ((node
= node
->Next()))
1546 wxControl
*item
= (wxControl
*)node
->Data();
1547 wxSize sz
= item
->GetSize();
1548 wxPoint pos
= item
->GetPosition();
1549 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1550 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1552 int controlX
= (horizontal
? currentPos
: pos
.x
);
1553 int controlY
= (horizontal
? pos
.y
: currentPos
);
1555 item
->Move(controlX
, controlY
);
1557 int resX
= controlX
;
1558 int resY
= controlY
;
1560 // Also update the associated resource
1561 // We need to convert to dialog units if this is not a dialog or panel, but
1562 // the parent resource specifies dialog units.
1563 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1565 wxPoint convertedPos
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(resX
, resY
));
1566 resX
= convertedPos
.x
;
1567 resY
= convertedPos
.y
;
1569 resource
->SetSize(resX
, resY
, resource
->GetWidth(), resource
->GetHeight());
1571 currentPos
+= (horizontal
? (sz
.x
+ spacing
) : (sz
.y
+ spacing
));
1576 void wxResourceManager::AddSelection(wxWindow
*win
)
1578 if (!m_selections
.Member(win
))
1579 m_selections
.Append(win
);
1582 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1584 m_selections
.DeleteObject(win
);
1587 void wxResourceManager::DeselectItemIfNecessary(wxWindow
*win
)
1589 if (win
->IsKindOf(CLASSINFO(wxControl
)) && (win
->GetEventHandler() != win
))
1591 // Deselect and refresh window in case we leave selection
1593 wxControl
*item
= (wxControl
*)win
;
1594 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1595 if (childHandler
->IsSelected())
1597 wxResourceManager::GetCurrentResourceManager()->RemoveSelection(item
);
1598 childHandler
->SelectItem(FALSE
);
1600 item
->GetParent()->Refresh();
1606 // Need to search through resource table removing this from
1607 // any resource which has this as a parent.
1608 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1610 m_resourceTable
.BeginFind();
1612 while ((node
= m_resourceTable
.Next()))
1614 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1615 if (thisRes
->GetChildren().Member(res
))
1617 thisRes
->GetChildren().DeleteObject(res
);
1624 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1629 RemoveResourceFromParent(res
);
1631 wxNode
*node
= res
->GetChildren().First();
1634 wxNode
*next
= node
->Next();
1635 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1636 DeleteResource(child
);
1640 // If this is a button or message resource, delete the
1641 // associate bitmap resource if not being used.
1642 wxString
resType(res
->GetType());
1644 /* shouldn't have to do this now bitmaps are ref-counted
1645 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1647 PossiblyDeleteBitmapResource(res->GetValue4());
1651 // Remove symbol from table if appropriate
1652 if (!IsSymbolUsed(res
, res
->GetId()))
1654 m_symbolTable
.RemoveSymbol(res
->GetId());
1657 m_resourceTable
.Delete(res
->GetName());
1663 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1665 DeselectItemIfNecessary(win
);
1667 wxItemResource
*res
= FindResourceForWindow(win
);
1669 DisassociateResource(res
);
1670 DeleteResource(res
);
1671 UpdateResourceList();
1676 // Will eventually have bitmap type information, for different
1678 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1680 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1684 MakeUniqueName("bitmap", buf
);
1685 resource
= new wxItemResource
;
1686 resource
->SetType("wxBitmap");
1687 resource
->SetName(buf
);
1689 // A bitmap resource has one or more children, specifying
1690 // alternative bitmaps.
1691 wxItemResource
*child
= new wxItemResource
;
1692 child
->SetType("wxBitmap");
1693 child
->SetName(filename
);
1694 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1695 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1696 child
->SetValue3(0); // Depth
1697 child
->SetSize(0,0,0,0);
1698 resource
->GetChildren().Append(child
);
1700 m_resourceTable
.AddResource(resource
);
1702 UpdateResourceList();
1705 return resource
->GetName();
1707 return wxEmptyString
;
1710 // Delete the bitmap resource if it isn't being used by another resource.
1711 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1713 if (!IsBitmapResourceUsed(resourceName
))
1715 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1716 DeleteResource(res
);
1717 UpdateResourceList();
1721 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1723 m_resourceTable
.BeginFind();
1725 while ((node
= m_resourceTable
.Next()))
1727 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1728 wxString
resType(res
->GetType());
1729 if (resType
== "wxDialog")
1731 wxNode
*node1
= res
->GetChildren().First();
1734 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1735 wxString
childResType(child
->GetType());
1737 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1738 child
->GetValue4() &&
1739 (strcmp(child
->GetValue4(), resourceName
) == 0))
1741 node1
= node1
->Next();
1748 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1749 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1751 if (!resource
|| (resource
->GetValue4() == ""))
1752 return wxEmptyString
;
1753 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1754 if (!bitmapResource
)
1755 return wxEmptyString
;
1757 wxNode
*node
= bitmapResource
->GetChildren().First();
1760 // Eventually augment this to return a bitmap of the right kind or something...
1761 // Maybe the root of the filename remains the same, so it doesn't matter which we
1762 // pick up. Otherwise how do we specify multiple filenames... too boring...
1763 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1764 return child
->GetName();
1766 //node = node->Next();
1768 return wxEmptyString
;
1771 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1773 m_resourceTable
.BeginFind();
1775 while ((node
= m_resourceTable
.Next()))
1777 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1778 wxString
resType(res
->GetType());
1779 if (resType
== "wxBitmap")
1781 wxNode
*node1
= res
->GetChildren().First();
1784 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1785 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1787 node1
= node1
->Next();
1794 // Is this window identifier symbol in use?
1795 // Let's assume that we can't have 2 names for the same integer id.
1796 // Therefore we can tell by the integer id whether the symbol is
1798 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1800 m_resourceTable
.BeginFind();
1802 while ((node
= m_resourceTable
.Next()))
1804 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1806 wxString
resType(res
->GetType());
1807 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1809 if ((res
!= thisResource
) && (res
->GetId() == id
))
1812 wxNode
*node1
= res
->GetChildren().First();
1815 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1816 if ((child
!= thisResource
) && (child
->GetId() == id
))
1818 node1
= node1
->Next();
1825 // Is this window identifier compatible with the given name? (i.e.
1826 // does it already exist under a different name)
1827 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1829 if (m_symbolTable
.SymbolExists(name
))
1831 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1838 // Change all integer ids that match oldId, to newId.
1839 // This is necessary if an id is changed for one resource - all resources
1841 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1843 m_resourceTable
.BeginFind();
1845 while ((node
= m_resourceTable
.Next()))
1847 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1849 wxString
resType(res
->GetType());
1850 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1852 if (res
->GetId() == oldId
)
1855 wxNode
*node1
= res
->GetChildren().First();
1858 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1859 if (child
->GetId() == oldId
)
1860 child
->SetId(newId
);
1862 node1
= node1
->Next();
1868 // If any resource ids were missing (or their symbol was missing),
1869 // repair them i.e. give them new ids. Returns TRUE if any resource
1870 // needed repairing.
1871 bool wxResourceManager::RepairResourceIds()
1873 bool repaired
= FALSE
;
1875 m_resourceTable
.BeginFind();
1877 while ((node
= m_resourceTable
.Next()))
1879 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1880 wxString
resType(res
->GetType());
1881 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1884 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1886 wxString newSymbolName
;
1887 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1889 if (res
->GetId() == 0)
1892 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1896 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1902 wxNode
*node1
= res
->GetChildren().First();
1905 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1907 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1909 wxString newSymbolName
;
1910 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1912 if (child
->GetId() == 0)
1914 child
->SetId(newId
);
1915 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1919 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1925 node1
= node1
->Next();
1933 // Deletes 'win' and creates a new window from the resource that
1934 // was associated with it. E.g. if you can't change properties on the
1935 // fly, you'll need to delete the window and create it again.
1936 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
, bool instantiateFirst
)
1938 wxItemResource
*resource
= FindResourceForWindow(win
);
1940 // Put the current window properties into the wxItemResource object
1942 wxWindowPropertyInfo
*newInfo
= NULL
;
1945 newInfo
= CreatePropertyInfoForWindow(win
);
1949 // May not always want to copy values back from the resource
1950 if (instantiateFirst
)
1951 info
->InstantiateResource(resource
);
1953 wxWindow
*newWin
= NULL
;
1954 wxWindow
*parent
= win
->GetParent();
1955 wxItemResource
* parentResource
= NULL
;
1957 parentResource
= FindResourceForWindow(parent
);
1959 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1962 newWin
= FindWindowForResource(resource
);
1966 DisassociateResource(resource
);
1967 if (win
->GetEventHandler() != win
)
1968 win
->PopEventHandler(TRUE
);
1971 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1972 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1973 AssociateResource(resource
, newWin
);
1974 UpdateResourceList();
1978 info
->SetPropertyWindow(newWin
);
1986 // Delete resource highlighted in the listbox
1987 bool wxResourceManager::DeleteSelection()
1989 int sel
= m_editorResourceTree
->GetSelection();
1992 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1993 wxItemResource
*res
= data
->GetResource();
1994 wxWindow
*win
= FindWindowForResource(res
);
1997 DeleteResource(win
);
1999 UpdateResourceList();
2008 // Delete resource highlighted in the listbox
2009 bool wxResourceManager::RecreateSelection()
2011 wxNode
*node
= GetSelections().First();
2014 wxControl
*item
= (wxControl
*)node
->Data();
2015 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
2016 wxNode
*next
= node
->Next();
2017 childHandler
->SelectItem(FALSE
);
2019 RemoveSelection(item
);
2021 RecreateWindowFromResource(item
);
2028 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
2033 // Ensures that all currently shown windows are saved to resources,
2034 // e.g. just before writing to a .wxr file.
2035 bool wxResourceManager::InstantiateAllResourcesFromWindows()
2037 m_resourceTable
.BeginFind();
2039 while ((node
= m_resourceTable
.Next()))
2041 wxItemResource
*res
= (wxItemResource
*)node
->Data();
2042 wxString
resType(res
->GetType());
2044 if (resType
== "wxDialog")
2046 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
2048 InstantiateResourceFromWindow(res
, win
, TRUE
);
2050 else if (resType
== "wxPanel")
2052 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
2054 InstantiateResourceFromWindow(res
, win
, TRUE
);
2060 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
2062 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
2063 info
->SetResource(resource
);
2064 info
->InstantiateResource(resource
);
2069 wxNode
*node
= resource
->GetChildren().First();
2072 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2073 wxWindow
*childWindow
= FindWindowForResource(child
);
2078 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
2079 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
2082 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
2083 node
= node
->Next();
2090 // Create a window information object for the give window
2091 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
2093 wxWindowPropertyInfo
*info
= NULL
;
2094 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
2096 info
= new wxScrollBarPropertyInfo(win
);
2098 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
2100 info
= new wxGroupBoxPropertyInfo(win
);
2102 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
2104 info
= new wxCheckBoxPropertyInfo(win
);
2106 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
2108 info
= new wxSliderPropertyInfo(win
);
2110 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
2112 info
= new wxGaugePropertyInfo(win
);
2114 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
2116 info
= new wxListBoxPropertyInfo(win
);
2118 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
2120 info
= new wxRadioBoxPropertyInfo(win
);
2122 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
2124 info
= new wxRadioButtonPropertyInfo(win
);
2126 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
2128 info
= new wxComboBoxPropertyInfo(win
);
2130 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
2132 info
= new wxChoicePropertyInfo(win
);
2134 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
2136 info
= new wxBitmapButtonPropertyInfo(win
);
2138 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
2140 info
= new wxButtonPropertyInfo(win
);
2142 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
2144 info
= new wxStaticBitmapPropertyInfo(win
);
2146 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
2148 info
= new wxStaticTextPropertyInfo(win
);
2150 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
2152 info
= new wxTextPropertyInfo(win
);
2154 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
2156 info
= new wxPanelPropertyInfo(win
);
2160 info
= new wxWindowPropertyInfo(win
);
2165 // Edit the given window
2166 void wxResourceManager::EditWindow(wxWindow
*win
)
2168 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2171 info
->SetResource(FindResourceForWindow(win
));
2172 wxString
str("Editing ");
2173 str
+= win
->GetClassInfo()->GetClassName();
2175 if (win
->GetName() != "")
2176 str
+= win
->GetName();
2178 str
+= "properties";
2179 info
->Edit(NULL
, str
);
2183 // Generate a window id and a first stab at a name
2184 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2186 m_symbolIdCounter
++;
2187 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2188 m_symbolIdCounter
++;
2190 int nameId
= m_symbolIdCounter
;
2193 str
.Printf("%d", nameId
);
2194 idName
= prefix
+ str
;
2196 while (m_symbolTable
.SymbolExists(idName
))
2199 str
.Printf("%d", nameId
);
2200 idName
= prefix
+ str
;
2203 return m_symbolIdCounter
;
2208 * Resource editor frame
2211 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2213 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2214 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2215 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2216 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2217 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2218 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2219 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2220 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2221 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2222 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2223 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2224 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2225 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2226 EVT_MENU(RESED_CONVERT_WXRS
, wxResourceEditorFrame::OnConvertWXRs
)
2227 EVT_CLOSE(wxResourceEditorFrame::OnCloseWindow
)
2230 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2231 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2232 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2237 wxResourceEditorFrame::~wxResourceEditorFrame()
2241 void wxResourceEditorFrame::OnConvertWXRs(wxCommandEvent
& WXUNUSED(event
))
2243 manager
->ConvertWXRs();
2246 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2248 manager
->New(FALSE
);
2251 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2253 manager
->CreateNewPanel();
2256 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2261 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2263 manager
->Clear(TRUE
, FALSE
);
2266 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2271 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2276 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2278 manager
->Clear(TRUE
, FALSE
) ;
2282 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2285 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart <julian.smart@ukonline.co.uk>\nJulian Smart (c) 1996-1999", wxDIALOG_EDITOR_VERSION
);
2286 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2289 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2291 manager
->TestCurrentDialog(this);
2294 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2297 wxBeginBusyCursor();
2298 manager
->GetHelpController()->LoadFile();
2299 manager
->GetHelpController()->DisplayContents();
2304 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2306 manager
->DeleteSelection();
2309 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2311 manager
->RecreateSelection();
2314 void wxResourceEditorFrame::OnCloseWindow(wxCloseEvent
& event
)
2316 wxPropertyInfo::CloseWindow();
2317 manager
->ClearCurrentDialog();
2318 if (manager
->Modified())
2320 if (!manager
->Clear(TRUE
, FALSE
))
2331 manager
->m_resourceEditorWindowSize
.width
= w
;
2332 manager
->m_resourceEditorWindowSize
.height
= h
;
2335 GetPosition(&x
, &y
);
2337 manager
->m_resourceEditorWindowSize
.x
= x
;
2338 manager
->m_resourceEditorWindowSize
.y
= y
;
2340 manager
->SetEditorFrame(NULL
);
2341 manager
->SetEditorToolBar(NULL
);
2347 * Resource editor window that contains the dialog/panel being edited
2350 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2351 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2354 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2356 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2360 m_childWindow
= NULL
;
2362 SetBackgroundColour(* wxWHITE
);
2365 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2369 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2376 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2380 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2383 wxString
str(res
->GetTitle());
2385 ViewStart(& x
, & y
);
2387 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2389 dc
.SetBackgroundMode(wxTRANSPARENT
);
2390 dc
.SetTextForeground(wxColour(0, 0, 0));
2393 dc
.GetTextExtent(str
, & w
, & h
);
2395 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2400 // Popup menu callback
2401 void ObjectMenuProc(wxMenu
*menu
, wxCommandEvent
& event
)
2403 wxWindow
*data
= (wxWindow
*)menu
->GetClientData();
2407 switch (event
.GetId())
2409 case OBJECT_MENU_TITLE
:
2414 case OBJECT_MENU_EDIT
:
2416 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2419 case OBJECT_MENU_DELETE
:
2421 // Before deleting a dialog, give the user a last chance
2422 // change their mind, in case they accidentally right
2423 // clicked the dialog rather than the widget they were
2425 if (data
->IsKindOf(CLASSINFO(wxPanel
)))
2427 wxString
str(wxT("Deleting dialog : "));
2428 str
+= data
->GetName();
2429 if (wxMessageBox(wxT("Are you sure?"), str
, wxYES_NO
| wxCENTRE
) == wxNO
)
2433 wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data
);
2435 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2436 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2437 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2450 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2451 // EVT_PAINT(EditorToolBar::OnPaint)
2454 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2456 wxToolBar(frame
, -1, pos
, size
, style
)
2460 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2462 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2466 case TOOLBAR_LOAD_FILE
:
2473 manager
->CreateNewPanel();
2476 case TOOLBAR_SAVE_FILE
:
2484 wxBeginBusyCursor();
2485 manager
->GetHelpController()->DisplayContents();
2490 case TOOLBAR_FORMAT_HORIZ
:
2492 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2495 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2497 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2500 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2502 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2505 case TOOLBAR_FORMAT_VERT
:
2507 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2510 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2512 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2515 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2517 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2520 case TOOLBAR_COPY_SIZE
:
2522 manager
->CopySize(TOOLBAR_COPY_SIZE
);
2525 case TOOLBAR_COPY_WIDTH
:
2527 manager
->CopySize(TOOLBAR_COPY_WIDTH
);
2530 case TOOLBAR_COPY_HEIGHT
:
2532 manager
->CopySize(TOOLBAR_COPY_HEIGHT
);
2535 case TOOLBAR_DISTRIBUTE_HORIZ
:
2537 manager
->DistributePositions(TOOLBAR_DISTRIBUTE_HORIZ
);
2540 case TOOLBAR_DISTRIBUTE_VERT
:
2542 manager
->DistributePositions(TOOLBAR_DISTRIBUTE_VERT
);
2545 case TOOLBAR_TO_BACK
:
2547 manager
->ToBackOrFront(TRUE
);
2550 case TOOLBAR_TO_FRONT
:
2552 manager
->ToBackOrFront(FALSE
);
2561 void EditorToolBar::OnMouseEnter(int toolIndex
)
2563 wxFrame
*frame
= (wxFrame
*)GetParent();
2571 case TOOLBAR_LOAD_FILE
:
2572 frame
->SetStatusText("Load project file");
2574 case TOOLBAR_SAVE_FILE
:
2575 frame
->SetStatusText("Save project file");
2578 frame
->SetStatusText("Create a new resource");
2580 case TOOLBAR_FORMAT_HORIZ
:
2581 frame
->SetStatusText("Align items horizontally");
2583 case TOOLBAR_FORMAT_VERT
:
2584 frame
->SetStatusText("Align items vertically");
2586 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2587 frame
->SetStatusText("Left-align items");
2589 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2590 frame
->SetStatusText("Right-align items");
2592 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2593 frame
->SetStatusText("Top-align items");
2595 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2596 frame
->SetStatusText("Bottom-align items");
2598 case TOOLBAR_COPY_SIZE
:
2599 frame
->SetStatusText("Copy size from first selection");
2601 case TOOLBAR_TO_FRONT
:
2602 frame
->SetStatusText("Put image to front");
2604 case TOOLBAR_TO_BACK
:
2605 frame
->SetStatusText("Put image to back");
2608 frame
->SetStatusText("Display help contents");
2614 else frame
->SetStatusText("");
2617 bool ResourceEditorDialogTester::ProcessEvent(wxEvent
& event
)
2619 if (event
.IsCommandEvent() && event
.GetId() != wxID_OK
&& event
.GetId() != wxID_CANCEL
)
2625 return wxDialog::ProcessEvent(event
);
2628 static int gs_LabelInsertionCount
= 0;
2630 // Convert old WXRs to new
2631 bool wxResourceManager::ConvertWXRs()
2633 gs_LabelInsertionCount
= 0;
2634 m_symbolIdCounter
= 20000;
2636 wxString currentPath
= wxGetCwd();
2637 wxString oldWXRPath
, newWXRPath
;
2639 wxDirDialog
dialog(NULL
, wxT("Choose directory for old WXRs"), currentPath
);
2641 if (dialog
.ShowModal() == wxID_OK
)
2643 oldWXRPath
= dialog
.GetPath();
2648 wxDirDialog
dialog2(NULL
, wxT("Choose directory for new WXRs"), oldWXRPath
);
2650 if (dialog2
.ShowModal() == wxID_OK
)
2652 newWXRPath
= dialog2
.GetPath();
2657 if (newWXRPath
== oldWXRPath
)
2659 wxMessageBox(wxT("Sorry, the directories must be different."));
2663 wxDir
dir(oldWXRPath
);
2664 if (!dir
.IsOpened())
2667 wxArrayString stringArray
;
2670 bool ok
= dir
.GetFirst(& filename
, wxT("*.wxr"));
2673 stringArray
.Add(filename
);
2675 ok
= dir
.GetNext(& filename
);
2678 // Pop up a progress dialog
2679 wxProgressDialog
progressDialog(wxT("Converting WXR files"), wxT("Converting files..."));
2682 for (i
= 0; i
< stringArray
.Count(); i
++)
2684 progressDialog
.Update((int) (100.0 * ((double) i
/ (double) stringArray
.Count())));
2686 filename
= stringArray
[i
];
2687 wxString oldPath
= oldWXRPath
+ wxString(wxFILE_SEP_PATH
) + filename
;
2688 wxString newPath
= newWXRPath
+ wxString(wxFILE_SEP_PATH
) + filename
;
2690 DoConvertWXR(oldPath
, newPath
);
2694 msg
.Printf(wxT("Dialog Editor inserted %d labels."), gs_LabelInsertionCount
);
2700 bool wxResourceManager::DoConvertWXR(const wxString
& oldPath
, const wxString
& newPath
)
2703 if (!Clear(TRUE
, FALSE
))
2706 m_symbolTable
.AddStandardSymbols();
2708 if (!m_resourceTable
.ParseResourceFile(oldPath
))
2711 msg
.Printf(wxT("Could not read file %s"), (const char*) oldPath
);
2712 wxMessageBox(msg
, "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
2715 m_currentFilename
= oldPath
;
2717 //SetFrameTitle(m_currentFilename);
2719 //UpdateResourceList();
2721 // Construct include filename from this file
2722 m_symbolFilename
= m_currentFilename
;
2724 wxStripExtension(m_symbolFilename
);
2725 m_symbolFilename
+= wxT(".h");
2727 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
2732 // Set the id counter to the last known id
2733 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
2736 // Now check in case some (or all) resources don't have resource ids, or they
2737 // don't match the .h file, or something of that nature.
2738 bool altered
= RepairResourceIds();
2740 // Do any necessary changes to the resources
2741 m_resourceTable
.BeginFind();
2743 while ((node
= m_resourceTable
.Next()))
2745 wxItemResource
*res
= (wxItemResource
*)node
->Data();
2746 ChangeOldToNewResource(NULL
, res
);
2749 // Change the filename before saving
2751 m_currentFilename
= newPath
;
2752 m_symbolFilename
= m_currentFilename
;
2753 wxStripExtension(m_symbolFilename
);
2754 m_symbolFilename
+= wxT(".h");
2766 bool wxResourceManager::ChangeOldToNewResource(wxItemResource
* parent
, wxItemResource
* res
)
2768 // Change these according to your needs
2770 // Change all fonts to use system defaults for fonts, colours etc.
2771 static bool s_useSystemDefaultsAlways
= FALSE
; // TRUE;
2773 // Increase dialog height by this amount (wxWin 2 uses dialog client size now)
2774 static int s_increaseDialogSize
= -18;
2776 // How many points to decrease the font sizes by, since
2777 // wxWin 2 fonts are larger in Windows
2778 static int s_decreaseFontSize
= 3;
2780 wxString
itemType(res
->GetType());
2782 wxFont font
= res
->GetFont();
2784 if ((s_decreaseFontSize
) > 0 && font
.Ok())
2786 wxFont newFont
= wxFont(font
.GetPointSize() - s_decreaseFontSize
,
2787 font
.GetFamily(), font
.GetStyle(), font
.GetWeight(),
2788 font
.GetUnderlined(), font
.GetFaceName());
2789 res
->SetFont(newFont
);
2792 if (itemType
== wxT("wxDialogBox") || itemType
== wxT("wxDialog") || itemType
== wxT("wxPanel"))
2794 if (itemType
== wxT("wxDialogBox"))
2795 res
->SetType(wxT("wxDialog"));
2797 if (itemType
== wxT("wxDialogBox") || itemType
== wxT("wxDialog"))
2799 // Only change the height if it has a caption, i.e. it's going to be
2800 // used as a proper dialog and not a panel
2801 if (res
->GetStyle() & wxCAPTION
)
2802 res
->SetSize(res
->GetX(), res
->GetY(), res
->GetWidth(), res
->GetHeight() + s_increaseDialogSize
);
2805 if (s_useSystemDefaultsAlways
)
2806 res
->SetResourceStyle(res
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
2808 if (res
->GetValue1())
2809 res
->SetStyle(res
->GetStyle() | wxDIALOG_MODAL
);
2811 wxNode
*node
= res
->GetChildren().First();
2814 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2816 ChangeOldToNewResource(res
, child
);
2817 node
= node
->Next();
2820 else if (itemType
== wxT("wxMessage"))
2822 // Figure out if this is a bitmap or text message
2823 if (res
->GetValue4().IsEmpty())
2824 res
->SetType(wxT("wxStaticText"));
2826 res
->SetType(wxT("wxStaticBitmap"));
2828 else if (itemType
== wxT("wxButton"))
2830 // Figure out if this is a bitmap or text message
2831 if (res
->GetValue4().IsEmpty())
2835 res
->SetType(wxT("wxBitmapButton"));
2837 else if (itemType
== wxT("wxGroupBox"))
2839 res
->SetType(wxT("wxStaticBox"));
2841 else if (itemType
== wxT("wxText"))
2843 res
->SetType(wxT("wxTextCtrl"));
2845 else if (itemType
== wxT("wxMultiText"))
2847 res
->SetType(wxT("wxTextCtrl"));
2848 res
->SetStyle(res
->GetStyle() | wxTE_MULTILINE
);
2851 itemType
= res
->GetType();
2853 if (!res
->GetTitle().IsEmpty() &&
2854 (itemType
== wxT("wxTextCtrl") || itemType
== wxT("wxChoice") ||
2855 itemType
== wxT("wxComboBox") || itemType
== wxT("wxGauge") ||
2856 itemType
== wxT("wxListBox")))
2858 // Insert a label control resource, adjusting the size of this
2859 // resource accordingly.
2860 InsertLabelResource(parent
, res
);
2866 // Insert a label control resource, adjusting the size of this
2867 // resource accordingly.
2868 bool wxResourceManager::InsertLabelResource(wxItemResource
* parent
, wxItemResource
* res
)
2870 gs_LabelInsertionCount
++;
2872 bool isHorizontal
= TRUE
;
2874 // Determine panel orientation
2875 if (parent
->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL
)
2877 isHorizontal
= FALSE
;
2879 else if (parent
->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL
)
2881 isHorizontal
= TRUE
;
2885 if (res
->GetResourceStyle() & wxRESOURCE_VERTICAL_LABEL
)
2887 isHorizontal
= FALSE
;
2889 else if (res
->GetResourceStyle() & wxRESOURCE_HORIZONTAL_LABEL
)
2891 isHorizontal
= TRUE
;
2894 int x
= res
->GetX();
2895 int y
= res
->GetY();
2896 int width
= res
->GetWidth();
2897 int height
= res
->GetHeight();
2899 // Find the font specified
2901 if (res
->GetFont().Ok())
2902 font
= res
->GetFont();
2904 font
= parent
->GetFont();
2906 if (!font
.Ok() || (parent
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
))
2907 font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
2910 wxCoord labelWidth
, labelHeight
;
2913 dc
.GetTextExtent(res
->GetTitle(), & labelWidth
, & labelHeight
);
2915 // Vert/horizontal margin between controls
2925 x
+= labelWidth
+ margin
;
2926 width
-= (labelWidth
+ margin
);
2930 y
+= labelHeight
+ margin
;
2931 height
-= (labelHeight
+ margin
);
2934 if (res
->GetType() == wxT("wxTextCtrl"))
2938 else if (res
->GetType() == wxT("wxChoice") || res
->GetType() == wxT("wxComboBox"))
2944 res
->SetSize(x
, y
, width
, height
);
2946 wxItemResource
* staticItem
= new wxItemResource
;
2947 staticItem
->SetSize(labelX
, labelY
, labelWidth
, labelHeight
);
2948 staticItem
->SetTitle(res
->GetTitle());
2949 staticItem
->SetFont(font
);
2950 staticItem
->SetStyle(0);
2951 staticItem
->SetType(wxT("wxStaticText"));
2953 wxString newSymbolName
;
2954 int newId
= GenerateWindowId(wxT("ID_STATICTEXT"), newSymbolName
) ;
2955 staticItem
->SetId(newId
);
2957 newSymbolName
= res
->GetName() + wxT("_Label");
2958 staticItem
->SetName(newSymbolName
);
2959 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
2961 wxNode
* node
= parent
->GetChildren().Member(res
);
2963 wxASSERT( (node
!= NULL
) );
2965 parent
->GetChildren().Insert(node
, staticItem
);
2967 // Remove the title from this resource since we've replaced it
2968 // with a static text control
2969 res
->SetTitle(wxEmptyString
);