fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / form / formcontrolfactory.cxx
blob5197304149c6228f3a9c606a55f976ea65007104
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "svx/dbtoolsclient.hxx"
22 #include "formcontrolfactory.hxx"
23 #include "fmcontrollayout.hxx"
24 #include "fmprop.hrc"
25 #include "svx/fmresids.hrc"
26 #include "fmservs.hxx"
27 #include "svx/dialmgr.hxx"
28 #include "svx/svdouno.hxx"
30 #include <com/sun/star/form/XFormComponent.hpp>
31 #include <com/sun/star/form/FormComponentType.hpp>
32 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
33 #include <com/sun/star/awt/MouseWheelBehavior.hpp>
34 #include <com/sun/star/form/XGridColumnFactory.hpp>
35 #include <com/sun/star/style/VerticalAlignment.hpp>
36 #include <com/sun/star/awt/LineEndFormat.hpp>
37 #include <com/sun/star/awt/ImageScaleMode.hpp>
38 #include <com/sun/star/sdbc/DataType.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 #include <com/sun/star/awt/FontDescriptor.hpp>
44 #include <comphelper/componentcontext.hxx>
45 #include <comphelper/numbers.hxx>
46 #include <unotools/syslocale.hxx>
47 #include <tools/gen.hxx>
48 #include <tools/diagnose_ex.h>
50 #include <set>
52 //........................................................................
53 namespace svxform
55 //........................................................................
57 using ::com::sun::star::uno::Reference;
58 using ::com::sun::star::uno::XInterface;
59 using ::com::sun::star::uno::UNO_QUERY;
60 using ::com::sun::star::uno::UNO_QUERY_THROW;
61 using ::com::sun::star::uno::UNO_SET_THROW;
62 using ::com::sun::star::uno::Exception;
63 using ::com::sun::star::uno::RuntimeException;
64 using ::com::sun::star::uno::Any;
65 using ::com::sun::star::uno::makeAny;
66 using ::com::sun::star::uno::Sequence;
67 using ::com::sun::star::uno::Type;
68 using ::com::sun::star::beans::XPropertySet;
69 using ::com::sun::star::awt::XControlModel;
70 using ::com::sun::star::form::XFormComponent;
71 using ::com::sun::star::container::XIndexAccess;
72 using ::com::sun::star::beans::XPropertySetInfo;
73 using ::com::sun::star::beans::PropertyValue;
74 using ::com::sun::star::container::XChild;
75 using ::com::sun::star::form::XGridColumnFactory;
76 using ::com::sun::star::style::VerticalAlignment_MIDDLE;
77 using ::com::sun::star::beans::Property;
78 using ::com::sun::star::uno::TypeClass_DOUBLE;
79 using ::com::sun::star::uno::TypeClass_LONG;
80 using ::com::sun::star::util::XNumberFormats;
81 using ::com::sun::star::util::XNumberFormatTypes;
82 using ::com::sun::star::awt::FontDescriptor;
83 using ::com::sun::star::lang::Locale;
84 using ::com::sun::star::lang::XServiceInfo;
85 using ::com::sun::star::container::XNameAccess;
87 namespace FormComponentType = ::com::sun::star::form::FormComponentType;
88 namespace ScrollBarOrientation = ::com::sun::star::awt::ScrollBarOrientation;
89 namespace MouseWheelBehavior = ::com::sun::star::awt::MouseWheelBehavior;
90 namespace LineEndFormat = ::com::sun::star::awt::LineEndFormat;
91 namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode;
92 namespace DataType = ::com::sun::star::sdbc::DataType;
93 namespace ColumnValue = ::com::sun::star::sdbc::ColumnValue;
94 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
96 //====================================================================
97 //= FormControlFactory_Data
98 //====================================================================
99 struct FormControlFactory_Data
101 ::comphelper::ComponentContext m_aContext;
103 FormControlFactory_Data( const ::comphelper::ComponentContext& _rContext )
104 :m_aContext( _rContext )
109 //====================================================================
110 //= FormControlFactory
111 //====================================================================
112 //--------------------------------------------------------------------
113 FormControlFactory::FormControlFactory( const ::comphelper::ComponentContext& _rContext )
114 :m_pData( new FormControlFactory_Data( _rContext ) )
118 //--------------------------------------------------------------------
119 FormControlFactory::~FormControlFactory()
123 //--------------------------------------------------------------------
124 sal_Int16 FormControlFactory::initializeControlModel( const DocumentType _eDocType, const SdrUnoObj& _rObject )
126 return initializeControlModel(
127 _eDocType,
128 Reference< XPropertySet >( _rObject.GetUnoControlModel(), UNO_QUERY ),
129 _rObject.GetCurrentBoundRect()
133 //--------------------------------------------------------------------
134 sal_Int16 FormControlFactory::initializeControlModel( const DocumentType _eDocType, const Reference< XPropertySet >& _rxControlModel )
136 return initializeControlModel(
137 _eDocType, _rxControlModel, Rectangle()
141 // -----------------------------------------------------------------------------
142 namespace
144 //....................................................................
145 static OUString lcl_getUniqueLabel_nothrow( const Reference< XPropertySet >& _rxControlModel, const OUString& _rBaseLabel )
147 OUString sLabel( _rBaseLabel );
150 typedef ::std::set< OUString > StringBag;
151 StringBag aUsedLabels;
153 Reference< XFormComponent > xFormComponent( _rxControlModel, UNO_QUERY_THROW );
154 Reference< XIndexAccess > xContainer( xFormComponent->getParent(), UNO_QUERY_THROW );
155 // loop through all siblings of the control model, and collect their labels
156 for ( sal_Int32 index=xContainer->getCount(); index>0; )
158 Reference< XPropertySet > xElement( xContainer->getByIndex( --index ), UNO_QUERY_THROW );
159 if ( xElement == _rxControlModel )
160 continue;
162 Reference< XPropertySetInfo > xPSI( xElement->getPropertySetInfo(), UNO_SET_THROW );
163 if ( !xPSI->hasPropertyByName( FM_PROP_LABEL ) )
164 continue;
166 OUString sElementLabel;
167 OSL_VERIFY( xElement->getPropertyValue( FM_PROP_LABEL ) >>= sElementLabel );
168 aUsedLabels.insert( sElementLabel );
171 // now find a free label
172 sal_Int32 i=2;
173 while ( aUsedLabels.find( sLabel ) != aUsedLabels.end() )
175 OUStringBuffer aBuffer( _rBaseLabel );
176 aBuffer.appendAscii( " " );
177 aBuffer.append( (sal_Int32)i++ );
178 sLabel = aBuffer.makeStringAndClear();
181 catch( const Exception& )
183 DBG_UNHANDLED_EXCEPTION();
185 return sLabel;
188 //....................................................................
189 static Sequence< PropertyValue > lcl_getDataSourceIndirectProperties( const Reference< XPropertySet >& _rxControlModel,
190 const ::comphelper::ComponentContext& _rContext )
192 OSL_PRECOND( _rxControlModel.is(), "lcl_getDataSourceIndirectProperties: invalid model!" );
194 Sequence< PropertyValue > aInfo;
197 Reference< XChild > xChild( _rxControlModel, UNO_QUERY );
198 Reference< XPropertySet > xForm;
199 if ( xChild.is() )
200 xForm = xForm.query( xChild->getParent() );
202 if ( Reference< XGridColumnFactory >( xForm, UNO_QUERY ).is() )
203 { // hmm. the model is a grid column, in real
204 xChild = xChild.query( xForm );
205 xForm = xForm.query( xChild->getParent() );
208 OSL_ENSURE( xForm.is(), "lcl_getDataSourceIndirectProperties: could not determine the form!" );
209 if ( !xForm.is() )
210 return aInfo;
211 OUString sDataSourceName;
212 xForm->getPropertyValue( FM_PROP_DATASOURCE ) >>= sDataSourceName;
214 Reference< XPropertySet > xDsProperties;
215 if ( !sDataSourceName.isEmpty() )
216 xDsProperties = xDsProperties.query( OStaticDataAccessTools().getDataSource( sDataSourceName, _rContext.getUNOContext() ) );
217 if ( xDsProperties.is() )
218 xDsProperties->getPropertyValue( OUString( "Info" ) ) >>= aInfo;
220 catch( const Exception& )
222 OSL_FAIL( "lcl_getDataSourceIndirectProperties: caught an exception!" );
224 return aInfo;
227 //....................................................................
228 static const sal_Char* aCharacterAndParagraphProperties[] =
230 "CharFontName",
231 "CharFontStyleName",
232 "CharFontFamily",
233 "CharFontCharSet",
234 "CharFontPitch",
235 "CharColor",
236 "CharEscapement",
237 "CharHeight",
238 "CharUnderline",
239 "CharWeight",
240 "CharPosture",
241 "CharAutoKerning",
242 "CharBackColor",
243 "CharBackTransparent",
244 "CharCaseMap",
245 "CharCrossedOut",
246 "CharFlash",
247 "CharStrikeout",
248 "CharWordMode",
249 "CharKerning",
250 "CharLocale",
251 "CharKeepTogether",
252 "CharNoLineBreak",
253 "CharShadowed",
254 "CharFontType",
255 "CharStyleName",
256 "CharContoured",
257 "CharCombineIsOn",
258 "CharCombinePrefix",
259 "CharCombineSuffix",
260 "CharEmphasize",
261 "CharRelief",
262 "RubyText",
263 "RubyAdjust",
264 "RubyCharStyleName",
265 "RubyIsAbove",
266 "CharRotation",
267 "CharRotationIsFitToLine",
268 "CharScaleWidth",
269 "HyperLinkURL",
270 "HyperLinkTarget",
271 "HyperLinkName",
272 "VisitedCharStyleName",
273 "UnvisitedCharStyleName",
274 "CharEscapementHeight",
275 "CharNoHyphenation",
276 "CharUnderlineColor",
277 "CharUnderlineHasColor",
278 "CharStyleNames",
279 "CharHeightAsian",
280 "CharWeightAsian",
281 "CharFontNameAsian",
282 "CharFontStyleNameAsian",
283 "CharFontFamilyAsian",
284 "CharFontCharSetAsian",
285 "CharFontPitchAsian",
286 "CharPostureAsian",
287 "CharLocaleAsian",
288 "ParaIsCharacterDistance",
289 "ParaIsForbiddenRules",
290 "ParaIsHangingPunctuation",
291 "CharHeightComplex",
292 "CharWeightComplex",
293 "CharFontNameComplex",
294 "CharFontStyleNameComplex",
295 "CharFontFamilyComplex",
296 "CharFontCharSetComplex",
297 "CharFontPitchComplex",
298 "CharPostureComplex",
299 "CharLocaleComplex",
300 "ParaAdjust",
301 "ParaLineSpacing",
302 "ParaBackColor",
303 "ParaBackTransparent",
304 "ParaBackGraphicURL",
305 "ParaBackGraphicFilter",
306 "ParaBackGraphicLocation",
307 "ParaLastLineAdjust",
308 "ParaExpandSingleWord",
309 "ParaLeftMargin",
310 "ParaRightMargin",
311 "ParaTopMargin",
312 "ParaBottomMargin",
313 "ParaLineNumberCount",
314 "ParaLineNumberStartValue",
315 "PageDescName",
316 "PageNumberOffset",
317 "ParaRegisterModeActive",
318 "ParaTabStops",
319 "ParaStyleName",
320 "DropCapFormat",
321 "DropCapWholeWord",
322 "ParaKeepTogether",
323 "Setting",
324 "ParaSplit",
325 "Setting",
326 "NumberingLevel",
327 "NumberingRules",
328 "NumberingStartValue",
329 "ParaIsNumberingRestart",
330 "NumberingStyleName",
331 "ParaOrphans",
332 "ParaWidows",
333 "ParaShadowFormat",
334 "LeftBorder",
335 "RightBorder",
336 "TopBorder",
337 "BottomBorder",
338 "BorderDistance",
339 "LeftBorderDistance",
340 "RightBorderDistance",
341 "TopBorderDistance",
342 "BottomBorderDistance",
343 "BreakType",
344 "DropCapCharStyleName",
345 "ParaFirstLineIndent",
346 "ParaIsAutoFirstLineIndent",
347 "ParaIsHyphenation",
348 "ParaHyphenationMaxHyphens",
349 "ParaHyphenationMaxLeadingChars",
350 "ParaHyphenationMaxTrailingChars",
351 "ParaVertAlignment",
352 "ParaUserDefinedAttributes",
353 "NumberingIsNumber",
354 "ParaIsConnectBorder",
355 NULL
358 //....................................................................
359 static void lcl_initializeCharacterAttributes( const Reference< XPropertySet >& _rxModel )
363 Reference< XPropertySet > xStyle( ControlLayouter::getDefaultDocumentTextStyle( _rxModel ), UNO_SET_THROW );
365 // transfer all properties which are described by the style
366 Reference< XPropertySetInfo > xSourcePropInfo( xStyle->getPropertySetInfo(), UNO_SET_THROW );
367 Reference< XPropertySetInfo > xDestPropInfo( _rxModel->getPropertySetInfo(), UNO_SET_THROW );
369 OUString sPropertyName;
370 const sal_Char** pCharacterProperty = aCharacterAndParagraphProperties;
371 while ( *pCharacterProperty )
373 sPropertyName = OUString::createFromAscii( *pCharacterProperty );
375 if ( xSourcePropInfo->hasPropertyByName( sPropertyName ) && xDestPropInfo->hasPropertyByName( sPropertyName ) )
376 _rxModel->setPropertyValue( sPropertyName, xStyle->getPropertyValue( sPropertyName ) );
378 ++pCharacterProperty;
381 catch( const Exception& )
383 DBG_UNHANDLED_EXCEPTION();
388 //--------------------------------------------------------------------
389 sal_Int16 FormControlFactory::initializeControlModel( const DocumentType _eDocType, const Reference< XPropertySet >& _rxControlModel,
390 const Rectangle& _rControlBoundRect )
392 sal_Int16 nClassId = FormComponentType::CONTROL;
394 OSL_ENSURE( _rxControlModel.is(), "FormControlFactory::initializeControlModel: invalid model!" );
395 if ( !_rxControlModel.is() )
396 return nClassId;
400 ControlLayouter::initializeControlLayout( _rxControlModel, _eDocType );
402 _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId;
403 Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
404 switch ( nClassId )
406 case FormComponentType::SCROLLBAR:
407 _rxControlModel->setPropertyValue( OUString( "LiveScroll" ), makeAny( (sal_Bool)sal_True ) );
408 // NO break!
409 case FormComponentType::SPINBUTTON:
411 sal_Int32 eOrientation = ScrollBarOrientation::HORIZONTAL;
412 if ( !_rControlBoundRect.IsEmpty() && ( _rControlBoundRect.GetWidth() < _rControlBoundRect.GetHeight() ) )
413 eOrientation = ScrollBarOrientation::VERTICAL;
414 _rxControlModel->setPropertyValue( FM_PROP_ORIENTATION, makeAny( eOrientation ) );
416 break;
418 case FormComponentType::LISTBOX:
419 case FormComponentType::COMBOBOX:
421 sal_Bool bDropDown = !_rControlBoundRect.IsEmpty() && ( _rControlBoundRect.GetWidth() >= 3 * _rControlBoundRect.GetHeight() );
422 if ( xPSI->hasPropertyByName( FM_PROP_DROPDOWN ) )
423 _rxControlModel->setPropertyValue( FM_PROP_DROPDOWN, makeAny( (sal_Bool)bDropDown ) );
424 _rxControlModel->setPropertyValue( FM_PROP_LINECOUNT, makeAny( sal_Int16( 20 ) ) );
426 break;
428 case FormComponentType::TEXTFIELD:
430 initializeTextFieldLineEnds( _rxControlModel );
431 lcl_initializeCharacterAttributes( _rxControlModel );
433 if ( !_rControlBoundRect.IsEmpty()
434 && !( _rControlBoundRect.GetWidth() > 4 * _rControlBoundRect.GetHeight() )
437 if ( xPSI->hasPropertyByName( FM_PROP_MULTILINE ) )
438 _rxControlModel->setPropertyValue( FM_PROP_MULTILINE, makeAny( (sal_Bool)sal_True ) );
441 break;
443 case FormComponentType::RADIOBUTTON:
444 case FormComponentType::CHECKBOX:
445 case FormComponentType::FIXEDTEXT:
447 OUString sVertAlignPropertyName( "VerticalAlign" );
448 if ( xPSI->hasPropertyByName( sVertAlignPropertyName ) )
449 _rxControlModel->setPropertyValue( sVertAlignPropertyName, makeAny( VerticalAlignment_MIDDLE ) );
451 break;
453 case FormComponentType::IMAGEBUTTON:
454 case FormComponentType::IMAGECONTROL:
456 const OUString sScaleModeProperty( "ScaleMode" );
457 if ( xPSI->hasPropertyByName( sScaleModeProperty ) )
458 _rxControlModel->setPropertyValue( sScaleModeProperty, makeAny( ImageScaleMode::Isotropic ) );
460 break;
463 // initial default label for the control
464 if ( xPSI->hasPropertyByName( FM_PROP_LABEL ) )
466 OUString sExistingLabel;
467 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_LABEL ) >>= sExistingLabel );
468 if ( sExistingLabel.isEmpty() )
470 OUString sInitialLabel;
471 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_NAME ) >>= sInitialLabel );
473 sal_uInt16 nTitleResId = 0;
474 switch ( nClassId )
476 case FormComponentType::COMMANDBUTTON: nTitleResId = RID_STR_PROPTITLE_PUSHBUTTON; break;
477 case FormComponentType::RADIOBUTTON: nTitleResId = RID_STR_PROPTITLE_RADIOBUTTON; break;
478 case FormComponentType::CHECKBOX: nTitleResId = RID_STR_PROPTITLE_CHECKBOX; break;
479 case FormComponentType::GROUPBOX: nTitleResId = RID_STR_PROPTITLE_GROUPBOX; break;
480 case FormComponentType::FIXEDTEXT: nTitleResId = RID_STR_PROPTITLE_FIXEDTEXT; break;
483 if ( nTitleResId )
484 sInitialLabel = String( SVX_RES( nTitleResId ) );
486 _rxControlModel->setPropertyValue(
487 FM_PROP_LABEL,
488 makeAny( lcl_getUniqueLabel_nothrow( _rxControlModel, sInitialLabel ) )
493 // strict format = yes is the default (i93467)
494 if ( xPSI->hasPropertyByName( FM_PROP_STRICTFORMAT ) )
496 _rxControlModel->setPropertyValue( FM_PROP_STRICTFORMAT, makeAny( sal_Bool( sal_True ) ) );
499 // mouse wheel: don't use it for scrolling by default (i110036)
500 if ( xPSI->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) )
502 _rxControlModel->setPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR, makeAny( MouseWheelBehavior::SCROLL_DISABLED ) );
505 if ( xPSI->hasPropertyByName( FM_PROP_WRITING_MODE ) )
506 _rxControlModel->setPropertyValue( FM_PROP_WRITING_MODE, makeAny( WritingMode2::CONTEXT ) );
508 catch( const Exception& )
510 DBG_UNHANDLED_EXCEPTION();
512 return nClassId;
515 //------------------------------------------------------------------------------
516 void FormControlFactory::initializeTextFieldLineEnds( const Reference< XPropertySet >& _rxModel )
518 OSL_PRECOND( _rxModel.is(), "initializeTextFieldLineEnds: invalid model!" );
519 if ( !_rxModel.is() )
520 return;
524 Reference< XPropertySetInfo > xInfo = _rxModel->getPropertySetInfo();
525 if ( !xInfo.is() || !xInfo->hasPropertyByName( FM_PROP_LINEENDFORMAT ) )
526 return;
528 // let's see if the data source which the form belongs to (if any)
529 // has a setting for the preferred line end format
530 sal_Bool bDosLineEnds = sal_False;
531 Sequence< PropertyValue > aInfo = lcl_getDataSourceIndirectProperties( _rxModel, m_pData->m_aContext );
532 const PropertyValue* pInfo = aInfo.getConstArray();
533 const PropertyValue* pInfoEnd = pInfo + aInfo.getLength();
534 for ( ; pInfo != pInfoEnd; ++pInfo )
536 if ( pInfo->Name == "PreferDosLikeLineEnds" )
538 pInfo->Value >>= bDosLineEnds;
539 break;
543 sal_Int16 nLineEndFormat = bDosLineEnds ? LineEndFormat::CARRIAGE_RETURN_LINE_FEED : LineEndFormat::LINE_FEED;
544 _rxModel->setPropertyValue( FM_PROP_LINEENDFORMAT, makeAny( nLineEndFormat ) );
546 catch( const Exception& )
548 DBG_UNHANDLED_EXCEPTION();
552 //------------------------------------------------------------------------------
553 void FormControlFactory::initializeFieldDependentProperties( const Reference< XPropertySet >& _rxDatabaseField,
554 const Reference< XPropertySet >& _rxControlModel, const Reference< XNumberFormats >& _rxNumberFormats )
556 OSL_PRECOND( _rxDatabaseField.is() && _rxControlModel.is(),
557 "FormControlFactory::initializeFieldDependentProperties: illegal params!" );
558 if ( !_rxDatabaseField.is() || !_rxControlModel.is() )
559 return;
563 ////////////////////////////////////////////////////////////////////////
564 // if the field has a numeric format, and the model has a "Scale" property, sync it
565 Reference< XPropertySetInfo > xFieldPSI( _rxDatabaseField->getPropertySetInfo(), UNO_SET_THROW );
566 Reference< XPropertySetInfo > xModelPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW );
568 if ( xModelPSI->hasPropertyByName( FM_PROP_DECIMAL_ACCURACY ) )
570 sal_Int32 nFormatKey = 0;
571 if ( xFieldPSI->hasPropertyByName( FM_PROP_FORMATKEY ) )
573 _rxDatabaseField->getPropertyValue( FM_PROP_FORMATKEY ) >>= nFormatKey;
575 else
577 nFormatKey = OStaticDataAccessTools().getDefaultNumberFormat(
578 _rxDatabaseField,
579 Reference< XNumberFormatTypes >( _rxNumberFormats, UNO_QUERY ),
580 SvtSysLocale().GetLanguageTag().getLocale()
584 Any aScaleVal( ::comphelper::getNumberFormatDecimals( _rxNumberFormats, nFormatKey ) );
585 _rxControlModel->setPropertyValue( FM_PROP_DECIMAL_ACCURACY, aScaleVal );
588 ////////////////////////////////////////////////////////////////////////
589 // minimum and maximum of the control according to the type of the database field
590 sal_Int32 nDataType = DataType::OTHER;
591 OSL_VERIFY( _rxDatabaseField->getPropertyValue( FM_PROP_FIELDTYPE ) >>= nDataType );
593 if ( xModelPSI->hasPropertyByName( FM_PROP_VALUEMIN )
594 && xModelPSI->hasPropertyByName( FM_PROP_VALUEMAX )
597 sal_Int32 nMinValue = -1000000000, nMaxValue = 1000000000;
598 switch ( nDataType )
600 case DataType::TINYINT : nMinValue = 0; nMaxValue = 255; break;
601 case DataType::SMALLINT : nMinValue = -32768; nMaxValue = 32767; break;
602 case DataType::INTEGER : nMinValue = 0x80000000; nMaxValue = 0x7FFFFFFF; break;
603 // double and singles are ignored
606 Any aValue;
608 // both the minimum and the maximum value properties can be either Long or Double
609 Property aProperty = xModelPSI->getPropertyByName( FM_PROP_VALUEMIN );
610 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
611 aValue <<= (double)nMinValue;
612 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
613 aValue <<= (sal_Int32)nMinValue;
614 else
616 OSL_FAIL( "FormControlFactory::initializeFieldDependentProperties: unexpected property type (MinValue)!" );
618 _rxControlModel->setPropertyValue( FM_PROP_VALUEMIN, aValue );
620 // both the minimum and the maximum value properties can be either Long or Double
621 aProperty = xModelPSI->getPropertyByName( FM_PROP_VALUEMAX );
622 if ( aProperty.Type.getTypeClass() == TypeClass_DOUBLE )
623 aValue <<= (double)nMaxValue;
624 else if ( aProperty.Type.getTypeClass() == TypeClass_LONG )
625 aValue <<= (sal_Int32)nMaxValue;
626 else
628 OSL_FAIL( "FormControlFactory::initializeFieldDependentProperties: unexpected property type (MaxValue)!" );
630 _rxControlModel->setPropertyValue( FM_PROP_VALUEMAX, aValue );
633 ////////////////////////////////////////////////////////////////////////
634 // a check box can be tristate if and only if the column it is bound to is nullable
635 sal_Int16 nClassId = FormComponentType::CONTROL;
636 OSL_VERIFY( _rxControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId );
637 if ( nClassId == FormComponentType::CHECKBOX )
639 sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN;
640 OSL_VERIFY( _rxDatabaseField->getPropertyValue( FM_PROP_ISNULLABLE ) >>= nNullable );
641 _rxControlModel->setPropertyValue( FM_PROP_TRISTATE, makeAny( sal_Bool( ColumnValue::NO_NULLS != nNullable ) ) );
644 catch( const Exception& )
646 DBG_UNHANDLED_EXCEPTION();
650 //------------------------------------------------------------------------------
651 OUString FormControlFactory::getDefaultName( sal_Int16 _nClassId, const Reference< XServiceInfo >& _rxObject )
653 sal_uInt16 nResId(0);
655 switch ( _nClassId )
657 case FormComponentType::COMMANDBUTTON: nResId = RID_STR_PROPTITLE_PUSHBUTTON; break;
658 case FormComponentType::RADIOBUTTON: nResId = RID_STR_PROPTITLE_RADIOBUTTON; break;
659 case FormComponentType::CHECKBOX: nResId = RID_STR_PROPTITLE_CHECKBOX; break;
660 case FormComponentType::LISTBOX: nResId = RID_STR_PROPTITLE_LISTBOX; break;
661 case FormComponentType::COMBOBOX: nResId = RID_STR_PROPTITLE_COMBOBOX; break;
662 case FormComponentType::GROUPBOX: nResId = RID_STR_PROPTITLE_GROUPBOX; break;
663 case FormComponentType::IMAGEBUTTON: nResId = RID_STR_PROPTITLE_IMAGEBUTTON; break;
664 case FormComponentType::FIXEDTEXT: nResId = RID_STR_PROPTITLE_FIXEDTEXT; break;
665 case FormComponentType::GRIDCONTROL: nResId = RID_STR_PROPTITLE_DBGRID; break;
666 case FormComponentType::FILECONTROL: nResId = RID_STR_PROPTITLE_FILECONTROL; break;
667 case FormComponentType::DATEFIELD: nResId = RID_STR_PROPTITLE_DATEFIELD; break;
668 case FormComponentType::TIMEFIELD: nResId = RID_STR_PROPTITLE_TIMEFIELD; break;
669 case FormComponentType::NUMERICFIELD: nResId = RID_STR_PROPTITLE_NUMERICFIELD; break;
670 case FormComponentType::CURRENCYFIELD: nResId = RID_STR_PROPTITLE_CURRENCYFIELD; break;
671 case FormComponentType::PATTERNFIELD: nResId = RID_STR_PROPTITLE_PATTERNFIELD; break;
672 case FormComponentType::IMAGECONTROL: nResId = RID_STR_PROPTITLE_IMAGECONTROL; break;
673 case FormComponentType::HIDDENCONTROL: nResId = RID_STR_PROPTITLE_HIDDEN; break;
674 case FormComponentType::SCROLLBAR: nResId = RID_STR_PROPTITLE_SCROLLBAR; break;
675 case FormComponentType::SPINBUTTON: nResId = RID_STR_PROPTITLE_SPINBUTTON; break;
676 case FormComponentType::NAVIGATIONBAR: nResId = RID_STR_PROPTITLE_NAVBAR; break;
678 case FormComponentType::TEXTFIELD:
679 nResId = RID_STR_PROPTITLE_EDIT;
680 if ( _rxObject.is() && _rxObject->supportsService( FM_SUN_COMPONENT_FORMATTEDFIELD ) )
681 nResId = RID_STR_PROPTITLE_FORMATTED;
682 break;
684 default:
685 nResId = RID_STR_CONTROL; break;
688 return String( SVX_RES( nResId ) );
691 //------------------------------------------------------------------------------
692 OUString FormControlFactory::getDefaultUniqueName_ByComponentType( const Reference< XNameAccess >& _rxContainer,
693 const Reference< XPropertySet >& _rxObject )
695 sal_Int16 nClassId = FormComponentType::CONTROL;
696 OSL_VERIFY( _rxObject->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId );
697 OUString sBaseName = getDefaultName( nClassId, Reference< XServiceInfo >( _rxObject, UNO_QUERY ) );
699 return getUniqueName( _rxContainer, sBaseName );
702 //------------------------------------------------------------------------------
703 OUString FormControlFactory::getUniqueName( const Reference< XNameAccess >& _rxContainer, const OUString& _rBaseName )
705 sal_Int32 n = 0;
706 OUString sName;
709 OUStringBuffer aBuf( _rBaseName );
710 aBuf.appendAscii( " " );
711 aBuf.append( ++n );
712 sName = aBuf.makeStringAndClear();
714 while ( _rxContainer->hasByName( sName ) );
716 return sName;
719 //........................................................................
720 } // namespace svxform
721 //........................................................................
723 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */