LibreOffice Module vcl (master) 1
fmtfield.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 <tools/debug.hxx>
21#include <boost/property_tree/json_parser.hpp>
23#include <comphelper/string.hxx>
25#include <vcl/builder.hxx>
26#include <vcl/event.hxx>
27#include <vcl/settings.hxx>
28#include <vcl/commandevent.hxx>
29#include <svl/zformat.hxx>
33#include <vcl/weld.hxx>
36#include <limits>
37#include <map>
38#include <rtl/math.hxx>
39#include <rtl/ustrbuf.hxx>
40#include <sal/log.hxx>
41#include <svl/numformat.hxx>
42#include <osl/diagnose.h>
43#include <tools/json_writer.hxx>
44
45using namespace ::com::sun::star::lang;
46using namespace ::com::sun::star::util;
47
48// hmm. No support for regular expression. Well, I always (not really :) wanted to write a finite automat
49// so here comes a finite automat ...
50
51namespace validation
52{
54 {
55 _rRow.insert( Transition( '_', END ) );
56 }
57
59 {
60 _rRow.insert( Transition( 'e', EXPONENT_START ) );
61 }
62
63 static void lcl_insertSignTransitions( StateTransitions& _rRow, const State eNextState )
64 {
65 _rRow.insert( Transition( '-', eNextState ) );
66 _rRow.insert( Transition( '+', eNextState ) );
67 }
68
69 static void lcl_insertDigitTransitions( StateTransitions& _rRow, const State eNextState )
70 {
71 for ( sal_Unicode aChar = '0'; aChar <= '9'; ++aChar )
72 _rRow.insert( Transition( aChar, eNextState ) );
73 }
74
75 static void lcl_insertCommonPreCommaTransitions( StateTransitions& _rRow, const sal_Unicode _cThSep, const sal_Unicode _cDecSep )
76 {
77 // digits are allowed
79
80 // the thousand separator is allowed
81 _rRow.insert( Transition( _cThSep, DIGIT_PRE_COMMA ) );
82
83 // a comma is allowed
84 _rRow.insert( Transition( _cDecSep, DIGIT_POST_COMMA ) );
85 }
86
88 {
89 // build up our transition table
90
91 // how to proceed from START
92 {
94 rRow.insert( Transition( '_', NUM_START ) );
95 // if we encounter the normalizing character, we want to proceed with the number
96 }
97
98 // how to proceed from NUM_START
99 {
101
102 // a sign is allowed
104
105 // common transitions for the two pre-comma states
106 lcl_insertCommonPreCommaTransitions( rRow, _cThSep, _cDecSep );
107
108 // the exponent may start here
109 // (this would mean string like "_+e10_", but this is a valid fragment, though no valid number)
111 }
112
113 // how to proceed from DIGIT_PRE_COMMA
114 {
116
117 // common transitions for the two pre-comma states
118 lcl_insertCommonPreCommaTransitions( rRow, _cThSep, _cDecSep );
119
120 // the exponent may start here
122
123 // the final transition indicating the end of the string
124 // (if there is no comma and no post-comma, then the string may end here)
126 }
127
128 // how to proceed from DIGIT_POST_COMMA
129 {
131
132 // there might be digits, which would keep the state at DIGIT_POST_COMMA
134
135 // the exponent may start here
137
138 // the string may end here
140 }
141
142 // how to proceed from EXPONENT_START
143 {
145
146 // there may be a sign
148
149 // there may be digits
151
152 // the string may end here
154 }
155
156 // how to proceed from EXPONENT_DIGIT
157 {
159
160 // there may be digits
162
163 // the string may end here
165 }
166
167 // how to proceed from END
168 {
169 /*StateTransitions& rRow =*/ m_aTransitions[ EXPONENT_DIGIT ];
170 // no valid transition to leave this state
171 // (note that we, for consistency, nevertheless want to have a row in the table)
172 }
173 }
174
175 bool NumberValidator::implValidateNormalized( const OUString& _rText )
176 {
177 const sal_Unicode* pCheckPos = _rText.getStr();
178 State eCurrentState = START;
179
180 while ( END != eCurrentState )
181 {
182 // look up the transition row for the current state
183 TransitionTable::const_iterator aRow = m_aTransitions.find( eCurrentState );
184 DBG_ASSERT( m_aTransitions.end() != aRow,
185 "NumberValidator::implValidateNormalized: invalid transition table (row not found)!" );
186
187 if ( m_aTransitions.end() != aRow )
188 {
189 // look up the current character in this row
190 StateTransitions::const_iterator aTransition = aRow->second.find( *pCheckPos );
191 if ( aRow->second.end() != aTransition )
192 {
193 // there is a valid transition for this character
194 eCurrentState = aTransition->second;
195 ++pCheckPos;
196 continue;
197 }
198 }
199
200 // if we're here, there is no valid transition
201 break;
202 }
203
204 DBG_ASSERT( ( END != eCurrentState ) || ( 0 == *pCheckPos ),
205 "NumberValidator::implValidateNormalized: inconsistency!" );
206 // if we're at END, then the string should be done, too - the string should be normalized, means ending
207 // a "_" and not containing any other "_" (except at the start), and "_" is the only possibility
208 // to reach the END state
209
210 // the string is valid if and only if we reached the final state
211 return ( END == eCurrentState );
212 }
213
214 bool NumberValidator::isValidNumericFragment( std::u16string_view _rText )
215 {
216 if ( _rText.empty() )
217 // empty strings are always allowed
218 return true;
219
220 // normalize the string
221 OUString sNormalized = OUString::Concat("_") + _rText + "_";
222
223 return implValidateNormalized( sNormalized );
224 }
225}
226
229
230SvNumberFormatter* Formatter::StaticFormatter::GetFormatter()
231{
232 if (!s_cFormatter)
233 {
234 // get the Office's locale and translate
235 LanguageType eSysLanguage = SvtSysLocale().GetLanguageTag().getLanguageType( false);
237 ::comphelper::getProcessComponentContext(),
238 eSysLanguage);
239 }
240 return s_cFormatter;
241}
242
244{
245 ++s_nReferences;
246}
247
249{
250 if (--s_nReferences == 0)
251 {
252 delete s_cFormatter;
253 s_cFormatter = nullptr;
254 }
255}
256
258 :m_aLastSelection(0,0)
259 ,m_dMinValue(0)
260 ,m_dMaxValue(0)
261 ,m_bHasMin(false)
262 ,m_bHasMax(false)
263 ,m_bWrapOnLimits(false)
264 ,m_bStrictFormat(true)
266 ,m_bAutoColor(false)
267 ,m_bEnableNaN(false)
269 ,m_bDefaultValueSet(false)
273 ,m_nFormatKey(0)
274 ,m_pFormatter(nullptr)
275 ,m_dSpinSize(1)
276 ,m_dSpinFirst(-1000000)
277 ,m_dSpinLast(1000000)
278 ,m_bTreatAsNumber(true)
279 ,m_pLastOutputColor(nullptr)
281{
282}
283
285{
286}
287
288void Formatter::SetFieldText(const OUString& rStr, const Selection& rNewSelection)
289{
290 SetEntryText(rStr, rNewSelection);
292}
293
294void Formatter::SetTextFormatted(const OUString& rStr)
295{
296 SAL_INFO_IF(GetOrCreateFormatter()->IsTextFormat(m_nFormatKey), "svtools",
297 "FormattedField::SetTextFormatted : valid only with text formats !");
298
299 m_sCurrentTextValue = rStr;
300
301 OUString sFormatted;
302 double dNumber = 0.0;
303 // IsNumberFormat changes the format key parameter
304 sal_uInt32 nTempFormatKey = static_cast< sal_uInt32 >( m_nFormatKey );
306 GetOrCreateFormatter()->IsNumberFormat(m_sCurrentTextValue, nTempFormatKey, dNumber) )
307 {
309 }
310 else
311 {
314 sFormatted,
316 }
317
318 // calculate the new selection
320 Selection aNewSel(aSel);
321 aNewSel.Normalize();
322 sal_Int32 nNewLen = sFormatted.getLength();
323 sal_Int32 nCurrentLen = GetEntryText().getLength();
324 if ((nNewLen > nCurrentLen) && (aNewSel.Max() == nCurrentLen))
325 { // the new text is longer and the cursor was behind the last char (of the old text)
326 if (aNewSel.Min() == 0)
327 { // the whole text was selected -> select the new text on the whole, too
328 aNewSel.Max() = nNewLen;
329 if (!nCurrentLen)
330 { // there wasn't really a previous selection (as there was no previous text), we're setting a new one -> check the selection options
332 if (nSelOptions & SelectionOptions::ShowFirst)
333 { // selection should be from right to left -> swap min and max
334 aNewSel.Min() = aNewSel.Max();
335 aNewSel.Max() = 0;
336 }
337 }
338 }
339 else if (aNewSel.Max() == aNewSel.Min())
340 { // there was no selection -> set the cursor behind the new last char
341 aNewSel.Max() = nNewLen;
342 aNewSel.Min() = nNewLen;
343 }
344 }
345 else if (aNewSel.Max() > nNewLen)
346 aNewSel.Max() = nNewLen;
347 else
348 aNewSel = aSel; // don't use the justified version
349 SetEntryText(sFormatted, aNewSel);
351}
352
353OUString const & Formatter::GetTextValue() const
354{
356 {
357 const_cast<Formatter*>(this)->m_sCurrentTextValue = GetEntryText();
358 const_cast<Formatter*>(this)->m_ValueState = valueString;
359 }
360 return m_sCurrentTextValue;
361}
362
364{
365 if ( m_bEnableNaN == _bEnable )
366 return;
367
368 m_bEnableNaN = _bEnable;
369}
370
371void Formatter::SetAutoColor(bool _bAutomatic)
372{
373 if (_bAutomatic == m_bAutoColor)
374 return;
375
376 m_bAutoColor = _bAutomatic;
377 if (m_bAutoColor)
378 {
379 // if auto color is switched on, adjust the current text color, too
381 }
382}
383
384void Formatter::Modify(bool makeValueDirty)
385{
386 if (!IsStrictFormat())
387 {
388 if(makeValueDirty)
391 return;
392 }
393
394 OUString sCheck = GetEntryText();
395 if (CheckText(sCheck))
396 {
397 m_sLastValidText = sCheck;
399 if(makeValueDirty)
401 }
402 else
403 {
405 }
406
408}
409
410void Formatter::ImplSetTextImpl(const OUString& rNew, Selection const * pNewSel)
411{
412 if (m_bAutoColor)
414
415 if (pNewSel)
416 SetEntryText(rNew, *pNewSel);
417 else
418 {
420 aSel.Normalize();
421
422 sal_Int32 nNewLen = rNew.getLength();
423 sal_Int32 nCurrentLen = GetEntryText().getLength();
424
425 if ((nNewLen > nCurrentLen) && (aSel.Max() == nCurrentLen))
426 { // new text is longer and the cursor is behind the last char
427 if (aSel.Min() == 0)
428 {
429 if (!nCurrentLen)
430 { // there wasn't really a previous selection (as there was no previous text)
431 aSel.Max() = 0;
432 }
433 else
434 { // the whole text was selected -> select the new text on the whole, too
435 aSel.Max() = nNewLen;
436 }
437 }
438 else if (aSel.Max() == aSel.Min())
439 { // there was no selection -> set the cursor behind the new last char
440 aSel.Max() = nNewLen;
441 aSel.Min() = nNewLen;
442 }
443 }
444 else if (aSel.Max() > nNewLen)
445 aSel.Max() = nNewLen;
446 SetEntryText(rNew, aSel);
447 }
448
449 m_ValueState = valueDirty; // not always necessary, but better re-evaluate for safety reasons
450}
451
453{
454 m_nFormatKey = nFormatKey;
455 bool bNeedFormatter = (m_pFormatter == nullptr) && (nFormatKey != 0);
456 if (bNeedFormatter)
457 {
458 GetOrCreateFormatter(); // this creates a standard formatter
459
460 // It might happen that the standard formatter makes no sense here, but it takes a default
461 // format. Thus, it is possible to set one of the other standard keys (which are spanning
462 // across multiple formatters).
463 m_nFormatKey = nFormatKey;
464 // When calling SetFormatKey without a formatter, the key must be one of the standard values
465 // that is available for all formatters (and, thus, also in this new one).
466 DBG_ASSERT(m_pFormatter->GetEntry(nFormatKey) != nullptr, "FormattedField::ImplSetFormatKey : invalid format key !");
467 }
468}
469
471{
472 bool bNoFormatter = (m_pFormatter == nullptr);
473 ImplSetFormatKey(nFormatKey);
475}
476
477void Formatter::SetFormatter(SvNumberFormatter* pFormatter, bool bResetFormat)
478{
479
480 if (bResetFormat)
481 {
482 m_pFormatter = pFormatter;
483
484 // calc the default format key from the Office's UI locale
485 if ( m_pFormatter )
486 {
487 // get the Office's locale and translate
488 LanguageType eSysLanguage = SvtSysLocale().GetLanguageTag().getLanguageType( false);
489 // get the standard numeric format for this language
490 m_nFormatKey = m_pFormatter->GetStandardFormat( SvNumFormatType::NUMBER, eSysLanguage );
491 }
492 else
493 m_nFormatKey = 0;
494 }
495 else
496 {
497 LanguageType aOldLang;
498 OUString sOldFormat = GetFormat(aOldLang);
499
500 sal_uInt32 nDestKey = pFormatter->TestNewString(sOldFormat);
501 if (nDestKey == NUMBERFORMAT_ENTRY_NOT_FOUND)
502 {
503 // language of the new formatter
504 const SvNumberformat* pDefaultEntry = pFormatter->GetEntry(0);
505 LanguageType aNewLang = pDefaultEntry ? pDefaultEntry->GetLanguage() : LANGUAGE_DONTKNOW;
506
507 // convert the old format string into the new language
508 sal_Int32 nCheckPos;
510 pFormatter->PutandConvertEntry(sOldFormat, nCheckPos, nType, nDestKey, aOldLang, aNewLang, true);
511 m_nFormatKey = nDestKey;
512 }
513 m_pFormatter = pFormatter;
514 }
515
517}
518
519OUString Formatter::GetFormat(LanguageType& eLang) const
520{
522 DBG_ASSERT(pFormatEntry != nullptr, "FormattedField::GetFormat: no number format for the given format key.");
523 OUString sFormatString = pFormatEntry ? pFormatEntry->GetFormatstring() : OUString();
524 eLang = pFormatEntry ? pFormatEntry->GetLanguage() : LANGUAGE_DONTKNOW;
525
526 return sFormatString;
527}
528
529bool Formatter::SetFormat(const OUString& rFormatString, LanguageType eLang)
530{
531 sal_uInt32 nNewKey = GetOrCreateFormatter()->TestNewString(rFormatString, eLang);
532 if (nNewKey == NUMBERFORMAT_ENTRY_NOT_FOUND)
533 {
534 sal_Int32 nCheckPos;
536 OUString rFormat(rFormatString);
537 if (!GetOrCreateFormatter()->PutEntry(rFormat, nCheckPos, nType, nNewKey, eLang))
538 return false;
539 DBG_ASSERT(nNewKey != NUMBERFORMAT_ENTRY_NOT_FOUND, "FormattedField::SetFormatString : PutEntry returned an invalid key !");
540 }
541
542 if (nNewKey != m_nFormatKey)
543 SetFormatKey(nNewKey);
544 return true;
545}
546
548{
550 "FormattedField::GetThousandsSep : Are you sure what you are doing when setting the precision of a text format?");
551
552 bool bThousand, IsRed;
553 sal_uInt16 nPrecision, nLeadingCnt;
554 GetOrCreateFormatter()->GetFormatSpecialInfo(m_nFormatKey, bThousand, IsRed, nPrecision, nLeadingCnt);
555
556 return bThousand;
557}
558
559void Formatter::SetThousandsSep(bool _bUseSeparator)
560{
562 "FormattedField::SetThousandsSep : Are you sure what you are doing when setting the precision of a text format?");
563
564 // get the current settings
565 bool bThousand, IsRed;
566 sal_uInt16 nPrecision, nLeadingCnt;
567 GetOrCreateFormatter()->GetFormatSpecialInfo(m_nFormatKey, bThousand, IsRed, nPrecision, nLeadingCnt);
568 if (bThousand == _bUseSeparator)
569 return;
570
571 // we need the language for the following
572 LanguageType eLang;
573 GetFormat(eLang);
574
575 // generate a new format ...
576 OUString sFmtDescription = GetOrCreateFormatter()->GenerateFormat(m_nFormatKey, eLang, _bUseSeparator, IsRed, nPrecision, nLeadingCnt);
577 // ... and introduce it to the formatter
578 sal_Int32 nCheckPos = 0;
579 sal_uInt32 nNewKey;
581 GetOrCreateFormatter()->PutEntry(sFmtDescription, nCheckPos, nType, nNewKey, eLang);
582
583 // set the new key
584 ImplSetFormatKey(nNewKey);
586}
587
589{
591 "FormattedField::GetDecimalDigits : Are you sure what you are doing when setting the precision of a text format?");
592
593 bool bThousand, IsRed;
594 sal_uInt16 nPrecision, nLeadingCnt;
595 GetOrCreateFormatter()->GetFormatSpecialInfo(m_nFormatKey, bThousand, IsRed, nPrecision, nLeadingCnt);
596
597 return nPrecision;
598}
599
600void Formatter::SetDecimalDigits(sal_uInt16 _nPrecision)
601{
603 "FormattedField::SetDecimalDigits : Are you sure what you are doing when setting the precision of a text format?");
604
605 // get the current settings
606 bool bThousand, IsRed;
607 sal_uInt16 nPrecision, nLeadingCnt;
608 GetOrCreateFormatter()->GetFormatSpecialInfo(m_nFormatKey, bThousand, IsRed, nPrecision, nLeadingCnt);
609 if (nPrecision == _nPrecision)
610 return;
611
612 // we need the language for the following
613 LanguageType eLang;
614 GetFormat(eLang);
615
616 // generate a new format ...
617 OUString sFmtDescription = GetOrCreateFormatter()->GenerateFormat(m_nFormatKey, eLang, bThousand, IsRed, _nPrecision, nLeadingCnt);
618 // ... and introduce it to the formatter
619 sal_Int32 nCheckPos = 0;
620 sal_uInt32 nNewKey;
622 GetOrCreateFormatter()->PutEntry(sFmtDescription, nCheckPos, nType, nNewKey, eLang);
623
624 // set the new key
625 ImplSetFormatKey(nNewKey);
627}
628
630{
631 m_pLastOutputColor = nullptr;
632
633 if ( (_nWhat == FORMAT_CHANGE_TYPE::FORMATTER) && m_pFormatter )
635
636 ReFormat();
637}
638
640{
641 // special treatment for empty texts
642 if (GetEntryText().isEmpty())
643 {
644 if (!IsEmptyFieldEnabled())
645 {
646 if (TreatingAsNumber())
647 {
649 Modify();
651 }
652 else
653 {
654 OUString sNew = GetTextValue();
655 if (!sNew.isEmpty())
656 SetTextFormatted(sNew);
657 else
660 }
661 }
662 }
663 else
664 {
665 Commit();
666 }
667}
668
670{
671 // remember the old text
672 OUString sOld(GetEntryText());
673
674 // do the reformat
675 ReFormat();
676
677 // did the text change?
678 if (GetEntryText() != sOld)
679 { // consider the field as modified,
680 // but we already have the most recent value;
681 // don't reparse it from the text
682 // (can lead to data loss when the format is lossy,
683 // as is e.g. our default date format: 2-digit year!)
684 Modify(false);
685 }
686}
687
689{
690 if (!IsEmptyFieldEnabled() || !GetEntryText().isEmpty())
691 {
692 if (TreatingAsNumber())
693 {
694 double dValue = GetValue();
695 if ( m_bEnableNaN && std::isnan( dValue ) )
696 return;
697 ImplSetValue( dValue, true );
698 }
699 else
701 }
702}
703
704void Formatter::SetMinValue(double dMin)
705{
706 DBG_ASSERT(m_bTreatAsNumber, "FormattedField::SetMinValue : only to be used in numeric mode !");
707
708 m_dMinValue = dMin;
709 m_bHasMin = true;
710 // for checking the current value at the new border -> ImplSetValue
711 ReFormat();
712}
713
714void Formatter::SetMaxValue(double dMax)
715{
716 DBG_ASSERT(m_bTreatAsNumber, "FormattedField::SetMaxValue : only to be used in numeric mode !");
717
718 m_dMaxValue = dMax;
719 m_bHasMax = true;
720 // for checking the current value at the new border -> ImplSetValue
721 ReFormat();
722}
723
724void Formatter::SetTextValue(const OUString& rText)
725{
726 SetFieldText(rText, Selection(0, 0));
727 ReFormat();
728}
729
731{
732 if (bEnable == m_bEnableEmptyField)
733 return;
734
735 m_bEnableEmptyField = bEnable;
736 if (!m_bEnableEmptyField && GetEntryText().isEmpty())
738}
739
740void Formatter::ImplSetValue(double dVal, bool bForce)
741{
742 if (m_bHasMin && (dVal<m_dMinValue))
743 {
744 dVal = m_bWrapOnLimits ? fmod(dVal + m_dMaxValue + 1 - m_dMinValue, m_dMaxValue + 1) + m_dMinValue
745 : m_dMinValue;
746 }
747 if (m_bHasMax && (dVal>m_dMaxValue))
748 {
749 dVal = m_bWrapOnLimits ? fmod(dVal - m_dMinValue, m_dMaxValue + 1) + m_dMinValue
750 : m_dMaxValue;
751 }
752 if (!bForce && (dVal == GetValue()))
753 return;
754
755 DBG_ASSERT(GetOrCreateFormatter() != nullptr, "FormattedField::ImplSetValue : can't set a value without a formatter !");
756
758 UpdateCurrentValue(dVal);
759
760 if (!m_aOutputHdl.IsSet() || !m_aOutputHdl.Call(nullptr))
761 {
762 OUString sNewText;
763 if (GetOrCreateFormatter()->IsTextFormat(m_nFormatKey))
764 {
765 // first convert the number as string in standard format
766 OUString sTemp;
768 // then encode the string in the corresponding text format
770 }
771 else
772 {
774 {
776 }
777 else
778 {
780 }
781 }
782 ImplSetTextImpl(sNewText, nullptr);
783 DBG_ASSERT(CheckText(sNewText), "FormattedField::ImplSetValue : formatted string doesn't match the criteria !");
784 }
785
787}
788
789bool Formatter::ImplGetValue(double& dNewVal)
790{
791 dNewVal = m_dCurrentValue;
793 return true;
794
795 // tdf#155241 default to m_dDefaultValue only if explicitly set
796 // otherwise default to m_dCurrentValue
798 dNewVal = m_dDefaultValue;
799
800 OUString sText(GetEntryText());
801 if (sText.isEmpty())
802 return true;
803
804 bool bUseExternalFormatterValue = false;
805 if (m_aInputHdl.IsSet())
806 {
807 sal_Int64 nResult;
808 auto eState = m_aInputHdl.Call(&nResult);
809 bUseExternalFormatterValue = eState != TRISTATE_INDET;
810 if (bUseExternalFormatterValue)
811 {
812 if (eState == TRISTATE_TRUE)
813 {
814 dNewVal = nResult;
816 }
817 else
818 dNewVal = m_dCurrentValue;
819 }
820 }
821
822 if (!bUseExternalFormatterValue)
823 {
824 DBG_ASSERT(GetOrCreateFormatter() != nullptr, "FormattedField::ImplGetValue : can't give you a current value without a formatter !");
825
826 sal_uInt32 nFormatKey = m_nFormatKey; // IsNumberFormat changes the FormatKey!
827
828 if (GetOrCreateFormatter()->IsTextFormat(nFormatKey) && m_bTreatAsNumber)
829 // for detection of values like "1,1" in fields that are formatted as text
830 nFormatKey = 0;
831
832 // special treatment for percentage formatting
833 if (GetOrCreateFormatter()->GetType(m_nFormatKey) == SvNumFormatType::PERCENT)
834 {
835 // the language of our format
837 // the default number format for this language
838 sal_uLong nStandardNumericFormat = m_pFormatter->GetStandardFormat(SvNumFormatType::NUMBER, eLanguage);
839
840 sal_uInt32 nTempFormat = nStandardNumericFormat;
841 double dTemp;
842 if (m_pFormatter->IsNumberFormat(sText, nTempFormat, dTemp) &&
843 SvNumFormatType::NUMBER == m_pFormatter->GetType(nTempFormat))
844 // the string is equivalent to a number formatted one (has no % sign) -> append it
845 sText += "%";
846 // (with this, an input of '3' becomes '3%', which then by the formatter is translated
847 // into 0.03. Without this, the formatter would give us the double 3 for an input '3',
848 // which equals 300 percent.
849 }
850 if (!GetOrCreateFormatter()->IsNumberFormat(sText, nFormatKey, dNewVal))
851 return false;
852 }
853
854 if (m_bHasMin && (dNewVal<m_dMinValue))
855 dNewVal = m_dMinValue;
856 if (m_bHasMax && (dNewVal>m_dMaxValue))
857 dNewVal = m_dMaxValue;
858 return true;
859}
860
861void Formatter::SetValue(double dVal)
862{
864}
865
867{
869 UpdateCurrentValue(m_bEnableNaN ? std::numeric_limits<double>::quiet_NaN() : m_dDefaultValue);
870
872 return m_dCurrentValue;
873}
874
876{
878}
879
881{
883}
884
885namespace
886{
887 class FieldFormatter : public Formatter
888 {
889 private:
890 FormattedField& m_rSpinButton;
891 public:
892 FieldFormatter(FormattedField& rSpinButton)
893 : m_rSpinButton(rSpinButton)
894 {
895 }
896
897 // Formatter overrides
898 virtual Selection GetEntrySelection() const override
899 {
900 return m_rSpinButton.GetSelection();
901 }
902
903 virtual OUString GetEntryText() const override
904 {
905 return m_rSpinButton.GetText();
906 }
907
908 void SetEntryText(const OUString& rText, const Selection& rSel) override
909 {
910 m_rSpinButton.SpinField::SetText(rText, rSel);
911 }
912
913 virtual void SetEntryTextColor(const ::Color* pColor) override
914 {
915 if (pColor)
916 m_rSpinButton.SetControlForeground(*pColor);
917 else
918 m_rSpinButton.SetControlForeground();
919 }
920
921 virtual SelectionOptions GetEntrySelectionOptions() const override
922 {
923 return m_rSpinButton.GetSettings().GetStyleSettings().GetSelectionOptions();
924 }
925
926 virtual void FieldModified() override
927 {
928 m_rSpinButton.SpinField::Modify();
929 }
930
931 virtual void UpdateCurrentValue(double dCurrentValue) override
932 {
933 Formatter::UpdateCurrentValue(dCurrentValue);
934 m_rSpinButton.SetUpperEnabled(!m_bHasMax || dCurrentValue < m_dMaxValue);
935 m_rSpinButton.SetLowerEnabled(!m_bHasMin || dCurrentValue > m_dMinValue);
936 }
937 };
938
939 class DoubleNumericFormatter : public FieldFormatter
940 {
941 private:
942 DoubleNumericField& m_rNumericSpinButton;
943 public:
944 DoubleNumericFormatter(DoubleNumericField& rNumericSpinButton)
945 : FieldFormatter(rNumericSpinButton)
946 , m_rNumericSpinButton(rNumericSpinButton)
947 {
948 }
949
950 virtual bool CheckText(const OUString& sText) const override
951 {
952 // We'd like to implement this using the NumberFormatter::IsNumberFormat, but unfortunately, this doesn't
953 // recognize fragments of numbers (like, for instance "1e", which happens during entering e.g. "1e10")
954 // Thus, the roundabout way via a regular expression
955 return m_rNumericSpinButton.GetNumberValidator().isValidNumericFragment(sText);
956 }
957
958 virtual void FormatChanged(FORMAT_CHANGE_TYPE nWhat) override
959 {
960 m_rNumericSpinButton.ResetConformanceTester();
961 FieldFormatter::FormatChanged(nWhat);
962 }
963 };
964
965 class DoubleCurrencyFormatter : public FieldFormatter
966 {
967 private:
968 DoubleCurrencyField& m_rCurrencySpinButton;
969 bool m_bChangingFormat;
970 public:
971 DoubleCurrencyFormatter(DoubleCurrencyField& rNumericSpinButton)
972 : FieldFormatter(rNumericSpinButton)
973 , m_rCurrencySpinButton(rNumericSpinButton)
974 , m_bChangingFormat(false)
975 {
976 }
977
978 virtual void FormatChanged(FORMAT_CHANGE_TYPE nWhat) override
979 {
980 if (m_bChangingFormat)
981 {
982 FieldFormatter::FormatChanged(nWhat);
983 return;
984 }
985
986 switch (nWhat)
987 {
991 // the aspects which changed don't take our currency settings into account (in fact, they most probably
992 // destroyed them)
993 m_rCurrencySpinButton.UpdateCurrencyFormat();
994 break;
996 OSL_FAIL("DoubleCurrencyField::FormatChanged : somebody modified my key !");
997 // We always build our own format from the settings we get via special methods (setCurrencySymbol etc.).
998 // Nobody but ourself should modify the format key directly!
999 break;
1000 default: break;
1001 }
1002
1003 FieldFormatter::FormatChanged(nWhat);
1004 }
1005
1006 void GuardSetFormat(const OUString& rString, LanguageType eLanguage)
1007 {
1008 // set this new basic format
1009 m_bChangingFormat = true;
1010 SetFormat(rString, eLanguage);
1011 m_bChangingFormat = false;
1012 }
1013
1014 };
1015}
1016
1017DoubleNumericField::DoubleNumericField(vcl::Window* pParent, WinBits nStyle)
1018 : FormattedField(pParent, nStyle)
1019{
1020 m_xOwnFormatter.reset(new DoubleNumericFormatter(*this));
1021 m_pFormatter = m_xOwnFormatter.get();
1022 ResetConformanceTester();
1023}
1024
1025DoubleNumericField::~DoubleNumericField() = default;
1026
1027void DoubleNumericField::ResetConformanceTester()
1028{
1029 // the thousands and the decimal separator are language dependent
1030 Formatter& rFormatter = GetFormatter();
1031 const SvNumberformat* pFormatEntry = rFormatter.GetOrCreateFormatter()->GetEntry(rFormatter.GetFormatKey());
1032
1033 sal_Unicode cSeparatorThousand = ',';
1034 sal_Unicode cSeparatorDecimal = '.';
1035 if (pFormatEntry)
1036 {
1037 LocaleDataWrapper aLocaleInfo( LanguageTag( pFormatEntry->GetLanguage()) );
1038
1039 OUString sSeparator = aLocaleInfo.getNumThousandSep();
1040 if (!sSeparator.isEmpty())
1041 cSeparatorThousand = sSeparator[0];
1042
1043 sSeparator = aLocaleInfo.getNumDecimalSep();
1044 if (!sSeparator.isEmpty())
1045 cSeparatorDecimal = sSeparator[0];
1046 }
1047
1048 m_pNumberValidator.reset(new validation::NumberValidator( cSeparatorThousand, cSeparatorDecimal ));
1049}
1050
1051
1052DoubleCurrencyField::DoubleCurrencyField(vcl::Window* pParent, WinBits nStyle)
1053 :FormattedField(pParent, nStyle)
1054{
1055 m_xOwnFormatter.reset(new DoubleCurrencyFormatter(*this));
1056 m_pFormatter = m_xOwnFormatter.get();
1057
1058 m_bPrependCurrSym = false;
1059
1060 // initialize with a system currency format
1061 m_sCurrencySymbol = SvtSysLocale().GetLocaleData().getCurrSymbol();
1062 UpdateCurrencyFormat();
1063}
1064
1065void DoubleCurrencyField::setCurrencySymbol(const OUString& rSymbol)
1066{
1067 if (m_sCurrencySymbol == rSymbol)
1068 return;
1069
1070 m_sCurrencySymbol = rSymbol;
1071 UpdateCurrencyFormat();
1072 m_pFormatter->FormatChanged(FORMAT_CHANGE_TYPE::CURRENCY_SYMBOL);
1073}
1074
1075void DoubleCurrencyField::setPrependCurrSym(bool _bPrepend)
1076{
1077 if (m_bPrependCurrSym == _bPrepend)
1078 return;
1079
1080 m_bPrependCurrSym = _bPrepend;
1081 UpdateCurrencyFormat();
1082 m_pFormatter->FormatChanged(FORMAT_CHANGE_TYPE::CURRSYM_POSITION);
1083}
1084
1085void DoubleCurrencyField::UpdateCurrencyFormat()
1086{
1087 // the old settings
1088 LanguageType eLanguage;
1089 m_pFormatter->GetFormat(eLanguage);
1090 bool bThSep = m_pFormatter->GetThousandsSep();
1091 sal_uInt16 nDigits = m_pFormatter->GetDecimalDigits();
1092
1093 // build a new format string with the base class' and my own settings
1094
1095 /* Strangely with gcc 4.6.3 this needs a temporary LanguageTag, otherwise
1096 * there's
1097 * error: request for member 'getNumThousandSep' in 'aLocaleInfo', which is
1098 * of non-class type 'LocaleDataWrapper(LanguageTag)' */
1099 LocaleDataWrapper aLocaleInfo(( LanguageTag(eLanguage) ));
1100
1101 OUStringBuffer sNewFormat;
1102 if (bThSep)
1103 {
1104 sNewFormat.append("#" + aLocaleInfo.getNumThousandSep() + "##0");
1105 }
1106 else
1107 sNewFormat.append('0');
1108
1109 if (nDigits)
1110 {
1111 sNewFormat.append(aLocaleInfo.getNumDecimalSep());
1112 comphelper::string::padToLength(sNewFormat, sNewFormat.getLength() + nDigits, '0');
1113 }
1114
1115 if (getPrependCurrSym())
1116 {
1117 OUString sSymbol = getCurrencySymbol();
1118 sSymbol = comphelper::string::strip(sSymbol, ' ');
1119
1120 OUString sTemp =
1121 "[$" + sSymbol + "] "
1122 + sNewFormat
1123 // for negative values : $ -0.00, not -$ 0.00...
1124 // (the real solution would be a possibility to choose a "positive currency format" and a "negative currency format"...
1125 // But not now... (and hey, you could take a formatted field for this...))
1126 // FS - 31.03.00 74642
1127 + ";[$"
1128 + sSymbol
1129 + "] -"
1130 + sNewFormat;
1131
1132 sNewFormat = sTemp;
1133 }
1134 else
1135 {
1136 OUString sTemp = getCurrencySymbol();
1137 sTemp = comphelper::string::strip(sTemp, ' ');
1138
1139 sNewFormat.append(" [$" + sTemp + "]");
1140 }
1141
1142 // set this new basic format
1143 static_cast<DoubleCurrencyFormatter*>(m_pFormatter)->GuardSetFormat(sNewFormat.makeStringAndClear(), eLanguage);
1144}
1145
1147 : SpinField(pParent, nStyle, WindowType::FORMATTEDFIELD)
1148 , m_pFormatter(nullptr)
1149{
1150}
1151
1153{
1154 m_pFormatter = nullptr;
1155 m_xOwnFormatter.reset();
1157}
1158
1159void FormattedField::SetText(const OUString& rStr)
1160{
1161 GetFormatter().SetFieldText(rStr, Selection(0, 0));
1162}
1163
1164void FormattedField::SetText(const OUString& rStr, const Selection& rNewSelection)
1165{
1166 GetFormatter().SetFieldText(rStr, rNewSelection);
1167 SetSelection(rNewSelection);
1168}
1169
1170bool FormattedField::set_property(const OUString &rKey, const OUString &rValue)
1171{
1172 if (rKey == "digits")
1173 GetFormatter().SetDecimalDigits(rValue.toInt32());
1174 else if (rKey == "wrap")
1176 else
1177 return SpinField::set_property(rKey, rValue);
1178 return true;
1179}
1180
1182{
1183 Formatter& rFormatter = GetFormatter();
1184 auto nScale = weld::SpinButton::Power10(rFormatter.GetDecimalDigits());
1185
1186 sal_Int64 nValue = std::round(rFormatter.GetValue() * nScale);
1187 sal_Int64 nSpinSize = std::round(rFormatter.GetSpinSize() * nScale);
1188 assert(nSpinSize != 0);
1189 sal_Int64 nRemainder = rFormatter.GetDisableRemainderFactor() || nSpinSize == 0 ? 0 : nValue % nSpinSize;
1190 if (nValue >= 0)
1191 nValue = (nRemainder == 0) ? nValue + nSpinSize : nValue + nSpinSize - nRemainder;
1192 else
1193 nValue = (nRemainder == 0) ? nValue + nSpinSize : nValue - nRemainder;
1194
1195 // setValue handles under- and overflows (min/max) automatically
1196 rFormatter.SetValue(static_cast<double>(nValue) / nScale);
1197 SetModifyFlag();
1198 Modify();
1199
1200 SpinField::Up();
1201}
1202
1204{
1205 Formatter& rFormatter = GetFormatter();
1206 auto nScale = weld::SpinButton::Power10(rFormatter.GetDecimalDigits());
1207
1208 sal_Int64 nValue = std::round(rFormatter.GetValue() * nScale);
1209 sal_Int64 nSpinSize = std::round(rFormatter.GetSpinSize() * nScale);
1210 assert(nSpinSize != 0);
1211 sal_Int64 nRemainder = rFormatter.GetDisableRemainderFactor() || nSpinSize == 0 ? 0 : nValue % nSpinSize;
1212 if (nValue >= 0)
1213 nValue = (nRemainder == 0) ? nValue - nSpinSize : nValue - nRemainder;
1214 else
1215 nValue = (nRemainder == 0) ? nValue - nSpinSize : nValue - nSpinSize - nRemainder;
1216
1217 // setValue handles under- and overflows (min/max) automatically
1218 rFormatter.SetValue(static_cast<double>(nValue) / nScale);
1219 SetModifyFlag();
1220 Modify();
1221
1223}
1224
1226{
1227 Formatter& rFormatter = GetFormatter();
1228 if (rFormatter.HasMinValue())
1229 {
1230 rFormatter.SetValue(rFormatter.GetMinValue());
1231 SetModifyFlag();
1232 Modify();
1233 }
1234
1236}
1237
1239{
1240 Formatter& rFormatter = GetFormatter();
1241 if (rFormatter.HasMaxValue())
1242 {
1243 rFormatter.SetValue(rFormatter.GetMaxValue());
1244 SetModifyFlag();
1245 Modify();
1246 }
1247
1249}
1250
1252{
1253 GetFormatter().Modify();
1254}
1255
1257{
1258 if (rNEvt.GetType() == NotifyEventType::KEYINPUT)
1260 return SpinField::PreNotify(rNEvt);
1261}
1262
1264{
1265 if ((rNEvt.GetType() == NotifyEventType::KEYINPUT) && !IsReadOnly())
1266 {
1267 const KeyEvent& rKEvt = *rNEvt.GetKeyEvent();
1268 sal_uInt16 nMod = rKEvt.GetKeyCode().GetModifier();
1269 switch ( rKEvt.GetKeyCode().GetCode() )
1270 {
1271 case KEY_UP:
1272 case KEY_DOWN:
1273 case KEY_PAGEUP:
1274 case KEY_PAGEDOWN:
1275 {
1276 Formatter& rFormatter = GetFormatter();
1277 if (!nMod && rFormatter.GetOrCreateFormatter()->IsTextFormat(rFormatter.GetFormatKey()))
1278 {
1279 // the base class would translate this into calls to Up/Down/First/Last,
1280 // but we don't want this if we are text-formatted
1281 return true;
1282 }
1283 }
1284 }
1285 }
1286
1287 if ((rNEvt.GetType() == NotifyEventType::COMMAND) && !IsReadOnly())
1288 {
1289 const CommandEvent* pCommand = rNEvt.GetCommandEvent();
1290 if (pCommand->GetCommand() == CommandEventId::Wheel)
1291 {
1293 Formatter& rFormatter = GetFormatter();
1294 if ((pData->GetMode() == CommandWheelMode::SCROLL) &&
1295 rFormatter.GetOrCreateFormatter()->IsTextFormat(rFormatter.GetFormatKey()))
1296 {
1297 // same as above : prevent the base class from doing Up/Down-calls
1298 // (normally I should put this test into the Up/Down methods itself, shouldn't I ?)
1299 // FS - 71553 - 19.01.00
1300 return true;
1301 }
1302 }
1303 }
1304
1307
1308 return SpinField::EventNotify( rNEvt );
1309}
1310
1312{
1313 if (!m_pFormatter)
1314 {
1315 m_xOwnFormatter.reset(new FieldFormatter(*this));
1317 }
1318 return *m_pFormatter;
1319}
1320
1322{
1323 m_xOwnFormatter.reset();
1324 m_pFormatter = pFormatter;
1325}
1326
1327// currently used by online
1328void FormattedField::SetValueFromString(const OUString& rStr)
1329{
1330 sal_Int32 nEnd;
1331 rtl_math_ConversionStatus eStatus;
1332 Formatter& rFormatter = GetFormatter();
1333 double fValue = ::rtl::math::stringToDouble(rStr, '.', rFormatter.GetDecimalDigits(), &eStatus, &nEnd );
1334
1335 if (eStatus == rtl_math_ConversionStatus_Ok &&
1336 nEnd == rStr.getLength())
1337 {
1338 rFormatter.SetValue(fValue);
1339 SetModifyFlag();
1340 Modify();
1341
1342 // Notify the value has changed
1343 SpinField::Up();
1344 }
1345 else
1346 {
1347 SAL_WARN("vcl", "fail to convert the value: " << rStr);
1348 }
1349}
1350
1352{
1353 SpinField::DumpAsPropertyTree(rJsonWriter);
1354 Formatter& rFormatter = GetFormatter();
1355 rJsonWriter.put("min", rFormatter.GetMinValue());
1356 rJsonWriter.put("max", rFormatter.GetMaxValue());
1357 rJsonWriter.put("value", rFormatter.GetValue());
1358 rJsonWriter.put("step", rFormatter.GetSpinSize());
1359}
1360
1362{
1364}
1365
1366/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool toBool(std::string_view rValue)
Definition: builder.cxx:92
const StyleSettings & GetStyleSettings() const
CommandEventId GetCommand() const
const CommandWheelData * GetWheelData() const
virtual bool set_property(const OUString &rKey, const OUString &rValue) override
Definition: edit.cxx:183
virtual const Selection & GetSelection() const
Definition: edit.cxx:2474
virtual void DumpAsPropertyTree(tools::JsonWriter &rJsonWriter) override
Dumps itself and potentially its children to a property tree, to be written easily to JSON.
Definition: edit.cxx:2924
virtual void SetSelection(const Selection &rSelection)
Definition: edit.cxx:2400
virtual bool IsReadOnly() const
Definition: edit.hxx:175
virtual void SetModifyFlag()
Definition: edit.cxx:2594
virtual OUString GetText() const override
Definition: edit.cxx:2570
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
virtual void First() override
Definition: fmtfield.cxx:1225
void SetValueFromString(const OUString &rStr)
Definition: fmtfield.cxx:1328
virtual void Last() override
Definition: fmtfield.cxx:1238
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: fmtfield.cxx:1263
FormattedField(vcl::Window *pParent, WinBits nStyle)
Definition: fmtfield.cxx:1146
Formatter * m_pFormatter
Definition: fmtfield.hxx:60
Formatter & GetFormatter()
Definition: fmtfield.cxx:1311
std::unique_ptr< Formatter > m_xOwnFormatter
Definition: fmtfield.hxx:59
virtual void Down() override
Definition: fmtfield.cxx:1203
virtual void Up() override
Definition: fmtfield.cxx:1181
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: fmtfield.cxx:1152
virtual void Modify() override
Definition: fmtfield.cxx:1251
virtual bool set_property(const OUString &rKey, const OUString &rValue) override
Definition: fmtfield.cxx:1170
virtual void SetText(const OUString &rStr) override
Definition: fmtfield.cxx:1159
virtual FactoryFunction GetUITestFactory() const override
Definition: fmtfield.cxx:1361
bool PreNotify(NotifyEvent &rNEvt) override
Definition: fmtfield.cxx:1256
virtual void DumpAsPropertyTree(tools::JsonWriter &) override
Dumps itself and potentially its children to a property tree, to be written easily to JSON.
Definition: fmtfield.cxx:1351
void SetFormatter(Formatter *pFormatter)
Definition: fmtfield.cxx:1321
static sal_uLong s_nReferences
Definition: formatter.hxx:93
static SvNumberFormatter * s_cFormatter
Definition: formatter.hxx:92
void SetTextValue(const OUString &rText)
Definition: fmtfield.cxx:724
void SetValue(double dVal)
Definition: fmtfield.cxx:861
Selection m_aLastSelection
Definition: formatter.hxx:106
void SetDecimalDigits(sal_uInt16 _nPrecision)
Definition: fmtfield.cxx:600
void UseInputStringForFormatting()
When being set to true, the strings in the field are formatted using the InputLine format.
Definition: fmtfield.cxx:880
void EntryLostFocus()
Definition: fmtfield.cxx:639
void SetThousandsSep(bool _bUseSeparator)
Definition: fmtfield.cxx:559
double m_dSpinFirst
Definition: formatter.hxx:131
double GetSpinSize() const
Definition: formatter.hxx:228
virtual void SetEntryTextColor(const Color *pColor)=0
bool TreatingAsNumber() const
Definition: formatter.hxx:236
bool m_bDefaultValueSet
Definition: formatter.hxx:120
void SetAutoColor(bool _bAutomatic)
Definition: fmtfield.cxx:371
virtual Selection GetEntrySelection() const =0
void Commit()
reformats the current text.
Definition: fmtfield.cxx:669
bool m_bUseInputStringForFormatting
Definition: formatter.hxx:144
sal_uInt16 GetDecimalDigits() const
Definition: fmtfield.cxx:588
double m_dMaxValue
Definition: formatter.hxx:109
double GetMinValue() const
Definition: formatter.hxx:166
void EnableEmptyField(bool bEnable)
Definition: fmtfield.cxx:730
virtual void FieldModified()=0
SvNumberFormatter * GetOrCreateFormatter() const
Definition: formatter.hxx:195
bool IsUsingInputStringForFormatting() const
Definition: formatter.hxx:289
void SetTextFormatted(const OUString &rText)
Definition: fmtfield.cxx:294
bool IsStrictFormat() const
Definition: formatter.hxx:223
virtual void SetEntryText(const OUString &rText, const Selection &rSel)=0
Link< LinkParamNone *, bool > m_aOutputHdl
Definition: formatter.hxx:147
SvNumberFormatter * m_pFormatter
Definition: formatter.hxx:127
virtual void FormatChanged(FORMAT_CHANGE_TYPE nWhat)
Definition: fmtfield.cxx:629
void SetLastSelection(const Selection &rSelection)
Definition: formatter.hxx:189
sal_uLong m_nFormatKey
Definition: formatter.hxx:126
bool m_bHasMin
Definition: formatter.hxx:110
bool ImplGetValue(double &dNewVal)
Definition: fmtfield.cxx:789
void ImplSetTextImpl(const OUString &rNew, Selection const *pNewSel)
Definition: fmtfield.cxx:410
bool m_bEnableNaN
Definition: formatter.hxx:118
void SetWrapOnLimits(bool bWrapOnLimits)
Definition: formatter.hxx:209
double m_dMinValue
Definition: formatter.hxx:108
void SetFormatter(SvNumberFormatter *pFormatter, bool bResetFormat=true)
Definition: fmtfield.cxx:477
bool m_bDisableRemainderFactor
Definition: formatter.hxx:119
double GetMaxValue() const
Definition: formatter.hxx:171
void SetFormatKey(sal_uLong nFormatKey)
Definition: fmtfield.cxx:470
bool GetDisableRemainderFactor() const
Definition: formatter.hxx:207
OUString GetFormat(LanguageType &eLang) const
Definition: fmtfield.cxx:519
void ImplSetValue(double dValue, bool bForce)
Definition: fmtfield.cxx:740
OUString m_sCurrentTextValue
Definition: formatter.hxx:138
bool GetThousandsSep() const
Definition: fmtfield.cxx:547
virtual bool CheckText(const OUString &) const
Definition: formatter.hxx:303
bool m_bTreatAsNumber
Definition: formatter.hxx:136
OUString const & GetTextValue() const
Definition: fmtfield.cxx:353
bool m_bAutoColor
Definition: formatter.hxx:117
sal_uLong GetFormatKey() const
Definition: formatter.hxx:192
virtual void SetMaxValue(double dMax)
Definition: fmtfield.cxx:714
void SetFieldText(const OUString &rText, const Selection &rNewSelection)
Definition: fmtfield.cxx:288
double m_dDefaultValue
Definition: formatter.hxx:124
void ReFormat()
Definition: fmtfield.cxx:688
bool m_bWrapOnLimits
Definition: formatter.hxx:113
double m_dSpinLast
Definition: formatter.hxx:132
bool m_bStrictFormat
Definition: formatter.hxx:114
OUString m_sDefaultText
Definition: formatter.hxx:139
double m_dCurrentValue
Definition: formatter.hxx:123
virtual OUString GetEntryText() const =0
void ImplSetFormatKey(sal_uLong nFormatKey)
Definition: fmtfield.cxx:452
void EnableNotANumber(bool _bEnable)
enables handling of not-a-number value.
Definition: fmtfield.cxx:363
bool SetFormat(const OUString &rFormatString, LanguageType eLang)
Definition: fmtfield.cxx:529
bool IsEmptyFieldEnabled() const
Definition: formatter.hxx:181
virtual void SetMinValue(double dMin)
Definition: fmtfield.cxx:704
bool HasMinValue() const
Definition: formatter.hxx:163
void DisableRemainderFactor()
Definition: fmtfield.cxx:875
bool HasMaxValue() const
Definition: formatter.hxx:168
valueState m_ValueState
Definition: formatter.hxx:122
Link< sal_Int64 *, TriState > m_aInputHdl
Definition: formatter.hxx:146
double m_dSpinSize
Definition: formatter.hxx:130
const Color * m_pLastOutputColor
Definition: formatter.hxx:142
virtual ~Formatter()
Definition: fmtfield.cxx:284
bool m_bEnableEmptyField
Definition: formatter.hxx:116
bool m_bHasMax
Definition: formatter.hxx:111
void Modify(bool makeValueDirty=true)
Definition: fmtfield.cxx:384
OUString m_sLastValidText
Definition: formatter.hxx:103
virtual void UpdateCurrentValue(double dCurrentValue)
Definition: formatter.hxx:314
double GetValue()
Definition: fmtfield.cxx:866
virtual SelectionOptions GetEntrySelectionOptions() const =0
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:57
LanguageType getLanguageType(bool bResolveSystem=true) const
const OUString & getCurrSymbol() const
const KeyEvent * GetKeyEvent() const
Definition: event.hxx:316
const CommandEvent * GetCommandEvent() const
Definition: event.hxx:332
NotifyEventType GetType() const
Definition: event.hxx:308
tools::Long Min() const
void Normalize()
tools::Long Max() const
virtual void Last()
Definition: spinfld.cxx:374
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: spinfld.cxx:485
virtual void First()
Definition: spinfld.cxx:369
SAL_DLLPRIVATE void SetLowerEnabled(bool bEnabled)
Definition: spinfld.cxx:594
virtual bool PreNotify(NotifyEvent &rNEvt) override
Definition: spinfld.cxx:858
virtual void Down()
Definition: spinfld.cxx:364
virtual void Up()
Definition: spinfld.cxx:359
SAL_DLLPRIVATE void SetUpperEnabled(bool bEnabled)
Definition: spinfld.cxx:583
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: spinfld.cxx:352
SelectionOptions GetSelectionOptions() const
sal_uInt32 GetStandardFormat(SvNumFormatType eType, LanguageType eLnge=LANGUAGE_DONTKNOW)
bool PutEntry(OUString &rString, sal_Int32 &nCheckPos, SvNumFormatType &nType, sal_uInt32 &nKey, LanguageType eLnge=LANGUAGE_DONTKNOW, bool bReplaceBooleanEquivalent=true)
sal_uInt32 TestNewString(const OUString &sFormatString, LanguageType eLnge=LANGUAGE_DONTKNOW)
OUString GenerateFormat(sal_uInt32 nIndex, LanguageType eLnge=LANGUAGE_DONTKNOW, bool bThousand=false, bool IsRed=false, sal_uInt16 nPrecision=0, sal_uInt16 nLeadingCnt=1)
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, const Color **ppColor, bool bUseStarFormat=false)
bool PutandConvertEntry(OUString &rString, sal_Int32 &nCheckPos, SvNumFormatType &nType, sal_uInt32 &nKey, LanguageType eLnge, LanguageType eNewLnge, bool bConvertDateOrder, bool bReplaceBooleanEquivalent=true)
bool IsTextFormat(sal_uInt32 nFIndex) const
void GetInputLineString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &rOutString, bool bFiltering=false, bool bForceSystemLocale=false)
SvNumFormatType GetType(sal_uInt32 nFIndex) const
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
void SetEvalDateFormat(NfEvalDateFormat eEDF)
void GetFormatSpecialInfo(sal_uInt32 nFormat, bool &bThousand, bool &IsRed, sal_uInt16 &nPrecision, sal_uInt16 &nLeadingCnt)
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
LanguageType GetLanguage() const
const OUString & GetFormatstring() const
const LanguageTag & GetLanguageTag() const
const LocaleDataWrapper & GetLocaleData() const
void put(std::u16string_view pPropName, const OUString &rPropValue)
bool implValidateNormalized(const OUString &_rText)
Definition: fmtfield.cxx:175
TransitionTable m_aTransitions
Definition: formatter.hxx:64
bool isValidNumericFragment(std::u16string_view _rText)
Definition: fmtfield.cxx:214
NumberValidator(const sal_Unicode _cThSep, const sal_Unicode _cDecSep)
Definition: fmtfield.cxx:87
sal_uInt16 GetCode() const
Definition: keycod.hxx:49
sal_uInt16 GetModifier() const
Definition: keycod.hxx:52
void SetControlForeground()
Definition: window2.cxx:486
const AllSettings & GetSettings() const
Definition: window3.cxx:129
static unsigned int Power10(unsigned int n)
Definition: builder.cxx:267
#define DBG_ASSERT(sCon, aError)
sal_Int16 nValue
FORMAT_CHANGE_TYPE
Definition: formatter.hxx:77
TRISTATE_INDET
TRISTATE_TRUE
std::function< std::unique_ptr< UIObject >(vcl::Window *)> FactoryFunction
constexpr sal_uInt16 KEY_PAGEDOWN
Definition: keycodes.hxx:117
constexpr sal_uInt16 KEY_UP
Definition: keycodes.hxx:111
constexpr sal_uInt16 KEY_DOWN
Definition: keycodes.hxx:110
constexpr sal_uInt16 KEY_PAGEUP
Definition: keycodes.hxx:116
#define LANGUAGE_DONTKNOW
#define SAL_INFO_IF(condition, area, stream)
#define SAL_WARN(area, stream)
std::unique_ptr< sal_Int32[]> pData
OString strip(const OString &rIn, char c)
OStringBuffer & padToLength(OStringBuffer &rBuffer, sal_Int32 nLength, char cFill='\0')
const sal_Int16 FORMATTEDFIELD
static void lcl_insertCommonPreCommaTransitions(StateTransitions &_rRow, const sal_Unicode _cThSep, const sal_Unicode _cDecSep)
Definition: fmtfield.cxx:75
StateTransitions::value_type Transition
Definition: formatter.hxx:55
@ DIGIT_PRE_COMMA
Definition: formatter.hxx:41
@ EXPONENT_START
Definition: formatter.hxx:44
@ DIGIT_POST_COMMA
Definition: formatter.hxx:43
@ EXPONENT_DIGIT
Definition: formatter.hxx:46
static void lcl_insertStartExponentTransition(StateTransitions &_rRow)
Definition: fmtfield.cxx:58
static void lcl_insertDigitTransitions(StateTransitions &_rRow, const State eNextState)
Definition: fmtfield.cxx:69
static void lcl_insertSignTransitions(StateTransitions &_rRow, const State eNextState)
Definition: fmtfield.cxx:63
static void lcl_insertStopTransition(StateTransitions &_rRow)
Definition: fmtfield.cxx:53
::std::map< sal_Unicode, State > StateTransitions
Definition: formatter.hxx:52
QPRO_FUNC_TYPE nType
SelectionOptions
Definition: settings.hxx:179
sal_uIntPtr sal_uLong
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)
sal_uInt16 sal_Unicode
sal_Int64 WinBits
Definition: wintypes.hxx:109
WindowType
Definition: wintypes.hxx:27
SvNumFormatType
NF_EVALDATEFORMAT_FORMAT_INTL
constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND