Bump version to 4.3-4
[LibreOffice.git] / basctl / source / dlged / dlgedview.cxx
blobc75fd1915a2263f2203d7c0af5c986b411b65c81
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 <svx/svxids.hrc>
25 #include <sfx2/viewfrm.hxx>
27 #include <basidesh.hxx>
28 #include <iderdll.hxx>
29 #include "dlgedobj.hxx"
31 namespace basctl
34 TYPEINIT1( DlgEdView, SdrView );
36 DlgEdView::DlgEdView (SdrModel& rModel, OutputDevice& rOut, DlgEditor& rEditor) :
37 SdrView(&rModel, &rOut),
38 rDlgEditor(rEditor)
40 // #114898#
41 SetBufferedOutputAllowed(true);
42 SetBufferedOverlayAllowed(true);
45 DlgEdView::~DlgEdView()
49 void DlgEdView::MarkListHasChanged()
51 SdrView::MarkListHasChanged();
53 DlgEdHint aHint( DlgEdHint::SELECTIONCHANGED );
54 rDlgEditor.Broadcast( aHint );
55 rDlgEditor.UpdatePropertyBrowserDelayed();
58 void DlgEdView::MakeVisible( const Rectangle& rRect, Window& rWin )
60 // visible area
61 MapMode aMap( rWin.GetMapMode() );
62 Point aOrg( aMap.GetOrigin() );
63 Size aVisSize( rWin.GetOutputSize() );
64 Rectangle RectTmp( Point(-aOrg.X(),-aOrg.Y()), aVisSize );
65 Rectangle aVisRect( RectTmp );
67 // check, if rectangle is inside visible area
68 if ( !aVisRect.IsInside( rRect ) )
70 // calculate scroll distance; the rectangle must be inside the visible area
71 sal_Int32 nScrollX = 0, nScrollY = 0;
73 sal_Int32 nVisLeft = aVisRect.Left();
74 sal_Int32 nVisRight = aVisRect.Right();
75 sal_Int32 nVisTop = aVisRect.Top();
76 sal_Int32 nVisBottom = aVisRect.Bottom();
78 sal_Int32 nDeltaX = rDlgEditor.GetHScroll()->GetLineSize();
79 sal_Int32 nDeltaY = rDlgEditor.GetVScroll()->GetLineSize();
81 while ( rRect.Right() > nVisRight + nScrollX )
82 nScrollX += nDeltaX;
84 while ( rRect.Left() < nVisLeft + nScrollX )
85 nScrollX -= nDeltaX;
87 while ( rRect.Bottom() > nVisBottom + nScrollY )
88 nScrollY += nDeltaY;
90 while ( rRect.Top() < nVisTop + nScrollY )
91 nScrollY -= nDeltaY;
93 // don't scroll beyond the page size
94 Size aPageSize = rDlgEditor.GetPage().GetSize();
95 sal_Int32 nPageWidth = aPageSize.Width();
96 sal_Int32 nPageHeight = aPageSize.Height();
98 if ( nVisRight + nScrollX > nPageWidth )
99 nScrollX = nPageWidth - nVisRight;
101 if ( nVisLeft + nScrollX < 0 )
102 nScrollX = -nVisLeft;
104 if ( nVisBottom + nScrollY > nPageHeight )
105 nScrollY = nPageHeight - nVisBottom;
107 if ( nVisTop + nScrollY < 0 )
108 nScrollY = -nVisTop;
110 // scroll window
111 rWin.Update();
112 rWin.Scroll( -nScrollX, -nScrollY );
113 aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
114 rWin.SetMapMode( aMap );
115 rWin.Update();
116 rWin.Invalidate();
118 // update scroll bars
119 rDlgEditor.UpdateScrollBars();
121 DlgEdHint aHint( DlgEdHint::WINDOWSCROLLED );
122 rDlgEditor.Broadcast( aHint );
126 SdrObject* impLocalHitCorrection(SdrObject* pRetval, const Point& rPnt, sal_uInt16 nTol)
128 DlgEdObj* pDlgEdObj = dynamic_cast< DlgEdObj* >(pRetval);
130 if(pDlgEdObj)
132 bool bExcludeInner(false);
134 if(0 != dynamic_cast< DlgEdForm* >(pRetval))
136 // from DlgEdForm::CheckHit; exclude inner for DlgEdForm
137 bExcludeInner = true;
139 else if(pDlgEdObj->supportsService("com.sun.star.awt.UnoControlGroupBoxModel"))
141 // from DlgEdObj::CheckHit; exclude inner for group shapes
142 bExcludeInner = true;
145 if(bExcludeInner)
147 // use direct model data; it's a DlgEdObj, so GetLastBoundRect()
148 // will access aOutRect directly
149 const Rectangle aOuterRectangle(pDlgEdObj->GetLastBoundRect());
151 if(!aOuterRectangle.IsEmpty()
152 && RECT_EMPTY != aOuterRectangle.Right()
153 && RECT_EMPTY != aOuterRectangle.Bottom())
155 basegfx::B2DRange aOuterRange(
156 aOuterRectangle.Left(), aOuterRectangle.Top(),
157 aOuterRectangle.Right(), aOuterRectangle.Bottom());
159 if(nTol)
161 aOuterRange.grow(-1.0 * nTol);
164 if(aOuterRange.isInside(basegfx::B2DPoint(rPnt.X(), rPnt.Y())))
166 pRetval = 0;
172 return pRetval;
175 SdrObject* DlgEdView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nTol, SdrObject* pObj, SdrPageView* pPV, sal_uLong nOptions, const SetOfByte* pMVisLay) const
177 // call parent
178 SdrObject* pRetval = SdrView::CheckSingleSdrObjectHit(rPnt, nTol, pObj, pPV, nOptions, pMVisLay);
180 if(pRetval)
182 // check hitted object locally
183 pRetval = impLocalHitCorrection(pRetval, rPnt, nTol);
186 return pRetval;
189 } // namespace basctl
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */