Update git submodules
[LibreOffice.git] / sd / source / ui / slidesorter / inc / controller / SlsSelectionManager.hxx
blob4f52d49e617a7ee533d10cb3eb04c7062bce945e
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 #pragma once
22 #include <sal/types.h>
23 #include <tools/link.hxx>
24 #include <vector>
25 #include <memory>
27 class SdPage;
29 namespace sd::slidesorter
31 class SlideSorter;
34 namespace sd::slidesorter::controller
36 class SlideSorterController;
37 class SelectionObserver;
39 /** This class is a part of the controller and handles the selection of
40 slides.
41 <p>It has methods to modify the selected slides (delete them or
42 move them to other places in the document), change the visible area so
43 to make the selected slides visible, tell listeners when the selection
44 changes.</p>
46 class SelectionManager
48 public:
49 /** Create a new SelectionManager for the given slide sorter.
51 SelectionManager(SlideSorter& rSlideSorter);
53 ~SelectionManager();
55 /** Delete the currently selected slides. When this method returns the
56 selection is empty.
57 @param bSelectFollowingPage
58 When <TRUE/> then after deleting the selected pages make the
59 slide after the last selected page the new current page.
60 When <FALSE/> then make the first slide before the selected
61 pages the new current slide.
63 void DeleteSelectedPages(const bool bSelectFollowingPage = true);
65 /** Call this method after the selection has changed (possible several
66 calls to the PageSelector) to invalidate the relevant slots and send
67 appropriate events.
69 void SelectionHasChanged();
71 /** Add a listener that is called when the selection of the slide sorter
72 changes.
73 @param rListener
74 When this method is called multiple times for the same listener
75 the second and all following calls are ignored. Each listener
76 is added only once.
78 void AddSelectionChangeListener(const Link<LinkParamNone*, void>& rListener);
80 /** Remove a listener that was called when the selection of the slide
81 sorter changes.
82 @param rListener
83 It is safe to pass a listener that was not added are has been
84 removed previously. Such calls are ignored.
86 void RemoveSelectionChangeListener(const Link<LinkParamNone*, void>& rListener);
88 /** Return the position where to insert pasted slides based on the
89 current selection. When there is a selection then the insert
90 position is behind the last slide. When the selection is empty then
91 most of the time the insert position is at the end of the document.
92 There is an exception right after the display of a popup-menu. The
93 position of the associated insertion marker is stored here and reset
94 the next time the selection changes.
96 sal_Int32 GetInsertionPosition() const;
98 /** Store an insertion position temporarily. It is reset when the
99 selection changes the next time.
101 void SetInsertionPosition(const sal_Int32 nInsertionPosition);
103 const std::shared_ptr<SelectionObserver>& GetSelectionObserver() const
105 return mpSelectionObserver;
108 private:
109 SlideSorter& mrSlideSorter;
110 SlideSorterController& mrController;
112 ::std::vector<Link<LinkParamNone*, void>> maSelectionChangeListeners;
114 /** The insertion position is only temporarily valid. Negative values
115 indicate that the explicit insertion position is not valid. In this
116 case GetInsertionPosition() calculates it from the current selection.
118 sal_Int32 mnInsertionPosition;
120 std::shared_ptr<SelectionObserver> mpSelectionObserver;
122 /** Delete the given list of normal pages. This method is a helper
123 function for DeleteSelectedPages().
124 @param rSelectedNormalPages
125 A list of normal pages. Supplying master pages is an error.
127 void DeleteSelectedNormalPages(const ::std::vector<SdPage*>& rSelectedNormalPages);
129 /** Delete the given list of master pages. This method is a helper
130 function for DeleteSelectedPages().
131 @param rSelectedMasterPages
132 A list of master pages. Supplying normal pages is an error.
134 void DeleteSelectedMasterPages(const ::std::vector<SdPage*>& rSelectedMasterPages);
137 } // end of namespace ::sd::slidesorter::controller
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */