namespace validation
{ // the states of our automat. enum State
{
START, // at the very start of the string
NUM_START, // the very start of the number
DIGIT_PRE_COMMA, // some pre-comma digits are read, perhaps including some thousand separators
DIGIT_POST_COMMA, // reading digits after the comma
EXPONENT_START, // at the very start of the exponent value // (means: not including the "e" which denotes the exponent)
EXPONENT_DIGIT, // currently reading the digits of the exponent
END // reached the end of the string
};
// a row in the transition table (means the set of states to be reached from a given state) typedef ::std::map< sal_Unicode, State > StateTransitions;
// a single transition typedef StateTransitions::value_type Transition;
enumclass FORMAT_CHANGE_TYPE
{
KEYONLY = 0x00, // only a new key was set
FORMATTER = 0x01, // a new formatter was set, usually implies a change of the key, too
PRECISION = 0x02, // a new precision was set
THOUSANDSSEP = 0x03, // the thousands separator setting changed
CURRENCY_SYMBOL = 0x10,
CURRSYM_POSITION = 0x20,
};
class VCL_DLLPUBLIC Formatter
{ public: // A SvNumberFormatter is very expensive (regarding time and space), it is a Singleton class StaticFormatter
{ static SvNumberFormatter* s_cFormatter; static sal_uLong s_nReferences; public:
StaticFormatter();
~StaticFormatter();
TriState m_eState; // if m_eState is TRISTATE_TRUE, this contains the value double m_fValue;
};
protected:
OUString m_sLastValidText; // Has nothing to do with the current value. It is the last text, which was valid at input (checked by CheckText, // not yet through formatter)
Selection m_aLastSelection;
// There is a difference, when text formatting is enabled, if LostFocus formats the current String and displays it, // or if a double is created from the String and then bool m_bTreatAsNumber; // And with the following members we can use it for formatted text output as well ...
OUString m_sCurrentTextValue;
OUString m_sDefaultText;
// The last color from the Formatter at the last output operation (not we would use it, but you can get it) const Color* m_pLastOutputColor;
// Current value void SetValue(double dVal); double GetValue(); // The default implementation uses a formatter, if available
void SetTextValue(const OUString& rText); // The String is transformed to a double (with a formatter) and SetValue is called afterwards
bool IsEmptyFieldEnabled() const { return m_bEnableEmptyField; } void EnableEmptyField(bool bEnable); // If disabled, the value will be reset to the last valid value on leave
void SetDefaultValue(double dDefault) { m_dDefaultValue = dDefault; m_ValueState = valueDirty; m_bDefaultValueSet = true; } // If the current String is invalid, GetValue() returns this value double GetDefaultValue() const { return m_dDefaultValue; }
// Make the formatter recreate the output text from the value on the next // format attempt even if the value is the same as the current value. // Needed if the associated widget had its text changed by something other // that this Formatter (typically blanked out) since the last formatting void InvalidateValueState() { m_ValueState = valueDirty; }
SvNumberFormatter* GetFormatter() const { return m_pFormatter; } void SetFormatter(SvNumberFormatter* pFormatter, bool bResetFormat = true); // If bResetFormat is sal_False, the old format is tried to be kept. (expensive, if it is no default format, available in all formatters) // If sal_True, the new FormatKey is set to zero
bool GetThousandsSep() const; void SetThousandsSep(bool _bUseSeparator); // the is no check if the current format is numeric, so be cautious when calling these functions
sal_uInt16 GetDecimalDigits() const; void SetDecimalDigits(sal_uInt16 _nPrecision); // There is no check if the current format is numeric, so be cautious when calling these functions
SvNumberFormatter* StandardFormatter() { return m_aStaticFormatter; } // If no new Formatter is created explicitly, this can be used in SetFormatter...
OUString GetFormat(LanguageType& eLang) const; bool SetFormat(const OUString& rFormatString, LanguageType eLang); // sal_False, if the FormatString could not be set (and very probably is invalid) // This Object is shared via all instances, so be careful!
bool IsStrictFormat() const { return m_bStrictFormat; } void SetStrictFormat(bool bEnable) { m_bStrictFormat = bEnable; } // Check format during input
//The following methods are interesting, if m_bTreatAsNumber is set to sal_False //If someone does not care about all the double handling and just wants to print the text formatted. //(((The text will be formatted, using the Formatter, and then set) void SetTextFormatted(const OUString& rText);
OUString const & GetTextValue() const;
// The last colour from the Formatter's last output operation. Output operations get triggered by: // SetValue, SetTextValue, SetTextFormatted, also indirectly via SetMin - / -MaxValue const Color* GetLastOutputColor() const { return m_pLastOutputColor; }
/** reformats the current text. Interesting if the user entered some text in an "input format", and thisshouldbeformattedinthe"outputformat"(whichmaydiffer,e.g.byadditionalnumeric digitsorsuch).
*/ void Commit();
// enable automatic coloring. if set to sal_True, and the format the field is working with for any current value // says that it has to be painted in a special color (e.g. a format where negative numbers should be printed // red), the text is painted with that color automatically. // The color used is the same as returned by GetLastOutputColor() void SetAutoColor(bool _bAutomatic);
/** When being set to true, the strings in the field are formatted using the InputLineformat.That'salsowhatyougetinCalcwhenyoueditacell usingF2
*/ void UseInputStringForFormatting(); bool IsUsingInputStringForFormatting() const { return m_bUseInputStringForFormatting;}
void Modify(bool makeValueDirty = true);
void EntryLostFocus();
void ReFormat();
// any aspect of the current format has changed virtualvoid FormatChanged(FORMAT_CHANGE_TYPE nWhat);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.