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

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/properties/wxspropertygridmanager.cpp

  • 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: wxspropertygridmanager.cpp 4850 2008-01-29 21:45:49Z byo $
 
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/properties/wxspropertygridmanager.cpp $
 
21
*/
 
22
 
 
23
#include "wxspropertygridmanager.h"
 
24
#include "wxspropertycontainer.h"
 
25
 
 
26
#include <manager.h>
 
27
#include <logmanager.h>
 
28
 
 
29
IMPLEMENT_CLASS(wxsPropertyGridManager,wxPropertyGridManager)
 
30
 
 
31
wxsPropertyGridManager::wxsPropertyGridManager(
 
32
    wxWindow* parent,
 
33
    wxWindowID id,
 
34
    const wxPoint& pos,
 
35
    const wxSize& size,
 
36
    long style,
 
37
    const wxChar* name):
 
38
        wxPropertyGridManager(parent,id,pos,size,style,name),
 
39
        MainContainer(0)
 
40
{
 
41
    Singleton = this;
 
42
    PropertiesList = 0;
 
43
}
 
44
 
 
45
wxsPropertyGridManager::~wxsPropertyGridManager()
 
46
{
 
47
    PGIDs.Clear();
 
48
    PGEnteries.Clear();
 
49
    PGIndexes.Clear();
 
50
    PGContainers.Clear();
 
51
    PGContainersSet.clear();
 
52
    for ( size_t i=0; i<GetPageCount(); i++ )
 
53
    {
 
54
        ClearPage(i);
 
55
    }
 
56
    PreviousIndex = -1;
 
57
    PreviousProperty = 0;
 
58
    if ( Singleton == this )
 
59
    {
 
60
        Singleton = 0;
 
61
    }
 
62
    DeleteTemporaryPropertiesList();
 
63
}
 
64
 
 
65
void wxsPropertyGridManager::OnChange(wxPropertyGridEvent& event)
 
66
{
 
67
    wxPGId ID = event.GetProperty();
 
68
    for ( size_t i = PGIDs.Count(); i-- > 0; )
 
69
    {
 
70
        if ( PGIDs[i] == ID )
 
71
        {
 
72
            wxsPropertyContainer* Container = PGContainers[i];
 
73
            if ( !PGEnteries[i]->PGRead(Container,this,ID,PGIndexes[i]) )
 
74
            {
 
75
                Manager::Get()->GetLogManager()->DebugLogError(
 
76
                    _T("wxSmith: Couldn't read value from wxsPropertyGridManager"));
 
77
            }
 
78
 
 
79
            // Notifying about property change
 
80
            Container->NotifyPropertyChangeFromPropertyGrid();
 
81
 
 
82
            // Notifying about sub property change
 
83
            if ( Container!=MainContainer && MainContainer!=0 )
 
84
            {
 
85
                MainContainer->OnSubPropertyChanged(Container);
 
86
            }
 
87
            Update(0);
 
88
            return;
 
89
        }
 
90
    }
 
91
 
 
92
    // Did not found changed id, it's time to say to container
 
93
    MainContainer->OnExtraPropertyChanged(this,ID);
 
94
}
 
95
 
 
96
void wxsPropertyGridManager::Update(wxsPropertyContainer* PC)
 
97
{
 
98
    if ( PC && PGContainersSet.find(PC) == PGContainersSet.end() )
 
99
    {
 
100
        // This container is not used here
 
101
        return;
 
102
    }
 
103
 
 
104
    for ( size_t i = PGIDs.Count(); i-- > 0; )
 
105
    {
 
106
        PGEnteries[i]->PGWrite(PGContainers[i],this,PGIDs[i],PGIndexes[i]);
 
107
    }
 
108
}
 
109
 
 
110
void wxsPropertyGridManager::UnbindAll()
 
111
{
 
112
    // TODO: Remove all extra pages, leave only first one
 
113
    PGIDs.Clear();
 
114
    PGEnteries.Clear();
 
115
    PGIndexes.Clear();
 
116
    PGContainers.Clear();
 
117
    PGContainersSet.clear();
 
118
    for ( size_t i=0; i<GetPageCount(); i++ )
 
119
    {
 
120
        ClearPage(i);
 
121
    }
 
122
    PreviousIndex = -1;
 
123
    PreviousProperty = 0;
 
124
    SetNewMainContainer(0);
 
125
}
 
126
 
 
127
void wxsPropertyGridManager::UnbindPropertyContainer(wxsPropertyContainer* PC)
 
128
{
 
129
    if ( PGContainersSet.find(PC) == PGContainersSet.end() )
 
130
    {
 
131
        // This container is not used here
 
132
        return;
 
133
    }
 
134
 
 
135
    if ( PC == MainContainer )
 
136
    {
 
137
        // Main container unbinds all
 
138
        UnbindAll();
 
139
        return;
 
140
    }
 
141
 
 
142
    Freeze();
 
143
    for ( size_t i = PGIDs.Count(); i-- > 0; )
 
144
    {
 
145
        if ( PGContainers[i] == PC )
 
146
        {
 
147
            Delete(PGIDs[i]);
 
148
            PGIDs.RemoveAt(i);
 
149
            PGEnteries.RemoveAt(i);
 
150
            PGIndexes.RemoveAt(i);
 
151
            PGContainers.RemoveAt(i);
 
152
        }
 
153
    }
 
154
    Thaw();
 
155
 
 
156
    // If there are no properties, we have unbinded main property container
 
157
    if ( !PGIDs.Count() )
 
158
    {
 
159
        for ( size_t i=0; i<GetPageCount(); i++ )
 
160
        {
 
161
            ClearPage(i);
 
162
        }
 
163
        SetNewMainContainer(0);
 
164
    }
 
165
}
 
166
 
 
167
long wxsPropertyGridManager::Register(wxsPropertyContainer* Container,wxsProperty* Property,wxPGId Id,long Index)
 
168
{
 
169
    if ( !Property ) return -1;
 
170
 
 
171
    if ( Property != PreviousProperty )
 
172
    {
 
173
        PreviousIndex = -1;
 
174
    }
 
175
 
 
176
    if ( Index < 0 )
 
177
    {
 
178
        Index = ++PreviousIndex;
 
179
    }
 
180
 
 
181
    PGEnteries.Add(Property);
 
182
    PGIDs.Add(Id);
 
183
    PGIndexes.Add(Index);
 
184
    PGContainers.Add(Container);
 
185
    PGContainersSet.insert(Container);
 
186
    return Index;
 
187
}
 
188
 
 
189
void wxsPropertyGridManager::NewPropertyContainerStart()
 
190
{
 
191
    UnbindAll();
 
192
    DeleteTemporaryPropertiesList();
 
193
}
 
194
 
 
195
void wxsPropertyGridManager::NewPropertyContainerAddProperty(wxsProperty* Property,wxsPropertyContainer* Container)
 
196
{
 
197
    TemporaryPropertiesList* NewItem = new TemporaryPropertiesList;
 
198
    NewItem->Property = Property;
 
199
    NewItem->Container = Container;
 
200
    NewItem->Priority = Property->GetPriority();
 
201
    int Priority = NewItem->Priority;
 
202
 
 
203
    TemporaryPropertiesList *Prev = 0, *Search;
 
204
    for ( Search = PropertiesList; Search && Search->Property->GetPriority() >= Priority; Prev = Search, Search = Search->Next );
 
205
 
 
206
    NewItem->Next = Search;
 
207
    ( Prev ? Prev->Next : PropertiesList ) = NewItem;
 
208
}
 
209
 
 
210
void wxsPropertyGridManager::NewPropertyContainerFinish(wxsPropertyContainer* Container)
 
211
{
 
212
    SetTargetPage(0);
 
213
 
 
214
    while ( PropertiesList )
 
215
    {
 
216
        TemporaryPropertiesList* Next = PropertiesList->Next;
 
217
        PropertiesList->Property->PGCreate(PropertiesList->Container,this,GetRoot());
 
218
        delete PropertiesList;
 
219
        PropertiesList = Next;
 
220
    }
 
221
 
 
222
    SetNewMainContainer(Container);
 
223
}
 
224
 
 
225
void wxsPropertyGridManager::SetNewMainContainer(wxsPropertyContainer* Container)
 
226
{
 
227
    MainContainer = Container;
 
228
    OnContainerChanged(MainContainer);
 
229
}
 
230
 
 
231
void wxsPropertyGridManager::DeleteTemporaryPropertiesList()
 
232
{
 
233
    while ( PropertiesList )
 
234
    {
 
235
        TemporaryPropertiesList* Next = PropertiesList->Next;
 
236
        delete PropertiesList;
 
237
        PropertiesList = Next;
 
238
    }
 
239
}
 
240
 
 
241
void wxsPropertyGridManager::StoreSelected(SelectionData* Data)
 
242
{
 
243
    if ( !Data )
 
244
    {
 
245
        Data = &LastSelection;
 
246
    }
 
247
 
 
248
    Data->m_PageIndex = GetSelectedPage();
 
249
 
 
250
    wxPGId Selected = GetSelectedProperty();
 
251
    if ( wxPGIdIsOk(Selected) )
 
252
    {
 
253
        Data->m_PropertyName = GetPropertyName(Selected);
 
254
    }
 
255
    else
 
256
    {
 
257
        Data->m_PropertyName.Clear();
 
258
    }
 
259
}
 
260
 
 
261
void wxsPropertyGridManager::RestoreSelected(const SelectionData* Data)
 
262
{
 
263
    if ( !Data )
 
264
    {
 
265
        Data = &LastSelection;
 
266
    }
 
267
 
 
268
    if ( Data->m_PageIndex < 0 ) return;
 
269
    if ( Data->m_PageIndex >= (int)GetPageCount() ) return;
 
270
    if ( Data->m_PropertyName.IsEmpty() ) return;
 
271
 
 
272
    SelectPage(Data->m_PageIndex);
 
273
    SelectProperty(Data->m_PropertyName);
 
274
}
 
275
 
 
276
 
 
277
wxsPropertyGridManager* wxsPropertyGridManager::Singleton = 0;
 
278
 
 
279
BEGIN_EVENT_TABLE(wxsPropertyGridManager,wxPropertyGridManager)
 
280
    EVT_PG_CHANGED(-1,wxsPropertyGridManager::OnChange)
 
281
END_EVENT_TABLE()