1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 28 #include <com/sun/star/text/HoriOrientation.hpp> 29 #include <vcl/window.hxx> 30 31 #include "swtypes.hxx" 32 #include "shdwcrsr.hxx" 33 34 using namespace ::com::sun::star; 35 36 37 SwShadowCursor::~SwShadowCursor() 38 { 39 if( USHRT_MAX != nOldMode ) 40 DrawCrsr( aOldPt, nOldHeight, nOldMode ); 41 } 42 43 void SwShadowCursor::SetPos( const Point& rPt, long nHeight, sal_uInt16 nMode ) 44 { 45 Point aPt( pWin->LogicToPixel( rPt )); 46 nHeight = pWin->LogicToPixel( Size( 0, nHeight )).Height(); 47 if( aOldPt != aPt || nOldHeight != nHeight || nOldMode != nMode ) 48 { 49 if( USHRT_MAX != nOldMode ) 50 DrawCrsr( aOldPt, nOldHeight, nOldMode ); 51 52 DrawCrsr( aPt, nHeight, nMode ); 53 nOldMode = nMode; 54 nOldHeight = nHeight; 55 aOldPt = aPt; 56 } 57 } 58 59 void SwShadowCursor::DrawTri( const Point& rPt, long nHeight, sal_Bool bLeft ) 60 { 61 long nLineDiff = ( nHeight / 2 ); 62 long nLineDiffHalf = nLineDiff / 2; 63 64 // Punkt oben 65 Point aPt1( (bLeft ? rPt.X() - 3 : rPt.X() + 3), 66 rPt.Y() + nLineDiffHalf ); 67 // Punkt unten 68 Point aPt2( aPt1.X(), aPt1.Y() + nHeight - nLineDiff - 1 ); 69 long nDiff = bLeft ? -1 : 1; 70 while( aPt1.Y() <= aPt2.Y() ) 71 { 72 pWin->DrawLine( aPt1, aPt2 ); 73 aPt1.Y()++, aPt2.Y()--; 74 aPt2.X() = aPt1.X() += nDiff; 75 } 76 } 77 78 void SwShadowCursor::DrawCrsr( const Point& rPt, long nHeight, sal_uInt16 nMode ) 79 { 80 nHeight = (((nHeight / 4)+1) * 4) + 1; 81 82 pWin->Push(); 83 84 pWin->SetMapMode( MAP_PIXEL ); 85 pWin->SetRasterOp( ROP_XOR ); 86 87 pWin->SetLineColor( Color( aCol.GetColor() ^ COL_WHITE ) ); 88 89 // 1. der Strich: 90 pWin->DrawLine( Point( rPt.X(), rPt.Y() + 1), 91 Point( rPt.X(), rPt.Y() - 2 + nHeight )); 92 93 // 2. das Dreieck 94 if( text::HoriOrientation::LEFT == nMode || text::HoriOrientation::CENTER == nMode ) // Pfeil nach rechts 95 DrawTri( rPt, nHeight, sal_False ); 96 if( text::HoriOrientation::RIGHT == nMode || text::HoriOrientation::CENTER == nMode ) // Pfeil nach links 97 DrawTri( rPt, nHeight, sal_True ); 98 99 pWin->Pop(); 100 } 101 102 void SwShadowCursor::Paint() 103 { 104 if( USHRT_MAX != nOldMode ) 105 DrawCrsr( aOldPt, nOldHeight, nOldMode ); 106 } 107 108 Rectangle SwShadowCursor::GetRect() const 109 { 110 long nH = nOldHeight; 111 Point aPt( aOldPt ); 112 113 nH = (((nH / 4)+1) * 4) + 1; 114 long nWidth = nH / 4 + 3 + 1; 115 116 Size aSz( nWidth, nH ); 117 118 if( text::HoriOrientation::RIGHT == nOldMode ) 119 aPt.X() -= aSz.Width(); 120 else if( text::HoriOrientation::CENTER == nOldMode ) 121 { 122 aPt.X() -= aSz.Width(); 123 aSz.Width() *= 2; 124 } 125 126 return pWin->PixelToLogic( Rectangle( aPt, aSz ) ); 127 } 128 129 130 131 132