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 <dlgedview.hxx>
22 #include <dlgedpage.hxx>
24 #include <svtools/scrolladaptor.hxx>
25 #include <vcl/canvastools.hxx>
27 #include <dlgedobj.hxx>
36 : SdrView(rSdrModel
, &rOut
),
39 SetBufferedOutputAllowed(true);
40 SetBufferedOverlayAllowed(true);
43 DlgEdView::~DlgEdView()
47 void DlgEdView::MarkListHasChanged()
49 SdrView::MarkListHasChanged();
51 DlgEdHint
aHint( DlgEdHint::SELECTIONCHANGED
);
52 rDlgEditor
.Broadcast( aHint
);
53 rDlgEditor
.UpdatePropertyBrowserDelayed();
56 void DlgEdView::MakeVisible( const tools::Rectangle
& rRect
, vcl::Window
& rWin
)
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
);
65 // check, if rectangle is inside visible area
66 if ( aVisRect
.Contains( rRect
) )
69 // calculate scroll distance; the rectangle must be inside the visible area
70 sal_Int32 nScrollX
= 0, nScrollY
= 0;
72 sal_Int32 nVisLeft
= aVisRect
.Left();
73 sal_Int32 nVisRight
= aVisRect
.Right();
74 sal_Int32 nVisTop
= aVisRect
.Top();
75 sal_Int32 nVisBottom
= aVisRect
.Bottom();
77 sal_Int32 nDeltaX
= rDlgEditor
.GetHScroll()->GetLineSize();
78 sal_Int32 nDeltaY
= rDlgEditor
.GetVScroll()->GetLineSize();
80 while ( rRect
.Right() > nVisRight
+ nScrollX
)
83 while ( rRect
.Left() < nVisLeft
+ nScrollX
)
86 while ( rRect
.Bottom() > nVisBottom
+ nScrollY
)
89 while ( rRect
.Top() < nVisTop
+ nScrollY
)
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();
97 if ( nVisRight
+ nScrollX
> nPageWidth
)
98 nScrollX
= nPageWidth
- nVisRight
;
100 if ( nVisLeft
+ nScrollX
< 0 )
101 nScrollX
= -nVisLeft
;
103 if ( nVisBottom
+ nScrollY
> nPageHeight
)
104 nScrollY
= nPageHeight
- nVisBottom
;
106 if ( nVisTop
+ nScrollY
< 0 )
110 rWin
.PaintImmediately();
111 rWin
.Scroll( -nScrollX
, -nScrollY
);
112 aMap
.SetOrigin( Point( aOrg
.X() - nScrollX
, aOrg
.Y() - nScrollY
) );
113 rWin
.SetMapMode( aMap
);
116 // update scroll bars
117 rDlgEditor
.UpdateScrollBars();
119 DlgEdHint
aHint( DlgEdHint::WINDOWSCROLLED
);
120 rDlgEditor
.Broadcast( aHint
);
123 static SdrObject
* impLocalHitCorrection(SdrObject
* pRetval
, const Point
& rPnt
, sal_uInt16 nTol
)
125 DlgEdObj
* pDlgEdObj
= dynamic_cast< DlgEdObj
* >(pRetval
);
129 bool bExcludeInner(false);
131 if(dynamic_cast< DlgEdForm
* >(pRetval
) != nullptr)
133 // from DlgEdForm::CheckHit; exclude inner for DlgEdForm
134 bExcludeInner
= true;
136 else if(pDlgEdObj
->supportsService(u
"com.sun.star.awt.UnoControlGroupBoxModel"_ustr
))
138 // from DlgEdObj::CheckHit; exclude inner for group shapes
139 bExcludeInner
= true;
144 // use direct model data; it's a DlgEdObj, so GetLastBoundRect()
145 // will access aOutRect directly
146 const tools::Rectangle
aOuterRectangle(pDlgEdObj
->GetLastBoundRect());
148 if(!aOuterRectangle
.IsEmpty())
150 basegfx::B2DRange aOuterRange
= vcl::unotools::b2DRectangleFromRectangle(aOuterRectangle
);
154 aOuterRange
.grow(-1.0 * nTol
);
157 if(aOuterRange
.isInside(basegfx::B2DPoint(rPnt
.X(), rPnt
.Y())))
168 SdrObject
* DlgEdView::CheckSingleSdrObjectHit(const Point
& rPnt
, sal_uInt16 nTol
, SdrObject
* pObj
, SdrPageView
* pPV
, SdrSearchOptions nOptions
, const SdrLayerIDSet
* pMVisLay
) const
171 SdrObject
* pRetval
= SdrView::CheckSingleSdrObjectHit(rPnt
, nTol
, pObj
, pPV
, nOptions
, pMVisLay
);
175 // check hit object locally
176 pRetval
= impLocalHitCorrection(pRetval
, rPnt
, nTol
);
182 } // namespace basctl
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */