LibreOffice Module svtools (master) 1
slidesorterbaropt.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
26
27#include <comphelper/lok.hxx>
29#include <mutex>
30
31using namespace ::utl;
32using namespace ::osl;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star;
35
36constexpr OUStringLiteral ROOTNODE_SLIDESORTERBAR = u"Office.Impress/MultiPaneGUI/SlideSorterBar/Visible";
37
38constexpr OUStringLiteral PROPERTYNAME_VISIBLE_IMPRESSVIEW = u"ImpressView";
39#define PROPERTYHANDLE_VISIBLE_IMPRESSVIEW 0
40constexpr OUStringLiteral PROPERTYNAME_VISIBLE_OUTLINEVIEW = u"OutlineView";
41#define PROPERTYHANDLE_VISIBLE_OUTLINEVIEW 1
42constexpr OUStringLiteral PROPERTYNAME_VISIBLE_NOTESVIEW = u"NotesView";
43#define PROPERTYHANDLE_VISIBLE_NOTESVIEW 2
44constexpr OUStringLiteral PROPERTYNAME_VISIBLE_HANDOUTVIEW = u"HandoutView";
45#define PROPERTYHANDLE_VISIBLE_HANDOUTVIEW 3
46constexpr OUStringLiteral PROPERTYNAME_VISIBLE_SLIDESORTERVIEW = u"SlideSorterView";
47#define PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW 4
48constexpr OUStringLiteral PROPERTYNAME_VISIBLE_DRAWVIEW = u"DrawView";
49#define PROPERTYHANDLE_VISIBLE_DRAWVIEW 5
50
51static std::mutex & GetInitMutex()
52{
53 static std::mutex theSvtSlideSorterBarOptionsMutex;
54 return theSvtSlideSorterBarOptionsMutex;
55}
56
57
58class SvtSlideSorterBarOptions_Impl : public ConfigItem
59{
60 Sequence< OUString > m_seqPropertyNames;
61
62 public:
63
66
76 virtual void Notify( const Sequence< OUString >& seqPropertyNames ) override;
77
82 void Load( const Sequence< OUString >& rPropertyNames );
83
84 // public interface
91
92 private:
93 virtual void ImplCommit() final override;
94
102 static Sequence< OUString > GetPropertyNames();
103
104 void SetVisibleViewImpl( bool& bVisibleView, bool bVisible );
105
106 public:
107 void SetVisibleImpressView( bool bVisible)
109
110 void SetVisibleOutlineView( bool bVisible)
112
113 void SetVisibleNotesView( bool bVisible)
115
116 void SetVisibleHandoutView( bool bVisible)
118
119 void SetVisibleSlideSorterView( bool bVisible)
121
122 void SetVisibleDrawView( bool bVisible)
124
125};
126
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 )
137
138{
139 // Use our static list of configuration keys to get his values.
140 Sequence< Any > seqValues = GetProperties( m_seqPropertyNames );
141
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" );
147
148 // Copy values from list in right order to our internal member.
149 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
150 {
151 if (!seqValues[nProperty].hasValue())
152 continue;
153 switch( nProperty )
154 {
156 {
157 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
158 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
159 break;
160 }
162 {
163 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
164 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
165 break;
166 }
168 {
169 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
170 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
171 break;
172 }
174 {
175 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
176 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
177 break;
178 }
180 {
181 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
182 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
183 break;
184 }
186 {
187 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
188 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
189 break;
190 }
191 }
192 }
193
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 );
197}
198
200{
201 if (IsModified())
202 Commit();
203}
204
205void SvtSlideSorterBarOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
206{
207 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
208 Sequence< Any > seqValues = GetProperties( rPropertyNames );
209
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" );
215
216 // Copy values from list in right order to our internal member.
217 for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
218 {
219 if (!seqValues[nProperty].hasValue())
220 continue;
221 switch( comphelper::findValue(aInternalPropertyNames, rPropertyNames[nProperty]) )
222 {
224 {
225 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
226 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
227 }
228 break;
230 {
231 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
232 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
233 }
234 break;
236 {
237 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
238 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
239 }
240 break;
242 {
243 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
244 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
245 }
246 break;
248 {
249 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
250 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
251 }
252 break;
253
255 {
256 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
257 OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
258 }
259 break;
260 }
261 }
262}
263
264void SvtSlideSorterBarOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
265{
266 Load( rPropertyNames );
267}
268
270{
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 )
276 {
277 switch( nProperty )
278 {
280 {
281 seqValuesRange[nProperty] <<= m_bVisibleImpressView;
282 break;
283 }
285 {
286 seqValuesRange[nProperty] <<= m_bVisibleOutlineView;
287 break;
288 }
290 {
291 seqValuesRange[nProperty] <<= m_bVisibleNotesView;
292 break;
293 }
295 {
296 seqValuesRange[nProperty] <<= m_bVisibleHandoutView;
297 break;
298 }
300 {
301 seqValuesRange[nProperty] <<= m_bVisibleSlideSorterView;
302 break;
303 }
305 {
306 seqValuesRange[nProperty] <<= m_bVisibleDrawView;
307 break;
308 }
309
310 }
311 }
312 // Set properties in configuration.
313 PutProperties( m_seqPropertyNames, seqValues );
314}
315
317{
318 // Build list of configuration key names.
319 return
320 {
327 };
328}
329
330void SvtSlideSorterBarOptions_Impl::SetVisibleViewImpl( bool& bVisibleView, bool bVisible )
331{
332 if( bVisibleView != bVisible )
333 {
334 bVisibleView = bVisible;
335 SetModified();
336 }
337}
338
339namespace {
340 std::weak_ptr<SvtSlideSorterBarOptions_Impl> g_pSlideSorterBarOptions;
341}
342
344{
345 // Global access, must be guarded (multithreading!).
346 std::unique_lock aGuard( GetInitMutex() );
347
348 m_pImpl = g_pSlideSorterBarOptions.lock();
349 if( !m_pImpl )
350 {
351 m_pImpl = std::make_shared<SvtSlideSorterBarOptions_Impl>();
352 g_pSlideSorterBarOptions = m_pImpl;
353 }
354}
355
357{
358 // Global access, must be guarded (multithreading!)
359 std::unique_lock aGuard( GetInitMutex() );
360
361 m_pImpl.reset();
362}
363
365{
366 static const bool bRunningUnitTest = getenv("LO_TESTNAME");
367 return m_pImpl->m_bVisibleImpressView && (!bRunningUnitTest || !comphelper::LibreOfficeKit::isActive());
368}
369
371{
372 m_pImpl->SetVisibleImpressView( bVisible );
373}
374
376{
377 return m_pImpl->m_bVisibleOutlineView;
378}
379
381{
382 m_pImpl->SetVisibleOutlineView( bVisible );
383}
384
386{
387 return m_pImpl->m_bVisibleNotesView;
388}
389
391{
392 m_pImpl->SetVisibleNotesView( bVisible );
393}
394
396{
397 return m_pImpl->m_bVisibleHandoutView;
398}
399
401{
402 m_pImpl->SetVisibleHandoutView( bVisible );
403}
404
406{
407 return m_pImpl->m_bVisibleSlideSorterView && !comphelper::LibreOfficeKit::isActive();
408}
409
411{
412 m_pImpl->SetVisibleSlideSorterView( bVisible );
413}
414
416{
417 return m_pImpl->m_bVisibleDrawView;
418}
419
421{
422 m_pImpl->SetVisibleDrawView( bVisible );
423}
424
425/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static Sequence< OUString > GetPropertyNames()
return list of key names of our configuration management which represent our module tree
void SetVisibleDrawView(bool bVisible)
void SetVisibleSlideSorterView(bool bVisible)
void SetVisibleOutlineView(bool bVisible)
void SetVisibleImpressView(bool bVisible)
Sequence< OUString > m_seqPropertyNames
virtual void Notify(const Sequence< OUString > &seqPropertyNames) override
called for notify of configmanager
void Load(const Sequence< OUString > &rPropertyNames)
loads required data from the configuration.
void SetVisibleNotesView(bool bVisible)
void SetVisibleHandoutView(bool bVisible)
void SetVisibleViewImpl(bool &bVisibleView, bool bVisible)
virtual void ImplCommit() final override
void SetVisibleSlideSorterView(bool bVisible)
void SetVisibleImpressView(bool bVisible)
void SetVisibleHandoutView(bool bVisible)
std::shared_ptr< SvtSlideSorterBarOptions_Impl > m_pImpl
void SetVisibleDrawView(bool bVisible)
void SetVisibleOutlineView(bool bVisible)
void SetVisibleNotesView(bool bVisible)
virtual ~SvtSlideSorterBarOptions() override
int nCount
#define DBG_ASSERT(sCon, aError)
float u
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
static std::mutex & GetInitMutex()
#define PROPERTYHANDLE_VISIBLE_IMPRESSVIEW
#define PROPERTYHANDLE_VISIBLE_OUTLINEVIEW
constexpr OUStringLiteral PROPERTYNAME_VISIBLE_DRAWVIEW
constexpr OUStringLiteral PROPERTYNAME_VISIBLE_IMPRESSVIEW
constexpr OUStringLiteral PROPERTYNAME_VISIBLE_HANDOUTVIEW
#define PROPERTYHANDLE_VISIBLE_HANDOUTVIEW
constexpr OUStringLiteral PROPERTYNAME_VISIBLE_NOTESVIEW
constexpr OUStringLiteral ROOTNODE_SLIDESORTERBAR
#define PROPERTYHANDLE_VISIBLE_NOTESVIEW
#define PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW
#define PROPERTYHANDLE_VISIBLE_DRAWVIEW
constexpr OUStringLiteral PROPERTYNAME_VISIBLE_SLIDESORTERVIEW
constexpr OUStringLiteral PROPERTYNAME_VISIBLE_OUTLINEVIEW
bool bVisible