Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_INC_IMPIMAGETREE_HXX
21 : #define INCLUDED_VCL_INC_IMPIMAGETREE_HXX
22 :
23 : #include "sal/config.h"
24 :
25 : #include <memory>
26 : #include <unordered_map>
27 : #include <vector>
28 :
29 : #include "com/sun/star/uno/Reference.hxx"
30 : #include "rtl/ustring.hxx"
31 : #include "salhelper/singletonref.hxx"
32 :
33 : namespace com { namespace sun { namespace star { namespace container {
34 : class XNameAccess;
35 : } } } }
36 : class BitmapEx;
37 :
38 : class ImplImageTree {
39 : public:
40 : ImplImageTree();
41 :
42 : ~ImplImageTree();
43 :
44 : bool loadImage(
45 : OUString const & name, OUString const & style,
46 : BitmapEx & bitmap, bool localized = false, bool loadMissing = false );
47 :
48 : bool loadDefaultImage(
49 : OUString const & style,
50 : BitmapEx& bitmap);
51 :
52 : /** a crude form of life cycle control (called from DeInitVCL; otherwise,
53 : * if the ImplImageTree singleton were destroyed during exit that would
54 : * be too late for the destructors of the bitmaps in maIconCache)*/
55 : void shutDown();
56 :
57 : css::uno::Reference< css::container::XNameAccess > getNameAccess();
58 :
59 : private:
60 : ImplImageTree(const ImplImageTree&) SAL_DELETED_FUNCTION;
61 : ImplImageTree& operator=(const ImplImageTree&) SAL_DELETED_FUNCTION;
62 :
63 : typedef std::unordered_map<OUString, std::pair<bool, BitmapEx>, OUStringHash> IconCache;
64 : typedef std::unordered_map<OUString, OUString, OUStringHash> IconLinkHash;
65 :
66 666 : struct IconSet {
67 : OUString maURL;
68 : css::uno::Reference<css::container::XNameAccess> maNameAccess;
69 : IconCache maIconCache;
70 : IconLinkHash maLinkHash;
71 :
72 222 : IconSet() {}
73 222 : IconSet(const OUString &aURL) : maURL(aURL) {}
74 : };
75 :
76 : /// Map between the theme name(s) and the content.
77 : typedef std::unordered_map<OUString, IconSet, OUStringHash> StyleIconSet;
78 :
79 : /// Remember all the (used) icon styles and individual icons in them.
80 : StyleIconSet maIconSet;
81 :
82 : /// Styly used for the current operations; switches switch several times during fallback search.
83 : OUString maCurrentStyle;
84 :
85 : bool doLoadImage(
86 : OUString const & name, OUString const & style,
87 : BitmapEx & bitmap, bool localized);
88 :
89 : bool checkPathAccess();
90 :
91 : void setStyle(OUString const & style );
92 :
93 : void createStyle();
94 :
95 : bool iconCacheLookup( OUString const & name, bool localized, BitmapEx & bitmap );
96 :
97 : bool findImage(std::vector< OUString > const & paths, BitmapEx & bitmap );
98 :
99 : void loadImageLinks();
100 :
101 : void parseLinkFile(std::shared_ptr<SvStream> stream);
102 :
103 : /// Return name of a real .png according to links.txt.
104 : OUString const & getRealImageName(OUString const & name);
105 :
106 : /** Rerurn name of the fallback style for the provided one.
107 :
108 : Must not be cyclic :-) The last theme in the chain returns an empty string.
109 : */
110 : static OUString fallbackStyle(const OUString &style);
111 : };
112 :
113 : typedef salhelper::SingletonRef< ImplImageTree > ImplImageTreeSingletonRef;
114 :
115 : #endif
116 :
117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|