2014-07-03 18:47:10 +02:00
|
|
|
/* -*- 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>
|
2014-07-30 17:15:49 +02:00
|
|
|
#include <svx/drawitem.hxx>
|
2014-07-03 18:47:10 +02:00
|
|
|
#include <svx/dialogs.hrc>
|
2014-07-08 19:08:38 +02:00
|
|
|
#include <svtools/colrdlg.hxx>
|
2014-10-28 21:09:16 +02:00
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <vcl/settings.hxx>
|
2014-07-03 18:47:10 +02:00
|
|
|
|
2014-07-10 16:14:29 +02:00
|
|
|
#define STR_DEFAULT_PAL "Default palette"
|
|
|
|
#define STR_DOC_COLORS "Document colors"
|
|
|
|
#define STR_DOC_COLOR_PREFIX "Document Color "
|
|
|
|
|
2014-07-03 18:47:10 +02:00
|
|
|
PaletteManager::PaletteManager() :
|
2014-10-28 21:09:16 +02:00
|
|
|
mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()),
|
2014-07-03 18:47:10 +02:00
|
|
|
mnNumOfPalettes(2),
|
|
|
|
mnCurrentPalette(0),
|
2014-07-08 19:08:38 +02:00
|
|
|
mnColorCount(0),
|
2014-09-25 11:42:04 +01:00
|
|
|
mpBtnUpdater(NULL),
|
2014-07-08 19:08:38 +02:00
|
|
|
mLastColor(COL_AUTO)
|
2014-07-03 18:47:10 +02:00
|
|
|
{
|
|
|
|
LoadPalettes();
|
|
|
|
mnNumOfPalettes += maPalettes.size();
|
|
|
|
}
|
|
|
|
|
2014-07-25 16:45:13 +02:00
|
|
|
PaletteManager::~PaletteManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-03 18:47:10 +02:00
|
|
|
void PaletteManager::LoadPalettes()
|
|
|
|
{
|
2014-07-30 19:45:37 +02:00
|
|
|
maPalettes.clear();
|
2014-07-03 18:47:10 +02:00
|
|
|
OUString aPalPath = SvtPathOptions().GetPalettePath();
|
|
|
|
|
|
|
|
osl::Directory aDir(aPalPath);
|
|
|
|
osl::DirectoryItem aDirItem;
|
2014-07-10 16:14:29 +02:00
|
|
|
osl::FileStatus aFileStat( osl_FileStatus_Mask_FileName |
|
|
|
|
osl_FileStatus_Mask_FileURL |
|
|
|
|
osl_FileStatus_Mask_Type );
|
2014-07-03 18:47:10 +02:00
|
|
|
if( aDir.open() == osl::FileBase::E_None )
|
|
|
|
{
|
|
|
|
while( aDir.getNextItem(aDirItem) == osl::FileBase::E_None )
|
|
|
|
{
|
|
|
|
aDirItem.getFileStatus(aFileStat);
|
|
|
|
if(aFileStat.isRegular() || aFileStat.isLink())
|
|
|
|
{
|
2014-07-10 16:14:29 +02:00
|
|
|
OUString aFName = aFileStat.getFileName();
|
2014-07-25 16:45:13 +02:00
|
|
|
Palette* pPalette = 0;
|
2014-07-10 16:14:29 +02:00
|
|
|
if( aFName.endsWithIgnoreAsciiCase(".gpl") )
|
2014-07-25 16:45:13 +02:00
|
|
|
pPalette = new PaletteGPL( aFileStat.getFileURL(), aFName );
|
|
|
|
else if( aFName.endsWithIgnoreAsciiCase(".soc") )
|
|
|
|
pPalette = new PaletteSOC( aFileStat.getFileURL(), aFName );
|
|
|
|
|
|
|
|
if( pPalette && pPalette->IsValid() )
|
|
|
|
maPalettes.push_back( pPalette );
|
2014-07-03 18:47:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ) ) )
|
2014-10-17 12:22:22 +02:00
|
|
|
pColorList = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
|
2014-07-03 18:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2014-10-28 14:29:46 +02:00
|
|
|
rColorSet.addEntriesForColorVector(aColors, STR_DOC_COLOR_PREFIX );
|
2014-07-03 18:47:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-30 19:45:37 +02:00
|
|
|
maPalettes[mnCurrentPalette-1].LoadColorSet( rColorSet );
|
2014-07-25 16:45:13 +02:00
|
|
|
mnColorCount = rColorSet.GetItemCount();
|
2014-07-03 18:47:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 17:35:50 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 16:14:29 +02:00
|
|
|
std::vector<OUString> PaletteManager::GetPaletteList()
|
|
|
|
{
|
|
|
|
std::vector<OUString> aPaletteNames;
|
|
|
|
|
|
|
|
aPaletteNames.push_back( STR_DEFAULT_PAL );
|
|
|
|
|
2014-07-30 19:45:37 +02:00
|
|
|
for( boost::ptr_vector<Palette>::iterator it = maPalettes.begin();
|
2014-07-10 16:14:29 +02:00
|
|
|
it != maPalettes.end();
|
|
|
|
++it)
|
|
|
|
{
|
2014-07-30 19:45:37 +02:00
|
|
|
aPaletteNames.push_back( (*it).GetName() );
|
2014-07-10 16:14:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
aPaletteNames.push_back( STR_DOC_COLORS );
|
|
|
|
|
|
|
|
return aPaletteNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteManager::SetPalette( sal_Int32 nPos )
|
2014-07-03 18:47:10 +02:00
|
|
|
{
|
2014-07-10 16:14:29 +02:00
|
|
|
mnCurrentPalette = nPos;
|
2014-07-03 18:47:10 +02:00
|
|
|
}
|
|
|
|
|
2014-07-10 16:14:29 +02:00
|
|
|
sal_Int32 PaletteManager::GetPalette()
|
2014-07-03 18:47:10 +02:00
|
|
|
{
|
2014-07-10 16:14:29 +02:00
|
|
|
return mnCurrentPalette;
|
2014-07-03 18:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
long PaletteManager::GetColorCount()
|
|
|
|
{
|
|
|
|
return mnColorCount;
|
|
|
|
}
|
|
|
|
|
2014-08-11 17:35:50 +02:00
|
|
|
long PaletteManager::GetRecentColorCount()
|
|
|
|
{
|
|
|
|
return maRecentColors.size();
|
|
|
|
}
|
|
|
|
|
2014-07-08 19:08:38 +02:00
|
|
|
const Color& PaletteManager::GetLastColor()
|
|
|
|
{
|
|
|
|
return mLastColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaletteManager::SetLastColor(const Color& rLastColor)
|
|
|
|
{
|
|
|
|
mLastColor = rLastColor;
|
|
|
|
}
|
|
|
|
|
2014-08-11 17:35:50 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-07-08 19:08:38 +02:00
|
|
|
void PaletteManager::SetBtnUpdater(svx::ToolboxButtonColorUpdater* pBtnUpdater)
|
|
|
|
{
|
|
|
|
mpBtnUpdater = pBtnUpdater;
|
|
|
|
}
|
|
|
|
|
2014-09-17 18:58:05 +03:00
|
|
|
void PaletteManager::PopupColorPicker(const OUString& aCommand)
|
2014-07-08 19:08:38 +02:00
|
|
|
{
|
2014-10-19 16:24:55 +08:00
|
|
|
// The calling object goes away during aColorDlg.Execute(), so we must copy this
|
|
|
|
OUString aCommandCopy = aCommand;
|
2014-07-08 19:08:38 +02:00
|
|
|
SvColorDialog aColorDlg( 0 );
|
|
|
|
aColorDlg.SetColor ( mLastColor );
|
|
|
|
aColorDlg.SetMode( svtools::ColorPickerMode_MODIFY );
|
|
|
|
if( aColorDlg.Execute() == RET_OK )
|
|
|
|
{
|
2014-09-25 11:42:04 +01:00
|
|
|
if (mpBtnUpdater)
|
|
|
|
mpBtnUpdater->Update( aColorDlg.GetColor() );
|
2014-07-08 19:08:38 +02:00
|
|
|
mLastColor = aColorDlg.GetColor();
|
2014-08-11 17:35:50 +02:00
|
|
|
AddRecentColor( mLastColor );
|
2014-10-19 16:24:55 +08:00
|
|
|
DispatchColorCommand(aCommandCopy, mLastColor);
|
2014-07-30 17:15:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-17 18:58:05 +03:00
|
|
|
void PaletteManager::DispatchColorCommand(const OUString& aCommand, const Color aColor)
|
2014-07-30 17:15:49 +02:00
|
|
|
{
|
|
|
|
using namespace css::uno;
|
|
|
|
using namespace css::frame;
|
|
|
|
using namespace css::beans;
|
|
|
|
using namespace css::util;
|
|
|
|
|
|
|
|
Reference<XComponentContext> xContext(comphelper::getProcessComponentContext());
|
|
|
|
Reference<XDesktop2> xDesktop = Desktop::create(xContext);
|
|
|
|
Reference<XDispatchProvider> xDispatchProvider(xDesktop->getCurrentFrame(), UNO_QUERY );
|
|
|
|
if (xDispatchProvider.is())
|
|
|
|
{
|
|
|
|
INetURLObject aObj( aCommand );
|
|
|
|
|
|
|
|
Sequence<PropertyValue> aArgs(1);
|
|
|
|
aArgs[0].Name = aObj.GetURLPath();
|
|
|
|
aArgs[0].Value = makeAny(sal_Int32(aColor.GetColor()));
|
|
|
|
|
|
|
|
URL aTargetURL;
|
|
|
|
aTargetURL.Complete = aCommand;
|
|
|
|
Reference<XURLTransformer> xURLTransformer(URLTransformer::create(comphelper::getProcessComponentContext()));
|
|
|
|
xURLTransformer->parseStrict(aTargetURL);
|
|
|
|
|
|
|
|
Reference<XDispatch> xDispatch = xDispatchProvider->queryDispatch(aTargetURL, OUString(), 0);
|
|
|
|
if (xDispatch.is())
|
|
|
|
xDispatch->dispatch(aTargetURL, aArgs);
|
2014-07-08 19:08:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 18:47:10 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|