Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/inc/global.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
#include "address.hxx"
23
#include "typedstrdata.hxx"
24
#include <i18nlangtag/lang.h>
25
#include <svx/svdtypes.hxx>
26
#include <rtl/ref.hxx>
27
#include <sal/types.h>
28
#include <com/sun/star/i18n/CollatorOptions.hpp>
29
#include <com/sun/star/sheet/CellFlags.hpp>
30
#include "scdllapi.h"
31
#include <rtl/ustring.hxx>
32
#include <tools/long.hxx>
33
#include <o3tl/unit_conversion.hxx>
34
35
#include <atomic>
36
// HACK: <atomic> includes <stdbool.h>, which in some Clang versions does '#define bool bool',
37
// which confuses clang plugins.
38
#undef bool
39
40
#include <memory>
41
#include <optional>
42
#include <string_view>
43
#include <unordered_map>
44
45
namespace com::sun::star::uno { template <typename > class Reference; }
46
47
class SfxItemSet;
48
class SfxViewShell;
49
struct ScCalcConfig;
50
enum class SvtScriptType : sal_uInt8;
51
enum class FormulaError : sal_uInt16;
52
enum class SvNumFormatType : sal_Int16;
53
54
1
#define SC_COLLATOR_IGNORES css::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE
55
56
//  Calc has lots of names...
57
//  Clipboard names are in so3/soapp.hxx now
58
//  STRING_SCAPP was "scalc3", "scalc4", now just "scalc"
59
60
inline constexpr OUString STRING_SCAPP = u"scalc"_ustr;
61
62
inline constexpr OUString STRING_STANDARD = u"Standard"_ustr;
63
64
// Have the dreaded programmatic filter name defined in one place.
65
inline constexpr OUString SC_TEXT_CSV_FILTER_NAME = u"Text - txt - csv (StarCalc)"_ustr;
66
inline constexpr OUString SC_HTML_FILTER_NAME = u"HTML (StarCalc)"_ustr;
67
inline constexpr OUString SC_HTML_WEBQ_FILTER_NAME = u"calc_HTML_WebQuery"_ustr;
68
inline constexpr OUString SC_LOTUS_FILTER_NAME = u"Lotus"_ustr;
69
inline constexpr OUString SC_DBASE_FILTER_NAME = u"dBase"_ustr;
70
inline constexpr OUString SC_DIF_FILTER_NAME = u"DIF"_ustr;
71
inline constexpr OUString SC_SC50_FILTER_NAME = u"StarCalc 5.0"_ustr;
72
inline constexpr OUString SC_SOXML_FILTER_NAME = u"StarOffice XML (Calc)"_ustr;
73
inline constexpr OUString SC_QPRO6_FILTER_NAME = u"Quattro Pro 6.0"_ustr;
74
inline constexpr OUString SC_XL4_FILTER_NAME = u"MS Excel 4.0"_ustr;
75
inline constexpr OUString SC_XL4TMPL_FILTER_NAME = u"MS Excel 4.0 Vorlage/Template"_ustr;
76
inline constexpr OUString SC_XL5_FILTER_NAME = u"MS Excel 5.0/95"_ustr;
77
inline constexpr OUString SC_XL5TMPL_FILTER_NAME = u"MS Excel 5.0/95 Vorlage/Template"_ustr;
78
inline constexpr OUString SC_XL95_FILTER_NAME = u"MS Excel 95"_ustr;
79
inline constexpr OUString SC_XL95TMPL_FILTER_NAME = u"MS Excel 95 Vorlage/Template"_ustr;
80
inline constexpr OUString SC_XL97_FILTER_NAME = u"MS Excel 97"_ustr;
81
inline constexpr OUString SC_XL97TMPL_FILTER_NAME = u"MS Excel 97 Vorlage/Template"_ustr;
82
inline constexpr OUString SC_SYLK_FILTER_NAME = u"SYLK"_ustr;
83
inline constexpr OUString SC_RTF_FILTER_NAME = u"Rich Text Format (StarCalc)"_ustr;
84
85
// characters
86
87
const sal_Unicode CHAR_NBSP     = 0x00A0;
88
const sal_Unicode CHAR_SHY      = 0x00AD;
89
const sal_Unicode CHAR_ZWSP     = 0x200B;
90
const sal_Unicode CHAR_LRM      = 0x200E;
91
const sal_Unicode CHAR_RLM      = 0x200F;
92
const sal_Unicode CHAR_NBHY     = 0x2011;
93
const sal_Unicode CHAR_WJ       = 0x2060;
94
const sal_Unicode CHAR_NNBSP    = 0x202F; //NARROW NO-BREAK SPACE
95
96
#define MINDOUBLE   1.7e-307
97
0
#define MAXDOUBLE   1.7e307
98
99
const sal_uInt16 MINZOOM = 20;
100
const sal_uInt16 MAXZOOM = 400;
101
102
const SCSIZE MAXSUBTOTAL        = 3;
103
104
// ~105.88 twip, i.e. about 2 times narrower than o3tl::Length::ch, which is 210 twip
105
inline constexpr auto TWIPS_PER_CHAR = o3tl::toTwips(1 / 13.6, o3tl::Length::in);
106
107
inline constexpr sal_Int32 STD_COL_WIDTH = o3tl::convert(64, o3tl::Length::pt, o3tl::Length::twip);
108
inline constexpr sal_Int32 STD_EXTRA_WIDTH = o3tl::convert(2, o3tl::Length::mm, o3tl::Length::twip);
109
110
inline constexpr sal_Int32 MAX_EXTRA_WIDTH = o3tl::convert(42, o3tl::Length::cm, o3tl::Length::twip);
111
inline constexpr sal_Int32 MAX_EXTRA_HEIGHT = o3tl::convert(42, o3tl::Length::cm, o3tl::Length::twip);
112
inline constexpr sal_Int32 MAX_COL_WIDTH = o3tl::convert(1, o3tl::Length::m, o3tl::Length::twip);
113
inline constexpr sal_Int32 MAX_ROW_HEIGHT = o3tl::convert(1, o3tl::Length::m, o3tl::Length::twip);
114
115
                                    /* standard row height: text + margin - STD_ROWHEIGHT_DIFF */
116
8.38M
#define STD_ROWHEIGHT_DIFF  23
117
118
namespace sc
119
{
120
0
    constexpr ::tools::Long TwipsToEvenHMM( ::tools::Long nTwips ) { return o3tl::convert(nTwips, 127, 144) * 2; }
121
}
122
123
                                    // standard size as OLE server (cells)
124
80.4k
#define OLE_STD_CELLS_X     4
125
80.4k
#define OLE_STD_CELLS_Y     5
126
127
128
                                    // repaint flags (for messages)
129
enum class PaintPartFlags {
130
    NONE          = 0x00,
131
    Grid          = 0x01,
132
    Top           = 0x02,
133
    Left          = 0x04,
134
    Extras        = 0x08,
135
    Marks         = 0x10,
136
    Objects       = 0x20,
137
    Size          = 0x40,
138
    All           = Grid | Top | Left | Extras | Objects | Size,
139
};
140
namespace o3tl {
141
    template<> struct typed_flags<PaintPartFlags> : is_typed_flags<PaintPartFlags, 0x07f> {};
142
}
143
144
                                    // flags for columns / rows
145
enum class CRFlags : sal_uInt8 {
146
    // Filtered always together with Hidden
147
    // Filtered and ManualSize only valid for rows
148
    NONE        = 0x00,
149
    Hidden      = 0x01,
150
    ManualBreak = 0x02,
151
    Filtered    = 0x04,
152
    ManualSize  = 0x08,
153
    All         = Hidden | ManualBreak | Filtered | ManualSize
154
};
155
namespace o3tl {
156
    template<> struct typed_flags<CRFlags> : is_typed_flags<CRFlags, 0x0f> {};
157
}
158
159
enum class ScBreakType {
160
    NONE   = 0x00,
161
    Page   = 0x01,
162
    Manual = 0x02
163
};
164
namespace o3tl {
165
    template<> struct typed_flags<ScBreakType> : is_typed_flags<ScBreakType, 0x03> {};
166
}
167
168
enum class InsertDeleteFlags : sal_Int32
169
{
170
    NONE             = 0x0000,
171
    VALUE            = css::sheet::CellFlags::VALUE,      /// 0x0001 Numeric values (and numeric results if InsertDeleteFlags::FORMULA is not set).
172
    DATETIME         = css::sheet::CellFlags::DATETIME,   /// 0x0002 Dates, times, datetime values.
173
    STRING           = css::sheet::CellFlags::STRING,     /// 0x0004 Strings (and string results if InsertDeleteFlags::FORMULA is not set).
174
    NOTE             = css::sheet::CellFlags::ANNOTATION, /// 0x0008 Cell notes.
175
    FORMULA          = css::sheet::CellFlags::FORMULA,    /// 0x0010 Formula cells.
176
    HARDATTR         = css::sheet::CellFlags::HARDATTR,   /// 0x0020 Hard cell attributes.
177
    STYLES           = css::sheet::CellFlags::STYLES,     /// 0x0040 Cell styles.
178
    OBJECTS          = css::sheet::CellFlags::OBJECTS,    /// 0x0080 Drawing objects.
179
    EDITATTR         = css::sheet::CellFlags::EDITATTR,   /// 0x0100 Rich-text attributes.
180
    /// No value yet for css::sheet::CellFlags::FORMATTED (0x0200)
181
    OUTLINE          = 0x0800,   /// Sheet / outlining (grouping) information
182
    SPARKLINES       = 0x4000,   /// Sparklines in a cell.
183
    NOCAPTIONS       = 0x8000,   /// Internal use only (undo etc.): do not copy/delete caption objects of cell notes.
184
    ADDNOTES         = 0x0400,   /// Internal use only (copy from clip): do not delete existing cell contents when pasting notes.
185
    SPECIAL_BOOLEAN  = 0x1000,
186
    FORGETCAPTIONS   = 0x2000,   /// Internal use only (d&d undo): do not delete caption objects of cell notes.
187
    ATTRIB           = HARDATTR | STYLES,
188
    CONTENTS         = VALUE | DATETIME | STRING | NOTE | FORMULA | OUTLINE | SPARKLINES,
189
    // tdf#116127 - add EDITATTR to ALL flags in order to check for valid function inputs
190
    ALL              = CONTENTS | ATTRIB | OBJECTS | SPARKLINES | EDITATTR,
191
    /// Copy flags for auto/series fill functions: do not touch notes and drawing objects.
192
    AUTOFILL         = ALL & ~(NOTE | OBJECTS)
193
};
194
namespace o3tl
195
{
196
    template<> struct typed_flags<InsertDeleteFlags> : is_typed_flags<InsertDeleteFlags, 0xfdff> {};
197
}
198
static_assert((InsertDeleteFlags::ATTRIB & InsertDeleteFlags::CONTENTS) == InsertDeleteFlags::NONE, "these must match");
199
200
201
enum class ScPasteFunc {
202
    NONE, ADD, SUB, MUL, DIV
203
};
204
                                        // bits for HasAttr
205
enum class HasAttrFlags {
206
    NONE            = 0x0000,
207
    Lines           = 0x0001,
208
    Merged          = 0x0002,
209
    Overlapped      = 0x0004,
210
    Protected       = 0x0008,
211
    Shadow          = 0x0010,
212
    NeedHeight      = 0x0020,
213
    ShadowRight     = 0x0040,
214
    ShadowDown      = 0x0080,
215
    AutoFilter      = 0x0100,
216
    Conditional     = 0x0200,
217
    Rotate          = 0x0400,
218
    NotOverlapped   = 0x0800,
219
    RightOrCenter   = 0x1000,   // right or centered logical alignment
220
};
221
namespace o3tl {
222
    template<> struct typed_flags<HasAttrFlags> : is_typed_flags<HasAttrFlags, 0x1fff> {};
223
}
224
225
226
// Layer id's for drawing.
227
// These are both id's and positions.
228
inline constexpr SdrLayerID SC_LAYER_FRONT   (0);
229
inline constexpr SdrLayerID SC_LAYER_BACK    (1);
230
inline constexpr SdrLayerID SC_LAYER_INTERN  (2);
231
inline constexpr SdrLayerID SC_LAYER_CONTROLS(3);
232
inline constexpr SdrLayerID SC_LAYER_HIDDEN  (4);
233
234
//  link tables
235
enum class ScLinkMode {
236
    NONE, NORMAL, VALUE
237
};
238
                                        //  input
239
enum class ScEnterMode {
240
    NORMAL, BLOCK, MATRIX
241
};
242
243
                                        //  step = 10pt, max. indention = 100 steps
244
0
#define SC_INDENT_STEP      200
245
246
enum class ScScenarioFlags{             //  scenario flags
247
    NONE       = 0,
248
    CopyAll    = 1,
249
    ShowFrame  = 2,
250
    PrintFrame = 4,
251
    TwoWay     = 8,
252
    Attrib     = 16,
253
    Value      = 32,
254
    Protected  = 64
255
};
256
namespace o3tl {
257
    template<> struct typed_flags<ScScenarioFlags> : is_typed_flags<ScScenarioFlags, 127> {};
258
}
259
260
enum class SubtotalFlags {
261
    NONE              = 0x00,
262
    IgnoreNestedStAg  = 0x08,
263
    IgnoreErrVal      = 0x04,
264
    IgnoreHidden      = 0x02,
265
    IgnoreFiltered    = 0x01
266
};
267
namespace o3tl {
268
    template<> struct typed_flags<SubtotalFlags> : is_typed_flags<SubtotalFlags, 0x0f> {};
269
}
270
271
enum class ScCloneFlags{
272
/** Default cell clone flags: do not start listening, do not adjust 3D refs to
273
    old position, clone note captions of cell notes. */
274
    Default          = 0x0000,
275
276
/** If set, cloned formula cells will start to listen to the document. */
277
    StartListening   = 0x0001,
278
279
/** If set, absolute refs will not transformed to external references */
280
    NoMakeAbsExternal = 0x0002,
281
282
/** If set, global named expressions will be converted to sheet-local named
283
    expressions. */
284
    NamesToLocal   = 0x0004
285
};
286
namespace o3tl
287
{
288
    template<> struct typed_flags<ScCloneFlags> : is_typed_flags<ScCloneFlags, 0x0007> {};
289
}
290
291
enum CellType
292
    {
293
        CELLTYPE_NONE,
294
        CELLTYPE_VALUE,
295
        CELLTYPE_STRING,
296
        CELLTYPE_FORMULA,
297
        CELLTYPE_EDIT,
298
    };
299
300
enum class DelCellCmd
301
    {
302
        CellsUp,
303
        CellsLeft,
304
        Rows,
305
        Cols,
306
        NONE
307
    };
308
309
enum InsCellCmd
310
    {
311
        INS_CELLSDOWN,
312
        INS_CELLSRIGHT,
313
        INS_INSROWS_BEFORE,
314
        INS_INSCOLS_BEFORE,
315
        INS_NONE,
316
        INS_INSROWS_AFTER,
317
        INS_INSCOLS_AFTER
318
    };
319
320
enum UpdateRefMode
321
    {
322
        URM_INSDEL,
323
        URM_COPY,
324
        URM_MOVE,
325
        URM_REORDER
326
    };
327
328
enum FillDir
329
    {
330
        FILL_TO_BOTTOM,
331
        FILL_TO_RIGHT,
332
        FILL_TO_TOP,
333
        FILL_TO_LEFT
334
    };
335
336
enum FillCmd
337
    {
338
        FILL_SIMPLE,
339
        FILL_LINEAR,
340
        FILL_GROWTH,
341
        FILL_DATE,
342
        FILL_AUTO
343
    };
