diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-06-18 21:30:10 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-06-20 12:41:53 +0200 |
commit | 1f8d45c276760a173c3e30c78b8b740414a5b05f (patch) | |
tree | 4e22f39b8515a1839c9dc64146725ca02ec9b6f9 /svx | |
parent | 6e5e83025c948b699bb65839ef810a45a98ba014 (diff) |
weld SvxColorTabPage
Change-Id: I5dc6f949edcb34aa110dfa9415e2ac886d0dfa4c
Reviewed-on: https://gerrit.libreoffice.org/56111
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/inc/palettes.hxx | 3 | ||||
-rw-r--r-- | svx/source/dialog/hexcolorcontrol.cxx | 107 | ||||
-rw-r--r-- | svx/source/tbxctrls/Palette.cxx | 37 | ||||
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 52 | ||||
-rw-r--r-- | svx/source/tbxctrls/SvxColorValueSet.cxx | 52 |
5 files changed, 143 insertions, 108 deletions
diff --git a/svx/inc/palettes.hxx b/svx/inc/palettes.hxx index 8aa05b8fecfd..da0cdd24e9b2 100644 --- a/svx/inc/palettes.hxx +++ b/svx/inc/palettes.hxx @@ -42,6 +42,7 @@ public: virtual const OUString& GetName() override; virtual const OUString& GetPath() override; virtual void LoadColorSet( SvxColorValueSet& rColorSet ) override; + virtual void LoadColorSet( ColorValueSet& rColorSet ) override; virtual bool IsValid() override; }; @@ -67,6 +68,7 @@ public: virtual const OUString& GetName() override; virtual const OUString& GetPath() override; virtual void LoadColorSet( SvxColorValueSet& rColorSet ) override; + virtual void LoadColorSet( ColorValueSet& rColorSet ) override; virtual bool IsValid() override; }; @@ -86,6 +88,7 @@ public: virtual const OUString& GetName() override; virtual const OUString& GetPath() override; virtual void LoadColorSet( SvxColorValueSet& rColorSet ) override; + virtual void LoadColorSet( ColorValueSet& rColorSet ) override; virtual bool IsValid() override; }; diff --git a/svx/source/dialog/hexcolorcontrol.cxx b/svx/source/dialog/hexcolorcontrol.cxx index 51927caa5202..afb910712b9b 100644 --- a/svx/source/dialog/hexcolorcontrol.cxx +++ b/svx/source/dialog/hexcolorcontrol.cxx @@ -19,113 +19,6 @@ #include <svx/hexcolorcontrol.hxx> -HexColorControl::HexColorControl( vcl::Window* pParent, WinBits nStyle ) - : Edit(pParent, nStyle) -{ - SetMaxTextLen( 6 ); -} - -VCL_BUILDER_FACTORY_ARGS(HexColorControl, WB_BORDER) - -void HexColorControl::SetColor(Color nColor) -{ - OUStringBuffer aBuffer; - sax::Converter::convertColor(aBuffer, nColor); - SetText(aBuffer.makeStringAndClear().copy(1)); -} - -Color HexColorControl::GetColor() -{ - sal_Int32 nColor = -1; - - OUString aStr("#"); - aStr += GetText(); - sal_Int32 nLen = aStr.getLength(); - - if (nLen < 7) - { - static const sal_Char* const pNullStr = "000000"; - aStr += OUString::createFromAscii( &pNullStr[nLen-1] ); - } - - sax::Converter::convertColor(nColor, aStr); - - if (nColor == -1) - SetControlBackground(COL_RED); - else - SetControlBackground(); - - return Color(nColor); -} - -bool HexColorControl::PreNotify( NotifyEvent& rNEvt ) -{ - if ( (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) - { - if ( ImplProcessKeyInput( *rNEvt.GetKeyEvent() ) ) - return true; - } - - return Edit::PreNotify( rNEvt ); -} - -void HexColorControl::Paste() -{ - css::uno::Reference<css::datatransfer::clipboard::XClipboard> aClipboard(GetClipboard()); - if (aClipboard.is()) - { - css::uno::Reference<css::datatransfer::XTransferable> xDataObj; - - try - { - SolarMutexReleaser aReleaser; - xDataObj = aClipboard->getContents(); - } - catch (const css::uno::Exception&) - { - } - - if (xDataObj.is()) - { - css::datatransfer::DataFlavor aFlavor; - SotExchange::GetFormatDataFlavor(SotClipboardFormatId::STRING, aFlavor); - try - { - css::uno::Any aData = xDataObj->getTransferData(aFlavor); - OUString aText; - aData >>= aText; - - if( !aText.isEmpty() && aText.startsWith( "#" ) ) - aText = aText.copy(1); - - if( aText.getLength() > 6 ) - aText = aText.copy( 0, 6 ); - - SetText(aText); - } - catch(const css::uno::Exception&) - {} - } - } -} - -bool HexColorControl::ImplProcessKeyInput( const KeyEvent& rKEv ) -{ - const vcl::KeyCode& rKeyCode = rKEv.GetKeyCode(); - - if( rKeyCode.GetGroup() == KEYGROUP_ALPHA && !rKeyCode.IsMod1() && !rKeyCode.IsMod2() ) - { - if( (rKeyCode.GetCode() < KEY_A) || (rKeyCode.GetCode() > KEY_F) ) - return true; - } - else if( rKeyCode.GetGroup() == KEYGROUP_NUM ) - { - if( rKeyCode.IsShift() ) - return true; - } - return false; -} - namespace weld { HexColorControl::HexColorControl(weld::Entry* pEntry) diff --git a/svx/source/tbxctrls/Palette.cxx b/svx/source/tbxctrls/Palette.cxx index a5c12db487e1..6f90ec00e4f3 100644 --- a/svx/source/tbxctrls/Palette.cxx +++ b/svx/source/tbxctrls/Palette.cxx @@ -49,6 +49,17 @@ void PaletteASE::LoadColorSet( SvxColorValueSet& rColorSet ) } } +void PaletteASE::LoadColorSet( ColorValueSet& rColorSet ) +{ + rColorSet.Clear(); + int nIx = 1; + for (ColorList::const_iterator it = maColors.begin(); it != maColors.end(); ++it) + { + rColorSet.InsertItem(nIx, it->first, it->second); + ++nIx; + } +} + const OUString& PaletteASE::GetName() { return maASEPaletteName; @@ -210,6 +221,19 @@ void PaletteGPL::LoadColorSet( SvxColorValueSet& rColorSet ) } } +void PaletteGPL::LoadColorSet( ColorValueSet& rColorSet ) +{ + LoadPalette(); + + rColorSet.Clear(); + int nIx = 1; + for (ColorList::const_iterator it = maColors.begin(); it != maColors.end(); ++it) + { + rColorSet.InsertItem(nIx, it->first, it->second); + ++nIx; + } +} + bool PaletteGPL::IsValid() { return mbValidPalette; @@ -356,6 +380,19 @@ void PaletteSOC::LoadColorSet( SvxColorValueSet& rColorSet ) rColorSet.addEntriesForXColorList( *mpColorList ); } +void PaletteSOC::LoadColorSet( ColorValueSet& rColorSet ) +{ + if( !mbLoadedPalette ) + { + mbLoadedPalette = true; + mpColorList = XPropertyList::AsColorList(XPropertyList::CreatePropertyListFromURL(XPropertyListType::Color, maFPath)); + (void)mpColorList->Load(); + } + rColorSet.Clear(); + if( mpColorList.is() ) + rColorSet.addEntriesForXColorList( *mpColorList ); +} + bool PaletteSOC::IsValid() { return true; diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index ddd952cf6cb2..48bd555893ee 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -155,6 +155,40 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) } } +void PaletteManager::ReloadColorSet(ColorValueSet &rColorSet) +{ + if( mnCurrentPalette == 0) + { + rColorSet.Clear(); + css::uno::Sequence< sal_Int32 > CustomColorList( officecfg::Office::Common::UserColors::CustomColor::get() ); + css::uno::Sequence< OUString > CustomColorNameList( officecfg::Office::Common::UserColors::CustomColorName::get() ); + int nIx = 1; + for (int i = 0; i < CustomColorList.getLength(); ++i) + { + Color aColor(CustomColorList[i]); + rColorSet.InsertItem(nIx, aColor, CustomColorNameList[i]); + ++nIx; + } + } + else if( mnCurrentPalette == mnNumOfPalettes - 1 ) + { + // Add doc colors to palette + SfxObjectShell* pDocSh = SfxObjectShell::Current(); + if (pDocSh) + { + std::set<Color> aColors = pDocSh->GetDocColors(); + mnColorCount = aColors.size(); + rColorSet.Clear(); + rColorSet.addEntriesForColorSet(aColors, SvxResId( RID_SVXSTR_DOC_COLOR_PREFIX ) + " " ); + } + } + else + { + m_Palettes[mnCurrentPalette - 1]->LoadColorSet( rColorSet ); + mnColorCount = rColorSet.GetItemCount(); + } +} + void PaletteManager::ReloadRecentColorSet(SvxColorValueSet& rColorSet) { maRecentColors.clear(); @@ -173,6 +207,24 @@ void PaletteManager::ReloadRecentColorSet(SvxColorValueSet& rColorSet) } } +void PaletteManager::ReloadRecentColorSet(ColorValueSet& rColorSet) +{ + maRecentColors.clear(); + rColorSet.Clear(); + css::uno::Sequence< sal_Int32 > Colorlist(officecfg::Office::Common::UserColors::RecentColor::get()); + css::uno::Sequence< OUString > ColorNamelist(officecfg::Office::Common::UserColors::RecentColorName::get()); + int nIx = 1; + const bool bHasColorNames = Colorlist.getLength() == ColorNamelist.getLength(); + for (int i = 0; i < Colorlist.getLength(); ++i) + { + Color aColor(Colorlist[i]); + OUString sColorName = bHasColorNames ? ColorNamelist[i] : ("#" + aColor.AsRGBHexString().toAsciiUpperCase()); + maRecentColors.emplace_back(aColor, sColorName); + rColorSet.InsertItem(nIx, aColor, sColorName); + ++nIx; + } +} + std::vector<OUString> PaletteManager::GetPaletteList() { std::vector<OUString> aPaletteNames; diff --git a/svx/source/tbxctrls/SvxColorValueSet.cxx b/svx/source/tbxctrls/SvxColorValueSet.cxx index 62e2dc8a596e..d7622100677a 100644 --- a/svx/source/tbxctrls/SvxColorValueSet.cxx +++ b/svx/source/tbxctrls/SvxColorValueSet.cxx @@ -29,7 +29,8 @@ SvxColorValueSet::SvxColorValueSet(vcl::Window* _pParent, WinBits nWinStyle) SetEdgeBlending(true); } -ColorValueSet::ColorValueSet() +ColorValueSet::ColorValueSet(weld::ScrolledWindow* pWindow) + : SvtValueSet(pWindow) { SetEdgeBlending(true); } @@ -95,6 +96,27 @@ void ColorValueSet::addEntriesForXColorList(const XColorList& rXColorList, sal_u } } +void ColorValueSet::addEntriesForColorSet(const std::set<Color>& rColorSet, const OUString& rNamePrefix) +{ + sal_uInt32 nStartIndex = 1; + if(rNamePrefix.getLength() != 0) + { + for(std::set<Color>::const_iterator it = rColorSet.begin(); + it != rColorSet.end(); ++it, nStartIndex++) + { + InsertItem(nStartIndex, *it, rNamePrefix + OUString::number(nStartIndex)); + } + } + else + { + for(std::set<Color>::const_iterator it = rColorSet.begin(); + it != rColorSet.end(); ++it, nStartIndex++) + { + InsertItem(nStartIndex, *it, ""); + } + } +} + void SvxColorValueSet::addEntriesForColorSet(const std::set<Color>& rColorSet, const OUString& rNamePrefix) { sal_uInt32 nStartIndex = 1; @@ -116,6 +138,34 @@ void SvxColorValueSet::addEntriesForColorSet(const std::set<Color>& rColorSet, c } } +Size ColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount) +{ + if(!nEntryCount) + { + nEntryCount++; + } + + const sal_uInt32 nRowCount(ceil(double(nEntryCount)/SvxColorValueSet::getColumnCount())); + const Size aItemSize(SvxColorValueSet::getEntryEdgeLength() - 2, SvxColorValueSet::getEntryEdgeLength() - 2); + const WinBits aWinBits(GetStyle() & ~WB_VSCROLL); + + if (nRowCount > SvxColorValueSet::getMaxRowCount()) + { + SetStyle(aWinBits|WB_VSCROLL); + } + else + { + SetStyle(aWinBits); + } + + SetColCount(SvxColorValueSet::getColumnCount()); + SetLineCount(std::min(nRowCount, SvxColorValueSet::getMaxRowCount())); + SetItemWidth(aItemSize.Width()); + SetItemHeight(aItemSize.Height()); + + return CalcWindowSizePixel(aItemSize); +} + Size SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount) { if(!nEntryCount) |