]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/reseditr.h
wxImageList ctor now takes the same arguments as the MSW version (but it's
[wxWidgets.git] / utils / dialoged / src / reseditr.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: reseditr.h
3 // Purpose: Resource editor class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _RESEDITR_H_
13 #define _RESEDITR_H_
14
15 #define wxDIALOG_EDITOR_VERSION 1.6
16
17 #ifdef __GNUG__
18 #pragma interface "reseditr.h"
19 #endif
20
21 #include "wx/wx.h"
22 #include "wx/string.h"
23 #include "wx/layout.h"
24 #include "wx/resource.h"
25 #include "wx/tbarsmpl.h"
26
27 #include "proplist.h"
28
29 #if defined(__WINDOWS__) && defined(__WIN95__)
30 #include "wx/tbar95.h"
31 #elif defined(__WINDOWS__)
32 #include "wx/tbarmsw.h"
33 #endif
34
35 #define RESED_DELETE 1
36 #define RESED_TOGGLE_TEST_MODE 2
37 #define RESED_RECREATE 3
38 #define RESED_CLEAR 4
39 #define RESED_NEW_DIALOG 5
40 #define RESED_NEW_PANEL 6
41
42 #define RESED_CONTENTS 20
43
44 /*
45 * Controls loading, saving, user interface of resource editor(s).
46 */
47
48 class wxResourceEditorFrame;
49 class EditorToolPalette;
50 class EditorToolBar;
51 class wxWindowPropertyInfo;
52
53 #ifdef __WINDOWS__
54 #define wxHelpController wxWinHelpController
55 #else
56 #define wxHelpController wxXLPHelpController;
57 #endif
58
59 class wxHelpController;
60
61 /*
62 * The resourceTable contains a list of wxItemResources (which each may
63 * have further children, defining e.g. a dialog box with controls).
64 *
65 * We need to associate actual windows with each wxItemResource,
66 * instead of the current 'one current window' scheme.
67 *
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
79 * the purpose.
80 *
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
83 * in situ.
84 *
85 *
86 */
87
88 class wxResourceTableWithSaving: public wxResourceTable
89 {
90 public:
91 wxResourceTableWithSaving(void):wxResourceTable()
92 {
93 }
94 virtual bool Save(const wxString& filename);
95 virtual bool SaveResource(ostream& stream, wxItemResource *item);
96
97 void GenerateWindowStyleString(long windowStyle, char *buf);
98 void GeneratePanelStyleString(long windowStyle, char *buf);
99 void GenerateDialogStyleString(long windowStyle, char *buf);
100
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);
113
114 bool GenerateStyle(char *buf, long windowStyle, long flag, char *strStyle);
115
116 void OutputFont(ostream& stream, wxFont *font);
117 wxControl *CreateItem(wxPanel *panel, wxItemResource *childResource);
118 };
119
120 class wxResourceManager: public wxObject
121 {
122 protected:
123 wxHelpController *helpInstance;
124 wxResourceTableWithSaving resourceTable;
125 wxFrame *editorFrame;
126 wxPanel *editorPanel;
127 wxMenu *popupMenu;
128 wxListBox *editorResourceList;
129 EditorToolPalette *editorPalette;
130 EditorToolBar *editorToolBar;
131 int nameCounter;
132 bool modified;
133 bool editMode;
134 wxHashTable resourceAssociations;
135 wxList selections;
136 wxString currentFilename;
137
138 public:
139
140 // Options to be saved/restored
141 wxString optionsResourceFilename; // e.g. dialoged.ini, .dialogrc
142 wxRectangle propertyWindowSize;
143 wxRectangle resourceEditorWindowSize;
144
145 public:
146 static wxResourceManager *currentResourceManager;
147
148 wxResourceManager(void);
149 ~wxResourceManager(void);
150
151 bool Initialize(void);
152
153 bool LoadOptions(void);
154 bool SaveOptions(void);
155
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");
159
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);
173
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);
181
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);
189
190 virtual bool DeleteSelection(bool deleteWindow = TRUE);
191
192 virtual bool DeleteResource(wxItemResource *res);
193 virtual bool DeleteResource(wxWindow *win, bool deleteWindow = TRUE);
194
195 // Add bitmap resource if there isn't already one with this filename.
196 virtual char *AddBitmapResource(char *filename);
197
198 // Delete the bitmap resource if it isn't being used by another resource.
199 virtual void PossiblyDeleteBitmapResource(char *resourceName);
200
201 // Helper function for above
202 virtual bool IsBitmapResourceUsed(char *resourceName);
203
204 wxItemResource *FindBitmapResourceByFilename(char *filename);
205
206 char *FindBitmapFilenameForResource(wxItemResource *resource);
207
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);
212
213 virtual bool RecreateSelection(void);
214
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);
218
219 virtual bool EditDialog(wxDialog *dialog, wxWindow *parent);
220
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; }
228
229 void AddSelection(wxWindow *win);
230 void RemoveSelection(wxWindow *win);
231
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; }
237
238 inline wxHelpController *GetHelpInstance(void) { return helpInstance; }
239
240 virtual void MakeUniqueName(char *prefix, char *buf);
241
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);
248
249 virtual bool InstantiateAllResourcesFromWindows(void);
250 virtual bool InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse = FALSE);
251
252 virtual void Modify(bool mod = TRUE) { modified = mod; }
253 virtual bool Modified(void) { return modified; }
254
255 inline bool GetEditMode(void) { return editMode; }
256 void SetEditMode(bool flag, bool changeCurrentResource = TRUE);
257
258 inline wxResourceTable& GetResourceTable(void) { return resourceTable; }
259 inline wxHashTable& GetResourceAssociations(void) { return resourceAssociations; }
260
261 inline wxString& GetCurrentFilename(void) { return currentFilename; }
262
263 // void UsePosition(bool usePos, wxItemResource *resource = NULL, int x = 0, int y = 0);
264 };
265
266 class wxResourceEditorFrame: public wxFrame
267 {
268 public:
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);
274 bool OnClose(void);
275 };
276
277 class wxResourceEditorPanel: public wxPanel
278 {
279 public:
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);
284 };
285
286 class DialogEditorPanelFrame: public wxFrame
287 {
288 public:
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)
291 {
292 }
293 bool OnClose(void);
294 };
295
296 // Edit menu
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
313
314 #define OBJECT_EDITOR_NEW_ITEM 240
315 #define OBJECT_EDITOR_NEW_SUBWINDOW 241
316
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
322
323 #define OBJECT_EDITOR_TOGGLE_TEST_MODE 255
324
325 #define OBJECT_EDITOR_RC_CONVERT 260
326 #define OBJECT_EDITOR_RC_CONVERT_MENU 261
327 #define OBJECT_EDITOR_RC_CONVERT_DIALOG 262
328
329 #define OBJECT_EDITOR_GRID 263
330
331 #define OBJECT_MENU_EDIT 1
332 #define OBJECT_MENU_DELETE 2
333
334 /*
335 * Main toolbar
336 *
337 */
338
339 #if defined(__WINDOWS__) && defined(__WIN95__)
340 class EditorToolBar: public wxToolBar95
341 #elif defined(__WINDOWS__)
342 class EditorToolBar: public wxToolBarMSW
343 #else
344 class EditorToolBar: public wxToolBarSimple
345 #endif
346 {
347 public:
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);
353
354 DECLARE_EVENT_TABLE()
355 };
356
357 // Toolbar ids
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
364
365 // Formatting tools
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
372
373 #define TOOLBAR_TO_FRONT 16
374 #define TOOLBAR_TO_BACK 17
375 #define TOOLBAR_COPY_SIZE 18
376
377 #endif
378