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