xref: /trunk/main/cui/source/options/treeopt.cxx (revision c47da6ea)
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 
SetViewOptUserItem(SvtViewOptions & rOpt,const String & rData)165 static inline void SetViewOptUserItem( SvtViewOptions& rOpt, const String& rData )
166 {
167     rOpt.SetUserItem( VIEWOPT_DATANAME, makeAny( rtl::OUString( rData ) ) );
168 }
169 
GetViewOptUserItem(const SvtViewOptions & rOpt)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 
setGroupName(const rtl::OUString & rModule,const String & rGroupName)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 
getGroupName(const rtl::OUString & rModule,bool bForced)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 
deleteGroupNames()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 
getGroupNodeId(const rtl::OUString & rModule)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 
IsEmailSupported() const302     sal_Bool IsEmailSupported() const {return bIsEmailSupported;}
303 
304 };
305 /*-- 29.10.2004 13:57:25---------------------------------------------------
306 
307   -----------------------------------------------------------------------*/
MailMergeCfg_Impl()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   -----------------------------------------------------------------------*/
~MailMergeCfg_Impl()322 MailMergeCfg_Impl::~MailMergeCfg_Impl()
323 {
324 }
325 /* -------------------------------------------------------------------------*/
Commit()326 void MailMergeCfg_Impl::Commit()
327 {
328 }
329 
Notify(const com::sun::star::uno::Sequence<rtl::OUString> &)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 );
CreateGeneralTabPage(sal_uInt16 nId,Window * pParent,const SfxItemSet & rSet)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 
lcl_getStringFromID(sal_uInt16 _nPageId,String & _rGroupName,String & _rPageName)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 
lcl_isOptionHidden(sal_uInt16 _nPageId,const SvtOptionsDialogOptions & _rOptOptions)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 
OptionsPageInfoOptionsPageInfo514     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 
OptionsGroupInfoOptionsGroupInfo528 	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 ) {}
~OptionsGroupInfoOptionsGroupInfo532     ~OptionsGroupInfo() { delete m_pInItemSet; delete m_pOutItemSet; }
533 };
534 
535 /* -----------------04.05.99 15:51-------------------
536  *
537  * --------------------------------------------------*/
Collapse(SvLBoxEntry * pParent)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     maColorTab           (),\
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;
OfaTreeOptionsDialog(Window * pParent,const Reference<XFrame> & _xFrame,bool bActivateLastSelection)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 
OfaTreeOptionsDialog(Window * pParent,const rtl::OUString & rExtensionId)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 
~OfaTreeOptionsDialog()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  * --------------------------------------------------*/
AddTabPage(sal_uInt16 nId,const String & rPageName,sal_uInt16 nGroup)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  * --------------------------------------------------*/
AddGroup(const String & rGroupName,SfxShell * pCreateShell,SfxModule * pCreateModule,sal_uInt16 nDialogId)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  * --------------------------------------------------*/
IMPL_LINK(OfaTreeOptionsDialog,ShowPageHdl_Impl,SvTreeListBox *,EMPTYARG)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  * --------------------------------------------------*/
IMPL_LINK(OfaTreeOptionsDialog,BackHdl_Impl,PushButton *,EMPTYARG)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  * --------------------------------------------------*/
IMPL_LINK(OfaTreeOptionsDialog,OKHdl_Impl,Button *,EMPTYARG)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  * --------------------------------------------------*/
IMPL_LINK(OfaTreeOptionsDialog,ExpandedHdl_Impl,SvTreeListBox *,pBox)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  * --------------------------------------------------*/
ApplyItemSets()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 
InitTreeAndHandler()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  * --------------------------------------------------*/
ActivatePage(sal_uInt16 nResId)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 
ActivatePage(const String & rPageURL)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  * --------------------------------------------------*/
ActivateLastSelection()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  * --------------------------------------------------*/
Notify(NotifyEvent & rNEvt)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 
DataChanged(const DataChangedEvent & rDCEvt)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:
FlagSet_Impl(bool & bFlag)1067         FlagSet_Impl(bool& bFlag) : rFlag(bFlag){rFlag = true;}
~FlagSet_Impl()1068         ~FlagSet_Impl(){rFlag = false;}
1069 };
1070 
IMPL_LINK(OfaTreeOptionsDialog,SelectHdl_Impl,Timer *,EMPTYARG)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 SvxColorTableItem* pPtr = NULL;
1205 				if ( SfxViewFrame::Current() && SfxViewFrame::Current()->GetDispatcher() )
1206 					pPtr = dynamic_cast< const SvxColorTableItem* >(SfxViewFrame::Current()->
1207 						GetDispatcher()->Execute(SID_GET_COLORTABLE, SFX_CALLMODE_SYNCHRON));
1208 				maColorTab = pPtr ? pPtr->GetColorTable() : XColorList::GetStdColorList();
1209 
1210 				rColPage.SetColorTable( maColorTab );
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 
OfaPageResource()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 
EnableSSO(void)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 
thisModule()1483 extern "C" { static void SAL_CALL thisModule() {} }
1484 
GetSSOCreator(void)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 
CreateItemSet(sal_uInt16 nId)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             SID_ATTR_ODFENCRYPTION, SID_ATTR_ODFENCRYPTION,
1631             0 );
1632             SFX_APP()->GetOptions(*pRet);
1633             break;
1634 
1635 		case SID_SB_STARBASEOPTIONS:
1636             pRet = new SfxItemSet( SFX_APP()->GetPool(),
1637             SID_SB_POOLING_ENABLED, SID_SB_DB_REGISTER,
1638             0 );
1639 			::offapp::ConnectionPoolConfig::GetOptions(*pRet);
1640 			::svx::DbRegisteredNamesConfig::GetOptions(*pRet);
1641 			break;
1642 
1643 		case SID_SCH_EDITOPTIONS:
1644 		{
1645 			SvxChartOptions aChartOpt;
1646             pRet = new SfxItemSet( SFX_APP()->GetPool(), SID_SCH_EDITOPTIONS, SID_SCH_EDITOPTIONS );
1647 			pRet->Put( SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aChartOpt.GetDefaultColors() ) );
1648 			break;
1649 		}
1650 	}
1651 	return pRet;
1652 }
1653 
ApplyItemSet(sal_uInt16 nId,const SfxItemSet & rSet)1654 void OfaTreeOptionsDialog::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
1655 {
1656 	switch(nId)
1657 	{
1658 		case SID_GENERAL_OPTIONS:
1659 		{
1660 			utl::MiscCfg	aMisc;
1661 			const SfxPoolItem* pItem;
1662             SfxItemSet aOptSet(SFX_APP()->GetPool(), SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER );
1663             aOptSet.Put(rSet);
1664             if(aOptSet.Count())
1665                 SFX_APP()->SetOptions( aOptSet );
1666     		// Dispatcher neu holen, weil SetOptions() ggf. den Dispatcher zerst"ort hat
1667             SfxViewFrame *pViewFrame = SfxViewFrame::Current();
1668 // -------------------------------------------------------------------------
1669 //			Year2000 auswerten
1670 // -------------------------------------------------------------------------
1671             sal_uInt16 nY2K = USHRT_MAX;
1672             if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_YEAR2000, sal_False, &pItem ) )
1673                 nY2K = ((const SfxUInt16Item*)pItem)->GetValue();
1674             if( USHRT_MAX != nY2K )
1675             {
1676                 if ( pViewFrame )
1677                 {
1678                     SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1679                     pDispatch->Execute( SID_ATTR_YEAR2000, SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1680                 }
1681                 aMisc.SetYear2000(nY2K);
1682             }
1683 
1684 // -------------------------------------------------------------------------
1685 //			Drucken auswerten
1686 // -------------------------------------------------------------------------
1687 			if(SFX_ITEM_SET == rSet.GetItemState(SID_PRINTER_NOTFOUND_WARN, sal_False, &pItem))
1688 				aMisc.SetNotFoundWarning(((const SfxBoolItem*)pItem)->GetValue());
1689 
1690 			if(SFX_ITEM_SET == rSet.GetItemState(SID_PRINTER_CHANGESTODOC, sal_False, &pItem))
1691 			{
1692 				const SfxFlagItem* pFlag = (const SfxFlagItem*)pItem;
1693 				aMisc.SetPaperSizeWarning(0 != (pFlag->GetValue() &  SFX_PRINTER_CHG_SIZE ));
1694                 aMisc.SetPaperOrientationWarning(0 !=  (pFlag->GetValue() & SFX_PRINTER_CHG_ORIENTATION ));
1695 			}
1696 // -------------------------------------------------------------------------
1697 //			evaluate help options
1698 // -------------------------------------------------------------------------
1699 			if ( SvtHelpOptions().IsHelpTips() != Help::IsQuickHelpEnabled() )
1700 				SvtHelpOptions().IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
1701 			if ( SvtHelpOptions().IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
1702 				SvtHelpOptions().IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
1703         }
1704 		break;
1705         case SID_LANGUAGE_OPTIONS :
1706         {
1707             OfaTreeOptionsDialog::ApplyLanguageOptions(rSet);
1708         }
1709         break;
1710 		case SID_INET_DLG :
1711         case SID_FILTER_DLG:
1712 			SFX_APP()->SetOptions( rSet );
1713 		break;
1714 
1715 		case SID_SB_STARBASEOPTIONS:
1716 			::offapp::ConnectionPoolConfig::SetOptions( rSet );
1717 			::svx::DbRegisteredNamesConfig::SetOptions(rSet);
1718 			break;
1719 
1720         case SID_SCH_EDITOPTIONS:
1721             // nothing to do. Chart options only apply to newly created charts
1722             break;
1723 
1724         default:
1725         {
1726             DBG_ERROR( "Unhandled option in ApplyItemSet" );
1727         }
1728         break;
1729 	}
1730 
1731 }
ApplyLanguageOptions(const SfxItemSet & rSet)1732 void OfaTreeOptionsDialog::ApplyLanguageOptions(const SfxItemSet& rSet)
1733 {
1734     sal_Bool bSaveSpellCheck = sal_False;
1735     const SfxPoolItem* pItem;
1736 
1737     if ( SFX_ITEM_SET == rSet.GetItemState( SID_SPELL_MODIFIED, sal_False, &pItem ) )
1738     {
1739         bSaveSpellCheck = ( (const SfxBoolItem*)pItem )->GetValue();
1740     }
1741     Reference< XMultiServiceFactory >  xMgr( ::comphelper::getProcessServiceFactory() );
1742     Reference< XPropertySet >  xProp(
1743             xMgr->createInstance( ::rtl::OUString::createFromAscii(
1744                     "com.sun.star.linguistic2.LinguProperties") ),
1745             UNO_QUERY );
1746     if ( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_HYPHENREGION, sal_False, &pItem ) )
1747     {
1748         const SfxHyphenRegionItem* pHyphenItem = (const SfxHyphenRegionItem*)pItem;
1749 
1750         if (xProp.is())
1751         {
1752             xProp->setPropertyValue(
1753                     String::CreateFromAscii(UPN_HYPH_MIN_LEADING),
1754                     makeAny((sal_Int16) pHyphenItem->GetMinLead()) );
1755             xProp->setPropertyValue(
1756                     String::CreateFromAscii(UPN_HYPH_MIN_TRAILING),
1757                     makeAny((sal_Int16) pHyphenItem->GetMinTrail()) );
1758         }
1759         bSaveSpellCheck = sal_True;
1760     }
1761 
1762     SfxViewFrame *pViewFrame = SfxViewFrame::Current();
1763     if ( pViewFrame )
1764     {
1765         SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1766         pItem = 0;
1767         if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_LANGUAGE, sal_False, &pItem ))
1768         {
1769             pDispatch->Execute(pItem->Which(),    SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1770             bSaveSpellCheck = sal_True;
1771         }
1772         if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE, sal_False, &pItem ))
1773         {
1774             pDispatch->Execute(pItem->Which(),    SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1775             bSaveSpellCheck = sal_True;
1776         }
1777         if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE, sal_False, &pItem ))
1778         {
1779             pDispatch->Execute(pItem->Which(),    SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1780             bSaveSpellCheck = sal_True;
1781         }
1782 
1783         if( SFX_ITEM_SET == rSet.GetItemState(SID_AUTOSPELL_CHECK, sal_False, &pItem ))
1784         {
1785             sal_Bool bOnlineSpelling = ((const SfxBoolItem*)pItem)->GetValue();
1786             pDispatch->Execute(SID_AUTOSPELL_CHECK,
1787                 SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, pItem, 0L);
1788 
1789             if (xProp.is())
1790             {
1791                 xProp->setPropertyValue(
1792                         String::CreateFromAscii(UPN_IS_SPELL_AUTO),
1793                         makeAny(bOnlineSpelling) );
1794             }
1795         }
1796 
1797         if( bSaveSpellCheck )
1798         {
1799             //! the config item has changed since we modified the
1800             //! property set it uses
1801             pDispatch->Execute(SID_SPELLCHECKER_CHANGED, SFX_CALLMODE_ASYNCHRON);
1802         }
1803     }
1804 
1805     if( SFX_ITEM_SET == rSet.GetItemState(SID_OPT_LOCALE_CHANGED, sal_False, &pItem ))
1806     {
1807         SfxViewFrame* _pViewFrame = SfxViewFrame::GetFirst();
1808         while ( _pViewFrame )
1809         {
1810             _pViewFrame->GetDispatcher()->Execute(pItem->Which(),    SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1811             _pViewFrame = SfxViewFrame::GetNext( *_pViewFrame );
1812         }
1813     }
1814 }
1815 
getCurrentFactory_Impl(const Reference<XFrame> & _xFrame)1816 rtl::OUString getCurrentFactory_Impl( const Reference< XFrame >& _xFrame )
1817 {
1818     rtl::OUString sIdentifier;
1819     Reference < XFrame > xCurrentFrame( _xFrame );
1820     Reference < XModuleManager > xModuleManager( ::comphelper::getProcessServiceFactory()->createInstance(
1821         DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY );
1822     if ( !xCurrentFrame.is() )
1823     {
1824         Reference< XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
1825             DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
1826         if ( xDesktop.is() )
1827             xCurrentFrame = xDesktop->getCurrentFrame();
1828     }
1829 
1830     if ( xCurrentFrame.is() && xModuleManager.is() )
1831     {
1832         try
1833         {
1834             sIdentifier = xModuleManager->identify( xCurrentFrame );
1835         }
1836         catch ( ::com::sun::star::frame::UnknownModuleException& )
1837         {
1838             DBG_WARNING( "getActiveModule_Impl(): unknown module" );
1839         }
1840         catch ( Exception& )
1841         {
1842             DBG_ERRORFILE( "getActiveModule_Impl(): exception of XModuleManager::identify()" );
1843         }
1844     }
1845 
1846     return sIdentifier;
1847 }
1848 
Initialize(const Reference<XFrame> & _xFrame)1849 void OfaTreeOptionsDialog::Initialize( const Reference< XFrame >& _xFrame )
1850 {
1851 	OfaPageResource aDlgResource;
1852 	sal_uInt16 nGroup = 0;
1853 
1854     SvtOptionsDialogOptions aOptionsDlgOpt;
1855     sal_uInt16 i, nPageId;
1856 
1857     // %PRODUCTNAME options
1858     sal_Bool isSSOEnabled = EnableSSO();
1859     if ( !lcl_isOptionHidden( SID_GENERAL_OPTIONS, aOptionsDlgOpt ) )
1860     {
1861         ResStringArray& rGeneralArray = aDlgResource.GetGeneralArray();
1862         setGroupName( C2U("ProductName"), rGeneralArray.GetString(0) );
1863         nGroup = AddGroup( rGeneralArray.GetString(0), 0, 0, SID_GENERAL_OPTIONS );
1864         sal_uInt16 nEnd = static_cast< sal_uInt16 >( rGeneralArray.Count() );
1865         String sPageTitle;
1866 
1867         for ( i = 1; i < nEnd; ++i )
1868         {
1869             String sNewTitle = rGeneralArray.GetString(i);
1870             nPageId = (sal_uInt16)rGeneralArray.GetValue(i);
1871             if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1872                 continue;
1873 
1874             // Disable Online Update page if service not installed
1875             if( RID_SVXPAGE_ONLINEUPDATE == nPageId )
1876             {
1877                 const ::rtl::OUString sService = C2U("com.sun.star.setup.UpdateCheck");
1878 
1879                 try
1880                 {
1881                     Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
1882                     Reference < XInterface > xService( xFactory->createInstance( sService ) );
1883 
1884                     if( ! xService.is() )
1885                         continue;
1886                 }
1887                 catch ( ::com::sun::star::loader::CannotActivateFactoryException& )
1888                 {
1889                     continue;
1890                 }
1891             }
1892             // Disable OOoImprovement page if not enabled
1893             if( RID_SVXPAGE_IMPROVEMENT == nPageId )
1894             {
1895                 continue;
1896             }
1897             if ( nPageId != RID_SVXPAGE_SSO || isSSOEnabled )
1898             {
1899                 AddTabPage( nPageId, sNewTitle, nGroup );
1900             }
1901         }
1902         // private iteration hack for Improvement Program
1903         // hack for OOo 3.1
1904         // should not be in found in any later release
1905         for(bool bOnce = false; bOnce==false; bOnce=true)
1906         {
1907             String sNewTitle = C2U("Improvement Program");
1908             {
1909                 SvxImprovementPage aTempTabPage(this);
1910                 sNewTitle = aTempTabPage.GetTitleText();
1911             }
1912             nPageId = RID_SVXPAGE_IMPROVEMENT;
1913             if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1914                 continue;
1915             // Disable OOoImprovement page if not enabled
1916             {
1917                 const ::rtl::OUString sService = C2U("com.sun.star.oooimprovement.CoreController");
1918                 try
1919                 {
1920                     Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
1921                     Reference < ::com::sun::star::oooimprovement::XCoreController > xService( xFactory->createInstance( sService ), UNO_QUERY );
1922 
1923                     if( ! xService.is() )
1924                         continue;
1925                     if( ! xService->showBuiltinOptionsPage(1))
1926                         continue;
1927                 }
1928                 catch ( ::com::sun::star::loader::CannotActivateFactoryException& )
1929                 {
1930                     continue;
1931                 }
1932             }
1933             if ( nPageId != RID_SVXPAGE_SSO || isSSOEnabled )
1934             {
1935                 AddTabPage( nPageId, sNewTitle, nGroup );
1936             }
1937         }
1938     }
1939 
1940     // Load and Save options
1941     if ( !lcl_isOptionHidden( SID_FILTER_DLG, aOptionsDlgOpt ) )
1942     {
1943         ResStringArray& rFilterArray = aDlgResource.GetFilterArray();
1944         setGroupName( C2U("LoadSave"), rFilterArray.GetString(0) );
1945         nGroup = AddGroup( rFilterArray.GetString(0), 0, 0, SID_FILTER_DLG );
1946         for ( i = 1; i < rFilterArray.Count(); ++i )
1947         {
1948             nPageId = (sal_uInt16)rFilterArray.GetValue(i);
1949             if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1950                 AddTabPage( nPageId, rFilterArray.GetString(i), nGroup );
1951         }
1952     }
1953 
1954     // Language options
1955     SvtLanguageOptions aLanguageOptions;
1956     if ( !lcl_isOptionHidden( SID_LANGUAGE_OPTIONS, aOptionsDlgOpt ) )
1957     {
1958         ResStringArray& rLangArray = aDlgResource.GetLangArray();
1959         setGroupName( C2U("LanguageSettings"), rLangArray.GetString(0) );
1960         nGroup = AddGroup( rLangArray.GetString(0), 0, 0, SID_LANGUAGE_OPTIONS );
1961         for ( i = 1; i < rLangArray.Count(); ++i )
1962         {
1963             nPageId = (sal_uInt16)rLangArray.GetValue(i);
1964             if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1965                 continue;
1966             if ( ( RID_SVXPAGE_JSEARCH_OPTIONS != nPageId || aLanguageOptions.IsJapaneseFindEnabled() ) &&
1967                  ( RID_SVXPAGE_ASIAN_LAYOUT != nPageId    || aLanguageOptions.IsAsianTypographyEnabled() ) &&
1968                  ( RID_SVXPAGE_OPTIONS_CTL != nPageId     || aLanguageOptions.IsCTLFontEnabled() ) )
1969                 AddTabPage( nPageId, rLangArray.GetString(i), nGroup );
1970         }
1971     }
1972 
1973 
1974     rtl::OUString aFactory = getCurrentFactory_Impl( _xFrame );
1975     rtl::OUString sTemp = GetModuleIdentifier( comphelper::getProcessServiceFactory(), _xFrame );
1976     DBG_ASSERT( sTemp == aFactory, "S H I T!!!" );
1977 
1978     // Writer and Writer/Web options
1979     sal_Bool bHasAnyFilter = sal_False;
1980     SvtModuleOptions aModuleOpt;
1981     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
1982     {
1983         // Textdokument
1984         bHasAnyFilter = sal_True;
1985         ResStringArray& rTextArray = aDlgResource.GetTextArray();
1986         if (   aFactory.equalsAscii( "com.sun.star.text.TextDocument" )
1987             || aFactory.equalsAscii( "com.sun.star.text.WebDocument" )
1988             || aFactory.equalsAscii( "com.sun.star.text.GlobalDocument" ) )
1989         {
1990             SfxModule* pSwMod = (*(SfxModule**) GetAppData(SHL_WRITER));
1991             if ( !lcl_isOptionHidden( SID_SW_EDITOPTIONS, aOptionsDlgOpt ) )
1992             {
1993                 if ( aFactory.equalsAscii( "com.sun.star.text.WebDocument" ) )
1994                     setGroupName( C2U("WriterWeb"), rTextArray.GetString(0) );
1995                 else
1996                     setGroupName( C2U("Writer"), rTextArray.GetString(0) );
1997                 nGroup = AddGroup(rTextArray.GetString(0), pSwMod, pSwMod, SID_SW_EDITOPTIONS );
1998                 for ( i = 1; i < rTextArray.Count(); ++i )
1999                 {
2000                     nPageId = (sal_uInt16)rTextArray.GetValue(i);
2001                     if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2002                         continue;
2003                     if ( ( RID_SW_TP_STD_FONT_CJK != nPageId || aLanguageOptions.IsCJKFontEnabled() ) &&
2004                          ( RID_SW_TP_STD_FONT_CTL != nPageId || aLanguageOptions.IsCTLFontEnabled() ) &&
2005                          ( RID_SW_TP_MAILCONFIG != nPageId || MailMergeCfg_Impl().IsEmailSupported() ) )
2006                         AddTabPage( nPageId, rTextArray.GetString(i), nGroup );
2007                 }
2008 #ifdef DBG_UTIL
2009                 AddTabPage( RID_SW_TP_OPTTEST_PAGE, String::CreateFromAscii("Interner Test"), nGroup );
2010 #endif
2011             }
2012 
2013             // HTML-Dokument
2014             if ( !lcl_isOptionHidden( SID_SW_ONLINEOPTIONS, aOptionsDlgOpt ) )
2015             {
2016                 ResStringArray& rHTMLArray = aDlgResource.GetHTMLArray();
2017                 nGroup = AddGroup(rHTMLArray.GetString(0), pSwMod, pSwMod, SID_SW_ONLINEOPTIONS );
2018                 for( i = 1; i < rHTMLArray.Count(); ++i )
2019                 {
2020                     nPageId = (sal_uInt16)rHTMLArray.GetValue(i);
2021                     if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2022                         AddTabPage( nPageId, rHTMLArray.GetString(i), nGroup );
2023                 }
2024 #ifdef DBG_UTIL
2025                 AddTabPage( RID_SW_TP_OPTTEST_PAGE, String::CreateFromAscii("Interner Test"), nGroup );
2026 #endif
2027             }
2028         }
2029     }
2030 
2031     // Calc options
2032     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
2033     {
2034         bHasAnyFilter = sal_True;
2035         if ( aFactory.equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ))
2036         {
2037             if ( !lcl_isOptionHidden( SID_SC_EDITOPTIONS, aOptionsDlgOpt ) )
2038             {
2039                 ResStringArray& rCalcArray = aDlgResource.GetCalcArray();
2040                 SfxModule* pScMod = ( *( SfxModule** ) GetAppData( SHL_CALC ) );
2041                 setGroupName( C2U("Calc"), rCalcArray.GetString(0) );
2042                 nGroup = AddGroup( rCalcArray.GetString( 0 ), pScMod, pScMod, SID_SC_EDITOPTIONS );
2043                 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rCalcArray.Count() );
2044                 for ( i = 1; i < nCount; ++i )
2045                 {
2046                     nPageId = (sal_uInt16)rCalcArray.GetValue(i);
2047                     if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2048                         continue;
2049 //                  if( bCTL || nId != RID_OFA_TP_INTERNATIONAL )
2050 //                  #103755# if an international tabpage is need one day, this should be used again... ;-)
2051                     if ( nPageId != RID_OFA_TP_INTERNATIONAL )
2052                         AddTabPage( nPageId, rCalcArray.GetString( i ), nGroup );
2053                 }
2054             }
2055         }
2056     }
2057 
2058     // Impress options
2059     SfxModule* pSdMod = ( *( SfxModule** ) GetAppData( SHL_DRAW ) );
2060     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
2061     {
2062         bHasAnyFilter = sal_True;
2063         if ( aFactory.equalsAscii( "com.sun.star.presentation.PresentationDocument" ))
2064         {
2065             if ( !lcl_isOptionHidden( SID_SD_EDITOPTIONS, aOptionsDlgOpt ) )
2066             {
2067                 ResStringArray& rImpressArray = aDlgResource.GetImpressArray();
2068                 setGroupName( C2U("Impress"), rImpressArray.GetString(0) );
2069                 nGroup = AddGroup( rImpressArray.GetString( 0 ), pSdMod, pSdMod, SID_SD_EDITOPTIONS );
2070                 const sal_Bool bCTL = aLanguageOptions.IsCTLFontEnabled();
2071                 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rImpressArray.Count() );
2072                 for ( i = 1; i < nCount; ++i )
2073                 {
2074                     nPageId = (sal_uInt16)rImpressArray.GetValue(i);
2075                     if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2076                         continue;
2077                     if ( bCTL || nPageId != RID_OFA_TP_INTERNATIONAL_IMPR )
2078                         AddTabPage( nPageId, rImpressArray.GetString(i), nGroup );
2079                 }
2080             }
2081         }
2082     }
2083 
2084     // Draw options
2085     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
2086     {
2087         if ( aFactory.equalsAscii( "com.sun.star.drawing.DrawingDocument" ))
2088         {
2089             if ( !lcl_isOptionHidden( SID_SD_GRAPHIC_OPTIONS, aOptionsDlgOpt ) )
2090             {
2091                 ResStringArray& rDrawArray = aDlgResource.GetDrawArray();
2092                 setGroupName( C2U("Draw"), rDrawArray.GetString(0) );
2093                 nGroup = AddGroup( rDrawArray.GetString( 0 ), pSdMod, pSdMod, SID_SD_GRAPHIC_OPTIONS );
2094                 const sal_Bool bCTL = aLanguageOptions.IsCTLFontEnabled();
2095                 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rDrawArray.Count() );
2096                 for ( i = 1; i < nCount; ++i )
2097                 {
2098                     nPageId = (sal_uInt16)rDrawArray.GetValue(i);
2099                     if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2100                         continue;
2101                     if ( bCTL || nPageId != RID_OFA_TP_INTERNATIONAL_SD )
2102                         AddTabPage( nPageId, rDrawArray.GetString(i), nGroup );
2103                 }
2104             }
2105         }
2106     }
2107 
2108     // Math options
2109     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
2110     {
2111         if ( aFactory.equalsAscii( "com.sun.star.formula.FormulaProperties" ))
2112         {
2113             if ( !lcl_isOptionHidden( SID_SM_EDITOPTIONS, aOptionsDlgOpt ) )
2114             {
2115                 ResStringArray& rStarMathArray = aDlgResource.GetStarMathArray();
2116                 SfxModule* pSmMod = (*(SfxModule**) GetAppData(SHL_SM));
2117                 setGroupName( C2U("Math"), rStarMathArray.GetString(0) );
2118                 nGroup = AddGroup(rStarMathArray.GetString(0), pSmMod, pSmMod, SID_SM_EDITOPTIONS );
2119                 for ( i = 1; i < rStarMathArray.Count(); ++i )
2120                 {
2121                     nPageId = (sal_uInt16)rStarMathArray.GetValue(i);
2122                     if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2123                         AddTabPage( nPageId, rStarMathArray.GetString(i), nGroup );
2124                 }
2125             }
2126         }
2127     }
2128 
2129     // Database - needed only if there is an application which integrates with databases
2130     if ( !lcl_isOptionHidden( SID_SB_STARBASEOPTIONS, aOptionsDlgOpt ) &&
2131         (   aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE )
2132         ||  aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER )
2133         ||  aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC )
2134         ) )
2135     {
2136         ResStringArray& rDSArray = aDlgResource.GetDatasourcesArray();
2137         setGroupName( C2U("Base"), rDSArray.GetString(0) );
2138         nGroup = AddGroup( rDSArray.GetString(0), 0, NULL, SID_SB_STARBASEOPTIONS );
2139         for ( i = 1; i < rDSArray.Count(); ++i )
2140         {
2141             nPageId = (sal_uInt16)rDSArray.GetValue(i);
2142             if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2143                 AddTabPage( nPageId, rDSArray.GetString(i), nGroup );
2144         }
2145     }
2146 
2147     // Chart options (always installed and active)
2148     if ( !lcl_isOptionHidden( SID_SCH_EDITOPTIONS, aOptionsDlgOpt ) )
2149     {
2150         ResStringArray& rChartArray = aDlgResource.GetChartArray();
2151         setGroupName( C2U("Charts"), rChartArray.GetString(0) );
2152         nGroup = AddGroup( rChartArray.GetString(0), 0, 0, SID_SCH_EDITOPTIONS );
2153         for ( i = 1; i < rChartArray.Count(); ++i )
2154         {
2155             nPageId = (sal_uInt16)rChartArray.GetValue(i);
2156             if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2157                AddTabPage( nPageId, rChartArray.GetString(i), nGroup );
2158         }
2159     }
2160 
2161     // Internet options
2162     if ( !lcl_isOptionHidden( SID_INET_DLG, aOptionsDlgOpt ) )
2163     {
2164         ResStringArray& rInetArray = aDlgResource.GetInetArray();
2165         setGroupName( C2U("Internet"), rInetArray.GetString(0) );
2166         nGroup = AddGroup(rInetArray.GetString(0), 0, 0, SID_INET_DLG );
2167 
2168         for ( i = 1; i < rInetArray.Count(); ++i )
2169         {
2170             nPageId = (sal_uInt16)rInetArray.GetValue(i);
2171             if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
2172                 continue;
2173 #if defined WNT
2174             // Disable E-mail tab-page on Windows
2175             if ( nPageId == RID_SVXPAGE_INET_MAIL )
2176                 continue;
2177 #endif
2178             AddTabPage( nPageId, rInetArray.GetString(i), nGroup );
2179         }
2180     }
2181 
2182 /*!!!
2183     ResizeTreeLB();
2184     ActivateLastSelection();
2185  */
2186 }
2187 
2188 namespace
2189 {
MoveControl(Control & _rCtrl,long _nDeltaPixel)2190 	void MoveControl( Control& _rCtrl, long _nDeltaPixel )
2191 	{
2192 		Point	aPt( _rCtrl.GetPosPixel() );
2193 		aPt.X() += _nDeltaPixel;
2194 		_rCtrl.SetPosPixel( aPt );
2195 	}
2196 }
2197 
ResizeTreeLB(void)2198 void OfaTreeOptionsDialog::ResizeTreeLB( void )
2199 {
2200     const long  nMax = aHiddenGB.GetSizePixel().Width() * 42 / 100;
2201                                             // don't ask where 42 comes from... but it looks / feels ok ;-)
2202     long        nDelta = 50;                // min.
2203     sal_uInt16      nDepth = 0;
2204     const long  nIndent0 = PixelToLogic( Size( 28, 0 ) ).Width();
2205     const long  nIndent1 = PixelToLogic( Size( 52, 0 ) ).Width();
2206 
2207 	SvTreeList*			pTreeList = aTreeLB.GetModel();
2208 	DBG_ASSERT( pTreeList, "-OfaTreeOptionsDialog::ResizeTreeLB(): no model, no cookies!" );
2209 
2210 	SvListEntry*		pEntry = pTreeList->First();
2211 	while( pEntry )
2212 	{
2213         long n = aTreeLB.GetTextWidth( aTreeLB.GetEntryText( static_cast< SvLBoxEntry* >( pEntry ) ) );
2214 		n += ( nDepth == 0 )? nIndent0 : nIndent1;
2215 
2216 		if( n > nDelta )
2217 			nDelta = n;
2218 
2219 		pEntry = pTreeList->Next( pEntry, &nDepth );
2220 	}
2221 
2222 	nDelta = LogicToPixel( Size( nDelta + 3, 0 ) ).Width();			// + extra space [logic]
2223 	nDelta += GetSettings().GetStyleSettings().GetScrollBarSize();	// + scroll bar, in case it's needed
2224 
2225 	if( nDelta > nMax )
2226 		nDelta = nMax;
2227 
2228 	// starting resizing with this
2229 	Size			aSize( GetSizePixel() );
2230 	aSize.Width() += nDelta;
2231 	SetSizePixel( aSize );
2232 
2233 	// resize treelistbox
2234 	aSize = aTreeLB.GetSizePixel();
2235 	aSize.Width() += nDelta;
2236 	aTreeLB.SetSizePixel( aSize );
2237 
2238 	// ... and move depending controls
2239 	MoveControl( aOkPB, nDelta );
2240 	MoveControl( aCancelPB, nDelta );
2241 	MoveControl( aHelpPB, nDelta );
2242 	MoveControl( aBackPB, nDelta );
2243 	MoveControl( aHiddenGB, nDelta );
2244 	MoveControl( aPageTitleFT, nDelta );
2245 	MoveControl( aLine1FL, nDelta );
2246 	MoveControl( aHelpFT, nDelta );
2247 	MoveControl( aHelpImg, nDelta );
2248 }
2249 
isNodeActive(OptionsNode * pNode,Module * pModule)2250 bool isNodeActive( OptionsNode* pNode, Module* pModule )
2251 {
2252     if ( pNode )
2253     {
2254         // Node for all modules active?
2255         if ( pNode->m_bAllModules )
2256             return true;
2257 
2258         // AOO-Nodes (Writer, Calc, Impress...) are active if node is already inserted
2259         if ( getGroupName( pNode->m_sId, false ).Len() > 0 )
2260             return true;
2261 
2262         // no module -> not active
2263         if ( !pModule )
2264             return false;
2265 
2266         // search node in active module
2267         if ( pModule->m_bActive )
2268         {
2269             for ( sal_uInt32 j = 0; j < pModule->m_aNodeList.size(); ++j )
2270                 if ( pModule->m_aNodeList[j]->m_sId == pNode->m_sId )
2271                     return true;
2272         }
2273     }
2274     return false;
2275 }
2276 
LoadExtensionOptions(const rtl::OUString & rExtensionId)2277 void OfaTreeOptionsDialog::LoadExtensionOptions( const rtl::OUString& rExtensionId )
2278 {
2279     Module* pModule = NULL;
2280     Reference< XMultiServiceFactory > xMSFac = comphelper::getProcessServiceFactory();
2281     // open optionsdialog.xcu
2282     Reference< XNameAccess > xRoot(
2283         ::comphelper::ConfigurationHelper::openConfig(
2284             xMSFac, C2U("org.openoffice.Office.OptionsDialog"),
2285             ::comphelper::ConfigurationHelper::E_READONLY ), UNO_QUERY );
2286     DBG_ASSERT( xRoot.is(), "OfaTreeOptionsDialog::LoadExtensionOptions(): no config" );
2287     // when called by Tools - Options then load nodes of active module
2288     if ( rExtensionId.getLength() == 0 )
2289         pModule = LoadModule( GetModuleIdentifier( xMSFac, Reference< XFrame >() ), xRoot );
2290 
2291     VectorOfNodes aNodeList;
2292     LoadNodes( xRoot, pModule, rExtensionId, aNodeList );
2293     InsertNodes( aNodeList );
2294 }
2295 
GetModuleIdentifier(const Reference<XMultiServiceFactory> & xMFac,const Reference<XFrame> & rFrame)2296 rtl::OUString OfaTreeOptionsDialog::GetModuleIdentifier(
2297     const Reference< XMultiServiceFactory >& xMFac, const Reference< XFrame >& rFrame )
2298 {
2299     rtl::OUString sModule;
2300     Reference < XFrame > xCurrentFrame( rFrame );
2301     Reference < XModuleManager > xModuleManager( xMFac->createInstance(
2302         C2U("com.sun.star.frame.ModuleManager") ), UNO_QUERY );
2303 
2304     if ( !xCurrentFrame.is() )
2305     {
2306         Reference < XDesktop > xDesktop( xMFac->createInstance(
2307             C2U("com.sun.star.frame.Desktop") ), UNO_QUERY );
2308         if ( xDesktop.is() )
2309             xCurrentFrame = xDesktop->getCurrentFrame();
2310     }
2311 
2312     if ( xCurrentFrame.is() && xModuleManager.is() )
2313     {
2314         try
2315         {
2316             sModule = xModuleManager->identify( xCurrentFrame );
2317         }
2318         catch ( ::com::sun::star::frame::UnknownModuleException& )
2319         {
2320             DBG_WARNING( "OfaTreeOptionsDialog::GetModuleIdentifier(): unknown module" );
2321         }
2322         catch ( Exception& )
2323         {
2324             DBG_ERRORFILE( "OfaTreeOptionsDialog::GetModuleIdentifier(): exception of XModuleManager::identify()" );
2325         }
2326     }
2327     return sModule;
2328 }
2329 
LoadModule(const rtl::OUString & rModuleIdentifier,const Reference<XNameAccess> & xRoot)2330 Module* OfaTreeOptionsDialog::LoadModule(
2331     const rtl::OUString& rModuleIdentifier, const Reference< XNameAccess >& xRoot )
2332 {
2333     Module* pModule = NULL;
2334     Reference< XNameAccess > xSet;
2335 
2336     if ( xRoot->hasByName( C2U("Modules") ) )
2337     {
2338         xRoot->getByName( C2U("Modules") ) >>= xSet;
2339         if ( xSet.is() )
2340         {
2341             Sequence< rtl::OUString > seqNames = xSet->getElementNames();
2342             for ( int i = 0; i < seqNames.getLength(); ++i )
2343             {
2344                 rtl::OUString sModule( seqNames[i] );
2345                 if ( rModuleIdentifier == sModule )
2346                 {
2347                     // current active module found
2348                     pModule = new Module( sModule );
2349                     pModule->m_bActive = true;
2350 
2351                     Reference< XNameAccess > xModAccess;
2352                     xSet->getByName( seqNames[i] ) >>= xModAccess;
2353                     if ( xModAccess.is() )
2354                     {
2355                         // load the nodes of this module
2356                         Reference< XNameAccess > xNodeAccess;
2357                         xModAccess->getByName( C2U("Nodes") ) >>= xNodeAccess;
2358                         if ( xNodeAccess.is() )
2359                         {
2360                             Sequence< rtl::OUString > xTemp = xNodeAccess->getElementNames();
2361                             Reference< XNameAccess > xAccess;
2362                             sal_Int32 nIndex = -1;
2363                             for ( int x = 0; x < xTemp.getLength(); ++x )
2364                             {
2365                                 xNodeAccess->getByName( xTemp[x] ) >>= xAccess;
2366                                 if ( xAccess.is() )
2367                                 {
2368                                     xAccess->getByName( C2U("Index") ) >>= nIndex;
2369                                     if ( nIndex < 0 )
2370                                         // append nodes with index < 0
2371                                         pModule->m_aNodeList.push_back(
2372                                             new OrderedEntry( nIndex, xTemp[x] ) );
2373                                     else
2374                                     {
2375                                         // search position of the node
2376                                         sal_uInt32 y = 0;
2377                                         for ( ; y < pModule->m_aNodeList.size(); ++y )
2378                                         {
2379                                             sal_Int32 nNodeIdx = pModule->m_aNodeList[y]->m_nIndex;
2380                                             if ( nNodeIdx < 0 || nNodeIdx > nIndex )
2381                                                 break;
2382                                         }
2383                                         // and insert the node on this position
2384                                         pModule->m_aNodeList.insert(
2385                                             pModule->m_aNodeList.begin() + y,
2386                                             new OrderedEntry( nIndex, xTemp[x] ) );
2387                                     }
2388                                 }
2389                             }
2390                         }
2391                     }
2392                 }
2393             }
2394         }
2395     }
2396     return pModule;
2397 }
2398 
LoadNodes(const Reference<XNameAccess> & xRoot,Module * pModule,const rtl::OUString & rExtensionId,VectorOfNodes & rOutNodeList)2399 void OfaTreeOptionsDialog::LoadNodes(
2400     const Reference< XNameAccess >& xRoot, Module* pModule,
2401     const rtl::OUString& rExtensionId, VectorOfNodes& rOutNodeList )
2402 {
2403     Reference< XNameAccess > xSet;
2404     if ( xRoot->hasByName( C2U("Nodes") ) )
2405     {
2406         xRoot->getByName( C2U("Nodes") ) >>= xSet;
2407         if ( xSet.is() )
2408         {
2409             VectorOfNodes aNodeList;
2410             Sequence< rtl::OUString > seqNames = xSet->getElementNames();
2411 
2412             for ( int i = 0; i < seqNames.getLength(); ++i )
2413             {
2414                 String sGroupName( seqNames[i] );
2415                 Reference< XNameAccess > xNodeAccess;
2416                 xSet->getByName( seqNames[i] ) >>= xNodeAccess;
2417 
2418                 if ( xNodeAccess.is() )
2419                 {
2420                     rtl::OUString sNodeId, sLabel, sPageURL, sGroupId;
2421                     bool bAllModules = false;
2422                     sal_Int32 nGroupIndex = 0;
2423 
2424                     sNodeId = seqNames[i];
2425                     xNodeAccess->getByName( C2U("Label") ) >>= sLabel;
2426                     xNodeAccess->getByName( C2U("OptionsPage") ) >>= sPageURL;
2427                     xNodeAccess->getByName( C2U("AllModules") ) >>= bAllModules;
2428                     xNodeAccess->getByName( C2U("GroupId") ) >>= sGroupId;
2429                     xNodeAccess->getByName( C2U("GroupIndex") ) >>= nGroupIndex;
2430 
2431                     if ( sLabel.getLength() == 0 )
2432                         sLabel = sGroupName;
2433                     String sTemp = getGroupName( sLabel, rExtensionId.getLength() > 0 );
2434                     if ( sTemp.Len() > 0 )
2435                         sLabel = sTemp;
2436                     OptionsNode* pNode =
2437                         new OptionsNode( sNodeId, sLabel, sPageURL, bAllModules, sGroupId, nGroupIndex );
2438 
2439                     if ( !rExtensionId.getLength() && !isNodeActive( pNode, pModule ) )
2440                     {
2441                         delete pNode;
2442                         continue;
2443                     }
2444 
2445                     Reference< XNameAccess > xLeavesSet;
2446                     xNodeAccess->getByName( C2U( "Leaves" ) ) >>= xLeavesSet;
2447                     if ( xLeavesSet.is() )
2448                     {
2449                         Sequence< rtl::OUString > seqLeaves = xLeavesSet->getElementNames();
2450                         for ( int j = 0; j < seqLeaves.getLength(); ++j )
2451                         {
2452                             Reference< XNameAccess > xLeaveAccess;
2453                             xLeavesSet->getByName( seqLeaves[j] ) >>= xLeaveAccess;
2454 
2455                             if ( xLeaveAccess.is() )
2456                             {
2457                                 rtl::OUString sId, sLeafLabel, sEventHdl, sLeafURL, sLeafGrpId;
2458                                 sal_Int32 nLeafGrpIdx = 0;
2459 
2460                                 xLeaveAccess->getByName( C2U("Id") ) >>= sId;
2461                                 xLeaveAccess->getByName( C2U("Label") ) >>= sLeafLabel;
2462                                 xLeaveAccess->getByName( C2U("OptionsPage") ) >>= sLeafURL;
2463                                 xLeaveAccess->getByName( C2U("EventHandlerService") ) >>= sEventHdl;
2464                                 xLeaveAccess->getByName( C2U("GroupId") ) >>= sLeafGrpId;
2465                                 xLeaveAccess->getByName( C2U("GroupIndex") ) >>= nLeafGrpIdx;
2466 
2467                                 if ( !rExtensionId.getLength() || sId == rExtensionId )
2468                                 {
2469                                     OptionsLeaf* pLeaf = new OptionsLeaf(
2470                                         sId, sLeafLabel, sLeafURL, sEventHdl, sLeafGrpId, nLeafGrpIdx );
2471 
2472                                     if ( sLeafGrpId.getLength() > 0 )
2473                                     {
2474                                         bool bAlreadyOpened = false;
2475                                         if ( pNode->m_aGroupedLeaves.size() > 0 )
2476                                         {
2477                                             for ( sal_uInt32 k = 0;
2478                                                     k < pNode->m_aGroupedLeaves.size(); ++k )
2479                                             {
2480                                                 if ( pNode->m_aGroupedLeaves[k].size() > 0 &&
2481                                                      pNode->m_aGroupedLeaves[k][0]->m_sGroupId
2482                                                         == sLeafGrpId )
2483                                                 {
2484                                                     sal_uInt32 l = 0;
2485                                                     for ( ; l < pNode->m_aGroupedLeaves[k].size(); ++l )
2486                                                     {
2487                                                         if ( pNode->m_aGroupedLeaves[k][l]->
2488                                                                 m_nGroupIndex >= nLeafGrpIdx )
2489                                                             break;
2490                                                     }
2491                                                     pNode->m_aGroupedLeaves[k].insert(
2492                                                         pNode->m_aGroupedLeaves[k].begin() + l, pLeaf );
2493                                                     bAlreadyOpened = true;
2494                                                     break;
2495                                                 }
2496                                             }
2497                                         }
2498                                         if ( !bAlreadyOpened )
2499                                         {
2500                                             VectorOfLeaves aGroupedLeaves;
2501                                             aGroupedLeaves.push_back( pLeaf );
2502                                             pNode->m_aGroupedLeaves.push_back( aGroupedLeaves );
2503                                         }
2504                                     }
2505                                     else
2506                                         pNode->m_aLeaves.push_back(
2507                                             new OptionsLeaf(
2508                                                 sId, sLeafLabel, sLeafURL,
2509                                                 sEventHdl, sLeafGrpId, nLeafGrpIdx ) );
2510                                 }
2511                             }
2512                         }
2513                     }
2514 
2515                     // do not insert nodes without leaves
2516                     if ( pNode->m_aLeaves.size() > 0 || pNode->m_aGroupedLeaves.size() > 0 )
2517                     {
2518                         pModule ? aNodeList.push_back( pNode ) : rOutNodeList.push_back( pNode );
2519                     }
2520                     else
2521                         delete pNode;
2522                 }
2523             }
2524 
2525             if ( pModule && aNodeList.size() > 0 )
2526             {
2527                 sal_uInt32 i = 0, j = 0;
2528                 for ( ; i < pModule->m_aNodeList.size(); ++i )
2529                 {
2530                     rtl::OUString sNodeId = pModule->m_aNodeList[i]->m_sId;
2531                     for ( j = 0; j < aNodeList.size(); ++j )
2532                     {
2533                         OptionsNode* pNode = aNodeList[j];
2534                         if ( pNode->m_sId == sNodeId )
2535                         {
2536                             rOutNodeList.push_back( pNode );
2537                             aNodeList.erase( aNodeList.begin() + j );
2538                             break;
2539                         }
2540                     }
2541                 }
2542 
2543                 for ( i = 0; i < aNodeList.size(); ++i )
2544                     rOutNodeList.push_back( aNodeList[i] );
2545             }
2546         }
2547     }
2548 }
2549 
lcl_getGroupId(const rtl::OUString & rGroupName,const SvTreeListBox & rTreeLB)2550 sal_uInt16 lcl_getGroupId( const rtl::OUString& rGroupName, const SvTreeListBox& rTreeLB )
2551 {
2552     String sGroupName( rGroupName );
2553     sal_uInt16 nRet = 0;
2554     SvLBoxEntry* pEntry = rTreeLB.First();
2555     while( pEntry )
2556     {
2557         if ( !rTreeLB.GetParent( pEntry ) )
2558         {
2559             String sTemp( rTreeLB.GetEntryText( pEntry ) );
2560             if ( sTemp == sGroupName )
2561                 return nRet;
2562             nRet++;
2563         }
2564         pEntry = rTreeLB.Next( pEntry );
2565     }
2566 
2567     return USHRT_MAX;
2568 }
2569 
lcl_insertLeaf(OfaTreeOptionsDialog * pDlg,OptionsNode * pNode,OptionsLeaf * pLeaf,const SvTreeListBox & rTreeLB)2570 void lcl_insertLeaf(
2571     OfaTreeOptionsDialog* pDlg, OptionsNode* pNode, OptionsLeaf* pLeaf, const SvTreeListBox& rTreeLB )
2572 {
2573     sal_uInt16 nGrpId = lcl_getGroupId( pNode->m_sLabel, rTreeLB );
2574     if ( USHRT_MAX == nGrpId )
2575     {
2576         sal_uInt16 nNodeGrpId = getGroupNodeId( pNode->m_sId );
2577         nGrpId = pDlg->AddGroup( pNode->m_sLabel, NULL, NULL, nNodeGrpId );
2578         if ( pNode->m_sPageURL.getLength() > 0 )
2579         {
2580             SvLBoxEntry* pGrpEntry = rTreeLB.GetEntry( 0, nGrpId );
2581             DBG_ASSERT( pGrpEntry, "OfaTreeOptionsDialog::InsertNodes(): no group" );
2582             if ( pGrpEntry )
2583             {
2584                 OptionsGroupInfo* pGrpInfo =
2585                     static_cast<OptionsGroupInfo*>(pGrpEntry->GetUserData());
2586                 pGrpInfo->m_sPageURL = pNode->m_sPageURL;
2587             }
2588         }
2589     }
2590     OptionsPageInfo* pInfo = pDlg->AddTabPage( 0, pLeaf->m_sLabel, nGrpId );
2591     pInfo->m_sPageURL = pLeaf->m_sPageURL;
2592     pInfo->m_sEventHdl = pLeaf->m_sEventHdl;
2593 }
2594 
InsertNodes(const VectorOfNodes & rNodeList)2595 void  OfaTreeOptionsDialog::InsertNodes( const VectorOfNodes& rNodeList )
2596 {
2597     for ( sal_uInt32 i = 0; i < rNodeList.size(); ++i )
2598     {
2599         OptionsNode* pNode = rNodeList[i];
2600 
2601         if ( pNode->m_aLeaves.size() > 0 || pNode->m_aGroupedLeaves.size() > 0 )
2602         {
2603             sal_uInt32 j = 0;
2604             for ( ; j < pNode->m_aGroupedLeaves.size(); ++j )
2605             {
2606                 for ( sal_uInt32 k = 0; k < pNode->m_aGroupedLeaves[j].size(); ++k )
2607                 {
2608                     OptionsLeaf* pLeaf = pNode->m_aGroupedLeaves[j][k];
2609                     lcl_insertLeaf( this, pNode, pLeaf, aTreeLB );
2610                 }
2611             }
2612 
2613             for ( j = 0; j < pNode->m_aLeaves.size(); ++j )
2614             {
2615                 OptionsLeaf* pLeaf = pNode->m_aLeaves[j];
2616                 lcl_insertLeaf( this, pNode, pLeaf, aTreeLB );
2617             }
2618         }
2619     }
2620 }
2621 
Execute()2622 short OfaTreeOptionsDialog::Execute()
2623 {
2624     ::std::auto_ptr< SvxDicListChgClamp > pClamp;
2625     if ( !bIsFromExtensionManager )
2626     {
2627         // collect all DictionaryList Events while the dialog is executed
2628         Reference<com::sun::star::linguistic2::XDictionaryList> xDictionaryList(SvxGetDictionaryList());
2629         pClamp = ::std::auto_ptr< SvxDicListChgClamp >( new SvxDicListChgClamp( xDictionaryList ) );
2630     }
2631 	short nRet = SfxModalDialog::Execute();
2632 
2633 	if( RET_OK == nRet )
2634 	{
2635 		ApplyItemSets();
2636 		if( GetColorTable() )
2637 		{
2638 			GetColorTable()->Save();
2639 
2640 			// notify current viewframe if it uses the same color table
2641 			if ( SfxViewFrame::Current() && SfxViewFrame::Current()->GetDispatcher() )
2642 			{
2643 				const SvxColorTableItem* pPtr = dynamic_cast< const SvxColorTableItem* >(
2644                     SfxViewFrame::Current()->GetDispatcher()->Execute(SID_GET_COLORTABLE, SFX_CALLMODE_SYNCHRON));
2645 				if( pPtr )
2646 				{
2647                     XColorListSharedPtr aColorTab = pPtr->GetColorTable();
2648 
2649                     if( aColorTab &&
2650                         aColorTab->GetPath() == GetColorTable()->GetPath() &&
2651                         aColorTab->GetName() == GetColorTable()->GetName() )
2652                         SfxObjectShell::Current()->PutItem( SvxColorTableItem( GetColorTable(), SID_COLOR_TABLE ) );
2653 				}
2654 			}
2655 		}
2656 
2657         utl::ConfigManager::GetConfigManager()->StoreConfigItems();
2658     }
2659 
2660 	return nRet;
2661 }
2662 
2663 // class ExtensionsTabPage -----------------------------------------------
2664 
ExtensionsTabPage(Window * pParent,WinBits nStyle,const rtl::OUString & rPageURL,const rtl::OUString & rEvtHdl,const Reference<awt::XContainerWindowProvider> & rProvider)2665 ExtensionsTabPage::ExtensionsTabPage(
2666     Window* pParent, WinBits nStyle, const rtl::OUString& rPageURL,
2667     const rtl::OUString& rEvtHdl, const Reference< awt::XContainerWindowProvider >& rProvider ) :
2668 
2669     TabPage( pParent, nStyle ),
2670 
2671     m_sPageURL          ( rPageURL ),
2672     m_sEventHdl         ( rEvtHdl ),
2673     m_xWinProvider      ( rProvider ),
2674     m_bIsWindowHidden   ( false )
2675 
2676 {
2677 }
2678 
2679 // -----------------------------------------------------------------------
2680 
~ExtensionsTabPage()2681 ExtensionsTabPage::~ExtensionsTabPage()
2682 {
2683     Hide();
2684     DeactivatePage();
2685 
2686     if ( m_xPage.is() )
2687     {
2688         Reference< XComponent > xComponent( m_xPage, UNO_QUERY );
2689         if ( xComponent.is() )
2690         {
2691             try
2692             {
2693                 xComponent->dispose();
2694             }
2695             catch ( const Exception & )
2696             {
2697             }
2698         }
2699         m_xPage.clear();
2700     }
2701 }
2702 
2703 // -----------------------------------------------------------------------
2704 
CreateDialogWithHandler()2705 void ExtensionsTabPage::CreateDialogWithHandler()
2706 {
2707     try
2708     {
2709         bool bWithHandler = ( m_sEventHdl.getLength() > 0 );
2710         if ( bWithHandler )
2711         {
2712             Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
2713             m_xEventHdl = Reference< awt::XContainerWindowEventHandler >(
2714                 xFactory->createInstance( m_sEventHdl ), UNO_QUERY );
2715         }
2716 
2717         if ( !bWithHandler || m_xEventHdl.is() )
2718         {
2719             SetStyle( GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
2720             Reference< awt::XWindowPeer > xParent( VCLUnoHelper::GetInterface( this ), UNO_QUERY );
2721             m_xPage = Reference < awt::XWindow >(
2722                 m_xWinProvider->createContainerWindow(
2723                     m_sPageURL, rtl::OUString(), xParent, m_xEventHdl ), UNO_QUERY );
2724 
2725             Reference< awt::XControl > xPageControl( m_xPage, UNO_QUERY );
2726             if ( xPageControl.is() )
2727             {
2728                 Reference< awt::XWindowPeer > xWinPeer( xPageControl->getPeer() );
2729                 if ( xWinPeer.is() )
2730                 {
2731                     Window* pWindow = VCLUnoHelper::GetWindow( xWinPeer );
2732                     if ( pWindow )
2733                         pWindow->SetStyle( pWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
2734                 }
2735             }
2736         }
2737     }
2738     catch ( ::com::sun::star::lang::IllegalArgumentException& )
2739     {
2740         DBG_ERRORFILE( "ExtensionsTabPage::CreateDialogWithHandler(): illegal argument" );
2741     }
2742     catch ( Exception& )
2743     {
2744         DBG_ERRORFILE( "ExtensionsTabPage::CreateDialogWithHandler(): exception of XDialogProvider2::createDialogWithHandler()" );
2745     }
2746 }
2747 
2748 // -----------------------------------------------------------------------
2749 
DispatchAction(const rtl::OUString & rAction)2750 sal_Bool ExtensionsTabPage::DispatchAction( const rtl::OUString& rAction )
2751 {
2752     sal_Bool bRet = sal_False;
2753     if ( m_xEventHdl.is() )
2754     {
2755         try
2756         {
2757             bRet = m_xEventHdl->callHandlerMethod( m_xPage, makeAny( rAction ), C2U("external_event") );
2758         }
2759         catch ( Exception& )
2760         {
2761             DBG_ERRORFILE( "ExtensionsTabPage::DispatchAction(): exception of XDialogEventHandler::callHandlerMethod()" );
2762         }
2763     }
2764     return bRet;
2765 }
2766 
2767 // -----------------------------------------------------------------------
2768 
ActivatePage()2769 void ExtensionsTabPage::ActivatePage()
2770 {
2771     TabPage::ActivatePage();
2772 
2773     if ( !m_xPage.is() )
2774     {
2775         CreateDialogWithHandler();
2776 
2777         if ( m_xPage.is() )
2778         {
2779             Point aPos = Point();
2780             Size aSize = GetSizePixel();
2781             m_xPage->setPosSize( aPos.X() + 1, aPos.Y() + 1,
2782                                  aSize.Width() - 2, aSize.Height() - 2, awt::PosSize::POSSIZE );
2783             if ( m_sEventHdl.getLength() > 0 )
2784                 DispatchAction( C2U("initialize") );
2785         }
2786     }
2787 
2788     if ( m_xPage.is() )
2789     {
2790         m_xPage->setVisible( sal_True );
2791         m_bIsWindowHidden = false;
2792     }
2793 }
2794 
2795 // -----------------------------------------------------------------------
2796 
DeactivatePage()2797 void ExtensionsTabPage::DeactivatePage()
2798 {
2799     TabPage::DeactivatePage();
2800 
2801     if ( m_xPage.is() )
2802         m_xPage->setVisible( sal_False );
2803 }
2804 
2805 // -----------------------------------------------------------------------
2806 
ResetPage()2807 void ExtensionsTabPage::ResetPage()
2808 {
2809     DispatchAction( C2U("back") );
2810     ActivatePage();
2811 }
2812 
2813 // -----------------------------------------------------------------------
2814 
SavePage()2815 void ExtensionsTabPage::SavePage()
2816 {
2817     DispatchAction( C2U("ok") );
2818 }
2819