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