]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/reseditr.h
dde51c0ea62bde45af096aee9a229b5693a40bef
[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/toolbar.h"
26 #include "wx/imaglist.h"
27
28 #include "proplist.h"
29 #include "symbtabl.h"
30
31 #define RESED_DELETE 1
32 #define RESED_RECREATE 3
33 #define RESED_CLEAR 4
34 #define RESED_NEW_DIALOG 5
35 #define RESED_NEW_PANEL 6
36 #define RESED_TEST 10
37
38 #define RESED_CONTENTS 20
39
40 #define IDC_TREECTRL 100
41 #define IDC_LISTCTRL 101
42
43 // For control list ('palette')
44 #define RESED_POINTER 0
45 #define RESED_BUTTON 1
46 #define RESED_BMPBUTTON 2
47 #define RESED_STATICTEXT 3
48 #define RESED_STATICBMP 4
49 #define RESED_STATICBOX 5
50 #define RESED_TEXTCTRL_SINGLE 6
51 #define RESED_TEXTCTRL_MULTIPLE 7
52 #define RESED_LISTBOX 8
53 #define RESED_CHOICE 9
54 #define RESED_COMBOBOX 10
55 #define RESED_CHECKBOX 11
56 #define RESED_SLIDER 12
57 #define RESED_GAUGE 13
58 #define RESED_RADIOBOX 14
59 #define RESED_RADIOBUTTON 15
60 #define RESED_SCROLLBAR 16
61 #define RESED_TREECTRL 17
62 #define RESED_LISTCTRL 18
63 #define RESED_SPINBUTTON 19
64
65 /*
66 * Controls loading, saving, user interface of resource editor(s).
67 */
68
69 class wxResourceEditorFrame;
70 class EditorToolBar;
71 class wxWindowPropertyInfo;
72 class wxResourceEditorProjectTree;
73 class wxResourceEditorControlList;
74
75 #ifdef __WXMSW__
76 #define wxHelpController wxWinHelpController
77 #else
78 #define wxHelpController wxXLPHelpController;
79 #endif
80
81 class wxHelpController;
82
83 /*
84 * The resourceTable contains a list of wxItemResources (which each may
85 * have further children, defining e.g. a dialog box with controls).
86 *
87 * We need to associate actual windows with each wxItemResource,
88 * instead of the current 'one current window' scheme.
89 *
90 * - We create a new dialog, create a wxItemResource,
91 * associate the dialog with wxItemResource via a hash table.
92 * Must be a hash table in case dialog is deleted without
93 * telling the resource manager.
94 * - When we save the resource after editing/closing the dialog,
95 * we check the wxItemResource/wxDialog and children for
96 * consistency (throw away items no longer in the wxDialog,
97 * create any new wxItemResources).
98 * - We save the wxItemResources via the wxPropertyInfo classes,
99 * so devolve the code to the appropriate class.
100 * This involves creating a new temporary wxPropertyInfo for
101 * the purpose.
102 *
103 * We currently assume we only create one instance of a window for
104 * each wxItemResource. We will need to relax this when we're editing
105 * in situ.
106 *
107 *
108 */
109
110 class wxResourceTableWithSaving: public wxResourceTable
111 {
112 public:
113 wxResourceTableWithSaving():wxResourceTable()
114 {
115 }
116 virtual bool Save(const wxString& filename);
117 virtual bool SaveResource(ostream& stream, wxItemResource *item);
118
119 void GenerateWindowStyleString(long windowStyle, char *buf);
120 void GeneratePanelStyleString(long windowStyle, char *buf);
121 void GenerateDialogStyleString(long windowStyle, char *buf);
122
123 void GenerateRadioBoxStyleString(long windowStyle, char *buf);
124 void GenerateMessageStyleString(long windowStyle, char *buf);
125 void GenerateTextStyleString(long windowStyle, char *buf);
126 void GenerateButtonStyleString(long windowStyle, char *buf);
127 void GenerateCheckBoxStyleString(long windowStyle, char *buf);
128 void GenerateRadioButtonStyleString(long windowStyle, char *buf);
129 void GenerateListBoxStyleString(long windowStyle, char *buf);
130 void GenerateSliderStyleString(long windowStyle, char *buf);
131 void GenerateGroupBoxStyleString(long windowStyle, char *buf);
132 void GenerateGaugeStyleString(long windowStyle, char *buf);
133 void GenerateChoiceStyleString(long windowStyle, char *buf);
134 void GenerateScrollBarStyleString(long windowStyle, char *buf);
135 void GenerateItemStyleString(long windowStyle, char *buf);
136
137 bool GenerateStyle(char *buf, long windowStyle, long flag, char *strStyle);
138
139 void OutputFont(ostream& stream, wxFont *font);
140 wxControl *CreateItem(wxPanel *panel, wxItemResource *childResource);
141 };
142
143 class wxResourceEditorScrolledWindow;
144
145 class wxResourceManager: public wxObject
146 {
147 friend class wxResourceEditorFrame;
148
149 public:
150 wxResourceManager();
151 ~wxResourceManager();
152
153 // Operations
154
155 // Initializes the resource manager
156 bool Initialize();
157
158 // Load/save window size etc.
159 bool LoadOptions();
160 bool SaveOptions();
161
162 // Show or hide the resource editor frame, which displays a list
163 // of resources with ability to edit them.
164 virtual bool ShowResourceEditor(bool show, wxWindow *parent = NULL, const char *title = "wxWindows Dialog Editor");
165
166 virtual bool Save();
167 virtual bool SaveAs();
168 virtual bool Save(const wxString& filename);
169 virtual bool Load(const wxString& filename);
170 virtual bool Clear(bool deleteWindows = TRUE, bool force = TRUE);
171 virtual void SetFrameTitle(const wxString& filename);
172 virtual void ClearCurrentDialog();
173 virtual bool New(bool loadFromFile = TRUE, const wxString& filename = "");
174 virtual bool SaveIfModified();
175 virtual void AlignItems(int flag);
176 virtual void CopySize();
177 virtual void ToBackOrFront(bool toBack);
178 virtual wxWindow *FindParentOfSelection();
179
180 virtual wxFrame *OnCreateEditorFrame(const char *title);
181 virtual wxMenuBar *OnCreateEditorMenuBar(wxFrame *parent);
182 virtual wxResourceEditorScrolledWindow *OnCreateEditorPanel(wxFrame *parent);
183 virtual wxToolBarBase *OnCreateToolBar(wxFrame *parent);
184
185 // Create a window information object for the give window
186 wxWindowPropertyInfo* CreatePropertyInfoForWindow(wxWindow *win);
187 // Edit the given window
188 void EditWindow(wxWindow *win);
189
190 virtual void UpdateResourceList();
191 virtual void AddItemsRecursively(long parent, wxItemResource *resource);
192 virtual bool EditSelectedResource();
193 virtual bool Edit(wxItemResource *res);
194 virtual bool CreateNewPanel();
195 virtual bool CreatePanelItem(wxItemResource *panelResource, wxPanel *panel, char *itemType, int x = 10, int y = 10, bool isBitmap = FALSE);
196 virtual bool DeleteSelection();
197 virtual bool TestCurrentDialog(wxWindow* parent);
198
199 // Saves the window info into the resource, and deletes the
200 // handler. Doesn't actually disassociate the window from
201 // the resources. Replaces OnClose.
202 virtual bool SaveInfoAndDeleteHandler(wxWindow* win);
203
204 // Destroys the window. If this is the 'current' panel, NULLs the
205 // variable.
206 virtual bool DeleteWindow(wxWindow* win);
207 virtual bool DeleteResource(wxItemResource *res);
208 virtual bool DeleteResource(wxWindow *win);
209
210 // Add bitmap resource if there isn't already one with this filename.
211 virtual char *AddBitmapResource(char *filename);
212
213 // Delete the bitmap resource if it isn't being used by another resource.
214 virtual void PossiblyDeleteBitmapResource(char *resourceName);
215
216 // Helper function for above
217 virtual bool IsBitmapResourceUsed(char *resourceName);
218
219 wxItemResource *FindBitmapResourceByFilename(char *filename);
220
221 char *FindBitmapFilenameForResource(wxItemResource *resource);
222
223 // Is this window identifier in use?
224 bool IsSymbolUsed(wxItemResource* thisResource, wxWindowID id) ;
225
226 // Is this window identifier compatible with the given name? (i.e.
227 // does it already exist under a different name)
228 bool IsIdentifierOK(const wxString& name, wxWindowID id);
229
230 // Change all integer ids that match oldId, to newId.
231 // This is necessary if an id is changed for one resource - all resources
232 // must be changed.
233 void ChangeIds(int oldId, int newId);
234
235 // Deletes 'win' and creates a new window from the resource that
236 // was associated with it. E.g. if you can't change properties on the
237 // fly, you'll need to delete the window and create it again.
238 virtual wxWindow *RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info = NULL);
239
240 virtual bool RecreateSelection();
241
242 // Need to search through resource table removing this from
243 // any resource which has this as a parent.
244 virtual bool RemoveResourceFromParent(wxItemResource *res);
245
246 virtual bool EditDialog(wxDialog *dialog, wxWindow *parent);
247
248 void AddSelection(wxWindow *win);
249 void RemoveSelection(wxWindow *win);
250
251 virtual void MakeUniqueName(char *prefix, char *buf);
252
253 // (Dis)associate resource<->physical window
254 // Doesn't delete any windows.
255 virtual void AssociateResource(wxItemResource *resource, wxWindow *win);
256 virtual bool DisassociateResource(wxItemResource *resource);
257 virtual bool DisassociateResource(wxWindow *win);
258 virtual bool DisassociateWindows();
259 virtual wxItemResource *FindResourceForWindow(wxWindow *win);
260 virtual wxWindow *FindWindowForResource(wxItemResource *resource);
261
262 virtual bool InstantiateAllResourcesFromWindows();
263 virtual bool InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse = FALSE);
264
265 // Accessors
266 inline void SetEditorFrame(wxFrame *fr) { m_editorFrame = fr; }
267 inline void SetEditorToolBar(EditorToolBar *tb) { m_editorToolBar = tb; }
268 inline wxFrame *GetEditorFrame() const { return m_editorFrame; }
269 inline wxResourceEditorProjectTree *GetEditorResourceTree() const { return m_editorResourceTree; }
270 inline wxResourceEditorControlList *GetEditorControlList() const { return m_editorControlList; }
271 inline wxList& GetSelections() { return m_selections; }
272 inline wxMenu *GetPopupMenu() const { return m_popupMenu; }
273 inline wxHelpController *GetHelpController() const { return m_helpController; }
274
275 inline void Modify(bool mod = TRUE) { m_modified = mod; }
276 inline bool Modified() const { return m_modified; }
277
278 inline wxResourceTable& GetResourceTable() { return m_resourceTable; }
279 inline wxHashTable& GetResourceAssociations() { return m_resourceAssociations; }
280
281 inline wxString GetCurrentFilename() const { return m_currentFilename; }
282 static wxResourceManager* GetCurrentResourceManager() { return sm_currentResourceManager; }
283
284 inline void SetSymbolFilename(const wxString& s) { m_symbolFilename = s; }
285 inline wxString GetSymbolFilename() const { return m_symbolFilename; }
286
287 inline wxRect& GetPropertyWindowSize() { return m_propertyWindowSize; }
288 inline wxRect& GetResourceEditorWindowSize() { return m_resourceEditorWindowSize; }
289
290 wxResourceSymbolTable& GetSymbolTable() { return m_symbolTable; }
291
292 // Generate a window id and a first stab at a name
293 int GenerateWindowId(const wxString& prefix, wxString& idName) ;
294
295 // Member variables
296 protected:
297 wxHelpController* m_helpController;
298 wxResourceTableWithSaving m_resourceTable;
299 wxFrame* m_editorFrame;
300 wxResourceEditorScrolledWindow* m_editorPanel;
301 wxMenu* m_popupMenu;
302 wxResourceEditorProjectTree* m_editorResourceTree;
303 wxResourceEditorControlList* m_editorControlList;
304 EditorToolBar* m_editorToolBar;
305 int m_nameCounter;
306 int m_symbolIdCounter; // For generating window ids
307 bool m_modified;
308 wxHashTable m_resourceAssociations;
309 wxList m_selections;
310 wxString m_currentFilename;
311 wxBitmap* m_bitmapImage; // Default for static bitmaps/buttons
312
313 wxImageList m_imageList;
314 long m_rootDialogItem; // Root of dialog hierarchy in tree (unused)
315
316 // Options to be saved/restored
317 wxString m_optionsResourceFilename; // e.g. dialoged.ini, .dialogrc
318 wxRect m_propertyWindowSize;
319 wxRect m_resourceEditorWindowSize;
320 static wxResourceManager* sm_currentResourceManager;
321
322 // Symbol table with identifiers for controls
323 wxResourceSymbolTable m_symbolTable;
324 // Filename for include file, e.g. resource.h
325 wxString m_symbolFilename;
326 };
327
328
329 class wxResourceEditorFrame: public wxFrame
330 {
331 public:
332 DECLARE_CLASS(wxResourceEditorFrame)
333
334 wxResourceManager *manager;
335 wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title,
336 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(600, 400),
337 long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "frame");
338 ~wxResourceEditorFrame();
339
340 bool OnClose();
341
342 void OnNew(wxCommandEvent& event);
343 void OnOpen(wxCommandEvent& event);
344 void OnNewDialog(wxCommandEvent& event);
345 void OnClear(wxCommandEvent& event);
346 void OnSave(wxCommandEvent& event);
347 void OnSaveAs(wxCommandEvent& event);
348 void OnExit(wxCommandEvent& event);
349 void OnAbout(wxCommandEvent& event);
350 void OnContents(wxCommandEvent& event);
351 void OnDeleteSelection(wxCommandEvent& event);
352 void OnRecreateSelection(wxCommandEvent& event);
353 void OnTest(wxCommandEvent& event);
354
355 DECLARE_EVENT_TABLE()
356 };
357
358 class wxResourceEditorScrolledWindow: public wxScrolledWindow
359 {
360 public:
361 wxResourceEditorScrolledWindow(wxWindow *parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
362 long style = 0);
363 ~wxResourceEditorScrolledWindow();
364
365 void OnScroll(wxScrollEvent& event);
366 void OnPaint(wxPaintEvent& event);
367
368 void DrawTitle(wxDC& dc);
369
370 // Accessors
371 inline int GetMarginX() { return m_marginX; }
372 inline int GetMarginY() { return m_marginY; }
373
374 public:
375 wxWindow* m_childWindow;
376 private:
377 int m_marginX, m_marginY;
378
379 DECLARE_EVENT_TABLE()
380 };
381
382 #define OBJECT_MENU_EDIT 1
383 #define OBJECT_MENU_DELETE 2
384
385 /*
386 * Main toolbar
387 *
388 */
389
390 class EditorToolBar: public wxToolBar
391 {
392 public:
393 EditorToolBar(wxFrame *frame, const wxPoint& pos = wxPoint(0, 0), const wxSize& size = wxSize(0, 0),
394 long style = wxTB_HORIZONTAL);
395 bool OnLeftClick(int toolIndex, bool toggled);
396 void OnMouseEnter(int toolIndex);
397 void OnPaint(wxPaintEvent& event);
398
399 DECLARE_EVENT_TABLE()
400 };
401
402 // Toolbar ids
403 #define TOOLBAR_LOAD_FILE 1
404 #define TOOLBAR_SAVE_FILE 2
405 #define TOOLBAR_NEW 3
406 #define TOOLBAR_TREE 5
407 #define TOOLBAR_HELP 6
408
409 // Formatting tools
410 #define TOOLBAR_FORMAT_HORIZ 10
411 #define TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN 11
412 #define TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN 12
413 #define TOOLBAR_FORMAT_VERT 13
414 #define TOOLBAR_FORMAT_VERT_TOP_ALIGN 14
415 #define TOOLBAR_FORMAT_VERT_BOT_ALIGN 15
416
417 #define TOOLBAR_TO_FRONT 16
418 #define TOOLBAR_TO_BACK 17
419 #define TOOLBAR_COPY_SIZE 18
420
421 #endif
422