bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / component / Pattern.cxx
blob67335d0905e3460682592ec517cd22daad0e5fa1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "Pattern.hxx"
22 //.........................................................................
23 namespace frm
25 //.........................................................................
27 using ::com::sun::star::uno::Reference;
28 using ::com::sun::star::lang::XMultiServiceFactory;
29 using ::com::sun::star::uno::Sequence;
30 using ::com::sun::star::uno::Type;
31 using ::com::sun::star::beans::Property;
32 using ::com::sun::star::uno::Exception;
33 using ::com::sun::star::uno::XInterface;
34 using ::com::sun::star::uno::Any;
35 using ::com::sun::star::uno::makeAny;
36 using ::com::sun::star::sdbc::XRowSet;
37 using ::com::sun::star::uno::UNO_QUERY;
39 namespace FormComponentType = ::com::sun::star::form::FormComponentType;
41 //==================================================================
42 // OPatternControl
43 //==================================================================
44 //------------------------------------------------------------------
45 OPatternControl::OPatternControl(const Reference<XMultiServiceFactory>& _rxFactory)
46 :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD)
50 //------------------------------------------------------------------
51 InterfaceRef SAL_CALL OPatternControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
53 return *(new OPatternControl(_rxFactory));
56 //------------------------------------------------------------------------------
57 Sequence<Type> OPatternControl::_getTypes()
59 return OBoundControl::_getTypes();
62 //------------------------------------------------------------------------------
63 StringSequence OPatternControl::getSupportedServiceNames() throw()
65 StringSequence aSupported = OBoundControl::getSupportedServiceNames();
66 aSupported.realloc(aSupported.getLength() + 1);
68 OUString*pArray = aSupported.getArray();
69 pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_PATTERNFIELD;
70 return aSupported;
73 //==================================================================
74 // OPatternModel
75 //==================================================================
76 //------------------------------------------------------------------
77 InterfaceRef SAL_CALL OPatternModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
79 return *(new OPatternModel(_rxFactory));
82 //------------------------------------------------------------------------------
83 Sequence<Type> OPatternModel::_getTypes()
85 return OEditBaseModel::_getTypes();
88 //------------------------------------------------------------------
89 DBG_NAME( OPatternModel )
90 //------------------------------------------------------------------
91 OPatternModel::OPatternModel(const Reference<XMultiServiceFactory>& _rxFactory)
92 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, sal_False, sal_False )
93 // use the old control name for compytibility reasons
95 DBG_CTOR( OPatternModel, NULL );
97 m_nClassId = FormComponentType::PATTERNFIELD;
98 initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
101 //------------------------------------------------------------------
102 OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
103 :OEditBaseModel( _pOriginal, _rxFactory )
105 DBG_CTOR( OPatternModel, NULL );
108 //------------------------------------------------------------------
109 OPatternModel::~OPatternModel()
111 DBG_DTOR( OPatternModel, NULL );
114 // XCloneable
115 //------------------------------------------------------------------------------
116 IMPLEMENT_DEFAULT_CLONING( OPatternModel )
118 // XServiceInfo
119 //------------------------------------------------------------------------------
120 StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw()
122 StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
123 aSupported.realloc(aSupported.getLength() + 2);
125 OUString*pArray = aSupported.getArray();
126 pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD;
127 pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_PATTERNFIELD;
128 return aSupported;
132 //------------------------------------------------------------------------------
133 void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
135 BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
136 DECL_PROP2(DEFAULT_TEXT, OUString, BOUND, MAYBEDEFAULT);
137 DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND);
138 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
139 DECL_PROP2(FILTERPROPOSAL, sal_Bool, BOUND, MAYBEDEFAULT);
140 END_DESCRIBE_PROPERTIES();
143 //------------------------------------------------------------------------------
144 OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
146 return OUString(FRM_COMPONENT_PATTERNFIELD); // old (non-sun) name for compatibility !
149 //------------------------------------------------------------------------------
150 sal_Bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
152 Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
154 if ( aNewValue != m_aLastKnownValue )
156 OUString sNewValue;
157 aNewValue >>= sNewValue;
159 if ( !aNewValue.hasValue()
160 || ( sNewValue.isEmpty() // an empty string
161 && m_bEmptyIsNull // which should be interpreted as NULL
165 m_xColumnUpdate->updateNull();
167 else
169 OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" );
170 if ( !m_pFormattedValue.get() )
171 return sal_False;
173 if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
174 return sal_False;
177 m_aLastKnownValue = aNewValue;
180 return sal_True;
183 //------------------------------------------------------------------------------
184 void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
186 OEditBaseModel::onConnectedDbColumn( _rxForm );
188 Reference< XPropertySet > xField( getField() );
189 if ( !xField.is() )
190 return;
192 m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
195 //------------------------------------------------------------------------------
196 void OPatternModel::onDisconnectedDbColumn()
198 OEditBaseModel::onDisconnectedDbColumn();
199 m_pFormattedValue.reset();
202 // XPropertyChangeListener
203 //------------------------------------------------------------------------------
204 Any OPatternModel::translateDbColumnToControlValue()
206 OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" );
208 if ( m_pFormattedValue.get() )
210 OUString sValue( m_pFormattedValue->getFormattedValue() );
211 if ( sValue.isEmpty()
212 && m_pFormattedValue->getColumn().is()
213 && m_pFormattedValue->getColumn()->wasNull()
216 m_aLastKnownValue.clear();
218 else
220 m_aLastKnownValue <<= sValue;
223 else
224 m_aLastKnownValue.clear();
226 return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( OUString() );
227 // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
230 // XReset
231 //------------------------------------------------------------------------------
232 Any OPatternModel::getDefaultForReset() const
234 return makeAny( m_aDefaultText );
237 //------------------------------------------------------------------------------
238 void OPatternModel::resetNoBroadcast()
240 OEditBaseModel::resetNoBroadcast();
241 m_aLastKnownValue.clear();
244 //.........................................................................
245 } // namespace frm
246 //.........................................................................
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */