xref: /AOO41X/main/basctl/source/dlged/dlgedview.cxx (revision 31598a226906602f93ad246cbee896e3caca5f8f)
1*31598a22SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*31598a22SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*31598a22SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*31598a22SAndrew Rist  * distributed with this work for additional information
6*31598a22SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*31598a22SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*31598a22SAndrew Rist  * "License"); you may not use this file except in compliance
9*31598a22SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*31598a22SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*31598a22SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*31598a22SAndrew Rist  * software distributed under the License is distributed on an
15*31598a22SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*31598a22SAndrew Rist  * KIND, either express or implied.  See the License for the
17*31598a22SAndrew Rist  * specific language governing permissions and limitations
18*31598a22SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*31598a22SAndrew Rist  *************************************************************/
21*31598a22SAndrew Rist 
22*31598a22SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basctl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "dlgedview.hxx"
29cdf0e10cSrcweir #include "dlged.hxx"
30cdf0e10cSrcweir #include <dlgedpage.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #ifndef _SVXIDS_HRC
33cdf0e10cSrcweir #include <svx/svxids.hrc>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <basidesh.hxx>
38cdf0e10cSrcweir #include <iderdll.hxx>
39cdf0e10cSrcweir #include "dlgedobj.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir TYPEINIT1( DlgEdView, SdrView );
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //----------------------------------------------------------------------------
44cdf0e10cSrcweir 
DlgEdView(SdrModel * pModel,OutputDevice * pOut,DlgEditor * pEditor)45cdf0e10cSrcweir DlgEdView::DlgEdView( SdrModel* pModel, OutputDevice* pOut, DlgEditor* pEditor )
46cdf0e10cSrcweir 	:SdrView( pModel, pOut )
47cdf0e10cSrcweir 	,pDlgEditor( pEditor )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir 	// #114898#
50cdf0e10cSrcweir 	SetBufferedOutputAllowed(true);
51cdf0e10cSrcweir 	SetBufferedOverlayAllowed(true);
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //----------------------------------------------------------------------------
55cdf0e10cSrcweir 
~DlgEdView()56cdf0e10cSrcweir DlgEdView::~DlgEdView()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //----------------------------------------------------------------------------
61cdf0e10cSrcweir 
MarkListHasChanged()62cdf0e10cSrcweir void DlgEdView::MarkListHasChanged()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	SdrView::MarkListHasChanged();
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	DlgEdHint aHint( DLGED_HINT_SELECTIONCHANGED );
67cdf0e10cSrcweir 	if ( pDlgEditor )
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir 		pDlgEditor->Broadcast( aHint );
70cdf0e10cSrcweir         pDlgEditor->UpdatePropertyBrowserDelayed();
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir //----------------------------------------------------------------------------
75cdf0e10cSrcweir 
MakeVisible(const Rectangle & rRect,Window & rWin)76cdf0e10cSrcweir void DlgEdView::MakeVisible( const Rectangle& rRect, Window& rWin )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	// visible area
79cdf0e10cSrcweir 	MapMode aMap( rWin.GetMapMode() );
80cdf0e10cSrcweir 	Point aOrg( aMap.GetOrigin() );
81cdf0e10cSrcweir 	Size aVisSize( rWin.GetOutputSize() );
82cdf0e10cSrcweir     Rectangle RectTmp( Point(-aOrg.X(),-aOrg.Y()), aVisSize );
83cdf0e10cSrcweir 	Rectangle aVisRect( RectTmp );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	// check, if rectangle is inside visible area
86cdf0e10cSrcweir 	if ( !aVisRect.IsInside( rRect ) )
87cdf0e10cSrcweir 	{
88cdf0e10cSrcweir 		// calculate scroll distance; the rectangle must be inside the visible area
89cdf0e10cSrcweir 		sal_Int32 nScrollX = 0, nScrollY = 0;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 		sal_Int32 nVisLeft   = aVisRect.Left();
92cdf0e10cSrcweir 		sal_Int32 nVisRight  = aVisRect.Right();
93cdf0e10cSrcweir 		sal_Int32 nVisTop    = aVisRect.Top();
94cdf0e10cSrcweir 		sal_Int32 nVisBottom = aVisRect.Bottom();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		sal_Int32 nDeltaX = pDlgEditor->GetHScroll()->GetLineSize();
97cdf0e10cSrcweir 		sal_Int32 nDeltaY = pDlgEditor->GetVScroll()->GetLineSize();
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		while ( rRect.Right() > nVisRight + nScrollX )
100cdf0e10cSrcweir 			nScrollX += nDeltaX;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 		while ( rRect.Left() < nVisLeft + nScrollX )
103cdf0e10cSrcweir 			nScrollX -= nDeltaX;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		while ( rRect.Bottom() > nVisBottom + nScrollY )
106cdf0e10cSrcweir 			nScrollY += nDeltaY;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 		while ( rRect.Top() < nVisTop + nScrollY )
109cdf0e10cSrcweir 			nScrollY -= nDeltaY;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		// don't scroll beyond the page size
112cdf0e10cSrcweir 		Size aPageSize = pDlgEditor->GetPage()->GetSize();
113cdf0e10cSrcweir 		sal_Int32 nPageWidth  = aPageSize.Width();
114cdf0e10cSrcweir 		sal_Int32 nPageHeight = aPageSize.Height();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		if ( nVisRight + nScrollX > nPageWidth )
117cdf0e10cSrcweir 			nScrollX = nPageWidth - nVisRight;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 		if ( nVisLeft + nScrollX < 0 )
120cdf0e10cSrcweir 			nScrollX = -nVisLeft;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 		if ( nVisBottom + nScrollY > nPageHeight )
123cdf0e10cSrcweir 			nScrollY = nPageHeight - nVisBottom;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		if ( nVisTop + nScrollY < 0 )
126cdf0e10cSrcweir 			nScrollY = -nVisTop;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		// scroll window
129cdf0e10cSrcweir 		rWin.Update();
130cdf0e10cSrcweir 		rWin.Scroll( -nScrollX, -nScrollY );
131cdf0e10cSrcweir 		aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
132cdf0e10cSrcweir 		rWin.SetMapMode( aMap );
133cdf0e10cSrcweir 		rWin.Update();
134cdf0e10cSrcweir 		rWin.Invalidate();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 		// update scroll bars
137cdf0e10cSrcweir 		if ( pDlgEditor )
138cdf0e10cSrcweir 			pDlgEditor->UpdateScrollBars();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 		DlgEdHint aHint( DLGED_HINT_WINDOWSCROLLED );
141cdf0e10cSrcweir 		if ( pDlgEditor )
142cdf0e10cSrcweir 			pDlgEditor->Broadcast( aHint );
143cdf0e10cSrcweir 	}
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir //----------------------------------------------------------------------------
147cdf0e10cSrcweir 
impLocalHitCorrection(SdrObject * pRetval,const Point & rPnt,sal_uInt16 nTol)148cdf0e10cSrcweir SdrObject* impLocalHitCorrection(SdrObject* pRetval, const Point& rPnt, sal_uInt16 nTol)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     DlgEdObj* pDlgEdObj = dynamic_cast< DlgEdObj* >(pRetval);
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     if(pDlgEdObj)
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         bool bExcludeInner(false);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         if(0 != dynamic_cast< DlgEdForm* >(pRetval))
157cdf0e10cSrcweir         {
158cdf0e10cSrcweir             // from DlgEdForm::CheckHit; exclude inner for DlgEdForm
159cdf0e10cSrcweir             bExcludeInner = true;
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir         else if(pDlgEdObj->supportsService("com.sun.star.awt.UnoControlGroupBoxModel"))
162cdf0e10cSrcweir         {
163cdf0e10cSrcweir             // from DlgEdObj::CheckHit; exclude inner for group shapes
164cdf0e10cSrcweir             bExcludeInner = true;
165cdf0e10cSrcweir         }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         if(bExcludeInner)
168cdf0e10cSrcweir         {
169cdf0e10cSrcweir             // use direct model data; it's a DlgEdObj, so GetLastBoundRect()
170cdf0e10cSrcweir             // will access aOutRect directly
171cdf0e10cSrcweir             const Rectangle aOuterRectangle(pDlgEdObj->GetLastBoundRect());
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	        if(!aOuterRectangle.IsEmpty()
174cdf0e10cSrcweir 		        && RECT_EMPTY != aOuterRectangle.Right()
175cdf0e10cSrcweir 		        && RECT_EMPTY != aOuterRectangle.Bottom())
176cdf0e10cSrcweir 	        {
177cdf0e10cSrcweir                 basegfx::B2DRange aOuterRange(
178cdf0e10cSrcweir                     aOuterRectangle.Left(), aOuterRectangle.Top(),
179cdf0e10cSrcweir                     aOuterRectangle.Right(), aOuterRectangle.Bottom());
180cdf0e10cSrcweir 
181cdf0e10cSrcweir                 if(nTol)
182cdf0e10cSrcweir                 {
183cdf0e10cSrcweir                     aOuterRange.grow(-1.0 * nTol);
184cdf0e10cSrcweir                 }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir                 if(aOuterRange.isInside(basegfx::B2DPoint(rPnt.X(), rPnt.Y())))
187cdf0e10cSrcweir                 {
188cdf0e10cSrcweir                     pRetval = 0;
189cdf0e10cSrcweir                 }
190cdf0e10cSrcweir             }
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     return pRetval;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
CheckSingleSdrObjectHit(const Point & rPnt,sal_uInt16 nTol,SdrObject * pObj,SdrPageView * pPV,sal_uLong nOptions,const SetOfByte * pMVisLay) const197cdf0e10cSrcweir SdrObject* DlgEdView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nTol, SdrObject* pObj, SdrPageView* pPV, sal_uLong nOptions, const SetOfByte* pMVisLay) const
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     // call parent
200cdf0e10cSrcweir     SdrObject* pRetval = SdrView::CheckSingleSdrObjectHit(rPnt, nTol, pObj, pPV, nOptions, pMVisLay);
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     if(pRetval)
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         // check hitted object locally
205cdf0e10cSrcweir         pRetval = impLocalHitCorrection(pRetval, rPnt, nTol);
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     return pRetval;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir //----------------------------------------------------------------------------
212cdf0e10cSrcweir // eof
213