LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/uiview - viewprt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 133 5.3 %
Date: 2012-12-27 Functions: 3 10 30.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             : /*--------------------------------------------------------------------
      70             :     Beschreibung:   Drucker an Sfx uebergeben
      71             :  --------------------------------------------------------------------*/
      72         128 : SfxPrinter* SwView::GetPrinter( sal_Bool bCreate )
      73             : {
      74         128 :     const IDocumentDeviceAccess* pIDDA = GetWrtShell().getIDocumentDeviceAccess();
      75         128 :     SfxPrinter *pOld = pIDDA->getPrinter( false );
      76         128 :     SfxPrinter *pPrt = pIDDA->getPrinter( bCreate );
      77         128 :     if ( pOld != pPrt )
      78             :     {
      79           0 :         sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
      80           0 :         ::SetAppPrintOptions( &GetWrtShell(), bWeb );
      81             :     }
      82         128 :     return pPrt;
      83             : }
      84             : 
      85             : /*--------------------------------------------------------------------
      86             :     Beschreibung:   Druckerwechsel weitermelden
      87             :  --------------------------------------------------------------------*/
      88           0 : void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter* pNew, sal_Bool bWeb )
      89             : {
      90           0 :     SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb);
      91           0 :     if( !pOpt)
      92           0 :         return;
      93             : 
      94             :     // Applikationseigene Druckoptionen aus SfxPrinter auslesen
      95           0 :     const SfxItemSet& rSet = pNew->GetOptions();
      96             : 
      97             :     const SwAddPrinterItem* pAddPrinterAttr;
      98           0 :     if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, sal_False,
      99           0 :         (const SfxPoolItem**)&pAddPrinterAttr ) )
     100             :     {
     101           0 :         if( pIDDA )
     102           0 :             pIDDA->setPrintData( *pAddPrinterAttr );
     103           0 :         if( !pAddPrinterAttr->GetFax().isEmpty() )
     104           0 :             pOpt->SetFaxName(pAddPrinterAttr->GetFax());
     105             :     }
     106             : }
     107             : 
     108           0 : sal_uInt16 SwView::SetPrinter(SfxPrinter* pNew, sal_uInt16 nDiffFlags, bool  )
     109             : {
     110           0 :     SwWrtShell &rSh = GetWrtShell();
     111           0 :     SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
     112           0 :     if ( pOld && pOld->IsPrinting() )
     113           0 :         return SFX_PRINTERROR_BUSY;
     114             : 
     115           0 :     if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags )
     116             :     {
     117           0 :         rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
     118           0 :         if ( nDiffFlags & SFX_PRINTER_PRINTER )
     119           0 :             rSh.SetModified();
     120             :     }
     121           0 :     sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
     122           0 :     if ( nDiffFlags & SFX_PRINTER_OPTIONS )
     123           0 :         ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, bWeb );
     124             : 
     125           0 :     const sal_Bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? sal_True : sal_False;
     126           0 :     const sal_Bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? sal_True : sal_False;
     127           0 :     if ( bChgOri || bChgSize )
     128             :     {
     129           0 :         rSh.StartAllAction();
     130           0 :         if ( bChgOri )
     131           0 :             rSh.ChgAllPageOrientation( sal_uInt16(pNew->GetOrientation()) );
     132           0 :         if ( bChgSize )
     133             :         {
     134           0 :             Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
     135           0 :             rSh.ChgAllPageSize( aSz );
     136             :         }
     137           0 :         rSh.SetModified();
     138           0 :         rSh.EndAllAction();
     139           0 :         InvalidateRulerPos();
     140             :     }
     141           0 :     return 0;
     142             : }
     143             : 
     144           0 : bool SwView::HasPrintOptionsPage() const
     145             : {
     146           0 :     return true;
     147             : }
     148             : 
     149             : /*--------------------------------------------------------------------
     150             :     Beschreibung:   TabPage fuer applikationsspezifische Druckoptionen
     151             :  --------------------------------------------------------------------*/
     152           0 : SfxTabPage* SwView::CreatePrintOptionsPage(Window* pParent,
     153             :                                                     const SfxItemSet& rSet)
     154             : {
     155           0 :     return ::CreatePrintOptionsPage( pParent, rSet, sal_False );
     156             : }
     157             : 
     158             : /*--------------------------------------------------------------------
     159             :     Beschreibung:   Print-Dispatcher
     160             :  --------------------------------------------------------------------*/
     161           0 : void SwView::ExecutePrint(SfxRequest& rReq)
     162             : {
     163           0 :     sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
     164           0 :     ::SetAppPrintOptions( &GetWrtShell(), bWeb );
     165           0 :     switch (rReq.GetSlot())
     166             :     {
     167             :         case FN_FAX:
     168             :         {
     169           0 :             SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb);
     170           0 :             String sFaxName(pPrintOptions->GetFaxName());
     171           0 :             if (sFaxName.Len())
     172             :             {
     173           0 :                 SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName);
     174           0 :                 SfxBoolItem aSilent( SID_SILENT, sal_True );
     175             :                 GetViewFrame()->GetDispatcher()->Execute( SID_PRINTDOC,
     176             :                             SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
     177           0 :                             &aPrinterName, &aSilent, 0L );
     178             :             }
     179             :             else
     180             :             {
     181           0 :                 InfoBox aInfoBox(&GetEditWin(), SW_RES(MSG_ERR_NO_FAX));
     182           0 :                 String sMsg = aInfoBox.GetMessText();
     183           0 :                 sal_uInt16 nResNo = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS;
     184           0 :                 sMsg.SearchAndReplace(rtl::OUString("%1"), String(SW_RES(nResNo)));
     185           0 :                 aInfoBox.SetMessText(sMsg);
     186           0 :                 aInfoBox.Execute();
     187           0 :                 SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE);
     188             :                 GetViewFrame()->GetDispatcher()->Execute(SID_SW_EDITOPTIONS,
     189             :                             SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
     190           0 :                             &aDefPage, 0L );
     191           0 :             }
     192             :         }
     193           0 :         break;
     194             :         case SID_PRINTDOC:
     195             :         case SID_PRINTDOCDIRECT:
     196             :         {
     197           0 :             SwWrtShell* pSh = &GetWrtShell();
     198           0 :             SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
     199           0 :             sal_Bool bSilent = pSilentItem ? pSilentItem->GetValue() : sal_False;
     200           0 :             SFX_REQUEST_ARG(rReq, pPrintFromMergeItem, SfxBoolItem, FN_QRY_MERGE, sal_False);
     201           0 :             if(pPrintFromMergeItem)
     202           0 :                 rReq.RemoveItem(FN_QRY_MERGE);
     203           0 :             sal_Bool bFromMerge = pPrintFromMergeItem ? pPrintFromMergeItem->GetValue() : sal_False;
     204           0 :             SwMiscConfig aMiscConfig;
     205           0 :             bool bPrintSelection = false;
     206           0 :             if(!bSilent && !bFromMerge &&
     207           0 :                     SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc())
     208             :             {
     209           0 :                 QueryBox aBox( &GetEditWin(), SW_RES( MSG_PRINT_AS_MERGE ));
     210           0 :                 short nRet = aBox.Execute();
     211           0 :                 if(RET_YES == nRet)
     212             :                 {
     213           0 :                     SfxBoolItem aBool(FN_QRY_MERGE, sal_True);
     214             :                     GetViewFrame()->GetDispatcher()->Execute(
     215           0 :                                 FN_QRY_MERGE, SFX_CALLMODE_ASYNCHRON, &aBool, 0L);
     216           0 :                     rReq.Ignore();
     217           0 :                     return;
     218           0 :                 }
     219             :             }
     220           0 :             else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent )
     221             :             {
     222           0 :                 if( ( pSh->IsSelection() || pSh->IsFrmSelected() || pSh->IsObjSelected() ) )
     223             :                 {
     224           0 :                     short nBtn = SvxPrtQryBox(&GetEditWin()).Execute();
     225           0 :                     if( RET_CANCEL == nBtn )
     226             :                         return;
     227             : 
     228           0 :                     if( RET_OK == nBtn )
     229           0 :                         bPrintSelection = true;
     230             :                 }
     231             :             }
     232             : 
     233             :             //#i61455# if master documentes are printed silently without loaded links then update the links now
     234           0 :             if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() )
     235             :             {
     236           0 :                 pSh->GetLinkManager().UpdateAllLinks( false, false, false, 0 );
     237             :             }
     238           0 :             SfxRequest aReq( rReq );
     239           0 :             SfxBoolItem aBool(SID_SELECTION, bPrintSelection);
     240           0 :             aReq.AppendItem( aBool );
     241           0 :             SfxViewShell::ExecuteSlot( aReq, SfxViewShell::GetInterface() );
     242           0 :             return;
     243             :         }
     244             :         default:
     245             :             OSL_ENSURE(!this, "wrong dispatcher");
     246           0 :             return;
     247             :     }
     248             : }
     249             : 
     250             : /*--------------------------------------------------------------------
     251             :     Beschreibung:   Page Drucker/Zusaetze erzeugen fuer SwView und
     252             :                     SwPagePreview
     253             :  --------------------------------------------------------------------*/
     254           0 : SfxTabPage* CreatePrintOptionsPage( Window *pParent,
     255             :                                 const SfxItemSet &rOptions, sal_Bool bPreview )
     256             : {
     257           0 :     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     258             :     OSL_ENSURE(pFact, "No Print Dialog");
     259           0 :     if (!pFact)
     260           0 :         return NULL;
     261             : 
     262           0 :     ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc(TP_OPTPRINT_PAGE);
     263             :     OSL_ENSURE(pFact, "No Page Creator");
     264           0 :     if (!fnCreatePage)
     265           0 :         return NULL;
     266             : 
     267           0 :     SfxTabPage* pPage = (*fnCreatePage)(pParent, rOptions);
     268             :     OSL_ENSURE(pPage, "No page");
     269           0 :     if (!pPage)
     270           0 :         return NULL;
     271             : 
     272           0 :     SfxAllItemSet aSet(*(rOptions.GetPool()));
     273           0 :     aSet.Put(SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview));
     274           0 :     aSet.Put(SfxBoolItem(SID_FAX_LIST, sal_True));
     275           0 :     pPage->PageCreated(aSet);
     276           0 :     return pPage;
     277             : }
     278             : 
     279           0 : void SetAppPrintOptions( ViewShell* pSh, sal_Bool bWeb )
     280             : {
     281           0 :     const IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
     282           0 :     SwPrintData aPrtData = pIDDA->getPrintData();
     283             : 
     284           0 :     if( pIDDA->getPrinter( false ) )
     285             :     {
     286             :         // Applikationseigene Druckoptionen in SfxPrinter schiessen
     287           0 :         SwAddPrinterItem aAddPrinterItem (FN_PARAM_ADDPRINTER, aPrtData);
     288           0 :         SfxItemSet aSet( pSh->GetAttrPool(),
     289             :                     FN_PARAM_ADDPRINTER,        FN_PARAM_ADDPRINTER,
     290             :                     SID_HTML_MODE,              SID_HTML_MODE,
     291             :                     SID_PRINTER_NOTFOUND_WARN,  SID_PRINTER_NOTFOUND_WARN,
     292             :                     SID_PRINTER_CHANGESTODOC,   SID_PRINTER_CHANGESTODOC,
     293           0 :                     0 );
     294             : 
     295           0 :         utl::MiscCfg aMisc;
     296             : 
     297           0 :         if(bWeb)
     298             :             aSet.Put(SfxUInt16Item(SID_HTML_MODE,
     299           0 :                     ::GetHtmlMode(((SwWrtShell*)pSh)->GetView().GetDocShell())));
     300             :         aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN,
     301           0 :                         aMisc.IsNotFoundWarning() ));
     302           0 :         aSet.Put(aAddPrinterItem);
     303             :         aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC,
     304           0 :             (aMisc.IsPaperSizeWarning() ? SFX_PRINTER_CHG_SIZE : 0)   |
     305           0 :             (aMisc.IsPaperOrientationWarning()  ? SFX_PRINTER_CHG_ORIENTATION : 0 )));
     306             : 
     307           0 :         pIDDA->getPrinter( true )->SetOptions( aSet );
     308           0 :     }
     309             : 
     310          30 : }
     311             : 
     312             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10