xref: /AOO41X/main/sd/source/ui/slidesorter/view/SlsViewCacheContext.cxx (revision 4799f5ba13c0140a13cf2e05fc58d1eb59f25ad2)
15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55b190011SAndrew Rist  * distributed with this work for additional information
65b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist  * "License"); you may not use this file except in compliance
95b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist  * software distributed under the License is distributed on an
155b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
175b190011SAndrew Rist  * specific language governing permissions and limitations
185b190011SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205b190011SAndrew Rist  *************************************************************/
215b190011SAndrew Rist 
225b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "SlsViewCacheContext.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "SlideSorter.hxx"
29cdf0e10cSrcweir #include "model/SlideSorterModel.hxx"
30cdf0e10cSrcweir #include "model/SlsPageDescriptor.hxx"
31cdf0e10cSrcweir #include "model/SlsPageEnumerationProvider.hxx"
32cdf0e10cSrcweir #include "view/SlideSorterView.hxx"
33cdf0e10cSrcweir #include "sdpage.hxx"
34cdf0e10cSrcweir #include "Window.hxx"
35cdf0e10cSrcweir #include "drawdoc.hxx"
36cdf0e10cSrcweir #include "tools/IdleDetection.hxx"
37cdf0e10cSrcweir #include <svx/svdpage.hxx>
38cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx>
39cdf0e10cSrcweir #include <vcl/window.hxx>
40cdf0e10cSrcweir #include <svx/sdr/contact/objectcontact.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace view {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
ViewCacheContext(SlideSorter & rSlideSorter)45cdf0e10cSrcweir ViewCacheContext::ViewCacheContext (SlideSorter& rSlideSorter)
46cdf0e10cSrcweir     : mrModel(rSlideSorter.GetModel()),
47cdf0e10cSrcweir       mrSlideSorter(rSlideSorter)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
~ViewCacheContext(void)54cdf0e10cSrcweir ViewCacheContext::~ViewCacheContext (void)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
NotifyPreviewCreation(cache::CacheKey aKey,const Bitmap &)61cdf0e10cSrcweir void ViewCacheContext::NotifyPreviewCreation (
62cdf0e10cSrcweir     cache::CacheKey aKey,
63cdf0e10cSrcweir     const Bitmap&)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     const model::SharedPageDescriptor pDescriptor (GetDescriptor(aKey));
66cdf0e10cSrcweir     if (pDescriptor.get() != NULL)
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         // Force a repaint that will trigger their re-creation.
69cdf0e10cSrcweir         mrSlideSorter.GetView().RequestRepaint(pDescriptor);
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir     else
72cdf0e10cSrcweir     {
73*4799f5baSAndre Fischer         // It is OK when a preview was created for a page that is not
74*4799f5baSAndre Fischer         // currently displayed because both normal and master pages are
75*4799f5baSAndre Fischer         // kept in the same cache.
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
IsIdle(void)82cdf0e10cSrcweir bool ViewCacheContext::IsIdle (void)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     sal_Int32 nIdleState (tools::IdleDetection::GetIdleState(mrSlideSorter.GetContentWindow().get()));
85cdf0e10cSrcweir     if (nIdleState == tools::IdleDetection::IDET_IDLE)
86cdf0e10cSrcweir         return true;
87cdf0e10cSrcweir     else
88cdf0e10cSrcweir         return false;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
IsVisible(cache::CacheKey aKey)94cdf0e10cSrcweir bool ViewCacheContext::IsVisible (cache::CacheKey aKey)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     const model::SharedPageDescriptor pDescriptor (GetDescriptor(aKey));
97cdf0e10cSrcweir     return pDescriptor && pDescriptor->HasState(model::PageDescriptor::ST_Visible);
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
GetPage(cache::CacheKey aKey)103cdf0e10cSrcweir const SdrPage* ViewCacheContext::GetPage (cache::CacheKey aKey)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     return static_cast<const SdrPage*>(aKey);
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
GetEntryList(bool bVisible)111cdf0e10cSrcweir ::boost::shared_ptr<std::vector<cache::CacheKey> > ViewCacheContext::GetEntryList (bool bVisible)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     ::boost::shared_ptr<std::vector<cache::CacheKey> > pKeys (new std::vector<cache::CacheKey>());
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     model::PageEnumeration aPageEnumeration (
116cdf0e10cSrcweir         bVisible
117cdf0e10cSrcweir             ? model::PageEnumerationProvider::CreateVisiblePagesEnumeration(mrModel)
118cdf0e10cSrcweir             : model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     while (aPageEnumeration.HasMoreElements())
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         model::SharedPageDescriptor pDescriptor (aPageEnumeration.GetNextElement());
123cdf0e10cSrcweir         pKeys->push_back(pDescriptor->GetPage());
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     return pKeys;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 
GetPriority(cache::CacheKey aKey)132cdf0e10cSrcweir sal_Int32 ViewCacheContext::GetPriority (cache::CacheKey aKey)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     return - (static_cast<const SdrPage*>(aKey)->GetPageNum()-1) / 2;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 
GetDescriptor(cache::CacheKey aKey)140cdf0e10cSrcweir model::SharedPageDescriptor ViewCacheContext::GetDescriptor (cache::CacheKey aKey)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     sal_uInt16 nPageIndex ((static_cast<const SdrPage*>(aKey)->GetPageNum() - 1) / 2);
143cdf0e10cSrcweir     return mrModel.GetPageDescriptor(nPageIndex);
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
GetModel(void)149cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::uno::XInterface> ViewCacheContext::GetModel (void)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     if (mrModel.GetDocument() == NULL)
152cdf0e10cSrcweir         return NULL;
153cdf0e10cSrcweir     else
154cdf0e10cSrcweir         return mrModel.GetDocument()->getUnoModel();
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::view
158