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