/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::UNO_QUERY; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::uno::UNO_SET_THROW; using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::XComponentContext; using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::form::XFormComponent; using ::com::sun::star::container::XIndexAccess; using ::com::sun::star::beans::XPropertySetInfo; using ::com::sun::star::beans::PropertyValue; using ::com::sun::star::container::XChild; using ::com::sun::star::form::XGridColumnFactory; using ::com::sun::star::style::VerticalAlignment_MIDDLE; using ::com::sun::star::beans::Property; using ::com::sun::star::uno::TypeClass_DOUBLE; using ::com::sun::star::uno::TypeClass_LONG; using ::com::sun::star::util::XNumberFormats; using ::com::sun::star::util::XNumberFormatTypes; using ::com::sun::star::lang::XServiceInfo; using ::com::sun::star::container::XNameAccess;
if ( Reference< XGridColumnFactory >( xForm, UNO_QUERY ).is() )
{ // hmm. the model is a grid column, in real
xChild.set(xForm, css::uno::UNO_QUERY);
xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
}
OSL_ENSURE( xForm.is(), "lcl_getDataSourceIndirectProperties: could not determine the form!" ); if ( !xForm.is() ) return aInfo;
OUString sDataSourceName;
xForm->getPropertyValue( FM_PROP_DATASOURCE ) >>= sDataSourceName;
// transfer all properties which are described by the style
Reference< XPropertySetInfo > xSourcePropInfo( xStyle->getPropertySetInfo(), UNO_SET_THROW );
Reference< XPropertySetInfo > xDestPropInfo( _rxModel->getPropertySetInfo(), UNO_SET_THROW );
// strict format = yes is the default (i93467) if ( xPSI->hasPropertyByName( FM_PROP_STRICTFORMAT ) )
{
_rxControlModel->setPropertyValue( FM_PROP_STRICTFORMAT, Any( true ) );
}
// mouse wheel: don't use it for scrolling by default (i110036) if ( xPSI->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) )
{
_rxControlModel->setPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR, Any( MouseWheelBehavior::SCROLL_DISABLED ) );
}
// let's see if the data source which the form belongs to (if any) // has a setting for the preferred line end format bool bDosLineEnds = false; const Sequence< PropertyValue > aInfo = lcl_getDataSourceIndirectProperties( _rxModel, m_xContext ); const PropertyValue* pInfo = std::find_if(aInfo.begin(), aInfo.end(),
[](const PropertyValue& rInfo) { return rInfo.Name == "PreferDosLikeLineEnds"; }); if (pInfo != aInfo.end())
pInfo->Value >>= bDosLineEnds;
// if the field has a numeric format, and the model has a "Scale" property, sync it
Reference< XPropertySetInfo > xFieldPSI( _rxDatabaseField->getPropertySetInfo(), UNO_SET_THROW );
Reference< XPropertySetInfo > xModelPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
// minimum and maximum of the control according to the type of the database field
sal_Int32 nDataType = DataType::OTHER;
OSL_VERIFY( _rxDatabaseField->getPropertyValue( FM_PROP_FIELDTYPE ) >>= nDataType );
if ( xModelPSI->hasPropertyByName( FM_PROP_VALUEMIN )
&& xModelPSI->hasPropertyByName( FM_PROP_VALUEMAX )
)
{
sal_Int32 nMinValue = -1000000000, nMaxValue = 1000000000; switch ( nDataType )
{ case DataType::TINYINT : nMinValue = 0; nMaxValue = 255; break; case DataType::SMALLINT : nMinValue = -32768; nMaxValue = 32767; break; case DataType::INTEGER : nMinValue = 0x80000000; nMaxValue = 0x7FFFFFFF; break; // double and singles are ignored
}
Any aValue;
// both the minimum and the maximum value properties can be either Long or Double
Property aProperty = xModelPSI->getPropertyByName( FM_PROP_VALUEMIN ); if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
aValue <<= static_cast<double>(nMinValue); elseif ( aProperty.Type.getTypeClass() == TypeClass_LONG )
aValue <<= nMinValue; else
{
OSL_FAIL( "FormControlFactory::initializeFieldDependentProperties: unexpected property type (MinValue)!" );
}
_rxControlModel->setPropertyValue( FM_PROP_VALUEMIN, aValue );
// both the minimum and the maximum value properties can be either Long or Double
aProperty = xModelPSI->getPropertyByName( FM_PROP_VALUEMAX ); if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
aValue <<= static_cast<double>(nMaxValue); elseif ( aProperty.Type.getTypeClass() == TypeClass_LONG )
aValue <<= nMaxValue; else
{
OSL_FAIL( "FormControlFactory::initializeFieldDependentProperties: unexpected property type (MaxValue)!" );
}
_rxControlModel->setPropertyValue( FM_PROP_VALUEMAX, aValue );
}
// a check box can be tristate if and only if the column it is bound to is nullable
sal_Int16 nClassId = FormComponentType::CONTROL;
OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId ); if ( nClassId == FormComponentType::CHECKBOX )
{
sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN;
OSL_VERIFY( _rxDatabaseField->getPropertyValue( FM_PROP_ISNULLABLE ) >>= nNullable );
_rxControlModel->setPropertyValue( FM_PROP_TRISTATE, Any( ColumnValue::NO_NULLS != nNullable ) );
}
} catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("svx");
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.