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