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_VIEW_LAYOUTER_HXX
21 : #define SD_SLIDESORTER_VIEW_LAYOUTER_HXX
22 :
23 : #include "SlideSorter.hxx"
24 : #include "view/SlsPageObjectLayouter.hxx"
25 : #include "view/SlsTheme.hxx"
26 : #include <sal/types.h>
27 : #include <tools/fract.hxx>
28 : #include <vcl/mapmod.hxx>
29 : #include <vector>
30 : #include <utility>
31 :
32 :
33 : class Size;
34 :
35 : namespace sd { namespace slidesorter { namespace view {
36 :
37 : class InsertPosition;
38 :
39 :
40 :
41 : /** Calculate the size and position of page objects displayed by a slide
42 : sorter. The layouter takes into account various input values:
43 : 1.) Size of the window in which the slide sorter is displayed.
44 : 2.) Desired and minimal and maximal widths of page objects.
45 : 3.) Minimal and maximal number of columns.
46 : 4.) Vertical and horizontal gaps between objects in adjacent columns.
47 : 5.) Borders arround every page object.
48 : 6.) Vertical and horizontal borders between enclosing page and outer
49 : page objects.
50 : From these it calculates various output values:
51 : 1.) The width of page objects.
52 : 2.) The number of columns.
53 : 3.) The size of the enclosing page.
54 :
55 : <p>Sizes and lengths are all in pixel except where explicitly stated
56 : otherwise.</p>
57 :
58 : <p>The GetIndex... methods may return indices that are larger than or
59 : equal to (zero based) the number of pages. This is so because the
60 : number of pages is not known to the class instances. Indices are
61 : calculated with reference to the general grid layout of page
62 : objects.</p>
63 : */
64 : class Layouter
65 : {
66 : public:
67 : enum Orientation { HORIZONTAL, VERTICAL, GRID };
68 :
69 : Layouter (
70 : const SharedSdWindow& rpWindow,
71 : const ::boost::shared_ptr<Theme>& rpTheme);
72 : ~Layouter (void);
73 :
74 : ::boost::shared_ptr<PageObjectLayouter> GetPageObjectLayouter (void) const;
75 : /** Set the interval of valid column counts. When nMinimalColumnCount
76 : <= nMaximalColumnCount is not fullfilled then the call is ignored.
77 : @param nMinimalColumnCount
78 : The default value is 1. The question whether higher values make
79 : any sense is left to the caller.
80 : @param nMaximalColumnCount
81 : The default value is 5.
82 : */
83 : void SetColumnCount (sal_Int32 nMinimalColumnCount,
84 : sal_Int32 nMaximalColumnCount);
85 :
86 : /** Central method of this class. It takes the input values and
87 : calculates the output values. Both given sizes must not be 0 in any
88 : dimension or the call is ignored.
89 : @param eOrientation
90 : This defines the generaly layout and specifies whether there may
91 : be more than one row or more than one column.
92 : @param rWindowSize
93 : The size of the window in pixels that the slide sorter is
94 : displayed in. This can differ from the size of mpWindow during
95 : detection of whether or not the scroll bars should be visible.
96 : @param rPreviewModelSize
97 : Size of each page in model coordinates.
98 : @param rpWindow
99 : The map mode of this window is adapted to the new layout of the
100 : page objects.
101 : @return
102 : The return value indicates whether the Get... methods can be
103 : used to obtain valid values (<TRUE/>).
104 : */
105 : bool Rearrange (
106 : const Orientation eOrientation,
107 : const Size& rWindowSize,
108 : const Size& rPreviewModelSize,
109 : const sal_uInt32 nPageCount);
110 :
111 : /** Return the number of columns.
112 : */
113 : sal_Int32 GetColumnCount (void) const;
114 :
115 : sal_Int32 GetIndex (const sal_Int32 nRow, const sal_Int32 nColumn) const;
116 :
117 : /** Return the scale factor that can be set at the map mode of the
118 : output window.
119 : */
120 : Fraction GetScaleFactor (void) const;
121 :
122 : Size GetPageObjectSize (void) const;
123 :
124 : /** Return the bounding box in window coordinates of the nIndex-th page
125 : object.
126 : */
127 : Rectangle GetPageObjectBox (
128 : const sal_Int32 nIndex,
129 : const bool bIncludeBorderAndGap = false) const;
130 :
131 : /** Return the bounding box in model coordinates of the page that
132 : contains the given amount of page objects.
133 : */
134 : Rectangle GetTotalBoundingBox (void) const;
135 :
136 : /** Return the index of the first fully or partially visible page
137 : object. This takes into account only the vertical dimension.
138 : @return
139 : The second index may be larger than the number of existing
140 : page objects.
141 : */
142 : Range GetRangeOfVisiblePageObjects (const Rectangle& rVisibleArea) const;
143 :
144 : /** Return the index of the page object that is rendered at the given
145 : point.
146 : @param rPosition
147 : The position is expected to be in model coordinates relative to
148 : the page origin.
149 : @param bIncludePageBorders
150 : When <TRUE/> then include the page borders into the calculation,
151 : i.e. when a point lies in the border of a page object but not on
152 : the actual page area the index of that page is returned;
153 : otherwise -1 would be returned to indicate that no page object
154 : has been hit.
155 : @param bClampToValidRange
156 : When <TRUE/> then values outside the valid range [0,mnPageCount)
157 : are mapped to 0 (when smaller than 0) or mnPageCount-1 when
158 : equal to or larger than mnPageCount.
159 : When <FALSE/> then -1 is returned for values outside the valid range.
160 : @return
161 : The returned index may be larger than the number of existing
162 : page objects.
163 : */
164 : sal_Int32 GetIndexAtPoint (
165 : const Point& rModelPosition,
166 : const bool bIncludePageBorders = false,
167 : const bool bClampToValidRange = true) const;
168 :
169 : /** Return an object that describes the logical and visual properties of
170 : where to do an insert operation when the user would release the the
171 : mouse button at the given position after a drag operation and of
172 : where and how to display an insertion indicator.
173 : @param rModelPosition
174 : The position in the model coordinate system for which to
175 : determine the insertion page index. The position does not have
176 : to be over a page object to return a valid value.
177 : @param rIndicatorSize
178 : The size of the insertion indicator. This size is used to adapt
179 : the location when at the left or right of a row or at the top or
180 : bottom of a column.
181 : @param rModel
182 : The model is used to get access to the selection states of the
183 : pages. This in turn is used to determine the visual bounding
184 : boxes.
185 : */
186 : InsertPosition GetInsertPosition (
187 : const Point& rModelPosition,
188 : const Size& rIndicatorSize,
189 : model::SlideSorterModel& rModel) const;
190 :
191 : Range GetValidHorizontalSizeRange (void) const;
192 : Range GetValidVerticalSizeRange (void) const;
193 :
194 : class Implementation;
195 :
196 : private:
197 : ::boost::scoped_ptr<Implementation> mpImplementation;
198 : SharedSdWindow mpWindow;
199 : };
200 :
201 :
202 :
203 :
204 :
205 : /** Collect all values concerning the logical and visual properties of the
206 : insertion position that is used for drag-and-drop and copy-and-past.
207 : */
208 : class InsertPosition
209 : {
210 : public:
211 : InsertPosition (void);
212 : InsertPosition& operator= (const InsertPosition& rInsertPosition);
213 : bool operator== (const InsertPosition& rInsertPosition) const;
214 : bool operator!= (const InsertPosition& rInsertPosition) const;
215 :
216 : void SetLogicalPosition (
217 : const sal_Int32 nRow,
218 : const sal_Int32 nColumn,
219 : const sal_Int32 nIndex,
220 : const bool bIsAtRunStart,
221 : const bool bIsAtRunEnd,
222 : const bool bIsExtraSpaceNeeded);
223 : void SetGeometricalPosition(
224 : const Point aLocation,
225 : const Point aLeadingOffset,
226 : const Point aTrailingOffset);
227 :
228 0 : sal_Int32 GetRow (void) const { return mnRow; }
229 0 : sal_Int32 GetColumn (void) const { return mnColumn; }
230 0 : sal_Int32 GetIndex (void) const { return mnIndex; }
231 0 : Point GetLocation (void) const { return maLocation; }
232 0 : Point GetLeadingOffset (void) const { return maLeadingOffset; }
233 0 : Point GetTrailingOffset (void) const { return maTrailingOffset; }
234 0 : bool IsAtRunStart (void) const { return mbIsAtRunStart; }
235 0 : bool IsAtRunEnd (void) const { return mbIsAtRunEnd; }
236 0 : bool IsExtraSpaceNeeded (void) const { return mbIsExtraSpaceNeeded; }
237 :
238 : private:
239 : sal_Int32 mnRow;
240 : sal_Int32 mnColumn;
241 : sal_Int32 mnIndex;
242 : bool mbIsAtRunStart : 1;
243 : bool mbIsAtRunEnd : 1;
244 : bool mbIsExtraSpaceNeeded : 1;
245 : Point maLocation;
246 : Point maLeadingOffset;
247 : Point maTrailingOffset;
248 : };
249 :
250 :
251 :
252 : } } } // end of namespace ::sd::slidesorter::view
253 :
254 : #endif
255 :
256 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|