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 "navigationbar.hxx"
21 :
22 : #include <com/sun/star/text/WritingMode2.hpp>
23 :
24 : #include <comphelper/streamsection.hxx>
25 : #include <comphelper/basicio.hxx>
26 : #include <comphelper/processfactory.hxx>
27 :
28 : namespace frm
29 : {
30 :
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::beans;
33 : using namespace ::com::sun::star::form;
34 : using namespace ::com::sun::star::awt;
35 : using namespace ::com::sun::star::io;
36 : using namespace ::com::sun::star::lang;
37 : using namespace ::com::sun::star::util;
38 : using namespace ::com::sun::star::container;
39 : using namespace ::comphelper;
40 :
41 : namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
42 :
43 : #define REGISTER_VOID_PROP( prop, memberAny, type ) \
44 : registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT | PropertyAttribute::MAYBEVOID, \
45 : &memberAny, cppu::UnoType<type>::get() );
46 :
47 11 : ONavigationBarModel::ONavigationBarModel( const Reference< XComponentContext >& _rxFactory )
48 : :OControlModel( _rxFactory, OUString() )
49 11 : ,FontControlModel( true )
50 : {
51 :
52 11 : m_nClassId = FormComponentType::NAVIGATIONBAR;
53 11 : implInitPropertyContainer();
54 :
55 11 : getPropertyDefaultByHandle( PROPERTY_ID_DEFAULTCONTROL ) >>= m_sDefaultControl;
56 11 : getPropertyDefaultByHandle( PROPERTY_ID_ICONSIZE ) >>= m_nIconSize;
57 11 : getPropertyDefaultByHandle( PROPERTY_ID_BORDER ) >>= m_nBorder;
58 11 : getPropertyDefaultByHandle( PROPERTY_ID_DELAY ) >>= m_nDelay;
59 11 : getPropertyDefaultByHandle( PROPERTY_ID_ENABLED ) >>= m_bEnabled;
60 11 : getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE ) >>= m_bEnableVisible;
61 11 : getPropertyDefaultByHandle( PROPERTY_ID_SHOW_POSITION ) >>= m_bShowPosition;
62 11 : getPropertyDefaultByHandle( PROPERTY_ID_SHOW_NAVIGATION ) >>= m_bShowNavigation;
63 11 : getPropertyDefaultByHandle( PROPERTY_ID_SHOW_RECORDACTIONS ) >>= m_bShowActions;
64 11 : getPropertyDefaultByHandle( PROPERTY_ID_SHOW_FILTERSORT ) >>= m_bShowFilterSort;
65 11 : getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE ) >>= m_nWritingMode;
66 11 : getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE ) >>= m_nContextWritingMode;
67 11 : }
68 :
69 :
70 1 : ONavigationBarModel::ONavigationBarModel( const ONavigationBarModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
71 : :OControlModel( _pOriginal, _rxFactory )
72 1 : ,FontControlModel( _pOriginal )
73 : {
74 :
75 1 : implInitPropertyContainer();
76 :
77 1 : m_aTabStop = _pOriginal->m_aTabStop;
78 1 : m_aBackgroundColor = _pOriginal->m_aBackgroundColor;
79 1 : m_sDefaultControl = _pOriginal->m_sDefaultControl;
80 1 : m_sHelpText = _pOriginal->m_sHelpText;
81 1 : m_sHelpURL = _pOriginal->m_sHelpURL;
82 1 : m_bEnabled = _pOriginal->m_bEnabled;
83 1 : m_bEnableVisible = _pOriginal->m_bEnableVisible;
84 1 : m_nIconSize = _pOriginal->m_nIconSize;
85 1 : m_nBorder = _pOriginal->m_nBorder;
86 1 : m_nDelay = _pOriginal->m_nDelay;
87 1 : m_bShowPosition = _pOriginal->m_bShowPosition;
88 1 : m_bShowNavigation = _pOriginal->m_bShowNavigation;
89 1 : m_bShowActions = _pOriginal->m_bShowActions;
90 1 : m_bShowFilterSort = _pOriginal->m_bShowFilterSort;
91 1 : m_nWritingMode = _pOriginal->m_nWritingMode;
92 1 : m_nContextWritingMode = _pOriginal->m_nContextWritingMode;
93 1 : }
94 :
95 :
96 12 : void ONavigationBarModel::implInitPropertyContainer()
97 : {
98 12 : REGISTER_PROP_2( DEFAULTCONTROL, m_sDefaultControl, BOUND, MAYBEDEFAULT );
99 12 : REGISTER_PROP_2( HELPTEXT, m_sHelpText, BOUND, MAYBEDEFAULT );
100 12 : REGISTER_PROP_2( HELPURL, m_sHelpURL, BOUND, MAYBEDEFAULT );
101 12 : REGISTER_PROP_2( ENABLED, m_bEnabled, BOUND, MAYBEDEFAULT );
102 12 : REGISTER_PROP_2( ENABLEVISIBLE, m_bEnableVisible, BOUND, MAYBEDEFAULT );
103 12 : REGISTER_PROP_2( ICONSIZE, m_nIconSize, BOUND, MAYBEDEFAULT );
104 12 : REGISTER_PROP_2( BORDER, m_nBorder, BOUND, MAYBEDEFAULT );
105 12 : REGISTER_PROP_2( DELAY, m_nDelay, BOUND, MAYBEDEFAULT );
106 12 : REGISTER_PROP_2( SHOW_POSITION, m_bShowPosition, BOUND, MAYBEDEFAULT );
107 12 : REGISTER_PROP_2( SHOW_NAVIGATION, m_bShowNavigation, BOUND, MAYBEDEFAULT );
108 12 : REGISTER_PROP_2( SHOW_RECORDACTIONS, m_bShowActions, BOUND, MAYBEDEFAULT );
109 12 : REGISTER_PROP_2( SHOW_FILTERSORT, m_bShowFilterSort, BOUND, MAYBEDEFAULT );
110 12 : REGISTER_PROP_2( WRITING_MODE, m_nWritingMode, BOUND, MAYBEDEFAULT );
111 12 : REGISTER_PROP_3( CONTEXT_WRITING_MODE,m_nContextWritingMode, BOUND, MAYBEDEFAULT, TRANSIENT );
112 :
113 12 : REGISTER_VOID_PROP( TABSTOP, m_aTabStop, sal_Bool );
114 12 : REGISTER_VOID_PROP( BACKGROUNDCOLOR, m_aBackgroundColor, sal_Int32 );
115 12 : }
116 :
117 :
118 36 : ONavigationBarModel::~ONavigationBarModel()
119 : {
120 12 : if ( !OComponentHelper::rBHelper.bDisposed )
121 : {
122 0 : acquire();
123 0 : dispose();
124 : }
125 :
126 24 : }
127 :
128 :
129 3247 : Any SAL_CALL ONavigationBarModel::queryAggregation( const Type& _rType ) throw ( RuntimeException, std::exception )
130 : {
131 3247 : Any aReturn = ONavigationBarModel_BASE::queryInterface( _rType );
132 :
133 3247 : if ( !aReturn.hasValue() )
134 1181 : aReturn = OControlModel::queryAggregation( _rType );
135 :
136 3247 : return aReturn;
137 : }
138 :
139 :
140 2 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarModel, OControlModel, ONavigationBarModel_BASE )
141 :
142 :
143 1 : IMPLEMENT_DEFAULT_CLONING( ONavigationBarModel )
144 :
145 :
146 7 : OUString SAL_CALL ONavigationBarModel::getImplementationName() throw(RuntimeException, std::exception)
147 : {
148 7 : return getImplementationName_Static();
149 : }
150 :
151 :
152 6 : Sequence< OUString > SAL_CALL ONavigationBarModel::getSupportedServiceNames() throw(RuntimeException, std::exception)
153 : {
154 6 : return getSupportedServiceNames_Static();
155 : }
156 :
157 7 : OUString SAL_CALL ONavigationBarModel::getImplementationName_Static()
158 : {
159 7 : return OUString( "com.sun.star.comp.form.ONavigationBarModel" );
160 : }
161 :
162 6 : Sequence< OUString > SAL_CALL ONavigationBarModel::getSupportedServiceNames_Static()
163 : {
164 6 : Sequence< OUString > aSupported = OControlModel::getSupportedServiceNames_Static();
165 6 : aSupported.realloc( aSupported.getLength() + 2 );
166 :
167 6 : OUString* pArray = aSupported.getArray();
168 6 : pArray[ aSupported.getLength() - 2 ] = "com.sun.star.awt.UnoControlModel";
169 6 : pArray[ aSupported.getLength() - 1 ] = FRM_SUN_COMPONENT_NAVTOOLBAR;
170 6 : return aSupported;
171 : }
172 :
173 12 : void SAL_CALL ONavigationBarModel::disposing()
174 : {
175 12 : OControlModel::disposing( );
176 12 : }
177 :
178 1 : OUString SAL_CALL ONavigationBarModel::getServiceName() throw ( RuntimeException, std::exception )
179 : {
180 1 : return OUString(FRM_SUN_COMPONENT_NAVTOOLBAR);
181 : }
182 :
183 : #define PERSIST_TABSTOP 0x0001
184 : #define PERSIST_BACKGROUND 0x0002
185 : #define PERSIST_TEXTCOLOR 0x0004
186 : #define PERSIST_TEXTLINECOLOR 0x0008
187 :
188 : #define PERSIST_ENABLED 0x0001
189 : #define PERSIST_LARGEICONS 0x0002
190 : // leaf a leap here - this will allow for two more icon size values to be stored compatibly
191 : #define PERSIST_SHOW_POSITION 0x0008
192 : #define PERSIST_SHOW_NAVIGATION 0x0010
193 : #define PERSIST_SHOW_ACTIONS 0x0020
194 : #define PERSIST_SHOW_FILTERSORT 0x0040
195 :
196 :
197 1 : void SAL_CALL ONavigationBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream ) throw ( IOException, RuntimeException, std::exception )
198 : {
199 : // open a section for compatibility - if we later on write additional members,
200 : // then older versions can skip them
201 1 : OStreamSection aEnsureBlockCompat( _rxOutStream );
202 :
203 : // base class
204 1 : OControlModel::write( _rxOutStream );
205 :
206 : {
207 1 : OStreamSection aEnsureCompat( _rxOutStream );
208 : // determine which properties are not void and need to be written
209 1 : sal_Int32 nNonVoids = 0;
210 1 : if ( m_aTabStop.hasValue() )
211 0 : nNonVoids |= PERSIST_TABSTOP;
212 1 : if ( m_aBackgroundColor.hasValue() )
213 0 : nNonVoids |= PERSIST_BACKGROUND;
214 1 : if ( hasTextColor() )
215 0 : nNonVoids |= PERSIST_TEXTCOLOR;
216 1 : if ( hasTextLineColor() )
217 0 : nNonVoids |= PERSIST_TEXTLINECOLOR;
218 :
219 1 : _rxOutStream->writeLong( nNonVoids );
220 :
221 : // the maybeboid anys
222 1 : if ( nNonVoids & PERSIST_TABSTOP )
223 : {
224 0 : bool bTabStop( false );
225 0 : m_aTabStop >>= bTabStop;
226 0 : _rxOutStream->writeBoolean( bTabStop );
227 : }
228 1 : if ( nNonVoids & PERSIST_BACKGROUND )
229 : {
230 0 : sal_Int32 nBackgroundColor = 0;
231 0 : m_aBackgroundColor >>= nBackgroundColor;
232 0 : _rxOutStream->writeLong( nBackgroundColor );
233 : }
234 1 : if ( nNonVoids & PERSIST_TEXTCOLOR )
235 : {
236 0 : _rxOutStream->writeLong( getTextColor() );
237 : }
238 1 : if ( nNonVoids & PERSIST_TEXTLINECOLOR )
239 : {
240 0 : _rxOutStream->writeLong( getTextLineColor() );
241 1 : }
242 : }
243 :
244 : {
245 1 : OStreamSection aEnsureCompat( _rxOutStream );
246 1 : ::comphelper::operator<<( _rxOutStream, getFont() );
247 : }
248 :
249 : // our boolean flags
250 1 : sal_Int32 nFlags = 0;
251 1 : if ( m_bEnabled ) nFlags |= PERSIST_ENABLED;
252 1 : if ( m_nIconSize ) nFlags |= PERSIST_LARGEICONS; // at the moment, this is quasi boolean
253 1 : if ( m_bShowPosition ) nFlags |= PERSIST_SHOW_POSITION;
254 1 : if ( m_bShowNavigation ) nFlags |= PERSIST_SHOW_NAVIGATION;
255 1 : if ( m_bShowActions ) nFlags |= PERSIST_SHOW_ACTIONS;
256 1 : if ( m_bShowFilterSort ) nFlags |= PERSIST_SHOW_FILTERSORT;
257 1 : _rxOutStream->writeLong( nFlags );
258 :
259 : // our strings
260 1 : _rxOutStream->writeUTF( m_sHelpText );
261 1 : _rxOutStream->writeUTF( m_sHelpURL );
262 1 : _rxOutStream->writeUTF( m_sDefaultControl );
263 :
264 : // misc
265 1 : _rxOutStream->writeShort( m_nBorder );
266 1 : _rxOutStream->writeLong ( m_nDelay );
267 1 : }
268 :
269 :
270 1 : void SAL_CALL ONavigationBarModel::read( const Reference< XObjectInputStream >& _rxInStream ) throw ( IOException, RuntimeException, std::exception )
271 : {
272 1 : OStreamSection aEnsureBlockCompat( _rxInStream );
273 :
274 : // base class
275 1 : OControlModel::read( _rxInStream );
276 :
277 : {
278 1 : OStreamSection aEnsureCompat( _rxInStream );
279 : // determine which properties were non-void
280 1 : sal_Int32 nNonVoids = _rxInStream->readLong( );
281 :
282 : // the maybeboid anys
283 1 : if ( nNonVoids & PERSIST_TABSTOP )
284 0 : m_aTabStop = makeAny( _rxInStream->readBoolean() );
285 : else
286 1 : m_aTabStop.clear();
287 :
288 1 : if ( nNonVoids & PERSIST_BACKGROUND )
289 0 : m_aBackgroundColor = makeAny( _rxInStream->readLong() );
290 : else
291 1 : m_aBackgroundColor.clear();
292 :
293 1 : if ( nNonVoids & PERSIST_TEXTCOLOR )
294 0 : setTextColor( _rxInStream->readLong() );
295 : else
296 1 : clearTextColor();
297 :
298 1 : if ( nNonVoids & PERSIST_TEXTLINECOLOR )
299 0 : setTextLineColor( _rxInStream->readLong() );
300 : else
301 1 : clearTextLineColor();
302 : }
303 :
304 : {
305 1 : OStreamSection aEnsureCompat( _rxInStream );
306 2 : FontDescriptor aFont;
307 1 : ::comphelper::operator>>( _rxInStream, aFont );
308 2 : setFont( aFont );
309 : }
310 :
311 : // our boolean flags
312 1 : sal_Int32 nFlags = _rxInStream->readLong( );
313 1 : m_bEnabled = ( nFlags & PERSIST_ENABLED ) != 0;
314 1 : m_nIconSize = ( nFlags & PERSIST_LARGEICONS ) ? 1 : 0;
315 1 : m_bShowPosition = ( nFlags & PERSIST_SHOW_POSITION ) != 0;
316 1 : m_bShowNavigation = ( nFlags & PERSIST_SHOW_NAVIGATION ) != 0;
317 1 : m_bShowActions = ( nFlags & PERSIST_SHOW_ACTIONS ) != 0;
318 1 : m_bShowFilterSort = ( nFlags & PERSIST_SHOW_FILTERSORT ) != 0;
319 :
320 : // our strings
321 1 : m_sHelpText = _rxInStream->readUTF( );
322 1 : m_sHelpURL = _rxInStream->readUTF( );
323 1 : m_sDefaultControl = _rxInStream->readUTF( );
324 :
325 : // misc
326 1 : m_nBorder = _rxInStream->readShort();
327 1 : m_nDelay = _rxInStream->readLong();
328 1 : }
329 :
330 :
331 2271 : void SAL_CALL ONavigationBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
332 : {
333 2271 : if ( isRegisteredProperty( _nHandle ) )
334 : {
335 948 : OPropertyContainerHelper::getFastPropertyValue( _rValue, _nHandle );
336 : }
337 1323 : else if ( isFontRelatedProperty( _nHandle ) )
338 : {
339 645 : FontControlModel::getFastPropertyValue( _rValue, _nHandle );
340 : }
341 : else
342 : {
343 678 : OControlModel::getFastPropertyValue( _rValue, _nHandle );
344 : }
345 2271 : }
346 :
347 :
348 801 : sal_Bool SAL_CALL ONavigationBarModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue,
349 : sal_Int32 _nHandle, const Any& _rValue ) throw( IllegalArgumentException )
350 : {
351 801 : bool bModified = false;
352 :
353 801 : if ( isRegisteredProperty( _nHandle ) )
354 : {
355 456 : bModified = OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
356 : }
357 345 : else if ( isFontRelatedProperty( _nHandle ) )
358 : {
359 145 : bModified = FontControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
360 : }
361 : else
362 : {
363 200 : bModified = OControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
364 : }
365 :
366 800 : return bModified;
367 : }
368 :
369 :
370 274 : void SAL_CALL ONavigationBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception, std::exception )
371 : {
372 274 : if ( isRegisteredProperty( _nHandle ) )
373 : {
374 128 : OPropertyContainerHelper::setFastPropertyValue( _nHandle, _rValue );
375 : }
376 146 : else if ( isFontRelatedProperty( _nHandle ) )
377 : {
378 : FontControlModel::setFastPropertyValue_NoBroadcast_impl(
379 : *this, &ONavigationBarModel::setDependentFastPropertyValue,
380 79 : _nHandle, _rValue);
381 : }
382 : else
383 : {
384 67 : OControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
385 : }
386 274 : }
387 :
388 :
389 136 : Any ONavigationBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
390 : {
391 136 : Any aDefault;
392 :
393 136 : switch ( _nHandle )
394 : {
395 : case PROPERTY_ID_TABSTOP:
396 : case PROPERTY_ID_BACKGROUNDCOLOR:
397 : /* void */
398 4 : break;
399 : case PROPERTY_ID_WRITING_MODE:
400 : case PROPERTY_ID_CONTEXT_WRITING_MODE:
401 22 : aDefault <<= WritingMode2::CONTEXT;
402 22 : break;
403 :
404 : case PROPERTY_ID_ENABLED:
405 : case PROPERTY_ID_ENABLEVISIBLE:
406 : case PROPERTY_ID_SHOW_POSITION:
407 : case PROPERTY_ID_SHOW_NAVIGATION:
408 : case PROPERTY_ID_SHOW_RECORDACTIONS:
409 : case PROPERTY_ID_SHOW_FILTERSORT:
410 66 : aDefault <<= true;
411 66 : break;
412 :
413 : case PROPERTY_ID_ICONSIZE:
414 11 : aDefault <<= (sal_Int16)0;
415 11 : break;
416 :
417 : case PROPERTY_ID_DEFAULTCONTROL:
418 11 : aDefault <<= OUString( "com.sun.star.form.control.NavigationToolBar" );
419 11 : break;
420 :
421 : case PROPERTY_ID_HELPTEXT:
422 : case PROPERTY_ID_HELPURL:
423 0 : aDefault <<= OUString();
424 0 : break;
425 :
426 : case PROPERTY_ID_BORDER:
427 11 : aDefault <<= (sal_Int16)0;
428 11 : break;
429 :
430 : case PROPERTY_ID_DELAY:
431 11 : aDefault <<= (sal_Int32)20;
432 11 : break;
433 :
434 : default:
435 0 : if ( isFontRelatedProperty( _nHandle ) )
436 0 : aDefault = FontControlModel::getPropertyDefaultByHandle( _nHandle );
437 : else
438 0 : aDefault = OControlModel::getPropertyDefaultByHandle( _nHandle );
439 : }
440 136 : return aDefault;
441 : }
442 :
443 :
444 12 : void ONavigationBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
445 : {
446 12 : BEGIN_DESCRIBE_PROPERTIES( 1, OControlModel )
447 12 : DECL_PROP2( TABINDEX, sal_Int16, BOUND, MAYBEDEFAULT );
448 : END_DESCRIBE_PROPERTIES();
449 :
450 : // properties which the OPropertyContainerHelper is responsible for
451 12 : Sequence< Property > aContainedProperties;
452 12 : describeProperties( aContainedProperties );
453 :
454 : // properties which the FontControlModel is responsible for
455 24 : Sequence< Property > aFontProperties;
456 12 : describeFontRelatedProperties( aFontProperties );
457 :
458 24 : _rProps = concatSequences(
459 : aContainedProperties,
460 : aFontProperties,
461 : _rProps
462 24 : );
463 12 : }
464 :
465 : } // namespace frm
466 :
467 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* SAL_CALL
468 11 : com_sun_star_comp_form_ONavigationBarModel_get_implementation(css::uno::XComponentContext* context,
469 : css::uno::Sequence<css::uno::Any> const &)
470 : {
471 11 : return cppu::acquire(new frm::ONavigationBarModel(context));
472 : }
473 :
474 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|