2
* This file is part of wxSmith plugin for Code::Blocks Studio
3
* Copyright (C) 2006-2007 Bartlomiej Swiecki
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.
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.
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/>.
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 $
23
#ifndef WXSITEMRESDATA_H
24
#define WXSITEMRESDATA_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"
37
/** \brief Class holding data for item resources and operating on it */
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.
51
* Parameters passed to constructor are GLOBAL paths (opposite to
52
* wxsItemRes where names are relative to .cbp's directory).
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
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.
74
virtual ~wxsItemResData();
76
/** \brief Loading resource
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
85
/** \brief Saving resource
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)
93
/** \brief Checking if resource was loaded properly
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.
99
inline bool IsOk() { return m_IsOK; }
101
/** \brief Function starting change of resource data
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.
110
* Change of resource is any operation made on any wxsItem
111
* class inside the resource (including the root class).
115
/** \brief Function ending change of resource data
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.
124
/** \brief Checking if item has modified state */
125
inline bool GetModified() { return m_Undo.IsModified(); }
127
/** \brief Getting root item
128
* \return pointer to item on success, 0 when data wasn't initialized properly
130
inline wxsItem* GetRootItem() { return m_RootItem; }
132
/** \brief Getting main item of selection */
133
inline wxsItem* GetRootSelection() { return m_RootSelection; }
135
/** \brief Getting properties filter based on current edit mode */
136
inline int GetPropertiesFilter() { return m_PropertiesFilter; }
138
/** \brief Getting name of wxs file (global path) */
139
inline const wxString& GetWxsFileName() { return m_SrcFileName; }
141
/** \brief Getting name of source file (global path) */
142
inline const wxString& GetSrcFileName() { return m_SrcFileName; }
144
/** \brief Getting name of header file (global path) */
145
inline const wxString& GetHdrFileName() { return m_HdrFileName; }
147
/** \brief Getting name of XRC file (global path) */
148
inline const wxString& GetXrcFileName() { return m_XrcFileName; }
150
/** \brief Getting name of class of edited resource */
151
inline const wxString& GetClassName() { return m_ClassName; }
153
/** \brief Getting name class used as base for this resource (like wxDialog) */
154
inline const wxString& GetClassType() { return m_ClassType; }
156
/** \brief Getting language used in resource */
157
inline wxsCodingLang GetLanguage() { return m_Language; }
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); }
162
/** \brief Showing popup menu from given item */
163
inline wxsItemEditor* GetEditor() { return m_Editor; }
165
/* ************************ */
166
/* Undo buffer operations */
167
/* ************************ */
169
/** \brief Checking if can Undo */
170
inline bool CanUndo() { return m_Undo.CanUndo(); }
172
/** \brief Ckecing if can Redo */
173
inline bool CanRedo() { return m_Undo.CanRedo(); }
175
/** \brief Undoing */
176
inline void Undo() { SetXmlData(m_Undo.Undo()); }
178
/** \brief Redoing */
179
inline void Redo() { SetXmlData(m_Undo.Redo()); }
181
/** \brief Checking if current content is read only */
182
inline bool IsReadOnly() { return m_ReadOnly; }
184
/* ********************** */
185
/* Clipboard operations */
186
/* ********************** */
188
/** \brief Checking if we can paste current clipboard content */
191
/** \brief Cutting current selection to clipboard */
194
/** \brief Copying current selectin to clipboard */
197
/** \brief Pasting components from clipboard
198
* \param Parent parent for new items
199
* \param Position initial position for new items
201
void Paste(wxsParent* Parent,int Position);
204
/* ********************** */
205
/* Selection operations */
206
/* ********************** */
208
/** \brief Checking of there's any selection */
211
/** \brief Selecting one item */
212
bool SelectItem(wxsItem* Item,bool UnselectOther);
214
/** \brief Getting last selected item or 0 if there's no valid selection */
215
inline wxsItem* GetLastSelection() { return m_RootSelection; }
217
/* ******************* */
218
/* Operating on data */
219
/* ******************* */
221
/** \brief Adding new item
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)
234
bool InsertNew(wxsItem* New,wxsParent* Parent,int Position);
236
/** \brief Adding new tool
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
244
bool InsertNewTool(wxsTool* Tool);
246
/** \brief Deleting all selected items */
247
void DeleteSelected();
249
/** \brief Getting number of tools */
250
inline int GetToolsCount() { return (int)m_Tools.Count(); }
252
/** \brief Getting tool at given index */
253
inline wxsTool* GetTool(int Index) { return ((Index>=0)&&(Index<GetToolsCount())) ? m_Tools[Index] : 0; }
255
/* ******************* */
256
/* Preview functions */
257
/* ******************* */
259
/** \brief Checking if there's preview already */
260
inline bool IsPreview() { return m_Preview!=0; }
262
/** \brief Showing preview of current resource content */
265
/** \brief Closing window with current resource content */
268
/** \brief Function notifying that preview has been closed externally */
269
inline void NotifyPreviewClosed() { m_Preview = 0; }
271
/* *********************** */
272
/* Notification handlers */
273
/* *********************** */
275
/** \brief Notification of change of data
277
* This function is called from wxsItem objects
278
* notifying about change of such item.
280
void NotifyChange(wxsItem* Changed);
284
WX_DECLARE_STRING_HASH_MAP(TiXmlElement*,IdToXmlMapT);
285
WX_DECLARE_HASH_MAP(wxsItem*,wxsResourceItemId,wxPointerHash,wxPointerEqual,ItemToIdMapT);
286
WX_DEFINE_ARRAY(wxsTool*,ToolArrayT);
288
/** \brief Generating string with xml data for this item
289
* \note used when creating undo enteries
291
wxString GetXmlData();
293
/** \brief Restoring resource data from string with xml data */
294
bool SetXmlData(const wxString& XmlData);
296
/** \brief Rebuilding all files kept up-to-date after change in resource */
299
/** \brief Rebuilding sources for this resource */
300
void RebuildSourceCode();
302
/** \brief Rebuilding XRC file managed by this resource */
303
bool RebuildXrcFile();
305
// Various loading functinos
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);
314
// Various saving function
315
bool SaveInFileMode();
316
bool SaveInMixedMode();
317
bool SaveInSourceMode();
318
void SaveExtraDataReq(wxsItem* Item,TiXmlElement* Node);
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);
333
void StoreTreeIdsReq(wxsItem* Item);
334
bool FindId(wxsResourceItemId& Id,wxsItem* Item);
335
void DetectAutoCodeBlocks();
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();
350
// Wrappers to m_Functions functionality
351
inline wxWindow* BuildExactPreview(wxWindow* Parent) { return m_Functions->OnBuildExactPreview(Parent,this); }
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;
368
wxsItem* m_RootSelection;
370
long m_PropertiesFilter;
374
wxsItemUndoBuffer m_Undo;
375
wxsCorrector m_Corrector;