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