Kaydet (Commit) e3fcf559 authored tarafından Krisztian Pinter's avatar Krisztian Pinter Kaydeden (comit) Tomaž Vajngerl

Add PaletteManager, refactor palette code

Change-Id: I7e30fc895834318514b51bc648d32aa6d297bfae
üst 24933a3c
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SVX_PALETTE_HXX
#define INCLUDED_SVX_PALETTE_HXX
#include <rtl/ustring.hxx>
#include <tools/color.hxx>
class Palette
{
public:
typedef std::pair<Color, OString> NamedColor;
typedef std::vector< NamedColor > ColorList;
private:
bool mbLoaded;
OUString maFname;
OString maName;
ColorList maColors;
void LoadPalette();
public:
Palette(const OUString &rFname);
const OString& GetPaletteName();
const ColorList& GetPaletteColors();
};
#endif // INCLUDED_SVX_PALETTE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SVX_PALETTEMANAGER_HXX
#define INCLUDED_SVX_PALETTEMANAGER_HXX
#include <svx/SvxColorValueSet.hxx>
#include <rtl/ustring.hxx>
class PaletteManager
{
sal_uInt16 mnNumOfPalettes;
sal_uInt16 mnCurrentPalette;
long mnColorCount;
std::vector<Palette> maPalettes;
public:
PaletteManager();
void LoadPalettes();
void ReloadColorSet(SvxColorValueSet& rColorSet);
void PrevPalette();
void NextPalette();
long GetColorCount();
OUString GetPaletteName();
};
#endif // INCLUDED_SVX_PALETTEMANAGER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -19,21 +19,12 @@ ...@@ -19,21 +19,12 @@
#ifndef INCLUDED_SVX_SVXCOLORVALUESET_HXX #ifndef INCLUDED_SVX_SVXCOLORVALUESET_HXX
#define INCLUDED_SVX_SVXCOLORVALUESET_HXX #define INCLUDED_SVX_SVXCOLORVALUESET_HXX
#include <svx/Palette.hxx>
#include <svtools/valueset.hxx> #include <svtools/valueset.hxx>
#include <svx/svxdllapi.h> #include <svx/svxdllapi.h>
class XColorList; class XColorList;
struct Palette
{
typedef std::pair<Color, OString> NamedColor;
typedef std::vector< NamedColor > ColorList;
Palette(){};
Palette(const OUString &rFname);
OString maName;
ColorList maColors;
};
class SVX_DLLPUBLIC SvxColorValueSet : public ValueSet class SVX_DLLPUBLIC SvxColorValueSet : public ValueSet
{ {
private: private:
...@@ -50,7 +41,7 @@ public: ...@@ -50,7 +41,7 @@ public:
void addEntriesForXColorList(const XColorList& rXColorList, sal_uInt32 nStartIndex = 1); void addEntriesForXColorList(const XColorList& rXColorList, sal_uInt32 nStartIndex = 1);
void loadColorVector(const std::vector<Color>& rColorVector, const OUString& rNamePrefix, sal_uInt32 nStartIndex = 1); void loadColorVector(const std::vector<Color>& rColorVector, const OUString& rNamePrefix, sal_uInt32 nStartIndex = 1);
void loadPalette(const Palette& rPalette); void loadPalette(Palette& rPalette);
Size layoutAllVisible(sal_uInt32 nEntryCount); Size layoutAllVisible(sal_uInt32 nEntryCount);
Size layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount); Size layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount);
}; };
......
...@@ -133,6 +133,7 @@ ...@@ -133,6 +133,7 @@
#include <svx/svxdllapi.h> #include <svx/svxdllapi.h>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <com/sun/star/awt/FontDescriptor.hpp> #include <com/sun/star/awt/FontDescriptor.hpp>
#include <svx/PaletteManager.hxx>
// important im tbxctrls.hxx created HeDaBu !!! // important im tbxctrls.hxx created HeDaBu !!!
class SvxLineItem; class SvxLineItem;
...@@ -221,7 +222,7 @@ class SVX_DLLPUBLIC SvxColorToolBoxControl : public SfxToolBoxControl ...@@ -221,7 +222,7 @@ class SVX_DLLPUBLIC SvxColorToolBoxControl : public SfxToolBoxControl
::boost::scoped_ptr< ::svx::ToolboxButtonColorUpdater > pBtnUpdater; ::boost::scoped_ptr< ::svx::ToolboxButtonColorUpdater > pBtnUpdater;
Color mLastColor; Color mLastColor;
sal_uInt16 nCurrentPalette; PaletteManager mrPaletteManager;
DECL_LINK( SelectedHdl, Color* ); DECL_LINK( SelectedHdl, Color* );
public: public:
SFX_DECL_TOOLBOX_CONTROL(); SFX_DECL_TOOLBOX_CONTROL();
...@@ -242,7 +243,7 @@ class SVX_DLLPUBLIC SvxLineColorToolBoxControl : public SfxToolBoxControl ...@@ -242,7 +243,7 @@ class SVX_DLLPUBLIC SvxLineColorToolBoxControl : public SfxToolBoxControl
{ {
::boost::scoped_ptr< ::svx::ToolboxButtonColorUpdater > pBtnUpdater; ::boost::scoped_ptr< ::svx::ToolboxButtonColorUpdater > pBtnUpdater;
Color mLastColor; Color mLastColor;
sal_uInt16 nCurrentPalette; PaletteManager mrPaletteManager;
DECL_LINK( SelectedHdl, Color* ); DECL_LINK( SelectedHdl, Color* );
public: public:
SFX_DECL_TOOLBOX_CONTROL(); SFX_DECL_TOOLBOX_CONTROL();
......
...@@ -344,6 +344,8 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ ...@@ -344,6 +344,8 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/table/viewcontactoftableobj \ svx/source/table/viewcontactoftableobj \
svx/source/tbxctrls/extrusioncontrols \ svx/source/tbxctrls/extrusioncontrols \
svx/source/tbxctrls/fontworkgallery \ svx/source/tbxctrls/fontworkgallery \
svx/source/tbxctrls/Palette \
svx/source/tbxctrls/PaletteManager \
svx/source/tbxctrls/tbcontrl \ svx/source/tbxctrls/tbcontrl \
svx/source/tbxctrls/tbxcolorupdate \ svx/source/tbxctrls/tbxcolorupdate \
svx/source/tbxctrls/SvxColorValueSet \ svx/source/tbxctrls/SvxColorValueSet \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <svx/Palette.hxx>
#include <tools/stream.hxx>
// finds first token in rStr from index, separated by whitespace
// returns position of next token in index
OString lcl_getToken(const OString& rStr, sal_Int32& index)
{
sal_Int32 substart, toklen = 0;
while(index < rStr.getLength() &&
(rStr[index] == ' ' || rStr[index] == '\n' || rStr[index] == '\t'))
++index;
if(index == rStr.getLength())
{
index = -1;
return OString();
}
substart = index;
while(index < rStr.getLength() &&
!(rStr[index] == ' ' || rStr[index] == '\n' || rStr[index] == '\t'))
{
++index;
++toklen;
}
while(index < rStr.getLength() &&
(rStr[index] == ' ' || rStr[index] == '\n' || rStr[index] == '\t'))
++index;
if(index == rStr.getLength())
index = -1;
return rStr.copy(substart, toklen);
}
Palette::Palette(const OUString &rFname) :
mbLoaded( false ),
maFname( rFname ){}
const OString& Palette::GetPaletteName()
{
LoadPalette();
return maName;
}
const Palette::ColorList& Palette::GetPaletteColors()
{
LoadPalette();
return maColors;
}
void Palette::LoadPalette()
{
if( mbLoaded ) return;
mbLoaded = true;
// TODO add error handling!!!
SvFileStream aFile(maFname, STREAM_READ);
OString aLine;
aFile.ReadLine(aLine);
if( !aLine.startsWith("GIMP Palette") ) return;
aFile.ReadLine(aLine);
if( aLine.startsWith("Name: ", &maName) )
{
aFile.ReadLine(aLine);
if( aLine.startsWith("Columns: "))
aFile.ReadLine(aLine); // we can ignore this
}
do {
if (aLine[0] != '#' && aLine[0] != '\n')
{
// TODO check if r,g,b are 0<= x <=255, or just clamp?
sal_Int32 nIndex = 0;
OString token;
token = lcl_getToken(aLine, nIndex);
if(token == "" || nIndex == -1) continue;
sal_Int32 r = token.toInt32();
token = lcl_getToken(aLine, nIndex);
if(token == "" || nIndex == -1) continue;
sal_Int32 g = token.toInt32();
token = lcl_getToken(aLine, nIndex);
if(token == "") continue;
sal_Int32 b = token.toInt32();
OString name;
if(nIndex != -1)
name = aLine.copy(nIndex);
maColors.push_back(std::make_pair(Color(r, g, b), name));
}
} while (aFile.ReadLine(aLine));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <svx/PaletteManager.hxx>
#include <osl/file.hxx>
#include <unotools/pathoptions.hxx>
#include <sfx2/objsh.hxx>
#include "svx/drawitem.hxx"
#include <svx/dialogs.hrc>
PaletteManager::PaletteManager() :
mnNumOfPalettes(2),
mnCurrentPalette(0),
mnColorCount(0)
{
LoadPalettes();
mnNumOfPalettes += maPalettes.size();
}
void PaletteManager::LoadPalettes()
{
OUString aPalPath = SvtPathOptions().GetPalettePath();
osl::Directory aDir(aPalPath);
maPalettes.clear();
osl::DirectoryItem aDirItem;
osl::FileStatus aFileStat(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type);
if( aDir.open() == osl::FileBase::E_None )
{
while( aDir.getNextItem(aDirItem) == osl::FileBase::E_None )
{
aDirItem.getFileStatus(aFileStat);
if(aFileStat.isRegular() || aFileStat.isLink())
{
OUString aPath = aFileStat.getFileURL();
if(aPath.getLength() > 4 &&
aPath.copy(aPath.getLength()-4).toAsciiLowerCase() == ".gpl")
{
maPalettes.push_back(Palette(aPath));
}
}
}
}
}
void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet)
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
if( mnCurrentPalette == 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() )
{
mnColorCount = pColorList->Count();
rColorSet.Clear();
rColorSet.addEntriesForXColorList(*pColorList);
}
}
else if( mnCurrentPalette == mnNumOfPalettes - 1 )
{
// Add doc colors to palette
std::vector<Color> aColors = pDocSh->GetDocColors();
mnColorCount = aColors.size();
rColorSet.Clear();
rColorSet.loadColorVector(aColors, "Document Color ");
}
else
{
Palette& rPal = maPalettes[mnCurrentPalette-1];
mnColorCount = rPal.GetPaletteColors().size();
rColorSet.Clear();
rColorSet.loadPalette(rPal);
}
}
void PaletteManager::PrevPalette()
{
mnCurrentPalette = mnCurrentPalette == 0 ? mnNumOfPalettes - 1 : mnCurrentPalette - 1;
}
void PaletteManager::NextPalette()
{
mnCurrentPalette = mnCurrentPalette == mnNumOfPalettes - 1 ? 0 : mnCurrentPalette + 1;
}
long PaletteManager::GetColorCount()
{
return mnColorCount;
}
OUString PaletteManager::GetPaletteName()
{
if( mnCurrentPalette == 0 )
return OUString("Default palette");
else if( mnCurrentPalette == mnNumOfPalettes - 1 )
return OUString("Document colors");
else
return OStringToOUString(maPalettes[mnCurrentPalette - 1].GetPaletteName(), RTL_TEXTENCODING_ASCII_US);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -23,85 +23,6 @@ ...@@ -23,85 +23,6 @@
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/settings.hxx> #include <vcl/settings.hxx>
// finds first token in rStr from index, separated by whitespace
// returns position of next token in index
OString lcl_getToken(const OString& rStr, sal_Int32& index)
{
sal_Int32 substart, toklen = 0;
while(index < rStr.getLength() &&
(rStr[index] == ' ' || rStr[index] == '\n' || rStr[index] == '\t'))
++index;
if(index == rStr.getLength())
{
index = -1;
return OString();
}
substart = index;
while(index < rStr.getLength() &&
!(rStr[index] == ' ' || rStr[index] == '\n' || rStr[index] == '\t'))
{
++index;
++toklen;
}
while(index < rStr.getLength() &&
(rStr[index] == ' ' || rStr[index] == '\n' || rStr[index] == '\t'))
++index;
if(index == rStr.getLength())
index = -1;
return rStr.copy(substart, toklen);
}
Palette::Palette(const OUString &rFname)
{
// TODO add error handling!!!
SvFileStream aFile(rFname, STREAM_READ);
OString aPaletteName;
OString aLine;
aFile.ReadLine(aLine);
if( !aLine.startsWith("GIMP Palette") ) return;
aFile.ReadLine(aLine);
if( aLine.startsWith("Name: ", &aPaletteName) )
{
aFile.ReadLine(aLine);
if( aLine.startsWith("Columns: "))
aFile.ReadLine(aLine); // we can ignore this
}
do {
if (aLine[0] != '#' && aLine[0] != '\n')
{
// TODO check if r,g,b are 0<= x <=255, or just clamp?
sal_Int32 nIndex = 0;
OString token;
token = lcl_getToken(aLine, nIndex);
if(token == "" || nIndex == -1) continue;
sal_Int32 r = token.toInt32();
token = lcl_getToken(aLine, nIndex);
if(token == "" || nIndex == -1) continue;
sal_Int32 g = token.toInt32();
token = lcl_getToken(aLine, nIndex);
if(token == "") continue;
sal_Int32 b = token.toInt32();
OString name;
if(nIndex != -1)
name = aLine.copy(nIndex);
maColors.push_back(std::make_pair(Color(r, g, b), name));
}
} while (aFile.ReadLine(aLine));
}
SvxColorValueSet::SvxColorValueSet(Window* _pParent, WinBits nWinStyle) SvxColorValueSet::SvxColorValueSet(Window* _pParent, WinBits nWinStyle)
: ValueSet(_pParent, nWinStyle) : ValueSet(_pParent, nWinStyle)
{ {
...@@ -186,9 +107,9 @@ void SvxColorValueSet::loadColorVector(const std::vector<Color>& rColorVector, c ...@@ -186,9 +107,9 @@ void SvxColorValueSet::loadColorVector(const std::vector<Color>& rColorVector, c
} }
void SvxColorValueSet::loadPalette(const Palette& rPalette) void SvxColorValueSet::loadPalette(Palette& rPalette)
{ {
const Palette::ColorList &rColors = rPalette.maColors; const Palette::ColorList &rColors = rPalette.GetPaletteColors();
Clear(); Clear();
int nIx = 1; int nIx = 1;
for(Palette::ColorList::const_iterator it = rColors.begin(); for(Palette::ColorList::const_iterator it = rColors.begin();
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <com/sun/star/frame/XFrame.hpp> #include <com/sun/star/frame/XFrame.hpp>
#include <svx/SvxColorValueSet.hxx> #include <svx/SvxColorValueSet.hxx>
#include <svx/PaletteManager.hxx>
class SvxColorWindow_Impl : public SfxPopupWindow class SvxColorWindow_Impl : public SfxPopupWindow
{ {
...@@ -36,15 +37,15 @@ private: ...@@ -36,15 +37,15 @@ private:
SvxColorValueSet aColorSet; SvxColorValueSet aColorSet;
PushButton aButtonLeft; PushButton aButtonLeft;
PushButton aButtonRight; PushButton aButtonRight;
FixedText aPaletteName;
OUString maCommand; OUString maCommand;
Link maSelectedLink; Link maSelectedLink;
const sal_uInt16 nNavButtonWidth; const sal_uInt16 nNavButtonWidth;
const sal_uInt16 nNavButtonHeight; const sal_uInt16 nNavButtonHeight;
sal_uInt16& rnCurrentPalette; PaletteManager& mrPaletteManager;
sal_uInt16 nNumOfPalettes;
void ReloadColorSet(); void Update();
DECL_LINK( SelectHdl, void * ); DECL_LINK( SelectHdl, void * );
DECL_LINK( StepLeftClickHdl, void * ); DECL_LINK( StepLeftClickHdl, void * );
...@@ -56,7 +57,7 @@ protected: ...@@ -56,7 +57,7 @@ protected:
public: public:
SvxColorWindow_Impl( const OUString& rCommand, SvxColorWindow_Impl( const OUString& rCommand,
sal_uInt16& rnCurrentPalette_, PaletteManager& rPaletteManager,
sal_uInt16 nSlotId, sal_uInt16 nSlotId,
const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
const OUString& rWndTitle, const OUString& rWndTitle,
......
...@@ -30,11 +30,9 @@ ...@@ -30,11 +30,9 @@
#include <svtools/ctrltool.hxx> #include <svtools/ctrltool.hxx>
#include <svtools/borderhelper.hxx> #include <svtools/borderhelper.hxx>
#include <svl/stritem.hxx> #include <svl/stritem.hxx>
#include <unotools/pathoptions.hxx>
#include <sfx2/tplpitem.hxx> #include <sfx2/tplpitem.hxx>
#include <sfx2/dispatch.hxx> #include <sfx2/dispatch.hxx>
#include <sfx2/viewsh.hxx> #include <sfx2/viewsh.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/docfac.hxx> #include <sfx2/docfac.hxx>
#include <sfx2/templdlg.hxx> #include <sfx2/templdlg.hxx>
#include <svl/isethint.hxx> #include <svl/isethint.hxx>
...@@ -1003,7 +1001,7 @@ void SvxFontNameBox_Impl::Select() ...@@ -1003,7 +1001,7 @@ void SvxFontNameBox_Impl::Select()
#endif #endif
SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
sal_uInt16& rnCurrentPalette_, PaletteManager& rPaletteManager,
sal_uInt16 nSlotId, sal_uInt16 nSlotId,
const Reference< XFrame >& rFrame, const Reference< XFrame >& rFrame,
const OUString& rWndTitle, const OUString& rWndTitle,
...@@ -1013,11 +1011,11 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, ...@@ -1013,11 +1011,11 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
aColorSet ( this, WinBits( WB_ITEMBORDER | WB_NAMEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT) ), aColorSet ( this, WinBits( WB_ITEMBORDER | WB_NAMEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT) ),
aButtonLeft ( this ), aButtonLeft ( this ),
aButtonRight( this ), aButtonRight( this ),
aPaletteName( this ),
maCommand( rCommand ), maCommand( rCommand ),
nNavButtonWidth ( 20 ), nNavButtonWidth ( 20 ),
nNavButtonHeight( 20 ), nNavButtonHeight( 20 ),
rnCurrentPalette( rnCurrentPalette_ ), mrPaletteManager( rPaletteManager )
nNumOfPalettes( 1 )
{ {
if ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId ) if ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId )
...@@ -1051,9 +1049,6 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, ...@@ -1051,9 +1049,6 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_LINECOLOR ) ); aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_LINECOLOR ) );
} }
if( SfxObjectShell::Current()->GetDocColors().size() > 0 )
nNumOfPalettes++;
aButtonLeft.SetText("<"); aButtonLeft.SetText("<");
aButtonLeft.SetClickHdl( LINK( this, SvxColorWindow_Impl, StepLeftClickHdl ) ); aButtonLeft.SetClickHdl( LINK( this, SvxColorWindow_Impl, StepLeftClickHdl ) );
aButtonLeft.Show(); aButtonLeft.Show();
...@@ -1068,49 +1063,20 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, ...@@ -1068,49 +1063,20 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand,
SetText( rWndTitle ); SetText( rWndTitle );
aColorSet.Show(); aColorSet.Show();
aPaletteName.Show();
AddStatusListener( OUString( ".uno:ColorTableState" )); AddStatusListener( OUString( ".uno:ColorTableState" ));
AddStatusListener( maCommand ); AddStatusListener( maCommand );
ReloadColorSet(); Update();
} }
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() ) void SvxColorWindow_Impl::Update()
{ {
nColorCount = pColorList->Count(); mrPaletteManager.ReloadColorSet(aColorSet);
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)); const Size aNewSize(aColorSet.layoutAllVisible(mrPaletteManager.GetColorCount()));
aColorSet.SetOutputSizePixel(aNewSize); aColorSet.SetOutputSizePixel(aNewSize);
static sal_Int32 nAdd = 4; static sal_Int32 nAdd = 4;
...@@ -1122,6 +1088,10 @@ void SvxColorWindow_Impl::ReloadColorSet() ...@@ -1122,6 +1088,10 @@ void SvxColorWindow_Impl::ReloadColorSet()
aButtonRight.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight)); aButtonRight.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight));
aButtonRight.SetPosPixel(Point(aNewSize.Width() + nAdd - nNavButtonWidth, aNewSize.Height() + nAdd + 1)); aButtonRight.SetPosPixel(Point(aNewSize.Width() + nAdd - nNavButtonWidth, aNewSize.Height() + nAdd + 1));
aPaletteName.SetSizePixel(Size(150, nNavButtonHeight));
aPaletteName.SetPosPixel(Point(nNavButtonWidth, aNewSize.Height() + nAdd + 1));
aPaletteName.SetText(mrPaletteManager.GetPaletteName());
} }
SvxColorWindow_Impl::~SvxColorWindow_Impl() SvxColorWindow_Impl::~SvxColorWindow_Impl()
...@@ -1135,7 +1105,7 @@ void SvxColorWindow_Impl::KeyInput( const KeyEvent& rKEvt ) ...@@ -1135,7 +1105,7 @@ void SvxColorWindow_Impl::KeyInput( const KeyEvent& rKEvt )
SfxPopupWindow* SvxColorWindow_Impl::Clone() const SfxPopupWindow* SvxColorWindow_Impl::Clone() const
{ {
return new SvxColorWindow_Impl( maCommand, rnCurrentPalette, theSlotId, GetFrame(), GetText(), GetParent() ); return new SvxColorWindow_Impl( maCommand, mrPaletteManager, theSlotId, GetFrame(), GetText(), GetParent() );
} }
IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl) IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl)
...@@ -1177,15 +1147,15 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl) ...@@ -1177,15 +1147,15 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl)
IMPL_LINK_NOARG(SvxColorWindow_Impl, StepLeftClickHdl) IMPL_LINK_NOARG(SvxColorWindow_Impl, StepLeftClickHdl)
{ {
rnCurrentPalette = (rnCurrentPalette - 1) % nNumOfPalettes; mrPaletteManager.PrevPalette();
ReloadColorSet(); Update();
return 0; return 0;
} }
IMPL_LINK_NOARG(SvxColorWindow_Impl, StepRightClickHdl) IMPL_LINK_NOARG(SvxColorWindow_Impl, StepRightClickHdl)
{ {
rnCurrentPalette = (rnCurrentPalette + 1) % nNumOfPalettes; mrPaletteManager.NextPalette();
ReloadColorSet(); Update();
return 0; return 0;
} }
...@@ -2222,8 +2192,7 @@ SvxColorToolBoxControl::SvxColorToolBoxControl( ...@@ -2222,8 +2192,7 @@ SvxColorToolBoxControl::SvxColorToolBoxControl(
sal_uInt16 nId, sal_uInt16 nId,
ToolBox& rTbx ) : ToolBox& rTbx ) :
SfxToolBoxControl( nSlotId, nId, rTbx ), SfxToolBoxControl( nSlotId, nId, rTbx ),
mLastColor( COL_AUTO ), mLastColor( COL_AUTO )
nCurrentPalette( 0 )
{ {
rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
...@@ -2277,7 +2246,7 @@ SfxPopupWindow* SvxColorToolBoxControl::CreatePopupWindow() ...@@ -2277,7 +2246,7 @@ SfxPopupWindow* SvxColorToolBoxControl::CreatePopupWindow()
SvxColorWindow_Impl* pColorWin = SvxColorWindow_Impl* pColorWin =
new SvxColorWindow_Impl( new SvxColorWindow_Impl(
m_aCommandURL, m_aCommandURL,
nCurrentPalette, mrPaletteManager,
GetSlotId(), GetSlotId(),
m_xFrame, m_xFrame,
SVX_RESSTR( RID_SVXITEMS_EXTRAS_CHARCOLOR ), SVX_RESSTR( RID_SVXITEMS_EXTRAS_CHARCOLOR ),
...@@ -2385,8 +2354,7 @@ SvxLineColorToolBoxControl::SvxLineColorToolBoxControl( ...@@ -2385,8 +2354,7 @@ SvxLineColorToolBoxControl::SvxLineColorToolBoxControl(
ToolBox& rTbx ) : ToolBox& rTbx ) :
SfxToolBoxControl( nSlotId, nId, rTbx ), SfxToolBoxControl( nSlotId, nId, rTbx ),
mLastColor( COL_BLACK ), mLastColor( COL_BLACK )
nCurrentPalette( 0 )
{ {
rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
addStatusListener( OUString( ".uno:XLineColor" ) ); addStatusListener( OUString( ".uno:XLineColor" ) );
...@@ -2407,7 +2375,7 @@ SfxPopupWindow* SvxLineColorToolBoxControl::CreatePopupWindow() ...@@ -2407,7 +2375,7 @@ SfxPopupWindow* SvxLineColorToolBoxControl::CreatePopupWindow()
SvxColorWindow_Impl* pColorWin = SvxColorWindow_Impl* pColorWin =
new SvxColorWindow_Impl( new SvxColorWindow_Impl(
m_aCommandURL, m_aCommandURL,
nCurrentPalette, mrPaletteManager,
GetSlotId(), GetSlotId(),
m_xFrame, m_xFrame,
SVX_RESSTR( RID_SVXSTR_LINECOLOR ), SVX_RESSTR( RID_SVXSTR_LINECOLOR ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment