Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/vcl/toolkit/field.hxx
Line
Count
Source
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
#pragma once
21
22
#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23
#error "don't use this in new code"
24
#endif
25
26
#include <sal/config.h>
27
28
#include <string_view>
29
30
#include <config_options.h>
31
#include <tools/date.hxx>
32
#include <tools/fldunit.hxx>
33
#include <tools/time.hxx>
34
#include <vcl/toolkit/combobox.hxx>
35
#include <vcl/toolkit/spinfld.hxx>
36
#include <vcl/formatter.hxx>
37
38
namespace com::sun::star::lang { struct Locale; }
39
40
class CalendarWrapper;
41
class LocaleDataWrapper;
42
class LanguageTag;
43
44
class VCL_DLLPUBLIC FormatterBase
45
{
46
private:
47
    VclPtr<Edit>            mpField;
48
    mutable std::unique_ptr<LocaleDataWrapper>
49
                            mpLocaleDataWrapper;
50
    bool                    mbReformat;
51
    bool                    mbStrictFormat;
52
    bool                    mbEmptyFieldValue;
53
    bool                    mbEmptyFieldValueEnabled;
54
55
protected:
56
    SAL_DLLPRIVATE void     ImplSetText( const OUString& rText, Selection const * pNewSel = nullptr );
57
0
    SAL_DLLPRIVATE bool     ImplGetEmptyFieldValue() const  { return mbEmptyFieldValue; }
58
59
0
    void                    SetEmptyFieldValueData( bool bValue ) { mbEmptyFieldValue = bValue; }
60
61
    SAL_DLLPRIVATE LocaleDataWrapper& ImplGetLocaleDataWrapper() const;
62
    /** reset the LocaleDataWrapper when the language tag changes */
63
    SAL_DLLPRIVATE void ImplResetLocaleDataWrapper() const;
64
65
0
    Edit*                   GetField() const            { return mpField; }
66
0
    void                    ClearField() { mpField.reset(); }
67
68
public:
69
    explicit                FormatterBase(Edit* pField);
70
    virtual                 ~FormatterBase();
71
72
    const LocaleDataWrapper& GetLocaleDataWrapper() const;
73
74
0
    bool                    MustBeReformatted() const   { return mbReformat; }
75
0
    void                    MarkToBeReformatted( bool b ) { mbReformat = b; }
76
77
    void                    SetStrictFormat( bool bStrict );
78
0
    bool                    IsStrictFormat() const { return mbStrictFormat; }
79
80
    virtual void            Reformat();
81
    virtual void            ReformatAll();
82
83
    const css::lang::Locale& GetLocale() const;
84
    const LanguageTag&      GetLanguageTag() const;
85
86
    void                    SetEmptyFieldValue();
87
    bool                    IsEmptyFieldValue() const;
88
89
0
    void                    EnableEmptyFieldValue( bool bEnable )   { mbEmptyFieldValueEnabled = bEnable; }
90
0
    bool                    IsEmptyFieldValueEnabled() const        { return mbEmptyFieldValueEnabled; }
91
};
92
93
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) SAL_LOPLUGIN_ANNOTATE("crosscast") NumericFormatter : public FormatterBase
94
{
95
public:
96
    virtual                 ~NumericFormatter() override;
97
98
    virtual void            Reformat() override;
99
100
    void                    SetMin( sal_Int64 nNewMin );
101
0
    sal_Int64               GetMin() const { return mnMin; }
102
    void                    SetMax( sal_Int64 nNewMax );
103
0
    sal_Int64               GetMax() const { return mnMax; }
104
105
    sal_Int64               ClipAgainstMinMax(sal_Int64 nValue) const;
106
    sal_Int64               ClipDoubleAgainstMinMax(double nValue) const;
107
108
0
    void                    SetFirst( sal_Int64 nNewFirst )   { mnFirst = nNewFirst; }
109
0
    sal_Int64               GetFirst() const                  { return mnFirst; }
110
0
    void                    SetLast( sal_Int64 nNewLast )     { mnLast = nNewLast; }
111
0
    sal_Int64               GetLast() const                   { return mnLast; }
112
0
    void                    SetSpinSize( sal_Int64 nNewSize ) { mnSpinSize = nNewSize; }
113
0
    sal_Int64               GetSpinSize() const               { return mnSpinSize; }
114
115
    void                    SetDecimalDigits( sal_uInt16 nDigits );
116
0
    sal_uInt16                  GetDecimalDigits() const { return mnDecimalDigits;}
117
118
    void                    SetUseThousandSep( bool b );
119
0
    bool                    IsUseThousandSep() const { return mbThousandSep; }
120
121
    void                    SetUserValue( sal_Int64 nNewValue );
122
    virtual void            SetValue( sal_Int64 nNewValue );
123
    sal_Int64               GetValue() const;
124
    virtual OUString        CreateFieldText( sal_Int64 nValue ) const;
125
126
    sal_Int64               Normalize( sal_Int64 nValue ) const;
127
    sal_Int64               Denormalize( sal_Int64 nValue ) const;
128
129
    OUString                GetValueString() const;
130
    void                    SetValueFromString(const OUString& rStr);
131
132
protected:
133
    sal_Int64               mnLastValue;
134
    sal_Int64               mnMin;
135
    sal_Int64               mnMax;
136
    bool                    mbFormatting;
137
138
    // the members below are used in all derivatives of NumericFormatter
139
    // not in NumericFormatter itself.
140
    sal_Int64               mnSpinSize;
141
    sal_Int64               mnFirst;
142
    sal_Int64               mnLast;
143
144
                            NumericFormatter(Edit* pEdit);
145
146
    void                    FieldUp();
147
    void                    FieldDown();
148
    void                    FieldFirst();
149
    void                    FieldLast();
150
    void                    FormatValue(Selection const * pNewSelection = nullptr);
151
152
    SAL_DLLPRIVATE void     ImplNumericReformat();
153
    SAL_DLLPRIVATE void     ImplNewFieldValue( sal_Int64 nNewValue );
154
    SAL_DLLPRIVATE void     ImplSetUserValue( sal_Int64 nNewValue, Selection const * pNewSelection = nullptr );
155
156
    virtual sal_Int64       GetValueFromString(std::u16string_view rStr) const;
157
158
private:
159
    sal_uInt16              mnDecimalDigits;
160
    bool                    mbThousandSep;
161
162
};
163
164
class VCL_DLLPUBLIC MetricFormatter : public NumericFormatter
165
{
166
public:
167
    SAL_DLLPRIVATE virtual                 ~MetricFormatter() override;
168
169
    SAL_DLLPRIVATE virtual void            Reformat() override;
170
171
    SAL_DLLPRIVATE virtual void            SetUnit( FieldUnit meUnit );
172
0
    FieldUnit               GetUnit() const { return meUnit; }
173
    void                    SetCustomUnitText( const OUString& rStr );
174
0
    const OUString&         GetCustomUnitText() const { return maCustomUnitText; }
175
176
    using NumericFormatter::SetMax;
177
    void                    SetMax( sal_Int64 nNewMax, FieldUnit eInUnit );
178
    using NumericFormatter::GetMax;
179
    sal_Int64               GetMax( FieldUnit eOutUnit ) const;
180
    using NumericFormatter::SetMin;
181
    void                    SetMin( sal_Int64 nNewMin, FieldUnit eInUnit );
182
    using NumericFormatter::GetMin;
183
    sal_Int64               GetMin( FieldUnit eOutUnit ) const;
184
185
    void                    SetValue( sal_Int64 nNewValue, FieldUnit eInUnit );
186
    SAL_DLLPRIVATE virtual void            SetValue( sal_Int64 nValue ) override;
187
    using NumericFormatter::SetUserValue;
188
    void                    SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit );
189
    using NumericFormatter::GetValue;
190
    sal_Int64               GetValue( FieldUnit eOutUnit ) const;
191
    SAL_DLLPRIVATE virtual OUString        CreateFieldText( sal_Int64 nValue ) const override;
192
    sal_Int64               GetCorrectedValue( FieldUnit eOutUnit ) const;
193
194
protected:
195
    FieldUnit               meUnit;
196
197
    SAL_DLLPRIVATE                         MetricFormatter(Edit* pEdit);
198
199
    SAL_DLLPRIVATE void     ImplMetricReformat( std::u16string_view rStr, double& rValue, OUString& rOutStr );
200
201
    SAL_DLLPRIVATE virtual sal_Int64       GetValueFromString(std::u16string_view rStr) const override;
202
    SAL_DLLPRIVATE sal_Int64               GetValueFromStringUnit(std::u16string_view rStr, FieldUnit eOutUnit) const;
203
204
private:
205
    OUString                maCustomUnitText;
206
};
207
208
class VCL_DLLPUBLIC MetricField final : public SpinField, public MetricFormatter
209
{
210
public:
211
    explicit                MetricField( vcl::Window* pParent, WinBits nWinStyle );
212
213
    SAL_DLLPRIVATE virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
214
    SAL_DLLPRIVATE virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
215
216
    SAL_DLLPRIVATE virtual Size            CalcMinimumSize() const override;
217
218
    SAL_DLLPRIVATE virtual void            Modify() override;
219
220
    SAL_DLLPRIVATE virtual void            Up() override;
221
    SAL_DLLPRIVATE virtual void            Down() override;
222
    SAL_DLLPRIVATE virtual void            First() override;
223
    SAL_DLLPRIVATE virtual void            Last() override;
224
225
    virtual void            SetUnit( FieldUnit meUnit ) override;
226
227
    void                    SetFirst( sal_Int64 nNewFirst, FieldUnit eInUnit );
228
    sal_Int64               GetFirst( FieldUnit eOutUnit ) const;
229
    void                    SetLast( sal_Int64 nNewLast, FieldUnit eInUnit );
230
    sal_Int64               GetLast( FieldUnit eOutUnit ) const;
231
232
    SAL_DLLPRIVATE virtual bool            set_property(const OUString &rKey, const OUString &rValue) override;
233
    SAL_DLLPRIVATE virtual void            dispose() override;
234
235
    SAL_DLLPRIVATE virtual FactoryFunction GetUITestFactory() const override;
236
};
237
238
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) MetricBox final : public ComboBox, public MetricFormatter
239
{
240
public:
241
    explicit                MetricBox( vcl::Window* pParent, WinBits nWinStyle );
242
243
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
244
    virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
245
246
    virtual Size            CalcMinimumSize() const override;
247
248
    virtual void            Modify() override;
249
250
    virtual void            ReformatAll() override;
251
252
    // Needed, because GetValue() with nPos hide these functions
253
    using MetricFormatter::GetValue;
254
255
    virtual void            dispose() override;
256
};
257
258
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) CurrencyFormatter : public NumericFormatter
259
{
260
protected:
261
                            CurrencyFormatter(Edit* pEdit);
262
    SAL_DLLPRIVATE void     ImplCurrencyReformat( std::u16string_view rStr, OUString& rOutStr );
263
    virtual sal_Int64       GetValueFromString(std::u16string_view rStr) const override;
264
265
public:
266
    virtual                 ~CurrencyFormatter() override;
267
268
    virtual void            Reformat() override;
269
270
    virtual void            SetValue( sal_Int64 nNewValue ) override;
271
    virtual OUString        CreateFieldText( sal_Int64 nValue ) const override;
272
};
273
274
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) CurrencyField final : public SpinField, public CurrencyFormatter
275
{
276
public:
277
    CurrencyField( vcl::Window* pParent, WinBits nWinStyle );
278
279
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
280
    virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
281
282
    virtual void            Modify() override;
283
284
    virtual void            Up() override;
285
    virtual void            Down() override;
286
    virtual void            First() override;
287
    virtual void            Last() override;
288
    virtual void            dispose() override;
289
};
290
291
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) TimeFormatter : public FormatterBase
292
{
293
private:
294
    tools::Time             maLastTime;
295
    tools::Time             maMin;
296
    tools::Time             maMax;
297
    TimeFieldFormat         meFormat;
298
    TimeFormat              mnTimeFormat;
299
    bool                    mbDuration;
300
    bool                    mbEnforceValidValue;
301
302
protected:
303
    tools::Time             maFieldTime;
304
305
                            TimeFormatter(Edit* pEdit);
306
307
    SAL_DLLPRIVATE void     ImplTimeReformat( std::u16string_view rStr, OUString& rOutStr );
308
    SAL_DLLPRIVATE void     ImplNewFieldValue( const tools::Time& rTime );
309
    SAL_DLLPRIVATE void     ImplSetUserTime( const tools::Time& rNewTime, Selection const * pNewSelection = nullptr );
310
    SAL_DLLPRIVATE bool     ImplAllowMalformedInput() const;
311
312
public:
313
    static OUString         FormatTime(const tools::Time& rNewTime, TimeFieldFormat eFormat, TimeFormat eHourFormat, bool bDuration, const LocaleDataWrapper& rLocaleData);
314
    static bool             TextToTime(std::u16string_view rStr, tools::Time& rTime, TimeFieldFormat eFormat, bool bDuration, const LocaleDataWrapper& rLocaleDataWrapper, bool _bSkipInvalidCharacters = true);
315
    static int              GetTimeArea(TimeFieldFormat eFormat, std::u16string_view rText, int nCursor,
316
                                        const LocaleDataWrapper& rLocaleDataWrapper);
317
    static tools::Time      SpinTime(bool bUp, const tools::Time& rTime, TimeFieldFormat eFormat,
318
                                     bool bDuration, std::u16string_view rText, int nCursor,
319
                                     const LocaleDataWrapper& rLocaleDataWrapper);
320
321
    virtual                 ~TimeFormatter() override;
322
323
    virtual void            Reformat() override;
324
    virtual void            ReformatAll() override;
325
326
    void                    SetMin( const tools::Time& rNewMin );
327
0
    const tools::Time&             GetMin() const { return maMin; }
328
    void                    SetMax( const tools::Time& rNewMax );
329
0
    const tools::Time&             GetMax() const { return maMax; }
330
331
    void                    SetTimeFormat( TimeFormat eNewFormat );
332
0
    TimeFormat              GetTimeFormat() const { return mnTimeFormat;}
333
334
    void                    SetFormat( TimeFieldFormat eNewFormat );
335
0
    TimeFieldFormat         GetFormat() const { return meFormat; }
336
337
    void                    SetDuration( bool mbDuration );
338
0
    bool                    IsDuration() const { return mbDuration; }
339
340
    void                    SetTime( const tools::Time& rNewTime );
341
    void                    SetUserTime( const tools::Time& rNewTime );
342
    tools::Time             GetTime() const;
343
0
    void                    SetEmptyTime() { FormatterBase::SetEmptyFieldValue(); }
344
0
    bool                    IsEmptyTime() const { return FormatterBase::IsEmptyFieldValue(); }
345
346
    /** enables or disables the enforcement of valid values
347
348
        If this is set to true (which is the default), then GetTime will always return a valid
349
        time, no matter whether the current text can really be interpreted as time. (Note: this
350
        is the compatible behavior).
351
352
        If this is set to false, the GetTime will return GetInvalidTime, in case the current text
353
        cannot be interpreted as time.
354
355
        In addition, if this is set to false, the text in the field will <em>not</em> be corrected
356
        when the control loses the focus - instead, the invalid input will be preserved.
357
    */
358
0
    void                    EnforceValidValue( bool _bEnforce ) { mbEnforceValidValue = _bEnforce; }
359
0
    bool             IsEnforceValidValue( ) const { return mbEnforceValidValue; }
360
};
361
362
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) TimeField final : public SpinField, public TimeFormatter
363
{
364
private:
365
    tools::Time                    maFirst;
366
    tools::Time                    maLast;
367
368
    SAL_DLLPRIVATE void     ImplTimeSpinArea( bool bUp );
369
370
public:
371
    explicit                TimeField( vcl::Window* pParent, WinBits nWinStyle );
372
373
    virtual bool            PreNotify( NotifyEvent& rNEvt ) override;
374
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
375
    virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
376
377
    virtual void            Modify() override;
378
379
    virtual void            Up() override;
380
    virtual void            Down() override;
381
    virtual void            First() override;
382
    virtual void            Last() override;
383
384
0
    void                    SetFirst( const tools::Time& rNewFirst )   { maFirst = rNewFirst; }
385
0
    const tools::Time&      GetFirst() const                    { return maFirst; }
386
0
    void                    SetLast( const tools::Time& rNewLast )     { maLast = rNewLast; }
387
0
    const tools::Time&      GetLast() const                     { return maLast; }
388
389
    void                    SetExtFormat( ExtTimeFieldFormat eFormat );
390
    virtual void            dispose() override;
391
};
392
393
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateFormatter : public FormatterBase
394
{
395
private:
396
    Formatter::StaticFormatter maStaticFormatter;
397
    std::unique_ptr<CalendarWrapper> mxCalendarWrapper;
398
    Date                    maFieldDate;
399
    Date                    maLastDate;
400
    Date                    maMin;
401
    Date                    maMax;
402
    bool                    mbLongFormat;
403
    bool                    mbShowDateCentury;
404
    ExtDateFieldFormat      mnExtDateFormat;
405
    bool                    mbEnforceValidValue;
406
407
protected:
408
                            DateFormatter(Edit* pEdit);
409
410
0
    SAL_DLLPRIVATE const Date& ImplGetFieldDate() const    { return maFieldDate; }
411
    SAL_DLLPRIVATE void     ImplDateReformat( const OUString& rStr, OUString& rOutStr );
412
    SAL_DLLPRIVATE void     ImplSetUserDate( const Date& rNewDate,
413
                                             Selection const * pNewSelection = nullptr );
414
    SAL_DLLPRIVATE OUString ImplGetDateAsText( const Date& rDate ) const;
415
    SAL_DLLPRIVATE void     ImplNewFieldValue( const Date& rDate );
416
    CalendarWrapper&        GetCalendarWrapper() const;
417
418
    SAL_DLLPRIVATE bool     ImplAllowMalformedInput() const;
419
420
public:
421
    static OUString         FormatDate(const Date& rNewDate, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleData, const Formatter::StaticFormatter& rStaticFormatter);
422
    static bool             TextToDate(const OUString& rStr, Date& rTime, ExtDateFieldFormat eFormat, const LocaleDataWrapper& rLocaleDataWrapper, const CalendarWrapper& rCalendarWrapper);
423
    static int              GetDateArea(ExtDateFieldFormat& eFormat, std::u16string_view rText, int nCursor, const LocaleDataWrapper& rLocaleDataWrapper);
424
425
    virtual                 ~DateFormatter() override;
426
427
    virtual void            Reformat() override;
428
    virtual void            ReformatAll() override;
429
430
    void                    SetExtDateFormat( ExtDateFieldFormat eFormat );
431
    ExtDateFieldFormat      GetExtDateFormat( bool bResolveSystemFormat = false ) const;
432
433
    void                    SetMin( const Date& rNewMin );
434
0
    const Date&             GetMin() const { return maMin; }
435
436
    void                    SetMax( const Date& rNewMax );
437
0
    const Date&             GetMax() const { return maMax; }
438
439
440
    // MT: Remove these methods too, ExtDateFormat should be enough!
441
    //     What should happen if using DDMMYYYY, but ShowCentury=false?
442
443
    void                    SetLongFormat( bool bLong );
444
0
    bool                    IsLongFormat() const { return mbLongFormat; }
445
    void                    SetShowDateCentury( bool bShowCentury );
446
0
    bool                    IsShowDateCentury() const { return mbShowDateCentury; }
447
448
449
    void                    SetDate( const Date& rNewDate );
450
    Date                    GetDate() const;
451
    void                    SetEmptyDate();
452
    bool                    IsEmptyDate() const;
453
454
0
    void                    ResetLastDate() { maLastDate = Date( Date::EMPTY ); }
455
456
    static void             ExpandCentury( Date& rDate );
457
    static void             ExpandCentury( Date& rDate, sal_uInt16 nTwoDigitYearStart );
458
459
    /** enables or disables the enforcement of valid values
460
461
        If this is set to true (which is the default), then GetDate will always return a valid
462
        date, no matter whether the current text can really be interpreted as date. (Note: this
463
        is the compatible behavior).
464
465
        If this is set to false, the GetDate will return GetInvalidDate, in case the current text
466
        cannot be interpreted as date.
467
468
        In addition, if this is set to false, the text in the field will \em not be corrected
469
        when the control loses the focus - instead, the invalid input will be preserved.
470
    */
471
0
    void                    EnforceValidValue( bool _bEnforce ) { mbEnforceValidValue = _bEnforce; }
472
0
    bool             IsEnforceValidValue( ) const { return mbEnforceValidValue; }
473
};
474
475
class SAL_DLLPUBLIC_RTTI DateField : public SpinField, public DateFormatter
476
{
477
private:
478
    Date                    maFirst;
479
    Date                    maLast;
480
481
protected:
482
    void                    ImplDateSpinArea( bool bUp );
483
484
public:
485
    explicit                DateField( vcl::Window* pParent, WinBits nWinStyle );
486
487
    virtual bool            PreNotify( NotifyEvent& rNEvt ) override;
488
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
489
    virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
490
491
    virtual void            Modify() override;
492
493
    virtual void            Up() override;
494
    virtual void            Down() override;
495
    virtual void            First() override;
496
    virtual void            Last() override;
497
498
0
    void                    SetFirst( const Date& rNewFirst )   { maFirst = rNewFirst; }
499
0
    const Date&             GetFirst() const                    { return maFirst; }
500
0
    void                    SetLast( const Date& rNewLast )     { maLast = rNewLast; }
501
0
    const Date&             GetLast() const                     { return maLast; }
502
    virtual void            dispose() override;
503
};
504
505
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) NumericBox final : public ComboBox, public NumericFormatter
506
{
507
    SAL_DLLPRIVATE void     ImplNumericReformat( std::u16string_view rStr, sal_Int64& rValue, OUString& rOutStr );
508
public:
509
    explicit                NumericBox( vcl::Window* pParent, WinBits nWinStyle );
510
511
    virtual Size            CalcMinimumSize() const override;
512
513
    virtual bool            PreNotify( NotifyEvent& rNEvt ) override;
514
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
515
    virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
516
517
    virtual void            Modify() override;
518
519
    virtual void            ReformatAll() override;
520
521
    virtual void            dispose() override;
522
};
523
524
0
#define PATTERN_FORMAT_EMPTYLITERALS    (sal_uInt16(0x0001))
525
526
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) PatternFormatter : public FormatterBase
527
{
528
private:
529
    OString                m_aEditMask;
530
    OUString               maLiteralMask;
531
    bool                   mbSameMask;
532
    bool                   mbInPattKeyInput;
533
534
protected:
535
                            PatternFormatter(Edit* pEdit);
536
537
0
    SAL_DLLPRIVATE bool     ImplIsSameMask() const { return mbSameMask; }
538
0
    SAL_DLLPRIVATE bool&    ImplGetInPattKeyInput() { return mbInPattKeyInput; }
539
540
public:
541
    virtual                 ~PatternFormatter() override;
542
543
    virtual void            Reformat() override;
544
545
    void SetMask(const OString& rEditMask, const OUString& rLiteralMask );
546
0
    const OString& GetEditMask() const { return m_aEditMask; }
547
0
    const OUString&        GetLiteralMask() const  { return maLiteralMask; }
548
549
    void                    SetString( const OUString& rStr );
550
    OUString                GetString() const;
551
};
552
553
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) PatternField final : public SpinField, public PatternFormatter
554
{
555
public:
556
    explicit                PatternField( vcl::Window* pParent, WinBits nWinStyle );
557
558
    virtual bool            PreNotify( NotifyEvent& rNEvt ) override;
559
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
560
    virtual void            Modify() override;
561
    virtual void            dispose() override;
562
};
563
564
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) PatternBox final : public ComboBox, public PatternFormatter
565
{
566
public:
567
                            PatternBox( vcl::Window* pParent, WinBits nWinStyle );
568
569
    virtual bool            PreNotify( NotifyEvent& rNEvt ) override;
570
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
571
572
    virtual void            Modify() override;
573
574
    virtual void            ReformatAll() override;
575
    virtual void            dispose() override;
576
};
577
578
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) CurrencyBox final : public ComboBox, public CurrencyFormatter
579
{
580
public:
581
    explicit                CurrencyBox( vcl::Window* pParent, WinBits nWinStyle );
582
583
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
584
    virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
585
586
    virtual void            Modify() override;
587
588
    virtual void            ReformatAll() override;
589
590
    virtual void            dispose() override;
591
};
592
593
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) DateBox final : public ComboBox, public DateFormatter
594
{
595
public:
596
    explicit                DateBox( vcl::Window* pParent, WinBits nWinStyle );
597
598
    virtual bool            PreNotify( NotifyEvent& rNEvt ) override;
599
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
600
    virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
601
602
    virtual void            Modify() override;
603
604
    virtual void            ReformatAll() override;
605
    virtual void            dispose() override;
606
};
607
608
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) TimeBox final : public ComboBox, public TimeFormatter
609
{
610
public:
611
    explicit                TimeBox( vcl::Window* pParent, WinBits nWinStyle );
612
613
    virtual bool            PreNotify( NotifyEvent& rNEvt ) override;
614
    virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
615
    virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
616
617
    virtual void            Modify() override;
618
619
    virtual void            ReformatAll() override;
620
    virtual void            dispose() override;
621
};
622
623
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */