1b0724fc6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5b0724fc6SAndrew Rist * distributed with this work for additional information 6b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance 9b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at 10b0724fc6SAndrew Rist * 11b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12b0724fc6SAndrew Rist * 13b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14b0724fc6SAndrew Rist * software distributed under the License is distributed on an 15b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the 17b0724fc6SAndrew Rist * specific language governing permissions and limitations 18b0724fc6SAndrew Rist * under the License. 19b0724fc6SAndrew Rist * 20b0724fc6SAndrew Rist *************************************************************/ 21b0724fc6SAndrew Rist 22b0724fc6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <toolkit/helper/formpdfexport.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir /** === begin UNO includes === **/ 30cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 31cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 32cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 33cdf0e10cSrcweir #include <com/sun/star/form/XForm.hpp> 34cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 35cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 36cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 37cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp> 38cdf0e10cSrcweir #include <com/sun/star/awt/TextAlign.hpp> 39cdf0e10cSrcweir #include <com/sun/star/style/VerticalAlignment.hpp> 40cdf0e10cSrcweir #include <com/sun/star/form/FormButtonType.hpp> 41cdf0e10cSrcweir #include <com/sun/star/form/FormSubmitMethod.hpp> 42cdf0e10cSrcweir /** === end UNO includes === **/ 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 45cdf0e10cSrcweir #include <tools/diagnose_ex.h> 46cdf0e10cSrcweir #include <vcl/pdfextoutdevdata.hxx> 47cdf0e10cSrcweir #include <vcl/outdev.hxx> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include <functional> 50cdf0e10cSrcweir #include <algorithm> 51cdf0e10cSrcweir 52cdf0e10cSrcweir //........................................................................ 53cdf0e10cSrcweir namespace toolkitform 54cdf0e10cSrcweir { 55cdf0e10cSrcweir //........................................................................ 56cdf0e10cSrcweir 57cdf0e10cSrcweir using namespace ::com::sun::star; 58cdf0e10cSrcweir using namespace ::com::sun::star::uno; 59cdf0e10cSrcweir using namespace ::com::sun::star::awt; 60cdf0e10cSrcweir using namespace ::com::sun::star::style; 61cdf0e10cSrcweir using namespace ::com::sun::star::beans; 62cdf0e10cSrcweir using namespace ::com::sun::star::form; 63cdf0e10cSrcweir using namespace ::com::sun::star::lang; 64cdf0e10cSrcweir using namespace ::com::sun::star::container; 65cdf0e10cSrcweir 66cdf0e10cSrcweir // used strings 67cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_CLASSID(RTL_CONSTASCII_USTRINGPARAM("ClassId")); 68cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_NAME(RTL_CONSTASCII_USTRINGPARAM("Name")); 69cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_STRINGITEMLIST(RTL_CONSTASCII_USTRINGPARAM("StringItemList")); 70cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_HELPTEXT(RTL_CONSTASCII_USTRINGPARAM("HelpText")); 71cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_TEXT(RTL_CONSTASCII_USTRINGPARAM("Text")); 72cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_LABEL(RTL_CONSTASCII_USTRINGPARAM("Label")); 73cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_READONLY(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); 74cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_BORDER(RTL_CONSTASCII_USTRINGPARAM("Border")); 75cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_BACKGROUNDCOLOR(RTL_CONSTASCII_USTRINGPARAM("BackgroundColor")); 76cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_TEXTCOLOR(RTL_CONSTASCII_USTRINGPARAM("TextColor")); 77cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_MULTILINE(RTL_CONSTASCII_USTRINGPARAM("MultiLine")); 78cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_ALIGN(RTL_CONSTASCII_USTRINGPARAM("Align")); 79cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_FONT(RTL_CONSTASCII_USTRINGPARAM("FontDescriptor")); 80cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_MAXTEXTLEN(RTL_CONSTASCII_USTRINGPARAM("MaxTextLen")); 81cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_TARGET_URL(RTL_CONSTASCII_USTRINGPARAM("TargetURL")); 82cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_STATE(RTL_CONSTASCII_USTRINGPARAM("State")); 83cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_REFVALUE(RTL_CONSTASCII_USTRINGPARAM("RefValue")); 84cdf0e10cSrcweir static const ::rtl::OUString FM_PROP_DROPDOWN(RTL_CONSTASCII_USTRINGPARAM("Dropdown")); 85cdf0e10cSrcweir static const ::rtl::OUString FM_SUN_COMPONENT_FILECONTROL(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FileControl")); 86cdf0e10cSrcweir 87cdf0e10cSrcweir namespace 88cdf0e10cSrcweir { 89cdf0e10cSrcweir //-------------------------------------------------------------------- 90cdf0e10cSrcweir /** determines the FormComponentType of a form control 91cdf0e10cSrcweir */ classifyFormControl(const Reference<XPropertySet> & _rxModel)92cdf0e10cSrcweir sal_Int16 classifyFormControl( const Reference< XPropertySet >& _rxModel ) SAL_THROW(( Exception )) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir sal_Int16 nControlType = FormComponentType::CONTROL; 95cdf0e10cSrcweir 96cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI; 97cdf0e10cSrcweir if ( _rxModel.is() ) 98cdf0e10cSrcweir xPSI = _rxModel->getPropertySetInfo(); 99cdf0e10cSrcweir if ( xPSI.is() && xPSI->hasPropertyByName( FM_PROP_CLASSID ) ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir OSL_VERIFY( _rxModel->getPropertyValue( FM_PROP_CLASSID ) >>= nControlType ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir return nControlType; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir //-------------------------------------------------------------------- 108cdf0e10cSrcweir /** (default-)creates a PDF widget according to a given FormComponentType 109cdf0e10cSrcweir */ createDefaultWidget(sal_Int16 _nFormComponentType)110cdf0e10cSrcweir ::vcl::PDFWriter::AnyWidget* createDefaultWidget( sal_Int16 _nFormComponentType ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir switch ( _nFormComponentType ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir case FormComponentType::COMMANDBUTTON: 115cdf0e10cSrcweir return new ::vcl::PDFWriter::PushButtonWidget; 116cdf0e10cSrcweir case FormComponentType::CHECKBOX: 117cdf0e10cSrcweir return new ::vcl::PDFWriter::CheckBoxWidget; 118cdf0e10cSrcweir case FormComponentType::RADIOBUTTON: 119cdf0e10cSrcweir return new ::vcl::PDFWriter::RadioButtonWidget; 120cdf0e10cSrcweir case FormComponentType::LISTBOX: 121cdf0e10cSrcweir return new ::vcl::PDFWriter::ListBoxWidget; 122cdf0e10cSrcweir case FormComponentType::COMBOBOX: 123cdf0e10cSrcweir return new ::vcl::PDFWriter::ComboBoxWidget; 124cdf0e10cSrcweir 125cdf0e10cSrcweir case FormComponentType::TEXTFIELD: 126cdf0e10cSrcweir case FormComponentType::FILECONTROL: 127cdf0e10cSrcweir case FormComponentType::DATEFIELD: 128cdf0e10cSrcweir case FormComponentType::TIMEFIELD: 129cdf0e10cSrcweir case FormComponentType::NUMERICFIELD: 130cdf0e10cSrcweir case FormComponentType::CURRENCYFIELD: 131cdf0e10cSrcweir case FormComponentType::PATTERNFIELD: 132cdf0e10cSrcweir return new ::vcl::PDFWriter::EditWidget; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir return NULL; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir //-------------------------------------------------------------------- 138cdf0e10cSrcweir /** determines a unique number for the radio group which the given radio 139cdf0e10cSrcweir button model belongs to 140cdf0e10cSrcweir 141cdf0e10cSrcweir The number is guaranteed to be 142cdf0e10cSrcweir <ul><li>unique within the document in which the button lives</li> 143cdf0e10cSrcweir <li>the same for subsequent calls with other radio button models, 144cdf0e10cSrcweir which live in the same document, and belong to the same group</li> 145cdf0e10cSrcweir </ul> 146cdf0e10cSrcweir 147cdf0e10cSrcweir @precond 148cdf0e10cSrcweir the model must be part of the form component hierarchy in a document 149cdf0e10cSrcweir */ determineRadioGroupId(const Reference<XPropertySet> & _rxRadioModel)150cdf0e10cSrcweir sal_Int32 determineRadioGroupId( const Reference< XPropertySet >& _rxRadioModel ) SAL_THROW((Exception)) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir OSL_ENSURE( classifyFormControl( _rxRadioModel ) == FormComponentType::RADIOBUTTON, 153cdf0e10cSrcweir "determineRadioGroupId: this *is* no radio button model!" ); 154cdf0e10cSrcweir // The fact that radio button groups need to be unique within the complete 155cdf0e10cSrcweir // host document makes it somewhat difficult ... 156cdf0e10cSrcweir // Problem is that two form radio buttons belong to the same group if 157cdf0e10cSrcweir // - they have the same parent 158cdf0e10cSrcweir // - AND they have the same name 159cdf0e10cSrcweir // This implies that we need some knowledge about (potentially) *all* radio button 160cdf0e10cSrcweir // groups in the document. 161cdf0e10cSrcweir 162cdf0e10cSrcweir // get the root-level container 163cdf0e10cSrcweir Reference< XChild > xChild( _rxRadioModel, UNO_QUERY ); 164cdf0e10cSrcweir Reference< XForm > xParentForm( xChild.is() ? xChild->getParent() : Reference< XInterface >(), UNO_QUERY ); 165cdf0e10cSrcweir OSL_ENSURE( xParentForm.is(), "determineRadioGroupId: no parent form -> group id!" ); 166cdf0e10cSrcweir if ( !xParentForm.is() ) 167cdf0e10cSrcweir return -1; 168cdf0e10cSrcweir 169cdf0e10cSrcweir while ( xParentForm.is() ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir xChild = xParentForm.get(); 172cdf0e10cSrcweir xParentForm = xParentForm.query( xChild->getParent() ); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir Reference< XIndexAccess > xRoot( xChild->getParent(), UNO_QUERY ); 175cdf0e10cSrcweir OSL_ENSURE( xRoot.is(), "determineRadioGroupId: unable to determine the root of the form component hierarchy!" ); 176cdf0e10cSrcweir if ( !xRoot.is() ) 177cdf0e10cSrcweir return -1; 178cdf0e10cSrcweir 179cdf0e10cSrcweir // count the leafs in the hierarchy, until we encounter radio button 180cdf0e10cSrcweir ::std::vector< Reference< XIndexAccess > > aAncestors; 181cdf0e10cSrcweir ::std::vector< sal_Int32 > aPath; 182cdf0e10cSrcweir 183cdf0e10cSrcweir Reference< XInterface > xNormalizedLookup( _rxRadioModel, UNO_QUERY ); 184cdf0e10cSrcweir ::rtl::OUString sRadioGroupName; 185cdf0e10cSrcweir OSL_VERIFY( _rxRadioModel->getPropertyValue( FM_PROP_NAME ) >>= sRadioGroupName ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir Reference< XIndexAccess > xCurrentContainer( xRoot ); 188cdf0e10cSrcweir sal_Int32 nStartWithChild = 0; 189cdf0e10cSrcweir sal_Int32 nGroupsEncountered = 0; 190cdf0e10cSrcweir do 191cdf0e10cSrcweir { 192cdf0e10cSrcweir Reference< XNameAccess > xElementNameAccess( xCurrentContainer, UNO_QUERY ); 193cdf0e10cSrcweir OSL_ENSURE( xElementNameAccess.is(), "determineRadioGroupId: no name container?" ); 194cdf0e10cSrcweir if ( !xElementNameAccess.is() ) 195cdf0e10cSrcweir return -1; 196cdf0e10cSrcweir 197cdf0e10cSrcweir if ( nStartWithChild == 0 ) 198cdf0e10cSrcweir { // we encounter this container the first time. In particular, we did not 199cdf0e10cSrcweir // just step up 200cdf0e10cSrcweir nGroupsEncountered += xElementNameAccess->getElementNames().getLength(); 201cdf0e10cSrcweir // this is way too much: Not all of the elements in the current container 202cdf0e10cSrcweir // may form groups, especially if they're forms. But anyway, this number is 203cdf0e10cSrcweir // sufficient for our purpose. Finally, the container contains *at most* 204cdf0e10cSrcweir // that much groups 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir sal_Int32 nCount = xCurrentContainer->getCount(); 208cdf0e10cSrcweir sal_Int32 i; 209cdf0e10cSrcweir for ( i = nStartWithChild; i < nCount; ++i ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir Reference< XInterface > xElement( xCurrentContainer->getByIndex( i ), UNO_QUERY ); 212cdf0e10cSrcweir if ( !xElement.is() ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir OSL_ENSURE( sal_False, "determineRadioGroupId: very suspicious!" ); 215cdf0e10cSrcweir continue; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir Reference< XIndexAccess > xNewContainer( xElement, UNO_QUERY ); 219cdf0e10cSrcweir if ( xNewContainer.is() ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir // step down the hierarchy 222cdf0e10cSrcweir aAncestors.push_back( xCurrentContainer ); 223cdf0e10cSrcweir xCurrentContainer = xNewContainer; 224cdf0e10cSrcweir aPath.push_back( i ); 225cdf0e10cSrcweir nStartWithChild = 0; 226cdf0e10cSrcweir break; 227cdf0e10cSrcweir // out of the inner loop, but continue with the outer loop 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir if ( xElement.get() == xNormalizedLookup.get() ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir // look up the name of the radio group in the list of all element names 233cdf0e10cSrcweir Sequence< ::rtl::OUString > aElementNames( xElementNameAccess->getElementNames() ); 234cdf0e10cSrcweir const ::rtl::OUString* pElementNames = aElementNames.getConstArray(); 235cdf0e10cSrcweir const ::rtl::OUString* pElementNamesEnd = pElementNames + aElementNames.getLength(); 236cdf0e10cSrcweir while ( pElementNames != pElementNamesEnd ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir if ( *pElementNames == sRadioGroupName ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir sal_Int32 nLocalGroupIndex = pElementNames - aElementNames.getConstArray(); 241cdf0e10cSrcweir OSL_ENSURE( nLocalGroupIndex < xElementNameAccess->getElementNames().getLength(), 242cdf0e10cSrcweir "determineRadioGroupId: inconsistency!" ); 243cdf0e10cSrcweir 244cdf0e10cSrcweir sal_Int32 nGlobalGroupId = nGroupsEncountered - xElementNameAccess->getElementNames().getLength() + nLocalGroupIndex; 245cdf0e10cSrcweir return nGlobalGroupId; 246cdf0e10cSrcweir } 247cdf0e10cSrcweir ++pElementNames; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir OSL_ENSURE( sal_False, "determineRadioGroupId: did not find the radios element name!" ); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir if ( !( i < nCount ) ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir // the loop terminated because there were no more elements 256cdf0e10cSrcweir // -> step up, if possible 257cdf0e10cSrcweir if ( aAncestors.empty() ) 258cdf0e10cSrcweir break; 259cdf0e10cSrcweir 260cdf0e10cSrcweir xCurrentContainer = aAncestors.back(); aAncestors.pop_back(); 261cdf0e10cSrcweir nStartWithChild = aPath.back() + 1; aPath.pop_back(); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir } 264cdf0e10cSrcweir while ( true ); 265cdf0e10cSrcweir return -1; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir //-------------------------------------------------------------------- 269cdf0e10cSrcweir /** copies a StringItemList to a PDF widget's list 270cdf0e10cSrcweir */ getStringItemVector(const Reference<XPropertySet> & _rxModel,::std::vector<::rtl::OUString> & _rVector)271cdf0e10cSrcweir void getStringItemVector( const Reference< XPropertySet >& _rxModel, ::std::vector< ::rtl::OUString >& _rVector ) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir Sequence< ::rtl::OUString > aListEntries; 274cdf0e10cSrcweir OSL_VERIFY( _rxModel->getPropertyValue( FM_PROP_STRINGITEMLIST ) >>= aListEntries ); 275cdf0e10cSrcweir ::std::copy( aListEntries.getConstArray(), aListEntries.getConstArray() + aListEntries.getLength(), 276cdf0e10cSrcweir ::std::back_insert_iterator< ::std::vector< ::rtl::OUString > >( _rVector ) ); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir //-------------------------------------------------------------------- 281cdf0e10cSrcweir /** creates a PDF compatible control descriptor for the given control 282cdf0e10cSrcweir */ describePDFControl(const Reference<XControl> & _rxControl,::std::auto_ptr<::vcl::PDFWriter::AnyWidget> & _rpDescriptor,::vcl::PDFExtOutDevData & i_pdfExportData)283cdf0e10cSrcweir void TOOLKIT_DLLPUBLIC describePDFControl( const Reference< XControl >& _rxControl, 284cdf0e10cSrcweir ::std::auto_ptr< ::vcl::PDFWriter::AnyWidget >& _rpDescriptor, ::vcl::PDFExtOutDevData& i_pdfExportData ) SAL_THROW(()) 285cdf0e10cSrcweir { 286*3d762826SHerbert Dürr _rpDescriptor.reset(); 287cdf0e10cSrcweir OSL_ENSURE( _rxControl.is(), "describePDFControl: invalid (NULL) control!" ); 288cdf0e10cSrcweir if ( !_rxControl.is() ) 289cdf0e10cSrcweir return; 290cdf0e10cSrcweir 291cdf0e10cSrcweir try 292cdf0e10cSrcweir { 293cdf0e10cSrcweir Reference< XPropertySet > xModelProps( _rxControl->getModel(), UNO_QUERY ); 294cdf0e10cSrcweir sal_Int16 nControlType = classifyFormControl( xModelProps ); 295cdf0e10cSrcweir _rpDescriptor.reset( createDefaultWidget( nControlType ) ); 296cdf0e10cSrcweir if ( !_rpDescriptor.get() ) 297cdf0e10cSrcweir // no PDF widget available for this 298cdf0e10cSrcweir return; 299cdf0e10cSrcweir 300cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI( xModelProps->getPropertySetInfo() ); 301cdf0e10cSrcweir Reference< XServiceInfo > xSI( xModelProps, UNO_QUERY ); 302cdf0e10cSrcweir OSL_ENSURE( xSI.is(), "describePDFControl: no service info!" ); 303cdf0e10cSrcweir // if we survived classifyFormControl, then it's a real form control, and they all have 304cdf0e10cSrcweir // service infos 305cdf0e10cSrcweir 306cdf0e10cSrcweir // ================================ 307cdf0e10cSrcweir // set the common widget properties 308cdf0e10cSrcweir 309cdf0e10cSrcweir // -------------------------------- 310cdf0e10cSrcweir // Name, Description, Text 311cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_NAME ) >>= _rpDescriptor->Name ); 312cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_HELPTEXT ) >>= _rpDescriptor->Description ); 313cdf0e10cSrcweir Any aText; 314cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_TEXT ) ) 315cdf0e10cSrcweir aText = xModelProps->getPropertyValue( FM_PROP_TEXT ); 316cdf0e10cSrcweir else if ( xPSI->hasPropertyByName( FM_PROP_LABEL ) ) 317cdf0e10cSrcweir aText = xModelProps->getPropertyValue( FM_PROP_LABEL ); 318cdf0e10cSrcweir if ( aText.hasValue() ) 319cdf0e10cSrcweir OSL_VERIFY( aText >>= _rpDescriptor->Text ); 320cdf0e10cSrcweir 321cdf0e10cSrcweir // -------------------------------- 322cdf0e10cSrcweir // readonly 323cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_READONLY ) ) 324cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_READONLY ) >>= _rpDescriptor->ReadOnly ); 325cdf0e10cSrcweir 326cdf0e10cSrcweir // -------------------------------- 327cdf0e10cSrcweir // border 328cdf0e10cSrcweir { 329cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_BORDER ) ) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir sal_Int16 nBorderType = 0; 332cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_BORDER ) >>= nBorderType ); 333cdf0e10cSrcweir _rpDescriptor->Border = ( nBorderType != 0 ); 334cdf0e10cSrcweir 335cdf0e10cSrcweir ::rtl::OUString sBorderColorPropertyName( RTL_CONSTASCII_USTRINGPARAM( "BorderColor" ) ); 336cdf0e10cSrcweir if ( xPSI->hasPropertyByName( sBorderColorPropertyName ) ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir sal_Int32 nBoderColor = COL_TRANSPARENT; 339cdf0e10cSrcweir if ( xModelProps->getPropertyValue( sBorderColorPropertyName ) >>= nBoderColor ) 340cdf0e10cSrcweir _rpDescriptor->BorderColor = Color( nBoderColor ); 341cdf0e10cSrcweir else 342cdf0e10cSrcweir _rpDescriptor->BorderColor = Color( COL_BLACK ); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir } 345cdf0e10cSrcweir } 346cdf0e10cSrcweir 347cdf0e10cSrcweir // -------------------------------- 348cdf0e10cSrcweir // background color 349cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_BACKGROUNDCOLOR ) ) 350cdf0e10cSrcweir { 351cdf0e10cSrcweir sal_Int32 nBackColor = COL_TRANSPARENT; 352cdf0e10cSrcweir xModelProps->getPropertyValue( FM_PROP_BACKGROUNDCOLOR ) >>= nBackColor; 353cdf0e10cSrcweir _rpDescriptor->Background = true; 354cdf0e10cSrcweir _rpDescriptor->BackgroundColor = Color( nBackColor ); 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir // -------------------------------- 358cdf0e10cSrcweir // text color 359cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_TEXTCOLOR ) ) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir sal_Int32 nTextColor = COL_TRANSPARENT; 362cdf0e10cSrcweir xModelProps->getPropertyValue( FM_PROP_TEXTCOLOR ) >>= nTextColor; 363cdf0e10cSrcweir _rpDescriptor->TextColor = Color( nTextColor ); 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir // -------------------------------- 367cdf0e10cSrcweir // text style 368cdf0e10cSrcweir _rpDescriptor->TextStyle = 0; 369cdf0e10cSrcweir // ............................ 370cdf0e10cSrcweir // multi line and word break 371cdf0e10cSrcweir // The MultiLine property of the control is mapped to both the "MULTILINE" and 372cdf0e10cSrcweir // "WORDBREAK" style flags 373cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_MULTILINE ) ) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir sal_Bool bMultiLine = sal_False; 376cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_MULTILINE ) >>= bMultiLine ); 377cdf0e10cSrcweir if ( bMultiLine ) 378cdf0e10cSrcweir _rpDescriptor->TextStyle |= TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK; 379cdf0e10cSrcweir } 380cdf0e10cSrcweir // ............................ 381cdf0e10cSrcweir // horizontal alignment 382cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_ALIGN ) ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir sal_Int16 nAlign = awt::TextAlign::LEFT; 385cdf0e10cSrcweir xModelProps->getPropertyValue( FM_PROP_ALIGN ) >>= nAlign; 386cdf0e10cSrcweir // TODO: when the property is VOID - are there situations/UIs where this 387cdf0e10cSrcweir // means something else than LEFT? 388cdf0e10cSrcweir switch ( nAlign ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir case awt::TextAlign::LEFT: _rpDescriptor->TextStyle |= TEXT_DRAW_LEFT; break; 391cdf0e10cSrcweir case awt::TextAlign::CENTER: _rpDescriptor->TextStyle |= TEXT_DRAW_CENTER; break; 392cdf0e10cSrcweir case awt::TextAlign::RIGHT: _rpDescriptor->TextStyle |= TEXT_DRAW_RIGHT; break; 393cdf0e10cSrcweir default: 394cdf0e10cSrcweir OSL_ENSURE( sal_False, "describePDFControl: invalid text align!" ); 395cdf0e10cSrcweir } 396cdf0e10cSrcweir } 397cdf0e10cSrcweir // ............................ 398cdf0e10cSrcweir // vertical alignment 399cdf0e10cSrcweir { 400cdf0e10cSrcweir ::rtl::OUString sVertAlignPropertyName( RTL_CONSTASCII_USTRINGPARAM( "VerticalAlign" ) ); 401cdf0e10cSrcweir if ( xPSI->hasPropertyByName( sVertAlignPropertyName ) ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir sal_Int16 nAlign = VerticalAlignment_MIDDLE; 404cdf0e10cSrcweir xModelProps->getPropertyValue( sVertAlignPropertyName ) >>= nAlign; 405cdf0e10cSrcweir switch ( nAlign ) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir case VerticalAlignment_TOP: _rpDescriptor->TextStyle |= TEXT_DRAW_TOP; break; 408cdf0e10cSrcweir case VerticalAlignment_MIDDLE: _rpDescriptor->TextStyle |= TEXT_DRAW_VCENTER; break; 409cdf0e10cSrcweir case VerticalAlignment_BOTTOM: _rpDescriptor->TextStyle |= TEXT_DRAW_BOTTOM; break; 410cdf0e10cSrcweir default: 411cdf0e10cSrcweir OSL_ENSURE( sal_False, "describePDFControl: invalid vertical text align!" ); 412cdf0e10cSrcweir } 413cdf0e10cSrcweir } 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir // font 417cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_FONT ) ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir FontDescriptor aUNOFont; 420cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_FONT ) >>= aUNOFont ); 421cdf0e10cSrcweir _rpDescriptor->TextFont = VCLUnoHelper::CreateFont( aUNOFont, Font() ); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir 424cdf0e10cSrcweir // tab order 425cdf0e10cSrcweir rtl::OUString aTabIndexString( RTL_CONSTASCII_USTRINGPARAM( "TabIndex" ) ); 426cdf0e10cSrcweir if ( xPSI->hasPropertyByName( aTabIndexString ) ) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir sal_Int16 nIndex = -1; 429cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( aTabIndexString ) >>= nIndex ); 430cdf0e10cSrcweir _rpDescriptor->TabOrder = nIndex; 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir // ================================ 434cdf0e10cSrcweir // special widget properties 435cdf0e10cSrcweir // -------------------------------- 436cdf0e10cSrcweir // edits 437cdf0e10cSrcweir if ( _rpDescriptor->getType() == ::vcl::PDFWriter::Edit ) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir ::vcl::PDFWriter::EditWidget* pEditWidget = static_cast< ::vcl::PDFWriter::EditWidget* >( _rpDescriptor.get() ); 440cdf0e10cSrcweir // ............................ 441cdf0e10cSrcweir // multiline (already flagged in the TextStyle) 442cdf0e10cSrcweir pEditWidget->MultiLine = ( _rpDescriptor->TextStyle & TEXT_DRAW_MULTILINE ) != 0; 443cdf0e10cSrcweir // ............................ 444cdf0e10cSrcweir // password input 445cdf0e10cSrcweir ::rtl::OUString sEchoCharPropName( RTL_CONSTASCII_USTRINGPARAM( "EchoChar" ) ); 446cdf0e10cSrcweir if ( xPSI->hasPropertyByName( sEchoCharPropName ) ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir sal_Int16 nEchoChar = 0; 449cdf0e10cSrcweir if ( ( xModelProps->getPropertyValue( sEchoCharPropName ) >>= nEchoChar ) && ( nEchoChar != 0 ) ) 450cdf0e10cSrcweir pEditWidget->Password = true; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir // ............................ 453cdf0e10cSrcweir // file select 454cdf0e10cSrcweir if ( xSI->supportsService( FM_SUN_COMPONENT_FILECONTROL ) ) 455cdf0e10cSrcweir pEditWidget->FileSelect = true; 456cdf0e10cSrcweir // ............................ 457cdf0e10cSrcweir // maximum text length 458cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_MAXTEXTLEN ) ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir sal_Int16 nMaxTextLength = 0; 461cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_MAXTEXTLEN ) >>= nMaxTextLength ); 462cdf0e10cSrcweir if ( nMaxTextLength <= 0 ) 463cdf0e10cSrcweir // "-1" has a special meaning for database-bound controls 464cdf0e10cSrcweir nMaxTextLength = 0; 465cdf0e10cSrcweir pEditWidget->MaxLen = nMaxTextLength; 466cdf0e10cSrcweir } 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir // -------------------------------- 470cdf0e10cSrcweir // buttons 471cdf0e10cSrcweir if ( _rpDescriptor->getType() == ::vcl::PDFWriter::PushButton ) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir ::vcl::PDFWriter::PushButtonWidget* pButtonWidget = static_cast< ::vcl::PDFWriter::PushButtonWidget* >( _rpDescriptor.get() ); 474cdf0e10cSrcweir FormButtonType eButtonType = FormButtonType_PUSH; 475cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ButtonType" ) ) ) >>= eButtonType ); 476cdf0e10cSrcweir if ( eButtonType == FormButtonType_SUBMIT ) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir // if a button is a submit button, then it uses the URL at it's parent form 479cdf0e10cSrcweir Reference< XChild > xChild( xModelProps, UNO_QUERY ); 480cdf0e10cSrcweir Reference < XPropertySet > xParentProps; 481cdf0e10cSrcweir if ( xChild.is() ) 482cdf0e10cSrcweir xParentProps = xParentProps.query( xChild->getParent() ); 483cdf0e10cSrcweir if ( xParentProps.is() ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir Reference< XServiceInfo > xParentSI( xParentProps, UNO_QUERY ); 486cdf0e10cSrcweir if ( xParentSI.is() && xParentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.component.HTMLForm" ) ) ) ) 487cdf0e10cSrcweir { 488cdf0e10cSrcweir OSL_VERIFY( xParentProps->getPropertyValue( FM_PROP_TARGET_URL ) >>= pButtonWidget->URL ); 489cdf0e10cSrcweir pButtonWidget->Submit = true; 490cdf0e10cSrcweir FormSubmitMethod eMethod = FormSubmitMethod_POST; 491cdf0e10cSrcweir OSL_VERIFY( xParentProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SubmitMethod" ) ) ) >>= eMethod ); 492cdf0e10cSrcweir pButtonWidget->SubmitGet = (eMethod == FormSubmitMethod_GET); 493cdf0e10cSrcweir } 494cdf0e10cSrcweir } 495cdf0e10cSrcweir } 496cdf0e10cSrcweir else if ( eButtonType == FormButtonType_URL ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir ::rtl::OUString sURL; 499cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_TARGET_URL ) >>= sURL ); 500cdf0e10cSrcweir const bool bDocumentLocalTarget = ( sURL.getLength() > 0 ) && ( sURL.getStr()[0] == '#' ); 501cdf0e10cSrcweir if ( bDocumentLocalTarget ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir const ::rtl::OUString sDestinationName( sURL.copy(1) ); 504cdf0e10cSrcweir // Register the destination for for future handling ... 505cdf0e10cSrcweir pButtonWidget->Dest = i_pdfExportData.RegisterDest(); 506cdf0e10cSrcweir 507cdf0e10cSrcweir // and put it into the bookmarks, to ensure the future handling really happens 508cdf0e10cSrcweir ::std::vector< ::vcl::PDFExtOutDevBookmarkEntry >& rBookmarks( i_pdfExportData.GetBookmarks() ); 509cdf0e10cSrcweir ::vcl::PDFExtOutDevBookmarkEntry aBookmark; 510cdf0e10cSrcweir aBookmark.nDestId = pButtonWidget->Dest; 511cdf0e10cSrcweir aBookmark.aBookmark = sURL; 512cdf0e10cSrcweir rBookmarks.push_back( aBookmark ); 513cdf0e10cSrcweir } 514cdf0e10cSrcweir else 515cdf0e10cSrcweir pButtonWidget->URL = sURL; 516cdf0e10cSrcweir 517cdf0e10cSrcweir pButtonWidget->Submit = false; 518cdf0e10cSrcweir } 519cdf0e10cSrcweir 520cdf0e10cSrcweir // TODO: 521cdf0e10cSrcweir // In PDF files, buttons are either reset, url or submit buttons. So if we have a simple PUSH button 522cdf0e10cSrcweir // in a document, then this means that we do not export a SubmitToURL, which means that in PDF, 523cdf0e10cSrcweir // the button is used as reset button. 524cdf0e10cSrcweir // Is this desired? If no, we would have to reset _rpDescriptor to NULL here, in case eButtonType 525cdf0e10cSrcweir // != FormButtonType_SUBMIT && != FormButtonType_RESET 526cdf0e10cSrcweir 527cdf0e10cSrcweir // the PDF exporter defaults the text style, if 0. To prevent this, we have to transfer the UNO 528cdf0e10cSrcweir // defaults to the PDF widget 529cdf0e10cSrcweir if ( !pButtonWidget->TextStyle ) 530cdf0e10cSrcweir pButtonWidget->TextStyle = TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER; 531cdf0e10cSrcweir } 532cdf0e10cSrcweir 533cdf0e10cSrcweir // -------------------------------- 534cdf0e10cSrcweir // check boxes 535cdf0e10cSrcweir if ( _rpDescriptor->getType() == ::vcl::PDFWriter::CheckBox ) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir ::vcl::PDFWriter::CheckBoxWidget* pCheckBoxWidget = static_cast< ::vcl::PDFWriter::CheckBoxWidget* >( _rpDescriptor.get() ); 538cdf0e10cSrcweir sal_Int16 nState = 0; 539cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_STATE ) >>= nState ); 540cdf0e10cSrcweir pCheckBoxWidget->Checked = ( nState != 0 ); 541cdf0e10cSrcweir } 542cdf0e10cSrcweir 543cdf0e10cSrcweir // -------------------------------- 544cdf0e10cSrcweir // radio buttons 545cdf0e10cSrcweir if ( _rpDescriptor->getType() == ::vcl::PDFWriter::RadioButton ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir ::vcl::PDFWriter::RadioButtonWidget* pRadioWidget = static_cast< ::vcl::PDFWriter::RadioButtonWidget* >( _rpDescriptor.get() ); 548cdf0e10cSrcweir sal_Int16 nState = 0; 549cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_STATE ) >>= nState ); 550cdf0e10cSrcweir pRadioWidget->Selected = ( nState != 0 ); 551cdf0e10cSrcweir pRadioWidget->RadioGroup = determineRadioGroupId( xModelProps ); 552cdf0e10cSrcweir try 553cdf0e10cSrcweir { 554cdf0e10cSrcweir xModelProps->getPropertyValue( FM_PROP_REFVALUE ) >>= pRadioWidget->OnValue; 555cdf0e10cSrcweir } 556cdf0e10cSrcweir catch(...) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir pRadioWidget->OnValue = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "On" ) ); 559cdf0e10cSrcweir } 560cdf0e10cSrcweir } 561cdf0e10cSrcweir 562cdf0e10cSrcweir // -------------------------------- 563cdf0e10cSrcweir // list boxes 564cdf0e10cSrcweir if ( _rpDescriptor->getType() == ::vcl::PDFWriter::ListBox ) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir ::vcl::PDFWriter::ListBoxWidget* pListWidget = static_cast< ::vcl::PDFWriter::ListBoxWidget* >( _rpDescriptor.get() ); 567cdf0e10cSrcweir // ............................ 568cdf0e10cSrcweir // drop down 569cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_DROPDOWN ) >>= pListWidget->DropDown ); 570cdf0e10cSrcweir // ............................ 571cdf0e10cSrcweir // multi selection 572cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiSelection" ) ) ) >>= pListWidget->MultiSelect ); 573cdf0e10cSrcweir // ............................ 574cdf0e10cSrcweir // entries 575cdf0e10cSrcweir getStringItemVector( xModelProps, pListWidget->Entries ); 576cdf0e10cSrcweir // since we explicitly list the entries in the order in which they appear, they should not be 577cdf0e10cSrcweir // resorted by the PDF viewer 578cdf0e10cSrcweir pListWidget->Sort = false; 579cdf0e10cSrcweir 580cdf0e10cSrcweir // get selected items 581cdf0e10cSrcweir Sequence< sal_Int16 > aSelectIndices; 582cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectedItems" ) ) ) >>= aSelectIndices ); 583cdf0e10cSrcweir if( aSelectIndices.getLength() > 0 ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir pListWidget->SelectedEntries.resize( 0 ); 586cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSelectIndices.getLength(); i++ ) 587cdf0e10cSrcweir { 588cdf0e10cSrcweir sal_Int16 nIndex = aSelectIndices.getConstArray()[i]; 589cdf0e10cSrcweir if( nIndex >= 0 && nIndex < (sal_Int16)pListWidget->Entries.size() ) 590cdf0e10cSrcweir pListWidget->SelectedEntries.push_back( nIndex ); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir } 593cdf0e10cSrcweir } 594cdf0e10cSrcweir 595cdf0e10cSrcweir // -------------------------------- 596cdf0e10cSrcweir // combo boxes 597cdf0e10cSrcweir if ( _rpDescriptor->getType() == ::vcl::PDFWriter::ComboBox ) 598cdf0e10cSrcweir { 599cdf0e10cSrcweir ::vcl::PDFWriter::ComboBoxWidget* pComboWidget = static_cast< ::vcl::PDFWriter::ComboBoxWidget* >( _rpDescriptor.get() ); 600cdf0e10cSrcweir // ............................ 601cdf0e10cSrcweir // entries 602cdf0e10cSrcweir getStringItemVector( xModelProps, pComboWidget->Entries ); 603cdf0e10cSrcweir // same reasoning as above 604cdf0e10cSrcweir pComboWidget->Sort = false; 605cdf0e10cSrcweir } 606cdf0e10cSrcweir 607cdf0e10cSrcweir // ================================ 608cdf0e10cSrcweir // some post-processing 609cdf0e10cSrcweir // -------------------------------- 610cdf0e10cSrcweir // text line ends 611cdf0e10cSrcweir // some controls may (always or dependent on other settings) return UNIX line ends 612cdf0e10cSrcweir String aConverter( _rpDescriptor->Text ); 613cdf0e10cSrcweir _rpDescriptor->Text = aConverter.ConvertLineEnd( LINEEND_CRLF ); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir catch( const Exception& ) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 618cdf0e10cSrcweir } 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir //........................................................................ 622cdf0e10cSrcweir } // namespace toolkitform 623cdf0e10cSrcweir //........................................................................ 624