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 .
20 #include <unotools/configmgr.hxx>
22 #include <o3tl/any.hxx>
23 #include <osl/diagnose.h>
24 #include <com/sun/star/uno/Sequence.hxx>
29 using namespace com::sun::star::uno
;
32 Sequence
<OUString
> SwPrintOptions::GetPropertyNames()
34 static const char* aPropNames
[] =
36 "Content/Graphic", // 0
38 "Content/Control", // 2
39 "Content/Background", // 3
40 "Content/PrintBlack", // 4
44 "Page/BrochureRightToLeft", // 8
45 "Output/SinglePrintJob", // 9
47 "Papertray/FromPrinterSetup", // 11
48 "Content/Drawing", // 12 not in SW/Web
49 "Page/LeftPage", // 13 not in SW/Web
50 "Page/RightPage", // 14 not in SW/Web
51 "EmptyPages", // 15 not in SW/Web
52 "Content/PrintPlaceholders", // 16 not in Sw/Web
53 "Content/PrintHiddenText" // 17 not in Sw/Web
55 const int nCount
= bIsWeb
? 12 : 18;
56 Sequence
<OUString
> aNames(nCount
);
57 OUString
* pNames
= aNames
.getArray();
58 for(int i
= 0; i
< nCount
; i
++)
60 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
65 SwPrintOptions::SwPrintOptions(bool bWeb
) :
66 ConfigItem(bWeb
? OUString("Office.WriterWeb/Print") : OUString("Office.Writer/Print"),
67 ConfigItemMode::DelayedUpdate
|ConfigItemMode::ReleaseTree
),
70 m_bPrintPageBackground
= !bWeb
;
71 m_bPrintBlackFont
= bWeb
;
72 m_bPrintTextPlaceholder
= m_bPrintHiddenText
= false;
74 m_bPrintEmptyPages
= false;
76 Sequence
<OUString
> aNames
= GetPropertyNames();
77 Sequence
<Any
> aValues
= GetProperties(aNames
);
78 const Any
* pValues
= aValues
.getConstArray();
79 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
80 if(aValues
.getLength() == aNames
.getLength())
82 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
84 if(pValues
[nProp
].hasValue())
88 case 0: m_bPrintGraphic
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
89 case 1: m_bPrintTable
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
90 case 2: m_bPrintControl
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
91 case 3: m_bPrintPageBackground
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
92 case 4: m_bPrintBlackFont
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
96 pValues
[nProp
] >>= nTmp
;
97 m_nPrintPostIts
= static_cast<SwPostItMode
>(nTmp
);
100 case 6: m_bPrintReverse
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
101 case 7: m_bPrintProspect
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
102 case 8: m_bPrintProspectRTL
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
103 case 9: m_bPrintSingleJobs
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
104 case 10: pValues
[nProp
] >>= m_sFaxName
; break;
105 case 11: m_bPaperFromSetup
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
106 case 12: m_bPrintDraw
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
107 case 13: m_bPrintLeftPages
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
108 case 14: m_bPrintRightPages
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
109 case 15: m_bPrintEmptyPages
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
110 case 16: m_bPrintTextPlaceholder
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
111 case 17: m_bPrintHiddenText
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
117 // currently there is just one checkbox for print drawings and print graphics
118 // In the UI. (File/Print dialog and Tools/Options/.../Print)
119 // And since print graphics is the only available in Writer and WrtierWeb ...
121 m_bPrintDraw
= m_bPrintGraphic
;
124 SwPrintOptions::~SwPrintOptions()
128 void SwPrintOptions::Notify( const css::uno::Sequence
< OUString
>& ) {}
130 void SwPrintOptions::ImplCommit()
132 Sequence
<OUString
> aNames
= GetPropertyNames();
134 Sequence
<Any
> aValues(aNames
.getLength());
135 Any
* pValues
= aValues
.getArray();
137 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
141 case 0: pValues
[nProp
] <<= m_bPrintGraphic
; break;
142 case 1: pValues
[nProp
] <<= m_bPrintTable
; break;
143 case 2: pValues
[nProp
] <<= m_bPrintControl
; break;
144 case 3: pValues
[nProp
] <<= m_bPrintPageBackground
; break;
145 case 4: pValues
[nProp
] <<= m_bPrintBlackFont
; break;
146 case 5: pValues
[nProp
] <<= (sal_Int32
)m_nPrintPostIts
; break;
147 case 6: pValues
[nProp
] <<= m_bPrintReverse
; break;
148 case 7: pValues
[nProp
] <<= m_bPrintProspect
; break;
149 case 8: pValues
[nProp
] <<= m_bPrintProspectRTL
; break;
150 case 9: pValues
[nProp
] <<= m_bPrintSingleJobs
; break;
151 case 10: pValues
[nProp
] <<= m_sFaxName
; break;
152 case 11: pValues
[nProp
] <<= m_bPaperFromSetup
; break;
153 case 12: pValues
[nProp
] <<= m_bPrintDraw
; break;
154 case 13: pValues
[nProp
] <<= m_bPrintLeftPages
; break;
155 case 14: pValues
[nProp
] <<= m_bPrintRightPages
; break;
156 case 15: pValues
[nProp
] <<= m_bPrintEmptyPages
; break;
157 case 16: pValues
[nProp
] <<= m_bPrintTextPlaceholder
; break;
158 case 17: pValues
[nProp
] <<= m_bPrintHiddenText
; break;
162 // currently there is just one checkbox for print drawings and print graphics
163 // In the UI. (File/Print dialog and Tools/Options/.../Print)
164 // And since print graphics is the only available in Writer and WrtierWeb ...
165 m_bPrintDraw
= m_bPrintGraphic
;
167 PutProperties(aNames
, aValues
);
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */