~ubuntu-branches/ubuntu/oneiric/codeblocks/oneiric

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/wxwidgets/wxsparent.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: 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 $
 
21
*/
 
22
 
 
23
#ifndef WXSPARENT_H
 
24
#define WXSPARENT_H
 
25
 
 
26
#include "wxsitem.h"
 
27
 
 
28
/** \brief This class represents widget with child items
 
29
 *
 
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.
 
35
 *
 
36
 */
 
37
class wxsParent: public wxsItem
 
38
{
 
39
    public:
 
40
 
 
41
        /** \brief Ctor */
 
42
        wxsParent(wxsItemResData* Data,const wxsItemInfo* Info,long PropertiesFlags,const wxsEventDesc* Events,const wxsStyleSet* StyleSet);
 
43
 
 
44
        /** \brief Dctor */
 
45
        virtual ~wxsParent();
 
46
 
 
47
        /** \brief Getting number of children */
 
48
        inline int GetChildCount() { return (int)Children.Count(); }
 
49
 
 
50
        /** \brief Getting child at specified index */
 
51
        wxsItem* GetChild(int Index);
 
52
 
 
53
        /** \brief Adding new child item */
 
54
        bool AddChild(wxsItem* Child,int Position=-1);
 
55
 
 
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.
 
59
         */
 
60
        void UnbindChild(int Index);
 
61
 
 
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.
 
65
         */
 
66
        void UnbindChild(wxsItem* Child);
 
67
 
 
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.
 
73
         */
 
74
        int MoveChild(int OldIndex,int NewIndex);
 
75
 
 
76
        /** \brief Getting child index
 
77
         *  \return index of child or -1 if there's no such child
 
78
         */
 
79
        int GetChildIndex(wxsItem* Child);
 
80
 
 
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.
 
85
         */
 
86
        bool IsGrandChild(wxsItem* Child,bool Safe=false);
 
87
 
 
88
        /** \brief Function storing extra info for child in xml node */
 
89
        void StoreExtraData(int Index,TiXmlElement* Element);
 
90
 
 
91
        /** \brief Function setting up child's extra data from xml node */
 
92
        void RestoreExtraData(int Index,TiXmlElement* Element);
 
93
 
 
94
        /** \brief Function getting extra data for given child */
 
95
        wxsPropertyContainer* GetChildExtra(int Index);
 
96
 
 
97
        /** \brief Function checking if given item can be added to this one
 
98
         * \note This is only a wrapper to OnCanAddChild virtual function
 
99
         */
 
100
        inline bool CanAddChild(wxsItem* Item,bool ShowMessage) { return OnCanAddChild(Item,ShowMessage); }
 
101
 
 
102
        /** \brief Function checking if given child is visible in editor
 
103
         * \note This function is only a wrapper to OnIsChildPreviewVisible
 
104
         */
 
105
        inline bool IsChildPreviewVisible(wxsItem* Child) { return OnIsChildPreviewVisible(Child); }
 
106
 
 
107
        /** \brief Ensuring that child item is visible in preview
 
108
         * \note This is only a wrapper to OnEnsureChildPreviewVisible
 
109
         */
 
110
        inline bool EnsureChildPreviewVisible(wxsItem* Child) { return OnEnsureChildPreviewVisible(Child); }
 
111
 
 
112
    protected:
 
113
 
 
114
        /* *********************************************************************** */
 
115
        /*  Followig functions may be used to easy create wxsParent-derived class  */
 
116
        /* *********************************************************************** */
 
117
 
 
118
        /** \brief Function building extra data block for item
 
119
         *
 
120
         * This function may be overridden in child classes to add extra
 
121
         * configuration for each child, f.ex. configuration of sizer enteries.
 
122
         */
 
123
        virtual wxsPropertyContainer* OnBuildExtra() { return 0; }
 
124
 
 
125
        /** \brief Returning name of additional object created for child items
 
126
         *
 
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.
 
131
         */
 
132
        virtual wxString OnXmlGetExtraObjectClass() { return wxEmptyString; }
 
133
 
 
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
 
138
         */
 
139
        virtual bool OnCanAddChild(wxsItem* Item,bool ShowMessage) { return true; }
 
140
 
 
141
        /** \brief Function adding panels for child to wxsAdvQPP class
 
142
         *
 
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.
 
146
         */
 
147
        virtual void OnAddChildQPP(wxsItem* Child,wxsAdvQPP* QPP);
 
148
 
 
149
        /* **************************************************************** */
 
150
        /*  Following functions may be also overridden but it shouldn't be  */
 
151
        /*  necessarry                                                      */
 
152
        /* **************************************************************** */
 
153
 
 
154
        /** \brief Function enumerating properties for given child
 
155
         *
 
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
 
159
         * child item.
 
160
         *
 
161
         * Default implementation calls Child->EnumItemProperties(Flags)
 
162
         * and Extra->EnumProperties at the end.
 
163
         *
 
164
         * \note This function MUST call Child->EnumItemProperties(Flags)
 
165
         *       somewhere in the code.
 
166
         */
 
167
        void OnEnumChildProperties(wxsItem* Child,long Flags);
 
168
 
 
169
        /** \brief Rewritten xml reading function - it will add support for children loading */
 
170
        virtual bool OnXmlRead(TiXmlElement* Element,bool IsXRC,bool IsExtra);
 
171
 
 
172
        /** \brief Rewritten xml writing function - it will add support for children saving */
 
173
        virtual bool OnXmlWrite(TiXmlElement* Element,bool IsXRC,bool IsExtra);
 
174
 
 
175
        /** \brief Function loading child from given xml node
 
176
         *
 
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
 
181
         * additional data.
 
182
         */
 
183
        virtual bool OnXmlReadChild(TiXmlElement* Elem,bool IsXRC,bool IsExtra);
 
184
 
 
185
        /** \brief Function saving child to goven xml node
 
186
         *
 
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.
 
190
         */
 
191
        virtual bool OnXmlWriteChild(int Index,TiXmlElement* Elem,bool IsXRC,bool IsExtra);
 
192
 
 
193
        /** \brief Function checking if given child preview is visible in editor
 
194
         *
 
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
 
197
         * inside editor
 
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
 
201
         */
 
202
        virtual bool OnIsChildPreviewVisible(wxsItem* Child) { return true; }
 
203
 
 
204
        /** \brief Function ensuring that given child of this item is visible inside editor
 
205
         *
 
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
 
211
         */
 
212
        virtual bool OnEnsureChildPreviewVisible(wxsItem* Child) { return false; }
 
213
 
 
214
    private:
 
215
 
 
216
        /** \brief Function converting this item to wxsParent class.
 
217
         *
 
218
         * Function is private to make sure that no child classes will
 
219
         * overload it.
 
220
         */
 
221
        virtual wxsParent* ConvertToParent() { return this; }
 
222
 
 
223
        WX_DEFINE_ARRAY(wxsItem*,wxArrayItem);
 
224
        WX_DEFINE_ARRAY(wxsPropertyContainer*,wxArrayExtra);
 
225
 
 
226
        wxArrayItem  Children;   ///< \brief Array of child items
 
227
        wxArrayExtra Extra;      ///< \brief Array of extra data stored in generic void pointer
 
228
 
 
229
        friend class wxsItem;
 
230
};
 
231
 
 
232
#endif