bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / view / SlsPageObjectLayouter.cxx
blob6940830fd94c86ee75e29a439abb9a1a9351086a
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 #include "view/SlsPageObjectLayouter.hxx"
22 #include "model/SlsPageDescriptor.hxx"
23 #include "view/SlsFontProvider.hxx"
24 #include "view/SlsTheme.hxx"
25 #include "tools/IconCache.hxx"
26 #include "Window.hxx"
27 #include "res_bmp.hrc"
29 namespace sd { namespace slidesorter { namespace view {
31 namespace {
32 const static sal_Int32 gnLeftPageNumberOffset = 2;
33 const static sal_Int32 gnRightPageNumberOffset = 5;
34 const static sal_Int32 gnOuterBorderWidth = 5;
35 const static sal_Int32 gnInfoAreaMinWidth = 26;
38 PageObjectLayouter::PageObjectLayouter (
39 const Size& rPageObjectWindowSize,
40 const Size& rPageSize,
41 sd::Window *pWindow,
42 const sal_Int32 nPageCount)
43 : mpWindow(pWindow),
44 maPageObjectSize(rPageObjectWindowSize.Width(), rPageObjectWindowSize.Height()),
45 maPageObjectBoundingBox(),
46 maPageNumberAreaBoundingBox(),
47 maPreviewBoundingBox(),
48 maTransitionEffectBoundingBox(),
49 maTransitionEffectIcon(IconCache::Instance().GetIcon(BMP_FADE_EFFECT_INDICATOR)),
50 maCustomAnimationEffectIcon(IconCache::Instance().GetIcon(BMP_CUSTOM_ANIMATION_INDICATOR)),
51 mpPageNumberFont(Theme::GetFont(Theme::Font_PageNumber, *pWindow))
53 const Size aPageNumberAreaSize (GetPageNumberAreaSize(nPageCount));
55 const int nMaximumBorderWidth (gnOuterBorderWidth);
56 const int nFocusIndicatorWidth (Theme_FocusIndicatorWidth);
58 maPreviewBoundingBox = CalculatePreviewBoundingBox(
59 maPageObjectSize,
60 Size(rPageSize.Width(), rPageSize.Height()),
61 aPageNumberAreaSize.Width(),
62 nFocusIndicatorWidth);
63 maFocusIndicatorBoundingBox = Rectangle(Point(0,0), maPageObjectSize);
64 maPageObjectBoundingBox = Rectangle(
65 Point(
66 nFocusIndicatorWidth,
67 nFocusIndicatorWidth),
68 Size(
69 maPageObjectSize.Width()-2*nFocusIndicatorWidth,
70 maPageObjectSize.Height()-2*nFocusIndicatorWidth));
72 maPageNumberAreaBoundingBox = Rectangle(
73 Point(
74 std::max(gnLeftPageNumberOffset,
75 sal_Int32(maPreviewBoundingBox.Left()
76 - gnRightPageNumberOffset
77 - aPageNumberAreaSize.Width())),
78 nMaximumBorderWidth),
79 aPageNumberAreaSize);
81 const Size aIconSize (maTransitionEffectIcon.GetSizePixel());
82 maTransitionEffectBoundingBox = Rectangle(
83 Point(
84 (maPreviewBoundingBox.Left() - 2*aIconSize.Width()) / 2,
85 maPreviewBoundingBox.Bottom() - aIconSize.Height()),
86 aIconSize);
87 maCustomAnimationEffectBoundingBox = Rectangle(
88 Point(
89 (maPreviewBoundingBox.Left() - 2*aIconSize.Width()) / 2,
90 maPreviewBoundingBox.Bottom() - 2*aIconSize.Height()),
91 aIconSize);
94 PageObjectLayouter::~PageObjectLayouter()
98 Rectangle PageObjectLayouter::CalculatePreviewBoundingBox (
99 Size& rPageObjectSize,
100 const Size& rPageSize,
101 const sal_Int32 nPageNumberAreaWidth,
102 const sal_Int32 nFocusIndicatorWidth)
104 const sal_Int32 nIconWidth (maTransitionEffectIcon.GetSizePixel().Width());
105 const sal_Int32 nLeftAreaWidth (
106 ::std::max(
107 gnInfoAreaMinWidth,
108 gnRightPageNumberOffset
109 + ::std::max(
110 nPageNumberAreaWidth,
111 nIconWidth)));
112 sal_Int32 nPreviewWidth;
113 sal_Int32 nPreviewHeight;
114 const double nPageAspectRatio (double(rPageSize.Width()) / double(rPageSize.Height()));
115 if (rPageObjectSize.Height() == 0)
117 // Calculate height so that the preview fills the available
118 // horizontal space completely while observing the aspect ratio of
119 // the preview.
120 nPreviewWidth = rPageObjectSize.Width()
121 - nLeftAreaWidth - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
122 nPreviewHeight = ::basegfx::fround(nPreviewWidth / nPageAspectRatio);
123 rPageObjectSize.setHeight(nPreviewHeight + 2*gnOuterBorderWidth + 2*nFocusIndicatorWidth + 1);
125 else if (rPageObjectSize.Width() == 0)
127 // Calculate the width of the page object so that the preview fills
128 // the available vertical space completely while observing the
129 // aspect ratio of the preview.
130 nPreviewHeight = rPageObjectSize.Height() - 2*gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
131 nPreviewWidth = ::basegfx::fround(nPreviewHeight * nPageAspectRatio);
132 rPageObjectSize.setWidth(nPreviewWidth
133 + nLeftAreaWidth + gnOuterBorderWidth + 2*nFocusIndicatorWidth + 1);
136 else
138 // The size of the page object is given. Calculate the size of the
139 // preview.
140 nPreviewWidth = rPageObjectSize.Width()
141 - nLeftAreaWidth - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
142 nPreviewHeight = rPageObjectSize.Height()
143 - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
144 if (double(nPreviewWidth)/double(nPreviewHeight) > nPageAspectRatio)
145 nPreviewWidth = ::basegfx::fround(nPreviewHeight * nPageAspectRatio);
146 else
147 nPreviewHeight = ::basegfx::fround(nPreviewWidth / nPageAspectRatio);
149 // When the preview does not fill the available space completely then
150 // place it flush right and vertically centered.
151 const int nLeft (rPageObjectSize.Width()
152 - gnOuterBorderWidth - nPreviewWidth - nFocusIndicatorWidth - 1);
153 const int nTop ((rPageObjectSize.Height() - nPreviewHeight)/2);
154 return Rectangle(
155 nLeft,
156 nTop,
157 nLeft + nPreviewWidth,
158 nTop + nPreviewHeight);
161 Rectangle PageObjectLayouter::GetBoundingBox (
162 const model::SharedPageDescriptor& rpPageDescriptor,
163 const Part ePart,
164 const CoordinateSystem eCoordinateSystem,
165 bool bIgnoreLocation)
167 OSL_ASSERT(rpPageDescriptor);
168 Point aLocation(0,0);
169 if (rpPageDescriptor)
170 aLocation = rpPageDescriptor->GetLocation( bIgnoreLocation );
171 return GetBoundingBox(aLocation, ePart, eCoordinateSystem);
174 Rectangle PageObjectLayouter::GetBoundingBox (
175 const Point& rPageObjectLocation,
176 const Part ePart,
177 const CoordinateSystem eCoordinateSystem)
179 Rectangle aBoundingBox;
180 switch (ePart)
182 case FocusIndicator:
183 aBoundingBox = maFocusIndicatorBoundingBox;
184 break;
186 case PageObject:
187 case MouseOverIndicator:
188 aBoundingBox = maPageObjectBoundingBox;
189 break;
191 case Preview:
192 aBoundingBox = maPreviewBoundingBox;
193 break;
195 case PageNumber:
196 aBoundingBox = maPageNumberAreaBoundingBox;
197 break;
199 case Name:
200 aBoundingBox = maPageNumberAreaBoundingBox;
201 break;
203 case TransitionEffectIndicator:
204 aBoundingBox = maTransitionEffectBoundingBox;
205 break;
206 case CustomAnimationEffectIndicator:
207 aBoundingBox = maCustomAnimationEffectBoundingBox;
208 break;
211 // Adapt coordinates to the requested coordinate system.
212 Point aLocation (rPageObjectLocation);
213 if (eCoordinateSystem == WindowCoordinateSystem)
214 aLocation += mpWindow->GetMapMode().GetOrigin();
216 return Rectangle(
217 aBoundingBox.TopLeft() + aLocation,
218 aBoundingBox.BottomRight() + aLocation);
221 Size PageObjectLayouter::GetPreviewSize (
222 const CoordinateSystem eCoordinateSystem)
224 return GetBoundingBox(Point(0,0), PageObjectLayouter::Preview,
225 eCoordinateSystem).GetSize();
228 Size PageObjectLayouter::GetGridMaxSize(const CoordinateSystem eCoordinateSystem)
230 return GetBoundingBox(Point(0,0), PageObjectLayouter::FocusIndicator,
231 eCoordinateSystem).GetSize();
234 Size PageObjectLayouter::GetPageNumberAreaSize (const int nPageCount)
236 OSL_ASSERT(mpWindow);
238 // Set the correct font.
239 vcl::Font aOriginalFont (mpWindow->GetFont());
240 if (mpPageNumberFont)
241 mpWindow->SetFont(*mpPageNumberFont);
243 OUString sPageNumberTemplate;
244 if (nPageCount < 10)
245 sPageNumberTemplate = "9";
246 else if (nPageCount < 100)
247 sPageNumberTemplate = "99";
248 else if (nPageCount < 200)
249 // Just for the case that 1 is narrower than 9.
250 sPageNumberTemplate = "199";
251 else if (nPageCount < 1000)
252 sPageNumberTemplate = "999";
253 else
254 sPageNumberTemplate = "9999";
255 // More then 9999 pages are not handled.
257 const Size aSize (
258 mpWindow->GetTextWidth(sPageNumberTemplate),
259 mpWindow->GetTextHeight());
261 mpWindow->SetFont(aOriginalFont);
263 return aSize;
266 } } } // end of namespace ::sd::slidesorter::view
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */