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