nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / view / printdata.cxx
blob03526c134e56fe718d33cea396a4bdec9a53dbff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <printdata.hxx>
22 #include <strings.hrc>
23 #include <doc.hxx>
24 #include <IDocumentDeviceAccess.hxx>
25 #include <unotxdoc.hxx>
26 #include <wdocsh.hxx>
27 #include <viewsh.hxx>
28 #include <docfld.hxx>
30 #include <svl/languageoptions.hxx>
31 #include <toolkit/awt/vclxdevice.hxx>
32 #include <unotools/moduleoptions.hxx>
33 #include <vcl/outdev.hxx>
34 #include <osl/diagnose.h>
36 using namespace ::com::sun::star;
38 SwRenderData::SwRenderData()
42 SwRenderData::~SwRenderData()
44 OSL_ENSURE( !m_pPostItShell, "m_pPostItShell should already have been deleted" );
45 OSL_ENSURE( !m_pPostItFields, " should already have been deleted" );
48 void SwRenderData::CreatePostItData( SwDoc& rDoc, const SwViewOption *pViewOpt, OutputDevice *pOutDev )
50 DeletePostItData();
51 m_pPostItFields.reset(new SetGetExpFields);
52 sw_GetPostIts( rDoc.getIDocumentFieldsAccess(), m_pPostItFields.get() );
54 //!! Disable spell and grammar checking in the temporary document.
55 //!! Otherwise the grammar checker might process it and crash if we later on
56 //!! simply delete this document while he is still at it.
57 SwViewOption aViewOpt( *pViewOpt );
58 aViewOpt.SetOnlineSpell( false );
60 m_pPostItShell.reset(new SwViewShell(*new SwDoc, nullptr, &aViewOpt, pOutDev));
63 void SwRenderData::DeletePostItData()
65 if (HasPostItData())
67 // printer needs to remain at the real document
68 m_pPostItShell->GetDoc()->getIDocumentDeviceAccess().setPrinter( nullptr, false, false );
69 { // avoid destroying layout from SwDoc dtor
70 rtl::Reference<SwDoc> const xKeepAlive(m_pPostItShell->GetDoc());
71 m_pPostItShell.reset();
73 m_pPostItFields.reset();
77 void SwRenderData::SetTempDocShell(SfxObjectShellLock const& xShell)
79 m_xTempDocShell = xShell;
82 bool SwRenderData::NeedNewViewOptionAdjust( const SwViewShell& rCompare ) const
84 return !(m_pViewOptionAdjust && m_pViewOptionAdjust->checkShell( rCompare ));
87 void SwRenderData::ViewOptionAdjustStart(
88 SwViewShell &rSh, const SwViewOption &rViewOptions)
90 if (m_pViewOptionAdjust)
92 OSL_FAIL("error: there should be no ViewOptionAdjust active when calling this function" );
94 m_pViewOptionAdjust.reset(
95 new SwViewOptionAdjust_Impl( rSh, rViewOptions ));
98 void SwRenderData::ViewOptionAdjust(SwPrintData const*const pPrtOptions, bool setShowPlaceHoldersInPDF)
100 m_pViewOptionAdjust->AdjustViewOptions( pPrtOptions, setShowPlaceHoldersInPDF );
103 void SwRenderData::ViewOptionAdjustStop()
105 m_pViewOptionAdjust.reset();
108 void SwRenderData::ViewOptionAdjustCrashPreventionKludge()
110 m_pViewOptionAdjust->DontTouchThatViewShellItSmellsFunny();
113 void SwRenderData::MakeSwPrtOptions(
114 SwDocShell const*const pDocShell,
115 SwPrintUIOptions const*const pOpt,
116 bool const bIsPDFExport)
118 if (!pDocShell || !pOpt)
119 return;
121 m_pPrtOptions.reset(new SwPrintData);
122 SwPrintData & rOptions(*m_pPrtOptions);
124 // get default print options
125 bool bWeb = dynamic_cast<const SwWebDocShell*>( pDocShell) != nullptr;
126 ::sw::InitPrintOptionsFromApplication(rOptions, bWeb);
128 // get print options to use from provided properties
129 rOptions.m_bPrintGraphic = pOpt->IsPrintGraphics();
130 rOptions.m_bPrintTable = true; // for now it was decided that tables should always be printed
131 rOptions.m_bPrintDraw = pOpt->IsPrintDrawings();
132 rOptions.m_bPrintControl = pOpt->IsPrintFormControls();
133 rOptions.m_bPrintLeftPages = pOpt->IsPrintLeftPages();
134 rOptions.m_bPrintRightPages = pOpt->IsPrintRightPages();
135 rOptions.m_bPrintPageBackground = pOpt->IsPrintPageBackground();
136 rOptions.m_bPrintEmptyPages = pOpt->IsPrintEmptyPages( bIsPDFExport );
137 // bUpdateFieldsInPrinting <-- not set here; mail merge only
138 rOptions.m_bPaperFromSetup = pOpt->IsPaperFromSetup();
139 rOptions.m_bPrintReverse = false; /*handled by print dialog now*/
140 rOptions.m_bPrintProspect = pOpt->IsPrintProspect();
141 rOptions.m_bPrintProspectRTL = pOpt->IsPrintProspectRTL();
142 // bPrintSingleJobs <-- not set here; mail merge and or configuration
143 // bModified <-- not set here; mail merge only
144 rOptions.m_bPrintBlackFont = pOpt->IsPrintWithBlackTextColor();
145 rOptions.m_bPrintHiddenText = pOpt->IsPrintHiddenText();
146 rOptions.m_bPrintTextPlaceholder = pOpt->IsPrintTextPlaceholders();
147 rOptions.m_nPrintPostIts = pOpt->GetPrintPostItsType();
149 //! needs to be set after MakeOptions since the assignment operation in that
150 //! function will destroy the pointers
151 rOptions.SetRenderData( this );
154 SwPrintUIOptions::SwPrintUIOptions(
155 sal_uInt16 nCurrentPage,
156 bool bWeb,
157 bool bSwSrcView,
158 bool bHasSelection,
159 bool bHasPostIts,
160 const SwPrintData &rDefaultPrintData ) :
161 m_rDefaultPrintData( rDefaultPrintData )
163 // printing HTML sources does not have any valid UI options.
164 // It's just the source code that gets printed...
165 if (bSwSrcView)
167 m_aUIProperties.clear();
168 return;
171 // check if either CJK or CTL is enabled
172 SvtLanguageOptions aLangOpt;
173 bool bRTL = aLangOpt.IsCJKFontEnabled() || aLangOpt.IsCTLFontEnabled();
175 // create sequence of print UI options
176 // (5 options are not available for Writer-Web)
177 const int nRTLOpts = bRTL ? 1 : 0;
178 const int nNumProps = nRTLOpts + (bWeb ? 15 : 19);
179 m_aUIProperties.resize( nNumProps);
180 int nIdx = 0;
182 // load the writer PrinterOptions into the custom tab
183 m_aUIProperties[nIdx].Name = "OptionsUIFile";
184 m_aUIProperties[nIdx++].Value <<= OUString("modules/swriter/ui/printeroptions.ui");
186 // create "writer" section (new tab page in dialog)
187 SvtModuleOptions aModOpt;
188 OUString aAppGroupname( SwResId( STR_PRINTOPTUI_PRODUCTNAME) );
189 aAppGroupname = aAppGroupname.replaceFirst( "%s", aModOpt.GetModuleName( SvtModuleOptions::EModule::WRITER ) );
190 m_aUIProperties[ nIdx++ ].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, ".HelpID:vcl:PrintDialog:TabPage:AppPage");
192 // create sub section for Contents
193 m_aUIProperties[ nIdx++ ].Value = setSubgroupControlOpt("contents", SwResId( STR_PRINTOPTUI_CONTENTS), OUString());
195 // create a bool option for background
196 bool bDefaultVal = rDefaultPrintData.IsPrintPageBackground();
197 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("pagebackground", SwResId( STR_PRINTOPTUI_PAGE_BACKGROUND),
198 ".HelpID:vcl:PrintDialog:PrintPageBackground:CheckBox",
199 "PrintPageBackground",
200 bDefaultVal);
202 // create a bool option for pictures/graphics AND OLE and drawing objects as well
203 bDefaultVal = rDefaultPrintData.IsPrintGraphic() || rDefaultPrintData.IsPrintDraw();
204 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("pictures", SwResId( STR_PRINTOPTUI_PICTURES),
205 ".HelpID:vcl:PrintDialog:PrintPicturesAndObjects:CheckBox",
206 "PrintPicturesAndObjects",
207 bDefaultVal);
208 if (!bWeb)
210 // create a bool option for hidden text
211 bDefaultVal = rDefaultPrintData.IsPrintHiddenText();
212 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("hiddentext", SwResId( STR_PRINTOPTUI_HIDDEN),
213 ".HelpID:vcl:PrintDialog:PrintHiddenText:CheckBox",
214 "PrintHiddenText",
215 bDefaultVal);
217 // create a bool option for place holder
218 bDefaultVal = rDefaultPrintData.IsPrintTextPlaceholder();
219 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("placeholders", SwResId( STR_PRINTOPTUI_TEXT_PLACEHOLDERS),
220 ".HelpID:vcl:PrintDialog:PrintTextPlaceholder:CheckBox",
221 "PrintTextPlaceholder",
222 bDefaultVal);
225 // create a bool option for controls
226 bDefaultVal = rDefaultPrintData.IsPrintControl();
227 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("formcontrols", SwResId( STR_PRINTOPTUI_FORM_CONTROLS),
228 ".HelpID:vcl:PrintDialog:PrintControls:CheckBox",
229 "PrintControls",
230 bDefaultVal);
232 // create sub section for Color
233 m_aUIProperties[ nIdx++ ].Value = setSubgroupControlOpt("color", SwResId( STR_PRINTOPTUI_COLOR), OUString());
235 // create a bool option for printing text with black font color
236 bDefaultVal = rDefaultPrintData.IsPrintBlackFont();
237 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("textinblack", SwResId( STR_PRINTOPTUI_PRINT_BLACK),
238 ".HelpID:vcl:PrintDialog:PrintBlackFonts:CheckBox",
239 "PrintBlackFonts",
240 bDefaultVal);
242 if (!bWeb)
244 // create subgroup for misc options
245 m_aUIProperties[ nIdx++ ].Value = setSubgroupControlOpt("pages", SwResId( STR_PRINTOPTUI_PAGES_TEXT), OUString());
247 // create a bool option for printing automatically inserted blank pages
248 bDefaultVal = rDefaultPrintData.IsPrintEmptyPages();
249 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("autoblankpages", SwResId( STR_PRINTOPTUI_PRINT_BLANK),
250 ".HelpID:vcl:PrintDialog:PrintEmptyPages:CheckBox",
251 "PrintEmptyPages",
252 bDefaultVal);
255 // create a bool option for paper tray
256 bDefaultVal = rDefaultPrintData.IsPaperFromSetup();
257 vcl::PrinterOptionsHelper::UIControlOptions aPaperTrayOpt;
258 aPaperTrayOpt.maGroupHint = "OptionsPageOptGroup";
259 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("printpaperfromsetup", SwResId( STR_PRINTOPTUI_ONLY_PAPER),
260 ".HelpID:vcl:PrintDialog:PrintPaperFromSetup:CheckBox",
261 "PrintPaperFromSetup",
262 bDefaultVal,
263 aPaperTrayOpt);
265 // print range selection
266 vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
267 aPrintRangeOpt.maGroupHint = "PrintRange";
268 aPrintRangeOpt.mbInternalOnly = true;
269 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt( "printrange",
270 SwResId( STR_PRINTOPTUI_PAGES_TEXT ),
271 OUString(),
272 aPrintRangeOpt );
274 // create a choice for the content to create
275 const OUString aPrintRangeName( "PrintContent" );
276 uno::Sequence< OUString > aChoices( 3 );
277 uno::Sequence< sal_Bool > aChoicesDisabled( 3 );
278 uno::Sequence< OUString > aHelpIds( 3 );
279 uno::Sequence< OUString > aWidgetIds( 3 );
280 aChoices[0] = SwResId( STR_PRINTOPTUI_PRINTALLPAGES );
281 aChoicesDisabled[0] = false;
282 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0";
283 aWidgetIds[0] = "rbAllPages";
284 aChoices[1] = SwResId( STR_PRINTOPTUI_PRINTPAGES );
285 aChoicesDisabled[1] = false;
286 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1";
287 aWidgetIds[1] = "rbRangePages";
288 aChoices[2] = SwResId( STR_PRINTOPTUI_PRINTSELECTION );
289 aChoicesDisabled[2] = !bHasSelection;
290 aHelpIds[2] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:2";
291 aWidgetIds[2] = "rbRangeSelection";
292 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
293 aHelpIds, aPrintRangeName,
294 aChoices,
295 bHasSelection ? 2 : 0,
296 aChoicesDisabled);
298 // show an Edit dependent on "Pages" selected
299 vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt( aPrintRangeName, 1, true );
300 m_aUIProperties[nIdx++].Value = setEditControlOpt("pagerange", OUString(),
301 ".HelpID:vcl:PrintDialog:PageRange:Edit",
302 "PageRange",
303 OUString::number( nCurrentPage ) /* set text box to current page number */,
304 aPageRangeOpt);
306 vcl::PrinterOptionsHelper::UIControlOptions aEvenOddOpt(aPrintRangeName, -1, true);
307 m_aUIProperties[ nIdx++ ].Value = setChoiceListControlOpt("evenoddbox",
308 OUString(),
309 uno::Sequence<OUString>(),
310 "EvenOdd",
311 uno::Sequence<OUString>(),
313 uno::Sequence< sal_Bool >(),
314 aEvenOddOpt);
316 // create a list box for notes content
317 const SwPostItMode nPrintPostIts = rDefaultPrintData.GetPrintPostIts();
318 aChoices.realloc( 5 );
319 aChoices[0] = SwResId( STR_PRINTOPTUI_NONE);
320 aChoices[1] = SwResId( STR_PRINTOPTUI_COMMENTS_ONLY);
321 aChoices[2] = SwResId( STR_PRINTOPTUI_PLACE_END);
322 aChoices[3] = SwResId( STR_PRINTOPTUI_PLACE_PAGE);
323 aChoices[4] = SwResId( STR_PRINTOPTUI_PLACE_MARGINS);
324 aHelpIds.realloc( 2 );
325 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintAnnotationMode:FixedText";
326 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintAnnotationMode:ListBox";
327 vcl::PrinterOptionsHelper::UIControlOptions aAnnotOpt( "PrintProspect", 0, false );
328 aAnnotOpt.mbEnabled = bHasPostIts;
329 m_aUIProperties[ nIdx++ ].Value = setChoiceListControlOpt("writercomments",
330 SwResId( STR_PRINTOPTUI_COMMENTS),
331 aHelpIds,
332 "PrintAnnotationMode",
333 aChoices,
334 bHasPostIts ? static_cast<sal_uInt16>(nPrintPostIts) : 0,
335 uno::Sequence< sal_Bool >(),
336 aAnnotOpt);
338 // create subsection for Page settings
339 vcl::PrinterOptionsHelper::UIControlOptions aPageSetOpt;
340 aPageSetOpt.maGroupHint = "LayoutPage";
342 // create a bool option for brochure
343 bDefaultVal = rDefaultPrintData.IsPrintProspect();
344 const OUString aBrochurePropertyName( "PrintProspect" );
345 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("brochure", SwResId( STR_PRINTOPTUI_BROCHURE),
346 ".HelpID:vcl:PrintDialog:PrintProspect:CheckBox",
347 aBrochurePropertyName,
348 bDefaultVal,
349 aPageSetOpt);
351 if (bRTL)
353 // create a bool option for brochure RTL dependent on brochure
354 uno::Sequence< OUString > aBRTLChoices( 2 );
355 aBRTLChoices[0] = SwResId( STR_PRINTOPTUI_LEFT_SCRIPT);
356 aBRTLChoices[1] = SwResId( STR_PRINTOPTUI_RIGHT_SCRIPT);
357 vcl::PrinterOptionsHelper::UIControlOptions aBrochureRTLOpt( aBrochurePropertyName, -1, true );
358 uno::Sequence<OUString> aBRTLHelpIds { ".HelpID:vcl:PrintDialog:PrintProspectRTL:ListBox" };
359 aBrochureRTLOpt.maGroupHint = "LayoutPage";
360 // RTL brochure choices
361 // 0 : left-to-right
362 // 1 : right-to-left
363 const sal_Int16 nBRTLChoice = rDefaultPrintData.IsPrintProspectRTL() ? 1 : 0;
364 m_aUIProperties[ nIdx++ ].Value = setChoiceListControlOpt("scriptdirection",
365 OUString(),
366 aBRTLHelpIds,
367 "PrintProspectRTL",
368 aBRTLChoices,
369 nBRTLChoice,
370 uno::Sequence< sal_Bool >(),
371 aBrochureRTLOpt);
374 assert(nIdx == nNumProps);
377 SwPrintUIOptions::~SwPrintUIOptions()
381 bool SwPrintUIOptions::IsPrintLeftPages() const
383 // take care of different property names for the option.
384 // for compatibility the old name should win (may still be used for PDF export or via Uno API)
386 // 0: left and right pages
387 // 1: left pages only
388 // 2: right pages only
389 sal_Int64 nEOPages = getIntValue( "EvenOdd", 0 /* default: all */ );
390 bool bRes = nEOPages != 1;
391 bRes = getBoolValue( "EvenOdd", bRes /* <- default value if property is not found */ );
392 return bRes;
395 bool SwPrintUIOptions::IsPrintRightPages() const
397 // take care of different property names for the option.
398 // for compatibility the old name should win (may still be used for PDF export or via Uno API)
400 sal_Int64 nEOPages = getIntValue( "EvenOdd", 0 /* default: all */ );
401 bool bRes = nEOPages != 2;
402 bRes = getBoolValue( "EvenOdd", bRes /* <- default value if property is not found */ );
403 return bRes;
406 bool SwPrintUIOptions::IsPrintEmptyPages( bool bIsPDFExport ) const
408 // take care of different property names for the option.
410 bool bRes = bIsPDFExport ?
411 !getBoolValue( "IsSkipEmptyPages", true ) :
412 getBoolValue( "PrintEmptyPages", true );
413 return bRes;
416 bool SwPrintUIOptions::IsPrintGraphics() const
418 // take care of different property names for the option.
419 // for compatibility the old name should win (may still be used for PDF export or via Uno API)
421 bool bRes = getBoolValue( "PrintPicturesAndObjects", true );
422 bRes = getBoolValue( "PrintGraphics", bRes );
423 return bRes;
426 bool SwPrintUIOptions::IsPrintDrawings() const
428 // take care of different property names for the option.
429 // for compatibility the old name should win (may still be used for PDF export or via Uno API)
431 bool bRes = getBoolValue( "PrintPicturesAndObjects", true );
432 bRes = getBoolValue( "PrintDrawings", bRes );
433 return bRes;
436 bool SwPrintUIOptions::processPropertiesAndCheckFormat( const uno::Sequence< beans::PropertyValue >& i_rNewProp )
438 bool bChanged = processProperties( i_rNewProp );
440 uno::Reference< awt::XDevice > xRenderDevice;
441 uno::Any aVal( getValue( "RenderDevice" ) );
442 aVal >>= xRenderDevice;
444 VclPtr< OutputDevice > pOut;
445 if (xRenderDevice.is())
447 VCLXDevice* pDevice = comphelper::getUnoTunnelImplementation<VCLXDevice>( xRenderDevice );
448 if (pDevice)
449 pOut = pDevice->GetOutputDevice();
451 bChanged = bChanged || (pOut.get() != m_pLast.get());
452 if( pOut )
453 m_pLast = pOut;
455 return bChanged;
458 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */