LCOV - code coverage report
Current view: top level - sw/source/core/uibase/uiview - viewprt.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 134 0.0 %
Date: 2014-04-14 Functions: 0 10 0.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/msgbox.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             : 
      58             : #include <globals.hrc>
      59             : #include <view.hrc>
      60             : #include <app.hrc>
      61             : #include <swwrtshitem.hxx>
      62             : #include "swabstdlg.hxx"
      63             : #include <svl/slstitm.hxx>
      64             : 
      65             : #include <unomid.h>
      66             : 
      67             : using namespace ::com::sun::star;
      68             : 
      69             : // Hand over the printer to Sfx
      70             : 
      71           0 : SfxPrinter* SwView::GetPrinter( bool bCreate )
      72             : {
      73           0 :     const IDocumentDeviceAccess* pIDDA = GetWrtShell().getIDocumentDeviceAccess();
      74           0 :     SfxPrinter *pOld = pIDDA->getPrinter( false );
      75           0 :     SfxPrinter *pPrt = pIDDA->getPrinter( bCreate );
      76           0 :     if ( pOld != pPrt )
      77             :     {
      78           0 :         sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
      79           0 :         ::SetAppPrintOptions( &GetWrtShell(), bWeb );
      80             :     }
      81           0 :     return pPrt;
      82             : }
      83             : 
      84             : // Propagate printer change
      85             : 
      86           0 : void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter* pNew, sal_Bool bWeb )
      87             : {
      88           0 :     SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb);
      89           0 :     if( !pOpt)
      90           0 :         return;
      91             : 
      92             :     // Reading Application own printing options from SfxPrinter
      93           0 :     const SfxItemSet& rSet = pNew->GetOptions();
      94             : 
      95             :     const SwAddPrinterItem* pAddPrinterAttr;
      96           0 :     if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, false,
      97           0 :         (const SfxPoolItem**)&pAddPrinterAttr ) )
      98             :     {
      99           0 :         if( pIDDA )
     100           0 :             pIDDA->setPrintData( *pAddPrinterAttr );
     101           0 :         if( !pAddPrinterAttr->GetFax().isEmpty() )
     102           0 :             pOpt->SetFaxName(pAddPrinterAttr->GetFax());
     103             :     }
     104             : }
     105             : 
     106           0 : sal_uInt16 SwView::SetPrinter(SfxPrinter* pNew, sal_uInt16 nDiffFlags, bool  )
     107             : {
     108           0 :     SwWrtShell &rSh = GetWrtShell();
     109           0 :     SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
     110           0 :     if ( pOld && pOld->IsPrinting() )
     111           0 :         return SFX_PRINTERROR_BUSY;
     112             : 
     113           0 :     if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags )
     114             :     {
     115           0 :         rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
     116           0 :         if ( nDiffFlags & SFX_PRINTER_PRINTER )
     117           0 :             rSh.SetModified();
     118             :     }
     119           0 :     sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
     120           0 :     if ( nDiffFlags & SFX_PRINTER_OPTIONS )
     121           0 :         ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, bWeb );
     122             : 
     123           0 :     const sal_Bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? sal_True : sal_False;
     124           0 :     const sal_Bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? sal_True : sal_False;
     125           0 :     if ( bChgOri || bChgSize )
     126             :     {
     127           0 :         rSh.StartAllAction();
     128           0 :         if ( bChgOri )
     129           0 :             rSh.ChgAllPageOrientation( sal_uInt16(pNew->GetOrientation()) );
     130           0 :         if ( bChgSize )
     131             :         {
     132           0 :             Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
     133           0 :             rSh.ChgAllPageSize( aSz );
     134             :         }
     135           0 :         rSh.SetModified();
     136           0 :         rSh.EndAllAction();
     137           0 :         InvalidateRulerPos();
     138             :     }
     139           0 :     return 0;
     140             : }
     141             : 
     142           0 : bool SwView::HasPrintOptionsPage() const
     143             : {
     144           0 :     return true;
     145             : }
     146             : 
     147             : // TabPage for application-specific print options
     148             : 
     149           0 : SfxTabPage* SwView::CreatePrintOptionsPage(Window* pParent,
     150             :                                                     const SfxItemSet& rSet)
     151             : {
     152           0 :     return ::CreatePrintOptionsPage( pParent, rSet, sal_False );
     153             : }
     154             : 
     155             : // Print dispatcher
     156             : 
     157           0 : void SwView::ExecutePrint(SfxRequest& rReq)
     158             : {
     159           0 :     sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
     160           0 :     ::SetAppPrintOptions( &GetWrtShell(), bWeb );
     161           0 :     switch (rReq.GetSlot())
     162             :     {
     163             :         case FN_FAX:
     164             :         {
     165           0 :             SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb);
     166           0 :             OUString sFaxName(pPrintOptions->GetFaxName());
     167           0 :             if (!sFaxName.isEmpty())
     168             :             {
     169           0 :                 SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName);
     170           0 :                 SfxBoolItem aSilent( SID_SILENT, true );
     171             :                 GetViewFrame()->GetDispatcher()->Execute( SID_PRINTDOC,
     172             :                             SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
     173           0 :                             &aPrinterName, &aSilent, 0L );
     174             :             }
     175             :             else
     176             :             {
     177           0 :                 InfoBox aInfoBox(&GetEditWin(), SW_RES(MSG_ERR_NO_FAX));
     178           0 :                 OUString sMsg = aInfoBox.GetMessText();
     179           0 :                 sal_uInt16 nResNo = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS;
     180           0 :                 sMsg = sMsg.replaceFirst("%1", OUString(SW_RES(nResNo)));
     181           0 :                 aInfoBox.SetMessText(sMsg);
     182           0 :                 aInfoBox.Execute();
     183           0 :                 SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE);
     184             :                 GetViewFrame()->GetDispatcher()->Execute(SID_SW_EDITOPTIONS,
     185             :                             SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
     186           0 :                             &aDefPage, 0L );
     187           0 :             }
     188             :         }
     189           0 :         break;
     190             :         case SID_PRINTDOC:
     191             :         case SID_PRINTDOCDIRECT:
     192             :         {
     193           0 :             SwWrtShell* pSh = &GetWrtShell();
     194           0 :             SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, false);
     195           0 :             sal_Bool bSilent = pSilentItem ? pSilentItem->GetValue() : sal_False;
     196           0 :             SFX_REQUEST_ARG(rReq, pPrintFromMergeItem, SfxBoolItem, FN_QRY_MERGE, false);
     197           0 :             if(pPrintFromMergeItem)
     198           0 :                 rReq.RemoveItem(FN_QRY_MERGE);
     199           0 :             sal_Bool bFromMerge = pPrintFromMergeItem ? pPrintFromMergeItem->GetValue() : sal_False;
     200           0 :             SwMiscConfig aMiscConfig;
     201           0 :             bool bPrintSelection = false;
     202           0 :             if(!bSilent && !bFromMerge &&
     203           0 :                     SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc())
     204             :             {
     205           0 :                 QueryBox aBox( &GetEditWin(), SW_RES( MSG_PRINT_AS_MERGE ));
     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, SFX_CALLMODE_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(!this, "wrong dispatcher");
     242           0 :             return;
     243             :     }
     244             : }
     245             : 
     246             : // Create page printer/additions for SwView and SwPagePreview
     247             : 
     248           0 : SfxTabPage* CreatePrintOptionsPage( Window *pParent,
     249             :                                 const SfxItemSet &rOptions, sal_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, sal_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           0 : }
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10