1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
)
40 hBitmap
= CreateBitmap( (int)nDX
, (int)nDY
, 1, 1, NULL
);
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
,
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;
62 hBitmap
= CreateDIBSection( hDC
, &aBitmapInfo
,
63 DIB_RGB_COLORS
, &pDummy
, NULL
,
70 // =======================================================================
72 SalVirtualDevice
* WinSalInstance::CreateVirtualDevice( SalGraphics
* pSGraphics
,
75 const SystemGraphicsData
* pData
)
77 WinSalGraphics
* pGraphics
= static_cast<WinSalGraphics
*>(pSGraphics
);
91 hDC
= CreateCompatibleDC( pGraphics
->mhDC
);
93 ImplWriteLastError( GetLastError(), "CreateCompatibleDC in CreateVirtualDevice" );
95 hBmp
= ImplCreateVirDevBitmap( pGraphics
->mhDC
,
96 nDX
, nDY
, nBitCount
);
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!" );
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
);
130 pVDev
->mhDefBmp
= SelectBitmap( hDC
, hBmp
);
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
;
149 DeleteBitmap( hBmp
);
154 // -----------------------------------------------------------------------
156 void WinSalInstance::DestroyVirtualDevice( SalVirtualDevice
* 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
);
187 if( mpGraphics
->mhDefPal
)
188 SelectPalette( mpGraphics
->mhDC
, mpGraphics
->mhDefPal
, TRUE
);
189 ImplSalDeInitGraphics( mpGraphics
);
191 SelectBitmap( mpGraphics
->mhDC
, mhDefBmp
);
193 DeleteDC( mpGraphics
->mhDC
);
195 DeleteBitmap( mhBmp
);
200 // -----------------------------------------------------------------------
202 SalGraphics
* WinSalVirtualDevice::GetGraphics()
213 // -----------------------------------------------------------------------
215 void WinSalVirtualDevice::ReleaseGraphics( SalGraphics
* )
220 // -----------------------------------------------------------------------
222 sal_Bool
WinSalVirtualDevice::SetSize( long nDX
, long nDY
)
224 if( mbForeignDC
|| !mhBmp
)
228 HBITMAP hNewBmp
= ImplCreateVirDevBitmap( mhDC
, nDX
, nDY
,
232 SelectBitmap( mhDC
, hNewBmp
);
233 DeleteBitmap( mhBmp
);
239 ImplWriteLastError( GetLastError(), "ImplCreateVirDevBitmap in SetSize" );
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: */