Bump version to 4.3-4
[LibreOffice.git] / cui / source / options / treeopt.cxx
blob69f68513a91031a71dc6842c32f3300d5c4b5e10
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "cuires.hrc"
21 #include "helpid.hrc"
22 #include "treeopt.hrc"
24 #include <svx/dialogs.hrc>
26 #include "cfgchart.hxx"
27 #include "connpoolconfig.hxx"
28 #include "connpooloptions.hxx"
29 #include "cuioptgenrl.hxx"
30 #include "cuitabarea.hxx"
31 #include "dbregister.hxx"
32 #include "dbregisterednamesconfig.hxx"
33 #include "dialmgr.hxx"
34 #include "fontsubs.hxx"
35 #include "optaboutconfig.hxx"
36 #include "optaccessibility.hxx"
37 #include "optasian.hxx"
38 #include "optchart.hxx"
39 #include "optcolor.hxx"
40 #include "optctl.hxx"
41 #include "optfltr.hxx"
42 #include "optgdlg.hxx"
43 #include "opthtml.hxx"
44 #include "optinet2.hxx"
45 #include "optjava.hxx"
46 #include "optjsearch.hxx"
47 #include "optlingu.hxx"
48 #include "optmemory.hxx"
49 #include "optpath.hxx"
50 #include "optsave.hxx"
51 #include "optupdt.hxx"
52 #include "personalization.hxx"
53 #include "treeopt.hxx"
54 #include "optbasic.hxx"
56 #include <com/sun/star/awt/XContainerWindowEventHandler.hpp>
57 #include <com/sun/star/awt/ContainerWindowProvider.hpp>
58 #include <com/sun/star/awt/XControl.hpp>
59 #include <com/sun/star/awt/PosSize.hpp>
60 #include <com/sun/star/frame/Desktop.hpp>
61 #include <com/sun/star/frame/ModuleManager.hpp>
62 #include <com/sun/star/loader/CannotActivateFactoryException.hpp>
63 #include <com/sun/star/linguistic2/LinguProperties.hpp>
64 #include <com/sun/star/util/theMacroExpander.hpp>
65 #include <com/sun/star/setup/UpdateCheck.hpp>
66 #include <comphelper/processfactory.hxx>
67 #include <editeng/langitem.hxx>
68 #include <editeng/optitems.hxx>
69 #include <editeng/unolingu.hxx>
70 #include <linguistic/misc.hxx>
71 #include <officecfg/Office/OptionsDialog.hxx>
72 #include <osl/module.hxx>
73 #include <osl/process.h>
74 #include <rtl/bootstrap.hxx>
75 #include <rtl/uri.hxx>
76 #include <sfx2/app.hxx>
77 #include <sfx2/dispatch.hxx>
78 #include <sfx2/module.hxx>
79 #include <sfx2/printopt.hxx>
80 #include <sfx2/shell.hxx>
81 #include <sfx2/tplpitem.hxx>
82 #include <sfx2/viewsh.hxx>
83 #include <svl/languageoptions.hxx>
84 #include <svtools/helpopt.hxx>
85 #include <svx/drawitem.hxx>
86 #include <svx/xtable.hxx>
87 #include <svx/xpool.hxx>
88 #include <toolkit/helper/vclunohelper.hxx>
89 #include <tools/shl.hxx>
90 #include <tools/urlobj.hxx>
91 #include <unotools/linguprops.hxx>
92 #include <unotools/misccfg.hxx>
93 #include <unotools/moduleoptions.hxx>
94 #include <unotools/optionsdlg.hxx>
95 #include <unotools/viewoptions.hxx>
96 #include <vcl/help.hxx>
97 #include <vcl/layout.hxx>
98 #include <vcl/msgbox.hxx>
99 #include <vcl/waitobj.hxx>
100 #include <vcl/settings.hxx>
101 #include "svtools/treelistentry.hxx"
103 #ifdef LINUX
104 #include <sys/stat.h>
105 #endif
107 #include <boost/scoped_ptr.hpp>
109 using namespace ::com::sun::star;
110 using namespace ::com::sun::star::beans;
111 using namespace ::com::sun::star::container;
112 using namespace ::com::sun::star::frame;
113 using namespace ::com::sun::star::lang;
114 using namespace ::com::sun::star::linguistic2;
115 using namespace ::com::sun::star::uno;
116 using namespace ::com::sun::star::util;
118 #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
120 LastPageSaver* OfaTreeOptionsDialog::pLastPageSaver = NULL;
122 // some stuff for easier changes for SvtViewOptions
123 static const sal_Char* pViewOptDataName = "page data";
124 #define VIEWOPT_DATANAME OUString::createFromAscii( pViewOptDataName )
126 static XOutdevItemPool* mpStaticXOutdevItemPool = 0L;
128 static inline void SetViewOptUserItem( SvtViewOptions& rOpt, const OUString& rData )
130 rOpt.SetUserItem( VIEWOPT_DATANAME, makeAny( OUString( rData ) ) );
133 static inline OUString GetViewOptUserItem( const SvtViewOptions& rOpt )
135 Any aAny( rOpt.GetUserItem( VIEWOPT_DATANAME ) );
136 OUString aUserData;
137 aAny >>= aUserData;
139 return aUserData;
142 struct ModuleToGroupNameMap_Impl
144 const char* m_pModule;
145 OUString m_sGroupName;
146 sal_uInt16 m_nNodeId;
149 static OfaPageResource* pPageRes = NULL;
151 static ModuleToGroupNameMap_Impl ModuleMap[] =
153 { "ProductName", OUString(), SID_GENERAL_OPTIONS },
154 { "LanguageSettings", OUString(), SID_LANGUAGE_OPTIONS },
155 { "Internet", OUString(), SID_INET_DLG },
156 { "LoadSave", OUString(), SID_FILTER_DLG },
157 { "Writer", OUString(), SID_SW_EDITOPTIONS },
158 { "WriterWeb", OUString(), SID_SW_ONLINEOPTIONS },
159 { "Math", OUString(), SID_SM_EDITOPTIONS },
160 { "Calc", OUString(), SID_SC_EDITOPTIONS },
161 { "Impress", OUString(), SID_SD_EDITOPTIONS },
162 { "Draw", OUString(), SID_SD_GRAPHIC_OPTIONS },
163 { "Charts", OUString(), SID_SCH_EDITOPTIONS },
164 { "Base", OUString(), SID_SB_STARBASEOPTIONS },
166 { NULL, OUString(), 0xFFFF }
169 static void setGroupName( const OUString& rModule, const OUString& rGroupName )
171 sal_uInt16 nIndex = 0;
172 while ( ModuleMap[ nIndex ].m_pModule )
174 OUString sTemp =
175 OUString::createFromAscii( ModuleMap[ nIndex ].m_pModule );
176 if ( sTemp == rModule )
178 ModuleMap[ nIndex ].m_sGroupName = rGroupName;
179 break;
181 ++nIndex;
185 static OUString getGroupName( const OUString& rModule, bool bForced )
187 OUString sGroupName;
188 sal_uInt16 nIndex = 0;
189 while ( ModuleMap[ nIndex ].m_pModule )
191 OUString sTemp =
192 OUString::createFromAscii( ModuleMap[ nIndex ].m_pModule );
193 if ( sTemp == rModule )
195 sGroupName = ModuleMap[ nIndex ].m_sGroupName;
196 break;
198 ++nIndex;
201 if ( sGroupName.isEmpty() && bForced )
203 if ( !pPageRes )
204 pPageRes = new OfaPageResource;
206 if ( rModule == "Writer" )
207 sGroupName = pPageRes->GetTextArray().GetString(0);
208 else if ( rModule == "WriterWeb" )
209 sGroupName = pPageRes->GetHTMLArray().GetString(0);
210 else if ( rModule == "Calc" )
211 sGroupName = pPageRes->GetCalcArray().GetString(0);
212 else if ( rModule == "Impress" )
213 sGroupName = pPageRes->GetImpressArray().GetString(0);
214 else if ( rModule == "Draw" )
215 sGroupName = pPageRes->GetDrawArray().GetString(0);
216 else if ( rModule == "Math" )
217 sGroupName = pPageRes->GetStarMathArray().GetString(0);
218 else if ( rModule == "Base" )
219 sGroupName = pPageRes->GetDatasourcesArray().GetString(0);
221 return sGroupName;
224 static void deleteGroupNames()
226 sal_uInt16 nIndex = 0;
227 while ( ModuleMap[ nIndex ].m_pModule )
228 ModuleMap[ nIndex++ ].m_sGroupName = OUString();
231 static sal_uInt16 getGroupNodeId( const OUString& rModule )
233 sal_uInt16 nNodeId = 0xFFFF, nIndex = 0;
234 while ( ModuleMap[ nIndex ].m_pModule )
236 OUString sTemp =
237 OUString::createFromAscii( ModuleMap[ nIndex ].m_pModule );
238 if ( sTemp == rModule )
240 nNodeId = ModuleMap[ nIndex ].m_nNodeId;
241 break;
243 ++nIndex;
246 return nNodeId;
249 class MailMergeCfg_Impl : public utl::ConfigItem
251 friend class SvxEMailTabPage;
252 // variables
253 bool bIsEmailSupported;
255 public:
256 MailMergeCfg_Impl();
257 virtual ~MailMergeCfg_Impl();
259 virtual void Commit() SAL_OVERRIDE;
260 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& _rPropertyNames) SAL_OVERRIDE;
262 bool IsEmailSupported() const {return bIsEmailSupported;}
266 MailMergeCfg_Impl::MailMergeCfg_Impl() :
267 utl::ConfigItem("Office.Writer/MailMergeWizard"),
268 bIsEmailSupported(false)
270 Sequence<OUString> aNames(1);
271 aNames.getArray()[0] = "EMailSupported";
272 const Sequence< Any > aValues = GetProperties(aNames);
273 const Any* pValues = aValues.getConstArray();
274 if(aValues.getLength() && pValues[0].hasValue())
275 pValues[0] >>= bIsEmailSupported;
278 MailMergeCfg_Impl::~MailMergeCfg_Impl()
281 /* -------------------------------------------------------------------------*/
282 void MailMergeCfg_Impl::Commit()
286 void MailMergeCfg_Impl::Notify( const com::sun::star::uno::Sequence< OUString >& )
290 //typedef SfxTabPage* (*FNCreateTabPage)( Window *pParent, const SfxItemSet &rAttrSet );
291 SfxTabPage* CreateGeneralTabPage( sal_uInt16 nId, Window* pParent, const SfxItemSet& rSet )
293 CreateTabPage fnCreate = 0;
294 switch(nId)
296 case RID_SFXPAGE_SAVE: fnCreate = &SvxSaveTabPage::Create; break;
297 case RID_SFXPAGE_PATH: fnCreate = &SvxPathTabPage::Create; break;
298 case RID_SFXPAGE_GENERAL: fnCreate = &SvxGeneralTabPage::Create; break;
299 case RID_SFXPAGE_PRINTOPTIONS: fnCreate = &SfxCommonPrintOptionsTabPage::Create; break;
300 case OFA_TP_LANGUAGES: fnCreate = &OfaLanguagesTabPage::Create; break;
301 case RID_SFXPAGE_LINGU: fnCreate = &SvxLinguTabPage::Create; break;
302 case RID_SVXPAGE_COLOR: fnCreate = &SvxColorTabPage::Create; break;
303 case OFA_TP_VIEW: fnCreate = &OfaViewTabPage::Create; break;
304 case OFA_TP_MISC: fnCreate = &OfaMiscTabPage::Create; break;
305 case OFA_TP_MEMORY: fnCreate = &OfaMemoryOptionsPage::Create; break;
306 case RID_SVXPAGE_ASIAN_LAYOUT: fnCreate = &SvxAsianLayoutPage::Create; break;
307 case RID_SVX_FONT_SUBSTITUTION: fnCreate = &SvxFontSubstTabPage::Create; break;
308 case RID_SVXPAGE_INET_PROXY: fnCreate = &SvxProxyTabPage::Create; break;
309 case RID_SVXPAGE_INET_SECURITY: fnCreate = &SvxSecurityTabPage::Create; break;
310 case RID_SVXPAGE_INET_MAIL: fnCreate = &SvxEMailTabPage::Create; break;
311 case RID_SVXPAGE_PERSONALIZATION: fnCreate = &SvxPersonalizationTabPage::Create; break;
312 case RID_SVXPAGE_COLORCONFIG: fnCreate = &SvxColorOptionsTabPage::Create; break;
313 case RID_OFAPAGE_HTMLOPT: fnCreate = &OfaHtmlTabPage::Create; break;
314 case SID_OPTFILTER_MSOFFICE: fnCreate = &OfaMSFilterTabPage::Create; break;
315 case RID_OFAPAGE_MSFILTEROPT2: fnCreate = &OfaMSFilterTabPage2::Create; break;
316 case RID_SVXPAGE_JSEARCH_OPTIONS: fnCreate = &SvxJSearchOptionsPage::Create ; break;
317 case SID_SB_CONNECTIONPOOLING: fnCreate = &::offapp::ConnectionPoolOptionsPage::Create; break;
318 case SID_SB_DBREGISTEROPTIONS: fnCreate = &::svx::DbRegistrationOptionsPage::Create; break;
319 case RID_SVXPAGE_ACCESSIBILITYCONFIG: fnCreate = &SvxAccessibilityOptionsTabPage::Create; break;
320 case RID_SVXPAGE_OPTIONS_CTL: fnCreate = &SvxCTLOptionsPage::Create ; break;
321 case RID_SVXPAGE_INET_MOZPLUGIN: fnCreate = &MozPluginTabPage::Create; break;
322 case RID_SVXPAGE_OPTIONS_JAVA: fnCreate = &SvxJavaOptionsPage::Create ; break;
323 case RID_SVXPAGE_ONLINEUPDATE: fnCreate = &SvxOnlineUpdateTabPage::Create; break;
324 case RID_OPTPAGE_CHART_DEFCOLORS: fnCreate = &SvxDefaultColorOptPage::Create; break;
325 #ifndef DISABLE_SCRIPTING
326 case RID_SVXPAGE_BASICIDE_OPTIONS: fnCreate = &SvxBasicIDEOptionsPage::Create; break;
327 #endif
330 SfxTabPage* pRet = fnCreate ? (*fnCreate)( pParent, rSet ) : NULL;
331 return pRet;
334 struct OptionsMapping_Impl
336 const char* m_pGroupName;
337 const char* m_pPageName;
338 sal_uInt16 m_nPageId;
341 static OptionsMapping_Impl const OptionsMap_Impl[] =
343 // GROUP PAGE PAGE-ID
344 { "ProductName", NULL, SID_GENERAL_OPTIONS },
345 { "ProductName", "UserData", RID_SFXPAGE_GENERAL },
346 { "ProductName", "General", OFA_TP_MISC },
347 { "ProductName", "Memory", OFA_TP_MEMORY },
348 { "ProductName", "View", OFA_TP_VIEW },
349 { "ProductName", "Print", RID_SFXPAGE_PRINTOPTIONS },
350 { "ProductName", "Paths", RID_SFXPAGE_PATH },
351 { "ProductName", "Colors", RID_SVXPAGE_COLOR },
352 { "ProductName", "Fonts", RID_SVX_FONT_SUBSTITUTION },
353 { "ProductName", "Security", RID_SVXPAGE_INET_SECURITY },
354 { "ProductName", "Personalization", RID_SVXPAGE_PERSONALIZATION },
355 { "ProductName", "Appearance", RID_SVXPAGE_COLORCONFIG },
356 { "ProductName", "Accessibility", RID_SVXPAGE_ACCESSIBILITYCONFIG },
357 { "ProductName", "Java", RID_SVXPAGE_OPTIONS_JAVA },
358 { "ProductName", "BasicIDEOptions", RID_SVXPAGE_BASICIDE_OPTIONS },
359 { "ProductName", "OnlineUpdate", RID_SVXPAGE_ONLINEUPDATE },
360 { "LanguageSettings", NULL, SID_LANGUAGE_OPTIONS },
361 { "LanguageSettings", "Languages", OFA_TP_LANGUAGES },
362 { "LanguageSettings", "WritingAids", RID_SFXPAGE_LINGU },
363 { "LanguageSettings", "SearchingInJapanese", RID_SVXPAGE_JSEARCH_OPTIONS },
364 { "LanguageSettings", "AsianLayout", RID_SVXPAGE_ASIAN_LAYOUT },
365 { "LanguageSettings", "ComplexTextLayout", RID_SVXPAGE_OPTIONS_CTL },
366 { "Internet", NULL, SID_INET_DLG },
367 { "Internet", "Proxy", RID_SVXPAGE_INET_PROXY },
368 { "Internet", "Email", RID_SVXPAGE_INET_MAIL },
369 { "Internet", "MozillaPlugin", RID_SVXPAGE_INET_MOZPLUGIN },
370 { "LoadSave", NULL, SID_FILTER_DLG },
371 { "LoadSave", "General", RID_SFXPAGE_SAVE },
372 { "LoadSave", "VBAProperties", SID_OPTFILTER_MSOFFICE },
373 { "LoadSave", "MicrosoftOffice", RID_OFAPAGE_MSFILTEROPT2 },
374 { "LoadSave", "HTMLCompatibility", RID_OFAPAGE_HTMLOPT },
375 { "Writer", NULL, SID_SW_EDITOPTIONS },
376 { "Writer", "General", RID_SW_TP_OPTLOAD_PAGE },
377 { "Writer", "View", RID_SW_TP_CONTENT_OPT },
378 { "Writer", "FormattingAids", RID_SW_TP_OPTSHDWCRSR },
379 { "Writer", "Grid", RID_SVXPAGE_GRID },
380 { "Writer", "BasicFontsWestern", RID_SW_TP_STD_FONT },
381 { "Writer", "BasicFontsAsian", RID_SW_TP_STD_FONT_CJK },
382 { "Writer", "BasicFontsCTL", RID_SW_TP_STD_FONT_CTL },
383 { "Writer", "Print", RID_SW_TP_OPTPRINT_PAGE },
384 { "Writer", "Table", RID_SW_TP_OPTTABLE_PAGE },
385 { "Writer", "Changes", RID_SW_TP_REDLINE_OPT },
386 { "Writer", "Comparison", RID_SW_TP_COMPARISON_OPT },
387 { "Writer", "Compatibility", RID_SW_TP_OPTCOMPATIBILITY_PAGE },
388 { "Writer", "AutoCaption", RID_SW_TP_OPTCAPTION_PAGE },
389 { "Writer", "MailMerge", RID_SW_TP_MAILCONFIG },
390 { "WriterWeb", NULL, SID_SW_ONLINEOPTIONS },
391 { "WriterWeb", "View", RID_SW_TP_HTML_CONTENT_OPT },
392 { "WriterWeb", "FormattingAids", RID_SW_TP_HTML_OPTSHDWCRSR },
393 { "WriterWeb", "Grid", RID_SW_TP_HTML_OPTGRID_PAGE },
394 { "WriterWeb", "Print", RID_SW_TP_HTML_OPTPRINT_PAGE },
395 { "WriterWeb", "Table", RID_SW_TP_HTML_OPTTABLE_PAGE },
396 { "WriterWeb", "Background", RID_SW_TP_BACKGROUND },
397 { "Math", NULL, SID_SM_EDITOPTIONS },
398 { "Math", "Settings", SID_SM_TP_PRINTOPTIONS },
399 { "Calc", NULL, SID_SC_EDITOPTIONS },
400 { "Calc", "General", SID_SC_TP_LAYOUT },
401 { "Calc", "View", SID_SC_TP_CONTENT },
402 { "Calc", "Calculate", SID_SC_TP_CALC },
403 { "Calc", "Formula", SID_SC_TP_FORMULA },
404 { "Calc", "SortLists", SID_SC_TP_USERLISTS },
405 { "Calc", "Changes", SID_SC_TP_CHANGES },
406 { "Calc", "Compatibility", SID_SC_TP_COMPATIBILITY },
407 { "Calc", "Grid", SID_SC_TP_GRID },
408 { "Calc", "Print", RID_SC_TP_PRINT },
409 { "Impress", NULL, SID_SD_EDITOPTIONS },
410 { "Impress", "General", SID_SI_TP_MISC },
411 { "Impress", "View", SID_SI_TP_CONTENTS },
412 { "Impress", "Grid", SID_SI_TP_SNAP },
413 { "Impress", "Print", SID_SI_TP_PRINT },
414 { "Draw", NULL, SID_SD_GRAPHIC_OPTIONS },
415 { "Draw", "General", SID_SD_TP_MISC },
416 { "Draw", "View", SID_SD_TP_CONTENTS },
417 { "Draw", "Grid", SID_SD_TP_SNAP },
418 { "Draw", "Print", SID_SD_TP_PRINT },
419 { "Charts", NULL, SID_SCH_EDITOPTIONS },
420 { "Charts", "DefaultColors", RID_OPTPAGE_CHART_DEFCOLORS },
421 { "Base", NULL, SID_SB_STARBASEOPTIONS },
422 { "Base", "Connections", SID_SB_CONNECTIONPOOLING },
423 { "Base", "Databases", SID_SB_DBREGISTEROPTIONS },
424 { NULL, NULL, 0 }
427 static bool lcl_getStringFromID( sal_uInt16 _nPageId, OUString& _rGroupName, OUString& _rPageName )
429 bool bRet = false;
431 sal_uInt16 nIdx = 0;
432 while ( OptionsMap_Impl[nIdx].m_pGroupName != NULL )
434 if ( _nPageId == OptionsMap_Impl[nIdx].m_nPageId )
436 bRet = true;
437 _rGroupName = OUString::createFromAscii( OptionsMap_Impl[nIdx].m_pGroupName );
438 if ( OptionsMap_Impl[nIdx].m_pPageName != NULL )
439 _rPageName = OUString::createFromAscii( OptionsMap_Impl[nIdx].m_pPageName );
440 break;
442 ++nIdx;
445 return bRet;
448 static bool lcl_isOptionHidden( sal_uInt16 _nPageId, const SvtOptionsDialogOptions& _rOptOptions )
450 bool bIsHidden = false;
451 OUString sGroupName, sPageName;
452 if ( lcl_getStringFromID( _nPageId, sGroupName, sPageName ) )
454 if ( sPageName.isEmpty() )
455 bIsHidden = _rOptOptions.IsGroupHidden( sGroupName );
456 else
457 bIsHidden = _rOptOptions.IsPageHidden( sPageName, sGroupName );
459 return bIsHidden;
462 struct OptionsPageInfo
464 SfxTabPage* m_pPage;
465 sal_uInt16 m_nPageId;
466 OUString m_sPageURL;
467 OUString m_sEventHdl;
468 ExtensionsTabPage* m_pExtPage;
470 OptionsPageInfo( sal_uInt16 nId ) : m_pPage( NULL ), m_nPageId( nId ), m_pExtPage( NULL ) {}
473 struct OptionsGroupInfo
475 SfxItemSet* m_pInItemSet;
476 SfxItemSet* m_pOutItemSet;
477 SfxShell* m_pShell; // used to create the page
478 SfxModule* m_pModule; // used to create the ItemSet
479 sal_uInt16 m_nDialogId; // Id of the former dialog
480 bool m_bLoadError; // load fails?
481 OUString m_sPageURL;
482 ExtensionsTabPage* m_pExtPage;
484 OptionsGroupInfo( SfxShell* pSh, SfxModule* pMod, sal_uInt16 nId ) :
485 m_pInItemSet( NULL ), m_pOutItemSet( NULL ), m_pShell( pSh ),
486 m_pModule( pMod ), m_nDialogId( nId ), m_bLoadError( false ),
487 m_sPageURL( OUString() ), m_pExtPage( NULL ) {}
488 ~OptionsGroupInfo() { delete m_pInItemSet; delete m_pOutItemSet; }
493 #define INI_LIST() \
494 pCurrentPageEntry ( NULL ),\
495 aOkPB ( this, CUI_RES( PB_OK ) ),\
496 aCancelPB ( this, CUI_RES( PB_CANCEL ) ),\
497 aHelpPB ( this, CUI_RES( PB_HELP ) ),\
498 aBackPB ( this, CUI_RES( PB_BACK ) ),\
499 aSeparatorFL ( this, CUI_RES( FL_SEPARATOR ) ),\
500 aTreeLB ( this, CUI_RES( TLB_PAGES ) ),\
501 sTitle ( GetText() ),\
502 sNotLoadedError ( CUI_RES( ST_LOAD_ERROR ) ),\
503 pColorPageItemSet ( NULL ),\
504 mpColorPage ( NULL ),\
505 bForgetSelection ( false ),\
506 bIsFromExtensionManager( false ), \
507 bIsForSetDocumentLanguage( false )
509 // Ctor() with Frame -----------------------------------------------------
510 using namespace ::com::sun::star;
511 OfaTreeOptionsDialog::OfaTreeOptionsDialog(
512 Window* pParent,
513 const Reference< XFrame >& _xFrame,
514 bool bActivateLastSelection ) :
516 SfxModalDialog( pParent, CUI_RES( RID_OFADLG_OPTIONS_TREE ) ),
517 INI_LIST()
519 FreeResource();
521 InitTreeAndHandler();
522 Initialize( _xFrame );
523 LoadExtensionOptions( OUString() );
524 ResizeTreeLB();
525 if (bActivateLastSelection)
526 ActivateLastSelection();
528 aTreeLB.SetAccessibleName(GetDisplayText());
531 // Ctor() with ExtensionId -----------------------------------------------
533 OfaTreeOptionsDialog::OfaTreeOptionsDialog( Window* pParent, const OUString& rExtensionId ) :
535 SfxModalDialog( pParent, CUI_RES( RID_OFADLG_OPTIONS_TREE ) ),
536 INI_LIST()
538 FreeResource();
540 bIsFromExtensionManager = ( !rExtensionId.isEmpty() );
541 InitTreeAndHandler();
542 LoadExtensionOptions( rExtensionId );
543 ResizeTreeLB();
544 ActivateLastSelection();
547 OfaTreeOptionsDialog::~OfaTreeOptionsDialog()
549 maTreeLayoutTimer.Stop();
550 pCurrentPageEntry = NULL;
551 SvTreeListEntry* pEntry = aTreeLB.First();
552 // first children
553 while(pEntry)
555 // if Child (has parent), then OptionsPageInfo
556 if(aTreeLB.GetParent(pEntry))
558 OptionsPageInfo *pPageInfo = (OptionsPageInfo *)pEntry->GetUserData();
559 if(pPageInfo->m_pPage)
561 pPageInfo->m_pPage->FillUserData();
562 OUString aPageData(pPageInfo->m_pPage->GetUserData());
563 if ( !aPageData.isEmpty() )
565 SvtViewOptions aTabPageOpt( E_TABPAGE, OUString::number( pPageInfo->m_nPageId) );
566 SetViewOptUserItem( aTabPageOpt, aPageData );
568 delete pPageInfo->m_pPage;
571 if (pPageInfo->m_nPageId == RID_SFXPAGE_LINGU)
573 // write personal dictionaries
574 Reference< XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
575 if (xDicList.is())
577 linguistic::SaveDictionaries( xDicList );
581 if( pPageInfo->m_pExtPage )
582 delete pPageInfo->m_pExtPage;
584 delete pPageInfo;
586 pEntry = aTreeLB.Next(pEntry);
589 // and parents
590 pEntry = aTreeLB.First();
591 while(pEntry)
593 if(!aTreeLB.GetParent(pEntry))
595 OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo*)pEntry->GetUserData();
596 if ( pGroupInfo && pGroupInfo->m_pExtPage )
597 delete pGroupInfo->m_pExtPage;
598 delete pGroupInfo;
600 pEntry = aTreeLB.Next(pEntry);
602 delete pColorPageItemSet;
603 deleteGroupNames();
606 OptionsPageInfo* OfaTreeOptionsDialog::AddTabPage(
607 sal_uInt16 nId, const OUString& rPageName, sal_uInt16 nGroup )
609 OptionsPageInfo* pPageInfo = new OptionsPageInfo( nId );
610 SvTreeListEntry* pParent = aTreeLB.GetEntry( 0, nGroup );
611 DBG_ASSERT( pParent, "OfaTreeOptionsDialog::AddTabPage(): no group found" );
612 SvTreeListEntry* pEntry = aTreeLB.InsertEntry( rPageName, pParent );
613 pEntry->SetUserData( pPageInfo );
614 return pPageInfo;
617 // the ItemSet* is passed on to the dialog's ownership
618 sal_uInt16 OfaTreeOptionsDialog::AddGroup(const OUString& rGroupName,
619 SfxShell* pCreateShell,
620 SfxModule* pCreateModule,
621 sal_uInt16 nDialogId )
623 SvTreeListEntry* pEntry = aTreeLB.InsertEntry(rGroupName);
624 OptionsGroupInfo* pInfo =
625 new OptionsGroupInfo( pCreateShell, pCreateModule, nDialogId );
626 pEntry->SetUserData(pInfo);
627 sal_uInt16 nRet = 0;
628 pEntry = aTreeLB.First();
629 while(pEntry)
631 if(!aTreeLB.GetParent(pEntry))
632 nRet++;
633 pEntry = aTreeLB.Next(pEntry);
635 return nRet - 1;
638 IMPL_LINK_NOARG(OfaTreeOptionsDialog, ShowPageHdl_Impl)
640 SelectHdl_Impl();
641 return 0;
644 IMPL_LINK_NOARG(OfaTreeOptionsDialog, BackHdl_Impl)
646 if ( pCurrentPageEntry && aTreeLB.GetParent( pCurrentPageEntry ) )
648 OptionsPageInfo* pPageInfo = (OptionsPageInfo*)pCurrentPageEntry->GetUserData();
649 if ( pPageInfo->m_pPage )
651 OptionsGroupInfo* pGroupInfo =
652 (OptionsGroupInfo*)aTreeLB.GetParent( pCurrentPageEntry )->GetUserData();
653 if ( RID_SVXPAGE_COLOR == pPageInfo->m_nPageId )
654 pPageInfo->m_pPage->Reset( *pColorPageItemSet );
655 else
656 pPageInfo->m_pPage->Reset( *pGroupInfo->m_pInItemSet );
658 else if ( pPageInfo->m_pExtPage )
659 pPageInfo->m_pExtPage->ResetPage();
661 return 0;
664 IMPL_LINK_NOARG(OfaTreeOptionsDialog, OKHdl_Impl)
666 aTreeLB.EndSelection();
667 if ( pCurrentPageEntry && aTreeLB.GetParent( pCurrentPageEntry ) )
669 OptionsPageInfo* pPageInfo = (OptionsPageInfo *)pCurrentPageEntry->GetUserData();
670 if ( pPageInfo->m_pPage )
672 OptionsGroupInfo* pGroupInfo =
673 (OptionsGroupInfo *)aTreeLB.GetParent(pCurrentPageEntry)->GetUserData();
674 if ( RID_SVXPAGE_COLOR != pPageInfo->m_nPageId
675 && pPageInfo->m_pPage->HasExchangeSupport() )
677 int nLeave = pPageInfo->m_pPage->DeactivatePage(pGroupInfo->m_pOutItemSet);
678 if ( nLeave == SfxTabPage::KEEP_PAGE )
680 // the page mustn't be left
681 aTreeLB.Select(pCurrentPageEntry);
682 return 0;
685 pPageInfo->m_pPage->Hide();
689 SvTreeListEntry* pEntry = aTreeLB.First();
690 while ( pEntry )
692 if ( aTreeLB.GetParent( pEntry ) )
694 OptionsPageInfo* pPageInfo = (OptionsPageInfo *)pEntry->GetUserData();
695 if ( pPageInfo->m_pPage && !pPageInfo->m_pPage->HasExchangeSupport() )
697 OptionsGroupInfo* pGroupInfo =
698 (OptionsGroupInfo*)aTreeLB.GetParent(pEntry)->GetUserData();
699 pPageInfo->m_pPage->FillItemSet(*pGroupInfo->m_pOutItemSet);
702 if ( pPageInfo->m_pExtPage )
704 pPageInfo->m_pExtPage->DeactivatePage();
705 pPageInfo->m_pExtPage->SavePage();
708 pEntry = aTreeLB.Next(pEntry);
710 EndDialog(RET_OK);
711 return 0;
714 // an opened group shall be completely visible
715 IMPL_LINK(OfaTreeOptionsDialog, ExpandedHdl_Impl, SvTreeListBox*, pBox )
717 pBox->Update();
718 pBox->InitStartEntry();
719 SvTreeListEntry* pEntry = pBox->GetHdlEntry();
720 if(pEntry && pBox->IsExpanded(pEntry))
722 sal_uInt32 nChildCount = pBox->GetChildCount( pEntry );
724 SvTreeListEntry* pNext = pEntry;
725 for(sal_uInt32 i = 0; i < nChildCount;i++)
727 pNext = pBox->GetNextEntryInView(pNext);
728 if(!pNext)
730 pBox->ScrollOutputArea( -(short)(nChildCount - i + 1) );
731 break;
733 else
735 Size aSz(pBox->GetOutputSizePixel());
736 int nHeight = pBox->GetEntryHeight();
737 Point aPos(pBox->GetEntryPosition(pNext));
738 if(aPos.Y()+nHeight > aSz.Height())
740 pBox->ScrollOutputArea( -(short)(nChildCount - i + 1) );
741 break;
746 return 0;
749 void OfaTreeOptionsDialog::ApplyItemSets()
751 SvTreeListEntry* pEntry = aTreeLB.First();
752 while(pEntry)
754 if(!aTreeLB.GetParent(pEntry))
756 OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo *)pEntry->GetUserData();
757 if(pGroupInfo->m_pOutItemSet)
759 if(pGroupInfo->m_pShell)
760 pGroupInfo->m_pShell->ApplyItemSet( pGroupInfo->m_nDialogId, *pGroupInfo->m_pOutItemSet);
761 else
762 ApplyItemSet( pGroupInfo->m_nDialogId, *pGroupInfo->m_pOutItemSet);
765 pEntry = aTreeLB.Next(pEntry);
769 void OfaTreeOptionsDialog::InitTreeAndHandler()
771 maTreeLayoutTimer.SetTimeout(50);
772 maTreeLayoutTimer.SetTimeoutHdl( LINK( this, OfaTreeOptionsDialog, ImplHandleTreeLayoutTimerHdl ) );
774 aTreeLB.SetNodeDefaultImages();
776 aTreeLB.SetHelpId( HID_OFADLG_TREELISTBOX );
777 aTreeLB.SetStyle( aTreeLB.GetStyle()|WB_HASBUTTONS | WB_HASBUTTONSATROOT |
778 WB_HASLINES | WB_HASLINESATROOT |
779 WB_CLIPCHILDREN | WB_HSCROLL | WB_FORCE_MAKEVISIBLE | WB_QUICK_SEARCH );
780 aTreeLB.SetSpaceBetweenEntries( 0 );
781 aTreeLB.SetSelectionMode( SINGLE_SELECTION );
782 aTreeLB.SetSublistOpenWithLeftRight( true );
783 aTreeLB.SetExpandedHdl( LINK( this, OfaTreeOptionsDialog, ExpandedHdl_Impl ) );
784 aTreeLB.SetSelectHdl( LINK( this, OfaTreeOptionsDialog, ShowPageHdl_Impl ) );
785 aBackPB.SetClickHdl( LINK( this, OfaTreeOptionsDialog, BackHdl_Impl ) );
786 aOkPB.SetClickHdl( LINK( this, OfaTreeOptionsDialog, OKHdl_Impl ) );
789 void OfaTreeOptionsDialog::ActivatePage( sal_uInt16 nResId )
791 bIsForSetDocumentLanguage = false;
792 if ( nResId == OFA_TP_LANGUAGES_FOR_SET_DOCUMENT_LANGUAGE )
794 bIsForSetDocumentLanguage = true;
795 nResId = OFA_TP_LANGUAGES;
798 DBG_ASSERT( !bIsFromExtensionManager, "OfaTreeOptionsDialog::ActivatePage(): call from extension manager" );
799 if ( !pLastPageSaver )
800 pLastPageSaver = new LastPageSaver;
801 bForgetSelection = true;
802 sal_uInt16 nTemp = pLastPageSaver->m_nLastPageId;
803 pLastPageSaver->m_nLastPageId = nResId;
804 ActivateLastSelection();
805 pLastPageSaver->m_nLastPageId = nTemp;
808 void OfaTreeOptionsDialog::ActivatePage( const OUString& rPageURL )
810 DBG_ASSERT( !bIsFromExtensionManager, "OfaTreeOptionsDialog::ActivatePage(): call from extension manager" );
811 if ( !pLastPageSaver )
812 pLastPageSaver = new LastPageSaver;
813 bForgetSelection = true;
814 pLastPageSaver->m_nLastPageId = 0;
815 pLastPageSaver->m_sLastPageURL_Tools = rPageURL;
816 ActivateLastSelection();
819 void OfaTreeOptionsDialog::ActivateLastSelection()
821 SvTreeListEntry* pEntry = NULL;
822 if ( pLastPageSaver )
824 OUString sExpand( EXPAND_PROTOCOL );
825 OUString sLastURL = bIsFromExtensionManager ? pLastPageSaver->m_sLastPageURL_ExtMgr
826 : pLastPageSaver->m_sLastPageURL_Tools;
827 if ( sLastURL.isEmpty() )
829 sLastURL = !bIsFromExtensionManager ? pLastPageSaver->m_sLastPageURL_ExtMgr
830 : pLastPageSaver->m_sLastPageURL_Tools;
833 // MacroExpander to convert "expand"-URL to "file"-URL
834 Reference< XMacroExpander > xMacroExpander;
835 bool bMustExpand = ( INetURLObject( sLastURL ).GetProtocol() == INET_PROT_FILE );
837 if ( bMustExpand )
839 Reference< XComponentContext > xContext(
840 comphelper::getProcessComponentContext() );
841 xMacroExpander = theMacroExpander::get(xContext);
844 SvTreeListEntry* pTemp = aTreeLB.First();
845 while( !pEntry && pTemp )
847 // restore only selection of a leaf
848 if ( aTreeLB.GetParent( pTemp ) && pTemp->GetUserData() )
850 OptionsPageInfo* pPageInfo = (OptionsPageInfo*)pTemp->GetUserData();
851 OUString sPageURL = pPageInfo->m_sPageURL;
852 if ( bMustExpand
853 && !sPageURL.isEmpty()
854 && sPageURL.startsWith( sExpand ) )
856 // cut protocol
857 OUString sTemp( sPageURL.copy( sExpand.getLength() ) );
858 // decode uri class chars
859 sTemp = ::rtl::Uri::decode(
860 sTemp, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
861 // expand string
862 sPageURL = xMacroExpander->expandMacros( sTemp );
865 if ( ( !bIsFromExtensionManager
866 && pPageInfo->m_nPageId && pPageInfo->m_nPageId == pLastPageSaver->m_nLastPageId )
867 || ( !pPageInfo->m_nPageId && sLastURL == sPageURL ) )
868 pEntry = pTemp;
870 pTemp = aTreeLB.Next(pTemp);
874 if ( !pEntry )
876 pEntry = aTreeLB.First();
877 pEntry = aTreeLB.Next(pEntry);
880 if ( !pEntry )
881 return;
883 SvTreeListEntry* pParent = aTreeLB.GetParent(pEntry);
884 aTreeLB.Expand(pParent);
885 aTreeLB.MakeVisible(pParent);
886 aTreeLB.MakeVisible(pEntry);
887 aTreeLB.Select(pEntry);
888 aTreeLB.GrabFocus();
891 bool OfaTreeOptionsDialog::Notify( NotifyEvent& rNEvt )
893 if ( rNEvt.GetType() == EVENT_KEYINPUT )
895 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
896 const KeyCode aKeyCode = pKEvt->GetKeyCode();
898 if( aKeyCode.GetCode() == KEY_PAGEUP ||
899 aKeyCode.GetCode() == KEY_PAGEDOWN)
901 SvTreeListEntry* pCurEntry = aTreeLB.FirstSelected();
902 SvTreeListEntry* pTemp = 0;
903 if(aKeyCode.GetCode() == KEY_PAGEDOWN)
905 pTemp = aTreeLB.Next( pCurEntry ) ;
906 if(pTemp && !aTreeLB.GetParent(pTemp))
908 pTemp = aTreeLB.Next( pTemp ) ;
909 aTreeLB.Select(pTemp);
912 else
914 pTemp = aTreeLB.Prev( pCurEntry ) ;
915 if(pTemp && !aTreeLB.GetParent(pTemp))
917 pTemp = aTreeLB.Prev( pTemp ) ;
920 if(pTemp)
922 if(!aTreeLB.IsExpanded(aTreeLB.GetParent(pTemp)))
923 aTreeLB.Expand(aTreeLB.GetParent(pTemp));
924 aTreeLB.MakeVisible(pTemp);
925 aTreeLB.Select(pTemp);
929 return SfxModalDialog::Notify(rNEvt);
932 bool OfaTreeOptionsDialog::hasTreePendingLayout() const
934 return maTreeLayoutTimer.IsActive();
937 void OfaTreeOptionsDialog::queue_resize()
939 if (hasTreePendingLayout())
940 return;
941 if (IsInClose())
942 return;
943 maTreeLayoutTimer.Start();
946 IMPL_LINK( OfaTreeOptionsDialog, ImplHandleTreeLayoutTimerHdl, void*, EMPTYARG )
948 if (pCurrentPageEntry && aTreeLB.GetParent(pCurrentPageEntry))
950 OptionsPageInfo* pPageInfo = (OptionsPageInfo*)pCurrentPageEntry->GetUserData();
951 if (pPageInfo->m_pPage && ::isLayoutEnabled(pPageInfo->m_pPage))
952 SetPaneSize(pPageInfo->m_pPage);
954 return 0;
958 void OfaTreeOptionsDialog::SetPaneSize(Window *pPane)
960 //The OfaTreeOptionsDialog is not fully widget layout enabled
961 //yet so it's a classic fixed dimension dialog, but to make
962 //it possible to incrementally convert it over each pane
963 //can be converted to .ui layout format and the fixed area
964 //size reserved for panes is allocated to them here
965 Point aPos(aSeparatorFL.GetPosPixel().X(), aTreeLB.GetPosPixel().Y());
966 Size aSize(aSeparatorFL.GetSizePixel().Width(),
967 aSeparatorFL.GetPosPixel().Y() - aTreeLB.GetPosPixel().Y());
968 pPane->SetPosSizePixel( aPos, aSize );
971 void OfaTreeOptionsDialog::SelectHdl_Impl()
973 SvTreeListBox* pBox = &aTreeLB;
975 if(pCurrentPageEntry == pBox->GetCurEntry())
977 pBox->EndSelection();
978 return;
981 SvTreeListEntry* pEntry = pBox->GetCurEntry();
982 SvTreeListEntry* pParent = pBox->GetParent(pEntry);
984 // If the user has selected a category, automatically switch to a suitable
985 // default sub-page instead.
986 if (!pParent)
988 pBox->EndSelection();
989 return;
992 pBox->EndSelection();
994 TabPage* pOldPage = NULL;
995 TabPage* pNewPage = NULL;
996 OptionsPageInfo* pOptPageInfo = ( pCurrentPageEntry && aTreeLB.GetParent( pCurrentPageEntry ) )
997 ? (OptionsPageInfo*)pCurrentPageEntry->GetUserData() : NULL;
999 if ( pOptPageInfo && pOptPageInfo->m_pPage && pOptPageInfo->m_pPage->IsVisible() )
1001 pOldPage = pOptPageInfo->m_pPage;
1002 OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo*)aTreeLB.GetParent(pCurrentPageEntry)->GetUserData();
1003 int nLeave = SfxTabPage::LEAVE_PAGE;
1004 if ( RID_SVXPAGE_COLOR != pOptPageInfo->m_nPageId && pOptPageInfo->m_pPage->HasExchangeSupport() )
1005 nLeave = pOptPageInfo->m_pPage->DeactivatePage( pGroupInfo->m_pOutItemSet );
1007 if ( nLeave == SfxTabPage::KEEP_PAGE )
1009 // we cannot leave this page
1010 pBox->Select( pCurrentPageEntry );
1011 return;
1013 else
1014 pOptPageInfo->m_pPage->Hide();
1016 else if ( pOptPageInfo && pOptPageInfo->m_pExtPage )
1018 pOptPageInfo->m_pExtPage->Hide();
1019 pOptPageInfo->m_pExtPage->DeactivatePage();
1021 else if ( pCurrentPageEntry && !aTreeLB.GetParent( pCurrentPageEntry ) )
1023 OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo*)pCurrentPageEntry->GetUserData();
1024 if ( pGroupInfo && pGroupInfo->m_pExtPage )
1026 pGroupInfo->m_pExtPage->Hide();
1027 pGroupInfo->m_pExtPage->DeactivatePage();
1031 OptionsPageInfo *pPageInfo = (OptionsPageInfo *)pEntry->GetUserData();
1032 OptionsGroupInfo* pGroupInfo = (OptionsGroupInfo *)pParent->GetUserData();
1033 if(!pPageInfo->m_pPage && pPageInfo->m_nPageId > 0)
1035 if(pGroupInfo->m_bLoadError)
1036 return;
1037 if ( RID_SVXPAGE_COLOR == pPageInfo->m_nPageId )
1039 if(!pColorPageItemSet)
1041 // Move usage of a static XOutdevItemPool instance here
1042 if(!mpStaticXOutdevItemPool)
1043 mpStaticXOutdevItemPool = new XOutdevItemPool();
1045 pColorPageItemSet = new SfxItemSet( *mpStaticXOutdevItemPool, XATTR_FILLSTYLE, XATTR_FILLCOLOR);
1046 pColorPageItemSet->Put( XFillColorItem() );
1049 else
1051 if(pGroupInfo->m_pModule /*&& !pGroupInfo->pModule->IsLoaded()*/)
1053 SfxModule* pOldModule = pGroupInfo->m_pModule;
1054 bool bIdentical = pGroupInfo->m_pModule == pGroupInfo->m_pShell;
1056 WaitObject aWait(this);
1057 //pGroupInfo->pModule = pGroupInfo->pModule->Load();
1058 if(!pGroupInfo->m_pModule)
1060 pGroupInfo->m_bLoadError = true;
1061 InfoBox(pBox, sNotLoadedError).Execute();
1062 return;
1064 if(bIdentical)
1065 pGroupInfo->m_pShell = pGroupInfo->m_pModule;
1066 // now test whether there was the same module in other groups, too (e. g. Text+HTML)
1067 SvTreeListEntry* pTemp = aTreeLB.First();
1068 while(pTemp)
1070 if(!aTreeLB.GetParent(pTemp) && pTemp != pEntry)
1072 OptionsGroupInfo* pTGInfo = (OptionsGroupInfo *)pTemp->GetUserData();
1073 if(pTGInfo->m_pModule == pOldModule)
1075 pTGInfo->m_pModule = pGroupInfo->m_pModule;
1076 if(bIdentical)
1077 pTGInfo->m_pShell = pGroupInfo->m_pModule;
1080 pTemp = aTreeLB.Next(pTemp);
1084 if(!pGroupInfo->m_pInItemSet)
1085 pGroupInfo->m_pInItemSet = pGroupInfo->m_pShell
1086 ? pGroupInfo->m_pShell->CreateItemSet( pGroupInfo->m_nDialogId )
1087 : CreateItemSet( pGroupInfo->m_nDialogId );
1088 if(!pGroupInfo->m_pOutItemSet)
1089 pGroupInfo->m_pOutItemSet = new SfxItemSet(
1090 *pGroupInfo->m_pInItemSet->GetPool(),
1091 pGroupInfo->m_pInItemSet->GetRanges());
1094 if(pPageInfo->m_nPageId == RID_SVXPAGE_COLOR)
1096 pPageInfo->m_pPage = ::CreateGeneralTabPage(
1097 pPageInfo->m_nPageId, this, *pColorPageItemSet );
1098 mpColorPage = (SvxColorTabPage*)pPageInfo->m_pPage;
1099 mpColorPage->SetupForViewFrame( SfxViewFrame::Current() );
1101 else
1103 pPageInfo->m_pPage = ::CreateGeneralTabPage(pPageInfo->m_nPageId, this, *pGroupInfo->m_pInItemSet );
1105 if(!pPageInfo->m_pPage && pGroupInfo->m_pModule)
1106 pPageInfo->m_pPage = pGroupInfo->m_pModule->CreateTabPage(pPageInfo->m_nPageId, this, *pGroupInfo->m_pInItemSet);
1110 DBG_ASSERT( pPageInfo->m_pPage, "tabpage could not created");
1111 if ( pPageInfo->m_pPage )
1113 SvtViewOptions aTabPageOpt( E_TABPAGE, OUString::number( pPageInfo->m_nPageId) );
1114 pPageInfo->m_pPage->SetUserData( GetViewOptUserItem( aTabPageOpt ) );
1116 Point aPagePos( aSeparatorFL.GetPosPixel().X(), aTreeLB.GetPosPixel().Y());
1117 pPageInfo->m_pPage->SetPosPixel( aPagePos );
1118 if ( RID_SVXPAGE_COLOR == pPageInfo->m_nPageId )
1120 pPageInfo->m_pPage->Reset( *pColorPageItemSet );
1121 pPageInfo->m_pPage->ActivatePage( *pColorPageItemSet );
1123 else
1125 pPageInfo->m_pPage->Reset( *pGroupInfo->m_pInItemSet );
1127 if (::isLayoutEnabled(pPageInfo->m_pPage))
1128 SetPaneSize(pPageInfo->m_pPage);
1131 else if ( 0 == pPageInfo->m_nPageId && !pPageInfo->m_pExtPage )
1133 if ( !m_xContainerWinProvider.is() )
1135 m_xContainerWinProvider = awt::ContainerWindowProvider::create( ::comphelper::getProcessComponentContext() );
1138 pPageInfo->m_pExtPage = new ExtensionsTabPage(
1139 this, 0, pPageInfo->m_sPageURL, pPageInfo->m_sEventHdl, m_xContainerWinProvider );
1141 SetPaneSize(pPageInfo->m_pExtPage);
1144 if ( pPageInfo->m_pPage )
1146 if ( RID_SVXPAGE_COLOR != pPageInfo->m_nPageId &&
1147 pPageInfo->m_pPage->HasExchangeSupport())
1149 pPageInfo->m_pPage->ActivatePage(*pGroupInfo->m_pOutItemSet);
1151 pPageInfo->m_pPage->Show();
1153 else if ( pPageInfo->m_pExtPage )
1155 pPageInfo->m_pExtPage->Show();
1156 pPageInfo->m_pExtPage->ActivatePage();
1160 OUStringBuffer sTitleBuf(sTitle);
1161 sTitleBuf.append(" - ");
1162 sTitleBuf.append(aTreeLB.GetEntryText(pParent));
1163 sTitleBuf.append(" - ");
1164 sTitleBuf.append(aTreeLB.GetEntryText(pEntry));
1165 SetText(sTitleBuf.makeStringAndClear());
1168 pCurrentPageEntry = pEntry;
1169 if ( !bForgetSelection )
1171 if ( !pLastPageSaver )
1172 pLastPageSaver = new LastPageSaver;
1173 if ( !bIsFromExtensionManager )
1174 pLastPageSaver->m_nLastPageId = pPageInfo->m_nPageId;
1175 if ( pPageInfo->m_pExtPage )
1177 if ( bIsFromExtensionManager )
1178 pLastPageSaver->m_sLastPageURL_ExtMgr = pPageInfo->m_sPageURL;
1179 else
1180 pLastPageSaver->m_sLastPageURL_Tools = pPageInfo->m_sPageURL;
1183 pNewPage = pPageInfo->m_pPage;
1185 // restore lost focus, if necessary
1186 Window* pFocusWin = Application::GetFocusWindow();
1187 // if the focused window is not the options treebox and the old page has the focus
1188 if ( pFocusWin && pFocusWin != pBox && pOldPage && pOldPage->HasChildPathFocus() )
1189 // then set the focus to the new page or if we are on a group set the focus to the options treebox
1190 pNewPage ? pNewPage->GrabFocus() : pBox->GrabFocus();
1192 //fdo#58170 use current page's layout child HelpId, unless there isn't a
1193 //current page
1194 OString sHelpId(HID_OFADLG_TREELISTBOX);
1195 if (::isLayoutEnabled(pNewPage))
1197 Window *pFirstChild = pNewPage->GetWindow(WINDOW_FIRSTCHILD);
1198 assert(pFirstChild);
1199 sHelpId = pFirstChild->GetHelpId();
1201 pBox->SetHelpId(sHelpId);
1203 return;
1206 OfaPageResource::OfaPageResource() :
1207 Resource(CUI_RES(RID_OFADLG_OPTIONS_TREE_PAGES)),
1208 aGeneralDlgAry(CUI_RES(SID_GENERAL_OPTIONS)),
1209 aInetDlgAry(CUI_RES(SID_INET_DLG)),
1210 aLangDlgAry(CUI_RES(SID_LANGUAGE_OPTIONS)),
1211 aTextDlgAry(CUI_RES(SID_SW_EDITOPTIONS)),
1212 aHTMLDlgAry(CUI_RES(SID_SW_ONLINEOPTIONS)),
1213 aCalcDlgAry(CUI_RES(SID_SC_EDITOPTIONS)),
1214 aStarMathDlgAry(CUI_RES(SID_SM_EDITOPTIONS)),
1215 aImpressDlgAry(CUI_RES(SID_SD_EDITOPTIONS)),
1216 aDrawDlgAry(CUI_RES(SID_SD_GRAPHIC_OPTIONS)),
1217 aChartDlgAry(CUI_RES(SID_SCH_EDITOPTIONS)),
1218 aFilterDlgAry(CUI_RES(SID_FILTER_DLG)),
1219 aDatasourcesDlgAry(CUI_RES(SID_SB_STARBASEOPTIONS))
1221 FreeResource();
1224 SfxItemSet* OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId )
1226 Reference< XLinguProperties > xProp( SvxGetLinguPropertySet() );
1227 SfxItemSet* pRet = 0;
1228 switch(nId)
1230 case SID_GENERAL_OPTIONS:
1232 pRet = new SfxItemSet(
1233 SFX_APP()->GetPool(),
1234 SID_ATTR_METRIC, SID_ATTR_SPELL,
1235 SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK,
1236 SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER,
1237 SID_ATTR_YEAR2000, SID_ATTR_YEAR2000,
1238 SID_HTML_MODE, SID_HTML_MODE,
1239 0 );
1241 SfxItemSet aOptSet( SFX_APP()->GetPool(), SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER );
1242 SFX_APP()->GetOptions(aOptSet);
1243 pRet->Put(aOptSet);
1245 utl::MiscCfg aMisc;
1246 const SfxPoolItem* pItem;
1247 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1248 if ( pViewFrame )
1250 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1252 // miscellaneous - Year2000
1253 if( SFX_ITEM_AVAILABLE <= pDispatch->QueryState( SID_ATTR_YEAR2000, pItem ) )
1254 pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, ((const SfxUInt16Item*)pItem)->GetValue() ) );
1255 else
1256 pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, (sal_uInt16)aMisc.GetYear2000() ) );
1258 else
1259 pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, (sal_uInt16)aMisc.GetYear2000() ) );
1262 // miscellaneous - Tabulator
1263 pRet->Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN, aMisc.IsNotFoundWarning()));
1265 sal_uInt16 nFlag = aMisc.IsPaperSizeWarning() ? SFX_PRINTER_CHG_SIZE : 0;
1266 nFlag |= aMisc.IsPaperOrientationWarning() ? SFX_PRINTER_CHG_ORIENTATION : 0;
1267 pRet->Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC, nFlag ));
1270 break;
1271 case SID_LANGUAGE_OPTIONS :
1273 pRet = new SfxItemSet(SFX_APP()->GetPool(),
1274 SID_ATTR_LANGUAGE, SID_AUTOSPELL_CHECK,
1275 SID_ATTR_CHAR_CJK_LANGUAGE, SID_ATTR_CHAR_CTL_LANGUAGE,
1276 SID_OPT_LOCALE_CHANGED, SID_OPT_LOCALE_CHANGED,
1277 SID_SET_DOCUMENT_LANGUAGE, SID_SET_DOCUMENT_LANGUAGE,
1278 0 );
1280 // for linguistic
1282 Reference< XSpellChecker1 > xSpell = SvxGetSpellChecker();
1283 pRet->Put(SfxSpellCheckItem( xSpell, SID_ATTR_SPELL ));
1284 SfxHyphenRegionItem aHyphen( SID_ATTR_HYPHENREGION );
1286 sal_Int16 nMinLead = 2,
1287 nMinTrail = 2;
1288 if (xProp.is())
1290 nMinLead = xProp->getHyphMinLeading();
1291 nMinTrail = xProp->getHyphMinTrailing();
1293 aHyphen.GetMinLead() = (sal_uInt8)nMinLead;
1294 aHyphen.GetMinTrail() = (sal_uInt8)nMinTrail;
1296 const SfxPoolItem* pItem;
1297 SfxPoolItem* pClone;
1298 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1299 if ( pViewFrame )
1301 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1302 if(SFX_ITEM_AVAILABLE <= pDispatch->QueryState(SID_ATTR_LANGUAGE, pItem))
1303 pRet->Put(SfxUInt16Item(SID_ATTR_LANGUAGE, ((const SvxLanguageItem*)pItem)->GetLanguage()));
1304 if(SFX_ITEM_AVAILABLE <= pDispatch->QueryState(SID_ATTR_CHAR_CJK_LANGUAGE, pItem))
1305 pRet->Put(SfxUInt16Item(SID_ATTR_CHAR_CJK_LANGUAGE, ((const SvxLanguageItem*)pItem)->GetLanguage()));
1306 if(SFX_ITEM_AVAILABLE <= pDispatch->QueryState(SID_ATTR_CHAR_CTL_LANGUAGE, pItem))
1307 pRet->Put(SfxUInt16Item(SID_ATTR_CHAR_CTL_LANGUAGE, ((const SvxLanguageItem*)pItem)->GetLanguage()));
1309 pRet->Put(aHyphen);
1310 if(SFX_ITEM_AVAILABLE <= pDispatch->QueryState(SID_AUTOSPELL_CHECK, pItem))
1312 pClone = pItem->Clone();
1313 pRet->Put(*pClone);
1314 delete pClone;
1316 else
1318 bool bVal = false;
1319 if (xProp.is())
1321 bVal = xProp->getIsSpellAuto();
1324 pRet->Put(SfxBoolItem(SID_AUTOSPELL_CHECK, bVal));
1327 pRet->Put( SfxBoolItem( SID_SET_DOCUMENT_LANGUAGE, bIsForSetDocumentLanguage ) );
1329 break;
1330 case SID_INET_DLG :
1331 pRet = new SfxItemSet( SFX_APP()->GetPool(),
1332 SID_BASIC_ENABLED, SID_BASIC_ENABLED,
1333 //SID_OPTIONS_START - ..END
1334 SID_INET_PROXY_TYPE, SID_INET_PROXY_PORT,
1335 SID_SAVEREL_INET, SID_SAVEREL_FSYS,
1336 SID_INET_SMTPSERVER, SID_INET_SMTPSERVER,
1337 SID_INET_NOPROXY, SID_INET_SOCKS_PROXY_PORT,
1338 SID_INET_DNS_AUTO, SID_INET_DNS_SERVER,
1339 SID_SECURE_URL, SID_SECURE_URL,
1340 0L );
1341 SFX_APP()->GetOptions(*pRet);
1342 break;
1343 case SID_FILTER_DLG:
1344 pRet = new SfxItemSet( SFX_APP()->GetPool(),
1345 SID_ATTR_DOCINFO, SID_ATTR_AUTOSAVEMINUTE,
1346 SID_SAVEREL_INET, SID_SAVEREL_FSYS,
1347 SID_ATTR_PRETTYPRINTING, SID_ATTR_PRETTYPRINTING,
1348 SID_ATTR_WARNALIENFORMAT, SID_ATTR_WARNALIENFORMAT,
1349 0 );
1350 SFX_APP()->GetOptions(*pRet);
1351 break;
1353 case SID_SB_STARBASEOPTIONS:
1354 pRet = new SfxItemSet( SFX_APP()->GetPool(),
1355 SID_SB_POOLING_ENABLED, SID_SB_DB_REGISTER,
1356 0 );
1357 ::offapp::ConnectionPoolConfig::GetOptions(*pRet);
1358 ::svx::DbRegisteredNamesConfig::GetOptions(*pRet);
1359 break;
1361 case SID_SCH_EDITOPTIONS:
1363 SvxChartOptions aChartOpt;
1364 pRet = new SfxItemSet( SFX_APP()->GetPool(), SID_SCH_EDITOPTIONS, SID_SCH_EDITOPTIONS );
1365 pRet->Put( SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aChartOpt.GetDefaultColors() ) );
1366 break;
1369 return pRet;
1372 void OfaTreeOptionsDialog::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
1374 switch(nId)
1376 case SID_GENERAL_OPTIONS:
1378 utl::MiscCfg aMisc;
1379 const SfxPoolItem* pItem;
1380 SfxItemSet aOptSet(SFX_APP()->GetPool(), SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER );
1381 aOptSet.Put(rSet);
1382 if(aOptSet.Count())
1383 SFX_APP()->SetOptions( aOptSet );
1384 // get dispatcher anew, because SetOptions() might have destroyed the dispatcher
1385 SfxViewFrame *pViewFrame = SfxViewFrame::Current();
1387 // evaluate Year2000
1389 sal_uInt16 nY2K = USHRT_MAX;
1390 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_YEAR2000, false, &pItem ) )
1391 nY2K = ((const SfxUInt16Item*)pItem)->GetValue();
1392 if( USHRT_MAX != nY2K )
1394 if ( pViewFrame )
1396 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1397 pDispatch->Execute( SID_ATTR_YEAR2000, SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1399 aMisc.SetYear2000(nY2K);
1403 // evaluate print
1405 if(SFX_ITEM_SET == rSet.GetItemState(SID_PRINTER_NOTFOUND_WARN, false, &pItem))
1406 aMisc.SetNotFoundWarning(((const SfxBoolItem*)pItem)->GetValue());
1408 if(SFX_ITEM_SET == rSet.GetItemState(SID_PRINTER_CHANGESTODOC, false, &pItem))
1410 const SfxFlagItem* pFlag = (const SfxFlagItem*)pItem;
1411 aMisc.SetPaperSizeWarning(0 != (pFlag->GetValue() & SFX_PRINTER_CHG_SIZE ));
1412 aMisc.SetPaperOrientationWarning(0 != (pFlag->GetValue() & SFX_PRINTER_CHG_ORIENTATION ));
1415 // evaluate help options
1417 if ( SvtHelpOptions().IsHelpTips() != Help::IsQuickHelpEnabled() )
1418 SvtHelpOptions().IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
1419 if ( SvtHelpOptions().IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
1420 SvtHelpOptions().IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
1422 break;
1423 case SID_LANGUAGE_OPTIONS :
1425 OfaTreeOptionsDialog::ApplyLanguageOptions(rSet);
1427 break;
1428 case SID_INET_DLG :
1429 case SID_FILTER_DLG:
1430 SFX_APP()->SetOptions( rSet );
1431 break;
1433 case SID_SB_STARBASEOPTIONS:
1434 ::offapp::ConnectionPoolConfig::SetOptions( rSet );
1435 ::svx::DbRegisteredNamesConfig::SetOptions(rSet);
1436 break;
1438 case SID_SCH_EDITOPTIONS:
1439 // nothing to do. Chart options only apply to newly created charts
1440 break;
1442 default:
1444 OSL_FAIL( "Unhandled option in ApplyItemSet" );
1446 break;
1450 void OfaTreeOptionsDialog::ApplyLanguageOptions(const SfxItemSet& rSet)
1452 bool bSaveSpellCheck = false;
1453 const SfxPoolItem* pItem;
1455 if ( SFX_ITEM_SET == rSet.GetItemState( SID_SPELL_MODIFIED, false, &pItem ) )
1457 bSaveSpellCheck = ( (const SfxBoolItem*)pItem )->GetValue();
1459 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1460 Reference< XLinguProperties > xProp = LinguProperties::create( xContext );
1461 if ( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_HYPHENREGION, false, &pItem ) )
1463 const SfxHyphenRegionItem* pHyphenItem = (const SfxHyphenRegionItem*)pItem;
1465 xProp->setHyphMinLeading( (sal_Int16) pHyphenItem->GetMinLead() );
1466 xProp->setHyphMinTrailing( (sal_Int16) pHyphenItem->GetMinTrail() );
1467 bSaveSpellCheck = true;
1470 SfxViewFrame *pViewFrame = SfxViewFrame::Current();
1471 if ( pViewFrame )
1473 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1474 pItem = 0;
1475 if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_LANGUAGE, false, &pItem ))
1477 pDispatch->Execute(pItem->Which(), SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1478 bSaveSpellCheck = true;
1480 if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE, false, &pItem ))
1482 pDispatch->Execute(pItem->Which(), SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1483 bSaveSpellCheck = true;
1485 if(SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE, false, &pItem ))
1487 pDispatch->Execute(pItem->Which(), SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1488 bSaveSpellCheck = true;
1491 if( SFX_ITEM_SET == rSet.GetItemState(SID_AUTOSPELL_CHECK, false, &pItem ))
1493 bool bOnlineSpelling = ((const SfxBoolItem*)pItem)->GetValue();
1494 pDispatch->Execute(SID_AUTOSPELL_CHECK,
1495 SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, pItem, 0L);
1497 xProp->setIsSpellAuto( bOnlineSpelling );
1500 if( bSaveSpellCheck )
1502 //! the config item has changed since we modified the
1503 //! property set it uses
1504 pDispatch->Execute(SID_SPELLCHECKER_CHANGED, SFX_CALLMODE_ASYNCHRON);
1508 if( SFX_ITEM_SET == rSet.GetItemState(SID_OPT_LOCALE_CHANGED, false, &pItem ))
1510 SfxViewFrame* _pViewFrame = SfxViewFrame::GetFirst();
1511 while ( _pViewFrame )
1513 _pViewFrame->GetDispatcher()->Execute(pItem->Which(), SFX_CALLMODE_ASYNCHRON, pItem, 0L);
1514 _pViewFrame = SfxViewFrame::GetNext( *_pViewFrame );
1519 OUString getCurrentFactory_Impl( const Reference< XFrame >& _xFrame )
1521 OUString sIdentifier;
1522 Reference < XFrame > xCurrentFrame( _xFrame );
1523 Reference < XModuleManager2 > xModuleManager = ModuleManager::create(::comphelper::getProcessComponentContext());
1524 if ( !xCurrentFrame.is() )
1526 Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1527 xCurrentFrame = xDesktop->getCurrentFrame();
1530 if ( xCurrentFrame.is() )
1534 sIdentifier = xModuleManager->identify( xCurrentFrame );
1536 catch ( ::com::sun::star::frame::UnknownModuleException& )
1538 DBG_WARNING( "getActiveModule_Impl(): unknown module" );
1540 catch ( Exception& )
1542 SAL_WARN( "cui.options", "getActiveModule_Impl(): exception of XModuleManager::identify()" );
1546 return sIdentifier;
1549 void OfaTreeOptionsDialog::Initialize( const Reference< XFrame >& _xFrame )
1551 OfaPageResource aDlgResource;
1552 sal_uInt16 nGroup = 0;
1554 SvtOptionsDialogOptions aOptionsDlgOpt;
1555 sal_uInt16 i, nPageId;
1557 // %PRODUCTNAME options
1558 if ( !lcl_isOptionHidden( SID_GENERAL_OPTIONS, aOptionsDlgOpt ) )
1560 ResStringArray& rGeneralArray = aDlgResource.GetGeneralArray();
1561 setGroupName( "ProductName", rGeneralArray.GetString(0) );
1562 nGroup = AddGroup( rGeneralArray.GetString(0), 0, 0, SID_GENERAL_OPTIONS );
1563 sal_uInt16 nEnd = static_cast< sal_uInt16 >( rGeneralArray.Count() );
1565 for ( i = 1; i < nEnd; ++i )
1567 OUString sNewTitle = rGeneralArray.GetString(i);
1568 nPageId = (sal_uInt16)rGeneralArray.GetValue(i);
1569 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1570 continue;
1572 // Disable Online Update page if service not installed
1573 if( RID_SVXPAGE_ONLINEUPDATE == nPageId )
1577 Reference < XInterface > xService( setup::UpdateCheck::create( ::comphelper::getProcessComponentContext() ) );
1578 if( ! xService.is() )
1579 continue;
1581 catch ( ::com::sun::star::uno::DeploymentException& )
1583 continue;
1586 AddTabPage( nPageId, sNewTitle, nGroup );
1590 // Load and Save options
1591 if ( !lcl_isOptionHidden( SID_FILTER_DLG, aOptionsDlgOpt ) )
1593 ResStringArray& rFilterArray = aDlgResource.GetFilterArray();
1594 setGroupName( "LoadSave", rFilterArray.GetString(0) );
1595 nGroup = AddGroup( rFilterArray.GetString(0), 0, 0, SID_FILTER_DLG );
1596 for ( i = 1; i < rFilterArray.Count(); ++i )
1598 nPageId = (sal_uInt16)rFilterArray.GetValue(i);
1599 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1600 AddTabPage( nPageId, rFilterArray.GetString(i), nGroup );
1604 // Language options
1605 SvtLanguageOptions aLanguageOptions;
1606 if ( !lcl_isOptionHidden( SID_LANGUAGE_OPTIONS, aOptionsDlgOpt ) )
1608 ResStringArray& rLangArray = aDlgResource.GetLangArray();
1609 setGroupName( "LanguageSettings", rLangArray.GetString(0) );
1610 nGroup = AddGroup( rLangArray.GetString(0), 0, 0, SID_LANGUAGE_OPTIONS );
1611 for ( i = 1; i < rLangArray.Count(); ++i )
1613 nPageId = (sal_uInt16)rLangArray.GetValue(i);
1614 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1615 continue;
1616 if ( ( RID_SVXPAGE_JSEARCH_OPTIONS != nPageId || aLanguageOptions.IsJapaneseFindEnabled() ) &&
1617 ( RID_SVXPAGE_ASIAN_LAYOUT != nPageId || aLanguageOptions.IsAsianTypographyEnabled() ) &&
1618 ( RID_SVXPAGE_OPTIONS_CTL != nPageId || aLanguageOptions.IsCTLFontEnabled() ) )
1619 AddTabPage( nPageId, rLangArray.GetString(i), nGroup );
1624 OUString aFactory = getCurrentFactory_Impl( _xFrame );
1625 DBG_ASSERT( GetModuleIdentifier( _xFrame ) == aFactory, "S H I T!!!" );
1627 // Writer and Writer/Web options
1628 SvtModuleOptions aModuleOpt;
1629 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
1631 // text document
1632 ResStringArray& rTextArray = aDlgResource.GetTextArray();
1633 if ( aFactory == "com.sun.star.text.TextDocument"
1634 || aFactory == "com.sun.star.text.WebDocument"
1635 || aFactory == "com.sun.star.text.GlobalDocument" )
1637 SfxModule* pSwMod = (*(SfxModule**) GetAppData(SHL_WRITER));
1638 if ( !lcl_isOptionHidden( SID_SW_EDITOPTIONS, aOptionsDlgOpt ) )
1640 if ( aFactory == "com.sun.star.text.WebDocument" )
1641 setGroupName( "WriterWeb", rTextArray.GetString(0) );
1642 else
1643 setGroupName( "Writer", rTextArray.GetString(0) );
1644 nGroup = AddGroup(rTextArray.GetString(0), pSwMod, pSwMod, SID_SW_EDITOPTIONS );
1645 for ( i = 1; i < rTextArray.Count(); ++i )
1647 nPageId = (sal_uInt16)rTextArray.GetValue(i);
1648 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1649 continue;
1650 if ( ( RID_SW_TP_STD_FONT_CJK != nPageId || aLanguageOptions.IsCJKFontEnabled() ) &&
1651 ( RID_SW_TP_STD_FONT_CTL != nPageId || aLanguageOptions.IsCTLFontEnabled() ) &&
1652 ( RID_SW_TP_MAILCONFIG != nPageId || MailMergeCfg_Impl().IsEmailSupported() ) )
1653 AddTabPage( nPageId, rTextArray.GetString(i), nGroup );
1655 #ifdef DBG_UTIL
1656 AddTabPage( RID_SW_TP_OPTTEST_PAGE, OUString("Internal Test"), nGroup );
1657 #endif
1660 // HTML documents
1661 if ( !lcl_isOptionHidden( SID_SW_ONLINEOPTIONS, aOptionsDlgOpt ) )
1663 ResStringArray& rHTMLArray = aDlgResource.GetHTMLArray();
1664 nGroup = AddGroup(rHTMLArray.GetString(0), pSwMod, pSwMod, SID_SW_ONLINEOPTIONS );
1665 for( i = 1; i < rHTMLArray.Count(); ++i )
1667 nPageId = (sal_uInt16)rHTMLArray.GetValue(i);
1668 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1669 AddTabPage( nPageId, rHTMLArray.GetString(i), nGroup );
1671 #ifdef DBG_UTIL
1672 AddTabPage( RID_SW_TP_OPTTEST_PAGE, OUString("Internal Test"), nGroup );
1673 #endif
1678 // Calc options
1679 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
1681 if ( aFactory == "com.sun.star.sheet.SpreadsheetDocument" )
1683 if ( !lcl_isOptionHidden( SID_SC_EDITOPTIONS, aOptionsDlgOpt ) )
1685 ResStringArray& rCalcArray = aDlgResource.GetCalcArray();
1686 SfxModule* pScMod = ( *( SfxModule** ) GetAppData( SHL_CALC ) );
1687 setGroupName( "Calc", rCalcArray.GetString(0) );
1688 nGroup = AddGroup( rCalcArray.GetString( 0 ), pScMod, pScMod, SID_SC_EDITOPTIONS );
1689 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rCalcArray.Count() );
1690 for ( i = 1; i < nCount; ++i )
1692 nPageId = (sal_uInt16)rCalcArray.GetValue(i);
1693 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1694 continue;
1696 AddTabPage( nPageId, rCalcArray.GetString( i ), nGroup );
1702 // Impress options
1703 SfxModule* pSdMod = ( *( SfxModule** ) GetAppData( SHL_DRAW ) );
1704 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
1706 if ( aFactory == "com.sun.star.presentation.PresentationDocument" )
1708 if ( !lcl_isOptionHidden( SID_SD_EDITOPTIONS, aOptionsDlgOpt ) )
1710 ResStringArray& rImpressArray = aDlgResource.GetImpressArray();
1711 setGroupName( "Impress", rImpressArray.GetString(0) );
1712 nGroup = AddGroup( rImpressArray.GetString( 0 ), pSdMod, pSdMod, SID_SD_EDITOPTIONS );
1713 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rImpressArray.Count() );
1714 for ( i = 1; i < nCount; ++i )
1716 nPageId = (sal_uInt16)rImpressArray.GetValue(i);
1717 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1718 continue;
1720 AddTabPage( nPageId, rImpressArray.GetString(i), nGroup );
1726 // Draw options
1727 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
1729 if ( aFactory == "com.sun.star.drawing.DrawingDocument" )
1731 if ( !lcl_isOptionHidden( SID_SD_GRAPHIC_OPTIONS, aOptionsDlgOpt ) )
1733 ResStringArray& rDrawArray = aDlgResource.GetDrawArray();
1734 setGroupName( "Draw", rDrawArray.GetString(0) );
1735 nGroup = AddGroup( rDrawArray.GetString( 0 ), pSdMod, pSdMod, SID_SD_GRAPHIC_OPTIONS );
1736 const sal_uInt16 nCount = static_cast< const sal_uInt16 >( rDrawArray.Count() );
1737 for ( i = 1; i < nCount; ++i )
1739 nPageId = (sal_uInt16)rDrawArray.GetValue(i);
1740 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1741 continue;
1743 AddTabPage( nPageId, rDrawArray.GetString(i), nGroup );
1749 // Math options
1750 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
1752 if ( aFactory == "com.sun.star.formula.FormulaProperties" )
1754 if ( !lcl_isOptionHidden( SID_SM_EDITOPTIONS, aOptionsDlgOpt ) )
1756 ResStringArray& rStarMathArray = aDlgResource.GetStarMathArray();
1757 SfxModule* pSmMod = (*(SfxModule**) GetAppData(SHL_SM));
1758 setGroupName( "Math", rStarMathArray.GetString(0) );
1759 nGroup = AddGroup(rStarMathArray.GetString(0), pSmMod, pSmMod, SID_SM_EDITOPTIONS );
1760 for ( i = 1; i < rStarMathArray.Count(); ++i )
1762 nPageId = (sal_uInt16)rStarMathArray.GetValue(i);
1763 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1764 AddTabPage( nPageId, rStarMathArray.GetString(i), nGroup );
1770 // Database - needed only if there is an application which integrates with databases
1771 if ( !lcl_isOptionHidden( SID_SB_STARBASEOPTIONS, aOptionsDlgOpt ) &&
1772 ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE )
1773 || aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER )
1774 || aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC )
1777 ResStringArray& rDSArray = aDlgResource.GetDatasourcesArray();
1778 setGroupName( "Base", rDSArray.GetString(0) );
1779 nGroup = AddGroup( rDSArray.GetString(0), 0, NULL, SID_SB_STARBASEOPTIONS );
1780 for ( i = 1; i < rDSArray.Count(); ++i )
1782 nPageId = (sal_uInt16)rDSArray.GetValue(i);
1783 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1784 AddTabPage( nPageId, rDSArray.GetString(i), nGroup );
1788 // Chart options (always installed and active)
1789 if ( !lcl_isOptionHidden( SID_SCH_EDITOPTIONS, aOptionsDlgOpt ) )
1791 ResStringArray& rChartArray = aDlgResource.GetChartArray();
1792 setGroupName( "Charts", rChartArray.GetString(0) );
1793 nGroup = AddGroup( rChartArray.GetString(0), 0, 0, SID_SCH_EDITOPTIONS );
1794 for ( i = 1; i < rChartArray.Count(); ++i )
1796 nPageId = (sal_uInt16)rChartArray.GetValue(i);
1797 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1798 AddTabPage( nPageId, rChartArray.GetString(i), nGroup );
1802 // Internet options
1803 if ( !lcl_isOptionHidden( SID_INET_DLG, aOptionsDlgOpt ) )
1805 ResStringArray& rInetArray = aDlgResource.GetInetArray();
1806 setGroupName( "Internet", rInetArray.GetString(0) );
1807 nGroup = AddGroup(rInetArray.GetString(0), 0, 0, SID_INET_DLG );
1809 for ( i = 1; i < rInetArray.Count(); ++i )
1811 nPageId = (sal_uInt16)rInetArray.GetValue(i);
1812 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1813 continue;
1814 #if defined WNT
1815 // Disable E-mail tab-page on Windows
1816 if ( nPageId == RID_SVXPAGE_INET_MAIL )
1817 continue;
1818 #endif
1819 #if defined MACOSX
1820 // Disable Mozilla Plug-in tab-page on Mac
1821 if ( nPageId == RID_SVXPAGE_INET_MOZPLUGIN )
1822 continue;
1823 #endif
1824 #ifdef LINUX
1825 // Disable Mozilla Plug-in tab-page on Linux if we find a
1826 // globally installed plugin
1827 if ( nPageId == RID_SVXPAGE_INET_MOZPLUGIN ) {
1828 struct stat sb;
1829 char *p;
1830 bool bHaveSystemWidePlugin = false;
1831 char mozpaths[]="/usr/lib/mozilla/plugins/libnpsoplugin.so:/usr/lib/firefox/plugins/libnpsoplugin.so:/usr/lib/mozilla-firefox/plugins/libnpsoplugin.so:/usr/lib/iceweasel/plugins/libnpsoplugin.so:/usr/lib/iceape/plugins/libnpsoplugin.so:/usr/lib/browser-plugins/libnpsoplugin.so:/usr/lib64/browser-plugins/libnpsoplugin.so";
1833 p = strtok(mozpaths, ":");
1834 while (p != NULL) {
1835 if (stat(p, &sb) != -1) {
1836 bHaveSystemWidePlugin = true;
1837 break;
1839 p = strtok(NULL, ":");
1842 if (bHaveSystemWidePlugin == true)
1843 continue;
1845 #endif
1846 AddTabPage( nPageId, rInetArray.GetString(i), nGroup );
1850 /*!!!
1851 ResizeTreeLB();
1852 ActivateLastSelection();
1856 namespace
1858 void MoveControl( Control& _rCtrl, long _nDeltaPixel )
1860 Point aPt( _rCtrl.GetPosPixel() );
1861 aPt.X() += _nDeltaPixel;
1862 _rCtrl.SetPosPixel( aPt );
1866 void OfaTreeOptionsDialog::ResizeTreeLB( void )
1868 const long nMax = aSeparatorFL.GetSizePixel().Width() * 42 / 100;
1869 // don't ask where 42 comes from... but it looks / feels ok ;-)
1870 long nDelta = 50; // min.
1871 sal_uInt16 nDepth = 0;
1872 const long nIndent0 = PixelToLogic( Size( 28, 0 ) ).Width();
1873 const long nIndent1 = PixelToLogic( Size( 52, 0 ) ).Width();
1875 SvTreeList* pTreeList = aTreeLB.GetModel();
1876 DBG_ASSERT( pTreeList, "-OfaTreeOptionsDialog::ResizeTreeLB(): no model, no cookies!" );
1878 SvTreeListEntry* pEntry = pTreeList->First();
1879 while( pEntry )
1881 long n = aTreeLB.GetTextWidth(aTreeLB.GetEntryText(pEntry));
1882 n += ((nDepth == 0) ? nIndent0 : nIndent1);
1884 if( n > nDelta )
1885 nDelta = n;
1887 pEntry = pTreeList->Next( pEntry, &nDepth );
1890 nDelta = LogicToPixel( Size( nDelta + 3, 0 ) ).Width(); // + extra space [logic]
1891 nDelta += GetSettings().GetStyleSettings().GetScrollBarSize(); // + scroll bar, in case it's needed
1893 if( nDelta > nMax )
1894 nDelta = nMax;
1896 // starting resizing with this
1897 Size aSize( GetSizePixel() );
1898 aSize.Width() += nDelta;
1899 SetSizePixel( aSize );
1901 // resize treelistbox
1902 aSize = aTreeLB.GetSizePixel();
1903 aSize.Width() += nDelta;
1904 aTreeLB.SetSizePixel( aSize );
1906 // ... and move depending controls
1907 MoveControl( aOkPB, nDelta );
1908 MoveControl( aCancelPB, nDelta );
1909 MoveControl( aHelpPB, nDelta );
1910 MoveControl( aBackPB, nDelta );
1911 MoveControl( aSeparatorFL, nDelta );
1914 bool isNodeActive( OptionsNode* pNode, Module* pModule )
1916 if ( pNode )
1918 // Node for all modules actine?
1919 if ( pNode->m_bAllModules )
1920 return true;
1922 // OOo-Nodes (Writer, Calc, Impress...) are active if node is already inserted
1923 if ( !getGroupName( pNode->m_sId, false ).isEmpty() )
1924 return true;
1926 // no module -> not active
1927 if ( !pModule )
1928 return false;
1930 // search node in active module
1931 if ( pModule->m_bActive )
1933 for ( sal_uInt32 j = 0; j < pModule->m_aNodeList.size(); ++j )
1934 if ( pModule->m_aNodeList[j]->m_sId == pNode->m_sId )
1935 return true;
1938 return false;
1941 void OfaTreeOptionsDialog::LoadExtensionOptions( const OUString& rExtensionId )
1943 Module* pModule = NULL;
1945 // when called by Tools - Options then load nodes of active module
1946 if ( rExtensionId.isEmpty() )
1948 pModule = LoadModule( GetModuleIdentifier( Reference< XFrame >() ) );
1951 VectorOfNodes aNodeList = LoadNodes( pModule, rExtensionId );
1952 InsertNodes( aNodeList );
1954 delete pModule;
1957 OUString OfaTreeOptionsDialog::GetModuleIdentifier( const Reference< XFrame >& rFrame )
1959 OUString sModule;
1960 Reference < XFrame > xCurrentFrame( rFrame );
1961 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
1962 Reference < XModuleManager2 > xModuleManager = ModuleManager::create(xContext);
1964 if ( !xCurrentFrame.is() )
1966 Reference < XDesktop2 > xDesktop = Desktop::create( xContext );
1967 xCurrentFrame = xDesktop->getCurrentFrame();
1970 if ( xCurrentFrame.is() )
1974 sModule = xModuleManager->identify( xCurrentFrame );
1976 catch ( ::com::sun::star::frame::UnknownModuleException& )
1978 DBG_WARNING( "OfaTreeOptionsDialog::GetModuleIdentifier(): unknown module" );
1980 catch ( Exception& )
1982 SAL_WARN( "cui.options", "OfaTreeOptionsDialog::GetModuleIdentifier(): exception of XModuleManager::identify()" );
1985 return sModule;
1988 Module* OfaTreeOptionsDialog::LoadModule(
1989 const OUString& rModuleIdentifier )
1991 Module* pModule = NULL;
1992 Reference< XNameAccess > xSet(
1993 officecfg::Office::OptionsDialog::Modules::get());
1995 Sequence< OUString > seqNames = xSet->getElementNames();
1996 for ( int i = 0; i < seqNames.getLength(); ++i )
1998 OUString sModule( seqNames[i] );
1999 if ( rModuleIdentifier == sModule )
2001 // current active module found
2002 pModule = new Module( sModule );
2003 pModule->m_bActive = true;
2005 Reference< XNameAccess > xModAccess;
2006 xSet->getByName( seqNames[i] ) >>= xModAccess;
2007 if ( xModAccess.is() )
2009 // load the nodes of this module
2010 Reference< XNameAccess > xNodeAccess;
2011 xModAccess->getByName( "Nodes" ) >>= xNodeAccess;
2012 if ( xNodeAccess.is() )
2014 Sequence< OUString > xTemp = xNodeAccess->getElementNames();
2015 Reference< XNameAccess > xAccess;
2016 sal_Int32 nIndex = -1;
2017 for ( int x = 0; x < xTemp.getLength(); ++x )
2019 xNodeAccess->getByName( xTemp[x] ) >>= xAccess;
2020 if ( xAccess.is() )
2022 xAccess->getByName( "Index" ) >>= nIndex;
2023 if ( nIndex < 0 )
2024 // append nodes with index < 0
2025 pModule->m_aNodeList.push_back(
2026 new OrderedEntry( nIndex, xTemp[x] ) );
2027 else
2029 // search position of the node
2030 sal_uInt32 y = 0;
2031 for ( ; y < pModule->m_aNodeList.size(); ++y )
2033 sal_Int32 nNodeIdx = pModule->m_aNodeList[y]->m_nIndex;
2034 if ( nNodeIdx < 0 || nNodeIdx > nIndex )
2035 break;
2037 // and insert the node on this position
2038 pModule->m_aNodeList.insert(
2039 pModule->m_aNodeList.begin() + y,
2040 new OrderedEntry( nIndex, xTemp[x] ) );
2046 break;
2049 return pModule;
2052 VectorOfNodes OfaTreeOptionsDialog::LoadNodes(
2053 Module* pModule, const OUString& rExtensionId)
2055 VectorOfNodes aOutNodeList;
2057 Reference< XNameAccess > xSet(
2058 officecfg::Office::OptionsDialog::Nodes::get());
2059 VectorOfNodes aNodeList;
2060 Sequence< OUString > seqNames = xSet->getElementNames();
2062 for ( int i = 0; i < seqNames.getLength(); ++i )
2064 OUString sGroupName( seqNames[i] );
2065 Reference< XNameAccess > xNodeAccess;
2066 xSet->getByName( seqNames[i] ) >>= xNodeAccess;
2068 if ( xNodeAccess.is() )
2070 OUString sNodeId, sLabel, sPageURL, sGroupId;
2071 bool bAllModules = false;
2072 sal_Int32 nGroupIndex = 0;
2074 sNodeId = seqNames[i];
2075 xNodeAccess->getByName( "Label" ) >>= sLabel;
2076 xNodeAccess->getByName( "OptionsPage" ) >>= sPageURL;
2077 xNodeAccess->getByName( "AllModules" ) >>= bAllModules;
2078 xNodeAccess->getByName( "GroupId" ) >>= sGroupId;
2079 xNodeAccess->getByName( "GroupIndex" ) >>= nGroupIndex;
2081 if ( sLabel.isEmpty() )
2082 sLabel = sGroupName;
2083 OUString sTemp = getGroupName( sLabel, !rExtensionId.isEmpty() );
2084 if ( !sTemp.isEmpty() )
2085 sLabel = sTemp;
2086 OptionsNode* pNode =
2087 new OptionsNode( sNodeId, sLabel, sPageURL, bAllModules, sGroupId, nGroupIndex );
2089 if ( rExtensionId.isEmpty() && !isNodeActive( pNode, pModule ) )
2091 delete pNode;
2092 continue;
2095 Reference< XNameAccess > xLeavesSet;
2096 xNodeAccess->getByName( "Leaves" ) >>= xLeavesSet;
2097 if ( xLeavesSet.is() )
2099 Sequence< OUString > seqLeaves = xLeavesSet->getElementNames();
2100 for ( int j = 0; j < seqLeaves.getLength(); ++j )
2102 Reference< XNameAccess > xLeaveAccess;
2103 xLeavesSet->getByName( seqLeaves[j] ) >>= xLeaveAccess;
2105 if ( xLeaveAccess.is() )
2107 OUString sId, sLeafLabel, sEventHdl, sLeafURL, sLeafGrpId;
2108 sal_Int32 nLeafGrpIdx = 0;
2110 xLeaveAccess->getByName( "Id" ) >>= sId;
2111 xLeaveAccess->getByName( "Label" ) >>= sLeafLabel;
2112 xLeaveAccess->getByName( "OptionsPage" ) >>= sLeafURL;
2113 xLeaveAccess->getByName( "EventHandlerService" ) >>= sEventHdl;
2114 xLeaveAccess->getByName( "GroupId" ) >>= sLeafGrpId;
2115 xLeaveAccess->getByName( "GroupIndex" ) >>= nLeafGrpIdx;
2117 if ( rExtensionId.isEmpty() || sId == rExtensionId )
2119 OptionsLeaf* pLeaf = new OptionsLeaf(
2120 sId, sLeafLabel, sLeafURL, sEventHdl, sLeafGrpId, nLeafGrpIdx );
2122 if ( !sLeafGrpId.isEmpty() )
2124 bool bAlreadyOpened = false;
2125 if ( pNode->m_aGroupedLeaves.size() > 0 )
2127 for ( sal_uInt32 k = 0;
2128 k < pNode->m_aGroupedLeaves.size(); ++k )
2130 if ( pNode->m_aGroupedLeaves[k].size() > 0 &&
2131 pNode->m_aGroupedLeaves[k][0]->m_sGroupId
2132 == sLeafGrpId )
2134 sal_uInt32 l = 0;
2135 for ( ; l < pNode->m_aGroupedLeaves[k].size(); ++l )
2137 if ( pNode->m_aGroupedLeaves[k][l]->
2138 m_nGroupIndex >= nLeafGrpIdx )
2139 break;
2141 pNode->m_aGroupedLeaves[k].insert(
2142 pNode->m_aGroupedLeaves[k].begin() + l, pLeaf );
2143 bAlreadyOpened = true;
2144 break;
2148 if ( !bAlreadyOpened )
2150 VectorOfLeaves aGroupedLeaves;
2151 aGroupedLeaves.push_back( pLeaf );
2152 pNode->m_aGroupedLeaves.push_back( aGroupedLeaves );
2155 else
2156 pNode->m_aLeaves.push_back( pLeaf );
2162 // do not insert nodes without leaves
2163 if ( pNode->m_aLeaves.size() > 0 || pNode->m_aGroupedLeaves.size() > 0 )
2165 pModule ? aNodeList.push_back( pNode ) : aOutNodeList.push_back( pNode );
2167 else
2168 delete pNode;
2172 if ( pModule && aNodeList.size() > 0 )
2174 sal_uInt32 i = 0, j = 0;
2175 for ( ; i < pModule->m_aNodeList.size(); ++i )
2177 OUString sNodeId = pModule->m_aNodeList[i]->m_sId;
2178 for ( j = 0; j < aNodeList.size(); ++j )
2180 OptionsNode* pNode = aNodeList[j];
2181 if ( pNode->m_sId == sNodeId )
2183 aOutNodeList.push_back( pNode );
2184 aNodeList.erase( aNodeList.begin() + j );
2185 break;
2190 for ( i = 0; i < aNodeList.size(); ++i )
2191 aOutNodeList.push_back( aNodeList[i] );
2193 return aOutNodeList;
2196 static sal_uInt16 lcl_getGroupId( const OUString& rGroupName, const SvTreeListBox& rTreeLB )
2198 OUString sGroupName( rGroupName );
2199 sal_uInt16 nRet = 0;
2200 SvTreeListEntry* pEntry = rTreeLB.First();
2201 while( pEntry )
2203 if ( !rTreeLB.GetParent( pEntry ) )
2205 OUString sTemp( rTreeLB.GetEntryText( pEntry ) );
2206 if ( sTemp == sGroupName )
2207 return nRet;
2208 nRet++;
2210 pEntry = rTreeLB.Next( pEntry );
2213 return USHRT_MAX;
2216 static void lcl_insertLeaf(
2217 OfaTreeOptionsDialog* pDlg, OptionsNode* pNode, OptionsLeaf* pLeaf, const SvTreeListBox& rTreeLB )
2219 sal_uInt16 nGrpId = lcl_getGroupId( pNode->m_sLabel, rTreeLB );
2220 if ( USHRT_MAX == nGrpId )
2222 sal_uInt16 nNodeGrpId = getGroupNodeId( pNode->m_sId );
2223 nGrpId = pDlg->AddGroup( pNode->m_sLabel, NULL, NULL, nNodeGrpId );
2224 if ( !pNode->m_sPageURL.isEmpty() )
2226 SvTreeListEntry* pGrpEntry = rTreeLB.GetEntry( 0, nGrpId );
2227 DBG_ASSERT( pGrpEntry, "OfaTreeOptionsDialog::InsertNodes(): no group" );
2228 if ( pGrpEntry )
2230 OptionsGroupInfo* pGrpInfo =
2231 static_cast<OptionsGroupInfo*>(pGrpEntry->GetUserData());
2232 pGrpInfo->m_sPageURL = pNode->m_sPageURL;
2236 OptionsPageInfo* pInfo = pDlg->AddTabPage( 0, pLeaf->m_sLabel, nGrpId );
2237 pInfo->m_sPageURL = pLeaf->m_sPageURL;
2238 pInfo->m_sEventHdl = pLeaf->m_sEventHdl;
2241 void OfaTreeOptionsDialog::InsertNodes( const VectorOfNodes& rNodeList )
2243 for ( sal_uInt32 i = 0; i < rNodeList.size(); ++i )
2245 OptionsNode* pNode = rNodeList[i];
2247 if ( pNode->m_aLeaves.size() > 0 || pNode->m_aGroupedLeaves.size() > 0 )
2249 sal_uInt32 j = 0;
2250 for ( ; j < pNode->m_aGroupedLeaves.size(); ++j )
2252 for ( sal_uInt32 k = 0; k < pNode->m_aGroupedLeaves[j].size(); ++k )
2254 OptionsLeaf* pLeaf = pNode->m_aGroupedLeaves[j][k];
2255 lcl_insertLeaf( this, pNode, pLeaf, aTreeLB );
2259 for ( j = 0; j < pNode->m_aLeaves.size(); ++j )
2261 OptionsLeaf* pLeaf = pNode->m_aLeaves[j];
2262 lcl_insertLeaf( this, pNode, pLeaf, aTreeLB );
2268 short OfaTreeOptionsDialog::Execute()
2270 boost::scoped_ptr< SvxDicListChgClamp > pClamp;
2271 if ( !bIsFromExtensionManager )
2273 // collect all DictionaryList Events while the dialog is executed
2274 Reference<com::sun::star::linguistic2::XSearchableDictionaryList> xDictionaryList(SvxGetDictionaryList());
2275 pClamp.reset( new SvxDicListChgClamp( xDictionaryList ) );
2277 short nRet = SfxModalDialog::Execute();
2279 if( RET_OK == nRet )
2281 ApplyItemSets();
2282 if( mpColorPage )
2283 mpColorPage->SaveToViewFrame( SfxViewFrame::Current() );
2284 utl::ConfigManager::storeConfigItems();
2287 return nRet;
2290 // class ExtensionsTabPage -----------------------------------------------
2292 ExtensionsTabPage::ExtensionsTabPage(
2293 Window* pParent, WinBits nStyle, const OUString& rPageURL,
2294 const OUString& rEvtHdl, const Reference< awt::XContainerWindowProvider >& rProvider ) :
2296 TabPage( pParent, nStyle ),
2298 m_sPageURL ( rPageURL ),
2299 m_sEventHdl ( rEvtHdl ),
2300 m_xWinProvider ( rProvider ),
2301 m_bIsWindowHidden ( false )
2308 ExtensionsTabPage::~ExtensionsTabPage()
2310 Hide();
2311 DeactivatePage();
2313 if ( m_xPage.is() )
2315 Reference< XComponent > xComponent( m_xPage, UNO_QUERY );
2316 if ( xComponent.is() )
2320 xComponent->dispose();
2322 catch ( const Exception & )
2326 m_xPage.clear();
2332 void ExtensionsTabPage::CreateDialogWithHandler()
2336 bool bWithHandler = ( !m_sEventHdl.isEmpty() );
2337 if ( bWithHandler )
2339 Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
2340 m_xEventHdl = Reference< awt::XContainerWindowEventHandler >(
2341 xFactory->createInstance( m_sEventHdl ), UNO_QUERY );
2344 if ( !bWithHandler || m_xEventHdl.is() )
2346 SetStyle( GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
2347 Reference< awt::XWindowPeer > xParent( VCLUnoHelper::GetInterface( this ), UNO_QUERY );
2348 m_xPage = Reference < awt::XWindow >(
2349 m_xWinProvider->createContainerWindow(
2350 m_sPageURL, OUString(), xParent, m_xEventHdl ), UNO_QUERY );
2352 Reference< awt::XControl > xPageControl( m_xPage, UNO_QUERY );
2353 if ( xPageControl.is() )
2355 Reference< awt::XWindowPeer > xWinPeer( xPageControl->getPeer() );
2356 if ( xWinPeer.is() )
2358 Window* pWindow = VCLUnoHelper::GetWindow( xWinPeer );
2359 if ( pWindow )
2360 pWindow->SetStyle( pWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
2365 catch ( ::com::sun::star::lang::IllegalArgumentException& )
2367 SAL_WARN( "cui.options", "ExtensionsTabPage::CreateDialogWithHandler(): illegal argument" );
2369 catch ( Exception& )
2371 SAL_WARN( "cui.options", "ExtensionsTabPage::CreateDialogWithHandler(): exception of XDialogProvider2::createDialogWithHandler()" );
2377 bool ExtensionsTabPage::DispatchAction( const OUString& rAction )
2379 bool bRet = false;
2380 if ( m_xEventHdl.is() )
2384 bRet = m_xEventHdl->callHandlerMethod( m_xPage, makeAny( rAction ), "external_event" );
2386 catch ( Exception& )
2388 SAL_WARN( "cui.options", "ExtensionsTabPage::DispatchAction(): exception of XDialogEventHandler::callHandlerMethod()" );
2391 return bRet;
2396 void ExtensionsTabPage::ActivatePage()
2398 TabPage::ActivatePage();
2400 if ( !m_xPage.is() )
2402 CreateDialogWithHandler();
2404 if ( m_xPage.is() )
2406 Point aPos = Point();
2407 Size aSize = GetSizePixel();
2408 m_xPage->setPosSize( aPos.X() + 1, aPos.Y() + 1,
2409 aSize.Width() - 2, aSize.Height() - 2, awt::PosSize::POSSIZE );
2410 if ( !m_sEventHdl.isEmpty() )
2411 DispatchAction( "initialize" );
2415 if ( m_xPage.is() )
2417 m_xPage->setVisible( sal_True );
2418 m_bIsWindowHidden = false;
2424 void ExtensionsTabPage::DeactivatePage()
2426 TabPage::DeactivatePage();
2428 if ( m_xPage.is() )
2429 m_xPage->setVisible( sal_False );
2434 void ExtensionsTabPage::ResetPage()
2436 DispatchAction( "back" );
2437 ActivatePage();
2442 void ExtensionsTabPage::SavePage()
2444 DispatchAction( "ok" );
2447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */