editeng/source/items/textitem.cxx      |    2 ++
 include/sfx2/objsh.hxx                 |    1 +
 include/svx/ColorSets.hxx              |    2 ++
 include/svx/strings.hrc                |   13 +++++++++++++
 sd/source/ui/docshell/docshell.cxx     |   25 +++++++++++++++++++++++++
 sd/source/ui/inc/DrawDocShell.hxx      |    2 ++
 sfx2/source/doc/objcont.cxx            |    2 ++
 svx/source/styles/ColorSets.cxx        |   15 +++++++++++++++
 svx/source/tbxctrls/PaletteManager.cxx |   27 +++++++++++++++++++++++++--
 9 files changed, 87 insertions(+), 2 deletions(-)

New commits:
commit 4bbbd15fb8e8269a8bdfd188d3ca2a2a84c00922
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Dec 17 09:19:20 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Dec 17 11:40:09 2021 +0100

    sd theme: add a "theme" palette to the color picker
    
    This implements listing the current theme colors (which depend on what
    is the master page of the current slide) in the color picker and also
    allows picking those colors.
    
    The colors are picked as-is for now, not yet setting the color theme
    index in the document model.
    
    Change-Id: I2553725c29c2a9f9de80f86b38d22a06bf9c0364
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126994
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/editeng/source/items/textitem.cxx 
b/editeng/source/items/textitem.cxx
index 32c269480c5a..f3338f300567 100644
--- a/editeng/source/items/textitem.cxx
+++ b/editeng/source/items/textitem.cxx
@@ -1521,6 +1521,8 @@ void SvxColorItem::dumpAsXml(xmlTextWriterPtr pWriter) 
const
     std::stringstream ss;
     ss << mColor;
     (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), 
BAD_CAST(ss.str().c_str()));
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("theme-index"),
+                                      
BAD_CAST(OString::number(maThemeIndex).getStr()));
 
     OUString aStr;
     IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index cbdf256c6c67..553489e14aa9 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -558,6 +558,7 @@ public:
     StarBASIC*                  GetBasic() const;
 
     virtual std::set<Color>     GetDocColors();
+    virtual std::vector<Color> GetThemeColors();
 
     // Accessibility Check
     virtual sfx::AccessibilityIssueCollection runAccessibilityCheck();
diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx
index c4aa0ae2b9bc..ac9008cbeb32 100644
--- a/include/svx/ColorSets.hxx
+++ b/include/svx/ColorSets.hxx
@@ -92,6 +92,8 @@ public:
     static std::unique_ptr<Theme> FromAny(const css::uno::Any& rVal);
 
     void UpdateSdrPage(SdrPage* pPage);
+
+    std::vector<Color> GetColors() const;
 };
 
 } // end of namespace svx
diff --git a/include/svx/strings.hrc b/include/svx/strings.hrc
index 8505c410a3df..2e00e3c4c1a7 100644
--- a/include/svx/strings.hrc
+++ b/include/svx/strings.hrc
@@ -1118,7 +1118,20 @@
 #define RID_SVXSTR_CHARFONTNAME_NOTAVAILABLE                
NC_("RID_SVXSTR_CHARFONTNAME_NOTAVAILABLE", "Font Name. The current font is not 
available and will be substituted.")
 #define RID_SVXSTR_CUSTOM_PAL                               
NC_("RID_SVXSTR_CUSTOM_PAL", "custom")
 #define RID_SVXSTR_DOC_COLORS                               
NC_("RID_SVXSTR_DOC_COLORS", "Document colors")
+#define RID_SVXSTR_THEME_COLORS                             
NC_("RID_SVXSTR_THEME_COLORS", "Theme colors")
 #define RID_SVXSTR_DOC_COLOR_PREFIX                         
NC_("RID_SVXSTR_DOC_COLOR_PREFIX", "Document Color")
+#define RID_SVXSTR_THEME_COLOR1                             
NC_("RID_SVXSTR_THEME_COLOR1", "Background - Dark 1")
+#define RID_SVXSTR_THEME_COLOR2                             
NC_("RID_SVXSTR_THEME_COLOR2", "Text - Light 1")
+#define RID_SVXSTR_THEME_COLOR3                             
NC_("RID_SVXSTR_THEME_COLOR3", "Background - Dark 2")
+#define RID_SVXSTR_THEME_COLOR4                             
NC_("RID_SVXSTR_THEME_COLOR4", "Text - Light 2")
+#define RID_SVXSTR_THEME_COLOR5                             
NC_("RID_SVXSTR_THEME_COLOR5", "Accent 1")
+#define RID_SVXSTR_THEME_COLOR6                             
NC_("RID_SVXSTR_THEME_COLOR6", "Accent 2")
+#define RID_SVXSTR_THEME_COLOR7                             
NC_("RID_SVXSTR_THEME_COLOR7", "Accent 3")
+#define RID_SVXSTR_THEME_COLOR8                             
NC_("RID_SVXSTR_THEME_COLOR8", "Accent 4")
+#define RID_SVXSTR_THEME_COLOR9                             
NC_("RID_SVXSTR_THEME_COLOR9", "Accent 5")
+#define RID_SVXSTR_THEME_COLOR10                            
NC_("RID_SVXSTR_THEME_COLOR10", "Accent 6")
+#define RID_SVXSTR_THEME_COLOR11                            
NC_("RID_SVXSTR_THEME_COLOR11", "Hyperlink")
+#define RID_SVXSTR_THEME_COLOR12                            
NC_("RID_SVXSTR_THEME_COLOR12", "Followed Hyperlink")
 
 #define RID_SVX_EXTRUSION_BAR                               
NC_("RID_SVX_EXTRUSION_BAR", "Extrusion")
 #define RID_SVXSTR_UNDO_APPLY_EXTRUSION_ON_OFF              
NC_("RID_SVXSTR_UNDO_APPLY_EXTRUSION_ON_OFF", "Apply Extrusion On/Off")
diff --git a/sd/source/ui/docshell/docshell.cxx 
b/sd/source/ui/docshell/docshell.cxx
index 886efb0f7acb..78279687a039 100644
--- a/sd/source/ui/docshell/docshell.cxx
+++ b/sd/source/ui/docshell/docshell.cxx
@@ -59,6 +59,8 @@
 #include <ViewShellBase.hxx>
 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
 #include <comphelper/lok.hxx>
+#include <DrawViewShell.hxx>
+#include <sdpage.hxx>
 
 using namespace sd;
 #define ShellClass_DrawDocShell
@@ -485,6 +487,29 @@ void DrawDocShell::ClearUndoBuffer()
         pUndoManager->Clear();
 }
 
+std::vector<Color> DrawDocShell::GetThemeColors()
+{
+    auto pViewShell = dynamic_cast<sd::DrawViewShell*>(GetViewShell());
+    if (!pViewShell)
+    {
+        return {};
+    }
+
+    SdPage* pPage = pViewShell->getCurrentPage();
+    svx::Theme* pTheme = pPage->getSdrPageProperties().GetTheme();
+    if (!pPage->IsMasterPage())
+    {
+        pTheme = pPage->TRG_GetMasterPage().getSdrPageProperties().GetTheme();
+    }
+
+    if (!pTheme)
+    {
+        return {};
+    }
+
+    return pTheme->GetColors();
+}
+
 } // end of namespace sd
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/inc/DrawDocShell.hxx 
b/sd/source/ui/inc/DrawDocShell.hxx
index 850d4f448a03..5f15ffe9922f 100644
--- a/sd/source/ui/inc/DrawDocShell.hxx
+++ b/sd/source/ui/inc/DrawDocShell.hxx
@@ -201,6 +201,8 @@ public:
 
     void                    ClearUndoBuffer();
 
+    std::vector<Color> GetThemeColors() override;
+
 protected:
 
     SdDrawDocument*         mpDoc;
diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx
index fa1d444bb6be..8313cfc3dc75 100644
--- a/sfx2/source/doc/objcont.cxx
+++ b/sfx2/source/doc/objcont.cxx
@@ -321,6 +321,8 @@ std::set<Color> SfxObjectShell::GetDocColors()
     return empty;
 }
 
+std::vector<Color> SfxObjectShell::GetThemeColors() { return 
std::vector<Color>(); }
+
 sfx::AccessibilityIssueCollection SfxObjectShell::runAccessibilityCheck()
 {
     sfx::AccessibilityIssueCollection aCollection;
diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx
index 30a9dd423d78..c77e6ccf2d76 100644
--- a/svx/source/styles/ColorSets.cxx
+++ b/svx/source/styles/ColorSets.cxx
@@ -312,6 +312,21 @@ void Theme::UpdateSdrPage(SdrPage* pPage)
     }
 }
 
+std::vector<Color> Theme::GetColors() const
+{
+    if (!mpColorSet)
+    {
+        return {};
+    }
+
+    std::vector<Color> aColors;
+    for (size_t i = 0; i < 12; ++i)
+    {
+        aColors.push_back(mpColorSet->getColor(i));
+    }
+    return aColors;
+}
+
 } // end of namespace svx
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/tbxctrls/PaletteManager.cxx 
b/svx/source/tbxctrls/PaletteManager.cxx
index d2395778ff8f..8b0a85deb101 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -45,7 +45,7 @@
 
 PaletteManager::PaletteManager() :
     
mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()),
-    mnNumOfPalettes(2),
+    mnNumOfPalettes(3),
     mnCurrentPalette(0),
     mnColorCount(0),
     mpBtnUpdater(nullptr),
@@ -141,6 +141,28 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet 
&rColorSet)
             ++nIx;
         }
     }
+    else if (mnCurrentPalette == mnNumOfPalettes - 2)
+    {
+        SfxObjectShell* pObjectShell = SfxObjectShell::Current();
+        if (pObjectShell)
+        {
+            std::vector<Color> aColors = pObjectShell->GetThemeColors();
+            mnColorCount = aColors.size();
+            rColorSet.Clear();
+            std::vector<OUString> aNames = {
+                SvxResId(RID_SVXSTR_THEME_COLOR1),  
SvxResId(RID_SVXSTR_THEME_COLOR2),
+                SvxResId(RID_SVXSTR_THEME_COLOR3),  
SvxResId(RID_SVXSTR_THEME_COLOR4),
+                SvxResId(RID_SVXSTR_THEME_COLOR5),  
SvxResId(RID_SVXSTR_THEME_COLOR6),
+                SvxResId(RID_SVXSTR_THEME_COLOR7),  
SvxResId(RID_SVXSTR_THEME_COLOR8),
+                SvxResId(RID_SVXSTR_THEME_COLOR9),  
SvxResId(RID_SVXSTR_THEME_COLOR10),
+                SvxResId(RID_SVXSTR_THEME_COLOR11), 
SvxResId(RID_SVXSTR_THEME_COLOR12),
+            };
+            for (int i = 0; i < 12; ++i)
+            {
+                rColorSet.InsertItem(i, aColors[i], aNames[i]);
+            }
+        }
+    }
     else if( mnCurrentPalette == mnNumOfPalettes - 1 )
     {
         // Add doc colors to palette
@@ -188,6 +210,7 @@ std::vector<OUString> PaletteManager::GetPaletteList()
     {
         aPaletteNames.push_back( (*it).GetName() );
     }
+    aPaletteNames.push_back(SvxResId(RID_SVXSTR_THEME_COLORS));
     aPaletteNames.push_back( SvxResId ( RID_SVXSTR_DOC_COLORS ) );
 
     return aPaletteNames;
@@ -245,7 +268,7 @@ OUString PaletteManager::GetPaletteName()
 
 OUString PaletteManager::GetSelectedPalettePath()
 {
-    if(mnCurrentPalette != mnNumOfPalettes - 1 && mnCurrentPalette != 0)
+    if (mnCurrentPalette < m_Palettes.size() && mnCurrentPalette != 0)
         return m_Palettes[mnCurrentPalette - 1]->GetPath();
     else
         return OUString();

Reply via email to