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>
This commit is contained in:
parent
1ae61b0ac4
commit
3b4d2cfaaf
2 changed files with 102 additions and 2 deletions
|
@ -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: */
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue