Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/printdlg.hxx
Line
Count
Source
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
#pragma once
21
22
#include <vcl/bitmap.hxx>
23
#include <vcl/gdimtf.hxx>
24
#include <vcl/idle.hxx>
25
#include <vcl/print.hxx>
26
#include <vcl/weld/Button.hxx>
27
#include <vcl/weld/CheckButton.hxx>
28
#include <vcl/weld/ComboBox.hxx>
29
#include <vcl/weld/DialogController.hxx>
30
#include <vcl/weld/Entry.hxx>
31
#include <vcl/weld/Expander.hxx>
32
#include <vcl/weld/Frame.hxx>
33
#include <vcl/weld/Image.hxx>
34
#include <vcl/weld/Label.hxx>
35
#include <vcl/weld/MetricSpinButton.hxx>
36
#include <vcl/weld/Notebook.hxx>
37
#include <vcl/weld/ProgressBar.hxx>
38
#include <vcl/weld/RadioButton.hxx>
39
#include <vcl/weld/ScrolledWindow.hxx>
40
#include <vcl/weld/SpinButton.hxx>
41
#include <vcl/weld/customweld.hxx>
42
43
#include <map>
44
45
namespace vcl
46
{
47
    class PrintDialog final : public weld::GenericDialogController
48
    {
49
        friend class MoreOptionsDialog;
50
    public:
51
52
        class PrintPreviewWindow final : public weld::CustomWidgetController
53
        {
54
            PrintDialog*        mpDialog;
55
            GDIMetaFile         maMtf;
56
            Size                maOrigSize;
57
            Size                maPreviewSize;
58
            sal_Int32           mnDPIX;
59
            sal_Int32           mnDPIY;
60
            Bitmap              maPreviewBitmap;
61
            OUString            maReplacementString;
62
            bool                mbGreyscale;
63
64
            OUString            maHorzText;
65
            OUString            maVertText;
66
67
            void preparePreviewBitmap();
68
69
        public:
70
            PrintPreviewWindow(PrintDialog* pDialog);
71
            virtual ~PrintPreviewWindow() override;
72
73
            virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
74
            virtual bool Command( const CommandEvent& ) override;
75
            virtual void Resize() override;
76
77
            void setPreview( const GDIMetaFile&, const Size& i_rPaperSize,
78
                             std::u16string_view i_rPaperName,
79
                             const OUString& i_rNoPageString,
80
                             sal_Int32 i_nDPIX, sal_Int32 i_nDPIY,
81
                             bool i_bGreyscale
82
                            );
83
        };
84
85
        class ShowNupOrderWindow final : public weld::CustomWidgetController
86
        {
87
            NupOrderType mnOrderMode;
88
            int mnRows;
89
            int mnColumns;
90
        public:
91
            ShowNupOrderWindow();
92
93
            virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
94
95
            virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
96
97
            void setValues( NupOrderType i_nOrderMode, int i_nColumns, int i_nRows )
98
0
            {
99
0
                mnOrderMode = i_nOrderMode;
100
0
                mnRows = i_nRows;
101
0
                mnColumns = i_nColumns;
102
0
                Invalidate();
103
0
            }
104
        };
105
106
        PrintDialog(weld::Window*, std::shared_ptr<PrinterController> );
107
        virtual ~PrintDialog() override;
108
109
        bool isPrintToFile() const;
110
        bool isCollate() const;
111
        bool isSingleJobs() const;
112
        bool hasPreview() const;
113
114
        void setPaperSizes();
115
        void previewForward();
116
        void previewBackward();
117
        void previewFirst();
118
        void previewLast();
119
120
    private:
121
122
        std::unique_ptr<weld::Builder>          mxCustomOptionsUIBuilder;
123
124
        std::shared_ptr<PrinterController>      maPController;
125
126
        std::unique_ptr<weld::Notebook>         mxTabCtrl;
127
        std::unique_ptr<weld::ScrolledWindow>   mxScrolledWindow;
128
        std::unique_ptr<weld::Frame>            mxPageLayoutFrame;
129
        std::unique_ptr<weld::ComboBox>         mxPrinters;
130
        std::unique_ptr<weld::Label>            mxStatusTxt;
131
        std::unique_ptr<weld::Button>           mxSetupButton;
132
133
        std::unique_ptr<weld::SpinButton>       mxCopyCountField;
134
        std::unique_ptr<weld::CheckButton>      mxCollateBox;
135
        std::unique_ptr<weld::Image>            mxCollateImage;
136
        std::unique_ptr<weld::Entry>            mxPageRangeEdit;
137
        std::unique_ptr<weld::RadioButton>      mxPageRangesRadioButton;
138
        std::unique_ptr<weld::ComboBox>         mxPaperSidesBox;
139
        std::unique_ptr<weld::CheckButton>      mxSingleJobsBox;
140
        std::unique_ptr<weld::CheckButton>      mxReverseOrderBox;
141
142
        std::unique_ptr<weld::Button>           mxOKButton;
143
        std::unique_ptr<weld::Button>           mxCancelButton;
144
145
        std::unique_ptr<weld::Button>           mxBackwardBtn;
146
        std::unique_ptr<weld::Button>           mxForwardBtn;
147
        std::unique_ptr<weld::Button>           mxFirstBtn;
148
        std::unique_ptr<weld::Button>           mxLastBtn;
149
150
        std::unique_ptr<weld::CheckButton>      mxPreviewBox;
151
        std::unique_ptr<weld::Label>            mxNumPagesText;
152
        std::unique_ptr<PrintPreviewWindow>     mxPreview;
153
        std::unique_ptr<weld::CustomWeld>       mxPreviewWindow;
154
        std::unique_ptr<weld::Entry>            mxPageEdit;
155
156
        std::unique_ptr<weld::RadioButton>      mxPagesBtn;
157
        std::unique_ptr<weld::RadioButton>      mxBrochureBtn;
158
        std::unique_ptr<weld::Label>            mxPagesBoxTitleTxt;
159
        std::unique_ptr<weld::ComboBox>         mxNupPagesBox;
160
161
        // controls for "Custom" page mode
162
        std::unique_ptr<weld::Label>            mxNupNumPagesTxt;
163
        std::unique_ptr<weld::SpinButton>       mxNupColEdt;
164
        std::unique_ptr<weld::Label>            mxNupTimesTxt;
165
        std::unique_ptr<weld::SpinButton>       mxNupRowsEdt;
166
        std::unique_ptr<weld::Label>            mxPageMarginTxt1;
167
        std::unique_ptr<weld::MetricSpinButton> mxPageMarginEdt;
168
        std::unique_ptr<weld::Label>            mxPageMarginTxt2;
169
        std::unique_ptr<weld::Label>            mxSheetMarginTxt1;
170
        std::unique_ptr<weld::MetricSpinButton> mxSheetMarginEdt;
171
        std::unique_ptr<weld::Label>            mxSheetMarginTxt2;
172
        std::unique_ptr<weld::ComboBox>         mxPaperSizeBox;
173
        std::unique_ptr<weld::ComboBox>         mxOrientationBox;
174
175
        // page order ("left to right, then down")
176
        std::unique_ptr<weld::Label>            mxNupOrderTxt;
177
        std::unique_ptr<weld::ComboBox>         mxNupOrderBox;
178
        std::unique_ptr<ShowNupOrderWindow>     mxNupOrder;
179
        std::unique_ptr<weld::CustomWeld>       mxNupOrderWin;
180
        /// border around each page
181
        std::unique_ptr<weld::CheckButton>      mxBorderCB;
182
        std::unique_ptr<weld::Expander>         mxRangeExpander;
183
        std::unique_ptr<weld::Expander>         mxLayoutExpander;
184
        std::unique_ptr<weld::Widget>           mxCustom;
185
186
        OUString                                maPrintToFileText;
187
        OUString                                maPrintText;
188
        OUString                                maDefPrtText;
189
190
        OUString                                maPageStr;
191
        OUString                                maNoPageStr;
192
        OUString                                maNoPreviewStr;
193
        sal_Int32                               mnCurPage;
194
        sal_Int32                               mnCachedPages;
195
196
        std::vector<std::unique_ptr<weld::Widget>>
197
                                                maExtraControls;
198
199
        std::map<weld::Widget*, OUString>
200
                                                maControlToPropertyMap;
201
        std::map<OUString, std::vector<weld::Widget*>>
202
                                                maPropertyToWindowMap;
203
        std::map<weld::Widget*, sal_Int32>
204
                                                maControlToNumValMap;
205
206
        Size                                    maNupPortraitSize;
207
        Size                                    maNupLandscapeSize;
208
        /// internal, used for automatic Nup-Portrait/landscape
209
        Size                                    maFirstPageSize;
210
211
        bool                                    mbShowLayoutFrame;
212
        // cache is allowed, unless explicitly disabled for this update
213
        bool mbUseCacheForPreview = true;
214
215
        Paper                                   mePaper;
216
217
        Size                                    maCustomPaperSize;
218
        bool                                    mbHasCustomPaperEntry;
219
220
        // Paper size from combobox in 1/100th mm; avoids PixelToLogic issues.
221
        Size                                    maSelectedPaperSize;
222
223
        Idle maUpdatePreviewIdle;
224
        DECL_LINK(updatePreviewIdle, Timer*, void);
225
226
        DECL_LINK(ClickOKCancelHdl, weld::Button&, void);
227
        DECL_LINK(ClickForwardHdl, weld::Button&, void);
228
        DECL_LINK(ClickBackwardHdl, weld::Button&, void);
229
        DECL_LINK(ClickFirstHdl, weld::Button&, void);
230
        DECL_LINK(ClickLastHdl, weld::Button&, void);
231
        DECL_LINK(ClickSetupHdl, weld::Button&, void);
232
        DECL_LINK(SelectPrinterHdl, weld::ComboBox&, void);
233
        DECL_LINK(SelectPaperSidesHdl, weld::ComboBox&, void);
234
        DECL_LINK(SelectOrientationHdl, weld::ComboBox&, void);
235
        DECL_LINK(SelectNupOrderHdl, weld::ComboBox&, void);
236
        DECL_LINK(SelectNupPagesHdl, weld::ComboBox&, void);
237
        DECL_LINK(SelectPaperSizeHdl, weld::ComboBox&, void);
238
        DECL_LINK( ActivateHdl, weld::Entry&, bool );
239
        DECL_LINK( FocusOutHdl, weld::Widget&, void );
240
        DECL_LINK( SpinModifyHdl, weld::SpinButton&, void );
241
        DECL_LINK( MetricSpinModifyHdl, weld::MetricSpinButton&, void );
242
        DECL_LINK(TogglePreviewHdl, weld::Toggleable&, void);
243
        DECL_LINK(ToggleBorderHdl, weld::Toggleable&, void);
244
        DECL_LINK(ToggleSingleJobsHdl, weld::Toggleable&, void);
245
        DECL_LINK(ToggleCollateHdl, weld::Toggleable&, void);
246
        DECL_LINK(ToggleReverseOrderHdl, weld::Toggleable&, void);
247
        DECL_LINK(ToggleBrochureHdl, weld::Toggleable&, void);
248
249
        DECL_LINK( UIOption_CheckHdl, weld::Toggleable&, void );
250
        DECL_LINK( UIOption_RadioHdl, weld::Toggleable&, void );
251
        DECL_LINK( UIOption_SelectHdl, weld::ComboBox&, void );
252
        DECL_LINK( UIOption_SpinModifyHdl, weld::SpinButton&, void );
253
        DECL_LINK( UIOption_EntryModifyHdl, weld::Entry&, void );
254
255
        css::beans::PropertyValue* getValueForWindow(weld::Widget*) const;
256
257
        void ImplDestroy();
258
        void preparePreview( bool i_bMayUseCache );
259
        void schedulePreviewUpdate(bool i_bMayUseCache);
260
        void setupPaperSidesBox();
261
        void storeToSettings();
262
        void readFromSettings();
263
        void setPaperOrientation( Orientation eOrientation, bool fromUser );
264
        void updateOrientationBox( bool bAutomatic = true );
265
        void updatePageSize( int nOrientation );
266
        void updatePageRange( const sal_Int32 nPages );
267
        bool hasOrientationChanged() const;
268
        void setPreviewText();
269
        void updatePrinterText();
270
        void checkControlDependencies();
271
        void checkOptionalControlDependencies();
272
        void makeEnabled( weld::Widget* );
273
        void updateWindowFromProperty( const OUString& );
274
        void initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& );
275
        void showAdvancedControls( bool );
276
        void updateNup( bool i_bMayUseCache = true );
277
        void updateNupFromPages( bool i_bMayUseCache = true );
278
        void enableNupControls( bool bEnable );
279
        void setupOptionalUI();
280
        Size const & getJobPageSize();
281
282
    };
283
284
    class PrintProgressDialog final : public weld::GenericDialogController
285
    {
286
        OUString            maStr;
287
        bool                mbCanceled;
288
        sal_Int32           mnCur;
289
        sal_Int32           mnMax;
290
291
        std::unique_ptr<weld::Label> mxText;
292
        std::unique_ptr<weld::ProgressBar> mxProgress;
293
        std::unique_ptr<weld::Button> mxButton;
294
295
        DECL_LINK( ClickHdl, weld::Button&, void );
296
297
    public:
298
        PrintProgressDialog(weld::Window* i_pParent, int i_nMax);
299
        virtual ~PrintProgressDialog() override;
300
0
        bool isCanceled() const { return mbCanceled; }
301
        void setProgress( int i_nCurrent );
302
        void tick();
303
    };
304
}
305
306
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */