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 <DrawViewShell.hxx>
22 #include <sal/log.hxx>
23 #include <rtl/math.hxx>
24 #include <comphelper/lok.hxx>
26 #include <DrawDocShell.hxx>
28 #include <slideshow.hxx>
32 void DrawViewShell::GotoBookmark(std::u16string_view rBookmark
)
34 ::sd::DrawDocShell
* pDocSh
= GetDocSh();
37 if( !pDocSh
->GetViewShell() ) //#i26016# this case occurs if the jump-target-document was opened already with file open dialog before triggering the jump via hyperlink
38 pDocSh
->Connect(this);
39 pDocSh
->GotoBookmark(rBookmark
);
44 * Make area visible (scroll part of picture)
46 \************************************************************************/
48 void DrawViewShell::MakeVisible(const ::tools::Rectangle
& rRect
, vcl::Window
& rWin
)
50 if ( (IsMouseButtonDown() && !IsMouseSelecting()) || SlideShow::IsRunning( GetViewShellBase() ) )
53 // tdf#98646 check if Rectangle which contains the bounds of the region to
54 // be shown eventually contains values that cause overflows when processing
55 // e.g. when calling GetWidth()
56 const bool bOverflowInX(!rtl::math::approxEqual(static_cast<double>(rRect
.getOpenWidth()), static_cast<double>(rRect
.Right()) - static_cast<double>(rRect
.Left())));
57 const bool bOverflowInY(!rtl::math::approxEqual(static_cast<double>(rRect
.getOpenHeight()), static_cast<double>(rRect
.Bottom()) - static_cast<double>(rRect
.Top())));
59 if(bOverflowInX
|| bOverflowInY
)
61 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
65 // In older versions, if in X or Y the size of the object was
66 // smaller than the visible area, the user-defined zoom was
67 // changed. This was decided to be a bug for
68 // StarOffice 6.x (Apr 2002), thus I developed a
69 // version which instead handles X/Y bigger/smaller and visibility
70 // questions separately
71 const Size
aLogicSize(rRect
.GetSize());
74 Size
aVisSizePixel(rWin
.GetOutputSizePixel());
75 bool bTiledRendering
= comphelper::LibreOfficeKit::isActive() && !rWin
.IsMapModeEnabled();
78 rWin
.GetOutDev()->Push(vcl::PushFlags::MAPMODE
);
81 ::tools::Rectangle
aVisArea(rWin
.PixelToLogic(::tools::Rectangle(Point(0,0), aVisSizePixel
)));
83 rWin
.GetOutDev()->Pop();
84 Size
aVisAreaSize(aVisArea
.GetSize());
86 if ( aVisArea
.Contains(rRect
) )
89 // object is not entirely in visible area
90 sal_Int32
nFreeSpaceX(aVisAreaSize
.Width() - aLogicSize
.Width());
91 sal_Int32
nFreeSpaceY(aVisAreaSize
.Height() - aLogicSize
.Height());
93 // allow a mode for move-only visibility without zooming.
94 const sal_Int32
nPercentBorder(30);
95 const ::tools::Rectangle
aInnerRectangle(
96 aVisArea
.Left() + ((aVisAreaSize
.Width() * nPercentBorder
) / 200),
97 aVisArea
.Top() + ((aVisAreaSize
.Height() * nPercentBorder
) / 200),
98 aVisArea
.Right() - ((aVisAreaSize
.Width() * nPercentBorder
) / 200),
99 aVisArea
.Bottom() - ((aVisAreaSize
.Height() * nPercentBorder
) / 200)
101 Point
aNewPos(aVisArea
.TopLeft());
105 if(aInnerRectangle
.Left() > rRect
.Right())
107 // object moves out to the left
108 aNewPos
.AdjustX( -(aVisAreaSize
.Width() / 2) );
111 if(aInnerRectangle
.Right() < rRect
.Left())
113 // object moves out to the right
114 aNewPos
.AdjustX(aVisAreaSize
.Width() / 2 );
119 if(nFreeSpaceX
> rRect
.GetWidth())
121 nFreeSpaceX
= rRect
.GetWidth();
126 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
130 const ::tools::Long
distRight(rRect
.Right() - aNewPos
.X() - aVisAreaSize
.Width());
134 ::tools::Long mult
= (distRight
/ nFreeSpaceX
) + 1;
135 aNewPos
.AdjustX(mult
* nFreeSpaceX
);
138 const ::tools::Long
distLeft(aNewPos
.X() - rRect
.Left());
142 ::tools::Long mult
= (distLeft
/ nFreeSpaceX
) + 1;
143 aNewPos
.AdjustX( -(mult
* nFreeSpaceX
) );
150 if(aInnerRectangle
.Top() > rRect
.Bottom())
152 // object moves out to the top
153 aNewPos
.AdjustY( -(aVisAreaSize
.Height() / 2) );
156 if(aInnerRectangle
.Bottom() < rRect
.Top())
158 // object moves out to the right
159 aNewPos
.AdjustY(aVisAreaSize
.Height() / 2 );
164 if(nFreeSpaceY
> rRect
.GetHeight())
166 nFreeSpaceY
= rRect
.GetHeight();
171 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
175 const ::tools::Long
distBottom(rRect
.Bottom() - aNewPos
.Y() - aVisAreaSize
.Height());
179 ::tools::Long mult
= (distBottom
/ nFreeSpaceY
) + 1;
180 aNewPos
.AdjustY(mult
* nFreeSpaceY
);
183 const ::tools::Long
distTop(aNewPos
.Y() - rRect
.Top());
187 ::tools::Long mult
= (distTop
/ nFreeSpaceY
) + 1;
188 aNewPos
.AdjustY( -(mult
* nFreeSpaceY
) );
193 // did position change? Does it need to be set?
194 if(aNewPos
!= aVisArea
.TopLeft())
196 aVisArea
.SetPos(aNewPos
);
197 SetZoomRect(aVisArea
);
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */