Updated core
[LibreOffice.git] / svtools / source / config / slidesorterbaropt.cxx
blob4f3231e04837d18b12cf6e16eaee0bd4e70786d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <osl/diagnose.h>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
28 #include <comphelper/lok.hxx>
29 #include <rtl/instance.hxx>
31 using namespace ::utl;
32 using namespace ::osl;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star;
36 #define ROOTNODE_SLIDESORTERBAR OUString("Office.Impress/MultiPaneGUI/SlideSorterBar/Visible")
38 #define PROPERTYNAME_VISIBLE_IMPRESSVIEW OUString("ImpressView")
39 #define PROPERTYHANDLE_VISIBLE_IMPRESSVIEW 0
40 #define PROPERTYNAME_VISIBLE_OUTLINEVIEW OUString("OutlineView")
41 #define PROPERTYHANDLE_VISIBLE_OUTLINEVIEW 1
42 #define PROPERTYNAME_VISIBLE_NOTESVIEW OUString("NotesView")
43 #define PROPERTYHANDLE_VISIBLE_NOTESVIEW 2
44 #define PROPERTYNAME_VISIBLE_HANDOUTVIEW OUString("HandoutView")
45 #define PROPERTYHANDLE_VISIBLE_HANDOUTVIEW 3
46 #define PROPERTYNAME_VISIBLE_SLIDESORTERVIEW OUString("SlideSorterView")
47 #define PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW 4
48 #define PROPERTYNAME_VISIBLE_DRAWVIEW OUString("DrawView")
49 #define PROPERTYHANDLE_VISIBLE_DRAWVIEW 5
51 class SvtSlideSorterBarOptions_Impl : public ConfigItem
53 Sequence< OUString > m_seqPropertyNames;
55 public:
57 SvtSlideSorterBarOptions_Impl();
58 virtual ~SvtSlideSorterBarOptions_Impl();
60 /** called for notify of configmanager
62 These method is called from the ConfigManager before application ends or from the
63 PropertyChangeListener if the sub tree broadcasts changes. You must update your
64 internal values.
66 \sa baseclass ConfigItem
67 \param[in,out] seqPropertyNames is the list of properties which should be updated.
69 virtual void Notify( const Sequence< OUString >& seqPropertyNames ) SAL_OVERRIDE;
71 /**
72 loads required data from the configuration. It's called in the constructor to
73 read all entries and form ::Notify to re-read changed setting
75 void Load( const Sequence< OUString >& rPropertyNames );
77 // public interface
78 bool m_bVisibleImpressView;
79 bool m_bVisibleOutlineView;
80 bool m_bVisibleNotesView;
81 bool m_bVisibleHandoutView;
82 bool m_bVisibleSlideSorterView;
83 bool m_bVisibleDrawView;
85 private:
86 virtual void ImplCommit() SAL_OVERRIDE;
88 /** return list of key names of our configuration management which represent oue module tree
90 These methods return a static const list of key names. We need it to get needed values from our
91 configuration management.
93 \return A list of needed configuration keys is returned.
95 static Sequence< OUString > GetPropertyNames();
97 void SetVisibleViewImpl( bool& bVisibleView, bool bVisible );
99 public:
100 void SetVisibleImpressView( bool bVisible)
101 { SetVisibleViewImpl( m_bVisibleImpressView, bVisible ); }
103 void SetVisibleOutlineView( bool bVisible)
104 { SetVisibleViewImpl( m_bVisibleOutlineView, bVisible ); }
106 void SetVisibleNotesView( bool bVisible)
107 { SetVisibleViewImpl( m_bVisibleNotesView, bVisible ); }
109 void SetVisibleHandoutView( bool bVisible)
110 { SetVisibleViewImpl( m_bVisibleHandoutView, bVisible ); }
112 void SetVisibleSlideSorterView( bool bVisible)
113 { SetVisibleViewImpl( m_bVisibleSlideSorterView, bVisible ); }
115 void SetVisibleDrawView( bool bVisible)
116 { SetVisibleViewImpl( m_bVisibleDrawView, bVisible ); }
120 SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()
121 // Init baseclasses first
122 : ConfigItem( ROOTNODE_SLIDESORTERBAR )
124 , m_bVisibleImpressView( false )
125 , m_bVisibleOutlineView( false )
126 , m_bVisibleNotesView( false )
127 , m_bVisibleHandoutView( false )
128 , m_bVisibleSlideSorterView( false )
129 , m_bVisibleDrawView( false )
132 m_seqPropertyNames = GetPropertyNames( );
134 // Use our static list of configuration keys to get his values.
135 Sequence< Any > seqValues = GetProperties( m_seqPropertyNames );
137 // Safe impossible cases.
138 // We need values from ALL configuration keys.
139 // Follow assignment use order of values in relation to our list of key names!
140 DBG_ASSERT( !(m_seqPropertyNames.getLength()!=seqValues.getLength()),
141 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
143 // Copy values from list in right order to our internal member.
144 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
146 if (!seqValues[nProperty].hasValue())
147 continue;
148 switch( nProperty )
150 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW :
152 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
153 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
154 break;
156 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
158 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
159 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
160 break;
162 case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
164 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
165 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
166 break;
168 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
170 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
171 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
172 break;
174 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
176 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
177 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
178 break;
180 case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
182 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
183 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
184 break;
189 // Enable notification mechanism of our baseclass.
190 // We need it to get information about changes outside these class on our used configuration keys!
191 EnableNotification( m_seqPropertyNames );
194 SvtSlideSorterBarOptions_Impl::~SvtSlideSorterBarOptions_Impl()
196 assert(!IsModified()); // should have been committed
199 static int lcl_MapPropertyName( const OUString& rCompare,
200 const uno::Sequence< OUString>& aInternalPropertyNames)
202 for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
204 if( aInternalPropertyNames[nProp] == rCompare )
205 return nProp;
207 return -1;
210 void SvtSlideSorterBarOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
212 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
213 Sequence< Any > seqValues = GetProperties( rPropertyNames );
215 // Safe impossible cases.
216 // We need values from ALL configuration keys.
217 // Follow assignment use order of values in relation to our list of key names!
218 DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()),
219 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
221 // Copy values from list in right order to our internal member.
222 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
224 if (!seqValues[nProperty].hasValue())
225 continue;
226 switch( lcl_MapPropertyName(rPropertyNames[nProperty], aInternalPropertyNames) )
228 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
230 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
231 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
233 break;
234 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
236 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
237 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
239 break;
240 case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
242 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
243 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
245 break;
246 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
248 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
249 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
251 break;
252 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
254 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
255 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
257 break;
259 case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
261 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
262 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
264 break;
269 void SvtSlideSorterBarOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
271 Load( rPropertyNames );
274 void SvtSlideSorterBarOptions_Impl::ImplCommit()
276 // Get names of supported properties, create a list for values and copy current values to it.
277 sal_Int32 nCount = m_seqPropertyNames.getLength();
278 Sequence< Any > seqValues ( nCount );
279 for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
281 switch( nProperty )
283 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
285 seqValues[nProperty] <<= m_bVisibleImpressView;
286 break;
288 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW:
290 seqValues[nProperty] <<= m_bVisibleOutlineView;
291 break;
293 case PROPERTYHANDLE_VISIBLE_NOTESVIEW:
295 seqValues[nProperty] <<= m_bVisibleNotesView;
296 break;
298 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW:
300 seqValues[nProperty] <<= m_bVisibleHandoutView;
301 break;
303 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW:
305 seqValues[nProperty] <<= m_bVisibleSlideSorterView;
306 break;
308 case PROPERTYHANDLE_VISIBLE_DRAWVIEW:
310 seqValues[nProperty] <<= m_bVisibleDrawView;
311 break;
316 // Set properties in configuration.
317 PutProperties( m_seqPropertyNames, seqValues );
320 Sequence< OUString > SvtSlideSorterBarOptions_Impl::GetPropertyNames()
322 // Build list of configuration key names.
323 OUString pProperties[] =
325 PROPERTYNAME_VISIBLE_IMPRESSVIEW,
326 PROPERTYNAME_VISIBLE_OUTLINEVIEW,
327 PROPERTYNAME_VISIBLE_NOTESVIEW,
328 PROPERTYNAME_VISIBLE_HANDOUTVIEW,
329 PROPERTYNAME_VISIBLE_SLIDESORTERVIEW,
330 PROPERTYNAME_VISIBLE_DRAWVIEW,
333 // Initialize return sequence with these list and run
334 return Sequence< OUString >( pProperties, SAL_N_ELEMENTS( pProperties ) );
337 void SvtSlideSorterBarOptions_Impl::SetVisibleViewImpl( bool& bVisibleView, bool bVisible )
339 if( bVisibleView != bVisible )
341 bVisibleView = bVisible;
342 SetModified();
346 // initialize static member, see definition for further information
347 // DON'T DO IT IN YOUR HEADER!
348 SvtSlideSorterBarOptions_Impl* SvtSlideSorterBarOptions::m_pDataContainer = NULL ;
349 sal_Int32 SvtSlideSorterBarOptions::m_nRefCount = 0 ;
351 SvtSlideSorterBarOptions::SvtSlideSorterBarOptions()
353 // Global access, must be guarded (multithreading!).
354 MutexGuard aGuard( GetInitMutex() );
355 ++m_nRefCount;
356 // ... and initialize our data container only if it not already exist!
357 if( m_pDataContainer == NULL )
359 m_pDataContainer = new SvtSlideSorterBarOptions_Impl;
363 SvtSlideSorterBarOptions::~SvtSlideSorterBarOptions()
365 // Global access, must be guarded (multithreading!)
366 MutexGuard aGuard( GetInitMutex() );
367 --m_nRefCount;
368 // If last instance was deleted we must destroy our static data container!
369 if( m_nRefCount <= 0 )
371 if (m_pDataContainer->IsModified())
372 m_pDataContainer->Commit();
373 delete m_pDataContainer;
374 m_pDataContainer = NULL;
378 bool SvtSlideSorterBarOptions::GetVisibleImpressView() const
380 return m_pDataContainer->m_bVisibleImpressView && !comphelper::LibreOfficeKit::isActive();
383 void SvtSlideSorterBarOptions::SetVisibleImpressView(bool bVisible)
385 m_pDataContainer->SetVisibleImpressView( bVisible );
388 bool SvtSlideSorterBarOptions::GetVisibleOutlineView() const
390 return m_pDataContainer->m_bVisibleOutlineView;
393 void SvtSlideSorterBarOptions::SetVisibleOutlineView(bool bVisible)
395 m_pDataContainer->SetVisibleOutlineView( bVisible );
398 bool SvtSlideSorterBarOptions::GetVisibleNotesView() const
400 return m_pDataContainer->m_bVisibleNotesView;
403 void SvtSlideSorterBarOptions::SetVisibleNotesView(bool bVisible)
405 m_pDataContainer->SetVisibleNotesView( bVisible );
408 bool SvtSlideSorterBarOptions::GetVisibleHandoutView() const
410 return m_pDataContainer->m_bVisibleHandoutView;
413 void SvtSlideSorterBarOptions::SetVisibleHandoutView(bool bVisible)
415 m_pDataContainer->SetVisibleHandoutView( bVisible );
418 bool SvtSlideSorterBarOptions::GetVisibleSlideSorterView() const
420 return m_pDataContainer->m_bVisibleSlideSorterView && !comphelper::LibreOfficeKit::isActive();
423 void SvtSlideSorterBarOptions::SetVisibleSlideSorterView(bool bVisible)
425 m_pDataContainer->SetVisibleSlideSorterView( bVisible );
428 bool SvtSlideSorterBarOptions::GetVisibleDrawView() const
430 return m_pDataContainer->m_bVisibleDrawView;
433 void SvtSlideSorterBarOptions::SetVisibleDrawView(bool bVisible)
435 m_pDataContainer->SetVisibleDrawView( bVisible );
438 namespace
440 class theSvtSlideSorterBarOptionsMutex :
441 public rtl::Static< osl::Mutex, theSvtSlideSorterBarOptionsMutex > {};
444 Mutex & SvtSlideSorterBarOptions::GetInitMutex()
446 return theSvtSlideSorterBarOptionsMutex::get();
449 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */