LibreOffice Module vcl (master) 1
formpdfexport.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
21#include <memory>
22#include <vcl/formpdfexport.hxx>
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
42#include <vcl/unohelp.hxx>
43
44#include <algorithm>
45#include <iterator>
46
47
48static vcl::Font CreateFont( const css::awt::FontDescriptor& rDescr )
49{
50 vcl::Font aFont;
51 if ( !rDescr.Name.isEmpty() )
52 aFont.SetFamilyName( rDescr.Name );
53 if ( !rDescr.StyleName.isEmpty() )
54 aFont.SetStyleName( rDescr.StyleName );
55 if ( rDescr.Height )
56 aFont.SetFontSize( Size( rDescr.Width, rDescr.Height ) );
57 if ( static_cast<FontFamily>(rDescr.Family) != FAMILY_DONTKNOW )
58 aFont.SetFamily( static_cast<FontFamily>(rDescr.Family) );
59 if ( static_cast<rtl_TextEncoding>(rDescr.CharSet) != RTL_TEXTENCODING_DONTKNOW )
60 aFont.SetCharSet( static_cast<rtl_TextEncoding>(rDescr.CharSet) );
61 if ( static_cast<FontPitch>(rDescr.Pitch) != PITCH_DONTKNOW )
62 aFont.SetPitch( static_cast<FontPitch>(rDescr.Pitch) );
63 if ( rDescr.CharacterWidth )
64 aFont.SetWidthType(vcl::unohelper::ConvertFontWidth(rDescr.CharacterWidth));
65 if ( rDescr.Weight )
66 aFont.SetWeight(vcl::unohelper::ConvertFontWeight(rDescr.Weight));
67 if ( rDescr.Slant != css::awt::FontSlant_DONTKNOW )
69 if ( static_cast<FontLineStyle>(rDescr.Underline) != LINESTYLE_DONTKNOW )
70 aFont.SetUnderline( static_cast<FontLineStyle>(rDescr.Underline) );
71 if ( static_cast<FontStrikeout>(rDescr.Strikeout) != STRIKEOUT_DONTKNOW )
72 aFont.SetStrikeout( static_cast<FontStrikeout>(rDescr.Strikeout) );
73
74 // Not DONTKNOW
75 aFont.SetOrientation( Degree10(static_cast<sal_Int16>(rDescr.Orientation * 10)) );
76 aFont.SetKerning( static_cast<FontKerning>(rDescr.Kerning) );
77 aFont.SetWordLineMode( rDescr.WordLineMode );
78
79 return aFont;
80}
81
82namespace toolkitform
83{
84
85
86 using namespace ::com::sun::star;
87 using namespace ::com::sun::star::uno;
88 using namespace ::com::sun::star::awt;
89 using namespace ::com::sun::star::style;
90 using namespace ::com::sun::star::beans;
91 using namespace ::com::sun::star::form;
92 using namespace ::com::sun::star::lang;
93 using namespace ::com::sun::star::container;
94
95 constexpr OUStringLiteral FM_PROP_NAME = u"Name";
96
97 namespace
98 {
99
102 sal_Int16 classifyFormControl( const Reference< XPropertySet >& _rxModel )
103 {
104 static constexpr OUStringLiteral FM_PROP_CLASSID = u"ClassId";
105 sal_Int16 nControlType = FormComponentType::CONTROL;
106
107 Reference< XPropertySetInfo > xPSI;
108 if ( _rxModel.is() )
109 xPSI = _rxModel->getPropertySetInfo();
110 if ( xPSI.is() && xPSI->hasPropertyByName( FM_PROP_CLASSID ) )
111 {
112 if( ! (_rxModel->getPropertyValue( FM_PROP_CLASSID ) >>= nControlType) ) {
113 SAL_WARN("toolkit.helper", "classifyFormControl: unable to get property " << FM_PROP_CLASSID);
114 }
115 }
116
117 return nControlType;
118 }
119
120
123 std::unique_ptr<vcl::PDFWriter::AnyWidget> createDefaultWidget( sal_Int16 _nFormComponentType )
124 {
125 switch ( _nFormComponentType )
126 {
127 case FormComponentType::COMMANDBUTTON:
128 return std::make_unique<vcl::PDFWriter::PushButtonWidget>();
129 case FormComponentType::CHECKBOX:
130 return std::make_unique<vcl::PDFWriter::CheckBoxWidget>();
131 case FormComponentType::RADIOBUTTON:
132 return std::make_unique<vcl::PDFWriter::RadioButtonWidget>();
133 case FormComponentType::LISTBOX:
134 return std::make_unique<vcl::PDFWriter::ListBoxWidget>();
135 case FormComponentType::COMBOBOX:
136 return std::make_unique<vcl::PDFWriter::ComboBoxWidget>();
137
138 case FormComponentType::TEXTFIELD:
139 case FormComponentType::FILECONTROL:
140 case FormComponentType::DATEFIELD:
141 case FormComponentType::TIMEFIELD:
142 case FormComponentType::NUMERICFIELD:
143 case FormComponentType::CURRENCYFIELD:
144 case FormComponentType::PATTERNFIELD:
145 return std::make_unique<vcl::PDFWriter::EditWidget>();
146 }
147 return nullptr;
148 }
149
150
163 sal_Int32 determineRadioGroupId( const Reference< XPropertySet >& _rxRadioModel )
164 {
165 OSL_ENSURE( classifyFormControl( _rxRadioModel ) == FormComponentType::RADIOBUTTON,
166 "determineRadioGroupId: this *is* no radio button model!" );
167 // The fact that radio button groups need to be unique within the complete
168 // host document makes it somewhat difficult ...
169 // Problem is that two form radio buttons belong to the same group if
170 // - they have the same parent
171 // - AND they have the same name or group name
172 // This implies that we need some knowledge about (potentially) *all* radio button
173 // groups in the document.
174
175 // get the root-level container
176 Reference< XChild > xChild( _rxRadioModel, UNO_QUERY );
177 Reference< XForm > xParentForm( xChild.is() ? xChild->getParent() : Reference< XInterface >(), UNO_QUERY );
178 OSL_ENSURE( xParentForm.is(), "determineRadioGroupId: no parent form -> group id!" );
179 if ( !xParentForm.is() )
180 return -1;
181
182 while ( xParentForm.is() )
183 {
184 xChild = xParentForm.get();
185 xParentForm.set(xChild->getParent(), css::uno::UNO_QUERY);
186 }
187 Reference< XIndexAccess > xRoot( xChild->getParent(), UNO_QUERY );
188 OSL_ENSURE( xRoot.is(), "determineRadioGroupId: unable to determine the root of the form component hierarchy!" );
189 if ( !xRoot.is() )
190 return -1;
191
192 // count the leafs in the hierarchy, until we encounter radio button
193 ::std::vector< Reference< XIndexAccess > > aAncestors;
194 ::std::vector< sal_Int32 > aPath;
195
196 Reference< XInterface > xNormalizedLookup( _rxRadioModel, UNO_QUERY );
197 Reference< XIndexAccess > xCurrentContainer( xRoot );
198 sal_Int32 nStartWithChild = 0;
199 sal_Int32 nGroupsEncountered = 0;
200 do
201 {
202 std::unordered_map<OUString,sal_Int32> GroupNameMap;
203 std::unordered_map<OUString,sal_Int32> SharedNameMap;
204 sal_Int32 nCount = xCurrentContainer->getCount();
205 sal_Int32 i;
206 for ( i = nStartWithChild; i < nCount; ++i )
207 {
208 Reference< XInterface > xElement( xCurrentContainer->getByIndex( i ), UNO_QUERY );
209 if ( !xElement.is() )
210 {
211 OSL_FAIL( "determineRadioGroupId: very suspicious!" );
212 continue;
213 }
214
215 Reference< XIndexAccess > xNewContainer( xElement, UNO_QUERY );
216 if ( xNewContainer.is() )
217 {
218 // step down the hierarchy
219 aAncestors.push_back( xCurrentContainer );
220 xCurrentContainer = xNewContainer;
221 aPath.push_back( i );
222 nStartWithChild = 0;
223 break;
224 // out of the inner loop, but continue with the outer loop
225 }
226
227 if ( xElement.get() == xNormalizedLookup.get() )
228 {
229 // Our radio button is in this container.
230 // Now take the time to ID this container's groups and return the button's groupId
231 for ( i = 0; i < nCount; ++i )
232 {
233 try
234 {
235 xElement.set( xCurrentContainer->getByIndex( i ), UNO_QUERY_THROW );
236 Reference< XServiceInfo > xModelSI( xElement, UNO_QUERY_THROW );
237 if ( xModelSI->supportsService("com.sun.star.awt.UnoControlRadioButtonModel") )
238 {
239 Reference< XPropertySet > aProps( xElement, UNO_QUERY_THROW );
240
241 OUString sGroupName;
242 aProps->getPropertyValue("GroupName") >>= sGroupName;
243 if ( !sGroupName.isEmpty() )
244 {
245 // map: unique key is the group name, so attempts to add a different ID value
246 // for an existing group are ignored - keeping the first ID - perfect for this scenario.
247 GroupNameMap.emplace( sGroupName, nGroupsEncountered + i );
248
249 if ( xElement.get() == xNormalizedLookup.get() )
250 return GroupNameMap[sGroupName];
251 }
252 else
253 {
254 // Old implementation didn't have a GroupName, just identical Control names.
255 aProps->getPropertyValue( FM_PROP_NAME ) >>= sGroupName;
256 SharedNameMap.emplace( sGroupName, nGroupsEncountered + i );
257
258 if ( xElement.get() == xNormalizedLookup.get() )
259 return SharedNameMap[sGroupName];
260 }
261
262 }
263 }
264 catch( uno::Exception& )
265 {
266 DBG_UNHANDLED_EXCEPTION("toolkit");
267 }
268 }
269 SAL_WARN("toolkit.helper","determineRadioGroupId: did not find the radios element's group!" );
270 }
271 }
272
273 // we encounter this container the first time. In particular, we did not just step up
274 if ( nStartWithChild == 0 )
275 {
276 // Our control wasn't in this container, so consider every item to be a possible unique group.
277 // This is way too much: Not all of the elements in the current container will form groups.
278 // But anyway, this number is sufficient for our purpose, since sequential group ids are not required.
279 // Ultimately, the container contains *at most* this many groups.
280 nGroupsEncountered += nCount;
281 }
282
283 if ( i >= nCount )
284 {
285 // the loop terminated because there were no more elements
286 // -> step up, if possible
287 if ( aAncestors.empty() )
288 break;
289
290 xCurrentContainer = aAncestors.back(); aAncestors.pop_back();
291 nStartWithChild = aPath.back() + 1; aPath.pop_back();
292 }
293 }
294 while ( true );
295 return -1;
296 }
297
298
301 void getStringItemVector( const Reference< XPropertySet >& _rxModel, ::std::vector< OUString >& _rVector )
302 {
303 Sequence< OUString > aListEntries;
304 if( ! (_rxModel->getPropertyValue( "StringItemList" ) >>= aListEntries) ) {
305 SAL_WARN("toolkit.helper", "getStringItemVector: unable to get property StringItemList");
306 }
307 _rVector.insert( _rVector.end(), std::cbegin(aListEntries), std::cend(aListEntries) );
308 }
309 }
310
311
314 std::unique_ptr<vcl::PDFWriter::AnyWidget> describePDFControl( const Reference< XControl >& _rxControl,
315 vcl::PDFExtOutDevData& i_pdfExportData )
316 {
317 std::unique_ptr<vcl::PDFWriter::AnyWidget> Descriptor;
318 OSL_ENSURE( _rxControl.is(), "describePDFControl: invalid (NULL) control!" );
319 if ( !_rxControl.is() )
320 return Descriptor;
321
322 try
323 {
324 Reference< XPropertySet > xModelProps( _rxControl->getModel(), UNO_QUERY );
325 sal_Int16 nControlType = classifyFormControl( xModelProps );
326 Descriptor = createDefaultWidget( nControlType );
327 if (!Descriptor)
328 // no PDF widget available for this
329 return Descriptor;
330
331 Reference< XPropertySetInfo > xPSI( xModelProps->getPropertySetInfo() );
332 Reference< XServiceInfo > xSI( xModelProps, UNO_QUERY );
333 OSL_ENSURE( xSI.is(), "describePDFControl: no service info!" );
334 // if we survived classifyFormControl, then it's a real form control, and they all have
335 // service infos
336
337
338 // set the common widget properties
339
340
341 // Name, Description, Text
342 if( ! (xModelProps->getPropertyValue( FM_PROP_NAME ) >>= Descriptor->Name) ) {
343 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_NAME);
344 }
345 if( ! (xModelProps->getPropertyValue( "HelpText" ) >>= Descriptor->Description) ) {
346 SAL_INFO("toolkit.helper", "describePDFControl: unable to get property HelpText");
347 }
348 Any aText;
349 static constexpr OUStringLiteral FM_PROP_TEXT = u"Text";
350 static constexpr OUStringLiteral FM_PROP_LABEL = u"Label";
351 static constexpr OUStringLiteral FM_PROP_VALUE = u"Value";
352 if ( xPSI->hasPropertyByName( FM_PROP_TEXT ) )
353 aText = xModelProps->getPropertyValue( FM_PROP_TEXT );
354 else if ( xPSI->hasPropertyByName( FM_PROP_LABEL ) )
355 aText = xModelProps->getPropertyValue( FM_PROP_LABEL );
356 else if ( xPSI->hasPropertyByName( FM_PROP_VALUE ) )
357 {
358 double aValue;
359 if (xModelProps->getPropertyValue( FM_PROP_VALUE ) >>= aValue)
360 aText <<= OUString::number(aValue);
361 }
362
363 if ( aText.hasValue() ) {
364 if( ! (aText >>= Descriptor->Text) ) {
365 SAL_WARN("toolkit.helper", "describePDFControl: unable to assign aText to Descriptor->Text");
366 }
367 }
368
369
370 // readonly
371 static constexpr OUStringLiteral FM_PROP_READONLY = u"ReadOnly";
372 if ( xPSI->hasPropertyByName( FM_PROP_READONLY ) )
373 if( ! (xModelProps->getPropertyValue( FM_PROP_READONLY ) >>= Descriptor->ReadOnly) )
374 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_READONLY);
375
376
377 // border
378 {
379 static constexpr OUStringLiteral FM_PROP_BORDER = u"Border";
380 if ( xPSI->hasPropertyByName( FM_PROP_BORDER ) )
381 {
382 sal_Int16 nBorderType = 0;
383 if( ! (xModelProps->getPropertyValue( FM_PROP_BORDER ) >>= nBorderType) )
384 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_BORDER);
385 Descriptor->Border = ( nBorderType != 0 );
386
387 OUString sBorderColorPropertyName( "BorderColor" );
388 if ( xPSI->hasPropertyByName( sBorderColorPropertyName ) )
389 {
390 Color nBorderColor = COL_TRANSPARENT;
391 if ( xModelProps->getPropertyValue( sBorderColorPropertyName ) >>= nBorderColor )
392 Descriptor->BorderColor = nBorderColor;
393 else
394 Descriptor->BorderColor = COL_BLACK;
395 }
396 }
397 }
398
399
400 // background color
401 static constexpr OUStringLiteral FM_PROP_BACKGROUNDCOLOR = u"BackgroundColor";
402 if ( xPSI->hasPropertyByName( FM_PROP_BACKGROUNDCOLOR ) )
403 {
404 Color nBackColor = COL_TRANSPARENT;
405 xModelProps->getPropertyValue( FM_PROP_BACKGROUNDCOLOR ) >>= nBackColor;
406 Descriptor->Background = true;
407 Descriptor->BackgroundColor = nBackColor;
408 }
409
410
411 // text color
412 static constexpr OUStringLiteral FM_PROP_TEXTCOLOR = u"TextColor";
413 if ( xPSI->hasPropertyByName( FM_PROP_TEXTCOLOR ) )
414 {
415 Color nTextColor = COL_TRANSPARENT;
416 xModelProps->getPropertyValue( FM_PROP_TEXTCOLOR ) >>= nTextColor;
417 Descriptor->TextColor = nTextColor;
418 }
419
420
421 // text style
422 Descriptor->TextStyle = DrawTextFlags::NONE;
423
424 // multi line and word break
425 // The MultiLine property of the control is mapped to both the "MULTILINE" and
426 // "WORDBREAK" style flags
427 static constexpr OUStringLiteral FM_PROP_MULTILINE = u"MultiLine";
428 if ( xPSI->hasPropertyByName( FM_PROP_MULTILINE ) )
429 {
430 bool bMultiLine = false;
431 if( ! (xModelProps->getPropertyValue( FM_PROP_MULTILINE ) >>= bMultiLine) )
432 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_MULTILINE);
433 if ( bMultiLine )
434 Descriptor->TextStyle |= DrawTextFlags::MultiLine | DrawTextFlags::WordBreak;
435 }
436
437 // horizontal alignment
438 static constexpr OUStringLiteral FM_PROP_ALIGN = u"Align";
439 if ( xPSI->hasPropertyByName( FM_PROP_ALIGN ) )
440 {
441 sal_Int16 nAlign = awt::TextAlign::LEFT;
442 xModelProps->getPropertyValue( FM_PROP_ALIGN ) >>= nAlign;
443 // TODO: when the property is VOID - are there situations/UIs where this
444 // means something else than LEFT?
445 switch ( nAlign )
446 {
447 case awt::TextAlign::LEFT: Descriptor->TextStyle |= DrawTextFlags::Left; break;
448 case awt::TextAlign::CENTER: Descriptor->TextStyle |= DrawTextFlags::Center; break;
449 case awt::TextAlign::RIGHT: Descriptor->TextStyle |= DrawTextFlags::Right; break;
450 default:
451 OSL_FAIL( "describePDFControl: invalid text align!" );
452 }
453 }
454
455 // vertical alignment
456 {
457 OUString sVertAlignPropertyName( "VerticalAlign" );
458 if ( xPSI->hasPropertyByName( sVertAlignPropertyName ) )
459 {
460 VerticalAlignment nAlign = VerticalAlignment_MIDDLE;
461 xModelProps->getPropertyValue( sVertAlignPropertyName ) >>= nAlign;
462 switch ( nAlign )
463 {
464 case VerticalAlignment_TOP: Descriptor->TextStyle |= DrawTextFlags::Top; break;
465 case VerticalAlignment_MIDDLE: Descriptor->TextStyle |= DrawTextFlags::VCenter; break;
466 case VerticalAlignment_BOTTOM: Descriptor->TextStyle |= DrawTextFlags::Bottom; break;
467 default:
468 OSL_FAIL( "describePDFControl: invalid vertical text align!" );
469 }
470 }
471 }
472
473 // font
474 static constexpr OUStringLiteral FM_PROP_FONT = u"FontDescriptor";
475 if ( xPSI->hasPropertyByName( FM_PROP_FONT ) )
476 {
477 FontDescriptor aUNOFont;
478 if( ! (xModelProps->getPropertyValue( FM_PROP_FONT ) >>= aUNOFont) )
479 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_FONT);
480 Descriptor->TextFont = CreateFont( aUNOFont );
481 }
482
483 // tab order
484 OUString aTabIndexString( "TabIndex" );
485 if ( xPSI->hasPropertyByName( aTabIndexString ) )
486 {
487 sal_Int16 nIndex = -1;
488 if( ! (xModelProps->getPropertyValue( aTabIndexString ) >>= nIndex) )
489 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << aTabIndexString);
490 Descriptor->TabOrder = nIndex;
491 }
492
493
494 // special widget properties
495
496 // edits
497 if ( Descriptor->getType() == vcl::PDFWriter::Edit )
498 {
499 vcl::PDFWriter::EditWidget* pEditWidget = static_cast< vcl::PDFWriter::EditWidget* >( Descriptor.get() );
500
501 // multiline (already flagged in the TextStyle)
502 pEditWidget->MultiLine = bool( Descriptor->TextStyle & DrawTextFlags::MultiLine );
503
504 // password input
505 OUString sEchoCharPropName( "EchoChar" );
506 if ( xPSI->hasPropertyByName( sEchoCharPropName ) )
507 {
508 sal_Int16 nEchoChar = 0;
509 if ( ( xModelProps->getPropertyValue( sEchoCharPropName ) >>= nEchoChar ) && ( nEchoChar != 0 ) )
510 pEditWidget->Password = true;
511 }
512
513 // file select
514 if ( xSI->supportsService( "com.sun.star.form.component.FileControl" ) )
515 pEditWidget->FileSelect = true;
516
517 // maximum text length
518 static constexpr OUStringLiteral FM_PROP_MAXTEXTLEN = u"MaxTextLen";
519 if ( xPSI->hasPropertyByName( FM_PROP_MAXTEXTLEN ) )
520 {
521 sal_Int16 nMaxTextLength = 0;
522 if( ! (xModelProps->getPropertyValue( FM_PROP_MAXTEXTLEN ) >>= nMaxTextLength) )
523 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_MAXTEXTLEN);
524 if ( nMaxTextLength <= 0 )
525 // "-1" has a special meaning for database-bound controls
526 nMaxTextLength = 0;
527 pEditWidget->MaxLen = nMaxTextLength;
528 }
529
530 switch ( nControlType )
531 {
532 case FormComponentType::CURRENCYFIELD:
533 case FormComponentType::NUMERICFIELD:
534 {
535
536 pEditWidget->Format = vcl::PDFWriter::Number;
537
538 static constexpr OUStringLiteral FM_PROP_CURRENCYSYMBOL = u"CurrencySymbol";
539 if ( xPSI->hasPropertyByName( FM_PROP_CURRENCYSYMBOL ) )
540 {
541 OUString sCurrencySymbol;
542 if( ! (xModelProps->getPropertyValue( FM_PROP_CURRENCYSYMBOL ) >>= sCurrencySymbol) )
543 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_CURRENCYSYMBOL);
544 pEditWidget->CurrencySymbol = sCurrencySymbol;
545 }
546
547 static constexpr OUStringLiteral FM_PROP_DECIMALACCURACY = u"DecimalAccuracy";
548 if ( xPSI->hasPropertyByName( FM_PROP_DECIMALACCURACY ) )
549 {
550 sal_Int32 nDecimalAccuracy = 0;
551 if( ! (xModelProps->getPropertyValue( FM_PROP_DECIMALACCURACY ) >>= nDecimalAccuracy) )
552 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_DECIMALACCURACY);
553 pEditWidget->DecimalAccuracy = nDecimalAccuracy;
554 }
555
556 static constexpr OUStringLiteral FM_PROP_PREPENDCURRENCYSYMBOL = u"PrependCurrencySymbol";
557 if ( xPSI->hasPropertyByName( FM_PROP_PREPENDCURRENCYSYMBOL ) )
558 {
559 bool bPrependCurrencySymbol = true;
560 if( ! (xModelProps->getPropertyValue( FM_PROP_PREPENDCURRENCYSYMBOL ) >>= bPrependCurrencySymbol) )
561 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_PREPENDCURRENCYSYMBOL);
562 pEditWidget->PrependCurrencySymbol = bPrependCurrencySymbol;
563 }
564 } break;
565 case FormComponentType::TIMEFIELD:
566 {
567 pEditWidget->Format = vcl::PDFWriter::Time;
568
569 static constexpr OUStringLiteral FM_PROP_TIMEFORMAT = u"TimeFormat";
570 if ( xPSI->hasPropertyByName( FM_PROP_TIMEFORMAT ) )
571 {
572 sal_Int32 nTimeFormat = 0;
573 if( ! (xModelProps->getPropertyValue( FM_PROP_TIMEFORMAT ) >>= nTimeFormat) )
574 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_TIMEFORMAT);
575
576 switch ( nTimeFormat )
577 {
578 case 0:
579 pEditWidget->TimeFormat = "HH:MM"; //13:45
580 break;
581 case 1:
582 pEditWidget->TimeFormat = "HH:MM:ss"; //13:45:00
583 break;
584 case 2:
585 pEditWidget->TimeFormat = "h:MMtt"; //01:45 PM
586 break;
587 case 3:
588 pEditWidget->TimeFormat = "h:MM:sstt"; //01:45:00 PM
589 break;
590 }
591 }
592 } break;
593 case FormComponentType::DATEFIELD:
594 {
595 pEditWidget->Format = vcl::PDFWriter::Date;
596
597 static constexpr OUStringLiteral FM_PROP_DATEFORMAT = u"DateFormat";
598 if ( xPSI->hasPropertyByName( FM_PROP_DATEFORMAT ) )
599 {
600 sal_Int32 nDateFormat = 0;
601 if( ! (xModelProps->getPropertyValue( FM_PROP_DATEFORMAT ) >>= nDateFormat) )
602 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_DATEFORMAT);
603
604 switch ( nDateFormat )
605 {
606 case 0:
607 case 1:
608 pEditWidget->DateFormat = "mm/dd/yy"; // Standard (short)
609 break;
610 case 2:
611 case 3:
612 pEditWidget->DateFormat = "mm/dd/yyyy"; // Standard (long)
613 break;
614 case 4:
615 pEditWidget->DateFormat = "dd/mm/yy"; // DD/MM/YY
616 break;
617 case 5:
618 pEditWidget->DateFormat = "mm/dd/yy"; // MM/DD/YY
619 break;
620 case 6:
621 pEditWidget->DateFormat = "yy/mm/dd"; // YY/MM/DD
622 break;
623 case 7:
624 pEditWidget->DateFormat = "dd/mm/yyyy"; // DD/MM/YYYY
625 break;
626 case 8:
627 pEditWidget->DateFormat = "mm/dd/yyyy"; // MM/DD/YYYY
628 break;
629 case 9:
630 pEditWidget->DateFormat = "yyyy/mm/dd"; // YYYY/MM/DD
631 break;
632 case 10:
633 pEditWidget->DateFormat = "yy-mm-dd"; // YY-MM-DD
634 break;
635 case 11:
636 pEditWidget->DateFormat = "yyyy-mm-dd"; // YYYY-MM-DD
637 break;
638 }
639 }
640 } break;
641 }
642 }
643
644 // buttons
645 if ( Descriptor->getType() == vcl::PDFWriter::PushButton )
646 {
647 vcl::PDFWriter::PushButtonWidget* pButtonWidget = static_cast< vcl::PDFWriter::PushButtonWidget* >( Descriptor.get() );
648 FormButtonType eButtonType = FormButtonType_PUSH;
649 if( ! (xModelProps->getPropertyValue("ButtonType") >>= eButtonType) )
650 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property ButtonType");
651 static constexpr OUStringLiteral FM_PROP_TARGET_URL = u"TargetURL";
652 if ( eButtonType == FormButtonType_SUBMIT )
653 {
654 // if a button is a submit button, then it uses the URL at its parent form
655 Reference< XChild > xChild( xModelProps, UNO_QUERY );
656 Reference < XPropertySet > xParentProps;
657 if ( xChild.is() )
658 xParentProps.set(xChild->getParent(), css::uno::UNO_QUERY);
659 if ( xParentProps.is() )
660 {
661 Reference< XServiceInfo > xParentSI( xParentProps, UNO_QUERY );
662 if ( xParentSI.is() && xParentSI->supportsService("com.sun.star.form.component.HTMLForm") )
663 {
664 if( ! (xParentProps->getPropertyValue( FM_PROP_TARGET_URL ) >>= pButtonWidget->URL) )
665 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_TARGET_URL);
666 pButtonWidget->Submit = true;
667 FormSubmitMethod eMethod = FormSubmitMethod_POST;
668 if( ! (xParentProps->getPropertyValue("SubmitMethod") >>= eMethod) )
669 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_TARGET_URL);
670 pButtonWidget->SubmitGet = (eMethod == FormSubmitMethod_GET);
671 }
672 }
673 }
674 else if ( eButtonType == FormButtonType_URL )
675 {
676 OUString sURL;
677 if( ! (xModelProps->getPropertyValue( FM_PROP_TARGET_URL ) >>= sURL) )
678 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_TARGET_URL);
679 const bool bDocumentLocalTarget = sURL.startsWith("#");
680 if ( bDocumentLocalTarget )
681 {
682 // Register the destination for future handling ...
683 pButtonWidget->Dest = i_pdfExportData.RegisterDest();
684
685 // and put it into the bookmarks, to ensure the future handling really happens
686 ::std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks( i_pdfExportData.GetBookmarks() );
688 aBookmark.nDestId = pButtonWidget->Dest;
689 aBookmark.aBookmark = sURL;
690 rBookmarks.push_back( aBookmark );
691 }
692 else
693 pButtonWidget->URL = sURL;
694
695 pButtonWidget->Submit = false;
696 }
697
698 // TODO:
699 // In PDF files, buttons are either reset, url or submit buttons. So if we have a simple PUSH button
700 // in a document, then this means that we do not export a SubmitToURL, which means that in PDF,
701 // the button is used as reset button.
702 // Is this desired? If no, we would have to reset Descriptor to NULL here, in case eButtonType
703 // != FormButtonType_SUBMIT && != FormButtonType_RESET
704
705 // the PDF exporter defaults the text style, if 0. To prevent this, we have to transfer the UNO
706 // defaults to the PDF widget
707 if ( pButtonWidget->TextStyle == DrawTextFlags::NONE )
709 }
710
711
712 // check boxes
713 static constexpr OUStringLiteral FM_PROP_STATE = u"State";
714 if ( Descriptor->getType() == vcl::PDFWriter::CheckBox )
715 {
716 vcl::PDFWriter::CheckBoxWidget* pCheckBoxWidget = static_cast< vcl::PDFWriter::CheckBoxWidget* >( Descriptor.get() );
717 sal_Int16 nState = 0;
718 if( ! (xModelProps->getPropertyValue( FM_PROP_STATE ) >>= nState) )
719 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_STATE);
720 pCheckBoxWidget->Checked = ( nState != 0 );
721
722 try
723 {
724 xModelProps->getPropertyValue( "RefValue" ) >>= pCheckBoxWidget->OnValue;
725 }
726 catch(...)
727 {
728 }
729
730 try
731 {
732 xModelProps->getPropertyValue( "SecondaryRefValue" ) >>= pCheckBoxWidget->OffValue;
733 }
734 catch(...)
735 {
736 }
737 }
738
739
740 // radio buttons
741 if ( Descriptor->getType() == vcl::PDFWriter::RadioButton )
742 {
743 vcl::PDFWriter::RadioButtonWidget* pRadioWidget = static_cast< vcl::PDFWriter::RadioButtonWidget* >( Descriptor.get() );
744 sal_Int16 nState = 0;
745 if( ! (xModelProps->getPropertyValue( FM_PROP_STATE ) >>= nState) )
746 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_STATE);
747 pRadioWidget->Selected = ( nState != 0 );
748 pRadioWidget->RadioGroup = determineRadioGroupId( xModelProps );
749 try
750 {
751 xModelProps->getPropertyValue( "RefValue" ) >>= pRadioWidget->OnValue;
752 }
753 catch(...)
754 {
755 }
756
757 try
758 {
759 xModelProps->getPropertyValue( "SecondaryRefValue" ) >>= pRadioWidget->OffValue;
760 }
761 catch(...)
762 {
763 }
764 }
765
766
767 // list boxes
768 if ( Descriptor->getType() == vcl::PDFWriter::ListBox )
769 {
770 vcl::PDFWriter::ListBoxWidget* pListWidget = static_cast< vcl::PDFWriter::ListBoxWidget* >( Descriptor.get() );
771
772 // drop down
773 if( ! (xModelProps->getPropertyValue( "Dropdown" ) >>= pListWidget->DropDown) )
774 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property Dropdown");
775
776 // multi selection
777 if( ! (xModelProps->getPropertyValue("MultiSelection") >>= pListWidget->MultiSelect) )
778 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property MultiSelection");
779
780 // entries
781 getStringItemVector( xModelProps, pListWidget->Entries );
782
783 // get selected items
784 Sequence< sal_Int16 > aSelectIndices;
785 if( ! (xModelProps->getPropertyValue("SelectedItems") >>= aSelectIndices) )
786 SAL_WARN("toolkit.helper", "describePDFControl: unable to get property SelectedItems");
787 if( aSelectIndices.hasElements() )
788 {
789 pListWidget->SelectedEntries.resize( 0 );
790 auto nEntriesSize = static_cast<sal_Int16>(pListWidget->Entries.size());
791 std::copy_if(std::cbegin(aSelectIndices), std::cend(aSelectIndices), std::back_inserter(pListWidget->SelectedEntries),
792 [&nEntriesSize](const sal_Int16 nIndex) { return nIndex >= 0 && nIndex < nEntriesSize; });
793 }
794 }
795
796
797 // combo boxes
798 if ( Descriptor->getType() == vcl::PDFWriter::ComboBox )
799 {
800 vcl::PDFWriter::ComboBoxWidget* pComboWidget = static_cast< vcl::PDFWriter::ComboBoxWidget* >( Descriptor.get() );
801
802 // entries
803 getStringItemVector( xModelProps, pComboWidget->Entries );
804 }
805
806
807 // some post-processing
808
809 // text line ends
810 // some controls may (always or dependent on other settings) return UNIX line ends
811 Descriptor->Text = convertLineEnd(Descriptor->Text, LINEEND_CRLF);
812 }
813 catch( const Exception& )
814 {
815 TOOLS_WARN_EXCEPTION( "toolkit", "describePDFControl" );
816 }
817 return Descriptor;
818 }
819
820
821} // namespace toolkitform
822
823
824/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetFontSize(const Size &)
Definition: font/font.cxx:149
void SetOrientation(Degree10 nLineOrientation)
Definition: font/font.cxx:197
void SetWidthType(FontWidth)
Definition: font/font.cxx:242
void SetStyleName(const OUString &rStyleName)
Definition: font/font.cxx:143
void SetWordLineMode(bool bWordLine)
Definition: font/font.cxx:296
void SetPitch(FontPitch ePitch)
Definition: font/font.cxx:191
void SetItalic(FontItalic)
Definition: font/font.cxx:248
void SetWeight(FontWeight)
Definition: font/font.cxx:236
void SetFamily(FontFamily)
Definition: font/font.cxx:155
void SetUnderline(FontLineStyle)
Definition: font/font.cxx:266
void SetCharSet(rtl_TextEncoding)
Definition: font/font.cxx:161
void SetKerning(FontKerning nKerning)
Definition: font/font.cxx:209
void SetFamilyName(const OUString &rFamilyName)
Definition: font/font.cxx:137
void SetStrikeout(FontStrikeout)
Definition: font/font.cxx:278
std::vector< PDFExtOutDevBookmarkEntry > & GetBookmarks()
sal_Int32 RegisterDest()
registers a destination for which a destination ID needs to be known immediately, instead of later on...
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
float u
sal_Int32 nState
constexpr OUStringLiteral FM_PROP_READONLY
constexpr OUStringLiteral FM_PROP_DATEFORMAT
constexpr OUStringLiteral FM_PROP_CLASSID
#define FM_PROP_BACKGROUNDCOLOR
constexpr OUStringLiteral FM_PROP_TIMEFORMAT
constexpr OUStringLiteral FM_PROP_MULTILINE
constexpr OUStringLiteral FM_PROP_LABEL
constexpr OUStringLiteral FM_PROP_TEXT
constexpr OUStringLiteral FM_PROP_TARGET_URL
constexpr OUStringLiteral FM_PROP_ALIGN
#define FM_PROP_TEXTCOLOR
constexpr OUStringLiteral FM_PROP_STATE
constexpr OUStringLiteral FM_PROP_FONT
constexpr OUStringLiteral FM_PROP_BORDER
constexpr OUStringLiteral FM_PROP_MAXTEXTLEN
constexpr OUStringLiteral FM_PROP_VALUE
constexpr OUStringLiteral FM_PROP_CURRENCYSYMBOL
FontKerning
Definition: fntstyle.hxx:29
FontLineStyle
LINESTYLE_DONTKNOW
FontStrikeout
STRIKEOUT_DONTKNOW
FontPitch
PITCH_DONTKNOW
FontFamily
FAMILY_DONTKNOW
static vcl::Font CreateFont(const css::awt::FontDescriptor &rDescr)
sal_Int32 nIndex
LINEEND_CRLF
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
@ Exception
int i
std::unique_ptr< vcl::PDFWriter::AnyWidget > describePDFControl(const Reference< XControl > &_rxControl, vcl::PDFExtOutDevData &i_pdfExportData)
creates a PDF compatible control descriptor for the given control
constexpr OUStringLiteral FM_PROP_NAME
VCL_DLLPUBLIC css::awt::FontSlant ConvertFontSlant(FontItalic eWeight)
Definition: unohelp.cxx:156
VCL_DLLPUBLIC float ConvertFontWidth(FontWidth eWidth)
Definition: unohelp.cxx:48
VCL_DLLPUBLIC float ConvertFontWeight(FontWeight eWeight)
Definition: unohelp.cxx:102
OUString aBookmark
link target name, respectively destination name
sal_Int32 nDestId
ID of the named destination denoted by the bookmark, or -1 if the entry denotes a link instead of a n...
std::vector< OUString > Entries
Definition: pdfwriter.hxx:444
std::vector< OUString > Entries
Definition: pdfwriter.hxx:423
std::vector< sal_Int32 > SelectedEntries
Definition: pdfwriter.hxx:424