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 .
21 #include "Columns.hxx"
22 #include "findpos.hxx"
24 #include "property.hrc"
25 #include "property.hxx"
26 #include "services.hxx"
28 #include <com/sun/star/form/FormComponentType.hpp>
29 #include <com/sun/star/form/XForm.hpp>
30 #include <com/sun/star/form/XLoadable.hpp>
31 #include <com/sun/star/text/WritingMode2.hpp>
33 #include <comphelper/basicio.hxx>
34 #include <comphelper/container.hxx>
35 #include <comphelper/extract.hxx>
36 #include <cppuhelper/queryinterface.hxx>
37 #include <toolkit/helper/vclunohelper.hxx>
38 #include <vcl/svapp.hxx>
40 using namespace ::com::sun::star::uno
;
42 //.........................................................................
45 //.........................................................................
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::sdb
;
49 using namespace ::com::sun::star::sdbc
;
50 using namespace ::com::sun::star::sdbcx
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::container
;
53 using namespace ::com::sun::star::form
;
54 using namespace ::com::sun::star::awt
;
55 using namespace ::com::sun::star::io
;
56 using namespace ::com::sun::star::lang
;
57 using namespace ::com::sun::star::util
;
58 using namespace ::com::sun::star::view
;
60 namespace WritingMode2
= ::com::sun::star::text::WritingMode2
;
62 const sal_uInt16 ROWHEIGHT
= 0x0001;
63 const sal_uInt16 FONTTYPE
= 0x0002;
64 const sal_uInt16 FONTSIZE
= 0x0004;
65 const sal_uInt16 FONTATTRIBS
= 0x0008;
66 const sal_uInt16 TABSTOP
= 0x0010;
67 const sal_uInt16 TEXTCOLOR
= 0x0020;
68 const sal_uInt16 FONTDESCRIPTOR
= 0x0040;
69 const sal_uInt16 RECORDMARKER
= 0x0080;
70 const sal_uInt16 BACKGROUNDCOLOR
= 0x0100;
72 //------------------------------------------------------------------
73 InterfaceRef SAL_CALL
OGridControlModel_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
75 return *(new OGridControlModel(_rxFactory
));
78 DBG_NAME(OGridControlModel
);
79 //------------------------------------------------------------------
80 OGridControlModel::OGridControlModel(const Reference
<XMultiServiceFactory
>& _rxFactory
)
81 :OControlModel(_rxFactory
, OUString())
82 ,OInterfaceContainer(_rxFactory
, m_aMutex
, ::getCppuType(static_cast<Reference
<XPropertySet
>*>(NULL
)))
83 ,OErrorBroadcaster( OComponentHelper::rBHelper
)
84 ,FontControlModel( false )
85 ,m_aSelectListeners(m_aMutex
)
86 ,m_aResetListeners(m_aMutex
)
87 ,m_aRowSetChangeListeners(m_aMutex
)
88 ,m_aDefaultControl( FRM_SUN_CONTROL_GRIDCONTROL
)
90 ,m_nWritingMode( WritingMode2::CONTEXT
)
91 ,m_nContextWritingMode( WritingMode2::CONTEXT
)
92 ,m_bEnableVisible(sal_True
)
94 ,m_bNavigation(sal_True
)
95 ,m_bRecordMarker(sal_True
)
96 ,m_bPrintable(sal_True
)
97 ,m_bAlwaysShowCursor(sal_False
)
98 ,m_bDisplaySynchron(sal_True
)
100 DBG_CTOR(OGridControlModel
,NULL
);
102 m_nClassId
= FormComponentType::GRIDCONTROL
;
105 //------------------------------------------------------------------
106 OGridControlModel::OGridControlModel( const OGridControlModel
* _pOriginal
, const Reference
< XMultiServiceFactory
>& _rxFactory
)
107 :OControlModel( _pOriginal
, _rxFactory
)
108 ,OInterfaceContainer( _rxFactory
, m_aMutex
, ::getCppuType( static_cast<Reference
<XPropertySet
>*>( NULL
) ) )
109 ,OErrorBroadcaster( OComponentHelper::rBHelper
)
110 ,FontControlModel( _pOriginal
)
111 ,m_aSelectListeners( m_aMutex
)
112 ,m_aResetListeners( m_aMutex
)
113 ,m_aRowSetChangeListeners( m_aMutex
)
115 DBG_CTOR(OGridControlModel
,NULL
);
117 m_aDefaultControl
= _pOriginal
->m_aDefaultControl
;
118 m_bEnable
= _pOriginal
->m_bEnable
;
119 m_bEnableVisible
= _pOriginal
->m_bEnableVisible
;
120 m_bNavigation
= _pOriginal
->m_bNavigation
;
121 m_nBorder
= _pOriginal
->m_nBorder
;
122 m_nWritingMode
= _pOriginal
->m_nWritingMode
;
123 m_nContextWritingMode
= _pOriginal
->m_nContextWritingMode
;
124 m_bRecordMarker
= _pOriginal
->m_bRecordMarker
;
125 m_bPrintable
= _pOriginal
->m_bPrintable
;
126 m_bAlwaysShowCursor
= _pOriginal
->m_bAlwaysShowCursor
;
127 m_bDisplaySynchron
= _pOriginal
->m_bDisplaySynchron
;
130 cloneColumns( _pOriginal
);
132 // TODO: clone the events?
135 //------------------------------------------------------------------
136 OGridControlModel::~OGridControlModel()
138 if (!OComponentHelper::rBHelper
.bDisposed
)
144 DBG_DTOR(OGridControlModel
,NULL
);
148 //------------------------------------------------------------------------------
149 Reference
< XCloneable
> SAL_CALL
OGridControlModel::createClone( ) throw (RuntimeException
)
151 OGridControlModel
* pClone
= new OGridControlModel( this, getContext().getLegacyServiceFactory() );
152 osl_atomic_increment( &pClone
->m_refCount
);
153 pClone
->OControlModel::clonedFrom( this );
154 // do not call OInterfaceContainer::clonedFrom, it would clone the elements aka columns, which is
155 // already done in the ctor
156 //pClone->OInterfaceContainer::clonedFrom( *this );
157 osl_atomic_decrement( &pClone
->m_refCount
);
158 return static_cast< XCloneable
* >( static_cast< OControlModel
* >( pClone
) );
161 //------------------------------------------------------------------------------
162 void OGridControlModel::cloneColumns( const OGridControlModel
* _pOriginalContainer
)
166 Reference
< XCloneable
> xColCloneable
;
168 const OInterfaceArray::const_iterator pColumnStart
= _pOriginalContainer
->m_aItems
.begin();
169 const OInterfaceArray::const_iterator pColumnEnd
= _pOriginalContainer
->m_aItems
.end();
170 for ( OInterfaceArray::const_iterator pColumn
= pColumnStart
; pColumn
!= pColumnEnd
; ++pColumn
)
172 // ask the col for a factory for the clone
173 xColCloneable
= xColCloneable
.query( *pColumn
);
174 DBG_ASSERT( xColCloneable
.is(), "OGridControlModel::cloneColumns: column is not cloneable!" );
176 if ( xColCloneable
.is() )
178 // create a clone of the column
179 Reference
< XCloneable
> xColClone( xColCloneable
->createClone() );
180 DBG_ASSERT( xColClone
.is(), "OGridControlModel::cloneColumns: invalid column clone!" );
182 if ( xColClone
.is() )
184 // insert this clone into our own container
185 insertByIndex( pColumn
- pColumnStart
, xColClone
->queryInterface( m_aElementType
) );
191 catch( const Exception
& )
193 OSL_FAIL( "OGridControlModel::cloneColumns: caught an exception while cloning the columns!" );
198 //------------------------------------------------------------------------------
199 StringSequence
OGridControlModel::getSupportedServiceNames() throw(RuntimeException
)
201 StringSequence aSupported
= OControlModel::getSupportedServiceNames();
202 aSupported
.realloc(aSupported
.getLength() + 2);
204 OUString
*pArray
= aSupported
.getArray();
205 pArray
[aSupported
.getLength()-2] = OUString("com.sun.star.awt.UnoControlModel");
206 pArray
[aSupported
.getLength()-1] = FRM_SUN_COMPONENT_GRIDCONTROL
;
210 //------------------------------------------------------------------------------
211 Any SAL_CALL
OGridControlModel::queryAggregation( const Type
& _rType
) throw (RuntimeException
)
213 Any aReturn
= OGridControlModel_BASE::queryInterface(_rType
);
215 if ( !aReturn
.hasValue() )
217 aReturn
= OControlModel::queryAggregation( _rType
);
218 if ( !aReturn
.hasValue() )
220 aReturn
= OInterfaceContainer::queryInterface( _rType
);
221 if ( !aReturn
.hasValue() )
222 aReturn
= OErrorBroadcaster::queryInterface( _rType
);
229 //------------------------------------------------------------------------------
230 void SAL_CALL
OGridControlModel::errorOccured( const SQLErrorEvent
& _rEvent
) throw (RuntimeException
)
232 // forward the errors which happened to my columns to my own listeners
237 //------------------------------------------------------------------------------
238 Reference
< XRowSet
> SAL_CALL
OGridControlModel::getRowSet( ) throw (RuntimeException
)
240 return Reference
< XRowSet
>( getParent(), UNO_QUERY
);
243 //------------------------------------------------------------------------------
244 void SAL_CALL
OGridControlModel::setRowSet( const Reference
< XRowSet
>& /*_rxDataSource*/ ) throw (RuntimeException
)
246 OSL_FAIL( "OGridControlModel::setRowSet: not supported!" );
249 //--------------------------------------------------------------------
250 void SAL_CALL
OGridControlModel::addRowSetChangeListener( const Reference
< XRowSetChangeListener
>& i_Listener
) throw (RuntimeException
)
252 if ( i_Listener
.is() )
253 m_aRowSetChangeListeners
.addInterface( i_Listener
);
256 //--------------------------------------------------------------------
257 void SAL_CALL
OGridControlModel::removeRowSetChangeListener( const Reference
< XRowSetChangeListener
>& i_Listener
) throw (RuntimeException
)
259 m_aRowSetChangeListeners
.removeInterface( i_Listener
);
263 //------------------------------------------------------------------------------
264 void SAL_CALL
OGridControlModel::setParent( const InterfaceRef
& i_Parent
) throw(NoSupportException
, RuntimeException
)
266 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
267 if ( i_Parent
== getParent() )
270 OControlModel::setParent( i_Parent
);
272 EventObject
aEvent( *this );
274 m_aRowSetChangeListeners
.notifyEach( &XRowSetChangeListener::onRowSetChanged
, aEvent
);
277 //------------------------------------------------------------------------------
278 Sequence
< Type
> SAL_CALL
OGridControlModel::getTypes( ) throw(RuntimeException
)
280 return concatSequences(
282 OControlModel::getTypes(),
283 OInterfaceContainer::getTypes(),
284 OErrorBroadcaster::getTypes()
286 OGridControlModel_BASE::getTypes()
291 //------------------------------------------------------------------------------
292 void OGridControlModel::disposing()
294 OControlModel::disposing();
295 OErrorBroadcaster::disposing();
296 OInterfaceContainer::disposing();
300 EventObject
aEvt(static_cast<XWeak
*>(this));
301 m_aSelectListeners
.disposeAndClear(aEvt
);
302 m_aResetListeners
.disposeAndClear(aEvt
);
303 m_aRowSetChangeListeners
.disposeAndClear(aEvt
);
307 //------------------------------------------------------------------------------
308 void OGridControlModel::disposing(const EventObject
& _rEvent
) throw( RuntimeException
)
310 OControlModel::disposing( _rEvent
);
311 OInterfaceContainer::disposing( _rEvent
);
314 // XSelectionSupplier
315 //-----------------------------------------------------------------------------
316 sal_Bool SAL_CALL
OGridControlModel::select(const Any
& rElement
) throw(IllegalArgumentException
, RuntimeException
)
318 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
320 Reference
<XPropertySet
> xSel
;
321 if (rElement
.hasValue() && !::cppu::extractInterface(xSel
, rElement
))
323 throw IllegalArgumentException();
325 InterfaceRef xMe
= static_cast<XWeak
*>(this);
329 Reference
<XChild
> xAsChild(xSel
, UNO_QUERY
);
330 if (!xAsChild
.is() || (xAsChild
->getParent() != xMe
))
332 throw IllegalArgumentException();
336 if ( xSel
!= m_xSelection
)
340 m_aSelectListeners
.notifyEach( &XSelectionChangeListener::selectionChanged
, EventObject( *this ) );
346 //-----------------------------------------------------------------------------
347 Any SAL_CALL
OGridControlModel::getSelection() throw(RuntimeException
)
349 return makeAny(m_xSelection
);
352 //-----------------------------------------------------------------------------
353 void OGridControlModel::addSelectionChangeListener(const Reference
< XSelectionChangeListener
>& _rxListener
) throw( RuntimeException
)
355 m_aSelectListeners
.addInterface(_rxListener
);
358 //-----------------------------------------------------------------------------
359 void OGridControlModel::removeSelectionChangeListener(const Reference
< XSelectionChangeListener
>& _rxListener
) throw( RuntimeException
)
361 m_aSelectListeners
.removeInterface(_rxListener
);
364 // XGridColumnFactory
365 //------------------------------------------------------------------------------
366 Reference
<XPropertySet
> SAL_CALL
OGridControlModel::createColumn(const OUString
& ColumnType
) throw ( :: com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
369 const Sequence
< OUString
>& rColumnTypes
= frm::getColumnTypes();
370 return createColumn( ::detail::findPos( ColumnType
, rColumnTypes
) );
373 //------------------------------------------------------------------------------
374 Reference
<XPropertySet
> OGridControlModel::createColumn(sal_Int32 nTypeId
) const
376 Reference
<XPropertySet
> xReturn
;
379 case TYPE_CHECKBOX
: xReturn
= new CheckBoxColumn( getContext() ); break;
380 case TYPE_COMBOBOX
: xReturn
= new ComboBoxColumn( getContext() ); break;
381 case TYPE_CURRENCYFIELD
: xReturn
= new CurrencyFieldColumn( getContext() ); break;
382 case TYPE_DATEFIELD
: xReturn
= new DateFieldColumn( getContext() ); break;
383 case TYPE_LISTBOX
: xReturn
= new ListBoxColumn( getContext() ); break;
384 case TYPE_NUMERICFIELD
: xReturn
= new NumericFieldColumn( getContext() ); break;
385 case TYPE_PATTERNFIELD
: xReturn
= new PatternFieldColumn( getContext() ); break;
386 case TYPE_TEXTFIELD
: xReturn
= new TextFieldColumn( getContext() ); break;
387 case TYPE_TIMEFIELD
: xReturn
= new TimeFieldColumn( getContext() ); break;
388 case TYPE_FORMATTEDFIELD
: xReturn
= new FormattedFieldColumn( getContext() ); break;
390 OSL_FAIL("OGridControlModel::createColumn: Unknown Column");
396 //------------------------------------------------------------------------------
397 StringSequence SAL_CALL
OGridControlModel::getColumnTypes() throw ( ::com::sun::star::uno::RuntimeException
)
399 return frm::getColumnTypes();
403 //-----------------------------------------------------------------------------
404 void SAL_CALL
OGridControlModel::reset() throw ( ::com::sun::star::uno::RuntimeException
)
406 ::cppu::OInterfaceIteratorHelper
aIter(m_aResetListeners
);
407 EventObject
aEvt(static_cast<XWeak
*>(this));
408 sal_Bool bContinue
= sal_True
;
409 while (aIter
.hasMoreElements() && bContinue
)
410 bContinue
=((XResetListener
*)aIter
.next())->approveReset(aEvt
);
415 m_aResetListeners
.notifyEach( &XResetListener::resetted
, aEvt
);
419 //-----------------------------------------------------------------------------
420 void SAL_CALL
OGridControlModel::addResetListener(const Reference
<XResetListener
>& _rxListener
) throw ( ::com::sun::star::uno::RuntimeException
)
422 m_aResetListeners
.addInterface(_rxListener
);
425 //-----------------------------------------------------------------------------
426 void SAL_CALL
OGridControlModel::removeResetListener(const Reference
<XResetListener
>& _rxListener
) throw ( ::com::sun::star::uno::RuntimeException
)
428 m_aResetListeners
.removeInterface(_rxListener
);
431 //-----------------------------------------------------------------------------
432 void OGridControlModel::_reset()
434 Reference
<XReset
> xReset
;
435 sal_Int32 nCount
= getCount();
436 for (sal_Int32 nIndex
=0; nIndex
< nCount
; nIndex
++)
438 getByIndex( nIndex
) >>= xReset
;
445 //------------------------------------------------------------------------------
446 void OGridControlModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
448 BEGIN_DESCRIBE_BASE_PROPERTIES( 37 )
449 DECL_PROP1(NAME
, OUString
, BOUND
);
450 DECL_PROP2(CLASSID
, sal_Int16
, READONLY
, TRANSIENT
);
451 DECL_PROP1(TAG
, OUString
, BOUND
);
452 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
453 DECL_PROP3(TABSTOP
, sal_Bool
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
454 DECL_PROP2(HASNAVIGATION
, sal_Bool
, BOUND
, MAYBEDEFAULT
);
455 DECL_PROP1(ENABLED
, sal_Bool
, BOUND
);
456 DECL_PROP2(ENABLEVISIBLE
, sal_Bool
, BOUND
, MAYBEDEFAULT
);
457 DECL_PROP1(BORDER
, sal_Int16
, BOUND
);
458 DECL_PROP2(BORDERCOLOR
, sal_Int16
, BOUND
, MAYBEVOID
);
459 DECL_PROP1(DEFAULTCONTROL
, OUString
, BOUND
);
460 DECL_PROP3(TEXTCOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
461 DECL_PROP3(BACKGROUNDCOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
462 DECL_PROP2(FONT
, FontDescriptor
, BOUND
, MAYBEDEFAULT
);
463 DECL_PROP3(ROWHEIGHT
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
464 DECL_PROP1(HELPTEXT
, OUString
, BOUND
);
465 DECL_PROP1(FONT_NAME
, OUString
, MAYBEDEFAULT
);
466 DECL_PROP1(FONT_STYLENAME
, OUString
, MAYBEDEFAULT
);
467 DECL_PROP1(FONT_FAMILY
, sal_Int16
, MAYBEDEFAULT
);
468 DECL_PROP1(FONT_CHARSET
, sal_Int16
, MAYBEDEFAULT
);
469 DECL_PROP1(FONT_HEIGHT
, float, MAYBEDEFAULT
);
470 DECL_PROP1(FONT_WEIGHT
, float, MAYBEDEFAULT
);
471 DECL_PROP1(FONT_SLANT
, sal_Int16
, MAYBEDEFAULT
);
472 DECL_PROP1(FONT_UNDERLINE
, sal_Int16
, MAYBEDEFAULT
);
473 DECL_BOOL_PROP1(FONT_WORDLINEMODE
, MAYBEDEFAULT
);
474 DECL_PROP3(TEXTLINECOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
475 DECL_PROP2(FONTEMPHASISMARK
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
476 DECL_PROP2(FONTRELIEF
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
477 DECL_PROP1(FONT_STRIKEOUT
, sal_Int16
, MAYBEDEFAULT
);
478 DECL_PROP2(RECORDMARKER
, sal_Bool
, BOUND
, MAYBEDEFAULT
);
479 DECL_PROP2(PRINTABLE
, sal_Bool
, BOUND
, MAYBEDEFAULT
);
480 DECL_PROP4(CURSORCOLOR
, sal_Int32
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
, TRANSIENT
);
481 DECL_PROP3(ALWAYSSHOWCURSOR
, sal_Bool
, BOUND
, MAYBEDEFAULT
, TRANSIENT
);
482 DECL_PROP3(DISPLAYSYNCHRON
, sal_Bool
, BOUND
, MAYBEDEFAULT
, TRANSIENT
);
483 DECL_PROP2(HELPURL
, OUString
, BOUND
, MAYBEDEFAULT
);
484 DECL_PROP2(WRITING_MODE
, sal_Int16
, BOUND
, MAYBEDEFAULT
);
485 DECL_PROP3(CONTEXT_WRITING_MODE
,sal_Int16
, BOUND
, MAYBEDEFAULT
, TRANSIENT
);
486 END_DESCRIBE_PROPERTIES();
489 //------------------------------------------------------------------------------
490 void OGridControlModel::getFastPropertyValue(Any
& rValue
, sal_Int32 nHandle
) const
494 case PROPERTY_ID_CONTEXT_WRITING_MODE
:
495 rValue
<<= m_nContextWritingMode
;
497 case PROPERTY_ID_WRITING_MODE
:
498 rValue
<<= m_nWritingMode
;
500 case PROPERTY_ID_HELPTEXT
:
501 rValue
<<= m_sHelpText
;
503 case PROPERTY_ID_HELPURL
:
504 rValue
<<= m_sHelpURL
;
506 case PROPERTY_ID_DISPLAYSYNCHRON
:
507 setBOOL(rValue
, m_bDisplaySynchron
);
509 case PROPERTY_ID_ALWAYSSHOWCURSOR
:
510 setBOOL(rValue
, m_bAlwaysShowCursor
);
512 case PROPERTY_ID_CURSORCOLOR
:
513 rValue
= m_aCursorColor
;
515 case PROPERTY_ID_PRINTABLE
:
516 setBOOL(rValue
, m_bPrintable
);
518 case PROPERTY_ID_TABSTOP
:
521 case PROPERTY_ID_HASNAVIGATION
:
522 setBOOL(rValue
, m_bNavigation
);
524 case PROPERTY_ID_RECORDMARKER
:
525 setBOOL(rValue
, m_bRecordMarker
);
527 case PROPERTY_ID_ENABLED
:
528 setBOOL(rValue
, m_bEnable
);
530 case PROPERTY_ID_ENABLEVISIBLE
:
531 setBOOL(rValue
, m_bEnableVisible
);
533 case PROPERTY_ID_BORDER
:
534 rValue
<<= (sal_Int16
)m_nBorder
;
536 case PROPERTY_ID_BORDERCOLOR
:
537 rValue
<<= m_aBorderColor
;
539 case PROPERTY_ID_DEFAULTCONTROL
:
540 rValue
<<= m_aDefaultControl
;
542 case PROPERTY_ID_BACKGROUNDCOLOR
:
543 rValue
= m_aBackgroundColor
;
545 case PROPERTY_ID_ROWHEIGHT
:
546 rValue
= m_aRowHeight
;
550 if ( isFontRelatedProperty( nHandle
) )
551 FontControlModel::getFastPropertyValue( rValue
, nHandle
);
553 OControlModel::getFastPropertyValue( rValue
, nHandle
);
557 //------------------------------------------------------------------------------
558 sal_Bool
OGridControlModel::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
,
559 sal_Int32 nHandle
, const Any
& rValue
)throw( IllegalArgumentException
)
561 sal_Bool
bModified(sal_False
);
564 case PROPERTY_ID_CONTEXT_WRITING_MODE
:
565 bModified
= tryPropertyValue( rConvertedValue
, rOldValue
, rValue
, m_nContextWritingMode
);
567 case PROPERTY_ID_WRITING_MODE
:
568 bModified
= tryPropertyValue( rConvertedValue
, rOldValue
, rValue
, m_nWritingMode
);
570 case PROPERTY_ID_HELPTEXT
:
571 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_sHelpText
);
573 case PROPERTY_ID_HELPURL
:
574 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_sHelpURL
);
576 case PROPERTY_ID_DISPLAYSYNCHRON
:
577 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bDisplaySynchron
);
579 case PROPERTY_ID_ALWAYSSHOWCURSOR
:
580 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bAlwaysShowCursor
);
582 case PROPERTY_ID_CURSORCOLOR
:
583 if (!rValue
.hasValue() || !m_aCursorColor
.hasValue())
585 if (rValue
.hasValue() && (TypeClass_LONG
!= rValue
.getValueType().getTypeClass()))
587 throw IllegalArgumentException();
589 rOldValue
= m_aCursorColor
;
590 rConvertedValue
= rValue
;
591 bModified
= (rOldValue
.getValue() != rConvertedValue
.getValue());
594 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getINT32(m_aCursorColor
));
596 case PROPERTY_ID_PRINTABLE
:
597 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bPrintable
);
599 case PROPERTY_ID_TABSTOP
:
600 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aTabStop
, ::getBooleanCppuType());
602 case PROPERTY_ID_HASNAVIGATION
:
603 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bNavigation
);
605 case PROPERTY_ID_RECORDMARKER
:
606 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bRecordMarker
);
608 case PROPERTY_ID_ENABLED
:
609 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bEnable
);
611 case PROPERTY_ID_ENABLEVISIBLE
:
612 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bEnableVisible
);
614 case PROPERTY_ID_BORDER
:
615 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_nBorder
);
617 case PROPERTY_ID_BORDERCOLOR
:
618 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aBorderColor
, ::getCppuType((const sal_Int32
*)NULL
));
620 case PROPERTY_ID_DEFAULTCONTROL
:
621 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aDefaultControl
);
623 case PROPERTY_ID_BACKGROUNDCOLOR
:
624 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aBackgroundColor
, ::getCppuType((const sal_Int32
*)NULL
));
626 case PROPERTY_ID_ROWHEIGHT
:
628 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aRowHeight
, ::getCppuType((const sal_Int32
*)NULL
));
630 sal_Int32
nNewVal( 0 );
631 if ( ( rConvertedValue
>>= nNewVal
) && ( nNewVal
<= 0 ) )
633 rConvertedValue
.clear();
634 bModified
= m_aRowHeight
.hasValue();
639 if ( isFontRelatedProperty( nHandle
) )
640 bModified
= FontControlModel::convertFastPropertyValue( rConvertedValue
, rOldValue
, nHandle
, rValue
);
642 bModified
= OControlModel::convertFastPropertyValue( rConvertedValue
, rOldValue
, nHandle
, rValue
);
647 //------------------------------------------------------------------------------
648 void OGridControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const Any
& rValue
) throw ( ::com::sun::star::uno::Exception
)
652 case PROPERTY_ID_CONTEXT_WRITING_MODE
:
653 rValue
>>= m_nContextWritingMode
;
655 case PROPERTY_ID_WRITING_MODE
:
656 rValue
>>= m_nWritingMode
;
658 case PROPERTY_ID_HELPTEXT
:
659 rValue
>>= m_sHelpText
;
661 case PROPERTY_ID_HELPURL
:
662 rValue
>>= m_sHelpURL
;
664 case PROPERTY_ID_DISPLAYSYNCHRON
:
665 m_bDisplaySynchron
= getBOOL(rValue
);
667 case PROPERTY_ID_ALWAYSSHOWCURSOR
:
668 m_bAlwaysShowCursor
= getBOOL(rValue
);
670 case PROPERTY_ID_CURSORCOLOR
:
671 m_aCursorColor
= rValue
;
673 case PROPERTY_ID_PRINTABLE
:
674 m_bPrintable
= getBOOL(rValue
);
676 case PROPERTY_ID_TABSTOP
:
679 case PROPERTY_ID_HASNAVIGATION
:
680 m_bNavigation
= getBOOL(rValue
);
682 case PROPERTY_ID_ENABLED
:
683 m_bEnable
= getBOOL(rValue
);
685 case PROPERTY_ID_ENABLEVISIBLE
:
686 m_bEnableVisible
= getBOOL(rValue
);
688 case PROPERTY_ID_RECORDMARKER
:
689 m_bRecordMarker
= getBOOL(rValue
);
691 case PROPERTY_ID_BORDER
:
692 rValue
>>= m_nBorder
;
694 case PROPERTY_ID_BORDERCOLOR
:
695 m_aBorderColor
= rValue
;
697 case PROPERTY_ID_DEFAULTCONTROL
:
698 rValue
>>= m_aDefaultControl
;
700 case PROPERTY_ID_BACKGROUNDCOLOR
:
701 m_aBackgroundColor
= rValue
;
703 case PROPERTY_ID_ROWHEIGHT
:
704 m_aRowHeight
= rValue
;
708 if ( isFontRelatedProperty( nHandle
) )
710 FontDescriptor
aOldFont( getFont() );
712 FontControlModel::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
714 if ( isFontAggregateProperty( nHandle
) )
715 firePropertyChange( PROPERTY_ID_FONT
, makeAny( getFont() ), makeAny( aOldFont
) );
718 OControlModel::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
725 //------------------------------------------------------------------------------
726 Any
OGridControlModel::getPropertyDefaultByHandle( sal_Int32 nHandle
) const
731 case PROPERTY_ID_CONTEXT_WRITING_MODE
:
732 case PROPERTY_ID_WRITING_MODE
:
733 aReturn
<<= WritingMode2::CONTEXT
;
736 case PROPERTY_ID_DEFAULTCONTROL
:
737 aReturn
<<= OUString( STARDIV_ONE_FORM_CONTROL_GRID
);
740 case PROPERTY_ID_PRINTABLE
:
741 case PROPERTY_ID_HASNAVIGATION
:
742 case PROPERTY_ID_RECORDMARKER
:
743 case PROPERTY_ID_DISPLAYSYNCHRON
:
744 case PROPERTY_ID_ENABLED
:
745 case PROPERTY_ID_ENABLEVISIBLE
:
746 aReturn
= makeBoolAny(sal_True
);
749 case PROPERTY_ID_ALWAYSSHOWCURSOR
:
750 aReturn
= makeBoolAny(sal_False
);
753 case PROPERTY_ID_HELPURL
:
754 case PROPERTY_ID_HELPTEXT
:
755 aReturn
<<= OUString();
758 case PROPERTY_ID_BORDER
:
759 aReturn
<<= (sal_Int16
)1;
762 case PROPERTY_ID_BORDERCOLOR
:
763 case PROPERTY_ID_TABSTOP
:
764 case PROPERTY_ID_BACKGROUNDCOLOR
:
765 case PROPERTY_ID_ROWHEIGHT
:
766 case PROPERTY_ID_CURSORCOLOR
:
771 if ( isFontRelatedProperty( nHandle
) )
772 aReturn
= FontControlModel::getPropertyDefaultByHandle( nHandle
);
774 aReturn
= OControlModel::getPropertyDefaultByHandle(nHandle
);
779 //------------------------------------------------------------------------------
780 OGridColumn
* OGridControlModel::getColumnImplementation(const InterfaceRef
& _rxIFace
) const
782 OGridColumn
* pImplementation
= NULL
;
783 Reference
< XUnoTunnel
> xUnoTunnel( _rxIFace
, UNO_QUERY
);
784 if ( xUnoTunnel
.is() )
785 pImplementation
= reinterpret_cast<OGridColumn
*>(xUnoTunnel
->getSomething(OGridColumn::getUnoTunnelImplementationId()));
787 return pImplementation
;
790 //------------------------------------------------------------------------------
791 void OGridControlModel::gotColumn( const Reference
< XInterface
>& _rxColumn
)
793 Reference
< XSQLErrorBroadcaster
> xBroadcaster( _rxColumn
, UNO_QUERY
);
794 if ( xBroadcaster
.is() )
795 xBroadcaster
->addSQLErrorListener( this );
798 //------------------------------------------------------------------------------
799 void OGridControlModel::lostColumn(const Reference
< XInterface
>& _rxColumn
)
801 if ( m_xSelection
== _rxColumn
)
802 { // the currently selected element was replaced
803 m_xSelection
.clear();
804 EventObject
aEvt( static_cast< XWeak
* >( this ) );
805 m_aSelectListeners
.notifyEach( &XSelectionChangeListener::selectionChanged
, aEvt
);
808 Reference
< XSQLErrorBroadcaster
> xBroadcaster( _rxColumn
, UNO_QUERY
);
809 if ( xBroadcaster
.is() )
810 xBroadcaster
->removeSQLErrorListener( this );
813 //------------------------------------------------------------------------------
814 void OGridControlModel::implRemoved(const InterfaceRef
& _rxObject
)
816 OInterfaceContainer::implRemoved(_rxObject
);
817 lostColumn(_rxObject
);
820 //------------------------------------------------------------------------------
821 void OGridControlModel::implInserted( const ElementDescription
* _pElement
)
823 OInterfaceContainer::implInserted( _pElement
);
824 gotColumn( _pElement
->xInterface
);
827 //------------------------------------------------------------------------------
828 void OGridControlModel::impl_replacedElement( const ContainerEvent
& _rEvent
, ::osl::ClearableMutexGuard
& _rInstanceLock
)
830 Reference
< XInterface
> xOldColumn( _rEvent
.ReplacedElement
, UNO_QUERY
);
831 Reference
< XInterface
> xNewColumn( _rEvent
.Element
, UNO_QUERY
);
833 bool bNewSelection
= ( xOldColumn
== m_xSelection
);
835 lostColumn( xOldColumn
);
836 gotColumn( xNewColumn
);
839 m_xSelection
.set( xNewColumn
, UNO_QUERY
);
841 OInterfaceContainer::impl_replacedElement( _rEvent
, _rInstanceLock
);
842 // <<---- SYNCHRONIZED
846 m_aSelectListeners
.notifyEach( &XSelectionChangeListener::selectionChanged
, EventObject( *this ) );
850 //------------------------------------------------------------------------------
851 ElementDescription
* OGridControlModel::createElementMetaData( )
853 return new ColumnDescription
;
856 //------------------------------------------------------------------------------
857 void OGridControlModel::approveNewElement( const Reference
< XPropertySet
>& _rxObject
, ElementDescription
* _pElement
)
859 OGridColumn
* pCol
= getColumnImplementation( _rxObject
);
861 throw IllegalArgumentException();
863 OInterfaceContainer::approveNewElement( _rxObject
, _pElement
);
865 // if we're here, the object passed all tests
867 static_cast< ColumnDescription
* >( _pElement
)->pColumn
= pCol
;
871 //------------------------------------------------------------------------------
872 OUString SAL_CALL
OGridControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
)
874 return OUString(FRM_COMPONENT_GRID
); // old (non-sun) name for compatibility !
877 //------------------------------------------------------------------------------
878 void OGridControlModel::write(const Reference
<XObjectOutputStream
>& _rxOutStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
880 OControlModel::write(_rxOutStream
);
882 Reference
<XMarkableStream
> xMark(_rxOutStream
, UNO_QUERY
);
885 _rxOutStream
->writeShort(0x0008);
888 sal_Int32 nLen
= getCount();
889 _rxOutStream
->writeLong(nLen
);
891 for (sal_Int32 i
= 0; i
< nLen
; i
++)
893 // zuerst den Servicenamen fuer das darunterliegende Model
894 pCol
= getColumnImplementation(m_aItems
[i
]);
895 DBG_ASSERT(pCol
!= NULL
, "OGridControlModel::write : such items should never reach it into my container !");
897 _rxOutStream
<< pCol
->getModelName();
899 // dann das Object selbst
900 sal_Int32 nMark
= xMark
->createMark();
901 sal_Int32 nObjLen
= 0;
902 _rxOutStream
->writeLong(nObjLen
);
905 pCol
->write(_rxOutStream
);
907 // feststellen der Laenge
908 nObjLen
= xMark
->offsetToMark(nMark
) - 4;
909 xMark
->jumpToMark(nMark
);
910 _rxOutStream
->writeLong(nObjLen
);
911 xMark
->jumpToFurthest();
912 xMark
->deleteMark(nMark
);
916 writeEvents(_rxOutStream
);
919 // Maskierung fuer alle any Typen
920 sal_uInt16 nAnyMask
= 0;
921 if (m_aRowHeight
.getValueType().getTypeClass() == TypeClass_LONG
)
922 nAnyMask
|= ROWHEIGHT
;
923 if ( getFont() != getDefaultFont() )
924 nAnyMask
|= FONTATTRIBS
| FONTSIZE
| FONTTYPE
| FONTDESCRIPTOR
;
925 if (m_aTabStop
.getValueType().getTypeClass() == TypeClass_BOOLEAN
)
927 if ( hasTextColor() )
928 nAnyMask
|= TEXTCOLOR
;
929 if (m_aBackgroundColor
.getValueType().getTypeClass() == TypeClass_LONG
)
930 nAnyMask
|= BACKGROUNDCOLOR
;
931 if (!m_bRecordMarker
)
932 nAnyMask
|= RECORDMARKER
;
934 _rxOutStream
->writeShort(nAnyMask
);
936 if (nAnyMask
& ROWHEIGHT
)
937 _rxOutStream
->writeLong(getINT32(m_aRowHeight
));
940 const FontDescriptor
& aFont
= getFont();
941 if ( nAnyMask
& FONTDESCRIPTOR
)
944 _rxOutStream
->writeShort( sal::static_int_cast
< sal_Int16
>( VCLUnoHelper::ConvertFontWeight( aFont
.Weight
) ) );
945 _rxOutStream
->writeShort( sal::static_int_cast
< sal_Int16
>( aFont
.Slant
) );
946 _rxOutStream
->writeShort( aFont
.Underline
);
947 _rxOutStream
->writeShort( aFont
.Strikeout
);
948 _rxOutStream
->writeShort( sal_Int16(aFont
.Orientation
* 10) );
949 _rxOutStream
->writeBoolean( aFont
.Kerning
);
950 _rxOutStream
->writeBoolean( aFont
.WordLineMode
);
953 _rxOutStream
->writeLong( aFont
.Width
);
954 _rxOutStream
->writeLong( aFont
.Height
);
955 _rxOutStream
->writeShort( sal::static_int_cast
< sal_Int16
>( VCLUnoHelper::ConvertFontWidth( aFont
.CharacterWidth
) ) );
958 _rxOutStream
->writeUTF( aFont
.Name
);
959 _rxOutStream
->writeUTF( aFont
.StyleName
);
960 _rxOutStream
->writeShort( aFont
.Family
);
961 _rxOutStream
->writeShort( aFont
.CharSet
);
962 _rxOutStream
->writeShort( aFont
.Pitch
);
965 _rxOutStream
<< m_aDefaultControl
;
967 _rxOutStream
->writeShort(m_nBorder
);
968 _rxOutStream
->writeBoolean(m_bEnable
);
970 if (nAnyMask
& TABSTOP
)
971 _rxOutStream
->writeBoolean(getBOOL(m_aTabStop
));
973 _rxOutStream
->writeBoolean(m_bNavigation
);
975 if (nAnyMask
& TEXTCOLOR
)
976 _rxOutStream
->writeLong( getTextColor() );
979 _rxOutStream
<< m_sHelpText
;
981 if (nAnyMask
& FONTDESCRIPTOR
)
982 _rxOutStream
<< getFont();
984 if (nAnyMask
& RECORDMARKER
)
985 _rxOutStream
->writeBoolean(m_bRecordMarker
);
988 _rxOutStream
->writeBoolean(m_bPrintable
);
991 if (nAnyMask
& BACKGROUNDCOLOR
)
992 _rxOutStream
->writeLong(getINT32(m_aBackgroundColor
));
995 //------------------------------------------------------------------------------
996 void OGridControlModel::read(const Reference
<XObjectInputStream
>& _rxInStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
999 OControlModel::read(_rxInStream
);
1001 Reference
<XMarkableStream
> xMark(_rxInStream
, UNO_QUERY
);
1004 sal_Int16 nVersion
= _rxInStream
->readShort();
1006 // 2. Einlesen der Spalten
1007 sal_Int32 nLen
= _rxInStream
->readLong();
1010 for (sal_Int32 i
= 0; i
< nLen
; i
++)
1012 // Lesen des Modelnamen
1014 OUString sModelName
;
1015 _rxInStream
>> sModelName
;
1017 Reference
<XPropertySet
> xCol(createColumn(getColumnTypeByModelName(sModelName
)));
1018 DBG_ASSERT(xCol
.is(), "OGridControlModel::read : unknown column type !");
1019 sal_Int32 nObjLen
= _rxInStream
->readLong();
1022 sal_Int32 nMark
= xMark
->createMark();
1025 OGridColumn
* pCol
= getColumnImplementation(xCol
);
1026 pCol
->read(_rxInStream
);
1028 xMark
->jumpToMark(nMark
);
1029 _rxInStream
->skipBytes(nObjLen
);
1030 xMark
->deleteMark(nMark
);
1034 implInsert( i
, xCol
, sal_False
, NULL
, sal_False
);
1038 // In der Basisimplementierung werden die Events nur gelesen, Elemente im Container existieren
1039 // da aber vor TF_ONE fuer das GridControl immer Events geschrieben wurden, muessen sie auch immer
1040 // mit gelesen werden
1041 sal_Int32 nObjLen
= _rxInStream
->readLong();
1044 sal_Int32 nMark
= xMark
->createMark();
1045 Reference
<XPersistObject
> xObj(m_xEventAttacher
, UNO_QUERY
);
1047 xObj
->read(_rxInStream
);
1048 xMark
->jumpToMark(nMark
);
1049 _rxInStream
->skipBytes(nObjLen
);
1050 xMark
->deleteMark(nMark
);
1053 // Attachement lesen
1054 for (sal_Int32 i
= 0; i
< nLen
; i
++)
1056 InterfaceRef
xIfc(m_aItems
[i
], UNO_QUERY
);
1057 Reference
<XPropertySet
> xSet(xIfc
, UNO_QUERY
);
1060 m_xEventAttacher
->attach( i
, xIfc
, aHelper
);
1063 // 4. Einlesen der Attribute
1067 // Maskierung fuer any
1068 sal_uInt16 nAnyMask
= _rxInStream
->readShort();
1070 if (nAnyMask
& ROWHEIGHT
)
1072 sal_Int32 nValue
= _rxInStream
->readLong();
1073 m_aRowHeight
<<= (sal_Int32
)nValue
;
1076 FontDescriptor
aFont( getFont() );
1077 if ( nAnyMask
& FONTATTRIBS
)
1079 aFont
.Weight
= (float)VCLUnoHelper::ConvertFontWeight( _rxInStream
->readShort() );
1081 aFont
.Slant
= (FontSlant
)_rxInStream
->readShort();
1082 aFont
.Underline
= _rxInStream
->readShort();
1083 aFont
.Strikeout
= _rxInStream
->readShort();
1084 aFont
.Orientation
= ( (float)_rxInStream
->readShort() ) / 10;
1085 aFont
.Kerning
= _rxInStream
->readBoolean();
1086 aFont
.WordLineMode
= _rxInStream
->readBoolean();
1088 if ( nAnyMask
& FONTSIZE
)
1090 aFont
.Width
= (sal_Int16
)_rxInStream
->readLong();
1091 aFont
.Height
= (sal_Int16
)_rxInStream
->readLong();
1092 aFont
.CharacterWidth
= (float)VCLUnoHelper::ConvertFontWidth( _rxInStream
->readShort() );
1094 if ( nAnyMask
& FONTTYPE
)
1096 aFont
.Name
= _rxInStream
->readUTF();
1097 aFont
.StyleName
= _rxInStream
->readUTF();
1098 aFont
.Family
= _rxInStream
->readShort();
1099 aFont
.CharSet
= _rxInStream
->readShort();
1100 aFont
.Pitch
= _rxInStream
->readShort();
1103 if ( nAnyMask
& ( FONTATTRIBS
| FONTSIZE
| FONTTYPE
) )
1107 _rxInStream
>> m_aDefaultControl
;
1108 m_nBorder
= _rxInStream
->readShort();
1109 m_bEnable
= _rxInStream
->readBoolean();
1111 if (nAnyMask
& TABSTOP
)
1113 m_aTabStop
= makeBoolAny(_rxInStream
->readBoolean());
1117 m_bNavigation
= _rxInStream
->readBoolean();
1119 if (nAnyMask
& TEXTCOLOR
)
1121 sal_Int32 nValue
= _rxInStream
->readLong();
1122 setTextColor( (sal_Int32
)nValue
);
1127 _rxInStream
>> m_sHelpText
;
1129 if (nAnyMask
& FONTDESCRIPTOR
)
1131 FontDescriptor aUNOFont
;
1132 _rxInStream
>> aUNOFont
;
1136 if (nAnyMask
& RECORDMARKER
)
1137 m_bRecordMarker
= _rxInStream
->readBoolean();
1141 m_bPrintable
= _rxInStream
->readBoolean();
1143 if (nAnyMask
& BACKGROUNDCOLOR
)
1145 sal_Int32 nValue
= _rxInStream
->readLong();
1146 m_aBackgroundColor
<<= (sal_Int32
)nValue
;
1150 //.........................................................................
1152 //.........................................................................
1154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */