Update git submodules
[LibreOffice.git] / vcl / inc / implimagetree.hxx
blobbeecb233e1d9af1c418fa83f690ff48645492f07
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_INC_IMPLIMAGETREE_HXX
21 #define INCLUDED_VCL_INC_IMPLIMAGETREE_HXX
23 #include <sal/config.h>
25 #include <memory>
26 #include <unordered_map>
27 #include <utility>
28 #include <vector>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <rtl/ustring.hxx>
32 #include <vcl/bitmapex.hxx>
33 #include <i18nlangtag/languagetag.hxx>
34 #include <vcl/ImageTree.hxx>
36 namespace com::sun::star::container {
37 class XNameAccess;
40 namespace com::sun::star::io {
41 class XInputStream;
44 struct ImageRequestParameters
46 OUString msName;
47 OUString msStyle;
48 BitmapEx& mrBitmap;
49 bool mbLocalized;
50 ImageLoadFlags meFlags;
51 bool mbWriteImageToCache;
52 sal_Int32 mnScalePercentage;
54 ImageRequestParameters(OUString aName, OUString aStyle, BitmapEx& rBitmap, bool bLocalized,
55 ImageLoadFlags eFlags, sal_Int32 nScalePercentage)
56 : msName(std::move(aName))
57 , msStyle(std::move(aStyle))
58 , mrBitmap(rBitmap)
59 , mbLocalized(bLocalized)
60 , meFlags(eFlags)
61 , mbWriteImageToCache(false)
62 , mnScalePercentage(nScalePercentage)
65 bool convertToDarkTheme();
66 sal_Int32 scalePercentage();
69 class ImplImageTree
71 public:
72 ImplImageTree();
73 ~ImplImageTree();
75 OUString getImageUrl(
76 OUString const & name, OUString const & style, OUString const & lang);
78 css::uno::Reference<css::io::XInputStream> getImageXInputStream(OUString const & rName,
79 OUString const & rStyle, OUString const & rLang);
81 std::shared_ptr<SvMemoryStream> getImageStream(
82 OUString const & rName, OUString const & rStyle, OUString const & rLang);
84 bool loadImage(
85 OUString const & name, OUString const & style,
86 BitmapEx & bitmap, bool localized,
87 const ImageLoadFlags eFlags,
88 sal_Int32 nScalePercentage = -1);
90 /** a crude form of life cycle control (called from DeInitVCL; otherwise,
91 * if the ImplImageTree singleton were destroyed during exit that would
92 * be too late for the destructors of the bitmaps in maIconCache)*/
93 void shutdown();
95 css::uno::Reference< css::container::XNameAccess > const & getNameAccess();
97 private:
98 ImplImageTree(const ImplImageTree&) = delete;
99 ImplImageTree& operator=(const ImplImageTree&) = delete;
101 typedef std::unordered_map<OUString, std::pair<bool,BitmapEx>> IconCache;
102 typedef std::unordered_map<sal_Int32, IconCache> ScaledIconCache;
103 typedef std::unordered_map<OUString, OUString> IconLinkHash;
105 struct IconSet
107 OUString maURL;
108 css::uno::Reference<css::container::XNameAccess> maNameAccess;
109 ScaledIconCache maScaledIconCaches;
110 IconLinkHash maLinkHash;
112 IconSet()
114 maLinkHash.reserve(50);
117 IconSet(OUString aURL)
118 : maURL(std::move(aURL))
120 maLinkHash.reserve(50);
124 /// Remember all the (used) icon styles and individual icons in them.
125 /// Map between the theme name(s) and the content.
126 std::unordered_map<OUString, IconSet> maIconSets;
128 /// Style used for the current operations; switches switch several times during fallback search.
129 OUString maCurrentStyle;
131 IconSet& getCurrentIconSet()
133 return maIconSets[maCurrentStyle];
136 bool doLoadImage(ImageRequestParameters& rParameters);
138 std::vector<OUString> getPaths(OUString const & name, LanguageTag const & rLanguageTag);
140 bool checkPathAccess();
142 void setStyle(OUString const & rStyle);
144 void createStyle();
146 IconCache &getIconCache(const ImageRequestParameters& rParameters);
148 bool iconCacheLookup(ImageRequestParameters& rParameters);
150 bool findImage(std::vector<OUString> const & rPaths, ImageRequestParameters& rParameters);
152 void loadImageLinks();
154 void parseLinkFile(std::shared_ptr<SvStream> const & aStream);
156 /// Return name of a real .png according to links.txt.
157 OUString const & getRealImageName(OUString const & rName);
160 /** Return name of the fallback style for the provided one.
162 Must not be cyclic :-) The last theme in the chain returns an empty string.
164 static OUString fallbackStyle(std::u16string_view rStyle);
167 #endif
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */