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