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