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 {
159 OUStringBuffer aBuffer( _rBaseLabel );
160 aBuffer.append( " " );
161 aBuffer.append( i++ );
162 sLabel = aBuffer.makeStringAndClear();
163 }
164 }
165 catch( const Exception& )
166 {
168 }
169 return sLabel;
170 }
171
172
173 Sequence< PropertyValue > lcl_getDataSourceIndirectProperties( const Reference< XPropertySet >& _rxControlModel,
174 const Reference<XComponentContext>& _rContext )
175 {
176 OSL_PRECOND( _rxControlModel.is(), "lcl_getDataSourceIndirectProperties: invalid model!" );
177
178 Sequence< PropertyValue > aInfo;
179 try
180 {
181 Reference< XChild > xChild( _rxControlModel, UNO_QUERY );
182 Reference< XPropertySet > xForm;
183 if ( xChild.is() )
184 xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
185
186 if ( Reference< XGridColumnFactory >( xForm, UNO_QUERY ).is() )
187 { // hmm. the model is a grid column, in real
188 xChild.set(xForm, css::uno::UNO_QUERY);
189 xForm.set(xChild->getParent(), css::uno::UNO_QUERY);
190 }
191
192 OSL_ENSURE( xForm.is(), "lcl_getDataSourceIndirectProperties: could not determine the form!" );
193 if ( !xForm.is() )
194 return aInfo;
195 OUString sDataSourceName;
196 xForm->getPropertyValue( FM_PROP_DATASOURCE ) >>= sDataSourceName;
197
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;
203 }
204 catch( const Exception& )
205 {
206 TOOLS_WARN_EXCEPTION( "svx", "lcl_getDataSourceIndirectProperties" );
207 }
208 return aInfo;
209 }
210
211
212 const char* aCharacterAndParagraphProperties[] =
213 {
214 "CharFontName",
215 "CharFontStyleName",
216 "CharFontFamily",
217 "CharFontCharSet",
218 "CharFontPitch",
219 "CharColor",
220 "CharEscapement",
221 "CharHeight",
222 "CharUnderline",
223 "CharWeight",
224 "CharPosture",
225 "CharAutoKerning",
226 "CharBackColor",
227 "CharBackTransparent",
228 "CharCaseMap",
229 "CharCrossedOut",
230 "CharFlash",
231 "CharStrikeout",
232 "CharWordMode",
233 "CharKerning",
234 "CharLocale",
235 "CharKeepTogether",
236 "CharNoLineBreak",
237 "CharShadowed",
238 "CharFontType",
239 "CharStyleName",
240 "CharContoured",
241 "CharCombineIsOn",
242 "CharCombinePrefix",
243 "CharCombineSuffix",
244 "CharEmphasize",
245 "CharRelief",
246 "RubyText",
247 "RubyAdjust",
248 "RubyCharStyleName",
249 "RubyIsAbove",
250 "CharRotation",
251 "CharRotationIsFitToLine",
252 "CharScaleWidth",
253 "HyperLinkURL",
254 "HyperLinkTarget",
255 "HyperLinkName",
256 "VisitedCharStyleName",
257 "UnvisitedCharStyleName",
258 "CharEscapementHeight",
259 "CharNoHyphenation",
260 "CharUnderlineColor",
261 "CharUnderlineHasColor",
262 "CharStyleNames",
263 "CharHeightAsian",
264 "CharWeightAsian",
265 "CharFontNameAsian",
266 "CharFontStyleNameAsian",
267 "CharFontFamilyAsian",
268 "CharFontCharSetAsian",
269 "CharFontPitchAsian",
270 "CharPostureAsian",
271 "CharLocaleAsian",
272 "ParaIsCharacterDistance",
273 "ParaIsForbiddenRules",
274 "ParaIsHangingPunctuation",
275 "CharHeightComplex",
276 "CharWeightComplex",
277 "CharFontNameComplex",
278 "CharFontStyleNameComplex",
279 "CharFontFamilyComplex",
280 "CharFontCharSetComplex",
281 "CharFontPitchComplex",
282 "CharPostureComplex",
283 "CharLocaleComplex",
284 "ParaAdjust",
285 "ParaLineSpacing",
286 "ParaBackColor",
287 "ParaBackTransparent",
288 "ParaBackGraphic",
289 "ParaBackGraphicURL",
290 "ParaBackGraphicFilter",
291 "ParaBackGraphicLocation",
292 "ParaLastLineAdjust",
293 "ParaExpandSingleWord",
294 "ParaLeftMargin",
295 "ParaRightMargin",
296 "ParaTopMargin",
297 "ParaBottomMargin",
298 "ParaLineNumberCount",
299 "ParaLineNumberStartValue",
300 "PageDescName",
301 "PageNumberOffset",
302 "ParaRegisterModeActive",
303 "ParaTabStops",
304 "ParaStyleName",
305 "DropCapFormat",
306 "DropCapWholeWord",
307 "ParaKeepTogether",
308 "Setting",
309 "ParaSplit",
310 "Setting",
311 "NumberingLevel",
312 "NumberingRules",
313 "NumberingStartValue",
314 "ParaIsNumberingRestart",
315 "NumberingStyleName",
316 "ParaOrphans",
317 "ParaWidows",
318 "ParaShadowFormat",
319 "LeftBorder",
320 "RightBorder",
321 "TopBorder",
322 "BottomBorder",
323 "BorderDistance",
324 "LeftBorderDistance",
325 "RightBorderDistance",
326 "TopBorderDistance",
327 "BottomBorderDistance",
328 "BreakType",
329 "DropCapCharStyleName",
330 "ParaFirstLineIndent",
331 "ParaIsAutoFirstLineIndent",
332 "ParaIsHyphenation",
333 "ParaHyphenationMaxHyphens",
334 "ParaHyphenationMaxLeadingChars",
335 "ParaHyphenationMaxTrailingChars",
336 "ParaVertAlignment",
337 "ParaUserDefinedAttributes",
338 "NumberingIsNumber",
339 "ParaIsConnectBorder",
340 nullptr
341 };
342
343
344 void lcl_initializeCharacterAttributes( const Reference< XPropertySet >& _rxModel )
345 {
346 try
347 {
348 Reference< XPropertySet > xStyle( ControlLayouter::getDefaultDocumentTextStyle( _rxModel ), UNO_SET_THROW );
349
350 // transfer all properties which are described by the style
351 Reference< XPropertySetInfo > xSourcePropInfo( xStyle->getPropertySetInfo(), UNO_SET_THROW );
352 Reference< XPropertySetInfo > xDestPropInfo( _rxModel->getPropertySetInfo(), UNO_SET_THROW );
353
354 OUString sPropertyName;
355 const char** pCharacterProperty = aCharacterAndParagraphProperties;
356 while ( *pCharacterProperty )
357 {
358 sPropertyName = OUString::createFromAscii( *pCharacterProperty );
359
360 if ( xSourcePropInfo->hasPropertyByName( sPropertyName ) && xDestPropInfo->hasPropertyByName( sPropertyName ) )
361 _rxModel->setPropertyValue( sPropertyName, xStyle->getPropertyValue( sPropertyName ) );
362
363 ++pCharacterProperty;
364 }
365 }
366 catch( const Exception& )
367 {
369 }
370 }
371 }
372
373
374 sal_Int16 FormControlFactory::initializeControlModel( const DocumentType _eDocType, const Reference< XPropertySet >& _rxControlModel,
375 const tools::Rectangle& _rControlBoundRect )
376 {
377 sal_Int16 nClassId = FormComponentType::CONTROL;
378
379 OSL_ENSURE( _rxControlModel.is(), "FormControlFactory::initializeControlModel: invalid model!" );
380 if ( !_rxControlModel.is() )
381 return nClassId;
382
383 try
384 {
385 ControlLayouter::initializeControlLayout( _rxControlModel, _eDocType );
386
387 _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId;
388 Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
389 switch ( nClassId )
390 {
391 case FormComponentType::SCROLLBAR:
392 _rxControlModel->setPropertyValue("LiveScroll", Any( true ) );
393 [[fallthrough]];
394 case FormComponentType::SPINBUTTON:
395 {
396 sal_Int32 eOrientation = ScrollBarOrientation::HORIZONTAL;
397 if ( !_rControlBoundRect.IsEmpty() && ( _rControlBoundRect.GetWidth() < _rControlBoundRect.GetHeight() ) )
398 eOrientation = ScrollBarOrientation::VERTICAL;
399 _rxControlModel->setPropertyValue( FM_PROP_ORIENTATION, Any( eOrientation ) );
400 }
401 break;
402
403 case FormComponentType::LISTBOX:
404 case FormComponentType::COMBOBOX:
405 {
406 bool bDropDown = !_rControlBoundRect.IsEmpty() && ( _rControlBoundRect.GetWidth() >= 3 * _rControlBoundRect.GetHeight() );
407 if ( xPSI->hasPropertyByName( FM_PROP_DROPDOWN ) )
408 _rxControlModel->setPropertyValue( FM_PROP_DROPDOWN, Any( bDropDown ) );
409 _rxControlModel->setPropertyValue( FM_PROP_LINECOUNT, Any( sal_Int16( 20 ) ) );
410 }
411 break;
412
413 case FormComponentType::TEXTFIELD:
414 {
415 initializeTextFieldLineEnds( _rxControlModel );
416 lcl_initializeCharacterAttributes( _rxControlModel );
417
418 if ( !_rControlBoundRect.IsEmpty()
419 && ( _rControlBoundRect.GetWidth() <= 4 * _rControlBoundRect.GetHeight() )
420 )
421 {
422 if ( xPSI->hasPropertyByName( FM_PROP_MULTILINE ) )
423 _rxControlModel->setPropertyValue( FM_PROP_MULTILINE, Any( true ) );
424 }
425 }
426 break;
427
428 case FormComponentType::RADIOBUTTON:
429 case FormComponentType::CHECKBOX:
430 case FormComponentType::FIXEDTEXT:
431 {
432 OUString sVertAlignPropertyName( "VerticalAlign" );
433 if ( xPSI->hasPropertyByName( sVertAlignPropertyName ) )
434 _rxControlModel->setPropertyValue( sVertAlignPropertyName, Any( VerticalAlignment_MIDDLE ) );
435 }
436 break;
437
438 case FormComponentType::IMAGEBUTTON:
439 case FormComponentType::IMAGECONTROL:
440 {
441 static const OUStringLiteral sScaleModeProperty( u"ScaleMode" );
442 if ( xPSI->hasPropertyByName( sScaleModeProperty ) )
443 _rxControlModel->setPropertyValue( sScaleModeProperty, Any( ImageScaleMode::ISOTROPIC ) );
444 }
445 break;
446 }
447
448 // initial default label for the control
449 if ( xPSI->hasPropertyByName( FM_PROP_LABEL ) )
450 {
451 OUString sExistingLabel;
452 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_LABEL ) >>= sExistingLabel );
453 if ( sExistingLabel.isEmpty() )
454 {
455 OUString sInitialLabel;
456 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_NAME ) >>= sInitialLabel );
457
458 TranslateId pTitleResId;
459 switch ( nClassId )
460 {
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;
466 }
467
468 if (pTitleResId)
469 sInitialLabel = SvxResId(pTitleResId);
470
471 _rxControlModel->setPropertyValue(
473 Any( lcl_getUniqueLabel_nothrow( _rxControlModel, sInitialLabel ) )
474 );
475 }
476 }
477
478 // strict format = yes is the default (i93467)
479 if ( xPSI->hasPropertyByName( FM_PROP_STRICTFORMAT ) )
480 {
481 _rxControlModel->setPropertyValue( FM_PROP_STRICTFORMAT, Any( true ) );
482 }
483
484 // mouse wheel: don't use it for scrolling by default (i110036)
485 if ( xPSI->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) )
486 {
487 _rxControlModel->setPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR, Any( MouseWheelBehavior::SCROLL_DISABLED ) );
488 }
489
490 if ( xPSI->hasPropertyByName( FM_PROP_WRITING_MODE ) )
491 _rxControlModel->setPropertyValue( FM_PROP_WRITING_MODE, Any( WritingMode2::CONTEXT ) );
492 }
493 catch( const Exception& )
494 {
496 }
497 return nClassId;
498 }
499
500
501 void FormControlFactory::initializeTextFieldLineEnds( const Reference< XPropertySet >& _rxModel )
502 {
503 OSL_PRECOND( _rxModel.is(), "initializeTextFieldLineEnds: invalid model!" );
504 if ( !_rxModel.is() )
505 return;
506
507 try
508 {
509 Reference< XPropertySetInfo > xInfo = _rxModel->getPropertySetInfo();
510 if ( !xInfo.is() || !xInfo->hasPropertyByName( FM_PROP_LINEENDFORMAT ) )
511 return;
512
513 // let's see if the data source which the form belongs to (if any)
514 // has a setting for the preferred line end format
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;
521
522 sal_Int16 nLineEndFormat = bDosLineEnds ? LineEndFormat::CARRIAGE_RETURN_LINE_FEED : LineEndFormat::LINE_FEED;
523 _rxModel->setPropertyValue( FM_PROP_LINEENDFORMAT, Any( nLineEndFormat ) );
524 }
525 catch( const Exception& )
526 {
528 }
529 }
530
531
532 void FormControlFactory::initializeFieldDependentProperties( const Reference< XPropertySet >& _rxDatabaseField,
533 const Reference< XPropertySet >& _rxControlModel, const Reference< XNumberFormats >& _rxNumberFormats )
534 {
535 OSL_PRECOND( _rxDatabaseField.is() && _rxControlModel.is(),
536 "FormControlFactory::initializeFieldDependentProperties: illegal params!" );
537 if ( !_rxDatabaseField.is() || !_rxControlModel.is() )
538 return;
539
540 try
541 {
542
543 // if the field has a numeric format, and the model has a "Scale" property, sync it
544 Reference< XPropertySetInfo > xFieldPSI( _rxDatabaseField->getPropertySetInfo(), UNO_SET_THROW );
545 Reference< XPropertySetInfo > xModelPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
546
547 if ( xModelPSI->hasPropertyByName( FM_PROP_DECIMAL_ACCURACY ) )
548 {
549 sal_Int32 nFormatKey = 0;
550 if ( xFieldPSI->hasPropertyByName( FM_PROP_FORMATKEY ) )
551 {
552 _rxDatabaseField->getPropertyValue( FM_PROP_FORMATKEY ) >>= nFormatKey;
553 }
554 else
555 {
556 nFormatKey = getDefaultNumberFormat(
557 _rxDatabaseField,
558 Reference< XNumberFormatTypes >( _rxNumberFormats, UNO_QUERY ),
559 SvtSysLocale().GetLanguageTag().getLocale()
560 );
561 }
562
563 Any aScaleVal( ::comphelper::getNumberFormatDecimals( _rxNumberFormats, nFormatKey ) );
564 _rxControlModel->setPropertyValue( FM_PROP_DECIMAL_ACCURACY, aScaleVal );
565 }
566
567
568 // minimum and maximum of the control according to the type of the database field
569 sal_Int32 nDataType = DataType::OTHER;
570 OSL_VERIFY( _rxDatabaseField->getPropertyValue( FM_PROP_FIELDTYPE ) >>= nDataType );
571
572 if ( xModelPSI->hasPropertyByName( FM_PROP_VALUEMIN )
573 && xModelPSI->hasPropertyByName( FM_PROP_VALUEMAX )
574 )
575 {
576 sal_Int32 nMinValue = -1000000000, nMaxValue = 1000000000;
577 switch ( nDataType )
578 {
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;
582 // double and singles are ignored
583 }
584
585 Any aValue;
586
587 // both the minimum and the maximum value properties can be either Long or Double
588 Property aProperty = xModelPSI->getPropertyByName( FM_PROP_VALUEMIN );
589 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
590 aValue <<= static_cast<double>(nMinValue);
591 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
592 aValue <<= nMinValue;
593 else
594 {
595 OSL_FAIL( "FormControlFactory::initializeFieldDependentProperties: unexpected property type (MinValue)!" );
596 }
597 _rxControlModel->setPropertyValue( FM_PROP_VALUEMIN, aValue );
598
599 // both the minimum and the maximum value properties can be either Long or Double
600 aProperty = xModelPSI->getPropertyByName( FM_PROP_VALUEMAX );
601 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
602 aValue <<= static_cast<double>(nMaxValue);
603 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
604 aValue <<= nMaxValue;
605 else
606 {
607 OSL_FAIL( "FormControlFactory::initializeFieldDependentProperties: unexpected property type (MaxValue)!" );
608 }
609 _rxControlModel->setPropertyValue( FM_PROP_VALUEMAX, aValue );
610 }
611
612
613 // a check box can be tristate if and only if the column it is bound to is nullable
614 sal_Int16 nClassId = FormComponentType::CONTROL;
615 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId );
616 if ( nClassId == FormComponentType::CHECKBOX )
617 {
618 sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN;
619 OSL_VERIFY( _rxDatabaseField->getPropertyValue( FM_PROP_ISNULLABLE ) >>= nNullable );
620 _rxControlModel->setPropertyValue( FM_PROP_TRISTATE, Any( ColumnValue::NO_NULLS != nNullable ) );
621 }
622 }
623 catch( const Exception& )
624 {
626 }
627 }
628
629
630 OUString FormControlFactory::getDefaultName( sal_Int16 _nClassId, const Reference< XServiceInfo >& _rxObject )
631 {
632 TranslateId pResId;
633
634 switch ( _nClassId )
635 {
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;
656
657 case FormComponentType::TEXTFIELD:
658 pResId = RID_STR_PROPTITLE_EDIT;
659 if ( _rxObject.is() && _rxObject->supportsService( FM_SUN_COMPONENT_FORMATTEDFIELD ) )
660 pResId = RID_STR_PROPTITLE_FORMATTED;
661 break;
662
663 default:
664 pResId = RID_STR_CONTROL; break;
665 }
666
667 return SvxResId(pResId);
668 }
669
670
671 OUString FormControlFactory::getDefaultUniqueName_ByComponentType( const Reference< XNameAccess >& _rxContainer,
672 const Reference< XPropertySet >& _rxObject )
673 {
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 ) );
677
678 return getUniqueName( _rxContainer, sBaseName );
679 }
680
681
682 OUString FormControlFactory::getUniqueName( const Reference< XNameAccess >& _rxContainer, std::u16string_view _rBaseName )
683 {
684 sal_Int32 n = 0;
685 OUString sName;
686 do
687 {
688 OUStringBuffer aBuf( _rBaseName );
689 aBuf.append( " " );
690 aBuf.append( ++n );
691 sName = aBuf.makeStringAndClear();
692 }
693 while ( _rxContainer->hasByName( sName ) );
694
695 return sName;
696 }
697
698
699}
700
701
702/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nDataType
Reference< XComponentContext > m_xContext
virtual const tools::Rectangle & GetCurrentBoundRect() const
Definition: svdobj.cxx:926
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
aBuf
std::set< OUString > StringBag
@ Exception
class SAL_NO_VTABLE XPropertySet
Definition: xmlexchg.hxx:28
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
std::unique_ptr< char[]> aBuffer