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"
21 #include <property.hxx>
22 #include <services.hxx>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/form/FormComponentType.hpp>
26 #include <com/sun/star/text/WritingMode2.hpp>
28 #include <comphelper/streamsection.hxx>
29 #include <comphelper/basicio.hxx>
30 #include <tools/debug.hxx>
32 using namespace comphelper
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::com::sun::star::form
;
40 using namespace ::com::sun::star::awt
;
41 using namespace ::com::sun::star::io
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::util
;
44 using namespace ::com::sun::star::container
;
45 using namespace ::comphelper
;
47 namespace WritingMode2
= ::com::sun::star::text::WritingMode2
;
49 ONavigationBarModel::ONavigationBarModel( const Reference
< XComponentContext
>& _rxFactory
)
50 :OControlModel( _rxFactory
, OUString() )
51 ,FontControlModel( true )
54 m_nClassId
= FormComponentType::NAVIGATIONBAR
;
55 implInitPropertyContainer();
57 getPropertyDefaultByHandle( PROPERTY_ID_DEFAULTCONTROL
) >>= m_sDefaultControl
;
58 getPropertyDefaultByHandle( PROPERTY_ID_ICONSIZE
) >>= m_nIconSize
;
59 getPropertyDefaultByHandle( PROPERTY_ID_BORDER
) >>= m_nBorder
;
60 getPropertyDefaultByHandle( PROPERTY_ID_DELAY
) >>= m_nDelay
;
61 getPropertyDefaultByHandle( PROPERTY_ID_ENABLED
) >>= m_bEnabled
;
62 getPropertyDefaultByHandle( PROPERTY_ID_ENABLEVISIBLE
) >>= m_bEnableVisible
;
63 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_POSITION
) >>= m_bShowPosition
;
64 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_NAVIGATION
) >>= m_bShowNavigation
;
65 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_RECORDACTIONS
) >>= m_bShowActions
;
66 getPropertyDefaultByHandle( PROPERTY_ID_SHOW_FILTERSORT
) >>= m_bShowFilterSort
;
67 getPropertyDefaultByHandle( PROPERTY_ID_WRITING_MODE
) >>= m_nWritingMode
;
68 getPropertyDefaultByHandle( PROPERTY_ID_CONTEXT_WRITING_MODE
) >>= m_nContextWritingMode
;
72 ONavigationBarModel::ONavigationBarModel( const ONavigationBarModel
* _pOriginal
, const Reference
< XComponentContext
>& _rxFactory
)
73 :OControlModel( _pOriginal
, _rxFactory
)
74 ,FontControlModel( _pOriginal
)
77 implInitPropertyContainer();
79 m_aTabStop
= _pOriginal
->m_aTabStop
;
80 m_aBackgroundColor
= _pOriginal
->m_aBackgroundColor
;
81 m_sDefaultControl
= _pOriginal
->m_sDefaultControl
;
82 m_sHelpText
= _pOriginal
->m_sHelpText
;
83 m_sHelpURL
= _pOriginal
->m_sHelpURL
;
84 m_bEnabled
= _pOriginal
->m_bEnabled
;
85 m_bEnableVisible
= _pOriginal
->m_bEnableVisible
;
86 m_nIconSize
= _pOriginal
->m_nIconSize
;
87 m_nBorder
= _pOriginal
->m_nBorder
;
88 m_nDelay
= _pOriginal
->m_nDelay
;
89 m_bShowPosition
= _pOriginal
->m_bShowPosition
;
90 m_bShowNavigation
= _pOriginal
->m_bShowNavigation
;
91 m_bShowActions
= _pOriginal
->m_bShowActions
;
92 m_bShowFilterSort
= _pOriginal
->m_bShowFilterSort
;
93 m_nWritingMode
= _pOriginal
->m_nWritingMode
;
94 m_nContextWritingMode
= _pOriginal
->m_nContextWritingMode
;
98 void ONavigationBarModel::implInitPropertyContainer()
100 registerProperty( PROPERTY_DEFAULTCONTROL
, PROPERTY_ID_DEFAULTCONTROL
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
101 &m_sDefaultControl
, cppu::UnoType
<decltype(m_sDefaultControl
)>::get() );
102 registerProperty( PROPERTY_HELPTEXT
, PROPERTY_ID_HELPTEXT
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
103 &m_sHelpText
, cppu::UnoType
<decltype(m_sHelpText
)>::get() );
104 registerProperty( PROPERTY_HELPURL
, PROPERTY_ID_HELPURL
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
105 &m_sHelpURL
, cppu::UnoType
<decltype(m_sHelpURL
)>::get() );
106 registerProperty( PROPERTY_ENABLED
, PROPERTY_ID_ENABLED
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
107 &m_bEnabled
, cppu::UnoType
<decltype(m_bEnabled
)>::get() );
108 registerProperty( PROPERTY_ENABLEVISIBLE
, PROPERTY_ID_ENABLEVISIBLE
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
109 &m_bEnableVisible
, cppu::UnoType
<decltype(m_bEnableVisible
)>::get() );
110 registerProperty( PROPERTY_ICONSIZE
, PROPERTY_ID_ICONSIZE
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
111 &m_nIconSize
, cppu::UnoType
<decltype(m_nIconSize
)>::get() );
112 registerProperty( PROPERTY_BORDER
, PROPERTY_ID_BORDER
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
113 &m_nBorder
, cppu::UnoType
<decltype(m_nBorder
)>::get() );
114 registerProperty( PROPERTY_DELAY
, PROPERTY_ID_DELAY
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
115 &m_nDelay
, cppu::UnoType
<decltype(m_nDelay
)>::get() );
116 registerProperty( PROPERTY_SHOW_POSITION
, PROPERTY_ID_SHOW_POSITION
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
117 &m_bShowPosition
, cppu::UnoType
<decltype(m_bShowPosition
)>::get() );
118 registerProperty( PROPERTY_SHOW_NAVIGATION
, PROPERTY_ID_SHOW_NAVIGATION
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
119 &m_bShowNavigation
, cppu::UnoType
<decltype(m_bShowNavigation
)>::get() );
120 registerProperty( PROPERTY_SHOW_RECORDACTIONS
, PROPERTY_ID_SHOW_RECORDACTIONS
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
121 &m_bShowActions
, cppu::UnoType
<decltype(m_bShowActions
)>::get() );
122 registerProperty( PROPERTY_SHOW_FILTERSORT
, PROPERTY_ID_SHOW_FILTERSORT
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
123 &m_bShowFilterSort
, cppu::UnoType
<decltype(m_bShowFilterSort
)>::get() );
124 registerProperty( PROPERTY_WRITING_MODE
, PROPERTY_ID_WRITING_MODE
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
,
125 &m_nWritingMode
, cppu::UnoType
<decltype(m_nWritingMode
)>::get() );
127 registerProperty( PROPERTY_CONTEXT_WRITING_MODE
, PROPERTY_ID_CONTEXT_WRITING_MODE
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
| PropertyAttribute::TRANSIENT
,
128 &m_nContextWritingMode
, cppu::UnoType
<decltype(m_nContextWritingMode
)>::get() );
130 registerMayBeVoidProperty( PROPERTY_TABSTOP
, PROPERTY_ID_TABSTOP
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
| PropertyAttribute::MAYBEVOID
,
131 &m_aTabStop
, cppu::UnoType
<sal_Bool
>::get() );
133 registerMayBeVoidProperty( PROPERTY_BACKGROUNDCOLOR
, PROPERTY_ID_BACKGROUNDCOLOR
, PropertyAttribute::BOUND
| PropertyAttribute::MAYBEDEFAULT
| PropertyAttribute::MAYBEVOID
,
134 &m_aBackgroundColor
, cppu::UnoType
<sal_Int32
>::get() );
138 ONavigationBarModel::~ONavigationBarModel()
140 if ( !OComponentHelper::rBHelper
.bDisposed
)
149 Any SAL_CALL
ONavigationBarModel::queryAggregation( const Type
& _rType
)
151 Any aReturn
= ONavigationBarModel_BASE::queryInterface( _rType
);
153 if ( !aReturn
.hasValue() )
154 aReturn
= OControlModel::queryAggregation( _rType
);
160 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarModel
, OControlModel
, ONavigationBarModel_BASE
)
163 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
ONavigationBarModel::createClone()
165 rtl::Reference
<ONavigationBarModel
> pClone
= new ONavigationBarModel(this, getContext());
166 pClone
->clonedFrom(this);
171 OUString SAL_CALL
ONavigationBarModel::getImplementationName()
173 return "com.sun.star.comp.form.ONavigationBarModel";
177 Sequence
< OUString
> SAL_CALL
ONavigationBarModel::getSupportedServiceNames()
179 Sequence
< OUString
> aSupported
= OControlModel::getSupportedServiceNames_Static();
180 aSupported
.realloc( aSupported
.getLength() + 2 );
182 OUString
* pArray
= aSupported
.getArray();
183 pArray
[ aSupported
.getLength() - 2 ] = "com.sun.star.awt.UnoControlModel";
184 pArray
[ aSupported
.getLength() - 1 ] = FRM_SUN_COMPONENT_NAVTOOLBAR
;
188 OUString SAL_CALL
ONavigationBarModel::getServiceName()
190 return FRM_SUN_COMPONENT_NAVTOOLBAR
;
193 #define PERSIST_TABSTOP 0x0001
194 #define PERSIST_BACKGROUND 0x0002
195 #define PERSIST_TEXTCOLOR 0x0004
196 #define PERSIST_TEXTLINECOLOR 0x0008
198 #define PERSIST_ENABLED 0x0001
199 #define PERSIST_LARGEICONS 0x0002
200 // leaf a leap here - this will allow for two more icon size values to be stored compatibly
201 #define PERSIST_SHOW_POSITION 0x0008
202 #define PERSIST_SHOW_NAVIGATION 0x0010
203 #define PERSIST_SHOW_ACTIONS 0x0020
204 #define PERSIST_SHOW_FILTERSORT 0x0040
207 void SAL_CALL
ONavigationBarModel::write( const Reference
< XObjectOutputStream
>& _rxOutStream
)
209 // open a section for compatibility - if we later on write additional members,
210 // then older versions can skip them
211 OStreamSection
aEnsureBlockCompat( _rxOutStream
);
214 OControlModel::write( _rxOutStream
);
217 OStreamSection
aEnsureCompat( _rxOutStream
);
218 // determine which properties are not void and need to be written
219 sal_Int32 nNonVoids
= 0;
220 if ( m_aTabStop
.hasValue() )
221 nNonVoids
|= PERSIST_TABSTOP
;
222 if ( m_aBackgroundColor
.hasValue() )
223 nNonVoids
|= PERSIST_BACKGROUND
;
224 if ( hasTextColor() )
225 nNonVoids
|= PERSIST_TEXTCOLOR
;
226 if ( hasTextLineColor() )
227 nNonVoids
|= PERSIST_TEXTLINECOLOR
;
229 _rxOutStream
->writeLong( nNonVoids
);
231 // the maybeboid anys
232 if ( nNonVoids
& PERSIST_TABSTOP
)
234 bool bTabStop( false );
235 m_aTabStop
>>= bTabStop
;
236 _rxOutStream
->writeBoolean( bTabStop
);
238 if ( nNonVoids
& PERSIST_BACKGROUND
)
240 sal_Int32 nBackgroundColor
= 0;
241 m_aBackgroundColor
>>= nBackgroundColor
;
242 _rxOutStream
->writeLong( nBackgroundColor
);
244 if ( nNonVoids
& PERSIST_TEXTCOLOR
)
246 _rxOutStream
->writeLong( sal_Int32(getTextColor()) );
248 if ( nNonVoids
& PERSIST_TEXTLINECOLOR
)
250 _rxOutStream
->writeLong( sal_Int32(getTextLineColor()) );
255 OStreamSection
aEnsureCompat( _rxOutStream
);
256 ::comphelper::operator<<( _rxOutStream
, getFont() );
260 sal_Int32 nFlags
= 0;
261 if ( m_bEnabled
) nFlags
|= PERSIST_ENABLED
;
262 if ( m_nIconSize
) nFlags
|= PERSIST_LARGEICONS
; // at the moment, this is quasi boolean
263 if ( m_bShowPosition
) nFlags
|= PERSIST_SHOW_POSITION
;
264 if ( m_bShowNavigation
) nFlags
|= PERSIST_SHOW_NAVIGATION
;
265 if ( m_bShowActions
) nFlags
|= PERSIST_SHOW_ACTIONS
;
266 if ( m_bShowFilterSort
) nFlags
|= PERSIST_SHOW_FILTERSORT
;
267 _rxOutStream
->writeLong( nFlags
);
270 _rxOutStream
->writeUTF( m_sHelpText
);
271 _rxOutStream
->writeUTF( m_sHelpURL
);
272 _rxOutStream
->writeUTF( m_sDefaultControl
);
275 _rxOutStream
->writeShort( m_nBorder
);
276 _rxOutStream
->writeLong ( m_nDelay
);
280 void SAL_CALL
ONavigationBarModel::read( const Reference
< XObjectInputStream
>& _rxInStream
)
282 OStreamSection
aEnsureBlockCompat( _rxInStream
);
285 OControlModel::read( _rxInStream
);
288 OStreamSection
aEnsureCompat( _rxInStream
);
289 // determine which properties were non-void
290 sal_Int32 nNonVoids
= _rxInStream
->readLong( );
292 // the maybeboid anys
293 if ( nNonVoids
& PERSIST_TABSTOP
)
294 m_aTabStop
<<= _rxInStream
->readBoolean();
298 if ( nNonVoids
& PERSIST_BACKGROUND
)
299 m_aBackgroundColor
<<= _rxInStream
->readLong();
301 m_aBackgroundColor
.clear();
303 if ( nNonVoids
& PERSIST_TEXTCOLOR
)
304 setTextColor( ::Color(ColorTransparency
, _rxInStream
->readLong()) );
308 if ( nNonVoids
& PERSIST_TEXTLINECOLOR
)
309 setTextLineColor( ::Color(ColorTransparency
, _rxInStream
->readLong()) );
311 clearTextLineColor();
315 OStreamSection
aEnsureCompat( _rxInStream
);
316 FontDescriptor aFont
;
317 ::comphelper::operator>>( _rxInStream
, aFont
);
322 sal_Int32 nFlags
= _rxInStream
->readLong( );
323 m_bEnabled
= ( nFlags
& PERSIST_ENABLED
) != 0;
324 m_nIconSize
= ( nFlags
& PERSIST_LARGEICONS
) ? 1 : 0;
325 m_bShowPosition
= ( nFlags
& PERSIST_SHOW_POSITION
) != 0;
326 m_bShowNavigation
= ( nFlags
& PERSIST_SHOW_NAVIGATION
) != 0;
327 m_bShowActions
= ( nFlags
& PERSIST_SHOW_ACTIONS
) != 0;
328 m_bShowFilterSort
= ( nFlags
& PERSIST_SHOW_FILTERSORT
) != 0;
331 m_sHelpText
= _rxInStream
->readUTF( );
332 m_sHelpURL
= _rxInStream
->readUTF( );
333 m_sDefaultControl
= _rxInStream
->readUTF( );
336 m_nBorder
= _rxInStream
->readShort();
337 m_nDelay
= _rxInStream
->readLong();
341 void SAL_CALL
ONavigationBarModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
343 if ( isRegisteredProperty( _nHandle
) )
345 OPropertyContainerHelper::getFastPropertyValue( _rValue
, _nHandle
);
347 else if ( isFontRelatedProperty( _nHandle
) )
349 FontControlModel::getFastPropertyValue( _rValue
, _nHandle
);
353 OControlModel::getFastPropertyValue( _rValue
, _nHandle
);
358 sal_Bool SAL_CALL
ONavigationBarModel::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
,
359 sal_Int32 _nHandle
, const Any
& _rValue
)
361 bool bModified
= false;
363 if ( isRegisteredProperty( _nHandle
) )
365 bModified
= OPropertyContainerHelper::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
367 else if ( isFontRelatedProperty( _nHandle
) )
369 bModified
= FontControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
373 bModified
= OControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
380 void SAL_CALL
ONavigationBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
)
382 if ( isRegisteredProperty( _nHandle
) )
384 OPropertyContainerHelper::setFastPropertyValue( _nHandle
, _rValue
);
386 else if ( isFontRelatedProperty( _nHandle
) )
388 FontControlModel::setFastPropertyValue_NoBroadcast_impl(
389 *this, &ONavigationBarModel::setDependentFastPropertyValue
,
394 OControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
399 Any
ONavigationBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
405 case PROPERTY_ID_TABSTOP
:
406 case PROPERTY_ID_BACKGROUNDCOLOR
:
409 case PROPERTY_ID_WRITING_MODE
:
410 case PROPERTY_ID_CONTEXT_WRITING_MODE
:
411 aDefault
<<= WritingMode2::CONTEXT
;
414 case PROPERTY_ID_ENABLED
:
415 case PROPERTY_ID_ENABLEVISIBLE
:
416 case PROPERTY_ID_SHOW_POSITION
:
417 case PROPERTY_ID_SHOW_NAVIGATION
:
418 case PROPERTY_ID_SHOW_RECORDACTIONS
:
419 case PROPERTY_ID_SHOW_FILTERSORT
:
423 case PROPERTY_ID_ICONSIZE
:
424 aDefault
<<= sal_Int16(0);
427 case PROPERTY_ID_DEFAULTCONTROL
:
428 aDefault
<<= OUString( "com.sun.star.form.control.NavigationToolBar" );
431 case PROPERTY_ID_HELPTEXT
:
432 case PROPERTY_ID_HELPURL
:
433 aDefault
<<= OUString();
436 case PROPERTY_ID_BORDER
:
437 aDefault
<<= sal_Int16(0);
440 case PROPERTY_ID_DELAY
:
441 aDefault
<<= sal_Int32(20);
445 if ( isFontRelatedProperty( _nHandle
) )
446 aDefault
= FontControlModel::getPropertyDefaultByHandle( _nHandle
);
448 aDefault
= OControlModel::getPropertyDefaultByHandle( _nHandle
);
454 void ONavigationBarModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
456 OControlModel::describeFixedProperties( _rProps
);
457 sal_Int32 nOldCount
= _rProps
.getLength();
458 _rProps
.realloc( nOldCount
+ 1);
459 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
460 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
);
461 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
463 // properties which the OPropertyContainerHelper is responsible for
464 Sequence
< Property
> aContainedProperties
;
465 describeProperties( aContainedProperties
);
467 // properties which the FontControlModel is responsible for
468 Sequence
< Property
> aFontProperties
;
469 describeFontRelatedProperties( aFontProperties
);
471 _rProps
= concatSequences(
472 aContainedProperties
,
480 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
481 com_sun_star_comp_form_ONavigationBarModel_get_implementation(css::uno::XComponentContext
* context
,
482 css::uno::Sequence
<css::uno::Any
> const &)
484 return cppu::acquire(new frm::ONavigationBarModel(context
));
487 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */