1*5900e8ecSAndrew Rist /**************************************************************
2*5900e8ecSAndrew Rist  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <vcl/svapp.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <ipwin.hxx>
31cdf0e10cSrcweir #include <hatchwindow.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /************************************************************************/
34cdf0e10cSrcweir /*************************************************************************
35cdf0e10cSrcweir |*    SvResizeHelper::SvResizeHelper()
36cdf0e10cSrcweir |*
37cdf0e10cSrcweir |*    Beschreibung
38cdf0e10cSrcweir *************************************************************************/
SvResizeHelper()39cdf0e10cSrcweir SvResizeHelper::SvResizeHelper()
40cdf0e10cSrcweir 	: aBorder( 5, 5 )
41cdf0e10cSrcweir 	, nGrab( -1 )
42cdf0e10cSrcweir 	, bResizeable( sal_True )
43cdf0e10cSrcweir {
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
46cdf0e10cSrcweir /*************************************************************************
47cdf0e10cSrcweir |*    SvResizeHelper::FillHandleRects()
48cdf0e10cSrcweir |*
49cdf0e10cSrcweir |*    Beschreibung: Die acht Handles zum vergroessern
50cdf0e10cSrcweir *************************************************************************/
FillHandleRectsPixel(Rectangle aRects[8]) const51cdf0e10cSrcweir void SvResizeHelper::FillHandleRectsPixel( Rectangle aRects[ 8 ] ) const
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	// nur wegen EMPTY_RECT
54cdf0e10cSrcweir 	Point aBottomRight = aOuter.BottomRight();
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	// Links Oben
57cdf0e10cSrcweir 	aRects[ 0 ] = Rectangle( aOuter.TopLeft(), aBorder );
58cdf0e10cSrcweir 	// Oben Mitte
59cdf0e10cSrcweir 	aRects[ 1 ] = Rectangle( Point( aOuter.Center().X() - aBorder.Width() / 2,
60cdf0e10cSrcweir 									aOuter.Top() ),
61cdf0e10cSrcweir 							aBorder );
62cdf0e10cSrcweir 	// Oben Rechts
63cdf0e10cSrcweir 	aRects[ 2 ] = Rectangle( Point( aBottomRight.X() - aBorder.Width() +1,
64cdf0e10cSrcweir 									aOuter.Top() ),
65cdf0e10cSrcweir 							aBorder );
66cdf0e10cSrcweir 	// Mitte Rechts
67cdf0e10cSrcweir 	aRects[ 3 ] = Rectangle( Point( aBottomRight.X() - aBorder.Width() +1,
68cdf0e10cSrcweir 									aOuter.Center().Y() - aBorder.Height() / 2 ),
69cdf0e10cSrcweir 							aBorder );
70cdf0e10cSrcweir 	// Unten Rechts
71cdf0e10cSrcweir 	aRects[ 4 ] = Rectangle( Point( aBottomRight.X() - aBorder.Width() +1,
72cdf0e10cSrcweir 									aBottomRight.Y() - aBorder.Height() +1 ),
73cdf0e10cSrcweir 							aBorder );
74cdf0e10cSrcweir 	// Mitte Unten
75cdf0e10cSrcweir 	aRects[ 5 ] = Rectangle( Point( aOuter.Center().X() - aBorder.Width() / 2,
76cdf0e10cSrcweir 									aBottomRight.Y() - aBorder.Height() +1),
77cdf0e10cSrcweir 							aBorder );
78cdf0e10cSrcweir 	// Links Unten
79cdf0e10cSrcweir 	aRects[ 6 ] = Rectangle( Point( aOuter.Left(),
80cdf0e10cSrcweir 									aBottomRight.Y() - aBorder.Height() +1),
81cdf0e10cSrcweir 							aBorder );
82cdf0e10cSrcweir 	// Mitte Links
83cdf0e10cSrcweir 	aRects[ 7 ] = Rectangle( Point( aOuter.Left(),
84cdf0e10cSrcweir 									aOuter.Center().Y() - aBorder.Height() / 2 ),
85cdf0e10cSrcweir 							aBorder );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir /*************************************************************************
89cdf0e10cSrcweir |*    SvResizeHelper::FillMoveRectsPixel()
90cdf0e10cSrcweir |*
91cdf0e10cSrcweir |*    Beschreibung: Die vier Kanten werden berechnet
92cdf0e10cSrcweir *************************************************************************/
FillMoveRectsPixel(Rectangle aRects[4]) const93cdf0e10cSrcweir void SvResizeHelper::FillMoveRectsPixel( Rectangle aRects[ 4 ] ) const
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	// Oben
96cdf0e10cSrcweir 	aRects[ 0 ] = aOuter;
97cdf0e10cSrcweir 	aRects[ 0 ].Bottom() = aRects[ 0 ].Top() + aBorder.Height() -1;
98cdf0e10cSrcweir 	// Rechts
99cdf0e10cSrcweir 	aRects[ 1 ] = aOuter;
100cdf0e10cSrcweir 	aRects[ 1 ].Left() = aRects[ 1 ].Right() - aBorder.Width() -1;
101cdf0e10cSrcweir 	//Unten
102cdf0e10cSrcweir 	aRects[ 2 ] = aOuter;
103cdf0e10cSrcweir 	aRects[ 2 ].Top() = aRects[ 2 ].Bottom() - aBorder.Height() -1;
104cdf0e10cSrcweir 	//Links
105cdf0e10cSrcweir 	aRects[ 3 ] = aOuter;
106cdf0e10cSrcweir 	aRects[ 3 ].Right() = aRects[ 3 ].Left() + aBorder.Width() -1;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir /*************************************************************************
110cdf0e10cSrcweir |*    SvResizeHelper::Draw()
111cdf0e10cSrcweir |*
112cdf0e10cSrcweir |*    Beschreibung
113cdf0e10cSrcweir *************************************************************************/
Draw(OutputDevice * pDev)114cdf0e10cSrcweir void SvResizeHelper::Draw( OutputDevice * pDev )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	pDev->Push();
117cdf0e10cSrcweir 	pDev->SetMapMode( MapMode() );
118cdf0e10cSrcweir 	Color aColBlack;
119cdf0e10cSrcweir 	Color aFillColor( COL_LIGHTGRAY );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	pDev->SetFillColor( aFillColor );
122cdf0e10cSrcweir 	pDev->SetLineColor();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	Rectangle   aMoveRects[ 4 ];
125cdf0e10cSrcweir 	FillMoveRectsPixel( aMoveRects );
126cdf0e10cSrcweir 	sal_uInt16 i;
127cdf0e10cSrcweir 	for( i = 0; i < 4; i++ )
128cdf0e10cSrcweir 		pDev->DrawRect( aMoveRects[ i ] );
129cdf0e10cSrcweir 	if( bResizeable )
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		// Handles malen
132cdf0e10cSrcweir 		pDev->SetFillColor( aColBlack );
133cdf0e10cSrcweir 		Rectangle   aRects[ 8 ];
134cdf0e10cSrcweir 		FillHandleRectsPixel( aRects );
135cdf0e10cSrcweir 		for( i = 0; i < 8; i++ )
136cdf0e10cSrcweir 			pDev->DrawRect( aRects[ i ] );
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 	pDev->Pop();
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir /*************************************************************************
142cdf0e10cSrcweir |*    SvResizeHelper::InvalidateBorder()
143cdf0e10cSrcweir |*
144cdf0e10cSrcweir |*    Beschreibung
145cdf0e10cSrcweir *************************************************************************/
InvalidateBorder(Window * pWin)146cdf0e10cSrcweir void SvResizeHelper::InvalidateBorder( Window * pWin )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	Rectangle   aMoveRects[ 4 ];
149cdf0e10cSrcweir 	FillMoveRectsPixel( aMoveRects );
150cdf0e10cSrcweir 	for( sal_uInt16 i = 0; i < 4; i++ )
151cdf0e10cSrcweir 		pWin->Invalidate( aMoveRects[ i ] );
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir /*************************************************************************
155cdf0e10cSrcweir |*    SvResizeHelper::SelectBegin()
156cdf0e10cSrcweir |*
157cdf0e10cSrcweir |*    Beschreibung
158cdf0e10cSrcweir *************************************************************************/
SelectBegin(Window * pWin,const Point & rPos)159cdf0e10cSrcweir sal_Bool SvResizeHelper::SelectBegin( Window * pWin, const Point & rPos )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	if( -1 == nGrab )
162cdf0e10cSrcweir 	{
163cdf0e10cSrcweir 		nGrab = SelectMove( pWin, rPos );
164cdf0e10cSrcweir 		if( -1 != nGrab )
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir 			aSelPos = rPos; // Start-Position merken
167cdf0e10cSrcweir 			pWin->CaptureMouse();
168cdf0e10cSrcweir 			return sal_True;
169cdf0e10cSrcweir 		}
170cdf0e10cSrcweir 	}
171cdf0e10cSrcweir 	return sal_False;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir /*************************************************************************
175cdf0e10cSrcweir |*    SvResizeHelper::SelectMove()
176cdf0e10cSrcweir |*
177cdf0e10cSrcweir |*    Beschreibung
178cdf0e10cSrcweir *************************************************************************/
SelectMove(Window * pWin,const Point & rPos)179cdf0e10cSrcweir short SvResizeHelper::SelectMove( Window * pWin, const Point & rPos )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	if( -1 == nGrab )
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 		if( bResizeable )
184cdf0e10cSrcweir 		{
185cdf0e10cSrcweir 			Rectangle aRects[ 8 ];
186cdf0e10cSrcweir 			FillHandleRectsPixel( aRects );
187cdf0e10cSrcweir 			for( sal_uInt16 i = 0; i < 8; i++ )
188cdf0e10cSrcweir 				if( aRects[ i ].IsInside( rPos ) )
189cdf0e10cSrcweir 					return i;
190cdf0e10cSrcweir 		}
191cdf0e10cSrcweir 		// Move-Rect ueberlappen Handles
192cdf0e10cSrcweir 		Rectangle aMoveRects[ 4 ];
193cdf0e10cSrcweir 		FillMoveRectsPixel( aMoveRects );
194cdf0e10cSrcweir 		for( sal_uInt16 i = 0; i < 4; i++ )
195cdf0e10cSrcweir 			if( aMoveRects[ i ].IsInside( rPos ) )
196cdf0e10cSrcweir 				return 8;
197cdf0e10cSrcweir 	}
198cdf0e10cSrcweir 	else
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir 		Rectangle aRect( GetTrackRectPixel( rPos ) );
201cdf0e10cSrcweir 		aRect.SetSize( pWin->PixelToLogic( aRect.GetSize() ) );
202cdf0e10cSrcweir 		aRect.SetPos( pWin->PixelToLogic( aRect.TopLeft() ) );
203cdf0e10cSrcweir 		pWin->ShowTracking( aRect );
204cdf0e10cSrcweir 	}
205cdf0e10cSrcweir 	return nGrab;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
GetTrackPosPixel(const Rectangle & rRect) const208cdf0e10cSrcweir Point SvResizeHelper::GetTrackPosPixel( const Rectangle & rRect ) const
209cdf0e10cSrcweir {
210cdf0e10cSrcweir 	// wie das Rechteck zurueckkommt ist egal, es zaehlt welches Handle
211cdf0e10cSrcweir 	// initial angefasst wurde
212cdf0e10cSrcweir 	Point aPos;
213cdf0e10cSrcweir 	Rectangle aRect( rRect );
214cdf0e10cSrcweir 	aRect.Justify();
215cdf0e10cSrcweir 	// nur wegen EMPTY_RECT
216cdf0e10cSrcweir 	Point aBR = aOuter.BottomRight();
217cdf0e10cSrcweir 	Point aTR = aOuter.TopRight();
218cdf0e10cSrcweir 	Point aBL = aOuter.BottomLeft();
219cdf0e10cSrcweir 	switch( nGrab )
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir 		case 0:
222cdf0e10cSrcweir 			aPos = aRect.TopLeft() - aOuter.TopLeft();
223cdf0e10cSrcweir 			break;
224cdf0e10cSrcweir 		case 1:
225cdf0e10cSrcweir 			aPos.Y() =  aRect.Top() - aOuter.Top();
226cdf0e10cSrcweir 			break;
227cdf0e10cSrcweir 		case 2:
228cdf0e10cSrcweir 			aPos =  aRect.TopRight() - aTR;
229cdf0e10cSrcweir 			break;
230cdf0e10cSrcweir 		case 3:
231cdf0e10cSrcweir 			aPos.X() = aRect.Right() - aTR.X();
232cdf0e10cSrcweir 			break;
233cdf0e10cSrcweir 		case 4:
234cdf0e10cSrcweir 			aPos =  aRect.BottomRight() - aBR;
235cdf0e10cSrcweir 			break;
236cdf0e10cSrcweir 		case 5:
237cdf0e10cSrcweir 			aPos.Y() = aRect.Bottom() - aBR.Y();
238cdf0e10cSrcweir 			break;
239cdf0e10cSrcweir 		case 6:
240cdf0e10cSrcweir 			aPos =  aRect.BottomLeft() - aBL;
241cdf0e10cSrcweir 			break;
242cdf0e10cSrcweir 		case 7:
243cdf0e10cSrcweir 			aPos.X() = aRect.Left() - aOuter.Left();
244cdf0e10cSrcweir 			break;
245cdf0e10cSrcweir 		case 8:
246cdf0e10cSrcweir 			aPos = aRect.TopLeft() - aOuter.TopLeft();
247cdf0e10cSrcweir 			break;
248cdf0e10cSrcweir 	}
249cdf0e10cSrcweir 	return aPos += aSelPos;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir /*************************************************************************
253cdf0e10cSrcweir |*    SvResizeHelper::GetTrackRectPixel()
254cdf0e10cSrcweir |*
255cdf0e10cSrcweir |*    Beschreibung
256cdf0e10cSrcweir *************************************************************************/
GetTrackRectPixel(const Point & rTrackPos) const257cdf0e10cSrcweir Rectangle SvResizeHelper::GetTrackRectPixel( const Point & rTrackPos ) const
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	Rectangle aTrackRect;
260cdf0e10cSrcweir 	if( -1 != nGrab )
261cdf0e10cSrcweir 	{
262cdf0e10cSrcweir 		Point aDiff = rTrackPos - aSelPos;
263cdf0e10cSrcweir 		aTrackRect = aOuter;
264cdf0e10cSrcweir 		Point aBR = aOuter.BottomRight();
265cdf0e10cSrcweir 		switch( nGrab )
266cdf0e10cSrcweir 		{
267cdf0e10cSrcweir 			case 0:
268cdf0e10cSrcweir 				aTrackRect.Top() += aDiff.Y();
269cdf0e10cSrcweir 				aTrackRect.Left() += aDiff.X();
270cdf0e10cSrcweir 				break;
271cdf0e10cSrcweir 			case 1:
272cdf0e10cSrcweir 				aTrackRect.Top() += aDiff.Y();
273cdf0e10cSrcweir 				break;
274cdf0e10cSrcweir 			case 2:
275cdf0e10cSrcweir 				aTrackRect.Top() += aDiff.Y();
276cdf0e10cSrcweir 				aTrackRect.Right() = aBR.X() + aDiff.X();
277cdf0e10cSrcweir 				break;
278cdf0e10cSrcweir 			case 3:
279cdf0e10cSrcweir 				aTrackRect.Right() = aBR.X() + aDiff.X();
280cdf0e10cSrcweir 				break;
281cdf0e10cSrcweir 			case 4:
282cdf0e10cSrcweir 				aTrackRect.Bottom() = aBR.Y() + aDiff.Y();
283cdf0e10cSrcweir 				aTrackRect.Right() = aBR.X() + aDiff.X();
284cdf0e10cSrcweir 				break;
285cdf0e10cSrcweir 			case 5:
286cdf0e10cSrcweir 				aTrackRect.Bottom() = aBR.Y() + aDiff.Y();
287cdf0e10cSrcweir 				break;
288cdf0e10cSrcweir 			case 6:
289cdf0e10cSrcweir 				aTrackRect.Bottom() = aBR.Y() + aDiff.Y();
290cdf0e10cSrcweir 				aTrackRect.Left() += aDiff.X();
291cdf0e10cSrcweir 				break;
292cdf0e10cSrcweir 			case 7:
293cdf0e10cSrcweir 				aTrackRect.Left() += aDiff.X();
294cdf0e10cSrcweir 				break;
295cdf0e10cSrcweir 			case 8:
296cdf0e10cSrcweir                 if( Application::GetSettings().GetLayoutRTL() )
297cdf0e10cSrcweir                     aDiff.X() = -aDiff.X(); // workaround for move in RTL mode
298cdf0e10cSrcweir 				aTrackRect.SetPos( aTrackRect.TopLeft() + aDiff );
299cdf0e10cSrcweir 				break;
300cdf0e10cSrcweir /*
301cdf0e10cSrcweir 			case 0:
302cdf0e10cSrcweir 				aTrackRect = Rectangle( rTrackPos, aOuter.BottomRight() );
303cdf0e10cSrcweir 				break;
304cdf0e10cSrcweir 			case 1:
305cdf0e10cSrcweir 				aTrackRect = Rectangle( Point( aOuter.Left(), rTrackPos.Y() ),
306cdf0e10cSrcweir 										 aOuter.BottomRight() );
307cdf0e10cSrcweir 				break;
308cdf0e10cSrcweir 			case 2:
309cdf0e10cSrcweir 				aTrackRect = Rectangle( rTrackPos, aOuter.BottomLeft() );
310cdf0e10cSrcweir 				break;
311cdf0e10cSrcweir 			case 3:
312cdf0e10cSrcweir 				aTrackRect = Rectangle( Point( rTrackPos.X(), aOuter.Top() ),
313cdf0e10cSrcweir 										 aOuter.BottomLeft() );
314cdf0e10cSrcweir 				break;
315cdf0e10cSrcweir 			case 4:
316cdf0e10cSrcweir 				aTrackRect = Rectangle( rTrackPos, aOuter.TopLeft() );
317cdf0e10cSrcweir 				break;
318cdf0e10cSrcweir 			case 5:
319cdf0e10cSrcweir 				aTrackRect = Rectangle( aOuter.TopLeft(),
320cdf0e10cSrcweir 									 Point( aOuter.Right(), rTrackPos.Y() ) );
321cdf0e10cSrcweir 				break;
322cdf0e10cSrcweir 			case 6:
323cdf0e10cSrcweir 				aTrackRect = Rectangle( aOuter.TopRight(), rTrackPos );
324cdf0e10cSrcweir 				break;
325cdf0e10cSrcweir 			case 7:
326cdf0e10cSrcweir 				aTrackRect = Rectangle( Point( rTrackPos.X(), aOuter.Top() ),
327cdf0e10cSrcweir 										 aOuter.BottomRight() );
328cdf0e10cSrcweir 				break;
329cdf0e10cSrcweir 			case 8:
330cdf0e10cSrcweir 				aTrackRect = Rectangle( aOuter.TopLeft() + rTrackPos - aSelPos,
331cdf0e10cSrcweir 										aOuter.GetSize() );
332cdf0e10cSrcweir 				break;
333cdf0e10cSrcweir */
334cdf0e10cSrcweir 		}
335cdf0e10cSrcweir 	}
336cdf0e10cSrcweir 	return aTrackRect;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
ValidateRect(Rectangle & rValidate) const339cdf0e10cSrcweir void SvResizeHelper::ValidateRect( Rectangle & rValidate ) const
340cdf0e10cSrcweir {
341cdf0e10cSrcweir 	switch( nGrab )
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		case 0:
344cdf0e10cSrcweir 			if( rValidate.Top() > rValidate.Bottom() )
345cdf0e10cSrcweir 			{
346cdf0e10cSrcweir 				rValidate.Top() = rValidate.Bottom();
347cdf0e10cSrcweir 				rValidate.Bottom() = RECT_EMPTY;
348cdf0e10cSrcweir 			}
349cdf0e10cSrcweir 			if( rValidate.Left() > rValidate.Right() )
350cdf0e10cSrcweir 			{
351cdf0e10cSrcweir 				rValidate.Left() = rValidate.Right();
352cdf0e10cSrcweir 				rValidate.Right() = RECT_EMPTY;
353cdf0e10cSrcweir 			}
354cdf0e10cSrcweir 			break;
355cdf0e10cSrcweir 		case 1:
356cdf0e10cSrcweir 			if( rValidate.Top() > rValidate.Bottom() )
357cdf0e10cSrcweir 			{
358cdf0e10cSrcweir 				rValidate.Top() = rValidate.Bottom();
359cdf0e10cSrcweir 				rValidate.Bottom() = RECT_EMPTY;
360cdf0e10cSrcweir 			}
361cdf0e10cSrcweir 			break;
362cdf0e10cSrcweir 		case 2:
363cdf0e10cSrcweir 			if( rValidate.Top() > rValidate.Bottom() )
364cdf0e10cSrcweir 			{
365cdf0e10cSrcweir 				rValidate.Top() = rValidate.Bottom();
366cdf0e10cSrcweir 				rValidate.Bottom() = RECT_EMPTY;
367cdf0e10cSrcweir 			}
368cdf0e10cSrcweir 			if( rValidate.Left() > rValidate.Right() )
369cdf0e10cSrcweir 				rValidate.Right() = RECT_EMPTY;
370cdf0e10cSrcweir 			break;
371cdf0e10cSrcweir 		case 3:
372cdf0e10cSrcweir 			if( rValidate.Left() > rValidate.Right() )
373cdf0e10cSrcweir 				rValidate.Right() = RECT_EMPTY;
374cdf0e10cSrcweir 			break;
375cdf0e10cSrcweir 		case 4:
376cdf0e10cSrcweir 			if( rValidate.Top() > rValidate.Bottom() )
377cdf0e10cSrcweir 				rValidate.Bottom() = RECT_EMPTY;
378cdf0e10cSrcweir 			if( rValidate.Left() > rValidate.Right() )
379cdf0e10cSrcweir 				rValidate.Right() = RECT_EMPTY;
380cdf0e10cSrcweir 			break;
381cdf0e10cSrcweir 		case 5:
382cdf0e10cSrcweir 			if( rValidate.Top() > rValidate.Bottom() )
383cdf0e10cSrcweir 				rValidate.Bottom() = RECT_EMPTY;
384cdf0e10cSrcweir 			break;
385cdf0e10cSrcweir 		case 6:
386cdf0e10cSrcweir 			if( rValidate.Top() > rValidate.Bottom() )
387cdf0e10cSrcweir 				rValidate.Bottom() = RECT_EMPTY;
388cdf0e10cSrcweir 			if( rValidate.Left() > rValidate.Right() )
389cdf0e10cSrcweir 			{
390cdf0e10cSrcweir 				rValidate.Left() = rValidate.Right();
391cdf0e10cSrcweir 				rValidate.Right() = RECT_EMPTY;
392cdf0e10cSrcweir 			}
393cdf0e10cSrcweir 			break;
394cdf0e10cSrcweir 		case 7:
395cdf0e10cSrcweir 			if( rValidate.Left() > rValidate.Right() )
396cdf0e10cSrcweir 			{
397cdf0e10cSrcweir 				rValidate.Left() = rValidate.Right();
398cdf0e10cSrcweir 				rValidate.Right() = RECT_EMPTY;
399cdf0e10cSrcweir 			}
400cdf0e10cSrcweir 			break;
401cdf0e10cSrcweir 	}
402cdf0e10cSrcweir 	if( rValidate.Right() == RECT_EMPTY )
403cdf0e10cSrcweir 		rValidate.Right() = rValidate.Left();
404cdf0e10cSrcweir 	if( rValidate.Bottom() == RECT_EMPTY )
405cdf0e10cSrcweir 		rValidate.Bottom() = rValidate.Top();
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 	// Mindestgr"osse 5 x 5
408cdf0e10cSrcweir 	if( rValidate.Left() + 5 > rValidate.Right() )
409cdf0e10cSrcweir 		rValidate.Right() = rValidate.Left() +5;
410cdf0e10cSrcweir 	if( rValidate.Top() + 5 > rValidate.Bottom() )
411cdf0e10cSrcweir 		rValidate.Bottom() = rValidate.Top() +5;
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir /*************************************************************************
415cdf0e10cSrcweir |*    SvResizeHelper::SelectRelease()
416cdf0e10cSrcweir |*
417cdf0e10cSrcweir |*    Beschreibung
418cdf0e10cSrcweir *************************************************************************/
SelectRelease(Window * pWin,const Point & rPos,Rectangle & rOutPosSize)419cdf0e10cSrcweir sal_Bool SvResizeHelper::SelectRelease( Window * pWin, const Point & rPos,
420cdf0e10cSrcweir 									Rectangle & rOutPosSize )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir 	if( -1 != nGrab )
423cdf0e10cSrcweir 	{
424cdf0e10cSrcweir 		rOutPosSize = GetTrackRectPixel( rPos );
425cdf0e10cSrcweir 		rOutPosSize.Justify();
426cdf0e10cSrcweir 		nGrab = -1;
427cdf0e10cSrcweir 		pWin->ReleaseMouse();
428cdf0e10cSrcweir 		pWin->HideTracking();
429cdf0e10cSrcweir 		return sal_True;
430cdf0e10cSrcweir 	}
431cdf0e10cSrcweir 	return sal_False;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir /*************************************************************************
435cdf0e10cSrcweir |*    SvResizeHelper::Release()
436cdf0e10cSrcweir |*
437cdf0e10cSrcweir |*    Beschreibung
438cdf0e10cSrcweir *************************************************************************/
Release(Window * pWin)439cdf0e10cSrcweir void SvResizeHelper::Release( Window * pWin )
440cdf0e10cSrcweir {
441cdf0e10cSrcweir 	if( nGrab != -1 )
442cdf0e10cSrcweir 	{
443cdf0e10cSrcweir 		pWin->ReleaseMouse();
444cdf0e10cSrcweir 		pWin->HideTracking();
445cdf0e10cSrcweir 		nGrab = -1;
446cdf0e10cSrcweir 	}
447cdf0e10cSrcweir }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir /*************************************************************************
450cdf0e10cSrcweir |*    SvResizeWindow::SvResizeWindow()
451cdf0e10cSrcweir |*
452cdf0e10cSrcweir |*    Beschreibung
453cdf0e10cSrcweir *************************************************************************/
SvResizeWindow(Window * pParent,VCLXHatchWindow * pWrapper)454cdf0e10cSrcweir SvResizeWindow::SvResizeWindow
455cdf0e10cSrcweir (
456cdf0e10cSrcweir 	Window * pParent,
457cdf0e10cSrcweir 	VCLXHatchWindow* pWrapper
458cdf0e10cSrcweir )
459cdf0e10cSrcweir 	: Window( pParent, WB_CLIPCHILDREN )
460cdf0e10cSrcweir 	, m_nMoveGrab( -1 )
461cdf0e10cSrcweir     , m_bActive( sal_False )
462cdf0e10cSrcweir 	, m_pWrapper( pWrapper )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir 	OSL_ENSURE( pParent != NULL && pWrapper != NULL, "Wrong initialization of hatch window!\n" );
465cdf0e10cSrcweir 	SetBackground();
466cdf0e10cSrcweir 	SetAccessibleRole( ::com::sun::star::accessibility::AccessibleRole::EMBEDDED_OBJECT );
467cdf0e10cSrcweir 	m_aResizer.SetOuterRectPixel( Rectangle( Point(), GetOutputSizePixel() ) );
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir /*************************************************************************
471cdf0e10cSrcweir |*    SvResizeWindow::SetHatchBorderPixel()
472cdf0e10cSrcweir |*
473cdf0e10cSrcweir |*    Beschreibung
474cdf0e10cSrcweir *************************************************************************/
SetHatchBorderPixel(const Size & rSize)475cdf0e10cSrcweir void SvResizeWindow::SetHatchBorderPixel( const Size & rSize )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir 	 m_aResizer.SetBorderPixel( rSize );
478cdf0e10cSrcweir }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir /*************************************************************************
481cdf0e10cSrcweir |*    SvResizeWindow::SelectMouse()
482cdf0e10cSrcweir |*
483cdf0e10cSrcweir |*    Beschreibung
484cdf0e10cSrcweir *************************************************************************/
SelectMouse(const Point & rPos)485cdf0e10cSrcweir void SvResizeWindow::SelectMouse( const Point & rPos )
486cdf0e10cSrcweir {
487cdf0e10cSrcweir 	short nGrab = m_aResizer.SelectMove( this, rPos );
488cdf0e10cSrcweir 	if( nGrab >= 4 )
489cdf0e10cSrcweir 		nGrab -= 4;
490cdf0e10cSrcweir 	if( m_nMoveGrab != nGrab )
491cdf0e10cSrcweir 	{ // Pointer hat sich geaendert
492cdf0e10cSrcweir 		if( -1 == nGrab )
493cdf0e10cSrcweir 			SetPointer( m_aOldPointer );
494cdf0e10cSrcweir 		else
495cdf0e10cSrcweir 		{
496cdf0e10cSrcweir 			PointerStyle aStyle = POINTER_MOVE;
497cdf0e10cSrcweir 			if( nGrab == 3 )
498cdf0e10cSrcweir 				aStyle = POINTER_ESIZE;
499cdf0e10cSrcweir 			else if( nGrab == 2 )
500cdf0e10cSrcweir 				aStyle = POINTER_NESIZE;
501cdf0e10cSrcweir 			else if( nGrab == 1 )
502cdf0e10cSrcweir 				aStyle = POINTER_SSIZE;
503cdf0e10cSrcweir 			else if( nGrab == 0 )
504cdf0e10cSrcweir 				aStyle = POINTER_SESIZE;
505cdf0e10cSrcweir 			if( m_nMoveGrab == -1 ) // das erste mal
506cdf0e10cSrcweir 			{
507cdf0e10cSrcweir 				m_aOldPointer = GetPointer();
508cdf0e10cSrcweir 				SetPointer( Pointer( aStyle ) );
509cdf0e10cSrcweir 			}
510cdf0e10cSrcweir 			else
511cdf0e10cSrcweir 				SetPointer( Pointer( aStyle ) );
512cdf0e10cSrcweir 		}
513cdf0e10cSrcweir 		m_nMoveGrab = nGrab;
514cdf0e10cSrcweir 	}
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir /*************************************************************************
518cdf0e10cSrcweir |*    SvResizeWindow::MouseButtonDown()
519cdf0e10cSrcweir |*
520cdf0e10cSrcweir |*    Beschreibung
521cdf0e10cSrcweir *************************************************************************/
MouseButtonDown(const MouseEvent & rEvt)522cdf0e10cSrcweir void SvResizeWindow::MouseButtonDown( const MouseEvent & rEvt )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir 	if( m_aResizer.SelectBegin( this, rEvt.GetPosPixel() ) )
525cdf0e10cSrcweir 		SelectMouse( rEvt.GetPosPixel() );
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir /*************************************************************************
529cdf0e10cSrcweir |*    SvResizeWindow::MouseMove()
530cdf0e10cSrcweir |*
531cdf0e10cSrcweir |*    Beschreibung
532cdf0e10cSrcweir *************************************************************************/
MouseMove(const MouseEvent & rEvt)533cdf0e10cSrcweir void SvResizeWindow::MouseMove( const MouseEvent & rEvt )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir 	if( m_aResizer.GetGrab() == -1 )
536cdf0e10cSrcweir 		SelectMouse( rEvt.GetPosPixel() );
537cdf0e10cSrcweir 	else
538cdf0e10cSrcweir 	{
539cdf0e10cSrcweir 		Rectangle aRect( m_aResizer.GetTrackRectPixel( rEvt.GetPosPixel() ) );
540cdf0e10cSrcweir 		Point aDiff = GetPosPixel();
541cdf0e10cSrcweir 		aRect.SetPos( aRect.TopLeft() + aDiff );
542cdf0e10cSrcweir 		m_aResizer.ValidateRect( aRect );
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 		m_pWrapper->QueryObjAreaPixel( aRect );
545cdf0e10cSrcweir 		aRect.SetPos( aRect.TopLeft() - aDiff );
546cdf0e10cSrcweir 		Point aPos = m_aResizer.GetTrackPosPixel( aRect );
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 		SelectMouse( aPos );
549cdf0e10cSrcweir 	}
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir /*************************************************************************
553cdf0e10cSrcweir |*    SvResizeWindow::MouseButtonUp()
554cdf0e10cSrcweir |*
555cdf0e10cSrcweir |*    Beschreibung
556cdf0e10cSrcweir *************************************************************************/
MouseButtonUp(const MouseEvent & rEvt)557cdf0e10cSrcweir void SvResizeWindow::MouseButtonUp( const MouseEvent & rEvt )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir 	if( m_aResizer.GetGrab() != -1 )
560cdf0e10cSrcweir 	{
561cdf0e10cSrcweir 		Rectangle aRect( m_aResizer.GetTrackRectPixel( rEvt.GetPosPixel() ) );
562cdf0e10cSrcweir 		Point aDiff = GetPosPixel();
563cdf0e10cSrcweir 		aRect.SetPos( aRect.TopLeft() + aDiff );
564cdf0e10cSrcweir 		// aRect -= GetAllBorderPixel();
565cdf0e10cSrcweir 		m_aResizer.ValidateRect( aRect );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 		m_pWrapper->QueryObjAreaPixel( aRect );
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 		Rectangle aOutRect;
570cdf0e10cSrcweir 		if( m_aResizer.SelectRelease( this, rEvt.GetPosPixel(), aOutRect ) )
571cdf0e10cSrcweir 		{
572cdf0e10cSrcweir 			m_nMoveGrab = -1;
573cdf0e10cSrcweir 			SetPointer( m_aOldPointer );
574cdf0e10cSrcweir 			m_pWrapper->RequestObjAreaPixel( aRect );
575cdf0e10cSrcweir 		}
576cdf0e10cSrcweir 	}
577cdf0e10cSrcweir }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir /*************************************************************************
580cdf0e10cSrcweir |*    SvResizeWindow::KeyEvent()
581cdf0e10cSrcweir |*
582cdf0e10cSrcweir |*    Beschreibung
583cdf0e10cSrcweir *************************************************************************/
KeyInput(const KeyEvent & rEvt)584cdf0e10cSrcweir void SvResizeWindow::KeyInput( const KeyEvent & rEvt )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir 	if( rEvt.GetKeyCode().GetCode() == KEY_ESCAPE )
587cdf0e10cSrcweir 	{
588cdf0e10cSrcweir 		m_aResizer.Release( this );
589cdf0e10cSrcweir 		m_pWrapper->InplaceDeactivate();
590cdf0e10cSrcweir 	}
591cdf0e10cSrcweir }
592cdf0e10cSrcweir 
593cdf0e10cSrcweir /*************************************************************************
594cdf0e10cSrcweir |*    SvResizeWindow::Resize()
595cdf0e10cSrcweir |*
596cdf0e10cSrcweir |*    Beschreibung
597cdf0e10cSrcweir *************************************************************************/
Resize()598cdf0e10cSrcweir void SvResizeWindow::Resize()
599cdf0e10cSrcweir {
600cdf0e10cSrcweir 	m_aResizer.InvalidateBorder( this ); // alten Bereich
601cdf0e10cSrcweir 	m_aResizer.SetOuterRectPixel( Rectangle( Point(), GetOutputSizePixel() ) );
602cdf0e10cSrcweir 	m_aResizer.InvalidateBorder( this ); // neuen Bereich
603cdf0e10cSrcweir }
604cdf0e10cSrcweir 
605cdf0e10cSrcweir /*************************************************************************
606cdf0e10cSrcweir |*    SvResizeWindow::Paint()
607cdf0e10cSrcweir |*
608cdf0e10cSrcweir |*    Beschreibung
609cdf0e10cSrcweir *************************************************************************/
Paint(const Rectangle &)610cdf0e10cSrcweir void SvResizeWindow::Paint( const Rectangle & /*rRect*/ )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir 	m_aResizer.Draw( this );
613cdf0e10cSrcweir }
614cdf0e10cSrcweir 
PreNotify(NotifyEvent & rEvt)615cdf0e10cSrcweir long SvResizeWindow::PreNotify( NotifyEvent& rEvt )
616cdf0e10cSrcweir {
617cdf0e10cSrcweir     if ( rEvt.GetType() == EVENT_GETFOCUS && !m_bActive )
618cdf0e10cSrcweir     {
619cdf0e10cSrcweir         m_bActive = sal_True;
620cdf0e10cSrcweir         m_pWrapper->Activated();
621cdf0e10cSrcweir     }
622cdf0e10cSrcweir 
623cdf0e10cSrcweir     return Window::PreNotify(rEvt);
624cdf0e10cSrcweir }
625cdf0e10cSrcweir 
Notify(NotifyEvent & rEvt)626cdf0e10cSrcweir long SvResizeWindow::Notify( NotifyEvent& rEvt )
627cdf0e10cSrcweir {
628cdf0e10cSrcweir     if ( rEvt.GetType() == EVENT_LOSEFOCUS && m_bActive )
629cdf0e10cSrcweir     {
630cdf0e10cSrcweir         sal_Bool bHasFocus = HasChildPathFocus(sal_True);
631cdf0e10cSrcweir         if ( !bHasFocus )
632cdf0e10cSrcweir         {
633cdf0e10cSrcweir             m_bActive = sal_False;
634cdf0e10cSrcweir             m_pWrapper->Deactivated();
635cdf0e10cSrcweir         }
636cdf0e10cSrcweir     }
637cdf0e10cSrcweir 
638cdf0e10cSrcweir     return Window::Notify(rEvt);
639cdf0e10cSrcweir }
640cdf0e10cSrcweir 
641