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
40bool 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.
72static 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!
82bool 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 {
93 m_pVirDev->SetLineColor();
94 if( m_pOut )
95 {
96 if( m_pVirDev->GetFillColor() != m_pOut->GetFillColor() )
97 m_pVirDev->SetFillColor( m_pOut->GetFillColor() );
98 }
99 }
100
101 if( rNew.Width() > m_aSize.Width() )
102 {
103 m_aSize.setWidth( rNew.Width() );
104 if( !m_pVirDev->SetOutputSizePixel( m_aSize ) )
105 {
107 m_aSize.setWidth( 0 );
108 return false;
109 }
110 }
111 return true;
112}
113
119void 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;
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
164 if( m_pVirDev->GetFillColor() != m_pOut->GetFillColor() )
165 m_pVirDev->SetFillColor( m_pOut->GetFillColor() );
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" );
183 m_pOut->DrawOutDev( m_aRect.Pos(), m_aRect.SSize(),
186 m_pOut = nullptr;
187}
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
void SetPixelOffset(const Size &rOffset)
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
OutDevType GetOutDevType() const
bool IsEmpty() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
constexpr tools::Long Width() const
void Enter(SwViewShell *pShell, SwRect &rRect, bool bOn)
OD 27.09.2002 #103636# - change 2nd parameter <rRect> - no longer <const>
Definition: virtoutp.cxx:119
Size m_aSize
Definition: virtoutp.hxx:38
void Flush_()
Definition: virtoutp.cxx:180
sal_uInt16 m_nCount
Definition: virtoutp.hxx:39
SwRect m_aRect
Definition: virtoutp.hxx:36
void Flush()
Definition: virtoutp.hxx:56
VclPtr< OutputDevice > m_pOut
Definition: virtoutp.hxx:34
SwViewShell * m_pShell
Definition: virtoutp.hxx:33
bool DoesFit(const Size &rOut)
Definition: virtoutp.cxx:82
VclPtr< VirtualDevice > m_pVirDev
Definition: virtoutp.hxx:35
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
bool HasArea() const
Definition: swrect.hxx:300
void Pos(const Point &rNew)
Definition: swrect.hxx:171
void SSize(const Size &rNew)
Definition: swrect.hxx:180
void AddHeight(const tools::Long nAdd)
Definition: swrect.cxx:124
void AddWidth(const tools::Long nAdd)
Definition: swrect.cxx:123
tools::Rectangle SVRect() const
Definition: swrect.hxx:292
static bool HasSameRect(const SwRect &rRect)
Save Clipping if exactly the ClipRect is outputted.
Definition: virtoutp.cxx:40
static bool FlushVout()
Output virtual Device (e.g. for animations)
Definition: virtoutp.cxx:30
static SwLayVout * s_pVout
Definition: rootfrm.hxx:104
bool IsTest3() const
Definition: viewopt.hxx:604
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:347
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:433
vcl::Window * GetWin() const
Definition: viewsh.hxx:346
void disposeAndClear()
static VclPtr< reference_type > Create(Arg &&... arg)
constexpr tools::Long GetWidth() const
constexpr Size GetSize() const
bool IsReallyVisible() const
Size GetOutputSizePixel() const
void SetOutDev(SwViewShell *pSh, OutputDevice *pOut)
Definition: notxtfrm.cxx:169
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
#define VIRTUALHEIGHT
Definition: virtoutp.hxx:27