1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EditBase.cxx,v $
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"
33 #include "EditBase.hxx"
34 #include "property.hxx"
35 #ifndef _FRM_PROPERTY_HRC_
36 #include "property.hrc"
38 #include "services.hxx"
39 #include <tools/debug.hxx>
40 #include <comphelper/basicio.hxx>
41 #include <cppuhelper/queryinterface.hxx>
42 #include "frm_resource.hxx"
43 #ifndef _FRM_RESOURCE_HRC_
44 #include "frm_resource.hrc"
47 //.........................................................................
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::sdb
;
52 using namespace ::com::sun::star::sdbc
;
53 using namespace ::com::sun::star::sdbcx
;
54 using namespace ::com::sun::star::beans
;
55 using namespace ::com::sun::star::container
;
56 using namespace ::com::sun::star::form
;
57 using namespace ::com::sun::star::awt
;
58 using namespace ::com::sun::star::io
;
59 using namespace ::com::sun::star::lang
;
60 using namespace ::com::sun::star::util
;
62 const sal_uInt16 DEFAULT_LONG
= 0x0001;
63 const sal_uInt16 DEFAULT_DOUBLE
= 0x0002;
64 const sal_uInt16 FILTERPROPOSAL
= 0x0004;
66 DBG_NAME( OEditBaseModel
)
67 //------------------------------------------------------------------
68 OEditBaseModel::OEditBaseModel( const Reference
< XMultiServiceFactory
>& _rxFactory
, const ::rtl::OUString
& rUnoControlModelName
,
69 const ::rtl::OUString
& rDefault
, const sal_Bool _bSupportExternalBinding
, const sal_Bool _bSupportsValidation
)
70 :OBoundControlModel( _rxFactory
, rUnoControlModelName
, rDefault
, sal_True
, _bSupportExternalBinding
, _bSupportsValidation
)
71 ,m_nLastReadVersion(0)
72 ,m_bEmptyIsNull(sal_True
)
73 ,m_bFilterProposal(sal_False
)
75 DBG_CTOR( OEditBaseModel
, NULL
);
78 //------------------------------------------------------------------
79 OEditBaseModel::OEditBaseModel( const OEditBaseModel
* _pOriginal
, const Reference
< XMultiServiceFactory
>& _rxFactory
)
80 :OBoundControlModel( _pOriginal
, _rxFactory
)
81 ,m_nLastReadVersion(0)
83 DBG_CTOR( OEditBaseModel
, NULL
);
85 m_bFilterProposal
= _pOriginal
->m_bFilterProposal
;
86 m_bEmptyIsNull
= _pOriginal
->m_bEmptyIsNull
;
87 m_aDefault
= _pOriginal
->m_aDefault
;
88 m_aDefaultText
= _pOriginal
->m_aDefaultText
;
91 //------------------------------------------------------------------
92 OEditBaseModel::~OEditBaseModel( )
94 DBG_DTOR( OEditBaseModel
, NULL
);
98 //------------------------------------------------------------------------------
99 void OEditBaseModel::write(const Reference
<XObjectOutputStream
>& _rxOutStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
101 OBoundControlModel::write(_rxOutStream
);
104 sal_uInt16 nVersionId
= 0x0005;
105 DBG_ASSERT((getPersistenceFlags() & ~PF_SPECIAL_FLAGS
) == 0,
106 "OEditBaseModel::write : invalid special version flags !");
107 // please don't use other flags, older versions can't interpret them !
109 nVersionId
|= getPersistenceFlags();
110 _rxOutStream
->writeShort(nVersionId
);
113 _rxOutStream
->writeShort(0); // obsolete
114 _rxOutStream
<< m_aDefaultText
;
116 // Maskierung fuer any
117 sal_uInt16 nAnyMask
= 0;
118 if (m_aDefault
.getValueType().getTypeClass() == TypeClass_LONG
)
119 nAnyMask
|= DEFAULT_LONG
;
120 else if (m_aDefault
.getValueType().getTypeClass() == TypeClass_DOUBLE
)
121 nAnyMask
|= DEFAULT_DOUBLE
;
123 if (m_bFilterProposal
) // da boolean, kein Wert speichern
124 nAnyMask
|= FILTERPROPOSAL
;
126 _rxOutStream
->writeBoolean(m_bEmptyIsNull
);
127 _rxOutStream
->writeShort(nAnyMask
);
129 if ((nAnyMask
& DEFAULT_LONG
) == DEFAULT_LONG
)
130 _rxOutStream
->writeLong(getINT32(m_aDefault
));
131 else if ((nAnyMask
& DEFAULT_DOUBLE
) == DEFAULT_DOUBLE
)
132 _rxOutStream
->writeDouble(getDouble(m_aDefault
));
134 // since version 5 we write the help text
135 writeHelpTextCompatibly(_rxOutStream
);
136 // (that's potentially bad : at the time I added the above line we had two derived classes : OEditModel and
137 // OFormattedModel. The first one does not have an own version handling, so it can't write the help text itself,
138 // the second one does it's own writing (reading) after calling our method, so normally we shouldn't write any
139 // additional members as this is not compatible to older office versions.
140 // We decided to place the writing of the help text here as it seems the less worse alternative. There is no delivered
141 // office version including formatted controls (and thus the OFormattedModel), and the OFormattedModel::read seems
142 // robust against this change (as it will read a wrong and unknown file version and thus set it's members to defaults).
144 if ((nVersionId
& PF_HANDLE_COMMON_PROPS
) != 0)
145 writeCommonEditProperties(_rxOutStream
);
147 // !!! properties common to all OEditBaseModel derived classes should be written in writeCommonEditProperties !!!
150 //------------------------------------------------------------------------------
151 sal_uInt16
OEditBaseModel::getPersistenceFlags() const
153 return PF_HANDLE_COMMON_PROPS
;
156 //------------------------------------------------------------------------------
157 void OEditBaseModel::read(const Reference
<XObjectInputStream
>& _rxInStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
159 OBoundControlModel::read(_rxInStream
);
160 ::osl::MutexGuard
aGuard(m_aMutex
);
162 // Version eigene Versionsnummer
163 sal_uInt16 nVersion
= _rxInStream
->readShort();
164 m_nLastReadVersion
= nVersion
;
166 sal_Bool bHandleCommonProps
= (nVersion
& PF_HANDLE_COMMON_PROPS
) != 0;
167 nVersion
= nVersion
& ~PF_SPECIAL_FLAGS
;
170 _rxInStream
->readShort();
172 _rxInStream
>> m_aDefaultText
;
174 if (nVersion
>= 0x0003)
176 m_bEmptyIsNull
= _rxInStream
->readBoolean();
178 sal_uInt16 nAnyMask
= _rxInStream
->readShort();
179 if ((nAnyMask
& DEFAULT_LONG
) == DEFAULT_LONG
)
181 sal_Int32 nValue
= _rxInStream
->readLong();
182 m_aDefault
<<= (sal_Int32
)nValue
;
184 else if ((nAnyMask
& DEFAULT_DOUBLE
) == DEFAULT_DOUBLE
)
186 double fValue
= _rxInStream
->readDouble();
187 m_aDefault
<<= (double)fValue
;
190 if ((nAnyMask
& FILTERPROPOSAL
) == FILTERPROPOSAL
)
191 m_bFilterProposal
= sal_True
;
195 readHelpTextCompatibly(_rxInStream
);
197 if (bHandleCommonProps
)
198 readCommonEditProperties(_rxInStream
);
200 // Nach dem Lesen die Defaultwerte anzeigen
201 if ( getControlSource().getLength() )
202 // (not if we don't have a control source - the "State" property acts like it is persistent, then)
206 //------------------------------------------------------------------------------
207 void OEditBaseModel::defaultCommonEditProperties()
209 OBoundControlModel::defaultCommonProperties();
210 // no own common properties at the moment
213 //------------------------------------------------------------------------------
214 void OEditBaseModel::readCommonEditProperties(const Reference
<XObjectInputStream
>& _rxInStream
)
216 sal_Int32 nLen
= _rxInStream
->readLong();
218 Reference
<XMarkableStream
> xMark(_rxInStream
, UNO_QUERY
);
219 DBG_ASSERT(xMark
.is(), "OBoundControlModel::readCommonProperties : can only work with markable streams !");
220 sal_Int32 nMark
= xMark
->createMark();
222 // read properties common to all OBoundControlModels
223 OBoundControlModel::readCommonProperties(_rxInStream
);
225 // read properties common to all OEditBaseModels
227 // skip the remaining bytes
228 xMark
->jumpToMark(nMark
);
229 _rxInStream
->skipBytes(nLen
);
230 xMark
->deleteMark(nMark
);
233 //------------------------------------------------------------------------------
234 void OEditBaseModel::writeCommonEditProperties(const Reference
<XObjectOutputStream
>& _rxOutStream
)
236 Reference
<XMarkableStream
> xMark(_rxOutStream
, UNO_QUERY
);
237 DBG_ASSERT(xMark
.is(), "OEditBaseModel::writeCommonProperties : can only work with markable streams !");
238 sal_Int32 nMark
= xMark
->createMark();
240 // a placeholder where we will write the overall length (later in this method)
242 _rxOutStream
->writeLong(nLen
);
244 // write properties common to all OBoundControlModels
245 OBoundControlModel::writeCommonProperties(_rxOutStream
);
247 // write properties common to all OEditBaseModels
249 // close the block - write the correct length at the beginning
250 nLen
= xMark
->offsetToMark(nMark
) - sizeof(nLen
);
251 xMark
->jumpToMark(nMark
);
252 _rxOutStream
->writeLong(nLen
);
253 xMark
->jumpToFurthest();
254 xMark
->deleteMark(nMark
);
257 //------------------------------------------------------------------------------
258 void OEditBaseModel::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
262 case PROPERTY_ID_EMPTY_IS_NULL
:
263 rValue
<<= (sal_Bool
)m_bEmptyIsNull
;
265 case PROPERTY_ID_FILTERPROPOSAL
:
266 rValue
<<= (sal_Bool
)m_bFilterProposal
;
268 case PROPERTY_ID_DEFAULT_TEXT
:
269 rValue
<<= m_aDefaultText
;
271 case PROPERTY_ID_DEFAULT_VALUE
:
272 case PROPERTY_ID_DEFAULT_DATE
:
273 case PROPERTY_ID_DEFAULT_TIME
:
277 OBoundControlModel::getFastPropertyValue(rValue
, nHandle
);
281 //------------------------------------------------------------------------------
282 sal_Bool
OEditBaseModel::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
,
283 sal_Int32 nHandle
, const Any
& rValue
) throw( IllegalArgumentException
)
285 sal_Bool
bModified(sal_False
);
288 case PROPERTY_ID_EMPTY_IS_NULL
:
289 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bEmptyIsNull
);
291 case PROPERTY_ID_FILTERPROPOSAL
:
292 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_bFilterProposal
);
294 case PROPERTY_ID_DEFAULT_TEXT
:
295 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aDefaultText
);
297 case PROPERTY_ID_DEFAULT_VALUE
:
298 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aDefault
, ::getCppuType((const double*)0));
300 case PROPERTY_ID_DEFAULT_DATE
:
301 case PROPERTY_ID_DEFAULT_TIME
:
302 bModified
= tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_aDefault
, ::getCppuType((const sal_Int32
*)0));
305 bModified
= OBoundControlModel::convertFastPropertyValue(
314 //------------------------------------------------------------------------------
315 void OEditBaseModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const Any
& rValue
) throw ( ::com::sun::star::uno::Exception
)
319 case PROPERTY_ID_EMPTY_IS_NULL
:
320 DBG_ASSERT(rValue
.getValueType().getTypeClass() == TypeClass_BOOLEAN
, "invalid type" );
321 m_bEmptyIsNull
= getBOOL(rValue
);
323 case PROPERTY_ID_FILTERPROPOSAL
:
324 DBG_ASSERT(rValue
.getValueType().getTypeClass() == TypeClass_BOOLEAN
, "invalid type" );
325 m_bFilterProposal
= getBOOL(rValue
);
327 // Aenderung der defaultwerte fuehrt zu reset
328 case PROPERTY_ID_DEFAULT_TEXT
:
329 DBG_ASSERT(rValue
.getValueType().getTypeClass() == TypeClass_STRING
, "invalid type" );
330 rValue
>>= m_aDefaultText
;
333 case PROPERTY_ID_DEFAULT_VALUE
:
334 case PROPERTY_ID_DEFAULT_DATE
:
335 case PROPERTY_ID_DEFAULT_TIME
:
340 OBoundControlModel::setFastPropertyValue_NoBroadcast(nHandle
, rValue
);
345 //------------------------------------------------------------------------------
346 Any
OEditBaseModel::getPropertyDefaultByHandle( sal_Int32 nHandle
) const
350 case PROPERTY_ID_DEFAULT_TEXT
:
351 return makeAny(::rtl::OUString());
352 case PROPERTY_ID_FILTERPROPOSAL
:
353 return Any(makeAny((sal_Bool
)sal_False
));
354 case PROPERTY_ID_DEFAULT_VALUE
:
355 case PROPERTY_ID_DEFAULT_DATE
:
356 case PROPERTY_ID_DEFAULT_TIME
:
359 return OBoundControlModel::getPropertyDefaultByHandle(nHandle
);
363 //.........................................................................
365 //.........................................................................