1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: global.cxx,v $
10 * $Revision: 1.56.102.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
37 #include <vcl/svapp.hxx>
38 #include "scitems.hxx"
39 #include <svx/algitem.hxx>
40 #include <svx/brshitem.hxx>
41 #include <svx/editobj.hxx>
42 #include <svx/scripttypeitem.hxx>
43 #include <svx/srchitem.hxx>
44 #include <svx/langitem.hxx>
45 #include <sfx2/docfile.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <sfx2/objsh.hxx>
48 #include <sfx2/viewfrm.hxx>
49 #include <sfx2/viewsh.hxx>
50 #include <svtools/stritem.hxx>
51 #include <svtools/zforlist.hxx>
52 #include <svtools/zformat.hxx>
53 #include <vcl/image.hxx>
54 #include <vcl/virdev.hxx>
55 #include <tools/rcid.h>
56 #include <unotools/charclass.hxx>
63 #include <i18npool/mslangid.hxx>
64 #include <com/sun/star/lang/Locale.hpp>
65 #include <comphelper/processfactory.hxx>
66 #include <unotools/calendarwrapper.hxx>
67 #include <unotools/collatorwrapper.hxx>
68 #include <com/sun/star/i18n/CollatorOptions.hpp>
69 #include <unotools/intlwrapper.hxx>
70 #include <svtools/syslocale.hxx>
71 #include <unotools/transliterationwrapper.hxx>
74 #include "scresid.hxx"
75 #include "autoform.hxx"
76 #include "document.hxx"
77 #include "patattr.hxx"
78 #include "addincol.hxx"
79 #include "adiasync.hxx"
80 #include "userlist.hxx"
81 #include "interpre.hxx"
82 #include "strload.hxx"
83 #include "docpool.hxx"
84 #include "unitconv.hxx"
85 #include "compiler.hxx"
86 #include "parclass.hxx"
87 #include "funcdesc.hxx"
88 #include "globstr.hrc"
89 #include "scfuncs.hrc"
92 #include "appoptio.hxx"
94 // -----------------------------------------------------------------------
96 #define CLIPST_AVAILABLE 0
97 #define CLIPST_CAPTURED 1
98 #define CLIPST_DELETE 2
101 ScDocShellRef
* ScGlobal::pDrawClipDocShellRef
= NULL
;
102 SvxSearchItem
* ScGlobal::pSearchItem
= NULL
;
103 ScAutoFormat
* ScGlobal::pAutoFormat
= NULL
;
104 FuncCollection
* ScGlobal::pFuncCollection
= NULL
;
105 ScUnoAddInCollection
* ScGlobal::pAddInCollection
= NULL
;
106 ScUserList
* ScGlobal::pUserList
= NULL
;
107 String
** ScGlobal::ppRscString
= NULL
;
108 LanguageType
ScGlobal::eLnge
= LANGUAGE_SYSTEM
;
109 ::com::sun::star::lang::Locale
* ScGlobal::pLocale
= NULL
;
110 SvtSysLocale
* ScGlobal::pSysLocale
= NULL
;
111 const CharClass
* ScGlobal::pCharClass
= NULL
;
112 const LocaleDataWrapper
* ScGlobal::pLocaleData
= NULL
;
113 CalendarWrapper
* ScGlobal::pCalendar
= NULL
;
114 CollatorWrapper
* ScGlobal::pCollator
= NULL
;
115 CollatorWrapper
* ScGlobal::pCaseCollator
= NULL
;
116 ::utl::TransliterationWrapper
* ScGlobal::pTransliteration
= NULL
;
117 ::utl::TransliterationWrapper
* ScGlobal::pCaseTransliteration
= NULL
;
118 ::com::sun::star::uno::Reference
< ::com::sun::star::i18n::XOrdinalSuffix
> ScGlobal::xOrdinalSuffix
= NULL
;
119 IntlWrapper
* ScGlobal::pScIntlWrapper
= NULL
;
120 sal_Unicode
ScGlobal::cListDelimiter
= ',';
121 String
* ScGlobal::pEmptyString
= NULL
;
122 String
* ScGlobal::pStrClipDocName
= NULL
;
124 SvxBrushItem
* ScGlobal::pEmptyBrushItem
= NULL
;
125 SvxBrushItem
* ScGlobal::pButtonBrushItem
= NULL
;
126 SvxBrushItem
* ScGlobal::pEmbeddedBrushItem
= NULL
;
127 SvxBrushItem
* ScGlobal::pProtectedBrushItem
= NULL
;
129 ImageList
* ScGlobal::pOutlineBitmaps
= NULL
;
130 ImageList
* ScGlobal::pOutlineBitmapsHC
= NULL
;
132 ScFunctionList
* ScGlobal::pStarCalcFunctionList
= NULL
;
133 ScFunctionMgr
* ScGlobal::pStarCalcFunctionMgr
= NULL
;
135 ScUnitConverter
* ScGlobal::pUnitConverter
= NULL
;
136 SvNumberFormatter
* ScGlobal::pEnglishFormatter
= NULL
;
138 double ScGlobal::nScreenPPTX
= 96.0;
139 double ScGlobal::nScreenPPTY
= 96.0;
141 USHORT
ScGlobal::nDefFontHeight
= 240;
142 USHORT
ScGlobal::nStdRowHeight
= 257;
144 long ScGlobal::nLastRowHeightExtra
= 0;
145 long ScGlobal::nLastColWidthExtra
= STD_EXTRA_WIDTH
;
147 static USHORT nPPTZoom
= 0; // ScreenZoom used to determine nScreenPPTX/Y
154 bool SC_DLLPUBLIC
ScGetWriteTeamInfo()
160 SfxViewShell
* pScActiveViewShell
= NULL
; //! als Member !!!!!
161 USHORT nScClickMouseModifier
= 0; //! dito
162 USHORT nScFillModeMouseModifier
= 0; //! dito
164 // Hack: ScGlobal::GetUserList() muss InitAppOptions in der UI aufrufen,
165 // damit UserList aus Cfg geladen wird
167 void global_InitAppOptions();
169 //========================================================================
171 // statische Funktionen
173 //========================================================================
175 BOOL
ScGlobal::HasAttrChanged( const SfxItemSet
& rNewAttrs
,
176 const SfxItemSet
& rOldAttrs
,
177 const USHORT nWhich
)
179 BOOL bInvalidate
= FALSE
;
180 const SfxItemState eNewState
= rNewAttrs
.GetItemState( nWhich
);
181 const SfxItemState eOldState
= rOldAttrs
.GetItemState( nWhich
);
183 //----------------------------------------------------------
185 if ( eNewState
== eOldState
)
187 // beide Items gesetzt
188 // PoolItems, d.h. Pointer-Vergleich zulaessig
189 if ( SFX_ITEM_SET
== eOldState
)
190 bInvalidate
= (&rNewAttrs
.Get( nWhich
) != &rOldAttrs
.Get( nWhich
));
194 // ein Default-Item dabei
195 // PoolItems, d.h. Item-Vergleich noetig
197 const SfxPoolItem
& rOldItem
= ( SFX_ITEM_SET
== eOldState
)
198 ? rOldAttrs
.Get( nWhich
)
199 : rOldAttrs
.GetPool()->GetDefaultItem( nWhich
);
201 const SfxPoolItem
& rNewItem
= ( SFX_ITEM_SET
== eNewState
)
202 ? rNewAttrs
.Get( nWhich
)
203 : rNewAttrs
.GetPool()->GetDefaultItem( nWhich
);
205 bInvalidate
= sal::static_int_cast
<BOOL
>(rNewItem
!= rOldItem
);
211 ULONG
ScGlobal::GetStandardFormat( SvNumberFormatter
& rFormatter
,
212 ULONG nFormat
, short nType
)
214 const SvNumberformat
* pFormat
= rFormatter
.GetEntry( nFormat
);
216 return rFormatter
.GetStandardFormat( nFormat
, nType
, pFormat
->GetLanguage() );
217 return rFormatter
.GetStandardFormat( nType
, eLnge
);
220 ULONG
ScGlobal::GetStandardFormat( double fNumber
, SvNumberFormatter
& rFormatter
,
221 ULONG nFormat
, short nType
)
223 const SvNumberformat
* pFormat
= rFormatter
.GetEntry( nFormat
);
225 return rFormatter
.GetStandardFormat( fNumber
, nFormat
, nType
,
226 pFormat
->GetLanguage() );
227 return rFormatter
.GetStandardFormat( nType
, eLnge
);
232 SvNumberFormatter
* ScGlobal::GetEnglishFormatter()
234 if ( !pEnglishFormatter
)
236 pEnglishFormatter
= new SvNumberFormatter(
237 ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US
);
238 pEnglishFormatter
->SetEvalDateFormat( NF_EVALDATEFORMAT_INTL_FORMAT
);
240 return pEnglishFormatter
;
244 //------------------------------------------------------------------------
246 BOOL
ScGlobal::CheckWidthInvalidate( BOOL
& bNumFormatChanged
,
247 const SfxItemSet
& rNewAttrs
,
248 const SfxItemSet
& rOldAttrs
)
250 // Ueberpruefen, ob Attributaenderungen in rNewAttrs gegnueber
251 // rOldAttrs die Textbreite an einer Zelle ungueltig machen
254 HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_VALUE_FORMAT
);
255 return ( bNumFormatChanged
256 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_LANGUAGE_FORMAT
)
257 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT
)
258 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CJK_FONT
)
259 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CTL_FONT
)
260 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_HEIGHT
)
261 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CJK_FONT_HEIGHT
)
262 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CTL_FONT_HEIGHT
)
263 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_WEIGHT
)
264 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CJK_FONT_WEIGHT
)
265 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CTL_FONT_WEIGHT
)
266 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_POSTURE
)
267 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CJK_FONT_POSTURE
)
268 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_CTL_FONT_POSTURE
)
269 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_UNDERLINE
)
270 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_OVERLINE
)
271 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_CROSSEDOUT
)
272 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_CONTOUR
)
273 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_FONT_SHADOWED
)
274 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_STACKED
)
275 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_ROTATE_VALUE
)
276 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_ROTATE_MODE
)
277 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_LINEBREAK
)
278 || HasAttrChanged( rNewAttrs
, rOldAttrs
, ATTR_MARGIN
)
282 const SvxSearchItem
& ScGlobal::GetSearchItem()
286 pSearchItem
= new SvxSearchItem( SID_SEARCH_ITEM
);
287 pSearchItem
->SetAppFlag( SVX_SEARCHAPP_CALC
);
292 void ScGlobal::SetSearchItem( const SvxSearchItem
& rNew
)
294 // Hier waere ein Zuweisungsoperator ganz nett:
296 pSearchItem
= (SvxSearchItem
*)rNew
.Clone();
298 pSearchItem
->SetWhich( SID_SEARCH_ITEM
);
301 void ScGlobal::ClearAutoFormat()
303 if (pAutoFormat
!=NULL
)
310 ScAutoFormat
* ScGlobal::GetAutoFormat()
314 pAutoFormat
= new ScAutoFormat
;
321 FuncCollection
* ScGlobal::GetFuncCollection()
323 if (!pFuncCollection
)
324 pFuncCollection
= new FuncCollection();
325 return pFuncCollection
;
328 ScUnoAddInCollection
* ScGlobal::GetAddInCollection()
330 if (!pAddInCollection
)
331 pAddInCollection
= new ScUnoAddInCollection();
332 return pAddInCollection
;
335 ScUserList
* ScGlobal::GetUserList()
337 // Hack: Cfg-Item an der App ggF. laden
339 global_InitAppOptions();
342 pUserList
= new ScUserList();
346 void ScGlobal::SetUserList( const ScUserList
* pNewList
)
351 pUserList
= new ScUserList( *pNewList
);
353 *pUserList
= *pNewList
;
362 const String
& ScGlobal::GetRscString( USHORT nIndex
)
364 DBG_ASSERT( nIndex
< STR_COUNT
, "ScGlobal::GetRscString - invalid string index");
365 if( !ppRscString
[ nIndex
] )
368 // Map former globstr.src strings moved to compiler.src
383 case STR_NO_NAME_REF
:
396 ppRscString
[ nIndex
] = new String(
397 ScCompiler::GetNativeSymbol( eOp
));
399 ppRscString
[ nIndex
] = new String(
400 ScRscStrLoader( RID_GLOBSTR
, nIndex
).GetString());
402 return *ppRscString
[ nIndex
];
405 String
ScGlobal::GetErrorString(USHORT nErrNumber
)
410 case NOTAVAILABLE
: nErrNumber
= STR_NV_STR
; break;
411 case errNoRef
: nErrNumber
= STR_NO_REF_TABLE
; break;
412 case errNoName
: nErrNumber
= STR_NO_NAME_REF
; break;
413 case errNoAddin
: nErrNumber
= STR_NO_ADDIN
; break;
414 case errNoMacro
: nErrNumber
= STR_NO_MACRO
; break;
416 case errNoValue
: nErrNumber
= STR_NO_VALUE
; break;
417 case errNoCode
: nErrNumber
= STR_NULL_ERROR
; break;
418 case errDivisionByZero
: nErrNumber
= STR_DIV_ZERO
; break;
419 case errIllegalFPOperation
: nErrNumber
= STR_NUM_ERROR
; break;
421 default : sResStr
= GetRscString(STR_ERROR_STR
);
422 sResStr
+= String::CreateFromInt32( nErrNumber
);
427 sResStr
= GetRscString( nErrNumber
);
431 String
ScGlobal::GetLongErrorString(USHORT nErrNumber
)
438 case errIllegalArgument
:
439 nErrNumber
= STR_LONG_ERR_ILL_ARG
;
445 case errIllegalFPOperation
:
446 nErrNumber
= STR_LONG_ERR_ILL_FPO
;
449 nErrNumber
= STR_LONG_ERR_ILL_CHAR
;
451 case errIllegalParameter
:
452 nErrNumber
= STR_LONG_ERR_ILL_PAR
;
455 nErrNumber
= STR_LONG_ERR_ILL_SEP
;
458 case errPairExpected
:
459 nErrNumber
= STR_LONG_ERR_PAIR
;
461 case errOperatorExpected
:
462 nErrNumber
= STR_LONG_ERR_OP_EXP
;
464 case errVariableExpected
:
465 case errParameterExpected
:
466 nErrNumber
= STR_LONG_ERR_VAR_EXP
;
468 case errCodeOverflow
:
469 nErrNumber
= STR_LONG_ERR_CODE_OVF
;
471 case errStringOverflow
:
472 nErrNumber
= STR_LONG_ERR_STR_OVF
;
474 case errStackOverflow
:
475 case errInterpOverflow
:
476 nErrNumber
= STR_LONG_ERR_STACK_OVF
;
479 case errUnknownState
:
480 case errUnknownVariable
:
481 case errUnknownOpCode
:
482 case errUnknownStackVariable
:
483 case errUnknownToken
:
486 nErrNumber
= STR_LONG_ERR_SYNTAX
;
488 case errCircularReference
:
489 nErrNumber
= STR_LONG_ERR_CIRC_REF
;
491 case errNoConvergence
:
492 nErrNumber
= STR_LONG_ERR_NO_CONV
;
495 nErrNumber
= STR_LONG_ERR_NO_REF
;
498 nErrNumber
= STR_LONG_ERR_NO_NAME
;
501 nErrNumber
= STR_LONG_ERR_NO_ADDIN
;
504 nErrNumber
= STR_LONG_ERR_NO_MACRO
;
506 case errDivisionByZero
:
507 nErrNumber
= STR_LONG_ERR_DIV_ZERO
;
510 nErrNumber
= STR_ERR_LONG_NESTED_ARRAY
;
513 nErrNumber
= STR_LONG_ERR_NO_VALUE
;
516 nErrNumber
= STR_LONG_ERR_NV
;
519 nErrNumber
= STR_ERROR_STR
;
522 String
aRes( GetRscString( nErrNumber
) );
525 String
aOderSo( GetRscString( STR_ODER_SO
) );
526 aOderSo
.SearchAndReplace( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("%s")), aRes
);
532 SvxBrushItem
* ScGlobal::GetButtonBrushItem()
534 pButtonBrushItem
->SetColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
535 return pButtonBrushItem
;
538 const String
& ScGlobal::GetEmptyString()
540 return *pEmptyString
;
543 ImageList
* ScGlobal::GetOutlineSymbols( bool bHC
)
545 ImageList
*& rpImageList
= bHC
? pOutlineBitmapsHC
: pOutlineBitmaps
;
547 rpImageList
= new ImageList( ScResId( bHC
? RID_OUTLINEBITMAPS_H
: RID_OUTLINEBITMAPS
) );
551 void ScGlobal::Init()
553 pEmptyString
= new String
;
555 // Die Default-Sprache fuer Zahlenformate (ScGlobal::eLnge)
556 // muss immer LANGUAGE_SYSTEM sein
557 //! Dann kann auch die Variable raus
558 eLnge
= LANGUAGE_SYSTEM
;
560 //! Wenn Sortierung etc. von der Sprache der installierten Offfice-Version
561 //! abhaengen sollen, hier "Application::GetSettings().GetUILanguage()"
562 pSysLocale
= new SvtSysLocale
;
563 pCharClass
= pSysLocale
->GetCharClassPtr();
564 pLocaleData
= pSysLocale
->GetLocaleDataPtr();
566 ppRscString
= new String
*[ STR_COUNT
];
567 for( USHORT nC
= 0 ; nC
< STR_COUNT
; nC
++ ) ppRscString
[ nC
] = NULL
;
569 pEmptyBrushItem
= new SvxBrushItem( Color( COL_TRANSPARENT
), ATTR_BACKGROUND
);
570 pButtonBrushItem
= new SvxBrushItem( Color(), ATTR_BACKGROUND
);
571 pEmbeddedBrushItem
= new SvxBrushItem( Color( COL_LIGHTCYAN
), ATTR_BACKGROUND
);
572 pProtectedBrushItem
= new SvxBrushItem( Color( COL_LIGHTGRAY
), ATTR_BACKGROUND
);
575 //ScCompiler::InitSymbolsNative();
576 // ScParameterClassification _after_ Compiler, needs function resources if
577 // arguments are to be merged in, which in turn need strings of function
578 // names from the compiler.
579 ScParameterClassification::Init();
580 srand( (unsigned) time( NULL
) ); // Random Seed Init fuer Interpreter
584 pStrClipDocName
= new String( ScResId( SCSTR_NONAME
) );
585 *pStrClipDocName
+= '1';
587 // ScDocumentPool::InitVersionMaps() ist schon vorher gerufen worden
590 void ScGlobal::UpdatePPT( OutputDevice
* pDev
)
592 USHORT nCurrentZoom
= Application::GetSettings().GetStyleSettings().GetScreenZoom();
593 if ( nCurrentZoom
!= nPPTZoom
)
595 // Screen PPT values must be updated when ScreenZoom has changed.
596 // If called from Window::DataChanged, the window is passed as pDev,
597 // to make sure LogicToPixel uses a device which already uses the new zoom.
598 // For the initial settings, NULL is passed and GetDefaultDevice used.
601 pDev
= Application::GetDefaultDevice();
602 Point aPix1000
= pDev
->LogicToPixel( Point(1000,1000), MAP_TWIP
);
603 nScreenPPTX
= aPix1000
.X() / 1000.0;
604 nScreenPPTY
= aPix1000
.Y() / 1000.0;
605 nPPTZoom
= nCurrentZoom
;
609 const String
& ScGlobal::GetClipDocName()
611 return *pStrClipDocName
;
614 void ScGlobal::SetClipDocName( const String
& rNew
)
616 *pStrClipDocName
= rNew
;
620 void ScGlobal::InitTextHeight(SfxItemPool
* pPool
)
624 DBG_ERROR("kein Pool bei ScGlobal::InitTextHeight");
628 const ScPatternAttr
* pPattern
= (const ScPatternAttr
*)&pPool
->GetDefaultItem(ATTR_PATTERN
);
631 DBG_ERROR("kein Default-Pattern bei ScGlobal::InitTextHeight");
635 // String aTestString('X');
636 OutputDevice
* pDefaultDev
= Application::GetDefaultDevice();
637 VirtualDevice
aVirtWindow( *pDefaultDev
);
638 aVirtWindow
.SetMapMode(MAP_PIXEL
);
640 pPattern
->GetFont(aDefFont
, SC_AUTOCOL_BLACK
, &aVirtWindow
); // font color doesn't matter here
641 aVirtWindow
.SetFont(aDefFont
);
642 nDefFontHeight
= (USHORT
) aVirtWindow
.PixelToLogic(Size(0, aVirtWindow
.GetTextHeight()),
645 const SvxMarginItem
* pMargin
= (const SvxMarginItem
*)&pPattern
->GetItem(ATTR_MARGIN
);
647 nStdRowHeight
= (USHORT
) ( nDefFontHeight
+
648 pMargin
->GetTopMargin() + pMargin
->GetBottomMargin()
649 - STD_ROWHEIGHT_DIFF
);
652 void ScGlobal::Clear()
654 // asyncs _vor_ ExitExternalFunc zerstoeren!
655 theAddInAsyncTbl
.DeleteAndDestroy( 0, theAddInAsyncTbl
.Count() );
657 DELETEZ(pAutoFormat
);
658 DELETEZ(pSearchItem
);
659 DELETEZ(pFuncCollection
);
660 DELETEZ(pAddInCollection
);
663 for( USHORT nC
= 0 ; nC
< STR_COUNT
; nC
++ )
664 if( ppRscString
) delete ppRscString
[ nC
];
665 delete[] ppRscString
;
668 DELETEZ(pStarCalcFunctionList
); // vor ResMgr zerstoeren!
669 DELETEZ(pStarCalcFunctionMgr
);
670 ScParameterClassification::Exit();
671 ScCompiler::DeInit();
672 ScInterpreter::GlobalExit(); // statischen Stack loeschen
674 DELETEZ(pEmptyBrushItem
);
675 DELETEZ(pButtonBrushItem
);
676 DELETEZ(pEmbeddedBrushItem
);
677 DELETEZ(pProtectedBrushItem
);
678 DELETEZ(pOutlineBitmaps
);
679 DELETEZ(pOutlineBitmapsHC
);
680 // DELETEZ(pAnchorBitmap);
681 // DELETEZ(pGrayAnchorBitmap);
682 DELETEZ(pEnglishFormatter
);
683 DELETEZ(pCaseTransliteration
);
684 DELETEZ(pTransliteration
);
685 DELETEZ(pCaseCollator
);
688 //! do NOT delete pCharClass since it is a pointer to the single SvtSysLocale instance
690 //! do NOT delete pLocaleData since it is a pointer to the single SvtSysLocale instance
694 DELETEZ(pScIntlWrapper
);
695 DELETEZ(pStrClipDocName
);
697 DELETEZ(pUnitConverter
);
699 ScDocumentPool::DeleteVersionMaps();
701 DELETEZ(pEmptyString
);
704 //------------------------------------------------------------------------
707 CharSet
ScGlobal::GetCharsetValue( const String
& rCharSet
)
709 // new TextEncoding values
710 if ( CharClass::isAsciiNumeric( rCharSet
) )
712 sal_Int32 nVal
= rCharSet
.ToInt32();
713 if ( !nVal
|| nVal
== RTL_TEXTENCODING_DONTKNOW
)
714 return gsl_getSystemTextEncoding();
715 return (CharSet
) nVal
;
717 // old CharSet values for compatibility
718 else if (rCharSet
.EqualsIgnoreCaseAscii("ANSI") ) return RTL_TEXTENCODING_MS_1252
;
719 else if (rCharSet
.EqualsIgnoreCaseAscii("MAC") ) return RTL_TEXTENCODING_APPLE_ROMAN
;
720 else if (rCharSet
.EqualsIgnoreCaseAscii("IBMPC") ) return RTL_TEXTENCODING_IBM_850
;
721 else if (rCharSet
.EqualsIgnoreCaseAscii("IBMPC_437")) return RTL_TEXTENCODING_IBM_437
;
722 else if (rCharSet
.EqualsIgnoreCaseAscii("IBMPC_850")) return RTL_TEXTENCODING_IBM_850
;
723 else if (rCharSet
.EqualsIgnoreCaseAscii("IBMPC_860")) return RTL_TEXTENCODING_IBM_860
;
724 else if (rCharSet
.EqualsIgnoreCaseAscii("IBMPC_861")) return RTL_TEXTENCODING_IBM_861
;
725 else if (rCharSet
.EqualsIgnoreCaseAscii("IBMPC_863")) return RTL_TEXTENCODING_IBM_863
;
726 else if (rCharSet
.EqualsIgnoreCaseAscii("IBMPC_865")) return RTL_TEXTENCODING_IBM_865
;
727 // else if (rCharSet.EqualsIgnoreCaseAscii("SYSTEM") ) return gsl_getSystemTextEncoding();
728 else return gsl_getSystemTextEncoding();
731 //------------------------------------------------------------------------
734 String
ScGlobal::GetCharsetString( CharSet eVal
)
736 const sal_Char
* pChar
;
739 // old CharSet strings for compatibility
740 case RTL_TEXTENCODING_MS_1252
: pChar
= "ANSI"; break;
741 case RTL_TEXTENCODING_APPLE_ROMAN
: pChar
= "MAC"; break;
742 // IBMPC == IBMPC_850
743 case RTL_TEXTENCODING_IBM_437
: pChar
= "IBMPC_437"; break;
744 case RTL_TEXTENCODING_IBM_850
: pChar
= "IBMPC_850"; break;
745 case RTL_TEXTENCODING_IBM_860
: pChar
= "IBMPC_860"; break;
746 case RTL_TEXTENCODING_IBM_861
: pChar
= "IBMPC_861"; break;
747 case RTL_TEXTENCODING_IBM_863
: pChar
= "IBMPC_863"; break;
748 case RTL_TEXTENCODING_IBM_865
: pChar
= "IBMPC_865"; break;
749 case RTL_TEXTENCODING_DONTKNOW
: pChar
= "SYSTEM"; break;
750 // new string of TextEncoding value
752 return String::CreateFromInt32( eVal
);
754 return String::CreateFromAscii(pChar
);
757 //------------------------------------------------------------------------
759 bool ScGlobal::HasStarCalcFunctionList()
761 return ( pStarCalcFunctionList
!= NULL
);
764 ScFunctionList
* ScGlobal::GetStarCalcFunctionList()
766 if ( !pStarCalcFunctionList
)
767 pStarCalcFunctionList
= new ScFunctionList
;
769 return pStarCalcFunctionList
;
772 //------------------------------------------------------------------------
774 ScFunctionMgr
* ScGlobal::GetStarCalcFunctionMgr()
776 if ( !pStarCalcFunctionMgr
)
777 pStarCalcFunctionMgr
= new ScFunctionMgr
;
779 return pStarCalcFunctionMgr
;
782 void ScGlobal::ResetFunctionList()
784 // FunctionMgr has pointers into FunctionList, must also be updated
786 DELETEZ( pStarCalcFunctionMgr
);
787 DELETEZ( pStarCalcFunctionList
);
790 //------------------------------------------------------------------------
793 ScUnitConverter
* ScGlobal::GetUnitConverter()
795 if ( !pUnitConverter
)
796 pUnitConverter
= new ScUnitConverter
;
798 return pUnitConverter
;
802 //------------------------------------------------------------------------
805 const sal_Unicode
* ScGlobal::UnicodeStrChr( const sal_Unicode
* pStr
,
819 // ----------------------------------------------------------------------------
821 void ScGlobal::AddToken( String
& rTokenList
, const String
& rToken
, sal_Unicode cSep
, xub_StrLen nSepCount
, bool bForceSep
)
823 if( bForceSep
|| (rToken
.Len() && rTokenList
.Len()) )
824 rTokenList
.Expand( rTokenList
.Len() + nSepCount
, cSep
);
825 rTokenList
.Append( rToken
);
828 bool ScGlobal::IsQuoted( const String
& rString
, sal_Unicode cQuote
)
830 return (rString
.Len() >= 2) && (rString
.GetChar( 0 ) == cQuote
) && (rString
.GetChar( rString
.Len() - 1 ) == cQuote
);
833 void ScGlobal::AddQuotes( String
& rString
, sal_Unicode cQuote
, bool bEscapeEmbedded
)
838 pQ
[0] = pQ
[1] = cQuote
;
840 String
aQuotes( pQ
);
841 rString
.SearchAndReplaceAll( cQuote
, aQuotes
);
843 rString
.Insert( cQuote
, 0 ).Append( cQuote
);
846 void ScGlobal::EraseQuotes( String
& rString
, sal_Unicode cQuote
, bool bUnescapeEmbedded
)
848 if ( IsQuoted( rString
, cQuote
) )
850 rString
.Erase( rString
.Len() - 1 ).Erase( 0, 1 );
851 if (bUnescapeEmbedded
)
854 pQ
[0] = pQ
[1] = cQuote
;
856 String
aQuotes( pQ
);
857 rString
.SearchAndReplaceAll( aQuotes
, cQuote
);
862 xub_StrLen
ScGlobal::FindUnquoted( const String
& rString
, sal_Unicode cChar
, xub_StrLen nStart
, sal_Unicode cQuote
)
864 const sal_Unicode
* const pStart
= rString
.GetBuffer();
865 const sal_Unicode
* const pStop
= pStart
+ rString
.Len();
866 const sal_Unicode
* p
= pStart
+ nStart
;
867 bool bQuoted
= false;
870 if (*p
== cChar
&& !bQuoted
)
871 return sal::static_int_cast
< xub_StrLen
>( p
- pStart
);
872 else if (*p
== cQuote
)
876 else if (p
< pStop
-1 && *(p
+1) == cQuote
)
883 return STRING_NOTFOUND
;
886 const sal_Unicode
* ScGlobal::FindUnquoted( const sal_Unicode
* pString
, sal_Unicode cChar
, sal_Unicode cQuote
)
888 const sal_Unicode
* p
= pString
;
889 bool bQuoted
= false;
892 if (*p
== cChar
&& !bQuoted
)
894 else if (*p
== cQuote
)
898 else if (*(p
+1) == cQuote
)
908 //------------------------------------------------------------------------
910 BOOL
ScGlobal::EETextObjEqual( const EditTextObject
* pObj1
,
911 const EditTextObject
* pObj2
)
913 if ( pObj1
== pObj2
) // both empty or the same object
916 if ( pObj1
&& pObj2
)
918 // first test for equal text content
919 USHORT nParCount
= pObj1
->GetParagraphCount();
920 if ( nParCount
!= pObj2
->GetParagraphCount() )
922 for (USHORT nPar
=0; nPar
<nParCount
; nPar
++)
923 if ( pObj1
->GetText(nPar
) != pObj2
->GetText(nPar
) )
926 SvMemoryStream aStream1
;
927 SvMemoryStream aStream2
;
928 pObj1
->Store( aStream1
);
929 pObj2
->Store( aStream2
);
930 ULONG nSize
= aStream1
.Tell();
931 if ( aStream2
.Tell() == nSize
)
932 if ( !memcmp( aStream1
.GetData(), aStream2
.GetData(), (USHORT
) nSize
) )
939 void ScGlobal::OpenURL( const String
& rURL
, const String
& rTarget
)
941 // OpenURL wird immer ueber irgendwelche Umwege durch Mausklicks im GridWindow
942 // aufgerufen, darum stimmen pScActiveViewShell und nScClickMouseModifier.
944 SfxStringItem
aUrl( SID_FILE_NAME
, rURL
);
945 SfxStringItem
aTarget( SID_TARGETNAME
, rTarget
);
947 if ( nScClickMouseModifier
& KEY_MOD1
) // control-click -> into new window
949 String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("_blank")) );
951 SfxViewFrame
* pFrame
= NULL
;
953 if ( pScActiveViewShell
)
955 pFrame
= pScActiveViewShell
->GetViewFrame();
956 SfxMedium
* pMed
= pFrame
->GetObjectShell()->GetMedium();
958 aReferName
= pMed
->GetName();
961 SfxFrameItem
aFrm( SID_DOCFRAME
, pFrame
);
962 SfxStringItem
aReferer( SID_REFERER
, aReferName
);
964 SfxBoolItem
aNewView( SID_OPEN_NEW_VIEW
, FALSE
);
965 SfxBoolItem
aBrowsing( SID_BROWSE
, TRUE
);
967 // kein SID_SILENT mehr wegen Bug #42525# (war angeblich sowieso falsch)
969 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
971 pViewFrm
->GetDispatcher()->Execute( SID_OPENDOC
,
972 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
975 &aNewView
, &aBrowsing
,
979 //------------------------------------------------------------------------
981 BOOL
ScGlobal::IsSystemRTL()
983 return MsLangId::isRightToLeft( Application::GetSettings().GetLanguage() );
986 BYTE
ScGlobal::GetDefaultScriptType()
988 // Used when text contains only WEAK characters.
989 // Script type of office language is used then (same as GetEditDefaultLanguage,
990 // to get consistent behavior of text in simple cells and EditEngine,
991 // also same as GetAppLanguage() in Writer)
993 return (BYTE
) SvtLanguageOptions::GetScriptTypeOfLanguage( Application::GetSettings().GetLanguage() );
996 LanguageType
ScGlobal::GetEditDefaultLanguage()
998 // used for EditEngine::SetDefaultLanguage
1000 return Application::GetSettings().GetLanguage();
1003 USHORT
ScGlobal::GetScriptedWhichID( BYTE nScriptType
, USHORT nWhich
)
1005 switch ( nScriptType
)
1007 case SCRIPTTYPE_LATIN
:
1008 case SCRIPTTYPE_ASIAN
:
1009 case SCRIPTTYPE_COMPLEX
:
1010 break; // take exact matches
1011 default: // prefer one, first COMPLEX, then ASIAN
1012 if ( nScriptType
& SCRIPTTYPE_COMPLEX
)
1013 nScriptType
= SCRIPTTYPE_COMPLEX
;
1014 else if ( nScriptType
& SCRIPTTYPE_ASIAN
)
1015 nScriptType
= SCRIPTTYPE_ASIAN
;
1017 switch ( nScriptType
)
1019 case SCRIPTTYPE_COMPLEX
:
1025 nWhich
= ATTR_CTL_FONT
;
1027 case ATTR_FONT_HEIGHT
:
1028 case ATTR_CJK_FONT_HEIGHT
:
1029 nWhich
= ATTR_CTL_FONT_HEIGHT
;
1031 case ATTR_FONT_WEIGHT
:
1032 case ATTR_CJK_FONT_WEIGHT
:
1033 nWhich
= ATTR_CTL_FONT_WEIGHT
;
1035 case ATTR_FONT_POSTURE
:
1036 case ATTR_CJK_FONT_POSTURE
:
1037 nWhich
= ATTR_CTL_FONT_POSTURE
;
1042 case SCRIPTTYPE_ASIAN
:
1048 nWhich
= ATTR_CJK_FONT
;
1050 case ATTR_FONT_HEIGHT
:
1051 case ATTR_CTL_FONT_HEIGHT
:
1052 nWhich
= ATTR_CJK_FONT_HEIGHT
;
1054 case ATTR_FONT_WEIGHT
:
1055 case ATTR_CTL_FONT_WEIGHT
:
1056 nWhich
= ATTR_CJK_FONT_WEIGHT
;
1058 case ATTR_FONT_POSTURE
:
1059 case ATTR_CTL_FONT_POSTURE
:
1060 nWhich
= ATTR_CJK_FONT_POSTURE
;
1073 case ATTR_CTL_FONT_HEIGHT
:
1074 case ATTR_CJK_FONT_HEIGHT
:
1075 nWhich
= ATTR_FONT_HEIGHT
;
1077 case ATTR_CTL_FONT_WEIGHT
:
1078 case ATTR_CJK_FONT_WEIGHT
:
1079 nWhich
= ATTR_FONT_WEIGHT
;
1081 case ATTR_CTL_FONT_POSTURE
:
1082 case ATTR_CJK_FONT_POSTURE
:
1083 nWhich
= ATTR_FONT_POSTURE
;
1091 //------------------------------------------------------------------------
1093 void ScGlobal::AddLanguage( SfxItemSet
& rSet
, SvNumberFormatter
& rFormatter
)
1095 DBG_ASSERT( rSet
.GetItemState( ATTR_LANGUAGE_FORMAT
, FALSE
) == SFX_ITEM_DEFAULT
,
1096 "ScGlobal::AddLanguage - language already added");
1098 const SfxPoolItem
* pHardItem
;
1099 if ( rSet
.GetItemState( ATTR_VALUE_FORMAT
, FALSE
, &pHardItem
) == SFX_ITEM_SET
)
1101 const SvNumberformat
* pHardFormat
= rFormatter
.GetEntry(
1102 ((const SfxUInt32Item
*)pHardItem
)->GetValue() );
1104 ULONG nParentFmt
= 0; // pool default
1105 const SfxItemSet
* pParent
= rSet
.GetParent();
1107 nParentFmt
= ((const SfxUInt32Item
&)pParent
->Get( ATTR_VALUE_FORMAT
)).GetValue();
1108 const SvNumberformat
* pParFormat
= rFormatter
.GetEntry( nParentFmt
);
1110 if ( pHardFormat
&& pParFormat
&&
1111 (pHardFormat
->GetLanguage() != pParFormat
->GetLanguage()) )
1112 rSet
.Put( SvxLanguageItem( pHardFormat
->GetLanguage(), ATTR_LANGUAGE_FORMAT
) );
1120 //===================================================================
1121 // class ScFunctionList:
1122 //===================================================================
1124 //===================================================================
1126 // fuer temporaere Objekte zum Holen der Resourcen
1128 class ScFuncRes
: public Resource
1131 ScFuncRes( ResId
&, ScFuncDesc
*, bool & rbSuppressed
);
1137 //--------------------------------------------------------------------
1139 ScFuncRes::ScFuncRes( ResId
&aRes
, ScFuncDesc
* pDesc
, bool & rbSuppressed
)
1142 rbSuppressed
= (bool)GetNum();
1143 pDesc
->nCategory
= GetNum();
1144 pDesc
->nHelpId
= GetNum() + 32768; //! Hack, see scfuncs.src
1145 pDesc
->nArgCount
= GetNum();
1146 USHORT nArgs
= pDesc
->nArgCount
;
1147 if (nArgs
>= VAR_ARGS
)
1148 nArgs
-= VAR_ARGS
- 1;
1151 pDesc
->pDefArgFlags
= new ScFuncDesc::ParameterFlags
[nArgs
];
1152 for (USHORT i
= 0; i
< nArgs
; i
++)
1154 pDesc
->pDefArgFlags
[i
].bOptional
= (bool)GetNum();
1157 // Need to read the value from the resource even if nArgs==0 to advance the
1158 // resource position pointer, so this can't be in the if(nArgs) block above.
1159 USHORT nSuppressed
= GetNum();
1162 if (nSuppressed
> nArgs
)
1164 DBG_ERROR3( "ScFuncRes: suppressed parameters count mismatch on OpCode %u: suppressed %d > params %d",
1165 aRes
.GetId(), (int)nSuppressed
, (int)nArgs
);
1166 nSuppressed
= nArgs
; // sanitize
1168 for (USHORT i
=0; i
< nSuppressed
; ++i
)
1170 USHORT nParam
= GetNum();
1173 if (pDesc
->nArgCount
>= VAR_ARGS
&& nParam
== nArgs
-1)
1175 DBG_ERROR3( "ScFuncRes: VAR_ARGS parameters can't be suppressed, on OpCode %u: param %d == arg %d-1",
1176 aRes
.GetId(), (int)nParam
, (int)nArgs
);
1180 pDesc
->pDefArgFlags
[nParam
].bSuppress
= true;
1181 pDesc
->bHasSuppressedArgs
= true;
1186 DBG_ERROR3( "ScFuncRes: suppressed parameter exceeds count on OpCode %u: param %d >= args %d",
1187 aRes
.GetId(), (int)nParam
, (int)nArgs
);
1192 pDesc
->pFuncName
= new String( ScCompiler::GetNativeSymbol( static_cast<OpCode
>( aRes
.GetId())));
1193 pDesc
->pFuncDesc
= new String(ScResId(1));
1197 pDesc
->ppDefArgNames
= new String
*[nArgs
];
1198 pDesc
->ppDefArgDescs
= new String
*[nArgs
];
1199 for (USHORT i
= 0; i
< nArgs
; i
++)
1201 pDesc
->ppDefArgNames
[i
] = new String(ScResId(2*(i
+1) ));
1202 pDesc
->ppDefArgDescs
[i
] = new String(ScResId(2*(i
+1)+1));
1209 //------------------------------------------------------------------------
1211 USHORT
ScFuncRes::GetNum()
1213 return ReadShortRes();
1216 //=========================================================================
1218 // um an die protected von Resource ranzukommen
1219 class ScResourcePublisher
: public Resource
1222 void FreeResource() { Resource::FreeResource(); }
1224 ScResourcePublisher( const ScResId
& rId
) : Resource( rId
) {}
1225 ~ScResourcePublisher() { FreeResource(); }
1226 BOOL
IsAvailableRes( const ResId
& rId
) const
1227 { return Resource::IsAvailableRes( rId
); }
1232 ScFunctionList::ScFunctionList() :
1233 nMaxFuncNameLen ( 0 )
1235 ScFuncDesc
* pDesc
= NULL
;
1236 xub_StrLen nStrLen
= 0;
1237 FuncCollection
* pFuncColl
;
1239 USHORT nDescBlock
[] =
1241 RID_SC_FUNCTION_DESCRIPTIONS1
,
1242 RID_SC_FUNCTION_DESCRIPTIONS2
1244 const USHORT nBlocks
= sizeof(nDescBlock
) / sizeof(USHORT
);
1246 aFunctionList
.Clear();
1248 for ( USHORT k
= 0; k
< nBlocks
; k
++ )
1250 ::std::auto_ptr
<ScResourcePublisher
> pBlock( new ScResourcePublisher( ScResId( nDescBlock
[k
] ) ) );
1251 // Browse for all possible OpCodes. This is not the fastest method, but
1252 // otherwise the sub resources within the resource blocks and the
1253 // resource blocks themselfs would had to be ordered according to
1254 // OpCodes, which is utopian..
1255 for (i
= 0; i
<= SC_OPCODE_LAST_OPCODE_ID
; i
++)
1258 aRes
.SetRT(RSC_RESOURCE
);
1259 // Sub resource of OpCode available?
1260 if (pBlock
->IsAvailableRes(aRes
))
1262 pDesc
= new ScFuncDesc
;
1263 bool bSuppressed
= false;
1264 ScFuncRes
aSubRes( aRes
, pDesc
, bSuppressed
);
1265 // Instead of dealing with this exceptional case at 1001 places
1266 // we simply don't add an entirely suppressed function to the
1267 // list and delete it.
1273 aFunctionList
.Insert( pDesc
, LIST_APPEND
);
1275 nStrLen
= (*(pDesc
->pFuncName
)).Len();
1276 if (nStrLen
> nMaxFuncNameLen
)
1277 nMaxFuncNameLen
= nStrLen
;
1283 USHORT nNextId
= SC_OPCODE_LAST_OPCODE_ID
+ 1; // FuncID for AddIn functions
1285 // Auswertung AddIn-Liste
1286 String
aDefArgNameValue(RTL_CONSTASCII_STRINGPARAM("value"));
1287 String
aDefArgNameString(RTL_CONSTASCII_STRINGPARAM("string"));
1288 String
aDefArgNameValues(RTL_CONSTASCII_STRINGPARAM("values"));
1289 String
aDefArgNameStrings(RTL_CONSTASCII_STRINGPARAM("strings"));
1290 String
aDefArgNameCells(RTL_CONSTASCII_STRINGPARAM("cells"));
1291 String
aDefArgNameNone(RTL_CONSTASCII_STRINGPARAM("none"));
1292 String
aDefArgDescValue(RTL_CONSTASCII_STRINGPARAM("a value"));
1293 String
aDefArgDescString(RTL_CONSTASCII_STRINGPARAM("a string"));
1294 String
aDefArgDescValues(RTL_CONSTASCII_STRINGPARAM("array of values"));
1295 String
aDefArgDescStrings(RTL_CONSTASCII_STRINGPARAM("array of strings"));
1296 String
aDefArgDescCells(RTL_CONSTASCII_STRINGPARAM("range of cells"));
1297 String
aDefArgDescNone(RTL_CONSTASCII_STRINGPARAM("none"));
1298 String aArgName
, aArgDesc
;
1299 pFuncColl
= ScGlobal::GetFuncCollection();
1300 for (i
= 0; i
< pFuncColl
->GetCount(); i
++)
1302 pDesc
= new ScFuncDesc
;
1303 FuncData
*pAddInFuncData
= (FuncData
*)pFuncColl
->At(i
);
1304 USHORT nArgs
= pAddInFuncData
->GetParamCount() - 1;
1305 pAddInFuncData
->GetParamDesc( aArgName
, aArgDesc
, 0 );
1306 pDesc
->nFIndex
= nNextId
++; // ??? OpCode vergeben
1307 pDesc
->nCategory
= ID_FUNCTION_GRP_ADDINS
;
1308 pDesc
->pFuncName
= new String(pAddInFuncData
->GetInternalName());
1309 pDesc
->pFuncName
->ToUpperAscii();
1310 pDesc
->pFuncDesc
= new String( aArgDesc
);
1311 *(pDesc
->pFuncDesc
) += '\n';
1312 pDesc
->pFuncDesc
->AppendAscii(RTL_CONSTASCII_STRINGPARAM( "( AddIn: " ));
1313 *(pDesc
->pFuncDesc
) += pAddInFuncData
->GetModuleName();
1314 pDesc
->pFuncDesc
->AppendAscii(RTL_CONSTASCII_STRINGPARAM( " )" ));
1315 pDesc
->nArgCount
= nArgs
;
1318 pDesc
->pDefArgFlags
= new ScFuncDesc::ParameterFlags
[nArgs
];
1319 pDesc
->ppDefArgNames
= new String
*[nArgs
];
1320 pDesc
->ppDefArgDescs
= new String
*[nArgs
];
1321 for (j
= 0; j
< nArgs
; j
++)
1323 pDesc
->pDefArgFlags
[j
].bOptional
= false;
1324 pDesc
->pDefArgFlags
[j
].bSuppress
= false;
1325 pAddInFuncData
->GetParamDesc( aArgName
, aArgDesc
, j
+1 );
1326 if ( aArgName
.Len() )
1327 pDesc
->ppDefArgNames
[j
] = new String( aArgName
);
1330 switch (pAddInFuncData
->GetParamType(j
+1))
1333 pDesc
->ppDefArgNames
[j
] = new String( aDefArgNameValue
);
1336 pDesc
->ppDefArgNames
[j
] = new String( aDefArgNameString
);
1338 case PTR_DOUBLE_ARR
:
1339 pDesc
->ppDefArgNames
[j
] = new String( aDefArgNameValues
);
1341 case PTR_STRING_ARR
:
1342 pDesc
->ppDefArgNames
[j
] = new String( aDefArgNameStrings
);
1345 pDesc
->ppDefArgNames
[j
] = new String( aDefArgNameCells
);
1348 pDesc
->ppDefArgNames
[j
] = new String( aDefArgNameNone
);
1352 if ( aArgDesc
.Len() )
1353 pDesc
->ppDefArgDescs
[j
] = new String( aArgDesc
);
1356 switch (pAddInFuncData
->GetParamType(j
+1))
1359 pDesc
->ppDefArgDescs
[j
] = new String( aDefArgDescValue
);
1362 pDesc
->ppDefArgDescs
[j
] = new String( aDefArgDescString
);
1364 case PTR_DOUBLE_ARR
:
1365 pDesc
->ppDefArgDescs
[j
] = new String( aDefArgDescValues
);
1367 case PTR_STRING_ARR
:
1368 pDesc
->ppDefArgDescs
[j
] = new String( aDefArgDescStrings
);
1371 pDesc
->ppDefArgDescs
[j
] = new String( aDefArgDescCells
);
1374 pDesc
->ppDefArgDescs
[j
] = new String( aDefArgDescNone
);
1380 // pDesc->nHelpId = 0;
1382 aFunctionList
.Insert(pDesc
, LIST_APPEND
);
1383 nStrLen
= (*(pDesc
->pFuncName
)).Len();
1384 if ( nStrLen
> nMaxFuncNameLen
)
1385 nMaxFuncNameLen
= nStrLen
;
1390 ScUnoAddInCollection
* pUnoAddIns
= ScGlobal::GetAddInCollection();
1391 long nUnoCount
= pUnoAddIns
->GetFuncCount();
1392 for (long nFunc
=0; nFunc
<nUnoCount
; nFunc
++)
1394 pDesc
= new ScFuncDesc
;
1395 pDesc
->nFIndex
= nNextId
++;
1397 if ( pUnoAddIns
->FillFunctionDesc( nFunc
, *pDesc
) )
1399 aFunctionList
.Insert(pDesc
, LIST_APPEND
);
1400 nStrLen
= (*(pDesc
->pFuncName
)).Len();
1401 if (nStrLen
> nMaxFuncNameLen
)
1402 nMaxFuncNameLen
= nStrLen
;
1409 //------------------------------------------------------------------------
1411 ScFunctionList::~ScFunctionList()
1413 const ScFuncDesc
* pDesc
= First();
1422 //========================================================================
1423 // class ScFuncDesc:
1425 ScFuncDesc::ScFuncDesc() :
1428 ppDefArgNames (NULL
),
1429 ppDefArgDescs (NULL
),
1430 pDefArgFlags (NULL
),
1435 bIncomplete (false),
1436 bHasSuppressedArgs(false)
1439 //------------------------------------------------------------------------
1441 ScFuncDesc::~ScFuncDesc()
1446 //------------------------------------------------------------------------
1448 void ScFuncDesc::Clear()
1450 USHORT nArgs
= nArgCount
;
1451 if (nArgs
>= VAR_ARGS
) nArgs
-= VAR_ARGS
-1;
1454 for (USHORT i
=0; i
<nArgs
; i
++ )
1456 delete ppDefArgNames
[i
];
1457 delete ppDefArgDescs
[i
];
1459 delete [] ppDefArgNames
;
1460 delete [] ppDefArgDescs
;
1461 delete [] pDefArgFlags
;
1464 ppDefArgNames
= NULL
;
1465 ppDefArgDescs
= NULL
;
1466 pDefArgFlags
= NULL
;
1477 bIncomplete
= false;
1478 bHasSuppressedArgs
= false;
1481 //------------------------------------------------------------------------
1483 String
ScFuncDesc::GetParamList() const
1485 const String
& sep
= ScCompiler::GetNativeSymbol(ocSep
);
1489 if ( nArgCount
> 0 )
1491 if ( nArgCount
< VAR_ARGS
)
1493 USHORT nLastSuppressed
= nArgCount
;
1494 USHORT nLastAdded
= nArgCount
;
1495 for ( USHORT i
=0; i
<nArgCount
; i
++ )
1497 if (pDefArgFlags
[i
].bSuppress
)
1498 nLastSuppressed
= i
;
1502 aSig
+= *(ppDefArgNames
[i
]);
1503 if ( i
!= nArgCount
-1 )
1506 aSig
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " " ));
1510 // If only suppressed parameters follow the last added parameter,
1512 if (nLastSuppressed
< nArgCount
&& nLastAdded
< nLastSuppressed
&&
1514 aSig
.Erase( aSig
.Len() - 2 );
1518 USHORT nFix
= nArgCount
- VAR_ARGS
;
1519 for ( USHORT nArg
= 0; nArg
< nFix
; nArg
++ )
1521 if (!pDefArgFlags
[nArg
].bSuppress
)
1523 aSig
+= *(ppDefArgNames
[nArg
]);
1525 aSig
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " " ));
1528 /* NOTE: Currently there are no suppressed var args parameters. If
1529 * there were, we'd have to cope with it here and above for the fix
1530 * parameters. For now parameters are always added, so no special
1531 * treatment of a trailing "; " necessary. */
1532 aSig
+= *(ppDefArgNames
[nFix
]);
1535 aSig
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " " ));
1536 aSig
+= *(ppDefArgNames
[nFix
]);
1539 aSig
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " ... " ));
1546 //------------------------------------------------------------------------
1548 String
ScFuncDesc::GetSignature() const
1556 String
aParamList( GetParamList() );
1557 if( aParamList
.Len() )
1559 aSig
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "( " ));
1560 aSig
.Append( aParamList
);
1561 // U+00A0 (NBSP) prevents automatic line break
1562 aSig
.Append( static_cast< sal_Unicode
>(0xA0) ).Append( ')' );
1565 aSig
.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" ));
1570 //------------------------------------------------------------------------
1572 ::rtl::OUString
ScFuncDesc::getFormula( const ::std::vector
< ::rtl::OUString
>& _aArguments
) const
1574 const String
& sep
= ScCompiler::GetNativeSymbol(ocSep
);
1576 ::rtl::OUStringBuffer aFormula
;
1580 aFormula
.append( *pFuncName
);
1582 aFormula
.appendAscii( "(" );
1583 ::std::vector
< ::rtl::OUString
>::const_iterator aIter
= _aArguments
.begin();
1584 ::std::vector
< ::rtl::OUString
>::const_iterator aEnd
= _aArguments
.end();
1586 if ( nArgCount
> 0 && aIter
!= aEnd
)
1588 BOOL bLastArg
= ( aIter
->getLength() == 0 );
1590 while( aIter
!= aEnd
&& !bLastArg
)
1592 aFormula
.append( *(aIter
) );
1593 if ( aIter
!= (aEnd
-1) )
1595 bLastArg
= !( (aIter
+1)->getLength() > 0 );
1597 aFormula
.append( sep
);
1604 aFormula
.appendAscii( ")" );
1606 return aFormula
.makeStringAndClear();
1609 //------------------------------------------------------------------------
1611 USHORT
ScFuncDesc::GetSuppressedArgCount() const
1613 if (!bHasSuppressedArgs
|| !pDefArgFlags
)
1616 USHORT nArgs
= nArgCount
;
1617 if (nArgs
>= VAR_ARGS
)
1618 nArgs
-= VAR_ARGS
- 1;
1619 USHORT nCount
= nArgs
;
1620 for (USHORT i
=0; i
< nArgs
; ++i
)
1622 if (pDefArgFlags
[i
].bSuppress
)
1625 if (nArgCount
>= VAR_ARGS
)
1626 nCount
+= VAR_ARGS
- 1;
1630 //------------------------------------------------------------------------
1632 ::rtl::OUString
ScFuncDesc::getFunctionName() const
1634 ::rtl::OUString sRet
;
1639 // -----------------------------------------------------------------------------
1640 const formula::IFunctionCategory
* ScFuncDesc::getCategory() const
1642 return ScGlobal::GetStarCalcFunctionMgr()->getCategory(nCategory
);
1644 // -----------------------------------------------------------------------------
1645 ::rtl::OUString
ScFuncDesc::getDescription() const
1647 ::rtl::OUString sRet
;
1652 // -----------------------------------------------------------------------------
1653 // GetSuppressedArgCount
1654 xub_StrLen
ScFuncDesc::getSuppressedArgumentCount() const
1656 return GetSuppressedArgCount();
1658 // -----------------------------------------------------------------------------
1660 void ScFuncDesc::fillVisibleArgumentMapping(::std::vector
<USHORT
>& _rArguments
) const
1662 if (!bHasSuppressedArgs
|| !pDefArgFlags
)
1664 _rArguments
.resize( nArgCount
);
1665 ::std::iota( _rArguments
.begin(), _rArguments
.end(), 0);
1668 _rArguments
.reserve( nArgCount
);
1669 USHORT nArgs
= nArgCount
;
1670 if (nArgs
>= VAR_ARGS
)
1671 nArgs
-= VAR_ARGS
- 1;
1672 for (USHORT i
=0; i
< nArgs
; ++i
)
1674 if (!pDefArgFlags
[i
].bSuppress
)
1675 _rArguments
.push_back(i
);
1678 // -----------------------------------------------------------------------------
1679 void ScFuncDesc::initArgumentInfo() const
1681 // get the full argument description
1682 // (add-in has to be instantiated to get the type information)
1684 if ( bIncomplete
&& pFuncName
)
1686 ScUnoAddInCollection
& rAddIns
= *ScGlobal::GetAddInCollection();
1687 String aIntName
= rAddIns
.FindFunction( *pFuncName
, TRUE
); // pFuncName is upper-case
1689 if ( aIntName
.Len() )
1691 // GetFuncData with bComplete=true loads the component and updates
1692 // the global function list if needed.
1694 rAddIns
.GetFuncData( aIntName
, true );
1699 DBG_ERRORFILE( "couldn't initialize add-in function" );
1700 const_cast<ScFuncDesc
*>(this)->bIncomplete
= FALSE
; // even if there was an error, don't try again
1704 // -----------------------------------------------------------------------------
1705 ::rtl::OUString
ScFuncDesc::getSignature() const
1707 return GetSignature();
1709 // -----------------------------------------------------------------------------
1710 long ScFuncDesc::getHelpId() const
1714 // -----------------------------------------------------------------------------
1717 sal_uInt32
ScFuncDesc::getParameterCount() const
1721 // -----------------------------------------------------------------------------
1722 ::rtl::OUString
ScFuncDesc::getParameterName(sal_uInt32 _nPos
) const
1724 return *(ppDefArgNames
[_nPos
]);
1726 // -----------------------------------------------------------------------------
1727 ::rtl::OUString
ScFuncDesc::getParameterDescription(sal_uInt32 _nPos
) const
1729 return *(ppDefArgDescs
[_nPos
]);
1731 // -----------------------------------------------------------------------------
1732 bool ScFuncDesc::isParameterOptional(sal_uInt32 _nPos
) const
1734 return pDefArgFlags
[_nPos
].bOptional
;
1736 // -----------------------------------------------------------------------------
1737 //========================================================================
1738 // class ScFunctionMgr:
1740 ScFunctionMgr::ScFunctionMgr()
1741 : pFuncList ( ScGlobal::GetStarCalcFunctionList() ),
1742 pCurCatList ( NULL
)
1744 DBG_ASSERT( pFuncList
, "Funktionsliste nicht gefunden." );
1745 ULONG nCount
= pFuncList
->GetCount();
1746 const ScFuncDesc
* pDesc
;
1750 for ( USHORT i
=0; i
<MAX_FUNCCAT
; i
++ ) // Kategorie-Listen erstellen
1751 aCatLists
[i
] = new List
;
1753 pRootList
= aCatLists
[0]; // Gesamtliste ("Alle") erstellen
1754 CollatorWrapper
* pCaseCollator
= ScGlobal::GetCaseCollator();
1755 for ( n
=0; n
<nCount
; n
++ )
1758 pDesc
= pFuncList
->GetFunction(n
);
1759 for (nTmpCnt
= 0; nTmpCnt
< n
; nTmpCnt
++)
1761 // ist zwar case-sensitiv, aber Umlaute muessen richtig einsortiert werden
1763 const ScFuncDesc
* pTmpDesc
= (const ScFuncDesc
*)pRootList
->GetObject(nTmpCnt
);
1764 if ( pCaseCollator
->compareString(*pDesc
->pFuncName
, *pTmpDesc
->pFuncName
) == COMPARE_LESS
)
1767 pRootList
->Insert((void*)pDesc
, nTmpCnt
); // Einsortieren
1770 for ( n
=0; n
<nCount
; n
++ ) // in Gruppenlisten kopieren
1772 pDesc
= (const ScFuncDesc
*)pRootList
->GetObject(n
);
1773 DBG_ASSERT((pDesc
->nCategory
) < MAX_FUNCCAT
, "Unbekannte Kategorie");
1774 if ((pDesc
->nCategory
) < MAX_FUNCCAT
)
1775 aCatLists
[pDesc
->nCategory
]->Insert((void*)pDesc
, LIST_APPEND
);
1779 //------------------------------------------------------------------------
1781 ScFunctionMgr::~ScFunctionMgr()
1783 for (USHORT i
= 0; i
< MAX_FUNCCAT
; i
++)
1784 delete aCatLists
[i
];
1785 // delete pFuncList; // Macht spaeter die App
1788 //------------------------------------------------------------------------
1790 const ScFuncDesc
* ScFunctionMgr::Get( const String
& rFName
) const
1792 const ScFuncDesc
* pDesc
= NULL
;
1793 if (rFName
.Len() <= pFuncList
->GetMaxFuncNameLen())
1794 for (pDesc
= First(0); pDesc
; pDesc
= Next())
1795 if (rFName
.EqualsIgnoreCaseAscii(*(pDesc
->pFuncName
)))
1800 //------------------------------------------------------------------------
1802 const ScFuncDesc
* ScFunctionMgr::Get( USHORT nFIndex
) const
1804 const ScFuncDesc
* pDesc
;
1805 for (pDesc
= First(0); pDesc
; pDesc
= Next())
1806 if (pDesc
->nFIndex
== nFIndex
)
1811 //------------------------------------------------------------------------
1813 const ScFuncDesc
* ScFunctionMgr::First( USHORT nCategory
) const
1815 DBG_ASSERT( nCategory
< MAX_FUNCCAT
, "Unbekannte Kategorie" );
1817 if ( nCategory
< MAX_FUNCCAT
)
1819 pCurCatList
= aCatLists
[nCategory
];
1820 return (const ScFuncDesc
*)pCurCatList
->First();
1829 //------------------------------------------------------------------------
1831 const ScFuncDesc
* ScFunctionMgr::Next() const
1834 return (const ScFuncDesc
*)pCurCatList
->Next();
1838 sal_uInt32
ScFunctionMgr::getCount() const
1840 return MAX_FUNCCAT
- 1;
1842 const formula::IFunctionCategory
* ScFunctionMgr::getCategory(sal_uInt32 nCategory
) const
1844 formula::IFunctionCategory
* pRet
= NULL
;
1845 if ( nCategory
< (MAX_FUNCCAT
-1) )
1847 pRet
= new ScFunctionCategory(const_cast<ScFunctionMgr
*>(this),aCatLists
[nCategory
+1],nCategory
); // aCatLists[0] is "all"
1851 // -----------------------------------------------------------------------------
1852 const formula::IFunctionDescription
* ScFunctionMgr::getFunctionByName(const ::rtl::OUString
& _sFunctionName
) const
1854 return Get(_sFunctionName
);
1856 // -----------------------------------------------------------------------------
1857 void ScFunctionMgr::fillLastRecentlyUsedFunctions(::std::vector
< const formula::IFunctionDescription
*>& _rLastRUFunctions
) const
1861 const ScAppOptions
& rAppOpt
= SC_MOD()->GetAppOptions();
1862 USHORT nLRUFuncCount
= Min( rAppOpt
.GetLRUFuncListCount(), (USHORT
)LRU_MAX
);
1863 USHORT
* pLRUListIds
= rAppOpt
.GetLRUFuncList();
1867 for ( USHORT i
=0; i
<nLRUFuncCount
; i
++ )
1868 _rLastRUFunctions
.push_back( Get( pLRUListIds
[i
] ) );
1871 // -----------------------------------------------------------------------------
1872 String
ScFunctionMgr::GetCategoryName(sal_uInt32 _nCategoryNumber
)
1874 if ( _nCategoryNumber
> SC_FUNCGROUP_COUNT
)
1876 DBG_ERROR("Invalid category number!");
1878 } // if ( _nCategoryNumber >= SC_FUNCGROUP_COUNT )
1880 ::std::auto_ptr
<ScResourcePublisher
> pCategories( new ScResourcePublisher( ScResId( RID_FUNCTION_CATEGORIES
) ) );
1881 return String(ScResId((USHORT
)_nCategoryNumber
));
1883 sal_Unicode
ScFunctionMgr::getSingleToken(const formula::IFunctionManager::EToken _eToken
) const
1888 return ScCompiler::GetNativeSymbol(ocOpen
).GetChar(0);
1890 return ScCompiler::GetNativeSymbol(ocClose
).GetChar(0);
1892 return ScCompiler::GetNativeSymbol(ocSep
).GetChar(0);
1894 return ScCompiler::GetNativeSymbol(ocArrayOpen
).GetChar(0);
1896 return ScCompiler::GetNativeSymbol(ocArrayClose
).GetChar(0);
1897 } // switch(_eToken)
1900 // -----------------------------------------------------------------------------
1901 sal_uInt32
ScFunctionCategory::getCount() const
1903 return m_pCategory
->Count();
1905 // -----------------------------------------------------------------------------
1906 const formula::IFunctionManager
* ScFunctionCategory::getFunctionManager() const
1910 // -----------------------------------------------------------------------------
1911 ::rtl::OUString
ScFunctionCategory::getName() const
1913 if ( !m_sName
.getLength() )
1914 m_sName
= ScFunctionMgr::GetCategoryName(m_nCategory
+1);
1917 // -----------------------------------------------------------------------------
1918 const formula::IFunctionDescription
* ScFunctionCategory::getFunction(sal_uInt32 _nPos
) const
1920 const ScFuncDesc
* pDesc
= NULL
;
1922 for (pDesc
= (const ScFuncDesc
*)m_pCategory
->First(); i
< _nPos
&& pDesc
; pDesc
= (const ScFuncDesc
*)m_pCategory
->Next(),++i
)
1926 // -----------------------------------------------------------------------------
1927 sal_uInt32
ScFunctionCategory::getNumber() const
1931 // -----------------------------------------------------------------------------
1933 //------------------------------------------------------------------------
1935 utl::TransliterationWrapper
* ScGlobal::GetpTransliteration() //add by CHINA001
1937 if ( !pTransliteration
)
1939 const LanguageType eOfficeLanguage
= Application::GetSettings().GetLanguage();
1940 pTransliteration
= new ::utl::TransliterationWrapper(
1941 ::comphelper::getProcessServiceFactory(), SC_TRANSLITERATION_IGNORECASE
);
1942 pTransliteration
->loadModuleIfNeeded( eOfficeLanguage
);
1946 "ScGlobal::GetpTransliteration() called before ScGlobal::Init()");
1947 return pTransliteration
;
1950 const LocaleDataWrapper
* ScGlobal::GetpLocaleData()
1954 "ScGlobal::GetpLocaleData() called before ScGlobal::Init()");
1957 CalendarWrapper
* ScGlobal::GetCalendar()
1961 pCalendar
= new CalendarWrapper( ::comphelper::getProcessServiceFactory() );
1962 pCalendar
->loadDefaultCalendar( *GetLocale() );
1966 CollatorWrapper
* ScGlobal::GetCollator()
1970 pCollator
= new CollatorWrapper( ::comphelper::getProcessServiceFactory() );
1971 pCollator
->loadDefaultCollator( *GetLocale(), SC_COLLATOR_IGNORES
);
1972 } // if ( !pCollator )
1975 CollatorWrapper
* ScGlobal::GetCaseCollator()
1977 if ( !pCaseCollator
)
1979 pCaseCollator
= new CollatorWrapper( ::comphelper::getProcessServiceFactory() );
1980 pCaseCollator
->loadDefaultCollator( *GetLocale(), 0 );
1981 } // if ( !pCaseCollator )
1982 return pCaseCollator
;
1984 ::utl::TransliterationWrapper
* ScGlobal::GetCaseTransliteration()
1986 if ( !pCaseTransliteration
)
1988 const LanguageType eOfficeLanguage
= Application::GetSettings().GetLanguage();
1989 pCaseTransliteration
= new ::utl::TransliterationWrapper(::comphelper::getProcessServiceFactory(), SC_TRANSLITERATION_CASESENSE
);
1990 pCaseTransliteration
->loadModuleIfNeeded( eOfficeLanguage
);
1991 } // if ( !pCaseTransliteration )
1992 return pCaseTransliteration
;
1994 IntlWrapper
* ScGlobal::GetScIntlWrapper()
1996 if ( !pScIntlWrapper
)
1998 pScIntlWrapper
= new IntlWrapper( ::comphelper::getProcessServiceFactory(), *GetLocale() );
2000 return pScIntlWrapper
;
2002 ::com::sun::star::lang::Locale
* ScGlobal::GetLocale()
2006 pLocale
= new ::com::sun::star::lang::Locale( Application::GetSettings().GetLocale());