summaryrefslogtreecommitdiff
path: root/svx/source
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2011-09-30 19:43:09 +0200
committerStephan Bergmann <sbergman@redhat.com>2011-09-30 19:43:09 +0200
commitcce442bc139b93ec4263173d26cdd94dbbf5f3b0 (patch)
tree3389ffab5191681c4fef9d88dbd0114134e59c2b /svx/source
parentc35ad52639b3a1f79fa9ec884096a4a0f65bb973 (diff)
Cleaned up DGColorNameLookUp.
Diffstat (limited to 'svx/source')
-rw-r--r--svx/source/accessibility/DescriptionGenerator.cxx4
-rw-r--r--svx/source/accessibility/lookupcolorname.cxx (renamed from svx/source/accessibility/DGColorNameLookUp.cxx)114
-rw-r--r--svx/source/accessibility/lookupcolorname.hxx66
-rw-r--r--svx/source/inc/DGColorNameLookUp.hxx92
4 files changed, 122 insertions, 154 deletions
diff --git a/svx/source/accessibility/DescriptionGenerator.cxx b/svx/source/accessibility/DescriptionGenerator.cxx
index 4d0dc1d884c2..b98799e6b261 100644
--- a/svx/source/accessibility/DescriptionGenerator.cxx
+++ b/svx/source/accessibility/DescriptionGenerator.cxx
@@ -58,7 +58,7 @@
#include <svx/xdef.hxx>
#include "svx/unoapi.hxx"
#include "accessibility.hrc"
-#include "DGColorNameLookUp.hxx"
+#include "lookupcolorname.hxx"
using namespace ::rtl;
using namespace ::com::sun::star;
@@ -291,7 +291,7 @@ void DescriptionGenerator::AddColor (const OUString& sPropertyName,
aValue >>= nValue;
}
- msDescription.append (DGColorNameLookUp::Instance().LookUpColor (nValue));
+ msDescription.append (lookUpColorName(nValue));
}
catch (::com::sun::star::beans::UnknownPropertyException)
{
diff --git a/svx/source/accessibility/DGColorNameLookUp.cxx b/svx/source/accessibility/lookupcolorname.cxx
index ca673015bc62..6a03ac3d314b 100644
--- a/svx/source/accessibility/DGColorNameLookUp.cxx
+++ b/svx/source/accessibility/lookupcolorname.cxx
@@ -26,73 +26,53 @@
*
************************************************************************/
-// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
-#include "DGColorNameLookUp.hxx"
-#include <com/sun/star/container/XNameContainer.hpp>
-#include <com/sun/star/container/XNameAccess.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <comphelper/processfactory.hxx>
-#include <osl/mutex.hxx>
-#include <vcl/svapp.hxx>
+#include "sal/config.h"
+#include "boost/noncopyable.hpp"
+#include "boost/unordered_map.hpp"
+#include "com/sun/star/container/XNameAccess.hpp"
+#include "com/sun/star/container/XNameContainer.hpp"
+#include "com/sun/star/lang/XMultiServiceFactory.hpp"
+#include "com/sun/star/uno/Any.hxx"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "comphelper/processfactory.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+#include "vcl/svapp.hxx"
-using ::rtl::OUString;
-using namespace ::com::sun::star;
+namespace {
-namespace accessibility {
-
-namespace
-{
- class theDGColorNameLookUp
- : public rtl::Static< DGColorNameLookUp, theDGColorNameLookUp >
- {
- };
-}
+namespace css = com::sun::star;
-DGColorNameLookUp& DGColorNameLookUp::Instance()
-{
- return theDGColorNameLookUp::get();
-}
+class ColorNameMap: private boost::noncopyable {
+public:
+ ColorNameMap();
-OUString DGColorNameLookUp::LookUpColor (long int nColor) const
-{
- OUString sColorName;
- tColorValueToNameMap::const_iterator I;
- I = maColorValueToNameMap.find (nColor);
- if (I != maColorValueToNameMap.end())
- // Found the color value. Return the associated name.
- sColorName = I->second;
- else
- {
- // Did not find the given color. Append its rgb tuple to the
- // description.
- ::rtl::OUStringBuffer sNameBuffer;
- sNameBuffer.append (sal_Unicode('#'));
- sNameBuffer.append (nColor, 16);
- sColorName = sNameBuffer.makeStringAndClear();
- }
- return sColorName;
-}
+ rtl::OUString lookUp(long color) const;
+private:
+ typedef boost::unordered_map< long, rtl::OUString > Map;
+ Map map_;
+};
-
-DGColorNameLookUp::DGColorNameLookUp()
-{
- uno::Sequence<OUString> aNames;
- uno::Reference<container::XNameAccess> xNA;
+ColorNameMap::ColorNameMap() {
+ css::uno::Sequence< rtl::OUString > aNames;
+ css::uno::Reference< css::container::XNameAccess > xNA;
try
{
// Create color table in which to look up the given color.
- uno::Reference<container::XNameContainer> xColorTable (
- ::comphelper::getProcessServiceFactory()->createInstance(
- OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ColorTable")) ),
- uno::UNO_QUERY);
+ css::uno::Reference< css::container::XNameContainer > xColorTable (
+ comphelper::getProcessServiceFactory()->createInstance(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ColorTable")) ),
+ css::uno::UNO_QUERY);
// Get list of color names in order to iterate over the color table.
- xNA = uno::Reference<container::XNameAccess>(xColorTable, uno::UNO_QUERY);
+ xNA = css::uno::Reference< css::container::XNameAccess >(xColorTable, css::uno::UNO_QUERY);
if (xNA.is())
{
// Look the solar mutex here as workarround for missing lock in
@@ -101,7 +81,7 @@ DGColorNameLookUp::DGColorNameLookUp()
aNames = xNA->getElementNames();
}
}
- catch (uno::RuntimeException const&)
+ catch (css::uno::RuntimeException const&)
{
// When an exception occurred then whe have an empty name sequence
// and the loop below is not entered.
@@ -114,12 +94,12 @@ DGColorNameLookUp::DGColorNameLookUp()
// Get the numerical value for the i-th color name.
try
{
- uno::Any aColor (xNA->getByName (aNames[i]));
+ css::uno::Any aColor (xNA->getByName (aNames[i]));
long nColor = 0;
aColor >>= nColor;
- maColorValueToNameMap[nColor] = aNames[i];
+ map_[nColor] = aNames[i];
}
- catch (uno::RuntimeException const&)
+ catch (css::uno::RuntimeException const&)
{
// Ignore the exception: the color who lead to the exception
// is not included into the map.
@@ -127,14 +107,28 @@ DGColorNameLookUp::DGColorNameLookUp()
}
}
+rtl::OUString ColorNameMap::lookUp(long color) const {
+ Map::const_iterator i(map_.find(color));
+ if (i != map_.end()) {
+ return i->second;
+ }
+ // Did not find the given color; return its RGB tuple representation:
+ rtl::OUStringBuffer buf;
+ buf.append(sal_Unicode('#'));
+ buf.append(color, 16);
+ return buf.makeStringAndClear();
+}
+struct theColorNameMap: public rtl::Static< ColorNameMap, theColorNameMap > {};
+}
-DGColorNameLookUp::~DGColorNameLookUp()
-{
- maColorValueToNameMap.clear();
+namespace accessibility {
+
+rtl::OUString lookUpColorName(long color) {
+ return theColorNameMap::get().lookUp(color);
}
-} // end of namespace accessibility
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/accessibility/lookupcolorname.hxx b/svx/source/accessibility/lookupcolorname.hxx
new file mode 100644
index 000000000000..92000e0322d8
--- /dev/null
+++ b/svx/source/accessibility/lookupcolorname.hxx
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_SVX_SOURCE_ACCESSIBILITY_LOOKUPCOLORNAME_HXX
+#define INCLUDED_SVX_SOURCE_ACCESSIBILITY_LOOKUPCOLORNAME_HXX
+
+#include "sal/config.h"
+
+namespace rtl { class OUString; }
+
+namespace accessibility {
+
+/** This is a color name lookup targeted to be used by the accessibility
+ <type>DescriptionGenerator</type> class. It encapsulates a
+ <type>com.sun.star.drawing.ColorTable</type> and provides an inverse look
+ up of color names for given numerical color descriptions (the RGB values
+ encoded as an integer).
+
+ <p>The implementation uses as singleton so that the
+ <type>com.sun.star.drawing.ColorTable</type> object needs to be created
+ only once. That singleton instance for now lives until the application
+ terminates. However, the color table from which it takes its values may
+ change during this time. Reacting to these changes remains a task for the
+ future.</p>
+
+ @param nColor
+ This integer is the sum of the 8 Bit red value shifted left 16 Bits, the
+ green value shifted left 8 Bits, and the unshifted blue value.
+
+ @return
+ The returned string is either the color name of the specified color or,
+ when no name exists, a string of the form "#RRGGBB" with two hexadecimal
+ digits for each color component.
+*/
+rtl::OUString lookUpColorName(long color);
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/inc/DGColorNameLookUp.hxx b/svx/source/inc/DGColorNameLookUp.hxx
deleted file mode 100644
index 0b0068d3a8dc..000000000000
--- a/svx/source/inc/DGColorNameLookUp.hxx
+++ /dev/null
@@ -1,92 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef _SVX_ACCESSIBILITY_DG_COLOR_NAME_LOOK_UP_HXX
-#define _SVX_ACCESSIBILITY_DG_COLOR_NAME_LOOK_UP_HXX
-
-#include <rtl/ustrbuf.hxx>
-#include <rtl/instance.hxx>
-#include <boost/unordered_map.hpp>
-#include <boost/noncopyable.hpp>
-
-namespace accessibility {
-
-/** This is a color name lookup targeted to be used by the accessibility
- <type>DescriptionGenerator</type> class (hence the DG prefix). It
- encapsulates a <type>com.sun.star.drawing.ColorTable</type> and provides
- an inverse look up of color names for given a numerical color
- descriptions--the RGB values encoded as integer.
-
- <p>The class itself is designed as singleton so that the
- <type>com.sun.star.drawing.ColorTable</type> object needs to be created
- only once.</p>
-
- <p>The singleton instance of this class lives at the moment until the
- application terminates. However, the color table from which it takes
- its values may change during this time. Reacting to these changes
- remains a task for the future.</p>
-*/
-class DGColorNameLookUp : private ::boost::noncopyable
-{
-public:
- /** Return the single instance of this class. Use this to look up
- color names with the <member>LookUpColor()</member> method.
- */
- static DGColorNameLookUp& Instance();
-
- /** Return the color name of the color expressed by the given integer.
- @param nColor
- This integer is the sum of the 8 Bit red value shifted left 16
- Bits, the green value shifted left 8 Bits, and the unshifted
- blue value.
- @return
- The returned string is either the color name of the specified
- color or, when no name exists, a string of the form "#RRGGBB"
- with two hexadecimal digits for each color component.
- */
- ::rtl::OUString LookUpColor (long int nColor) const;
-
-private:
- /// Define hash map type to convert numerical color values to names.
- typedef boost::unordered_map<long int, ::rtl::OUString>
- tColorValueToNameMap;
-
- /// This ma translates from numerical color values to names.
- tColorValueToNameMap maColorValueToNameMap;
-
-public:
- /// Can only construct via singleton
- DGColorNameLookUp();
- ~DGColorNameLookUp();
-};
-
-} // end of namespace accessibility
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */