1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <vcl/svapp.hxx>
21 #include "scitems.hxx"
22 #include <svx/algitem.hxx>
23 #include <editeng/brushitem.hxx>
24 #include <editeng/editobj.hxx>
25 #include <editeng/scripttypeitem.hxx>
26 #include <svl/srchitem.hxx>
27 #include <editeng/langitem.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <sfx2/viewsh.hxx>
33 #include <svl/stritem.hxx>
34 #include <svl/zforlist.hxx>
35 #include <svl/zformat.hxx>
36 #include <vcl/image.hxx>
37 #include <vcl/virdev.hxx>
38 #include <vcl/settings.hxx>
39 #include <sal/macros.h>
40 #include <tools/rcid.h>
41 #include <unotools/charclass.hxx>
42 #include <unotools/securityoptions.hxx>
47 #include <svx/svdmodel.hxx>
49 #include <i18nlangtag/mslangid.hxx>
50 #include <com/sun/star/lang/Locale.hpp>
51 #include <comphelper/processfactory.hxx>
52 #include <comphelper/random.hxx>
53 #include <comphelper/string.hxx>
54 #include <unotools/calendarwrapper.hxx>
55 #include <unotools/collatorwrapper.hxx>
56 #include <com/sun/star/i18n/CollatorOptions.hpp>
57 #include <unotools/intlwrapper.hxx>
58 #include <unotools/syslocale.hxx>
59 #include <unotools/transliterationwrapper.hxx>
61 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
64 #include "scresid.hxx"
65 #include "autoform.hxx"
66 #include "document.hxx"
67 #include "patattr.hxx"
68 #include "addincol.hxx"
69 #include "adiasync.hxx"
70 #include "userlist.hxx"
71 #include "interpre.hxx"
72 #include "strload.hxx"
73 #include "docpool.hxx"
74 #include "unitconv.hxx"
75 #include "compiler.hxx"
76 #include "parclass.hxx"
77 #include "funcdesc.hxx"
78 #include "globstr.hrc"
79 #include "scfuncs.hrc"
82 #include "appoptio.hxx"
83 #include "editutil.hxx"
85 tools::SvRef
<ScDocShell
>* ScGlobal::pDrawClipDocShellRef
= NULL
;
86 SvxSearchItem
* ScGlobal::pSearchItem
= NULL
;
87 ScAutoFormat
* ScGlobal::pAutoFormat
= NULL
;
88 FuncCollection
* ScGlobal::pFuncCollection
= NULL
;
89 ScUnoAddInCollection
* ScGlobal::pAddInCollection
= NULL
;
90 ScUserList
* ScGlobal::pUserList
= NULL
;
91 OUString
** ScGlobal::ppRscString
= NULL
;
92 LanguageType
ScGlobal::eLnge
= LANGUAGE_SYSTEM
;
93 ::com::sun::star::lang::Locale
* ScGlobal::pLocale
= NULL
;
94 SvtSysLocale
* ScGlobal::pSysLocale
= NULL
;
95 const CharClass
* ScGlobal::pCharClass
= NULL
;
96 const LocaleDataWrapper
* ScGlobal::pLocaleData
= NULL
;
97 CalendarWrapper
* ScGlobal::pCalendar
= NULL
;
98 CollatorWrapper
* ScGlobal::pCollator
= NULL
;
99 CollatorWrapper
* ScGlobal::pCaseCollator
= NULL
;
100 ::utl::TransliterationWrapper
* ScGlobal::pTransliteration
= NULL
;
101 ::utl::TransliterationWrapper
* ScGlobal::pCaseTransliteration
= NULL
;
102 ::com::sun::star::uno::Reference
< ::com::sun::star::i18n::XOrdinalSuffix
> ScGlobal::xOrdinalSuffix
= NULL
;
103 IntlWrapper
* ScGlobal::pScIntlWrapper
= NULL
;
104 sal_Unicode
ScGlobal::cListDelimiter
= ',';
105 OUString
* ScGlobal::pEmptyOUString
= NULL
;
106 OUString
* ScGlobal::pStrClipDocName
= NULL
;
108 SvxBrushItem
* ScGlobal::pEmptyBrushItem
= NULL
;
109 SvxBrushItem
* ScGlobal::pButtonBrushItem
= NULL
;
110 SvxBrushItem
* ScGlobal::pEmbeddedBrushItem
= NULL
;
111 SvxBrushItem
* ScGlobal::pProtectedBrushItem
= NULL
;
113 ImageList
* ScGlobal::pOutlineBitmaps
= NULL
;
115 ScFunctionList
* ScGlobal::pStarCalcFunctionList
= NULL
;
116 ScFunctionMgr
* ScGlobal::pStarCalcFunctionMgr
= NULL
;
118 ScUnitConverter
* ScGlobal::pUnitConverter
= NULL
;
119 SvNumberFormatter
* ScGlobal::pEnglishFormatter
= NULL
;
120 ScFieldEditEngine
* ScGlobal::pFieldEditEngine
= NULL
;
122 double ScGlobal::nScreenPPTX
= 96.0;
123 double ScGlobal::nScreenPPTY
= 96.0;
125 sal_uInt16
ScGlobal::nDefFontHeight
= 225;
126 sal_uInt16
ScGlobal::nStdRowHeight
= 256;
128 long ScGlobal::nLastRowHeightExtra
= 0;
129 long ScGlobal::nLastColWidthExtra
= STD_EXTRA_WIDTH
;
131 static sal_uInt16 nPPTZoom
= 0; // ScreenZoom used to determine nScreenPPTX/Y
133 SfxViewShell
* pScActiveViewShell
= NULL
; //FIXME: Make this a member
134 sal_uInt16 nScClickMouseModifier
= 0; //FIXME: This too
135 sal_uInt16 nScFillModeMouseModifier
= 0; //FIXME: And this
139 bool ScGlobal::HasAttrChanged( const SfxItemSet
& rNewAttrs
,
140 const SfxItemSet
& rOldAttrs
,
141 const sal_uInt16 nWhich
)
143 bool bInvalidate
= false;
144 const SfxItemState eNewState
= rNewAttrs
.GetItemState( nWhich
);
145 const SfxItemState eOldState
= rOldAttrs
.GetItemState( nWhich
);
147 if ( eNewState
== eOldState
)
150 // PoolItems, meaning comparing pointers is valid
151 if ( SfxItemState::SET
== eOldState
)
152 bInvalidate
= (&rNewAttrs
.Get( nWhich
) != &rOldAttrs
.Get( nWhich
));
156 // Contains a Default Item
157 // PoolItems, meaning Item comparison necessary
158 const SfxPoolItem
& rOldItem
= ( SfxItemState::SET
== eOldState
)
159 ? rOldAttrs
.Get( nWhich
)
160 : rOldAttrs
.GetPool()->GetDefaultItem( nWhich
);
162 const SfxPoolItem
& rNewItem
= ( SfxItemState::SET
== eNewState
)
163 ? rNewAttrs
.Get( nWhich
)
164 : rNewAttrs
.GetPool()->GetDefaultItem( nWhich
);
166 bInvalidate
= rNewItem
!= rOldItem
;
172 sal_uLong
ScGlobal::GetStandardFormat( SvNumberFormatter
& rFormatter
,
173 sal_uLong nFormat
, short nType
)
175 const SvNumberformat
* pFormat
= rFormatter
.GetEntry( nFormat
);
177 return rFormatter
.GetStandardFormat( nFormat
, nType
, pFormat
->GetLanguage() );
178 return rFormatter
.GetStandardFormat( nType
, eLnge
);
181 sal_uInt16
ScGlobal::GetStandardRowHeight()
183 return nStdRowHeight
;
186 SvNumberFormatter
* ScGlobal::GetEnglishFormatter()
188 if ( !pEnglishFormatter
)
190 pEnglishFormatter
= new SvNumberFormatter(
191 ::comphelper::getProcessComponentContext(), LANGUAGE_ENGLISH_US
);
192 pEnglishFormatter
->SetEvalDateFormat( NF_EVALDATEFORMAT_INTL_FORMAT
);
194 return pEnglishFormatter
;
197 bool ScGlobal::CheckWidthInvalidate( bool& bNumFormatChanged
,
198 const SfxItemSet
& rNewAttrs
,
199 const SfxItemSet
& rOldAttrs
)
201 // Check whether attribute changes in rNewAttrs compared to rOldAttrs render
202 // the text width at a cell invalid
204 HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_VALUE_FORMAT
);
205 return ( bNumFormatChanged
206 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_LANGUAGE_FORMAT
)
207 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT
)
208 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CJK_FONT
)
209 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CTL_FONT
)
210 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_HEIGHT
)
211 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CJK_FONT_HEIGHT
)
212 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CTL_FONT_HEIGHT
)
213 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_WEIGHT
)
214 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CJK_FONT_WEIGHT
)
215 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CTL_FONT_WEIGHT
)
216 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_POSTURE
)
217 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CJK_FONT_POSTURE
)
218 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CTL_FONT_POSTURE
)
219 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_UNDERLINE
)
220 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_OVERLINE
)
221 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_CROSSEDOUT
)
222 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_CONTOUR
)
223 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_SHADOWED
)
224 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_STACKED
)
225 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_ROTATE_VALUE
)
226 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_ROTATE_MODE
)
227 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_LINEBREAK
)
228 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_MARGIN
)
232 const SvxSearchItem
& ScGlobal::GetSearchItem()
236 pSearchItem
= new SvxSearchItem( SID_SEARCH_ITEM
);
237 pSearchItem
->SetAppFlag( SvxSearchApp::CALC
);
242 void ScGlobal::SetSearchItem( const SvxSearchItem
& rNew
)
244 // FIXME: An assignement operator would be nice here
246 pSearchItem
= static_cast<SvxSearchItem
*>(rNew
.Clone());
248 pSearchItem
->SetWhich( SID_SEARCH_ITEM
);
249 pSearchItem
->SetAppFlag( SvxSearchApp::CALC
);
252 void ScGlobal::ClearAutoFormat()
254 if (pAutoFormat
!=NULL
)
261 ScAutoFormat
* ScGlobal::GetAutoFormat()
266 ScAutoFormat
* ScGlobal::GetOrCreateAutoFormat()
270 pAutoFormat
= new ScAutoFormat
;
277 FuncCollection
* ScGlobal::GetFuncCollection()
279 if (!pFuncCollection
)
280 pFuncCollection
= new FuncCollection();
281 return pFuncCollection
;
284 ScUnoAddInCollection
* ScGlobal::GetAddInCollection()
286 if (!pAddInCollection
)
287 pAddInCollection
= new ScUnoAddInCollection();
288 return pAddInCollection
;
291 ScUserList
* ScGlobal::GetUserList()
293 // Hack: Load Cfg item at the App
294 global_InitAppOptions();
297 pUserList
= new ScUserList();
301 void ScGlobal::SetUserList( const ScUserList
* pNewList
)
306 pUserList
= new ScUserList( *pNewList
);
308 *pUserList
= *pNewList
;
317 const OUString
& ScGlobal::GetRscString( sal_uInt16 nIndex
)
319 assert( nIndex
< SC_GLOBSTR_STR_COUNT
);
320 if( !ppRscString
[ nIndex
] )
323 // Map former globstr.src strings moved to compiler.src
338 case STR_NO_NAME_REF
:
351 ppRscString
[ nIndex
] = new OUString( ScCompiler::GetNativeSymbol( eOp
));
353 ppRscString
[ nIndex
] = new OUString( SC_STRLOAD( RID_GLOBSTR
, nIndex
));
355 return *ppRscString
[ nIndex
];
358 OUString
ScGlobal::GetErrorString(sal_uInt16 nErrNumber
)
363 case NOTAVAILABLE
: nErrNumber
= STR_NV_STR
; break;
364 case errNoRef
: nErrNumber
= STR_NO_REF_TABLE
; break;
365 case errNoName
: nErrNumber
= STR_NO_NAME_REF
; break;
366 case errNoAddin
: nErrNumber
= STR_NO_ADDIN
; break;
367 case errNoMacro
: nErrNumber
= STR_NO_MACRO
; break;
369 case errNoValue
: nErrNumber
= STR_NO_VALUE
; break;
370 case errNoCode
: nErrNumber
= STR_NULL_ERROR
; break;
371 case errDivisionByZero
: nErrNumber
= STR_DIV_ZERO
; break;
372 case errIllegalFPOperation
: nErrNumber
= STR_NUM_ERROR
; break;
374 default : sResStr
= GetRscString(STR_ERROR_STR
) + OUString::number( nErrNumber
);
379 sResStr
= GetRscString( nErrNumber
);
383 OUString
ScGlobal::GetLongErrorString(sal_uInt16 nErrNumber
)
390 case errIllegalArgument
:
391 nErrNumber
= STR_LONG_ERR_ILL_ARG
;
397 case errIllegalFPOperation
:
398 nErrNumber
= STR_LONG_ERR_ILL_FPO
;
401 nErrNumber
= STR_LONG_ERR_ILL_CHAR
;
403 case errIllegalParameter
:
404 nErrNumber
= STR_LONG_ERR_ILL_PAR
;
407 nErrNumber
= STR_LONG_ERR_ILL_SEP
;
410 case errPairExpected
:
411 nErrNumber
= STR_LONG_ERR_PAIR
;
413 case errOperatorExpected
:
414 nErrNumber
= STR_LONG_ERR_OP_EXP
;
416 case errVariableExpected
:
417 case errParameterExpected
:
418 nErrNumber
= STR_LONG_ERR_VAR_EXP
;
420 case errCodeOverflow
:
421 nErrNumber
= STR_LONG_ERR_CODE_OVF
;
423 case errStringOverflow
:
424 nErrNumber
= STR_LONG_ERR_STR_OVF
;
426 case errStackOverflow
:
427 case errInterpOverflow
:
428 nErrNumber
= STR_LONG_ERR_STACK_OVF
;
431 case errUnknownState
:
432 case errUnknownVariable
:
433 case errUnknownOpCode
:
434 case errUnknownStackVariable
:
435 case errUnknownToken
:
438 nErrNumber
= STR_LONG_ERR_SYNTAX
;
440 case errCircularReference
:
441 nErrNumber
= STR_LONG_ERR_CIRC_REF
;
443 case errNoConvergence
:
444 nErrNumber
= STR_LONG_ERR_NO_CONV
;
447 nErrNumber
= STR_LONG_ERR_NO_REF
;
450 nErrNumber
= STR_LONG_ERR_NO_NAME
;
453 nErrNumber
= STR_LONG_ERR_NO_ADDIN
;
456 nErrNumber
= STR_LONG_ERR_NO_MACRO
;
458 case errDivisionByZero
:
459 nErrNumber
= STR_LONG_ERR_DIV_ZERO
;
462 nErrNumber
= STR_ERR_LONG_NESTED_ARRAY
;
465 nErrNumber
= STR_LONG_ERR_NO_VALUE
;
468 nErrNumber
= STR_LONG_ERR_NV
;
471 nErrNumber
= STR_ERROR_STR
;
474 OUString
aRes( GetRscString( nErrNumber
) );
478 SvxBrushItem
* ScGlobal::GetButtonBrushItem()
480 pButtonBrushItem
->SetColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
481 return pButtonBrushItem
;
484 const OUString
& ScGlobal::GetEmptyOUString()
486 return *pEmptyOUString
;
489 ImageList
* ScGlobal::GetOutlineSymbols()
491 ImageList
*& rpImageList
= pOutlineBitmaps
;
493 rpImageList
= new ImageList( ScResId( RID_OUTLINEBITMAPS
) );
497 void ScGlobal::Init()
499 pEmptyOUString
= new OUString
;
501 // The default language for number formats (ScGlobal::eLnge) must
502 // always be LANGUAGE_SYSTEM
503 // FIXME: So remove this variable?
504 eLnge
= LANGUAGE_SYSTEM
;
506 // FIXME: If the sort-order etc. should depend the installed Office version
507 // use Application::GetSettings().GetUILanguage() here
508 pSysLocale
= new SvtSysLocale
;
509 pCharClass
= pSysLocale
->GetCharClassPtr();
510 pLocaleData
= pSysLocale
->GetLocaleDataPtr();
512 ppRscString
= new OUString
*[ SC_GLOBSTR_STR_COUNT
];
513 for( sal_uInt16 nC
= 0 ; nC
< SC_GLOBSTR_STR_COUNT
; nC
++ ) ppRscString
[ nC
] = NULL
;
515 pEmptyBrushItem
= new SvxBrushItem( Color( COL_TRANSPARENT
), ATTR_BACKGROUND
);
516 pButtonBrushItem
= new SvxBrushItem( Color(), ATTR_BACKGROUND
);
517 pEmbeddedBrushItem
= new SvxBrushItem( Color( COL_LIGHTCYAN
), ATTR_BACKGROUND
);
518 pProtectedBrushItem
= new SvxBrushItem( Color( COL_LIGHTGRAY
), ATTR_BACKGROUND
);
521 //ScCompiler::InitSymbolsNative();
522 // ScParameterClassification _after_ Compiler, needs function resources if
523 // arguments are to be merged in, which in turn need strings of function
524 // names from the compiler.
525 ScParameterClassification::Init();
529 pStrClipDocName
= new OUString( ScResId( SCSTR_NONAME
) );
530 *pStrClipDocName
+= "1";
532 // ScDocumentPool::InitVersionMaps() has been called earlier already
535 void ScGlobal::UpdatePPT( OutputDevice
* pDev
)
537 sal_uInt16 nCurrentZoom
= Application::GetSettings().GetStyleSettings().GetScreenZoom();
538 if ( nCurrentZoom
!= nPPTZoom
)
540 // Screen PPT values must be updated when ScreenZoom has changed.
541 // If called from Window::DataChanged, the window is passed as pDev,
542 // to make sure LogicToPixel uses a device which already uses the new zoom.
543 // For the initial settings, NULL is passed and GetDefaultDevice used.
546 pDev
= Application::GetDefaultDevice();
547 Point aPix1000
= pDev
->LogicToPixel( Point(1000,1000), MAP_TWIP
);
548 nScreenPPTX
= aPix1000
.X() / 1000.0;
549 nScreenPPTY
= aPix1000
.Y() / 1000.0;
550 nPPTZoom
= nCurrentZoom
;
554 const OUString
& ScGlobal::GetClipDocName()
556 return *pStrClipDocName
;
559 void ScGlobal::SetClipDocName( const OUString
& rNew
)
561 *pStrClipDocName
= rNew
;
564 void ScGlobal::InitTextHeight(SfxItemPool
* pPool
)
568 OSL_FAIL("ScGlobal::InitTextHeight: No Pool");
572 const ScPatternAttr
* pPattern
= static_cast<const ScPatternAttr
*>(&pPool
->GetDefaultItem(ATTR_PATTERN
));
575 OSL_FAIL("ScGlobal::InitTextHeight: No default pattern");
579 OutputDevice
* pDefaultDev
= Application::GetDefaultDevice();
580 ScopedVclPtrInstance
< VirtualDevice
> pVirtWindow( *pDefaultDev
);
581 pVirtWindow
->SetMapMode(MAP_PIXEL
);
583 pPattern
->GetFont(aDefFont
, SC_AUTOCOL_BLACK
, pVirtWindow
); // Font color doesn't matter here
584 pVirtWindow
->SetFont(aDefFont
);
585 sal_uInt16 nTest
= static_cast<sal_uInt16
>(
586 pVirtWindow
->PixelToLogic(Size(0, pVirtWindow
->GetTextHeight()), MAP_TWIP
).Height());
588 if (nTest
> nDefFontHeight
)
589 nDefFontHeight
= nTest
;
591 const SvxMarginItem
* pMargin
= static_cast<const SvxMarginItem
*>(&pPattern
->GetItem(ATTR_MARGIN
));
593 nTest
= static_cast<sal_uInt16
>(
594 nDefFontHeight
+ pMargin
->GetTopMargin() + pMargin
->GetBottomMargin() - STD_ROWHEIGHT_DIFF
);
596 if (nTest
> nStdRowHeight
)
597 nStdRowHeight
= nTest
;
600 void ScGlobal::Clear()
602 // Destroy asyncs _before_ ExitExternalFunc!
603 for( ScAddInAsyncs::iterator it
= theAddInAsyncTbl
.begin(); it
!= theAddInAsyncTbl
.end(); ++it
)
607 theAddInAsyncTbl
.clear();
609 DELETEZ(pAutoFormat
);
610 DELETEZ(pSearchItem
);
611 DELETEZ(pFuncCollection
);
612 DELETEZ(pAddInCollection
);
615 for( sal_uInt16 nC
= 0 ; nC
< SC_GLOBSTR_STR_COUNT
; nC
++ )
616 if( ppRscString
) delete ppRscString
[ nC
];
617 delete[] ppRscString
;
620 DELETEZ(pStarCalcFunctionList
); // Destroy before ResMgr!
621 DELETEZ(pStarCalcFunctionMgr
);
622 ScParameterClassification::Exit();
623 ScCompiler::DeInit();
624 ScInterpreter::GlobalExit(); // Delete static Stack
626 DELETEZ(pEmptyBrushItem
);
627 DELETEZ(pButtonBrushItem
);
628 DELETEZ(pEmbeddedBrushItem
);
629 DELETEZ(pProtectedBrushItem
);
630 DELETEZ(pOutlineBitmaps
);
631 DELETEZ(pEnglishFormatter
);
632 DELETEZ(pCaseTransliteration
);
633 DELETEZ(pTransliteration
);
634 DELETEZ(pCaseCollator
);
637 // Do NOT delete pCharClass since it is a pointer to the single SvtSysLocale instance !
639 // Do NOT delete pLocaleData since it is a pointer to the single SvtSysLocale instance !
643 DELETEZ(pScIntlWrapper
);
644 DELETEZ(pStrClipDocName
);
646 DELETEZ(pUnitConverter
);
647 DELETEZ(pFieldEditEngine
);
649 ScDocumentPool::DeleteVersionMaps();
651 DELETEZ(pEmptyOUString
);
654 rtl_TextEncoding
ScGlobal::GetCharsetValue( const OUString
& rCharSet
)
656 // new TextEncoding values
657 if ( CharClass::isAsciiNumeric( rCharSet
) )
659 sal_Int32 nVal
= rCharSet
.toInt32();
660 if ( !nVal
|| nVal
== RTL_TEXTENCODING_DONTKNOW
)
661 return osl_getThreadTextEncoding();
662 return (rtl_TextEncoding
) nVal
;
664 // old CharSet values for compatibility
665 else if (rCharSet
.equalsIgnoreAsciiCase("ANSI") ) return RTL_TEXTENCODING_MS_1252
;
666 else if (rCharSet
.equalsIgnoreAsciiCase("MAC") ) return RTL_TEXTENCODING_APPLE_ROMAN
;
667 else if (rCharSet
.equalsIgnoreAsciiCase("IBMPC") ) return RTL_TEXTENCODING_IBM_850
;
668 else if (rCharSet
.equalsIgnoreAsciiCase("IBMPC_437")) return RTL_TEXTENCODING_IBM_437
;
669 else if (rCharSet
.equalsIgnoreAsciiCase("IBMPC_850")) return RTL_TEXTENCODING_IBM_850
;
670 else if (rCharSet
.equalsIgnoreAsciiCase("IBMPC_860")) return RTL_TEXTENCODING_IBM_860
;
671 else if (rCharSet
.equalsIgnoreAsciiCase("IBMPC_861")) return RTL_TEXTENCODING_IBM_861
;
672 else if (rCharSet
.equalsIgnoreAsciiCase("IBMPC_863")) return RTL_TEXTENCODING_IBM_863
;
673 else if (rCharSet
.equalsIgnoreAsciiCase("IBMPC_865")) return RTL_TEXTENCODING_IBM_865
;
674 else return osl_getThreadTextEncoding();
677 OUString
ScGlobal::GetCharsetString( rtl_TextEncoding eVal
)
679 const sal_Char
* pChar
;
682 // old CharSet strings for compatibility
683 case RTL_TEXTENCODING_MS_1252
: pChar
= "ANSI"; break;
684 case RTL_TEXTENCODING_APPLE_ROMAN
: pChar
= "MAC"; break;
685 // IBMPC == IBMPC_850
686 case RTL_TEXTENCODING_IBM_437
: pChar
= "IBMPC_437"; break;
687 case RTL_TEXTENCODING_IBM_850
: pChar
= "IBMPC_850"; break;
688 case RTL_TEXTENCODING_IBM_860
: pChar
= "IBMPC_860"; break;
689 case RTL_TEXTENCODING_IBM_861
: pChar
= "IBMPC_861"; break;
690 case RTL_TEXTENCODING_IBM_863
: pChar
= "IBMPC_863"; break;
691 case RTL_TEXTENCODING_IBM_865
: pChar
= "IBMPC_865"; break;
692 case RTL_TEXTENCODING_DONTKNOW
: pChar
= "SYSTEM"; break;
693 // new string of TextEncoding value
695 return OUString::number( eVal
);
697 return OUString::createFromAscii(pChar
);
700 bool ScGlobal::HasStarCalcFunctionList()
702 return ( pStarCalcFunctionList
!= NULL
);
705 ScFunctionList
* ScGlobal::GetStarCalcFunctionList()
707 if ( !pStarCalcFunctionList
)
708 pStarCalcFunctionList
= new ScFunctionList
;
710 return pStarCalcFunctionList
;
713 ScFunctionMgr
* ScGlobal::GetStarCalcFunctionMgr()
715 if ( !pStarCalcFunctionMgr
)
716 pStarCalcFunctionMgr
= new ScFunctionMgr
;
718 return pStarCalcFunctionMgr
;
721 void ScGlobal::ResetFunctionList()
723 // FunctionMgr has pointers into FunctionList, must also be updated
724 DELETEZ( pStarCalcFunctionMgr
);
725 DELETEZ( pStarCalcFunctionList
);
728 ScUnitConverter
* ScGlobal::GetUnitConverter()
730 if ( !pUnitConverter
)
731 pUnitConverter
= new ScUnitConverter
;
733 return pUnitConverter
;
736 const sal_Unicode
* ScGlobal::UnicodeStrChr( const sal_Unicode
* pStr
,
750 OUString
ScGlobal::addToken(const OUString
& rTokenList
, const OUString
& rToken
,
751 sal_Unicode cSep
, sal_Int32 nSepCount
, bool bForceSep
)
753 OUStringBuffer
aBuf(rTokenList
);
754 if( bForceSep
|| (!rToken
.isEmpty() && !rTokenList
.isEmpty()) )
755 comphelper::string::padToLength(aBuf
, aBuf
.getLength() + nSepCount
, cSep
);
757 return aBuf
.makeStringAndClear();
760 bool ScGlobal::IsQuoted( const OUString
& rString
, sal_Unicode cQuote
)
762 return (rString
.getLength() >= 2) && (rString
[0] == cQuote
) && (rString
[ rString
.getLength() - 1 ] == cQuote
);
765 void ScGlobal::AddQuotes( OUString
& rString
, sal_Unicode cQuote
, bool bEscapeEmbedded
)
770 pQ
[0] = pQ
[1] = cQuote
;
772 OUString
aQuotes( pQ
);
773 rString
= rString
.replaceAll( OUString(cQuote
), aQuotes
);
775 rString
= OUString( cQuote
) + rString
+ OUString( cQuote
);
778 void ScGlobal::EraseQuotes( OUString
& rString
, sal_Unicode cQuote
, bool bUnescapeEmbedded
)
780 if ( IsQuoted( rString
, cQuote
) )
782 rString
= rString
.copy( 1, rString
.getLength() - 2 );
783 if (bUnescapeEmbedded
)
786 pQ
[0] = pQ
[1] = cQuote
;
788 OUString
aQuotes( pQ
);
789 rString
= rString
.replaceAll( aQuotes
, OUString(cQuote
));
794 sal_Int32
ScGlobal::FindUnquoted( const OUString
& rString
, sal_Unicode cChar
)
796 const sal_Unicode cQuote
= '\'';
797 const sal_Unicode
* const pStart
= rString
.getStr();
798 const sal_Unicode
* const pStop
= pStart
+ rString
.getLength();
799 const sal_Unicode
* p
= pStart
;
800 bool bQuoted
= false;
803 if (*p
== cChar
&& !bQuoted
)
804 return sal::static_int_cast
< sal_Int32
>( p
- pStart
);
805 else if (*p
== cQuote
)
809 else if (p
< pStop
-1 && *(p
+1) == cQuote
)
819 const sal_Unicode
* ScGlobal::FindUnquoted( const sal_Unicode
* pString
, sal_Unicode cChar
, sal_Unicode cQuote
)
821 const sal_Unicode
* p
= pString
;
822 bool bQuoted
= false;
825 if (*p
== cChar
&& !bQuoted
)
827 else if (*p
== cQuote
)
831 else if (*(p
+1) == cQuote
)
841 bool ScGlobal::EETextObjEqual( const EditTextObject
* pObj1
,
842 const EditTextObject
* pObj2
)
844 if ( pObj1
== pObj2
) // Both empty or the same object
847 if ( pObj1
&& pObj2
)
849 // First test for equal text content
850 sal_Int32 nParCount
= pObj1
->GetParagraphCount();
851 if ( nParCount
!= pObj2
->GetParagraphCount() )
853 for (sal_Int32 nPar
=0; nPar
<nParCount
; nPar
++)
854 if ( pObj1
->GetText(nPar
) != pObj2
->GetText(nPar
) )
857 SvMemoryStream aStream1
;
858 SvMemoryStream aStream2
;
859 pObj1
->Store( aStream1
);
860 pObj2
->Store( aStream2
);
861 sal_uLong nSize
= aStream1
.Tell();
862 if ( aStream2
.Tell() == nSize
)
863 if ( !memcmp( aStream1
.GetData(), aStream2
.GetData(), (sal_uInt16
) nSize
) )
870 void ScGlobal::OpenURL(const OUString
& rURL
, const OUString
& rTarget
, const SdrModel
* pDrawLayer
)
872 if (pDrawLayer
&& pDrawLayer
->isTiledRendering())
874 pDrawLayer
->libreOfficeKitCallback(LOK_CALLBACK_HYPERLINK_CLICKED
, rURL
.toUtf8().getStr());
878 // OpenURL is always called in the GridWindow by mouse clicks in some way or another.
879 // That's why pScActiveViewShell and nScClickMouseModifier are correct.
880 // SvtSecurityOptions to access Libreoffice global security parameters
881 SvtSecurityOptions aSecOpt
;
882 bool bCtrlClickHappened
= (nScClickMouseModifier
& KEY_MOD1
);
883 bool bCtrlClickSecOption
= aSecOpt
.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK
);
884 if( bCtrlClickHappened
&& !( bCtrlClickSecOption
) )
886 // return since ctrl+click happened when the
887 // ctrl+click security option was disabled, link should not open
890 else if( !( bCtrlClickHappened
) && bCtrlClickSecOption
)
892 // ctrl+click did not happen; only click happened maybe with some
893 // other key combo. and security option is set, so return
896 SfxStringItem
aUrl( SID_FILE_NAME
, rURL
);
897 SfxStringItem
aTarget( SID_TARGETNAME
, rTarget
);
898 aTarget
.SetValue(OUString("_blank"));
899 SfxViewFrame
* pFrame
= NULL
;
901 if ( pScActiveViewShell
)
903 pFrame
= pScActiveViewShell
->GetViewFrame();
904 SfxMedium
* pMed
= pFrame
->GetObjectShell()->GetMedium();
906 aReferName
= pMed
->GetName();
909 SfxFrameItem
aFrm( SID_DOCFRAME
, pFrame
);
910 SfxStringItem
aReferer( SID_REFERER
, aReferName
);
912 SfxBoolItem
aNewView( SID_OPEN_NEW_VIEW
, false );
913 SfxBoolItem
aBrowsing( SID_BROWSE
, true );
915 // No SID_SILENT anymore
916 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
918 pViewFrm
->GetDispatcher()->Execute( SID_OPENDOC
,
919 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
922 &aNewView
, &aBrowsing
,
926 bool ScGlobal::IsSystemRTL()
928 return MsLangId::isRightToLeft( Application::GetSettings().GetLanguageTag().getLanguageType() );
931 SvtScriptType
ScGlobal::GetDefaultScriptType()
933 // Used when text contains only WEAK characters.
934 // Script type of office language is used then (same as GetEditDefaultLanguage,
935 // to get consistent behavior of text in simple cells and EditEngine,
936 // also same as GetAppLanguage() in Writer)
937 return SvtLanguageOptions::GetScriptTypeOfLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
940 LanguageType
ScGlobal::GetEditDefaultLanguage()
942 // Used for EditEngine::SetDefaultLanguage
943 return Application::GetSettings().GetLanguageTag().getLanguageType();
946 sal_uInt16
ScGlobal::GetScriptedWhichID( SvtScriptType nScriptType
, sal_uInt16 nWhich
)
948 switch ( nScriptType
)
950 case SvtScriptType::LATIN
:
951 case SvtScriptType::ASIAN
:
952 case SvtScriptType::COMPLEX
:
953 break; // take exact matches
954 default: // prefer one, first COMPLEX, then ASIAN
955 if ( nScriptType
& SvtScriptType::COMPLEX
)
956 nScriptType
= SvtScriptType::COMPLEX
;
957 else if ( nScriptType
& SvtScriptType::ASIAN
)
958 nScriptType
= SvtScriptType::ASIAN
;
960 switch ( nScriptType
)
962 case SvtScriptType::COMPLEX
:
968 nWhich
= ATTR_CTL_FONT
;
970 case ATTR_FONT_HEIGHT
:
971 case ATTR_CJK_FONT_HEIGHT
:
972 nWhich
= ATTR_CTL_FONT_HEIGHT
;
974 case ATTR_FONT_WEIGHT
:
975 case ATTR_CJK_FONT_WEIGHT
:
976 nWhich
= ATTR_CTL_FONT_WEIGHT
;
978 case ATTR_FONT_POSTURE
:
979 case ATTR_CJK_FONT_POSTURE
:
980 nWhich
= ATTR_CTL_FONT_POSTURE
;
985 case SvtScriptType::ASIAN
:
991 nWhich
= ATTR_CJK_FONT
;
993 case ATTR_FONT_HEIGHT
:
994 case ATTR_CTL_FONT_HEIGHT
:
995 nWhich
= ATTR_CJK_FONT_HEIGHT
;
997 case ATTR_FONT_WEIGHT
:
998 case ATTR_CTL_FONT_WEIGHT
:
999 nWhich
= ATTR_CJK_FONT_WEIGHT
;
1001 case ATTR_FONT_POSTURE
:
1002 case ATTR_CTL_FONT_POSTURE
:
1003 nWhich
= ATTR_CJK_FONT_POSTURE
;
1016 case ATTR_CTL_FONT_HEIGHT
:
1017 case ATTR_CJK_FONT_HEIGHT
:
1018 nWhich
= ATTR_FONT_HEIGHT
;
1020 case ATTR_CTL_FONT_WEIGHT
:
1021 case ATTR_CJK_FONT_WEIGHT
:
1022 nWhich
= ATTR_FONT_WEIGHT
;
1024 case ATTR_CTL_FONT_POSTURE
:
1025 case ATTR_CJK_FONT_POSTURE
:
1026 nWhich
= ATTR_FONT_POSTURE
;
1034 void ScGlobal::AddLanguage( SfxItemSet
& rSet
, SvNumberFormatter
& rFormatter
)
1036 OSL_ENSURE( rSet
.GetItemState( ATTR_LANGUAGE_FORMAT
, false ) == SfxItemState::DEFAULT
,
1037 "ScGlobal::AddLanguage - language already added");
1039 const SfxPoolItem
* pHardItem
;
1040 if ( rSet
.GetItemState( ATTR_VALUE_FORMAT
, false, &pHardItem
) == SfxItemState::SET
)
1042 const SvNumberformat
* pHardFormat
= rFormatter
.GetEntry(
1043 static_cast<const SfxUInt32Item
*>(pHardItem
)->GetValue() );
1045 sal_uLong nParentFmt
= 0; // Pool default
1046 const SfxItemSet
* pParent
= rSet
.GetParent();
1048 nParentFmt
= static_cast<const SfxUInt32Item
&>(pParent
->Get( ATTR_VALUE_FORMAT
)).GetValue();
1049 const SvNumberformat
* pParFormat
= rFormatter
.GetEntry( nParentFmt
);
1051 if ( pHardFormat
&& pParFormat
&&
1052 (pHardFormat
->GetLanguage() != pParFormat
->GetLanguage()) )
1053 rSet
.Put( SvxLanguageItem( pHardFormat
->GetLanguage(), ATTR_LANGUAGE_FORMAT
) );
1057 utl::TransliterationWrapper
* ScGlobal::GetpTransliteration()
1059 if ( !pTransliteration
)
1061 const LanguageType eOfficeLanguage
= Application::GetSettings().GetLanguageTag().getLanguageType();
1062 pTransliteration
= new ::utl::TransliterationWrapper(
1063 ::comphelper::getProcessComponentContext(), SC_TRANSLITERATION_IGNORECASE
);
1064 pTransliteration
->loadModuleIfNeeded( eOfficeLanguage
);
1068 "ScGlobal::GetpTransliteration() called before ScGlobal::Init()");
1069 return pTransliteration
;
1072 const LocaleDataWrapper
* ScGlobal::GetpLocaleData()
1076 "ScGlobal::GetpLocaleData() called before ScGlobal::Init()");
1079 CalendarWrapper
* ScGlobal::GetCalendar()
1083 pCalendar
= new CalendarWrapper( ::comphelper::getProcessComponentContext() );
1084 pCalendar
->loadDefaultCalendar( *GetLocale() );
1088 CollatorWrapper
* ScGlobal::GetCollator()
1092 pCollator
= new CollatorWrapper( ::comphelper::getProcessComponentContext() );
1093 pCollator
->loadDefaultCollator( *GetLocale(), SC_COLLATOR_IGNORES
);
1097 CollatorWrapper
* ScGlobal::GetCaseCollator()
1099 if ( !pCaseCollator
)
1101 pCaseCollator
= new CollatorWrapper( ::comphelper::getProcessComponentContext() );
1102 pCaseCollator
->loadDefaultCollator( *GetLocale(), 0 );
1104 return pCaseCollator
;
1106 ::utl::TransliterationWrapper
* ScGlobal::GetCaseTransliteration()
1108 if ( !pCaseTransliteration
)
1110 const LanguageType eOfficeLanguage
= Application::GetSettings().GetLanguageTag().getLanguageType();
1111 pCaseTransliteration
= new ::utl::TransliterationWrapper(::comphelper::getProcessComponentContext(), SC_TRANSLITERATION_CASESENSE
);
1112 pCaseTransliteration
->loadModuleIfNeeded( eOfficeLanguage
);
1114 return pCaseTransliteration
;
1116 IntlWrapper
* ScGlobal::GetScIntlWrapper()
1118 if ( !pScIntlWrapper
)
1120 pScIntlWrapper
= new IntlWrapper( LanguageTag( *GetLocale()) );
1122 return pScIntlWrapper
;
1124 ::com::sun::star::lang::Locale
* ScGlobal::GetLocale()
1128 pLocale
= new ::com::sun::star::lang::Locale( Application::GetSettings().GetLanguageTag().getLocale());
1133 ScFieldEditEngine
& ScGlobal::GetStaticFieldEditEngine()
1135 if (!pFieldEditEngine
)
1137 // Creating a ScFieldEditEngine with pDocument=NULL leads to document
1138 // specific fields not being resolvable! See
1139 // ScFieldEditEngine::CalcFieldValue(). pEnginePool=NULL lets
1140 // EditEngine internally create and delete a default pool.
1141 pFieldEditEngine
= new ScFieldEditEngine( NULL
, NULL
);
1143 return *pFieldEditEngine
;
1146 OUString
ScGlobal::ReplaceOrAppend( const OUString
& rString
,
1147 const OUString
& rPlaceholder
, const OUString
& rReplacement
)
1149 if (rString
.isEmpty())
1150 return rReplacement
;
1151 sal_Int32 nFound
= rString
.indexOf( rPlaceholder
);
1154 if (rString
[rString
.getLength()-1] == ' ')
1155 return rString
+ rReplacement
;
1156 return rString
+ " " + rReplacement
;
1158 return rString
.replaceFirst( rPlaceholder
, rReplacement
, &nFound
);
1161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */