1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/instance.hxx>
29 #include "itemholder2.hxx"
31 #include <svtools/imgdef.hxx>
32 #include <vcl/svapp.hxx>
36 using namespace ::utl
;
37 using namespace ::rtl
;
38 using namespace ::osl
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star
;
42 #define ROOTNODE_TOOLPANEL OUString("Office.Impress/MultiPaneGUI/ToolPanel/Visible")
44 #define PROPERTYNAME_VISIBLE_IMPRESSVIEW OUString("ImpressView")
45 #define PROPERTYHANDLE_VISIBLE_IMPRESSVIEW 0
46 #define PROPERTYNAME_VISIBLE_OUTLINEVIEW OUString("OutlineView")
47 #define PROPERTYHANDLE_VISIBLE_OUTLINEVIEW 1
48 #define PROPERTYNAME_VISIBLE_NOTESVIEW OUString("NotesView")
49 #define PROPERTYHANDLE_VISIBLE_NOTESVIEW 2
50 #define PROPERTYNAME_VISIBLE_HANDOUTVIEW OUString("HandoutView")
51 #define PROPERTYHANDLE_VISIBLE_HANDOUTVIEW 3
52 #define PROPERTYNAME_VISIBLE_SLIDESORTERVIEW OUString("SlideSorterView")
53 #define PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW 4
55 class SvtToolPanelOptions_Impl
: public ConfigItem
58 Sequence
< OUString
> m_seqPropertyNames
;
62 SvtToolPanelOptions_Impl();
63 ~SvtToolPanelOptions_Impl();
65 /** called for notify of configmanager
67 These method is called from the ConfigManager before application ends or from the
68 PropertyChangeListener if the sub tree broadcasts changes. You must update your
71 \sa baseclass ConfigItem
72 \param[in,out] seqPropertyNames is the list of properties which should be updated.
74 virtual void Notify( const Sequence
< OUString
>& seqPropertyNames
);
77 loads required data from the configuration. It's called in the constructor to
78 read all entries and form ::Notify to re-read changed setting
80 void Load( const Sequence
< OUString
>& rPropertyNames
);
82 /** write changes to configuration
84 These method writes the changed values into the sub tree
85 and should always called in our destructor to guarantee consistency of config data.
87 \sa baseclass ConfigItem
89 virtual void Commit();
92 bool m_bVisibleImpressView
;
93 bool m_bVisibleOutlineView
;
94 bool m_bVisibleNotesView
;
95 bool m_bVisibleHandoutView
;
96 bool m_bVisibleSlideSorterView
;
99 /** return list of key names of our configuration management which represent oue module tree
101 These methods return a static const list of key names. We need it to get needed values from our
102 configuration management.
104 \return A list of needed configuration keys is returned.
106 static Sequence
< OUString
> GetPropertyNames();
111 SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()
112 // Init baseclasses first
113 : ConfigItem( ROOTNODE_TOOLPANEL
)
115 , m_bVisibleImpressView( false )
116 , m_bVisibleOutlineView( false )
117 , m_bVisibleNotesView( false )
118 , m_bVisibleHandoutView( false )
119 , m_bVisibleSlideSorterView( false )
122 m_seqPropertyNames
= GetPropertyNames( );
124 // Use our static list of configuration keys to get his values.
125 Sequence
< Any
> seqValues
= GetProperties( m_seqPropertyNames
);
127 // Safe impossible cases.
128 // We need values from ALL configuration keys.
129 // Follow assignment use order of values in relation to our list of key names!
130 DBG_ASSERT( !(m_seqPropertyNames
.getLength()!=seqValues
.getLength()),
131 "SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()\nI miss some values of configuration keys!\n" );
133 // Copy values from list in right order to our internal member.
134 for( sal_Int32 nProperty
=0; nProperty
<seqValues
.getLength(); ++nProperty
)
136 if (seqValues
[nProperty
].hasValue()==sal_False
)
140 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW
:
142 if( !(seqValues
[nProperty
] >>= m_bVisibleImpressView
) )
143 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleImpressView\"!" );
146 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW
:
148 if( !(seqValues
[nProperty
] >>= m_bVisibleOutlineView
) )
149 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleOutlineView\"!" );
152 case PROPERTYHANDLE_VISIBLE_NOTESVIEW
:
154 if( !(seqValues
[nProperty
] >>= m_bVisibleNotesView
) )
155 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleNotesView\"!" );
158 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW
:
160 if( !(seqValues
[nProperty
] >>= m_bVisibleHandoutView
) )
161 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleHandoutView\"!" );
164 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW
:
166 if( !(seqValues
[nProperty
] >>= m_bVisibleSlideSorterView
) )
167 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleSlideSorterView\"!" );
173 // Enable notification mechanism of our baseclass.
174 // We need it to get information about changes outside these class on our used configuration keys!
175 EnableNotification( m_seqPropertyNames
);
178 SvtToolPanelOptions_Impl::~SvtToolPanelOptions_Impl()
183 static int lcl_MapPropertyName( const OUString rCompare
,
184 const uno::Sequence
< OUString
>& aInternalPropertyNames
)
186 for(int nProp
= 0; nProp
< aInternalPropertyNames
.getLength(); ++nProp
)
188 if( aInternalPropertyNames
[nProp
] == rCompare
)
194 void SvtToolPanelOptions_Impl::Load( const Sequence
< OUString
>& rPropertyNames
)
196 const uno::Sequence
< OUString
> aInternalPropertyNames( GetPropertyNames());
197 Sequence
< Any
> seqValues
= GetProperties( rPropertyNames
);
199 // Safe impossible cases.
200 // We need values from ALL configuration keys.
201 // Follow assignment use order of values in relation to our list of key names!
202 DBG_ASSERT( !(rPropertyNames
.getLength()!=seqValues
.getLength()),
203 "SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()\nI miss some values of configuration keys!\n" );
205 // Copy values from list in right order to our internal member.
206 for( sal_Int32 nProperty
=0; nProperty
<seqValues
.getLength(); ++nProperty
)
208 if (seqValues
[nProperty
].hasValue()==sal_False
)
210 switch( lcl_MapPropertyName(rPropertyNames
[nProperty
], aInternalPropertyNames
) )
212 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW
:
214 if( !(seqValues
[nProperty
] >>= m_bVisibleImpressView
) )
215 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleImpressView\"!" );
218 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW
:
220 if( !(seqValues
[nProperty
] >>= m_bVisibleOutlineView
) )
221 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleOutlineView\"!" );
224 case PROPERTYHANDLE_VISIBLE_NOTESVIEW
:
226 if( !(seqValues
[nProperty
] >>= m_bVisibleNotesView
) )
227 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleNotesView\"!" );
230 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW
:
232 if( !(seqValues
[nProperty
] >>= m_bVisibleHandoutView
) )
233 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleHandoutView\"!" );
236 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW
:
238 if( !(seqValues
[nProperty
] >>= m_bVisibleSlideSorterView
) )
239 OSL_FAIL("Wrong type of \"ToolPanel\\VisibleSlideSorterView\"!" );
246 void SvtToolPanelOptions_Impl::Notify( const Sequence
< OUString
>& rPropertyNames
)
248 Load( rPropertyNames
);
251 void SvtToolPanelOptions_Impl::Commit()
253 // Get names of supported properties, create a list for values and copy current values to it.
254 sal_Int32 nCount
= m_seqPropertyNames
.getLength();
255 Sequence
< Any
> seqValues ( nCount
);
256 for( sal_Int32 nProperty
=0; nProperty
<nCount
; ++nProperty
)
260 case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW
:
262 seqValues
[nProperty
] <<= m_bVisibleImpressView
;
265 case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW
:
267 seqValues
[nProperty
] <<= m_bVisibleOutlineView
;
270 case PROPERTYHANDLE_VISIBLE_NOTESVIEW
:
272 seqValues
[nProperty
] <<= m_bVisibleNotesView
;
275 case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW
:
277 seqValues
[nProperty
] <<= m_bVisibleHandoutView
;
280 case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW
:
282 seqValues
[nProperty
] <<= m_bVisibleSlideSorterView
;
287 // Set properties in configuration.
288 PutProperties( m_seqPropertyNames
, seqValues
);
291 Sequence
< OUString
> SvtToolPanelOptions_Impl::GetPropertyNames()
293 // Build list of configuration key names.
294 OUString pProperties
[] =
296 PROPERTYNAME_VISIBLE_IMPRESSVIEW
,
297 PROPERTYNAME_VISIBLE_OUTLINEVIEW
,
298 PROPERTYNAME_VISIBLE_NOTESVIEW
,
299 PROPERTYNAME_VISIBLE_HANDOUTVIEW
,
300 PROPERTYNAME_VISIBLE_SLIDESORTERVIEW
,
303 // Initialize return sequence with these list and run
304 return Sequence
< OUString
>( pProperties
, SAL_N_ELEMENTS( pProperties
) );
307 // initialize static member, see definition for further information
308 // DON'T DO IT IN YOUR HEADER!
309 SvtToolPanelOptions_Impl
* SvtToolPanelOptions::m_pDataContainer
= NULL
;
310 sal_Int32
SvtToolPanelOptions::m_nRefCount
= 0;
312 SvtToolPanelOptions::SvtToolPanelOptions()
314 // Global access, must be guarded (multithreading!).
315 MutexGuard
aGuard( GetInitMutex() );
317 // ... and initialize our data container only if it not already exist!
318 if( m_pDataContainer
== NULL
)
320 m_pDataContainer
= new SvtToolPanelOptions_Impl
;
324 SvtToolPanelOptions::~SvtToolPanelOptions()
326 // Global access, must be guarded (multithreading!)
327 MutexGuard
aGuard( GetInitMutex() );
329 // If last instance was deleted we must destroy our static data container!
330 if( m_nRefCount
<= 0 )
332 delete m_pDataContainer
;
333 m_pDataContainer
= NULL
;
337 bool SvtToolPanelOptions::GetVisibleImpressView() const
339 return m_pDataContainer
->m_bVisibleImpressView
;
342 void SvtToolPanelOptions::SetVisibleImpressView(bool bVisible
)
344 m_pDataContainer
->m_bVisibleImpressView
= bVisible
;
347 bool SvtToolPanelOptions::GetVisibleOutlineView() const
349 return m_pDataContainer
->m_bVisibleOutlineView
;
352 void SvtToolPanelOptions::SetVisibleOutlineView(bool bVisible
)
354 m_pDataContainer
->m_bVisibleOutlineView
= bVisible
;
357 bool SvtToolPanelOptions::GetVisibleNotesView() const
359 return m_pDataContainer
->m_bVisibleNotesView
;
362 void SvtToolPanelOptions::SetVisibleNotesView(bool bVisible
)
364 m_pDataContainer
->m_bVisibleNotesView
= bVisible
;
367 bool SvtToolPanelOptions::GetVisibleHandoutView() const
369 return m_pDataContainer
->m_bVisibleHandoutView
;
372 void SvtToolPanelOptions::SetVisibleHandoutView(bool bVisible
)
374 m_pDataContainer
->m_bVisibleHandoutView
= bVisible
;
377 bool SvtToolPanelOptions::GetVisibleSlideSorterView() const
379 return m_pDataContainer
->m_bVisibleSlideSorterView
;
382 void SvtToolPanelOptions::SetVisibleSlideSorterView(bool bVisible
)
384 m_pDataContainer
->m_bVisibleSlideSorterView
= bVisible
;
389 class theSvtToolPanelOptionsMutex
:
390 public rtl::Static
< osl::Mutex
, theSvtToolPanelOptionsMutex
> {};
393 Mutex
& SvtToolPanelOptions::GetInitMutex()
395 return theSvtToolPanelOptionsMutex::get();
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */