LCOV - code coverage report
Current view: top level - sd/source/ui/app - sdmod.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 64 86 74.4 %
Date: 2014-04-11 Functions: 17 20 85.0 %
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 <sfx2/app.hxx>
      26             : #include <vcl/status.hxx>
      27             : #include <svl/intitem.hxx>
      28             : #include <sfx2/msg.hxx>
      29             : #include <sfx2/objface.hxx>
      30             : #include <sfx2/printer.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         642 : TYPEINIT1( SdModule, SfxModule );
      58             : 
      59             : #define SdModule
      60             : #include "sdslots.hxx"
      61             : 
      62             : 
      63        2886 : SFX_IMPL_INTERFACE(SdModule, SfxModule, SdResId(STR_APPLICATIONOBJECTBAR))
      64             : {
      65          16 :     SFX_STATUSBAR_REGISTRATION(SdResId(RID_DRAW_STATUSBAR));
      66          16 : }
      67             : 
      68             : // Ctor
      69          16 : SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
      70             : :   SfxModule( SfxApplication::CreateResManager("sd"), false,
      71             :                   pFact1, pFact2, NULL ),
      72             :     pTransferClip(NULL),
      73             :     pTransferDrag(NULL),
      74             :     pTransferSelection(NULL),
      75             :     pImpressOptions(NULL),
      76             :     pDrawOptions(NULL),
      77             :     pSearchItem(NULL),
      78             :     pNumberFormatter( NULL ),
      79             :     bWaterCan(sal_False),
      80          16 :     mpResourceContainer(new ::sd::SdGlobalResourceContainer())
      81             : {
      82          16 :     SetName( OUString( "StarDraw" ) );  // Do not translate!
      83          16 :     pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
      84          16 :     pSearchItem->SetAppFlag(SVX_SEARCHAPP_DRAW);
      85          16 :     StartListening( *SFX_APP() );
      86          16 :     SvxErrorHandler::ensure();
      87             :     mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL,
      88             :                                          ERRCODE_AREA_SD,
      89             :                                          ERRCODE_AREA_SD_END,
      90          16 :                                          GetResMgr() );
      91             : 
      92             :     // Create a new ref device and (by calling SetReferenceDevice())
      93             :     // set its resolution to 600 DPI.  This leads to a visually better
      94             :     // formatting of text in small sizes (6 point and below.)
      95          16 :     VirtualDevice* pDevice = new VirtualDevice;
      96          16 :     mpVirtualRefDevice = pDevice;
      97          16 :     pDevice->SetMapMode( MAP_100TH_MM );
      98          16 :     pDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 );
      99          16 : }
     100             : 
     101             : // Dtor
     102          33 : SdModule::~SdModule()
     103             : {
     104          11 :     delete pSearchItem;
     105             : 
     106          11 :     if( pNumberFormatter )
     107           1 :         delete pNumberFormatter;
     108             : 
     109          11 :     ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
     110          11 :     if( pDocShell )
     111             :     {
     112           0 :         ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
     113           0 :         if (pViewShell)
     114             :         {
     115             :             // Removing our event listener
     116           0 :             Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
     117             :         }
     118             :     }
     119             : 
     120          11 :     mpResourceContainer.reset();
     121             : 
     122             :     // Mark the module in the global AppData structure as deleted.
     123          11 :     SdModule** ppShellPointer = (SdModule**)GetAppData(SHL_DRAW);
     124          11 :     if (ppShellPointer != NULL)
     125          11 :         (*ppShellPointer) = NULL;
     126             : 
     127          11 :     delete mpErrorHdl;
     128          11 :     delete static_cast< VirtualDevice* >( mpVirtualRefDevice );
     129          22 : }
     130             : 
     131             : /// get notifications
     132        2594 : void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
     133             : {
     134        2678 :     if( rHint.ISA( SfxSimpleHint ) &&
     135          84 :         ( (SfxSimpleHint&) rHint ).GetId() == SFX_HINT_DEINITIALIZING )
     136             :     {
     137          11 :         delete pImpressOptions, pImpressOptions = NULL;
     138          11 :         delete pDrawOptions, pDrawOptions = NULL;
     139             :     }
     140        2594 : }
     141             : 
     142             : /// Return options
     143        1897 : SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
     144             : {
     145        1897 :     SdOptions* pOptions = NULL;
     146             : 
     147        1897 :     if (eDocType == DOCUMENT_TYPE_DRAW)
     148             :     {
     149        1159 :         if (!pDrawOptions)
     150          10 :             pDrawOptions = new SdOptions( SDCFG_DRAW );
     151             : 
     152        1159 :         pOptions = pDrawOptions;
     153             :     }
     154         738 :     else if (eDocType == DOCUMENT_TYPE_IMPRESS)
     155             :     {
     156         738 :         if (!pImpressOptions)
     157           9 :             pImpressOptions = new SdOptions( SDCFG_IMPRESS );
     158             : 
     159         738 :         pOptions = pImpressOptions;
     160             :     }
     161        1897 :     if( pOptions )
     162             :     {
     163        1897 :         sal_uInt16 nMetric = pOptions->GetMetric();
     164             : 
     165        1897 :         ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
     166        1897 :         SdDrawDocument* pDoc = NULL;
     167        1897 :         if (pDocSh)
     168         479 :             pDoc = pDocSh->GetDoc();
     169             : 
     170        1897 :         if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
     171         479 :             PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
     172             :     }
     173             : 
     174        1897 :     return(pOptions);
     175             : }
     176             : 
     177             : /**
     178             :  * Open and return option stream for internal options;
     179             :  * if the stream is opened for reading but does not exist, an 'empty'
     180             :  * RefObject is returned
     181             :  */
     182           0 : SvStorageStreamRef SdModule::GetOptionStream( const OUString& rOptionName,
     183             :                                               SdOptionStreamMode eMode )
     184             : {
     185           0 :     ::sd::DrawDocShell*     pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
     186           0 :     SvStorageStreamRef  xStm;
     187             : 
     188           0 :     if( pDocSh )
     189             :     {
     190           0 :         DocumentType    eType = pDocSh->GetDoc()->GetDocumentType();
     191             : 
     192           0 :         if( !xOptionStorage.Is() )
     193             :         {
     194           0 :             INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
     195             : 
     196           0 :             aURL.Append( OUString( "drawing.cfg" ) );
     197             : 
     198           0 :             SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE );
     199             : 
     200           0 :             if( pStm )
     201           0 :                 xOptionStorage = new SvStorage( pStm, true );
     202             :         }
     203             : 
     204           0 :         OUString        aStmName;
     205             : 
     206           0 :         if( DOCUMENT_TYPE_DRAW == eType )
     207           0 :             aStmName = "Draw_";
     208             :         else
     209           0 :             aStmName = "Impress_";
     210             : 
     211           0 :         aStmName += rOptionName;
     212             : 
     213           0 :         if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
     214           0 :             xStm = xOptionStorage->OpenSotStream( aStmName );
     215             :     }
     216             : 
     217           0 :     return xStm;
     218             : }
     219             : 
     220          13 : SvNumberFormatter* SdModule::GetNumberFormatter()
     221             : {
     222          13 :     if( !pNumberFormatter )
     223           3 :         pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM );
     224             : 
     225          13 :     return pNumberFormatter;
     226             : }
     227             : 
     228         485 : OutputDevice* SdModule::GetVirtualRefDevice (void)
     229             : {
     230         485 :     return mpVirtualRefDevice;
     231             : }
     232             : 
     233             : /** This method is deprecated and only an alias to
     234             :  *   <member>GetVirtualRefDevice()</member>.  The given argument is ignored.
     235             :  */
     236         151 : OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& )
     237             : {
     238         151 :     return GetVirtualRefDevice();
     239          48 : }
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10