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(__WINDOWS__) && !defined(__GNUWIN32__)
47 #include <strstream.h>
61 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
62 void wxResourceEditWindow(wxWindow
*win
);
63 wxWindowPropertyInfo
*wxCreatePropertyInfoForWindow(wxWindow
*win
);
64 wxResourceManager
*wxResourceManager::currentResourceManager
= NULL
;
66 // Bitmaps for toolbar
67 wxBitmap
*ToolbarLoadBitmap
= NULL
;
68 wxBitmap
*ToolbarSaveBitmap
= NULL
;
69 wxBitmap
*ToolbarNewBitmap
= NULL
;
70 wxBitmap
*ToolbarVertBitmap
= NULL
;
71 wxBitmap
*ToolbarAlignTBitmap
= NULL
;
72 wxBitmap
*ToolbarAlignBBitmap
= NULL
;
73 wxBitmap
*ToolbarHorizBitmap
= NULL
;
74 wxBitmap
*ToolbarAlignLBitmap
= NULL
;
75 wxBitmap
*ToolbarAlignRBitmap
= NULL
;
76 wxBitmap
*ToolbarCopySizeBitmap
= NULL
;
77 wxBitmap
*ToolbarToFrontBitmap
= NULL
;
78 wxBitmap
*ToolbarToBackBitmap
= NULL
;
79 wxBitmap
*ToolbarHelpBitmap
= NULL
;
81 wxBitmap
*wxWinBitmap
= NULL
;
84 #include "bitmaps/load.xbm"
85 #include "bitmaps/save.xbm"
86 #include "bitmaps/new.xbm"
87 #include "bitmaps/vert.xbm"
88 #include "bitmaps/alignt.xbm"
89 #include "bitmaps/alignb.xbm"
90 #include "bitmaps/horiz.xbm"
91 #include "bitmaps/alignl.xbm"
92 #include "bitmaps/alignr.xbm"
93 #include "bitmaps/copysize.xbm"
94 #include "bitmaps/tofront.xbm"
95 #include "bitmaps/toback.xbm"
96 #include "bitmaps/help.xbm"
97 #include "bitmaps/wxwin.xbm"
105 wxResourceManager::wxResourceManager(void)
107 currentResourceManager
= this;
111 editorResourceList
= NULL
;
112 editorPalette
= NULL
;
115 currentFilename
= "";
117 editorToolBar
= NULL
;
119 // Default window positions
120 resourceEditorWindowSize
.width
= 470;
121 resourceEditorWindowSize
.height
= 300;
123 resourceEditorWindowSize
.x
= 0;
124 resourceEditorWindowSize
.y
= 0;
126 propertyWindowSize
.width
= 300;
127 propertyWindowSize
.height
= 300;
132 wxResourceManager::~wxResourceManager(void)
134 currentResourceManager
= NULL
;
137 helpInstance
->Quit();
142 bool wxResourceManager::Initialize(void)
144 // Set up the resource filename for each platform.
146 // dialoged.ini in the Windows directory
148 GetWindowsDirectory(buf
, 256);
149 strcat(buf
, "\\dialoged.ini");
150 optionsResourceFilename
= buf
;
153 (void)wxGetHomeDir(buf
);
154 strcat(buf
, "/.hardyrc");
155 optionsResourceFilename
= buf
;
157 #error "Unsupported platform."
162 helpInstance
= new wxHelpController
;
163 helpInstance
->Initialize("dialoged");
166 popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
167 popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
168 popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
173 wxWinBitmap
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
176 wxWinBitmap
= new wxBitmap(wxwin_bits
, wxwin_width
, wxwin_height
);
182 bool wxResourceManager::LoadOptions(void)
184 wxGetResource("DialogEd", "editorWindowX", &resourceEditorWindowSize
.x
, optionsResourceFilename
.GetData());
185 wxGetResource("DialogEd", "editorWindowY", &resourceEditorWindowSize
.y
, optionsResourceFilename
.GetData());
186 wxGetResource("DialogEd", "editorWindowWidth", &resourceEditorWindowSize
.width
, optionsResourceFilename
.GetData());
187 wxGetResource("DialogEd", "editorWindowHeight", &resourceEditorWindowSize
.height
, optionsResourceFilename
.GetData());
188 wxGetResource("DialogEd", "propertyWindowX", &propertyWindowSize
.x
, optionsResourceFilename
.GetData());
189 wxGetResource("DialogEd", "propertyWindowY", &propertyWindowSize
.y
, optionsResourceFilename
.GetData());
190 wxGetResource("DialogEd", "propertyWindowWidth", &propertyWindowSize
.width
, optionsResourceFilename
.GetData());
191 wxGetResource("DialogEd", "propertyWindowHeight", &propertyWindowSize
.height
, optionsResourceFilename
.GetData());
195 bool wxResourceManager::SaveOptions(void)
197 wxWriteResource("DialogEd", "editorWindowX", resourceEditorWindowSize
.x
, optionsResourceFilename
.GetData());
198 wxWriteResource("DialogEd", "editorWindowY", resourceEditorWindowSize
.y
, optionsResourceFilename
.GetData());
199 wxWriteResource("DialogEd", "editorWindowWidth", resourceEditorWindowSize
.width
, optionsResourceFilename
.GetData());
200 wxWriteResource("DialogEd", "editorWindowHeight", resourceEditorWindowSize
.height
, optionsResourceFilename
.GetData());
202 wxWriteResource("DialogEd", "propertyWindowX", propertyWindowSize
.x
, optionsResourceFilename
.GetData());
203 wxWriteResource("DialogEd", "propertyWindowY", propertyWindowSize
.y
, optionsResourceFilename
.GetData());
204 wxWriteResource("DialogEd", "propertyWindowWidth", propertyWindowSize
.width
, optionsResourceFilename
.GetData());
205 wxWriteResource("DialogEd", "propertyWindowHeight", propertyWindowSize
.height
, optionsResourceFilename
.GetData());
210 // Show or hide the resource editor frame, which displays a list
211 // of resources with ability to edit them.
212 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*parent
, const char *title
)
218 editorFrame
->Iconize(FALSE
);
219 editorFrame
->Show(TRUE
);
222 editorFrame
= OnCreateEditorFrame(title
);
224 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(editorFrame
);
225 editorFrame
->SetMenuBar(menuBar
);
226 editorPanel
= OnCreateEditorPanel(editorFrame
);
227 editorToolBar
= (EditorToolBar
*)OnCreateToolBar(editorFrame
);
228 editorPalette
= OnCreatePalette(editorFrame
);
230 // Constraints for toolbar
231 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
232 c
->left
.SameAs (editorFrame
, wxLeft
, 0);
233 c
->top
.SameAs (editorFrame
, wxTop
, 0);
234 c
->right
.SameAs (editorFrame
, wxRight
, 0);
235 c
->bottom
.Unconstrained();
236 c
->width
.Unconstrained();
237 c
->height
.Absolute(28);
238 editorToolBar
->SetConstraints(c
);
240 // Constraints for palette
241 c
= new wxLayoutConstraints
;
242 c
->left
.SameAs (editorFrame
, wxLeft
, 0);
243 c
->top
.SameAs (editorToolBar
, wxBottom
, 0);
244 c
->right
.SameAs (editorFrame
, wxRight
, 0);
245 c
->bottom
.Unconstrained();
246 c
->width
.Unconstrained();
247 c
->height
.Absolute(34);
248 editorPalette
->SetConstraints(c
);
250 // Constraints for panel
251 c
= new wxLayoutConstraints
;
252 c
->left
.SameAs (editorFrame
, wxLeft
, 0);
253 c
->top
.SameAs (editorPalette
, wxBottom
, 0);
254 c
->right
.SameAs (editorFrame
, wxRight
, 0);
255 c
->bottom
.SameAs (editorFrame
, wxBottom
, 0);
256 c
->width
.Unconstrained();
257 c
->height
.Unconstrained();
258 editorPanel
->SetConstraints(c
);
260 editorFrame
->SetAutoLayout(TRUE
);
262 UpdateResourceList();
263 editorFrame
->Show(TRUE
);
268 wxFrame
*fr
= editorFrame
;
269 if (editorFrame
->OnClose())
280 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
284 if (filename
== wxString(""))
285 editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
288 wxString
str("wxWindows Dialog Editor - ");
289 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
291 editorFrame
->SetTitle(str
);
296 bool wxResourceManager::Save(void)
298 if (currentFilename
== wxString(""))
301 return Save(currentFilename
);
304 bool wxResourceManager::Save(const wxString
& filename
)
306 // Ensure all visible windows are saved to their resources
307 currentFilename
= filename
;
308 SetFrameTitle(currentFilename
);
309 InstantiateAllResourcesFromWindows();
310 if (resourceTable
.Save(filename
))
319 bool wxResourceManager::SaveAs(void)
321 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST currentFilename
), wxFileNameFromPath(WXSTRINGCAST currentFilename
),
322 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
));
324 if (s
.IsNull() || s
== "")
328 Save(currentFilename
);
332 bool wxResourceManager::SaveIfModified(void)
339 bool wxResourceManager::Load(const wxString
& filename
)
341 return New(TRUE
, filename
);
344 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
346 if (!Clear(TRUE
, FALSE
))
351 wxString str
= filename
;
352 if (str
== wxString(""))
354 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, NULL
));
355 if (!f
.IsNull() && f
!= "")
361 if (!resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
363 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
366 currentFilename
= str
;
368 SetFrameTitle(currentFilename
);
370 UpdateResourceList();
375 currentFilename
= "";
382 bool wxResourceManager::Clear(bool deleteWindows
, bool force
)
384 if (!force
&& Modified())
386 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
390 if (!SaveIfModified())
396 DisassociateWindows(deleteWindows
);
398 resourceTable
.ClearTable();
399 UpdateResourceList();
404 bool wxResourceManager::DisassociateWindows(bool deleteWindows
)
406 resourceTable
.BeginFind();
408 while (node
= resourceTable
.Next())
410 wxItemResource
*res
= (wxItemResource
*)node
->Data();
411 DisassociateResource(res
, deleteWindows
);
417 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
419 if (!resourceAssociations
.Get((long)resource
))
420 resourceAssociations
.Put((long)resource
, win
);
422 wxNode
*node
= resource
->GetChildren().First();
425 wxItemResource
*child
= (wxItemResource
*)node
->Data();
426 wxWindow
*childWindow
= (wxWindow
*)resourceAssociations
.Get((long)child
);
428 childWindow
= win
->FindWindow(child
->GetName());
430 AssociateResource(child
, childWindow
);
434 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? child
->GetName() : "(unnamed)");
435 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
442 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
, bool deleteWindow
)
444 wxWindow
*win
= FindWindowForResource(resource
);
448 // Disassociate children of window without deleting windows
449 // since they'll be deleted by parent.
450 if (win
->GetChildren())
452 wxNode
*node
= win
->GetChildren()->First();
455 wxWindow
*child
= (wxWindow
*)node
->Data();
456 if (child
->IsKindOf(CLASSINFO(wxControl
)))
457 DisassociateResource(child
, FALSE
);
464 if (win
->IsKindOf(CLASSINFO(wxPanel
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
465 delete win
->GetParent(); // Delete frame
466 else if ( win
->IsKindOf(CLASSINFO(wxControl
)) )
468 wxEvtHandler
*childHandler
= win
->GetEventHandler();
469 if ( childHandler
!= win
)
471 win
->PopEventHandler();
477 // Is this enough? What about event handler? TODO
480 RemoveSelection(win
);
481 resourceAssociations
.Delete((long)resource
);
485 bool wxResourceManager::DisassociateResource(wxWindow
*win
, bool deleteWindow
)
487 wxItemResource
*res
= FindResourceForWindow(win
);
489 return DisassociateResource(res
, deleteWindow
);
493 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
495 resourceAssociations
.BeginFind();
497 while (node
= resourceAssociations
.Next())
499 wxWindow
*w
= (wxWindow
*)node
->Data();
502 return (wxItemResource
*)node
->key
.integer
;
508 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
510 return (wxWindow
*)resourceAssociations
.Get((long)resource
);
514 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
518 sprintf(buf
, "%s%d", prefix
, nameCounter
);
521 if (!resourceTable
.FindResource(buf
))
526 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
528 int frameWidth
= 420;
529 int frameHeight
= 300;
531 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, (char *)title
,
533 resourceEditorWindowSize
.x
, resourceEditorWindowSize
.y
,
534 resourceEditorWindowSize
.width
, resourceEditorWindowSize
.height
,
538 wxFrame::UseNativeStatusBar(FALSE
);
540 frame
->CreateStatusBar(2);
542 wxFrame::UseNativeStatusBar(TRUE
);
544 frame
->SetStatusText(editMode
? "Edit mode" : "Test mode", 1);
545 frame
->SetAutoLayout(TRUE
);
547 wxIcon
*icon
= new wxIcon("DIALOGEDICON");
548 frame
->SetIcon(icon
);
553 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*parent
)
555 wxMenuBar
*menuBar
= new wxMenuBar
;
557 wxMenu
*fileMenu
= new wxMenu
;
558 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
559 fileMenu
->Append(RESED_NEW_PANEL
, "New &panel", "Create a new panel");
560 fileMenu
->AppendSeparator();
561 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
562 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
563 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
564 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
565 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
566 fileMenu
->AppendSeparator();
567 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
569 wxMenu
*editMenu
= new wxMenu
;
570 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
571 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
572 editMenu
->AppendSeparator();
573 editMenu
->Append(RESED_TOGGLE_TEST_MODE
, "&Toggle edit/test mode", "Toggle edit/test mode");
575 wxMenu
*helpMenu
= new wxMenu
;
576 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
577 helpMenu
->AppendSeparator();
578 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
580 menuBar
->Append(fileMenu
, "&File");
581 menuBar
->Append(editMenu
, "&Edit");
582 menuBar
->Append(helpMenu
, "&Help");
587 wxPanel
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
589 wxResourceEditorPanel
*panel
= new wxResourceEditorPanel(parent
);
591 editorResourceList
= new wxListBox(panel
, -1, wxPoint(0, 0), wxSize(-1, -1));
593 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
594 c
->left
.SameAs (panel
, wxLeft
, 5);
595 c
->top
.SameAs (panel
, wxTop
, 5);
596 c
->right
.SameAs (panel
, wxRight
, 5);
597 c
->bottom
.SameAs (panel
, wxBottom
, 5);
598 c
->width
.Unconstrained();
599 c
->height
.Unconstrained();
600 editorResourceList
->SetConstraints(c
);
605 wxToolBarBase
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
607 // Load palette bitmaps
609 ToolbarLoadBitmap
= new wxBitmap("LOADTOOL");
610 ToolbarSaveBitmap
= new wxBitmap("SAVETOOL");
611 ToolbarNewBitmap
= new wxBitmap("NEWTOOL");
612 ToolbarVertBitmap
= new wxBitmap("VERTTOOL");
613 ToolbarAlignTBitmap
= new wxBitmap("ALIGNTTOOL");
614 ToolbarAlignBBitmap
= new wxBitmap("ALIGNBTOOL");
615 ToolbarHorizBitmap
= new wxBitmap("HORIZTOOL");
616 ToolbarAlignLBitmap
= new wxBitmap("ALIGNLTOOL");
617 ToolbarAlignRBitmap
= new wxBitmap("ALIGNRTOOL");
618 ToolbarCopySizeBitmap
= new wxBitmap("COPYSIZETOOL");
619 ToolbarToBackBitmap
= new wxBitmap("TOBACKTOOL");
620 ToolbarToFrontBitmap
= new wxBitmap("TOFRONTTOOL");
621 ToolbarHelpBitmap
= new wxBitmap("HELPTOOL");
624 ToolbarLoadBitmap
= new wxBitmap(load_bits
, load_width
, load_height
);
625 ToolbarSaveBitmap
= new wxBitmap(save_bits
, save_width
, save_height
);
626 ToolbarNewBitmap
= new wxBitmap(new_bits
, save_width
, save_height
);
627 ToolbarVertBitmap
= new wxBitmap(vert_bits
, vert_width
, vert_height
);
628 ToolbarAlignTBitmap
= new wxBitmap(alignt_bits
, alignt_width
, alignt_height
);
629 ToolbarAlignBBitmap
= new wxBitmap(alignb_bits
, alignb_width
, alignb_height
);
630 ToolbarHorizBitmap
= new wxBitmap(horiz_bits
, horiz_width
, horiz_height
);
631 ToolbarAlignLBitmap
= new wxBitmap(alignl_bits
, alignl_width
, alignl_height
);
632 ToolbarAlignRBitmap
= new wxBitmap(alignr_bits
, alignr_width
, alignr_height
);
633 ToolbarCopySizeBitmap
= new wxBitmap(copysize_bits
, copysize_width
, copysize_height
);
634 ToolbarToBackBitmap
= new wxBitmap(toback_bits
, toback_width
, toback_height
);
635 ToolbarToFrontBitmap
= new wxBitmap(tofront_bits
, tofront_width
, tofront_height
);
636 // ToolbarCPPBitmap = new wxBitmap(cpp_bits, cpp_width, cpp_height);
637 // ToolbarTreeBitmap = new wxBitmap(tree_bits, tree_width, tree_height);
638 ToolbarHelpBitmap
= new wxBitmap(help_bits
, help_width
, help_height
);
641 // Create the toolbar
642 EditorToolBar
*toolbar
= new EditorToolBar(parent
, 0, 0, -1, -1, wxNO_BORDER
,
644 toolbar
->SetMargins(2, 2);
645 // toolbar->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH);
652 int width
= ToolbarLoadBitmap
->GetWidth();
657 toolbar
->AddSeparator();
658 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, (wxBitmap
*)NULL
,
659 FALSE
, (float)currentX
, -1, NULL
, "New dialog");
660 currentX
+= width
+ dx
;
661 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, (wxBitmap
*)NULL
,
662 FALSE
, (float)currentX
, -1, NULL
, "Load");
663 currentX
+= width
+ dx
;
664 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, (wxBitmap
*)NULL
,
665 FALSE
, (float)currentX
, -1, NULL
, "Save");
666 currentX
+= width
+ dx
+ gap
;
667 toolbar
->AddSeparator();
668 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, (wxBitmap
*)NULL
,
669 FALSE
, (float)currentX
, -1, NULL
, "Horizontal align");
670 currentX
+= width
+ dx
;
671 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, (wxBitmap
*)NULL
,
672 FALSE
, (float)currentX
, -1, NULL
, "Top align");
673 currentX
+= width
+ dx
;
674 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, (wxBitmap
*)NULL
,
675 FALSE
, (float)currentX
, -1, NULL
, "Bottom align");
676 currentX
+= width
+ dx
;
677 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, (wxBitmap
*)NULL
,
678 FALSE
, (float)currentX
, -1, NULL
, "Vertical align");
679 currentX
+= width
+ dx
;
680 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, (wxBitmap
*)NULL
,
681 FALSE
, (float)currentX
, -1, NULL
, "Left align");
682 currentX
+= width
+ dx
;
683 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, (wxBitmap
*)NULL
,
684 FALSE
, (float)currentX
, -1, NULL
, "Right align");
685 currentX
+= width
+ dx
;
686 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, (wxBitmap
*)NULL
,
687 FALSE
, (float)currentX
, -1, NULL
, "Copy size");
688 currentX
+= width
+ dx
+ gap
;
689 toolbar
->AddSeparator();
690 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, (wxBitmap
*)NULL
,
691 FALSE
, (float)currentX
, -1, NULL
, "To front");
692 currentX
+= width
+ dx
;
693 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, (wxBitmap
*)NULL
,
694 FALSE
, (float)currentX
, -1, NULL
, "To back");
695 currentX
+= width
+ dx
+ gap
;
697 toolbar->AddTool(TOOLBAR_GEN_CPP, ToolbarCPPBitmap, (wxBitmap *)NULL,
698 FALSE, (float)currentX, -1, NULL);
699 currentX += width + dx;
701 toolbar->AddTool(TOOLBAR_TREE, ToolbarTreeBitmap, (wxBitmap *)NULL,
702 FALSE, (float)currentX, -1, NULL);
703 currentX += width + dx;
705 toolbar
->AddSeparator();
706 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, (wxBitmap
*)NULL
,
707 FALSE
, (float)currentX
, -1, NULL
, "Help");
708 currentX
+= width
+ dx
;
710 toolbar
->CreateTools();
714 // parent->OnSize(-1, -1);
717 void wxResourceManager::UpdateResourceList(void)
719 editorResourceList
->Clear();
720 resourceTable
.BeginFind();
722 while (node
= resourceTable
.Next())
724 wxItemResource
*res
= (wxItemResource
*)node
->Data();
725 wxString
resType(res
->GetType());
726 // if (res->GetType() == wxTYPE_DIALOG_BOX || res->GetType() == wxTYPE_FRAME || res->GetType() == wxTYPE_BITMAP)
727 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
729 AddItemsRecursively(0, res
);
734 void wxResourceManager::AddItemsRecursively(int level
, wxItemResource
*resource
)
736 int padWidth
= level
*4;
738 wxString
theString("");
739 theString
.Append(' ', padWidth
);
740 theString
+= resource
->GetName();
742 editorResourceList
->Append(theString
.GetData(), (char *)resource
);
744 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
746 wxNode
*node
= resource
->GetChildren().First();
749 wxItemResource
*res
= (wxItemResource
*)node
->Data();
750 AddItemsRecursively(level
+1, res
);
756 bool wxResourceManager::EditSelectedResource(void)
758 int sel
= editorResourceList
->GetSelection();
761 wxItemResource
*res
= (wxItemResource
*)editorResourceList
->wxListBox::GetClientData(sel
);
767 bool wxResourceManager::Edit(wxItemResource
*res
)
769 wxString
resType(res
->GetType());
770 if (resType
== "wxDialog" || resType
== "wxDialogBox")
772 wxDialog
*dialog
= (wxDialog
*)FindWindowForResource(res
);
777 dialog
= new wxDialog
;
778 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(dialog
, res
, dialog
->GetEventHandler(),
780 dialog
->PushEventHandler(handler
);
782 // dialog->SetUserEditMode(TRUE);
784 dialog
->LoadFromResource(GetEditorFrame(), res
->GetName(), &resourceTable
);
785 handler
->AddChildHandlers(); // Add event handlers for all controls
786 dialog
->SetModal(FALSE
);
787 AssociateResource(res
, dialog
);
791 else if (resType
== "wxPanel")
793 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
795 panel
->GetParent()->Show(TRUE
);
798 DialogEditorPanelFrame
*frame
= new DialogEditorPanelFrame(GetEditorFrame(), res
->GetName(), 10, 10, 400, 300, wxDEFAULT_FRAME_STYLE
, res
->GetName());
800 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
802 panel
->PushEventHandler(handler
);
803 // panel->SetUserEditMode(TRUE);
805 panel
->LoadFromResource(frame
, res
->GetName(), &resourceTable
);
806 handler
->AddChildHandlers(); // Add event handlers for all controls
807 AssociateResource(res
, panel
);
808 frame
->SetClientSize(res
->GetWidth(), res
->GetHeight());
815 bool wxResourceManager::CreateNewDialog(void)
818 MakeUniqueName("dialog", buf
);
820 wxItemResource
*resource
= new wxItemResource
;
821 // resource->SetType(wxTYPE_DIALOG_BOX);
822 resource
->SetType("wxDialog");
823 resource
->SetName(buf
);
824 resource
->SetTitle(buf
);
825 resourceTable
.AddResource(resource
);
828 wxDialog
*dialog
= new wxDialog(GetEditorFrame(), -1, buf
, wxPoint(10, 10), wxSize(400, 300), wxDEFAULT_DIALOG_STYLE
, buf
);
830 dialog->SetBackgroundColour(*wxLIGHT_GREY);
831 dialog->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH);
832 dialog->SetButtonColour(*wxBLACK);
833 dialog->SetLabelColour(*wxBLACK);
836 wxDialog
*dialog
= new wxDialog(GetEditorFrame(), -1, buf
, wxPoint(10, 10), wxSize(400, 300), wxDEFAULT_DIALOG_STYLE
, buf
);
839 resource
->SetValue1(FALSE
); // Modeless to start with
840 resource
->SetStyle(dialog
->GetWindowStyleFlag());
842 // For editing in situ we will need to use the hash table to ensure
843 // we don't dereference invalid pointers.
844 // resourceWindowTable.Put((long)resource, dialog);
846 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(dialog
, resource
, dialog
->GetEventHandler(),
849 dialog
->PushEventHandler(handler
);
851 dialog
->Centre(wxBOTH
);
852 // dialog->SetUserEditMode(TRUE);
855 SetEditMode(TRUE
, FALSE
);
857 AssociateResource(resource
, dialog
);
858 // SetCurrentResource(resource);
859 // SetCurrentResourceWindow(dialog);
860 UpdateResourceList();
867 bool wxResourceManager::CreateNewPanel(void)
870 MakeUniqueName("panel", buf
);
872 wxItemResource
*resource
= new wxItemResource
;
873 // resource->SetType(wxTYPE_PANEL);
874 resource
->SetType("wxPanel");
875 resource
->SetName(buf
);
876 resource
->SetTitle(buf
);
877 resourceTable
.AddResource(resource
);
879 DialogEditorPanelFrame
*frame
= new DialogEditorPanelFrame(GetEditorFrame(), buf
, 10, 10, 400, 300, wxDEFAULT_FRAME_STYLE
, buf
);
882 wxPanel
*panel
= new wxPanel(frame
, -1, wxPoint(0, 0), wxSize(400, 300), 0, buf
);
884 panel->SetBackgroundColour(*wxLIGHT_GREY);
885 panel->GetDC()->SetBackground(wxLIGHT_GREY_BRUSH);
886 panel->SetButtonColour(*wxBLACK);
887 panel->SetLabelColour(*wxBLACK);
891 wxPanel
*panel
= new wxPanel(frame
, -1, wxPoint(0, 0), wxSize(400, 300), 0, buf
);
894 resource
->SetStyle(panel
->GetWindowStyleFlag());
896 // For editing in situ we will need to use the hash table to ensure
897 // we don't dereference invalid pointers.
898 // resourceWindowTable.Put((long)resource, panel);
900 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
902 panel
->PushEventHandler(handler
);
904 panel
->Centre(wxBOTH
);
905 // panel->SetUserEditMode(TRUE);
908 SetEditMode(TRUE
, FALSE
);
910 AssociateResource(resource
, panel
);
911 // SetCurrentResource(resource);
912 // SetCurrentResourceWindow(panel);
913 UpdateResourceList();
920 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
923 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
928 wxItemResource
*res
= new wxItemResource
;
929 wxControl
*newItem
= NULL
;
930 res
->SetSize(x
, y
, -1, -1);
933 wxString
itemType(iType
);
935 if (itemType
== "wxButton")
937 MakeUniqueName("button", buf
);
940 newItem
= new wxBitmapButton(panel
, -1, wxWinBitmap
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
942 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
944 if (itemType
== "wxBitmapButton")
946 MakeUniqueName("button", buf
);
948 newItem
= new wxBitmapButton(panel
, -1, wxWinBitmap
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
950 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
952 MakeUniqueName("message", buf
);
955 newItem
= new wxStaticBitmap(panel
, -1, wxWinBitmap
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
957 newItem
= new wxStaticText(panel
, -1, "Message", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
959 else if (itemType
== "wxStaticBitmap")
961 MakeUniqueName("message", buf
);
963 newItem
= new wxStaticBitmap(panel
, -1, wxWinBitmap
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
965 else if (itemType
== "wxCheckBox")
967 MakeUniqueName("checkbox", buf
);
969 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
971 else if (itemType
== "wxListBox")
973 MakeUniqueName("listbox", buf
);
975 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
977 else if (itemType
== "wxRadioBox")
979 MakeUniqueName("radiobox", buf
);
981 wxString names
[] = { "One", "Two" };
982 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
983 wxHORIZONTAL
, wxDefaultValidator
, buf
);
984 res
->SetStringValues(new wxStringList("One", "Two", NULL
));
986 else if (itemType
== "wxChoice")
988 MakeUniqueName("choice", buf
);
990 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
992 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
994 MakeUniqueName("group", buf
);
996 newItem
= new wxStaticBox(panel
, -1, "Groupbox", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
998 else if (itemType
== "wxGauge")
1000 MakeUniqueName("gauge", buf
);
1002 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1004 else if (itemType
== "wxSlider")
1006 MakeUniqueName("slider", buf
);
1008 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1010 else if (itemType
== "wxText" || itemType
== "wxTextCtrl")
1012 MakeUniqueName("text", buf
);
1014 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1017 else if (itemType == "wxMultiText")
1019 MakeUniqueName("multitext", buf);
1021 newItem = new wxMultiText(panel, (wxFunction)NULL, "Multitext", "", x, y, -1, -1, 0, wxDefaultValidator, buf);
1024 else if (itemType
== "wxScrollBar")
1026 MakeUniqueName("scrollbar", buf
);
1028 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1033 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1035 res
->SetStyle(newItem
->GetWindowStyleFlag());
1036 AssociateResource(res
, newItem
);
1037 panelResource
->GetChildren().Append(res
);
1039 UpdateResourceList();
1044 // Find the first dialog or panel for which
1045 // there is a selected panel item.
1046 wxWindow
*wxResourceManager::FindParentOfSelection(void)
1048 resourceTable
.BeginFind();
1050 while (node
= resourceTable
.Next())
1052 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1053 wxWindow
*win
= FindWindowForResource(res
);
1056 wxNode
*node1
= win
->GetChildren()->First();
1059 wxControl
*item
= (wxControl
*)node1
->Data();
1060 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1061 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1063 node1
= node1
->Next();
1070 // Format the panel items according to 'flag'
1071 void wxResourceManager::AlignItems(int flag
)
1073 wxWindow
*win
= FindParentOfSelection();
1077 wxNode
*node
= GetSelections().First();
1081 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1082 if (firstSelection
->GetParent() != win
)
1087 firstSelection
->GetPosition(&firstX
, &firstY
);
1088 firstSelection
->GetSize(&firstW
, &firstH
);
1089 int centreX
= (int)(firstX
+ (firstW
/ 2));
1090 int centreY
= (int)(firstY
+ (firstH
/ 2));
1092 while (node
= node
->Next())
1094 wxControl
*item
= (wxControl
*)node
->Data();
1095 if (item
->GetParent() == win
)
1098 item
->GetPosition(&x
, &y
);
1099 item
->GetSize(&w
, &h
);
1105 case TOOLBAR_FORMAT_HORIZ
:
1108 newY
= (int)(centreY
- (h
/2.0));
1111 case TOOLBAR_FORMAT_VERT
:
1113 newX
= (int)(centreX
- (w
/2.0));
1117 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1123 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1129 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1131 newX
= firstX
+ firstW
- w
;
1135 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1138 newY
= firstY
+ firstH
- h
;
1146 item
->SetSize(newX
, newY
, w
, h
);
1152 // Copy the first image's size to subsequent images
1153 void wxResourceManager::CopySize(void)
1155 wxWindow
*win
= FindParentOfSelection();
1159 wxNode
*node
= GetSelections().First();
1163 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1164 if (firstSelection
->GetParent() != win
)
1169 firstSelection
->GetPosition(&firstX
, &firstY
);
1170 firstSelection
->GetSize(&firstW
, &firstH
);
1171 int centreX
= (int)(firstX
+ (firstW
/ 2));
1172 int centreY
= (int)(firstY
+ (firstH
/ 2));
1174 while (node
= node
->Next())
1176 wxControl
*item
= (wxControl
*)node
->Data();
1177 if (item
->GetParent() == win
)
1178 item
->SetSize(-1, -1, firstW
, firstH
);
1183 void wxResourceManager::ToBackOrFront(bool toBack
)
1185 wxWindow
*win
= FindParentOfSelection();
1188 wxItemResource
*winResource
= FindResourceForWindow(win
);
1190 wxNode
*node
= GetSelections().First();
1193 wxControl
*item
= (wxControl
*)node
->Data();
1194 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1195 if (item
->GetParent() == win
)
1197 win
->GetChildren()->DeleteObject(item
);
1199 winResource
->GetChildren().DeleteObject(itemResource
);
1202 win
->GetChildren()->Insert(item
);
1204 winResource
->GetChildren().Insert(itemResource
);
1208 win
->GetChildren()->Append(item
);
1210 winResource
->GetChildren().Append(itemResource
);
1213 node
= node
->Next();
1218 void wxResourceManager::AddSelection(wxWindow
*win
)
1220 if (!selections
.Member(win
))
1221 selections
.Append(win
);
1224 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1226 selections
.DeleteObject(win
);
1229 // Need to search through resource table removing this from
1230 // any resource which has this as a parent.
1231 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1233 resourceTable
.BeginFind();
1235 while (node
= resourceTable
.Next())
1237 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1238 if (thisRes
->GetChildren().Member(res
))
1240 thisRes
->GetChildren().DeleteObject(res
);
1247 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1252 RemoveResourceFromParent(res
);
1254 wxNode
*node
= res
->GetChildren().First();
1257 wxNode
*next
= node
->Next();
1258 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1259 DeleteResource(child
);
1263 // If this is a button or message resource, delete the
1264 // associate bitmap resource if not being used.
1265 wxString
resType(res
->GetType());
1267 if ((resType
== "wxMessage" || resType
== "wxButton") && res
->GetValue4())
1269 PossiblyDeleteBitmapResource(res
->GetValue4());
1272 resourceTable
.Delete(res
->GetName());
1278 bool wxResourceManager::DeleteResource(wxWindow
*win
, bool deleteWindow
)
1280 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1282 // Deselect and refresh window in case we leave selection
1284 wxControl
*item
= (wxControl
*)win
;
1285 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1286 if (childHandler
->IsSelected())
1288 RemoveSelection(item
);
1289 childHandler
->SelectItem(FALSE
);
1290 item
->GetParent()->Refresh();
1294 wxItemResource
*res
= FindResourceForWindow(win
);
1296 DisassociateResource(res
, deleteWindow
);
1297 DeleteResource(res
);
1298 UpdateResourceList();
1300 // What about associated event handler? Must clean up! BUGBUG
1301 // if (win && deleteWindow)
1306 // Will eventually have bitmap type information, for different
1308 char *wxResourceManager::AddBitmapResource(char *filename
)
1310 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1314 MakeUniqueName("bitmap", buf
);
1315 resource
= new wxItemResource
;
1316 resource
->SetType("wxBitmap");
1317 resource
->SetName(buf
);
1319 // A bitmap resource has one or more children, specifying
1320 // alternative bitmaps.
1321 wxItemResource
*child
= new wxItemResource
;
1322 child
->SetType("wxBitmap");
1323 child
->SetName(filename
);
1324 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1325 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1326 child
->SetValue3(0); // Depth
1327 child
->SetSize(0,0,0,0);
1328 resource
->GetChildren().Append(child
);
1330 resourceTable
.AddResource(resource
);
1332 UpdateResourceList();
1335 return resource
->GetName();
1340 // Delete the bitmap resource if it isn't being used by another resource.
1341 void wxResourceManager::PossiblyDeleteBitmapResource(char *resourceName
)
1343 if (!IsBitmapResourceUsed(resourceName
))
1345 wxItemResource
*res
= resourceTable
.FindResource(resourceName
);
1346 DeleteResource(res
);
1347 UpdateResourceList();
1351 bool wxResourceManager::IsBitmapResourceUsed(char *resourceName
)
1353 resourceTable
.BeginFind();
1355 while (node
= resourceTable
.Next())
1357 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1358 wxString
resType(res
->GetType());
1359 if (resType
== "wxDialog")
1361 wxNode
*node1
= res
->GetChildren().First();
1364 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1365 wxString
childResType(child
->GetType());
1367 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1368 child
->GetValue4() &&
1369 (strcmp(child
->GetValue4(), resourceName
) == 0))
1371 node1
= node1
->Next();
1378 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1379 char *wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1381 if (!resource
|| !resource
->GetValue4())
1383 wxItemResource
*bitmapResource
= resourceTable
.FindResource(resource
->GetValue4());
1384 if (!bitmapResource
)
1387 wxNode
*node
= bitmapResource
->GetChildren().First();
1390 // Eventually augment this to return a bitmap of the right kind or something...
1391 // Maybe the root of the filename remains the same, so it doesn't matter which we
1392 // pick up. Otherwise how do we specify multiple filenames... too boring...
1393 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1394 return child
->GetName();
1396 node
= node
->Next();
1401 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(char *filename
)
1403 resourceTable
.BeginFind();
1405 while (node
= resourceTable
.Next())
1407 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1408 wxString
resType(res
->GetType());
1409 if (resType
== "wxBitmap")
1411 wxNode
*node1
= res
->GetChildren().First();
1414 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1415 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1417 node1
= node1
->Next();
1424 // Deletes 'win' and creates a new window from the resource that
1425 // was associated with it. E.g. if you can't change properties on the
1426 // fly, you'll need to delete the window and create it again.
1427 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1429 wxItemResource
*resource
= FindResourceForWindow(win
);
1431 // Put the current window properties into the wxItemResource object
1433 wxWindowPropertyInfo
*newInfo
= NULL
;
1436 newInfo
= wxCreatePropertyInfoForWindow(win
);
1440 info
->InstantiateResource(resource
);
1442 wxWindow
*newWin
= NULL
;
1443 wxWindow
*parent
= win
->GetParent();
1445 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1447 bool isDialog
= win
->IsKindOf(CLASSINFO(wxDialog
));
1448 wxWindow
*parent
= win
->GetParent();
1450 win
->GetEventHandler()->OnClose();
1452 if (!isDialog
&& parent
)
1454 // Delete frame parent of panel if this is not a dialog box
1455 parent
->Close(TRUE
);
1459 newWin
= FindWindowForResource(resource
);
1463 DisassociateResource(resource
, FALSE
);
1465 newWin
= resourceTable
.CreateItem((wxPanel
*)parent
, resource
);
1466 AssociateResource(resource
, newWin
);
1467 UpdateResourceList();
1471 info
->SetPropertyWindow(newWin
);
1479 // Delete resource highlighted in the listbox
1480 bool wxResourceManager::DeleteSelection(bool deleteWindow
)
1482 int sel
= editorResourceList
->GetSelection();
1485 wxItemResource
*res
= (wxItemResource
*)editorResourceList
->wxListBox::GetClientData(sel
);
1486 wxWindow
*win
= FindWindowForResource(res
);
1488 if (res == currentResource)
1490 currentResource = NULL;
1491 currentResourceWindow = NULL;
1495 DisassociateResource(res
, deleteWindow
);
1496 DeleteResource(res
);
1497 UpdateResourceList();
1500 // What about associated event handler? Must clean up! BUGBUG
1501 if (win && deleteWindow)
1511 // Delete resource highlighted in the listbox
1512 bool wxResourceManager::RecreateSelection(void)
1514 wxNode
*node
= GetSelections().First();
1517 wxControl
*item
= (wxControl
*)node
->Data();
1518 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1519 wxNode
*next
= node
->Next();
1520 childHandler
->SelectItem(FALSE
);
1522 RemoveSelection(item
);
1524 RecreateWindowFromResource(item
);
1531 bool wxResourceManager::EditDialog(wxDialog
*dialog
, wxWindow
*parent
)
1536 void wxResourceManager::SetEditMode(bool flag
, bool changeCurrentResource
)
1540 editorFrame
->SetStatusText(editMode
? "Edit mode" : "Test mode", 1);
1542 // Switch mode for each dialog in the resource list
1543 resourceTable
.BeginFind();
1544 wxNode
*node
= resourceTable
.Next();
1547 wxItemResource
*resource
= (wxItemResource
*)node
->Data();
1548 wxWindow
*currentResourceWindow
= FindWindowForResource(resource
);
1550 if (changeCurrentResource
&& currentResourceWindow
&& (currentResourceWindow
->IsKindOf(CLASSINFO(wxPanel
))))
1552 wxPanel
*panel
= (wxPanel
*)currentResourceWindow
;
1555 // If we have already installed our own handler, don't bother editing.
1556 // This test will need to be changed eventually because for in-situ editing,
1557 // the user might have installed a different one anyway.
1558 wxEvtHandler
*handler
= panel
->GetEventHandler();
1559 handler
->SetEvtHandlerEnabled(TRUE
);
1560 // Enable all children
1561 wxNode
*node
= panel
->GetChildren()->First();
1564 wxControl
*item
= (wxControl
*)node
->Data();
1565 if ( item
->IsKindOf(CLASSINFO(wxControl
)) )
1567 wxEvtHandler
*childHandler
= item
->GetEventHandler();
1568 childHandler
->SetEvtHandlerEnabled(TRUE
);
1570 node
= node
->Next();
1575 wxEvtHandler
*handler
= panel
->GetEventHandler();
1576 handler
->SetEvtHandlerEnabled(FALSE
);
1577 // Deselect all items on the dialog and refresh.
1578 wxNode
*node
= panel
->GetChildren()->First();
1581 wxControl
*item
= (wxControl
*)node
->Data();
1582 if (item
->IsKindOf(CLASSINFO(wxControl
)))
1584 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1585 childHandler
->SetEvtHandlerEnabled(FALSE
);
1586 childHandler
->SelectItem(FALSE
);
1588 node
= node
->Next();
1593 node
= resourceTable
.Next();
1597 // Ensures that all currently shown windows are saved to resources,
1598 // e.g. just before writing to a .wxr file.
1599 bool wxResourceManager::InstantiateAllResourcesFromWindows(void)
1601 resourceTable
.BeginFind();
1603 while (node
= resourceTable
.Next())
1605 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1606 wxString
resType(res
->GetType());
1608 if (resType
== "wxDialog")
1610 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1612 InstantiateResourceFromWindow(res
, win
, TRUE
);
1614 else if (resType
== "wxPanel")
1616 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1618 InstantiateResourceFromWindow(res
, win
, TRUE
);
1624 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1626 wxWindowPropertyInfo
*info
= wxCreatePropertyInfoForWindow(window
);
1627 info
->SetResource(resource
);
1628 info
->InstantiateResource(resource
);
1633 wxNode
*node
= resource
->GetChildren().First();
1636 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1637 wxWindow
*childWindow
= FindWindowForResource(child
);
1642 sprintf(buf
, "Could not find window %s", child
->GetName());
1643 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1646 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1647 node
= node
->Next();
1656 * Resource editor frame
1659 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, char *title
,
1660 int x
, int y
, int width
, int height
, long style
, char *name
):
1661 wxFrame(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), style
, name
)
1666 wxResourceEditorFrame::~wxResourceEditorFrame(void)
1670 void wxResourceEditorFrame::OldOnMenuCommand(int cmd
)
1676 manager
->New(FALSE
);
1679 case RESED_NEW_DIALOG
:
1681 manager
->CreateNewDialog();
1684 case RESED_NEW_PANEL
:
1686 manager
->CreateNewPanel();
1696 manager
->Clear(TRUE
, FALSE
);
1711 manager
->Clear(TRUE
, FALSE
) ;
1718 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
1719 (void)wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
1722 case RESED_CONTENTS
:
1724 wxBeginBusyCursor();
1725 manager
->GetHelpInstance()->LoadFile();
1726 manager
->GetHelpInstance()->DisplayContents();
1732 manager
->DeleteSelection();
1735 case RESED_RECREATE
:
1737 manager
->RecreateSelection();
1740 case RESED_TOGGLE_TEST_MODE
:
1742 manager
->SetEditMode(!manager
->GetEditMode());
1750 bool wxResourceEditorFrame::OnClose(void)
1752 if (manager
->Modified())
1755 int ans = wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO | wxCANCEL);
1756 if (ans == wxCANCEL)
1759 if (!manager->SaveIfModified())
1762 if (!manager
->Clear(TRUE
, FALSE
))
1770 manager
->resourceEditorWindowSize
.width
= w
;
1771 manager
->resourceEditorWindowSize
.height
= h
;
1774 GetPosition(&x
, &y
);
1776 manager
->resourceEditorWindowSize
.x
= x
;
1777 manager
->resourceEditorWindowSize
.y
= y
;
1779 manager
->SetEditorFrame(NULL
);
1780 manager
->SetEditorToolBar(NULL
);
1781 manager
->SetEditorPalette(NULL
);
1787 * Resource editor panel
1790 wxResourceEditorPanel::wxResourceEditorPanel(wxWindow
*parent
, int x
, int y
, int width
, int height
,
1791 long style
, char *name
):
1792 wxPanel(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), style
, name
)
1796 wxResourceEditorPanel::~wxResourceEditorPanel(void)
1800 void wxResourceEditorPanel::OnDefaultAction(wxControl
*item
)
1802 wxResourceEditorFrame
*frame
= (wxResourceEditorFrame
*)GetParent();
1803 wxResourceManager
*manager
= frame
->manager
;
1805 if (item
== manager
->GetEditorResourceList())
1807 manager
->EditSelectedResource();
1811 // Popup menu callback
1812 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
1814 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
1818 switch (event
.GetInt())
1820 case OBJECT_MENU_EDIT
:
1822 wxResourceEditWindow(data
);
1825 case OBJECT_MENU_DELETE
:
1827 wxResourceManager::currentResourceManager
->DeleteResource(data
);
1835 wxWindowPropertyInfo
*wxCreatePropertyInfoForWindow(wxWindow
*win
)
1837 wxWindowPropertyInfo
*info
= NULL
;
1838 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1840 info
= new wxScrollBarPropertyInfo(win
);
1842 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1844 info
= new wxGroupBoxPropertyInfo(win
);
1846 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1848 info
= new wxCheckBoxPropertyInfo(win
);
1850 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1852 info
= new wxSliderPropertyInfo(win
);
1854 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1856 info
= new wxGaugePropertyInfo(win
);
1858 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1860 info
= new wxListBoxPropertyInfo(win
);
1862 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1864 info
= new wxRadioBoxPropertyInfo(win
);
1866 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1868 info
= new wxChoicePropertyInfo(win
);
1870 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1872 info
= new wxButtonPropertyInfo(win
);
1874 if (((wxButton *)win)->IsBitmap())
1875 ((wxButtonPropertyInfo *)info)->isBitmapButton = TRUE;
1878 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1880 info
= new wxStaticTextPropertyInfo(win
);
1882 if (((wxMessage *)win)->IsBitmap())
1883 ((wxMessagePropertyInfo *)info)->isBitmapMessage = TRUE;
1886 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1888 info
= new wxTextPropertyInfo(win
);
1890 else if (win
->IsKindOf(CLASSINFO(wxDialog
)))
1892 info
= new wxDialogPropertyInfo(win
);
1894 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1896 info
= new wxPanelPropertyInfo(win
);
1900 info
= new wxWindowPropertyInfo(win
);
1905 // Popup menu callback
1906 void wxResourceEditWindow(wxWindow
*win
)
1908 wxWindowPropertyInfo
*info
= wxCreatePropertyInfoForWindow(win
);
1911 info
->SetResource(wxResourceManager::currentResourceManager
->FindResourceForWindow(win
));
1912 wxString
str("Editing ");
1913 str
+= win
->GetClassInfo()->GetClassName();
1915 if (win
->GetName() != "")
1916 str
+= win
->GetName();
1918 str
+= "properties";
1919 info
->Edit(NULL
, WXSTRINGCAST str
);
1929 #if defined(__WINDOWS__) && defined(__WIN95__)
1930 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar95
)
1931 #elif defined(__WINDOWS__)
1932 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBarMSW
)
1934 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBarSimple
)
1936 EVT_PAINT(EditorToolBar::OnPaint
)
1939 EditorToolBar::EditorToolBar(wxFrame
*frame
, int x
, int y
, int w
, int h
,
1940 long style
, int direction
, int RowsOrColumns
):
1941 #if defined(__WINDOWS__) && defined(__WIN95__)
1942 wxToolBar95(frame
, -1, wxPoint(x
, y
), wxSize(w
, h
), style
, direction
, RowsOrColumns
)
1943 #elif defined(__WINDOWS__)
1944 wxToolBarMSW(frame
, -1, wxPoint(x
, y
), wxSize(w
, h
), style
, direction
, RowsOrColumns
)
1946 wxToolBarSimple(frame
, -1, wxPoint(x
, y
), wxSize(w
, h
), style
, direction
, RowsOrColumns
)
1951 bool EditorToolBar::OnLeftClick(int toolIndex
, bool toggled
)
1953 wxResourceManager
*manager
= wxResourceManager::currentResourceManager
;
1957 case TOOLBAR_LOAD_FILE
:
1964 manager
->New(FALSE
);
1967 case TOOLBAR_SAVE_FILE
:
1974 wxBeginBusyCursor();
1975 manager
->GetHelpInstance()->LoadFile();
1976 manager
->GetHelpInstance()->DisplayContents();
1980 case TOOLBAR_FORMAT_HORIZ
:
1982 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
1985 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1987 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
1990 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1992 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
1995 case TOOLBAR_FORMAT_VERT
:
1997 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2000 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2002 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2005 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2007 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2010 case TOOLBAR_COPY_SIZE
:
2012 manager
->CopySize();
2015 case TOOLBAR_TO_BACK
:
2017 manager
->ToBackOrFront(TRUE
);
2020 case TOOLBAR_TO_FRONT
:
2022 manager
->ToBackOrFront(FALSE
);
2031 void EditorToolBar::OnMouseEnter(int toolIndex
)
2033 wxFrame
*frame
= (wxFrame
*)GetParent();
2041 case TOOLBAR_LOAD_FILE
:
2042 frame
->SetStatusText("Load project file");
2044 case TOOLBAR_SAVE_FILE
:
2045 frame
->SetStatusText("Save project file");
2048 frame
->SetStatusText("Create a new resource");
2050 case TOOLBAR_FORMAT_HORIZ
:
2051 frame
->SetStatusText("Align items horizontally");
2053 case TOOLBAR_FORMAT_VERT
:
2054 frame
->SetStatusText("Align items vertically");
2056 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2057 frame
->SetStatusText("Left-align items");
2059 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2060 frame
->SetStatusText("Right-align items");
2062 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2063 frame
->SetStatusText("Top-align items");
2065 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2066 frame
->SetStatusText("Bottom-align items");
2068 case TOOLBAR_COPY_SIZE
:
2069 frame
->SetStatusText("Copy size from first selection");
2071 case TOOLBAR_TO_FRONT
:
2072 frame
->SetStatusText("Put image to front");
2074 case TOOLBAR_TO_BACK
:
2075 frame
->SetStatusText("Put image to back");
2078 frame
->SetStatusText("Display help contents");
2084 else frame
->SetStatusText("");
2087 void EditorToolBar::OnPaint(wxPaintEvent
& event
)
2089 #if defined(__WINDOWS__) && defined(__WIN95__)
2090 wxToolBar95::OnPaint(event
);
2091 #elif defined(__WINDOWS__)
2092 wxToolBarMSW::OnPaint(event
);
2094 wxToolBarSimple::OnPaint(event
);
2100 dc
.SetPen(wxBLACK_PEN
);
2101 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
2102 dc
.DrawLine(0, h
-1, w
, h
-1);
2106 * Frame for editing a panel in
2109 bool DialogEditorPanelFrame::OnClose(void)
2111 wxWindow
*child
= (wxWindow
*)GetChildren()->First()->Data();
2112 wxEvtHandler
*handler
= child
->GetEventHandler();
2113 return handler
->OnClose();