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: wxsparent.h 4850 2008-01-29 21:45:49Z byo $
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/wxwidgets/wxsparent.h $
28
/** \brief This class represents widget with child items
30
* Each item may have some additional configuration stored in wxsPropertyContainer
31
* class. These informations must be created in OnBuildExtra function and can
32
* be used to keep some extra properties for each child (like configuration of item
33
* in sizer). Returned container should properly read / write items from / to
34
* xml data since this will be used.
37
class wxsParent: public wxsItem
42
wxsParent(wxsItemResData* Data,const wxsItemInfo* Info,long PropertiesFlags,const wxsEventDesc* Events,const wxsStyleSet* StyleSet);
47
/** \brief Getting number of children */
48
inline int GetChildCount() { return (int)Children.Count(); }
50
/** \brief Getting child at specified index */
51
wxsItem* GetChild(int Index);
53
/** \brief Adding new child item */
54
bool AddChild(wxsItem* Child,int Position=-1);
56
/** \brief Unbinding child item by index (0-based number of child)
57
* \note This function does not delete item but only remove the connection
58
* between item and parent.
60
void UnbindChild(int Index);
62
/** \brief Unbinding child item by pointer
63
* \note This function does not delete item but only remove the connection
64
* between item and parent.
66
void UnbindChild(wxsItem* Child);
68
/** \brief Moving item from one position to another
69
* \param OldIndex old position of item
70
* \param NewIndex new position of item
71
* \return Real positionof item after moving it (and after checking
72
* boundings) or -1, if OldIndex was invalid.
74
int MoveChild(int OldIndex,int NewIndex);
76
/** \brief Getting child index
77
* \return index of child or -1 if there's no such child
79
int GetChildIndex(wxsItem* Child);
81
/** \brief Function checking if give item is grandchild (chld or child of child or...) of this item
82
* \param Child searched child
83
* \param Safe set to true if there's no certainity that Child pointer is valid one.
84
* It will work slower but won't produse seg faults.
86
bool IsGrandChild(wxsItem* Child,bool Safe=false);
88
/** \brief Function storing extra info for child in xml node */
89
void StoreExtraData(int Index,TiXmlElement* Element);
91
/** \brief Function setting up child's extra data from xml node */
92
void RestoreExtraData(int Index,TiXmlElement* Element);
94
/** \brief Function getting extra data for given child */
95
wxsPropertyContainer* GetChildExtra(int Index);
97
/** \brief Function checking if given item can be added to this one
98
* \note This is only a wrapper to OnCanAddChild virtual function
100
inline bool CanAddChild(wxsItem* Item,bool ShowMessage) { return OnCanAddChild(Item,ShowMessage); }
102
/** \brief Function checking if given child is visible in editor
103
* \note This function is only a wrapper to OnIsChildPreviewVisible
105
inline bool IsChildPreviewVisible(wxsItem* Child) { return OnIsChildPreviewVisible(Child); }
107
/** \brief Ensuring that child item is visible in preview
108
* \note This is only a wrapper to OnEnsureChildPreviewVisible
110
inline bool EnsureChildPreviewVisible(wxsItem* Child) { return OnEnsureChildPreviewVisible(Child); }
114
/* *********************************************************************** */
115
/* Followig functions may be used to easy create wxsParent-derived class */
116
/* *********************************************************************** */
118
/** \brief Function building extra data block for item
120
* This function may be overridden in child classes to add extra
121
* configuration for each child, f.ex. configuration of sizer enteries.
123
virtual wxsPropertyContainer* OnBuildExtra() { return 0; }
125
/** \brief Returning name of additional object created for child items
127
* This function affects behaviour of standard OnXmlReadChild and OnXmlWriteChild
128
* functions. If it returns non-empty string, child items will have
129
* additional <object...> xml node created and it will use StoreExtraData and
130
* RestoreExtraData to save extra informations.
132
virtual wxString OnXmlGetExtraObjectClass() { return wxEmptyString; }
134
/** \brief Function checking if given item can be added to this one
135
* \param Item checked item
136
* \param ShowMessage if true and item can not be added, show message
137
* explaining why it can not be done
139
virtual bool OnCanAddChild(wxsItem* Item,bool ShowMessage) { return true; }
141
/** \brief Function adding panels for child to wxsAdvQPP class
143
* Analogically to EnumChildProperties, this function should create
144
* additional panels and register them inside wxsAdvQPP class and
145
* should call Child->MyAddQPP(QPP) somewhere inside.
147
virtual void OnAddChildQPP(wxsItem* Child,wxsAdvQPP* QPP);
149
/* **************************************************************** */
150
/* Following functions may be also overridden but it shouldn't be */
152
/* **************************************************************** */
154
/** \brief Function enumerating properties for given child
156
* This function should create properties for child item, it's done
157
* in parent item because of possible extra data. Parent can add
158
* here some additional properties before and/or after properties of
161
* Default implementation calls Child->EnumItemProperties(Flags)
162
* and Extra->EnumProperties at the end.
164
* \note This function MUST call Child->EnumItemProperties(Flags)
165
* somewhere in the code.
167
void OnEnumChildProperties(wxsItem* Child,long Flags);
169
/** \brief Rewritten xml reading function - it will add support for children loading */
170
virtual bool OnXmlRead(TiXmlElement* Element,bool IsXRC,bool IsExtra);
172
/** \brief Rewritten xml writing function - it will add support for children saving */
173
virtual bool OnXmlWrite(TiXmlElement* Element,bool IsXRC,bool IsExtra);
175
/** \brief Function loading child from given xml node
177
* This function will be called for each <object...> nodes inside
178
* parent. It must validate this node and add children if this can
179
* be done. By default, this function simply load new class, but some
180
* containers require extended objects (like sizeritem) to store
183
virtual bool OnXmlReadChild(TiXmlElement* Elem,bool IsXRC,bool IsExtra);
185
/** \brief Function saving child to goven xml node
187
* This function will be called for each child. Element passed
188
* as param is pointer to newly created <object...> node where
189
* child should be stored.
191
virtual bool OnXmlWriteChild(int Index,TiXmlElement* Elem,bool IsXRC,bool IsExtra);
193
/** \brief Function checking if given child preview is visible in editor
195
* This function may be used by items like wxNotebook which show only
196
* one child item. It's used to avoid operating on invisible items
198
* \note this function does not check if parent item is visible
199
* \param Child pointer to child
200
* \return true if child visible, false if not
202
virtual bool OnIsChildPreviewVisible(wxsItem* Child) { return true; }
204
/** \brief Function ensuring that given child of this item is visible inside editor
206
* This function is used to automatically switch visible child for containers
207
* like wxNotebook (only one chid is show, other are hidden) when somebody
208
* clicks on it on resource browser.
209
* \note This function does not make sure that parent is visible
210
* \return false if nothing has changed, true if preview must be refreshed
212
virtual bool OnEnsureChildPreviewVisible(wxsItem* Child) { return false; }
216
/** \brief Function converting this item to wxsParent class.
218
* Function is private to make sure that no child classes will
221
virtual wxsParent* ConvertToParent() { return this; }
223
WX_DEFINE_ARRAY(wxsItem*,wxArrayItem);
224
WX_DEFINE_ARRAY(wxsPropertyContainer*,wxArrayExtra);
226
wxArrayItem Children; ///< \brief Array of child items
227
wxArrayExtra Extra; ///< \brief Array of extra data stored in generic void pointer
229
friend class wxsItem;