1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26
27
28 #include "File.hxx"
29
30 #include <com/sun/star/form/FormComponentType.hpp>
31
32 #ifndef _FRM_PROPERTY_HRC_
33 #include "property.hrc"
34 #endif
35 #include "services.hxx"
36 #include <tools/debug.hxx>
37 #include <comphelper/container.hxx>
38 #include <comphelper/basicio.hxx>
39 #include <comphelper/guarding.hxx>
40
41 //.........................................................................
42 namespace frm
43 {
44 //.........................................................................
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::sdb;
47 using namespace ::com::sun::star::sdbc;
48 using namespace ::com::sun::star::sdbcx;
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
57 //------------------------------------------------------------------
OFileControlModel_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)58 InterfaceRef SAL_CALL OFileControlModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
59 {
60 return *(new OFileControlModel(_rxFactory));
61 }
62
63 //------------------------------------------------------------------------------
_getTypes()64 Sequence<Type> OFileControlModel::_getTypes()
65 {
66 static Sequence<Type> aTypes;
67 if (!aTypes.getLength())
68 {
69 // my base class
70 Sequence<Type> aBaseClassTypes = OControlModel::_getTypes();
71
72 Sequence<Type> aOwnTypes(1);
73 Type* pOwnTypes = aOwnTypes.getArray();
74 pOwnTypes[0] = getCppuType((Reference<XReset>*)NULL);
75
76 aTypes = concatSequences(aBaseClassTypes, aOwnTypes);
77 }
78 return aTypes;
79 }
80
81
82 // XServiceInfo
83 //------------------------------------------------------------------------------
getSupportedServiceNames()84 StringSequence OFileControlModel::getSupportedServiceNames()
85 {
86 StringSequence aSupported = OControlModel::getSupportedServiceNames();
87 aSupported.realloc(aSupported.getLength() + 1);
88
89 ::rtl::OUString*pArray = aSupported.getArray();
90 pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_FILECONTROL;
91 return aSupported;
92 }
93
94 //------------------------------------------------------------------
DBG_NAME(OFileControlModel)95 DBG_NAME( OFileControlModel )
96 //------------------------------------------------------------------
97 OFileControlModel::OFileControlModel(const Reference<XMultiServiceFactory>& _rxFactory)
98 :OControlModel(_rxFactory, VCL_CONTROLMODEL_FILECONTROL)
99 ,m_aResetListeners(m_aMutex)
100 {
101 DBG_CTOR( OFileControlModel, NULL );
102 m_nClassId = FormComponentType::FILECONTROL;
103 }
104
105 //------------------------------------------------------------------
OFileControlModel(const OFileControlModel * _pOriginal,const Reference<XMultiServiceFactory> & _rxFactory)106 OFileControlModel::OFileControlModel( const OFileControlModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
107 :OControlModel( _pOriginal, _rxFactory )
108 ,m_aResetListeners( m_aMutex )
109 {
110 DBG_CTOR( OFileControlModel, NULL );
111
112 m_sDefaultValue = _pOriginal->m_sDefaultValue;
113 }
114
115 //------------------------------------------------------------------
~OFileControlModel()116 OFileControlModel::~OFileControlModel()
117 {
118 if (!OComponentHelper::rBHelper.bDisposed)
119 {
120 acquire();
121 dispose();
122 }
123 DBG_DTOR( OFileControlModel, NULL );
124 }
125
126 //------------------------------------------------------------------------------
IMPLEMENT_DEFAULT_CLONING(OFileControlModel)127 IMPLEMENT_DEFAULT_CLONING( OFileControlModel )
128
129 //------------------------------------------------------------------------------
130 Any SAL_CALL OFileControlModel::queryAggregation(const Type& _rType)
131 {
132 Any aReturn = OControlModel::queryAggregation(_rType);
133 if (!aReturn.hasValue())
134 aReturn = ::cppu::queryInterface(_rType
135 ,static_cast<XReset*>(this)
136 );
137
138 return aReturn;
139 }
140
141 // OComponentHelper
142 //-----------------------------------------------------------------------------
disposing()143 void OFileControlModel::disposing()
144 {
145 OControlModel::disposing();
146
147 EventObject aEvt(static_cast<XWeak*>(this));
148 m_aResetListeners.disposeAndClear(aEvt);
149 }
150
151 //------------------------------------------------------------------------------
getPropertyDefaultByHandle(sal_Int32 _nHandle) const152 Any OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
153 {
154 Any aReturn;
155 switch ( _nHandle )
156 {
157 case PROPERTY_ID_DEFAULT_TEXT:
158 return makeAny( ::rtl::OUString() );
159 }
160 return OControlModel::getPropertyDefaultByHandle( _nHandle );
161 }
162
163 //------------------------------------------------------------------------------
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const164 void OFileControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
165 {
166 switch (nHandle)
167 {
168 case PROPERTY_ID_DEFAULT_TEXT : rValue <<= m_sDefaultValue; break;
169 default:
170 OControlModel::getFastPropertyValue(rValue, nHandle);
171 }
172 }
173
174 //------------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)175 void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue)
176 {
177 switch (nHandle)
178 {
179 case PROPERTY_ID_DEFAULT_TEXT :
180 DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
181 rValue >>= m_sDefaultValue;
182 break;
183 default:
184 OControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue);
185 }
186 }
187
188 //------------------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)189 sal_Bool OFileControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
190 {
191 switch (nHandle)
192 {
193 case PROPERTY_ID_DEFAULT_TEXT :
194 return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sDefaultValue);
195 default:
196 return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
197 }
198 }
199
200 //------------------------------------------------------------------------------
describeFixedProperties(Sequence<Property> & _rProps) const201 void OFileControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
202 {
203 BEGIN_DESCRIBE_PROPERTIES( 2, OControlModel )
204 DECL_PROP1(DEFAULT_TEXT, ::rtl::OUString, BOUND);
205 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
206 END_DESCRIBE_PROPERTIES();
207 }
208
209 //------------------------------------------------------------------------------
getServiceName()210 ::rtl::OUString SAL_CALL OFileControlModel::getServiceName()
211 {
212 return FRM_COMPONENT_FILECONTROL; // old (non-sun) name for compatibility !
213 }
214
215 //------------------------------------------------------------------------------
write(const Reference<stario::XObjectOutputStream> & _rxOutStream)216 void OFileControlModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream)
217 {
218 OControlModel::write(_rxOutStream);
219
220 ::osl::MutexGuard aGuard(m_aMutex);
221
222 // Version
223 _rxOutStream->writeShort(0x0002);
224 // Default-Wert
225 _rxOutStream << m_sDefaultValue;
226 writeHelpTextCompatibly(_rxOutStream);
227 }
228
229 //------------------------------------------------------------------------------
read(const Reference<stario::XObjectInputStream> & _rxInStream)230 void OFileControlModel::read(const Reference<stario::XObjectInputStream>& _rxInStream)
231 {
232 OControlModel::read(_rxInStream);
233 ::osl::MutexGuard aGuard(m_aMutex);
234
235 // Version
236 sal_uInt16 nVersion = _rxInStream->readShort();
237 // Default-Wert
238 switch (nVersion)
239 {
240 case 1:
241 _rxInStream >> m_sDefaultValue; break;
242 case 2:
243 _rxInStream >> m_sDefaultValue;
244 readHelpTextCompatibly(_rxInStream);
245 break;
246 default:
247 DBG_ERROR("OFileControlModel::read : unknown version !");
248 m_sDefaultValue = ::rtl::OUString();
249 }
250
251 // Nach dem Lesen die Defaultwerte anzeigen
252 // _reset();
253 }
254
255 //-----------------------------------------------------------------------------
reset()256 void SAL_CALL OFileControlModel::reset()
257 {
258 ::cppu::OInterfaceIteratorHelper aIter(m_aResetListeners);
259 EventObject aEvt(static_cast<XWeak*>(this));
260 sal_Bool bContinue = sal_True;
261 while (aIter.hasMoreElements() && bContinue)
262 bContinue =((XResetListener*)aIter.next())->approveReset(aEvt);
263
264 if (bContinue)
265 {
266 {
267 // Wenn Models threadSave
268 ::osl::MutexGuard aGuard(m_aMutex);
269 _reset();
270 }
271 m_aResetListeners.notifyEach( &XResetListener::resetted, aEvt );
272 }
273 }
274
275 //-----------------------------------------------------------------------------
addResetListener(const Reference<XResetListener> & _rxListener)276 void OFileControlModel::addResetListener(const Reference<XResetListener>& _rxListener)
277 {
278 m_aResetListeners.addInterface(_rxListener);
279 }
280
281 //-----------------------------------------------------------------------------
removeResetListener(const Reference<XResetListener> & _rxListener)282 void OFileControlModel::removeResetListener(const Reference<XResetListener>& _rxListener)
283 {
284 m_aResetListeners.removeInterface(_rxListener);
285 }
286
287 //------------------------------------------------------------------------------
_reset()288 void OFileControlModel::_reset()
289 {
290 { // release our mutex once (it's acquired in the calling method !), as setting aggregate properties
291 // may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
292 // our own mutex locked
293 // FS - 72451 - 31.01.00
294 MutexRelease aRelease(m_aMutex);
295 m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(m_sDefaultValue));
296 }
297 }
298
299 //.........................................................................
300 } // namespace frm
301 //.........................................................................
302