LibreOffice Module vcl (master)  1
outdev/clipping.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 <sal/config.h>
21 #include <osl/diagnose.h>
22 
23 #include <tools/debug.hxx>
24 #include <vcl/metaact.hxx>
25 #include <vcl/virdev.hxx>
26 #include <vcl/gdimtf.hxx>
27 #include <vcl/outdev.hxx>
28 
29 #include <salgdi.hxx>
30 
32  const Point& rPos, const Size& rSize, const Size& rBackgroundSize) const
33 {
34  rSaveDevice.DrawOutDev(Point(), rBackgroundSize, rPos, rSize, *this);
35 }
36 
38 {
39 
40  return PixelToLogic( maRegion );
41 }
42 
44 {
45 
46  if ( mpMetaFile )
48 
49  SetDeviceClipRegion( nullptr );
50 
51  if( mpAlphaVDev )
53 }
54 
56 {
57 
58  if ( mpMetaFile )
59  mpMetaFile->AddAction( new MetaClipRegionAction( rRegion, true ) );
60 
61  if ( rRegion.IsNull() )
62  {
63  SetDeviceClipRegion( nullptr );
64  }
65  else
66  {
67  vcl::Region aRegion = LogicToPixel( rRegion );
68  SetDeviceClipRegion( &aRegion );
69  }
70 
71  if( mpAlphaVDev )
72  mpAlphaVDev->SetClipRegion( rRegion );
73 }
74 
75 bool OutputDevice::SelectClipRegion( const vcl::Region& rRegion, SalGraphics* pGraphics )
76 {
78 
79  if( !pGraphics )
80  {
81  if( !mpGraphics && !AcquireGraphics() )
82  return false;
83  pGraphics = mpGraphics;
84  }
85 
86  bool bClipRegion = pGraphics->SetClipRegion( rRegion, this );
87  OSL_ENSURE( bClipRegion, "OutputDevice::SelectClipRegion() - can't create region" );
88  return bClipRegion;
89 }
90 
91 void OutputDevice::MoveClipRegion( long nHorzMove, long nVertMove )
92 {
93 
94  if ( mbClipRegion )
95  {
96  if( mpMetaFile )
97  mpMetaFile->AddAction( new MetaMoveClipRegionAction( nHorzMove, nVertMove ) );
98 
100  ImplLogicHeightToDevicePixel( nVertMove ) );
101  mbInitClipRegion = true;
102  }
103 
104  if( mpAlphaVDev )
105  mpAlphaVDev->MoveClipRegion( nHorzMove, nVertMove );
106 }
107 
109 {
110 
111  if ( mpMetaFile )
113 
114  tools::Rectangle aRect = LogicToPixel( rRect );
115  maRegion.Intersect( aRect );
116  mbClipRegion = true;
117  mbInitClipRegion = true;
118 
119  if( mpAlphaVDev )
121 }
122 
124 {
125 
126  if(!rRegion.IsNull())
127  {
128  if ( mpMetaFile )
130 
131  vcl::Region aRegion = LogicToPixel( rRegion );
132  maRegion.Intersect( aRegion );
133  mbClipRegion = true;
134  mbInitClipRegion = true;
135  }
136 
137  if( mpAlphaVDev )
138  mpAlphaVDev->IntersectClipRegion( rRegion );
139 }
140 
142 {
144 
145  if ( mbClipRegion )
146  {
147  if ( maRegion.IsEmpty() )
148  mbOutputClipped = true;
149  else
150  {
151  mbOutputClipped = false;
152 
153  // #102532# Respect output offset also for clip region
155 
156  if ( aRegion.IsEmpty() )
157  {
158  mbOutputClipped = true;
159  }
160  else
161  {
162  mbOutputClipped = false;
163  SelectClipRegion( aRegion );
164  }
165  }
166 
167  mbClipRegionSet = true;
168  }
169  else
170  {
171  if ( mbClipRegionSet )
172  {
174  mbClipRegionSet = false;
175  }
176 
177  mbOutputClipped = false;
178  }
179 
180  mbInitClipRegion = false;
181 }
182 
184 {
186  mnOutOffY,
188  mnOutOffY + GetOutputHeightPixel() - 1
189  });
190  return aRegion;
191 }
192 
194 {
195  return GetClipRegion();
196 }
197 
199 {
200  // this is only used in Window, but we still need it as it's called
201  // on in other clipping functions
202 }
203 
205 {
207 
208  if ( !pRegion )
209  {
210  if ( mbClipRegion )
211  {
212  maRegion = vcl::Region(true);
213  mbClipRegion = false;
214  mbInitClipRegion = true;
215  }
216  }
217  else
218  {
219  maRegion = *pRegion;
220  mbClipRegion = true;
221  mbInitClipRegion = true;
222  }
223 }
224 
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
vcl::Region GetClipRegion() const
long mnOutOffX
Output offset for device output in pixel (pseudo window offset within window system's frames) ...
Definition: outdev.hxx:342
bool IsNull() const
Definition: region.hxx:102
virtual void ClipToPaintRegion(tools::Rectangle &rDstRect)
SAL_DLLPRIVATE void SetDeviceClipRegion(const vcl::Region *pRegion)
long mnOutOffY
Output offset for device output in pixel (pseudo window offset within window system's frames) ...
Definition: outdev.hxx:344
vcl::Region maRegion
Definition: outdev.hxx:361
bool mbOutputClipped
Definition: outdev.hxx:381
void IntersectClipRegion(const tools::Rectangle &rRect)
bool SelectClipRegion(const vcl::Region &, SalGraphics *pGraphics=nullptr)
bool mbClipRegionSet
Definition: outdev.hxx:389
void Move(long nHorzMove, long nVertMove)
Definition: region.cxx:414
SalGraphics * mpGraphics
Graphics context to draw on.
Definition: outdev.hxx:316
bool IsEmpty() const
Definition: region.cxx:228
virtual bool AcquireGraphics() const =0
Acquire a graphics device that the output device uses to draw on.
void Intersect(const tools::Rectangle &rRegion)
Definition: region.cxx:584
void MoveClipRegion(long nHorzMove, long nVertMove)
bool SetClipRegion(const vcl::Region &, const OutputDevice *pOutDev)
virtual void SaveBackground(VirtualDevice &rSaveDevice, const Point &rPos, const Size &rSize, const Size &rBackgroundSize) const
long GetOutputWidthPixel() const
Definition: outdev.hxx:443
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1185
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:940
VclPtr< VirtualDevice > mpAlphaVDev
Definition: outdev.hxx:331
SAL_DLLPRIVATE vcl::Region ImplPixelToDevicePixel(const vcl::Region &rRegion) const
Convert a region in pixel units to a region in device pixel units and coords.
Definition: map.cxx:637
bool mbClipRegion
Definition: outdev.hxx:377
long GetOutputHeightPixel() const
Definition: outdev.hxx:444
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:539
virtual vcl::Region GetActiveClipRegion() const
bool mbInitClipRegion
Definition: outdev.hxx:388
virtual void InitClipRegion()
virtual void DrawOutDev(const Point &rDestPt, const Size &rDestSize, const Point &rSrcPt, const Size &rSrcSize)
Definition: outdev.cxx:348
SAL_DLLPRIVATE long ImplLogicWidthToDevicePixel(long nWidth) const
Convert a logical width to a width in units of device pixels.
Definition: map.cxx:430
virtual vcl::Region ClipToDeviceBounds(vcl::Region aRegion) const
Perform actual rect clip against outdev dimensions, to generate empty clips whenever one of the value...
SAL_DLLPRIVATE long ImplLogicHeightToDevicePixel(long nHeight) const
Convert a logical height to a height in units of device pixels.
Definition: map.cxx:440
#define DBG_TESTSOLARMUTEX()
virtual void ResetClipRegion()=0
GDIMetaFile * mpMetaFile
Definition: outdev.hxx:319