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() )
159 OUStringBuffer
aBuffer( _rBaseLabel );
162 sLabel =
aBuffer.makeStringAndClear();
165 catch(
const Exception& )
173 Sequence< PropertyValue > lcl_getDataSourceIndirectProperties(
const Reference< XPropertySet >& _rxControlModel,
174 const Reference<XComponentContext>& _rContext )
176 OSL_PRECOND( _rxControlModel.is(),
"lcl_getDataSourceIndirectProperties: invalid model!" );
178 Sequence< PropertyValue > aInfo;
181 Reference< XChild > xChild( _rxControlModel, UNO_QUERY );
182 Reference< XPropertySet > xForm;
184 xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
186 if ( Reference< XGridColumnFactory >( xForm, UNO_QUERY ).is() )
188 xChild.set(xForm, css::uno::UNO_QUERY);
189 xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
192 OSL_ENSURE( xForm.is(),
"lcl_getDataSourceIndirectProperties: could not determine the form!" );
195 OUString sDataSourceName;
198 Reference< XPropertySet > xDsProperties;
199 if ( !sDataSourceName.isEmpty() )
200 xDsProperties.set(
getDataSource( sDataSourceName, _rContext ), css::uno::UNO_QUERY);
201 if ( xDsProperties.is() )
202 xDsProperties->getPropertyValue(
"Info") >>= aInfo;
204 catch(
const Exception& )
212 const char* aCharacterAndParagraphProperties[] =
227 "CharBackTransparent",
251 "CharRotationIsFitToLine",
256 "VisitedCharStyleName",
257 "UnvisitedCharStyleName",
258 "CharEscapementHeight",
260 "CharUnderlineColor",
261 "CharUnderlineHasColor",
266 "CharFontStyleNameAsian",
267 "CharFontFamilyAsian",
268 "CharFontCharSetAsian",
269 "CharFontPitchAsian",
272 "ParaIsCharacterDistance",
273 "ParaIsForbiddenRules",
274 "ParaIsHangingPunctuation",
277 "CharFontNameComplex",
278 "CharFontStyleNameComplex",
279 "CharFontFamilyComplex",
280 "CharFontCharSetComplex",
281 "CharFontPitchComplex",
282 "CharPostureComplex",
287 "ParaBackTransparent",
289 "ParaBackGraphicURL",
290 "ParaBackGraphicFilter",
291 "ParaBackGraphicLocation",
292 "ParaLastLineAdjust",
293 "ParaExpandSingleWord",
298 "ParaLineNumberCount",
299 "ParaLineNumberStartValue",
302 "ParaRegisterModeActive",
313 "NumberingStartValue",
314 "ParaIsNumberingRestart",
315 "NumberingStyleName",
324 "LeftBorderDistance",
325 "RightBorderDistance",
327 "BottomBorderDistance",
329 "DropCapCharStyleName",
330 "ParaFirstLineIndent",
331 "ParaIsAutoFirstLineIndent",
333 "ParaHyphenationMaxHyphens",
334 "ParaHyphenationMaxLeadingChars",
335 "ParaHyphenationMaxTrailingChars",
337 "ParaUserDefinedAttributes",
339 "ParaIsConnectBorder",
344 void lcl_initializeCharacterAttributes(
const Reference< XPropertySet >& _rxModel )
351 Reference< XPropertySetInfo > xSourcePropInfo( xStyle->getPropertySetInfo(), UNO_SET_THROW );
352 Reference< XPropertySetInfo > xDestPropInfo( _rxModel->getPropertySetInfo(), UNO_SET_THROW );
354 OUString sPropertyName;
355 const char** pCharacterProperty = aCharacterAndParagraphProperties;
356 while ( *pCharacterProperty )
358 sPropertyName = OUString::createFromAscii( *pCharacterProperty );
360 if ( xSourcePropInfo->hasPropertyByName( sPropertyName ) && xDestPropInfo->hasPropertyByName( sPropertyName ) )
361 _rxModel->setPropertyValue( sPropertyName, xStyle->getPropertyValue( sPropertyName ) );
363 ++pCharacterProperty;
366 catch(
const Exception& )
377 sal_Int16 nClassId = FormComponentType::CONTROL;
379 OSL_ENSURE( _rxControlModel.is(),
"FormControlFactory::initializeControlModel: invalid model!" );
380 if ( !_rxControlModel.is() )
388 Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
391 case FormComponentType::SCROLLBAR:
392 _rxControlModel->setPropertyValue(
"LiveScroll",
Any(
true ) );
394 case FormComponentType::SPINBUTTON:
396 sal_Int32 eOrientation = ScrollBarOrientation::HORIZONTAL;
398 eOrientation = ScrollBarOrientation::VERTICAL;
403 case FormComponentType::LISTBOX:
404 case FormComponentType::COMBOBOX:
406 bool bDropDown = !_rControlBoundRect.
IsEmpty() && ( _rControlBoundRect.
GetWidth() >= 3 * _rControlBoundRect.
GetHeight() );
413 case FormComponentType::TEXTFIELD:
416 lcl_initializeCharacterAttributes( _rxControlModel );
418 if ( !_rControlBoundRect.
IsEmpty()
428 case FormComponentType::RADIOBUTTON:
429 case FormComponentType::CHECKBOX:
430 case FormComponentType::FIXEDTEXT:
432 OUString sVertAlignPropertyName(
"VerticalAlign" );
433 if ( xPSI->hasPropertyByName( sVertAlignPropertyName ) )
434 _rxControlModel->setPropertyValue( sVertAlignPropertyName,
Any( VerticalAlignment_MIDDLE ) );
438 case FormComponentType::IMAGEBUTTON:
439 case FormComponentType::IMAGECONTROL:
441 static const OUStringLiteral sScaleModeProperty( u
"ScaleMode" );
442 if ( xPSI->hasPropertyByName( sScaleModeProperty ) )
443 _rxControlModel->setPropertyValue( sScaleModeProperty,
Any( ImageScaleMode::ISOTROPIC ) );
451 OUString sExistingLabel;
452 OSL_VERIFY( _rxControlModel->getPropertyValue(
FM_PROP_LABEL ) >>= sExistingLabel );
453 if ( sExistingLabel.isEmpty() )
455 OUString sInitialLabel;
456 OSL_VERIFY( _rxControlModel->getPropertyValue(
FM_PROP_NAME ) >>= sInitialLabel );
461 case FormComponentType::COMMANDBUTTON: pTitleResId = RID_STR_PROPTITLE_PUSHBUTTON;
break;
462 case FormComponentType::RADIOBUTTON: pTitleResId = RID_STR_PROPTITLE_RADIOBUTTON;
break;
463 case FormComponentType::CHECKBOX: pTitleResId = RID_STR_PROPTITLE_CHECKBOX;
break;
464 case FormComponentType::GROUPBOX: pTitleResId = RID_STR_PROPTITLE_GROUPBOX;
break;
465 case FormComponentType::FIXEDTEXT: pTitleResId = RID_STR_PROPTITLE_FIXEDTEXT;
break;
469 sInitialLabel =
SvxResId(pTitleResId);
471 _rxControlModel->setPropertyValue(
473 Any( lcl_getUniqueLabel_nothrow( _rxControlModel, sInitialLabel ) )
493 catch(
const Exception& )
503 OSL_PRECOND( _rxModel.is(),
"initializeTextFieldLineEnds: invalid model!" );
504 if ( !_rxModel.is() )
509 Reference< XPropertySetInfo > xInfo = _rxModel->getPropertySetInfo();
515 bool bDosLineEnds =
false;
516 const Sequence< PropertyValue > aInfo = lcl_getDataSourceIndirectProperties( _rxModel,
m_xContext );
517 const PropertyValue* pInfo = std::find_if(aInfo.begin(), aInfo.end(),
518 [](
const PropertyValue& rInfo) { return rInfo.Name ==
"PreferDosLikeLineEnds"; });
519 if (pInfo != aInfo.end())
520 pInfo->Value >>= bDosLineEnds;
522 sal_Int16 nLineEndFormat = bDosLineEnds ? LineEndFormat::CARRIAGE_RETURN_LINE_FEED : LineEndFormat::LINE_FEED;
533 const Reference< XPropertySet >& _rxControlModel,
const Reference< XNumberFormats >& _rxNumberFormats )
535 OSL_PRECOND( _rxDatabaseField.is() && _rxControlModel.is(),
536 "FormControlFactory::initializeFieldDependentProperties: illegal params!" );
537 if ( !_rxDatabaseField.is() || !_rxControlModel.is() )
544 Reference< XPropertySetInfo > xFieldPSI( _rxDatabaseField->getPropertySetInfo(), UNO_SET_THROW );
545 Reference< XPropertySetInfo > xModelPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
549 sal_Int32 nFormatKey = 0;
558 Reference< XNumberFormatTypes >( _rxNumberFormats, UNO_QUERY ),
563 Any aScaleVal( ::comphelper::getNumberFormatDecimals( _rxNumberFormats, nFormatKey ) );
576 sal_Int32 nMinValue = -1000000000, nMaxValue = 1000000000;
579 case DataType::TINYINT : nMinValue = 0; nMaxValue = 255;
break;
580 case DataType::SMALLINT : nMinValue = -32768; nMaxValue = 32767;
break;
581 case DataType::INTEGER : nMinValue = 0x80000000; nMaxValue = 0x7FFFFFFF;
break;
589 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
590 aValue <<= static_cast<double>(nMinValue);
591 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
592 aValue <<= nMinValue;
595 OSL_FAIL(
"FormControlFactory::initializeFieldDependentProperties: unexpected property type (MinValue)!" );
601 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
602 aValue <<= static_cast<double>(nMaxValue);
603 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
604 aValue <<= nMaxValue;
607 OSL_FAIL(
"FormControlFactory::initializeFieldDependentProperties: unexpected property type (MaxValue)!" );
614 sal_Int16 nClassId = FormComponentType::CONTROL;
615 OSL_VERIFY( _rxControlModel->getPropertyValue(
FM_PROP_CLASSID ) >>= nClassId );
616 if ( nClassId == FormComponentType::CHECKBOX )
618 sal_Int32
nNullable = ColumnValue::NULLABLE_UNKNOWN;
636 case FormComponentType::COMMANDBUTTON: pResId = RID_STR_PROPTITLE_PUSHBUTTON;
break;
637 case FormComponentType::RADIOBUTTON: pResId = RID_STR_PROPTITLE_RADIOBUTTON;
break;
638 case FormComponentType::CHECKBOX: pResId = RID_STR_PROPTITLE_CHECKBOX;
break;
639 case FormComponentType::LISTBOX: pResId = RID_STR_PROPTITLE_LISTBOX;
break;
640 case FormComponentType::COMBOBOX: pResId = RID_STR_PROPTITLE_COMBOBOX;
break;
641 case FormComponentType::GROUPBOX: pResId = RID_STR_PROPTITLE_GROUPBOX;
break;
642 case FormComponentType::IMAGEBUTTON: pResId = RID_STR_PROPTITLE_IMAGEBUTTON;
break;
643 case FormComponentType::FIXEDTEXT: pResId = RID_STR_PROPTITLE_FIXEDTEXT;
break;
644 case FormComponentType::GRIDCONTROL: pResId = RID_STR_PROPTITLE_DBGRID;
break;
645 case FormComponentType::FILECONTROL: pResId = RID_STR_PROPTITLE_FILECONTROL;
break;
646 case FormComponentType::DATEFIELD: pResId = RID_STR_PROPTITLE_DATEFIELD;
break;
647 case FormComponentType::TIMEFIELD: pResId = RID_STR_PROPTITLE_TIMEFIELD;
break;
648 case FormComponentType::NUMERICFIELD: pResId = RID_STR_PROPTITLE_NUMERICFIELD;
break;
649 case FormComponentType::CURRENCYFIELD: pResId = RID_STR_PROPTITLE_CURRENCYFIELD;
break;
650 case FormComponentType::PATTERNFIELD: pResId = RID_STR_PROPTITLE_PATTERNFIELD;
break;
651 case FormComponentType::IMAGECONTROL: pResId = RID_STR_PROPTITLE_IMAGECONTROL;
break;
652 case FormComponentType::HIDDENCONTROL: pResId = RID_STR_PROPTITLE_HIDDEN;
break;
653 case FormComponentType::SCROLLBAR: pResId = RID_STR_PROPTITLE_SCROLLBAR;
break;
654 case FormComponentType::SPINBUTTON: pResId = RID_STR_PROPTITLE_SPINBUTTON;
break;
655 case FormComponentType::NAVIGATIONBAR: pResId = RID_STR_PROPTITLE_NAVBAR;
break;
657 case FormComponentType::TEXTFIELD:
658 pResId = RID_STR_PROPTITLE_EDIT;
660 pResId = RID_STR_PROPTITLE_FORMATTED;
664 pResId = RID_STR_CONTROL;
break;
672 const Reference< XPropertySet >& _rxObject )
674 sal_Int16 nClassId = FormComponentType::CONTROL;
675 OSL_VERIFY( _rxObject->getPropertyValue(
FM_PROP_CLASSID ) >>= nClassId );
676 OUString sBaseName =
getDefaultName( nClassId, Reference< XServiceInfo >( _rxObject, UNO_QUERY ) );
688 OUStringBuffer
aBuf( _rBaseName );
693 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)
std::unique_ptr< char[]> aBuffer