Update ooo320-m1
[ooovba.git] / sd / source / ui / slidesorter / inc / view / SlsLayouter.hxx
blob5c8a3d8ee5f5a66f64cfc0d139bb627a0790db66
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsLayouter.hxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SD_SLIDESORTER_VIEW_LAYOUTER_HXX
32 #define SD_SLIDESORTER_VIEW_LAYOUTER_HXX
34 #include <sal/types.h>
35 #include <tools/fract.hxx>
36 #include <vcl/mapmod.hxx>
37 #include <vector>
38 #include <utility>
40 class MapMode;
41 class OutputDevice;
42 class Size;
44 namespace sd { namespace slidesorter { namespace view {
46 /** Calculate the size and position of page objects displayed by a slide
47 sorter. The layouter takes into account various input values:
48 1.) Size of the window in which the slide sorter is displayed.
49 2.) Desired and minimal and maximal widths of page objects.
50 3.) Minimal and maximal number of columns.
51 4.) Vertical and horizontal gaps between objects in adjacent columns.
52 5.) Borders arround every page object.
53 6.) Vertical and horizontal borders between enclosing page and outer
54 page objects.
55 From these it calculates various output values:
56 1.) The width of page objects.
57 2.) The number of columns.
58 3.) The size of the enclosing page.
60 <p>Sizes and lengths are all in pixel except where explicitly stated
61 otherwise.</p>
63 <p>The GetIndex... methods may return indices that are larger than or
64 equal to (zero based) the number of pages. This is so because the
65 number of pages is not known to the class instances. Indices are
66 calculated with reference to the general grid layout of page
67 objects.</p>
69 class Layouter
71 public:
72 Layouter (void);
73 ~Layouter (void);
75 /** Set the minimal, the maximal, and the desired width of the page
76 objects. The three parameters have to fullfill the constraint
77 nMinimalWidth <= nPreferredWidth <= nMaximalWidth or the call is
78 ignored.
80 void SetObjectWidth (sal_Int32 nMinimalWidth, sal_Int32 nMaximalWidth,
81 sal_Int32 nPreferredWidth);
83 /** Set the horizontal and vertical borders in pixel coordinates between
84 the enclosing window and page objects. The borders may be painted
85 larger then the given values when the space for the insertion marker
86 is not sufficient.
87 @param nLeftBorder
88 Use a negative value to indicate that the left border size
89 shall not be modified. A value of 10 is the default.
90 @param nRightBorder
91 Use a negative value to indicate that the right border size
92 shall not be modified. A value of 10 is the default.
93 @param nTopBorder
94 Use a negative value to indicate that the top border size
95 shall not be modified. A value of 10 is the default.
96 @param nBottomBorder
97 Use a negative value to indicate that the bottom border size
98 shall not be modified. A value of 10 is the default.
100 void SetBorders (sal_Int32 nLeftBorder, sal_Int32 nRightBorder,
101 sal_Int32 nTopBorder, sal_Int32 nBottomBorder);
103 /** Set the borders arround every page object.
104 @param nLeftBorder
105 A negative value indicates that the left border shall not be
106 modified. A value of 0 is the default.
107 @param nRightBorder
108 A negative value indicates that the left border shall not be
109 modified. A value of 0 is the default.
110 @param nTopBorder
111 A negative value indicates that the left border shall not be
112 modified. A value of 0 is the default.
113 @param nBottomBorder
114 A negative value indicates that the left border shall not be
115 modified. A value of 0 is the default.
117 void SetPageBorders (sal_Int32 nLeftBorder, sal_Int32 nRightBorder,
118 sal_Int32 nTopBorder, sal_Int32 nBottomBorder);
120 /** Set the horizontal and vertical gaps between adjacent page objects.
121 These gaps are only relevant when there is more than one column or
122 more than one row. Negative values indicate that the respective gap
123 is not set.
125 void SetGaps (sal_Int32 nHorizontalGap, sal_Int32 nVerticalGap);
127 /** Set the interval of valid column counts. When nMinimalColumnCount
128 <= nMaximalColumnCount is not fullfilled then the call is ignored.
129 @param nMinimalColumnCount
130 The default value is 1. The question whether higher values make
131 any sense is left to the caller.
132 @param nMaximalColumnCount
133 The default value is 5.
135 void SetColumnCount (sal_Int32 nMinimalColumnCount,
136 sal_Int32 nMaximalColumnCount);
138 /** Central method of this class. It takes the input values and
139 calculates the output values. Both given sizes must not be 0 in any
140 dimension or the call is ignored.
141 @param rWindowSize
142 The size of the window in pixels that the slide sorter is
143 displayed in.
144 @param rPageObjectSize
145 Size of each page in model coordinates.
146 @param pDevice
147 The map mode of this output device is adapted to the new layout
148 of the page objects.
149 @return
150 The return value indicates whether the Get... methods can be
151 used to obtain valid values (<TRUE/>).
153 bool RearrangeHorizontal (
154 const Size& rWindowSize,
155 const Size& rPageObjectSize,
156 OutputDevice* pDevice,
157 const sal_uInt32 nPageCount);
158 bool RearrangeVertical (
159 const Size& rWindowSize,
160 const Size& rPageObjectSize,
161 OutputDevice* pDevice);
163 /** Change the zoom factor. This does not change the general layout
164 (number of columns).
166 void SetZoom (double nZoomFactor, OutputDevice* pDevice);
167 void SetZoom (Fraction nZoomFactor, OutputDevice* pDevice);
169 /** Return the number of columns.
171 sal_Int32 GetColumnCount (void) const;
173 /** Returns whether the column count is fixed (<TRUE/>) or variable
174 (<FALSE/>). It is fixed if SetColumnCount() was called with the
175 same value for minimal and maximal column count.
177 bool IsColumnCountFixed (void) const;
179 /** Return the scale factor that can be set at the map mode of the
180 output window.
182 Fraction GetScaleFactor (void) const;
184 Size GetPageObjectSize (void) const;
186 /** Return the bounding box in model coordinates of the nIndex-th page
187 object.
189 Rectangle GetPageObjectBox (sal_Int32 nIndex) const;
191 /** Return the bounding box in model coordinates of the page that
192 contains the given amount of page objects.
194 Rectangle GetPageBox (sal_Int32 nObjectCount) const;
196 /** Return the rectangle that bounds the insertion marker that is
197 specified by the parameters.
198 @param nIndex
199 Index of the page object from which the position of the marker
200 will be calculated.
201 @param bVertical
202 When <TRUE/> then the insertion marker will be calculated with a
203 vertical orientation positioned to the left or right of the
204 specified page object. A horizontal orientation is indicated by
205 <FALSE/>. In this case the marker will be positioned above or
206 below the page object.
207 @param bLeftOrTop
208 This flag indicates whether the insertion marker will be
209 positioned above or to the left (<TRUE/>) the page object. When
210 <FALSE/> is given then the marker will be positioned below or to
211 the right of the page object.
213 Rectangle GetInsertionMarkerBox (
214 sal_Int32 nIndex,
215 bool bVertical,
216 bool bLeftOrTop) const;
218 /** Return the index of the first fully or partially visible page
219 object. This takes into account only the vertical dimension.
221 sal_Int32 GetIndexOfFirstVisiblePageObject (
222 const Rectangle& rVisibleArea) const;
224 /** Return the index of the last fully or partially visible page
225 object. This takes into account only the vertical dimension.
226 @return
227 The returned index may be larger than the number of existing
228 page objects.
230 sal_Int32 GetIndexOfLastVisiblePageObject (
231 const Rectangle& rVisibleArea) const;
233 /** Return the index of the page object that is rendered at the given
234 point.
235 @param rPosition
236 The position is expected to be in model coordinates relative to
237 the page origin.
238 @param bIncludePageBorders
239 When <TRUE/> then include the page borders into the calculation,
240 i.e. when a point lies in the border of a page object but not on
241 the actual page area the index of that page is returned;
242 otherwise -1 would be returned to indicate that no page object
243 has been hit.
244 @return
245 The returned index may be larger than the number of existing
246 page objects.
248 sal_Int32 GetIndexAtPoint (
249 const Point& rModelPosition,
250 bool bIncludePageBorders = false) const;
252 /** Return the page index of where to do an insert operation when the
253 user would release the the mouse button at the given position after
254 a drag operation.
255 @param rPosition
256 The position in the model coordinate system for which to
257 determine the insertion page index. The position does not have
258 to be over a page object to return a valid value.
259 @param bAllowVerticalPosition
260 When this flag is <TRUE/> then the vertical gaps between rows
261 may be taken into account for calculating the insertion index as
262 well as the horizontal gaps between columns. This will happen
263 only when there is only one column.
264 (better name, anyone?)
265 @return
266 Returns the page index, as accepted by the slide sorter model,
267 of the page after which an insertion would take place. An index
268 of 0 means that insertion will take place before the first page,
269 An index equal to or greater than the page count means to insert
270 after the last page.
271 A value of -1 indicates that no valid insertion index exists for
272 the given point.
274 sal_Int32 GetInsertionIndex (
275 const Point& rModelPosition,
276 bool bAllowVerticalPosition) const;
278 typedef ::std::pair<double,double> DoublePoint;
279 /** Transform a point given in model coordinates in to layouter
280 coordinates. Layouter coordinates are floating point numbers where
281 the integer part denotes a row or a column and the part after the
282 decimal point is a relative position in that row or column.
284 DoublePoint ConvertModelToLayouterCoordinates (
285 const Point& rModelPoint) const;
287 /** Transform a point given in layouter coordinates to model
288 coordinates. See ConvertModelToLayouterCoordinates for a
289 description of layouter coordinates.
291 Point ConvertLayouterToModelCoordinates (
292 const DoublePoint&rLayouterPoint) const;
294 typedef ::std::vector<Rectangle> BackgroundRectangleList;
295 const BackgroundRectangleList& GetBackgroundRectangleList (void) const;
297 private:
298 class ScreenAndModelValue {public:
299 sal_Int32 mnScreen,mnModel;
300 explicit ScreenAndModelValue (sal_Int32 nScreen, sal_Int32 nModel = 0)
301 : mnScreen(nScreen),mnModel(nModel) {}
303 ScreenAndModelValue mnRequestedLeftBorder;
304 ScreenAndModelValue mnRequestedRightBorder;
305 ScreenAndModelValue mnRequestedTopBorder;
306 ScreenAndModelValue mnRequestedBottomBorder;
307 ScreenAndModelValue mnLeftBorder;
308 ScreenAndModelValue mnRightBorder;
309 ScreenAndModelValue mnTopBorder;
310 ScreenAndModelValue mnBottomBorder;
311 ScreenAndModelValue mnLeftPageBorder;
312 ScreenAndModelValue mnRightPageBorder;
313 ScreenAndModelValue mnTopPageBorder;
314 ScreenAndModelValue mnBottomPageBorder;
315 ScreenAndModelValue mnVerticalGap;
316 ScreenAndModelValue mnHorizontalGap;
317 ScreenAndModelValue mnInsertionMarkerThickness;
318 ScreenAndModelValue mnTotalVerticalGap;
319 ScreenAndModelValue mnTotalHorizontalGap;
320 sal_Int32 mnMinimalWidth;
321 sal_Int32 mnPreferredWidth;
322 sal_Int32 mnMaximalWidth;
323 sal_Int32 mnMinimalColumnCount;
324 sal_Int32 mnMaximalColumnCount;
325 sal_Int32 mnColumnCount;
326 Size maPageObjectModelSize;
327 Size maPageObjectPixelSize;
329 BackgroundRectangleList maBackgroundRectangleList;
331 enum GapMembership { GM_NONE, GM_PREVIOUS, GM_BOTH, GM_NEXT,
332 GM_PAGE_BORDER};
334 /** Calculate the row that the point with the given vertical coordinate
335 is over. The horizontal component is ignored.
336 @param nYPosition
337 Vertical position in model coordinates.
338 @param bIncludeBordersAndGaps
339 When this flag is <TRUE/> then the area of borders and gaps are
340 interpreted as belonging to one of the rows.
341 @param eGapMembership
342 Specifies to what row the gap areas belong. Here GM_NONE
343 corresponds to bIncludeBordersAndGaps being <FALSE/>. When
344 GM_BOTH is given then the upper half is associated to the row
345 above and the lower half to the row below. Values of
346 GM_PREVIOUS and GM_NEXT associate the whole gap area with the
347 row above or below respectively.
349 sal_Int32 GetRowAtPosition (
350 sal_Int32 nYPosition,
351 bool bIncludeBordersAndGaps,
352 GapMembership eGapMembership = GM_NONE) const;
354 /** Calculate the column that the point with the given horizontal
355 coordinate is over. The verical component is ignored.
356 @param nXPosition
357 Horizontal position in model coordinates.
358 @param bIncludeBordersAndGaps
359 When this flag is <TRUE/> then the area of borders and gaps are
360 interpreted as belonging to one of the columns.
361 @param eGapMembership
362 Specifies to what column the gap areas belong. Here GM_NONE
363 corresponds to bIncludeBordersAndGaps being <FALSE/>. When
364 GM_BOTH is given then the left half is associated with the
365 column at the left and the right half with the column to the
366 right. Values of GM_PREVIOUS and GM_NEXT associate the whole
367 gap area with the column to the left or right respectively.
369 sal_Int32 GetColumnAtPosition (
370 sal_Int32 nXPosition,
371 bool bIncludeBordersAndGaps,
372 GapMembership eGapMembership = GM_NONE) const;
374 /** This method is typically called from GetRowAtPosition() and
375 GetColumnAtPosition() to handle a position that lies inside the gap
376 between two adjacent rows or columns.
377 @param nDistanceIntoGap
378 Vertical distance from the bottom of the upper row down into the
379 gap or or horizontal distance from the right edge right into the
380 gap.
381 @param eGapMemberhship
382 This value decides what areas in the gap belong to which (or no)
383 row or column.
384 @param nIndex
385 The row index of the upper row or the column index of the left
386 column.
387 @param nLeftOrTopPageBorder
388 Width in model coordinates of the border the the right of or
389 below a page.
390 @param nGap
391 Width or height of the gap in model coordiantes between the
392 page borders.
393 @return
394 Returns either the index of the upper row (as given as nRow), the
395 index of the lower row (nRow+1) or -1 to indicate that the
396 position belongs to no row.
398 sal_Int32 ResolvePositionInGap (
399 sal_Int32 nDistanceIntoGap,
400 GapMembership eGapMembership,
401 sal_Int32 nIndex,
402 sal_Int32 nLeftOrTopPageBorder,
403 sal_Int32 nGap) const;
406 } } } // end of namespace ::sd::slidesorter::view
408 #endif