include/svl/style.hxx                              |    3 -
 svx/source/tbxctrls/StylesPreviewWindow.cxx        |   50 +++++++++++++++------
 sw/inc/format.hxx                                  |    2 
 sw/qa/uitest/writer_tests4/tdf167956.py            |    2 
 sw/source/core/attr/format.cxx                     |   19 +++++++
 sw/source/uibase/app/docstyle.cxx                  |   14 +++++
 sw/source/writerfilter/dmapper/StyleSheetTable.cxx |    1 
 7 files changed, 75 insertions(+), 16 deletions(-)

New commits:
commit 2260fa5381ec1274a142e9b45f11ee5b8a176db2
Author:     Szymon Kłos <[email protected]>
AuthorDate: Mon Nov 17 08:29:11 2025 +0000
Commit:     Szymon Kłos <[email protected]>
CommitDate: Sat Nov 29 09:24:58 2025 +0100

    notebookbar: style previews should show user defined styles
    
    - favourites are only supported in docx so far
    - user defined were previously shown too
    - avoid duplicates in the icon view
    
    Change-Id: Ic58c8a2e036d8b218c992999310357335ebdd553
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194094
    (cherry picked from commit 46914195fb557f573a25b7b9a297d5d4c16f0d7e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194625
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <[email protected]>

diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx 
b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index cf7400b08efd..983228980851 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -520,7 +520,10 @@ void StylesPreviewWindow_Base::Select(const OUString& 
rStyleName)
 
 void StylesPreviewWindow_Base::UpdateSelection()
 {
-    for (std::vector<std::pair<OUString, OUString>>::size_type i = 0; i < 
m_aAllStyles.size(); ++i)
+    if (!m_xStylesView || !m_xStylesView->n_children())
+        return;
+
+    for (StylePreviewList::size_type i = 0; i < m_aAllStyles.size(); ++i)
     {
         if (m_aAllStyles[i].first == m_sSelectedStyle || 
m_aAllStyles[i].second == m_sSelectedStyle)
         {
@@ -607,6 +610,36 @@ OString 
StylesPreviewWindow_Base::GetCachedPreviewJson(const StylePreviewDescrip
     return sResult;
 }
 
+namespace
+{
+inline void lcl_AppendParaStyles(StylePreviewList& rAllStyles, 
SfxStyleSheetBasePool* pPool,
+                                 SfxStyleSearchBits eBits)
+{
+    if (!pPool)
+        return;
+
+    auto xIter = pPool->CreateIterator(SfxStyleFamily::Para, eBits);
+
+    SfxStyleSheetBase* pStyle = xIter->First();
+
+    while (pStyle)
+    {
+        const OUString sName(pStyle->GetName());
+
+        // do not duplicate
+        const auto aFound = std::find_if(
+            rAllStyles.begin(), rAllStyles.end(), [sName](const 
StylePreviewDescriptor& element) {
+                return element.first == sName || element.second == sName;
+            });
+
+        if (aFound == rAllStyles.end())
+            rAllStyles.push_back(StylePreviewDescriptor(sName, sName));
+
+        pStyle = xIter->Next();
+    }
+}
+}
+
 void StylesPreviewWindow_Base::UpdateStylesList()
 {
     m_aAllStyles = m_aDefaultStyles;
@@ -615,20 +648,13 @@ void StylesPreviewWindow_Base::UpdateStylesList()
     SfxStyleSheetBasePool* pStyleSheetPool = nullptr;
 
     if (pDocShell)
-        pStyleSheetPool = pDocShell->GetStyleSheetPool();
-
-    if (pStyleSheetPool)
     {
-        auto xIter
-            = pStyleSheetPool->CreateIterator(SfxStyleFamily::Para, 
SfxStyleSearchBits::Favourite);
-
-        SfxStyleSheetBase* pStyle = xIter->First();
+        pStyleSheetPool = pDocShell->GetStyleSheetPool();
 
-        while (pStyle)
+        if (pStyleSheetPool)
         {
-            OUString sName(pStyle->GetName());
-            m_aAllStyles.push_back(std::pair<OUString, OUString>(sName, 
sName));
-            pStyle = xIter->Next();
+            lcl_AppendParaStyles(m_aAllStyles, pStyleSheetPool,
+                                 SfxStyleSearchBits::Favourite | 
SfxStyleSearchBits::UserDefined);
         }
     }
 
commit 788a225f641a76df93a61c27adc0bce52a50ce81
Author:     Szymon Kłos <[email protected]>
AuthorDate: Wed Nov 12 16:50:25 2025 +0000
Commit:     Szymon Kłos <[email protected]>
CommitDate: Sat Nov 29 09:24:48 2025 +0100

    Writer: iterate styles to show also favourite in the notebookbar
    
    - qFormat - specifies if style should be shown in more prominent places
      in the UI even if unused
    - we show it in that case not only in all styles in sidebar, but also
      in the notebookbar style previews
    - this is Writer specific, implemented on sw/ style iterator and SwFormat
      level
    - XStyles is interface common for all modules but in fact we do per module
      implementations it seems and there is no sense to propagate that value
      everywhere
    - currently we have also qFormat export so just reuse grab bag value
    
    Change-Id: Iee8f35a3e575c3c1caf6c67f8b489d7d64932cf5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193398
    (cherry picked from commit cee5c21e0c8c64c78e5d04ff4e300edfaac30404)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194550
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <[email protected]>

diff --git a/include/svl/style.hxx b/include/svl/style.hxx
index a36861197252..e1f0707c2700 100644
--- a/include/svl/style.hxx
+++ b/include/svl/style.hxx
@@ -65,6 +65,7 @@ enum class SfxStyleSearchBits {
     SwCondColl  = 0x0040,
 
     Auto        = 0x0000, ///< automatic: flags from application
+    Favourite   = 0x0100, ///< styles selected to be always visible (search 
mask)
     Hidden      = 0x0200, ///< hidden styles (search mask)
     ReadOnly    = 0x2000, ///< readonly styles (search mask)
     Used        = 0x4000, ///< used styles (search mask)
@@ -73,7 +74,7 @@ enum class SfxStyleSearchBits {
     All         = 0xe27f, ///< all styles
 };
 namespace o3tl {
-    template<> struct typed_flags<SfxStyleSearchBits> : 
is_typed_flags<SfxStyleSearchBits, 0xe27f> {};
+    template<> struct typed_flags<SfxStyleSearchBits> : 
is_typed_flags<SfxStyleSearchBits, 0xe37f> {};
 }
 
 
diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx 
b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index 44eed42120a9..cf7400b08efd 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -619,8 +619,8 @@ void StylesPreviewWindow_Base::UpdateStylesList()
 
     if (pStyleSheetPool)
     {
-        auto xIter = pStyleSheetPool->CreateIterator(SfxStyleFamily::Para,
-                                                     
SfxStyleSearchBits::UserDefined);
+        auto xIter
+            = pStyleSheetPool->CreateIterator(SfxStyleFamily::Para, 
SfxStyleSearchBits::Favourite);
 
         SfxStyleSheetBase* pStyle = xIter->First();
 
diff --git a/sw/inc/format.hxx b/sw/inc/format.hxx
index 43fb9f6b4217..9933a98926c8 100644
--- a/sw/inc/format.hxx
+++ b/sw/inc/format.hxx
@@ -179,6 +179,8 @@ public:
     bool IsAuto() const                 { return m_bAutoFormat; }
     void SetAuto( bool bNew )           { m_bAutoFormat = bNew; }
 
+    bool IsFavourite() const;
+
     bool IsHidden() const               { return m_bHidden; }
     void SetHidden( bool bValue )       { m_bHidden = bValue; }
 
diff --git a/sw/qa/uitest/writer_tests4/tdf167956.py 
b/sw/qa/uitest/writer_tests4/tdf167956.py
index 7aa31450bea4..731808135ac9 100644
--- a/sw/qa/uitest/writer_tests4/tdf167956.py
+++ b/sw/qa/uitest/writer_tests4/tdf167956.py
@@ -36,7 +36,7 @@ class tdf167956(UITestCase):
 
             # Without the fix in place, this test would have crashed here
             self.wait_until_styles_are_displayed(xStylesView)
-            self.assertEqual("14", get_state_as_dict(xStylesView)["Children"])
+            self.assertLessEqual("10", 
get_state_as_dict(xStylesView)["Children"])
             self.assertEqual("Intense Quote", 
get_state_as_dict(xStylesView)["SelectEntryText"])
 
             # Reset to the default toolbar
diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx
index 4b350b6f75c6..e985b0822a0f 100644
--- a/sw/source/core/attr/format.cxx
+++ b/sw/source/core/attr/format.cxx
@@ -756,6 +756,25 @@ void SwFormat::RemoveAllUnos()
     SwClientNotify(*this, aMsgHint);
 }
 
+bool SwFormat::IsFavourite() const
+{
+    if (!m_pGrabBagItem) return false;
+
+    const auto& rItems = m_pGrabBagItem->GetGrabBag();
+    const auto aIt = rItems.find(u"qFormat"_ustr);
+    if (aIt != rItems.end())
+    {
+        sal_Int32 nVal = 0;
+        if (aIt->second >>= nVal)
+        {
+            if (nVal == 1)
+                return true;
+        }
+    }
+
+    return false;
+}
+
 bool SwFormat::IsUsed() const
 {
     bool isUsed = false;
diff --git a/sw/source/uibase/app/docstyle.cxx 
b/sw/source/uibase/app/docstyle.cxx
index 73818d9ac2d5..f551747830f5 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -2889,6 +2889,7 @@ SfxStyleSheetBase*  SwStyleSheetIterator::First()
 
     bool bSearchHidden( nMask & SfxStyleSearchBits::Hidden );
     bool bOnlyHidden = nMask == SfxStyleSearchBits::Hidden;
+    bool bFavourite = nMask == SfxStyleSearchBits::Favourite;
 
     const bool bOrganizer = static_cast<const 
SwDocStyleSheetPool*>(pBasePool)->IsOrganizerMode();
     bool bAll = ( nSrchMask & SfxStyleSearchBits::AllVisible ) == 
SfxStyleSearchBits::AllVisible;
@@ -2984,7 +2985,7 @@ SfxStyleSheetBase*  SwStyleSheetIterator::First()
             SwTextFormatColl* pColl = (*rDoc.GetTextFormatColls())[ i ];
 
             const bool bUsed = bOrganizer || rDoc.IsUsed(*pColl) || 
IsUsedInComments(pColl->GetName());
-            if ( ( !bSearchHidden && pColl->IsHidden( ) && !bUsed ) || 
pColl->IsDefault() )
+            if ( ( !bSearchHidden && pColl->IsHidden( ) && !bUsed && 
!bFavourite ) || pColl->IsDefault() )
                 continue;
 
             if ( nSMask == SfxStyleSearchBits::Hidden && !pColl->IsHidden( ) )
@@ -3056,6 +3057,12 @@ SfxStyleSheetBase*  SwStyleSheetIterator::First()
                 }
                 else
                 {
+                    if ( tmpMask & SfxStyleSearchBits::Favourite )
+                    {
+                        SwFormat* pFormat = rDoc.FindTextFormatCollByName( 
pColl->GetName() );
+                        if (!(pFormat && pFormat->IsFavourite())) continue;
+                    }
+
                     // searched for used and found none
                     if( bIsSearchUsed )
                         continue;
@@ -3334,6 +3341,7 @@ void SwStyleSheetIterator::AppendStyleList(const 
std::vector<OUString>& rList,
     {
         UIName i(rEntry);
         bool bHidden = false;
+        bool bFavourite = false;
         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(i, nSection);
         switch ( nSection )
         {
@@ -3342,6 +3350,7 @@ void SwStyleSheetIterator::AppendStyleList(const 
std::vector<OUString>& rList,
                     bUsed = 
rDoc.getIDocumentStylePoolAccess().IsPoolTextCollUsed( nId );
                     SwFormat* pFormat = rDoc.FindTextFormatCollByName( i );
                     bHidden = pFormat && pFormat->IsHidden( );
+                    bFavourite = pFormat && pFormat->IsFavourite();
                 }
                 break;
             case SwGetPoolIdFromName::ChrFmt:
@@ -3349,6 +3358,7 @@ void SwStyleSheetIterator::AppendStyleList(const 
std::vector<OUString>& rList,
                     bUsed = 
rDoc.getIDocumentStylePoolAccess().IsPoolFormatUsed( nId );
                     SwFormat* pFormat = rDoc.FindCharFormatByName( i );
                     bHidden = pFormat && pFormat->IsHidden( );
+                    bFavourite = pFormat && pFormat->IsFavourite();
                 }
                 break;
             case SwGetPoolIdFromName::FrmFmt:
@@ -3377,7 +3387,7 @@ void SwStyleSheetIterator::AppendStyleList(const 
std::vector<OUString>& rList,
         }
 
         bool bMatchHidden = ( bTestHidden && ( bHidden || !bOnlyHidden ) ) || 
( !bTestHidden && ( !bHidden || bUsed ) );
-        if ( ( !bTestUsed && bMatchHidden ) || ( bTestUsed && bUsed ) )
+        if ( ( !bTestUsed && bMatchHidden ) || ( bTestUsed && bUsed ) || 
bFavourite )
             m_aLst.Append( eFamily, i );
     }
 }
diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx 
b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
index b8bbee4efc72..b3a63416ab5a 100644
--- a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
+++ b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx
@@ -582,6 +582,7 @@ void StyleSheetTable::lcl_sprm(Sprm & rSprm)
                 break;
                 case NS_ooxml::LN_CT_Style_qFormat:
                     aValue.Name = "qFormat";
+                    aValue.Value <<= nIntValue;
                 break;
                 case NS_ooxml::LN_CT_Style_semiHidden:
                     aValue.Name = "semiHidden";

Reply via email to