update dev300-m58
[ooovba.git] / sfx2 / source / appl / module.cxx
bloba25f25c01f4caed56a5f7d94f5c0c82f0447596c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: module.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #ifndef GCC
35 #endif
37 #include <stdio.h>
38 #include <tools/rcid.h>
40 #include <cstdarg>
41 #include <sfx2/module.hxx>
42 #include <sfx2/app.hxx>
43 #include "arrdecl.hxx"
44 #include "sfxresid.hxx"
45 #include <sfx2/msgpool.hxx>
46 #include <sfx2/tbxctrl.hxx>
47 #include "stbitem.hxx"
48 #include <sfx2/mnuitem.hxx>
49 #include <sfx2/childwin.hxx>
50 #include <sfx2/mnumgr.hxx>
51 #include <sfx2/docfac.hxx>
52 #include <sfx2/objface.hxx>
53 #include <sfx2/viewfrm.hxx>
55 #define SfxModule
56 #include "sfxslots.hxx"
58 static SfxModuleArr_Impl* pModules=0;
60 class SfxModule_Impl
62 public:
64 SfxSlotPool* pSlotPool;
65 SfxTbxCtrlFactArr_Impl* pTbxCtrlFac;
66 SfxStbCtrlFactArr_Impl* pStbCtrlFac;
67 SfxMenuCtrlFactArr_Impl* pMenuCtrlFac;
68 SfxChildWinFactArr_Impl* pFactArr;
69 ImageList* pImgListSmall;
70 ImageList* pImgListBig;
71 ImageList* pImgListHiSmall;
72 ImageList* pImgListHiBig;
74 SfxModule_Impl();
75 ~SfxModule_Impl();
76 ImageList* GetImageList( ResMgr*, BOOL, BOOL bHiContrast = FALSE );
79 SfxModule_Impl::SfxModule_Impl()
80 : pSlotPool(0)
84 SfxModule_Impl::~SfxModule_Impl()
86 delete pSlotPool;
87 delete pTbxCtrlFac;
88 delete pStbCtrlFac;
89 delete pMenuCtrlFac;
90 delete pFactArr;
91 delete pImgListSmall;
92 delete pImgListBig;
93 delete pImgListHiSmall;
94 delete pImgListHiBig;
97 ImageList* SfxModule_Impl::GetImageList( ResMgr* pResMgr, BOOL bBig, BOOL bHiContrast )
99 ImageList*& rpList = bBig ? ( bHiContrast ? pImgListHiBig: pImgListBig ) :
100 ( bHiContrast ? pImgListHiSmall : pImgListSmall );
101 if ( !rpList )
103 ResId aResId( bBig ? ( bHiContrast ? RID_DEFAULTIMAGELIST_LCH : RID_DEFAULTIMAGELIST_LC ) :
104 ( bHiContrast ? RID_DEFAULTIMAGELIST_SCH : RID_DEFAULTIMAGELIST_SC ), *pResMgr );
105 aResId.SetRT( RSC_IMAGELIST );
107 DBG_ASSERT( pResMgr->IsAvailable(aResId), "No default ImageList!" );
109 if ( pResMgr->IsAvailable(aResId) )
110 rpList = new ImageList( aResId );
111 else
112 rpList = new ImageList();
115 return rpList; }
117 TYPEINIT1(SfxModule, SfxShell);
119 //=========================================================================
121 SFX_IMPL_INTERFACE(SfxModule,SfxShell,SfxResId(0))
125 //====================================================================
127 ResMgr* SfxModule::GetResMgr()
129 return pResMgr;
132 //====================================================================
134 SfxModule::SfxModule( ResMgr* pMgrP, BOOL bDummyP,
135 SfxObjectFactory* pFactoryP )
136 : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
138 Construct_Impl();
139 if ( pFactoryP )
140 pFactoryP->SetModule_Impl( this );
143 SfxModule::SfxModule( ResMgr* pMgrP, BOOL bDummyP,
144 SfxObjectFactory* pFactoryP, ... )
145 : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
147 Construct_Impl();
148 va_list pVarArgs;
149 va_start( pVarArgs, pFactoryP );
150 for ( SfxObjectFactory *pArg = pFactoryP; pArg;
151 pArg = va_arg( pVarArgs, SfxObjectFactory* ) )
152 pArg->SetModule_Impl( this );
153 va_end(pVarArgs);
156 void SfxModule::Construct_Impl()
158 if( !bDummy )
160 SfxApplication *pApp = SFX_APP();
161 SfxModuleArr_Impl& rArr = GetModules_Impl();
162 SfxModule* pPtr = (SfxModule*)this;
163 rArr.C40_INSERT( SfxModule, pPtr, rArr.Count() );
164 pImpl = new SfxModule_Impl;
165 pImpl->pSlotPool = new SfxSlotPool( &pApp->GetAppSlotPool_Impl(), pResMgr );
167 pImpl->pTbxCtrlFac=0;
168 pImpl->pStbCtrlFac=0;
169 pImpl->pMenuCtrlFac=0;
170 pImpl->pFactArr=0;
171 pImpl->pImgListSmall=0;
172 pImpl->pImgListBig=0;
173 pImpl->pImgListHiSmall=0;
174 pImpl->pImgListHiBig=0;
176 SetPool( &pApp->GetPool() );
180 //====================================================================
182 SfxModule::~SfxModule()
184 if( !bDummy )
186 if ( SFX_APP()->Get_Impl() )
188 // Das Modul wird noch vor dem DeInitialize zerst"ort, also auis dem Array entfernen
189 SfxModuleArr_Impl& rArr = GetModules_Impl();
190 for( USHORT nPos = rArr.Count(); nPos--; )
192 if( rArr[ nPos ] == this )
194 rArr.Remove( nPos );
195 break;
199 delete pImpl;
202 delete pResMgr;
206 //-------------------------------------------------------------------------
208 SfxSlotPool* SfxModule::GetSlotPool() const
210 return pImpl->pSlotPool;
213 //-------------------------------------------------------------------------
215 void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact)
217 DBG_ASSERT( pImpl, "Kein echtes Modul!" );
219 if (!pImpl->pFactArr)
220 pImpl->pFactArr = new SfxChildWinFactArr_Impl;
222 //#ifdef DBG_UTIL
223 for (USHORT nFactory=0; nFactory<pImpl->pFactArr->Count(); ++nFactory)
225 if (pFact->nId == (*pImpl->pFactArr)[nFactory]->nId)
227 pImpl->pFactArr->Remove( nFactory );
228 DBG_ERROR("ChildWindow mehrfach registriert!");
229 return;
232 //#endif
234 pImpl->pFactArr->C40_INSERT(
235 SfxChildWinFactory, pFact, pImpl->pFactArr->Count() );
238 //-------------------------------------------------------------------------
240 void SfxModule::RegisterChildWindowContext( USHORT nId,
241 SfxChildWinContextFactory *pFact)
243 DBG_ASSERT( pImpl, "Kein echtes Modul!" );
245 USHORT nCount = pImpl->pFactArr->Count();
246 for (USHORT nFactory=0; nFactory<nCount; ++nFactory)
248 SfxChildWinFactory *pF = (*pImpl->pFactArr)[nFactory];
249 if ( nId == pF->nId )
251 if ( !pF->pArr )
252 pF->pArr = new SfxChildWinContextArr_Impl;
253 pF->pArr->C40_INSERT( SfxChildWinContextFactory, pFact, pF->pArr->Count() );
254 return;
258 DBG_ERROR( "Kein ChildWindow fuer diesen Context!" );
261 //-------------------------------------------------------------------------
263 void SfxModule::RegisterToolBoxControl( SfxTbxCtrlFactory *pFact )
265 if (!pImpl->pTbxCtrlFac)
266 pImpl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
268 #ifdef DBG_UTIL
269 for ( USHORT n=0; n<pImpl->pTbxCtrlFac->Count(); n++ )
271 SfxTbxCtrlFactory *pF = (*pImpl->pTbxCtrlFac)[n];
272 if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
273 (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
275 DBG_WARNING("TbxController-Registrierung ist nicht eindeutig!");
278 #endif
280 pImpl->pTbxCtrlFac->C40_INSERT( SfxTbxCtrlFactory, pFact, pImpl->pTbxCtrlFac->Count() );
283 //-------------------------------------------------------------------------
285 void SfxModule::RegisterStatusBarControl( SfxStbCtrlFactory *pFact )
287 if (!pImpl->pStbCtrlFac)
288 pImpl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
290 #ifdef DBG_UTIL
291 for ( USHORT n=0; n<pImpl->pStbCtrlFac->Count(); n++ )
293 SfxStbCtrlFactory *pF = (*pImpl->pStbCtrlFac)[n];
294 if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
295 (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
297 DBG_WARNING("StbController-Registrierung ist nicht eindeutig!");
300 #endif
302 pImpl->pStbCtrlFac->C40_INSERT( SfxStbCtrlFactory, pFact, pImpl->pStbCtrlFac->Count() );
305 //-------------------------------------------------------------------------
307 void SfxModule::RegisterMenuControl( SfxMenuCtrlFactory *pFact )
309 if (!pImpl->pMenuCtrlFac)
310 pImpl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
312 #ifdef DBG_UTIL
313 for ( USHORT n=0; n<pImpl->pMenuCtrlFac->Count(); n++ )
315 SfxMenuCtrlFactory *pF = (*pImpl->pMenuCtrlFac)[n];
316 if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
317 (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
319 DBG_WARNING("MenuController-Registrierung ist nicht eindeutig!");
322 #endif
324 pImpl->pMenuCtrlFac->C40_INSERT( SfxMenuCtrlFactory, pFact, pImpl->pMenuCtrlFac->Count() );
327 //-------------------------------------------------------------------------
329 SfxTbxCtrlFactArr_Impl* SfxModule::GetTbxCtrlFactories_Impl() const
331 return pImpl->pTbxCtrlFac;
334 //-------------------------------------------------------------------------
336 SfxStbCtrlFactArr_Impl* SfxModule::GetStbCtrlFactories_Impl() const
338 return pImpl->pStbCtrlFac;
341 //-------------------------------------------------------------------------
343 SfxMenuCtrlFactArr_Impl* SfxModule::GetMenuCtrlFactories_Impl() const
345 return pImpl->pMenuCtrlFac;
348 //-------------------------------------------------------------------------
350 SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const
352 return pImpl->pFactArr;
355 ImageList* SfxModule::GetImageList_Impl( BOOL bBig )
357 return pImpl->GetImageList( pResMgr, bBig, FALSE );
360 ImageList* SfxModule::GetImageList_Impl( BOOL bBig, BOOL bHiContrast )
362 return pImpl->GetImageList( pResMgr, bBig, bHiContrast );
365 SfxTabPage* SfxModule::CreateTabPage( USHORT, Window*, const SfxItemSet& )
367 return NULL;
370 SfxModuleArr_Impl& SfxModule::GetModules_Impl()
372 if( !pModules )
373 pModules = new SfxModuleArr_Impl;
374 return *pModules;
377 void SfxModule::DestroyModules_Impl()
379 if ( pModules )
381 SfxModuleArr_Impl& rModules = *pModules;
382 for( USHORT nPos = rModules.Count(); nPos--; )
384 SfxModule* pMod = rModules.GetObject(nPos);
385 delete pMod;
390 void SfxModule::Invalidate( USHORT nId )
392 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) )
393 if ( pFrame->GetObjectShell()->GetModule() == this )
394 Invalidate_Impl( pFrame->GetBindings(), nId );
397 BOOL SfxModule::IsActive() const
399 SfxViewFrame* pFrame = SfxViewFrame::Current();
400 if ( pFrame && pFrame->GetObjectShell()->GetFactory().GetModule() == this )
401 return TRUE;
402 return FALSE;
405 SfxModule* SfxModule::GetActiveModule( SfxViewFrame* pFrame )
407 if ( !pFrame )
408 pFrame = SfxViewFrame::Current();
409 SfxObjectShell* pSh = 0;
410 if( pFrame )
411 pSh = pFrame->GetObjectShell();
412 return pSh ? pSh->GetModule() : 0;