diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sd/source/ui/app/sdmod.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sd/source/ui/app/sdmod.cxx')
-rw-r--r-- | sd/source/ui/app/sdmod.cxx | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/sd/source/ui/app/sdmod.cxx b/sd/source/ui/app/sdmod.cxx new file mode 100644 index 000000000..c7d56831d --- /dev/null +++ b/sd/source/ui/app/sdmod.cxx @@ -0,0 +1,216 @@ +/* -*- 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 <unotools/pathoptions.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <unotools/resmgr.hxx> +#include <tools/urlobj.hxx> +#include <vcl/virdev.hxx> +#include <vcl/svapp.hxx> +#include <svl/numformat.hxx> +#include <svl/intitem.hxx> +#include <sfx2/msg.hxx> +#include <sfx2/objface.hxx> +#include <comphelper/processfactory.hxx> +#include <svtools/ehdl.hxx> + +#include <svx/svxids.hrc> +#include <svl/srchitem.hxx> +#include <svx/svxerr.hxx> + +#include <svtools/colorcfg.hxx> + +#include <sdmod.hxx> +#include <sdresid.hxx> +#include <optsitem.hxx> +#include <DrawDocShell.hxx> +#include <drawdoc.hxx> +#include <errhdl.hrc> + +#define ShellClass_SdModule +#include <sdslots.hxx> + +SFX_IMPL_INTERFACE(SdModule, SfxModule) + +void SdModule::InitInterface_Impl() +{ + GetStaticInterface()->RegisterStatusBar(StatusBarId::DrawStatusBar); +} + +// Ctor +SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 ) +: SfxModule("sd", {pFact1, pFact2}), + pTransferClip(nullptr), + pTransferDrag(nullptr), + pTransferSelection(nullptr), + pImpressOptions(nullptr), + pDrawOptions(nullptr), + bWaterCan(false), + mbEventListenerAdded(false), + mpColorConfig(new svtools::ColorConfig) +{ + SetName( "StarDraw" ); // Do not translate! + pSearchItem.reset( new SvxSearchItem(SID_SEARCH_ITEM) ); + pSearchItem->SetAppFlag(SvxSearchApp::DRAW); + StartListening( *SfxGetpApp() ); + SvxErrorHandler::ensure(); + mpErrorHdl.reset( new SfxErrorHandler(RID_SD_ERRHDL, ErrCodeArea::Sd, ErrCodeArea::Sd, GetResLocale()) ); + + // Create a new ref device and (by calling SetReferenceDevice()) + // set its resolution to 600 DPI. This leads to a visually better + // formatting of text in small sizes (6 point and below.) + mpVirtualRefDevice.reset(VclPtr<VirtualDevice>::Create()); + mpVirtualRefDevice->SetMapMode(MapMode(MapUnit::Map100thMM)); + mpVirtualRefDevice->SetReferenceDevice ( VirtualDevice::RefDevMode::Dpi600 ); +} + +OUString SdResId(TranslateId aId) +{ + return Translate::get(aId, SD_MOD()->GetResLocale()); +} + +OUString SdResId(TranslateNId aContextSingularPlural, int nCardinality) +{ + return Translate::nget(aContextSingularPlural, nCardinality, SD_MOD()->GetResLocale()); +} + +// Dtor +SdModule::~SdModule() +{ + pSearchItem.reset(); + pNumberFormatter.reset(); + + if (mbEventListenerAdded) + { + Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) ); + } + + mpErrorHdl.reset(); + mpVirtualRefDevice.disposeAndClear(); +} + +void SdModule::SetSearchItem(std::unique_ptr<SvxSearchItem> pItem) +{ + pSearchItem = std::move(pItem); +} + +/// get notifications +void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint ) +{ + if( rHint.GetId() == SfxHintId::Deinitializing ) + { + delete pImpressOptions; + pImpressOptions = nullptr; + delete pDrawOptions; + pDrawOptions = nullptr; + } +} + +/// Return options +SdOptions* SdModule::GetSdOptions(DocumentType eDocType) +{ + SdOptions* pOptions = nullptr; + + if (eDocType == DocumentType::Draw) + { + if (!pDrawOptions) + pDrawOptions = new SdOptions(false); + + pOptions = pDrawOptions; + } + else if (eDocType == DocumentType::Impress) + { + if (!pImpressOptions) + pImpressOptions = new SdOptions(true); + + pOptions = pImpressOptions; + } + if( pOptions ) + { + sal_uInt16 nMetric = pOptions->GetMetric(); + + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + SdDrawDocument* pDoc = nullptr; + if (pDocSh) + pDoc = pDocSh->GetDoc(); + + if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() ) + PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) ); + } + + return pOptions; +} + +/** + * Open and return option stream for internal options; + * if the stream is opened for reading but does not exist, an 'empty' + * RefObject is returned + */ +tools::SvRef<SotStorageStream> SdModule::GetOptionStream( std::u16string_view rOptionName, + SdOptionStreamMode eMode ) +{ + ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() ); + tools::SvRef<SotStorageStream> xStm; + + if( pDocSh ) + { + DocumentType eType = pDocSh->GetDoc()->GetDocumentType(); + + if( !xOptionStorage.is() ) + { + INetURLObject aURL( SvtPathOptions().GetUserConfigPath() ); + + aURL.Append( u"drawing.cfg" ); + + std::unique_ptr<SvStream> pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READWRITE ); + + if( pStm ) + xOptionStorage = new SotStorage( pStm.release(), true ); + } + + OUString aStmName; + + if( DocumentType::Draw == eType ) + aStmName = "Draw_"; + else + aStmName = "Impress_"; + + aStmName += rOptionName; + + if( SdOptionStreamMode::Store == eMode || xOptionStorage->IsContained( aStmName ) ) + xStm = xOptionStorage->OpenSotStream( aStmName ); + } + + return xStm; +} + +SvNumberFormatter* SdModule::GetNumberFormatter() +{ + if( !pNumberFormatter ) + pNumberFormatter.reset( new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM ) ); + + return pNumberFormatter.get(); +} + +svtools::ColorConfig& SdModule::GetColorConfig() +{ + return *mpColorConfig; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |