LibreOffice Module sd (master) 1
SlsSelectionObserver.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <SlideSorter.hxx>
26#include <sdpage.hxx>
27#include <osl/diagnose.h>
28
30{
32 : mpSelectionObserver(
33 rSlideSorter.GetController().GetSelectionManager()->GetSelectionObserver())
34{
36 mpSelectionObserver->StartObservation();
37}
38
39SelectionObserver::Context::~Context() COVERITY_NOEXCEPT_FALSE
40{
41 if (mpSelectionObserver)
42 mpSelectionObserver->EndObservation();
43}
44
46{
47 if (mpSelectionObserver)
48 {
49 mpSelectionObserver->AbortObservation();
50 mpSelectionObserver.reset();
51 }
52}
53
54//===== SelectionObserver =====================================================
55
57 : mrSlideSorter(rSlideSorter)
59 , mbPageEventOccurred(false)
60{
61}
62
64
66{
68 return;
69
71
72 const SdPage* pPage = dynamic_cast<const SdPage*>(pSdrPage);
73 if (pPage == nullptr)
74 return;
75
76 //NotifyPageEvent is called for add, remove, *and* change position so for
77 //the change position case we must ensure we don't end up with the slide
78 //duplicated in our list
79 std::vector<const SdPage*>::iterator iPage(
80 std::find(maInsertedPages.begin(), maInsertedPages.end(), pPage));
81 if (iPage != maInsertedPages.end())
82 maInsertedPages.erase(iPage);
83
84 if (pPage->IsInserted())
85 maInsertedPages.push_back(pPage);
86}
87
89{
90 OSL_ASSERT(!mbIsObservationActive);
91 maInsertedPages.clear();
93}
94
96{
97 OSL_ASSERT(mbIsObservationActive);
99 maInsertedPages.clear();
100}
101
103{
104 OSL_ASSERT(mbIsObservationActive);
105 mbIsObservationActive = false;
106
108 return;
109
112 rSelector.DeselectAllPages();
113 if (!maInsertedPages.empty())
114 {
115 // Select the inserted pages.
116 for (const auto& rpPage : maInsertedPages)
117 {
118 rSelector.SelectPage(rpPage);
119 }
120 maInsertedPages.clear();
121 }
122
123 aUpdateLock.Release();
125 bool bSuccess = rFocusManager.SetFocusedPageFromCurrentPage();
126 // tdf#129346 nothing currently selected, select something, if possible
127 // but (tdf#129346) only if setting focus to current page failed
128 if (rSelector.GetPageCount() && rSelector.GetSelectedPageCount() == 0)
129 {
130 if (bSuccess)
131 rSelector.SelectPage(rFocusManager.GetFocusedPageDescriptor());
132 else
133 rSelector.SelectPage(0);
134 }
135}
136
137} // end of namespace ::sd::slidesorter::controller
138
139/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsInserted() const
Show previews for all the slides in a document and allow the user to insert or delete slides and modi...
Definition: SlideSorter.hxx:62
SD_DLLPUBLIC controller::SlideSorterController & GetController() const
This class manages the focus of the slide sorter.
model::SharedPageDescriptor GetFocusedPageDescriptor() const
Return the descriptor of the page that currently has the focus.
bool SetFocusedPageFromCurrentPage()
Set the focused page to the one that is the current slide of the Slide Manager.
Use the UpdateLock whenever you do a complex selection, i.e.
A sub-controller that handles page selection of the slide browser.
int GetPageCount() const
This convenience method returns the same number of pages that SlideSorterModel.GetPageCount() returns...
void SelectPage(int nPageIndex)
Select the specified descriptor.
virtual std::shared_ptr< SfxDialogController > GetController() override