LCOV - code coverage report
Current view: top level - sfx2/source/view - printer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 30 111 27.0 %
Date: 2012-08-25 Functions: 9 19 47.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 158 15.8 %

           Branch data     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                 :        162 :     SfxPrinter_Impl() :
      46                 :            :         mbAll       ( sal_True ),
      47                 :            :         mbSelection ( sal_True ),
      48                 :            :         mbFromTo    ( sal_True ),
      49                 :        162 :         mbRange     ( sal_True ) {}
      50                 :        158 :     ~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                 :         22 : 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         [ +  - ]:         22 :     JobSetup aFileJobSetup;
      79         [ +  - ]:         22 :     rStream >> aFileJobSetup;
      80                 :            : 
      81                 :            :     // Get printers
      82 [ +  - ][ +  - ]:         22 :     SfxPrinter *pPrinter = new SfxPrinter( pOptions, aFileJobSetup );
      83         [ +  - ]:         22 :     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                 :        132 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions ) :
     102                 :            : 
     103                 :            : /*  [Description]
     104                 :            : 
     105                 :            :     This constructor creates a default printer.
     106                 :            : */
     107                 :            : 
     108                 :            :     pOptions( pTheOptions ),
     109         [ +  - ]:        132 :     bKnown(sal_True)
     110                 :            : 
     111                 :            : {
     112         [ +  - ]:        132 :     pImpl = new SfxPrinter_Impl;
     113                 :        132 : }
     114                 :            : 
     115                 :            : //--------------------------------------------------------------------
     116                 :            : 
     117                 :         22 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
     118                 :            :                         const JobSetup& rTheOrigJobSetup ) :
     119                 :            : 
     120                 :            :     Printer         ( rTheOrigJobSetup.GetPrinterName() ),
     121 [ +  - ][ +  - ]:         22 :     pOptions        ( pTheOptions )
     122                 :            : 
     123                 :            : {
     124         [ +  - ]:         22 :     pImpl = new SfxPrinter_Impl;
     125         [ +  - ]:         22 :     bKnown = GetName() == rTheOrigJobSetup.GetPrinterName();
     126                 :            : 
     127         [ +  + ]:         22 :     if ( bKnown )
     128         [ +  - ]:          3 :         SetJobSetup( rTheOrigJobSetup );
     129                 :         22 : }
     130                 :            : 
     131                 :            : //--------------------------------------------------------------------
     132                 :            : 
     133                 :          8 : SfxPrinter::SfxPrinter( SfxItemSet* pTheOptions,
     134                 :            :                         const String& rPrinterName ) :
     135                 :            : 
     136                 :            :     Printer         ( rPrinterName ),
     137                 :            :     pOptions        ( pTheOptions ),
     138 [ +  - ][ +  - ]:          8 :     bKnown          ( String( GetName() ) == rPrinterName )
         [ +  - ][ +  - ]
                 [ +  - ]
     139                 :            : 
     140                 :            : {
     141         [ +  - ]:          8 :     pImpl = new SfxPrinter_Impl;
     142                 :          8 : }
     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         [ +  - ]:        158 : SfxPrinter::~SfxPrinter()
     187                 :            : {
     188 [ +  - ][ +  - ]:        158 :     delete pOptions;
     189         [ +  - ]:        158 :     delete pImpl;
     190         [ -  + ]:        316 : }
     191                 :            : 
     192                 :            : //--------------------------------------------------------------------
     193                 :            : 
     194                 :         31 : void SfxPrinter::SetOptions( const SfxItemSet &rNewOptions )
     195                 :            : {
     196                 :         31 :     pOptions->Set(rNewOptions);
     197                 :         31 : }
     198                 :            : 
     199                 :            : //--------------------------------------------------------------------
     200                 :            : 
     201                 :          0 : SfxPrintOptionsDialog::SfxPrintOptionsDialog( Window *pParent,
     202                 :            :                                               SfxViewShell *pViewShell,
     203                 :            :                                               const SfxItemSet *pSet ) :
     204                 :            : 
     205                 :            :     ModalDialog( pParent, WinBits( WB_STDMODAL | WB_3DLOOK ) ),
     206                 :            : 
     207                 :            :     aOkBtn      ( this ),
     208                 :            :     aCancelBtn  ( this ),
     209                 :            :     aHelpBtn    ( this ),
     210                 :          0 :     pDlgImpl    ( new SfxPrintOptDlg_Impl ),
     211                 :            :     pViewSh     ( pViewShell ),
     212         [ #  # ]:          0 :     pOptions    ( pSet->Clone() ),
     213 [ #  # ][ #  # ]:          0 :     pPage       ( NULL )
         [ #  # ][ #  # ]
     214                 :            : 
     215                 :            : {
     216 [ #  # ][ #  # ]:          0 :     SetText( SfxResId(STR_PRINT_OPTIONS_TITLE).toString() );
         [ #  # ][ #  # ]
                 [ #  # ]
     217                 :            : 
     218                 :            :     // Insert TabPage
     219         [ #  # ]:          0 :     pPage = pViewSh->CreatePrintOptionsPage( this, *pOptions );
     220                 :            :     DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
     221         [ #  # ]:          0 :     if( pPage )
     222                 :            :     {
     223         [ #  # ]:          0 :         pPage->Reset( *pOptions );
     224 [ #  # ][ #  # ]:          0 :         SetHelpId( pPage->GetHelpId() );
     225         [ #  # ]:          0 :         pPage->Show();
     226                 :            :     }
     227                 :            : 
     228                 :            :     // Set dialog size
     229 [ #  # ][ #  # ]:          0 :     Size a6Sz = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
                 [ #  # ]
     230 [ #  # ][ #  # ]:          0 :     Size aBtnSz = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
                 [ #  # ]
     231 [ #  # ][ #  # ]:          0 :     Size aOutSz( pPage ? pPage->GetSizePixel() : Size() );
     232                 :          0 :     aOutSz.Height() += 6;
     233                 :          0 :     long nWidth = aBtnSz.Width();
     234                 :          0 :     nWidth += a6Sz.Width();
     235                 :          0 :     aOutSz.Width() += nWidth;
     236         [ #  # ]:          0 :     if ( aOutSz.Height() < 90 )
     237                 :            :         // at least the height of the 3 buttons
     238                 :          0 :         aOutSz.Height() = 90;
     239         [ #  # ]:          0 :     SetOutputSizePixel( aOutSz );
     240                 :            : 
     241                 :            :     // set position and size of the buttons
     242                 :          0 :     Point aBtnPos( aOutSz.Width() - aBtnSz.Width() - a6Sz.Width(), a6Sz.Height() );
     243         [ #  # ]:          0 :     aOkBtn.SetPosSizePixel( aBtnPos, aBtnSz );
     244                 :          0 :     aBtnPos.Y() += aBtnSz.Height() + ( a6Sz.Height() / 2 );
     245         [ #  # ]:          0 :     aCancelBtn.SetPosSizePixel( aBtnPos, aBtnSz );
     246                 :          0 :     aBtnPos.Y() += aBtnSz.Height() + a6Sz.Height();
     247         [ #  # ]:          0 :     aHelpBtn.SetPosSizePixel( aBtnPos, aBtnSz );
     248                 :            : 
     249         [ #  # ]:          0 :     aCancelBtn.Show();
     250         [ #  # ]:          0 :     aOkBtn.Show();
     251         [ #  # ]:          0 :     aHelpBtn.Show();
     252                 :          0 : }
     253                 :            : 
     254                 :            : //--------------------------------------------------------------------
     255                 :            : 
     256 [ #  # ][ #  # ]:          0 : SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
                 [ #  # ]
     257                 :            : {
     258                 :          0 :     delete pDlgImpl;
     259 [ #  # ][ #  # ]:          0 :     delete pPage;
     260 [ #  # ][ #  # ]:          0 :     delete pOptions;
     261         [ #  # ]:          0 : }
     262                 :            : 
     263                 :            : //--------------------------------------------------------------------
     264                 :            : 
     265                 :          0 : short SfxPrintOptionsDialog::Execute()
     266                 :            : {
     267         [ #  # ]:          0 :     if( ! pPage )
     268                 :          0 :         return RET_CANCEL;
     269                 :            : 
     270                 :          0 :     short nRet = ModalDialog::Execute();
     271         [ #  # ]:          0 :     if ( nRet == RET_OK )
     272                 :          0 :         pPage->FillItemSet( *pOptions );
     273                 :            :     else
     274                 :          0 :         pPage->Reset( *pOptions );
     275                 :          0 :     return nRet;
     276                 :            : }
     277                 :            : 
     278                 :            : //--------------------------------------------------------------------
     279                 :            : 
     280                 :          0 : long SfxPrintOptionsDialog::Notify( NotifyEvent& rNEvt )
     281                 :            : {
     282         [ #  # ]:          0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
     283                 :            :     {
     284 [ #  # ][ #  # ]:          0 :         if ( rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1 && pDlgImpl->mbHelpDisabled )
                 [ #  # ]
     285                 :          0 :             return 1; // help disabled -> <F1> does nothing
     286                 :            :     }
     287                 :            : 
     288                 :          0 :     return ModalDialog::Notify( rNEvt );
     289                 :            : }
     290                 :            : 
     291                 :            : //--------------------------------------------------------------------
     292                 :            : 
     293                 :          0 : void SfxPrintOptionsDialog::DisableHelp()
     294                 :            : {
     295                 :          0 :     pDlgImpl->mbHelpDisabled = sal_True;
     296                 :            : 
     297                 :          0 :     aHelpBtn.Disable();
     298                 :          0 : }
     299                 :            : 
     300                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10