merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / utlui / shdwcrsr.cxx
blob248af8d69b7c18ff012ab021e70226d021415b0a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shdwcrsr.cxx,v $
10 * $Revision: 1.7 $
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_sw.hxx"
35 #include <com/sun/star/text/HoriOrientation.hpp>
36 #include <vcl/window.hxx>
38 #include "swtypes.hxx"
39 #include "shdwcrsr.hxx"
41 using namespace ::com::sun::star;
44 SwShadowCursor::~SwShadowCursor()
46 if( USHRT_MAX != nOldMode )
47 DrawCrsr( aOldPt, nOldHeight, nOldMode );
50 void SwShadowCursor::SetPos( const Point& rPt, long nHeight, USHORT nMode )
52 Point aPt( pWin->LogicToPixel( rPt ));
53 nHeight = pWin->LogicToPixel( Size( 0, nHeight )).Height();
54 if( aOldPt != aPt || nOldHeight != nHeight || nOldMode != nMode )
56 if( USHRT_MAX != nOldMode )
57 DrawCrsr( aOldPt, nOldHeight, nOldMode );
59 DrawCrsr( aPt, nHeight, nMode );
60 nOldMode = nMode;
61 nOldHeight = nHeight;
62 aOldPt = aPt;
66 void SwShadowCursor::DrawTri( const Point& rPt, long nHeight, BOOL bLeft )
68 long nLineDiff = ( nHeight / 2 );
69 long nLineDiffHalf = nLineDiff / 2;
71 // Punkt oben
72 Point aPt1( (bLeft ? rPt.X() - 3 : rPt.X() + 3),
73 rPt.Y() + nLineDiffHalf );
74 // Punkt unten
75 Point aPt2( aPt1.X(), aPt1.Y() + nHeight - nLineDiff - 1 );
76 long nDiff = bLeft ? -1 : 1;
77 while( aPt1.Y() <= aPt2.Y() )
79 pWin->DrawLine( aPt1, aPt2 );
80 aPt1.Y()++, aPt2.Y()--;
81 aPt2.X() = aPt1.X() += nDiff;
85 void SwShadowCursor::DrawCrsr( const Point& rPt, long nHeight, USHORT nMode )
87 nHeight = (((nHeight / 4)+1) * 4) + 1;
89 pWin->Push();
91 pWin->SetMapMode( MAP_PIXEL );
92 pWin->SetRasterOp( ROP_XOR );
94 pWin->SetLineColor( Color( aCol.GetColor() ^ COL_WHITE ) );
96 // 1. der Strich:
97 pWin->DrawLine( Point( rPt.X(), rPt.Y() + 1),
98 Point( rPt.X(), rPt.Y() - 2 + nHeight ));
100 // 2. das Dreieck
101 if( text::HoriOrientation::LEFT == nMode || text::HoriOrientation::CENTER == nMode ) // Pfeil nach rechts
102 DrawTri( rPt, nHeight, FALSE );
103 if( text::HoriOrientation::RIGHT == nMode || text::HoriOrientation::CENTER == nMode ) // Pfeil nach links
104 DrawTri( rPt, nHeight, TRUE );
106 pWin->Pop();
109 void SwShadowCursor::Paint()
111 if( USHRT_MAX != nOldMode )
112 DrawCrsr( aOldPt, nOldHeight, nOldMode );
115 Rectangle SwShadowCursor::GetRect() const
117 long nH = nOldHeight;
118 Point aPt( aOldPt );
120 nH = (((nH / 4)+1) * 4) + 1;
121 long nWidth = nH / 4 + 3 + 1;
123 Size aSz( nWidth, nH );
125 if( text::HoriOrientation::RIGHT == nOldMode )
126 aPt.X() -= aSz.Width();
127 else if( text::HoriOrientation::CENTER == nOldMode )
129 aPt.X() -= aSz.Width();
130 aSz.Width() *= 2;
133 return pWin->PixelToLogic( Rectangle( aPt, aSz ) );