bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / view / SlsViewCacheContext.cxx
blobffd9a825319c25588651ed2887f6e6a32ac60163
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include "SlsViewCacheContext.hxx"
22 #include "SlideSorter.hxx"
23 #include "model/SlideSorterModel.hxx"
24 #include "model/SlsPageDescriptor.hxx"
25 #include "model/SlsPageEnumerationProvider.hxx"
26 #include "view/SlideSorterView.hxx"
27 #include "sdpage.hxx"
28 #include "Window.hxx"
29 #include "drawdoc.hxx"
30 #include "tools/IdleDetection.hxx"
31 #include <svx/svdpage.hxx>
32 #include <svx/sdr/contact/viewcontact.hxx>
33 #include <vcl/window.hxx>
34 #include <svx/sdr/contact/objectcontact.hxx>
36 namespace sd { namespace slidesorter { namespace view {
38 ViewCacheContext::ViewCacheContext (SlideSorter& rSlideSorter)
39 : mrModel(rSlideSorter.GetModel()),
40 mrSlideSorter(rSlideSorter)
44 ViewCacheContext::~ViewCacheContext()
48 void ViewCacheContext::NotifyPreviewCreation (
49 cache::CacheKey aKey,
50 const Bitmap&)
52 const model::SharedPageDescriptor pDescriptor (GetDescriptor(aKey));
53 if (pDescriptor.get() != NULL)
55 // Force a repaint that will trigger their re-creation.
56 mrSlideSorter.GetView().RequestRepaint(pDescriptor);
58 else
60 // It is OK when a preview was created for a page that is not
61 // currently displayed because both normal and master pages are
62 // kept in the same cache.
66 bool ViewCacheContext::IsIdle()
68 sal_Int32 nIdleState (tools::IdleDetection::GetIdleState(mrSlideSorter.GetContentWindow()));
69 if (nIdleState == tools::IdleDetection::IDET_IDLE)
70 return true;
71 else
72 return false;
75 bool ViewCacheContext::IsVisible (cache::CacheKey aKey)
77 const model::SharedPageDescriptor pDescriptor (GetDescriptor(aKey));
78 return pDescriptor && pDescriptor->HasState(model::PageDescriptor::ST_Visible);
81 const SdrPage* ViewCacheContext::GetPage (cache::CacheKey aKey)
83 return static_cast<const SdrPage*>(aKey);
86 ::boost::shared_ptr<std::vector<cache::CacheKey> > ViewCacheContext::GetEntryList (bool bVisible)
88 ::boost::shared_ptr<std::vector<cache::CacheKey> > pKeys (new std::vector<cache::CacheKey>());
90 model::PageEnumeration aPageEnumeration (
91 bVisible
92 ? model::PageEnumerationProvider::CreateVisiblePagesEnumeration(mrModel)
93 : model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
95 while (aPageEnumeration.HasMoreElements())
97 model::SharedPageDescriptor pDescriptor (aPageEnumeration.GetNextElement());
98 pKeys->push_back(pDescriptor->GetPage());
101 return pKeys;
104 sal_Int32 ViewCacheContext::GetPriority (cache::CacheKey aKey)
106 return - (static_cast<const SdrPage*>(aKey)->GetPageNum()-1) / 2;
109 model::SharedPageDescriptor ViewCacheContext::GetDescriptor (cache::CacheKey aKey)
111 sal_uInt16 nPageIndex ((static_cast<const SdrPage*>(aKey)->GetPageNum() - 1) / 2);
112 return mrModel.GetPageDescriptor(nPageIndex);
115 ::com::sun::star::uno::Reference<com::sun::star::uno::XInterface> ViewCacheContext::GetModel()
117 if (mrModel.GetDocument() == NULL)
118 return NULL;
119 else
120 return mrModel.GetDocument()->getUnoModel();
123 } } } // end of namespace ::sd::slidesorter::view
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */