1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <tools/rcid.h>
24 #include <sfx2/module.hxx>
25 #include <sfx2/app.hxx>
26 #include "arrdecl.hxx"
27 #include <sfx2/sfxresid.hxx>
28 #include <sfx2/msgpool.hxx>
29 #include <sfx2/tbxctrl.hxx>
30 #include <sfx2/stbitem.hxx>
31 #include <sfx2/mnuitem.hxx>
32 #include <sfx2/childwin.hxx>
33 #include <sfx2/mnumgr.hxx>
34 #include <sfx2/docfac.hxx>
35 #include <sfx2/objface.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <svl/intitem.hxx>
38 #include <sfx2/taskpane.hxx>
39 #include <tools/diagnose_ex.h>
40 #include <rtl/strbuf.hxx>
41 #include <sal/log.hxx>
44 #include "sfxslots.hxx"
46 static SfxModuleArr_Impl
* pModules
=0;
52 SfxSlotPool
* pSlotPool
;
53 SfxTbxCtrlFactArr_Impl
* pTbxCtrlFac
;
54 SfxStbCtrlFactArr_Impl
* pStbCtrlFac
;
55 SfxMenuCtrlFactArr_Impl
* pMenuCtrlFac
;
56 SfxChildWinFactArr_Impl
* pFactArr
;
57 ImageList
* pImgListSmall
;
58 ImageList
* pImgListBig
;
62 ImageList
* GetImageList( ResMgr
* pResMgr
, bool bBig
);
65 SfxModule_Impl::SfxModule_Impl()
66 : pSlotPool(0), pTbxCtrlFac(0), pStbCtrlFac(0), pMenuCtrlFac(0), pFactArr(0), pImgListSmall(0), pImgListBig(0)
70 SfxModule_Impl::~SfxModule_Impl()
81 ImageList
* SfxModule_Impl::GetImageList( ResMgr
* pResMgr
, bool bBig
)
83 ImageList
*& rpList
= bBig
? pImgListBig
: pImgListSmall
;
86 ResId
aResId( bBig
? ( RID_DEFAULTIMAGELIST_LC
) : ( RID_DEFAULTIMAGELIST_SC
), *pResMgr
);
88 aResId
.SetRT( RSC_IMAGELIST
);
90 DBG_ASSERT( pResMgr
->IsAvailable(aResId
), "No default ImageList!" );
92 if ( pResMgr
->IsAvailable(aResId
) )
93 rpList
= new ImageList( aResId
);
95 rpList
= new ImageList();
100 TYPEINIT1(SfxModule
, SfxShell
);
102 //=========================================================================
104 SFX_IMPL_INTERFACE(SfxModule
,SfxShell
,SfxResId(0))
108 //====================================================================
110 ResMgr
* SfxModule::GetResMgr()
115 //====================================================================
117 SfxModule::SfxModule( ResMgr
* pMgrP
, sal_Bool bDummyP
,
118 SfxObjectFactory
* pFactoryP
, ... )
119 : pResMgr( pMgrP
), bDummy( bDummyP
), pImpl(0L)
123 va_start( pVarArgs
, pFactoryP
);
124 for ( SfxObjectFactory
*pArg
= pFactoryP
; pArg
;
125 pArg
= va_arg( pVarArgs
, SfxObjectFactory
* ) )
126 pArg
->SetModule_Impl( this );
130 void SfxModule::Construct_Impl()
134 SfxApplication
*pApp
= SFX_APP();
135 SfxModuleArr_Impl
& rArr
= GetModules_Impl();
136 SfxModule
* pPtr
= (SfxModule
*)this;
137 rArr
.push_back( pPtr
);
138 pImpl
= new SfxModule_Impl
;
139 pImpl
->pSlotPool
= new SfxSlotPool( &pApp
->GetAppSlotPool_Impl(), pResMgr
);
141 pImpl
->pTbxCtrlFac
=0;
142 pImpl
->pStbCtrlFac
=0;
143 pImpl
->pMenuCtrlFac
=0;
145 pImpl
->pImgListSmall
=0;
146 pImpl
->pImgListBig
=0;
148 SetPool( &pApp
->GetPool() );
152 //====================================================================
154 SfxModule::~SfxModule()
158 if ( SFX_APP()->Get_Impl() )
160 // The module will be destroyed before the Deinitialize,
161 // so remove from the array
162 SfxModuleArr_Impl
& rArr
= GetModules_Impl();
163 for( sal_uInt16 nPos
= rArr
.size(); nPos
--; )
165 if( rArr
[ nPos
] == this )
167 rArr
.erase( rArr
.begin() + nPos
);
179 //-------------------------------------------------------------------------
181 SfxSlotPool
* SfxModule::GetSlotPool() const
183 return pImpl
->pSlotPool
;
186 //-------------------------------------------------------------------------
188 void SfxModule::RegisterChildWindow(SfxChildWinFactory
*pFact
)
190 DBG_ASSERT( pImpl
, "No real Module!" );
192 if (!pImpl
->pFactArr
)
193 pImpl
->pFactArr
= new SfxChildWinFactArr_Impl
;
195 for (sal_uInt16 nFactory
=0; nFactory
<pImpl
->pFactArr
->size(); ++nFactory
)
197 if (pFact
->nId
== (*pImpl
->pFactArr
)[nFactory
]->nId
)
199 pImpl
->pFactArr
->erase( pImpl
->pFactArr
->begin() + nFactory
);
200 SAL_WARN("sfx.appl", "ChildWindow registered multiple times!");
205 pImpl
->pFactArr
->push_back( pFact
);
208 //-------------------------------------------------------------------------
210 void SfxModule::RegisterToolBoxControl( SfxTbxCtrlFactory
*pFact
)
212 if (!pImpl
->pTbxCtrlFac
)
213 pImpl
->pTbxCtrlFac
= new SfxTbxCtrlFactArr_Impl
;
216 for ( sal_uInt16 n
=0; n
<pImpl
->pTbxCtrlFac
->size(); n
++ )
218 SfxTbxCtrlFactory
*pF
= (*pImpl
->pTbxCtrlFac
)[n
];
219 if ( pF
->nTypeId
&& pF
->nTypeId
== pFact
->nTypeId
&&
220 (pF
->nSlotId
== pFact
->nSlotId
|| pF
->nSlotId
== 0) )
222 DBG_WARNING("TbxController-Registering is not clearly defined!");
227 pImpl
->pTbxCtrlFac
->push_back( pFact
);
230 //-------------------------------------------------------------------------
232 void SfxModule::RegisterStatusBarControl( SfxStbCtrlFactory
*pFact
)
234 if (!pImpl
->pStbCtrlFac
)
235 pImpl
->pStbCtrlFac
= new SfxStbCtrlFactArr_Impl
;
238 for ( sal_uInt16 n
=0; n
<pImpl
->pStbCtrlFac
->size(); n
++ )
240 SfxStbCtrlFactory
*pF
= (*pImpl
->pStbCtrlFac
)[n
];
241 if ( pF
->nTypeId
&& pF
->nTypeId
== pFact
->nTypeId
&&
242 (pF
->nSlotId
== pFact
->nSlotId
|| pF
->nSlotId
== 0) )
244 DBG_WARNING("TbxController-Registering is not clearly defined!");
249 pImpl
->pStbCtrlFac
->push_back( pFact
);
252 //-------------------------------------------------------------------------
254 void SfxModule::RegisterMenuControl( SfxMenuCtrlFactory
*pFact
)
256 if (!pImpl
->pMenuCtrlFac
)
257 pImpl
->pMenuCtrlFac
= new SfxMenuCtrlFactArr_Impl
;
260 for ( sal_uInt16 n
=0; n
<pImpl
->pMenuCtrlFac
->size(); n
++ )
262 SfxMenuCtrlFactory
*pF
= (*pImpl
->pMenuCtrlFac
)[n
];
263 if ( pF
->nTypeId
&& pF
->nTypeId
== pFact
->nTypeId
&&
264 (pF
->nSlotId
== pFact
->nSlotId
|| pF
->nSlotId
== 0) )
266 DBG_WARNING("MenuController-Registering is not clearly defined!");
271 pImpl
->pMenuCtrlFac
->push_back( pFact
);
274 //-------------------------------------------------------------------------
276 SfxTbxCtrlFactArr_Impl
* SfxModule::GetTbxCtrlFactories_Impl() const
278 return pImpl
->pTbxCtrlFac
;
281 //-------------------------------------------------------------------------
283 SfxStbCtrlFactArr_Impl
* SfxModule::GetStbCtrlFactories_Impl() const
285 return pImpl
->pStbCtrlFac
;
288 //-------------------------------------------------------------------------
290 SfxMenuCtrlFactArr_Impl
* SfxModule::GetMenuCtrlFactories_Impl() const
292 return pImpl
->pMenuCtrlFac
;
295 //-------------------------------------------------------------------------
297 SfxChildWinFactArr_Impl
* SfxModule::GetChildWinFactories_Impl() const
299 return pImpl
->pFactArr
;
302 ImageList
* SfxModule::GetImageList_Impl( sal_Bool bBig
)
304 return pImpl
->GetImageList( pResMgr
, bBig
);
307 SfxTabPage
* SfxModule::CreateTabPage( sal_uInt16
, Window
*, const SfxItemSet
& )
312 SfxModuleArr_Impl
& SfxModule::GetModules_Impl()
315 pModules
= new SfxModuleArr_Impl
;
319 void SfxModule::DestroyModules_Impl()
323 SfxModuleArr_Impl
& rModules
= *pModules
;
324 for( sal_uInt16 nPos
= rModules
.size(); nPos
--; )
326 SfxModule
* pMod
= rModules
[nPos
];
329 delete pModules
, pModules
= 0;
333 void SfxModule::Invalidate( sal_uInt16 nId
)
335 for( SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst(); pFrame
; pFrame
= SfxViewFrame::GetNext( *pFrame
) )
336 if ( pFrame
->GetObjectShell()->GetModule() == this )
337 Invalidate_Impl( pFrame
->GetBindings(), nId
);
340 bool SfxModule::IsChildWindowAvailable( const sal_uInt16 i_nId
, const SfxViewFrame
* i_pViewFrame
) const
342 if ( i_nId
!= SID_TASKPANE
)
343 // by default, assume it is
346 const SfxViewFrame
* pViewFrame
= i_pViewFrame
? i_pViewFrame
: GetFrame();
347 ENSURE_OR_RETURN( pViewFrame
, "SfxModule::IsChildWindowAvailable: no frame to ask for the module identifier!", false );
348 return ::sfx2::ModuleTaskPane::ModuleHasToolPanels( pViewFrame
->GetFrame().GetFrameInterface() );
351 SfxModule
* SfxModule::GetActiveModule( SfxViewFrame
* pFrame
)
354 pFrame
= SfxViewFrame::Current();
355 SfxObjectShell
* pSh
= 0;
357 pSh
= pFrame
->GetObjectShell();
358 return pSh
? pSh
->GetModule() : 0;
361 FieldUnit
SfxModule::GetModuleFieldUnit( ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> const & i_frame
)
363 ENSURE_OR_RETURN( i_frame
.is(), "SfxModule::GetModuleFieldUnit: invalid frame!", FUNIT_100TH_MM
);
365 // find SfxViewFrame for the given XFrame
366 SfxViewFrame
* pViewFrame
= SfxViewFrame::GetFirst();
367 while ( pViewFrame
!= NULL
)
369 if ( pViewFrame
->GetFrame().GetFrameInterface() == i_frame
)
371 pViewFrame
= SfxViewFrame::GetNext( *pViewFrame
);
373 ENSURE_OR_RETURN( pViewFrame
!= NULL
, "SfxModule::GetModuleFieldUnit: unable to find an SfxViewFrame for the given XFrame", FUNIT_100TH_MM
);
376 SfxModule
const * pModule
= GetActiveModule( pViewFrame
);
377 ENSURE_OR_RETURN( pModule
!= NULL
, "SfxModule::GetModuleFieldUnit: no SfxModule for the given frame!", FUNIT_100TH_MM
);
379 return pModule
->GetFieldUnit();
383 FieldUnit
SfxModule::GetCurrentFieldUnit()
385 FieldUnit eUnit
= FUNIT_INCH
;
386 SfxModule
* pModule
= GetActiveModule();
389 const SfxPoolItem
* pItem
= pModule
->GetItem( SID_ATTR_METRIC
);
391 eUnit
= (FieldUnit
)( (SfxUInt16Item
*)pItem
)->GetValue();
394 SAL_WARN( "sfx.appl", "GetModuleFieldUnit(): no module found" );
398 FieldUnit
SfxModule::GetFieldUnit() const
400 FieldUnit eUnit
= FUNIT_INCH
;
401 const SfxPoolItem
* pItem
= GetItem( SID_ATTR_METRIC
);
403 eUnit
= (FieldUnit
)( (SfxUInt16Item
*)pItem
)->GetValue();
407 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */