summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrisztian Pinter <pin.terminator@gmail.com>2014-06-19 16:04:00 +0200
committerKrisztian Pinter <pin.terminator@gmail.com>2014-07-25 17:14:09 +0200
commit8b41daa9100d9468cf7ba7783d01ea6eca7ba3ec (patch)
tree50410a92cb99df79207d2021d58046bdd62ff5d0
parent8fead2728c00c2f1019286676eda0b5a7d5161cd (diff)
Add ability to switch between default and document colors
Change-Id: Ice8d58028a531b37d2c03fdc3e55eea850c53d44
-rw-r--r--include/svx/SvxColorValueSet.hxx1
-rw-r--r--svx/source/tbxctrls/SvxColorValueSet.cxx13
-rw-r--r--svx/source/tbxctrls/colorwindow.hxx3
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx113
4 files changed, 83 insertions, 47 deletions
diff --git a/include/svx/SvxColorValueSet.hxx b/include/svx/SvxColorValueSet.hxx
index 8690a480fb4b..7502d93f6104 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 4f145fcf573b..1ee94f1cc208 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 6bb9f92f1ace..c6999860d535 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 4891ebe38889..da69d77b145c 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -1032,32 +1032,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 );
@@ -1089,29 +1067,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 );
@@ -1121,6 +1086,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()
@@ -1176,13 +1193,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;
}