tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / basctl / source / dlged / dlgedview.cxx
blob5ffe5185a2fb5a0d71305a686d4cb4735c7adb7f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
21 #include <dlged.hxx>
22 #include <dlgedpage.hxx>
24 #include <svtools/scrolladaptor.hxx>
25 #include <vcl/canvastools.hxx>
27 #include <dlgedobj.hxx>
29 namespace basctl
32 DlgEdView::DlgEdView(
33 SdrModel& rSdrModel,
34 OutputDevice& rOut,
35 DlgEditor& rEditor)
36 : SdrView(rSdrModel, &rOut),
37 rDlgEditor(rEditor)
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 )
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 );
65 // check, if rectangle is inside visible area
66 if ( aVisRect.Contains( rRect ) )
67 return;
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 )
81 nScrollX += nDeltaX;
83 while ( rRect.Left() < nVisLeft + nScrollX )
84 nScrollX -= nDeltaX;
86 while ( rRect.Bottom() > nVisBottom + nScrollY )
87 nScrollY += nDeltaY;
89 while ( rRect.Top() < nVisTop + nScrollY )
90 nScrollY -= nDeltaY;
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 )
107 nScrollY = -nVisTop;
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();
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);
127 if(pDlgEdObj)
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;
142 if(bExcludeInner)
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);
152 if(nTol)
154 aOuterRange.grow(-1.0 * nTol);
157 if(aOuterRange.isInside(basegfx::B2DPoint(rPnt.X(), rPnt.Y())))
159 pRetval = nullptr;
165 return pRetval;
168 SdrObject* DlgEdView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nTol, SdrObject* pObj, SdrPageView* pPV, SdrSearchOptions nOptions, const SdrLayerIDSet* pMVisLay) const
170 // call parent
171 SdrObject* pRetval = SdrView::CheckSingleSdrObjectHit(rPnt, nTol, pObj, pPV, nOptions, pMVisLay);
173 if(pRetval)
175 // check hit object locally
176 pRetval = impLocalHitCorrection(pRetval, rPnt, nTol);
179 return pRetval;
182 } // namespace basctl
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */