LibreOffice Module sw (master)  1
shdwcrsr.cxx
Go to the documentation of this file.
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 <vcl/window.hxx>
22 #include <swtypes.hxx>
23 #include <shdwcrsr.hxx>
24 
25 using namespace ::com::sun::star;
26 
28 {
29  if( USHRT_MAX != nOldMode )
31 }
32 
33 void SwShadowCursor::SetPos( const Point& rPt, long nHeight, sal_uInt16 nMode )
34 {
35  Point aPt( pWin->LogicToPixel( rPt ));
36  nHeight = pWin->LogicToPixel( Size( 0, nHeight )).Height();
37  if( aOldPt != aPt || nOldHeight != nHeight || nOldMode != nMode )
38  {
39  if( USHRT_MAX != nOldMode )
41 
42  DrawCursor( aPt, nHeight, nMode );
43  nOldMode = nMode;
44  nOldHeight = nHeight;
45  aOldPt = aPt;
46  }
47 }
48 
49 void SwShadowCursor::DrawTri( const Point& rPt, long nHeight, bool bLeft )
50 {
51  long nLineDiff = nHeight / 2;
52  long nLineDiffHalf = nLineDiff / 2;
53 
54  // Dot above
55  Point aPt1( (bLeft ? rPt.X() - 3 : rPt.X() + 3),
56  rPt.Y() + nLineDiffHalf );
57  // Dot below
58  Point aPt2( aPt1.X(), aPt1.Y() + nHeight - nLineDiff - 1 );
59  long nDiff = bLeft ? -1 : 1;
60  while( aPt1.Y() <= aPt2.Y() )
61  {
62  pWin->DrawLine( aPt1, aPt2 );
63  aPt1.AdjustY( 1 );
64  aPt2.AdjustY( -1 );
65  aPt2.setX( aPt1.AdjustX(nDiff ) );
66  }
67 }
68 
69 void SwShadowCursor::DrawCursor( const Point& rPt, long nHeight, sal_uInt16 nMode )
70 {
71  nHeight = (((nHeight / 4)+1) * 4) + 1;
72 
73  pWin->Push();
74 
75  pWin->SetMapMode(MapMode(MapUnit::MapPixel));
76  pWin->SetRasterOp( RasterOp::Xor );
77 
78  pWin->SetLineColor( Color( sal_uInt32(aCol) ^ sal_uInt32(COL_WHITE) ) );
79 
80  // 1. The Line:
81  pWin->DrawLine( Point( rPt.X(), rPt.Y() + 1),
82  Point( rPt.X(), rPt.Y() - 2 + nHeight ));
83 
84  // 2. The Triangle
85  if( text::HoriOrientation::LEFT == nMode || text::HoriOrientation::CENTER == nMode ) // Arrow to the right
86  DrawTri( rPt, nHeight, false );
87  if( text::HoriOrientation::RIGHT == nMode || text::HoriOrientation::CENTER == nMode ) // Arrow to the left
88  DrawTri( rPt, nHeight, true );
89 
90  pWin->Pop();
91 }
92 
94 {
95  if( USHRT_MAX != nOldMode )
97 }
98 
100 {
101  long nH = nOldHeight;
102  Point aPt( aOldPt );
103 
104  nH = (((nH / 4)+1) * 4) + 1;
105  long nWidth = nH / 4 + 3 + 1;
106 
107  Size aSz( nWidth, nH );
108 
110  aPt.AdjustX( -(aSz.Width()) );
111  else if( text::HoriOrientation::CENTER == nOldMode )
112  {
113  aPt.AdjustX( -(aSz.Width()) );
114  aSz.setWidth( aSz.Width() * 2 );
115  }
116 
117  return pWin->PixelToLogic( tools::Rectangle( aPt, aSz ) );
118 }
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
sal_uInt16 nOldMode
Definition: shdwcrsr.hxx:34
long AdjustX(long nHorzMove)
VclPtr< vcl::Window > pWin
Definition: shdwcrsr.hxx:30
void SetMapMode()
tools::Rectangle GetRect() const
Definition: shdwcrsr.cxx:99
void Paint()
Definition: shdwcrsr.cxx:93
void DrawLine(const Point &rStartPt, const Point &rEndPt)
void SetLineColor()
void DrawTri(const Point &rPt, long nHeight, bool bLeft)
Definition: shdwcrsr.cxx:49
long X() const
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
void SetRasterOp(RasterOp eRasterOp)
void DrawCursor(const Point &rPt, long nHeight, sal_uInt16 nMode)
Definition: shdwcrsr.cxx:69
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
Color const aCol
Definition: shdwcrsr.hxx:31
void SetPos(const Point &rPt, long nHeight, sal_uInt16 nMode)
Definition: shdwcrsr.cxx:33
void Push(PushFlags nFlags=PushFlags::ALL)
void setWidth(long nWidth)
long Y() const