LibreOffice Module extensions (master) 1
standardcontrol.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#include "standardcontrol.hxx"
21#include "pcrcommon.hxx"
22
23#include <com/sun/star/beans/IllegalTypeException.hpp>
24#include <com/sun/star/lang/IllegalArgumentException.hpp>
25#include <com/sun/star/util/DateTime.hpp>
26#include <com/sun/star/util/Date.hpp>
27#include <com/sun/star/util/Time.hpp>
28#include <com/sun/star/util/Color.hpp>
29#include <com/sun/star/util/MeasureUnit.hpp>
30#include <com/sun/star/inspection/PropertyControlType.hpp>
31#include <comphelper/string.hxx>
34
35
36// ugly dependencies for the OColorControl
37#include <svx/svxids.hrc>
38
39#include <tools/datetime.hxx>
40#include <unotools/datetime.hxx>
41#include <o3tl/string_view.hxx>
42
43#include <limits>
44#include <memory>
45
46namespace pcr
47{
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::awt;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::util;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::inspection;
55
56 //= OTimeControl
57 OTimeControl::OTimeControl(std::unique_ptr<weld::FormattedSpinButton> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bReadOnly)
58 : OTimeControl_Base(PropertyControlType::TimeField, std::move(xBuilder), std::move(xWidget), bReadOnly)
59 , m_xFormatter(new weld::TimeFormatter(*getTypedControlWindow()))
60 {
61 m_xFormatter->SetExtFormat(ExtTimeFieldFormat::LongDuration);
62 }
63
64 void SAL_CALL OTimeControl::setValue( const Any& _rValue )
65 {
66 util::Time aUNOTime;
67 if ( !( _rValue >>= aUNOTime ) )
68 {
69 getTypedControlWindow()->set_text("");
71 }
72 else
73 {
74 m_xFormatter->SetTime(::tools::Time(aUNOTime));
75 }
76 }
77
79 {
80 Any aPropValue;
81 if ( !getTypedControlWindow()->get_text().isEmpty() )
82 {
83 aPropValue <<= m_xFormatter->GetTime().GetUNOTime();
84 }
85 return aPropValue;
86 }
87
89 {
90 return ::cppu::UnoType<util::Time>::get();
91 }
92
93 //= ODateControl
94 ODateControl::ODateControl(std::unique_ptr<weld::Container> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bReadOnly)
95 : ODateControl_Base(PropertyControlType::DateField, std::move(xBuilder), std::move(xWidget), bReadOnly)
96 , m_xEntry(m_xBuilder->weld_entry("entry"))
97 , m_xCalendarBox(std::make_unique<SvtCalendarBox>(m_xBuilder->weld_menu_button("button"), false))
98 {
100
101 m_xEntryFormatter->SetStrictFormat(true);
102 m_xEntryFormatter->SetMin(::Date(1, 1, 1600));
103 m_xEntryFormatter->SetMax(::Date(1, 1, 9999));
104
105 m_xEntryFormatter->SetExtDateFormat(ExtDateFieldFormat::SystemShortYYYY);
106 m_xEntryFormatter->EnableEmptyField(true);
107
108 m_xCalendarBox->connect_activated(LINK(this, ODateControl, ActivateHdl));
109
110 m_xCalendarBox->get_button().connect_toggled(LINK(this, ODateControl, ToggleHdl));
111 }
112
114 {
115 m_xEntryFormatter.reset();
116 m_xEntry.reset();
117 m_xCalendarBox.reset();
119 }
120
121 void SAL_CALL ODateControl::setValue( const Any& _rValue )
122 {
123 util::Date aUNODate;
124 if ( !( _rValue >>= aUNODate ) )
125 {
126 m_xEntry->set_text(OUString());
127 }
128 else
129 {
130 ::Date aDate( aUNODate.Day, aUNODate.Month, aUNODate.Year );
131 m_xEntryFormatter->SetDate(aDate);
132 }
133 }
134
136 {
137 m_xEntryFormatter->SetDate(m_xCalendarBox->get_date());
138 setModified();
139 m_xEntry->grab_focus();
140 }
141
142 IMPL_LINK(ODateControl, ToggleHdl, weld::Toggleable&, rToggle, void)
143 {
144 if (!rToggle.get_active())
145 return;
146 ::Date aDate = m_xEntryFormatter->GetDate();
147 if (aDate.IsEmpty())
148 {
149 // with an empty date preselect today in the calendar
150 aDate = ::Date(::Date::SYSTEM);
151 }
152 m_xCalendarBox->set_date(aDate);
153 }
154
156 {
157 Any aPropValue;
158 if (!m_xEntry->get_text().isEmpty())
159 {
160 ::Date aDate(m_xEntryFormatter->GetDate());
161 aPropValue <<= aDate.GetUNODate();
162 }
163 return aPropValue;
164 }
165
167 {
168 return ::cppu::UnoType<util::Date>::get();
169 }
170
171 //= OEditControl
172 OEditControl::OEditControl(std::unique_ptr<weld::Entry> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bPW, bool bReadOnly)
173 : OEditControl_Base( bPW ? PropertyControlType::CharacterField : PropertyControlType::TextField, std::move(xBuilder), std::move(xWidget), bReadOnly )
174 {
175 m_bIsPassword = bPW;
176
177 auto pWidget = getTypedControlWindow();
178 pWidget->set_sensitive(true);
179 pWidget->set_editable(!bReadOnly);
180
181 if (m_bIsPassword)
182 pWidget->set_max_length( 1 );
183 }
184
185 void SAL_CALL OEditControl::setValue( const Any& _rValue )
186 {
187 OUString sText;
188 if ( m_bIsPassword )
189 {
190 sal_Int16 nValue = 0;
191 _rValue >>= nValue;
192 if ( nValue )
193 {
194 sText = OUString(static_cast<sal_Unicode>(nValue));
195 }
196 }
197 else
198 _rValue >>= sText;
199
200 getTypedControlWindow()->set_text( sText );
201 }
202
204 {
205 Any aPropValue;
206
207 OUString sText( getTypedControlWindow()->get_text() );
208 if ( m_bIsPassword )
209 {
210 if ( !sText.isEmpty() )
211 aPropValue <<= static_cast<sal_Int16>(sText[0]);
212 }
213 else
214 aPropValue <<= sText;
215
216 return aPropValue;
217 }
218
220 {
222 }
223
225 {
227
228 // for password controls, we fire a commit for every single change
229 if ( m_bIsPassword )
231 }
232
233 static sal_Int64 ImplCalcLongValue( double nValue, sal_uInt16 nDigits )
234 {
235 double n = nValue;
236 for ( sal_uInt16 d = 0; d < nDigits; ++d )
237 n *= 10;
238
239 return o3tl::saturating_cast<sal_Int64>(n);
240 }
241
242 static double ImplCalcDoubleValue(sal_Int64 nValue, sal_uInt16 nDigits )
243 {
244 double n = nValue;
245 for ( sal_uInt16 d = 0; d < nDigits; ++d )
246 n /= 10;
247 return n;
248 }
249
250 ODateTimeControl::ODateTimeControl(std::unique_ptr<weld::Container> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bReadOnly)
251 : ODateTimeControl_Base(PropertyControlType::DateTimeField, std::move(xBuilder), std::move(xWidget), bReadOnly)
252 , m_xDate(std::make_unique<SvtCalendarBox>(m_xBuilder->weld_menu_button("datefield")))
253 , m_xTime(m_xBuilder->weld_formatted_spin_button("timefield"))
254 , m_xFormatter(new weld::TimeFormatter(*m_xTime))
255 {
256 m_xFormatter->SetExtFormat(ExtTimeFieldFormat::LongDuration);
257 }
258
259 void SAL_CALL ODateTimeControl::setValue( const Any& _rValue )
260 {
261 if ( !_rValue.hasValue() )
262 {
263 m_xDate->set_date(::Date(::Date::SYSTEM));
264 m_xTime->set_text("");
266 }
267 else
268 {
269 util::DateTime aUNODateTime;
270 OSL_VERIFY( _rValue >>= aUNODateTime );
271
272 ::DateTime aDateTime( ::DateTime::EMPTY );
273 ::utl::typeConvert( aUNODateTime, aDateTime );
274
275 m_xDate->set_date(aDateTime);
276 m_xFormatter->SetTime(aDateTime);
277 }
278 }
279
281 {
282 Any aPropValue;
283 if (!m_xTime->get_text().isEmpty())
284 {
285 ::DateTime aDateTime(m_xDate->get_date(), m_xFormatter->GetTime());
286
287 util::DateTime aUNODateTime;
288 ::utl::typeConvert( aDateTime, aUNODateTime );
289
290 aPropValue <<= aUNODateTime;
291 }
292 return aPropValue;
293 }
294
296 {
297 return ::cppu::UnoType<util::DateTime>::get();
298 }
299
300 //= OHyperlinkControl
301 OHyperlinkControl::OHyperlinkControl(std::unique_ptr<weld::Container> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bReadOnly)
302 : OHyperlinkControl_Base(PropertyControlType::HyperlinkField, std::move(xBuilder), std::move(xWidget), bReadOnly)
303 , m_xEntry(m_xBuilder->weld_entry("entry"))
304 , m_xButton(m_xBuilder->weld_button("button"))
305 , m_aActionListeners(m_aMutex)
306 {
307 auto pWidget = getTypedControlWindow();
308 pWidget->set_sensitive(true);
309 m_xEntry->set_editable(!bReadOnly);
310
311 m_xButton->connect_clicked(LINK(this, OHyperlinkControl, OnHyperlinkClicked));
312 }
313
315 {
316 OUString sText = m_xEntry->get_text();
317 return Any( sText );
318 }
319
320 void SAL_CALL OHyperlinkControl::setValue( const Any& _value )
321 {
322 OUString sText;
323 _value >>= sText;
324 m_xEntry->set_text( sText );
325 }
326
328 {
329 return ::cppu::UnoType<OUString>::get();
330 }
331
332 void SAL_CALL OHyperlinkControl::addActionListener( const Reference< XActionListener >& listener )
333 {
334 if ( listener.is() )
336 }
337
338 void SAL_CALL OHyperlinkControl::removeActionListener( const Reference< XActionListener >& listener )
339 {
341 }
342
344 {
345 m_xButton.reset();
346 m_xEntry.reset();
348
349 EventObject aEvent( *this );
351 }
352
353 IMPL_LINK_NOARG( OHyperlinkControl, OnHyperlinkClicked, weld::Button&, void )
354 {
355 ActionEvent aEvent( *this, "clicked" );
356 m_aActionListeners.forEach< XActionListener >(
357 [&aEvent] (uno::Reference<awt::XActionListener> const& xListener)
358 { return xListener->actionPerformed(aEvent); });
359 }
360
361 //= ONumericControl
362 ONumericControl::ONumericControl(std::unique_ptr<weld::MetricSpinButton> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bReadOnly)
363 : ONumericControl_Base(PropertyControlType::NumericField, std::move(xBuilder), std::move(xWidget), bReadOnly)
364 , m_eValueUnit( FieldUnit::NONE )
365 , m_nFieldToUNOValueFactor( 1 )
366 {
367 Optional< double > value( getMaxValue() );
368 value.Value = -value.Value;
370 }
371
373 {
374 return getTypedControlWindow()->get_digits();
375 }
376
377 void SAL_CALL ONumericControl::setDecimalDigits( ::sal_Int16 decimaldigits )
378 {
380 sal_Int64 min, max;
381 pControlWindow->get_range(min, max, FieldUnit::NONE);
382 pControlWindow->set_digits(decimaldigits);
383 pControlWindow->set_range(min, max, FieldUnit::NONE);
384 }
385
386 Optional< double > SAL_CALL ONumericControl::getMinValue()
387 {
388 Optional< double > aReturn( true, 0 );
389
390 sal_Int64 minValue = getTypedControlWindow()->get_min(FieldUnit::NONE);
391 if ( minValue == std::numeric_limits<sal_Int64>::min() )
392 aReturn.IsPresent = false;
393 else
394 aReturn.Value = static_cast<double>(minValue);
395
396 return aReturn;
397 }
398
399 void SAL_CALL ONumericControl::setMinValue( const Optional< double >& _minvalue )
400 {
401 if ( !_minvalue.IsPresent )
402 getTypedControlWindow()->set_min( std::numeric_limits<sal_Int64>::min(), FieldUnit::NONE );
403 else
405 }
406
407 Optional< double > SAL_CALL ONumericControl::getMaxValue()
408 {
409 Optional< double > aReturn( true, 0 );
410
411 sal_Int64 maxValue = getTypedControlWindow()->get_max(FieldUnit::NONE);
412 if ( maxValue == std::numeric_limits<sal_Int64>::max() )
413 aReturn.IsPresent = false;
414 else
415 aReturn.Value = static_cast<double>(maxValue);
416
417 return aReturn;
418 }
419
420 void SAL_CALL ONumericControl::setMaxValue( const Optional< double >& _maxvalue )
421 {
422 if ( !_maxvalue.IsPresent )
423 getTypedControlWindow()->set_max( std::numeric_limits<sal_Int64>::max(), FieldUnit::NONE );
424 else
426 }
427
428 ::sal_Int16 SAL_CALL ONumericControl::getDisplayUnit()
429 {
431 }
432
433 void SAL_CALL ONumericControl::setDisplayUnit( ::sal_Int16 _displayunit )
434 {
435 if ( ( _displayunit < MeasureUnit::MM_100TH ) || ( _displayunit > MeasureUnit::PERCENT ) )
436 throw IllegalArgumentException();
437 if ( ( _displayunit == MeasureUnit::MM_100TH )
438 || ( _displayunit == MeasureUnit::MM_10TH )
439 || ( _displayunit == MeasureUnit::INCH_1000TH )
440 || ( _displayunit == MeasureUnit::INCH_100TH )
441 || ( _displayunit == MeasureUnit::INCH_10TH )
442 || ( _displayunit == MeasureUnit::PERCENT )
443 )
444 throw IllegalArgumentException();
445
446 sal_Int16 nDummyFactor = 1;
447 FieldUnit eFieldUnit = VCLUnoHelper::ConvertToFieldUnit( _displayunit, nDummyFactor );
448 if ( nDummyFactor != 1 )
449 // everything which survived the checks above should result in a factor of 1, i.e.,
450 // it should have a direct counterpart as FieldUnit
451 throw RuntimeException();
452 getTypedControlWindow()->set_unit(eFieldUnit);
453 }
454
455 ::sal_Int16 SAL_CALL ONumericControl::getValueUnit()
456 {
458 }
459
460 void SAL_CALL ONumericControl::setValueUnit( ::sal_Int16 _valueunit )
461 {
462 if ( ( _valueunit < MeasureUnit::MM_100TH ) || ( _valueunit > MeasureUnit::PERCENT ) )
463 throw IllegalArgumentException();
465 }
466
467 void SAL_CALL ONumericControl::setValue( const Any& _rValue )
468 {
469 if ( !_rValue.hasValue() )
470 {
471 getTypedControlWindow()->set_text( "" );
472 }
473 else
474 {
475 double nValue( 0 );
476 OSL_VERIFY( _rValue >>= nValue );
479 }
480 }
481
482 sal_Int64 ONumericControl::impl_apiValueToFieldValue_nothrow( double _nApiValue ) const
483 {
484 sal_Int64 nControlValue = ImplCalcLongValue( _nApiValue, getTypedControlWindow()->get_digits() );
486 return nControlValue;
487 }
488
489 double ONumericControl::impl_fieldValueToApiValue_nothrow(sal_Int64 nFieldValue) const
490 {
491 double nApiValue = ImplCalcDoubleValue( nFieldValue, getTypedControlWindow()->get_digits() );
492 nApiValue *= m_nFieldToUNOValueFactor;
493 return nApiValue;
494 }
495
497 {
498 Any aPropValue;
499 if ( !getTypedControlWindow()->get_text().isEmpty() )
500 {
502 if (nValue)
503 aPropValue <<= nValue;
504 }
505 return aPropValue;
506 }
507
509 {
510 return ::cppu::UnoType<double>::get();
511 }
512
513 //= OColorControl
514 OColorControl::OColorControl(std::unique_ptr<ColorListBox> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bReadOnly)
515 : OColorControl_Base(PropertyControlType::ColorListBox, std::move(xBuilder), std::move(xWidget), bReadOnly)
516 {
517 getTypedControlWindow()->SetSlotId(SID_FM_CTL_PROPERTIES);
518 }
519
520 void SAL_CALL OColorControl::setValue( const Any& _rValue )
521 {
522 css::util::Color nColor = sal_uInt32(COL_TRANSPARENT);
523 if (_rValue.hasValue())
524 _rValue >>= nColor;
525 getTypedControlWindow()->SelectEntry(::Color(ColorTransparency, nColor));
526 }
527
529 {
530 Any aPropValue;
531 ::Color aRgbCol = getTypedControlWindow()->GetSelectEntryColor();
532 if (aRgbCol == COL_TRANSPARENT)
533 return aPropValue;
534 aPropValue <<= aRgbCol;
535 return aPropValue;
536 }
537
539 {
540 return ::cppu::UnoType<sal_Int32>::get();
541 }
542
544 {
546
547 // fire a commit
549 }
550
551 //= OListboxControl
552 OListboxControl::OListboxControl(std::unique_ptr<weld::ComboBox> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bReadOnly)
553 : OListboxControl_Base(PropertyControlType::ListBox, std::move(xBuilder), std::move(xWidget), bReadOnly)
554 {
555 }
556
558 {
559 OUString sControlValue( getTypedControlWindow()->get_active_text() );
560
561 Any aPropValue;
562 if ( !sControlValue.isEmpty() )
563 aPropValue <<= sControlValue;
564 return aPropValue;
565 }
566
568 {
569 return ::cppu::UnoType<OUString>::get();
570 }
571
572 void SAL_CALL OListboxControl::setValue( const Any& _rValue )
573 {
574 if ( !_rValue.hasValue() )
575 getTypedControlWindow()->set_active(-1);
576 else
577 {
578 OUString sSelection;
579 _rValue >>= sSelection;
580
581 if (getTypedControlWindow()->find_text(sSelection) == -1)
582 getTypedControlWindow()->insert_text(0, sSelection);
583
584 if (sSelection != getTypedControlWindow()->get_active_text())
585 getTypedControlWindow()->set_active_text(sSelection);
586 }
587 }
588
590 {
591 getTypedControlWindow()->clear();
592 }
593
594 void SAL_CALL OListboxControl::prependListEntry( const OUString& NewEntry )
595 {
596 getTypedControlWindow()->insert_text(0, NewEntry);
597 }
598
599 void SAL_CALL OListboxControl::appendListEntry( const OUString& NewEntry )
600 {
601 getTypedControlWindow()->append_text(NewEntry);
602 }
603
604 Sequence< OUString > SAL_CALL OListboxControl::getListEntries()
605 {
606 const sal_Int32 nCount = getTypedControlWindow()->get_count();
607 Sequence< OUString > aRet(nCount);
608 OUString* pIter = aRet.getArray();
609 for (sal_Int32 i = 0; i < nCount ; ++i,++pIter)
610 *pIter = getTypedControlWindow()->get_text(i);
611
612 return aRet;
613 }
614
616 {
618
619 // fire a commit
621 }
622
623 //= OComboboxControl
624 OComboboxControl::OComboboxControl(std::unique_ptr<weld::ComboBox> xWidget, std::unique_ptr<weld::Builder> xBuilder, bool bReadOnly)
625 : OComboboxControl_Base(PropertyControlType::ComboBox, std::move(xBuilder), std::move(xWidget), bReadOnly)
626 {
627 getTypedControlWindow()->connect_changed( LINK( this, OComboboxControl, OnEntrySelected ) );
628 }
629
630 void SAL_CALL OComboboxControl::setValue( const Any& _rValue )
631 {
632 OUString sText;
633 _rValue >>= sText;
634 weld::ComboBox* pControlWindow = getTypedControlWindow();
635 // tdf#138701 leave current cursor valid if the contents won't change
636 if (pControlWindow->get_active_text() != sText)
637 pControlWindow->set_entry_text(sText);
638 }
639
641 {
642 return Any( getTypedControlWindow()->get_active_text() );
643 }
644
646 {
647 return ::cppu::UnoType<OUString>::get();
648 }
649
651 {
652 getTypedControlWindow()->clear();
653 }
654
655 void SAL_CALL OComboboxControl::prependListEntry( const OUString& NewEntry )
656 {
657 getTypedControlWindow()->insert_text(0, NewEntry);
658 }
659
660 void SAL_CALL OComboboxControl::appendListEntry( const OUString& NewEntry )
661 {
662 getTypedControlWindow()->append_text( NewEntry );
663 }
664
665 Sequence< OUString > SAL_CALL OComboboxControl::getListEntries( )
666 {
667 const sal_Int32 nCount = getTypedControlWindow()->get_count();
668 Sequence< OUString > aRet(nCount);
669 OUString* pIter = aRet.getArray();
670 for (sal_Int32 i = 0; i < nCount ; ++i,++pIter)
671 *pIter = getTypedControlWindow()->get_text(i);
672
673 return aRet;
674 }
675
677 {
678 // fire a commit
679 notifyModifiedValue();
680 }
681
682 namespace
683 {
684
685 StlSyntaxSequence< OUString > lcl_convertMultiLineToList( std::u16string_view _rCompsedTextWithLineBreaks )
686 {
687 sal_Int32 nLines = comphelper::string::getTokenCount(_rCompsedTextWithLineBreaks, '\n');
688 StlSyntaxSequence< OUString > aStrings( nLines );
689 if (nLines)
690 {
691 StlSyntaxSequence< OUString >::iterator stringItem = aStrings.begin();
692 sal_Int32 nIdx {0};
693 do
694 {
695 *stringItem = o3tl::getToken(_rCompsedTextWithLineBreaks, 0, '\n', nIdx );
696 ++stringItem;
697 }
698 while (nIdx>0);
699 }
700 return aStrings;
701 }
702
703 OUString lcl_convertListToMultiLine( const StlSyntaxSequence< OUString >& _rStrings )
704 {
705 OUStringBuffer sMultiLineText;
706 for ( StlSyntaxSequence< OUString >::const_iterator item = _rStrings.begin();
707 item != _rStrings.end();
708 )
709 {
710 sMultiLineText.append(*item);
711 if ( ++item != _rStrings.end() )
712 sMultiLineText.append("\n");
713 }
714 return sMultiLineText.makeStringAndClear();
715 }
716
717
718 OUString lcl_convertListToDisplayText( const StlSyntaxSequence< OUString >& _rStrings )
719 {
720 OUStringBuffer aComposed;
721 for ( StlSyntaxSequence< OUString >::const_iterator strings = _rStrings.begin();
722 strings != _rStrings.end();
723 ++strings
724 )
725 {
726 if ( strings != _rStrings.begin() )
727 aComposed.append( ';' );
728 aComposed.append( "\"" + *strings + "\"" );
729 }
730 return aComposed.makeStringAndClear();
731 }
732 }
733
735 {
736 // if there are newlines or something else which the entry cannot show, then make
737 // just the multiline dropdown editable as the canonical source for text
738 m_xEntry->set_sensitive(m_xEntry->get_text() == m_xTextView->get_text());
739 }
740
742 {
743 m_xEntry->set_text(lcl_convertListToDisplayText(rStrings));
744 m_xTextView->set_text(lcl_convertListToMultiLine(rStrings));
746 }
747
749 {
750 return lcl_convertMultiLineToList(m_xTextView->get_text());
751 }
752
753 void OMultilineEditControl::SetTextValue(const OUString& rText)
754 {
755 OSL_PRECOND( m_nOperationMode == eMultiLineText, "OMultilineEditControl::SetTextValue: illegal call!" );
756
757 m_xTextView->set_text(rText);
758 m_xEntry->set_text(rText);
760 }
761
763 {
764 OSL_PRECOND( m_nOperationMode == eMultiLineText, "OMultilineEditControl::GetTextValue: illegal call!" );
765 return m_xTextView->get_text();
766 }
767
768 //= OMultilineEditControl
769 OMultilineEditControl::OMultilineEditControl(std::unique_ptr<weld::Container> xWidget, std::unique_ptr<weld::Builder> xBuilder, MultiLineOperationMode eMode, bool bReadOnly)
770 : OMultilineEditControl_Base(eMode == eMultiLineText ? PropertyControlType::MultiLineTextField : PropertyControlType::StringListField,
771 std::move(xBuilder), std::move(xWidget), bReadOnly)
772 , m_nOperationMode(eMode)
773 , m_xEntry(m_xBuilder->weld_entry("entry"))
774 , m_xButton(m_xBuilder->weld_menu_button("button"))
775 , m_xPopover(m_xBuilder->weld_widget("popover"))
776 , m_xTextView(m_xBuilder->weld_text_view("textview"))
777 , m_xOk(m_xBuilder->weld_button("ok"))
778 {
779 m_xButton->set_popover(m_xPopover.get());
780 m_xTextView->set_size_request(m_xTextView->get_approximate_digit_width() * 30, m_xTextView->get_height_rows(8));
781 m_xOk->connect_clicked(LINK(this, OMultilineEditControl, ButtonHandler));
782 }
783
785 {
786 // tdf#139070 during editing update the entry to look like how it will
787 // look once editing is finished so that the default behaviour of vcl
788 // to strip newlines and the default behaviour of gtk to show a newline
789 // symbol is suppressed
790 OUString sText = m_xTextView->get_text();
791 auto aSeq = lcl_convertMultiLineToList(sText);
792 if (aSeq.getLength() > 1)
793 m_xEntry->set_text(lcl_convertListToDisplayText(aSeq));
794 else
795 m_xEntry->set_text(sText);
796 CheckEntryTextViewMisMatch();
797 setModified();
798 }
799
801 {
802 m_xTextView->set_text(m_xEntry->get_text());
804 setModified();
805 }
806
808 {
809 m_xButton->set_active(false);
810 notifyModifiedValue();
811 }
812
813 void SAL_CALL OMultilineEditControl::setValue( const Any& _rValue )
814 {
816
817 switch (m_nOperationMode)
818 {
819 case eMultiLineText:
820 {
821 OUString sText;
822 if ( !( _rValue >>= sText ) && _rValue.hasValue() )
823 throw IllegalTypeException();
824 SetTextValue(sText);
825 break;
826 }
827 case eStringList:
828 {
829 Sequence< OUString > aStringLines;
830 if ( !( _rValue >>= aStringLines ) && _rValue.hasValue() )
831 throw IllegalTypeException();
833 break;
834 }
835 }
836 }
837
839 {
841
842 Any aValue;
843 switch (m_nOperationMode)
844 {
845 case eMultiLineText:
846 aValue <<= GetTextValue();
847 break;
848 case eStringList:
849 aValue <<= GetStringListValue();
850 break;
851 }
852 return aValue;
853 }
854
856 {
858 return ::cppu::UnoType<OUString>::get();
860 }
861
862} // namespace pcr
863
864/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define min(a, b)
Definition: StdAfx2.h:50
AnyEventRef aEvent
double d
sal_Int32 GetDate() const
css::util::Date GetUNODate() const
bool IsEmpty() const
static sal_Int16 ConvertToMeasurementUnit(FieldUnit _nFieldUnit, sal_Int16 _rFieldToUNOValueFactor)
static FieldUnit ConvertToFieldUnit(sal_Int16 _nMeasurementUnit, sal_Int16 &_rFieldToUNOValueFactor)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
css::uno::Type const & get()
implements a base class for <type scope="css::inspection">XPropertyControl</type> implementations
virtual void SAL_CALL notifyModifiedValue() override
TControlWindow * getTypedControlWindow()
void impl_checkDisposed_throw()
checks whether the instance is already disposed
virtual void SAL_CALL disposing() override
virtual void setModified() override
virtual css::uno::Type SAL_CALL getValueType() override
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
virtual css::uno::Any SAL_CALL getValue() override
OColorControl(std::unique_ptr< ColorListBox > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bReadOnly)
virtual void SAL_CALL appendListEntry(const OUString &NewEntry) override
virtual css::uno::Type SAL_CALL getValueType() override
virtual void SAL_CALL clearList() override
virtual css::uno::Any SAL_CALL getValue() override
virtual void SAL_CALL prependListEntry(const OUString &NewEntry) override
virtual css::uno::Sequence< OUString > SAL_CALL getListEntries() override
OComboboxControl(std::unique_ptr< weld::ComboBox > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bReadOnly)
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
std::unique_ptr< weld::Entry > m_xEntry
std::unique_ptr< weld::DateFormatter > m_xEntryFormatter
ODateControl(std::unique_ptr< weld::Container > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bReadOnly)
virtual css::uno::Type SAL_CALL getValueType() override
virtual void SAL_CALL disposing() override
virtual css::uno::Any SAL_CALL getValue() override
std::unique_ptr< SvtCalendarBox > m_xCalendarBox
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
std::unique_ptr< SvtCalendarBox > m_xDate
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
std::unique_ptr< weld::FormattedSpinButton > m_xTime
virtual css::uno::Any SAL_CALL getValue() override
std::unique_ptr< weld::TimeFormatter > m_xFormatter
ODateTimeControl(std::unique_ptr< weld::Container > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bReadOnly)
virtual css::uno::Type SAL_CALL getValueType() override
virtual void setModified() override
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
virtual css::uno::Any SAL_CALL getValue() override
OEditControl(std::unique_ptr< weld::Entry > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bPassWord, bool bReadOnly)
virtual css::uno::Type SAL_CALL getValueType() override
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
virtual css::uno::Type SAL_CALL getValueType() override
OHyperlinkControl(std::unique_ptr< weld::Container > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bReadOnly)
virtual void SAL_CALL addActionListener(const css::uno::Reference< css::awt::XActionListener > &listener) override
virtual css::uno::Any SAL_CALL getValue() override
virtual void SAL_CALL removeActionListener(const css::uno::Reference< css::awt::XActionListener > &listener) override
std::unique_ptr< weld::Button > m_xButton
virtual void SAL_CALL disposing() override
std::unique_ptr< weld::Entry > m_xEntry
::comphelper::OInterfaceContainerHelper2 m_aActionListeners
OListboxControl(std::unique_ptr< weld::ComboBox > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bReadOnly)
virtual css::uno::Type SAL_CALL getValueType() override
virtual void SAL_CALL appendListEntry(const OUString &NewEntry) override
virtual css::uno::Any SAL_CALL getValue() override
virtual void setModified() override
virtual css::uno::Sequence< OUString > SAL_CALL getListEntries() override
virtual void SAL_CALL prependListEntry(const OUString &NewEntry) override
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
virtual void SAL_CALL clearList() override
std::unique_ptr< weld::Entry > m_xEntry
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
virtual css::uno::Any SAL_CALL getValue() override
StlSyntaxSequence< OUString > GetStringListValue() const
std::unique_ptr< weld::Button > m_xOk
MultiLineOperationMode m_nOperationMode
std::unique_ptr< weld::MenuButton > m_xButton
std::unique_ptr< weld::TextView > m_xTextView
virtual void editChanged() override
void SetTextValue(const OUString &rText)
std::unique_ptr< weld::Widget > m_xPopover
OMultilineEditControl(std::unique_ptr< weld::Container > xWidget, std::unique_ptr< weld::Builder > xBuilder, MultiLineOperationMode eMode, bool bReadOnly)
void SetStringListValue(const StlSyntaxSequence< OUString > &_rStrings)
virtual css::uno::Type SAL_CALL getValueType() override
ONumericControl(std::unique_ptr< weld::MetricSpinButton > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bReadOnly)
virtual void SAL_CALL setDisplayUnit(::sal_Int16 _displayunit) override
virtual css::uno::Type SAL_CALL getValueType() override
sal_Int64 impl_apiValueToFieldValue_nothrow(double nApiValue) const
converts an API value (double, as passed into set[Max|Min|]Value) into a int value which can be passe...
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
virtual void SAL_CALL setValueUnit(::sal_Int16 _valueunit) override
virtual void SAL_CALL setDecimalDigits(::sal_Int16 _decimaldigits) override
double impl_fieldValueToApiValue_nothrow(sal_Int64 nFieldValue) const
converts a control value, as obtained from our Numeric field, into a value which can passed to outer ...
virtual css::uno::Any SAL_CALL getValue() override
virtual ::sal_Int16 SAL_CALL getDecimalDigits() override
virtual css::beans::Optional< double > SAL_CALL getMaxValue() override
virtual ::sal_Int16 SAL_CALL getDisplayUnit() override
virtual ::sal_Int16 SAL_CALL getValueUnit() override
sal_Int16 m_nFieldToUNOValueFactor
virtual css::beans::Optional< double > SAL_CALL getMinValue() override
virtual void SAL_CALL setMaxValue(const css::beans::Optional< double > &_maxvalue) override
virtual void SAL_CALL setMinValue(const css::beans::Optional< double > &_minvalue) override
OTimeControl(std::unique_ptr< weld::FormattedSpinButton > xWidget, std::unique_ptr< weld::Builder > xBuilder, bool bReadOnly)
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
virtual css::uno::Any SAL_CALL getValue() override
virtual css::uno::Type SAL_CALL getValueType() override
std::unique_ptr< weld::TimeFormatter > m_xFormatter
const ELEMENT * const_iterator
Definition: pcrcommon.hxx:84
virtual OUString get_active_text() const=0
virtual void set_entry_text(const OUString &rStr)=0
void set_range(sal_Int64 min, sal_Int64 max, FieldUnit eValueUnit)
void get_range(sal_Int64 &min, sal_Int64 &max, FieldUnit eDestUnit) const
void set_digits(unsigned int digits)
ColorTransparency
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
Any value
int nCount
#define max(a, b)
FieldUnit
sal_Int16 nValue
bool bReadOnly
sal_Int16 nControlValue
Mode eMode
sal_Int64 n
Sequence< sal_Int8 > aSeq
::osl::Mutex m_aMutex
Definition: logger.cxx:98
NONE
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
Type
int i
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
a property handler for any virtual string properties
Definition: browserline.cxx:39
static sal_Int64 ImplCalcLongValue(double nValue, sal_uInt16 nDigits)
MultiLineOperationMode
@ eMultiLineText
IMPL_LINK(OBrowserLine, OnButtonClicked, weld::Button &, rButton, void)
static double ImplCalcDoubleValue(sal_Int64 nValue, sal_uInt16 nDigits)
IMPL_LINK_NOARG(OBrowserLine, OnButtonFocus, weld::Widget &, void)
sal_uInt16 sal_Unicode