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