LibreOffice Module sw (master)  1
virtoutp.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 "virtoutp.hxx"
21 #include <viewopt.hxx>
22 #include <rootfrm.hxx>
23 
24 /* The SWLayVout class manages the virtual output devices.
25  * RootFrame has a static member of this class which is created in FrameInit
26  * and destroyed in FrameFinit.
27  * */
28 
30 {
31  if (SwRootFrame::s_pVout->IsFlushable())
32  {
34  return true;
35  }
36  return false;
37 }
38 
39 bool SwRootFrame::HasSameRect( const SwRect& rRect )
40 {
41  if (SwRootFrame::s_pVout->IsFlushable())
42  return ( rRect == SwRootFrame::s_pVout->GetOrgRect() );
43  return false;
44 }
45 
69 // define to control, if old or new solution for setting the mapping for
70 // a virtual output device is used.
71 static void SetMappingForVirtDev( const Point& _rNewOrigin,
72  const vcl::RenderContext* _pOrgOutDev,
73  vcl::RenderContext* _pVirDev )
74 {
75  // new solution: set pixel offset at virtual output device
76  Point aPixelOffset = _pOrgOutDev->LogicToPixel( _rNewOrigin );
77  _pVirDev->SetPixelOffset( Size( -aPixelOffset.X(), -aPixelOffset.Y() ) );
78 }
79 
80 // rSize must be pixel coordinates!
81 bool SwLayVout::DoesFit( const Size &rNew )
82 {
83  if( rNew.Height() > VIRTUALHEIGHT )
84  return false;
85  if( rNew.Width() <= 0 || rNew.Height() <= 0 )
86  return false;
87  if( rNew.Width() <= aSize.Width() )
88  return true;
89  if( !pVirDev )
90  {
93  if( pOut )
94  {
95  if( pVirDev->GetFillColor() != pOut->GetFillColor() )
97  }
98  }
99 
100  if( rNew.Width() > aSize.Width() )
101  {
102  aSize.setWidth( rNew.Width() );
103  if( !pVirDev->SetOutputSizePixel( aSize ) )
104  {
106  aSize.setWidth( 0 );
107  return false;
108  }
109  }
110  return true;
111 }
112 
118 void SwLayVout::Enter( SwViewShell *pShell, SwRect &rRect, bool bOn )
119 {
120  Flush();
121 
122 #ifdef DBG_UTIL
123  if( pShell->GetViewOptions()->IsTest3() )
124  {
125  ++nCount;
126  return;
127  }
128 #endif
129 
130  bOn = bOn && !nCount && rRect.HasArea() && pShell->GetWin();
131  ++nCount;
132  if( !bOn )
133  return;
134 
135  pSh = pShell;
136  pOut = nullptr;
137  OutputDevice *pO = pSh->GetOut();
138 // We don't cheat on printers or virtual output devices...
139  if( OUTDEV_WINDOW != pO->GetOutDevType() )
140  return;
141 
142  pOut = pO;
143  Size aPixSz( pOut->PixelToLogic( Size( 1,1 )) );
144  SwRect aTmp( rRect );
145  aTmp.SSize().AdjustWidth(aPixSz.Width()/2 + 1 );
146  aTmp.SSize().AdjustHeight(aPixSz.Height()/2 + 1 );
147  tools::Rectangle aTmpRect( pO->LogicToPixel( aTmp.SVRect() ) );
148 
149  OSL_ENSURE( !pSh->GetWin()->IsReallyVisible() ||
150  aTmpRect.GetWidth() <= pSh->GetWin()->GetOutputSizePixel().Width() + 2,
151  "Paintwidth bigger than visarea?" );
152  // Does the rectangle fit in our buffer?
153  if( !DoesFit( aTmpRect.GetSize() ) )
154  {
155  pOut = nullptr;
156  return;
157  }
158 
159  aRect = SwRect( pO->PixelToLogic( aTmpRect ) );
160 
161  SetOutDev( pSh, pVirDev );
162 
163  if( pVirDev->GetFillColor() != pOut->GetFillColor() )
165 
166  MapMode aMapMode( pOut->GetMapMode() );
167  // OD 12.11.2002 #96272# - use method to set mapping
168  //aMapMode.SetOrigin( Point(0,0) - aRect.Pos() );
170 
171  if( aMapMode != pVirDev->GetMapMode() )
172  pVirDev->SetMapMode( aMapMode );
173 
175  rRect = aRect;
176 
177 }
178 
180 {
181  OSL_ENSURE( pVirDev, "SwLayVout::DrawOut: nothing left Toulouse" );
183  aRect.Pos(), aRect.SSize(), *pVirDev );
184  SetOutDev( pSh, pOut );
185  pOut = nullptr;
186 }
187 
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:341
long Width() const
OutDevType GetOutDevType() const
void SetPixelOffset(const Size &rOffset)
sal_uInt16 nCount
Definition: virtoutp.hxx:39
long GetWidth() const
long Height() const
SwViewShell * pSh
Definition: virtoutp.hxx:33
void Enter(SwViewShell *pShell, SwRect &rRect, bool bOn)
OD 27.09.2002 #103636# - change 2nd parameter - no longer
Definition: virtoutp.cxx:118
const MapMode & GetMapMode() const
#define VIRTUALHEIGHT
Definition: virtoutp.hxx:27
void Pos(const Point &rNew)
Definition: swrect.hxx:167
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
void SetMapMode()
OUTDEV_WINDOW
static void SetMappingForVirtDev(const Point &_rNewOrigin, const vcl::RenderContext *_pOrgOutDev, vcl::RenderContext *_pVirDev)
method to set mapping/pixel offset for virtual output device
Definition: virtoutp.cxx:71
void Flush_()
Definition: virtoutp.cxx:179
VclPtr< VirtualDevice > pVirDev
Definition: virtoutp.hxx:35
void SetLineColor()
bool SetOutputSizePixel(const Size &rNewSize, bool bErase=true)
SwRect aRect
Definition: virtoutp.hxx:36
bool HasArea() const
Definition: swrect.hxx:290
void SetFillColor()
Size GetOutputSizePixel() const
void SSize(const Size &rNew)
Definition: swrect.hxx:176
long X() const
Size GetSize() const
void Flush()
Definition: virtoutp.hxx:56
bool DoesFit(const Size &rOut)
Definition: virtoutp.cxx:81
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
Size aSize
Definition: virtoutp.hxx:38
VclPtr< OutputDevice > pOut
Definition: virtoutp.hxx:34
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:426
vcl::Window * GetWin() const
Definition: viewsh.hxx:340
static VclPtr< reference_type > Create(Arg &&...arg)
static SwLayVout * s_pVout
Definition: rootfrm.hxx:102
bool IsReallyVisible() const
void SetOutDev(SwViewShell *pSh, OutputDevice *pOut)
Definition: notxtfrm.cxx:174
static bool FlushVout()
Output virtual Device (e.g. for animations)
Definition: virtoutp.cxx:29
bool IsTest3() const
Definition: viewopt.hxx:457
void setWidth(long nWidth)
static bool HasSameRect(const SwRect &rRect)
Save Clipping if exactly the ClipRect is outputted.
Definition: virtoutp.cxx:39
SAL_DLLPRIVATE void DrawOutDev(const Point &, const Size &, const Point &, const Size &, const Printer &)=delete
long Y() const
const Color & GetFillColor() const