1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource editor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "reseditr.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/checkbox.h"
27 #include "wx/button.h"
28 #include "wx/choice.h"
29 #include "wx/listbox.h"
30 #include "wx/radiobox.h"
31 #include "wx/statbox.h"
33 #include "wx/slider.h"
34 #include "wx/textctrl.h"
36 #include "wx/toolbar.h"
39 #include "wx/scrolbar.h"
40 #include "wx/config.h"
48 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
51 #include <strstream.h>
71 static void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
);
72 wxResourceManager
*wxResourceManager::sm_currentResourceManager
= NULL
;
75 #include "bitmaps/load.xpm"
76 #include "bitmaps/save.xpm"
77 #include "bitmaps/new.xpm"
78 #include "bitmaps/vert.xpm"
79 #include "bitmaps/alignt.xpm"
80 #include "bitmaps/alignb.xpm"
81 #include "bitmaps/horiz.xpm"
82 #include "bitmaps/alignl.xpm"
83 #include "bitmaps/alignr.xpm"
84 #include "bitmaps/copysize.xpm"
85 #include "bitmaps/tofront.xpm"
86 #include "bitmaps/toback.xpm"
87 #include "bitmaps/help.xpm"
88 #include "bitmaps/wxwin.xpm"
95 wxResourceManager::wxResourceManager():
96 m_imageList(16, 16, TRUE
)
98 sm_currentResourceManager
= this;
100 m_editorPanel
= NULL
;
102 m_editorResourceTree
= NULL
;
103 m_editorControlList
= NULL
;
105 m_symbolIdCounter
= 99;
107 m_currentFilename
= "";
108 m_symbolFilename
= "";
109 m_editorToolBar
= NULL
;
111 // Default window positions
112 m_resourceEditorWindowSize
.width
= 500;
113 m_resourceEditorWindowSize
.height
= 450;
115 m_resourceEditorWindowSize
.x
= 0;
116 m_resourceEditorWindowSize
.y
= 0;
118 m_propertyWindowSize
.width
= 300;
119 m_propertyWindowSize
.height
= 300;
122 m_helpController
= NULL
;
125 m_bitmapImage
= NULL
;
126 m_rootDialogItem
= 0;
129 wxResourceManager::~wxResourceManager()
131 sm_currentResourceManager
= NULL
;
135 if (m_helpController
)
137 m_helpController
->Quit();
138 delete m_helpController
;
139 m_helpController
= NULL
;
143 delete m_bitmapImage
;
147 bool wxResourceManager::Initialize()
149 // Set up the resource filename for each platform.
151 // dialoged.ini in the Windows directory
153 GetWindowsDirectory(buf
, 256);
154 strcat(buf
, "\\dialoged.ini");
155 m_optionsResourceFilename
= buf
;
156 #elif defined(__WXGTK__)
157 wxGetHomeDir( &m_optionsResourceFilename
);
158 m_optionsResourceFilename
+= "/.dialogedrc";
160 #error "Unsupported platform."
166 m_helpController
= new wxHelpController
;
167 m_helpController
->Initialize("dialoged");
170 m_popupMenu
= new wxMenu("", (wxFunction
)ObjectMenuProc
);
171 m_popupMenu
->Append(OBJECT_MENU_EDIT
, "Edit properties");
172 m_popupMenu
->Append(OBJECT_MENU_DELETE
, "Delete object");
177 m_bitmapImage
= new wxBitmap("WXWINBMP", wxBITMAP_TYPE_BMP_RESOURCE
);
180 m_bitmapImage
= new wxBitmap( wxwin_xpm
);
184 // Initialize the image list icons
186 wxIcon
icon1("DIALOG_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
187 wxIcon
icon2("FOLDER1_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
188 wxIcon
icon3("FOLDER2_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
189 wxIcon
icon4("BUTTONSM_ICON", wxBITMAP_TYPE_ICO_RESOURCE
, 16, 16);
190 m_imageList
.Add(icon1
);
191 m_imageList
.Add(icon2
);
192 m_imageList
.Add(icon3
);
193 m_imageList
.Add(icon4
);
196 m_symbolTable
.AddStandardSymbols();
201 bool wxResourceManager::LoadOptions()
203 wxConfig
config("DialogEd", "wxWindows");
205 config
.Read("editorWindowX", &m_resourceEditorWindowSize
.x
);
206 config
.Read("editorWindowY", &m_resourceEditorWindowSize
.y
);
207 config
.Read("editorWindowWidth", &m_resourceEditorWindowSize
.width
);
208 config
.Read("editorWindowHeight", &m_resourceEditorWindowSize
.height
);
209 config
.Read("propertyWindowX", &m_propertyWindowSize
.x
);
210 config
.Read("propertyWindowY", &m_propertyWindowSize
.y
);
211 config
.Read("propertyWindowWidth", &m_propertyWindowSize
.width
);
212 config
.Read("propertyWindowHeight", &m_propertyWindowSize
.height
);
215 wxGetResource("DialogEd", "editorWindowX", &m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
216 wxGetResource("DialogEd", "editorWindowY", &m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
217 wxGetResource("DialogEd", "editorWindowWidth", &m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
218 wxGetResource("DialogEd", "editorWindowHeight", &m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
219 wxGetResource("DialogEd", "propertyWindowX", &m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
220 wxGetResource("DialogEd", "propertyWindowY", &m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
221 wxGetResource("DialogEd", "propertyWindowWidth", &m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
222 wxGetResource("DialogEd", "propertyWindowHeight", &m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
227 bool wxResourceManager::SaveOptions()
229 wxConfig
config("DialogEd", "wxWindows");
231 config
.Write("editorWindowX", m_resourceEditorWindowSize
.x
);
232 config
.Write("editorWindowY", m_resourceEditorWindowSize
.y
);
233 config
.Write("editorWindowWidth", m_resourceEditorWindowSize
.width
);
234 config
.Write("editorWindowHeight", m_resourceEditorWindowSize
.height
);
235 config
.Write("propertyWindowX", m_propertyWindowSize
.x
);
236 config
.Write("propertyWindowY", m_propertyWindowSize
.y
);
237 config
.Write("propertyWindowWidth", m_propertyWindowSize
.width
);
238 config
.Write("propertyWindowHeight", m_propertyWindowSize
.height
);
240 wxWriteResource("DialogEd", "editorWindowX", m_resourceEditorWindowSize.x, m_optionsResourceFilename.GetData());
241 wxWriteResource("DialogEd", "editorWindowY", m_resourceEditorWindowSize.y, m_optionsResourceFilename.GetData());
242 wxWriteResource("DialogEd", "editorWindowWidth", m_resourceEditorWindowSize.width, m_optionsResourceFilename.GetData());
243 wxWriteResource("DialogEd", "editorWindowHeight", m_resourceEditorWindowSize.height, m_optionsResourceFilename.GetData());
245 wxWriteResource("DialogEd", "propertyWindowX", m_propertyWindowSize.x, m_optionsResourceFilename.GetData());
246 wxWriteResource("DialogEd", "propertyWindowY", m_propertyWindowSize.y, m_optionsResourceFilename.GetData());
247 wxWriteResource("DialogEd", "propertyWindowWidth", m_propertyWindowSize.width, m_optionsResourceFilename.GetData());
248 wxWriteResource("DialogEd", "propertyWindowHeight", m_propertyWindowSize.height, m_optionsResourceFilename.GetData());
254 // Show or hide the resource editor frame, which displays a list
255 // of resources with ability to edit them.
256 bool wxResourceManager::ShowResourceEditor(bool show
, wxWindow
*WXUNUSED(parent
), const char *title
)
262 m_editorFrame
->Iconize(FALSE
);
263 m_editorFrame
->Show(TRUE
);
266 m_editorFrame
= OnCreateEditorFrame(title
);
268 wxMenuBar
*menuBar
= OnCreateEditorMenuBar(m_editorFrame
);
269 m_editorFrame
->SetMenuBar(menuBar
);
271 m_editorToolBar
= (EditorToolBar
*)OnCreateToolBar(m_editorFrame
);
272 m_editorControlList
= new wxResourceEditorControlList(m_editorFrame
, IDC_LISTCTRL
, wxPoint(0, 0), wxSize(-1, -1));
273 m_editorResourceTree
= new wxResourceEditorProjectTree(m_editorFrame
, IDC_TREECTRL
, wxPoint(0, 0), wxSize(-1, -1),
275 m_editorPanel
= OnCreateEditorPanel(m_editorFrame
);
277 m_editorResourceTree
->SetImageList(& m_imageList
);
279 // Constraints for toolbar
280 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
281 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
282 c
->top
.SameAs (m_editorFrame
, wxTop
, 0);
283 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
284 c
->bottom
.Unconstrained();
285 c
->width
.Unconstrained();
286 c
->height
.Absolute(28);
287 m_editorToolBar
->SetConstraints(c
);
289 // Constraints for listbox
290 c
= new wxLayoutConstraints
;
291 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
292 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
293 c
->right
.Absolute (150);
294 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
295 c
->width
.Unconstrained();
296 c
->height
.Unconstrained();
297 m_editorResourceTree
->SetConstraints(c
);
299 // Constraints for panel
300 c
= new wxLayoutConstraints
;
301 c
->left
.SameAs (m_editorResourceTree
, wxRight
, 0);
302 c
->top
.SameAs (m_editorToolBar
, wxBottom
, 0);
303 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
304 c
->bottom
.SameAs (m_editorControlList
, wxTop
, 0);
305 c
->width
.Unconstrained();
306 c
->height
.Unconstrained();
307 m_editorPanel
->SetConstraints(c
);
309 // Constraints for control list (bottom window)
310 c
= new wxLayoutConstraints
;
311 c
->left
.SameAs (m_editorFrame
, wxLeft
, 0);
312 c
->right
.SameAs (m_editorFrame
, wxRight
, 0);
313 c
->bottom
.SameAs (m_editorFrame
, wxBottom
, 0);
314 c
->width
.Unconstrained();
316 c
->height
.Absolute(105);
318 c
->height
.Absolute(60);
321 m_editorControlList
->SetConstraints(c
);
323 m_editorFrame
->SetAutoLayout(TRUE
);
325 UpdateResourceList();
327 m_editorFrame
->Show(TRUE
);
332 wxFrame
*fr
= m_editorFrame
;
333 if (m_editorFrame
->OnClose())
337 m_editorFrame
= NULL
;
338 m_editorPanel
= NULL
;
344 void wxResourceManager::SetFrameTitle(const wxString
& filename
)
348 if (filename
== wxString(""))
349 m_editorFrame
->SetTitle("wxWindows Dialog Editor - untitled");
352 wxString
str("wxWindows Dialog Editor - ");
353 wxString
str2(wxFileNameFromPath(WXSTRINGCAST filename
));
355 m_editorFrame
->SetTitle(str
);
360 bool wxResourceManager::Save()
362 if (m_currentFilename
== wxString(""))
365 return Save(m_currentFilename
);
368 bool wxResourceManager::Save(const wxString
& filename
)
370 // Ensure all visible windows are saved to their resources
371 m_currentFilename
= filename
;
372 SetFrameTitle(m_currentFilename
);
373 InstantiateAllResourcesFromWindows();
374 if (m_resourceTable
.Save(filename
))
376 m_symbolTable
.WriteIncludeFile(m_symbolFilename
);
384 bool wxResourceManager::SaveAs()
386 wxString
s(wxFileSelector("Save resource file", wxPathOnly(WXSTRINGCAST m_currentFilename
), wxFileNameFromPath(WXSTRINGCAST m_currentFilename
),
387 "wxr", "*.wxr", wxSAVE
| wxOVERWRITE_PROMPT
));
389 if (s
.IsNull() || s
== "")
392 m_currentFilename
= s
;
393 wxStripExtension(m_currentFilename
);
394 m_currentFilename
+= ".wxr";
396 // Construct include filename from this file
397 m_symbolFilename
= m_currentFilename
;
399 wxStripExtension(m_symbolFilename
);
400 m_symbolFilename
+= ".h";
402 Save(m_currentFilename
);
406 bool wxResourceManager::SaveIfModified()
413 bool wxResourceManager::Load(const wxString
& filename
)
415 return New(TRUE
, filename
);
418 bool wxResourceManager::New(bool loadFromFile
, const wxString
& filename
)
420 if (!Clear(TRUE
, FALSE
))
423 m_symbolTable
.AddStandardSymbols();
427 wxString str
= filename
;
428 if (str
== wxString(""))
430 wxString
f(wxFileSelector("Open resource file", NULL
, NULL
, "wxr", "*.wxr", 0, NULL
));
431 if (!f
.IsNull() && f
!= "")
437 if (!m_resourceTable
.ParseResourceFile(WXSTRINGCAST str
))
439 wxMessageBox("Could not read file.", "Resource file load error", wxOK
| wxICON_EXCLAMATION
);
442 m_currentFilename
= str
;
444 SetFrameTitle(m_currentFilename
);
446 UpdateResourceList();
448 // Construct include filename from this file
449 m_symbolFilename
= m_currentFilename
;
451 wxStripExtension(m_symbolFilename
);
452 m_symbolFilename
+= ".h";
454 if (!m_symbolTable
.ReadIncludeFile(m_symbolFilename
))
456 wxString
str("Could not find include file ");
457 str
+= m_symbolFilename
;
458 str
+= ".\nDialog Editor maintains a header file containing id symbols to be used in the application.\n";
459 str
+= "The next time this .wxr file is saved, a header file will be saved also.";
460 wxMessageBox(str
, "Dialog Editor Warning", wxOK
);
462 m_symbolIdCounter
= 99;
466 // Set the id counter to the last known id
467 m_symbolIdCounter
= m_symbolTable
.FindHighestId();
470 // Now check in case some (or all) resources don't have resource ids, or they
471 // don't match the .h file, or something of that nature.
472 bool altered
= RepairResourceIds();
475 wxMessageBox("Some resources have had new identifiers associated with them, since they were missing.",
476 "Dialog Editor Warning", wxOK
);
487 m_currentFilename
= "";
494 bool wxResourceManager::Clear(bool WXUNUSED(deleteWindows
), bool force
)
496 if (!force
&& Modified())
498 int ans
= wxMessageBox("Save modified resource file?", "Dialog Editor", wxYES_NO
| wxCANCEL
);
502 if (!SaveIfModified())
508 ClearCurrentDialog();
509 DisassociateWindows();
511 m_symbolTable
.Clear();
512 m_resourceTable
.ClearTable();
513 UpdateResourceList();
518 bool wxResourceManager::DisassociateWindows()
520 m_resourceTable
.BeginFind();
522 while ((node
= m_resourceTable
.Next()))
524 wxItemResource
*res
= (wxItemResource
*)node
->Data();
525 DisassociateResource(res
);
531 void wxResourceManager::AssociateResource(wxItemResource
*resource
, wxWindow
*win
)
533 if (!m_resourceAssociations
.Get((long)resource
))
534 m_resourceAssociations
.Put((long)resource
, win
);
536 wxNode
*node
= resource
->GetChildren().First();
539 wxItemResource
*child
= (wxItemResource
*)node
->Data();
540 wxWindow
*childWindow
= (wxWindow
*)m_resourceAssociations
.Get((long)child
);
542 childWindow
= win
->FindWindow(child
->GetName());
544 AssociateResource(child
, childWindow
);
548 sprintf(buf
, "AssociateResource: cannot find child window %s", child
->GetName() ? (const char*) child
->GetName() : "(unnamed)");
549 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
556 bool wxResourceManager::DisassociateResource(wxItemResource
*resource
)
558 wxWindow
*win
= FindWindowForResource(resource
);
562 // Disassociate children of window
563 wxNode
*node
= win
->GetChildren().First();
566 wxWindow
*child
= (wxWindow
*)node
->Data();
567 if (child
->IsKindOf(CLASSINFO(wxControl
)))
568 DisassociateResource(child
);
572 RemoveSelection(win
);
573 m_resourceAssociations
.Delete((long)resource
);
577 bool wxResourceManager::DisassociateResource(wxWindow
*win
)
579 wxItemResource
*res
= FindResourceForWindow(win
);
581 return DisassociateResource(res
);
586 // Saves the window info into the resource, and deletes the
587 // handler. Doesn't actually disassociate the window from
588 // the resources. Replaces OnClose.
589 bool wxResourceManager::SaveInfoAndDeleteHandler(wxWindow
* win
)
591 wxItemResource
*res
= FindResourceForWindow(win
);
593 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
595 wxResourceEditorDialogHandler
* handler
= (wxResourceEditorDialogHandler
*) win
->GetEventHandler();
596 win
->PopEventHandler();
598 // Now reset all child event handlers
599 wxNode
*node
= win
->GetChildren().First();
602 wxWindow
*child
= (wxWindow
*)node
->Data();
603 wxEvtHandler
*childHandler
= child
->GetEventHandler();
604 if ( child
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
!= child
)
606 child
->PopEventHandler(TRUE
);
614 win
->PopEventHandler(TRUE
);
617 // Save the information
618 InstantiateResourceFromWindow(res
, win
, TRUE
);
620 // DisassociateResource(win);
625 // Destroys the window. If this is the 'current' panel, NULLs the
627 bool wxResourceManager::DeleteWindow(wxWindow
* win
)
629 bool clearDisplay
= FALSE
;
630 if (m_editorPanel
->m_childWindow
== win
)
632 m_editorPanel
->m_childWindow
= NULL
;
639 m_editorPanel
->Clear();
644 wxItemResource
*wxResourceManager::FindResourceForWindow(wxWindow
*win
)
646 m_resourceAssociations
.BeginFind();
648 while ((node
= m_resourceAssociations
.Next()))
650 wxWindow
*w
= (wxWindow
*)node
->Data();
653 return (wxItemResource
*)node
->GetKeyInteger();
659 wxWindow
*wxResourceManager::FindWindowForResource(wxItemResource
*resource
)
661 return (wxWindow
*)m_resourceAssociations
.Get((long)resource
);
665 void wxResourceManager::MakeUniqueName(char *prefix
, char *buf
)
669 sprintf(buf
, "%s%d", prefix
, m_nameCounter
);
672 if (!m_resourceTable
.FindResource(buf
))
677 wxFrame
*wxResourceManager::OnCreateEditorFrame(const char *title
)
680 int frameWidth = 420;
681 int frameHeight = 300;
684 wxResourceEditorFrame
*frame
= new wxResourceEditorFrame(this, NULL
, title
,
685 wxPoint(m_resourceEditorWindowSize
.x
, m_resourceEditorWindowSize
.y
),
686 wxSize(m_resourceEditorWindowSize
.width
, m_resourceEditorWindowSize
.height
),
687 wxDEFAULT_FRAME_STYLE
);
689 frame
->CreateStatusBar(1);
691 frame
->SetAutoLayout(TRUE
);
693 frame
->SetIcon(wxIcon("DIALOGEDICON"));
698 wxMenuBar
*wxResourceManager::OnCreateEditorMenuBar(wxFrame
*WXUNUSED(parent
))
700 wxMenuBar
*menuBar
= new wxMenuBar
;
702 wxMenu
*fileMenu
= new wxMenu
;
703 fileMenu
->Append(RESED_NEW_DIALOG
, "New &dialog", "Create a new dialog");
704 fileMenu
->AppendSeparator();
705 fileMenu
->Append(wxID_NEW
, "&New project", "Clear the current project");
706 fileMenu
->Append(wxID_OPEN
, "&Open...", "Load a resource file");
707 fileMenu
->Append(wxID_SAVE
, "&Save", "Save a resource file");
708 fileMenu
->Append(wxID_SAVEAS
, "Save &As...", "Save a resource file as...");
709 fileMenu
->Append(RESED_CLEAR
, "&Clear", "Clear current resources");
710 fileMenu
->AppendSeparator();
711 fileMenu
->Append(wxID_EXIT
, "E&xit", "Exit resource editor");
713 wxMenu
*editMenu
= new wxMenu
;
714 editMenu
->Append(RESED_TEST
, "&Test Dialog", "Test dialog");
715 editMenu
->Append(RESED_RECREATE
, "&Recreate", "Recreate the selected resource(s)");
716 editMenu
->Append(RESED_DELETE
, "&Delete", "Delete the selected resource(s)");
718 wxMenu
*helpMenu
= new wxMenu
;
719 helpMenu
->Append(RESED_CONTENTS
, "&Help topics", "Invokes the on-line help");
720 helpMenu
->AppendSeparator();
721 helpMenu
->Append(wxID_ABOUT
, "&About", "About wxWindows Dialog Editor");
723 menuBar
->Append(fileMenu
, "&File");
724 menuBar
->Append(editMenu
, "&Edit");
725 menuBar
->Append(helpMenu
, "&Help");
730 wxResourceEditorScrolledWindow
*wxResourceManager::OnCreateEditorPanel(wxFrame
*parent
)
732 wxResourceEditorScrolledWindow
*panel
= new wxResourceEditorScrolledWindow(parent
, wxDefaultPosition
, wxDefaultSize
,
733 // wxSUNKEN_BORDER|wxCLIP_CHILDREN);
736 panel
->SetScrollbars(10, 10, 100, 100);
741 wxToolBar
*wxResourceManager::OnCreateToolBar(wxFrame
*parent
)
743 // Load palette bitmaps
745 wxBitmap
ToolbarLoadBitmap("LOADTOOL");
746 wxBitmap
ToolbarSaveBitmap("SAVETOOL");
747 wxBitmap
ToolbarNewBitmap("NEWTOOL");
748 wxBitmap
ToolbarVertBitmap("VERTTOOL");
749 wxBitmap
ToolbarAlignTBitmap("ALIGNTTOOL");
750 wxBitmap
ToolbarAlignBBitmap("ALIGNBTOOL");
751 wxBitmap
ToolbarHorizBitmap("HORIZTOOL");
752 wxBitmap
ToolbarAlignLBitmap("ALIGNLTOOL");
753 wxBitmap
ToolbarAlignRBitmap("ALIGNRTOOL");
754 wxBitmap
ToolbarCopySizeBitmap("COPYSIZETOOL");
755 wxBitmap
ToolbarToBackBitmap("TOBACKTOOL");
756 wxBitmap
ToolbarToFrontBitmap("TOFRONTTOOL");
757 wxBitmap
ToolbarHelpBitmap("HELPTOOL");
760 wxBitmap
ToolbarLoadBitmap( load_xpm
);
761 wxBitmap
ToolbarSaveBitmap( save_xpm
);
762 wxBitmap
ToolbarNewBitmap( new_xpm
);
763 wxBitmap
ToolbarVertBitmap( vert_xpm
);
764 wxBitmap
ToolbarAlignTBitmap( alignt_xpm
);
765 wxBitmap
ToolbarAlignBBitmap( alignb_xpm
);
766 wxBitmap
ToolbarHorizBitmap( horiz_xpm
);
767 wxBitmap
ToolbarAlignLBitmap( alignl_xpm
);
768 wxBitmap
ToolbarAlignRBitmap( alignr_xpm
);
769 wxBitmap
ToolbarCopySizeBitmap( copysize_xpm
);
770 wxBitmap
ToolbarToBackBitmap( toback_xpm
);
771 wxBitmap
ToolbarToFrontBitmap( tofront_xpm
);
772 wxBitmap
ToolbarHelpBitmap( help_xpm
);
775 // Create the toolbar
776 EditorToolBar
*toolbar
= new EditorToolBar(parent
, wxPoint(0, 0), wxSize(-1, -1), wxNO_BORDER
|wxTB_HORIZONTAL
);
777 toolbar
->SetMargins(2, 2);
784 int width
= 24; // ToolbarLoadBitmap->GetWidth(); ???
789 toolbar
->AddSeparator();
790 toolbar
->AddTool(TOOLBAR_NEW
, ToolbarNewBitmap
, wxNullBitmap
,
791 FALSE
, (float)currentX
, -1, NULL
, "New dialog");
792 currentX
+= width
+ dx
;
793 toolbar
->AddTool(TOOLBAR_LOAD_FILE
, ToolbarLoadBitmap
, wxNullBitmap
,
794 FALSE
, (float)currentX
, -1, NULL
, "Load");
795 currentX
+= width
+ dx
;
796 toolbar
->AddTool(TOOLBAR_SAVE_FILE
, ToolbarSaveBitmap
, wxNullBitmap
,
797 FALSE
, (float)currentX
, -1, NULL
, "Save");
798 currentX
+= width
+ dx
+ gap
;
799 toolbar
->AddSeparator();
800 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ
, ToolbarVertBitmap
, wxNullBitmap
,
801 FALSE
, (float)currentX
, -1, NULL
, "Horizontal align");
802 currentX
+= width
+ dx
;
803 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_TOP_ALIGN
, ToolbarAlignTBitmap
, wxNullBitmap
,
804 FALSE
, (float)currentX
, -1, NULL
, "Top align");
805 currentX
+= width
+ dx
;
806 toolbar
->AddTool(TOOLBAR_FORMAT_VERT_BOT_ALIGN
, ToolbarAlignBBitmap
, wxNullBitmap
,
807 FALSE
, (float)currentX
, -1, NULL
, "Bottom align");
808 currentX
+= width
+ dx
;
809 toolbar
->AddTool(TOOLBAR_FORMAT_VERT
, ToolbarHorizBitmap
, wxNullBitmap
,
810 FALSE
, (float)currentX
, -1, NULL
, "Vertical align");
811 currentX
+= width
+ dx
;
812 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
, ToolbarAlignLBitmap
, wxNullBitmap
,
813 FALSE
, (float)currentX
, -1, NULL
, "Left align");
814 currentX
+= width
+ dx
;
815 toolbar
->AddTool(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
, ToolbarAlignRBitmap
, wxNullBitmap
,
816 FALSE
, (float)currentX
, -1, NULL
, "Right align");
817 currentX
+= width
+ dx
;
818 toolbar
->AddTool(TOOLBAR_COPY_SIZE
, ToolbarCopySizeBitmap
, wxNullBitmap
,
819 FALSE
, (float)currentX
, -1, NULL
, "Copy size");
820 currentX
+= width
+ dx
+ gap
;
821 toolbar
->AddSeparator();
822 toolbar
->AddTool(TOOLBAR_TO_FRONT
, ToolbarToFrontBitmap
, wxNullBitmap
,
823 FALSE
, (float)currentX
, -1, NULL
, "To front");
824 currentX
+= width
+ dx
;
825 toolbar
->AddTool(TOOLBAR_TO_BACK
, ToolbarToBackBitmap
, wxNullBitmap
,
826 FALSE
, (float)currentX
, -1, NULL
, "To back");
827 currentX
+= width
+ dx
+ gap
;
829 toolbar
->AddSeparator();
830 toolbar
->AddTool(TOOLBAR_HELP
, ToolbarHelpBitmap
, wxNullBitmap
,
831 FALSE
, (float)currentX
, -1, NULL
, "Help");
832 currentX
+= width
+ dx
;
839 void wxResourceManager::UpdateResourceList()
841 if (!m_editorResourceTree
)
844 m_editorResourceTree
->SetInvalid(TRUE
);
845 m_editorResourceTree
->DeleteAllItems();
847 long id
= m_editorResourceTree
->AddRoot("Dialogs", 1, 2);
849 m_resourceTable
.BeginFind();
851 while ((node
= m_resourceTable
.Next()))
853 wxItemResource
*res
= (wxItemResource
*)node
->Data();
854 wxString
resType(res
->GetType());
855 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel" || resType
== "wxBitmap")
857 AddItemsRecursively(id
, res
);
860 m_editorResourceTree
->Expand(id
);
861 m_editorResourceTree
->SetInvalid(FALSE
);
864 void wxResourceManager::AddItemsRecursively(long parent
, wxItemResource
*resource
)
866 wxString
theString("");
867 theString
= resource
->GetName();
870 wxString
resType(resource
->GetType());
871 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
876 long id
= m_editorResourceTree
->AppendItem(parent
, theString
, imageId
);
878 m_editorResourceTree
->SetItemData(id
, new wxResourceTreeData(resource
));
880 if (strcmp(resource
->GetType(), "wxBitmap") != 0)
882 wxNode
*node
= resource
->GetChildren().First();
885 wxItemResource
*res
= (wxItemResource
*)node
->Data();
886 AddItemsRecursively(id
, res
);
890 // m_editorResourceTree->ExpandItem(id, wxTREE_EXPAND_EXPAND);
893 bool wxResourceManager::EditSelectedResource()
895 int sel
= m_editorResourceTree
->GetSelection();
898 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
899 wxItemResource
*res
= data
->GetResource();
905 bool wxResourceManager::Edit(wxItemResource
*res
)
907 ClearCurrentDialog();
909 wxString
resType(res
->GetType());
910 wxPanel
*panel
= (wxPanel
*)FindWindowForResource(res
);
914 wxMessageBox("Should not find panel in wxResourceManager::Edit");
919 // long style = res->GetStyle();
920 // res->SetStyle(style|wxRAISED_BORDER);
922 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, res
, panel
->GetEventHandler(),
925 panel
->LoadFromResource(m_editorPanel
, res
->GetName(), &m_resourceTable
);
927 panel
->PushEventHandler(handler
);
929 // res->SetStyle(style);
930 handler
->AddChildHandlers(); // Add event handlers for all controls
931 AssociateResource(res
, panel
);
933 m_editorPanel
->m_childWindow
= panel
;
934 panel
->Move(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY());
938 wxClientDC
dc(m_editorPanel
);
939 m_editorPanel
->DrawTitle(dc
);
944 bool wxResourceManager::CreateNewPanel()
946 ClearCurrentDialog();
949 MakeUniqueName("dialog", buf
);
951 wxItemResource
*resource
= new wxItemResource
;
952 resource
->SetType("wxDialog");
953 resource
->SetName(buf
);
954 resource
->SetTitle(buf
);
955 resource
->SetResourceStyle(wxRESOURCE_USE_DEFAULTS
);
956 resource
->SetResourceStyle(wxRESOURCE_DIALOG_UNITS
);
959 int id
= GenerateWindowId("ID_DIALOG", newIdName
);
962 // This is now guaranteed to be unique, so just add to symbol table
963 m_symbolTable
.AddSymbol(newIdName
, id
);
965 m_resourceTable
.AddResource(resource
);
967 wxSize
size(400, 300);
969 wxPanel
*panel
= new wxPanel(m_editorPanel
, -1,
970 wxPoint(m_editorPanel
->GetMarginX(), m_editorPanel
->GetMarginY()),
971 size
, wxRAISED_BORDER
|wxDEFAULT_DIALOG_STYLE
, buf
);
972 m_editorPanel
->m_childWindow
= panel
;
974 resource
->SetStyle(panel
->GetWindowStyleFlag());
976 // Store dialog units in resource
977 size
= panel
->ConvertPixelsToDialog(size
);
979 resource
->SetSize(10, 10, size
.x
, size
.y
);
981 // For editing in situ we will need to use the hash table to ensure
982 // we don't dereference invalid pointers.
983 // resourceWindowTable.Put((long)resource, panel);
985 wxResourceEditorDialogHandler
*handler
= new wxResourceEditorDialogHandler(panel
, resource
, panel
->GetEventHandler(),
987 panel
->PushEventHandler(handler
);
989 AssociateResource(resource
, panel
);
990 UpdateResourceList();
993 m_editorPanel
->m_childWindow
->Refresh();
997 wxClientDC
dc(m_editorPanel
);
998 m_editorPanel
->DrawTitle(dc
);
1003 bool wxResourceManager::CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *iType
, int x
, int y
, bool isBitmap
)
1006 if (!panel
->IsKindOf(CLASSINFO(wxPanel
)) && !panel
->IsKindOf(CLASSINFO(wxDialog
)))
1011 wxItemResource
*res
= new wxItemResource
;
1012 wxControl
*newItem
= NULL
;
1014 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1016 wxPoint pt
= panel
->ConvertPixelsToDialog(wxPoint(x
, y
));
1017 res
->SetSize(pt
.x
, pt
.y
, -1, -1);
1019 else res
->SetSize(x
, y
, -1, -1);
1021 res
->SetType(iType
);
1025 wxString
itemType(iType
);
1027 if (itemType
== "wxButton")
1029 prefix
= "ID_BUTTON";
1030 MakeUniqueName("button", buf
);
1033 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1035 newItem
= new wxButton(panel
, -1, "Button", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1037 if (itemType
== "wxBitmapButton")
1039 prefix
= "ID_BITMAPBUTTON";
1040 MakeUniqueName("button", buf
);
1042 newItem
= new wxBitmapButton(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1044 else if (itemType
== "wxMessage" || itemType
== "wxStaticText")
1046 prefix
= "ID_STATIC";
1047 MakeUniqueName("statictext", buf
);
1050 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(0, 0), 0, buf
);
1052 newItem
= new wxStaticText(panel
, -1, "Static", wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1054 else if (itemType
== "wxStaticBitmap")
1056 prefix
= "ID_STATICBITMAP";
1057 MakeUniqueName("static", buf
);
1059 newItem
= new wxStaticBitmap(panel
, -1, * m_bitmapImage
, wxPoint(x
, y
), wxSize(-1, -1), 0, buf
);
1061 else if (itemType
== "wxCheckBox")
1063 prefix
= "ID_CHECKBOX";
1064 MakeUniqueName("checkbox", buf
);
1066 newItem
= new wxCheckBox(panel
, -1, "Checkbox", wxPoint(x
, y
), wxSize(-1, -1), 0, wxDefaultValidator
, buf
);
1068 else if (itemType
== "wxListBox")
1070 prefix
= "ID_LISTBOX";
1071 MakeUniqueName("listbox", buf
);
1073 newItem
= new wxListBox(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1075 else if (itemType
== "wxRadioBox")
1077 prefix
= "ID_RADIOBOX";
1078 MakeUniqueName("radiobox", buf
);
1080 wxString names
[] = { "One", "Two" };
1081 newItem
= new wxRadioBox(panel
, -1, "Radiobox", wxPoint(x
, y
), wxSize(-1, -1), 2, names
, 2,
1082 wxHORIZONTAL
, wxDefaultValidator
, buf
);
1083 res
->SetStringValues(wxStringList("One", "Two", NULL
));
1085 else if (itemType
== "wxRadioButton")
1087 prefix
= "ID_RADIOBUTTON";
1088 MakeUniqueName("radiobutton", buf
);
1090 wxString names
[] = { "One", "Two" };
1091 newItem
= new wxRadioButton(panel
, -1, "Radiobutton", wxPoint(x
, y
), wxSize(-1, -1),
1092 0, wxDefaultValidator
, buf
);
1094 else if (itemType
== "wxChoice")
1096 prefix
= "ID_CHOICE";
1097 MakeUniqueName("choice", buf
);
1099 newItem
= new wxChoice(panel
, -1, wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, 0, wxDefaultValidator
, buf
);
1101 else if (itemType
== "wxComboBox")
1103 prefix
= "ID_COMBOBOX";
1104 MakeUniqueName("combobox", buf
);
1106 newItem
= new wxComboBox(panel
, -1, "", wxPoint(x
, y
), wxSize(-1, -1), 0, NULL
, wxCB_DROPDOWN
, wxDefaultValidator
, buf
);
1108 else if (itemType
== "wxGroupBox" || itemType
== "wxStaticBox")
1110 prefix
= "ID_STATICBOX";
1111 MakeUniqueName("staticbox", buf
);
1113 newItem
= new wxStaticBox(panel
, -1, "Static", wxPoint(x
, y
), wxSize(200, 200), 0, buf
);
1115 else if (itemType
== "wxGauge")
1117 prefix
= "ID_GAUGE";
1118 MakeUniqueName("gauge", buf
);
1120 newItem
= new wxGauge(panel
, -1, 10, wxPoint(x
, y
), wxSize(80, 30), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1122 else if (itemType
== "wxSlider")
1124 prefix
= "ID_SLIDER";
1125 MakeUniqueName("slider", buf
);
1127 newItem
= new wxSlider(panel
, -1, 1, 1, 10, wxPoint(x
, y
), wxSize(120, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1129 else if (itemType
== "wxText" || itemType
== "wxTextCtrl (single-line)")
1131 prefix
= "ID_TEXTCTRL";
1132 MakeUniqueName("textctrl", buf
);
1134 res
->SetType("wxTextCtrl");
1135 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, -1), 0, wxDefaultValidator
, buf
);
1137 else if (itemType
== "wxMultiText" || itemType
== "wxTextCtrl (multi-line)")
1139 prefix
= "ID_TEXTCTRL";
1140 MakeUniqueName("textctrl", buf
);
1142 res
->SetType("wxTextCtrl");
1143 newItem
= new wxTextCtrl(panel
, -1, "", wxPoint(x
, y
), wxSize(120, 100), wxTE_MULTILINE
, wxDefaultValidator
, buf
);
1145 else if (itemType
== "wxScrollBar")
1147 prefix
= "ID_SCROLLBAR";
1148 MakeUniqueName("scrollbar", buf
);
1150 newItem
= new wxScrollBar(panel
, -1, wxPoint(x
, y
), wxSize(140, -1), wxHORIZONTAL
, wxDefaultValidator
, buf
);
1155 int actualW
, actualH
;
1156 newItem
->GetSize(&actualW
, &actualH
);
1157 wxSize
actualSize(actualW
, actualH
);
1159 if ((panelResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
1161 actualSize
= panel
->ConvertPixelsToDialog(actualSize
);
1163 res
->SetSize(res
->GetX(), res
->GetY(), actualSize
.x
, actualSize
.y
);
1166 int id
= GenerateWindowId(prefix
, newIdName
);
1169 // This is now guaranteed to be unique, so just add to symbol table
1170 m_symbolTable
.AddSymbol(newIdName
, id
);
1172 newItem
->PushEventHandler(new wxResourceEditorControlHandler(newItem
, newItem
));
1174 res
->SetStyle(newItem
->GetWindowStyleFlag());
1175 AssociateResource(res
, newItem
);
1176 panelResource
->GetChildren().Append(res
);
1178 UpdateResourceList();
1183 void wxResourceManager::ClearCurrentDialog()
1185 if (m_editorPanel
->m_childWindow
)
1187 SaveInfoAndDeleteHandler(m_editorPanel
->m_childWindow
);
1188 DisassociateResource(m_editorPanel
->m_childWindow
);
1189 DeleteWindow(m_editorPanel
->m_childWindow
);
1190 m_editorPanel
->m_childWindow
= NULL
;
1191 m_editorPanel
->Clear();
1195 bool wxResourceManager::TestCurrentDialog(wxWindow
* parent
)
1197 if (m_editorPanel
->m_childWindow
)
1199 wxItemResource
* item
= FindResourceForWindow(m_editorPanel
->m_childWindow
);
1203 // Make sure the resources are up-to-date w.r.t. the window
1204 InstantiateResourceFromWindow(item
, m_editorPanel
->m_childWindow
, TRUE
);
1206 wxDialog
* dialog
= new wxDialog
;
1207 bool success
= FALSE
;
1208 if (dialog
->LoadFromResource(parent
, item
->GetName(), & m_resourceTable
))
1211 dialog
->ShowModal();
1219 // Find the first dialog or panel for which
1220 // there is a selected panel item.
1221 wxWindow
*wxResourceManager::FindParentOfSelection()
1223 m_resourceTable
.BeginFind();
1225 while ((node
= m_resourceTable
.Next()))
1227 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1228 wxWindow
*win
= FindWindowForResource(res
);
1231 wxNode
*node1
= win
->GetChildren().First();
1234 wxControl
*item
= (wxControl
*)node1
->Data();
1235 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1236 if (item
->IsKindOf(CLASSINFO(wxControl
)) && childHandler
->IsSelected())
1238 node1
= node1
->Next();
1245 // Format the panel items according to 'flag'
1246 void wxResourceManager::AlignItems(int flag
)
1248 wxWindow
*win
= FindParentOfSelection();
1252 wxNode
*node
= GetSelections().First();
1256 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1257 if (firstSelection
->GetParent() != win
)
1262 firstSelection
->GetPosition(&firstX
, &firstY
);
1263 firstSelection
->GetSize(&firstW
, &firstH
);
1264 int centreX
= (int)(firstX
+ (firstW
/ 2));
1265 int centreY
= (int)(firstY
+ (firstH
/ 2));
1267 while ((node
= node
->Next()))
1269 wxControl
*item
= (wxControl
*)node
->Data();
1270 if (item
->GetParent() == win
)
1273 item
->GetPosition(&x
, &y
);
1274 item
->GetSize(&w
, &h
);
1280 case TOOLBAR_FORMAT_HORIZ
:
1283 newY
= (int)(centreY
- (h
/2.0));
1286 case TOOLBAR_FORMAT_VERT
:
1288 newX
= (int)(centreX
- (w
/2.0));
1292 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
1298 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
1304 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
1306 newX
= firstX
+ firstW
- w
;
1310 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
1313 newY
= firstY
+ firstH
- h
;
1321 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1322 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1324 item
->SetSize(newX
, newY
, w
, h
);
1326 // Also update the associated resource
1327 // We need to convert to dialog units if this is not a dialog or panel, but
1328 // the parent resource specifies dialog units.
1329 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1331 wxPoint pt
= item
->GetParent()->ConvertPixelsToDialog(wxPoint(newX
, newY
));
1332 newX
= pt
.x
; newY
= pt
.y
;
1333 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
1336 resource
->SetSize(newX
, newY
, w
, h
);
1342 // Copy the first image's size to subsequent images
1343 void wxResourceManager::CopySize()
1345 wxWindow
*win
= FindParentOfSelection();
1349 wxNode
*node
= GetSelections().First();
1353 wxControl
*firstSelection
= (wxControl
*)node
->Data();
1354 if (firstSelection
->GetParent() != win
)
1359 firstSelection
->GetPosition(&firstX
, &firstY
);
1360 firstSelection
->GetSize(&firstW
, &firstH
);
1362 while ((node
= node
->Next()))
1364 wxControl
*item
= (wxControl
*)node
->Data();
1365 if (item
->GetParent() == win
)
1367 item
->SetSize(-1, -1, firstW
, firstH
);
1369 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
);
1370 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item
->GetParent());
1372 // Also update the associated resource
1373 // We need to convert to dialog units if this is not a dialog or panel, but
1374 // the parent resource specifies dialog units.
1375 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
1377 wxSize sz
= item
->GetParent()->ConvertPixelsToDialog(wxSize(firstW
, firstH
));
1378 firstW
= sz
.x
; firstH
= sz
.y
;
1380 resource
->SetSize(resource
->GetX(), resource
->GetY(), firstW
, firstH
);
1387 void wxResourceManager::ToBackOrFront(bool toBack
)
1389 wxWindow
*win
= FindParentOfSelection();
1392 wxItemResource
*winResource
= FindResourceForWindow(win
);
1394 wxNode
*node
= GetSelections().First();
1397 wxControl
*item
= (wxControl
*)node
->Data();
1398 wxItemResource
*itemResource
= FindResourceForWindow(item
);
1399 if (item
->GetParent() == win
)
1401 win
->GetChildren().DeleteObject(item
);
1403 winResource
->GetChildren().DeleteObject(itemResource
);
1406 win
->GetChildren().Insert(item
);
1408 winResource
->GetChildren().Insert(itemResource
);
1412 win
->GetChildren().Append(item
);
1414 winResource
->GetChildren().Append(itemResource
);
1417 node
= node
->Next();
1422 void wxResourceManager::AddSelection(wxWindow
*win
)
1424 if (!m_selections
.Member(win
))
1425 m_selections
.Append(win
);
1428 void wxResourceManager::RemoveSelection(wxWindow
*win
)
1430 m_selections
.DeleteObject(win
);
1433 // Need to search through resource table removing this from
1434 // any resource which has this as a parent.
1435 bool wxResourceManager::RemoveResourceFromParent(wxItemResource
*res
)
1437 m_resourceTable
.BeginFind();
1439 while ((node
= m_resourceTable
.Next()))
1441 wxItemResource
*thisRes
= (wxItemResource
*)node
->Data();
1442 if (thisRes
->GetChildren().Member(res
))
1444 thisRes
->GetChildren().DeleteObject(res
);
1451 bool wxResourceManager::DeleteResource(wxItemResource
*res
)
1456 RemoveResourceFromParent(res
);
1458 wxNode
*node
= res
->GetChildren().First();
1461 wxNode
*next
= node
->Next();
1462 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1463 DeleteResource(child
);
1467 // If this is a button or message resource, delete the
1468 // associate bitmap resource if not being used.
1469 wxString
resType(res
->GetType());
1471 /* shouldn't have to do this now bitmaps are ref-counted
1472 if ((resType == "wxMessage" || resType == "wxStaticBitmap" || resType == "wxButton" || resType == "wxBitmapButton") && res->GetValue4())
1474 PossiblyDeleteBitmapResource(res->GetValue4());
1478 // Remove symbol from table if appropriate
1479 if (!IsSymbolUsed(res
, res
->GetId()))
1481 m_symbolTable
.RemoveSymbol(res
->GetId());
1484 m_resourceTable
.Delete(res
->GetName());
1490 bool wxResourceManager::DeleteResource(wxWindow
*win
)
1492 if (win
->IsKindOf(CLASSINFO(wxControl
)))
1494 // Deselect and refresh window in case we leave selection
1496 wxControl
*item
= (wxControl
*)win
;
1497 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1498 if (childHandler
->IsSelected())
1500 RemoveSelection(item
);
1501 childHandler
->SelectItem(FALSE
);
1503 item
->GetParent()->Refresh();
1508 wxItemResource
*res
= FindResourceForWindow(win
);
1510 DisassociateResource(res
);
1511 DeleteResource(res
);
1512 UpdateResourceList();
1517 // Will eventually have bitmap type information, for different
1519 wxString
wxResourceManager::AddBitmapResource(const wxString
& filename
)
1521 wxItemResource
*resource
= FindBitmapResourceByFilename(filename
);
1525 MakeUniqueName("bitmap", buf
);
1526 resource
= new wxItemResource
;
1527 resource
->SetType("wxBitmap");
1528 resource
->SetName(buf
);
1530 // A bitmap resource has one or more children, specifying
1531 // alternative bitmaps.
1532 wxItemResource
*child
= new wxItemResource
;
1533 child
->SetType("wxBitmap");
1534 child
->SetName(filename
);
1535 child
->SetValue1(wxBITMAP_TYPE_BMP
);
1536 child
->SetValue2(RESOURCE_PLATFORM_ANY
);
1537 child
->SetValue3(0); // Depth
1538 child
->SetSize(0,0,0,0);
1539 resource
->GetChildren().Append(child
);
1541 m_resourceTable
.AddResource(resource
);
1543 UpdateResourceList();
1546 return resource
->GetName();
1548 return wxEmptyString
;
1551 // Delete the bitmap resource if it isn't being used by another resource.
1552 void wxResourceManager::PossiblyDeleteBitmapResource(const wxString
& resourceName
)
1554 if (!IsBitmapResourceUsed(resourceName
))
1556 wxItemResource
*res
= m_resourceTable
.FindResource(resourceName
);
1557 DeleteResource(res
);
1558 UpdateResourceList();
1562 bool wxResourceManager::IsBitmapResourceUsed(const wxString
& resourceName
)
1564 m_resourceTable
.BeginFind();
1566 while ((node
= m_resourceTable
.Next()))
1568 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1569 wxString
resType(res
->GetType());
1570 if (resType
== "wxDialog")
1572 wxNode
*node1
= res
->GetChildren().First();
1575 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1576 wxString
childResType(child
->GetType());
1578 if ((childResType
== "wxMessage" || childResType
== "wxButton") &&
1579 child
->GetValue4() &&
1580 (strcmp(child
->GetValue4(), resourceName
) == 0))
1582 node1
= node1
->Next();
1589 // Given a wxButton or wxMessage, find the corresponding bitmap filename.
1590 wxString
wxResourceManager::FindBitmapFilenameForResource(wxItemResource
*resource
)
1592 if (!resource
|| (resource
->GetValue4() == ""))
1593 return wxEmptyString
;
1594 wxItemResource
*bitmapResource
= m_resourceTable
.FindResource(resource
->GetValue4());
1595 if (!bitmapResource
)
1596 return wxEmptyString
;
1598 wxNode
*node
= bitmapResource
->GetChildren().First();
1601 // Eventually augment this to return a bitmap of the right kind or something...
1602 // Maybe the root of the filename remains the same, so it doesn't matter which we
1603 // pick up. Otherwise how do we specify multiple filenames... too boring...
1604 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1605 return child
->GetName();
1607 node
= node
->Next();
1609 return wxEmptyString
;
1612 wxItemResource
*wxResourceManager::FindBitmapResourceByFilename(const wxString
& filename
)
1614 m_resourceTable
.BeginFind();
1616 while ((node
= m_resourceTable
.Next()))
1618 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1619 wxString
resType(res
->GetType());
1620 if (resType
== "wxBitmap")
1622 wxNode
*node1
= res
->GetChildren().First();
1625 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1626 if (child
->GetName() && (strcmp(child
->GetName(), filename
) == 0))
1628 node1
= node1
->Next();
1635 // Is this window identifier symbol in use?
1636 // Let's assume that we can't have 2 names for the same integer id.
1637 // Therefore we can tell by the integer id whether the symbol is
1639 bool wxResourceManager::IsSymbolUsed(wxItemResource
* thisResource
, wxWindowID id
)
1641 m_resourceTable
.BeginFind();
1643 while ((node
= m_resourceTable
.Next()))
1645 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1647 wxString
resType(res
->GetType());
1648 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1650 if ((res
!= thisResource
) && (res
->GetId() == id
))
1653 wxNode
*node1
= res
->GetChildren().First();
1656 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1657 if ((child
!= thisResource
) && (child
->GetId() == id
))
1659 node1
= node1
->Next();
1666 // Is this window identifier compatible with the given name? (i.e.
1667 // does it already exist under a different name)
1668 bool wxResourceManager::IsIdentifierOK(const wxString
& name
, wxWindowID id
)
1670 if (m_symbolTable
.SymbolExists(name
))
1672 int foundId
= m_symbolTable
.GetIdForSymbol(name
);
1679 // Change all integer ids that match oldId, to newId.
1680 // This is necessary if an id is changed for one resource - all resources
1682 void wxResourceManager::ChangeIds(int oldId
, int newId
)
1684 m_resourceTable
.BeginFind();
1686 while ((node
= m_resourceTable
.Next()))
1688 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1690 wxString
resType(res
->GetType());
1691 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1693 if (res
->GetId() == oldId
)
1696 wxNode
*node1
= res
->GetChildren().First();
1699 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1700 if (child
->GetId() == oldId
)
1701 child
->SetId(newId
);
1703 node1
= node1
->Next();
1709 // If any resource ids were missing (or their symbol was missing),
1710 // repair them i.e. give them new ids. Returns TRUE if any resource
1711 // needed repairing.
1712 bool wxResourceManager::RepairResourceIds()
1714 bool repaired
= FALSE
;
1716 m_resourceTable
.BeginFind();
1718 while ((node
= m_resourceTable
.Next()))
1720 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1721 wxString
resType(res
->GetType());
1722 if (resType
== "wxDialog" || resType
== "wxDialogBox" || resType
== "wxPanel")
1725 if ( (res
->GetId() == 0) || ((res
->GetId() > 0) && !m_symbolTable
.IdExists(res
->GetId())) )
1727 wxString newSymbolName
;
1728 int newId
= GenerateWindowId("ID_DIALOG", newSymbolName
) ;
1730 if (res
->GetId() == 0)
1733 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1737 m_symbolTable
.AddSymbol(newSymbolName
, res
->GetId());
1743 wxNode
*node1
= res
->GetChildren().First();
1746 wxItemResource
*child
= (wxItemResource
*)node1
->Data();
1748 if ( (child
->GetId() == 0) || ((child
->GetId() > 0) && !m_symbolTable
.IdExists(child
->GetId())) )
1750 wxString newSymbolName
;
1751 int newId
= GenerateWindowId("ID_CONTROL", newSymbolName
) ;
1753 if (child
->GetId() == 0)
1755 child
->SetId(newId
);
1756 m_symbolTable
.AddSymbol(newSymbolName
, newId
);
1760 m_symbolTable
.AddSymbol(newSymbolName
, child
->GetId());
1766 node1
= node1
->Next();
1774 // Deletes 'win' and creates a new window from the resource that
1775 // was associated with it. E.g. if you can't change properties on the
1776 // fly, you'll need to delete the window and create it again.
1777 wxWindow
*wxResourceManager::RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
)
1779 wxItemResource
*resource
= FindResourceForWindow(win
);
1781 // Put the current window properties into the wxItemResource object
1783 wxWindowPropertyInfo
*newInfo
= NULL
;
1786 newInfo
= CreatePropertyInfoForWindow(win
);
1790 info
->InstantiateResource(resource
);
1792 wxWindow
*newWin
= NULL
;
1793 wxWindow
*parent
= win
->GetParent();
1794 wxItemResource
* parentResource
= NULL
;
1796 parentResource
= FindResourceForWindow(parent
);
1798 if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1801 newWin
= FindWindowForResource(resource
);
1805 DisassociateResource(resource
);
1806 if (win
->GetEventHandler() != win
)
1807 win
->PopEventHandler(TRUE
);
1810 newWin
= m_resourceTable
.CreateItem((wxPanel
*)parent
, resource
, parentResource
);
1811 newWin
->PushEventHandler(new wxResourceEditorControlHandler((wxControl
*) newWin
, (wxControl
*) newWin
));
1812 AssociateResource(resource
, newWin
);
1813 UpdateResourceList();
1817 info
->SetPropertyWindow(newWin
);
1825 // Delete resource highlighted in the listbox
1826 bool wxResourceManager::DeleteSelection()
1828 int sel
= m_editorResourceTree
->GetSelection();
1831 wxResourceTreeData
*data
= (wxResourceTreeData
*)m_editorResourceTree
->GetItemData(sel
);
1832 wxItemResource
*res
= data
->GetResource();
1833 wxWindow
*win
= FindWindowForResource(res
);
1836 DeleteResource(win
);
1838 UpdateResourceList();
1847 // Delete resource highlighted in the listbox
1848 bool wxResourceManager::RecreateSelection()
1850 wxNode
*node
= GetSelections().First();
1853 wxControl
*item
= (wxControl
*)node
->Data();
1854 wxResourceEditorControlHandler
*childHandler
= (wxResourceEditorControlHandler
*)item
->GetEventHandler();
1855 wxNode
*next
= node
->Next();
1856 childHandler
->SelectItem(FALSE
);
1858 RemoveSelection(item
);
1860 RecreateWindowFromResource(item
);
1867 bool wxResourceManager::EditDialog(wxDialog
*WXUNUSED(dialog
), wxWindow
*WXUNUSED(parent
))
1872 // Ensures that all currently shown windows are saved to resources,
1873 // e.g. just before writing to a .wxr file.
1874 bool wxResourceManager::InstantiateAllResourcesFromWindows()
1876 m_resourceTable
.BeginFind();
1878 while ((node
= m_resourceTable
.Next()))
1880 wxItemResource
*res
= (wxItemResource
*)node
->Data();
1881 wxString
resType(res
->GetType());
1883 if (resType
== "wxDialog")
1885 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1887 InstantiateResourceFromWindow(res
, win
, TRUE
);
1889 else if (resType
== "wxPanel")
1891 wxWindow
*win
= (wxWindow
*)FindWindowForResource(res
);
1893 InstantiateResourceFromWindow(res
, win
, TRUE
);
1899 bool wxResourceManager::InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
)
1901 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(window
);
1902 info
->SetResource(resource
);
1903 info
->InstantiateResource(resource
);
1908 wxNode
*node
= resource
->GetChildren().First();
1911 wxItemResource
*child
= (wxItemResource
*)node
->Data();
1912 wxWindow
*childWindow
= FindWindowForResource(child
);
1917 sprintf(buf
, "Could not find window %s", (const char*) child
->GetName());
1918 wxMessageBox(buf
, "Dialog Editor problem", wxOK
);
1921 InstantiateResourceFromWindow(child
, childWindow
, recurse
);
1922 node
= node
->Next();
1929 // Create a window information object for the give window
1930 wxWindowPropertyInfo
*wxResourceManager::CreatePropertyInfoForWindow(wxWindow
*win
)
1932 wxWindowPropertyInfo
*info
= NULL
;
1933 if (win
->IsKindOf(CLASSINFO(wxScrollBar
)))
1935 info
= new wxScrollBarPropertyInfo(win
);
1937 else if (win
->IsKindOf(CLASSINFO(wxStaticBox
)))
1939 info
= new wxGroupBoxPropertyInfo(win
);
1941 else if (win
->IsKindOf(CLASSINFO(wxCheckBox
)))
1943 info
= new wxCheckBoxPropertyInfo(win
);
1945 else if (win
->IsKindOf(CLASSINFO(wxSlider
)))
1947 info
= new wxSliderPropertyInfo(win
);
1949 else if (win
->IsKindOf(CLASSINFO(wxGauge
)))
1951 info
= new wxGaugePropertyInfo(win
);
1953 else if (win
->IsKindOf(CLASSINFO(wxListBox
)))
1955 info
= new wxListBoxPropertyInfo(win
);
1957 else if (win
->IsKindOf(CLASSINFO(wxRadioBox
)))
1959 info
= new wxRadioBoxPropertyInfo(win
);
1961 else if (win
->IsKindOf(CLASSINFO(wxRadioButton
)))
1963 info
= new wxRadioButtonPropertyInfo(win
);
1965 else if (win
->IsKindOf(CLASSINFO(wxComboBox
)))
1967 info
= new wxComboBoxPropertyInfo(win
);
1969 else if (win
->IsKindOf(CLASSINFO(wxChoice
)))
1971 info
= new wxChoicePropertyInfo(win
);
1973 else if (win
->IsKindOf(CLASSINFO(wxBitmapButton
)))
1975 info
= new wxBitmapButtonPropertyInfo(win
);
1977 else if (win
->IsKindOf(CLASSINFO(wxButton
)))
1979 info
= new wxButtonPropertyInfo(win
);
1981 else if (win
->IsKindOf(CLASSINFO(wxStaticBitmap
)))
1983 info
= new wxStaticBitmapPropertyInfo(win
);
1985 else if (win
->IsKindOf(CLASSINFO(wxStaticText
)))
1987 info
= new wxStaticTextPropertyInfo(win
);
1989 else if (win
->IsKindOf(CLASSINFO(wxTextCtrl
)))
1991 info
= new wxTextPropertyInfo(win
);
1993 else if (win
->IsKindOf(CLASSINFO(wxPanel
)))
1995 info
= new wxPanelPropertyInfo(win
);
1999 info
= new wxWindowPropertyInfo(win
);
2004 // Edit the given window
2005 void wxResourceManager::EditWindow(wxWindow
*win
)
2007 wxWindowPropertyInfo
*info
= CreatePropertyInfoForWindow(win
);
2010 info
->SetResource(FindResourceForWindow(win
));
2011 wxString
str("Editing ");
2012 str
+= win
->GetClassInfo()->GetClassName();
2014 if (win
->GetName() != "")
2015 str
+= win
->GetName();
2017 str
+= "properties";
2018 info
->Edit(NULL
, str
);
2022 // Generate a window id and a first stab at a name
2023 int wxResourceManager::GenerateWindowId(const wxString
& prefix
, wxString
& idName
)
2025 m_symbolIdCounter
++;
2026 while (m_symbolTable
.IdExists(m_symbolIdCounter
))
2027 m_symbolIdCounter
++;
2029 int nameId
= m_symbolIdCounter
;
2032 str
.Printf("%d", nameId
);
2033 idName
= prefix
+ str
;
2035 while (m_symbolTable
.SymbolExists(idName
))
2038 str
.Printf("%d", nameId
);
2039 idName
= prefix
+ str
;
2042 return m_symbolIdCounter
;
2047 * Resource editor frame
2050 IMPLEMENT_CLASS(wxResourceEditorFrame
, wxFrame
)
2052 BEGIN_EVENT_TABLE(wxResourceEditorFrame
, wxFrame
)
2053 EVT_MENU(wxID_NEW
, wxResourceEditorFrame::OnNew
)
2054 EVT_MENU(RESED_NEW_DIALOG
, wxResourceEditorFrame::OnNewDialog
)
2055 EVT_MENU(wxID_OPEN
, wxResourceEditorFrame::OnOpen
)
2056 EVT_MENU(RESED_CLEAR
, wxResourceEditorFrame::OnClear
)
2057 EVT_MENU(wxID_SAVE
, wxResourceEditorFrame::OnSave
)
2058 EVT_MENU(wxID_SAVEAS
, wxResourceEditorFrame::OnSaveAs
)
2059 EVT_MENU(wxID_EXIT
, wxResourceEditorFrame::OnExit
)
2060 EVT_MENU(wxID_ABOUT
, wxResourceEditorFrame::OnAbout
)
2061 EVT_MENU(RESED_CONTENTS
, wxResourceEditorFrame::OnContents
)
2062 EVT_MENU(RESED_DELETE
, wxResourceEditorFrame::OnDeleteSelection
)
2063 EVT_MENU(RESED_RECREATE
, wxResourceEditorFrame::OnRecreateSelection
)
2064 EVT_MENU(RESED_TEST
, wxResourceEditorFrame::OnTest
)
2067 wxResourceEditorFrame::wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, const wxString
& title
,
2068 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
):
2069 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
2074 wxResourceEditorFrame::~wxResourceEditorFrame()
2078 void wxResourceEditorFrame::OnNew(wxCommandEvent
& WXUNUSED(event
))
2080 manager
->New(FALSE
);
2083 void wxResourceEditorFrame::OnNewDialog(wxCommandEvent
& WXUNUSED(event
))
2085 manager
->CreateNewPanel();
2088 void wxResourceEditorFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
2093 void wxResourceEditorFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
2095 manager
->Clear(TRUE
, FALSE
);
2098 void wxResourceEditorFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
2103 void wxResourceEditorFrame::OnSaveAs(wxCommandEvent
& WXUNUSED(event
))
2108 void wxResourceEditorFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
2110 manager
->Clear(TRUE
, FALSE
) ;
2114 void wxResourceEditorFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
2117 sprintf(buf
, "wxWindows Dialog Editor %.1f\nAuthor: Julian Smart J.Smart@ed.ac.uk\nJulian Smart (c) 1996", wxDIALOG_EDITOR_VERSION
);
2118 wxMessageBox(buf
, "About Dialog Editor", wxOK
|wxCENTRE
);
2121 void wxResourceEditorFrame::OnTest(wxCommandEvent
& WXUNUSED(event
))
2123 manager
->TestCurrentDialog(this);
2126 void wxResourceEditorFrame::OnContents(wxCommandEvent
& WXUNUSED(event
))
2129 wxBeginBusyCursor();
2130 manager
->GetHelpController()->LoadFile();
2131 manager
->GetHelpController()->DisplayContents();
2136 void wxResourceEditorFrame::OnDeleteSelection(wxCommandEvent
& WXUNUSED(event
))
2138 manager
->DeleteSelection();
2141 void wxResourceEditorFrame::OnRecreateSelection(wxCommandEvent
& WXUNUSED(event
))
2143 manager
->RecreateSelection();
2146 bool wxResourceEditorFrame::OnClose()
2148 if (manager
->Modified())
2150 if (!manager
->Clear(TRUE
, FALSE
))
2158 manager
->m_resourceEditorWindowSize
.width
= w
;
2159 manager
->m_resourceEditorWindowSize
.height
= h
;
2162 GetPosition(&x
, &y
);
2164 manager
->m_resourceEditorWindowSize
.x
= x
;
2165 manager
->m_resourceEditorWindowSize
.y
= y
;
2167 manager
->SetEditorFrame(NULL
);
2168 manager
->SetEditorToolBar(NULL
);
2174 * Resource editor window that contains the dialog/panel being edited
2177 BEGIN_EVENT_TABLE(wxResourceEditorScrolledWindow
, wxScrolledWindow
)
2178 EVT_SCROLL(wxResourceEditorScrolledWindow::OnScroll
)
2179 EVT_PAINT(wxResourceEditorScrolledWindow::OnPaint
)
2182 wxResourceEditorScrolledWindow::wxResourceEditorScrolledWindow(wxWindow
*parent
, const wxPoint
& pos
, const wxSize
& size
,
2184 wxScrolledWindow(parent
, -1, pos
, size
, style
)
2188 m_childWindow
= NULL
;
2191 wxResourceEditorScrolledWindow::~wxResourceEditorScrolledWindow()
2195 void wxResourceEditorScrolledWindow::OnScroll(wxScrollEvent
& event
)
2197 wxScrolledWindow::OnScroll(event
);
2200 ViewStart(& x
, & y
);
2203 m_childWindow
->Move(m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10));
2206 void wxResourceEditorScrolledWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2213 void wxResourceEditorScrolledWindow::DrawTitle(wxDC
& dc
)
2217 wxItemResource
* res
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_childWindow
);
2220 wxString
str(res
->GetTitle());
2222 ViewStart(& x
, & y
);
2224 wxFont
font(10, wxSWISS
, wxNORMAL
, wxBOLD
);
2226 dc
.SetBackgroundMode(wxTRANSPARENT
);
2227 dc
.SetTextForeground(wxColour(0, 0, 0));
2230 dc
.GetTextExtent(str
, & w
, & h
);
2232 dc
.DrawText(str
, m_marginX
+ (- x
* 10), m_marginY
+ (- y
* 10) - h
- 5);
2237 // Popup menu callback
2238 void ObjectMenuProc(wxMenu
& menu
, wxCommandEvent
& event
)
2240 wxWindow
*data
= (wxWindow
*)menu
.GetClientData();
2244 switch (event
.GetInt())
2246 case OBJECT_MENU_EDIT
:
2248 wxResourceManager::GetCurrentResourceManager()->EditWindow(data
);
2251 case OBJECT_MENU_DELETE
:
2253 wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data
);
2254 wxResourceManager::GetCurrentResourceManager()->DeleteResource(data
);
2255 wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data
);
2268 #ifdef __WXGTK__ // I don't dare to delete it...
2270 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2275 BEGIN_EVENT_TABLE(EditorToolBar
, wxToolBar
)
2276 EVT_PAINT(EditorToolBar::OnPaint
)
2281 EditorToolBar::EditorToolBar(wxFrame
*frame
, const wxPoint
& pos
, const wxSize
& size
,
2283 wxToolBar(frame
, -1, pos
, size
, style
)
2287 bool EditorToolBar::OnLeftClick(int toolIndex
, bool WXUNUSED(toggled
))
2289 wxResourceManager
*manager
= wxResourceManager::GetCurrentResourceManager();
2293 case TOOLBAR_LOAD_FILE
:
2300 manager
->CreateNewPanel();
2303 case TOOLBAR_SAVE_FILE
:
2311 wxBeginBusyCursor();
2312 manager
->GetHelpController()->LoadFile();
2313 manager
->GetHelpController()->DisplayContents();
2318 case TOOLBAR_FORMAT_HORIZ
:
2320 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ
);
2323 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2325 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
);
2328 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2330 manager
->AlignItems(TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
);
2333 case TOOLBAR_FORMAT_VERT
:
2335 manager
->AlignItems(TOOLBAR_FORMAT_VERT
);
2338 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2340 manager
->AlignItems(TOOLBAR_FORMAT_VERT_TOP_ALIGN
);
2343 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2345 manager
->AlignItems(TOOLBAR_FORMAT_VERT_BOT_ALIGN
);
2348 case TOOLBAR_COPY_SIZE
:
2350 manager
->CopySize();
2353 case TOOLBAR_TO_BACK
:
2355 manager
->ToBackOrFront(TRUE
);
2358 case TOOLBAR_TO_FRONT
:
2360 manager
->ToBackOrFront(FALSE
);
2369 void EditorToolBar::OnMouseEnter(int toolIndex
)
2371 wxFrame
*frame
= (wxFrame
*)GetParent();
2379 case TOOLBAR_LOAD_FILE
:
2380 frame
->SetStatusText("Load project file");
2382 case TOOLBAR_SAVE_FILE
:
2383 frame
->SetStatusText("Save project file");
2386 frame
->SetStatusText("Create a new resource");
2388 case TOOLBAR_FORMAT_HORIZ
:
2389 frame
->SetStatusText("Align items horizontally");
2391 case TOOLBAR_FORMAT_VERT
:
2392 frame
->SetStatusText("Align items vertically");
2394 case TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN
:
2395 frame
->SetStatusText("Left-align items");
2397 case TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN
:
2398 frame
->SetStatusText("Right-align items");
2400 case TOOLBAR_FORMAT_VERT_TOP_ALIGN
:
2401 frame
->SetStatusText("Top-align items");
2403 case TOOLBAR_FORMAT_VERT_BOT_ALIGN
:
2404 frame
->SetStatusText("Bottom-align items");
2406 case TOOLBAR_COPY_SIZE
:
2407 frame
->SetStatusText("Copy size from first selection");
2409 case TOOLBAR_TO_FRONT
:
2410 frame
->SetStatusText("Put image to front");
2412 case TOOLBAR_TO_BACK
:
2413 frame
->SetStatusText("Put image to back");
2416 frame
->SetStatusText("Display help contents");
2422 else frame
->SetStatusText("");