]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/reseditr.h
updates for swig generated code
[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 2.1
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 #include "wx/treectrl.h"
28 #include "wx/proplist.h"
29 #include "wx/txtstrm.h"
30 #include "symbtabl.h"
31 #include "winstyle.h"
32
33 #define RESED_DELETE 301
34 #define RESED_RECREATE 303
35 #define RESED_CLEAR 304
36 #define RESED_NEW_DIALOG 305
37 #define RESED_NEW_PANEL 306
38 #define RESED_TEST 310
39 #define RESED_CONVERT_WXRS 311 // Convert old WXRs to new
40
41 #define RESED_CONTENTS 320
42
43 #define IDC_TREECTRL 500
44 #define IDC_LISTCTRL 501
45
46 // For control list ('palette')
47 #define RESED_POINTER 0
48 #define RESED_BUTTON 1
49 #define RESED_BMPBUTTON 2
50 #define RESED_STATICTEXT 3
51 #define RESED_STATICBMP 4
52 #define RESED_STATICBOX 5
53 #define RESED_TEXTCTRL_SINGLE 6
54 #define RESED_TEXTCTRL_MULTIPLE 7
55 #define RESED_LISTBOX 8
56 #define RESED_CHOICE 9
57 #define RESED_COMBOBOX 10
58 #define RESED_CHECKBOX 11
59 #define RESED_SLIDER 12
60 #define RESED_GAUGE 13
61 #define RESED_RADIOBOX 14
62 #define RESED_RADIOBUTTON 15
63 #define RESED_SCROLLBAR 16
64 #define RESED_TREECTRL 17
65 #define RESED_LISTCTRL 18
66 #define RESED_SPINBUTTON 19
67
68 /*
69 * Controls loading, saving, user interface of resource editor(s).
70 */
71
72 class wxResourceEditorFrame;
73 class EditorToolBar;
74 class wxWindowPropertyInfo;
75 class wxResourceEditorProjectTree;
76 class wxResourceEditorControlList;
77
78 #ifdef __WXMSW__
79 #define wxHelpController wxWinHelpController
80 #else
81 #define wxHelpController wxHTMLHelpController;
82 #endif
83
84 class wxHelpController;
85
86 /*
87 * The resourceTable contains a list of wxItemResources (which each may
88 * have further children, defining e.g. a dialog box with controls).
89 *
90 * We need to associate actual windows with each wxItemResource,
91 * instead of the current 'one current window' scheme.
92 *
93 * - We create a new dialog, create a wxItemResource,
94 * associate the dialog with wxItemResource via a hash table.
95 * Must be a hash table in case dialog is deleted without
96 * telling the resource manager.
97 * - When we save the resource after editing/closing the dialog,
98 * we check the wxItemResource/wxDialog and children for
99 * consistency (throw away items no longer in the wxDialog,
100 * create any new wxItemResources).
101 * - We save the wxItemResources via the wxPropertyInfo classes,
102 * so devolve the code to the appropriate class.
103 * This involves creating a new temporary wxPropertyInfo for
104 * the purpose.
105 *
106 * We currently assume we only create one instance of a window for
107 * each wxItemResource. We will need to relax this when we're editing
108 * in situ.
109 *
110 *
111 */
112
113 class wxResourceTableWithSaving: public wxResourceTable
114 {
115 public:
116 wxResourceTableWithSaving():wxResourceTable()
117 {
118 // Add all known window styles
119 m_styleTable.Init();
120 }
121 virtual bool Save(const wxString& filename);
122 virtual bool SaveResource(wxTextOutputStream& stream, wxItemResource* item, wxItemResource* parentItem);
123
124 void GeneratePanelStyleString(long windowStyle, char *buf);
125 void GenerateDialogStyleString(long windowStyle, char *buf);
126
127 void GenerateControlStyleString(const wxString& windowClass, long windowStyle, char *buf);
128
129 void OutputFont(wxTextOutputStream& stream, const wxFont& font);
130 wxControl *CreateItem(wxPanel *panel, const wxItemResource *childResource, const wxItemResource* parentResource);
131
132 protected:
133 wxWindowStyleTable m_styleTable;
134 };
135
136 class wxResourceEditorScrolledWindow;
137
138 class wxResourceManager: public wxObject
139 {
140 friend class wxResourceEditorFrame;
141
142 public:
143 wxResourceManager();
144 ~wxResourceManager();
145
146 // Operations
147
148 // Initializes the resource manager
149 bool Initialize();
150
151 // Load/save window size etc.
152 bool LoadOptions();
153 bool SaveOptions();
154
155 // Show or hide the resource editor frame, which displays a list
156 // of resources with ability to edit them.
157 virtual bool ShowResourceEditor(bool show, wxWindow *parent = NULL, const char *title = "wxWindows Dialog Editor");
158
159 // Convert old WXRs to new
160 virtual bool ConvertWXRs();
161 bool DoConvertWXR(const wxString& oldPath, const wxString& newPath);
162 bool ChangeOldToNewResource(wxItemResource* parent, wxItemResource* res);
163 bool InsertLabelResource(wxItemResource* parent, wxItemResource* res);
164
165 virtual bool Save();
166 virtual bool SaveAs();
167 virtual bool Save(const wxString& filename);
168 virtual bool Load(const wxString& filename);
169 virtual bool Clear(bool deleteWindows = TRUE, bool force = TRUE);
170 virtual void SetFrameTitle(const wxString& filename);
171 virtual void ClearCurrentDialog();
172 virtual bool New(bool loadFromFile = TRUE, const wxString& filename = "");
173 virtual bool SaveIfModified();
174 virtual void AlignItems(int flag);
175 virtual void CopySize(int command); // Copy width, height or both from first control
176 virtual void ToBackOrFront(bool toBack);
177 virtual void DistributePositions(int command); // Distribute controls evenly between first and last
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 wxToolBar *OnCreateToolBar(wxFrame *parent);
184
185 // Create a window information object for the given 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 wxString AddBitmapResource(const wxString& filename);
212
213 // Delete the bitmap resource if it isn't being used by another resource.
214 virtual void PossiblyDeleteBitmapResource(const wxString& resourceName);
215
216 // Helper function for above
217 virtual bool IsBitmapResourceUsed(const wxString& resourceName);
218
219 wxItemResource *FindBitmapResourceByFilename(const wxString& filename);
220
221 wxString 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 // If any resource ids were missing (or their symbol was missing),
236 // repair them i.e. give them new ids. Returns TRUE if any resource
237 // needed repairing.
238 bool RepairResourceIds();
239
240 // Deletes 'win' and creates a new window from the resource that
241 // was associated with it. E.g. if you can't change properties on the
242 // fly, you'll need to delete the window and create it again.
243 virtual wxWindow *RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info = NULL, bool instantiateFirst = TRUE);
244
245 virtual bool RecreateSelection();
246
247 // Remove selection handles if this control is selected
248 void DeselectItemIfNecessary(wxWindow *win);
249
250 // Need to search through resource table removing this from
251 // any resource which has this as a parent.
252 virtual bool RemoveResourceFromParent(wxItemResource *res);
253
254 virtual bool EditDialog(wxDialog *dialog, wxWindow *parent);
255
256 void AddSelection(wxWindow *win);
257 void RemoveSelection(wxWindow *win);
258
259 virtual void MakeUniqueName(char *prefix, char *buf);
260
261 // (Dis)associate resource<->physical window
262 // Doesn't delete any windows.
263 virtual void AssociateResource(wxItemResource *resource, wxWindow *win);
264 virtual bool DisassociateResource(wxItemResource *resource);
265 virtual bool DisassociateResource(wxWindow *win);
266 virtual bool DisassociateWindows();
267 virtual wxItemResource *FindResourceForWindow(wxWindow *win);
268 virtual wxWindow *FindWindowForResource(wxItemResource *resource);
269
270 virtual bool InstantiateAllResourcesFromWindows();
271 virtual bool InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse = FALSE);
272
273 // Accessors
274 inline void SetEditorFrame(wxFrame *fr) { m_editorFrame = fr; }
275 inline void SetEditorToolBar(EditorToolBar *tb) { m_editorToolBar = tb; }
276 inline wxFrame *GetEditorFrame() const { return m_editorFrame; }
277 inline wxResourceEditorProjectTree *GetEditorResourceTree() const { return m_editorResourceTree; }
278 inline wxResourceEditorControlList *GetEditorControlList() const { return m_editorControlList; }
279 inline wxList& GetSelections() { return m_selections; }
280 inline wxMenu *GetPopupMenu() const { return m_popupMenu; }
281 #ifdef __WXMSW__
282 inline wxHelpController *GetHelpController() const { return m_helpController; }
283 #endif
284
285 inline void Modify(bool mod = TRUE) { m_modified = mod; }
286 inline bool Modified() const { return m_modified; }
287
288 inline wxResourceTable& GetResourceTable() { return m_resourceTable; }
289 inline wxHashTable& GetResourceAssociations() { return m_resourceAssociations; }
290
291 inline wxString GetCurrentFilename() const { return m_currentFilename; }
292 static wxResourceManager* GetCurrentResourceManager() { return sm_currentResourceManager; }
293
294 inline void SetSymbolFilename(const wxString& s) { m_symbolFilename = s; }
295 inline wxString GetSymbolFilename() const { return m_symbolFilename; }
296
297 inline wxRect& GetPropertyWindowSize() { return m_propertyWindowSize; }
298 inline wxRect& GetResourceEditorWindowSize() { return m_resourceEditorWindowSize; }
299
300 wxResourceSymbolTable& GetSymbolTable() { return m_symbolTable; }
301
302 // Generate a window id and a first stab at a name
303 int GenerateWindowId(const wxString& prefix, wxString& idName) ;
304
305 // Member variables
306 protected:
307 #ifdef __WXMSW__
308 wxHelpController* m_helpController;
309 #endif
310 wxResourceTableWithSaving m_resourceTable;
311 wxFrame* m_editorFrame;
312 wxResourceEditorScrolledWindow* m_editorPanel;
313 wxMenu* m_popupMenu;
314 wxResourceEditorProjectTree* m_editorResourceTree;
315 wxResourceEditorControlList* m_editorControlList;
316 EditorToolBar* m_editorToolBar;
317 int m_nameCounter;
318 int m_symbolIdCounter; // For generating window ids
319 bool m_modified;
320 wxHashTable m_resourceAssociations;
321 wxList m_selections;
322 wxString m_currentFilename;
323 wxBitmap* m_bitmapImage; // Default for static bitmaps/buttons
324
325 wxImageList m_imageList;
326 long m_rootDialogItem; // Root of dialog hierarchy in tree (unused)
327
328 // Options to be saved/restored
329 wxString m_optionsResourceFilename; // e.g. dialoged.ini, .dialogrc
330 wxRect m_propertyWindowSize;
331 wxRect m_resourceEditorWindowSize;
332 static wxResourceManager* sm_currentResourceManager;
333
334 // Symbol table with identifiers for controls
335 wxResourceSymbolTable m_symbolTable;
336 // Filename for include file, e.g. resource.h
337 wxString m_symbolFilename;
338 };
339
340
341 class wxResourceEditorFrame: public wxFrame
342 {
343 public:
344 DECLARE_CLASS(wxResourceEditorFrame)
345
346 wxResourceManager *manager;
347 wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title,
348 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(600, 400),
349 long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "frame");
350 ~wxResourceEditorFrame();
351
352 void OnCloseWindow(wxCloseEvent& event);
353
354 void OnNew(wxCommandEvent& event);
355 void OnOpen(wxCommandEvent& event);
356 void OnNewDialog(wxCommandEvent& event);
357 void OnClear(wxCommandEvent& event);
358 void OnSave(wxCommandEvent& event);
359 void OnSaveAs(wxCommandEvent& event);
360 void OnExit(wxCommandEvent& event);
361 void OnAbout(wxCommandEvent& event);
362 void OnContents(wxCommandEvent& event);
363 void OnDeleteSelection(wxCommandEvent& event);
364 void OnRecreateSelection(wxCommandEvent& event);
365 void OnTest(wxCommandEvent& event);
366 void OnConvertWXRs(wxCommandEvent& event);
367
368 DECLARE_EVENT_TABLE()
369 };
370
371 class wxResourceEditorScrolledWindow: public wxScrolledWindow
372 {
373 public:
374 wxResourceEditorScrolledWindow(wxWindow *parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
375 long style = 0);
376 ~wxResourceEditorScrolledWindow();
377
378 void OnPaint(wxPaintEvent& event);
379
380 void DrawTitle(wxDC& dc);
381
382 // Accessors
383 inline int GetMarginX() { return m_marginX; }
384 inline int GetMarginY() { return m_marginY; }
385
386 public:
387 wxWindow* m_childWindow;
388 private:
389 int m_marginX, m_marginY;
390
391 DECLARE_EVENT_TABLE()
392 };
393
394 #define OBJECT_MENU_TITLE 1
395 #define OBJECT_MENU_EDIT 2
396 #define OBJECT_MENU_DELETE 3
397
398 /*
399 * Main toolbar
400 *
401 */
402
403 class EditorToolBar: public wxToolBar
404 {
405 public:
406 EditorToolBar(wxFrame *frame, const wxPoint& pos = wxPoint(0, 0), const wxSize& size = wxSize(0, 0),
407 long style = wxTB_HORIZONTAL);
408 bool OnLeftClick(int toolIndex, bool toggled);
409 void OnMouseEnter(int toolIndex);
410
411 DECLARE_EVENT_TABLE()
412 };
413
414 // Toolbar ids
415 #define TOOLBAR_LOAD_FILE 101
416 #define TOOLBAR_SAVE_FILE 102
417 #define TOOLBAR_NEW 103
418 #define TOOLBAR_TREE 105
419 #define TOOLBAR_HELP 106
420
421 // Formatting tools
422 #define TOOLBAR_FORMAT_HORIZ 110
423 #define TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN 111
424 #define TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN 112
425 #define TOOLBAR_FORMAT_VERT 113
426 #define TOOLBAR_FORMAT_VERT_TOP_ALIGN 114
427 #define TOOLBAR_FORMAT_VERT_BOT_ALIGN 115
428
429 #define TOOLBAR_TO_FRONT 116
430 #define TOOLBAR_TO_BACK 117
431 #define TOOLBAR_COPY_SIZE 118
432 #define TOOLBAR_COPY_WIDTH 119
433 #define TOOLBAR_COPY_HEIGHT 120
434 #define TOOLBAR_DISTRIBUTE_HORIZ 121
435 #define TOOLBAR_DISTRIBUTE_VERT 122
436
437 /*
438 * this class is used to store data associated with a tree item
439 */
440 class wxResourceTreeData : public wxTreeItemData
441 {
442 public:
443 wxResourceTreeData(wxItemResource *resource) { m_resource = resource; }
444
445 wxItemResource *GetResource() const { return m_resource; }
446
447 private:
448 wxItemResource *m_resource;
449 };
450
451 #endif
452