1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include "scitems.hxx"
32cdf0e10cSrcweir #include <svx/algitem.hxx>
33cdf0e10cSrcweir #include <editeng/brshitem.hxx>
34cdf0e10cSrcweir #include <editeng/editobj.hxx>
35cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
36cdf0e10cSrcweir #include <svl/srchitem.hxx>
37cdf0e10cSrcweir #include <editeng/langitem.hxx>
38cdf0e10cSrcweir #include <sfx2/docfile.hxx>
39cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
40cdf0e10cSrcweir #include <sfx2/objsh.hxx>
41cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
42cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
43cdf0e10cSrcweir #include <svl/stritem.hxx>
44cdf0e10cSrcweir #include <svl/zforlist.hxx>
45cdf0e10cSrcweir #include <svl/zformat.hxx>
46cdf0e10cSrcweir #include <vcl/image.hxx>
47cdf0e10cSrcweir #include <vcl/virdev.hxx>
48cdf0e10cSrcweir #include <tools/rcid.h>
49cdf0e10cSrcweir #include <unotools/charclass.hxx>
50cdf0e10cSrcweir #include <stdlib.h>
51cdf0e10cSrcweir #include <time.h>
52cdf0e10cSrcweir #include <ctype.h>
53cdf0e10cSrcweir #include <numeric>
54cdf0e10cSrcweir
55cdf0e10cSrcweir
56cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
57cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
58cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
59cdf0e10cSrcweir #include <unotools/calendarwrapper.hxx>
60cdf0e10cSrcweir #include <unotools/collatorwrapper.hxx>
61cdf0e10cSrcweir #include <com/sun/star/i18n/CollatorOptions.hpp>
62cdf0e10cSrcweir #include <unotools/intlwrapper.hxx>
63cdf0e10cSrcweir #include <unotools/syslocale.hxx>
64cdf0e10cSrcweir #include <unotools/transliterationwrapper.hxx>
65cdf0e10cSrcweir
66cdf0e10cSrcweir #include "global.hxx"
67cdf0e10cSrcweir #include "scresid.hxx"
68cdf0e10cSrcweir #include "autoform.hxx"
69cdf0e10cSrcweir #include "document.hxx"
70cdf0e10cSrcweir #include "patattr.hxx"
71cdf0e10cSrcweir #include "addincol.hxx"
72cdf0e10cSrcweir #include "adiasync.hxx"
73cdf0e10cSrcweir #include "userlist.hxx"
74cdf0e10cSrcweir #include "interpre.hxx"
75cdf0e10cSrcweir #include "strload.hxx"
76cdf0e10cSrcweir #include "docpool.hxx"
77cdf0e10cSrcweir #include "unitconv.hxx"
78cdf0e10cSrcweir #include "compiler.hxx"
79cdf0e10cSrcweir #include "parclass.hxx"
80cdf0e10cSrcweir #include "funcdesc.hxx"
81cdf0e10cSrcweir #include "globstr.hrc"
82cdf0e10cSrcweir #include "scfuncs.hrc"
83cdf0e10cSrcweir #include "sc.hrc"
84cdf0e10cSrcweir #include "scmod.hxx"
85cdf0e10cSrcweir #include "appoptio.hxx"
86cdf0e10cSrcweir
87cdf0e10cSrcweir // -----------------------------------------------------------------------
88cdf0e10cSrcweir
89cdf0e10cSrcweir #define CLIPST_AVAILABLE 0
90cdf0e10cSrcweir #define CLIPST_CAPTURED 1
91cdf0e10cSrcweir #define CLIPST_DELETE 2
92cdf0e10cSrcweir #define CLIPST_DRAW 3
93cdf0e10cSrcweir
94cdf0e10cSrcweir ScDocShellRef* ScGlobal::pDrawClipDocShellRef = NULL;
95cdf0e10cSrcweir SvxSearchItem* ScGlobal::pSearchItem = NULL;
96cdf0e10cSrcweir ScAutoFormat* ScGlobal::pAutoFormat = NULL;
97cdf0e10cSrcweir FuncCollection* ScGlobal::pFuncCollection = NULL;
98cdf0e10cSrcweir ScUnoAddInCollection* ScGlobal::pAddInCollection = NULL;
99cdf0e10cSrcweir ScUserList* ScGlobal::pUserList = NULL;
100cdf0e10cSrcweir String** ScGlobal::ppRscString = NULL;
101cdf0e10cSrcweir LanguageType ScGlobal::eLnge = LANGUAGE_SYSTEM;
102cdf0e10cSrcweir ::com::sun::star::lang::Locale* ScGlobal::pLocale = NULL;
103cdf0e10cSrcweir SvtSysLocale* ScGlobal::pSysLocale = NULL;
104cdf0e10cSrcweir const CharClass* ScGlobal::pCharClass = NULL;
105cdf0e10cSrcweir const LocaleDataWrapper* ScGlobal::pLocaleData = NULL;
106cdf0e10cSrcweir CalendarWrapper* ScGlobal::pCalendar = NULL;
107cdf0e10cSrcweir CollatorWrapper* ScGlobal::pCollator = NULL;
108cdf0e10cSrcweir CollatorWrapper* ScGlobal::pCaseCollator = NULL;
109cdf0e10cSrcweir ::utl::TransliterationWrapper* ScGlobal::pTransliteration = NULL;
110cdf0e10cSrcweir ::utl::TransliterationWrapper* ScGlobal::pCaseTransliteration = NULL;
111cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XOrdinalSuffix> ScGlobal::xOrdinalSuffix = NULL;
112cdf0e10cSrcweir IntlWrapper* ScGlobal::pScIntlWrapper = NULL;
113cdf0e10cSrcweir sal_Unicode ScGlobal::cListDelimiter = ',';
114cdf0e10cSrcweir String* ScGlobal::pEmptyString = NULL;
115cdf0e10cSrcweir String* ScGlobal::pStrClipDocName = NULL;
116cdf0e10cSrcweir
117cdf0e10cSrcweir SvxBrushItem* ScGlobal::pEmptyBrushItem = NULL;
118cdf0e10cSrcweir SvxBrushItem* ScGlobal::pButtonBrushItem = NULL;
119cdf0e10cSrcweir SvxBrushItem* ScGlobal::pEmbeddedBrushItem = NULL;
120cdf0e10cSrcweir SvxBrushItem* ScGlobal::pProtectedBrushItem = NULL;
121cdf0e10cSrcweir
122cdf0e10cSrcweir ImageList* ScGlobal::pOutlineBitmaps = NULL;
123cdf0e10cSrcweir ImageList* ScGlobal::pOutlineBitmapsHC = NULL;
124cdf0e10cSrcweir
125cdf0e10cSrcweir ScFunctionList* ScGlobal::pStarCalcFunctionList = NULL;
126cdf0e10cSrcweir ScFunctionMgr* ScGlobal::pStarCalcFunctionMgr = NULL;
127cdf0e10cSrcweir
128cdf0e10cSrcweir ScUnitConverter* ScGlobal::pUnitConverter = NULL;
129cdf0e10cSrcweir SvNumberFormatter* ScGlobal::pEnglishFormatter = NULL;
130cdf0e10cSrcweir
131cdf0e10cSrcweir double ScGlobal::nScreenPPTX = 96.0;
132cdf0e10cSrcweir double ScGlobal::nScreenPPTY = 96.0;
133cdf0e10cSrcweir
134cdf0e10cSrcweir sal_uInt16 ScGlobal::nDefFontHeight = 240;
135cdf0e10cSrcweir sal_uInt16 ScGlobal::nStdRowHeight = 257;
136cdf0e10cSrcweir
137cdf0e10cSrcweir long ScGlobal::nLastRowHeightExtra = 0;
138cdf0e10cSrcweir long ScGlobal::nLastColWidthExtra = STD_EXTRA_WIDTH;
139cdf0e10cSrcweir
140cdf0e10cSrcweir static sal_uInt16 nPPTZoom = 0; // ScreenZoom used to determine nScreenPPTX/Y
141cdf0e10cSrcweir
142cdf0e10cSrcweir
143cdf0e10cSrcweir class SfxViewShell;
144cdf0e10cSrcweir SfxViewShell* pScActiveViewShell = NULL; //! als Member !!!!!
145cdf0e10cSrcweir sal_uInt16 nScClickMouseModifier = 0; //! dito
146cdf0e10cSrcweir sal_uInt16 nScFillModeMouseModifier = 0; //! dito
147cdf0e10cSrcweir
148cdf0e10cSrcweir // Hack: ScGlobal::GetUserList() muss InitAppOptions in der UI aufrufen,
149cdf0e10cSrcweir // damit UserList aus Cfg geladen wird
150cdf0e10cSrcweir
151cdf0e10cSrcweir void global_InitAppOptions();
152cdf0e10cSrcweir
153cdf0e10cSrcweir //========================================================================
154cdf0e10cSrcweir //
155cdf0e10cSrcweir // statische Funktionen
156cdf0e10cSrcweir //
157cdf0e10cSrcweir //========================================================================
158cdf0e10cSrcweir
HasAttrChanged(const SfxItemSet & rNewAttrs,const SfxItemSet & rOldAttrs,const sal_uInt16 nWhich)159cdf0e10cSrcweir sal_Bool ScGlobal::HasAttrChanged( const SfxItemSet& rNewAttrs,
160cdf0e10cSrcweir const SfxItemSet& rOldAttrs,
161cdf0e10cSrcweir const sal_uInt16 nWhich )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir sal_Bool bInvalidate = sal_False;
164cdf0e10cSrcweir const SfxItemState eNewState = rNewAttrs.GetItemState( nWhich );
165cdf0e10cSrcweir const SfxItemState eOldState = rOldAttrs.GetItemState( nWhich );
166cdf0e10cSrcweir
167cdf0e10cSrcweir //----------------------------------------------------------
168cdf0e10cSrcweir
169cdf0e10cSrcweir if ( eNewState == eOldState )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir // beide Items gesetzt
172cdf0e10cSrcweir // PoolItems, d.h. Pointer-Vergleich zulaessig
173cdf0e10cSrcweir if ( SFX_ITEM_SET == eOldState )
174cdf0e10cSrcweir bInvalidate = (&rNewAttrs.Get( nWhich ) != &rOldAttrs.Get( nWhich ));
175cdf0e10cSrcweir }
176cdf0e10cSrcweir else
177cdf0e10cSrcweir {
178cdf0e10cSrcweir // ein Default-Item dabei
179cdf0e10cSrcweir // PoolItems, d.h. Item-Vergleich noetig
180cdf0e10cSrcweir
181cdf0e10cSrcweir const SfxPoolItem& rOldItem = ( SFX_ITEM_SET == eOldState )
182cdf0e10cSrcweir ? rOldAttrs.Get( nWhich )
183cdf0e10cSrcweir : rOldAttrs.GetPool()->GetDefaultItem( nWhich );
184cdf0e10cSrcweir
185cdf0e10cSrcweir const SfxPoolItem& rNewItem = ( SFX_ITEM_SET == eNewState )
186cdf0e10cSrcweir ? rNewAttrs.Get( nWhich )
187cdf0e10cSrcweir : rNewAttrs.GetPool()->GetDefaultItem( nWhich );
188cdf0e10cSrcweir
189cdf0e10cSrcweir bInvalidate = sal::static_int_cast<sal_Bool>(rNewItem != rOldItem);
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir return bInvalidate;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
GetStandardFormat(SvNumberFormatter & rFormatter,sal_uLong nFormat,short nType)195cdf0e10cSrcweir sal_uLong ScGlobal::GetStandardFormat( SvNumberFormatter& rFormatter,
196cdf0e10cSrcweir sal_uLong nFormat, short nType )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir const SvNumberformat* pFormat = rFormatter.GetEntry( nFormat );
199cdf0e10cSrcweir if ( pFormat )
200cdf0e10cSrcweir return rFormatter.GetStandardFormat( nFormat, nType, pFormat->GetLanguage() );
201cdf0e10cSrcweir return rFormatter.GetStandardFormat( nType, eLnge );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
GetStandardFormat(double fNumber,SvNumberFormatter & rFormatter,sal_uLong nFormat,short nType)204cdf0e10cSrcweir sal_uLong ScGlobal::GetStandardFormat( double fNumber, SvNumberFormatter& rFormatter,
205cdf0e10cSrcweir sal_uLong nFormat, short nType )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir const SvNumberformat* pFormat = rFormatter.GetEntry( nFormat );
208cdf0e10cSrcweir if ( pFormat )
209cdf0e10cSrcweir return rFormatter.GetStandardFormat( fNumber, nFormat, nType,
210cdf0e10cSrcweir pFormat->GetLanguage() );
211cdf0e10cSrcweir return rFormatter.GetStandardFormat( nType, eLnge );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir
215cdf0e10cSrcweir // static
GetEnglishFormatter()216cdf0e10cSrcweir SvNumberFormatter* ScGlobal::GetEnglishFormatter()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir if ( !pEnglishFormatter )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir pEnglishFormatter = new SvNumberFormatter(
221cdf0e10cSrcweir ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US );
222cdf0e10cSrcweir pEnglishFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_INTL_FORMAT );
223cdf0e10cSrcweir }
224cdf0e10cSrcweir return pEnglishFormatter;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir
228cdf0e10cSrcweir //------------------------------------------------------------------------
229cdf0e10cSrcweir
CheckWidthInvalidate(sal_Bool & bNumFormatChanged,const SfxItemSet & rNewAttrs,const SfxItemSet & rOldAttrs)230cdf0e10cSrcweir sal_Bool ScGlobal::CheckWidthInvalidate( sal_Bool& bNumFormatChanged,
231cdf0e10cSrcweir const SfxItemSet& rNewAttrs,
232cdf0e10cSrcweir const SfxItemSet& rOldAttrs )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir // Ueberpruefen, ob Attributaenderungen in rNewAttrs gegnueber
235cdf0e10cSrcweir // rOldAttrs die Textbreite an einer Zelle ungueltig machen
236cdf0e10cSrcweir
237cdf0e10cSrcweir bNumFormatChanged =
238cdf0e10cSrcweir HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_VALUE_FORMAT );
239cdf0e10cSrcweir return ( bNumFormatChanged
240cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_LANGUAGE_FORMAT )
241cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT )
242cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT )
243cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT )
244cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_HEIGHT )
245cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_HEIGHT )
246cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_HEIGHT )
247cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_WEIGHT )
248cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_WEIGHT )
249cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_WEIGHT )
250cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_POSTURE )
251cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_POSTURE )
252cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_POSTURE )
253cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_UNDERLINE )
254cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_OVERLINE )
255cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_CROSSEDOUT )
256cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_CONTOUR )
257cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_SHADOWED )
258cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_STACKED )
259cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_ROTATE_VALUE )
260cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_ROTATE_MODE )
261cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_LINEBREAK )
262cdf0e10cSrcweir || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_MARGIN )
263cdf0e10cSrcweir );
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
GetSearchItem()266cdf0e10cSrcweir const SvxSearchItem& ScGlobal::GetSearchItem()
267cdf0e10cSrcweir {
268cdf0e10cSrcweir if (!pSearchItem)
269cdf0e10cSrcweir {
270cdf0e10cSrcweir pSearchItem = new SvxSearchItem( SID_SEARCH_ITEM );
271cdf0e10cSrcweir pSearchItem->SetAppFlag( SVX_SEARCHAPP_CALC );
272cdf0e10cSrcweir }
273cdf0e10cSrcweir return *pSearchItem;
274cdf0e10cSrcweir }
275cdf0e10cSrcweir
SetSearchItem(const SvxSearchItem & rNew)276cdf0e10cSrcweir void ScGlobal::SetSearchItem( const SvxSearchItem& rNew )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir // Hier waere ein Zuweisungsoperator ganz nett:
279cdf0e10cSrcweir delete pSearchItem;
280cdf0e10cSrcweir pSearchItem = (SvxSearchItem*)rNew.Clone();
281cdf0e10cSrcweir
282cdf0e10cSrcweir pSearchItem->SetWhich( SID_SEARCH_ITEM );
283cdf0e10cSrcweir pSearchItem->SetAppFlag( SVX_SEARCHAPP_CALC );
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
ClearAutoFormat()286cdf0e10cSrcweir void ScGlobal::ClearAutoFormat()
287cdf0e10cSrcweir {
288cdf0e10cSrcweir if (pAutoFormat!=NULL)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir delete pAutoFormat;
291cdf0e10cSrcweir pAutoFormat=NULL;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir }
294cdf0e10cSrcweir
GetAutoFormat()295cdf0e10cSrcweir ScAutoFormat* ScGlobal::GetAutoFormat()
296cdf0e10cSrcweir {
297cdf0e10cSrcweir if ( !pAutoFormat )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir pAutoFormat = new ScAutoFormat;
300cdf0e10cSrcweir pAutoFormat->Load();
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir return pAutoFormat;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
GetFuncCollection()306cdf0e10cSrcweir FuncCollection* ScGlobal::GetFuncCollection()
307cdf0e10cSrcweir {
308cdf0e10cSrcweir if (!pFuncCollection)
309cdf0e10cSrcweir pFuncCollection = new FuncCollection();
310cdf0e10cSrcweir return pFuncCollection;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
GetAddInCollection()313cdf0e10cSrcweir ScUnoAddInCollection* ScGlobal::GetAddInCollection()
314cdf0e10cSrcweir {
315cdf0e10cSrcweir if (!pAddInCollection)
316cdf0e10cSrcweir pAddInCollection = new ScUnoAddInCollection();
317cdf0e10cSrcweir return pAddInCollection;
318cdf0e10cSrcweir }
319cdf0e10cSrcweir
GetUserList()320cdf0e10cSrcweir ScUserList* ScGlobal::GetUserList()
321cdf0e10cSrcweir {
322cdf0e10cSrcweir // Hack: Cfg-Item an der App ggF. laden
323cdf0e10cSrcweir
324cdf0e10cSrcweir global_InitAppOptions();
325cdf0e10cSrcweir
326cdf0e10cSrcweir if (!pUserList)
327cdf0e10cSrcweir pUserList = new ScUserList();
328cdf0e10cSrcweir return pUserList;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
SetUserList(const ScUserList * pNewList)331cdf0e10cSrcweir void ScGlobal::SetUserList( const ScUserList* pNewList )
332cdf0e10cSrcweir {
333cdf0e10cSrcweir if ( pNewList )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir if ( !pUserList )
336cdf0e10cSrcweir pUserList = new ScUserList( *pNewList );
337cdf0e10cSrcweir else
338cdf0e10cSrcweir *pUserList = *pNewList;
339cdf0e10cSrcweir }
340cdf0e10cSrcweir else
341cdf0e10cSrcweir {
342cdf0e10cSrcweir delete pUserList;
343cdf0e10cSrcweir pUserList = NULL;
344cdf0e10cSrcweir }
345cdf0e10cSrcweir }
346cdf0e10cSrcweir
GetRscString(sal_uInt16 nIndex)347cdf0e10cSrcweir const String& ScGlobal::GetRscString( sal_uInt16 nIndex )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir DBG_ASSERT( nIndex < STR_COUNT, "ScGlobal::GetRscString - invalid string index");
350cdf0e10cSrcweir if( !ppRscString[ nIndex ] )
351cdf0e10cSrcweir {
352cdf0e10cSrcweir OpCode eOp = ocNone;
353cdf0e10cSrcweir // Map former globstr.src strings moved to compiler.src
354cdf0e10cSrcweir switch (nIndex)
355cdf0e10cSrcweir {
356cdf0e10cSrcweir case STR_NULL_ERROR:
357cdf0e10cSrcweir eOp = ocErrNull;
358cdf0e10cSrcweir break;
359cdf0e10cSrcweir case STR_DIV_ZERO:
360cdf0e10cSrcweir eOp = ocErrDivZero;
361cdf0e10cSrcweir break;
362cdf0e10cSrcweir case STR_NO_VALUE:
363cdf0e10cSrcweir eOp = ocErrValue;
364cdf0e10cSrcweir break;
365cdf0e10cSrcweir case STR_NOREF_STR:
366cdf0e10cSrcweir eOp = ocErrRef;
367cdf0e10cSrcweir break;
368cdf0e10cSrcweir case STR_NO_NAME_REF:
369cdf0e10cSrcweir eOp = ocErrName;
370cdf0e10cSrcweir break;
371cdf0e10cSrcweir case STR_NUM_ERROR:
372cdf0e10cSrcweir eOp = ocErrNum;
373cdf0e10cSrcweir break;
374cdf0e10cSrcweir case STR_NV_STR:
375cdf0e10cSrcweir eOp = ocErrNA;
376cdf0e10cSrcweir break;
377cdf0e10cSrcweir default:
378cdf0e10cSrcweir ; // nothing
379cdf0e10cSrcweir }
380cdf0e10cSrcweir if (eOp != ocNone)
381cdf0e10cSrcweir ppRscString[ nIndex ] = new String(
382cdf0e10cSrcweir ScCompiler::GetNativeSymbol( eOp));
383cdf0e10cSrcweir else
384cdf0e10cSrcweir ppRscString[ nIndex ] = new String(
385cdf0e10cSrcweir ScRscStrLoader( RID_GLOBSTR, nIndex ).GetString());
386cdf0e10cSrcweir }
387cdf0e10cSrcweir return *ppRscString[ nIndex ];
388cdf0e10cSrcweir }
389cdf0e10cSrcweir
GetErrorString(sal_uInt16 nErrNumber)390cdf0e10cSrcweir String ScGlobal::GetErrorString(sal_uInt16 nErrNumber)
391cdf0e10cSrcweir {
392cdf0e10cSrcweir String sResStr;
393cdf0e10cSrcweir switch (nErrNumber)
394cdf0e10cSrcweir {
395cdf0e10cSrcweir case NOTAVAILABLE : nErrNumber = STR_NV_STR; break;
396cdf0e10cSrcweir case errNoRef : nErrNumber = STR_NO_REF_TABLE; break;
397cdf0e10cSrcweir case errNoName : nErrNumber = STR_NO_NAME_REF; break;
398cdf0e10cSrcweir case errNoAddin : nErrNumber = STR_NO_ADDIN; break;
399cdf0e10cSrcweir case errNoMacro : nErrNumber = STR_NO_MACRO; break;
400cdf0e10cSrcweir case errDoubleRef :
401cdf0e10cSrcweir case errNoValue : nErrNumber = STR_NO_VALUE; break;
402cdf0e10cSrcweir case errNoCode : nErrNumber = STR_NULL_ERROR; break;
403cdf0e10cSrcweir case errDivisionByZero : nErrNumber = STR_DIV_ZERO; break;
404cdf0e10cSrcweir case errIllegalFPOperation : nErrNumber = STR_NUM_ERROR; break;
405cdf0e10cSrcweir
406cdf0e10cSrcweir default : sResStr = GetRscString(STR_ERROR_STR);
407cdf0e10cSrcweir sResStr += String::CreateFromInt32( nErrNumber );
408cdf0e10cSrcweir nErrNumber = 0;
409cdf0e10cSrcweir break;
410cdf0e10cSrcweir }
411cdf0e10cSrcweir if( nErrNumber )
412cdf0e10cSrcweir sResStr = GetRscString( nErrNumber );
413cdf0e10cSrcweir return sResStr;
414cdf0e10cSrcweir }
415cdf0e10cSrcweir
GetLongErrorString(sal_uInt16 nErrNumber)416cdf0e10cSrcweir String ScGlobal::GetLongErrorString(sal_uInt16 nErrNumber)
417cdf0e10cSrcweir {
418cdf0e10cSrcweir switch (nErrNumber)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir case 0:
421cdf0e10cSrcweir break;
422cdf0e10cSrcweir case 1:
423cdf0e10cSrcweir case errIllegalArgument:
424cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_ILL_ARG;
425cdf0e10cSrcweir break;
426cdf0e10cSrcweir case 2:
427cdf0e10cSrcweir case 3:
428cdf0e10cSrcweir case 4:
429cdf0e10cSrcweir case 5:
430cdf0e10cSrcweir case errIllegalFPOperation:
431cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_ILL_FPO;
432cdf0e10cSrcweir break;
433cdf0e10cSrcweir case errIllegalChar:
434cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_ILL_CHAR;
435cdf0e10cSrcweir break;
436cdf0e10cSrcweir case errIllegalParameter:
437cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_ILL_PAR;
438cdf0e10cSrcweir break;
439cdf0e10cSrcweir case errSeparator:
440cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_ILL_SEP;
441cdf0e10cSrcweir break;
442cdf0e10cSrcweir case errPair:
443cdf0e10cSrcweir case errPairExpected:
444cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_PAIR;
445cdf0e10cSrcweir break;
446cdf0e10cSrcweir case errOperatorExpected:
447cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_OP_EXP;
448cdf0e10cSrcweir break;
449cdf0e10cSrcweir case errVariableExpected:
450cdf0e10cSrcweir case errParameterExpected:
451cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_VAR_EXP;
452cdf0e10cSrcweir break;
453cdf0e10cSrcweir case errCodeOverflow:
454cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_CODE_OVF;
455cdf0e10cSrcweir break;
456cdf0e10cSrcweir case errStringOverflow:
457cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_STR_OVF;
458cdf0e10cSrcweir break;
459cdf0e10cSrcweir case errStackOverflow:
460cdf0e10cSrcweir case errInterpOverflow:
461cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_STACK_OVF;
462cdf0e10cSrcweir break;
463cdf0e10cSrcweir case errIllegalJump:
464cdf0e10cSrcweir case errUnknownState:
465cdf0e10cSrcweir case errUnknownVariable:
466cdf0e10cSrcweir case errUnknownOpCode:
467cdf0e10cSrcweir case errUnknownStackVariable:
468cdf0e10cSrcweir case errUnknownToken:
469cdf0e10cSrcweir case errNoCode:
470cdf0e10cSrcweir case errDoubleRef:
471cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_SYNTAX;
472cdf0e10cSrcweir break;
473cdf0e10cSrcweir case errCircularReference:
474cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_CIRC_REF;
475cdf0e10cSrcweir break;
476cdf0e10cSrcweir case errNoConvergence:
477cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_NO_CONV;
478cdf0e10cSrcweir break;
479cdf0e10cSrcweir case errNoRef:
480cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_NO_REF;
481cdf0e10cSrcweir break;
482cdf0e10cSrcweir case errNoName:
483cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_NO_NAME;
484cdf0e10cSrcweir break;
485cdf0e10cSrcweir case errNoAddin:
486cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_NO_ADDIN;
487cdf0e10cSrcweir break;
488cdf0e10cSrcweir case errNoMacro:
489cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_NO_MACRO;
490cdf0e10cSrcweir break;
491cdf0e10cSrcweir case errDivisionByZero:
492cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_DIV_ZERO;
493cdf0e10cSrcweir break;
494cdf0e10cSrcweir case errNestedArray:
495cdf0e10cSrcweir nErrNumber = STR_ERR_LONG_NESTED_ARRAY;
496cdf0e10cSrcweir break;
497cdf0e10cSrcweir case errNoValue:
498cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_NO_VALUE;
499cdf0e10cSrcweir break;
500cdf0e10cSrcweir case NOTAVAILABLE:
501cdf0e10cSrcweir nErrNumber = STR_LONG_ERR_NV;
502cdf0e10cSrcweir break;
503cdf0e10cSrcweir default:
504cdf0e10cSrcweir nErrNumber = STR_ERROR_STR;
505cdf0e10cSrcweir break;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir String aRes( GetRscString( nErrNumber ) );
508cdf0e10cSrcweir return aRes;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir
GetButtonBrushItem()511cdf0e10cSrcweir SvxBrushItem* ScGlobal::GetButtonBrushItem()
512cdf0e10cSrcweir {
513cdf0e10cSrcweir pButtonBrushItem->SetColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
514cdf0e10cSrcweir return pButtonBrushItem;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir
GetEmptyString()517cdf0e10cSrcweir const String& ScGlobal::GetEmptyString()
518cdf0e10cSrcweir {
519cdf0e10cSrcweir return *pEmptyString;
520cdf0e10cSrcweir }
521cdf0e10cSrcweir
GetOutlineSymbols(bool bHC)522cdf0e10cSrcweir ImageList* ScGlobal::GetOutlineSymbols( bool bHC )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir ImageList*& rpImageList = bHC ? pOutlineBitmapsHC : pOutlineBitmaps;
525cdf0e10cSrcweir if( !rpImageList )
526cdf0e10cSrcweir rpImageList = new ImageList( ScResId( bHC ? RID_OUTLINEBITMAPS_H : RID_OUTLINEBITMAPS ) );
527cdf0e10cSrcweir return rpImageList;
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
Init()530cdf0e10cSrcweir void ScGlobal::Init()
531cdf0e10cSrcweir {
532cdf0e10cSrcweir pEmptyString = new String;
533cdf0e10cSrcweir
534cdf0e10cSrcweir // Die Default-Sprache fuer Zahlenformate (ScGlobal::eLnge)
535cdf0e10cSrcweir // muss immer LANGUAGE_SYSTEM sein
536cdf0e10cSrcweir //! Dann kann auch die Variable raus
537cdf0e10cSrcweir eLnge = LANGUAGE_SYSTEM;
538cdf0e10cSrcweir
539cdf0e10cSrcweir //! Wenn Sortierung etc. von der Sprache der installierten Offfice-Version
540cdf0e10cSrcweir //! abhaengen sollen, hier "Application::GetSettings().GetUILanguage()"
541cdf0e10cSrcweir pSysLocale = new SvtSysLocale;
542cdf0e10cSrcweir pCharClass = pSysLocale->GetCharClassPtr();
543cdf0e10cSrcweir pLocaleData = pSysLocale->GetLocaleDataPtr();
544cdf0e10cSrcweir
545cdf0e10cSrcweir ppRscString = new String *[ STR_COUNT ];
546cdf0e10cSrcweir for( sal_uInt16 nC = 0 ; nC < STR_COUNT ; nC++ ) ppRscString[ nC ] = NULL;
547cdf0e10cSrcweir
548cdf0e10cSrcweir pEmptyBrushItem = new SvxBrushItem( Color( COL_TRANSPARENT ), ATTR_BACKGROUND );
549cdf0e10cSrcweir pButtonBrushItem = new SvxBrushItem( Color(), ATTR_BACKGROUND );
550cdf0e10cSrcweir pEmbeddedBrushItem = new SvxBrushItem( Color( COL_LIGHTCYAN ), ATTR_BACKGROUND );
551cdf0e10cSrcweir pProtectedBrushItem = new SvxBrushItem( Color( COL_LIGHTGRAY ), ATTR_BACKGROUND );
552cdf0e10cSrcweir
553cdf0e10cSrcweir UpdatePPT(NULL);
554cdf0e10cSrcweir //ScCompiler::InitSymbolsNative();
555cdf0e10cSrcweir // ScParameterClassification _after_ Compiler, needs function resources if
556cdf0e10cSrcweir // arguments are to be merged in, which in turn need strings of function
557cdf0e10cSrcweir // names from the compiler.
558cdf0e10cSrcweir ScParameterClassification::Init();
559cdf0e10cSrcweir srand( (unsigned) time( NULL ) ); // Random Seed Init fuer Interpreter
560cdf0e10cSrcweir
561cdf0e10cSrcweir InitAddIns();
562cdf0e10cSrcweir
563cdf0e10cSrcweir pStrClipDocName = new String( ScResId( SCSTR_NONAME ) );
564cdf0e10cSrcweir *pStrClipDocName += '1';
565cdf0e10cSrcweir
566cdf0e10cSrcweir // ScDocumentPool::InitVersionMaps() ist schon vorher gerufen worden
567cdf0e10cSrcweir }
568cdf0e10cSrcweir
UpdatePPT(OutputDevice * pDev)569cdf0e10cSrcweir void ScGlobal::UpdatePPT( OutputDevice* pDev )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir sal_uInt16 nCurrentZoom = Application::GetSettings().GetStyleSettings().GetScreenZoom();
572cdf0e10cSrcweir if ( nCurrentZoom != nPPTZoom )
573cdf0e10cSrcweir {
574cdf0e10cSrcweir // Screen PPT values must be updated when ScreenZoom has changed.
575cdf0e10cSrcweir // If called from Window::DataChanged, the window is passed as pDev,
576cdf0e10cSrcweir // to make sure LogicToPixel uses a device which already uses the new zoom.
577cdf0e10cSrcweir // For the initial settings, NULL is passed and GetDefaultDevice used.
578cdf0e10cSrcweir
579cdf0e10cSrcweir if ( !pDev )
580cdf0e10cSrcweir pDev = Application::GetDefaultDevice();
581cdf0e10cSrcweir Point aPix1000 = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
582cdf0e10cSrcweir nScreenPPTX = aPix1000.X() / 1000.0;
583cdf0e10cSrcweir nScreenPPTY = aPix1000.Y() / 1000.0;
584cdf0e10cSrcweir nPPTZoom = nCurrentZoom;
585cdf0e10cSrcweir }
586cdf0e10cSrcweir }
587cdf0e10cSrcweir
GetClipDocName()588cdf0e10cSrcweir const String& ScGlobal::GetClipDocName()
589cdf0e10cSrcweir {
590cdf0e10cSrcweir return *pStrClipDocName;
591cdf0e10cSrcweir }
592cdf0e10cSrcweir
SetClipDocName(const String & rNew)593cdf0e10cSrcweir void ScGlobal::SetClipDocName( const String& rNew )
594cdf0e10cSrcweir {
595cdf0e10cSrcweir *pStrClipDocName = rNew;
596cdf0e10cSrcweir }
597cdf0e10cSrcweir
598cdf0e10cSrcweir
InitTextHeight(SfxItemPool * pPool)599cdf0e10cSrcweir void ScGlobal::InitTextHeight(SfxItemPool* pPool)
600cdf0e10cSrcweir {
601cdf0e10cSrcweir if (!pPool)
602cdf0e10cSrcweir {
603cdf0e10cSrcweir DBG_ERROR("kein Pool bei ScGlobal::InitTextHeight");
604cdf0e10cSrcweir return;
605cdf0e10cSrcweir }
606cdf0e10cSrcweir
607cdf0e10cSrcweir const ScPatternAttr* pPattern = (const ScPatternAttr*)&pPool->GetDefaultItem(ATTR_PATTERN);
608cdf0e10cSrcweir if (!pPattern)
609cdf0e10cSrcweir {
610cdf0e10cSrcweir DBG_ERROR("kein Default-Pattern bei ScGlobal::InitTextHeight");
611cdf0e10cSrcweir return;
612cdf0e10cSrcweir }
613cdf0e10cSrcweir
614cdf0e10cSrcweir // String aTestString('X');
615cdf0e10cSrcweir OutputDevice* pDefaultDev = Application::GetDefaultDevice();
616cdf0e10cSrcweir VirtualDevice aVirtWindow( *pDefaultDev );
617cdf0e10cSrcweir aVirtWindow.SetMapMode(MAP_PIXEL);
618cdf0e10cSrcweir Font aDefFont;
619cdf0e10cSrcweir pPattern->GetFont(aDefFont, SC_AUTOCOL_BLACK, &aVirtWindow); // font color doesn't matter here
620cdf0e10cSrcweir aVirtWindow.SetFont(aDefFont);
621cdf0e10cSrcweir nDefFontHeight = (sal_uInt16) aVirtWindow.PixelToLogic(Size(0, aVirtWindow.GetTextHeight()),
622cdf0e10cSrcweir MAP_TWIP).Height();
623cdf0e10cSrcweir
624cdf0e10cSrcweir const SvxMarginItem* pMargin = (const SvxMarginItem*)&pPattern->GetItem(ATTR_MARGIN);
625cdf0e10cSrcweir
626cdf0e10cSrcweir nStdRowHeight = (sal_uInt16) ( nDefFontHeight +
627cdf0e10cSrcweir pMargin->GetTopMargin() + pMargin->GetBottomMargin()
628cdf0e10cSrcweir - STD_ROWHEIGHT_DIFF );
629cdf0e10cSrcweir }
630cdf0e10cSrcweir
Clear()631cdf0e10cSrcweir void ScGlobal::Clear()
632cdf0e10cSrcweir {
633cdf0e10cSrcweir // asyncs _vor_ ExitExternalFunc zerstoeren!
634cdf0e10cSrcweir theAddInAsyncTbl.DeleteAndDestroy( 0, theAddInAsyncTbl.Count() );
635cdf0e10cSrcweir ExitExternalFunc();
636cdf0e10cSrcweir DELETEZ(pAutoFormat);
637cdf0e10cSrcweir DELETEZ(pSearchItem);
638cdf0e10cSrcweir DELETEZ(pFuncCollection);
639cdf0e10cSrcweir DELETEZ(pAddInCollection);
640cdf0e10cSrcweir DELETEZ(pUserList);
641cdf0e10cSrcweir
642cdf0e10cSrcweir for( sal_uInt16 nC = 0 ; nC < STR_COUNT ; nC++ )
643cdf0e10cSrcweir if( ppRscString ) delete ppRscString[ nC ];
644cdf0e10cSrcweir delete[] ppRscString;
645cdf0e10cSrcweir ppRscString = NULL;
646cdf0e10cSrcweir
647cdf0e10cSrcweir DELETEZ(pStarCalcFunctionList); // vor ResMgr zerstoeren!
648cdf0e10cSrcweir DELETEZ(pStarCalcFunctionMgr);
649cdf0e10cSrcweir ScParameterClassification::Exit();
650cdf0e10cSrcweir ScCompiler::DeInit();
651cdf0e10cSrcweir ScInterpreter::GlobalExit(); // statischen Stack loeschen
652cdf0e10cSrcweir
653cdf0e10cSrcweir DELETEZ(pEmptyBrushItem);
654cdf0e10cSrcweir DELETEZ(pButtonBrushItem);
655cdf0e10cSrcweir DELETEZ(pEmbeddedBrushItem);
656cdf0e10cSrcweir DELETEZ(pProtectedBrushItem);
657cdf0e10cSrcweir DELETEZ(pOutlineBitmaps);
658cdf0e10cSrcweir DELETEZ(pOutlineBitmapsHC);
659cdf0e10cSrcweir // DELETEZ(pAnchorBitmap);
660cdf0e10cSrcweir // DELETEZ(pGrayAnchorBitmap);
661cdf0e10cSrcweir DELETEZ(pEnglishFormatter);
662cdf0e10cSrcweir DELETEZ(pCaseTransliteration);
663cdf0e10cSrcweir DELETEZ(pTransliteration);
664cdf0e10cSrcweir DELETEZ(pCaseCollator);
665cdf0e10cSrcweir DELETEZ(pCollator);
666cdf0e10cSrcweir DELETEZ(pCalendar);
667cdf0e10cSrcweir //! do NOT delete pCharClass since it is a pointer to the single SvtSysLocale instance
668cdf0e10cSrcweir pCharClass = NULL;
669cdf0e10cSrcweir //! do NOT delete pLocaleData since it is a pointer to the single SvtSysLocale instance
670cdf0e10cSrcweir pLocaleData = NULL;
671cdf0e10cSrcweir DELETEZ(pSysLocale);
672cdf0e10cSrcweir DELETEZ(pLocale);
673cdf0e10cSrcweir DELETEZ(pScIntlWrapper);
674cdf0e10cSrcweir DELETEZ(pStrClipDocName);
675cdf0e10cSrcweir
676cdf0e10cSrcweir DELETEZ(pUnitConverter);
677cdf0e10cSrcweir
678cdf0e10cSrcweir ScDocumentPool::DeleteVersionMaps();
679cdf0e10cSrcweir
680cdf0e10cSrcweir DELETEZ(pEmptyString);
681cdf0e10cSrcweir }
682cdf0e10cSrcweir
683cdf0e10cSrcweir //------------------------------------------------------------------------
684cdf0e10cSrcweir
685cdf0e10cSrcweir // static
GetCharsetValue(const String & rCharSet)686cdf0e10cSrcweir CharSet ScGlobal::GetCharsetValue( const String& rCharSet )
687cdf0e10cSrcweir {
688cdf0e10cSrcweir // new TextEncoding values
689cdf0e10cSrcweir if ( CharClass::isAsciiNumeric( rCharSet ) )
690cdf0e10cSrcweir {
691cdf0e10cSrcweir sal_Int32 nVal = rCharSet.ToInt32();
692cdf0e10cSrcweir if ( !nVal || nVal == RTL_TEXTENCODING_DONTKNOW )
693cdf0e10cSrcweir return gsl_getSystemTextEncoding();
694cdf0e10cSrcweir return (CharSet) nVal;
695cdf0e10cSrcweir }
696cdf0e10cSrcweir // old CharSet values for compatibility
697cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("ANSI") ) return RTL_TEXTENCODING_MS_1252;
698cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("MAC") ) return RTL_TEXTENCODING_APPLE_ROMAN;
699cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("IBMPC") ) return RTL_TEXTENCODING_IBM_850;
700cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("IBMPC_437")) return RTL_TEXTENCODING_IBM_437;
701cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("IBMPC_850")) return RTL_TEXTENCODING_IBM_850;
702cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("IBMPC_860")) return RTL_TEXTENCODING_IBM_860;
703cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("IBMPC_861")) return RTL_TEXTENCODING_IBM_861;
704cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("IBMPC_863")) return RTL_TEXTENCODING_IBM_863;
705cdf0e10cSrcweir else if (rCharSet.EqualsIgnoreCaseAscii("IBMPC_865")) return RTL_TEXTENCODING_IBM_865;
706cdf0e10cSrcweir // else if (rCharSet.EqualsIgnoreCaseAscii("SYSTEM") ) return gsl_getSystemTextEncoding();
707cdf0e10cSrcweir else return gsl_getSystemTextEncoding();
708cdf0e10cSrcweir }
709cdf0e10cSrcweir
710cdf0e10cSrcweir //------------------------------------------------------------------------
711cdf0e10cSrcweir
712cdf0e10cSrcweir // static
GetCharsetString(CharSet eVal)713cdf0e10cSrcweir String ScGlobal::GetCharsetString( CharSet eVal )
714cdf0e10cSrcweir {
715cdf0e10cSrcweir const sal_Char* pChar;
716cdf0e10cSrcweir switch ( eVal )
717cdf0e10cSrcweir {
718cdf0e10cSrcweir // old CharSet strings for compatibility
719cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1252: pChar = "ANSI"; break;
720cdf0e10cSrcweir case RTL_TEXTENCODING_APPLE_ROMAN: pChar = "MAC"; break;
721cdf0e10cSrcweir // IBMPC == IBMPC_850
722cdf0e10cSrcweir case RTL_TEXTENCODING_IBM_437: pChar = "IBMPC_437"; break;
723cdf0e10cSrcweir case RTL_TEXTENCODING_IBM_850: pChar = "IBMPC_850"; break;
724cdf0e10cSrcweir case RTL_TEXTENCODING_IBM_860: pChar = "IBMPC_860"; break;
725cdf0e10cSrcweir case RTL_TEXTENCODING_IBM_861: pChar = "IBMPC_861"; break;
726cdf0e10cSrcweir case RTL_TEXTENCODING_IBM_863: pChar = "IBMPC_863"; break;
727cdf0e10cSrcweir case RTL_TEXTENCODING_IBM_865: pChar = "IBMPC_865"; break;
728cdf0e10cSrcweir case RTL_TEXTENCODING_DONTKNOW: pChar = "SYSTEM"; break;
729cdf0e10cSrcweir // new string of TextEncoding value
730cdf0e10cSrcweir default:
731cdf0e10cSrcweir return String::CreateFromInt32( eVal );
732cdf0e10cSrcweir }
733cdf0e10cSrcweir return String::CreateFromAscii(pChar);
734cdf0e10cSrcweir }
735cdf0e10cSrcweir
736cdf0e10cSrcweir //------------------------------------------------------------------------
737cdf0e10cSrcweir
HasStarCalcFunctionList()738cdf0e10cSrcweir bool ScGlobal::HasStarCalcFunctionList()
739cdf0e10cSrcweir {
740cdf0e10cSrcweir return ( pStarCalcFunctionList != NULL );
741cdf0e10cSrcweir }
742cdf0e10cSrcweir
GetStarCalcFunctionList()743cdf0e10cSrcweir ScFunctionList* ScGlobal::GetStarCalcFunctionList()
744cdf0e10cSrcweir {
745cdf0e10cSrcweir if ( !pStarCalcFunctionList )
746cdf0e10cSrcweir pStarCalcFunctionList = new ScFunctionList;
747cdf0e10cSrcweir
748cdf0e10cSrcweir return pStarCalcFunctionList;
749cdf0e10cSrcweir }
750cdf0e10cSrcweir
751cdf0e10cSrcweir //------------------------------------------------------------------------
752cdf0e10cSrcweir
GetStarCalcFunctionMgr()753cdf0e10cSrcweir ScFunctionMgr* ScGlobal::GetStarCalcFunctionMgr()
754cdf0e10cSrcweir {
755cdf0e10cSrcweir if ( !pStarCalcFunctionMgr )
756cdf0e10cSrcweir pStarCalcFunctionMgr = new ScFunctionMgr;
757cdf0e10cSrcweir
758cdf0e10cSrcweir return pStarCalcFunctionMgr;
759cdf0e10cSrcweir }
760cdf0e10cSrcweir
ResetFunctionList()761cdf0e10cSrcweir void ScGlobal::ResetFunctionList()
762cdf0e10cSrcweir {
763cdf0e10cSrcweir // FunctionMgr has pointers into FunctionList, must also be updated
764cdf0e10cSrcweir
765cdf0e10cSrcweir DELETEZ( pStarCalcFunctionMgr );
766cdf0e10cSrcweir DELETEZ( pStarCalcFunctionList );
767cdf0e10cSrcweir }
768cdf0e10cSrcweir
769cdf0e10cSrcweir //------------------------------------------------------------------------
770cdf0e10cSrcweir
771cdf0e10cSrcweir // static
GetUnitConverter()772cdf0e10cSrcweir ScUnitConverter* ScGlobal::GetUnitConverter()
773cdf0e10cSrcweir {
774cdf0e10cSrcweir if ( !pUnitConverter )
775cdf0e10cSrcweir pUnitConverter = new ScUnitConverter;
776cdf0e10cSrcweir
777cdf0e10cSrcweir return pUnitConverter;
778cdf0e10cSrcweir }
779cdf0e10cSrcweir
780cdf0e10cSrcweir
781cdf0e10cSrcweir //------------------------------------------------------------------------
782cdf0e10cSrcweir
783cdf0e10cSrcweir // static
UnicodeStrChr(const sal_Unicode * pStr,sal_Unicode c)784cdf0e10cSrcweir const sal_Unicode* ScGlobal::UnicodeStrChr( const sal_Unicode* pStr,
785cdf0e10cSrcweir sal_Unicode c )
786cdf0e10cSrcweir {
787cdf0e10cSrcweir if ( !pStr )
788cdf0e10cSrcweir return NULL;
789cdf0e10cSrcweir while ( *pStr )
790cdf0e10cSrcweir {
791cdf0e10cSrcweir if ( *pStr == c )
792cdf0e10cSrcweir return pStr;
793cdf0e10cSrcweir pStr++;
794cdf0e10cSrcweir }
795cdf0e10cSrcweir return NULL;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir
798cdf0e10cSrcweir // ----------------------------------------------------------------------------
799cdf0e10cSrcweir
AddToken(String & rTokenList,const String & rToken,sal_Unicode cSep,xub_StrLen nSepCount,bool bForceSep)800cdf0e10cSrcweir void ScGlobal::AddToken( String& rTokenList, const String& rToken, sal_Unicode cSep, xub_StrLen nSepCount, bool bForceSep )
801cdf0e10cSrcweir {
802cdf0e10cSrcweir if( bForceSep || (rToken.Len() && rTokenList.Len()) )
803cdf0e10cSrcweir rTokenList.Expand( rTokenList.Len() + nSepCount, cSep );
804cdf0e10cSrcweir rTokenList.Append( rToken );
805cdf0e10cSrcweir }
806cdf0e10cSrcweir
IsQuoted(const String & rString,sal_Unicode cQuote)807cdf0e10cSrcweir bool ScGlobal::IsQuoted( const String& rString, sal_Unicode cQuote )
808cdf0e10cSrcweir {
809cdf0e10cSrcweir return (rString.Len() >= 2) && (rString.GetChar( 0 ) == cQuote) && (rString.GetChar( rString.Len() - 1 ) == cQuote);
810cdf0e10cSrcweir }
811cdf0e10cSrcweir
AddQuotes(String & rString,sal_Unicode cQuote,bool bEscapeEmbedded)812cdf0e10cSrcweir void ScGlobal::AddQuotes( String& rString, sal_Unicode cQuote, bool bEscapeEmbedded )
813cdf0e10cSrcweir {
814cdf0e10cSrcweir if (bEscapeEmbedded)
815cdf0e10cSrcweir {
816cdf0e10cSrcweir sal_Unicode pQ[3];
817cdf0e10cSrcweir pQ[0] = pQ[1] = cQuote;
818cdf0e10cSrcweir pQ[2] = 0;
819cdf0e10cSrcweir String aQuotes( pQ );
820cdf0e10cSrcweir rString.SearchAndReplaceAll( cQuote, aQuotes);
821cdf0e10cSrcweir }
822cdf0e10cSrcweir rString.Insert( cQuote, 0 ).Append( cQuote );
823cdf0e10cSrcweir }
824cdf0e10cSrcweir
EraseQuotes(String & rString,sal_Unicode cQuote,bool bUnescapeEmbedded)825cdf0e10cSrcweir void ScGlobal::EraseQuotes( String& rString, sal_Unicode cQuote, bool bUnescapeEmbedded )
826cdf0e10cSrcweir {
827cdf0e10cSrcweir if ( IsQuoted( rString, cQuote ) )
828cdf0e10cSrcweir {
829cdf0e10cSrcweir rString.Erase( rString.Len() - 1 ).Erase( 0, 1 );
830cdf0e10cSrcweir if (bUnescapeEmbedded)
831cdf0e10cSrcweir {
832cdf0e10cSrcweir sal_Unicode pQ[3];
833cdf0e10cSrcweir pQ[0] = pQ[1] = cQuote;
834cdf0e10cSrcweir pQ[2] = 0;
835cdf0e10cSrcweir String aQuotes( pQ );
836cdf0e10cSrcweir rString.SearchAndReplaceAll( aQuotes, cQuote);
837cdf0e10cSrcweir }
838cdf0e10cSrcweir }
839cdf0e10cSrcweir }
840cdf0e10cSrcweir
FindUnquoted(const String & rString,sal_Unicode cChar,xub_StrLen nStart,sal_Unicode cQuote)841cdf0e10cSrcweir xub_StrLen ScGlobal::FindUnquoted( const String& rString, sal_Unicode cChar, xub_StrLen nStart, sal_Unicode cQuote )
842cdf0e10cSrcweir {
843cdf0e10cSrcweir const sal_Unicode* const pStart = rString.GetBuffer();
844cdf0e10cSrcweir const sal_Unicode* const pStop = pStart + rString.Len();
845cdf0e10cSrcweir const sal_Unicode* p = pStart + nStart;
846cdf0e10cSrcweir bool bQuoted = false;
847cdf0e10cSrcweir while (p < pStop)
848cdf0e10cSrcweir {
849cdf0e10cSrcweir if (*p == cChar && !bQuoted)
850cdf0e10cSrcweir return sal::static_int_cast< xub_StrLen >( p - pStart );
851cdf0e10cSrcweir else if (*p == cQuote)
852cdf0e10cSrcweir {
853cdf0e10cSrcweir if (!bQuoted)
854cdf0e10cSrcweir bQuoted = true;
855cdf0e10cSrcweir else if (p < pStop-1 && *(p+1) == cQuote)
856cdf0e10cSrcweir ++p;
857cdf0e10cSrcweir else
858cdf0e10cSrcweir bQuoted = false;
859cdf0e10cSrcweir }
860cdf0e10cSrcweir ++p;
861cdf0e10cSrcweir }
862cdf0e10cSrcweir return STRING_NOTFOUND;
863cdf0e10cSrcweir }
864cdf0e10cSrcweir
FindUnquoted(const sal_Unicode * pString,sal_Unicode cChar,sal_Unicode cQuote)865cdf0e10cSrcweir const sal_Unicode* ScGlobal::FindUnquoted( const sal_Unicode* pString, sal_Unicode cChar, sal_Unicode cQuote )
866cdf0e10cSrcweir {
867cdf0e10cSrcweir const sal_Unicode* p = pString;
868cdf0e10cSrcweir bool bQuoted = false;
869cdf0e10cSrcweir while (*p)
870cdf0e10cSrcweir {
871cdf0e10cSrcweir if (*p == cChar && !bQuoted)
872cdf0e10cSrcweir return p;
873cdf0e10cSrcweir else if (*p == cQuote)
874cdf0e10cSrcweir {
875cdf0e10cSrcweir if (!bQuoted)
876cdf0e10cSrcweir bQuoted = true;
877cdf0e10cSrcweir else if (*(p+1) == cQuote)
878cdf0e10cSrcweir ++p;
879cdf0e10cSrcweir else
880cdf0e10cSrcweir bQuoted = false;
881cdf0e10cSrcweir }
882cdf0e10cSrcweir ++p;
883cdf0e10cSrcweir }
884cdf0e10cSrcweir return NULL;
885cdf0e10cSrcweir }
886cdf0e10cSrcweir
887cdf0e10cSrcweir //------------------------------------------------------------------------
888cdf0e10cSrcweir
EETextObjEqual(const EditTextObject * pObj1,const EditTextObject * pObj2)889cdf0e10cSrcweir sal_Bool ScGlobal::EETextObjEqual( const EditTextObject* pObj1,
890cdf0e10cSrcweir const EditTextObject* pObj2 )
891cdf0e10cSrcweir {
892cdf0e10cSrcweir if ( pObj1 == pObj2 ) // both empty or the same object
893cdf0e10cSrcweir return sal_True;
894cdf0e10cSrcweir
895cdf0e10cSrcweir if ( pObj1 && pObj2 )
896cdf0e10cSrcweir {
897cdf0e10cSrcweir // first test for equal text content
898*7a980842SDamjanJovanovic sal_uInt32 nParCount = pObj1->GetParagraphCount();
899cdf0e10cSrcweir if ( nParCount != pObj2->GetParagraphCount() )
900cdf0e10cSrcweir return sal_False;
901*7a980842SDamjanJovanovic for (sal_uInt32 nPar=0; nPar<nParCount; nPar++)
902cdf0e10cSrcweir if ( pObj1->GetText(nPar) != pObj2->GetText(nPar) )
903cdf0e10cSrcweir return sal_False;
904cdf0e10cSrcweir
905cdf0e10cSrcweir SvMemoryStream aStream1;
906cdf0e10cSrcweir SvMemoryStream aStream2;
907cdf0e10cSrcweir pObj1->Store( aStream1 );
908cdf0e10cSrcweir pObj2->Store( aStream2 );
909cdf0e10cSrcweir sal_uLong nSize = aStream1.Tell();
910cdf0e10cSrcweir if ( aStream2.Tell() == nSize )
911cdf0e10cSrcweir if ( !memcmp( aStream1.GetData(), aStream2.GetData(), (sal_uInt16) nSize ) )
912cdf0e10cSrcweir return sal_True;
913cdf0e10cSrcweir }
914cdf0e10cSrcweir
915cdf0e10cSrcweir return sal_False;
916cdf0e10cSrcweir }
917cdf0e10cSrcweir
OpenURL(const String & rURL,const String & rTarget)918cdf0e10cSrcweir void ScGlobal::OpenURL( const String& rURL, const String& rTarget )
919cdf0e10cSrcweir {
920cdf0e10cSrcweir // OpenURL wird immer ueber irgendwelche Umwege durch Mausklicks im GridWindow
921cdf0e10cSrcweir // aufgerufen, darum stimmen pScActiveViewShell und nScClickMouseModifier.
922cdf0e10cSrcweir
923cdf0e10cSrcweir SfxStringItem aUrl( SID_FILE_NAME, rURL );
924cdf0e10cSrcweir SfxStringItem aTarget( SID_TARGETNAME, rTarget );
925cdf0e10cSrcweir
926cdf0e10cSrcweir if ( nScClickMouseModifier & KEY_MOD1 ) // control-click -> into new window
927cdf0e10cSrcweir aTarget.SetValue(
928cdf0e10cSrcweir String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("_blank")) );
929cdf0e10cSrcweir
930cdf0e10cSrcweir SfxViewFrame* pFrame = NULL;
931cdf0e10cSrcweir String aReferName;
932cdf0e10cSrcweir if ( pScActiveViewShell )
933cdf0e10cSrcweir {
934cdf0e10cSrcweir pFrame = pScActiveViewShell->GetViewFrame();
935cdf0e10cSrcweir SfxMedium* pMed = pFrame->GetObjectShell()->GetMedium();
936cdf0e10cSrcweir if (pMed)
937cdf0e10cSrcweir aReferName = pMed->GetName();
938cdf0e10cSrcweir }
939cdf0e10cSrcweir
940cdf0e10cSrcweir SfxFrameItem aFrm( SID_DOCFRAME, pFrame );
941cdf0e10cSrcweir SfxStringItem aReferer( SID_REFERER, aReferName );
942cdf0e10cSrcweir
943cdf0e10cSrcweir SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, sal_False );
944cdf0e10cSrcweir SfxBoolItem aBrowsing( SID_BROWSE, sal_True );
945cdf0e10cSrcweir
946cdf0e10cSrcweir // kein SID_SILENT mehr wegen Bug #42525# (war angeblich sowieso falsch)
947cdf0e10cSrcweir
948cdf0e10cSrcweir SfxViewFrame* pViewFrm = SfxViewFrame::Current();
949cdf0e10cSrcweir if (pViewFrm)
950cdf0e10cSrcweir pViewFrm->GetDispatcher()->Execute( SID_OPENDOC,
951cdf0e10cSrcweir SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
952cdf0e10cSrcweir &aUrl, &aTarget,
953cdf0e10cSrcweir &aFrm, &aReferer,
954cdf0e10cSrcweir &aNewView, &aBrowsing,
955cdf0e10cSrcweir 0L );
956cdf0e10cSrcweir }
957cdf0e10cSrcweir
958cdf0e10cSrcweir //------------------------------------------------------------------------
959cdf0e10cSrcweir
IsSystemRTL()960cdf0e10cSrcweir sal_Bool ScGlobal::IsSystemRTL()
961cdf0e10cSrcweir {
962cdf0e10cSrcweir return MsLangId::isRightToLeft( Application::GetSettings().GetLanguage() );
963cdf0e10cSrcweir }
964cdf0e10cSrcweir
GetDefaultScriptType()965cdf0e10cSrcweir sal_uInt8 ScGlobal::GetDefaultScriptType()
966cdf0e10cSrcweir {
967cdf0e10cSrcweir // Used when text contains only WEAK characters.
968cdf0e10cSrcweir // Script type of office language is used then (same as GetEditDefaultLanguage,
969cdf0e10cSrcweir // to get consistent behavior of text in simple cells and EditEngine,
970cdf0e10cSrcweir // also same as GetAppLanguage() in Writer)
971cdf0e10cSrcweir
972cdf0e10cSrcweir return (sal_uInt8) SvtLanguageOptions::GetScriptTypeOfLanguage( Application::GetSettings().GetLanguage() );
973cdf0e10cSrcweir }
974cdf0e10cSrcweir
GetEditDefaultLanguage()975cdf0e10cSrcweir LanguageType ScGlobal::GetEditDefaultLanguage()
976cdf0e10cSrcweir {
977cdf0e10cSrcweir // used for EditEngine::SetDefaultLanguage
978cdf0e10cSrcweir
979cdf0e10cSrcweir return Application::GetSettings().GetLanguage();
980cdf0e10cSrcweir }
981cdf0e10cSrcweir
GetScriptedWhichID(sal_uInt8 nScriptType,sal_uInt16 nWhich)982cdf0e10cSrcweir sal_uInt16 ScGlobal::GetScriptedWhichID( sal_uInt8 nScriptType, sal_uInt16 nWhich )
983cdf0e10cSrcweir {
984cdf0e10cSrcweir switch ( nScriptType )
985cdf0e10cSrcweir {
986cdf0e10cSrcweir case SCRIPTTYPE_LATIN:
987cdf0e10cSrcweir case SCRIPTTYPE_ASIAN:
988cdf0e10cSrcweir case SCRIPTTYPE_COMPLEX:
989cdf0e10cSrcweir break; // take exact matches
990cdf0e10cSrcweir default: // prefer one, first COMPLEX, then ASIAN
991cdf0e10cSrcweir if ( nScriptType & SCRIPTTYPE_COMPLEX )
992cdf0e10cSrcweir nScriptType = SCRIPTTYPE_COMPLEX;
993cdf0e10cSrcweir else if ( nScriptType & SCRIPTTYPE_ASIAN )
994cdf0e10cSrcweir nScriptType = SCRIPTTYPE_ASIAN;
995cdf0e10cSrcweir }
996cdf0e10cSrcweir switch ( nScriptType )
997cdf0e10cSrcweir {
998cdf0e10cSrcweir case SCRIPTTYPE_COMPLEX:
999cdf0e10cSrcweir {
1000cdf0e10cSrcweir switch ( nWhich )
1001cdf0e10cSrcweir {
1002cdf0e10cSrcweir case ATTR_FONT:
1003cdf0e10cSrcweir case ATTR_CJK_FONT:
1004cdf0e10cSrcweir nWhich = ATTR_CTL_FONT;
1005cdf0e10cSrcweir break;
1006cdf0e10cSrcweir case ATTR_FONT_HEIGHT:
1007cdf0e10cSrcweir case ATTR_CJK_FONT_HEIGHT:
1008cdf0e10cSrcweir nWhich = ATTR_CTL_FONT_HEIGHT;
1009cdf0e10cSrcweir break;
1010cdf0e10cSrcweir case ATTR_FONT_WEIGHT:
1011cdf0e10cSrcweir case ATTR_CJK_FONT_WEIGHT:
1012cdf0e10cSrcweir nWhich = ATTR_CTL_FONT_WEIGHT;
1013cdf0e10cSrcweir break;
1014cdf0e10cSrcweir case ATTR_FONT_POSTURE:
1015cdf0e10cSrcweir case ATTR_CJK_FONT_POSTURE:
1016cdf0e10cSrcweir nWhich = ATTR_CTL_FONT_POSTURE;
1017cdf0e10cSrcweir break;
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir }
1020cdf0e10cSrcweir break;
1021cdf0e10cSrcweir case SCRIPTTYPE_ASIAN:
1022cdf0e10cSrcweir {
1023cdf0e10cSrcweir switch ( nWhich )
1024cdf0e10cSrcweir {
1025cdf0e10cSrcweir case ATTR_FONT:
1026cdf0e10cSrcweir case ATTR_CTL_FONT:
1027cdf0e10cSrcweir nWhich = ATTR_CJK_FONT;
1028cdf0e10cSrcweir break;
1029cdf0e10cSrcweir case ATTR_FONT_HEIGHT:
1030cdf0e10cSrcweir case ATTR_CTL_FONT_HEIGHT:
1031cdf0e10cSrcweir nWhich = ATTR_CJK_FONT_HEIGHT;
1032cdf0e10cSrcweir break;
1033cdf0e10cSrcweir case ATTR_FONT_WEIGHT:
1034cdf0e10cSrcweir case ATTR_CTL_FONT_WEIGHT:
1035cdf0e10cSrcweir nWhich = ATTR_CJK_FONT_WEIGHT;
1036cdf0e10cSrcweir break;
1037cdf0e10cSrcweir case ATTR_FONT_POSTURE:
1038cdf0e10cSrcweir case ATTR_CTL_FONT_POSTURE:
1039cdf0e10cSrcweir nWhich = ATTR_CJK_FONT_POSTURE;
1040cdf0e10cSrcweir break;
1041cdf0e10cSrcweir }
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir break;
1044cdf0e10cSrcweir default:
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir switch ( nWhich )
1047cdf0e10cSrcweir {
1048cdf0e10cSrcweir case ATTR_CTL_FONT:
1049cdf0e10cSrcweir case ATTR_CJK_FONT:
1050cdf0e10cSrcweir nWhich = ATTR_FONT;
1051cdf0e10cSrcweir break;
1052cdf0e10cSrcweir case ATTR_CTL_FONT_HEIGHT:
1053cdf0e10cSrcweir case ATTR_CJK_FONT_HEIGHT:
1054cdf0e10cSrcweir nWhich = ATTR_FONT_HEIGHT;
1055cdf0e10cSrcweir break;
1056cdf0e10cSrcweir case ATTR_CTL_FONT_WEIGHT:
1057cdf0e10cSrcweir case ATTR_CJK_FONT_WEIGHT:
1058cdf0e10cSrcweir nWhich = ATTR_FONT_WEIGHT;
1059cdf0e10cSrcweir break;
1060cdf0e10cSrcweir case ATTR_CTL_FONT_POSTURE:
1061cdf0e10cSrcweir case ATTR_CJK_FONT_POSTURE:
1062cdf0e10cSrcweir nWhich = ATTR_FONT_POSTURE;
1063cdf0e10cSrcweir break;
1064cdf0e10cSrcweir }
1065cdf0e10cSrcweir }
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir return nWhich;
1068cdf0e10cSrcweir }
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir //------------------------------------------------------------------------
1071cdf0e10cSrcweir
AddLanguage(SfxItemSet & rSet,SvNumberFormatter & rFormatter)1072cdf0e10cSrcweir void ScGlobal::AddLanguage( SfxItemSet& rSet, SvNumberFormatter& rFormatter )
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir DBG_ASSERT( rSet.GetItemState( ATTR_LANGUAGE_FORMAT, sal_False ) == SFX_ITEM_DEFAULT,
1075cdf0e10cSrcweir "ScGlobal::AddLanguage - language already added");
1076cdf0e10cSrcweir
1077cdf0e10cSrcweir const SfxPoolItem* pHardItem;
1078cdf0e10cSrcweir if ( rSet.GetItemState( ATTR_VALUE_FORMAT, sal_False, &pHardItem ) == SFX_ITEM_SET )
1079cdf0e10cSrcweir {
1080cdf0e10cSrcweir const SvNumberformat* pHardFormat = rFormatter.GetEntry(
1081cdf0e10cSrcweir ((const SfxUInt32Item*)pHardItem)->GetValue() );
1082cdf0e10cSrcweir
1083cdf0e10cSrcweir sal_uLong nParentFmt = 0; // pool default
1084cdf0e10cSrcweir const SfxItemSet* pParent = rSet.GetParent();
1085cdf0e10cSrcweir if ( pParent )
1086cdf0e10cSrcweir nParentFmt = ((const SfxUInt32Item&)pParent->Get( ATTR_VALUE_FORMAT )).GetValue();
1087cdf0e10cSrcweir const SvNumberformat* pParFormat = rFormatter.GetEntry( nParentFmt );
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir if ( pHardFormat && pParFormat &&
1090cdf0e10cSrcweir (pHardFormat->GetLanguage() != pParFormat->GetLanguage()) )
1091cdf0e10cSrcweir rSet.Put( SvxLanguageItem( pHardFormat->GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
1092cdf0e10cSrcweir }
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir
1095cdf0e10cSrcweir
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir
1098cdf0e10cSrcweir
1099cdf0e10cSrcweir //===================================================================
1100cdf0e10cSrcweir // class ScFunctionList:
1101cdf0e10cSrcweir //===================================================================
1102cdf0e10cSrcweir
1103cdf0e10cSrcweir //===================================================================
1104cdf0e10cSrcweir // class ScFuncRes
1105cdf0e10cSrcweir // fuer temporaere Objekte zum Holen der Resourcen
1106cdf0e10cSrcweir
1107cdf0e10cSrcweir class ScFuncRes : public Resource
1108cdf0e10cSrcweir {
1109cdf0e10cSrcweir public:
1110cdf0e10cSrcweir ScFuncRes( ResId&, ScFuncDesc*, bool & rbSuppressed );
1111cdf0e10cSrcweir
1112cdf0e10cSrcweir private:
1113cdf0e10cSrcweir sal_uInt16 GetNum();
1114cdf0e10cSrcweir };
1115cdf0e10cSrcweir
1116cdf0e10cSrcweir //--------------------------------------------------------------------
1117cdf0e10cSrcweir
ScFuncRes(ResId & aRes,ScFuncDesc * pDesc,bool & rbSuppressed)1118cdf0e10cSrcweir ScFuncRes::ScFuncRes( ResId &aRes, ScFuncDesc* pDesc, bool & rbSuppressed )
1119cdf0e10cSrcweir : Resource(aRes)
1120cdf0e10cSrcweir {
1121cdf0e10cSrcweir rbSuppressed = (bool)GetNum();
1122cdf0e10cSrcweir pDesc->nCategory = GetNum();
1123cdf0e10cSrcweir pDesc->sHelpId = ReadByteStringRes(); //! Hack, see scfuncs.src
1124cdf0e10cSrcweir pDesc->nArgCount = GetNum();
1125cdf0e10cSrcweir sal_uInt16 nArgs = pDesc->nArgCount;
11261b1b70fbSAndrew Rist if (nArgs >= PAIRED_VAR_ARGS)
11271b1b70fbSAndrew Rist nArgs -= PAIRED_VAR_ARGS - 2;
11281b1b70fbSAndrew Rist else if (nArgs >= VAR_ARGS)
1129cdf0e10cSrcweir nArgs -= VAR_ARGS - 1;
1130cdf0e10cSrcweir if (nArgs)
1131cdf0e10cSrcweir {
1132cdf0e10cSrcweir pDesc->pDefArgFlags = new ScFuncDesc::ParameterFlags[nArgs];
1133cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nArgs; i++)
1134cdf0e10cSrcweir {
1135cdf0e10cSrcweir pDesc->pDefArgFlags[i].bOptional = (bool)GetNum();
1136cdf0e10cSrcweir }
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir // Need to read the value from the resource even if nArgs==0 to advance the
1139cdf0e10cSrcweir // resource position pointer, so this can't be in the if(nArgs) block above.
1140cdf0e10cSrcweir sal_uInt16 nSuppressed = GetNum();
1141cdf0e10cSrcweir if (nSuppressed)
1142cdf0e10cSrcweir {
1143cdf0e10cSrcweir if (nSuppressed > nArgs)
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir DBG_ERROR3( "ScFuncRes: suppressed parameters count mismatch on OpCode %u: suppressed %d > params %d",
1146cdf0e10cSrcweir aRes.GetId(), (int)nSuppressed, (int)nArgs);
1147cdf0e10cSrcweir nSuppressed = nArgs; // sanitize
1148cdf0e10cSrcweir }
1149cdf0e10cSrcweir for (sal_uInt16 i=0; i < nSuppressed; ++i)
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir sal_uInt16 nParam = GetNum();
1152cdf0e10cSrcweir if (nParam < nArgs)
1153cdf0e10cSrcweir {
11541b1b70fbSAndrew Rist if (pDesc->nArgCount >= PAIRED_VAR_ARGS && nParam >= nArgs-2)
11551b1b70fbSAndrew Rist {
11561b1b70fbSAndrew Rist DBG_ERROR3( "ScFuncRes: PAIRED_VAR_ARGS parameters can't be suppressed, on OpCode %u: param %d >= arg %d-2",
11571b1b70fbSAndrew Rist aRes.GetId(), (int)nParam, (int)nArgs);
11581b1b70fbSAndrew Rist }
11591b1b70fbSAndrew Rist else if (pDesc->nArgCount >= VAR_ARGS && nParam == nArgs-1)
1160cdf0e10cSrcweir {
1161cdf0e10cSrcweir DBG_ERROR3( "ScFuncRes: VAR_ARGS parameters can't be suppressed, on OpCode %u: param %d == arg %d-1",
1162cdf0e10cSrcweir aRes.GetId(), (int)nParam, (int)nArgs);
1163cdf0e10cSrcweir }
1164cdf0e10cSrcweir else
1165cdf0e10cSrcweir {
1166cdf0e10cSrcweir pDesc->pDefArgFlags[nParam].bSuppress = true;
1167cdf0e10cSrcweir pDesc->bHasSuppressedArgs = true;
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir else
1171cdf0e10cSrcweir {
1172cdf0e10cSrcweir DBG_ERROR3( "ScFuncRes: suppressed parameter exceeds count on OpCode %u: param %d >= args %d",
1173cdf0e10cSrcweir aRes.GetId(), (int)nParam, (int)nArgs);
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir }
1176cdf0e10cSrcweir }
1177cdf0e10cSrcweir
1178cdf0e10cSrcweir pDesc->pFuncName = new String( ScCompiler::GetNativeSymbol( static_cast<OpCode>( aRes.GetId())));
1179cdf0e10cSrcweir pDesc->pFuncDesc = new String(ScResId(1));
1180cdf0e10cSrcweir
1181cdf0e10cSrcweir if (nArgs)
1182cdf0e10cSrcweir {
1183cdf0e10cSrcweir pDesc->ppDefArgNames = new String*[nArgs];
1184cdf0e10cSrcweir pDesc->ppDefArgDescs = new String*[nArgs];
1185cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nArgs; i++)
1186cdf0e10cSrcweir {
1187cdf0e10cSrcweir pDesc->ppDefArgNames[i] = new String(ScResId(2*(i+1) ));
1188cdf0e10cSrcweir pDesc->ppDefArgDescs[i] = new String(ScResId(2*(i+1)+1));
1189cdf0e10cSrcweir }
1190cdf0e10cSrcweir }
1191cdf0e10cSrcweir
1192cdf0e10cSrcweir FreeResource();
1193cdf0e10cSrcweir }
1194cdf0e10cSrcweir
1195cdf0e10cSrcweir //------------------------------------------------------------------------
1196cdf0e10cSrcweir
GetNum()1197cdf0e10cSrcweir sal_uInt16 ScFuncRes::GetNum()
1198cdf0e10cSrcweir {
1199cdf0e10cSrcweir return ReadShortRes();
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir //=========================================================================
1203cdf0e10cSrcweir
1204cdf0e10cSrcweir // um an die protected von Resource ranzukommen
1205cdf0e10cSrcweir class ScResourcePublisher : public Resource
1206cdf0e10cSrcweir {
1207cdf0e10cSrcweir private:
FreeResource()1208cdf0e10cSrcweir void FreeResource() { Resource::FreeResource(); }
1209cdf0e10cSrcweir public:
ScResourcePublisher(const ScResId & rId)1210cdf0e10cSrcweir ScResourcePublisher( const ScResId& rId ) : Resource( rId ) {}
~ScResourcePublisher()1211cdf0e10cSrcweir ~ScResourcePublisher() { FreeResource(); }
IsAvailableRes(const ResId & rId) const1212cdf0e10cSrcweir sal_Bool IsAvailableRes( const ResId& rId ) const
1213cdf0e10cSrcweir { return Resource::IsAvailableRes( rId ); }
1214cdf0e10cSrcweir
1215cdf0e10cSrcweir };
1216cdf0e10cSrcweir
1217cdf0e10cSrcweir
ScFunctionList()1218cdf0e10cSrcweir ScFunctionList::ScFunctionList() :
1219cdf0e10cSrcweir nMaxFuncNameLen ( 0 )
1220cdf0e10cSrcweir {
1221cdf0e10cSrcweir ScFuncDesc* pDesc = NULL;
1222cdf0e10cSrcweir xub_StrLen nStrLen = 0;
1223cdf0e10cSrcweir FuncCollection* pFuncColl;
1224cdf0e10cSrcweir sal_uInt16 i,j;
1225cdf0e10cSrcweir sal_uInt16 nDescBlock[] =
1226cdf0e10cSrcweir {
1227cdf0e10cSrcweir RID_SC_FUNCTION_DESCRIPTIONS1,
1228cdf0e10cSrcweir RID_SC_FUNCTION_DESCRIPTIONS2
1229cdf0e10cSrcweir };
1230cdf0e10cSrcweir const sal_uInt16 nBlocks = sizeof(nDescBlock) / sizeof(sal_uInt16);
1231cdf0e10cSrcweir
1232cdf0e10cSrcweir aFunctionList.Clear();
1233cdf0e10cSrcweir
1234cdf0e10cSrcweir for ( sal_uInt16 k = 0; k < nBlocks; k++ )
1235cdf0e10cSrcweir {
1236cdf0e10cSrcweir ::std::auto_ptr<ScResourcePublisher> pBlock( new ScResourcePublisher( ScResId( nDescBlock[k] ) ) );
1237cdf0e10cSrcweir // Browse for all possible OpCodes. This is not the fastest method, but
1238cdf0e10cSrcweir // otherwise the sub resources within the resource blocks and the
123986e1cf34SPedro Giffuni // resource blocks themselves would had to be ordered according to
1240cdf0e10cSrcweir // OpCodes, which is utopian..
1241cdf0e10cSrcweir for (i = 0; i <= SC_OPCODE_LAST_OPCODE_ID; i++)
1242cdf0e10cSrcweir {
1243cdf0e10cSrcweir ScResId aRes(i);
1244cdf0e10cSrcweir aRes.SetRT(RSC_RESOURCE);
1245cdf0e10cSrcweir // Sub resource of OpCode available?
1246cdf0e10cSrcweir if (pBlock->IsAvailableRes(aRes))
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir pDesc = new ScFuncDesc;
1249cdf0e10cSrcweir bool bSuppressed = false;
1250cdf0e10cSrcweir ScFuncRes aSubRes( aRes, pDesc, bSuppressed);
1251cdf0e10cSrcweir // Instead of dealing with this exceptional case at 1001 places
1252cdf0e10cSrcweir // we simply don't add an entirely suppressed function to the
1253cdf0e10cSrcweir // list and delete it.
1254cdf0e10cSrcweir if (bSuppressed)
1255cdf0e10cSrcweir delete pDesc;
1256cdf0e10cSrcweir else
1257cdf0e10cSrcweir {
1258cdf0e10cSrcweir pDesc->nFIndex = i;
1259cdf0e10cSrcweir aFunctionList.Insert( pDesc, LIST_APPEND );
1260cdf0e10cSrcweir
1261cdf0e10cSrcweir nStrLen = (*(pDesc->pFuncName)).Len();
1262cdf0e10cSrcweir if (nStrLen > nMaxFuncNameLen)
1263cdf0e10cSrcweir nMaxFuncNameLen = nStrLen;
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir }
1266cdf0e10cSrcweir }
1267cdf0e10cSrcweir }
1268cdf0e10cSrcweir
1269cdf0e10cSrcweir sal_uInt16 nNextId = SC_OPCODE_LAST_OPCODE_ID + 1; // FuncID for AddIn functions
1270cdf0e10cSrcweir
1271cdf0e10cSrcweir // Auswertung AddIn-Liste
1272cdf0e10cSrcweir String aDefArgNameValue(RTL_CONSTASCII_STRINGPARAM("value"));
1273cdf0e10cSrcweir String aDefArgNameString(RTL_CONSTASCII_STRINGPARAM("string"));
1274cdf0e10cSrcweir String aDefArgNameValues(RTL_CONSTASCII_STRINGPARAM("values"));
1275cdf0e10cSrcweir String aDefArgNameStrings(RTL_CONSTASCII_STRINGPARAM("strings"));
1276cdf0e10cSrcweir String aDefArgNameCells(RTL_CONSTASCII_STRINGPARAM("cells"));
1277cdf0e10cSrcweir String aDefArgNameNone(RTL_CONSTASCII_STRINGPARAM("none"));
1278cdf0e10cSrcweir String aDefArgDescValue(RTL_CONSTASCII_STRINGPARAM("a value"));
1279cdf0e10cSrcweir String aDefArgDescString(RTL_CONSTASCII_STRINGPARAM("a string"));
1280cdf0e10cSrcweir String aDefArgDescValues(RTL_CONSTASCII_STRINGPARAM("array of values"));
1281cdf0e10cSrcweir String aDefArgDescStrings(RTL_CONSTASCII_STRINGPARAM("array of strings"));
1282cdf0e10cSrcweir String aDefArgDescCells(RTL_CONSTASCII_STRINGPARAM("range of cells"));
1283cdf0e10cSrcweir String aDefArgDescNone(RTL_CONSTASCII_STRINGPARAM("none"));
1284cdf0e10cSrcweir String aArgName, aArgDesc;
1285cdf0e10cSrcweir pFuncColl = ScGlobal::GetFuncCollection();
1286cdf0e10cSrcweir for (i = 0; i < pFuncColl->GetCount(); i++)
1287cdf0e10cSrcweir {
1288cdf0e10cSrcweir pDesc = new ScFuncDesc;
1289cdf0e10cSrcweir FuncData *pAddInFuncData = (FuncData*)pFuncColl->At(i);
1290cdf0e10cSrcweir sal_uInt16 nArgs = pAddInFuncData->GetParamCount() - 1;
1291cdf0e10cSrcweir pAddInFuncData->GetParamDesc( aArgName, aArgDesc, 0 );
1292cdf0e10cSrcweir pDesc->nFIndex = nNextId++; // ??? OpCode vergeben
1293cdf0e10cSrcweir pDesc->nCategory = ID_FUNCTION_GRP_ADDINS;
1294cdf0e10cSrcweir pDesc->pFuncName = new String(pAddInFuncData->GetInternalName());
1295cdf0e10cSrcweir pDesc->pFuncName->ToUpperAscii();
1296cdf0e10cSrcweir pDesc->pFuncDesc = new String( aArgDesc );
1297cdf0e10cSrcweir *(pDesc->pFuncDesc) += '\n';
1298cdf0e10cSrcweir pDesc->pFuncDesc->AppendAscii(RTL_CONSTASCII_STRINGPARAM( "( AddIn: " ));
1299cdf0e10cSrcweir *(pDesc->pFuncDesc) += pAddInFuncData->GetModuleName();
1300cdf0e10cSrcweir pDesc->pFuncDesc->AppendAscii(RTL_CONSTASCII_STRINGPARAM( " )" ));
1301cdf0e10cSrcweir pDesc->nArgCount = nArgs;
1302cdf0e10cSrcweir if (nArgs)
1303cdf0e10cSrcweir {
1304cdf0e10cSrcweir pDesc->pDefArgFlags = new ScFuncDesc::ParameterFlags[nArgs];
1305cdf0e10cSrcweir pDesc->ppDefArgNames = new String*[nArgs];
1306cdf0e10cSrcweir pDesc->ppDefArgDescs = new String*[nArgs];
1307cdf0e10cSrcweir for (j = 0; j < nArgs; j++)
1308cdf0e10cSrcweir {
1309cdf0e10cSrcweir pDesc->pDefArgFlags[j].bOptional = false;
1310cdf0e10cSrcweir pDesc->pDefArgFlags[j].bSuppress = false;
1311cdf0e10cSrcweir pAddInFuncData->GetParamDesc( aArgName, aArgDesc, j+1 );
1312cdf0e10cSrcweir if ( aArgName.Len() )
1313cdf0e10cSrcweir pDesc->ppDefArgNames[j] = new String( aArgName );
1314cdf0e10cSrcweir else
1315cdf0e10cSrcweir {
1316cdf0e10cSrcweir switch (pAddInFuncData->GetParamType(j+1))
1317cdf0e10cSrcweir {
1318cdf0e10cSrcweir case PTR_DOUBLE:
1319cdf0e10cSrcweir pDesc->ppDefArgNames[j] = new String( aDefArgNameValue );
1320cdf0e10cSrcweir break;
1321cdf0e10cSrcweir case PTR_STRING:
1322cdf0e10cSrcweir pDesc->ppDefArgNames[j] = new String( aDefArgNameString );
1323cdf0e10cSrcweir break;
1324cdf0e10cSrcweir case PTR_DOUBLE_ARR:
1325cdf0e10cSrcweir pDesc->ppDefArgNames[j] = new String( aDefArgNameValues );
1326cdf0e10cSrcweir break;
1327cdf0e10cSrcweir case PTR_STRING_ARR:
1328cdf0e10cSrcweir pDesc->ppDefArgNames[j] = new String( aDefArgNameStrings );
1329cdf0e10cSrcweir break;
1330cdf0e10cSrcweir case PTR_CELL_ARR:
1331cdf0e10cSrcweir pDesc->ppDefArgNames[j] = new String( aDefArgNameCells );
1332cdf0e10cSrcweir break;
1333cdf0e10cSrcweir default:
1334cdf0e10cSrcweir pDesc->ppDefArgNames[j] = new String( aDefArgNameNone );
1335cdf0e10cSrcweir break;
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir }
1338cdf0e10cSrcweir if ( aArgDesc.Len() )
1339cdf0e10cSrcweir pDesc->ppDefArgDescs[j] = new String( aArgDesc );
1340cdf0e10cSrcweir else
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir switch (pAddInFuncData->GetParamType(j+1))
1343cdf0e10cSrcweir {
1344cdf0e10cSrcweir case PTR_DOUBLE:
1345cdf0e10cSrcweir pDesc->ppDefArgDescs[j] = new String( aDefArgDescValue );
1346cdf0e10cSrcweir break;
1347cdf0e10cSrcweir case PTR_STRING:
1348cdf0e10cSrcweir pDesc->ppDefArgDescs[j] = new String( aDefArgDescString );
1349cdf0e10cSrcweir break;
1350cdf0e10cSrcweir case PTR_DOUBLE_ARR:
1351cdf0e10cSrcweir pDesc->ppDefArgDescs[j] = new String( aDefArgDescValues );
1352cdf0e10cSrcweir break;
1353cdf0e10cSrcweir case PTR_STRING_ARR:
1354cdf0e10cSrcweir pDesc->ppDefArgDescs[j] = new String( aDefArgDescStrings );
1355cdf0e10cSrcweir break;
1356cdf0e10cSrcweir case PTR_CELL_ARR:
1357cdf0e10cSrcweir pDesc->ppDefArgDescs[j] = new String( aDefArgDescCells );
1358cdf0e10cSrcweir break;
1359cdf0e10cSrcweir default:
1360cdf0e10cSrcweir pDesc->ppDefArgDescs[j] = new String( aDefArgDescNone );
1361cdf0e10cSrcweir break;
1362cdf0e10cSrcweir }
1363cdf0e10cSrcweir }
1364cdf0e10cSrcweir }
1365cdf0e10cSrcweir }
1366cdf0e10cSrcweir // pDesc->nHelpId = 0;
1367cdf0e10cSrcweir
1368cdf0e10cSrcweir aFunctionList.Insert(pDesc, LIST_APPEND);
1369cdf0e10cSrcweir nStrLen = (*(pDesc->pFuncName)).Len();
1370cdf0e10cSrcweir if ( nStrLen > nMaxFuncNameLen)
1371cdf0e10cSrcweir nMaxFuncNameLen = nStrLen;
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir
1374cdf0e10cSrcweir // StarOne AddIns
1375cdf0e10cSrcweir
1376cdf0e10cSrcweir ScUnoAddInCollection* pUnoAddIns = ScGlobal::GetAddInCollection();
1377cdf0e10cSrcweir long nUnoCount = pUnoAddIns->GetFuncCount();
1378cdf0e10cSrcweir for (long nFunc=0; nFunc<nUnoCount; nFunc++)
1379cdf0e10cSrcweir {
1380cdf0e10cSrcweir pDesc = new ScFuncDesc;
1381cdf0e10cSrcweir pDesc->nFIndex = nNextId++;
1382cdf0e10cSrcweir
1383cdf0e10cSrcweir if ( pUnoAddIns->FillFunctionDesc( nFunc, *pDesc ) )
1384cdf0e10cSrcweir {
1385cdf0e10cSrcweir aFunctionList.Insert(pDesc, LIST_APPEND);
1386cdf0e10cSrcweir nStrLen = (*(pDesc->pFuncName)).Len();
1387cdf0e10cSrcweir if (nStrLen > nMaxFuncNameLen)
1388cdf0e10cSrcweir nMaxFuncNameLen = nStrLen;
1389cdf0e10cSrcweir }
1390cdf0e10cSrcweir else
1391cdf0e10cSrcweir delete pDesc;
1392cdf0e10cSrcweir }
1393cdf0e10cSrcweir }
1394cdf0e10cSrcweir
1395cdf0e10cSrcweir //------------------------------------------------------------------------
1396cdf0e10cSrcweir
~ScFunctionList()1397cdf0e10cSrcweir ScFunctionList::~ScFunctionList()
1398cdf0e10cSrcweir {
1399cdf0e10cSrcweir const ScFuncDesc* pDesc = First();
1400cdf0e10cSrcweir while (pDesc)
1401cdf0e10cSrcweir {
1402cdf0e10cSrcweir delete pDesc;
1403cdf0e10cSrcweir pDesc = Next();
1404cdf0e10cSrcweir }
1405cdf0e10cSrcweir }
1406cdf0e10cSrcweir
1407cdf0e10cSrcweir
1408cdf0e10cSrcweir //========================================================================
1409cdf0e10cSrcweir // class ScFuncDesc:
1410cdf0e10cSrcweir
ScFuncDesc()1411cdf0e10cSrcweir ScFuncDesc::ScFuncDesc() :
1412cdf0e10cSrcweir pFuncName (NULL),
1413cdf0e10cSrcweir pFuncDesc (NULL),
1414cdf0e10cSrcweir ppDefArgNames (NULL),
1415cdf0e10cSrcweir ppDefArgDescs (NULL),
1416cdf0e10cSrcweir pDefArgFlags (NULL),
1417cdf0e10cSrcweir nFIndex (0),
1418cdf0e10cSrcweir nCategory (0),
1419cdf0e10cSrcweir nArgCount (0),
1420cdf0e10cSrcweir bIncomplete (false),
1421cdf0e10cSrcweir bHasSuppressedArgs(false)
1422cdf0e10cSrcweir {}
1423cdf0e10cSrcweir
1424cdf0e10cSrcweir //------------------------------------------------------------------------
1425cdf0e10cSrcweir
~ScFuncDesc()1426cdf0e10cSrcweir ScFuncDesc::~ScFuncDesc()
1427cdf0e10cSrcweir {
1428cdf0e10cSrcweir Clear();
1429cdf0e10cSrcweir }
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir //------------------------------------------------------------------------
1432cdf0e10cSrcweir
Clear()1433cdf0e10cSrcweir void ScFuncDesc::Clear()
1434cdf0e10cSrcweir {
1435cdf0e10cSrcweir sal_uInt16 nArgs = nArgCount;
14361b1b70fbSAndrew Rist if (nArgs >= PAIRED_VAR_ARGS) nArgs -= PAIRED_VAR_ARGS - 2;
14371b1b70fbSAndrew Rist else if (nArgs >= VAR_ARGS) nArgs -= VAR_ARGS - 1;
1438cdf0e10cSrcweir if (nArgs)
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir for (sal_uInt16 i=0; i<nArgs; i++ )
1441cdf0e10cSrcweir {
1442cdf0e10cSrcweir delete ppDefArgNames[i];
1443cdf0e10cSrcweir delete ppDefArgDescs[i];
1444cdf0e10cSrcweir }
1445cdf0e10cSrcweir delete [] ppDefArgNames;
1446cdf0e10cSrcweir delete [] ppDefArgDescs;
1447cdf0e10cSrcweir delete [] pDefArgFlags;
1448cdf0e10cSrcweir }
1449cdf0e10cSrcweir nArgCount = 0;
1450cdf0e10cSrcweir ppDefArgNames = NULL;
1451cdf0e10cSrcweir ppDefArgDescs = NULL;
1452cdf0e10cSrcweir pDefArgFlags = NULL;
1453cdf0e10cSrcweir
1454cdf0e10cSrcweir delete pFuncName;
1455cdf0e10cSrcweir pFuncName = NULL;
1456cdf0e10cSrcweir
1457cdf0e10cSrcweir delete pFuncDesc;
1458cdf0e10cSrcweir pFuncDesc = NULL;
1459cdf0e10cSrcweir
1460cdf0e10cSrcweir nFIndex = 0;
1461cdf0e10cSrcweir nCategory = 0;
1462cdf0e10cSrcweir sHelpId = "";
1463cdf0e10cSrcweir bIncomplete = false;
1464cdf0e10cSrcweir bHasSuppressedArgs = false;
1465cdf0e10cSrcweir }
1466cdf0e10cSrcweir
1467cdf0e10cSrcweir //------------------------------------------------------------------------
1468cdf0e10cSrcweir
GetParamList() const1469cdf0e10cSrcweir String ScFuncDesc::GetParamList() const
1470cdf0e10cSrcweir {
1471cdf0e10cSrcweir const String& sep = ScCompiler::GetNativeSymbol(ocSep);
1472cdf0e10cSrcweir
1473cdf0e10cSrcweir String aSig;
1474cdf0e10cSrcweir
1475cdf0e10cSrcweir if ( nArgCount > 0 )
1476cdf0e10cSrcweir {
1477cdf0e10cSrcweir if ( nArgCount < VAR_ARGS )
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir sal_uInt16 nLastSuppressed = nArgCount;
1480cdf0e10cSrcweir sal_uInt16 nLastAdded = nArgCount;
1481cdf0e10cSrcweir for ( sal_uInt16 i=0; i<nArgCount; i++ )
1482cdf0e10cSrcweir {
1483cdf0e10cSrcweir if (pDefArgFlags[i].bSuppress)
1484cdf0e10cSrcweir nLastSuppressed = i;
1485cdf0e10cSrcweir else
1486cdf0e10cSrcweir {
1487cdf0e10cSrcweir nLastAdded = i;
1488cdf0e10cSrcweir aSig += *(ppDefArgNames[i]);
1489cdf0e10cSrcweir if ( i != nArgCount-1 )
1490cdf0e10cSrcweir {
1491cdf0e10cSrcweir aSig.Append(sep);
1492cdf0e10cSrcweir aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " " ));
1493cdf0e10cSrcweir }
1494cdf0e10cSrcweir }
1495cdf0e10cSrcweir }
1496cdf0e10cSrcweir // If only suppressed parameters follow the last added parameter,
1497cdf0e10cSrcweir // remove one "; "
1498cdf0e10cSrcweir if (nLastSuppressed < nArgCount && nLastAdded < nLastSuppressed &&
1499cdf0e10cSrcweir aSig.Len() >= 2)
1500cdf0e10cSrcweir aSig.Erase( aSig.Len() - 2 );
1501cdf0e10cSrcweir }
15021b1b70fbSAndrew Rist else if ( nArgCount < PAIRED_VAR_ARGS)
1503cdf0e10cSrcweir {
1504cdf0e10cSrcweir sal_uInt16 nFix = nArgCount - VAR_ARGS;
1505cdf0e10cSrcweir for ( sal_uInt16 nArg = 0; nArg < nFix; nArg++ )
1506cdf0e10cSrcweir {
1507cdf0e10cSrcweir if (!pDefArgFlags[nArg].bSuppress)
1508cdf0e10cSrcweir {
1509cdf0e10cSrcweir aSig += *(ppDefArgNames[nArg]);
1510cdf0e10cSrcweir aSig.Append(sep);
1511cdf0e10cSrcweir aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " " ));
1512cdf0e10cSrcweir }
1513cdf0e10cSrcweir }
1514cdf0e10cSrcweir /* NOTE: Currently there are no suppressed var args parameters. If
1515cdf0e10cSrcweir * there were, we'd have to cope with it here and above for the fix
1516cdf0e10cSrcweir * parameters. For now parameters are always added, so no special
1517cdf0e10cSrcweir * treatment of a trailing "; " necessary. */
1518cdf0e10cSrcweir aSig += *(ppDefArgNames[nFix]);
1519cdf0e10cSrcweir aSig += '1';
1520cdf0e10cSrcweir aSig.Append(sep);
1521cdf0e10cSrcweir aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " " ));
1522cdf0e10cSrcweir aSig += *(ppDefArgNames[nFix]);
1523cdf0e10cSrcweir aSig += '2';
1524cdf0e10cSrcweir aSig.Append(sep);
1525cdf0e10cSrcweir aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " ... " ));
1526cdf0e10cSrcweir }
15271b1b70fbSAndrew Rist else
15281b1b70fbSAndrew Rist {
15291b1b70fbSAndrew Rist sal_uInt16 nFix = nArgCount - PAIRED_VAR_ARGS;
15301b1b70fbSAndrew Rist for ( sal_uInt16 nArg = 0; nArg < nFix; nArg++ )
15311b1b70fbSAndrew Rist {
15321b1b70fbSAndrew Rist if (!pDefArgFlags[nArg].bSuppress)
15331b1b70fbSAndrew Rist {
15341b1b70fbSAndrew Rist aSig += *(ppDefArgNames[nArg]);
15351b1b70fbSAndrew Rist aSig.Append(sep);
15361b1b70fbSAndrew Rist aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " " ));
15371b1b70fbSAndrew Rist }
15381b1b70fbSAndrew Rist }
15391b1b70fbSAndrew Rist
15401b1b70fbSAndrew Rist aSig += *(ppDefArgNames[nFix]);
15411b1b70fbSAndrew Rist aSig += '1';
15421b1b70fbSAndrew Rist aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
15431b1b70fbSAndrew Rist aSig += *(ppDefArgNames[nFix+1]);
15441b1b70fbSAndrew Rist aSig += '1';
15451b1b70fbSAndrew Rist aSig.Append(sep);
15461b1b70fbSAndrew Rist aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " " ));
15471b1b70fbSAndrew Rist aSig += *(ppDefArgNames[nFix]);
15481b1b70fbSAndrew Rist aSig += '2';
15491b1b70fbSAndrew Rist aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
15501b1b70fbSAndrew Rist aSig += *(ppDefArgNames[nFix+1]);
15511b1b70fbSAndrew Rist aSig += '2';
15521b1b70fbSAndrew Rist aSig.Append(sep);
15531b1b70fbSAndrew Rist aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " ... " ));
15541b1b70fbSAndrew Rist }
1555cdf0e10cSrcweir }
1556cdf0e10cSrcweir
1557cdf0e10cSrcweir return aSig;
1558cdf0e10cSrcweir }
1559cdf0e10cSrcweir
1560cdf0e10cSrcweir //------------------------------------------------------------------------
1561cdf0e10cSrcweir
GetSignature() const1562cdf0e10cSrcweir String ScFuncDesc::GetSignature() const
1563cdf0e10cSrcweir {
1564cdf0e10cSrcweir String aSig;
1565cdf0e10cSrcweir
1566cdf0e10cSrcweir if(pFuncName)
1567cdf0e10cSrcweir {
1568cdf0e10cSrcweir aSig = *pFuncName;
1569cdf0e10cSrcweir
1570cdf0e10cSrcweir String aParamList( GetParamList() );
1571cdf0e10cSrcweir if( aParamList.Len() )
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "( " ));
1574cdf0e10cSrcweir aSig.Append( aParamList );
1575cdf0e10cSrcweir // U+00A0 (NBSP) prevents automatic line break
1576cdf0e10cSrcweir aSig.Append( static_cast< sal_Unicode >(0xA0) ).Append( ')' );
1577cdf0e10cSrcweir }
1578cdf0e10cSrcweir else
1579cdf0e10cSrcweir aSig.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" ));
1580cdf0e10cSrcweir }
1581cdf0e10cSrcweir return aSig;
1582cdf0e10cSrcweir }
1583cdf0e10cSrcweir
1584cdf0e10cSrcweir //------------------------------------------------------------------------
1585cdf0e10cSrcweir
getFormula(const::std::vector<::rtl::OUString> & _aArguments) const1586cdf0e10cSrcweir ::rtl::OUString ScFuncDesc::getFormula( const ::std::vector< ::rtl::OUString >& _aArguments ) const
1587cdf0e10cSrcweir {
1588cdf0e10cSrcweir const String& sep = ScCompiler::GetNativeSymbol(ocSep);
1589cdf0e10cSrcweir
1590cdf0e10cSrcweir ::rtl::OUStringBuffer aFormula;
1591cdf0e10cSrcweir
1592cdf0e10cSrcweir if(pFuncName)
1593cdf0e10cSrcweir {
1594cdf0e10cSrcweir aFormula.append( *pFuncName );
1595cdf0e10cSrcweir
1596cdf0e10cSrcweir aFormula.appendAscii( "(" );
1597cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator aIter = _aArguments.begin();
1598cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator aEnd = _aArguments.end();
1599cdf0e10cSrcweir
1600cdf0e10cSrcweir if ( nArgCount > 0 && aIter != aEnd )
1601cdf0e10cSrcweir {
1602cdf0e10cSrcweir sal_Bool bLastArg = ( aIter->getLength() == 0 );
1603cdf0e10cSrcweir
1604cdf0e10cSrcweir while( aIter != aEnd && !bLastArg )
1605cdf0e10cSrcweir {
1606cdf0e10cSrcweir aFormula.append( *(aIter) );
1607cdf0e10cSrcweir if ( aIter != (aEnd-1) )
1608cdf0e10cSrcweir {
1609cdf0e10cSrcweir bLastArg = !( (aIter+1)->getLength() > 0 );
1610cdf0e10cSrcweir if ( !bLastArg )
1611cdf0e10cSrcweir aFormula.append( sep );
1612cdf0e10cSrcweir }
1613cdf0e10cSrcweir
1614cdf0e10cSrcweir ++aIter;
1615cdf0e10cSrcweir }
1616cdf0e10cSrcweir }
1617cdf0e10cSrcweir
1618cdf0e10cSrcweir aFormula.appendAscii( ")" );
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir return aFormula.makeStringAndClear();
1621cdf0e10cSrcweir }
1622cdf0e10cSrcweir
1623cdf0e10cSrcweir //------------------------------------------------------------------------
1624cdf0e10cSrcweir
GetSuppressedArgCount() const1625cdf0e10cSrcweir sal_uInt16 ScFuncDesc::GetSuppressedArgCount() const
1626cdf0e10cSrcweir {
1627cdf0e10cSrcweir if (!bHasSuppressedArgs || !pDefArgFlags)
1628cdf0e10cSrcweir return nArgCount;
1629cdf0e10cSrcweir
1630cdf0e10cSrcweir sal_uInt16 nArgs = nArgCount;
16311b1b70fbSAndrew Rist if (nArgs >= PAIRED_VAR_ARGS)
16321b1b70fbSAndrew Rist nArgs -= PAIRED_VAR_ARGS - 2;
16331b1b70fbSAndrew Rist else if (nArgs >= VAR_ARGS)
1634cdf0e10cSrcweir nArgs -= VAR_ARGS - 1;
1635cdf0e10cSrcweir sal_uInt16 nCount = nArgs;
1636cdf0e10cSrcweir for (sal_uInt16 i=0; i < nArgs; ++i)
1637cdf0e10cSrcweir {
1638cdf0e10cSrcweir if (pDefArgFlags[i].bSuppress)
1639cdf0e10cSrcweir --nCount;
1640cdf0e10cSrcweir }
16411b1b70fbSAndrew Rist if (nArgCount >= PAIRED_VAR_ARGS)
16421b1b70fbSAndrew Rist nCount += PAIRED_VAR_ARGS - 2;
16431b1b70fbSAndrew Rist else if (nArgCount >= VAR_ARGS)
1644cdf0e10cSrcweir nCount += VAR_ARGS - 1;
1645cdf0e10cSrcweir return nCount;
1646cdf0e10cSrcweir }
1647cdf0e10cSrcweir
1648cdf0e10cSrcweir //------------------------------------------------------------------------
1649cdf0e10cSrcweir
getFunctionName() const1650cdf0e10cSrcweir ::rtl::OUString ScFuncDesc::getFunctionName() const
1651cdf0e10cSrcweir {
1652cdf0e10cSrcweir ::rtl::OUString sRet;
1653cdf0e10cSrcweir if ( pFuncName )
1654cdf0e10cSrcweir sRet = *pFuncName;
1655cdf0e10cSrcweir return sRet;
1656cdf0e10cSrcweir }
1657cdf0e10cSrcweir // -----------------------------------------------------------------------------
getCategory() const1658cdf0e10cSrcweir const formula::IFunctionCategory* ScFuncDesc::getCategory() const
1659cdf0e10cSrcweir {
1660cdf0e10cSrcweir return ScGlobal::GetStarCalcFunctionMgr()->getCategory(nCategory);
1661cdf0e10cSrcweir }
1662cdf0e10cSrcweir // -----------------------------------------------------------------------------
getDescription() const1663cdf0e10cSrcweir ::rtl::OUString ScFuncDesc::getDescription() const
1664cdf0e10cSrcweir {
1665cdf0e10cSrcweir ::rtl::OUString sRet;
1666cdf0e10cSrcweir if ( pFuncDesc )
1667cdf0e10cSrcweir sRet = *pFuncDesc;
1668cdf0e10cSrcweir return sRet;
1669cdf0e10cSrcweir }
1670cdf0e10cSrcweir // -----------------------------------------------------------------------------
1671cdf0e10cSrcweir // GetSuppressedArgCount
getSuppressedArgumentCount() const1672cdf0e10cSrcweir xub_StrLen ScFuncDesc::getSuppressedArgumentCount() const
1673cdf0e10cSrcweir {
1674cdf0e10cSrcweir return GetSuppressedArgCount();
1675cdf0e10cSrcweir }
1676cdf0e10cSrcweir // -----------------------------------------------------------------------------
1677cdf0e10cSrcweir //
fillVisibleArgumentMapping(::std::vector<sal_uInt16> & _rArguments) const1678cdf0e10cSrcweir void ScFuncDesc::fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const
1679cdf0e10cSrcweir {
1680cdf0e10cSrcweir if (!bHasSuppressedArgs || !pDefArgFlags)
1681cdf0e10cSrcweir {
1682cdf0e10cSrcweir _rArguments.resize( nArgCount);
168383d0117dSHerbert Dürr ::std::vector<sal_uInt16>::iterator it = _rArguments.begin();
168483d0117dSHerbert Dürr for( sal_uInt16 n = 0; n < nArgCount; ++n, ++it )
168583d0117dSHerbert Dürr *it = n;
1686cdf0e10cSrcweir }
1687cdf0e10cSrcweir
1688cdf0e10cSrcweir _rArguments.reserve( nArgCount);
1689cdf0e10cSrcweir sal_uInt16 nArgs = nArgCount;
16901b1b70fbSAndrew Rist if (nArgs >= PAIRED_VAR_ARGS)
16911b1b70fbSAndrew Rist nArgs -= PAIRED_VAR_ARGS - 2;
16921b1b70fbSAndrew Rist else if (nArgs >= VAR_ARGS)
1693cdf0e10cSrcweir nArgs -= VAR_ARGS - 1;
1694cdf0e10cSrcweir for (sal_uInt16 i=0; i < nArgs; ++i)
1695cdf0e10cSrcweir {
1696cdf0e10cSrcweir if (!pDefArgFlags[i].bSuppress)
1697cdf0e10cSrcweir _rArguments.push_back(i);
1698cdf0e10cSrcweir }
1699cdf0e10cSrcweir }
1700cdf0e10cSrcweir // -----------------------------------------------------------------------------
initArgumentInfo() const1701cdf0e10cSrcweir void ScFuncDesc::initArgumentInfo() const
1702cdf0e10cSrcweir {
1703cdf0e10cSrcweir // get the full argument description
1704cdf0e10cSrcweir // (add-in has to be instantiated to get the type information)
1705cdf0e10cSrcweir
1706cdf0e10cSrcweir if ( bIncomplete && pFuncName )
1707cdf0e10cSrcweir {
1708cdf0e10cSrcweir ScUnoAddInCollection& rAddIns = *ScGlobal::GetAddInCollection();
1709cdf0e10cSrcweir String aIntName = rAddIns.FindFunction( *pFuncName, sal_True ); // pFuncName is upper-case
1710cdf0e10cSrcweir
1711cdf0e10cSrcweir if ( aIntName.Len() )
1712cdf0e10cSrcweir {
1713cdf0e10cSrcweir // GetFuncData with bComplete=true loads the component and updates
1714cdf0e10cSrcweir // the global function list if needed.
1715cdf0e10cSrcweir
1716cdf0e10cSrcweir rAddIns.GetFuncData( aIntName, true );
1717cdf0e10cSrcweir }
1718cdf0e10cSrcweir
1719cdf0e10cSrcweir if ( bIncomplete )
1720cdf0e10cSrcweir {
1721cdf0e10cSrcweir DBG_ERRORFILE( "couldn't initialize add-in function" );
1722cdf0e10cSrcweir const_cast<ScFuncDesc*>(this)->bIncomplete = sal_False; // even if there was an error, don't try again
1723cdf0e10cSrcweir }
1724cdf0e10cSrcweir }
1725cdf0e10cSrcweir }
1726cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSignature() const1727cdf0e10cSrcweir ::rtl::OUString ScFuncDesc::getSignature() const
1728cdf0e10cSrcweir {
1729cdf0e10cSrcweir return GetSignature();
1730cdf0e10cSrcweir }
1731cdf0e10cSrcweir // -----------------------------------------------------------------------------
getHelpId() const1732cdf0e10cSrcweir rtl::OString ScFuncDesc::getHelpId() const
1733cdf0e10cSrcweir {
1734cdf0e10cSrcweir return sHelpId;
1735cdf0e10cSrcweir }
1736cdf0e10cSrcweir // -----------------------------------------------------------------------------
1737cdf0e10cSrcweir
1738cdf0e10cSrcweir // parameter
getParameterCount() const1739cdf0e10cSrcweir sal_uInt32 ScFuncDesc::getParameterCount() const
1740cdf0e10cSrcweir {
1741cdf0e10cSrcweir return nArgCount;
1742cdf0e10cSrcweir }
1743cdf0e10cSrcweir // -----------------------------------------------------------------------------
getParameterName(sal_uInt32 _nPos) const1744cdf0e10cSrcweir ::rtl::OUString ScFuncDesc::getParameterName(sal_uInt32 _nPos) const
1745cdf0e10cSrcweir {
1746cdf0e10cSrcweir return *(ppDefArgNames[_nPos]);
1747cdf0e10cSrcweir }
1748cdf0e10cSrcweir // -----------------------------------------------------------------------------
getParameterDescription(sal_uInt32 _nPos) const1749cdf0e10cSrcweir ::rtl::OUString ScFuncDesc::getParameterDescription(sal_uInt32 _nPos) const
1750cdf0e10cSrcweir {
1751cdf0e10cSrcweir return *(ppDefArgDescs[_nPos]);
1752cdf0e10cSrcweir }
1753cdf0e10cSrcweir // -----------------------------------------------------------------------------
isParameterOptional(sal_uInt32 _nPos) const1754cdf0e10cSrcweir bool ScFuncDesc::isParameterOptional(sal_uInt32 _nPos) const
1755cdf0e10cSrcweir {
1756cdf0e10cSrcweir return pDefArgFlags[_nPos].bOptional;
1757cdf0e10cSrcweir }
1758cdf0e10cSrcweir // -----------------------------------------------------------------------------
1759cdf0e10cSrcweir //========================================================================
1760cdf0e10cSrcweir // class ScFunctionMgr:
1761cdf0e10cSrcweir
ScFunctionMgr()1762cdf0e10cSrcweir ScFunctionMgr::ScFunctionMgr()
1763cdf0e10cSrcweir : pFuncList ( ScGlobal::GetStarCalcFunctionList() ),
1764cdf0e10cSrcweir pCurCatList ( NULL )
1765cdf0e10cSrcweir {
1766cdf0e10cSrcweir DBG_ASSERT( pFuncList, "Funktionsliste nicht gefunden." );
1767cdf0e10cSrcweir sal_uLong nCount = pFuncList->GetCount();
1768cdf0e10cSrcweir const ScFuncDesc* pDesc;
1769cdf0e10cSrcweir List* pRootList;
1770cdf0e10cSrcweir sal_uLong n;
1771cdf0e10cSrcweir
1772cdf0e10cSrcweir for ( sal_uInt16 i=0; i<MAX_FUNCCAT; i++ ) // Kategorie-Listen erstellen
1773cdf0e10cSrcweir aCatLists[i] = new List;
1774cdf0e10cSrcweir
1775cdf0e10cSrcweir pRootList = aCatLists[0]; // Gesamtliste ("Alle") erstellen
1776cdf0e10cSrcweir CollatorWrapper* pCaseCollator = ScGlobal::GetCaseCollator();
1777cdf0e10cSrcweir for ( n=0; n<nCount; n++ )
1778cdf0e10cSrcweir {
1779cdf0e10cSrcweir sal_uLong nTmpCnt=0;
1780cdf0e10cSrcweir pDesc = pFuncList->GetFunction(n);
1781cdf0e10cSrcweir for (nTmpCnt = 0; nTmpCnt < n; nTmpCnt++)
1782cdf0e10cSrcweir {
1783cdf0e10cSrcweir // ist zwar case-sensitiv, aber Umlaute muessen richtig einsortiert werden
1784cdf0e10cSrcweir
1785cdf0e10cSrcweir const ScFuncDesc* pTmpDesc = (const ScFuncDesc*)pRootList->GetObject(nTmpCnt);
1786cdf0e10cSrcweir if ( pCaseCollator->compareString(*pDesc->pFuncName, *pTmpDesc->pFuncName ) == COMPARE_LESS )
1787cdf0e10cSrcweir break;
1788cdf0e10cSrcweir }
1789cdf0e10cSrcweir pRootList->Insert((void*)pDesc, nTmpCnt); // Einsortieren
1790cdf0e10cSrcweir }
1791cdf0e10cSrcweir
1792cdf0e10cSrcweir for ( n=0; n<nCount; n++ ) // in Gruppenlisten kopieren
1793cdf0e10cSrcweir {
1794cdf0e10cSrcweir pDesc = (const ScFuncDesc*)pRootList->GetObject(n);
1795cdf0e10cSrcweir DBG_ASSERT((pDesc->nCategory) < MAX_FUNCCAT, "Unbekannte Kategorie");
1796cdf0e10cSrcweir if ((pDesc->nCategory) < MAX_FUNCCAT)
1797cdf0e10cSrcweir aCatLists[pDesc->nCategory]->Insert((void*)pDesc, LIST_APPEND);
1798cdf0e10cSrcweir }
1799cdf0e10cSrcweir }
1800cdf0e10cSrcweir
1801cdf0e10cSrcweir //------------------------------------------------------------------------
1802cdf0e10cSrcweir
~ScFunctionMgr()1803cdf0e10cSrcweir ScFunctionMgr::~ScFunctionMgr()
1804cdf0e10cSrcweir {
1805cdf0e10cSrcweir for (sal_uInt16 i = 0; i < MAX_FUNCCAT; i++)
1806cdf0e10cSrcweir delete aCatLists[i];
1807cdf0e10cSrcweir // delete pFuncList; // Macht spaeter die App
1808cdf0e10cSrcweir }
1809cdf0e10cSrcweir
1810cdf0e10cSrcweir //------------------------------------------------------------------------
1811cdf0e10cSrcweir
Get(const String & rFName) const1812cdf0e10cSrcweir const ScFuncDesc* ScFunctionMgr::Get( const String& rFName ) const
1813cdf0e10cSrcweir {
1814cdf0e10cSrcweir const ScFuncDesc* pDesc = NULL;
1815cdf0e10cSrcweir if (rFName.Len() <= pFuncList->GetMaxFuncNameLen())
1816cdf0e10cSrcweir for (pDesc = First(0); pDesc; pDesc = Next())
1817cdf0e10cSrcweir if (rFName.EqualsIgnoreCaseAscii(*(pDesc->pFuncName)))
1818cdf0e10cSrcweir break;
1819cdf0e10cSrcweir return pDesc;
1820cdf0e10cSrcweir }
1821cdf0e10cSrcweir
1822cdf0e10cSrcweir //------------------------------------------------------------------------
1823cdf0e10cSrcweir
Get(sal_uInt16 nFIndex) const1824cdf0e10cSrcweir const ScFuncDesc* ScFunctionMgr::Get( sal_uInt16 nFIndex ) const
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir const ScFuncDesc* pDesc;
1827cdf0e10cSrcweir for (pDesc = First(0); pDesc; pDesc = Next())
1828cdf0e10cSrcweir if (pDesc->nFIndex == nFIndex)
1829cdf0e10cSrcweir break;
1830cdf0e10cSrcweir return pDesc;
1831cdf0e10cSrcweir }
1832cdf0e10cSrcweir
1833cdf0e10cSrcweir //------------------------------------------------------------------------
1834cdf0e10cSrcweir
First(sal_uInt16 nCategory) const1835cdf0e10cSrcweir const ScFuncDesc* ScFunctionMgr::First( sal_uInt16 nCategory ) const
1836cdf0e10cSrcweir {
1837cdf0e10cSrcweir DBG_ASSERT( nCategory < MAX_FUNCCAT, "Unbekannte Kategorie" );
1838cdf0e10cSrcweir
1839cdf0e10cSrcweir if ( nCategory < MAX_FUNCCAT )
1840cdf0e10cSrcweir {
1841cdf0e10cSrcweir pCurCatList = aCatLists[nCategory];
1842cdf0e10cSrcweir return (const ScFuncDesc*)pCurCatList->First();
1843cdf0e10cSrcweir }
1844cdf0e10cSrcweir else
1845cdf0e10cSrcweir {
1846cdf0e10cSrcweir pCurCatList = NULL;
1847cdf0e10cSrcweir return NULL;
1848cdf0e10cSrcweir }
1849cdf0e10cSrcweir }
1850cdf0e10cSrcweir
1851cdf0e10cSrcweir //------------------------------------------------------------------------
1852cdf0e10cSrcweir
Next() const1853cdf0e10cSrcweir const ScFuncDesc* ScFunctionMgr::Next() const
1854cdf0e10cSrcweir {
1855cdf0e10cSrcweir if ( pCurCatList )
1856cdf0e10cSrcweir return (const ScFuncDesc*)pCurCatList->Next();
1857cdf0e10cSrcweir else
1858cdf0e10cSrcweir return NULL;
1859cdf0e10cSrcweir }
getCount() const1860cdf0e10cSrcweir sal_uInt32 ScFunctionMgr::getCount() const
1861cdf0e10cSrcweir {
1862cdf0e10cSrcweir return MAX_FUNCCAT - 1;
1863cdf0e10cSrcweir }
getCategory(sal_uInt32 nCategory) const1864cdf0e10cSrcweir const formula::IFunctionCategory* ScFunctionMgr::getCategory(sal_uInt32 nCategory) const
1865cdf0e10cSrcweir {
1866cdf0e10cSrcweir formula::IFunctionCategory* pRet = NULL;
1867cdf0e10cSrcweir if ( nCategory < (MAX_FUNCCAT-1) )
1868cdf0e10cSrcweir {
1869cdf0e10cSrcweir pRet = new ScFunctionCategory(const_cast<ScFunctionMgr*>(this),aCatLists[nCategory+1],nCategory); // aCatLists[0] is "all"
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir return pRet;
1872cdf0e10cSrcweir }
1873cdf0e10cSrcweir // -----------------------------------------------------------------------------
getFunctionByName(const::rtl::OUString & _sFunctionName) const1874cdf0e10cSrcweir const formula::IFunctionDescription* ScFunctionMgr::getFunctionByName(const ::rtl::OUString& _sFunctionName) const
1875cdf0e10cSrcweir {
1876cdf0e10cSrcweir return Get(_sFunctionName);
1877cdf0e10cSrcweir }
1878cdf0e10cSrcweir // -----------------------------------------------------------------------------
fillLastRecentlyUsedFunctions(::std::vector<const formula::IFunctionDescription * > & _rLastRUFunctions) const1879cdf0e10cSrcweir void ScFunctionMgr::fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& _rLastRUFunctions) const
1880cdf0e10cSrcweir {
1881cdf0e10cSrcweir #define LRU_MAX 10
1882cdf0e10cSrcweir
1883cdf0e10cSrcweir const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
1884cdf0e10cSrcweir sal_uInt16 nLRUFuncCount = Min( rAppOpt.GetLRUFuncListCount(), (sal_uInt16)LRU_MAX );
1885cdf0e10cSrcweir sal_uInt16* pLRUListIds = rAppOpt.GetLRUFuncList();
1886cdf0e10cSrcweir
1887cdf0e10cSrcweir if ( pLRUListIds )
1888cdf0e10cSrcweir {
1889cdf0e10cSrcweir for ( sal_uInt16 i=0; i<nLRUFuncCount; i++ )
1890cdf0e10cSrcweir _rLastRUFunctions.push_back( Get( pLRUListIds[i] ) );
1891cdf0e10cSrcweir }
1892cdf0e10cSrcweir }
1893cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetCategoryName(sal_uInt32 _nCategoryNumber)1894cdf0e10cSrcweir String ScFunctionMgr::GetCategoryName(sal_uInt32 _nCategoryNumber )
1895cdf0e10cSrcweir {
1896cdf0e10cSrcweir if ( _nCategoryNumber > SC_FUNCGROUP_COUNT )
1897cdf0e10cSrcweir {
1898cdf0e10cSrcweir DBG_ERROR("Invalid category number!");
1899cdf0e10cSrcweir return String();
1900cdf0e10cSrcweir } // if ( _nCategoryNumber >= SC_FUNCGROUP_COUNT )
1901cdf0e10cSrcweir
1902cdf0e10cSrcweir ::std::auto_ptr<ScResourcePublisher> pCategories( new ScResourcePublisher( ScResId( RID_FUNCTION_CATEGORIES ) ) );
1903cdf0e10cSrcweir return String(ScResId((sal_uInt16)_nCategoryNumber));
1904cdf0e10cSrcweir }
getSingleToken(const formula::IFunctionManager::EToken _eToken) const1905cdf0e10cSrcweir sal_Unicode ScFunctionMgr::getSingleToken(const formula::IFunctionManager::EToken _eToken) const
1906cdf0e10cSrcweir {
1907cdf0e10cSrcweir switch(_eToken)
1908cdf0e10cSrcweir {
1909cdf0e10cSrcweir case eOk:
1910cdf0e10cSrcweir return ScCompiler::GetNativeSymbol(ocOpen).GetChar(0);
1911cdf0e10cSrcweir case eClose:
1912cdf0e10cSrcweir return ScCompiler::GetNativeSymbol(ocClose).GetChar(0);
1913cdf0e10cSrcweir case eSep:
1914cdf0e10cSrcweir return ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
1915cdf0e10cSrcweir case eArrayOpen:
1916cdf0e10cSrcweir return ScCompiler::GetNativeSymbol(ocArrayOpen).GetChar(0);
1917cdf0e10cSrcweir case eArrayClose:
1918cdf0e10cSrcweir return ScCompiler::GetNativeSymbol(ocArrayClose).GetChar(0);
1919cdf0e10cSrcweir } // switch(_eToken)
1920cdf0e10cSrcweir return 0;
1921cdf0e10cSrcweir }
1922cdf0e10cSrcweir // -----------------------------------------------------------------------------
getCount() const1923cdf0e10cSrcweir sal_uInt32 ScFunctionCategory::getCount() const
1924cdf0e10cSrcweir {
1925cdf0e10cSrcweir return m_pCategory->Count();
1926cdf0e10cSrcweir }
1927cdf0e10cSrcweir // -----------------------------------------------------------------------------
getFunctionManager() const1928cdf0e10cSrcweir const formula::IFunctionManager* ScFunctionCategory::getFunctionManager() const
1929cdf0e10cSrcweir {
1930cdf0e10cSrcweir return m_pMgr;
1931cdf0e10cSrcweir }
1932cdf0e10cSrcweir // -----------------------------------------------------------------------------
getName() const1933cdf0e10cSrcweir ::rtl::OUString ScFunctionCategory::getName() const
1934cdf0e10cSrcweir {
1935cdf0e10cSrcweir if ( !m_sName.getLength() )
1936cdf0e10cSrcweir m_sName = ScFunctionMgr::GetCategoryName(m_nCategory+1);
1937cdf0e10cSrcweir return m_sName;
1938cdf0e10cSrcweir }
1939cdf0e10cSrcweir // -----------------------------------------------------------------------------
getFunction(sal_uInt32 _nPos) const1940cdf0e10cSrcweir const formula::IFunctionDescription* ScFunctionCategory::getFunction(sal_uInt32 _nPos) const
1941cdf0e10cSrcweir {
1942cdf0e10cSrcweir const ScFuncDesc* pDesc = NULL;
1943cdf0e10cSrcweir sal_uInt32 i = 0;
1944cdf0e10cSrcweir for (pDesc = (const ScFuncDesc*)m_pCategory->First(); i < _nPos && pDesc; pDesc = (const ScFuncDesc*)m_pCategory->Next(),++i)
1945cdf0e10cSrcweir ;
1946cdf0e10cSrcweir return pDesc;
1947cdf0e10cSrcweir }
1948cdf0e10cSrcweir // -----------------------------------------------------------------------------
getNumber() const1949cdf0e10cSrcweir sal_uInt32 ScFunctionCategory::getNumber() const
1950cdf0e10cSrcweir {
1951cdf0e10cSrcweir return m_nCategory;
1952cdf0e10cSrcweir }
1953cdf0e10cSrcweir // -----------------------------------------------------------------------------
1954cdf0e10cSrcweir
1955cdf0e10cSrcweir //------------------------------------------------------------------------
1956cdf0e10cSrcweir
GetpTransliteration()1957cdf0e10cSrcweir utl::TransliterationWrapper* ScGlobal::GetpTransliteration() //add by CHINA001
1958cdf0e10cSrcweir {
1959cdf0e10cSrcweir if ( !pTransliteration )
1960cdf0e10cSrcweir {
1961cdf0e10cSrcweir const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguage();
1962cdf0e10cSrcweir pTransliteration = new ::utl::TransliterationWrapper(
1963cdf0e10cSrcweir ::comphelper::getProcessServiceFactory(), SC_TRANSLITERATION_IGNORECASE );
1964cdf0e10cSrcweir pTransliteration->loadModuleIfNeeded( eOfficeLanguage );
1965cdf0e10cSrcweir }
1966cdf0e10cSrcweir DBG_ASSERT(
1967cdf0e10cSrcweir pTransliteration,
1968cdf0e10cSrcweir "ScGlobal::GetpTransliteration() called before ScGlobal::Init()");
1969cdf0e10cSrcweir return pTransliteration;
1970cdf0e10cSrcweir }
1971cdf0e10cSrcweir
GetpLocaleData()1972cdf0e10cSrcweir const LocaleDataWrapper* ScGlobal::GetpLocaleData()
1973cdf0e10cSrcweir {
1974cdf0e10cSrcweir DBG_ASSERT(
1975cdf0e10cSrcweir pLocaleData,
1976cdf0e10cSrcweir "ScGlobal::GetpLocaleData() called before ScGlobal::Init()");
1977cdf0e10cSrcweir return pLocaleData;
1978cdf0e10cSrcweir }
GetCalendar()1979cdf0e10cSrcweir CalendarWrapper* ScGlobal::GetCalendar()
1980cdf0e10cSrcweir {
1981cdf0e10cSrcweir if ( !pCalendar )
1982cdf0e10cSrcweir {
1983cdf0e10cSrcweir pCalendar = new CalendarWrapper( ::comphelper::getProcessServiceFactory() );
1984cdf0e10cSrcweir pCalendar->loadDefaultCalendar( *GetLocale() );
1985cdf0e10cSrcweir }
1986cdf0e10cSrcweir return pCalendar;
1987cdf0e10cSrcweir }
GetCollator()1988cdf0e10cSrcweir CollatorWrapper* ScGlobal::GetCollator()
1989cdf0e10cSrcweir {
1990cdf0e10cSrcweir if ( !pCollator )
1991cdf0e10cSrcweir {
1992cdf0e10cSrcweir pCollator = new CollatorWrapper( ::comphelper::getProcessServiceFactory() );
1993cdf0e10cSrcweir pCollator->loadDefaultCollator( *GetLocale(), SC_COLLATOR_IGNORES );
1994cdf0e10cSrcweir } // if ( !pCollator )
1995cdf0e10cSrcweir return pCollator;
1996cdf0e10cSrcweir }
GetCaseCollator()1997cdf0e10cSrcweir CollatorWrapper* ScGlobal::GetCaseCollator()
1998cdf0e10cSrcweir {
1999cdf0e10cSrcweir if ( !pCaseCollator )
2000cdf0e10cSrcweir {
2001cdf0e10cSrcweir pCaseCollator = new CollatorWrapper( ::comphelper::getProcessServiceFactory() );
2002cdf0e10cSrcweir pCaseCollator->loadDefaultCollator( *GetLocale(), 0 );
2003cdf0e10cSrcweir } // if ( !pCaseCollator )
2004cdf0e10cSrcweir return pCaseCollator;
2005cdf0e10cSrcweir }
GetCaseTransliteration()2006cdf0e10cSrcweir ::utl::TransliterationWrapper* ScGlobal::GetCaseTransliteration()
2007cdf0e10cSrcweir {
2008cdf0e10cSrcweir if ( !pCaseTransliteration )
2009cdf0e10cSrcweir {
2010cdf0e10cSrcweir const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguage();
2011cdf0e10cSrcweir pCaseTransliteration = new ::utl::TransliterationWrapper(::comphelper::getProcessServiceFactory(), SC_TRANSLITERATION_CASESENSE );
2012cdf0e10cSrcweir pCaseTransliteration->loadModuleIfNeeded( eOfficeLanguage );
2013cdf0e10cSrcweir } // if ( !pCaseTransliteration )
2014cdf0e10cSrcweir return pCaseTransliteration;
2015cdf0e10cSrcweir }
GetScIntlWrapper()2016cdf0e10cSrcweir IntlWrapper* ScGlobal::GetScIntlWrapper()
2017cdf0e10cSrcweir {
2018cdf0e10cSrcweir if ( !pScIntlWrapper )
2019cdf0e10cSrcweir {
2020cdf0e10cSrcweir pScIntlWrapper = new IntlWrapper( ::comphelper::getProcessServiceFactory(), *GetLocale() );
2021cdf0e10cSrcweir }
2022cdf0e10cSrcweir return pScIntlWrapper;
2023cdf0e10cSrcweir }
GetLocale()2024cdf0e10cSrcweir ::com::sun::star::lang::Locale* ScGlobal::GetLocale()
2025cdf0e10cSrcweir {
2026cdf0e10cSrcweir if ( !pLocale )
2027cdf0e10cSrcweir {
2028cdf0e10cSrcweir pLocale = new ::com::sun::star::lang::Locale( Application::GetSettings().GetLocale());
2029cdf0e10cSrcweir }
2030cdf0e10cSrcweir return pLocale;
2031cdf0e10cSrcweir }
2032cdf0e10cSrcweir
2033