merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slidesorter / inc / cache / SlsPageCacheManager.hxx
blob3633dbafbde2e76ef8a157179becaf2260258ffb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsPageCacheManager.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_PAGE_CACHE_MANAGER_HXX
32 #define SD_PAGE_CACHE_MANAGER_HXX
34 #include <sal/types.h>
35 #include <com/sun/star/uno/XInterface.hpp>
36 #include <boost/shared_ptr.hpp>
37 #include <memory>
38 #include <vector>
40 class Size;
41 class SdDrawDocument;
42 class SdrPage;
44 namespace sd { namespace slidesorter { namespace view {
45 class SlideSorterView;
46 class PageObjectViewObjectContact;
47 } } }
49 namespace sd { namespace slidesorter { namespace model {
50 class SlideSorterModel;
51 } } }
53 namespace sd { namespace slidesorter { namespace cache {
55 namespace css = ::com::sun::star;
57 class BitmapCache;
60 /** Provide and manage the preview bitmap caches for all slide sorter
61 instances. There is one cache per active slide sorter plus a small
62 number of caches that are no longer in use. The later are kept to speed
63 up the switching between views.
65 class PageCacheManager
67 public:
68 typedef BitmapCache Cache;
69 typedef ::std::vector< ::std::pair<Size, ::boost::shared_ptr<BitmapCache> > > BestFittingPageCaches;
70 typedef css::uno::Reference<css::uno::XInterface> DocumentKey;
72 /** Return the one instance of the PageCacheManager class.
74 static ::boost::shared_ptr<PageCacheManager> Instance (void);
76 /** Look up the cache for the given model in which the previews have the
77 specified size. If no such cache exists, then one is created. When
78 a new BitmapCache is created its Recycle() method is called with a
79 sorted list of existing caches from which the new one initialize its
80 previews.
81 @return
82 The returned cache lives as long as somebody keeps a shared
83 pointer and the ReleaseCache() method has not been called.
85 ::boost::shared_ptr<Cache> GetCache (
86 DocumentKey pDocument,
87 const Size& rPreviewSize);
89 /** Tell the cache manager to release its own reference to the specified
90 cache. After that the cache will live as long as the caller (and
91 maybe others) holds its reference.
93 void ReleaseCache (const ::boost::shared_ptr<Cache>& rpCache);
95 /** This is an information to the cache manager that the size of preview
96 bitmaps in the specified cache has changed.
99 ::boost::shared_ptr<Cache> ChangeSize (
100 const ::boost::shared_ptr<Cache>& rpCache,
101 const Size& rOldPreviewSize,
102 const Size& rNewPreviewSize);
104 /** Invalidate the preview bitmap for one slide that belongs to the
105 specified document. The bitmaps for this slide in all caches are
106 marked as out-of-date and will be re-created when they are requested
107 the next time.
109 void InvalidatePreviewBitmap (
110 DocumentKey pDocument,
111 const SdrPage* pPage);
113 /** Invalidate all the caches that are currently in use and destroy
114 those that are not. This is used for example when the high contrast
115 mode is turned on or off.
117 void InvalidateAllCaches (void);
119 private:
120 /** Singleton instance of the cache manager. Note that this is a weak
121 pointer. The (implementation class of) ViewShellBase holds a
122 shared_ptr so that the cache manager has the same life time as the
123 ViewShellBase.
125 static ::boost::weak_ptr<PageCacheManager> mpInstance;
127 /// List of active caches.
128 class PageCacheContainer;
129 ::std::auto_ptr<PageCacheContainer> mpPageCaches;
131 /// List of inactive, recently used caches.
132 class RecentlyUsedPageCaches;
133 ::std::auto_ptr<RecentlyUsedPageCaches> mpRecentlyUsedPageCaches;
135 /** The maximal number of recently used caches that are kept alive after
136 they have become inactive, i.e. after they are not used anymore by a
137 slide sorter.
139 const sal_uInt32 mnMaximalRecentlyCacheCount;
141 PageCacheManager (void);
142 ~PageCacheManager (void);
144 class Deleter;
145 friend class Deleter;
147 ::boost::shared_ptr<Cache> GetRecentlyUsedCache(
148 DocumentKey pDocument,
149 const Size& rSize);
151 /** Add the given cache to the list of recently used caches for the
152 document. There is one such list per document. Each least has at
153 most mnMaximalRecentlyCacheCount members.
155 void PutRecentlyUsedCache(
156 DocumentKey pDocument,
157 const Size& rPreviewSize,
158 const ::boost::shared_ptr<Cache>& rpCache);
160 /** Return a sorted list of the available caches, both active caches and
161 those recently used, for the given document. The sort order is so
162 that an exact match of the preview size is at the front. Other
163 caches follow with the largest size first.
165 BestFittingPageCaches GetBestFittingCaches (
166 DocumentKey pDocument,
167 const Size& rPreviewSize);
169 /** This method is used internally to initialize a newly created
170 BitmapCache with already exisiting previews.
172 void Recycle (
173 const ::boost::shared_ptr<Cache>& rpCache,
174 DocumentKey pDocument,
175 const Size& rPreviewSize);
178 } } } // end of namespace ::sd::slidesorter::cache
180 #endif