merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / source / gdi / salvd.cxx
blob54422a139f1788350aa493a94fcebca61a561827
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.21 $
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"
34 #include <tools/prex.h>
35 #include <X11/extensions/Xrender.h>
36 #include <tools/postx.h>
38 #include <salunx.h>
39 #include <saldata.hxx>
40 #include <saldisp.hxx>
41 #include <vcl/salinst.hxx>
42 #include <salgdi.h>
43 #include <salvd.h>
44 #include <vcl/sysdata.hxx>
46 // -=-= SalInstance =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
47 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
48 SalVirtualDevice* X11SalInstance::CreateVirtualDevice( SalGraphics* pGraphics,
49 long nDX, long nDY,
50 USHORT nBitCount, const SystemGraphicsData *pData )
52 X11SalVirtualDevice *pVDev = new X11SalVirtualDevice();
53 if( !nBitCount && pGraphics )
54 nBitCount = pGraphics->GetBitCount();
56 if( pData && pData->hDrawable != None )
58 XLIB_Window aRoot;
59 int x, y;
60 unsigned int w = 0, h = 0, bw, d;
61 Display* pDisp = GetX11SalData()->GetDisplay()->GetDisplay();
62 XGetGeometry( pDisp, pData->hDrawable,
63 &aRoot, &x, &y, &w, &h, &bw, &d );
64 int nScreen = 0;
65 while( nScreen < ScreenCount( pDisp ) )
67 if( RootWindow( pDisp, nScreen ) == aRoot )
68 break;
69 nScreen++;
71 nDX = (long)w;
72 nDY = (long)h;
73 if( !pVDev->Init( GetX11SalData()->GetDisplay(), nDX, nDY, nBitCount, nScreen, pData->hDrawable, pData->pRenderFormat ) )
75 delete pVDev;
76 return NULL;
79 else if( !pVDev->Init( GetX11SalData()->GetDisplay(), nDX, nDY, nBitCount,
80 pGraphics ? static_cast<X11SalGraphics*>(pGraphics)->GetScreenNumber() :
81 GetX11SalData()->GetDisplay()->GetDefaultScreenNumber() ) )
83 delete pVDev;
84 return NULL;
87 pVDev->InitGraphics( pVDev );
88 return pVDev;
91 void X11SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice )
93 delete pDevice;
96 // -=-= SalGraphicsData =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
97 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
98 void X11SalGraphics::Init( X11SalVirtualDevice *pDevice, SalColormap* pColormap, bool bDeleteColormap )
100 SalColormap *pOrigDeleteColormap = m_pDeleteColormap;
102 SalDisplay *pDisplay = pDevice->GetDisplay();
103 m_nScreen = pDevice->GetScreenNumber();
105 int nVisualDepth = pDisplay->GetColormap( m_nScreen ).GetVisual().GetDepth();
106 int nDeviceDepth = pDevice->GetDepth();
108 if( pColormap )
110 m_pColormap = pColormap;
111 if( bDeleteColormap )
112 m_pDeleteColormap = pColormap;
114 else
115 if( nDeviceDepth == nVisualDepth )
116 m_pColormap = &pDisplay->GetColormap( m_nScreen );
117 else
118 if( nDeviceDepth == 1 )
119 m_pColormap = m_pDeleteColormap = new SalColormap();
121 if (m_pDeleteColormap != pOrigDeleteColormap)
122 delete pOrigDeleteColormap;
124 const Drawable aVdevDrawable = pDevice->GetDrawable();
125 SetDrawable( aVdevDrawable, m_nScreen );
127 m_pVDev = pDevice;
128 m_pFrame = NULL;
130 bWindow_ = pDisplay->IsDisplay();
131 bVirDev_ = TRUE;
134 // -=-= SalVirDevData / SalVirtualDevice -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
135 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
136 BOOL X11SalVirtualDevice::Init( SalDisplay *pDisplay,
137 long nDX, long nDY,
138 USHORT nBitCount,
139 int nScreen,
140 Pixmap hDrawable,
141 void* pRenderFormatVoid )
143 SalColormap* pColormap = NULL;
144 bool bDeleteColormap = false;
146 pDisplay_ = pDisplay;
147 pGraphics_ = new X11SalGraphics();
148 m_nScreen = nScreen;
149 if( pRenderFormatVoid ) {
150 XRenderPictFormat *pRenderFormat = ( XRenderPictFormat* )pRenderFormatVoid;
151 pGraphics_->SetXRenderFormat( pRenderFormat );
152 if( pRenderFormat->colormap )
153 pColormap = new SalColormap( pDisplay, pRenderFormat->colormap, m_nScreen );
154 else
155 pColormap = new SalColormap( nBitCount );
156 bDeleteColormap = true;
158 else if( nBitCount != pDisplay->GetVisual( m_nScreen ).GetDepth() )
160 pColormap = new SalColormap( nBitCount );
161 bDeleteColormap = true;
163 pGraphics_->SetLayout( 0 ); // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
164 nDX_ = nDX;
165 nDY_ = nDY;
166 nDepth_ = nBitCount;
168 if( hDrawable == None )
169 hDrawable_ = XCreatePixmap( GetXDisplay(),
170 pDisplay_->GetDrawable( m_nScreen ),
171 nDX_, nDY_,
172 GetDepth() );
173 else
175 hDrawable_ = hDrawable;
176 bExternPixmap_ = TRUE;
179 pGraphics_->Init( this, pColormap, bDeleteColormap );
181 return hDrawable_ != None ? TRUE : FALSE;
184 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
185 X11SalVirtualDevice::X11SalVirtualDevice()
187 pDisplay_ = (SalDisplay*)ILLEGAL_POINTER;
188 pGraphics_ = NULL;
189 hDrawable_ = None;
190 nDX_ = 0;
191 nDY_ = 0;
192 nDepth_ = 0;
193 bGraphics_ = FALSE;
194 bExternPixmap_ = FALSE;
197 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
198 X11SalVirtualDevice::~X11SalVirtualDevice()
200 if( pGraphics_ )
201 delete pGraphics_;
202 pGraphics_ = NULL;
204 if( GetDrawable() && !bExternPixmap_ )
205 XFreePixmap( GetXDisplay(), GetDrawable() );
208 SalGraphics* X11SalVirtualDevice::GetGraphics()
210 if( bGraphics_ )
211 return NULL;
213 if( pGraphics_ )
214 bGraphics_ = TRUE;
216 return pGraphics_;
219 void X11SalVirtualDevice::ReleaseGraphics( SalGraphics* )
220 { bGraphics_ = FALSE; }
222 BOOL X11SalVirtualDevice::SetSize( long nDX, long nDY )
224 if( bExternPixmap_ )
225 return FALSE;
227 // #144688#
228 // the X protocol request CreatePixmap puts an upper bound
229 // of 16 bit to the size. Beyond that there may be implementation
230 // limits of the Xserver; which we should catch by a failed XCreatePixmap
231 // call. However extra large values should be caught here since we'd run into
232 // 16 bit truncation here without noticing.
233 if( nDX < 0 || nDX > 65535 ||
234 nDY < 0 || nDY > 65535 )
235 return FALSE;
237 if( !nDX ) nDX = 1;
238 if( !nDY ) nDY = 1;
240 Pixmap h = XCreatePixmap( GetXDisplay(),
241 pDisplay_->GetDrawable( m_nScreen ),
242 nDX, nDY, nDepth_ );
244 if( !h )
246 if( !GetDrawable() )
248 hDrawable_ = XCreatePixmap( GetXDisplay(),
249 pDisplay_->GetDrawable( m_nScreen ),
250 1, 1, nDepth_ );
251 nDX_ = 1;
252 nDY_ = 1;
254 return FALSE;
257 if( GetDrawable() )
258 XFreePixmap( GetXDisplay(), GetDrawable() );
259 hDrawable_ = h;
261 nDX_ = nDX;
262 nDY_ = nDY;
264 if( pGraphics_ )
265 InitGraphics( this );
267 return TRUE;
270 void X11SalVirtualDevice::GetSize( long& rWidth, long& rHeight )
272 rWidth = GetWidth();
273 rHeight = GetHeight();