diff --git a/include/svx/lboxctrl.hxx b/include/svx/lboxctrl.hxx index 928b81080feb..5aeaf54ee4b3 100644 --- a/include/svx/lboxctrl.hxx +++ b/include/svx/lboxctrl.hxx @@ -20,38 +20,36 @@ #ifndef INCLUDED_SVX_LBOXCTRL_HXX #define INCLUDED_SVX_LBOXCTRL_HXX -#include #include #include +#include #include class ToolBox; class SvxPopupWindowListBox; - -class SVX_DLLPUBLIC SvxUndoRedoControl final : public SfxToolBoxControl +class SVX_DLLPUBLIC SvxUndoRedoControl final : public svt::PopupWindowController { - OUString aActionStr; - VclPtr pPopupWin; std::vector< OUString > aUndoRedoList; OUString aDefaultTooltip; - void Impl_SetInfo( sal_Int32 nCount ); - - DECL_LINK( PopupModeEndHdl, FloatingWindow*, void ); - DECL_LINK( SelectHdl, ListBox&, void ); - public: - SFX_DECL_TOOLBOX_CONTROL(); - - SvxUndoRedoControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ); + SvxUndoRedoControl(const css::uno::Reference& rContext); virtual ~SvxUndoRedoControl() override; - virtual void StateChanged( sal_uInt16 nSID, - SfxItemState eState, - const SfxPoolItem* pState ) override; + using svt::ToolboxController::createPopupWindow; + virtual VclPtr createPopupWindow( vcl::Window* pParent ) override; - virtual VclPtr CreatePopupWindow() override; + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual css::uno::Sequence SAL_CALL getSupportedServiceNames() override; + + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) override; + + virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) override; + + void Do(sal_Int16 nCount); }; #endif diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu index ec3474f0594c..bad60fb6b38f 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu @@ -1536,6 +1536,28 @@ com.sun.star.comp.svx.UnderlineToolBoxControl + + + .uno:Undo + + + + + + com.sun.star.comp.svx.UndoRedoToolBoxControl + + + + + .uno:Redo + + + + + + com.sun.star.comp.svx.UndoRedoToolBoxControl + + .uno:XLineColor diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx index d3a1bbdc1035..dfcb7d5edc11 100644 --- a/sc/source/ui/app/scdll.cxx +++ b/sc/source/ui/app/scdll.cxx @@ -151,8 +151,6 @@ void ScDLL::Init() SvxStyleToolBoxControl ::RegisterControl(SID_STYLE_APPLY, pMod); SvxClipBoardControl ::RegisterControl(SID_PASTE, pMod ); SvxClipBoardControl ::RegisterControl(SID_PASTE_UNFORMATTED, pMod ); - SvxUndoRedoControl ::RegisterControl(SID_UNDO, pMod ); - SvxUndoRedoControl ::RegisterControl(SID_REDO, pMod ); svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH, pMod ); sc::ScNumberFormatControl ::RegisterControl(SID_NUMBER_TYPE_FORMAT, pMod ); diff --git a/sd/source/ui/app/sddll.cxx b/sd/source/ui/app/sddll.cxx index e990d56053c9..a4805671b59e 100644 --- a/sd/source/ui/app/sddll.cxx +++ b/sd/source/ui/app/sddll.cxx @@ -206,10 +206,6 @@ void SdDLL::RegisterControllers(SdModule* pMod) SvxModifyControl::RegisterControl( SID_DOC_MODIFIED, pMod ); SvxZoomSliderControl::RegisterControl( SID_ATTR_ZOOMSLIDER, pMod ); - // #UndoRedo# - SvxUndoRedoControl::RegisterControl( SID_UNDO , pMod ); - SvxUndoRedoControl::RegisterControl( SID_REDO , pMod ); - svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH, pMod ); SvxClipBoardControl::RegisterControl( SID_PASTE, pMod ); diff --git a/starmath/source/smdll.cxx b/starmath/source/smdll.cxx index a53d53ed0ffd..78dc2183bca6 100644 --- a/starmath/source/smdll.cxx +++ b/starmath/source/smdll.cxx @@ -68,8 +68,6 @@ namespace SvxZoomStatusBarControl::RegisterControl(SID_ATTR_ZOOM, pModule); SvxZoomSliderControl::RegisterControl(SID_ATTR_ZOOMSLIDER, pModule); SvxModifyControl::RegisterControl(SID_TEXTSTATUS, pModule); - SvxUndoRedoControl::RegisterControl(SID_UNDO, pModule); - SvxUndoRedoControl::RegisterControl(SID_REDO, pModule); XmlSecStatusBarControl::RegisterControl(SID_SIGNATURE, pModule); SmCmdBoxWrapper::RegisterChildWindow(true); diff --git a/svx/source/tbxctrls/lboxctrl.cxx b/svx/source/tbxctrls/lboxctrl.cxx index 3d709f52cb7a..28c3dc6f4fa3 100644 --- a/svx/source/tbxctrls/lboxctrl.cxx +++ b/svx/source/tbxctrls/lboxctrl.cxx @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -42,41 +42,38 @@ #include #include +#include +#include +#include +#include + + using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::util; using namespace ::com::sun::star::frame; -class SvxPopupWindowListBox; - -class SvxPopupWindowListBox: public SfxPopupWindow +class SvxPopupWindowListBox final : public svtools::ToolbarPopup { VclPtr m_pListBox; - ToolBox & rToolBox; - bool bUserSel; - sal_uInt16 const nTbxId; + rtl::Reference m_xControl; + + DECL_LINK( SelectHdl, ListBox&, void ); public: - SvxPopupWindowListBox( sal_uInt16 nSlotId, const OUString& rCommandURL, sal_uInt16 nTbxId, ToolBox& rTbx ); + SvxPopupWindowListBox(SvxUndoRedoControl* pControl, vcl::Window* pParent); virtual ~SvxPopupWindowListBox() override; virtual void dispose() override; - // SfxPopupWindow - virtual void PopupModeEnd() override; - virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; - ListBox & GetListBox() { return *m_pListBox; } - bool IsUserSelected() const { return bUserSel; } - void SetUserSelected( bool bVal ) { bUserSel = bVal; } + void SetInfo(sal_Int32 nCount); }; -SvxPopupWindowListBox::SvxPopupWindowListBox(sal_uInt16 nSlotId, const OUString& rCommandURL, sal_uInt16 nId, ToolBox& rTbx) - : SfxPopupWindow(nSlotId, &rTbx, "FloatingUndoRedo", "svx/ui/floatingundoredo.ui") - , rToolBox(rTbx) - , bUserSel(false) - , nTbxId(nId) +SvxPopupWindowListBox::SvxPopupWindowListBox(SvxUndoRedoControl* pControl, vcl::Window* pParent) + : ToolbarPopup(pControl->getFrameInterface(), pParent, "FloatingUndoRedo", "svx/ui/floatingundoredo.ui") + , m_xControl(pControl) { - DBG_ASSERT( nSlotId == GetId(), "id mismatch" ); get(m_pListBox, "treeview"); WinBits nBits(m_pListBox->GetStyle()); nBits &= ~WB_SIMPLEMODE; @@ -86,7 +83,8 @@ SvxPopupWindowListBox::SvxPopupWindowListBox(sal_uInt16 nSlotId, const OUString& m_pListBox->set_height_request(aSize.Height()); m_pListBox->EnableMultiSelection( true, true ); SetBackground( GetSettings().GetStyleSettings().GetDialogColor() ); - AddStatusListener( rCommandURL ); + + m_pListBox->SetSelectHdl( LINK( this, SvxPopupWindowListBox, SelectHdl ) ); } SvxPopupWindowListBox::~SvxPopupWindowListBox() @@ -97,156 +95,142 @@ SvxPopupWindowListBox::~SvxPopupWindowListBox() void SvxPopupWindowListBox::dispose() { m_pListBox.clear(); - SfxPopupWindow::dispose(); + ToolbarPopup::dispose(); } -void SvxPopupWindowListBox::PopupModeEnd() +void SvxPopupWindowListBox::SetInfo( sal_Int32 nCount ) { - rToolBox.EndSelection(); - SfxPopupWindow::PopupModeEnd(); - //FloatingWindow::PopupModeEnd(); - - if( SfxViewShell::Current() ) - { - vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow(); - if (pShellWnd) - pShellWnd->GrabFocus(); - } -} - - -void SvxPopupWindowListBox::statusChanged( const css::frame::FeatureStateEvent& rEvent ) -{ - rToolBox.EnableItem( nTbxId, rEvent.IsEnabled ); - SfxPopupWindow::statusChanged( rEvent ); -} - -IMPL_LINK_NOARG(SvxUndoRedoControl, PopupModeEndHdl, FloatingWindow*, void) -{ - if( pPopupWin && FloatWinPopupFlags::NONE == pPopupWin->GetPopupModeFlags() && - pPopupWin->IsUserSelected() ) - { - const sal_Int32 nCount = pPopupWin->GetListBox().GetSelectedEntryCount(); - - INetURLObject aObj( m_aCommandURL ); - - Sequence< PropertyValue > aArgs( 1 ); - aArgs[0].Name = aObj.GetURLPath(); - aArgs[0].Value <<= sal_Int16( nCount ); - SfxToolBoxControl::Dispatch( m_aCommandURL, aArgs ); - } -} - - -void SvxUndoRedoControl::Impl_SetInfo( sal_Int32 nCount ) -{ - DBG_ASSERT( pPopupWin, "NULL pointer, PopupWindow missing" ); - const char* pId; if (nCount == 1) - pId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTION : RID_SVXSTR_NUM_REDO_ACTION; + pId = m_xControl->getCommandURL() == ".uno:Undo" ? RID_SVXSTR_NUM_UNDO_ACTION : RID_SVXSTR_NUM_REDO_ACTION; else - pId = SID_UNDO == GetSlotId() ? RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS; - aActionStr = SvxResId(pId); - + pId = m_xControl->getCommandURL() == ".uno:Undo" ? RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS; + OUString aActionStr = SvxResId(pId); OUString aText = aActionStr.replaceAll("$(ARG1)", OUString::number(nCount)); - pPopupWin->SetText(aText); + SetText(aText); } - -IMPL_LINK_NOARG(SvxUndoRedoControl, SelectHdl, ListBox&, void) +IMPL_LINK(SvxPopupWindowListBox, SelectHdl, ListBox&, rListBox, void) { - if (pPopupWin) + if (rListBox.IsTravelSelect()) + SetInfo(rListBox.GetSelectedEntryCount()); + else { - //pPopupWin->SetUserSelected( false ); + fprintf(stderr, "popdown\n"); + m_xControl->Do(GetListBox().GetSelectedEntryCount()); + EndPopupMode(); + } +} - ListBox &rListBox = pPopupWin->GetListBox(); - if (rListBox.IsTravelSelect()) - Impl_SetInfo( rListBox.GetSelectedEntryCount() ); - else +void SvxUndoRedoControl::Do(sal_Int16 nCount) +{ + Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); + if ( xDispatchProvider.is() ) + { + css::util::URL aTargetURL; + Reference < XURLTransformer > xTrans( URLTransformer::create(::comphelper::getProcessComponentContext()) ); + aTargetURL.Complete = m_aCommandURL; + xTrans->parseStrict( aTargetURL ); + + Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 ); + if ( xDispatch.is() ) { - pPopupWin->SetUserSelected( true ); - pPopupWin->EndPopupMode(); + INetURLObject aObj( m_aCommandURL ); + Sequence< PropertyValue > aArgs( 1 ); + aArgs[0].Name = aObj.GetURLPath(); + aArgs[0].Value <<= nCount; + xDispatch->dispatch(aTargetURL, aArgs); } } } - -SFX_IMPL_TOOLBOX_CONTROL( SvxUndoRedoControl, SfxStringItem ); - -SvxUndoRedoControl::SvxUndoRedoControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) - :SfxToolBoxControl( nSlotId, nId, rTbx ), - pPopupWin ( nullptr ) +SvxUndoRedoControl::SvxUndoRedoControl(const css::uno::Reference& rContext) + : PopupWindowController(rContext, nullptr, OUString()) { - rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) ); - rTbx.Invalidate(); - aDefaultTooltip = rTbx.GetQuickHelpText( nId ); +} + +void SvxUndoRedoControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) +{ + PopupWindowController::initialize(rArguments); + + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL) + { + pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWN | pToolBox->GetItemBits(nId)); + aDefaultTooltip = pToolBox->GetQuickHelpText(nId); + } } SvxUndoRedoControl::~SvxUndoRedoControl() { } -void SvxUndoRedoControl::StateChanged( - sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) +// XStatusListener +void SAL_CALL SvxUndoRedoControl::statusChanged(const css::frame::FeatureStateEvent& rEvent) { - if ( nSID == SID_UNDO || nSID == SID_REDO ) + if (rEvent.FeatureURL.Main == ".uno:GetUndoStrings" || rEvent.FeatureURL.Main == ".uno:GetRedoStrings") { - if ( eState == SfxItemState::DISABLED ) - { - ToolBox& rBox = GetToolBox(); - rBox.SetQuickHelpText( GetId(), aDefaultTooltip ); - } - else if ( auto pStringItem = dynamic_cast( pState) ) - { - ToolBox& rBox = GetToolBox(); - const OUString& aQuickHelpText = pStringItem->GetValue(); - rBox.SetQuickHelpText( GetId(), aQuickHelpText ); - } - GetToolBox().EnableItem( GetId(), - SfxItemState::DISABLED != GetItemState(pState) ); + css::uno::Sequence aStrings; + rEvent.State >>= aStrings; + aUndoRedoList = comphelper::sequenceToContainer>(aStrings); + return; } - else - { - aUndoRedoList.clear(); - if ( auto pStringListItem = dynamic_cast( pState) ) - { - aUndoRedoList = pStringListItem->GetList(); - } + PopupWindowController::statusChanged(rEvent); + + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if (!getToolboxId(nId, &pToolBox)) + return; + + if (!rEvent.IsEnabled) + { + pToolBox->SetQuickHelpText(nId, aDefaultTooltip); + return; } + + OUString aQuickHelpText; + if (rEvent.State >>= aQuickHelpText) + pToolBox->SetQuickHelpText(nId, aQuickHelpText); } -VclPtr SvxUndoRedoControl::CreatePopupWindow() +VclPtr SvxUndoRedoControl::createPopupWindow(vcl::Window* pParent) { - DBG_ASSERT(( SID_UNDO == GetSlotId() || SID_REDO == GetSlotId() ), "mismatching ids" ); - if ( m_aCommandURL == ".uno:Undo" ) updateStatus( ".uno:GetUndoStrings"); else updateStatus( ".uno:GetRedoStrings"); - ToolBox& rBox = GetToolBox(); + auto xPopupWin = VclPtr::Create(this, pParent); - pPopupWin = VclPtr::Create( GetSlotId(), m_aCommandURL, GetId(), rBox ); - pPopupWin->SetPopupModeEndHdl( LINK( this, SvxUndoRedoControl, PopupModeEndHdl ) ); - ListBox &rListBox = pPopupWin->GetListBox(); - rListBox.SetSelectHdl( LINK( this, SvxUndoRedoControl, SelectHdl ) ); + ListBox &rListBox = xPopupWin->GetListBox(); for(const OUString & s : aUndoRedoList) rListBox.InsertEntry( s ); - rListBox.SelectEntryPos( 0 ); - aActionStr = SvxResId(SID_UNDO == GetSlotId() ? - RID_SVXSTR_NUM_UNDO_ACTIONS : RID_SVXSTR_NUM_REDO_ACTIONS); - Impl_SetInfo( rListBox.GetSelectedEntryCount() ); + rListBox.SelectEntryPos(0); + xPopupWin->SetInfo(rListBox.GetSelectedEntryCount()); - // move focus in floating window without - // closing it (GrabFocus() would close it!) - pPopupWin->StartPopupMode( &rBox, FloatWinPopupFlags::GrabFocus ); - //pPopupWin->GetListBox().GrabFocus(); + return xPopupWin; +} - return pPopupWin; +OUString SvxUndoRedoControl::getImplementationName() +{ + return "com.sun.star.comp.svx.UndoRedoToolBoxControl"; +} + +css::uno::Sequence SvxUndoRedoControl::getSupportedServiceNames() +{ + return { "com.sun.star.frame.ToolbarController" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * +com_sun_star_comp_svx_UndoRedoToolBoxControl_get_implementation( + css::uno::XComponentContext* rContext, + css::uno::Sequence const & ) +{ + return cppu::acquire(new SvxUndoRedoControl(rContext)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/util/svx.component b/svx/util/svx.component index 90e3419e5f1b..e54318dea597 100644 --- a/svx/util/svx.component +++ b/svx/util/svx.component @@ -124,4 +124,8 @@ constructor="com_sun_star_comp_svx_UnderlineToolBoxControl_get_implementation"> + + + diff --git a/sw/source/uibase/app/swmodule.cxx b/sw/source/uibase/app/swmodule.cxx index c9ba933ee7a6..95e3c9eecd39 100644 --- a/sw/source/uibase/app/swmodule.cxx +++ b/sw/source/uibase/app/swmodule.cxx @@ -281,8 +281,6 @@ void SwDLL::RegisterControls() svx::ParaFirstLineSpacingControl::RegisterControl(SID_ATTR_PARA_FIRSTLINESPACE, pMod); SvxClipBoardControl::RegisterControl(SID_PASTE, pMod ); - SvxUndoRedoControl::RegisterControl(SID_UNDO, pMod ); - SvxUndoRedoControl::RegisterControl(SID_REDO, pMod ); svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH, pMod ); SvxFillToolBoxControl::RegisterControl(SID_ATTR_FILL_STYLE, pMod );