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>
27 using namespace com::sun::star::uno
;
30 Sequence
<OUString
> SwPrintOptions::GetPropertyNames() const
32 static const char* aPropNames
[] =
34 "Content/Graphic", // 0
36 "Content/Control", // 2
37 "Content/Background", // 3
38 "Content/PrintBlack", // 4
42 "Page/BrochureRightToLeft", // 8
43 "Output/SinglePrintJob", // 9
45 "Papertray/FromPrinterSetup", // 11
46 "Content/Drawing", // 12 not in SW/Web
47 "Page/LeftPage", // 13 not in SW/Web
48 "Page/RightPage", // 14 not in SW/Web
49 "EmptyPages", // 15 not in SW/Web
50 "Content/PrintPlaceholders", // 16 not in Sw/Web
51 "Content/PrintHiddenText" // 17 not in Sw/Web
53 const int nCount
= m_bIsWeb
? 12 : 18;
54 Sequence
<OUString
> aNames(nCount
);
55 OUString
* pNames
= aNames
.getArray();
56 for(int i
= 0; i
< nCount
; i
++)
58 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
63 SwPrintOptions::SwPrintOptions(bool bWeb
) :
64 ConfigItem(bWeb
? OUString("Office.WriterWeb/Print") : OUString("Office.Writer/Print"),
65 ConfigItemMode::ReleaseTree
),
68 m_bPrintPageBackground
= !bWeb
;
69 m_bPrintBlackFont
= bWeb
;
70 m_bPrintTextPlaceholder
= m_bPrintHiddenText
= false;
72 m_bPrintEmptyPages
= false;
74 Sequence
<OUString
> aNames
= GetPropertyNames();
75 Sequence
<Any
> aValues
= GetProperties(aNames
);
76 const Any
* pValues
= aValues
.getConstArray();
77 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
78 if(aValues
.getLength() == aNames
.getLength())
80 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
82 if(pValues
[nProp
].hasValue())
86 case 0: m_bPrintGraphic
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
87 case 1: m_bPrintTable
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
88 case 2: m_bPrintControl
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
89 case 3: m_bPrintPageBackground
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
90 case 4: m_bPrintBlackFont
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
94 pValues
[nProp
] >>= nTmp
;
95 m_nPrintPostIts
= static_cast<SwPostItMode
>(nTmp
);
98 case 6: m_bPrintReverse
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
99 case 7: m_bPrintProspect
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
100 case 8: m_bPrintProspectRTL
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
101 case 9: m_bPrintSingleJobs
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
102 case 10: pValues
[nProp
] >>= m_sFaxName
; break;
103 case 11: m_bPaperFromSetup
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
104 case 12: m_bPrintDraw
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
105 case 13: m_bPrintLeftPages
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
106 case 14: m_bPrintRightPages
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
107 case 15: m_bPrintEmptyPages
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
108 case 16: m_bPrintTextPlaceholder
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
109 case 17: m_bPrintHiddenText
= *o3tl::doAccess
<bool>(pValues
[nProp
]); break;
115 // currently there is just one checkbox for print drawings and print graphics
116 // In the UI. (File/Print dialog and Tools/Options/.../Print)
117 // And since print graphics is the only available in Writer and WriterWeb...
119 m_bPrintDraw
= m_bPrintGraphic
;
122 SwPrintOptions::~SwPrintOptions()
126 void SwPrintOptions::Notify( const css::uno::Sequence
< OUString
>& ) {}
128 void SwPrintOptions::ImplCommit()
130 Sequence
<OUString
> aNames
= GetPropertyNames();
132 Sequence
<Any
> aValues(aNames
.getLength());
133 Any
* pValues
= aValues
.getArray();
135 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
139 case 0: pValues
[nProp
] <<= m_bPrintGraphic
; break;
140 case 1: pValues
[nProp
] <<= m_bPrintTable
; break;
141 case 2: pValues
[nProp
] <<= m_bPrintControl
; break;
142 case 3: pValues
[nProp
] <<= m_bPrintPageBackground
; break;
143 case 4: pValues
[nProp
] <<= m_bPrintBlackFont
; break;
144 case 5: pValues
[nProp
] <<= static_cast<sal_Int32
>(m_nPrintPostIts
) ; break;
145 case 6: pValues
[nProp
] <<= m_bPrintReverse
; break;
146 case 7: pValues
[nProp
] <<= m_bPrintProspect
; break;
147 case 8: pValues
[nProp
] <<= m_bPrintProspectRTL
; break;
148 case 9: pValues
[nProp
] <<= m_bPrintSingleJobs
; break;
149 case 10: pValues
[nProp
] <<= m_sFaxName
; break;
150 case 11: pValues
[nProp
] <<= m_bPaperFromSetup
; break;
151 case 12: pValues
[nProp
] <<= m_bPrintDraw
; break;
152 case 13: pValues
[nProp
] <<= m_bPrintLeftPages
; break;
153 case 14: pValues
[nProp
] <<= m_bPrintRightPages
; break;
154 case 15: pValues
[nProp
] <<= m_bPrintEmptyPages
; break;
155 case 16: pValues
[nProp
] <<= m_bPrintTextPlaceholder
; break;
156 case 17: pValues
[nProp
] <<= m_bPrintHiddenText
; break;
160 // currently there is just one checkbox for print drawings and print graphics
161 // In the UI. (File/Print dialog and Tools/Options/.../Print)
162 // And since print graphics is the only available in Writer and WriterWeb...
163 m_bPrintDraw
= m_bPrintGraphic
;
165 PutProperties(aNames
, aValues
);
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */