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