xref: /trunk/main/sw/source/ui/utlui/initui.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <unotools/localedatawrapper.hxx>
33 #include <viewsh.hxx>
34 #include <initui.hxx>
35 #include <edtwin.hxx>
36 #include <shellres.hxx>
37 #include <fldbas.hxx>
38 #include <glosdoc.hxx>
39 #include <gloslst.hxx>
40 
41 #ifndef _UTLUI_HRC
42 #include <utlui.hrc>
43 #endif
44 #ifndef _INITUI_HRC
45 #include <initui.hrc>
46 #endif
47 #ifndef _COMCORE_HRC
48 #include <comcore.hrc>
49 #endif
50 #include <authfld.hxx>
51 #ifndef _DBMGR_HXX
52 #include <dbmgr.hxx>
53 #endif
54 #include <unotools/syslocale.hxx>
55 
56 #include <unomid.h>
57 
58 /*--------------------------------------------------------------------
59     Beschreibung:   globale Pointer
60  --------------------------------------------------------------------*/
61 
62 SwGlossaries*       pGlossaries = 0;
63 
64 // Liefert alle benoetigten Pfade. Wird durch UI initialisiert
65 SwGlossaryList*     pGlossaryList = 0;
66 
67 String* pOldGrfCat = 0;
68 String* pOldTabCat = 0;
69 String* pOldFrmCat = 0;
70 String* pOldDrwCat = 0;
71 String* pCurrGlosGroup = 0;
72 
73 String* GetOldGrfCat()
74 {
75     return pOldGrfCat;
76 }
77 String* GetOldTabCat()
78 {
79     return pOldTabCat;
80 }
81 String* GetOldFrmCat()
82 {
83     return pOldFrmCat;
84 }
85 String* GetOldDrwCat()
86 {
87     return pOldDrwCat;
88 }
89 String* GetCurrGlosGroup()
90 {
91     return pCurrGlosGroup;
92 }
93 void SetCurrGlosGroup(String* pStr)
94 {
95     pCurrGlosGroup = pStr;
96 }
97 
98 SvStringsDtor* pDBNameList = 0;
99 
100 SvStringsDtor*  pAuthFieldNameList = 0;
101 SvStringsDtor*  pAuthFieldTypeList = 0;
102 
103 /*--------------------------------------------------------------------
104     Beschreibung:   UI beenden
105  --------------------------------------------------------------------*/
106 
107 void _FinitUI()
108 {
109     SwNewDBMgr::RemoveDbtoolsClient();
110     delete ViewShell::GetShellRes();
111     ViewShell::SetShellRes( 0 );
112 
113     SwEditWin::_FinitStaticData();
114 
115     DELETEZ(pGlossaries);
116 
117     delete SwFieldType::pFldNames;
118 
119     delete pOldGrfCat;
120     delete pOldTabCat;
121     delete pOldFrmCat;
122     delete pOldDrwCat;
123     delete pCurrGlosGroup;
124     delete pDBNameList;
125     delete pGlossaryList;
126     delete pAuthFieldNameList;
127     delete pAuthFieldTypeList;
128 
129 
130 }
131 /*--------------------------------------------------------------------
132     Beschreibung:   Initialisierung
133  --------------------------------------------------------------------*/
134 
135 
136 void _InitUI()
137 {
138     // ShellResource gibt der CORE die Moeglichkeit mit Resourcen zu arbeiten
139     ViewShell::SetShellRes( new ShellResource );
140     pDBNameList = new SvStringsDtor( 5, 5 );
141     SwEditWin::_InitStaticData();
142 }
143 
144 
145 ShellResource::ShellResource()
146     : Resource( SW_RES(RID_SW_SHELLRES) ),
147     aPostItAuthor( SW_RES( STR_POSTIT_AUTHOR ) ),
148     aPostItPage( SW_RES( STR_POSTIT_PAGE ) ),
149     aPostItLine( SW_RES( STR_POSTIT_LINE ) ),
150 
151     aCalc_Syntax( SW_RES( STR_CALC_SYNTAX ) ),
152     aCalc_ZeroDiv( SW_RES( STR_CALC_ZERODIV ) ),
153     aCalc_Brack( SW_RES( STR_CALC_BRACK ) ),
154     aCalc_Pow( SW_RES( STR_CALC_POW ) ),
155     aCalc_VarNFnd( SW_RES( STR_CALC_VARNFND ) ),
156     aCalc_Overflow( SW_RES( STR_CALC_OVERFLOW ) ),
157     aCalc_WrongTime( SW_RES( STR_CALC_WRONGTIME ) ),
158     aCalc_Default( SW_RES( STR_CALC_DEFAULT ) ),
159     aCalc_Error( SW_RES( STR_CALC_ERROR ) ),
160 
161     aGetRefFld_Up( SW_RES( STR_GETREFFLD_UP ) ),
162     aGetRefFld_Down( SW_RES( STR_GETREFFLD_DOWN ) ),
163     // --> OD 2007-09-13 #i81002#
164     aGetRefFld_RefItemNotFound( SW_RES( STR_GETREFFLD_REFITEMNOTFOUND ) ),
165     // <--
166     aStrAllPageHeadFoot( SW_RES( STR_ALLPAGE_HEADFOOT ) ),
167     aStrNone( SW_RES( STR_TEMPLATE_NONE )),
168     aFixedStr( SW_RES( STR_FIELD_FIXED )),
169     sDurationFormat( SW_RES( STR_DURATION_FORMAT )),
170 
171     aTOXIndexName(          SW_RES(STR_TOI)),
172     aTOXUserName(           SW_RES(STR_TOU)),
173     aTOXContentName(        SW_RES(STR_TOC)),
174     aTOXIllustrationsName(  SW_RES(STR_TOX_ILL)),
175     aTOXObjectsName(        SW_RES(STR_TOX_OBJ)),
176     aTOXTablesName(         SW_RES(STR_TOX_TBL)),
177     aTOXAuthoritiesName(    SW_RES(STR_TOX_AUTH)),
178     aHyperlinkClick( SW_RES( STR_HYPERLINK_CLICK)),
179     pAutoFmtNameLst(0),
180     sPageDescFirstName(     SW_RES(STR_PAGEDESC_FIRSTNAME)),
181     sPageDescFollowName(    SW_RES(STR_PAGEDESC_FOLLOWNAME)),
182     sPageDescName(          SW_RES(STR_PAGEDESC_NAME))
183 {
184     const sal_uInt16 nCount = FLD_DOCINFO_END - FLD_DOCINFO_BEGIN;
185 
186     KeyCode aCode( KEY_SPACE );
187     KeyCode aModifiedCode( KEY_SPACE, KEY_MOD1 );
188     String aModStr( aModifiedCode.GetName() );
189     aModStr.SearchAndReplace( aCode.GetName(), String() );
190     aModStr.SearchAndReplaceAllAscii( "+", String() );
191     aHyperlinkClick.SearchAndReplaceAllAscii( "%s", aModStr );
192 
193     for(sal_uInt16 i = 0; i < nCount; ++i)
194     {
195         String* pNew = new SW_RESSTR(FLD_DOCINFO_BEGIN + i);
196         aDocInfoLst.Insert(pNew, aDocInfoLst.Count());
197     }
198 
199     FreeResource();
200 }
201 
202 ShellResource::~ShellResource()
203 {
204     if( pAutoFmtNameLst )
205         delete pAutoFmtNameLst, pAutoFmtNameLst = 0;
206 }
207 
208 String ShellResource::GetPageDescName( sal_uInt16 nNo, sal_Bool bIsFirst, sal_Bool bFollow )
209 {
210     String sRet( bIsFirst ? sPageDescFirstName
211                           : bFollow ? sPageDescFollowName
212                                     : sPageDescName );
213     sRet.SearchAndReplaceAscii( "$(ARG1)", String::CreateFromInt32( nNo ));
214     return sRet;
215 }
216 
217 
218 SwGlossaries* GetGlossaries()
219 {
220     if (!pGlossaries)
221         pGlossaries = new SwGlossaries;
222     return (pGlossaries);
223 }
224 
225 sal_Bool HasGlossaryList()
226 {
227     return pGlossaryList != 0;
228 }
229 
230 SwGlossaryList* GetGlossaryList()
231 {
232     if(!pGlossaryList)
233         pGlossaryList = new SwGlossaryList();
234 
235     return pGlossaryList;
236 }
237 
238 struct ImpAutoFmtNameListLoader : public Resource
239 {
240     ImpAutoFmtNameListLoader( SvStringsDtor& rLst );
241 };
242 
243 void ShellResource::_GetAutoFmtNameLst() const
244 {
245     SvStringsDtor** ppLst = (SvStringsDtor**)&pAutoFmtNameLst;
246     *ppLst = new SvStringsDtor( STR_AUTOFMTREDL_END );
247     ImpAutoFmtNameListLoader aTmp( **ppLst );
248 }
249 
250 ImpAutoFmtNameListLoader::ImpAutoFmtNameListLoader( SvStringsDtor& rLst )
251     : Resource( ResId(RID_SHELLRES_AUTOFMTSTRS, *pSwResMgr) )
252 {
253     for( sal_uInt16 n = 0; n < STR_AUTOFMTREDL_END; ++n )
254     {
255         String* p = new String( ResId( n + 1, *pSwResMgr) );
256         if(STR_AUTOFMTREDL_TYPO == n)
257         {
258 #ifdef WNT
259             //fuer Windows Sonderbehandlung, da MS hier ein paar Zeichen im Dialogfont vergessen hat
260             p->SearchAndReplace(C2S("%1"), C2S(",,"));
261             p->SearchAndReplace(C2S("%2"), C2S("''"));
262 #else
263             const SvtSysLocale aSysLocale;
264             const LocaleDataWrapper& rLclD = aSysLocale.GetLocaleData();
265             //unter richtigen Betriebssystemen funktioniert es auch so
266             p->SearchAndReplace(C2S("%1"), rLclD.getDoubleQuotationMarkStart());
267             p->SearchAndReplace(C2S("%2"), rLclD.getDoubleQuotationMarkEnd());
268 #endif
269         }
270         rLst.Insert( p, n );
271     }
272     FreeResource();
273 }
274 /* -----------------16.09.99 12:28-------------------
275 
276  --------------------------------------------------*/
277 const String&   SwAuthorityFieldType::GetAuthFieldName(ToxAuthorityField eType)
278 {
279     if(!pAuthFieldNameList)
280     {
281         pAuthFieldNameList = new SvStringsDtor(AUTH_FIELD_END, 1);
282         for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
283         {
284             String*  pTmp = new String(SW_RES(STR_AUTH_FIELD_START + i));
285             pAuthFieldNameList->Insert(pTmp, pAuthFieldNameList->Count());
286         }
287     }
288     return *pAuthFieldNameList->GetObject( static_cast< sal_uInt16 >(eType) );
289 }
290 /* -----------------16.09.99 12:29-------------------
291 
292  --------------------------------------------------*/
293 const String&   SwAuthorityFieldType::GetAuthTypeName(ToxAuthorityType eType)
294 {
295     if(!pAuthFieldTypeList)
296     {
297         pAuthFieldTypeList = new SvStringsDtor(AUTH_TYPE_END, 1);
298         for(sal_uInt16 i = 0; i < AUTH_TYPE_END; i++)
299             pAuthFieldTypeList->Insert(
300                 new String(SW_RES(STR_AUTH_TYPE_START + i)),
301                                     pAuthFieldTypeList->Count());
302     }
303     return *pAuthFieldTypeList->GetObject( static_cast< sal_uInt16 >(eType) );
304 }
305 
306 
307 
308