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