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 <svtools/slidesorterbaropt.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>
27 #include <rtl/instance.hxx>
29 using namespace ::utl
;
30 using namespace ::rtl
;
31 using namespace ::osl
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star
;
35 #define ROOTNODE_SLIDESORTERBAR OUString("Office.Impress/MultiPaneGUI/SlideSorterBar/Visible")
37 #define PROPERTYNAME_VISIBLE_IMPRESSVIEW OUString("ImpressView")
38 #define PROPERTYHANDLE_VISIBLE_IMPRESSVIEW 0
39 #define PROPERTYNAME_VISIBLE_OUTLINEVIEW OUString("OutlineView")
40 #define PROPERTYHANDLE_VISIBLE_OUTLINEVIEW 1
41 #define PROPERTYNAME_VISIBLE_NOTESVIEW OUString("NotesView")
42 #define PROPERTYHANDLE_VISIBLE_NOTESVIEW 2
43 #define PROPERTYNAME_VISIBLE_HANDOUTVIEW OUString("HandoutView")
44 #define PROPERTYHANDLE_VISIBLE_HANDOUTVIEW 3
45 #define PROPERTYNAME_VISIBLE_SLIDESORTERVIEW OUString("SlideSorterView")
46 #define PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW 4
47 #define PROPERTYNAME_VISIBLE_DRAWVIEW OUString("DrawView")
48 #define PROPERTYHANDLE_VISIBLE_DRAWVIEW 5
50 class SvtSlideSorterBarOptions_Impl
: public ConfigItem
52 Sequence
< OUString
> m_seqPropertyNames
;
56 SvtSlideSorterBarOptions_Impl();
57 ~SvtSlideSorterBarOptions_Impl();
59 /** called for notify of configmanager
61 These method is called from the ConfigManager before application ends or from the
62 PropertyChangeListener if the sub tree broadcasts changes. You must update your
65 \sa baseclass ConfigItem
66 \param[in,out] seqPropertyNames is the list of properties which should be updated.
68 virtual void Notify( const Sequence
< OUString
>& seqPropertyNames
);
71 loads required data from the configuration. It's called in the constructor to
72 read all entries and form ::Notify to re-read changed setting
74 void Load( const Sequence
< OUString
>& rPropertyNames
);
76 /** write changes to configuration
78 These method writes the changed values into the sub tree
79 and should always called in our destructor to guarantee consistency of config data.
81 \sa baseclass ConfigItem
83 virtual void Commit();
86 bool m_bVisibleImpressView
;
87 bool m_bVisibleOutlineView
;
88 bool m_bVisibleNotesView
;
89 bool m_bVisibleHandoutView
;
90 bool m_bVisibleSlideSorterView
;
91 bool m_bVisibleDrawView
;
94 /** return list of key names of our configuration management which represent oue module tree
96 These methods return a static const list of key names. We need it to get needed values from our
97 configuration management.
99 \return A list of needed configuration keys is returned.
101 static Sequence
< OUString
> GetPropertyNames();
106 SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()
107 // Init baseclasses first
108 : ConfigItem( ROOTNODE_SLIDESORTERBAR
)
110 , m_bVisibleImpressView( false )
111 , m_bVisibleOutlineView( false )
112 , m_bVisibleNotesView( false )
113 , m_bVisibleHandoutView( false )
114 , m_bVisibleSlideSorterView( false )
115 , m_bVisibleDrawView( false )
118 m_seqPropertyNames
= GetPropertyNames( );
120 // Use our static list of configuration keys to get his values.
121 Sequence
< Any
> seqValues
= GetProperties( m_seqPropertyNames
);
123 // Safe impossible cases.
124 // We need values from ALL configuration keys.
125 // Follow assignment use order of values in relation to our list of key names!
126 DBG_ASSERT( !(m_seqPropertyNames
.getLength()!=seqValues
.getLength()),
127 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
129 // Copy values from list in right order to our internal member.
130 for( sal_Int32 nProperty
=0; nProperty
<seqValues
.getLength(); ++nProperty
)
132 if (seqValues
[nProperty
].hasValue()==sal_False
)
136 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW
:
138 if( !(seqValues
[nProperty
] >>= m_bVisibleImpressView
) )
139 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
142 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW
:
144 if( !(seqValues
[nProperty
] >>= m_bVisibleOutlineView
) )
145 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
148 case PROPERTYHANDLE_VISIBLE_NOTESVIEW
:
150 if( !(seqValues
[nProperty
] >>= m_bVisibleNotesView
) )
151 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
154 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW
:
156 if( !(seqValues
[nProperty
] >>= m_bVisibleHandoutView
) )
157 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
160 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW
:
162 if( !(seqValues
[nProperty
] >>= m_bVisibleSlideSorterView
) )
163 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
166 case PROPERTYHANDLE_VISIBLE_DRAWVIEW
:
168 if( !(seqValues
[nProperty
] >>= m_bVisibleDrawView
) )
169 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
175 // Enable notification mechanism of our baseclass.
176 // We need it to get information about changes outside these class on our used configuration keys!
177 EnableNotification( m_seqPropertyNames
);
180 SvtSlideSorterBarOptions_Impl::~SvtSlideSorterBarOptions_Impl()
185 static int lcl_MapPropertyName( const OUString rCompare
,
186 const uno::Sequence
< OUString
>& aInternalPropertyNames
)
188 for(int nProp
= 0; nProp
< aInternalPropertyNames
.getLength(); ++nProp
)
190 if( aInternalPropertyNames
[nProp
] == rCompare
)
196 void SvtSlideSorterBarOptions_Impl::Load( const Sequence
< OUString
>& rPropertyNames
)
198 const uno::Sequence
< OUString
> aInternalPropertyNames( GetPropertyNames());
199 Sequence
< Any
> seqValues
= GetProperties( rPropertyNames
);
201 // Safe impossible cases.
202 // We need values from ALL configuration keys.
203 // Follow assignment use order of values in relation to our list of key names!
204 DBG_ASSERT( !(rPropertyNames
.getLength()!=seqValues
.getLength()),
205 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
207 // Copy values from list in right order to our internal member.
208 for( sal_Int32 nProperty
=0; nProperty
<seqValues
.getLength(); ++nProperty
)
210 if (seqValues
[nProperty
].hasValue()==sal_False
)
212 switch( lcl_MapPropertyName(rPropertyNames
[nProperty
], aInternalPropertyNames
) )
214 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW
:
216 if( !(seqValues
[nProperty
] >>= m_bVisibleImpressView
) )
217 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
220 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW
:
222 if( !(seqValues
[nProperty
] >>= m_bVisibleOutlineView
) )
223 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
226 case PROPERTYHANDLE_VISIBLE_NOTESVIEW
:
228 if( !(seqValues
[nProperty
] >>= m_bVisibleNotesView
) )
229 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
232 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW
:
234 if( !(seqValues
[nProperty
] >>= m_bVisibleHandoutView
) )
235 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
238 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW
:
240 if( !(seqValues
[nProperty
] >>= m_bVisibleSlideSorterView
) )
241 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
245 case PROPERTYHANDLE_VISIBLE_DRAWVIEW
:
247 if( !(seqValues
[nProperty
] >>= m_bVisibleDrawView
) )
248 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
255 void SvtSlideSorterBarOptions_Impl::Notify( const Sequence
< OUString
>& rPropertyNames
)
257 Load( rPropertyNames
);
260 void SvtSlideSorterBarOptions_Impl::Commit()
262 // Get names of supported properties, create a list for values and copy current values to it.
263 sal_Int32 nCount
= m_seqPropertyNames
.getLength();
264 Sequence
< Any
> seqValues ( nCount
);
265 for( sal_Int32 nProperty
=0; nProperty
<nCount
; ++nProperty
)
269 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW
:
271 seqValues
[nProperty
] <<= m_bVisibleImpressView
;
274 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW
:
276 seqValues
[nProperty
] <<= m_bVisibleOutlineView
;
279 case PROPERTYHANDLE_VISIBLE_NOTESVIEW
:
281 seqValues
[nProperty
] <<= m_bVisibleNotesView
;
284 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW
:
286 seqValues
[nProperty
] <<= m_bVisibleHandoutView
;
289 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW
:
291 seqValues
[nProperty
] <<= m_bVisibleSlideSorterView
;
294 case PROPERTYHANDLE_VISIBLE_DRAWVIEW
:
296 seqValues
[nProperty
] <<= m_bVisibleDrawView
;
302 // Set properties in configuration.
303 PutProperties( m_seqPropertyNames
, seqValues
);
306 Sequence
< OUString
> SvtSlideSorterBarOptions_Impl::GetPropertyNames()
308 // Build list of configuration key names.
309 OUString pProperties
[] =
311 PROPERTYNAME_VISIBLE_IMPRESSVIEW
,
312 PROPERTYNAME_VISIBLE_OUTLINEVIEW
,
313 PROPERTYNAME_VISIBLE_NOTESVIEW
,
314 PROPERTYNAME_VISIBLE_HANDOUTVIEW
,
315 PROPERTYNAME_VISIBLE_SLIDESORTERVIEW
,
316 PROPERTYNAME_VISIBLE_DRAWVIEW
,
319 // Initialize return sequence with these list and run
320 return Sequence
< OUString
>( pProperties
, SAL_N_ELEMENTS( pProperties
) );
323 // initialize static member, see definition for further information
324 // DON'T DO IT IN YOUR HEADER!
325 SvtSlideSorterBarOptions_Impl
* SvtSlideSorterBarOptions::m_pDataContainer
= NULL
;
326 sal_Int32
SvtSlideSorterBarOptions::m_nRefCount
= 0 ;
328 SvtSlideSorterBarOptions::SvtSlideSorterBarOptions()
330 // Global access, must be guarded (multithreading!).
331 MutexGuard
aGuard( GetInitMutex() );
333 // ... and initialize our data container only if it not already exist!
334 if( m_pDataContainer
== NULL
)
336 m_pDataContainer
= new SvtSlideSorterBarOptions_Impl
;
340 SvtSlideSorterBarOptions::~SvtSlideSorterBarOptions()
342 // Global access, must be guarded (multithreading!)
343 MutexGuard
aGuard( GetInitMutex() );
345 // If last instance was deleted we must destroy our static data container!
346 if( m_nRefCount
<= 0 )
348 delete m_pDataContainer
;
349 m_pDataContainer
= NULL
;
353 bool SvtSlideSorterBarOptions::GetVisibleImpressView() const
355 return m_pDataContainer
->m_bVisibleImpressView
;
358 void SvtSlideSorterBarOptions::SetVisibleImpressView(bool bVisible
)
360 m_pDataContainer
->m_bVisibleImpressView
= bVisible
;
363 bool SvtSlideSorterBarOptions::GetVisibleOutlineView() const
365 return m_pDataContainer
->m_bVisibleOutlineView
;
368 void SvtSlideSorterBarOptions::SetVisibleOutlineView(bool bVisible
)
370 m_pDataContainer
->m_bVisibleOutlineView
= bVisible
;
373 bool SvtSlideSorterBarOptions::GetVisibleNotesView() const
375 return m_pDataContainer
->m_bVisibleNotesView
;
378 void SvtSlideSorterBarOptions::SetVisibleNotesView(bool bVisible
)
380 m_pDataContainer
->m_bVisibleNotesView
= bVisible
;
383 bool SvtSlideSorterBarOptions::GetVisibleHandoutView() const
385 return m_pDataContainer
->m_bVisibleHandoutView
;
388 void SvtSlideSorterBarOptions::SetVisibleHandoutView(bool bVisible
)
390 m_pDataContainer
->m_bVisibleHandoutView
= bVisible
;
393 bool SvtSlideSorterBarOptions::GetVisibleSlideSorterView() const
395 return m_pDataContainer
->m_bVisibleSlideSorterView
;
398 void SvtSlideSorterBarOptions::SetVisibleSlideSorterView(bool bVisible
)
400 m_pDataContainer
->m_bVisibleSlideSorterView
= bVisible
;
403 bool SvtSlideSorterBarOptions::GetVisibleDrawView() const
405 return m_pDataContainer
->m_bVisibleDrawView
;
408 void SvtSlideSorterBarOptions::SetVisibleDrawView(bool bVisible
)
410 m_pDataContainer
->m_bVisibleDrawView
= bVisible
;
415 class theSvtSlideSorterBarOptionsMutex
:
416 public rtl::Static
< osl::Mutex
, theSvtSlideSorterBarOptionsMutex
> {};
419 Mutex
& SvtSlideSorterBarOptions::GetInitMutex()
421 return theSvtSlideSorterBarOptionsMutex::get();
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */