merge the formfield patch from ooo-build
[ooovba.git] / forms / source / component / navigationbar.cxx
blob54e0b0eb4f38da1125d90dc95c26a0ca37bde77a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: navigationbar.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "navigationbar.hxx"
34 #include "frm_module.hxx"
36 #include <com/sun/star/text/WritingMode2.hpp>
38 #include <comphelper/streamsection.hxx>
39 #include <comphelper/basicio.hxx>
41 //--------------------------------------------------------------------------
42 extern "C" void SAL_CALL createRegistryInfo_ONavigationBarModel()
44 static ::frm::OMultiInstanceAutoRegistration< ::frm::ONavigationBarModel > aAutoRegistration;
47 //.........................................................................
48 namespace frm
50 //.........................................................................
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::form;
55 using namespace ::com::sun::star::awt;
56 using namespace ::com::sun::star::io;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::util;
59 using namespace ::com::sun::star::container;
60 using namespace ::comphelper;
62 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
64 #define REGISTER_VOID_PROP( prop, memberAny, type ) \
65 registerMayBeVoidProperty( PROPERTY_##prop, PROPERTY_ID_##prop, PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT | PropertyAttribute::MAYBEVOID, \
66 &memberAny, ::getCppuType( static_cast< type* >( NULL ) ) );
68 //==================================================================
69 // ONavigationBarModel
70 //==================================================================
71 DBG_NAME( ONavigationBarModel )
72 //------------------------------------------------------------------
73 ONavigationBarModel::ONavigationBarModel( const Reference< XMultiServiceFactory >& _rxFactory )
74 :OControlModel( _rxFactory, ::rtl::OUString() )
75 ,FontControlModel( true )
77 DBG_CTOR( ONavigationBarModel, NULL );
79 m_nClassId = FormComponentType::NAVIGATIONBAR;
80 implInitPropertyContainer();
82 getPropertyDefaultByHandle( PROPERTY_ID_DEFAULTCONTROL ) >>= m_sDefaultControl;
83 getPropertyDefaultByHandle( PROPERTY_ID_ICONSIZE ) >>= m_nIconSize;
84 getPropertyDefaultByHandle( PROPERTY_ID_BORDER ) >>= m_nBorder;
85 getPropertyDefaultByHandle( PROPERTY_ID_DELAY ) >>= m_nDelay;
86 getPropertyDefaultByHandle( PROPERTY_ID_ENABLED ) >>= m_bEnabled;
87 getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE ) >>= m_bEnableVisible;
88 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_POSITION ) >>= m_bShowPosition;
89 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_NAVIGATION ) >>= m_bShowNavigation;
90 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_RECORDACTIONS ) >>= m_bShowActions;
91 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_FILTERSORT ) >>= m_bShowFilterSort;
92 getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE ) >>= m_nWritingMode;
93 getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE ) >>= m_nContextWritingMode;
96 //------------------------------------------------------------------
97 ONavigationBarModel::ONavigationBarModel( const ONavigationBarModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
98 :OControlModel( _pOriginal, _rxFactory )
99 ,FontControlModel( _pOriginal )
101 DBG_CTOR( ONavigationBarModel, NULL );
103 implInitPropertyContainer();
105 m_aTabStop = _pOriginal->m_aTabStop;
106 m_aBackgroundColor = _pOriginal->m_aBackgroundColor;
107 m_sDefaultControl = _pOriginal->m_sDefaultControl;
108 m_sHelpText = _pOriginal->m_sHelpText;
109 m_sHelpURL = _pOriginal->m_sHelpURL;
110 m_bEnabled = _pOriginal->m_bEnabled;
111 m_bEnableVisible = _pOriginal->m_bEnableVisible;
112 m_nIconSize = _pOriginal->m_nIconSize;
113 m_nBorder = _pOriginal->m_nBorder;
114 m_nDelay = _pOriginal->m_nDelay;
115 m_bShowPosition = _pOriginal->m_bShowPosition;
116 m_bShowNavigation = _pOriginal->m_bShowNavigation;
117 m_bShowActions = _pOriginal->m_bShowActions;
118 m_bShowFilterSort = _pOriginal->m_bShowFilterSort;
119 m_nWritingMode = _pOriginal->m_nWritingMode;
120 m_nContextWritingMode = _pOriginal->m_nContextWritingMode;
123 //------------------------------------------------------------------
124 void ONavigationBarModel::implInitPropertyContainer()
126 REGISTER_PROP_2( DEFAULTCONTROL, m_sDefaultControl, BOUND, MAYBEDEFAULT );
127 REGISTER_PROP_2( HELPTEXT, m_sHelpText, BOUND, MAYBEDEFAULT );
128 REGISTER_PROP_2( HELPURL, m_sHelpURL, BOUND, MAYBEDEFAULT );
129 REGISTER_PROP_2( ENABLED, m_bEnabled, BOUND, MAYBEDEFAULT );
130 REGISTER_PROP_2( ENABLEVISIBLE, m_bEnableVisible, BOUND, MAYBEDEFAULT );
131 REGISTER_PROP_2( ICONSIZE, m_nIconSize, BOUND, MAYBEDEFAULT );
132 REGISTER_PROP_2( BORDER, m_nBorder, BOUND, MAYBEDEFAULT );
133 REGISTER_PROP_2( DELAY, m_nDelay, BOUND, MAYBEDEFAULT );
134 REGISTER_PROP_2( SHOW_POSITION, m_bShowPosition, BOUND, MAYBEDEFAULT );
135 REGISTER_PROP_2( SHOW_NAVIGATION, m_bShowNavigation, BOUND, MAYBEDEFAULT );
136 REGISTER_PROP_2( SHOW_RECORDACTIONS, m_bShowActions, BOUND, MAYBEDEFAULT );
137 REGISTER_PROP_2( SHOW_FILTERSORT, m_bShowFilterSort, BOUND, MAYBEDEFAULT );
138 REGISTER_PROP_2( WRITING_MODE, m_nWritingMode, BOUND, MAYBEDEFAULT );
139 REGISTER_PROP_3( CONTEXT_WRITING_MODE,m_nContextWritingMode, BOUND, MAYBEDEFAULT, TRANSIENT );
141 REGISTER_VOID_PROP( TABSTOP, m_aTabStop, sal_Bool );
142 REGISTER_VOID_PROP( BACKGROUNDCOLOR, m_aBackgroundColor, sal_Int32 );
145 //------------------------------------------------------------------
146 ONavigationBarModel::~ONavigationBarModel()
148 if ( !OComponentHelper::rBHelper.bDisposed )
150 acquire();
151 dispose();
154 DBG_DTOR( ONavigationBarModel, NULL );
157 //------------------------------------------------------------------
158 Any SAL_CALL ONavigationBarModel::queryAggregation( const Type& _rType ) throw ( RuntimeException )
160 Any aReturn = ONavigationBarModel_BASE::queryInterface( _rType );
162 if ( !aReturn.hasValue() )
163 aReturn = OControlModel::queryAggregation( _rType );
165 return aReturn;
168 //------------------------------------------------------------------
169 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarModel, OControlModel, ONavigationBarModel_BASE )
171 //------------------------------------------------------------------------------
172 IMPLEMENT_DEFAULT_CLONING( ONavigationBarModel )
174 //------------------------------------------------------------------
175 ::rtl::OUString SAL_CALL ONavigationBarModel::getImplementationName() throw(RuntimeException)
177 return getImplementationName_Static();
180 //------------------------------------------------------------------
181 Sequence< ::rtl::OUString > SAL_CALL ONavigationBarModel::getSupportedServiceNames() throw(RuntimeException)
183 return getSupportedServiceNames_Static();
186 //------------------------------------------------------------------
187 ::rtl::OUString SAL_CALL ONavigationBarModel::getImplementationName_Static()
189 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.form.ONavigationBarModel" ) );
192 //------------------------------------------------------------------
193 Sequence< ::rtl::OUString > SAL_CALL ONavigationBarModel::getSupportedServiceNames_Static()
195 Sequence< ::rtl::OUString > aSupported = OControlModel::getSupportedServiceNames_Static();
196 aSupported.realloc( aSupported.getLength() + 2 );
198 ::rtl::OUString* pArray = aSupported.getArray();
199 pArray[ aSupported.getLength() - 2 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlModel" ) );
200 pArray[ aSupported.getLength() - 1 ] = FRM_SUN_COMPONENT_NAVTOOLBAR;
201 return aSupported;
204 //------------------------------------------------------------------
205 Reference< XInterface > SAL_CALL ONavigationBarModel::Create( const Reference< XMultiServiceFactory >& _rxFactory )
207 return *( new ONavigationBarModel( _rxFactory ) );
210 //------------------------------------------------------------------
211 void SAL_CALL ONavigationBarModel::disposing()
213 OControlModel::disposing( );
216 //------------------------------------------------------------------
217 ::rtl::OUString SAL_CALL ONavigationBarModel::getServiceName() throw ( RuntimeException )
219 return FRM_SUN_COMPONENT_NAVTOOLBAR;
222 //------------------------------------------------------------------
223 #define PERSIST_TABSTOP 0x0001
224 #define PERSIST_BACKGROUND 0x0002
225 #define PERSIST_TEXTCOLOR 0x0004
226 #define PERSIST_TEXTLINECOLOR 0x0008
228 #define PERSIST_ENABLED 0x0001
229 #define PERSIST_LARGEICONS 0x0002
230 // leaf a leap here - this will allow for two more icon size values to be stored compatibly
231 #define PERSIST_SHOW_POSITION 0x0008
232 #define PERSIST_SHOW_NAVIGATION 0x0010
233 #define PERSIST_SHOW_ACTIONS 0x0020
234 #define PERSIST_SHOW_FILTERSORT 0x0040
236 //------------------------------------------------------------------
237 void SAL_CALL ONavigationBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream ) throw ( IOException, RuntimeException )
239 // open a section for compatibility - if we later on write additional members,
240 // then older versions can skip them
241 Reference< XDataOutputStream > xDataOut( _rxOutStream, UNO_QUERY );
242 OStreamSection aEnsureBlockCompat( xDataOut );
244 // base class
245 OControlModel::write( _rxOutStream );
248 OStreamSection aEnsureCompat( xDataOut );
249 // determine which properties are not void and need to be written
250 sal_Int32 nNonVoids = 0;
251 if ( m_aTabStop.hasValue() )
252 nNonVoids |= PERSIST_TABSTOP;
253 if ( m_aBackgroundColor.hasValue() )
254 nNonVoids |= PERSIST_BACKGROUND;
255 if ( hasTextColor() )
256 nNonVoids |= PERSIST_TEXTCOLOR;
257 if ( hasTextLineColor() )
258 nNonVoids |= PERSIST_TEXTLINECOLOR;
260 _rxOutStream->writeLong( nNonVoids );
262 // the maybeboid anys
263 if ( nNonVoids & PERSIST_TABSTOP )
265 sal_Bool bTabStop( sal_False );
266 m_aTabStop >>= bTabStop;
267 _rxOutStream->writeBoolean( bTabStop );
269 if ( nNonVoids & PERSIST_BACKGROUND )
271 sal_Int32 nBackgroundColor = 0;
272 m_aBackgroundColor >>= nBackgroundColor;
273 _rxOutStream->writeLong( nBackgroundColor );
275 if ( nNonVoids & PERSIST_TEXTCOLOR )
277 _rxOutStream->writeLong( getTextColor() );
279 if ( nNonVoids & PERSIST_TEXTLINECOLOR )
281 _rxOutStream->writeLong( getTextLineColor() );
286 OStreamSection aEnsureCompat( xDataOut );
287 ::comphelper::operator<<( _rxOutStream, getFont() );
290 // our boolean flags
291 sal_Int32 nFlags = 0;
292 if ( m_bEnabled ) nFlags |= PERSIST_ENABLED;
293 if ( m_nIconSize ) nFlags |= PERSIST_LARGEICONS; // at the moment, this is quasi boolean
294 if ( m_bShowPosition ) nFlags |= PERSIST_SHOW_POSITION;
295 if ( m_bShowNavigation ) nFlags |= PERSIST_SHOW_NAVIGATION;
296 if ( m_bShowActions ) nFlags |= PERSIST_SHOW_ACTIONS;
297 if ( m_bShowFilterSort ) nFlags |= PERSIST_SHOW_FILTERSORT;
298 _rxOutStream->writeLong( nFlags );
300 // our strings
301 _rxOutStream->writeUTF( m_sHelpText );
302 _rxOutStream->writeUTF( m_sHelpURL );
303 _rxOutStream->writeUTF( m_sDefaultControl );
305 // misc
306 _rxOutStream->writeShort( m_nBorder );
307 _rxOutStream->writeLong ( m_nDelay );
310 //------------------------------------------------------------------
311 void SAL_CALL ONavigationBarModel::read( const Reference< XObjectInputStream >& _rxInStream ) throw ( IOException, RuntimeException )
313 Reference< XDataInputStream > xDataIn( _rxInStream, UNO_QUERY );
314 OStreamSection aEnsureBlockCompat( xDataIn );
316 // base class
317 OControlModel::read( _rxInStream );
320 OStreamSection aEnsureCompat( xDataIn );
321 // determine which properties were non-void
322 sal_Int32 nNonVoids = _rxInStream->readLong( );
324 // the maybeboid anys
325 if ( nNonVoids & PERSIST_TABSTOP )
326 m_aTabStop = makeAny( _rxInStream->readBoolean() );
327 else
328 m_aTabStop.clear();
330 if ( nNonVoids & PERSIST_BACKGROUND )
331 m_aBackgroundColor = makeAny( _rxInStream->readLong() );
332 else
333 m_aBackgroundColor.clear();
335 if ( nNonVoids & PERSIST_TEXTCOLOR )
336 setTextColor( _rxInStream->readLong() );
337 else
338 clearTextColor();
340 if ( nNonVoids & PERSIST_TEXTLINECOLOR )
341 setTextLineColor( _rxInStream->readLong() );
342 else
343 clearTextLineColor();
347 OStreamSection aEnsureCompat( xDataIn );
348 FontDescriptor aFont;
349 ::comphelper::operator>>( _rxInStream, aFont );
350 setFont( aFont );
353 // our boolean flags
354 sal_Int32 nFlags = _rxInStream->readLong( );
355 m_bEnabled = ( nFlags & PERSIST_ENABLED ) ? sal_True : sal_False;
356 m_nIconSize = ( nFlags & PERSIST_LARGEICONS ) ? 1 : 0;
357 m_bShowPosition = ( nFlags & PERSIST_SHOW_POSITION ) ? sal_True : sal_False;
358 m_bShowNavigation = ( nFlags & PERSIST_SHOW_NAVIGATION ) ? sal_True : sal_False;
359 m_bShowActions = ( nFlags & PERSIST_SHOW_ACTIONS ) ? sal_True : sal_False;
360 m_bShowFilterSort = ( nFlags & PERSIST_SHOW_FILTERSORT ) ? sal_True : sal_False;
362 // our strings
363 m_sHelpText = _rxInStream->readUTF( );
364 m_sHelpURL = _rxInStream->readUTF( );
365 m_sDefaultControl = _rxInStream->readUTF( );
367 // misc
368 m_nBorder = _rxInStream->readShort();
369 m_nDelay = _rxInStream->readLong();
372 //------------------------------------------------------------------
373 void SAL_CALL ONavigationBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
375 if ( isRegisteredProperty( _nHandle ) )
377 OPropertyContainerHelper::getFastPropertyValue( _rValue, _nHandle );
379 else if ( isFontRelatedProperty( _nHandle ) )
381 FontControlModel::getFastPropertyValue( _rValue, _nHandle );
383 else
385 OControlModel::getFastPropertyValue( _rValue, _nHandle );
389 //------------------------------------------------------------------
390 sal_Bool SAL_CALL ONavigationBarModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue,
391 sal_Int32 _nHandle, const Any& _rValue ) throw( IllegalArgumentException )
393 sal_Bool bModified = sal_False;
395 if ( isRegisteredProperty( _nHandle ) )
397 bModified = OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
399 else if ( isFontRelatedProperty( _nHandle ) )
401 bModified = FontControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
403 else
405 bModified = OControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
408 return bModified;
411 //------------------------------------------------------------------
412 void SAL_CALL ONavigationBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
414 if ( isRegisteredProperty( _nHandle ) )
416 OPropertyContainerHelper::setFastPropertyValue( _nHandle, _rValue );
418 else if ( isFontRelatedProperty( _nHandle ) )
420 FontDescriptor aOldFont( getFont() );
422 FontControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
424 if ( isFontAggregateProperty( _nHandle ) )
425 firePropertyChange( PROPERTY_ID_FONT, makeAny( getFont() ), makeAny( aOldFont ) );
427 else
429 OControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
433 //------------------------------------------------------------------
434 Any ONavigationBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
436 Any aDefault;
438 switch ( _nHandle )
440 case PROPERTY_ID_TABSTOP:
441 case PROPERTY_ID_BACKGROUNDCOLOR:
442 /* void */
443 break;
444 case PROPERTY_ID_WRITING_MODE:
445 case PROPERTY_ID_CONTEXT_WRITING_MODE:
446 aDefault <<= WritingMode2::CONTEXT;
447 break;
449 case PROPERTY_ID_ENABLED:
450 case PROPERTY_ID_ENABLEVISIBLE:
451 case PROPERTY_ID_SHOW_POSITION:
452 case PROPERTY_ID_SHOW_NAVIGATION:
453 case PROPERTY_ID_SHOW_RECORDACTIONS:
454 case PROPERTY_ID_SHOW_FILTERSORT:
455 aDefault <<= (sal_Bool)sal_True;
456 break;
458 case PROPERTY_ID_ICONSIZE:
459 aDefault <<= (sal_Int16)0;
460 break;
462 case PROPERTY_ID_DEFAULTCONTROL:
463 aDefault <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.control.NavigationToolBar" ) );
464 break;
466 case PROPERTY_ID_HELPTEXT:
467 case PROPERTY_ID_HELPURL:
468 aDefault <<= ::rtl::OUString();
469 break;
471 case PROPERTY_ID_BORDER:
472 aDefault <<= (sal_Int16)0;
473 break;
475 case PROPERTY_ID_DELAY:
476 aDefault <<= (sal_Int32)20;
477 break;
479 default:
480 if ( isFontRelatedProperty( _nHandle ) )
481 aDefault = FontControlModel::getPropertyDefaultByHandle( _nHandle );
482 else
483 aDefault = OControlModel::getPropertyDefaultByHandle( _nHandle );
485 return aDefault;
488 //------------------------------------------------------------------
489 void ONavigationBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
491 BEGIN_DESCRIBE_PROPERTIES( 1, OControlModel )
492 DECL_PROP2( TABINDEX, sal_Int16, BOUND, MAYBEDEFAULT );
493 END_DESCRIBE_PROPERTIES();
495 // properties which the OPropertyContainerHelper is responsible for
496 Sequence< Property > aContainedProperties;
497 describeProperties( aContainedProperties );
499 // properties which the FontControlModel is responsible for
500 Sequence< Property > aFontProperties;
501 describeFontRelatedProperties( aFontProperties );
503 _rProps = concatSequences(
504 aContainedProperties,
505 aFontProperties,
506 _rProps
510 //.........................................................................
511 } // namespace frm
512 //.........................................................................