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 .
22 #include <model/SlsSharedPageDescriptor.hxx>
24 #include <osl/mutex.hxx>
25 #include <vcl/region.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
32 namespace sd::slidesorter
36 namespace com::sun::star::container
40 namespace com::sun::star::drawing
45 namespace sd::slidesorter::model
47 inline sal_Int32
FromCoreIndex(const sal_uInt16 nCoreIndex
) { return (nCoreIndex
- 1) / 2; }
49 /** The model of the slide sorter gives access to the slides that are to be
50 displayed in the slide sorter view. Via the SetDocumentSlides() method
51 this set of slides can be modified (but do not call it directly, use
52 SlideSorterController::SetDocumentSlides() instead.)
54 class SlideSorterModel final
57 SlideSorterModel(SlideSorter
& rSlideSorter
);
62 /** This method is present to let the view create a ShowView for
65 SdDrawDocument
* GetDocument();
67 /** Set a new edit mode and return whether the edit mode really
68 has been changed. When the edit mode is changed then the
69 previous page descriptor list is replaced by a new one which
72 A return value of <TRUE/> indicates that the edit mode has
73 changed and thus the page descriptor list has been set up
74 to reflect that change. A repaint is necessary.
76 bool SetEditMode(EditMode eEditMode
);
78 EditMode
GetEditMode() const { return meEditMode
; }
80 /** Return the number of slides in the document regardless of whether
81 they are visible or not or whether they are hidden or not.
82 The number of slides depends on the set of slides available through
83 the XIndexAccess given to SetDocumentSlides().
85 sal_Int32
GetPageCount() const;
87 /** Return a page descriptor for the page with the specified index.
88 Page descriptors are created on demand. The page descriptor is
89 found (or not found) in constant time.
91 The index of the requested slide. The valid values
92 are 0 to GetPageCount()-1.
94 When <TRUE/> and the requested page descriptor is missing then
95 it is created. When <FALSE/> then an empty reference is
96 returned for missing descriptors.
98 When the given index is not valid, i.e. lower than zero or
99 larger than or equal to the number of pages then an empty
100 reference is returned. Note that the page count may change
101 between calls to GetPageCount() and GetPageDescriptor().
103 SharedPageDescriptor
GetPageDescriptor(const sal_Int32 nPageIndex
,
104 const bool bCreate
= true) const;
106 /** Return a page descriptor for the given XDrawPage. Page descriptors
107 are created on demand. The page descriptor is found (or not found)
108 in (at most) linear time. Note that all page descriptors in front of
109 the one associated with the given XDrawPage are created when not yet
110 present. When the XDrawPage is not found then all descriptors are
113 Returns the index to the requested page descriptor or -1 when
114 there is no such page descriptor.
116 sal_Int32
GetIndex(const css::uno::Reference
<css::drawing::XDrawPage
>& rxSlide
) const;
118 /** Return a page descriptor for the given SdrPage. Page descriptors
119 are created on demand. The page descriptor is found (or not found)
120 in (at most) linear time. Note that all page descriptors in front of
121 the one associated with the given XDrawPage are created when not yet
122 present. When the SdrPage is not found then all descriptors are
125 Returns the index to the requested page descriptor or -1 when
126 there is no such page descriptor.
128 sal_Int32
GetIndex(const SdrPage
* pPage
) const;
130 /** Return an index for accessing an SdrModel that corresponds to the
131 given SlideSorterModel index. In many cases we just have to apply
132 the n*2+1 magic. Only when a special model is set, like a custom
133 slide show, then the returned value is different.
135 sal_uInt16
GetCoreIndex(const sal_Int32 nIndex
) const;
137 /** Call this method after the document has changed its structure. This
138 will get the model in sync with the SdDrawDocument. This method
139 tries not to throw away too much information already gathered. This
140 is especially important for previews of complex pages that take some
145 /** Delete all descriptors that currently are in the container. The size
146 of the container, however, is not altered. Use the AdaptSize
149 void ClearDescriptorList();
151 /** Set the selection of the document to exactly that of the called model.
153 void SynchronizeDocumentSelection();
155 /** Set the selection of the called model to exactly that of the document.
157 void SynchronizeModelSelection();
159 /** Return the mutex so that the caller can lock it and then safely
162 ::osl::Mutex
& GetMutex() { return maMutex
; }
164 /** Set the XIndexAccess from which the called SlideSorterModel takes
167 The set of slides accessible through this XIndexAccess are not
168 necessarily the same as the ones of the XModel of the
169 XController (although it typically is a subset).
171 void SetDocumentSlides(const css::uno::Reference
<css::container::XIndexAccess
>& rxSlides
);
173 /** Return the set of pages that is currently displayed by the slide sorter.
175 css::uno::Reference
<css::container::XIndexAccess
> GetDocumentSlides() const;
177 /** This method is called when the edit mode has changed. It calls
178 SetDocumentSlides() with the set of slides or master pages obtained
179 from the model of the XController.
181 void UpdatePageList();
183 bool IsReadOnly() const;
185 /** The current selection is saved by copying the ST_Selected state into
186 ST_WasSelected for slides.
188 void SaveCurrentSelection();
190 /** The current selection is restored from the ST_WasSelected state from
193 The returned region has to be repainted to reflect the updated
196 vcl::Region
RestoreSelection();
198 /** Typically called from controller::Listener this method handles the
199 insertion and deletion of single pages.
201 Returns <TRUE/> when the given page is relevant for the current
202 page kind and edit mode.
204 bool NotifyPageEvent(const SdrPage
* pPage
);
207 mutable ::osl::Mutex maMutex
;
208 SlideSorter
& mrSlideSorter
;
209 css::uno::Reference
<css::container::XIndexAccess
> mxSlides
;
211 mutable ::std::vector
<SharedPageDescriptor
> maPageDescriptors
;
213 /** Resize the descriptor container according to current values of
214 page kind and edit mode.
218 SdPage
* GetPage(const sal_Int32 nCoreIndex
) const;
219 void InsertSlide(SdPage
* pPage
, bool bMarkSelected
);
220 // return if this page was marked as selected before being removed
221 bool DeleteSlide(const SdPage
* pPage
);
222 void UpdateIndices(const sal_Int32 nFirstIndex
);
225 } // end of namespace ::sd::slidesorter::model
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */