1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
27 #include "res_bmp.hrc"
29 namespace sd
{ namespace slidesorter
{ namespace view
{
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
,
42 const sal_Int32 nPageCount
)
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(
60 Size(rPageSize
.Width(), rPageSize
.Height()),
61 aPageNumberAreaSize
.Width(),
62 nFocusIndicatorWidth
);
63 maFocusIndicatorBoundingBox
= Rectangle(Point(0,0), maPageObjectSize
);
64 maPageObjectBoundingBox
= Rectangle(
67 nFocusIndicatorWidth
),
69 maPageObjectSize
.Width()-2*nFocusIndicatorWidth
,
70 maPageObjectSize
.Height()-2*nFocusIndicatorWidth
));
72 maPageNumberAreaBoundingBox
= Rectangle(
74 std::max(gnLeftPageNumberOffset
,
75 sal_Int32(maPreviewBoundingBox
.Left()
76 - gnRightPageNumberOffset
77 - aPageNumberAreaSize
.Width())),
81 const Size
aIconSize (maTransitionEffectIcon
.GetSizePixel());
82 maTransitionEffectBoundingBox
= Rectangle(
84 (maPreviewBoundingBox
.Left() - 2*aIconSize
.Width()) / 2,
85 maPreviewBoundingBox
.Bottom() - aIconSize
.Height()),
87 maCustomAnimationEffectBoundingBox
= Rectangle(
89 (maPreviewBoundingBox
.Left() - 2*aIconSize
.Width()) / 2,
90 maPreviewBoundingBox
.Bottom() - 2*aIconSize
.Height()),
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 (
108 gnRightPageNumberOffset
110 nPageNumberAreaWidth
,
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
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);
138 // The size of the page object is given. Calculate the size of the
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
);
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);
157 nLeft
+ nPreviewWidth
,
158 nTop
+ nPreviewHeight
);
161 Rectangle
PageObjectLayouter::GetBoundingBox (
162 const model::SharedPageDescriptor
& rpPageDescriptor
,
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
,
177 const CoordinateSystem eCoordinateSystem
)
179 Rectangle aBoundingBox
;
183 aBoundingBox
= maFocusIndicatorBoundingBox
;
187 case MouseOverIndicator
:
188 aBoundingBox
= maPageObjectBoundingBox
;
192 aBoundingBox
= maPreviewBoundingBox
;
196 aBoundingBox
= maPageNumberAreaBoundingBox
;
200 aBoundingBox
= maPageNumberAreaBoundingBox
;
203 case TransitionEffectIndicator
:
204 aBoundingBox
= maTransitionEffectBoundingBox
;
206 case CustomAnimationEffectIndicator
:
207 aBoundingBox
= maCustomAnimationEffectBoundingBox
;
211 // Adapt coordinates to the requested coordinate system.
212 Point
aLocation (rPageObjectLocation
);
213 if (eCoordinateSystem
== WindowCoordinateSystem
)
214 aLocation
+= mpWindow
->GetMapMode().GetOrigin();
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
;
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";
254 sPageNumberTemplate
= "9999";
255 // More then 9999 pages are not handled.
258 mpWindow
->GetTextWidth(sPageNumberTemplate
),
259 mpWindow
->GetTextHeight());
261 mpWindow
->SetFont(aOriginalFont
);
266 } } } // end of namespace ::sd::slidesorter::view
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */