/* -*- 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 #include #include #include #include #include #include #include #include "sderror.hxx" #include "sdmod.hxx" #include "sdresid.hxx" #include "optsitem.hxx" #include "DrawDocShell.hxx" #include "drawdoc.hxx" #include "app.hrc" #include "glob.hrc" #include "strings.hrc" #include "res_bmp.hrc" #include "cfgids.hxx" #include "tools/SdGlobalResourceContainer.hxx" TYPEINIT1( SdModule, SfxModule ); #define SdModule #include "sdslots.hxx" SFX_IMPL_INTERFACE(SdModule, SfxModule) void SdModule::InitInterface_Impl() { GetStaticInterface()->RegisterStatusBar(SdResId(RID_DRAW_STATUSBAR)); } // Ctor SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 ) : SfxModule( ResMgr::CreateResMgr("sd"), false, pFact1, pFact2, NULL ), pTransferClip(NULL), pTransferDrag(NULL), pTransferSelection(NULL), pImpressOptions(NULL), pDrawOptions(NULL), pSearchItem(NULL), pNumberFormatter( NULL ), bWaterCan(false), mpResourceContainer(new ::sd::SdGlobalResourceContainer()), mbEventListenerAdded(false) { SetName( OUString( "StarDraw" ) ); // Do not translate! pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM); pSearchItem->SetAppFlag(SvxSearchApp::DRAW); StartListening( *SfxGetpApp() ); SvxErrorHandler::ensure(); mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL, ERRCODE_AREA_SD, ERRCODE_AREA_SD_END, GetResMgr() ); // 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::Create()); mpVirtualRefDevice->SetMapMode( MAP_100TH_MM ); mpVirtualRefDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 ); } // Dtor SdModule::~SdModule() { delete pSearchItem; delete pNumberFormatter; if (mbEventListenerAdded) { Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) ); } mpResourceContainer.reset(); // Mark the module in the global AppData structure as deleted. SdModule** ppShellPointer = reinterpret_cast(GetAppData(SHL_DRAW)); if (ppShellPointer != NULL) (*ppShellPointer) = NULL; delete mpErrorHdl; mpVirtualRefDevice.disposeAndClear(); } /// get notifications void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint ) { const SfxSimpleHint* pSimpleHint = dynamic_cast(&rHint); if( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING ) { delete pImpressOptions, pImpressOptions = NULL; delete pDrawOptions, pDrawOptions = NULL; } } /// Return options SdOptions* SdModule::GetSdOptions(DocumentType eDocType) { SdOptions* pOptions = NULL; if (eDocType == DOCUMENT_TYPE_DRAW) { if (!pDrawOptions) pDrawOptions = new SdOptions( SDCFG_DRAW ); pOptions = pDrawOptions; } else if (eDocType == DOCUMENT_TYPE_IMPRESS) { if (!pImpressOptions) pImpressOptions = new SdOptions( SDCFG_IMPRESS ); pOptions = pImpressOptions; } if( pOptions ) { sal_uInt16 nMetric = pOptions->GetMetric(); ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() ); SdDrawDocument* pDoc = NULL; 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 SdModule::GetOptionStream( const OUString& rOptionName, SdOptionStreamMode eMode ) { ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() ); tools::SvRef xStm; if( pDocSh ) { DocumentType eType = pDocSh->GetDoc()->GetDocumentType(); if( !xOptionStorage.Is() ) { INetURLObject aURL( SvtPathOptions().GetUserConfigPath() ); aURL.Append( OUString( "drawing.cfg" ) ); SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE ); if( pStm ) xOptionStorage = new SotStorage( pStm, true ); } OUString aStmName; if( DOCUMENT_TYPE_DRAW == eType ) aStmName = "Draw_"; else aStmName = "Impress_"; aStmName += rOptionName; if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) ) xStm = xOptionStorage->OpenSotStream( aStmName ); } return xStm; } SvNumberFormatter* SdModule::GetNumberFormatter() { if( !pNumberFormatter ) pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM ); return pNumberFormatter; } /** This method is deprecated and only an alias to * GetVirtualRefDevice(). The given argument is ignored. */ OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& ) { return GetVirtualRefDevice(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */