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 .
20 #include <sfx2/module.hxx>
21 #include <sfx2/app.hxx>
22 #include <sfx2/msgpool.hxx>
23 #include <sfx2/tbxctrl.hxx>
24 #include <sfx2/stbitem.hxx>
25 #include <sfx2/childwin.hxx>
26 #include <sfx2/docfac.hxx>
27 #include <sfx2/objface.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/tabdlg.hxx>
30 #include <sfx2/sfxsids.hrc>
31 #include <svl/intitem.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <unotools/resmgr.hxx>
34 #include <sal/log.hxx>
36 #define ShellClass_SfxModule
37 #include <sfxslots.hxx>
38 #include <childwinimpl.hxx>
39 #include <ctrlfactoryimpl.hxx>
45 std::unique_ptr
<SfxSlotPool
> pSlotPool
;
46 std::unique_ptr
<SfxTbxCtrlFactArr_Impl
> pTbxCtrlFac
;
47 std::unique_ptr
<SfxStbCtrlFactArr_Impl
> pStbCtrlFac
;
48 std::unique_ptr
<SfxChildWinFactArr_Impl
> pFactArr
;
55 SfxModule_Impl::SfxModule_Impl()
59 SfxModule_Impl::~SfxModule_Impl()
67 SFX_IMPL_SUPERCLASS_INTERFACE(SfxModule
, SfxShell
)
69 SfxModule::SfxModule(const OString
& rResName
, std::initializer_list
<SfxObjectFactory
*> pFactoryList
)
72 Construct_Impl(rResName
);
73 for (auto pFactory
: pFactoryList
)
76 pFactory
->SetModule_Impl( this );
80 void SfxModule::Construct_Impl(const OString
& rResName
)
82 SfxApplication
*pApp
= SfxApplication::GetOrCreate();
83 pImpl
= new SfxModule_Impl
;
84 pImpl
->pSlotPool
.reset( new SfxSlotPool(&pApp
->GetAppSlotPool_Impl()) );
85 pImpl
->maResName
= rResName
;
87 SetPool( &pApp
->GetPool() );
90 SfxModule::~SfxModule()
92 //TODO how to silence useuniqueptr
99 std::locale
SfxModule::GetResLocale() const
101 return Translate::Create(pImpl
->maResName
.getStr());
104 SfxSlotPool
* SfxModule::GetSlotPool() const
106 return pImpl
->pSlotPool
.get();
110 void SfxModule::RegisterChildWindow(std::unique_ptr
<SfxChildWinFactory
> pFact
)
112 DBG_ASSERT( pImpl
, "No real Module!" );
114 if (!pImpl
->pFactArr
)
115 pImpl
->pFactArr
.reset( new SfxChildWinFactArr_Impl
);
117 for (size_t nFactory
=0; nFactory
<pImpl
->pFactArr
->size(); ++nFactory
)
119 if (pFact
->nId
== (*pImpl
->pFactArr
)[nFactory
].nId
)
121 pImpl
->pFactArr
->erase( pImpl
->pFactArr
->begin() + nFactory
);
122 SAL_WARN("sfx.appl", "ChildWindow registered multiple times!");
127 pImpl
->pFactArr
->push_back( std::move(pFact
) );
131 void SfxModule::RegisterToolBoxControl( const SfxTbxCtrlFactory
& rFact
)
133 if (!pImpl
->pTbxCtrlFac
)
134 pImpl
->pTbxCtrlFac
.reset( new SfxTbxCtrlFactArr_Impl
);
137 for ( size_t n
=0; n
<pImpl
->pTbxCtrlFac
->size(); n
++ )
139 SfxTbxCtrlFactory
*pF
= &(*pImpl
->pTbxCtrlFac
)[n
];
140 if ( pF
->nTypeId
== rFact
.nTypeId
&&
141 (pF
->nSlotId
== rFact
.nSlotId
|| pF
->nSlotId
== 0) )
143 SAL_INFO("sfx.appl", "TbxController-Registering is not clearly defined!");
148 pImpl
->pTbxCtrlFac
->push_back( rFact
);
152 void SfxModule::RegisterStatusBarControl( const SfxStbCtrlFactory
& rFact
)
154 if (!pImpl
->pStbCtrlFac
)
155 pImpl
->pStbCtrlFac
.reset( new SfxStbCtrlFactArr_Impl
);
158 for ( size_t n
=0; n
<pImpl
->pStbCtrlFac
->size(); n
++ )
160 SfxStbCtrlFactory
*pF
= &(*pImpl
->pStbCtrlFac
)[n
];
161 if ( pF
->nTypeId
== rFact
.nTypeId
&&
162 (pF
->nSlotId
== rFact
.nSlotId
|| pF
->nSlotId
== 0) )
164 SAL_INFO("sfx.appl", "TbxController-Registering is not clearly defined!");
169 pImpl
->pStbCtrlFac
->push_back( rFact
);
173 SfxTbxCtrlFactArr_Impl
* SfxModule::GetTbxCtrlFactories_Impl() const
175 return pImpl
->pTbxCtrlFac
.get();
179 SfxStbCtrlFactArr_Impl
* SfxModule::GetStbCtrlFactories_Impl() const
181 return pImpl
->pStbCtrlFac
.get();
184 SfxChildWinFactArr_Impl
* SfxModule::GetChildWinFactories_Impl() const
186 return pImpl
->pFactArr
.get();
189 std::unique_ptr
<SfxTabPage
> SfxModule::CreateTabPage(sal_uInt16
, weld::Container
*, weld::DialogController
*, const SfxItemSet
&)
194 void SfxModule::Invalidate( sal_uInt16 nId
)
196 for( SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst(); pFrame
; pFrame
= SfxViewFrame::GetNext( *pFrame
) )
197 if ( pFrame
->GetObjectShell()->GetModule() == this )
198 Invalidate_Impl( pFrame
->GetBindings(), nId
);
201 SfxModule
* SfxModule::GetActiveModule( SfxViewFrame
* pFrame
)
204 pFrame
= SfxViewFrame::Current();
205 SfxObjectShell
* pSh
= nullptr;
207 pSh
= pFrame
->GetObjectShell();
208 return pSh
? pSh
->GetModule() : nullptr;
211 FieldUnit
SfxModule::GetModuleFieldUnit( css::uno::Reference
< css::frame::XFrame
> const & i_frame
)
213 ENSURE_OR_RETURN( i_frame
.is(), "SfxModule::GetModuleFieldUnit: invalid frame!", FieldUnit::MM_100TH
);
215 // find SfxViewFrame for the given XFrame
216 SfxViewFrame
* pViewFrame
= SfxViewFrame::GetFirst();
217 while ( pViewFrame
!= nullptr )
219 if ( pViewFrame
->GetFrame().GetFrameInterface() == i_frame
)
221 pViewFrame
= SfxViewFrame::GetNext( *pViewFrame
);
224 pViewFrame
!= nullptr,
225 "SfxModule::GetModuleFieldUnit: unable to find an SfxViewFrame for the given XFrame",
226 FieldUnit::MM_100TH
);
229 SfxModule
const * pModule
= GetActiveModule( pViewFrame
);
230 ENSURE_OR_RETURN(pModule
!= nullptr,
231 "SfxModule::GetModuleFieldUnit: no SfxModule for the given frame!",
232 FieldUnit::MM_100TH
);
233 return pModule
->GetFieldUnit();
236 FieldUnit
SfxModule::GetCurrentFieldUnit()
238 FieldUnit eUnit
= FieldUnit::INCH
;
239 SfxModule
* pModule
= GetActiveModule();
242 const SfxPoolItem
* pItem
= pModule
->GetItem( SID_ATTR_METRIC
);
244 eUnit
= static_cast<FieldUnit
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
247 SAL_WARN( "sfx.appl", "GetModuleFieldUnit(): no module found" );
251 FieldUnit
SfxModule::GetFieldUnit() const
253 FieldUnit eUnit
= FieldUnit::INCH
;
254 const SfxPoolItem
* pItem
= GetItem( SID_ATTR_METRIC
);
256 eUnit
= static_cast<FieldUnit
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */