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