1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ipwin.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <com/sun/star/accessibility/AccessibleRole.hpp>
35 #include <vcl/svapp.hxx>
38 #include <hatchwindow.hxx>
40 /************************************************************************/
41 /*************************************************************************
42 |* SvResizeHelper::SvResizeHelper()
45 *************************************************************************/
46 SvResizeHelper::SvResizeHelper()
53 /*************************************************************************
54 |* SvResizeHelper::FillHandleRects()
56 |* Beschreibung: Die acht Handles zum vergroessern
57 *************************************************************************/
58 void SvResizeHelper::FillHandleRectsPixel( Rectangle aRects
[ 8 ] ) const
60 // nur wegen EMPTY_RECT
61 Point aBottomRight
= aOuter
.BottomRight();
64 aRects
[ 0 ] = Rectangle( aOuter
.TopLeft(), aBorder
);
66 aRects
[ 1 ] = Rectangle( Point( aOuter
.Center().X() - aBorder
.Width() / 2,
70 aRects
[ 2 ] = Rectangle( Point( aBottomRight
.X() - aBorder
.Width() +1,
74 aRects
[ 3 ] = Rectangle( Point( aBottomRight
.X() - aBorder
.Width() +1,
75 aOuter
.Center().Y() - aBorder
.Height() / 2 ),
78 aRects
[ 4 ] = Rectangle( Point( aBottomRight
.X() - aBorder
.Width() +1,
79 aBottomRight
.Y() - aBorder
.Height() +1 ),
82 aRects
[ 5 ] = Rectangle( Point( aOuter
.Center().X() - aBorder
.Width() / 2,
83 aBottomRight
.Y() - aBorder
.Height() +1),
86 aRects
[ 6 ] = Rectangle( Point( aOuter
.Left(),
87 aBottomRight
.Y() - aBorder
.Height() +1),
90 aRects
[ 7 ] = Rectangle( Point( aOuter
.Left(),
91 aOuter
.Center().Y() - aBorder
.Height() / 2 ),
95 /*************************************************************************
96 |* SvResizeHelper::FillMoveRectsPixel()
98 |* Beschreibung: Die vier Kanten werden berechnet
99 *************************************************************************/
100 void SvResizeHelper::FillMoveRectsPixel( Rectangle aRects
[ 4 ] ) const
103 aRects
[ 0 ] = aOuter
;
104 aRects
[ 0 ].Bottom() = aRects
[ 0 ].Top() + aBorder
.Height() -1;
106 aRects
[ 1 ] = aOuter
;
107 aRects
[ 1 ].Left() = aRects
[ 1 ].Right() - aBorder
.Width() -1;
109 aRects
[ 2 ] = aOuter
;
110 aRects
[ 2 ].Top() = aRects
[ 2 ].Bottom() - aBorder
.Height() -1;
112 aRects
[ 3 ] = aOuter
;
113 aRects
[ 3 ].Right() = aRects
[ 3 ].Left() + aBorder
.Width() -1;
116 /*************************************************************************
117 |* SvResizeHelper::Draw()
120 *************************************************************************/
121 void SvResizeHelper::Draw( OutputDevice
* pDev
)
124 pDev
->SetMapMode( MapMode() );
126 Color
aFillColor( COL_LIGHTGRAY
);
128 pDev
->SetFillColor( aFillColor
);
129 pDev
->SetLineColor();
131 Rectangle aMoveRects
[ 4 ];
132 FillMoveRectsPixel( aMoveRects
);
134 for( i
= 0; i
< 4; i
++ )
135 pDev
->DrawRect( aMoveRects
[ i
] );
139 pDev
->SetFillColor( aColBlack
);
140 Rectangle aRects
[ 8 ];
141 FillHandleRectsPixel( aRects
);
142 for( i
= 0; i
< 8; i
++ )
143 pDev
->DrawRect( aRects
[ i
] );
148 /*************************************************************************
149 |* SvResizeHelper::InvalidateBorder()
152 *************************************************************************/
153 void SvResizeHelper::InvalidateBorder( Window
* pWin
)
155 Rectangle aMoveRects
[ 4 ];
156 FillMoveRectsPixel( aMoveRects
);
157 for( USHORT i
= 0; i
< 4; i
++ )
158 pWin
->Invalidate( aMoveRects
[ i
] );
161 /*************************************************************************
162 |* SvResizeHelper::SelectBegin()
165 *************************************************************************/
166 BOOL
SvResizeHelper::SelectBegin( Window
* pWin
, const Point
& rPos
)
170 nGrab
= SelectMove( pWin
, rPos
);
173 aSelPos
= rPos
; // Start-Position merken
174 pWin
->CaptureMouse();
181 /*************************************************************************
182 |* SvResizeHelper::SelectMove()
185 *************************************************************************/
186 short SvResizeHelper::SelectMove( Window
* pWin
, const Point
& rPos
)
192 Rectangle aRects
[ 8 ];
193 FillHandleRectsPixel( aRects
);
194 for( USHORT i
= 0; i
< 8; i
++ )
195 if( aRects
[ i
].IsInside( rPos
) )
198 // Move-Rect ueberlappen Handles
199 Rectangle aMoveRects
[ 4 ];
200 FillMoveRectsPixel( aMoveRects
);
201 for( USHORT i
= 0; i
< 4; i
++ )
202 if( aMoveRects
[ i
].IsInside( rPos
) )
207 Rectangle
aRect( GetTrackRectPixel( rPos
) );
208 aRect
.SetSize( pWin
->PixelToLogic( aRect
.GetSize() ) );
209 aRect
.SetPos( pWin
->PixelToLogic( aRect
.TopLeft() ) );
210 pWin
->ShowTracking( aRect
);
215 Point
SvResizeHelper::GetTrackPosPixel( const Rectangle
& rRect
) const
217 // wie das Rechteck zurueckkommt ist egal, es zaehlt welches Handle
218 // initial angefasst wurde
220 Rectangle
aRect( rRect
);
222 // nur wegen EMPTY_RECT
223 Point aBR
= aOuter
.BottomRight();
224 Point aTR
= aOuter
.TopRight();
225 Point aBL
= aOuter
.BottomLeft();
229 aPos
= aRect
.TopLeft() - aOuter
.TopLeft();
232 aPos
.Y() = aRect
.Top() - aOuter
.Top();
235 aPos
= aRect
.TopRight() - aTR
;
238 aPos
.X() = aRect
.Right() - aTR
.X();
241 aPos
= aRect
.BottomRight() - aBR
;
244 aPos
.Y() = aRect
.Bottom() - aBR
.Y();
247 aPos
= aRect
.BottomLeft() - aBL
;
250 aPos
.X() = aRect
.Left() - aOuter
.Left();
253 aPos
= aRect
.TopLeft() - aOuter
.TopLeft();
256 return aPos
+= aSelPos
;
259 /*************************************************************************
260 |* SvResizeHelper::GetTrackRectPixel()
263 *************************************************************************/
264 Rectangle
SvResizeHelper::GetTrackRectPixel( const Point
& rTrackPos
) const
266 Rectangle aTrackRect
;
269 Point aDiff
= rTrackPos
- aSelPos
;
271 Point aBR
= aOuter
.BottomRight();
275 aTrackRect
.Top() += aDiff
.Y();
276 aTrackRect
.Left() += aDiff
.X();
279 aTrackRect
.Top() += aDiff
.Y();
282 aTrackRect
.Top() += aDiff
.Y();
283 aTrackRect
.Right() = aBR
.X() + aDiff
.X();
286 aTrackRect
.Right() = aBR
.X() + aDiff
.X();
289 aTrackRect
.Bottom() = aBR
.Y() + aDiff
.Y();
290 aTrackRect
.Right() = aBR
.X() + aDiff
.X();
293 aTrackRect
.Bottom() = aBR
.Y() + aDiff
.Y();
296 aTrackRect
.Bottom() = aBR
.Y() + aDiff
.Y();
297 aTrackRect
.Left() += aDiff
.X();
300 aTrackRect
.Left() += aDiff
.X();
303 if( Application::GetSettings().GetLayoutRTL() )
304 aDiff
.X() = -aDiff
.X(); // workaround for move in RTL mode
305 aTrackRect
.SetPos( aTrackRect
.TopLeft() + aDiff
);
309 aTrackRect = Rectangle( rTrackPos, aOuter.BottomRight() );
312 aTrackRect = Rectangle( Point( aOuter.Left(), rTrackPos.Y() ),
313 aOuter.BottomRight() );
316 aTrackRect = Rectangle( rTrackPos, aOuter.BottomLeft() );
319 aTrackRect = Rectangle( Point( rTrackPos.X(), aOuter.Top() ),
320 aOuter.BottomLeft() );
323 aTrackRect = Rectangle( rTrackPos, aOuter.TopLeft() );
326 aTrackRect = Rectangle( aOuter.TopLeft(),
327 Point( aOuter.Right(), rTrackPos.Y() ) );
330 aTrackRect = Rectangle( aOuter.TopRight(), rTrackPos );
333 aTrackRect = Rectangle( Point( rTrackPos.X(), aOuter.Top() ),
334 aOuter.BottomRight() );
337 aTrackRect = Rectangle( aOuter.TopLeft() + rTrackPos - aSelPos,
346 void SvResizeHelper::ValidateRect( Rectangle
& rValidate
) const
351 if( rValidate
.Top() > rValidate
.Bottom() )
353 rValidate
.Top() = rValidate
.Bottom();
354 rValidate
.Bottom() = RECT_EMPTY
;
356 if( rValidate
.Left() > rValidate
.Right() )
358 rValidate
.Left() = rValidate
.Right();
359 rValidate
.Right() = RECT_EMPTY
;
363 if( rValidate
.Top() > rValidate
.Bottom() )
365 rValidate
.Top() = rValidate
.Bottom();
366 rValidate
.Bottom() = RECT_EMPTY
;
370 if( rValidate
.Top() > rValidate
.Bottom() )
372 rValidate
.Top() = rValidate
.Bottom();
373 rValidate
.Bottom() = RECT_EMPTY
;
375 if( rValidate
.Left() > rValidate
.Right() )
376 rValidate
.Right() = RECT_EMPTY
;
379 if( rValidate
.Left() > rValidate
.Right() )
380 rValidate
.Right() = RECT_EMPTY
;
383 if( rValidate
.Top() > rValidate
.Bottom() )
384 rValidate
.Bottom() = RECT_EMPTY
;
385 if( rValidate
.Left() > rValidate
.Right() )
386 rValidate
.Right() = RECT_EMPTY
;
389 if( rValidate
.Top() > rValidate
.Bottom() )
390 rValidate
.Bottom() = RECT_EMPTY
;
393 if( rValidate
.Top() > rValidate
.Bottom() )
394 rValidate
.Bottom() = RECT_EMPTY
;
395 if( rValidate
.Left() > rValidate
.Right() )
397 rValidate
.Left() = rValidate
.Right();
398 rValidate
.Right() = RECT_EMPTY
;
402 if( rValidate
.Left() > rValidate
.Right() )
404 rValidate
.Left() = rValidate
.Right();
405 rValidate
.Right() = RECT_EMPTY
;
409 if( rValidate
.Right() == RECT_EMPTY
)
410 rValidate
.Right() = rValidate
.Left();
411 if( rValidate
.Bottom() == RECT_EMPTY
)
412 rValidate
.Bottom() = rValidate
.Top();
414 // Mindestgr"osse 5 x 5
415 if( rValidate
.Left() + 5 > rValidate
.Right() )
416 rValidate
.Right() = rValidate
.Left() +5;
417 if( rValidate
.Top() + 5 > rValidate
.Bottom() )
418 rValidate
.Bottom() = rValidate
.Top() +5;
421 /*************************************************************************
422 |* SvResizeHelper::SelectRelease()
425 *************************************************************************/
426 BOOL
SvResizeHelper::SelectRelease( Window
* pWin
, const Point
& rPos
,
427 Rectangle
& rOutPosSize
)
431 rOutPosSize
= GetTrackRectPixel( rPos
);
432 rOutPosSize
.Justify();
434 pWin
->ReleaseMouse();
435 pWin
->HideTracking();
441 /*************************************************************************
442 |* SvResizeHelper::Release()
445 *************************************************************************/
446 void SvResizeHelper::Release( Window
* pWin
)
450 pWin
->ReleaseMouse();
451 pWin
->HideTracking();
456 /*************************************************************************
457 |* SvResizeWindow::SvResizeWindow()
460 *************************************************************************/
461 SvResizeWindow::SvResizeWindow
464 VCLXHatchWindow
* pWrapper
466 : Window( pParent
, WB_CLIPCHILDREN
)
468 , m_bActive( sal_False
)
469 , m_pWrapper( pWrapper
)
471 OSL_ENSURE( pParent
!= NULL
&& pWrapper
!= NULL
, "Wrong initialization of hatch window!\n" );
473 SetAccessibleRole( ::com::sun::star::accessibility::AccessibleRole::EMBEDDED_OBJECT
);
474 m_aResizer
.SetOuterRectPixel( Rectangle( Point(), GetOutputSizePixel() ) );
477 /*************************************************************************
478 |* SvResizeWindow::SetHatchBorderPixel()
481 *************************************************************************/
482 void SvResizeWindow::SetHatchBorderPixel( const Size
& rSize
)
484 m_aResizer
.SetBorderPixel( rSize
);
487 /*************************************************************************
488 |* SvResizeWindow::SelectMouse()
491 *************************************************************************/
492 void SvResizeWindow::SelectMouse( const Point
& rPos
)
494 short nGrab
= m_aResizer
.SelectMove( this, rPos
);
497 if( m_nMoveGrab
!= nGrab
)
498 { // Pointer hat sich geaendert
500 SetPointer( m_aOldPointer
);
503 PointerStyle aStyle
= POINTER_MOVE
;
505 aStyle
= POINTER_ESIZE
;
506 else if( nGrab
== 2 )
507 aStyle
= POINTER_NESIZE
;
508 else if( nGrab
== 1 )
509 aStyle
= POINTER_SSIZE
;
510 else if( nGrab
== 0 )
511 aStyle
= POINTER_SESIZE
;
512 if( m_nMoveGrab
== -1 ) // das erste mal
514 m_aOldPointer
= GetPointer();
515 SetPointer( Pointer( aStyle
) );
518 SetPointer( Pointer( aStyle
) );
524 /*************************************************************************
525 |* SvResizeWindow::MouseButtonDown()
528 *************************************************************************/
529 void SvResizeWindow::MouseButtonDown( const MouseEvent
& rEvt
)
531 if( m_aResizer
.SelectBegin( this, rEvt
.GetPosPixel() ) )
532 SelectMouse( rEvt
.GetPosPixel() );
535 /*************************************************************************
536 |* SvResizeWindow::MouseMove()
539 *************************************************************************/
540 void SvResizeWindow::MouseMove( const MouseEvent
& rEvt
)
542 if( m_aResizer
.GetGrab() == -1 )
543 SelectMouse( rEvt
.GetPosPixel() );
546 Rectangle
aRect( m_aResizer
.GetTrackRectPixel( rEvt
.GetPosPixel() ) );
547 Point aDiff
= GetPosPixel();
548 aRect
.SetPos( aRect
.TopLeft() + aDiff
);
549 m_aResizer
.ValidateRect( aRect
);
551 m_pWrapper
->QueryObjAreaPixel( aRect
);
552 aRect
.SetPos( aRect
.TopLeft() - aDiff
);
553 Point aPos
= m_aResizer
.GetTrackPosPixel( aRect
);
559 /*************************************************************************
560 |* SvResizeWindow::MouseButtonUp()
563 *************************************************************************/
564 void SvResizeWindow::MouseButtonUp( const MouseEvent
& rEvt
)
566 if( m_aResizer
.GetGrab() != -1 )
568 Rectangle
aRect( m_aResizer
.GetTrackRectPixel( rEvt
.GetPosPixel() ) );
569 Point aDiff
= GetPosPixel();
570 aRect
.SetPos( aRect
.TopLeft() + aDiff
);
571 // aRect -= GetAllBorderPixel();
572 m_aResizer
.ValidateRect( aRect
);
574 m_pWrapper
->QueryObjAreaPixel( aRect
);
577 if( m_aResizer
.SelectRelease( this, rEvt
.GetPosPixel(), aOutRect
) )
580 SetPointer( m_aOldPointer
);
581 m_pWrapper
->RequestObjAreaPixel( aRect
);
586 /*************************************************************************
587 |* SvResizeWindow::KeyEvent()
590 *************************************************************************/
591 void SvResizeWindow::KeyInput( const KeyEvent
& rEvt
)
593 if( rEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
)
595 m_aResizer
.Release( this );
596 m_pWrapper
->InplaceDeactivate();
600 /*************************************************************************
601 |* SvResizeWindow::Resize()
604 *************************************************************************/
605 void SvResizeWindow::Resize()
607 m_aResizer
.InvalidateBorder( this ); // alten Bereich
608 m_aResizer
.SetOuterRectPixel( Rectangle( Point(), GetOutputSizePixel() ) );
609 m_aResizer
.InvalidateBorder( this ); // neuen Bereich
612 /*************************************************************************
613 |* SvResizeWindow::Paint()
616 *************************************************************************/
617 void SvResizeWindow::Paint( const Rectangle
& /*rRect*/ )
619 m_aResizer
.Draw( this );
622 long SvResizeWindow::PreNotify( NotifyEvent
& rEvt
)
624 if ( rEvt
.GetType() == EVENT_GETFOCUS
&& !m_bActive
)
626 m_bActive
= sal_True
;
627 m_pWrapper
->Activated();
630 return Window::PreNotify(rEvt
);
633 long SvResizeWindow::Notify( NotifyEvent
& rEvt
)
635 if ( rEvt
.GetType() == EVENT_LOSEFOCUS
&& m_bActive
)
637 BOOL bHasFocus
= HasChildPathFocus(TRUE
);
640 m_bActive
= sal_False
;
641 m_pWrapper
->Deactivated();
645 return Window::Notify(rEvt
);