1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SW_INC_PRINTDATA_HXX
20 #define INCLUDED_SW_INC_PRINTDATA_HXX
22 #include <sal/types.h>
23 #include <rtl/ustring.hxx>
24 #include <vcl/print.hxx>
25 #include <sfx2/objsh.hxx>
27 #include <o3tl/sorted_vector.hxx>
35 class SetGetExpFields
;
37 class SwViewOptionAdjust_Impl
;
41 /** this must match the definitions in css::text::NotePrintMode */
42 enum class SwPostItMode
54 const SwRenderData
* m_pRenderData
; // not owner
58 bool m_bPrintGraphic
, m_bPrintControl
, m_bPrintPageBackground
,
60 //#i81434# - printing of hidden text
61 m_bPrintHiddenText
, m_bPrintTextPlaceholder
,
62 m_bPrintLeftPages
, m_bPrintRightPages
, m_bPrintProspect
,
68 SwPostItMode m_nPrintPostIts
;
73 m_pRenderData
= nullptr;
79 m_bPrintPageBackground
=
80 m_bPrintEmptyPages
= true;
87 m_bPrintTextPlaceholder
= false;
89 m_nPrintPostIts
= SwPostItMode::NONE
;
92 virtual ~SwPrintData() {}
94 SwPrintData(SwPrintData
const &) = default;
95 SwPrintData(SwPrintData
&&) = default;
96 SwPrintData
& operator =(SwPrintData
const &) = default;
97 SwPrintData
& operator =(SwPrintData
&&) = default;
99 bool operator==(const SwPrintData
& rData
)const
102 m_bPrintGraphic
== rData
.m_bPrintGraphic
&&
103 m_bPrintControl
== rData
.m_bPrintControl
&&
104 m_bPrintPageBackground
== rData
.m_bPrintPageBackground
&&
105 m_bPrintBlackFont
== rData
.m_bPrintBlackFont
&&
106 m_bPrintLeftPages
== rData
.m_bPrintLeftPages
&&
107 m_bPrintRightPages
== rData
.m_bPrintRightPages
&&
108 m_bPrintProspect
== rData
.m_bPrintProspect
&&
109 m_bPrintProspectRTL
== rData
.m_bPrintProspectRTL
&&
110 m_bPaperFromSetup
== rData
.m_bPaperFromSetup
&&
111 m_bPrintEmptyPages
== rData
.m_bPrintEmptyPages
&&
112 m_nPrintPostIts
== rData
.m_nPrintPostIts
&&
113 m_sFaxName
== rData
.m_sFaxName
&&
114 m_bPrintHiddenText
== rData
.m_bPrintHiddenText
&&
115 m_bPrintTextPlaceholder
== rData
.m_bPrintTextPlaceholder
;
118 /** Note: in the context where this class is used the pointers should always be valid
119 during the lifetime of this object */
120 const SwRenderData
& GetRenderData() const { return *m_pRenderData
; }
121 void SetRenderData( const SwRenderData
*pData
) { m_pRenderData
= pData
; }
123 bool IsPrintGraphic() const { return m_bPrintGraphic
; }
124 bool IsPrintControl() const { return m_bPrintControl
; }
125 bool IsPrintLeftPage() const { return m_bPrintLeftPages
; }
126 bool IsPrintRightPage() const { return m_bPrintRightPages
; }
127 bool IsPaperFromSetup() const { return m_bPaperFromSetup
; }
128 bool IsPrintEmptyPages() const { return m_bPrintEmptyPages
; }
129 bool IsPrintProspect() const { return m_bPrintProspect
; }
130 bool IsPrintProspectRTL() const { return m_bPrintProspectRTL
; }
131 bool IsPrintPageBackground() const { return m_bPrintPageBackground
; }
132 bool IsPrintBlackFont() const { return m_bPrintBlackFont
; }
133 SwPostItMode
GetPrintPostIts() const { return m_nPrintPostIts
; }
134 const OUString
& GetFaxName() const { return m_sFaxName
; }
135 bool IsPrintHiddenText() const { return m_bPrintHiddenText
; }
136 bool IsPrintTextPlaceholder() const { return m_bPrintTextPlaceholder
; }
138 void SetPrintGraphic( bool b
) { doSetModified(); m_bPrintGraphic
= b
; }
139 void SetPrintControl( bool b
) { doSetModified(); m_bPrintControl
= b
; }
140 void SetPrintLeftPage( bool b
) { doSetModified(); m_bPrintLeftPages
= b
; }
141 void SetPrintRightPage( bool b
) { doSetModified(); m_bPrintRightPages
= b
; }
142 void SetPaperFromSetup( bool b
) { doSetModified(); m_bPaperFromSetup
= b
; }
143 void SetPrintEmptyPages( bool b
) { doSetModified(); m_bPrintEmptyPages
= b
; }
144 void SetPrintPostIts( SwPostItMode n
) { doSetModified(); m_nPrintPostIts
= n
; }
145 void SetPrintProspect( bool b
) { doSetModified(); m_bPrintProspect
= b
; }
146 void SetPrintProspect_RTL( bool b
) { doSetModified(); m_bPrintProspectRTL
= b
; }
147 void SetPrintPageBackground( bool b
) { doSetModified(); m_bPrintPageBackground
= b
; }
148 void SetPrintBlackFont( bool b
) { doSetModified(); m_bPrintBlackFont
= b
; }
149 void SetFaxName( const OUString
& rSet
) { m_sFaxName
= rSet
; }
150 void SetPrintHiddenText( bool b
) { doSetModified(); m_bPrintHiddenText
= b
; }
151 void SetPrintTextPlaceholder( bool b
) { doSetModified(); m_bPrintTextPlaceholder
= b
; }
153 virtual void doSetModified () {}
156 class SwPrintUIOptions final
: public vcl::PrinterOptionsHelper
158 VclPtr
< OutputDevice
> m_pLast
;
159 const SwPrintData
& m_rDefaultPrintData
;
162 SwPrintUIOptions( sal_uInt16 nCurrentPage
, bool bWeb
, bool bSwSrcView
, bool bHasSelection
, bool bHasPostIts
, const SwPrintData
&rDefaultPrintData
);
163 virtual ~SwPrintUIOptions();
165 bool processPropertiesAndCheckFormat( const css::uno::Sequence
< css::beans::PropertyValue
>& i_rNewProp
);
167 bool IsPrintFormControls() const { return getBoolValue( "PrintControls", m_rDefaultPrintData
.m_bPrintControl
); }
168 bool IsPrintPageBackground() const { return getBoolValue( "PrintPageBackground", m_rDefaultPrintData
.m_bPrintPageBackground
); }
169 bool IsPrintProspect() const { return getBoolValue( "PrintProspect", m_rDefaultPrintData
.m_bPrintProspect
); }
170 bool IsPrintProspectRTL() const { return getIntValue( "PrintProspectRTL", m_rDefaultPrintData
.m_bPrintProspectRTL
? 1 : 0 ) != 0; }
171 bool IsPrintTextPlaceholders() const { return getBoolValue( "PrintTextPlaceholder", m_rDefaultPrintData
.m_bPrintTextPlaceholder
); }
172 bool IsPrintHiddenText() const { return getBoolValue( "PrintHiddenText", m_rDefaultPrintData
.m_bPrintHiddenText
); }
173 bool IsPrintWithBlackTextColor() const { return getBoolValue( "PrintBlackFonts", m_rDefaultPrintData
.m_bPrintBlackFont
); }
174 SwPostItMode
GetPrintPostItsType() const { return static_cast< SwPostItMode
>(getIntValue( "PrintAnnotationMode", static_cast<sal_uInt16
>(m_rDefaultPrintData
.m_nPrintPostIts
) )); }
175 bool IsPaperFromSetup() const { return getBoolValue( "PrintPaperFromSetup", m_rDefaultPrintData
.m_bPaperFromSetup
); }
177 bool IsPrintLeftPages() const;
178 bool IsPrintRightPages() const;
179 bool IsPrintEmptyPages( bool bIsPDFExport
) const;
180 bool IsPrintGraphics() const;
183 /** A class that stores temporary data that is needed for rendering the document.
184 Usually this data is created when 'getRendererCount' is called and
185 and it is used in the 'render' function of that same interface */
188 /** pages valid for printing (according to the current settings)
189 This set of pages does NOT depend on the 'PageRange' that is used as a printing option! */
190 o3tl::sorted_vector
< sal_Int32
> m_aValidPages
; ///< the set of possible pages (see StringRangeEnumerator::getRangesFromString )
192 /// printer paper tray to use for each of the m_aValidPages above
193 std::map
< sal_Int32
, sal_Int32
> m_aPrinterPaperTrays
;
195 /** vector of pages and their order to be printed (duplicates and any order allowed!)
196 (see 'render' in unotxdoc.cxx)
197 negative entry indicates the page to be printed is from the post-it doc */
198 std::vector
< sal_Int32
> m_aPagesToPrint
;
200 /** for prospect printing: the pairs of pages to be printed together on a single prospect page.
201 -1 indicates a half page to be left empty. */
202 std::vector
< std::pair
< sal_Int32
, sal_Int32
> > m_aPagePairs
;
204 OUString m_aPageRange
;
206 /** temp print document -- must live longer than m_pViewOptionAdjust!
207 also this is a Lock and not a Ref because Ref does not delete the doc */
208 SfxObjectShellLock m_xTempDocShell
;
210 /// the view options to be applied for printing
211 std::unique_ptr
<SwViewOptionAdjust_Impl
> m_pViewOptionAdjust
;
213 std::unique_ptr
<SwPrintData
> m_pPrtOptions
;
217 // PostIt relevant data
218 /// an array of "SetGetExpField *" sorted by page and line numbers
219 std::unique_ptr
<SetGetExpFields
> m_pPostItFields
;
220 /// this contains a SwDoc with the post-it content
221 std::unique_ptr
<SwViewShell
> m_pPostItShell
;
227 bool HasPostItData() const { return m_pPostItShell
!= nullptr; }
228 void CreatePostItData( SwDoc
& rDoc
, const SwViewOption
*pViewOpt
, OutputDevice
*pOutDev
);
229 void DeletePostItData();
231 SfxObjectShellLock
const& GetTempDocShell() const { return m_xTempDocShell
;}
232 void SetTempDocShell(SfxObjectShellLock
const&);
234 bool IsViewOptionAdjust() const { return m_pViewOptionAdjust
!= nullptr; }
235 bool NeedNewViewOptionAdjust( const SwViewShell
& ) const;
236 void ViewOptionAdjustStart( SwViewShell
&rSh
, const SwViewOption
&rViewOptions
);
237 void ViewOptionAdjust( SwPrintData
const* const pPrtOptions
, bool setShowPlaceHoldersInPDF
);
238 void ViewOptionAdjustStop();
239 void ViewOptionAdjustCrashPreventionKludge();
241 bool HasSwPrtOptions() const { return m_pPrtOptions
!= nullptr; }
242 SwPrintData
const* GetSwPrtOptions() const { return m_pPrtOptions
.get(); }
243 void MakeSwPrtOptions( SwDocShell
const*const pDocShell
,
244 SwPrintUIOptions
const*const pOpt
, bool const bIsPDFExport
);
246 typedef std::vector
< std::pair
< sal_Int32
, sal_Int32
> > PagePairsVec_t
;
248 o3tl::sorted_vector
< sal_Int32
> & GetValidPagesSet() { return m_aValidPages
; }
249 const o3tl::sorted_vector
< sal_Int32
> & GetValidPagesSet() const { return m_aValidPages
; }
251 /** a map for printer paper tray numbers to use for each document page
252 a value of -1 for the tray means that there is no specific tray defined */
253 std::map
< sal_Int32
, sal_Int32
>& GetPrinterPaperTrays() { return m_aPrinterPaperTrays
; }
254 const std::map
< sal_Int32
, sal_Int32
>& GetPrinterPaperTrays() const { return m_aPrinterPaperTrays
; }
256 /** used for 'normal' printing
257 A page value of 0 as entry indicates that this page is not from the document but
258 from the post-it document. (See also GetPostItStartFrame below) */
259 std::vector
< sal_Int32
> & GetPagesToPrint() { return m_aPagesToPrint
; }
260 const std::vector
< sal_Int32
> & GetPagesToPrint() const { return m_aPagesToPrint
; }
262 /// used for prospect printing only
263 PagePairsVec_t
& GetPagePairsForProspectPrinting() { return m_aPagePairs
; }
264 const PagePairsVec_t
& GetPagePairsForProspectPrinting() const { return m_aPagePairs
; }
266 const OUString
& GetPageRange() const { return m_aPageRange
; }
267 void SetPageRange( const OUString
&rRange
) { m_aPageRange
= rRange
; }
272 void InitPrintOptionsFromApplication(SwPrintData
& o_rData
, bool const bWeb
);
276 #endif // INCLUDED_SW_INC_PRINTDATA_HXX
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */