1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/text/HoriOrientation.hpp>
21 #include <shdwcrsr.hxx>
23 using namespace ::com::sun::star
;
25 SwShadowCursor::~SwShadowCursor()
27 if( USHRT_MAX
!= m_nOldMode
)
28 DrawCursor( m_aOldPt
, m_nOldHeight
, m_nOldMode
);
31 void SwShadowCursor::SetPos( const Point
& rPt
, tools::Long nHeight
, sal_uInt16 nMode
)
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
)
37 if( USHRT_MAX
!= m_nOldMode
)
38 DrawCursor( m_aOldPt
, m_nOldHeight
, m_nOldMode
);
40 DrawCursor( aPt
, nHeight
, nMode
);
42 m_nOldHeight
= nHeight
;
47 void SwShadowCursor::DrawTri( const Point
& rPt
, tools::Long nHeight
, bool bLeft
)
49 tools::Long nLineDiff
= nHeight
/ 2;
50 tools::Long nLineDiffHalf
= nLineDiff
/ 2;
53 Point
aPt1( (bLeft
? rPt
.X() - 3 : rPt
.X() + 3),
54 rPt
.Y() + nLineDiffHalf
);
56 Point
aPt2( aPt1
.X(), aPt1
.Y() + nHeight
- nLineDiff
- 1 );
57 tools::Long nDiff
= bLeft
? -1 : 1;
58 while( aPt1
.Y() <= aPt2
.Y() )
60 m_pWin
->GetOutDev()->DrawLine( aPt1
, aPt2
);
63 aPt2
.setX( aPt1
.AdjustX(nDiff
) );
67 void SwShadowCursor::DrawCursor( const Point
& rPt
, tools::Long nHeight
, sal_uInt16 nMode
)
69 nHeight
= (((nHeight
/ 4)+1) * 4) + 1;
71 m_pWin
->GetOutDev()->Push();
73 m_pWin
->SetMapMode(MapMode(MapUnit::MapPixel
));
74 m_pWin
->GetOutDev()->SetRasterOp( RasterOp::Xor
);
76 m_pWin
->GetOutDev()->SetLineColor( Color( ColorTransparency
, sal_uInt32(m_aCol
) ^ sal_uInt32(COL_WHITE
) ) );
79 m_pWin
->GetOutDev()->DrawLine( Point( rPt
.X(), rPt
.Y() + 1),
80 Point( rPt
.X(), rPt
.Y() - 2 + nHeight
));
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 );
88 m_pWin
->GetOutDev()->Pop();
91 void SwShadowCursor::Paint()
93 if( USHRT_MAX
!= m_nOldMode
)
94 DrawCursor( m_aOldPt
, m_nOldHeight
, m_nOldMode
);
97 tools::Rectangle
SwShadowCursor::GetRect() const
99 tools::Long nH
= m_nOldHeight
;
100 Point
aPt( m_aOldPt
);
102 nH
= (((nH
/ 4)+1) * 4) + 1;
103 tools::Long nWidth
= nH
/ 4 + 3 + 1;
105 Size
aSz( nWidth
, nH
);
107 if( text::HoriOrientation::RIGHT
== m_nOldMode
)
108 aPt
.AdjustX( -(aSz
.Width()) );
109 else if( text::HoriOrientation::CENTER
== m_nOldMode
)
111 aPt
.AdjustX( -(aSz
.Width()) );
112 aSz
.setWidth( aSz
.Width() * 2 );
115 return m_pWin
->PixelToLogic( tools::Rectangle( aPt
, aSz
) );
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */