update dev300-m58
[ooovba.git] / forms / source / component / Pattern.cxx
blobf7cf04ac3f8132f6cb0b9dd299b00cc638aba1ce
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: Pattern.cxx,v $
10 * $Revision: 1.18 $
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 "Pattern.hxx"
36 /** === begin UNO includes === **/
37 /** === end UNO includes === **/
39 //.........................................................................
40 namespace frm
42 //.........................................................................
44 /** === begin UNO using === **/
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::lang::XMultiServiceFactory;
47 using ::com::sun::star::uno::Sequence;
48 using ::com::sun::star::uno::Type;
49 using ::com::sun::star::beans::Property;
50 using ::com::sun::star::uno::Exception;
51 using ::com::sun::star::uno::XInterface;
52 using ::com::sun::star::uno::Any;
53 using ::com::sun::star::uno::makeAny;
54 using ::com::sun::star::sdbc::XRowSet;
55 using ::com::sun::star::uno::UNO_QUERY;
56 /** === end UNO using === **/
57 namespace FormComponentType = ::com::sun::star::form::FormComponentType;
59 //==================================================================
60 // OPatternControl
61 //==================================================================
62 //------------------------------------------------------------------
63 OPatternControl::OPatternControl(const Reference<XMultiServiceFactory>& _rxFactory)
64 :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD)
68 //------------------------------------------------------------------
69 InterfaceRef SAL_CALL OPatternControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
71 return *(new OPatternControl(_rxFactory));
74 //------------------------------------------------------------------------------
75 Sequence<Type> OPatternControl::_getTypes()
77 return OBoundControl::_getTypes();
80 //------------------------------------------------------------------------------
81 StringSequence OPatternControl::getSupportedServiceNames() throw()
83 StringSequence aSupported = OBoundControl::getSupportedServiceNames();
84 aSupported.realloc(aSupported.getLength() + 1);
86 ::rtl::OUString*pArray = aSupported.getArray();
87 pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_PATTERNFIELD;
88 return aSupported;
91 //==================================================================
92 // OPatternModel
93 //==================================================================
94 //------------------------------------------------------------------
95 InterfaceRef SAL_CALL OPatternModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
97 return *(new OPatternModel(_rxFactory));
100 //------------------------------------------------------------------------------
101 Sequence<Type> OPatternModel::_getTypes()
103 return OEditBaseModel::_getTypes();
106 //------------------------------------------------------------------
107 DBG_NAME( OPatternModel )
108 //------------------------------------------------------------------
109 OPatternModel::OPatternModel(const Reference<XMultiServiceFactory>& _rxFactory)
110 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, sal_False, sal_False )
111 // use the old control name for compytibility reasons
113 DBG_CTOR( OPatternModel, NULL );
115 m_nClassId = FormComponentType::PATTERNFIELD;
116 initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
119 //------------------------------------------------------------------
120 OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
121 :OEditBaseModel( _pOriginal, _rxFactory )
123 DBG_CTOR( OPatternModel, NULL );
126 //------------------------------------------------------------------
127 OPatternModel::~OPatternModel()
129 DBG_DTOR( OPatternModel, NULL );
132 // XCloneable
133 //------------------------------------------------------------------------------
134 IMPLEMENT_DEFAULT_CLONING( OPatternModel )
136 // XServiceInfo
137 //------------------------------------------------------------------------------
138 StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw()
140 StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
141 aSupported.realloc(aSupported.getLength() + 2);
143 ::rtl::OUString*pArray = aSupported.getArray();
144 pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD;
145 pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_PATTERNFIELD;
146 return aSupported;
150 //------------------------------------------------------------------------------
151 void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
153 BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
154 DECL_PROP2(DEFAULT_TEXT, ::rtl::OUString, BOUND, MAYBEDEFAULT);
155 DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND);
156 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
157 DECL_PROP2(FILTERPROPOSAL, sal_Bool, BOUND, MAYBEDEFAULT);
158 END_DESCRIBE_PROPERTIES();
161 //------------------------------------------------------------------------------
162 ::rtl::OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
164 return FRM_COMPONENT_PATTERNFIELD; // old (non-sun) name for compatibility !
167 //------------------------------------------------------------------------------
168 sal_Bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
170 Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
172 if ( aNewValue != m_aLastKnownValue )
174 ::rtl::OUString sNewValue;
175 aNewValue >>= sNewValue;
177 if ( !aNewValue.hasValue()
178 || ( !sNewValue.getLength() // an empty string
179 && m_bEmptyIsNull // which should be interpreted as NULL
183 m_xColumnUpdate->updateNull();
185 else
187 OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" );
188 if ( !m_pFormattedValue.get() )
189 return sal_False;
191 if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
192 return sal_False;
195 m_aLastKnownValue = aNewValue;
198 return sal_True;
201 //------------------------------------------------------------------------------
202 void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
204 OEditBaseModel::onConnectedDbColumn( _rxForm );
206 Reference< XPropertySet > xField( getField() );
207 if ( !xField.is() )
208 return;
210 m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
213 //------------------------------------------------------------------------------
214 void OPatternModel::onDisconnectedDbColumn()
216 OEditBaseModel::onDisconnectedDbColumn();
217 m_pFormattedValue.reset();
220 // XPropertyChangeListener
221 //------------------------------------------------------------------------------
222 Any OPatternModel::translateDbColumnToControlValue()
224 OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" );
226 if ( m_pFormattedValue.get() )
228 ::rtl::OUString sValue( m_pFormattedValue->getFormattedValue() );
229 if ( !sValue.getLength()
230 && m_pFormattedValue->getColumn().is()
231 && m_pFormattedValue->getColumn()->wasNull()
234 m_aLastKnownValue.clear();
236 else
238 m_aLastKnownValue <<= sValue;
241 else
242 m_aLastKnownValue.clear();
244 return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( ::rtl::OUString() );
245 // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
248 // XReset
249 //------------------------------------------------------------------------------
250 Any OPatternModel::getDefaultForReset() const
252 return makeAny( m_aDefaultText );
255 //.........................................................................
256 } // namespace frm
257 //.........................................................................