bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / slidesorter / view / SlsPageObjectLayouter.cxx
blob93be4844ebbd3bedbee398196ef16201dff4c25b
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>
28 #include <bitmaps.hlst>
29 #include <osl/diagnose.h>
31 namespace sd { namespace slidesorter { namespace view {
33 namespace {
34 const static sal_Int32 gnLeftPageNumberOffset = 2;
35 const static sal_Int32 gnRightPageNumberOffset = 5;
36 const static sal_Int32 gnOuterBorderWidth = 5;
37 const static sal_Int32 gnInfoAreaMinWidth = 26;
40 PageObjectLayouter::PageObjectLayouter (
41 const Size& rPageObjectWindowSize,
42 const Size& rPageSize,
43 sd::Window *pWindow,
44 const sal_Int32 nPageCount)
45 : mpWindow(pWindow),
46 maPageObjectBoundingBox(),
47 maPageNumberAreaBoundingBox(),
48 maPreviewBoundingBox(),
49 maTransitionEffectBoundingBox(),
50 maTransitionEffectIcon(IconCache::Instance().GetIcon(BMP_FADE_EFFECT_INDICATOR)),
51 maCustomAnimationEffectIcon(IconCache::Instance().GetIcon(BMP_CUSTOM_ANIMATION_INDICATOR)),
52 mpPageNumberFont(Theme::GetFont(Theme::Font_PageNumber, *pWindow))
54 const Size aPageNumberAreaSize (GetPageNumberAreaSize(nPageCount));
56 const int nMaximumBorderWidth (gnOuterBorderWidth);
57 const int nFocusIndicatorWidth (Theme_FocusIndicatorWidth);
59 Size aPageObjectSize(rPageObjectWindowSize.Width(), rPageObjectWindowSize.Height());
60 maPreviewBoundingBox = CalculatePreviewBoundingBox(
61 aPageObjectSize,
62 Size(rPageSize.Width(), rPageSize.Height()),
63 aPageNumberAreaSize.Width(),
64 nFocusIndicatorWidth);
65 maFocusIndicatorBoundingBox = ::tools::Rectangle(Point(0,0), aPageObjectSize);
66 maPageObjectBoundingBox = ::tools::Rectangle(
67 Point(
68 nFocusIndicatorWidth,
69 nFocusIndicatorWidth),
70 Size(
71 aPageObjectSize.Width()-2*nFocusIndicatorWidth,
72 aPageObjectSize.Height()-2*nFocusIndicatorWidth));
74 maPageNumberAreaBoundingBox = ::tools::Rectangle(
75 Point(
76 std::max(gnLeftPageNumberOffset,
77 sal_Int32(maPreviewBoundingBox.Left()
78 - gnRightPageNumberOffset
79 - aPageNumberAreaSize.Width())),
80 nMaximumBorderWidth),
81 aPageNumberAreaSize);
83 const Size aIconSize (maTransitionEffectIcon.GetSizePixel());
84 maTransitionEffectBoundingBox = ::tools::Rectangle(
85 Point(
86 (maPreviewBoundingBox.Left() - 2*aIconSize.Width()) / 2,
87 maPreviewBoundingBox.Bottom() - aIconSize.Height()),
88 aIconSize);
89 maCustomAnimationEffectBoundingBox = ::tools::Rectangle(
90 Point(
91 (maPreviewBoundingBox.Left() - 2*aIconSize.Width()) / 2,
92 maPreviewBoundingBox.Bottom() - 2*aIconSize.Height()),
93 aIconSize);
96 PageObjectLayouter::~PageObjectLayouter()
100 ::tools::Rectangle PageObjectLayouter::CalculatePreviewBoundingBox (
101 Size& rPageObjectSize,
102 const Size& rPageSize,
103 const sal_Int32 nPageNumberAreaWidth,
104 const sal_Int32 nFocusIndicatorWidth)
106 const sal_Int32 nIconWidth (maTransitionEffectIcon.GetSizePixel().Width());
107 const sal_Int32 nLeftAreaWidth (
108 ::std::max(
109 gnInfoAreaMinWidth,
110 gnRightPageNumberOffset
111 + ::std::max(
112 nPageNumberAreaWidth,
113 nIconWidth)));
114 sal_Int32 nPreviewWidth;
115 sal_Int32 nPreviewHeight;
116 const double nPageAspectRatio (double(rPageSize.Width()) / double(rPageSize.Height()));
117 if (rPageObjectSize.Height() == 0)
119 // Calculate height so that the preview fills the available
120 // horizontal space completely while observing the aspect ratio of
121 // the preview.
122 nPreviewWidth = rPageObjectSize.Width()
123 - nLeftAreaWidth - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
124 nPreviewHeight = ::basegfx::fround(nPreviewWidth / nPageAspectRatio);
125 rPageObjectSize.setHeight(nPreviewHeight + 2*gnOuterBorderWidth + 2*nFocusIndicatorWidth + 1);
127 else if (rPageObjectSize.Width() == 0)
129 // Calculate the width of the page object so that the preview fills
130 // the available vertical space completely while observing the
131 // aspect ratio of the preview.
132 nPreviewHeight = rPageObjectSize.Height() - 2*gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
133 nPreviewWidth = ::basegfx::fround(nPreviewHeight * nPageAspectRatio);
134 rPageObjectSize.setWidth(nPreviewWidth
135 + nLeftAreaWidth + gnOuterBorderWidth + 2*nFocusIndicatorWidth + 1);
138 else
140 // The size of the page object is given. Calculate the size of the
141 // preview.
142 nPreviewWidth = rPageObjectSize.Width()
143 - nLeftAreaWidth - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
144 nPreviewHeight = rPageObjectSize.Height()
145 - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
146 if (double(nPreviewWidth)/double(nPreviewHeight) > nPageAspectRatio)
147 nPreviewWidth = ::basegfx::fround(nPreviewHeight * nPageAspectRatio);
148 else
149 nPreviewHeight = ::basegfx::fround(nPreviewWidth / nPageAspectRatio);
151 // When the preview does not fill the available space completely then
152 // place it flush right and vertically centered.
153 const int nLeft (rPageObjectSize.Width()
154 - gnOuterBorderWidth - nPreviewWidth - nFocusIndicatorWidth - 1);
155 const int nTop ((rPageObjectSize.Height() - nPreviewHeight)/2);
156 return ::tools::Rectangle(
157 nLeft,
158 nTop,
159 nLeft + nPreviewWidth,
160 nTop + nPreviewHeight);
163 ::tools::Rectangle PageObjectLayouter::GetBoundingBox (
164 const model::SharedPageDescriptor& rpPageDescriptor,
165 const Part ePart,
166 const CoordinateSystem eCoordinateSystem,
167 bool bIgnoreLocation)
169 OSL_ASSERT(rpPageDescriptor);
170 Point aLocation(0,0);
171 if (rpPageDescriptor)
172 aLocation = rpPageDescriptor->GetLocation( bIgnoreLocation );
173 return GetBoundingBox(aLocation, ePart, eCoordinateSystem);
176 ::tools::Rectangle PageObjectLayouter::GetBoundingBox (
177 const Point& rPageObjectLocation,
178 const Part ePart,
179 const CoordinateSystem eCoordinateSystem)
181 ::tools::Rectangle aBoundingBox;
182 switch (ePart)
184 case Part::FocusIndicator:
185 aBoundingBox = maFocusIndicatorBoundingBox;
186 break;
188 case Part::PageObject:
189 aBoundingBox = maPageObjectBoundingBox;
190 break;
192 case Part::Preview:
193 aBoundingBox = maPreviewBoundingBox;
194 break;
196 case Part::PageNumber:
197 aBoundingBox = maPageNumberAreaBoundingBox;
198 break;
200 case Part::TransitionEffectIndicator:
201 aBoundingBox = maTransitionEffectBoundingBox;
202 break;
203 case Part::CustomAnimationEffectIndicator:
204 aBoundingBox = maCustomAnimationEffectBoundingBox;
205 break;
208 // Adapt coordinates to the requested coordinate system.
209 Point aLocation (rPageObjectLocation);
210 if (eCoordinateSystem == WindowCoordinateSystem)
211 aLocation += mpWindow->GetMapMode().GetOrigin();
213 return ::tools::Rectangle(
214 aBoundingBox.TopLeft() + aLocation,
215 aBoundingBox.BottomRight() + aLocation);
218 Size PageObjectLayouter::GetPreviewSize ()
220 return GetBoundingBox(Point(0,0), PageObjectLayouter::Part::Preview,
221 WindowCoordinateSystem).GetSize();
224 Size PageObjectLayouter::GetGridMaxSize()
226 return GetBoundingBox(Point(0,0), PageObjectLayouter::Part::FocusIndicator,
227 WindowCoordinateSystem).GetSize();
230 Size PageObjectLayouter::GetPageNumberAreaSize (const int nPageCount)
232 OSL_ASSERT(mpWindow);
234 // Set the correct font.
235 vcl::Font aOriginalFont (mpWindow->GetFont());
236 if (mpPageNumberFont)
237 mpWindow->SetFont(*mpPageNumberFont);
239 OUString sPageNumberTemplate;
240 if (nPageCount < 10)
241 sPageNumberTemplate = "9";
242 else if (nPageCount < 100)
243 sPageNumberTemplate = "99";
244 else if (nPageCount < 200)
245 // Just for the case that 1 is narrower than 9.
246 sPageNumberTemplate = "199";
247 else if (nPageCount < 1000)
248 sPageNumberTemplate = "999";
249 else
250 sPageNumberTemplate = "9999";
251 // More then 9999 pages are not handled.
253 const Size aSize (
254 mpWindow->GetTextWidth(sPageNumberTemplate),
255 mpWindow->GetTextHeight());
257 mpWindow->SetFont(aOriginalFont);
259 return aSize;
262 } } } // end of namespace ::sd::slidesorter::view
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */