LCOV - code coverage report
Current view: top level - sw/source/core/doc - DocumentDeviceManager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 132 158 83.5 %
Date: 2014-11-03 Functions: 16 18 88.9 %
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 <DocumentDeviceManager.hxx>
      21             : 
      22             : #include <IDocumentDeviceAccess.hxx>
      23             : #include <doc.hxx>
      24             : #include <DocumentSettingManager.hxx>
      25             : #include <IDocumentDrawModelAccess.hxx>
      26             : #include <IDocumentState.hxx>
      27             : #include <IDocumentLayoutAccess.hxx>
      28             : #include <sfx2/printer.hxx>
      29             : #include <vcl/virdev.hxx>
      30             : #include <vcl/outdev.hxx>
      31             : #include <vcl/jobset.hxx>
      32             : #include <printdata.hxx>
      33             : #include <vcl/mapmod.hxx>
      34             : #include <svl/itemset.hxx>
      35             : #include <svx/svdmodel.hxx>
      36             : #include <cmdid.h>
      37             : #include <drawdoc.hxx>
      38             : #include <wdocsh.hxx>
      39             : #include <prtopt.hxx>
      40             : #include <viewsh.hxx>
      41             : #include <rootfrm.hxx>
      42             : #include <viewopt.hxx>
      43             : #include <swwait.hxx>
      44             : #include <fntcache.hxx>
      45             : 
      46             : 
      47             : class SwDocShell;
      48             : class SwWait;
      49             : 
      50             : 
      51             : namespace sw {
      52             : 
      53        5052 : DocumentDeviceManager::DocumentDeviceManager( SwDoc& i_rSwdoc ) : m_rSwdoc( i_rSwdoc ), mpPrt(0), mpVirDev(0), mpPrtData(0) {}
      54             : 
      55       47550 : SfxPrinter* DocumentDeviceManager::getPrinter(/*[in]*/ bool bCreate ) const
      56             : {
      57       47550 :     SfxPrinter* pRet = 0;
      58       47550 :     if ( !bCreate ||  mpPrt )
      59       47522 :         pRet =  mpPrt;
      60             :     else
      61          28 :         pRet = &CreatePrinter_();
      62             : 
      63       47550 :     return pRet;
      64             : }
      65             : 
      66          48 : void DocumentDeviceManager::setPrinter(/*[in]*/ SfxPrinter *pP,/*[in]*/ bool bDeleteOld,/*[in]*/ bool bCallPrtDataChanged )
      67             : {
      68          48 :     if ( pP !=  mpPrt )
      69             :     {
      70          46 :         if ( bDeleteOld )
      71          46 :             delete  mpPrt;
      72          46 :          mpPrt = pP;
      73             : 
      74             :         // our printer should always use TWIP. Don't rely on this being set in SwViewShell::InitPrt, there
      75             :         // are situations where this isn't called.
      76             :         // #i108712# / 2010-02-26 / frank.schoenheit@sun.com
      77          46 :         if ( mpPrt )
      78             :         {
      79          46 :             MapMode aMapMode( mpPrt->GetMapMode() );
      80          46 :             aMapMode.SetMapUnit( MAP_TWIP );
      81          46 :              mpPrt->SetMapMode( aMapMode );
      82             :         }
      83             : 
      84          46 :         if ( m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel() && !m_rSwdoc.GetDocumentSettingManager().get( IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
      85          22 :             m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->SetRefDevice( mpPrt );
      86             :     }
      87             : 
      88          96 :     if ( bCallPrtDataChanged &&
      89             :          // #i41075# Do not call PrtDataChanged() if we do not
      90             :          // use the printer for formatting:
      91          48 :          !m_rSwdoc.GetDocumentSettingManager().get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
      92          22 :         PrtDataChanged();
      93          48 : }
      94             : 
      95     3501976 : VirtualDevice* DocumentDeviceManager::getVirtualDevice(/*[in]*/ bool bCreate ) const
      96             : {
      97     3501976 :     VirtualDevice* pRet = 0;
      98     3501976 :     if ( !bCreate || mpVirDev )
      99     3496946 :         pRet = mpVirDev;
     100             :     else
     101        5030 :         pRet = &CreateVirtualDevice_();
     102             : 
     103     3501976 :     return pRet;
     104             : }
     105             : 
     106        5030 : void DocumentDeviceManager::setVirtualDevice(/*[in]*/ VirtualDevice* pVd,/*[in]*/ bool bDeleteOld, /*[in]*/ bool )
     107             : {
     108        5030 :     if ( mpVirDev != pVd )
     109             :     {
     110        5030 :         if ( bDeleteOld )
     111        5030 :             delete mpVirDev;
     112        5030 :         mpVirDev = pVd;
     113             : 
     114        5030 :         if ( m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel() && m_rSwdoc.GetDocumentSettingManager().get( IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
     115        5030 :             m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->SetRefDevice( mpVirDev );
     116             :     }
     117        5030 : }
     118             : 
     119     3513474 : OutputDevice* DocumentDeviceManager::getReferenceDevice(/*[in]*/ bool bCreate ) const
     120             : {
     121     3513474 :     OutputDevice* pRet = 0;
     122     3513474 :     if ( !m_rSwdoc.GetDocumentSettingManager().get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
     123             :     {
     124       11500 :         pRet = getPrinter( bCreate );
     125             : 
     126       11500 :         if ( bCreate && !mpPrt->IsValid() )
     127             :         {
     128           0 :             pRet = getVirtualDevice( true );
     129             :         }
     130             :     }
     131             :     else
     132             :     {
     133     3501974 :         pRet = getVirtualDevice( bCreate );
     134             :     }
     135             : 
     136     3513474 :     return pRet;
     137             : }
     138             : 
     139         310 : void DocumentDeviceManager::setReferenceDeviceType(/*[in]*/ bool bNewVirtual, /*[in]*/ bool bNewHiRes )
     140             : {
     141         606 :     if ( m_rSwdoc.GetDocumentSettingManager().get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) != bNewVirtual ||
     142         296 :          m_rSwdoc.GetDocumentSettingManager().get(IDocumentSettingAccess::USE_HIRES_VIRTUAL_DEVICE) != bNewHiRes )
     143             :     {
     144          16 :         if ( bNewVirtual )
     145             :         {
     146           2 :             VirtualDevice* pMyVirDev = getVirtualDevice( true );
     147           2 :             if ( !bNewHiRes )
     148           2 :                 pMyVirDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE06 );
     149             :             else
     150           0 :                 pMyVirDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
     151             : 
     152           2 :             if( m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel() )
     153           2 :                 m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->SetRefDevice( pMyVirDev );
     154             :         }
     155             :         else
     156             :         {
     157             :             // #i41075#
     158             :             // We have to take care that a printer exists before calling
     159             :             // PrtDataChanged() in order to prevent that PrtDataChanged()
     160             :             // triggers this funny situation:
     161             :             // getReferenceDevice()->getPrinter()->CreatePrinter_()
     162             :             // ->setPrinter()-> PrtDataChanged()
     163          14 :             SfxPrinter* pPrinter = getPrinter( true );
     164          14 :             if( m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel() )
     165          14 :                 m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->SetRefDevice( pPrinter );
     166             :         }
     167             : 
     168          16 :         m_rSwdoc.GetDocumentSettingManager().set(IDocumentSettingAccess::USE_VIRTUAL_DEVICE, bNewVirtual );
     169          16 :         m_rSwdoc.GetDocumentSettingManager().set(IDocumentSettingAccess::USE_HIRES_VIRTUAL_DEVICE, bNewHiRes );
     170          16 :         PrtDataChanged();
     171          16 :         m_rSwdoc.getIDocumentState().SetModified();
     172             :     }
     173         310 : }
     174             : 
     175           0 : const JobSetup* DocumentDeviceManager::getJobsetup() const
     176             : {
     177           0 :     return mpPrt ? &mpPrt->GetJobSetup() : 0;
     178             : }
     179             : 
     180           0 : void DocumentDeviceManager::setJobsetup(/*[in]*/ const JobSetup &rJobSetup )
     181             : {
     182           0 :     bool bCheckPageDescs = 0 == mpPrt;
     183           0 :     bool bDataChanged = false;
     184             : 
     185           0 :     if ( mpPrt )
     186             :     {
     187           0 :         if ( mpPrt->GetName() == rJobSetup.GetPrinterName() )
     188             :         {
     189           0 :             if ( mpPrt->GetJobSetup() != rJobSetup )
     190             :             {
     191           0 :                 mpPrt->SetJobSetup( rJobSetup );
     192           0 :                 bDataChanged = true;
     193             :             }
     194             :         }
     195             :         else
     196           0 :             delete mpPrt, mpPrt = 0;
     197             :     }
     198             : 
     199           0 :     if( !mpPrt )
     200             :     {
     201             :         //The ItemSet is deleted by Sfx!
     202           0 :         SfxItemSet *pSet = new SfxItemSet( m_rSwdoc.GetAttrPool(),
     203             :                         FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
     204             :                         SID_HTML_MODE,  SID_HTML_MODE,
     205             :                         SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
     206             :                         SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
     207           0 :                         0 );
     208           0 :         SfxPrinter *p = new SfxPrinter( pSet, rJobSetup );
     209           0 :         if ( bCheckPageDescs )
     210           0 :             setPrinter( p, true, true );
     211             :         else
     212             :         {
     213           0 :             mpPrt = p;
     214           0 :             bDataChanged = true;
     215             :         }
     216             :     }
     217           0 :     if ( bDataChanged && !m_rSwdoc.GetDocumentSettingManager().get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
     218           0 :         PrtDataChanged();
     219           0 : }
     220             : 
     221        6664 : const SwPrintData & DocumentDeviceManager::getPrintData() const
     222             : {
     223        6664 :     if(!mpPrtData)
     224             :     {
     225         308 :         DocumentDeviceManager * pThis = const_cast< DocumentDeviceManager * >(this);
     226         308 :         pThis->mpPrtData = new SwPrintData;
     227             : 
     228             :         // SwPrintData should be initialized from the configuration,
     229             :         // the respective config item is implemented by SwPrintOptions which
     230             :         // is also derived from SwPrintData
     231         308 :         const SwDocShell *pDocSh = m_rSwdoc.GetDocShell();
     232             :         OSL_ENSURE( pDocSh, "pDocSh is 0, can't determine if this is a WebDoc or not" );
     233         308 :         bool bWeb = 0 != dynamic_cast< const SwWebDocShell * >(pDocSh);
     234         308 :         SwPrintOptions aPrintOptions( bWeb );
     235         308 :         *pThis->mpPrtData = aPrintOptions;
     236             :     }
     237        6664 :     return *mpPrtData;
     238             : }
     239             : 
     240        4734 : void DocumentDeviceManager::setPrintData(/*[in]*/ const SwPrintData& rPrtData )
     241             : {
     242        4734 :     if(!mpPrtData)
     243        4734 :         mpPrtData = new SwPrintData;
     244        4734 :     *mpPrtData = rPrtData;
     245        4734 : }
     246             : 
     247       15135 : DocumentDeviceManager::~DocumentDeviceManager()
     248             : {
     249        5045 :     delete mpPrtData;
     250        5045 :     delete mpVirDev;
     251        5045 :     DELETEZ( mpPrt );
     252       10090 : }
     253             : 
     254        5030 : VirtualDevice& DocumentDeviceManager::CreateVirtualDevice_() const
     255             : {
     256             : #ifdef IOS
     257             :     VirtualDevice* pNewVir = new VirtualDevice( 8 );
     258             : #else
     259        5030 :     VirtualDevice* pNewVir = new VirtualDevice( 1 );
     260             : #endif
     261             : 
     262        5030 :     pNewVir->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
     263             : 
     264             :     // #i60945# External leading compatibility for unix systems.
     265        5030 :     if ( m_rSwdoc.GetDocumentSettingManager().get(IDocumentSettingAccess::UNIX_FORCE_ZERO_EXT_LEADING ) )
     266           4 :         pNewVir->Compat_ZeroExtleadBug();
     267             : 
     268        5030 :     MapMode aMapMode( pNewVir->GetMapMode() );
     269        5030 :     aMapMode.SetMapUnit( MAP_TWIP );
     270        5030 :     pNewVir->SetMapMode( aMapMode );
     271             : 
     272        5030 :     const_cast<DocumentDeviceManager*>(this)->setVirtualDevice( pNewVir, true, true );
     273        5030 :     return *mpVirDev;
     274             : }
     275             : 
     276          28 : SfxPrinter& DocumentDeviceManager::CreatePrinter_() const
     277             : {
     278             :     OSL_ENSURE( ! mpPrt, "Do not call CreatePrinter_(), call getPrinter() instead" );
     279             : 
     280             : #if OSL_DEBUG_LEVEL > 1
     281             :     OSL_TRACE( "Printer will be created!" );
     282             : #endif
     283             : 
     284             :     // We create a default SfxPrinter.
     285             :     // The ItemSet is deleted by Sfx!
     286          28 :     SfxItemSet *pSet = new SfxItemSet( m_rSwdoc.GetAttrPool(),
     287             :                     FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
     288             :                     SID_HTML_MODE,  SID_HTML_MODE,
     289             :                     SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
     290             :                     SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
     291          28 :                     0 );
     292             : 
     293          28 :     SfxPrinter* pNewPrt = new SfxPrinter( pSet );
     294          28 :     const_cast<DocumentDeviceManager*>(this)->setPrinter( pNewPrt, true, true );
     295          28 :     return *mpPrt;
     296             : }
     297             : 
     298          38 : void DocumentDeviceManager::PrtDataChanged()
     299             : {
     300             : // If you change this, also modify InJobSetup in Sw3io if appropriate.
     301             : 
     302             :     // #i41075#
     303             :     OSL_ENSURE( m_rSwdoc.getIDocumentSettingAccess().get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) ||
     304             :             0 != getPrinter( false ), "PrtDataChanged will be called recursively!" );
     305          38 :     SwRootFrm* pTmpRoot = m_rSwdoc.getIDocumentLayoutAccess().GetCurrentLayout();
     306          38 :     boost::scoped_ptr<SwWait> pWait;
     307          38 :     bool bEndAction = false;
     308             : 
     309          38 :     if( m_rSwdoc.GetDocShell() )
     310          38 :         m_rSwdoc.GetDocShell()->UpdateFontList();
     311             : 
     312          38 :     bool bDraw = true;
     313          38 :     if ( pTmpRoot )
     314             :     {
     315           4 :         SwViewShell *pSh = m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell();
     316          12 :         if( pSh &&
     317           4 :             (!pSh->GetViewOptions()->getBrowseMode() ||
     318           0 :              pSh->GetViewOptions()->IsPrtFormat()) )
     319             :         {
     320           4 :             if ( m_rSwdoc.GetDocShell() )
     321           4 :                 pWait.reset(new SwWait( *m_rSwdoc.GetDocShell(), true ));
     322             : 
     323           4 :             pTmpRoot->StartAllAction();
     324           4 :             bEndAction = true;
     325             : 
     326           4 :             bDraw = false;
     327           4 :             if( m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel() )
     328             :             {
     329           4 :                 m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->SetAddExtLeading( m_rSwdoc.GetDocumentSettingManager().get(IDocumentSettingAccess::ADD_EXT_LEADING) );
     330           4 :                 m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->SetRefDevice( getReferenceDevice( false ) );
     331             :             }
     332             : 
     333           4 :             pFntCache->Flush();
     334             : 
     335           4 :             std::set<SwRootFrm*> aAllLayouts = m_rSwdoc.GetAllLayouts();
     336           4 :             std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::InvalidateAllCntnt), INV_SIZE));
     337             : 
     338           4 :             do
     339             :             {
     340           4 :                 pSh->InitPrt( getPrinter(false) );
     341           4 :                 pSh = (SwViewShell*)pSh->GetNext();
     342             :             }
     343           8 :             while ( pSh != m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell() );
     344             :         }
     345             :     }
     346          38 :     if ( bDraw && m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel() )
     347             :     {
     348          34 :         const bool bTmpAddExtLeading = m_rSwdoc.GetDocumentSettingManager().get(IDocumentSettingAccess::ADD_EXT_LEADING);
     349          34 :         if ( bTmpAddExtLeading != m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->IsAddExtLeading() )
     350           6 :             m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->SetAddExtLeading( bTmpAddExtLeading );
     351             : 
     352          34 :         OutputDevice* pOutDev = getReferenceDevice( false );
     353          34 :         if ( pOutDev != m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->GetRefDevice() )
     354           0 :             m_rSwdoc.getIDocumentDrawModelAccess().GetDrawModel()->SetRefDevice( pOutDev );
     355             :     }
     356             : 
     357          38 :     m_rSwdoc.PrtOLENotify( true );
     358             : 
     359          38 :     if ( bEndAction )
     360           4 :         pTmpRoot->EndAllAction();
     361          38 : }
     362             : 
     363         270 : }
     364             : 
     365             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10