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() )
53 if ( SlideShow::IsRunning( GetViewShellBase() ) && !SlideShow::IsInteractiveSlideshow( &GetViewShellBase() ) ) // IASS
56 // tdf#98646 check if Rectangle which contains the bounds of the region to
57 // be shown eventually contains values that cause overflows when processing
58 // e.g. when calling GetWidth()
59 const bool bOverflowInX(!rtl::math::approxEqual(static_cast<double>(rRect
.getOpenWidth()), static_cast<double>(rRect
.Right()) - static_cast<double>(rRect
.Left())));
60 const bool bOverflowInY(!rtl::math::approxEqual(static_cast<double>(rRect
.getOpenHeight()), static_cast<double>(rRect
.Bottom()) - static_cast<double>(rRect
.Top())));
62 if(bOverflowInX
|| bOverflowInY
)
64 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
68 // In older versions, if in X or Y the size of the object was
69 // smaller than the visible area, the user-defined zoom was
70 // changed. This was decided to be a bug for
71 // StarOffice 6.x (Apr 2002), thus I developed a
72 // version which instead handles X/Y bigger/smaller and visibility
73 // questions separately
74 const Size
aLogicSize(rRect
.GetSize());
77 Size
aVisSizePixel(rWin
.GetOutputSizePixel());
78 bool bTiledRendering
= comphelper::LibreOfficeKit::isActive() && !rWin
.IsMapModeEnabled();
81 rWin
.GetOutDev()->Push(vcl::PushFlags::MAPMODE
);
84 ::tools::Rectangle
aVisArea(rWin
.PixelToLogic(::tools::Rectangle(Point(0,0), aVisSizePixel
)));
86 rWin
.GetOutDev()->Pop();
87 Size
aVisAreaSize(aVisArea
.GetSize());
89 if ( aVisArea
.Contains(rRect
) )
92 // object is not entirely in visible area
93 sal_Int32
nFreeSpaceX(aVisAreaSize
.Width() - aLogicSize
.Width());
94 sal_Int32
nFreeSpaceY(aVisAreaSize
.Height() - aLogicSize
.Height());
96 // allow a mode for move-only visibility without zooming.
97 const sal_Int32
nPercentBorder(30);
98 const ::tools::Rectangle
aInnerRectangle(
99 aVisArea
.Left() + ((aVisAreaSize
.Width() * nPercentBorder
) / 200),
100 aVisArea
.Top() + ((aVisAreaSize
.Height() * nPercentBorder
) / 200),
101 aVisArea
.Right() - ((aVisAreaSize
.Width() * nPercentBorder
) / 200),
102 aVisArea
.Bottom() - ((aVisAreaSize
.Height() * nPercentBorder
) / 200)
104 Point
aNewPos(aVisArea
.TopLeft());
108 if(aInnerRectangle
.Left() > rRect
.Right())
110 // object moves out to the left
111 aNewPos
.AdjustX( -(aVisAreaSize
.Width() / 2) );
114 if(aInnerRectangle
.Right() < rRect
.Left())
116 // object moves out to the right
117 aNewPos
.AdjustX(aVisAreaSize
.Width() / 2 );
122 if(nFreeSpaceX
> rRect
.GetWidth())
124 nFreeSpaceX
= rRect
.GetWidth();
129 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
133 const ::tools::Long
distRight(rRect
.Right() - aNewPos
.X() - aVisAreaSize
.Width());
137 ::tools::Long mult
= (distRight
/ nFreeSpaceX
) + 1;
138 aNewPos
.AdjustX(mult
* nFreeSpaceX
);
141 const ::tools::Long
distLeft(aNewPos
.X() - rRect
.Left());
145 ::tools::Long mult
= (distLeft
/ nFreeSpaceX
) + 1;
146 aNewPos
.AdjustX( -(mult
* nFreeSpaceX
) );
153 if(aInnerRectangle
.Top() > rRect
.Bottom())
155 // object moves out to the top
156 aNewPos
.AdjustY( -(aVisAreaSize
.Height() / 2) );
159 if(aInnerRectangle
.Bottom() < rRect
.Top())
161 // object moves out to the right
162 aNewPos
.AdjustY(aVisAreaSize
.Height() / 2 );
167 if(nFreeSpaceY
> rRect
.GetHeight())
169 nFreeSpaceY
= rRect
.GetHeight();
174 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
178 const ::tools::Long
distBottom(rRect
.Bottom() - aNewPos
.Y() - aVisAreaSize
.Height());
182 ::tools::Long mult
= (distBottom
/ nFreeSpaceY
) + 1;
183 aNewPos
.AdjustY(mult
* nFreeSpaceY
);
186 const ::tools::Long
distTop(aNewPos
.Y() - rRect
.Top());
190 ::tools::Long mult
= (distTop
/ nFreeSpaceY
) + 1;
191 aNewPos
.AdjustY( -(mult
* nFreeSpaceY
) );
196 // did position change? Does it need to be set?
197 if(aNewPos
!= aVisArea
.TopLeft())
199 aVisArea
.SetPos(aNewPos
);
200 SetZoomRect(aVisArea
);
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */