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 #include +#include #include #include #include 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(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 xController; + css::uno::Reference 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( 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 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( 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( + 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 VclPtrSetUpdateMode(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& pFunctionListBox, const OUString& filterTerm = OUString() ); + + void SetStylesInfo(SfxStylesInfo_Impl* pStyles); }; #endif // INCLUDED_CUI_SOURCE_INC_COMMANDCATEGORYLISTBOX_HXX