344
345
enum ScMoveDirection
346
{
347
    SC_MOVE_RIGHT,
348
    SC_MOVE_LEFT,
349
    SC_MOVE_UP,
350
    SC_MOVE_DOWN
351
};
352
353
enum FillDateCmd
354
    {
355
        FILL_DAY,
356
        FILL_WEEKDAY,
357
        FILL_MONTH,
358
        FILL_END_OF_MONTH,
359
        FILL_YEAR
360
    };
361
362
enum ScDirection
363
    {
364
        DIR_BOTTOM,
365
        DIR_RIGHT,
366
        DIR_TOP,
367
        DIR_LEFT
368
    };
369
370
enum ScSizeMode
371
    {
372
        SC_SIZE_DIRECT,             // set size or hide if value is 0
373
        SC_SIZE_OPTIMAL,            // set optimal size for everything
374
        SC_SIZE_SHOW,               // show with original size
375
        SC_SIZE_VISOPT,             // set optimal size only if visible
376
        SC_SIZE_ORIGINAL            // only set size, don't change visible flag
377
    };
378
379
enum ScInputMode
380
    {
381
        SC_INPUT_NONE,
382
        SC_INPUT_TYPE,              // input, while not in inplace mode
383
        SC_INPUT_TABLE,             // text cursor in the table
384
        SC_INPUT_TOP                // text cursor in the input line
385
    };
