fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / config / slidesorterbaropt.cxx
blobcf0208ea0ac75f76120a016abeebe00d7cd7c928
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 <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
27 #include <rtl/logfile.hxx>
28 #include <rtl/instance.hxx>
30 using namespace ::utl;
31 using namespace ::rtl;
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 ~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 );
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 /** write changes to configuration
79 These method writes the changed values into the sub tree
80 and should always called in our destructor to guarantee consistency of config data.
82 \sa baseclass ConfigItem
84 virtual void Commit();
86 // public interface
87 bool m_bVisibleImpressView;
88 bool m_bVisibleOutlineView;
89 bool m_bVisibleNotesView;
90 bool m_bVisibleHandoutView;
91 bool m_bVisibleSlideSorterView;
92 bool m_bVisibleDrawView;
94 private:
95 /** return list of key names of our configuration management which represent oue module tree
97 These methods return a static const list of key names. We need it to get needed values from our
98 configuration management.
100 \return A list of needed configuration keys is returned.
102 static Sequence< OUString > GetPropertyNames();
104 protected:
107 SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()
108 // Init baseclasses first
109 : ConfigItem( ROOTNODE_SLIDESORTERBAR )
111 , m_bVisibleImpressView( false )
112 , m_bVisibleOutlineView( false )
113 , m_bVisibleNotesView( false )
114 , m_bVisibleHandoutView( false )
115 , m_bVisibleSlideSorterView( false )
116 , m_bVisibleDrawView( false )
119 m_seqPropertyNames = GetPropertyNames( );
121 // Use our static list of configuration keys to get his values.
122 Sequence< Any > seqValues = GetProperties( m_seqPropertyNames );
124 // Safe impossible cases.
125 // We need values from ALL configuration keys.
126 // Follow assignment use order of values in relation to our list of key names!
127 DBG_ASSERT( !(m_seqPropertyNames.getLength()!=seqValues.getLength()),
128 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
130 // Copy values from list in right order to our internal member.
131 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
133 if (seqValues[nProperty].hasValue()==sal_False)
134 continue;
135 switch( nProperty )
137 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW :
139 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
140 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
141 break;
143 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
145 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
146 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
147 break;
149 case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
151 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
152 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
153 break;
155 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
157 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
158 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
159 break;
161 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
163 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
164 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
165 break;
167 case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
169 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
170 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
171 break;
176 // Enable notification mechanism of our baseclass.
177 // We need it to get information about changes outside these class on our used configuration keys!
178 EnableNotification( m_seqPropertyNames );
181 SvtSlideSorterBarOptions_Impl::~SvtSlideSorterBarOptions_Impl()
183 Commit();
186 static int lcl_MapPropertyName( const OUString rCompare,
187 const uno::Sequence< OUString>& aInternalPropertyNames)
189 for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
191 if( aInternalPropertyNames[nProp] == rCompare )
192 return nProp;
194 return -1;
197 void SvtSlideSorterBarOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
199 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
200 Sequence< Any > seqValues = GetProperties( rPropertyNames );
202 // Safe impossible cases.
203 // We need values from ALL configuration keys.
204 // Follow assignment use order of values in relation to our list of key names!
205 DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()),
206 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
208 // Copy values from list in right order to our internal member.
209 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
211 if (seqValues[nProperty].hasValue()==sal_False)
212 continue;
213 switch( lcl_MapPropertyName(rPropertyNames[nProperty], aInternalPropertyNames) )
215 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
217 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
218 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
220 break;
221 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
223 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
224 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
226 break;
227 case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
229 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
230 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
232 break;
233 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
235 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
236 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
238 break;
239 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
241 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
242 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
244 break;
246 case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
248 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
249 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
251 break;
256 void SvtSlideSorterBarOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
258 Load( rPropertyNames );
261 void SvtSlideSorterBarOptions_Impl::Commit()
263 // Get names of supported properties, create a list for values and copy current values to it.
264 sal_Int32 nCount = m_seqPropertyNames.getLength();
265 Sequence< Any > seqValues ( nCount );
266 for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
268 switch( nProperty )
270 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
272 seqValues[nProperty] <<= m_bVisibleImpressView;
273 break;
275 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW:
277 seqValues[nProperty] <<= m_bVisibleOutlineView;
278 break;
280 case PROPERTYHANDLE_VISIBLE_NOTESVIEW:
282 seqValues[nProperty] <<= m_bVisibleNotesView;
283 break;
285 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW:
287 seqValues[nProperty] <<= m_bVisibleHandoutView;
288 break;
290 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW:
292 seqValues[nProperty] <<= m_bVisibleSlideSorterView;
293 break;
295 case PROPERTYHANDLE_VISIBLE_DRAWVIEW:
297 seqValues[nProperty] <<= m_bVisibleDrawView;
298 break;
303 // Set properties in configuration.
304 PutProperties( m_seqPropertyNames, seqValues );
307 Sequence< OUString > SvtSlideSorterBarOptions_Impl::GetPropertyNames()
309 // Build list of configuration key names.
310 OUString pProperties[] =
312 PROPERTYNAME_VISIBLE_IMPRESSVIEW,
313 PROPERTYNAME_VISIBLE_OUTLINEVIEW,
314 PROPERTYNAME_VISIBLE_NOTESVIEW,
315 PROPERTYNAME_VISIBLE_HANDOUTVIEW,
316 PROPERTYNAME_VISIBLE_SLIDESORTERVIEW,
317 PROPERTYNAME_VISIBLE_DRAWVIEW,
320 // Initialize return sequence with these list and run
321 return Sequence< OUString >( pProperties, SAL_N_ELEMENTS( pProperties ) );
324 // initialize static member, see definition for further information
325 // DON'T DO IT IN YOUR HEADER!
326 SvtSlideSorterBarOptions_Impl* SvtSlideSorterBarOptions::m_pDataContainer = NULL ;
327 sal_Int32 SvtSlideSorterBarOptions::m_nRefCount = 0 ;
329 SvtSlideSorterBarOptions::SvtSlideSorterBarOptions()
331 // Global access, must be guarded (multithreading!).
332 MutexGuard aGuard( GetInitMutex() );
333 ++m_nRefCount;
334 // ... and initialize our data container only if it not already exist!
335 if( m_pDataContainer == NULL )
337 RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtSlideSorterBarOptions_Impl::ctor()");
338 m_pDataContainer = new SvtSlideSorterBarOptions_Impl;
342 SvtSlideSorterBarOptions::~SvtSlideSorterBarOptions()
344 // Global access, must be guarded (multithreading!)
345 MutexGuard aGuard( GetInitMutex() );
346 --m_nRefCount;
347 // If last instance was deleted we must destroy our static data container!
348 if( m_nRefCount <= 0 )
350 delete m_pDataContainer;
351 m_pDataContainer = NULL;
355 bool SvtSlideSorterBarOptions::GetVisibleImpressView() const
357 return m_pDataContainer->m_bVisibleImpressView;
360 void SvtSlideSorterBarOptions::SetVisibleImpressView(bool bVisible)
362 m_pDataContainer->m_bVisibleImpressView = bVisible;
365 bool SvtSlideSorterBarOptions::GetVisibleOutlineView() const
367 return m_pDataContainer->m_bVisibleOutlineView;
370 void SvtSlideSorterBarOptions::SetVisibleOutlineView(bool bVisible)
372 m_pDataContainer->m_bVisibleOutlineView = bVisible;
375 bool SvtSlideSorterBarOptions::GetVisibleNotesView() const
377 return m_pDataContainer->m_bVisibleNotesView;
380 void SvtSlideSorterBarOptions::SetVisibleNotesView(bool bVisible)
382 m_pDataContainer->m_bVisibleNotesView = bVisible;
385 bool SvtSlideSorterBarOptions::GetVisibleHandoutView() const
387 return m_pDataContainer->m_bVisibleHandoutView;
390 void SvtSlideSorterBarOptions::SetVisibleHandoutView(bool bVisible)
392 m_pDataContainer->m_bVisibleHandoutView = bVisible;
395 bool SvtSlideSorterBarOptions::GetVisibleSlideSorterView() const
397 return m_pDataContainer->m_bVisibleSlideSorterView;
400 void SvtSlideSorterBarOptions::SetVisibleSlideSorterView(bool bVisible)
402 m_pDataContainer->m_bVisibleSlideSorterView = bVisible;
405 bool SvtSlideSorterBarOptions::GetVisibleDrawView() const
407 return m_pDataContainer->m_bVisibleDrawView;
410 void SvtSlideSorterBarOptions::SetVisibleDrawView(bool bVisible)
412 m_pDataContainer->m_bVisibleDrawView = bVisible;
415 namespace
417 class theSvtSlideSorterBarOptionsMutex :
418 public rtl::Static< osl::Mutex, theSvtSlideSorterBarOptionsMutex > {};
421 Mutex & SvtSlideSorterBarOptions::GetInitMutex()
423 return theSvtSlideSorterBarOptionsMutex::get();
426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */