diff options
Diffstat (limited to 'extensions/source/bibliography/toolbar.cxx')
-rw-r--r-- | extensions/source/bibliography/toolbar.cxx | 134 |
1 files changed, 66 insertions, 68 deletions
diff --git a/extensions/source/bibliography/toolbar.cxx b/extensions/source/bibliography/toolbar.cxx index ae054801d8db..e4041c5a80f1 100644 --- a/extensions/source/bibliography/toolbar.cxx +++ b/extensions/source/bibliography/toolbar.cxx @@ -19,8 +19,7 @@ #include <sal/config.h> -#include <string_view> - +#include <comphelper/propertyvalue.hxx> #include <comphelper/processfactory.hxx> #include <com/sun/star/frame/XDispatch.hpp> #include <com/sun/star/frame/XDispatchProvider.hpp> @@ -32,11 +31,12 @@ #include <o3tl/any.hxx> #include <svtools/miscopt.hxx> #include <svtools/imgdef.hxx> +#include <utility> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> -#include <vcl/menu.hxx> #include <vcl/mnemonic.hxx> #include <vcl/event.hxx> +#include <vcl/weldutils.hxx> #include <bitmaps.hlst> #include "bibtools.hxx" @@ -49,9 +49,9 @@ using namespace ::com::sun::star::beans; // Constants -------------------------------------------------------------- -BibToolBarListener::BibToolBarListener(BibToolBar *pTB, const OUString& aStr, sal_uInt16 nId): +BibToolBarListener::BibToolBarListener(BibToolBar *pTB, OUString aStr, ToolBoxItemId nId): nIndex(nId), - aCommand(aStr), + aCommand(std::move(aStr)), pToolBar(pTB) { } @@ -77,7 +77,7 @@ void BibToolBarListener::statusChanged(const css::frame::FeatureStateEvent& rEvt }; -BibTBListBoxListener::BibTBListBoxListener(BibToolBar *pTB, const OUString& aStr, sal_uInt16 nId): +BibTBListBoxListener::BibTBListBoxListener(BibToolBar *pTB, const OUString& aStr, ToolBoxItemId nId): BibToolBarListener(pTB,aStr,nId) { } @@ -115,7 +115,7 @@ void BibTBListBoxListener::statusChanged(const css::frame::FeatureStateEvent& rE pToolBar->SelectSourceEntry(rEvt.FeatureDescriptor); }; -BibTBQueryMenuListener::BibTBQueryMenuListener(BibToolBar *pTB, const OUString& aStr, sal_uInt16 nId): +BibTBQueryMenuListener::BibTBQueryMenuListener(BibToolBar *pTB, const OUString& aStr, ToolBoxItemId nId): BibToolBarListener(pTB,aStr,nId) { } @@ -152,7 +152,7 @@ void BibTBQueryMenuListener::statusChanged(const frame::FeatureStateEvent& rEvt) } }; -BibTBEditListener::BibTBEditListener(BibToolBar *pTB, const OUString& aStr, sal_uInt16 nId): +BibTBEditListener::BibTBEditListener(BibToolBar *pTB, const OUString& aStr, ToolBoxItemId nId): BibToolBarListener(pTB,aStr,nId) { } @@ -224,18 +224,18 @@ EditControl::~EditControl() BibToolBar::BibToolBar(vcl::Window* pParent, Link<void*,void> aLink) : ToolBox(pParent, "toolbar", "modules/sbibliography/ui/toolbar.ui") + , aIdle("BibToolBar") , xSource(VclPtr<ComboBoxControl>::Create(this)) , pLbSource(xSource->get_widget()) , xQuery(VclPtr<EditControl>::Create(this)) , pEdQuery(xQuery->get_widget()) - , pPopupMenu(VclPtr<PopupMenu>::Create()) + , xBuilder(Application::CreateBuilder(nullptr, "modules/sbibliography/ui/autofiltermenu.ui")) + , xPopupMenu(xBuilder->weld_menu("menu")) , nMenuId(0) - , nSelMenuItem(0) , aLayoutManager(aLink) , nSymbolsSize(SFX_SYMBOLS_SIZE_SMALL) { - SvtMiscOptions aSvtMiscOptions; - nSymbolsSize = aSvtMiscOptions.GetCurrentSymbolsSize(); + nSymbolsSize = SvtMiscOptions::GetCurrentSymbolsSize(); xSource->Show(); pLbSource->connect_changed(LINK( this, BibToolBar, SelHdl)); @@ -280,6 +280,8 @@ void BibToolBar::dispose() xQuery.disposeAndClear(); pLbSource = nullptr; xSource.disposeAndClear(); + xPopupMenu.reset(); + xBuilder.reset(); ToolBox::dispose(); } @@ -295,12 +297,12 @@ void BibToolBar::InitListener() util::URL aQueryURL; aQueryURL.Complete = ".uno:Bib/MenuFilter"; xTrans->parseStrict( aQueryURL); - BibToolBarListener* pQuery=new BibTBQueryMenuListener(this, aQueryURL.Complete, nTBC_BT_AUTOFILTER); - xDisp->addStatusListener(uno::Reference< frame::XStatusListener > (pQuery),aQueryURL); + rtl::Reference<BibToolBarListener> pQuery=new BibTBQueryMenuListener(this, aQueryURL.Complete, nTBC_BT_AUTOFILTER); + xDisp->addStatusListener(pQuery, aQueryURL); for(ToolBox::ImplToolItems::size_type nPos=0;nPos<nCount;nPos++) { - sal_uInt16 nId=GetItemId(nPos); + ToolBoxItemId nId=GetItemId(nPos); if (!nId) continue; @@ -339,7 +341,7 @@ void BibToolBar::SetXController(const uno::Reference< frame::XController > & xCt void BibToolBar::Select() { - sal_uInt16 nId=GetCurItemId(); + ToolBoxItemId nId=GetCurItemId(); if (nId != nTBC_BT_AUTOFILTER) { @@ -347,19 +349,16 @@ void BibToolBar::Select() } else { - Sequence<PropertyValue> aPropVal(2); - PropertyValue* pPropertyVal = const_cast<PropertyValue*>(aPropVal.getConstArray()); - pPropertyVal[0].Name="QueryText"; - OUString aSelection = pEdQuery->get_text(); - pPropertyVal[0].Value <<= aSelection; - - pPropertyVal[1].Name="QueryField"; - pPropertyVal[1].Value <<= aQueryField; + Sequence<PropertyValue> aPropVal + { + comphelper::makePropertyValue("QueryText", pEdQuery->get_text()), + comphelper::makePropertyValue("QueryField", aQueryField) + }; SendDispatch(nId,aPropVal); } } -void BibToolBar::SendDispatch(sal_uInt16 nId, const Sequence< PropertyValue >& rArgs) +void BibToolBar::SendDispatch(ToolBoxItemId nId, const Sequence< PropertyValue >& rArgs) { OUString aCommand = GetItemCommand(nId); @@ -387,7 +386,7 @@ void BibToolBar::SendDispatch(sal_uInt16 nId, const Sequence< PropertyValue >& r void BibToolBar::Click() { - sal_uInt16 nId = GetCurItemId(); + ToolBoxItemId nId = GetCurItemId(); vcl::Window* pWin = GetParent(); @@ -411,21 +410,23 @@ void BibToolBar::Click() void BibToolBar::ClearFilterMenu() { - pPopupMenu->Clear(); + xPopupMenu->clear(); nMenuId=0; } -sal_uInt16 BibToolBar::InsertFilterItem(const OUString& aMenuEntry) + +sal_uInt16 BibToolBar::InsertFilterItem(const OUString& rMenuEntry) { nMenuId++; - pPopupMenu->InsertItem(nMenuId,aMenuEntry); - + xPopupMenu->append_check(OUString::number(nMenuId), rMenuEntry); return nMenuId; } -void BibToolBar::SelectFilterItem(sal_uInt16 nId) + +void BibToolBar::SelectFilterItem(sal_uInt16 nId) { - pPopupMenu->CheckItem(nId); - nSelMenuItem=nId; - aQueryField = MnemonicGenerator::EraseAllMnemonicChars( pPopupMenu->GetItemText(nId) ); + OUString sId = OUString::number(nId); + xPopupMenu->set_active(sId, true); + sSelMenuItem = sId; + aQueryField = MnemonicGenerator::EraseAllMnemonicChars(xPopupMenu->get_label(sId)); } void BibToolBar::EnableSourceList(bool bFlag) @@ -470,20 +471,18 @@ bool BibToolBar::PreNotify( NotifyEvent& rNEvt ) { bool bResult = true; - MouseNotifyEvent nSwitch=rNEvt.GetType(); - if (pEdQuery && pEdQuery->has_focus() && nSwitch == MouseNotifyEvent::KEYINPUT) + NotifyEventType nSwitch=rNEvt.GetType(); + if (pEdQuery && pEdQuery->has_focus() && nSwitch == NotifyEventType::KEYINPUT) { const vcl::KeyCode& aKeyCode=rNEvt.GetKeyEvent()->GetKeyCode(); sal_uInt16 nKey = aKeyCode.GetCode(); if(nKey == KEY_RETURN) { - Sequence<PropertyValue> aPropVal(2); - PropertyValue* pPropertyVal = const_cast<PropertyValue*>(aPropVal.getConstArray()); - pPropertyVal[0].Name = "QueryText"; - OUString aSelection = pEdQuery->get_text(); - pPropertyVal[0].Value <<= aSelection; - pPropertyVal[1].Name="QueryField"; - pPropertyVal[1].Value <<= aQueryField; + Sequence<PropertyValue> aPropVal + { + comphelper::makePropertyValue("QueryText", pEdQuery->get_text()), + comphelper::makePropertyValue("QueryField", aQueryField) + }; SendDispatch(nTBC_BT_AUTOFILTER, aPropVal); return bResult; } @@ -502,39 +501,38 @@ IMPL_LINK_NOARG( BibToolBar, SelHdl, weld::ComboBox&, void ) IMPL_LINK_NOARG( BibToolBar, SendSelHdl, Timer*, void ) { - Sequence<PropertyValue> aPropVal(1); - PropertyValue* pPropertyVal = const_cast<PropertyValue*>(aPropVal.getConstArray()); - pPropertyVal[0].Name = "DataSourceName"; - OUString aEntry( MnemonicGenerator::EraseAllMnemonicChars( pLbSource->get_active_text() ) ); - pPropertyVal[0].Value <<= aEntry; + Sequence<PropertyValue> aPropVal + { + comphelper::makePropertyValue("DataSourceName", MnemonicGenerator::EraseAllMnemonicChars( pLbSource->get_active_text() )) + }; SendDispatch(nTBC_SOURCE, aPropVal); } -IMPL_LINK_NOARG( BibToolBar, MenuHdl, ToolBox*, void) +IMPL_LINK_NOARG(BibToolBar, MenuHdl, ToolBox*, void) { - sal_uInt16 nId=GetCurItemId(); + ToolBoxItemId nId = GetCurItemId(); if (nId != nTBC_BT_AUTOFILTER) return; EndSelection(); // before SetDropMode (SetDropMode calls SetItemImage) SetItemDown(nTBC_BT_AUTOFILTER, true); - nId = pPopupMenu->Execute(this, GetItemRect(nTBC_BT_AUTOFILTER)); + tools::Rectangle aRect(GetItemRect(nTBC_BT_AUTOFILTER)); + weld::Window* pParent = weld::GetPopupParent(*this, aRect); + OUString sId = xPopupMenu->popup_at_rect(pParent, aRect); - if(nId>0) + if (!sId.isEmpty()) { - pPopupMenu->CheckItem(nSelMenuItem,false); - pPopupMenu->CheckItem(nId); - nSelMenuItem=nId; - aQueryField = MnemonicGenerator::EraseAllMnemonicChars( pPopupMenu->GetItemText(nId) ); - Sequence<PropertyValue> aPropVal(2); - PropertyValue* pPropertyVal = const_cast<PropertyValue*>(aPropVal.getConstArray()); - pPropertyVal[0].Name = "QueryText"; - OUString aSelection = pEdQuery->get_text(); - pPropertyVal[0].Value <<= aSelection; - pPropertyVal[1].Name="QueryField"; - pPropertyVal[1].Value <<= aQueryField; + xPopupMenu->set_active(sSelMenuItem, false); + xPopupMenu->set_active(sId, true); + sSelMenuItem = sId; + aQueryField = MnemonicGenerator::EraseAllMnemonicChars(xPopupMenu->get_label(sId)); + Sequence<PropertyValue> aPropVal + { + comphelper::makePropertyValue("QueryText", pEdQuery->get_text()), + comphelper::makePropertyValue("QueryField", aQueryField) + }; SendDispatch(nTBC_BT_AUTOFILTER, aPropVal); } @@ -562,7 +560,7 @@ void BibToolBar::DataChanged( const DataChangedEvent& rDCEvt ) IMPL_LINK_NOARG( BibToolBar, OptionsChanged_Impl, LinkParamNone*, void ) { bool bRebuildToolBar = false; - sal_Int16 eSymbolsSize = SvtMiscOptions().GetCurrentSymbolsSize(); + sal_Int16 eSymbolsSize = SvtMiscOptions::GetCurrentSymbolsSize(); if ( nSymbolsSize != eSymbolsSize ) { nSymbolsSize = eSymbolsSize; @@ -576,7 +574,7 @@ IMPL_LINK_NOARG( BibToolBar, OptionsChanged_Impl, LinkParamNone*, void ) IMPL_LINK_NOARG( BibToolBar, SettingsChanged_Impl, VclSimpleEvent&, void ) { // Check if toolbar button size have changed and we have to use system settings - sal_Int16 eSymbolsSize = SvtMiscOptions().GetCurrentSymbolsSize(); + sal_Int16 eSymbolsSize = SvtMiscOptions::GetCurrentSymbolsSize(); if ( eSymbolsSize != nSymbolsSize ) { nSymbolsSize = eSymbolsSize; @@ -593,9 +591,9 @@ void BibToolBar::RebuildToolbar() void BibToolBar::ApplyImageList() { - SetItemImage(nTBC_BT_AUTOFILTER, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? OUString(RID_EXTBMP_AUTOFILTER_SC) : OUString(RID_EXTBMP_AUTOFILTER_LC))); - SetItemImage(nTBC_BT_FILTERCRIT, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? OUString(RID_EXTBMP_FILTERCRIT_SC) : OUString(RID_EXTBMP_FILTERCRIT_LC))); - SetItemImage(nTBC_BT_REMOVEFILTER, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? OUString(RID_EXTBMP_REMOVE_FILTER_SORT_SC) : OUString(RID_EXTBMP_REMOVE_FILTER_SORT_LC))); + SetItemImage(nTBC_BT_AUTOFILTER, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? RID_EXTBMP_AUTOFILTER_SC : RID_EXTBMP_AUTOFILTER_LC)); + SetItemImage(nTBC_BT_FILTERCRIT, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? RID_EXTBMP_FILTERCRIT_SC : RID_EXTBMP_FILTERCRIT_LC)); + SetItemImage(nTBC_BT_REMOVEFILTER, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? RID_EXTBMP_REMOVE_FILTER_SORT_SC : RID_EXTBMP_REMOVE_FILTER_SORT_LC)); AdjustToolBox(); } |