diff options
-rw-r--r-- | include/svx/Palette.hxx | 19 | ||||
-rw-r--r-- | include/svx/PaletteManager.hxx | 6 | ||||
-rw-r--r-- | svx/source/tbxctrls/Palette.cxx | 66 | ||||
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 51 | ||||
-rw-r--r-- | svx/source/tbxctrls/colorwindow.hxx | 12 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 57 |
6 files changed, 129 insertions, 82 deletions
diff --git a/include/svx/Palette.hxx b/include/svx/Palette.hxx index f7ced038c3e6..d31e9580b792 100644 --- a/include/svx/Palette.hxx +++ b/include/svx/Palette.hxx @@ -21,6 +21,7 @@ #include <rtl/ustring.hxx> #include <tools/color.hxx> +#include <tools/stream.hxx> class Palette { @@ -28,17 +29,23 @@ public: typedef std::pair<Color, OString> NamedColor; typedef std::vector< NamedColor > ColorList; private: - bool mbLoaded; - OUString maFname; - OString maName; + bool mbLoadedPalette; + bool mbValidPalette; + OUString maFName; + OUString maFPath; + OUString maName; ColorList maColors; - void LoadPalette(); + bool ReadPaletteHeader(SvFileStream& rFileStream); + void LoadPaletteHeader(); + void LoadPalette(); public: - Palette(const OUString &rFname); + Palette( const OUString &rFPath, const OUString &rFName ); - const OString& GetPaletteName(); + const OUString& GetName(); const ColorList& GetPaletteColors(); + + bool IsValid(); }; #endif // INCLUDED_SVX_PALETTE_HXX diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx index e1d720153e38..925f67bf27c9 100644 --- a/include/svx/PaletteManager.hxx +++ b/include/svx/PaletteManager.hxx @@ -37,8 +37,10 @@ public: PaletteManager(); void LoadPalettes(); void ReloadColorSet(SvxColorValueSet& rColorSet); - void PrevPalette(); - void NextPalette(); + std::vector<OUString> GetPaletteList(); + void SetPalette( sal_Int32 nPos ); + sal_Int32 GetPalette(); + long GetColorCount(); OUString GetPaletteName(); const Color& GetLastColor(); diff --git a/svx/source/tbxctrls/Palette.cxx b/svx/source/tbxctrls/Palette.cxx index aebb7f0fa48d..f84f2d523e7a 100644 --- a/svx/source/tbxctrls/Palette.cxx +++ b/svx/source/tbxctrls/Palette.cxx @@ -18,7 +18,6 @@ */ #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 @@ -52,13 +51,17 @@ OString lcl_getToken(const OString& rStr, sal_Int32& index) return rStr.copy(substart, toklen); } -Palette::Palette(const OUString &rFname) : - mbLoaded( false ), - maFname( rFname ){} +Palette::Palette( const OUString &rFPath, const OUString &rFName ) : + mbLoadedPalette( false ), + mbValidPalette( false ), + maFName( rFName ), + maFPath( rFPath ) +{ + LoadPaletteHeader(); +} -const OString& Palette::GetPaletteName() +const OUString& Palette::GetName() { - LoadPalette(); return maName; } @@ -68,27 +71,52 @@ const Palette::ColorList& Palette::GetPaletteColors() return maColors; } -void Palette::LoadPalette() +bool Palette::IsValid() { - if( mbLoaded ) return; - - mbLoaded = true; - - // TODO add error handling!!! - SvFileStream aFile(maFname, STREAM_READ); + return mbValidPalette; +} +bool Palette::ReadPaletteHeader(SvFileStream& rFileStream) +{ OString aLine; + OString aName; - aFile.ReadLine(aLine); - if( !aLine.startsWith("GIMP Palette") ) return; - aFile.ReadLine(aLine); - if( aLine.startsWith("Name: ", &maName) ) + rFileStream.ReadLine(aLine); + if( !aLine.startsWith("GIMP Palette") ) return false; + rFileStream.ReadLine(aLine); + if( aLine.startsWith("Name: ", &aName) ) { - aFile.ReadLine(aLine); + maName = OStringToOUString(aName, RTL_TEXTENCODING_ASCII_US); + rFileStream.ReadLine(aLine); if( aLine.startsWith("Columns: ")) - aFile.ReadLine(aLine); // we can ignore this + rFileStream.ReadLine(aLine); // we can ignore this + } + else + { + maName = maFName; } + return true; +} + +//TODO make this LoadPaletteHeader and set a bool if palette is incorrect +void Palette::LoadPaletteHeader() +{ + SvFileStream aFile(maFPath, STREAM_READ); + mbValidPalette = ReadPaletteHeader( aFile ); +} +void Palette::LoadPalette() +{ + if( mbLoadedPalette ) return; + mbLoadedPalette = true; + + // TODO add error handling!!! + SvFileStream aFile(maFPath, STREAM_READ); + mbValidPalette = ReadPaletteHeader( aFile ); + + if( !mbValidPalette ) return; + + OString aLine; do { if (aLine[0] != '#' && aLine[0] != '\n') { diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index e9933d4eff96..95c351dd24e6 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -25,6 +25,10 @@ #include <svx/dialogs.hrc> #include <svtools/colrdlg.hxx> +#define STR_DEFAULT_PAL "Default palette" +#define STR_DOC_COLORS "Document colors" +#define STR_DOC_COLOR_PREFIX "Document Color " + PaletteManager::PaletteManager() : mnNumOfPalettes(2), mnCurrentPalette(0), @@ -42,7 +46,9 @@ void PaletteManager::LoadPalettes() osl::Directory aDir(aPalPath); maPalettes.clear(); osl::DirectoryItem aDirItem; - osl::FileStatus aFileStat(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type); + osl::FileStatus aFileStat( osl_FileStatus_Mask_FileName | + osl_FileStatus_Mask_FileURL | + osl_FileStatus_Mask_Type ); if( aDir.open() == osl::FileBase::E_None ) { while( aDir.getNextItem(aDirItem) == osl::FileBase::E_None ) @@ -50,11 +56,12 @@ void PaletteManager::LoadPalettes() aDirItem.getFileStatus(aFileStat); if(aFileStat.isRegular() || aFileStat.isLink()) { - OUString aPath = aFileStat.getFileURL(); - if(aPath.getLength() > 4 && - aPath.copy(aPath.getLength()-4).toAsciiLowerCase() == ".gpl") + OUString aFName = aFileStat.getFileName(); + if( aFName.endsWithIgnoreAsciiCase(".gpl") ) { - maPalettes.push_back(Palette(aPath)); + Palette aPalette( aFileStat.getFileURL(), aFName ); + if( aPalette.IsValid() ) + maPalettes.push_back( aPalette ); } } } @@ -93,7 +100,7 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) std::vector<Color> aColors = pDocSh->GetDocColors(); mnColorCount = aColors.size(); rColorSet.Clear(); - rColorSet.loadColorVector(aColors, "Document Color "); + rColorSet.loadColorVector(aColors, STR_DOC_COLOR_PREFIX ); } else { @@ -104,14 +111,32 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) } } -void PaletteManager::PrevPalette() +std::vector<OUString> PaletteManager::GetPaletteList() +{ + std::vector<OUString> aPaletteNames; + + aPaletteNames.push_back( STR_DEFAULT_PAL ); + + for( std::vector<Palette>::iterator it = maPalettes.begin(); + it != maPalettes.end(); + ++it) + { + aPaletteNames.push_back( it->GetName() ); + } + + aPaletteNames.push_back( STR_DOC_COLORS ); + + return aPaletteNames; +} + +void PaletteManager::SetPalette( sal_Int32 nPos ) { - mnCurrentPalette = mnCurrentPalette == 0 ? mnNumOfPalettes - 1 : mnCurrentPalette - 1; + mnCurrentPalette = nPos; } -void PaletteManager::NextPalette() +sal_Int32 PaletteManager::GetPalette() { - mnCurrentPalette = mnCurrentPalette == mnNumOfPalettes - 1 ? 0 : mnCurrentPalette + 1; + return mnCurrentPalette; } long PaletteManager::GetColorCount() @@ -122,11 +147,11 @@ long PaletteManager::GetColorCount() OUString PaletteManager::GetPaletteName() { if( mnCurrentPalette == 0 ) - return OUString("Default palette"); + return OUString( STR_DEFAULT_PAL ); else if( mnCurrentPalette == mnNumOfPalettes - 1 ) - return OUString("Document colors"); + return OUString( STR_DOC_COLORS ); else - return OStringToOUString(maPalettes[mnCurrentPalette - 1].GetPaletteName(), RTL_TEXTENCODING_ASCII_US); + return maPalettes[mnCurrentPalette - 1].GetName(); } const Color& PaletteManager::GetLastColor() diff --git a/svx/source/tbxctrls/colorwindow.hxx b/svx/source/tbxctrls/colorwindow.hxx index fe8fe8d27e33..fd8eef7701f6 100644 --- a/svx/source/tbxctrls/colorwindow.hxx +++ b/svx/source/tbxctrls/colorwindow.hxx @@ -30,6 +30,7 @@ #include <com/sun/star/frame/XFrame.hpp> #include <svx/SvxColorValueSet.hxx> #include <svx/PaletteManager.hxx> +#include <vcl/combobox.hxx> // class SvxColorWindow_Impl -------------------------------------------------- @@ -42,22 +43,19 @@ class SvxColorWindow_Impl : public SfxPopupWindow private: const sal_uInt16 theSlotId; SvxColorValueSet aColorSet; - PushButton aButtonLeft; - PushButton aButtonRight; + ComboBox aPaletteComboBox; PushButton aButtonPicker; - FixedText aPaletteName; OUString maCommand; Link maSelectedLink; - const sal_uInt16 nNavButtonWidth; - const sal_uInt16 nNavButtonHeight; + const sal_uInt16 nButtonWidth; + const sal_uInt16 nButtonHeight; PaletteManager& mrPaletteManager; void UpdateGUI(); DECL_LINK( SelectHdl, void * ); - DECL_LINK( StepLeftClickHdl, void * ); - DECL_LINK( StepRightClickHdl, void * ); + DECL_LINK( SelectPaletteHdl, void *); DECL_LINK( OpenPickerClickHdl, void * ); protected: diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index b3360a545d88..f75c049450cc 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -1025,13 +1025,11 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, SfxPopupWindow( nSlotId, rFrame, pParentWindow, WinBits( WB_STDPOPUP | WB_OWNERDRAWDECORATION ) ), theSlotId( nSlotId ), aColorSet ( this, WinBits( WB_ITEMBORDER | WB_NAMEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT) ), - aButtonLeft ( this ), - aButtonRight( this ), + aPaletteComboBox( this, WinBits( WB_BORDER | WB_DROPDOWN | WB_AUTOSIZE) ), aButtonPicker( this ), - aPaletteName( this ), maCommand( rCommand ), - nNavButtonWidth ( 20 ), - nNavButtonHeight( 20 ), + nButtonWidth ( 28 ), + nButtonHeight( 28 ), mrPaletteManager( rPaletteManager ) { @@ -1066,22 +1064,21 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, aColorSet.SetAccessibleName( SVX_RESSTR( RID_SVXSTR_LINECOLOR ) ); } - aButtonLeft.SetText("<"); - aButtonLeft.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight)); - aButtonLeft.SetClickHdl( LINK( this, SvxColorWindow_Impl, StepLeftClickHdl ) ); - aButtonLeft.Show(); - - aButtonRight.SetText(">"); - aButtonRight.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight)); - aButtonRight.SetClickHdl( LINK( this, SvxColorWindow_Impl, StepRightClickHdl ) ); - aButtonRight.Show(); + aPaletteComboBox.SetSelectHdl( LINK( this, SvxColorWindow_Impl, SelectPaletteHdl ) ); + aPaletteComboBox.AdaptDropDownLineCountToMaximum(); + aPaletteComboBox.Show(); + std::vector<OUString> aPaletteList = mrPaletteManager.GetPaletteList(); + for( std::vector<OUString>::iterator it = aPaletteList.begin(); it != aPaletteList.end(); ++it ) + { + aPaletteComboBox.InsertEntry( *it ); + } + aPaletteComboBox.SetText( aPaletteList[ mrPaletteManager.GetPalette() ] ); aButtonPicker.SetText("P"); - aButtonPicker.SetSizePixel(Size(nNavButtonWidth, nNavButtonHeight)); + aButtonPicker.SetSizePixel(Size(nButtonWidth, nButtonHeight)); aButtonPicker.SetClickHdl( LINK( this, SvxColorWindow_Impl, OpenPickerClickHdl ) ); aButtonPicker.Show(); - aPaletteName.SetSizePixel(Size(150, nNavButtonHeight)); aColorSet.Show(); aColorSet.SetSelectHdl( LINK( this, SvxColorWindow_Impl, SelectHdl ) ); @@ -1089,8 +1086,6 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, aColorSet.SetHelpId( HID_POPUP_COLOR_CTRL ); SetText( rWndTitle ); - aPaletteName.Show(); - AddStatusListener( OUString( ".uno:ColorTableState" )); AddStatusListener( maCommand ); @@ -1107,16 +1102,13 @@ void SvxColorWindow_Impl::UpdateGUI() static sal_Int32 nAdd = 4; //TODO: Move left/right buttons above the colors - SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd + nNavButtonHeight)); - - aButtonLeft.SetPosPixel(Point(0, aNewSize.Height() + nAdd + 1)); + SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd + nButtonHeight)); - aButtonRight.SetPosPixel(Point(aNewSize.Width() + nAdd - nNavButtonWidth, aNewSize.Height() + nAdd + 1)); + aPaletteComboBox.SetPosPixel(Point(0, aNewSize.Height() + nAdd + 1)); - aButtonPicker.SetPosPixel(Point(aNewSize.Width() + nAdd - 2 * nNavButtonWidth, aNewSize.Height() + nAdd + 1)); + aButtonPicker.SetPosPixel(Point(aNewSize.Width() + nAdd - nButtonWidth, aNewSize.Height() + nAdd + 1)); - aPaletteName.SetPosPixel(Point(nNavButtonWidth, aNewSize.Height() + nAdd + 1)); - aPaletteName.SetText(mrPaletteManager.GetPaletteName()); + aPaletteComboBox.SetSizePixel(Size(aNewSize.Width() - nButtonWidth, nButtonHeight)); } SvxColorWindow_Impl::~SvxColorWindow_Impl() @@ -1170,16 +1162,11 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectHdl) return 0; } -IMPL_LINK_NOARG(SvxColorWindow_Impl, StepLeftClickHdl) -{ - mrPaletteManager.PrevPalette(); - UpdateGUI(); - return 0; -} - -IMPL_LINK_NOARG(SvxColorWindow_Impl, StepRightClickHdl) +IMPL_LINK_NOARG(SvxColorWindow_Impl, SelectPaletteHdl) { - mrPaletteManager.NextPalette(); + OUString sSrchTxt = aPaletteComboBox.GetText(); + sal_Int32 nPos = aPaletteComboBox.GetEntryPos( sSrchTxt ); + mrPaletteManager.SetPalette( nPos ); UpdateGUI(); return 0; } @@ -1192,7 +1179,7 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, OpenPickerClickHdl) void SvxColorWindow_Impl::Resize() { - lcl_ResizeValueSet( *this, aColorSet, nNavButtonHeight + 2); + lcl_ResizeValueSet( *this, aColorSet, nButtonHeight + 2); } void SvxColorWindow_Impl::StartSelection() |