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>
33 namespace sd::slidesorter::view
{
35 ViewCacheContext::ViewCacheContext (SlideSorter
& rSlideSorter
)
36 : mrModel(rSlideSorter
.GetModel()),
37 mrSlideSorter(rSlideSorter
)
41 ViewCacheContext::~ViewCacheContext()
45 void ViewCacheContext::NotifyPreviewCreation(cache::CacheKey aKey
)
47 const model::SharedPageDescriptor
pDescriptor (GetDescriptor(aKey
));
50 // Force a repaint that will trigger their re-creation.
51 mrSlideSorter
.GetView().RequestRepaint(pDescriptor
);
55 // It is OK when a preview was created for a page that is not
56 // currently displayed because both normal and master pages are
57 // kept in the same cache.
61 bool ViewCacheContext::IsIdle()
63 tools::IdleState
nIdleState (tools::IdleDetection::GetIdleState(mrSlideSorter
.GetContentWindow()));
64 return nIdleState
== tools::IdleState::Idle
;
67 bool ViewCacheContext::IsVisible (cache::CacheKey aKey
)
69 const model::SharedPageDescriptor
pDescriptor (GetDescriptor(aKey
));
70 return pDescriptor
&& pDescriptor
->HasState(model::PageDescriptor::ST_Visible
);
73 const SdrPage
* ViewCacheContext::GetPage (cache::CacheKey aKey
)
78 std::shared_ptr
<std::vector
<cache::CacheKey
> > ViewCacheContext::GetEntryList (bool bVisible
)
80 auto pKeys
= std::make_shared
<std::vector
<cache::CacheKey
>>();
82 model::PageEnumeration
aPageEnumeration (
84 ? model::PageEnumerationProvider::CreateVisiblePagesEnumeration(mrModel
)
85 : model::PageEnumerationProvider::CreateAllPagesEnumeration(mrModel
));
87 while (aPageEnumeration
.HasMoreElements())
89 model::SharedPageDescriptor
pDescriptor (aPageEnumeration
.GetNextElement());
90 pKeys
->push_back(pDescriptor
->GetPage());
96 sal_Int32
ViewCacheContext::GetPriority (cache::CacheKey aKey
)
98 return - (aKey
->GetPageNum()-1) / 2;
101 model::SharedPageDescriptor
ViewCacheContext::GetDescriptor (cache::CacheKey aKey
)
103 sal_uInt16
nPageIndex ((aKey
->GetPageNum() - 1) / 2);
104 return mrModel
.GetPageDescriptor(nPageIndex
);
107 SdXImpressDocument
* ViewCacheContext::GetModel()
109 if (mrModel
.GetDocument() == nullptr)
112 return mrModel
.GetDocument()->getUnoModel();
115 } // end of namespace ::sd::slidesorter::view
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */