Bug Summary

File:home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx
Warning:line 1064, column 27
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name printdlg.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/glm -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/libmount -isystem /usr/include/blkid -isystem /usr/include/cairo -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/pixman-1 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/libxml2 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/dbus-1.0 -isystem /usr/lib64/dbus-1.0/include -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D VCL_DLLIMPLEMENTATION -D DLLIMPLEMENTATION_UITEST -D CUI_DLL_NAME="libcuilo.so" -D DESKTOP_DETECTOR_DLL_NAME="libdesktop_detectorlo.so" -D TK_DLL_NAME="libtklo.so" -D SYSTEM_ZLIB -D GLM_FORCE_CTOR_INIT -D SK_USER_CONFIG_HEADER=</home/maarten/src/libreoffice/core/config_host/config_skia.h> -D SKIA_DLL -D ENABLE_CUPS -D HAVE_VALGRIND_HEADERS -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/epoxy/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/core -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/effects -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/gpu -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/config -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/ports -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/third_party/vulkan -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/tools/gpu -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia -I /home/maarten/src/libreoffice/core/external/skia/inc/ -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/mdds/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/lcms2/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/harfbuzz/src -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/graphite/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/pdfium -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/pdfium/public -D COMPONENT_BUILD -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/libpng -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/libjpeg-turbo -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/vcl/inc -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libxml2 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx
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 <printdlg.hxx>
21#include <svdata.hxx>
22#include <strings.hrc>
23#include <bitmaps.hlst>
24
25#include <vcl/QueueInfo.hxx>
26#include <vcl/commandevent.hxx>
27#include <vcl/naturalsort.hxx>
28#include <vcl/print.hxx>
29#include <vcl/wall.hxx>
30#include <vcl/decoview.hxx>
31#include <configsettings.hxx>
32#include <vcl/help.hxx>
33#include <vcl/svapp.hxx>
34#include <vcl/settings.hxx>
35#include <vcl/virdev.hxx>
36
37#include <unotools/localedatawrapper.hxx>
38
39#include <sal/log.hxx>
40#include <osl/diagnose.h>
41#include <rtl/ustrbuf.hxx>
42
43#include <com/sun/star/beans/PropertyValue.hpp>
44
45using namespace vcl;
46using namespace com::sun::star;
47using namespace com::sun::star::uno;
48using namespace com::sun::star::lang;
49using namespace com::sun::star::container;
50using namespace com::sun::star::beans;
51
52enum
53{
54 ORIENTATION_AUTOMATIC,
55 ORIENTATION_PORTRAIT,
56 ORIENTATION_LANDSCAPE
57};
58
59namespace {
60 bool lcl_ListBoxCompare( const OUString& rStr1, const OUString& rStr2 )
61 {
62 return vcl::NaturalSortCompare( rStr1, rStr2 ) < 0;
63 }
64}
65
66MoreOptionsDialog::MoreOptionsDialog(PrintDialog* i_pParent)
67 : GenericDialogController(i_pParent->getDialog(), "vcl/ui/moreoptionsdialog.ui", "MoreOptionsDialog")
68 , mpParent( i_pParent )
69 , mxOKButton(m_xBuilder->weld_button("ok"))
70 , mxCancelButton(m_xBuilder->weld_button("cancel"))
71 , mxSingleJobsBox(m_xBuilder->weld_check_button("singlejobs"))
72{
73 mxSingleJobsBox->set_active( mpParent->isSingleJobs() );
74
75 mxOKButton->connect_clicked( LINK( this, MoreOptionsDialog, ClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<MoreOptionsDialog
*>(this), &MoreOptionsDialog::LinkStubClickHdl)
);
76 mxCancelButton->connect_clicked( LINK( this, MoreOptionsDialog, ClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<MoreOptionsDialog
*>(this), &MoreOptionsDialog::LinkStubClickHdl)
);
77}
78
79MoreOptionsDialog::~MoreOptionsDialog()
80{
81}
82
83IMPL_LINK (MoreOptionsDialog, ClickHdl, weld::Button&, rButton, void)void MoreOptionsDialog::LinkStubClickHdl(void * instance, weld
::Button& data) { return static_cast<MoreOptionsDialog
*>(instance)->ClickHdl(data); } void MoreOptionsDialog
::ClickHdl(weld::Button& rButton)
84{
85 if (&rButton == mxOKButton.get())
86 {
87 mpParent->mbSingleJobs = mxSingleJobsBox->get_active();
88 m_xDialog->response(RET_OK);
89 }
90 else if (&rButton == mxCancelButton.get())
91 {
92 m_xDialog->response(RET_CANCEL);
93 }
94}
95
96PrintDialog::PrintPreviewWindow::PrintPreviewWindow(PrintDialog* pDialog)
97 : mpDialog(pDialog)
98 , maMtf()
99 , maOrigSize( 10, 10 )
100 , maPreviewSize()
101 , mnDPIX(Application::GetDefaultDevice()->GetDPIX())
102 , mnDPIY(Application::GetDefaultDevice()->GetDPIY())
103 , maPreviewBitmap()
104 , maReplacementString()
105 , mbGreyscale( false )
106{
107}
108
109PrintDialog::PrintPreviewWindow::~PrintPreviewWindow()
110{
111}
112
113void PrintDialog::PrintPreviewWindow::Resize()
114{
115 Size aNewSize(GetOutputSizePixel());
116 long nTextHeight = GetDrawingArea()->get_text_height();
117 // leave small space for decoration
118 aNewSize.AdjustWidth( -(nTextHeight + 2) );
119 aNewSize.AdjustHeight( -(nTextHeight + 2) );
120 Size aScaledSize;
121 double fScale = 1.0;
122
123 // #i106435# catch corner case of Size(0,0)
124 Size aOrigSize( maOrigSize );
125 if( aOrigSize.Width() < 1 )
126 aOrigSize.setWidth( aNewSize.Width() );
127 if( aOrigSize.Height() < 1 )
128 aOrigSize.setHeight( aNewSize.Height() );
129 if( aOrigSize.Width() > aOrigSize.Height() )
130 {
131 aScaledSize = Size( aNewSize.Width(), aNewSize.Width() * aOrigSize.Height() / aOrigSize.Width() );
132 if( aScaledSize.Height() > aNewSize.Height() )
133 fScale = double(aNewSize.Height())/double(aScaledSize.Height());
134 }
135 else
136 {
137 aScaledSize = Size( aNewSize.Height() * aOrigSize.Width() / aOrigSize.Height(), aNewSize.Height() );
138 if( aScaledSize.Width() > aNewSize.Width() )
139 fScale = double(aNewSize.Width())/double(aScaledSize.Width());
140 }
141 aScaledSize.setWidth( long(aScaledSize.Width()*fScale) );
142 aScaledSize.setHeight( long(aScaledSize.Height()*fScale) );
143
144 maPreviewSize = aScaledSize;
145
146 // check and evtl. recreate preview bitmap
147 preparePreviewBitmap();
148}
149
150void PrintDialog::PrintPreviewWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
151{
152 pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 45,
153 pDrawingArea->get_text_height() * 30);
154 CustomWidgetController::SetDrawingArea(pDrawingArea);
155}
156
157void PrintDialog::PrintPreviewWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
158{
159 rRenderContext.Push();
160 if (vcl::Window* pDefaultDevice = dynamic_cast<vcl::Window*>(Application::GetDefaultDevice()))
161 {
162 Font aFont(rRenderContext.GetSettings().GetStyleSettings().GetLabelFont());
163 pDefaultDevice->SetPointFont(rRenderContext, aFont);
164 }
165
166 rRenderContext.SetBackground(Wallpaper(Application::GetSettings().GetStyleSettings().GetDialogColor()));
167 rRenderContext.Erase();
168
169 auto nTextHeight = rRenderContext.GetTextHeight();
170 Size aSize(GetOutputSizePixel());
171 Point aOffset((aSize.Width() - maPreviewSize.Width() + nTextHeight) / 2,
172 (aSize.Height() - maPreviewSize.Height() + nTextHeight) / 2);
173
174 // horizontal line
175 {
176 auto nWidth = rRenderContext.GetTextWidth(maHorzText);
177
178 auto nStart = aOffset.X() + (maPreviewSize.Width() - nWidth) / 2;
179 rRenderContext.DrawText(Point(nStart, aOffset.Y() - nTextHeight), maHorzText, 0, maHorzText.getLength());
180
181 DecorationView aDecoView(&rRenderContext);
182 auto nTop = aOffset.Y() - (nTextHeight / 2);
183 aDecoView.DrawSeparator(Point(aOffset.X(), nTop), Point(nStart - 2, nTop), false);
184 aDecoView.DrawSeparator(Point(nStart + nWidth + 2, nTop), Point(aOffset.X() + maPreviewSize.Width(), nTop), false);
185 }
186
187 // vertical line
188 {
189 rRenderContext.Push(PushFlags::FONT);
190 vcl::Font aFont(rRenderContext.GetFont());
191 aFont.SetOrientation(900);
192 rRenderContext.SetFont(aFont);
193
194 auto nLeft = aOffset.X() - nTextHeight;
195
196 auto nWidth = rRenderContext.GetTextWidth(maVertText);
197 auto nStart = aOffset.Y() + (maPreviewSize.Height() + nWidth) / 2;
198
199 rRenderContext.DrawText(Point(nLeft, nStart), maVertText, 0, maVertText.getLength());
200
201 DecorationView aDecoView(&rRenderContext);
202 nLeft = aOffset.X() - (nTextHeight / 2);
203 aDecoView.DrawSeparator(Point(nLeft, aOffset.Y()), Point(nLeft, nStart - nWidth - 2), true);
204 aDecoView.DrawSeparator(Point(nLeft, nStart + 2), Point(nLeft, aOffset.Y() + maPreviewSize.Height()), true);
205
206 rRenderContext.Pop();
207 }
208
209 if (!maReplacementString.isEmpty())
210 {
211 // replacement is active
212 tools::Rectangle aTextRect(aOffset + Point(2, 2), Size(maPreviewSize.Width() - 4, maPreviewSize.Height() - 4));
213 rRenderContext.DrawText(aTextRect, maReplacementString,
214 DrawTextFlags::Center | DrawTextFlags::VCenter |
215 DrawTextFlags::WordBreak | DrawTextFlags::MultiLine);
216 }
217 else
218 {
219 BitmapEx aPreviewBitmap(maPreviewBitmap);
220
221 // This explicit force-to-scale allows us to get the
222 // mentioned best quality here. Unfortunately this is
223 // currently not sure when using just ::DrawBitmap with
224 // a defined size or ::DrawOutDev
225 aPreviewBitmap.Scale(maPreviewSize, BmpScaleFlag::BestQuality);
226 rRenderContext.DrawBitmapEx(aOffset, aPreviewBitmap);
227 }
228
229 tools::Rectangle aFrameRect(aOffset + Point(-1, -1), Size(maPreviewSize.Width() + 2, maPreviewSize.Height() + 2));
230 DecorationView aDecorationView(&rRenderContext);
231 aDecorationView.DrawFrame(aFrameRect, DrawFrameStyle::Group);
232
233 rRenderContext.Pop();
234}
235
236bool PrintDialog::PrintPreviewWindow::Command( const CommandEvent& rEvt )
237{
238 if( rEvt.GetCommand() == CommandEventId::Wheel )
239 {
240 const CommandWheelData* pWheelData = rEvt.GetWheelData();
241 if(pWheelData->GetDelta() > 0)
242 mpDialog->previewForward();
243 else if (pWheelData->GetDelta() < 0)
244 mpDialog->previewBackward();
245 return true;
246 }
247 return CustomWidgetController::Command(rEvt);
248}
249
250void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPreview,
251 const Size& i_rOrigSize,
252 const OUString& i_rPaperName,
253 const OUString& i_rReplacement,
254 sal_Int32 i_nDPIX,
255 sal_Int32 i_nDPIY,
256 bool i_bGreyscale
257 )
258{
259 maMtf = i_rNewPreview;
260 mnDPIX = i_nDPIX;
261 mnDPIY = i_nDPIY;
262 maOrigSize = i_rOrigSize;
263 maReplacementString = i_rReplacement;
264 mbGreyscale = i_bGreyscale;
265
266 // use correct measurements
267 const LocaleDataWrapper& rLocWrap(Application::GetSettings().GetLocaleDataWrapper());
268 MapUnit eUnit = MapUnit::MapMM;
269 int nDigits = 0;
270 if( rLocWrap.getMeasurementSystemEnum() == MeasurementSystem::US )
271 {
272 eUnit = MapUnit::Map100thInch;
273 nDigits = 2;
274 }
275 Size aLogicPaperSize(OutputDevice::LogicToLogic(i_rOrigSize, MapMode(MapUnit::Map100thMM), MapMode(eUnit)));
276 OUString aNumText( rLocWrap.getNum( aLogicPaperSize.Width(), nDigits ) );
277 OUStringBuffer aBuf;
278 aBuf.append( aNumText )
279 .append( u' ' );
280 aBuf.appendAscii( eUnit == MapUnit::MapMM ? "mm" : "in" );
281 if( !i_rPaperName.isEmpty() )
282 {
283 aBuf.append( " (" );
284 aBuf.append( i_rPaperName );
285 aBuf.append( ')' );
286 }
287 maHorzText = aBuf.makeStringAndClear();
288
289 aNumText = rLocWrap.getNum( aLogicPaperSize.Height(), nDigits );
290 aBuf.append( aNumText )
291 .append( u' ' );
292 aBuf.appendAscii( eUnit == MapUnit::MapMM ? "mm" : "in" );
293 maVertText = aBuf.makeStringAndClear();
294
295 // We have a new Metafile and evtl. a new page, so we need to reset
296 // the PreviewBitmap to force new creation
297 maPreviewBitmap = Bitmap();
298
299 // sets/calculates e.g. maPreviewSize
300 // also triggers preparePreviewBitmap()
301 Resize();
302
303 Invalidate();
304}
305
306void PrintDialog::PrintPreviewWindow::preparePreviewBitmap()
307{
308 if(maPreviewSize.IsEmpty())
309 {
310 // not yet fully initialized, no need to prepare anything
311 return;
312 }
313
314 // define an allowed number of pixels, also see
315 // defaults for primitive renderers and similar. This
316 // might be centralized and made dependent of 32/64bit
317 const sal_uInt32 nMaxSquarePixels(500000);
318
319 // check how big (squarePixels) the preview is currently (with
320 // max value of MaxSquarePixels)
321 const sal_uInt32 nCurrentSquarePixels(
322 std::min(
323 nMaxSquarePixels,
324 static_cast<sal_uInt32>(maPreviewBitmap.GetSizePixel().getWidth())
325 * static_cast<sal_uInt32>(maPreviewBitmap.GetSizePixel().getHeight())));
326
327 // check how big (squarePixels) the preview needs to be (with
328 // max value of MaxSquarePixels)
329 const sal_uInt32 nRequiredSquarePixels(
330 std::min(
331 nMaxSquarePixels,
332 static_cast<sal_uInt32>(maPreviewSize.getWidth())
333 * static_cast<sal_uInt32>(maPreviewSize.getHeight())));
334
335 // check if preview is big enough. Use a scaling value in
336 // the comparison to not get bigger at the last possible moment
337 // what may look awkward and pixelated (again). This means
338 // to use a percentage value - if we have at least
339 // that value of required pixels, we are good.
340 static const double fPreventAwkwardFactor(1.35); // 35%
341 if(nCurrentSquarePixels >= static_cast<sal_uInt32>(nRequiredSquarePixels * fPreventAwkwardFactor))
342 {
343 // at this place we also could add a mechanism to let the preview
344 // bitmap 'shrink' again if it is currently 'too big' -> bigger
345 // than required. I think this is not necessary for now.
346
347 // already sufficient, done.
348 return;
349 }
350
351 // check if we have enough square pixels e.g for 8x8 pixels
352 if(nRequiredSquarePixels < 64)
353 {
354 // too small preview - let it empty
355 return;
356 }
357
358 // Calculate nPlannedSquarePixels which is the required size
359 // expanded by a percentage (with max value of MaxSquarePixels)
360 static const double fExtraSpaceFactor(1.65); // 65%
361 const sal_uInt32 nPlannedSquarePixels(
362 std::min(
363 nMaxSquarePixels,
364 static_cast<sal_uInt32>(maPreviewSize.getWidth() * fExtraSpaceFactor)
365 * static_cast<sal_uInt32>(maPreviewSize.getHeight() * fExtraSpaceFactor)));
366
367 // calculate back new width and height - it might have been
368 // truncated by MaxSquarePixels.
369 // We know that w*h == nPlannedSquarePixels and w/h == ratio
370 const double fRatio(static_cast<double>(maPreviewSize.getWidth()) / static_cast<double>(maPreviewSize.getHeight()));
371 const double fNewWidth(sqrt(static_cast<double>(nPlannedSquarePixels) * fRatio));
372 const double fNewHeight(sqrt(static_cast<double>(nPlannedSquarePixels) / fRatio));
373 const Size aScaledSize(basegfx::fround(fNewWidth), basegfx::fround(fNewHeight));
374
375 // check if this eventual maximum is already reached
376 // due to having hit the MaxSquarePixels. Due to using
377 // an integer AspectRatio, we cannot make a numeric exact
378 // comparison - we need to compare if we are close
379 const double fScaledSizeSquare(static_cast<double>(aScaledSize.getWidth() * aScaledSize.getHeight()));
380 const double fPreviewSizeSquare(static_cast<double>(maPreviewBitmap.GetSizePixel().getWidth() * maPreviewBitmap.GetSizePixel().getHeight()));
381
382 // test as equal up to 0.1% (0.001)
383 if(fPreviewSizeSquare != 0.0 && fabs((fScaledSizeSquare / fPreviewSizeSquare) - 1.0) < 0.001)
384 {
385 // maximum is reached, avoid bigger scaling
386 return;
387 }
388
389 // create temporary VDev and render to it
390 ScopedVclPtrInstance<VirtualDevice> pPrerenderVDev(*Application::GetDefaultDevice());
391 pPrerenderVDev->SetOutputSizePixel(aScaledSize, false);
392 pPrerenderVDev->SetReferenceDevice( mnDPIX, mnDPIY );
393 pPrerenderVDev->EnableOutput();
394 pPrerenderVDev->SetBackground( Wallpaper(COL_WHITE) );
395
396 GDIMetaFile aMtf( maMtf );
397
398 Size aVDevSize( pPrerenderVDev->GetOutputSizePixel() );
399 const Size aLogicSize( pPrerenderVDev->PixelToLogic( aVDevSize, MapMode( MapUnit::Map100thMM ) ) );
400 Size aOrigSize( maOrigSize );
401 if( aOrigSize.Width() < 1 )
402 aOrigSize.setWidth( aLogicSize.Width() );
403 if( aOrigSize.Height() < 1 )
404 aOrigSize.setHeight( aLogicSize.Height() );
405 double fScale = double(aLogicSize.Width())/double(aOrigSize.Width());
406
407 pPrerenderVDev->Erase();
408 pPrerenderVDev->Push();
409 pPrerenderVDev->SetMapMode(MapMode(MapUnit::Map100thMM));
410 DrawModeFlags nOldDrawMode = pPrerenderVDev->GetDrawMode();
411 if( mbGreyscale )
412 pPrerenderVDev->SetDrawMode( pPrerenderVDev->GetDrawMode() |
413 ( DrawModeFlags::GrayLine | DrawModeFlags::GrayFill | DrawModeFlags::GrayText |
414 DrawModeFlags::GrayBitmap | DrawModeFlags::GrayGradient ) );
415 aMtf.WindStart();
416 aMtf.Scale( fScale, fScale );
417 aMtf.WindStart();
418
419 const AntialiasingFlags nOriginalAA(pPrerenderVDev->GetAntialiasing());
420 pPrerenderVDev->SetAntialiasing(nOriginalAA | AntialiasingFlags::Enable);
421 aMtf.Play( pPrerenderVDev.get(), Point( 0, 0 ), aLogicSize );
422 pPrerenderVDev->SetAntialiasing(nOriginalAA);
423
424 pPrerenderVDev->Pop();
425
426 pPrerenderVDev->SetMapMode(MapMode(MapUnit::MapPixel));
427
428 maPreviewBitmap = pPrerenderVDev->GetBitmapEx(Point(0, 0), aVDevSize);
429
430 pPrerenderVDev->SetDrawMode( nOldDrawMode );
431}
432
433PrintDialog::ShowNupOrderWindow::ShowNupOrderWindow()
434 : mnOrderMode( NupOrderType::LRTB )
435 , mnRows( 1 )
436 , mnColumns( 1 )
437{
438}
439
440void PrintDialog::ShowNupOrderWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
441{
442 Size aSize(70, 70);
443 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
444 CustomWidgetController::SetDrawingArea(pDrawingArea);
445 SetOutputSizePixel(aSize);
446}
447
448void PrintDialog::ShowNupOrderWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*i_rRect*/)
449{
450 rRenderContext.SetMapMode(MapMode(MapUnit::MapPixel));
451 rRenderContext.SetTextColor(rRenderContext.GetSettings().GetStyleSettings().GetFieldTextColor());
452 rRenderContext.SetBackground(Wallpaper(Application::GetSettings().GetStyleSettings().GetFieldColor()));
453 rRenderContext.Erase();
454
455 int nPages = mnRows * mnColumns;
456 Font aFont(rRenderContext.GetSettings().GetStyleSettings().GetFieldFont());
457 aFont.SetFontSize(Size(0, 24));
458 rRenderContext.SetFont(aFont);
459 Size aSampleTextSize(rRenderContext.GetTextWidth(OUString::number(nPages + 1)), rRenderContext.GetTextHeight());
460 Size aOutSize(GetOutputSizePixel());
461 Size aSubSize(aOutSize.Width() / mnColumns, aOutSize.Height() / mnRows);
462 // calculate font size: shrink the sample text so it fits
463 double fX = double(aSubSize.Width()) / double(aSampleTextSize.Width());
464 double fY = double(aSubSize.Height()) / double(aSampleTextSize.Height());
465 double fScale = (fX < fY) ? fX : fY;
466 long nFontHeight = long(24.0 * fScale) - 3;
467 if (nFontHeight < 5)
468 nFontHeight = 5;
469 aFont.SetFontSize(Size( 0, nFontHeight));
470 rRenderContext.SetFont(aFont);
471 long nTextHeight = rRenderContext.GetTextHeight();
472 for (int i = 0; i < nPages; i++)
473 {
474 OUString aPageText(OUString::number(i + 1));
475 int nX = 0, nY = 0;
476 switch (mnOrderMode)
477 {
478 case NupOrderType::LRTB:
479 nX = (i % mnColumns);
480 nY = (i / mnColumns);
481 break;
482 case NupOrderType::TBLR:
483 nX = (i / mnRows);
484 nY = (i % mnRows);
485 break;
486 case NupOrderType::RLTB:
487 nX = mnColumns - 1 - (i % mnColumns);
488 nY = (i / mnColumns);
489 break;
490 case NupOrderType::TBRL:
491 nX = mnColumns - 1 - (i / mnRows);
492 nY = (i % mnRows);
493 break;
494 }
495 Size aTextSize(rRenderContext.GetTextWidth(aPageText), nTextHeight);
496 int nDeltaX = (aSubSize.Width() - aTextSize.Width()) / 2;
497 int nDeltaY = (aSubSize.Height() - aTextSize.Height()) / 2;
498 rRenderContext.DrawText(Point(nX * aSubSize.Width() + nDeltaX,
499 nY * aSubSize.Height() + nDeltaY), aPageText);
500 }
501 DecorationView aDecorationView(&rRenderContext);
502 aDecorationView.DrawFrame(tools::Rectangle(Point(0, 0), aOutSize), DrawFrameStyle::Group);
503}
504
505Size const & PrintDialog::getJobPageSize()
506{
507 if( maFirstPageSize.IsEmpty() )
508 {
509 maFirstPageSize = maNupPortraitSize;
510 GDIMetaFile aMtf;
511 if( maPController->getPageCountProtected() > 0 )
512 {
513 PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true );
514 maFirstPageSize = aPageSize.aSize;
515 }
516 }
517 return maFirstPageSize;
518}
519
520PrintDialog::PrintDialog(weld::Window* i_pWindow, const std::shared_ptr<PrinterController>& i_rController)
521 : GenericDialogController(i_pWindow, "vcl/ui/printdialog.ui", "PrintDialog")
522 , maPController( i_rController )
523 , mxTabCtrl(m_xBuilder->weld_notebook("tabcontrol"))
524 , mxPageLayoutFrame(m_xBuilder->weld_frame("layoutframe"))
525 , mxPrinters(m_xBuilder->weld_combo_box("printersbox"))
526 , mxStatusTxt(m_xBuilder->weld_label("status"))
527 , mxSetupButton(m_xBuilder->weld_button("setup"))
528 , mxCopyCountField(m_xBuilder->weld_spin_button("copycount"))
529 , mxCollateBox(m_xBuilder->weld_check_button("collate"))
530 , mxCollateImage(m_xBuilder->weld_image("collateimage"))
531 , mxPageRangeEdit(m_xBuilder->weld_entry("pagerange"))
532 , mxPageRangesRadioButton(m_xBuilder->weld_radio_button("rbRangePages"))
533 , mxPaperSidesBox(m_xBuilder->weld_combo_box("sidesbox"))
534 , mxReverseOrderBox(m_xBuilder->weld_check_button("reverseorder"))
535 , mxOKButton(m_xBuilder->weld_button("ok"))
536 , mxCancelButton(m_xBuilder->weld_button("cancel"))
537 , mxHelpButton(m_xBuilder->weld_button("help"))
538 , mxMoreOptionsBtn(m_xBuilder->weld_button("moreoptionsbtn"))
539 , mxBackwardBtn(m_xBuilder->weld_button("backward"))
540 , mxForwardBtn(m_xBuilder->weld_button("forward"))
541 , mxFirstBtn(m_xBuilder->weld_button("btnFirst"))
542 , mxLastBtn(m_xBuilder->weld_button("btnLast"))
543 , mxPreviewBox(m_xBuilder->weld_check_button("previewbox"))
544 , mxNumPagesText(m_xBuilder->weld_label("totalnumpages"))
545 , mxPreview(new PrintPreviewWindow(this))
546 , mxPreviewWindow(new weld::CustomWeld(*m_xBuilder, "preview", *mxPreview))
547 , mxPageEdit(m_xBuilder->weld_entry("pageedit"))
548 , mxPagesBtn(m_xBuilder->weld_radio_button("pagespersheetbtn"))
549 , mxBrochureBtn(m_xBuilder->weld_radio_button("brochure"))
550 , mxPagesBoxTitleTxt(m_xBuilder->weld_label("pagespersheettxt"))
551 , mxNupPagesBox(m_xBuilder->weld_combo_box("pagespersheetbox"))
552 , mxNupNumPagesTxt(m_xBuilder->weld_label("pagestxt"))
553 , mxNupColEdt(m_xBuilder->weld_spin_button("pagecols"))
554 , mxNupTimesTxt(m_xBuilder->weld_label("by"))
555 , mxNupRowsEdt(m_xBuilder->weld_spin_button("pagerows"))
556 , mxPageMarginTxt1(m_xBuilder->weld_label("pagemargintxt1"))
557 , mxPageMarginEdt(m_xBuilder->weld_metric_spin_button("pagemarginsb", FieldUnit::MM))
558 , mxPageMarginTxt2(m_xBuilder->weld_label("pagemargintxt2"))
559 , mxSheetMarginTxt1(m_xBuilder->weld_label("sheetmargintxt1"))
560 , mxSheetMarginEdt(m_xBuilder->weld_metric_spin_button("sheetmarginsb", FieldUnit::MM))
561 , mxSheetMarginTxt2(m_xBuilder->weld_label("sheetmargintxt2"))
562 , mxPaperSizeBox(m_xBuilder->weld_combo_box("papersizebox"))
563 , mxOrientationBox(m_xBuilder->weld_combo_box("pageorientationbox"))
564 , mxNupOrderTxt(m_xBuilder->weld_label("labelorder"))
565 , mxNupOrderBox(m_xBuilder->weld_combo_box("orderbox"))
566 , mxNupOrder(new ShowNupOrderWindow)
567 , mxNupOrderWin(new weld::CustomWeld(*m_xBuilder, "orderpreview", *mxNupOrder))
568 , mxBorderCB(m_xBuilder->weld_check_button("bordercb"))
569 , mxRangeExpander(m_xBuilder->weld_expander("exRangeExpander"))
570 , mxLayoutExpander(m_xBuilder->weld_expander("exLayoutExpander"))
571 , mxCustom(m_xBuilder->weld_widget("customcontents"))
572 , maPrintToFileText( VclResId( SV_PRINT_TOFILE_TXTreinterpret_cast<char const *>("SV_PRINT_TOFILE_TXT" "\004"
u8"Print to File...")
) )
573 , maDefPrtText( VclResId( SV_PRINT_DEFPRT_TXTreinterpret_cast<char const *>("SV_PRINT_DEFPRT_TXT" "\004"
u8"Default printer")
) )
574 , maNoPageStr( VclResId( SV_PRINT_NOPAGESreinterpret_cast<char const *>("SV_PRINT_NOPAGES" "\004"
u8"No pages")
) )
575 , maNoPreviewStr( VclResId( SV_PRINT_NOPREVIEWreinterpret_cast<char const *>("SV_PRINT_NOPREVIEW" "\004"
u8"Preview is disabled")
) )
576 , mnCurPage( 0 )
577 , mnCachedPages( 0 )
578 , mbCollateAlwaysOff(false)
579 , mbShowLayoutFrame( true )
580 , mbSingleJobs( false )
581 , maUpdatePreviewIdle("Print Dialog Update Preview Idle")
582 , maUpdatePreviewNoCacheIdle("Print Dialog Update Preview (no cache) Idle")
583{
584 // save printbutton text, gets exchanged occasionally with print to file
585 maPrintText = mxOKButton->get_label();
586
587 maPageStr = mxNumPagesText->get_label();
588
589 Printer::updatePrinters();
590
591 mxPrinters->append_text(maPrintToFileText);
592 // fill printer listbox
593 std::vector< OUString > rQueues( Printer::GetPrinterQueues() );
594 std::sort( rQueues.begin(), rQueues.end(), lcl_ListBoxCompare );
595 for( const auto& rQueue : rQueues )
596 {
597 mxPrinters->append_text(rQueue);
598 }
599 // select current printer
600 if (mxPrinters->find_text(maPController->getPrinter()->GetName()) != -1)
601 mxPrinters->set_active_text(maPController->getPrinter()->GetName());
602 else
603 {
604 // fall back to last printer
605 SettingsConfigItem* pItem = SettingsConfigItem::get();
606 OUString aValue( pItem->getValue( "PrintDialog",
607 "LastPrinter" ) );
608 if (mxPrinters->find_text(aValue) != -1)
609 {
610 mxPrinters->set_active_text(aValue);
611 maPController->setPrinter( VclPtrInstance<Printer>( aValue ) );
612 }
613 else
614 {
615 // fall back to default printer
616 mxPrinters->set_active_text(Printer::GetDefaultPrinterName());
617 maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) );
618 }
619 }
620
621 // not printing to file
622 maPController->resetPrinterOptions( false );
623
624 // update the text fields for the printer
625 updatePrinterText();
626
627 // set paper sizes listbox
628 setPaperSizes();
629
630 // setup dependencies
631 checkControlDependencies();
632
633 // setup paper sides box
634 setupPaperSidesBox();
635
636 // set initial focus to "Number of copies"
637 mxCopyCountField->grab_focus();
638 mxCopyCountField->select_region(0, -1);
639
640 // setup sizes for N-Up
641 Size aNupSize( maPController->getPrinter()->PixelToLogic(
642 maPController->getPrinter()->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) ) );
643 if( maPController->getPrinter()->GetOrientation() == Orientation::Landscape )
644 {
645 maNupLandscapeSize = aNupSize;
646 // coverity[swapped_arguments : FALSE] - this is in the correct order
647 maNupPortraitSize = Size( aNupSize.Height(), aNupSize.Width() );
648 }
649 else
650 {
651 maNupPortraitSize = aNupSize;
652 // coverity[swapped_arguments : FALSE] - this is in the correct order
653 maNupLandscapeSize = Size( aNupSize.Height(), aNupSize.Width() );
654 }
655
656 maUpdatePreviewIdle.SetPriority(TaskPriority::POST_PAINT);
657 maUpdatePreviewIdle.SetInvokeHandler(LINK( this, PrintDialog, updatePreviewIdle)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubupdatePreviewIdle)
);
658 maUpdatePreviewNoCacheIdle.SetPriority(TaskPriority::POST_PAINT);
659 maUpdatePreviewNoCacheIdle.SetInvokeHandler(LINK(this, PrintDialog, updatePreviewNoCacheIdle)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubupdatePreviewNoCacheIdle
)
);
660
661 initFromMultiPageSetup( maPController->getMultipage() );
662
663 // setup optional UI options set by application
664 setupOptionalUI();
665
666 // hide layout frame if unwanted
667 mxPageLayoutFrame->set_visible(mbShowLayoutFrame);
668
669 // restore settings from last run
670 readFromSettings();
671
672 // setup click hdl
673 mxOKButton->connect_clicked(LINK(this, PrintDialog, ClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
674 mxCancelButton->connect_clicked(LINK(this, PrintDialog, ClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
675 mxHelpButton->connect_clicked(LINK(this, PrintDialog, ClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
676 mxSetupButton->connect_clicked( LINK( this, PrintDialog, ClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
677 mxMoreOptionsBtn->connect_clicked( LINK( this, PrintDialog, ClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
678 mxBackwardBtn->connect_clicked(LINK(this, PrintDialog, ClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
679 mxForwardBtn->connect_clicked(LINK(this, PrintDialog, ClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
680 mxFirstBtn->connect_clicked(LINK(this, PrintDialog, ClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
681 mxLastBtn->connect_clicked( LINK( this, PrintDialog, ClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
682 mxPreviewBox->connect_clicked( LINK( this, PrintDialog, ClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
683 mxBorderCB->connect_clicked( LINK( this, PrintDialog, ClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubClickHdl)
);
684
685 // setup toggle hdl
686 mxReverseOrderBox->connect_toggled( LINK( this, PrintDialog, ToggleHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubToggleHdl)
);
687 mxCollateBox->connect_toggled( LINK( this, PrintDialog, ToggleHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubToggleHdl)
);
688 mxPagesBtn->connect_toggled( LINK( this, PrintDialog, ToggleHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubToggleHdl)
);
689
690 // setup select hdl
691 mxPrinters->connect_changed( LINK( this, PrintDialog, SelectHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSelectHdl)
);
692 mxPaperSidesBox->connect_changed( LINK( this, PrintDialog, SelectHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSelectHdl)
);
693 mxNupPagesBox->connect_changed( LINK( this, PrintDialog, SelectHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSelectHdl)
);
694 mxOrientationBox->connect_changed( LINK( this, PrintDialog, SelectHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSelectHdl)
);
695 mxNupOrderBox->connect_changed( LINK( this, PrintDialog, SelectHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSelectHdl)
);
696 mxPaperSizeBox->connect_changed( LINK( this, PrintDialog, SelectHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSelectHdl)
);
697
698 // setup modify hdl
699 mxPageEdit->connect_activate( LINK( this, PrintDialog, ActivateHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubActivateHdl)
);
700 mxPageEdit->connect_focus_out( LINK( this, PrintDialog, FocusOutHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubFocusOutHdl)
);
701 mxCopyCountField->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSpinModifyHdl)
);
702 mxNupColEdt->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSpinModifyHdl)
);
703 mxNupRowsEdt->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubSpinModifyHdl)
);
704 mxPageMarginEdt->connect_value_changed( LINK( this, PrintDialog, MetricSpinModifyHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubMetricSpinModifyHdl)
);
705 mxSheetMarginEdt->connect_value_changed( LINK( this, PrintDialog, MetricSpinModifyHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubMetricSpinModifyHdl)
);
706
707 mxRangeExpander->connect_expanded(LINK( this, PrintDialog, ExpandHdl)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubExpandHdl)
);
708 mxLayoutExpander->connect_expanded(LINK( this, PrintDialog, ExpandHdl)::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubExpandHdl)
);
709
710 updateNupFromPages();
711}
712
713IMPL_LINK_NOARG(PrintDialog, ExpandHdl, weld::Expander&, void)void PrintDialog::LinkStubExpandHdl(void * instance, weld::Expander
& data) { return static_cast<PrintDialog *>(instance
)->ExpandHdl(data); } void PrintDialog::ExpandHdl(__attribute__
((unused)) weld::Expander&)
714{
715 m_xDialog->resize_to_request();
716}
717
718PrintDialog::~PrintDialog()
719{
720}
721
722void PrintDialog::setupPaperSidesBox()
723{
724 DuplexMode eDuplex = maPController->getPrinter()->GetDuplexMode();
725
726 if ( eDuplex == DuplexMode::Unknown || isPrintToFile() )
727 {
728 mxPaperSidesBox->set_active( 0 );
729 mxPaperSidesBox->set_sensitive( false );
730 }
731 else
732 {
733 mxPaperSidesBox->set_active( static_cast<sal_Int32>(eDuplex) - 1 );
734 mxPaperSidesBox->set_sensitive( true );
735 }
736}
737
738void PrintDialog::storeToSettings()
739{
740 SettingsConfigItem* pItem = SettingsConfigItem::get();
741
742 pItem->setValue( "PrintDialog",
743 "LastPrinter",
744 isPrintToFile() ? Printer::GetDefaultPrinterName()
745 : mxPrinters->get_active_text() );
746
747 pItem->setValue( "PrintDialog",
748 "LastPage",
749 mxTabCtrl->get_tab_label_text(mxTabCtrl->get_current_page_ident()));
750
751 pItem->setValue( "PrintDialog",
752 "WindowState",
753 OStringToOUString(m_xDialog->get_window_state(WindowStateMask::All), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))) );
754
755 pItem->setValue( "PrintDialog",
756 "CopyCount",
757 mxCopyCountField->get_text() );
758
759 pItem->setValue( "PrintDialog",
760 "Collate",
761 mxCollateBox->get_active() ? OUString("true") :
762 OUString("false") );
763
764 pItem->setValue( "PrintDialog",
765 "CollateSingleJobs",
766 mbSingleJobs ? OUString("true") :
767 OUString("false") );
768
769 pItem->setValue( "PrintDialog",
770 "HasPreview",
771 hasPreview() ? OUString("true") :
772 OUString("false") );
773
774 pItem->Commit();
775}
776
777void PrintDialog::readFromSettings()
778{
779 SettingsConfigItem* pItem = SettingsConfigItem::get();
780
781 // read last selected tab page; if it exists, activate it
782 OUString aValue = pItem->getValue( "PrintDialog",
783 "LastPage" );
784 sal_uInt16 nCount = mxTabCtrl->get_n_pages();
785 for (sal_uInt16 i = 0; i < nCount; ++i)
786 {
787 OString sPageId = mxTabCtrl->get_page_ident(i);
788 if (aValue == mxTabCtrl->get_tab_label_text(sPageId))
789 {
790 mxTabCtrl->set_current_page(sPageId);
791 break;
792 }
793 }
794
795 // persistent window state
796 aValue = pItem->getValue( "PrintDialog",
797 "WindowState" );
798 if (!aValue.isEmpty())
799 m_xDialog->set_window_state(OUStringToOString(aValue, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))));
800
801 // collate
802 aValue = pItem->getValue( "PrintDialog",
803 "CollateBox" );
804 if( aValue.equalsIgnoreAsciiCase("alwaysoff") )
805 {
806 mbCollateAlwaysOff = true;
807 mxCollateBox->set_active( false );
808 mxCollateBox->set_sensitive( false );
809 }
810 else
811 {
812 mbCollateAlwaysOff = false;
813 aValue = pItem->getValue( "PrintDialog",
814 "Collate" );
815 mxCollateBox->set_active( aValue.equalsIgnoreAsciiCase("true") );
816 }
817
818 // collate single jobs
819 aValue = pItem->getValue( "PrintDialog",
820 "CollateSingleJobs" );
821 if ( aValue.equalsIgnoreAsciiCase("true") )
822 mbSingleJobs = true;
823 else
824 mbSingleJobs = false;
825
826 // preview box
827 aValue = pItem->getValue( "PrintDialog",
828 "HasPreview" );
829 if ( aValue.equalsIgnoreAsciiCase("false") )
830 mxPreviewBox->set_active( false );
831 else
832 mxPreviewBox->set_active( true );
833
834}
835
836void PrintDialog::setPaperSizes()
837{
838 mxPaperSizeBox->clear();
839
840 VclPtr<Printer> aPrt( maPController->getPrinter() );
841 mePaper = aPrt->GetPaper();
842
843 if ( isPrintToFile() )
844 {
845 mxPaperSizeBox->set_sensitive( false );
846 }
847 else
848 {
849 for (int nPaper = 0; nPaper < aPrt->GetPaperInfoCount(); nPaper++)
850 {
851 PaperInfo aInfo = aPrt->GetPaperInfo( nPaper );
852 aInfo.doSloppyFit();
853 Paper ePaper = aInfo.getPaper();
854
855 const LocaleDataWrapper& rLocWrap(Application::GetSettings().GetLocaleDataWrapper());
856 MapUnit eUnit = MapUnit::MapMM;
857 int nDigits = 0;
858 if( rLocWrap.getMeasurementSystemEnum() == MeasurementSystem::US )
859 {
860 eUnit = MapUnit::Map100thInch;
861 nDigits = 2;
862 }
863 Size aSize = aPrt->GetPaperSize( nPaper );
864 Size aLogicPaperSize( OutputDevice::LogicToLogic( aSize, MapMode( MapUnit::Map100thMM ), MapMode( eUnit ) ) );
865
866 OUString aWidth( rLocWrap.getNum( aLogicPaperSize.Width(), nDigits ) );
867 OUString aHeight( rLocWrap.getNum( aLogicPaperSize.Height(), nDigits ) );
868 OUString aUnit = eUnit == MapUnit::MapMM ? OUString("mm") : OUString("in");
869 OUString aPaperName = Printer::GetPaperName( ePaper ) + " " + aWidth + aUnit + " x " + aHeight + aUnit;
870
871 mxPaperSizeBox->append_text(aPaperName);
872
873 if ( ePaper == mePaper )
874 mxPaperSizeBox->set_active( nPaper );
875 }
876
877 mxPaperSizeBox->set_sensitive( true );
878 }
879}
880
881void PrintDialog::updatePrinterText()
882{
883 const OUString aDefPrt( Printer::GetDefaultPrinterName() );
884 const QueueInfo* pInfo = Printer::GetQueueInfo( mxPrinters->get_active_text(), true );
885 if( pInfo )
886 {
887 // FIXME: status text
888 OUString aStatus;
889 if( aDefPrt == pInfo->GetPrinterName() )
890 aStatus = maDefPrtText;
891 mxStatusTxt->set_label( aStatus );
892 }
893 else
894 {
895 mxStatusTxt->set_label( OUString() );
896 }
897}
898
899void PrintDialog::setPreviewText()
900{
901 OUString aNewText( maPageStr.replaceFirst( "%n", OUString::number( mnCachedPages ) ) );
902 mxNumPagesText->set_label( aNewText );
903}
904
905IMPL_LINK_NOARG(PrintDialog, updatePreviewIdle, Timer*, void)void PrintDialog::LinkStubupdatePreviewIdle(void * instance, Timer
* data) { return static_cast<PrintDialog *>(instance)->
updatePreviewIdle(data); } void PrintDialog::updatePreviewIdle
(__attribute__ ((unused)) Timer*)
906{
907 preparePreview(true);
908}
909
910IMPL_LINK_NOARG(PrintDialog, updatePreviewNoCacheIdle, Timer*, void)void PrintDialog::LinkStubupdatePreviewNoCacheIdle(void * instance
, Timer* data) { return static_cast<PrintDialog *>(instance
)->updatePreviewNoCacheIdle(data); } void PrintDialog::updatePreviewNoCacheIdle
(__attribute__ ((unused)) Timer*)
911{
912 preparePreview(false);
913}
914
915void PrintDialog::preparePreview( bool i_bMayUseCache )
916{
917 VclPtr<Printer> aPrt( maPController->getPrinter() );
918 Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) );
919 // tdf#123076 Get paper size for the preview top label
920 mePaper = aPrt->GetPaper();
921 GDIMetaFile aMtf;
922
923 // page range may have changed depending on options
924 sal_Int32 nPages = maPController->getFilteredPageCount();
925 mnCachedPages = nPages;
926
927 setPreviewText();
928
929 if ( !hasPreview() )
930 {
931 mxPreview->setPreview( aMtf, aCurPageSize,
932 Printer::GetPaperName( mePaper ),
933 maNoPreviewStr,
934 aPrt->GetDPIX(), aPrt->GetDPIY(),
935 aPrt->GetPrinterOptions().IsConvertToGreyscales()
936 );
937
938 mxForwardBtn->set_sensitive( false );
939 mxBackwardBtn->set_sensitive( false );
940 mxFirstBtn->set_sensitive( false );
941 mxLastBtn->set_sensitive( false );
942
943 mxPageEdit->set_sensitive( false );
944
945 return;
946 }
947
948 if( mnCurPage >= nPages )
949 mnCurPage = nPages-1;
950 if( mnCurPage < 0 )
951 mnCurPage = 0;
952
953
954 const MapMode aMapMode( MapUnit::Map100thMM );
955 if( nPages > 0 )
956 {
957 PrinterController::PageSize aPageSize =
958 maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache );
959 if( ! aPageSize.bFullPaper )
960 {
961 Point aOff( aPrt->PixelToLogic( aPrt->GetPageOffsetPixel(), aMapMode ) );
962 aMtf.Move( aOff.X(), aOff.Y() );
963 }
964 }
965
966 mxPreview->setPreview( aMtf, aCurPageSize,
967 Printer::GetPaperName( mePaper ),
968 nPages > 0 ? OUString() : maNoPageStr,
969 aPrt->GetDPIX(), aPrt->GetDPIY(),
970 aPrt->GetPrinterOptions().IsConvertToGreyscales()
971 );
972
973 mxForwardBtn->set_sensitive( mnCurPage < nPages-1 );
974 mxBackwardBtn->set_sensitive( mnCurPage != 0 );
975 mxFirstBtn->set_sensitive( mnCurPage != 0 );
976 mxLastBtn->set_sensitive( mnCurPage < nPages-1 );
977 mxPageEdit->set_sensitive( nPages > 1 );
978}
979
980void PrintDialog::updateOrientationBox( const bool bAutomatic )
981{
982 if ( !bAutomatic )
983 {
984 Orientation eOrientation = maPController->getPrinter()->GetOrientation();
985 mxOrientationBox->set_active( static_cast<sal_Int32>(eOrientation) + 1 );
986 }
987 else if ( hasOrientationChanged() )
988 {
989 mxOrientationBox->set_active( ORIENTATION_AUTOMATIC );
990 }
991}
992
993bool PrintDialog::hasOrientationChanged() const
994{
995 const int nOrientation = mxOrientationBox->get_active();
996 const Orientation eOrientation = maPController->getPrinter()->GetOrientation();
997
998 return (nOrientation == ORIENTATION_LANDSCAPE && eOrientation == Orientation::Portrait)
999 || (nOrientation == ORIENTATION_PORTRAIT && eOrientation == Orientation::Landscape);
1000}
1001
1002// make sure paper size matches paper orientation
1003void PrintDialog::checkPaperSize( Size& rPaperSize )
1004{
1005 Orientation eOrientation = maPController->getPrinter()->GetOrientation();
1006 if ( (eOrientation == Orientation::Portrait && rPaperSize.Width() > rPaperSize.Height()) ||
1007 (eOrientation == Orientation::Landscape && rPaperSize.Width() < rPaperSize.Height()) )
1008 {
1009 // coverity[swapped-arguments : FALSE] - this is in the correct order
1010 rPaperSize = Size( rPaperSize.Height(), rPaperSize.Width() );
1011 }
1012}
1013
1014// Always use this function to set paper orientation to make sure everything behaves well
1015void PrintDialog::setPaperOrientation( Orientation eOrientation )
1016{
1017 VclPtr<Printer> aPrt( maPController->getPrinter() );
1018 aPrt->SetOrientation( eOrientation );
1019
1020 // check if it's necessary to swap width and height of paper
1021 if ( maPController->isPaperSizeFromUser() )
1022 {
1023 Size& aPaperSize = maPController->getPaperSizeFromUser();
1024 checkPaperSize( aPaperSize );
1025 }
1026 else if ( maPController->getPapersizeFromSetup() )
1027 {
1028 Size& aPaperSize = maPController->getPaperSizeSetup();
1029 checkPaperSize( aPaperSize );
1030 }
1031}
1032
1033void PrintDialog::checkControlDependencies()
1034{
1035 if (mxCopyCountField->get_value() > 1)
1036 mxCollateBox->set_sensitive( !mbCollateAlwaysOff );
1037 else
1038 mxCollateBox->set_sensitive( false );
1039
1040 OUString aImg(mxCollateBox->get_active() ? OUString(SV_PRINT_COLLATE_BMP"vcl/res/collate.png") : OUString(SV_PRINT_NOCOLLATE_BMP"vcl/res/ncollate.png"));
1041
1042 mxCollateImage->set_from_icon_name(aImg);
1043
1044 // enable setup button only for printers that can be setup
1045 bool bHaveSetup = maPController->getPrinter()->HasSupport( PrinterSupport::SetupDialog );
1046 mxSetupButton->set_sensitive(bHaveSetup);
1047}
1048
1049void PrintDialog::checkOptionalControlDependencies()
1050{
1051 for( const auto& rEntry : maControlToPropertyMap )
1052 {
1053 bool bShouldbeEnabled = maPController->isUIOptionEnabled( rEntry.second );
1054
1055 if (bShouldbeEnabled && dynamic_cast<weld::RadioButton*>(rEntry.first))
4
Assuming 'bShouldbeEnabled' is true
5
Assuming field 'first' is null
6
Assuming pointer value is null
7
Taking false branch
1056 {
1057 auto r_it = maControlToNumValMap.find( rEntry.first );
1058 if( r_it != maControlToNumValMap.end() )
1059 {
1060 bShouldbeEnabled = maPController->isUIChoiceEnabled( rEntry.second, r_it->second );
1061 }
1062 }
1063
1064 bool bIsEnabled = rEntry.first->get_sensitive();
8
Called C++ object pointer is null
1065 // Enable does not do a change check first, so can be less cheap than expected
1066 if (bShouldbeEnabled != bIsEnabled)
1067 rEntry.first->set_sensitive( bShouldbeEnabled );
1068 }
1069}
1070
1071void PrintDialog::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS )
1072{
1073 mxNupOrderWin->show();
1074 mxPagesBtn->set_active(true);
1075 mxBrochureBtn->hide();
1076
1077 // setup field units for metric fields
1078 const LocaleDataWrapper& rLocWrap(Application::GetSettings().GetLocaleDataWrapper());
1079 FieldUnit eUnit = FieldUnit::MM;
1080 sal_uInt16 nDigits = 0;
1081 if( rLocWrap.getMeasurementSystemEnum() == MeasurementSystem::US )
1082 {
1083 eUnit = FieldUnit::INCH;
1084 nDigits = 2;
1085 }
1086 // set units
1087 mxPageMarginEdt->set_unit( eUnit );
1088 mxSheetMarginEdt->set_unit( eUnit );
1089
1090 // set precision
1091 mxPageMarginEdt->set_digits( nDigits );
1092 mxSheetMarginEdt->set_digits( nDigits );
1093
1094 mxSheetMarginEdt->set_value( mxSheetMarginEdt->normalize( i_rMPS.nLeftMargin ), FieldUnit::MM_100TH );
1095 mxPageMarginEdt->set_value( mxPageMarginEdt->normalize( i_rMPS.nHorizontalSpacing ), FieldUnit::MM_100TH );
1096 mxBorderCB->set_active( i_rMPS.bDrawBorder );
1097 mxNupRowsEdt->set_value( i_rMPS.nRows );
1098 mxNupColEdt->set_value( i_rMPS.nColumns );
1099 mxNupOrderBox->set_active( static_cast<sal_Int32>(i_rMPS.nOrder) );
1100 if( i_rMPS.nRows != 1 || i_rMPS.nColumns != 1 )
1101 {
1102 mxNupPagesBox->set_active( mxNupPagesBox->get_count()-1 );
1103 showAdvancedControls( true );
1104 mxNupOrder->setValues( i_rMPS.nOrder, i_rMPS.nColumns, i_rMPS.nRows );
1105 }
1106}
1107
1108void PrintDialog::updateNup( bool i_bMayUseCache )
1109{
1110 int nRows = mxNupRowsEdt->get_value();
1111 int nCols = mxNupColEdt->get_value();
1112 long nPageMargin = mxPageMarginEdt->denormalize(mxPageMarginEdt->get_value( FieldUnit::MM_100TH ));
1113 long nSheetMargin = mxSheetMarginEdt->denormalize(mxSheetMarginEdt->get_value( FieldUnit::MM_100TH ));
1114
1115 PrinterController::MultiPageSetup aMPS;
1116 aMPS.nRows = nRows;
1117 aMPS.nColumns = nCols;
1118 aMPS.nLeftMargin =
1119 aMPS.nTopMargin =
1120 aMPS.nRightMargin =
1121 aMPS.nBottomMargin = nSheetMargin;
1122
1123 aMPS.nHorizontalSpacing =
1124 aMPS.nVerticalSpacing = nPageMargin;
1125
1126 aMPS.bDrawBorder = mxBorderCB->get_active();
1127
1128 aMPS.nOrder = static_cast<NupOrderType>(mxNupOrderBox->get_active());
1129
1130 int nOrientationMode = mxOrientationBox->get_active();
1131 if( nOrientationMode == ORIENTATION_LANDSCAPE )
1132 aMPS.aPaperSize = maNupLandscapeSize;
1133 else if( nOrientationMode == ORIENTATION_PORTRAIT )
1134 aMPS.aPaperSize = maNupPortraitSize;
1135 else // automatic mode
1136 {
1137 // get size of first real page to see if it is portrait or landscape
1138 // we assume same page sizes for all the pages for this
1139 Size aPageSize = getJobPageSize();
1140
1141 Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows );
1142 if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape
1143 {
1144 aMPS.aPaperSize = maNupLandscapeSize;
1145 setPaperOrientation( Orientation::Landscape );
1146 }
1147 else
1148 {
1149 aMPS.aPaperSize = maNupPortraitSize;
1150 setPaperOrientation( Orientation::Portrait );
1151 }
1152 }
1153
1154 maPController->setMultipage( aMPS );
1155
1156 mxNupOrder->setValues( aMPS.nOrder, nCols, nRows );
1157
1158 if (i_bMayUseCache)
1159 maUpdatePreviewIdle.Start();
1160 else
1161 maUpdatePreviewNoCacheIdle.Start();
1162}
1163
1164void PrintDialog::updateNupFromPages( bool i_bMayUseCache )
1165{
1166 int nPages = mxNupPagesBox->get_active_id().toInt32();
1167 int nRows = mxNupRowsEdt->get_value();
1168 int nCols = mxNupColEdt->get_value();
1169 long nPageMargin = mxPageMarginEdt->denormalize(mxPageMarginEdt->get_value( FieldUnit::MM_100TH ));
1170 long nSheetMargin = mxSheetMarginEdt->denormalize(mxSheetMarginEdt->get_value( FieldUnit::MM_100TH ));
1171 bool bCustom = false;
1172
1173 if( nPages == 1 )
1174 {
1175 nRows = nCols = 1;
1176 nSheetMargin = 0;
1177 nPageMargin = 0;
1178 }
1179 else if( nPages == 2 || nPages == 4 || nPages == 6 || nPages == 9 || nPages == 16 )
1180 {
1181 Size aJobPageSize( getJobPageSize() );
1182 bool bPortrait = aJobPageSize.Width() < aJobPageSize.Height();
1183 if( nPages == 2 )
1184 {
1185 if( bPortrait )
1186 {
1187 nRows = 1;
1188 nCols = 2;
1189 }
1190 else
1191 {
1192 nRows = 2;
1193 nCols = 1;
1194 }
1195 }
1196 else if( nPages == 4 )
1197 nRows = nCols = 2;
1198 else if( nPages == 6 )
1199 {
1200 if( bPortrait )
1201 {
1202 nRows = 2;
1203 nCols = 3;
1204 }
1205 else
1206 {
1207 nRows = 3;
1208 nCols = 2;
1209 }
1210 }
1211 else if( nPages == 9 )
1212 nRows = nCols = 3;
1213 else if( nPages == 16 )
1214 nRows = nCols = 4;
1215 nPageMargin = 0;
1216 nSheetMargin = 0;
1217 }
1218 else
1219 bCustom = true;
1220
1221 if( nPages > 1 )
1222 {
1223 // set upper limits for margins based on job page size and rows/columns
1224 Size aSize( getJobPageSize() );
1225
1226 // maximum sheet distance: 1/2 sheet
1227 long nHorzMax = aSize.Width()/2;
1228 long nVertMax = aSize.Height()/2;
1229 if( nSheetMargin > nHorzMax )
1230 nSheetMargin = nHorzMax;
1231 if( nSheetMargin > nVertMax )
1232 nSheetMargin = nVertMax;
1233
1234 mxSheetMarginEdt->set_max(
1235 mxSheetMarginEdt->normalize(
1236 std::min(nHorzMax, nVertMax) ), FieldUnit::MM_100TH );
1237
1238 // maximum page distance
1239 nHorzMax = (aSize.Width() - 2*nSheetMargin);
1240 if( nCols > 1 )
1241 nHorzMax /= (nCols-1);
1242 nVertMax = (aSize.Height() - 2*nSheetMargin);
1243 if( nRows > 1 )
1244 nHorzMax /= (nRows-1);
1245
1246 if( nPageMargin > nHorzMax )
1247 nPageMargin = nHorzMax;
1248 if( nPageMargin > nVertMax )
1249 nPageMargin = nVertMax;
1250
1251 mxPageMarginEdt->set_max(
1252 mxSheetMarginEdt->normalize(
1253 std::min(nHorzMax, nVertMax ) ), FieldUnit::MM_100TH );
1254 }
1255
1256 mxNupRowsEdt->set_value( nRows );
1257 mxNupColEdt->set_value( nCols );
1258 mxPageMarginEdt->set_value( mxPageMarginEdt->normalize( nPageMargin ), FieldUnit::MM_100TH );
1259 mxSheetMarginEdt->set_value( mxSheetMarginEdt->normalize( nSheetMargin ), FieldUnit::MM_100TH );
1260
1261 showAdvancedControls( bCustom );
1262 updateNup( i_bMayUseCache );
1263}
1264
1265void PrintDialog::enableNupControls( bool bEnable )
1266{
1267 mxNupPagesBox->set_sensitive( bEnable );
1268 mxNupNumPagesTxt->set_sensitive( bEnable );
1269 mxNupColEdt->set_sensitive( bEnable );
1270 mxNupTimesTxt->set_sensitive( bEnable );
1271 mxNupRowsEdt->set_sensitive( bEnable );
1272 mxPageMarginTxt1->set_sensitive( bEnable );
1273 mxPageMarginEdt->set_sensitive( bEnable );
1274 mxPageMarginTxt2->set_sensitive( bEnable );
1275 mxSheetMarginTxt1->set_sensitive( bEnable );
1276 mxSheetMarginEdt->set_sensitive( bEnable );
1277 mxSheetMarginTxt2->set_sensitive( bEnable );
1278 mxNupOrderTxt->set_sensitive( bEnable );
1279 mxNupOrderBox->set_sensitive( bEnable );
1280 mxNupOrderWin->set_sensitive( bEnable );
1281 mxBorderCB->set_sensitive( bEnable );
1282}
1283
1284void PrintDialog::showAdvancedControls( bool i_bShow )
1285{
1286 mxNupNumPagesTxt->set_visible( i_bShow );
1287 mxNupColEdt->set_visible( i_bShow );
1288 mxNupTimesTxt->set_visible( i_bShow );
1289 mxNupRowsEdt->set_visible( i_bShow );
1290 mxPageMarginTxt1->set_visible( i_bShow );
1291 mxPageMarginEdt->set_visible( i_bShow );
1292 mxPageMarginTxt2->set_visible( i_bShow );
1293 mxSheetMarginTxt1->set_visible( i_bShow );
1294 mxSheetMarginEdt->set_visible( i_bShow );
1295 mxSheetMarginTxt2->set_visible( i_bShow );
1296}
1297
1298namespace
1299{
1300 void setHelpId( weld::Widget* i_pWindow, const Sequence< OUString >& i_rHelpIds, sal_Int32 i_nIndex )
1301 {
1302 if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() )
1303 i_pWindow->set_help_id( OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ) );
1304 }
1305
1306 void setHelpText( weld::Widget* i_pWindow, const Sequence< OUString >& i_rHelpTexts, sal_Int32 i_nIndex )
1307 {
1308 // without a help text set and the correct smartID,
1309 // help texts will be retrieved from the online help system
1310 if( i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength() )
1311 i_pWindow->set_tooltip_text(i_rHelpTexts.getConstArray()[i_nIndex]);
1312 }
1313}
1314
1315void PrintDialog::setupOptionalUI()
1316{
1317 const Sequence< PropertyValue >& rOptions( maPController->getUIOptions() );
1318 for( const auto& rOption : rOptions )
1319 {
1320 if (rOption.Name == "OptionsUIFile")
1321 {
1322 OUString sOptionsUIFile;
1323 rOption.Value >>= sOptionsUIFile;
1324 mxCustomOptionsUIBuilder.reset(Application::CreateBuilder(mxCustom.get(), sOptionsUIFile));
1325 std::unique_ptr<weld::Container> xWindow = mxCustomOptionsUIBuilder->weld_container("box");
1326 xWindow->show();
1327 continue;
1328 }
1329
1330 Sequence< beans::PropertyValue > aOptProp;
1331 rOption.Value >>= aOptProp;
1332
1333 // extract ui element
1334 OUString aCtrlType;
1335 OString aID;
1336 OUString aText;
1337 OUString aPropertyName;
1338 Sequence< OUString > aChoices;
1339 Sequence< sal_Bool > aChoicesDisabled;
1340 Sequence< OUString > aHelpTexts;
1341 Sequence< OUString > aIDs;
1342 Sequence< OUString > aHelpIds;
1343 sal_Int64 nMinValue = 0, nMaxValue = 0;
1344 OUString aGroupingHint;
1345
1346 for( const beans::PropertyValue& rEntry : std::as_const(aOptProp) )
1347 {
1348 if ( rEntry.Name == "ID" )
1349 {
1350 rEntry.Value >>= aIDs;
1351 aID = OUStringToOString(aIDs[0], RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
1352 }
1353 if ( rEntry.Name == "Text" )
1354 {
1355 rEntry.Value >>= aText;
1356 }
1357 else if ( rEntry.Name == "ControlType" )
1358 {
1359 rEntry.Value >>= aCtrlType;
1360 }
1361 else if ( rEntry.Name == "Choices" )
1362 {
1363 rEntry.Value >>= aChoices;
1364 }
1365 else if ( rEntry.Name == "ChoicesDisabled" )
1366 {
1367 rEntry.Value >>= aChoicesDisabled;
1368 }
1369 else if ( rEntry.Name == "Property" )
1370 {
1371 PropertyValue aVal;
1372 rEntry.Value >>= aVal;
1373 aPropertyName = aVal.Name;
1374 }
1375 else if ( rEntry.Name == "Enabled" )
1376 {
1377 }
1378 else if ( rEntry.Name == "GroupingHint" )
1379 {
1380 rEntry.Value >>= aGroupingHint;
1381 }
1382 else if ( rEntry.Name == "DependsOnName" )
1383 {
1384 }
1385 else if ( rEntry.Name == "DependsOnEntry" )
1386 {
1387 }
1388 else if ( rEntry.Name == "AttachToDependency" )
1389 {
1390 }
1391 else if ( rEntry.Name == "MinValue" )
1392 {
1393 rEntry.Value >>= nMinValue;
1394 }
1395 else if ( rEntry.Name == "MaxValue" )
1396 {
1397 rEntry.Value >>= nMaxValue;
1398 }
1399 else if ( rEntry.Name == "HelpText" )
1400 {
1401 if( ! (rEntry.Value >>= aHelpTexts) )
1402 {
1403 OUString aHelpText;
1404 if( rEntry.Value >>= aHelpText )
1405 {
1406 aHelpTexts.realloc( 1 );
1407 *aHelpTexts.getArray() = aHelpText;
1408 }
1409 }
1410 }
1411 else if ( rEntry.Name == "HelpId" )
1412 {
1413 if( ! (rEntry.Value >>= aHelpIds ) )
1414 {
1415 OUString aHelpId;
1416 if( rEntry.Value >>= aHelpId )
1417 {
1418 aHelpIds.realloc( 1 );
1419 *aHelpIds.getArray() = aHelpId;
1420 }
1421 }
1422 }
1423 else if ( rEntry.Name == "HintNoLayoutPage" )
1424 {
1425 bool bHasLayoutFrame = false;
1426 rEntry.Value >>= bHasLayoutFrame;
1427 mbShowLayoutFrame = !bHasLayoutFrame;
1428 }
1429 }
1430
1431 if (aCtrlType == "Group")
1432 {
1433 aID = "custom";
1434
1435 weld::Container* pPage = mxTabCtrl->get_page(aID);
1436 if (!pPage)
1437 continue;
1438
1439 mxTabCtrl->set_tab_label_text(aID, aText);
1440
1441 // set help id
1442 if (aHelpIds.hasElements())
1443 pPage->set_help_id(OUStringToOString(aHelpIds.getConstArray()[0], RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))));
1444
1445 // set help text
1446 if (aHelpTexts.hasElements())
1447 pPage->set_tooltip_text(aHelpTexts.getConstArray()[0]);
1448
1449 pPage->show();
1450 }
1451 else if (aCtrlType == "Subgroup" && !aID.isEmpty())
1452 {
1453 std::unique_ptr<weld::Widget> xWidget;
1454 // since 'New Print Dialog Design' fromwhich in calc is not a frame anymore
1455 if (aID == "fromwhich")
1456 {
1457 std::unique_ptr<weld::Label> xLabel = m_xBuilder->weld_label(aID);
1458 xLabel->set_label(aText);
1459 xWidget = std::move(xLabel);
1460 }
1461 else
1462 {
1463 std::unique_ptr<weld::Frame> xFrame = m_xBuilder->weld_frame(aID);
1464 if (!xFrame && mxCustomOptionsUIBuilder)
1465 xFrame = mxCustomOptionsUIBuilder->weld_frame(aID);
1466 if (xFrame)
1467 {
1468 xFrame->set_label(aText);
1469 xWidget = std::move(xFrame);
1470 }
1471 }
1472
1473 if (!xWidget)
1474 continue;
1475
1476 // set help id
1477 setHelpId(xWidget.get(), aHelpIds, 0);
1478 // set help text
1479 setHelpText(xWidget.get(), aHelpTexts, 0);
1480
1481 xWidget->show();
1482 }
1483 // EVIL
1484 else if( aCtrlType == "Bool" && aGroupingHint == "LayoutPage" && aPropertyName == "PrintProspect" )
1485 {
1486 mxBrochureBtn->set_label(aText);
1487 mxBrochureBtn->show();
1488
1489 bool bVal = false;
1490 PropertyValue* pVal = maPController->getValue( aPropertyName );
1491 if( pVal )
1492 pVal->Value >>= bVal;
1493 mxBrochureBtn->set_active( bVal );
1494 mxBrochureBtn->set_sensitive( maPController->isUIOptionEnabled( aPropertyName ) && pVal != nullptr );
1495 mxBrochureBtn->connect_toggled( LINK( this, PrintDialog, ToggleHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubToggleHdl)
);
1496
1497 maPropertyToWindowMap[aPropertyName].emplace_back(mxBrochureBtn.get());
1498 maControlToPropertyMap[mxBrochureBtn.get()] = aPropertyName;
1499
1500 // set help id
1501 setHelpId( mxBrochureBtn.get(), aHelpIds, 0 );
1502 // set help text
1503 setHelpText( mxBrochureBtn.get(), aHelpTexts, 0 );
1504 }
1505 else if (aCtrlType == "Bool")
1506 {
1507 // add a check box
1508 std::unique_ptr<weld::CheckButton> xNewBox = m_xBuilder->weld_check_button(aID);
1509 if (!xNewBox && mxCustomOptionsUIBuilder)
1510 xNewBox = mxCustomOptionsUIBuilder->weld_check_button(aID);
1511 if (!xNewBox)
1512 continue;
1513
1514 xNewBox->set_label( aText );
1515 xNewBox->show();
1516
1517 bool bVal = false;
1518 PropertyValue* pVal = maPController->getValue( aPropertyName );
1519 if( pVal )
1520 pVal->Value >>= bVal;
1521 xNewBox->set_active( bVal );
1522 xNewBox->connect_toggled( LINK( this, PrintDialog, UIOption_CheckHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubUIOption_CheckHdl)
);
1523
1524 maExtraControls.emplace_back(std::move(xNewBox));
1525
1526 weld::Widget* pWidget = maExtraControls.back().get();
1527
1528 maPropertyToWindowMap[aPropertyName].emplace_back(pWidget);
1529 maControlToPropertyMap[pWidget] = aPropertyName;
1530
1531 // set help id
1532 setHelpId(pWidget, aHelpIds, 0);
1533 // set help text
1534 setHelpText(pWidget, aHelpTexts, 0);
1535 }
1536 else if (aCtrlType == "Radio")
1537 {
1538 sal_Int32 nCurHelpText = 0;
1539
1540 // iterate options
1541 sal_Int32 nSelectVal = 0;
1542 PropertyValue* pVal = maPController->getValue( aPropertyName );
1543 if( pVal && pVal->Value.hasValue() )
1544 pVal->Value >>= nSelectVal;
1545 for( sal_Int32 m = 0; m < aChoices.getLength(); m++ )
1546 {
1547 aID = OUStringToOString(aIDs[m], RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
1548 std::unique_ptr<weld::RadioButton> xBtn = m_xBuilder->weld_radio_button(aID);
1549 if (!xBtn && mxCustomOptionsUIBuilder)
1550 xBtn = mxCustomOptionsUIBuilder->weld_radio_button(aID);
1551 if (!xBtn)
1552 continue;
1553
1554 xBtn->set_label( aChoices[m] );
1555 xBtn->set_active( m == nSelectVal );
1556 xBtn->connect_toggled( LINK( this, PrintDialog, UIOption_RadioHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubUIOption_RadioHdl)
);
1557 if( aChoicesDisabled.getLength() > m && aChoicesDisabled[m] )
1558 xBtn->set_sensitive( false );
1559 xBtn->show();
1560
1561 maExtraControls.emplace_back(std::move(xBtn));
1562
1563 weld::Widget* pWidget = maExtraControls.back().get();
1564
1565 maPropertyToWindowMap[ aPropertyName ].emplace_back(pWidget);
1566 maControlToPropertyMap[pWidget] = aPropertyName;
1567 maControlToNumValMap[pWidget] = m;
1568
1569 // set help id
1570 setHelpId( pWidget, aHelpIds, nCurHelpText );
1571 // set help text
1572 setHelpText( pWidget, aHelpTexts, nCurHelpText );
1573 nCurHelpText++;
1574 }
1575 }
1576 else if ( aCtrlType == "List" )
1577 {
1578 std::unique_ptr<weld::ComboBox> xList = m_xBuilder->weld_combo_box(aID);
1579 if (!xList && mxCustomOptionsUIBuilder)
1580 xList = mxCustomOptionsUIBuilder->weld_combo_box(aID);
1581 if (!xList)
1582 continue;
1583
1584 // iterate options
1585 for( const auto& rChoice : std::as_const(aChoices) )
1586 xList->append_text(rChoice);
1587
1588 sal_Int32 nSelectVal = 0;
1589 PropertyValue* pVal = maPController->getValue( aPropertyName );
1590 if( pVal && pVal->Value.hasValue() )
1591 pVal->Value >>= nSelectVal;
1592 xList->set_active(nSelectVal);
1593 xList->connect_changed( LINK( this, PrintDialog, UIOption_SelectHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubUIOption_SelectHdl)
);
1594 xList->show();
1595
1596 maExtraControls.emplace_back(std::move(xList));
1597
1598 weld::Widget* pWidget = maExtraControls.back().get();
1599
1600 maPropertyToWindowMap[ aPropertyName ].emplace_back(pWidget);
1601 maControlToPropertyMap[pWidget] = aPropertyName;
1602
1603 // set help id
1604 setHelpId( pWidget, aHelpIds, 0 );
1605 // set help text
1606 setHelpText( pWidget, aHelpTexts, 0 );
1607 }
1608 else if ( aCtrlType == "Range" )
1609 {
1610 std::unique_ptr<weld::SpinButton> xField = m_xBuilder->weld_spin_button(aID);
1611 if (!xField && mxCustomOptionsUIBuilder)
1612 xField = mxCustomOptionsUIBuilder->weld_spin_button(aID);
1613 if (!xField)
1614 continue;
1615
1616 // set min/max and current value
1617 if(nMinValue != nMaxValue)
1618 xField->set_range(nMinValue, nMaxValue);
1619
1620 sal_Int64 nCurVal = 0;
1621 PropertyValue* pVal = maPController->getValue( aPropertyName );
1622 if( pVal && pVal->Value.hasValue() )
1623 pVal->Value >>= nCurVal;
1624 xField->set_value( nCurVal );
1625 xField->connect_value_changed( LINK( this, PrintDialog, UIOption_SpinModifyHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubUIOption_SpinModifyHdl
)
);
1626 xField->show();
1627
1628 maExtraControls.emplace_back(std::move(xField));
1629
1630 weld::Widget* pWidget = maExtraControls.back().get();
1631
1632 maPropertyToWindowMap[ aPropertyName ].emplace_back(pWidget);
1633 maControlToPropertyMap[pWidget] = aPropertyName;
1634
1635 // set help id
1636 setHelpId( pWidget, aHelpIds, 0 );
1637 // set help text
1638 setHelpText( pWidget, aHelpTexts, 0 );
1639 }
1640 else if (aCtrlType == "Edit")
1641 {
1642 std::unique_ptr<weld::Entry> xField = m_xBuilder->weld_entry(aID);
1643 if (!xField && mxCustomOptionsUIBuilder)
1644 xField = mxCustomOptionsUIBuilder->weld_entry(aID);
1645 if (!xField)
1646 continue;
1647
1648 OUString aCurVal;
1649 PropertyValue* pVal = maPController->getValue( aPropertyName );
1650 if( pVal && pVal->Value.hasValue() )
1651 pVal->Value >>= aCurVal;
1652 xField->set_text( aCurVal );
1653 xField->connect_changed( LINK( this, PrintDialog, UIOption_EntryModifyHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintDialog
*>(this), &PrintDialog::LinkStubUIOption_EntryModifyHdl
)
);
1654 xField->show();
1655
1656 maExtraControls.emplace_back(std::move(xField));
1657
1658 weld::Widget* pWidget = maExtraControls.back().get();
1659
1660 maPropertyToWindowMap[ aPropertyName ].emplace_back(pWidget);
1661 maControlToPropertyMap[pWidget] = aPropertyName;
1662
1663 // set help id
1664 setHelpId( pWidget, aHelpIds, 0 );
1665 // set help text
1666 setHelpText( pWidget, aHelpTexts, 0 );
1667 }
1668 else
1669 {
1670 SAL_WARN( "vcl", "Unsupported UI option: \"" << aCtrlType << '"')do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Unsupported UI option: \"" << aCtrlType <<
'"') == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN)
, ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1670" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Unsupported UI option: \"" <<
aCtrlType << '"'), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Unsupported UI option: \"" <<
aCtrlType << '"'; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1670" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Unsupported UI option: \"" << aCtrlType <<
'"') == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN)
, ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1670" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Unsupported UI option: \"" <<
aCtrlType << '"'), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Unsupported UI option: \"" <<
aCtrlType << '"'; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1670" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1671 }
1672 }
1673
1674 // #i106506# if no brochure button, then the singular Pages radio button
1675 // makes no sense, so replace it by a FixedText label
1676 if (!mxBrochureBtn->get_visible() && mxPagesBtn->get_visible())
1677 {
1678 mxPagesBoxTitleTxt->set_label(mxPagesBtn->get_label());
1679 mxPagesBoxTitleTxt->show();
1680 mxPagesBtn->hide();
1681
1682 mxPagesBoxTitleTxt->set_accessible_relation_label_for(mxNupPagesBox.get());
1683 mxNupPagesBox->set_accessible_relation_labeled_by(mxPagesBoxTitleTxt.get());
1684 mxPagesBtn->set_accessible_relation_label_for(nullptr);
1685 }
1686
1687 // update enable states
1688 checkOptionalControlDependencies();
1689
1690 // print range not shown (currently math only) -> hide spacer line and reverse order
1691 if (!mxPageRangeEdit->get_visible())
1692 {
1693 mxReverseOrderBox->hide();
1694 }
1695
1696 if (!mxCustomOptionsUIBuilder)
1697 mxTabCtrl->remove_page(mxTabCtrl->get_page_ident(1));
1698}
1699
1700void PrintDialog::makeEnabled( weld::Widget* i_pWindow )
1701{
1702 auto it = maControlToPropertyMap.find( i_pWindow );
1703 if( it != maControlToPropertyMap.end() )
1704 {
1705 OUString aDependency( maPController->makeEnabled( it->second ) );
1706 if( !aDependency.isEmpty() )
1707 updateWindowFromProperty( aDependency );
1708 }
1709}
1710
1711void PrintDialog::updateWindowFromProperty( const OUString& i_rProperty )
1712{
1713 beans::PropertyValue* pValue = maPController->getValue( i_rProperty );
1714 auto it = maPropertyToWindowMap.find( i_rProperty );
1715 if( !(pValue && it != maPropertyToWindowMap.end()) )
1716 return;
1717
1718 const auto& rWindows( it->second );
1719 if( rWindows.empty() )
1720 return;
1721
1722 bool bVal = false;
1723 sal_Int32 nVal = -1;
1724 if( pValue->Value >>= bVal )
1725 {
1726 // we should have a CheckBox for this one
1727 weld::CheckButton* pBox = dynamic_cast<weld::CheckButton*>(rWindows.front());
1728 if( pBox )
1729 {
1730 pBox->set_active( bVal );
1731 }
1732 else if ( i_rProperty == "PrintProspect" )
1733 {
1734 // EVIL special case
1735 if( bVal )
1736 mxBrochureBtn->set_active(true);
1737 else
1738 mxPagesBtn->set_active(true);
1739 }
1740 else
1741 {
1742 SAL_WARN( "vcl", "missing a checkbox" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "missing a checkbox") == 1) { ::sal_detail_log( (
::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1742" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "missing a checkbox"), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"missing a checkbox"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1742" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "missing a checkbox") == 1) { ::sal_detail_log( (
::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1742" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "missing a checkbox"), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"missing a checkbox"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1742" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1743 }
1744 }
1745 else if( pValue->Value >>= nVal )
1746 {
1747 // this could be a ListBox or a RadioButtonGroup
1748 weld::ComboBox* pList = dynamic_cast<weld::ComboBox*>(rWindows.front());
1749 if( pList )
1750 {
1751 pList->set_active( static_cast< sal_uInt16 >(nVal) );
1752 }
1753 else if( nVal >= 0 && nVal < sal_Int32(rWindows.size() ) )
1754 {
1755 weld::RadioButton* pBtn = dynamic_cast<weld::RadioButton*>(rWindows[nVal]);
1756 SAL_WARN_IF( !pBtn, "vcl", "unexpected control for property" )do { if (true && (!pBtn)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "unexpected control for property"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1756" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "unexpected control for property"), 0
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "unexpected control for property"; ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1756" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "unexpected control for property") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1756" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "unexpected control for property"), 0
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "unexpected control for property"; ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1756" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1757 if( pBtn )
1758 pBtn->set_active(true);
1759 }
1760 }
1761}
1762
1763bool PrintDialog::isPrintToFile() const
1764{
1765 return ( mxPrinters->get_active() == 0 );
1766}
1767
1768bool PrintDialog::isCollate() const
1769{
1770 return mxCopyCountField->get_value() > 1 && mxCollateBox->get_active();
1771}
1772
1773bool PrintDialog::hasPreview() const
1774{
1775 return mxPreviewBox->get_active();
1776}
1777
1778PropertyValue* PrintDialog::getValueForWindow( weld::Widget* i_pWindow ) const
1779{
1780 PropertyValue* pVal = nullptr;
1781 auto it = maControlToPropertyMap.find( i_pWindow );
1782 if( it != maControlToPropertyMap.end() )
1783 {
1784 pVal = maPController->getValue( it->second );
1785 SAL_WARN_IF( !pVal, "vcl", "property value not found" )do { if (true && (!pVal)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "property value not found"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1785" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "property value not found"), 0); } else
{ ::std::ostringstream sal_detail_stream; sal_detail_stream <<
"property value not found"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1785" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "property value not found") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1785" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "property value not found"), 0); } else
{ ::std::ostringstream sal_detail_stream; sal_detail_stream <<
"property value not found"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1785" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1786 }
1787 else
1788 {
1789 OSL_FAIL( "changed control not in property map" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/printdlg.cxx"
":" "1789" ": "), "%s", "changed control not in property map"
); } } while (false)
;
1790 }
1791 return pVal;
1792}
1793
1794IMPL_LINK(PrintDialog, ToggleHdl, weld::ToggleButton&, rButton, void)void PrintDialog::LinkStubToggleHdl(void * instance, weld::ToggleButton
& data) { return static_cast<PrintDialog *>(instance
)->ToggleHdl(data); } void PrintDialog::ToggleHdl(weld::ToggleButton
& rButton)
1795{
1796 ClickHdl(rButton);
1797}
1798
1799IMPL_LINK(PrintDialog, ClickHdl, weld::Button&, rButton, void)void PrintDialog::LinkStubClickHdl(void * instance, weld::Button
& data) { return static_cast<PrintDialog *>(instance
)->ClickHdl(data); } void PrintDialog::ClickHdl(weld::Button
& rButton)
1800{
1801 if (&rButton == mxOKButton.get() || &rButton == mxCancelButton.get())
1802 {
1803 storeToSettings();
1804 m_xDialog->response(&rButton == mxOKButton.get() ? RET_OK : RET_CANCEL);
1805 }
1806 else if( &rButton == mxHelpButton.get() )
1807 {
1808 // start help system
1809 Help* pHelp = Application::GetHelp();
1810 if( pHelp )
1811 {
1812 pHelp->Start("vcl/ui/printdialog/PrintDialog", mxOKButton.get());
1813 }
1814 }
1815 else if ( &rButton == mxPreviewBox.get() )
1816 {
1817 maUpdatePreviewIdle.Start();
1818 }
1819 else if( &rButton == mxForwardBtn.get() )
1820 {
1821 previewForward();
1822 }
1823 else if( &rButton == mxBackwardBtn.get() )
1824 {
1825 previewBackward();
1826 }
1827 else if( &rButton == mxFirstBtn.get() )
1828 {
1829 previewFirst();
1830 }
1831 else if( &rButton == mxLastBtn.get() )
1832 {
1833 previewLast();
1834 }
1835 else if( &rButton == mxBrochureBtn.get() )
1836 {
1837 PropertyValue* pVal = getValueForWindow( &rButton );
1838 if( pVal )
1839 {
1840 bool bVal = mxBrochureBtn->get_active();
1841 pVal->Value <<= bVal;
1842
1843 checkOptionalControlDependencies();
1844
1845 // update preview and page settings
1846 maUpdatePreviewNoCacheIdle.Start();
1847 }
1848 if( mxBrochureBtn->get_active() )
1849 {
1850 mxOrientationBox->set_sensitive( false );
1851 mxOrientationBox->set_active( ORIENTATION_LANDSCAPE );
1852 mxNupPagesBox->set_active( 0 );
1853 updateNupFromPages();
1854 showAdvancedControls( false );
1855 enableNupControls( false );
1856 }
1857 }
1858 else if( &rButton == mxPagesBtn.get() )
1859 {
1860 mxOrientationBox->set_sensitive( true );
1861 mxOrientationBox->set_active( ORIENTATION_AUTOMATIC );
1862 enableNupControls( true );
1863 updateNupFromPages();
1864 }
1865 else if( &rButton == mxCollateBox.get() )
1866 {
1867 maPController->setValue( "Collate",
1868 makeAny( isCollate() ) );
1869 checkControlDependencies();
1870 }
1871 else if( &rButton == mxReverseOrderBox.get() )
1872 {
1873 bool bChecked = mxReverseOrderBox->get_active();
1874 maPController->setReversePrint( bChecked );
1875 maPController->setValue( "PrintReverse",
1876 makeAny( bChecked ) );
1877 maUpdatePreviewIdle.Start();
1878 }
1879 else if( &rButton == mxBorderCB.get() )
1880 {
1881 updateNup();
1882 }
1883 else if ( &rButton == mxMoreOptionsBtn.get() )
1884 {
1885 mxMoreOptionsDlg.reset(new MoreOptionsDialog(this));
1886 mxMoreOptionsDlg->run();
1887 }
1888 else
1889 {
1890 if( &rButton == mxSetupButton.get() )
1891 {
1892 maPController->setupPrinter(m_xDialog.get());
1893
1894 if ( !isPrintToFile() )
1895 {
1896 VclPtr<Printer> aPrt( maPController->getPrinter() );
1897 mePaper = aPrt->GetPaper();
1898
1899 for (int nPaper = 0; nPaper < aPrt->GetPaperInfoCount(); nPaper++ )
1900 {
1901 PaperInfo aInfo = aPrt->GetPaperInfo( nPaper );
1902 aInfo.doSloppyFit();
1903 Paper ePaper = aInfo.getPaper();
1904
1905 if ( mePaper == ePaper )
1906 {
1907 mxPaperSizeBox->set_active( nPaper );
1908 break;
1909 }
1910 }
1911 }
1912
1913 updateOrientationBox( false );
1914 setupPaperSidesBox();
1915
1916 // tdf#63905 don't use cache: page size may change
1917 maUpdatePreviewNoCacheIdle.Start();
1918 }
1919 checkControlDependencies();
1920 }
1921
1922}
1923
1924IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void )void PrintDialog::LinkStubSelectHdl(void * instance, weld::ComboBox
& data) { return static_cast<PrintDialog *>(instance
)->SelectHdl(data); } void PrintDialog::SelectHdl(weld::ComboBox
& rBox)
1925{
1926 if (&rBox == mxPrinters.get())
1927 {
1928 if ( !isPrintToFile() )
1929 {
1930 OUString aNewPrinter(rBox.get_active_text());
1931 // set new printer
1932 maPController->setPrinter( VclPtrInstance<Printer>( aNewPrinter ) );
1933 maPController->resetPrinterOptions( false );
1934
1935 updateOrientationBox();
1936
1937 // update text fields
1938 mxOKButton->set_label(maPrintText);
1939 updatePrinterText();
1940 setPaperSizes();
1941 maUpdatePreviewIdle.Start();
1942 }
1943 else // print to file
1944 {
1945 // use the default printer or FIXME: the last used one?
1946 maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) );
1947 mxOKButton->set_label(maPrintToFileText);
1948 maPController->resetPrinterOptions( true );
1949
1950 setPaperSizes();
1951 updateOrientationBox();
1952 maUpdatePreviewIdle.Start();
1953 }
1954
1955 setupPaperSidesBox();
1956 }
1957 else if ( &rBox == mxPaperSidesBox.get() )
1958 {
1959 DuplexMode eDuplex = static_cast<DuplexMode>(mxPaperSidesBox->get_active() + 1);
1960 maPController->getPrinter()->SetDuplexMode( eDuplex );
1961 }
1962 else if( &rBox == mxOrientationBox.get() )
1963 {
1964 int nOrientation = mxOrientationBox->get_active();
1965 if ( nOrientation != ORIENTATION_AUTOMATIC )
1966 setPaperOrientation( static_cast<Orientation>( nOrientation - 1 ) );
1967
1968 updateNup( false );
1969 }
1970 else if ( &rBox == mxNupOrderBox.get() )
1971 {
1972 updateNup();
1973 }
1974 else if( &rBox == mxNupPagesBox.get() )
1975 {
1976 if( !mxPagesBtn->get_active() )
1977 mxPagesBtn->set_active(true);
1978 updateNupFromPages( false );
1979 }
1980 else if ( &rBox == mxPaperSizeBox.get() )
1981 {
1982 VclPtr<Printer> aPrt( maPController->getPrinter() );
1983 PaperInfo aInfo = aPrt->GetPaperInfo( rBox.get_active() );
1984 aInfo.doSloppyFit();
1985 mePaper = aInfo.getPaper();
1986
1987 if ( mePaper == PAPER_USER )
1988 aPrt->SetPaperSizeUser( Size( aInfo.getWidth(), aInfo.getHeight() ) );
1989 else
1990 aPrt->SetPaper( mePaper );
1991
1992 Size aPaperSize( aInfo.getWidth(), aInfo.getHeight() );
1993 checkPaperSize( aPaperSize );
1994 maPController->setPaperSizeFromUser( aPaperSize );
1995
1996 maUpdatePreviewIdle.Start();
1997 }
1998}
1999
2000IMPL_LINK_NOARG(PrintDialog, MetricSpinModifyHdl, weld::MetricSpinButton&, void)void PrintDialog::LinkStubMetricSpinModifyHdl(void * instance
, weld::MetricSpinButton& data) { return static_cast<PrintDialog
*>(instance)->MetricSpinModifyHdl(data); } void PrintDialog
::MetricSpinModifyHdl(__attribute__ ((unused)) weld::MetricSpinButton
&)
2001{
2002 checkControlDependencies();
2003 updateNupFromPages();
2004}
2005
2006IMPL_LINK_NOARG(PrintDialog, FocusOutHdl, weld::Widget&, void)void PrintDialog::LinkStubFocusOutHdl(void * instance, weld::
Widget& data) { return static_cast<PrintDialog *>(instance
)->FocusOutHdl(data); } void PrintDialog::FocusOutHdl(__attribute__
((unused)) weld::Widget&)
2007{
2008 ActivateHdl(*mxPageEdit);
2009}
2010
2011IMPL_LINK_NOARG(PrintDialog, ActivateHdl, weld::Entry&, bool)bool PrintDialog::LinkStubActivateHdl(void * instance, weld::
Entry& data) { return static_cast<PrintDialog *>(instance
)->ActivateHdl(data); } bool PrintDialog::ActivateHdl(__attribute__
((unused)) weld::Entry&)
2012{
2013 sal_Int32 nPage = mxPageEdit->get_text().toInt32();
2014 if (nPage < 1)
2015 {
2016 nPage = 1;
2017 mxPageEdit->set_text("1");
2018 }
2019 else if (nPage > mnCachedPages)
2020 {
2021 nPage = mnCachedPages;
2022 mxPageEdit->set_text(OUString::number(mnCachedPages));
2023 }
2024 int nNewCurPage = nPage - 1;
2025 if (nNewCurPage != mnCurPage)
2026 {
2027 mnCurPage = nNewCurPage;
2028 maUpdatePreviewIdle.Start();
2029 }
2030 return true;
2031}
2032
2033IMPL_LINK( PrintDialog, SpinModifyHdl, weld::SpinButton&, rEdit, void )void PrintDialog::LinkStubSpinModifyHdl(void * instance, weld
::SpinButton& data) { return static_cast<PrintDialog *
>(instance)->SpinModifyHdl(data); } void PrintDialog::SpinModifyHdl
(weld::SpinButton& rEdit)
2034{
2035 checkControlDependencies();
2036 if (&rEdit == mxNupRowsEdt.get() || &rEdit == mxNupColEdt.get())
2037 {
2038 updateNupFromPages();
2039 }
2040 else if( &rEdit == mxCopyCountField.get() )
2041 {
2042 maPController->setValue( "CopyCount",
2043 makeAny( sal_Int32(mxCopyCountField->get_value()) ) );
2044 maPController->setValue( "Collate",
2045 makeAny( isCollate() ) );
2046 }
2047}
2048
2049IMPL_LINK( PrintDialog, UIOption_CheckHdl, weld::ToggleButton&, i_rBox, void )void PrintDialog::LinkStubUIOption_CheckHdl(void * instance, weld
::ToggleButton& data) { return static_cast<PrintDialog
*>(instance)->UIOption_CheckHdl(data); } void PrintDialog
::UIOption_CheckHdl(weld::ToggleButton& i_rBox)
2050{
2051 PropertyValue* pVal = getValueForWindow( &i_rBox );
2052 if( pVal )
2053 {
2054 makeEnabled( &i_rBox );
2055
2056 bool bVal = i_rBox.get_active();
2057 pVal->Value <<= bVal;
2058
2059 checkOptionalControlDependencies();
2060
2061 // update preview and page settings
2062 maUpdatePreviewNoCacheIdle.Start();
2063 }
2064}
2065
2066IMPL_LINK( PrintDialog, UIOption_RadioHdl, weld::ToggleButton&, i_rBtn, void )void PrintDialog::LinkStubUIOption_RadioHdl(void * instance, weld
::ToggleButton& data) { return static_cast<PrintDialog
*>(instance)->UIOption_RadioHdl(data); } void PrintDialog
::UIOption_RadioHdl(weld::ToggleButton& i_rBtn)
2067{
2068 // this handler gets called for all radiobuttons that get unchecked, too
2069 // however we only want one notification for the new value (that is for
2070 // the button that gets checked)
2071 if( !i_rBtn.get_active() )
2072 return;
2073
2074 PropertyValue* pVal = getValueForWindow( &i_rBtn );
2075 auto it = maControlToNumValMap.find( &i_rBtn );
2076 if( !(pVal && it != maControlToNumValMap.end()) )
2077 return;
2078
2079 makeEnabled( &i_rBtn );
2080
2081 sal_Int32 nVal = it->second;
2082 pVal->Value <<= nVal;
2083
2084 updateOrientationBox();
2085
2086 checkOptionalControlDependencies();
2087
2088 // tdf#41205 give focus to the page range edit if the corresponding radio button was selected
2089 if (pVal->Name == "PrintContent" && mxPageRangesRadioButton->get_active())
2090 mxPageRangeEdit->grab_focus();
2091
2092 // update preview and page settings
2093 maUpdatePreviewNoCacheIdle.Start();
2094}
2095
2096IMPL_LINK( PrintDialog, UIOption_SelectHdl, weld::ComboBox&, i_rBox, void )void PrintDialog::LinkStubUIOption_SelectHdl(void * instance,
weld::ComboBox& data) { return static_cast<PrintDialog
*>(instance)->UIOption_SelectHdl(data); } void PrintDialog
::UIOption_SelectHdl(weld::ComboBox& i_rBox)
2097{
2098 PropertyValue* pVal = getValueForWindow( &i_rBox );
2099 if( !pVal )
2100 return;
2101
2102 makeEnabled( &i_rBox );
2103
2104 sal_Int32 nVal( i_rBox.get_active() );
2105 pVal->Value <<= nVal;
2106
2107 //If we are in impress we start in print slides mode and get a
2108 //maFirstPageSize for slides which are usually landscape mode, if we
2109 //change to notes which are usually in portrait mode, and then visit
2110 //n-up print, we will assume notes are in landscape unless we throw
2111 //away maFirstPageSize when we change page content type
2112 if (pVal->Name == "PageContentType")
2113 maFirstPageSize = Size();
2114
2115 checkOptionalControlDependencies();
2116
2117 // update preview and page settings
2118 maUpdatePreviewNoCacheIdle.Start();
2119}
2120
2121IMPL_LINK( PrintDialog, UIOption_SpinModifyHdl, weld::SpinButton&, i_rBox, void )void PrintDialog::LinkStubUIOption_SpinModifyHdl(void * instance
, weld::SpinButton& data) { return static_cast<PrintDialog
*>(instance)->UIOption_SpinModifyHdl(data); } void PrintDialog
::UIOption_SpinModifyHdl(weld::SpinButton& i_rBox)
2122{
2123 PropertyValue* pVal = getValueForWindow( &i_rBox );
2124 if( pVal )
2125 {
2126 makeEnabled( &i_rBox );
2127
2128 sal_Int64 nVal = i_rBox.get_value();
2129 pVal->Value <<= nVal;
2130
2131 checkOptionalControlDependencies();
2132
2133 // update preview and page settings
2134 maUpdatePreviewNoCacheIdle.Start();
2135 }
2136}
2137
2138IMPL_LINK( PrintDialog, UIOption_EntryModifyHdl, weld::Entry&, i_rBox, void )void PrintDialog::LinkStubUIOption_EntryModifyHdl(void * instance
, weld::Entry& data) { return static_cast<PrintDialog *
>(instance)->UIOption_EntryModifyHdl(data); } void PrintDialog
::UIOption_EntryModifyHdl(weld::Entry& i_rBox)
1
Calling 'PrintDialog::UIOption_EntryModifyHdl'
2139{
2140 PropertyValue* pVal = getValueForWindow( &i_rBox );
2141 if( pVal
1.1
'pVal' is non-null
)
2
Taking true branch
2142 {
2143 makeEnabled( &i_rBox );
2144
2145 OUString aVal( i_rBox.get_text() );
2146 pVal->Value <<= aVal;
2147
2148 checkOptionalControlDependencies();
3
Calling 'PrintDialog::checkOptionalControlDependencies'
2149
2150 // update preview and page settings
2151 maUpdatePreviewNoCacheIdle.Start();
2152 }
2153}
2154
2155void PrintDialog::previewForward()
2156{
2157 sal_Int32 nValue = mxPageEdit->get_text().toInt32() + 1;
2158 if (nValue <= mnCachedPages)
2159 {
2160 mxPageEdit->set_text(OUString::number(nValue));
2161 ActivateHdl(*mxPageEdit);
2162 }
2163}
2164
2165void PrintDialog::previewBackward()
2166{
2167 sal_Int32 nValue = mxPageEdit->get_text().toInt32() - 1;
2168 if (nValue >= 1)
2169 {
2170 mxPageEdit->set_text(OUString::number(nValue));
2171 ActivateHdl(*mxPageEdit);
2172 }
2173}
2174
2175void PrintDialog::previewFirst()
2176{
2177 mxPageEdit->set_text("1");
2178 ActivateHdl(*mxPageEdit);
2179}
2180
2181void PrintDialog::previewLast()
2182{
2183 mxPageEdit->set_text(OUString::number(mnCachedPages));
2184 ActivateHdl(*mxPageEdit);
2185}
2186
2187
2188static OUString getNewLabel(const OUString& aLabel, int i_nCurr, int i_nMax)
2189{
2190 OUString aNewText( aLabel.replaceFirst( "%p", OUString::number( i_nCurr ) ) );
2191 aNewText = aNewText.replaceFirst( "%n", OUString::number( i_nMax ) );
2192
2193 return aNewText;
2194}
2195
2196// PrintProgressDialog
2197PrintProgressDialog::PrintProgressDialog(weld::Window* i_pParent, int i_nMax)
2198 : GenericDialogController(i_pParent, "vcl/ui/printprogressdialog.ui", "PrintProgressDialog")
2199 , mbCanceled(false)
2200 , mnCur(0)
2201 , mnMax(i_nMax)
2202 , mxText(m_xBuilder->weld_label("label"))
2203 , mxProgress(m_xBuilder->weld_progress_bar("progressbar"))
2204 , mxButton(m_xBuilder->weld_button("cancel"))
2205{
2206 if( mnMax < 1 )
2207 mnMax = 1;
2208
2209 maStr = mxText->get_label();
2210
2211 //just multiply largest value by 10 and take the width of that string as
2212 //the max size we will want
2213 mxText->set_label(getNewLabel(maStr, mnMax * 10, mnMax * 10));
2214 mxText->set_size_request(mxText->get_preferred_size().Width(), -1);
2215
2216 //Pick a useful max width
2217 mxProgress->set_size_request(mxProgress->get_approximate_digit_width() * 25, -1);
2218
2219 mxButton->connect_clicked( LINK( this, PrintProgressDialog, ClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<PrintProgressDialog
*>(this), &PrintProgressDialog::LinkStubClickHdl)
);
2220
2221 // after this patch f7157f04fab298423e2c4f6a7e5f8e361164b15f, we have seen the calc Max string (sometimes) look above
2222 // now init to the right start values
2223 mxText->set_label(getNewLabel(maStr, mnCur, mnMax));
2224}
2225
2226PrintProgressDialog::~PrintProgressDialog()
2227{
2228}
2229
2230IMPL_LINK_NOARG(PrintProgressDialog, ClickHdl, weld::Button&, void)void PrintProgressDialog::LinkStubClickHdl(void * instance, weld
::Button& data) { return static_cast<PrintProgressDialog
*>(instance)->ClickHdl(data); } void PrintProgressDialog
::ClickHdl(__attribute__ ((unused)) weld::Button&)
2231{
2232 mbCanceled = true;
2233}
2234
2235void PrintProgressDialog::setProgress( int i_nCurrent )
2236{
2237 mnCur = i_nCurrent;
2238
2239 if( mnMax < 1 )
2240 mnMax = 1;
2241
2242 mxText->set_label(getNewLabel(maStr, mnCur, mnMax));
2243
2244 // here view the dialog, with the right label
2245 mxProgress->set_percentage(mnCur*100/mnMax);
2246}
2247
2248void PrintProgressDialog::tick()
2249{
2250 if( mnCur < mnMax )
2251 setProgress( ++mnCur );
2252}
2253
2254/* vim:set shiftwidth=4 softtabstop=4 expandtab: */