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 .
22 #include "Columns.hxx"
23 #include "property.hrc"
24 #include "property.hxx"
25 #include "componenttools.hxx"
26 #include "findpos.hxx"
27 #include <com/sun/star/io/XPersistObject.hpp>
28 #include <com/sun/star/io/XObjectOutputStream.hpp>
29 #include <com/sun/star/io/XObjectInputStream.hpp>
30 #include <com/sun/star/io/XMarkableStream.hpp>
31 #include <com/sun/star/form/XFormComponent.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/form/binding/XBindableValue.hpp>
34 #include <com/sun/star/beans/XPropertyContainer.hpp>
35 #include <com/sun/star/text/XText.hpp>
36 #include <comphelper/sequence.hxx>
37 #include <comphelper/property.hxx>
38 #include <comphelper/basicio.hxx>
39 #include <comphelper/servicehelper.hxx>
40 #include "services.hxx"
41 #include "frm_resource.hrc"
42 #include <tools/debug.hxx>
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::container
;
51 using namespace ::com::sun::star::form
;
52 using namespace ::com::sun::star::awt
;
53 using namespace ::com::sun::star::io
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::util
;
56 using namespace ::com::sun::star::text
;
57 using namespace ::com::sun::star::form::binding
;
59 const sal_uInt16 WIDTH
= 0x0001;
60 const sal_uInt16 ALIGN
= 0x0002;
61 const sal_uInt16 OLD_HIDDEN
= 0x0004;
62 const sal_uInt16 COMPATIBLE_HIDDEN
= 0x0008;
65 const css::uno::Sequence
<OUString
>& getColumnTypes()
67 static css::uno::Sequence
<OUString
> aColumnTypes(10);
68 if (aColumnTypes
.getConstArray()[0].isEmpty())
70 OUString
* pNames
= aColumnTypes
.getArray();
71 pNames
[TYPE_CHECKBOX
] = "CheckBox";
72 pNames
[TYPE_COMBOBOX
] = "ComboBox";
73 pNames
[TYPE_CURRENCYFIELD
] = "CurrencyField";
74 pNames
[TYPE_DATEFIELD
] = "DateField";
75 pNames
[TYPE_FORMATTEDFIELD
] = "FormattedField";
76 pNames
[TYPE_LISTBOX
] = "ListBox";
77 pNames
[TYPE_NUMERICFIELD
] = "NumericField";
78 pNames
[TYPE_PATTERNFIELD
] = "PatternField";
79 pNames
[TYPE_TEXTFIELD
] = "TextField";
80 pNames
[TYPE_TIMEFIELD
] = "TimeField";
86 sal_Int32
getColumnTypeByModelName(const OUString
& aModelName
)
88 const OUString
aModelPrefix ("com.sun.star.form.component.");
89 const OUString
aCompatibleModelPrefix ("stardiv.one.form.component.");
91 sal_Int32 nTypeId
= -1;
92 if (aModelName
== FRM_COMPONENT_EDIT
)
93 nTypeId
= TYPE_TEXTFIELD
;
96 sal_Int32 nPrefixPos
= aModelName
.indexOf(aModelPrefix
);
98 sal_Int32 nCompatiblePrefixPos
= aModelName
.indexOf(aCompatibleModelPrefix
);
99 DBG_ASSERT( (nPrefixPos
!= -1) || (nCompatiblePrefixPos
!= -1),
100 "::getColumnTypeByModelName() : wrong servivce !");
103 OUString aColumnType
= (nPrefixPos
!= -1)
104 ? aModelName
.copy(aModelPrefix
.getLength())
105 : aModelName
.copy(aCompatibleModelPrefix
.getLength());
107 const css::uno::Sequence
<OUString
>& rColumnTypes
= getColumnTypes();
108 nTypeId
= ::detail::findPos(aColumnType
, rColumnTypes
);
115 class theOGridColumnImplementationId
: public rtl::Static
< UnoTunnelIdInit
, theOGridColumnImplementationId
> {};
118 const Sequence
<sal_Int8
>& OGridColumn::getUnoTunnelImplementationId()
120 return theOGridColumnImplementationId::get().getSeq();
124 sal_Int64 SAL_CALL
OGridColumn::getSomething( const Sequence
<sal_Int8
>& _rIdentifier
) throw(RuntimeException
, std::exception
)
126 sal_Int64
nReturn(0);
128 if ( (_rIdentifier
.getLength() == 16)
129 && (0 == memcmp( getUnoTunnelImplementationId().getConstArray(), _rIdentifier
.getConstArray(), 16 ))
132 nReturn
= reinterpret_cast<sal_Int64
>(this);
136 Reference
< XUnoTunnel
> xAggTunnel
;
137 if ( query_aggregation( m_xAggregate
, xAggTunnel
) )
138 return xAggTunnel
->getSomething( _rIdentifier
);
144 Sequence
<sal_Int8
> SAL_CALL
OGridColumn::getImplementationId() throw(RuntimeException
, std::exception
)
146 return css::uno::Sequence
<sal_Int8
>();
150 Sequence
<Type
> SAL_CALL
OGridColumn::getTypes() throw(RuntimeException
, std::exception
)
152 TypeBag
aTypes( OGridColumn_BASE::getTypes() );
153 // erase the types which we do not support
154 aTypes
.removeType( cppu::UnoType
<XFormComponent
>::get() );
155 aTypes
.removeType( cppu::UnoType
<XServiceInfo
>::get() );
156 aTypes
.removeType( cppu::UnoType
<XBindableValue
>::get() );
157 aTypes
.removeType( cppu::UnoType
<XPropertyContainer
>::get() );
159 // but re-add their base class(es)
160 aTypes
.addType( cppu::UnoType
<XChild
>::get() );
162 Reference
< XTypeProvider
> xProv
;
163 if ( query_aggregation( m_xAggregate
, xProv
))
164 aTypes
.addTypes( xProv
->getTypes() );
166 aTypes
.removeType( cppu::UnoType
<XTextRange
>::get() );
167 aTypes
.removeType( cppu::UnoType
<XSimpleText
>::get() );
168 aTypes
.removeType( cppu::UnoType
<XText
>::get() );
170 return aTypes
.getTypes();
174 Any SAL_CALL
OGridColumn::queryAggregation( const Type
& _rType
) throw (RuntimeException
, std::exception
)
177 // some functionality at our aggregate cannot be reasonably fulfilled here.
178 if ( _rType
.equals(cppu::UnoType
<XFormComponent
>::get())
179 || _rType
.equals(cppu::UnoType
<XServiceInfo
>::get())
180 || _rType
.equals(cppu::UnoType
<XBindableValue
>::get())
181 || _rType
.equals(cppu::UnoType
<XPropertyContainer
>::get())
182 || comphelper::isAssignableFrom(cppu::UnoType
<XTextRange
>::get(),_rType
)
186 aReturn
= OGridColumn_BASE::queryAggregation(_rType
);
187 if (!aReturn
.hasValue())
189 aReturn
= OPropertySetAggregationHelper::queryInterface(_rType
);
190 if (!aReturn
.hasValue() && m_xAggregate
.is())
191 aReturn
= m_xAggregate
->queryAggregation(_rType
);
198 OGridColumn::OGridColumn( const Reference
<XComponentContext
>& _rContext
, const OUString
& _sModelName
)
199 :OGridColumn_BASE(m_aMutex
)
200 ,OPropertySetAggregationHelper(OGridColumn_BASE::rBHelper
)
201 ,m_aHidden( makeAny( false ) )
202 ,m_aModelName(_sModelName
)
205 // Create the UnoControlModel
206 if ( !m_aModelName
.isEmpty() ) // is there a to-be-aggregated model?
208 osl_atomic_increment( &m_refCount
);
211 m_xAggregate
.set( _rContext
->getServiceManager()->createInstanceWithContext( m_aModelName
, _rContext
), UNO_QUERY
);
212 setAggregation( m_xAggregate
);
215 if ( m_xAggregate
.is() )
216 { // don't omit those brackets - they ensure that the following temporary is properly deleted
217 m_xAggregate
->setDelegator( static_cast< ::cppu::OWeakObject
* >( this ) );
220 // Set refcount back to zero
221 osl_atomic_decrement( &m_refCount
);
226 OGridColumn::OGridColumn( const OGridColumn
* _pOriginal
)
227 :OGridColumn_BASE( m_aMutex
)
228 ,OPropertySetAggregationHelper( OGridColumn_BASE::rBHelper
)
231 m_aWidth
= _pOriginal
->m_aWidth
;
232 m_aAlign
= _pOriginal
->m_aAlign
;
233 m_aHidden
= _pOriginal
->m_aHidden
;
234 m_aModelName
= _pOriginal
->m_aModelName
;
235 m_aLabel
= _pOriginal
->m_aLabel
;
237 osl_atomic_increment( &m_refCount
);
240 m_xAggregate
= createAggregateClone( _pOriginal
);
241 setAggregation( m_xAggregate
);
244 if ( m_xAggregate
.is() )
245 { // don't omit this brackets - they ensure that the following temporary is properly deleted
246 m_xAggregate
->setDelegator( static_cast< ::cppu::OWeakObject
* >( this ) );
249 osl_atomic_decrement( &m_refCount
);
253 OGridColumn::~OGridColumn()
255 if (!OGridColumn_BASE::rBHelper
.bDisposed
)
261 // Free the aggregate
262 if (m_xAggregate
.is())
264 css::uno::Reference
<css::uno::XInterface
> xIface
;
265 m_xAggregate
->setDelegator(xIface
);
272 void SAL_CALL
OGridColumn::disposing(const EventObject
& _rSource
) throw(RuntimeException
, std::exception
)
274 OPropertySetAggregationHelper::disposing(_rSource
);
276 Reference
<XEventListener
> xEvtLstner
;
277 if (query_aggregation(m_xAggregate
, xEvtLstner
))
278 xEvtLstner
->disposing(_rSource
);
283 void OGridColumn::disposing()
285 OGridColumn_BASE::disposing();
286 OPropertySetAggregationHelper::disposing();
288 Reference
<XComponent
> xComp
;
289 if (query_aggregation(m_xAggregate
, xComp
))
294 void OGridColumn::clearAggregateProperties( Sequence
< Property
>& _rProps
, bool bAllowDropDown
)
296 // some properties are not to be exposed to the outer world
297 ::std::set
< OUString
> aForbiddenProperties
;
298 aForbiddenProperties
.insert( PROPERTY_ALIGN
);
299 aForbiddenProperties
.insert( PROPERTY_AUTOCOMPLETE
);
300 aForbiddenProperties
.insert( PROPERTY_BACKGROUNDCOLOR
);
301 aForbiddenProperties
.insert( PROPERTY_BORDER
);
302 aForbiddenProperties
.insert( PROPERTY_BORDERCOLOR
);
303 aForbiddenProperties
.insert( PROPERTY_ECHO_CHAR
);
304 aForbiddenProperties
.insert( PROPERTY_FILLCOLOR
);
305 aForbiddenProperties
.insert( PROPERTY_FONT
);
306 aForbiddenProperties
.insert( PROPERTY_FONT_NAME
);
307 aForbiddenProperties
.insert( PROPERTY_FONT_STYLENAME
);
308 aForbiddenProperties
.insert( PROPERTY_FONT_FAMILY
);
309 aForbiddenProperties
.insert( PROPERTY_FONT_CHARSET
);
310 aForbiddenProperties
.insert( PROPERTY_FONT_HEIGHT
);
311 aForbiddenProperties
.insert( PROPERTY_FONT_WEIGHT
);
312 aForbiddenProperties
.insert( PROPERTY_FONT_SLANT
);
313 aForbiddenProperties
.insert( PROPERTY_FONT_UNDERLINE
);
314 aForbiddenProperties
.insert( PROPERTY_FONT_STRIKEOUT
);
315 aForbiddenProperties
.insert( PROPERTY_FONT_WORDLINEMODE
);
316 aForbiddenProperties
.insert( PROPERTY_TEXTLINECOLOR
);
317 aForbiddenProperties
.insert( PROPERTY_FONTEMPHASISMARK
);
318 aForbiddenProperties
.insert( PROPERTY_FONTRELIEF
);
319 aForbiddenProperties
.insert( PROPERTY_HARDLINEBREAKS
);
320 aForbiddenProperties
.insert( PROPERTY_HSCROLL
);
321 aForbiddenProperties
.insert( PROPERTY_LABEL
);
322 aForbiddenProperties
.insert( PROPERTY_LINECOLOR
);
323 aForbiddenProperties
.insert( PROPERTY_MULTISELECTION
);
324 aForbiddenProperties
.insert( PROPERTY_PRINTABLE
);
325 aForbiddenProperties
.insert( PROPERTY_TABINDEX
);
326 aForbiddenProperties
.insert( PROPERTY_TABSTOP
);
327 aForbiddenProperties
.insert( PROPERTY_TEXTCOLOR
);
328 aForbiddenProperties
.insert( PROPERTY_VSCROLL
);
329 aForbiddenProperties
.insert( PROPERTY_CONTROLLABEL
);
330 aForbiddenProperties
.insert( PROPERTY_RICH_TEXT
);
331 aForbiddenProperties
.insert( PROPERTY_VERTICAL_ALIGN
);
332 aForbiddenProperties
.insert( PROPERTY_IMAGE_URL
);
333 aForbiddenProperties
.insert( PROPERTY_IMAGE_POSITION
);
334 aForbiddenProperties
.insert( OUString( "EnableVisible" ) );
335 if ( !bAllowDropDown
)
336 aForbiddenProperties
.insert( PROPERTY_DROPDOWN
);
338 Sequence
< Property
> aNewProps( _rProps
.getLength() );
339 Property
* pNewProps
= aNewProps
.getArray();
341 const Property
* pProps
= _rProps
.getConstArray();
342 const Property
* pPropsEnd
= pProps
+ _rProps
.getLength();
343 for ( ; pProps
!= pPropsEnd
; ++pProps
)
345 if ( aForbiddenProperties
.find( pProps
->Name
) == aForbiddenProperties
.end() )
346 *pNewProps
++ = *pProps
;
349 aNewProps
.realloc( pNewProps
- aNewProps
.getArray() );
354 void OGridColumn::setOwnProperties(Sequence
<Property
>& aDescriptor
)
356 aDescriptor
.realloc(5);
357 Property
* pProperties
= aDescriptor
.getArray();
358 DECL_PROP1(LABEL
, OUString
, BOUND
);
359 DECL_PROP3(WIDTH
, sal_Int32
, BOUND
, MAYBEVOID
, MAYBEDEFAULT
);
360 DECL_PROP3(ALIGN
, sal_Int16
, BOUND
, MAYBEVOID
, MAYBEDEFAULT
);
361 DECL_BOOL_PROP2(HIDDEN
, BOUND
, MAYBEDEFAULT
);
362 DECL_PROP1(COLUMNSERVICENAME
, OUString
, READONLY
);
365 // Reference<XPropertySet>
367 void OGridColumn::getFastPropertyValue(Any
& rValue
, sal_Int32 nHandle
) const
371 case PROPERTY_ID_COLUMNSERVICENAME
:
372 rValue
<<= m_aModelName
;
374 case PROPERTY_ID_LABEL
:
377 case PROPERTY_ID_WIDTH
:
380 case PROPERTY_ID_ALIGN
:
383 case PROPERTY_ID_HIDDEN
:
387 OPropertySetAggregationHelper::getFastPropertyValue(rValue
, nHandle
);
392 sal_Bool
OGridColumn::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
,
393 sal_Int32 nHandle
, const Any
& rValue
)throw( IllegalArgumentException
)
395 bool bModified(false);
398 case PROPERTY_ID_LABEL
:
399 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aLabel
);
401 case PROPERTY_ID_WIDTH
:
402 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aWidth
, cppu::UnoType
<sal_Int32
>::get());
404 case PROPERTY_ID_ALIGN
:
405 bModified
= tryPropertyValue( rConvertedValue
, rOldValue
, rValue
, m_aAlign
, cppu::UnoType
<sal_Int32
>::get());
406 // strange enough, css.awt.TextAlign is a 32-bit integer, while the Align property (both here for grid controls
407 // and for ordinary toolkit controls) is a 16-bit integer. So, allow for 32 bit, but normalize it to 16 bit
410 sal_Int32
nAlign( 0 );
411 if ( rConvertedValue
>>= nAlign
)
412 rConvertedValue
<<= (sal_Int16
)nAlign
;
415 case PROPERTY_ID_HIDDEN
:
416 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getBOOL(m_aHidden
));
423 void OGridColumn::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const Any
& rValue
) throw (css::uno::Exception
, std::exception
)
427 case PROPERTY_ID_LABEL
:
428 DBG_ASSERT(rValue
.getValueType().getTypeClass() == TypeClass_STRING
, "invalid type" );
431 case PROPERTY_ID_WIDTH
:
434 case PROPERTY_ID_ALIGN
:
437 case PROPERTY_ID_HIDDEN
:
446 Any
OGridColumn::getPropertyDefaultByHandle( sal_Int32 nHandle
) const
450 case PROPERTY_ID_WIDTH
:
451 case PROPERTY_ID_ALIGN
:
453 case PROPERTY_ID_HIDDEN
:
454 return makeAny(false);
456 return OPropertySetAggregationHelper::getPropertyDefaultByHandle(nHandle
);
462 Reference
< XCloneable
> SAL_CALL
OGridColumn::createClone( ) throw (RuntimeException
, std::exception
)
464 OGridColumn
* pNewColumn
= createCloneColumn();
470 void SAL_CALL
OGridColumn::write(const Reference
<XObjectOutputStream
>& _rxOutStream
)
472 // 1. Write the UnoControl
473 Reference
<XMarkableStream
> xMark(_rxOutStream
, UNO_QUERY
);
474 sal_Int32 nMark
= xMark
->createMark();
477 _rxOutStream
->writeLong(nLen
);
479 Reference
<XPersistObject
> xPersist
;
480 if (query_aggregation(m_xAggregate
, xPersist
))
481 xPersist
->write(_rxOutStream
);
483 // Calculate the length
484 nLen
= xMark
->offsetToMark(nMark
) - 4;
485 xMark
->jumpToMark(nMark
);
486 _rxOutStream
->writeLong(nLen
);
487 xMark
->jumpToFurthest();
488 xMark
->deleteMark(nMark
);
490 // 2. Write a version number
491 _rxOutStream
->writeShort(0x0002);
493 sal_uInt16 nAnyMask
= 0;
494 if (m_aWidth
.getValueType().getTypeClass() == TypeClass_LONG
)
497 if (m_aAlign
.getValueTypeClass() == TypeClass_SHORT
)
500 nAnyMask
|= COMPATIBLE_HIDDEN
;
502 _rxOutStream
->writeShort(nAnyMask
);
504 if (nAnyMask
& WIDTH
)
505 _rxOutStream
->writeLong(getINT32(m_aWidth
));
506 if (nAnyMask
& ALIGN
)
507 _rxOutStream
->writeShort(getINT16(m_aAlign
));
510 _rxOutStream
<< m_aLabel
;
512 // the new place for the hidden flag : after m_aLabel, so older office version read the correct label, too
513 if (nAnyMask
& COMPATIBLE_HIDDEN
)
514 _rxOutStream
->writeBoolean(getBOOL(m_aHidden
));
518 void SAL_CALL
OGridColumn::read(const Reference
<XObjectInputStream
>& _rxInStream
)
520 // 1. Read the UnoControl
521 sal_Int32 nLen
= _rxInStream
->readLong();
524 Reference
<XMarkableStream
> xMark(_rxInStream
, UNO_QUERY
);
525 sal_Int32 nMark
= xMark
->createMark();
526 Reference
<XPersistObject
> xPersist
;
527 if (query_aggregation(m_xAggregate
, xPersist
))
528 xPersist
->read(_rxInStream
);
530 xMark
->jumpToMark(nMark
);
531 _rxInStream
->skipBytes(nLen
);
532 xMark
->deleteMark(nMark
);
535 // 2. Write a version number
536 sal_uInt16 nVersion
= _rxInStream
->readShort(); (void)nVersion
;
537 sal_uInt16 nAnyMask
= _rxInStream
->readShort();
539 if (nAnyMask
& WIDTH
)
541 sal_Int32 nValue
= _rxInStream
->readLong();
542 m_aWidth
<<= (sal_Int32
)nValue
;
545 if (nAnyMask
& ALIGN
)
547 sal_Int16 nValue
= _rxInStream
->readShort();
550 if (nAnyMask
& OLD_HIDDEN
)
552 bool bValue
= _rxInStream
->readBoolean();
553 m_aHidden
<<= bValue
;
557 _rxInStream
>> m_aLabel
;
559 if (nAnyMask
& COMPATIBLE_HIDDEN
)
561 bool bValue
= _rxInStream
->readBoolean();
562 m_aHidden
<<= bValue
;
567 IMPL_COLUMN(TextFieldColumn
, FRM_SUN_COMPONENT_TEXTFIELD
, false);
568 IMPL_COLUMN(PatternFieldColumn
, FRM_SUN_COMPONENT_PATTERNFIELD
, false);
569 IMPL_COLUMN(DateFieldColumn
, FRM_SUN_COMPONENT_DATEFIELD
, true);
570 IMPL_COLUMN(TimeFieldColumn
, FRM_SUN_COMPONENT_TIMEFIELD
, false);
571 IMPL_COLUMN(NumericFieldColumn
, FRM_SUN_COMPONENT_NUMERICFIELD
, false);
572 IMPL_COLUMN(CurrencyFieldColumn
, FRM_SUN_COMPONENT_CURRENCYFIELD
, false);
573 IMPL_COLUMN(CheckBoxColumn
, FRM_SUN_COMPONENT_CHECKBOX
, false);
574 IMPL_COLUMN(ComboBoxColumn
, FRM_SUN_COMPONENT_COMBOBOX
, false);
575 IMPL_COLUMN(ListBoxColumn
, FRM_SUN_COMPONENT_LISTBOX
, false);
576 IMPL_COLUMN(FormattedFieldColumn
, FRM_SUN_COMPONENT_FORMATTEDFIELD
, false);
582 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */