diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-12-18 14:31:14 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-12-19 07:26:24 +0000 |
commit | bf5f6df9e47bd31dc052c6411f6f88ec2d4e3cea (patch) | |
tree | f573562af0d55e5cdb0bfe405db2967efd72d2e8 /vcl/inc | |
parent | f9a97a5d5aca8473845bca2e17c5826b772b8f3c (diff) |
vcl: separate ImplImageTree - ImageTree singleton and public iface
ImplImageTree was used outside of VCL which is not consistent with
the name and the header also contains a lot of implementation
detail. This separates the implementation to ImplImageTree and
the public interface and singleton to ImageTree only.
Change-Id: I3a26444f0f6971a6b1d83472e9cef19c93192d3e
Reviewed-on: https://gerrit.libreoffice.org/32134
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/inc')
-rw-r--r-- | vcl/inc/implimagetree.hxx | 136 | ||||
-rw-r--r-- | vcl/inc/pch/precompiled_vcl.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/vcldemo-debug.hxx | 25 |
3 files changed, 137 insertions, 26 deletions
diff --git a/vcl/inc/implimagetree.hxx b/vcl/inc/implimagetree.hxx new file mode 100644 index 000000000000..a229177c4709 --- /dev/null +++ b/vcl/inc/implimagetree.hxx @@ -0,0 +1,136 @@ +/* -*- 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_VCL_INC_IMPLIMAGETREE_HXX +#define INCLUDED_VCL_INC_IMPLIMAGETREE_HXX + +#include <sal/config.h> + +#include <memory> +#include <unordered_map> +#include <utility> +#include <vector> + +#include <com/sun/star/uno/Reference.hxx> +#include <rtl/ustring.hxx> +#include <vcl/bitmapex.hxx> +#include <vcl/dllapi.h> +#include <i18nlangtag/languagetag.hxx> +#include <vcl/ImageTree.hxx> + +namespace com { namespace sun { namespace star { namespace container { + class XNameAccess; +}}}} + +class ImplImageTree +{ +public: + ImplImageTree(); + ~ImplImageTree(); + + OUString getImageUrl( + OUString const & name, OUString const & style, OUString const & lang); + + bool loadImage( + OUString const & name, OUString const & style, + BitmapEx & bitmap, bool localized, + const ImageLoadFlags eFlags = ImageLoadFlags::NONE); + + bool loadDefaultImage( + OUString const & style, + BitmapEx& bitmap, + const ImageLoadFlags eFlags = ImageLoadFlags::NONE); + + /** a crude form of life cycle control (called from DeInitVCL; otherwise, + * if the ImplImageTree singleton were destroyed during exit that would + * be too late for the destructors of the bitmaps in maIconCache)*/ + void shutdown(); + + css::uno::Reference< css::container::XNameAccess > getNameAccess(); + +private: + ImplImageTree(const ImplImageTree&) = delete; + ImplImageTree& operator=(const ImplImageTree&) = delete; + + typedef std::unordered_map<OUString, std::pair<bool, BitmapEx>, OUStringHash> IconCache; + typedef std::unordered_map<OUString, OUString, OUStringHash> IconLinkHash; + + struct IconSet + { + OUString maURL; + css::uno::Reference<css::container::XNameAccess> maNameAccess; + IconCache maIconCache; + IconLinkHash maLinkHash; + + IconSet() + {} + + IconSet(const OUString & rURL) + : maURL(rURL) + {} + }; + + /// Map between the theme name(s) and the content. + typedef std::unordered_map<OUString, IconSet, OUStringHash> StyleIconSet; + + /// Remember all the (used) icon styles and individual icons in them. + StyleIconSet maIconSets; + + /// Style used for the current operations; switches switch several times during fallback search. + OUString maCurrentStyle; + + IconSet& getCurrentIconSet() + { + return maIconSets[maCurrentStyle]; + } + + bool doLoadImage( + OUString const & name, OUString const & style, + BitmapEx & bitmap, bool localized, const ImageLoadFlags eFlags); + + std::vector<OUString> getPaths(OUString const & name, LanguageTag& rLanguageTag); + + bool checkPathAccess(); + + void setStyle(OUString const & rStyle); + + void createStyle(); + + bool iconCacheLookup(OUString const & rName, bool bLocalized, const ImageLoadFlags eFlags, BitmapEx & rBitmap); + + bool findImage(std::vector<OUString> const & rPaths, BitmapEx & rBitmap, const ImageLoadFlags eFlags); + + void loadImageLinks(); + + void parseLinkFile(std::shared_ptr<SvStream> const & aStream); + + /// Return name of a real .png according to links.txt. + OUString const & getRealImageName(OUString const & rName); + + + /** Return name of the fallback style for the provided one. + + Must not be cyclic :-) The last theme in the chain returns an empty string. + */ + static OUString fallbackStyle(const OUString &rStyle); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/pch/precompiled_vcl.hxx b/vcl/inc/pch/precompiled_vcl.hxx index ec459c710e0e..94c0fcd18778 100644 --- a/vcl/inc/pch/precompiled_vcl.hxx +++ b/vcl/inc/pch/precompiled_vcl.hxx @@ -150,7 +150,7 @@ #include <vcl/help.hxx> #include <vcl/i18nhelp.hxx> #include <vcl/image.hxx> -#include <vcl/implimagetree.hxx> +#include <vcl/ImageTree.hxx> #include <vcl/keycod.hxx> #include <vcl/keycodes.hxx> #include <vcl/layout.hxx> diff --git a/vcl/inc/vcldemo-debug.hxx b/vcl/inc/vcldemo-debug.hxx deleted file mode 100644 index 37dae2481b9e..000000000000 --- a/vcl/inc/vcldemo-debug.hxx +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- 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_INC_VCLDEMO_DEBUG_HXX -#define INCLUDED_VCL_INC_VCLDEMO_DEBUG_HXX - -#include <sal/config.h> - -#include <com/sun/star/uno/Sequence.hxx> -#include <rtl/ustring.hxx> -#include <sal/types.h> -#include <vcl/dllapi.h> - -// For vcldemo / debugging -VCL_DLLPUBLIC css::uno::Sequence< OUString > ImageTree_getAllImageNames(); - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |