fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / config / toolpanelopt.cxx
blob2e62765b49d140290fc972998ad40e320cfbcb91
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/toolpanelopt.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>
26 #include <tools/link.hxx>
28 #include <rtl/logfile.hxx>
29 #include <rtl/instance.hxx>
30 #include "itemholder2.hxx"
32 #include <svtools/imgdef.hxx>
33 #include <vcl/svapp.hxx>
35 #include <list>
37 using namespace ::utl;
38 using namespace ::rtl;
39 using namespace ::osl;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star;
43 #define ROOTNODE_TOOLPANEL OUString("Office.Impress/MultiPaneGUI/ToolPanel/Visible")
45 #define PROPERTYNAME_VISIBLE_IMPRESSVIEW OUString("ImpressView")
46 #define PROPERTYHANDLE_VISIBLE_IMPRESSVIEW 0
47 #define PROPERTYNAME_VISIBLE_OUTLINEVIEW OUString("OutlineView")
48 #define PROPERTYHANDLE_VISIBLE_OUTLINEVIEW 1
49 #define PROPERTYNAME_VISIBLE_NOTESVIEW OUString("NotesView")
50 #define PROPERTYHANDLE_VISIBLE_NOTESVIEW 2
51 #define PROPERTYNAME_VISIBLE_HANDOUTVIEW OUString("HandoutView")
52 #define PROPERTYHANDLE_VISIBLE_HANDOUTVIEW 3
53 #define PROPERTYNAME_VISIBLE_SLIDESORTERVIEW OUString("SlideSorterView")
54 #define PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW 4
56 class SvtToolPanelOptions_Impl : public ConfigItem
58 private:
59 Sequence< OUString > m_seqPropertyNames;
61 public:
63 SvtToolPanelOptions_Impl();
64 ~SvtToolPanelOptions_Impl();
66 /** called for notify of configmanager
68 These method is called from the ConfigManager before application ends or from the
69 PropertyChangeListener if the sub tree broadcasts changes. You must update your
70 internal values.
72 \sa baseclass ConfigItem
73 \param[in,out] seqPropertyNames is the list of properties which should be updated.
75 virtual void Notify( const Sequence< OUString >& seqPropertyNames );
77 /**
78 loads required data from the configuration. It's called in the constructor to
79 read all entries and form ::Notify to re-read changed setting
81 void Load( const Sequence< OUString >& rPropertyNames );
83 /** write changes to configuration
85 These method writes the changed values into the sub tree
86 and should always called in our destructor to guarantee consistency of config data.
88 \sa baseclass ConfigItem
90 virtual void Commit();
92 // public interface
93 bool m_bVisibleImpressView;
94 bool m_bVisibleOutlineView;
95 bool m_bVisibleNotesView;
96 bool m_bVisibleHandoutView;
97 bool m_bVisibleSlideSorterView;
99 private:
100 /** return list of key names of our configuration management which represent oue module tree
102 These methods return a static const list of key names. We need it to get needed values from our
103 configuration management.
105 \return A list of needed configuration keys is returned.
107 static Sequence< OUString > GetPropertyNames();
109 protected:
112 SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()
113 // Init baseclasses first
114 : ConfigItem( ROOTNODE_TOOLPANEL )
116 , m_bVisibleImpressView( false )
117 , m_bVisibleOutlineView( false )
118 , m_bVisibleNotesView( false )
119 , m_bVisibleHandoutView( false )
120 , m_bVisibleSlideSorterView( false )
123 m_seqPropertyNames = GetPropertyNames( );
125 // Use our static list of configuration keys to get his values.
126 Sequence< Any > seqValues = GetProperties( m_seqPropertyNames );
128 // Safe impossible cases.
129 // We need values from ALL configuration keys.
130 // Follow assignment use order of values in relation to our list of key names!
131 DBG_ASSERT( !(m_seqPropertyNames.getLength()!=seqValues.getLength()),
132 "SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()\nI miss some values of configuration keys!\n" );
134 // Copy values from list in right order to our internal member.
135 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
137 if (seqValues[nProperty].hasValue()==sal_False)
138 continue;
139 switch( nProperty )
141 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW :
143 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
144 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleImpressView\"!" );
145 break;
147 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
149 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
150 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleOutlineView\"!" );
151 break;
153 case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
155 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
156 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleNotesView\"!" );
157 break;
159 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
161 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
162 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleHandoutView\"!" );
163 break;
165 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
167 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
168 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleSlideSorterView\"!" );
169 break;
174 // Enable notification mechanism of our baseclass.
175 // We need it to get information about changes outside these class on our used configuration keys!
176 EnableNotification( m_seqPropertyNames );
179 SvtToolPanelOptions_Impl::~SvtToolPanelOptions_Impl()
181 Commit();
184 static int lcl_MapPropertyName( const OUString rCompare,
185 const uno::Sequence< OUString>& aInternalPropertyNames)
187 for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
189 if( aInternalPropertyNames[nProp] == rCompare )
190 return nProp;
192 return -1;
195 void SvtToolPanelOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
197 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
198 Sequence< Any > seqValues = GetProperties( rPropertyNames );
200 // Safe impossible cases.
201 // We need values from ALL configuration keys.
202 // Follow assignment use order of values in relation to our list of key names!
203 DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()),
204 "SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()\nI miss some values of configuration keys!\n" );
206 // Copy values from list in right order to our internal member.
207 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
209 if (seqValues[nProperty].hasValue()==sal_False)
210 continue;
211 switch( lcl_MapPropertyName(rPropertyNames[nProperty], aInternalPropertyNames) )
213 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
215 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
216 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleImpressView\"!" );
218 break;
219 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
221 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
222 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleOutlineView\"!" );
224 break;
225 case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
227 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
228 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleNotesView\"!" );
230 break;
231 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
233 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
234 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleHandoutView\"!" );
236 break;
237 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
239 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
240 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleSlideSorterView\"!" );
242 break;
247 void SvtToolPanelOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
249 Load( rPropertyNames );
252 void SvtToolPanelOptions_Impl::Commit()
254 // Get names of supported properties, create a list for values and copy current values to it.
255 sal_Int32 nCount = m_seqPropertyNames.getLength();
256 Sequence< Any > seqValues ( nCount );
257 for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
259 switch( nProperty )
261 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
263 seqValues[nProperty] <<= m_bVisibleImpressView;
264 break;
266 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW:
268 seqValues[nProperty] <<= m_bVisibleOutlineView;
269 break;
271 case PROPERTYHANDLE_VISIBLE_NOTESVIEW:
273 seqValues[nProperty] <<= m_bVisibleNotesView;
274 break;
276 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW:
278 seqValues[nProperty] <<= m_bVisibleHandoutView;
279 break;
281 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW:
283 seqValues[nProperty] <<= m_bVisibleSlideSorterView;
284 break;
288 // Set properties in configuration.
289 PutProperties( m_seqPropertyNames, seqValues );
292 Sequence< OUString > SvtToolPanelOptions_Impl::GetPropertyNames()
294 // Build list of configuration key names.
295 OUString pProperties[] =
297 PROPERTYNAME_VISIBLE_IMPRESSVIEW,
298 PROPERTYNAME_VISIBLE_OUTLINEVIEW,
299 PROPERTYNAME_VISIBLE_NOTESVIEW,
300 PROPERTYNAME_VISIBLE_HANDOUTVIEW,
301 PROPERTYNAME_VISIBLE_SLIDESORTERVIEW,
304 // Initialize return sequence with these list and run
305 return Sequence< OUString >( pProperties, SAL_N_ELEMENTS( pProperties ) );
308 // initialize static member, see definition for further information
309 // DON'T DO IT IN YOUR HEADER!
310 SvtToolPanelOptions_Impl* SvtToolPanelOptions::m_pDataContainer = NULL;
311 sal_Int32 SvtToolPanelOptions::m_nRefCount = 0;
313 SvtToolPanelOptions::SvtToolPanelOptions()
315 // Global access, must be guarded (multithreading!).
316 MutexGuard aGuard( GetInitMutex() );
317 ++m_nRefCount;
318 // ... and initialize our data container only if it not already exist!
319 if( m_pDataContainer == NULL )
321 RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtToolPanelOptions_Impl::ctor()");
322 m_pDataContainer = new SvtToolPanelOptions_Impl;
326 SvtToolPanelOptions::~SvtToolPanelOptions()
328 // Global access, must be guarded (multithreading!)
329 MutexGuard aGuard( GetInitMutex() );
330 --m_nRefCount;
331 // If last instance was deleted we must destroy our static data container!
332 if( m_nRefCount <= 0 )
334 delete m_pDataContainer;
335 m_pDataContainer = NULL;
339 bool SvtToolPanelOptions::GetVisibleImpressView() const
341 return m_pDataContainer->m_bVisibleImpressView;
344 void SvtToolPanelOptions::SetVisibleImpressView(bool bVisible)
346 m_pDataContainer->m_bVisibleImpressView = bVisible;
349 bool SvtToolPanelOptions::GetVisibleOutlineView() const
351 return m_pDataContainer->m_bVisibleOutlineView;
354 void SvtToolPanelOptions::SetVisibleOutlineView(bool bVisible)
356 m_pDataContainer->m_bVisibleOutlineView = bVisible;
359 bool SvtToolPanelOptions::GetVisibleNotesView() const
361 return m_pDataContainer->m_bVisibleNotesView;
364 void SvtToolPanelOptions::SetVisibleNotesView(bool bVisible)
366 m_pDataContainer->m_bVisibleNotesView = bVisible;
369 bool SvtToolPanelOptions::GetVisibleHandoutView() const
371 return m_pDataContainer->m_bVisibleHandoutView;
374 void SvtToolPanelOptions::SetVisibleHandoutView(bool bVisible)
376 m_pDataContainer->m_bVisibleHandoutView = bVisible;
379 bool SvtToolPanelOptions::GetVisibleSlideSorterView() const
381 return m_pDataContainer->m_bVisibleSlideSorterView;
384 void SvtToolPanelOptions::SetVisibleSlideSorterView(bool bVisible)
386 m_pDataContainer->m_bVisibleSlideSorterView = bVisible;
389 namespace
391 class theSvtToolPanelOptionsMutex :
392 public rtl::Static< osl::Mutex, theSvtToolPanelOptionsMutex > {};
395 Mutex & SvtToolPanelOptions::GetInitMutex()
397 return theSvtToolPanelOptionsMutex::get();
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */