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: 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 $
23
#include "wxspropertygridmanager.h"
24
#include "wxspropertycontainer.h"
27
#include <logmanager.h>
29
IMPLEMENT_CLASS(wxsPropertyGridManager,wxPropertyGridManager)
31
wxsPropertyGridManager::wxsPropertyGridManager(
38
wxPropertyGridManager(parent,id,pos,size,style,name),
45
wxsPropertyGridManager::~wxsPropertyGridManager()
51
PGContainersSet.clear();
52
for ( size_t i=0; i<GetPageCount(); i++ )
58
if ( Singleton == this )
62
DeleteTemporaryPropertiesList();
65
void wxsPropertyGridManager::OnChange(wxPropertyGridEvent& event)
67
wxPGId ID = event.GetProperty();
68
for ( size_t i = PGIDs.Count(); i-- > 0; )
72
wxsPropertyContainer* Container = PGContainers[i];
73
if ( !PGEnteries[i]->PGRead(Container,this,ID,PGIndexes[i]) )
75
Manager::Get()->GetLogManager()->DebugLogError(
76
_T("wxSmith: Couldn't read value from wxsPropertyGridManager"));
79
// Notifying about property change
80
Container->NotifyPropertyChangeFromPropertyGrid();
82
// Notifying about sub property change
83
if ( Container!=MainContainer && MainContainer!=0 )
85
MainContainer->OnSubPropertyChanged(Container);
92
// Did not found changed id, it's time to say to container
93
MainContainer->OnExtraPropertyChanged(this,ID);
96
void wxsPropertyGridManager::Update(wxsPropertyContainer* PC)
98
if ( PC && PGContainersSet.find(PC) == PGContainersSet.end() )
100
// This container is not used here
104
for ( size_t i = PGIDs.Count(); i-- > 0; )
106
PGEnteries[i]->PGWrite(PGContainers[i],this,PGIDs[i],PGIndexes[i]);
110
void wxsPropertyGridManager::UnbindAll()
112
// TODO: Remove all extra pages, leave only first one
116
PGContainers.Clear();
117
PGContainersSet.clear();
118
for ( size_t i=0; i<GetPageCount(); i++ )
123
PreviousProperty = 0;
124
SetNewMainContainer(0);
127
void wxsPropertyGridManager::UnbindPropertyContainer(wxsPropertyContainer* PC)
129
if ( PGContainersSet.find(PC) == PGContainersSet.end() )
131
// This container is not used here
135
if ( PC == MainContainer )
137
// Main container unbinds all
143
for ( size_t i = PGIDs.Count(); i-- > 0; )
145
if ( PGContainers[i] == PC )
149
PGEnteries.RemoveAt(i);
150
PGIndexes.RemoveAt(i);
151
PGContainers.RemoveAt(i);
156
// If there are no properties, we have unbinded main property container
157
if ( !PGIDs.Count() )
159
for ( size_t i=0; i<GetPageCount(); i++ )
163
SetNewMainContainer(0);
167
long wxsPropertyGridManager::Register(wxsPropertyContainer* Container,wxsProperty* Property,wxPGId Id,long Index)
169
if ( !Property ) return -1;
171
if ( Property != PreviousProperty )
178
Index = ++PreviousIndex;
181
PGEnteries.Add(Property);
183
PGIndexes.Add(Index);
184
PGContainers.Add(Container);
185
PGContainersSet.insert(Container);
189
void wxsPropertyGridManager::NewPropertyContainerStart()
192
DeleteTemporaryPropertiesList();
195
void wxsPropertyGridManager::NewPropertyContainerAddProperty(wxsProperty* Property,wxsPropertyContainer* Container)
197
TemporaryPropertiesList* NewItem = new TemporaryPropertiesList;
198
NewItem->Property = Property;
199
NewItem->Container = Container;
200
NewItem->Priority = Property->GetPriority();
201
int Priority = NewItem->Priority;
203
TemporaryPropertiesList *Prev = 0, *Search;
204
for ( Search = PropertiesList; Search && Search->Property->GetPriority() >= Priority; Prev = Search, Search = Search->Next );
206
NewItem->Next = Search;
207
( Prev ? Prev->Next : PropertiesList ) = NewItem;
210
void wxsPropertyGridManager::NewPropertyContainerFinish(wxsPropertyContainer* Container)
214
while ( PropertiesList )
216
TemporaryPropertiesList* Next = PropertiesList->Next;
217
PropertiesList->Property->PGCreate(PropertiesList->Container,this,GetRoot());
218
delete PropertiesList;
219
PropertiesList = Next;
222
SetNewMainContainer(Container);
225
void wxsPropertyGridManager::SetNewMainContainer(wxsPropertyContainer* Container)
227
MainContainer = Container;
228
OnContainerChanged(MainContainer);
231
void wxsPropertyGridManager::DeleteTemporaryPropertiesList()
233
while ( PropertiesList )
235
TemporaryPropertiesList* Next = PropertiesList->Next;
236
delete PropertiesList;
237
PropertiesList = Next;
241
void wxsPropertyGridManager::StoreSelected(SelectionData* Data)
245
Data = &LastSelection;
248
Data->m_PageIndex = GetSelectedPage();
250
wxPGId Selected = GetSelectedProperty();
251
if ( wxPGIdIsOk(Selected) )
253
Data->m_PropertyName = GetPropertyName(Selected);
257
Data->m_PropertyName.Clear();
261
void wxsPropertyGridManager::RestoreSelected(const SelectionData* Data)
265
Data = &LastSelection;
268
if ( Data->m_PageIndex < 0 ) return;
269
if ( Data->m_PageIndex >= (int)GetPageCount() ) return;
270
if ( Data->m_PropertyName.IsEmpty() ) return;
272
SelectPage(Data->m_PageIndex);
273
SelectProperty(Data->m_PropertyName);
277
wxsPropertyGridManager* wxsPropertyGridManager::Singleton = 0;
279
BEGIN_EVENT_TABLE(wxsPropertyGridManager,wxPropertyGridManager)
280
EVT_PG_CHANGED(-1,wxsPropertyGridManager::OnChange)