diff options
author | Krisztian Pinter <pin.terminator@gmail.com> | 2014-08-11 17:35:50 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2014-09-17 10:19:55 +0200 |
commit | 93c4e3c9349a1ea07b822a2824559ad28f4a9a5e (patch) | |
tree | b92faf4285f5bb1677fe1f89d19f691889d56cfd | |
parent | 43b896d20abf500a882fc67f16cd0902918e5794 (diff) |
Add recent colors
Change-Id: Id6b2239149bf7d0b3c9242efb7a72091e32c3384
-rw-r--r-- | include/svx/Palette.hxx | 1 | ||||
-rw-r--r-- | include/svx/PaletteManager.hxx | 17 | ||||
-rw-r--r-- | svx/source/tbxctrls/Palette.cxx | 3 | ||||
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 32 | ||||
-rw-r--r-- | svx/source/tbxctrls/colorwindow.hxx | 6 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 71 | ||||
-rw-r--r-- | 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<Color, OUString> 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 <svx/Palette.hxx> #include <rtl/ustring.hxx> #include <svx/tbxcolorupdate.hxx> +#include <deque> #include <tools/urlobj.hxx> #include <comphelper/processfactory.hxx> @@ -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<Color> maRecentColors; boost::ptr_vector<Palette> maPalettes; public: PaletteManager(); ~PaletteManager(); void LoadPalettes(); void ReloadColorSet(SvxColorValueSet& rColorSet); + void ReloadRecentColorSet(SvxColorValueSet& rColorSet); std::vector<OUString> 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<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 ) { 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 @@ <property name="can_focus">False</property> <property name="orientation">vertical</property> <child> - <object class="GtkBox" id="box2"> + <object class="GtkButton" id="auto_color_button"> + <property name="label" translatable="yes">Automatic</property> <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkComboBox" id="palette_listbox"> - <property name="visible">True</property> - <property name="can_focus">False</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="color_picker_button"> - <property name="label">Color picker</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> + <property name="can_focus">True</property> + <property name="receives_default">True</property> </object> <packing> <property name="expand">False</property> @@ -45,6 +23,28 @@ </packing> </child> <child> + <object class="GtkSeparator" id="separator4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="palette_listbox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child> <object class="svxlo-SvxColorValueSet" id="colorset"> <property name="visible">True</property> <property name="can_focus">True</property> @@ -53,7 +53,7 @@ <packing> <property name="expand">True</property> <property name="fill">True</property> - <property name="position">1</property> + <property name="position">3</property> </packing> </child> <child> @@ -64,7 +64,67 @@ <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">2</property> + <property name="position">4</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0.019999999552965164</property> + <property name="label" translatable="yes">Recent</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">5</property> + </packing> + </child> + <child> + <object class="svxlo-SvxColorValueSet" id="recent_colorset"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">7</property> + </packing> + </child> + <child> + <object class="GtkSeparator" id="separator3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">8</property> + </packing> + </child> + <child> + <object class="GtkButton" id="color_picker_button"> + <property name="label">Color picker</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">9</property> + </packing> + </child> + <child> + <object class="GtkSeparator" id="separator2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">10</property> </packing> </child> </object> |