Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cui / source / options / treeopt.cxx
blobd3c65eb0c847487c3bfd18e6431b834e32453734
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 <memory>
21 #include <string_view>
23 #include <config_features.h>
24 #include <config_feature_opencl.h>
25 #include <config_feature_desktop.h>
26 #include <config_gpgme.h>
28 #include <officecfg/Office/Common.hxx>
29 #include <officecfg/Office/Writer.hxx>
31 #include <svx/dialogs.hrc>
32 #include <svx/svxids.hrc>
34 #include <treeopt.hrc>
35 #include <helpids.h>
37 #include "cfgchart.hxx"
38 #include "connpoolconfig.hxx"
39 #include "connpooloptions.hxx"
40 #include <cuioptgenrl.hxx>
41 #include <dbregister.hxx>
42 #include "dbregisterednamesconfig.hxx"
43 #include <dialmgr.hxx>
44 #include "fontsubs.hxx"
45 #include "optaccessibility.hxx"
46 #include <optasian.hxx>
47 #include "optchart.hxx"
48 #include "optcolor.hxx"
49 #include "optctl.hxx"
50 #include "optfltr.hxx"
51 #include "optgdlg.hxx"
52 #include "opthtml.hxx"
53 #include "optinet2.hxx"
54 #include "optjava.hxx"
55 #include "optjsearch.hxx"
56 #include <optlingu.hxx>
57 #if HAVE_FEATURE_OPENCL
58 #include "optopencl.hxx"
59 #endif
60 #include <optpath.hxx>
61 #include "optsave.hxx"
62 #include "optupdt.hxx"
63 #include "personalization.hxx"
64 #include <treeopt.hxx>
65 #include "optbasic.hxx"
66 #include "optlanguagetool.hxx"
67 #include "optdeepl.hxx"
69 #include <com/sun/star/awt/XContainerWindowEventHandler.hpp>
70 #include <com/sun/star/awt/ContainerWindowProvider.hpp>
71 #include <com/sun/star/awt/XControl.hpp>
72 #include <com/sun/star/awt/PosSize.hpp>
73 #include <com/sun/star/frame/Desktop.hpp>
74 #include <com/sun/star/frame/ModuleManager.hpp>
75 #include <com/sun/star/frame/UnknownModuleException.hpp>
76 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
77 #include <com/sun/star/linguistic2/LinguProperties.hpp>
78 #include <com/sun/star/setup/UpdateCheck.hpp>
79 #include <comphelper/getexpandeduri.hxx>
80 #include <comphelper/processfactory.hxx>
81 #include <editeng/langitem.hxx>
82 #include <editeng/optitems.hxx>
83 #include <editeng/unolingu.hxx>
84 #include <linguistic/misc.hxx>
85 #include <officecfg/Office/OptionsDialog.hxx>
86 #include <sfx2/app.hxx>
87 #include <sfx2/dispatch.hxx>
88 #include <sfx2/module.hxx>
89 #include <sfx2/printopt.hxx>
90 #include <sfx2/shell.hxx>
91 #include <sfx2/viewsh.hxx>
92 #include <sfx2/viewfrm.hxx>
93 #include <svl/flagitem.hxx>
94 #include <svl/intitem.hxx>
95 #include <svl/cjkoptions.hxx>
96 #include <svl/ctloptions.hxx>
97 #include <svx/databaseregistrationui.hxx>
98 #include <toolkit/helper/vclunohelper.hxx>
99 #include <tools/urlobj.hxx>
100 #include <comphelper/diagnose_ex.hxx>
101 #include <unotools/configmgr.hxx>
102 #include <unotools/moduleoptions.hxx>
103 #include <unotools/optionsdlg.hxx>
104 #include <unotools/viewoptions.hxx>
105 #include <utility>
106 #include <vcl/help.hxx>
107 #include <vcl/svapp.hxx>
108 #include <vcl/weldutils.hxx>
109 #include <vcl/window.hxx>
110 #include <sal/log.hxx>
112 using namespace ::com::sun::star;
113 using namespace ::com::sun::star::beans;
114 using namespace ::com::sun::star::container;
115 using namespace ::com::sun::star::frame;
116 using namespace ::com::sun::star::lang;
117 using namespace ::com::sun::star::linguistic2;
118 using namespace ::com::sun::star::uno;
119 using namespace ::com::sun::star::util;
121 LastPageSaver* OfaTreeOptionsDialog::pLastPageSaver = nullptr;
123 // some stuff for easier changes for SvtViewOptions
124 constexpr OUStringLiteral VIEWOPT_DATANAME = u"page data";
126 static void SetViewOptUserItem( SvtViewOptions& rOpt, const OUString& rData )
128 rOpt.SetUserItem( VIEWOPT_DATANAME, Any( rData ) );
131 static OUString GetViewOptUserItem( const SvtViewOptions& rOpt )
133 Any aAny( rOpt.GetUserItem( VIEWOPT_DATANAME ) );
134 OUString aUserData;
135 aAny >>= aUserData;
137 return aUserData;
140 namespace {
142 struct ModuleToGroupNameMap_Impl
144 std::u16string_view m_pModule;
145 OUString m_sGroupName;
146 sal_uInt16 m_nNodeId;
150 static ModuleToGroupNameMap_Impl ModuleMap[] =
152 { u"ProductName", OUString(), SID_GENERAL_OPTIONS },
153 { u"LanguageSettings", OUString(), SID_LANGUAGE_OPTIONS },
154 { u"Internet", OUString(), SID_INET_DLG },
155 { u"LoadSave", OUString(), SID_FILTER_DLG },
156 { u"Writer", OUString(), SID_SW_EDITOPTIONS },
157 { u"WriterWeb", OUString(), SID_SW_ONLINEOPTIONS },
158 { u"Math", OUString(), SID_SM_EDITOPTIONS },
159 { u"Calc", OUString(), SID_SC_EDITOPTIONS },
160 { u"Impress", OUString(), SID_SD_EDITOPTIONS },
161 { u"Draw", OUString(), SID_SD_GRAPHIC_OPTIONS },
162 { u"Charts", OUString(), SID_SCH_EDITOPTIONS },
163 { u"Base", OUString(), SID_SB_STARBASEOPTIONS },
166 static void setGroupName( std::u16string_view rModule, const OUString& rGroupName )
168 for (ModuleToGroupNameMap_Impl& rEntry : ModuleMap)
170 if ( rEntry.m_pModule == rModule )
172 rEntry.m_sGroupName = rGroupName;
173 break;
178 static OUString getGroupName( std::u16string_view rModule, bool bForced )
180 OUString sGroupName;
181 for (const ModuleToGroupNameMap_Impl& rEntry : ModuleMap)
183 if ( rEntry.m_pModule == rModule )
185 sGroupName = rEntry.m_sGroupName;
186 break;
190 if ( sGroupName.isEmpty() && bForced )
192 if ( rModule == u"Writer" )
193 sGroupName = CuiResId(SID_SW_EDITOPTIONS_RES[0].first);
194 else if ( rModule == u"WriterWeb" )
195 sGroupName = CuiResId(SID_SW_ONLINEOPTIONS_RES[0].first);
196 else if ( rModule == u"Calc" )
197 sGroupName = CuiResId(SID_SC_EDITOPTIONS_RES[0].first);
198 else if ( rModule == u"Impress" )
199 sGroupName = CuiResId(SID_SD_EDITOPTIONS_RES[0].first);
200 else if ( rModule == u"Draw" )
201 sGroupName = CuiResId(SID_SD_GRAPHIC_OPTIONS_RES[0].first);
202 else if ( rModule == u"Math" )
203 sGroupName = CuiResId(SID_SM_EDITOPTIONS_RES[0].first);
204 else if ( rModule == u"Base" )
205 sGroupName = CuiResId(SID_SB_STARBASEOPTIONS_RES[0].first);
207 return sGroupName;
210 static void deleteGroupNames()
212 for (ModuleToGroupNameMap_Impl& rEntry : ModuleMap)
213 rEntry.m_sGroupName.clear();
216 static sal_uInt16 getGroupNodeId( std::u16string_view rModule )
218 sal_uInt16 nNodeId = 0xFFFF;
219 for (const ModuleToGroupNameMap_Impl& rEntry : ModuleMap)
221 if ( rEntry.m_pModule == rModule )
223 nNodeId = rEntry.m_nNodeId;
224 break;
228 return nNodeId;
231 namespace {
233 bool MailMergeCfgIsEmailSupported()
235 std::optional<bool> b = officecfg::Office::Writer::MailMergeWizard::EMailSupported::get();
236 return b && *b;
241 //typedef SfxTabPage* (*FNCreateTabPage)(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rAttrSet);
242 static std::unique_ptr<SfxTabPage> CreateGeneralTabPage(sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
244 CreateTabPage fnCreate = nullptr;
245 switch(nId)
247 case RID_SFXPAGE_SAVE: fnCreate = &SvxSaveTabPage::Create; break;
248 case RID_SFXPAGE_PATH: fnCreate = &SvxPathTabPage::Create; break;
249 case RID_SFXPAGE_GENERAL: fnCreate = &SvxGeneralTabPage::Create; break;
250 case RID_SFXPAGE_PRINTOPTIONS: fnCreate = &SfxCommonPrintOptionsTabPage::Create; break;
251 case OFA_TP_LANGUAGES: fnCreate = &OfaLanguagesTabPage::Create; break;
252 case RID_SFXPAGE_LINGU: fnCreate = &SvxLinguTabPage::Create; break;
253 case OFA_TP_VIEW: fnCreate = &OfaViewTabPage::Create; break;
254 case OFA_TP_MISC: fnCreate = &OfaMiscTabPage::Create; break;
255 case RID_SVXPAGE_ASIAN_LAYOUT: fnCreate = &SvxAsianLayoutPage::Create; break;
256 case RID_SVX_FONT_SUBSTITUTION: fnCreate = &SvxFontSubstTabPage::Create; break;
257 case RID_SVXPAGE_INET_PROXY: fnCreate = &SvxProxyTabPage::Create; break;
258 case RID_SVXPAGE_INET_SECURITY: fnCreate = &SvxSecurityTabPage::Create; break;
259 case RID_SVXPAGE_INET_MAIL: fnCreate = &SvxEMailTabPage::Create; break;
260 #if HAVE_FEATURE_DESKTOP
261 case RID_SVXPAGE_PERSONALIZATION: fnCreate = &SvxPersonalizationTabPage::Create; break;
262 #endif
263 case RID_SVXPAGE_COLORCONFIG: fnCreate = &SvxColorOptionsTabPage::Create; break;
264 case RID_OFAPAGE_HTMLOPT: fnCreate = &OfaHtmlTabPage::Create; break;
265 case SID_OPTFILTER_MSOFFICE: fnCreate = &OfaMSFilterTabPage::Create; break;
266 case RID_OFAPAGE_MSFILTEROPT2: fnCreate = &OfaMSFilterTabPage2::Create; break;
267 case RID_SVXPAGE_JSEARCH_OPTIONS: fnCreate = &SvxJSearchOptionsPage::Create ; break;
268 case SID_SB_CONNECTIONPOOLING: fnCreate = &::offapp::ConnectionPoolOptionsPage::Create; break;
269 case SID_SB_DBREGISTEROPTIONS: fnCreate = &svx::DbRegistrationOptionsPage::Create; break;
270 case RID_SVXPAGE_ACCESSIBILITYCONFIG: fnCreate = &SvxAccessibilityOptionsTabPage::Create; break;
271 case RID_SVXPAGE_OPTIONS_CTL: fnCreate = &SvxCTLOptionsPage::Create ; break;
272 case RID_SVXPAGE_LANGTOOL_OPTIONS: fnCreate = &OptLanguageToolTabPage::Create ; break;
273 case RID_SVXPAGE_DEEPL_OPTIONS: fnCreate = &OptDeeplTabPage::Create ; break;
274 case RID_SVXPAGE_OPTIONS_JAVA: fnCreate = &SvxJavaOptionsPage::Create ; break;
275 #if HAVE_FEATURE_OPENCL
276 case RID_SVXPAGE_OPENCL: fnCreate = &SvxOpenCLTabPage::Create ; break;
277 #endif
278 case RID_SVXPAGE_ONLINEUPDATE: fnCreate = &SvxOnlineUpdateTabPage::Create; break;
279 case RID_OPTPAGE_CHART_DEFCOLORS: fnCreate = &SvxDefaultColorOptPage::Create; break;
280 #if HAVE_FEATURE_SCRIPTING
281 case RID_SVXPAGE_BASICIDE_OPTIONS: fnCreate = &SvxBasicIDEOptionsPage::Create; break;
282 #endif
285 return fnCreate ? (*fnCreate)( pPage, pController, &rSet ) : nullptr;
288 namespace {
290 struct OptionsMapping_Impl
292 const char* m_pGroupName;
293 const char* m_pPageName;
294 sal_uInt16 m_nPageId;
299 OptionsMapping_Impl const OptionsMap_Impl[] =
301 // GROUP PAGE PAGE-ID
302 { "ProductName", nullptr, SID_GENERAL_OPTIONS },
303 { "ProductName", "UserData", RID_SFXPAGE_GENERAL },
304 { "ProductName", "General", OFA_TP_MISC },
305 { "ProductName", "View", OFA_TP_VIEW },
306 { "ProductName", "Print", RID_SFXPAGE_PRINTOPTIONS },
307 { "ProductName", "Paths", RID_SFXPAGE_PATH },
308 { "ProductName", "Fonts", RID_SVX_FONT_SUBSTITUTION },
309 { "ProductName", "Security", RID_SVXPAGE_INET_SECURITY },
310 { "ProductName", "Personalization", RID_SVXPAGE_PERSONALIZATION },
311 { "ProductName", "Appearance", RID_SVXPAGE_COLORCONFIG },
312 { "ProductName", "Accessibility", RID_SVXPAGE_ACCESSIBILITYCONFIG },
313 { "ProductName", "Java", RID_SVXPAGE_OPTIONS_JAVA },
314 { "ProductName", "BasicIDEOptions", RID_SVXPAGE_BASICIDE_OPTIONS },
315 { "ProductName", "OnlineUpdate", RID_SVXPAGE_ONLINEUPDATE },
316 { "LanguageSettings", nullptr, SID_LANGUAGE_OPTIONS },
317 { "LanguageSettings", "Languages", OFA_TP_LANGUAGES },
318 { "LanguageSettings", "WritingAids", RID_SFXPAGE_LINGU },
319 { "LanguageSettings", "SearchingInJapanese", RID_SVXPAGE_JSEARCH_OPTIONS },
320 { "LanguageSettings", "AsianLayout", RID_SVXPAGE_ASIAN_LAYOUT },
321 { "LanguageSettings", "ComplexTextLayout", RID_SVXPAGE_OPTIONS_CTL },
322 { "Internet", nullptr, SID_INET_DLG },
323 { "Internet", "Proxy", RID_SVXPAGE_INET_PROXY },
324 { "Internet", "Email", RID_SVXPAGE_INET_MAIL },
325 { "LoadSave", nullptr, SID_FILTER_DLG },
326 { "LoadSave", "General", RID_SFXPAGE_SAVE },
327 { "LoadSave", "VBAProperties", SID_OPTFILTER_MSOFFICE },
328 { "LoadSave", "MicrosoftOffice", RID_OFAPAGE_MSFILTEROPT2 },
329 { "LoadSave", "HTMLCompatibility", RID_OFAPAGE_HTMLOPT },
330 { "Writer", nullptr, SID_SW_EDITOPTIONS },
331 { "Writer", "General", RID_SW_TP_OPTLOAD_PAGE },
332 { "Writer", "View", RID_SW_TP_CONTENT_OPT },
333 { "Writer", "FormattingAids", RID_SW_TP_OPTSHDWCRSR },
334 { "Writer", "Grid", RID_SVXPAGE_GRID },
335 { "Writer", "BasicFontsWestern", RID_SW_TP_STD_FONT },
336 { "Writer", "BasicFontsAsian", RID_SW_TP_STD_FONT_CJK },
337 { "Writer", "BasicFontsCTL", RID_SW_TP_STD_FONT_CTL },
338 { "Writer", "Print", RID_SW_TP_OPTPRINT_PAGE },
339 { "Writer", "Table", RID_SW_TP_OPTTABLE_PAGE },
340 { "Writer", "Changes", RID_SW_TP_REDLINE_OPT },
341 { "Writer", "Comparison", RID_SW_TP_COMPARISON_OPT },
342 { "Writer", "Compatibility", RID_SW_TP_OPTCOMPATIBILITY_PAGE },
343 { "Writer", "AutoCaption", RID_SW_TP_OPTCAPTION_PAGE },
344 { "Writer", "MailMerge", RID_SW_TP_MAILCONFIG },
345 { "WriterWeb", nullptr, SID_SW_ONLINEOPTIONS },
346 { "WriterWeb", "View", RID_SW_TP_HTML_CONTENT_OPT },
347 { "WriterWeb", "FormattingAids", RID_SW_TP_HTML_OPTSHDWCRSR },
348 { "WriterWeb", "Grid", RID_SW_TP_HTML_OPTGRID_PAGE },
349 { "WriterWeb", "Print", RID_SW_TP_HTML_OPTPRINT_PAGE },
350 { "WriterWeb", "Table", RID_SW_TP_HTML_OPTTABLE_PAGE },
351 { "WriterWeb", "Background", RID_SW_TP_BACKGROUND },
352 { "Math", nullptr, SID_SM_EDITOPTIONS },
353 { "Math", "Settings", SID_SM_TP_PRINTOPTIONS },
354 { "Calc", nullptr, SID_SC_EDITOPTIONS },
355 { "Calc", "General", SID_SC_TP_LAYOUT },
356 { "Calc", "View", SID_SC_TP_CONTENT },
357 { "Calc", "Calculate", SID_SC_TP_CALC },
358 { "Calc", "Formula", SID_SC_TP_FORMULA },
359 { "Calc", "SortLists", SID_SC_TP_USERLISTS },
360 { "Calc", "Changes", SID_SC_TP_CHANGES },
361 { "Calc", "Compatibility", SID_SC_TP_COMPATIBILITY },
362 { "Calc", "Grid", SID_SC_TP_GRID },
363 { "Calc", "Print", RID_SC_TP_PRINT },
364 { "Impress", nullptr, SID_SD_EDITOPTIONS },
365 { "Impress", "General", SID_SI_TP_MISC },
366 { "Impress", "View", SID_SI_TP_CONTENTS },
367 { "Impress", "Grid", SID_SI_TP_SNAP },
368 { "Impress", "Print", SID_SI_TP_PRINT },
369 { "Draw", nullptr, SID_SD_GRAPHIC_OPTIONS },
370 { "Draw", "General", SID_SD_TP_MISC },
371 { "Draw", "View", SID_SD_TP_CONTENTS },
372 { "Draw", "Grid", SID_SD_TP_SNAP },
373 { "Draw", "Print", SID_SD_TP_PRINT },
374 { "Charts", nullptr, SID_SCH_EDITOPTIONS },
375 { "Charts", "DefaultColors", RID_OPTPAGE_CHART_DEFCOLORS },
376 { "Base", nullptr, SID_SB_STARBASEOPTIONS },
377 { "Base", "Connections", SID_SB_CONNECTIONPOOLING },
378 { "Base", "Databases", SID_SB_DBREGISTEROPTIONS },
379 { nullptr, nullptr, 0 }
382 static bool lcl_getStringFromID( sal_uInt16 _nPageId, OUString& _rGroupName, OUString& _rPageName )
384 bool bRet = false;
386 sal_uInt16 nIdx = 0;
387 while ( OptionsMap_Impl[nIdx].m_pGroupName != nullptr )
389 if ( _nPageId == OptionsMap_Impl[nIdx].m_nPageId )
391 bRet = true;
392 _rGroupName = OUString::createFromAscii( OptionsMap_Impl[nIdx].m_pGroupName );
393 if ( OptionsMap_Impl[nIdx].m_pPageName != nullptr )
394 _rPageName = OUString::createFromAscii( OptionsMap_Impl[nIdx].m_pPageName );
395 break;
397 ++nIdx;
400 return bRet;
403 static bool lcl_isOptionHidden( sal_uInt16 _nPageId, const SvtOptionsDialogOptions& _rOptOptions )
405 bool bIsHidden = false;
406 OUString sGroupName, sPageName;
407 if ( lcl_getStringFromID( _nPageId, sGroupName, sPageName ) )
409 if ( sPageName.isEmpty() )
410 bIsHidden = _rOptOptions.IsGroupHidden( sGroupName );
411 else
412 bIsHidden = _rOptOptions.IsPageHidden( sPageName, sGroupName );
414 return bIsHidden;
417 struct OptionsPageInfo
419 std::unique_ptr<SfxTabPage> m_xPage;
420 sal_uInt16 m_nPageId;
421 OUString m_sPageURL;
422 OUString m_sEventHdl;
423 std::unique_ptr<ExtensionsTabPage> m_xExtPage;
425 explicit OptionsPageInfo( sal_uInt16 nId ) : m_nPageId( nId ) {}
428 struct OptionsGroupInfo
430 std::optional<SfxItemSet> m_pInItemSet;
431 std::unique_ptr<SfxItemSet> m_pOutItemSet;
432 SfxShell* m_pShell; // used to create the page
433 SfxModule* m_pModule; // used to create the ItemSet
434 sal_uInt16 m_nDialogId; // Id of the former dialog
436 OptionsGroupInfo( SfxShell* pSh, SfxModule* pMod, sal_uInt16 nId ) :
437 m_pShell( pSh ),
438 m_pModule( pMod ), m_nDialogId( nId ) {}
441 // Basic ctor with common initialization
442 OfaTreeOptionsDialog::OfaTreeOptionsDialog(weld::Window* pParent, bool fromExtensionManager)
443 : SfxOkDialogController(pParent, "cui/ui/optionsdialog.ui", "OptionsDialog")
444 , xOkPB(m_xBuilder->weld_button("ok"))
445 , xApplyPB(m_xBuilder->weld_button("apply"))
446 , xBackPB(m_xBuilder->weld_button("revert"))
447 , xTreeLB(m_xBuilder->weld_tree_view("pages"))
448 , xTabBox(m_xBuilder->weld_container("box"))
449 , m_pParent(pParent)
450 , sTitle(m_xDialog->get_title())
451 , bForgetSelection(false)
452 , bIsFromExtensionManager(fromExtensionManager)
453 , bIsForSetDocumentLanguage(false)
454 , bNeedsRestart(false)
455 , eRestartReason(svtools::RESTART_REASON_NONE)
457 Size aSize(xTreeLB->get_approximate_digit_width() * 82, xTreeLB->get_height_rows(30));
458 #if HAVE_FEATURE_GPGME
459 // tdf#115015: make enough space for crypto settings (approx. 14 text edits + padding)
460 aSize.setHeight((weld::GetMinimumEditHeight() + 6) * 14);
461 #endif
462 xTabBox->set_size_request(aSize.Width(), aSize.Height());
463 xTreeLB->set_size_request(xTreeLB->get_approximate_digit_width() * 35, aSize.Height());
465 // Init tree and handler
466 xTreeLB->set_help_id(HID_OFADLG_TREELISTBOX);
467 xTreeLB->connect_changed(LINK(this, OfaTreeOptionsDialog, ShowPageHdl_Impl));
468 xBackPB->connect_clicked(LINK(this, OfaTreeOptionsDialog, BackHdl_Impl));
469 xApplyPB->connect_clicked(LINK(this, OfaTreeOptionsDialog, ApplyHdl_Impl));
470 xOkPB->connect_clicked(LINK(this, OfaTreeOptionsDialog, ApplyHdl_Impl));
471 m_xDialog->connect_help(LINK(this, OfaTreeOptionsDialog, HelpHdl_Impl));
473 xTreeLB->set_accessible_name(sTitle);
476 // Ctor() with Frame -----------------------------------------------------
477 OfaTreeOptionsDialog::OfaTreeOptionsDialog(weld::Window* pParent, const Reference< XFrame >& _xFrame, bool bActivateLastSelection)
478 : OfaTreeOptionsDialog(pParent, false)
480 Initialize( _xFrame );
481 LoadExtensionOptions( u"" );
482 if (bActivateLastSelection)
483 ActivateLastSelection();
486 // Ctor() with ExtensionId -----------------------------------------------
487 OfaTreeOptionsDialog::OfaTreeOptionsDialog(weld::Window* pParent, std::u16string_view rExtensionId)
488 : OfaTreeOptionsDialog(pParent, !rExtensionId.empty())
490 LoadExtensionOptions( rExtensionId );
491 ActivateLastSelection();
494 OfaTreeOptionsDialog::~OfaTreeOptionsDialog()
496 xCurrentPageEntry.reset();
498 std::unique_ptr<weld::TreeIter> xEntry = xTreeLB->make_iterator();
499 bool bEntry = xTreeLB->get_iter_first(*xEntry);
500 // first children
501 while (bEntry)
503 // if Child (has parent), then OptionsPageInfo
504 if (xTreeLB->get_iter_depth(*xEntry))
506 OptionsPageInfo *pPageInfo = weld::fromId<OptionsPageInfo*>(xTreeLB->get_id(*xEntry));
507 if(pPageInfo->m_xPage)
509 pPageInfo->m_xPage->FillUserData();
510 OUString aPageData(pPageInfo->m_xPage->GetUserData());
511 if ( !aPageData.isEmpty() )
513 SvtViewOptions aTabPageOpt( EViewType::TabPage, OUString::number( pPageInfo->m_nPageId) );
514 SetViewOptUserItem( aTabPageOpt, aPageData );
516 pPageInfo->m_xPage.reset();
519 if (pPageInfo->m_nPageId == RID_SFXPAGE_LINGU)
521 // write personal dictionaries
522 Reference< XSearchableDictionaryList > xDicList( LinguMgr::GetDictionaryList() );
523 if (xDicList.is())
525 linguistic::SaveDictionaries( xDicList );
529 pPageInfo->m_xExtPage.reset();
531 delete pPageInfo;
533 bEntry = xTreeLB->iter_next(*xEntry);
536 // and parents
537 bEntry = xTreeLB->get_iter_first(*xEntry);
538 while (bEntry)
540 if (!xTreeLB->get_iter_depth(*xEntry))
542 OptionsGroupInfo* pGroupInfo = weld::fromId<OptionsGroupInfo*>(xTreeLB->get_id(*xEntry));
543 delete pGroupInfo;
545 bEntry = xTreeLB->iter_next(*xEntry);
547 deleteGroupNames();
550 OptionsPageInfo* OfaTreeOptionsDialog::AddTabPage(
551 sal_uInt16 nId, const OUString& rPageName, sal_uInt16 nGroup )
553 std::unique_ptr<weld::TreeIter> xParent = xTreeLB->make_iterator();
554 if (!xTreeLB->get_iter_first(*xParent))
555 return nullptr;
556 xTreeLB->iter_nth_sibling(*xParent, nGroup);
558 OptionsPageInfo* pPageInfo = new OptionsPageInfo( nId );
559 OUString sId(weld::toId(pPageInfo));
560 xTreeLB->insert(xParent.get(), -1, &rPageName, &sId, nullptr, nullptr, false, nullptr);
561 return pPageInfo;
564 // the ItemSet* is passed on to the dialog's ownership
565 sal_uInt16 OfaTreeOptionsDialog::AddGroup(const OUString& rGroupName,
566 SfxShell* pCreateShell,
567 SfxModule* pCreateModule,
568 sal_uInt16 nDialogId )
570 OptionsGroupInfo* pInfo =
571 new OptionsGroupInfo( pCreateShell, pCreateModule, nDialogId );
572 OUString sId(weld::toId(pInfo));
573 xTreeLB->append(sId, rGroupName);
575 sal_uInt16 nRet = 0;
576 std::unique_ptr<weld::TreeIter> xEntry = xTreeLB->make_iterator();
577 bool bEntry = xTreeLB->get_iter_first(*xEntry);
578 while (bEntry)
580 if (!xTreeLB->get_iter_depth(*xEntry))
581 nRet++;
582 bEntry = xTreeLB->iter_next(*xEntry);
584 return nRet - 1;
587 IMPL_LINK_NOARG(OfaTreeOptionsDialog, ShowPageHdl_Impl, weld::TreeView&, void)
589 SelectHdl_Impl();
592 void OfaTreeOptionsDialog::ResetCurrentPageFromConfig()
594 if (!(xCurrentPageEntry && xTreeLB->get_iter_depth(*xCurrentPageEntry)))
595 return;
597 OptionsPageInfo* pPageInfo = weld::fromId<OptionsPageInfo*>(xTreeLB->get_id(*xCurrentPageEntry));
598 if (pPageInfo->m_xPage)
600 std::unique_ptr<weld::TreeIter> xParent = xTreeLB->make_iterator(xCurrentPageEntry.get());
601 xTreeLB->iter_parent(*xParent);
602 OptionsGroupInfo* pGroupInfo =
603 weld::fromId<OptionsGroupInfo*>(xTreeLB->get_id(*xParent));
604 pPageInfo->m_xPage->Reset( &*pGroupInfo->m_pInItemSet );
606 else if ( pPageInfo->m_xExtPage )
607 pPageInfo->m_xExtPage->ResetPage();
610 IMPL_LINK_NOARG(OfaTreeOptionsDialog, BackHdl_Impl, weld::Button&, void)
612 ResetCurrentPageFromConfig();
615 void OfaTreeOptionsDialog::ApplyOptions()
617 std::unique_ptr<weld::TreeIter> xEntry = xTreeLB->make_iterator();
618 bool bEntry = xTreeLB->get_iter_first(*xEntry);
619 while (bEntry)
621 if (xTreeLB->get_iter_depth(*xEntry))
623 OptionsPageInfo* pPageInfo = weld::fromId<OptionsPageInfo*>(xTreeLB->get_id(*xEntry));
624 if ( pPageInfo->m_xPage && !pPageInfo->m_xPage->HasExchangeSupport() )
626 std::unique_ptr<weld::TreeIter> xParent = xTreeLB->make_iterator(xEntry.get());
627 xTreeLB->iter_parent(*xParent);
628 OptionsGroupInfo* pGroupInfo =
629 weld::fromId<OptionsGroupInfo*>(xTreeLB->get_id(*xParent));
630 pPageInfo->m_xPage->FillItemSet(pGroupInfo->m_pOutItemSet.get());
633 if ( pPageInfo->m_xExtPage )
635 pPageInfo->m_xExtPage->DeactivatePage();
636 pPageInfo->m_xExtPage->SavePage();
638 if ( pPageInfo->m_xPage && RID_OPTPAGE_CHART_DEFCOLORS == pPageInfo->m_nPageId )
640 SvxDefaultColorOptPage* pPage = static_cast<SvxDefaultColorOptPage *>(pPageInfo->m_xPage.get());
641 pPage->SaveChartOptions();
644 bEntry = xTreeLB->iter_next(*xEntry);
648 IMPL_LINK_NOARG(OfaTreeOptionsDialog, HelpHdl_Impl, weld::Widget&, bool)
650 Help* pHelp = Application::GetHelp();
651 if (pHelp && xCurrentPageEntry && xTreeLB->get_iter_depth(*xCurrentPageEntry))
653 OptionsPageInfo* pPageInfo = weld::fromId<OptionsPageInfo*>(xTreeLB->get_id(*xCurrentPageEntry));
654 if (pPageInfo->m_xPage)
656 OUString sHelpId(pPageInfo->m_xPage->GetHelpId());
657 pHelp->Start(sHelpId, m_xDialog.get());
658 return false;
661 return true;
664 IMPL_LINK(OfaTreeOptionsDialog, ApplyHdl_Impl, weld::Button&, rButton, void)
666 bool bOkPressed = &rButton == xOkPB.get();
668 OptionsGroupInfo* pGroupInfo = nullptr;
670 if (xCurrentPageEntry && xTreeLB->get_iter_depth(*xCurrentPageEntry))
672 OptionsPageInfo* pPageInfo = weld::fromId<OptionsPageInfo*>(xTreeLB->get_id(*xCurrentPageEntry));
673 if ( pPageInfo->m_xPage )
675 std::unique_ptr<weld::TreeIter> xParent = xTreeLB->make_iterator(xCurrentPageEntry.get());
676 xTreeLB->iter_parent(*xParent);
678 pGroupInfo = weld::fromId<OptionsGroupInfo*>(xTreeLB->get_id(*xParent));
679 if ( RID_SVXPAGE_COLOR != pPageInfo->m_nPageId
680 && pPageInfo->m_xPage->HasExchangeSupport() )
682 DeactivateRC nLeave = pPageInfo->m_xPage->DeactivatePage(pGroupInfo->m_pOutItemSet.get());
683 if ( nLeave == DeactivateRC::KeepPage )
685 // the page mustn't be left, so return early
686 assert(xTreeLB->is_selected(*xCurrentPageEntry)); // presumably this must be true here
687 if (bOkPressed)
688 return;
694 ApplyOptions();
695 ApplyItemSets();
696 utl::ConfigManager::storeConfigItems();
698 if (bOkPressed)
699 m_xDialog->response(RET_OK);
700 else
702 // tdf#137930 rebuild the in and out itemsets to reflect the current
703 // post-apply state
704 if (pGroupInfo && pGroupInfo->m_pInItemSet)
706 // tdf#138596 seeing as the SfxTabPages keep pointers to the m_pInItemSet
707 // we update the contents of the existing SfxItemSets to match
708 // the current settings, rather than create new ones
709 auto xInItemSet = pGroupInfo->m_pShell
710 ? pGroupInfo->m_pShell->CreateItemSet( pGroupInfo->m_nDialogId )
711 : CreateItemSet( pGroupInfo->m_nDialogId );
712 pGroupInfo->m_pInItemSet->Set(*xInItemSet, false);
713 pGroupInfo->m_pOutItemSet->ClearItem();
716 // for the Apply case, now that the settings are saved to config,
717 // reload the current page so it knows what the config now states
718 ResetCurrentPageFromConfig();
719 // reselect it to undo possible DeactivatePage above
720 xCurrentPageEntry.reset();
721 SelectHdl_Impl();
724 if (!bNeedsRestart)
725 return;
727 SolarMutexGuard aGuard;
728 weld::Window* pParent;
729 if (!bOkPressed)
730 pParent = m_xDialog.get();
731 else
733 m_xDialog->hide();
734 pParent = m_pParent;
736 bool bRestart = ::svtools::executeRestartDialog(comphelper::getProcessComponentContext(),
737 pParent, eRestartReason);
738 if (bRestart && !bOkPressed)
739 m_xDialog->response(RET_OK);
742 void OfaTreeOptionsDialog::ApplyItemSets()
744 std::unique_ptr<weld::TreeIter> xEntry = xTreeLB->make_iterator();
745 bool bEntry = xTreeLB->get_iter_first(*xEntry);
746 while (bEntry)
748 if (!xTreeLB->get_iter_depth(*xEntry))
750 OptionsGroupInfo* pGroupInfo = weld::fromId<OptionsGroupInfo*>(xTreeLB->get_id(*xEntry));
751 if(pGroupInfo->m_pOutItemSet)
753 if(pGroupInfo->m_pShell)
754 pGroupInfo->m_pShell->ApplyItemSet( pGroupInfo->m_nDialogId, *pGroupInfo->m_pOutItemSet);
755 else
756 ApplyItemSet( pGroupInfo->m_nDialogId, *pGroupInfo->m_pOutItemSet);
759 bEntry = xTreeLB->iter_next(*xEntry);
763 void OfaTreeOptionsDialog::ActivatePage( sal_uInt16 nResId )
765 bIsForSetDocumentLanguage = false;
766 if ( nResId == OFA_TP_LANGUAGES_FOR_SET_DOCUMENT_LANGUAGE )
768 bIsForSetDocumentLanguage = true;
769 nResId = OFA_TP_LANGUAGES;
772 DBG_ASSERT( !bIsFromExtensionManager, "OfaTreeOptionsDialog::ActivatePage(): call from extension manager" );
773 if ( !pLastPageSaver )
774 pLastPageSaver = new LastPageSaver;
775 bForgetSelection = true;
776 sal_uInt16 nTemp = pLastPageSaver->m_nLastPageId;
777 pLastPageSaver->m_nLastPageId = nResId;
778 ActivateLastSelection();
779 pLastPageSaver->m_nLastPageId = nTemp;
782 void OfaTreeOptionsDialog::ActivatePage( const OUString& rPageURL )
784 DBG_ASSERT( !bIsFromExtensionManager, "OfaTreeOptionsDialog::ActivatePage(): call from extension manager" );
785 if ( !pLastPageSaver )
786 pLastPageSaver = new LastPageSaver;
787 bForgetSelection = true;
788 pLastPageSaver->m_nLastPageId = 0;
789 pLastPageSaver->m_sLastPageURL_Tools = rPageURL;
790 ActivateLastSelection();
793 void OfaTreeOptionsDialog::ActivateLastSelection()
795 std::unique_ptr<weld::TreeIter> xEntry;
797 if (pLastPageSaver)
799 OUString sLastURL = bIsFromExtensionManager ? pLastPageSaver->m_sLastPageURL_ExtMgr
800 : pLastPageSaver->m_sLastPageURL_Tools;
801 if ( sLastURL.isEmpty() )
803 sLastURL = !bIsFromExtensionManager ? pLastPageSaver->m_sLastPageURL_ExtMgr
804 : pLastPageSaver->m_sLastPageURL_Tools;
807 bool bMustExpand = ( INetURLObject( sLastURL ).GetProtocol() == INetProtocol::File );
809 std::unique_ptr<weld::TreeIter> xTemp = xTreeLB->make_iterator();
810 bool bTemp = xTreeLB->get_iter_first(*xTemp);
811 while (bTemp)
813 // restore only selection of a leaf
814 if (xTreeLB->get_iter_depth(*xTemp) && xTreeLB->get_id(*xTemp).toInt64())
816 OptionsPageInfo* pPageInfo = weld::fromId<OptionsPageInfo*>(xTreeLB->get_id(*xTemp));
817 OUString sPageURL = pPageInfo->m_sPageURL;
818 if ( bMustExpand )
820 sPageURL = comphelper::getExpandedUri(
821 comphelper::getProcessComponentContext(), sPageURL);
824 if ( ( !bIsFromExtensionManager
825 && pPageInfo->m_nPageId && pPageInfo->m_nPageId == pLastPageSaver->m_nLastPageId )
826 || ( !pPageInfo->m_nPageId && sLastURL == sPageURL ) )
828 xEntry = xTreeLB->make_iterator(xTemp.get());
829 break;
832 bTemp = xTreeLB->iter_next(*xTemp);
836 if (!xEntry)
838 xEntry = xTreeLB->make_iterator();
839 if (!xTreeLB->get_iter_first(*xEntry) || !xTreeLB->iter_next(*xEntry))
840 xEntry.reset();
843 if (!xEntry)
844 return;
846 std::unique_ptr<weld::TreeIter> xParent(xTreeLB->make_iterator(xEntry.get()));
847 xTreeLB->iter_parent(*xParent);
848 xTreeLB->expand_row(*xParent);
849 xTreeLB->scroll_to_row(*xParent);
850 xTreeLB->scroll_to_row(*xEntry);
851 xTreeLB->set_cursor(*xEntry);
852 xTreeLB->select(*xEntry);
853 xTreeLB->grab_focus();
854 SelectHdl_Impl();
857 void OfaTreeOptionsDialog::InitItemSets(OptionsGroupInfo& rGroupInfo)
859 if (!rGroupInfo.m_pInItemSet)
860 rGroupInfo.m_pInItemSet.emplace( rGroupInfo.m_pShell
861 ? *rGroupInfo.m_pShell->CreateItemSet( rGroupInfo.m_nDialogId )
862 : *CreateItemSet( rGroupInfo.m_nDialogId ) );
863 if (!rGroupInfo.m_pOutItemSet)
864 rGroupInfo.m_pOutItemSet = std::make_unique<SfxItemSet>(
865 *rGroupInfo.m_pInItemSet->GetPool(),
866 rGroupInfo.m_pInItemSet->GetRanges());
869 void OfaTreeOptionsDialog::SelectHdl_Impl()
871 std::unique_ptr<weld::TreeIter> xEntry(xTreeLB->make_iterator());
873 if (!xTreeLB->get_cursor(xEntry.get()))
874 return;
876 if (xCurrentPageEntry && xCurrentPageEntry->equal(*xEntry))
877 return;
879 std::unique_ptr<weld::TreeIter> xParent(xTreeLB->make_iterator(xEntry.get()));
880 bool bParent = xTreeLB->iter_parent(*xParent);
882 // If the user has selected a category, automatically switch to a suitable
883 // default sub-page instead.
884 if (!bParent)
885 return;
887 BuilderPage* pNewPage = nullptr;
888 OptionsPageInfo* pOptPageInfo = (xCurrentPageEntry && xTreeLB->get_iter_depth(*xCurrentPageEntry))
889 ? weld::fromId<OptionsPageInfo*>(xTreeLB->get_id(*xCurrentPageEntry)) : nullptr;
891 if (pOptPageInfo && pOptPageInfo->m_xPage && pOptPageInfo->m_xPage->IsVisible())
893 std::unique_ptr<weld::TreeIter> xCurParent(xTreeLB->make_iterator(xCurrentPageEntry.get()));
894 xTreeLB->iter_parent(*xCurParent);
896 OptionsGroupInfo* pGroupInfo = weld::fromId<OptionsGroupInfo*>(xTreeLB->get_id(*xCurParent));
897 DeactivateRC nLeave = DeactivateRC::LeavePage;
898 if ( RID_SVXPAGE_COLOR != pOptPageInfo->m_nPageId && pOptPageInfo->m_xPage->HasExchangeSupport() )
899 nLeave = pOptPageInfo->m_xPage->DeactivatePage( pGroupInfo->m_pOutItemSet.get() );
901 if ( nLeave == DeactivateRC::KeepPage )
903 // we cannot leave this page, this is may be from a user clicking a different entry
904 // in the tree so reselect the current page
905 xTreeLB->select(*xCurrentPageEntry);
906 return;
908 else
909 pOptPageInfo->m_xPage->set_visible(false);
911 else if ( pOptPageInfo && pOptPageInfo->m_xExtPage )
913 pOptPageInfo->m_xExtPage->Hide();
914 pOptPageInfo->m_xExtPage->DeactivatePage();
917 OptionsPageInfo *pPageInfo = weld::fromId<OptionsPageInfo*>(xTreeLB->get_id(*xEntry));
918 OptionsGroupInfo* pGroupInfo = weld::fromId<OptionsGroupInfo*>(xTreeLB->get_id(*xParent));
919 if(!pPageInfo->m_xPage && pPageInfo->m_nPageId > 0)
921 InitItemSets(*pGroupInfo);
923 pPageInfo->m_xPage = ::CreateGeneralTabPage(pPageInfo->m_nPageId, xTabBox.get(), this, *pGroupInfo->m_pInItemSet);
925 if(!pPageInfo->m_xPage && pGroupInfo->m_pModule)
926 pPageInfo->m_xPage = pGroupInfo->m_pModule->CreateTabPage(pPageInfo->m_nPageId, xTabBox.get(), this, *pGroupInfo->m_pInItemSet);
928 DBG_ASSERT( pPageInfo->m_xPage, "tabpage could not created");
929 if ( pPageInfo->m_xPage )
931 SvtViewOptions aTabPageOpt( EViewType::TabPage, OUString::number( pPageInfo->m_nPageId) );
932 pPageInfo->m_xPage->SetUserData( GetViewOptUserItem( aTabPageOpt ) );
933 pPageInfo->m_xPage->SetFrame( m_xFrame );
934 pPageInfo->m_xPage->Reset( &*pGroupInfo->m_pInItemSet );
937 else if ( 0 == pPageInfo->m_nPageId && !pPageInfo->m_xExtPage )
939 if ( !m_xContainerWinProvider.is() )
941 m_xContainerWinProvider = awt::ContainerWindowProvider::create( ::comphelper::getProcessComponentContext() );
944 pPageInfo->m_xExtPage = std::make_unique<ExtensionsTabPage>(
945 xTabBox.get(), pPageInfo->m_sPageURL, pPageInfo->m_sEventHdl, m_xContainerWinProvider);
948 if ( pPageInfo->m_xPage )
950 if ( RID_SVXPAGE_COLOR != pPageInfo->m_nPageId &&
951 pPageInfo->m_xPage->HasExchangeSupport())
953 pPageInfo->m_xPage->ActivatePage(*pGroupInfo->m_pOutItemSet);
955 pPageInfo->m_xPage->set_visible(true);
957 else if ( pPageInfo->m_xExtPage )
959 pPageInfo->m_xExtPage->Show();
960 pPageInfo->m_xExtPage->ActivatePage();
964 OUString sTitleText = sTitle
965 + " - " + xTreeLB->get_text(*xParent)
966 + " - " + xTreeLB->get_text(*xEntry);
967 m_xDialog->set_title(sTitleText);
970 xCurrentPageEntry = std::move(xEntry);
972 if ( !bForgetSelection )
974 if ( !pLastPageSaver )
975 pLastPageSaver = new LastPageSaver;
976 if ( !bIsFromExtensionManager )
977 pLastPageSaver->m_nLastPageId = pPageInfo->m_nPageId;
978 if ( pPageInfo->m_xExtPage )
980 if ( bIsFromExtensionManager )
981 pLastPageSaver->m_sLastPageURL_ExtMgr = pPageInfo->m_sPageURL;
982 else
983 pLastPageSaver->m_sLastPageURL_Tools = pPageInfo->m_sPageURL;
986 pNewPage = pPageInfo->m_xPage.get();
988 // fdo#58170 use current page's layout child HelpId, unless there isn't a current page
989 OUString sHelpId(pNewPage ? pNewPage->GetHelpId() : OUString());
990 if (sHelpId.isEmpty())
991 sHelpId = HID_OFADLG_TREELISTBOX;
992 xTreeLB->set_help_id(sHelpId);
995 std::optional<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId )
997 Reference< XLinguProperties > xProp( LinguMgr::GetLinguPropertySet() );
998 std::optional<SfxItemSet> pRet;
999 switch(nId)
1001 case SID_GENERAL_OPTIONS:
1003 pRet.emplace(
1004 SfxGetpApp()->GetPool(),
1005 svl::Items<
1006 SID_HTML_MODE, SID_HTML_MODE,
1007 SID_ATTR_METRIC, SID_ATTR_METRIC,
1008 SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK,
1009 SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER,
1010 SID_ATTR_YEAR2000, SID_ATTR_YEAR2000> );
1012 SfxItemSetFixed<SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER> aOptSet( SfxGetpApp()->GetPool() );
1013 SfxApplication::GetOptions(aOptSet);
1014 pRet->Put(aOptSet);
1016 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1017 if ( pViewFrame )
1019 const SfxUInt16Item* pItem = nullptr;
1020 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1022 // miscellaneous - Year2000
1023 if( SfxItemState::DEFAULT <= pDispatch->QueryState( SID_ATTR_YEAR2000, pItem ) )
1024 pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, pItem->GetValue() ) );
1025 else
1026 pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, officecfg::Office::Common::DateFormat::TwoDigitYear::get() ) );
1028 else
1029 pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, officecfg::Office::Common::DateFormat::TwoDigitYear::get() ) );
1032 // miscellaneous - Tabulator
1033 pRet->Put(SfxBoolItem(SID_PRINTER_NOTFOUND_WARN, officecfg::Office::Common::Print::Warning::NotFound::get()));
1035 SfxPrinterChangeFlags nFlag = officecfg::Office::Common::Print::Warning::PaperSize::get() ? SfxPrinterChangeFlags::CHG_SIZE : SfxPrinterChangeFlags::NONE;
1036 nFlag |= officecfg::Office::Common::Print::Warning::PaperOrientation::get() ? SfxPrinterChangeFlags::CHG_ORIENTATION : SfxPrinterChangeFlags::NONE;
1037 pRet->Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC, static_cast<int>(nFlag) ));
1040 break;
1041 case SID_LANGUAGE_OPTIONS :
1043 pRet.emplace(
1044 SfxGetpApp()->GetPool(),
1045 svl::Items<
1046 SID_ATTR_CHAR_CJK_LANGUAGE, SID_ATTR_CHAR_CJK_LANGUAGE,
1047 SID_ATTR_CHAR_CTL_LANGUAGE, SID_ATTR_CHAR_CTL_LANGUAGE,
1048 SID_SET_DOCUMENT_LANGUAGE, SID_SET_DOCUMENT_LANGUAGE,
1049 SID_ATTR_LANGUAGE, SID_ATTR_LANGUAGE,
1050 SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK,
1051 SID_OPT_LOCALE_CHANGED, SID_OPT_LOCALE_CHANGED>);
1053 // for linguistic
1054 SfxHyphenRegionItem aHyphen( SID_ATTR_HYPHENREGION );
1056 sal_Int16 nMinLead = 2,
1057 nMinTrail = 2;
1058 if (xProp.is())
1060 nMinLead = xProp->getHyphMinLeading();
1061 nMinTrail = xProp->getHyphMinTrailing();
1063 aHyphen.GetMinLead() = static_cast<sal_uInt8>(nMinLead);
1064 aHyphen.GetMinTrail() = static_cast<sal_uInt8>(nMinTrail);
1066 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1067 if ( pViewFrame )
1069 const SvxLanguageItem* pLangItem = nullptr;
1070 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1071 if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_ATTR_LANGUAGE, pLangItem))
1072 pRet->Put(*pLangItem, SID_ATTR_LANGUAGE);
1073 if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_ATTR_CHAR_CJK_LANGUAGE, pLangItem))
1074 pRet->Put(*pLangItem, SID_ATTR_CHAR_CJK_LANGUAGE);
1075 if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_ATTR_CHAR_CTL_LANGUAGE, pLangItem))
1076 pRet->Put(*pLangItem, SID_ATTR_CHAR_CTL_LANGUAGE);
1078 pRet->Put(aHyphen);
1079 const SfxPoolItem* pItem = nullptr;
1080 if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_AUTOSPELL_CHECK, pItem))
1082 pRet->Put(std::unique_ptr<SfxPoolItem>(pItem->Clone()));
1084 else
1086 bool bVal = false;
1087 if (xProp.is())
1089 bVal = xProp->getIsSpellAuto();
1092 pRet->Put(SfxBoolItem(SID_AUTOSPELL_CHECK, bVal));
1095 pRet->Put( SfxBoolItem( SID_SET_DOCUMENT_LANGUAGE, bIsForSetDocumentLanguage ) );
1097 break;
1098 case SID_INET_DLG :
1099 pRet.emplace( SfxGetpApp()->GetPool(),
1100 svl::Items<
1101 //SID_OPTIONS_START - ..END
1102 SID_SAVEREL_INET, SID_SAVEREL_FSYS,
1103 SID_INET_NOPROXY, SID_INET_FTP_PROXY_PORT,
1104 SID_SECURE_URL, SID_SECURE_URL> );
1105 SfxApplication::GetOptions(*pRet);
1106 break;
1107 case SID_FILTER_DLG:
1108 pRet.emplace(
1109 SfxGetpApp()->GetPool(),
1110 svl::Items<
1111 SID_ATTR_WARNALIENFORMAT, SID_ATTR_WARNALIENFORMAT,
1112 SID_ATTR_DOCINFO, SID_ATTR_AUTOSAVEMINUTE,
1113 SID_SAVEREL_INET, SID_SAVEREL_FSYS,
1114 SID_ATTR_PRETTYPRINTING, SID_ATTR_PRETTYPRINTING> );
1115 SfxApplication::GetOptions(*pRet);
1116 break;
1118 case SID_SB_STARBASEOPTIONS:
1119 pRet.emplace( SfxGetpApp()->GetPool(),
1120 svl::Items<SID_SB_POOLING_ENABLED, SID_SB_DB_REGISTER> );
1121 ::offapp::ConnectionPoolConfig::GetOptions(*pRet);
1122 svx::DbRegisteredNamesConfig::GetOptions(*pRet);
1123 break;
1125 case SID_SCH_EDITOPTIONS:
1127 pRet.emplace( SfxGetpApp()->GetPool(), svl::Items<SID_SCH_EDITOPTIONS, SID_SCH_EDITOPTIONS> );
1128 pRet->Put( SvxChartColorTableItem( SID_SCH_EDITOPTIONS, SvxChartOptions::GetDefaultColors() ) );
1129 break;
1132 return pRet;
1135 void OfaTreeOptionsDialog::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
1137 switch(nId)
1139 case SID_GENERAL_OPTIONS:
1141 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
1143 SfxItemSetFixed<SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER> aOptSet(SfxGetpApp()->GetPool());
1144 aOptSet.Put(rSet);
1145 if(aOptSet.Count())
1146 SfxGetpApp()->SetOptions( aOptSet );
1147 // get dispatcher anew, because SetOptions() might have destroyed the dispatcher
1148 SfxViewFrame *pViewFrame = SfxViewFrame::Current();
1150 // evaluate Year2000
1151 sal_uInt16 nY2K = USHRT_MAX;
1152 const SfxUInt16Item* pYearItem = rSet.GetItemIfSet( SID_ATTR_YEAR2000, false );
1153 if( pYearItem )
1154 nY2K = pYearItem->GetValue();
1155 if( USHRT_MAX != nY2K )
1157 if ( pViewFrame )
1159 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1160 pDispatch->ExecuteList(SID_ATTR_YEAR2000,
1161 SfxCallMode::ASYNCHRON, { pYearItem });
1163 officecfg::Office::Common::DateFormat::TwoDigitYear::set(nY2K, batch);
1166 // evaluate print
1167 if(const SfxBoolItem* pWarnItem = rSet.GetItemIfSet(SID_PRINTER_NOTFOUND_WARN, false))
1168 officecfg::Office::Common::Print::Warning::NotFound::set(pWarnItem->GetValue(), batch);
1170 if(const SfxFlagItem* pFlag = rSet.GetItemIfSet(SID_PRINTER_CHANGESTODOC, false))
1172 bool bPaperSizeWarning = bool(static_cast<SfxPrinterChangeFlags>(pFlag->GetValue()) & SfxPrinterChangeFlags::CHG_SIZE);
1173 officecfg::Office::Common::Print::Warning::PaperSize::set(bPaperSizeWarning, batch);
1174 bool bPaperOrientationWarning = bool(static_cast<SfxPrinterChangeFlags>(pFlag->GetValue()) & SfxPrinterChangeFlags::CHG_ORIENTATION);
1175 officecfg::Office::Common::Print::Warning::PaperOrientation::set(bPaperOrientationWarning, batch);
1178 // evaluate help options
1179 bool bHelpTips = officecfg::Office::Common::Help::Tip::get();
1180 if ( bHelpTips != Help::IsQuickHelpEnabled() )
1181 bHelpTips ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
1182 bool bExtendedHelp = officecfg::Office::Common::Help::ExtendedTip::get();
1183 if ( bExtendedHelp != Help::IsBalloonHelpEnabled() )
1184 bExtendedHelp ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
1186 batch->commit();
1188 break;
1189 case SID_LANGUAGE_OPTIONS :
1191 OfaTreeOptionsDialog::ApplyLanguageOptions(rSet);
1193 break;
1194 case SID_INET_DLG :
1195 case SID_FILTER_DLG:
1196 SfxGetpApp()->SetOptions( rSet );
1197 break;
1199 case SID_SB_STARBASEOPTIONS:
1200 ::offapp::ConnectionPoolConfig::SetOptions( rSet );
1201 svx::DbRegisteredNamesConfig::SetOptions(rSet);
1202 break;
1204 case SID_SCH_EDITOPTIONS:
1205 // nothing to do. Chart options only apply to newly created charts
1206 break;
1208 default:
1210 SAL_WARN("cui.options", "Unhandled option in ApplyItemSet");
1212 break;
1216 void OfaTreeOptionsDialog::ApplyLanguageOptions(const SfxItemSet& rSet)
1218 bool bSaveSpellCheck = false;
1219 const SfxPoolItem* pItem = nullptr;
1221 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1222 Reference< XLinguProperties > xProp = LinguProperties::create( xContext );
1223 if ( const SfxHyphenRegionItem* pHyphenItem = rSet.GetItemIfSet(SID_ATTR_HYPHENREGION, false ) )
1225 xProp->setHyphMinLeading( static_cast<sal_Int16>(pHyphenItem->GetMinLead()) );
1226 xProp->setHyphMinTrailing( static_cast<sal_Int16>(pHyphenItem->GetMinTrail()) );
1227 bSaveSpellCheck = true;
1230 SfxViewFrame *pViewFrame = SfxViewFrame::Current();
1231 if ( pViewFrame )
1233 SfxDispatcher* pDispatch = pViewFrame->GetDispatcher();
1234 pItem = nullptr;
1235 if(SfxItemState::SET == rSet.GetItemState( SID_ATTR_LANGUAGE, false, &pItem ))
1237 pDispatch->ExecuteList(pItem->Which(), SfxCallMode::SYNCHRON, { pItem });
1238 bSaveSpellCheck = true;
1240 if(SfxItemState::SET == rSet.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE, false, &pItem ))
1242 pDispatch->ExecuteList(pItem->Which(), SfxCallMode::SYNCHRON, { pItem });
1243 bSaveSpellCheck = true;
1245 if(SfxItemState::SET == rSet.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE, false, &pItem ))
1247 pDispatch->ExecuteList(pItem->Which(), SfxCallMode::SYNCHRON, { pItem });
1248 bSaveSpellCheck = true;
1251 if( SfxItemState::SET == rSet.GetItemState(SID_AUTOSPELL_CHECK, false, &pItem ))
1253 bool bOnlineSpelling = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1254 pDispatch->ExecuteList(SID_AUTOSPELL_CHECK,
1255 SfxCallMode::ASYNCHRON|SfxCallMode::RECORD, { pItem });
1257 xProp->setIsSpellAuto( bOnlineSpelling );
1260 if( bSaveSpellCheck )
1262 //! the config item has changed since we modified the
1263 //! property set it uses
1264 pDispatch->Execute(SID_SPELLCHECKER_CHANGED, SfxCallMode::ASYNCHRON);
1268 if( SfxItemState::SET == rSet.GetItemState(SID_OPT_LOCALE_CHANGED, false, &pItem ))
1270 SfxViewFrame* _pViewFrame = SfxViewFrame::GetFirst();
1271 while ( _pViewFrame )
1273 _pViewFrame->GetDispatcher()->ExecuteList(pItem->Which(),
1274 SfxCallMode::ASYNCHRON, { pItem });
1275 _pViewFrame = SfxViewFrame::GetNext( *_pViewFrame );
1280 OUString OfaTreeOptionsDialog::getCurrentFactory_Impl( const Reference< XFrame >& _xFrame )
1282 OUString sIdentifier;
1283 Reference < XFrame > xCurrentFrame( _xFrame );
1284 Reference < XModuleManager2 > xModuleManager = ModuleManager::create(::comphelper::getProcessComponentContext());
1285 if ( !xCurrentFrame.is() )
1287 Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1288 xCurrentFrame = xDesktop->getCurrentFrame();
1291 if ( xCurrentFrame.is() )
1295 sIdentifier = xModuleManager->identify( xCurrentFrame );
1297 catch ( css::frame::UnknownModuleException& )
1299 SAL_INFO( "cui.options", "unknown module" );
1301 catch ( Exception const & )
1303 TOOLS_WARN_EXCEPTION( "cui.options", "getActiveModule_Impl(): exception of XModuleManager::identify()" );
1307 return sIdentifier;
1310 void OfaTreeOptionsDialog::Initialize( const Reference< XFrame >& _xFrame )
1312 m_xFrame = _xFrame;
1313 sal_uInt16 nGroup = 0;
1315 SvtOptionsDialogOptions aOptionsDlgOpt;
1316 sal_uInt16 nPageId;
1318 // %PRODUCTNAME options
1319 if ( !lcl_isOptionHidden( SID_GENERAL_OPTIONS, aOptionsDlgOpt ) )
1321 setGroupName(u"ProductName", CuiResId(SID_GENERAL_OPTIONS_RES[0].first));
1322 nGroup = AddGroup(CuiResId(SID_GENERAL_OPTIONS_RES[0].first), nullptr, nullptr, SID_GENERAL_OPTIONS );
1323 const sal_uInt16 nEnd = static_cast<sal_uInt16>(std::size(SID_GENERAL_OPTIONS_RES));
1325 for (sal_uInt16 i = 1; i < nEnd; ++i)
1327 OUString sNewTitle = CuiResId(SID_GENERAL_OPTIONS_RES[i].first);
1328 nPageId = SID_GENERAL_OPTIONS_RES[i].second;
1329 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1330 continue;
1332 // Disable Online Update page if service not installed
1333 if( RID_SVXPAGE_ONLINEUPDATE == nPageId )
1337 Reference < XInterface > xService( setup::UpdateCheck::create( ::comphelper::getProcessComponentContext() ) );
1338 if( ! xService.is() )
1339 continue;
1341 catch ( css::uno::DeploymentException& )
1343 continue;
1347 // Disable Basic IDE options, if experimental features are not enabled
1348 if( RID_SVXPAGE_BASICIDE_OPTIONS == nPageId )
1350 if( ! officecfg::Office::Common::Misc::ExperimentalMode::get() )
1351 continue;
1354 AddTabPage( nPageId, sNewTitle, nGroup );
1358 // Load and Save options
1359 if ( !lcl_isOptionHidden( SID_FILTER_DLG, aOptionsDlgOpt ) )
1361 setGroupName( u"LoadSave", CuiResId(SID_FILTER_DLG_RES[0].first) );
1362 nGroup = AddGroup( CuiResId(SID_FILTER_DLG_RES[0].first), nullptr, nullptr, SID_FILTER_DLG );
1363 for ( size_t i = 1; i < std::size(SID_FILTER_DLG_RES); ++i )
1365 nPageId = static_cast<sal_uInt16>(SID_FILTER_DLG_RES[i].second);
1366 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1367 AddTabPage( nPageId, CuiResId(SID_FILTER_DLG_RES[i].first), nGroup );
1371 // Language options
1372 if ( !lcl_isOptionHidden( SID_LANGUAGE_OPTIONS, aOptionsDlgOpt ) )
1374 setGroupName(u"LanguageSettings", CuiResId(SID_LANGUAGE_OPTIONS_RES[0].first));
1375 nGroup = AddGroup(CuiResId(SID_LANGUAGE_OPTIONS_RES[0].first), nullptr, nullptr, SID_LANGUAGE_OPTIONS );
1376 for (size_t i = 1; i < std::size(SID_LANGUAGE_OPTIONS_RES); ++i)
1378 nPageId = static_cast<sal_uInt16>(SID_LANGUAGE_OPTIONS_RES[i].second);
1379 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1380 continue;
1382 // Disable DeepL translation settings, if experimental mode is not enabled
1383 if( RID_SVXPAGE_DEEPL_OPTIONS == nPageId )
1385 if( ! officecfg::Office::Common::Misc::ExperimentalMode::get() )
1386 continue;
1389 if ( ( RID_SVXPAGE_JSEARCH_OPTIONS != nPageId || SvtCJKOptions::IsJapaneseFindEnabled() ) &&
1390 ( RID_SVXPAGE_ASIAN_LAYOUT != nPageId || SvtCJKOptions::IsAsianTypographyEnabled() ) &&
1391 ( RID_SVXPAGE_OPTIONS_CTL != nPageId || SvtCTLOptions::IsCTLFontEnabled() ) )
1392 AddTabPage(nPageId, CuiResId(SID_LANGUAGE_OPTIONS_RES[i].first), nGroup);
1396 OUString aFactory = getCurrentFactory_Impl( _xFrame );
1397 DBG_ASSERT( GetModuleIdentifier( _xFrame ) == aFactory, "S H I T!!!" );
1399 // Writer and Writer/Web options
1400 SvtModuleOptions aModuleOpt;
1401 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::WRITER ) )
1403 // text document
1404 if ( aFactory == "com.sun.star.text.TextDocument"
1405 || aFactory == "com.sun.star.text.WebDocument"
1406 || aFactory == "com.sun.star.text.GlobalDocument" )
1408 SfxModule* pSwMod = SfxApplication::GetModule(SfxToolsModule::Writer);
1409 if ( !lcl_isOptionHidden( SID_SW_EDITOPTIONS, aOptionsDlgOpt ) )
1411 if ( aFactory == "com.sun.star.text.WebDocument" )
1412 setGroupName( u"WriterWeb", CuiResId(SID_SW_EDITOPTIONS_RES[0].first) );
1413 else
1414 setGroupName( u"Writer", CuiResId(SID_SW_EDITOPTIONS_RES[0].first) );
1415 nGroup = AddGroup(CuiResId(SID_SW_EDITOPTIONS_RES[0].first), pSwMod, pSwMod, SID_SW_EDITOPTIONS );
1416 for ( size_t i = 1; i < std::size(SID_SW_EDITOPTIONS_RES); ++i )
1418 nPageId = static_cast<sal_uInt16>(SID_SW_EDITOPTIONS_RES[i].second);
1419 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1420 continue;
1421 if ( ( RID_SW_TP_STD_FONT_CJK != nPageId || SvtCJKOptions::IsCJKFontEnabled() ) &&
1422 ( RID_SW_TP_STD_FONT_CTL != nPageId || SvtCTLOptions::IsCTLFontEnabled() ) &&
1423 ( RID_SW_TP_MAILCONFIG != nPageId || MailMergeCfgIsEmailSupported() ) )
1424 AddTabPage( nPageId, CuiResId(SID_SW_EDITOPTIONS_RES[i].first), nGroup );
1426 #ifdef DBG_UTIL
1427 AddTabPage( RID_SW_TP_OPTTEST_PAGE, "Internal Test", nGroup );
1428 #endif
1431 // HTML documents
1432 if ( !lcl_isOptionHidden( SID_SW_ONLINEOPTIONS, aOptionsDlgOpt ) )
1434 nGroup = AddGroup(CuiResId(SID_SW_ONLINEOPTIONS_RES[0].first), pSwMod, pSwMod, SID_SW_ONLINEOPTIONS );
1435 for( size_t i = 1; i < std::size(SID_SW_ONLINEOPTIONS_RES); ++i )
1437 nPageId = static_cast<sal_uInt16>(SID_SW_ONLINEOPTIONS_RES[i].second);
1438 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1439 AddTabPage(nPageId, CuiResId(SID_SW_ONLINEOPTIONS_RES[i].first), nGroup);
1441 #ifdef DBG_UTIL
1442 AddTabPage( RID_SW_TP_OPTTEST_PAGE, "Internal Test", nGroup );
1443 #endif
1448 // Calc options
1449 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::CALC ) )
1451 if ( aFactory == "com.sun.star.sheet.SpreadsheetDocument" )
1453 if ( !lcl_isOptionHidden( SID_SC_EDITOPTIONS, aOptionsDlgOpt ) )
1455 SfxModule* pScMod = SfxApplication::GetModule( SfxToolsModule::Calc );
1456 setGroupName( u"Calc", CuiResId(SID_SC_EDITOPTIONS_RES[0].first) );
1457 nGroup = AddGroup( CuiResId(SID_SC_EDITOPTIONS_RES[0].first), pScMod, pScMod, SID_SC_EDITOPTIONS );
1458 const sal_uInt16 nCount = static_cast<sal_uInt16>(std::size(SID_SC_EDITOPTIONS_RES));
1459 for ( sal_uInt16 i = 1; i < nCount; ++i )
1461 nPageId = static_cast<sal_uInt16>(SID_SC_EDITOPTIONS_RES[i].second);
1462 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1463 continue;
1465 AddTabPage( nPageId, CuiResId(SID_SC_EDITOPTIONS_RES[i].first), nGroup );
1471 // Impress options
1472 SfxModule* pSdMod = SfxApplication::GetModule( SfxToolsModule::Draw );
1473 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::IMPRESS ) )
1475 if ( aFactory == "com.sun.star.presentation.PresentationDocument" )
1477 if ( !lcl_isOptionHidden( SID_SD_EDITOPTIONS, aOptionsDlgOpt ) )
1479 setGroupName( u"Impress", CuiResId(SID_SD_EDITOPTIONS_RES[0].first) );
1480 nGroup = AddGroup( CuiResId(SID_SD_EDITOPTIONS_RES[0].first), pSdMod, pSdMod, SID_SD_EDITOPTIONS );
1481 const sal_uInt16 nCount = static_cast<sal_uInt16>(std::size(SID_SD_EDITOPTIONS_RES));
1482 for ( sal_uInt16 i = 1; i < nCount; ++i )
1484 nPageId = static_cast<sal_uInt16>(SID_SD_EDITOPTIONS_RES[i].second);
1485 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1486 continue;
1488 AddTabPage( nPageId, CuiResId(SID_SD_EDITOPTIONS_RES[i].first), nGroup );
1494 // Draw options
1495 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::DRAW ) )
1497 if ( aFactory == "com.sun.star.drawing.DrawingDocument" )
1499 if ( !lcl_isOptionHidden( SID_SD_GRAPHIC_OPTIONS, aOptionsDlgOpt ) )
1501 setGroupName( u"Draw", CuiResId(SID_SD_GRAPHIC_OPTIONS_RES[0].first) );
1502 nGroup = AddGroup( CuiResId(SID_SD_GRAPHIC_OPTIONS_RES[0].first), pSdMod, pSdMod, SID_SD_GRAPHIC_OPTIONS );
1503 const sal_uInt16 nCount = static_cast<sal_uInt16>(std::size(SID_SD_GRAPHIC_OPTIONS_RES));
1504 for ( sal_uInt16 i = 1; i < nCount; ++i )
1506 nPageId = static_cast<sal_uInt16>(SID_SD_GRAPHIC_OPTIONS_RES[i].second);
1507 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1508 continue;
1510 AddTabPage( nPageId, CuiResId(SID_SD_GRAPHIC_OPTIONS_RES[i].first), nGroup );
1516 // Math options
1517 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::MATH ) )
1519 if ( aFactory == "com.sun.star.formula.FormulaProperties" )
1521 if ( !lcl_isOptionHidden( SID_SM_EDITOPTIONS, aOptionsDlgOpt ) )
1523 SfxModule* pSmMod = SfxApplication::GetModule(SfxToolsModule::Math);
1524 setGroupName( u"Math", CuiResId(SID_SM_EDITOPTIONS_RES[0].first) );
1525 nGroup = AddGroup(CuiResId(SID_SM_EDITOPTIONS_RES[0].first), pSmMod, pSmMod, SID_SM_EDITOPTIONS );
1526 for ( size_t i = 1; i < std::size(SID_SM_EDITOPTIONS_RES); ++i )
1528 nPageId = static_cast<sal_uInt16>(SID_SM_EDITOPTIONS_RES[i].second);
1529 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1530 AddTabPage( nPageId, CuiResId(SID_SM_EDITOPTIONS_RES[i].first), nGroup );
1536 // Database - needed only if there is an application which integrates with databases
1537 if ( !lcl_isOptionHidden( SID_SB_STARBASEOPTIONS, aOptionsDlgOpt ) &&
1538 ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::DATABASE )
1539 || aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::WRITER )
1540 || aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::CALC )
1543 setGroupName( u"Base", CuiResId(SID_SB_STARBASEOPTIONS_RES[0].first) );
1544 nGroup = AddGroup( CuiResId(SID_SB_STARBASEOPTIONS_RES[0].first), nullptr, nullptr, SID_SB_STARBASEOPTIONS );
1545 for ( size_t i = 1; i < std::size(SID_SB_STARBASEOPTIONS_RES); ++i )
1547 nPageId = static_cast<sal_uInt16>(SID_SB_STARBASEOPTIONS_RES[i].second);
1548 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1549 AddTabPage( nPageId, CuiResId(SID_SB_STARBASEOPTIONS_RES[i].first), nGroup );
1553 // Chart options (always installed and active)
1554 if ( !lcl_isOptionHidden( SID_SCH_EDITOPTIONS, aOptionsDlgOpt ) )
1556 setGroupName( u"Charts", CuiResId(SID_SCH_EDITOPTIONS_RES[0].first) );
1557 nGroup = AddGroup( CuiResId(SID_SCH_EDITOPTIONS_RES[0].first), nullptr, nullptr, SID_SCH_EDITOPTIONS );
1558 for ( size_t i = 1; i < std::size(SID_SCH_EDITOPTIONS_RES); ++i )
1560 nPageId = static_cast<sal_uInt16>(SID_SCH_EDITOPTIONS_RES[i].second);
1561 if ( !lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1562 AddTabPage( nPageId, CuiResId(SID_SCH_EDITOPTIONS_RES[i].first), nGroup );
1566 // Internet options
1567 if ( lcl_isOptionHidden( SID_INET_DLG, aOptionsDlgOpt ) )
1568 return;
1570 setGroupName(u"Internet", CuiResId(SID_INET_DLG_RES[0].first));
1571 nGroup = AddGroup(CuiResId(SID_INET_DLG_RES[0].first), nullptr, nullptr, SID_INET_DLG );
1573 for ( size_t i = 1; i < std::size(SID_INET_DLG_RES); ++i )
1575 nPageId = static_cast<sal_uInt16>(SID_INET_DLG_RES[i].second);
1576 if ( lcl_isOptionHidden( nPageId, aOptionsDlgOpt ) )
1577 continue;
1578 #if defined(_WIN32)
1579 // Disable E-mail tab-page on Windows
1580 if ( nPageId == RID_SVXPAGE_INET_MAIL )
1581 continue;
1582 #endif
1583 AddTabPage( nPageId, CuiResId(SID_INET_DLG_RES[i].first), nGroup );
1587 static bool isNodeActive( OptionsNode const * pNode, Module* pModule )
1589 if ( !pNode )
1590 return false;
1592 // Node for all modules active?
1593 if ( pNode->m_bAllModules )
1594 return true;
1596 // OOo-Nodes (Writer, Calc, Impress...) are active if node is already inserted
1597 if ( !getGroupName( pNode->m_sId, false ).isEmpty() )
1598 return true;
1600 // no module -> not active
1601 if ( !pModule )
1602 return false;
1604 // search node in active module
1605 if ( pModule->m_bActive )
1607 for (auto const& j : pModule->m_aNodeList)
1608 if ( j->m_sId == pNode->m_sId )
1609 return true;
1611 return false;
1614 void OfaTreeOptionsDialog::LoadExtensionOptions( std::u16string_view rExtensionId )
1616 std::unique_ptr<Module> pModule;
1618 // when called by Tools - Options then load nodes of active module
1619 if ( rExtensionId.empty() )
1621 pModule = LoadModule( GetModuleIdentifier( Reference< XFrame >() ) );
1624 VectorOfNodes aNodeList = LoadNodes( pModule.get(), rExtensionId );
1625 InsertNodes( aNodeList );
1628 OUString OfaTreeOptionsDialog::GetModuleIdentifier( const Reference< XFrame >& rFrame )
1630 OUString sModule;
1631 Reference < XFrame > xCurrentFrame( rFrame );
1632 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
1633 Reference < XModuleManager2 > xModuleManager = ModuleManager::create(xContext);
1635 if ( !xCurrentFrame.is() )
1637 Reference < XDesktop2 > xDesktop = Desktop::create( xContext );
1638 xCurrentFrame = xDesktop->getCurrentFrame();
1641 if ( xCurrentFrame.is() )
1645 sModule = xModuleManager->identify( xCurrentFrame );
1647 catch ( css::frame::UnknownModuleException& )
1649 SAL_INFO( "cui.options", "unknown module" );
1651 catch ( Exception const & )
1653 TOOLS_WARN_EXCEPTION( "cui.options", "OfaTreeOptionsDialog::GetModuleIdentifier(): exception of XModuleManager::identify()");
1656 return sModule;
1659 std::unique_ptr<Module> OfaTreeOptionsDialog::LoadModule(
1660 std::u16string_view rModuleIdentifier )
1662 std::unique_ptr<Module> pModule;
1663 Reference< XNameAccess > xSet(
1664 officecfg::Office::OptionsDialog::Modules::get());
1666 const Sequence< OUString > seqNames = xSet->getElementNames();
1667 for ( const OUString& rModule : seqNames )
1669 if ( rModuleIdentifier == rModule )
1671 // current active module found
1672 pModule.reset(new Module);
1673 pModule->m_bActive = true;
1675 Reference< XNameAccess > xModAccess;
1676 xSet->getByName( rModule ) >>= xModAccess;
1677 if ( xModAccess.is() )
1679 // load the nodes of this module
1680 Reference< XNameAccess > xNodeAccess;
1681 xModAccess->getByName( "Nodes" ) >>= xNodeAccess;
1682 if ( xNodeAccess.is() )
1684 const Sequence< OUString > xTemp = xNodeAccess->getElementNames();
1685 Reference< XNameAccess > xAccess;
1686 sal_Int32 nIndex = -1;
1687 for ( const OUString& rNode : xTemp)
1689 xNodeAccess->getByName( rNode ) >>= xAccess;
1690 if ( xAccess.is() )
1692 xAccess->getByName( "Index" ) >>= nIndex;
1693 if ( nIndex < 0 )
1694 // append nodes with index < 0
1695 pModule->m_aNodeList.push_back(
1696 std::unique_ptr<OrderedEntry>(new OrderedEntry(nIndex, rNode)));
1697 else
1699 // search position of the node
1700 std::vector<OrderedEntry *>::size_type y = 0;
1701 for ( ; y < pModule->m_aNodeList.size(); ++y )
1703 sal_Int32 nNodeIdx = pModule->m_aNodeList[y]->m_nIndex;
1704 if ( nNodeIdx < 0 || nNodeIdx > nIndex )
1705 break;
1707 // and insert the node on this position
1708 pModule->m_aNodeList.insert(
1709 pModule->m_aNodeList.begin() + y,
1710 std::unique_ptr<OrderedEntry>(new OrderedEntry( nIndex, rNode )) );
1716 break;
1719 return pModule;
1722 VectorOfNodes OfaTreeOptionsDialog::LoadNodes(
1723 Module* pModule, std::u16string_view rExtensionId)
1725 VectorOfNodes aOutNodeList;
1727 Reference< XNameAccess > xSet(
1728 officecfg::Office::OptionsDialog::Nodes::get());
1729 VectorOfNodes aNodeList;
1730 const Sequence< OUString > seqNames = xSet->getElementNames();
1732 for ( OUString const & sGroupName : seqNames )
1734 Reference< XNameAccess > xNodeAccess;
1735 xSet->getByName( sGroupName ) >>= xNodeAccess;
1737 if ( xNodeAccess.is() )
1739 OUString sNodeId, sLabel, sPageURL;
1740 bool bAllModules = false;
1742 sNodeId = sGroupName;
1743 xNodeAccess->getByName( "Label" ) >>= sLabel;
1744 xNodeAccess->getByName( "OptionsPage" ) >>= sPageURL;
1745 xNodeAccess->getByName( "AllModules" ) >>= bAllModules;
1747 if ( sLabel.isEmpty() )
1748 sLabel = sGroupName;
1749 OUString sTemp = getGroupName( sLabel, !rExtensionId.empty() );
1750 if ( !sTemp.isEmpty() )
1751 sLabel = sTemp;
1752 std::unique_ptr<OptionsNode> pNode(new OptionsNode(sNodeId, sLabel, bAllModules));
1754 if ( rExtensionId.empty() && !isNodeActive( pNode.get(), pModule ) )
1756 continue;
1759 Reference< XNameAccess > xLeavesSet;
1760 xNodeAccess->getByName( "Leaves" ) >>= xLeavesSet;
1761 if ( xLeavesSet.is() )
1763 const Sequence< OUString > seqLeaves = xLeavesSet->getElementNames();
1764 for ( OUString const & leafName : seqLeaves )
1766 Reference< XNameAccess > xLeaveAccess;
1767 xLeavesSet->getByName( leafName ) >>= xLeaveAccess;
1769 if ( xLeaveAccess.is() )
1771 OUString sId, sLeafLabel, sEventHdl, sLeafURL, sLeafGrpId;
1772 sal_Int32 nLeafGrpIdx = 0;
1774 xLeaveAccess->getByName( "Id" ) >>= sId;
1775 xLeaveAccess->getByName( "Label" ) >>= sLeafLabel;
1776 xLeaveAccess->getByName( "OptionsPage" ) >>= sLeafURL;
1777 xLeaveAccess->getByName( "EventHandlerService" ) >>= sEventHdl;
1778 xLeaveAccess->getByName( "GroupId" ) >>= sLeafGrpId;
1779 xLeaveAccess->getByName( "GroupIndex" ) >>= nLeafGrpIdx;
1781 if ( rExtensionId.empty() || sId == rExtensionId )
1783 std::unique_ptr<OptionsLeaf> pLeaf(new OptionsLeaf(
1784 sLeafLabel, sLeafURL, sEventHdl, sLeafGrpId, nLeafGrpIdx ));
1786 if ( !sLeafGrpId.isEmpty() )
1788 bool bAlreadyOpened = false;
1789 if ( !pNode->m_aGroupedLeaves.empty() )
1791 for (auto & rGroup : pNode->m_aGroupedLeaves)
1793 if ( !rGroup.empty() &&
1794 rGroup[0]->m_sGroupId == sLeafGrpId )
1796 std::vector<std::unique_ptr<OptionsLeaf>>::size_type l = 0;
1797 for ( ; l < rGroup.size(); ++l )
1799 if ( rGroup[l]->m_nGroupIndex >= nLeafGrpIdx )
1800 break;
1802 rGroup.insert( rGroup.begin() + l, std::move(pLeaf) );
1803 bAlreadyOpened = true;
1804 break;
1808 if ( !bAlreadyOpened )
1810 std::vector< std::unique_ptr<OptionsLeaf> > aGroupedLeaves;
1811 aGroupedLeaves.push_back( std::move(pLeaf) );
1812 pNode->m_aGroupedLeaves.push_back( std::move(aGroupedLeaves) );
1815 else
1816 pNode->m_aLeaves.push_back( std::move(pLeaf) );
1822 // do not insert nodes without leaves
1823 if ( !pNode->m_aLeaves.empty() || !pNode->m_aGroupedLeaves.empty() )
1825 pModule ? aNodeList.push_back( std::move(pNode) ) : aOutNodeList.push_back( std::move(pNode) );
1830 if ( pModule && !aNodeList.empty() )
1832 for ( auto const & i: pModule->m_aNodeList )
1834 OUString sNodeId = i->m_sId;
1835 for ( auto j = aNodeList.begin(); j != aNodeList.end(); ++j )
1837 if ( (*j)->m_sId == sNodeId )
1839 aOutNodeList.push_back( std::move(*j) );
1840 aNodeList.erase( j );
1841 break;
1846 for ( auto & i: aNodeList )
1847 aOutNodeList.push_back( std::move(i) );
1849 return aOutNodeList;
1852 static sal_uInt16 lcl_getGroupId( std::u16string_view rGroupName, const weld::TreeView& rTreeLB )
1854 sal_uInt16 nRet = 0;
1856 std::unique_ptr<weld::TreeIter> xEntry = rTreeLB.make_iterator();
1857 bool bEntry = rTreeLB.get_iter_first(*xEntry);
1858 while (bEntry)
1860 if (!rTreeLB.get_iter_depth(*xEntry))
1862 OUString sTemp(rTreeLB.get_text(*xEntry));
1863 if (sTemp == rGroupName)
1864 return nRet;
1865 nRet++;
1867 bEntry = rTreeLB.iter_next(*xEntry);
1870 return USHRT_MAX;
1873 static void lcl_insertLeaf(
1874 OfaTreeOptionsDialog* pDlg, OptionsNode const * pNode, OptionsLeaf const * pLeaf, const weld::TreeView& rTreeLB )
1876 sal_uInt16 nGrpId = lcl_getGroupId( pNode->m_sLabel, rTreeLB );
1877 if ( USHRT_MAX == nGrpId )
1879 sal_uInt16 nNodeGrpId = getGroupNodeId( pNode->m_sId );
1880 nGrpId = pDlg->AddGroup( pNode->m_sLabel, nullptr, nullptr, nNodeGrpId );
1882 OptionsPageInfo* pInfo = pDlg->AddTabPage( 0, pLeaf->m_sLabel, nGrpId );
1883 pInfo->m_sPageURL = pLeaf->m_sPageURL;
1884 pInfo->m_sEventHdl = pLeaf->m_sEventHdl;
1887 void OfaTreeOptionsDialog::InsertNodes( const VectorOfNodes& rNodeList )
1889 for (auto const& node : rNodeList)
1891 if ( !node->m_aLeaves.empty() || !node->m_aGroupedLeaves.empty() )
1893 for ( auto const & j: node->m_aGroupedLeaves )
1895 for ( size_t k = 0; k < j.size(); ++k )
1897 lcl_insertLeaf( this, node.get(), j[k].get(), *xTreeLB );
1901 for ( auto const & j: node->m_aLeaves )
1903 lcl_insertLeaf( this, node.get(), j.get(), *xTreeLB );
1909 void OfaTreeOptionsDialog::SetNeedsRestart( svtools::RestartReason eReason)
1911 bNeedsRestart = true;
1912 eRestartReason = eReason;
1915 short OfaTreeOptionsDialog::run()
1917 std::unique_ptr< SvxDicListChgClamp > pClamp;
1918 if ( !bIsFromExtensionManager )
1920 // collect all DictionaryList Events while the dialog is executed
1921 Reference<css::linguistic2::XSearchableDictionaryList> xDictionaryList(LinguMgr::GetDictionaryList());
1922 pClamp.reset( new SvxDicListChgClamp( xDictionaryList ) );
1925 return SfxOkDialogController::run();
1928 // class ExtensionsTabPage -----------------------------------------------
1929 ExtensionsTabPage::ExtensionsTabPage(
1930 weld::Container* pParent, OUString aPageURL,
1931 OUString aEvtHdl, const Reference< awt::XContainerWindowProvider >& rProvider )
1932 : m_pContainer(pParent)
1933 , m_sPageURL(std::move(aPageURL))
1934 , m_sEventHdl(std::move(aEvtHdl))
1935 , m_xWinProvider(rProvider)
1939 ExtensionsTabPage::~ExtensionsTabPage()
1941 Hide();
1942 DeactivatePage();
1944 if ( m_xPage.is() )
1948 m_xPage->dispose();
1950 catch (const Exception&)
1953 m_xPage.clear();
1956 if ( m_xPageParent.is() )
1960 m_xPageParent->dispose();
1962 catch (const Exception&)
1965 m_xPageParent.clear();
1969 void ExtensionsTabPage::CreateDialogWithHandler()
1973 bool bWithHandler = !m_sEventHdl.isEmpty();
1974 if ( bWithHandler )
1976 Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
1977 m_xEventHdl.set( xFactory->createInstance( m_sEventHdl ), UNO_QUERY );
1980 if ( !bWithHandler || m_xEventHdl.is() )
1982 m_xPageParent = m_pContainer->CreateChildFrame();
1983 Reference<awt::XWindowPeer> xParent(m_xPageParent, UNO_QUERY);
1984 m_xPage =
1985 m_xWinProvider->createContainerWindow(
1986 m_sPageURL, OUString(), xParent, m_xEventHdl );
1988 Reference< awt::XControl > xPageControl( m_xPage, UNO_QUERY );
1989 if ( xPageControl.is() )
1991 Reference< awt::XWindowPeer > xWinPeer( xPageControl->getPeer() );
1992 if ( xWinPeer.is() )
1994 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWinPeer );
1995 if ( pWindow )
1996 pWindow->SetStyle( pWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
2001 catch (const Exception&)
2003 TOOLS_WARN_EXCEPTION( "cui.options", "ExtensionsTabPage::CreateDialogWithHandler(): exception of XDialogProvider2::createDialogWithHandler()");
2007 bool ExtensionsTabPage::DispatchAction( const OUString& rAction )
2009 bool bRet = false;
2010 if ( m_xEventHdl.is() )
2014 bRet = m_xEventHdl->callHandlerMethod( m_xPage, Any( rAction ), "external_event" );
2016 catch ( Exception const & )
2018 TOOLS_WARN_EXCEPTION( "cui.options", "ExtensionsTabPage::DispatchAction(): exception of XDialogEventHandler::callHandlerMethod()" );
2021 return bRet;
2024 void ExtensionsTabPage::Show()
2026 if (!m_xPageParent.is())
2027 return;
2029 VclPtr<vcl::Window> xPageParent = VCLUnoHelper::GetWindow(m_xPageParent);
2030 if (xPageParent)
2032 // NoActivate otherwise setVisible will call Window::Show which will grab
2033 // focus to the page by default
2034 xPageParent->Show(true, ShowFlags::NoActivate);
2037 m_xPageParent->setVisible(true);
2040 void ExtensionsTabPage::Hide()
2042 if (!m_xPageParent.is())
2043 return;
2044 m_xPageParent->setVisible(false);
2047 void ExtensionsTabPage::ActivatePage()
2049 if ( !m_xPage.is() )
2051 CreateDialogWithHandler();
2053 if ( m_xPage.is() )
2055 auto aWindowRect = m_xPageParent->getPosSize();
2056 m_xPage->setPosSize(0, 0, aWindowRect.Width, aWindowRect.Height, awt::PosSize::POSSIZE);
2057 if ( !m_sEventHdl.isEmpty() )
2058 DispatchAction( "initialize" );
2062 if ( m_xPage.is() )
2064 m_xPage->setVisible( true );
2068 void ExtensionsTabPage::DeactivatePage()
2070 if ( m_xPage.is() )
2071 m_xPage->setVisible( false );
2074 void ExtensionsTabPage::ResetPage()
2076 DispatchAction( "back" );
2077 ActivatePage();
2080 void ExtensionsTabPage::SavePage()
2082 DispatchAction( "ok" );
2085 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */