summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRishabh Kumar <kris.kr296@gmail.com>2016-06-01 01:31:53 +0530
committerKatarina Behrens <Katarina.Behrens@cib.de>2016-06-01 15:35:40 +0000
commit00fbca564251368da34caaceb719164e34764e10 (patch)
tree828aa9c164cf133a7d13b823ae508ebf141d3c86
parent5d78d488fd16fc7403c68cb42330e561ea30046c (diff)
Make class HexColorControl global
Change-Id: I755e5aab5425d5d136d5fe7c75706a93cf4559ae Reviewed-on: https://gerrit.libreoffice.org/25665 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
-rw-r--r--cui/source/dialogs/colorpicker.cxx123
-rw-r--r--include/svx/hexcolorcontrol.hxx50
-rw-r--r--svx/Library_svxcore.mk1
-rw-r--r--svx/source/dialog/hexcolorcontrol.cxx129
4 files changed, 181 insertions, 122 deletions
diff --git a/cui/source/dialogs/colorpicker.cxx b/cui/source/dialogs/colorpicker.cxx
index 7ba386e1c876..1cc7782477bd 100644
--- a/cui/source/dialogs/colorpicker.cxx
+++ b/cui/source/dialogs/colorpicker.cxx
@@ -40,6 +40,7 @@
#include <toolkit/helper/vclunohelper.hxx>
#include <sot/exchange.hxx>
#include <sot/formats.hxx>
+#include <svx/hexcolorcontrol.hxx>
#include <sax/tools/converter.hxx>
#include <basegfx/color/bcolortools.hxx>
#include "dialmgr.hxx"
@@ -131,128 +132,6 @@ static void RGBtoCMYK( double dR, double dG, double dB, double& fCyan, double& f
}
}
-class HexColorControl : public Edit
-{
-public:
- HexColorControl( vcl::Window* pParent, WinBits nStyle );
-
- virtual bool PreNotify( NotifyEvent& rNEvt ) override;
- virtual void Paste() override;
-
- void SetColor( sal_Int32 nColor );
- sal_Int32 GetColor();
-
-private:
- static bool ImplProcessKeyInput( const KeyEvent& rKEv );
-};
-
-HexColorControl::HexColorControl( vcl::Window* pParent, WinBits nStyle )
- : Edit(pParent, nStyle)
-{
- SetMaxTextLen( 6 );
-}
-
-VCL_BUILDER_FACTORY_ARGS(HexColorControl, WB_BORDER)
-
-void HexColorControl::SetColor(sal_Int32 nColor)
-{
- OUStringBuffer aBuffer;
- sax::Converter::convertColor(aBuffer, nColor);
- SetText(aBuffer.makeStringAndClear().copy(1));
-}
-
-sal_Int32 HexColorControl::GetColor()
-{
- sal_Int32 nColor = -1;
-
- OUString aStr("#");
- aStr += GetText();
- sal_Int32 nLen = aStr.getLength();
-
- if (nLen < 7)
- {
- static const sal_Char* pNullStr = "000000";
- aStr += OUString::createFromAscii( &pNullStr[nLen-1] );
- }
-
- sax::Converter::convertColor(nColor, aStr);
-
- if (nColor == -1)
- SetControlBackground(Color(COL_RED));
- else
- SetControlBackground();
-
- return 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;
-}
-
class ColorPreviewControl : public Control
{
public:
diff --git a/include/svx/hexcolorcontrol.hxx b/include/svx/hexcolorcontrol.hxx
new file mode 100644
index 000000000000..a9f9661e5e40
--- /dev/null
+++ b/include/svx/hexcolorcontrol.hxx
@@ -0,0 +1,50 @@
+/* -*- 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_HEXCOLOR_HXX
+#define INCLUDED_SVX_HEXCOLOR_HXX
+
+#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <vcl/dialog.hxx>
+#include <vcl/edit.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/builderfactory.hxx>
+#include <sot/exchange.hxx>
+#include <sax/tools/converter.hxx>
+#include <svx/svxdllapi.h>
+
+class SVX_DLLPUBLIC HexColorControl : public Edit
+{
+public:
+ HexColorControl( vcl::Window* pParent, WinBits nStyle );
+
+ virtual bool PreNotify( NotifyEvent& rNEvt ) override;
+ virtual void Paste() override;
+
+ void SetColor( sal_Int32 nColor );
+ sal_Int32 GetColor();
+
+private:
+ static bool ImplProcessKeyInput( const KeyEvent& rKEv );
+};
+
+#endif // INCLUDED_SVX_HEXCOLOR_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 40db4078077d..dc9a483be01c 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -115,6 +115,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/dialog/checklbx \
svx/source/dialog/dialmgr \
svx/source/dialog/dlgutil \
+ svx/source/dialog/hexcolorcontrol \
svx/source/dialog/framelink \
svx/source/dialog/langbox \
svx/source/dialog/stddlg \
diff --git a/svx/source/dialog/hexcolorcontrol.cxx b/svx/source/dialog/hexcolorcontrol.cxx
new file mode 100644
index 000000000000..5cf5db04eafb
--- /dev/null
+++ b/svx/source/dialog/hexcolorcontrol.cxx
@@ -0,0 +1,129 @@
+/* -*- 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/hexcolorcontrol.hxx>
+
+HexColorControl::HexColorControl( vcl::Window* pParent, WinBits nStyle )
+ : Edit(pParent, nStyle)
+{
+ SetMaxTextLen( 6 );
+}
+
+VCL_BUILDER_FACTORY_ARGS(HexColorControl, WB_BORDER)
+
+void HexColorControl::SetColor(sal_Int32 nColor)
+{
+ OUStringBuffer aBuffer;
+ sax::Converter::convertColor(aBuffer, nColor);
+ SetText(aBuffer.makeStringAndClear().copy(1));
+}
+
+sal_Int32 HexColorControl::GetColor()
+{
+ sal_Int32 nColor = -1;
+
+ OUString aStr("#");
+ aStr += GetText();
+ sal_Int32 nLen = aStr.getLength();
+
+ if (nLen < 7)
+ {
+ static const sal_Char* pNullStr = "000000";
+ aStr += OUString::createFromAscii( &pNullStr[nLen-1] );
+ }
+
+ sax::Converter::convertColor(nColor, aStr);
+
+ if (nColor == -1)
+ SetControlBackground(Color(COL_RED));
+ else
+ SetControlBackground();
+
+ return 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;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */