1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #include <com/sun/star/text/HoriOrientation.hpp> 21 #include <shdwcrsr.hxx> 22 23 using namespace ::com::sun::star; 24 25 SwShadowCursor::~SwShadowCursor() 26 { 27 if( USHRT_MAX != m_nOldMode ) 28 DrawCursor( m_aOldPt, m_nOldHeight, m_nOldMode ); 29 } 30 31 void SwShadowCursor::SetPos( const Point& rPt, tools::Long nHeight, sal_uInt16 nMode ) 32 { 33 Point aPt( m_pWin->LogicToPixel( rPt )); 34 nHeight = m_pWin->LogicToPixel( Size( 0, nHeight )).Height(); 35 if( m_aOldPt != aPt || m_nOldHeight != nHeight || m_nOldMode != nMode ) 36 { 37 if( USHRT_MAX != m_nOldMode ) 38 DrawCursor( m_aOldPt, m_nOldHeight, m_nOldMode ); 39 40 DrawCursor( aPt, nHeight, nMode ); 41 m_nOldMode = nMode; 42 m_nOldHeight = nHeight; 43 m_aOldPt = aPt; 44 } 45 } 46 47 void SwShadowCursor::DrawTri( const Point& rPt, tools::Long nHeight, bool bLeft ) 48 { 49 tools::Long nLineDiff = nHeight / 2; 50 tools::Long nLineDiffHalf = nLineDiff / 2; 51 52 // Dot above 53 Point aPt1( (bLeft ? rPt.X() - 3 : rPt.X() + 3), 54 rPt.Y() + nLineDiffHalf ); 55 // Dot below 56 Point aPt2( aPt1.X(), aPt1.Y() + nHeight - nLineDiff - 1 ); 57 tools::Long nDiff = bLeft ? -1 : 1; 58 while( aPt1.Y() <= aPt2.Y() ) 59 { 60 m_pWin->GetOutDev()->DrawLine( aPt1, aPt2 ); 61 aPt1.AdjustY( 1 ); 62 aPt2.AdjustY( -1 ); 63 aPt2.setX( aPt1.AdjustX(nDiff ) ); 64 } 65 } 66 67 void SwShadowCursor::DrawCursor( const Point& rPt, tools::Long nHeight, sal_uInt16 nMode ) 68 { 69 nHeight = (((nHeight / 4)+1) * 4) + 1; 70 71 m_pWin->GetOutDev()->Push(); 72 73 m_pWin->SetMapMode(MapMode(MapUnit::MapPixel)); 74 m_pWin->GetOutDev()->SetRasterOp( RasterOp::Xor ); 75 76 m_pWin->GetOutDev()->SetLineColor( Color( ColorTransparency, sal_uInt32(m_aCol) ^ sal_uInt32(COL_WHITE) ) ); 77 78 // 1. The Line: 79 m_pWin->GetOutDev()->DrawLine( Point( rPt.X(), rPt.Y() + 1), 80 Point( rPt.X(), rPt.Y() - 2 + nHeight )); 81 82 // 2. The Triangle 83 if( text::HoriOrientation::LEFT == nMode || text::HoriOrientation::CENTER == nMode ) // Arrow to the right 84 DrawTri( rPt, nHeight, false ); 85 if( text::HoriOrientation::RIGHT == nMode || text::HoriOrientation::CENTER == nMode ) // Arrow to the left 86 DrawTri( rPt, nHeight, true ); 87 88 m_pWin->GetOutDev()->Pop(); 89 } 90 91 void SwShadowCursor::Paint() 92 { 93 if( USHRT_MAX != m_nOldMode ) 94 DrawCursor( m_aOldPt, m_nOldHeight, m_nOldMode ); 95 } 96 97 tools::Rectangle SwShadowCursor::GetRect() const 98 { 99 tools::Long nH = m_nOldHeight; 100 Point aPt( m_aOldPt ); 101 102 nH = (((nH / 4)+1) * 4) + 1; 103 tools::Long nWidth = nH / 4 + 3 + 1; 104 105 Size aSz( nWidth, nH ); 106 107 if( text::HoriOrientation::RIGHT == m_nOldMode ) 108 aPt.AdjustX( -(aSz.Width()) ); 109 else if( text::HoriOrientation::CENTER == m_nOldMode ) 110 { 111 aPt.AdjustX( -(aSz.Width()) ); 112 aSz.setWidth( aSz.Width() * 2 ); 113 } 114 115 return m_pWin->PixelToLogic( tools::Rectangle( aPt, aSz ) ); 116 } 117 118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 119
