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 .
21 #include <unotools/printwarningoptions.hxx>
22 #include <unotools/configmgr.hxx>
23 #include <unotools/configitem.hxx>
24 #include <tools/debug.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
28 #include <itemholder1.hxx>
30 //_________________________________________________________________________________________________________________
32 //_________________________________________________________________________________________________________________
34 using namespace ::utl
;
35 using namespace ::rtl
;
36 using namespace ::osl
;
37 using namespace ::com::sun::star::uno
;
39 #define ROOTNODE_START OUString("Office.Common/Print")
41 #define PROPERTYNAME_PAPERSIZE OUString("Warning/PaperSize")
42 #define PROPERTYNAME_PAPERORIENTATION OUString("Warning/PaperOrientation")
43 #define PROPERTYNAME_NOTFOUND OUString("Warning/NotFound")
44 #define PROPERTYNAME_TRANSPARENCY OUString("Warning/Transparency")
45 #define PROPERTYNAME_PRINTINGMODIFIESDOCUMENT OUString("PrintingModifiesDocument")
47 #define PROPERTYHANDLE_PAPERSIZE 0
48 #define PROPERTYHANDLE_PAPERORIENTATION 1
49 #define PROPERTYHANDLE_NOTFOUND 2
50 #define PROPERTYHANDLE_TRANSPARENCY 3
51 #define PROPERTYHDL_PRINTINGMODIFIESDOCUMENT 4
53 #define PROPERTYCOUNT 5
55 class SvtPrintWarningOptions_Impl
: public ConfigItem
59 //---------------------------------------------------------------------------------------------------------
60 // constructor / destructor
61 //---------------------------------------------------------------------------------------------------------
63 SvtPrintWarningOptions_Impl();
64 ~SvtPrintWarningOptions_Impl();
66 //---------------------------------------------------------------------------------------------------------
67 // overloaded methods of baseclass
68 //---------------------------------------------------------------------------------------------------------
70 virtual void Commit();
71 virtual void Notify( const com::sun::star::uno::Sequence
< OUString
>& aPropertyNames
);
73 //---------------------------------------------------------------------------------------------------------
75 //---------------------------------------------------------------------------------------------------------
77 sal_Bool
IsPaperSize() const { return m_bPaperSize
; }
78 sal_Bool
IsPaperOrientation() const { return m_bPaperOrientation
; }
79 sal_Bool
IsNotFound() const { return m_bNotFound
; }
80 sal_Bool
IsTransparency() const { return m_bTransparency
; }
81 sal_Bool
IsModifyDocumentOnPrintingAllowed() const { return m_bModifyDocumentOnPrintingAllowed
; }
83 void SetPaperSize( sal_Bool bState
) { m_bPaperSize
= bState
; SetModified(); }
84 void SetPaperOrientation( sal_Bool bState
) { m_bPaperOrientation
= bState
; SetModified(); }
85 void SetNotFound( sal_Bool bState
) { m_bNotFound
= bState
; SetModified(); }
86 void SetTransparency( sal_Bool bState
) { m_bTransparency
= bState
; SetModified(); }
87 void SetModifyDocumentOnPrintingAllowed( sal_Bool bState
) { m_bModifyDocumentOnPrintingAllowed
= bState
; SetModified(); }
89 //-------------------------------------------------------------------------------------------------------------
91 //-------------------------------------------------------------------------------------------------------------
95 static Sequence
< OUString
> impl_GetPropertyNames();
97 //-------------------------------------------------------------------------------------------------------------
99 //-------------------------------------------------------------------------------------------------------------
103 sal_Bool m_bPaperSize
;
104 sal_Bool m_bPaperOrientation
;
105 sal_Bool m_bNotFound
;
106 sal_Bool m_bTransparency
;
107 sal_Bool m_bModifyDocumentOnPrintingAllowed
;
110 //*****************************************************************************************************************
112 //*****************************************************************************************************************
113 SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl() :
114 ConfigItem( ROOTNODE_START
),
115 m_bPaperSize( sal_False
),
116 m_bPaperOrientation( sal_False
),
117 m_bNotFound( sal_False
),
118 m_bTransparency( sal_True
),
119 m_bModifyDocumentOnPrintingAllowed( sal_True
)
121 Sequence
< OUString
> seqNames( impl_GetPropertyNames() );
122 Sequence
< Any
> seqValues( GetProperties( seqNames
) );
124 DBG_ASSERT( !(seqNames
.getLength()!=seqValues
.getLength()), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nI miss some values of configuration keys!\n" );
126 // Copy values from list in right order to our internal member.
127 sal_Int32 nPropertyCount
= seqValues
.getLength();
128 sal_Int32 nProperty
= 0;
130 for( nProperty
=0; nProperty
<nPropertyCount
; ++nProperty
)
132 DBG_ASSERT( !(seqValues
[nProperty
].hasValue()==sal_False
), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nInvalid property value for property detected!\n" );
136 case PROPERTYHANDLE_PAPERSIZE
:
138 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
139 seqValues
[nProperty
] >>= m_bPaperSize
;
143 case PROPERTYHANDLE_PAPERORIENTATION
:
145 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
146 seqValues
[nProperty
] >>= m_bPaperOrientation
;
150 case PROPERTYHANDLE_NOTFOUND
:
152 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
153 seqValues
[nProperty
] >>= m_bNotFound
;
157 case PROPERTYHANDLE_TRANSPARENCY
:
159 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
160 seqValues
[nProperty
] >>= m_bTransparency
;
163 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT
:
165 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
166 seqValues
[nProperty
] >>= m_bModifyDocumentOnPrintingAllowed
;
174 //*****************************************************************************************************************
176 //*****************************************************************************************************************
177 SvtPrintWarningOptions_Impl::~SvtPrintWarningOptions_Impl()
183 //*****************************************************************************************************************
185 //*****************************************************************************************************************
186 void SvtPrintWarningOptions_Impl::Commit()
188 Sequence
< OUString
> aSeqNames( impl_GetPropertyNames() );
189 Sequence
< Any
> aSeqValues( aSeqNames
.getLength() );
191 for( sal_Int32 nProperty
= 0, nCount
= aSeqNames
.getLength(); nProperty
< nCount
; ++nProperty
)
195 case PROPERTYHANDLE_PAPERSIZE
:
196 aSeqValues
[nProperty
] <<= m_bPaperSize
;
199 case PROPERTYHANDLE_PAPERORIENTATION
:
200 aSeqValues
[nProperty
] <<= m_bPaperOrientation
;
203 case PROPERTYHANDLE_NOTFOUND
:
204 aSeqValues
[nProperty
] <<= m_bNotFound
;
207 case PROPERTYHANDLE_TRANSPARENCY
:
208 aSeqValues
[nProperty
] <<= m_bTransparency
;
210 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT
:
211 aSeqValues
[nProperty
] <<= m_bModifyDocumentOnPrintingAllowed
;
216 PutProperties( aSeqNames
, aSeqValues
);
219 void SvtPrintWarningOptions_Impl::Notify( const Sequence
< OUString
>& )
223 //*****************************************************************************************************************
225 //*****************************************************************************************************************
226 Sequence
< OUString
> SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
228 // Build list of configuration key names.
229 const OUString pProperties
[] =
231 PROPERTYNAME_PAPERSIZE
,
232 PROPERTYNAME_PAPERORIENTATION
,
233 PROPERTYNAME_NOTFOUND
,
234 PROPERTYNAME_TRANSPARENCY
,
235 PROPERTYNAME_PRINTINGMODIFIESDOCUMENT
238 // Initialize return sequence with these list ...
239 const Sequence
< OUString
> seqPropertyNames( pProperties
, PROPERTYCOUNT
);
241 return seqPropertyNames
;
244 //*****************************************************************************************************************
245 // initialize static member
246 // DON'T DO IT IN YOUR HEADER!
247 // see definition for further information
248 //*****************************************************************************************************************
249 SvtPrintWarningOptions_Impl
* SvtPrintWarningOptions::m_pDataContainer
= NULL
;
250 sal_Int32
SvtPrintWarningOptions::m_nRefCount
= 0;
252 //*****************************************************************************************************************
254 //*****************************************************************************************************************
255 SvtPrintWarningOptions::SvtPrintWarningOptions()
257 // Global access, must be guarded (multithreading!).
258 MutexGuard
aGuard( GetOwnStaticMutex() );
259 // Increase ouer refcount ...
261 // ... and initialize ouer data container only if it not already!
262 if( m_pDataContainer
== NULL
)
264 m_pDataContainer
= new SvtPrintWarningOptions_Impl();
265 ItemHolder1::holdConfigItem(E_PRINTWARNINGOPTIONS
);
269 //*****************************************************************************************************************
271 //*****************************************************************************************************************
272 SvtPrintWarningOptions::~SvtPrintWarningOptions()
274 // Global access, must be guarded (multithreading!)
275 MutexGuard
aGuard( GetOwnStaticMutex() );
276 // Decrease ouer refcount.
278 // If last instance was deleted ...
279 // we must destroy ouer static data container!
280 if( m_nRefCount
<= 0 )
282 delete m_pDataContainer
;
283 m_pDataContainer
= NULL
;
287 //*****************************************************************************************************************
289 //*****************************************************************************************************************
290 sal_Bool
SvtPrintWarningOptions::IsPaperSize() const
292 MutexGuard
aGuard( GetOwnStaticMutex() );
293 return m_pDataContainer
->IsPaperSize();
296 //*****************************************************************************************************************
298 //*****************************************************************************************************************
299 sal_Bool
SvtPrintWarningOptions::IsPaperOrientation() const
301 MutexGuard
aGuard( GetOwnStaticMutex() );
302 return m_pDataContainer
->IsPaperOrientation();
305 //*****************************************************************************************************************
307 //*****************************************************************************************************************
308 sal_Bool
SvtPrintWarningOptions::IsTransparency() const
310 MutexGuard
aGuard( GetOwnStaticMutex() );
311 return m_pDataContainer
->IsTransparency();
314 //*****************************************************************************************************************
316 //*****************************************************************************************************************
317 void SvtPrintWarningOptions::SetPaperSize( sal_Bool bState
)
319 MutexGuard
aGuard( GetOwnStaticMutex() );
320 m_pDataContainer
->SetPaperSize( bState
);
323 //*****************************************************************************************************************
325 //*****************************************************************************************************************
326 void SvtPrintWarningOptions::SetPaperOrientation( sal_Bool bState
)
328 MutexGuard
aGuard( GetOwnStaticMutex() );
329 m_pDataContainer
->SetPaperOrientation( bState
);
332 //*****************************************************************************************************************
334 //*****************************************************************************************************************
335 void SvtPrintWarningOptions::SetTransparency( sal_Bool bState
)
337 MutexGuard
aGuard( GetOwnStaticMutex() );
338 m_pDataContainer
->SetTransparency( bState
);
340 // -----------------------------------------------------------------------------
342 sal_Bool
SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
344 MutexGuard
aGuard( GetOwnStaticMutex() );
345 return m_pDataContainer
->IsModifyDocumentOnPrintingAllowed();
348 // -----------------------------------------------------------------------------
350 void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( sal_Bool bState
)
352 MutexGuard
aGuard( GetOwnStaticMutex() );
353 m_pDataContainer
->SetModifyDocumentOnPrintingAllowed( bState
) ;
358 class thePrintWarningOptionsMutex
: public rtl::Static
<osl::Mutex
, thePrintWarningOptionsMutex
>{};
361 //*****************************************************************************************************************
363 //*****************************************************************************************************************
364 Mutex
& SvtPrintWarningOptions::GetOwnStaticMutex()
366 return thePrintWarningOptionsMutex::get();
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */