tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / sfx2 / source / appl / module.cxx
blobf82255446cf97d4f8a1a0d70c569da567c63a75c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <comphelper/diagnose_ex.hxx>
33 #include <unotools/resmgr.hxx>
34 #include <sal/log.hxx>
35 #include <comphelper/lok.hxx>
36 #include <unotools/localedatawrapper.hxx>
38 #define ShellClass_SfxModule
39 #include <sfxslots.hxx>
40 #include <optional>
42 class SfxModule_Impl
44 public:
46 std::optional<SfxSlotPool> pSlotPool;
47 std::vector<SfxTbxCtrlFactory> maTbxCtrlFactories;
48 std::vector<SfxStbCtrlFactory> maStbCtrlFactories;
49 std::vector<SfxChildWinFactory> maFactories;
50 OString maResName;
52 SfxModule_Impl();
53 ~SfxModule_Impl();
56 SfxModule_Impl::SfxModule_Impl()
60 SfxModule_Impl::~SfxModule_Impl()
62 pSlotPool.reset();
63 maTbxCtrlFactories.clear();
64 maStbCtrlFactories.clear();
67 SFX_IMPL_SUPERCLASS_INTERFACE(SfxModule, SfxShell)
69 SfxModule::SfxModule(const OString& rResName, std::initializer_list<SfxObjectFactory*> pFactoryList)
70 : pImpl(nullptr)
72 Construct_Impl(rResName);
73 for (auto pFactory : pFactoryList)
75 if (pFactory)
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.emplace(&pApp->GetAppSlotPool_Impl());
85 pImpl->maResName = rResName;
87 SetPool( &pApp->GetPool() );
90 SfxModule::~SfxModule()
92 //TODO how to silence useuniqueptr
93 if (true)
95 delete pImpl;
99 std::locale SfxModule::GetResLocale() const
101 return Translate::Create(pImpl->maResName);
104 SfxSlotPool* SfxModule::GetSlotPool() const
106 return &*pImpl->pSlotPool;
109 void SfxModule::RegisterChildWindow(const SfxChildWinFactory& rFact)
111 assert(pImpl && "No real Module!");
113 for (size_t nFactory=0; nFactory<pImpl->maFactories.size(); ++nFactory)
115 if (rFact.nId == pImpl->maFactories[nFactory].nId)
117 pImpl->maFactories.erase( pImpl->maFactories.begin() + nFactory );
118 SAL_WARN("sfx.appl", "ChildWindow registered multiple times!");
119 return;
123 pImpl->maFactories.push_back( rFact );
126 void SfxModule::RegisterToolBoxControl( const SfxTbxCtrlFactory& rFact )
128 #ifdef DBG_UTIL
129 for ( size_t n=0; n<pImpl->maTbxCtrlFactories.size(); n++ )
131 SfxTbxCtrlFactory *pF = &pImpl->maTbxCtrlFactories[n];
132 if ( pF->nTypeId == rFact.nTypeId &&
133 (pF->nSlotId == rFact.nSlotId || pF->nSlotId == 0) )
135 SAL_INFO("sfx.appl", "TbxController-Registering is not clearly defined!");
138 #endif
140 pImpl->maTbxCtrlFactories.push_back( rFact );
144 void SfxModule::RegisterStatusBarControl( const SfxStbCtrlFactory& rFact )
146 #ifdef DBG_UTIL
147 for ( size_t n=0; n<pImpl->maStbCtrlFactories.size(); n++ )
149 SfxStbCtrlFactory *pF = &pImpl->maStbCtrlFactories[n];
150 if ( pF->nTypeId == rFact.nTypeId &&
151 (pF->nSlotId == rFact.nSlotId || pF->nSlotId == 0) )
153 SAL_INFO("sfx.appl", "TbxController-Registering is not clearly defined!");
156 #endif
158 pImpl->maStbCtrlFactories.push_back( rFact );
162 SfxTbxCtrlFactory* SfxModule::GetTbxCtrlFactory(const std::type_info& rSlotType, sal_uInt16 nSlotID) const
164 // search for a factory with the given slot id
165 for (auto& rFactory : pImpl->maTbxCtrlFactories)
166 if( rFactory.nTypeId == rSlotType && rFactory.nSlotId == nSlotID )
167 return &rFactory;
169 // if no factory exists for the given slot id, see if we
170 // have a generic factory with the correct slot type and slot id == 0
171 for (auto& rFactory : pImpl->maTbxCtrlFactories)
172 if( rFactory.nTypeId == rSlotType && rFactory.nSlotId == 0 )
173 return &rFactory;
175 return nullptr;
179 SfxStbCtrlFactory* SfxModule::GetStbCtrlFactory(const std::type_info& rSlotType, sal_uInt16 nSlotID) const
181 for (auto& rFactory : pImpl->maStbCtrlFactories)
182 if ( rFactory.nTypeId == rSlotType &&
183 ( rFactory.nSlotId == 0 || rFactory.nSlotId == nSlotID ) )
184 return &rFactory;
185 return nullptr;
188 SfxChildWinFactory* SfxModule::GetChildWinFactoryById(sal_uInt16 nId) const
190 for (auto& rFactory : pImpl->maFactories)
191 if (rFactory.nId == nId)
192 return &rFactory;
193 return nullptr;
196 std::unique_ptr<SfxTabPage> SfxModule::CreateTabPage(sal_uInt16, weld::Container*, weld::DialogController*, const SfxItemSet&)
198 return nullptr;
201 void SfxModule::Invalidate( sal_uInt16 nId )
203 for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) )
204 if ( pFrame->GetObjectShell()->GetModule() == this )
205 Invalidate_Impl( pFrame->GetBindings(), nId );
208 SfxModule* SfxModule::GetActiveModule( SfxViewFrame* pFrame )
210 if ( !pFrame )
211 pFrame = SfxViewFrame::Current();
212 SfxObjectShell* pSh = nullptr;
213 if( pFrame )
214 pSh = pFrame->GetObjectShell();
215 return pSh ? pSh->GetModule() : nullptr;
218 FieldUnit SfxModule::GetModuleFieldUnit( css::uno::Reference< css::frame::XFrame > const & i_frame )
220 ENSURE_OR_RETURN( i_frame.is(), "SfxModule::GetModuleFieldUnit: invalid frame!", FieldUnit::MM_100TH );
222 // find SfxViewFrame for the given XFrame
223 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
224 while ( pViewFrame != nullptr )
226 if ( pViewFrame->GetFrame().GetFrameInterface() == i_frame )
227 break;
228 pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
230 ENSURE_OR_RETURN(
231 pViewFrame != nullptr,
232 "SfxModule::GetModuleFieldUnit: unable to find an SfxViewFrame for the given XFrame",
233 FieldUnit::MM_100TH);
235 // find the module
236 SfxModule const * pModule = GetActiveModule( pViewFrame );
237 ENSURE_OR_RETURN(pModule != nullptr,
238 "SfxModule::GetModuleFieldUnit: no SfxModule for the given frame!",
239 FieldUnit::MM_100TH);
240 return pModule->GetFieldUnit();
243 FieldUnit SfxModule::GetCurrentFieldUnit()
245 FieldUnit eUnit = FieldUnit::INCH;
246 SfxModule* pModule = GetActiveModule();
247 if ( pModule )
248 return pModule->GetFieldUnit();
249 else
250 SAL_WARN( "sfx.appl", "GetModuleFieldUnit(): no module found" );
251 return eUnit;
254 FieldUnit SfxModule::GetFieldUnit() const
256 if (comphelper::LibreOfficeKit::isActive())
258 MeasurementSystem eSystem
259 = LocaleDataWrapper(comphelper::LibreOfficeKit::getLocale()).getMeasurementSystemEnum();
260 return MeasurementSystem::Metric == eSystem ? FieldUnit::CM : FieldUnit::INCH;
262 FieldUnit eUnit = FieldUnit::INCH;
263 const SfxPoolItem* pItem = GetItem( SID_ATTR_METRIC );
264 if ( pItem )
265 eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
266 return eUnit;
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */