include/sfx2/sfxsids.hrc                                             |    1 
 include/svx/dialog/ThemeDialog.hxx                                   |   42 ++
 include/svx/theme/IThemeColorChanger.hxx                             |   26 +
 officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu |    8 
 svx/Library_svx.mk                                                   |    1 
 svx/UIConfig_svx.mk                                                  |    1 
 svx/sdi/svx.sdi                                                      |   17 +
 svx/source/dialog/ThemeDialog.cxx                                    |   63 
++++
 svx/uiconfig/ui/themedialog.ui                                       |  145 
++++++++++
 sw/sdi/_basesh.sdi                                                   |    7 
 sw/source/core/inc/ThemeColorChanger.hxx                             |    7 
 sw/source/core/model/ThemeColorChanger.cxx                           |    2 
 sw/source/uibase/shells/basesh.cxx                                   |   26 +
 sw/uiconfig/sglobal/menubar/menubar.xml                              |    1 
 sw/uiconfig/swriter/menubar/menubar.xml                              |    1 
 15 files changed, 346 insertions(+), 2 deletions(-)

New commits:
commit d4e4a2b96a787b4f99d68d7a417c37c97b47c170
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Jan 10 20:21:31 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sat Jan 14 12:26:15 2023 +0000

    ThemeDialog added which allows to change the theme used by the doc.
    
    ThemeDialog is a common dialog that can be used to select the
    theme used by the document. Currently it only implements colors
    but in the future also the fonts and formats (for shapes) will
    be adde.
    
    The IThemeColorChanger interface is used by the dialog to change
    the actual color values inside the document. For the writer the
    existing ThemeColorChanger is now implementing the interface.
    
    The dialog is accessible in Writer at Format -> Theme... in the
    main menu.
    
    Change-Id: I23c7dc9668cdc5427f36d604a76c433d6dbef497
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145264
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index e911e1d0d65d..4fb5892ba84b 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -469,6 +469,7 @@ class SvxZoomItem;
 #define SID_ACCESSIBILITY_CHECK             (SID_SFX_START + 812)
 #define SID_ASYNCHRON                       (SID_SFX_START + 813)
 #define SID_ACCESSIBILITY_CHECK_ONLINE      (SID_SFX_START + 814)
+#define SID_THEME_DIALOG                    (SID_SFX_START + 815)
 
 // default-ids for configuration
 #define SID_CONFIG                          (SID_SFX_START + 904)
diff --git a/include/svx/dialog/ThemeDialog.hxx 
b/include/svx/dialog/ThemeDialog.hxx
new file mode 100644
index 000000000000..968c54af9e98
--- /dev/null
+++ b/include/svx/dialog/ThemeDialog.hxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 <svx/svxdllapi.h>
+#include <vcl/weld.hxx>
+#include <svx/ColorSets.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/theme/IThemeColorChanger.hxx>
+#include <svx/dialog/ThemeColorValueSet.hxx>
+
+namespace svx
+{
+class SVX_DLLPUBLIC ThemeDialog final : public weld::GenericDialogController
+{
+private:
+    svx::Theme* mpTheme;
+    svx::ColorSets maColorSets;
+    std::shared_ptr<IThemeColorChanger> mpChanger;
+
+    std::unique_ptr<svx::ThemeColorValueSet> mxValueSetThemeColors;
+    std::unique_ptr<weld::CustomWeld> mxValueSetThemeColorsWindow;
+
+public:
+    ThemeDialog(weld::Window* pParent, svx::Theme* pTheme,
+                std::shared_ptr<IThemeColorChanger> const& pChanger);
+    virtual ~ThemeDialog() override;
+
+    DECL_LINK(DoubleClickValueSetHdl, ValueSet*, void);
+    void DoubleClickHdl();
+};
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/theme/IThemeColorChanger.hxx 
b/include/svx/theme/IThemeColorChanger.hxx
new file mode 100644
index 000000000000..5f90f273ee37
--- /dev/null
+++ b/include/svx/theme/IThemeColorChanger.hxx
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 <svx/svxdllapi.h>
+#include <svx/ColorSets.hxx>
+
+namespace svx
+{
+class SVX_DLLPUBLIC IThemeColorChanger
+{
+public:
+    virtual ~IThemeColorChanger() = default;
+    virtual void apply(svx::ColorSet const& rColorSet) = 0;
+};
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git 
a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index 9fa3b776f790..250d641f3b25 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -7465,6 +7465,14 @@ bit 3 (0x8): #define 
UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON 8
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:ThemeDialog" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Theme...</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:SidebarDeck.PropertyDeck" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">Open the Properties Deck</value>
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index 9021b46d7f1b..f4b2befd5394 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -175,6 +175,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
     svx/source/dialog/swframeexample \
     svx/source/dialog/swframeposstrings \
     svx/source/dialog/ThemeColorValueSet \
+    svx/source/dialog/ThemeDialog \
     svx/source/dialog/txencbox \
     svx/source/dialog/txenctab \
     svx/source/dialog/weldeditview \
diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk
index 33bc1797f20f..9f12a4819b53 100644
--- a/svx/UIConfig_svx.mk
+++ b/svx/UIConfig_svx.mk
@@ -142,6 +142,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\
        svx/uiconfig/ui/textcontrolchardialog \
        svx/uiconfig/ui/textcontrolparadialog \
        svx/uiconfig/ui/textunderlinecontrol \
+       svx/uiconfig/ui/themedialog \
        svx/uiconfig/ui/toolbarpopover \
        svx/uiconfig/ui/xmlsecstatmenu \
        svx/uiconfig/ui/xformspage \
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index 82c5700db86b..6710fdf145a7 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -12529,6 +12529,23 @@ SfxVoidItem GraphicSizeCheck SID_GRAPHIC_SIZE_CHECK
     GroupId = SfxGroupId::Modify;
 ]
 
+SfxVoidItem ThemeDialog SID_THEME_DIALOG
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+    AccelConfig = FALSE,
+    MenuConfig = FALSE,
+    ToolBoxConfig = FALSE,
+    GroupId = SfxGroupId::Modify;
+]
+
 SfxVoidItem AccessibilityCheck SID_ACCESSIBILITY_CHECK
 ()
 [
diff --git a/svx/source/dialog/ThemeDialog.cxx 
b/svx/source/dialog/ThemeDialog.cxx
new file mode 100644
index 000000000000..449a466e88e4
--- /dev/null
+++ b/svx/source/dialog/ThemeDialog.cxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 <svx/dialog/ThemeDialog.hxx>
+#include <docmodel/theme/ThemeColor.hxx>
+#include <vcl/svapp.hxx>
+
+namespace svx
+{
+ThemeDialog::ThemeDialog(weld::Window* pParent, svx::Theme* pTheme,
+                         std::shared_ptr<IThemeColorChanger> const& pChanger)
+    : GenericDialogController(pParent, "svx/ui/themedialog.ui", "ThemeDialog")
+    , mpTheme(pTheme)
+    , mpChanger(pChanger)
+    , mxValueSetThemeColors(new svx::ThemeColorValueSet)
+    , mxValueSetThemeColorsWindow(
+          new weld::CustomWeld(*m_xBuilder, "valueset_theme_colors", 
*mxValueSetThemeColors))
+{
+    mxValueSetThemeColors->SetColCount(2);
+    mxValueSetThemeColors->SetLineCount(6);
+    
mxValueSetThemeColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
+    mxValueSetThemeColors->SetDoubleClickHdl(LINK(this, ThemeDialog, 
DoubleClickValueSetHdl));
+
+    maColorSets.init();
+    maColorSets.insert(*mpTheme->GetColorSet());
+
+    for (auto const& rColorSet : maColorSets.getColorSets())
+    {
+        mxValueSetThemeColors->insert(rColorSet);
+    }
+
+    mxValueSetThemeColors->SetOptimalSize();
+
+    if (!maColorSets.getColorSets().empty())
+        mxValueSetThemeColors->SelectItem(1); // ItemId 1, position 0
+}
+
+ThemeDialog::~ThemeDialog() = default;
+
+IMPL_LINK_NOARG(ThemeDialog, DoubleClickValueSetHdl, ValueSet*, void) { 
DoubleClickHdl(); }
+
+void ThemeDialog::DoubleClickHdl()
+{
+    sal_uInt32 nItemId = mxValueSetThemeColors->GetSelectedItemId();
+    if (!nItemId)
+        return;
+
+    sal_uInt32 nIndex = nItemId - 1;
+
+    svx::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex);
+
+    mpChanger->apply(rColorSet);
+}
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/uiconfig/ui/themedialog.ui b/svx/uiconfig/ui/themedialog.ui
new file mode 100644
index 000000000000..90aecc8ad1c9
--- /dev/null
+++ b/svx/uiconfig/ui/themedialog.ui
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.40.0 -->
+<interface domain="svx">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkDialog" id="ThemeDialog">
+    <property name="width-request">640</property>
+    <property name="height-request">480</property>
+    <property name="can-focus">False</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="border-width">6</property>
+    <property name="title" translatable="yes" 
context="themedialog|Title">Theme</property>
+    <property name="type-hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialogBox1">
+        <property name="can-focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialogButtons">
+            <property name="can-focus">False</property>
+            <property name="layout-style">end</property>
+            <child>
+              <object class="GtkButton" id="help">
+                <property name="label" translatable="yes" 
context="stock">_Help</property>
+                <property name="visible">True</property>
+                <property name="can-focus">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="ok">
+                <property name="label" translatable="yes" 
context="stock">_OK</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">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="cancel">
+                <property name="label" translatable="yes" 
context="stock">_Cancel</property>
+                <property name="visible">True</property>
+                <property name="can-focus">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">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack-type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkNotebook">
+            <property name="visible">True</property>
+            <property name="can-focus">True</property>
+            <property name="hexpand">False</property>
+            <property name="vexpand">True</property>
+            <child>
+              <!-- n-columns=1 n-rows=1 -->
+              <object class="GtkGrid">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <child>
+                  <object class="GtkScrolledWindow" id="scroll_window">
+                    <property name="visible">True</property>
+                    <property name="can-focus">True</property>
+                    <property name="hexpand">False</property>
+                    <property name="vexpand">False</property>
+                    <property name="hscrollbar-policy">never</property>
+                    <property name="vscrollbar-policy">never</property>
+                    <property name="shadow-type">in</property>
+                    <child>
+                      <object class="GtkViewport">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <child>
+                          <object class="GtkDrawingArea" 
id="valueset_theme_colors">
+                            <property name="visible">True</property>
+                            <property name="can-focus">False</property>
+                            <property name="events">GDK_BUTTON_PRESS_MASK | 
GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | 
GDK_STRUCTURE_MASK</property>
+                            <property name="hexpand">True</property>
+                            <property name="vexpand">True</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left-attach">0</property>
+                    <property name="top-attach">0</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="label" translatable="yes" 
context="themedialog|tab-label">Colors</property>
+              </object>
+              <packing>
+                <property name="tab-fill">False</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-11">help</action-widget>
+      <action-widget response="-5">ok</action-widget>
+      <action-widget response="-6">cancel</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/sw/sdi/_basesh.sdi b/sw/sdi/_basesh.sdi
index 5ac4cb001eb3..a1468ffac8b1 100644
--- a/sw/sdi/_basesh.sdi
+++ b/sw/sdi/_basesh.sdi
@@ -617,4 +617,11 @@ interface BaseTextSelection
         StateMethod = GetState;
         DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
     ]
+
+    SID_THEME_DIALOG
+    [
+        ExecMethod = ExecDlg;
+        StateMethod = GetState;
+        DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
+    ]
 }
diff --git a/sw/source/core/inc/ThemeColorChanger.hxx 
b/sw/source/core/inc/ThemeColorChanger.hxx
index 0698126da3e9..d4ba7a9fcad5 100644
--- a/sw/source/core/inc/ThemeColorChanger.hxx
+++ b/sw/source/core/inc/ThemeColorChanger.hxx
@@ -11,10 +11,11 @@
 
 #include <docsh.hxx>
 #include <svx/ColorSets.hxx>
+#include <svx/theme/IThemeColorChanger.hxx>
 
 namespace sw
 {
-class ThemeColorChanger
+class ThemeColorChanger : public svx::IThemeColorChanger
 {
 private:
     SwDocShell* mpDocSh;
@@ -25,7 +26,9 @@ public:
     {
     }
 
-    void apply(svx::ColorSet const& rColorSet);
+    virtual ~ThemeColorChanger() override;
+
+    void apply(svx::ColorSet const& rColorSet) override;
 };
 
 } // end sw namespace
diff --git a/sw/source/core/model/ThemeColorChanger.cxx 
b/sw/source/core/model/ThemeColorChanger.cxx
index ff59c474748b..4c739547685b 100644
--- a/sw/source/core/model/ThemeColorChanger.cxx
+++ b/sw/source/core/model/ThemeColorChanger.cxx
@@ -229,6 +229,8 @@ void changeColor(SwFormat* pFormat, svx::ColorSet const& 
rColorSet, SwDoc* pDocu
 
 } // end anonymous namespace
 
+ThemeColorChanger::~ThemeColorChanger() {}
+
 void ThemeColorChanger::apply(svx::ColorSet const& rColorSet)
 {
     SwDoc* pDocument = mpDocSh->GetDoc();
diff --git a/sw/source/uibase/shells/basesh.cxx 
b/sw/source/uibase/shells/basesh.cxx
index 2e7489fda6de..44759890e695 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -80,8 +80,11 @@
 #include <strings.hrc>
 #include <unotxdoc.hxx>
 #include <doc.hxx>
+#include <drawdoc.hxx>
 #include <IDocumentSettingAccess.hxx>
+#include <IDocumentDrawModelAccess.hxx>
 #include <IDocumentUndoRedo.hxx>
+#include <ThemeColorChanger.hxx>
 #include <swabstdlg.hxx>
 #include <modcfg.hxx>
 #include <svx/fmshell.hxx>
@@ -94,6 +97,7 @@
 #include <memory>
 
 #include <svx/unobrushitemhelper.hxx>
+#include <svx/dialog/ThemeDialog.hxx>
 #include <comphelper/scopeguard.hxx>
 #include <comphelper/lok.hxx>
 #include <osl/diagnose.h>
@@ -2203,6 +2207,10 @@ void SwBaseShell::GetState( SfxItemSet &rSet )
                     rSet.DisableItem(nWhich);
             }
             break;
+            case SID_THEME_DIALOG:
+            {
+            }
+            break;
         }
         nWhich = aIter.NextWhich();
     }
@@ -3028,6 +3036,24 @@ void SwBaseShell::ExecDlg(SfxRequest &rReq)
         }
         break;
 
+        case SID_THEME_DIALOG:
+        {
+            auto* pDocument = rSh.GetDoc();
+            auto* pDocumentShell = pDocument->GetDocShell();
+            if (pDocumentShell)
+            {
+                SdrPage* pPage = 
pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
+                svx::Theme* pTheme = pPage->getSdrPageProperties().GetTheme();
+                if (pTheme)
+                {
+                    std::shared_ptr<svx::IThemeColorChanger> pChanger(new 
sw::ThemeColorChanger(pDocumentShell));
+                    auto pDialog = std::make_shared<svx::ThemeDialog>(pMDI, 
pTheme, pChanger);
+                    weld::DialogController::runAsync(pDialog, [](int) {});
+                }
+            }
+        }
+        break;
+
         default:OSL_FAIL("wrong Dispatcher (basesh.cxx)");
     }
     if(!bDone)
diff --git a/sw/uiconfig/sglobal/menubar/menubar.xml 
b/sw/uiconfig/sglobal/menubar/menubar.xml
index b933889b88f2..9b9d37689f10 100644
--- a/sw/uiconfig/sglobal/menubar/menubar.xml
+++ b/sw/uiconfig/sglobal/menubar/menubar.xml
@@ -443,6 +443,7 @@
       <menu:menuitem menu:id=".uno:FontDialog"/>
       <menu:menuitem menu:id=".uno:ParagraphDialog"/>
       <menu:menuitem menu:id=".uno:OutlineBullet"/>
+      <menu:menuitem menu:id=".uno:ThemeDialog"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:PageDialog"/>
       <menu:menuitem menu:id=".uno:TitlePageDialog" menu:style="text"/>
diff --git a/sw/uiconfig/swriter/menubar/menubar.xml 
b/sw/uiconfig/swriter/menubar/menubar.xml
index 3b48071edb82..295dfe7280c6 100644
--- a/sw/uiconfig/swriter/menubar/menubar.xml
+++ b/sw/uiconfig/swriter/menubar/menubar.xml
@@ -454,6 +454,7 @@
         </menu:menupopup>
       </menu:menu>
       <menu:menuitem menu:id=".uno:OutlineBullet"/>
+      <menu:menuitem menu:id=".uno:ThemeDialog"/>
       <menu:menuseparator/>
       <menu:menuitem menu:id=".uno:PageDialog"/>
       <menu:menuitem menu:id=".uno:TitlePageDialog"/>

Reply via email to