1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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(cache::CacheKey aKey
)
50 const model::SharedPageDescriptor
pDescriptor (GetDescriptor(aKey
));
51 if (pDescriptor
.get() != nullptr)
53 // Force a repaint that will trigger their re-creation.
54 mrSlideSorter
.GetView().RequestRepaint(pDescriptor
);
58 // It is OK when a preview was created for a page that is not
59 // currently displayed because both normal and master pages are
60 // kept in the same cache.
64 bool ViewCacheContext::IsIdle()
66 tools::IdleState
nIdleState (tools::IdleDetection::GetIdleState(mrSlideSorter
.GetContentWindow()));
67 return nIdleState
== tools::IdleState::Idle
;
70 bool ViewCacheContext::IsVisible (cache::CacheKey aKey
)
72 const model::SharedPageDescriptor
pDescriptor (GetDescriptor(aKey
));
73 return pDescriptor
&& pDescriptor
->HasState(model::PageDescriptor::ST_Visible
);
76 const SdrPage
* ViewCacheContext::GetPage (cache::CacheKey aKey
)
81 std::shared_ptr
<std::vector
<cache::CacheKey
> > ViewCacheContext::GetEntryList (bool bVisible
)
83 std::shared_ptr
<std::vector
<cache::CacheKey
> > pKeys (new std::vector
<cache::CacheKey
>);
85 model::PageEnumeration
aPageEnumeration (
87 ? model::PageEnumerationProvider::CreateVisiblePagesEnumeration(mrModel
)
88 : model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel
));
90 while (aPageEnumeration
.HasMoreElements())
92 model::SharedPageDescriptor
pDescriptor (aPageEnumeration
.GetNextElement());
93 pKeys
->push_back(pDescriptor
->GetPage());
99 sal_Int32
ViewCacheContext::GetPriority (cache::CacheKey aKey
)
101 return - (aKey
->GetPageNum()-1) / 2;
104 model::SharedPageDescriptor
ViewCacheContext::GetDescriptor (cache::CacheKey aKey
)
106 sal_uInt16
nPageIndex ((aKey
->GetPageNum() - 1) / 2);
107 return mrModel
.GetPageDescriptor(nPageIndex
);
110 css::uno::Reference
<css::uno::XInterface
> ViewCacheContext::GetModel()
112 if (mrModel
.GetDocument() == nullptr)
115 return mrModel
.GetDocument()->getUnoModel();
118 } } } // end of namespace ::sd::slidesorter::view
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */