24#include <svx/strings.hrc>
29#include <com/sun/star/form/XFormComponent.hpp>
30#include <com/sun/star/form/FormComponentType.hpp>
31#include <com/sun/star/awt/ScrollBarOrientation.hpp>
32#include <com/sun/star/awt/MouseWheelBehavior.hpp>
33#include <com/sun/star/form/XGridColumnFactory.hpp>
34#include <com/sun/star/style/VerticalAlignment.hpp>
35#include <com/sun/star/awt/LineEndFormat.hpp>
36#include <com/sun/star/awt/ImageScaleMode.hpp>
37#include <com/sun/star/sdbc/DataType.hpp>
38#include <com/sun/star/sdbc/XDataSource.hpp>
39#include <com/sun/star/util/XNumberFormatTypes.hpp>
40#include <com/sun/star/sdbc/ColumnValue.hpp>
41#include <com/sun/star/text/WritingMode2.hpp>
59 using ::com::sun::star::uno::Reference;
60 using ::com::sun::star::uno::UNO_QUERY;
61 using ::com::sun::star::uno::UNO_QUERY_THROW;
62 using ::com::sun::star::uno::UNO_SET_THROW;
63 using ::com::sun::star::uno::Exception;
64 using ::com::sun::star::uno::Any;
65 using ::com::sun::star::uno::Sequence;
66 using ::com::sun::star::uno::XComponentContext;
68 using ::com::sun::star::form::XFormComponent;
69 using ::com::sun::star::container::XIndexAccess;
70 using ::com::sun::star::beans::XPropertySetInfo;
71 using ::com::sun::star::beans::PropertyValue;
72 using ::com::sun::star::container::XChild;
73 using ::com::sun::star::form::XGridColumnFactory;
74 using ::com::sun::star::style::VerticalAlignment_MIDDLE;
75 using ::com::sun::star::beans::Property;
76 using ::com::sun::star::uno::TypeClass_DOUBLE;
77 using ::com::sun::star::uno::TypeClass_LONG;
78 using ::com::sun::star::util::XNumberFormats;
79 using ::com::sun::star::util::XNumberFormatTypes;
80 using ::com::sun::star::lang::XServiceInfo;
81 using ::com::sun::star::container::XNameAccess;
83 namespace FormComponentType = ::com::sun::star::form::FormComponentType;
84 namespace ScrollBarOrientation = ::com::sun::star::awt::ScrollBarOrientation;
85 namespace MouseWheelBehavior = ::com::sun::star::awt::MouseWheelBehavior;
86 namespace LineEndFormat = ::com::sun::star::awt::LineEndFormat;
87 namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode;
88 namespace DataType = ::com::sun::star::sdbc::DataType;
89 namespace ColumnValue = ::com::sun::star::sdbc::ColumnValue;
90 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
97 FormControlFactory::FormControlFactory( )
129 OUString lcl_getUniqueLabel_nothrow(
const Reference< XPropertySet >& _rxControlModel,
const OUString& _rBaseLabel )
131 OUString sLabel( _rBaseLabel );
134 typedef ::std::set< OUString >
StringBag;
137 Reference< XFormComponent > xFormComponent( _rxControlModel, UNO_QUERY_THROW );
138 Reference< XIndexAccess > xContainer( xFormComponent->getParent(), UNO_QUERY_THROW );
140 for ( sal_Int32 index=xContainer->getCount(); index>0; )
142 Reference< XPropertySet > xElement( xContainer->getByIndex( --index ), UNO_QUERY_THROW );
143 if ( xElement == _rxControlModel )
146 Reference< XPropertySetInfo > xPSI( xElement->getPropertySetInfo(), UNO_SET_THROW );
150 OUString sElementLabel;
151 OSL_VERIFY( xElement->getPropertyValue(
FM_PROP_LABEL ) >>= sElementLabel );
152 aUsedLabels.insert( sElementLabel );
157 while ( aUsedLabels.find( sLabel ) != aUsedLabels.end() )
158 sLabel = _rBaseLabel +
" " + OUString::number( i++ );
160 catch(
const Exception& )
168 Sequence< PropertyValue > lcl_getDataSourceIndirectProperties(
const Reference< XPropertySet >& _rxControlModel,
169 const Reference<XComponentContext>& _rContext )
171 OSL_PRECOND( _rxControlModel.is(),
"lcl_getDataSourceIndirectProperties: invalid model!" );
173 Sequence< PropertyValue > aInfo;
176 Reference< XChild > xChild( _rxControlModel, UNO_QUERY );
177 Reference< XPropertySet > xForm;
179 xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
181 if ( Reference< XGridColumnFactory >( xForm, UNO_QUERY ).is() )
183 xChild.set(xForm, css::uno::UNO_QUERY);
184 xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
187 OSL_ENSURE( xForm.is(),
"lcl_getDataSourceIndirectProperties: could not determine the form!" );
190 OUString sDataSourceName;
193 Reference< XPropertySet > xDsProperties;
194 if ( !sDataSourceName.isEmpty() )
195 xDsProperties.set(
getDataSource( sDataSourceName, _rContext ), css::uno::UNO_QUERY);
196 if ( xDsProperties.is() )
197 xDsProperties->getPropertyValue(
"Info") >>= aInfo;
199 catch(
const Exception& )
207 const char* aCharacterAndParagraphProperties[] =
222 "CharBackTransparent",
246 "CharRotationIsFitToLine",
251 "VisitedCharStyleName",
252 "UnvisitedCharStyleName",
253 "CharEscapementHeight",
255 "CharUnderlineColor",
256 "CharUnderlineHasColor",
261 "CharFontStyleNameAsian",
262 "CharFontFamilyAsian",
263 "CharFontCharSetAsian",
264 "CharFontPitchAsian",
267 "ParaIsCharacterDistance",
268 "ParaIsForbiddenRules",
269 "ParaIsHangingPunctuation",
272 "CharFontNameComplex",
273 "CharFontStyleNameComplex",
274 "CharFontFamilyComplex",
275 "CharFontCharSetComplex",
276 "CharFontPitchComplex",
277 "CharPostureComplex",
282 "ParaBackTransparent",
284 "ParaBackGraphicURL",
285 "ParaBackGraphicFilter",
286 "ParaBackGraphicLocation",
287 "ParaLastLineAdjust",
288 "ParaExpandSingleWord",
293 "ParaLineNumberCount",
294 "ParaLineNumberStartValue",
297 "ParaRegisterModeActive",
308 "NumberingStartValue",
309 "ParaIsNumberingRestart",
310 "NumberingStyleName",
319 "LeftBorderDistance",
320 "RightBorderDistance",
322 "BottomBorderDistance",
324 "DropCapCharStyleName",
325 "ParaFirstLineIndent",
326 "ParaIsAutoFirstLineIndent",
328 "ParaHyphenationMaxHyphens",
329 "ParaHyphenationMaxLeadingChars",
330 "ParaHyphenationMaxTrailingChars",
332 "ParaUserDefinedAttributes",
334 "ParaIsConnectBorder",
339 void lcl_initializeCharacterAttributes(
const Reference< XPropertySet >& _rxModel )
346 Reference< XPropertySetInfo > xSourcePropInfo( xStyle->getPropertySetInfo(), UNO_SET_THROW );
347 Reference< XPropertySetInfo > xDestPropInfo( _rxModel->getPropertySetInfo(), UNO_SET_THROW );
349 OUString sPropertyName;
350 const char** pCharacterProperty = aCharacterAndParagraphProperties;
351 while ( *pCharacterProperty )
353 sPropertyName = OUString::createFromAscii( *pCharacterProperty );
355 if ( xSourcePropInfo->hasPropertyByName( sPropertyName ) && xDestPropInfo->hasPropertyByName( sPropertyName ) )
356 _rxModel->setPropertyValue( sPropertyName, xStyle->getPropertyValue( sPropertyName ) );
358 ++pCharacterProperty;
361 catch(
const Exception& )
372 sal_Int16 nClassId = FormComponentType::CONTROL;
374 OSL_ENSURE( _rxControlModel.is(),
"FormControlFactory::initializeControlModel: invalid model!" );
375 if ( !_rxControlModel.is() )
383 Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
386 case FormComponentType::SCROLLBAR:
387 _rxControlModel->setPropertyValue(
"LiveScroll",
Any(
true ) );
389 case FormComponentType::SPINBUTTON:
391 sal_Int32 eOrientation = ScrollBarOrientation::HORIZONTAL;
393 eOrientation = ScrollBarOrientation::VERTICAL;
398 case FormComponentType::LISTBOX:
399 case FormComponentType::COMBOBOX:
401 bool bDropDown = !_rControlBoundRect.
IsEmpty() && ( _rControlBoundRect.
GetWidth() >= 3 * _rControlBoundRect.
GetHeight() );
408 case FormComponentType::TEXTFIELD:
411 lcl_initializeCharacterAttributes( _rxControlModel );
413 if ( !_rControlBoundRect.
IsEmpty()
423 case FormComponentType::RADIOBUTTON:
424 case FormComponentType::CHECKBOX:
425 case FormComponentType::FIXEDTEXT:
427 OUString sVertAlignPropertyName(
"VerticalAlign" );
428 if ( xPSI->hasPropertyByName( sVertAlignPropertyName ) )
429 _rxControlModel->setPropertyValue( sVertAlignPropertyName,
Any( VerticalAlignment_MIDDLE ) );
433 case FormComponentType::IMAGEBUTTON:
434 case FormComponentType::IMAGECONTROL:
436 static constexpr OUStringLiteral sScaleModeProperty( u
"ScaleMode" );
437 if ( xPSI->hasPropertyByName( sScaleModeProperty ) )
438 _rxControlModel->setPropertyValue( sScaleModeProperty,
Any( ImageScaleMode::ISOTROPIC ) );
446 OUString sExistingLabel;
447 OSL_VERIFY( _rxControlModel->getPropertyValue(
FM_PROP_LABEL ) >>= sExistingLabel );
448 if ( sExistingLabel.isEmpty() )
450 OUString sInitialLabel;
451 OSL_VERIFY( _rxControlModel->getPropertyValue(
FM_PROP_NAME ) >>= sInitialLabel );
456 case FormComponentType::COMMANDBUTTON: pTitleResId = RID_STR_PROPTITLE_PUSHBUTTON;
break;
457 case FormComponentType::RADIOBUTTON: pTitleResId = RID_STR_PROPTITLE_RADIOBUTTON;
break;
458 case FormComponentType::CHECKBOX: pTitleResId = RID_STR_PROPTITLE_CHECKBOX;
break;
459 case FormComponentType::GROUPBOX: pTitleResId = RID_STR_PROPTITLE_GROUPBOX;
break;
460 case FormComponentType::FIXEDTEXT: pTitleResId = RID_STR_PROPTITLE_FIXEDTEXT;
break;
464 sInitialLabel =
SvxResId(pTitleResId);
466 _rxControlModel->setPropertyValue(
468 Any( lcl_getUniqueLabel_nothrow( _rxControlModel, sInitialLabel ) )
488 catch(
const Exception& )
498 OSL_PRECOND( _rxModel.is(),
"initializeTextFieldLineEnds: invalid model!" );
499 if ( !_rxModel.is() )
504 Reference< XPropertySetInfo > xInfo = _rxModel->getPropertySetInfo();
510 bool bDosLineEnds =
false;
511 const Sequence< PropertyValue > aInfo = lcl_getDataSourceIndirectProperties( _rxModel,
m_xContext );
512 const PropertyValue* pInfo = std::find_if(aInfo.begin(), aInfo.end(),
513 [](
const PropertyValue& rInfo) { return rInfo.Name ==
"PreferDosLikeLineEnds"; });
514 if (pInfo != aInfo.end())
515 pInfo->Value >>= bDosLineEnds;
517 sal_Int16 nLineEndFormat = bDosLineEnds ? LineEndFormat::CARRIAGE_RETURN_LINE_FEED : LineEndFormat::LINE_FEED;
528 const Reference< XPropertySet >& _rxControlModel,
const Reference< XNumberFormats >& _rxNumberFormats )
530 OSL_PRECOND( _rxDatabaseField.is() && _rxControlModel.is(),
531 "FormControlFactory::initializeFieldDependentProperties: illegal params!" );
532 if ( !_rxDatabaseField.is() || !_rxControlModel.is() )
539 Reference< XPropertySetInfo > xFieldPSI( _rxDatabaseField->getPropertySetInfo(), UNO_SET_THROW );
540 Reference< XPropertySetInfo > xModelPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
544 sal_Int32 nFormatKey = 0;
553 Reference< XNumberFormatTypes >( _rxNumberFormats, UNO_QUERY ),
558 Any aScaleVal( ::comphelper::getNumberFormatDecimals( _rxNumberFormats, nFormatKey ) );
571 sal_Int32 nMinValue = -1000000000, nMaxValue = 1000000000;
574 case DataType::TINYINT : nMinValue = 0; nMaxValue = 255;
break;
575 case DataType::SMALLINT : nMinValue = -32768; nMaxValue = 32767;
break;
576 case DataType::INTEGER : nMinValue = 0x80000000; nMaxValue = 0x7FFFFFFF;
break;
584 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
585 aValue <<= static_cast<double>(nMinValue);
586 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
587 aValue <<= nMinValue;
590 OSL_FAIL(
"FormControlFactory::initializeFieldDependentProperties: unexpected property type (MinValue)!" );
596 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
597 aValue <<= static_cast<double>(nMaxValue);
598 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
599 aValue <<= nMaxValue;
602 OSL_FAIL(
"FormControlFactory::initializeFieldDependentProperties: unexpected property type (MaxValue)!" );
609 sal_Int16 nClassId = FormComponentType::CONTROL;
610 OSL_VERIFY( _rxControlModel->getPropertyValue(
FM_PROP_CLASSID ) >>= nClassId );
611 if ( nClassId == FormComponentType::CHECKBOX )
613 sal_Int32
nNullable = ColumnValue::NULLABLE_UNKNOWN;
631 case FormComponentType::COMMANDBUTTON: pResId = RID_STR_PROPTITLE_PUSHBUTTON;
break;
632 case FormComponentType::RADIOBUTTON: pResId = RID_STR_PROPTITLE_RADIOBUTTON;
break;
633 case FormComponentType::CHECKBOX: pResId = RID_STR_PROPTITLE_CHECKBOX;
break;
634 case FormComponentType::LISTBOX: pResId = RID_STR_PROPTITLE_LISTBOX;
break;
635 case FormComponentType::COMBOBOX: pResId = RID_STR_PROPTITLE_COMBOBOX;
break;
636 case FormComponentType::GROUPBOX: pResId = RID_STR_PROPTITLE_GROUPBOX;
break;
637 case FormComponentType::IMAGEBUTTON: pResId = RID_STR_PROPTITLE_IMAGEBUTTON;
break;
638 case FormComponentType::FIXEDTEXT: pResId = RID_STR_PROPTITLE_FIXEDTEXT;
break;
639 case FormComponentType::GRIDCONTROL: pResId = RID_STR_PROPTITLE_DBGRID;
break;
640 case FormComponentType::FILECONTROL: pResId = RID_STR_PROPTITLE_FILECONTROL;
break;
641 case FormComponentType::DATEFIELD: pResId = RID_STR_PROPTITLE_DATEFIELD;
break;
642 case FormComponentType::TIMEFIELD: pResId = RID_STR_PROPTITLE_TIMEFIELD;
break;
643 case FormComponentType::NUMERICFIELD: pResId = RID_STR_PROPTITLE_NUMERICFIELD;
break;
644 case FormComponentType::CURRENCYFIELD: pResId = RID_STR_PROPTITLE_CURRENCYFIELD;
break;
645 case FormComponentType::PATTERNFIELD: pResId = RID_STR_PROPTITLE_PATTERNFIELD;
break;
646 case FormComponentType::IMAGECONTROL: pResId = RID_STR_PROPTITLE_IMAGECONTROL;
break;
647 case FormComponentType::HIDDENCONTROL: pResId = RID_STR_PROPTITLE_HIDDEN;
break;
648 case FormComponentType::SCROLLBAR: pResId = RID_STR_PROPTITLE_SCROLLBAR;
break;
649 case FormComponentType::SPINBUTTON: pResId = RID_STR_PROPTITLE_SPINBUTTON;
break;
650 case FormComponentType::NAVIGATIONBAR: pResId = RID_STR_PROPTITLE_NAVBAR;
break;
652 case FormComponentType::TEXTFIELD:
653 pResId = RID_STR_PROPTITLE_EDIT;
655 pResId = RID_STR_PROPTITLE_FORMATTED;
659 pResId = RID_STR_CONTROL;
break;
667 const Reference< XPropertySet >& _rxObject )
669 sal_Int16 nClassId = FormComponentType::CONTROL;
670 OSL_VERIFY( _rxObject->getPropertyValue(
FM_PROP_CLASSID ) >>= nClassId );
671 OUString sBaseName =
getDefaultName( nClassId, Reference< XServiceInfo >( _rxObject, UNO_QUERY ) );
683 sName = OUString::Concat(_rBaseName) +
" " + OUString::number( ++
n );
685 while ( _rxContainer->hasByName(
sName ) );
Reference< XComponentContext > m_xContext
virtual const tools::Rectangle & GetCurrentBoundRect() const
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
OUString SvxResId(TranslateId aId)
constexpr OUStringLiteral FM_PROP_DECIMAL_ACCURACY
constexpr OUStringLiteral FM_PROP_ISNULLABLE
constexpr OUStringLiteral FM_PROP_CLASSID
constexpr OUStringLiteral FM_PROP_MULTILINE
constexpr OUStringLiteral FM_PROP_LABEL
constexpr OUStringLiteral FM_PROP_LINEENDFORMAT
constexpr OUStringLiteral FM_PROP_NAME
constexpr OUStringLiteral FM_PROP_VALUEMIN
constexpr OUStringLiteral FM_PROP_WRITING_MODE
constexpr OUStringLiteral FM_PROP_LINECOUNT
constexpr OUStringLiteral FM_PROP_STRICTFORMAT
constexpr OUStringLiteral FM_PROP_MOUSE_WHEEL_BEHAVIOR
constexpr OUStringLiteral FM_PROP_ORIENTATION
constexpr OUStringLiteral FM_PROP_DROPDOWN
constexpr OUStringLiteral FM_PROP_VALUEMAX
constexpr OUStringLiteral FM_PROP_FORMATKEY
constexpr OUStringLiteral FM_PROP_TRISTATE
constexpr OUStringLiteral FM_PROP_FIELDTYPE
constexpr OUStringLiteral FM_PROP_DATASOURCE
constexpr OUStringLiteral FM_SUN_COMPONENT_FORMATTEDFIELD
std::set< OUString > StringBag
class SAL_NO_VTABLE XPropertySet
const LanguageTag & getLocale()
class SvxPropertySetInfoPool
Reference< XComponentContext > getProcessComponentContext()
css::uno::Reference< css::uno::XInterface > getDataSource(const css::uno::Reference< css::uno::XInterface > &_rxDependentObject)