LibreOffice Module sd (master) 1
drviewsh.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <DrawViewShell.hxx>
21
22#include <sal/log.hxx>
23#include <rtl/math.hxx>
24#include <comphelper/lok.hxx>
25
26#include <DrawDocShell.hxx>
27
28#include <slideshow.hxx>
29
30namespace sd {
31
32void DrawViewShell::GotoBookmark(std::u16string_view rBookmark)
33{
34 ::sd::DrawDocShell* pDocSh = GetDocSh();
35 if( pDocSh )
36 {
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);
40 }
41}
42
48void DrawViewShell::MakeVisible(const ::tools::Rectangle& rRect, vcl::Window& rWin)
49{
51 return;
52
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())));
58
59 if(bOverflowInX || bOverflowInY)
60 {
61 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
62 return;
63 }
64
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());
72
73 // visible area
74 Size aVisSizePixel(rWin.GetOutputSizePixel());
75 bool bTiledRendering = comphelper::LibreOfficeKit::isActive() && !rWin.IsMapModeEnabled();
76 if (bTiledRendering)
77 {
79 rWin.EnableMapMode();
80 }
81 ::tools::Rectangle aVisArea(rWin.PixelToLogic(::tools::Rectangle(Point(0,0), aVisSizePixel)));
82 if (bTiledRendering)
83 rWin.GetOutDev()->Pop();
84 Size aVisAreaSize(aVisArea.GetSize());
85
86 if ( aVisArea.Contains(rRect) )
87 return;
88
89 // object is not entirely in visible area
90 sal_Int32 nFreeSpaceX(aVisAreaSize.Width() - aLogicSize.Width());
91 sal_Int32 nFreeSpaceY(aVisAreaSize.Height() - aLogicSize.Height());
92
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)
100 );
101 Point aNewPos(aVisArea.TopLeft());
102
103 if(nFreeSpaceX < 0)
104 {
105 if(aInnerRectangle.Left() > rRect.Right())
106 {
107 // object moves out to the left
108 aNewPos.AdjustX( -(aVisAreaSize.Width() / 2) );
109 }
110
111 if(aInnerRectangle.Right() < rRect.Left())
112 {
113 // object moves out to the right
114 aNewPos.AdjustX(aVisAreaSize.Width() / 2 );
115 }
116 }
117 else
118 {
119 if(nFreeSpaceX > rRect.GetWidth())
120 {
121 nFreeSpaceX = rRect.GetWidth();
122 }
123
124 if(nFreeSpaceX <= 0)
125 {
126 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
127 }
128 else
129 {
130 const ::tools::Long distRight(rRect.Right() - aNewPos.X() - aVisAreaSize.Width());
131
132 if(distRight > 0)
133 {
134 ::tools::Long mult = (distRight / nFreeSpaceX) + 1;
135 aNewPos.AdjustX(mult * nFreeSpaceX );
136 }
137
138 const ::tools::Long distLeft(aNewPos.X() - rRect.Left());
139
140 if(distLeft > 0)
141 {
142 ::tools::Long mult = (distLeft / nFreeSpaceX) + 1;
143 aNewPos.AdjustX( -(mult * nFreeSpaceX) );
144 }
145 }
146 }
147
148 if(nFreeSpaceY < 0)
149 {
150 if(aInnerRectangle.Top() > rRect.Bottom())
151 {
152 // object moves out to the top
153 aNewPos.AdjustY( -(aVisAreaSize.Height() / 2) );
154 }
155
156 if(aInnerRectangle.Bottom() < rRect.Top())
157 {
158 // object moves out to the right
159 aNewPos.AdjustY(aVisAreaSize.Height() / 2 );
160 }
161 }
162 else
163 {
164 if(nFreeSpaceY > rRect.GetHeight())
165 {
166 nFreeSpaceY = rRect.GetHeight();
167 }
168
169 if(nFreeSpaceY <= 0)
170 {
171 SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)");
172 }
173 else
174 {
175 const ::tools::Long distBottom(rRect.Bottom() - aNewPos.Y() - aVisAreaSize.Height());
176
177 if(distBottom > 0)
178 {
179 ::tools::Long mult = (distBottom / nFreeSpaceY) + 1;
180 aNewPos.AdjustY(mult * nFreeSpaceY );
181 }
182
183 const ::tools::Long distTop(aNewPos.Y() - rRect.Top());
184
185 if(distTop > 0)
186 {
187 ::tools::Long mult = (distTop / nFreeSpaceY) + 1;
188 aNewPos.AdjustY( -(mult * nFreeSpaceY) );
189 }
190 }
191 }
192
193 // did position change? Does it need to be set?
194 if(aNewPos != aVisArea.TopLeft())
195 {
196 aVisArea.SetPos(aNewPos);
197 SetZoomRect(aVisArea);
198 }
199}
200
201}
202
203/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
constexpr tools::Long Y() const
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
sd::ViewShell * GetViewShell()
void GotoBookmark(std::u16string_view rBookmark)
Definition: docshel4.cxx:695
void Connect(sd::ViewShell *pViewSh)
Definition: docshel2.cxx:147
bool IsMouseSelecting() const
virtual void SetZoomRect(const ::tools::Rectangle &rZoomRect) override
Set zoom rectangle for active window.
Definition: drviews1.cxx:298
void GotoBookmark(std::u16string_view rBookmark)
Definition: drviewsh.cxx:32
void MakeVisible(const ::tools::Rectangle &rRect, vcl::Window &rWin)
Make area visible (scroll part of picture) |* .
Definition: drviewsh.cxx:48
bool IsMouseButtonDown() const
static bool IsRunning(ViewShellBase const &rBase)
returns true if there is a running presentation for the given ViewShellBase
Definition: slideshow.cxx:208
SD_DLLPUBLIC DrawDocShell * GetDocSh() const
Definition: viewshel.cxx:1407
SD_DLLPUBLIC ViewShellBase & GetViewShellBase() const
Definition: viewshel.cxx:1397
bool Contains(const Point &rPOINT) const
constexpr tools::Long Top() const
constexpr Point TopLeft() const
void SetPos(const Point &rPoint)
constexpr Size GetSize() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
bool IsMapModeEnabled() const
::OutputDevice const * GetOutDev() const
Point PixelToLogic(const Point &rDevicePt) const
Size GetOutputSizePixel() const
void EnableMapMode(bool bEnable=true)
#define SAL_WARN(area, stream)
long Long