summaryrefslogtreecommitdiff
path: root/svx/source/tbxctrls
diff options
context:
space:
mode:
authorKrisztian Pinter <pin.terminator@gmail.com>2014-08-11 17:35:50 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2014-09-17 10:19:55 +0200
commit93c4e3c9349a1ea07b822a2824559ad28f4a9a5e (patch)
treeb92faf4285f5bb1677fe1f89d19f691889d56cfd /svx/source/tbxctrls
parent43b896d20abf500a882fc67f16cd0902918e5794 (diff)
Add recent colors
Change-Id: Id6b2239149bf7d0b3c9242efb7a72091e32c3384
Diffstat (limited to 'svx/source/tbxctrls')
-rw-r--r--svx/source/tbxctrls/Palette.cxx3
-rw-r--r--svx/source/tbxctrls/PaletteManager.cxx32
-rw-r--r--svx/source/tbxctrls/colorwindow.hxx6
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx71
4 files changed, 102 insertions, 10 deletions
diff --git a/svx/source/tbxctrls/Palette.cxx b/svx/source/tbxctrls/Palette.cxx
index 496e0fcc678e..ba5bdbd908f4 100644
--- a/svx/source/tbxctrls/Palette.cxx
+++ b/svx/source/tbxctrls/Palette.cxx
@@ -52,10 +52,9 @@ void PaletteGPL::LoadColorSet( SvxColorValueSet& rColorSet )
rColorSet.Clear();
int nIx = 1;
- for(ColorList::const_iterator it = maColors.begin();
+ for(typename ColorList::const_iterator it = maColors.begin();
it != maColors.end(); ++it)
{
- // TODO make it->second OUString
rColorSet.InsertItem(nIx, it->first, it->second);
++nIx;
}
diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx
index 98ae0b2dea29..101c00244fe3 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -30,6 +30,7 @@
#define STR_DOC_COLOR_PREFIX "Document Color "
PaletteManager::PaletteManager() :
+ mnMaxRecentColors(10),
mnNumOfPalettes(2),
mnCurrentPalette(0),
mnColorCount(0),
@@ -115,6 +116,18 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet)
}
}
+void PaletteManager::ReloadRecentColorSet(SvxColorValueSet& rColorSet)
+{
+ rColorSet.Clear();
+ int nIx = 1;
+ for(std::deque<Color>::const_iterator it = maRecentColors.begin();
+ it != maRecentColors.end(); ++it)
+ {
+ rColorSet.InsertItem(nIx, *it, "");
+ ++nIx;
+ }
+}
+
std::vector<OUString> PaletteManager::GetPaletteList()
{
std::vector<OUString> aPaletteNames;
@@ -148,6 +161,11 @@ long PaletteManager::GetColorCount()
return mnColorCount;
}
+long PaletteManager::GetRecentColorCount()
+{
+ return maRecentColors.size();
+}
+
OUString PaletteManager::GetPaletteName()
{
if( mnCurrentPalette == 0 )
@@ -168,6 +186,19 @@ void PaletteManager::SetLastColor(const Color& rLastColor)
mLastColor = rLastColor;
}
+void PaletteManager::AddRecentColor(const Color& rRecentColor)
+{
+ std::deque<Color>::iterator itColor =
+ std::find(maRecentColors.begin(), maRecentColors.end(), rRecentColor);
+ // if recent color to be added is already in list, remove it
+ if( itColor != maRecentColors.end() )
+ maRecentColors.erase( itColor );
+
+ maRecentColors.push_front( rRecentColor );
+ if( maRecentColors.size() > mnMaxRecentColors )
+ maRecentColors.pop_back();
+}
+
void PaletteManager::SetBtnUpdater(svx::ToolboxButtonColorUpdater* pBtnUpdater)
{
mpBtnUpdater = pBtnUpdater;
@@ -182,6 +213,7 @@ void PaletteManager::PopupColorPicker(const OUString aCommand)
{
mpBtnUpdater->Update( aColorDlg.GetColor() );
mLastColor = aColorDlg.GetColor();
+ AddRecentColor( mLastColor );
DispatchColorCommand(aCommand, mLastColor);
}
}
diff --git a/svx/source/tbxctrls/colorwindow.hxx b/svx/source/tbxctrls/colorwindow.hxx
index 68829dcb227f..37ca5a89ba9c 100644
--- a/svx/source/tbxctrls/colorwindow.hxx
+++ b/svx/source/tbxctrls/colorwindow.hxx
@@ -36,16 +36,22 @@ class SvxColorWindow_Impl : public SfxPopupWindow
private:
const sal_uInt16 theSlotId;
SvxColorValueSet* mpColorSet;
+ SvxColorValueSet* mpRecentColorSet;
Size maWindowSize;
ListBox* mpPaletteListBox;
+ PushButton* mpButtonAutoColor;
PushButton* mpButtonPicker;
OUString maCommand;
Link maSelectedLink;
PaletteManager& mrPaletteManager;
+ const sal_uInt16 mnColorSetCols;
+
DECL_LINK( SelectHdl, void * );
+ DECL_LINK( SelectRecentHdl, void * );
DECL_LINK( SelectPaletteHdl, void *);
+ DECL_LINK( AutoColorClickHdl, void * );
DECL_LINK( OpenPickerClickHdl, void * );
protected:
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index bfd275d08d34..ae02c6e892ba 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -1011,18 +1011,27 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
theSlotId( nSlotId ),
maWindowSize( 250, 350 ),
maCommand( rCommand ),
- mrPaletteManager( rPaletteManager )
+ mrPaletteManager( rPaletteManager ),
+ mnColorSetCols( 10 )
{
get(mpPaletteListBox, "palette_listbox");
+ get(mpButtonAutoColor, "auto_color_button");
get(mpButtonPicker, "color_picker_button");
get(mpColorSet, "colorset");
+ get(mpRecentColorSet, "recent_colorset");
+
+ mpColorSet->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT) );
+ mpRecentColorSet->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT) );
+
+ mpColorSet->SetColCount( mnColorSetCols );
+ mpColorSet->layoutAllVisible(mrPaletteManager.GetColorCount());
+ mpRecentColorSet->SetColCount( mnColorSetCols );
+ mpRecentColorSet->SetLineCount( 1 );
+ mpRecentColorSet->layoutAllVisible(mrPaletteManager.GetRecentColorCount());
- mpColorSet->SetStyle( WinBits(WB_ITEMBORDER | WB_NAMEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT) );
- mpColorSet->SetEdgeBlending( false );
if ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId )
{
- mpColorSet->SetStyle( mpColorSet->GetStyle() | WB_NONEFIELD );
mpColorSet->SetText( SVX_RESSTR( RID_SVXSTR_TRANSPARENT ) );
mpColorSet->SetAccessibleName( SVX_RESSTR( RID_SVXSTR_BACKGROUND ) );
}
@@ -1037,7 +1046,6 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
SfxItemState eState = aQueryStatus.QueryState( pDummy );
if( (SfxItemState::DEFAULT > eState) || ( SID_EXTRUSION_3D_COLOR == theSlotId ) )
{
- mpColorSet->SetStyle( mpColorSet->GetStyle() | WB_NONEFIELD );
mpColorSet->SetText( SVX_RESSTR( RID_SVXSTR_AUTOMATIC ) );
mpColorSet->SetAccessibleName( SVX_RESSTR( RID_SVXSTR_TEXTCOLOR ) );
}
@@ -1061,9 +1069,11 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
}
mpPaletteListBox->SelectEntryPos(mrPaletteManager.GetPalette(), true);
+ mpButtonAutoColor->SetClickHdl( LINK( this, SvxColorWindow_Impl, AutoColorClickHdl ) );
mpButtonPicker->SetClickHdl( LINK( this, SvxColorWindow_Impl, OpenPickerClickHdl ) );
mpColorSet->SetSelectHdl( LINK( this, SvxColorWindow_Impl, SelectHdl ) );
+ mpRecentColorSet->SetSelectHdl( LINK( this, SvxColorWindow_Impl, SelectRecentHdl ) );
SetHelpId( HID_POPUP_COLOR );
mpColorSet->SetHelpId( HID_POPUP_COLOR_CTRL );
SetText( rWndTitle );
@@ -1071,9 +1081,7 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
AddStatusListener( maCommand );
mrPaletteManager.ReloadColorSet(*mpColorSet);
- mpPaletteListBox->Show();
- mpButtonPicker->Show();
- mpColorSet->Show();
+ mrPaletteManager.ReloadRecentColorSet(*mpRecentColorSet);
}
SvxColorWindow_Impl::~SvxColorWindow_Impl()
@@ -1113,6 +1121,28 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl)
maSelectedLink.Call(&aColor);
PaletteManager::DispatchColorCommand(maCommand, aColor);
+ mrPaletteManager.AddRecentColor(aColor);
+ return 0;
+}
+
+IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectRecentHdl)
+{
+ sal_uInt16 nItemId = mpRecentColorSet->GetSelectItemId();
+ Color aColor;
+ aColor = mpRecentColorSet->GetItemColor( nItemId );
+
+ /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() calls.
+ This instance may be deleted in the meantime (i.e. when a dialog is opened
+ while in Dispatch()), accessing members will crash in this case. */
+ mpRecentColorSet->SetNoSelection();
+
+ if ( IsInPopupMode() )
+ EndPopupMode();
+
+ if ( maSelectedLink.IsSet() )
+ maSelectedLink.Call(&aColor);
+
+ PaletteManager::DispatchColorCommand(maCommand, aColor);
return 0;
}
@@ -1124,6 +1154,26 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectPaletteHdl)
return 0;
}
+IMPL_LINK_NOARG(SvxColorWindow_Impl, AutoColorClickHdl)
+{
+ Color aColor;
+ if (SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId)
+ aColor = COL_TRANSPARENT;
+ else if (SID_ATTR_CHAR_COLOR == theSlotId || SID_ATTR_CHAR_COLOR2 == theSlotId || SID_EXTRUSION_3D_COLOR == theSlotId)
+ aColor = COL_AUTO;
+
+ mpRecentColorSet->SetNoSelection();
+
+ if ( IsInPopupMode() )
+ EndPopupMode();
+
+ if ( maSelectedLink.IsSet() )
+ maSelectedLink.Call(&aColor);
+
+ PaletteManager::DispatchColorCommand(maCommand, aColor);
+ return 0;
+}
+
IMPL_LINK_NOARG(SvxColorWindow_Impl, OpenPickerClickHdl)
{
if ( IsInPopupMode() )
@@ -1135,6 +1185,7 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, OpenPickerClickHdl)
void SvxColorWindow_Impl::Resize()
{
mpColorSet->SetSizePixel( this->GetOutputSizePixel() );
+ mpRecentColorSet->SetSizePixel( this->GetOutputSizePixel() );
SetOutputSizePixel(maWindowSize);
}
@@ -1155,6 +1206,10 @@ void SvxColorWindow_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, co
if (( nSID == SID_COLOR_TABLE ) && ( pState->ISA( SvxColorListItem )))
{
mrPaletteManager.ReloadColorSet(*mpColorSet);
+ mrPaletteManager.ReloadRecentColorSet(*mpRecentColorSet);
+
+ mpColorSet->layoutAllVisible(mrPaletteManager.GetColorCount());
+ mpRecentColorSet->layoutAllVisible(mrPaletteManager.GetRecentColorCount());
}
else if ( SfxItemState::DEFAULT <= eState )
{