basctl/source/basicide/bastype2.cxx | 12 basctl/source/basicide/bastype3.cxx | 2 basctl/source/inc/bastype2.hxx | 12 cui/source/customize/CommandCategoryListBox.cxx | 159 ++---- cui/source/customize/SvxMenuConfigPage.cxx | 260 +++++---- cui/source/customize/SvxToolbarConfigPage.cxx | 635 +++++++++--------------- cui/source/customize/acccfg.cxx | 10 cui/source/customize/cfg.cxx | 567 +++++++-------------- cui/source/customize/cfgutil.cxx | 85 --- cui/source/dialogs/scriptdlg.cxx | 10 cui/source/inc/CommandCategoryListBox.hxx | 21 cui/source/inc/SvxMenuConfigPage.hxx | 27 - cui/source/inc/SvxToolbarConfigPage.hxx | 52 - cui/source/inc/acccfg.hxx | 3 cui/source/inc/cfg.hxx | 141 ++--- cui/source/inc/cfgutil.hxx | 48 + cui/source/inc/scriptdlg.hxx | 8 cui/uiconfig/ui/menuassignpage.ui | 316 ++++++++--- extras/source/glade/libreoffice-catalog.xml.in | 6 include/vcl/weld.hxx | 59 +- sd/source/ui/dlg/sdtreelb.cxx | 4 sd/source/ui/inc/sdtreelb.hxx | 2 solenv/bin/native-code.py | 2 solenv/sanitizers/ui/cui.suppr | 4 sw/source/uibase/dbui/dbtree.cxx | 2 sw/source/uibase/inc/dbtree.hxx | 2 uitest/writer_tests/customizeDialog.py | 3 vcl/inc/salframe.hxx | 11 vcl/inc/treeglue.hxx | 79 ++ vcl/source/app/salvtables.cxx | 154 ++++- vcl/source/treelist/treelistbox.cxx | 2 vcl/source/uitest/uiobject.cxx | 2 vcl/source/window/builder.cxx | 52 - vcl/unx/gtk3/gtk3gtkinst.cxx | 205 +++++-- vcl/win/gdi/salprn.cxx | 2 35 files changed, 1487 insertions(+), 1472 deletions(-)
New commits: commit ccb2b0078f07194befa61f1e3fd88e53ff236871 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Mon Mar 4 17:31:24 2019 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Mon Mar 11 10:00:31 2019 +0100 weld SvxMenuConfigPage/SvxToolbarConfigPage Change-Id: I166ac6c0be8461ea38db711796d1e14fc5b78998 Reviewed-on: https://gerrit.libreoffice.org/68889 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/basctl/source/basicide/bastype2.cxx b/basctl/source/basicide/bastype2.cxx index a5b0057803ed..129865c4087c 100644 --- a/basctl/source/basicide/bastype2.cxx +++ b/basctl/source/basicide/bastype2.cxx @@ -917,7 +917,7 @@ void SbTreeListBox::ScanEntry( const ScriptDocument& rDocument, LibraryLocation m_xControl->thaw(); } -void SbTreeListBox::ImpCreateLibEntries(weld::TreeIter& rIter, const ScriptDocument& rDocument, LibraryLocation eLocation) +void SbTreeListBox::ImpCreateLibEntries(const weld::TreeIter& rIter, const ScriptDocument& rDocument, LibraryLocation eLocation) { // get a sorted list of library names Sequence< OUString > aLibNames( rDocument.getLibraryNames() ); @@ -976,7 +976,7 @@ void SbTreeListBox::ImpCreateLibEntries(weld::TreeIter& rIter, const ScriptDocum } } -void SbTreeListBox::ImpCreateLibSubEntries(weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName) +void SbTreeListBox::ImpCreateLibSubEntries(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName) { // modules if ( nMode & BrowseMode::Modules ) @@ -1075,7 +1075,7 @@ void SbTreeListBox::ImpCreateLibSubEntries(weld::TreeIter& rLibRootEntry, const } } -void SbTreeListBox::ImpCreateLibSubEntriesInVBAMode(weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName ) +void SbTreeListBox::ImpCreateLibSubEntriesInVBAMode(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName ) { auto const aEntries = { std::make_pair( OBJ_TYPE_DOCUMENT_OBJECTS, IDEResId(RID_STR_DOCUMENT_OBJECTS) ), @@ -1102,7 +1102,7 @@ void SbTreeListBox::ImpCreateLibSubEntriesInVBAMode(weld::TreeIter& rLibRootEntr } } -void SbTreeListBox::ImpCreateLibSubSubEntriesInVBAMode(weld::TreeIter& rLibSubRootEntry, const ScriptDocument& rDocument, const OUString& rLibName) +void SbTreeListBox::ImpCreateLibSubSubEntriesInVBAMode(const weld::TreeIter& rLibSubRootEntry, const ScriptDocument& rDocument, const OUString& rLibName) { uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, rLibName ); if( !xLib.is() ) @@ -1347,7 +1347,7 @@ bool SbTreeListBox::IsEntryProtected(const weld::TreeIter* pEntry) void SbTreeListBox::AddEntry( const OUString& rText, const OUString& rImage, - weld::TreeIter* pParent, + const weld::TreeIter* pParent, bool bChildrenOnDemand, std::unique_ptr<Entry>&& rUserData) { @@ -1357,7 +1357,7 @@ void SbTreeListBox::AddEntry( void SbTreeListBox::SetEntryBitmaps(const weld::TreeIter& rIter, const OUString& rImage) { - m_xControl->set_expander_image(rIter, rImage); + m_xControl->set_image(rIter, rImage, -1); } LibraryType SbTreeListBox::GetLibraryType() const diff --git a/basctl/source/basicide/bastype3.cxx b/basctl/source/basicide/bastype3.cxx index 69bfb2c4e200..084b7def7345 100644 --- a/basctl/source/basicide/bastype3.cxx +++ b/basctl/source/basicide/bastype3.cxx @@ -130,7 +130,7 @@ void TreeListBox::RequestingChildren( SvTreeListEntry* pEntry ) } } -IMPL_LINK(SbTreeListBox, RequestingChildrenHdl, weld::TreeIter&, rEntry, bool) +IMPL_LINK(SbTreeListBox, RequestingChildrenHdl, const weld::TreeIter&, rEntry, bool) { EntryDescriptor aDesc = GetEntryDescriptor(&rEntry); const ScriptDocument& aDocument = aDesc.GetDocument(); diff --git a/basctl/source/inc/bastype2.hxx b/basctl/source/inc/bastype2.hxx index 4761fbb5ca9d..881bddb4fa09 100644 --- a/basctl/source/inc/bastype2.hxx +++ b/basctl/source/inc/bastype2.hxx @@ -259,12 +259,12 @@ private: void SetEntryBitmaps(const weld::TreeIter& rIter, const OUString& rImage); protected: - DECL_LINK(RequestingChildrenHdl, weld::TreeIter&, bool); + DECL_LINK(RequestingChildrenHdl, const weld::TreeIter&, bool); DECL_LINK(OpenCurrentHdl, weld::TreeView&, void); - void ImpCreateLibEntries(weld::TreeIter& rShellRootEntry, const ScriptDocument& rDocument, LibraryLocation eLocation); - void ImpCreateLibSubEntries(weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName); - void ImpCreateLibSubEntriesInVBAMode(weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName ); - void ImpCreateLibSubSubEntriesInVBAMode(weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName); + void ImpCreateLibEntries(const weld::TreeIter& rShellRootEntry, const ScriptDocument& rDocument, LibraryLocation eLocation); + void ImpCreateLibSubEntries(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName); + void ImpCreateLibSubEntriesInVBAMode(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName ); + void ImpCreateLibSubSubEntriesInVBAMode(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName); bool ImpFindEntry(weld::TreeIter& rIter, const OUString& rText); // DocumentEventListener @@ -300,7 +300,7 @@ public: static ItemType ConvertType (EntryType eType); bool IsValidEntry(weld::TreeIter& rEntry); void AddEntry(const OUString& rText, const OUString& rImage, - weld::TreeIter* pIter, bool bChildrenOnDemand, std::unique_ptr<Entry>&& rUserData); + const weld::TreeIter* pIter, bool bChildrenOnDemand, std::unique_ptr<Entry>&& rUserData); void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_changed(rLink); } std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pIter = nullptr) const { return m_xControl->make_iterator(pIter); } diff --git a/cui/source/customize/CommandCategoryListBox.cxx b/cui/source/customize/CommandCategoryListBox.cxx index 7b50dd9a8719..2f9a9a451512 100644 --- a/cui/source/customize/CommandCategoryListBox.cxx +++ b/cui/source/customize/CommandCategoryListBox.cxx @@ -41,18 +41,19 @@ #include <dialmgr.hxx> #include <strings.hrc> #include <bitmaps.hlst> +#include <comphelper/processfactory.hxx> #include <comphelper/sequenceashashmap.hxx> +#include <comphelper/string.hxx> +#include <i18nlangtag/languagetag.hxx> #include <i18nutil/searchopt.hxx> #include <sal/log.hxx> #include <cfg.hxx> //for SaveInData -CommandCategoryListBox::CommandCategoryListBox(vcl::Window* pParent) - : ListBox( pParent, WB_BORDER | WB_DROPDOWN | WB_SORT ) - , pStylesInfo( nullptr ) +CommandCategoryListBox::CommandCategoryListBox(std::unique_ptr<weld::ComboBox> xControl) + : pStylesInfo( nullptr ) + , m_xControl(std::move(xControl)) { - SetDropDownLineCount(25); - //Initialize search util m_searchOptions.AlgorithmType2 = css::util::SearchAlgorithms2::ABSOLUTE; m_searchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE; @@ -60,17 +61,9 @@ CommandCategoryListBox::CommandCategoryListBox(vcl::Window* pParent) | css::util::SearchFlags::REG_NOT_ENDOFLINE); } -VCL_BUILDER_FACTORY(CommandCategoryListBox); - CommandCategoryListBox::~CommandCategoryListBox() { - disposeOnce(); -} - -void CommandCategoryListBox::dispose() -{ ClearAll(); - ListBox::dispose(); } void CommandCategoryListBox::ClearAll() @@ -99,7 +92,7 @@ void CommandCategoryListBox::ClearAll() } m_aGroupInfo.clear(); - Clear(); + m_xControl->clear(); } void CommandCategoryListBox::Init( @@ -108,7 +101,7 @@ void CommandCategoryListBox::Init( const OUString& sModuleLongName) { // User will not see incomplete UI - SetUpdateMode(false); + m_xControl->freeze(); ClearAll(); m_xContext = xContext; @@ -136,24 +129,25 @@ void CommandCategoryListBox::Init( css::uno::Sequence< sal_Int16 > lGroups = xProvider->getSupportedCommandGroups(); sal_Int32 nGroupsLength = lGroups.getLength(); - sal_Int32 nEntryPos = 0; if ( nGroupsLength > 0 ) { // Add the category of "All commands" - nEntryPos = InsertEntry( CuiResId(RID_SVXSTR_ALLFUNCTIONS) ); m_aGroupInfo.push_back( std::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::GROUP_ALLFUNCTIONS, 0 ) ); - SetEntryData( nEntryPos, m_aGroupInfo.back().get() ); + m_xControl->append(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), CuiResId(RID_SVXSTR_ALLFUNCTIONS)); } // Separate the "All commands"category from the actual categories - AddSeparator( 0 ); + m_xControl->append_separator(); + + typedef std::pair<OUString, sal_Int16> str_id; + std::vector<str_id> aCategories; // Add the actual categories for (sal_Int32 i = 0; i < nGroupsLength; ++i) { - sal_Int16& rGroupID = lGroups[i]; - OUString sGroupID = OUString::number(rGroupID); + sal_Int16 nGroupID = lGroups[i]; + OUString sGroupID = OUString::number(nGroupID); OUString sGroupName; try @@ -166,33 +160,39 @@ void CommandCategoryListBox::Init( { continue; } + aCategories.emplace_back(std::make_pair(sGroupName, nGroupID)); + } + + auto const sort = comphelper::string::NaturalStringSorter( + comphelper::getProcessComponentContext(), + Application::GetSettings().GetUILanguageTag().getLocale()); + + std::sort(aCategories.begin(), aCategories.end(), + [&sort](const str_id& a, const str_id& b) + { return sort.compare(a.first, b.first) < 0; }); - nEntryPos = InsertEntry( sGroupName ); - m_aGroupInfo.push_back( - std::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::GROUP_FUNCTION, rGroupID ) ); - SetEntryData( nEntryPos, m_aGroupInfo.back().get() ); + // Add the actual categories + for (const auto &a : aCategories) + { + const OUString& rGroupName = a.first; + sal_Int16 nGroupID = a.second; + m_aGroupInfo.push_back(std::make_unique<SfxGroupInfo_Impl>(SfxCfgKind::GROUP_FUNCTION, nGroupID)); + m_xControl->append(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), rGroupName); } // Separate regular commands from styles and macros - AddSeparator( GetEntryCount() - 1 ); - - // Stop sorting, and add Macros and Styles to the end of the list - SetStyle(GetStyle() & ~WB_SORT); + m_xControl->append_separator(); // Add macros category - OUString sMacros( CuiResId(RID_SVXSTR_MACROS) ); - nEntryPos = InsertEntry( sMacros ); m_aGroupInfo.push_back( std::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::GROUP_SCRIPTCONTAINER, 0, nullptr) ); - SetEntryData( nEntryPos, m_aGroupInfo.back().get() ); + m_xControl->append(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), CuiResId(RID_SVXSTR_MACROS)); // Add styles category - OUString sStyle( CuiResId(RID_SVXSTR_GROUP_STYLES) ); - nEntryPos = InsertEntry( sStyle ); //TODO: last param should contain user data? m_aGroupInfo.push_back( std::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::GROUP_STYLES, 0, nullptr ) ); - SetEntryData( nEntryPos, m_aGroupInfo.back().get() ); + m_xControl->append(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), CuiResId(RID_SVXSTR_GROUP_STYLES)); } catch(const css::uno::RuntimeException&) { throw; } @@ -200,13 +200,13 @@ void CommandCategoryListBox::Init( {} // Reveal the updated UI to user - SetUpdateMode(true); - SelectEntryPos(0); + m_xControl->thaw(); + m_xControl->set_active(0); } void CommandCategoryListBox::FillFunctionsList( const css::uno::Sequence<css::frame::DispatchInformation>& xCommands, - const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox, + CuiConfigFunctionListBox* pFunctionListBox, const OUString& filterTerm, SaveInData *pCurrentSaveInData ) { @@ -233,17 +233,15 @@ void CommandCategoryListBox::FillFunctionsList( continue; } - Image aImage; + css::uno::Reference<css::graphic::XGraphic> xImage; if (pCurrentSaveInData) - aImage = pCurrentSaveInData->GetImage(rInfo.Command); - - SvTreeListEntry* pFuncEntry = pFunctionListBox->InsertEntry(sUIName, aImage, aImage ); + xImage = pCurrentSaveInData->GetImage(rInfo.Command); m_aGroupInfo.push_back( std::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::FUNCTION_SLOT, 0 ) ); SfxGroupInfo_Impl* pGrpInfo = m_aGroupInfo.back().get(); pGrpInfo->sCommand = rInfo.Command; pGrpInfo->sLabel = sUIName; - pFuncEntry->SetUserData(pGrpInfo); + pFunctionListBox->append(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), sUIName, xImage); } } @@ -274,11 +272,11 @@ OUString CommandCategoryListBox::getCommandName(const OUString& sCommand) return sUIName; } -void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox, - const OUString& filterTerm , SaveInData *pCurrentSaveInData) +void CommandCategoryListBox::categorySelected(CuiConfigFunctionListBox* pFunctionListBox, + const OUString& filterTerm , SaveInData *pCurrentSaveInData) { - SfxGroupInfo_Impl *pInfo = static_cast<SfxGroupInfo_Impl*>(GetSelectedEntryData()); - pFunctionListBox->SetUpdateMode(false); + SfxGroupInfo_Impl *pInfo = reinterpret_cast<SfxGroupInfo_Impl*>(m_xControl->get_active_id().toInt64()); + pFunctionListBox->freeze(); pFunctionListBox->ClearAll(); switch ( pInfo->nKind ) @@ -287,12 +285,12 @@ void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionLi { css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider( m_xFrame, css::uno::UNO_QUERY ); - sal_Int32 nEntryCount = GetEntryCount(); + sal_Int32 nEntryCount = m_xControl->get_count(); for (sal_Int32 nCurPos = 0; nCurPos < nEntryCount; ++nCurPos) { SfxGroupInfo_Impl *pCurrentInfo = - static_cast<SfxGroupInfo_Impl*>(GetEntryData(nCurPos)); + reinterpret_cast<SfxGroupInfo_Impl*>(m_xControl->get_id(nCurPos).toInt64()); if (pCurrentInfo->nKind == SfxCfgKind::GROUP_FUNCTION) { @@ -375,25 +373,22 @@ void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionLi continue; } - SvTreeListEntry* pMacroGroup = pFunctionListBox->InsertEntry( sUIName ); m_aGroupInfo.push_back( std::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::GROUP_SCRIPTCONTAINER, 0 ) ); - SfxGroupInfo_Impl* pGrpInfo = m_aGroupInfo.back().get(); - pMacroGroup->SetUserData(pGrpInfo); - pMacroGroup->EnableChildrenOnDemand(); + std::unique_ptr<weld::TreeIter> xMacroGroup(pFunctionListBox->append_ondemand(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), sUIName)); //Add the children and the grand children - addChildren( pMacroGroup, childGroup, pFunctionListBox, filterTerm, pCurrentSaveInData ); + addChildren(xMacroGroup.get(), childGroup, pFunctionListBox, filterTerm, pCurrentSaveInData); // Remove the main group if empty - if (!pMacroGroup->HasChildren()) + if (!pFunctionListBox->iter_has_child(*xMacroGroup)) { - pFunctionListBox->RemoveEntry( pMacroGroup ); + pFunctionListBox->remove(*xMacroGroup); } else if (!filterTerm.isEmpty()) { - pFunctionListBox->Expand( pMacroGroup ); + pFunctionListBox->expand_row(*xMacroGroup); } } } @@ -412,12 +407,10 @@ void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionLi continue; } - SvTreeListEntry* pFuncEntry = pFunctionListBox->InsertEntry( pIt.sLabel ); // Name of the style family m_aGroupInfo.push_back( std::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::GROUP_STYLES, 0 ) ); - SfxGroupInfo_Impl* pGrpInfo = m_aGroupInfo.back().get(); - pFuncEntry->SetUserData(pGrpInfo); - pFuncEntry->EnableChildrenOnDemand(); + // pIt.sLabel is Name of the style family + std::unique_ptr<weld::TreeIter> xFuncEntry(pFunctionListBox->append_ondemand(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), pIt.sLabel)); const std::vector< SfxStyleInfo_Impl > lStyles = pStylesInfo->getStyles(pIt.sFamily); @@ -441,26 +434,24 @@ void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionLi SfxStyleInfo_Impl* pStyle = new SfxStyleInfo_Impl(pStyleIt); - SvTreeListEntry* pSubFuncEntry = pFunctionListBox->InsertEntry( - sUIName, pFuncEntry ); - m_aGroupInfo.push_back( std::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() ); + + pFunctionListBox->append(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), sUIName, xFuncEntry.get()); } // Remove the style group from the list if no children - if (!pFuncEntry->HasChildren()) + if (!pFunctionListBox->iter_has_child(*xFuncEntry)) { - pFunctionListBox->RemoveEntry(pFuncEntry); + pFunctionListBox->remove(*xFuncEntry); } else if (!filterTerm.isEmpty()) { - pFunctionListBox->Expand(pFuncEntry); + pFunctionListBox->expand_row(*xFuncEntry); } } @@ -472,10 +463,10 @@ void CommandCategoryListBox::categorySelected( const VclPtr<SfxConfigFunctionLi break; } - if ( pFunctionListBox->GetEntryCount() ) - pFunctionListBox->Select( pFunctionListBox->GetEntry( nullptr, 0 ) ); + pFunctionListBox->thaw(); - pFunctionListBox->SetUpdateMode(true); + if (pFunctionListBox->n_children()) + pFunctionListBox->select(0); } void CommandCategoryListBox::SetStylesInfo(SfxStylesInfo_Impl* pStyles) @@ -484,8 +475,8 @@ void CommandCategoryListBox::SetStylesInfo(SfxStylesInfo_Impl* pStyles) } void CommandCategoryListBox::addChildren( - SvTreeListEntry* parentEntry, const css::uno::Reference< css::script::browse::XBrowseNode > &parentNode, - const VclPtr<SfxConfigFunctionListBox>& pFunctionListBox, const OUString& filterTerm , SaveInData *pCurrentSaveInData) + weld::TreeIter* parentEntry, const css::uno::Reference< css::script::browse::XBrowseNode > &parentNode, + CuiConfigFunctionListBox* pFunctionListBox, const OUString& filterTerm , SaveInData *pCurrentSaveInData) { // Setup search filter parameters m_searchOptions.searchString = filterTerm; @@ -500,21 +491,17 @@ void CommandCategoryListBox::addChildren( { OUString sUIName = child.get()->getName(); - SvTreeListEntry* pNewEntry = pFunctionListBox->InsertEntry( sUIName, parentEntry ); - m_aGroupInfo.push_back( std::make_unique<SfxGroupInfo_Impl>(SfxCfgKind::GROUP_SCRIPTCONTAINER, 0, static_cast<void *>( child.get()))); - pNewEntry->SetUserData( m_aGroupInfo.back().get() ); - pNewEntry->EnableChildrenOnDemand(); + std::unique_ptr<weld::TreeIter> xNewEntry(pFunctionListBox->append_ondemand(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), sUIName, parentEntry)); - addChildren(pNewEntry, child, pFunctionListBox, filterTerm, pCurrentSaveInData); + addChildren(xNewEntry.get(), child, pFunctionListBox, filterTerm, pCurrentSaveInData); // Remove the group if empty - if (!pNewEntry->HasChildren()) - pFunctionListBox->RemoveEntry( pNewEntry ); + if (!pFunctionListBox->iter_has_child(*xNewEntry)) + pFunctionListBox->remove(*xNewEntry); else - pFunctionListBox->Expand( pNewEntry ); - + pFunctionListBox->expand_row(*xNewEntry); } else if ( child.get()->getType() == css::script::browse::BrowseNodeTypes::SCRIPT ) { @@ -558,17 +545,15 @@ void CommandCategoryListBox::addChildren( OUString* pScriptURI = new OUString( uri ); - Image aImage; + css::uno::Reference<css::graphic::XGraphic> xImage; if (pCurrentSaveInData) - aImage = pCurrentSaveInData->GetImage(uri); - - SvTreeListEntry* pNewEntry = pFunctionListBox->InsertEntry( sUIName, aImage, aImage, parentEntry ); + xImage = pCurrentSaveInData->GetImage(uri); m_aGroupInfo.push_back( std::make_unique<SfxGroupInfo_Impl>( SfxCfgKind::FUNCTION_SCRIPT, 0, pScriptURI )); m_aGroupInfo.back()->sCommand = uri; m_aGroupInfo.back()->sLabel = sUIName; m_aGroupInfo.back()->sHelpText = description; - pNewEntry->SetUserData( m_aGroupInfo.back().get() ); + pFunctionListBox->append(OUString::number(reinterpret_cast<sal_Int64>(m_aGroupInfo.back().get())), sUIName, xImage, parentEntry); } } } diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx index 06836f52d6ea..8e8adf5ed598 100644 --- a/cui/source/customize/SvxMenuConfigPage.cxx +++ b/cui/source/customize/SvxMenuConfigPage.cxx @@ -96,68 +96,90 @@ #include <dlgname.hxx> -SvxMenuConfigPage::SvxMenuConfigPage(vcl::Window *pParent, const SfxItemSet& rSet, bool bIsMenuBar) +SvxMenuConfigPage::SvxMenuConfigPage(TabPageParent pParent, const SfxItemSet& rSet, bool bIsMenuBar) : SvxConfigPage(pParent, rSet) - , m_bIsMenuBar( bIsMenuBar ) + , m_bIsMenuBar(bIsMenuBar) { - m_pContentsListBox = VclPtr<SvxMenuEntriesListBox>::Create(m_pEntries, this); - m_pContentsListBox->set_grid_left_attach(0); - m_pContentsListBox->set_grid_top_attach(0); - m_pContentsListBox->set_hexpand(true); - m_pContentsListBox->set_vexpand(true); - m_pContentsListBox->Show(); - - m_pTopLevelListBox->SetSelectHdl( - LINK( this, SvxMenuConfigPage, SelectMenu ) ); - - m_pContentsListBox->SetSelectHdl( + m_xContentsListBox.reset(new SvxMenuEntriesListBox(m_xBuilder->weld_tree_view("menucontents"), this)); + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); + rTreeView.connect_size_allocate(LINK(this, SvxMenuConfigPage, MenuEntriesSizeAllocHdl)); + Size aSize(m_xFunctions->get_size_request()); + rTreeView.set_size_request(aSize.Width(), aSize.Height()); + MenuEntriesSizeAllocHdl(aSize); + rTreeView.set_grid_left_attach(0); + rTreeView.set_grid_top_attach(0); + rTreeView.set_hexpand(true); + rTreeView.set_vexpand(true); + rTreeView.show(); + + rTreeView.connect_changed( LINK( this, SvxMenuConfigPage, SelectMenuEntry ) ); - m_pGearBtn->SetSelectHdl( - LINK( this, SvxMenuConfigPage, GearHdl ) ); + rTreeView.connect_model_changed(LINK(this, SvxMenuConfigPage, ListModifiedHdl)); + + m_xGearBtn->connect_selected(LINK(this, SvxMenuConfigPage, GearHdl)); - m_pCommandCategoryListBox->SetSelectHdl( - LINK( this, SvxMenuConfigPage, SelectCategory ) ); + m_xCommandCategoryListBox->connect_changed(LINK(this, SvxMenuConfigPage, SelectCategory)); - m_pMoveUpButton->SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) ); - m_pMoveDownButton->SetClickHdl ( LINK( this, SvxConfigPage, MoveHdl) ); + m_xMoveUpButton->connect_clicked( LINK( this, SvxConfigPage, MoveHdl) ); + m_xMoveDownButton->connect_clicked( LINK( this, SvxConfigPage, MoveHdl) ); - m_pAddCommandButton->SetClickHdl( LINK( this, SvxMenuConfigPage, AddCommandHdl ) ); - m_pRemoveCommandButton->SetClickHdl( LINK( this, SvxMenuConfigPage, RemoveCommandHdl ) ); + m_xAddCommandButton->connect_clicked( LINK( this, SvxMenuConfigPage, AddCommandHdl ) ); + m_xRemoveCommandButton->connect_clicked( LINK( this, SvxMenuConfigPage, RemoveCommandHdl ) ); - m_pInsertBtn->SetSelectHdl( + m_xInsertBtn->connect_selected( LINK( this, SvxMenuConfigPage, InsertHdl ) ); - m_pModifyBtn->SetSelectHdl( + m_xModifyBtn->connect_selected( LINK( this, SvxMenuConfigPage, ModifyItemHdl ) ); - m_pResetBtn->SetClickHdl( + m_xResetBtn->connect_clicked( LINK( this, SvxMenuConfigPage, ResetMenuHdl ) ); - PopupMenu* pPopup = m_pModifyBtn->GetPopupMenu(); // These operations are not possible on menus/context menus yet - pPopup->EnableItem( pPopup->GetItemId("changeIcon"), false ); - pPopup->EnableItem( pPopup->GetItemId("resetIcon"), false ); - pPopup->EnableItem( pPopup->GetItemId("restoreItem"), false ); - pPopup->RemoveDisabledEntries(); + m_xModifyBtn->remove_item("changeIcon"); + m_xModifyBtn->remove_item("resetIcon"); + m_xModifyBtn->remove_item("restoreItem"); - PopupMenu* pGearMenu = m_pGearBtn->GetPopupMenu(); - pGearMenu->EnableItem( pGearMenu->GetItemId("gear_iconAndText"), false ); - pGearMenu->EnableItem( pGearMenu->GetItemId("gear_iconOnly"), false ); - pGearMenu->EnableItem( pGearMenu->GetItemId("gear_textOnly"), false ); - pGearMenu->RemoveDisabledEntries(); + m_xGearBtn->remove_item("gear_iconAndText"); + m_xGearBtn->remove_item("gear_iconOnly"); + m_xGearBtn->remove_item("gear_textOnly"); if ( !bIsMenuBar ) { //TODO: Remove this when the gear button is implemented for context menus - m_pGearBtn->Disable(); - m_pGearBtn->Hide(); + m_xGearBtn->set_sensitive(false); + m_xGearBtn->hide(); } else { // TODO: Remove this when it is possible to reset menubar menus individually - m_pResetBtn->Disable(); + m_xResetBtn->set_sensitive(false); } } +IMPL_LINK_NOARG(SvxMenuConfigPage, ListModifiedHdl, weld::TreeView&, void) +{ + // regenerate with the current ordering within the list + SvxEntries* pEntries = GetTopLevelSelection()->GetEntries(); + pEntries->clear(); + + for (int i = 0; i < m_xContentsListBox->n_children(); ++i) + pEntries->push_back(reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(i).toInt64())); + + GetSaveInData()->SetModified(); + GetTopLevelSelection()->SetModified(); + UpdateButtonStates(); +} + +IMPL_LINK(SvxMenuConfigPage, MenuEntriesSizeAllocHdl, const Size&, rSize, void) +{ + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); + std::vector<int> aWidths; + int nImageColWidth = rTreeView.get_checkbox_column_width(); + aWidths.push_back(nImageColWidth); + aWidths.push_back(rSize.Width() - 2 * nImageColWidth); + rTreeView.set_column_fixed_widths(aWidths); +} + SvxMenuConfigPage::~SvxMenuConfigPage() { disposeOnce(); @@ -167,33 +189,31 @@ SvxMenuConfigPage::~SvxMenuConfigPage() void SvxMenuConfigPage::Init() { // ensure that the UI is cleared before populating it - m_pTopLevelListBox->Clear(); - m_pContentsListBox->Clear(); + m_xTopLevelListBox->clear(); + m_xContentsListBox->clear(); ReloadTopLevelListBox(); - m_pTopLevelListBox->SelectEntryPos(0); - m_pTopLevelListBox->GetSelectHdl().Call(*m_pTopLevelListBox); + m_xTopLevelListBox->set_active(0); + SelectElement(); - m_pCommandCategoryListBox->Init( + m_xCommandCategoryListBox->Init( comphelper::getProcessComponentContext(), m_xFrame, vcl::CommandInfoProvider::GetModuleIdentifier(m_xFrame)); - m_pCommandCategoryListBox->categorySelected( m_pFunctions, OUString(), GetSaveInData() ); + m_xCommandCategoryListBox->categorySelected(m_xFunctions.get(), OUString(), GetSaveInData()); } void SvxMenuConfigPage::dispose() { - for ( sal_Int32 i = 0 ; i < m_pSaveInListBox->GetEntryCount(); ++i ) - { - delete static_cast<SaveInData*>(m_pSaveInListBox->GetEntryData( i )); - } - m_pSaveInListBox->Clear(); + for (int i = 0, nCount = m_xSaveInListBox->get_count(); i < nCount; ++i) + delete reinterpret_cast<SaveInData*>(m_xSaveInListBox->get_id(i).toInt64()); + m_xSaveInListBox->clear(); SvxConfigPage::dispose(); } -IMPL_LINK_NOARG( SvxMenuConfigPage, SelectMenuEntry, SvTreeListBox *, void ) +IMPL_LINK_NOARG(SvxMenuConfigPage, SelectMenuEntry, weld::TreeView&, void) { UpdateButtonStates(); } @@ -201,31 +221,30 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, SelectMenuEntry, SvTreeListBox *, void ) void SvxMenuConfigPage::UpdateButtonStates() { // Disable Up and Down buttons depending on current selection - SvTreeListEntry* selection = m_pContentsListBox->GetCurEntry(); + int selection = m_xContentsListBox->get_selected_index(); bool bIsSeparator = - selection && static_cast<SvxConfigEntry*>(selection->GetUserData())->IsSeparator(); + selection != -1 && reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(selection).toInt64())->IsSeparator(); bool bIsValidSelection = - !(m_pContentsListBox->GetEntryCount() == 0 || selection == nullptr); + !(m_xContentsListBox->n_children() == 0 || selection == -1); - m_pMoveUpButton->Enable( - bIsValidSelection && selection != m_pContentsListBox->First() ); - m_pMoveDownButton->Enable( - bIsValidSelection && selection != m_pContentsListBox->Last() ); + m_xMoveUpButton->set_sensitive( + bIsValidSelection && selection != 0 ); + m_xMoveDownButton->set_sensitive( + bIsValidSelection && selection != m_xContentsListBox->n_children() - 1); - m_pRemoveCommandButton->Enable( bIsValidSelection ); + m_xRemoveCommandButton->set_sensitive( bIsValidSelection ); - m_pModifyBtn->Enable( bIsValidSelection && !bIsSeparator); + m_xModifyBtn->set_sensitive( bIsValidSelection && !bIsSeparator); //Handle the gear button if (m_bIsMenuBar) { SvxConfigEntry* pMenuData = GetTopLevelSelection(); - PopupMenu* pGearPopup = m_pGearBtn->GetPopupMenu(); // Add option (gear_add) will always be enabled - pGearPopup->EnableItem( "gear_delete", pMenuData->IsDeletable() ); - pGearPopup->EnableItem( "gear_rename", pMenuData->IsRenamable() ); - pGearPopup->EnableItem( "gear_move", pMenuData->IsMovable() ); + m_xGearBtn->set_item_sensitive( "gear_delete", pMenuData->IsDeletable() ); + m_xGearBtn->set_item_sensitive( "gear_rename", pMenuData->IsRenamable() ); + m_xGearBtn->set_item_sensitive( "gear_move", pMenuData->IsMovable() ); } } @@ -246,13 +265,13 @@ void SvxMenuConfigPage::DeleteSelectedTopLevel() void SvxMenuConfigPage::DeleteSelectedContent() { - SvTreeListEntry *pActEntry = m_pContentsListBox->FirstSelected(); + int nActEntry = m_xContentsListBox->get_selected_index(); - if ( pActEntry != nullptr ) + if (nActEntry != -1) { // get currently selected menu entry SvxConfigEntry* pMenuEntry = - static_cast<SvxConfigEntry*>(pActEntry->GetUserData()); + reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64()); // get currently selected menu SvxConfigEntry* pMenu = GetTopLevelSelection(); @@ -261,7 +280,7 @@ void SvxMenuConfigPage::DeleteSelectedContent() SvxConfigPageHelper::RemoveEntry( pMenu->GetEntries(), pMenuEntry ); // remove menu entry from UI - m_pContentsListBox->GetModel()->Remove( pActEntry ); + m_xContentsListBox->remove(nActEntry); // if this is a submenu entry, redraw the menus list box if ( pMenuEntry->IsPopup() ) @@ -281,20 +300,19 @@ short SvxMenuConfigPage::QueryReset() { OUString msg = CuiResId( RID_SVXSTR_CONFIRM_MENU_RESET ); - OUString saveInName = m_pSaveInListBox->GetEntry( - m_pSaveInListBox->GetSelectedEntryPos() ); + OUString saveInName = m_xSaveInListBox->get_active_text(); OUString label = SvxConfigPageHelper::replaceSaveInName( msg, saveInName ); - std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetDialogFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, label)); return xQueryBox->run(); } -IMPL_LINK_NOARG( SvxMenuConfigPage, SelectMenu, ListBox&, void ) +void SvxMenuConfigPage::SelectElement() { - m_pContentsListBox->Clear(); + m_xContentsListBox->clear(); SvxConfigEntry* pMenuData = GetTopLevelSelection(); @@ -302,22 +320,24 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, SelectMenu, ListBox&, void ) { SvxEntries* pEntries = pMenuData->GetEntries(); + int i = 0; for (auto const& entry : *pEntries) { - InsertEntryIntoUI(entry); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(entry))); + m_xContentsListBox->insert(i, sId); + InsertEntryIntoUI(entry, i, 0); + ++i; } } UpdateButtonStates(); } -IMPL_LINK( SvxMenuConfigPage, GearHdl, MenuButton *, pButton, void ) +IMPL_LINK(SvxMenuConfigPage, GearHdl, const OString&, rIdent, void) { - OString sIdent = pButton->GetCurItemIdent(); - - if (sIdent == "gear_add") + if (rIdent == "gear_add") { - SvxMainMenuOrganizerDialog aDialog(GetFrameWeld(), + SvxMainMenuOrganizerDialog aDialog(GetDialogFrameWeld(), GetSaveInData()->GetEntries(), nullptr, true ); if (aDialog.run() == RET_OK) @@ -327,20 +347,20 @@ IMPL_LINK( SvxMenuConfigPage, GearHdl, MenuButton *, pButton, void ) GetSaveInData()->SetModified(); } } - else if (sIdent == "gear_delete") + else if (rIdent == "gear_delete") { DeleteSelectedTopLevel(); } - else if (sIdent == "gear_rename") + else if (rIdent == "gear_rename") { SvxConfigEntry* pMenuData = GetTopLevelSelection(); OUString sCurrentName( SvxConfigPageHelper::stripHotKey( pMenuData->GetName() ) ); OUString sDesc = CuiResId( RID_SVXSTR_LABEL_NEW_NAME ); - SvxNameDialog aNameDialog( GetFrameWeld(), sCurrentName, sDesc ); - aNameDialog.set_help_id( HID_SVX_CONFIG_RENAME_MENU ); - aNameDialog.set_title( CuiResId( RID_SVXSTR_RENAME_MENU ) ); + SvxNameDialog aNameDialog(GetDialogFrameWeld(), sCurrentName, sDesc); + aNameDialog.set_help_id(HID_SVX_CONFIG_RENAME_MENU); + aNameDialog.set_title(CuiResId(RID_SVXSTR_RENAME_MENU)); if ( aNameDialog.run() == RET_OK ) { @@ -356,11 +376,11 @@ IMPL_LINK( SvxMenuConfigPage, GearHdl, MenuButton *, pButton, void ) GetSaveInData()->SetModified(); } } - else if (sIdent == "gear_move") + else if (rIdent == "gear_move") { SvxConfigEntry* pMenuData = GetTopLevelSelection(); - SvxMainMenuOrganizerDialog aDialog(GetFrameWeld(), GetSaveInData()->GetEntries(), + SvxMainMenuOrganizerDialog aDialog(GetDialogFrameWeld(), GetSaveInData()->GetEntries(), pMenuData, false ); if (aDialog.run() == RET_OK) { @@ -374,26 +394,31 @@ IMPL_LINK( SvxMenuConfigPage, GearHdl, MenuButton *, pButton, void ) else { //This block should never be reached - SAL_WARN("cui.customize", "Unknown gear menu option: " << sIdent); + SAL_WARN("cui.customize", "Unknown gear menu option: " << rIdent); return; } UpdateButtonStates(); } -IMPL_LINK_NOARG( SvxMenuConfigPage, SelectCategory, ListBox&, void ) +IMPL_LINK_NOARG(SvxMenuConfigPage, SelectCategory, weld::ComboBox&, void) { - OUString aSearchTerm( m_pSearchEdit->GetText() ); + OUString aSearchTerm( m_xSearchEdit->get_text() ); - m_pCommandCategoryListBox->categorySelected( m_pFunctions, aSearchTerm, GetSaveInData() ); + m_xCommandCategoryListBox->categorySelected(m_xFunctions.get(), aSearchTerm, GetSaveInData()); } -IMPL_LINK_NOARG( SvxMenuConfigPage, AddCommandHdl, Button *, void ) +IMPL_LINK_NOARG( SvxMenuConfigPage, AddCommandHdl, weld::Button&, void ) { - AddFunction(); + int nPos = AddFunction(); + if (nPos == -1) + return; + SvxConfigEntry* pEntry = + reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nPos).toInt64()); + InsertEntryIntoUI(pEntry, nPos, 0); } -IMPL_LINK_NOARG( SvxMenuConfigPage, RemoveCommandHdl, Button *, void ) +IMPL_LINK_NOARG( SvxMenuConfigPage, RemoveCommandHdl, weld::Button&, void ) { DeleteSelectedContent(); if ( GetSaveInData()->IsModified() ) @@ -402,22 +427,21 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, RemoveCommandHdl, Button *, void ) } } -IMPL_LINK( SvxMenuConfigPage, InsertHdl, MenuButton *, pButton, void ) +IMPL_LINK(SvxMenuConfigPage, InsertHdl, const OString&, rIdent, void) { - OString sIdent = pButton->GetCurItemIdent(); - - if (sIdent == "insertseparator") + if (rIdent == "insertseparator") { SvxConfigEntry* pNewEntryData = new SvxConfigEntry; pNewEntryData->SetUserDefined(); - InsertEntry( pNewEntryData ); + int nPos = InsertEntry(pNewEntryData, -1); + InsertEntryIntoUI(pNewEntryData, nPos, 0); } - else if (sIdent == "insertsubmenu") + else if (rIdent == "insertsubmenu") { OUString aNewName; OUString aDesc = CuiResId( RID_SVXSTR_SUBMENU_NAME ); - SvxNameDialog aNameDialog(GetFrameWeld(), aNewName, aDesc); + SvxNameDialog aNameDialog(GetDialogFrameWeld(), aNewName, aDesc); aNameDialog.set_help_id(HID_SVX_CONFIG_NAME_SUBMENU); aNameDialog.set_title(CuiResId( RID_SVXSTR_ADD_SUBMENU)); @@ -430,10 +454,14 @@ IMPL_LINK( SvxMenuConfigPage, InsertHdl, MenuButton *, pButton, void ) pNewEntryData->SetName( aNewName ); pNewEntryData->SetUserDefined(); - InsertEntry( pNewEntryData ); + int nPos = InsertEntry(pNewEntryData, -1); + InsertEntryIntoUI(pNewEntryData, nPos, 0); ReloadTopLevelListBox(); + m_xContentsListBox->scroll_to_row(nPos); + m_xContentsListBox->select(nPos); + GetSaveInData()->SetModified(); } @@ -441,7 +469,7 @@ IMPL_LINK( SvxMenuConfigPage, InsertHdl, MenuButton *, pButton, void ) else { //This block should never be reached - SAL_WARN("cui.customize", "Unknown insert option: " << sIdent); + SAL_WARN("cui.customize", "Unknown insert option: " << rIdent); return; } @@ -451,22 +479,18 @@ IMPL_LINK( SvxMenuConfigPage, InsertHdl, MenuButton *, pButton, void ) } } -IMPL_LINK( SvxMenuConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) +IMPL_LINK(SvxMenuConfigPage, ModifyItemHdl, const OString&, rIdent, void) { - OString sIdent = pButton->GetCurItemIdent(); - - SAL_WARN("cui.customize", "sIdent: " << sIdent); - - if (sIdent == "renameItem") + if (rIdent == "renameItem") { - SvTreeListEntry* pActEntry = m_pContentsListBox->GetCurEntry(); + int nActEntry = m_xContentsListBox->get_selected_index(); SvxConfigEntry* pEntry = - static_cast<SvxConfigEntry*>(pActEntry->GetUserData()); + reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64()); OUString aNewName( SvxConfigPageHelper::stripHotKey( pEntry->GetName() ) ); OUString aDesc = CuiResId( RID_SVXSTR_LABEL_NEW_NAME ); - SvxNameDialog aNameDialog(GetFrameWeld(), aNewName, aDesc); + SvxNameDialog aNameDialog(GetDialogFrameWeld(), aNewName, aDesc); aNameDialog.set_help_id(HID_SVX_CONFIG_RENAME_MENU_ITEM); aNameDialog.set_title(CuiResId(RID_SVXSTR_RENAME_MENU)); @@ -475,7 +499,7 @@ IMPL_LINK( SvxMenuConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) aNewName = aNameDialog.GetName(); pEntry->SetName( aNewName ); - m_pContentsListBox->SetEntryText( pActEntry, aNewName ); + m_xContentsListBox->set_text(nActEntry, aNewName, 1); GetSaveInData()->SetModified(); GetTopLevelSelection()->SetModified(); @@ -484,7 +508,7 @@ IMPL_LINK( SvxMenuConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) else { //This block should never be reached - SAL_WARN("cui.customize", "Unknown insert option: " << sIdent); + SAL_WARN("cui.customize", "Unknown insert option: " << rIdent); return; } @@ -494,7 +518,7 @@ IMPL_LINK( SvxMenuConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) } } -IMPL_LINK_NOARG( SvxMenuConfigPage, ResetMenuHdl, Button *, void ) +IMPL_LINK_NOARG(SvxMenuConfigPage, ResetMenuHdl, weld::Button&, void) { SvxConfigEntry* pMenuData = GetTopLevelSelection(); @@ -504,7 +528,7 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, ResetMenuHdl, Button *, void ) return; } - std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetDialogFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, CuiResId(RID_SVXSTR_CONFIRM_RESTORE_DEFAULT_MENU))); @@ -512,20 +536,20 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, ResetMenuHdl, Button *, void ) // So we are resetting only if it is a context menu if (!m_bIsMenuBar && xQueryBox->run() == RET_YES) { - sal_Int32 nPos = m_pTopLevelListBox->GetSelectedEntryPos(); + sal_Int32 nPos = m_xTopLevelListBox->get_active(); ContextMenuSaveInData* pSaveInData = static_cast< ContextMenuSaveInData* >(GetSaveInData()); pSaveInData->ResetContextMenu(pMenuData); // ensure that the UI is cleared before populating it - m_pTopLevelListBox->Clear(); - m_pContentsListBox->Clear(); + m_xTopLevelListBox->clear(); + m_xContentsListBox->clear(); ReloadTopLevelListBox(); // Reselect the resetted menu - m_pTopLevelListBox->SelectEntryPos(nPos); - m_pTopLevelListBox->GetSelectHdl().Call(*m_pTopLevelListBox); + m_xTopLevelListBox->set_active(nPos); + SelectElement(); } } diff --git a/cui/source/customize/SvxToolbarConfigPage.cxx b/cui/source/customize/SvxToolbarConfigPage.cxx index 56c9c85c6734..252efe5bb7ba 100644 --- a/cui/source/customize/SvxToolbarConfigPage.cxx +++ b/cui/source/customize/SvxToolbarConfigPage.cxx @@ -96,60 +96,65 @@ #include <dlgname.hxx> -SvxToolbarConfigPage::SvxToolbarConfigPage(vcl::Window *pParent, const SfxItemSet& rSet) +SvxToolbarConfigPage::SvxToolbarConfigPage(TabPageParent pParent, const SfxItemSet& rSet) : SvxConfigPage(pParent, rSet) { - SetHelpId( HID_SVX_CONFIG_TOOLBAR ); - - m_pContentsListBox = VclPtr<SvxToolbarEntriesListBox>::Create(m_pEntries, this); - m_pContentsListBox->set_grid_left_attach(0); - m_pContentsListBox->set_grid_top_attach(0); - m_pContentsListBox->set_hexpand(true); - m_pContentsListBox->set_vexpand(true); - m_pContentsListBox->Show(); - - m_pTopLevelListBox->SetHelpId ( HID_SVX_TOPLEVELLISTBOX ); - m_pContentsListBox->SetHelpId( HID_SVX_CONFIG_TOOLBAR_CONTENTS ); - m_pSaveInListBox->SetHelpId( HID_SVX_SAVE_IN ); - m_pMoveUpButton->SetHelpId( HID_SVX_UP_TOOLBAR_ITEM ); - m_pMoveDownButton->SetHelpId( HID_SVX_DOWN_TOOLBAR_ITEM ); - m_pDescriptionField->SetHelpId ( HID_SVX_DESCFIELD ); - - m_pTopLevelListBox->SetSelectHdl( - LINK( this, SvxToolbarConfigPage, SelectToolbar ) ); - m_pContentsListBox->SetSelectHdl( + m_xContainer->set_help_id(HID_SVX_CONFIG_TOOLBAR); + + m_xContentsListBox.reset(new SvxToolbarEntriesListBox(m_xBuilder->weld_tree_view("toolcontents"), this)); + std::vector<int> aWidths; + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); + Size aSize(m_xFunctions->get_size_request()); + rTreeView.set_size_request(aSize.Width(), aSize.Height()); + aWidths.push_back(rTreeView.get_checkbox_column_width()); + aWidths.push_back(rTreeView.get_checkbox_column_width()); + rTreeView.set_column_fixed_widths(aWidths); + rTreeView.set_grid_left_attach(0); + rTreeView.set_grid_top_attach(0); + rTreeView.set_hexpand(true); + rTreeView.set_vexpand(true); + rTreeView.set_help_id( HID_SVX_CONFIG_TOOLBAR_CONTENTS ); + rTreeView.show(); + + rTreeView.connect_changed( LINK( this, SvxToolbarConfigPage, SelectToolbarEntry ) ); - m_pCommandCategoryListBox->SetSelectHdl( + + rTreeView.connect_model_changed(LINK(this, SvxToolbarConfigPage, ListModifiedHdl)); + + m_xTopLevelListBox->set_help_id ( HID_SVX_TOPLEVELLISTBOX ); + m_xSaveInListBox->set_help_id( HID_SVX_SAVE_IN ); + m_xMoveUpButton->set_help_id( HID_SVX_UP_TOOLBAR_ITEM ); + m_xMoveDownButton->set_help_id( HID_SVX_DOWN_TOOLBAR_ITEM ); + m_xDescriptionField->set_help_id ( HID_SVX_DESCFIELD ); + + m_xCommandCategoryListBox->connect_changed( LINK( this, SvxToolbarConfigPage, SelectCategory ) ); - m_pGearBtn->SetSelectHdl( + m_xGearBtn->connect_selected( LINK( this, SvxToolbarConfigPage, GearHdl ) ); - m_pMoveUpButton->SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) ); - m_pMoveDownButton->SetClickHdl ( LINK( this, SvxToolbarConfigPage, MoveHdl) ); + m_xMoveUpButton->connect_clicked( LINK( this, SvxToolbarConfigPage, MoveHdl) ); + m_xMoveDownButton->connect_clicked( LINK( this, SvxToolbarConfigPage, MoveHdl) ); // Always enable Up and Down buttons // added for issue i53677 by shizhoubo - m_pMoveDownButton->Enable(); - m_pMoveUpButton->Enable(); + m_xMoveDownButton->set_sensitive(true); + m_xMoveUpButton->set_sensitive(true); - m_pAddCommandButton->SetClickHdl( LINK( this, SvxToolbarConfigPage, AddCommandHdl ) ); - m_pRemoveCommandButton->SetClickHdl( LINK( this, SvxToolbarConfigPage, RemoveCommandHdl ) ); + m_xAddCommandButton->connect_clicked( LINK( this, SvxToolbarConfigPage, AddCommandHdl ) ); + m_xRemoveCommandButton->connect_clicked( LINK( this, SvxToolbarConfigPage, RemoveCommandHdl ) ); - m_pInsertBtn->SetSelectHdl( + m_xInsertBtn->connect_selected( LINK( this, SvxToolbarConfigPage, InsertHdl ) ); - m_pModifyBtn->SetSelectHdl( + m_xModifyBtn->connect_selected( LINK( this, SvxToolbarConfigPage, ModifyItemHdl ) ); - m_pResetBtn->SetClickHdl( + m_xResetBtn->connect_clicked( LINK( this, SvxToolbarConfigPage, ResetToolbarHdl ) ); // "Insert Submenu" is irrelevant to the toolbars - PopupMenu* pPopup = m_pInsertBtn->GetPopupMenu(); - pPopup->EnableItem(OString( "insertsubmenu"), false ); - pPopup->RemoveDisabledEntries(); + m_xInsertBtn->remove_item("insertsubmenu"); // Gear menu's "Move" action is irrelevant to the toolbars - pPopup = m_pGearBtn->GetPopupMenu(); - pPopup->EnableItem("gear_move", false); + m_xGearBtn->set_item_sensitive("gear_move", false); // default toolbar to select is standardbar unless a different one // has been passed in @@ -169,6 +174,23 @@ SvxToolbarConfigPage::SvxToolbarConfigPage(vcl::Window *pParent, const SfxItemSe } } +IMPL_LINK_NOARG(SvxToolbarConfigPage, ListModifiedHdl, weld::TreeView&, void) +{ + // regenerate with the current ordering within the list + SvxEntries* pEntries = GetTopLevelSelection()->GetEntries(); + pEntries->clear(); + + for (int i = 0; i < m_xContentsListBox->n_children(); ++i) + pEntries->push_back(reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(i).toInt64())); + + GetSaveInData()->SetModified(); + GetTopLevelSelection()->SetModified(); + + SvxConfigEntry* pToolbar = GetTopLevelSelection(); + if ( pToolbar ) + static_cast<ToolbarSaveInData*>(GetSaveInData())->ApplyToolbar( pToolbar ); +} + SvxToolbarConfigPage::~SvxToolbarConfigPage() { disposeOnce(); @@ -176,41 +198,41 @@ SvxToolbarConfigPage::~SvxToolbarConfigPage() void SvxToolbarConfigPage::dispose() { - for ( sal_Int32 i = 0 ; i < m_pSaveInListBox->GetEntryCount(); ++i ) + for (int i = 0, nCount = m_xSaveInListBox->get_count(); i < nCount; ++i) { ToolbarSaveInData* pData = - static_cast<ToolbarSaveInData*>(m_pSaveInListBox->GetEntryData( i )); - + reinterpret_cast<ToolbarSaveInData*>(m_xSaveInListBox->get_id(i).toInt64()); delete pData; } - m_pSaveInListBox->Clear(); + m_xSaveInListBox->clear(); SvxConfigPage::dispose(); } void SvxToolbarConfigPage::DeleteSelectedTopLevel() { - const sal_Int32 nSelectionPos = m_pTopLevelListBox->GetSelectedEntryPos(); + const sal_Int32 nSelectionPos = m_xTopLevelListBox->get_active(); ToolbarSaveInData* pSaveInData = static_cast<ToolbarSaveInData*>( GetSaveInData() ); pSaveInData->RemoveToolbar( GetTopLevelSelection() ); - if ( m_pTopLevelListBox->GetEntryCount() > 1 ) + int nCount = m_xTopLevelListBox->get_count(); + if (nCount > 1) { // select next entry after the one being deleted // selection position is indexed from 0 so need to // subtract one from the entry count - if ( nSelectionPos != m_pTopLevelListBox->GetEntryCount() - 1 ) + if (nSelectionPos != nCount - 1) { - m_pTopLevelListBox->SelectEntryPos( nSelectionPos + 1 ); + m_xTopLevelListBox->set_active(nSelectionPos + 1); } else { - m_pTopLevelListBox->SelectEntryPos( nSelectionPos - 1 ); + m_xTopLevelListBox->set_active(nSelectionPos - 1); } - m_pTopLevelListBox->GetSelectHdl().Call( *m_pTopLevelListBox ); + SelectElement(); // and now remove the entry - m_pTopLevelListBox->RemoveEntry( nSelectionPos ); + m_xTopLevelListBox->remove(nSelectionPos); } else { @@ -220,13 +242,13 @@ void SvxToolbarConfigPage::DeleteSelectedTopLevel() void SvxToolbarConfigPage::DeleteSelectedContent() { - SvTreeListEntry *pActEntry = m_pContentsListBox->FirstSelected(); + int nActEntry = m_xContentsListBox->get_selected_index(); - if ( pActEntry != nullptr ) + if (nActEntry != -1) { // get currently selected entry SvxConfigEntry* pEntry = - static_cast<SvxConfigEntry*>(pActEntry->GetUserData()); + reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64()); SvxConfigEntry* pToolbar = GetTopLevelSelection(); @@ -234,7 +256,7 @@ void SvxToolbarConfigPage::DeleteSelectedContent() SvxConfigPageHelper::RemoveEntry( pToolbar->GetEntries(), pEntry ); // remove toolbar entry from UI - m_pContentsListBox->GetModel()->Remove( pActEntry ); + m_xContentsListBox->remove(nActEntry); // delete data for toolbar entry delete pEntry; @@ -245,10 +267,10 @@ void SvxToolbarConfigPage::DeleteSelectedContent() // if this is the last entry in the toolbar and it is a user // defined toolbar pop up a dialog asking the user if they // want to delete the toolbar - if ( m_pContentsListBox->GetEntryCount() == 0 && + if ( m_xContentsListBox->n_children() == 0 && GetTopLevelSelection()->IsDeletable() ) { - std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetDialogFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, CuiResId(RID_SXVSTR_CONFIRM_DELETE_TOOLBAR))); if (xQueryBox->run() == RET_YES) @@ -259,9 +281,9 @@ void SvxToolbarConfigPage::DeleteSelectedContent() } } -IMPL_LINK( SvxToolbarConfigPage, MoveHdl, Button *, pButton, void ) +IMPL_LINK( SvxToolbarConfigPage, MoveHdl, weld::Button&, rButton, void ) { - MoveEntry(pButton == m_pMoveUpButton); + MoveEntry(&rButton == m_xMoveUpButton.get()); } void SvxToolbarConfigPage::MoveEntry( bool bMoveUp ) @@ -282,18 +304,18 @@ void SvxToolbarConfigPage::MoveEntry( bool bMoveUp ) void SvxToolbarConfigPage::Init() { // ensure that the UI is cleared before populating it - m_pTopLevelListBox->Clear(); - m_pContentsListBox->Clear(); + m_xTopLevelListBox->clear(); + m_xContentsListBox->clear(); ReloadTopLevelListBox(); sal_Int32 nPos = 0; if ( !m_aURLToSelect.isEmpty() ) { - for ( sal_Int32 i = 0 ; i < m_pTopLevelListBox->GetEntryCount(); ++i ) + for (sal_Int32 i = 0, nCount = m_xTopLevelListBox->get_count(); i < nCount; ++i) { SvxConfigEntry* pData = - static_cast<SvxConfigEntry*>(m_pTopLevelListBox->GetEntryData( i )); + reinterpret_cast<SvxConfigEntry*>(m_xTopLevelListBox->get_id(i).toInt64()); if ( pData->GetCommand().equals( m_aURLToSelect ) ) { @@ -307,14 +329,14 @@ void SvxToolbarConfigPage::Init() m_aURLToSelect += "standardbar"; } - m_pTopLevelListBox->SelectEntryPos(nPos); - m_pTopLevelListBox->GetSelectHdl().Call(*m_pTopLevelListBox); + m_xTopLevelListBox->set_active(nPos); + SelectElement(); - m_pCommandCategoryListBox->Init( + m_xCommandCategoryListBox->Init( comphelper::getProcessComponentContext(), m_xFrame, vcl::CommandInfoProvider::GetModuleIdentifier(m_xFrame)); - m_pCommandCategoryListBox->categorySelected( m_pFunctions, OUString(), GetSaveInData() ); + m_xCommandCategoryListBox->categorySelected(m_xFunctions.get(), OUString(), GetSaveInData()); } SaveInData* SvxToolbarConfigPage::CreateSaveInData( @@ -327,17 +349,16 @@ SaveInData* SvxToolbarConfigPage::CreateSaveInData( new ToolbarSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig )); } -IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectToolbarEntry, SvTreeListBox *, void ) +IMPL_LINK_NOARG(SvxToolbarConfigPage, SelectToolbarEntry, weld::TreeView&, void) { UpdateButtonStates(); } -IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void ) +IMPL_LINK( SvxToolbarConfigPage, GearHdl, const OString&, rIdent, void ) { - OString sIdent = pButton->GetCurItemIdent(); SvxConfigEntry* pCurrentToolbar = GetTopLevelSelection(); - if (sIdent == "gear_add") + if (rIdent == "gear_add") { OUString prefix = CuiResId( RID_SVXSTR_NEW_TOOLBAR ); @@ -347,13 +368,13 @@ IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void ) OUString aNewURL = SvxConfigPageHelper::generateCustomURL( GetSaveInData()->GetEntries() ); - SvxNewToolbarDialog aNameDialog(GetFrameWeld(), aNewName); + SvxNewToolbarDialog aNameDialog(GetDialogFrameWeld(), aNewName); - // Reflect the actual m_pSaveInListBox into the new toolbar dialog - for (sal_Int32 i = 0; i < m_pSaveInListBox->GetEntryCount(); ++i) - aNameDialog.m_xSaveInListBox->append_text(m_pSaveInListBox->GetEntry(i)); + // Reflect the actual m_xSaveInListBox into the new toolbar dialog + for (int i = 0, nCount = m_xSaveInListBox->get_count(); i < nCount; ++i) + aNameDialog.m_xSaveInListBox->append_text(m_xSaveInListBox->get_text(i)); - aNameDialog.m_xSaveInListBox->set_active(m_pSaveInListBox->GetSelectedEntryPos()); + aNameDialog.m_xSaveInListBox->set_active(m_xSaveInListBox->get_active()); if (aNameDialog.run() == RET_OK) { @@ -363,13 +384,13 @@ IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void ) int nInsertPos = aNameDialog.m_xSaveInListBox->get_active(); ToolbarSaveInData* pData = - static_cast<ToolbarSaveInData*>( - m_pSaveInListBox->GetEntryData( nInsertPos ) ); + reinterpret_cast<ToolbarSaveInData*>( + m_xSaveInListBox->get_id(nInsertPos).toInt64() ); if ( GetSaveInData() != pData ) { - m_pSaveInListBox->SelectEntryPos( nInsertPos ); - m_pSaveInListBox->GetSelectHdl().Call(*m_pSaveInListBox); + m_xSaveInListBox->set_active(nInsertPos); + SelectSaveInLocation(*m_xSaveInListBox); } SvxConfigEntry* pToolbar = @@ -380,15 +401,15 @@ IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void ) pData->CreateToolbar( pToolbar ); - nInsertPos = m_pTopLevelListBox->InsertEntry( pToolbar->GetName() ); - m_pTopLevelListBox->SetEntryData( nInsertPos, pToolbar ); - m_pTopLevelListBox->SelectEntryPos( nInsertPos ); - m_pTopLevelListBox->GetSelectHdl().Call(*m_pTopLevelListBox); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pToolbar))); + m_xTopLevelListBox->append(sId, pToolbar->GetName()); + m_xTopLevelListBox->set_active_id(sId); + SelectElement(); pData->SetModified(); } } - else if (sIdent == "gear_delete") + else if (rIdent == "gear_delete") { if ( pCurrentToolbar && pCurrentToolbar->IsDeletable() ) { @@ -396,20 +417,20 @@ IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void ) UpdateButtonStates(); } } - else if (sIdent == "gear_rename") + else if (rIdent == "gear_rename") { - sal_Int32 nSelectionPos = m_pTopLevelListBox->GetSelectedEntryPos(); + sal_Int32 nSelectionPos = m_xTopLevelListBox->get_active(); SvxConfigEntry* pToolbar = - static_cast<SvxConfigEntry*>(m_pTopLevelListBox->GetEntryData( nSelectionPos )); + reinterpret_cast<SvxConfigEntry*>(m_xTopLevelListBox->get_id(nSelectionPos).toInt64()); ToolbarSaveInData* pSaveInData = static_cast<ToolbarSaveInData*>( GetSaveInData() ); //Rename the toolbar OUString sCurrentName( SvxConfigPageHelper::stripHotKey( pToolbar->GetName() ) ); OUString sDesc = CuiResId( RID_SVXSTR_LABEL_NEW_NAME ); - SvxNameDialog aNameDialog( GetFrameWeld(), sCurrentName, sDesc ); - aNameDialog.set_help_id( HID_SVX_CONFIG_RENAME_TOOLBAR ); - aNameDialog.set_title( CuiResId( RID_SVXSTR_RENAME_TOOLBAR ) ); + SvxNameDialog aNameDialog(GetDialogFrameWeld(), sCurrentName, sDesc); + aNameDialog.set_help_id(HID_SVX_CONFIG_RENAME_TOOLBAR); + aNameDialog.set_title(CuiResId(RID_SVXSTR_RENAME_TOOLBAR)); if ( aNameDialog.run() == RET_OK ) { @@ -422,14 +443,13 @@ IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void ) pSaveInData->ApplyToolbar( pToolbar ); // have to use remove and insert to change the name - m_pTopLevelListBox->RemoveEntry( nSelectionPos ); - nSelectionPos = - m_pTopLevelListBox->InsertEntry( sNewName, nSelectionPos ); - m_pTopLevelListBox->SetEntryData( nSelectionPos, pToolbar ); - m_pTopLevelListBox->SelectEntryPos( nSelectionPos ); + m_xTopLevelListBox->remove(nSelectionPos); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pToolbar))); + m_xTopLevelListBox->insert(nSelectionPos, sNewName, &sId, nullptr, nullptr); + m_xTopLevelListBox->set_active_id(sId); } } - else if (sIdent == "gear_iconOnly" || sIdent == "gear_textOnly" || sIdent == "gear_iconAndText") + else if (rIdent == "gear_iconOnly" || rIdent == "gear_textOnly" || rIdent == "gear_iconAndText") { ToolbarSaveInData* pSaveInData = static_cast<ToolbarSaveInData*>( GetSaveInData() ); @@ -440,48 +460,46 @@ IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void ) } sal_Int32 nStyle = 0; - if (sIdent == "gear_iconOnly") + if (rIdent == "gear_iconOnly") nStyle = 0; - else if (sIdent == "gear_textOnly") + else if (rIdent == "gear_textOnly") nStyle = 1; - else if (sIdent == "gear_iconAndText") + else if (rIdent == "gear_iconAndText") nStyle = 2; pCurrentToolbar->SetStyle( nStyle ); pSaveInData->SetSystemStyle( m_xFrame, pCurrentToolbar->GetCommand(), nStyle ); - m_pTopLevelListBox->GetSelectHdl().Call( *m_pTopLevelListBox ); + SelectElement(); } else { //This block should never be reached - SAL_WARN("cui.customize", "Unknown gear menu option: " << sIdent); + SAL_WARN("cui.customize", "Unknown gear menu option: " << rIdent); return; } } -IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectCategory, ListBox&, void ) +IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectCategory, weld::ComboBox&, void ) { - OUString aSearchTerm( m_pSearchEdit->GetText() ); + OUString aSearchTerm(m_xSearchEdit->get_text()); - m_pCommandCategoryListBox->categorySelected( m_pFunctions, aSearchTerm, GetSaveInData() ); + m_xCommandCategoryListBox->categorySelected(m_xFunctions.get(), aSearchTerm, GetSaveInData()); } -IMPL_LINK_NOARG( SvxToolbarConfigPage, AddCommandHdl, Button *, void ) +IMPL_LINK_NOARG( SvxToolbarConfigPage, AddCommandHdl, weld::Button&, void ) { AddFunction(); } -IMPL_LINK_NOARG( SvxToolbarConfigPage, RemoveCommandHdl, Button *, void ) +IMPL_LINK_NOARG( SvxToolbarConfigPage, RemoveCommandHdl, weld::Button&, void ) { DeleteSelectedContent(); } -IMPL_LINK( SvxToolbarConfigPage, InsertHdl, MenuButton *, pButton, void ) +IMPL_LINK(SvxToolbarConfigPage, InsertHdl, const OString&, rIdent, void) { - OString sIdent = pButton->GetCurItemIdent(); - - if (sIdent == "insertseparator") + if (rIdent == "insertseparator") { // Get the currently selected toolbar SvxConfigEntry* pToolbar = GetTopLevelSelection(); @@ -489,11 +507,8 @@ IMPL_LINK( SvxToolbarConfigPage, InsertHdl, MenuButton *, pButton, void ) SvxConfigEntry* pNewEntryData = new SvxConfigEntry; pNewEntryData->SetUserDefined(); - SvTreeListEntry* pNewLBEntry = InsertEntry( pNewEntryData ); - - m_pContentsListBox->SetCheckButtonInvisible( pNewLBEntry ); - m_pContentsListBox->SetCheckButtonState( - pNewLBEntry, SvButtonState::Tristate ); + int nPos = InsertEntry(pNewEntryData, -1); + InsertEntryIntoUI(pNewEntryData, nPos, 1); static_cast<ToolbarSaveInData*>( GetSaveInData())->ApplyToolbar( pToolbar ); @@ -502,35 +517,34 @@ IMPL_LINK( SvxToolbarConfigPage, InsertHdl, MenuButton *, pButton, void ) else { //This block should never be reached - SAL_WARN("cui.customize", "Unknown insert option: " << sIdent); + SAL_WARN("cui.customize", "Unknown insert option: " << rIdent); return; } } -IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) +IMPL_LINK(SvxToolbarConfigPage, ModifyItemHdl, const OString&, rIdent, void) { bool bNeedsApply = false; // get currently selected toolbar SvxConfigEntry* pToolbar = GetTopLevelSelection(); - OString sIdent = pButton->GetCurItemIdent(); - if (sIdent.isEmpty() || pToolbar == nullptr) + if (rIdent.isEmpty() || pToolbar == nullptr) { - SAL_WARN("cui.customize", "No toolbar selected, or empty sIdent!"); + SAL_WARN("cui.customize", "No toolbar selected, or empty rIdent!"); return; } - if (sIdent == "renameItem") + if (rIdent == "renameItem") { - SvTreeListEntry* pActEntry = m_pContentsListBox->GetCurEntry(); + int nActEntry = m_xContentsListBox->get_selected_index(); SvxConfigEntry* pEntry = - static_cast<SvxConfigEntry*>(pActEntry->GetUserData()); + reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64()); OUString aNewName( SvxConfigPageHelper::stripHotKey( pEntry->GetName() ) ); OUString aDesc = CuiResId( RID_SVXSTR_LABEL_NEW_NAME ); - SvxNameDialog aNameDialog(GetFrameWeld(), aNewName, aDesc); + SvxNameDialog aNameDialog(GetDialogFrameWeld(), aNewName, aDesc); aNameDialog.set_help_id(HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM); aNameDialog.set_title(CuiResId(RID_SVXSTR_RENAME_TOOLBAR)); @@ -543,19 +557,15 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) else pEntry->SetName( aNewName ); - m_pContentsListBox->SetEntryText( pActEntry, aNewName ); + m_xContentsListBox->set_text(nActEntry, aNewName, 2); bNeedsApply = true; } } - else if (sIdent == "changeIcon") + else if (rIdent == "changeIcon") { - SvTreeListEntry* pActEntry = m_pContentsListBox->GetCurEntry(); + int nActEntry = m_xContentsListBox->get_selected_index(); SvxConfigEntry* pEntry = - static_cast<SvxConfigEntry*>(pActEntry->GetUserData()); - - // Position of entry within the list - // TODO: Add a GetSelectionPos() method to the SvTreeListBox class - sal_uInt16 nSelectionPos = m_pContentsListBox->GetModel()->GetAbsPos( pActEntry ); + reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64()); SvxIconSelectorDialog aIconDialog(GetDialogFrameWeld(), GetSaveInData()->GetImageManager(), @@ -575,13 +585,13 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) if ( !pEntry->GetBackupGraphic().is() ) { - css::uno::Reference< css::graphic::XGraphic > backup; - backup = SvxConfigPageHelper::GetGraphic( - GetSaveInData()->GetImageManager(), aURLSeq[ 0 ] ); + css::uno::Reference< css::graphic::XGraphic > backup = + SvxConfigPageHelper::GetGraphic(GetSaveInData()->GetImageManager(), + aURLSeq[0]); if ( backup.is() ) { - pEntry->SetBackupGraphic( backup ); + pEntry->SetBackupGraphic(backup); } } @@ -591,16 +601,15 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) GetSaveInData()->GetImageManager()->replaceImages( SvxConfigPageHelper::GetImageType(), aURLSeq, aGraphicSeq ); - m_pContentsListBox->GetModel()->Remove( pActEntry ); - SvTreeListEntry* pNewLBEntry = - InsertEntryIntoUI( pEntry, nSelectionPos ); + m_xContentsListBox->remove(nActEntry); - m_pContentsListBox->SetCheckButtonState( pNewLBEntry, - pEntry->IsVisible() ? - SvButtonState::Checked : SvButtonState::Unchecked ); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); + m_xContentsListBox->insert(nActEntry, sId); + m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible(), 0); + InsertEntryIntoUI(pEntry, nActEntry, 1); - m_pContentsListBox->Select( pNewLBEntry ); - m_pContentsListBox->MakeVisible( pNewLBEntry ); + m_xContentsListBox->select(nActEntry); + m_xContentsListBox->scroll_to_row(nActEntry); GetSaveInData()->PersistChanges( GetSaveInData()->GetImageManager() ); @@ -612,15 +621,11 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) } } } - else if (sIdent == "resetIcon") + else if (rIdent == "resetIcon") { - SvTreeListEntry* pActEntry = m_pContentsListBox->GetCurEntry(); + int nActEntry = m_xContentsListBox->get_selected_index(); SvxConfigEntry* pEntry = - static_cast<SvxConfigEntry*>(pActEntry->GetUserData()); - - // Position of entry within the list - // TODO: Add a GetSelectionPos() method to the SvTreeListBox class - sal_uInt16 nSelectionPos = m_pContentsListBox->GetModel()->GetAbsPos( pActEntry ); + reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64()); css::uno::Reference< css::graphic::XGraphic > backup = pEntry->GetBackupGraphic(); @@ -636,17 +641,15 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) GetSaveInData()->GetImageManager()->replaceImages( SvxConfigPageHelper::GetImageType(), aURLSeq, aGraphicSeq ); - m_pContentsListBox->GetModel()->Remove( pActEntry ); + m_xContentsListBox->remove(nActEntry); - SvTreeListEntry* pNewLBEntry = - InsertEntryIntoUI( pEntry, nSelectionPos ); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); + m_xContentsListBox->insert(nActEntry, sId); + m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible(), 0); + InsertEntryIntoUI(pEntry, nActEntry, 1); - m_pContentsListBox->SetCheckButtonState( pNewLBEntry, - pEntry->IsVisible() ? - SvButtonState::Checked : SvButtonState::Unchecked ); - - m_pContentsListBox->Select( pNewLBEntry ); - m_pContentsListBox->MakeVisible( pNewLBEntry ); + m_xContentsListBox->select(nActEntry); + m_xContentsListBox->scroll_to_row(nActEntry); // reset backup in entry pEntry->SetBackupGraphic( @@ -660,15 +663,11 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) SAL_WARN("cui.customize", "Error resetting image: " << e); } } - else if (sIdent == "restoreItem") + else if (rIdent == "restoreItem") { - SvTreeListEntry* pActEntry = m_pContentsListBox->GetCurEntry(); + int nActEntry = m_xContentsListBox->get_selected_index(); SvxConfigEntry* pEntry = - static_cast<SvxConfigEntry*>(pActEntry->GetUserData()); - - // Position of entry within the list - // TODO: Add a GetSelectionPos() method to the SvTreeListBox class - sal_uInt16 nSelectionPos = m_pContentsListBox->GetModel()->GetAbsPos( pActEntry ); + reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64()); ToolbarSaveInData* pSaveInData = static_cast<ToolbarSaveInData*>( GetSaveInData() ); @@ -679,8 +678,8 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) if ( !pEntry->GetName().equals( aSystemName ) ) { pEntry->SetName( aSystemName ); - m_pContentsListBox->SetEntryText( - pActEntry, SvxConfigPageHelper::stripHotKey( aSystemName ) ); + m_xContentsListBox->set_text( + nActEntry, SvxConfigPageHelper::stripHotKey(aSystemName), 2); bNeedsApply = true; } @@ -698,17 +697,16 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) GetSaveInData()->PersistChanges( GetSaveInData()->GetImageManager() ); - m_pContentsListBox->RemoveEntry( pActEntry ); + m_xContentsListBox->remove(nActEntry); - SvTreeListEntry* pNewLBEntry = - InsertEntryIntoUI( pEntry, nSelectionPos ); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); + m_xContentsListBox->insert(nActEntry, sId); + m_xContentsListBox->set_toggle(nActEntry, + pEntry->IsVisible(), 0); + InsertEntryIntoUI(pEntry, nActEntry, 1); - m_pContentsListBox->SetCheckButtonState( pNewLBEntry, - pEntry->IsVisible() ? - SvButtonState::Checked : SvButtonState::Unchecked ); - - m_pContentsListBox->Select( pNewLBEntry ); - m_pContentsListBox->MakeVisible( pNewLBEntry ); + m_xContentsListBox->select(nActEntry); + m_xContentsListBox->scroll_to_row(nActEntry); bNeedsApply = true; } @@ -720,7 +718,7 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) else { //This block should never be reached - SAL_WARN("cui.customize", "Unknown insert option: " << sIdent); + SAL_WARN("cui.customize", "Unknown insert option: " << rIdent); return; } @@ -731,14 +729,14 @@ IMPL_LINK( SvxToolbarConfigPage, ModifyItemHdl, MenuButton *, pButton, void ) } } -IMPL_LINK_NOARG( SvxToolbarConfigPage, ResetToolbarHdl, Button *, void ) +IMPL_LINK_NOARG(SvxToolbarConfigPage, ResetToolbarHdl, weld::Button&, void) { - sal_Int32 nSelectionPos = m_pTopLevelListBox->GetSelectedEntryPos(); + sal_Int32 nSelectionPos = m_xTopLevelListBox->get_active(); SvxConfigEntry* pToolbar = - static_cast<SvxConfigEntry*>(m_pTopLevelListBox->GetEntryData( nSelectionPos )); + reinterpret_cast<SvxConfigEntry*>(m_xTopLevelListBox->get_id(nSelectionPos).toInt64()); - std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetDialogFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, CuiResId(RID_SVXSTR_CONFIRM_RESTORE_DEFAULT))); if (xQueryBox->run() == RET_YES) @@ -748,115 +746,103 @@ IMPL_LINK_NOARG( SvxToolbarConfigPage, ResetToolbarHdl, Button *, void ) pSaveInData->RestoreToolbar( pToolbar ); - m_pTopLevelListBox->GetSelectHdl().Call( *m_pTopLevelListBox ); + SelectElement(); } } void SvxToolbarConfigPage::UpdateButtonStates() { SvxConfigEntry* pToolbar = GetTopLevelSelection(); - SvTreeListEntry* selection = m_pContentsListBox->GetCurEntry(); + int selection = m_xContentsListBox->get_selected_index(); bool bIsSeparator = - selection && static_cast<SvxConfigEntry*>(selection->GetUserData())->IsSeparator(); + selection != -1 && reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(selection).toInt64())->IsSeparator(); bool bIsValidSelection = - !(m_pContentsListBox->GetEntryCount() == 0 || selection == nullptr); + !(m_xContentsListBox->n_children() == 0 || selection == -1); - m_pMoveUpButton->Enable( bIsValidSelection ); - m_pMoveDownButton->Enable( bIsValidSelection ); + m_xMoveUpButton->set_sensitive( bIsValidSelection ); + m_xMoveDownButton->set_sensitive( bIsValidSelection ); - m_pRemoveCommandButton->Enable( bIsValidSelection ); + m_xRemoveCommandButton->set_sensitive( bIsValidSelection ); - m_pModifyBtn->Enable( bIsValidSelection && !bIsSeparator ); + m_xModifyBtn->set_sensitive( bIsValidSelection && !bIsSeparator ); // Handle the gear button - PopupMenu* pPopup = m_pGearBtn->GetPopupMenu(); // "gear_add" option is always enabled - pPopup->EnableItem( "gear_delete", pToolbar && pToolbar->IsDeletable() ); - pPopup->EnableItem( "gear_rename", pToolbar && pToolbar->IsRenamable() ); + m_xGearBtn->set_item_sensitive("gear_delete", pToolbar && pToolbar->IsDeletable()); + m_xGearBtn->set_item_sensitive("gear_rename", pToolbar && pToolbar->IsRenamable()); } short SvxToolbarConfigPage::QueryReset() { OUString msg = CuiResId( RID_SVXSTR_CONFIRM_TOOLBAR_RESET ); - OUString saveInName = m_pSaveInListBox->GetEntry( - m_pSaveInListBox->GetSelectedEntryPos() ); + OUString saveInName = m_xSaveInListBox->get_active_text(); OUString label = SvxConfigPageHelper::replaceSaveInName( msg, saveInName ); - std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetDialogFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, label)); return xQueryBox->run(); } -IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectToolbar, ListBox&, void ) +void SvxToolbarConfigPage::SelectElement() { - m_pContentsListBox->Clear(); + m_xContentsListBox->clear(); SvxConfigEntry* pToolbar = GetTopLevelSelection(); if ( pToolbar == nullptr ) { //TODO: Disable related buttons - m_pInsertBtn->Enable( false ); - m_pResetBtn->Enable( false ); - m_pGearBtn->Enable( false ); + m_xInsertBtn->set_sensitive( false ); + m_xResetBtn->set_sensitive( false ); + m_xGearBtn->set_sensitive( false ); return; } else { - m_pInsertBtn->Enable(); - m_pResetBtn->Enable(); - m_pGearBtn->Enable(); + m_xInsertBtn->set_sensitive(true); + m_xResetBtn->set_sensitive(true); + m_xGearBtn->set_sensitive(true); } - PopupMenu* pGearMenu = m_pGearBtn->GetPopupMenu(); - switch( pToolbar->GetStyle() ) + switch (pToolbar->GetStyle()) { case 0: { - pGearMenu->CheckItem( "gear_iconOnly" ); + m_xGearBtn->set_item_active("gear_iconOnly", true); break; } case 1: { - pGearMenu->CheckItem( "gear_textOnly" ); + m_xGearBtn->set_item_active("gear_textOnly", true); break; } case 2: { - pGearMenu->CheckItem( "gear_iconAndText" ); + m_xGearBtn->set_item_active("gear_iconAndText", true); break; } } + int i = 0; SvxEntries* pEntries = pToolbar->GetEntries(); for (auto const& entry : *pEntries) { - SvTreeListEntry* pNewLBEntry = InsertEntryIntoUI(entry); - - if(entry->IsSeparator()) - m_pContentsListBox->SetCheckButtonInvisible( pNewLBEntry ); - - if (entry->IsBinding()) - { - m_pContentsListBox->SetCheckButtonState( pNewLBEntry, - entry->IsVisible() ? SvButtonState::Checked : SvButtonState::Unchecked ); - } - else - { - m_pContentsListBox->SetCheckButtonState( - pNewLBEntry, SvButtonState::Tristate ); - } + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(entry))); + m_xContentsListBox->insert(i, sId); + if (entry->IsBinding() && !entry->IsSeparator()) + m_xContentsListBox->set_toggle(i, entry->IsVisible(), 0); + InsertEntryIntoUI(entry, i, 1); + ++i; } UpdateButtonStates(); } -void SvxToolbarConfigPage::AddFunction( - SvTreeListEntry* pTarget, bool bFront ) +void SvxToolbarConfigPage::AddFunction(int nTarget, bool bFront) { SvxConfigEntry* pToolbar = GetTopLevelSelection(); @@ -864,26 +850,22 @@ void SvxToolbarConfigPage::AddFunction( return; // Add the command to the contents listbox of the selected toolbar - SvTreeListEntry* pNewLBEntry = - SvxConfigPage::AddFunction( pTarget, bFront, true/*bAllowDuplicates*/ ); + int nNewLBEntry = + SvxConfigPage::AddFunction(nTarget, bFront, true/*bAllowDuplicates*/); - if (pNewLBEntry == nullptr) + if (nNewLBEntry == -1) return; - SvxConfigEntry* pEntry = static_cast<SvxConfigEntry*>(pNewLBEntry->GetUserData()); + SvxConfigEntry* pEntry = reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nNewLBEntry).toInt64()); - if ( pEntry->IsBinding() ) - { - pEntry->SetVisible( true ); - m_pContentsListBox->SetCheckButtonState( - pNewLBEntry, SvButtonState::Checked ); - } - else + if ( pEntry->IsBinding() ) //TODO sep ? { - m_pContentsListBox->SetCheckButtonState( - pNewLBEntry, SvButtonState::Tristate ); + pEntry->SetVisible(true); + m_xContentsListBox->set_toggle(nNewLBEntry, true, 0); } + InsertEntryIntoUI(pEntry, nNewLBEntry, 1); + // Changes are not visible on the toolbar until this point // TODO: Figure out a way to show the changes on the toolbar, but revert if // the dialog is closed by pressing "Cancel" @@ -894,187 +876,56 @@ void SvxToolbarConfigPage::AddFunction( } } -SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(vcl::Window* pParent, SvxToolbarConfigPage* pPg) - : SvxMenuEntriesListBox(pParent, pPg) - , pPage(pPg) +SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(std::unique_ptr<weld::TreeView> xParent, SvxToolbarConfigPage* pPg) + : SvxMenuEntriesListBox(std::move(xParent), pPg) { - m_pButtonData.reset(new SvLBoxButtonData( this )); - BuildCheckBoxButtonImages( m_pButtonData.get() ); - EnableCheckButton( m_pButtonData.get() ); + m_xControl->connect_toggled(LINK(this, SvxToolbarEntriesListBox, CheckButtonHdl)); + m_xControl->connect_key_press(Link<const KeyEvent&, bool>()); //acknowledge we first remove the old one + m_xControl->connect_key_press(LINK(this, SvxToolbarEntriesListBox, KeyInputHdl)); // then add the new one } SvxToolbarEntriesListBox::~SvxToolbarEntriesListBox() { - disposeOnce(); -} - -void SvxToolbarEntriesListBox::dispose() -{ - m_pButtonData.reset(); - - pPage.clear(); - SvxMenuEntriesListBox::dispose(); } -void SvxToolbarEntriesListBox::BuildCheckBoxButtonImages( SvLBoxButtonData* pData ) +void SvxToolbarEntriesListBox::ChangedVisibility(int nRow) { - // Build checkbox images according to the current application - // settings. This is necessary to be able to have correct colors - // in all color modes, like high contrast. - const AllSettings& rSettings = Application::GetSettings(); - - ScopedVclPtrInstance< VirtualDevice > pVDev; - Size aSize( 26, 20 ); - - pVDev->SetOutputSizePixel( aSize ); - - Image aImage = GetSizedImage( *pVDev, aSize, - CheckBox::GetCheckImage( rSettings, DrawButtonFlags::Default )); - - // Fill button data struct with new images - pData->SetImage(SvBmp::UNCHECKED, aImage); - pData->SetImage(SvBmp::CHECKED, GetSizedImage( *pVDev, aSize, CheckBox::GetCheckImage( rSettings, DrawButtonFlags::Checked )) ); - pData->SetImage(SvBmp::HICHECKED, GetSizedImage( *pVDev, aSize, CheckBox::GetCheckImage( rSettings, DrawButtonFlags::Checked | DrawButtonFlags::Pressed )) ); - pData->SetImage(SvBmp::HIUNCHECKED, GetSizedImage( *pVDev, aSize, CheckBox::GetCheckImage( rSettings, DrawButtonFlags::Default | DrawButtonFlags::Pressed)) ); - pData->SetImage(SvBmp::TRISTATE, GetSizedImage( *pVDev, aSize, Image() ) ); // Use tristate bitmaps to have no checkbox for separator entries - pData->SetImage(SvBmp::HITRISTATE, GetSizedImage( *pVDev, aSize, Image() ) ); -} + SvxConfigEntry* pEntryData = + reinterpret_cast<SvxConfigEntry*>(m_xControl->get_id(nRow).toInt64()); -Image SvxToolbarEntriesListBox::GetSizedImage( - VirtualDevice& rVDev, const Size& aNewSize, const Image& aImage ) -{ - // Create new checkbox images for treelistbox. They must have a - // decent width to have a clear column for the visibility checkbox. - - // Standard transparent color is light magenta as is won't be - // used for other things - Color aFillColor( COL_LIGHTMAGENTA ); - - // Position image at the center of (width-2),(height) rectangle. - // We need 2 pixels to have a bigger border to the next button image - sal_uInt16 nPosX = std::max( static_cast<sal_uInt16>(((( aNewSize.Width() - 2 ) - aImage.GetSizePixel().Width() ) / 2 ) - 1), sal_uInt16(0) ); - sal_uInt16 nPosY = std::max( static_cast<sal_uInt16>(((( aNewSize.Height() - 2 ) - aImage.GetSizePixel().Height() ) / 2 ) + 1), sal_uInt16(0) ); - Point aPos( std::max<sal_uInt16>(nPosX, 0), std::max<sal_uInt16>(nPosY, 0) ); - rVDev.SetFillColor( aFillColor ); - rVDev.SetLineColor( aFillColor ); - rVDev.DrawRect( ::tools::Rectangle( Point(), aNewSize )); - rVDev.DrawImage( aPos, aImage ); - - // Draw separator line 2 pixels left from the right border - Color aLineColor = GetDisplayBackground().GetColor().IsDark() ? COL_WHITE : COL_BLACK; - rVDev.SetLineColor( aLineColor ); - rVDev.DrawLine( Point( aNewSize.Width()-3, 0 ), Point( aNewSize.Width()-3, aNewSize.Height()-1 )); - - // Create new image that uses the fillcolor as transparent - return Image(BitmapEx(rVDev.GetBitmapEx(Point(), aNewSize).GetBitmap(), aFillColor)); -} - -void SvxToolbarEntriesListBox::DataChanged( const DataChangedEvent& rDCEvt ) -{ - SvTreeListBox::DataChanged( rDCEvt ); - - if (( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && - ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE )) - { - BuildCheckBoxButtonImages( m_pButtonData.get() ); - Invalidate(); - } -} - - -void SvxToolbarEntriesListBox::ChangeVisibility( SvTreeListEntry* pEntry ) -{ - if ( pEntry != nullptr ) + if (pEntryData->IsBinding()) { - SvxConfigEntry* pEntryData = - static_cast<SvxConfigEntry*>(pEntry->GetUserData()); - - if ( pEntryData->IsBinding() ) - { - pEntryData->SetVisible( !pEntryData->IsVisible() ); - - SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection(); + pEntryData->SetVisible(m_xControl->get_toggle(nRow, 0)); - ToolbarSaveInData* pToolbarSaveInData = static_cast<ToolbarSaveInData*>( - pPage->GetSaveInData() ); + SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection(); - pToolbarSaveInData->ApplyToolbar( pToolbar ); + ToolbarSaveInData* pToolbarSaveInData = static_cast<ToolbarSaveInData*>( + pPage->GetSaveInData() ); - SetCheckButtonState( pEntry, pEntryData->IsVisible() ? - SvButtonState::Checked : SvButtonState::Unchecked ); - } + pToolbarSaveInData->ApplyToolbar( pToolbar ); } } -void SvxToolbarEntriesListBox::CheckButtonHdl() +IMPL_LINK(SvxToolbarEntriesListBox, CheckButtonHdl, const row_col&, rRowCol, void) { - ChangeVisibility( GetHdlEntry() ); + ChangedVisibility(rRowCol.first); } -void SvxToolbarEntriesListBox::KeyInput( const KeyEvent& rKeyEvent ) +IMPL_LINK(SvxToolbarEntriesListBox, KeyInputHdl, const KeyEvent&, rKeyEvent, bool) { // space key will change visibility of toolbar items if ( rKeyEvent.GetKeyCode() == KEY_SPACE ) { - ChangeVisibility( GetCurEntry() ); - } - else - { - // pass on to superclass - SvxMenuEntriesListBox::KeyInput( rKeyEvent ); - } -} - -TriState SvxToolbarEntriesListBox::NotifyMoving( - SvTreeListEntry* pTarget, SvTreeListEntry* pSource, - SvTreeListEntry*& rpNewParent, sal_uLong& rNewChildPos) -{ - TriState result = SvxMenuEntriesListBox::NotifyMoving( - pTarget, pSource, rpNewParent, rNewChildPos ); - - if ( result ) - { - // Instant Apply changes to UI - SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection(); - if ( pToolbar != nullptr ) + int nRow = m_xControl->get_selected_index(); + SvxConfigEntry* pEntryData = reinterpret_cast<SvxConfigEntry*>(m_xControl->get_id(nRow).toInt64()); + if (pEntryData->IsBinding() && !pEntryData->IsSeparator()) { - ToolbarSaveInData* pSaveInData = - static_cast<ToolbarSaveInData*>( pPage->GetSaveInData() ); - pSaveInData->ApplyToolbar( pToolbar ); + m_xControl->set_toggle(nRow, !m_xControl->get_toggle(nRow, 0), 0); + ChangedVisibility(nRow); } + return true; } - - return result; -} - -TriState SvxToolbarEntriesListBox::NotifyCopying( - SvTreeListEntry* pTarget, - SvTreeListEntry*, - SvTreeListEntry*&, - sal_uLong&) -{ - - if ( !m_bIsInternalDrag ) - { - // if the target is NULL then add function to the start of the list - static_cast<SvxToolbarConfigPage*>(pPage.get())->AddFunction( pTarget, pTarget == nullptr ); - - // Instant Apply changes to UI - SvxConfigEntry* pToolbar = pPage->GetTopLevelSelection(); - if ( pToolbar != nullptr ) - { - ToolbarSaveInData* pSaveInData = - static_cast<ToolbarSaveInData*>( pPage->GetSaveInData() ); - pSaveInData->ApplyToolbar( pToolbar ); - } - - // AddFunction already adds the listbox entry so return TRISTATE_FALSE - // to stop another listbox entry being added - return TRISTATE_FALSE; - } - - // Copying is only allowed from external controls, not within the listbox - return TRISTATE_FALSE; + return SvxMenuEntriesListBox::KeyInputHdl(rKeyEvent); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/customize/acccfg.cxx b/cui/source/customize/acccfg.cxx index 4146be2ae20d..40f15d588721 100644 --- a/cui/source/customize/acccfg.cxx +++ b/cui/source/customize/acccfg.cxx @@ -887,6 +887,7 @@ SfxAcceleratorConfigPage::SfxAcceleratorConfigPage(TabPageParent pParent, const m_xOfficeButton->connect_clicked( LINK( this, SfxAcceleratorConfigPage, RadioHdl )); m_xModuleButton->connect_clicked( LINK( this, SfxAcceleratorConfigPage, RadioHdl )); m_xSearchEdit->connect_changed( LINK( this, SfxAcceleratorConfigPage, SearchUpdateHdl )); + m_xSearchEdit->connect_focus_out(LINK(this, SfxAcceleratorConfigPage, FocusOut_Impl)); // detect max keyname width int nMaxWidth = 0; @@ -1121,6 +1122,15 @@ IMPL_LINK_NOARG(SfxAcceleratorConfigPage, SearchUpdateHdl, weld::Entry&, void) m_aUpdateDataTimer.Start(); } +IMPL_LINK_NOARG(SfxAcceleratorConfigPage, FocusOut_Impl, weld::Widget&, void) +{ + if (m_aUpdateDataTimer.IsActive()) + { + m_aUpdateDataTimer.Stop(); + m_aUpdateDataTimer.Invoke(); + } +} + IMPL_LINK_NOARG(SfxAcceleratorConfigPage, Load, weld::Button&, void) { // ask for filename, where we should load the new config data from diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index d830b2ef8f7e..8f28bb77dc64 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -101,8 +101,6 @@ #include <dlgname.hxx> -#define ENTRY_HEIGHT 16 - namespace uno = com::sun::star::uno; namespace frame = com::sun::star::frame; namespace lang = com::sun::star::lang; @@ -178,12 +176,12 @@ SvxConfigPage::CanConfig( const OUString& aModuleId ) static VclPtr<SfxTabPage> CreateSvxMenuConfigPage( TabPageParent pParent, const SfxItemSet* rSet ) { - return VclPtr<SvxMenuConfigPage>::Create( pParent.pParent, *rSet ); + return VclPtr<SvxMenuConfigPage>::Create(pParent, *rSet); } static VclPtr<SfxTabPage> CreateSvxContextMenuConfigPage( TabPageParent pParent, const SfxItemSet* rSet ) { - return VclPtr<SvxMenuConfigPage>::Create( pParent.pParent, *rSet, false ); + return VclPtr<SvxMenuConfigPage>::Create(pParent, *rSet, false); } static VclPtr<SfxTabPage> CreateKeyboardConfigPage( TabPageParent pParent, const SfxItemSet* rSet ) @@ -193,7 +191,7 @@ static VclPtr<SfxTabPage> CreateKeyboardConfigPage( TabPageParent pParent, const static VclPtr<SfxTabPage> CreateSvxToolbarConfigPage( TabPageParent pParent, const SfxItemSet* rSet ) { - return VclPtr<SvxToolbarConfigPage>::Create( pParent.pParent, *rSet ); + return VclPtr<SvxToolbarConfigPage>::Create(pParent, *rSet); } static VclPtr<SfxTabPage> CreateSvxEventConfigPage( TabPageParent pParent, const SfxItemSet* rSet ) @@ -325,28 +323,17 @@ SaveInData::SaveInData( } } -Image SaveInData::GetImage( const OUString& rCommandURL ) +uno::Reference<graphic::XGraphic> SaveInData::GetImage(const OUString& rCommandURL) { - Image aImage; - uno::Reference< graphic::XGraphic > xGraphic = SvxConfigPageHelper::GetGraphic( m_xImgMgr, rCommandURL ); - if ( xGraphic.is() ) - { - aImage = Image( xGraphic ); - } - else if ( xDefaultImgMgr != nullptr && (*xDefaultImgMgr).is() ) + if (!xGraphic.is() && xDefaultImgMgr != nullptr && (*xDefaultImgMgr).is()) { xGraphic = SvxConfigPageHelper::GetGraphic( (*xDefaultImgMgr), rCommandURL ); - - if ( xGraphic.is() ) - { - aImage = Image( xGraphic ); - } } - return aImage; + return xGraphic; } bool SaveInData::PersistChanges( @@ -922,55 +909,25 @@ void ContextMenuSaveInData::ResetContextMenu( const SvxConfigEntry* pEntry ) m_pRootEntry.reset(); } -class PopupPainter : public SvLBoxString +void SvxMenuEntriesListBox::CreateDropDown() { -public: - explicit PopupPainter(const OUString& rStr) - : SvLBoxString(rStr) - { - } - - virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev, vcl::RenderContext& rRenderContext, - const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) override - { - SvLBoxString::Paint(rPos, rOutDev, rRenderContext, pView, rEntry); + int nWidth = m_xControl->get_text_height(); + m_xDropDown->SetOutputSizePixel(Size(nWidth, nWidth)); - rRenderContext.Push(PushFlags::FILLCOLOR); + int nSize = nWidth / 2; + int nHalfSize = nSize / 2; + int nY = nHalfSize; + int nX = 0; - long nX = rOutDev.GetSizePixel().Width(); - - ScrollBar* pVScroll = rOutDev.GetVScroll(); - if (pVScroll->IsVisible()) - { - nX -= pVScroll->GetSizePixel().Width(); - } + m_xDropDown->SetFillColor(COL_BLACK); - const SvViewDataItem* pItem = rOutDev.GetViewDataItem( &rEntry, this ); - nX -= pItem->maSize.Height(); - - long nSize = pItem->maSize.Height() / 2; - long nHalfSize = nSize / 2; - long nY = rPos.Y() + nHalfSize; - - if (rRenderContext.GetFillColor() == COL_WHITE) - { - rRenderContext.SetFillColor(COL_BLACK); - } - else - { - rRenderContext.SetFillColor(COL_WHITE); - } - - long n = 0; - while (n <= nHalfSize) - { - rRenderContext.DrawRect(::tools::Rectangle(nX + n, nY + n, nX + n, nY + nSize - n)); - ++n; - } - - rRenderContext.Pop(); + int n = 0; + while (n <= nHalfSize) + { + m_xDropDown->DrawRect(::tools::Rectangle(nX + n, nY + n, nX + n, nY + nSize - n)); + ++n; } -}; +} /****************************************************************************** * @@ -980,112 +937,21 @@ public: * listbox * *****************************************************************************/ -SvxMenuEntriesListBox::SvxMenuEntriesListBox(vcl::Window* pParent, SvxConfigPage* pPg) - : SvTreeListBox(pParent, WB_TABSTOP|WB_CLIPCHILDREN|WB_HIDESELECTION|WB_BORDER) +SvxMenuEntriesListBox::SvxMenuEntriesListBox(std::unique_ptr<weld::TreeView> xControl, SvxConfigPage* pPg) + : m_xControl(std::move(xControl)) + , m_xDropDown(VclPtr<VirtualDevice>::Create(*Application::GetDefaultDevice(), DeviceFormat::DEFAULT, DeviceFormat::DEFAULT)) , pPage(pPg) , m_bIsInternalDrag( false ) { - SetSpaceBetweenEntries( 3 ); - SetEntryHeight( ENTRY_HEIGHT ); - - SetHighlightRange(); - SetSelectionMode(SelectionMode::Single); - - SetDragDropMode( DragDropMode::CTRL_MOVE | - DragDropMode::APP_COPY | - DragDropMode::ENABLE_TOP | - DragDropMode::APP_DROP); + CreateDropDown(); + m_xControl->connect_key_press(LINK(this, SvxMenuEntriesListBox, KeyInputHdl)); } SvxMenuEntriesListBox::~SvxMenuEntriesListBox() { - disposeOnce(); -} - -void SvxMenuEntriesListBox::dispose() -{ - pPage.clear(); - SvTreeListBox::dispose(); -} - -// drag and drop support -DragDropMode SvxMenuEntriesListBox::NotifyStartDrag( - TransferDataContainer&, SvTreeListEntry* ) -{ - m_bIsInternalDrag = true; - return GetDragDropMode(); -} - -void SvxMenuEntriesListBox::DragFinished( sal_Int8 ) -{ - m_bIsInternalDrag = false; -} - -sal_Int8 SvxMenuEntriesListBox::AcceptDrop( const AcceptDropEvent& rEvt ) -{ - if ( m_bIsInternalDrag ) - { - // internal copy isn't allowed! - if ( rEvt.mnAction == DND_ACTION_COPY ) - return DND_ACTION_NONE; - else - return SvTreeListBox::AcceptDrop( rEvt ); - } - - // Always do COPY instead of MOVE if D&D comes from outside! - AcceptDropEvent aNewAcceptDropEvent( rEvt ); - aNewAcceptDropEvent.mnAction = DND_ACTION_COPY; - return SvTreeListBox::AcceptDrop( aNewAcceptDropEvent ); -} - -bool SvxMenuEntriesListBox::NotifyAcceptDrop( SvTreeListEntry* ) -{ - return true; -} - -TriState SvxMenuEntriesListBox::NotifyMoving( ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits