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