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