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 .
20 #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_MODEL_SLIDESORTERMODEL_HXX
21 #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_MODEL_SLIDESORTERMODEL_HXX
25 #include "model/SlsPageEnumeration.hxx"
26 #include "model/SlsSharedPageDescriptor.hxx"
29 #include <com/sun/star/drawing/XDrawPage.hpp>
30 #include <osl/mutex.hxx>
31 #include <vcl/region.hxx>
39 namespace sd
{ namespace slidesorter
{
43 namespace sd
{ namespace slidesorter
{ namespace model
{
45 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); }
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.)
53 class SlideSorterModel
56 SlideSorterModel (SlideSorter
& rSlideSorter
);
58 virtual ~SlideSorterModel();
61 /** This method is present to let the view create a ShowView for
64 SdDrawDocument
* GetDocument();
66 /** Set a new edit mode and return whether the edit mode really
67 has been changed. When the edit mode is changed then the
68 previous page descriptor list is replaced by a new one which
71 A return value of <TRUE/> indicates that the edit mode has
72 changed and thus the page descriptor list has been set up
73 to reflect that change. A repaint is necessary.
75 bool SetEditMode (EditMode eEditMode
);
77 /** Set the edit mode to that currently used by the controller.
79 bool SetEditModeFromController();
80 EditMode
GetEditMode() const { return meEditMode
;}
81 PageKind
GetPageType() const { return mePageKind
;}
83 /** Return the number of slides in the document regardless of whether
84 they are visible or not or whether they are hidden or not.
85 The number of slides depends on the set of slides available through
86 the XIndexAccess given to SetDocumentSlides().
88 sal_Int32
GetPageCount() const;
90 /** Return a page descriptor for the page with the specified index.
91 Page descriptors are created on demand. The page descriptor is
92 found (or not found) in constant time.
94 The index of the requested slide. The valid values
95 are 0 to GetPageCount()-1.
97 When <TRUE/> and the requested page descriptor is missing then
98 it is created. When <FALSE/> then an empty reference is
99 returned for missing descriptors.
101 When the given index is not valid, i.e. lower then zero or
102 larger than or equal to the number of pages then an empty
103 reference is returned. Note that the page count may change
104 between calls to GetPageCount() and GetPageDescriptor().
106 SharedPageDescriptor
GetPageDescriptor (
107 const sal_Int32 nPageIndex
,
108 const bool bCreate
= true) const;
110 /** Return a page descriptor for the given XDrawPage. Page descriptors
111 are created on demand. The page descriptor is found (or not found)
112 in (at most) linear time. Note that all page descriptors in front of
113 the one associated with the given XDrawPage are created when not yet
114 present. When the XDrawPage is not found then all descriptors are
117 Returns the index to the requested page descriptor or -1 when
118 there is no such page descriptor.
121 const ::com::sun::star::uno::Reference
<com::sun::star::drawing::XDrawPage
>& rxSlide
) const;
123 /** Return a page descriptor for the given SdrPage. Page descriptors
124 are created on demand. The page descriptor is found (or not found)
125 in (at most) linear time. Note that all page descriptors in front of
126 the one associated with the given XDrawPage are created when not yet
127 present. When the SdrPage is not found then all descriptors are
130 Returns the index to the requested page descriptor or -1 when
131 there is no such page descriptor.
133 sal_Int32
GetIndex (const SdrPage
* pPage
) const;
135 /** Return an index for accessing an SdrModel that corresponds to the
136 given SlideSorterModel index. In many cases we just have to apply
137 the n*2+1 magic. Only when a special model is set, like a custom
138 slide show, then the returned value is different.
140 sal_uInt16
GetCoreIndex (const sal_Int32 nIndex
) const;
142 /** Call this method after the document has changed its structure. This
143 will get the model in sync with the SdDrawDocument. This method
144 tries not to throw away to much information already gathered. This
145 is especially important for previews of complex pages that take some
150 /** Delete all descriptors that currently are in the container. The size
151 of the container, however, is not altered. Use the AdaptSize
154 void ClearDescriptorList();
156 /** Set the selection of the document to exactly that of the called model.
158 void SynchronizeDocumentSelection();
160 /** Set the selection of the called model to exactly that of the document.
162 void SynchronizeModelSelection();
164 /** Return the mutex so that the caller can lock it and then safely
167 ::osl::Mutex
& GetMutex() { return maMutex
;}
169 /** Set the XIndexAccess from which the called SlideSorterModel takes
172 The set of slides accessible through this XIndexAccess are not
173 necessarily the same as the ones of the XModel of the
174 XController (although it typically is a subset).
176 void SetDocumentSlides (const css::uno::Reference
<css::container::XIndexAccess
>& rxSlides
);
178 /** Return the set of pages that is currently displayed by the slide sorter.
180 css::uno::Reference
<css::container::XIndexAccess
> GetDocumentSlides() const;
182 /** This method is called when the edit mode has changed. It calls
183 SetDocumentSlides() with the set of slides or master pages obtained
184 from the model of the XController.
186 void UpdatePageList();
188 bool IsReadOnly() const;
190 /** The current selection is saved by copying the ST_Selected state into
191 ST_WasSelected for slides.
193 void SaveCurrentSelection();
195 /** The current selection is restored from the ST_WasSelected state from
198 The returned region has to be repainted to reflect the updated
201 vcl::Region
RestoreSelection();
203 /** Typically called from controller::Listener this method handles the
204 insertion and deletion of single pages.
206 Returns <TRUE/> when the given page is relevant for the current
207 page kind and edit mode.
209 bool NotifyPageEvent (const SdrPage
* pPage
);
212 mutable ::osl::Mutex maMutex
;
213 SlideSorter
& mrSlideSorter
;
214 ::com::sun::star::uno::Reference
<com::sun::star::container::XIndexAccess
> mxSlides
;
217 typedef ::std::vector
<SharedPageDescriptor
> DescriptorContainer
;
218 mutable DescriptorContainer maPageDescriptors
;
220 /** Resize the descriptor container according to current values of
221 page kind and edit mode.
225 SdPage
* GetPage (const sal_Int32 nCoreIndex
) const;
226 void InsertSlide (SdPage
* pPage
);
227 void DeleteSlide (const SdPage
* pPage
);
228 void UpdateIndices (const sal_Int32 nFirstIndex
);
231 } } } // end of namespace ::sd::slidesorter::model
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */