summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-11-18 18:42:40 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-11-19 13:02:53 +0100
commit6480b4d11a0cf2dd489d30b6290aa6d831704a45 (patch)
tree347f0a480b010959bc04c8e951f7c169f00bafc9 /vcl
parent8f07a723f932ac83b48afe55518b0a1e81e36f20 (diff)
move translating a command name to image name out of framework
This is the first step to decouple resolving of command names to image (icon) names. This is necessary to make allow additional processing of images before the image is passed on and better decision which image source to take. Change-Id: I129dc6a1ae812aaaca32696ef2a2749d5fa86a54
Diffstat (limited to 'vcl')
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/source/bitmap/CommandImageResolver.cxx161
2 files changed, 162 insertions, 0 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 0da204a390d7..ef21b307b900 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -328,6 +328,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/BitmapProcessor \
vcl/source/bitmap/BitmapTools \
vcl/source/bitmap/checksum \
+ vcl/source/bitmap/CommandImageResolver \
vcl/source/helper/canvasbitmap \
vcl/source/helper/canvastools \
vcl/source/helper/commandinfoprovider \
diff --git a/vcl/source/bitmap/CommandImageResolver.cxx b/vcl/source/bitmap/CommandImageResolver.cxx
new file mode 100644
index 000000000000..5c636d70c9bc
--- /dev/null
+++ b/vcl/source/bitmap/CommandImageResolver.cxx
@@ -0,0 +1,161 @@
+/* -*- 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/.
+ */
+
+#include <vcl/CommandImageResolver.hxx>
+
+#include <rtl/ustrbuf.hxx>
+#include <tools/urlobj.hxx>
+#include <svtools/miscopt.hxx>
+#include <officecfg/Office/Common.hxx>
+
+using css::uno::Sequence;
+
+namespace vcl
+{
+
+namespace
+{
+
+const char* ImageType_Prefixes[ImageType_COUNT] =
+{
+ "cmd/sc_",
+ "cmd/lc_"
+};
+
+OUString lclConvertToCanonicalName(const OUString& rFileName)
+{
+ bool bRemoveSlash(true);
+ sal_Int32 nLength = rFileName.getLength();
+ const sal_Unicode* pString = rFileName.getStr();
+
+ OUStringBuffer aBuffer(nLength);
+
+ for (sal_Int32 i = 0; i < nLength; i++)
+ {
+ const sal_Unicode cCurrentChar = pString[i];
+ switch (cCurrentChar)
+ {
+ // map forbidden characters to escape
+ case '/':
+ if (!bRemoveSlash)
+ aBuffer.append("%2f");
+ break;
+ case '\\': aBuffer.append("%5c"); bRemoveSlash = false; break;
+ case ':': aBuffer.append("%3a"); bRemoveSlash = false; break;
+ case '*': aBuffer.append("%2a"); bRemoveSlash = false; break;
+ case '?': aBuffer.append("%3f"); bRemoveSlash = false; break;
+ case '<': aBuffer.append("%3c"); bRemoveSlash = false; break;
+ case '>': aBuffer.append("%3e"); bRemoveSlash = false; break;
+ case '|': aBuffer.append("%7c"); bRemoveSlash = false; break;
+ default:
+ aBuffer.append(cCurrentChar); bRemoveSlash = false; break;
+ }
+ }
+ return aBuffer.makeStringAndClear();
+}
+
+} // end anonymouse namespace
+
+CommandImageResolver::CommandImageResolver()
+{
+ for (sal_Int32 n = 0; n < ImageType_COUNT; n++)
+ m_pImageList[n] = nullptr;
+}
+
+CommandImageResolver::~CommandImageResolver()
+{
+ for (sal_Int32 n = 0; n < ImageType_COUNT; n++)
+ delete m_pImageList[n];
+}
+
+bool CommandImageResolver::registerCommands(Sequence<OUString>& aCommandSequence)
+{
+ sal_Int32 nSequenceSize = aCommandSequence.getLength();
+
+ m_aImageCommandNameVector.resize(nSequenceSize);
+ m_aImageNameVector.resize(nSequenceSize);
+
+ for (sal_Int32 i = 0; i < nSequenceSize; ++i)
+ {
+ OUString aCommandName(aCommandSequence[i]);
+ OUString aImageName;
+
+ m_aImageCommandNameVector[i] = aCommandName;
+
+ if (aCommandName.indexOf(".uno:") != 0)
+ {
+ INetURLObject aUrlObject(aCommandName, INetURLObject::ENCODE_ALL);
+ aImageName = aUrlObject.GetURLPath();
+ aImageName = lclConvertToCanonicalName(aImageName);
+ }
+ else
+ {
+ // just remove the schema
+ if (aCommandName.getLength() > 5)
+ aImageName = aCommandName.copy(5);
+
+ // Search for query part.
+ if (aImageName.indexOf('?') != -1)
+ aImageName = lclConvertToCanonicalName(aImageName);
+ }
+
+ // Image names are not case-dependent. Always use lower case characters to
+ // reflect this.
+ aImageName = aImageName.toAsciiLowerCase();
+ aImageName += ".png";
+
+ m_aImageNameVector[i] = aImageName;
+ m_aCommandToImageNameMap[aCommandName] = aImageName;
+ }
+ return true;
+}
+
+bool CommandImageResolver::hasImage(const OUString& rCommandURL)
+{
+ CommandToImageNameMap::const_iterator pIterator = m_aCommandToImageNameMap.find(rCommandURL);
+ return pIterator != m_aCommandToImageNameMap.end();
+}
+
+ImageList* CommandImageResolver::getImageList(sal_Int16 nImageType)
+{
+ const OUString& rIconTheme = officecfg::Office::Common::Misc::SymbolStyle::get();
+
+ if (rIconTheme != m_sIconTheme)
+ {
+ m_sIconTheme = rIconTheme;
+ for (sal_Int32 n = 0; n < ImageType_COUNT; ++n)
+ {
+ delete m_pImageList[n];
+ m_pImageList[n] = nullptr;
+ }
+ }
+
+ if (!m_pImageList[nImageType])
+ {
+ OUString sIconPath = OUString::createFromAscii(ImageType_Prefixes[nImageType]);
+ m_pImageList[nImageType] = new ImageList(m_aImageNameVector, sIconPath);
+ }
+
+ return m_pImageList[nImageType];
+}
+
+Image CommandImageResolver::getImageFromCommandURL(sal_Int16 nImageType, const OUString& rCommandURL)
+{
+ CommandToImageNameMap::const_iterator pIterator = m_aCommandToImageNameMap.find(rCommandURL);
+ if (pIterator != m_aCommandToImageNameMap.end())
+ {
+ ImageList* pImageList = getImageList(nImageType);
+ return pImageList->GetImage(pIterator->second);
+ }
+ return Image();
+}
+
+} // end namespace vcl
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */