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 <vcl/vclptr.hxx>
23 #include <tools/gen.hxx>
24 #include <sal/types.h>
27 namespace sd
{ class Window
; }
28 namespace sd::slidesorter::model
{ class SlideSorterModel
; }
29 namespace sd::slidesorter::view
{ class PageObjectLayouter
; }
30 namespace sd::slidesorter::view
{ class Theme
; }
32 namespace sd::slidesorter::view
{
36 /** Calculate the size and position of page objects displayed by a slide
37 sorter. The layouter takes into account various input values:
38 1.) Size of the window in which the slide sorter is displayed.
39 2.) Desired and minimal and maximal widths of page objects.
40 3.) Minimal and maximal number of columns.
41 4.) Vertical and horizontal gaps between objects in adjacent columns.
42 5.) Borders around every page object.
43 6.) Vertical and horizontal borders between enclosing page and outer
45 From these, it calculates various output values:
46 1.) The width of page objects.
47 2.) The number of columns.
48 3.) The size of the enclosing page.
50 <p>Sizes and lengths are all in pixel except where explicitly stated
53 <p>The GetIndex... methods may return indices that are larger than or
54 equal to (zero based) the number of pages. This is so because the
55 number of pages is not known to the class instances. Indices are
56 calculated with reference to the general grid layout of page
62 enum Orientation
{ HORIZONTAL
, VERTICAL
, GRID
};
66 const std::shared_ptr
<Theme
>& rpTheme
);
69 std::shared_ptr
<PageObjectLayouter
> const & GetPageObjectLayouter() const;
70 /** Set the interval of valid column counts. When nMinimalColumnCount
71 <= nMaximalColumnCount is not fulfilled then the call is ignored.
72 @param nMinimalColumnCount
73 The default value is 1. The question whether higher values make
74 any sense is left to the caller.
75 @param nMaximalColumnCount
76 The default value is 5.
78 void SetColumnCount (sal_Int32 nMinimalColumnCount
,
79 sal_Int32 nMaximalColumnCount
);
81 /** Central method of this class. It takes the input values and
82 calculates the output values. Both given sizes must not be 0 in any
83 dimension or the call is ignored.
85 This defines the generally layout and specifies whether there may
86 be more than one row or more than one column.
88 The size of the window in pixels that the slide sorter is
89 displayed in. This can differ from the size of mpWindow during
90 detection of whether or not the scroll bars should be visible.
91 @param rPreviewModelSize
92 Size of each page in model coordinates.
94 The map mode of this window is adapted to the new layout of the
97 The return value indicates whether the Get... methods can be
98 used to obtain valid values (<TRUE/>).
101 const Orientation eOrientation
,
102 const Size
& rWindowSize
,
103 const Size
& rPreviewModelSize
,
104 const sal_uInt32 nPageCount
);
106 /** Return the number of columns.
108 sal_Int32
GetColumnCount() const;
110 sal_Int32
GetIndex (const sal_Int32 nRow
, const sal_Int32 nColumn
) const;
112 Size
const & GetPageObjectSize() const;
114 /** Return the bounding box in window coordinates of the nIndex-th page
117 ::tools::Rectangle
GetPageObjectBox (
118 const sal_Int32 nIndex
,
119 const bool bIncludeBorderAndGap
) const;
121 /** Return the bounding box in model coordinates of the page that
122 contains the given amount of page objects.
124 ::tools::Rectangle
GetTotalBoundingBox() const;
126 /** Return the index of the first fully or partially visible page
127 object. This takes into account only the vertical dimension.
129 The second index may be larger than the number of existing
132 Range
GetRangeOfVisiblePageObjects (const ::tools::Rectangle
& rVisibleArea
) const;
134 /** Return the index of the page object that is rendered at the given
137 The position is expected to be in model coordinates relative to
139 @param bIncludePageBorders
140 When <TRUE/> then include the page borders into the calculation,
141 i.e. when a point lies in the border of a page object but not on
142 the actual page area the index of that page is returned;
143 otherwise -1 would be returned to indicate that no page object
145 @param bClampToValidRange
146 When <TRUE/> then values outside the valid range [0,mnPageCount)
147 are mapped to 0 (when smaller than 0) or mnPageCount-1 when
148 equal to or larger than mnPageCount.
149 When <FALSE/> then -1 is returned for values outside the valid range.
151 The returned index may be larger than the number of existing
154 sal_Int32
GetIndexAtPoint (
155 const Point
& rModelPosition
,
156 const bool bIncludePageBorders
,
157 const bool bClampToValidRange
= true) const;
159 /** Return an object that describes the logical and visual properties of
160 where to do an insert operation when the user would release the
161 mouse button at the given position after a drag operation and of
162 where and how to display an insertion indicator.
163 @param rModelPosition
164 The position in the model coordinate system for which to
165 determine the insertion page index. The position does not have
166 to be over a page object to return a valid value.
167 @param rIndicatorSize
168 The size of the insertion indicator. This size is used to adapt
169 the location when at the left or right of a row or at the top or
172 The model is used to get access to the selection states of the
173 pages. This in turn is used to determine the visual bounding
176 InsertPosition
GetInsertPosition (
177 const Point
& rModelPosition
,
178 const Size
& rIndicatorSize
,
179 model::SlideSorterModel
const & rModel
) const;
181 Range
GetValidHorizontalSizeRange() const;
182 Range
GetValidVerticalSizeRange() const;
184 class Implementation
;
187 std::unique_ptr
<Implementation
> mpImplementation
;
188 VclPtr
<sd::Window
> mpWindow
;
191 /** Collect all values concerning the logical and visual properties of the
192 insertion position that is used for drag-and-drop and copy-and-paste.
198 bool operator== (const InsertPosition
& rInsertPosition
) const;
199 bool operator!= (const InsertPosition
& rInsertPosition
) const;
201 void SetLogicalPosition (
202 const sal_Int32 nRow
,
203 const sal_Int32 nColumn
,
204 const sal_Int32 nIndex
,
205 const bool bIsAtRunStart
,
206 const bool bIsAtRunEnd
,
207 const bool bIsExtraSpaceNeeded
);
208 void SetGeometricalPosition(
209 const Point
& rLocation
,
210 const Point
& rLeadingOffset
,
211 const Point
& rTrailingOffset
);
213 sal_Int32
GetRow() const { return mnRow
; }
214 sal_Int32
GetColumn() const { return mnColumn
; }
215 sal_Int32
GetIndex() const { return mnIndex
; }
216 const Point
& GetLocation() const { return maLocation
; }
217 const Point
& GetLeadingOffset() const { return maLeadingOffset
; }
218 const Point
& GetTrailingOffset() const { return maTrailingOffset
; }
219 bool IsAtRunStart() const { return mbIsAtRunStart
; }
220 bool IsAtRunEnd() const { return mbIsAtRunEnd
; }
221 bool IsExtraSpaceNeeded() const { return mbIsExtraSpaceNeeded
; }
227 bool mbIsAtRunStart
: 1;
228 bool mbIsAtRunEnd
: 1;
229 bool mbIsExtraSpaceNeeded
: 1;
231 Point maLeadingOffset
;
232 Point maTrailingOffset
;
235 } // end of namespace ::sd::slidesorter::view
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */