LibreOffice Module basctl (master) 1
dlgedview.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 <dlgedview.hxx>
21#include <dlged.hxx>
22#include <dlgedpage.hxx>
23
25#include <vcl/canvastools.hxx>
26
27#include <dlgedobj.hxx>
28
29namespace basctl
30{
31
33 SdrModel& rSdrModel,
34 OutputDevice& rOut,
35 DlgEditor& rEditor)
36: SdrView(rSdrModel, &rOut),
37 rDlgEditor(rEditor)
38{
41}
42
44{
45}
46
48{
50
52 rDlgEditor.Broadcast( aHint );
54}
55
57{
58 // visible area
59 MapMode aMap( rWin.GetMapMode() );
60 Point aOrg( aMap.GetOrigin() );
61 Size aVisSize( rWin.GetOutDev()->GetOutputSize() );
62 tools::Rectangle RectTmp( Point(-aOrg.X(),-aOrg.Y()), aVisSize );
63 tools::Rectangle aVisRect( RectTmp );
64
65 // check, if rectangle is inside visible area
66 if ( aVisRect.Contains( rRect ) )
67 return;
68
69 // calculate scroll distance; the rectangle must be inside the visible area
70 sal_Int32 nScrollX = 0, nScrollY = 0;
71
72 sal_Int32 nVisLeft = aVisRect.Left();
73 sal_Int32 nVisRight = aVisRect.Right();
74 sal_Int32 nVisTop = aVisRect.Top();
75 sal_Int32 nVisBottom = aVisRect.Bottom();
76
77 sal_Int32 nDeltaX = rDlgEditor.GetHScroll()->GetLineSize();
78 sal_Int32 nDeltaY = rDlgEditor.GetVScroll()->GetLineSize();
79
80 while ( rRect.Right() > nVisRight + nScrollX )
81 nScrollX += nDeltaX;
82
83 while ( rRect.Left() < nVisLeft + nScrollX )
84 nScrollX -= nDeltaX;
85
86 while ( rRect.Bottom() > nVisBottom + nScrollY )
87 nScrollY += nDeltaY;
88
89 while ( rRect.Top() < nVisTop + nScrollY )
90 nScrollY -= nDeltaY;
91
92 // don't scroll beyond the page size
93 Size aPageSize = rDlgEditor.GetPage().GetSize();
94 sal_Int32 nPageWidth = aPageSize.Width();
95 sal_Int32 nPageHeight = aPageSize.Height();
96
97 if ( nVisRight + nScrollX > nPageWidth )
98 nScrollX = nPageWidth - nVisRight;
99
100 if ( nVisLeft + nScrollX < 0 )
101 nScrollX = -nVisLeft;
102
103 if ( nVisBottom + nScrollY > nPageHeight )
104 nScrollY = nPageHeight - nVisBottom;
105
106 if ( nVisTop + nScrollY < 0 )
107 nScrollY = -nVisTop;
108
109 // scroll window
110 rWin.PaintImmediately();
111 rWin.Scroll( -nScrollX, -nScrollY );
112 aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
113 rWin.SetMapMode( aMap );
114 rWin.Invalidate();
115
116 // update scroll bars
118
120 rDlgEditor.Broadcast( aHint );
121}
122
123static SdrObject* impLocalHitCorrection(SdrObject* pRetval, const Point& rPnt, sal_uInt16 nTol)
124{
125 DlgEdObj* pDlgEdObj = dynamic_cast< DlgEdObj* >(pRetval);
126
127 if(pDlgEdObj)
128 {
129 bool bExcludeInner(false);
130
131 if(dynamic_cast< DlgEdForm* >(pRetval) != nullptr)
132 {
133 // from DlgEdForm::CheckHit; exclude inner for DlgEdForm
134 bExcludeInner = true;
135 }
136 else if(pDlgEdObj->supportsService("com.sun.star.awt.UnoControlGroupBoxModel"))
137 {
138 // from DlgEdObj::CheckHit; exclude inner for group shapes
139 bExcludeInner = true;
140 }
141
142 if(bExcludeInner)
143 {
144 // use direct model data; it's a DlgEdObj, so GetLastBoundRect()
145 // will access aOutRect directly
146 const tools::Rectangle aOuterRectangle(pDlgEdObj->GetLastBoundRect());
147
148 if(!aOuterRectangle.IsEmpty())
149 {
150 basegfx::B2DRange aOuterRange = vcl::unotools::b2DRectangleFromRectangle(aOuterRectangle);
151
152 if(nTol)
153 {
154 aOuterRange.grow(-1.0 * nTol);
155 }
156
157 if(aOuterRange.isInside(basegfx::B2DPoint(rPnt.X(), rPnt.Y())))
158 {
159 pRetval = nullptr;
160 }
161 }
162 }
163 }
164
165 return pRetval;
166}
167
168SdrObject* DlgEdView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nTol, SdrObject* pObj, SdrPageView* pPV, SdrSearchOptions nOptions, const SdrLayerIDSet* pMVisLay) const
169{
170 // call parent
171 SdrObject* pRetval = SdrView::CheckSingleSdrObjectHit(rPnt, nTol, pObj, pPV, nOptions, pMVisLay);
172
173 if(pRetval)
174 {
175 // check hit object locally
176 pRetval = impLocalHitCorrection(pRetval, rPnt, nTol);
177 }
178
179 return pRetval;
180}
181
182} // namespace basctl
183
184/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Size GetOutputSize() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
virtual tools::Long GetLineSize() const override
virtual SdrObject * CheckSingleSdrObjectHit(const Point &rPnt, sal_uInt16 nTol, SdrObject *pObj, SdrPageView *pPV, SdrSearchOptions nOptions, const SdrLayerIDSet *pMVisLay) const
virtual void MarkListHasChanged() override
virtual const tools::Rectangle & GetLastBoundRect() const
Size GetSize() const
void SetBufferedOverlayAllowed(bool bNew)
void SetBufferedOutputAllowed(bool bNew)
void Broadcast(const SfxHint &rHint)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool supportsService(OUString const &serviceName) const
Definition: dlgedobj.cxx:661
virtual void MarkListHasChanged() override
Definition: dlgedview.cxx:47
DlgEditor & rDlgEditor
Definition: dlgedview.hxx:37
DlgEdView(SdrModel &rSdrModel, OutputDevice &rOut, DlgEditor &rEditor)
Definition: dlgedview.cxx:32
virtual void MakeVisible(const tools::Rectangle &rRect, vcl::Window &rWin) override
Definition: dlgedview.cxx:56
virtual ~DlgEdView() override
Definition: dlgedview.cxx:43
virtual SdrObject * CheckSingleSdrObjectHit(const Point &rPnt, sal_uInt16 nTol, SdrObject *pObj, SdrPageView *pPV, SdrSearchOptions nOptions, const SdrLayerIDSet *pMVisLay) const override
Definition: dlgedview.cxx:168
ScrollAdaptor * GetVScroll() const
Definition: dlged.hxx:155
ScrollAdaptor * GetHScroll() const
Definition: dlged.hxx:154
void UpdateScrollBars()
Definition: dlged.cxx:324
DlgEdPage & GetPage() const
Definition: dlged.hxx:168
void UpdatePropertyBrowserDelayed()
Definition: dlged.cxx:1060
void grow(TYPE fValue)
bool isInside(const Tuple2D< TYPE > &rTuple) const
bool Contains(const Point &rPOINT) const
constexpr tools::Long Top() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
constexpr bool IsEmpty() const
void PaintImmediately()
void SetMapMode()
const MapMode & GetMapMode() const
::OutputDevice const * GetOutDev() const
virtual void Scroll(tools::Long nHorzScroll, tools::Long nVertScroll, ScrollFlags nFlags=ScrollFlags::NONE)
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
static SdrObject * impLocalHitCorrection(SdrObject *pRetval, const Point &rPnt, sal_uInt16 nTol)
Definition: dlgedview.cxx:123
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
HashMap_OWString_Interface aMap
SdrSearchOptions
const tools::Long nScrollX
const tools::Long nScrollY