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