tdf#119030: Disable entries if open file read-only is unchecked
[LibreOffice.git] / vcl / inc / implimagetree.hxx
blobe35c9ac6ccfbeaeb154098f5ee9d530597f0d186
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 <vcl/dllapi.h>
34 #include <i18nlangtag/languagetag.hxx>
35 #include <vcl/ImageTree.hxx>
37 namespace com { namespace sun { namespace star { namespace container {
38 class XNameAccess;
39 }}}}
41 struct ImageRequestParameters
43 OUString msName;
44 OUString msStyle;
45 BitmapEx& mrBitmap;
46 bool mbLocalized;
47 ImageLoadFlags meFlags;
48 bool mbWriteImageToCache;
50 ImageRequestParameters(const OUString & rName, const OUString & rStyle, BitmapEx& rBitmap, bool bLocalized, ImageLoadFlags eFlags)
51 : msName(rName)
52 , msStyle(rStyle)
53 , mrBitmap(rBitmap)
54 , mbLocalized(bLocalized)
55 , meFlags(eFlags)
56 , mbWriteImageToCache(false)
59 bool convertToDarkTheme();
60 sal_Int32 scalePercentage();
63 class ImplImageTree
65 public:
66 ImplImageTree();
67 ~ImplImageTree();
69 OUString getImageUrl(
70 OUString const & name, OUString const & style, OUString const & lang);
72 std::shared_ptr<SvMemoryStream> getImageStream(
73 OUString const & rName, OUString const & rStyle, OUString const & rLang);
75 bool loadImage(
76 OUString const & name, OUString const & style,
77 BitmapEx & bitmap, bool localized,
78 const ImageLoadFlags eFlags);
80 /** a crude form of life cycle control (called from DeInitVCL; otherwise,
81 * if the ImplImageTree singleton were destroyed during exit that would
82 * be too late for the destructors of the bitmaps in maIconCache)*/
83 void shutdown();
85 css::uno::Reference< css::container::XNameAccess > const & getNameAccess();
87 private:
88 ImplImageTree(const ImplImageTree&) = delete;
89 ImplImageTree& operator=(const ImplImageTree&) = delete;
91 typedef std::unordered_map<OUString, std::pair<bool, BitmapEx>> IconCache;
92 typedef std::unordered_map<OUString, OUString> IconLinkHash;
94 struct IconSet
96 OUString maURL;
97 css::uno::Reference<css::container::XNameAccess> maNameAccess;
98 IconCache maIconCache;
99 IconLinkHash maLinkHash;
101 IconSet()
104 IconSet(const OUString & rURL)
105 : maURL(rURL)
109 /// Remember all the (used) icon styles and individual icons in them.
110 /// Map between the theme name(s) and the content.
111 std::unordered_map<OUString, IconSet> maIconSets;
113 /// Style used for the current operations; switches switch several times during fallback search.
114 OUString maCurrentStyle;
116 IconSet& getCurrentIconSet()
118 return maIconSets[maCurrentStyle];
121 bool doLoadImage(ImageRequestParameters& rParameters);
123 std::vector<OUString> getPaths(OUString const & name, LanguageTag const & rLanguageTag);
125 bool checkPathAccess();
127 void setStyle(OUString const & rStyle);
129 void createStyle();
131 bool iconCacheLookup(ImageRequestParameters& rParameters);
133 bool findImage(std::vector<OUString> const & rPaths, ImageRequestParameters& rParameters);
135 void loadImageLinks();
137 void parseLinkFile(std::shared_ptr<SvStream> const & aStream);
139 /// Return name of a real .png according to links.txt.
140 OUString const & getRealImageName(OUString const & rName);
143 /** Return name of the fallback style for the provided one.
145 Must not be cyclic :-) The last theme in the chain returns an empty string.
147 static OUString fallbackStyle(const OUString &rStyle);
150 #endif
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */