From ed6e4c65965fefdf5b638d6a2f8ca5fac856aa3b Mon Sep 17 00:00:00 2001 From: Krisztian Pinter Date: Mon, 11 Aug 2014 17:35:50 +0200 Subject: Add recent colors Change-Id: Id6b2239149bf7d0b3c9242efb7a72091e32c3384 --- include/svx/Palette.hxx | 1 - include/svx/PaletteManager.hxx | 17 +++-- svx/source/tbxctrls/Palette.cxx | 3 +- svx/source/tbxctrls/PaletteManager.cxx | 32 +++++++++ svx/source/tbxctrls/colorwindow.hxx | 6 ++ svx/source/tbxctrls/tbcontrl.cxx | 71 +++++++++++++++++--- svx/uiconfig/ui/colorwindow.ui | 116 +++++++++++++++++++++++++-------- 7 files changed, 203 insertions(+), 43 deletions(-) diff --git a/include/svx/Palette.hxx b/include/svx/Palette.hxx index 11a34623ca51..6eab3f46bed2 100644 --- a/include/svx/Palette.hxx +++ b/include/svx/Palette.hxx @@ -29,7 +29,6 @@ typedef std::pair NamedColor; typedef std::vector< NamedColor > ColorList; - class Palette { public: diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx index e4144f96ca9c..cb70d2c4917d 100644 --- a/include/svx/PaletteManager.hxx +++ b/include/svx/PaletteManager.hxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -36,27 +37,35 @@ class PaletteManager { - sal_uInt16 mnNumOfPalettes; - sal_uInt16 mnCurrentPalette; + const sal_uInt16 mnMaxRecentColors; - long mnColorCount; + sal_uInt16 mnNumOfPalettes; + sal_uInt16 mnCurrentPalette; + + long mnColorCount; svx::ToolboxButtonColorUpdater* mpBtnUpdater; - Color mLastColor; + Color mLastColor; + std::deque maRecentColors; boost::ptr_vector maPalettes; public: PaletteManager(); ~PaletteManager(); void LoadPalettes(); void ReloadColorSet(SvxColorValueSet& rColorSet); + void ReloadRecentColorSet(SvxColorValueSet& rColorSet); std::vector GetPaletteList(); void SetPalette( sal_Int32 nPos ); sal_Int32 GetPalette(); long GetColorCount(); + long GetRecentColorCount(); OUString GetPaletteName(); + const Color& GetLastColor(); void SetLastColor(const Color& rLastColor); + void AddRecentColor(const Color& rRecentColor); + void SetBtnUpdater(svx::ToolboxButtonColorUpdater* pBtnUpdater); void PopupColorPicker(const OUString aCommand); static void DispatchColorCommand(const OUString aCommand, const Color aColor); 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::const_iterator it = maRecentColors.begin(); + it != maRecentColors.end(); ++it) + { + rColorSet.InsertItem(nIx, *it, ""); + ++nIx; + } +} + std::vector PaletteManager::GetPaletteList() { std::vector 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::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 70db254f9de2..58073f282b9f 100644 --- a/svx/source/tbxctrls/colorwindow.hxx +++ b/svx/source/tbxctrls/colorwindow.hxx @@ -43,16 +43,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 446fb1e55830..e01af4a6b3dc 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -1027,18 +1027,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 ) ); } @@ -1053,7 +1062,6 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, SfxItemState eState = aQueryStatus.QueryState( pDummy ); if( (SFX_ITEM_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 ) ); } @@ -1077,9 +1085,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 ); @@ -1087,9 +1097,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() @@ -1122,6 +1130,28 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl) while in Dispatch()), accessing members will crash in this case. */ mpColorSet->SetNoSelection(); + if ( IsInPopupMode() ) + EndPopupMode(); + + if ( maSelectedLink.IsSet() ) + 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(); @@ -1140,6 +1170,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() ) @@ -1151,6 +1201,7 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, OpenPickerClickHdl) void SvxColorWindow_Impl::Resize() { mpColorSet->SetSizePixel( this->GetOutputSizePixel() ); + mpRecentColorSet->SetSizePixel( this->GetOutputSizePixel() ); SetOutputSizePixel(maWindowSize); } @@ -1171,6 +1222,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 ( SFX_ITEM_DEFAULT <= eState ) { diff --git a/svx/uiconfig/ui/colorwindow.ui b/svx/uiconfig/ui/colorwindow.ui index 0527e78c7294..f33366a03b0c 100644 --- a/svx/uiconfig/ui/colorwindow.ui +++ b/svx/uiconfig/ui/colorwindow.ui @@ -10,33 +10,11 @@ False vertical - + + Automatic True - False - - - True - False - - - True - True - 0 - - - - - Color picker - True - True - True - - - False - False - 1 - - + True + True False @@ -44,6 +22,28 @@ 0 + + + True + False + + + False + True + 1 + + + + + True + False + + + False + False + 2 + + True @@ -53,7 +53,7 @@ True True - 1 + 3 @@ -64,7 +64,67 @@ False True - 2 + 4 + + + + + True + False + 0.019999999552965164 + Recent + + + False + True + 5 + + + + + True + True + True + + + True + True + 7 + + + + + True + False + + + False + True + 8 + + + + + Color picker + True + True + True + + + False + False + 9 + + + + + True + False + + + False + True + 10 -- cgit