Branch data Line data Source code
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 : :
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>
26 : : #include <tools/link.hxx>
27 : :
28 : : #include <rtl/logfile.hxx>
29 : : #include <rtl/instance.hxx>
30 : : #include "itemholder2.hxx"
31 : :
32 : : #include <svtools/imgdef.hxx>
33 : : #include <vcl/svapp.hxx>
34 : :
35 : : #include <list>
36 : :
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;
42 : :
43 : : #define ROOTNODE_SLIDESORTERBAR OUString("Office.Impress/MultiPaneGUI/SlideSorterBar/Visible")
44 : :
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
55 : : #define PROPERTYNAME_VISIBLE_DRAWVIEW OUString("DrawView")
56 : : #define PROPERTYHANDLE_VISIBLE_DRAWVIEW 5
57 : :
58 : : #define PROPERTYCOUNT 6
59 : :
60 : : class SvtSlideSorterBarOptions_Impl : public ConfigItem
61 : : {
62 : : private:
63 : : ::std::list<Link> aList;
64 : : Sequence< OUString > m_seqPropertyNames;
65 : :
66 : : public:
67 : :
68 : : SvtSlideSorterBarOptions_Impl();
69 : : ~SvtSlideSorterBarOptions_Impl();
70 : :
71 : : /** called for notify of configmanager
72 : :
73 : : These method is called from the ConfigManager before application ends or from the
74 : : PropertyChangeListener if the sub tree broadcasts changes. You must update your
75 : : internal values.
76 : :
77 : : \sa baseclass ConfigItem
78 : : \param[in,out] seqPropertyNames is the list of properties which should be updated.
79 : : */
80 : : virtual void Notify( const Sequence< OUString >& seqPropertyNames );
81 : :
82 : : /**
83 : : loads required data from the configuration. It's called in the constructor to
84 : : read all entries and form ::Notify to re-read changed setting
85 : : */
86 : : void Load( const Sequence< OUString >& rPropertyNames );
87 : :
88 : : /** write changes to configuration
89 : :
90 : : These method writes the changed values into the sub tree
91 : : and should always called in our destructor to guarantee consistency of config data.
92 : :
93 : : \sa baseclass ConfigItem
94 : : */
95 : : virtual void Commit();
96 : :
97 : : // public interface
98 : : bool m_bVisibleImpressView;
99 : : bool m_bVisibleOutlineView;
100 : : bool m_bVisibleNotesView;
101 : : bool m_bVisibleHandoutView;
102 : : bool m_bVisibleSlideSorterView;
103 : : bool m_bVisibleDrawView;
104 : :
105 : : void AddListenerLink( const Link& rLink );
106 : : void RemoveListenerLink( const Link& rLink );
107 : : void CallListeners();
108 : :
109 : : private:
110 : : /** return list of key names of our configuration management which represent oue module tree
111 : :
112 : : These methods return a static const list of key names. We need it to get needed values from our
113 : : configuration management.
114 : :
115 : : \return A list of needed configuration keys is returned.
116 : : */
117 : : static Sequence< OUString > GetPropertyNames();
118 : :
119 : : protected:
120 : : };
121 : :
122 : 1560 : SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()
123 : : // Init baseclasses first
124 : : : ConfigItem( ROOTNODE_SLIDESORTERBAR )
125 : :
126 : : , m_bVisibleImpressView( false )
127 : : , m_bVisibleOutlineView( false )
128 : : , m_bVisibleNotesView( false )
129 : : , m_bVisibleHandoutView( false )
130 : : , m_bVisibleSlideSorterView( false )
131 [ + - ][ + - ]: 1560 : , m_bVisibleDrawView( false )
[ + - ]
132 : :
133 : : {
134 [ + - ][ + - ]: 1560 : m_seqPropertyNames = GetPropertyNames( );
[ + - ]
135 : :
136 : : // Use our static list of configuration keys to get his values.
137 [ + - ]: 1560 : Sequence< Any > seqValues = GetProperties( m_seqPropertyNames );
138 : :
139 : : // Safe impossible cases.
140 : : // We need values from ALL configuration keys.
141 : : // Follow assignment use order of values in relation to our list of key names!
142 : : DBG_ASSERT( !(m_seqPropertyNames.getLength()!=seqValues.getLength()),
143 : : "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
144 : :
145 : : // Copy values from list in right order to our internal member.
146 [ + + ]: 10920 : for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
147 : : {
148 [ + - ][ - + ]: 9360 : if (seqValues[nProperty].hasValue()==sal_False)
149 : 0 : continue;
150 [ + + + + : 9360 : switch( nProperty )
+ + - ]
151 : : {
152 : : case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW :
153 : : {
154 [ + - ]: 1560 : if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
155 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
156 : 1560 : break;
157 : : }
158 : : case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
159 : : {
160 [ + - ]: 1560 : if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
161 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
162 : 1560 : break;
163 : : }
164 : : case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
165 : : {
166 [ + - ]: 1560 : if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
167 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
168 : 1560 : break;
169 : : }
170 : : case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
171 : : {
172 [ + - ]: 1560 : if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
173 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
174 : 1560 : break;
175 : : }
176 : : case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
177 : : {
178 [ + - ]: 1560 : if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
179 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
180 : 1560 : break;
181 : : }
182 : : case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
183 : : {
184 [ + - ]: 1560 : if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
185 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
186 : 1560 : break;
187 : : }
188 : : }
189 : : }
190 : :
191 : : // Enable notification mechanism of our baseclass.
192 : : // We need it to get information about changes outside these class on our used configuration keys!
193 [ + - ][ + - ]: 1560 : EnableNotification( m_seqPropertyNames );
194 : 1560 : }
195 : :
196 [ + - ]: 1560 : SvtSlideSorterBarOptions_Impl::~SvtSlideSorterBarOptions_Impl()
197 : : {
198 [ + - ]: 1560 : Commit();
199 [ - + ]: 3120 : }
200 : :
201 : 0 : static int lcl_MapPropertyName( const ::rtl::OUString rCompare,
202 : : const uno::Sequence< ::rtl::OUString>& aInternalPropertyNames)
203 : : {
204 [ # # ]: 0 : for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
205 : : {
206 [ # # ]: 0 : if( aInternalPropertyNames[nProp] == rCompare )
207 : 0 : return nProp;
208 : : }
209 : 0 : return -1;
210 : : }
211 : :
212 : 0 : void SvtSlideSorterBarOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
213 : : {
214 [ # # ]: 0 : const uno::Sequence< ::rtl::OUString> aInternalPropertyNames( GetPropertyNames());
215 [ # # ]: 0 : Sequence< Any > seqValues = GetProperties( rPropertyNames );
216 : :
217 : : // Safe impossible cases.
218 : : // We need values from ALL configuration keys.
219 : : // Follow assignment use order of values in relation to our list of key names!
220 : : DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()),
221 : : "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
222 : :
223 : : // Copy values from list in right order to our internal member.
224 [ # # ]: 0 : for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
225 : : {
226 [ # # ][ # # ]: 0 : if (seqValues[nProperty].hasValue()==sal_False)
227 : 0 : continue;
228 [ # # ][ # # : 0 : switch( lcl_MapPropertyName(rPropertyNames[nProperty], aInternalPropertyNames) )
# # # #
# ]
229 : : {
230 : : case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
231 : : {
232 [ # # ]: 0 : if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
233 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
234 : : }
235 : 0 : break;
236 : : case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
237 : : {
238 [ # # ]: 0 : if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
239 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
240 : : }
241 : 0 : break;
242 : : case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
243 : : {
244 [ # # ]: 0 : if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
245 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
246 : : }
247 : 0 : break;
248 : : case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
249 : : {
250 [ # # ]: 0 : if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
251 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
252 : : }
253 : 0 : break;
254 : : case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
255 : : {
256 [ # # ]: 0 : if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
257 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
258 : : }
259 : 0 : break;
260 : :
261 : : case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
262 : : {
263 [ # # ]: 0 : if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
264 : : OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
265 : : }
266 : 0 : break;
267 : : }
268 [ # # ][ # # ]: 0 : }
269 : 0 : }
270 : :
271 : 0 : void SvtSlideSorterBarOptions_Impl::AddListenerLink( const Link& rLink )
272 : : {
273 : 0 : aList.push_back( rLink );
274 : 0 : }
275 : :
276 : 0 : void SvtSlideSorterBarOptions_Impl::RemoveListenerLink( const Link& rLink )
277 : : {
278 [ # # ][ # # ]: 0 : for ( ::std::list<Link>::iterator iter = aList.begin(); iter != aList.end(); ++iter )
[ # # ]
279 : : {
280 [ # # ][ # # ]: 0 : if ( *iter == rLink )
[ # # ]
281 : : {
282 [ # # ]: 0 : aList.erase(iter);
283 : 0 : break;
284 : : }
285 : : }
286 : 0 : }
287 : :
288 : 0 : void SvtSlideSorterBarOptions_Impl::CallListeners()
289 : : {
290 [ # # ][ # # ]: 0 : for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
[ # # ][ # # ]
[ # # ]
291 [ # # ][ # # ]: 0 : iter->Call( this );
292 : 0 : }
293 : :
294 : 0 : void SvtSlideSorterBarOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
295 : : {
296 : 0 : Load( rPropertyNames );
297 : 0 : CallListeners();
298 : 0 : }
299 : :
300 : 1560 : void SvtSlideSorterBarOptions_Impl::Commit()
301 : : {
302 : : // Get names of supported properties, create a list for values and copy current values to it.
303 : 1560 : sal_Int32 nCount = m_seqPropertyNames.getLength();
304 [ + - ]: 1560 : Sequence< Any > seqValues ( nCount );
305 [ + + ]: 10920 : for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
306 : : {
307 [ + + + + : 9360 : switch( nProperty )
+ + - ]
308 : : {
309 : : case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
310 : : {
311 [ + - ][ + - ]: 1560 : seqValues[nProperty] <<= m_bVisibleImpressView;
312 : 1560 : break;
313 : : }
314 : : case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW:
315 : : {
316 [ + - ][ + - ]: 1560 : seqValues[nProperty] <<= m_bVisibleOutlineView;
317 : 1560 : break;
318 : : }
319 : : case PROPERTYHANDLE_VISIBLE_NOTESVIEW:
320 : : {
321 [ + - ][ + - ]: 1560 : seqValues[nProperty] <<= m_bVisibleNotesView;
322 : 1560 : break;
323 : : }
324 : : case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW:
325 : : {
326 [ + - ][ + - ]: 1560 : seqValues[nProperty] <<= m_bVisibleHandoutView;
327 : 1560 : break;
328 : : }
329 : : case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW:
330 : : {
331 [ + - ][ + - ]: 1560 : seqValues[nProperty] <<= m_bVisibleSlideSorterView;
332 : 1560 : break;
333 : : }
334 : : case PROPERTYHANDLE_VISIBLE_DRAWVIEW:
335 : : {
336 [ + - ][ + - ]: 1560 : seqValues[nProperty] <<= m_bVisibleDrawView;
337 : 1560 : break;
338 : : }
339 : :
340 : : }
341 : : }
342 : : // Set properties in configuration.
343 [ + - ][ + - ]: 1560 : PutProperties( m_seqPropertyNames, seqValues );
344 : 1560 : }
345 : :
346 : 1560 : Sequence< OUString > SvtSlideSorterBarOptions_Impl::GetPropertyNames()
347 : : {
348 : : // Build list of configuration key names.
349 : : OUString pProperties[] =
350 : : {
351 : : PROPERTYNAME_VISIBLE_IMPRESSVIEW,
352 : : PROPERTYNAME_VISIBLE_OUTLINEVIEW,
353 : : PROPERTYNAME_VISIBLE_NOTESVIEW,
354 : : PROPERTYNAME_VISIBLE_HANDOUTVIEW,
355 : : PROPERTYNAME_VISIBLE_SLIDESORTERVIEW,
356 : : PROPERTYNAME_VISIBLE_DRAWVIEW,
357 : 10920 : };
358 : :
359 : : // Initialize return sequence with these list and run
360 [ + + ][ # # ]: 10920 : return Sequence< OUString >( pProperties, SAL_N_ELEMENTS( pProperties ) );
[ + - ]
361 : : }
362 : :
363 : : // initialize static member, see definition for further information
364 : : // DON'T DO IT IN YOUR HEADER!
365 : : SvtSlideSorterBarOptions_Impl* SvtSlideSorterBarOptions::m_pDataContainer = NULL ;
366 : : sal_Int32 SvtSlideSorterBarOptions::m_nRefCount = 0 ;
367 : :
368 : 1560 : SvtSlideSorterBarOptions::SvtSlideSorterBarOptions()
369 : : {
370 : : // Global access, must be guarded (multithreading!).
371 [ + - ][ + - ]: 1560 : MutexGuard aGuard( GetInitMutex() );
372 : 1560 : ++m_nRefCount;
373 : : // ... and initialize our data container only if it not already exist!
374 [ + - ]: 1560 : if( m_pDataContainer == NULL )
375 : : {
376 : : RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtSlideSorterBarOptions_Impl::ctor()");
377 [ + - ][ + - ]: 1560 : m_pDataContainer = new SvtSlideSorterBarOptions_Impl;
378 [ + - ]: 1560 : }
379 : 1560 : }
380 : :
381 : 1560 : SvtSlideSorterBarOptions::~SvtSlideSorterBarOptions()
382 : : {
383 : : // Global access, must be guarded (multithreading!)
384 [ + - ][ + - ]: 1560 : MutexGuard aGuard( GetInitMutex() );
385 : 1560 : --m_nRefCount;
386 : : // If last instance was deleted we must destroy our static data container!
387 [ + - ]: 1560 : if( m_nRefCount <= 0 )
388 : : {
389 [ + - ][ + - ]: 1560 : delete m_pDataContainer;
390 : 1560 : m_pDataContainer = NULL;
391 [ + - ]: 1560 : }
392 [ - + ]: 1560 : }
393 : :
394 : 130 : bool SvtSlideSorterBarOptions::GetVisibleImpressView() const
395 : : {
396 : 130 : return m_pDataContainer->m_bVisibleImpressView;
397 : : }
398 : :
399 : 130 : void SvtSlideSorterBarOptions::SetVisibleImpressView(bool bVisible)
400 : : {
401 : 130 : m_pDataContainer->m_bVisibleImpressView = bVisible;
402 : 130 : }
403 : :
404 : 130 : bool SvtSlideSorterBarOptions::GetVisibleOutlineView() const
405 : : {
406 : 130 : return m_pDataContainer->m_bVisibleOutlineView;
407 : : }
408 : :
409 : 130 : void SvtSlideSorterBarOptions::SetVisibleOutlineView(bool bVisible)
410 : : {
411 : 130 : m_pDataContainer->m_bVisibleOutlineView = bVisible;
412 : 130 : }
413 : :
414 : 130 : bool SvtSlideSorterBarOptions::GetVisibleNotesView() const
415 : : {
416 : 130 : return m_pDataContainer->m_bVisibleNotesView;
417 : : }
418 : :
419 : 130 : void SvtSlideSorterBarOptions::SetVisibleNotesView(bool bVisible)
420 : : {
421 : 130 : m_pDataContainer->m_bVisibleNotesView = bVisible;
422 : 130 : }
423 : :
424 : 130 : bool SvtSlideSorterBarOptions::GetVisibleHandoutView() const
425 : : {
426 : 130 : return m_pDataContainer->m_bVisibleHandoutView;
427 : : }
428 : :
429 : 130 : void SvtSlideSorterBarOptions::SetVisibleHandoutView(bool bVisible)
430 : : {
431 : 130 : m_pDataContainer->m_bVisibleHandoutView = bVisible;
432 : 130 : }
433 : :
434 : 130 : bool SvtSlideSorterBarOptions::GetVisibleSlideSorterView() const
435 : : {
436 : 130 : return m_pDataContainer->m_bVisibleSlideSorterView;
437 : : }
438 : :
439 : 130 : void SvtSlideSorterBarOptions::SetVisibleSlideSorterView(bool bVisible)
440 : : {
441 : 130 : m_pDataContainer->m_bVisibleSlideSorterView = bVisible;
442 : 130 : }
443 : :
444 : 130 : bool SvtSlideSorterBarOptions::GetVisibleDrawView() const
445 : : {
446 : 130 : return m_pDataContainer->m_bVisibleDrawView;
447 : : }
448 : :
449 : 130 : void SvtSlideSorterBarOptions::SetVisibleDrawView(bool bVisible)
450 : : {
451 : 130 : m_pDataContainer->m_bVisibleDrawView = bVisible;
452 : 130 : }
453 : :
454 : : namespace
455 : : {
456 : : class theSvtSlideSorterBarOptionsMutex :
457 : : public rtl::Static< osl::Mutex, theSvtSlideSorterBarOptionsMutex > {};
458 : : }
459 : :
460 : 3120 : Mutex & SvtSlideSorterBarOptions::GetInitMutex()
461 : : {
462 : 3120 : return theSvtSlideSorterBarOptionsMutex::get();
463 : : }
464 : :
465 : 0 : void SvtSlideSorterBarOptions::AddListenerLink( const Link& rLink )
466 : : {
467 : 0 : m_pDataContainer->AddListenerLink( rLink );
468 : 0 : }
469 : :
470 : 0 : void SvtSlideSorterBarOptions::RemoveListenerLink( const Link& rLink )
471 : : {
472 : 0 : m_pDataContainer->RemoveListenerLink( rLink );
473 : 0 : }
474 : :
475 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|