merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / headless / svpvd.cxx
blobabac9ad2f435e0febddfecbd98d21f270ee8c4db
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svpvd.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "svpvd.hxx"
32 #include "svpgdi.hxx"
34 #include <basegfx/vector/b2ivector.hxx>
35 #include <basebmp/scanlineformats.hxx>
37 #include "stdio.h"
39 using namespace basegfx;
40 using namespace basebmp;
42 SvpSalVirtualDevice::~SvpSalVirtualDevice()
46 SalGraphics* SvpSalVirtualDevice::GetGraphics()
48 SvpSalGraphics* pGraphics = new SvpSalGraphics();
49 pGraphics->setDevice( m_aDevice );
50 m_aGraphics.push_back( pGraphics );
51 return pGraphics;
54 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics* pGraphics )
56 m_aGraphics.remove( dynamic_cast<SvpSalGraphics*>(pGraphics) );
57 delete pGraphics;
60 BOOL SvpSalVirtualDevice::SetSize( long nNewDX, long nNewDY )
62 B2IVector aDevSize( nNewDX, nNewDY );
63 if( aDevSize.getX() == 0 )
64 aDevSize.setX( 1 );
65 if( aDevSize.getY() == 0 )
66 aDevSize.setY( 1 );
67 if( ! m_aDevice.get() || m_aDevice->getSize() != aDevSize )
69 sal_uInt32 nFormat = SVP_DEFAULT_BITMAP_FORMAT;
70 std::vector< basebmp::Color > aDevPal;
71 switch( m_nBitCount )
73 case 1: nFormat = Format::ONE_BIT_MSB_PAL;
74 aDevPal.reserve(2);
75 aDevPal.push_back( basebmp::Color( 0, 0, 0 ) );
76 aDevPal.push_back( basebmp::Color( 0xff, 0xff, 0xff ) );
77 break;
78 case 4: nFormat = Format::FOUR_BIT_MSB_PAL; break;
79 case 8: nFormat = Format::EIGHT_BIT_PAL; break;
80 #ifdef OSL_BIGENDIAN
81 case 16: nFormat = Format::SIXTEEN_BIT_MSB_TC_MASK; break;
82 #else
83 case 16: nFormat = Format::SIXTEEN_BIT_LSB_TC_MASK; break;
84 #endif
85 case 0:
86 case 24: nFormat = Format::TWENTYFOUR_BIT_TC_MASK; break;
87 case 32: nFormat = Format::THIRTYTWO_BIT_TC_MASK; break;
89 m_aDevice = aDevPal.empty()
90 ? createBitmapDevice( aDevSize, false, nFormat )
91 : createBitmapDevice( aDevSize, false, nFormat, PaletteMemorySharedVector( new std::vector< basebmp::Color >(aDevPal) ) );
93 // update device in existing graphics
94 for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
95 it != m_aGraphics.end(); ++it )
96 (*it)->setDevice( m_aDevice );
99 return true;
102 void SvpSalVirtualDevice::GetSize( long& rWidth, long& rHeight )
104 if( m_aDevice.get() )
106 B2IVector aDevSize( m_aDevice->getSize() );
107 rWidth = aDevSize.getX();
108 rHeight = aDevSize.getY();
110 else
111 rWidth = rHeight = 0;