xref: /trunk/main/sfx2/source/appl/module.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef GCC
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <stdio.h>
35*cdf0e10cSrcweir #include <tools/rcid.h>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <cstdarg>
38*cdf0e10cSrcweir #include <sfx2/module.hxx>
39*cdf0e10cSrcweir #include <sfx2/app.hxx>
40*cdf0e10cSrcweir #include "arrdecl.hxx"
41*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
42*cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
43*cdf0e10cSrcweir #include <sfx2/tbxctrl.hxx>
44*cdf0e10cSrcweir #include "sfx2/stbitem.hxx"
45*cdf0e10cSrcweir #include <sfx2/mnuitem.hxx>
46*cdf0e10cSrcweir #include <sfx2/childwin.hxx>
47*cdf0e10cSrcweir #include <sfx2/mnumgr.hxx>
48*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
49*cdf0e10cSrcweir #include <sfx2/objface.hxx>
50*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
51*cdf0e10cSrcweir #include <svl/intitem.hxx>
52*cdf0e10cSrcweir #include "sfx2/taskpane.hxx"
53*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
54*cdf0e10cSrcweir #include <rtl/strbuf.hxx>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #define SfxModule
57*cdf0e10cSrcweir #include "sfxslots.hxx"
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir static SfxModuleArr_Impl* pModules=0;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir class SfxModule_Impl
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir public:
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     SfxSlotPool*                pSlotPool;
66*cdf0e10cSrcweir     SfxTbxCtrlFactArr_Impl*     pTbxCtrlFac;
67*cdf0e10cSrcweir     SfxStbCtrlFactArr_Impl*     pStbCtrlFac;
68*cdf0e10cSrcweir     SfxMenuCtrlFactArr_Impl*    pMenuCtrlFac;
69*cdf0e10cSrcweir     SfxChildWinFactArr_Impl*    pFactArr;
70*cdf0e10cSrcweir     ImageList*                  pImgListSmall;
71*cdf0e10cSrcweir     ImageList*                  pImgListBig;
72*cdf0e10cSrcweir     ImageList*                  pImgListHiSmall;
73*cdf0e10cSrcweir     ImageList*                  pImgListHiBig;
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir                                 SfxModule_Impl();
76*cdf0e10cSrcweir                                 ~SfxModule_Impl();
77*cdf0e10cSrcweir     ImageList*                  GetImageList( ResMgr*, sal_Bool, sal_Bool bHiContrast = sal_False );
78*cdf0e10cSrcweir };
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir SfxModule_Impl::SfxModule_Impl()
81*cdf0e10cSrcweir  : pSlotPool(0)
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir SfxModule_Impl::~SfxModule_Impl()
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     delete pSlotPool;
88*cdf0e10cSrcweir     delete pTbxCtrlFac;
89*cdf0e10cSrcweir     delete pStbCtrlFac;
90*cdf0e10cSrcweir     delete pMenuCtrlFac;
91*cdf0e10cSrcweir     delete pFactArr;
92*cdf0e10cSrcweir     delete pImgListSmall;
93*cdf0e10cSrcweir     delete pImgListBig;
94*cdf0e10cSrcweir     delete pImgListHiSmall;
95*cdf0e10cSrcweir     delete pImgListHiBig;
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir ImageList* SfxModule_Impl::GetImageList( ResMgr* pResMgr, sal_Bool bBig, sal_Bool bHiContrast )
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     ImageList*& rpList = bBig ? ( bHiContrast ? pImgListHiBig: pImgListBig ) :
101*cdf0e10cSrcweir                                 ( bHiContrast ? pImgListHiSmall : pImgListSmall );
102*cdf0e10cSrcweir     if ( !rpList )
103*cdf0e10cSrcweir     {
104*cdf0e10cSrcweir         ResId aResId( bBig ? ( bHiContrast ? RID_DEFAULTIMAGELIST_LCH : RID_DEFAULTIMAGELIST_LC ) :
105*cdf0e10cSrcweir                              ( bHiContrast ? RID_DEFAULTIMAGELIST_SCH : RID_DEFAULTIMAGELIST_SC ), *pResMgr );
106*cdf0e10cSrcweir         aResId.SetRT( RSC_IMAGELIST );
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir         DBG_ASSERT( pResMgr->IsAvailable(aResId), "No default ImageList!" );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         if ( pResMgr->IsAvailable(aResId) )
111*cdf0e10cSrcweir             rpList = new ImageList( aResId );
112*cdf0e10cSrcweir         else
113*cdf0e10cSrcweir             rpList = new ImageList();
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     return rpList; }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir TYPEINIT1(SfxModule, SfxShell);
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //=========================================================================
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir SFX_IMPL_INTERFACE(SfxModule,SfxShell,SfxResId(0))
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //====================================================================
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir ResMgr* SfxModule::GetResMgr()
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir     return pResMgr;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //====================================================================
134*cdf0e10cSrcweir /*
135*cdf0e10cSrcweir SfxModule::SfxModule( ResMgr* pMgrP, sal_Bool bDummyP,
136*cdf0e10cSrcweir                       SfxObjectFactory* pFactoryP )
137*cdf0e10cSrcweir     : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir     Construct_Impl();
140*cdf0e10cSrcweir     if ( pFactoryP )
141*cdf0e10cSrcweir         pFactoryP->SetModule_Impl( this );
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir */
144*cdf0e10cSrcweir SfxModule::SfxModule( ResMgr* pMgrP, sal_Bool bDummyP,
145*cdf0e10cSrcweir                       SfxObjectFactory* pFactoryP, ... )
146*cdf0e10cSrcweir     : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir     Construct_Impl();
149*cdf0e10cSrcweir     va_list pVarArgs;
150*cdf0e10cSrcweir     va_start( pVarArgs, pFactoryP );
151*cdf0e10cSrcweir     for ( SfxObjectFactory *pArg = pFactoryP; pArg;
152*cdf0e10cSrcweir          pArg = va_arg( pVarArgs, SfxObjectFactory* ) )
153*cdf0e10cSrcweir         pArg->SetModule_Impl( this );
154*cdf0e10cSrcweir     va_end(pVarArgs);
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir void SfxModule::Construct_Impl()
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir     if( !bDummy )
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir         SfxApplication *pApp = SFX_APP();
162*cdf0e10cSrcweir         SfxModuleArr_Impl& rArr = GetModules_Impl();
163*cdf0e10cSrcweir         SfxModule* pPtr = (SfxModule*)this;
164*cdf0e10cSrcweir         rArr.C40_INSERT( SfxModule, pPtr, rArr.Count() );
165*cdf0e10cSrcweir         pImpl = new SfxModule_Impl;
166*cdf0e10cSrcweir         pImpl->pSlotPool = new SfxSlotPool( &pApp->GetAppSlotPool_Impl(), pResMgr );
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         pImpl->pTbxCtrlFac=0;
169*cdf0e10cSrcweir         pImpl->pStbCtrlFac=0;
170*cdf0e10cSrcweir         pImpl->pMenuCtrlFac=0;
171*cdf0e10cSrcweir         pImpl->pFactArr=0;
172*cdf0e10cSrcweir         pImpl->pImgListSmall=0;
173*cdf0e10cSrcweir         pImpl->pImgListBig=0;
174*cdf0e10cSrcweir         pImpl->pImgListHiSmall=0;
175*cdf0e10cSrcweir         pImpl->pImgListHiBig=0;
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir         SetPool( &pApp->GetPool() );
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir //====================================================================
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir SfxModule::~SfxModule()
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     if( !bDummy )
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         if ( SFX_APP()->Get_Impl() )
188*cdf0e10cSrcweir         {
189*cdf0e10cSrcweir             // Das Modul wird noch vor dem DeInitialize zerst"ort, also auis dem Array entfernen
190*cdf0e10cSrcweir             SfxModuleArr_Impl& rArr = GetModules_Impl();
191*cdf0e10cSrcweir             for( sal_uInt16 nPos = rArr.Count(); nPos--; )
192*cdf0e10cSrcweir             {
193*cdf0e10cSrcweir                 if( rArr[ nPos ] == this )
194*cdf0e10cSrcweir                 {
195*cdf0e10cSrcweir                     rArr.Remove( nPos );
196*cdf0e10cSrcweir                     break;
197*cdf0e10cSrcweir                 }
198*cdf0e10cSrcweir             }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir             delete pImpl;
201*cdf0e10cSrcweir         }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         delete pResMgr;
204*cdf0e10cSrcweir     }
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir //-------------------------------------------------------------------------
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir SfxSlotPool* SfxModule::GetSlotPool() const
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     return pImpl->pSlotPool;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir //-------------------------------------------------------------------------
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact)
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     DBG_ASSERT( pImpl, "Kein echtes Modul!" );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     if (!pImpl->pFactArr)
221*cdf0e10cSrcweir         pImpl->pFactArr = new SfxChildWinFactArr_Impl;
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir //#ifdef DBG_UTIL
224*cdf0e10cSrcweir     for (sal_uInt16 nFactory=0; nFactory<pImpl->pFactArr->Count(); ++nFactory)
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         if (pFact->nId ==  (*pImpl->pFactArr)[nFactory]->nId)
227*cdf0e10cSrcweir         {
228*cdf0e10cSrcweir             pImpl->pFactArr->Remove( nFactory );
229*cdf0e10cSrcweir             DBG_ERROR("ChildWindow mehrfach registriert!");
230*cdf0e10cSrcweir             return;
231*cdf0e10cSrcweir         }
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir //#endif
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     pImpl->pFactArr->C40_INSERT(
236*cdf0e10cSrcweir         SfxChildWinFactory, pFact, pImpl->pFactArr->Count() );
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir //-------------------------------------------------------------------------
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir void SfxModule::RegisterChildWindowContext( sal_uInt16 nId,
242*cdf0e10cSrcweir         SfxChildWinContextFactory *pFact)
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir     DBG_ASSERT( pImpl, "Kein echtes Modul!" );
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir     sal_uInt16 nCount = pImpl->pFactArr->Count();
247*cdf0e10cSrcweir     for (sal_uInt16 nFactory=0; nFactory<nCount; ++nFactory)
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         SfxChildWinFactory *pF = (*pImpl->pFactArr)[nFactory];
250*cdf0e10cSrcweir         if ( nId == pF->nId )
251*cdf0e10cSrcweir         {
252*cdf0e10cSrcweir             if ( !pF->pArr )
253*cdf0e10cSrcweir                 pF->pArr = new SfxChildWinContextArr_Impl;
254*cdf0e10cSrcweir             pF->pArr->C40_INSERT( SfxChildWinContextFactory, pFact, pF->pArr->Count() );
255*cdf0e10cSrcweir             return;
256*cdf0e10cSrcweir         }
257*cdf0e10cSrcweir     }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir     DBG_ERROR( "Kein ChildWindow fuer diesen Context!" );
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir //-------------------------------------------------------------------------
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir void SfxModule::RegisterToolBoxControl( SfxTbxCtrlFactory *pFact )
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir     if (!pImpl->pTbxCtrlFac)
267*cdf0e10cSrcweir         pImpl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir #ifdef DBG_UTIL
270*cdf0e10cSrcweir     for ( sal_uInt16 n=0; n<pImpl->pTbxCtrlFac->Count(); n++ )
271*cdf0e10cSrcweir     {
272*cdf0e10cSrcweir         SfxTbxCtrlFactory *pF = (*pImpl->pTbxCtrlFac)[n];
273*cdf0e10cSrcweir         if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
274*cdf0e10cSrcweir             (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
275*cdf0e10cSrcweir         {
276*cdf0e10cSrcweir             DBG_WARNING("TbxController-Registrierung ist nicht eindeutig!");
277*cdf0e10cSrcweir         }
278*cdf0e10cSrcweir     }
279*cdf0e10cSrcweir #endif
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     pImpl->pTbxCtrlFac->C40_INSERT( SfxTbxCtrlFactory, pFact, pImpl->pTbxCtrlFac->Count() );
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir //-------------------------------------------------------------------------
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir void SfxModule::RegisterStatusBarControl( SfxStbCtrlFactory *pFact )
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir     if (!pImpl->pStbCtrlFac)
289*cdf0e10cSrcweir         pImpl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir #ifdef DBG_UTIL
292*cdf0e10cSrcweir     for ( sal_uInt16 n=0; n<pImpl->pStbCtrlFac->Count(); n++ )
293*cdf0e10cSrcweir     {
294*cdf0e10cSrcweir         SfxStbCtrlFactory *pF = (*pImpl->pStbCtrlFac)[n];
295*cdf0e10cSrcweir         if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
296*cdf0e10cSrcweir             (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
297*cdf0e10cSrcweir         {
298*cdf0e10cSrcweir             DBG_WARNING("StbController-Registrierung ist nicht eindeutig!");
299*cdf0e10cSrcweir         }
300*cdf0e10cSrcweir     }
301*cdf0e10cSrcweir #endif
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     pImpl->pStbCtrlFac->C40_INSERT( SfxStbCtrlFactory, pFact, pImpl->pStbCtrlFac->Count() );
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir //-------------------------------------------------------------------------
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir void SfxModule::RegisterMenuControl( SfxMenuCtrlFactory *pFact )
309*cdf0e10cSrcweir {
310*cdf0e10cSrcweir     if (!pImpl->pMenuCtrlFac)
311*cdf0e10cSrcweir         pImpl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir #ifdef DBG_UTIL
314*cdf0e10cSrcweir     for ( sal_uInt16 n=0; n<pImpl->pMenuCtrlFac->Count(); n++ )
315*cdf0e10cSrcweir     {
316*cdf0e10cSrcweir         SfxMenuCtrlFactory *pF = (*pImpl->pMenuCtrlFac)[n];
317*cdf0e10cSrcweir         if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
318*cdf0e10cSrcweir             (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
319*cdf0e10cSrcweir         {
320*cdf0e10cSrcweir             DBG_WARNING("MenuController-Registrierung ist nicht eindeutig!");
321*cdf0e10cSrcweir         }
322*cdf0e10cSrcweir     }
323*cdf0e10cSrcweir #endif
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     pImpl->pMenuCtrlFac->C40_INSERT( SfxMenuCtrlFactory, pFact, pImpl->pMenuCtrlFac->Count() );
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir //-------------------------------------------------------------------------
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir SfxTbxCtrlFactArr_Impl*  SfxModule::GetTbxCtrlFactories_Impl() const
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir     return pImpl->pTbxCtrlFac;
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir //-------------------------------------------------------------------------
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir SfxStbCtrlFactArr_Impl*  SfxModule::GetStbCtrlFactories_Impl() const
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     return pImpl->pStbCtrlFac;
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir //-------------------------------------------------------------------------
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl* SfxModule::GetMenuCtrlFactories_Impl() const
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir     return pImpl->pMenuCtrlFac;
347*cdf0e10cSrcweir }
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir //-------------------------------------------------------------------------
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir     return pImpl->pFactArr;
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir ImageList* SfxModule::GetImageList_Impl( sal_Bool bBig )
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir     return pImpl->GetImageList( pResMgr, bBig, sal_False );
359*cdf0e10cSrcweir }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir ImageList* SfxModule::GetImageList_Impl( sal_Bool bBig, sal_Bool bHiContrast )
362*cdf0e10cSrcweir {
363*cdf0e10cSrcweir     return pImpl->GetImageList( pResMgr, bBig, bHiContrast );
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir SfxTabPage* SfxModule::CreateTabPage( sal_uInt16, Window*, const SfxItemSet& )
367*cdf0e10cSrcweir {
368*cdf0e10cSrcweir     return NULL;
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir SfxModuleArr_Impl& SfxModule::GetModules_Impl()
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir     if( !pModules )
374*cdf0e10cSrcweir         pModules = new SfxModuleArr_Impl;
375*cdf0e10cSrcweir     return *pModules;
376*cdf0e10cSrcweir };
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir void SfxModule::DestroyModules_Impl()
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir     if ( pModules )
381*cdf0e10cSrcweir     {
382*cdf0e10cSrcweir         SfxModuleArr_Impl& rModules = *pModules;
383*cdf0e10cSrcweir         for( sal_uInt16 nPos = rModules.Count(); nPos--; )
384*cdf0e10cSrcweir     {
385*cdf0e10cSrcweir         SfxModule* pMod = rModules.GetObject(nPos);
386*cdf0e10cSrcweir         delete pMod;
387*cdf0e10cSrcweir     }
388*cdf0e10cSrcweir     }
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir void SfxModule::Invalidate( sal_uInt16 nId )
392*cdf0e10cSrcweir {
393*cdf0e10cSrcweir     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) )
394*cdf0e10cSrcweir         if ( pFrame->GetObjectShell()->GetModule() == this )
395*cdf0e10cSrcweir             Invalidate_Impl( pFrame->GetBindings(), nId );
396*cdf0e10cSrcweir }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir sal_Bool SfxModule::IsActive() const
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir     SfxViewFrame* pFrame = SfxViewFrame::Current();
401*cdf0e10cSrcweir     if ( pFrame && pFrame->GetObjectShell()->GetFactory().GetModule() == this )
402*cdf0e10cSrcweir         return sal_True;
403*cdf0e10cSrcweir     return sal_False;
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir bool SfxModule::IsChildWindowAvailable( const sal_uInt16 i_nId, const SfxViewFrame* i_pViewFrame ) const
407*cdf0e10cSrcweir {
408*cdf0e10cSrcweir     if ( i_nId != SID_TASKPANE )
409*cdf0e10cSrcweir         // by default, assume it is
410*cdf0e10cSrcweir         return true;
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir     const SfxViewFrame* pViewFrame = i_pViewFrame ? i_pViewFrame : GetFrame();
413*cdf0e10cSrcweir     ENSURE_OR_RETURN( pViewFrame, "SfxModule::IsChildWindowAvailable: no frame to ask for the module identifier!", false );
414*cdf0e10cSrcweir     return ::sfx2::ModuleTaskPane::ModuleHasToolPanels( pViewFrame->GetFrame().GetFrameInterface() );
415*cdf0e10cSrcweir }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir SfxModule* SfxModule::GetActiveModule( SfxViewFrame* pFrame )
418*cdf0e10cSrcweir {
419*cdf0e10cSrcweir     if ( !pFrame )
420*cdf0e10cSrcweir         pFrame = SfxViewFrame::Current();
421*cdf0e10cSrcweir     SfxObjectShell* pSh = 0;
422*cdf0e10cSrcweir     if( pFrame )
423*cdf0e10cSrcweir         pSh = pFrame->GetObjectShell();
424*cdf0e10cSrcweir     return pSh ? pSh->GetModule() : 0;
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir FieldUnit SfxModule::GetModuleFieldUnit( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > const & i_frame )
428*cdf0e10cSrcweir {
429*cdf0e10cSrcweir     ENSURE_OR_RETURN( i_frame.is(), "SfxModule::GetModuleFieldUnit: invalid frame!", FUNIT_100TH_MM );
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir     // find SfxViewFrame for the given XFrame
432*cdf0e10cSrcweir     SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
433*cdf0e10cSrcweir     while ( pViewFrame != NULL )
434*cdf0e10cSrcweir     {
435*cdf0e10cSrcweir         if ( pViewFrame->GetFrame().GetFrameInterface() == i_frame )
436*cdf0e10cSrcweir             break;
437*cdf0e10cSrcweir         pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir     ENSURE_OR_RETURN( pViewFrame != NULL, "SfxModule::GetModuleFieldUnit: unable to find an SfxViewFrame for the given XFrame", FUNIT_100TH_MM );
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir     // find the module
442*cdf0e10cSrcweir     SfxModule const * pModule = GetActiveModule( pViewFrame );
443*cdf0e10cSrcweir     ENSURE_OR_RETURN( pModule != NULL, "SfxModule::GetModuleFieldUnit: no SfxModule for the given frame!", FUNIT_100TH_MM );
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir     SfxPoolItem const * pItem = pModule->GetItem( SID_ATTR_METRIC );
446*cdf0e10cSrcweir     if ( pItem == NULL )
447*cdf0e10cSrcweir     {
448*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
449*cdf0e10cSrcweir         ::rtl::OStringBuffer message;
450*cdf0e10cSrcweir         message.append( "SfxModule::GetFieldUnit: no metric item in the module implemented by '" );
451*cdf0e10cSrcweir         message.append( typeid( *pModule ).name() );
452*cdf0e10cSrcweir         message.append( "'!" );
453*cdf0e10cSrcweir         OSL_ENSURE( false, message.makeStringAndClear().getStr() );
454*cdf0e10cSrcweir #endif
455*cdf0e10cSrcweir         return FUNIT_100TH_MM;
456*cdf0e10cSrcweir     }
457*cdf0e10cSrcweir     return (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir FieldUnit SfxModule::GetCurrentFieldUnit()
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir     FieldUnit eUnit = FUNIT_INCH;
463*cdf0e10cSrcweir     SfxModule* pModule = GetActiveModule();
464*cdf0e10cSrcweir     if ( pModule )
465*cdf0e10cSrcweir     {
466*cdf0e10cSrcweir         const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
467*cdf0e10cSrcweir         DBG_ASSERT( pItem, "GetFieldUnit(): no item" );
468*cdf0e10cSrcweir         if ( pItem )
469*cdf0e10cSrcweir             eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
470*cdf0e10cSrcweir     }
471*cdf0e10cSrcweir     else
472*cdf0e10cSrcweir         DBG_ERRORFILE( "GetModuleFieldUnit(): no module found" );
473*cdf0e10cSrcweir     return eUnit;
474*cdf0e10cSrcweir }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir FieldUnit SfxModule::GetFieldUnit() const
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir     FieldUnit eUnit = FUNIT_INCH;
479*cdf0e10cSrcweir     const SfxPoolItem* pItem = GetItem( SID_ATTR_METRIC );
480*cdf0e10cSrcweir     DBG_ASSERT( pItem, "GetFieldUnit(): no item" );
481*cdf0e10cSrcweir     if ( pItem )
482*cdf0e10cSrcweir         eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
483*cdf0e10cSrcweir     return eUnit;
484*cdf0e10cSrcweir }
485