Update ooo320-m1
[ooovba.git] / vcl / win / source / gdi / salvd.cxx
blobcb9bf85edb74469418a2b3f32fe13fecf53cf9f7
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: salvd.cxx,v $
10 * $Revision: 1.14 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/svwin.h>
34 #include <wincomp.hxx>
35 #include <saldata.hxx>
36 #include <salinst.h>
37 #include <salgdi.h>
38 #include <salvd.h>
39 #include <vcl/sysdata.hxx>
41 // =======================================================================
43 static HBITMAP ImplCreateVirDevBitmap( HDC hDC, long nDX, long nDY,
44 USHORT nBitCount )
46 HBITMAP hBitmap;
48 if ( nBitCount == 1 )
50 hBitmap = CreateBitmap( (int)nDX, (int)nDY, 1, 1, NULL );
52 else
54 // #146839# Don't use CreateCompatibleBitmap() - there seem to
55 // be build-in limits for those HBITMAPs, at least this fails
56 // rather often on large displays/multi-monitor setups.
57 BITMAPINFO aBitmapInfo;
58 aBitmapInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
59 aBitmapInfo.bmiHeader.biWidth = nDX;
60 aBitmapInfo.bmiHeader.biHeight = nDY;
61 aBitmapInfo.bmiHeader.biPlanes = 1;
62 aBitmapInfo.bmiHeader.biBitCount = (WORD)GetDeviceCaps( hDC,
63 BITSPIXEL );
64 aBitmapInfo.bmiHeader.biCompression = BI_RGB;
65 aBitmapInfo.bmiHeader.biSizeImage = 0;
66 aBitmapInfo.bmiHeader.biXPelsPerMeter = 0;
67 aBitmapInfo.bmiHeader.biYPelsPerMeter = 0;
68 aBitmapInfo.bmiHeader.biClrUsed = 0;
69 aBitmapInfo.bmiHeader.biClrImportant = 0;
71 void* pDummy;
72 hBitmap = CreateDIBSection( hDC, &aBitmapInfo,
73 DIB_RGB_COLORS, &pDummy, NULL,
74 0 );
77 return hBitmap;
80 // =======================================================================
82 SalVirtualDevice* WinSalInstance::CreateVirtualDevice( SalGraphics* pSGraphics,
83 long nDX, long nDY,
84 USHORT nBitCount,
85 const SystemGraphicsData* pData )
87 WinSalGraphics* pGraphics = static_cast<WinSalGraphics*>(pSGraphics);
89 HDC hDC = NULL;
90 HBITMAP hBmp = NULL;
91 BOOL bOk = FALSE;
93 if( pData )
95 hDC = pData->hDC;
96 hBmp = NULL;
97 bOk = (hDC != NULL);
99 else
101 hDC = CreateCompatibleDC( pGraphics->mhDC );
102 if( !hDC )
103 ImplWriteLastError( GetLastError(), "CreateCompatibleDC in CreateVirtualDevice" );
105 hBmp = ImplCreateVirDevBitmap( pGraphics->mhDC,
106 nDX, nDY, nBitCount );
107 if( !hBmp )
108 ImplWriteLastError( GetLastError(), "ImplCreateVirDevBitmap in CreateVirtualDevice" );
109 // #124826# continue even if hBmp could not be created
110 // if we would return a failure in this case, the process
111 // would terminate which is not required
113 DBG_ASSERT( hBmp, "WinSalInstance::CreateVirtualDevice(), could not create Bitmap!" );
115 bOk = (hDC != NULL);
118 if ( bOk )
120 WinSalVirtualDevice* pVDev = new WinSalVirtualDevice;
121 SalData* pSalData = GetSalData();
122 WinSalGraphics* pVirGraphics = new WinSalGraphics;
123 pVirGraphics->SetLayout( 0 ); // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
124 pVirGraphics->mhDC = hDC;
125 pVirGraphics->mhWnd = 0;
126 pVirGraphics->mbPrinter = FALSE;
127 pVirGraphics->mbVirDev = TRUE;
128 pVirGraphics->mbWindow = FALSE;
129 pVirGraphics->mbScreen = pGraphics->mbScreen;
130 if ( pSalData->mhDitherPal && pVirGraphics->mbScreen )
132 pVirGraphics->mhDefPal = SelectPalette( hDC, pSalData->mhDitherPal, TRUE );
133 RealizePalette( hDC );
135 ImplSalInitGraphics( pVirGraphics );
137 pVDev->mhDC = hDC;
138 pVDev->mhBmp = hBmp;
139 if( hBmp )
140 pVDev->mhDefBmp = SelectBitmap( hDC, hBmp );
141 else
142 pVDev->mhDefBmp = NULL;
143 pVDev->mpGraphics = pVirGraphics;
144 pVDev->mnBitCount = nBitCount;
145 pVDev->mbGraphics = FALSE;
146 pVDev->mbForeignDC = (pData != NULL);
148 // insert VirDev in VirDevList
149 pVDev->mpNext = pSalData->mpFirstVD;
150 pSalData->mpFirstVD = pVDev;
152 return pVDev;
154 else
156 if ( hDC && !pData )
157 DeleteDC( hDC );
158 if ( hBmp )
159 DeleteBitmap( hBmp );
160 return NULL;
164 // -----------------------------------------------------------------------
166 void WinSalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice )
168 delete pDevice;
171 // =======================================================================
173 WinSalVirtualDevice::WinSalVirtualDevice()
175 mhDC = (HDC) NULL; // HDC or 0 for Cache Device
176 mhBmp = (HBITMAP) NULL; // Memory Bitmap
177 mhDefBmp = (HBITMAP) NULL; // Default Bitmap
178 mpGraphics = NULL; // current VirDev graphics
179 mpNext = NULL; // next VirDev
180 mnBitCount = 0; // BitCount (0 or 1)
181 mbGraphics = FALSE; // is Graphics used
182 mbForeignDC = FALSE; // uses a foreign DC instead of a bitmap
185 // -----------------------------------------------------------------------
187 WinSalVirtualDevice::~WinSalVirtualDevice()
189 // remove VirDev from list of virtual devices
190 SalData* pSalData = GetSalData();
191 WinSalVirtualDevice** ppVirDev = &pSalData->mpFirstVD;
192 for(; (*ppVirDev != this) && *ppVirDev; ppVirDev = &(*ppVirDev)->mpNext );
193 if( *ppVirDev )
194 *ppVirDev = mpNext;
196 // destroy saved DC
197 if( mpGraphics->mhDefPal )
198 SelectPalette( mpGraphics->mhDC, mpGraphics->mhDefPal, TRUE );
199 ImplSalDeInitGraphics( mpGraphics );
200 if( mhDefBmp )
201 SelectBitmap( mpGraphics->mhDC, mhDefBmp );
202 if( !mbForeignDC )
203 DeleteDC( mpGraphics->mhDC );
204 if( mhBmp )
205 DeleteBitmap( mhBmp );
206 delete mpGraphics;
207 mpGraphics = NULL;
210 // -----------------------------------------------------------------------
212 SalGraphics* WinSalVirtualDevice::GetGraphics()
214 if ( mbGraphics )
215 return NULL;
217 if ( mpGraphics )
218 mbGraphics = TRUE;
220 return mpGraphics;
223 // -----------------------------------------------------------------------
225 void WinSalVirtualDevice::ReleaseGraphics( SalGraphics* )
227 mbGraphics = FALSE;
230 // -----------------------------------------------------------------------
232 BOOL WinSalVirtualDevice::SetSize( long nDX, long nDY )
234 if( mbForeignDC || !mhBmp )
235 return TRUE; // ???
236 else
238 HBITMAP hNewBmp = ImplCreateVirDevBitmap( mhDC, nDX, nDY,
239 mnBitCount );
240 if ( hNewBmp )
242 SelectBitmap( mhDC, hNewBmp );
243 DeleteBitmap( mhBmp );
244 mhBmp = hNewBmp;
245 return TRUE;
247 else
249 ImplWriteLastError( GetLastError(), "ImplCreateVirDevBitmap in SetSize" );
250 return FALSE;
255 void WinSalVirtualDevice::GetSize( long& rWidth, long& rHeight )
257 rWidth = GetDeviceCaps( mhDC, HORZRES );
258 rHeight= GetDeviceCaps( mhDC, VERTRES );