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