1*24acc546SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*24acc546SAndrew Rist * distributed with this work for additional information 6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance 9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*24acc546SAndrew Rist * software distributed under the License is distributed on an 15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the 17*24acc546SAndrew Rist * specific language governing permissions and limitations 18*24acc546SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*24acc546SAndrew Rist *************************************************************/ 21*24acc546SAndrew Rist 22*24acc546SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_forms.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "Pattern.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir /** === begin UNO includes === **/ 30cdf0e10cSrcweir /** === end UNO includes === **/ 31cdf0e10cSrcweir 32cdf0e10cSrcweir //......................................................................... 33cdf0e10cSrcweir namespace frm 34cdf0e10cSrcweir { 35cdf0e10cSrcweir //......................................................................... 36cdf0e10cSrcweir 37cdf0e10cSrcweir /** === begin UNO using === **/ 38cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 39cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 40cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 41cdf0e10cSrcweir using ::com::sun::star::uno::Type; 42cdf0e10cSrcweir using ::com::sun::star::beans::Property; 43cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 44cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 45cdf0e10cSrcweir using ::com::sun::star::uno::Any; 46cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 47cdf0e10cSrcweir using ::com::sun::star::sdbc::XRowSet; 48cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 49cdf0e10cSrcweir /** === end UNO using === **/ 50cdf0e10cSrcweir namespace FormComponentType = ::com::sun::star::form::FormComponentType; 51cdf0e10cSrcweir 52cdf0e10cSrcweir //================================================================== 53cdf0e10cSrcweir // OPatternControl 54cdf0e10cSrcweir //================================================================== 55cdf0e10cSrcweir //------------------------------------------------------------------ 56cdf0e10cSrcweir OPatternControl::OPatternControl(const Reference<XMultiServiceFactory>& _rxFactory) 57cdf0e10cSrcweir :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir //------------------------------------------------------------------ 62cdf0e10cSrcweir InterfaceRef SAL_CALL OPatternControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir return *(new OPatternControl(_rxFactory)); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir //------------------------------------------------------------------------------ 68cdf0e10cSrcweir Sequence<Type> OPatternControl::_getTypes() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir return OBoundControl::_getTypes(); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir //------------------------------------------------------------------------------ 74cdf0e10cSrcweir StringSequence OPatternControl::getSupportedServiceNames() throw() 75cdf0e10cSrcweir { 76cdf0e10cSrcweir StringSequence aSupported = OBoundControl::getSupportedServiceNames(); 77cdf0e10cSrcweir aSupported.realloc(aSupported.getLength() + 1); 78cdf0e10cSrcweir 79cdf0e10cSrcweir ::rtl::OUString*pArray = aSupported.getArray(); 80cdf0e10cSrcweir pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_PATTERNFIELD; 81cdf0e10cSrcweir return aSupported; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir //================================================================== 85cdf0e10cSrcweir // OPatternModel 86cdf0e10cSrcweir //================================================================== 87cdf0e10cSrcweir //------------------------------------------------------------------ 88cdf0e10cSrcweir InterfaceRef SAL_CALL OPatternModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir return *(new OPatternModel(_rxFactory)); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir //------------------------------------------------------------------------------ 94cdf0e10cSrcweir Sequence<Type> OPatternModel::_getTypes() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir return OEditBaseModel::_getTypes(); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir //------------------------------------------------------------------ 100cdf0e10cSrcweir DBG_NAME( OPatternModel ) 101cdf0e10cSrcweir //------------------------------------------------------------------ 102cdf0e10cSrcweir OPatternModel::OPatternModel(const Reference<XMultiServiceFactory>& _rxFactory) 103cdf0e10cSrcweir :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, sal_False, sal_False ) 104cdf0e10cSrcweir // use the old control name for compytibility reasons 105cdf0e10cSrcweir { 106cdf0e10cSrcweir DBG_CTOR( OPatternModel, NULL ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir m_nClassId = FormComponentType::PATTERNFIELD; 109cdf0e10cSrcweir initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT ); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir //------------------------------------------------------------------ 113cdf0e10cSrcweir OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory ) 114cdf0e10cSrcweir :OEditBaseModel( _pOriginal, _rxFactory ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir DBG_CTOR( OPatternModel, NULL ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir //------------------------------------------------------------------ 120cdf0e10cSrcweir OPatternModel::~OPatternModel() 121cdf0e10cSrcweir { 122cdf0e10cSrcweir DBG_DTOR( OPatternModel, NULL ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir // XCloneable 126cdf0e10cSrcweir //------------------------------------------------------------------------------ 127cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OPatternModel ) 128cdf0e10cSrcweir 129cdf0e10cSrcweir // XServiceInfo 130cdf0e10cSrcweir //------------------------------------------------------------------------------ 131cdf0e10cSrcweir StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw() 132cdf0e10cSrcweir { 133cdf0e10cSrcweir StringSequence aSupported = OBoundControlModel::getSupportedServiceNames(); 134cdf0e10cSrcweir aSupported.realloc(aSupported.getLength() + 2); 135cdf0e10cSrcweir 136cdf0e10cSrcweir ::rtl::OUString*pArray = aSupported.getArray(); 137cdf0e10cSrcweir pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD; 138cdf0e10cSrcweir pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_PATTERNFIELD; 139cdf0e10cSrcweir return aSupported; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir 143cdf0e10cSrcweir //------------------------------------------------------------------------------ 144cdf0e10cSrcweir void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const 145cdf0e10cSrcweir { 146cdf0e10cSrcweir BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel ) 147cdf0e10cSrcweir DECL_PROP2(DEFAULT_TEXT, ::rtl::OUString, BOUND, MAYBEDEFAULT); 148cdf0e10cSrcweir DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND); 149cdf0e10cSrcweir DECL_PROP1(TABINDEX, sal_Int16, BOUND); 150cdf0e10cSrcweir DECL_PROP2(FILTERPROPOSAL, sal_Bool, BOUND, MAYBEDEFAULT); 151cdf0e10cSrcweir END_DESCRIBE_PROPERTIES(); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir //------------------------------------------------------------------------------ 155cdf0e10cSrcweir ::rtl::OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir return FRM_COMPONENT_PATTERNFIELD; // old (non-sun) name for compatibility ! 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir //------------------------------------------------------------------------------ 161cdf0e10cSrcweir sal_Bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir if ( aNewValue != m_aLastKnownValue ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir ::rtl::OUString sNewValue; 168cdf0e10cSrcweir aNewValue >>= sNewValue; 169cdf0e10cSrcweir 170cdf0e10cSrcweir if ( !aNewValue.hasValue() 171cdf0e10cSrcweir || ( !sNewValue.getLength() // an empty string 172cdf0e10cSrcweir && m_bEmptyIsNull // which should be interpreted as NULL 173cdf0e10cSrcweir ) 174cdf0e10cSrcweir ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir m_xColumnUpdate->updateNull(); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir else 179cdf0e10cSrcweir { 180cdf0e10cSrcweir OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" ); 181cdf0e10cSrcweir if ( !m_pFormattedValue.get() ) 182cdf0e10cSrcweir return sal_False; 183cdf0e10cSrcweir 184cdf0e10cSrcweir if ( !m_pFormattedValue->setFormattedValue( sNewValue ) ) 185cdf0e10cSrcweir return sal_False; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir m_aLastKnownValue = aNewValue; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir return sal_True; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir //------------------------------------------------------------------------------ 195cdf0e10cSrcweir void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir OEditBaseModel::onConnectedDbColumn( _rxForm ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir Reference< XPropertySet > xField( getField() ); 200cdf0e10cSrcweir if ( !xField.is() ) 201cdf0e10cSrcweir return; 202cdf0e10cSrcweir 203cdf0e10cSrcweir m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir //------------------------------------------------------------------------------ 207cdf0e10cSrcweir void OPatternModel::onDisconnectedDbColumn() 208cdf0e10cSrcweir { 209cdf0e10cSrcweir OEditBaseModel::onDisconnectedDbColumn(); 210cdf0e10cSrcweir m_pFormattedValue.reset(); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir // XPropertyChangeListener 214cdf0e10cSrcweir //------------------------------------------------------------------------------ 215cdf0e10cSrcweir Any OPatternModel::translateDbColumnToControlValue() 216cdf0e10cSrcweir { 217cdf0e10cSrcweir OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" ); 218cdf0e10cSrcweir 219cdf0e10cSrcweir if ( m_pFormattedValue.get() ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir ::rtl::OUString sValue( m_pFormattedValue->getFormattedValue() ); 222cdf0e10cSrcweir if ( !sValue.getLength() 223cdf0e10cSrcweir && m_pFormattedValue->getColumn().is() 224cdf0e10cSrcweir && m_pFormattedValue->getColumn()->wasNull() 225cdf0e10cSrcweir ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir m_aLastKnownValue.clear(); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir else 230cdf0e10cSrcweir { 231cdf0e10cSrcweir m_aLastKnownValue <<= sValue; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir } 234cdf0e10cSrcweir else 235cdf0e10cSrcweir m_aLastKnownValue.clear(); 236cdf0e10cSrcweir 237cdf0e10cSrcweir return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( ::rtl::OUString() ); 238cdf0e10cSrcweir // (m_aLastKnownValue is alllowed to be VOID, the control value isn't) 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir // XReset 242cdf0e10cSrcweir //------------------------------------------------------------------------------ 243cdf0e10cSrcweir Any OPatternModel::getDefaultForReset() const 244cdf0e10cSrcweir { 245cdf0e10cSrcweir return makeAny( m_aDefaultText ); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir //------------------------------------------------------------------------------ 249cdf0e10cSrcweir void OPatternModel::resetNoBroadcast() 250cdf0e10cSrcweir { 251cdf0e10cSrcweir OEditBaseModel::resetNoBroadcast(); 252cdf0e10cSrcweir m_aLastKnownValue.clear(); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir //......................................................................... 256cdf0e10cSrcweir } // namespace frm 257cdf0e10cSrcweir //......................................................................... 258cdf0e10cSrcweir 259