/src/libreoffice/sd/source/ui/view/drviewsh.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
30 | | namespace sd { |
31 | | |
32 | | void DrawViewShell::GotoBookmark(std::u16string_view rBookmark) |
33 | 0 | { |
34 | 0 | ::sd::DrawDocShell* pDocSh = GetDocSh(); |
35 | 0 | if( pDocSh ) |
36 | 0 | { |
37 | 0 | 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 | 0 | pDocSh->Connect(this); |
39 | 0 | pDocSh->GotoBookmark(rBookmark); |
40 | 0 | } |
41 | 0 | } |
42 | | |
43 | | /** |
44 | | * Make area visible (scroll part of picture) |
45 | | |* |
46 | | \************************************************************************/ |
47 | | |
48 | | void DrawViewShell::MakeVisible(const ::tools::Rectangle& rRect, vcl::Window& rWin) |
49 | 0 | { |
50 | 0 | if ( IsMouseButtonDown() && !IsMouseSelecting() ) |
51 | 0 | return; |
52 | | |
53 | 0 | if ( SlideShow::IsRunning( GetViewShellBase() ) && !SlideShow::IsInteractiveSlideshow( &GetViewShellBase() ) ) // IASS |
54 | 0 | return; |
55 | | |
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 | 0 | const bool bOverflowInX(!rtl::math::approxEqual(static_cast<double>(rRect.getOpenWidth()), static_cast<double>(rRect.Right()) - static_cast<double>(rRect.Left()))); |
60 | 0 | const bool bOverflowInY(!rtl::math::approxEqual(static_cast<double>(rRect.getOpenHeight()), static_cast<double>(rRect.Bottom()) - static_cast<double>(rRect.Top()))); |
61 | |
|
62 | 0 | if(bOverflowInX || bOverflowInY) |
63 | 0 | { |
64 | 0 | SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)"); |
65 | 0 | return; |
66 | 0 | } |
67 | | |
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 | 0 | const Size aLogicSize(rRect.GetSize()); |
75 | | |
76 | | // visible area |
77 | 0 | Size aVisSizePixel(rWin.GetOutputSizePixel()); |
78 | 0 | bool bTiledRendering = comphelper::LibreOfficeKit::isActive() && !rWin.IsMapModeEnabled(); |
79 | 0 | if (bTiledRendering) |
80 | 0 | { |
81 | 0 | rWin.GetOutDev()->Push(vcl::PushFlags::MAPMODE); |
82 | 0 | rWin.EnableMapMode(); |
83 | 0 | } |
84 | 0 | ::tools::Rectangle aVisArea(rWin.PixelToLogic(::tools::Rectangle(Point(0,0), aVisSizePixel))); |
85 | 0 | if (bTiledRendering) |
86 | 0 | rWin.GetOutDev()->Pop(); |
87 | 0 | Size aVisAreaSize(aVisArea.GetSize()); |
88 | |
|
89 | 0 | if ( aVisArea.Contains(rRect) ) |
90 | 0 | return; |
91 | | |
92 | | // object is not entirely in visible area |
93 | 0 | sal_Int32 nFreeSpaceX(aVisAreaSize.Width() - aLogicSize.Width()); |
94 | 0 | sal_Int32 nFreeSpaceY(aVisAreaSize.Height() - aLogicSize.Height()); |
95 | | |
96 | | // allow a mode for move-only visibility without zooming. |
97 | 0 | const sal_Int32 nPercentBorder(30); |
98 | 0 | const ::tools::Rectangle aInnerRectangle( |
99 | 0 | aVisArea.Left() + ((aVisAreaSize.Width() * nPercentBorder) / 200), |
100 | 0 | aVisArea.Top() + ((aVisAreaSize.Height() * nPercentBorder) / 200), |
101 | 0 | aVisArea.Right() - ((aVisAreaSize.Width() * nPercentBorder) / 200), |
102 | 0 | aVisArea.Bottom() - ((aVisAreaSize.Height() * nPercentBorder) / 200) |
103 | 0 | ); |
104 | 0 | Point aNewPos(aVisArea.TopLeft()); |
105 | |
|
106 | 0 | if(nFreeSpaceX < 0) |
107 | 0 | { |
108 | 0 | if(aInnerRectangle.Left() > rRect.Right()) |
109 | 0 | { |
110 | | // object moves out to the left |
111 | 0 | aNewPos.AdjustX( -(aVisAreaSize.Width() / 2) ); |
112 | 0 | } |
113 | |
|
114 | 0 | if(aInnerRectangle.Right() < rRect.Left()) |
115 | 0 | { |
116 | | // object moves out to the right |
117 | 0 | aNewPos.AdjustX(aVisAreaSize.Width() / 2 ); |
118 | 0 | } |
119 | 0 | } |
120 | 0 | else |
121 | 0 | { |
122 | 0 | if(nFreeSpaceX > rRect.GetWidth()) |
123 | 0 | { |
124 | 0 | nFreeSpaceX = rRect.GetWidth(); |
125 | 0 | } |
126 | |
|
127 | 0 | if(nFreeSpaceX <= 0) |
128 | 0 | { |
129 | 0 | SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)"); |
130 | 0 | } |
131 | 0 | else |
132 | 0 | { |
133 | 0 | const ::tools::Long distRight(rRect.Right() - aNewPos.X() - aVisAreaSize.Width()); |
134 | |
|
135 | 0 | if(distRight > 0) |
136 | 0 | { |
137 | 0 | ::tools::Long mult = (distRight / nFreeSpaceX) + 1; |
138 | 0 | aNewPos.AdjustX(mult * nFreeSpaceX ); |
139 | 0 | } |
140 | |
|
141 | 0 | const ::tools::Long distLeft(aNewPos.X() - rRect.Left()); |
142 | |
|
143 | 0 | if(distLeft > 0) |
144 | 0 | { |
145 | 0 | ::tools::Long mult = (distLeft / nFreeSpaceX) + 1; |
146 | 0 | aNewPos.AdjustX( -(mult * nFreeSpaceX) ); |
147 | 0 | } |
148 | 0 | } |
149 | 0 | } |
150 | | |
151 | 0 | if(nFreeSpaceY < 0) |
152 | 0 | { |
153 | 0 | if(aInnerRectangle.Top() > rRect.Bottom()) |
154 | 0 | { |
155 | | // object moves out to the top |
156 | 0 | aNewPos.AdjustY( -(aVisAreaSize.Height() / 2) ); |
157 | 0 | } |
158 | |
|
159 | 0 | if(aInnerRectangle.Bottom() < rRect.Top()) |
160 | 0 | { |
161 | | // object moves out to the right |
162 | 0 | aNewPos.AdjustY(aVisAreaSize.Height() / 2 ); |
163 | 0 | } |
164 | 0 | } |
165 | 0 | else |
166 | 0 | { |
167 | 0 | if(nFreeSpaceY > rRect.GetHeight()) |
168 | 0 | { |
169 | 0 | nFreeSpaceY = rRect.GetHeight(); |
170 | 0 | } |
171 | |
|
172 | 0 | if(nFreeSpaceY <= 0) |
173 | 0 | { |
174 | 0 | SAL_WARN("sd", "The given Rectangle contains values that lead to numerical overflows (!)"); |
175 | 0 | } |
176 | 0 | else |
177 | 0 | { |
178 | 0 | const ::tools::Long distBottom(rRect.Bottom() - aNewPos.Y() - aVisAreaSize.Height()); |
179 | |
|
180 | 0 | if(distBottom > 0) |
181 | 0 | { |
182 | 0 | ::tools::Long mult = (distBottom / nFreeSpaceY) + 1; |
183 | 0 | aNewPos.AdjustY(mult * nFreeSpaceY ); |
184 | 0 | } |
185 | |
|
186 | 0 | const ::tools::Long distTop(aNewPos.Y() - rRect.Top()); |
187 | |
|
188 | 0 | if(distTop > 0) |
189 | 0 | { |
190 | 0 | ::tools::Long mult = (distTop / nFreeSpaceY) + 1; |
191 | 0 | aNewPos.AdjustY( -(mult * nFreeSpaceY) ); |
192 | 0 | } |
193 | 0 | } |
194 | 0 | } |
195 | | |
196 | | // did position change? Does it need to be set? |
197 | 0 | if(aNewPos != aVisArea.TopLeft()) |
198 | 0 | { |
199 | 0 | aVisArea.SetPos(aNewPos); |
200 | 0 | SetZoomRect(aVisArea); |
201 | 0 | } |
202 | 0 | } |
203 | | |
204 | | } |
205 | | |
206 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |