bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / component / Pattern.cxx
blob8631f0deec9a0147fe703659bb27e13953768351
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"
21 #include "comphelper/processfactory.hxx"
23 using ::com::sun::star::uno::Reference;
24 using ::com::sun::star::lang::XMultiServiceFactory;
25 using ::com::sun::star::uno::Sequence;
26 using ::com::sun::star::uno::Type;
27 using ::com::sun::star::uno::XComponentContext;
28 using ::com::sun::star::beans::Property;
29 using ::com::sun::star::uno::Exception;
30 using ::com::sun::star::uno::XInterface;
31 using ::com::sun::star::uno::Any;
32 using ::com::sun::star::uno::makeAny;
33 using ::com::sun::star::sdbc::XRowSet;
34 using ::com::sun::star::uno::UNO_QUERY;
36 namespace FormComponentType = ::com::sun::star::form::FormComponentType;
38 namespace frm
41 OPatternControl::OPatternControl(const Reference<XComponentContext>& _rxFactory)
42 :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD)
47 Sequence<Type> OPatternControl::_getTypes()
49 return OBoundControl::_getTypes();
53 StringSequence OPatternControl::getSupportedServiceNames() throw(std::exception)
55 StringSequence aSupported = OBoundControl::getSupportedServiceNames();
56 aSupported.realloc(aSupported.getLength() + 2);
58 OUString*pArray = aSupported.getArray();
59 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_PATTERNFIELD;
60 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_PATTERNFIELD;
61 return aSupported;
65 // OPatternModel
68 Sequence<Type> OPatternModel::_getTypes()
70 return OEditBaseModel::_getTypes();
75 OPatternModel::OPatternModel(const Reference<XComponentContext>& _rxFactory)
76 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, false, false )
77 // use the old control name for compytibility reasons
80 m_nClassId = FormComponentType::PATTERNFIELD;
81 initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
85 OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
86 :OEditBaseModel( _pOriginal, _rxFactory )
91 OPatternModel::~OPatternModel()
95 // XCloneable
97 IMPLEMENT_DEFAULT_CLONING( OPatternModel )
99 // XServiceInfo
101 StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw(std::exception)
103 StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
104 aSupported.realloc(aSupported.getLength() + 3);
106 OUString*pArray = aSupported.getArray();
107 pArray[aSupported.getLength()-3] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD;
108 pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_PATTERNFIELD;
109 pArray[aSupported.getLength()-1] = FRM_COMPONENT_PATTERNFIELD;
110 return aSupported;
115 void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
117 BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
118 DECL_PROP2(DEFAULT_TEXT, OUString, BOUND, MAYBEDEFAULT);
119 DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND);
120 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
121 DECL_PROP2(FILTERPROPOSAL, sal_Bool, BOUND, MAYBEDEFAULT);
122 END_DESCRIBE_PROPERTIES();
126 OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
128 return OUString(FRM_COMPONENT_PATTERNFIELD); // old (non-sun) name for compatibility !
132 bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
134 Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
136 if ( aNewValue != m_aLastKnownValue )
138 OUString sNewValue;
139 aNewValue >>= sNewValue;
141 if ( !aNewValue.hasValue()
142 || ( sNewValue.isEmpty() // an empty string
143 && m_bEmptyIsNull // which should be interpreted as NULL
147 m_xColumnUpdate->updateNull();
149 else
151 OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" );
152 if ( !m_pFormattedValue.get() )
153 return false;
155 if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
156 return false;
159 m_aLastKnownValue = aNewValue;
162 return true;
166 void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
168 OEditBaseModel::onConnectedDbColumn( _rxForm );
170 Reference< XPropertySet > xField( getField() );
171 if ( !xField.is() )
172 return;
174 m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
178 void OPatternModel::onDisconnectedDbColumn()
180 OEditBaseModel::onDisconnectedDbColumn();
181 m_pFormattedValue.reset();
184 // XPropertyChangeListener
186 Any OPatternModel::translateDbColumnToControlValue()
188 OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" );
190 if ( m_pFormattedValue.get() )
192 OUString sValue( m_pFormattedValue->getFormattedValue() );
193 if ( sValue.isEmpty()
194 && m_pFormattedValue->getColumn().is()
195 && m_pFormattedValue->getColumn()->wasNull()
198 m_aLastKnownValue.clear();
200 else
202 m_aLastKnownValue <<= sValue;
205 else
206 m_aLastKnownValue.clear();
208 return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( OUString() );
209 // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
212 // XReset
214 Any OPatternModel::getDefaultForReset() const
216 return makeAny( m_aDefaultText );
219 void OPatternModel::resetNoBroadcast()
221 OEditBaseModel::resetNoBroadcast();
222 m_aLastKnownValue.clear();
225 } // namespace frm
227 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
228 com_sun_star_form_OPatternModel_get_implementation(::com::sun::star::uno::XComponentContext* component,
229 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
231 return cppu::acquire(new frm::OPatternModel(component));
234 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
235 com_sun_star_form_OPatternControl_get_implementation(::com::sun::star::uno::XComponentContext* component,
236 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
238 return cppu::acquire(new frm::OPatternControl(component));
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */