xref: /AOO41X/main/basctl/source/dlged/dlgedview.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_basctl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "dlgedview.hxx"
33*cdf0e10cSrcweir #include "dlged.hxx"
34*cdf0e10cSrcweir #include <dlgedpage.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #ifndef _SVXIDS_HRC
37*cdf0e10cSrcweir #include <svx/svxids.hrc>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <basidesh.hxx>
42*cdf0e10cSrcweir #include <iderdll.hxx>
43*cdf0e10cSrcweir #include "dlgedobj.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir TYPEINIT1( DlgEdView, SdrView );
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //----------------------------------------------------------------------------
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir DlgEdView::DlgEdView( SdrModel* pModel, OutputDevice* pOut, DlgEditor* pEditor )
50*cdf0e10cSrcweir 	:SdrView( pModel, pOut )
51*cdf0e10cSrcweir 	,pDlgEditor( pEditor )
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir 	// #114898#
54*cdf0e10cSrcweir 	SetBufferedOutputAllowed(true);
55*cdf0e10cSrcweir 	SetBufferedOverlayAllowed(true);
56*cdf0e10cSrcweir }
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //----------------------------------------------------------------------------
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir DlgEdView::~DlgEdView()
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir //----------------------------------------------------------------------------
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir void DlgEdView::MarkListHasChanged()
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 	SdrView::MarkListHasChanged();
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 	DlgEdHint aHint( DLGED_HINT_SELECTIONCHANGED );
71*cdf0e10cSrcweir 	if ( pDlgEditor )
72*cdf0e10cSrcweir     {
73*cdf0e10cSrcweir 		pDlgEditor->Broadcast( aHint );
74*cdf0e10cSrcweir         pDlgEditor->UpdatePropertyBrowserDelayed();
75*cdf0e10cSrcweir     }
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //----------------------------------------------------------------------------
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir void DlgEdView::MakeVisible( const Rectangle& rRect, Window& rWin )
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	// visible area
83*cdf0e10cSrcweir 	MapMode aMap( rWin.GetMapMode() );
84*cdf0e10cSrcweir 	Point aOrg( aMap.GetOrigin() );
85*cdf0e10cSrcweir 	Size aVisSize( rWin.GetOutputSize() );
86*cdf0e10cSrcweir     Rectangle RectTmp( Point(-aOrg.X(),-aOrg.Y()), aVisSize );
87*cdf0e10cSrcweir 	Rectangle aVisRect( RectTmp );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	// check, if rectangle is inside visible area
90*cdf0e10cSrcweir 	if ( !aVisRect.IsInside( rRect ) )
91*cdf0e10cSrcweir 	{
92*cdf0e10cSrcweir 		// calculate scroll distance; the rectangle must be inside the visible area
93*cdf0e10cSrcweir 		sal_Int32 nScrollX = 0, nScrollY = 0;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 		sal_Int32 nVisLeft   = aVisRect.Left();
96*cdf0e10cSrcweir 		sal_Int32 nVisRight  = aVisRect.Right();
97*cdf0e10cSrcweir 		sal_Int32 nVisTop    = aVisRect.Top();
98*cdf0e10cSrcweir 		sal_Int32 nVisBottom = aVisRect.Bottom();
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 		sal_Int32 nDeltaX = pDlgEditor->GetHScroll()->GetLineSize();
101*cdf0e10cSrcweir 		sal_Int32 nDeltaY = pDlgEditor->GetVScroll()->GetLineSize();
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 		while ( rRect.Right() > nVisRight + nScrollX )
104*cdf0e10cSrcweir 			nScrollX += nDeltaX;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 		while ( rRect.Left() < nVisLeft + nScrollX )
107*cdf0e10cSrcweir 			nScrollX -= nDeltaX;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 		while ( rRect.Bottom() > nVisBottom + nScrollY )
110*cdf0e10cSrcweir 			nScrollY += nDeltaY;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 		while ( rRect.Top() < nVisTop + nScrollY )
113*cdf0e10cSrcweir 			nScrollY -= nDeltaY;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 		// don't scroll beyond the page size
116*cdf0e10cSrcweir 		Size aPageSize = pDlgEditor->GetPage()->GetSize();
117*cdf0e10cSrcweir 		sal_Int32 nPageWidth  = aPageSize.Width();
118*cdf0e10cSrcweir 		sal_Int32 nPageHeight = aPageSize.Height();
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 		if ( nVisRight + nScrollX > nPageWidth )
121*cdf0e10cSrcweir 			nScrollX = nPageWidth - nVisRight;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 		if ( nVisLeft + nScrollX < 0 )
124*cdf0e10cSrcweir 			nScrollX = -nVisLeft;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 		if ( nVisBottom + nScrollY > nPageHeight )
127*cdf0e10cSrcweir 			nScrollY = nPageHeight - nVisBottom;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 		if ( nVisTop + nScrollY < 0 )
130*cdf0e10cSrcweir 			nScrollY = -nVisTop;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 		// scroll window
133*cdf0e10cSrcweir 		rWin.Update();
134*cdf0e10cSrcweir 		rWin.Scroll( -nScrollX, -nScrollY );
135*cdf0e10cSrcweir 		aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
136*cdf0e10cSrcweir 		rWin.SetMapMode( aMap );
137*cdf0e10cSrcweir 		rWin.Update();
138*cdf0e10cSrcweir 		rWin.Invalidate();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 		// update scroll bars
141*cdf0e10cSrcweir 		if ( pDlgEditor )
142*cdf0e10cSrcweir 			pDlgEditor->UpdateScrollBars();
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 		DlgEdHint aHint( DLGED_HINT_WINDOWSCROLLED );
145*cdf0e10cSrcweir 		if ( pDlgEditor )
146*cdf0e10cSrcweir 			pDlgEditor->Broadcast( aHint );
147*cdf0e10cSrcweir 	}
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir //----------------------------------------------------------------------------
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir SdrObject* impLocalHitCorrection(SdrObject* pRetval, const Point& rPnt, sal_uInt16 nTol)
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     DlgEdObj* pDlgEdObj = dynamic_cast< DlgEdObj* >(pRetval);
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     if(pDlgEdObj)
157*cdf0e10cSrcweir     {
158*cdf0e10cSrcweir         bool bExcludeInner(false);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir         if(0 != dynamic_cast< DlgEdForm* >(pRetval))
161*cdf0e10cSrcweir         {
162*cdf0e10cSrcweir             // from DlgEdForm::CheckHit; exclude inner for DlgEdForm
163*cdf0e10cSrcweir             bExcludeInner = true;
164*cdf0e10cSrcweir         }
165*cdf0e10cSrcweir         else if(pDlgEdObj->supportsService("com.sun.star.awt.UnoControlGroupBoxModel"))
166*cdf0e10cSrcweir         {
167*cdf0e10cSrcweir             // from DlgEdObj::CheckHit; exclude inner for group shapes
168*cdf0e10cSrcweir             bExcludeInner = true;
169*cdf0e10cSrcweir         }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir         if(bExcludeInner)
172*cdf0e10cSrcweir         {
173*cdf0e10cSrcweir             // use direct model data; it's a DlgEdObj, so GetLastBoundRect()
174*cdf0e10cSrcweir             // will access aOutRect directly
175*cdf0e10cSrcweir             const Rectangle aOuterRectangle(pDlgEdObj->GetLastBoundRect());
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	        if(!aOuterRectangle.IsEmpty()
178*cdf0e10cSrcweir 		        && RECT_EMPTY != aOuterRectangle.Right()
179*cdf0e10cSrcweir 		        && RECT_EMPTY != aOuterRectangle.Bottom())
180*cdf0e10cSrcweir 	        {
181*cdf0e10cSrcweir                 basegfx::B2DRange aOuterRange(
182*cdf0e10cSrcweir                     aOuterRectangle.Left(), aOuterRectangle.Top(),
183*cdf0e10cSrcweir                     aOuterRectangle.Right(), aOuterRectangle.Bottom());
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir                 if(nTol)
186*cdf0e10cSrcweir                 {
187*cdf0e10cSrcweir                     aOuterRange.grow(-1.0 * nTol);
188*cdf0e10cSrcweir                 }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir                 if(aOuterRange.isInside(basegfx::B2DPoint(rPnt.X(), rPnt.Y())))
191*cdf0e10cSrcweir                 {
192*cdf0e10cSrcweir                     pRetval = 0;
193*cdf0e10cSrcweir                 }
194*cdf0e10cSrcweir             }
195*cdf0e10cSrcweir         }
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     return pRetval;
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir SdrObject* DlgEdView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nTol, SdrObject* pObj, SdrPageView* pPV, sal_uLong nOptions, const SetOfByte* pMVisLay) const
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     // call parent
204*cdf0e10cSrcweir     SdrObject* pRetval = SdrView::CheckSingleSdrObjectHit(rPnt, nTol, pObj, pPV, nOptions, pMVisLay);
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     if(pRetval)
207*cdf0e10cSrcweir     {
208*cdf0e10cSrcweir         // check hitted object locally
209*cdf0e10cSrcweir         pRetval = impLocalHitCorrection(pRetval, rPnt, nTol);
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     return pRetval;
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir //----------------------------------------------------------------------------
216*cdf0e10cSrcweir // eof
217