1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: printwarningoptions.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
36 //_________________________________________________________________________________________________________________
38 //_________________________________________________________________________________________________________________
40 #include <svtools/printwarningoptions.hxx>
41 #include <unotools/configmgr.hxx>
42 #include <unotools/configitem.hxx>
43 #include <tools/debug.hxx>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
47 #include <itemholder1.hxx>
49 //_________________________________________________________________________________________________________________
51 //_________________________________________________________________________________________________________________
53 using namespace ::utl
;
54 using namespace ::rtl
;
55 using namespace ::osl
;
56 using namespace ::com::sun::star::uno
;
58 //_________________________________________________________________________________________________________________
60 //_________________________________________________________________________________________________________________
62 #define ROOTNODE_START OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Print"))
64 #define PROPERTYNAME_PAPERSIZE OUString(RTL_CONSTASCII_USTRINGPARAM("Warning/PaperSize"))
65 #define PROPERTYNAME_PAPERORIENTATION OUString(RTL_CONSTASCII_USTRINGPARAM("Warning/PaperOrientation"))
66 #define PROPERTYNAME_NOTFOUND OUString(RTL_CONSTASCII_USTRINGPARAM("Warning/NotFound"))
67 #define PROPERTYNAME_TRANSPARENCY OUString(RTL_CONSTASCII_USTRINGPARAM("Warning/Transparency"))
68 #define PROPERTYNAME_PRINTINGMODIFIESDOCUMENT OUString(RTL_CONSTASCII_USTRINGPARAM("PrintingModifiesDocument"))
70 #define PROPERTYHANDLE_PAPERSIZE 0
71 #define PROPERTYHANDLE_PAPERORIENTATION 1
72 #define PROPERTYHANDLE_NOTFOUND 2
73 #define PROPERTYHANDLE_TRANSPARENCY 3
74 #define PROPERTYHDL_PRINTINGMODIFIESDOCUMENT 4
76 #define PROPERTYCOUNT 5
78 class SvtPrintWarningOptions_Impl
: public ConfigItem
82 //---------------------------------------------------------------------------------------------------------
83 // constructor / destructor
84 //---------------------------------------------------------------------------------------------------------
86 SvtPrintWarningOptions_Impl();
87 ~SvtPrintWarningOptions_Impl();
89 //---------------------------------------------------------------------------------------------------------
90 // overloaded methods of baseclass
91 //---------------------------------------------------------------------------------------------------------
93 virtual void Commit();
95 //---------------------------------------------------------------------------------------------------------
97 //---------------------------------------------------------------------------------------------------------
99 sal_Bool
IsPaperSize() const { return m_bPaperSize
; }
100 sal_Bool
IsPaperOrientation() const { return m_bPaperOrientation
; }
101 sal_Bool
IsNotFound() const { return m_bNotFound
; }
102 sal_Bool
IsTransparency() const { return m_bTransparency
; }
103 sal_Bool
IsModifyDocumentOnPrintingAllowed() const { return m_bModifyDocumentOnPrintingAllowed
; }
105 void SetPaperSize( sal_Bool bState
) { m_bPaperSize
= bState
; SetModified(); }
106 void SetPaperOrientation( sal_Bool bState
) { m_bPaperOrientation
= bState
; SetModified(); }
107 void SetNotFound( sal_Bool bState
) { m_bNotFound
= bState
; SetModified(); }
108 void SetTransparency( sal_Bool bState
) { m_bTransparency
= bState
; SetModified(); }
109 void SetModifyDocumentOnPrintingAllowed( sal_Bool bState
) { m_bModifyDocumentOnPrintingAllowed
= bState
; SetModified(); }
111 //-------------------------------------------------------------------------------------------------------------
113 //-------------------------------------------------------------------------------------------------------------
117 static Sequence
< OUString
> impl_GetPropertyNames();
119 //-------------------------------------------------------------------------------------------------------------
121 //-------------------------------------------------------------------------------------------------------------
125 sal_Bool m_bPaperSize
;
126 sal_Bool m_bPaperOrientation
;
127 sal_Bool m_bNotFound
;
128 sal_Bool m_bTransparency
;
129 sal_Bool m_bModifyDocumentOnPrintingAllowed
;
132 //_________________________________________________________________________________________________________________
134 //_________________________________________________________________________________________________________________
136 //*****************************************************************************************************************
138 //*****************************************************************************************************************
139 SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl() :
140 ConfigItem( ROOTNODE_START
),
141 m_bPaperSize( sal_False
),
142 m_bPaperOrientation( sal_False
),
143 m_bNotFound( sal_False
),
144 m_bTransparency( sal_True
),
145 m_bModifyDocumentOnPrintingAllowed( sal_True
)
147 Sequence
< OUString
> seqNames( impl_GetPropertyNames() );
148 Sequence
< Any
> seqValues( GetProperties( seqNames
) );
150 DBG_ASSERT( !(seqNames
.getLength()!=seqValues
.getLength()), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nI miss some values of configuration keys!\n" );
152 // Copy values from list in right order to our internal member.
153 sal_Int32 nPropertyCount
= seqValues
.getLength();
154 sal_Int32 nProperty
= 0;
156 for( nProperty
=0; nProperty
<nPropertyCount
; ++nProperty
)
158 DBG_ASSERT( !(seqValues
[nProperty
].hasValue()==sal_False
), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nInvalid property value for property detected!\n" );
162 case PROPERTYHANDLE_PAPERSIZE
:
164 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
165 seqValues
[nProperty
] >>= m_bPaperSize
;
169 case PROPERTYHANDLE_PAPERORIENTATION
:
171 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
172 seqValues
[nProperty
] >>= m_bPaperOrientation
;
176 case PROPERTYHANDLE_NOTFOUND
:
178 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
179 seqValues
[nProperty
] >>= m_bNotFound
;
183 case PROPERTYHANDLE_TRANSPARENCY
:
185 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
186 seqValues
[nProperty
] >>= m_bTransparency
;
189 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT
:
191 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
192 seqValues
[nProperty
] >>= m_bModifyDocumentOnPrintingAllowed
;
200 //*****************************************************************************************************************
202 //*****************************************************************************************************************
203 SvtPrintWarningOptions_Impl::~SvtPrintWarningOptions_Impl()
209 //*****************************************************************************************************************
211 //*****************************************************************************************************************
212 void SvtPrintWarningOptions_Impl::Commit()
214 Sequence
< OUString
> aSeqNames( impl_GetPropertyNames() );
215 Sequence
< Any
> aSeqValues( aSeqNames
.getLength() );
217 for( sal_Int32 nProperty
= 0, nCount
= aSeqNames
.getLength(); nProperty
< nCount
; ++nProperty
)
221 case PROPERTYHANDLE_PAPERSIZE
:
222 aSeqValues
[nProperty
] <<= m_bPaperSize
;
225 case PROPERTYHANDLE_PAPERORIENTATION
:
226 aSeqValues
[nProperty
] <<= m_bPaperOrientation
;
229 case PROPERTYHANDLE_NOTFOUND
:
230 aSeqValues
[nProperty
] <<= m_bNotFound
;
233 case PROPERTYHANDLE_TRANSPARENCY
:
234 aSeqValues
[nProperty
] <<= m_bTransparency
;
236 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT
:
237 aSeqValues
[nProperty
] <<= m_bModifyDocumentOnPrintingAllowed
;
242 PutProperties( aSeqNames
, aSeqValues
);
245 //*****************************************************************************************************************
247 //*****************************************************************************************************************
248 Sequence
< OUString
> SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
250 // Build static list of configuration key names.
251 static const OUString pProperties
[] =
253 PROPERTYNAME_PAPERSIZE
,
254 PROPERTYNAME_PAPERORIENTATION
,
255 PROPERTYNAME_NOTFOUND
,
256 PROPERTYNAME_TRANSPARENCY
,
257 PROPERTYNAME_PRINTINGMODIFIESDOCUMENT
260 // Initialize return sequence with these list ...
261 static const Sequence
< OUString
> seqPropertyNames( pProperties
, PROPERTYCOUNT
);
263 return seqPropertyNames
;
266 //*****************************************************************************************************************
267 // initialize static member
268 // DON'T DO IT IN YOUR HEADER!
269 // see definition for further informations
270 //*****************************************************************************************************************
271 SvtPrintWarningOptions_Impl
* SvtPrintWarningOptions::m_pDataContainer
= NULL
;
272 sal_Int32
SvtPrintWarningOptions::m_nRefCount
= 0;
274 //*****************************************************************************************************************
276 //*****************************************************************************************************************
277 SvtPrintWarningOptions::SvtPrintWarningOptions()
279 // Global access, must be guarded (multithreading!).
280 MutexGuard
aGuard( GetOwnStaticMutex() );
281 // Increase ouer refcount ...
283 // ... and initialize ouer data container only if it not already!
284 if( m_pDataContainer
== NULL
)
286 m_pDataContainer
= new SvtPrintWarningOptions_Impl();
287 ItemHolder1::holdConfigItem(E_PRINTWARNINGOPTIONS
);
291 //*****************************************************************************************************************
293 //*****************************************************************************************************************
294 SvtPrintWarningOptions::~SvtPrintWarningOptions()
296 // Global access, must be guarded (multithreading!)
297 MutexGuard
aGuard( GetOwnStaticMutex() );
298 // Decrease ouer refcount.
300 // If last instance was deleted ...
301 // we must destroy ouer static data container!
302 if( m_nRefCount
<= 0 )
304 delete m_pDataContainer
;
305 m_pDataContainer
= NULL
;
309 //*****************************************************************************************************************
311 //*****************************************************************************************************************
312 sal_Bool
SvtPrintWarningOptions::IsPaperSize() const
314 MutexGuard
aGuard( GetOwnStaticMutex() );
315 return m_pDataContainer
->IsPaperSize();
318 //*****************************************************************************************************************
320 //*****************************************************************************************************************
321 sal_Bool
SvtPrintWarningOptions::IsPaperOrientation() const
323 MutexGuard
aGuard( GetOwnStaticMutex() );
324 return m_pDataContainer
->IsPaperOrientation();
327 //*****************************************************************************************************************
329 //*****************************************************************************************************************
330 sal_Bool
SvtPrintWarningOptions::IsNotFound() const
332 MutexGuard
aGuard( GetOwnStaticMutex() );
333 return m_pDataContainer
->IsNotFound();
336 //*****************************************************************************************************************
338 //*****************************************************************************************************************
339 sal_Bool
SvtPrintWarningOptions::IsTransparency() const
341 MutexGuard
aGuard( GetOwnStaticMutex() );
342 return m_pDataContainer
->IsTransparency();
345 //*****************************************************************************************************************
347 //*****************************************************************************************************************
348 void SvtPrintWarningOptions::SetPaperSize( sal_Bool bState
)
350 MutexGuard
aGuard( GetOwnStaticMutex() );
351 m_pDataContainer
->SetPaperSize( bState
);
354 //*****************************************************************************************************************
356 //*****************************************************************************************************************
357 void SvtPrintWarningOptions::SetPaperOrientation( sal_Bool bState
)
359 MutexGuard
aGuard( GetOwnStaticMutex() );
360 m_pDataContainer
->SetPaperOrientation( bState
);
363 //*****************************************************************************************************************
365 //*****************************************************************************************************************
366 void SvtPrintWarningOptions::SetNotFound( sal_Bool bState
)
368 MutexGuard
aGuard( GetOwnStaticMutex() );
369 m_pDataContainer
->SetNotFound( bState
);
372 //*****************************************************************************************************************
374 //*****************************************************************************************************************
375 void SvtPrintWarningOptions::SetTransparency( sal_Bool bState
)
377 MutexGuard
aGuard( GetOwnStaticMutex() );
378 m_pDataContainer
->SetTransparency( bState
);
380 // -----------------------------------------------------------------------------
382 sal_Bool
SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
384 MutexGuard
aGuard( GetOwnStaticMutex() );
385 return m_pDataContainer
->IsModifyDocumentOnPrintingAllowed();
388 // -----------------------------------------------------------------------------
390 void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( sal_Bool bState
)
392 MutexGuard
aGuard( GetOwnStaticMutex() );
393 m_pDataContainer
->SetModifyDocumentOnPrintingAllowed( bState
) ;
396 //*****************************************************************************************************************
398 //*****************************************************************************************************************
399 Mutex
& SvtPrintWarningOptions::GetOwnStaticMutex()
401 // Initialize static mutex only for one time!
402 static Mutex
* pMutex
= NULL
;
403 // If these method first called (Mutex not already exist!) ...
406 // ... we must create a new one. Protect follow code with the global mutex -
407 // It must be - we create a static variable!
408 MutexGuard
aGuard( Mutex::getGlobalMutex() );
409 // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
412 // Create the new mutex and set it for return on static variable.
417 // Return new created or already existing mutex object.