Bump version to 4.1-6
[LibreOffice.git] / vcl / win / source / gdi / salvd.cxx
blob28d0f36f78bdba9c1fe876525170a853ad83e111
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svsys.h>
23 #include <vcl/sysdata.hxx>
25 #include <win/wincomp.hxx>
26 #include <win/saldata.hxx>
27 #include <win/salinst.h>
28 #include <win/salgdi.h>
29 #include <win/salvd.h>
31 // =======================================================================
33 static HBITMAP ImplCreateVirDevBitmap( HDC hDC, long nDX, long nDY,
34 sal_uInt16 nBitCount )
36 HBITMAP hBitmap;
38 if ( nBitCount == 1 )
40 hBitmap = CreateBitmap( (int)nDX, (int)nDY, 1, 1, NULL );
42 else
44 // #146839# Don't use CreateCompatibleBitmap() - there seem to
45 // be build-in limits for those HBITMAPs, at least this fails
46 // rather often on large displays/multi-monitor setups.
47 BITMAPINFO aBitmapInfo;
48 aBitmapInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
49 aBitmapInfo.bmiHeader.biWidth = nDX;
50 aBitmapInfo.bmiHeader.biHeight = nDY;
51 aBitmapInfo.bmiHeader.biPlanes = 1;
52 aBitmapInfo.bmiHeader.biBitCount = (WORD)GetDeviceCaps( hDC,
53 BITSPIXEL );
54 aBitmapInfo.bmiHeader.biCompression = BI_RGB;
55 aBitmapInfo.bmiHeader.biSizeImage = 0;
56 aBitmapInfo.bmiHeader.biXPelsPerMeter = 0;
57 aBitmapInfo.bmiHeader.biYPelsPerMeter = 0;
58 aBitmapInfo.bmiHeader.biClrUsed = 0;
59 aBitmapInfo.bmiHeader.biClrImportant = 0;
61 void* pDummy;
62 hBitmap = CreateDIBSection( hDC, &aBitmapInfo,
63 DIB_RGB_COLORS, &pDummy, NULL,
64 0 );
67 return hBitmap;
70 // =======================================================================
72 SalVirtualDevice* WinSalInstance::CreateVirtualDevice( SalGraphics* pSGraphics,
73 long nDX, long nDY,
74 sal_uInt16 nBitCount,
75 const SystemGraphicsData* pData )
77 WinSalGraphics* pGraphics = static_cast<WinSalGraphics*>(pSGraphics);
79 HDC hDC = NULL;
80 HBITMAP hBmp = NULL;
81 sal_Bool bOk = FALSE;
83 if( pData )
85 hDC = pData->hDC;
86 hBmp = NULL;
87 bOk = (hDC != NULL);
89 else
91 hDC = CreateCompatibleDC( pGraphics->mhDC );
92 if( !hDC )
93 ImplWriteLastError( GetLastError(), "CreateCompatibleDC in CreateVirtualDevice" );
95 hBmp = ImplCreateVirDevBitmap( pGraphics->mhDC,
96 nDX, nDY, nBitCount );
97 if( !hBmp )
98 ImplWriteLastError( GetLastError(), "ImplCreateVirDevBitmap in CreateVirtualDevice" );
99 // #124826# continue even if hBmp could not be created
100 // if we would return a failure in this case, the process
101 // would terminate which is not required
103 DBG_ASSERT( hBmp, "WinSalInstance::CreateVirtualDevice(), could not create Bitmap!" );
105 bOk = (hDC != NULL);
108 if ( bOk )
110 WinSalVirtualDevice* pVDev = new WinSalVirtualDevice;
111 SalData* pSalData = GetSalData();
112 WinSalGraphics* pVirGraphics = new WinSalGraphics;
113 pVirGraphics->SetLayout( 0 ); // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
114 pVirGraphics->mhDC = hDC;
115 pVirGraphics->mhWnd = 0;
116 pVirGraphics->mbPrinter = FALSE;
117 pVirGraphics->mbVirDev = TRUE;
118 pVirGraphics->mbWindow = FALSE;
119 pVirGraphics->mbScreen = pGraphics->mbScreen;
120 if ( pSalData->mhDitherPal && pVirGraphics->mbScreen )
122 pVirGraphics->mhDefPal = SelectPalette( hDC, pSalData->mhDitherPal, TRUE );
123 RealizePalette( hDC );
125 ImplSalInitGraphics( pVirGraphics );
127 pVDev->mhDC = hDC;
128 pVDev->mhBmp = hBmp;
129 if( hBmp )
130 pVDev->mhDefBmp = SelectBitmap( hDC, hBmp );
131 else
132 pVDev->mhDefBmp = NULL;
133 pVDev->mpGraphics = pVirGraphics;
134 pVDev->mnBitCount = nBitCount;
135 pVDev->mbGraphics = FALSE;
136 pVDev->mbForeignDC = (pData != NULL);
138 // insert VirDev in VirDevList
139 pVDev->mpNext = pSalData->mpFirstVD;
140 pSalData->mpFirstVD = pVDev;
142 return pVDev;
144 else
146 if ( hDC && !pData )
147 DeleteDC( hDC );
148 if ( hBmp )
149 DeleteBitmap( hBmp );
150 return NULL;
154 // -----------------------------------------------------------------------
156 void WinSalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice )
158 delete pDevice;
161 // =======================================================================
163 WinSalVirtualDevice::WinSalVirtualDevice()
165 mhDC = (HDC) NULL; // HDC or 0 for Cache Device
166 mhBmp = (HBITMAP) NULL; // Memory Bitmap
167 mhDefBmp = (HBITMAP) NULL; // Default Bitmap
168 mpGraphics = NULL; // current VirDev graphics
169 mpNext = NULL; // next VirDev
170 mnBitCount = 0; // BitCount (0 or 1)
171 mbGraphics = FALSE; // is Graphics used
172 mbForeignDC = FALSE; // uses a foreign DC instead of a bitmap
175 // -----------------------------------------------------------------------
177 WinSalVirtualDevice::~WinSalVirtualDevice()
179 // remove VirDev from list of virtual devices
180 SalData* pSalData = GetSalData();
181 WinSalVirtualDevice** ppVirDev = &pSalData->mpFirstVD;
182 for(; (*ppVirDev != this) && *ppVirDev; ppVirDev = &(*ppVirDev)->mpNext );
183 if( *ppVirDev )
184 *ppVirDev = mpNext;
186 // destroy saved DC
187 if( mpGraphics->mhDefPal )
188 SelectPalette( mpGraphics->mhDC, mpGraphics->mhDefPal, TRUE );
189 ImplSalDeInitGraphics( mpGraphics );
190 if( mhDefBmp )
191 SelectBitmap( mpGraphics->mhDC, mhDefBmp );
192 if( !mbForeignDC )
193 DeleteDC( mpGraphics->mhDC );
194 if( mhBmp )
195 DeleteBitmap( mhBmp );
196 delete mpGraphics;
197 mpGraphics = NULL;
200 // -----------------------------------------------------------------------
202 SalGraphics* WinSalVirtualDevice::GetGraphics()
204 if ( mbGraphics )
205 return NULL;
207 if ( mpGraphics )
208 mbGraphics = TRUE;
210 return mpGraphics;
213 // -----------------------------------------------------------------------
215 void WinSalVirtualDevice::ReleaseGraphics( SalGraphics* )
217 mbGraphics = FALSE;
220 // -----------------------------------------------------------------------
222 sal_Bool WinSalVirtualDevice::SetSize( long nDX, long nDY )
224 if( mbForeignDC || !mhBmp )
225 return TRUE; // ???
226 else
228 HBITMAP hNewBmp = ImplCreateVirDevBitmap( mhDC, nDX, nDY,
229 mnBitCount );
230 if ( hNewBmp )
232 SelectBitmap( mhDC, hNewBmp );
233 DeleteBitmap( mhBmp );
234 mhBmp = hNewBmp;
235 return TRUE;
237 else
239 ImplWriteLastError( GetLastError(), "ImplCreateVirDevBitmap in SetSize" );
240 return FALSE;
245 void WinSalVirtualDevice::GetSize( long& rWidth, long& rHeight )
247 rWidth = GetDeviceCaps( mhDC, HORZRES );
248 rHeight= GetDeviceCaps( mhDC, VERTRES );
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */