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