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 45 ViewCacheContext::ViewCacheContext (SlideSorter& rSlideSorter) 46 : mrModel(rSlideSorter.GetModel()), 47 mrSlideSorter(rSlideSorter) 48 { 49 } 50 51 52 53 54 ViewCacheContext::~ViewCacheContext (void) 55 { 56 } 57 58 59 60 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 OSL_ASSERT(pDescriptor); 74 } 75 } 76 77 78 79 80 bool ViewCacheContext::IsIdle (void) 81 { 82 sal_Int32 nIdleState (tools::IdleDetection::GetIdleState(mrSlideSorter.GetContentWindow().get())); 83 if (nIdleState == tools::IdleDetection::IDET_IDLE) 84 return true; 85 else 86 return false; 87 } 88 89 90 91 92 bool ViewCacheContext::IsVisible (cache::CacheKey aKey) 93 { 94 const model::SharedPageDescriptor pDescriptor (GetDescriptor(aKey)); 95 return pDescriptor && pDescriptor->HasState(model::PageDescriptor::ST_Visible); 96 } 97 98 99 100 101 const SdrPage* ViewCacheContext::GetPage (cache::CacheKey aKey) 102 { 103 return static_cast<const SdrPage*>(aKey); 104 } 105 106 107 108 109 ::boost::shared_ptr<std::vector<cache::CacheKey> > ViewCacheContext::GetEntryList (bool bVisible) 110 { 111 ::boost::shared_ptr<std::vector<cache::CacheKey> > pKeys (new std::vector<cache::CacheKey>()); 112 113 model::PageEnumeration aPageEnumeration ( 114 bVisible 115 ? model::PageEnumerationProvider::CreateVisiblePagesEnumeration(mrModel) 116 : model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel)); 117 118 while (aPageEnumeration.HasMoreElements()) 119 { 120 model::SharedPageDescriptor pDescriptor (aPageEnumeration.GetNextElement()); 121 pKeys->push_back(pDescriptor->GetPage()); 122 } 123 124 return pKeys; 125 } 126 127 128 129 130 sal_Int32 ViewCacheContext::GetPriority (cache::CacheKey aKey) 131 { 132 return - (static_cast<const SdrPage*>(aKey)->GetPageNum()-1) / 2; 133 } 134 135 136 137 138 model::SharedPageDescriptor ViewCacheContext::GetDescriptor (cache::CacheKey aKey) 139 { 140 sal_uInt16 nPageIndex ((static_cast<const SdrPage*>(aKey)->GetPageNum() - 1) / 2); 141 return mrModel.GetPageDescriptor(nPageIndex); 142 } 143 144 145 146 147 ::com::sun::star::uno::Reference<com::sun::star::uno::XInterface> ViewCacheContext::GetModel (void) 148 { 149 if (mrModel.GetDocument() == NULL) 150 return NULL; 151 else 152 return mrModel.GetDocument()->getUnoModel(); 153 } 154 155 } } } // end of namespace ::sd::slidesorter::view 156