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: wxsresourcefactory.cpp 4850 2008-01-29 21:45:49Z byo $
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/wxsresourcefactory.cpp $
23
#include "wxsresourcefactory.h"
25
// TODO: Support dynamic loading / unloading of factories
27
wxsResourceFactory* wxsResourceFactory::m_UpdateQueue = 0;
28
wxsResourceFactory* wxsResourceFactory::m_Initialized = 0;
29
wxsResourceFactory::HashT wxsResourceFactory::m_Hash;
30
wxString wxsResourceFactory::m_LastExternalName;
31
wxsResourceFactory* wxsResourceFactory::m_LastExternalFactory = 0;
32
bool wxsResourceFactory::m_AllAttached = false;
34
wxsResourceFactory::wxsResourceFactory()
36
m_Next = m_UpdateQueue;
41
wxsResourceFactory::~wxsResourceFactory()
45
void wxsResourceFactory::InitializeFromQueue()
47
while ( m_UpdateQueue )
49
wxsResourceFactory* NextFactory = m_UpdateQueue->m_Next;
50
m_UpdateQueue->Initialize();
51
m_UpdateQueue = NextFactory;
55
inline void wxsResourceFactory::Initialize()
57
for ( int i=OnGetCount(); i-->0; )
61
OnGetInfo(i,Name,GUI);
62
ResourceInfo& Info = m_Hash[Name];
63
Info.m_Factory = this;
66
if ( Info.m_MenuId < 0 )
68
Info.m_MenuId = wxNewId();
72
m_Next = m_Initialized;
82
wxsResource* wxsResourceFactory::Build(const wxString& ResourceType,wxsProject* Project)
84
InitializeFromQueue();
85
ResourceInfo& Info = m_Hash[ResourceType];
86
if ( !Info.m_Factory )
90
return Info.m_Factory->OnCreate(Info.m_Number,Project);
93
bool wxsResourceFactory::CanHandleExternal(const wxString& FileName)
95
InitializeFromQueue();
96
for ( wxsResourceFactory* Factory = m_Initialized; Factory; Factory=Factory->m_Next )
98
if ( Factory->OnCanHandleExternal(FileName) )
100
m_LastExternalName = FileName;
101
m_LastExternalFactory = Factory;
105
m_LastExternalName = wxEmptyString;
106
m_LastExternalFactory = 0;
110
wxsResource* wxsResourceFactory::BuildExternal(const wxString& FileName)
112
InitializeFromQueue();
113
if ( m_LastExternalFactory && (m_LastExternalName==FileName) )
115
return m_LastExternalFactory->OnBuildExternal(FileName);
117
for ( wxsResourceFactory* Factory = m_Initialized; Factory; Factory=Factory->m_Next )
119
wxsResource* Res = Factory->OnBuildExternal(FileName);
120
if ( Res ) return Res;
125
void wxsResourceFactory::BuildSmithMenu(wxMenu* menu)
127
InitializeFromQueue();
128
for ( HashT::iterator i=m_Hash.begin(); i!=m_Hash.end(); ++i )
130
if ( i->second.m_Factory == 0 ) continue;
131
wxString MenuEntry = _T("Add ") + i->first;
132
menu->Append(i->second.m_MenuId,MenuEntry);
136
bool wxsResourceFactory::NewResourceMenu(int Id,wxsProject* Project)
138
for ( HashT::iterator i=m_Hash.begin(); i!=m_Hash.end(); ++i )
140
if ( i->second.m_Factory == 0 ) continue;
141
if ( i->second.m_MenuId == Id )
143
return i->second.m_Factory->OnNewWizard(i->second.m_Number,Project);
149
int wxsResourceFactory::ResourceTreeIcon(const wxString& ResourceType)
151
InitializeFromQueue();
152
ResourceInfo& Info = m_Hash[ResourceType];
153
if ( !Info.m_Factory )
157
return Info.m_Factory->OnResourceTreeIcon(Info.m_Number);
160
void wxsResourceFactory::OnAttachAll()
162
if ( m_AllAttached ) return;
163
InitializeFromQueue();
164
for ( wxsResourceFactory* Factory = m_Initialized; Factory; Factory = Factory->m_Next )
166
if ( !Factory->m_Attached )
169
Factory->m_Attached = true;
172
m_AllAttached = true;
175
void wxsResourceFactory::OnReleaseAll()
177
if ( !m_AllAttached ) return;
178
InitializeFromQueue();
179
for ( wxsResourceFactory* Factory = m_Initialized; Factory; Factory = Factory->m_Next )
181
if ( Factory->m_Attached )
183
Factory->OnRelease();
184
Factory->m_Attached = false;
187
m_AllAttached = false;