1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource editor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "reseditr.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/checkbox.h"
27 #include "wx/button.h"
28 #include "wx/choice.h"
29 #include "wx/listbox.h"
30 #include "wx/radiobox.h"
31 #include "wx/statbox.h"
33 #include "wx/slider.h"
34 #include "wx/textctrl.h"
37 #include "wx/scrolbar.h"
44 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
47 #include <strstream.h>
62 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
63 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
66 #include "bitmaps/load.xbm"
67 #include "bitmaps/save.xbm"
68 #include "bitmaps/new.xbm"
69 #include "bitmaps/vert.xbm"
70 #include "bitmaps/alignt.xbm"
71 #include "bitmaps/alignb.xbm"
72 #include "bitmaps/horiz.xbm"
73 #include "bitmaps/alignl.xbm"
74 #include "bitmaps/alignr.xbm"
75 #include "bitmaps/copysize.xbm"
76 #include "bitmaps/tofront.xbm"
77 #include "bitmaps/toback.xbm"
78 #include "bitmaps/help.xbm"
79 #include "bitmaps/wxwin.xbm"
86 wxResourceManager::wxResourceManager():
87 m_imageList(16, 16, TRUE
)
89 sm_currentResourceManager
= this;
93 m_editorResourceTree
= NULL
;
94 m_editorControlList
= NULL
;
96 m_symbolIdCounter
= 99;
98 m_currentFilename
= "";
99 m_symbolFilename
= "";
100 m_editorToolBar
= NULL
;
102 // Default window positions
103 m_resourceEditorWindowSize
.width
= 470;
104 m_resourceEditorWindowSize
.height
= 300;
106 m_resourceEditorWindowSize
.x
= 0;
107 m_resourceEditorWindowSize
.y
= 0;
109 m_propertyWindowSize
.width
= 300;
110 m_propertyWindowSize
.height
= 300;
112 m_helpController
= NULL
;
114 m_bitmapImage
= NULL
;
115 m_rootDialogItem
= 0;
118 wxResourceManager::~wxResourceManager()
120 sm_currentResourceManager
= NULL
;
123 if (m_helpController
)
125 m_helpController
->Quit();
126 delete m_helpController
;
127 m_helpController
= NULL
;
129 delete m_bitmapImage
;
133 bool wxResourceManager::Initialize()
135 // Set up the resource filename for each platform.
137 // dialoged.ini in the Windows directory
139 GetWindowsDirectory(buf
, 256);
140 strcat(buf
, "\\dialoged.ini");
141 m_optionsResourceFilename
= buf
;
145 strcat(buf
, "/.dialogedrc");
146 m_optionsResourceFilename
= buf
;
148 #error "Unsupported platform."
153 m_helpController
= new wxHelpController
;
154 m_helpController
->Initialize("dialoged");
156 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
157 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
158 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
163 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
166 m_bitmapImage
= new wxBitmap(wxwin_bits
, wxwin_width
, wxwin_height
);
170 // Initialize the image list icons
172 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
173 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
174 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
175 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
176 m_imageList
.Add(icon1
);
177 m_imageList
.Add(icon2
);
178 m_imageList
.Add(icon3
);
179 m_imageList
.Add(icon4
);
182 m_symbolTable
.AddStandardSymbols();
187 bool wxResourceManager::LoadOptions()
189 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize
.x
, m_optionsResourceFilename
.GetData());
190 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize
.y
, m_optionsResourceFilename
.GetData());
191 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize
.width
, m_optionsResourceFilename
.GetData());
192 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize
.height
, m_optionsResourceFilename
.GetData());
193 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize
.x
, m_optionsResourceFilename
.GetData());
194 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize
.y
, m_optionsResourceFilename
.GetData());
195 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize
.width
, m_optionsResourceFilename
.GetData());
196 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize
.height
, m_optionsResourceFilename
.GetData());
200 bool wxResourceManager::SaveOptions()
202 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize
.x
, m_optionsResourceFilename
.GetData());
203 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize
.y
, m_optionsResourceFilename
.GetData());
204 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize
.width
, m_optionsResourceFilename
.GetData());
205 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize
.height
, m_optionsResourceFilename
.GetData());
207 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize
.x
, m_optionsResourceFilename
.GetData());
208 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize
.y
, m_optionsResourceFilename
.GetData());
209 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize
.width
, m_optionsResourceFilename
.GetData());
210 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize
.height
, m_optionsResourceFilename
.GetData());
215 // Show or hide the resource editor frame, which displays a list
216 // of resources with ability to edit them.
217 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*parent
, const char *title
)
223 m_editorFrame
->Iconize(FALSE
);
224 m_editorFrame
->Show(TRUE
);
227 m_editorFrame
= OnCreateEditorFrame(title
);
229 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
230 m_editorFrame
->SetMenuBar(menuBar
);
232 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
233 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
234 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
236 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
238 m_editorResourceTree
->SetImageList(& m_imageList
);
240 // Constraints for toolbar
241 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
242 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
243 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
244 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
245 c
->bottom
.Unconstrained();
246 c
->width
.Unconstrained();
247 c
->height
.Absolute(28);
248 m_editorToolBar
->SetConstraints(c
);
250 // Constraints for listbox
251 c
= new wxLayoutConstraints
;
252 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
253 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
254 c
->right
.Absolute (150);
255 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
256 c
->width
.Unconstrained();
257 c
->height
.Unconstrained();
258 m_editorResourceTree
->SetConstraints(c
);
260 // Constraints for panel
261 c
= new wxLayoutConstraints
;
262 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
263 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
264 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
265 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
266 c
->width
.Unconstrained();
267 c
->height
.Unconstrained();
268 m_editorPanel
->SetConstraints(c
);
270 // Constraints for control list (bottom window)
271 c
= new wxLayoutConstraints
;
272 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
273 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
274 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
275 c
->width
.Unconstrained();
276 c
->height
.Absolute(60);
277 m_editorControlList
->SetConstraints(c
);
279 m_editorFrame
->SetAutoLayout(TRUE
);
281 UpdateResourceList();
283 m_editorFrame
->Show(TRUE
);
288 wxFrame
*fr
= m_editorFrame
;
289 if (m_editorFrame
->OnClose())
293 m_editorFrame
= NULL
;
294 m_editorPanel
= NULL
;
300 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
304 if (filename
== wxString(""))
305 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
308 wxString
str("wxWindows Dialog Editor - ");
309 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
311 m_editorFrame
->SetTitle(str
);
316 bool wxResourceManager::Save()
318 if (m_currentFilename
== wxString(""))
321 return Save(m_currentFilename
);
324 bool wxResourceManager::Save(const wxString
& filename
)
326 // Ensure all visible windows are saved to their resources
327 m_currentFilename
= filename
;
328 SetFrameTitle(m_currentFilename
);
329 InstantiateAllResourcesFromWindows();
330 if (m_resourceTable
.Save(filename
))
339 bool wxResourceManager::SaveAs()
341 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
342 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
));
344 if (s
.IsNull() || s
== "")
347 m_currentFilename
= s
;
348 Save(m_currentFilename
);
352 bool wxResourceManager::SaveIfModified()
359 bool wxResourceManager::Load(const wxString
& filename
)
361 return New(TRUE
, filename
);
364 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
366 if (!Clear(TRUE
, FALSE
))
369 m_symbolTable
.AddStandardSymbols();
373 wxString str
= filename
;
374 if (str
== wxString(""))
376 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, NULL
));
377 if (!f
.IsNull() && f
!= "")
383 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
385 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
388 m_currentFilename
= str
;
390 SetFrameTitle(m_currentFilename
);
392 UpdateResourceList();
394 // Construct include filename from this file
395 m_symbolFilename
= m_currentFilename
;
397 wxStripExtension(m_symbolFilename
);
398 m_symbolFilename
+= ".h";
400 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
402 wxString
str("Could not find include file ");
403 str
+= m_symbolFilename
;
404 wxMessageBox(str
, "Dialog Editor Warning", MB_OK
);
406 m_symbolIdCounter
= 99;
410 // Set the id counter to the last known id
411 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
417 m_currentFilename
= "";
424 bool wxResourceManager::Clear(bool deleteWindows
, bool force
)
426 if (!force
&& Modified())
428 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
432 if (!SaveIfModified())
438 ClearCurrentDialog();
439 DisassociateWindows();
441 m_symbolTable
.Clear();
442 m_resourceTable
.ClearTable();
443 UpdateResourceList();
448 bool wxResourceManager::DisassociateWindows()
450 m_resourceTable
.BeginFind();
452 while (node
= m_resourceTable
.Next())
454 wxItemResource
*res
= (wxItemResource
*)node
->Data();
455 DisassociateResource(res
);
461 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
463 if (!m_resourceAssociations
.Get((long)resource
))
464 m_resourceAssociations
.Put((long)resource
, win
);
466 wxNode
*node
= resource
->GetChildren().First();
469 wxItemResource
*child
= (wxItemResource
*)node
->Data();
470 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
472 childWindow
= win
->FindWindow(child
->GetName());
474 AssociateResource(child
, childWindow
);
478 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? child
->GetName() : "(unnamed)");
479 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
486 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
488 wxWindow
*win
= FindWindowForResource(resource
);
492 // Disassociate children of window
493 if (win
->GetChildren())
495 wxNode
*node
= win
->GetChildren()->First();
498 wxWindow
*child
= (wxWindow
*)node
->Data();
499 if (child
->IsKindOf(CLASSINFO(wxControl
)))
500 DisassociateResource(child
);
505 RemoveSelection(win
);
506 m_resourceAssociations
.Delete((long)resource
);
510 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
512 wxItemResource
*res
= FindResourceForWindow(win
);
514 return DisassociateResource(res
);
519 // Saves the window info into the resource, and deletes the
520 // handler. Doesn't actually disassociate the window from
521 // the resources. Replaces OnClose.
522 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
524 wxItemResource
*res
= FindResourceForWindow(win
);
526 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
528 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
529 win
->PopEventHandler();
531 // Now reset all child event handlers
532 wxNode
*node
= win
->GetChildren()->First();
535 wxWindow
*child
= (wxWindow
*)node
->Data();
536 wxEvtHandler
*childHandler
= child
->GetEventHandler();
537 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
539 child
->PopEventHandler(TRUE
);
547 win
->PopEventHandler(TRUE
);
550 // Save the information
551 InstantiateResourceFromWindow(res
, win
, TRUE
);
553 // DisassociateResource(win);
558 // Destroys the window. If this is the 'current' panel, NULLs the
560 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
562 bool clearDisplay
= FALSE
;
563 if (m_editorPanel
->m_childWindow
== win
)
565 m_editorPanel
->m_childWindow
= NULL
;
572 m_editorPanel
->Clear();
577 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
579 m_resourceAssociations
.BeginFind();
581 while (node
= m_resourceAssociations
.Next())
583 wxWindow
*w
= (wxWindow
*)node
->Data();
586 return (wxItemResource
*)node
->key
.integer
;
592 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
594 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
598 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
602 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
605 if (!m_resourceTable
.FindResource(buf
))
610 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
612 int frameWidth
= 420;
613 int frameHeight
= 300;
615 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
616 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
617 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
618 wxDEFAULT_FRAME_STYLE
);
620 frame
->CreateStatusBar(1);
622 frame
->SetAutoLayout(TRUE
);
624 wxIcon
*icon
= new wxIcon("DIALOGEDICON");
625 frame
->SetIcon(icon
);
630 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*parent
)
632 wxMenuBar
*menuBar
= new wxMenuBar
;
634 wxMenu
*fileMenu
= new wxMenu
;
635 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
636 fileMenu
->AppendSeparator();
637 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
638 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
639 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
640 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
641 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
642 fileMenu
->AppendSeparator();
643 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
645 wxMenu
*editMenu
= new wxMenu
;
646 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
647 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
648 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
650 wxMenu
*helpMenu
= new wxMenu
;
651 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
652 helpMenu
->AppendSeparator();
653 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
655 menuBar
->Append(fileMenu
, "&File");
656 menuBar
->Append(editMenu
, "&Edit");
657 menuBar
->Append(helpMenu
, "&Help");
662 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
664 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
665 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
668 panel
->SetScrollbars(10, 10, 100, 100);
673 wxToolBarBase
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
675 // Load palette bitmaps
677 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
678 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
679 wxBitmap
ToolbarNewBitmap("NEWTOOL");
680 wxBitmap
ToolbarVertBitmap("VERTTOOL");
681 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
682 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
683 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
684 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
685 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
686 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
687 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
688 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
689 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
692 wxBitmap
ToolbarLoadBitmap(load_bits
, load_width
, load_height
);
693 wxBitmap
ToolbarSaveBitmap(save_bits
, save_width
, save_height
);
694 wxBitmap
ToolbarNewBitmap(new_bits
, save_width
, save_height
);
695 wxBitmap
ToolbarVertBitmap(vert_bits
, vert_width
, vert_height
);
696 wxBitmap
ToolbarAlignTBitmap(alignt_bits
, alignt_width
, alignt_height
);
697 wxBitmap
ToolbarAlignBBitmap(alignb_bits
, alignb_width
, alignb_height
);
698 wxBitmap
ToolbarHorizBitmap(horiz_bits
, horiz_width
, horiz_height
);
699 wxBitmap
ToolbarAlignLBitmap(alignl_bits
, alignl_width
, alignl_height
);
700 wxBitmap
ToolbarAlignRBitmap(alignr_bits
, alignr_width
, alignr_height
);
701 wxBitmap
ToolbarCopySizeBitmap(copysize_bits
, copysize_width
, copysize_height
);
702 wxBitmap
ToolbarToBackBitmap(toback_bits
, toback_width
, toback_height
);
703 wxBitmap
ToolbarToFrontBitmap(tofront_bits
, tofront_width
, tofront_height
);
704 wxBitmap
ToolbarHelpBitmap(help_bits
, help_width
, help_height
);
707 // Create the toolbar
708 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
709 toolbar
->SetMargins(2, 2);
716 int width
= ToolbarLoadBitmap
->GetWidth();
721 toolbar
->AddSeparator();
722 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, (wxBitmap
*)NULL
,
723 FALSE
, (float)currentX
, -1, NULL
, "New dialog");
724 currentX
+= width
+ dx
;
725 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, (wxBitmap
*)NULL
,
726 FALSE
, (float)currentX
, -1, NULL
, "Load");
727 currentX
+= width
+ dx
;
728 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, (wxBitmap
*)NULL
,
729 FALSE
, (float)currentX
, -1, NULL
, "Save");
730 currentX
+= width
+ dx
+ gap
;
731 toolbar
->AddSeparator();
732 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, (wxBitmap
*)NULL
,
733 FALSE
, (float)currentX
, -1, NULL
, "Horizontal align");
734 currentX
+= width
+ dx
;
735 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, (wxBitmap
*)NULL
,
736 FALSE
, (float)currentX
, -1, NULL
, "Top align");
737 currentX
+= width
+ dx
;
738 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, (wxBitmap
*)NULL
,
739 FALSE
, (float)currentX
, -1, NULL
, "Bottom align");
740 currentX
+= width
+ dx
;
741 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, (wxBitmap
*)NULL
,
742 FALSE
, (float)currentX
, -1, NULL
, "Vertical align");
743 currentX
+= width
+ dx
;
744 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, (wxBitmap
*)NULL
,
745 FALSE
, (float)currentX
, -1, NULL
, "Left align");
746 currentX
+= width
+ dx
;
747 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, (wxBitmap
*)NULL
,
748 FALSE
, (float)currentX
, -1, NULL
, "Right align");
749 currentX
+= width
+ dx
;
750 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, (wxBitmap
*)NULL
,
751 FALSE
, (float)currentX
, -1, NULL
, "Copy size");
752 currentX
+= width
+ dx
+ gap
;
753 toolbar
->AddSeparator();
754 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, (wxBitmap
*)NULL
,
755 FALSE
, (float)currentX
, -1, NULL
, "To front");
756 currentX
+= width
+ dx
;
757 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, (wxBitmap
*)NULL
,
758 FALSE
, (float)currentX
, -1, NULL
, "To back");
759 currentX
+= width
+ dx
+ gap
;
761 toolbar
->AddSeparator();
762 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, (wxBitmap
*)NULL
,
763 FALSE
, (float)currentX
, -1, NULL
, "Help");
764 currentX
+= width
+ dx
;
771 void wxResourceManager::UpdateResourceList()
773 if (!m_editorResourceTree
)
776 m_editorResourceTree
->SetInvalid(TRUE
);
777 m_editorResourceTree
->DeleteAllItems();
779 long id
= m_editorResourceTree
->InsertItem(0, "Dialogs"
785 m_resourceTable
.BeginFind();
787 while (node
= m_resourceTable
.Next())
789 wxItemResource
*res
= (wxItemResource
*)node
->Data();
790 wxString
resType(res
->GetType());
791 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
793 AddItemsRecursively(id
, res
);
796 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
797 m_editorResourceTree
->SetInvalid(FALSE
);
800 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
802 wxString
theString("");
803 theString
= resource
->GetName();
806 wxString
resType(resource
->GetType());
807 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
812 long id
= m_editorResourceTree
->InsertItem(parent
, theString
818 m_editorResourceTree
->SetItemData(id
, (long) resource
);
820 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
822 wxNode
*node
= resource
->GetChildren().First();
825 wxItemResource
*res
= (wxItemResource
*)node
->Data();
826 AddItemsRecursively(id
, res
);
830 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
833 bool wxResourceManager::EditSelectedResource()
835 int sel
= m_editorResourceTree
->GetSelection();
838 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
844 bool wxResourceManager::Edit(wxItemResource
*res
)
846 ClearCurrentDialog();
848 wxString
resType(res
->GetType());
849 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
853 wxMessageBox("Should not find panel in wxResourceManager::Edit");
858 long style
= res
->GetStyle();
859 res
->SetStyle(style
|wxRAISED_BORDER
);
861 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
864 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
866 panel
->PushEventHandler(handler
);
868 res
->SetStyle(style
);
869 handler
->AddChildHandlers(); // Add event handlers for all controls
870 AssociateResource(res
, panel
);
872 m_editorPanel
->m_childWindow
= panel
;
873 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
877 wxClientDC
dc(m_editorPanel
);
878 m_editorPanel
->DrawTitle(dc
);
883 bool wxResourceManager::CreateNewPanel()
885 ClearCurrentDialog();
888 MakeUniqueName("panel", buf
);
890 wxItemResource
*resource
= new wxItemResource
;
891 // resource->SetType(wxTYPE_PANEL);
892 resource
->SetType("wxPanel");
893 resource
->SetName(buf
);
894 resource
->SetTitle(buf
);
897 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
900 // This is now guaranteed to be unique, so just add to symbol table
901 m_symbolTable
.AddSymbol(newIdName
, id
);
903 m_resourceTable
.AddResource(resource
);
905 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
906 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
907 wxSize(400, 300), wxRAISED_BORDER
, buf
);
908 m_editorPanel
->m_childWindow
= panel
;
910 resource
->SetStyle(0); // panel->GetWindowStyleFlag());
911 resource
->SetSize(10, 10, 400, 300);
913 // For editing in situ we will need to use the hash table to ensure
914 // we don't dereference invalid pointers.
915 // resourceWindowTable.Put((long)resource, panel);
917 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
919 panel
->PushEventHandler(handler
);
921 AssociateResource(resource
, panel
);
922 UpdateResourceList();
925 m_editorPanel
->m_childWindow
->Refresh();
929 wxClientDC
dc(m_editorPanel
);
930 m_editorPanel
->DrawTitle(dc
);
935 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
938 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
943 wxItemResource
*res
= new wxItemResource
;
944 wxControl
*newItem
= NULL
;
945 res
->SetSize(x
, y
, -1, -1);
950 wxString
itemType(iType
);
952 if (itemType
== "wxButton")
954 prefix
= "ID_BUTTON";
955 MakeUniqueName("button", buf
);
958 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
960 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
962 if (itemType
== "wxBitmapButton")
964 prefix
= "ID_BITMAPBUTTON";
965 MakeUniqueName("button", buf
);
967 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
969 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
971 prefix
= "ID_STATIC";
972 MakeUniqueName("message", buf
);
975 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
977 newItem
= new wxStaticText(panel
, -1, "Message", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
979 else if (itemType
== "wxStaticBitmap")
981 prefix
= "ID_STATICBITMAP";
982 MakeUniqueName("message", buf
);
984 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
986 else if (itemType
== "wxCheckBox")
988 prefix
= "ID_CHECKBOX";
989 MakeUniqueName("checkbox", buf
);
991 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
993 else if (itemType
== "wxListBox")
995 prefix
= "ID_LISTBIX";
996 MakeUniqueName("listbox", buf
);
998 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1000 else if (itemType
== "wxRadioBox")
1002 prefix
= "ID_RADIOBOX";
1003 MakeUniqueName("radiobox", buf
);
1005 wxString names
[] = { "One", "Two" };
1006 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1007 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1008 res
->SetStringValues(new wxStringList("One", "Two", NULL
));
1010 else if (itemType
== "wxRadioButton")
1012 prefix
= "ID_RADIOBUTTON";
1013 MakeUniqueName("radiobutton", buf
);
1015 wxString names
[] = { "One", "Two" };
1016 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1017 0, wxDefaultValidator
, buf
);
1019 else if (itemType
== "wxChoice")
1021 prefix
= "ID_CHOICE";
1022 MakeUniqueName("choice", buf
);
1024 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1026 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1028 prefix
= "ID_STATICBOX";
1029 MakeUniqueName("group", buf
);
1031 newItem
= new wxStaticBox(panel
, -1, "Groupbox", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1033 else if (itemType
== "wxGauge")
1035 prefix
= "ID_GAUGE";
1036 MakeUniqueName("gauge", buf
);
1038 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1040 else if (itemType
== "wxSlider")
1042 prefix
= "ID_SLIDER";
1043 MakeUniqueName("slider", buf
);
1045 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1047 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1049 prefix
= "ID_TEXTCTRL";
1050 MakeUniqueName("textctrl", buf
);
1052 res
->SetType("wxTextCtrl");
1053 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1055 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1057 prefix
= "ID_TEXTCTRL";
1058 MakeUniqueName("textctrl", buf
);
1060 res
->SetType("wxTextCtrl");
1061 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1063 else if (itemType
== "wxScrollBar")
1065 prefix
= "ID_SCROLLBAR";
1066 MakeUniqueName("scrollbar", buf
);
1068 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1074 int id
= GenerateWindowId(prefix
, newIdName
);
1077 // This is now guaranteed to be unique, so just add to symbol table
1078 m_symbolTable
.AddSymbol(newIdName
, id
);
1080 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1082 res
->SetStyle(newItem
->GetWindowStyleFlag());
1083 AssociateResource(res
, newItem
);
1084 panelResource
->GetChildren().Append(res
);
1086 UpdateResourceList();
1091 void wxResourceManager::ClearCurrentDialog()
1093 if (m_editorPanel
->m_childWindow
)
1095 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1096 DisassociateResource(m_editorPanel
->m_childWindow
);
1097 DeleteWindow(m_editorPanel
->m_childWindow
);
1098 m_editorPanel
->m_childWindow
= NULL
;
1099 m_editorPanel
->Clear();
1103 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1105 if (m_editorPanel
->m_childWindow
)
1107 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1111 // Make sure the resources are up-to-date w.r.t. the window
1112 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1114 wxDialog
* dialog
= new wxDialog
;
1115 long oldStyle
= item
->GetStyle();
1116 bool success
= FALSE
;
1117 item
->SetStyle(wxDEFAULT_DIALOG_STYLE
);
1118 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1121 dialog
->ShowModal();
1124 item
->SetStyle(oldStyle
);
1130 // Find the first dialog or panel for which
1131 // there is a selected panel item.
1132 wxWindow
*wxResourceManager::FindParentOfSelection()
1134 m_resourceTable
.BeginFind();
1136 while (node
= m_resourceTable
.Next())
1138 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1139 wxWindow
*win
= FindWindowForResource(res
);
1142 wxNode
*node1
= win
->GetChildren()->First();
1145 wxControl
*item
= (wxControl
*)node1
->Data();
1146 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1147 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1149 node1
= node1
->Next();
1156 // Format the panel items according to 'flag'
1157 void wxResourceManager::AlignItems(int flag
)
1159 wxWindow
*win
= FindParentOfSelection();
1163 wxNode
*node
= GetSelections().First();
1167 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1168 if (firstSelection
->GetParent() != win
)
1173 firstSelection
->GetPosition(&firstX
, &firstY
);
1174 firstSelection
->GetSize(&firstW
, &firstH
);
1175 int centreX
= (int)(firstX
+ (firstW
/ 2));
1176 int centreY
= (int)(firstY
+ (firstH
/ 2));
1178 while (node
= node
->Next())
1180 wxControl
*item
= (wxControl
*)node
->Data();
1181 if (item
->GetParent() == win
)
1184 item
->GetPosition(&x
, &y
);
1185 item
->GetSize(&w
, &h
);
1191 case TOOLBAR_FORMAT_HORIZ
:
1194 newY
= (int)(centreY
- (h
/2.0));
1197 case TOOLBAR_FORMAT_VERT
:
1199 newX
= (int)(centreX
- (w
/2.0));
1203 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1209 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1215 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1217 newX
= firstX
+ firstW
- w
;
1221 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1224 newY
= firstY
+ firstH
- h
;
1232 item
->SetSize(newX
, newY
, w
, h
);
1238 // Copy the first image's size to subsequent images
1239 void wxResourceManager::CopySize()
1241 wxWindow
*win
= FindParentOfSelection();
1245 wxNode
*node
= GetSelections().First();
1249 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1250 if (firstSelection
->GetParent() != win
)
1255 firstSelection
->GetPosition(&firstX
, &firstY
);
1256 firstSelection
->GetSize(&firstW
, &firstH
);
1257 int centreX
= (int)(firstX
+ (firstW
/ 2));
1258 int centreY
= (int)(firstY
+ (firstH
/ 2));
1260 while (node
= node
->Next())
1262 wxControl
*item
= (wxControl
*)node
->Data();
1263 if (item
->GetParent() == win
)
1264 item
->SetSize(-1, -1, firstW
, firstH
);
1269 void wxResourceManager::ToBackOrFront(bool toBack
)
1271 wxWindow
*win
= FindParentOfSelection();
1274 wxItemResource
*winResource
= FindResourceForWindow(win
);
1276 wxNode
*node
= GetSelections().First();
1279 wxControl
*item
= (wxControl
*)node
->Data();
1280 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1281 if (item
->GetParent() == win
)
1283 win
->GetChildren()->DeleteObject(item
);
1285 winResource
->GetChildren().DeleteObject(itemResource
);
1288 win
->GetChildren()->Insert(item
);
1290 winResource
->GetChildren().Insert(itemResource
);
1294 win
->GetChildren()->Append(item
);
1296 winResource
->GetChildren().Append(itemResource
);
1299 node
= node
->Next();
1304 void wxResourceManager::AddSelection(wxWindow
*win
)
1306 if (!m_selections
.Member(win
))
1307 m_selections
.Append(win
);
1310 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1312 m_selections
.DeleteObject(win
);
1315 // Need to search through resource table removing this from
1316 // any resource which has this as a parent.
1317 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1319 m_resourceTable
.BeginFind();
1321 while (node
= m_resourceTable
.Next())
1323 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1324 if (thisRes
->GetChildren().Member(res
))
1326 thisRes
->GetChildren().DeleteObject(res
);
1333 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1338 RemoveResourceFromParent(res
);
1340 wxNode
*node
= res
->GetChildren().First();
1343 wxNode
*next
= node
->Next();
1344 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1345 DeleteResource(child
);
1349 // If this is a button or message resource, delete the
1350 // associate bitmap resource if not being used.
1351 wxString
resType(res
->GetType());
1353 if ((resType
== "wxMessage" || resType
== "wxStaticBitmap" || resType
== "wxButton" || resType
== "wxBitmapButton") && res
->GetValue4())
1355 PossiblyDeleteBitmapResource(res
->GetValue4());
1358 // Remove symbol from table if appropriate
1359 if (!IsSymbolUsed(res
, res
->GetId()))
1361 m_symbolTable
.RemoveSymbol(res
->GetId());
1364 m_resourceTable
.Delete(res
->GetName());
1370 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1372 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1374 // Deselect and refresh window in case we leave selection
1376 wxControl
*item
= (wxControl
*)win
;
1377 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1378 if (childHandler
->IsSelected())
1380 RemoveSelection(item
);
1381 childHandler
->SelectItem(FALSE
);
1382 item
->GetParent()->Refresh();
1386 wxItemResource
*res
= FindResourceForWindow(win
);
1388 DisassociateResource(res
);
1389 DeleteResource(res
);
1390 UpdateResourceList();
1395 // Will eventually have bitmap type information, for different
1397 char *wxResourceManager::AddBitmapResource(char *filename
)
1399 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1403 MakeUniqueName("bitmap", buf
);
1404 resource
= new wxItemResource
;
1405 resource
->SetType("wxBitmap");
1406 resource
->SetName(buf
);
1408 // A bitmap resource has one or more children, specifying
1409 // alternative bitmaps.
1410 wxItemResource
*child
= new wxItemResource
;
1411 child
->SetType("wxBitmap");
1412 child
->SetName(filename
);
1413 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1414 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1415 child
->SetValue3(0); // Depth
1416 child
->SetSize(0,0,0,0);
1417 resource
->GetChildren().Append(child
);
1419 m_resourceTable
.AddResource(resource
);
1421 UpdateResourceList();
1424 return resource
->GetName();
1429 // Delete the bitmap resource if it isn't being used by another resource.
1430 void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName
)
1432 if (!IsBitmapResourceUsed(resourceName
))
1434 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1435 DeleteResource(res
);
1436 UpdateResourceList();
1440 bool wxResourceManager::IsBitmapResourceUsed(char *resourceName
)
1442 m_resourceTable
.BeginFind();
1444 while (node
= m_resourceTable
.Next())
1446 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1447 wxString
resType(res
->GetType());
1448 if (resType
== "wxDialog")
1450 wxNode
*node1
= res
->GetChildren().First();
1453 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1454 wxString
childResType(child
->GetType());
1456 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1457 child
->GetValue4() &&
1458 (strcmp(child
->GetValue4(), resourceName
) == 0))
1460 node1
= node1
->Next();
1467 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1468 char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1470 if (!resource
|| !resource
->GetValue4())
1472 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1473 if (!bitmapResource
)
1476 wxNode
*node
= bitmapResource
->GetChildren().First();
1479 // Eventually augment this to return a bitmap of the right kind or something...
1480 // Maybe the root of the filename remains the same, so it doesn't matter which we
1481 // pick up. Otherwise how do we specify multiple filenames... too boring...
1482 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1483 return child
->GetName();
1485 node
= node
->Next();
1490 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(char *filename
)
1492 m_resourceTable
.BeginFind();
1494 while (node
= m_resourceTable
.Next())
1496 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1497 wxString
resType(res
->GetType());
1498 if (resType
== "wxBitmap")
1500 wxNode
*node1
= res
->GetChildren().First();
1503 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1504 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1506 node1
= node1
->Next();
1513 // Is this window identifier symbol in use?
1514 // Let's assume that we can't have 2 names for the same integer id.
1515 // Therefore we can tell by the integer id whether the symbol is
1517 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1519 m_resourceTable
.BeginFind();
1521 while (node
= m_resourceTable
.Next())
1523 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1524 if ((res
!= thisResource
) && (res
->GetId() == id
))
1527 wxString
resType(res
->GetType());
1528 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1530 wxNode
*node1
= res
->GetChildren().First();
1533 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1534 if ((child
!= thisResource
) && (child
->GetId() == id
))
1536 node1
= node1
->Next();
1543 // Is this window identifier compatible with the given name? (i.e.
1544 // does it already exist under a different name)
1545 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1547 if (m_symbolTable
.SymbolExists(name
))
1549 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1556 // Change all integer ids that match oldId, to newId.
1557 // This is necessary if an id is changed for one resource - all resources
1559 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1561 m_resourceTable
.BeginFind();
1563 while (node
= m_resourceTable
.Next())
1565 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1566 if (res
->GetId() == oldId
)
1569 wxString
resType(res
->GetType());
1570 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1572 wxNode
*node1
= res
->GetChildren().First();
1575 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1576 if (child
->GetId() == oldId
)
1577 child
->SetId(newId
);
1579 node1
= node1
->Next();
1585 // Deletes 'win' and creates a new window from the resource that
1586 // was associated with it. E.g. if you can't change properties on the
1587 // fly, you'll need to delete the window and create it again.
1588 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1590 wxItemResource
*resource
= FindResourceForWindow(win
);
1592 // Put the current window properties into the wxItemResource object
1594 wxWindowPropertyInfo
*newInfo
= NULL
;
1597 newInfo
= CreatePropertyInfoForWindow(win
);
1601 info
->InstantiateResource(resource
);
1603 wxWindow
*newWin
= NULL
;
1604 wxWindow
*parent
= win
->GetParent();
1606 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1609 newWin
= FindWindowForResource(resource
);
1613 DisassociateResource(resource
);
1615 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
);
1616 AssociateResource(resource
, newWin
);
1617 UpdateResourceList();
1621 info
->SetPropertyWindow(newWin
);
1629 // Delete resource highlighted in the listbox
1630 bool wxResourceManager::DeleteSelection()
1632 int sel
= m_editorResourceTree
->GetSelection();
1635 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
1636 wxWindow
*win
= FindWindowForResource(res
);
1639 DeleteResource(win
);
1641 UpdateResourceList();
1650 // Delete resource highlighted in the listbox
1651 bool wxResourceManager::RecreateSelection()
1653 wxNode
*node
= GetSelections().First();
1656 wxControl
*item
= (wxControl
*)node
->Data();
1657 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1658 wxNode
*next
= node
->Next();
1659 childHandler
->SelectItem(FALSE
);
1661 RemoveSelection(item
);
1663 RecreateWindowFromResource(item
);
1670 bool wxResourceManager::EditDialog(wxDialog
*dialog
, wxWindow
*parent
)
1675 // Ensures that all currently shown windows are saved to resources,
1676 // e.g. just before writing to a .wxr file.
1677 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1679 m_resourceTable
.BeginFind();
1681 while (node
= m_resourceTable
.Next())
1683 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1684 wxString
resType(res
->GetType());
1686 if (resType
== "wxDialog")
1688 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1690 InstantiateResourceFromWindow(res
, win
, TRUE
);
1692 else if (resType
== "wxPanel")
1694 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1696 InstantiateResourceFromWindow(res
, win
, TRUE
);
1702 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1704 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1705 info
->SetResource(resource
);
1706 info
->InstantiateResource(resource
);
1711 wxNode
*node
= resource
->GetChildren().First();
1714 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1715 wxWindow
*childWindow
= FindWindowForResource(child
);
1720 sprintf(buf
, "Could not find window %s", child
->GetName());
1721 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1724 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1725 node
= node
->Next();
1732 // Create a window information object for the give window
1733 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1735 wxWindowPropertyInfo
*info
= NULL
;
1736 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1738 info
= new wxScrollBarPropertyInfo(win
);
1740 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1742 info
= new wxGroupBoxPropertyInfo(win
);
1744 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1746 info
= new wxCheckBoxPropertyInfo(win
);
1748 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1750 info
= new wxSliderPropertyInfo(win
);
1752 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1754 info
= new wxGaugePropertyInfo(win
);
1756 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1758 info
= new wxListBoxPropertyInfo(win
);
1760 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1762 info
= new wxRadioBoxPropertyInfo(win
);
1764 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1766 info
= new wxRadioButtonPropertyInfo(win
);
1768 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1770 info
= new wxChoicePropertyInfo(win
);
1772 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1774 info
= new wxButtonPropertyInfo(win
);
1776 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1778 info
= new wxBitmapButtonPropertyInfo(win
);
1780 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1782 info
= new wxStaticTextPropertyInfo(win
);
1784 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1786 info
= new wxStaticBitmapPropertyInfo(win
);
1788 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1790 info
= new wxTextPropertyInfo(win
);
1792 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1794 info
= new wxPanelPropertyInfo(win
);
1798 info
= new wxWindowPropertyInfo(win
);
1803 // Edit the given window
1804 void wxResourceManager::EditWindow(wxWindow
*win
)
1806 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
1809 info
->SetResource(FindResourceForWindow(win
));
1810 wxString
str("Editing ");
1811 str
+= win
->GetClassInfo()->GetClassName();
1813 if (win
->GetName() != "")
1814 str
+= win
->GetName();
1816 str
+= "properties";
1817 info
->Edit(NULL
, str
);
1821 // Generate a window id and a first stab at a name
1822 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
1824 m_symbolIdCounter
++;
1825 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
1826 m_symbolIdCounter
++;
1828 int nameId
= m_symbolIdCounter
;
1831 str
.Printf("%d", nameId
);
1832 idName
= prefix
+ str
;
1834 while (m_symbolTable
.SymbolExists(idName
))
1837 str
.Printf("%d", nameId
);
1838 idName
= prefix
+ str
;
1841 return m_symbolIdCounter
;
1846 * Resource editor frame
1849 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
1851 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
1852 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
1853 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
1854 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
1855 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
1856 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
1857 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
1858 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
1859 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
1860 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
1861 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
1862 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
1863 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
1866 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
1867 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
1868 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
1873 wxResourceEditorFrame::~wxResourceEditorFrame()
1877 void wxResourceEditorFrame::OnNew(wxCommandEvent
& event
)
1879 manager
->New(FALSE
);
1882 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& event
)
1884 manager
->CreateNewPanel();
1887 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& event
)
1892 void wxResourceEditorFrame::OnClear(wxCommandEvent
& event
)
1894 manager
->Clear(TRUE
, FALSE
);
1897 void wxResourceEditorFrame::OnSave(wxCommandEvent
& event
)
1902 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& event
)
1907 void wxResourceEditorFrame::OnExit(wxCommandEvent
& event
)
1909 manager
->Clear(TRUE
, FALSE
) ;
1913 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& event
)
1916 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
1917 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
1920 void wxResourceEditorFrame::OnTest(wxCommandEvent
& event
)
1922 manager
->TestCurrentDialog(this);
1925 void wxResourceEditorFrame::OnContents(wxCommandEvent
& event
)
1927 wxBeginBusyCursor();
1928 manager
->GetHelpController()->LoadFile();
1929 manager
->GetHelpController()->DisplayContents();
1933 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& event
)
1935 manager
->DeleteSelection();
1938 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& event
)
1940 manager
->RecreateSelection();
1943 bool wxResourceEditorFrame::OnClose()
1945 if (manager
->Modified())
1947 if (!manager
->Clear(TRUE
, FALSE
))
1955 manager
->m_resourceEditorWindowSize
.width
= w
;
1956 manager
->m_resourceEditorWindowSize
.height
= h
;
1959 GetPosition(&x
, &y
);
1961 manager
->m_resourceEditorWindowSize
.x
= x
;
1962 manager
->m_resourceEditorWindowSize
.y
= y
;
1964 manager
->SetEditorFrame(NULL
);
1965 manager
->SetEditorToolBar(NULL
);
1971 * Resource editor window that contains the dialog/panel being edited
1974 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
1975 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
1976 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
1979 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
1981 wxScrolledWindow(parent
, -1, pos
, size
, style
)
1985 m_childWindow
= NULL
;
1988 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
1992 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
1994 wxScrolledWindow::OnScroll(event
);
1997 ViewStart(& x
, & y
);
2000 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
2003 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& event
)
2010 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2014 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2017 wxString
str(res
->GetTitle());
2019 ViewStart(& x
, & y
);
2021 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2023 dc
.SetBackgroundMode(wxTRANSPARENT
);
2024 dc
.SetTextForeground(wxColour(0, 0, 0));
2027 dc
.GetTextExtent(str
, & w
, & h
);
2029 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2034 // Popup menu callback
2035 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2037 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2041 switch (event
.GetInt())
2043 case OBJECT_MENU_EDIT
:
2045 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2048 case OBJECT_MENU_DELETE
:
2050 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2051 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2052 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2065 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2066 EVT_PAINT(EditorToolBar::OnPaint
)
2069 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2071 wxToolBar(frame
, -1, pos
, size
, style
)
2075 bool EditorToolBar::OnLeftClick(int toolIndex
, bool toggled
)
2077 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2081 case TOOLBAR_LOAD_FILE
:
2088 manager
->CreateNewPanel();
2091 case TOOLBAR_SAVE_FILE
:
2098 wxBeginBusyCursor();
2099 manager
->GetHelpController()->LoadFile();
2100 manager
->GetHelpController()->DisplayContents();
2104 case TOOLBAR_FORMAT_HORIZ
:
2106 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2109 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2111 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2114 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2116 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2119 case TOOLBAR_FORMAT_VERT
:
2121 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2124 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2126 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2129 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2131 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2134 case TOOLBAR_COPY_SIZE
:
2136 manager
->CopySize();
2139 case TOOLBAR_TO_BACK
:
2141 manager
->ToBackOrFront(TRUE
);
2144 case TOOLBAR_TO_FRONT
:
2146 manager
->ToBackOrFront(FALSE
);
2155 void EditorToolBar::OnMouseEnter(int toolIndex
)
2157 wxFrame
*frame
= (wxFrame
*)GetParent();
2165 case TOOLBAR_LOAD_FILE
:
2166 frame
->SetStatusText("Load project file");
2168 case TOOLBAR_SAVE_FILE
:
2169 frame
->SetStatusText("Save project file");
2172 frame
->SetStatusText("Create a new resource");
2174 case TOOLBAR_FORMAT_HORIZ
:
2175 frame
->SetStatusText("Align items horizontally");
2177 case TOOLBAR_FORMAT_VERT
:
2178 frame
->SetStatusText("Align items vertically");
2180 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2181 frame
->SetStatusText("Left-align items");
2183 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2184 frame
->SetStatusText("Right-align items");
2186 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2187 frame
->SetStatusText("Top-align items");
2189 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2190 frame
->SetStatusText("Bottom-align items");
2192 case TOOLBAR_COPY_SIZE
:
2193 frame
->SetStatusText("Copy size from first selection");
2195 case TOOLBAR_TO_FRONT
:
2196 frame
->SetStatusText("Put image to front");
2198 case TOOLBAR_TO_BACK
:
2199 frame
->SetStatusText("Put image to back");
2202 frame
->SetStatusText("Display help contents");
2208 else frame
->SetStatusText("");
2211 void EditorToolBar::OnPaint(wxPaintEvent
& event
)
2213 wxToolBar::OnPaint(event
);
2218 dc
.SetPen(wxBLACK_PEN
);
2219 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
2220 dc
.DrawLine(0, h
-1, w
, h
-1);