Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / view / printdata.cxx
blob790a6deeb5d5d13442d950213557daef2e96f9f0
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/cjkoptions.hxx>
31 #include <svl/ctloptions.hxx>
32 #include <toolkit/awt/vclxdevice.hxx>
33 #include <unotools/configmgr.hxx>
34 #include <unotools/moduleoptions.hxx>
35 #include <vcl/outdev.hxx>
36 #include <osl/diagnose.h>
38 using namespace ::com::sun::star;
40 SwRenderData::SwRenderData()
44 SwRenderData::~SwRenderData()
46 OSL_ENSURE( !m_pPostItShell, "m_pPostItShell should already have been deleted" );
47 OSL_ENSURE( !m_pPostItFields, " should already have been deleted" );
50 void SwRenderData::CreatePostItData( SwDoc& rDoc, const SwViewOption *pViewOpt, OutputDevice *pOutDev )
52 DeletePostItData();
53 m_pPostItFields.reset(new SetGetExpFields);
54 sw_GetPostIts( rDoc.getIDocumentFieldsAccess(), m_pPostItFields.get() );
56 //!! Disable spell and grammar checking in the temporary document.
57 //!! Otherwise the grammar checker might process it and crash if we later on
58 //!! simply delete this document while he is still at it.
59 SwViewOption aViewOpt( *pViewOpt );
60 aViewOpt.SetOnlineSpell( false );
62 m_pPostItShell.reset(new SwViewShell(*new SwDoc, nullptr, &aViewOpt, pOutDev));
65 void SwRenderData::DeletePostItData()
67 if (HasPostItData())
69 // printer needs to remain at the real document
70 m_pPostItShell->GetDoc()->getIDocumentDeviceAccess().setPrinter( nullptr, false, false );
71 { // avoid destroying layout from SwDoc dtor
72 rtl::Reference<SwDoc> const xKeepAlive(m_pPostItShell->GetDoc());
73 m_pPostItShell.reset();
75 m_pPostItFields.reset();
79 void SwRenderData::SetTempDocShell(SfxObjectShellLock const& xShell)
81 m_xTempDocShell = xShell;
84 bool SwRenderData::NeedNewViewOptionAdjust( const SwViewShell& rCompare ) const
86 return !(m_pViewOptionAdjust && m_pViewOptionAdjust->checkShell( rCompare ));
89 void SwRenderData::ViewOptionAdjustStart(
90 SwViewShell &rSh, const SwViewOption &rViewOptions)
92 if (m_pViewOptionAdjust)
94 OSL_FAIL("error: there should be no ViewOptionAdjust active when calling this function" );
96 m_pViewOptionAdjust.reset(
97 new SwViewOptionAdjust_Impl( rSh, rViewOptions ));
100 void SwRenderData::ViewOptionAdjust(SwPrintData const*const pPrtOptions, bool setShowPlaceHoldersInPDF)
102 m_pViewOptionAdjust->AdjustViewOptions( pPrtOptions, setShowPlaceHoldersInPDF );
105 void SwRenderData::ViewOptionAdjustStop()
107 m_pViewOptionAdjust.reset();
110 void SwRenderData::ViewOptionAdjustCrashPreventionKludge()
112 m_pViewOptionAdjust->DontTouchThatViewShellItSmellsFunny();
115 void SwRenderData::MakeSwPrtOptions(
116 SwDocShell const*const pDocShell,
117 SwPrintUIOptions const*const pOpt,
118 bool const bIsPDFExport)
120 if (!pDocShell || !pOpt)
121 return;
123 m_pPrtOptions.reset(new SwPrintData);
124 SwPrintData & rOptions(*m_pPrtOptions);
126 // get default print options
127 bool bWeb = dynamic_cast<const SwWebDocShell*>( pDocShell) != nullptr;
128 ::sw::InitPrintOptionsFromApplication(rOptions, bWeb);
130 // get print options to use from provided properties
131 rOptions.m_bPrintGraphic = pOpt->IsPrintGraphics();
132 rOptions.m_bPrintTable = true; // for now it was decided that tables should always be printed
133 rOptions.m_bPrintDraw = pOpt->IsPrintDrawings();
134 rOptions.m_bPrintControl = pOpt->IsPrintFormControls();
135 rOptions.m_bPrintLeftPages = pOpt->IsPrintLeftPages();
136 rOptions.m_bPrintRightPages = pOpt->IsPrintRightPages();
137 rOptions.m_bPrintPageBackground = pOpt->IsPrintPageBackground();
138 rOptions.m_bPrintEmptyPages = pOpt->IsPrintEmptyPages( bIsPDFExport );
139 // bUpdateFieldsInPrinting <-- not set here; mail merge only
140 rOptions.m_bPaperFromSetup = pOpt->IsPaperFromSetup();
141 rOptions.m_bPrintReverse = false; /*handled by print dialog now*/
142 rOptions.m_bPrintProspect = pOpt->IsPrintProspect();
143 rOptions.m_bPrintProspectRTL = pOpt->IsPrintProspectRTL();
144 // bPrintSingleJobs <-- not set here; mail merge and or configuration
145 // bModified <-- not set here; mail merge only
146 rOptions.m_bPrintBlackFont = pOpt->IsPrintWithBlackTextColor();
147 rOptions.m_bPrintHiddenText = pOpt->IsPrintHiddenText();
148 rOptions.m_bPrintTextPlaceholder = pOpt->IsPrintTextPlaceholders();
149 rOptions.m_nPrintPostIts = pOpt->GetPrintPostItsType();
151 //! needs to be set after MakeOptions since the assignment operation in that
152 //! function will destroy the pointers
153 rOptions.SetRenderData( this );
156 SwPrintUIOptions::SwPrintUIOptions(
157 sal_uInt16 nCurrentPage,
158 bool bWeb,
159 bool bSwSrcView,
160 bool bHasSelection,
161 bool bHasPostIts,
162 const SwPrintData &rDefaultPrintData ) :
163 m_rDefaultPrintData( rDefaultPrintData )
165 // printing HTML sources does not have any valid UI options.
166 // It's just the source code that gets printed...
167 if (bSwSrcView || utl::ConfigManager::IsFuzzing())
169 m_aUIProperties.clear();
170 return;
173 // check if either CJK or CTL is enabled
174 bool bRTL = SvtCJKOptions::IsCJKFontEnabled() || SvtCTLOptions::IsCTLFontEnabled();
176 // create sequence of print UI options
177 // (5 options are not available for Writer-Web)
178 const int nRTLOpts = bRTL ? 1 : 0;
179 const int nNumProps = nRTLOpts + (bWeb ? 15 : 19);
180 m_aUIProperties.resize( nNumProps);
181 int nIdx = 0;
183 // load the writer PrinterOptions into the custom tab
184 m_aUIProperties[nIdx].Name = "OptionsUIFile";
185 m_aUIProperties[nIdx++].Value <<= OUString("modules/swriter/ui/printeroptions.ui");
187 // create "writer" section (new tab page in dialog)
188 SvtModuleOptions aModOpt;
189 OUString aAppGroupname( SwResId( STR_PRINTOPTUI_PRODUCTNAME) );
190 aAppGroupname = aAppGroupname.replaceFirst( "%s", aModOpt.GetModuleName( SvtModuleOptions::EModule::WRITER ) );
191 m_aUIProperties[ nIdx++ ].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, ".HelpID:vcl:PrintDialog:TabPage:AppPage");
193 // create sub section for Contents
194 m_aUIProperties[ nIdx++ ].Value = setSubgroupControlOpt("contents", SwResId( STR_PRINTOPTUI_CONTENTS), OUString());
196 // create a bool option for background
197 bool bDefaultVal = rDefaultPrintData.IsPrintPageBackground();
198 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("pagebackground", SwResId( STR_PRINTOPTUI_PAGE_BACKGROUND),
199 ".HelpID:vcl:PrintDialog:PrintPageBackground:CheckBox",
200 "PrintPageBackground",
201 bDefaultVal);
203 // create a bool option for pictures/graphics AND OLE and drawing objects as well
204 bDefaultVal = rDefaultPrintData.IsPrintGraphic() || rDefaultPrintData.IsPrintDraw();
205 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("pictures", SwResId( STR_PRINTOPTUI_PICTURES),
206 ".HelpID:vcl:PrintDialog:PrintPicturesAndObjects:CheckBox",
207 "PrintPicturesAndObjects",
208 bDefaultVal);
209 if (!bWeb)
211 // create a bool option for hidden text
212 bDefaultVal = rDefaultPrintData.IsPrintHiddenText();
213 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("hiddentext", SwResId( STR_PRINTOPTUI_HIDDEN),
214 ".HelpID:vcl:PrintDialog:PrintHiddenText:CheckBox",
215 "PrintHiddenText",
216 bDefaultVal);
218 // create a bool option for place holder
219 bDefaultVal = rDefaultPrintData.IsPrintTextPlaceholder();
220 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("placeholders", SwResId( STR_PRINTOPTUI_TEXT_PLACEHOLDERS),
221 ".HelpID:vcl:PrintDialog:PrintTextPlaceholder:CheckBox",
222 "PrintTextPlaceholder",
223 bDefaultVal);
226 // create a bool option for controls
227 bDefaultVal = rDefaultPrintData.IsPrintControl();
228 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("formcontrols", SwResId( STR_PRINTOPTUI_FORM_CONTROLS),
229 ".HelpID:vcl:PrintDialog:PrintControls:CheckBox",
230 "PrintControls",
231 bDefaultVal);
233 // create sub section for Color
234 m_aUIProperties[ nIdx++ ].Value = setSubgroupControlOpt("color", SwResId( STR_PRINTOPTUI_COLOR), OUString());
236 // create a bool option for printing text with black font color
237 bDefaultVal = rDefaultPrintData.IsPrintBlackFont();
238 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("textinblack", SwResId( STR_PRINTOPTUI_PRINT_BLACK),
239 ".HelpID:vcl:PrintDialog:PrintBlackFonts:CheckBox",
240 "PrintBlackFonts",
241 bDefaultVal);
243 if (!bWeb)
245 // create subgroup for misc options
246 m_aUIProperties[ nIdx++ ].Value = setSubgroupControlOpt("pages", SwResId( STR_PRINTOPTUI_PAGES_TEXT), OUString());
248 // create a bool option for printing automatically inserted blank pages
249 bDefaultVal = rDefaultPrintData.IsPrintEmptyPages();
250 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("autoblankpages", SwResId( STR_PRINTOPTUI_PRINT_BLANK),
251 ".HelpID:vcl:PrintDialog:PrintEmptyPages:CheckBox",
252 "PrintEmptyPages",
253 bDefaultVal);
256 // create a bool option for paper tray
257 bDefaultVal = rDefaultPrintData.IsPaperFromSetup();
258 vcl::PrinterOptionsHelper::UIControlOptions aPaperTrayOpt;
259 aPaperTrayOpt.maGroupHint = "OptionsPageOptGroup";
260 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("printpaperfromsetup", SwResId( STR_PRINTOPTUI_ONLY_PAPER),
261 ".HelpID:vcl:PrintDialog:PrintPaperFromSetup:CheckBox",
262 "PrintPaperFromSetup",
263 bDefaultVal,
264 aPaperTrayOpt);
266 // print range selection
267 vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
268 aPrintRangeOpt.maGroupHint = "PrintRange";
269 aPrintRangeOpt.mbInternalOnly = true;
270 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt( "printrange",
271 SwResId( STR_PRINTOPTUI_PAGES_TEXT ),
272 OUString(),
273 aPrintRangeOpt );
275 // create a choice for the content to create
276 static const OUStringLiteral aPrintRangeName( u"PrintContent" );
277 uno::Sequence< OUString > aChoices{ SwResId( STR_PRINTOPTUI_PRINTALLPAGES ),
278 SwResId( STR_PRINTOPTUI_PRINTPAGES ),
279 SwResId( STR_PRINTOPTUI_PRINTSELECTION ) };
280 uno::Sequence< sal_Bool > aChoicesDisabled{ false, false, !bHasSelection };
281 uno::Sequence< OUString > aHelpIds{ ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0",
282 ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1",
283 ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:2" };
284 uno::Sequence< OUString > aWidgetIds{ "rbAllPages", "rbRangePages", "rbRangeSelection" };
285 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
286 aHelpIds, aPrintRangeName,
287 aChoices, 0 /* always default to 'All pages' */,
288 aChoicesDisabled);
290 // show an Edit dependent on "Pages" selected
291 vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt( aPrintRangeName, 1, true );
292 m_aUIProperties[nIdx++].Value = setEditControlOpt("pagerange", OUString(),
293 ".HelpID:vcl:PrintDialog:PageRange:Edit",
294 "PageRange",
295 OUString::number( nCurrentPage ) /* set text box to current page number */,
296 aPageRangeOpt);
298 vcl::PrinterOptionsHelper::UIControlOptions aEvenOddOpt(aPrintRangeName, -1, true);
299 m_aUIProperties[ nIdx++ ].Value = setChoiceListControlOpt("evenoddbox",
300 OUString(),
301 uno::Sequence<OUString>(),
302 "EvenOdd",
303 uno::Sequence<OUString>(),
305 uno::Sequence< sal_Bool >(),
306 aEvenOddOpt);
308 // create a list box for notes content
309 const SwPostItMode nPrintPostIts = rDefaultPrintData.GetPrintPostIts();
310 aChoices = { SwResId( STR_PRINTOPTUI_NONE),
311 SwResId( STR_PRINTOPTUI_COMMENTS_ONLY),
312 SwResId( STR_PRINTOPTUI_PLACE_END),
313 SwResId( STR_PRINTOPTUI_PLACE_PAGE),
314 SwResId( STR_PRINTOPTUI_PLACE_MARGINS) };
315 aHelpIds = { ".HelpID:vcl:PrintDialog:PrintAnnotationMode:FixedText",
316 ".HelpID:vcl:PrintDialog:PrintAnnotationMode:ListBox" };
317 vcl::PrinterOptionsHelper::UIControlOptions aAnnotOpt( "PrintProspect", 0, false );
318 aAnnotOpt.mbEnabled = bHasPostIts;
319 m_aUIProperties[ nIdx++ ].Value = setChoiceListControlOpt("writercomments",
320 SwResId( STR_PRINTOPTUI_COMMENTS),
321 aHelpIds,
322 "PrintAnnotationMode",
323 aChoices,
324 bHasPostIts ? static_cast<sal_uInt16>(nPrintPostIts) : 0,
325 uno::Sequence< sal_Bool >(),
326 aAnnotOpt);
328 // create subsection for Page settings
329 vcl::PrinterOptionsHelper::UIControlOptions aPageSetOpt;
330 aPageSetOpt.maGroupHint = "LayoutPage";
332 // create a bool option for brochure
333 bDefaultVal = rDefaultPrintData.IsPrintProspect();
334 static const OUStringLiteral aBrochurePropertyName( u"PrintProspect" );
335 m_aUIProperties[ nIdx++ ].Value = setBoolControlOpt("brochure", SwResId( STR_PRINTOPTUI_BROCHURE),
336 ".HelpID:vcl:PrintDialog:PrintProspect:CheckBox",
337 aBrochurePropertyName,
338 bDefaultVal,
339 aPageSetOpt);
341 if (bRTL)
343 // create a bool option for brochure RTL dependent on brochure
344 uno::Sequence< OUString > aBRTLChoices{ SwResId( STR_PRINTOPTUI_LEFT_SCRIPT),
345 SwResId( STR_PRINTOPTUI_RIGHT_SCRIPT) };
346 vcl::PrinterOptionsHelper::UIControlOptions aBrochureRTLOpt( aBrochurePropertyName, -1, true );
347 uno::Sequence<OUString> aBRTLHelpIds { ".HelpID:vcl:PrintDialog:PrintProspectRTL:ListBox" };
348 aBrochureRTLOpt.maGroupHint = "LayoutPage";
349 // RTL brochure choices
350 // 0 : left-to-right
351 // 1 : right-to-left
352 const sal_Int16 nBRTLChoice = rDefaultPrintData.IsPrintProspectRTL() ? 1 : 0;
353 m_aUIProperties[ nIdx++ ].Value = setChoiceListControlOpt("scriptdirection",
354 OUString(),
355 aBRTLHelpIds,
356 "PrintProspectRTL",
357 aBRTLChoices,
358 nBRTLChoice,
359 uno::Sequence< sal_Bool >(),
360 aBrochureRTLOpt);
363 assert(nIdx == nNumProps);
366 SwPrintUIOptions::~SwPrintUIOptions()
370 bool SwPrintUIOptions::IsPrintLeftPages() const
372 // take care of different property names for the option.
373 // for compatibility the old name should win (may still be used for PDF export or via Uno API)
375 // 0: left and right pages
376 // 1: left pages only
377 // 2: right pages only
378 sal_Int64 nEOPages = getIntValue( "EvenOdd", 0 /* default: all */ );
379 bool bRes = nEOPages != 1;
380 bRes = getBoolValue( "EvenOdd", bRes /* <- default value if property is not found */ );
381 return bRes;
384 bool SwPrintUIOptions::IsPrintRightPages() const
386 // take care of different property names for the option.
387 // for compatibility the old name should win (may still be used for PDF export or via Uno API)
389 sal_Int64 nEOPages = getIntValue( "EvenOdd", 0 /* default: all */ );
390 bool bRes = nEOPages != 2;
391 bRes = getBoolValue( "EvenOdd", bRes /* <- default value if property is not found */ );
392 return bRes;
395 bool SwPrintUIOptions::IsPrintEmptyPages( bool bIsPDFExport ) const
397 // take care of different property names for the option.
399 bool bRes = bIsPDFExport ?
400 !getBoolValue( "IsSkipEmptyPages", true ) :
401 getBoolValue( "PrintEmptyPages", true );
402 return bRes;
405 bool SwPrintUIOptions::IsPrintGraphics() const
407 // take care of different property names for the option.
408 // for compatibility the old name should win (may still be used for PDF export or via Uno API)
410 bool bRes = getBoolValue( "PrintPicturesAndObjects", true );
411 bRes = getBoolValue( "PrintGraphics", bRes );
412 return bRes;
415 bool SwPrintUIOptions::IsPrintDrawings() const
417 // take care of different property names for the option.
418 // for compatibility the old name should win (may still be used for PDF export or via Uno API)
420 bool bRes = getBoolValue( "PrintPicturesAndObjects", true );
421 bRes = getBoolValue( "PrintDrawings", bRes );
422 return bRes;
425 bool SwPrintUIOptions::processPropertiesAndCheckFormat( const uno::Sequence< beans::PropertyValue >& i_rNewProp )
427 bool bChanged = processProperties( i_rNewProp );
429 uno::Reference< awt::XDevice > xRenderDevice;
430 uno::Any aVal( getValue( "RenderDevice" ) );
431 aVal >>= xRenderDevice;
433 VclPtr< OutputDevice > pOut;
434 if (xRenderDevice.is())
436 VCLXDevice* pDevice = dynamic_cast<VCLXDevice*>( xRenderDevice.get() );
437 if (pDevice)
438 pOut = pDevice->GetOutputDevice();
440 bChanged = bChanged || (pOut.get() != m_pLast.get());
441 if( pOut )
442 m_pLast = pOut;
444 return bChanged;
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */