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 #include "CheckBox.hxx" 27 #include "property.hxx" 28 #ifndef _FRM_PROPERTY_HRC_ 29 #include "property.hrc" 30 #endif 31 #include "services.hxx" 32 #include <tools/debug.hxx> 33 #include <comphelper/basicio.hxx> 34 35 //......................................................................... 36 namespace frm 37 { 38 using namespace ::com::sun::star::uno; 39 using namespace ::com::sun::star::sdb; 40 using namespace ::com::sun::star::sdbc; 41 using namespace ::com::sun::star::sdbcx; 42 using namespace ::com::sun::star::beans; 43 using namespace ::com::sun::star::container; 44 using namespace ::com::sun::star::form; 45 using namespace ::com::sun::star::awt; 46 using namespace ::com::sun::star::io; 47 using namespace ::com::sun::star::lang; 48 using namespace ::com::sun::star::util; 49 using namespace ::com::sun::star::form::binding; 50 51 //================================================================== 52 //= OCheckBoxControl 53 //================================================================== 54 55 //------------------------------------------------------------------ 56 OCheckBoxControl::OCheckBoxControl(const Reference<XMultiServiceFactory>& _rxFactory) 57 :OBoundControl(_rxFactory, VCL_CONTROL_CHECKBOX) 58 { 59 } 60 61 //------------------------------------------------------------------ 62 InterfaceRef SAL_CALL OCheckBoxControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 63 { 64 return *(new OCheckBoxControl(_rxFactory)); 65 } 66 67 //------------------------------------------------------------------------------ 68 StringSequence SAL_CALL OCheckBoxControl::getSupportedServiceNames() 69 { 70 StringSequence aSupported = OBoundControl::getSupportedServiceNames(); 71 aSupported.realloc(aSupported.getLength() + 1); 72 73 ::rtl::OUString* pArray = aSupported.getArray(); 74 pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CHECKBOX; 75 return aSupported; 76 } 77 78 //================================================================== 79 //= OCheckBoxModel 80 //================================================================== 81 82 //================================================================== 83 InterfaceRef SAL_CALL OCheckBoxModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 84 { 85 return *(new OCheckBoxModel(_rxFactory)); 86 } 87 88 //------------------------------------------------------------------ 89 DBG_NAME( OCheckBoxModel ) 90 //------------------------------------------------------------------ 91 OCheckBoxModel::OCheckBoxModel(const Reference<XMultiServiceFactory>& _rxFactory) 92 :OReferenceValueComponent( _rxFactory, VCL_CONTROLMODEL_CHECKBOX, FRM_SUN_CONTROL_CHECKBOX, sal_True ) 93 // use the old control name for compytibility reasons 94 { 95 DBG_CTOR( OCheckBoxModel, NULL ); 96 97 m_nClassId = FormComponentType::CHECKBOX; 98 initValueProperty( PROPERTY_STATE, PROPERTY_ID_STATE ); 99 } 100 101 //------------------------------------------------------------------ 102 OCheckBoxModel::OCheckBoxModel( const OCheckBoxModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory ) 103 :OReferenceValueComponent( _pOriginal, _rxFactory ) 104 { 105 DBG_CTOR( OCheckBoxModel, NULL ); 106 } 107 108 //------------------------------------------------------------------------------ 109 OCheckBoxModel::~OCheckBoxModel() 110 { 111 DBG_DTOR( OCheckBoxModel, NULL ); 112 } 113 114 //------------------------------------------------------------------------------ 115 IMPLEMENT_DEFAULT_CLONING( OCheckBoxModel ) 116 117 // XServiceInfo 118 //------------------------------------------------------------------------------ 119 StringSequence SAL_CALL OCheckBoxModel::getSupportedServiceNames() 120 { 121 StringSequence aSupported = OReferenceValueComponent::getSupportedServiceNames(); 122 123 sal_Int32 nOldLen = aSupported.getLength(); 124 aSupported.realloc( nOldLen + 8 ); 125 ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen; 126 127 *pStoreTo++ = BINDABLE_CONTROL_MODEL; 128 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL; 129 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL; 130 131 *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL; 132 *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL; 133 134 *pStoreTo++ = FRM_SUN_COMPONENT_CHECKBOX; 135 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CHECKBOX; 136 *pStoreTo++ = BINDABLE_DATABASE_CHECK_BOX; 137 138 return aSupported; 139 } 140 141 //------------------------------------------------------------------------------ 142 void OCheckBoxModel::describeFixedProperties( Sequence< Property >& _rProps ) const 143 { 144 BEGIN_DESCRIBE_PROPERTIES( 1, OReferenceValueComponent ) 145 DECL_PROP1(TABINDEX, sal_Int16, BOUND); 146 END_DESCRIBE_PROPERTIES(); 147 } 148 149 //------------------------------------------------------------------------------ 150 ::rtl::OUString SAL_CALL OCheckBoxModel::getServiceName() 151 { 152 return FRM_COMPONENT_CHECKBOX; // old (non-sun) name for compatibility ! 153 } 154 155 //------------------------------------------------------------------------------ 156 void SAL_CALL OCheckBoxModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream) 157 { 158 OReferenceValueComponent::write(_rxOutStream); 159 160 // Version 161 _rxOutStream->writeShort(0x0003); 162 // Properties 163 _rxOutStream << getReferenceValue(); 164 _rxOutStream << (sal_Int16)getDefaultChecked(); 165 writeHelpTextCompatibly(_rxOutStream); 166 // from version 0x0003 : common properties 167 writeCommonProperties(_rxOutStream); 168 } 169 170 //------------------------------------------------------------------------------ 171 void SAL_CALL OCheckBoxModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) 172 { 173 OReferenceValueComponent::read(_rxInStream); 174 osl::MutexGuard aGuard(m_aMutex); 175 176 // Version 177 sal_uInt16 nVersion = _rxInStream->readShort(); 178 179 ::rtl::OUString sReferenceValue; 180 sal_Int16 nDefaultChecked( 0 ); 181 switch ( nVersion ) 182 { 183 case 0x0001: 184 _rxInStream >> sReferenceValue; 185 nDefaultChecked = _rxInStream->readShort(); 186 break; 187 case 0x0002: 188 _rxInStream >> sReferenceValue; 189 _rxInStream >> nDefaultChecked; 190 readHelpTextCompatibly( _rxInStream ); 191 break; 192 case 0x0003: 193 _rxInStream >> sReferenceValue; 194 _rxInStream >> nDefaultChecked; 195 readHelpTextCompatibly(_rxInStream); 196 readCommonProperties(_rxInStream); 197 break; 198 default: 199 DBG_ERROR("OCheckBoxModel::read : unknown version !"); 200 defaultCommonProperties(); 201 break; 202 } 203 setReferenceValue( sReferenceValue ); 204 setDefaultChecked( static_cast< ToggleState >( nDefaultChecked ) ); 205 206 // Nach dem Lesen die Defaultwerte anzeigen 207 if ( getControlSource().getLength() ) 208 // (not if we don't have a control source - the "State" property acts like it is persistent, then 209 resetNoBroadcast(); 210 } 211 212 //------------------------------------------------------------------------------ 213 Any OCheckBoxModel::translateDbColumnToControlValue() 214 { 215 Any aValue; 216 217 ////////////////////////////////////////////////////////////////// 218 // Wert an ControlModel setzen 219 sal_Bool bValue = m_xColumn->getBoolean(); 220 if ( m_xColumn->wasNull() ) 221 { 222 sal_Bool bTriState = sal_True; 223 if ( m_xAggregateSet.is() ) 224 m_xAggregateSet->getPropertyValue( PROPERTY_TRISTATE ) >>= bTriState; 225 aValue <<= (sal_Int16)( bTriState ? STATE_DONTKNOW : getDefaultChecked() ); 226 } 227 else 228 aValue <<= (sal_Int16)( bValue ? STATE_CHECK : STATE_NOCHECK ); 229 230 return aValue; 231 } 232 233 //----------------------------------------------------------------------------- 234 sal_Bool OCheckBoxModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 235 { 236 OSL_PRECOND( m_xColumnUpdate.is(), "OCheckBoxModel::commitControlValueToDbColumn: not bound!" ); 237 if ( m_xColumnUpdate.is() ) 238 { 239 Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) ); 240 try 241 { 242 sal_Int16 nValue = STATE_DONTKNOW; 243 aControlValue >>= nValue; 244 switch (nValue) 245 { 246 case STATE_DONTKNOW: 247 m_xColumnUpdate->updateNull(); 248 break; 249 case STATE_CHECK: 250 m_xColumnUpdate->updateBoolean( sal_True ); 251 break; 252 case STATE_NOCHECK: 253 m_xColumnUpdate->updateBoolean( sal_False ); 254 break; 255 default: 256 DBG_ERROR("OCheckBoxModel::commitControlValueToDbColumn: invalid value !"); 257 } 258 } 259 catch(Exception&) 260 { 261 DBG_ERROR("OCheckBoxModel::commitControlValueToDbColumn: could not commit !"); 262 } 263 } 264 return sal_True; 265 } 266 267 //......................................................................... 268 } 269 //......................................................................... 270