[Libreoffice-commits] core.git: Branch 'feature/gsoc14-colors' - include/svx svx/source svx/uiconfig

Krisztian Pinter pin.terminator at gmail.com
Mon Aug 11 23:48:02 PDT 2014


 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(-)

New commits:
commit ed6e4c65965fefdf5b638d6a2f8ca5fac856aa3b
Author: Krisztian Pinter <pin.terminator at gmail.com>
Date:   Mon Aug 11 17:35:50 2014 +0200

    Add recent colors
    
    Change-Id: Id6b2239149bf7d0b3c9242efb7a72091e32c3384

diff --git a/include/svx/Palette.hxx b/include/svx/Palette.hxx
index 11a3462..6eab3f4 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 e4144f9..cb70d2c 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 496e0fc..ba5bdbd 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 98ae0b2..101c002 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 70db254..58073f2 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 446fb1e..e01af4a 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()
@@ -1129,6 +1137,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;
 }
 
@@ -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 0527e78..f33366a 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>


More information about the Libreoffice-commits mailing list