LibreOffice Module svx (master) 1
formcontrolfactory.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
22#include <fmcontrollayout.hxx>
23#include <fmprop.hxx>
24#include <svx/strings.hrc>
25#include <fmservs.hxx>
26#include <svx/dialmgr.hxx>
27#include <svx/svdouno.hxx>
28
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>
42
46#include <tools/gen.hxx>
50
51#include <set>
52
53using namespace ::dbtools;
54
55namespace svxform
56{
57
58
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;
82
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;
91
92 FormControlFactory::FormControlFactory( const Reference<XComponentContext>& _rContext )
93 :m_xContext( _rContext )
94 {
95 }
96
97 FormControlFactory::FormControlFactory( )
99 {
100 }
101
102
104 {
105 }
106
107
108 sal_Int16 FormControlFactory::initializeControlModel( const DocumentType _eDocType, const SdrUnoObj& _rObject )
109 {
111 _eDocType,
112 Reference< XPropertySet >( _rObject.GetUnoControlModel(), UNO_QUERY ),
113 _rObject.GetCurrentBoundRect()
114 );
115 }
116
117
118 void FormControlFactory::initializeControlModel( const DocumentType _eDocType, const Reference< XPropertySet >& _rxControlModel )
119 {
121 _eDocType, _rxControlModel, tools::Rectangle()
122 );
123 }
124
125
126 namespace
127 {
128
129 OUString lcl_getUniqueLabel_nothrow( const Reference< XPropertySet >& _rxControlModel, const OUString& _rBaseLabel )
130 {
131 OUString sLabel( _rBaseLabel );
132 try
133 {
134 typedef ::std::set< OUString > StringBag;
135 StringBag aUsedLabels;
136
137 Reference< XFormComponent > xFormComponent( _rxControlModel, UNO_QUERY_THROW );
138 Reference< XIndexAccess > xContainer( xFormComponent->getParent(), UNO_QUERY_THROW );
139 // loop through all siblings of the control model, and collect their labels
140 for ( sal_Int32 index=xContainer->getCount(); index>0; )
141 {
142 Reference< XPropertySet > xElement( xContainer->getByIndex( --index ), UNO_QUERY_THROW );
143 if ( xElement == _rxControlModel )
144 continue;
145
146 Reference< XPropertySetInfo > xPSI( xElement->getPropertySetInfo(), UNO_SET_THROW );
147 if ( !xPSI->hasPropertyByName( FM_PROP_LABEL ) )
148 continue;
149
150 OUString sElementLabel;
151 OSL_VERIFY( xElement->getPropertyValue( FM_PROP_LABEL ) >>= sElementLabel );
152 aUsedLabels.insert( sElementLabel );
153 }
154
155 // now find a free label
156 sal_Int32 i=2;
157 while ( aUsedLabels.find( sLabel ) != aUsedLabels.end() )
158 sLabel = _rBaseLabel + " " + OUString::number( i++ );
159 }
160 catch( const Exception& )
161 {
163 }
164 return sLabel;
165 }
166
167
168 Sequence< PropertyValue > lcl_getDataSourceIndirectProperties( const Reference< XPropertySet >& _rxControlModel,
169 const Reference<XComponentContext>& _rContext )
170 {
171 OSL_PRECOND( _rxControlModel.is(), "lcl_getDataSourceIndirectProperties: invalid model!" );
172
173 Sequence< PropertyValue > aInfo;
174 try
175 {
176 Reference< XChild > xChild( _rxControlModel, UNO_QUERY );
177 Reference< XPropertySet > xForm;
178 if ( xChild.is() )
179 xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
180
181 if ( Reference< XGridColumnFactory >( xForm, UNO_QUERY ).is() )
182 { // hmm. the model is a grid column, in real
183 xChild.set(xForm, css::uno::UNO_QUERY);
184 xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
185 }
186
187 OSL_ENSURE( xForm.is(), "lcl_getDataSourceIndirectProperties: could not determine the form!" );
188 if ( !xForm.is() )
189 return aInfo;
190 OUString sDataSourceName;
191 xForm->getPropertyValue( FM_PROP_DATASOURCE ) >>= sDataSourceName;
192
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;
198 }
199 catch( const Exception& )
200 {
201 TOOLS_WARN_EXCEPTION( "svx", "lcl_getDataSourceIndirectProperties" );
202 }
203 return aInfo;
204 }
205
206
207 const char* aCharacterAndParagraphProperties[] =
208 {
209 "CharFontName",
210 "CharFontStyleName",
211 "CharFontFamily",
212 "CharFontCharSet",
213 "CharFontPitch",
214 "CharColor",
215 "CharEscapement",
216 "CharHeight",
217 "CharUnderline",
218 "CharWeight",
219 "CharPosture",
220 "CharAutoKerning",
221 "CharBackColor",
222 "CharBackTransparent",
223 "CharCaseMap",
224 "CharCrossedOut",
225 "CharFlash",
226 "CharStrikeout",
227 "CharWordMode",
228 "CharKerning",
229 "CharLocale",
230 "CharKeepTogether",
231 "CharNoLineBreak",
232 "CharShadowed",
233 "CharFontType",
234 "CharStyleName",
235 "CharContoured",
236 "CharCombineIsOn",
237 "CharCombinePrefix",
238 "CharCombineSuffix",
239 "CharEmphasize",
240 "CharRelief",
241 "RubyText",
242 "RubyAdjust",
243 "RubyCharStyleName",
244 "RubyIsAbove",
245 "CharRotation",
246 "CharRotationIsFitToLine",
247 "CharScaleWidth",
248 "HyperLinkURL",
249 "HyperLinkTarget",
250 "HyperLinkName",
251 "VisitedCharStyleName",
252 "UnvisitedCharStyleName",
253 "CharEscapementHeight",
254 "CharNoHyphenation",
255 "CharUnderlineColor",
256 "CharUnderlineHasColor",
257 "CharStyleNames",
258 "CharHeightAsian",
259 "CharWeightAsian",
260 "CharFontNameAsian",
261 "CharFontStyleNameAsian",
262 "CharFontFamilyAsian",
263 "CharFontCharSetAsian",
264 "CharFontPitchAsian",
265 "CharPostureAsian",
266 "CharLocaleAsian",
267 "ParaIsCharacterDistance",
268 "ParaIsForbiddenRules",
269 "ParaIsHangingPunctuation",
270 "CharHeightComplex",
271 "CharWeightComplex",
272 "CharFontNameComplex",
273 "CharFontStyleNameComplex",
274 "CharFontFamilyComplex",
275 "CharFontCharSetComplex",
276 "CharFontPitchComplex",
277 "CharPostureComplex",
278 "CharLocaleComplex",
279 "ParaAdjust",
280 "ParaLineSpacing",
281 "ParaBackColor",
282 "ParaBackTransparent",
283 "ParaBackGraphic",
284 "ParaBackGraphicURL",
285 "ParaBackGraphicFilter",
286 "ParaBackGraphicLocation",
287 "ParaLastLineAdjust",
288 "ParaExpandSingleWord",
289 "ParaLeftMargin",
290 "ParaRightMargin",
291 "ParaTopMargin",
292 "ParaBottomMargin",
293 "ParaLineNumberCount",
294 "ParaLineNumberStartValue",
295 "PageDescName",
296 "PageNumberOffset",
297 "ParaRegisterModeActive",
298 "ParaTabStops",
299 "ParaStyleName",
300 "DropCapFormat",
301 "DropCapWholeWord",
302 "ParaKeepTogether",
303 "Setting",
304 "ParaSplit",
305 "Setting",
306 "NumberingLevel",
307 "NumberingRules",
308 "NumberingStartValue",
309 "ParaIsNumberingRestart",
310 "NumberingStyleName",
311 "ParaOrphans",
312 "ParaWidows",
313 "ParaShadowFormat",
314 "LeftBorder",
315 "RightBorder",
316 "TopBorder",
317 "BottomBorder",
318 "BorderDistance",
319 "LeftBorderDistance",
320 "RightBorderDistance",
321 "TopBorderDistance",
322 "BottomBorderDistance",
323 "BreakType",
324 "DropCapCharStyleName",
325 "ParaFirstLineIndent",
326 "ParaIsAutoFirstLineIndent",
327 "ParaIsHyphenation",
328 "ParaHyphenationMaxHyphens",
329 "ParaHyphenationMaxLeadingChars",
330 "ParaHyphenationMaxTrailingChars",
331 "ParaVertAlignment",
332 "ParaUserDefinedAttributes",
333 "NumberingIsNumber",
334 "ParaIsConnectBorder",
335 nullptr
336 };
337
338
339 void lcl_initializeCharacterAttributes( const Reference< XPropertySet >& _rxModel )
340 {
341 try
342 {
343 Reference< XPropertySet > xStyle( ControlLayouter::getDefaultDocumentTextStyle( _rxModel ), UNO_SET_THROW );
344
345 // transfer all properties which are described by the style
346 Reference< XPropertySetInfo > xSourcePropInfo( xStyle->getPropertySetInfo(), UNO_SET_THROW );
347 Reference< XPropertySetInfo > xDestPropInfo( _rxModel->getPropertySetInfo(), UNO_SET_THROW );
348
349 OUString sPropertyName;
350 const char** pCharacterProperty = aCharacterAndParagraphProperties;
351 while ( *pCharacterProperty )
352 {
353 sPropertyName = OUString::createFromAscii( *pCharacterProperty );
354
355 if ( xSourcePropInfo->hasPropertyByName( sPropertyName ) && xDestPropInfo->hasPropertyByName( sPropertyName ) )
356 _rxModel->setPropertyValue( sPropertyName, xStyle->getPropertyValue( sPropertyName ) );
357
358 ++pCharacterProperty;
359 }
360 }
361 catch( const Exception& )
362 {
364 }
365 }
366 }
367
368
369 sal_Int16 FormControlFactory::initializeControlModel( const DocumentType _eDocType, const Reference< XPropertySet >& _rxControlModel,
370 const tools::Rectangle& _rControlBoundRect )
371 {
372 sal_Int16 nClassId = FormComponentType::CONTROL;
373
374 OSL_ENSURE( _rxControlModel.is(), "FormControlFactory::initializeControlModel: invalid model!" );
375 if ( !_rxControlModel.is() )
376 return nClassId;
377
378 try
379 {
380 ControlLayouter::initializeControlLayout( _rxControlModel, _eDocType );
381
382 _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId;
383 Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
384 switch ( nClassId )
385 {
386 case FormComponentType::SCROLLBAR:
387 _rxControlModel->setPropertyValue("LiveScroll", Any( true ) );
388 [[fallthrough]];
389 case FormComponentType::SPINBUTTON:
390 {
391 sal_Int32 eOrientation = ScrollBarOrientation::HORIZONTAL;
392 if ( !_rControlBoundRect.IsEmpty() && ( _rControlBoundRect.GetWidth() < _rControlBoundRect.GetHeight() ) )
393 eOrientation = ScrollBarOrientation::VERTICAL;
394 _rxControlModel->setPropertyValue( FM_PROP_ORIENTATION, Any( eOrientation ) );
395 }
396 break;
397
398 case FormComponentType::LISTBOX:
399 case FormComponentType::COMBOBOX:
400 {
401 bool bDropDown = !_rControlBoundRect.IsEmpty() && ( _rControlBoundRect.GetWidth() >= 3 * _rControlBoundRect.GetHeight() );
402 if ( xPSI->hasPropertyByName( FM_PROP_DROPDOWN ) )
403 _rxControlModel->setPropertyValue( FM_PROP_DROPDOWN, Any( bDropDown ) );
404 _rxControlModel->setPropertyValue( FM_PROP_LINECOUNT, Any( sal_Int16( 20 ) ) );
405 }
406 break;
407
408 case FormComponentType::TEXTFIELD:
409 {
410 initializeTextFieldLineEnds( _rxControlModel );
411 lcl_initializeCharacterAttributes( _rxControlModel );
412
413 if ( !_rControlBoundRect.IsEmpty()
414 && ( _rControlBoundRect.GetWidth() <= 4 * _rControlBoundRect.GetHeight() )
415 )
416 {
417 if ( xPSI->hasPropertyByName( FM_PROP_MULTILINE ) )
418 _rxControlModel->setPropertyValue( FM_PROP_MULTILINE, Any( true ) );
419 }
420 }
421 break;
422
423 case FormComponentType::RADIOBUTTON:
424 case FormComponentType::CHECKBOX:
425 case FormComponentType::FIXEDTEXT:
426 {
427 OUString sVertAlignPropertyName( "VerticalAlign" );
428 if ( xPSI->hasPropertyByName( sVertAlignPropertyName ) )
429 _rxControlModel->setPropertyValue( sVertAlignPropertyName, Any( VerticalAlignment_MIDDLE ) );
430 }
431 break;
432
433 case FormComponentType::IMAGEBUTTON:
434 case FormComponentType::IMAGECONTROL:
435 {
436 static constexpr OUStringLiteral sScaleModeProperty( u"ScaleMode" );
437 if ( xPSI->hasPropertyByName( sScaleModeProperty ) )
438 _rxControlModel->setPropertyValue( sScaleModeProperty, Any( ImageScaleMode::ISOTROPIC ) );
439 }
440 break;
441 }
442
443 // initial default label for the control
444 if ( xPSI->hasPropertyByName( FM_PROP_LABEL ) )
445 {
446 OUString sExistingLabel;
447 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_LABEL ) >>= sExistingLabel );
448 if ( sExistingLabel.isEmpty() )
449 {
450 OUString sInitialLabel;
451 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_NAME ) >>= sInitialLabel );
452
453 TranslateId pTitleResId;
454 switch ( nClassId )
455 {
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;
461 }
462
463 if (pTitleResId)
464 sInitialLabel = SvxResId(pTitleResId);
465
466 _rxControlModel->setPropertyValue(
468 Any( lcl_getUniqueLabel_nothrow( _rxControlModel, sInitialLabel ) )
469 );
470 }
471 }
472
473 // strict format = yes is the default (i93467)
474 if ( xPSI->hasPropertyByName( FM_PROP_STRICTFORMAT ) )
475 {
476 _rxControlModel->setPropertyValue( FM_PROP_STRICTFORMAT, Any( true ) );
477 }
478
479 // mouse wheel: don't use it for scrolling by default (i110036)
480 if ( xPSI->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) )
481 {
482 _rxControlModel->setPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR, Any( MouseWheelBehavior::SCROLL_DISABLED ) );
483 }
484
485 if ( xPSI->hasPropertyByName( FM_PROP_WRITING_MODE ) )
486 _rxControlModel->setPropertyValue( FM_PROP_WRITING_MODE, Any( WritingMode2::CONTEXT ) );
487 }
488 catch( const Exception& )
489 {
491 }
492 return nClassId;
493 }
494
495
496 void FormControlFactory::initializeTextFieldLineEnds( const Reference< XPropertySet >& _rxModel )
497 {
498 OSL_PRECOND( _rxModel.is(), "initializeTextFieldLineEnds: invalid model!" );
499 if ( !_rxModel.is() )
500 return;
501
502 try
503 {
504 Reference< XPropertySetInfo > xInfo = _rxModel->getPropertySetInfo();
505 if ( !xInfo.is() || !xInfo->hasPropertyByName( FM_PROP_LINEENDFORMAT ) )
506 return;
507
508 // let's see if the data source which the form belongs to (if any)
509 // has a setting for the preferred line end format
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;
516
517 sal_Int16 nLineEndFormat = bDosLineEnds ? LineEndFormat::CARRIAGE_RETURN_LINE_FEED : LineEndFormat::LINE_FEED;
518 _rxModel->setPropertyValue( FM_PROP_LINEENDFORMAT, Any( nLineEndFormat ) );
519 }
520 catch( const Exception& )
521 {
523 }
524 }
525
526
527 void FormControlFactory::initializeFieldDependentProperties( const Reference< XPropertySet >& _rxDatabaseField,
528 const Reference< XPropertySet >& _rxControlModel, const Reference< XNumberFormats >& _rxNumberFormats )
529 {
530 OSL_PRECOND( _rxDatabaseField.is() && _rxControlModel.is(),
531 "FormControlFactory::initializeFieldDependentProperties: illegal params!" );
532 if ( !_rxDatabaseField.is() || !_rxControlModel.is() )
533 return;
534
535 try
536 {
537
538 // if the field has a numeric format, and the model has a "Scale" property, sync it
539 Reference< XPropertySetInfo > xFieldPSI( _rxDatabaseField->getPropertySetInfo(), UNO_SET_THROW );
540 Reference< XPropertySetInfo > xModelPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
541
542 if ( xModelPSI->hasPropertyByName( FM_PROP_DECIMAL_ACCURACY ) )
543 {
544 sal_Int32 nFormatKey = 0;
545 if ( xFieldPSI->hasPropertyByName( FM_PROP_FORMATKEY ) )
546 {
547 _rxDatabaseField->getPropertyValue( FM_PROP_FORMATKEY ) >>= nFormatKey;
548 }
549 else
550 {
551 nFormatKey = getDefaultNumberFormat(
552 _rxDatabaseField,
553 Reference< XNumberFormatTypes >( _rxNumberFormats, UNO_QUERY ),
554 SvtSysLocale().GetLanguageTag().getLocale()
555 );
556 }
557
558 Any aScaleVal( ::comphelper::getNumberFormatDecimals( _rxNumberFormats, nFormatKey ) );
559 _rxControlModel->setPropertyValue( FM_PROP_DECIMAL_ACCURACY, aScaleVal );
560 }
561
562
563 // minimum and maximum of the control according to the type of the database field
564 sal_Int32 nDataType = DataType::OTHER;
565 OSL_VERIFY( _rxDatabaseField->getPropertyValue( FM_PROP_FIELDTYPE ) >>= nDataType );
566
567 if ( xModelPSI->hasPropertyByName( FM_PROP_VALUEMIN )
568 && xModelPSI->hasPropertyByName( FM_PROP_VALUEMAX )
569 )
570 {
571 sal_Int32 nMinValue = -1000000000, nMaxValue = 1000000000;
572 switch ( nDataType )
573 {
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;
577 // double and singles are ignored
578 }
579
580 Any aValue;
581
582 // both the minimum and the maximum value properties can be either Long or Double
583 Property aProperty = xModelPSI->getPropertyByName( FM_PROP_VALUEMIN );
584 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
585 aValue <<= static_cast<double>(nMinValue);
586 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
587 aValue <<= nMinValue;
588 else
589 {
590 OSL_FAIL( "FormControlFactory::initializeFieldDependentProperties: unexpected property type (MinValue)!" );
591 }
592 _rxControlModel->setPropertyValue( FM_PROP_VALUEMIN, aValue );
593
594 // both the minimum and the maximum value properties can be either Long or Double
595 aProperty = xModelPSI->getPropertyByName( FM_PROP_VALUEMAX );
596 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
597 aValue <<= static_cast<double>(nMaxValue);
598 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
599 aValue <<= nMaxValue;
600 else
601 {
602 OSL_FAIL( "FormControlFactory::initializeFieldDependentProperties: unexpected property type (MaxValue)!" );
603 }
604 _rxControlModel->setPropertyValue( FM_PROP_VALUEMAX, aValue );
605 }
606
607
608 // a check box can be tristate if and only if the column it is bound to is nullable
609 sal_Int16 nClassId = FormComponentType::CONTROL;
610 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId );
611 if ( nClassId == FormComponentType::CHECKBOX )
612 {
613 sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN;
614 OSL_VERIFY( _rxDatabaseField->getPropertyValue( FM_PROP_ISNULLABLE ) >>= nNullable );
615 _rxControlModel->setPropertyValue( FM_PROP_TRISTATE, Any( ColumnValue::NO_NULLS != nNullable ) );
616 }
617 }
618 catch( const Exception& )
619 {
621 }
622 }
623
624
625 OUString FormControlFactory::getDefaultName( sal_Int16 _nClassId, const Reference< XServiceInfo >& _rxObject )
626 {
627 TranslateId pResId;
628
629 switch ( _nClassId )
630 {
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;
651
652 case FormComponentType::TEXTFIELD:
653 pResId = RID_STR_PROPTITLE_EDIT;
654 if ( _rxObject.is() && _rxObject->supportsService( FM_SUN_COMPONENT_FORMATTEDFIELD ) )
655 pResId = RID_STR_PROPTITLE_FORMATTED;
656 break;
657
658 default:
659 pResId = RID_STR_CONTROL; break;
660 }
661
662 return SvxResId(pResId);
663 }
664
665
666 OUString FormControlFactory::getDefaultUniqueName_ByComponentType( const Reference< XNameAccess >& _rxContainer,
667 const Reference< XPropertySet >& _rxObject )
668 {
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 ) );
672
673 return getUniqueName( _rxContainer, sBaseName );
674 }
675
676
677 OUString FormControlFactory::getUniqueName( const Reference< XNameAccess >& _rxContainer, std::u16string_view _rBaseName )
678 {
679 sal_Int32 n = 0;
680 OUString sName;
681 do
682 {
683 sName = OUString::Concat(_rBaseName) + " " + OUString::number( ++n );
684 }
685 while ( _rxContainer->hasByName( sName ) );
686
687 return sName;
688 }
689
690
691}
692
693
694/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nDataType
Reference< XComponentContext > m_xContext
virtual const tools::Rectangle & GetCurrentBoundRect() const
Definition: svdobj.cxx:962
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
Definition: svdouno.hxx:88
static void initializeFieldDependentProperties(const css::uno::Reference< css::beans::XPropertySet > &_rxDatabaseField, const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const css::uno::Reference< css::util::XNumberFormats > &_rxNumberFormats)
static OUString getDefaultUniqueName_ByComponentType(const css::uno::Reference< css::container::XNameAccess > &_rxContainer, const css::uno::Reference< css::beans::XPropertySet > &_rxObject)
sal_Int16 initializeControlModel(const DocumentType _eDocType, const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const tools::Rectangle &_rControlBoundRect)
initializes the given control model which is to be newly inserted into a document
static OUString getUniqueName(const css::uno::Reference< css::container::XNameAccess > &_rxContainer, std::u16string_view _rBaseName)
void initializeTextFieldLineEnds(const css::uno::Reference< css::beans::XPropertySet > &_rxModel)
static OUString getDefaultName(const sal_Int16 nClassId, const css::uno::Reference< css::lang::XServiceInfo > &_rxObject)
css::uno::Reference< css::uno::XComponentContext > m_xContext
constexpr tools::Long GetWidth() const
constexpr tools::Long GetHeight() const
constexpr bool IsEmpty() const
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
constexpr OUStringLiteral FM_PROP_DECIMAL_ACCURACY
Definition: fmprop.hxx:74
constexpr OUStringLiteral FM_PROP_ISNULLABLE
Definition: fmprop.hxx:126
constexpr OUStringLiteral FM_PROP_CLASSID
Definition: fmprop.hxx:32
constexpr OUStringLiteral FM_PROP_MULTILINE
Definition: fmprop.hxx:53
constexpr OUStringLiteral FM_PROP_LABEL
Definition: fmprop.hxx:42
constexpr OUStringLiteral FM_PROP_LINEENDFORMAT
Definition: fmprop.hxx:137
constexpr OUStringLiteral FM_PROP_NAME
Definition: fmprop.hxx:31
constexpr OUStringLiteral FM_PROP_VALUEMIN
Definition: fmprop.hxx:38
constexpr OUStringLiteral FM_PROP_WRITING_MODE
Definition: fmprop.hxx:147
constexpr OUStringLiteral FM_PROP_LINECOUNT
Definition: fmprop.hxx:91
constexpr OUStringLiteral FM_PROP_STRICTFORMAT
Definition: fmprop.hxx:79
constexpr OUStringLiteral FM_PROP_MOUSE_WHEEL_BEHAVIOR
Definition: fmprop.hxx:148
constexpr OUStringLiteral FM_PROP_ORIENTATION
Definition: fmprop.hxx:136
constexpr OUStringLiteral FM_PROP_DROPDOWN
Definition: fmprop.hxx:98
constexpr OUStringLiteral FM_PROP_VALUEMAX
Definition: fmprop.hxx:39
constexpr OUStringLiteral FM_PROP_FORMATKEY
Definition: fmprop.hxx:67
constexpr OUStringLiteral FM_PROP_TRISTATE
Definition: fmprop.hxx:60
constexpr OUStringLiteral FM_PROP_FIELDTYPE
Definition: fmprop.hxx:77
constexpr OUStringLiteral FM_PROP_DATASOURCE
Definition: fmprop.hxx:80
constexpr OUStringLiteral FM_SUN_COMPONENT_FORMATTEDFIELD
Definition: fmservs.hxx:73
OUString sName
sal_Int32 nNullable
sal_Int64 n
std::set< OUString > StringBag
@ Exception
class SAL_NO_VTABLE XPropertySet
Definition: xmlexchg.hxx:29
const LanguageTag & getLocale()
class SvxPropertySetInfoPool
Reference< XComponentContext > getProcessComponentContext()
css::uno::Reference< css::uno::XInterface > getDataSource(const css::uno::Reference< css::uno::XInterface > &_rxDependentObject)
sal_Int32 getDefaultNumberFormat(const Reference< XPropertySet > &_xColumn, const Reference< XNumberFormatTypes > &_xTypes, const Locale &_rLocale)
int i
DataType
css::uno::Reference< css::beans::XPropertySet > getDefaultDocumentTextStyle(const css::uno::Reference< css::beans::XPropertySet > &_rxModel)
gets the "default" style in a document which can be used if some default text format is needed
void initializeControlLayout(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, DocumentType _eDocType)
initializes the layout of a newly created form control (model)
class FmSearchEngine - Impl class for FmSearchDialog
DocumentType