Line data Source code
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 : #include <unotools/printwarningoptions.hxx>
21 : #include <unotools/configmgr.hxx>
22 : #include <unotools/configitem.hxx>
23 : #include <tools/debug.hxx>
24 : #include <com/sun/star/uno/Any.hxx>
25 : #include <com/sun/star/uno/Sequence.hxx>
26 :
27 : #include "itemholder1.hxx"
28 :
29 : // namespaces
30 :
31 : using namespace ::utl;
32 : using namespace ::osl;
33 : using namespace ::com::sun::star::uno;
34 :
35 : #define ROOTNODE_START OUString("Office.Common/Print")
36 :
37 : #define PROPERTYNAME_PAPERSIZE OUString("Warning/PaperSize")
38 : #define PROPERTYNAME_PAPERORIENTATION OUString("Warning/PaperOrientation")
39 : #define PROPERTYNAME_NOTFOUND OUString("Warning/NotFound")
40 : #define PROPERTYNAME_TRANSPARENCY OUString("Warning/Transparency")
41 : #define PROPERTYNAME_PRINTINGMODIFIESDOCUMENT OUString("PrintingModifiesDocument")
42 :
43 : #define PROPERTYHANDLE_PAPERSIZE 0
44 : #define PROPERTYHANDLE_PAPERORIENTATION 1
45 : #define PROPERTYHANDLE_NOTFOUND 2
46 : #define PROPERTYHANDLE_TRANSPARENCY 3
47 : #define PROPERTYHDL_PRINTINGMODIFIESDOCUMENT 4
48 :
49 : #define PROPERTYCOUNT 5
50 :
51 : class SvtPrintWarningOptions_Impl : public ConfigItem
52 : {
53 : public:
54 :
55 : // constructor / destructor
56 :
57 : SvtPrintWarningOptions_Impl();
58 : virtual ~SvtPrintWarningOptions_Impl();
59 :
60 : // override methods of baseclass
61 :
62 : virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
63 :
64 : // public interface
65 :
66 0 : bool IsPaperSize() const { return m_bPaperSize; }
67 0 : bool IsPaperOrientation() const { return m_bPaperOrientation; }
68 0 : bool IsTransparency() const { return m_bTransparency; }
69 0 : bool IsModifyDocumentOnPrintingAllowed() const { return m_bModifyDocumentOnPrintingAllowed; }
70 :
71 0 : void SetPaperSize( bool bState ) { m_bPaperSize = bState; SetModified(); }
72 0 : void SetPaperOrientation( bool bState ) { m_bPaperOrientation = bState; SetModified(); }
73 0 : void SetTransparency( bool bState ) { m_bTransparency = bState; SetModified(); }
74 0 : void SetModifyDocumentOnPrintingAllowed( bool bState ) { m_bModifyDocumentOnPrintingAllowed = bState; SetModified(); }
75 :
76 : // private methods
77 :
78 : private:
79 :
80 : virtual void ImplCommit() SAL_OVERRIDE;
81 :
82 : static Sequence< OUString > impl_GetPropertyNames();
83 :
84 : // private member
85 :
86 : private:
87 :
88 : bool m_bPaperSize;
89 : bool m_bPaperOrientation;
90 : bool m_bNotFound;
91 : bool m_bTransparency;
92 : bool m_bModifyDocumentOnPrintingAllowed;
93 : };
94 :
95 : // constructor
96 :
97 0 : SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl() :
98 : ConfigItem( ROOTNODE_START ),
99 : m_bPaperSize( false ),
100 : m_bPaperOrientation( false ),
101 : m_bNotFound( false ),
102 : m_bTransparency( true ),
103 0 : m_bModifyDocumentOnPrintingAllowed( true )
104 : {
105 0 : Sequence< OUString > seqNames( impl_GetPropertyNames() );
106 0 : Sequence< Any > seqValues( GetProperties( seqNames ) );
107 :
108 : DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nI miss some values of configuration keys!\n" );
109 :
110 : // Copy values from list in right order to our internal member.
111 0 : sal_Int32 nPropertyCount = seqValues.getLength();
112 0 : sal_Int32 nProperty = 0;
113 :
114 0 : for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
115 : {
116 : DBG_ASSERT( seqValues[nProperty].hasValue(), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nInvalid property value for property detected!\n" );
117 :
118 0 : switch( nProperty )
119 : {
120 : case PROPERTYHANDLE_PAPERSIZE:
121 : {
122 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
123 0 : seqValues[nProperty] >>= m_bPaperSize;
124 : }
125 0 : break;
126 :
127 : case PROPERTYHANDLE_PAPERORIENTATION:
128 : {
129 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
130 0 : seqValues[nProperty] >>= m_bPaperOrientation;
131 : }
132 0 : break;
133 :
134 : case PROPERTYHANDLE_NOTFOUND:
135 : {
136 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
137 0 : seqValues[nProperty] >>= m_bNotFound;
138 : }
139 0 : break;
140 :
141 : case PROPERTYHANDLE_TRANSPARENCY:
142 : {
143 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
144 0 : seqValues[nProperty] >>= m_bTransparency;
145 : }
146 0 : break;
147 : case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
148 : {
149 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
150 0 : seqValues[nProperty] >>= m_bModifyDocumentOnPrintingAllowed;
151 : }
152 0 : break;
153 :
154 : }
155 0 : }
156 0 : }
157 :
158 : // destructor
159 :
160 0 : SvtPrintWarningOptions_Impl::~SvtPrintWarningOptions_Impl()
161 : {
162 : assert(!IsModified()); // should have been committed
163 0 : }
164 :
165 : // Commit
166 :
167 0 : void SvtPrintWarningOptions_Impl::ImplCommit()
168 : {
169 0 : Sequence< OUString > aSeqNames( impl_GetPropertyNames() );
170 0 : Sequence< Any > aSeqValues( aSeqNames.getLength() );
171 :
172 0 : for( sal_Int32 nProperty = 0, nCount = aSeqNames.getLength(); nProperty < nCount; ++nProperty )
173 : {
174 0 : switch( nProperty )
175 : {
176 : case PROPERTYHANDLE_PAPERSIZE:
177 0 : aSeqValues[nProperty] <<= m_bPaperSize;
178 0 : break;
179 :
180 : case PROPERTYHANDLE_PAPERORIENTATION:
181 0 : aSeqValues[nProperty] <<= m_bPaperOrientation;
182 0 : break;
183 :
184 : case PROPERTYHANDLE_NOTFOUND:
185 0 : aSeqValues[nProperty] <<= m_bNotFound;
186 0 : break;
187 :
188 : case PROPERTYHANDLE_TRANSPARENCY:
189 0 : aSeqValues[nProperty] <<= m_bTransparency;
190 0 : break;
191 : case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
192 0 : aSeqValues[nProperty] <<= m_bModifyDocumentOnPrintingAllowed;
193 0 : break;
194 : }
195 : }
196 :
197 0 : PutProperties( aSeqNames, aSeqValues );
198 0 : }
199 :
200 0 : void SvtPrintWarningOptions_Impl::Notify( const Sequence< OUString >& )
201 : {
202 0 : }
203 :
204 : // private method
205 :
206 0 : Sequence< OUString > SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
207 : {
208 : // Build list of configuration key names.
209 : const OUString pProperties[] =
210 : {
211 : PROPERTYNAME_PAPERSIZE,
212 : PROPERTYNAME_PAPERORIENTATION,
213 : PROPERTYNAME_NOTFOUND,
214 : PROPERTYNAME_TRANSPARENCY,
215 : PROPERTYNAME_PRINTINGMODIFIESDOCUMENT
216 0 : };
217 :
218 : // Initialize return sequence with these list ...
219 0 : const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
220 :
221 0 : return seqPropertyNames;
222 : }
223 :
224 : // initialize static member
225 : // DON'T DO IT IN YOUR HEADER!
226 : // see definition for further information
227 :
228 : SvtPrintWarningOptions_Impl* SvtPrintWarningOptions::m_pDataContainer = NULL;
229 : sal_Int32 SvtPrintWarningOptions::m_nRefCount = 0;
230 :
231 : // constructor
232 :
233 0 : SvtPrintWarningOptions::SvtPrintWarningOptions()
234 : {
235 : // Global access, must be guarded (multithreading!).
236 0 : MutexGuard aGuard( GetOwnStaticMutex() );
237 : // Increase our refcount ...
238 0 : ++m_nRefCount;
239 : // ... and initialize our data container only if it not already!
240 0 : if( m_pDataContainer == NULL )
241 : {
242 0 : m_pDataContainer = new SvtPrintWarningOptions_Impl();
243 0 : ItemHolder1::holdConfigItem(E_PRINTWARNINGOPTIONS);
244 0 : }
245 0 : }
246 :
247 : // destructor
248 :
249 0 : SvtPrintWarningOptions::~SvtPrintWarningOptions()
250 : {
251 : // Global access, must be guarded (multithreading!)
252 0 : MutexGuard aGuard( GetOwnStaticMutex() );
253 : // Decrease our refcount.
254 0 : --m_nRefCount;
255 : // If last instance was deleted ...
256 : // we must destroy our static data container!
257 0 : if( m_nRefCount <= 0 )
258 : {
259 0 : delete m_pDataContainer;
260 0 : m_pDataContainer = NULL;
261 0 : }
262 0 : }
263 :
264 : // public method
265 :
266 0 : bool SvtPrintWarningOptions::IsPaperSize() const
267 : {
268 0 : MutexGuard aGuard( GetOwnStaticMutex() );
269 0 : return m_pDataContainer->IsPaperSize();
270 : }
271 :
272 : // public method
273 :
274 0 : bool SvtPrintWarningOptions::IsPaperOrientation() const
275 : {
276 0 : MutexGuard aGuard( GetOwnStaticMutex() );
277 0 : return m_pDataContainer->IsPaperOrientation();
278 : }
279 :
280 : // public method
281 :
282 0 : bool SvtPrintWarningOptions::IsTransparency() const
283 : {
284 0 : MutexGuard aGuard( GetOwnStaticMutex() );
285 0 : return m_pDataContainer->IsTransparency();
286 : }
287 :
288 : // public method
289 :
290 0 : void SvtPrintWarningOptions::SetPaperSize( bool bState )
291 : {
292 0 : MutexGuard aGuard( GetOwnStaticMutex() );
293 0 : m_pDataContainer->SetPaperSize( bState );
294 0 : }
295 :
296 : // public method
297 :
298 0 : void SvtPrintWarningOptions::SetPaperOrientation( bool bState )
299 : {
300 0 : MutexGuard aGuard( GetOwnStaticMutex() );
301 0 : m_pDataContainer->SetPaperOrientation( bState );
302 0 : }
303 :
304 : // public method
305 :
306 0 : void SvtPrintWarningOptions::SetTransparency( bool bState )
307 : {
308 0 : MutexGuard aGuard( GetOwnStaticMutex() );
309 0 : m_pDataContainer->SetTransparency( bState );
310 0 : }
311 :
312 0 : bool SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
313 : {
314 0 : MutexGuard aGuard( GetOwnStaticMutex() );
315 0 : return m_pDataContainer->IsModifyDocumentOnPrintingAllowed();
316 : }
317 :
318 0 : void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( bool bState )
319 : {
320 0 : MutexGuard aGuard( GetOwnStaticMutex() );
321 0 : m_pDataContainer->SetModifyDocumentOnPrintingAllowed( bState );
322 0 : }
323 :
324 : namespace
325 : {
326 : class thePrintWarningOptionsMutex : public rtl::Static<osl::Mutex, thePrintWarningOptionsMutex>{};
327 : }
328 :
329 : // private method
330 :
331 0 : Mutex& SvtPrintWarningOptions::GetOwnStaticMutex()
332 : {
333 0 : return thePrintWarningOptionsMutex::get();
334 : }
335 :
336 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|