xref: /trunk/main/sw/source/ui/uiview/viewprt.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <com/sun/star/text/NotePrintMode.hpp>
32 
33 #if STLPORT_VERSION>=321
34 #include <cstdarg>
35 #endif
36 
37 #ifndef _CMDID_H
38 #include <cmdid.h>
39 #endif
40 
41 #ifndef _SVSTDARR_HXX
42 #define _SVSTDARR_STRINGSDTOR
43 #include <svl/svstdarr.hxx>
44 #endif
45 #include <sfx2/request.hxx>
46 
47 #include <sfx2/progress.hxx>
48 #include <sfx2/app.hxx>
49 #include <svl/flagitem.hxx>
50 #include <vcl/msgbox.hxx>
51 #include <vcl/oldprintadaptor.hxx>
52 #include <sfx2/printer.hxx>
53 #include <sfx2/prnmon.hxx>
54 #include <editeng/paperinf.hxx>
55 #include <sfx2/dispatch.hxx>
56 #include <unotools/misccfg.hxx>
57 #include <svx/prtqry.hxx>
58 #include <svx/svdview.hxx>
59 #include <svl/eitem.hxx>
60 #include <svl/stritem.hxx>
61 #include <svl/intitem.hxx>
62 #include <svl/flagitem.hxx>
63 #include <sfx2/linkmgr.hxx>
64 
65 #include <modcfg.hxx>
66 #include <edtwin.hxx>
67 #include <view.hxx>
68 #include <wrtsh.hxx>
69 #include <docsh.hxx>
70 #include <viewopt.hxx>
71 #include <prtopt.hxx>
72 #include <fontcfg.hxx>
73 #include <cfgitems.hxx>
74 #include <dbmgr.hxx>
75 #include <docstat.hxx>
76 #include <viewfunc.hxx>
77 #include <swmodule.hxx>
78 #include <wview.hxx>
79 #include <doc.hxx>
80 #include <fldbas.hxx>
81 
82 #include <globals.hrc>
83 #include <view.hrc>
84 #include <app.hrc>
85 #include <svl/eitem.hxx>
86 #include <swwrtshitem.hxx>
87 #include "swabstdlg.hxx"
88 #include <svl/slstitm.hxx>
89 
90 #include <unomid.h>
91 
92 using namespace ::com::sun::star;
93 
94 
95 /*--------------------------------------------------------------------
96     Beschreibung:   Drucker an Sfx uebergeben
97  --------------------------------------------------------------------*/
98 
99 
100 SfxPrinter* __EXPORT SwView::GetPrinter( sal_Bool bCreate )
101 {
102     const IDocumentDeviceAccess* pIDDA = GetWrtShell().getIDocumentDeviceAccess();
103     SfxPrinter *pOld = pIDDA->getPrinter( false );
104     SfxPrinter *pPrt = pIDDA->getPrinter( bCreate );
105     if ( pOld != pPrt )
106     {
107         sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
108         ::SetAppPrintOptions( &GetWrtShell(), bWeb );
109     }
110     return pPrt;
111 }
112 
113 /*--------------------------------------------------------------------
114     Beschreibung:   Druckerwechsel weitermelden
115  --------------------------------------------------------------------*/
116 
117 void SetPrinter( IDocumentDeviceAccess* pIDDA, SfxPrinter* pNew, sal_Bool bWeb )
118 {
119     SwPrintOptions* pOpt = SW_MOD()->GetPrtOptions(bWeb);
120     if( !pOpt)
121         return;
122 
123     // Applikationseigene Druckoptionen aus SfxPrinter auslesen
124     const SfxItemSet& rSet = pNew->GetOptions();
125 
126     const SwAddPrinterItem* pAddPrinterAttr;
127     if( SFX_ITEM_SET == rSet.GetItemState( FN_PARAM_ADDPRINTER, sal_False,
128         (const SfxPoolItem**)&pAddPrinterAttr ) )
129     {
130         if( pIDDA )
131             pIDDA->setPrintData( *pAddPrinterAttr );
132         if( pAddPrinterAttr->GetFax().getLength() )
133             pOpt->SetFaxName(pAddPrinterAttr->GetFax());
134     }
135 }
136 
137 
138 sal_uInt16 __EXPORT SwView::SetPrinter(SfxPrinter* pNew, sal_uInt16 nDiffFlags, bool  )
139 {
140     SwWrtShell &rSh = GetWrtShell();
141     SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
142     if ( pOld && pOld->IsPrinting() )
143         return SFX_PRINTERROR_BUSY;
144 
145     if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags )
146     {
147         rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
148         if ( nDiffFlags & SFX_PRINTER_PRINTER )
149             rSh.SetModified();
150     }
151     sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
152     if ( nDiffFlags & SFX_PRINTER_OPTIONS )
153         ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, bWeb );
154 
155     const sal_Bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? sal_True : sal_False;
156     const sal_Bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? sal_True : sal_False;
157     if ( bChgOri || bChgSize )
158     {
159         rSh.StartAllAction();
160         if ( bChgOri )
161             rSh.ChgAllPageOrientation( sal_uInt16(pNew->GetOrientation()) );
162         if ( bChgSize )
163         {
164             Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
165             rSh.ChgAllPageSize( aSz );
166         }
167         rSh.SetModified();
168         rSh.EndAllAction();
169         InvalidateRulerPos();
170     }
171     return 0;
172 }
173 
174 /*--------------------------------------------------------------------
175     Beschreibung:   TabPage fuer applikationsspezifische Druckoptionen
176  --------------------------------------------------------------------*/
177 
178 SfxTabPage* __EXPORT SwView::CreatePrintOptionsPage(Window* pParent,
179                                                     const SfxItemSet& rSet)
180 {
181     return ::CreatePrintOptionsPage( pParent, rSet, sal_False );
182 }
183 
184 /*--------------------------------------------------------------------
185     Beschreibung:   Print-Dispatcher
186  --------------------------------------------------------------------*/
187 
188 void __EXPORT SwView::ExecutePrint(SfxRequest& rReq)
189 {
190     sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
191     ::SetAppPrintOptions( &GetWrtShell(), bWeb );
192     switch (rReq.GetSlot())
193     {
194         case FN_FAX:
195         {
196             SwPrintOptions* pPrintOptions = SW_MOD()->GetPrtOptions(bWeb);
197             String sFaxName(pPrintOptions->GetFaxName());
198             if (sFaxName.Len())
199             {
200                 SfxStringItem aPrinterName(SID_PRINTER_NAME, sFaxName);
201                 SfxBoolItem aSilent( SID_SILENT, sal_True );
202                 GetViewFrame()->GetDispatcher()->Execute( SID_PRINTDOC,
203                             SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
204                             &aPrinterName, &aSilent, 0L );
205             }
206             else
207             {
208                 InfoBox aInfoBox(&GetEditWin(), SW_RES(MSG_ERR_NO_FAX));
209                 String sMsg = aInfoBox.GetMessText();
210                 sal_uInt16 nResNo = bWeb ? STR_WEBOPTIONS : STR_TEXTOPTIONS;
211                 sMsg.SearchAndReplace(String::CreateFromAscii("%1"), String(SW_RES(nResNo)));
212                 aInfoBox.SetMessText(sMsg);
213                 aInfoBox.Execute();
214                 SfxUInt16Item aDefPage(SID_SW_EDITOPTIONS, TP_OPTPRINT_PAGE);
215                 GetViewFrame()->GetDispatcher()->Execute(SID_SW_EDITOPTIONS,
216                             SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
217                             &aDefPage, 0L );
218             }
219         }
220         break;
221         case SID_PRINTDOC:
222         case SID_PRINTDOCDIRECT:
223         {
224             SwWrtShell* pSh = &GetWrtShell();
225             SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
226             sal_Bool bSilent = pSilentItem ? pSilentItem->GetValue() : sal_False;
227             SFX_REQUEST_ARG(rReq, pPrintFromMergeItem, SfxBoolItem, FN_QRY_MERGE, sal_False);
228             if(pPrintFromMergeItem)
229                 rReq.RemoveItem(FN_QRY_MERGE);
230             sal_Bool bFromMerge = pPrintFromMergeItem ? pPrintFromMergeItem->GetValue() : sal_False;
231             SwMiscConfig aMiscConfig;
232             bool bPrintSelection = false;
233             if(!bSilent && !bFromMerge &&
234                     SW_MOD()->GetModuleConfig()->IsAskForMailMerge() && pSh->IsAnyDatabaseFieldInDoc())
235             {
236                 QueryBox aBox( &GetEditWin(), SW_RES( MSG_PRINT_AS_MERGE ));
237                 short nRet = aBox.Execute();
238                 if(RET_YES == nRet)
239                 {
240                     SfxBoolItem aBool(FN_QRY_MERGE, sal_True);
241                     GetViewFrame()->GetDispatcher()->Execute(
242                                 FN_QRY_MERGE, SFX_CALLMODE_ASYNCHRON, &aBool, 0L);
243                     rReq.Ignore();
244                     return;
245                 }
246             }
247             else if( rReq.GetSlot() == SID_PRINTDOCDIRECT && ! bSilent )
248             {
249                 if( /*!bIsAPI && */
250                    ( pSh->IsSelection() || pSh->IsFrmSelected() || pSh->IsObjSelected() ) )
251                 {
252                     short nBtn = SvxPrtQryBox(&GetEditWin()).Execute();
253                     if( RET_CANCEL == nBtn )
254                         return;;
255 
256                     if( RET_OK == nBtn )
257                         bPrintSelection = true;
258                 }
259             }
260 
261             //#i61455# if master documentes are printed silently without loaded links then update the links now
262             if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() )
263             {
264                 pSh->GetLinkManager().UpdateAllLinks( sal_False, sal_False, sal_False, 0 );
265             }
266             SfxRequest aReq( rReq );
267             SfxBoolItem aBool(SID_SELECTION, bPrintSelection);
268             aReq.AppendItem( aBool );
269             SfxViewShell::ExecuteSlot( aReq, SfxViewShell::GetInterface() );
270             return;
271         }
272         default:
273             ASSERT(!this, falscher Dispatcher);
274             return;
275     }
276 }
277 
278 /*--------------------------------------------------------------------
279     Beschreibung:   Page Drucker/Zusaetze erzeugen fuer SwView und
280                     SwPagePreview
281  --------------------------------------------------------------------*/
282 
283 SfxTabPage* CreatePrintOptionsPage( Window *pParent,
284                                 const SfxItemSet &rOptions, sal_Bool bPreview )
285 {
286     SfxTabPage* pPage = NULL;
287     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
288     if ( pFact )
289     {
290         ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( TP_OPTPRINT_PAGE );
291         if ( fnCreatePage )
292             pPage = (*fnCreatePage)( pParent, rOptions );
293     }
294     SfxAllItemSet aSet(*(rOptions.GetPool()));
295     aSet.Put (SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview));
296     aSet.Put (SfxBoolItem(SID_FAX_LIST, sal_True));
297     pPage->PageCreated(aSet);
298     return pPage;
299 }
300 
301 
302 void SetAppPrintOptions( ViewShell* pSh, sal_Bool bWeb )
303 {
304     const IDocumentDeviceAccess* pIDDA = pSh->getIDocumentDeviceAccess();
305     SwPrintData aPrtData = pIDDA->getPrintData();
306 
307     if( pIDDA->getPrinter( false ) )
308     {
309         // Applikationseigene Druckoptionen in SfxPrinter schiessen
310         SwAddPrinterItem aAddPrinterItem (FN_PARAM_ADDPRINTER, aPrtData);
311         SfxItemSet aSet( pSh->GetAttrPool(),
312                     FN_PARAM_ADDPRINTER,        FN_PARAM_ADDPRINTER,
313                     SID_HTML_MODE,              SID_HTML_MODE,
314                     SID_PRINTER_NOTFOUND_WARN,  SID_PRINTER_NOTFOUND_WARN,
315                     SID_PRINTER_CHANGESTODOC,   SID_PRINTER_CHANGESTODOC,
316                     0 );
317 
318         utl::MiscCfg aMisc;
319 
320         if(bWeb)
321             aSet.Put(SfxUInt16Item(SID_HTML_MODE,
322                     ::GetHtmlMode(((SwWrtShell*)pSh)->GetView().GetDocShell())));
323         aSet.Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN,
324                         aMisc.IsNotFoundWarning() ));
325         aSet.Put(aAddPrinterItem);
326         aSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC,
327             (aMisc.IsPaperSizeWarning() ? SFX_PRINTER_CHG_SIZE : 0)   |
328             (aMisc.IsPaperOrientationWarning()  ? SFX_PRINTER_CHG_ORIENTATION : 0 )));
329 
330         pIDDA->getPrinter( true )->SetOptions( aSet );
331     }
332 
333 }
334