~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/wxwidgets/wxsitemresdata.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* This file is part of wxSmith plugin for Code::Blocks Studio
 
3
* Copyright (C) 2006-2007  Bartlomiej Swiecki
 
4
*
 
5
* wxSmith is free software; you can redistribute it and/or modify
 
6
* it under the terms of the GNU General Public License as published by
 
7
* the Free Software Foundation; either version 3 of the License, or
 
8
* (at your option) any later version.
 
9
*
 
10
* wxSmith is distributed in the hope that it will be useful,
 
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
* GNU General Public License for more details.
 
14
*
 
15
* You should have received a copy of the GNU General Public License
 
16
* along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
 
17
*
 
18
* $Revision: 4850 $
 
19
* $Id: wxsitemresdata.h 4850 2008-01-29 21:45:49Z byo $
 
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/wxwidgets/wxsitemresdata.h $
 
21
*/
 
22
 
 
23
#ifndef WXSITEMRESDATA_H
 
24
#define WXSITEMRESDATA_H
 
25
 
 
26
#include "wxsitem.h"
 
27
#include "wxsparent.h"
 
28
#include "wxsitemres.h"
 
29
#include "wxscorrector.h"
 
30
#include "wxsitemundobuffer.h"
 
31
#include "wxsitemresdataobject.h"
 
32
#include "../wxsresourcetree.h"
 
33
 
 
34
class wxsTool;
 
35
class wxsItemEditor;
 
36
 
 
37
/** \brief Class holding data for item resources and operating on it */
 
38
class wxsItemResData
 
