Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <vcl/svapp.hxx>
31 : : #include <vcl/timer.hxx>
32 : : #include <vcl/settings.hxx>
33 : : #include <vcl/window.hxx>
34 : : #include <vcl/cursor.hxx>
35 : :
36 : : #include <window.h>
37 : :
38 : : #include <tools/poly.hxx>
39 : :
40 : :
41 : : // =======================================================================
42 : :
43 : 2199 : struct ImplCursorData
44 : : {
45 : : AutoTimer maTimer; // Timer
46 : : Point maPixPos; // Pixel-Position
47 : : Point maPixRotOff; // Pixel-Offset-Position
48 : : Size maPixSize; // Pixel-Size
49 : : long mnPixSlant; // Pixel-Slant
50 : : short mnOrientation; // Pixel-Orientation
51 : : unsigned char mnDirection; // indicates writing direction
52 : : sal_uInt16 mnStyle; // Cursor-Style
53 : : bool mbCurVisible; // Ist Cursor aktuell sichtbar
54 : : Window* mpWindow; // Zugeordnetes Windows
55 : : };
56 : :
57 : : // =======================================================================
58 : :
59 : 69718 : static void ImplCursorInvert( ImplCursorData* pData )
60 : : {
61 : 69718 : Window* pWindow = pData->mpWindow;
62 : 69718 : bool bMapMode = pWindow->IsMapModeEnabled();
63 [ + - ]: 69718 : pWindow->EnableMapMode( false );
64 : : sal_uInt16 nInvertStyle;
65 [ - + ]: 69718 : if ( pData->mnStyle & CURSOR_SHADOW )
66 : 0 : nInvertStyle = INVERT_50;
67 : : else
68 : 69718 : nInvertStyle = 0;
69 : :
70 [ + - ]: 69718 : Rectangle aRect( pData->maPixPos, pData->maPixSize );
71 [ + - ][ + - ]: 69718 : if ( pData->mnDirection || pData->mnOrientation || pData->mnPixSlant )
[ - + ]
72 : : {
73 [ # # ]: 0 : Polygon aPoly( aRect );
74 [ # # ][ # # ]: 0 : if( aPoly.GetSize() == 5 )
75 : : {
76 [ # # ]: 0 : aPoly[1].X() += 1; // include the right border
77 [ # # ]: 0 : aPoly[2].X() += 1;
78 [ # # ]: 0 : if ( pData->mnPixSlant )
79 : : {
80 [ # # ]: 0 : Point aPoint = aPoly.GetPoint( 0 );
81 : 0 : aPoint.X() += pData->mnPixSlant;
82 [ # # ]: 0 : aPoly.SetPoint( aPoint, 0 );
83 [ # # ]: 0 : aPoly.SetPoint( aPoint, 4 );
84 [ # # ]: 0 : aPoint = aPoly.GetPoint( 1 );
85 : 0 : aPoint.X() += pData->mnPixSlant;
86 [ # # ]: 0 : aPoly.SetPoint( aPoint, 1 );
87 : : }
88 : :
89 : : // apply direction flag after slant to use the correct shape
90 [ # # ]: 0 : if ( pData->mnDirection )
91 : : {
92 [ # # ]: 0 : Point pAry[7];
93 : 0 : int delta = 3*aRect.getWidth()+1;
94 [ # # ]: 0 : if( pData->mnDirection == CURSOR_DIRECTION_LTR )
95 : : {
96 : : // left-to-right
97 [ # # ]: 0 : pAry[0] = aPoly.GetPoint( 0 );
98 [ # # ]: 0 : pAry[1] = aPoly.GetPoint( 1 );
99 : 0 : pAry[2] = pAry[1];
100 : 0 : pAry[2].X() += delta;
101 : 0 : pAry[3] = pAry[1];
102 : 0 : pAry[3].Y() += delta;
103 [ # # ]: 0 : pAry[4] = aPoly.GetPoint( 2 );
104 [ # # ]: 0 : pAry[5] = aPoly.GetPoint( 3 );
105 [ # # ]: 0 : pAry[6] = aPoly.GetPoint( 4 );
106 : : }
107 [ # # ]: 0 : else if( pData->mnDirection == CURSOR_DIRECTION_RTL )
108 : : {
109 : : // right-to-left
110 [ # # ]: 0 : pAry[0] = aPoly.GetPoint( 0 );
111 [ # # ]: 0 : pAry[1] = aPoly.GetPoint( 1 );
112 [ # # ]: 0 : pAry[2] = aPoly.GetPoint( 2 );
113 [ # # ]: 0 : pAry[3] = aPoly.GetPoint( 3 );
114 : 0 : pAry[4] = pAry[0];
115 : 0 : pAry[4].Y() += delta;
116 : 0 : pAry[5] = pAry[0];
117 : 0 : pAry[5].X() -= delta;
118 [ # # ]: 0 : pAry[6] = aPoly.GetPoint( 4 );
119 : : }
120 [ # # ][ # # ]: 0 : aPoly = Polygon( 7, pAry);
[ # # ]
121 : : }
122 : :
123 [ # # ]: 0 : if ( pData->mnOrientation )
124 [ # # ]: 0 : aPoly.Rotate( pData->maPixRotOff, pData->mnOrientation );
125 [ # # ]: 0 : pWindow->Invert( aPoly, nInvertStyle );
126 [ # # ]: 0 : }
127 : : }
128 : : else
129 [ + - ]: 69718 : pWindow->Invert( aRect, nInvertStyle );
130 [ + - ]: 69718 : pWindow->EnableMapMode( bMapMode );
131 : 69718 : }
132 : :
133 : : // -----------------------------------------------------------------------
134 : :
135 : 34859 : void Cursor::ImplDraw()
136 : : {
137 [ + - ][ + - ]: 34859 : if ( mpData && mpData->mpWindow && !mpData->mbCurVisible )
[ + - ]
138 : : {
139 : 34859 : Window* pWindow = mpData->mpWindow;
140 : 34859 : mpData->maPixPos = pWindow->LogicToPixel( maPos );
141 : 34859 : mpData->maPixSize = pWindow->LogicToPixel( maSize );
142 [ + - ]: 34859 : mpData->mnPixSlant = pWindow->LogicToPixel( Size( mnSlant, 0 ) ).Width();
143 : 34859 : mpData->mnOrientation = mnOrientation;
144 : 34859 : mpData->mnDirection = mnDirection;
145 [ + - ]: 34859 : long nOffsetY = pWindow->LogicToPixel( Size( 0, mnOffsetY ) ).Height();
146 : :
147 : : // Position um den Offset korrigieren
148 : 34859 : mpData->maPixPos.Y() -= nOffsetY;
149 : 34859 : mpData->maPixRotOff = mpData->maPixPos;
150 : 34859 : mpData->maPixRotOff.Y() += nOffsetY;
151 : :
152 : : // Wenn groesse 0 ist, nehmen wir die breite, die in den
153 : : // Settings eingestellt ist
154 [ + + ]: 34859 : if ( !mpData->maPixSize.Width() )
155 : 34780 : mpData->maPixSize.Width() = pWindow->GetSettings().GetStyleSettings().GetCursorSize();
156 : :
157 : : // Ausgabeflaeche berechnen und ausgeben
158 : 34859 : ImplCursorInvert( mpData );
159 : 34859 : mpData->mbCurVisible = true;
160 : : }
161 : 34859 : }
162 : :
163 : : // -----------------------------------------------------------------------
164 : :
165 : 34859 : void Cursor::ImplRestore()
166 : : {
167 [ + - ][ + - ]: 34859 : if ( mpData && mpData->mbCurVisible )
168 : : {
169 : 34859 : ImplCursorInvert( mpData );
170 : 34859 : mpData->mbCurVisible = false;
171 : : }
172 : 34859 : }
173 : :
174 : 72908 : void Cursor::ImplDoShow( bool bDrawDirect, bool bRestore )
175 : : {
176 [ + + ]: 72908 : if ( mbVisible )
177 : : {
178 : : Window* pWindow;
179 [ - + ]: 58390 : if ( mpWindow )
180 : 0 : pWindow = mpWindow;
181 : : else
182 : : {
183 : : // Gibt es ein aktives Fenster und ist der Cursor in dieses Fenster
184 : : // selektiert, dann zeige den Cursor an
185 : 58390 : pWindow = Application::GetFocusWindow();
186 [ + + ][ + + ]: 58390 : if ( !pWindow || (pWindow->mpWindowImpl->mpCursor != this) || pWindow->mpWindowImpl->mbInPaint
[ + + ][ + + ]
187 : 34878 : || !pWindow->mpWindowImpl->mpFrameData->mbHasFocus )
188 : 23611 : pWindow = NULL;
189 : : }
190 : :
191 [ + + ]: 58390 : if ( pWindow )
192 : : {
193 [ + + ]: 34779 : if ( !mpData )
194 : : {
195 [ + - ]: 1143 : mpData = new ImplCursorData;
196 : 1143 : mpData->mbCurVisible = false;
197 : 1143 : mpData->maTimer.SetTimeoutHdl( LINK( this, Cursor, ImplTimerHdl ) );
198 : : }
199 : :
200 : 34779 : mpData->mpWindow = pWindow;
201 : 34779 : mpData->mnStyle = mnStyle;
202 [ + + ][ + + ]: 34779 : if ( bDrawDirect || bRestore )
203 : 34742 : ImplDraw();
204 : :
205 [ + - ][ + + ]: 34779 : if ( !mpWindow && ! ( ! bDrawDirect && mpData->maTimer.IsActive()) )
[ + - ][ + - ]
206 : : {
207 : 34779 : mpData->maTimer.SetTimeout( pWindow->GetSettings().GetStyleSettings().GetCursorBlinkTime() );
208 [ - + ]: 34779 : if ( mpData->maTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME )
209 : 0 : mpData->maTimer.Start();
210 [ + + ]: 34779 : else if ( !mpData->mbCurVisible )
211 : 37 : ImplDraw();
212 : : }
213 : : }
214 : : }
215 : 72908 : }
216 : :
217 : 69355 : bool Cursor::ImplDoHide( bool bSuspend )
218 : : {
219 : 69355 : bool bWasCurVisible = false;
220 [ + + ][ + + ]: 69355 : if ( mpData && mpData->mpWindow )
221 : : {
222 : 38137 : bWasCurVisible = mpData->mbCurVisible;
223 [ + + ]: 38137 : if ( mpData->mbCurVisible )
224 : 34779 : ImplRestore();
225 : :
226 [ + + ]: 38137 : if ( !bSuspend )
227 : : {
228 : 32250 : mpData->maTimer.Stop();
229 : 32250 : mpData->mpWindow = NULL;
230 : : }
231 : : }
232 : 69355 : return bWasCurVisible;
233 : : }
234 : :
235 : 55950 : void Cursor::ImplShow( bool bDrawDirect )
236 : : {
237 : 55950 : ImplDoShow( bDrawDirect, false );
238 : 55950 : }
239 : :
240 : 52602 : void Cursor::ImplHide()
241 : : {
242 : 52602 : ImplDoHide( false );
243 : 52602 : }
244 : :
245 : 16958 : void Cursor::ImplResume( bool bRestore )
246 : : {
247 : 16958 : ImplDoShow( false, bRestore );
248 : 16958 : }
249 : :
250 : 16753 : bool Cursor::ImplSuspend()
251 : : {
252 : 16753 : return ImplDoHide( true );
253 : : }
254 : :
255 : 87005 : void Cursor::ImplNew()
256 : : {
257 [ + + ][ + + ]: 87005 : if ( mbVisible && mpData && mpData->mpWindow )
[ + - ]
258 : : {
259 [ + - ]: 80 : if ( mpData->mbCurVisible )
260 : 80 : ImplRestore();
261 : :
262 : 80 : ImplDraw();
263 [ + - ]: 80 : if ( !mpWindow )
264 : : {
265 [ - + ]: 80 : if ( mpData->maTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME )
266 : 0 : mpData->maTimer.Start();
267 : : }
268 : : }
269 : 87005 : }
270 : :
271 : : // -----------------------------------------------------------------------
272 : :
273 : 0 : IMPL_LINK_NOARG(Cursor, ImplTimerHdl)
274 : : {
275 [ # # ]: 0 : if ( mpData->mbCurVisible )
276 : 0 : ImplRestore();
277 : : else
278 : 0 : ImplDraw();
279 : 0 : return 0;
280 : : }
281 : :
282 : : // =======================================================================
283 : :
284 : 9091 : Cursor::Cursor()
285 : : {
286 : 9091 : mpData = NULL;
287 : 9091 : mpWindow = NULL;
288 : 9091 : mnSlant = 0;
289 : 9091 : mnOffsetY = 0;
290 : 9091 : mnOrientation = 0;
291 : 9091 : mnDirection = 0;
292 : 9091 : mnStyle = 0;
293 : 9091 : mbVisible = false;
294 : 9091 : }
295 : :
296 : : // -----------------------------------------------------------------------
297 : :
298 : 0 : Cursor::Cursor( const Cursor& rCursor ) :
299 : : maSize( rCursor.maSize ),
300 : 0 : maPos( rCursor.maPos )
301 : : {
302 : 0 : mpData = NULL;
303 : 0 : mpWindow = NULL;
304 : 0 : mnSlant = rCursor.mnSlant;
305 : 0 : mnOrientation = rCursor.mnOrientation;
306 : 0 : mnDirection = rCursor.mnDirection;
307 : 0 : mnStyle = 0;
308 : 0 : mbVisible = rCursor.mbVisible;
309 : 0 : }
310 : :
311 : : // -----------------------------------------------------------------------
312 : :
313 : 8984 : Cursor::~Cursor()
314 : : {
315 [ + + ]: 8984 : if ( mpData )
316 : : {
317 [ - + ]: 1056 : if ( mpData->mbCurVisible )
318 : 0 : ImplRestore();
319 : :
320 [ + - ]: 1056 : delete mpData;
321 : : }
322 : 8984 : }
323 : :
324 : : // -----------------------------------------------------------------------
325 : :
326 : 0 : void Cursor::SetStyle( sal_uInt16 nStyle )
327 : : {
328 [ # # ]: 0 : if ( mnStyle != nStyle )
329 : : {
330 : 0 : mnStyle = nStyle;
331 : 0 : ImplNew();
332 : : }
333 : 0 : }
334 : :
335 : : // -----------------------------------------------------------------------
336 : :
337 : 46181 : void Cursor::Show()
338 : : {
339 [ + + ]: 46181 : if ( !mbVisible )
340 : : {
341 : 45743 : mbVisible = true;
342 : 45743 : ImplShow();
343 : : }
344 : 46181 : }
345 : :
346 : : // -----------------------------------------------------------------------
347 : :
348 : 45256 : void Cursor::Hide()
349 : : {
350 [ + + ]: 45256 : if ( mbVisible )
351 : : {
352 : 42359 : mbVisible = false;
353 : 42359 : ImplHide();
354 : : }
355 : 45256 : }
356 : :
357 : : // -----------------------------------------------------------------------
358 : :
359 : 0 : void Cursor::SetWindow( Window* pWindow )
360 : : {
361 [ # # ]: 0 : if ( mpWindow != pWindow )
362 : : {
363 : 0 : mpWindow = pWindow;
364 : 0 : ImplNew();
365 : : }
366 : 0 : }
367 : :
368 : : // -----------------------------------------------------------------------
369 : :
370 : 40658 : void Cursor::SetPos( const Point& rPoint )
371 : : {
372 [ + + ]: 40658 : if ( maPos != rPoint )
373 : : {
374 : 9258 : maPos = rPoint;
375 : 9258 : ImplNew();
376 : : }
377 : 40658 : }
378 : :
379 : : // -----------------------------------------------------------------------
380 : :
381 : 40652 : void Cursor::SetSize( const Size& rSize )
382 : : {
383 [ + + ]: 40652 : if ( maSize != rSize )
384 : : {
385 : 6557 : maSize = rSize;
386 : 6557 : ImplNew();
387 : : }
388 : 40652 : }
389 : :
390 : : // -----------------------------------------------------------------------
391 : :
392 : 1318 : void Cursor::SetWidth( long nNewWidth )
393 : : {
394 [ - + ]: 1318 : if ( maSize.Width() != nNewWidth )
395 : : {
396 : 0 : maSize.Width() = nNewWidth;
397 : 0 : ImplNew();
398 : : }
399 : 1318 : }
400 : :
401 : : // -----------------------------------------------------------------------
402 : :
403 : 36988 : void Cursor::SetOrientation( short nNewOrientation )
404 : : {
405 [ - + ]: 36988 : if ( mnOrientation != nNewOrientation )
406 : : {
407 : 0 : mnOrientation = nNewOrientation;
408 : 0 : ImplNew();
409 : : }
410 : 36988 : }
411 : :
412 : : // -----------------------------------------------------------------------
413 : :
414 : 36988 : void Cursor::SetDirection( unsigned char nNewDirection )
415 : : {
416 [ - + ]: 36988 : if ( mnDirection != nNewDirection )
417 : : {
418 : 0 : mnDirection = nNewDirection;
419 : 0 : ImplNew();
420 : : }
421 : 36988 : }
422 : :
423 : : // -----------------------------------------------------------------------
424 : :
425 : 0 : Cursor& Cursor::operator=( const Cursor& rCursor )
426 : : {
427 : 0 : maPos = rCursor.maPos;
428 : 0 : maSize = rCursor.maSize;
429 : 0 : mnSlant = rCursor.mnSlant;
430 : 0 : mnOrientation = rCursor.mnOrientation;
431 : 0 : mnDirection = rCursor.mnDirection;
432 : 0 : mbVisible = rCursor.mbVisible;
433 : 0 : ImplNew();
434 : :
435 : 0 : return *this;
436 : : }
437 : :
438 : : // -----------------------------------------------------------------------
439 : :
440 : 0 : bool Cursor::operator==( const Cursor& rCursor ) const
441 : : {
442 : : return
443 : 0 : ((maPos == rCursor.maPos) &&
444 : 0 : (maSize == rCursor.maSize) &&
445 : : (mnSlant == rCursor.mnSlant) &&
446 : : (mnOrientation == rCursor.mnOrientation) &&
447 : : (mnDirection == rCursor.mnDirection) &&
448 [ # # ][ # # ]: 0 : (mbVisible == rCursor.mbVisible))
[ # # ][ # # ]
[ # # # # ]
449 : : ;
450 : : }
451 : :
452 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|