xref: /trunk/main/cui/source/options/treeopt.cxx (revision 369c5206)
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_cui.hxx"
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/loader/CannotActivateFactoryException.hpp>
33 #include <com/sun/star/linguistic2/XDictionaryList.hpp>
34 #include <com/sun/star/frame/XDesktop.hpp>
35 #include <com/sun/star/frame/XFrame.hpp>
36 #include <com/sun/star/frame/XModuleManager.hpp>
37 #include <com/sun/star/util/XMacroExpander.hpp>
38 #include <osl/module.hxx>
39 #include <com/sun/star/util/XCloseable.hpp>
40 #include <com/sun/star/frame/XLoadable.hpp>
41 #include <tools/rcid.h>
42 #include <tools/shl.hxx>
43 #include <tools/urlobj.hxx>
44 #include <comphelper/processfactory.hxx>
45 #include <toolkit/helper/vclunohelper.hxx>
46 #include <com/sun/star/beans/PropertyValue.hpp>
47 #include <com/sun/star/container/XNameContainer.hpp>
48 #include <com/sun/star/container/XNameAccess.hpp>
49 #include <com/sun/star/oooimprovement/XCoreController.hpp>
50 #include <comphelper/configurationhelper.hxx>
51 #include <com/sun/star/awt/XDialogProvider.hpp>
52 #include <com/sun/star/awt/XDialogProvider2.hpp>
53 #include <com/sun/star/awt/XContainerWindowProvider.hpp>
54 #include <com/sun/star/awt/XDialogEventHandler.hpp>
55 #include <com/sun/star/awt/XContainerWindowEventHandler.hpp>
56 #include <com/sun/star/awt/PosSize.hpp>
57 #include <com/sun/star/awt/XTopWindow.hpp>
58 #include <com/sun/star/awt/XControl.hpp>
59 #include <com/sun/star/awt/XTabController.hpp>
60 #include <vcl/help.hxx>
61 #include <linguistic/misc.hxx>
62 #include <svtools/helpopt.hxx>
63 #include <unotools/moduleoptions.hxx>
64 #include <svl/languageoptions.hxx>
65 #include <unotools/optionsdlg.hxx>
66 #include <sfx2/module.hxx>
67 #include <vcl/msgbox.hxx>
68 #include <sfx2/dispatch.hxx>
69 #include <vcl/waitobj.hxx>
70 #include <svl/slstitm.hxx>
71 #include <sfx2/viewfrm.hxx>
72 #include <unotools/viewoptions.hxx>
73 #include <sfx2/printopt.hxx>
74 #include <osl/module.h>
75 #include <osl/process.h>
76 #include <rtl/bootstrap.hxx>
77 #include <unotools/misccfg.hxx>
78 #include <sfx2/objsh.hxx>
79 #include <sfx2/viewsh.hxx>
80 #include <sfx2/tplpitem.hxx>
81 #include <svtools/apearcfg.hxx>
82 #include <unotools/linguprops.hxx>
83 #include <sfx2/app.hxx>
84 #include <svx/xdef.hxx>
85 #include <svx/xflclit.hxx>
86 #include <svx/xpool.hxx>
87 #include "cuitabarea.hxx"
88 #include <svx/ofaitem.hxx>
89 #include "opthtml.hxx"
90 #include "optcolor.hxx"
91 #include "optctl.hxx"
92 #include "optjava.hxx"
93 #include "optsave.hxx"
94 #include "optpath.hxx"
95 #include "cuioptgenrl.hxx"
96 #include "optlingu.hxx"
97 #include "optinet2.hxx"
98 #include "optasian.hxx"
99 #include "optaccessibility.hxx"
100 #include "optjsearch.hxx"
101 #include "connpooloptions.hxx"
102 #include "optupdt.hxx"
103 #include <optimprove.hxx>
104 #include "optchart.hxx"
105 #include "optgdlg.hxx"
106 #include "optmemory.hxx"
107 #include "optfltr.hxx"
108 #include <cuires.hrc>
109 #include "helpid.hrc"
110 #include <dialmgr.hxx>
111 #include "treeopt.hxx"
112 #include "treeopt.hrc"
113 #include "fontsubs.hxx"
114 #include <editeng/unolingu.hxx>
115 #include <svx/xtable.hxx>
116 #include "connpoolconfig.hxx"
117 #include "dbregister.hxx"
118 #include "dbregisterednamesconfig.hxx"
119 #include "cfgchart.hxx"
120 #include <svx/dialogs.hrc>
121 
122 #ifndef _SVX_LANGITEM_HXX
123 #define	ITEMID_LANGUAGE SID_ATTR_CHAR_LANGUAGE
124 #include <editeng/langitem.hxx>
125 #endif
126 
127 
128 #include <editeng/optitems.hxx>
129 
130 #include <svx/drawitem.hxx>
131 #include <rtl/uri.hxx>
132 
133 #ifdef LINUX
134 #include <string.h>
135 #include <sys/types.h>
136 #include <sys/stat.h>
137 #include <unistd.h>
138 #endif
139 
140 using namespace ::com::sun::star;
141 using namespace ::com::sun::star::beans;
142 using namespace ::com::sun::star::container;
143 using namespace ::com::sun::star::frame;
144 using namespace ::com::sun::star::lang;
145 using namespace ::com::sun::star::linguistic2;
146 using namespace ::com::sun::star::uno;
147 using namespace ::com::sun::star::util;
148 
149 #ifdef C2U
150     #error  "Who define C2U before! I use it to create const ascii strings ..."
151 #else
152     #define C2U(cChar)      rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( cChar ) )
153 #endif
154 
155 #define HINT_TIMEOUT            200
156 #define SELECT_FIRST_TIMEOUT	0
157 #define SELECT_TIMEOUT			300
158 #define COLORPAGE_UNKNOWN		((sal_uInt16)0xFFFF)
159 #define EXPAND_PROTOCOL         "vnd.sun.star.expand:"
160 
161 LastPageSaver* OfaTreeOptionsDialog::pLastPageSaver = NULL;
162 
163 // some stuff for easier changes for SvtViewOptions
164 static const sal_Char*		pViewOptDataName = "page data";
165 #define VIEWOPT_DATANAME    rtl::OUString::createFromAscii( pViewOptDataName )
166 
167 static XOutdevItemPool* mpStaticXOutdevItemPool = 0L;
168 
169 static inline void SetViewOptUserItem( SvtViewOptions& rOpt, const String& rData )
170 {
171     rOpt.SetUserItem( VIEWOPT_DATANAME, makeAny( rtl::OUString( rData ) ) );
172 }
173 
174 static inline String GetViewOptUserItem( const SvtViewOptions& rOpt )
175 {
176     Any aAny( rOpt.GetUserItem( VIEWOPT_DATANAME ) );
177     rtl::OUString aUserData;
178 	aAny >>= aUserData;
179 
180 	return String( aUserData );
181 }
182 
183 struct ModuleToGroupNameMap_Impl
184 {
185     const char* m_pModule;
186     String      m_sGroupName;
187     sal_uInt16      m_nNodeId;
188 };
189 
190 static OfaPageResource* pPageRes = NULL;
191 
192 static ModuleToGroupNameMap_Impl ModuleMap[] =
193 {
194     { "ProductName", String::EmptyString(), SID_GENERAL_OPTIONS },
195     { "LanguageSettings", String::EmptyString(), SID_LANGUAGE_OPTIONS },
196     { "Internet", String::EmptyString(), SID_INET_DLG },
197     { "LoadSave", String::EmptyString(), SID_FILTER_DLG },
198     { "Writer", String::EmptyString(), SID_SW_EDITOPTIONS },
199     { "WriterWeb", String::EmptyString(), SID_SW_ONLINEOPTIONS },
200     { "Math", String::EmptyString(), SID_SM_EDITOPTIONS },
201     { "Calc", String::EmptyString(), SID_SC_EDITOPTIONS },
202     { "Impress", String::EmptyString(), SID_SD_EDITOPTIONS },
203     { "Draw", String::EmptyString(), SID_SD_GRAPHIC_OPTIONS },
204     { "Charts", String::EmptyString(), SID_SCH_EDITOPTIONS },
205     { "Base", String::EmptyString(), SID_SB_STARBASEOPTIONS },
206 
207     { NULL, String::EmptyString(), 0xFFFF }
208 };
209 
210 static void setGroupName( const rtl::OUString& rModule, const String& rGroupName )
211 {
212     sal_uInt16 nIndex = 0;
213     while ( ModuleMap[ nIndex ].m_pModule )
214     {
215         rtl::OUString sTemp =
216             rtl::OUString::createFromAscii( ModuleMap[ nIndex ].m_pModule );
217         if ( sTemp == rModule )
218         {
219             ModuleMap[ nIndex ].m_sGroupName = rGroupName;
220             break;
221         }
222         ++nIndex;
223     }
224 }
225 
226 static String getGroupName( const rtl::OUString& rModule, bool bForced )
227 {
228     String sGroupName;
229     sal_uInt16 nIndex = 0;
230     while ( ModuleMap[ nIndex ].m_pModule )
231     {
232         rtl::OUString sTemp =
233             rtl::OUString::createFromAscii( ModuleMap[ nIndex ].m_pModule );
234         if ( sTemp == rModule )
235         {
236             sGroupName = ModuleMap[ nIndex ].m_sGroupName;
237             break;
238         }
239         ++nIndex;
240     }
241 
242     if ( sGroupName.Len() == 0 && bForced )
243     {
244         if ( !pPageRes )
245             pPageRes = new OfaPageResource;
246 
247         if ( rModule == C2U("Writer") )
248             sGroupName = pPageRes->GetTextArray().GetString(0);
249         else if ( rModule == C2U("WriterWeb") )
250             sGroupName = pPageRes->GetHTMLArray().GetString(0);
251         else if ( rModule == C2U("Calc") )
252             sGroupName = pPageRes->GetCalcArray().GetString(0);
253         else if ( rModule == C2U("Impress") )
254             sGroupName = pPageRes->GetImpressArray().GetString(0);
255         else if ( rModule == C2U("Draw") )
256             sGroupName = pPageRes->GetDrawArray().GetString(0);
257         else if ( rModule == C2U("Math") )
258             sGroupName = pPageRes->GetStarMathArray().GetString(0);
259         else if ( rModule == C2U("Base") )
260             sGroupName = pPageRes->GetDatasourcesArray().GetString(0);
261     }
262     return sGroupName;
263 }
264 
265 static void deleteGroupNames()
266 {
267     sal_uInt16 nIndex = 0;
268     while ( ModuleMap[ nIndex ].m_pModule )
269         ModuleMap[ nIndex++ ].m_sGroupName = String::EmptyString();
270 }
271 
272 static sal_uInt16 getGroupNodeId( const rtl::OUString& rModule )
273 {
274     sal_uInt16 nNodeId = 0xFFFF, nIndex = 0;
275     while ( ModuleMap[ nIndex ].m_pModule )
276     {
277         rtl::OUString sTemp =
278             rtl::OUString::createFromAscii( ModuleMap[ nIndex ].m_pModule );
279         if ( sTemp == rModule )
280         {
281             nNodeId = ModuleMap[ nIndex ].m_nNodeId;
282             break;
283         }
284         ++nIndex;
285     }
286 
287     return nNodeId;
288 }
289 
290 /*-- 29.10.2004 13:57:25---------------------------------------------------
291 
292   -----------------------------------------------------------------------*/
293 class MailMergeCfg_Impl : public utl::ConfigItem
294 {
295     friend class SvxEMailTabPage;
296     // variables
297     sal_Bool bIsEmailSupported;
298 
299 public:
300     MailMergeCfg_Impl();
301     virtual ~MailMergeCfg_Impl();
302 
303     virtual void    Commit();
304 	virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& _rPropertyNames);
305 
306     sal_Bool IsEmailSupported() const {return bIsEmailSupported;}
307 
308 };
309 /*-- 29.10.2004 13:57:25---------------------------------------------------
310 
311   -----------------------------------------------------------------------*/
312 MailMergeCfg_Impl::MailMergeCfg_Impl() :
313     utl::ConfigItem(C2U("Office.Writer/MailMergeWizard")),
314     bIsEmailSupported(sal_False)
315 {
316     Sequence<rtl::OUString> aNames(1);
317     aNames.getArray()[0] = C2U("EMailSupported");
318     const Sequence< Any > aValues = GetProperties(aNames);
319     const Any* pValues = aValues.getConstArray();
320     if(aValues.getLength() && pValues[0].hasValue())
321         pValues[0] >>= bIsEmailSupported;
322 }
323 /*-- 29.10.2004 13:57:25---------------------------------------------------
324 
325   -----------------------------------------------------------------------*/
326 MailMergeCfg_Impl::~MailMergeCfg_Impl()
327 {
328 }
329 /* -------------------------------------------------------------------------*/
330 void MailMergeCfg_Impl::Commit()
331 {
332 }
333 
334 void MailMergeCfg_Impl::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
335 {
336 }
337 
338 //typedef SfxTabPage* (*FNCreateTabPage)( Window *pParent, const SfxItemSet &rAttrSet );
339 SfxTabPage*	CreateGeneralTabPage( sal_uInt16 nId, Window* pParent, const SfxItemSet& rSet )
340 {
341 	CreateTabPage fnCreate = 0;
342 	switch(nId)
343 	{
344 		case RID_SFXPAGE_SAVE:						fnCreate = &SvxSaveTabPage::Create; break;
345 		case RID_SFXPAGE_PATH:						fnCreate = &SvxPathTabPage::Create; break;
346 		case RID_SFXPAGE_GENERAL:					fnCreate = &SvxGeneralTabPage::Create; break;
347 		case RID_SFXPAGE_PRINTOPTIONS:				fnCreate = &SfxCommonPrintOptionsTabPage::Create; break;
348 		case OFA_TP_LANGUAGES:						fnCreate = &OfaLanguagesTabPage::Create; break;
349 		case RID_SFXPAGE_LINGU:						fnCreate = &SvxLinguTabPage::Create; break;
350 		case RID_SVXPAGE_COLOR:						fnCreate = &SvxColorTabPage::Create; break;
351 		case OFA_TP_VIEW:							fnCreate = &OfaViewTabPage::Create; break;
352 		case OFA_TP_MISC:							fnCreate = &OfaMiscTabPage::Create; break;
353 		case OFA_TP_MEMORY:							fnCreate = &OfaMemoryOptionsPage::Create; break;
354 		case RID_SVXPAGE_ASIAN_LAYOUT:				fnCreate = &SvxAsianLayoutPage::Create; break;
355 		case RID_SVX_FONT_SUBSTITUTION:				fnCreate = &SvxFontSubstTabPage::Create; break;
356 		case RID_SVXPAGE_INET_PROXY:				fnCreate = &SvxProxyTabPage::Create; break;
357 		case RID_SVXPAGE_INET_SEARCH:				fnCreate = &SvxSearchTabPage::Create; break;
358 		case RID_SVXPAGE_INET_SECURITY:				fnCreate = &SvxSecurityTabPage::Create; break;
359 		case RID_SVXPAGE_INET_MAIL:					fnCreate = &SvxEMailTabPage::Create; break;
360 		case RID_SVXPAGE_COLORCONFIG:				fnCreate = &SvxColorOptionsTabPage::Create; break;
361 		case RID_OFAPAGE_HTMLOPT:					fnCreate = &OfaHtmlTabPage::Create; break;
362 		case SID_OPTFILTER_MSOFFICE:				fnCreate = &OfaMSFilterTabPage::Create; break;
363 		case RID_OFAPAGE_MSFILTEROPT2:				fnCreate = &OfaMSFilterTabPage2::Create; break;
364 		case RID_SVXPAGE_JSEARCH_OPTIONS:			fnCreate = &SvxJSearchOptionsPage::Create ; break;
365 		case SID_SB_CONNECTIONPOOLING:				fnCreate = &::offapp::ConnectionPoolOptionsPage::Create; break;
366 		case SID_SB_DBREGISTEROPTIONS:				fnCreate = &::svx::DbRegistrationOptionsPage::Create; break;
367 		case RID_SVXPAGE_ACCESSIBILITYCONFIG:		fnCreate = &SvxAccessibilityOptionsTabPage::Create; break;
368 		case RID_SVXPAGE_SSO:						fnCreate = GetSSOCreator(); break;
369 		case RID_SVXPAGE_OPTIONS_CTL:				fnCreate = &SvxCTLOptionsPage::Create ; break;
370 		//added by jmeng begin
371 		case RID_SVXPAGE_INET_MOZPLUGIN:			fnCreate = &MozPluginTabPage::Create; break;
372 		//added by jmeng end
373 		case RID_SVXPAGE_OPTIONS_JAVA:				fnCreate = &SvxJavaOptionsPage::Create ; break;
374         case RID_SVXPAGE_ONLINEUPDATE:				fnCreate = &SvxOnlineUpdateTabPage::Create; break;
375         case RID_OPTPAGE_CHART_DEFCOLORS:			fnCreate = &SvxDefaultColorOptPage::Create; break;
376         case RID_SVXPAGE_IMPROVEMENT:               fnCreate = &SvxImprovementOptionsPage::Create; break;
377 	}
378 
379 	SfxTabPage*	pRet = fnCreate ? (*fnCreate)( pParent, rSet ) : NULL;
380 	return pRet;
381 }
382 
383 
384 struct OptionsMapping_Impl
385 {
386     const char* m_pGroupName;
387     const char* m_pPageName;
388     sal_uInt16      m_nPageId;
389 };
390 
391 static OptionsMapping_Impl __READONLY_DATA OptionsMap_Impl[] =
392 {
393 //    GROUP                 PAGE                    PAGE-ID
394     { "ProductName",        NULL,                   SID_GENERAL_OPTIONS },
395     { "ProductName",        "UserData",             RID_SFXPAGE_GENERAL },
396     { "ProductName",        "General",              OFA_TP_MISC },
397     { "ProductName",        "Memory",               OFA_TP_MEMORY },
398     { "ProductName",        "View",                 OFA_TP_VIEW },
399     { "ProductName",        "Print",                RID_SFXPAGE_PRINTOPTIONS },
400     { "ProductName",        "Paths",                RID_SFXPAGE_PATH },
401     { "ProductName",        "Colors",               RID_SVXPAGE_COLOR },
402     { "ProductName",        "Fonts",                RID_SVX_FONT_SUBSTITUTION },
403     { "ProductName",        "Security",             RID_SVXPAGE_INET_SECURITY },
404     { "ProductName",        "Appearance",           RID_SVXPAGE_COLORCONFIG },
405     { "ProductName",        "Accessibility",        RID_SVXPAGE_ACCESSIBILITYCONFIG },
406     { "ProductName",        "Java",                 RID_SVXPAGE_OPTIONS_JAVA },
407     { "ProductName",        "NetworkIdentity",      RID_SVXPAGE_SSO },
408     { "ProductName",        "OnlineUpdate",         RID_SVXPAGE_ONLINEUPDATE },
409     { "ProductName",        "ImprovementProgram",   RID_SVXPAGE_IMPROVEMENT },
410     { "LanguageSettings",   NULL,                   SID_LANGUAGE_OPTIONS },
411     { "LanguageSettings",   "Languages",            OFA_TP_LANGUAGES  },
412     { "LanguageSettings",   "WritingAids",          RID_SFXPAGE_LINGU },
413     { "LanguageSettings",   "SearchingInJapanese",  RID_SVXPAGE_JSEARCH_OPTIONS },
414     { "LanguageSettings",   "AsianLayout",          RID_SVXPAGE_ASIAN_LAYOUT },
415     { "LanguageSettings",   "ComplexTextLayout",    RID_SVXPAGE_OPTIONS_CTL },
416     { "Internet",           NULL,                   SID_INET_DLG },
417     { "Internet",           "Proxy",                RID_SVXPAGE_INET_PROXY },
418     { "Internet",           "Search",               RID_SVXPAGE_INET_SEARCH },
419     { "Internet",           "Email",                RID_SVXPAGE_INET_MAIL },
420     { "Internet",           "MozillaPlugin",        RID_SVXPAGE_INET_MOZPLUGIN },
421     { "LoadSave",           NULL,                   SID_FILTER_DLG },
422     { "LoadSave",           "General",              RID_SFXPAGE_SAVE },
423     { "LoadSave",           "VBAProperties",        SID_OPTFILTER_MSOFFICE },
424     { "LoadSave",           "MicrosoftOffice",      RID_OFAPAGE_MSFILTEROPT2 },
425     { "LoadSave",           "HTMLCompatibility",    RID_OFAPAGE_HTMLOPT },
426     { "Writer",             NULL,                   SID_SW_EDITOPTIONS },
427     { "Writer",             "General",              RID_SW_TP_OPTLOAD_PAGE },
428     { "Writer",             "View",                 RID_SW_TP_CONTENT_OPT },
429     { "Writer",             "FormattingAids",       RID_SW_TP_OPTSHDWCRSR },
430     { "Writer",             "Grid",                 RID_SVXPAGE_GRID },
431     { "Writer",             "BasicFontsWestern",    RID_SW_TP_STD_FONT },
432     { "Writer",             "BasicFontsAsian",      RID_SW_TP_STD_FONT_CJK },
433     { "Writer",             "BasicFontsCTL",        RID_SW_TP_STD_FONT_CTL },
434     { "Writer",             "Print",                RID_SW_TP_OPTPRINT_PAGE },
435     { "Writer",             "Table",                RID_SW_TP_OPTTABLE_PAGE },
436     { "Writer",             "Changes",              RID_SW_TP_REDLINE_OPT },
437     { "Writer",             "Compatibility",        RID_SW_TP_OPTCOMPATIBILITY_PAGE },
438     { "Writer",             "AutoCaption",          RID_SW_TP_OPTCAPTION_PAGE },
439     { "Writer",             "MailMerge",            RID_SW_TP_MAILCONFIG },
440     { "WriterWeb",          NULL,                   SID_SW_ONLINEOPTIONS },
441     { "WriterWeb",          "View",                 RID_SW_TP_HTML_CONTENT_OPT },
442     { "WriterWeb",          "FormattingAids",       RID_SW_TP_HTML_OPTSHDWCRSR },
443     { "WriterWeb",          "Grid",                 RID_SW_TP_HTML_OPTGRID_PAGE },
444     { "WriterWeb",          "Print",                RID_SW_TP_HTML_OPTPRINT_PAGE },
445     { "WriterWeb",          "Table",                RID_SW_TP_HTML_OPTTABLE_PAGE },
446     { "WriterWeb",          "Background",           RID_SW_TP_BACKGROUND },
447     { "Math",               NULL,                   SID_SM_EDITOPTIONS },
448     { "Math",               "Settings",             SID_SM_TP_PRINTOPTIONS },
449     { "Calc",               NULL,                   SID_SC_EDITOPTIONS },
450     { "Calc",               "General",              SID_SC_TP_LAYOUT },
451     { "Calc",               "View",                 SID_SC_TP_CONTENT },
452     { "Calc",               "International",        RID_OFA_TP_INTERNATIONAL },
453     { "Calc",               "Calculate",            SID_SC_TP_CALC },
454     { "Calc",               "SortLists",            SID_SC_TP_USERLISTS },
455     { "Calc",               "Changes",              SID_SC_TP_CHANGES },
456     { "Calc",               "Grid",                 SID_SC_TP_GRID },
457     { "Calc",               "Print",                RID_SC_TP_PRINT },
458     { "Impress",            NULL,                   SID_SD_EDITOPTIONS },
459     { "Impress",            "General",              SID_SI_TP_MISC },
460     { "Impress",            "View",                 SID_SI_TP_CONTENTS },
461     { "Impress",            "Grid",                 SID_SI_TP_SNAP },
462     { "Impress",            "Print",                SID_SI_TP_PRINT },
463     { "Draw",               NULL,                   SID_SD_GRAPHIC_OPTIONS },
464     { "Draw",               "General",              SID_SD_TP_MISC },
465     { "Draw",               "View",                 SID_SD_TP_CONTENTS },
466     { "Draw",               "Grid",                 SID_SD_TP_SNAP },
467     { "Draw",               "Print",                SID_SD_TP_PRINT },
468     { "Charts",             NULL,                   SID_SCH_EDITOPTIONS },
469     { "Charts",             "DefaultColors",        RID_OPTPAGE_CHART_DEFCOLORS },
470     { "Base",               NULL,                   SID_SB_STARBASEOPTIONS },
471     { "Base",               "Connections",          SID_SB_CONNECTIONPOOLING },
472     { "Base",               "Databases",            SID_SB_DBREGISTEROPTIONS },
473     { NULL,                 NULL,                   0 }
474 };
475 
476 static sal_Bool lcl_getStringFromID( sal_uInt16 _nPageId, String& _rGroupName, String& _rPageName )
477 {
478     sal_Bool bRet = sal_False;
479 
480     sal_uInt16 nIdx = 0;
481     while ( OptionsMap_Impl[nIdx].m_pGroupName != NULL )
482     {
483         if ( _nPageId == OptionsMap_Impl[nIdx].m_nPageId )
484         {
485             bRet = sal_True;
486             _rGroupName = String( OptionsMap_Impl[nIdx].m_pGroupName, RTL_TEXTENCODING_ASCII_US );
487             if ( OptionsMap_Impl[nIdx].m_pPageName != NULL )
488                 _rPageName = String( OptionsMap_Impl[nIdx].m_pPageName, RTL_TEXTENCODING_ASCII_US );
489             break;
490         }
491         ++nIdx;
492     }
493 
494     return bRet;
495 }
496 
497 static sal_Bool lcl_isOptionHidden( sal_uInt16 _nPageId, const SvtOptionsDialogOptions& _rOptOptions )
498 {
499     sal_Bool bIsHidden = sal_False;
500     String sGroupName, sPageName;
501     if ( lcl_getStringFromID( _nPageId, sGroupName, sPageName ) )
502     {
503         if ( sPageName.Len() == 0 )
504             bIsHidden =  _rOptOptions.IsGroupHidden( sGroupName );
505         else
506             bIsHidden =  _rOptOptions.IsPageHidden( sPageName, sGroupName );
507     }
508     return bIsHidden;
509 }
510 
511 /* -----------------11.02.99 09:56-------------------
512  *
513  * --------------------------------------------------*/
514 struct OptionsPageInfo
515 {
516     SfxTabPage*         m_pPage;
517     sal_uInt16          m_nPageId;
518     rtl::OUString       m_sPageURL;
519     rtl::OUString       m_sEventHdl;
520     ExtensionsTabPage*  m_pExtPage;
521 
522     OptionsPageInfo( sal_uInt16 nId ) : m_pPage( NULL ), m_nPageId( nId ), m_pExtPage( NULL ) {}
523 };
524 
525 struct OptionsGroupInfo
526 {
527     SfxItemSet*         m_pInItemSet;
528     SfxItemSet*         m_pOutItemSet;
529     SfxShell*           m_pShell;       // used to create the page
530     SfxModule*          m_pModule;      // used to create the ItemSet
531     sal_uInt16          m_nDialogId;    // Id of the former dialog
532     sal_Bool            m_bLoadError;   // load fails?
533     rtl::OUString       m_sPageURL;
534     ExtensionsTabPage*  m_pExtPage;
535 
536 	OptionsGroupInfo( SfxShell* pSh, SfxModule* pMod, sal_uInt16 nId ) :
537         m_pInItemSet( NULL ), m_pOutItemSet( NULL ), m_pShell( pSh ),
538         m_pModule( pMod ), m_nDialogId( nId ), m_bLoadError( sal_False ),
539         m_sPageURL( rtl::OUString() ), m_pExtPage( NULL ) {}
540     ~OptionsGroupInfo() { delete m_pInItemSet; delete m_pOutItemSet; }
541 };
542 
543 /* -----------------04.05.99 15:51-------------------
544  *
545  * --------------------------------------------------*/
546 sal_Bool OfaOptionsTreeListBox::Collapse( SvLBoxEntry* pParent )
547 {
548 	bInCollapse = sal_True;
549 	sal_Bool bRet = SvTreeListBox::Collapse(pParent);
550 	bInCollapse = sal_False;
551 	return bRet;
552 }
553 
554 // -----------------------------------------------------------------------
555 
556 #define INI_LIST() \
557     aOkPB               ( this, CUI_RES( PB_OK ) ),\
558     aCancelPB           ( this, CUI_RES( PB_CANCEL ) ),\
559     aHelpPB             ( this, CUI_RES( PB_HELP ) ),\
560     aBackPB             ( this, CUI_RES( PB_BACK ) ),\
561     aHiddenGB           ( this, CUI_RES( FB_BORDER ) ),\
562     aPageTitleFT        ( this, CUI_RES( FT_PAGE_TITLE ) ),\
563     aLine1FL            ( this, CUI_RES( FL_LINE_1 ) ),\
564     aHelpFT             ( this, CUI_RES( FT_HELPTEXT ) ),\
565     aHelpImg            ( this, CUI_RES( IMG_HELP ) ),\
566     aHelpTextsArr       (       CUI_RES( STR_HELPTEXTS ) ),\
567     aTreeLB             ( this, CUI_RES( TLB_PAGES ) ),\
568     sTitle              ( GetText() ),\
569     sNotLoadedError     (       CUI_RES( ST_LOAD_ERROR ) ),\
570     pCurrentPageEntry   ( NULL ),\
571     pColorPageItemSet   ( NULL ),\
572     pColorTab           ( NULL ),\
573     nChangeType         ( CT_NONE ),\
574     nUnknownType        ( COLORPAGE_UNKNOWN ),\
575     nUnknownPos         ( COLORPAGE_UNKNOWN ),\
576     bIsAreaTP           ( sal_False ),\
577     bForgetSelection    ( sal_False ),\
578     bImageResized       ( sal_False ),\
579     bInSelectHdl_Impl   ( false ),\
580     bIsFromExtensionManager( false ), \
581     bIsForSetDocumentLanguage( false )
582 
583 // Ctor() with Frame -----------------------------------------------------
584 using namespace ::com::sun::star;
585 OfaTreeOptionsDialog::OfaTreeOptionsDialog(
586     Window* pParent,
587     const Reference< XFrame >& _xFrame,
588     bool bActivateLastSelection ) :
589 
590 	SfxModalDialog( pParent, CUI_RES( RID_OFADLG_OPTIONS_TREE ) ),
591     INI_LIST()
592 {
593 	FreeResource();
594 
595     InitTreeAndHandler();
596     Initialize( _xFrame );
597     LoadExtensionOptions( rtl::OUString() );
598     ResizeTreeLB();
599     if (bActivateLastSelection)
600         ActivateLastSelection();
601 
602 	aTreeLB.SetAccessibleName(GetDisplayText());
603 }
604 
605 // Ctor() with ExtensionId -----------------------------------------------
606 
607 OfaTreeOptionsDialog::OfaTreeOptionsDialog( Window* pParent, const rtl::OUString& rExtensionId ) :
608 
609     SfxModalDialog( pParent, CUI_RES( RID_OFADLG_OPTIONS_TREE ) ),
610 
611     INI_LIST()
612 
613 {
614     FreeResource();
615 
616     bIsFromExtensionManager = ( rExtensionId.getLength() > 0 );
617     InitTreeAndHandler();
618     LoadExtensionOptions( rExtensionId );
619     ResizeTreeLB();
620     ActivateLastSelection();
621 }
622 
623 /* -----------------11.02.99 07:58-------------------
624  *
625  * --------------------------------------------------*/
626 
627 OfaTreeOptionsDialog::~OfaTreeOptionsDialog()
628 {
629     SvLBoxEntry* pEntry = aTreeLB.First();
630     // first children
631     while(pEntry)
632     {
633         // if Child (has parent), then OptionsPageInfo
634         if(aTreeLB.GetParent(pEntry))
635         {
636             OptionsPageInfo *pPageInfo = (OptionsPageInfo *)pEntry->GetUserData();
637             if(pPageInfo->m_pPage)
638             {
639                 pPageInfo->m_pPage->FillUserData();
640                 String aPageData(pPageInfo->m_pPage->GetUserData());
641                 if ( aPageData.Len() )
642                 {
643                     SvtViewOptions aTabPageOpt( E_TABPAGE, String::CreateFromInt32( pPageInfo->m_nPageId ) );
644                     SetViewOptUserItem( aTabPageOpt, aPageData );
645                 }
646                 delete pPageInfo->m_pPage;
647             }
648 
649             if (pPageInfo->m_nPageId == RID_SFXPAGE_LINGU)
650             {
651                 // write personal dictionaries
652                 Reference< XDictionaryList >  xDicList( SvxGetDictionaryList() );
653                 if (xDicList.is())
654                 {
655                     linguistic::SaveDictionaries( xDicList );
656                 }
657             }
658 
659             if( pPageInfo->m_pExtPage )
660                 delete pPageInfo->m_pExtPage;
661 
662             delete pPageInfo;
663         }
664         pEntry = aTreeLB.Next(pEntry);
665     }
666 
667     // and parents
668     pEntry = aTreeLB.First();
669     while(pEntry)
670     {
671         if(!aTreeLB.GetParent(pEntry))
672         {
673             OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo*)pEntry->GetUserData();
674             if ( pGroupInfo && pGroupInfo->m_pExtPage )
675                 delete pGroupInfo->m_pExtPage;
676             delete pGroupInfo;
677         }
678         pEntry = aTreeLB.Next(pEntry);
679     }
680 	delete pColorPageItemSet;
681     deleteGroupNames();
682 }
683 
684 /* -----------------11.02.99 08:21-------------------
685  *
686  * --------------------------------------------------*/
687 OptionsPageInfo* OfaTreeOptionsDialog::AddTabPage(
688     sal_uInt16 nId, const String& rPageName, sal_uInt16 nGroup )
689 {
690     OptionsPageInfo* pPageInfo = new OptionsPageInfo( nId );
691 	SvLBoxEntry* pParent = aTreeLB.GetEntry( 0, nGroup );
692     DBG_ASSERT( pParent, "OfaTreeOptionsDialog::AddTabPage(): no group found" );
693     SvLBoxEntry* pEntry = aTreeLB.InsertEntry( rPageName, pParent );
694     pEntry->SetUserData( pPageInfo );
695     return pPageInfo;
696 }
697 
698 /* -----------------11.02.99 10:02-------------------
699  *	der ItemSet* geht in den Besitz des Dialogs
700  * --------------------------------------------------*/
701 sal_uInt16	OfaTreeOptionsDialog::AddGroup(const String& rGroupName,
702 										SfxShell* pCreateShell,
703 										SfxModule* pCreateModule,
704 										sal_uInt16 nDialogId )
705 {
706 	SvLBoxEntry* pEntry = aTreeLB.InsertEntry(rGroupName);
707 	OptionsGroupInfo* pInfo =
708 		new OptionsGroupInfo( pCreateShell, pCreateModule, nDialogId );
709 	pEntry->SetUserData(pInfo);
710 	sal_uInt16 nRet = 0;
711 	pEntry = aTreeLB.First();
712 	while(pEntry)
713 	{
714 		if(!aTreeLB.GetParent(pEntry))
715 			nRet++;
716 		pEntry = aTreeLB.Next(pEntry);
717 	}
718 	return nRet - 1;
719 }
720 
721 /* -----------------11.02.99 10:31-------------------
722  *
723  * --------------------------------------------------*/
724 IMPL_LINK(OfaTreeOptionsDialog, ShowPageHdl_Impl, SvTreeListBox*, EMPTYARG)
725 {
726 	if ( aSelectTimer.GetTimeout() == SELECT_FIRST_TIMEOUT )
727 	{
728 		aSelectTimer.SetTimeout( SELECT_TIMEOUT );
729 		SelectHdl_Impl( NULL );
730 	}
731     else if ( aSelectTimer.GetTimeout() == SELECT_TIMEOUT )
732 		aSelectTimer.Start();
733 
734 	return 0;
735 }
736 /* -----------------11.02.99 10:49-------------------
737  *
738  * --------------------------------------------------*/
739 IMPL_LINK( OfaTreeOptionsDialog, BackHdl_Impl, PushButton*, EMPTYARG )
740 {
741     if ( pCurrentPageEntry && aTreeLB.GetParent( pCurrentPageEntry ) )
742 	{
743 		OptionsPageInfo* pPageInfo = (OptionsPageInfo*)pCurrentPageEntry->GetUserData();
744         if ( pPageInfo->m_pPage )
745         {
746             OptionsGroupInfo* pGroupInfo =
747                 (OptionsGroupInfo*)aTreeLB.GetParent( pCurrentPageEntry )->GetUserData();
748             if ( RID_SVXPAGE_COLOR == pPageInfo->m_nPageId )
749                 pPageInfo->m_pPage->Reset( *pColorPageItemSet );
750             else
751                 pPageInfo->m_pPage->Reset( *pGroupInfo->m_pInItemSet );
752         }
753         else if ( pPageInfo->m_pExtPage )
754             pPageInfo->m_pExtPage->ResetPage();
755 	}
756 	return 0;
757 }
758 /* -----------------11.02.99 16:45-------------------
759  *
760  * --------------------------------------------------*/
761 IMPL_LINK( OfaTreeOptionsDialog, OKHdl_Impl, Button *, EMPTYARG )
762 {
763 	aTreeLB.EndSelection();
764     if ( pCurrentPageEntry && aTreeLB.GetParent( pCurrentPageEntry ) )
765 	{
766         OptionsPageInfo* pPageInfo = (OptionsPageInfo *)pCurrentPageEntry->GetUserData();
767         if ( pPageInfo->m_pPage )
768         {
769             OptionsGroupInfo* pGroupInfo =
770                 (OptionsGroupInfo *)aTreeLB.GetParent(pCurrentPageEntry)->GetUserData();
771             if ( RID_SVXPAGE_COLOR != pPageInfo->m_nPageId
772                 && pPageInfo->m_pPage->HasExchangeSupport() )
773             {
774                 int nLeave = pPageInfo->m_pPage->DeactivatePage(pGroupInfo->m_pOutItemSet);
775                 if ( nLeave == SfxTabPage::KEEP_PAGE )
776                 {
777                     //die Seite darf nicht verlassen werden!
778                     aTreeLB.Select(pCurrentPageEntry);
779                     return 0;
780                 }
781             }
782             pPageInfo->m_pPage->Hide();
783         }
784 	}
785 
786 	SvLBoxEntry* pEntry = aTreeLB.First();
787     while ( pEntry )
788 	{
789         if ( aTreeLB.GetParent( pEntry ) )
790 		{
791             OptionsPageInfo* pPageInfo = (OptionsPageInfo *)pEntry->GetUserData();
792             if ( pPageInfo->m_pPage && !pPageInfo->m_pPage->HasExchangeSupport() )
793 			{
794                 OptionsGroupInfo* pGroupInfo =
795                     (OptionsGroupInfo*)aTreeLB.GetParent(pEntry)->GetUserData();
796                 pPageInfo->m_pPage->FillItemSet(*pGroupInfo->m_pOutItemSet);
797 			}
798 
799             if ( pPageInfo->m_pExtPage )
800             {
801                 pPageInfo->m_pExtPage->DeactivatePage();
802                 pPageInfo->m_pExtPage->SavePage();
803             }
804 		}
805 		pEntry = aTreeLB.Next(pEntry);
806 	}
807 	EndDialog(RET_OK);
808 	return 0;
809 }
810 
811 /* -----------------17.02.99 09:15-------------------
812  * Eine aufgeklappte Gruppe soll vollstaendig sichtbar sein
813  * --------------------------------------------------*/
814 IMPL_LINK(OfaTreeOptionsDialog, ExpandedHdl_Impl, SvTreeListBox*, pBox )
815 {
816 	pBox->Update();
817 	pBox->InitStartEntry();
818 	SvLBoxEntry* pEntry = pBox->GetHdlEntry();
819 	if(pEntry && pBox->IsExpanded(pEntry))
820 	{
821 		sal_uInt32 nChildCount = pBox->GetChildCount( pEntry );
822 
823 		SvLBoxEntry* pNext = pEntry;
824 		for(sal_uInt32 i = 0; i < nChildCount;i++)
825 		{
826 			pNext = pBox->GetNextEntryInView(pNext);
827 			if(!pNext)
828 			{
829 				pBox->ScrollOutputArea( -(short)(nChildCount - i + 1) );
830 				break;
831 			}
832 			else
833 			{
834 				Size aSz(pBox->GetOutputSizePixel());
835 				int nHeight = pBox->GetEntryHeight();
836                 Point aPos(pBox->GetEntryPosition(pNext));
837 				if(aPos.Y()+nHeight > aSz.Height())
838 				{
839 					pBox->ScrollOutputArea( -(short)(nChildCount - i + 1) );
840 					break;
841 				}
842 			}
843 		}
844 	}
845 	return 0;
846 }
847 
848 /* -----------------11.02.99 10:49-------------------
849  *
850  * --------------------------------------------------*/
851 void OfaTreeOptionsDialog::ApplyItemSets()
852 {
853 	SvLBoxEntry* pEntry = aTreeLB.First();
854 	while(pEntry)
855 	{
856 		if(!aTreeLB.GetParent(pEntry))
857 		{
858 			OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo *)pEntry->GetUserData();
859             if(pGroupInfo->m_pOutItemSet)
860 			{
861                 if(pGroupInfo->m_pShell)
862                     pGroupInfo->m_pShell->ApplyItemSet( pGroupInfo->m_nDialogId, *pGroupInfo->m_pOutItemSet);
863 				else
864                     ApplyItemSet( pGroupInfo->m_nDialogId, *pGroupInfo->m_pOutItemSet);
865 			}
866 		}
867 		pEntry = aTreeLB.Next(pEntry);
868 	}
869 }
870 
871 void OfaTreeOptionsDialog::InitTreeAndHandler()
872 {
873     aTreeLB.SetNodeDefaultImages();
874     aPageImages = ImageList( CUI_RES( RID_IMGLIST_TREEOPT ) );
875     aPageImagesHC = ImageList( CUI_RES( RID_IMGLIST_TREEOPT_HC ) );
876 
877     aTreeLB.SetHelpId( HID_OFADLG_TREELISTBOX );
878     aTreeLB.SetStyle( aTreeLB.GetStyle()|WB_HASBUTTONS | WB_HASBUTTONSATROOT |
879                            WB_HASLINES | WB_HASLINESATROOT |
880                            WB_CLIPCHILDREN | WB_HSCROLL | WB_FORCE_MAKEVISIBLE | WB_QUICK_SEARCH );
881     aTreeLB.SetSpaceBetweenEntries( 0 );
882     aTreeLB.SetSelectionMode( SINGLE_SELECTION );
883     aTreeLB.SetSublistOpenWithLeftRight( sal_True );
884     aTreeLB.SetExpandedHdl( LINK( this, OfaTreeOptionsDialog, ExpandedHdl_Impl ) );
885     aTreeLB.SetSelectHdl( LINK( this, OfaTreeOptionsDialog, ShowPageHdl_Impl ) );
886     aBackPB.SetClickHdl( LINK( this, OfaTreeOptionsDialog, BackHdl_Impl ) );
887     aOkPB.SetClickHdl( LINK( this, OfaTreeOptionsDialog, OKHdl_Impl ) );
888 
889     aHiddenGB.Show();
890     aSelectTimer.SetTimeout( SELECT_FIRST_TIMEOUT );
891     aSelectTimer.SetTimeoutHdl( LINK( this, OfaTreeOptionsDialog, SelectHdl_Impl ) );
892 }
893 
894 /* -----------------17.02.99 09:51-------------------
895  *
896  * --------------------------------------------------*/
897 void OfaTreeOptionsDialog::ActivatePage( sal_uInt16 nResId )
898 {
899     bIsForSetDocumentLanguage = false;
900     if ( nResId == OFA_TP_LANGUAGES_FOR_SET_DOCUMENT_LANGUAGE )
901 	{
902         bIsForSetDocumentLanguage = true;
903         nResId = OFA_TP_LANGUAGES;
904 	}
905 
906     DBG_ASSERT( !bIsFromExtensionManager, "OfaTreeOptionsDialog::ActivatePage(): call from extension manager" );
907     if ( !pLastPageSaver )
908         pLastPageSaver = new LastPageSaver;
909 	bForgetSelection = sal_True;
910     sal_uInt16 nTemp = pLastPageSaver->m_nLastPageId;
911     pLastPageSaver->m_nLastPageId = nResId;
912 	ActivateLastSelection();
913     pLastPageSaver->m_nLastPageId = nTemp;
914 }
915 
916 void OfaTreeOptionsDialog::ActivatePage( const String& rPageURL )
917 {
918     DBG_ASSERT( !bIsFromExtensionManager, "OfaTreeOptionsDialog::ActivatePage(): call from extension manager" );
919     if ( !pLastPageSaver )
920         pLastPageSaver = new LastPageSaver;
921     bForgetSelection = sal_True;
922     pLastPageSaver->m_nLastPageId = 0;
923     pLastPageSaver->m_sLastPageURL_Tools = rPageURL;
924     ActivateLastSelection();
925 }
926 
927 /* -----------------16.02.99 13:17-------------------
928  *
929  * --------------------------------------------------*/
930 void OfaTreeOptionsDialog::ActivateLastSelection()
931 {
932     SvLBoxEntry* pEntry = NULL;
933     if ( pLastPageSaver )
934 	{
935         String sExpand( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL ) );
936         String sLastURL = bIsFromExtensionManager ? pLastPageSaver->m_sLastPageURL_ExtMgr
937                                                   : pLastPageSaver->m_sLastPageURL_Tools;
938         if ( sLastURL.Len() == 0 )
939         {
940             sLastURL = !bIsFromExtensionManager ? pLastPageSaver->m_sLastPageURL_ExtMgr
941                                                 : pLastPageSaver->m_sLastPageURL_Tools;
942         }
943 
944         // MacroExpander to convert "expand"-URL to "file"-URL
945         Reference< XMacroExpander > m_xMacroExpander;
946         bool bMustExpand = ( INetURLObject( sLastURL ).GetProtocol() == INET_PROT_FILE );
947 
948         if ( bMustExpand )
949         {
950             Reference< XComponentContext > xContext;
951             Reference< XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
952             xProps->getPropertyValue(
953                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ) >>= xContext;
954             if ( xContext.is() )
955                 m_xMacroExpander = Reference< com::sun::star::util::XMacroExpander >(
956                     xContext->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
957                         "/singletons/com.sun.star.util.theMacroExpander" ) ) ), UNO_QUERY );
958         }
959 
960 		SvLBoxEntry* pTemp = aTreeLB.First();
961         while( !pEntry && pTemp )
962 		{
963             // restore only selection of a leaf
964             if ( aTreeLB.GetParent( pTemp ) && pTemp->GetUserData() )
965 			{
966                 OptionsPageInfo* pPageInfo = (OptionsPageInfo*)pTemp->GetUserData();
967                 String sPageURL = pPageInfo->m_sPageURL;
968                 if ( bMustExpand
969                     && sPageURL.Len() > 0
970                     && sExpand.Match( sPageURL ) == STRING_MATCH )
971                 {
972                     // cut protocol
973                     ::rtl::OUString sTemp( sPageURL.Copy( sizeof( EXPAND_PROTOCOL ) -1 ) );
974                     // decode uri class chars
975                     sTemp = ::rtl::Uri::decode(
976                         sTemp, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
977                     // expand string
978                     sPageURL = m_xMacroExpander->expandMacros( sTemp );
979                 }
980 
981                 if ( ( !bIsFromExtensionManager
982                         && pPageInfo->m_nPageId && pPageInfo->m_nPageId == pLastPageSaver->m_nLastPageId )
983                             || ( !pPageInfo->m_nPageId && sLastURL == sPageURL ) )
984                     pEntry = pTemp;
985 			}
986 			pTemp = aTreeLB.Next(pTemp);
987 		}
988 	}
989 
990     if ( !pEntry )
991     {
992         pEntry = aTreeLB.First();
993         pEntry = aTreeLB.Next(pEntry);
994     }
995 
996     SvLBoxEntry* pParent = aTreeLB.GetParent(pEntry);
997     aTreeLB.Expand(pParent);
998     aTreeLB.MakeVisible(pParent);
999     aTreeLB.MakeVisible(pEntry);
1000     aTreeLB.Select(pEntry);
1001     aTreeLB.GrabFocus();
1002 }
1003 
1004 /* -----------------22.02.99 08:52-------------------
1005  *
1006  * --------------------------------------------------*/
1007 long	OfaTreeOptionsDialog::Notify( NotifyEvent& rNEvt )
1008 {
1009 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
1010 	{
1011 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1012 		const KeyCode aKeyCode = pKEvt->GetKeyCode();
1013 
1014 		if( aKeyCode.GetCode() == KEY_PAGEUP ||
1015 				aKeyCode.GetCode() == KEY_PAGEDOWN)
1016 		{
1017 			SvLBoxEntry* pCurEntry = aTreeLB.FirstSelected();
1018 			SvLBoxEntry*  pTemp = 0;
1019 			if(aKeyCode.GetCode() == KEY_PAGEDOWN)
1020 			{
1021 				pTemp =  aTreeLB.Next( pCurEntry ) ;
1022 				if(pTemp && !aTreeLB.GetParent(pTemp))
1023 				{
1024 					pTemp =  aTreeLB.Next( pTemp ) ;
1025 					aTreeLB.Select(pTemp);
1026 				}
1027 			}
1028 			else
1029 			{
1030 				pTemp =  aTreeLB.Prev( pCurEntry ) ;
1031 				if(pTemp && !aTreeLB.GetParent(pTemp))
1032 				{
1033 					pTemp =  aTreeLB.Prev( pTemp ) ;
1034 				}
1035 			}
1036 			if(pTemp)
1037 			{
1038 				if(!aTreeLB.IsExpanded(aTreeLB.GetParent(pTemp)))
1039 					aTreeLB.Expand(aTreeLB.GetParent(pTemp));
1040 				aTreeLB.MakeVisible(pTemp);
1041 				aTreeLB.Select(pTemp);
1042 			}
1043 		}
1044 	}
1045 	return SfxModalDialog::Notify(rNEvt);
1046 }
1047 
1048 // --------------------------------------------------------------------
1049 
1050 void OfaTreeOptionsDialog::DataChanged( const DataChangedEvent& rDCEvt )
1051 {
1052 	SfxModalDialog::DataChanged( rDCEvt );
1053 
1054 	SvLBoxEntry* pEntry = aTreeLB.GetCurEntry();
1055 	if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) &&
1056 		!aTreeLB.GetParent(pEntry))
1057 	{
1058 		OptionsGroupInfo* pInfo = static_cast<OptionsGroupInfo*>(pEntry->GetUserData());
1059 		bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
1060 		ImageList* pImgLst = bHighContrast ? &aPageImagesHC : &aPageImages;
1061 		for ( sal_uInt16 i = 0; i < aHelpTextsArr.Count(); ++i )
1062 		{
1063             if ( aHelpTextsArr.GetValue(i) == pInfo->m_nDialogId )
1064 			{
1065                 aHelpImg.SetImage( pImgLst->GetImage( pInfo->m_nDialogId ) );
1066 				break;
1067 			}
1068 		}
1069 	}
1070 }
1071 class FlagSet_Impl
1072 {
1073     bool & rFlag;
1074     public:
1075         FlagSet_Impl(bool& bFlag) : rFlag(bFlag){rFlag = true;}
1076         ~FlagSet_Impl(){rFlag = false;}
1077 };
1078 
1079 IMPL_LINK( OfaTreeOptionsDialog, SelectHdl_Impl, Timer*, EMPTYARG )
1080 {
1081 	SvTreeListBox* pBox = &aTreeLB;
1082 	SvLBoxEntry* pEntry = pBox->GetCurEntry();
1083 	SvLBoxEntry* pParent = pBox->GetParent(pEntry);
1084 	pBox->EndSelection();
1085 
1086 	DBG_ASSERT(!bInSelectHdl_Impl, "Timeout handler called twice");
1087     if(bInSelectHdl_Impl || pCurrentPageEntry == pEntry)
1088         return 0;
1089     //#111938# lock the SelectHdl_Impl to prevent multiple executes
1090     FlagSet_Impl aFlag(bInSelectHdl_Impl);
1091 	TabPage* pOldPage = NULL;
1092 	TabPage* pNewPage = NULL;
1093     OptionsPageInfo* pOptPageInfo = ( pCurrentPageEntry && aTreeLB.GetParent( pCurrentPageEntry ) )
1094         ? (OptionsPageInfo*)pCurrentPageEntry->GetUserData() : NULL;
1095 
1096     if ( pOptPageInfo && pOptPageInfo->m_pPage && pOptPageInfo->m_pPage->IsVisible() )
1097 	{
1098         pOldPage = pOptPageInfo->m_pPage;
1099         OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo*)aTreeLB.GetParent(pCurrentPageEntry)->GetUserData();
1100 		int nLeave = SfxTabPage::LEAVE_PAGE;
1101         if ( RID_SVXPAGE_COLOR != pOptPageInfo->m_nPageId && pOptPageInfo->m_pPage->HasExchangeSupport() )
1102            nLeave = pOptPageInfo->m_pPage->DeactivatePage( pGroupInfo->m_pOutItemSet );
1103 
1104         if ( nLeave == SfxTabPage::KEEP_PAGE )
1105 		{
1106             // we cannot leave this page
1107             pBox->Select( pCurrentPageEntry );
1108 			return 0;
1109 		}
1110 		else
1111             pOptPageInfo->m_pPage->Hide();
1112 	}
1113     else if ( pOptPageInfo && pOptPageInfo->m_pExtPage )
1114     {
1115         pOptPageInfo->m_pExtPage->Hide();
1116         pOptPageInfo->m_pExtPage->DeactivatePage();
1117     }
1118     else if ( pCurrentPageEntry && !aTreeLB.GetParent( pCurrentPageEntry ) )
1119     {
1120         OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo*)pCurrentPageEntry->GetUserData();
1121         if ( pGroupInfo && pGroupInfo->m_pExtPage )
1122         {
1123             pGroupInfo->m_pExtPage->Hide();
1124             pGroupInfo->m_pExtPage->DeactivatePage();
1125         }
1126     }
1127     if ( pParent )
1128 	{
1129 		aPageTitleFT.Hide();
1130 		aLine1FL.Hide();
1131 		aHelpFT.Hide();
1132 		aHelpImg.Hide();
1133 		OptionsPageInfo *pPageInfo = (OptionsPageInfo *)pEntry->GetUserData();
1134 		OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo *)pParent->GetUserData();
1135         if(!pPageInfo->m_pPage && pPageInfo->m_nPageId > 0)
1136 		{
1137             if(pGroupInfo->m_bLoadError)
1138 				return 0;
1139             if ( RID_SVXPAGE_COLOR == pPageInfo->m_nPageId )
1140 			{
1141 				if(!pColorPageItemSet)
1142 				{
1143 					// Move usage of a static XOutdevItemPool instance here
1144 					if(!mpStaticXOutdevItemPool)
1145 					{
1146 						mpStaticXOutdevItemPool = new XOutdevItemPool();
1147 					}
1148 					pColorPageItemSet = new SfxItemSet( *mpStaticXOutdevItemPool, XATTR_FILLSTYLE, XATTR_FILLCOLOR);
1149 					pColorPageItemSet->Put( XFillColorItem() );
1150 				}
1151 			}
1152 			else
1153 			{
1154                 if(pGroupInfo->m_pModule /*&& !pGroupInfo->pModule->IsLoaded()*/)
1155 				{
1156                     SfxModule* pOldModule = pGroupInfo->m_pModule;
1157                     sal_Bool bIdentical = pGroupInfo->m_pModule == pGroupInfo->m_pShell;
1158 
1159 					WaitObject aWait(this);
1160 					//pGroupInfo->pModule = pGroupInfo->pModule->Load();
1161                     if(!pGroupInfo->m_pModule)
1162 					{
1163                         pGroupInfo->m_bLoadError = sal_True;
1164 						InfoBox(pBox, sNotLoadedError).Execute();
1165 						return 0;
1166 					}
1167 					if(bIdentical)
1168                          pGroupInfo->m_pShell = pGroupInfo->m_pModule;
1169 					//jetzt noch testen, ob es auch in anderen Gruppen das gleiche Module gab (z.B. Text+HTML)
1170 					SvLBoxEntry* pTemp = aTreeLB.First();
1171 					while(pTemp)
1172 					{
1173 						if(!aTreeLB.GetParent(pTemp) && pTemp != pEntry)
1174 						{
1175 							OptionsGroupInfo* pTGInfo = (OptionsGroupInfo *)pTemp->GetUserData();
1176                             if(pTGInfo->m_pModule == pOldModule)
1177 							{
1178                                 pTGInfo->m_pModule = pGroupInfo->m_pModule;
1179 								if(bIdentical)
1180                                     pTGInfo->m_pShell = pGroupInfo->m_pModule;
1181 							}
1182 						}
1183 						pTemp = aTreeLB.Next(pTemp);
1184 					}
1185 				}
1186 
1187 //				if ( pPageInfo->nPageId != RID_OPTPAGE_CHART_DEFCOLORS )
1188 				{
1189                     if(!pGroupInfo->m_pInItemSet)
1190                         pGroupInfo->m_pInItemSet = pGroupInfo->m_pShell
1191                             ? pGroupInfo->m_pShell->CreateItemSet( pGroupInfo->m_nDialogId )
1192                             : CreateItemSet( pGroupInfo->m_nDialogId );
1193                     if(!pGroupInfo->m_pOutItemSet)
1194                         pGroupInfo->m_pOutItemSet = new SfxItemSet(
1195                             *pGroupInfo->m_pInItemSet->GetPool(),
1196                             pGroupInfo->m_pInItemSet->GetRanges());
1197 				}
1198 			}
1199 
1200             if(pGroupInfo->m_pModule)
1201 			{
1202                 pPageInfo->m_pPage = pGroupInfo->m_pModule->CreateTabPage(
1203                     pPageInfo->m_nPageId, this, *pGroupInfo->m_pInItemSet );
1204 			}
1205             else if(RID_SVXPAGE_COLOR != pPageInfo->m_nPageId)
1206                 pPageInfo->m_pPage = ::CreateGeneralTabPage( pPageInfo->m_nPageId, this, *pGroupInfo->m_pInItemSet );
1207 			else
1208 			{
1209                 pPageInfo->m_pPage = ::CreateGeneralTabPage(
1210                     pPageInfo->m_nPageId, this, *pColorPageItemSet );
1211                 SvxColorTabPage& rColPage = *(SvxColorTabPage*)pPageInfo->m_pPage;
1212 				const OfaPtrItem* pPtr = NULL;
1213 				if ( SfxViewFrame::Current() && SfxViewFrame::Current()->GetDispatcher() )
1214 					pPtr = (const OfaPtrItem*)SfxViewFrame::Current()->
1215 						GetDispatcher()->Execute( SID_GET_COLORTABLE, SFX_CALLMODE_SYNCHRON );
1216 				pColorTab = pPtr ? (XColorTable*)pPtr->GetValue() : XColorTable::GetStdColorTable();
1217 
1218 				rColPage.SetColorTable( pColorTab );
1219 				rColPage.SetPageType( &nUnknownType );
1220 				rColPage.SetDlgType( &nUnknownType );
1221 				rColPage.SetPos( &nUnknownPos );
1222 				rColPage.SetAreaTP( &bIsAreaTP );
1223 				rColPage.SetColorChgd( (ChangeType*)&nChangeType );
1224 				rColPage.Construct();
1225 			}
1226 
1227             DBG_ASSERT( pPageInfo->m_pPage, "tabpage could not created");
1228             if ( pPageInfo->m_pPage )
1229 			{
1230                 SvtViewOptions aTabPageOpt( E_TABPAGE, String::CreateFromInt32( pPageInfo->m_nPageId ) );
1231                 pPageInfo->m_pPage->SetUserData( GetViewOptUserItem( aTabPageOpt ) );
1232 
1233 				Point aTreePos(aTreeLB.GetPosPixel());
1234 				Size aTreeSize(aTreeLB.GetSizePixel());
1235 				Point aGBPos(aHiddenGB.GetPosPixel());
1236                 Size aPageSize(pPageInfo->m_pPage->GetSizePixel());
1237 				Size aGBSize(aHiddenGB.GetSizePixel());
1238 				Point aPagePos( aGBPos.X() + ( aGBSize.Width() - aPageSize.Width() ) / 2,
1239 								aGBPos.Y() + ( aGBSize.Height() - aPageSize.Height() ) / 2 );
1240                 pPageInfo->m_pPage->SetPosPixel( aPagePos );
1241                 if ( RID_SVXPAGE_COLOR == pPageInfo->m_nPageId )
1242 				{
1243                     pPageInfo->m_pPage->Reset( *pColorPageItemSet );
1244                     pPageInfo->m_pPage->ActivatePage( *pColorPageItemSet );
1245 				}
1246 				else
1247 				{
1248                     pPageInfo->m_pPage->Reset( *pGroupInfo->m_pInItemSet );
1249 				}
1250 			}
1251 		}
1252         else if ( 0 == pPageInfo->m_nPageId && !pPageInfo->m_pExtPage )
1253         {
1254             if ( !m_xContainerWinProvider.is() )
1255             {
1256                 Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
1257                 m_xContainerWinProvider = Reference < awt::XContainerWindowProvider >(
1258                     xFactory->createInstance(
1259                         C2U("com.sun.star.awt.ContainerWindowProvider") ), UNO_QUERY );
1260                 DBG_ASSERT( m_xContainerWinProvider.is(), "service com.sun.star.awt.ContainerWindowProvider could not be loaded" );
1261             }
1262 
1263             pPageInfo->m_pExtPage = new ExtensionsTabPage(
1264                 this, 0, pPageInfo->m_sPageURL, pPageInfo->m_sEventHdl, m_xContainerWinProvider );
1265             Size aSize = aHiddenGB.GetSizePixel();
1266             aSize.Width() = aSize.Width() - 4;
1267             aSize.Height() = aSize.Height() - 4;
1268             Point aPos = aHiddenGB.GetPosPixel();
1269             aPos.X() = aPos.X() + 2;
1270             aPos.Y() = aPos.Y() + 2;
1271             pPageInfo->m_pExtPage->SetPosSizePixel( aPos, aSize );
1272         }
1273 
1274         if ( pPageInfo->m_pPage )
1275 		{
1276             if ( RID_SVXPAGE_COLOR != pPageInfo->m_nPageId &&
1277                  pPageInfo->m_pPage->HasExchangeSupport())
1278 			{
1279                 pPageInfo->m_pPage->ActivatePage(*pGroupInfo->m_pOutItemSet);
1280 			}
1281             pPageInfo->m_pPage->Show();
1282         }
1283         else if ( pPageInfo->m_pExtPage )
1284         {
1285             pPageInfo->m_pExtPage->Show();
1286             pPageInfo->m_pExtPage->ActivatePage();
1287         }
1288 
1289         String sTmpTitle = sTitle;
1290         sTmpTitle += String::CreateFromAscii(" - ");
1291         sTmpTitle += aTreeLB.GetEntryText(pParent);
1292         sTmpTitle += String::CreateFromAscii(" - ");
1293         sTmpTitle += aTreeLB.GetEntryText(pEntry);
1294         SetText(sTmpTitle);
1295         pCurrentPageEntry = pEntry;
1296         if ( !bForgetSelection )
1297         {
1298             if ( !pLastPageSaver )
1299                 pLastPageSaver = new LastPageSaver;
1300             if ( !bIsFromExtensionManager )
1301                 pLastPageSaver->m_nLastPageId = pPageInfo->m_nPageId;
1302             if ( pPageInfo->m_pExtPage )
1303             {
1304                 if ( bIsFromExtensionManager )
1305                     pLastPageSaver->m_sLastPageURL_ExtMgr = pPageInfo->m_sPageURL;
1306                 else
1307                     pLastPageSaver->m_sLastPageURL_Tools = pPageInfo->m_sPageURL;
1308             }
1309         }
1310         pNewPage = pPageInfo->m_pPage;
1311 	}
1312 	else
1313 	{
1314 		OptionsGroupInfo* pTGInfo = (OptionsGroupInfo *)pEntry->GetUserData();
1315         if ( pTGInfo->m_sPageURL.getLength() == 0 )
1316         {
1317             bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
1318             ImageList* pImgLst = bHighContrast ? &aPageImagesHC : &aPageImages;
1319             //hier den Hilfetext anzeigen
1320             for ( sal_uInt16 i = 0; i < aHelpTextsArr.Count(); ++i )
1321             {
1322                 if ( aHelpTextsArr.GetValue(i) == pTGInfo->m_nDialogId )
1323                 {
1324                     aHelpFT.SetText(aHelpTextsArr.GetString(i));
1325                     aHelpImg.SetImage(pImgLst->GetImage(pTGInfo->m_nDialogId));
1326                     break;
1327                 }
1328             }
1329 
1330             aPageTitleFT.Show();
1331             aLine1FL.Show();
1332             aHelpFT.Show();
1333             aHelpImg.Show();
1334 
1335             //auf die Groesse der Bitmap anpassen
1336             if(!bImageResized)
1337             {
1338                 const long nCtrlDist = 2;
1339                 bImageResized = sal_True;
1340                 Point aImgPos(aHelpImg.GetPosPixel());
1341                 Size aImgSize(aHelpImg.GetSizePixel());
1342                 Point aTitlePos(aPageTitleFT.GetPosPixel());
1343                 Point aLinePos(aLine1FL.GetPosPixel());
1344                 Point aHelpPos(aHelpFT.GetPosPixel());
1345                 Size aHelpSize(aHelpFT.GetSizePixel());
1346                 long nXDiff = 0;
1347                 long nYDiff = 0;
1348                 if(aTitlePos.X() <= (aImgPos.X() + aImgSize.Width() + nCtrlDist))
1349                 {
1350                     nXDiff = aImgPos.X() + aImgSize.Width() + nCtrlDist - aTitlePos.X();
1351                 }
1352                 if(aLinePos.Y() <= (aImgPos.Y() + aImgSize.Height() + nCtrlDist))
1353                 {
1354                     nYDiff = aImgPos.Y() + aImgSize.Height() + nCtrlDist - aLinePos.Y();
1355                 }
1356                 aLinePos.Y() += nYDiff;
1357                 aLine1FL.SetPosPixel(aLinePos);
1358 
1359                 aTitlePos.X() += nXDiff;
1360                 aPageTitleFT.SetPosPixel(aTitlePos);
1361 
1362                 aHelpPos.X() += nXDiff;
1363                 aHelpPos.Y() += nYDiff;
1364                 aHelpSize.Width() -= nXDiff;
1365                 aHelpSize.Height() -= nYDiff;
1366                 aHelpFT.SetPosSizePixel(aHelpPos, aHelpSize);
1367 
1368                 Font aFont = aHelpFT.GetFont();
1369                 Size aSz = aFont.GetSize();
1370                 aSz.Height() = (aSz.Height() * 14 ) / 10;
1371                 aFont.SetSize(aSz);
1372                 aPageTitleFT.SetFont(aFont);
1373             }
1374 
1375             String sTmpTitle = sTitle;
1376             sTmpTitle += String::CreateFromAscii(" - ");
1377             aPageTitleFT.SetText(aTreeLB.GetEntryText(pEntry));
1378             sTmpTitle += aPageTitleFT.GetText();
1379             SetText(sTmpTitle);
1380             pCurrentPageEntry = NULL;
1381         }
1382         else
1383         {
1384             if ( !pTGInfo->m_pExtPage )
1385             {
1386                 if ( !m_xContainerWinProvider.is() )
1387                 {
1388                     Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
1389                     m_xContainerWinProvider = Reference < awt::XContainerWindowProvider >(
1390                         xFactory->createInstance(
1391                             C2U("com.sun.star.awt.ContainerWindowProvider") ), UNO_QUERY );
1392                     DBG_ASSERT( m_xContainerWinProvider.is(), "service com.sun.star.awt.ContainerWindowProvider could not be loaded" );
1393                 }
1394 
1395                 pTGInfo->m_pExtPage =
1396                     new ExtensionsTabPage( this, 0, pTGInfo->m_sPageURL, rtl::OUString(), m_xContainerWinProvider );
1397                 Size aSize = aHiddenGB.GetSizePixel();
1398                 aSize.Width() = aSize.Width() - 4;
1399                 aSize.Height() = aSize.Height() - 4;
1400                 Point aPos = aHiddenGB.GetPosPixel();
1401                 aPos.X() = aPos.X() + 2;
1402                 aPos.Y() = aPos.Y() + 2;
1403                 pTGInfo->m_pExtPage->SetPosSizePixel( aPos, aSize );
1404             }
1405 
1406             if ( pTGInfo->m_pExtPage )
1407             {
1408                 pTGInfo->m_pExtPage->Show();
1409                 pTGInfo->m_pExtPage->ActivatePage();
1410             }
1411 
1412             pCurrentPageEntry = pEntry;
1413         }
1414 	}
1415 
1416 	// restore lost focus, if necessary
1417 	Window* pFocusWin = Application::GetFocusWindow();
1418 	// if the focused window is not the options treebox and the old page has the focus
1419 	if ( pFocusWin && pFocusWin != pBox && pOldPage && pOldPage->HasChildPathFocus() )
1420 		// then set the focus to the new page or if we are on a group set the focus to the options treebox
1421 		pNewPage ? pNewPage->GrabFocus() : pBox->GrabFocus();
1422 
1423 	return 0;
1424 }
1425 
1426 /* -----------------11.02.99 15:51-------------------
1427  *
1428  * --------------------------------------------------*/
1429 
1430 OfaPageResource::OfaPageResource() :
1431 	Resource(CUI_RES(RID_OFADLG_OPTIONS_TREE_PAGES)),
1432 	aGeneralDlgAry(CUI_RES(SID_GENERAL_OPTIONS)),
1433     aInetDlgAry(CUI_RES(SID_INET_DLG)),
1434     aLangDlgAry(CUI_RES(SID_LANGUAGE_OPTIONS)),
1435     aTextDlgAry(CUI_RES(SID_SW_EDITOPTIONS)),
1436 	aHTMLDlgAry(CUI_RES(SID_SW_ONLINEOPTIONS)),
1437 	aCalcDlgAry(CUI_RES(SID_SC_EDITOPTIONS)),
1438 	aStarMathDlgAry(CUI_RES(SID_SM_EDITOPTIONS)),
1439 	aImpressDlgAry(CUI_RES(SID_SD_EDITOPTIONS)),
1440 	aDrawDlgAry(CUI_RES(SID_SD_GRAPHIC_OPTIONS)),
1441 	aChartDlgAry(CUI_RES(SID_SCH_EDITOPTIONS)),
1442     aFilterDlgAry(CUI_RES(SID_FILTER_DLG)),
1443 	aDatasourcesDlgAry(CUI_RES(SID_SB_STARBASEOPTIONS))
1444 {
1445 	FreeResource();
1446 }
1447 
1448 sal_Bool EnableSSO( void )
1449 {
1450 	// SSO must be enabled if the configuration manager bootstrap settings
1451 	// are configured as follows ...
1452 	//  CFG_Offline=false
1453 	//  CFG_ServerType=uno ( or unspecified )
1454 	//  CFG_BackendService=
1455 	//   com.sun.star.comp.configuration.backend.LdapSingleBackend
1456 
1457     rtl::OUString theIniFile;
1458 	osl_getExecutableFile( &theIniFile.pData );
1459 	theIniFile = theIniFile.copy( 0, theIniFile.lastIndexOf( '/' ) + 1 ) +
1460                  rtl::OUString::createFromAscii( SAL_CONFIGFILE( "configmgr" ) );
1461 	::rtl::Bootstrap theBootstrap( theIniFile );
1462 
1463     rtl::OUString theOfflineValue;
1464     rtl::OUString theDefaultOfflineValue = rtl::OUString::createFromAscii( "false" );
1465     theBootstrap.getFrom( rtl::OUString::createFromAscii( "CFG_Offline" ),
1466 						  theOfflineValue,
1467 						  theDefaultOfflineValue );
1468 
1469     rtl::OUString theServerTypeValue;
1470     theBootstrap.getFrom( rtl::OUString::createFromAscii( "CFG_ServerType" ),
1471 						  theServerTypeValue );
1472 
1473     rtl::OUString theBackendServiceTypeValue;
1474     theBootstrap.getFrom( rtl::OUString::createFromAscii( "CFG_BackendService" ),
1475 						  theBackendServiceTypeValue );
1476 
1477 	sal_Bool bSSOEnabled =
1478 		( theOfflineValue == theDefaultOfflineValue						&&
1479 		  ( theServerTypeValue.getLength() == 0 ||
1480           theServerTypeValue == rtl::OUString::createFromAscii( "uno" ) ) &&
1481 		  theBackendServiceTypeValue ==
1482             rtl::OUString::createFromAscii(
1483 				"com.sun.star.comp.configuration.backend.LdapSingleBackend" ) );
1484 	if ( bSSOEnabled && GetSSOCreator() == 0 )
1485 	{
1486 		bSSOEnabled = sal_False;
1487 	}
1488 	return bSSOEnabled;
1489 }
1490 
1491 extern "C" { static void SAL_CALL thisModule() {} }
1492 
1493 CreateTabPage GetSSOCreator( void )
1494 {
1495 	static CreateTabPage theSymbol = 0;
1496 	if ( theSymbol == 0 )
1497 	{
1498 		osl::Module aModule;
1499         rtl::OUString theModuleName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "ssoopt" ) ) );
1500 		if( aModule.loadRelative(
1501                 &thisModule, theModuleName, SAL_LOADMODULE_DEFAULT ) )
1502 		{
1503             rtl::OUString theSymbolName( rtl::OUString::createFromAscii( "CreateSSOTabPage" ) );
1504 			theSymbol = reinterpret_cast<CreateTabPage>(aModule.getFunctionSymbol( theSymbolName ));
1505 		}
1506 	}
1507 
1508 	return theSymbol;
1509 }
1510 
1511 SfxItemSet*	OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId )
1512 {
1513     Reference< XPropertySet >  xProp( SvxGetLinguPropertySet() );
1514 	SfxItemSet*	pRet = 0;
1515 	switch(nId)
1516 	{
1517         case SID_GENERAL_OPTIONS:
1518 		{
1519 			pRet = new SfxItemSet(
1520 				SFX_APP()->GetPool(),
1521                 SID_ATTR_METRIC, SID_ATTR_SPELL,
1522                 SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK,
1523                 SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER,
1524                 SID_ATTR_YEAR2000, SID_ATTR_YEAR2000,
1525 				SID_HTML_MODE, SID_HTML_MODE,
1526                 0 );
1527 
1528             SfxItemSet aOptSet( SFX_APP()->GetPool(), SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER );
1529             SFX_APP()->GetOptions(aOptSet);
1530             pRet->Put(aOptSet);
1531 
1532 			utl::MiscCfg	aMisc;
1533 			const SfxPoolItem* pItem;
1534             SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1535             if ( pViewFrame )
1536             {
1537                 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1538 
1539                 // Sonstiges - Year2000
1540                 if( SFX_ITEM_AVAILABLE <= pDispatch->QueryState( SID_ATTR_YEAR2000, pItem ) )
1541                     pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, ((const SfxUInt16Item*)pItem)->GetValue() ) );
1542                 else
1543                     pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, (sal_uInt16)aMisc.GetYear2000() ) );
1544             }
1545             else
1546                 pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, (sal_uInt16)aMisc.GetYear2000() ) );
1547 
1548 
1549 			// Sonstiges - Tabulator
1550             pRet->Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN, aMisc.IsNotFoundWarning()));
1551 
1552 			sal_uInt16 nFlag = aMisc.IsPaperSizeWarning() ? SFX_PRINTER_CHG_SIZE : 0;
1553             nFlag  |= aMisc.IsPaperOrientationWarning()  ? SFX_PRINTER_CHG_ORIENTATION : 0;
1554 			pRet->Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC, nFlag ));
1555 
1556         }
1557 		break;
1558         case SID_LANGUAGE_OPTIONS :
1559         {
1560             pRet = new SfxItemSet(SFX_APP()->GetPool(),
1561                     SID_ATTR_LANGUAGE, SID_AUTOSPELL_CHECK,
1562                     SID_ATTR_CHAR_CJK_LANGUAGE, SID_ATTR_CHAR_CTL_LANGUAGE,
1563                     SID_OPT_LOCALE_CHANGED, SID_OPT_LOCALE_CHANGED,
1564                     SID_SET_DOCUMENT_LANGUAGE, SID_SET_DOCUMENT_LANGUAGE,
1565 					0 );
1566 
1567 			// fuer die Linguistik
1568 
1569             Reference< XSpellChecker1 >  xSpell = SvxGetSpellChecker();
1570 			pRet->Put(SfxSpellCheckItem( xSpell, SID_ATTR_SPELL ));
1571 			SfxHyphenRegionItem aHyphen( SID_ATTR_HYPHENREGION );
1572 
1573 			sal_Int16 	nMinLead  = 2,
1574 						nMinTrail = 2;
1575 			if (xProp.is())
1576 			{
1577 				xProp->getPropertyValue( String::CreateFromAscii(
1578 						UPN_HYPH_MIN_LEADING) ) >>= nMinLead;
1579 				xProp->getPropertyValue( String::CreateFromAscii(
1580 						UPN_HYPH_MIN_TRAILING) ) >>= nMinTrail;
1581 			}
1582 			aHyphen.GetMinLead()  = (sal_uInt8)nMinLead;
1583 			aHyphen.GetMinTrail() = (sal_uInt8)nMinTrail;
1584 
1585 			const SfxPoolItem* pItem;
1586 			SfxPoolItem* pClone;
1587             SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1588             if ( pViewFrame )
1589             {
1590                 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1591                 if(SFX_ITEM_AVAILABLE <= pDispatch->QueryState(SID_ATTR_LANGUAGE, pItem))
1592                     pRet->Put(SfxUInt16Item(SID_ATTR_LANGUAGE, ((const SvxLanguageItem*)pItem)->GetLanguage()));
1593                 if(SFX_ITEM_AVAILABLE <= pDispatch->QueryState(SID_ATTR_CHAR_CJK_LANGUAGE, pItem))
1594                     pRet->Put(SfxUInt16Item(SID_ATTR_CHAR_CJK_LANGUAGE, ((const SvxLanguageItem*)pItem)->GetLanguage()));
1595                 if(SFX_ITEM_AVAILABLE <= pDispatch->QueryState(SID_ATTR_CHAR_CTL_LANGUAGE, pItem))
1596                     pRet->Put(SfxUInt16Item(SID_ATTR_CHAR_CTL_LANGUAGE, ((const SvxLanguageItem*)pItem)->GetLanguage()));
1597 
1598 				pRet->Put(aHyphen);
1599                 if(SFX_ITEM_AVAILABLE <= pDispatch->QueryState(SID_AUTOSPELL_CHECK, pItem))
1600                 {
1601                     pClone = pItem->Clone();
1602                     pRet->Put(*pClone);
1603                     delete pClone;
1604                 }
1605                 else
1606                 {
1607                         sal_Bool bVal = sal_False;
1608                         if (xProp.is())
1609                         {
1610                             xProp->getPropertyValue( String::CreateFromAscii( UPN_IS_SPELL_AUTO) ) >>= bVal;
1611                         }
1612 
1613                         pRet->Put(SfxBoolItem(SID_AUTOSPELL_CHECK, bVal));
1614                 }
1615             }
1616             pRet->Put( SfxBoolItem( SID_SET_DOCUMENT_LANGUAGE, bIsForSetDocumentLanguage ) );
1617         }
1618         break;
1619         case SID_INET_DLG :
1620 				pRet = new SfxItemSet( SFX_APP()->GetPool(),
1621 								SID_BASIC_ENABLED, SID_BASIC_ENABLED,
1622 				//SID_OPTIONS_START - ..END
1623 								SID_INET_EMAIL_NAME, SID_INET_PROXY_PORT,
1624 								SID_SAVEREL_INET, SID_SAVEREL_FSYS,
1625 								SID_INET_SMTPSERVER, SID_INET_SMTPSERVER,
1626 								SID_INET_NOPROXY, SID_INET_SOCKS_PROXY_PORT,
1627 								SID_INET_DNS_AUTO, SID_INET_DNS_SERVER,
1628 								SID_SECURE_URL, SID_SECURE_URL,
1629 								0L );
1630 				SFX_APP()->GetOptions(*pRet);
1631 		break;
1632 		case SID_FILTER_DLG:
1633             pRet = new SfxItemSet( SFX_APP()->GetPool(),
1634             SID_ATTR_DOCINFO, SID_ATTR_AUTOSAVEMINUTE,
1635             SID_SAVEREL_INET, SID_SAVEREL_FSYS,
1636 			SID_ATTR_PRETTYPRINTING, SID_ATTR_PRETTYPRINTING,
1637             SID_ATTR_WARNALIENFORMAT, SID_ATTR_WARNALIENFORMAT,
1638             0 );
1639             SFX_APP()->GetOptions(*pRet);
1640             break;
1641 
1642 		case SID_SB_STARBASEOPTIONS:
1643             pRet = new SfxItemSet( SFX_APP()->GetPool(),
1644             SID_SB_POOLING_ENABLED, SID_SB_DB_REGISTER,
1645             0 );
1646 			::offapp::ConnectionPoolConfig::GetOptions(*pRet);
1647 			::svx::DbRegisteredNamesConfig::GetOptions(*pRet);
1648 			break;
1649 
1650 		case SID_SCH_EDITOPTIONS:
1651 		{
1652 			SvxChartOptions aChartOpt;
1653             pRet = new SfxItemSet( SFX_APP()->GetPool(), SID_SCH_EDITOPTIONS, SID_SCH_EDITOPTIONS );
1654 			pRet->Put( SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aChartOpt.GetDefaultColors() ) );
1655 			break;
1656 		}
1657 	}
1658 	return pRet;
1659 }
1660 
1661 void OfaTreeOptionsDialog::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
1662 {
1663 	switch(nId)
1664 	{
1665 		case SID_GENERAL_OPTIONS:
1666 		{
1667 			utl::MiscCfg	aMisc;
1668 			const SfxPoolItem* pItem;
1669             SfxItemSet aOptSet(SFX_APP()->GetPool(), SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER );
1670             aOptSet.Put(rSet);
1671             if(aOptSet.Count())
1672                 SFX_APP()->SetOptions( aOptSet );
1673     		// Dispatcher neu holen, weil SetOptions() ggf. den Dispatcher zerst"ort hat
1674             SfxViewFrame *pViewFrame = SfxViewFrame::Current();
1675 // -------------------------------------------------------------------------
1676 //			Year2000 auswerten
1677 // -------------------------------------------------------------------------
1678             sal_uInt16 nY2K = USHRT_MAX;
1679             if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_YEAR2000, sal_False, &pItem ) )
1680                 nY2K = ((const SfxUInt16Item*)pItem)->GetValue();
1681             if( USHRT_MAX != nY2K )
1682             {
1683                 if ( pViewFrame )
1684                 {
1685                     SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1686                     pDispatch->Execute( SID_ATTR_YEAR2000, SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1687                 }
1688                 aMisc.SetYear2000(nY2K);
1689             }
1690 
1691 // -------------------------------------------------------------------------
1692 //			Drucken auswerten
1693 // -------------------------------------------------------------------------
1694 			if(SFX_ITEM_SET == rSet.GetItemState(SID_PRINTER_NOTFOUND_WARN, sal_False, &pItem))
1695 				aMisc.SetNotFoundWarning(((const SfxBoolItem*)pItem)->GetValue());
1696 
1697 			if(SFX_ITEM_SET == rSet.GetItemState(SID_PRINTER_CHANGESTODOC, sal_False, &pItem))
1698 			{
1699 				const SfxFlagItem* pFlag = (const SfxFlagItem*)pItem;
1700 				aMisc.SetPaperSizeWarning(0 != (pFlag->GetValue() &  SFX_PRINTER_CHG_SIZE ));
1701                 aMisc.SetPaperOrientationWarning(0 !=  (pFlag->GetValue() & SFX_PRINTER_CHG_ORIENTATION ));
1702 			}
1703 // -------------------------------------------------------------------------
1704 //			evaluate help options
1705 // -------------------------------------------------------------------------
1706 			if ( SvtHelpOptions().IsHelpTips() != Help::IsQuickHelpEnabled() )
1707 				SvtHelpOptions().IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
1708 			if ( SvtHelpOptions().IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
1709 				SvtHelpOptions().IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
1710         }
1711 		break;
1712         case SID_LANGUAGE_OPTIONS :
1713         {
1714             OfaTreeOptionsDialog::ApplyLanguageOptions(rSet);
1715         }
1716         break;
1717 		case SID_INET_DLG :
1718         case SID_FILTER_DLG:
1719 			SFX_APP()->SetOptions( rSet );
1720 		break;
1721 
1722 		case SID_SB_STARBASEOPTIONS:
1723 			::offapp::ConnectionPoolConfig::SetOptions( rSet );
1724 			::svx::DbRegisteredNamesConfig::SetOptions(rSet);
1725 			break;
1726 
1727         case SID_SCH_EDITOPTIONS:
1728             // nothing to do. Chart options only apply to newly created charts
1729             break;
1730 
1731         default:
1732         {
1733             DBG_ERROR( "Unhandled option in ApplyItemSet" );
1734         }
1735         break;
1736 	}
1737 
1738 }
1739 void OfaTreeOptionsDialog::ApplyLanguageOptions(const SfxItemSet& rSet)
1740 {
1741     sal_Bool bSaveSpellCheck = sal_False;
1742     const SfxPoolItem* pItem;
1743 
1744     if ( SFX_ITEM_SET == rSet.GetItemState( SID_SPELL_MODIFIED, sal_False, &pItem ) )
1745     {
1746         bSaveSpellCheck = ( (const SfxBoolItem*)pItem )->GetValue();
1747     }
1748     Reference< XMultiServiceFactory >  xMgr( ::comphelper::getProcessServiceFactory() );
1749     Reference< XPropertySet >  xProp(
1750             xMgr->createInstance( ::rtl::OUString::createFromAscii(
1751                     "com.sun.star.linguistic2.LinguProperties") ),
1752             UNO_QUERY );
1753     if ( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_HYPHENREGION, sal_False, &pItem ) )
1754     {
1755         const SfxHyphenRegionItem* pHyphenItem = (const SfxHyphenRegionItem*)pItem;
1756 
1757         if (xProp.is())
1758         {
1759             xProp->setPropertyValue(
1760                     String::CreateFromAscii(UPN_HYPH_MIN_LEADING),
1761                     makeAny((sal_Int16) pHyphenItem->GetMinLead()) );
1762             xProp->setPropertyValue(
1763                     String::CreateFromAscii(UPN_HYPH_MIN_TRAILING),
1764                     makeAny((sal_Int16) pHyphenItem->GetMinTrail()) );
1765         }
1766         bSaveSpellCheck = sal_True;
1767     }
1768 
1769     SfxViewFrame *pViewFrame = SfxViewFrame::Current();
1770     if ( pViewFrame )
1771     {
1772         SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1773         pItem = 0;
1774         if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_LANGUAGE, sal_False, &pItem ))
1775         {
1776             pDispatch->Execute(pItem->Which(),    SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1777             bSaveSpellCheck = sal_True;
1778         }
1779         if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE, sal_False, &pItem ))
1780         {
1781             pDispatch->Execute(pItem->Which(),    SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1782             bSaveSpellCheck = sal_True;
1783         }
1784         if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE, sal_False, &pItem ))
1785         {
1786             pDispatch->Execute(pItem->Which(),    SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1787             bSaveSpellCheck = sal_True;
1788         }
1789 
1790         if( SFX_ITEM_SET == rSet.GetItemState(SID_AUTOSPELL_CHECK, sal_False, &pItem ))
1791         {
1792             sal_Bool bOnlineSpelling = ((const SfxBoolItem*)pItem)->GetValue();
1793             pDispatch->Execute(SID_AUTOSPELL_CHECK,
1794                 SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, pItem, 0L);
1795 
1796             if (xProp.is())
1797             {
1798                 xProp->setPropertyValue(
1799                         String::CreateFromAscii(UPN_IS_SPELL_AUTO),
1800                         makeAny(bOnlineSpelling) );
1801             }
1802         }
1803 
1804         if( bSaveSpellCheck )
1805         {
1806             //! the config item has changed since we modified the
1807             //! property set it uses
1808             pDispatch->Execute(SID_SPELLCHECKER_CHANGED, SFX_CALLMODE_ASYNCHRON);
1809         }
1810     }
1811 
1812     if( SFX_ITEM_SET == rSet.GetItemState(SID_OPT_LOCALE_CHANGED, sal_False, &pItem ))
1813     {
1814         SfxViewFrame* _pViewFrame = SfxViewFrame::GetFirst();
1815         while ( _pViewFrame )
1816         {
1817             _pViewFrame->GetDispatcher()->Execute(pItem->Which(),    SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1818             _pViewFrame = SfxViewFrame::GetNext( *_pViewFrame );
1819         }
1820     }
1821 }
1822 
1823 rtl::OUString getCurrentFactory_Impl( const Reference< XFrame >& _xFrame )
1824 {
1825     rtl::OUString sIdentifier;
1826     Reference < XFrame > xCurrentFrame( _xFrame );
1827     Reference < XModuleManager > xModuleManager( ::comphelper::getProcessServiceFactory()->createInstance(
1828         DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY );
1829     if ( !xCurrentFrame.is() )
1830     {
1831         Reference< XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
1832             DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
1833         if ( xDesktop.is() )
1834             xCurrentFrame = xDesktop->getCurrentFrame();
1835     }
1836 
1837     if ( xCurrentFrame.is() && xModuleManager.is() )
1838     {
1839         try
1840         {
1841             sIdentifier = xModuleManager->identify( xCurrentFrame );
1842         }
1843         catch ( ::com::sun::star::frame::UnknownModuleException& )
1844         {
1845             DBG_WARNING( "getActiveModule_Impl(): unknown module" );
1846         }
1847         catch ( Exception& )
1848         {
1849             DBG_ERRORFILE( "getActiveModule_Impl(): exception of XModuleManager::identify()" );
1850         }
1851     }
1852 
1853     return sIdentifier;
1854 }
1855 
1856 void OfaTreeOptionsDialog::Initialize( const Reference< XFrame >& _xFrame )
1857 {
1858 	OfaPageResource aDlgResource;
1859 	sal_uInt16 nGroup = 0;
1860 
1861     SvtOptionsDialogOptions aOptionsDlgOpt;
1862     sal_uInt16 i, nPageId;
1863 
1864     // %PRODUCTNAME options
1865     sal_Bool isSSOEnabled = EnableSSO();
1866     if ( !lcl_isOptionHidden( SID_GENERAL_OPTIONS, aOptionsDlgOpt ) )
1867     {
1868         ResStringArray& rGeneralArray = aDlgResource.GetGeneralArray();
1869         setGroupName( C2U("ProductName"), rGeneralArray.GetString(0) );
1870         nGroup = AddGroup( rGeneralArray.GetString(0), 0, 0, SID_GENERAL_OPTIONS );
1871         sal_uInt16 nEnd = static_cast< sal_uInt16 >( rGeneralArray.Count() );
1872         String sPageTitle;
1873 
1874         for ( i = 1; i < nEnd; ++i )
1875         {
1876             String sNewTitle = rGeneralArray.GetString(i);
1877             nPageId = (sal_uInt16)rGeneralArray.GetValue(i);
1878             if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1879                 continue;
1880 
1881             // Disable Online Update page if service not installed
1882             if( RID_SVXPAGE_ONLINEUPDATE == nPageId )
1883             {
1884                 const ::rtl::OUString sService = C2U("com.sun.star.setup.UpdateCheck");
1885 
1886                 try
1887                 {
1888                     Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
1889                     Reference < XInterface > xService( xFactory->createInstance( sService ) );
1890 
1891                     if( ! xService.is() )
1892                         continue;
1893                 }
1894                 catch ( ::com::sun::star::loader::CannotActivateFactoryException& )
1895                 {
1896                     continue;
1897                 }
1898             }
1899             // Disable OOoImprovement page if not enabled
1900             if( RID_SVXPAGE_IMPROVEMENT == nPageId )
1901             {
1902                 continue;
1903             }
1904             if ( nPageId != RID_SVXPAGE_SSO || isSSOEnabled )
1905             {
1906                 AddTabPage( nPageId, sNewTitle, nGroup );
1907             }
1908         }
1909         // private iteration hack for Improvement Program
1910         // hack for OOo 3.1
1911         // should not be in found in any later release
1912         for(bool bOnce = false; bOnce==false; bOnce=true)
1913         {
1914             String sNewTitle = C2U("Improvement Program");
1915             {
1916                 SvxImprovementPage aTempTabPage(this);
1917                 sNewTitle = aTempTabPage.GetTitleText();
1918             }
1919             nPageId = RID_SVXPAGE_IMPROVEMENT;
1920             if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1921                 continue;
1922             // Disable OOoImprovement page if not enabled
1923             {
1924                 const ::rtl::OUString sService = C2U("com.sun.star.oooimprovement.CoreController");
1925                 try
1926                 {
1927                     Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
1928                     Reference < ::com::sun::star::oooimprovement::XCoreController > xService( xFactory->createInstance( sService ), UNO_QUERY );
1929 
1930                     if( ! xService.is() )
1931                         continue;
1932                     if( ! xService->showBuiltinOptionsPage(1))
1933                         continue;
1934                 }
1935                 catch ( ::com::sun::star::loader::CannotActivateFactoryException& )
1936                 {
1937                     continue;
1938                 }
1939             }
1940             if ( nPageId != RID_SVXPAGE_SSO || isSSOEnabled )
1941             {
1942                 AddTabPage( nPageId, sNewTitle, nGroup );
1943             }
1944         }
1945     }
1946 
1947     // Load and Save options
1948     if ( !lcl_isOptionHidden( SID_FILTER_DLG, aOptionsDlgOpt ) )
1949     {
1950         ResStringArray& rFilterArray = aDlgResource.GetFilterArray();
1951         setGroupName( C2U("LoadSave"), rFilterArray.GetString(0) );
1952         nGroup = AddGroup( rFilterArray.GetString(0), 0, 0, SID_FILTER_DLG );
1953         for ( i = 1; i < rFilterArray.Count(); ++i )
1954         {
1955             nPageId = (sal_uInt16)rFilterArray.GetValue(i);
1956             if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1957                 AddTabPage( nPageId, rFilterArray.GetString(i), nGroup );
1958         }
1959     }
1960 
1961     // Language options
1962     SvtLanguageOptions aLanguageOptions;
1963     if ( !lcl_isOptionHidden( SID_LANGUAGE_OPTIONS, aOptionsDlgOpt ) )
1964     {
1965         ResStringArray& rLangArray = aDlgResource.GetLangArray();
1966         setGroupName( C2U("LanguageSettings"), rLangArray.GetString(0) );
1967         nGroup = AddGroup( rLangArray.GetString(0), 0, 0, SID_LANGUAGE_OPTIONS );
1968         for ( i = 1; i < rLangArray.Count(); ++i )
1969         {
1970             nPageId = (sal_uInt16)rLangArray.GetValue(i);
1971             if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1972                 continue;
1973             if ( ( RID_SVXPAGE_JSEARCH_OPTIONS != nPageId || aLanguageOptions.IsJapaneseFindEnabled() ) &&
1974                  ( RID_SVXPAGE_ASIAN_LAYOUT != nPageId    || aLanguageOptions.IsAsianTypographyEnabled() ) &&
1975                  ( RID_SVXPAGE_OPTIONS_CTL != nPageId     || aLanguageOptions.IsCTLFontEnabled() ) )
1976                 AddTabPage( nPageId, rLangArray.GetString(i), nGroup );
1977         }
1978     }
1979 
1980 
1981     rtl::OUString aFactory = getCurrentFactory_Impl( _xFrame );
1982     rtl::OUString sTemp = GetModuleIdentifier( comphelper::getProcessServiceFactory(), _xFrame );
1983     DBG_ASSERT( sTemp == aFactory, "S H I T!!!" );
1984 
1985     // Writer and Writer/Web options
1986     sal_Bool bHasAnyFilter = sal_False;
1987     SvtModuleOptions aModuleOpt;
1988     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
1989     {
1990         // Textdokument
1991         bHasAnyFilter = sal_True;
1992         ResStringArray& rTextArray = aDlgResource.GetTextArray();
1993         if (   aFactory.equalsAscii( "com.sun.star.text.TextDocument" )
1994             || aFactory.equalsAscii( "com.sun.star.text.WebDocument" )
1995             || aFactory.equalsAscii( "com.sun.star.text.GlobalDocument" ) )
1996         {
1997             SfxModule* pSwMod = (*(SfxModule**) GetAppData(SHL_WRITER));
1998             if ( !lcl_isOptionHidden( SID_SW_EDITOPTIONS, aOptionsDlgOpt ) )
1999             {
2000                 if ( aFactory.equalsAscii( "com.sun.star.text.WebDocument" ) )
2001                     setGroupName( C2U("WriterWeb"), rTextArray.GetString(0) );
2002                 else
2003                     setGroupName( C2U("Writer"), rTextArray.GetString(0) );
2004                 nGroup = AddGroup(rTextArray.GetString(0), pSwMod, pSwMod, SID_SW_EDITOPTIONS );
2005                 for ( i = 1; i < rTextArray.Count(); ++i )
2006                 {
2007                     nPageId = (sal_uInt16)rTextArray.GetValue(i);
2008                     if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2009                         continue;
2010                     if ( ( RID_SW_TP_STD_FONT_CJK != nPageId || aLanguageOptions.IsCJKFontEnabled() ) &&
2011                          ( RID_SW_TP_STD_FONT_CTL != nPageId || aLanguageOptions.IsCTLFontEnabled() ) &&
2012                          ( RID_SW_TP_MAILCONFIG != nPageId || MailMergeCfg_Impl().IsEmailSupported() ) )
2013                         AddTabPage( nPageId, rTextArray.GetString(i), nGroup );
2014                 }
2015 #ifdef DBG_UTIL
2016                 AddTabPage( RID_SW_TP_OPTTEST_PAGE, String::CreateFromAscii("Interner Test"), nGroup );
2017 #endif
2018             }
2019 
2020             // HTML-Dokument
2021             if ( !lcl_isOptionHidden( SID_SW_ONLINEOPTIONS, aOptionsDlgOpt ) )
2022             {
2023                 ResStringArray& rHTMLArray = aDlgResource.GetHTMLArray();
2024                 nGroup = AddGroup(rHTMLArray.GetString(0), pSwMod, pSwMod, SID_SW_ONLINEOPTIONS );
2025                 for( i = 1; i < rHTMLArray.Count(); ++i )
2026                 {
2027                     nPageId = (sal_uInt16)rHTMLArray.GetValue(i);
2028                     if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2029                         AddTabPage( nPageId, rHTMLArray.GetString(i), nGroup );
2030                 }
2031 #ifdef DBG_UTIL
2032                 AddTabPage( RID_SW_TP_OPTTEST_PAGE, String::CreateFromAscii("Interner Test"), nGroup );
2033 #endif
2034             }
2035         }
2036     }
2037 
2038     // Calc options
2039     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
2040     {
2041         bHasAnyFilter = sal_True;
2042         if ( aFactory.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ))
2043         {
2044             if ( !lcl_isOptionHidden( SID_SC_EDITOPTIONS, aOptionsDlgOpt ) )
2045             {
2046                 ResStringArray& rCalcArray = aDlgResource.GetCalcArray();
2047                 SfxModule* pScMod = ( *( SfxModule** ) GetAppData( SHL_CALC ) );
2048                 setGroupName( C2U("Calc"), rCalcArray.GetString(0) );
2049                 nGroup = AddGroup( rCalcArray.GetString( 0 ), pScMod, pScMod, SID_SC_EDITOPTIONS );
2050                 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rCalcArray.Count() );
2051                 for ( i = 1; i < nCount; ++i )
2052                 {
2053                     nPageId = (sal_uInt16)rCalcArray.GetValue(i);
2054                     if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2055                         continue;
2056 //                  if( bCTL || nId != RID_OFA_TP_INTERNATIONAL )
2057 //                  #103755# if an international tabpage is need one day, this should be used again... ;-)
2058                     if ( nPageId != RID_OFA_TP_INTERNATIONAL )
2059                         AddTabPage( nPageId, rCalcArray.GetString( i ), nGroup );
2060                 }
2061             }
2062         }
2063     }
2064 
2065     // Impress options
2066     SfxModule* pSdMod = ( *( SfxModule** ) GetAppData( SHL_DRAW ) );
2067     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
2068     {
2069         bHasAnyFilter = sal_True;
2070         if ( aFactory.equalsAscii( "com.sun.star.presentation.PresentationDocument" ))
2071         {
2072             if ( !lcl_isOptionHidden( SID_SD_EDITOPTIONS, aOptionsDlgOpt ) )
2073             {
2074                 ResStringArray& rImpressArray = aDlgResource.GetImpressArray();
2075                 setGroupName( C2U("Impress"), rImpressArray.GetString(0) );
2076                 nGroup = AddGroup( rImpressArray.GetString( 0 ), pSdMod, pSdMod, SID_SD_EDITOPTIONS );
2077                 const sal_Bool bCTL = aLanguageOptions.IsCTLFontEnabled();
2078                 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rImpressArray.Count() );
2079                 for ( i = 1; i < nCount; ++i )
2080                 {
2081                     nPageId = (sal_uInt16)rImpressArray.GetValue(i);
2082                     if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2083                         continue;
2084                     if ( bCTL || nPageId != RID_OFA_TP_INTERNATIONAL_IMPR )
2085                         AddTabPage( nPageId, rImpressArray.GetString(i), nGroup );
2086                 }
2087             }
2088         }
2089     }
2090 
2091     // Draw options
2092     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
2093     {
2094         if ( aFactory.equalsAscii( "com.sun.star.drawing.DrawingDocument" ))
2095         {
2096             if ( !lcl_isOptionHidden( SID_SD_GRAPHIC_OPTIONS, aOptionsDlgOpt ) )
2097             {
2098                 ResStringArray& rDrawArray = aDlgResource.GetDrawArray();
2099                 setGroupName( C2U("Draw"), rDrawArray.GetString(0) );
2100                 nGroup = AddGroup( rDrawArray.GetString( 0 ), pSdMod, pSdMod, SID_SD_GRAPHIC_OPTIONS );
2101                 const sal_Bool bCTL = aLanguageOptions.IsCTLFontEnabled();
2102                 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rDrawArray.Count() );
2103                 for ( i = 1; i < nCount; ++i )
2104                 {
2105                     nPageId = (sal_uInt16)rDrawArray.GetValue(i);
2106                     if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2107                         continue;
2108                     if ( bCTL || nPageId != RID_OFA_TP_INTERNATIONAL_SD )
2109                         AddTabPage( nPageId, rDrawArray.GetString(i), nGroup );
2110                 }
2111             }
2112         }
2113     }
2114 
2115     // Math options
2116     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
2117     {
2118         if ( aFactory.equalsAscii( "com.sun.star.formula.FormulaProperties" ))
2119         {
2120             if ( !lcl_isOptionHidden( SID_SM_EDITOPTIONS, aOptionsDlgOpt ) )
2121             {
2122                 ResStringArray& rStarMathArray = aDlgResource.GetStarMathArray();
2123                 SfxModule* pSmMod = (*(SfxModule**) GetAppData(SHL_SM));
2124                 setGroupName( C2U("Math"), rStarMathArray.GetString(0) );
2125                 nGroup = AddGroup(rStarMathArray.GetString(0), pSmMod, pSmMod, SID_SM_EDITOPTIONS );
2126                 for ( i = 1; i < rStarMathArray.Count(); ++i )
2127                 {
2128                     nPageId = (sal_uInt16)rStarMathArray.GetValue(i);
2129                     if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2130                         AddTabPage( nPageId, rStarMathArray.GetString(i), nGroup );
2131                 }
2132             }
2133         }
2134     }
2135 
2136     // Database - needed only if there is an application which integrates with databases
2137     if ( !lcl_isOptionHidden( SID_SB_STARBASEOPTIONS, aOptionsDlgOpt ) &&
2138         (   aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE )
2139         ||  aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER )
2140         ||  aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC )
2141         ) )
2142     {
2143         ResStringArray& rDSArray = aDlgResource.GetDatasourcesArray();
2144         setGroupName( C2U("Base"), rDSArray.GetString(0) );
2145         nGroup = AddGroup( rDSArray.GetString(0), 0, NULL, SID_SB_STARBASEOPTIONS );
2146         for ( i = 1; i < rDSArray.Count(); ++i )
2147         {
2148             nPageId = (sal_uInt16)rDSArray.GetValue(i);
2149             if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2150                 AddTabPage( nPageId, rDSArray.GetString(i), nGroup );
2151         }
2152     }
2153 
2154     // Chart options (always installed and active)
2155     if ( !lcl_isOptionHidden( SID_SCH_EDITOPTIONS, aOptionsDlgOpt ) )
2156     {
2157         ResStringArray& rChartArray = aDlgResource.GetChartArray();
2158         setGroupName( C2U("Charts"), rChartArray.GetString(0) );
2159         nGroup = AddGroup( rChartArray.GetString(0), 0, 0, SID_SCH_EDITOPTIONS );
2160         for ( i = 1; i < rChartArray.Count(); ++i )
2161         {
2162             nPageId = (sal_uInt16)rChartArray.GetValue(i);
2163             if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2164                AddTabPage( nPageId, rChartArray.GetString(i), nGroup );
2165         }
2166     }
2167 
2168     // Internet options
2169     if ( !lcl_isOptionHidden( SID_INET_DLG, aOptionsDlgOpt ) )
2170     {
2171         ResStringArray& rInetArray = aDlgResource.GetInetArray();
2172         setGroupName( C2U("Internet"), rInetArray.GetString(0) );
2173         nGroup = AddGroup(rInetArray.GetString(0), 0, 0, SID_INET_DLG );
2174 
2175         for ( i = 1; i < rInetArray.Count(); ++i )
2176         {
2177             nPageId = (sal_uInt16)rInetArray.GetValue(i);
2178             if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2179                 continue;
2180 #if defined WNT
2181             // Disable E-mail tab-page on Windows
2182             if ( nPageId == RID_SVXPAGE_INET_MAIL )
2183                 continue;
2184 #endif
2185 #if defined MACOSX
2186             // Disable Mozilla Plug-in tab-page on Mac
2187             if ( nPageId == RID_SVXPAGE_INET_MOZPLUGIN )
2188                 continue;
2189 #endif
2190 #ifdef LINUX
2191             // Disable Mozilla Plug-in tab-page on Linux if we find a
2192             // globally installed plugin
2193             if ( nPageId == RID_SVXPAGE_INET_MOZPLUGIN ) {
2194                 struct stat sb;
2195                 char *p;
2196                 bool bHaveSystemWidePlugin = false;
2197                 char mozpaths[]="/usr/lib/mozilla/plugins/libnpsoplugin.so:/usr/lib/firefox/plugins/libnpsoplugin.so:/usr/lib/mozilla-firefox/plugins/libnpsoplugin.so:/usr/lib/iceweasel/plugins/libnpsoplugin.so:/usr/lib/iceape/plugins/libnpsoplugin.so:/usr/lib/browser-plugins/libnpsoplugin.so:/usr/lib64/browser-plugins/libnpsoplugin.so";
2198 
2199                 p = strtok(mozpaths, ":");
2200                 while (p != NULL) {
2201                     if (stat(p, &sb) != -1) {
2202                          bHaveSystemWidePlugin = true;
2203                          break;
2204                     }
2205                     p = strtok(NULL, ":");
2206                 }
2207 
2208                 if (bHaveSystemWidePlugin == true)
2209                     continue;
2210             }
2211 #endif
2212             AddTabPage( nPageId, rInetArray.GetString(i), nGroup );
2213         }
2214     }
2215 
2216 /*!!!
2217     ResizeTreeLB();
2218     ActivateLastSelection();
2219  */
2220 }
2221 
2222 namespace
2223 {
2224 	void MoveControl( Control& _rCtrl, long _nDeltaPixel )
2225 	{
2226 		Point	aPt( _rCtrl.GetPosPixel() );
2227 		aPt.X() += _nDeltaPixel;
2228 		_rCtrl.SetPosPixel( aPt );
2229 	}
2230 }
2231 
2232 void OfaTreeOptionsDialog::ResizeTreeLB( void )
2233 {
2234     const long  nMax = aHiddenGB.GetSizePixel().Width() * 42 / 100;
2235                                             // don't ask where 42 comes from... but it looks / feels ok ;-)
2236     long        nDelta = 50;                // min.
2237     sal_uInt16      nDepth = 0;
2238     const long  nIndent0 = PixelToLogic( Size( 28, 0 ) ).Width();
2239     const long  nIndent1 = PixelToLogic( Size( 52, 0 ) ).Width();
2240 
2241 	SvTreeList*			pTreeList = aTreeLB.GetModel();
2242 	DBG_ASSERT( pTreeList, "-OfaTreeOptionsDialog::ResizeTreeLB(): no model, no cookies!" );
2243 
2244 	SvListEntry*		pEntry = pTreeList->First();
2245 	while( pEntry )
2246 	{
2247         long n = aTreeLB.GetTextWidth( aTreeLB.GetEntryText( static_cast< SvLBoxEntry* >( pEntry ) ) );
2248 		n += ( nDepth == 0 )? nIndent0 : nIndent1;
2249 
2250 		if( n > nDelta )
2251 			nDelta = n;
2252 
2253 		pEntry = pTreeList->Next( pEntry, &nDepth );
2254 	}
2255 
2256 	nDelta = LogicToPixel( Size( nDelta + 3, 0 ) ).Width();			// + extra space [logic]
2257 	nDelta += GetSettings().GetStyleSettings().GetScrollBarSize();	// + scroll bar, in case it's needed
2258 
2259 	if( nDelta > nMax )
2260 		nDelta = nMax;
2261 
2262 	// starting resizing with this
2263 	Size			aSize( GetSizePixel() );
2264 	aSize.Width() += nDelta;
2265 	SetSizePixel( aSize );
2266 
2267 	// resize treelistbox
2268 	aSize = aTreeLB.GetSizePixel();
2269 	aSize.Width() += nDelta;
2270 	aTreeLB.SetSizePixel( aSize );
2271 
2272 	// ... and move depending controls
2273 	MoveControl( aOkPB, nDelta );
2274 	MoveControl( aCancelPB, nDelta );
2275 	MoveControl( aHelpPB, nDelta );
2276 	MoveControl( aBackPB, nDelta );
2277 	MoveControl( aHiddenGB, nDelta );
2278 	MoveControl( aPageTitleFT, nDelta );
2279 	MoveControl( aLine1FL, nDelta );
2280 	MoveControl( aHelpFT, nDelta );
2281 	MoveControl( aHelpImg, nDelta );
2282 }
2283 
2284 bool isNodeActive( OptionsNode* pNode, Module* pModule )
2285 {
2286     if ( pNode )
2287     {
2288         // Node for all modules actine?
2289         if ( pNode->m_bAllModules )
2290             return true;
2291 
2292         // OOo-Nodes (Writer, Calc, Impress...) are active if node is already inserted
2293         if ( getGroupName( pNode->m_sId, false ).Len() > 0 )
2294             return true;
2295 
2296         // no module -> not active
2297         if ( !pModule )
2298             return false;
2299 
2300         // search node in active module
2301         if ( pModule->m_bActive )
2302         {
2303             for ( sal_uInt32 j = 0; j < pModule->m_aNodeList.size(); ++j )
2304                 if ( pModule->m_aNodeList[j]->m_sId == pNode->m_sId )
2305                     return true;
2306         }
2307     }
2308     return false;
2309 }
2310 
2311 void OfaTreeOptionsDialog::LoadExtensionOptions( const rtl::OUString& rExtensionId )
2312 {
2313     Module* pModule = NULL;
2314     Reference< XMultiServiceFactory > xMSFac = comphelper::getProcessServiceFactory();
2315     // open optionsdialog.xcu
2316     Reference< XNameAccess > xRoot(
2317         ::comphelper::ConfigurationHelper::openConfig(
2318             xMSFac, C2U("org.openoffice.Office.OptionsDialog"),
2319             ::comphelper::ConfigurationHelper::E_READONLY ), UNO_QUERY );
2320     DBG_ASSERT( xRoot.is(), "OfaTreeOptionsDialog::LoadExtensionOptions(): no config" );
2321     // when called by Tools - Options then load nodes of active module
2322     if ( rExtensionId.getLength() == 0 )
2323         pModule = LoadModule( GetModuleIdentifier( xMSFac, Reference< XFrame >() ), xRoot );
2324 
2325     VectorOfNodes aNodeList;
2326     LoadNodes( xRoot, pModule, rExtensionId, aNodeList );
2327     InsertNodes( aNodeList );
2328 }
2329 
2330 rtl::OUString OfaTreeOptionsDialog::GetModuleIdentifier(
2331     const Reference< XMultiServiceFactory >& xMFac, const Reference< XFrame >& rFrame )
2332 {
2333     rtl::OUString sModule;
2334     Reference < XFrame > xCurrentFrame( rFrame );
2335     Reference < XModuleManager > xModuleManager( xMFac->createInstance(
2336         C2U("com.sun.star.frame.ModuleManager") ), UNO_QUERY );
2337 
2338     if ( !xCurrentFrame.is() )
2339     {
2340         Reference < XDesktop > xDesktop( xMFac->createInstance(
2341             C2U("com.sun.star.frame.Desktop") ), UNO_QUERY );
2342         if ( xDesktop.is() )
2343             xCurrentFrame = xDesktop->getCurrentFrame();
2344     }
2345 
2346     if ( xCurrentFrame.is() && xModuleManager.is() )
2347     {
2348         try
2349         {
2350             sModule = xModuleManager->identify( xCurrentFrame );
2351         }
2352         catch ( ::com::sun::star::frame::UnknownModuleException& )
2353         {
2354             DBG_WARNING( "OfaTreeOptionsDialog::GetModuleIdentifier(): unknown module" );
2355         }
2356         catch ( Exception& )
2357         {
2358             DBG_ERRORFILE( "OfaTreeOptionsDialog::GetModuleIdentifier(): exception of XModuleManager::identify()" );
2359         }
2360     }
2361     return sModule;
2362 }
2363 
2364 Module* OfaTreeOptionsDialog::LoadModule(
2365     const rtl::OUString& rModuleIdentifier, const Reference< XNameAccess >& xRoot )
2366 {
2367     Module* pModule = NULL;
2368     Reference< XNameAccess > xSet;
2369 
2370     if ( xRoot->hasByName( C2U("Modules") ) )
2371     {
2372         xRoot->getByName( C2U("Modules") ) >>= xSet;
2373         if ( xSet.is() )
2374         {
2375             Sequence< rtl::OUString > seqNames = xSet->getElementNames();
2376             for ( int i = 0; i < seqNames.getLength(); ++i )
2377             {
2378                 rtl::OUString sModule( seqNames[i] );
2379                 if ( rModuleIdentifier == sModule )
2380                 {
2381                     // current active module found
2382                     pModule = new Module( sModule );
2383                     pModule->m_bActive = true;
2384 
2385                     Reference< XNameAccess > xModAccess;
2386                     xSet->getByName( seqNames[i] ) >>= xModAccess;
2387                     if ( xModAccess.is() )
2388                     {
2389                         // load the nodes of this module
2390                         Reference< XNameAccess > xNodeAccess;
2391                         xModAccess->getByName( C2U("Nodes") ) >>= xNodeAccess;
2392                         if ( xNodeAccess.is() )
2393                         {
2394                             Sequence< rtl::OUString > xTemp = xNodeAccess->getElementNames();
2395                             Reference< XNameAccess > xAccess;
2396                             sal_Int32 nIndex = -1;
2397                             for ( int x = 0; x < xTemp.getLength(); ++x )
2398                             {
2399                                 xNodeAccess->getByName( xTemp[x] ) >>= xAccess;
2400                                 if ( xAccess.is() )
2401                                 {
2402                                     xAccess->getByName( C2U("Index") ) >>= nIndex;
2403                                     if ( nIndex < 0 )
2404                                         // append nodes with index < 0
2405                                         pModule->m_aNodeList.push_back(
2406                                             new OrderedEntry( nIndex, xTemp[x] ) );
2407                                     else
2408                                     {
2409                                         // search position of the node
2410                                         sal_uInt32 y = 0;
2411                                         for ( ; y < pModule->m_aNodeList.size(); ++y )
2412                                         {
2413                                             sal_Int32 nNodeIdx = pModule->m_aNodeList[y]->m_nIndex;
2414                                             if ( nNodeIdx < 0 || nNodeIdx > nIndex )
2415                                                 break;
2416                                         }
2417                                         // and insert the node on this position
2418                                         pModule->m_aNodeList.insert(
2419                                             pModule->m_aNodeList.begin() + y,
2420                                             new OrderedEntry( nIndex, xTemp[x] ) );
2421                                     }
2422                                 }
2423                             }
2424                         }
2425                     }
2426                 }
2427             }
2428         }
2429     }
2430     return pModule;
2431 }
2432 
2433 void OfaTreeOptionsDialog::LoadNodes(
2434     const Reference< XNameAccess >& xRoot, Module* pModule,
2435     const rtl::OUString& rExtensionId, VectorOfNodes& rOutNodeList )
2436 {
2437     Reference< XNameAccess > xSet;
2438     if ( xRoot->hasByName( C2U("Nodes") ) )
2439     {
2440         xRoot->getByName( C2U("Nodes") ) >>= xSet;
2441         if ( xSet.is() )
2442         {
2443             VectorOfNodes aNodeList;
2444             Sequence< rtl::OUString > seqNames = xSet->getElementNames();
2445 
2446             for ( int i = 0; i < seqNames.getLength(); ++i )
2447             {
2448                 String sGroupName( seqNames[i] );
2449                 Reference< XNameAccess > xNodeAccess;
2450                 xSet->getByName( seqNames[i] ) >>= xNodeAccess;
2451 
2452                 if ( xNodeAccess.is() )
2453                 {
2454                     rtl::OUString sNodeId, sLabel, sPageURL, sGroupId;
2455                     bool bAllModules = false;
2456                     sal_Int32 nGroupIndex = 0;
2457 
2458                     sNodeId = seqNames[i];
2459                     xNodeAccess->getByName( C2U("Label") ) >>= sLabel;
2460                     xNodeAccess->getByName( C2U("OptionsPage") ) >>= sPageURL;
2461                     xNodeAccess->getByName( C2U("AllModules") ) >>= bAllModules;
2462                     xNodeAccess->getByName( C2U("GroupId") ) >>= sGroupId;
2463                     xNodeAccess->getByName( C2U("GroupIndex") ) >>= nGroupIndex;
2464 
2465                     if ( sLabel.getLength() == 0 )
2466                         sLabel = sGroupName;
2467                     String sTemp = getGroupName( sLabel, rExtensionId.getLength() > 0 );
2468                     if ( sTemp.Len() > 0 )
2469                         sLabel = sTemp;
2470                     OptionsNode* pNode =
2471                         new OptionsNode( sNodeId, sLabel, sPageURL, bAllModules, sGroupId, nGroupIndex );
2472 
2473                     if ( !rExtensionId.getLength() && !isNodeActive( pNode, pModule ) )
2474                     {
2475                         delete pNode;
2476                         continue;
2477                     }
2478 
2479                     Reference< XNameAccess > xLeavesSet;
2480                     xNodeAccess->getByName( C2U( "Leaves" ) ) >>= xLeavesSet;
2481                     if ( xLeavesSet.is() )
2482                     {
2483                         Sequence< rtl::OUString > seqLeaves = xLeavesSet->getElementNames();
2484                         for ( int j = 0; j < seqLeaves.getLength(); ++j )
2485                         {
2486                             Reference< XNameAccess > xLeaveAccess;
2487                             xLeavesSet->getByName( seqLeaves[j] ) >>= xLeaveAccess;
2488 
2489                             if ( xLeaveAccess.is() )
2490                             {
2491                                 rtl::OUString sId, sLeafLabel, sEventHdl, sLeafURL, sLeafGrpId;
2492                                 sal_Int32 nLeafGrpIdx = 0;
2493 
2494                                 xLeaveAccess->getByName( C2U("Id") ) >>= sId;
2495                                 xLeaveAccess->getByName( C2U("Label") ) >>= sLeafLabel;
2496                                 xLeaveAccess->getByName( C2U("OptionsPage") ) >>= sLeafURL;
2497                                 xLeaveAccess->getByName( C2U("EventHandlerService") ) >>= sEventHdl;
2498                                 xLeaveAccess->getByName( C2U("GroupId") ) >>= sLeafGrpId;
2499                                 xLeaveAccess->getByName( C2U("GroupIndex") ) >>= nLeafGrpIdx;
2500 
2501                                 if ( !rExtensionId.getLength() || sId == rExtensionId )
2502                                 {
2503                                     OptionsLeaf* pLeaf = new OptionsLeaf(
2504                                         sId, sLeafLabel, sLeafURL, sEventHdl, sLeafGrpId, nLeafGrpIdx );
2505 
2506                                     if ( sLeafGrpId.getLength() > 0 )
2507                                     {
2508                                         bool bAlreadyOpened = false;
2509                                         if ( pNode->m_aGroupedLeaves.size() > 0 )
2510                                         {
2511                                             for ( sal_uInt32 k = 0;
2512                                                     k < pNode->m_aGroupedLeaves.size(); ++k )
2513                                             {
2514                                                 if ( pNode->m_aGroupedLeaves[k].size() > 0 &&
2515                                                      pNode->m_aGroupedLeaves[k][0]->m_sGroupId
2516                                                         == sLeafGrpId )
2517                                                 {
2518                                                     sal_uInt32 l = 0;
2519                                                     for ( ; l < pNode->m_aGroupedLeaves[k].size(); ++l )
2520                                                     {
2521                                                         if ( pNode->m_aGroupedLeaves[k][l]->
2522                                                                 m_nGroupIndex >= nLeafGrpIdx )
2523                                                             break;
2524                                                     }
2525                                                     pNode->m_aGroupedLeaves[k].insert(
2526                                                         pNode->m_aGroupedLeaves[k].begin() + l, pLeaf );
2527                                                     bAlreadyOpened = true;
2528                                                     break;
2529                                                 }
2530                                             }
2531                                         }
2532                                         if ( !bAlreadyOpened )
2533                                         {
2534                                             VectorOfLeaves aGroupedLeaves;
2535                                             aGroupedLeaves.push_back( pLeaf );
2536                                             pNode->m_aGroupedLeaves.push_back( aGroupedLeaves );
2537                                         }
2538                                     }
2539                                     else
2540                                         pNode->m_aLeaves.push_back(
2541                                             new OptionsLeaf(
2542                                                 sId, sLeafLabel, sLeafURL,
2543                                                 sEventHdl, sLeafGrpId, nLeafGrpIdx ) );
2544                                 }
2545                             }
2546                         }
2547                     }
2548 
2549                     // do not insert nodes without leaves
2550                     if ( pNode->m_aLeaves.size() > 0 || pNode->m_aGroupedLeaves.size() > 0 )
2551                     {
2552                         pModule ? aNodeList.push_back( pNode ) : rOutNodeList.push_back( pNode );
2553                     }
2554                 }
2555             }
2556 
2557             if ( pModule && aNodeList.size() > 0 )
2558             {
2559                 sal_uInt32 i = 0, j = 0;
2560                 for ( ; i < pModule->m_aNodeList.size(); ++i )
2561                 {
2562                     rtl::OUString sNodeId = pModule->m_aNodeList[i]->m_sId;
2563                     for ( j = 0; j < aNodeList.size(); ++j )
2564                     {
2565                         OptionsNode* pNode = aNodeList[j];
2566                         if ( pNode->m_sId == sNodeId )
2567                         {
2568                             rOutNodeList.push_back( pNode );
2569                             aNodeList.erase( aNodeList.begin() + j );
2570                             break;
2571                         }
2572                     }
2573                 }
2574 
2575                 for ( i = 0; i < aNodeList.size(); ++i )
2576                     rOutNodeList.push_back( aNodeList[i] );
2577             }
2578         }
2579     }
2580 }
2581 
2582 sal_uInt16 lcl_getGroupId( const rtl::OUString& rGroupName, const SvTreeListBox& rTreeLB )
2583 {
2584     String sGroupName( rGroupName );
2585     sal_uInt16 nRet = 0;
2586     SvLBoxEntry* pEntry = rTreeLB.First();
2587     while( pEntry )
2588     {
2589         if ( !rTreeLB.GetParent( pEntry ) )
2590         {
2591             String sTemp( rTreeLB.GetEntryText( pEntry ) );
2592             if ( sTemp == sGroupName )
2593                 return nRet;
2594             nRet++;
2595         }
2596         pEntry = rTreeLB.Next( pEntry );
2597     }
2598 
2599     return USHRT_MAX;
2600 }
2601 
2602 void lcl_insertLeaf(
2603     OfaTreeOptionsDialog* pDlg, OptionsNode* pNode, OptionsLeaf* pLeaf, const SvTreeListBox& rTreeLB )
2604 {
2605     sal_uInt16 nGrpId = lcl_getGroupId( pNode->m_sLabel, rTreeLB );
2606     if ( USHRT_MAX == nGrpId )
2607     {
2608         sal_uInt16 nNodeGrpId = getGroupNodeId( pNode->m_sId );
2609         nGrpId = pDlg->AddGroup( pNode->m_sLabel, NULL, NULL, nNodeGrpId );
2610         if ( pNode->m_sPageURL.getLength() > 0 )
2611         {
2612             SvLBoxEntry* pGrpEntry = rTreeLB.GetEntry( 0, nGrpId );
2613             DBG_ASSERT( pGrpEntry, "OfaTreeOptionsDialog::InsertNodes(): no group" );
2614             if ( pGrpEntry )
2615             {
2616                 OptionsGroupInfo* pGrpInfo =
2617                     static_cast<OptionsGroupInfo*>(pGrpEntry->GetUserData());
2618                 pGrpInfo->m_sPageURL = pNode->m_sPageURL;
2619             }
2620         }
2621     }
2622     OptionsPageInfo* pInfo = pDlg->AddTabPage( 0, pLeaf->m_sLabel, nGrpId );
2623     pInfo->m_sPageURL = pLeaf->m_sPageURL;
2624     pInfo->m_sEventHdl = pLeaf->m_sEventHdl;
2625 }
2626 
2627 void  OfaTreeOptionsDialog::InsertNodes( const VectorOfNodes& rNodeList )
2628 {
2629     for ( sal_uInt32 i = 0; i < rNodeList.size(); ++i )
2630     {
2631         OptionsNode* pNode = rNodeList[i];
2632 
2633         if ( pNode->m_aLeaves.size() > 0 || pNode->m_aGroupedLeaves.size() > 0 )
2634         {
2635             sal_uInt32 j = 0;
2636             for ( ; j < pNode->m_aGroupedLeaves.size(); ++j )
2637             {
2638                 for ( sal_uInt32 k = 0; k < pNode->m_aGroupedLeaves[j].size(); ++k )
2639                 {
2640                     OptionsLeaf* pLeaf = pNode->m_aGroupedLeaves[j][k];
2641                     lcl_insertLeaf( this, pNode, pLeaf, aTreeLB );
2642                 }
2643             }
2644 
2645             for ( j = 0; j < pNode->m_aLeaves.size(); ++j )
2646             {
2647                 OptionsLeaf* pLeaf = pNode->m_aLeaves[j];
2648                 lcl_insertLeaf( this, pNode, pLeaf, aTreeLB );
2649             }
2650         }
2651     }
2652 }
2653 
2654 short OfaTreeOptionsDialog::Execute()
2655 {
2656     ::std::auto_ptr< SvxDicListChgClamp > pClamp;
2657     if ( !bIsFromExtensionManager )
2658     {
2659         // collect all DictionaryList Events while the dialog is executed
2660         Reference<com::sun::star::linguistic2::XDictionaryList> xDictionaryList(SvxGetDictionaryList());
2661         pClamp = ::std::auto_ptr< SvxDicListChgClamp >( new SvxDicListChgClamp( xDictionaryList ) );
2662     }
2663 	short nRet = SfxModalDialog::Execute();
2664 
2665 	if( RET_OK == nRet )
2666 	{
2667 		ApplyItemSets();
2668 		if( GetColorTable() )
2669 		{
2670 			GetColorTable()->Save();
2671 
2672 			// notify current viewframe it it uses the same color table
2673 			if ( SfxViewFrame::Current() && SfxViewFrame::Current()->GetDispatcher() )
2674 			{
2675 				const OfaPtrItem* pPtr = (const OfaPtrItem*)SfxViewFrame::Current()->GetDispatcher()->Execute( SID_GET_COLORTABLE, SFX_CALLMODE_SYNCHRON );
2676 				if( pPtr )
2677 				{
2678                     XColorTable* _pColorTab = (XColorTable*)pPtr->GetValue();
2679 
2680                     if( _pColorTab &&
2681                         _pColorTab->GetPath() == GetColorTable()->GetPath() &&
2682                         _pColorTab->GetName() == GetColorTable()->GetName() )
2683                         SfxObjectShell::Current()->PutItem( SvxColorTableItem( GetColorTable(), SID_COLOR_TABLE ) );
2684 				}
2685 			}
2686 		}
2687 
2688         utl::ConfigManager::GetConfigManager()->StoreConfigItems();
2689     }
2690 
2691 	return nRet;
2692 }
2693 
2694 // class ExtensionsTabPage -----------------------------------------------
2695 
2696 ExtensionsTabPage::ExtensionsTabPage(
2697     Window* pParent, WinBits nStyle, const rtl::OUString& rPageURL,
2698     const rtl::OUString& rEvtHdl, const Reference< awt::XContainerWindowProvider >& rProvider ) :
2699 
2700     TabPage( pParent, nStyle ),
2701 
2702     m_sPageURL          ( rPageURL ),
2703     m_sEventHdl         ( rEvtHdl ),
2704     m_xWinProvider      ( rProvider ),
2705     m_bIsWindowHidden   ( false )
2706 
2707 {
2708 }
2709 
2710 // -----------------------------------------------------------------------
2711 
2712 ExtensionsTabPage::~ExtensionsTabPage()
2713 {
2714     Hide();
2715     DeactivatePage();
2716 }
2717 
2718 // -----------------------------------------------------------------------
2719 
2720 void ExtensionsTabPage::CreateDialogWithHandler()
2721 {
2722     try
2723     {
2724         bool bWithHandler = ( m_sEventHdl.getLength() > 0 );
2725         if ( bWithHandler )
2726         {
2727             Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
2728             m_xEventHdl = Reference< awt::XContainerWindowEventHandler >(
2729                 xFactory->createInstance( m_sEventHdl ), UNO_QUERY );
2730         }
2731 
2732         if ( !bWithHandler || m_xEventHdl.is() )
2733         {
2734             SetStyle( GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
2735             Reference< awt::XWindowPeer > xParent( VCLUnoHelper::GetInterface( this ), UNO_QUERY );
2736             m_xPage = Reference < awt::XWindow >(
2737                 m_xWinProvider->createContainerWindow(
2738                     m_sPageURL, rtl::OUString(), xParent, m_xEventHdl ), UNO_QUERY );
2739 
2740             Reference< awt::XControl > xPageControl( m_xPage, UNO_QUERY );
2741             if ( xPageControl.is() )
2742             {
2743                 Reference< awt::XWindowPeer > xWinPeer( xPageControl->getPeer() );
2744                 if ( xWinPeer.is() )
2745                 {
2746                     Window* pWindow = VCLUnoHelper::GetWindow( xWinPeer );
2747                     if ( pWindow )
2748                         pWindow->SetStyle( pWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
2749                 }
2750             }
2751         }
2752     }
2753     catch ( ::com::sun::star::lang::IllegalArgumentException& )
2754     {
2755         DBG_ERRORFILE( "ExtensionsTabPage::CreateDialogWithHandler(): illegal argument" );
2756     }
2757     catch ( Exception& )
2758     {
2759         DBG_ERRORFILE( "ExtensionsTabPage::CreateDialogWithHandler(): exception of XDialogProvider2::createDialogWithHandler()" );
2760     }
2761 }
2762 
2763 // -----------------------------------------------------------------------
2764 
2765 sal_Bool ExtensionsTabPage::DispatchAction( const rtl::OUString& rAction )
2766 {
2767     sal_Bool bRet = sal_False;
2768     if ( m_xEventHdl.is() )
2769     {
2770         try
2771         {
2772             bRet = m_xEventHdl->callHandlerMethod( m_xPage, makeAny( rAction ), C2U("external_event") );
2773         }
2774         catch ( Exception& )
2775         {
2776             DBG_ERRORFILE( "ExtensionsTabPage::DispatchAction(): exception of XDialogEventHandler::callHandlerMethod()" );
2777         }
2778     }
2779     return bRet;
2780 }
2781 
2782 // -----------------------------------------------------------------------
2783 
2784 void ExtensionsTabPage::ActivatePage()
2785 {
2786     TabPage::ActivatePage();
2787 
2788     if ( !m_xPage.is() )
2789     {
2790         CreateDialogWithHandler();
2791 
2792         if ( m_xPage.is() )
2793         {
2794             Point aPos = Point();
2795             Size aSize = GetSizePixel();
2796             m_xPage->setPosSize( aPos.X() + 1, aPos.Y() + 1,
2797                                  aSize.Width() - 2, aSize.Height() - 2, awt::PosSize::POSSIZE );
2798             if ( m_sEventHdl.getLength() > 0 )
2799                 DispatchAction( C2U("initialize") );
2800         }
2801     }
2802 
2803     if ( m_xPage.is() )
2804     {
2805         m_xPage->setVisible( sal_True );
2806         m_bIsWindowHidden = false;
2807     }
2808 }
2809 
2810 // -----------------------------------------------------------------------
2811 
2812 void ExtensionsTabPage::DeactivatePage()
2813 {
2814     TabPage::DeactivatePage();
2815 
2816     if ( m_xPage.is() )
2817         m_xPage->setVisible( sal_False );
2818 }
2819 
2820 // -----------------------------------------------------------------------
2821 
2822 void ExtensionsTabPage::ResetPage()
2823 {
2824     DispatchAction( C2U("back") );
2825     ActivatePage();
2826 }
2827 
2828 // -----------------------------------------------------------------------
2829 
2830 void ExtensionsTabPage::SavePage()
2831 {
2832     DispatchAction( C2U("ok") );
2833 }
2834