diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-03-08 12:17:56 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-03-11 21:34:45 +0100 |
commit | cf4b65c75c07142be0fcab5835188a28e839b749 (patch) | |
tree | 41b2bd5cd5d419f33db3839c93b9e674a193c2c1 /svx | |
parent | e0e307675cc2b962d0dcb557f4af4a34a729da66 (diff) |
weld color picker
Change-Id: I487b9a0cc13b2b60a0f1e28667773b5d3b5c66cc
Reviewed-on: https://gerrit.libreoffice.org/51001
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/dialog/hexcolorcontrol.cxx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/svx/source/dialog/hexcolorcontrol.cxx b/svx/source/dialog/hexcolorcontrol.cxx index 61d38bdeb619..51927caa5202 100644 --- a/svx/source/dialog/hexcolorcontrol.cxx +++ b/svx/source/dialog/hexcolorcontrol.cxx @@ -126,4 +126,67 @@ bool HexColorControl::ImplProcessKeyInput( const KeyEvent& rKEv ) return false; } +namespace weld { + +HexColorControl::HexColorControl(weld::Entry* pEntry) + : m_xEntry(pEntry) +{ + m_xEntry->set_max_length(6); + m_xEntry->set_width_chars(6); + m_xEntry->connect_insert_text(LINK(this, HexColorControl, ImplProcessInputHdl)); +} + +void HexColorControl::SetColor(Color nColor) +{ + OUStringBuffer aBuffer; + sax::Converter::convertColor(aBuffer, nColor); + m_xEntry->set_text(aBuffer.makeStringAndClear().copy(1)); +} + +Color HexColorControl::GetColor() +{ + sal_Int32 nColor = -1; + + OUString aStr("#"); + aStr += m_xEntry->get_text(); + 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 0 + if (nColor == -1) + SetControlBackground(COL_RED); + else + SetControlBackground(); +#endif + + return Color(nColor); +} + +IMPL_LINK(HexColorControl, ImplProcessInputHdl, OUString&, rTest, bool) +{ + const sal_Unicode* pTest = rTest.getStr(); + sal_Int32 nLen = rTest.getLength(); + + OUStringBuffer aFilter(nLen); + for (sal_Int32 i = 0; i < nLen; ++i) + { + if (rtl::isAsciiHexDigit(*pTest)) + aFilter.append(*pTest); + ++pTest; + } + + rTest = aFilter.makeStringAndClear(); + return true; +} + + +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |