update dev300-m58
[ooovba.git] / forms / source / component / Grid.cxx
blob500909fdc5d9baa434e855371d66f1b525220bd4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Grid.cxx,v $
10 * $Revision: 1.43 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
34 #include "Columns.hxx"
35 #include "findpos.hxx"
36 #include "Grid.hxx"
37 #include "property.hrc"
38 #include "property.hxx"
39 #include "services.hxx"
41 /** === begin UNO includes === **/
42 #include <com/sun/star/form/FormComponentType.hpp>
43 #include <com/sun/star/form/XForm.hpp>
44 #include <com/sun/star/form/XLoadable.hpp>
45 #include <com/sun/star/text/WritingMode2.hpp>
46 /** === end UNO includes === **/
48 #include <comphelper/basicio.hxx>
49 #include <comphelper/container.hxx>
50 #include <comphelper/extract.hxx>
51 #include <cppuhelper/queryinterface.hxx>
52 #include <toolkit/helper/vclunohelper.hxx>
53 #include <vcl/svapp.hxx>
55 using namespace ::com::sun::star::uno;
57 //.........................................................................
58 namespace frm
60 //.........................................................................
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::sdb;
64 using namespace ::com::sun::star::sdbc;
65 using namespace ::com::sun::star::sdbcx;
66 using namespace ::com::sun::star::beans;
67 using namespace ::com::sun::star::container;
68 using namespace ::com::sun::star::form;
69 using namespace ::com::sun::star::awt;
70 using namespace ::com::sun::star::io;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::util;
73 using namespace ::com::sun::star::view;
75 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
77 const sal_uInt16 ROWHEIGHT = 0x0001;
78 const sal_uInt16 FONTTYPE = 0x0002;
79 const sal_uInt16 FONTSIZE = 0x0004;
80 const sal_uInt16 FONTATTRIBS = 0x0008;
81 const sal_uInt16 TABSTOP = 0x0010;
82 const sal_uInt16 TEXTCOLOR = 0x0020;
83 const sal_uInt16 FONTDESCRIPTOR = 0x0040;
84 const sal_uInt16 RECORDMARKER = 0x0080;
85 const sal_uInt16 BACKGROUNDCOLOR = 0x0100;
87 //------------------------------------------------------------------
88 InterfaceRef SAL_CALL OGridControlModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
90 return *(new OGridControlModel(_rxFactory));
93 DBG_NAME(OGridControlModel);
94 //------------------------------------------------------------------
95 OGridControlModel::OGridControlModel(const Reference<XMultiServiceFactory>& _rxFactory)
96 :OControlModel(_rxFactory, ::rtl::OUString())
97 ,OInterfaceContainer(_rxFactory, m_aMutex, ::getCppuType(static_cast<Reference<XPropertySet>*>(NULL)))
98 ,OErrorBroadcaster( OComponentHelper::rBHelper )
99 ,FontControlModel( false )
100 ,m_aSelectListeners(m_aMutex)
101 ,m_aResetListeners(m_aMutex)
102 ,m_aRowSetChangeListeners(m_aMutex)
103 ,m_aDefaultControl( FRM_SUN_CONTROL_GRIDCONTROL )
104 ,m_nBorder(1)
105 ,m_nWritingMode( WritingMode2::CONTEXT )
106 ,m_nContextWritingMode( WritingMode2::CONTEXT )
107 ,m_bEnableVisible(sal_True)
108 ,m_bEnable(sal_True)
109 ,m_bNavigation(sal_True)
110 ,m_bRecordMarker(sal_True)
111 ,m_bPrintable(sal_True)
112 ,m_bAlwaysShowCursor(sal_False)
113 ,m_bDisplaySynchron(sal_True)
115 DBG_CTOR(OGridControlModel,NULL);
117 m_nClassId = FormComponentType::GRIDCONTROL;
120 //------------------------------------------------------------------
121 OGridControlModel::OGridControlModel( const OGridControlModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
122 :OControlModel( _pOriginal, _rxFactory )
123 ,OInterfaceContainer( _rxFactory, m_aMutex, ::getCppuType( static_cast<Reference<XPropertySet>*>( NULL ) ) )
124 ,OErrorBroadcaster( OComponentHelper::rBHelper )
125 ,FontControlModel( _pOriginal )
126 ,m_aSelectListeners( m_aMutex )
127 ,m_aResetListeners( m_aMutex )
128 ,m_aRowSetChangeListeners( m_aMutex )
130 DBG_CTOR(OGridControlModel,NULL);
132 m_aDefaultControl = _pOriginal->m_aDefaultControl;
133 m_bEnable = _pOriginal->m_bEnable;
134 m_bEnableVisible = _pOriginal->m_bEnableVisible;
135 m_bNavigation = _pOriginal->m_bNavigation;
136 m_nBorder = _pOriginal->m_nBorder;
137 m_nWritingMode = _pOriginal->m_nWritingMode;
138 m_nContextWritingMode = _pOriginal->m_nContextWritingMode;
139 m_bRecordMarker = _pOriginal->m_bRecordMarker;
140 m_bPrintable = _pOriginal->m_bPrintable;
141 m_bAlwaysShowCursor = _pOriginal->m_bAlwaysShowCursor;
142 m_bDisplaySynchron = _pOriginal->m_bDisplaySynchron;
144 // clone the columns
145 cloneColumns( _pOriginal );
147 // TODO: clone the events?
150 //------------------------------------------------------------------
151 OGridControlModel::~OGridControlModel()
153 if (!OComponentHelper::rBHelper.bDisposed)
155 acquire();
156 dispose();
159 DBG_DTOR(OGridControlModel,NULL);
162 // XCloneable
163 //------------------------------------------------------------------------------
164 Reference< XCloneable > SAL_CALL OGridControlModel::createClone( ) throw (RuntimeException)
166 OGridControlModel* pClone = new OGridControlModel( this, getContext().getLegacyServiceFactory() );
167 osl_incrementInterlockedCount( &pClone->m_refCount );
168 pClone->OControlModel::clonedFrom( this );
169 // do not call OInterfaceContainer::clonedFrom, it would clone the elements aka columns, which is
170 // already done in the ctor
171 //pClone->OInterfaceContainer::clonedFrom( *this );
172 osl_decrementInterlockedCount( &pClone->m_refCount );
173 return static_cast< XCloneable* >( static_cast< OControlModel* >( pClone ) );
176 //------------------------------------------------------------------------------
177 void OGridControlModel::cloneColumns( const OGridControlModel* _pOriginalContainer )
181 Reference< XCloneable > xColCloneable;
183 const OInterfaceArray::const_iterator pColumnStart = _pOriginalContainer->m_aItems.begin();
184 const OInterfaceArray::const_iterator pColumnEnd = _pOriginalContainer->m_aItems.end();
185 for ( OInterfaceArray::const_iterator pColumn = pColumnStart; pColumn != pColumnEnd; ++pColumn )
187 // ask the col for a factory for the clone
188 xColCloneable = xColCloneable.query( *pColumn );
189 DBG_ASSERT( xColCloneable.is(), "OGridControlModel::cloneColumns: column is not cloneable!" );
191 if ( xColCloneable.is() )
193 // create a clone of the column
194 Reference< XCloneable > xColClone( xColCloneable->createClone() );
195 DBG_ASSERT( xColClone.is(), "OGridControlModel::cloneColumns: invalid column clone!" );
197 if ( xColClone.is() )
199 // insert this clone into our own container
200 insertByIndex( pColumn - pColumnStart, xColClone->queryInterface( m_aElementType ) );
206 catch( const Exception& )
208 DBG_ERROR( "OGridControlModel::cloneColumns: caught an exception while cloning the columns!" );
212 // XServiceInfo
213 //------------------------------------------------------------------------------
214 StringSequence OGridControlModel::getSupportedServiceNames() throw(RuntimeException)
216 StringSequence aSupported = OControlModel::getSupportedServiceNames();
217 aSupported.realloc(aSupported.getLength() + 2);
219 ::rtl::OUString*pArray = aSupported.getArray();
220 pArray[aSupported.getLength()-2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlModel"));
221 pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_GRIDCONTROL;
222 return aSupported;
225 //------------------------------------------------------------------------------
226 Any SAL_CALL OGridControlModel::queryAggregation( const Type& _rType ) throw (RuntimeException)
228 Any aReturn = OGridControlModel_BASE::queryInterface(_rType);
230 if ( !aReturn.hasValue() )
232 aReturn = OControlModel::queryAggregation( _rType );
233 if ( !aReturn.hasValue() )
235 aReturn = OInterfaceContainer::queryInterface( _rType );
236 if ( !aReturn.hasValue() )
237 aReturn = OErrorBroadcaster::queryInterface( _rType );
240 return aReturn;
243 // XSQLErrorListener
244 //------------------------------------------------------------------------------
245 void SAL_CALL OGridControlModel::errorOccured( const SQLErrorEvent& _rEvent ) throw (RuntimeException)
247 // forward the errors which happened to my columns to my own listeners
248 onError( _rEvent );
251 // XRowSetSupplier
252 //------------------------------------------------------------------------------
253 Reference< XRowSet > SAL_CALL OGridControlModel::getRowSet( ) throw (RuntimeException)
255 return Reference< XRowSet >( getParent(), UNO_QUERY );
258 //------------------------------------------------------------------------------
259 void SAL_CALL OGridControlModel::setRowSet( const Reference< XRowSet >& /*_rxDataSource*/ ) throw (RuntimeException)
261 OSL_ENSURE( false, "OGridControlModel::setRowSet: not supported!" );
264 //--------------------------------------------------------------------
265 void SAL_CALL OGridControlModel::addRowSetChangeListener( const Reference< XRowSetChangeListener >& i_Listener ) throw (RuntimeException)
267 if ( i_Listener.is() )
268 m_aRowSetChangeListeners.addInterface( i_Listener );
271 //--------------------------------------------------------------------
272 void SAL_CALL OGridControlModel::removeRowSetChangeListener( const Reference< XRowSetChangeListener >& i_Listener ) throw (RuntimeException)
274 m_aRowSetChangeListeners.removeInterface( i_Listener );
277 // XChild
278 //------------------------------------------------------------------------------
279 void SAL_CALL OGridControlModel::setParent( const InterfaceRef& i_Parent ) throw(NoSupportException, RuntimeException)
281 ::osl::ClearableMutexGuard aGuard( m_aMutex );
282 if ( i_Parent == getParent() )
283 return;
285 OControlModel::setParent( i_Parent );
287 EventObject aEvent( *this );
288 aGuard.clear();
289 m_aRowSetChangeListeners.notifyEach( &XRowSetChangeListener::onRowSetChanged, aEvent );
292 //------------------------------------------------------------------------------
293 Sequence< Type > SAL_CALL OGridControlModel::getTypes( ) throw(RuntimeException)
295 return concatSequences(
296 concatSequences(
297 OControlModel::getTypes(),
298 OInterfaceContainer::getTypes(),
299 OErrorBroadcaster::getTypes()
301 OGridControlModel_BASE::getTypes()
305 // OComponentHelper
306 //------------------------------------------------------------------------------
307 void OGridControlModel::disposing()
309 OControlModel::disposing();
310 OErrorBroadcaster::disposing();
311 OInterfaceContainer::disposing();
313 setParent(NULL);
315 EventObject aEvt(static_cast<XWeak*>(this));
316 m_aSelectListeners.disposeAndClear(aEvt);
317 m_aResetListeners.disposeAndClear(aEvt);
318 m_aRowSetChangeListeners.disposeAndClear(aEvt);
321 // XEventListener
322 //------------------------------------------------------------------------------
323 void OGridControlModel::disposing(const EventObject& _rEvent) throw( RuntimeException )
325 OControlModel::disposing( _rEvent );
326 OInterfaceContainer::disposing( _rEvent );
329 // XSelectionSupplier
330 //-----------------------------------------------------------------------------
331 sal_Bool SAL_CALL OGridControlModel::select(const Any& rElement) throw(IllegalArgumentException, RuntimeException)
333 ::osl::ClearableMutexGuard aGuard( m_aMutex );
335 Reference<XPropertySet> xSel;
336 if (rElement.hasValue() && !::cppu::extractInterface(xSel, rElement))
338 throw IllegalArgumentException();
340 InterfaceRef xMe = static_cast<XWeak*>(this);
342 if (xSel.is())
344 Reference<XChild> xAsChild(xSel, UNO_QUERY);
345 if (!xAsChild.is() || (xAsChild->getParent() != xMe))
347 throw IllegalArgumentException();
351 if ( xSel != m_xSelection )
353 m_xSelection = xSel;
354 aGuard.clear();
355 m_aSelectListeners.notifyEach( &XSelectionChangeListener::selectionChanged, EventObject( *this ) );
356 return sal_True;
358 return sal_False;
361 //-----------------------------------------------------------------------------
362 Any SAL_CALL OGridControlModel::getSelection() throw(RuntimeException)
364 return makeAny(m_xSelection);
367 //-----------------------------------------------------------------------------
368 void OGridControlModel::addSelectionChangeListener(const Reference< XSelectionChangeListener >& _rxListener) throw( RuntimeException )
370 m_aSelectListeners.addInterface(_rxListener);
373 //-----------------------------------------------------------------------------
374 void OGridControlModel::removeSelectionChangeListener(const Reference< XSelectionChangeListener >& _rxListener) throw( RuntimeException )
376 m_aSelectListeners.removeInterface(_rxListener);
379 // XGridColumnFactory
380 //------------------------------------------------------------------------------
381 Reference<XPropertySet> SAL_CALL OGridControlModel::createColumn(const ::rtl::OUString& ColumnType) throw ( :: com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
383 const Sequence< ::rtl::OUString >& rColumnTypes = frm::getColumnTypes();
384 return createColumn( detail::findPos( ColumnType, rColumnTypes ) );
387 //------------------------------------------------------------------------------
388 Reference<XPropertySet> OGridControlModel::createColumn(sal_Int32 nTypeId) const
390 Reference<XPropertySet> xReturn;
391 switch (nTypeId)
393 case TYPE_CHECKBOX: xReturn = new CheckBoxColumn( getContext() ); break;
394 case TYPE_COMBOBOX: xReturn = new ComboBoxColumn( getContext() ); break;
395 case TYPE_CURRENCYFIELD: xReturn = new CurrencyFieldColumn( getContext() ); break;
396 case TYPE_DATEFIELD: xReturn = new DateFieldColumn( getContext() ); break;
397 case TYPE_LISTBOX: xReturn = new ListBoxColumn( getContext() ); break;
398 case TYPE_NUMERICFIELD: xReturn = new NumericFieldColumn( getContext() ); break;
399 case TYPE_PATTERNFIELD: xReturn = new PatternFieldColumn( getContext() ); break;
400 case TYPE_TEXTFIELD: xReturn = new TextFieldColumn( getContext() ); break;
401 case TYPE_TIMEFIELD: xReturn = new TimeFieldColumn( getContext() ); break;
402 case TYPE_FORMATTEDFIELD: xReturn = new FormattedFieldColumn( getContext() ); break;
403 default:
404 DBG_ERROR("OGridControlModel::createColumn: Unknown Column");
405 break;
407 return xReturn;
410 //------------------------------------------------------------------------------
411 StringSequence SAL_CALL OGridControlModel::getColumnTypes() throw ( ::com::sun::star::uno::RuntimeException)
413 return frm::getColumnTypes();
416 // XReset
417 //-----------------------------------------------------------------------------
418 void SAL_CALL OGridControlModel::reset() throw ( ::com::sun::star::uno::RuntimeException)
420 ::cppu::OInterfaceIteratorHelper aIter(m_aResetListeners);
421 EventObject aEvt(static_cast<XWeak*>(this));
422 sal_Bool bContinue = sal_True;
423 while (aIter.hasMoreElements() && bContinue)
424 bContinue =((XResetListener*)aIter.next())->approveReset(aEvt);
426 if (bContinue)
428 _reset();
429 m_aResetListeners.notifyEach( &XResetListener::resetted, aEvt );
433 //-----------------------------------------------------------------------------
434 void SAL_CALL OGridControlModel::addResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException)
436 m_aResetListeners.addInterface(_rxListener);
439 //-----------------------------------------------------------------------------
440 void SAL_CALL OGridControlModel::removeResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException)
442 m_aResetListeners.removeInterface(_rxListener);
445 //-----------------------------------------------------------------------------
446 void OGridControlModel::_reset()
448 Reference<XReset> xReset;
449 sal_Int32 nCount = getCount();
450 for (sal_Int32 nIndex=0; nIndex < nCount; nIndex++)
452 getByIndex( nIndex ) >>= xReset;
453 if (xReset.is())
454 xReset->reset();
458 // XPropertySet
459 //------------------------------------------------------------------------------
460 void OGridControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
462 BEGIN_DESCRIBE_BASE_PROPERTIES( 37 )
463 DECL_PROP1(NAME, ::rtl::OUString, BOUND);
464 DECL_PROP2(CLASSID, sal_Int16, READONLY, TRANSIENT);
465 DECL_PROP1(TAG, ::rtl::OUString, BOUND);
466 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
467 DECL_PROP3(TABSTOP, sal_Bool, BOUND, MAYBEDEFAULT, MAYBEVOID);
468 DECL_PROP2(HASNAVIGATION, sal_Bool, BOUND, MAYBEDEFAULT);
469 DECL_PROP1(ENABLED, sal_Bool, BOUND);
470 DECL_PROP2(ENABLEVISIBLE, sal_Bool, BOUND, MAYBEDEFAULT);
471 DECL_PROP1(BORDER, sal_Int16, BOUND);
472 DECL_PROP2(BORDERCOLOR, sal_Int16, BOUND, MAYBEVOID);
473 DECL_PROP1(DEFAULTCONTROL, ::rtl::OUString, BOUND);
474 DECL_PROP3(TEXTCOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID);
475 DECL_PROP3(BACKGROUNDCOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID);
476 DECL_PROP2(FONT, FontDescriptor, BOUND, MAYBEDEFAULT);
477 DECL_PROP3(ROWHEIGHT, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID);
478 DECL_PROP1(HELPTEXT, ::rtl::OUString, BOUND);
479 DECL_PROP1(FONT_NAME, ::rtl::OUString, MAYBEDEFAULT);
480 DECL_PROP1(FONT_STYLENAME, ::rtl::OUString, MAYBEDEFAULT);
481 DECL_PROP1(FONT_FAMILY, sal_Int16, MAYBEDEFAULT);
482 DECL_PROP1(FONT_CHARSET, sal_Int16, MAYBEDEFAULT);
483 DECL_PROP1(FONT_HEIGHT, float, MAYBEDEFAULT);
484 DECL_PROP1(FONT_WEIGHT, float, MAYBEDEFAULT);
485 DECL_PROP1(FONT_SLANT, sal_Int16, MAYBEDEFAULT);
486 DECL_PROP1(FONT_UNDERLINE, sal_Int16, MAYBEDEFAULT);
487 DECL_BOOL_PROP1(FONT_WORDLINEMODE, MAYBEDEFAULT);
488 DECL_PROP3(TEXTLINECOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID);
489 DECL_PROP2(FONTEMPHASISMARK, sal_Int16, BOUND, MAYBEDEFAULT);
490 DECL_PROP2(FONTRELIEF, sal_Int16, BOUND, MAYBEDEFAULT);
491 DECL_PROP1(FONT_STRIKEOUT, sal_Int16, MAYBEDEFAULT);
492 DECL_PROP2(RECORDMARKER, sal_Bool, BOUND, MAYBEDEFAULT );
493 DECL_PROP2(PRINTABLE, sal_Bool, BOUND, MAYBEDEFAULT );
494 DECL_PROP4(CURSORCOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID , TRANSIENT);
495 DECL_PROP3(ALWAYSSHOWCURSOR, sal_Bool, BOUND, MAYBEDEFAULT, TRANSIENT);
496 DECL_PROP3(DISPLAYSYNCHRON, sal_Bool, BOUND, MAYBEDEFAULT, TRANSIENT);
497 DECL_PROP2(HELPURL, ::rtl::OUString, BOUND, MAYBEDEFAULT);
498 DECL_PROP2(WRITING_MODE, sal_Int16, BOUND, MAYBEDEFAULT);
499 DECL_PROP3(CONTEXT_WRITING_MODE,sal_Int16, BOUND, MAYBEDEFAULT, TRANSIENT);
500 END_DESCRIBE_PROPERTIES();
503 //------------------------------------------------------------------------------
504 void OGridControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle ) const
506 switch (nHandle)
508 case PROPERTY_ID_CONTEXT_WRITING_MODE:
509 rValue <<= m_nContextWritingMode;
510 break;
511 case PROPERTY_ID_WRITING_MODE:
512 rValue <<= m_nWritingMode;
513 break;
514 case PROPERTY_ID_HELPTEXT:
515 rValue <<= m_sHelpText;
516 break;
517 case PROPERTY_ID_HELPURL:
518 rValue <<= m_sHelpURL;
519 break;
520 case PROPERTY_ID_DISPLAYSYNCHRON:
521 setBOOL(rValue, m_bDisplaySynchron);
522 break;
523 case PROPERTY_ID_ALWAYSSHOWCURSOR:
524 setBOOL(rValue, m_bAlwaysShowCursor);
525 break;
526 case PROPERTY_ID_CURSORCOLOR:
527 rValue = m_aCursorColor;
528 break;
529 case PROPERTY_ID_PRINTABLE:
530 setBOOL(rValue, m_bPrintable);
531 break;
532 case PROPERTY_ID_TABSTOP:
533 rValue = m_aTabStop;
534 break;
535 case PROPERTY_ID_HASNAVIGATION:
536 setBOOL(rValue, m_bNavigation);
537 break;
538 case PROPERTY_ID_RECORDMARKER:
539 setBOOL(rValue, m_bRecordMarker);
540 break;
541 case PROPERTY_ID_ENABLED:
542 setBOOL(rValue, m_bEnable);
543 break;
544 case PROPERTY_ID_ENABLEVISIBLE:
545 setBOOL(rValue, m_bEnableVisible);
546 break;
547 case PROPERTY_ID_BORDER:
548 rValue <<= (sal_Int16)m_nBorder;
549 break;
550 case PROPERTY_ID_BORDERCOLOR:
551 rValue <<= m_aBorderColor;
552 break;
553 case PROPERTY_ID_DEFAULTCONTROL:
554 rValue <<= m_aDefaultControl;
555 break;
556 case PROPERTY_ID_BACKGROUNDCOLOR:
557 rValue = m_aBackgroundColor;
558 break;
559 case PROPERTY_ID_ROWHEIGHT:
560 rValue = m_aRowHeight;
561 break;
563 default:
564 if ( isFontRelatedProperty( nHandle ) )
565 FontControlModel::getFastPropertyValue( rValue, nHandle );
566 else
567 OControlModel::getFastPropertyValue( rValue, nHandle );
571 //------------------------------------------------------------------------------
572 sal_Bool OGridControlModel::convertFastPropertyValue( Any& rConvertedValue, Any& rOldValue,
573 sal_Int32 nHandle, const Any& rValue )throw( IllegalArgumentException )
575 sal_Bool bModified(sal_False);
576 switch (nHandle)
578 case PROPERTY_ID_CONTEXT_WRITING_MODE:
579 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_nContextWritingMode );
580 break;
581 case PROPERTY_ID_WRITING_MODE:
582 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_nWritingMode );
583 break;
584 case PROPERTY_ID_HELPTEXT:
585 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sHelpText);
586 break;
587 case PROPERTY_ID_HELPURL:
588 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sHelpURL);
589 break;
590 case PROPERTY_ID_DISPLAYSYNCHRON:
591 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bDisplaySynchron);
592 break;
593 case PROPERTY_ID_ALWAYSSHOWCURSOR:
594 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAlwaysShowCursor);
595 break;
596 case PROPERTY_ID_CURSORCOLOR:
597 if (!rValue.hasValue() || !m_aCursorColor.hasValue())
599 if (rValue.hasValue() && (TypeClass_LONG != rValue.getValueType().getTypeClass()))
601 throw IllegalArgumentException();
603 rOldValue = m_aCursorColor;
604 rConvertedValue = rValue;
605 bModified = (rOldValue.getValue() != rConvertedValue.getValue());
607 else
608 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, getINT32(m_aCursorColor));
609 break;
610 case PROPERTY_ID_PRINTABLE:
611 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bPrintable);
612 break;
613 case PROPERTY_ID_TABSTOP:
614 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aTabStop, ::getBooleanCppuType());
615 break;
616 case PROPERTY_ID_HASNAVIGATION:
617 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bNavigation);
618 break;
619 case PROPERTY_ID_RECORDMARKER:
620 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bRecordMarker);
621 break;
622 case PROPERTY_ID_ENABLED:
623 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEnable);
624 break;
625 case PROPERTY_ID_ENABLEVISIBLE:
626 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEnableVisible);
627 break;
628 case PROPERTY_ID_BORDER:
629 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_nBorder);
630 break;
631 case PROPERTY_ID_BORDERCOLOR:
632 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aBorderColor, ::getCppuType((const sal_Int32*)NULL));
633 break;
634 case PROPERTY_ID_DEFAULTCONTROL:
635 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aDefaultControl);
636 break;
637 case PROPERTY_ID_BACKGROUNDCOLOR:
638 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aBackgroundColor, ::getCppuType((const sal_Int32*)NULL));
639 break;
640 case PROPERTY_ID_ROWHEIGHT:
642 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aRowHeight, ::getCppuType((const sal_Int32*)NULL));
644 sal_Int32 nNewVal( 0 );
645 if ( ( rConvertedValue >>= nNewVal ) && ( nNewVal <= 0 ) )
647 rConvertedValue.clear();
648 bModified = m_aRowHeight.hasValue();
651 break;
652 default:
653 if ( isFontRelatedProperty( nHandle ) )
654 bModified = FontControlModel::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
655 else
656 bModified = OControlModel::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue);
658 return bModified;
661 //------------------------------------------------------------------------------
662 void OGridControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw ( ::com::sun::star::uno::Exception)
664 switch (nHandle)
666 case PROPERTY_ID_CONTEXT_WRITING_MODE:
667 rValue >>= m_nContextWritingMode;
668 break;
669 case PROPERTY_ID_WRITING_MODE:
670 rValue >>= m_nWritingMode;
671 break;
672 case PROPERTY_ID_HELPTEXT:
673 rValue >>= m_sHelpText;
674 break;
675 case PROPERTY_ID_HELPURL:
676 rValue >>= m_sHelpURL;
677 break;
678 case PROPERTY_ID_DISPLAYSYNCHRON:
679 m_bDisplaySynchron = getBOOL(rValue);
680 break;
681 case PROPERTY_ID_ALWAYSSHOWCURSOR:
682 m_bAlwaysShowCursor = getBOOL(rValue);
683 break;
684 case PROPERTY_ID_CURSORCOLOR:
685 m_aCursorColor = rValue;
686 break;
687 case PROPERTY_ID_PRINTABLE:
688 m_bPrintable = getBOOL(rValue);
689 break;
690 case PROPERTY_ID_TABSTOP:
691 m_aTabStop = rValue;
692 break;
693 case PROPERTY_ID_HASNAVIGATION:
694 m_bNavigation = getBOOL(rValue);
695 break;
696 case PROPERTY_ID_ENABLED:
697 m_bEnable = getBOOL(rValue);
698 break;
699 case PROPERTY_ID_ENABLEVISIBLE:
700 m_bEnableVisible = getBOOL(rValue);
701 break;
702 case PROPERTY_ID_RECORDMARKER:
703 m_bRecordMarker = getBOOL(rValue);
704 break;
705 case PROPERTY_ID_BORDER:
706 rValue >>= m_nBorder;
707 break;
708 case PROPERTY_ID_BORDERCOLOR:
709 m_aBorderColor = rValue;
710 break;
711 case PROPERTY_ID_DEFAULTCONTROL:
712 rValue >>= m_aDefaultControl;
713 break;
714 case PROPERTY_ID_BACKGROUNDCOLOR:
715 m_aBackgroundColor = rValue;
716 break;
717 case PROPERTY_ID_ROWHEIGHT:
718 m_aRowHeight = rValue;
719 break;
721 default:
722 if ( isFontRelatedProperty( nHandle ) )
724 FontDescriptor aOldFont( getFont() );
726 FontControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue );
728 if ( isFontAggregateProperty( nHandle ) )
729 firePropertyChange( PROPERTY_ID_FONT, makeAny( getFont() ), makeAny( aOldFont ) );
731 else
732 OControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue );
737 //XPropertyState
739 //------------------------------------------------------------------------------
740 Any OGridControlModel::getPropertyDefaultByHandle( sal_Int32 nHandle ) const
742 Any aReturn;
743 switch (nHandle)
745 case PROPERTY_ID_CONTEXT_WRITING_MODE:
746 case PROPERTY_ID_WRITING_MODE:
747 aReturn <<= WritingMode2::CONTEXT;
748 break;
750 case PROPERTY_ID_DEFAULTCONTROL:
751 aReturn <<= ::rtl::OUString( STARDIV_ONE_FORM_CONTROL_GRID );
752 break;
754 case PROPERTY_ID_PRINTABLE:
755 case PROPERTY_ID_HASNAVIGATION:
756 case PROPERTY_ID_RECORDMARKER:
757 case PROPERTY_ID_DISPLAYSYNCHRON:
758 case PROPERTY_ID_ENABLED:
759 case PROPERTY_ID_ENABLEVISIBLE:
760 aReturn = makeBoolAny(sal_True);
761 break;
763 case PROPERTY_ID_ALWAYSSHOWCURSOR:
764 aReturn = makeBoolAny(sal_False);
765 break;
767 case PROPERTY_ID_HELPURL:
768 case PROPERTY_ID_HELPTEXT:
769 aReturn <<= ::rtl::OUString();
770 break;
772 case PROPERTY_ID_BORDER:
773 aReturn <<= (sal_Int16)1;
774 break;
776 case PROPERTY_ID_BORDERCOLOR:
777 case PROPERTY_ID_TABSTOP:
778 case PROPERTY_ID_BACKGROUNDCOLOR:
779 case PROPERTY_ID_ROWHEIGHT:
780 case PROPERTY_ID_CURSORCOLOR:
781 // void
782 break;
784 default:
785 if ( isFontRelatedProperty( nHandle ) )
786 aReturn = FontControlModel::getPropertyDefaultByHandle( nHandle );
787 else
788 aReturn = OControlModel::getPropertyDefaultByHandle(nHandle);
790 return aReturn;
793 //------------------------------------------------------------------------------
794 OGridColumn* OGridControlModel::getColumnImplementation(const InterfaceRef& _rxIFace) const
796 OGridColumn* pImplementation = NULL;
797 Reference< XUnoTunnel > xUnoTunnel( _rxIFace, UNO_QUERY );
798 if ( xUnoTunnel.is() )
799 pImplementation = reinterpret_cast<OGridColumn*>(xUnoTunnel->getSomething(OGridColumn::getUnoTunnelImplementationId()));
801 return pImplementation;
804 //------------------------------------------------------------------------------
805 void OGridControlModel::gotColumn( const Reference< XInterface >& _rxColumn )
807 Reference< XSQLErrorBroadcaster > xBroadcaster( _rxColumn, UNO_QUERY );
808 if ( xBroadcaster.is() )
809 xBroadcaster->addSQLErrorListener( this );
812 //------------------------------------------------------------------------------
813 void OGridControlModel::lostColumn(const Reference< XInterface >& _rxColumn)
815 if ( m_xSelection == _rxColumn )
816 { // the currently selected element was replaced
817 m_xSelection.clear();
818 EventObject aEvt( static_cast< XWeak* >( this ) );
819 m_aSelectListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvt );
822 Reference< XSQLErrorBroadcaster > xBroadcaster( _rxColumn, UNO_QUERY );
823 if ( xBroadcaster.is() )
824 xBroadcaster->removeSQLErrorListener( this );
827 //------------------------------------------------------------------------------
828 void OGridControlModel::implRemoved(const InterfaceRef& _rxObject)
830 OInterfaceContainer::implRemoved(_rxObject);
831 lostColumn(_rxObject);
834 //------------------------------------------------------------------------------
835 void OGridControlModel::implInserted( const ElementDescription* _pElement )
837 OInterfaceContainer::implInserted( _pElement );
838 gotColumn( _pElement->xInterface );
841 //------------------------------------------------------------------------------
842 void OGridControlModel::impl_replacedElement( const ContainerEvent& _rEvent, ::osl::ClearableMutexGuard& _rInstanceLock )
844 Reference< XInterface > xOldColumn( _rEvent.ReplacedElement, UNO_QUERY );
845 Reference< XInterface > xNewColumn( _rEvent.Element, UNO_QUERY );
847 bool bNewSelection = ( xOldColumn == m_xSelection );
849 lostColumn( xOldColumn );
850 gotColumn( xNewColumn );
852 if ( bNewSelection )
853 m_xSelection.set( xNewColumn, UNO_QUERY );
855 OInterfaceContainer::impl_replacedElement( _rEvent, _rInstanceLock );
856 // <<---- SYNCHRONIZED
858 if ( bNewSelection )
860 m_aSelectListeners.notifyEach( &XSelectionChangeListener::selectionChanged, EventObject( *this ) );
864 //------------------------------------------------------------------------------
865 ElementDescription* OGridControlModel::createElementMetaData( )
867 return new ColumnDescription;
870 //------------------------------------------------------------------------------
871 void OGridControlModel::approveNewElement( const Reference< XPropertySet >& _rxObject, ElementDescription* _pElement )
873 OGridColumn* pCol = getColumnImplementation( _rxObject );
874 if ( !pCol )
875 throw IllegalArgumentException();
877 OInterfaceContainer::approveNewElement( _rxObject, _pElement );
879 // if we're here, the object passed all tests
880 if ( _pElement )
881 static_cast< ColumnDescription* >( _pElement )->pColumn = pCol;
884 // XPersistObject
885 //------------------------------------------------------------------------------
886 ::rtl::OUString SAL_CALL OGridControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
888 return FRM_COMPONENT_GRID; // old (non-sun) name for compatibility !
891 //------------------------------------------------------------------------------
892 void OGridControlModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
894 OControlModel::write(_rxOutStream);
896 Reference<XMarkableStream> xMark(_rxOutStream, UNO_QUERY);
898 // 1. Version
899 _rxOutStream->writeShort(0x0008);
901 // 2. Columns
902 sal_Int32 nLen = getCount();
903 _rxOutStream->writeLong(nLen);
904 OGridColumn* pCol;
905 for (sal_Int32 i = 0; i < nLen; i++)
907 // zuerst den Servicenamen fuer das darunterliegende Model
908 pCol = getColumnImplementation(m_aItems[i]);
909 DBG_ASSERT(pCol != NULL, "OGridControlModel::write : such items should never reach it into my container !");
911 _rxOutStream << pCol->getModelName();
913 // dann das Object selbst
914 sal_Int32 nMark = xMark->createMark();
915 sal_Int32 nObjLen = 0;
916 _rxOutStream->writeLong(nObjLen);
918 // schreiben der Col
919 pCol->write(_rxOutStream);
921 // feststellen der Laenge
922 nObjLen = xMark->offsetToMark(nMark) - 4;
923 xMark->jumpToMark(nMark);
924 _rxOutStream->writeLong(nObjLen);
925 xMark->jumpToFurthest();
926 xMark->deleteMark(nMark);
929 // 3. Events
930 writeEvents(_rxOutStream);
932 // 4. Attribute
933 // Maskierung fuer alle any Typen
934 sal_uInt16 nAnyMask = 0;
935 if (m_aRowHeight.getValueType().getTypeClass() == TypeClass_LONG)
936 nAnyMask |= ROWHEIGHT;
937 if ( getFont() != getDefaultFont() )
938 nAnyMask |= FONTATTRIBS | FONTSIZE | FONTTYPE | FONTDESCRIPTOR;
939 if (m_aTabStop.getValueType().getTypeClass() == TypeClass_BOOLEAN)
940 nAnyMask |= TABSTOP;
941 if ( hasTextColor() )
942 nAnyMask |= TEXTCOLOR;
943 if (m_aBackgroundColor.getValueType().getTypeClass() == TypeClass_LONG)
944 nAnyMask |= BACKGROUNDCOLOR;
945 if (!m_bRecordMarker)
946 nAnyMask |= RECORDMARKER;
948 _rxOutStream->writeShort(nAnyMask);
950 if (nAnyMask & ROWHEIGHT)
951 _rxOutStream->writeLong(getINT32(m_aRowHeight));
953 // old structures
954 const FontDescriptor& aFont = getFont();
955 if ( nAnyMask & FONTDESCRIPTOR )
957 // Attrib
958 _rxOutStream->writeShort( sal::static_int_cast< sal_Int16 >( VCLUnoHelper::ConvertFontWeight( aFont.Weight ) ) );
959 _rxOutStream->writeShort( sal::static_int_cast< sal_Int16 >( aFont.Slant ) );
960 _rxOutStream->writeShort( aFont.Underline );
961 _rxOutStream->writeShort( aFont.Strikeout );
962 _rxOutStream->writeShort( sal_Int16(aFont.Orientation * 10) );
963 _rxOutStream->writeBoolean( aFont.Kerning );
964 _rxOutStream->writeBoolean( aFont.WordLineMode );
966 // Size
967 _rxOutStream->writeLong( aFont.Width );
968 _rxOutStream->writeLong( aFont.Height );
969 _rxOutStream->writeShort( sal::static_int_cast< sal_Int16 >( VCLUnoHelper::ConvertFontWidth( aFont.CharacterWidth ) ) );
971 // Type
972 _rxOutStream->writeUTF( aFont.Name );
973 _rxOutStream->writeUTF( aFont.StyleName );
974 _rxOutStream->writeShort( aFont.Family );
975 _rxOutStream->writeShort( aFont.CharSet );
976 _rxOutStream->writeShort( aFont.Pitch );
979 _rxOutStream << m_aDefaultControl;
981 _rxOutStream->writeShort(m_nBorder);
982 _rxOutStream->writeBoolean(m_bEnable);
984 if (nAnyMask & TABSTOP)
985 _rxOutStream->writeBoolean(getBOOL(m_aTabStop));
987 _rxOutStream->writeBoolean(m_bNavigation);
989 if (nAnyMask & TEXTCOLOR)
990 _rxOutStream->writeLong( getTextColor() );
992 // neu ab Version 6
993 _rxOutStream << m_sHelpText;
995 if (nAnyMask & FONTDESCRIPTOR)
996 _rxOutStream << getFont();
998 if (nAnyMask & RECORDMARKER)
999 _rxOutStream->writeBoolean(m_bRecordMarker);
1001 // neu ab Version 7
1002 _rxOutStream->writeBoolean(m_bPrintable);
1004 // new since 8
1005 if (nAnyMask & BACKGROUNDCOLOR)
1006 _rxOutStream->writeLong(getINT32(m_aBackgroundColor));
1009 //------------------------------------------------------------------------------
1010 void OGridControlModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
1012 OControlModel::read(_rxInStream);
1014 Reference<XMarkableStream> xMark(_rxInStream, UNO_QUERY);
1016 // 1. Version
1017 sal_Int16 nVersion = _rxInStream->readShort();
1019 // 2. Einlesen der Spalten
1020 sal_Int32 nLen = _rxInStream->readLong();
1021 if (nLen)
1023 for (sal_Int32 i = 0; i < nLen; i++)
1025 // Lesen des Modelnamen
1027 ::rtl::OUString sModelName;
1028 _rxInStream >> sModelName;
1030 Reference<XPropertySet> xCol(createColumn(getColumnTypeByModelName(sModelName)));
1031 DBG_ASSERT(xCol.is(), "OGridControlModel::read : unknown column type !");
1032 sal_Int32 nObjLen = _rxInStream->readLong();
1033 if (nObjLen)
1035 sal_Int32 nMark = xMark->createMark();
1036 if (xCol.is())
1038 OGridColumn* pCol = getColumnImplementation(xCol);
1039 pCol->read(_rxInStream);
1041 xMark->jumpToMark(nMark);
1042 _rxInStream->skipBytes(nObjLen);
1043 xMark->deleteMark(nMark);
1046 if ( xCol.is() )
1047 implInsert( i, xCol, sal_False, NULL, sal_False );
1051 // In der Basisimplementierung werden die Events nur gelesen, Elemente im Container existieren
1052 // da aber vor TF_ONE fuer das GridControl immer Events geschrieben wurden, muessen sie auch immer
1053 // mit gelesen werden
1054 sal_Int32 nObjLen = _rxInStream->readLong();
1055 if (nObjLen)
1057 sal_Int32 nMark = xMark->createMark();
1058 Reference<XPersistObject> xObj(m_xEventAttacher, UNO_QUERY);
1059 if (xObj.is())
1060 xObj->read(_rxInStream);
1061 xMark->jumpToMark(nMark);
1062 _rxInStream->skipBytes(nObjLen);
1063 xMark->deleteMark(nMark);
1066 // Attachement lesen
1067 for (sal_Int32 i = 0; i < nLen; i++)
1069 InterfaceRef xIfc(m_aItems[i], UNO_QUERY);
1070 Reference<XPropertySet> xSet(xIfc, UNO_QUERY);
1071 Any aHelper;
1072 aHelper <<= xSet;
1073 m_xEventAttacher->attach( i, xIfc, aHelper );
1076 // 4. Einlesen der Attribute
1077 if (nVersion == 1)
1078 return;
1080 // Maskierung fuer any
1081 sal_uInt16 nAnyMask = _rxInStream->readShort();
1083 if (nAnyMask & ROWHEIGHT)
1085 sal_Int32 nValue = _rxInStream->readLong();
1086 m_aRowHeight <<= (sal_Int32)nValue;
1089 FontDescriptor aFont( getFont() );
1090 if ( nAnyMask & FONTATTRIBS )
1092 aFont.Weight = (float)VCLUnoHelper::ConvertFontWeight( _rxInStream->readShort() );
1094 aFont.Slant = (FontSlant)_rxInStream->readShort();
1095 aFont.Underline = _rxInStream->readShort();
1096 aFont.Strikeout = _rxInStream->readShort();
1097 aFont.Orientation = ( (float)_rxInStream->readShort() ) / 10;
1098 aFont.Kerning = _rxInStream->readBoolean();
1099 aFont.WordLineMode = _rxInStream->readBoolean();
1101 if ( nAnyMask & FONTSIZE )
1103 aFont.Width = (sal_Int16)_rxInStream->readLong();
1104 aFont.Height = (sal_Int16)_rxInStream->readLong();
1105 aFont.CharacterWidth = (float)VCLUnoHelper::ConvertFontWidth( _rxInStream->readShort() );
1107 if ( nAnyMask & FONTTYPE )
1109 aFont.Name = _rxInStream->readUTF();
1110 aFont.StyleName = _rxInStream->readUTF();
1111 aFont.Family = _rxInStream->readShort();
1112 aFont.CharSet = _rxInStream->readShort();
1113 aFont.Pitch = _rxInStream->readShort();
1116 if ( nAnyMask & ( FONTATTRIBS | FONTSIZE | FONTTYPE ) )
1117 setFont( aFont );
1119 // Name
1120 _rxInStream >> m_aDefaultControl;
1121 m_nBorder = _rxInStream->readShort();
1122 m_bEnable = _rxInStream->readBoolean();
1124 if (nAnyMask & TABSTOP)
1126 m_aTabStop = makeBoolAny(_rxInStream->readBoolean());
1129 if (nVersion > 3)
1130 m_bNavigation = _rxInStream->readBoolean();
1132 if (nAnyMask & TEXTCOLOR)
1134 sal_Int32 nValue = _rxInStream->readLong();
1135 setTextColor( (sal_Int32)nValue );
1138 // neu ab Version 6
1139 if (nVersion > 5)
1140 _rxInStream >> m_sHelpText;
1142 if (nAnyMask & FONTDESCRIPTOR)
1144 FontDescriptor aUNOFont;
1145 _rxInStream >> aUNOFont;
1146 setFont( aFont );
1149 if (nAnyMask & RECORDMARKER)
1150 m_bRecordMarker = _rxInStream->readBoolean();
1152 // neu ab Version 7
1153 if (nVersion > 6)
1154 m_bPrintable = _rxInStream->readBoolean();
1156 if (nAnyMask & BACKGROUNDCOLOR)
1158 sal_Int32 nValue = _rxInStream->readLong();
1159 m_aBackgroundColor <<= (sal_Int32)nValue;
1163 //.........................................................................
1164 } // namespace frm
1165 //.........................................................................