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 <SlideSorter.hxx>
21 #include <controller/SlideSorterController.hxx>
22 #include <controller/SlsSelectionManager.hxx>
23 #include <controller/SlsSelectionObserver.hxx>
24 #include <controller/SlsPageSelector.hxx>
25 #include <controller/SlsFocusManager.hxx>
26 #include <model/SlideSorterModel.hxx>
27 #include <model/SlsPageDescriptor.hxx>
28 #include <svx/svdmodel.hxx>
29 #include <drawdoc.hxx>
32 namespace sd
{ namespace slidesorter
{ namespace controller
{
34 SelectionObserver::Context::Context (SlideSorter
const & rSlideSorter
)
35 : mpSelectionObserver(
36 rSlideSorter
.GetController().GetSelectionManager()->GetSelectionObserver())
38 if (mpSelectionObserver
)
39 mpSelectionObserver
->StartObservation();
42 SelectionObserver::Context::~Context() COVERITY_NOEXCEPT_FALSE
44 if (mpSelectionObserver
)
45 mpSelectionObserver
->EndObservation();
48 void SelectionObserver::Context::Abort()
50 if (mpSelectionObserver
)
52 mpSelectionObserver
->AbortObservation();
53 mpSelectionObserver
.reset();
57 //===== SelectionObserver =====================================================
59 SelectionObserver::SelectionObserver (SlideSorter
& rSlideSorter
)
60 : mrSlideSorter(rSlideSorter
)
61 , mbIsObservationActive(false)
62 , mbPageEventOccurred(false)
67 SelectionObserver::~SelectionObserver()
71 void SelectionObserver::NotifyPageEvent (const SdrPage
* pSdrPage
)
73 if (!mbIsObservationActive
)
76 mbPageEventOccurred
= true;
78 const SdPage
* pPage
= dynamic_cast<const SdPage
*>(pSdrPage
);
82 //NotifyPageEvent is called for add, remove, *and* change position so for
83 //the change position case we must ensure we don't end up with the slide
84 //duplicated in our list
85 std::vector
<const SdPage
*>::iterator
iPage(
86 std::find(maInsertedPages
.begin(), maInsertedPages
.end(), pPage
));
87 if (iPage
!= maInsertedPages
.end())
88 maInsertedPages
.erase(iPage
);
90 if (pPage
->IsInserted())
91 maInsertedPages
.push_back(pPage
);
94 void SelectionObserver::StartObservation()
96 OSL_ASSERT(!mbIsObservationActive
);
97 maInsertedPages
.clear();
98 mbIsObservationActive
= true;
101 void SelectionObserver::AbortObservation()
103 OSL_ASSERT(mbIsObservationActive
);
104 mbIsObservationActive
= false;
105 maInsertedPages
.clear();
108 void SelectionObserver::EndObservation()
110 OSL_ASSERT(mbIsObservationActive
);
111 mbIsObservationActive
= false;
113 if (!mbPageEventOccurred
)
116 PageSelector
& rSelector (mrSlideSorter
.GetController().GetPageSelector());
117 PageSelector::UpdateLock
aUpdateLock (mrSlideSorter
);
118 rSelector
.DeselectAllPages();
119 if ( ! maInsertedPages
.empty())
121 // Select the inserted pages.
122 for (const auto& rpPage
: maInsertedPages
)
124 rSelector
.SelectPage(rpPage
);
126 maInsertedPages
.clear();
129 aUpdateLock
.Release();
130 mrSlideSorter
.GetController().GetFocusManager().SetFocusedPageToCurrentPage();
134 } } } // end of namespace ::sd::slidesorter::controller
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */