LCOV - code coverage report
Current view: top level - sd/source/ui/app - sdmod.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 63 85 74.1 %
Date: 2014-11-03 Functions: 16 19 84.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <unotools/pathoptions.hxx>
      21             : #include <svl/languageoptions.hxx>
      22             : #include <unotools/ucbstreamhelper.hxx>
      23             : #include <tools/urlobj.hxx>
      24             : #include <vcl/virdev.hxx>
      25             : #include <vcl/status.hxx>
      26             : #include <svl/intitem.hxx>
      27             : #include <sfx2/msg.hxx>
      28             : #include <sfx2/objface.hxx>
      29             : #include <sfx2/printer.hxx>
      30             : #include <sfx2/request.hxx>
      31             : #include <svx/pszctrl.hxx>
      32             : #include <svx/zoomctrl.hxx>
      33             : #include <svx/modctrl.hxx>
      34             : #include <svl/zforlist.hxx>
      35             : #include <comphelper/processfactory.hxx>
      36             : #include <svtools/ehdl.hxx>
      37             : 
      38             : #include <svx/svxids.hrc>
      39             : #include <svl/srchitem.hxx>
      40             : #include <svx/svxerr.hxx>
      41             : 
      42             : #include <svx/xmlsecctrl.hxx>
      43             : 
      44             : #include "sderror.hxx"
      45             : #include "sdmod.hxx"
      46             : #include "sdresid.hxx"
      47             : #include "optsitem.hxx"
      48             : #include "DrawDocShell.hxx"
      49             : #include "drawdoc.hxx"
      50             : #include "app.hrc"
      51             : #include "glob.hrc"
      52             : #include "strings.hrc"
      53             : #include "res_bmp.hrc"
      54             : #include "cfgids.hxx"
      55             : #include "tools/SdGlobalResourceContainer.hxx"
      56             : 
      57        1371 : TYPEINIT1( SdModule, SfxModule );
      58             : 
      59             : #define SdModule
      60             : #include "sdslots.hxx"
      61             : 
      62        4304 : SFX_IMPL_INTERFACE(SdModule, SfxModule, SdResId(STR_APPLICATIONOBJECTBAR))
      63             : 
      64          36 : void SdModule::InitInterface_Impl()
      65             : {
      66          36 :     GetStaticInterface()->RegisterStatusBar(SdResId(RID_DRAW_STATUSBAR));
      67          36 : }
      68             : 
      69             : // Ctor
      70          36 : SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
      71             : :   SfxModule( ResMgr::CreateResMgr("sd"), false,
      72             :                   pFact1, pFact2, NULL ),
      73             :     pTransferClip(NULL),
      74             :     pTransferDrag(NULL),
      75             :     pTransferSelection(NULL),
      76             :     pImpressOptions(NULL),
      77             :     pDrawOptions(NULL),
      78             :     pSearchItem(NULL),
      79             :     pNumberFormatter( NULL ),
      80             :     bWaterCan(false),
      81          36 :     mpResourceContainer(new ::sd::SdGlobalResourceContainer())
      82             : {
      83          36 :     SetName( OUString( "StarDraw" ) );  // Do not translate!
      84          36 :     pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
      85          36 :     pSearchItem->SetAppFlag(SVX_SEARCHAPP_DRAW);
      86          36 :     StartListening( *SfxGetpApp() );
      87          36 :     SvxErrorHandler::ensure();
      88             :     mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL,
      89             :                                          ERRCODE_AREA_SD,
      90             :                                          ERRCODE_AREA_SD_END,
      91          36 :                                          GetResMgr() );
      92             : 
      93             :     // Create a new ref device and (by calling SetReferenceDevice())
      94             :     // set its resolution to 600 DPI.  This leads to a visually better
      95             :     // formatting of text in small sizes (6 point and below.)
      96          36 :     VirtualDevice* pDevice = new VirtualDevice;
      97          36 :     mpVirtualRefDevice = pDevice;
      98          36 :     pDevice->SetMapMode( MAP_100TH_MM );
      99          36 :     pDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 );
     100          36 : }
     101             : 
     102             : // Dtor
     103          66 : SdModule::~SdModule()
     104             : {
     105          22 :     delete pSearchItem;
     106             : 
     107          22 :     if( pNumberFormatter )
     108           2 :         delete pNumberFormatter;
     109             : 
     110          22 :     ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
     111          22 :     if( pDocShell )
     112             :     {
     113           0 :         ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
     114           0 :         if (pViewShell)
     115             :         {
     116             :             // Removing our event listener
     117           0 :             Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
     118             :         }
     119             :     }
     120             : 
     121          22 :     mpResourceContainer.reset();
     122             : 
     123             :     // Mark the module in the global AppData structure as deleted.
     124          22 :     SdModule** ppShellPointer = (SdModule**)GetAppData(SHL_DRAW);
     125          22 :     if (ppShellPointer != NULL)
     126          22 :         (*ppShellPointer) = NULL;
     127             : 
     128          22 :     delete mpErrorHdl;
     129          22 :     delete static_cast< VirtualDevice* >( mpVirtualRefDevice );
     130          44 : }
     131             : 
     132             : /// get notifications
     133        5894 : void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
     134             : {
     135        5894 :     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
     136        5894 :     if( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
     137             :     {
     138          22 :         delete pImpressOptions, pImpressOptions = NULL;
     139          22 :         delete pDrawOptions, pDrawOptions = NULL;
     140             :     }
     141        5894 : }
     142             : 
     143             : /// Return options
     144        3704 : SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
     145             : {
     146        3704 :     SdOptions* pOptions = NULL;
     147             : 
     148        3704 :     if (eDocType == DOCUMENT_TYPE_DRAW)
     149             :     {
     150        1837 :         if (!pDrawOptions)
     151          20 :             pDrawOptions = new SdOptions( SDCFG_DRAW );
     152             : 
     153        1837 :         pOptions = pDrawOptions;
     154             :     }
     155        1867 :     else if (eDocType == DOCUMENT_TYPE_IMPRESS)
     156             :     {
     157        1867 :         if (!pImpressOptions)
     158          22 :             pImpressOptions = new SdOptions( SDCFG_IMPRESS );
     159             : 
     160        1867 :         pOptions = pImpressOptions;
     161             :     }
     162        3704 :     if( pOptions )
     163             :     {
     164        3704 :         sal_uInt16 nMetric = pOptions->GetMetric();
     165             : 
     166        3704 :         ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
     167        3704 :         SdDrawDocument* pDoc = NULL;
     168        3704 :         if (pDocSh)
     169        1026 :             pDoc = pDocSh->GetDoc();
     170             : 
     171        3704 :         if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
     172        1026 :             PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
     173             :     }
     174             : 
     175        3704 :     return(pOptions);
     176             : }
     177             : 
     178             : /**
     179             :  * Open and return option stream for internal options;
     180             :  * if the stream is opened for reading but does not exist, an 'empty'
     181             :  * RefObject is returned
     182             :  */
     183           0 : SvStorageStreamRef SdModule::GetOptionStream( const OUString& rOptionName,
     184             :                                               SdOptionStreamMode eMode )
     185             : {
     186           0 :     ::sd::DrawDocShell*     pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
     187           0 :     SvStorageStreamRef  xStm;
     188             : 
     189           0 :     if( pDocSh )
     190             :     {
     191           0 :         DocumentType    eType = pDocSh->GetDoc()->GetDocumentType();
     192             : 
     193           0 :         if( !xOptionStorage.Is() )
     194             :         {
     195           0 :             INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
     196             : 
     197           0 :             aURL.Append( OUString( "drawing.cfg" ) );
     198             : 
     199           0 :             SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE );
     200             : 
     201           0 :             if( pStm )
     202           0 :                 xOptionStorage = new SvStorage( pStm, true );
     203             :         }
     204             : 
     205           0 :         OUString        aStmName;
     206             : 
     207           0 :         if( DOCUMENT_TYPE_DRAW == eType )
     208           0 :             aStmName = "Draw_";
     209             :         else
     210           0 :             aStmName = "Impress_";
     211             : 
     212           0 :         aStmName += rOptionName;
     213             : 
     214           0 :         if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
     215           0 :             xStm = xOptionStorage->OpenSotStream( aStmName );
     216             :     }
     217             : 
     218           0 :     return xStm;
     219             : }
     220             : 
     221          60 : SvNumberFormatter* SdModule::GetNumberFormatter()
     222             : {
     223          60 :     if( !pNumberFormatter )
     224           6 :         pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM );
     225             : 
     226          60 :     return pNumberFormatter;
     227             : }
     228             : 
     229             : /** This method is deprecated and only an alias to
     230             :  *   <member>GetVirtualRefDevice()</member>.  The given argument is ignored.
     231             :  */
     232         398 : OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& )
     233             : {
     234         398 :     return GetVirtualRefDevice();
     235         114 : }
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10