386
387
enum ScVObjMode                     // output modes of objects on a page
388
{
389
    VOBJ_MODE_SHOW,
390
    VOBJ_MODE_HIDE
391
};
392
393
enum ScAnchorType                   // anchor of a character object
394
{
395
    SCA_CELL,                       // anchor to cell, move with cell
396
    SCA_CELL_RESIZE,                // anchor to cell, move and resize with cell
397
    SCA_PAGE,                       // anchor to page, independent of any cells
398
    SCA_DONTKNOW                    // for multi selection
399
};
400
401
enum ScGetDBMode
402
{
403
    SC_DB_MAKE,         ///< create "untitled" (if necessary)
404
    SC_DB_AUTOFILTER,   ///< force use of sheet-local instead of document global anonymous range
405
    SC_DB_IMPORT,       ///< create "Importx" (if necessary)
406
    SC_DB_OLD           ///< don't create
407
};
408
409
/// For ScDBFunc::GetDBData()
410
enum class ScGetDBSelection
411
{
412
    /** Keep selection as is, expand to used data area if no selection. */
413
    Keep,
414
415
    /** Shrink selection to actually used data area within the selection. */
416
    ShrinkToUsedData,
417
418
    /** If only one row or portion thereof is selected, shrink row to used data
419
        columns and select further rows down until end of data. If an area is
420
        selected, shrink rows to actually used columns. Else, no selection,
421
        expand to used data area. */
422
    RowDown,
423
424
    /** Behave as if the range corresponding to a ScDBData area was selected,
425
        for API use. */
426
    ForceMark
427
};
428
429
enum ScLkUpdMode    // modes for updating links
430
{
431
    LM_ALWAYS,
432
    LM_NEVER,
433
    LM_ON_DEMAND,
434
    LM_UNKNOWN
435
};
436
437
// enum with values equal to old DBObject enum from sdb
438
enum ScDBObject
439
{
440
    ScDbTable,
441
    ScDbQuery
442
};
443
444
namespace sc {
445
446
enum class EditAction
447
{
448
    Unknown,
449
    InsertColumnsBefore,
450
    InsertColumnsAfter,
451
    InsertRowsBefore,
452
    InsertRowsAfter,
453
    DeleteColumns,
454
    DeleteRows,
455
    UpdatePivotTable
456
};
457
458
}
459
460
struct ScImportParam
461
{
462
    SCCOL           nCol1;
463
    SCROW           nRow1;
464
    SCCOL           nCol2;
465
    SCROW           nRow2;
466
    bool            bImport;
467
    OUString aDBName;                    // alias of data base
468
    OUString aStatement;
469
    bool            bNative;
470
    bool            bSql;                       // statement or name?
471
    sal_uInt8       nType;                      // enum DBObject
472
473
    ScImportParam();
474
    ScImportParam( const ScImportParam& r );
475
    ~ScImportParam();
476
477
    ScImportParam&  operator=   ( const ScImportParam& r );
478
    bool            operator==  ( const ScImportParam& r ) const;
479
};
480
481
// Formula data replacement character for a pair of parentheses at end of
482
// function name, to force sorting parentheses before all other characters.
483
// Collation may treat parentheses differently.
484
inline constexpr sal_Unicode cParenthesesReplacement = 0x0001;
485
struct InputHandlerFunctionNames
486
{
487
    ScTypedCaseStrSet       maFunctionData;
488
    ScTypedCaseStrSet       maFunctionDataPara;
489
    std::set<sal_Unicode>   maFunctionChar;
490
};
491
492
class ScDocShell;
493
class SvxSearchItem;
494
class ScAutoFormat;
495
class LegacyFuncCollection;
496
class ScUnoAddInCollection;
497
class ScUserList;
498
class SvxBrushItem;
499
class ScFunctionList;
500
class ScFunctionMgr;
501
class SfxItemPool;
502
class EditTextObject;
503
class SfxObjectShell;
504
class SvNumberFormatter;
505
struct ScInterpreterContext;
506
class ScUnitConverter;
507
class CharClass;
508
class LocaleDataWrapper;
509
class SvtSysLocale;
510
class CalendarWrapper;
511
class CollatorWrapper;
512
class ScFieldEditEngine;
513
514
namespace com::sun::star {
515
    namespace lang {
516
        struct Locale;
517
    }
518
    namespace i18n {
519
        class XOrdinalSuffix;
520
    }
521
}
522
namespace utl {
523
    class TransliterationWrapper;
524
}
525
526
namespace sc {
527
    class SharedStringPoolPurge;
528
}
529
530
class ScGlobal
531
{
532
    static std::unique_ptr<SvxSearchItem> xSearchItem;
533
    static std::unique_ptr<ScAutoFormat> xAutoFormat;
534
    static std::atomic<LegacyFuncCollection*> pLegacyFuncCollection;
535
    static std::atomic<ScUnoAddInCollection*> pAddInCollection;
536
    static std::unique_ptr<ScUserList> xUserList;
537
    static OUString         aStrClipDocName;
538
    static std::unique_ptr<SvxBrushItem> xEmptyBrushItem;
539
    static std::unique_ptr<SvxBrushItem> xButtonBrushItem;
540
541
    static std::unordered_map<OUString, std::unique_ptr<ScFunctionList>> xStarCalcFunctionList;
542
    static std::unordered_map<OUString, std::unique_ptr<ScFunctionMgr>> xStarCalcFunctionMgr;
543
544
    static std::atomic<ScUnitConverter*> pUnitConverter;
545
546
    static std::unique_ptr<SvNumberFormatter> xEnglishFormatter;          // for UNO / XML export
547
548
    static css::uno::Reference< css::i18n::XOrdinalSuffix> xOrdinalSuffix;
549
    static std::optional<CalendarWrapper>    oCalendar;
550
    static std::atomic<CollatorWrapper*>     pCaseCollator;
551
    static std::atomic<CollatorWrapper*>     pCollator;
552
    static std::atomic<::utl::TransliterationWrapper*> pTransliteration;
553
    static std::atomic<::utl::TransliterationWrapper*> pCaseTransliteration;
554
    static std::atomic<css::lang::Locale*>   pLocale;
555
556
    static std::unique_ptr<ScFieldEditEngine> xFieldEditEngine;
557
558
    static std::atomic<sc::SharedStringPoolPurge*> pSharedStringPoolPurge;
559
560
    static std::unordered_map<OUString, InputHandlerFunctionNames> maInputHandlerFunctionNames;
561
562
    static void                 InitPPT();
563
564
public:
565
    static std::optional<SvtSysLocale> oSysLocale;
566
    SC_DLLPUBLIC static const LocaleDataWrapper& getLocaleData();
567
    SC_DLLPUBLIC static const CharClass& getCharClass();
568
569
    static CalendarWrapper&     GetCalendar();
570
    /// case-insensitive collator
571
    SC_DLLPUBLIC static CollatorWrapper& GetCollator();
572
    /// case-sensitive collator
573
    static CollatorWrapper&     GetCaseCollator();
574
    static CollatorWrapper&     GetCollator(bool bCaseSensitive);
575
    static css::lang::Locale&   GetLocale();
576
577
    SC_DLLPUBLIC static ::utl::TransliterationWrapper& GetTransliteration();
578
    static ::utl::TransliterationWrapper& GetCaseTransliteration();
579
    static ::utl::TransliterationWrapper& GetTransliteration(bool bCaseSensitive);
580
581
    SC_DLLPUBLIC static LanguageType            eLnge;
582
    static constexpr sal_Unicode cListDelimiter = ',';
583
584
    static const OUString&      GetClipDocName();
585
    static void                 SetClipDocName( const OUString& rNew );
586
    SC_DLLPUBLIC static const SvxSearchItem&    GetSearchItem();
587
    SC_DLLPUBLIC static void                    SetSearchItem( const SvxSearchItem& rNew );
588
    SC_DLLPUBLIC static ScAutoFormat*       GetAutoFormat();
589
    SC_DLLPUBLIC static ScAutoFormat*       GetOrCreateAutoFormat();
590
    static void                 ClearAutoFormat(); //BugId 54209
591
    static LegacyFuncCollection*      GetLegacyFuncCollection();
592
    SC_DLLPUBLIC static ScUnoAddInCollection* GetAddInCollection();
593
    SC_DLLPUBLIC static ScUserList&         GetUserList();
594
    static void                 SetUserList( const ScUserList* pNewList );
595
    /**
596
     * Open the specified URL.
597
     * @param bIgnoreSettings - If true, ignore security settings (Ctrl-Click) and just open the URL.
598
     */
599
    SC_DLLPUBLIC static void OpenURL(const OUString& rURL, const OUString& rTarget, bool bIgnoreSettings = false);
600
    /// Whether the URL can be opened according to current security options (Click/Ctrl-Click)
601
    static bool                 ShouldOpenURL();
602
    SC_DLLPUBLIC static OUString            GetAbsDocName( const OUString& rFileName,
603
                                                const SfxObjectShell* pShell );
604
    SC_DLLPUBLIC static OUString            GetDocTabName( std::u16string_view rFileName,
605
                                                std::u16string_view rTabName );
606
    SC_DLLPUBLIC static sal_uInt32 GetStandardFormat( ScInterpreterContext&, sal_uInt32 nFormat, SvNumFormatType nType );
607
608
    /// Horizontal pixel per twips factor.
609
    SC_DLLPUBLIC static double              nScreenPPTX;
610
    /// Vertical pixel per twips factor.
611
    SC_DLLPUBLIC static double              nScreenPPTY;
612
613
    static rtl::Reference<ScDocShell> xDrawClipDocShellRef;
614
615
    static sal_uInt16           nDefFontHeight;
616
    SC_DLLPUBLIC static sal_uInt16           nStdRowHeight;
617
618
    SC_DLLPUBLIC static ::tools::Long                nLastRowHeightExtra;
619
    static ::tools::Long             nLastColWidthExtra;
620
621
    SC_DLLPUBLIC static void Init();                     // during start up
622
    static void             InitAddIns();
623
    SC_DLLPUBLIC static void Clear();                    // at the end of the program
624
625
    static void             InitTextHeight(SfxItemPool& rPool);
626
195k
    static const SvxBrushItem* GetEmptyBrushItem() { return xEmptyBrushItem.get(); }
627
    static SvxBrushItem*    GetButtonBrushItem();
628
629
    static bool             HasStarCalcFunctionList();
630
    static ScFunctionList*  GetStarCalcFunctionList();
631
    static ScFunctionMgr*   GetStarCalcFunctionMgr();
632
    static void             ResetFunctionList();
633
    static const InputHandlerFunctionNames& GetInputHandlerFunctionNames();
634
635
    static OUString         GetErrorString(FormulaError nErrNumber);
636
    static OUString         GetLongErrorString(FormulaError nErrNumber);
637
    static bool             EETextObjEqual( const EditTextObject* pObj1,
638
                                            const EditTextObject* pObj2 );
639
    static bool             CheckWidthInvalidate( bool& bNumFormatChanged,
640
                                                  const SfxItemSet& rNewAttrs,
641
                                                  const SfxItemSet& rOldAttrs );
642
    static bool             HasAttrChanged( const SfxItemSet& rNewAttrs,
643
                                            const SfxItemSet& rOldAttrs,
644
                                            const sal_uInt16      nWhich );
645
646
    static ScUnitConverter* GetUnitConverter();
647
648
    /// strchr() functionality on unicode, as long as we need it for FormulaToken etc.
649
    static const sal_Unicode* UnicodeStrChr( const sal_Unicode* pStr, sal_Unicode c );
650
651
    static sal_Unicode ToUpperAlpha( sal_Unicode c )
652
4.45M
        { return ( c >= 'a' && c <= 'z' ) ? ( c-'a'+'A' ) : c; }
653
654
    /** Adds the string rToken to rTokenList, using a list separator character.
655
        @param rTokenList  The string list where the token will be appended to.
656
        @param rToken  The token string to append to the token list.
657
        @param cSep  The character to separate the tokens.
658
        @param nSepCount  Specifies how often cSep is inserted between two tokens.
659
        @param bForceSep  true = Always insert separator; false = Only, if not at begin or end. */
660
    SC_DLLPUBLIC static OUString addToken(
661
                                std::u16string_view rTokenList, std::u16string_view rToken,
662
                                sal_Unicode cSep, sal_Int32 nSepCount = 1,
663
                                bool bForceSep = false );
664
665
    /** Returns true, if the first and last character of the string is cQuote. */
666
    SC_DLLPUBLIC static bool             IsQuoted( std::u16string_view rString, sal_Unicode cQuote );
667
668
    /** Inserts the character cQuote at beginning and end of rString.
669
        @param bEscapeEmbedded      If <TRUE/>, embedded quote characters are
670
                                    escaped by doubling them.
671
     */
672
    SC_DLLPUBLIC static void             AddQuotes( OUString& rString, sal_Unicode cQuote, bool bEscapeEmbedded = true );
673
674
    /** Erases the character cQuote from rString, if it exists at beginning AND end.
675
        @param bUnescapeEmbedded    If <TRUE/>, embedded doubled quote characters
676
                                    are unescaped by replacing them with a
677
                                    single instance.
678
     */
679
    SC_DLLPUBLIC static void             EraseQuotes( OUString& rString, sal_Unicode cQuote, bool bUnescapeEmbedded = true );
680
681
    /** Finds an unquoted instance of cChar in rString, starting at
682
        offset nStart. Unquoted instances may occur when concatenating two
683
        quoted strings with a separator, for example, 's1':'s2'. Embedded
684
        quotes have to be escaped by being doubled. Caller must ensure that
685
        nStart points into an unquoted range or the opening quote. Specialty:
686
        if cChar=='\'' the first quote character from nStart on is found.
687
        @returns offset if found, else -1
688
     */
689
    SC_DLLPUBLIC static sal_Int32   FindUnquoted( const OUString& rString, sal_Unicode cChar, sal_Int32 nStart = 0 );
690
691
    /** Finds an unquoted instance of cChar in null-terminated pString. Same
692
        semantics as FindUnquoted( const String&, ...)
693
        @returns: pointer to cChar if found, else NULL
694
     */
695
    SC_DLLPUBLIC static const sal_Unicode* FindUnquoted( const sal_Unicode* pString, sal_Unicode cChar );
696
697
    static  rtl_TextEncoding GetCharsetValue( std::u16string_view rCharSet );
698
    static  OUString        GetCharsetString( rtl_TextEncoding eVal );
699
700
    /// a "ReadOnly" formatter for UNO/XML export
701
    static  SvNumberFormatter*  GetEnglishFormatter();
702
703
    static bool IsSystemRTL();                      // depending on system language
704
    static LanguageType GetEditDefaultLanguage();   // for EditEngine::SetDefaultLanguage
705
    SC_DLLPUBLIC static SvtScriptType GetDefaultScriptType();             // for all WEAK characters
706
    /** Map ATTR_((CJK|CTL)_)?FONT_... to proper WhichIDs.
707
        If more than one SvtScriptType::... values are or'ed together, prefers
708
        first COMPLEX, then ASIAN */
709
    SC_DLLPUBLIC static sal_uInt16 GetScriptedWhichID( SvtScriptType nScriptType, sal_uInt16 nWhich );
710
711
    /** Adds a language item to the item set, if the number format item contains
712
        a language that differs from its parent's language. */
713
    SC_DLLPUBLIC static void             AddLanguage( SfxItemSet& rSet, const SvNumberFormatter& rFormatter );
714
715
    /** Obtain the ordinal suffix for a number according to the system locale */
716
    static OUString         GetOrdinalSuffix( sal_Int32 nNumber);
717
718
    static sc::SharedStringPoolPurge& GetSharedStringPoolPurge();
719
720
    /** Replaces the first occurrence of rPlaceholder in rString with
721
        rReplacement, or if rPlaceholder is not found appends one space if
722
        rString does not end in a space and appends rReplacement.
723
724
        Meant to be used with resource strings ala "Column %1" where a
725
        translation may have omitted the %1 placeholder and a simple
726
        replacement would end up with nothing replaced so no column indicator
727
        in the result string.
728
     */
729
    SC_DLLPUBLIC static OUString    ReplaceOrAppend( const OUString& rString,
730
                                                     std::u16string_view rPlaceholder,
731
                                                     const OUString& rReplacement );
732
733
734
    /** Convert string content to numeric value.
735
736
        In any case, if rError is set 0.0 is returned.
737
738
        If nStringNoValueError is FormulaError::CellNoValue, that is unconditionally
739
        assigned to rError and 0.0 is returned. The caller is expected to
740
        handle this situation. Used by the interpreter.
741
742
        Usually FormulaError::NoValue is passed as nStringNoValueError.
743
744
        Otherwise, depending on the string conversion configuration different
745
        approaches are taken:
746
747
748
        For ScCalcConfig::StringConversion::ILLEGAL
749
        The error value passed in nStringNoValueError is assigned to rError
750
        (and 0.0 returned).
751
752
753
        For ScCalcConfig::StringConversion::ZERO
754
        A zero value is returned and no error assigned.
755
756
757
        For ScCalcConfig::StringConversion::LOCALE
758
759
        If the string is empty or consists only of spaces, if "treat empty
760
        string as zero" is set 0.0 is returned, else nStringNoValueError
761
        assigned to rError (and 0.0 returned).
762
763
        Else a non-empty string is passed to the number formatter's scanner to
764
        be parsed locale dependent. If that does not detect a numeric value
765
        nStringNoValueError is assigned to rError (and 0.0 returned).
766
767
        If no number formatter was passed, the conversion falls back to
768
        UNAMBIGUOUS.
769
770
771
        For ScCalcConfig::StringConversion::UNAMBIGUOUS
772
773
        If the string is empty or consists only of spaces, if "treat empty
774
        string as zero" is set 0.0 is returned, else nStringNoValueError
775
        assigned to rError (and 0.0 returned).
776
777
        If the string is not empty the following conversion rules are applied:
778
779
        Converted are only integer numbers including exponent, and ISO 8601 dates
780
        and times in their extended formats with separators. Anything else,
781
        especially fractional numeric values with decimal separators or dates other
782
        than ISO 8601 would be locale dependent and is a no-no. Leading and
783
        trailing blanks are ignored.
784
785
        The following ISO 8601 formats are converted:
786
787
        CCYY-MM-DD
788
        CCYY-MM-DDThh:mm
789
        CCYY-MM-DDThh:mm:ss
790
        CCYY-MM-DDThh:mm:ss,s
791
        CCYY-MM-DDThh:mm:ss.s
792
        hh:mm
793
        hh:mm:ss
794
        hh:mm:ss,s
795
        hh:mm:ss.s
796
797
        The century CC may not be omitted and the two-digit year setting is not
798
        taken into account. Instead of the T date and time separator exactly one
799
        blank may be used.
800
801
        If a date is given, it must be a valid Gregorian calendar date. In this
802
        case the optional time must be in the range 00:00 to 23:59:59.99999...
803
        If only time is given, it may have any value for hours, taking elapsed time
804
        into account; minutes and seconds are limited to the value 59 as well.
805
806
        If the string can not be converted to a numeric value, the error value
807
        passed in nStringNoValueError is assigned to rError.
808
809
810
        @param rStr
811
            The string to be converted.
812
813
        @param rConfig
814
            The calculation configuration.
815
816
        @param rError
817
            Contains the error on return, if any. If an error was set before
818
            and the conversion did not result in an error, still 0.0 is
819
            returned.
820
821
        @param nStringNoValueError
822
            The error value to be assigned to rError if string could not be
823
            converted to number.
824
825
        @param pFormatter
826
            The number formatter to use in case of
827
            ScCalcConfig::StringConversion::LOCALE. Can but should not be
828
            nullptr in which case conversion falls back to
829
            ScCalcConfig::StringConversion::UNAMBIGUOUS and if a date is
830
            detected the null date is assumed to be the standard 1899-12-30
831
            instead of the configured null date.
832
833
        @param rCurFmtType
834
            Can be assigned a format type in case a date or time or date+time
835
            string was converted, e.g. SvNumFormatType::DATE or
836
            SvNumFormatType::TIME or a combination thereof.
837
838
     */
839
    static double ConvertStringToValue( const OUString& rStr, const ScCalcConfig& rConfig,
840
            FormulaError & rError, FormulaError nStringNoValueError,
841
            ScInterpreterContext& rContext, SvNumFormatType & rCurFmtType );
842
843
    /// Calc's threaded group calculation is in progress.
844
    SC_DLLPUBLIC static bool bThreadedGroupCalcInProgress;
845
};
846
847
// maybe move to dbdata.hxx (?):
848
849
enum ScQueryOp
850
    {
851
        SC_EQUAL,
852
        SC_LESS,
853
        SC_GREATER,
854
        SC_LESS_EQUAL,
855
        SC_GREATER_EQUAL,
856
        SC_NOT_EQUAL,
857
        SC_TOPVAL,
858
        SC_BOTVAL,
859
        SC_TOPPERC,
860
        SC_BOTPERC,
861
        SC_CONTAINS,
862
        SC_DOES_NOT_CONTAIN,
863
        SC_BEGINS_WITH,
864
        SC_DOES_NOT_BEGIN_WITH,
865
        SC_ENDS_WITH,
866
        SC_DOES_NOT_END_WITH
867
    };
868
869
enum ScQueryConnect
870
    {
871
        SC_AND,
872
        SC_OR
873
    };
874
875
enum ScSubTotalFunc : sal_Int16
876
    {
877
        SUBTOTAL_FUNC_NONE  = 0,
878
        SUBTOTAL_FUNC_AVE   = 1,
879
        SUBTOTAL_FUNC_CNT   = 2,
880
        SUBTOTAL_FUNC_CNT2  = 3,
881
        SUBTOTAL_FUNC_MAX   = 4,
882
        SUBTOTAL_FUNC_MIN   = 5,
883
        SUBTOTAL_FUNC_PROD  = 6,
884
        SUBTOTAL_FUNC_STD   = 7,
885
        SUBTOTAL_FUNC_STDP  = 8,
886
        SUBTOTAL_FUNC_SUM   = 9,
887
        SUBTOTAL_FUNC_VAR   = 10,
888
        SUBTOTAL_FUNC_VARP  = 11,
889
        SUBTOTAL_FUNC_MED   = 12,
890
        SUBTOTAL_FUNC_SELECTION_COUNT = 13
891
    };
892
893
enum ScAggregateFunc
894
    {
895
        AGGREGATE_FUNC_AVE     = 1,
896
        AGGREGATE_FUNC_CNT     = 2,
897
        AGGREGATE_FUNC_CNT2    = 3,
898
        AGGREGATE_FUNC_MAX     = 4,
899
        AGGREGATE_FUNC_MIN     = 5,
900
        AGGREGATE_FUNC_PROD    = 6,
901
        AGGREGATE_FUNC_STD     = 7,
902
        AGGREGATE_FUNC_STDP    = 8,
903
        AGGREGATE_FUNC_SUM     = 9,
904
        AGGREGATE_FUNC_VAR     = 10,
905
        AGGREGATE_FUNC_VARP    = 11,
906
        AGGREGATE_FUNC_MEDIAN  = 12,
907
        AGGREGATE_FUNC_MODSNGL = 13,
908
        AGGREGATE_FUNC_LARGE   = 14,
909
        AGGREGATE_FUNC_SMALL   = 15,
910
        AGGREGATE_FUNC_PERCINC = 16,
911
        AGGREGATE_FUNC_QRTINC  = 17,
912
        AGGREGATE_FUNC_PERCEXC = 18,
913
        AGGREGATE_FUNC_QRTEXC  = 19
914
    };
