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