extensions leaks out details of Color Selector, patch it up
and rebase it on SvxColorListBox
Change-Id: I3afef689ab0dc3c34e465810d82bf21797907558
diff --git a/extensions/source/propctrlr/commoncontrol.cxx b/extensions/source/propctrlr/commoncontrol.cxx
index 7458804..6e9cb6b 100644
--- a/extensions/source/propctrlr/commoncontrol.cxx
+++ b/extensions/source/propctrlr/commoncontrol.cxx
@@ -104,6 +104,11 @@ namespace pcr
setModified();
}
IMPL_LINK_NOARG( CommonBehaviourControlHelper, ColorModifiedHdl, SvxColorListBox&, void )
{
setModified();
}
IMPL_LINK_NOARG( CommonBehaviourControlHelper, GetFocusHdl, Control&, void )
{
try
diff --git a/extensions/source/propctrlr/commoncontrol.hxx b/extensions/source/propctrlr/commoncontrol.hxx
index 05771dd..0d46aaa 100644
--- a/extensions/source/propctrlr/commoncontrol.hxx
+++ b/extensions/source/propctrlr/commoncontrol.hxx
@@ -32,6 +32,7 @@
class NotifyEvent;
class Control;
class ListBox;
class SvxColorListBox;
class Edit;
namespace pcr
@@ -90,6 +91,7 @@ namespace pcr
/// may be used by derived classes, they forward the event to the PropCtrListener
DECL_LINK( ModifiedHdl, ListBox&, void );
DECL_LINK( ColorModifiedHdl, SvxColorListBox&, void );
DECL_LINK( EditModifiedHdl, Edit&, void );
DECL_LINK( GetFocusHdl, Control&, void );
DECL_LINK( LoseFocusHdl, Control&, void );
@@ -150,8 +152,9 @@ namespace pcr
inline void impl_checkDisposed_throw();
private:
VclPtr<TControlWindow> m_pControlWindow;
void implSetModifyHandler(std::true_type);
void implSetModifyHandler(std::false_type);
void implSetModifyHandler(const Edit&);
void implSetModifyHandler(const ListBox&);
void implSetModifyHandler(const SvxColorListBox&);
};
@@ -165,7 +168,7 @@ namespace pcr
{
if ( _bDoSetHandlers )
{
implSetModifyHandler(std::is_base_of<::Edit,TControlWindow>());
implSetModifyHandler(*m_pControlWindow);
m_pControlWindow->SetGetFocusHdl( LINK( this, CommonBehaviourControlHelper, GetFocusHdl ) );
m_pControlWindow->SetLoseFocusHdl( LINK( this, CommonBehaviourControlHelper, LoseFocusHdl ) );
}
@@ -173,18 +176,24 @@ namespace pcr
}
template< class TControlInterface, class TControlWindow >
inline void CommonBehaviourControl< TControlInterface, TControlWindow >::implSetModifyHandler(std::true_type)
inline void CommonBehaviourControl< TControlInterface, TControlWindow >::implSetModifyHandler(const Edit&)
{
m_pControlWindow->SetModifyHdl( LINK( this, CommonBehaviourControlHelper, EditModifiedHdl ) );
}
template< class TControlInterface, class TControlWindow >
inline void CommonBehaviourControl< TControlInterface, TControlWindow >::implSetModifyHandler(std::false_type)
inline void CommonBehaviourControl< TControlInterface, TControlWindow >::implSetModifyHandler(const ListBox&)
{
m_pControlWindow->SetModifyHdl( LINK( this, CommonBehaviourControlHelper, ModifiedHdl ) );
}
template< class TControlInterface, class TControlWindow >
inline void CommonBehaviourControl< TControlInterface, TControlWindow >::implSetModifyHandler(const SvxColorListBox&)
{
m_pControlWindow->SetModifyHdl( LINK( this, CommonBehaviourControlHelper, ColorModifiedHdl ) );
}
template< class TControlInterface, class TControlWindow >
inline void CommonBehaviourControl< TControlInterface, TControlWindow >::impl_checkDisposed_throw()
{
if ( ComponentBaseClass::rBHelper.bDisposed )
diff --git a/extensions/source/propctrlr/standardcontrol.cxx b/extensions/source/propctrlr/standardcontrol.cxx
index ca2412f..7d42296 100644
--- a/extensions/source/propctrlr/standardcontrol.cxx
+++ b/extensions/source/propctrlr/standardcontrol.cxx
@@ -657,141 +657,50 @@ namespace pcr
return aStr.makeStringAndClear();
}
OColorControl::OColorControl(vcl::Window* pParent, WinBits nWinStyle)
:OColorControl_Base( PropertyControlType::ColorListBox, pParent, nWinStyle )
: OColorControl_Base(PropertyControlType::ColorListBox, pParent, nWinStyle)
{
// initialize the color listbox
XColorListRef pColorList;
SfxObjectShell* pDocSh = SfxObjectShell::Current();
const SfxPoolItem* pItem = pDocSh ? pDocSh->GetItem( SID_COLOR_TABLE ) : nullptr;
if ( pItem )
{
DBG_ASSERT(dynamic_cast< const SvxColorListItem* >(pItem) != nullptr, "OColorControl::OColorControl: invalid color item!");
pColorList = static_cast<const SvxColorListItem*>( pItem )->GetColorList();
}
if ( !pColorList.is() )
pColorList = XColorList::GetStdColorList();
DBG_ASSERT(pColorList.is(), "OColorControl::OColorControl: no color table!");
if ( pColorList.is() )
{
for (long i = 0; i < pColorList->Count(); ++i)
{
const XColorEntry* pEntry = pColorList->GetColor(i);
getTypedControlWindow()->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
}
}
getTypedControlWindow()->SetDropDownLineCount( LB_DEFAULT_COUNT );
if ( ( nWinStyle & WB_READONLY ) != 0 )
{
getTypedControlWindow()->SetReadOnly();
getTypedControlWindow()->Enable();
}
}
void SAL_CALL OColorControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException, std::exception)
{
if ( _rValue.hasValue() )
{
css::util::Color nColor = COL_TRANSPARENT;
if ( _rValue >>= nColor )
{
::Color aRgbCol((ColorData)nColor);
getTypedControlWindow()->SelectEntry( aRgbCol );
if ( !getTypedControlWindow()->IsEntrySelected( aRgbCol ) )
{ // the given color is not part of the list -> insert a new entry with the hex code of the color
OUString aStr("0x");
aStr += MakeHexStr(nColor,8);
getTypedControlWindow()->InsertEntry( aRgbCol, aStr );
getTypedControlWindow()->SelectEntry( aRgbCol );
}
}
else
{
OUString sNonColorValue;
if ( !( _rValue >>= sNonColorValue ) )
throw IllegalTypeException();
getTypedControlWindow()->SelectEntry( sNonColorValue );
if ( !getTypedControlWindow()->IsEntrySelected( sNonColorValue ) )
getTypedControlWindow()->SetNoSelection();
}
_rValue >>= nColor;
::Color aRgbCol((ColorData)nColor);
getTypedControlWindow()->SelectEntry(std::make_pair(aRgbCol, MakeHexStr(nColor, 8)));
}
else
getTypedControlWindow()->SetNoSelection();
}
Any SAL_CALL OColorControl::getValue() throw (RuntimeException, std::exception)
{
Any aPropValue;
if ( getTypedControlWindow()->GetSelectEntryCount() > 0 )
if (!getTypedControlWindow()->IsNoSelection())
{
OUString sSelectedEntry = getTypedControlWindow()->GetSelectEntry();
if ( m_aNonColorEntries.find( sSelectedEntry ) != m_aNonColorEntries.end() )
aPropValue <<= sSelectedEntry;
else
{
::Color aRgbCol = getTypedControlWindow()->GetSelectEntryColor();
aPropValue <<= (css::util::Color)aRgbCol.GetColor();
}
::Color aRgbCol = getTypedControlWindow()->GetSelectEntryColor();
aPropValue <<= (css::util::Color)aRgbCol.GetColor();
}
return aPropValue;
}
Type SAL_CALL OColorControl::getValueType() throw (RuntimeException, std::exception)
{
return ::cppu::UnoType<sal_Int32>::get();
}
void SAL_CALL OColorControl::clearList() throw (RuntimeException, std::exception)
{
getTypedControlWindow()->Clear();
}
void SAL_CALL OColorControl::prependListEntry( const OUString& NewEntry ) throw (RuntimeException, std::exception)
{
getTypedControlWindow()->InsertEntry( NewEntry, 0 );
m_aNonColorEntries.insert( NewEntry );
}
void SAL_CALL OColorControl::appendListEntry( const OUString& NewEntry ) throw (RuntimeException, std::exception)
{
getTypedControlWindow()->InsertEntry( NewEntry );
m_aNonColorEntries.insert( NewEntry );
}
Sequence< OUString > SAL_CALL OColorControl::getListEntries( ) throw (RuntimeException, std::exception)
{
if ( !m_aNonColorEntries.empty() )
return Sequence< OUString >(&(*m_aNonColorEntries.begin()),m_aNonColorEntries.size());
return Sequence< OUString >();
}
void OColorControl::setModified()
{
OColorControl_Base::setModified();
if ( !getTypedControlWindow()->IsTravelSelect() )
// fire a commit
notifyModifiedValue();
// fire a commit
notifyModifiedValue();
}
//= OListboxControl
OListboxControl::OListboxControl( vcl::Window* pParent, WinBits nWinStyle)
:OListboxControl_Base( PropertyControlType::ListBox, pParent, nWinStyle )
{
diff --git a/extensions/source/propctrlr/standardcontrol.hxx b/extensions/source/propctrlr/standardcontrol.hxx
index ab026d6..d3f64e7 100644
--- a/extensions/source/propctrlr/standardcontrol.hxx
+++ b/extensions/source/propctrlr/standardcontrol.hxx
@@ -34,6 +34,7 @@
#include <vcl/combobox.hxx>
#include <svtools/calendar.hxx>
#include <svtools/fmtfield.hxx>
#include <svx/colorbox.hxx>
#include <set>
@@ -60,18 +61,18 @@ namespace pcr
TListboxWindow::SetSelectHdl( LINK(this, ListLikeControlWithModifyHandler, OnSelect) );
}
void SetModifyHdl( const Link<ListBox&,void>& _rLink ) { aModifyHdl = _rLink;; }
void SetModifyHdl( const Link<TListboxWindow&,void>& _rLink ) { aModifyHdl = _rLink;; }
private:
DECL_LINK(OnSelect, ListBox&, void);
Link<ListBox&,void> aModifyHdl;
DECL_LINK(OnSelect, TListboxWindow&, void);
Link<TListboxWindow&,void> aModifyHdl;
};
template< class LISTBOX_WINDOW >
void ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::LinkStubOnSelect(void * instance, ListBox& data) {
void ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::LinkStubOnSelect(void * instance, LISTBOX_WINDOW& data) {
return static_cast<ListLikeControlWithModifyHandler< LISTBOX_WINDOW > *>(instance)->OnSelect(data);
}
template< class LISTBOX_WINDOW >
void ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::OnSelect(ListBox& rListBox)
void ListLikeControlWithModifyHandler< LISTBOX_WINDOW >::OnSelect(LISTBOX_WINDOW& rListBox)
{
aModifyHdl.Call(rListBox);
}
@@ -260,14 +261,11 @@ namespace pcr
//= OColorControl
typedef CommonBehaviourControl < css::inspection::XStringListControl
, ListLikeControlWithModifyHandler< ColorListBox >
typedef CommonBehaviourControl < css::inspection::XPropertyControl
, ListLikeControlWithModifyHandler<SvxColorListBox>
> OColorControl_Base;
class OColorControl : public OColorControl_Base
{
private:
::std::set< OUString > m_aNonColorEntries;
public:
OColorControl( vcl::Window* pParent, WinBits nWinStyle );
@@ -276,12 +274,6 @@ namespace pcr
virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::beans::IllegalTypeException, css::uno::RuntimeException, std::exception) override;
virtual css::uno::Type SAL_CALL getValueType() throw (css::uno::RuntimeException, std::exception) override;
// XStringListControl
virtual void SAL_CALL clearList( ) throw (css::uno::RuntimeException, std::exception) override;
virtual void SAL_CALL prependListEntry( const OUString& NewEntry ) throw (css::uno::RuntimeException, std::exception) override;
virtual void SAL_CALL appendListEntry( const OUString& NewEntry ) throw (css::uno::RuntimeException, std::exception) override;
virtual css::uno::Sequence< OUString > SAL_CALL getListEntries( ) throw (css::uno::RuntimeException, std::exception) override;
protected:
// CommonBehaviourControlHelper::setModified
virtual void setModified() override;
diff --git a/include/svx/colorbox.hxx b/include/svx/colorbox.hxx
index 5fa4bfb..f6dee67 100644
--- a/include/svx/colorbox.hxx
+++ b/include/svx/colorbox.hxx
@@ -45,7 +45,7 @@ private:
void LockWidthRequest();
VclPtr<SvxColorWindow> getColorWindow() const;
public:
SvxColorListBox(vcl::Window* pParent);
SvxColorListBox(vcl::Window* pParent, WinBits nStyle = 0);
virtual ~SvxColorListBox() override;
virtual void dispose() override;
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 6650163..800e53a 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -3200,8 +3200,8 @@ void SvxListBoxColorWrapper::operator()(const OUString& /*rCommand*/, const Name
mxControl->Selected(rColor);
}
SvxColorListBox::SvxColorListBox(vcl::Window* pParent)
: MenuButton(pParent)
SvxColorListBox::SvxColorListBox(vcl::Window* pParent, WinBits nStyle)
: MenuButton(pParent, nStyle)
, m_aColorWrapper(this)
, m_aAutoDisplayColor(Application::GetSettings().GetStyleSettings().GetDialogColor())
, m_nSlotId(0)