]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
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" | |
ae8351fc JS |
25 | #include "wx/toolbar.h" |
26 | #include "wx/imaglist.h" | |
457814b5 JS |
27 | |
28 | #include "proplist.h" | |
29 | ||
457814b5 | 30 | #define RESED_DELETE 1 |
457814b5 JS |
31 | #define RESED_RECREATE 3 |
32 | #define RESED_CLEAR 4 | |
33 | #define RESED_NEW_DIALOG 5 | |
34 | #define RESED_NEW_PANEL 6 | |
ae8351fc | 35 | #define RESED_TEST 10 |
457814b5 JS |
36 | |
37 | #define RESED_CONTENTS 20 | |
38 | ||
ae8351fc JS |
39 | #define IDC_TREECTRL 100 |
40 | #define IDC_LISTCTRL 101 | |
41 | ||
42 | // For control list ('palette') | |
43 | #define RESED_POINTER 0 | |
44 | #define RESED_BUTTON 1 | |
45 | #define RESED_BMPBUTTON 2 | |
46 | #define RESED_STATICTEXT 3 | |
47 | #define RESED_STATICBMP 4 | |
48 | #define RESED_STATICBOX 5 | |
49 | #define RESED_TEXTCTRL_SINGLE 6 | |
50 | #define RESED_TEXTCTRL_MULTIPLE 7 | |
51 | #define RESED_LISTBOX 8 | |
52 | #define RESED_CHOICE 9 | |
53 | #define RESED_COMBOBOX 10 | |
54 | #define RESED_CHECKBOX 11 | |
55 | #define RESED_SLIDER 12 | |
56 | #define RESED_GAUGE 13 | |
57 | #define RESED_RADIOBOX 14 | |
58 | #define RESED_RADIOBUTTON 15 | |
59 | #define RESED_SCROLLBAR 16 | |
60 | #define RESED_TREECTRL 17 | |
61 | #define RESED_LISTCTRL 18 | |
62 | #define RESED_SPINBUTTON 19 | |
63 | ||
457814b5 JS |
64 | /* |
65 | * Controls loading, saving, user interface of resource editor(s). | |
66 | */ | |
67 | ||
68 | class wxResourceEditorFrame; | |
69 | class EditorToolPalette; | |
70 | class EditorToolBar; | |
71 | class wxWindowPropertyInfo; | |
ae8351fc JS |
72 | class wxResourceEditorProjectTree; |
73 | class wxResourceEditorControlList; | |
457814b5 JS |
74 | |
75 | #ifdef __WINDOWS__ | |
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: | |
ae8351fc | 113 | wxResourceTableWithSaving():wxResourceTable() |
457814b5 JS |
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 GenerateListBoxStyleString(long windowStyle, char *buf); | |
129 | void GenerateSliderStyleString(long windowStyle, char *buf); | |
130 | void GenerateGroupBoxStyleString(long windowStyle, char *buf); | |
131 | void GenerateGaugeStyleString(long windowStyle, char *buf); | |
132 | void GenerateChoiceStyleString(long windowStyle, char *buf); | |
133 | void GenerateScrollBarStyleString(long windowStyle, char *buf); | |
134 | void GenerateItemStyleString(long windowStyle, char *buf); | |
135 | ||
136 | bool GenerateStyle(char *buf, long windowStyle, long flag, char *strStyle); | |
137 | ||
138 | void OutputFont(ostream& stream, wxFont *font); | |
139 | wxControl *CreateItem(wxPanel *panel, wxItemResource *childResource); | |
140 | }; | |
141 | ||
ae8351fc JS |
142 | class wxResourceEditorScrolledWindow; |
143 | ||
457814b5 JS |
144 | class wxResourceManager: public wxObject |
145 | { | |
ae8351fc | 146 | friend class wxResourceEditorFrame; |
457814b5 | 147 | |
ae8351fc JS |
148 | public: |
149 | wxResourceManager(); | |
150 | ~wxResourceManager(); | |
457814b5 | 151 | |
ae8351fc | 152 | // Operations |
457814b5 | 153 | |
ae8351fc JS |
154 | // Initializes the resource manager |
155 | bool Initialize(); | |
457814b5 | 156 | |
ae8351fc JS |
157 | // Load/save window size etc. |
158 | bool LoadOptions(); | |
159 | bool SaveOptions(); | |
457814b5 JS |
160 | |
161 | // Show or hide the resource editor frame, which displays a list | |
162 | // of resources with ability to edit them. | |
163 | virtual bool ShowResourceEditor(bool show, wxWindow *parent = NULL, const char *title = "wxWindows Dialog Editor"); | |
164 | ||
ae8351fc JS |
165 | virtual bool Save(); |
166 | virtual bool SaveAs(); | |
457814b5 JS |
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); | |
ae8351fc | 171 | virtual void ClearCurrentDialog(); |
457814b5 | 172 | virtual bool New(bool loadFromFile = TRUE, const wxString& filename = ""); |
ae8351fc | 173 | virtual bool SaveIfModified(); |
457814b5 | 174 | virtual void AlignItems(int flag); |
ae8351fc | 175 | virtual void CopySize(); |
457814b5 | 176 | virtual void ToBackOrFront(bool toBack); |
ae8351fc | 177 | virtual wxWindow *FindParentOfSelection(); |
457814b5 JS |
178 | |
179 | virtual wxFrame *OnCreateEditorFrame(const char *title); | |
180 | virtual wxMenuBar *OnCreateEditorMenuBar(wxFrame *parent); | |
ae8351fc | 181 | virtual wxResourceEditorScrolledWindow *OnCreateEditorPanel(wxFrame *parent); |
457814b5 JS |
182 | virtual wxToolBarBase *OnCreateToolBar(wxFrame *parent); |
183 | virtual EditorToolPalette *OnCreatePalette(wxFrame *parent); | |
457814b5 | 184 | |
ae8351fc JS |
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(); | |
457814b5 | 193 | virtual bool Edit(wxItemResource *res); |
ae8351fc | 194 | virtual bool CreateNewPanel(); |
457814b5 JS |
195 | virtual bool CreatePanelItem(wxItemResource *panelResource, wxPanel *panel, char *itemType, int x = 10, int y = 10, bool isBitmap = FALSE); |
196 | ||
ae8351fc JS |
197 | virtual bool DeleteSelection(); |
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); | |
457814b5 | 203 | |
ae8351fc JS |
204 | // Destroys the window. If this is the 'current' panel, NULLs the |
205 | // variable. | |
206 | virtual bool DeleteWindow(wxWindow* win); | |
457814b5 | 207 | virtual bool DeleteResource(wxItemResource *res); |
ae8351fc | 208 | virtual bool DeleteResource(wxWindow *win); |
457814b5 JS |
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 | // Deletes 'win' and creates a new window from the resource that | |
224 | // was associated with it. E.g. if you can't change properties on the | |
225 | // fly, you'll need to delete the window and create it again. | |
226 | virtual wxWindow *RecreateWindowFromResource(wxWindow *win, wxWindowPropertyInfo *info = NULL); | |
227 | ||
ae8351fc | 228 | virtual bool RecreateSelection(); |
457814b5 JS |
229 | |
230 | // Need to search through resource table removing this from | |
231 | // any resource which has this as a parent. | |
232 | virtual bool RemoveResourceFromParent(wxItemResource *res); | |
233 | ||
234 | virtual bool EditDialog(wxDialog *dialog, wxWindow *parent); | |
235 | ||
457814b5 JS |
236 | void AddSelection(wxWindow *win); |
237 | void RemoveSelection(wxWindow *win); | |
238 | ||
457814b5 JS |
239 | virtual void MakeUniqueName(char *prefix, char *buf); |
240 | ||
241 | // (Dis)associate resource<->physical window | |
ae8351fc | 242 | // Doesn't delete any windows. |
457814b5 | 243 | virtual void AssociateResource(wxItemResource *resource, wxWindow *win); |
ae8351fc JS |
244 | virtual bool DisassociateResource(wxItemResource *resource); |
245 | virtual bool DisassociateResource(wxWindow *win); | |
246 | virtual bool DisassociateWindows(); | |
457814b5 JS |
247 | virtual wxItemResource *FindResourceForWindow(wxWindow *win); |
248 | virtual wxWindow *FindWindowForResource(wxItemResource *resource); | |
249 | ||
ae8351fc | 250 | virtual bool InstantiateAllResourcesFromWindows(); |
457814b5 JS |
251 | virtual bool InstantiateResourceFromWindow(wxItemResource *resource, wxWindow *window, bool recurse = FALSE); |
252 | ||
ae8351fc JS |
253 | // Accessors |
254 | inline void SetEditorFrame(wxFrame *fr) { m_editorFrame = fr; } | |
255 | inline void SetEditorToolBar(EditorToolBar *tb) { m_editorToolBar = tb; } | |
256 | inline void SetEditorPalette(EditorToolPalette *pal) { m_editorPalette = pal; } | |
257 | inline wxFrame *GetEditorFrame() const { return m_editorFrame; } | |
258 | inline wxResourceEditorProjectTree *GetEditorResourceTree() const { return m_editorResourceTree; } | |
259 | inline wxResourceEditorControlList *GetEditorControlList() const { return m_editorControlList; } | |
260 | inline EditorToolPalette *GetEditorPalette() const { return m_editorPalette; } | |
261 | inline wxList& GetSelections() { return m_selections; } | |
262 | inline wxMenu *GetPopupMenu() const { return m_popupMenu; } | |
263 | inline wxHelpController *GetHelpController() const { return m_helpController; } | |
457814b5 | 264 | |
ae8351fc JS |
265 | inline void Modify(bool mod = TRUE) { m_modified = mod; } |
266 | inline bool Modified() const { return m_modified; } | |
457814b5 | 267 | |
ae8351fc JS |
268 | inline wxResourceTable& GetResourceTable() { return m_resourceTable; } |
269 | inline wxHashTable& GetResourceAssociations() { return m_resourceAssociations; } | |
270 | ||
271 | inline wxString& GetCurrentFilename() { return m_currentFilename; } | |
272 | static wxResourceManager* GetCurrentResourceManager() { return sm_currentResourceManager; } | |
273 | ||
274 | inline wxRect& GetPropertyWindowSize() { return m_propertyWindowSize; } | |
275 | inline wxRect& GetResourceEditorWindowSize() { return m_resourceEditorWindowSize; } | |
457814b5 | 276 | |
ae8351fc JS |
277 | // Member variables |
278 | protected: | |
279 | wxHelpController* m_helpController; | |
280 | wxResourceTableWithSaving m_resourceTable; | |
281 | wxFrame* m_editorFrame; | |
282 | wxResourceEditorScrolledWindow* m_editorPanel; | |
283 | wxMenu* m_popupMenu; | |
284 | wxResourceEditorProjectTree* m_editorResourceTree; | |
285 | wxResourceEditorControlList* m_editorControlList; | |
286 | EditorToolPalette* m_editorPalette; | |
287 | EditorToolBar* m_editorToolBar; | |
288 | int m_nameCounter; | |
289 | bool m_modified; | |
290 | wxHashTable m_resourceAssociations; | |
291 | wxList m_selections; | |
292 | wxString m_currentFilename; | |
293 | wxBitmap* m_bitmapImage; // Default for static bitmaps/buttons | |
294 | ||
295 | wxImageList m_imageList; | |
296 | long m_rootDialogItem; // Root of dialog hierarchy in tree (unused) | |
297 | ||
298 | // Options to be saved/restored | |
299 | wxString m_optionsResourceFilename; // e.g. dialoged.ini, .dialogrc | |
300 | wxRect m_propertyWindowSize; | |
301 | wxRect m_resourceEditorWindowSize; | |
302 | static wxResourceManager* sm_currentResourceManager; | |
457814b5 JS |
303 | }; |
304 | ||
ae8351fc | 305 | |
457814b5 JS |
306 | class wxResourceEditorFrame: public wxFrame |
307 | { | |
308 | public: | |
ae8351fc JS |
309 | DECLARE_CLASS(wxResourceEditorFrame) |
310 | ||
457814b5 | 311 | wxResourceManager *manager; |
ae8351fc JS |
312 | wxResourceEditorFrame(wxResourceManager *resMan, wxFrame *parent, const wxString& title, |
313 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(600, 400), | |
314 | long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "frame"); | |
315 | ~wxResourceEditorFrame(); | |
316 | ||
317 | bool OnClose(); | |
318 | ||
319 | void OnNew(wxCommandEvent& event); | |
320 | void OnOpen(wxCommandEvent& event); | |
321 | void OnNewDialog(wxCommandEvent& event); | |
322 | void OnClear(wxCommandEvent& event); | |
323 | void OnSave(wxCommandEvent& event); | |
324 | void OnSaveAs(wxCommandEvent& event); | |
325 | void OnExit(wxCommandEvent& event); | |
326 | void OnAbout(wxCommandEvent& event); | |
327 | void OnContents(wxCommandEvent& event); | |
328 | void OnDeleteSelection(wxCommandEvent& event); | |
329 | void OnRecreateSelection(wxCommandEvent& event); | |
330 | void OnTest(wxCommandEvent& event); | |
331 | ||
332 | DECLARE_EVENT_TABLE() | |
457814b5 JS |
333 | }; |
334 | ||
ae8351fc | 335 | class wxResourceEditorScrolledWindow: public wxScrolledWindow |
457814b5 JS |
336 | { |
337 | public: | |
ae8351fc JS |
338 | wxResourceEditorScrolledWindow(wxWindow *parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
339 | long style = 0); | |
340 | ~wxResourceEditorScrolledWindow(); | |
341 | ||
342 | void OnScroll(wxScrollEvent& event); | |
343 | void OnPaint(wxPaintEvent& event); | |
344 | ||
345 | void DrawTitle(wxDC& dc); | |
346 | ||
347 | // Accessors | |
348 | inline int GetMarginX() { return m_marginX; } | |
349 | inline int GetMarginY() { return m_marginY; } | |
457814b5 | 350 | |
457814b5 | 351 | public: |
ae8351fc JS |
352 | wxWindow* m_childWindow; |
353 | private: | |
354 | int m_marginX, m_marginY; | |
457814b5 | 355 | |
ae8351fc JS |
356 | DECLARE_EVENT_TABLE() |
357 | }; | |
457814b5 JS |
358 | |
359 | #define OBJECT_MENU_EDIT 1 | |
360 | #define OBJECT_MENU_DELETE 2 | |
361 | ||
362 | /* | |
363 | * Main toolbar | |
364 | * | |
365 | */ | |
366 | ||
ae8351fc | 367 | class EditorToolBar: public wxToolBar |
457814b5 | 368 | { |
ae8351fc JS |
369 | public: |
370 | EditorToolBar(wxFrame *frame, const wxPoint& pos = wxPoint(0, 0), const wxSize& size = wxSize(0, 0), | |
457814b5 JS |
371 | long style = 0, int direction = wxVERTICAL, int RowsOrColumns = 2); |
372 | bool OnLeftClick(int toolIndex, bool toggled); | |
373 | void OnMouseEnter(int toolIndex); | |
374 | void OnPaint(wxPaintEvent& event); | |
375 | ||
376 | DECLARE_EVENT_TABLE() | |
377 | }; | |
378 | ||
379 | // Toolbar ids | |
ae8351fc JS |
380 | #define TOOLBAR_LOAD_FILE 1 |
381 | #define TOOLBAR_SAVE_FILE 2 | |
382 | #define TOOLBAR_NEW 3 | |
383 | #define TOOLBAR_TREE 5 | |
384 | #define TOOLBAR_HELP 6 | |
457814b5 JS |
385 | |
386 | // Formatting tools | |
ae8351fc JS |
387 | #define TOOLBAR_FORMAT_HORIZ 10 |
388 | #define TOOLBAR_FORMAT_HORIZ_LEFT_ALIGN 11 | |
457814b5 | 389 | #define TOOLBAR_FORMAT_HORIZ_RIGHT_ALIGN 12 |
ae8351fc JS |
390 | #define TOOLBAR_FORMAT_VERT 13 |
391 | #define TOOLBAR_FORMAT_VERT_TOP_ALIGN 14 | |
392 | #define TOOLBAR_FORMAT_VERT_BOT_ALIGN 15 | |
457814b5 | 393 | |
ae8351fc JS |
394 | #define TOOLBAR_TO_FRONT 16 |
395 | #define TOOLBAR_TO_BACK 17 | |
396 | #define TOOLBAR_COPY_SIZE 18 | |
457814b5 JS |
397 | |
398 | #endif | |
399 |