1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 #include <com/sun/star/text/HoriOrientation.hpp> 33 #include <vcl/window.hxx> 34 35 #include "swtypes.hxx" 36 #include "shdwcrsr.hxx" 37 38 using namespace ::com::sun::star; 39 40 41 SwShadowCursor::~SwShadowCursor() 42 { 43 if( USHRT_MAX != nOldMode ) 44 DrawCrsr( aOldPt, nOldHeight, nOldMode ); 45 } 46 47 void SwShadowCursor::SetPos( const Point& rPt, long nHeight, sal_uInt16 nMode ) 48 { 49 Point aPt( pWin->LogicToPixel( rPt )); 50 nHeight = pWin->LogicToPixel( Size( 0, nHeight )).Height(); 51 if( aOldPt != aPt || nOldHeight != nHeight || nOldMode != nMode ) 52 { 53 if( USHRT_MAX != nOldMode ) 54 DrawCrsr( aOldPt, nOldHeight, nOldMode ); 55 56 DrawCrsr( aPt, nHeight, nMode ); 57 nOldMode = nMode; 58 nOldHeight = nHeight; 59 aOldPt = aPt; 60 } 61 } 62 63 void SwShadowCursor::DrawTri( const Point& rPt, long nHeight, sal_Bool bLeft ) 64 { 65 long nLineDiff = ( nHeight / 2 ); 66 long nLineDiffHalf = nLineDiff / 2; 67 68 // Punkt oben 69 Point aPt1( (bLeft ? rPt.X() - 3 : rPt.X() + 3), 70 rPt.Y() + nLineDiffHalf ); 71 // Punkt unten 72 Point aPt2( aPt1.X(), aPt1.Y() + nHeight - nLineDiff - 1 ); 73 long nDiff = bLeft ? -1 : 1; 74 while( aPt1.Y() <= aPt2.Y() ) 75 { 76 pWin->DrawLine( aPt1, aPt2 ); 77 aPt1.Y()++, aPt2.Y()--; 78 aPt2.X() = aPt1.X() += nDiff; 79 } 80 } 81 82 void SwShadowCursor::DrawCrsr( const Point& rPt, long nHeight, sal_uInt16 nMode ) 83 { 84 nHeight = (((nHeight / 4)+1) * 4) + 1; 85 86 pWin->Push(); 87 88 pWin->SetMapMode( MAP_PIXEL ); 89 pWin->SetRasterOp( ROP_XOR ); 90 91 pWin->SetLineColor( Color( aCol.GetColor() ^ COL_WHITE ) ); 92 93 // 1. der Strich: 94 pWin->DrawLine( Point( rPt.X(), rPt.Y() + 1), 95 Point( rPt.X(), rPt.Y() - 2 + nHeight )); 96 97 // 2. das Dreieck 98 if( text::HoriOrientation::LEFT == nMode || text::HoriOrientation::CENTER == nMode ) // Pfeil nach rechts 99 DrawTri( rPt, nHeight, sal_False ); 100 if( text::HoriOrientation::RIGHT == nMode || text::HoriOrientation::CENTER == nMode ) // Pfeil nach links 101 DrawTri( rPt, nHeight, sal_True ); 102 103 pWin->Pop(); 104 } 105 106 void SwShadowCursor::Paint() 107 { 108 if( USHRT_MAX != nOldMode ) 109 DrawCrsr( aOldPt, nOldHeight, nOldMode ); 110 } 111 112 Rectangle SwShadowCursor::GetRect() const 113 { 114 long nH = nOldHeight; 115 Point aPt( aOldPt ); 116 117 nH = (((nH / 4)+1) * 4) + 1; 118 long nWidth = nH / 4 + 3 + 1; 119 120 Size aSz( nWidth, nH ); 121 122 if( text::HoriOrientation::RIGHT == nOldMode ) 123 aPt.X() -= aSz.Width(); 124 else if( text::HoriOrientation::CENTER == nOldMode ) 125 { 126 aPt.X() -= aSz.Width(); 127 aSz.Width() *= 2; 128 } 129 130 return pWin->PixelToLogic( Rectangle( aPt, aSz ) ); 131 } 132 133 134 135 136