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 "navigationbar.hxx"
22 #include <com/sun/star/text/WritingMode2.hpp>
24 #include <comphelper/streamsection.hxx>
25 #include <comphelper/basicio.hxx>
26 #include <comphelper/processfactory.hxx>
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
;
41 namespace WritingMode2
= ::com::sun::star::text::WritingMode2
;
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() );
47 ONavigationBarModel::ONavigationBarModel( const Reference
< XComponentContext
>& _rxFactory
)
48 :OControlModel( _rxFactory
, OUString() )
49 ,FontControlModel( true )
52 m_nClassId
= FormComponentType::NAVIGATIONBAR
;
53 implInitPropertyContainer();
55 getPropertyDefaultByHandle( PROPERTY_ID_DEFAULTCONTROL
) >>= m_sDefaultControl
;
56 getPropertyDefaultByHandle( PROPERTY_ID_ICONSIZE
) >>= m_nIconSize
;
57 getPropertyDefaultByHandle( PROPERTY_ID_BORDER
) >>= m_nBorder
;
58 getPropertyDefaultByHandle( PROPERTY_ID_DELAY
) >>= m_nDelay
;
59 getPropertyDefaultByHandle( PROPERTY_ID_ENABLED
) >>= m_bEnabled
;
60 getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE
) >>= m_bEnableVisible
;
61 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_POSITION
) >>= m_bShowPosition
;
62 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_NAVIGATION
) >>= m_bShowNavigation
;
63 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_RECORDACTIONS
) >>= m_bShowActions
;
64 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_FILTERSORT
) >>= m_bShowFilterSort
;
65 getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE
) >>= m_nWritingMode
;
66 getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE
) >>= m_nContextWritingMode
;
70 ONavigationBarModel::ONavigationBarModel( const ONavigationBarModel
* _pOriginal
, const Reference
< XComponentContext
>& _rxFactory
)
71 :OControlModel( _pOriginal
, _rxFactory
)
72 ,FontControlModel( _pOriginal
)
75 implInitPropertyContainer();
77 m_aTabStop
= _pOriginal
->m_aTabStop
;
78 m_aBackgroundColor
= _pOriginal
->m_aBackgroundColor
;
79 m_sDefaultControl
= _pOriginal
->m_sDefaultControl
;
80 m_sHelpText
= _pOriginal
->m_sHelpText
;
81 m_sHelpURL
= _pOriginal
->m_sHelpURL
;
82 m_bEnabled
= _pOriginal
->m_bEnabled
;
83 m_bEnableVisible
= _pOriginal
->m_bEnableVisible
;
84 m_nIconSize
= _pOriginal
->m_nIconSize
;
85 m_nBorder
= _pOriginal
->m_nBorder
;
86 m_nDelay
= _pOriginal
->m_nDelay
;
87 m_bShowPosition
= _pOriginal
->m_bShowPosition
;
88 m_bShowNavigation
= _pOriginal
->m_bShowNavigation
;
89 m_bShowActions
= _pOriginal
->m_bShowActions
;
90 m_bShowFilterSort
= _pOriginal
->m_bShowFilterSort
;
91 m_nWritingMode
= _pOriginal
->m_nWritingMode
;
92 m_nContextWritingMode
= _pOriginal
->m_nContextWritingMode
;
96 void ONavigationBarModel::implInitPropertyContainer()
98 REGISTER_PROP_2( DEFAULTCONTROL
, m_sDefaultControl
, BOUND
, MAYBEDEFAULT
);
99 REGISTER_PROP_2( HELPTEXT
, m_sHelpText
, BOUND
, MAYBEDEFAULT
);
100 REGISTER_PROP_2( HELPURL
, m_sHelpURL
, BOUND
, MAYBEDEFAULT
);
101 REGISTER_PROP_2( ENABLED
, m_bEnabled
, BOUND
, MAYBEDEFAULT
);
102 REGISTER_PROP_2( ENABLEVISIBLE
, m_bEnableVisible
, BOUND
, MAYBEDEFAULT
);
103 REGISTER_PROP_2( ICONSIZE
, m_nIconSize
, BOUND
, MAYBEDEFAULT
);
104 REGISTER_PROP_2( BORDER
, m_nBorder
, BOUND
, MAYBEDEFAULT
);
105 REGISTER_PROP_2( DELAY
, m_nDelay
, BOUND
, MAYBEDEFAULT
);
106 REGISTER_PROP_2( SHOW_POSITION
, m_bShowPosition
, BOUND
, MAYBEDEFAULT
);
107 REGISTER_PROP_2( SHOW_NAVIGATION
, m_bShowNavigation
, BOUND
, MAYBEDEFAULT
);
108 REGISTER_PROP_2( SHOW_RECORDACTIONS
, m_bShowActions
, BOUND
, MAYBEDEFAULT
);
109 REGISTER_PROP_2( SHOW_FILTERSORT
, m_bShowFilterSort
, BOUND
, MAYBEDEFAULT
);
110 REGISTER_PROP_2( WRITING_MODE
, m_nWritingMode
, BOUND
, MAYBEDEFAULT
);
111 REGISTER_PROP_3( CONTEXT_WRITING_MODE
,m_nContextWritingMode
, BOUND
, MAYBEDEFAULT
, TRANSIENT
);
113 REGISTER_VOID_PROP( TABSTOP
, m_aTabStop
, sal_Bool
);
114 REGISTER_VOID_PROP( BACKGROUNDCOLOR
, m_aBackgroundColor
, sal_Int32
);
118 ONavigationBarModel::~ONavigationBarModel()
120 if ( !OComponentHelper::rBHelper
.bDisposed
)
129 Any SAL_CALL
ONavigationBarModel::queryAggregation( const Type
& _rType
) throw ( RuntimeException
, std::exception
)
131 Any aReturn
= ONavigationBarModel_BASE::queryInterface( _rType
);
133 if ( !aReturn
.hasValue() )
134 aReturn
= OControlModel::queryAggregation( _rType
);
140 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarModel
, OControlModel
, ONavigationBarModel_BASE
)
143 IMPLEMENT_DEFAULT_CLONING( ONavigationBarModel
)
146 OUString SAL_CALL
ONavigationBarModel::getImplementationName() throw(RuntimeException
, std::exception
)
148 return getImplementationName_Static();
152 Sequence
< OUString
> SAL_CALL
ONavigationBarModel::getSupportedServiceNames() throw(RuntimeException
, std::exception
)
154 return getSupportedServiceNames_Static();
157 OUString SAL_CALL
ONavigationBarModel::getImplementationName_Static()
159 return OUString( "com.sun.star.comp.form.ONavigationBarModel" );
162 Sequence
< OUString
> SAL_CALL
ONavigationBarModel::getSupportedServiceNames_Static()
164 Sequence
< OUString
> aSupported
= OControlModel::getSupportedServiceNames_Static();
165 aSupported
.realloc( aSupported
.getLength() + 2 );
167 OUString
* pArray
= aSupported
.getArray();
168 pArray
[ aSupported
.getLength() - 2 ] = "com.sun.star.awt.UnoControlModel";
169 pArray
[ aSupported
.getLength() - 1 ] = FRM_SUN_COMPONENT_NAVTOOLBAR
;
173 void SAL_CALL
ONavigationBarModel::disposing()
175 OControlModel::disposing( );
178 OUString SAL_CALL
ONavigationBarModel::getServiceName() throw ( RuntimeException
, std::exception
)
180 return OUString(FRM_SUN_COMPONENT_NAVTOOLBAR
);
183 #define PERSIST_TABSTOP 0x0001
184 #define PERSIST_BACKGROUND 0x0002
185 #define PERSIST_TEXTCOLOR 0x0004
186 #define PERSIST_TEXTLINECOLOR 0x0008
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
197 void SAL_CALL
ONavigationBarModel::write( const Reference
< XObjectOutputStream
>& _rxOutStream
) throw ( IOException
, RuntimeException
, std::exception
)
199 // open a section for compatibility - if we later on write additional members,
200 // then older versions can skip them
201 OStreamSection
aEnsureBlockCompat( _rxOutStream
);
204 OControlModel::write( _rxOutStream
);
207 OStreamSection
aEnsureCompat( _rxOutStream
);
208 // determine which properties are not void and need to be written
209 sal_Int32 nNonVoids
= 0;
210 if ( m_aTabStop
.hasValue() )
211 nNonVoids
|= PERSIST_TABSTOP
;
212 if ( m_aBackgroundColor
.hasValue() )
213 nNonVoids
|= PERSIST_BACKGROUND
;
214 if ( hasTextColor() )
215 nNonVoids
|= PERSIST_TEXTCOLOR
;
216 if ( hasTextLineColor() )
217 nNonVoids
|= PERSIST_TEXTLINECOLOR
;
219 _rxOutStream
->writeLong( nNonVoids
);
221 // the maybeboid anys
222 if ( nNonVoids
& PERSIST_TABSTOP
)
224 bool bTabStop( false );
225 m_aTabStop
>>= bTabStop
;
226 _rxOutStream
->writeBoolean( bTabStop
);
228 if ( nNonVoids
& PERSIST_BACKGROUND
)
230 sal_Int32 nBackgroundColor
= 0;
231 m_aBackgroundColor
>>= nBackgroundColor
;
232 _rxOutStream
->writeLong( nBackgroundColor
);
234 if ( nNonVoids
& PERSIST_TEXTCOLOR
)
236 _rxOutStream
->writeLong( getTextColor() );
238 if ( nNonVoids
& PERSIST_TEXTLINECOLOR
)
240 _rxOutStream
->writeLong( getTextLineColor() );
245 OStreamSection
aEnsureCompat( _rxOutStream
);
246 ::comphelper::operator<<( _rxOutStream
, getFont() );
250 sal_Int32 nFlags
= 0;
251 if ( m_bEnabled
) nFlags
|= PERSIST_ENABLED
;
252 if ( m_nIconSize
) nFlags
|= PERSIST_LARGEICONS
; // at the moment, this is quasi boolean
253 if ( m_bShowPosition
) nFlags
|= PERSIST_SHOW_POSITION
;
254 if ( m_bShowNavigation
) nFlags
|= PERSIST_SHOW_NAVIGATION
;
255 if ( m_bShowActions
) nFlags
|= PERSIST_SHOW_ACTIONS
;
256 if ( m_bShowFilterSort
) nFlags
|= PERSIST_SHOW_FILTERSORT
;
257 _rxOutStream
->writeLong( nFlags
);
260 _rxOutStream
->writeUTF( m_sHelpText
);
261 _rxOutStream
->writeUTF( m_sHelpURL
);
262 _rxOutStream
->writeUTF( m_sDefaultControl
);
265 _rxOutStream
->writeShort( m_nBorder
);
266 _rxOutStream
->writeLong ( m_nDelay
);
270 void SAL_CALL
ONavigationBarModel::read( const Reference
< XObjectInputStream
>& _rxInStream
) throw ( IOException
, RuntimeException
, std::exception
)
272 OStreamSection
aEnsureBlockCompat( _rxInStream
);
275 OControlModel::read( _rxInStream
);
278 OStreamSection
aEnsureCompat( _rxInStream
);
279 // determine which properties were non-void
280 sal_Int32 nNonVoids
= _rxInStream
->readLong( );
282 // the maybeboid anys
283 if ( nNonVoids
& PERSIST_TABSTOP
)
284 m_aTabStop
= makeAny( _rxInStream
->readBoolean() );
288 if ( nNonVoids
& PERSIST_BACKGROUND
)
289 m_aBackgroundColor
= makeAny( _rxInStream
->readLong() );
291 m_aBackgroundColor
.clear();
293 if ( nNonVoids
& PERSIST_TEXTCOLOR
)
294 setTextColor( _rxInStream
->readLong() );
298 if ( nNonVoids
& PERSIST_TEXTLINECOLOR
)
299 setTextLineColor( _rxInStream
->readLong() );
301 clearTextLineColor();
305 OStreamSection
aEnsureCompat( _rxInStream
);
306 FontDescriptor aFont
;
307 ::comphelper::operator>>( _rxInStream
, aFont
);
312 sal_Int32 nFlags
= _rxInStream
->readLong( );
313 m_bEnabled
= ( nFlags
& PERSIST_ENABLED
) != 0;
314 m_nIconSize
= ( nFlags
& PERSIST_LARGEICONS
) ? 1 : 0;
315 m_bShowPosition
= ( nFlags
& PERSIST_SHOW_POSITION
) != 0;
316 m_bShowNavigation
= ( nFlags
& PERSIST_SHOW_NAVIGATION
) != 0;
317 m_bShowActions
= ( nFlags
& PERSIST_SHOW_ACTIONS
) != 0;
318 m_bShowFilterSort
= ( nFlags
& PERSIST_SHOW_FILTERSORT
) != 0;
321 m_sHelpText
= _rxInStream
->readUTF( );
322 m_sHelpURL
= _rxInStream
->readUTF( );
323 m_sDefaultControl
= _rxInStream
->readUTF( );
326 m_nBorder
= _rxInStream
->readShort();
327 m_nDelay
= _rxInStream
->readLong();
331 void SAL_CALL
ONavigationBarModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
333 if ( isRegisteredProperty( _nHandle
) )
335 OPropertyContainerHelper::getFastPropertyValue( _rValue
, _nHandle
);
337 else if ( isFontRelatedProperty( _nHandle
) )
339 FontControlModel::getFastPropertyValue( _rValue
, _nHandle
);
343 OControlModel::getFastPropertyValue( _rValue
, _nHandle
);
348 sal_Bool SAL_CALL
ONavigationBarModel::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
,
349 sal_Int32 _nHandle
, const Any
& _rValue
) throw( IllegalArgumentException
)
351 bool bModified
= false;
353 if ( isRegisteredProperty( _nHandle
) )
355 bModified
= OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
357 else if ( isFontRelatedProperty( _nHandle
) )
359 bModified
= FontControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
363 bModified
= OControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
370 void SAL_CALL
ONavigationBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw ( Exception
, std::exception
)
372 if ( isRegisteredProperty( _nHandle
) )
374 OPropertyContainerHelper::setFastPropertyValue( _nHandle
, _rValue
);
376 else if ( isFontRelatedProperty( _nHandle
) )
378 FontControlModel::setFastPropertyValue_NoBroadcast_impl(
379 *this, &ONavigationBarModel::setDependentFastPropertyValue
,
384 OControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
389 Any
ONavigationBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
395 case PROPERTY_ID_TABSTOP
:
396 case PROPERTY_ID_BACKGROUNDCOLOR
:
399 case PROPERTY_ID_WRITING_MODE
:
400 case PROPERTY_ID_CONTEXT_WRITING_MODE
:
401 aDefault
<<= WritingMode2::CONTEXT
;
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
:
413 case PROPERTY_ID_ICONSIZE
:
414 aDefault
<<= (sal_Int16
)0;
417 case PROPERTY_ID_DEFAULTCONTROL
:
418 aDefault
<<= OUString( "com.sun.star.form.control.NavigationToolBar" );
421 case PROPERTY_ID_HELPTEXT
:
422 case PROPERTY_ID_HELPURL
:
423 aDefault
<<= OUString();
426 case PROPERTY_ID_BORDER
:
427 aDefault
<<= (sal_Int16
)0;
430 case PROPERTY_ID_DELAY
:
431 aDefault
<<= (sal_Int32
)20;
435 if ( isFontRelatedProperty( _nHandle
) )
436 aDefault
= FontControlModel::getPropertyDefaultByHandle( _nHandle
);
438 aDefault
= OControlModel::getPropertyDefaultByHandle( _nHandle
);
444 void ONavigationBarModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
446 BEGIN_DESCRIBE_PROPERTIES( 1, OControlModel
)
447 DECL_PROP2( TABINDEX
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
448 END_DESCRIBE_PROPERTIES();
450 // properties which the OPropertyContainerHelper is responsible for
451 Sequence
< Property
> aContainedProperties
;
452 describeProperties( aContainedProperties
);
454 // properties which the FontControlModel is responsible for
455 Sequence
< Property
> aFontProperties
;
456 describeFontRelatedProperties( aFontProperties
);
458 _rProps
= concatSequences(
459 aContainedProperties
,
467 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
468 com_sun_star_comp_form_ONavigationBarModel_get_implementation(css::uno::XComponentContext
* context
,
469 css::uno::Sequence
<css::uno::Any
> const &)
471 return cppu::acquire(new frm::ONavigationBarModel(context
));
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */