xref: /aoo41x/main/sd/source/ui/inc/tools/IconCache.hxx (revision 67e470da)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_ICON_CACHE_HXX
25 #define SD_ICON_CACHE_HXX
26 
27 #include "SdGlobalResourceContainer.hxx"
28 #include <vcl/image.hxx>
29 
30 namespace sd {
31 
32 /** This simple class stores frequently used icons so that the classes that
33     use the icons do not have to store them in every one of their
34     instances.
35 
36     Icons are adressed over their resource id and are loaded on demand.
37 
38     This cache acts like a singleton with a lifetime equal to that of the sd
39     module.
40 */
41 class IconCache
42     : public SdGlobalResource
43 {
44 public:
45     /** The lifetime of the returned reference is limited to that of the sd
46         module.
47     */
48     static IconCache& Instance (void);
49 
50     /** Return the icon with the given resource id.
51         @return
52             The returned Image may be empty when there is no icon for the
53             given id or an error occured.  Should not happen under normal
54             circumstances.
55     */
56     Image GetIcon (sal_uInt16 nResourceId);
57 
58 private:
59     class Implementation;
60     ::std::auto_ptr<Implementation> mpImpl;
61 
62     /** The constructor creates the one instance of the cache and registers
63         it at the SdGlobalResourceContainer to limit is lifetime to that of
64         the sd module.
65     */
66     IconCache (void);
67 
68     /** This destructor is called by SdGlobalResourceContainer.
69     */
70     virtual ~IconCache (void);
71 };
72 
73 } // end of namespace sd
74 
75 #endif
76