LCOV - code coverage report
Current view: top level - sw/source/uibase/uiview - viewprt.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 21 133 15.8 %
Date: 2014-11-03 Functions: 4 10 40.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 <com/sun/star/text/NotePrintMode.hpp>
      21             : #include <cstdarg>
      22             : #include <cmdid.h>
      23             : #include <sfx2/request.hxx>
      24             : #include <sfx2/progress.hxx>
      25             : #include <sfx2/app.hxx>
      26             : #include <vcl/layout.hxx>
      27             : #include <vcl/oldprintadaptor.hxx>
      28             : #include <sfx2/printer.hxx>
      29             : #include <sfx2/prnmon.hxx>
      30             : #include <editeng/paperinf.hxx>
      31             : #include <sfx2/dispatch.hxx>
      32             : #include <unotools/misccfg.hxx>
      33             : #include <svx/prtqry.hxx>
      34             : #include <svx/svdview.hxx>
      35             : #include <svl/eitem.hxx>
      36             : #include <svl/stritem.hxx>
      37             : #include <svl/intitem.hxx>
      38             : #include <svl/flagitem.hxx>
      39             : #include <sfx2/linkmgr.hxx>
      40             : 
      41             : #include <modcfg.hxx>
      42             : #include <edtwin.hxx>
      43             : #include <view.hxx>
      44             : #include <wrtsh.hxx>
      45             : #include <docsh.hxx>
      46             : #include <viewopt.hxx>
      47             : #include <prtopt.hxx>
      48             : #include <fontcfg.hxx>
      49             : #include <cfgitems.hxx>
      50             : #include <dbmgr.hxx>
      51             : #include <docstat.hxx>
      52             : #include <viewfunc.hxx>
      53             : #include <swmodule.hxx>
      54             : #include <wview.hxx>
      55             : #include <doc.hxx>
      56             : #include <fldbas.hxx>
      57             : #include <IDocumentDeviceAccess.hxx>
      58             : 
      59             : #include <globals.hrc>
      60             : #include <view.hrc>
      61             : #include <app.hrc>
      62             : #include <swwrtshitem.hxx>
      63             : #include "swabstdlg.hxx"
      64             : #include <svl/slstitm.hxx>
      65             : 
      66             : #include <unomid.h>
      67             : 
      68             : using namespace ::com::sun::star;
      69             : 
      70             : // Hand over the printer to Sfx
      71             : 
      72       11652 : SfxPrinter* SwView::GetPrinter( bool bCreate )
      73             : {
      74       11652 :     const IDocumentDeviceAccess* pIDDA = GetWrtShell().getIDocumentDeviceAccess();
      75       11652 :     SfxPrinter *pOld = pIDDA->getPrinter( false );
      76       11652 :     SfxPrinter *pPrt = pIDDA->getPrinter( bCreate );
      77       11652 :     if ( pOld != pPrt )
      78             :     {
      79           0 :         bool bWeb = 0 != dynamic_cast<SwWebView*>(this);
      80           0 :         ::SetAppPrintOptions( &GetWrtShell(), bWeb );
      81             :     }
      82       11652 :     return pPrt;
      83             : }
      84             : 
      85             : // Propagate printer change
      86             : 
      87           0 : void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter* pNew, bool bWeb )
      88             : {
      89           0 :     SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb);
      90           0 :     if( !pOpt)
      91           0 :         return;
      92             : 
      93             :     // Reading Application own printing options from SfxPrinter
      94           0 :     const SfxItemSet& rSet = pNew->GetOptions();
      95             : 
      96             :     const SwAddPrinterItem* pAddPrinterAttr;
      97           0 :     if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, false,
      98           0 :         (const SfxPoolItem**)&pAddPrinterAttr ) )
      99             :     {
     100           0 :         if( pIDDA )
     101           0 :             pIDDA->setPrintData( *pAddPrinterAttr );
     102           0 :         if( !pAddPrinterAttr->GetFax().isEmpty() )
     103           0 :             pOpt->SetFaxName(pAddPrinterAttr->GetFax());
     104             :     }
     105             : }
     106             : 
     107           2 : sal_uInt16 SwView::SetPrinter(SfxPrinter* pNew, sal_uInt16 nDiffFlags, bool  )
     108             : {
     109           2 :     SwWrtShell &rSh = GetWrtShell();
     110           2 :     SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
     111           2 :     if ( pOld && pOld->IsPrinting() )
     112           0 :         return SFX_PRINTERROR_BUSY;
     113             : 
     114           2 :     if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags )
     115             :     {
     116           2 :         rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
     117           2 :         if ( nDiffFlags & SFX_PRINTER_PRINTER )
     118           2 :             rSh.SetModified();
     119             :     }
     120           2 :     bool bWeb = this->ISA(SwWebView);
     121           2 :     if ( nDiffFlags & SFX_PRINTER_OPTIONS )
     122           0 :         ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, bWeb );
     123             : 
     124           2 :     const bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION;
     125           2 :     const bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE;
     126           2 :     if ( bChgOri || bChgSize )
     127             :     {
     128           0 :         rSh.StartAllAction();
     129           0 :         if ( bChgOri )
     130           0 :             rSh.ChgAllPageOrientation( pNew->GetOrientation() );
     131           0 :         if ( bChgSize )
     132             :         {
     133           0 :             Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
     134           0 :             rSh.ChgAllPageSize( aSz );
     135             :         }
     136           0 :         rSh.SetModified();
     137           0 :         rSh.EndAllAction();
     138           0 :         InvalidateRulerPos();
     139             :     }
     140           2 :     return 0;
     141             : }
     142             : 
     143           0 : bool SwView::HasPrintOptionsPage() const
     144             : {
     145           0 :     return true;
     146             : }
     147             : 
     148             : // TabPage for application-specific print options
     149             : 
     150           0 : SfxTabPage* SwView::CreatePrintOptionsPage(vcl::Window* pParent,
     151             :                                                     const SfxItemSet& rSet)
     152             : {
     153           0 :     return ::CreatePrintOptionsPage( pParent, rSet, false );
     154             : }
     155             : 
     156             : // Print dispatcher
     157             : 
     158           0 : void SwView::ExecutePrint(SfxRequest& rReq)
     159             : {
     160           0 :     bool bWeb = 0 != PTR_CAST(SwWebView, this);
     161           0 :     ::SetAppPrintOptions( &GetWrtShell(), bWeb );
     162           0 :     switch (rReq.GetSlot())
     163             :     {
     164             :         case FN_FAX:
     165             :         {
     166           0 :             SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb);
     167           0 :             OUString sFaxName(pPrintOptions->GetFaxName());
     168           0 :             if (!sFaxName.isEmpty())
     169             :             {
     170           0 :                 SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName);
     171           0 :                 SfxBoolItem aSilent( SID_SILENT, true );
     172             :                 GetViewFrame()->GetDispatcher()->Execute( SID_PRINTDOC,
     173             :                             SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
     174           0 :                             &aPrinterName, &aSilent, 0L );
     175             :             }
     176             :             else
     177             :             {
     178           0 :                 MessageDialog aInfoBox(&GetEditWin(), SW_RES(STR_ERR_NO_FAX), VCL_MESSAGE_INFO);
     179           0 :                 sal_uInt16 nResNo = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS;
     180           0 :                 aInfoBox.set_primary_text(aInfoBox.get_primary_text().replaceFirst("%1", OUString(SW_RES(nResNo))));
     181           0 :                 aInfoBox.Execute();
     182           0 :                 SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE);
     183             :                 GetViewFrame()->GetDispatcher()->Execute(SID_SW_EDITOPTIONS,
     184             :                             SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
     185           0 :                             &aDefPage, 0L );
     186           0 :             }
     187             :         }
     188           0 :         break;
     189             :         case SID_PRINTDOC:
     190             :         case SID_PRINTDOCDIRECT:
     191             :         {
     192           0 :             SwWrtShell* pSh = &GetWrtShell();
     193           0 :             SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, false);
     194           0 :             bool bSilent = pSilentItem ? pSilentItem->GetValue() : sal_False;
     195           0 :             SFX_REQUEST_ARG(rReq, pPrintFromMergeItem, SfxBoolItem, FN_QRY_MERGE, false);
     196           0 :             if(pPrintFromMergeItem)
     197           0 :                 rReq.RemoveItem(FN_QRY_MERGE);
     198           0 :             bool bFromMerge = pPrintFromMergeItem ? pPrintFromMergeItem->GetValue() : sal_False;
     199           0 :             SwMiscConfig aMiscConfig;
     200           0 :             bool bPrintSelection = false;
     201           0 :             if(!bSilent && !bFromMerge &&
     202           0 :                     SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc())
     203             :             {
     204           0 :                 MessageDialog aBox(&GetEditWin(), "PrintMergeDialog",
     205           0 :                                    "modules/swriter/ui/printmergedialog.ui");
     206           0 :                 short nRet = aBox.Execute();
     207           0 :                 if(RET_YES == nRet)
     208             :                 {
     209           0 :                     SfxBoolItem aBool(FN_QRY_MERGE, true);
     210             :                     GetViewFrame()->GetDispatcher()->Execute(
     211           0 :                                 FN_QRY_MERGE, SfxCallMode::ASYNCHRON, &aBool, 0L);
     212           0 :                     rReq.Ignore();
     213           0 :                     return;
     214           0 :                 }
     215             :             }
     216           0 :             else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent )
     217             :             {
     218           0 :                 if( ( pSh->IsSelection() || pSh->IsFrmSelected() || pSh->IsObjSelected() ) )
     219             :                 {
     220           0 :                     short nBtn = SvxPrtQryBox(&GetEditWin()).Execute();
     221           0 :                     if( RET_CANCEL == nBtn )
     222           0 :                         return;
     223             : 
     224           0 :                     if( RET_OK == nBtn )
     225           0 :                         bPrintSelection = true;
     226             :                 }
     227             :             }
     228             : 
     229             :             //#i61455# if master documentes are printed silently without loaded links then update the links now
     230           0 :             if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() )
     231             :             {
     232           0 :                 pSh->GetLinkManager().UpdateAllLinks( false, false, false, 0 );
     233             :             }
     234           0 :             SfxRequest aReq( rReq );
     235           0 :             SfxBoolItem aBool(SID_SELECTION, bPrintSelection);
     236           0 :             aReq.AppendItem( aBool );
     237           0 :             SfxViewShell::ExecuteSlot( aReq, SfxViewShell::GetInterface() );
     238           0 :             return;
     239             :         }
     240             :         default:
     241             :             OSL_ENSURE(false, "wrong dispatcher");
     242           0 :             return;
     243             :     }
     244             : }
     245             : 
     246             : // Create page printer/additions for SwView and SwPagePreview
     247             : 
     248           0 : SfxTabPage* CreatePrintOptionsPage( vcl::Window *pParent,
     249             :                                 const SfxItemSet &rOptions, bool bPreview )
     250             : {
     251           0 :     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     252             :     OSL_ENSURE(pFact, "No Print Dialog");
     253           0 :     if (!pFact)
     254           0 :         return NULL;
     255             : 
     256           0 :     ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc(TP_OPTPRINT_PAGE);
     257             :     OSL_ENSURE(pFact, "No Page Creator");
     258           0 :     if (!fnCreatePage)
     259           0 :         return NULL;
     260             : 
     261           0 :     SfxTabPage* pPage = (*fnCreatePage)(pParent, &rOptions);
     262             :     OSL_ENSURE(pPage, "No page");
     263           0 :     if (!pPage)
     264           0 :         return NULL;
     265             : 
     266           0 :     SfxAllItemSet aSet(*(rOptions.GetPool()));
     267           0 :     aSet.Put(SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview));
     268           0 :     aSet.Put(SfxBoolItem(SID_FAX_LIST, true));
     269           0 :     pPage->PageCreated(aSet);
     270           0 :     return pPage;
     271             : }
     272             : 
     273           0 : void SetAppPrintOptions( SwViewShell* pSh, bool bWeb )
     274             : {
     275           0 :     const IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
     276           0 :     SwPrintData aPrtData = pIDDA->getPrintData();
     277             : 
     278           0 :     if( pIDDA->getPrinter( false ) )
     279             :     {
     280             :         // Close application own printing options in SfxPrinter.
     281           0 :         SwAddPrinterItem aAddPrinterItem (FN_PARAM_ADDPRINTER, aPrtData);
     282           0 :         SfxItemSet aSet( pSh->GetAttrPool(),
     283             :                     FN_PARAM_ADDPRINTER,        FN_PARAM_ADDPRINTER,
     284             :                     SID_HTML_MODE,              SID_HTML_MODE,
     285             :                     SID_PRINTER_NOTFOUND_WARN,  SID_PRINTER_NOTFOUND_WARN,
     286             :                     SID_PRINTER_CHANGESTODOC,   SID_PRINTER_CHANGESTODOC,
     287           0 :                     0 );
     288             : 
     289           0 :         utl::MiscCfg aMisc;
     290             : 
     291           0 :         if(bWeb)
     292             :             aSet.Put(SfxUInt16Item(SID_HTML_MODE,
     293           0 :                     ::GetHtmlMode(((SwWrtShell*)pSh)->GetView().GetDocShell())));
     294             :         aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN,
     295           0 :                         aMisc.IsNotFoundWarning() ));
     296           0 :         aSet.Put(aAddPrinterItem);
     297             :         aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC,
     298           0 :             (aMisc.IsPaperSizeWarning() ? SFX_PRINTER_CHG_SIZE : 0)   |
     299           0 :             (aMisc.IsPaperOrientationWarning()  ? SFX_PRINTER_CHG_ORIENTATION : 0 )));
     300             : 
     301           0 :         pIDDA->getPrinter( true )->SetOptions( aSet );
     302           0 :     }
     303             : 
     304         270 : }
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10