bump product version to 7.6.3.2-android
[LibreOffice.git] / svtools / source / config / slidesorterbaropt.cxx
blob784e0894ef2747f21506520c56531184e5bc6328
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/configitem.hxx>
22 #include <tools/debug.hxx>
23 #include <osl/diagnose.h>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
27 #include <comphelper/lok.hxx>
28 #include <comphelper/sequence.hxx>
29 #include <mutex>
31 using namespace ::utl;
32 using namespace ::osl;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star;
36 constexpr OUStringLiteral ROOTNODE_SLIDESORTERBAR = u"Office.Impress/MultiPaneGUI/SlideSorterBar/Visible";
38 constexpr OUStringLiteral PROPERTYNAME_VISIBLE_IMPRESSVIEW = u"ImpressView";
39 #define PROPERTYHANDLE_VISIBLE_IMPRESSVIEW 0
40 constexpr OUStringLiteral PROPERTYNAME_VISIBLE_OUTLINEVIEW = u"OutlineView";
41 #define PROPERTYHANDLE_VISIBLE_OUTLINEVIEW 1
42 constexpr OUStringLiteral PROPERTYNAME_VISIBLE_NOTESVIEW = u"NotesView";
43 #define PROPERTYHANDLE_VISIBLE_NOTESVIEW 2
44 constexpr OUStringLiteral PROPERTYNAME_VISIBLE_HANDOUTVIEW = u"HandoutView";
45 #define PROPERTYHANDLE_VISIBLE_HANDOUTVIEW 3
46 constexpr OUStringLiteral PROPERTYNAME_VISIBLE_SLIDESORTERVIEW = u"SlideSorterView";
47 #define PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW 4
48 constexpr OUStringLiteral PROPERTYNAME_VISIBLE_DRAWVIEW = u"DrawView";
49 #define PROPERTYHANDLE_VISIBLE_DRAWVIEW 5
51 static std::mutex & GetInitMutex()
53 static std::mutex theSvtSlideSorterBarOptionsMutex;
54 return theSvtSlideSorterBarOptionsMutex;
58 class SvtSlideSorterBarOptions_Impl : public ConfigItem
60 Sequence< OUString > m_seqPropertyNames;
62 public:
64 SvtSlideSorterBarOptions_Impl();
65 ~SvtSlideSorterBarOptions_Impl() override;
67 /** called for notify of configmanager
69 This method is called from the ConfigManager before the application ends or from the
70 PropertyChangeListener if the sub tree broadcasts changes. You must update your
71 internal values.
73 \sa baseclass ConfigItem
74 \param[in,out] seqPropertyNames is the list of properties which should be updated.
76 virtual void Notify( const Sequence< OUString >& seqPropertyNames ) override;
78 /**
79 loads required data from the configuration. It's called in the constructor to
80 read all entries and form ::Notify to re-read changed setting
82 void Load( const Sequence< OUString >& rPropertyNames );
84 // public interface
85 bool m_bVisibleImpressView;
86 bool m_bVisibleOutlineView;
87 bool m_bVisibleNotesView;
88 bool m_bVisibleHandoutView;
89 bool m_bVisibleSlideSorterView;
90 bool m_bVisibleDrawView;
92 private:
93 virtual void ImplCommit() final override;
95 /** return list of key names of our configuration management which represent our module tree
97 This method returns a static const list of key names. We need it to get needed values from
98 configuration management.
100 \return A list of needed configuration keys is returned.
102 static Sequence< OUString > GetPropertyNames();
104 void SetVisibleViewImpl( bool& bVisibleView, bool bVisible );
106 public:
107 void SetVisibleImpressView( bool bVisible)
108 { SetVisibleViewImpl( m_bVisibleImpressView, bVisible ); }
110 void SetVisibleOutlineView( bool bVisible)
111 { SetVisibleViewImpl( m_bVisibleOutlineView, bVisible ); }
113 void SetVisibleNotesView( bool bVisible)
114 { SetVisibleViewImpl( m_bVisibleNotesView, bVisible ); }
116 void SetVisibleHandoutView( bool bVisible)
117 { SetVisibleViewImpl( m_bVisibleHandoutView, bVisible ); }
119 void SetVisibleSlideSorterView( bool bVisible)
120 { SetVisibleViewImpl( m_bVisibleSlideSorterView, bVisible ); }
122 void SetVisibleDrawView( bool bVisible)
123 { SetVisibleViewImpl( m_bVisibleDrawView, bVisible ); }
127 SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()
128 // Init baseclasses first
129 : ConfigItem( ROOTNODE_SLIDESORTERBAR )
130 , m_seqPropertyNames(GetPropertyNames())
131 , m_bVisibleImpressView( false )
132 , m_bVisibleOutlineView( false )
133 , m_bVisibleNotesView( false )
134 , m_bVisibleHandoutView( false )
135 , m_bVisibleSlideSorterView( false )
136 , m_bVisibleDrawView( false )
139 // Use our static list of configuration keys to get his values.
140 Sequence< Any > seqValues = GetProperties( m_seqPropertyNames );
142 // Safe impossible cases.
143 // We need values from ALL configuration keys.
144 // Follow assignment use order of values in relation to our list of key names!
145 DBG_ASSERT( !(m_seqPropertyNames.getLength()!=seqValues.getLength()),
146 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
148 // Copy values from list in right order to our internal member.
149 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
151 if (!seqValues[nProperty].hasValue())
152 continue;
153 switch( nProperty )
155 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW :
157 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
158 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
159 break;
161 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
163 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
164 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
165 break;
167 case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
169 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
170 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
171 break;
173 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
175 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
176 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
177 break;
179 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
181 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
182 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
183 break;
185 case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
187 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
188 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
189 break;
194 // Enable notification mechanism of our baseclass.
195 // We need it to get information about changes outside these class on our used configuration keys!
196 EnableNotification( m_seqPropertyNames );
199 SvtSlideSorterBarOptions_Impl::~SvtSlideSorterBarOptions_Impl()
201 if (IsModified())
202 Commit();
205 void SvtSlideSorterBarOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
207 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
208 Sequence< Any > seqValues = GetProperties( rPropertyNames );
210 // Safe impossible cases.
211 // We need values from ALL configuration keys.
212 // Follow assignment use order of values in relation to our list of key names!
213 DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()),
214 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
216 // Copy values from list in right order to our internal member.
217 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
219 if (!seqValues[nProperty].hasValue())
220 continue;
221 switch( comphelper::findValue(aInternalPropertyNames, rPropertyNames[nProperty]) )
223 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
225 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
226 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
228 break;
229 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
231 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
232 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
234 break;
235 case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
237 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
238 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
240 break;
241 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
243 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
244 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
246 break;
247 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
249 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
250 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
252 break;
254 case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
256 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
257 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
259 break;
264 void SvtSlideSorterBarOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
266 Load( rPropertyNames );
269 void SvtSlideSorterBarOptions_Impl::ImplCommit()
271 // Get names of supported properties, create a list for values and copy current values to it.
272 sal_Int32 nCount = m_seqPropertyNames.getLength();
273 Sequence< Any > seqValues ( nCount );
274 auto seqValuesRange = asNonConstRange(seqValues);
275 for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
277 switch( nProperty )
279 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
281 seqValuesRange[nProperty] <<= m_bVisibleImpressView;
282 break;
284 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW:
286 seqValuesRange[nProperty] <<= m_bVisibleOutlineView;
287 break;
289 case PROPERTYHANDLE_VISIBLE_NOTESVIEW:
291 seqValuesRange[nProperty] <<= m_bVisibleNotesView;
292 break;
294 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW:
296 seqValuesRange[nProperty] <<= m_bVisibleHandoutView;
297 break;
299 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW:
301 seqValuesRange[nProperty] <<= m_bVisibleSlideSorterView;
302 break;
304 case PROPERTYHANDLE_VISIBLE_DRAWVIEW:
306 seqValuesRange[nProperty] <<= m_bVisibleDrawView;
307 break;
312 // Set properties in configuration.
313 PutProperties( m_seqPropertyNames, seqValues );
316 Sequence< OUString > SvtSlideSorterBarOptions_Impl::GetPropertyNames()
318 // Build list of configuration key names.
319 return
321 PROPERTYNAME_VISIBLE_IMPRESSVIEW,
322 PROPERTYNAME_VISIBLE_OUTLINEVIEW,
323 PROPERTYNAME_VISIBLE_NOTESVIEW,
324 PROPERTYNAME_VISIBLE_HANDOUTVIEW,
325 PROPERTYNAME_VISIBLE_SLIDESORTERVIEW,
326 PROPERTYNAME_VISIBLE_DRAWVIEW,
330 void SvtSlideSorterBarOptions_Impl::SetVisibleViewImpl( bool& bVisibleView, bool bVisible )
332 if( bVisibleView != bVisible )
334 bVisibleView = bVisible;
335 SetModified();
339 namespace {
340 std::weak_ptr<SvtSlideSorterBarOptions_Impl> g_pSlideSorterBarOptions;
343 SvtSlideSorterBarOptions::SvtSlideSorterBarOptions()
345 // Global access, must be guarded (multithreading!).
346 std::unique_lock aGuard( GetInitMutex() );
348 m_pImpl = g_pSlideSorterBarOptions.lock();
349 if( !m_pImpl )
351 m_pImpl = std::make_shared<SvtSlideSorterBarOptions_Impl>();
352 g_pSlideSorterBarOptions = m_pImpl;
356 SvtSlideSorterBarOptions::~SvtSlideSorterBarOptions()
358 // Global access, must be guarded (multithreading!)
359 std::unique_lock aGuard( GetInitMutex() );
361 m_pImpl.reset();
364 bool SvtSlideSorterBarOptions::GetVisibleImpressView() const
366 static const bool bRunningUnitTest = getenv("LO_TESTNAME");
367 return m_pImpl->m_bVisibleImpressView && (!bRunningUnitTest || !comphelper::LibreOfficeKit::isActive());
370 void SvtSlideSorterBarOptions::SetVisibleImpressView(bool bVisible)
372 m_pImpl->SetVisibleImpressView( bVisible );
375 bool SvtSlideSorterBarOptions::GetVisibleOutlineView() const
377 return m_pImpl->m_bVisibleOutlineView;
380 void SvtSlideSorterBarOptions::SetVisibleOutlineView(bool bVisible)
382 m_pImpl->SetVisibleOutlineView( bVisible );
385 bool SvtSlideSorterBarOptions::GetVisibleNotesView() const
387 return m_pImpl->m_bVisibleNotesView;
390 void SvtSlideSorterBarOptions::SetVisibleNotesView(bool bVisible)
392 m_pImpl->SetVisibleNotesView( bVisible );
395 bool SvtSlideSorterBarOptions::GetVisibleHandoutView() const
397 return m_pImpl->m_bVisibleHandoutView;
400 void SvtSlideSorterBarOptions::SetVisibleHandoutView(bool bVisible)
402 m_pImpl->SetVisibleHandoutView( bVisible );
405 bool SvtSlideSorterBarOptions::GetVisibleSlideSorterView() const
407 return m_pImpl->m_bVisibleSlideSorterView && !comphelper::LibreOfficeKit::isActive();
410 void SvtSlideSorterBarOptions::SetVisibleSlideSorterView(bool bVisible)
412 m_pImpl->SetVisibleSlideSorterView( bVisible );
415 bool SvtSlideSorterBarOptions::GetVisibleDrawView() const
417 return m_pImpl->m_bVisibleDrawView;
420 void SvtSlideSorterBarOptions::SetVisibleDrawView(bool bVisible)
422 m_pImpl->SetVisibleDrawView( bVisible );
425 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */