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"
46 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
49 #include <strstream.h>
66 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
67 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
70 #include "bitmaps/load.xpm"
71 #include "bitmaps/save.xpm"
72 #include "bitmaps/new.xpm"
73 #include "bitmaps/vert.xpm"
74 #include "bitmaps/alignt.xpm"
75 #include "bitmaps/alignb.xpm"
76 #include "bitmaps/horiz.xpm"
77 #include "bitmaps/alignl.xpm"
78 #include "bitmaps/alignr.xpm"
79 #include "bitmaps/copysize.xpm"
80 #include "bitmaps/tofront.xpm"
81 #include "bitmaps/toback.xpm"
82 #include "bitmaps/help.xpm"
83 #include "bitmaps/wxwin.xpm"
90 wxResourceManager::wxResourceManager():
91 m_imageList(16, 16, TRUE
)
93 sm_currentResourceManager
= this;
97 m_editorResourceTree
= NULL
;
98 m_editorControlList
= NULL
;
100 m_symbolIdCounter
= 99;
102 m_currentFilename
= "";
103 m_symbolFilename
= "";
104 m_editorToolBar
= NULL
;
106 // Default window positions
107 m_resourceEditorWindowSize
.width
= 470;
108 m_resourceEditorWindowSize
.height
= 300;
110 m_resourceEditorWindowSize
.x
= 0;
111 m_resourceEditorWindowSize
.y
= 0;
113 m_propertyWindowSize
.width
= 300;
114 m_propertyWindowSize
.height
= 300;
117 m_helpController
= NULL
;
120 m_bitmapImage
= NULL
;
121 m_rootDialogItem
= 0;
124 wxResourceManager::~wxResourceManager()
126 sm_currentResourceManager
= NULL
;
130 if (m_helpController
)
132 m_helpController
->Quit();
133 delete m_helpController
;
134 m_helpController
= NULL
;
138 delete m_bitmapImage
;
142 bool wxResourceManager::Initialize()
144 // Set up the resource filename for each platform.
146 // dialoged.ini in the Windows directory
148 GetWindowsDirectory(buf
, 256);
149 strcat(buf
, "\\dialoged.ini");
150 m_optionsResourceFilename
= buf
;
151 #elif defined(__WXGTK__)
154 strcat(buf
, "/.dialogedrc");
155 m_optionsResourceFilename
= buf
;
157 #error "Unsupported platform."
163 m_helpController
= new wxHelpController
;
164 m_helpController
->Initialize("dialoged");
167 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
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
);
177 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
181 // Initialize the image list icons
183 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
184 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
185 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
186 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
187 m_imageList
.Add(icon1
);
188 m_imageList
.Add(icon2
);
189 m_imageList
.Add(icon3
);
190 m_imageList
.Add(icon4
);
193 m_symbolTable
.AddStandardSymbols();
198 bool wxResourceManager::LoadOptions()
200 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize
.x
, m_optionsResourceFilename
.GetData());
201 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize
.y
, m_optionsResourceFilename
.GetData());
202 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize
.width
, m_optionsResourceFilename
.GetData());
203 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize
.height
, m_optionsResourceFilename
.GetData());
204 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize
.x
, m_optionsResourceFilename
.GetData());
205 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize
.y
, m_optionsResourceFilename
.GetData());
206 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize
.width
, m_optionsResourceFilename
.GetData());
207 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize
.height
, m_optionsResourceFilename
.GetData());
211 bool wxResourceManager::SaveOptions()
213 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize
.x
, m_optionsResourceFilename
.GetData());
214 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize
.y
, m_optionsResourceFilename
.GetData());
215 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize
.width
, m_optionsResourceFilename
.GetData());
216 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize
.height
, m_optionsResourceFilename
.GetData());
218 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize
.x
, m_optionsResourceFilename
.GetData());
219 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize
.y
, m_optionsResourceFilename
.GetData());
220 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize
.width
, m_optionsResourceFilename
.GetData());
221 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize
.height
, m_optionsResourceFilename
.GetData());
226 // Show or hide the resource editor frame, which displays a list
227 // of resources with ability to edit them.
228 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
234 m_editorFrame
->Iconize(FALSE
);
235 m_editorFrame
->Show(TRUE
);
238 m_editorFrame
= OnCreateEditorFrame(title
);
240 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
241 m_editorFrame
->SetMenuBar(menuBar
);
243 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
244 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
245 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
247 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
249 m_editorResourceTree
->SetImageList(& m_imageList
);
251 // Constraints for toolbar
252 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
253 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
254 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
255 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
256 c
->bottom
.Unconstrained();
257 c
->width
.Unconstrained();
258 c
->height
.Absolute(28);
259 m_editorToolBar
->SetConstraints(c
);
261 // Constraints for listbox
262 c
= new wxLayoutConstraints
;
263 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
264 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
265 c
->right
.Absolute (150);
266 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
267 c
->width
.Unconstrained();
268 c
->height
.Unconstrained();
269 m_editorResourceTree
->SetConstraints(c
);
271 // Constraints for panel
272 c
= new wxLayoutConstraints
;
273 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
274 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
275 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
276 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
277 c
->width
.Unconstrained();
278 c
->height
.Unconstrained();
279 m_editorPanel
->SetConstraints(c
);
281 // Constraints for control list (bottom window)
282 c
= new wxLayoutConstraints
;
283 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
284 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
285 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
286 c
->width
.Unconstrained();
288 c
->height
.Absolute(70);
290 c
->height
.Absolute(60);
293 m_editorControlList
->SetConstraints(c
);
295 m_editorFrame
->SetAutoLayout(TRUE
);
297 UpdateResourceList();
299 m_editorFrame
->Show(TRUE
);
304 wxFrame
*fr
= m_editorFrame
;
305 if (m_editorFrame
->OnClose())
309 m_editorFrame
= NULL
;
310 m_editorPanel
= NULL
;
316 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
320 if (filename
== wxString(""))
321 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
324 wxString
str("wxWindows Dialog Editor - ");
325 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
327 m_editorFrame
->SetTitle(str
);
332 bool wxResourceManager::Save()
334 if (m_currentFilename
== wxString(""))
337 return Save(m_currentFilename
);
340 bool wxResourceManager::Save(const wxString
& filename
)
342 // Ensure all visible windows are saved to their resources
343 m_currentFilename
= filename
;
344 SetFrameTitle(m_currentFilename
);
345 InstantiateAllResourcesFromWindows();
346 if (m_resourceTable
.Save(filename
))
348 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
356 bool wxResourceManager::SaveAs()
358 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
359 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
));
361 if (s
.IsNull() || s
== "")
364 m_currentFilename
= s
;
365 wxStripExtension(m_currentFilename
);
366 m_currentFilename
+= ".wxr";
368 // Construct include filename from this file
369 m_symbolFilename
= m_currentFilename
;
371 wxStripExtension(m_symbolFilename
);
372 m_symbolFilename
+= ".h";
374 Save(m_currentFilename
);
378 bool wxResourceManager::SaveIfModified()
385 bool wxResourceManager::Load(const wxString
& filename
)
387 return New(TRUE
, filename
);
390 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
392 if (!Clear(TRUE
, FALSE
))
395 m_symbolTable
.AddStandardSymbols();
399 wxString str
= filename
;
400 if (str
== wxString(""))
402 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, NULL
));
403 if (!f
.IsNull() && f
!= "")
409 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
411 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
414 m_currentFilename
= str
;
416 SetFrameTitle(m_currentFilename
);
418 UpdateResourceList();
420 // Construct include filename from this file
421 m_symbolFilename
= m_currentFilename
;
423 wxStripExtension(m_symbolFilename
);
424 m_symbolFilename
+= ".h";
426 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
428 wxString
str("Could not find include file ");
429 str
+= m_symbolFilename
;
430 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
431 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
432 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
434 m_symbolIdCounter
= 99;
438 // Set the id counter to the last known id
439 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
442 // Now check in case some (or all) resources don't have resource ids, or they
443 // don't match the .h file, or something of that nature.
444 bool altered
= RepairResourceIds();
447 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
448 "Dialog Editor Warning", wxOK
);
459 m_currentFilename
= "";
466 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
468 if (!force
&& Modified())
470 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
474 if (!SaveIfModified())
480 ClearCurrentDialog();
481 DisassociateWindows();
483 m_symbolTable
.Clear();
484 m_resourceTable
.ClearTable();
485 UpdateResourceList();
490 bool wxResourceManager::DisassociateWindows()
492 m_resourceTable
.BeginFind();
494 while (node
= m_resourceTable
.Next())
496 wxItemResource
*res
= (wxItemResource
*)node
->Data();
497 DisassociateResource(res
);
503 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
505 if (!m_resourceAssociations
.Get((long)resource
))
506 m_resourceAssociations
.Put((long)resource
, win
);
508 wxNode
*node
= resource
->GetChildren().First();
511 wxItemResource
*child
= (wxItemResource
*)node
->Data();
512 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
514 childWindow
= win
->FindWindow(child
->GetName());
516 AssociateResource(child
, childWindow
);
520 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? child
->GetName() : "(unnamed)");
521 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
528 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
530 wxWindow
*win
= FindWindowForResource(resource
);
534 // Disassociate children of window
535 if (win
->GetChildren())
537 wxNode
*node
= win
->GetChildren()->First();
540 wxWindow
*child
= (wxWindow
*)node
->Data();
541 if (child
->IsKindOf(CLASSINFO(wxControl
)))
542 DisassociateResource(child
);
547 RemoveSelection(win
);
548 m_resourceAssociations
.Delete((long)resource
);
552 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
554 wxItemResource
*res
= FindResourceForWindow(win
);
556 return DisassociateResource(res
);
561 // Saves the window info into the resource, and deletes the
562 // handler. Doesn't actually disassociate the window from
563 // the resources. Replaces OnClose.
564 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
566 wxItemResource
*res
= FindResourceForWindow(win
);
568 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
570 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
571 win
->PopEventHandler();
573 // Now reset all child event handlers
574 wxNode
*node
= win
->GetChildren()->First();
577 wxWindow
*child
= (wxWindow
*)node
->Data();
578 wxEvtHandler
*childHandler
= child
->GetEventHandler();
579 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
581 child
->PopEventHandler(TRUE
);
589 win
->PopEventHandler(TRUE
);
592 // Save the information
593 InstantiateResourceFromWindow(res
, win
, TRUE
);
595 // DisassociateResource(win);
600 // Destroys the window. If this is the 'current' panel, NULLs the
602 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
604 bool clearDisplay
= FALSE
;
605 if (m_editorPanel
->m_childWindow
== win
)
607 m_editorPanel
->m_childWindow
= NULL
;
614 m_editorPanel
->Clear();
619 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
621 m_resourceAssociations
.BeginFind();
623 while (node
= m_resourceAssociations
.Next())
625 wxWindow
*w
= (wxWindow
*)node
->Data();
628 return (wxItemResource
*)node
->key
.integer
;
634 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
636 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
640 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
644 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
647 if (!m_resourceTable
.FindResource(buf
))
652 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
654 int frameWidth
= 420;
655 int frameHeight
= 300;
657 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
658 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
659 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
660 wxDEFAULT_FRAME_STYLE
);
662 frame
->CreateStatusBar(1);
664 frame
->SetAutoLayout(TRUE
);
666 wxIcon
*icon
= new wxIcon("DIALOGEDICON");
667 frame
->SetIcon(icon
);
672 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
674 wxMenuBar
*menuBar
= new wxMenuBar
;
676 wxMenu
*fileMenu
= new wxMenu
;
677 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
678 fileMenu
->AppendSeparator();
679 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
680 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
681 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
682 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
683 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
684 fileMenu
->AppendSeparator();
685 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
687 wxMenu
*editMenu
= new wxMenu
;
688 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
689 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
690 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
692 wxMenu
*helpMenu
= new wxMenu
;
693 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
694 helpMenu
->AppendSeparator();
695 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
697 menuBar
->Append(fileMenu
, "&File");
698 menuBar
->Append(editMenu
, "&Edit");
699 menuBar
->Append(helpMenu
, "&Help");
704 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
706 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
707 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
710 panel
->SetScrollbars(10, 10, 100, 100);
715 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
717 // Load palette bitmaps
719 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
720 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
721 wxBitmap
ToolbarNewBitmap("NEWTOOL");
722 wxBitmap
ToolbarVertBitmap("VERTTOOL");
723 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
724 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
725 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
726 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
727 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
728 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
729 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
730 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
731 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
734 wxBitmap
ToolbarLoadBitmap( load_xpm
);
735 wxBitmap
ToolbarSaveBitmap( save_xpm
);
736 wxBitmap
ToolbarNewBitmap( new_xpm
);
737 wxBitmap
ToolbarVertBitmap( vert_xpm
);
738 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
739 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
740 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
741 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
742 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
743 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
744 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
745 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
746 wxBitmap
ToolbarHelpBitmap( help_xpm
);
749 // Create the toolbar
750 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
751 toolbar
->SetMargins(2, 2);
758 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
763 toolbar
->AddSeparator();
764 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, (wxBitmap
*)NULL
,
765 FALSE
, (float)currentX
, -1, NULL
, "New dialog");
766 currentX
+= width
+ dx
;
767 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, (wxBitmap
*)NULL
,
768 FALSE
, (float)currentX
, -1, NULL
, "Load");
769 currentX
+= width
+ dx
;
770 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, (wxBitmap
*)NULL
,
771 FALSE
, (float)currentX
, -1, NULL
, "Save");
772 currentX
+= width
+ dx
+ gap
;
773 toolbar
->AddSeparator();
774 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, (wxBitmap
*)NULL
,
775 FALSE
, (float)currentX
, -1, NULL
, "Horizontal align");
776 currentX
+= width
+ dx
;
777 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, (wxBitmap
*)NULL
,
778 FALSE
, (float)currentX
, -1, NULL
, "Top align");
779 currentX
+= width
+ dx
;
780 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, (wxBitmap
*)NULL
,
781 FALSE
, (float)currentX
, -1, NULL
, "Bottom align");
782 currentX
+= width
+ dx
;
783 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, (wxBitmap
*)NULL
,
784 FALSE
, (float)currentX
, -1, NULL
, "Vertical align");
785 currentX
+= width
+ dx
;
786 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, (wxBitmap
*)NULL
,
787 FALSE
, (float)currentX
, -1, NULL
, "Left align");
788 currentX
+= width
+ dx
;
789 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, (wxBitmap
*)NULL
,
790 FALSE
, (float)currentX
, -1, NULL
, "Right align");
791 currentX
+= width
+ dx
;
792 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, (wxBitmap
*)NULL
,
793 FALSE
, (float)currentX
, -1, NULL
, "Copy size");
794 currentX
+= width
+ dx
+ gap
;
795 toolbar
->AddSeparator();
796 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, (wxBitmap
*)NULL
,
797 FALSE
, (float)currentX
, -1, NULL
, "To front");
798 currentX
+= width
+ dx
;
799 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, (wxBitmap
*)NULL
,
800 FALSE
, (float)currentX
, -1, NULL
, "To back");
801 currentX
+= width
+ dx
+ gap
;
803 toolbar
->AddSeparator();
804 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, (wxBitmap
*)NULL
,
805 FALSE
, (float)currentX
, -1, NULL
, "Help");
806 currentX
+= width
+ dx
;
813 void wxResourceManager::UpdateResourceList()
815 if (!m_editorResourceTree
)
818 m_editorResourceTree
->SetInvalid(TRUE
);
819 m_editorResourceTree
->DeleteAllItems();
821 long id
= m_editorResourceTree
->InsertItem(0, "Dialogs"
827 m_resourceTable
.BeginFind();
829 while (node
= m_resourceTable
.Next())
831 wxItemResource
*res
= (wxItemResource
*)node
->Data();
832 wxString
resType(res
->GetType());
833 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
835 AddItemsRecursively(id
, res
);
838 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
839 m_editorResourceTree
->SetInvalid(FALSE
);
842 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
844 wxString
theString("");
845 theString
= resource
->GetName();
848 wxString
resType(resource
->GetType());
849 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
854 long id
= m_editorResourceTree
->InsertItem(parent
, theString
860 m_editorResourceTree
->SetItemData(id
, (long) resource
);
862 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
864 wxNode
*node
= resource
->GetChildren().First();
867 wxItemResource
*res
= (wxItemResource
*)node
->Data();
868 AddItemsRecursively(id
, res
);
872 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
875 bool wxResourceManager::EditSelectedResource()
877 int sel
= m_editorResourceTree
->GetSelection();
880 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
886 bool wxResourceManager::Edit(wxItemResource
*res
)
888 ClearCurrentDialog();
890 wxString
resType(res
->GetType());
891 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
895 wxMessageBox("Should not find panel in wxResourceManager::Edit");
900 long style
= res
->GetStyle();
901 res
->SetStyle(style
|wxRAISED_BORDER
);
903 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
906 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
908 panel
->PushEventHandler(handler
);
910 res
->SetStyle(style
);
911 handler
->AddChildHandlers(); // Add event handlers for all controls
912 AssociateResource(res
, panel
);
914 m_editorPanel
->m_childWindow
= panel
;
915 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
919 wxClientDC
dc(m_editorPanel
);
920 m_editorPanel
->DrawTitle(dc
);
925 bool wxResourceManager::CreateNewPanel()
927 ClearCurrentDialog();
930 MakeUniqueName("dialog", buf
);
932 wxItemResource
*resource
= new wxItemResource
;
933 resource
->SetType("wxDialog");
934 resource
->SetName(buf
);
935 resource
->SetTitle(buf
);
938 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
941 // This is now guaranteed to be unique, so just add to symbol table
942 m_symbolTable
.AddSymbol(newIdName
, id
);
944 m_resourceTable
.AddResource(resource
);
946 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
947 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
948 wxSize(400, 300), wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
949 m_editorPanel
->m_childWindow
= panel
;
951 resource
->SetStyle(panel
->GetWindowStyleFlag());
952 resource
->SetSize(10, 10, 400, 300);
954 // For editing in situ we will need to use the hash table to ensure
955 // we don't dereference invalid pointers.
956 // resourceWindowTable.Put((long)resource, panel);
958 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
960 panel
->PushEventHandler(handler
);
962 AssociateResource(resource
, panel
);
963 UpdateResourceList();
966 m_editorPanel
->m_childWindow
->Refresh();
970 wxClientDC
dc(m_editorPanel
);
971 m_editorPanel
->DrawTitle(dc
);
976 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
979 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
984 wxItemResource
*res
= new wxItemResource
;
985 wxControl
*newItem
= NULL
;
986 res
->SetSize(x
, y
, -1, -1);
991 wxString
itemType(iType
);
993 if (itemType
== "wxButton")
995 prefix
= "ID_BUTTON";
996 MakeUniqueName("button", buf
);
999 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1001 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1003 if (itemType
== "wxBitmapButton")
1005 prefix
= "ID_BITMAPBUTTON";
1006 MakeUniqueName("button", buf
);
1008 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1010 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1012 prefix
= "ID_STATIC";
1013 MakeUniqueName("statictext", buf
);
1016 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1018 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1020 else if (itemType
== "wxStaticBitmap")
1022 prefix
= "ID_STATICBITMAP";
1023 MakeUniqueName("static", buf
);
1025 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1027 else if (itemType
== "wxCheckBox")
1029 prefix
= "ID_CHECKBOX";
1030 MakeUniqueName("checkbox", buf
);
1032 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1034 else if (itemType
== "wxListBox")
1036 prefix
= "ID_LISTBOX";
1037 MakeUniqueName("listbox", buf
);
1039 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1041 else if (itemType
== "wxRadioBox")
1043 prefix
= "ID_RADIOBOX";
1044 MakeUniqueName("radiobox", buf
);
1046 wxString names
[] = { "One", "Two" };
1047 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1048 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1049 res
->SetStringValues(new wxStringList("One", "Two", NULL
));
1051 else if (itemType
== "wxRadioButton")
1053 prefix
= "ID_RADIOBUTTON";
1054 MakeUniqueName("radiobutton", buf
);
1056 wxString names
[] = { "One", "Two" };
1057 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1058 0, wxDefaultValidator
, buf
);
1060 else if (itemType
== "wxChoice")
1062 prefix
= "ID_CHOICE";
1063 MakeUniqueName("choice", buf
);
1065 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1067 else if (itemType
== "wxComboBox")
1069 prefix
= "ID_COMBOBOX";
1070 MakeUniqueName("combobox", buf
);
1072 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1074 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1076 prefix
= "ID_STATICBOX";
1077 MakeUniqueName("staticbox", buf
);
1079 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1081 else if (itemType
== "wxGauge")
1083 prefix
= "ID_GAUGE";
1084 MakeUniqueName("gauge", buf
);
1086 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1088 else if (itemType
== "wxSlider")
1090 prefix
= "ID_SLIDER";
1091 MakeUniqueName("slider", buf
);
1093 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1095 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1097 prefix
= "ID_TEXTCTRL";
1098 MakeUniqueName("textctrl", buf
);
1100 res
->SetType("wxTextCtrl");
1101 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1103 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1105 prefix
= "ID_TEXTCTRL";
1106 MakeUniqueName("textctrl", buf
);
1108 res
->SetType("wxTextCtrl");
1109 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1111 else if (itemType
== "wxScrollBar")
1113 prefix
= "ID_SCROLLBAR";
1114 MakeUniqueName("scrollbar", buf
);
1116 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1122 int id
= GenerateWindowId(prefix
, newIdName
);
1125 // This is now guaranteed to be unique, so just add to symbol table
1126 m_symbolTable
.AddSymbol(newIdName
, id
);
1128 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1130 res
->SetStyle(newItem
->GetWindowStyleFlag());
1131 AssociateResource(res
, newItem
);
1132 panelResource
->GetChildren().Append(res
);
1134 UpdateResourceList();
1139 void wxResourceManager::ClearCurrentDialog()
1141 if (m_editorPanel
->m_childWindow
)
1143 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1144 DisassociateResource(m_editorPanel
->m_childWindow
);
1145 DeleteWindow(m_editorPanel
->m_childWindow
);
1146 m_editorPanel
->m_childWindow
= NULL
;
1147 m_editorPanel
->Clear();
1151 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1153 if (m_editorPanel
->m_childWindow
)
1155 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1159 // Make sure the resources are up-to-date w.r.t. the window
1160 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1162 wxDialog
* dialog
= new wxDialog
;
1163 long oldStyle
= item
->GetStyle();
1164 bool success
= FALSE
;
1165 // item->SetStyle(wxDEFAULT_DIALOG_STYLE);
1166 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1169 dialog
->ShowModal();
1172 // item->SetStyle(oldStyle);
1178 // Find the first dialog or panel for which
1179 // there is a selected panel item.
1180 wxWindow
*wxResourceManager::FindParentOfSelection()
1182 m_resourceTable
.BeginFind();
1184 while (node
= m_resourceTable
.Next())
1186 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1187 wxWindow
*win
= FindWindowForResource(res
);
1190 wxNode
*node1
= win
->GetChildren()->First();
1193 wxControl
*item
= (wxControl
*)node1
->Data();
1194 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1195 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1197 node1
= node1
->Next();
1204 // Format the panel items according to 'flag'
1205 void wxResourceManager::AlignItems(int flag
)
1207 wxWindow
*win
= FindParentOfSelection();
1211 wxNode
*node
= GetSelections().First();
1215 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1216 if (firstSelection
->GetParent() != win
)
1221 firstSelection
->GetPosition(&firstX
, &firstY
);
1222 firstSelection
->GetSize(&firstW
, &firstH
);
1223 int centreX
= (int)(firstX
+ (firstW
/ 2));
1224 int centreY
= (int)(firstY
+ (firstH
/ 2));
1226 while (node
= node
->Next())
1228 wxControl
*item
= (wxControl
*)node
->Data();
1229 if (item
->GetParent() == win
)
1232 item
->GetPosition(&x
, &y
);
1233 item
->GetSize(&w
, &h
);
1239 case TOOLBAR_FORMAT_HORIZ
:
1242 newY
= (int)(centreY
- (h
/2.0));
1245 case TOOLBAR_FORMAT_VERT
:
1247 newX
= (int)(centreX
- (w
/2.0));
1251 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1257 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1263 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1265 newX
= firstX
+ firstW
- w
;
1269 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1272 newY
= firstY
+ firstH
- h
;
1280 item
->SetSize(newX
, newY
, w
, h
);
1286 // Copy the first image's size to subsequent images
1287 void wxResourceManager::CopySize()
1289 wxWindow
*win
= FindParentOfSelection();
1293 wxNode
*node
= GetSelections().First();
1297 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1298 if (firstSelection
->GetParent() != win
)
1303 firstSelection
->GetPosition(&firstX
, &firstY
);
1304 firstSelection
->GetSize(&firstW
, &firstH
);
1305 int centreX
= (int)(firstX
+ (firstW
/ 2));
1306 int centreY
= (int)(firstY
+ (firstH
/ 2));
1308 while (node
= node
->Next())
1310 wxControl
*item
= (wxControl
*)node
->Data();
1311 if (item
->GetParent() == win
)
1312 item
->SetSize(-1, -1, firstW
, firstH
);
1317 void wxResourceManager::ToBackOrFront(bool toBack
)
1319 wxWindow
*win
= FindParentOfSelection();
1322 wxItemResource
*winResource
= FindResourceForWindow(win
);
1324 wxNode
*node
= GetSelections().First();
1327 wxControl
*item
= (wxControl
*)node
->Data();
1328 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1329 if (item
->GetParent() == win
)
1331 win
->GetChildren()->DeleteObject(item
);
1333 winResource
->GetChildren().DeleteObject(itemResource
);
1336 win
->GetChildren()->Insert(item
);
1338 winResource
->GetChildren().Insert(itemResource
);
1342 win
->GetChildren()->Append(item
);
1344 winResource
->GetChildren().Append(itemResource
);
1347 node
= node
->Next();
1352 void wxResourceManager::AddSelection(wxWindow
*win
)
1354 if (!m_selections
.Member(win
))
1355 m_selections
.Append(win
);
1358 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1360 m_selections
.DeleteObject(win
);
1363 // Need to search through resource table removing this from
1364 // any resource which has this as a parent.
1365 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1367 m_resourceTable
.BeginFind();
1369 while (node
= m_resourceTable
.Next())
1371 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1372 if (thisRes
->GetChildren().Member(res
))
1374 thisRes
->GetChildren().DeleteObject(res
);
1381 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1386 RemoveResourceFromParent(res
);
1388 wxNode
*node
= res
->GetChildren().First();
1391 wxNode
*next
= node
->Next();
1392 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1393 DeleteResource(child
);
1397 // If this is a button or message resource, delete the
1398 // associate bitmap resource if not being used.
1399 wxString
resType(res
->GetType());
1401 if ((resType
== "wxMessage" || resType
== "wxStaticBitmap" || resType
== "wxButton" || resType
== "wxBitmapButton") && res
->GetValue4())
1403 PossiblyDeleteBitmapResource(res
->GetValue4());
1406 // Remove symbol from table if appropriate
1407 if (!IsSymbolUsed(res
, res
->GetId()))
1409 m_symbolTable
.RemoveSymbol(res
->GetId());
1412 m_resourceTable
.Delete(res
->GetName());
1418 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1420 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1422 // Deselect and refresh window in case we leave selection
1424 wxControl
*item
= (wxControl
*)win
;
1425 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1426 if (childHandler
->IsSelected())
1428 RemoveSelection(item
);
1429 childHandler
->SelectItem(FALSE
);
1430 item
->GetParent()->Refresh();
1434 wxItemResource
*res
= FindResourceForWindow(win
);
1436 DisassociateResource(res
);
1437 DeleteResource(res
);
1438 UpdateResourceList();
1443 // Will eventually have bitmap type information, for different
1445 char *wxResourceManager::AddBitmapResource(char *filename
)
1447 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1451 MakeUniqueName("bitmap", buf
);
1452 resource
= new wxItemResource
;
1453 resource
->SetType("wxBitmap");
1454 resource
->SetName(buf
);
1456 // A bitmap resource has one or more children, specifying
1457 // alternative bitmaps.
1458 wxItemResource
*child
= new wxItemResource
;
1459 child
->SetType("wxBitmap");
1460 child
->SetName(filename
);
1461 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1462 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1463 child
->SetValue3(0); // Depth
1464 child
->SetSize(0,0,0,0);
1465 resource
->GetChildren().Append(child
);
1467 m_resourceTable
.AddResource(resource
);
1469 UpdateResourceList();
1472 return resource
->GetName();
1477 // Delete the bitmap resource if it isn't being used by another resource.
1478 void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName
)
1480 if (!IsBitmapResourceUsed(resourceName
))
1482 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1483 DeleteResource(res
);
1484 UpdateResourceList();
1488 bool wxResourceManager::IsBitmapResourceUsed(char *resourceName
)
1490 m_resourceTable
.BeginFind();
1492 while (node
= m_resourceTable
.Next())
1494 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1495 wxString
resType(res
->GetType());
1496 if (resType
== "wxDialog")
1498 wxNode
*node1
= res
->GetChildren().First();
1501 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1502 wxString
childResType(child
->GetType());
1504 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1505 child
->GetValue4() &&
1506 (strcmp(child
->GetValue4(), resourceName
) == 0))
1508 node1
= node1
->Next();
1515 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1516 char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1518 if (!resource
|| !resource
->GetValue4())
1520 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1521 if (!bitmapResource
)
1524 wxNode
*node
= bitmapResource
->GetChildren().First();
1527 // Eventually augment this to return a bitmap of the right kind or something...
1528 // Maybe the root of the filename remains the same, so it doesn't matter which we
1529 // pick up. Otherwise how do we specify multiple filenames... too boring...
1530 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1531 return child
->GetName();
1533 node
= node
->Next();
1538 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(char *filename
)
1540 m_resourceTable
.BeginFind();
1542 while (node
= m_resourceTable
.Next())
1544 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1545 wxString
resType(res
->GetType());
1546 if (resType
== "wxBitmap")
1548 wxNode
*node1
= res
->GetChildren().First();
1551 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1552 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1554 node1
= node1
->Next();
1561 // Is this window identifier symbol in use?
1562 // Let's assume that we can't have 2 names for the same integer id.
1563 // Therefore we can tell by the integer id whether the symbol is
1565 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1567 m_resourceTable
.BeginFind();
1569 while (node
= m_resourceTable
.Next())
1571 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1573 wxString
resType(res
->GetType());
1574 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1576 if ((res
!= thisResource
) && (res
->GetId() == id
))
1579 wxNode
*node1
= res
->GetChildren().First();
1582 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1583 if ((child
!= thisResource
) && (child
->GetId() == id
))
1585 node1
= node1
->Next();
1592 // Is this window identifier compatible with the given name? (i.e.
1593 // does it already exist under a different name)
1594 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1596 if (m_symbolTable
.SymbolExists(name
))
1598 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1605 // Change all integer ids that match oldId, to newId.
1606 // This is necessary if an id is changed for one resource - all resources
1608 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1610 m_resourceTable
.BeginFind();
1612 while (node
= m_resourceTable
.Next())
1614 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1616 wxString
resType(res
->GetType());
1617 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1619 if (res
->GetId() == oldId
)
1622 wxNode
*node1
= res
->GetChildren().First();
1625 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1626 if (child
->GetId() == oldId
)
1627 child
->SetId(newId
);
1629 node1
= node1
->Next();
1635 // If any resource ids were missing (or their symbol was missing),
1636 // repair them i.e. give them new ids. Returns TRUE if any resource
1637 // needed repairing.
1638 bool wxResourceManager::RepairResourceIds()
1640 bool repaired
= FALSE
;
1642 m_resourceTable
.BeginFind();
1644 while (node
= m_resourceTable
.Next())
1646 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1647 wxString
resType(res
->GetType());
1648 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1651 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1653 wxString newSymbolName
;
1654 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1656 if (res
->GetId() == 0)
1659 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1663 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1669 wxNode
*node1
= res
->GetChildren().First();
1672 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1674 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1676 wxString newSymbolName
;
1677 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1679 if (child
->GetId() == 0)
1681 child
->SetId(newId
);
1682 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1686 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1692 node1
= node1
->Next();
1700 // Deletes 'win' and creates a new window from the resource that
1701 // was associated with it. E.g. if you can't change properties on the
1702 // fly, you'll need to delete the window and create it again.
1703 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1705 wxItemResource
*resource
= FindResourceForWindow(win
);
1707 // Put the current window properties into the wxItemResource object
1709 wxWindowPropertyInfo
*newInfo
= NULL
;
1712 newInfo
= CreatePropertyInfoForWindow(win
);
1716 info
->InstantiateResource(resource
);
1718 wxWindow
*newWin
= NULL
;
1719 wxWindow
*parent
= win
->GetParent();
1721 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1724 newWin
= FindWindowForResource(resource
);
1728 DisassociateResource(resource
);
1729 if (win
->GetEventHandler() != win
)
1730 win
->PopEventHandler(TRUE
);
1733 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
);
1734 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1735 AssociateResource(resource
, newWin
);
1736 UpdateResourceList();
1740 info
->SetPropertyWindow(newWin
);
1748 // Delete resource highlighted in the listbox
1749 bool wxResourceManager::DeleteSelection()
1751 int sel
= m_editorResourceTree
->GetSelection();
1754 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
1755 wxWindow
*win
= FindWindowForResource(res
);
1758 DeleteResource(win
);
1760 UpdateResourceList();
1769 // Delete resource highlighted in the listbox
1770 bool wxResourceManager::RecreateSelection()
1772 wxNode
*node
= GetSelections().First();
1775 wxControl
*item
= (wxControl
*)node
->Data();
1776 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1777 wxNode
*next
= node
->Next();
1778 childHandler
->SelectItem(FALSE
);
1780 RemoveSelection(item
);
1782 RecreateWindowFromResource(item
);
1789 bool wxResourceManager::EditDialog(wxDialog
*dialog
, wxWindow
*parent
)
1794 // Ensures that all currently shown windows are saved to resources,
1795 // e.g. just before writing to a .wxr file.
1796 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1798 m_resourceTable
.BeginFind();
1800 while (node
= m_resourceTable
.Next())
1802 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1803 wxString
resType(res
->GetType());
1805 if (resType
== "wxDialog")
1807 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1809 InstantiateResourceFromWindow(res
, win
, TRUE
);
1811 else if (resType
== "wxPanel")
1813 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1815 InstantiateResourceFromWindow(res
, win
, TRUE
);
1821 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1823 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1824 info
->SetResource(resource
);
1825 info
->InstantiateResource(resource
);
1830 wxNode
*node
= resource
->GetChildren().First();
1833 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1834 wxWindow
*childWindow
= FindWindowForResource(child
);
1839 sprintf(buf
, "Could not find window %s", child
->GetName());
1840 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1843 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1844 node
= node
->Next();
1851 // Create a window information object for the give window
1852 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1854 wxWindowPropertyInfo
*info
= NULL
;
1855 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1857 info
= new wxScrollBarPropertyInfo(win
);
1859 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1861 info
= new wxGroupBoxPropertyInfo(win
);
1863 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1865 info
= new wxCheckBoxPropertyInfo(win
);
1867 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1869 info
= new wxSliderPropertyInfo(win
);
1871 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1873 info
= new wxGaugePropertyInfo(win
);
1875 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1877 info
= new wxListBoxPropertyInfo(win
);
1879 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1881 info
= new wxRadioBoxPropertyInfo(win
);
1883 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1885 info
= new wxRadioButtonPropertyInfo(win
);
1887 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1889 info
= new wxChoicePropertyInfo(win
);
1891 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
1893 info
= new wxComboBoxPropertyInfo(win
);
1895 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1897 info
= new wxButtonPropertyInfo(win
);
1899 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1901 info
= new wxBitmapButtonPropertyInfo(win
);
1903 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1905 info
= new wxStaticTextPropertyInfo(win
);
1907 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1909 info
= new wxStaticBitmapPropertyInfo(win
);
1911 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1913 info
= new wxTextPropertyInfo(win
);
1915 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1917 info
= new wxPanelPropertyInfo(win
);
1921 info
= new wxWindowPropertyInfo(win
);
1926 // Edit the given window
1927 void wxResourceManager::EditWindow(wxWindow
*win
)
1929 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
1932 info
->SetResource(FindResourceForWindow(win
));
1933 wxString
str("Editing ");
1934 str
+= win
->GetClassInfo()->GetClassName();
1936 if (win
->GetName() != "")
1937 str
+= win
->GetName();
1939 str
+= "properties";
1940 info
->Edit(NULL
, str
);
1944 // Generate a window id and a first stab at a name
1945 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
1947 m_symbolIdCounter
++;
1948 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
1949 m_symbolIdCounter
++;
1951 int nameId
= m_symbolIdCounter
;
1954 str
.Printf("%d", nameId
);
1955 idName
= prefix
+ str
;
1957 while (m_symbolTable
.SymbolExists(idName
))
1960 str
.Printf("%d", nameId
);
1961 idName
= prefix
+ str
;
1964 return m_symbolIdCounter
;
1969 * Resource editor frame
1972 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
1974 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
1975 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
1976 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
1977 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
1978 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
1979 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
1980 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
1981 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
1982 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
1983 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
1984 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
1985 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
1986 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
1989 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
1990 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
1991 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
1996 wxResourceEditorFrame::~wxResourceEditorFrame()
2000 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2002 manager
->New(FALSE
);
2005 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2007 manager
->CreateNewPanel();
2010 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2015 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2017 manager
->Clear(TRUE
, FALSE
);
2020 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2025 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2030 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2032 manager
->Clear(TRUE
, FALSE
) ;
2036 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2039 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
2040 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2043 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2045 manager
->TestCurrentDialog(this);
2048 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2051 wxBeginBusyCursor();
2052 manager
->GetHelpController()->LoadFile();
2053 manager
->GetHelpController()->DisplayContents();
2058 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2060 manager
->DeleteSelection();
2063 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2065 manager
->RecreateSelection();
2068 bool wxResourceEditorFrame::OnClose()
2070 if (manager
->Modified())
2072 if (!manager
->Clear(TRUE
, FALSE
))
2080 manager
->m_resourceEditorWindowSize
.width
= w
;
2081 manager
->m_resourceEditorWindowSize
.height
= h
;
2084 GetPosition(&x
, &y
);
2086 manager
->m_resourceEditorWindowSize
.x
= x
;
2087 manager
->m_resourceEditorWindowSize
.y
= y
;
2089 manager
->SetEditorFrame(NULL
);
2090 manager
->SetEditorToolBar(NULL
);
2096 * Resource editor window that contains the dialog/panel being edited
2099 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2100 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
2101 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2104 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2106 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2110 m_childWindow
= NULL
;
2113 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2117 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
2119 wxScrolledWindow::OnScroll(event
);
2122 ViewStart(& x
, & y
);
2125 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
2128 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2135 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2139 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2142 wxString
str(res
->GetTitle());
2144 ViewStart(& x
, & y
);
2146 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2148 dc
.SetBackgroundMode(wxTRANSPARENT
);
2149 dc
.SetTextForeground(wxColour(0, 0, 0));
2152 dc
.GetTextExtent(str
, & w
, & h
);
2154 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2159 // Popup menu callback
2160 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2162 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2166 switch (event
.GetInt())
2168 case OBJECT_MENU_EDIT
:
2170 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2173 case OBJECT_MENU_DELETE
:
2175 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2176 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2177 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2190 #ifdef __WXGTK__ // I don't dare to delete it...
2192 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2197 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2198 EVT_PAINT(EditorToolBar::OnPaint
)
2203 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2205 wxToolBar(frame
, -1, pos
, size
, style
)
2209 bool EditorToolBar::OnLeftClick(int toolIndex
, bool toggled
)
2211 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2215 case TOOLBAR_LOAD_FILE
:
2222 manager
->CreateNewPanel();
2225 case TOOLBAR_SAVE_FILE
:
2233 wxBeginBusyCursor();
2234 manager
->GetHelpController()->LoadFile();
2235 manager
->GetHelpController()->DisplayContents();
2240 case TOOLBAR_FORMAT_HORIZ
:
2242 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2245 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2247 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2250 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2252 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2255 case TOOLBAR_FORMAT_VERT
:
2257 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2260 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2262 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2265 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2267 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2270 case TOOLBAR_COPY_SIZE
:
2272 manager
->CopySize();
2275 case TOOLBAR_TO_BACK
:
2277 manager
->ToBackOrFront(TRUE
);
2280 case TOOLBAR_TO_FRONT
:
2282 manager
->ToBackOrFront(FALSE
);
2291 void EditorToolBar::OnMouseEnter(int toolIndex
)
2293 wxFrame
*frame
= (wxFrame
*)GetParent();
2301 case TOOLBAR_LOAD_FILE
:
2302 frame
->SetStatusText("Load project file");
2304 case TOOLBAR_SAVE_FILE
:
2305 frame
->SetStatusText("Save project file");
2308 frame
->SetStatusText("Create a new resource");
2310 case TOOLBAR_FORMAT_HORIZ
:
2311 frame
->SetStatusText("Align items horizontally");
2313 case TOOLBAR_FORMAT_VERT
:
2314 frame
->SetStatusText("Align items vertically");
2316 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2317 frame
->SetStatusText("Left-align items");
2319 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2320 frame
->SetStatusText("Right-align items");
2322 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2323 frame
->SetStatusText("Top-align items");
2325 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2326 frame
->SetStatusText("Bottom-align items");
2328 case TOOLBAR_COPY_SIZE
:
2329 frame
->SetStatusText("Copy size from first selection");
2331 case TOOLBAR_TO_FRONT
:
2332 frame
->SetStatusText("Put image to front");
2334 case TOOLBAR_TO_BACK
:
2335 frame
->SetStatusText("Put image to back");
2338 frame
->SetStatusText("Display help contents");
2344 else frame
->SetStatusText("");