[Libreoffice-commits] core.git: cui/source

Muhammet Kara muhammet.kara at pardus.org.tr
Wed Nov 22 11:01:44 UTC 2017


 cui/source/customize/CommandCategoryListBox.cxx |   99 +++++++++++++++++++++++-
 cui/source/inc/CommandCategoryListBox.hxx       |    5 +
 2 files changed, 102 insertions(+), 2 deletions(-)

New commits:
commit 3b4d2cfaaf2a6088304d65a608a9034df701537b
Author: Muhammet Kara <muhammet.kara at pardus.org.tr>
Date:   Mon Nov 20 08:50:15 2017 +0300

    tdf#112207: Allow assigning styles to ui elements
    
    Change-Id: I777059e2c5139dcf1b24504023fb417b9b56b3d8
    Reviewed-on: https://gerrit.libreoffice.org/42594
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/cui/source/customize/CommandCategoryListBox.cxx b/cui/source/customize/CommandCategoryListBox.cxx
index e307bd99f037..1763196db5ab 100644
--- a/cui/source/customize/CommandCategoryListBox.cxx
+++ b/cui/source/customize/CommandCategoryListBox.cxx
@@ -32,12 +32,14 @@
 
 #include <dialmgr.hxx>
 #include <strings.hrc>
+#include <bitmaps.hlst>
 #include <comphelper/sequenceashashmap.hxx>
 #include <o3tl/make_unique.hxx>
 #include <i18nutil/searchopt.hxx>
 
 CommandCategoryListBox::CommandCategoryListBox(vcl::Window* pParent)
     : ListBox( pParent, WB_BORDER | WB_DROPDOWN)
+    , pStylesInfo( nullptr )
 {
     SetDropDownLineCount(25);
 
@@ -64,6 +66,16 @@ void CommandCategoryListBox::dispose()
 void CommandCategoryListBox::ClearAll()
 {
     //TODO: Handle SfxCfgKind::GROUP_SCRIPTCONTAINER when it gets added to Init
+    // Clear style info objects from m_aGroupInfo vector to avoid memory leak
+    for (const auto & It : m_aGroupInfo)
+    {
+        if ( It->nKind == SfxCfgKind::GROUP_STYLES && It->pObject )
+        {
+            SfxStyleInfo_Impl* pStyle = static_cast<SfxStyleInfo_Impl*>(It->pObject);
+            delete pStyle;
+        }
+    }
+
     m_aGroupInfo.clear();
     Clear();
 }
@@ -84,6 +96,17 @@ void CommandCategoryListBox::Init(
     m_xModuleCategoryInfo.set(m_xGlobalCategoryInfo->getByName(m_sModuleLongName), css::uno::UNO_QUERY_THROW);
     m_xUICmdDescription   = css::frame::theUICommandDescription::get( m_xContext );
 
+    // Support style commands
+    css::uno::Reference<css::frame::XController> xController;
+    css::uno::Reference<css::frame::XModel> xModel;
+    if (xFrame.is())
+        xController = xFrame->getController();
+    if (xController.is())
+        xModel = xController->getModel();
+
+    m_aStylesInfo.init(sModuleLongName, xModel);
+    SetStylesInfo(&m_aStylesInfo);
+
 /**** InitModule Start ****/
     try
     {
@@ -124,7 +147,12 @@ void CommandCategoryListBox::Init(
             SetEntryData( nEntryPos, m_aGroupInfo.back().get() );
         }
 
-
+        // Add styles
+        OUString sStyle( CuiResId(RID_SVXSTR_GROUP_STYLES) );
+        nEntryPos = InsertEntry( sStyle );
+        //TODO: last param should contain user data?
+        m_aGroupInfo.push_back( o3tl::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::GROUP_STYLES, 0, nullptr ) );
+        SetEntryData( nEntryPos, m_aGroupInfo.back().get() );
     }
     catch(const css::uno::RuntimeException&)
         { throw; }
@@ -250,7 +278,69 @@ void CommandCategoryListBox::categorySelected(  const VclPtr<SfxConfigFunctionLi
         }
         case SfxCfgKind::GROUP_STYLES:
         {
-            //TODO:Implement
+            const std::vector< SfxStyleInfo_Impl > lStyleFamilies = pStylesInfo->getStyleFamilies();
+
+            for ( const auto & pIt : lStyleFamilies )
+            {
+                if ( pIt.sLabel.isEmpty() )
+                {
+                    continue;
+                }
+
+                SvTreeListEntry* pFuncEntry = pFunctionListBox->InsertEntry(
+                    pIt.sLabel, // Name of the style family
+                    Image( BitmapEx(RID_CUIBMP_EXPANDED) ), Image( BitmapEx(RID_CUIBMP_COLLAPSED) ) );
+
+                m_aGroupInfo.push_back( o3tl::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::GROUP_STYLES, 0 ) );
+                SfxGroupInfo_Impl* pGrpInfo = m_aGroupInfo.back().get();
+                pFuncEntry->SetUserData(pGrpInfo);
+                pFuncEntry->EnableChildrenOnDemand();
+
+                const std::vector< SfxStyleInfo_Impl > lStyles = pStylesInfo->getStyles(pIt.sFamily);
+
+                // Setup search filter parameters
+                m_searchOptions.searchString = filterTerm;
+                utl::TextSearch textSearch( m_searchOptions );
+
+                // Insert children (styles)
+                for ( const auto & pStyleIt : lStyles )
+                {
+                    OUString sUIName = pStyleIt.sLabel;
+                    sal_Int32 aStartPos = 0;
+                    sal_Int32 aEndPos = sUIName.getLength();
+
+                    // Apply the search filter
+                    if (!filterTerm.isEmpty()
+                            && !textSearch.SearchForward( sUIName, &aStartPos, &aEndPos ) )
+                    {
+                        continue;
+                    }
+
+                    SfxStyleInfo_Impl* pStyle = new SfxStyleInfo_Impl(pStyleIt);
+
+                    SvTreeListEntry* pSubFuncEntry = pFunctionListBox->InsertEntry(
+                                sUIName, pFuncEntry );
+
+                    m_aGroupInfo.push_back(
+                                o3tl::make_unique<SfxGroupInfo_Impl>(
+                                    SfxCfgKind::GROUP_STYLES, 0, pStyle ) );
+
+                    m_aGroupInfo.back()->sCommand = pStyle->sCommand;
+                    m_aGroupInfo.back()->sLabel = pStyle->sLabel;
+                    pSubFuncEntry->SetUserData( m_aGroupInfo.back().get() );
+                }
+
+                // Remove the style group from the list if no children
+                if (!pFuncEntry->HasChildren())
+                {
+                    pFunctionListBox->RemoveEntry(pFuncEntry);
+                }
+                else
+                {
+                    pFunctionListBox->Expand(pFuncEntry);
+                }
+            }
+
             break;
         }
         default:
@@ -265,4 +355,9 @@ void CommandCategoryListBox::categorySelected(  const VclPtr<SfxConfigFunctionLi
     pFunctionListBox->SetUpdateMode(true);
 }
 
+void CommandCategoryListBox::SetStylesInfo(SfxStylesInfo_Impl* pStyles)
+{
+    pStylesInfo = pStyles;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/cui/source/inc/CommandCategoryListBox.hxx b/cui/source/inc/CommandCategoryListBox.hxx
index 0a2778d8a1c0..a80f80a6f5be 100644
--- a/cui/source/inc/CommandCategoryListBox.hxx
+++ b/cui/source/inc/CommandCategoryListBox.hxx
@@ -36,6 +36,9 @@ class CommandCategoryListBox : public ListBox
     // For search
     i18nutil::SearchOptions2 m_searchOptions;
 
+    SfxStylesInfo_Impl* pStylesInfo;
+    SfxStylesInfo_Impl m_aStylesInfo;
+
 public:
     CommandCategoryListBox( vcl::Window* pParent );
     virtual ~CommandCategoryListBox() override;
@@ -59,6 +62,8 @@ public:
     */
     void categorySelected(  const VclPtr<SfxConfigFunctionListBox>&  pFunctionListBox,
                             const OUString& filterTerm = OUString() );
+
+    void                SetStylesInfo(SfxStylesInfo_Impl* pStyles);
 };
 
 #endif // INCLUDED_CUI_SOURCE_INC_COMMANDCATEGORYLISTBOX_HXX


More information about the Libreoffice-commits mailing list