1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include <tools/rcid.h>
34 #include <sfx2/module.hxx>
35 #include <sfx2/app.hxx>
36 #include "arrdecl.hxx"
37 #include "sfx2/sfxresid.hxx"
38 #include <sfx2/msgpool.hxx>
39 #include <sfx2/tbxctrl.hxx>
40 #include "sfx2/stbitem.hxx"
41 #include <sfx2/mnuitem.hxx>
42 #include <sfx2/childwin.hxx>
43 #include <sfx2/mnumgr.hxx>
44 #include <sfx2/docfac.hxx>
45 #include <sfx2/objface.hxx>
46 #include <sfx2/viewfrm.hxx>
47 #include <svl/intitem.hxx>
48 #include "sfx2/taskpane.hxx"
49 #include <tools/diagnose_ex.h>
50 #include <rtl/strbuf.hxx>
51 #include <sal/log.hxx>
54 #include "sfxslots.hxx"
56 static SfxModuleArr_Impl
* pModules
=0;
62 SfxSlotPool
* pSlotPool
;
63 SfxTbxCtrlFactArr_Impl
* pTbxCtrlFac
;
64 SfxStbCtrlFactArr_Impl
* pStbCtrlFac
;
65 SfxMenuCtrlFactArr_Impl
* pMenuCtrlFac
;
66 SfxChildWinFactArr_Impl
* pFactArr
;
67 ImageList
* pImgListSmall
;
68 ImageList
* pImgListBig
;
72 ImageList
* GetImageList( ResMgr
* pResMgr
, bool bBig
);
75 SfxModule_Impl::SfxModule_Impl()
80 SfxModule_Impl::~SfxModule_Impl()
91 ImageList
* SfxModule_Impl::GetImageList( ResMgr
* pResMgr
, bool bBig
)
93 ImageList
*& rpList
= bBig
? pImgListBig
: pImgListSmall
;
96 ResId
aResId( bBig
? ( RID_DEFAULTIMAGELIST_LC
) : ( RID_DEFAULTIMAGELIST_SC
), *pResMgr
);
98 aResId
.SetRT( RSC_IMAGELIST
);
100 DBG_ASSERT( pResMgr
->IsAvailable(aResId
), "No default ImageList!" );
102 if ( pResMgr
->IsAvailable(aResId
) )
103 rpList
= new ImageList( aResId
);
105 rpList
= new ImageList();
110 TYPEINIT1(SfxModule
, SfxShell
);
112 //=========================================================================
114 SFX_IMPL_INTERFACE(SfxModule
,SfxShell
,SfxResId(0))
118 //====================================================================
120 ResMgr
* SfxModule::GetResMgr()
125 //====================================================================
127 SfxModule::SfxModule( ResMgr
* pMgrP
, sal_Bool bDummyP
,
128 SfxObjectFactory
* pFactoryP
, ... )
129 : pResMgr( pMgrP
), bDummy( bDummyP
), pImpl(0L)
133 va_start( pVarArgs
, pFactoryP
);
134 for ( SfxObjectFactory
*pArg
= pFactoryP
; pArg
;
135 pArg
= va_arg( pVarArgs
, SfxObjectFactory
* ) )
136 pArg
->SetModule_Impl( this );
140 void SfxModule::Construct_Impl()
144 SfxApplication
*pApp
= SFX_APP();
145 SfxModuleArr_Impl
& rArr
= GetModules_Impl();
146 SfxModule
* pPtr
= (SfxModule
*)this;
147 rArr
.C40_INSERT( SfxModule
, pPtr
, rArr
.Count() );
148 pImpl
= new SfxModule_Impl
;
149 pImpl
->pSlotPool
= new SfxSlotPool( &pApp
->GetAppSlotPool_Impl(), pResMgr
);
151 pImpl
->pTbxCtrlFac
=0;
152 pImpl
->pStbCtrlFac
=0;
153 pImpl
->pMenuCtrlFac
=0;
155 pImpl
->pImgListSmall
=0;
156 pImpl
->pImgListBig
=0;
158 SetPool( &pApp
->GetPool() );
162 //====================================================================
164 SfxModule::~SfxModule()
168 if ( SFX_APP()->Get_Impl() )
170 // The module will be destroyed before the Deinitialize,
171 // so remove from the array
172 SfxModuleArr_Impl
& rArr
= GetModules_Impl();
173 for( sal_uInt16 nPos
= rArr
.Count(); nPos
--; )
175 if( rArr
[ nPos
] == this )
189 //-------------------------------------------------------------------------
191 SfxSlotPool
* SfxModule::GetSlotPool() const
193 return pImpl
->pSlotPool
;
196 //-------------------------------------------------------------------------
198 void SfxModule::RegisterChildWindow(SfxChildWinFactory
*pFact
)
200 DBG_ASSERT( pImpl
, "No real Module!" );
202 if (!pImpl
->pFactArr
)
203 pImpl
->pFactArr
= new SfxChildWinFactArr_Impl
;
205 for (sal_uInt16 nFactory
=0; nFactory
<pImpl
->pFactArr
->Count(); ++nFactory
)
207 if (pFact
->nId
== (*pImpl
->pFactArr
)[nFactory
]->nId
)
209 pImpl
->pFactArr
->Remove( nFactory
);
210 SAL_WARN("sfx2.appl", "ChildWindow registered multiple times!");
215 pImpl
->pFactArr
->C40_INSERT(
216 SfxChildWinFactory
, pFact
, pImpl
->pFactArr
->Count() );
219 //-------------------------------------------------------------------------
221 void SfxModule::RegisterToolBoxControl( SfxTbxCtrlFactory
*pFact
)
223 if (!pImpl
->pTbxCtrlFac
)
224 pImpl
->pTbxCtrlFac
= new SfxTbxCtrlFactArr_Impl
;
227 for ( sal_uInt16 n
=0; n
<pImpl
->pTbxCtrlFac
->Count(); n
++ )
229 SfxTbxCtrlFactory
*pF
= (*pImpl
->pTbxCtrlFac
)[n
];
230 if ( pF
->nTypeId
&& pF
->nTypeId
== pFact
->nTypeId
&&
231 (pF
->nSlotId
== pFact
->nSlotId
|| pF
->nSlotId
== 0) )
233 DBG_WARNING("TbxController-Registering is not clearly defined!");
238 pImpl
->pTbxCtrlFac
->C40_INSERT( SfxTbxCtrlFactory
, pFact
, pImpl
->pTbxCtrlFac
->Count() );
241 //-------------------------------------------------------------------------
243 void SfxModule::RegisterStatusBarControl( SfxStbCtrlFactory
*pFact
)
245 if (!pImpl
->pStbCtrlFac
)
246 pImpl
->pStbCtrlFac
= new SfxStbCtrlFactArr_Impl
;
249 for ( sal_uInt16 n
=0; n
<pImpl
->pStbCtrlFac
->Count(); n
++ )
251 SfxStbCtrlFactory
*pF
= (*pImpl
->pStbCtrlFac
)[n
];
252 if ( pF
->nTypeId
&& pF
->nTypeId
== pFact
->nTypeId
&&
253 (pF
->nSlotId
== pFact
->nSlotId
|| pF
->nSlotId
== 0) )
255 DBG_WARNING("TbxController-Registering is not clearly defined!");
260 pImpl
->pStbCtrlFac
->C40_INSERT( SfxStbCtrlFactory
, pFact
, pImpl
->pStbCtrlFac
->Count() );
263 //-------------------------------------------------------------------------
265 void SfxModule::RegisterMenuControl( SfxMenuCtrlFactory
*pFact
)
267 if (!pImpl
->pMenuCtrlFac
)
268 pImpl
->pMenuCtrlFac
= new SfxMenuCtrlFactArr_Impl
;
271 for ( sal_uInt16 n
=0; n
<pImpl
->pMenuCtrlFac
->Count(); n
++ )
273 SfxMenuCtrlFactory
*pF
= (*pImpl
->pMenuCtrlFac
)[n
];
274 if ( pF
->nTypeId
&& pF
->nTypeId
== pFact
->nTypeId
&&
275 (pF
->nSlotId
== pFact
->nSlotId
|| pF
->nSlotId
== 0) )
277 DBG_WARNING("MenuController-Registering is not clearly defined!");
282 pImpl
->pMenuCtrlFac
->C40_INSERT( SfxMenuCtrlFactory
, pFact
, pImpl
->pMenuCtrlFac
->Count() );
285 //-------------------------------------------------------------------------
287 SfxTbxCtrlFactArr_Impl
* SfxModule::GetTbxCtrlFactories_Impl() const
289 return pImpl
->pTbxCtrlFac
;
292 //-------------------------------------------------------------------------
294 SfxStbCtrlFactArr_Impl
* SfxModule::GetStbCtrlFactories_Impl() const
296 return pImpl
->pStbCtrlFac
;
299 //-------------------------------------------------------------------------
301 SfxMenuCtrlFactArr_Impl
* SfxModule::GetMenuCtrlFactories_Impl() const
303 return pImpl
->pMenuCtrlFac
;
306 //-------------------------------------------------------------------------
308 SfxChildWinFactArr_Impl
* SfxModule::GetChildWinFactories_Impl() const
310 return pImpl
->pFactArr
;
313 ImageList
* SfxModule::GetImageList_Impl( sal_Bool bBig
)
315 return pImpl
->GetImageList( pResMgr
, bBig
);
318 SfxTabPage
* SfxModule::CreateTabPage( sal_uInt16
, Window
*, const SfxItemSet
& )
323 SfxModuleArr_Impl
& SfxModule::GetModules_Impl()
326 pModules
= new SfxModuleArr_Impl
;
330 void SfxModule::DestroyModules_Impl()
334 SfxModuleArr_Impl
& rModules
= *pModules
;
335 for( sal_uInt16 nPos
= rModules
.Count(); nPos
--; )
337 SfxModule
* pMod
= rModules
.GetObject(nPos
);
340 delete pModules
, pModules
= 0;
344 void SfxModule::Invalidate( sal_uInt16 nId
)
346 for( SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst(); pFrame
; pFrame
= SfxViewFrame::GetNext( *pFrame
) )
347 if ( pFrame
->GetObjectShell()->GetModule() == this )
348 Invalidate_Impl( pFrame
->GetBindings(), nId
);
351 bool SfxModule::IsChildWindowAvailable( const sal_uInt16 i_nId
, const SfxViewFrame
* i_pViewFrame
) const
353 if ( i_nId
!= SID_TASKPANE
)
354 // by default, assume it is
357 const SfxViewFrame
* pViewFrame
= i_pViewFrame
? i_pViewFrame
: GetFrame();
358 ENSURE_OR_RETURN( pViewFrame
, "SfxModule::IsChildWindowAvailable: no frame to ask for the module identifier!", false );
359 return ::sfx2::ModuleTaskPane::ModuleHasToolPanels( pViewFrame
->GetFrame().GetFrameInterface() );
362 SfxModule
* SfxModule::GetActiveModule( SfxViewFrame
* pFrame
)
365 pFrame
= SfxViewFrame::Current();
366 SfxObjectShell
* pSh
= 0;
368 pSh
= pFrame
->GetObjectShell();
369 return pSh
? pSh
->GetModule() : 0;
372 FieldUnit
SfxModule::GetModuleFieldUnit( ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> const & i_frame
)
374 ENSURE_OR_RETURN( i_frame
.is(), "SfxModule::GetModuleFieldUnit: invalid frame!", FUNIT_100TH_MM
);
376 // find SfxViewFrame for the given XFrame
377 SfxViewFrame
* pViewFrame
= SfxViewFrame::GetFirst();
378 while ( pViewFrame
!= NULL
)
380 if ( pViewFrame
->GetFrame().GetFrameInterface() == i_frame
)
382 pViewFrame
= SfxViewFrame::GetNext( *pViewFrame
);
384 ENSURE_OR_RETURN( pViewFrame
!= NULL
, "SfxModule::GetModuleFieldUnit: unable to find an SfxViewFrame for the given XFrame", FUNIT_100TH_MM
);
387 SfxModule
const * pModule
= GetActiveModule( pViewFrame
);
388 ENSURE_OR_RETURN( pModule
!= NULL
, "SfxModule::GetModuleFieldUnit: no SfxModule for the given frame!", FUNIT_100TH_MM
);
390 SfxPoolItem
const * pItem
= pModule
->GetItem( SID_ATTR_METRIC
);
395 "SfxModule::GetFieldUnit: no metric item in the module implemented"
396 " by '" << typeid(*pModule
).name() << "'!");
397 return FUNIT_100TH_MM
;
399 return (FieldUnit
)( (SfxUInt16Item
*)pItem
)->GetValue();
402 FieldUnit
SfxModule::GetCurrentFieldUnit()
404 FieldUnit eUnit
= FUNIT_INCH
;
405 SfxModule
* pModule
= GetActiveModule();
408 const SfxPoolItem
* pItem
= pModule
->GetItem( SID_ATTR_METRIC
);
409 DBG_ASSERT( pItem
, "GetFieldUnit(): no item" );
411 eUnit
= (FieldUnit
)( (SfxUInt16Item
*)pItem
)->GetValue();
414 SAL_WARN( "sfx2.appl", "GetModuleFieldUnit(): no module found" );
418 FieldUnit
SfxModule::GetFieldUnit() const
420 FieldUnit eUnit
= FUNIT_INCH
;
421 const SfxPoolItem
* pItem
= GetItem( SID_ATTR_METRIC
);
422 DBG_ASSERT( pItem
, "GetFieldUnit(): no item" );
424 eUnit
= (FieldUnit
)( (SfxUInt16Item
*)pItem
)->GetValue();
428 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */