1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource editor class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
15 #define wxDIALOG_EDITOR_VERSION 1.6
18 #pragma interface "reseditr.h"
22 #include "wx/string.h"
23 #include "wx/layout.h"
24 #include "wx/resource.h"
25 #include "wx/tbarsmpl.h"
29 #if defined(__WINDOWS__) && defined(__WIN95__)
30 #include "wx/tbar95.h"
31 #elif defined(__WINDOWS__)
32 #include "wx/tbarmsw.h"
35 #define RESED_DELETE 1
36 #define RESED_TOGGLE_TEST_MODE 2
37 #define RESED_RECREATE 3
39 #define RESED_NEW_DIALOG 5
40 #define RESED_NEW_PANEL 6
42 #define RESED_CONTENTS 20
45 * Controls loading, saving, user interface of resource editor(s).
48 class wxResourceEditorFrame
;
49 class EditorToolPalette
;
51 class wxWindowPropertyInfo
;
54 #define wxHelpController wxWinHelpController
56 #define wxHelpController wxXLPHelpController;
59 class wxHelpController
;
62 * The resourceTable contains a list of wxItemResources (which each may
63 * have further children, defining e.g. a dialog box with controls).
65 * We need to associate actual windows with each wxItemResource,
66 * instead of the current 'one current window' scheme.
68 * - We create a new dialog, create a wxItemResource,
69 * associate the dialog with wxItemResource via a hash table.
70 * Must be a hash table in case dialog is deleted without
71 * telling the resource manager.
72 * - When we save the resource after editing/closing the dialog,
73 * we check the wxItemResource/wxDialog and children for
74 * consistency (throw away items no longer in the wxDialog,
75 * create any new wxItemResources).
76 * - We save the wxItemResources via the wxPropertyInfo classes,
77 * so devolve the code to the appropriate class.
78 * This involves creating a new temporary wxPropertyInfo for
81 * We currently assume we only create one instance of a window for
82 * each wxItemResource. We will need to relax this when we're editing
88 class wxResourceTableWithSaving
: public wxResourceTable
91 wxResourceTableWithSaving(void):wxResourceTable()
94 virtual bool Save(const wxString
& filename
);
95 virtual bool SaveResource(ostream
& stream
, wxItemResource
*item
);
97 void GenerateWindowStyleString(long windowStyle
, char *buf
);
98 void GeneratePanelStyleString(long windowStyle
, char *buf
);
99 void GenerateDialogStyleString(long windowStyle
, char *buf
);
101 void GenerateRadioBoxStyleString(long windowStyle
, char *buf
);
102 void GenerateMessageStyleString(long windowStyle
, char *buf
);
103 void GenerateTextStyleString(long windowStyle
, char *buf
);
104 void GenerateButtonStyleString(long windowStyle
, char *buf
);
105 void GenerateCheckBoxStyleString(long windowStyle
, char *buf
);
106 void GenerateListBoxStyleString(long windowStyle
, char *buf
);
107 void GenerateSliderStyleString(long windowStyle
, char *buf
);
108 void GenerateGroupBoxStyleString(long windowStyle
, char *buf
);
109 void GenerateGaugeStyleString(long windowStyle
, char *buf
);
110 void GenerateChoiceStyleString(long windowStyle
, char *buf
);
111 void GenerateScrollBarStyleString(long windowStyle
, char *buf
);
112 void GenerateItemStyleString(long windowStyle
, char *buf
);
114 bool GenerateStyle(char *buf
, long windowStyle
, long flag
, char *strStyle
);
116 void OutputFont(ostream
& stream
, wxFont
*font
);
117 wxControl
*CreateItem(wxPanel
*panel
, wxItemResource
*childResource
);
120 class wxResourceManager
: public wxObject
123 wxHelpController
*helpInstance
;
124 wxResourceTableWithSaving resourceTable
;
125 wxFrame
*editorFrame
;
126 wxPanel
*editorPanel
;
128 wxListBox
*editorResourceList
;
129 EditorToolPalette
*editorPalette
;
130 EditorToolBar
*editorToolBar
;
134 wxHashTable resourceAssociations
;
136 wxString currentFilename
;
140 // Options to be saved/restored
141 wxString optionsResourceFilename
; // e.g. dialoged.ini, .dialogrc
142 wxRectangle propertyWindowSize
;
143 wxRectangle resourceEditorWindowSize
;
146 static wxResourceManager
*currentResourceManager
;
148 wxResourceManager(void);
149 ~wxResourceManager(void);
151 bool Initialize(void);
153 bool LoadOptions(void);
154 bool SaveOptions(void);
156 // Show or hide the resource editor frame, which displays a list
157 // of resources with ability to edit them.
158 virtual bool ShowResourceEditor(bool show
, wxWindow
*parent
= NULL
, const char *title
= "wxWindows Dialog Editor");
160 virtual bool Save(void);
161 virtual bool SaveAs(void);
162 virtual bool Save(const wxString
& filename
);
163 virtual bool Load(const wxString
& filename
);
164 virtual bool Clear(bool deleteWindows
= TRUE
, bool force
= TRUE
);
165 virtual void SetFrameTitle(const wxString
& filename
);
166 virtual bool DisassociateWindows(bool deleteWindows
= TRUE
);
167 virtual bool New(bool loadFromFile
= TRUE
, const wxString
& filename
= "");
168 virtual bool SaveIfModified(void);
169 virtual void AlignItems(int flag
);
170 virtual void CopySize(void);
171 virtual void ToBackOrFront(bool toBack
);
172 virtual wxWindow
*FindParentOfSelection(void);
174 virtual wxFrame
*OnCreateEditorFrame(const char *title
);
175 virtual wxMenuBar
*OnCreateEditorMenuBar(wxFrame
*parent
);
176 virtual wxPanel
*OnCreateEditorPanel(wxFrame
*parent
);
177 virtual wxToolBarBase
*OnCreateToolBar(wxFrame
*parent
);
178 virtual EditorToolPalette
*OnCreatePalette(wxFrame
*parent
);
179 // virtual bool DeletePalette(void);
180 virtual bool InitializeTools(void);
182 virtual void UpdateResourceList(void);
183 virtual void AddItemsRecursively(int level
, wxItemResource
*resource
);
184 virtual bool EditSelectedResource(void);
185 virtual bool Edit(wxItemResource
*res
);
186 virtual bool CreateNewDialog(void);
187 virtual bool CreateNewPanel(void);
188 virtual bool CreatePanelItem(wxItemResource
*panelResource
, wxPanel
*panel
, char *itemType
, int x
= 10, int y
= 10, bool isBitmap
= FALSE
);
190 virtual bool DeleteSelection(bool deleteWindow
= TRUE
);
192 virtual bool DeleteResource(wxItemResource
*res
);
193 virtual bool DeleteResource(wxWindow
*win
, bool deleteWindow
= TRUE
);
195 // Add bitmap resource if there isn't already one with this filename.
196 virtual char *AddBitmapResource(char *filename
);
198 // Delete the bitmap resource if it isn't being used by another resource.
199 virtual void PossiblyDeleteBitmapResource(char *resourceName
);
201 // Helper function for above
202 virtual bool IsBitmapResourceUsed(char *resourceName
);
204 wxItemResource
*FindBitmapResourceByFilename(char *filename
);
206 char *FindBitmapFilenameForResource(wxItemResource
*resource
);
208 // Deletes 'win' and creates a new window from the resource that
209 // was associated with it. E.g. if you can't change properties on the
210 // fly, you'll need to delete the window and create it again.
211 virtual wxWindow
*RecreateWindowFromResource(wxWindow
*win
, wxWindowPropertyInfo
*info
= NULL
);
213 virtual bool RecreateSelection(void);
215 // Need to search through resource table removing this from
216 // any resource which has this as a parent.
217 virtual bool RemoveResourceFromParent(wxItemResource
*res
);
219 virtual bool EditDialog(wxDialog
*dialog
, wxWindow
*parent
);
221 inline void SetEditorFrame(wxFrame
*fr
) { editorFrame
= fr
; }
222 inline void SetEditorToolBar(EditorToolBar
*tb
) { editorToolBar
= tb
; }
223 inline void SetEditorPalette(EditorToolPalette
*pal
) { editorPalette
= pal
; }
224 inline wxFrame
*GetEditorFrame(void) { return editorFrame
; }
225 inline wxListBox
*GetEditorResourceList(void) { return editorResourceList
; }
226 inline EditorToolPalette
*GetEditorPalette(void) { return editorPalette
; }
227 inline wxList
& GetSelections(void) { return selections
; }
229 void AddSelection(wxWindow
*win
);
230 void RemoveSelection(wxWindow
*win
);
232 // inline void SetCurrentResource(wxItemResource *item) { currentResource = item; }
233 // inline void SetCurrentResourceWindow(wxWindow *win) { currentResourceWindow = win; }
234 // inline wxItemResource *GetCurrentResource(void) { return currentResource; }
235 // inline wxWindow *GetCurrentResourceWindow(void) { return currentResourceWindow; }
236 inline wxMenu
*GetPopupMenu(void) { return popupMenu
; }
238 inline wxHelpController
*GetHelpInstance(void) { return helpInstance
; }
240 virtual void MakeUniqueName(char *prefix
, char *buf
);
242 // (Dis)associate resource<->physical window
243 virtual void AssociateResource(wxItemResource
*resource
, wxWindow
*win
);
244 virtual bool DisassociateResource(wxItemResource
*resource
, bool deleteWindow
= TRUE
);
245 virtual bool DisassociateResource(wxWindow
*win
, bool deleteWindow
= TRUE
);
246 virtual wxItemResource
*FindResourceForWindow(wxWindow
*win
);
247 virtual wxWindow
*FindWindowForResource(wxItemResource
*resource
);
249 virtual bool InstantiateAllResourcesFromWindows(void);
250 virtual bool InstantiateResourceFromWindow(wxItemResource
*resource
, wxWindow
*window
, bool recurse
= FALSE
);
252 virtual void Modify(bool mod
= TRUE
) { modified
= mod
; }
253 virtual bool Modified(void) { return modified
; }
255 inline bool GetEditMode(void) { return editMode
; }
256 void SetEditMode(bool flag
, bool changeCurrentResource
= TRUE
);
258 inline wxResourceTable
& GetResourceTable(void) { return resourceTable
; }
259 inline wxHashTable
& GetResourceAssociations(void) { return resourceAssociations
; }
261 inline wxString
& GetCurrentFilename(void) { return currentFilename
; }
263 // void UsePosition(bool usePos, wxItemResource *resource = NULL, int x = 0, int y = 0);
266 class wxResourceEditorFrame
: public wxFrame
269 wxResourceManager
*manager
;
270 wxResourceEditorFrame(wxResourceManager
*resMan
, wxFrame
*parent
, char *title
, int x
= -1, int y
= -1, int width
= 600, int height
= 400,
271 long style
= 0, char *name
= "frame");
272 ~wxResourceEditorFrame(void);
273 void OldOnMenuCommand(int cmd
);
277 class wxResourceEditorPanel
: public wxPanel
280 wxResourceEditorPanel(wxWindow
*parent
, int x
= -1, int y
= -1, int width
= 600, int height
= 400,
281 long style
= 0, char *name
= "panel");
282 ~wxResourceEditorPanel(void);
283 void OnDefaultAction(wxControl
*item
);
286 class DialogEditorPanelFrame
: public wxFrame
289 DialogEditorPanelFrame(wxFrame
*parent
, char *title
, int x
, int y
, int w
, int h
, long style
, char *name
):
290 wxFrame(parent
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
), style
, name
)
297 #define OBJECT_EDITOR_NEW_FRAME 220
298 #define OBJECT_EDITOR_NEW_DIALOG 221
299 #define OBJECT_EDITOR_NEW_PANEL 222
300 #define OBJECT_EDITOR_NEW_CANVAS 223
301 #define OBJECT_EDITOR_NEW_TEXT_WINDOW 224
302 #define OBJECT_EDITOR_NEW_BUTTON 225
303 #define OBJECT_EDITOR_NEW_CHECKBOX 226
304 #define OBJECT_EDITOR_NEW_MESSAGE 227
305 #define OBJECT_EDITOR_NEW_CHOICE 228
306 #define OBJECT_EDITOR_NEW_LISTBOX 229
307 #define OBJECT_EDITOR_NEW_RADIOBOX 230
308 #define OBJECT_EDITOR_NEW_SLIDER 231
309 #define OBJECT_EDITOR_NEW_TEXT 232
310 #define OBJECT_EDITOR_NEW_MULTITEXT 233
311 #define OBJECT_EDITOR_NEW_GAUGE 234
312 #define OBJECT_EDITOR_NEW_GROUPBOX 235
314 #define OBJECT_EDITOR_NEW_ITEM 240
315 #define OBJECT_EDITOR_NEW_SUBWINDOW 241
317 #define OBJECT_EDITOR_EDIT_MENU 250
318 #define OBJECT_EDITOR_EDIT_ATTRIBUTES 251
319 #define OBJECT_EDITOR_CLOSE_OBJECT 252
320 #define OBJECT_EDITOR_DELETE_OBJECT 253
321 #define OBJECT_EDITOR_EDIT_TOOLBAR 254
323 #define OBJECT_EDITOR_TOGGLE_TEST_MODE 255
325 #define OBJECT_EDITOR_RC_CONVERT 260
326 #define OBJECT_EDITOR_RC_CONVERT_MENU 261
327 #define OBJECT_EDITOR_RC_CONVERT_DIALOG 262
329 #define OBJECT_EDITOR_GRID 263
331 #define OBJECT_MENU_EDIT 1
332 #define OBJECT_MENU_DELETE 2
339 #if defined(__WINDOWS__) && defined(__WIN95__)
340 class EditorToolBar
: public wxToolBar95
341 #elif defined(__WINDOWS__)
342 class EditorToolBar
: public wxToolBarMSW
344 class EditorToolBar
: public wxToolBarSimple
348 EditorToolBar(wxFrame
*frame
, int x
= 0, int y
= 0, int w
= -1, int h
= -1,
349 long style
= 0, int direction
= wxVERTICAL
, int RowsOrColumns
= 2);
350 bool OnLeftClick(int toolIndex
, bool toggled
);
351 void OnMouseEnter(int toolIndex
);
352 void OnPaint(wxPaintEvent
& event
);
354 DECLARE_EVENT_TABLE()
358 #define TOOLBAR_LOAD_FILE 1
359 #define TOOLBAR_SAVE_FILE 2
360 #define TOOLBAR_NEW 3
361 // #define TOOLBAR_GEN_CLIPS 4
362 #define TOOLBAR_TREE 5
363 #define TOOLBAR_HELP 6
366 #define TOOLBAR_FORMAT_HORIZ 10
367 #define TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN 11
368 #define TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN 12
369 #define TOOLBAR_FORMAT_VERT 13
370 #define TOOLBAR_FORMAT_VERT_TOP_ALIGN 14
371 #define TOOLBAR_FORMAT_VERT_BOT_ALIGN 15
373 #define TOOLBAR_TO_FRONT 16
374 #define TOOLBAR_TO_BACK 17
375 #define TOOLBAR_COPY_SIZE 18