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"
34 #include <tools/prex.h>
35 #include <X11/extensions/Xrender.h>
36 #include <tools/postx.h>
39 #include <saldata.hxx>
40 #include <saldisp.hxx>
41 #include <vcl/salinst.hxx>
44 #include <vcl/sysdata.hxx>
46 // -=-= SalInstance =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
47 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
48 SalVirtualDevice
* X11SalInstance::CreateVirtualDevice( SalGraphics
* pGraphics
,
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
)
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
);
65 while( nScreen
< ScreenCount( pDisp
) )
67 if( RootWindow( pDisp
, nScreen
) == aRoot
)
73 if( !pVDev
->Init( GetX11SalData()->GetDisplay(), nDX
, nDY
, nBitCount
, nScreen
, pData
->hDrawable
, pData
->pRenderFormat
) )
79 else if( !pVDev
->Init( GetX11SalData()->GetDisplay(), nDX
, nDY
, nBitCount
,
80 pGraphics
? static_cast<X11SalGraphics
*>(pGraphics
)->GetScreenNumber() :
81 GetX11SalData()->GetDisplay()->GetDefaultScreenNumber() ) )
87 pVDev
->InitGraphics( pVDev
);
91 void X11SalInstance::DestroyVirtualDevice( SalVirtualDevice
* 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();
110 m_pColormap
= pColormap
;
111 if( bDeleteColormap
)
112 m_pDeleteColormap
= pColormap
;
115 if( nDeviceDepth
== nVisualDepth
)
116 m_pColormap
= &pDisplay
->GetColormap( m_nScreen
);
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
);
130 bWindow_
= pDisplay
->IsDisplay();
134 // -=-= SalVirDevData / SalVirtualDevice -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
135 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
136 BOOL
X11SalVirtualDevice::Init( SalDisplay
*pDisplay
,
141 void* pRenderFormatVoid
)
143 SalColormap
* pColormap
= NULL
;
144 bool bDeleteColormap
= false;
146 pDisplay_
= pDisplay
;
147 pGraphics_
= new X11SalGraphics();
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
);
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()
168 if( hDrawable
== None
)
169 hDrawable_
= XCreatePixmap( GetXDisplay(),
170 pDisplay_
->GetDrawable( m_nScreen
),
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
;
194 bExternPixmap_
= FALSE
;
197 // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
198 X11SalVirtualDevice::~X11SalVirtualDevice()
204 if( GetDrawable() && !bExternPixmap_
)
205 XFreePixmap( GetXDisplay(), GetDrawable() );
208 SalGraphics
* X11SalVirtualDevice::GetGraphics()
219 void X11SalVirtualDevice::ReleaseGraphics( SalGraphics
* )
220 { bGraphics_
= FALSE
; }
222 BOOL
X11SalVirtualDevice::SetSize( long nDX
, long nDY
)
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 )
240 Pixmap h
= XCreatePixmap( GetXDisplay(),
241 pDisplay_
->GetDrawable( m_nScreen
),
248 hDrawable_
= XCreatePixmap( GetXDisplay(),
249 pDisplay_
->GetDrawable( m_nScreen
),
258 XFreePixmap( GetXDisplay(), GetDrawable() );
265 InitGraphics( this );
270 void X11SalVirtualDevice::GetSize( long& rWidth
, long& rHeight
)
273 rHeight
= GetHeight();