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