39
{
 
40
    public:
 
41
 
 
42
        /** \brief Ctor
 
43
         *
 
44
         * Constructor tries to load resource. Depending on what
 
45
         * parameters are empty strings, given type of file is assumed.
 
46
         *  - If Wxs, Src and Hdr file names are empty, it's only Xrc file.
 
47
         *  - If Xrc is empty but no other, it's resource not using Xrc file
 
48
         *  - If all file names are not empty, it's resoure using Xrc file
 
49
         *  - Other combinations are invalid.
 
50
         *
 
51
         * Parameters passed to constructor are GLOBAL paths (opposite to
 
52
         * wxsItemRes where names are relative to .cbp's directory).
 
53
         */
 
54
        wxsItemResData(
 
55
            const wxString& WxsFileName,
 
56
            const wxString& SrcFileName,
 
57
            const wxString& HdrFileName,
 
58
            const wxString& XrcFileName,
 
59
            const wxString& ClassName,
 
60
            const wxString& ClassType,
 
61
            wxsCodingLang   Language,
 
62
            bool UseForwardDeclarations,
 
63
            wxsResourceItemId TreeId,
 
64
            wxsItemEditor*  Editor,
 
65
            wxsItemResFunctions* Functions
 
66
            );
 
67
 
 
68
        /** \brief Dctor
 
69
         *
 
70
         * \note When wxsItemResData is deleted and the
 
71
         *       data is in modified state (was not saved after modification),
 
72
         *       all changes are lost. Please call Save() to avoid this.
 
73
         */
 
74
        virtual ~wxsItemResData();
 
75
 
 
76
        /** \brief Loading resource
 
77
         *
 
78
         * This function (Re)loads resource from
 
79
         * files. Current resource content is moved into
 
80
         * undo buffer and resource data is replaced by the one
 
81
         * loaded from file.
 
82
         */
 
83
        bool Load();
 
84
 
 
85
        /** \brief Saving resource
 
86
         *
 
87
         * This function saves resource to wxs file
 
88
         * (note that Src / Hdr / Xrc files are not saved
 
89
         * because they're updated after each resource change)
 
90
         */
 
91
        bool Save();
 
92
 
 
93
        /** \brief Checking if resource was loaded properly
 
94
         *
 
95
         * This function may be used to check if resource was properly
 
96
         * loaded. It may be especially usual after checking if
 
97
         * constructor has loaded all data properly.
 
98
         */
 
99
        inline bool IsOk() { return m_IsOK; }
 
100
 
 
101
        /** \brief Function starting change of resource data
 
102
         *
 
103
         * This function Notifies that resource is going to change.
 
104
         * It locks data from other changes. Each resource
 
105
         * change must be finished with call to EndChange function.
 
106
         * Between BeginChagne and EndChange call there should not
 
107
         * be any call to gui item, so do not jump out of event
 
108
         * function before EndChange is called.
 
109
         *
 
110
         * Change of resource is any operation made on any wxsItem
 
111
         * class inside the resource (including the root class).
 
112
         */
 
113
        void BeginChange();
 
114
 
 
115
        /** \brief Function ending change of resource data
 
116
         *
 
117
         * This function must be paired with BeginChange() call.
 
118
         * it notifies that change of resource has been finished
 
119
         * and that it's good time to update all data on the screen
 
120
         * ans store new undo buffer entry.
 
121
         */
 
122
        void EndChange();
 
123
 
 
124
        /** \brief Checking if item has modified state */
 
125
        inline bool GetModified() { return m_Undo.IsModified(); }
 
126
 
 
127
        /** \brief Getting root item
 
128
         *  \return pointer to item on success, 0 when data wasn't initialized properly
 
129
         */
 
130
        inline wxsItem* GetRootItem() { return m_RootItem; }
 
131
 
 
132
        /** \brief Getting main item of selection */
 
133
        inline wxsItem* GetRootSelection() { return m_RootSelection; }
 
134
 
 
135
        /** \brief Getting properties filter based on current edit  mode */
 
136
        inline int GetPropertiesFilter() { return m_PropertiesFilter; }
 
137
 
 
138
        /** \brief Getting name of wxs file (global path) */
 
139
        inline const wxString& GetWxsFileName() { return m_SrcFileName; }
 
140
 
 
141
        /** \brief Getting name of source file (global path) */
 
142
        inline const wxString& GetSrcFileName() { return m_SrcFileName; }
 
143
 
 
144
        /** \brief Getting name of header file (global path) */
 
145
        inline const wxString& GetHdrFileName() { return m_HdrFileName; }
 
146
 
 
147
        /** \brief Getting name of XRC file (global path) */
 
148
        inline const wxString& GetXrcFileName() { return m_XrcFileName; }
 
149
 
 
150
        /** \brief Getting name of class of edited resource */
 
151
        inline const wxString& GetClassName() { return m_ClassName; }
 
152
 
 
153
        /** \brief Getting name class used as base for this resource (like wxDialog) */
 
154
        inline const wxString& GetClassType() { return m_ClassType; }
 
155
 
 
156
        /** \brief Getting language used in resource */
 
157
        inline wxsCodingLang GetLanguage() { return m_Language; }
 
158
 
 
159
        /** \brief Searching for tree id in main resource tree for given item */
 
160
        inline bool GetTreeId(wxsResourceItemId& Id,wxsItem* Item) { return FindId(Id,Item); }
 
161
 
 
162
        /** \brief Showing popup menu from given item */
 
163
        inline wxsItemEditor* GetEditor() { return m_Editor; }
 
164
 
 
165
        /* ************************ */
 
166
        /*  Undo buffer operations  */
 
167
        /* ************************ */
 
168
 
 
169
                /** \brief Checking if can Undo */
 
170
                inline bool CanUndo() { return m_Undo.CanUndo(); }
 
171
 
 
172
                /** \brief Ckecing if can Redo */
 
173
                inline bool CanRedo() { return m_Undo.CanRedo(); }
 
174
 
 
175
                /** \brief Undoing */
 
176
                inline void Undo() { SetXmlData(m_Undo.Undo()); }
 
177
 
 
178
                /** \brief Redoing */
 
179
                inline void Redo() { SetXmlData(m_Undo.Redo()); }
 
180
 
 
181
        /** \brief Checking if current content is read only */
 
182
        inline bool IsReadOnly() { return m_ReadOnly; }
 
183
 
 
184
                /* ********************** */
 
185
                /*  Clipboard operations  */
 
186
                /* ********************** */
 
187
 
 
188
                /** \brief Checking if we can paste current clipboard content */
 
189
                bool CanPaste();
 
190
 
 
191
                /** \brief Cutting current selection to clipboard */
 
192
                void Cut();
 
193
 
 
194
                /** \brief Copying current selectin to clipboard */
 
195
                void Copy();
 
196
 
 
197
                /** \brief Pasting components from clipboard
 
198
                 *  \param Parent parent for new items
 
199
                 *  \param Position initial position for new items
 
200
                 */
 
201
                void Paste(wxsParent* Parent,int Position);
 
202
 
 
203
 
 
204
                /* ********************** */
 
205
                /*  Selection operations  */
 
206
                /* ********************** */
 
207
 
 
208
                /** \brief Checking of there's any selection */
 
209
                bool AnySelected();
 
210
 
 
211
                /** \brief Selecting one item */
 
212
                bool SelectItem(wxsItem* Item,bool UnselectOther);
 
213
 
 
214
                /** \brief Getting last selected item or 0 if there's no valid selection */
 
215
                inline wxsItem* GetLastSelection() { return m_RootSelection; }
 
216
 
 
217
                /* ******************* */
 
218
                /*  Operating on data  */
 
219
                /* ******************* */
 
220
 
 
221
                /** \brief Adding new item
 
222
                 *
 
223
                 * This function tries to add new item into
 
224
                 * given position. If it's possible, new item
 
225
                 * is added and true is returned. If it's
 
226
                 * impossible, new item is deleted internally
 
227
                 * and function returns false.
 
228
                 * \note To add tool item use InsertNewTool
 
229
                 * \param New new item
 
230
                 * \param Parent item which will become parent of New
 
231
                 * \param Position position inside Parent (if <0 or  out of range,
 
232
                 *        appending New at the end of Parent's children)
 
233
                 */
 
234
        bool InsertNew(wxsItem* New,wxsParent* Parent,int Position);
 
235
 
 
236
        /** \brief Adding new tool
 
237
         *
 
238
         * This function adds new tool into this resource.
 
239
         * Since tools require special threatment, they
 
240
         * need separate function.
 
241
         * \param Tool new tool
 
242
         * \return true on success, false otherwise
 
243
         */
 
244
        bool InsertNewTool(wxsTool* Tool);
 
245
 
 
246
        /** \brief Deleting all selected items */
 
247
        void DeleteSelected();
 
248
 
 
249
        /** \brief Getting number of tools */
 
250
        inline int GetToolsCount() { return (int)m_Tools.Count(); }
 
251
 
 
252
        /** \brief Getting tool at given index */
 
253
        inline wxsTool* GetTool(int Index) { return ((Index>=0)&&(Index<GetToolsCount())) ? m_Tools[Index] : 0; }
 
254
 
 
255
        /* ******************* */
 
256
        /*  Preview functions  */
 
257
        /* ******************* */
 
258
 
 
259
        /** \brief Checking if there's preview already */
 
260
        inline bool IsPreview() { return m_Preview!=0; }
 
261
 
 
262
        /** \brief Showing preview of current resource content */
 
263
        bool ShowPreview();
 
264
 
 
265
        /** \brief Closing window with current resource content */
 
266
        bool HidePreview();
 
267
 
 
268
        /** \brief Function notifying that preview has been closed externally */
 
269
        inline void NotifyPreviewClosed() { m_Preview = 0; }
 
270
 
 
271
        /* *********************** */
 
272
        /*  Notification handlers  */
 
273
        /* *********************** */
 
274
 
 
275
        /** \brief Notification of change of data
 
276
         *
 
277
         * This function is called from wxsItem objects
 
278
         * notifying about change of such item.
 
279
         */
 
280
        void NotifyChange(wxsItem* Changed);
 
281
 
 
282
    private:
 
283
 
 
284
        WX_DECLARE_STRING_HASH_MAP(TiXmlElement*,IdToXmlMapT);
 
285
        WX_DECLARE_HASH_MAP(wxsItem*,wxsResourceItemId,wxPointerHash,wxPointerEqual,ItemToIdMapT);
 
286
        WX_DEFINE_ARRAY(wxsTool*,ToolArrayT);
 
287
 
 
288
        /** \brief Generating string with xml data for this item
 
289
         *  \note used when creating undo enteries
 
290
         */
 
291
        wxString GetXmlData();
 
292
 
 
293
        /** \brief Restoring resource data from string with xml data */
 
294
        bool SetXmlData(const wxString& XmlData);
 
295
 
 
296
        /** \brief Rebuilding all files kept up-to-date after change in resource */
 
297
        void RebuildFiles();
 
298
 
 
299
        /** \brief Rebuilding sources for this resource */
 
300
        void RebuildSourceCode();
 
301
 
 
302
        /** \brief Rebuilding XRC file managed by this resource */
 
303
        bool RebuildXrcFile();
 
304
 
 
305
        // Various loading functinos
 
306
        bool SilentLoad();
 
307
        bool LoadInFileMode();
 
308
        bool LoadInMixedMode();
 
309
        bool LoadInSourceMode();
 
310
        void UpdateExtraDataReq(wxsItem* Item,IdToXmlMapT& Map);
 
311
        void RecreateRootItem();
 
312
        void LoadToolsReq(TiXmlElement* Node,bool IsXRC,bool IsExtra);
 
313
 
 
314
        // Various saving function
 
315
        bool SaveInFileMode();
 
316
        bool SaveInMixedMode();
 
317
        bool SaveInSourceMode();
 
318
        void SaveExtraDataReq(wxsItem* Item,TiXmlElement* Node);
 
319
 
 
320
        // Some misc functions
 
321
        inline void StoreUndo() { m_Undo.StoreChange(GetXmlData()); }
 
322
        bool ValidateRootSelection();
 
323
        bool ValidateRootSelectionReq(wxsItem* Item,wxsItem*& NewSelection);
 
324
        void CopyReq(wxsItem* Item,wxsItemResDataObject* Data);
 
325
        bool AnySelectedReq(wxsItem* Item);
 
326
        void StoreTreeExpandState();
 
327
        void StoreTreeExpandStateReq(wxsItem* Item);
 
328
        void RestoreTreeExpandAndSelectionState();
 
329
        void RestoreTreeExpandAndSelectionStateReq(wxsItem* Item);
 
330
        void DeleteSelectedReq(wxsItem* Item);
 
331
        void RebuildTree();
 
332
        void StoreTreeIds();
 
333
        void StoreTreeIdsReq(wxsItem* Item);
 
334
        bool FindId(wxsResourceItemId& Id,wxsItem* Item);
 
335
        void DetectAutoCodeBlocks();
 
336
 
 
337
        // Functions used by RebuildSourceCode
 
338
        wxString DeclarationsCode(wxsCoderContext* Ctx);
 
339
        wxString IdentifiersCode(wxsCoderContext* Ctx);
 
340
        wxString InitializeCode(wxsCoderContext* Ctx);
 
341
        wxString IdInitCode(wxsCoderContext* Ctx);
 
342
        wxString HeadersCode(wxsCoderContext* Ctx);
 
343
        wxString HeadersNoPCHCode(wxsCoderContext* Ctx);
 
344
        wxString HeadersAllCode(wxsCoderContext* Ctx);
 
345
        wxString InternalHeadersCode(wxsCoderContext* Ctx);
 
346
        wxString InternalHeadersNoPCHCode(wxsCoderContext* Ctx);
 
347
        wxString InternalHeadersAllCode(wxsCoderContext* Ctx);
 
348
        wxString XRCLoadingCode();
 
349
 
 
350
        // Wrappers to m_Functions functionality
 
351
        inline wxWindow* BuildExactPreview(wxWindow* Parent) { return m_Functions->OnBuildExactPreview(Parent,this); }
 
352
 
 
353
        wxString m_WxsFileName;
 
354
        wxString m_SrcFileName;
 
355
        wxString m_HdrFileName;
 
356
        wxString m_XrcFileName;
 
357
        wxString m_ClassName;
 
358
        wxString m_ClassType;
 
359
        wxsCodingLang m_Language;
 
360
        wxsResourceItemId m_TreeId;
 
361
        wxsResourceItemId m_ToolsId;
 
362
        bool m_ToolsNodeIsExpanded;
 
363
        ItemToIdMapT m_IdMap;
 
364
        wxsItemEditor* m_Editor;
 
365
        wxsItemResFunctions* m_Functions;
 
366
 
 
367
        wxsItem* m_RootItem;
 
368
        wxsItem* m_RootSelection;
 
369
        ToolArrayT m_Tools;
 
370
        long m_PropertiesFilter;
 
371
 
 
372
        wxWindow* m_Preview;
 
373
 
 
374
        wxsItemUndoBuffer m_Undo;
 
375
        wxsCorrector m_Corrector;
 
376
 
 
377
        bool m_IsOK;
 
378
        bool m_IsEventTable;
 
379
        int m_LockCount;
 
380
 
 
381
        bool m_ReadOnly;
 
382
};
 
383
 
 
384
#endif