1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salvd.cxx,v $
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>
39 #include <vcl/sysdata.hxx>
41 // =======================================================================
43 static HBITMAP
ImplCreateVirDevBitmap( HDC hDC
, long nDX
, long nDY
,
50 hBitmap
= CreateBitmap( (int)nDX
, (int)nDY
, 1, 1, NULL
);
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
,
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;
72 hBitmap
= CreateDIBSection( hDC
, &aBitmapInfo
,
73 DIB_RGB_COLORS
, &pDummy
, NULL
,
80 // =======================================================================
82 SalVirtualDevice
* WinSalInstance::CreateVirtualDevice( SalGraphics
* pSGraphics
,
85 const SystemGraphicsData
* pData
)
87 WinSalGraphics
* pGraphics
= static_cast<WinSalGraphics
*>(pSGraphics
);
101 hDC
= CreateCompatibleDC( pGraphics
->mhDC
);
103 ImplWriteLastError( GetLastError(), "CreateCompatibleDC in CreateVirtualDevice" );
105 hBmp
= ImplCreateVirDevBitmap( pGraphics
->mhDC
,
106 nDX
, nDY
, nBitCount
);
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!" );
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
);
140 pVDev
->mhDefBmp
= SelectBitmap( hDC
, hBmp
);
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
;
159 DeleteBitmap( hBmp
);
164 // -----------------------------------------------------------------------
166 void WinSalInstance::DestroyVirtualDevice( SalVirtualDevice
* 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
);
197 if( mpGraphics
->mhDefPal
)
198 SelectPalette( mpGraphics
->mhDC
, mpGraphics
->mhDefPal
, TRUE
);
199 ImplSalDeInitGraphics( mpGraphics
);
201 SelectBitmap( mpGraphics
->mhDC
, mhDefBmp
);
203 DeleteDC( mpGraphics
->mhDC
);
205 DeleteBitmap( mhBmp
);
210 // -----------------------------------------------------------------------
212 SalGraphics
* WinSalVirtualDevice::GetGraphics()
223 // -----------------------------------------------------------------------
225 void WinSalVirtualDevice::ReleaseGraphics( SalGraphics
* )
230 // -----------------------------------------------------------------------
232 BOOL
WinSalVirtualDevice::SetSize( long nDX
, long nDY
)
234 if( mbForeignDC
|| !mhBmp
)
238 HBITMAP hNewBmp
= ImplCreateVirDevBitmap( mhDC
, nDX
, nDY
,
242 SelectBitmap( mhDC
, hNewBmp
);
243 DeleteBitmap( mhBmp
);
249 ImplWriteLastError( GetLastError(), "ImplCreateVirDevBitmap in SetSize" );
255 void WinSalVirtualDevice::GetSize( long& rWidth
, long& rHeight
)
257 rWidth
= GetDeviceCaps( mhDC
, HORZRES
);
258 rHeight
= GetDeviceCaps( mhDC
, VERTRES
);