LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/view - printer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 30 91 33.0 %
Date: 2012-12-27 Functions: 11 21 52.4 %
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 <vcl/virdev.hxx>
      21             : #include <vcl/metric.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <unotools/printwarningoptions.hxx>
      24             : #include <svtools/printoptions.hxx>
      25             : #include <vector>
      26             : 
      27             : #include <sfx2/printer.hxx>
      28             : #include <sfx2/printopt.hxx>
      29             : #include "sfxtypes.hxx"
      30             : #include <sfx2/prnmon.hxx>
      31             : #include <sfx2/viewsh.hxx>
      32             : #include <sfx2/tabdlg.hxx>
      33             : #include "sfx2/sfxresid.hxx"
      34             : #include "view.hrc"
      35             : 
      36             : // struct SfxPrinter_Impl ------------------------------------------------
      37             : 
      38             : struct SfxPrinter_Impl
      39             : {
      40             :     sal_Bool            mbAll;
      41             :     sal_Bool            mbSelection;
      42             :     sal_Bool            mbFromTo;
      43             :     sal_Bool            mbRange;
      44             : 
      45          47 :     SfxPrinter_Impl() :
      46             :         mbAll       ( sal_True ),
      47             :         mbSelection ( sal_True ),
      48             :         mbFromTo    ( sal_True ),
      49          47 :         mbRange     ( sal_True ) {}
      50          37 :     ~SfxPrinter_Impl() {}
      51             : };
      52             : 
      53             : struct SfxPrintOptDlg_Impl
      54             : {
      55             :     sal_Bool        mbHelpDisabled;
      56             : 
      57           0 :     SfxPrintOptDlg_Impl() :
      58           0 :         mbHelpDisabled  ( sal_False ) {}
      59             : };
      60             : 
      61             : // class SfxPrinter ------------------------------------------------------
      62             : 
      63           5 : SfxPrinter* SfxPrinter::Create( SvStream& rStream, SfxItemSet* pOptions )
      64             : 
      65             : /*  [Description]
      66             : 
      67             :     Creates a <SfxPrinter> from the stream. Loading is really only a jobsetup.
      68             :     If such a printer is not available on the system, then the original is
      69             :     marked as the original Job-setup and a comparable printer is selected from
      70             :     existing ones.
      71             : 
      72             :     The 'pOptions' are taken over in the generated SfxPrinter, the return
      73             :     value belongs to the caller.
      74             : */
      75             : 
      76             : {
      77             :     // Load JobSetup
      78           5 :     JobSetup aFileJobSetup;
      79           5 :     rStream >> aFileJobSetup;
      80             : 
      81             :     // Get printers
      82           5 :     SfxPrinter *pPrinter = new SfxPrinter( pOptions, aFileJobSetup );
      83           5 :     return pPrinter;
      84             : }
      85             : 
      86             : //--------------------------------------------------------------------
      87             : 
      88           0 : SvStream& SfxPrinter::Store( SvStream& rStream ) const
      89             : 
      90             : /*  [Description]
      91             : 
      92             :     Saves the used JobSetup of <SfxPrinter>s.
      93             : */
      94             : 
      95             : {
      96           0 :     return ( rStream << GetJobSetup() );
      97             : }
      98             : 
      99             : //--------------------------------------------------------------------
     100             : 
     101          41 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
     102             : 
     103             : /*  [Description]
     104             : 
     105             :     This constructor creates a default printer.
     106             : */
     107             : 
     108             :     pOptions( pTheOptions ),
     109          41 :     bKnown(sal_True)
     110             : 
     111             : {
     112          41 :     pImpl = new SfxPrinter_Impl;
     113          41 : }
     114             : 
     115             : //--------------------------------------------------------------------
     116             : 
     117           5 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
     118             :                         const JobSetup& rTheOrigJobSetup ) :
     119             : 
     120             :     Printer         ( rTheOrigJobSetup.GetPrinterName() ),
     121           5 :     pOptions        ( pTheOptions )
     122             : 
     123             : {
     124           5 :     pImpl = new SfxPrinter_Impl;
     125           5 :     bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
     126             : 
     127           5 :     if ( bKnown )
     128           0 :         SetJobSetup( rTheOrigJobSetup );
     129           5 : }
     130             : 
     131             : //--------------------------------------------------------------------
     132             : 
     133           1 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
     134             :                         const String& rPrinterName ) :
     135             : 
     136             :     Printer         ( rPrinterName ),
     137             :     pOptions        ( pTheOptions ),
     138           1 :     bKnown          ( String( GetName() ) == rPrinterName )
     139             : 
     140             : {
     141           1 :     pImpl = new SfxPrinter_Impl;
     142           1 : }
     143             : 
     144             : //--------------------------------------------------------------------
     145             : 
     146           0 : SfxPrinter::SfxPrinter( const SfxPrinter& rPrinter ) :
     147             : 
     148           0 :     Printer ( rPrinter.GetName() ),
     149           0 :     pOptions( rPrinter.GetOptions().Clone() ),
     150           0 :     bKnown  ( rPrinter.IsKnown() )
     151             : {
     152           0 :     SetJobSetup( rPrinter.GetJobSetup() );
     153           0 :     SetPrinterProps( &rPrinter );
     154           0 :     SetMapMode( rPrinter.GetMapMode() );
     155             : 
     156           0 :     pImpl = new SfxPrinter_Impl;
     157           0 :     pImpl->mbAll = rPrinter.pImpl->mbAll;
     158           0 :     pImpl->mbSelection = rPrinter.pImpl->mbSelection;
     159           0 :     pImpl->mbFromTo = rPrinter.pImpl->mbFromTo;
     160           0 :     pImpl->mbRange = rPrinter.pImpl->mbRange;
     161           0 : }
     162             : 
     163             : //--------------------------------------------------------------------
     164             : 
     165           0 : SfxPrinter* SfxPrinter::Clone() const
     166             : {
     167           0 :     if ( IsDefPrinter() )
     168             :     {
     169             :         SfxPrinter *pNewPrinter;
     170           0 :         pNewPrinter = new SfxPrinter( GetOptions().Clone() );
     171           0 :         pNewPrinter->SetJobSetup( GetJobSetup() );
     172           0 :         pNewPrinter->SetPrinterProps( this );
     173           0 :         pNewPrinter->SetMapMode( GetMapMode() );
     174           0 :         pNewPrinter->pImpl->mbAll = pImpl->mbAll;
     175           0 :         pNewPrinter->pImpl->mbSelection =pImpl->mbSelection;
     176           0 :         pNewPrinter->pImpl->mbFromTo = pImpl->mbFromTo;
     177           0 :         pNewPrinter->pImpl->mbRange =pImpl->mbRange;
     178           0 :         return pNewPrinter;
     179             :     }
     180             :     else
     181           0 :         return new SfxPrinter( *this );
     182             : }
     183             : 
     184             : //--------------------------------------------------------------------
     185             : 
     186         111 : SfxPrinter::~SfxPrinter()
     187             : {
     188          37 :     delete pOptions;
     189          37 :     delete pImpl;
     190          74 : }
     191             : 
     192             : //--------------------------------------------------------------------
     193             : 
     194           4 : void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
     195             : {
     196           4 :     pOptions->Set(rNewOptions);
     197           4 : }
     198             : 
     199             : //--------------------------------------------------------------------
     200             : 
     201           0 : SfxPrintOptionsDialog::SfxPrintOptionsDialog(Window *pParent,
     202             :                                               SfxViewShell *pViewShell,
     203             :                                               const SfxItemSet *pSet)
     204             : 
     205             :     : ModalDialog(pParent, "PrinterOptionsDialog",
     206             :         "sfx/ui/printeroptionsdialog.ui")
     207           0 :     , pDlgImpl(new SfxPrintOptDlg_Impl)
     208             :     , pViewSh(pViewShell)
     209           0 :     , pOptions(pSet->Clone())
     210             : {
     211           0 :     VclContainer *pVBox = get_content_area();
     212             : 
     213             :     // Insert TabPage
     214           0 :     pPage = pViewSh->CreatePrintOptionsPage(pVBox, *pOptions);
     215             :     DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
     216           0 :     if( pPage )
     217             :     {
     218           0 :         pPage->Reset( *pOptions );
     219           0 :         SetHelpId( pPage->GetHelpId() );
     220           0 :         pPage->Show();
     221             :     }
     222           0 : }
     223             : 
     224             : //--------------------------------------------------------------------
     225             : 
     226           0 : SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
     227             : {
     228           0 :     delete pDlgImpl;
     229           0 :     delete pPage;
     230           0 :     delete pOptions;
     231           0 : }
     232             : 
     233             : //--------------------------------------------------------------------
     234             : 
     235           0 : short SfxPrintOptionsDialog::Execute()
     236             : {
     237           0 :     if( ! pPage )
     238           0 :         return RET_CANCEL;
     239             : 
     240           0 :     short nRet = ModalDialog::Execute();
     241           0 :     if ( nRet == RET_OK )
     242           0 :         pPage->FillItemSet( *pOptions );
     243             :     else
     244           0 :         pPage->Reset( *pOptions );
     245           0 :     return nRet;
     246             : }
     247             : 
     248             : //--------------------------------------------------------------------
     249             : 
     250           0 : long SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
     251             : {
     252           0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
     253             :     {
     254           0 :         if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
     255           0 :             return 1; // help disabled -> <F1> does nothing
     256             :     }
     257             : 
     258           0 :     return ModalDialog::Notify( rNEvt );
     259             : }
     260             : 
     261             : //--------------------------------------------------------------------
     262             : 
     263           0 : void SfxPrintOptionsDialog::DisableHelp()
     264             : {
     265           0 :     pDlgImpl->mbHelpDisabled = sal_True;
     266             : 
     267           0 :     get<HelpButton>("help")->Disable();
     268          66 : }
     269             : 
     270             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10