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
))
332 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
340 bool wxResourceManager::SaveAs()
342 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
343 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
));
345 if (s
.IsNull() || s
== "")
348 m_currentFilename
= s
;
349 wxStripExtension(m_currentFilename
);
350 m_currentFilename
+= ".wxr";
352 // Construct include filename from this file
353 m_symbolFilename
= m_currentFilename
;
355 wxStripExtension(m_symbolFilename
);
356 m_symbolFilename
+= ".h";
358 Save(m_currentFilename
);
362 bool wxResourceManager::SaveIfModified()
369 bool wxResourceManager::Load(const wxString
& filename
)
371 return New(TRUE
, filename
);
374 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
376 if (!Clear(TRUE
, FALSE
))
379 m_symbolTable
.AddStandardSymbols();
383 wxString str
= filename
;
384 if (str
== wxString(""))
386 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, NULL
));
387 if (!f
.IsNull() && f
!= "")
393 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
395 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
398 m_currentFilename
= str
;
400 SetFrameTitle(m_currentFilename
);
402 UpdateResourceList();
404 // Construct include filename from this file
405 m_symbolFilename
= m_currentFilename
;
407 wxStripExtension(m_symbolFilename
);
408 m_symbolFilename
+= ".h";
410 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
412 wxString
str("Could not find include file ");
413 str
+= m_symbolFilename
;
414 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
415 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
416 wxMessageBox(str
, "Dialog Editor Warning", MB_OK
);
418 m_symbolIdCounter
= 99;
422 // Set the id counter to the last known id
423 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
426 // Now check in case some (or all) resources don't have resource ids, or they
427 // don't match the .h file, or something of that nature.
428 bool altered
= RepairResourceIds();
431 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.", "Dialog Editor Warning", MB_OK
);
442 m_currentFilename
= "";
449 bool wxResourceManager::Clear(bool deleteWindows
, bool force
)
451 if (!force
&& Modified())
453 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
457 if (!SaveIfModified())
463 ClearCurrentDialog();
464 DisassociateWindows();
466 m_symbolTable
.Clear();
467 m_resourceTable
.ClearTable();
468 UpdateResourceList();
473 bool wxResourceManager::DisassociateWindows()
475 m_resourceTable
.BeginFind();
477 while (node
= m_resourceTable
.Next())
479 wxItemResource
*res
= (wxItemResource
*)node
->Data();
480 DisassociateResource(res
);
486 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
488 if (!m_resourceAssociations
.Get((long)resource
))
489 m_resourceAssociations
.Put((long)resource
, win
);
491 wxNode
*node
= resource
->GetChildren().First();
494 wxItemResource
*child
= (wxItemResource
*)node
->Data();
495 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
497 childWindow
= win
->FindWindow(child
->GetName());
499 AssociateResource(child
, childWindow
);
503 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? child
->GetName() : "(unnamed)");
504 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
511 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
513 wxWindow
*win
= FindWindowForResource(resource
);
517 // Disassociate children of window
518 if (win
->GetChildren())
520 wxNode
*node
= win
->GetChildren()->First();
523 wxWindow
*child
= (wxWindow
*)node
->Data();
524 if (child
->IsKindOf(CLASSINFO(wxControl
)))
525 DisassociateResource(child
);
530 RemoveSelection(win
);
531 m_resourceAssociations
.Delete((long)resource
);
535 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
537 wxItemResource
*res
= FindResourceForWindow(win
);
539 return DisassociateResource(res
);
544 // Saves the window info into the resource, and deletes the
545 // handler. Doesn't actually disassociate the window from
546 // the resources. Replaces OnClose.
547 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
549 wxItemResource
*res
= FindResourceForWindow(win
);
551 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
553 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
554 win
->PopEventHandler();
556 // Now reset all child event handlers
557 wxNode
*node
= win
->GetChildren()->First();
560 wxWindow
*child
= (wxWindow
*)node
->Data();
561 wxEvtHandler
*childHandler
= child
->GetEventHandler();
562 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
564 child
->PopEventHandler(TRUE
);
572 win
->PopEventHandler(TRUE
);
575 // Save the information
576 InstantiateResourceFromWindow(res
, win
, TRUE
);
578 // DisassociateResource(win);
583 // Destroys the window. If this is the 'current' panel, NULLs the
585 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
587 bool clearDisplay
= FALSE
;
588 if (m_editorPanel
->m_childWindow
== win
)
590 m_editorPanel
->m_childWindow
= NULL
;
597 m_editorPanel
->Clear();
602 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
604 m_resourceAssociations
.BeginFind();
606 while (node
= m_resourceAssociations
.Next())
608 wxWindow
*w
= (wxWindow
*)node
->Data();
611 return (wxItemResource
*)node
->key
.integer
;
617 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
619 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
623 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
627 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
630 if (!m_resourceTable
.FindResource(buf
))
635 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
637 int frameWidth
= 420;
638 int frameHeight
= 300;
640 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
641 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
642 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
643 wxDEFAULT_FRAME_STYLE
);
645 frame
->CreateStatusBar(1);
647 frame
->SetAutoLayout(TRUE
);
649 wxIcon
*icon
= new wxIcon("DIALOGEDICON");
650 frame
->SetIcon(icon
);
655 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*parent
)
657 wxMenuBar
*menuBar
= new wxMenuBar
;
659 wxMenu
*fileMenu
= new wxMenu
;
660 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
661 fileMenu
->AppendSeparator();
662 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
663 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
664 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
665 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
666 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
667 fileMenu
->AppendSeparator();
668 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
670 wxMenu
*editMenu
= new wxMenu
;
671 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
672 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
673 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
675 wxMenu
*helpMenu
= new wxMenu
;
676 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
677 helpMenu
->AppendSeparator();
678 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
680 menuBar
->Append(fileMenu
, "&File");
681 menuBar
->Append(editMenu
, "&Edit");
682 menuBar
->Append(helpMenu
, "&Help");
687 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
689 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
690 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
693 panel
->SetScrollbars(10, 10, 100, 100);
698 wxToolBarBase
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
700 // Load palette bitmaps
702 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
703 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
704 wxBitmap
ToolbarNewBitmap("NEWTOOL");
705 wxBitmap
ToolbarVertBitmap("VERTTOOL");
706 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
707 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
708 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
709 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
710 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
711 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
712 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
713 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
714 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
717 wxBitmap
ToolbarLoadBitmap(load_bits
, load_width
, load_height
);
718 wxBitmap
ToolbarSaveBitmap(save_bits
, save_width
, save_height
);
719 wxBitmap
ToolbarNewBitmap(new_bits
, save_width
, save_height
);
720 wxBitmap
ToolbarVertBitmap(vert_bits
, vert_width
, vert_height
);
721 wxBitmap
ToolbarAlignTBitmap(alignt_bits
, alignt_width
, alignt_height
);
722 wxBitmap
ToolbarAlignBBitmap(alignb_bits
, alignb_width
, alignb_height
);
723 wxBitmap
ToolbarHorizBitmap(horiz_bits
, horiz_width
, horiz_height
);
724 wxBitmap
ToolbarAlignLBitmap(alignl_bits
, alignl_width
, alignl_height
);
725 wxBitmap
ToolbarAlignRBitmap(alignr_bits
, alignr_width
, alignr_height
);
726 wxBitmap
ToolbarCopySizeBitmap(copysize_bits
, copysize_width
, copysize_height
);
727 wxBitmap
ToolbarToBackBitmap(toback_bits
, toback_width
, toback_height
);
728 wxBitmap
ToolbarToFrontBitmap(tofront_bits
, tofront_width
, tofront_height
);
729 wxBitmap
ToolbarHelpBitmap(help_bits
, help_width
, help_height
);
732 // Create the toolbar
733 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
734 toolbar
->SetMargins(2, 2);
741 int width
= ToolbarLoadBitmap
->GetWidth();
746 toolbar
->AddSeparator();
747 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, (wxBitmap
*)NULL
,
748 FALSE
, (float)currentX
, -1, NULL
, "New dialog");
749 currentX
+= width
+ dx
;
750 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, (wxBitmap
*)NULL
,
751 FALSE
, (float)currentX
, -1, NULL
, "Load");
752 currentX
+= width
+ dx
;
753 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, (wxBitmap
*)NULL
,
754 FALSE
, (float)currentX
, -1, NULL
, "Save");
755 currentX
+= width
+ dx
+ gap
;
756 toolbar
->AddSeparator();
757 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, (wxBitmap
*)NULL
,
758 FALSE
, (float)currentX
, -1, NULL
, "Horizontal align");
759 currentX
+= width
+ dx
;
760 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, (wxBitmap
*)NULL
,
761 FALSE
, (float)currentX
, -1, NULL
, "Top align");
762 currentX
+= width
+ dx
;
763 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, (wxBitmap
*)NULL
,
764 FALSE
, (float)currentX
, -1, NULL
, "Bottom align");
765 currentX
+= width
+ dx
;
766 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, (wxBitmap
*)NULL
,
767 FALSE
, (float)currentX
, -1, NULL
, "Vertical align");
768 currentX
+= width
+ dx
;
769 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, (wxBitmap
*)NULL
,
770 FALSE
, (float)currentX
, -1, NULL
, "Left align");
771 currentX
+= width
+ dx
;
772 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, (wxBitmap
*)NULL
,
773 FALSE
, (float)currentX
, -1, NULL
, "Right align");
774 currentX
+= width
+ dx
;
775 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, (wxBitmap
*)NULL
,
776 FALSE
, (float)currentX
, -1, NULL
, "Copy size");
777 currentX
+= width
+ dx
+ gap
;
778 toolbar
->AddSeparator();
779 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, (wxBitmap
*)NULL
,
780 FALSE
, (float)currentX
, -1, NULL
, "To front");
781 currentX
+= width
+ dx
;
782 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, (wxBitmap
*)NULL
,
783 FALSE
, (float)currentX
, -1, NULL
, "To back");
784 currentX
+= width
+ dx
+ gap
;
786 toolbar
->AddSeparator();
787 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, (wxBitmap
*)NULL
,
788 FALSE
, (float)currentX
, -1, NULL
, "Help");
789 currentX
+= width
+ dx
;
796 void wxResourceManager::UpdateResourceList()
798 if (!m_editorResourceTree
)
801 m_editorResourceTree
->SetInvalid(TRUE
);
802 m_editorResourceTree
->DeleteAllItems();
804 long id
= m_editorResourceTree
->InsertItem(0, "Dialogs"
810 m_resourceTable
.BeginFind();
812 while (node
= m_resourceTable
.Next())
814 wxItemResource
*res
= (wxItemResource
*)node
->Data();
815 wxString
resType(res
->GetType());
816 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
818 AddItemsRecursively(id
, res
);
821 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
822 m_editorResourceTree
->SetInvalid(FALSE
);
825 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
827 wxString
theString("");
828 theString
= resource
->GetName();
831 wxString
resType(resource
->GetType());
832 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
837 long id
= m_editorResourceTree
->InsertItem(parent
, theString
843 m_editorResourceTree
->SetItemData(id
, (long) resource
);
845 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
847 wxNode
*node
= resource
->GetChildren().First();
850 wxItemResource
*res
= (wxItemResource
*)node
->Data();
851 AddItemsRecursively(id
, res
);
855 m_editorResourceTree
->ExpandItem(id
, wxTREE_EXPAND_EXPAND
);
858 bool wxResourceManager::EditSelectedResource()
860 int sel
= m_editorResourceTree
->GetSelection();
863 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
869 bool wxResourceManager::Edit(wxItemResource
*res
)
871 ClearCurrentDialog();
873 wxString
resType(res
->GetType());
874 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
878 wxMessageBox("Should not find panel in wxResourceManager::Edit");
883 long style
= res
->GetStyle();
884 res
->SetStyle(style
|wxRAISED_BORDER
);
886 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
889 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
891 panel
->PushEventHandler(handler
);
893 res
->SetStyle(style
);
894 handler
->AddChildHandlers(); // Add event handlers for all controls
895 AssociateResource(res
, panel
);
897 m_editorPanel
->m_childWindow
= panel
;
898 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
902 wxClientDC
dc(m_editorPanel
);
903 m_editorPanel
->DrawTitle(dc
);
908 bool wxResourceManager::CreateNewPanel()
910 ClearCurrentDialog();
913 MakeUniqueName("dialog", buf
);
915 wxItemResource
*resource
= new wxItemResource
;
916 resource
->SetType("wxDialog");
917 resource
->SetName(buf
);
918 resource
->SetTitle(buf
);
921 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
924 // This is now guaranteed to be unique, so just add to symbol table
925 m_symbolTable
.AddSymbol(newIdName
, id
);
927 m_resourceTable
.AddResource(resource
);
929 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
930 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
931 wxSize(400, 300), wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
932 m_editorPanel
->m_childWindow
= panel
;
934 resource
->SetStyle(panel
->GetWindowStyleFlag());
935 resource
->SetSize(10, 10, 400, 300);
937 // For editing in situ we will need to use the hash table to ensure
938 // we don't dereference invalid pointers.
939 // resourceWindowTable.Put((long)resource, panel);
941 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
943 panel
->PushEventHandler(handler
);
945 AssociateResource(resource
, panel
);
946 UpdateResourceList();
949 m_editorPanel
->m_childWindow
->Refresh();
953 wxClientDC
dc(m_editorPanel
);
954 m_editorPanel
->DrawTitle(dc
);
959 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
962 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
967 wxItemResource
*res
= new wxItemResource
;
968 wxControl
*newItem
= NULL
;
969 res
->SetSize(x
, y
, -1, -1);
974 wxString
itemType(iType
);
976 if (itemType
== "wxButton")
978 prefix
= "ID_BUTTON";
979 MakeUniqueName("button", buf
);
982 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
984 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
986 if (itemType
== "wxBitmapButton")
988 prefix
= "ID_BITMAPBUTTON";
989 MakeUniqueName("button", buf
);
991 newItem
= new wxBitmapButton(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
993 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
995 prefix
= "ID_STATIC";
996 MakeUniqueName("message", buf
);
999 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1001 newItem
= new wxStaticText(panel
, -1, "Message", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1003 else if (itemType
== "wxStaticBitmap")
1005 prefix
= "ID_STATICBITMAP";
1006 MakeUniqueName("message", buf
);
1008 newItem
= new wxStaticBitmap(panel
, -1, m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1010 else if (itemType
== "wxCheckBox")
1012 prefix
= "ID_CHECKBOX";
1013 MakeUniqueName("checkbox", buf
);
1015 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1017 else if (itemType
== "wxListBox")
1019 prefix
= "ID_LISTBOX";
1020 MakeUniqueName("listbox", buf
);
1022 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1024 else if (itemType
== "wxRadioBox")
1026 prefix
= "ID_RADIOBOX";
1027 MakeUniqueName("radiobox", buf
);
1029 wxString names
[] = { "One", "Two" };
1030 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1031 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1032 res
->SetStringValues(new wxStringList("One", "Two", NULL
));
1034 else if (itemType
== "wxRadioButton")
1036 prefix
= "ID_RADIOBUTTON";
1037 MakeUniqueName("radiobutton", buf
);
1039 wxString names
[] = { "One", "Two" };
1040 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1041 0, wxDefaultValidator
, buf
);
1043 else if (itemType
== "wxChoice")
1045 prefix
= "ID_CHOICE";
1046 MakeUniqueName("choice", buf
);
1048 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1050 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1052 prefix
= "ID_STATICBOX";
1053 MakeUniqueName("group", buf
);
1055 newItem
= new wxStaticBox(panel
, -1, "Groupbox", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1057 else if (itemType
== "wxGauge")
1059 prefix
= "ID_GAUGE";
1060 MakeUniqueName("gauge", buf
);
1062 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1064 else if (itemType
== "wxSlider")
1066 prefix
= "ID_SLIDER";
1067 MakeUniqueName("slider", buf
);
1069 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1071 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1073 prefix
= "ID_TEXTCTRL";
1074 MakeUniqueName("textctrl", buf
);
1076 res
->SetType("wxTextCtrl");
1077 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1079 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1081 prefix
= "ID_TEXTCTRL";
1082 MakeUniqueName("textctrl", buf
);
1084 res
->SetType("wxTextCtrl");
1085 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1087 else if (itemType
== "wxScrollBar")
1089 prefix
= "ID_SCROLLBAR";
1090 MakeUniqueName("scrollbar", buf
);
1092 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1098 int id
= GenerateWindowId(prefix
, newIdName
);
1101 // This is now guaranteed to be unique, so just add to symbol table
1102 m_symbolTable
.AddSymbol(newIdName
, id
);
1104 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1106 res
->SetStyle(newItem
->GetWindowStyleFlag());
1107 AssociateResource(res
, newItem
);
1108 panelResource
->GetChildren().Append(res
);
1110 UpdateResourceList();
1115 void wxResourceManager::ClearCurrentDialog()
1117 if (m_editorPanel
->m_childWindow
)
1119 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1120 DisassociateResource(m_editorPanel
->m_childWindow
);
1121 DeleteWindow(m_editorPanel
->m_childWindow
);
1122 m_editorPanel
->m_childWindow
= NULL
;
1123 m_editorPanel
->Clear();
1127 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1129 if (m_editorPanel
->m_childWindow
)
1131 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1135 // Make sure the resources are up-to-date w.r.t. the window
1136 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1138 wxDialog
* dialog
= new wxDialog
;
1139 long oldStyle
= item
->GetStyle();
1140 bool success
= FALSE
;
1141 // item->SetStyle(wxDEFAULT_DIALOG_STYLE);
1142 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1145 dialog
->ShowModal();
1148 // item->SetStyle(oldStyle);
1154 // Find the first dialog or panel for which
1155 // there is a selected panel item.
1156 wxWindow
*wxResourceManager::FindParentOfSelection()
1158 m_resourceTable
.BeginFind();
1160 while (node
= m_resourceTable
.Next())
1162 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1163 wxWindow
*win
= FindWindowForResource(res
);
1166 wxNode
*node1
= win
->GetChildren()->First();
1169 wxControl
*item
= (wxControl
*)node1
->Data();
1170 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1171 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1173 node1
= node1
->Next();
1180 // Format the panel items according to 'flag'
1181 void wxResourceManager::AlignItems(int flag
)
1183 wxWindow
*win
= FindParentOfSelection();
1187 wxNode
*node
= GetSelections().First();
1191 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1192 if (firstSelection
->GetParent() != win
)
1197 firstSelection
->GetPosition(&firstX
, &firstY
);
1198 firstSelection
->GetSize(&firstW
, &firstH
);
1199 int centreX
= (int)(firstX
+ (firstW
/ 2));
1200 int centreY
= (int)(firstY
+ (firstH
/ 2));
1202 while (node
= node
->Next())
1204 wxControl
*item
= (wxControl
*)node
->Data();
1205 if (item
->GetParent() == win
)
1208 item
->GetPosition(&x
, &y
);
1209 item
->GetSize(&w
, &h
);
1215 case TOOLBAR_FORMAT_HORIZ
:
1218 newY
= (int)(centreY
- (h
/2.0));
1221 case TOOLBAR_FORMAT_VERT
:
1223 newX
= (int)(centreX
- (w
/2.0));
1227 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1233 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1239 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1241 newX
= firstX
+ firstW
- w
;
1245 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1248 newY
= firstY
+ firstH
- h
;
1256 item
->SetSize(newX
, newY
, w
, h
);
1262 // Copy the first image's size to subsequent images
1263 void wxResourceManager::CopySize()
1265 wxWindow
*win
= FindParentOfSelection();
1269 wxNode
*node
= GetSelections().First();
1273 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1274 if (firstSelection
->GetParent() != win
)
1279 firstSelection
->GetPosition(&firstX
, &firstY
);
1280 firstSelection
->GetSize(&firstW
, &firstH
);
1281 int centreX
= (int)(firstX
+ (firstW
/ 2));
1282 int centreY
= (int)(firstY
+ (firstH
/ 2));
1284 while (node
= node
->Next())
1286 wxControl
*item
= (wxControl
*)node
->Data();
1287 if (item
->GetParent() == win
)
1288 item
->SetSize(-1, -1, firstW
, firstH
);
1293 void wxResourceManager::ToBackOrFront(bool toBack
)
1295 wxWindow
*win
= FindParentOfSelection();
1298 wxItemResource
*winResource
= FindResourceForWindow(win
);
1300 wxNode
*node
= GetSelections().First();
1303 wxControl
*item
= (wxControl
*)node
->Data();
1304 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1305 if (item
->GetParent() == win
)
1307 win
->GetChildren()->DeleteObject(item
);
1309 winResource
->GetChildren().DeleteObject(itemResource
);
1312 win
->GetChildren()->Insert(item
);
1314 winResource
->GetChildren().Insert(itemResource
);
1318 win
->GetChildren()->Append(item
);
1320 winResource
->GetChildren().Append(itemResource
);
1323 node
= node
->Next();
1328 void wxResourceManager::AddSelection(wxWindow
*win
)
1330 if (!m_selections
.Member(win
))
1331 m_selections
.Append(win
);
1334 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1336 m_selections
.DeleteObject(win
);
1339 // Need to search through resource table removing this from
1340 // any resource which has this as a parent.
1341 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1343 m_resourceTable
.BeginFind();
1345 while (node
= m_resourceTable
.Next())
1347 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1348 if (thisRes
->GetChildren().Member(res
))
1350 thisRes
->GetChildren().DeleteObject(res
);
1357 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1362 RemoveResourceFromParent(res
);
1364 wxNode
*node
= res
->GetChildren().First();
1367 wxNode
*next
= node
->Next();
1368 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1369 DeleteResource(child
);
1373 // If this is a button or message resource, delete the
1374 // associate bitmap resource if not being used.
1375 wxString
resType(res
->GetType());
1377 if ((resType
== "wxMessage" || resType
== "wxStaticBitmap" || resType
== "wxButton" || resType
== "wxBitmapButton") && res
->GetValue4())
1379 PossiblyDeleteBitmapResource(res
->GetValue4());
1382 // Remove symbol from table if appropriate
1383 if (!IsSymbolUsed(res
, res
->GetId()))
1385 m_symbolTable
.RemoveSymbol(res
->GetId());
1388 m_resourceTable
.Delete(res
->GetName());
1394 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1396 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1398 // Deselect and refresh window in case we leave selection
1400 wxControl
*item
= (wxControl
*)win
;
1401 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1402 if (childHandler
->IsSelected())
1404 RemoveSelection(item
);
1405 childHandler
->SelectItem(FALSE
);
1406 item
->GetParent()->Refresh();
1410 wxItemResource
*res
= FindResourceForWindow(win
);
1412 DisassociateResource(res
);
1413 DeleteResource(res
);
1414 UpdateResourceList();
1419 // Will eventually have bitmap type information, for different
1421 char *wxResourceManager::AddBitmapResource(char *filename
)
1423 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1427 MakeUniqueName("bitmap", buf
);
1428 resource
= new wxItemResource
;
1429 resource
->SetType("wxBitmap");
1430 resource
->SetName(buf
);
1432 // A bitmap resource has one or more children, specifying
1433 // alternative bitmaps.
1434 wxItemResource
*child
= new wxItemResource
;
1435 child
->SetType("wxBitmap");
1436 child
->SetName(filename
);
1437 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1438 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1439 child
->SetValue3(0); // Depth
1440 child
->SetSize(0,0,0,0);
1441 resource
->GetChildren().Append(child
);
1443 m_resourceTable
.AddResource(resource
);
1445 UpdateResourceList();
1448 return resource
->GetName();
1453 // Delete the bitmap resource if it isn't being used by another resource.
1454 void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName
)
1456 if (!IsBitmapResourceUsed(resourceName
))
1458 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1459 DeleteResource(res
);
1460 UpdateResourceList();
1464 bool wxResourceManager::IsBitmapResourceUsed(char *resourceName
)
1466 m_resourceTable
.BeginFind();
1468 while (node
= m_resourceTable
.Next())
1470 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1471 wxString
resType(res
->GetType());
1472 if (resType
== "wxDialog")
1474 wxNode
*node1
= res
->GetChildren().First();
1477 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1478 wxString
childResType(child
->GetType());
1480 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1481 child
->GetValue4() &&
1482 (strcmp(child
->GetValue4(), resourceName
) == 0))
1484 node1
= node1
->Next();
1491 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1492 char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1494 if (!resource
|| !resource
->GetValue4())
1496 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1497 if (!bitmapResource
)
1500 wxNode
*node
= bitmapResource
->GetChildren().First();
1503 // Eventually augment this to return a bitmap of the right kind or something...
1504 // Maybe the root of the filename remains the same, so it doesn't matter which we
1505 // pick up. Otherwise how do we specify multiple filenames... too boring...
1506 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1507 return child
->GetName();
1509 node
= node
->Next();
1514 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(char *filename
)
1516 m_resourceTable
.BeginFind();
1518 while (node
= m_resourceTable
.Next())
1520 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1521 wxString
resType(res
->GetType());
1522 if (resType
== "wxBitmap")
1524 wxNode
*node1
= res
->GetChildren().First();
1527 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1528 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1530 node1
= node1
->Next();
1537 // Is this window identifier symbol in use?
1538 // Let's assume that we can't have 2 names for the same integer id.
1539 // Therefore we can tell by the integer id whether the symbol is
1541 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1543 m_resourceTable
.BeginFind();
1545 while (node
= m_resourceTable
.Next())
1547 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1549 wxString
resType(res
->GetType());
1550 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1552 if ((res
!= thisResource
) && (res
->GetId() == id
))
1555 wxNode
*node1
= res
->GetChildren().First();
1558 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1559 if ((child
!= thisResource
) && (child
->GetId() == id
))
1561 node1
= node1
->Next();
1568 // Is this window identifier compatible with the given name? (i.e.
1569 // does it already exist under a different name)
1570 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1572 if (m_symbolTable
.SymbolExists(name
))
1574 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1581 // Change all integer ids that match oldId, to newId.
1582 // This is necessary if an id is changed for one resource - all resources
1584 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1586 m_resourceTable
.BeginFind();
1588 while (node
= m_resourceTable
.Next())
1590 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1592 wxString
resType(res
->GetType());
1593 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1595 if (res
->GetId() == oldId
)
1598 wxNode
*node1
= res
->GetChildren().First();
1601 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1602 if (child
->GetId() == oldId
)
1603 child
->SetId(newId
);
1605 node1
= node1
->Next();
1611 // If any resource ids were missing (or their symbol was missing),
1612 // repair them i.e. give them new ids. Returns TRUE if any resource
1613 // needed repairing.
1614 bool wxResourceManager::RepairResourceIds()
1616 bool repaired
= FALSE
;
1618 m_resourceTable
.BeginFind();
1620 while (node
= m_resourceTable
.Next())
1622 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1623 wxString
resType(res
->GetType());
1624 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1627 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1629 wxString newSymbolName
;
1630 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1632 if (res
->GetId() == 0)
1635 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1639 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1645 wxNode
*node1
= res
->GetChildren().First();
1648 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1650 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1652 wxString newSymbolName
;
1653 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1655 if (child
->GetId() == 0)
1657 child
->SetId(newId
);
1658 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1662 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1668 node1
= node1
->Next();
1676 // Deletes 'win' and creates a new window from the resource that
1677 // was associated with it. E.g. if you can't change properties on the
1678 // fly, you'll need to delete the window and create it again.
1679 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1681 wxItemResource
*resource
= FindResourceForWindow(win
);
1683 // Put the current window properties into the wxItemResource object
1685 wxWindowPropertyInfo
*newInfo
= NULL
;
1688 newInfo
= CreatePropertyInfoForWindow(win
);
1692 info
->InstantiateResource(resource
);
1694 wxWindow
*newWin
= NULL
;
1695 wxWindow
*parent
= win
->GetParent();
1697 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1700 newWin
= FindWindowForResource(resource
);
1704 DisassociateResource(resource
);
1706 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
);
1707 AssociateResource(resource
, newWin
);
1708 UpdateResourceList();
1712 info
->SetPropertyWindow(newWin
);
1720 // Delete resource highlighted in the listbox
1721 bool wxResourceManager::DeleteSelection()
1723 int sel
= m_editorResourceTree
->GetSelection();
1726 wxItemResource
*res
= (wxItemResource
*)m_editorResourceTree
->GetItemData(sel
);
1727 wxWindow
*win
= FindWindowForResource(res
);
1730 DeleteResource(win
);
1732 UpdateResourceList();
1741 // Delete resource highlighted in the listbox
1742 bool wxResourceManager::RecreateSelection()
1744 wxNode
*node
= GetSelections().First();
1747 wxControl
*item
= (wxControl
*)node
->Data();
1748 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1749 wxNode
*next
= node
->Next();
1750 childHandler
->SelectItem(FALSE
);
1752 RemoveSelection(item
);
1754 RecreateWindowFromResource(item
);
1761 bool wxResourceManager::EditDialog(wxDialog
*dialog
, wxWindow
*parent
)
1766 // Ensures that all currently shown windows are saved to resources,
1767 // e.g. just before writing to a .wxr file.
1768 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1770 m_resourceTable
.BeginFind();
1772 while (node
= m_resourceTable
.Next())
1774 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1775 wxString
resType(res
->GetType());
1777 if (resType
== "wxDialog")
1779 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1781 InstantiateResourceFromWindow(res
, win
, TRUE
);
1783 else if (resType
== "wxPanel")
1785 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1787 InstantiateResourceFromWindow(res
, win
, TRUE
);
1793 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1795 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1796 info
->SetResource(resource
);
1797 info
->InstantiateResource(resource
);
1802 wxNode
*node
= resource
->GetChildren().First();
1805 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1806 wxWindow
*childWindow
= FindWindowForResource(child
);
1811 sprintf(buf
, "Could not find window %s", child
->GetName());
1812 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1815 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1816 node
= node
->Next();
1823 // Create a window information object for the give window
1824 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1826 wxWindowPropertyInfo
*info
= NULL
;
1827 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1829 info
= new wxScrollBarPropertyInfo(win
);
1831 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1833 info
= new wxGroupBoxPropertyInfo(win
);
1835 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1837 info
= new wxCheckBoxPropertyInfo(win
);
1839 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1841 info
= new wxSliderPropertyInfo(win
);
1843 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1845 info
= new wxGaugePropertyInfo(win
);
1847 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1849 info
= new wxListBoxPropertyInfo(win
);
1851 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1853 info
= new wxRadioBoxPropertyInfo(win
);
1855 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1857 info
= new wxRadioButtonPropertyInfo(win
);
1859 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1861 info
= new wxChoicePropertyInfo(win
);
1863 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1865 info
= new wxButtonPropertyInfo(win
);
1867 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1869 info
= new wxBitmapButtonPropertyInfo(win
);
1871 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1873 info
= new wxStaticTextPropertyInfo(win
);
1875 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1877 info
= new wxStaticBitmapPropertyInfo(win
);
1879 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1881 info
= new wxTextPropertyInfo(win
);
1883 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1885 info
= new wxPanelPropertyInfo(win
);
1889 info
= new wxWindowPropertyInfo(win
);
1894 // Edit the given window
1895 void wxResourceManager::EditWindow(wxWindow
*win
)
1897 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
1900 info
->SetResource(FindResourceForWindow(win
));
1901 wxString
str("Editing ");
1902 str
+= win
->GetClassInfo()->GetClassName();
1904 if (win
->GetName() != "")
1905 str
+= win
->GetName();
1907 str
+= "properties";
1908 info
->Edit(NULL
, str
);
1912 // Generate a window id and a first stab at a name
1913 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
1915 m_symbolIdCounter
++;
1916 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
1917 m_symbolIdCounter
++;
1919 int nameId
= m_symbolIdCounter
;
1922 str
.Printf("%d", nameId
);
1923 idName
= prefix
+ str
;
1925 while (m_symbolTable
.SymbolExists(idName
))
1928 str
.Printf("%d", nameId
);
1929 idName
= prefix
+ str
;
1932 return m_symbolIdCounter
;
1937 * Resource editor frame
1940 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
1942 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
1943 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
1944 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
1945 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
1946 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
1947 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
1948 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
1949 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
1950 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
1951 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
1952 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
1953 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
1954 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
1957 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
1958 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
1959 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
1964 wxResourceEditorFrame::~wxResourceEditorFrame()
1968 void wxResourceEditorFrame::OnNew(wxCommandEvent
& event
)
1970 manager
->New(FALSE
);
1973 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& event
)
1975 manager
->CreateNewPanel();
1978 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& event
)
1983 void wxResourceEditorFrame::OnClear(wxCommandEvent
& event
)
1985 manager
->Clear(TRUE
, FALSE
);
1988 void wxResourceEditorFrame::OnSave(wxCommandEvent
& event
)
1993 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& event
)
1998 void wxResourceEditorFrame::OnExit(wxCommandEvent
& event
)
2000 manager
->Clear(TRUE
, FALSE
) ;
2004 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& event
)
2007 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
2008 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2011 void wxResourceEditorFrame::OnTest(wxCommandEvent
& event
)
2013 manager
->TestCurrentDialog(this);
2016 void wxResourceEditorFrame::OnContents(wxCommandEvent
& event
)
2018 wxBeginBusyCursor();
2019 manager
->GetHelpController()->LoadFile();
2020 manager
->GetHelpController()->DisplayContents();
2024 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& event
)
2026 manager
->DeleteSelection();
2029 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& event
)
2031 manager
->RecreateSelection();
2034 bool wxResourceEditorFrame::OnClose()
2036 if (manager
->Modified())
2038 if (!manager
->Clear(TRUE
, FALSE
))
2046 manager
->m_resourceEditorWindowSize
.width
= w
;
2047 manager
->m_resourceEditorWindowSize
.height
= h
;
2050 GetPosition(&x
, &y
);
2052 manager
->m_resourceEditorWindowSize
.x
= x
;
2053 manager
->m_resourceEditorWindowSize
.y
= y
;
2055 manager
->SetEditorFrame(NULL
);
2056 manager
->SetEditorToolBar(NULL
);
2062 * Resource editor window that contains the dialog/panel being edited
2065 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2066 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
2067 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2070 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2072 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2076 m_childWindow
= NULL
;
2079 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2083 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
2085 wxScrolledWindow::OnScroll(event
);
2088 ViewStart(& x
, & y
);
2091 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
2094 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& event
)
2101 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2105 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2108 wxString
str(res
->GetTitle());
2110 ViewStart(& x
, & y
);
2112 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2114 dc
.SetBackgroundMode(wxTRANSPARENT
);
2115 dc
.SetTextForeground(wxColour(0, 0, 0));
2118 dc
.GetTextExtent(str
, & w
, & h
);
2120 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2125 // Popup menu callback
2126 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2128 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2132 switch (event
.GetInt())
2134 case OBJECT_MENU_EDIT
:
2136 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2139 case OBJECT_MENU_DELETE
:
2141 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2142 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2143 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2156 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2157 EVT_PAINT(EditorToolBar::OnPaint
)
2160 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2162 wxToolBar(frame
, -1, pos
, size
, style
)
2166 bool EditorToolBar::OnLeftClick(int toolIndex
, bool toggled
)
2168 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2172 case TOOLBAR_LOAD_FILE
:
2179 manager
->CreateNewPanel();
2182 case TOOLBAR_SAVE_FILE
:
2189 wxBeginBusyCursor();
2190 manager
->GetHelpController()->LoadFile();
2191 manager
->GetHelpController()->DisplayContents();
2195 case TOOLBAR_FORMAT_HORIZ
:
2197 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2200 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2202 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2205 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2207 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2210 case TOOLBAR_FORMAT_VERT
:
2212 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2215 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2217 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2220 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2222 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2225 case TOOLBAR_COPY_SIZE
:
2227 manager
->CopySize();
2230 case TOOLBAR_TO_BACK
:
2232 manager
->ToBackOrFront(TRUE
);
2235 case TOOLBAR_TO_FRONT
:
2237 manager
->ToBackOrFront(FALSE
);
2246 void EditorToolBar::OnMouseEnter(int toolIndex
)
2248 wxFrame
*frame
= (wxFrame
*)GetParent();
2256 case TOOLBAR_LOAD_FILE
:
2257 frame
->SetStatusText("Load project file");
2259 case TOOLBAR_SAVE_FILE
:
2260 frame
->SetStatusText("Save project file");
2263 frame
->SetStatusText("Create a new resource");
2265 case TOOLBAR_FORMAT_HORIZ
:
2266 frame
->SetStatusText("Align items horizontally");
2268 case TOOLBAR_FORMAT_VERT
:
2269 frame
->SetStatusText("Align items vertically");
2271 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2272 frame
->SetStatusText("Left-align items");
2274 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2275 frame
->SetStatusText("Right-align items");
2277 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2278 frame
->SetStatusText("Top-align items");
2280 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2281 frame
->SetStatusText("Bottom-align items");
2283 case TOOLBAR_COPY_SIZE
:
2284 frame
->SetStatusText("Copy size from first selection");
2286 case TOOLBAR_TO_FRONT
:
2287 frame
->SetStatusText("Put image to front");
2289 case TOOLBAR_TO_BACK
:
2290 frame
->SetStatusText("Put image to back");
2293 frame
->SetStatusText("Display help contents");
2299 else frame
->SetStatusText("");
2302 void EditorToolBar::OnPaint(wxPaintEvent
& event
)
2304 wxToolBar::OnPaint(event
);
2309 dc
.SetPen(wxBLACK_PEN
);
2310 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
2311 dc
.DrawLine(0, h
-1, w
, h
-1);