1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_SD_SOURCE_UI_SLIDESORTER_INC_CACHE_SLSPAGECACHEMANAGER_HXX
21 #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CACHE_SLSPAGECACHEMANAGER_HXX
23 #include <sal/types.h>
24 #include <com/sun/star/uno/XInterface.hpp>
25 #include <boost/shared_ptr.hpp>
32 namespace sd
{ namespace slidesorter
{ namespace cache
{
36 /** Provide and manage the preview bitmap caches for all slide sorter
37 instances. There is one cache per active slide sorter plus a small
38 number of caches that are no longer in use. The later are kept to speed
39 up the switching between views.
41 class PageCacheManager
44 typedef BitmapCache Cache
;
45 typedef ::std::vector
< ::std::pair
<Size
, ::boost::shared_ptr
<BitmapCache
> > > BestFittingPageCaches
;
46 typedef css::uno::Reference
<css::uno::XInterface
> DocumentKey
;
48 /** Return the one instance of the PageCacheManager class.
50 static ::boost::shared_ptr
<PageCacheManager
> Instance();
52 /** Look up the cache for the given model in which the previews have the
53 specified size. If no such cache exists, then one is created. When
54 a new BitmapCache is created its Recycle() method is called with a
55 sorted list of existing caches from which the new one initialize its
58 The returned cache lives as long as somebody keeps a shared
59 pointer and the ReleaseCache() method has not been called.
61 ::boost::shared_ptr
<Cache
> GetCache (
62 DocumentKey pDocument
,
63 const Size
& rPreviewSize
);
65 /** Tell the cache manager to release its own reference to the specified
66 cache. After that the cache will live as long as the caller (and
67 maybe others) holds its reference.
69 void ReleaseCache (const ::boost::shared_ptr
<Cache
>& rpCache
);
71 /** This is an information to the cache manager that the size of preview
72 bitmaps in the specified cache has changed.
75 ::boost::shared_ptr
<Cache
> ChangeSize (
76 const ::boost::shared_ptr
<Cache
>& rpCache
,
77 const Size
& rOldPreviewSize
,
78 const Size
& rNewPreviewSize
);
80 /** Invalidate the preview bitmap for one slide that belongs to the
81 specified document. The bitmaps for this slide in all caches are
82 marked as out-of-date and will be re-created when they are requested
85 bool InvalidatePreviewBitmap (
86 DocumentKey pDocument
,
87 const SdrPage
* pPage
);
89 /** Invalidate the preview bitmaps for all slides that belong to the
90 specified document. This is necessary after model changes that
91 affect e.g. page number fields.
93 void InvalidateAllPreviewBitmaps (DocumentKey pDocument
);
95 /** Invalidate all the caches that are currently in use and destroy
96 those that are not. This is used for example when the high contrast
97 mode is turned on or off.
99 void InvalidateAllCaches();
101 /** Call this method when a page has been deleted and its preview
102 is not needed anymore.
104 void ReleasePreviewBitmap (const SdrPage
* pPage
);
107 /** Singleton instance of the cache manager. Note that this is a weak
108 pointer. The (implementation class of) ViewShellBase holds a
109 shared_ptr so that the cache manager has the same life time as the
112 static ::boost::weak_ptr
<PageCacheManager
> mpInstance
;
114 /// List of active caches.
115 class PageCacheContainer
;
116 ::std::unique_ptr
<PageCacheContainer
> mpPageCaches
;
118 /// List of inactive, recently used caches.
119 class RecentlyUsedPageCaches
;
120 ::std::unique_ptr
<RecentlyUsedPageCaches
> mpRecentlyUsedPageCaches
;
122 /** The maximal number of recently used caches that are kept alive after
123 they have become inactive, i.e. after they are not used anymore by a
126 const sal_uInt32 mnMaximalRecentlyCacheCount
;
132 friend class Deleter
;
134 ::boost::shared_ptr
<Cache
> GetRecentlyUsedCache(
135 DocumentKey pDocument
,
138 /** Add the given cache to the list of recently used caches for the
139 document. There is one such list per document. Each least has at
140 most mnMaximalRecentlyCacheCount members.
142 void PutRecentlyUsedCache(
143 DocumentKey pDocument
,
144 const Size
& rPreviewSize
,
145 const ::boost::shared_ptr
<Cache
>& rpCache
);
147 /** Return a sorted list of the available caches, both active caches and
148 those recently used, for the given document. The sort order is so
149 that an exact match of the preview size is at the front. Other
150 caches follow with the largest size first.
152 BestFittingPageCaches
GetBestFittingCaches (
153 DocumentKey pDocument
,
154 const Size
& rPreviewSize
);
156 /** This method is used internally to initialize a newly created
157 BitmapCache with already exisiting previews.
160 const ::boost::shared_ptr
<Cache
>& rpCache
,
161 DocumentKey pDocument
,
162 const Size
& rPreviewSize
);
165 } } } // end of namespace ::sd::slidesorter::cache
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */