xref: /trunk/main/sw/inc/printdata.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef SW_PRINTDATA_HXX
24 #define SW_PRINTDATA_HXX
25 
26 
27 #include <sal/types.h>
28 #include <rtl/ustring.hxx>
29 #include <vcl/print.hxx>
30 
31 #include <set>
32 #include <map>
33 #include <vector>
34 #include <utility>
35 
36 class SwPageFrm;
37 class SwDoc;
38 class SwDocShell;
39 class ViewShell;
40 class _SetGetExpFlds;
41 class SwViewOption;
42 class OutputDevice;
43 class SwViewOptionAdjust_Impl;
44 class SwPrtOptions;
45 class ViewShell;
46 class SfxViewShell;
47 
48 // forward declarations
49 class SwPrintUIOptions;
50 class SwRenderData;
51 
52 ////////////////////////////////////////////////////////////
53 
54 
55 class SwPrintData
56 {
57     const SwPrintUIOptions *    m_pPrintUIOptions;  // not owner
58     const SwRenderData *        m_pRenderData;      // not owner
59 
60 public:
61 
62     sal_Bool bPrintGraphic, bPrintTable, bPrintDraw, bPrintControl, bPrintPageBackground,
63              bPrintBlackFont,
64              //#i81434# - printing of hidden text
65              bPrintHiddenText, bPrintTextPlaceholder,
66              bPrintLeftPages, bPrintRightPages, bPrintReverse, bPrintProspect,
67              bPrintProspectRTL,
68              bPrintSingleJobs, bPaperFromSetup,
69              // --> FME 2005-12-13 #b6354161# Print empty pages
70              bPrintEmptyPages,
71              // <--
72              // #i56195# no field update while printing mail merge documents
73              bUpdateFieldsInPrinting,
74              bModified;
75 
76     sal_Int16           nPrintPostIts;
77     rtl::OUString       sFaxName;
78 
SwPrintData()79     SwPrintData()
80     {
81         m_pPrintUIOptions       = NULL;
82         m_pRenderData        = NULL;
83 
84         bPrintGraphic           =
85         bPrintTable             =
86         bPrintDraw              =
87         bPrintControl           =
88         bPrintLeftPages         =
89         bPrintRightPages        =
90         bPrintPageBackground    =
91         bPrintEmptyPages        =
92         bUpdateFieldsInPrinting = sal_True;
93 
94         bPaperFromSetup         =
95         bPrintReverse           =
96         bPrintProspect          =
97         bPrintProspectRTL       =
98         bPrintSingleJobs        =
99         bModified               =
100         bPrintBlackFont         =
101         bPrintHiddenText        =
102         bPrintTextPlaceholder   = sal_False;
103 
104         nPrintPostIts           = 0;
105     }
106 
~SwPrintData()107     virtual ~SwPrintData() {}
108 
operator ==(const SwPrintData & rData) const109     sal_Bool operator==(const SwPrintData& rData)const
110     {
111         return
112         bPrintGraphic       ==   rData.bPrintGraphic        &&
113         bPrintTable         ==   rData.bPrintTable          &&
114         bPrintDraw          ==   rData.bPrintDraw           &&
115         bPrintControl       ==   rData.bPrintControl        &&
116         bPrintPageBackground==   rData.bPrintPageBackground &&
117         bPrintBlackFont     ==   rData.bPrintBlackFont      &&
118         bPrintLeftPages     ==   rData.bPrintLeftPages      &&
119         bPrintRightPages    ==   rData.bPrintRightPages     &&
120         bPrintReverse       ==   rData.bPrintReverse        &&
121         bPrintProspect      ==   rData.bPrintProspect       &&
122         bPrintProspectRTL   ==   rData.bPrintProspectRTL    &&
123         bPrintSingleJobs    ==   rData.bPrintSingleJobs     &&
124         bPaperFromSetup     ==   rData.bPaperFromSetup      &&
125         bPrintEmptyPages    ==   rData.bPrintEmptyPages     &&
126         bUpdateFieldsInPrinting == rData.bUpdateFieldsInPrinting &&
127         nPrintPostIts       ==   rData.nPrintPostIts        &&
128         sFaxName            ==   rData.sFaxName             &&
129         bPrintHiddenText    ==   rData.bPrintHiddenText     &&
130         bPrintTextPlaceholder   ==   rData.bPrintTextPlaceholder;
131     }
132 
133     // Note: in the context where this class ist used the pointers should always be valid
134     // during the lifetime of this object
GetPrintUIOptions() const135     const SwPrintUIOptions &    GetPrintUIOptions() const       { return *m_pPrintUIOptions; }
GetRenderData() const136     const SwRenderData &        GetRenderData() const           { return *m_pRenderData; }
SetPrintUIOptions(const SwPrintUIOptions * pOpt)137     void  SetPrintUIOptions( const SwPrintUIOptions *pOpt )     { m_pPrintUIOptions = pOpt; }
SetRenderData(const SwRenderData * pData)138     void  SetRenderData( const SwRenderData *pData )            { m_pRenderData = pData; }
139 
IsPrintGraphic() const140     sal_Bool IsPrintGraphic() const             { return bPrintGraphic; }
IsPrintTable() const141     sal_Bool IsPrintTable() const               { return bPrintTable; }
IsPrintDraw() const142     sal_Bool IsPrintDraw() const                { return bPrintDraw; }
IsPrintControl() const143     sal_Bool IsPrintControl() const             { return bPrintControl; }
IsPrintLeftPage() const144     sal_Bool IsPrintLeftPage() const            { return bPrintLeftPages; }
IsPrintRightPage() const145     sal_Bool IsPrintRightPage() const           { return bPrintRightPages; }
IsPrintReverse() const146     sal_Bool IsPrintReverse() const             { return bPrintReverse; }
IsPaperFromSetup() const147     sal_Bool IsPaperFromSetup() const           { return bPaperFromSetup; }
IsPrintEmptyPages() const148     sal_Bool IsPrintEmptyPages() const          { return bPrintEmptyPages; }
IsPrintProspect() const149     sal_Bool IsPrintProspect() const            { return bPrintProspect; }
IsPrintProspectRTL() const150     sal_Bool IsPrintProspectRTL() const         { return bPrintProspectRTL; }
IsPrintPageBackground() const151     sal_Bool IsPrintPageBackground() const      { return bPrintPageBackground; }
IsPrintBlackFont() const152     sal_Bool IsPrintBlackFont() const           { return bPrintBlackFont; }
IsPrintSingleJobs() const153     sal_Bool IsPrintSingleJobs() const          { return bPrintSingleJobs; }
GetPrintPostIts() const154     sal_Int16 GetPrintPostIts() const           { return nPrintPostIts; }
GetFaxName() const155     const rtl::OUString GetFaxName() const      { return sFaxName; }
IsPrintHiddenText() const156     sal_Bool IsPrintHiddenText() const          { return bPrintHiddenText; }
IsPrintTextPlaceholder() const157     sal_Bool IsPrintTextPlaceholder() const     { return bPrintTextPlaceholder; }
158 
SetPrintGraphic(sal_Bool b)159     void SetPrintGraphic( sal_Bool b )              { doSetModified(); bPrintGraphic = b; }
SetPrintTable(sal_Bool b)160     void SetPrintTable( sal_Bool b )                { doSetModified(); bPrintTable = b; }
SetPrintDraw(sal_Bool b)161     void SetPrintDraw( sal_Bool b )                 { doSetModified(); bPrintDraw = b; }
SetPrintControl(sal_Bool b)162     void SetPrintControl( sal_Bool b )              { doSetModified(); bPrintControl = b; }
SetPrintLeftPage(sal_Bool b)163     void SetPrintLeftPage( sal_Bool b )             { doSetModified(); bPrintLeftPages = b; }
SetPrintRightPage(sal_Bool b)164     void SetPrintRightPage( sal_Bool b )            { doSetModified(); bPrintRightPages = b; }
SetPrintReverse(sal_Bool b)165     void SetPrintReverse( sal_Bool b )              { doSetModified(); bPrintReverse = b; }
SetPaperFromSetup(sal_Bool b)166     void SetPaperFromSetup( sal_Bool b )            { doSetModified(); bPaperFromSetup = b; }
SetPrintEmptyPages(sal_Bool b)167     void SetPrintEmptyPages( sal_Bool b )           { doSetModified(); bPrintEmptyPages = b; }
SetPrintPostIts(sal_Int16 n)168     void SetPrintPostIts( sal_Int16 n )             { doSetModified(); nPrintPostIts = n; }
SetPrintProspect(sal_Bool b)169     void SetPrintProspect( sal_Bool b )             { doSetModified(); bPrintProspect = b; }
SetPrintProspect_RTL(sal_Bool b)170     void SetPrintProspect_RTL( sal_Bool b )         { doSetModified(); bPrintProspectRTL = b; }
SetPrintPageBackground(sal_Bool b)171     void SetPrintPageBackground( sal_Bool b )       { doSetModified(); bPrintPageBackground = b; }
SetPrintBlackFont(sal_Bool b)172     void SetPrintBlackFont( sal_Bool b )            { doSetModified(); bPrintBlackFont = b; }
SetPrintSingleJobs(sal_Bool b)173     void SetPrintSingleJobs( sal_Bool b )           { doSetModified(); bPrintSingleJobs = b; }
SetFaxName(const rtl::OUString & rSet)174     void SetFaxName( const rtl::OUString& rSet )    { sFaxName = rSet; }
SetPrintHiddenText(sal_Bool b)175     void SetPrintHiddenText( sal_Bool b )           { doSetModified(); bPrintHiddenText = b; }
SetPrintTextPlaceholder(sal_Bool b)176     void SetPrintTextPlaceholder( sal_Bool b )      { doSetModified(); bPrintTextPlaceholder = b; }
177 
doSetModified()178     virtual void doSetModified () { bModified = sal_True;}
179 };
180 
181 
182 ////////////////////////////////////////////////////////////
183 
184 
185 class SwPrintUIOptions : public vcl::PrinterOptionsHelper
186 {
187     OutputDevice* m_pLast;
188     const SwPrintData & m_rDefaultPrintData;
189 
190 public:
191     SwPrintUIOptions( bool bWeb, bool bSwSrcView, bool bHasSelection, bool bHasPostIts, const SwPrintData &rDefaultPrintData );
192     virtual ~SwPrintUIOptions();
193 
194     bool processPropertiesAndCheckFormat( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& i_rNewProp );
195 
IsPrintFormControls() const196     bool IsPrintFormControls() const            { return getBoolValue( "PrintControls",        m_rDefaultPrintData.bPrintControl ); }
IsPrintPageBackground() const197     bool IsPrintPageBackground() const          { return getBoolValue( "PrintPageBackground",  m_rDefaultPrintData.bPrintPageBackground ); }
IsPrintProspect() const198     bool IsPrintProspect() const                { return getBoolValue( "PrintProspect",        m_rDefaultPrintData.bPrintProspect ); }
IsPrintProspectRTL() const199     bool IsPrintProspectRTL() const             { return getIntValue( "PrintProspectRTL",      m_rDefaultPrintData.bPrintProspectRTL ) ? true : false; }
IsPrintTextPlaceholders() const200     bool IsPrintTextPlaceholders() const        { return getBoolValue( "PrintTextPlaceholder", m_rDefaultPrintData.bPrintTextPlaceholder ); }
IsPrintHiddenText() const201     bool IsPrintHiddenText() const              { return getBoolValue( "PrintHiddenText",      m_rDefaultPrintData.bPrintHiddenText ); }
IsPrintWithBlackTextColor() const202     bool IsPrintWithBlackTextColor() const      { return getBoolValue( "PrintBlackFonts",      m_rDefaultPrintData.bPrintBlackFont ); }
GetPrintPostItsType() const203     sal_Int16 GetPrintPostItsType() const       { return static_cast< sal_Int16 >(getIntValue( "PrintAnnotationMode", m_rDefaultPrintData.nPrintPostIts )); }
IsPaperFromSetup() const204     bool IsPaperFromSetup() const               { return getBoolValue( "PrintPaperFromSetup",  m_rDefaultPrintData.bPaperFromSetup ); }
IsPrintReverse() const205     bool IsPrintReverse() const                 { return false; /*handled by print dialog now*/ /*getBoolValue( "PrintReversed",        m_rDefaultPrintData.bPrintReverse );*/ }
206 
207     bool IsPrintLeftPages() const;
208     bool IsPrintRightPages() const;
209     bool IsPrintEmptyPages( bool bIsPDFExport ) const;
210     bool IsPrintTables() const;
211     bool IsPrintGraphics() const;
212     bool IsPrintDrawings() const;
213 };
214 
215 
216 ////////////////////////////////////////////////////////////
217 
218 // A class that stores temporary data that is needed for rendering the document.
219 // Usually this data is created when 'getRendererCount' is called and
220 // and it is used in the 'render' function of that same interface
221 class SwRenderData
222 {
223     // pages valid for printing (according to the current settings)
224     // and their respective start frames (see getRendererCount in unotxdoc.cxx)
225     // This set of pages does NOT depend on the 'PageRange' that is used as a printing option!
226     std::set< sal_Int32 >                       m_aValidPages;          // the set of possible pages (see StringRangeEnumerator::getRangesFromString )
227     std::map< sal_Int32, const SwPageFrm * >    m_aValidStartFrames;    // the map of start frames for those pages
228 
229     // printer paper tray to use for each of the m_aValidPages above
230     std::map< sal_Int32, sal_Int32 >            m_aPrinterPaperTrays;
231 
232     // vector of pages and their order to be printed (duplicates and any order allowed!)
233     // (see 'render' in unotxdoc.cxx)
234     std::vector< sal_Int32 >                    m_aPagesToPrint;
235 
236     std::vector< const SwPageFrm * >            m_aPostItStartFrames;
237 
238     // for prospect printing: the pairs of pages to be printed together on a single prospect page.
239     // -1 indicates a half page to be left empty.
240     std::vector< std::pair< sal_Int32, sal_Int32 > >    m_aPagePairs;
241 
242     rtl::OUString               m_aPageRange;
243 
244     // the view options to be applied for printing
245     SwViewOptionAdjust_Impl *   m_pViewOptionAdjust;
246 
247     SwPrintData *               m_pPrtOptions;
248 
249 public:
250 
251     // PostIt relevant data
252     _SetGetExpFlds *    m_pPostItFields;    // an array of "_SetGetExpFld *" sorted by page and line numbers
253     SwDoc *             m_pPostItDoc;
254     ViewShell *         m_pPostItShell;
255 
256 public:
257     SwRenderData();
258     ~SwRenderData();
259 
260 
HasPostItData() const261     bool HasPostItData() const  { return m_pPostItShell != 0 && m_pPostItDoc != 0 && m_pPostItShell != 0; }
262     void CreatePostItData( SwDoc *pDoc, const SwViewOption *pViewOpt, OutputDevice *pOutDev );
263     void DeletePostItData();
264 
IsViewOptionAdjust() const265     bool IsViewOptionAdjust() const  { return m_pViewOptionAdjust != 0; }
266     bool NeedNewViewOptionAdjust( const ViewShell& ) const;
267     void ViewOptionAdjustStart( ViewShell &rSh, const SwViewOption &rViewOptions );
268     void ViewOptionAdjust( SwPrintData const* const pPrtOptions );
269     void ViewOptionAdjustStop();
270 
HasSwPrtOptions() const271     bool HasSwPrtOptions() const    { return m_pPrtOptions != 0; }
SetSwPrtOptions(SwPrintData * const pOpt)272     void SetSwPrtOptions(SwPrintData *const pOpt)   { m_pPrtOptions = pOpt; }
GetSwPrtOptions() const273     SwPrintData const*  GetSwPrtOptions() const     { return m_pPrtOptions; }
GetSwPrtOptionsRef()274     SwPrintData &       GetSwPrtOptionsRef()        { return *m_pPrtOptions; }
275     void MakeSwPrtOptions( SwPrintData & rOptions, const SwDocShell *pDocShell,
276             const SwPrintUIOptions *pOpt, const SwRenderData *pData, bool bIsPDFExport );
277 
278 
279     typedef std::map< sal_Int32, const SwPageFrm * >            ValidStartFramesMap_t;
280     typedef std::vector< std::pair< sal_Int32, sal_Int32 > >    PagePairsVec_t;
281 
GetValidPagesSet()282     std::set< sal_Int32 > &             GetValidPagesSet()          { return m_aValidPages; }
GetValidPagesSet() const283     const std::set< sal_Int32 > &       GetValidPagesSet() const    { return m_aValidPages; }
GetValidStartFrames()284     ValidStartFramesMap_t &             GetValidStartFrames()       { return m_aValidStartFrames; }
GetValidStartFrames() const285     const ValidStartFramesMap_t &       GetValidStartFrames() const { return m_aValidStartFrames; }
286 
287     // a map for printer paper tray numbers to use for each document page
288     // a value of -1 for the tray means that there is no specific tray defined
GetPrinterPaperTrays()289     std::map< sal_Int32, sal_Int32 >&        GetPrinterPaperTrays()          { return m_aPrinterPaperTrays; }
GetPrinterPaperTrays() const290     const std::map< sal_Int32, sal_Int32 >&  GetPrinterPaperTrays() const    { return m_aPrinterPaperTrays; }
291 
292     // used for 'normal' printing
293     // A page value of 0 as entry indicates that this page is not from the document but
294     // from the post-it document. (See also GetPostItStartFrame below)
GetPagesToPrint()295     std::vector< sal_Int32 > &          GetPagesToPrint()           { return m_aPagesToPrint; }
GetPagesToPrint() const296     const std::vector< sal_Int32 > &    GetPagesToPrint() const     { return m_aPagesToPrint; }
297 
298     // used for 'normal' printing with post-its
299     // - if the map entry will be NULL then the respective page to be printed is from
300     // the document. In that case use the value from GetPagesToPrint at the same index to
301     // get the phys. page number to be printed, and then retrieve the start frame to use
302     // from GetValidStartFrms.
303     // - If the entry is not NULL it is the start frame of the page from the post-it document
304     // that is to be printed
GetPostItStartFrames()305     std::vector< const SwPageFrm * > &          GetPostItStartFrames()          { return m_aPostItStartFrames; }
GetPostItStartFrames() const306     const std::vector< const SwPageFrm * > &    GetPostItStartFrames() const    { return m_aPostItStartFrames; }
307 
308     // used for prospect printing only
GetPagePairsForProspectPrinting()309     PagePairsVec_t &                    GetPagePairsForProspectPrinting()           { return m_aPagePairs; }
GetPagePairsForProspectPrinting() const310     const PagePairsVec_t &              GetPagePairsForProspectPrinting() const     { return m_aPagePairs; }
311 
GetPageRange() const312     rtl::OUString   GetPageRange() const                            { return m_aPageRange; }
SetPageRange(const rtl::OUString & rRange)313     void            SetPageRange( const rtl::OUString &rRange )     { m_aPageRange = rRange; }
314 };
315 
316 
317 ////////////////////////////////////////////////////////////
318 
319 // last remnants of swprtopt.hxx:
320 
321 #define POSTITS_NONE	0
322 #define POSTITS_ONLY	1
323 #define POSTITS_ENDDOC	2
324 #define POSTITS_ENDPAGE 3
325 
326 namespace sw {
327 
328 void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb);
329 
330 } // namespace sw
331 
332 #endif  // SW_PRINTDATA_HXX
333