svx/Library_svx.mk | 6 svx/source/accessibility/DGColorNameLookUp.cxx | 140 ---------------------- svx/source/accessibility/DescriptionGenerator.cxx | 4 svx/source/accessibility/lookupcolorname.cxx | 134 +++++++++++++++++++++ svx/source/accessibility/lookupcolorname.hxx | 66 ++++++++++ svx/source/inc/DGColorNameLookUp.hxx | 92 -------------- 6 files changed, 205 insertions(+), 237 deletions(-)
New commits: commit cce442bc139b93ec4263173d26cdd94dbbf5f3b0 Author: Stephan Bergmann <[email protected]> Date: Fri Sep 30 19:43:09 2011 +0200 Cleaned up DGColorNameLookUp. diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index ddc8f58..3754d8b 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -85,15 +85,15 @@ $(eval $(call gb_Library_add_exception_objects,svx,\ svx/source/accessibility/AccessibleShapeTreeInfo \ svx/source/accessibility/AccessibleTextEventQueue \ svx/source/accessibility/AccessibleTextHelper \ - svx/source/accessibility/charmapacc \ svx/source/accessibility/ChildrenManager \ svx/source/accessibility/ChildrenManagerImpl \ svx/source/accessibility/DescriptionGenerator \ - svx/source/accessibility/DGColorNameLookUp \ svx/source/accessibility/GraphCtlAccessibleContext \ svx/source/accessibility/ShapeTypeHandler \ - svx/source/accessibility/svxrectctaccessiblecontext \ svx/source/accessibility/SvxShapeTypes \ + svx/source/accessibility/charmapacc \ + svx/source/accessibility/lookupcolorname \ + svx/source/accessibility/svxrectctaccessiblecontext \ svx/source/customshapes/EnhancedCustomShape3d \ svx/source/customshapes/EnhancedCustomShapeEngine \ svx/source/customshapes/EnhancedCustomShapeFontWork \ diff --git a/svx/source/accessibility/DGColorNameLookUp.cxx b/svx/source/accessibility/DGColorNameLookUp.cxx deleted file mode 100644 index ca67301..0000000 --- a/svx/source/accessibility/DGColorNameLookUp.cxx +++ /dev/null @@ -1,140 +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. - * - ************************************************************************/ - -// 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> - - -using ::rtl::OUString; -using namespace ::com::sun::star; - -namespace accessibility { - -namespace -{ - class theDGColorNameLookUp - : public rtl::Static< DGColorNameLookUp, theDGColorNameLookUp > - { - }; -} - -DGColorNameLookUp& DGColorNameLookUp::Instance() -{ - return theDGColorNameLookUp::get(); -} - -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; -} - - - - -DGColorNameLookUp::DGColorNameLookUp() -{ - uno::Sequence<OUString> aNames; - uno::Reference<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); - - // Get list of color names in order to iterate over the color table. - xNA = uno::Reference<container::XNameAccess>(xColorTable, uno::UNO_QUERY); - if (xNA.is()) - { - // Look the solar mutex here as workarround for missing lock in - // called function. - SolarMutexGuard aGuard; - aNames = xNA->getElementNames(); - } - } - catch (uno::RuntimeException const&) - { - // When an exception occurred then whe have an empty name sequence - // and the loop below is not entered. - } - - // Fill the map to convert from numerical color values to names. - if (xNA.is()) - for (long int i=0; i<aNames.getLength(); i++) - { - // Get the numerical value for the i-th color name. - try - { - uno::Any aColor (xNA->getByName (aNames[i])); - long nColor = 0; - aColor >>= nColor; - maColorValueToNameMap[nColor] = aNames[i]; - } - catch (uno::RuntimeException const&) - { - // Ignore the exception: the color who lead to the exception - // is not included into the map. - } - } -} - - - - -DGColorNameLookUp::~DGColorNameLookUp() -{ - maColorValueToNameMap.clear(); -} - -} // end of namespace accessibility - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/accessibility/DescriptionGenerator.cxx b/svx/source/accessibility/DescriptionGenerator.cxx index 4d0dc1d..b98799e 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/lookupcolorname.cxx b/svx/source/accessibility/lookupcolorname.cxx new file mode 100644 index 0000000..6a03ac3 --- /dev/null +++ b/svx/source/accessibility/lookupcolorname.cxx @@ -0,0 +1,134 @@ +/* -*- 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. + * + ************************************************************************/ + +#include "precompiled_svx.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" + +namespace { + +namespace css = com::sun::star; + +class ColorNameMap: private boost::noncopyable { +public: + ColorNameMap(); + + rtl::OUString lookUp(long color) const; + +private: + typedef boost::unordered_map< long, rtl::OUString > Map; + + Map map_; +}; + +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. + 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 = 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 + // called function. + SolarMutexGuard aGuard; + aNames = xNA->getElementNames(); + } + } + catch (css::uno::RuntimeException const&) + { + // When an exception occurred then whe have an empty name sequence + // and the loop below is not entered. + } + + // Fill the map to convert from numerical color values to names. + if (xNA.is()) + for (long int i=0; i<aNames.getLength(); i++) + { + // Get the numerical value for the i-th color name. + try + { + css::uno::Any aColor (xNA->getByName (aNames[i])); + long nColor = 0; + aColor >>= nColor; + map_[nColor] = aNames[i]; + } + catch (css::uno::RuntimeException const&) + { + // Ignore the exception: the color who lead to the exception + // is not included into the map. + } + } +} + +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 > {}; + +} + +namespace accessibility { + +rtl::OUString lookUpColorName(long color) { + return theColorNameMap::get().lookUp(color); +} + +} + +/* 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 0000000..92000e0 --- /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 0b0068d..0000000 --- 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: */ _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
