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 #include "precompiled_sd.hxx"
25 
26 #include "SlsViewCacheContext.hxx"
27 
28 #include "SlideSorter.hxx"
29 #include "model/SlideSorterModel.hxx"
30 #include "model/SlsPageDescriptor.hxx"
31 #include "model/SlsPageEnumerationProvider.hxx"
32 #include "view/SlideSorterView.hxx"
33 #include "sdpage.hxx"
34 #include "Window.hxx"
35 #include "drawdoc.hxx"
36 #include "tools/IdleDetection.hxx"
37 #include <svx/svdpage.hxx>
38 #include <svx/sdr/contact/viewcontact.hxx>
39 #include <vcl/window.hxx>
40 #include <svx/sdr/contact/objectcontact.hxx>
41 
42 namespace sd { namespace slidesorter { namespace view {
43 
44 
ViewCacheContext(SlideSorter & rSlideSorter)45 ViewCacheContext::ViewCacheContext (SlideSorter& rSlideSorter)
46     : mrModel(rSlideSorter.GetModel()),
47       mrSlideSorter(rSlideSorter)
48 {
49 }
50 
51 
52 
53 
~ViewCacheContext(void)54 ViewCacheContext::~ViewCacheContext (void)
55 {
56 }
57 
58 
59 
60 
NotifyPreviewCreation(cache::CacheKey aKey,const Bitmap &)61 void ViewCacheContext::NotifyPreviewCreation (
62     cache::CacheKey aKey,
63     const Bitmap&)
64 {
65     const model::SharedPageDescriptor pDescriptor (GetDescriptor(aKey));
66     if (pDescriptor.get() != NULL)
67     {
68         // Force a repaint that will trigger their re-creation.
69         mrSlideSorter.GetView().RequestRepaint(pDescriptor);
70     }
71     else
72     {
73         // It is OK when a preview was created for a page that is not
74         // currently displayed because both normal and master pages are
75         // kept in the same cache.
76     }
77 }
78 
79 
80 
81 
IsIdle(void)82 bool ViewCacheContext::IsIdle (void)
83 {
84     sal_Int32 nIdleState (tools::IdleDetection::GetIdleState(mrSlideSorter.GetContentWindow().get()));
85     if (nIdleState == tools::IdleDetection::IDET_IDLE)
86         return true;
87     else
88         return false;
89 }
90 
91 
92 
93 
IsVisible(cache::CacheKey aKey)94 bool ViewCacheContext::IsVisible (cache::CacheKey aKey)
95 {
96     const model::SharedPageDescriptor pDescriptor (GetDescriptor(aKey));
97     return pDescriptor && pDescriptor->HasState(model::PageDescriptor::ST_Visible);
98 }
99 
100 
101 
102 
GetPage(cache::CacheKey aKey)103 const SdrPage* ViewCacheContext::GetPage (cache::CacheKey aKey)
104 {
105     return static_cast<const SdrPage*>(aKey);
106 }
107 
108 
109 
110 
GetEntryList(bool bVisible)111 ::boost::shared_ptr<std::vector<cache::CacheKey> > ViewCacheContext::GetEntryList (bool bVisible)
112 {
113     ::boost::shared_ptr<std::vector<cache::CacheKey> > pKeys (new std::vector<cache::CacheKey>());
114 
115     model::PageEnumeration aPageEnumeration (
116         bVisible
117             ? model::PageEnumerationProvider::CreateVisiblePagesEnumeration(mrModel)
118             : model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
119 
120     while (aPageEnumeration.HasMoreElements())
121     {
122         model::SharedPageDescriptor pDescriptor (aPageEnumeration.GetNextElement());
123         pKeys->push_back(pDescriptor->GetPage());
124     }
125 
126     return pKeys;
127 }
128 
129 
130 
131 
GetPriority(cache::CacheKey aKey)132 sal_Int32 ViewCacheContext::GetPriority (cache::CacheKey aKey)
133 {
134     return - (static_cast<const SdrPage*>(aKey)->GetPageNum()-1) / 2;
135 }
136 
137 
138 
139 
GetDescriptor(cache::CacheKey aKey)140 model::SharedPageDescriptor ViewCacheContext::GetDescriptor (cache::CacheKey aKey)
141 {
142     sal_uInt16 nPageIndex ((static_cast<const SdrPage*>(aKey)->GetPageNum() - 1) / 2);
143     return mrModel.GetPageDescriptor(nPageIndex);
144 }
145 
146 
147 
148 
GetModel(void)149 ::com::sun::star::uno::Reference<com::sun::star::uno::XInterface> ViewCacheContext::GetModel (void)
150 {
151     if (mrModel.GetDocument() == NULL)
152         return NULL;
153     else
154         return mrModel.GetDocument()->getUnoModel();
155 }
156 
157 } } } // end of namespace ::sd::slidesorter::view
158