[Libreoffice-commits] core.git: Branch 'feature/gsoc14-colors' - include/svx svx/source
Krisztian Pinter
pin.terminator at gmail.com
Thu Jun 19 07:06:12 PDT 2014
include/svx/SvxColorValueSet.hxx | 1
svx/source/tbxctrls/SvxColorValueSet.cxx | 13 +++
svx/source/tbxctrls/colorwindow.hxx | 3
svx/source/tbxctrls/tbcontrl.cxx | 113 ++++++++++++++++++-------------
4 files changed, 83 insertions(+), 47 deletions(-)
New commits:
commit 0d0c2fcb2fa2dfd0df8abc63e703d7f12fa6799f
Author: Krisztian Pinter <pin.terminator at gmail.com>
Date: Thu Jun 19 16:04:00 2014 +0200
Add ability to switch between default and document colors
Change-Id: Ice8d58028a531b37d2c03fdc3e55eea850c53d44
diff --git a/include/svx/SvxColorValueSet.hxx b/include/svx/SvxColorValueSet.hxx
index 8690a48..7502d93 100644
--- a/include/svx/SvxColorValueSet.hxx
+++ b/include/svx/SvxColorValueSet.hxx
@@ -39,6 +39,7 @@ public:
sal_uInt32 getColumnCount() const;
void addEntriesForXColorList(const XColorList& rXColorList, sal_uInt32 nStartIndex = 1);
+ void addEntriesForColorVector(const std::vector<Color>& rColorVector, sal_uInt32 nStartIndex = 1);
Size layoutAllVisible(sal_uInt32 nEntryCount);
Size layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount);
};
diff --git a/svx/source/tbxctrls/SvxColorValueSet.cxx b/svx/source/tbxctrls/SvxColorValueSet.cxx
index 4f145fc..1ee94f1 100644
--- a/svx/source/tbxctrls/SvxColorValueSet.cxx
+++ b/svx/source/tbxctrls/SvxColorValueSet.cxx
@@ -88,6 +88,19 @@ void SvxColorValueSet::addEntriesForXColorList(const XColorList& rXColorList, sa
}
}
+void SvxColorValueSet::addEntriesForColorVector(const std::vector<Color>& rColorVector, sal_uInt32 nStartIndex)
+{
+ const sal_uInt32 nColorCount(rColorVector.size());
+
+ //for(sal_uInt32 nIndex(0); nIndex < nColorCount; nIndex++, nStartIndex++)
+ for(std::vector<Color>::const_iterator it = rColorVector.begin();
+ it != rColorVector.end(); it++, nStartIndex++)
+ {
+ const Color& rEntry = *it;
+ InsertItem(nStartIndex, rEntry, "");
+ }
+}
+
Size SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount)
{
if(!nEntryCount)
diff --git a/svx/source/tbxctrls/colorwindow.hxx b/svx/source/tbxctrls/colorwindow.hxx
index 6bb9f92..c699986 100644
--- a/svx/source/tbxctrls/colorwindow.hxx
+++ b/svx/source/tbxctrls/colorwindow.hxx
@@ -49,6 +49,9 @@ private:
const sal_uInt16 nNavButtonWidth;
const sal_uInt16 nNavButtonHeight;
sal_uInt16& rnCurrentPalette;
+ sal_uInt16 nNumOfPalettes;
+
+ void ReloadColorSet();
DECL_LINK( SelectHdl, void * );
DECL_LINK( StepLeftClickHdl, void * );
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 1c8763f..f2608bd 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -1091,32 +1091,10 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
maCommand( rCommand ),
nNavButtonWidth ( 20 ),
nNavButtonHeight( 20 ),
- rnCurrentPalette( rnCurrentPalette_ )
+ rnCurrentPalette( rnCurrentPalette_ ),
+ nNumOfPalettes( 1 )
{
- SfxObjectShell* pDocSh = SfxObjectShell::Current();
- const SfxPoolItem* pItem = NULL;
- XColorListRef pColorList;
-
- if ( pDocSh )
- {
- if ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) )
- pColorList = ( (SvxColorListItem*)pItem )->GetColorList();
-//-------- Add doc colors to palette
- XColorEntry* pEntry;
- std::vector<Color> aColors = pDocSh->GetDocColors();
- for( unsigned int i = 0; i < aColors.size(); ++i )
- {
- pEntry = new XColorEntry( aColors[i],
- "Document Color " + OUString::number(i) );
- pColorList->Insert( pEntry, pColorList->Count() );
- }
-//---------
- }
-
- if ( !pColorList.is() )
- pColorList = XColorList::CreateStdColorList();
-
if ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId )
{
aColorSet.SetStyle( aColorSet.GetStyle() | WB_NONEFIELD );
@@ -1148,29 +1126,16 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_LINECOLOR ) );
}
- if ( pColorList.is() )
- {
- const long nColorCount(pColorList->Count());
- const Size aNewSize(aColorSet.layoutAllVisible(nColorCount));
- aColorSet.SetOutputSizePixel(aNewSize);
- static sal_Int32 nAdd = 4;
+ if( SfxObjectShell::Current()->GetDocColors().size() > 0 )
+ nNumOfPalettes++;
- SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd + nNavButtonHeight));
- aColorSet.Clear();
- aColorSet.addEntriesForXColorList(*pColorList);
+ aButtonLeft.SetText("<");
+ aButtonLeft.SetClickHdl( LINK( this, SvxColorWindow_Impl, StepLeftClickHdl ) );
+ aButtonLeft.Show();
- aButtonLeft.SetText("<");
- aButtonLeft.SetClickHdl( LINK( this, SvxColorWindow_Impl, StepLeftClickHdl ) );
- aButtonLeft.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight));
- aButtonLeft.SetPosPixel(Point(0, aNewSize.Height() + nAdd + 1));
- aButtonLeft.Show();
-
- aButtonRight.SetText(">");
- aButtonRight.SetClickHdl( LINK( this, SvxColorWindow_Impl, StepRightClickHdl ) );
- aButtonRight.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight));
- aButtonRight.SetPosPixel(Point(aNewSize.Width() + nAdd - nNavButtonWidth, aNewSize.Height() + nAdd + 1));
- aButtonRight.Show();
- }
+ aButtonRight.SetText(">");
+ aButtonRight.SetClickHdl( LINK( this, SvxColorWindow_Impl, StepRightClickHdl ) );
+ aButtonRight.Show();
aColorSet.SetSelectHdl( LINK( this, SvxColorWindow_Impl, SelectHdl ) );
SetHelpId( HID_POPUP_COLOR );
@@ -1180,6 +1145,58 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
AddStatusListener( OUString( ".uno:ColorTableState" ));
AddStatusListener( maCommand );
+
+ ReloadColorSet();
+}
+
+void SvxColorWindow_Impl::ReloadColorSet()
+{
+ SfxObjectShell* pDocSh = SfxObjectShell::Current();
+ long nColorCount = 0;
+
+ if( rnCurrentPalette == 0 )
+ {
+ const SfxPoolItem* pItem = NULL;
+ XColorListRef pColorList;
+
+ if ( pDocSh )
+ {
+ if ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) )
+ pColorList = ( (SvxColorListItem*)pItem )->GetColorList();
+ }
+
+ if ( !pColorList.is() )
+ pColorList = XColorList::CreateStdColorList();
+
+
+ if ( pColorList.is() )
+ {
+ nColorCount = pColorList->Count();
+ aColorSet.Clear();
+ aColorSet.addEntriesForXColorList(*pColorList);
+ }
+ }
+ else if( rnCurrentPalette == nNumOfPalettes - 1 )
+ {
+ // Add doc colors to palette
+ std::vector<Color> aColors = pDocSh->GetDocColors();
+ nColorCount = aColors.size();
+ aColorSet.Clear();
+ aColorSet.addEntriesForColorVector(aColors);
+ }
+
+ const Size aNewSize(aColorSet.layoutAllVisible(nColorCount));
+ aColorSet.SetOutputSizePixel(aNewSize);
+ static sal_Int32 nAdd = 4;
+
+ //TODO: Move left/right buttons above the colors
+ SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd + nNavButtonHeight));
+
+ aButtonLeft.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight));
+ aButtonLeft.SetPosPixel(Point(0, aNewSize.Height() + nAdd + 1));
+
+ aButtonRight.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight));
+ aButtonRight.SetPosPixel(Point(aNewSize.Width() + nAdd - nNavButtonWidth, aNewSize.Height() + nAdd + 1));
}
SvxColorWindow_Impl::~SvxColorWindow_Impl()
@@ -1235,13 +1252,15 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl)
IMPL_LINK_NOARG(SvxColorWindow_Impl, StepLeftClickHdl)
{
- rnCurrentPalette--;
+ rnCurrentPalette = (rnCurrentPalette - 1) % nNumOfPalettes;
+ ReloadColorSet();
return 0;
}
IMPL_LINK_NOARG(SvxColorWindow_Impl, StepRightClickHdl)
{
- rnCurrentPalette++;
+ rnCurrentPalette = (rnCurrentPalette + 1) % nNumOfPalettes;
+ ReloadColorSet();
return 0;
}
More information about the Libreoffice-commits
mailing list