915
916
class ScArea;
917
918
struct ScConsolidateParam
919
{
920
    SCCOL           nCol;                   // cursor position /
921
    SCROW           nRow;                   // or start of destination area respectively
922
    SCTAB           nTab;
923
    ScSubTotalFunc  eFunction;
924
    sal_uInt16      nDataAreaCount;         // number of data areas
925
    std::unique_ptr<ScArea[]> pDataAreas; // array of pointers into data areas
926
    bool            bByCol;
927
    bool            bByRow;
928
    bool            bReferenceData;         // reference source data
929
930
    ScConsolidateParam();
931
    ScConsolidateParam( const ScConsolidateParam& r );
932
    ~ScConsolidateParam();
933
934
    ScConsolidateParam& operator=       ( const ScConsolidateParam& r );
935
    bool                operator==      ( const ScConsolidateParam& r ) const;
936
    void                Clear           (); // = ClearDataAreas()+Members
937
    void                ClearDataAreas  ();
938
    void                SetAreas        ( std::unique_ptr<ScArea[]> pAreas, sal_uInt16 nCount );
939
};
940
941
extern SfxViewShell* pScActiveViewShell;
942
extern sal_uInt16 nScClickMouseModifier;
943
extern sal_uInt16 nScFillModeMouseModifier;
944
945
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */