Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <vcl/sysdata.hxx>
22 :
23 : #include <prex.h>
24 : #include <X11/extensions/Xrender.h>
25 : #include <postx.h>
26 :
27 : #include <unx/salunx.h>
28 : #include <unx/saldata.hxx>
29 : #include <unx/saldisp.hxx>
30 : #include <unx/salgdi.h>
31 : #include <unx/salvd.h>
32 : #include <unx/x11/xlimits.hxx>
33 :
34 : #include <salinst.hxx>
35 :
36 0 : SalVirtualDevice* X11SalInstance::CreateVirtualDevice( SalGraphics* pGraphics,
37 : long nDX, long nDY,
38 : sal_uInt16 nBitCount, const SystemGraphicsData *pData )
39 : {
40 0 : X11SalVirtualDevice *pVDev = new X11SalVirtualDevice();
41 0 : if( !nBitCount && pGraphics )
42 0 : nBitCount = pGraphics->GetBitCount();
43 :
44 0 : if( pData && pData->hDrawable != None )
45 : {
46 : XLIB_Window aRoot;
47 : int x, y;
48 0 : unsigned int w = 0, h = 0, bw, d;
49 0 : Display* pDisp = GetGenericData()->GetSalDisplay()->GetDisplay();
50 : XGetGeometry( pDisp, pData->hDrawable,
51 0 : &aRoot, &x, &y, &w, &h, &bw, &d );
52 0 : int nScreen = 0;
53 0 : while( nScreen < ScreenCount( pDisp ) )
54 : {
55 0 : if( RootWindow( pDisp, nScreen ) == aRoot )
56 0 : break;
57 0 : nScreen++;
58 : }
59 0 : nDX = (long)w;
60 0 : nDY = (long)h;
61 0 : if( !pVDev->Init( GetGenericData()->GetSalDisplay(), nDX, nDY, nBitCount,
62 : SalX11Screen( nScreen ), pData->hDrawable,
63 0 : static_cast< XRenderPictFormat* >( pData->pXRenderFormat )) )
64 : {
65 0 : delete pVDev;
66 0 : return NULL;
67 0 : }
68 : }
69 0 : else if( !pVDev->Init( GetGenericData()->GetSalDisplay(), nDX, nDY, nBitCount,
70 : pGraphics ? static_cast<X11SalGraphics*>(pGraphics)->GetScreenNumber() :
71 0 : GetGenericData()->GetSalDisplay()->GetDefaultXScreen() ) )
72 : {
73 0 : delete pVDev;
74 0 : return NULL;
75 : }
76 :
77 0 : pVDev->InitGraphics( pVDev );
78 0 : return pVDev;
79 : }
80 :
81 0 : void X11SalInstance::DestroyVirtualDevice( SalVirtualDevice* pDevice )
82 : {
83 0 : delete pDevice;
84 0 : }
85 :
86 0 : void X11SalGraphics::Init( X11SalVirtualDevice *pDevice, SalColormap* pColormap,
87 : bool bDeleteColormap )
88 : {
89 0 : SalColormap *pOrigDeleteColormap = m_pDeleteColormap;
90 :
91 0 : SalDisplay *pDisplay = pDevice->GetDisplay();
92 0 : m_nXScreen = pDevice->GetXScreenNumber();
93 :
94 0 : int nVisualDepth = pDisplay->GetColormap( m_nXScreen ).GetVisual().GetDepth();
95 0 : int nDeviceDepth = pDevice->GetDepth();
96 :
97 0 : if( pColormap )
98 : {
99 0 : m_pColormap = pColormap;
100 0 : if( bDeleteColormap )
101 0 : m_pDeleteColormap = pColormap;
102 : }
103 0 : else if( nDeviceDepth == nVisualDepth )
104 0 : m_pColormap = &pDisplay->GetColormap( m_nXScreen );
105 0 : else if( nDeviceDepth == 1 )
106 0 : m_pColormap = m_pDeleteColormap = new SalColormap();
107 :
108 0 : if (m_pDeleteColormap != pOrigDeleteColormap)
109 0 : delete pOrigDeleteColormap;
110 :
111 0 : const Drawable aVdevDrawable = pDevice->GetDrawable();
112 0 : SetDrawable( aVdevDrawable, m_nXScreen );
113 :
114 0 : m_pVDev = pDevice;
115 0 : m_pFrame = NULL;
116 :
117 0 : bWindow_ = pDisplay->IsDisplay();
118 0 : bVirDev_ = sal_True;
119 0 : }
120 :
121 0 : sal_Bool X11SalVirtualDevice::Init( SalDisplay *pDisplay,
122 : long nDX, long nDY,
123 : sal_uInt16 nBitCount,
124 : SalX11Screen nXScreen,
125 : Pixmap hDrawable,
126 : XRenderPictFormat* pXRenderFormat )
127 : {
128 0 : SalColormap* pColormap = NULL;
129 0 : bool bDeleteColormap = false;
130 :
131 0 : pDisplay_ = pDisplay;
132 0 : pGraphics_ = new X11SalGraphics();
133 0 : m_nXScreen = nXScreen;
134 0 : if( pXRenderFormat ) {
135 0 : pGraphics_->SetXRenderFormat( pXRenderFormat );
136 0 : if( pXRenderFormat->colormap )
137 0 : pColormap = new SalColormap( pDisplay, pXRenderFormat->colormap, m_nXScreen );
138 : else
139 0 : pColormap = new SalColormap( nBitCount );
140 0 : bDeleteColormap = true;
141 : }
142 0 : else if( nBitCount != pDisplay->GetVisual( m_nXScreen ).GetDepth() )
143 : {
144 0 : pColormap = new SalColormap( nBitCount );
145 0 : bDeleteColormap = true;
146 : }
147 0 : pGraphics_->SetLayout( 0 ); // by default no! mirroring for VirtualDevices, can be enabled with EnableRTL()
148 0 : nDX_ = nDX;
149 0 : nDY_ = nDY;
150 0 : nDepth_ = nBitCount;
151 :
152 0 : if( hDrawable == None )
153 : hDrawable_ = limitXCreatePixmap( GetXDisplay(),
154 : pDisplay_->GetDrawable( m_nXScreen ),
155 : nDX_, nDY_,
156 0 : GetDepth() );
157 : else
158 : {
159 0 : hDrawable_ = hDrawable;
160 0 : bExternPixmap_ = sal_True;
161 : }
162 :
163 0 : pGraphics_->Init( this, pColormap, bDeleteColormap );
164 :
165 0 : return hDrawable_ != None ? sal_True : sal_False;
166 : }
167 :
168 0 : X11SalVirtualDevice::X11SalVirtualDevice() :
169 0 : m_nXScreen( 0 )
170 : {
171 0 : pDisplay_ = NULL;
172 0 : pGraphics_ = NULL;
173 0 : hDrawable_ = None;
174 0 : nDX_ = 0;
175 0 : nDY_ = 0;
176 0 : nDepth_ = 0;
177 0 : bGraphics_ = sal_False;
178 0 : bExternPixmap_ = sal_False;
179 0 : }
180 :
181 0 : X11SalVirtualDevice::~X11SalVirtualDevice()
182 : {
183 0 : if( pGraphics_ )
184 0 : delete pGraphics_;
185 0 : pGraphics_ = NULL;
186 :
187 0 : if( GetDrawable() && !bExternPixmap_ )
188 0 : XFreePixmap( GetXDisplay(), GetDrawable() );
189 0 : }
190 :
191 0 : SalGraphics* X11SalVirtualDevice::GetGraphics()
192 : {
193 0 : if( bGraphics_ )
194 0 : return NULL;
195 :
196 0 : if( pGraphics_ )
197 0 : bGraphics_ = sal_True;
198 :
199 0 : return pGraphics_;
200 : }
201 :
202 0 : void X11SalVirtualDevice::ReleaseGraphics( SalGraphics* )
203 0 : { bGraphics_ = sal_False; }
204 :
205 0 : sal_Bool X11SalVirtualDevice::SetSize( long nDX, long nDY )
206 : {
207 0 : if( bExternPixmap_ )
208 0 : return sal_False;
209 :
210 0 : if( !nDX ) nDX = 1;
211 0 : if( !nDY ) nDY = 1;
212 :
213 : Pixmap h = limitXCreatePixmap( GetXDisplay(),
214 : pDisplay_->GetDrawable( m_nXScreen ),
215 0 : nDX, nDY, nDepth_ );
216 :
217 0 : if( !h )
218 : {
219 0 : if( !GetDrawable() )
220 : {
221 : hDrawable_ = limitXCreatePixmap( GetXDisplay(),
222 : pDisplay_->GetDrawable( m_nXScreen ),
223 0 : 1, 1, nDepth_ );
224 0 : nDX_ = 1;
225 0 : nDY_ = 1;
226 : }
227 0 : return sal_False;
228 : }
229 :
230 0 : if( GetDrawable() )
231 0 : XFreePixmap( GetXDisplay(), GetDrawable() );
232 0 : hDrawable_ = h;
233 :
234 0 : nDX_ = nDX;
235 0 : nDY_ = nDY;
236 :
237 0 : if( pGraphics_ )
238 0 : InitGraphics( this );
239 :
240 0 : return sal_True;
241 : }
242 :
243 0 : void X11SalVirtualDevice::GetSize( long& rWidth, long& rHeight )
244 : {
245 0 : rWidth = GetWidth();
246 0 : rHeight = GetHeight();
247 0 : }
248 :
249 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|