summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@pardus.org.tr>2017-11-20 08:50:15 +0300
committerKatarina Behrens <Katarina.Behrens@cib.de>2017-11-22 12:01:19 +0100
commit3b4d2cfaaf2a6088304d65a608a9034df701537b (patch)
treec0b71735a8cd135e12983be51fba50d4748add6a
parent1ae61b0ac4187b2938647f3ca0289a070a5dc7d2 (diff)
tdf#112207: Allow assigning styles to ui elements
Change-Id: I777059e2c5139dcf1b24504023fb417b9b56b3d8 Reviewed-on: https://gerrit.libreoffice.org/42594 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
-rw-r--r--cui/source/customize/CommandCategoryListBox.cxx99
-rw-r--r--cui/source/inc/CommandCategoryListBox.hxx5
2 files changed, 102 insertions, 2 deletions
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