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