Update git submodules
[LibreOffice.git] / sd / source / ui / slidesorter / inc / view / SlsLayouter.hxx
blobb91ae83c544cda448b999e14dfea527cfa7ecab9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <vcl/vclptr.hxx>
23 #include <tools/gen.hxx>
24 #include <sal/types.h>
25 #include <memory>
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 {
34 class InsertPosition;
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
44 page objects.
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
51 otherwise.</p>
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
57 objects.</p>
59 class Layouter
61 public:
62 enum Orientation { HORIZONTAL, VERTICAL, GRID };
64 Layouter (
65 sd::Window *rpWindow,
66 const std::shared_ptr<Theme>& rpTheme);
67 ~Layouter();
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.
84 @param eOrientation
85 This defines the generally layout and specifies whether there may
86 be more than one row or more than one column.
87 @param rWindowSize
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.
93 @param rpWindow
94 The map mode of this window is adapted to the new layout of the
95 page objects.
96 @return
97 The return value indicates whether the Get... methods can be
98 used to obtain valid values (<TRUE/>).
100 bool Rearrange (
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
115 object.
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.
128 @return
129 The second index may be larger than the number of existing
130 page objects.
132 Range GetRangeOfVisiblePageObjects (const ::tools::Rectangle& rVisibleArea) const;
134 /** Return the index of the page object that is rendered at the given
135 point.
136 @param rPosition
137 The position is expected to be in model coordinates relative to
138 the page origin.
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
144 has been hit.
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.
150 @return
151 The returned index may be larger than the number of existing
152 page objects.
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
170 bottom of a column.
171 @param rModel
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
174 boxes.
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;
186 private:
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.
194 class InsertPosition
196 public:
197 InsertPosition();
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; }
223 private:
224 sal_Int32 mnRow;
225 sal_Int32 mnColumn;
226 sal_Int32 mnIndex;
227 bool mbIsAtRunStart : 1;
228 bool mbIsAtRunEnd : 1;
229 bool mbIsExtraSpaceNeeded : 1;
230 Point maLocation;
231 Point maLeadingOffset;
232 Point maTrailingOffset;
235 } // end of namespace ::sd::slidesorter::view
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */