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/printwarningoptions.hxx>
21 #include <unotools/configitem.hxx>
22 #include <tools/debug.hxx>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
26 #include "itemholder1.hxx"
30 using namespace ::utl
;
31 using namespace ::osl
;
32 using namespace ::com::sun::star::uno
;
34 #define ROOTNODE_START "Office.Common/Print"
36 #define PROPERTYNAME_PAPERSIZE OUString("Warning/PaperSize")
37 #define PROPERTYNAME_PAPERORIENTATION OUString("Warning/PaperOrientation")
38 #define PROPERTYNAME_NOTFOUND OUString("Warning/NotFound")
39 #define PROPERTYNAME_TRANSPARENCY OUString("Warning/Transparency")
40 #define PROPERTYNAME_PRINTINGMODIFIESDOCUMENT OUString("PrintingModifiesDocument")
42 #define PROPERTYHANDLE_PAPERSIZE 0
43 #define PROPERTYHANDLE_PAPERORIENTATION 1
44 #define PROPERTYHANDLE_NOTFOUND 2
45 #define PROPERTYHANDLE_TRANSPARENCY 3
46 #define PROPERTYHDL_PRINTINGMODIFIESDOCUMENT 4
48 #define PROPERTYCOUNT 5
50 class SvtPrintWarningOptions_Impl
: public ConfigItem
54 // constructor / destructor
56 SvtPrintWarningOptions_Impl();
57 virtual ~SvtPrintWarningOptions_Impl() override
;
59 // override methods of baseclass
61 virtual void Notify( const css::uno::Sequence
< OUString
>& aPropertyNames
) override
;
65 bool IsPaperSize() const { return m_bPaperSize
; }
66 bool IsPaperOrientation() const { return m_bPaperOrientation
; }
67 bool IsTransparency() const { return m_bTransparency
; }
68 bool IsModifyDocumentOnPrintingAllowed() const { return m_bModifyDocumentOnPrintingAllowed
; }
70 void SetPaperSize( bool bState
) { m_bPaperSize
= bState
; SetModified(); }
71 void SetPaperOrientation( bool bState
) { m_bPaperOrientation
= bState
; SetModified(); }
72 void SetTransparency( bool bState
) { m_bTransparency
= bState
; SetModified(); }
73 void SetModifyDocumentOnPrintingAllowed( bool bState
) { m_bModifyDocumentOnPrintingAllowed
= bState
; SetModified(); }
79 virtual void ImplCommit() override
;
81 static Sequence
< OUString
> impl_GetPropertyNames();
88 bool m_bPaperOrientation
;
91 bool m_bModifyDocumentOnPrintingAllowed
;
96 SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl() :
97 ConfigItem( ROOTNODE_START
),
98 m_bPaperSize( false ),
99 m_bPaperOrientation( false ),
100 m_bNotFound( false ),
101 m_bTransparency( true ),
102 m_bModifyDocumentOnPrintingAllowed( true )
104 Sequence
< OUString
> seqNames( impl_GetPropertyNames() );
105 Sequence
< Any
> seqValues( GetProperties( seqNames
) );
107 DBG_ASSERT( !(seqNames
.getLength()!=seqValues
.getLength()), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nI miss some values of configuration keys!\n" );
109 // Copy values from list in right order to our internal member.
110 sal_Int32 nPropertyCount
= seqValues
.getLength();
111 sal_Int32 nProperty
= 0;
113 for( nProperty
=0; nProperty
<nPropertyCount
; ++nProperty
)
115 DBG_ASSERT( seqValues
[nProperty
].hasValue(), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nInvalid property value for property detected!\n" );
119 case PROPERTYHANDLE_PAPERSIZE
:
121 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
122 seqValues
[nProperty
] >>= m_bPaperSize
;
126 case PROPERTYHANDLE_PAPERORIENTATION
:
128 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
129 seqValues
[nProperty
] >>= m_bPaperOrientation
;
133 case PROPERTYHANDLE_NOTFOUND
:
135 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
136 seqValues
[nProperty
] >>= m_bNotFound
;
140 case PROPERTYHANDLE_TRANSPARENCY
:
142 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
143 seqValues
[nProperty
] >>= m_bTransparency
;
146 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT
:
148 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "Invalid type" );
149 seqValues
[nProperty
] >>= m_bModifyDocumentOnPrintingAllowed
;
159 SvtPrintWarningOptions_Impl::~SvtPrintWarningOptions_Impl()
161 assert(!IsModified()); // should have been committed
166 void SvtPrintWarningOptions_Impl::ImplCommit()
168 Sequence
< OUString
> aSeqNames( impl_GetPropertyNames() );
169 Sequence
< Any
> aSeqValues( aSeqNames
.getLength() );
171 for( sal_Int32 nProperty
= 0, nCount
= aSeqNames
.getLength(); nProperty
< nCount
; ++nProperty
)
175 case PROPERTYHANDLE_PAPERSIZE
:
176 aSeqValues
[nProperty
] <<= m_bPaperSize
;
179 case PROPERTYHANDLE_PAPERORIENTATION
:
180 aSeqValues
[nProperty
] <<= m_bPaperOrientation
;
183 case PROPERTYHANDLE_NOTFOUND
:
184 aSeqValues
[nProperty
] <<= m_bNotFound
;
187 case PROPERTYHANDLE_TRANSPARENCY
:
188 aSeqValues
[nProperty
] <<= m_bTransparency
;
190 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT
:
191 aSeqValues
[nProperty
] <<= m_bModifyDocumentOnPrintingAllowed
;
196 PutProperties( aSeqNames
, aSeqValues
);
199 void SvtPrintWarningOptions_Impl::Notify( const Sequence
< OUString
>& )
205 Sequence
< OUString
> SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
207 // Build list of configuration key names.
208 const OUString pProperties
[] =
210 PROPERTYNAME_PAPERSIZE
,
211 PROPERTYNAME_PAPERORIENTATION
,
212 PROPERTYNAME_NOTFOUND
,
213 PROPERTYNAME_TRANSPARENCY
,
214 PROPERTYNAME_PRINTINGMODIFIESDOCUMENT
217 // Initialize return sequence with these list ...
218 const Sequence
< OUString
> seqPropertyNames( pProperties
, PROPERTYCOUNT
);
220 return seqPropertyNames
;
223 static std::weak_ptr
<SvtPrintWarningOptions_Impl
> g_pPrintWarningOptions
;
225 SvtPrintWarningOptions::SvtPrintWarningOptions()
227 // Global access, must be guarded (multithreading!).
228 MutexGuard
aGuard( GetOwnStaticMutex() );
230 m_pImpl
= g_pPrintWarningOptions
.lock();
233 m_pImpl
= std::make_shared
<SvtPrintWarningOptions_Impl
>();
234 g_pPrintWarningOptions
= m_pImpl
;
235 ItemHolder1::holdConfigItem(EItem::PrintWarningOptions
);
239 SvtPrintWarningOptions::~SvtPrintWarningOptions()
241 // Global access, must be guarded (multithreading!)
242 MutexGuard
aGuard( GetOwnStaticMutex() );
249 bool SvtPrintWarningOptions::IsPaperSize() const
251 MutexGuard
aGuard( GetOwnStaticMutex() );
252 return m_pImpl
->IsPaperSize();
257 bool SvtPrintWarningOptions::IsPaperOrientation() const
259 MutexGuard
aGuard( GetOwnStaticMutex() );
260 return m_pImpl
->IsPaperOrientation();
265 bool SvtPrintWarningOptions::IsTransparency() const
267 MutexGuard
aGuard( GetOwnStaticMutex() );
268 return m_pImpl
->IsTransparency();
273 void SvtPrintWarningOptions::SetPaperSize( bool bState
)
275 MutexGuard
aGuard( GetOwnStaticMutex() );
276 m_pImpl
->SetPaperSize( bState
);
281 void SvtPrintWarningOptions::SetPaperOrientation( bool bState
)
283 MutexGuard
aGuard( GetOwnStaticMutex() );
284 m_pImpl
->SetPaperOrientation( bState
);
289 void SvtPrintWarningOptions::SetTransparency( bool bState
)
291 MutexGuard
aGuard( GetOwnStaticMutex() );
292 m_pImpl
->SetTransparency( bState
);
295 bool SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
297 MutexGuard
aGuard( GetOwnStaticMutex() );
298 return m_pImpl
->IsModifyDocumentOnPrintingAllowed();
301 void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( bool bState
)
303 MutexGuard
aGuard( GetOwnStaticMutex() );
304 m_pImpl
->SetModifyDocumentOnPrintingAllowed( bState
);
309 class thePrintWarningOptionsMutex
: public rtl::Static
<osl::Mutex
, thePrintWarningOptionsMutex
>{};
314 Mutex
& SvtPrintWarningOptions::GetOwnStaticMutex()
316 return thePrintWarningOptionsMutex::get();
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */