Kaydet (Commit) 9125a4f3 authored tarafından Maxim Monastirsky's avatar Maxim Monastirsky

Use FeatureStateEvent directly for status updates

... for SfxPopupWindow and SvxColorToolBoxControl (the
latter shares BorderColorStatus with SvxColorWindow_Impl,
so it was easier to convert it too).

Change-Id: Ifcb23fe5809e467322d1cf4d790420886ac79b47
üst f1bae1b5
......@@ -11,9 +11,7 @@
#include "ChartController.hxx"
#include <editeng/colritem.hxx>
#include <svx/tbcontrl.hxx>
#include <svx/svxids.hrc>
namespace chart { namespace sidebar {
......@@ -88,13 +86,14 @@ void ChartColorWrapper::updateData()
if (!xPropSet.is())
return;
css::uno::Any aAny = xPropSet->getPropertyValue(maPropertyName);
sal_uInt32 nColor = 0;
aAny >>= nColor;
Color aColor(nColor);
css::util::URL aUrl;
aUrl.Complete = ".uno:FillColor";
SvxColorItem aItem(aColor, SID_ATTR_FILL_COLOR);
mpControl->StateChanged(SID_ATTR_FILL_COLOR, SfxItemState::SET, &aItem);
css::frame::FeatureStateEvent aEvent;
aEvent.FeatureURL = aUrl;
aEvent.IsEnabled = true;
aEvent.State = xPropSet->getPropertyValue(maPropertyName);
mpControl->statusChanged(aEvent);
}
} }
......
......@@ -95,10 +95,7 @@ protected:
void UnbindListener();
void AddStatusListener( const OUString& rCommandURL );
// SfxStatusListenerInterface
using FloatingWindow::StateChanged;
virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState,
const SfxPoolItem* pState );
virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent );
public:
SfxPopupWindow( sal_uInt16 nId,
......
......@@ -77,8 +77,6 @@ public:
class SvxLineEndWindow : public SfxPopupWindow
{
using FloatingWindow::StateChanged;
private:
XLineEndListRef pLineEndList;
VclPtr<ValueSet> aLineEndSet;
......@@ -116,8 +114,7 @@ public:
void StartSelection();
virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState,
const SfxPoolItem* pState ) override;
virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
};
......
......@@ -222,15 +222,13 @@ class BorderColorStatus
public:
BorderColorStatus();
~BorderColorStatus();
void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState);
bool statusChanged( const css::frame::FeatureStateEvent& rEvent );
Color GetColor();
};
typedef std::function<void(const OUString&, const Color&)> ColorSelectFunction;
class SVX_DLLPUBLIC SvxColorToolBoxControl : public SfxToolBoxControl
{
using SfxToolBoxControl::StateChanged;
std::unique_ptr<svx::ToolboxButtonColorUpdater> m_xBtnUpdater;
PaletteManager m_aPaletteManager;
BorderColorStatus m_aBorderColorStatus;
......@@ -242,8 +240,9 @@ public:
SvxColorToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rToolBox);
virtual ~SvxColorToolBoxControl() override;
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState,
const SfxPoolItem* pState) override;
// XStatusListener
virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException, std::exception ) override;
virtual VclPtr<SfxPopupWindow> CreatePopupWindow() override;
virtual void Select(sal_uInt16 nSelectModifier) override;
......
......@@ -38,7 +38,6 @@
#include <editeng/fontitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <svx/tbcontrl.hxx>
#include <editeng/colritem.hxx>
#include <cppuhelper/supportsservice.hxx>
......@@ -195,12 +194,7 @@ void SAL_CALL OToolboxController::statusChanged( const FeatureStateEvent& Event
{
case SID_ATTR_CHAR_COLOR2:
case SID_BACKGROUND_COLOR:
{
util::Color nColor(COL_TRANSPARENT);
Event.State >>= nColor;
SvxColorItem aColorItem(::Color(nColor), 1);
static_cast<SvxColorToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SfxItemState::SET : SfxItemState::DISABLED,&aColorItem);
}
m_pToolbarController->statusChanged( Event );
break;
case SID_ATTR_CHAR_FONT:
{
......
......@@ -754,121 +754,7 @@ SfxFrameStatusListener::~SfxFrameStatusListener()
void SAL_CALL SfxFrameStatusListener::statusChanged( const css::frame::FeatureStateEvent& rEvent )
throw ( css::uno::RuntimeException, std::exception )
{
SfxViewFrame* pViewFrame = nullptr;
Reference < XController > xController;
SolarMutexGuard aGuard;
if ( m_xFrame.is() )
xController = m_xFrame->getController();
Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
if ( xProvider.is() )
{
Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, OUString(), 0 );
if ( xDisp.is() )
{
Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
SfxOfficeDispatch* pDisp = nullptr;
if ( xTunnel.is() )
{
sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
}
if ( pDisp )
pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
}
}
sal_uInt16 nSlotId = 0;
SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
if ( pSlot )
nSlotId = pSlot->GetSlotId();
if ( nSlotId > 0 )
{
if ( rEvent.Requery )
{
// requery for the notified state
addStatusListener( rEvent.FeatureURL.Complete );
}
else
{
SfxItemState eState = SfxItemState::DISABLED;
SfxPoolItem* pItem = nullptr;
if ( rEvent.IsEnabled )
{
eState = SfxItemState::DEFAULT;
css::uno::Type aType = rEvent.State.getValueType();
if ( aType == cppu::UnoType<void>::get() )
{
pItem = new SfxVoidItem( nSlotId );
eState = SfxItemState::UNKNOWN;
}
else if ( aType == cppu::UnoType<bool>::get() )
{
bool bTemp = false;
rEvent.State >>= bTemp ;
pItem = new SfxBoolItem( nSlotId, bTemp );
}
else if ( aType == ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get())
{
sal_uInt16 nTemp = 0;
rEvent.State >>= nTemp ;
pItem = new SfxUInt16Item( nSlotId, nTemp );
}
else if ( aType == cppu::UnoType<sal_uInt32>::get() )
{
sal_uInt32 nTemp = 0;
rEvent.State >>= nTemp ;
pItem = new SfxUInt32Item( nSlotId, nTemp );
}
else if ( aType == cppu::UnoType<OUString>::get() )
{
OUString sTemp ;
rEvent.State >>= sTemp ;
pItem = new SfxStringItem( nSlotId, sTemp );
}
else if ( aType == cppu::UnoType< css::frame::status::ItemStatus>::get() )
{
ItemStatus aItemStatus;
rEvent.State >>= aItemStatus;
SfxItemState tmpState = (SfxItemState) aItemStatus.State;
// make sure no-one tries to send us a combination of states
if (tmpState != SfxItemState::UNKNOWN && tmpState != SfxItemState::DISABLED &&
tmpState != SfxItemState::READONLY && tmpState != SfxItemState::DONTCARE &&
tmpState != SfxItemState::DEFAULT && tmpState != SfxItemState::SET)
throw css::uno::RuntimeException("unknown status");
eState = tmpState;
pItem = new SfxVoidItem( nSlotId );
}
else if ( aType == cppu::UnoType< css::frame::status::Visibility>::get() )
{
Visibility aVisibilityStatus;
rEvent.State >>= aVisibilityStatus;
pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
}
else
{
if ( pSlot )
pItem = pSlot->GetType()->CreateItem();
if ( pItem )
{
pItem->SetWhich( nSlotId );
pItem->PutValue( rEvent.State, 0 );
}
else
pItem = new SfxVoidItem( nSlotId );
}
}
if ( m_pCallee )
m_pCallee->StateChanged( nSlotId, eState, pItem );
delete pItem;
}
}
m_pCallee->statusChanged( rEvent );
}
SfxPopupWindow::SfxPopupWindow(
......@@ -1060,22 +946,9 @@ void SfxPopupWindow::StartCascading()
}
void SfxPopupWindow::StateChanged(
sal_uInt16 /*nSID*/,
SfxItemState eState,
const SfxPoolItem* /*pState*/ )
/* [Description]
See also <SfxControllerItem::StateChanged()>. In addition the Popup
will become hidden when eState==SfxItemState::DISABLED and in all other
cases it will be shown again if it is floating. In general this requires
to call the Base class.
Due to the parent the presentation mode is handled in a special way.
*/
void SfxPopupWindow::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
if ( SfxItemState::DISABLED == eState )
if ( !rEvent.IsEnabled )
{
Hide();
}
......
......@@ -35,8 +35,6 @@ class BorderColorStatus;
class SvxColorWindow_Impl : public SfxPopupWindow
{
using FloatingWindow::StateChanged;
private:
const sal_uInt16 theSlotId;
VclPtr<SvxColorValueSet> mpColorSet;
......@@ -76,7 +74,7 @@ public:
void StartSelection();
virtual void KeyInput( const KeyEvent& rKEvt ) override;
virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) override;
virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
void SetSelectedHdl( const Link<const Color&, void>& rLink ) { maSelectedLink = rLink; }
};
......
......@@ -50,8 +50,6 @@ class SvxPopupWindowListBox;
class SvxPopupWindowListBox: public SfxPopupWindow
{
using FloatingWindow::StateChanged;
VclPtr<ListBox> m_pListBox;
ToolBox & rToolBox;
bool bUserSel;
......@@ -64,8 +62,7 @@ public:
// SfxPopupWindow
virtual void PopupModeEnd() override;
virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState,
const SfxPoolItem* pState ) override;
virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
inline ListBox & GetListBox() { return *m_pListBox; }
......@@ -118,11 +115,10 @@ void SvxPopupWindowListBox::PopupModeEnd()
}
void SvxPopupWindowListBox::StateChanged(
sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
void SvxPopupWindowListBox::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
rToolBox.EnableItem( nTbxId, ( SfxToolBoxControl::GetItemState( pState ) != SfxItemState::DISABLED) );
SfxPopupWindow::StateChanged( nSID, eState, pState );
rToolBox.EnableItem( nTbxId, rEvent.IsEnabled );
SfxPopupWindow::statusChanged( rEvent );
}
SvxListBoxControl::SvxListBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
......
......@@ -483,15 +483,15 @@ void SvxLineEndWindow::StartSelection()
}
void SvxLineEndWindow::StateChanged(
sal_uInt16 nSID, SfxItemState, const SfxPoolItem* pState )
void SvxLineEndWindow::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
if ( nSID == SID_LINEEND_LIST )
if ( rEvent.FeatureURL.Complete == ".uno:LineEndListState" )
{
// The list of line ends (LineEndList) has changed
if ( pState && dynamic_cast<const SvxLineEndListItem*>( pState) != nullptr)
css::uno::Reference< css::uno::XWeak > xWeak;
if ( rEvent.State >>= xWeak )
{
pLineEndList = static_cast<const SvxLineEndListItem*>(pState)->GetLineEndList();
pLineEndList.set( static_cast< XLineEndList* >( xWeak.get() ) );
DBG_ASSERT( pLineEndList.is(), "LineEndList not found" );
aLineEndSet->Clear();
......
......@@ -54,6 +54,7 @@
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <svtools/colorcfg.hxx>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
......@@ -1466,38 +1467,28 @@ void SvxColorWindow_Impl::StartSelection()
mpColorSet->StartSelection();
}
void SvxColorWindow_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
void SvxColorWindow_Impl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
if ( nSID == SID_COLOR_TABLE )
if ( rEvent.IsEnabled && rEvent.FeatureURL.Complete == ".uno:ColorTableState"
&& mrPaletteManager.GetPalette() == 0)
{
if ( SfxItemState::DEFAULT == eState && mrPaletteManager.GetPalette() == 0 )
{
mrPaletteManager.ReloadColorSet(*mpColorSet);
mpColorSet->layoutToGivenHeight(mpColorSet->GetSizePixel().Height(), mrPaletteManager.GetColorCount());
}
mrPaletteManager.ReloadColorSet(*mpColorSet);
mpColorSet->layoutToGivenHeight(mpColorSet->GetSizePixel().Height(), mrPaletteManager.GetColorCount());
}
else
{
mpColorSet->SetNoSelection();
Color aColor( COL_TRANSPARENT );
if ( nSID == SID_FRAME_LINECOLOR
|| nSID == SID_ATTR_BORDER_DIAG_TLBR
|| nSID == SID_ATTR_BORDER_DIAG_BLTR )
if ( mrBorderColorStatus.statusChanged( rEvent ) )
{
mrBorderColorStatus.StateChanged( nSID, eState, pState );
aColor = mrBorderColorStatus.GetColor();
}
else if ( SfxItemState::DEFAULT <= eState && pState )
else if ( rEvent.IsEnabled )
{
if ( dynamic_cast<const SvxColorItem*>( pState) != nullptr )
aColor = static_cast<const SvxColorItem*>(pState)->GetValue();
else if ( dynamic_cast<const XLineColorItem*>( pState) != nullptr )
aColor = static_cast<const XLineColorItem*>(pState)->GetColorValue();
else if ( dynamic_cast<const XFillColorItem*>( pState) != nullptr )
aColor = static_cast<const XFillColorItem*>(pState)->GetColorValue();
else if ( dynamic_cast<const SvxBackgroundColorItem*>( pState) != nullptr )
aColor = static_cast<const SvxBackgroundColorItem*>(pState)->GetValue();
sal_Int32 nValue;
if ( rEvent.State >>= nValue )
aColor = nValue;
}
if ( aColor == COL_TRANSPARENT )
......@@ -1526,33 +1517,38 @@ BorderColorStatus::~BorderColorStatus()
{
}
void BorderColorStatus::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState )
bool BorderColorStatus::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
if ( SfxItemState::DEFAULT <= eState && pState )
Color aColor( COL_TRANSPARENT );
if ( rEvent.FeatureURL.Complete == ".uno:FrameLineColor" )
{
sal_Int32 nValue;
if ( rEvent.IsEnabled && ( rEvent.State >>= nValue ) )
aColor = nValue;
maColor = aColor;
return true;
}
else
{
if ( nSID == SID_FRAME_LINECOLOR && dynamic_cast<const SvxColorItem*>( pState) != nullptr )
css::table::BorderLine2 aTable;
if ( rEvent.IsEnabled && ( rEvent.State >>= aTable ) )
aColor = aTable.Color;
if ( rEvent.FeatureURL.Complete == ".uno:BorderTLBR" )
{
maColor = static_cast< const SvxColorItem* >(pState)->GetValue();
maTLBRColor = aColor;
return true;
}
else if ( dynamic_cast<const SvxLineItem*>( pState) != nullptr )
else if ( rEvent.FeatureURL.Complete == ".uno:BorderBLTR" )
{
const SvxBorderLine* pLine = static_cast< const SvxLineItem* >(pState)->GetLine();
Color aColor ( COL_TRANSPARENT );
if ( pLine )
aColor = pLine->GetColor();
if ( nSID == SID_ATTR_BORDER_DIAG_TLBR )
maTLBRColor = aColor;
else if ( nSID == SID_ATTR_BORDER_DIAG_BLTR )
maBLTRColor = aColor;
maBLTRColor = aColor;
return true;
}
}
else if ( nSID == SID_FRAME_LINECOLOR )
maColor = COL_TRANSPARENT;
else if ( nSID == SID_ATTR_BORDER_DIAG_TLBR )
maTLBRColor = COL_TRANSPARENT;
else if ( nSID == SID_ATTR_BORDER_DIAG_BLTR )
maBLTRColor = COL_TRANSPARENT;
return false;
}
Color BorderColorStatus::GetColor()
......@@ -2709,34 +2705,32 @@ IMPL_LINK(SvxColorToolBoxControl, SelectedHdl, const Color&, rColor, void)
m_aPaletteManager.SetLastColor( rColor );
}
void SvxColorToolBoxControl::StateChanged(
sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
void SvxColorToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
throw ( css::uno::RuntimeException, std::exception )
{
if ( nSID == SID_ATTR_CHAR_COLOR_EXT || nSID == SID_ATTR_CHAR_COLOR_BACKGROUND_EXT )
SfxToolBoxControl::StateChanged( nSID, eState, pState );
else if ( !m_bSplitButton )
if ( rEvent.FeatureURL.Complete == m_aCommandURL )
GetToolBox().EnableItem( GetId(), rEvent.IsEnabled );
bool bValue;
if ( !m_bSplitButton )
{
Color aColor( COL_TRANSPARENT );
if ( nSID == SID_FRAME_LINECOLOR
|| nSID == SID_ATTR_BORDER_DIAG_TLBR
|| nSID == SID_ATTR_BORDER_DIAG_BLTR )
if ( m_aBorderColorStatus.statusChanged( rEvent ) )
{
m_aBorderColorStatus.StateChanged( nSID, eState, pState );
aColor = m_aBorderColorStatus.GetColor();
}
else if ( SfxItemState::DEFAULT <= eState && pState )
else if ( rEvent.IsEnabled )
{
if ( dynamic_cast<const SvxColorItem*>( pState) != nullptr )
aColor = static_cast< const SvxColorItem* >(pState)->GetValue();
else if ( dynamic_cast<const XLineColorItem*>( pState) != nullptr )
aColor = static_cast< const XLineColorItem* >(pState)->GetColorValue();
else if ( dynamic_cast<const XFillColorItem*>( pState) != nullptr )
aColor = static_cast< const XFillColorItem* >(pState)->GetColorValue();
sal_Int32 nValue;
if ( rEvent.State >>= nValue )
aColor = nValue;
}
m_xBtnUpdater->Update( aColor );
m_aPaletteManager.SetLastColor(aColor);
}
else if ( rEvent.State >>= bValue )
GetToolBox().CheckItem( GetId(), bValue );
}
void SvxColorToolBoxControl::Select(sal_uInt16 /*nSelectModifier*/)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment