Resolves tdf#117463 - Dialog to show UI options

* New dialog to pick and apply one of the UI variants
* Tip-of-the-Day enhanced to execute UNO commands in order
to advertise the UI chooser on first start

Change-Id: I5e5c4a8e0fb11d11bafc99cc37b7ec244a993781
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99957
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
diff --git a/Repository.mk b/Repository.mk
index 4e5d64e..08061a6 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -939,6 +939,7 @@ $(eval $(call gb_Helper_register_packages_for_install,ooo,\
	wizards_properties \
	wizards_wizardshare \
	tipoftheday_images \
	toolbarmode_images \
	vcl_opengl_shader \
	vcl_theme_definitions \
	$(if $(filter WNT,$(OS)), \
diff --git a/cui/Library_cui.mk b/cui/Library_cui.mk
index ec2d222..1d1f0fe 100644
--- a/cui/Library_cui.mk
+++ b/cui/Library_cui.mk
@@ -147,6 +147,7 @@ $(eval $(call gb_Library_add_exception_objects,cui,\
    cui/source/dialogs/splitcelldlg \
    cui/source/dialogs/srchxtra \
    cui/source/dialogs/thesdlg \
    cui/source/dialogs/toolbarmodedlg \
    cui/source/dialogs/zoom \
    cui/source/factory/cuiexp \
    cui/source/factory/cuiresmgr \
diff --git a/cui/UIConfig_cui.mk b/cui/UIConfig_cui.mk
index a6dcd3b..153d6fe 100644
--- a/cui/UIConfig_cui.mk
+++ b/cui/UIConfig_cui.mk
@@ -203,6 +203,7 @@ $(eval $(call gb_UIConfig_add_uifiles,cui,\
	cui/uiconfig/ui/textdialog \
	cui/uiconfig/ui/textflowpage \
	cui/uiconfig/ui/thesaurus \
	cui/uiconfig/ui/toolbarmodedialog \
	cui/uiconfig/ui/transparencytabpage \
	cui/uiconfig/ui/tsaurldialog \
	cui/uiconfig/ui/twolinespage \
diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc
index fb43379..e96e76e 100644
--- a/cui/inc/strings.hrc
+++ b/cui/inc/strings.hrc
@@ -400,4 +400,6 @@
#define RID_SVXSTR_ADDITIONS_LOADING                NC_("RID_SVXSTR_ADDITIONS_LOADING", "Loading...")
#define RID_SVXSTR_ADDITIONS_DIALOG_TITLE_PREFIX    NC_("RID_SVXSTR_ADDITIONS_DIALOG_TITLE_PREFIX", "Extensions")

#define RID_SVXSTR_UI_APPLYALL                      NC_("RID_SVXSTR_UI_APPLYALL", "Apply to %MODULE")

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/inc/tipoftheday.hrc b/cui/inc/tipoftheday.hrc
index 74de677d..f464a1f 100644
--- a/cui/inc/tipoftheday.hrc
+++ b/cui/inc/tipoftheday.hrc
@@ -44,6 +44,7 @@

const std::tuple<const char*, OUString, OUString> TIPOFTHEDAY_STRINGARRAY[] =
{
     { NC_("RID_CUI_TIPOFTHEDAY", "%PRODUCTNAME offers a variety of user interface options to make you feel at home"), ".uno:ToolbarModeUI", "toolbarmode.png"},
     { NC_("RID_CUI_TIPOFTHEDAY", "Need to allow changes to parts of a read-only document in Writer? Insert frames or sections that can authorize changes."), "https://help.libreoffice.org/%PRODUCTVERSION/%LANGUAGENAME/text/swriter/guide/section_edit.html", "tipoftheday_w.png"}, //local help missing
     { NC_("RID_CUI_TIPOFTHEDAY", "To print the notes of your slides go to File ▸ Print ▸ Impress tab and select Notes under Document ▸ Type."), "", "tipoftheday_i.png"},
     { NC_("RID_CUI_TIPOFTHEDAY", "To start temporarily with a fresh user profile, or to restore a non-working %PRODUCTNAME, use Help ▸ Restart in Safe Mode."), "svx/ui/safemodedialog/SafeModeDialog", ""}, //https://help.libreoffice.org/%PRODUCTVERSION/%LANGUAGENAME/text/shared/01/profile_safe_mode.html
@@ -270,6 +271,8 @@ const std::tuple<const char*, OUString, OUString> TIPOFTHEDAY_STRINGARRAY[] =

#define STR_HELP_LINK                   NC_("STR_HELP_LINK", "%PRODUCTNAME Help")
#define STR_MORE_LINK                   NC_("STR_MORE_LINK", "More info")
#define STR_UNO_LINK                    NC_("STR_UNO_LINK", "Run this action now...")
#define STR_UNO_EXECUTE                 NC_("STR_UNO_EXECUTE", "Execute the command %COMMAND") //tooltip for STR_UNO_LINK
#define STR_TITLE                       NC_("STR_TITLE", "Tip of the Day")
#define STR_CMD                         NC_("STR_CMD", "⌘ Cmd") //use narrow no-break space U+202F here
#define STR_CTRL                        NC_("STR_CTRL", "Ctrl")
diff --git a/cui/inc/toolbarmode.hrc b/cui/inc/toolbarmode.hrc
new file mode 100644
index 0000000..25de3b5
--- /dev/null
+++ b/cui/inc/toolbarmode.hrc
@@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#define NC_(Context, String) reinterpret_cast<char const *>(Context "\004" u8##String)

#include <rtl/ustring.hxx>
#include <tuple>

/*
 Description, ui file name, preview file name
*/
const std::tuple<const char*, OUString, OUString> TOOLBARMODES_ARRAY[] =
{
    { NC_("RID_CUI_TOOLBARMODES", "Standard user interface with menu, toolbar, and collapsed sidebar. Intended to user who are familiar with the classic interface."), "Default", "default.png"},
    { NC_("RID_CUI_TOOLBARMODES", "Standard user interface but with only one toolbar. Intended for use on small screens."), "Single", "single.png"},
    { NC_("RID_CUI_TOOLBARMODES", "Standard user interface with expanded sidebar. Expert users who want to quickly change many different properties are advised to use this UI."), "Sidebar", "sidebar.png"},
    { NC_("RID_CUI_TOOLBARMODES", "The Tabbed user interface is the most similar to the Ribbons used by Microsoft. It organize functions in tabs and makes the main menu obsolete."), "notebookbar.ui", "notebookbar.png"},
    { NC_("RID_CUI_TOOLBARMODES", "The Tabbed Compact variant aims to be familiar with Microsoft's interface having at the same time a short interface for small screen sizes."), "notebookbar_compact.ui",  "notebookbar_compact.png"},
    { NC_("RID_CUI_TOOLBARMODES", "The Groupedbar Compact variant provides access to functions in groups with most frequently used features in icons and less often used in a dropdown menu. The compact variant favors vertical size."), "notebookbar_groupedbar_compact.ui", "notebookbar_groupedbar_compact.png"},
    { NC_("RID_CUI_TOOLBARMODES", "The Groupedbar interface provides access to functions in groups with most frequently used features in icons and less often used in a dropdown menu. The full variant favors functions and is slighly larger than other variants."), "notebookbar_groupedbar_full.ui", "notebookbar_groupedbar_full.png"},
    { NC_("RID_CUI_TOOLBARMODES", "The Contextual Single interface shows functions in a single line toolbar with contextual depending content."), "notebookbar_single.ui", "notebookbar_single.png"},
    { NC_("RID_CUI_TOOLBARMODES", "The Contextual Groups interface focus on beginners. It exposes to the most frequently used functions on groups with the core action as large icon and a couple of small additional features. All functions have a label. Depending on the context an additional section provides access to those functions."), "notebookbar_groups.ui", "notebookbar_groups.png"},
};

//hide experimental UIs
constexpr int nContextSingle = 7;
constexpr int nContextGroup = 8;

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx
index 4775ed0..c64362d 100644
--- a/cui/source/dialogs/tipofthedaydlg.cxx
+++ b/cui/source/dialogs/tipofthedaydlg.cxx
@@ -17,18 +17,22 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <sal/config.h>
#include <tipofthedaydlg.hxx>

#include <dialmgr.hxx>
#include <officecfg/Office/Common.hxx>
#include <osl/file.hxx>
#include <rtl/bootstrap.hxx>
#include <tipoftheday.hrc>

#include <vcl/graphicfilter.hxx>
#include <vcl/help.hxx>
#include <vcl/virdev.hxx>
#include <vcl/svapp.hxx>

#include <comphelper/dispatchcommand.hxx>
#include <comphelper/propertysequence.hxx>
#include <dialmgr.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <officecfg/Office/Common.hxx>
#include <osl/file.hxx>
#include <rtl/bootstrap.hxx>
#include <unotools/resmgr.hxx>
#include <unotools/configmgr.hxx>

@@ -108,6 +112,13 @@ void TipOfTheDayDialog::UpdateTip()
    {
        m_pLink->set_visible(false);
    }
    else if (aLink.startsWith(".uno:"))
    {
        m_pLink->set_uri(CuiResId(STR_UNO_EXECUTE).replaceFirst("%COMMAND", aLink));
        m_pLink->set_label(CuiResId(STR_UNO_LINK));
        m_pLink->set_visible(true);
        m_pLink->connect_activate_link(LINK(this, TipOfTheDayDialog, OnLinkClick));
    }
    else if (aLink.startsWith("http"))
    {
        // Links may have some %PRODUCTVERSION which need to be expanded
@@ -155,7 +166,15 @@ void TipOfTheDayDialog::UpdateTip()

IMPL_LINK_NOARG(TipOfTheDayDialog, OnLinkClick, weld::LinkButton&, bool)
{
    Application::GetHelp()->Start(aLink, static_cast<weld::Widget*>(nullptr));
    if (aLink.startsWith("http"))
    {
        Application::GetHelp()->Start(aLink, static_cast<weld::Widget*>(nullptr));
    }
    else if (aLink.startsWith(".uno:"))
    {
        comphelper::dispatchCommand(aLink, {});
        TipOfTheDayDialog::response(RET_OK);
    }
    return true;
}

diff --git a/cui/source/dialogs/toolbarmodedlg.cxx b/cui/source/dialogs/toolbarmodedlg.cxx
new file mode 100644
index 0000000..21bd705
--- /dev/null
+++ b/cui/source/dialogs/toolbarmodedlg.cxx
@@ -0,0 +1,214 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <sal/config.h>

#include <toolbarmodedlg.hxx>
#include <toolbarmode.hrc>

#include <com/sun/star/frame/ModuleManager.hpp>
#include <comphelper/dispatchcommand.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/types.hxx>
#include <dialmgr.hxx>
#include <officecfg/Office/UI/ToolbarMode.hxx>
#include <osl/file.hxx>
#include <rtl/bootstrap.hxx>
#include <sfx2/viewfrm.hxx>
#include <strings.hrc>
#include <svtools/miscopt.hxx>
#include <unotools/confignode.hxx>
#include <vcl/virdev.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/EnumContext.hxx>
#include <vcl/weld.hxx>

static OUString GetCurrentApp()
{
    OUString sResult;
    if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
    {
        const auto xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
        const auto xContext = comphelper::getProcessComponentContext();
        const auto xModuleManager = css::frame::ModuleManager::create(xContext);
        switch (vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xCurrentFrame)))
        {
            case vcl::EnumContext::Application::Writer:
                sResult = "Writer";
                break;
            case vcl::EnumContext::Application::Calc:
                sResult = "Calc";
                break;
            case vcl::EnumContext::Application::Impress:
                sResult = "Impress";
                break;
            case vcl::EnumContext::Application::Draw:
                sResult = "Draw";
                break;
            case vcl::EnumContext::Application::Formula:
                sResult = "Formula";
                break;
            case vcl::EnumContext::Application::Base:
                sResult = "Base";
                break;
            default:
                sResult = "Unsupported";
        }
    }
    return sResult;
}

static OUString GetCurrentMode()
{
    OUString sResult;
    if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
    {
        const auto xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
        const auto xContext = comphelper::getProcessComponentContext();
        const auto xModuleManager = css::frame::ModuleManager::create(xContext);
        const utl::OConfigurationTreeRoot aAppNode(
            xContext, "org.openoffice.Office.UI.ToolbarMode/Applications/" + GetCurrentApp(), true);
        if (aAppNode.isValid())
            sResult = comphelper::getString(aAppNode.getNodeValue("Active"));
    };
    return sResult;
}

ToolbarmodeDialog::ToolbarmodeDialog(weld::Window* pParent)
    : GenericDialogController(pParent, "cui/ui/toolbarmodedialog.ui", "ToolbarmodeDialog")
    , m_pImage(m_xBuilder->weld_image("imImage"))
    , m_pApply(m_xBuilder->weld_button("btnApply"))
    , m_pApplyAll(m_xBuilder->weld_button("btnApplyAll"))
    , m_pRadioButtons{ (m_xBuilder->weld_radio_button("rbButton1")),
                       (m_xBuilder->weld_radio_button("rbButton2")),
                       (m_xBuilder->weld_radio_button("rbButton3")),
                       (m_xBuilder->weld_radio_button("rbButton4")),
                       (m_xBuilder->weld_radio_button("rbButton5")),
                       (m_xBuilder->weld_radio_button("rbButton6")),
                       (m_xBuilder->weld_radio_button("rbButton7")),
                       (m_xBuilder->weld_radio_button("rbButton8")),
                       (m_xBuilder->weld_radio_button("rbButton9")) }
    , m_pInfoLabel(m_xBuilder->weld_label("lbInfo"))
{
    static_assert(SAL_N_ELEMENTS(m_pRadioButtons) == SAL_N_ELEMENTS(TOOLBARMODES_ARRAY));

    Link<weld::ToggleButton&, void> aLink = LINK(this, ToolbarmodeDialog, SelectToolbarmode);

    const OUString sCurrentMode = GetCurrentMode();
    for (unsigned long i = 0; i < SAL_N_ELEMENTS(m_pRadioButtons); i++)
    {
        m_pRadioButtons[i]->connect_toggled(aLink);
        if (sCurrentMode == std::get<1>(TOOLBARMODES_ARRAY[i]))
        {
            m_pRadioButtons[i]->set_active(true);
            UpdateImage(std::get<2>(TOOLBARMODES_ARRAY[i]));
            m_pInfoLabel->set_label(CuiResId(std::get<0>(TOOLBARMODES_ARRAY[i])));
        }
    }

    m_pApply->set_label(CuiResId(RID_SVXSTR_UI_APPLYALL).replaceFirst("%MODULE", GetCurrentApp()));
    m_pApply->connect_clicked(LINK(this, ToolbarmodeDialog, OnApplyClick));
    m_pApplyAll->connect_clicked(LINK(this, ToolbarmodeDialog, OnApplyClick));

    if (!SvtMiscOptions().IsExperimentalMode())
    {
        m_pRadioButtons[nContextSingle]->set_visible(false);
        m_pRadioButtons[nContextGroup]->set_visible(false);
    }
}

ToolbarmodeDialog::~ToolbarmodeDialog() = default;

static bool file_exists(const OUString& fileName)
{
    osl::File aFile(fileName);
    return aFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None;
}

int ToolbarmodeDialog::GetActiveRadioButton()
{
    for (unsigned long i = 0; i < SAL_N_ELEMENTS(m_pRadioButtons); i++)
    {
        if (m_pRadioButtons[i]->get_active())
            return i;
    }
    return -1;
}

void ToolbarmodeDialog::UpdateImage(OUString sFileName)
{
    // load image
    OUString aURL("$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/toolbarmode/");
    rtl::Bootstrap::expandMacros(aURL);
    aURL += sFileName;
    if (sFileName.isEmpty() || !file_exists(aURL))
        return;
    // draw image
    Graphic aGraphic;
    if (GraphicFilter::LoadGraphic(aURL, OUString(), aGraphic) == ERRCODE_NONE)
    {
        ScopedVclPtr<VirtualDevice> m_pVirDev = m_pImage->create_virtual_device();
        m_pVirDev->SetOutputSizePixel(aGraphic.GetSizePixel());
        m_pVirDev->DrawBitmapEx(Point(0, 0), aGraphic.GetBitmapEx());
        m_pImage->set_image(m_pVirDev.get());
        m_pVirDev.disposeAndClear();
    }
}

IMPL_LINK_NOARG(ToolbarmodeDialog, SelectToolbarmode, weld::ToggleButton&, void)
{
    const int i = GetActiveRadioButton();
    if (i > -1)
    {
        UpdateImage(std::get<2>(TOOLBARMODES_ARRAY[i]));
        m_pInfoLabel->set_label(CuiResId(std::get<0>(TOOLBARMODES_ARRAY[i])));
    }
}

IMPL_LINK(ToolbarmodeDialog, OnApplyClick, weld::Button&, rButton, void)
{
    const int i = GetActiveRadioButton();
    if (i == -1)
        return;
    const OUString sCmd = std::get<1>(TOOLBARMODES_ARRAY[i]);
    //apply to all except current module
    if (&rButton == m_pApplyAll.get())
    {
        std::shared_ptr<comphelper::ConfigurationChanges> aBatch(
            comphelper::ConfigurationChanges::create(::comphelper::getProcessComponentContext()));
        officecfg::Office::UI::ToolbarMode::ActiveWriter::set(sCmd, aBatch);
        officecfg::Office::UI::ToolbarMode::ActiveCalc::set(sCmd, aBatch);
        officecfg::Office::UI::ToolbarMode::ActiveImpress::set(sCmd, aBatch);
        officecfg::Office::UI::ToolbarMode::ActiveDraw::set(sCmd, aBatch);
        aBatch->commit();

        OUString sCurrentApp = GetCurrentApp();
        if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
        {
            const auto xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface();
            const auto xContext = comphelper::getProcessComponentContext();
            const auto xModuleManager = css::frame::ModuleManager::create(xContext);
            const utl::OConfigurationTreeRoot aAppNode(
                xContext, "org.openoffice.Office.UI.ToolbarMode/Applications/", true);
            if (sCurrentApp != "Writer")
                aAppNode.setNodeValue("Writer/Active", css::uno::makeAny(sCmd));
            if (sCurrentApp != "Calc")
                aAppNode.setNodeValue("Calc/Active", css::uno::makeAny(sCmd));
            if (sCurrentApp != "Impress")
                aAppNode.setNodeValue("Impress/Active", css::uno::makeAny(sCmd));
            if (sCurrentApp != "Draw")
                aAppNode.setNodeValue("Draw/Active", css::uno::makeAny(sCmd));
            aAppNode.commit();
        };
    }
    //apply to current module
    comphelper::dispatchCommand(".uno:ToolbarMode?Mode:string=" + sCmd, {});
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index 731303d..f970e4a 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -88,6 +88,7 @@
#include <hyphen.hxx>
#include <thesdlg.hxx>
#include <tipofthedaydlg.hxx>
#include <toolbarmodedlg.hxx>
#include <DiagramDialog.hxx>

using namespace ::com::sun::star;
@@ -1679,6 +1680,13 @@ AbstractDialogFactory_Impl::CreateTipOfTheDayDialog(weld::Window* pParent)
        std::make_unique<TipOfTheDayDialog>(pParent));
}

VclPtr<VclAbstractDialog>
AbstractDialogFactory_Impl::CreateToolbarmodeDialog(weld::Window* pParent)
{
    return VclPtr<CuiAbstractController_Impl>::Create(
        std::make_unique<ToolbarmodeDialog>(pParent));
}

VclPtr<AbstractDiagramDialog>
AbstractDialogFactory_Impl::CreateDiagramDialog(weld::Window* pParent, std::shared_ptr<DiagramDataInterface> pDiagramData)
{
diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx
index fd11ee4..4d0b569 100644
--- a/cui/source/factory/dlgfact.hxx
+++ b/cui/source/factory/dlgfact.hxx
@@ -941,6 +941,8 @@ public:

    virtual VclPtr<VclAbstractDialog> CreateTipOfTheDayDialog(weld::Window* pParent) override;

    virtual VclPtr<VclAbstractDialog> CreateToolbarmodeDialog(weld::Window* pParent) override;

    virtual VclPtr<AbstractDiagramDialog> CreateDiagramDialog(
        weld::Window* pParent,
        std::shared_ptr<DiagramDataInterface> pDiagramData) override;
diff --git a/cui/source/inc/toolbarmodedlg.hxx b/cui/source/inc/toolbarmodedlg.hxx
new file mode 100644
index 0000000..40d6dc8
--- /dev/null
+++ b/cui/source/inc/toolbarmodedlg.hxx
@@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <vcl/weld.hxx>

class ToolbarmodeDialog : public weld::GenericDialogController
{
public:
    ToolbarmodeDialog(weld::Window* pWindow);
    virtual ~ToolbarmodeDialog() override;

private:
    std::unique_ptr<weld::Image> m_pImage;
    std::unique_ptr<weld::Button> m_pApply;
    std::unique_ptr<weld::Button> m_pApplyAll;
    std::unique_ptr<weld::RadioButton> m_pRadioButtons[9];
    std::unique_ptr<weld::Label> m_pInfoLabel;

    void UpdateImage(OUString sFileName);
    int GetActiveRadioButton();
    DECL_LINK(SelectToolbarmode, weld::ToggleButton&, void);
    DECL_LINK(OnApplyClick, weld::Button&, void);
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/cui/uiconfig/ui/toolbarmodedialog.ui b/cui/uiconfig/ui/toolbarmodedialog.ui
new file mode 100644
index 0000000..79523b5
--- /dev/null
+++ b/cui/uiconfig/ui/toolbarmodedialog.ui
@@ -0,0 +1,381 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 -->
<interface domain="cui">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkImage" id="imgApply">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="stock">gtk-apply</property>
  </object>
  <object class="GtkDialog" id="ToolbarmodeDialog">
    <property name="can_focus">False</property>
    <property name="border_width">6</property>
    <property name="title" translatable="yes" context="ToolbarmodeDialog|Name">Select Your Preferred User Interface</property>
    <property name="resizable">False</property>
    <property name="modal">True</property>
    <property name="window_position">center-on-parent</property>
    <property name="type_hint">dialog</property>
    <child internal-child="vbox">
      <object class="GtkBox" id="dialog-vbox">
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <property name="spacing">12</property>
        <child internal-child="action_area">
          <object class="GtkButtonBox" id="dialog-action_area">
            <property name="can_focus">False</property>
            <property name="hexpand">True</property>
            <property name="layout_style">end</property>
            <child>
              <object class="GtkButton" id="btnApplyAll">
                <property name="label">A_pply to All</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="can_default">True</property>
                <property name="has_default">True</property>
                <property name="receives_default">True</property>
                <property name="use_underline">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="btnApply">
                <property name="label">A_pply to %MODULE</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="can_default">True</property>
                <property name="has_default">True</property>
                <property name="receives_default">True</property>
                <property name="image">imgApply</property>
                <property name="use_underline">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="btnClose">
                <property name="label">gtk-close</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="can_default">True</property>
                <property name="has_default">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">2</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="pack_type">end</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkBox">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkFrame">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_start">12</property>
                <property name="margin_end">12</property>
                <property name="label_xalign">0</property>
                <property name="shadow_type">none</property>
                <child>
                  <object class="GtkAlignment">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="left_padding">12</property>
                    <child>
                      <object class="GtkBox">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="orientation">vertical</property>
                        <property name="spacing">3</property>
                        <child>
                          <object class="GtkRadioButton" id="rbButton1">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton1">Standard Toolbar</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">0</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkRadioButton" id="rbButton2">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton2">Single Toolbar</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                            <property name="group">rbButton1</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">1</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkRadioButton" id="rbButton3">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton3">Sidebar</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                            <property name="group">rbButton1</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">2</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkRadioButton" id="rbButton4">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton4">Tabbed</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                            <property name="group">rbButton1</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">3</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkRadioButton" id="rbButton5">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton5">Tabbed Compact</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                            <property name="group">rbButton1</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">4</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkRadioButton" id="rbButton6">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton6">Groupedbar Compact</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                            <property name="group">rbButton1</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">5</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkRadioButton" id="rbButton7">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton7">Groupedbar</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                            <property name="group">rbButton1</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">6</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkRadioButton" id="rbButton8">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton8">Contextual Single</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                            <property name="group">rbButton1</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">7</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkRadioButton" id="rbButton9">
                            <property name="label" translatable="yes" context="ToolbarmodeDialog|radiobutton9">Contextual Groups</property>
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="receives_default">False</property>
                            <property name="halign">start</property>
                            <property name="valign">start</property>
                            <property name="active">True</property>
                            <property name="draw_indicator">True</property>
                            <property name="group">rbButton1</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">8</property>
                          </packing>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
                <child type="label">
                  <object class="GtkLabel">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="label" translatable="yes" context="ToolbarmodeDialog|leftframe">UI variants</property>
                    <attributes>
                      <attribute name="weight" value="bold"/>
                    </attributes>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkFrame">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_start">12</property>
                <property name="margin_end">12</property>
                <property name="label_xalign">0</property>
                <property name="shadow_type">none</property>
                <child>
                  <object class="GtkAlignment">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="left_padding">12</property>
                    <child>
                      <object class="GtkBox">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="orientation">vertical</property>
                        <property name="baseline_position">top</property>
                        <child>
                          <object class="GtkImage" id="imImage">
                            <property name="height_request">100</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="valign">center</property>
                            <property name="vexpand">True</property>
                            <property name="stock">gtk-missing-image</property>
                          </object>
                          <packing>
                            <property name="expand">False</property>
                            <property name="fill">True</property>
                            <property name="position">1</property>
                          </packing>
                        </child>
                        <child>
                          <object class="GtkLabel" id="lbInfo">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="valign">start</property>
                            <property name="margin_top">12</property>
                            <property name="label">Information:</property>
                            <property name="wrap">True</property>
                            <property name="wrap_mode">word-char</property>
                            <property name="max_width_chars">50</property>
                            <property name="xalign">0</property>
                          </object>
                          <packing>
                            <property name="expand">True</property>
                            <property name="fill">True</property>
                            <property name="position">1</property>
                          </packing>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
                <child type="label">
                  <object class="GtkLabel">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="label" translatable="yes" context="ToolbarmodeDialog|rightframe">Preview</property>
                    <attributes>
                      <attribute name="weight" value="bold"/>
                    </attributes>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
      </object>
    </child>
    <action-widgets>
      <action-widget response="-5">btnApplyAll</action-widget>
      <action-widget response="-5">btnApply</action-widget>
      <action-widget response="-7">btnClose</action-widget>
    </action-widgets>
    <child type="titlebar">
      <placeholder/>
    </child>
  </object>
</interface>
diff --git a/extras/source/tipoftheday/toolbarmode.png b/extras/source/tipoftheday/toolbarmode.png
new file mode 100644
index 0000000..e6e94f3
--- /dev/null
+++ b/extras/source/tipoftheday/toolbarmode.png
Binary files differ
diff --git a/extras/source/toolbarmode/default.png b/extras/source/toolbarmode/default.png
new file mode 100644
index 0000000..67c98d1
--- /dev/null
+++ b/extras/source/toolbarmode/default.png
Binary files differ
diff --git a/extras/source/toolbarmode/notebookbar.png b/extras/source/toolbarmode/notebookbar.png
new file mode 100644
index 0000000..ad4b1f9
--- /dev/null
+++ b/extras/source/toolbarmode/notebookbar.png
Binary files differ
diff --git a/extras/source/toolbarmode/notebookbar_compact.png b/extras/source/toolbarmode/notebookbar_compact.png
new file mode 100644
index 0000000..58583eb
--- /dev/null
+++ b/extras/source/toolbarmode/notebookbar_compact.png
Binary files differ
diff --git a/extras/source/toolbarmode/notebookbar_groupedbar_compact.png b/extras/source/toolbarmode/notebookbar_groupedbar_compact.png
new file mode 100644
index 0000000..52a44a1
--- /dev/null
+++ b/extras/source/toolbarmode/notebookbar_groupedbar_compact.png
Binary files differ
diff --git a/extras/source/toolbarmode/notebookbar_groupedbar_full.png b/extras/source/toolbarmode/notebookbar_groupedbar_full.png
new file mode 100644
index 0000000..50cb99c
--- /dev/null
+++ b/extras/source/toolbarmode/notebookbar_groupedbar_full.png
Binary files differ
diff --git a/extras/source/toolbarmode/notebookbar_groups.png b/extras/source/toolbarmode/notebookbar_groups.png
new file mode 100644
index 0000000..329796f
--- /dev/null
+++ b/extras/source/toolbarmode/notebookbar_groups.png
Binary files differ
diff --git a/extras/source/toolbarmode/notebookbar_single.png b/extras/source/toolbarmode/notebookbar_single.png
new file mode 100644
index 0000000..6de9b34
--- /dev/null
+++ b/extras/source/toolbarmode/notebookbar_single.png
Binary files differ
diff --git a/extras/source/toolbarmode/sidebar.png b/extras/source/toolbarmode/sidebar.png
new file mode 100644
index 0000000..e9311d4
--- /dev/null
+++ b/extras/source/toolbarmode/sidebar.png
Binary files differ
diff --git a/extras/source/toolbarmode/single.png b/extras/source/toolbarmode/single.png
new file mode 100644
index 0000000..6522e72
--- /dev/null
+++ b/extras/source/toolbarmode/single.png
Binary files differ
diff --git a/include/sfx2/sfxdlg.hxx b/include/sfx2/sfxdlg.hxx
index 9bd6008..d133e42 100644
--- a/include/sfx2/sfxdlg.hxx
+++ b/include/sfx2/sfxdlg.hxx
@@ -147,6 +147,8 @@ public:
    virtual VclPtr<VclAbstractDialog> CreateAboutDialog(weld::Window* _pParent) = 0;

    virtual VclPtr<VclAbstractDialog> CreateTipOfTheDayDialog(weld::Window* _pParent) = 0;

    virtual VclPtr<VclAbstractDialog> CreateToolbarmodeDialog(weld::Window* _pParent) = 0;
};

#endif
diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index 88d708e..8847234 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -272,6 +272,7 @@ class SvxSearchItem;
#define SID_REPLACEABLE                     (SID_SFX_START + 1739)
#define SID_ADDITIONS_DIALOG                (SID_SFX_START + 1740)
#define SID_ADDITIONS_TAG                   (SID_SFX_START + 1741)
#define SID_TOOLBAR_MODE_UI                 (SID_SFX_START + 1742)

//      SID_SFX_free_END                    (SID_SFX_START + 3999)

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index 1d807a9..240a86d 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -6229,6 +6229,14 @@
          <value>1</value>
        </prop>
      </node>
      <node oor:name=".uno:ToolbarModeUI" oor:op="replace">
        <prop oor:name="Label" oor:type="xs:string">
          <value xml:lang="en-US">User ~Interface...</value>
        </prop>
        <prop oor:name="Properties" oor:type="xs:int">
          <value>1</value>
        </prop>
      </node>
      <node oor:name=".uno:AvailableToolbars" oor:op="replace">
        <prop oor:name="Label" oor:type="xs:string">
          <value xml:lang="en-US">~Toolbars</value>
diff --git a/sfx2/sdi/appslots.sdi b/sfx2/sdi/appslots.sdi
index be81e3e..4b04948 100644
--- a/sfx2/sdi/appslots.sdi
+++ b/sfx2/sdi/appslots.sdi
@@ -155,6 +155,10 @@ interface Application
        ExecMethod = MiscExec_Impl ;
        StateMethod = MiscState_Impl ;
    ]
    SID_TOOLBAR_MODE_UI
    [
        ExecMethod = MiscExec_Impl ;
    ]
    SID_AVAILABLE_TOOLBARS
    [
        ExecMethod = MiscExec_Impl ;
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index a50b5f1..a0de55d 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -5257,6 +5257,22 @@ SfxVoidItem ToolbarMode SID_TOOLBAR_MODE
    GroupId = SfxGroupId::Application;
]

SfxVoidItem ToolbarModeUI SID_TOOLBAR_MODE_UI
[
    AutoUpdate = FALSE,
    FastCall = FALSE,
    ReadOnlyDoc = FALSE,
    Toggle = FALSE,
    Container = FALSE,
    RecordAbsolute = FALSE,
    RecordPerSet;

    AccelConfig = TRUE,
    MenuConfig = TRUE,
    ToolBoxConfig = TRUE,
    GroupId = SfxGroupId::Application;
]

SfxVoidItem AvailableToolbars SID_AVAILABLE_TOOLBARS
(SfxStringItem Toolbar SID_AVAILABLE_TOOLBARS)
[
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index b07974a..4f6564d 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -962,6 +962,15 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
            bDone = true;
            break;
        }
        case SID_TOOLBAR_MODE_UI:
        {
            SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
            ScopedVclPtr<VclAbstractDialog> pDlg(
                pFact->CreateToolbarmodeDialog(rReq.GetFrameWeld()));
            pDlg->Execute();
            bDone = true;
            break;
        }
        case SID_AVAILABLE_TOOLBARS:
        {
            const SfxStringItem* pToolbarName = rReq.GetArg<SfxStringItem>(SID_AVAILABLE_TOOLBARS);
diff --git a/solenv/sanitizers/ui/cui.suppr b/solenv/sanitizers/ui/cui.suppr
index d9d1260..c960dd2 100644
--- a/solenv/sanitizers/ui/cui.suppr
+++ b/solenv/sanitizers/ui/cui.suppr
@@ -276,3 +276,4 @@ cui/uiconfig/ui/wordcompletionpage.ui://GtkSpinButton[@id='maxentries'] duplicat
cui/uiconfig/ui/bulletandposition.ui://GtkToggleButton[@id='left'] button-no-label
cui/uiconfig/ui/bulletandposition.ui://GtkToggleButton[@id='center'] button-no-label
cui/uiconfig/ui/bulletandposition.ui://GtkToggleButton[@id='right'] button-no-label
cui/uiconfig/ui/toolbarmodedialog.ui://GtkLabel[@id='lbInfo'] orphan-label
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 4368770..05fe05b 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -24,6 +24,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
    Package_opengl_shader \
    Package_theme_definitions \
    Package_tipoftheday \
    Package_toolbarmode \
    UIConfig_vcl \
    $(if $(filter WNT,$(OS)), \
        Package_opengl_denylist ) \
diff --git a/vcl/Package_tipoftheday.mk b/vcl/Package_tipoftheday.mk
index 18a0867..ea81ee9 100644
--- a/vcl/Package_tipoftheday.mk
+++ b/vcl/Package_tipoftheday.mk
@@ -15,6 +15,7 @@ $(eval $(call gb_Package_add_files_with_dir,tipoftheday_images,$(LIBO_SHARE_FOLD
	tipoftheday_c.png \
	tipoftheday_i.png \
	tipoftheday_d.png \
	toolbarmode.png \
))

# vim: set noet sw=4 ts=4:
diff --git a/vcl/Package_toolbarmode.mk b/vcl/Package_toolbarmode.mk
new file mode 100644
index 0000000..9421001
--- /dev/null
+++ b/vcl/Package_toolbarmode.mk
@@ -0,0 +1,24 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

$(eval $(call gb_Package_Package,toolbarmode_images,$(SRCDIR)/extras/source/toolbarmode))

$(eval $(call gb_Package_add_files_with_dir,toolbarmode_images,$(LIBO_SHARE_FOLDER)/toolbarmode,\
    default.png \
    single.png \
    sidebar.png \
    notebookbar.png \
    notebookbar_compact.png \
    notebookbar_groupedbar_compact.png \
    notebookbar_groupedbar_full.png \
    notebookbar_single.png \
    notebookbar_groups.png \
))

# vim: set noet sw=4 ts=4: