Line data Source code
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 : #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>
43 : #include <stdlib.h>
44 : #include <time.h>
45 : #include <ctype.h>
46 : #include <numeric>
47 :
48 :
49 : #include <i18nlangtag/mslangid.hxx>
50 : #include <com/sun/star/lang/Locale.hpp>
51 : #include <comphelper/processfactory.hxx>
52 : #include <comphelper/string.hxx>
53 : #include <unotools/calendarwrapper.hxx>
54 : #include <unotools/collatorwrapper.hxx>
55 : #include <com/sun/star/i18n/CollatorOptions.hpp>
56 : #include <unotools/intlwrapper.hxx>
57 : #include <unotools/syslocale.hxx>
58 : #include <unotools/transliterationwrapper.hxx>
59 :
60 : #include "global.hxx"
61 : #include "scresid.hxx"
62 : #include "autoform.hxx"
63 : #include "document.hxx"
64 : #include "patattr.hxx"
65 : #include "addincol.hxx"
66 : #include "adiasync.hxx"
67 : #include "userlist.hxx"
68 : #include "interpre.hxx"
69 : #include "strload.hxx"
70 : #include "docpool.hxx"
71 : #include "unitconv.hxx"
72 : #include "compiler.hxx"
73 : #include "parclass.hxx"
74 : #include "funcdesc.hxx"
75 : #include "globstr.hrc"
76 : #include "scfuncs.hrc"
77 : #include "sc.hrc"
78 : #include "scmod.hxx"
79 : #include "appoptio.hxx"
80 : #include "random.hxx"
81 : #include "editutil.hxx"
82 :
83 :
84 : tools::SvRef<ScDocShell>* ScGlobal::pDrawClipDocShellRef = NULL;
85 : SvxSearchItem* ScGlobal::pSearchItem = NULL;
86 : ScAutoFormat* ScGlobal::pAutoFormat = NULL;
87 : FuncCollection* ScGlobal::pFuncCollection = NULL;
88 : ScUnoAddInCollection* ScGlobal::pAddInCollection = NULL;
89 : ScUserList* ScGlobal::pUserList = NULL;
90 : OUString** ScGlobal::ppRscString = NULL;
91 : LanguageType ScGlobal::eLnge = LANGUAGE_SYSTEM;
92 : ::com::sun::star::lang::Locale* ScGlobal::pLocale = NULL;
93 : SvtSysLocale* ScGlobal::pSysLocale = NULL;
94 : const CharClass* ScGlobal::pCharClass = NULL;
95 : const LocaleDataWrapper* ScGlobal::pLocaleData = NULL;
96 : CalendarWrapper* ScGlobal::pCalendar = NULL;
97 : CollatorWrapper* ScGlobal::pCollator = NULL;
98 : CollatorWrapper* ScGlobal::pCaseCollator = NULL;
99 : ::utl::TransliterationWrapper* ScGlobal::pTransliteration = NULL;
100 : ::utl::TransliterationWrapper* ScGlobal::pCaseTransliteration = NULL;
101 0 : ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XOrdinalSuffix> ScGlobal::xOrdinalSuffix = NULL;
102 : IntlWrapper* ScGlobal::pScIntlWrapper = NULL;
103 : sal_Unicode ScGlobal::cListDelimiter = ',';
104 : OUString* ScGlobal::pEmptyOUString = NULL;
105 : OUString* ScGlobal::pStrClipDocName = NULL;
106 :
107 : SvxBrushItem* ScGlobal::pEmptyBrushItem = NULL;
108 : SvxBrushItem* ScGlobal::pButtonBrushItem = NULL;
109 : SvxBrushItem* ScGlobal::pEmbeddedBrushItem = NULL;
110 : SvxBrushItem* ScGlobal::pProtectedBrushItem = NULL;
111 :
112 : ImageList* ScGlobal::pOutlineBitmaps = NULL;
113 :
114 : ScFunctionList* ScGlobal::pStarCalcFunctionList = NULL;
115 : ScFunctionMgr* ScGlobal::pStarCalcFunctionMgr = NULL;
116 :
117 : ScUnitConverter* ScGlobal::pUnitConverter = NULL;
118 : SvNumberFormatter* ScGlobal::pEnglishFormatter = NULL;
119 : ScFieldEditEngine* ScGlobal::pFieldEditEngine = NULL;
120 :
121 : double ScGlobal::nScreenPPTX = 96.0;
122 : double ScGlobal::nScreenPPTY = 96.0;
123 :
124 : sal_uInt16 ScGlobal::nDefFontHeight = 225;
125 : sal_uInt16 ScGlobal::nStdRowHeight = 256;
126 :
127 : long ScGlobal::nLastRowHeightExtra = 0;
128 : long ScGlobal::nLastColWidthExtra = STD_EXTRA_WIDTH;
129 :
130 : static sal_uInt16 nPPTZoom = 0; // ScreenZoom used to determine nScreenPPTX/Y
131 :
132 :
133 : class SfxViewShell;
134 : SfxViewShell* pScActiveViewShell = NULL; //! als Member !!!!!
135 : sal_uInt16 nScClickMouseModifier = 0; //! dito
136 : sal_uInt16 nScFillModeMouseModifier = 0; //! dito
137 :
138 : // Hack: ScGlobal::GetUserList() muss InitAppOptions in der UI aufrufen,
139 : // damit UserList aus Cfg geladen wird
140 :
141 : void global_InitAppOptions();
142 :
143 : // statische Funktionen
144 :
145 0 : bool ScGlobal::HasAttrChanged( const SfxItemSet& rNewAttrs,
146 : const SfxItemSet& rOldAttrs,
147 : const sal_uInt16 nWhich )
148 : {
149 0 : bool bInvalidate = false;
150 0 : const SfxItemState eNewState = rNewAttrs.GetItemState( nWhich );
151 0 : const SfxItemState eOldState = rOldAttrs.GetItemState( nWhich );
152 :
153 0 : if ( eNewState == eOldState )
154 : {
155 : // beide Items gesetzt
156 : // PoolItems, d.h. Pointer-Vergleich zulaessig
157 0 : if ( SFX_ITEM_SET == eOldState )
158 0 : bInvalidate = (&rNewAttrs.Get( nWhich ) != &rOldAttrs.Get( nWhich ));
159 : }
160 : else
161 : {
162 : // ein Default-Item dabei
163 : // PoolItems, d.h. Item-Vergleich noetig
164 :
165 : const SfxPoolItem& rOldItem = ( SFX_ITEM_SET == eOldState )
166 0 : ? rOldAttrs.Get( nWhich )
167 0 : : rOldAttrs.GetPool()->GetDefaultItem( nWhich );
168 :
169 : const SfxPoolItem& rNewItem = ( SFX_ITEM_SET == eNewState )
170 0 : ? rNewAttrs.Get( nWhich )
171 0 : : rNewAttrs.GetPool()->GetDefaultItem( nWhich );
172 :
173 0 : bInvalidate = rNewItem != rOldItem;
174 : }
175 :
176 0 : return bInvalidate;
177 : }
178 :
179 0 : sal_uLong ScGlobal::GetStandardFormat( SvNumberFormatter& rFormatter,
180 : sal_uLong nFormat, short nType )
181 : {
182 0 : const SvNumberformat* pFormat = rFormatter.GetEntry( nFormat );
183 0 : if ( pFormat )
184 0 : return rFormatter.GetStandardFormat( nFormat, nType, pFormat->GetLanguage() );
185 0 : return rFormatter.GetStandardFormat( nType, eLnge );
186 : }
187 :
188 0 : sal_uInt16 ScGlobal::GetStandardRowHeight()
189 : {
190 0 : return nStdRowHeight;
191 : }
192 :
193 0 : SvNumberFormatter* ScGlobal::GetEnglishFormatter()
194 : {
195 0 : if ( !pEnglishFormatter )
196 : {
197 : pEnglishFormatter = new SvNumberFormatter(
198 0 : ::comphelper::getProcessComponentContext(), LANGUAGE_ENGLISH_US );
199 0 : pEnglishFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_INTL_FORMAT );
200 : }
201 0 : return pEnglishFormatter;
202 : }
203 :
204 :
205 0 : bool ScGlobal::CheckWidthInvalidate( bool& bNumFormatChanged,
206 : const SfxItemSet& rNewAttrs,
207 : const SfxItemSet& rOldAttrs )
208 : {
209 : // Ueberpruefen, ob Attributaenderungen in rNewAttrs gegnueber
210 : // rOldAttrs die Textbreite an einer Zelle ungueltig machen
211 :
212 : bNumFormatChanged =
213 0 : HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_VALUE_FORMAT );
214 : return ( bNumFormatChanged
215 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_LANGUAGE_FORMAT )
216 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT )
217 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT )
218 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT )
219 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_HEIGHT )
220 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_HEIGHT )
221 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_HEIGHT )
222 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_WEIGHT )
223 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_WEIGHT )
224 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_WEIGHT )
225 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_POSTURE )
226 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_POSTURE )
227 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_POSTURE )
228 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_UNDERLINE )
229 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_OVERLINE )
230 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_CROSSEDOUT )
231 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_CONTOUR )
232 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_SHADOWED )
233 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_STACKED )
234 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_ROTATE_VALUE )
235 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_ROTATE_MODE )
236 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_LINEBREAK )
237 0 : || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_MARGIN )
238 0 : );
239 : }
240 :
241 0 : const SvxSearchItem& ScGlobal::GetSearchItem()
242 : {
243 0 : if (!pSearchItem)
244 : {
245 0 : pSearchItem = new SvxSearchItem( SID_SEARCH_ITEM );
246 0 : pSearchItem->SetAppFlag( SVX_SEARCHAPP_CALC );
247 : }
248 0 : return *pSearchItem;
249 : }
250 :
251 0 : void ScGlobal::SetSearchItem( const SvxSearchItem& rNew )
252 : {
253 : // Hier waere ein Zuweisungsoperator ganz nett:
254 0 : delete pSearchItem;
255 0 : pSearchItem = (SvxSearchItem*)rNew.Clone();
256 :
257 0 : pSearchItem->SetWhich( SID_SEARCH_ITEM );
258 0 : pSearchItem->SetAppFlag( SVX_SEARCHAPP_CALC );
259 0 : }
260 :
261 0 : void ScGlobal::ClearAutoFormat()
262 : {
263 0 : if (pAutoFormat!=NULL)
264 : {
265 0 : delete pAutoFormat;
266 0 : pAutoFormat=NULL;
267 : }
268 0 : }
269 :
270 0 : ScAutoFormat* ScGlobal::GetAutoFormat()
271 : {
272 0 : return pAutoFormat;
273 : }
274 :
275 0 : ScAutoFormat* ScGlobal::GetOrCreateAutoFormat()
276 : {
277 0 : if ( !pAutoFormat )
278 : {
279 0 : pAutoFormat = new ScAutoFormat;
280 0 : pAutoFormat->Load();
281 : }
282 :
283 0 : return pAutoFormat;
284 : }
285 :
286 0 : FuncCollection* ScGlobal::GetFuncCollection()
287 : {
288 0 : if (!pFuncCollection)
289 0 : pFuncCollection = new FuncCollection();
290 0 : return pFuncCollection;
291 : }
292 :
293 0 : ScUnoAddInCollection* ScGlobal::GetAddInCollection()
294 : {
295 0 : if (!pAddInCollection)
296 0 : pAddInCollection = new ScUnoAddInCollection();
297 0 : return pAddInCollection;
298 : }
299 :
300 0 : ScUserList* ScGlobal::GetUserList()
301 : {
302 : // Hack: Cfg-Item an der App ggF. laden
303 :
304 0 : global_InitAppOptions();
305 :
306 0 : if (!pUserList)
307 0 : pUserList = new ScUserList();
308 0 : return pUserList;
309 : }
310 :
311 0 : void ScGlobal::SetUserList( const ScUserList* pNewList )
312 : {
313 0 : if ( pNewList )
314 : {
315 0 : if ( !pUserList )
316 0 : pUserList = new ScUserList( *pNewList );
317 : else
318 0 : *pUserList = *pNewList;
319 : }
320 : else
321 : {
322 0 : delete pUserList;
323 0 : pUserList = NULL;
324 : }
325 0 : }
326 :
327 0 : const OUString& ScGlobal::GetRscString( sal_uInt16 nIndex )
328 : {
329 : assert( nIndex < SC_GLOBSTR_STR_COUNT);
330 0 : if( !ppRscString[ nIndex ] )
331 : {
332 0 : OpCode eOp = ocNone;
333 : // Map former globstr.src strings moved to compiler.src
334 0 : switch (nIndex)
335 : {
336 : case STR_NULL_ERROR:
337 0 : eOp = ocErrNull;
338 0 : break;
339 : case STR_DIV_ZERO:
340 0 : eOp = ocErrDivZero;
341 0 : break;
342 : case STR_NO_VALUE:
343 0 : eOp = ocErrValue;
344 0 : break;
345 : case STR_NOREF_STR:
346 0 : eOp = ocErrRef;
347 0 : break;
348 : case STR_NO_NAME_REF:
349 0 : eOp = ocErrName;
350 0 : break;
351 : case STR_NUM_ERROR:
352 0 : eOp = ocErrNum;
353 0 : break;
354 : case STR_NV_STR:
355 0 : eOp = ocErrNA;
356 0 : break;
357 : default:
358 : ; // nothing
359 : }
360 0 : if (eOp != ocNone)
361 0 : ppRscString[ nIndex ] = new OUString( ScCompiler::GetNativeSymbol( eOp));
362 : else
363 0 : ppRscString[ nIndex ] = new OUString( SC_STRLOAD( RID_GLOBSTR, nIndex ));
364 : }
365 0 : return *ppRscString[ nIndex ];
366 : }
367 :
368 0 : OUString ScGlobal::GetErrorString(sal_uInt16 nErrNumber)
369 : {
370 0 : OUString sResStr;
371 0 : switch (nErrNumber)
372 : {
373 0 : case NOTAVAILABLE : nErrNumber = STR_NV_STR; break;
374 0 : case errNoRef : nErrNumber = STR_NO_REF_TABLE; break;
375 0 : case errNoName : nErrNumber = STR_NO_NAME_REF; break;
376 0 : case errNoAddin : nErrNumber = STR_NO_ADDIN; break;
377 0 : case errNoMacro : nErrNumber = STR_NO_MACRO; break;
378 : case errDoubleRef :
379 0 : case errNoValue : nErrNumber = STR_NO_VALUE; break;
380 0 : case errNoCode : nErrNumber = STR_NULL_ERROR; break;
381 0 : case errDivisionByZero : nErrNumber = STR_DIV_ZERO; break;
382 0 : case errIllegalFPOperation : nErrNumber = STR_NUM_ERROR; break;
383 :
384 0 : default : sResStr = GetRscString(STR_ERROR_STR) + OUString::number( nErrNumber );
385 0 : nErrNumber = 0;
386 0 : break;
387 : }
388 0 : if( nErrNumber )
389 0 : sResStr = GetRscString( nErrNumber );
390 0 : return sResStr;
391 : }
392 :
393 0 : OUString ScGlobal::GetLongErrorString(sal_uInt16 nErrNumber)
394 : {
395 0 : switch (nErrNumber)
396 : {
397 : case 0:
398 0 : break;
399 : case 1:
400 : case errIllegalArgument:
401 0 : nErrNumber = STR_LONG_ERR_ILL_ARG;
402 0 : break;
403 : case 2:
404 : case 3:
405 : case 4:
406 : case 5:
407 : case errIllegalFPOperation:
408 0 : nErrNumber = STR_LONG_ERR_ILL_FPO;
409 0 : break;
410 : case errIllegalChar:
411 0 : nErrNumber = STR_LONG_ERR_ILL_CHAR;
412 0 : break;
413 : case errIllegalParameter:
414 0 : nErrNumber = STR_LONG_ERR_ILL_PAR;
415 0 : break;
416 : case errSeparator:
417 0 : nErrNumber = STR_LONG_ERR_ILL_SEP;
418 0 : break;
419 : case errPair:
420 : case errPairExpected:
421 0 : nErrNumber = STR_LONG_ERR_PAIR;
422 0 : break;
423 : case errOperatorExpected:
424 0 : nErrNumber = STR_LONG_ERR_OP_EXP;
425 0 : break;
426 : case errVariableExpected:
427 : case errParameterExpected:
428 0 : nErrNumber = STR_LONG_ERR_VAR_EXP;
429 0 : break;
430 : case errCodeOverflow:
431 0 : nErrNumber = STR_LONG_ERR_CODE_OVF;
432 0 : break;
433 : case errStringOverflow:
434 0 : nErrNumber = STR_LONG_ERR_STR_OVF;
435 0 : break;
436 : case errStackOverflow:
437 : case errInterpOverflow:
438 0 : nErrNumber = STR_LONG_ERR_STACK_OVF;
439 0 : break;
440 : case errIllegalJump:
441 : case errUnknownState:
442 : case errUnknownVariable:
443 : case errUnknownOpCode:
444 : case errUnknownStackVariable:
445 : case errUnknownToken:
446 : case errNoCode:
447 : case errDoubleRef:
448 0 : nErrNumber = STR_LONG_ERR_SYNTAX;
449 0 : break;
450 : case errCircularReference:
451 0 : nErrNumber = STR_LONG_ERR_CIRC_REF;
452 0 : break;
453 : case errNoConvergence:
454 0 : nErrNumber = STR_LONG_ERR_NO_CONV;
455 0 : break;
456 : case errNoRef:
457 0 : nErrNumber = STR_LONG_ERR_NO_REF;
458 0 : break;
459 : case errNoName:
460 0 : nErrNumber = STR_LONG_ERR_NO_NAME;
461 0 : break;
462 : case errNoAddin:
463 0 : nErrNumber = STR_LONG_ERR_NO_ADDIN;
464 0 : break;
465 : case errNoMacro:
466 0 : nErrNumber = STR_LONG_ERR_NO_MACRO;
467 0 : break;
468 : case errDivisionByZero:
469 0 : nErrNumber = STR_LONG_ERR_DIV_ZERO;
470 0 : break;
471 : case errNestedArray:
472 0 : nErrNumber = STR_ERR_LONG_NESTED_ARRAY;
473 0 : break;
474 : case errNoValue:
475 0 : nErrNumber = STR_LONG_ERR_NO_VALUE;
476 0 : break;
477 : case NOTAVAILABLE:
478 0 : nErrNumber = STR_LONG_ERR_NV;
479 0 : break;
480 : default:
481 0 : nErrNumber = STR_ERROR_STR;
482 0 : break;
483 : }
484 0 : OUString aRes( GetRscString( nErrNumber ) );
485 0 : return aRes;
486 : }
487 :
488 0 : SvxBrushItem* ScGlobal::GetButtonBrushItem()
489 : {
490 0 : pButtonBrushItem->SetColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
491 0 : return pButtonBrushItem;
492 : }
493 :
494 0 : const OUString& ScGlobal::GetEmptyOUString()
495 : {
496 0 : return *pEmptyOUString;
497 : }
498 :
499 0 : ImageList* ScGlobal::GetOutlineSymbols()
500 : {
501 0 : ImageList*& rpImageList = pOutlineBitmaps;
502 0 : if( !rpImageList )
503 0 : rpImageList = new ImageList( ScResId( RID_OUTLINEBITMAPS ) );
504 0 : return rpImageList;
505 : }
506 :
507 0 : void ScGlobal::Init()
508 : {
509 0 : pEmptyOUString = new OUString;
510 :
511 : // Die Default-Sprache fuer Zahlenformate (ScGlobal::eLnge)
512 : // muss immer LANGUAGE_SYSTEM sein
513 : //! Dann kann auch die Variable raus
514 0 : eLnge = LANGUAGE_SYSTEM;
515 :
516 : //! Wenn Sortierung etc. von der Sprache der installierten Offfice-Version
517 : //! abhaengen sollen, hier "Application::GetSettings().GetUILanguage()"
518 0 : pSysLocale = new SvtSysLocale;
519 0 : pCharClass = pSysLocale->GetCharClassPtr();
520 0 : pLocaleData = pSysLocale->GetLocaleDataPtr();
521 :
522 0 : ppRscString = new OUString *[ SC_GLOBSTR_STR_COUNT ];
523 0 : for( sal_uInt16 nC = 0 ; nC < SC_GLOBSTR_STR_COUNT ; nC++ ) ppRscString[ nC ] = NULL;
524 :
525 0 : pEmptyBrushItem = new SvxBrushItem( Color( COL_TRANSPARENT ), ATTR_BACKGROUND );
526 0 : pButtonBrushItem = new SvxBrushItem( Color(), ATTR_BACKGROUND );
527 0 : pEmbeddedBrushItem = new SvxBrushItem( Color( COL_LIGHTCYAN ), ATTR_BACKGROUND );
528 0 : pProtectedBrushItem = new SvxBrushItem( Color( COL_LIGHTGRAY ), ATTR_BACKGROUND );
529 :
530 0 : UpdatePPT(NULL);
531 : //ScCompiler::InitSymbolsNative();
532 : // ScParameterClassification _after_ Compiler, needs function resources if
533 : // arguments are to be merged in, which in turn need strings of function
534 : // names from the compiler.
535 0 : ScParameterClassification::Init();
536 0 : srand( (unsigned) time( NULL ) ); // Random Seed Init fuer Interpreter
537 0 : sc::rng::seed( time( NULL ) ); // seed for libc rand() replacement
538 :
539 0 : InitAddIns();
540 :
541 0 : pStrClipDocName = new OUString( ScResId( SCSTR_NONAME ) );
542 0 : *pStrClipDocName += "1";
543 :
544 : // ScDocumentPool::InitVersionMaps() ist schon vorher gerufen worden
545 0 : }
546 :
547 0 : void ScGlobal::UpdatePPT( OutputDevice* pDev )
548 : {
549 0 : sal_uInt16 nCurrentZoom = Application::GetSettings().GetStyleSettings().GetScreenZoom();
550 0 : if ( nCurrentZoom != nPPTZoom )
551 : {
552 : // Screen PPT values must be updated when ScreenZoom has changed.
553 : // If called from Window::DataChanged, the window is passed as pDev,
554 : // to make sure LogicToPixel uses a device which already uses the new zoom.
555 : // For the initial settings, NULL is passed and GetDefaultDevice used.
556 :
557 0 : if ( !pDev )
558 0 : pDev = Application::GetDefaultDevice();
559 0 : Point aPix1000 = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
560 0 : nScreenPPTX = aPix1000.X() / 1000.0;
561 0 : nScreenPPTY = aPix1000.Y() / 1000.0;
562 0 : nPPTZoom = nCurrentZoom;
563 : }
564 0 : }
565 :
566 0 : const OUString& ScGlobal::GetClipDocName()
567 : {
568 0 : return *pStrClipDocName;
569 : }
570 :
571 0 : void ScGlobal::SetClipDocName( const OUString& rNew )
572 : {
573 0 : *pStrClipDocName = rNew;
574 0 : }
575 :
576 :
577 0 : void ScGlobal::InitTextHeight(SfxItemPool* pPool)
578 : {
579 0 : if (!pPool)
580 : {
581 : OSL_FAIL("ScGlobal::InitTextHeight: No Pool");
582 0 : return;
583 : }
584 :
585 0 : const ScPatternAttr* pPattern = (const ScPatternAttr*)&pPool->GetDefaultItem(ATTR_PATTERN);
586 0 : if (!pPattern)
587 : {
588 : OSL_FAIL("ScGlobal::InitTextHeight: No default pattern");
589 0 : return;
590 : }
591 :
592 0 : OutputDevice* pDefaultDev = Application::GetDefaultDevice();
593 0 : VirtualDevice aVirtWindow( *pDefaultDev );
594 0 : aVirtWindow.SetMapMode(MAP_PIXEL);
595 0 : Font aDefFont;
596 0 : pPattern->GetFont(aDefFont, SC_AUTOCOL_BLACK, &aVirtWindow); // font color doesn't matter here
597 0 : aVirtWindow.SetFont(aDefFont);
598 : sal_uInt16 nTest = static_cast<sal_uInt16>(
599 0 : aVirtWindow.PixelToLogic(Size(0, aVirtWindow.GetTextHeight()), MAP_TWIP).Height());
600 :
601 0 : if (nTest > nDefFontHeight)
602 0 : nDefFontHeight = nTest;
603 :
604 0 : const SvxMarginItem* pMargin = (const SvxMarginItem*)&pPattern->GetItem(ATTR_MARGIN);
605 :
606 : nTest = static_cast<sal_uInt16>(
607 0 : nDefFontHeight + pMargin->GetTopMargin() + pMargin->GetBottomMargin() - STD_ROWHEIGHT_DIFF);
608 :
609 0 : if (nTest > nStdRowHeight)
610 0 : nStdRowHeight = nTest;
611 : }
612 :
613 0 : void ScGlobal::Clear()
614 : {
615 : // asyncs _vor_ ExitExternalFunc zerstoeren!
616 0 : for( ScAddInAsyncs::iterator it = theAddInAsyncTbl.begin(); it != theAddInAsyncTbl.end(); ++it )
617 : {
618 0 : delete *it;
619 : }
620 0 : theAddInAsyncTbl.clear();
621 0 : ExitExternalFunc();
622 0 : DELETEZ(pAutoFormat);
623 0 : DELETEZ(pSearchItem);
624 0 : DELETEZ(pFuncCollection);
625 0 : DELETEZ(pAddInCollection);
626 0 : DELETEZ(pUserList);
627 :
628 0 : for( sal_uInt16 nC = 0 ; nC < SC_GLOBSTR_STR_COUNT ; nC++ )
629 0 : if( ppRscString ) delete ppRscString[ nC ];
630 0 : delete[] ppRscString;
631 0 : ppRscString = NULL;
632 :
633 0 : DELETEZ(pStarCalcFunctionList); // vor ResMgr zerstoeren!
634 0 : DELETEZ(pStarCalcFunctionMgr);
635 0 : ScParameterClassification::Exit();
636 0 : ScCompiler::DeInit();
637 0 : ScInterpreter::GlobalExit(); // statischen Stack loeschen
638 :
639 0 : DELETEZ(pEmptyBrushItem);
640 0 : DELETEZ(pButtonBrushItem);
641 0 : DELETEZ(pEmbeddedBrushItem);
642 0 : DELETEZ(pProtectedBrushItem);
643 0 : DELETEZ(pOutlineBitmaps);
644 0 : DELETEZ(pEnglishFormatter);
645 0 : DELETEZ(pCaseTransliteration);
646 0 : DELETEZ(pTransliteration);
647 0 : DELETEZ(pCaseCollator);
648 0 : DELETEZ(pCollator);
649 0 : DELETEZ(pCalendar);
650 : //! do NOT delete pCharClass since it is a pointer to the single SvtSysLocale instance
651 0 : pCharClass = NULL;
652 : //! do NOT delete pLocaleData since it is a pointer to the single SvtSysLocale instance
653 0 : pLocaleData = NULL;
654 0 : DELETEZ(pSysLocale);
655 0 : DELETEZ(pLocale);
656 0 : DELETEZ(pScIntlWrapper);
657 0 : DELETEZ(pStrClipDocName);
658 :
659 0 : DELETEZ(pUnitConverter);
660 0 : DELETEZ(pFieldEditEngine);
661 :
662 0 : ScDocumentPool::DeleteVersionMaps();
663 :
664 0 : DELETEZ(pEmptyOUString);
665 0 : }
666 :
667 0 : rtl_TextEncoding ScGlobal::GetCharsetValue( const OUString& rCharSet )
668 : {
669 : // new TextEncoding values
670 0 : if ( CharClass::isAsciiNumeric( rCharSet ) )
671 : {
672 0 : sal_Int32 nVal = rCharSet.toInt32();
673 0 : if ( !nVal || nVal == RTL_TEXTENCODING_DONTKNOW )
674 0 : return osl_getThreadTextEncoding();
675 0 : return (rtl_TextEncoding) nVal;
676 : }
677 : // old CharSet values for compatibility
678 0 : else if (rCharSet.equalsIgnoreAsciiCase("ANSI") ) return RTL_TEXTENCODING_MS_1252;
679 0 : else if (rCharSet.equalsIgnoreAsciiCase("MAC") ) return RTL_TEXTENCODING_APPLE_ROMAN;
680 0 : else if (rCharSet.equalsIgnoreAsciiCase("IBMPC") ) return RTL_TEXTENCODING_IBM_850;
681 0 : else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_437")) return RTL_TEXTENCODING_IBM_437;
682 0 : else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_850")) return RTL_TEXTENCODING_IBM_850;
683 0 : else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_860")) return RTL_TEXTENCODING_IBM_860;
684 0 : else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_861")) return RTL_TEXTENCODING_IBM_861;
685 0 : else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_863")) return RTL_TEXTENCODING_IBM_863;
686 0 : else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_865")) return RTL_TEXTENCODING_IBM_865;
687 0 : else return osl_getThreadTextEncoding();
688 : }
689 :
690 0 : OUString ScGlobal::GetCharsetString( rtl_TextEncoding eVal )
691 : {
692 : const sal_Char* pChar;
693 0 : switch ( eVal )
694 : {
695 : // old CharSet strings for compatibility
696 0 : case RTL_TEXTENCODING_MS_1252: pChar = "ANSI"; break;
697 0 : case RTL_TEXTENCODING_APPLE_ROMAN: pChar = "MAC"; break;
698 : // IBMPC == IBMPC_850
699 0 : case RTL_TEXTENCODING_IBM_437: pChar = "IBMPC_437"; break;
700 0 : case RTL_TEXTENCODING_IBM_850: pChar = "IBMPC_850"; break;
701 0 : case RTL_TEXTENCODING_IBM_860: pChar = "IBMPC_860"; break;
702 0 : case RTL_TEXTENCODING_IBM_861: pChar = "IBMPC_861"; break;
703 0 : case RTL_TEXTENCODING_IBM_863: pChar = "IBMPC_863"; break;
704 0 : case RTL_TEXTENCODING_IBM_865: pChar = "IBMPC_865"; break;
705 0 : case RTL_TEXTENCODING_DONTKNOW: pChar = "SYSTEM"; break;
706 : // new string of TextEncoding value
707 : default:
708 0 : return OUString::number( eVal );
709 : }
710 0 : return OUString::createFromAscii(pChar);
711 : }
712 :
713 0 : bool ScGlobal::HasStarCalcFunctionList()
714 : {
715 0 : return ( pStarCalcFunctionList != NULL );
716 : }
717 :
718 0 : ScFunctionList* ScGlobal::GetStarCalcFunctionList()
719 : {
720 0 : if ( !pStarCalcFunctionList )
721 0 : pStarCalcFunctionList = new ScFunctionList;
722 :
723 0 : return pStarCalcFunctionList;
724 : }
725 :
726 0 : ScFunctionMgr* ScGlobal::GetStarCalcFunctionMgr()
727 : {
728 0 : if ( !pStarCalcFunctionMgr )
729 0 : pStarCalcFunctionMgr = new ScFunctionMgr;
730 :
731 0 : return pStarCalcFunctionMgr;
732 : }
733 :
734 0 : void ScGlobal::ResetFunctionList()
735 : {
736 : // FunctionMgr has pointers into FunctionList, must also be updated
737 :
738 0 : DELETEZ( pStarCalcFunctionMgr );
739 0 : DELETEZ( pStarCalcFunctionList );
740 0 : }
741 :
742 0 : ScUnitConverter* ScGlobal::GetUnitConverter()
743 : {
744 0 : if ( !pUnitConverter )
745 0 : pUnitConverter = new ScUnitConverter;
746 :
747 0 : return pUnitConverter;
748 : }
749 :
750 :
751 0 : const sal_Unicode* ScGlobal::UnicodeStrChr( const sal_Unicode* pStr,
752 : sal_Unicode c )
753 : {
754 0 : if ( !pStr )
755 0 : return NULL;
756 0 : while ( *pStr )
757 : {
758 0 : if ( *pStr == c )
759 0 : return pStr;
760 0 : pStr++;
761 : }
762 0 : return NULL;
763 : }
764 :
765 0 : OUString ScGlobal::addToken(const OUString& rTokenList, const OUString& rToken,
766 : sal_Unicode cSep, sal_Int32 nSepCount, bool bForceSep)
767 : {
768 0 : OUStringBuffer aBuf(rTokenList);
769 0 : if( bForceSep || (!rToken.isEmpty() && !rTokenList.isEmpty()) )
770 0 : comphelper::string::padToLength(aBuf, aBuf.getLength() + nSepCount, cSep);
771 0 : aBuf.append(rToken);
772 0 : return aBuf.makeStringAndClear();
773 : }
774 :
775 0 : bool ScGlobal::IsQuoted( const OUString& rString, sal_Unicode cQuote )
776 : {
777 0 : return (rString.getLength() >= 2) && (rString[0] == cQuote) && (rString[ rString.getLength() - 1 ] == cQuote);
778 : }
779 :
780 0 : void ScGlobal::AddQuotes( OUString& rString, sal_Unicode cQuote, bool bEscapeEmbedded )
781 : {
782 0 : if (bEscapeEmbedded)
783 : {
784 : sal_Unicode pQ[3];
785 0 : pQ[0] = pQ[1] = cQuote;
786 0 : pQ[2] = 0;
787 0 : OUString aQuotes( pQ );
788 0 : rString = rString.replaceAll( OUString(cQuote), aQuotes);
789 : }
790 0 : rString = OUString( cQuote ) + rString + OUString( cQuote );
791 0 : }
792 :
793 0 : void ScGlobal::EraseQuotes( OUString& rString, sal_Unicode cQuote, bool bUnescapeEmbedded )
794 : {
795 0 : if ( IsQuoted( rString, cQuote ) )
796 : {
797 0 : rString = rString.copy( 1, rString.getLength() - 2 );
798 0 : if (bUnescapeEmbedded)
799 : {
800 : sal_Unicode pQ[3];
801 0 : pQ[0] = pQ[1] = cQuote;
802 0 : pQ[2] = 0;
803 0 : OUString aQuotes( pQ );
804 0 : rString = rString.replaceAll( aQuotes, OUString(cQuote));
805 : }
806 : }
807 0 : }
808 :
809 0 : sal_Int32 ScGlobal::FindUnquoted( const OUString& rString, sal_Unicode cChar)
810 : {
811 0 : const sal_Unicode cQuote = '\'';
812 0 : const sal_Unicode* const pStart = rString.getStr();
813 0 : const sal_Unicode* const pStop = pStart + rString.getLength();
814 0 : const sal_Unicode* p = pStart;
815 0 : bool bQuoted = false;
816 0 : while (p < pStop)
817 : {
818 0 : if (*p == cChar && !bQuoted)
819 0 : return sal::static_int_cast< sal_Int32 >( p - pStart );
820 0 : else if (*p == cQuote)
821 : {
822 0 : if (!bQuoted)
823 0 : bQuoted = true;
824 0 : else if (p < pStop-1 && *(p+1) == cQuote)
825 0 : ++p;
826 : else
827 0 : bQuoted = false;
828 : }
829 0 : ++p;
830 : }
831 0 : return -1;
832 : }
833 :
834 0 : const sal_Unicode* ScGlobal::FindUnquoted( const sal_Unicode* pString, sal_Unicode cChar, sal_Unicode cQuote )
835 : {
836 0 : const sal_Unicode* p = pString;
837 0 : bool bQuoted = false;
838 0 : while (*p)
839 : {
840 0 : if (*p == cChar && !bQuoted)
841 0 : return p;
842 0 : else if (*p == cQuote)
843 : {
844 0 : if (!bQuoted)
845 0 : bQuoted = true;
846 0 : else if (*(p+1) == cQuote)
847 0 : ++p;
848 : else
849 0 : bQuoted = false;
850 : }
851 0 : ++p;
852 : }
853 0 : return NULL;
854 : }
855 :
856 0 : bool ScGlobal::EETextObjEqual( const EditTextObject* pObj1,
857 : const EditTextObject* pObj2 )
858 : {
859 0 : if ( pObj1 == pObj2 ) // both empty or the same object
860 0 : return true;
861 :
862 0 : if ( pObj1 && pObj2 )
863 : {
864 : // first test for equal text content
865 0 : sal_Int32 nParCount = pObj1->GetParagraphCount();
866 0 : if ( nParCount != pObj2->GetParagraphCount() )
867 0 : return false;
868 0 : for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
869 0 : if ( pObj1->GetText(nPar) != pObj2->GetText(nPar) )
870 0 : return false;
871 :
872 0 : SvMemoryStream aStream1;
873 0 : SvMemoryStream aStream2;
874 0 : pObj1->Store( aStream1 );
875 0 : pObj2->Store( aStream2 );
876 0 : sal_uLong nSize = aStream1.Tell();
877 0 : if ( aStream2.Tell() == nSize )
878 0 : if ( !memcmp( aStream1.GetData(), aStream2.GetData(), (sal_uInt16) nSize ) )
879 0 : return true;
880 : }
881 :
882 0 : return false;
883 : }
884 :
885 0 : void ScGlobal::OpenURL( const OUString& rURL, const OUString& rTarget )
886 : {
887 : // OpenURL wird immer ueber irgendwelche Umwege durch Mausklicks im GridWindow
888 : // aufgerufen, darum stimmen pScActiveViewShell und nScClickMouseModifier.
889 : //SvtSecurityOptions to access Libreoffice global security parameters
890 0 : SvtSecurityOptions aSecOpt;
891 0 : bool bCtrlClickHappened = (nScClickMouseModifier & KEY_MOD1);
892 0 : bool bCtrlClickSecOption = aSecOpt.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
893 0 : if( bCtrlClickHappened && !( bCtrlClickSecOption ) )
894 : {
895 : //return since ctrl+click happened when the
896 : //ctrl+click security option was disabled, link should not open
897 0 : return;
898 : }
899 0 : else if( !( bCtrlClickHappened ) && bCtrlClickSecOption )
900 : {
901 : //ctrl+click did not happen; only click happened maybe with some
902 : //other key combo. and security option is set, so return
903 0 : return;
904 : }
905 0 : SfxStringItem aUrl( SID_FILE_NAME, rURL );
906 0 : SfxStringItem aTarget( SID_TARGETNAME, rTarget );
907 0 : aTarget.SetValue(OUString("_blank"));
908 0 : SfxViewFrame* pFrame = NULL;
909 0 : OUString aReferName;
910 0 : if ( pScActiveViewShell )
911 : {
912 0 : pFrame = pScActiveViewShell->GetViewFrame();
913 0 : SfxMedium* pMed = pFrame->GetObjectShell()->GetMedium();
914 0 : if (pMed)
915 0 : aReferName = pMed->GetName();
916 : }
917 :
918 0 : SfxFrameItem aFrm( SID_DOCFRAME, pFrame );
919 0 : SfxStringItem aReferer( SID_REFERER, aReferName );
920 :
921 0 : SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, false );
922 0 : SfxBoolItem aBrowsing( SID_BROWSE, true );
923 :
924 : // kein SID_SILENT mehr
925 :
926 0 : SfxViewFrame* pViewFrm = SfxViewFrame::Current();
927 0 : if (pViewFrm)
928 : pViewFrm->GetDispatcher()->Execute( SID_OPENDOC,
929 : SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
930 : &aUrl, &aTarget,
931 : &aFrm, &aReferer,
932 : &aNewView, &aBrowsing,
933 0 : 0L );
934 : }
935 :
936 0 : bool ScGlobal::IsSystemRTL()
937 : {
938 0 : return MsLangId::isRightToLeft( Application::GetSettings().GetLanguageTag().getLanguageType() );
939 : }
940 :
941 0 : sal_uInt8 ScGlobal::GetDefaultScriptType()
942 : {
943 : // Used when text contains only WEAK characters.
944 : // Script type of office language is used then (same as GetEditDefaultLanguage,
945 : // to get consistent behavior of text in simple cells and EditEngine,
946 : // also same as GetAppLanguage() in Writer)
947 :
948 0 : return (sal_uInt8) SvtLanguageOptions::GetScriptTypeOfLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
949 : }
950 :
951 0 : LanguageType ScGlobal::GetEditDefaultLanguage()
952 : {
953 : // used for EditEngine::SetDefaultLanguage
954 :
955 0 : return Application::GetSettings().GetLanguageTag().getLanguageType();
956 : }
957 :
958 0 : sal_uInt16 ScGlobal::GetScriptedWhichID( sal_uInt8 nScriptType, sal_uInt16 nWhich )
959 : {
960 0 : switch ( nScriptType )
961 : {
962 : case SCRIPTTYPE_LATIN:
963 : case SCRIPTTYPE_ASIAN:
964 : case SCRIPTTYPE_COMPLEX:
965 0 : break; // take exact matches
966 : default: // prefer one, first COMPLEX, then ASIAN
967 0 : if ( nScriptType & SCRIPTTYPE_COMPLEX )
968 0 : nScriptType = SCRIPTTYPE_COMPLEX;
969 0 : else if ( nScriptType & SCRIPTTYPE_ASIAN )
970 0 : nScriptType = SCRIPTTYPE_ASIAN;
971 : }
972 0 : switch ( nScriptType )
973 : {
974 : case SCRIPTTYPE_COMPLEX:
975 : {
976 0 : switch ( nWhich )
977 : {
978 : case ATTR_FONT:
979 : case ATTR_CJK_FONT:
980 0 : nWhich = ATTR_CTL_FONT;
981 0 : break;
982 : case ATTR_FONT_HEIGHT:
983 : case ATTR_CJK_FONT_HEIGHT:
984 0 : nWhich = ATTR_CTL_FONT_HEIGHT;
985 0 : break;
986 : case ATTR_FONT_WEIGHT:
987 : case ATTR_CJK_FONT_WEIGHT:
988 0 : nWhich = ATTR_CTL_FONT_WEIGHT;
989 0 : break;
990 : case ATTR_FONT_POSTURE:
991 : case ATTR_CJK_FONT_POSTURE:
992 0 : nWhich = ATTR_CTL_FONT_POSTURE;
993 0 : break;
994 : }
995 : }
996 0 : break;
997 : case SCRIPTTYPE_ASIAN:
998 : {
999 0 : switch ( nWhich )
1000 : {
1001 : case ATTR_FONT:
1002 : case ATTR_CTL_FONT:
1003 0 : nWhich = ATTR_CJK_FONT;
1004 0 : break;
1005 : case ATTR_FONT_HEIGHT:
1006 : case ATTR_CTL_FONT_HEIGHT:
1007 0 : nWhich = ATTR_CJK_FONT_HEIGHT;
1008 0 : break;
1009 : case ATTR_FONT_WEIGHT:
1010 : case ATTR_CTL_FONT_WEIGHT:
1011 0 : nWhich = ATTR_CJK_FONT_WEIGHT;
1012 0 : break;
1013 : case ATTR_FONT_POSTURE:
1014 : case ATTR_CTL_FONT_POSTURE:
1015 0 : nWhich = ATTR_CJK_FONT_POSTURE;
1016 0 : break;
1017 : }
1018 : }
1019 0 : break;
1020 : default:
1021 : {
1022 0 : switch ( nWhich )
1023 : {
1024 : case ATTR_CTL_FONT:
1025 : case ATTR_CJK_FONT:
1026 0 : nWhich = ATTR_FONT;
1027 0 : break;
1028 : case ATTR_CTL_FONT_HEIGHT:
1029 : case ATTR_CJK_FONT_HEIGHT:
1030 0 : nWhich = ATTR_FONT_HEIGHT;
1031 0 : break;
1032 : case ATTR_CTL_FONT_WEIGHT:
1033 : case ATTR_CJK_FONT_WEIGHT:
1034 0 : nWhich = ATTR_FONT_WEIGHT;
1035 0 : break;
1036 : case ATTR_CTL_FONT_POSTURE:
1037 : case ATTR_CJK_FONT_POSTURE:
1038 0 : nWhich = ATTR_FONT_POSTURE;
1039 0 : break;
1040 : }
1041 : }
1042 : }
1043 0 : return nWhich;
1044 : }
1045 :
1046 0 : void ScGlobal::AddLanguage( SfxItemSet& rSet, SvNumberFormatter& rFormatter )
1047 : {
1048 : OSL_ENSURE( rSet.GetItemState( ATTR_LANGUAGE_FORMAT, false ) == SFX_ITEM_DEFAULT,
1049 : "ScGlobal::AddLanguage - language already added");
1050 :
1051 : const SfxPoolItem* pHardItem;
1052 0 : if ( rSet.GetItemState( ATTR_VALUE_FORMAT, false, &pHardItem ) == SFX_ITEM_SET )
1053 : {
1054 : const SvNumberformat* pHardFormat = rFormatter.GetEntry(
1055 0 : ((const SfxUInt32Item*)pHardItem)->GetValue() );
1056 :
1057 0 : sal_uLong nParentFmt = 0; // pool default
1058 0 : const SfxItemSet* pParent = rSet.GetParent();
1059 0 : if ( pParent )
1060 0 : nParentFmt = ((const SfxUInt32Item&)pParent->Get( ATTR_VALUE_FORMAT )).GetValue();
1061 0 : const SvNumberformat* pParFormat = rFormatter.GetEntry( nParentFmt );
1062 :
1063 0 : if ( pHardFormat && pParFormat &&
1064 0 : (pHardFormat->GetLanguage() != pParFormat->GetLanguage()) )
1065 0 : rSet.Put( SvxLanguageItem( pHardFormat->GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
1066 : }
1067 0 : }
1068 :
1069 :
1070 :
1071 :
1072 0 : utl::TransliterationWrapper* ScGlobal::GetpTransliteration()
1073 : {
1074 0 : if ( !pTransliteration )
1075 : {
1076 0 : const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
1077 : pTransliteration = new ::utl::TransliterationWrapper(
1078 0 : ::comphelper::getProcessComponentContext(), SC_TRANSLITERATION_IGNORECASE );
1079 0 : pTransliteration->loadModuleIfNeeded( eOfficeLanguage );
1080 : }
1081 : OSL_ENSURE(
1082 : pTransliteration,
1083 : "ScGlobal::GetpTransliteration() called before ScGlobal::Init()");
1084 0 : return pTransliteration;
1085 : }
1086 :
1087 0 : const LocaleDataWrapper* ScGlobal::GetpLocaleData()
1088 : {
1089 : OSL_ENSURE(
1090 : pLocaleData,
1091 : "ScGlobal::GetpLocaleData() called before ScGlobal::Init()");
1092 0 : return pLocaleData;
1093 : }
1094 0 : CalendarWrapper* ScGlobal::GetCalendar()
1095 : {
1096 0 : if ( !pCalendar )
1097 : {
1098 0 : pCalendar = new CalendarWrapper( ::comphelper::getProcessComponentContext() );
1099 0 : pCalendar->loadDefaultCalendar( *GetLocale() );
1100 : }
1101 0 : return pCalendar;
1102 : }
1103 0 : CollatorWrapper* ScGlobal::GetCollator()
1104 : {
1105 0 : if ( !pCollator )
1106 : {
1107 0 : pCollator = new CollatorWrapper( ::comphelper::getProcessComponentContext() );
1108 0 : pCollator->loadDefaultCollator( *GetLocale(), SC_COLLATOR_IGNORES );
1109 : }
1110 0 : return pCollator;
1111 : }
1112 0 : CollatorWrapper* ScGlobal::GetCaseCollator()
1113 : {
1114 0 : if ( !pCaseCollator )
1115 : {
1116 0 : pCaseCollator = new CollatorWrapper( ::comphelper::getProcessComponentContext() );
1117 0 : pCaseCollator->loadDefaultCollator( *GetLocale(), 0 );
1118 : }
1119 0 : return pCaseCollator;
1120 : }
1121 0 : ::utl::TransliterationWrapper* ScGlobal::GetCaseTransliteration()
1122 : {
1123 0 : if ( !pCaseTransliteration )
1124 : {
1125 0 : const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
1126 0 : pCaseTransliteration = new ::utl::TransliterationWrapper(::comphelper::getProcessComponentContext(), SC_TRANSLITERATION_CASESENSE );
1127 0 : pCaseTransliteration->loadModuleIfNeeded( eOfficeLanguage );
1128 : }
1129 0 : return pCaseTransliteration;
1130 : }
1131 0 : IntlWrapper* ScGlobal::GetScIntlWrapper()
1132 : {
1133 0 : if ( !pScIntlWrapper )
1134 : {
1135 0 : pScIntlWrapper = new IntlWrapper( LanguageTag( *GetLocale()) );
1136 : }
1137 0 : return pScIntlWrapper;
1138 : }
1139 0 : ::com::sun::star::lang::Locale* ScGlobal::GetLocale()
1140 : {
1141 0 : if ( !pLocale )
1142 : {
1143 0 : pLocale = new ::com::sun::star::lang::Locale( Application::GetSettings().GetLanguageTag().getLocale());
1144 : }
1145 0 : return pLocale;
1146 : }
1147 :
1148 0 : ScFieldEditEngine& ScGlobal::GetStaticFieldEditEngine()
1149 : {
1150 0 : if (!pFieldEditEngine)
1151 : {
1152 : // Creating a ScFieldEditEngine with pDocument=NULL leads to document
1153 : // specific fields not being resolvable! See
1154 : // ScFieldEditEngine::CalcFieldValue(). pEnginePool=NULL lets
1155 : // EditEngine internally create and delete a default pool.
1156 0 : pFieldEditEngine = new ScFieldEditEngine( NULL, NULL);
1157 : }
1158 0 : return *pFieldEditEngine;
1159 : }
1160 :
1161 0 : OUString ScGlobal::ReplaceOrAppend( const OUString& rString,
1162 : const OUString& rPlaceholder, const OUString& rReplacement )
1163 : {
1164 0 : if (rString.isEmpty())
1165 0 : return rReplacement;
1166 0 : sal_Int32 nFound = rString.indexOf( rPlaceholder);
1167 0 : if (nFound < 0)
1168 : {
1169 0 : if (rString[rString.getLength()-1] == ' ')
1170 0 : return rString + rReplacement;
1171 0 : return rString + " " + rReplacement;
1172 : }
1173 0 : return rString.replaceFirst( rPlaceholder, rReplacement, &nFound);
1174 0 : }
1175 :
1176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|