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: cursor.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_vcl.hxx"
33 #include <vcl/svapp.hxx>
34 #include <vcl/timer.hxx>
35 #include <vcl/settings.hxx>
36 #include <vcl/window.hxx>
37 #include <vcl/window.h>
38 #include <tools/poly.hxx>
39 #include <vcl/cursor.hxx>
42 // =======================================================================
46 AutoTimer maTimer
; // Timer
47 Point maPixPos
; // Pixel-Position
48 Point maPixRotOff
; // Pixel-Offset-Position
49 Size maPixSize
; // Pixel-Size
50 long mnPixSlant
; // Pixel-Slant
51 short mnOrientation
; // Pixel-Orientation
52 unsigned char mnDirection
; // indicates writing direction
53 USHORT mnStyle
; // Cursor-Style
54 BOOL mbCurVisible
; // Ist Cursor aktuell sichtbar
55 Window
* mpWindow
; // Zugeordnetes Windows
58 // =======================================================================
60 static void ImplCursorInvert( ImplCursorData
* pData
)
62 Window
* pWindow
= pData
->mpWindow
;
63 BOOL bMapMode
= pWindow
->IsMapModeEnabled();
64 pWindow
->EnableMapMode( FALSE
);
66 if ( pData
->mnStyle
& CURSOR_SHADOW
)
67 nInvertStyle
= INVERT_50
;
71 Rectangle
aRect( pData
->maPixPos
, pData
->maPixSize
);
72 if ( pData
->mnDirection
|| pData
->mnOrientation
|| pData
->mnPixSlant
)
74 Polygon
aPoly( aRect
);
75 if( aPoly
.GetSize() == 5 )
77 aPoly
[1].X() += 1; // include the right border
79 if ( pData
->mnPixSlant
)
81 Point aPoint
= aPoly
.GetPoint( 0 );
82 aPoint
.X() += pData
->mnPixSlant
;
83 aPoly
.SetPoint( aPoint
, 0 );
84 aPoly
.SetPoint( aPoint
, 4 );
85 aPoint
= aPoly
.GetPoint( 1 );
86 aPoint
.X() += pData
->mnPixSlant
;
87 aPoly
.SetPoint( aPoint
, 1 );
90 // apply direction flag after slant to use the correct shape
91 if ( pData
->mnDirection
)
94 int delta
= 3*aRect
.getWidth()+1;
95 if( pData
->mnDirection
== CURSOR_DIRECTION_LTR
)
98 pAry
[0] = aPoly
.GetPoint( 0 );
99 pAry
[1] = aPoly
.GetPoint( 1 );
101 pAry
[2].X() += delta
;
103 pAry
[3].Y() += delta
;
104 pAry
[4] = aPoly
.GetPoint( 2 );
105 pAry
[5] = aPoly
.GetPoint( 3 );
106 pAry
[6] = aPoly
.GetPoint( 4 );
108 else if( pData
->mnDirection
== CURSOR_DIRECTION_RTL
)
111 pAry
[0] = aPoly
.GetPoint( 0 );
112 pAry
[1] = aPoly
.GetPoint( 1 );
113 pAry
[2] = aPoly
.GetPoint( 2 );
114 pAry
[3] = aPoly
.GetPoint( 3 );
116 pAry
[4].Y() += delta
;
118 pAry
[5].X() -= delta
;
119 pAry
[6] = aPoly
.GetPoint( 4 );
121 aPoly
= Polygon( 7, pAry
);
124 if ( pData
->mnOrientation
)
125 aPoly
.Rotate( pData
->maPixRotOff
, pData
->mnOrientation
);
126 pWindow
->Invert( aPoly
, nInvertStyle
);
130 pWindow
->Invert( aRect
, nInvertStyle
);
131 pWindow
->EnableMapMode( bMapMode
);
134 // -----------------------------------------------------------------------
136 void Cursor::ImplDraw()
138 if ( mpData
&& mpData
->mpWindow
&& !mpData
->mbCurVisible
)
140 Window
* pWindow
= mpData
->mpWindow
;
141 mpData
->maPixPos
= pWindow
->LogicToPixel( maPos
);
142 mpData
->maPixSize
= pWindow
->LogicToPixel( maSize
);
143 mpData
->mnPixSlant
= pWindow
->LogicToPixel( Size( mnSlant
, 0 ) ).Width();
144 mpData
->mnOrientation
= mnOrientation
;
145 mpData
->mnDirection
= mnDirection
;
146 long nOffsetY
= pWindow
->LogicToPixel( Size( 0, mnOffsetY
) ).Height();
148 // Position um den Offset korrigieren
149 mpData
->maPixPos
.Y() -= nOffsetY
;
150 mpData
->maPixRotOff
= mpData
->maPixPos
;
151 mpData
->maPixRotOff
.Y() += nOffsetY
;
153 // Wenn groesse 0 ist, nehmen wir die breite, die in den
154 // Settings eingestellt ist
155 if ( !mpData
->maPixSize
.Width() )
156 mpData
->maPixSize
.Width() = pWindow
->GetSettings().GetStyleSettings().GetCursorSize();
158 // Ausgabeflaeche berechnen und ausgeben
159 ImplCursorInvert( mpData
);
160 mpData
->mbCurVisible
= TRUE
;
164 // -----------------------------------------------------------------------
166 void Cursor::ImplRestore()
168 if ( mpData
&& mpData
->mbCurVisible
)
170 ImplCursorInvert( mpData
);
171 mpData
->mbCurVisible
= FALSE
;
175 // -----------------------------------------------------------------------
177 void Cursor::ImplShow( BOOL bDrawDirect
)
186 // Gibt es ein aktives Fenster und ist der Cursor in dieses Fenster
187 // selektiert, dann zeige den Cursor an
188 pWindow
= Application::GetFocusWindow();
189 if ( !pWindow
|| (pWindow
->mpWindowImpl
->mpCursor
!= this) || pWindow
->mpWindowImpl
->mbInPaint
190 || !pWindow
->mpWindowImpl
->mpFrameData
->mbHasFocus
)
198 mpData
= new ImplCursorData
;
199 mpData
->mbCurVisible
= FALSE
;
200 mpData
->maTimer
.SetTimeoutHdl( LINK( this, Cursor
, ImplTimerHdl
) );
203 mpData
->mpWindow
= pWindow
;
204 mpData
->mnStyle
= mnStyle
;
210 mpData
->maTimer
.SetTimeout( pWindow
->GetSettings().GetStyleSettings().GetCursorBlinkTime() );
211 if ( mpData
->maTimer
.GetTimeout() != STYLE_CURSOR_NOBLINKTIME
)
212 mpData
->maTimer
.Start();
213 else if ( !mpData
->mbCurVisible
)
220 // -----------------------------------------------------------------------
222 void Cursor::ImplHide()
224 if ( mpData
&& mpData
->mpWindow
)
226 if ( mpData
->mbCurVisible
)
229 mpData
->maTimer
.Stop();
230 mpData
->mpWindow
= NULL
;
234 // -----------------------------------------------------------------------
236 void Cursor::ImplNew()
238 if ( mbVisible
&& mpData
&& mpData
->mpWindow
)
240 if ( mpData
->mbCurVisible
)
246 if ( mpData
->maTimer
.GetTimeout() != STYLE_CURSOR_NOBLINKTIME
)
247 mpData
->maTimer
.Start();
252 // -----------------------------------------------------------------------
254 IMPL_LINK( Cursor
, ImplTimerHdl
, AutoTimer
*, EMPTYARG
)
256 if ( mpData
->mbCurVisible
)
263 // =======================================================================
277 // -----------------------------------------------------------------------
279 Cursor::Cursor( const Cursor
& rCursor
) :
280 maSize( rCursor
.maSize
),
281 maPos( rCursor
.maPos
)
285 mnSlant
= rCursor
.mnSlant
;
286 mnOrientation
= rCursor
.mnOrientation
;
287 mnDirection
= rCursor
.mnDirection
;
289 mbVisible
= rCursor
.mbVisible
;
292 // -----------------------------------------------------------------------
298 if ( mpData
->mbCurVisible
)
305 // -----------------------------------------------------------------------
307 void Cursor::SetStyle( USHORT nStyle
)
309 if ( mnStyle
!= nStyle
)
316 // -----------------------------------------------------------------------
327 // -----------------------------------------------------------------------
338 // -----------------------------------------------------------------------
340 void Cursor::SetWindow( Window
* pWindow
)
342 if ( mpWindow
!= pWindow
)
349 // -----------------------------------------------------------------------
351 void Cursor::SetPos( const Point
& rPoint
)
353 if ( maPos
!= rPoint
)
360 // -----------------------------------------------------------------------
362 void Cursor::SetOffsetY( long nNewOffsetY
)
364 if ( mnOffsetY
!= nNewOffsetY
)
366 mnOffsetY
= nNewOffsetY
;
371 // -----------------------------------------------------------------------
373 void Cursor::SetSize( const Size
& rSize
)
375 if ( maSize
!= rSize
)
382 // -----------------------------------------------------------------------
384 void Cursor::SetWidth( long nNewWidth
)
386 if ( maSize
.Width() != nNewWidth
)
388 maSize
.Width() = nNewWidth
;
393 // -----------------------------------------------------------------------
395 void Cursor::SetHeight( long nNewHeight
)
397 if ( maSize
.Height() != nNewHeight
)
399 maSize
.Height() = nNewHeight
;
404 // -----------------------------------------------------------------------
406 void Cursor::SetSlant( long nNewSlant
)
408 if ( mnSlant
!= nNewSlant
)
415 // -----------------------------------------------------------------------
417 void Cursor::SetOrientation( short nNewOrientation
)
419 if ( mnOrientation
!= nNewOrientation
)
421 mnOrientation
= nNewOrientation
;
426 // -----------------------------------------------------------------------
428 void Cursor::SetDirection( unsigned char nNewDirection
)
430 if ( mnDirection
!= nNewDirection
)
432 mnDirection
= nNewDirection
;
437 // -----------------------------------------------------------------------
439 Cursor
& Cursor::operator=( const Cursor
& rCursor
)
441 maPos
= rCursor
.maPos
;
442 maSize
= rCursor
.maSize
;
443 mnSlant
= rCursor
.mnSlant
;
444 mnOrientation
= rCursor
.mnOrientation
;
445 mnDirection
= rCursor
.mnDirection
;
446 mbVisible
= rCursor
.mbVisible
;
452 // -----------------------------------------------------------------------
454 BOOL
Cursor::operator==( const Cursor
& rCursor
) const
456 if ( (maPos
== rCursor
.maPos
) &&
457 (maSize
== rCursor
.maSize
) &&
458 (mnSlant
== rCursor
.mnSlant
) &&
459 (mnOrientation
== rCursor
.mnOrientation
) &&
460 (mnDirection
== rCursor
.mnDirection
) &&
461 (mbVisible
== rCursor
.mbVisible
) )