Line data Source code
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 : #ifndef SD_SLIDESORTER_SLIDE_SORTER_MODEL_HXX
21 : #define SD_SLIDESORTER_SLIDE_SORTER_MODEL_HXX
22 :
23 : class SdDrawDocument;
24 :
25 : #include "model/SlsPageEnumeration.hxx"
26 : #include "model/SlsSharedPageDescriptor.hxx"
27 :
28 : #include "pres.hxx"
29 : #include <com/sun/star/drawing/XDrawPage.hpp>
30 : #include <osl/mutex.hxx>
31 : #include <vcl/region.hxx>
32 :
33 : #include <memory>
34 : #include <vector>
35 : #include <functional>
36 :
37 : class SdrPage;
38 : class SdPage;
39 :
40 : namespace sd { namespace slidesorter {
41 : class SlideSorter;
42 : } }
43 :
44 : namespace sd { namespace slidesorter { namespace model {
45 :
46 10 : inline sal_Int32 FromCoreIndex (const sal_uInt16 nCoreIndex) { return (nCoreIndex-1)/2; }
47 : inline sal_uInt16 ToCoreIndex (const sal_Int32 nIndex) { return nIndex*2+1; }
48 :
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.)
53 : */
54 : class SlideSorterModel
55 : {
56 : public:
57 : SlideSorterModel (SlideSorter& rSlideSorter);
58 : void Init (void);
59 :
60 : virtual ~SlideSorterModel (void);
61 : void Dispose (void);
62 :
63 : /** This method is present to let the view create a ShowView for
64 : displaying slides.
65 : */
66 : SdDrawDocument* GetDocument (void);
67 :
68 : /** Set a new edit mode and return whether the edit mode really
69 : has been changed. When the edit mode is changed then the
70 : previous page descriptor list is replaced by a new one which
71 : has to be repainted.
72 : @return
73 : A return value of <TRUE/> indicates that the edit mode has
74 : changed and thus the page descriptor list has been set up
75 : to reflect that change. A repaint is necessary.
76 : */
77 : bool SetEditMode (EditMode eEditMode);
78 :
79 : /** Set the edit mode to that currently used by the controller.
80 : */
81 : bool SetEditModeFromController (void);
82 : EditMode GetEditMode (void) const;
83 : PageKind GetPageType (void) const;
84 :
85 : /** Return the number of slides in the document regardless of whether
86 : they are visible or not or whether they are hidden or not.
87 : The number of slides depends on the set of slides available through
88 : the XIndexAccess given to SetDocumentSlides().
89 : */
90 : sal_Int32 GetPageCount (void) const;
91 :
92 : /** Return a page descriptor for the page with the specified index.
93 : Page descriptors are created on demand. The page descriptor is
94 : found (or not found) in constant time.
95 : @param nPageIndex
96 : The index of the requested slide. The valid values
97 : are 0 to GetPageCount()-1.
98 : @param bCreate
99 : When <TRUE/> and the requested page descriptor is missing then
100 : it is created. When <FALSE/> then an empty reference is
101 : returned for missing descriptors.
102 : @return
103 : When the given index is not valid, i.e. lower then zero or
104 : larger than or equal to the number of pages then an empty
105 : reference is returned. Note that the page count may change
106 : between calls to GetPageCount() and GetPageDescriptor().
107 : */
108 : SharedPageDescriptor GetPageDescriptor (
109 : const sal_Int32 nPageIndex,
110 : const bool bCreate = true) const;
111 :
112 : /** Return a page descriptor for the given XDrawPage. Page descriptors
113 : are created on demand. The page descriptor is found (or not found)
114 : in (at most) linear time. Note that all page descriptors in front of
115 : the one associated with the given XDrawPage are created when not yet
116 : present. When the XDrawPage is not found then all descriptors are
117 : created.
118 : @return
119 : Returns the index to the requested page descriptor or -1 when
120 : there is no such page descriptor.
121 : */
122 : sal_Int32 GetIndex (
123 : const ::com::sun::star::uno::Reference<com::sun::star::drawing::XDrawPage>& rxSlide) const;
124 :
125 : /** Return a page descriptor for the given SdrPage. Page descriptors
126 : are created on demand. The page descriptor is found (or not found)
127 : in (at most) linear time. Note that all page descriptors in front of
128 : the one associated with the given XDrawPage are created when not yet
129 : present. When the SdrPage is not found then all descriptors are
130 : created.
131 : @return
132 : Returns the index to the requested page descriptor or -1 when
133 : there is no such page descriptor.
134 : */
135 : sal_Int32 GetIndex (const SdrPage* pPage) const;
136 :
137 : /** Return an index for accessing an SdrModel that corresponds to the
138 : given SlideSorterModel index. In many cases we just have to apply
139 : the n*2+1 magic. Only when a special model is set, like a custom
140 : slide show, then the returned value is different.
141 : */
142 : sal_uInt16 GetCoreIndex (const sal_Int32 nIndex) const;
143 :
144 : /** Call this method after the document has changed its structure. This
145 : will get the model in sync with the SdDrawDocument. This method
146 : tries not to throw away to much information already gathered. This
147 : is especially important for previews of complex pages that take some
148 : time to create.
149 : */
150 : void Resync (void);
151 :
152 : /** Delete all descriptors that currently are in the container. The size
153 : of the container, however, is not altered. Use the AdaptSize
154 : method for that.
155 : */
156 : void ClearDescriptorList (void);
157 :
158 : /** Set the selection of the document to exactly that of the called model.
159 : */
160 : void SynchronizeDocumentSelection (void);
161 :
162 : /** Set the selection of the called model to exactly that of the document.
163 : */
164 : void SynchronizeModelSelection (void);
165 :
166 : /** Return the mutex so that the caller can lock it and then safely
167 : access the model.
168 : */
169 : ::osl::Mutex& GetMutex (void);
170 :
171 : /** Set the XIndexAccess from which the called SlideSorterModel takes
172 : its pages.
173 : @param rxSlides
174 : The set of slides accessible through this XIndexAccess are not
175 : necessarily the same as the ones of the XModel of the
176 : XController (although it typically is a subset).
177 : */
178 : void SetDocumentSlides (const css::uno::Reference<css::container::XIndexAccess>& rxSlides);
179 :
180 : /** Return the set of pages that is currently displayed by the slide sorter.
181 : */
182 : css::uno::Reference<css::container::XIndexAccess> GetDocumentSlides (void) const;
183 :
184 : /** This method is called when the edit mode has changed. It calls
185 : SetDocumentSlides() with the set of slides or master pages obtained
186 : from the model of the XController.
187 : */
188 : void UpdatePageList (void);
189 :
190 : bool IsReadOnly (void) const;
191 :
192 : /** The current selection is saved by copying the ST_Selected state into
193 : ST_WasSelected for slides.
194 : */
195 : void SaveCurrentSelection (void);
196 :
197 : /** The current selection is restored from the ST_WasSelected state from
198 : the slides.
199 : @returns
200 : The returned region has to be repainted to reflect the updated
201 : selection states.
202 : */
203 : Region RestoreSelection (void);
204 :
205 : /** Typically called from controller::Listener this method handles the
206 : insertion and deletion of single pages.
207 : @return
208 : Returns <TRUE/> when the given page is relevant for the current
209 : page kind and edit mode.
210 : */
211 : bool NotifyPageEvent (const SdrPage* pPage);
212 :
213 : private:
214 : mutable ::osl::Mutex maMutex;
215 : SlideSorter& mrSlideSorter;
216 : ::com::sun::star::uno::Reference<com::sun::star::container::XIndexAccess> mxSlides;
217 : PageKind mePageKind;
218 : EditMode meEditMode;
219 : typedef ::std::vector<SharedPageDescriptor> DescriptorContainer;
220 : mutable DescriptorContainer maPageDescriptors;
221 :
222 : /** Resize the descriptor container according to current values of
223 : page kind and edit mode.
224 : */
225 : void AdaptSize (void);
226 :
227 : SdPage* GetPage (const sal_Int32 nCoreIndex) const;
228 : void InsertSlide (SdPage* pPage);
229 : void DeleteSlide (const SdPage* pPage);
230 : void UpdateIndices (const sal_Int32 nFirstIndex);
231 : };
232 :
233 : } } } // end of namespace ::sd::slidesorter::model
234 :
235 : #endif
236 :
237 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|