/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ShellClass_SfxModule #include #include #include class SfxModule_Impl { public: std::unique_ptr pSlotPool; std::unique_ptr pTbxCtrlFac; std::unique_ptr pStbCtrlFac; std::unique_ptr pFactArr; OString maResName; SfxModule_Impl(); ~SfxModule_Impl(); }; SfxModule_Impl::SfxModule_Impl() { } SfxModule_Impl::~SfxModule_Impl() { pSlotPool.reset(); pTbxCtrlFac.reset(); pStbCtrlFac.reset(); pFactArr.reset(); } SFX_IMPL_SUPERCLASS_INTERFACE(SfxModule, SfxShell) SfxModule::SfxModule(const OString& rResName, std::initializer_list pFactoryList) : pImpl(nullptr) { Construct_Impl(rResName); for (auto pFactory : pFactoryList) { if (pFactory) pFactory->SetModule_Impl( this ); } } void SfxModule::Construct_Impl(const OString& rResName) { SfxApplication *pApp = SfxApplication::GetOrCreate(); pImpl = new SfxModule_Impl; pImpl->pSlotPool.reset( new SfxSlotPool(&pApp->GetAppSlotPool_Impl()) ); pImpl->maResName = rResName; SetPool( &pApp->GetPool() ); } SfxModule::~SfxModule() { //TODO how to silence useuniqueptr if (true) { delete pImpl; } } std::locale SfxModule::GetResLocale() const { return Translate::Create(pImpl->maResName.getStr()); } SfxSlotPool* SfxModule::GetSlotPool() const { return pImpl->pSlotPool.get(); } void SfxModule::RegisterChildWindow(std::unique_ptr pFact) { DBG_ASSERT( pImpl, "No real Module!" ); if (!pImpl->pFactArr) pImpl->pFactArr.reset( new SfxChildWinFactArr_Impl ); for (size_t nFactory=0; nFactorypFactArr->size(); ++nFactory) { if (pFact->nId == (*pImpl->pFactArr)[nFactory].nId) { pImpl->pFactArr->erase( pImpl->pFactArr->begin() + nFactory ); SAL_WARN("sfx.appl", "ChildWindow registered multiple times!"); return; } } pImpl->pFactArr->push_back( std::move(pFact) ); } void SfxModule::RegisterToolBoxControl( const SfxTbxCtrlFactory& rFact ) { if (!pImpl->pTbxCtrlFac) pImpl->pTbxCtrlFac.reset( new SfxTbxCtrlFactArr_Impl ); #ifdef DBG_UTIL for ( size_t n=0; npTbxCtrlFac->size(); n++ ) { SfxTbxCtrlFactory *pF = &(*pImpl->pTbxCtrlFac)[n]; if ( pF->nTypeId == rFact.nTypeId && (pF->nSlotId == rFact.nSlotId || pF->nSlotId == 0) ) { SAL_INFO("sfx.appl", "TbxController-Registering is not clearly defined!"); } } #endif pImpl->pTbxCtrlFac->push_back( rFact ); } void SfxModule::RegisterStatusBarControl( const SfxStbCtrlFactory& rFact ) { if (!pImpl->pStbCtrlFac) pImpl->pStbCtrlFac.reset( new SfxStbCtrlFactArr_Impl ); #ifdef DBG_UTIL for ( size_t n=0; npStbCtrlFac->size(); n++ ) { SfxStbCtrlFactory *pF = &(*pImpl->pStbCtrlFac)[n]; if ( pF->nTypeId == rFact.nTypeId && (pF->nSlotId == rFact.nSlotId || pF->nSlotId == 0) ) { SAL_INFO("sfx.appl", "TbxController-Registering is not clearly defined!"); } } #endif pImpl->pStbCtrlFac->push_back( rFact ); } SfxTbxCtrlFactArr_Impl* SfxModule::GetTbxCtrlFactories_Impl() const { return pImpl->pTbxCtrlFac.get(); } SfxStbCtrlFactArr_Impl* SfxModule::GetStbCtrlFactories_Impl() const { return pImpl->pStbCtrlFac.get(); } SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const { return pImpl->pFactArr.get(); } std::unique_ptr SfxModule::CreateTabPage(sal_uInt16, weld::Container*, weld::DialogController*, const SfxItemSet&) { return nullptr; } void SfxModule::Invalidate( sal_uInt16 nId ) { for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) ) if ( pFrame->GetObjectShell()->GetModule() == this ) Invalidate_Impl( pFrame->GetBindings(), nId ); } SfxModule* SfxModule::GetActiveModule( SfxViewFrame* pFrame ) { if ( !pFrame ) pFrame = SfxViewFrame::Current(); SfxObjectShell* pSh = nullptr; if( pFrame ) pSh = pFrame->GetObjectShell(); return pSh ? pSh->GetModule() : nullptr; } FieldUnit SfxModule::GetModuleFieldUnit( css::uno::Reference< css::frame::XFrame > const & i_frame ) { ENSURE_OR_RETURN( i_frame.is(), "SfxModule::GetModuleFieldUnit: invalid frame!", FieldUnit::MM_100TH ); // find SfxViewFrame for the given XFrame SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(); while ( pViewFrame != nullptr ) { if ( pViewFrame->GetFrame().GetFrameInterface() == i_frame ) break; pViewFrame = SfxViewFrame::GetNext( *pViewFrame ); } ENSURE_OR_RETURN( pViewFrame != nullptr, "SfxModule::GetModuleFieldUnit: unable to find an SfxViewFrame for the given XFrame", FieldUnit::MM_100TH); // find the module SfxModule const * pModule = GetActiveModule( pViewFrame ); ENSURE_OR_RETURN(pModule != nullptr, "SfxModule::GetModuleFieldUnit: no SfxModule for the given frame!", FieldUnit::MM_100TH); return pModule->GetFieldUnit(); } FieldUnit SfxModule::GetCurrentFieldUnit() { FieldUnit eUnit = FieldUnit::INCH; SfxModule* pModule = GetActiveModule(); if ( pModule ) { const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC ); if ( pItem ) eUnit = static_cast(static_cast(pItem)->GetValue()); } else SAL_WARN( "sfx.appl", "GetModuleFieldUnit(): no module found" ); return eUnit; } FieldUnit SfxModule::GetFieldUnit() const { FieldUnit eUnit = FieldUnit::INCH; const SfxPoolItem* pItem = GetItem( SID_ATTR_METRIC ); if ( pItem ) eUnit = static_cast(static_cast(pItem)->GetValue()); return eUnit; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ lue='distro/mimo/mimo-6-3'>distro/mimo/mimo-6-3 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
12 daysITEM: Refactor ItemTypeArmin Le Grand (Collabora)
ItemType is useful and faster than RTTI. Until now it was implemented by a 16-bit member in the base class, plus (potentially) all constructors having to hand a value in at item construction type (of type SfxItemType) to get that member set correctly. This works, but there is no reliable way to guarantee coverage, and there have already been cases with missing SfxItemType - these fallback to '0' and thus all Items with ItemType() == 0 are assumed equal and might be static_cast'ed to the wrong classes. Note that I identified *35* Items that had no correct ItemType set/implemented actually. It also uses 16-bit per incarnated Item at runtime. I thought and realized now a more systematic approach to do that with a pure virtual function at the Item itself. That can also be secured by a clang compiler plugin in the future to keep it working. It uses one virtual function per derived class, no longer space in incarnated Items. Also the constructors will get more simple again. But the main aspect is security - we cannot afford Items potentially being held as equal if they are not. Unfortunately C++ does not offer something like a 'strict pure virtual function' that would force to be overloaded in every derivation, but the used methotology and adding a clang test is reasonably safe. Have now done the cleanup of previous method. Change-Id: I04768285f1e9b73d64b0bb87df401944b5d35678 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180017 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2024-11-19svx: prefix members of SvxB3DVectorItemMiklos Vajna
See tdf#94879 for motivation. Change-Id: I74c53028d9966ca4059c7a145b3fb0d914d8ae77 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176770 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
2024-07-09Revert "fix and simplify the ItemInstanceManager mechanism"Noel Grandin
This reverts commit 85fd526fc681a994415bb422090d1d23aa7d54f6. Change-Id: I5019f72f88497f50a77666d57f2d16c2749bd1c9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170218 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2024-07-08make SvxB3DVectorItem hashableNoel Grandin
Change-Id: I759d5f225769d3833c6da664793a9d400a398a51 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170147 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2024-06-18Add SfxItemType to SfxPoolItemOliver Specht
The SfxPoolItem has a new member SfxItemType m_eItemType to compare types based on enums instead of typeinfo() which consumes a lot of time e.g. while AutoFormat is running Change-Id: I033ce67bc9a28ee4790f162380314de85fb4154e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166452 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de> Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
2022-01-29used TypedWhichId in the constructor of various svx *Item classesNoel Grandin
to act as an extra check that we have the association of Item and TypedWhichId annotations correct. (*) requires that I add an upcasting constructor to TypedWhichId (*) Make the field dialog stuff in writer use a new item id FN_FIELD_DIALOG_DOC_PROPS instead of abusing the existing SID_DOCINFO Change-Id: Ica4aea930c80124609a063768c9af5a189df1c27 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129098 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-03-19silence coverity unchecked return value from library on xmlText* functionsCaolán McNamara
Change-Id: I651abb00d8ae1bdbf758a6a0176fd8912531a585 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112753 Tested-by: Caolán McNamara <caolanm@redhat.com> Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2020-11-25tdf#42949 Fix new IWYU warnings in directory svxGabor Kelemen
Found with bin/find-unneeded-includes Only removal proposals are dealt with here. Change-Id: If578c5119b85f991825e91df37c42e28f16e9de5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100555 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>