summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-01-05 14:04:48 +0000
committerCaolán McNamara <caolanm@redhat.com>2017-01-05 15:00:54 +0000
commit4f5cd607e30633ca51263c2f45c4753e8990302f (patch)
tree5aba23b6bbaf5b0fa16fb5faa702c56c5f144aa0 /framework
parent57990e4b8ea2eaeb478b161b568e31036c7a5fe4 (diff)
move CommandImageResolver out of vcl and beside its only user
Change-Id: I2bd70d87bb12d5750d8427b8a8fe786cfce8961b
Diffstat (limited to 'framework')
-rw-r--r--framework/Library_fwk.mk1
-rw-r--r--framework/source/uiconfiguration/CommandImageResolver.cxx161
-rw-r--r--framework/source/uiconfiguration/CommandImageResolver.hxx58
-rw-r--r--framework/source/uiconfiguration/imagemanagerimpl.hxx2
4 files changed, 221 insertions, 1 deletions
diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk
index 2246286b0348..1eaf49756fb0 100644
--- a/framework/Library_fwk.mk
+++ b/framework/Library_fwk.mk
@@ -113,6 +113,7 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
framework/source/services/substitutepathvars \
framework/source/services/taskcreatorsrv \
framework/source/services/urltransformer \
+ framework/source/uiconfiguration/CommandImageResolver \
framework/source/uiconfiguration/globalsettings \
framework/source/uiconfiguration/graphicnameaccess \
framework/source/uiconfiguration/imagemanager \
diff --git a/framework/source/uiconfiguration/CommandImageResolver.cxx b/framework/source/uiconfiguration/CommandImageResolver.cxx
new file mode 100644
index 000000000000..98aec12e3b4c
--- /dev/null
+++ b/framework/source/uiconfiguration/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 "CommandImageResolver.hxx"
+#include <vcl/settings.hxx>
+#include <vcl/svapp.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <tools/urlobj.hxx>
+
+using css::uno::Sequence;
+
+namespace vcl
+{
+
+namespace
+{
+
+static const o3tl::enumarray<ImageType, const char*> ImageType_Prefixes =
+{
+ "cmd/sc_",
+ "cmd/lc_",
+ "cmd/32/"
+};
+
+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 (ImageList*& rp : m_pImageList)
+ rp = nullptr;
+}
+
+CommandImageResolver::~CommandImageResolver()
+{
+ for (ImageList* p : m_pImageList)
+ delete p;
+}
+
+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::EncodeMechanism::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(ImageType nImageType)
+{
+ const OUString sIconTheme = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
+
+ if (sIconTheme != m_sIconTheme)
+ {
+ m_sIconTheme = sIconTheme;
+ for (ImageList*& rp : m_pImageList)
+ {
+ delete rp;
+ rp = 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(ImageType 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: */
diff --git a/framework/source/uiconfiguration/CommandImageResolver.hxx b/framework/source/uiconfiguration/CommandImageResolver.hxx
new file mode 100644
index 000000000000..79368fc5ceca
--- /dev/null
+++ b/framework/source/uiconfiguration/CommandImageResolver.hxx
@@ -0,0 +1,58 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_VCL_COMMANDICONRESOLVER_HXX
+#define INCLUDED_VCL_COMMANDICONRESOLVER_HXX
+
+#include <vcl/dllapi.h>
+#include <vcl/image.hxx>
+#include <o3tl/enumarray.hxx>
+
+#include <com/sun/star/uno/Sequence.hxx>
+
+#include <unordered_map>
+#include <vector>
+
+namespace vcl
+{
+
+class CommandImageResolver final
+{
+private:
+ typedef std::unordered_map<OUString, OUString, OUStringHash > CommandToImageNameMap;
+
+ CommandToImageNameMap m_aCommandToImageNameMap;
+ std::vector<OUString> m_aImageCommandNameVector;
+ std::vector<OUString> m_aImageNameVector;
+
+ o3tl::enumarray<ImageType, ImageList*> m_pImageList;
+ OUString m_sIconTheme;
+
+ ImageList* getImageList(ImageType nImageType);
+
+public:
+ CommandImageResolver();
+ ~CommandImageResolver();
+
+ bool registerCommands(css::uno::Sequence<OUString>& aCommandSequence);
+ Image getImageFromCommandURL(ImageType nImageType, const OUString& rCommandURL);
+
+ std::vector<OUString>& getCommandNames()
+ {
+ return m_aImageCommandNameVector;
+ }
+
+ bool hasImage(const OUString& rCommandURL);
+};
+
+} // end namespace vcl
+
+#endif // INCLUDED_VCL_COMMANDICONRESOLVER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/uiconfiguration/imagemanagerimpl.hxx b/framework/source/uiconfiguration/imagemanagerimpl.hxx
index 1d5022b868ff..ec2cf9bb950e 100644
--- a/framework/source/uiconfiguration/imagemanagerimpl.hxx
+++ b/framework/source/uiconfiguration/imagemanagerimpl.hxx
@@ -48,7 +48,7 @@
#include <unordered_map>
#include <vector>
-#include <vcl/CommandImageResolver.hxx>
+#include "CommandImageResolver.hxx"
namespace framework
{