xref: /aoo41x/main/vcl/unx/generic/app/saldisp.cxx (revision 85372600)
1c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c82f2877SAndrew Rist  * distributed with this work for additional information
6c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10c82f2877SAndrew Rist  *
11c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12c82f2877SAndrew Rist  *
13c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17c82f2877SAndrew Rist  * specific language governing permissions and limitations
18c82f2877SAndrew Rist  * under the License.
19c82f2877SAndrew Rist  *
20c82f2877SAndrew Rist  *************************************************************/
21c82f2877SAndrew Rist 
22c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define SAL_XT
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
30cdf0e10cSrcweir #include <string.h>
31cdf0e10cSrcweir #include <stdio.h>
32cdf0e10cSrcweir #include <stdlib.h>
33cdf0e10cSrcweir #include <math.h>
34cdf0e10cSrcweir #include <sys/time.h>
35cdf0e10cSrcweir #include <pthread.h>
36cdf0e10cSrcweir #include <unistd.h>
37cdf0e10cSrcweir #include <ctype.h>
38cdf0e10cSrcweir #include <string.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #if defined(SOLARIS)
41cdf0e10cSrcweir #include <sal/alloca.h>
42cdf0e10cSrcweir #include <osl/module.h>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <tools/prex.h>
46cdf0e10cSrcweir #include <X11/cursorfont.h>
47cdf0e10cSrcweir #include "unx/x11_cursors/salcursors.h"
48cdf0e10cSrcweir #include "unx/x11_cursors/invert50.h"
49cdf0e10cSrcweir #ifdef SOLARIS
50cdf0e10cSrcweir #define XK_KOREAN
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir #include <X11/keysym.h>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include <X11/Xatom.h>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #ifdef USE_XINERAMA
57cdf0e10cSrcweir #ifdef USE_XINERAMA_XORG
58cdf0e10cSrcweir #include <X11/extensions/Xinerama.h>
59cdf0e10cSrcweir #elif defined USE_XINERAMA_XSUN
60cdf0e10cSrcweir #if defined(SOLARIS) && defined(INTEL) // missing extension header in standard installation
61cdf0e10cSrcweir #define MAXFRAMEBUFFERS       16
62cdf0e10cSrcweir Bool XineramaGetState(Display*, int);
63cdf0e10cSrcweir Status XineramaGetInfo(Display*, int, XRectangle*, unsigned char*, int*);
64cdf0e10cSrcweir #else
65cdf0e10cSrcweir #include <X11/extensions/xinerama.h>
66cdf0e10cSrcweir #endif
67cdf0e10cSrcweir #else
68cdf0e10cSrcweir #error USE_XINERAMA but no xinerama version
69cdf0e10cSrcweir #endif
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #include <tools/postx.h>
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #include <unx/salunx.h>
75cdf0e10cSrcweir #include <sal/types.h>
76cdf0e10cSrcweir #include "unx/i18n_im.hxx"
77cdf0e10cSrcweir #include "unx/i18n_xkb.hxx"
78cdf0e10cSrcweir #include <unx/saldisp.hxx>
79cdf0e10cSrcweir #include <unx/saldata.hxx>
80cdf0e10cSrcweir #include <salinst.hxx>
81cdf0e10cSrcweir #include <unx/salgdi.h>
82cdf0e10cSrcweir #include <unx/salframe.h>
83cdf0e10cSrcweir #include <vcl/keycodes.hxx>
84cdf0e10cSrcweir #include <vcl/salbtype.hxx>
85cdf0e10cSrcweir #include <unx/salbmp.h>
86cdf0e10cSrcweir #ifndef _OSL_THREADMUTEX_H_
87cdf0e10cSrcweir #include <osl/mutex.h>
88cdf0e10cSrcweir #endif
89cdf0e10cSrcweir #include <unx/salobj.h>
90cdf0e10cSrcweir #include <unx/sm.hxx>
91cdf0e10cSrcweir #include <unx/wmadaptor.hxx>
92cdf0e10cSrcweir #include <unx/dtint.hxx>
93cdf0e10cSrcweir 
94cdf0e10cSrcweir #include <osl/socket.h>
95cdf0e10cSrcweir #include <poll.h>
96cdf0e10cSrcweir 
97cdf0e10cSrcweir using namespace rtl;
98cdf0e10cSrcweir using namespace vcl_sal;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
101cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
102cdf0e10cSrcweir #define PSEUDOCOLOR12
103cdf0e10cSrcweir #define PSEUDOCOLOR8
104cdf0e10cSrcweir #define TRUECOLOR24
105cdf0e10cSrcweir #define TRUECOLOR16
106cdf0e10cSrcweir #define TRUECOLOR15
107cdf0e10cSrcweir #define TRUECOLOR12
108cdf0e10cSrcweir #define TRUECOLOR8
109cdf0e10cSrcweir 
110cdf0e10cSrcweir #define SALCOLOR_WHITE      MAKE_SALCOLOR( 0xFF, 0xFF, 0xFF )
111cdf0e10cSrcweir #define SALCOLOR_BLACK      MAKE_SALCOLOR( 0x00, 0x00, 0x00 )
112cdf0e10cSrcweir 
113cdf0e10cSrcweir // -=-= Prototyps =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
114cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
115cdf0e10cSrcweir // -=-= static variables -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
116cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
117cdf0e10cSrcweir static const char* const VisualClassName[] = {
118cdf0e10cSrcweir     "StaticGray",
119cdf0e10cSrcweir     "GrayScale",
120cdf0e10cSrcweir     "StaticColor",
121cdf0e10cSrcweir     "PseudoColor",
122cdf0e10cSrcweir     "TrueColor",
123cdf0e10cSrcweir     "DirectColor"
124cdf0e10cSrcweir };
125cdf0e10cSrcweir 
126cdf0e10cSrcweir static const char* const EventNames[] =
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     NULL,
129cdf0e10cSrcweir     NULL,
130cdf0e10cSrcweir     "KeyPress",
131cdf0e10cSrcweir     "KeyRelease",
132cdf0e10cSrcweir     "ButtonPress",
133cdf0e10cSrcweir     "ButtonRelease",
134cdf0e10cSrcweir     "MotionNotify",
135cdf0e10cSrcweir     "EnterNotify",
136cdf0e10cSrcweir     "LeaveNotify",
137cdf0e10cSrcweir     "FocusIn",
138cdf0e10cSrcweir     "FocusOut",
139cdf0e10cSrcweir     "KeymapNotify",
140cdf0e10cSrcweir     "Expose",
141cdf0e10cSrcweir     "GraphicsExpose",
142cdf0e10cSrcweir     "NoExpose",
143cdf0e10cSrcweir     "VisibilityNotify",
144cdf0e10cSrcweir     "CreateNotify",
145cdf0e10cSrcweir     "DestroyNotify",
146cdf0e10cSrcweir     "UnmapNotify",
147cdf0e10cSrcweir     "MapNotify",
148cdf0e10cSrcweir     "MapRequest",
149cdf0e10cSrcweir     "ReparentNotify",
150cdf0e10cSrcweir     "ConfigureNotify",
151cdf0e10cSrcweir     "ConfigureRequest",
152cdf0e10cSrcweir     "GravityNotify",
153cdf0e10cSrcweir     "ResizeRequest",
154cdf0e10cSrcweir     "CirculateNotify",
155cdf0e10cSrcweir     "CirculateRequest",
156cdf0e10cSrcweir     "PropertyNotify",
157cdf0e10cSrcweir     "SelectionClear",
158cdf0e10cSrcweir     "SelectionRequest",
159cdf0e10cSrcweir     "SelectionNotify",
160cdf0e10cSrcweir     "ColormapNotify",
161cdf0e10cSrcweir     "ClientMessage",
162cdf0e10cSrcweir     "MappingNotify"
163cdf0e10cSrcweir };
164cdf0e10cSrcweir 
165cdf0e10cSrcweir // -=-= global inline =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
166cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Null(const char * p)167cdf0e10cSrcweir inline const char *Null( const char *p ) { return p ? p : ""; }
GetEnv(const char * p)168cdf0e10cSrcweir inline const char *GetEnv( const char *p ) { return Null( getenv( p ) ); }
KeyStr(KeySym n)169cdf0e10cSrcweir inline const char *KeyStr( KeySym n ) { return Null( XKeysymToString( n ) ); }
170cdf0e10cSrcweir 
GetAtomName(Display * d,Atom a)171cdf0e10cSrcweir inline const char *GetAtomName( Display *d, Atom a )
172cdf0e10cSrcweir { return Null( XGetAtomName( d, a ) ); }
173cdf0e10cSrcweir 
Hypothenuse(long w,long h)174cdf0e10cSrcweir inline double Hypothenuse( long w, long h )
175cdf0e10cSrcweir { return sqrt( (double)((w*w)+(h*h)) ); }
176cdf0e10cSrcweir 
ColorDiff(int r,int g,int b)177cdf0e10cSrcweir inline int ColorDiff( int r, int g, int b )
178cdf0e10cSrcweir { return (r*r)+(g*g)+(b*b); }
179cdf0e10cSrcweir 
ColorDiff(SalColor c1,int r,int g,int b)180cdf0e10cSrcweir inline int ColorDiff( SalColor c1, int r, int g, int b )
181cdf0e10cSrcweir { return ColorDiff( (int)SALCOLOR_RED  (c1)-r,
182cdf0e10cSrcweir                     (int)SALCOLOR_GREEN(c1)-g,
183cdf0e10cSrcweir                     (int)SALCOLOR_BLUE (c1)-b ); }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir // -=-= global functions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
186cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sal_Shift(Pixel nMask)187cdf0e10cSrcweir static int sal_Shift( Pixel nMask )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     int i = 24;
190cdf0e10cSrcweir     if( nMask < 0x00010000 ) { nMask <<= 16; i -= 16; }
191cdf0e10cSrcweir     if( nMask < 0x01000000 ) { nMask <<=  8; i -=  8; }
192cdf0e10cSrcweir     if( nMask < 0x10000000 ) { nMask <<=  4; i -=  4; }
193cdf0e10cSrcweir     if( nMask < 0x40000000 ) { nMask <<=  2; i -=  2; }
194cdf0e10cSrcweir     if( nMask < 0x80000000 ) { nMask <<=  1; i -=  1; }
195cdf0e10cSrcweir     return i;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
sal_significantBits(Pixel nMask)198cdf0e10cSrcweir static int sal_significantBits( Pixel nMask )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     int nRotate = sizeof(Pixel)*4;
201cdf0e10cSrcweir     int nBits = 0;
202cdf0e10cSrcweir     while( nRotate-- )
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         if( nMask & 1 )
205cdf0e10cSrcweir             nBits++;
206cdf0e10cSrcweir         nMask >>= 1;
207cdf0e10cSrcweir     }
208cdf0e10cSrcweir     return nBits;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sal_GetVisualInfo(Display * pDisplay,XID nVID,XVisualInfo & rVI)212cdf0e10cSrcweir static sal_Bool sal_GetVisualInfo( Display *pDisplay, XID nVID, XVisualInfo &rVI )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir     int         nInfos;
215cdf0e10cSrcweir     XVisualInfo aTemplate;
216cdf0e10cSrcweir     XVisualInfo*pInfos;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     aTemplate.visualid = nVID;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     pInfos = XGetVisualInfo( pDisplay, VisualIDMask, &aTemplate, &nInfos );
221cdf0e10cSrcweir     if( !pInfos )
222cdf0e10cSrcweir         return sal_False;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     rVI = *pInfos;
225cdf0e10cSrcweir     XFree( pInfos );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     DBG_ASSERT( rVI.visualid == nVID,
228cdf0e10cSrcweir                 "sal_GetVisualInfo: could not get correct visual by visualId" );
229cdf0e10cSrcweir     return sal_True;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir // ---------------------------------------------------------------------------
233cdf0e10cSrcweir 
234cdf0e10cSrcweir // check wether displaystring is in format N.M or N. or just N
235cdf0e10cSrcweir // with N and M beeing natural numbers
236cdf0e10cSrcweir static sal_Bool
sal_IsDisplayNumber(const char * pDisplayString)237cdf0e10cSrcweir sal_IsDisplayNumber( const char *pDisplayString )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir 	if ( ! isdigit(*pDisplayString) )
240cdf0e10cSrcweir 		return sal_False;
241cdf0e10cSrcweir 	while ( isdigit(*(++pDisplayString)) )
242cdf0e10cSrcweir 		; /* do nothing */
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	if ( *pDisplayString == '.' )
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir 		while ( isdigit(*(++pDisplayString)) )
247cdf0e10cSrcweir 			; /* do nothing */
248cdf0e10cSrcweir 	}
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	return (*pDisplayString == '\0');
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir // check whether host1 and host2 point to the same ip address
254cdf0e10cSrcweir static sal_Bool
sal_EqualHosts(const OUString & Host1,const OUString & Host2)255cdf0e10cSrcweir sal_EqualHosts( const OUString& Host1, const OUString& Host2)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir 	oslSocketAddr pHostAddr1;
258cdf0e10cSrcweir 	oslSocketAddr pHostAddr2;
259cdf0e10cSrcweir 	sal_Bool bEqualAddress = sal_False;
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	if ( Host1.toChar() >= '0' && Host1.toChar() <= '9' )
262cdf0e10cSrcweir 		pHostAddr1 = osl_createInetSocketAddr( Host1.pData, 0 );
263cdf0e10cSrcweir 	else
264cdf0e10cSrcweir 		pHostAddr1 = osl_resolveHostname( Host1.pData );
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 	if ( Host2.toChar() >= '0' && Host2.toChar() <= '9' )
267cdf0e10cSrcweir 		pHostAddr2 = osl_createInetSocketAddr( Host2.pData, 0 );
268cdf0e10cSrcweir 	else
269cdf0e10cSrcweir 		pHostAddr2 = osl_resolveHostname( Host2.pData );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     if( pHostAddr1 && pHostAddr2 )
272cdf0e10cSrcweir         bEqualAddress = osl_isEqualSocketAddr( pHostAddr1, pHostAddr2 ) ? sal_True : sal_False;
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     if( pHostAddr1 )
275cdf0e10cSrcweir         osl_destroySocketAddr( pHostAddr1 );
276cdf0e10cSrcweir     if( pHostAddr2 )
277cdf0e10cSrcweir         osl_destroySocketAddr( pHostAddr2 );
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	return bEqualAddress;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir static sal_Bool
sal_IsLocalDisplay(Display * pDisplay)283cdf0e10cSrcweir sal_IsLocalDisplay( Display *pDisplay )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	const char *pDisplayString = DisplayString( pDisplay );
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	// no string, no idea
288cdf0e10cSrcweir 	if (   pDisplayString == NULL || pDisplayString[ 0 ] == '\0')
289cdf0e10cSrcweir 		return sal_False;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 	// check for ":x.y"
292cdf0e10cSrcweir 	if ( pDisplayString[ 0 ] == ':' )
293cdf0e10cSrcweir 		return sal_IsDisplayNumber( pDisplayString + 1 );
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 	// check for fixed token which all mean localhost:x.y
296cdf0e10cSrcweir 	const char  pLocal[]	= "localhost:";
297cdf0e10cSrcweir 	const int   nLocalLen 	= sizeof(pLocal) - 1;
298cdf0e10cSrcweir 	if ( strncmp(pDisplayString, pLocal, nLocalLen) == 0 )
299cdf0e10cSrcweir 		return sal_IsDisplayNumber( pDisplayString + nLocalLen );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 	const char  pUnix[]		= "unix:";
302cdf0e10cSrcweir 	const int   nUnixLen 	= sizeof(pUnix) - 1;
303cdf0e10cSrcweir 	if ( strncmp(pDisplayString, pUnix, 	 nUnixLen)      == 0 )
304cdf0e10cSrcweir 		return sal_IsDisplayNumber( pDisplayString + nUnixLen );
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 	const char  pLoopback[] = "127.0.0.1:";
307cdf0e10cSrcweir 	const int   nLoopbackLen= sizeof(pLoopback) - 1;
308cdf0e10cSrcweir 	if ( strncmp(pDisplayString, pLoopback,	 nLoopbackLen)  == 0 )
309cdf0e10cSrcweir 		return sal_IsDisplayNumber( pDisplayString + nLoopbackLen );
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 	// compare local hostname to displaystring, both may be ip address or
312cdf0e10cSrcweir 	// hostname
313cdf0e10cSrcweir 	sal_Bool  bEqual = sal_False;
314cdf0e10cSrcweir 	char *pDisplayHost 	= strdup(  pDisplayString );
315cdf0e10cSrcweir 	char *pPtr 			= strrchr( pDisplayHost, ':' );
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 	if( pPtr != NULL )
318cdf0e10cSrcweir 	{
319cdf0e10cSrcweir 		const OUString& rLocalHostname( GetX11SalData()->GetLocalHostName() );
320cdf0e10cSrcweir         if( rLocalHostname.getLength() )
321cdf0e10cSrcweir         {
322cdf0e10cSrcweir 			*pPtr = '\0';
323cdf0e10cSrcweir 			OUString aDisplayHostname( pDisplayHost, strlen( pDisplayHost ), osl_getThreadTextEncoding() );
324cdf0e10cSrcweir 			bEqual = sal_EqualHosts( rLocalHostname, aDisplayHostname );
325cdf0e10cSrcweir 			bEqual = bEqual && sal_IsDisplayNumber( pPtr + 1 );
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir 	}
328cdf0e10cSrcweir 	free( pDisplayHost );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	return bEqual;
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir // ---------------------------------------------------------------------------
334cdf0e10cSrcweir // IsLocal means soffice is running on the same host as the xserver
335cdf0e10cSrcweir // since it is not called very often and sal_IsLocalDisplay() is relative
336cdf0e10cSrcweir // expensive bLocal_ is initialized on first call
337cdf0e10cSrcweir 
IsLocal()338cdf0e10cSrcweir sal_Bool SalDisplay::IsLocal()
339cdf0e10cSrcweir {
340cdf0e10cSrcweir 	if ( ! mbLocalIsValid )
341cdf0e10cSrcweir 	{
342cdf0e10cSrcweir 		bLocal_ = sal_IsLocalDisplay( pDisp_ );
343cdf0e10cSrcweir 		mbLocalIsValid = sal_True;
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 	return (sal_Bool)bLocal_;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir // ---------------------------------------------------------------------------
349cdf0e10cSrcweir extern "C" srv_vendor_t
sal_GetServerVendor(Display * p_display)350cdf0e10cSrcweir sal_GetServerVendor( Display *p_display )
351cdf0e10cSrcweir {
352cdf0e10cSrcweir 	typedef struct {
353cdf0e10cSrcweir 		srv_vendor_t	e_vendor;	// vendor as enum
354cdf0e10cSrcweir 		const char		*p_name;	// vendor name as returned by VendorString()
355cdf0e10cSrcweir 		unsigned int	n_len;	// number of chars to compare
356cdf0e10cSrcweir 	} vendor_t;
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 	const vendor_t p_vendorlist[] = {
359cdf0e10cSrcweir 		{ vendor_xfree,       "The XFree86 Project, Inc", 		 13	},
360cdf0e10cSrcweir 		{ vendor_sun,         "Sun Microsystems, Inc.", 		 10	},
361cdf0e10cSrcweir 		{ vendor_attachmate,  "Attachmate Corporation", 		 10	},
362cdf0e10cSrcweir 		{ vendor_excursion,
363cdf0e10cSrcweir 			"DECWINDOWS DigitalEquipmentCorporation, eXcursion", 42 },
364cdf0e10cSrcweir 		{ vendor_hp,          "Hewlett-Packard Company", 		 17 },
365cdf0e10cSrcweir 		{ vendor_hummingbird, "Hummingbird Communications Ltd.", 11 },
366cdf0e10cSrcweir 		{ vendor_ibm,         "International Business Machines", 24 },
367cdf0e10cSrcweir 		{ vendor_sgi,         "Silicon Graphics",                 9 },
368cdf0e10cSrcweir 		{ vendor_sco,         "The Santa Cruz Operation", 		 16 },
369cdf0e10cSrcweir 		{ vendor_xinside,     "X Inside Inc.", 					 10	},
370cdf0e10cSrcweir 		// allways the last entry: vendor_none to indicate eol
371cdf0e10cSrcweir 		{ vendor_none, 	  	  NULL,								  0 },
372cdf0e10cSrcweir 	};
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 	// handle regular server vendors
375cdf0e10cSrcweir 	char     *p_name   = ServerVendor( p_display );
376cdf0e10cSrcweir     vendor_t *p_vendor;
377cdf0e10cSrcweir 	for (p_vendor = const_cast<vendor_t*>(p_vendorlist); p_vendor->e_vendor != vendor_none; p_vendor++)
378cdf0e10cSrcweir 	{
379cdf0e10cSrcweir 		if ( strncmp (p_name, p_vendor->p_name, p_vendor->n_len) == 0 )
380cdf0e10cSrcweir 			return p_vendor->e_vendor;
381cdf0e10cSrcweir 	}
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 	// vendor not found in list
384cdf0e10cSrcweir 	return vendor_unknown;
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
sal_IsTrustedSolaris(Display * p_display)387cdf0e10cSrcweir static sal_Bool sal_IsTrustedSolaris (Display *p_display)
388cdf0e10cSrcweir {
389cdf0e10cSrcweir     int      n_numextensions = 0;
390cdf0e10cSrcweir     char   **p_extensions    = XListExtensions (p_display, &n_numextensions);
391cdf0e10cSrcweir     sal_Bool b_is            = sal_False;
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     if (p_extensions != NULL)
394cdf0e10cSrcweir     {
395cdf0e10cSrcweir 	    for (int i = 0; !b_is && i < n_numextensions; i++)
396cdf0e10cSrcweir             b_is = (strcmp (p_extensions[i], "SUN_TSOL") == 0);
397cdf0e10cSrcweir 	    XFreeExtensionList (p_extensions);
398cdf0e10cSrcweir     }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     return b_is;
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir // -=-= SalDisplay -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
404cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BestVisual(Display * pDisplay,int nScreen,XVisualInfo & rVI)405cdf0e10cSrcweir sal_Bool SalDisplay::BestVisual( Display     *pDisplay,
406cdf0e10cSrcweir                              int          nScreen,
407cdf0e10cSrcweir                              XVisualInfo &rVI )
408cdf0e10cSrcweir {
409cdf0e10cSrcweir     VisualID nDefVID = XVisualIDFromVisual( DefaultVisual( pDisplay, nScreen ) );
410cdf0e10cSrcweir     VisualID    nVID = 0;
411cdf0e10cSrcweir     char       *pVID = getenv( "SAL_VISUAL" );
412cdf0e10cSrcweir     if( pVID )
413cdf0e10cSrcweir         sscanf( pVID, "%li", &nVID );
414cdf0e10cSrcweir 
415cdf0e10cSrcweir     if( nVID && sal_GetVisualInfo( pDisplay, nVID, rVI ) )
416cdf0e10cSrcweir         return rVI.visualid == nDefVID;
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 	XVisualInfo aVI;
419cdf0e10cSrcweir     aVI.screen = nScreen;
420cdf0e10cSrcweir 	// get all visuals
421cdf0e10cSrcweir 	int nVisuals;
422cdf0e10cSrcweir 	XVisualInfo* pVInfos = XGetVisualInfo( pDisplay, VisualScreenMask,
423cdf0e10cSrcweir 										   &aVI, &nVisuals );
424cdf0e10cSrcweir 	// pVInfos should contain at least one visual, otherwise
425cdf0e10cSrcweir 	// we're in trouble
426cdf0e10cSrcweir 	int* pWeight = (int*)alloca( sizeof(int)*nVisuals );
427cdf0e10cSrcweir 	int i;
428cdf0e10cSrcweir 	for( i = 0; i < nVisuals; i++ )
429cdf0e10cSrcweir 	{
430cdf0e10cSrcweir 		sal_Bool bUsable = sal_False;
431cdf0e10cSrcweir 		int nTrueColor = 1;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 		if ( pVInfos[i].screen != nScreen )
434cdf0e10cSrcweir 		{
435cdf0e10cSrcweir 			bUsable = sal_False;
436cdf0e10cSrcweir 		}
437cdf0e10cSrcweir 		else
438cdf0e10cSrcweir 		if( pVInfos[i].c_class == TrueColor )
439cdf0e10cSrcweir 		{
440cdf0e10cSrcweir 			nTrueColor = 2048;
441cdf0e10cSrcweir 			if( pVInfos[i].depth == 24 )
442cdf0e10cSrcweir 				bUsable = sal_True;
443cdf0e10cSrcweir #ifdef sal_TrueCOLOR8
444cdf0e10cSrcweir 			else if( pVInfos[i].depth == 8 )
445cdf0e10cSrcweir 			{
446cdf0e10cSrcweir 				nTrueColor = -1; // strongly discourage 8 bit true color
447cdf0e10cSrcweir 				bUsable = sal_True;
448cdf0e10cSrcweir 			}
449cdf0e10cSrcweir #endif
450cdf0e10cSrcweir #ifdef sal_TrueCOLOR15
451cdf0e10cSrcweir 			else if( pVInfos[i].depth == 15 )
452cdf0e10cSrcweir 				bUsable = sal_True;
453cdf0e10cSrcweir #endif
454cdf0e10cSrcweir #ifdef sal_TrueCOLOR16
455cdf0e10cSrcweir 			else if( pVInfos[i].depth == 16 )
456cdf0e10cSrcweir 				bUsable = sal_True;
457cdf0e10cSrcweir #endif
458cdf0e10cSrcweir #ifdef sal_TrueCOLOR32
459cdf0e10cSrcweir 			else if( pVInfos[i].depth == 32 )
460cdf0e10cSrcweir 			{
461cdf0e10cSrcweir 				nTrueColor = 256;
462cdf0e10cSrcweir 				// we do not have use for an alpha channel
463cdf0e10cSrcweir 				// better use a 24 or 16 bit truecolor visual if possible
464cdf0e10cSrcweir 				bUsable = sal_True;
465cdf0e10cSrcweir 			}
466cdf0e10cSrcweir #endif
467cdf0e10cSrcweir 		}
468cdf0e10cSrcweir 		else if( pVInfos[i].c_class == PseudoColor )
469cdf0e10cSrcweir 		{
470cdf0e10cSrcweir 			if( pVInfos[i].depth <= 8 )
471cdf0e10cSrcweir 				bUsable = sal_True;
472cdf0e10cSrcweir #ifdef PSEUDOCOLOR12
473cdf0e10cSrcweir 			else if( pVInfos[i].depth == 12 )
474cdf0e10cSrcweir 				bUsable = sal_True;
475cdf0e10cSrcweir #endif
476cdf0e10cSrcweir 		}
477cdf0e10cSrcweir 		pWeight[ i ] = bUsable ? nTrueColor*pVInfos[i].depth : -1024;
478cdf0e10cSrcweir 		pWeight[ i ] -= pVInfos[ i ].visualid;
479cdf0e10cSrcweir 	}
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 	int nBestVisual = 0;
482cdf0e10cSrcweir 	int nBestWeight = -1024;
483cdf0e10cSrcweir 	for( i = 0; i < nVisuals; i++ )
484cdf0e10cSrcweir 	{
485cdf0e10cSrcweir 		if( pWeight[ i ] > nBestWeight )
486cdf0e10cSrcweir 		{
487cdf0e10cSrcweir 			nBestWeight = pWeight[ i ];
488cdf0e10cSrcweir 			nBestVisual = i;
489cdf0e10cSrcweir 		}
490cdf0e10cSrcweir 	}
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	rVI = pVInfos[ nBestVisual ];
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 	XFree( pVInfos );
495cdf0e10cSrcweir 	return rVI.visualid == nDefVID;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
499cdf0e10cSrcweir 
SalDisplay(Display * display)500cdf0e10cSrcweir SalDisplay::SalDisplay( Display *display ) :
501cdf0e10cSrcweir         mpInputMethod( NULL ),
502cdf0e10cSrcweir 		pDisp_( display ),
503cdf0e10cSrcweir         m_pWMAdaptor( NULL ),
504cdf0e10cSrcweir         m_pDtIntegrator( NULL ),
505cdf0e10cSrcweir         m_bUseRandRWrapper( true ),
506cdf0e10cSrcweir         m_nLastUserEventTime( CurrentTime )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
509cdf0e10cSrcweir     fprintf( stderr, "SalDisplay::SalDisplay()\n" );
510cdf0e10cSrcweir #endif
511cdf0e10cSrcweir     X11SalData *pSalData  = GetX11SalData();
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     DBG_ASSERT( ! pSalData->GetDisplay(), "Second SalDisplay created !!!\n" );
514cdf0e10cSrcweir     pSalData->SetSalDisplay( this );
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 	pXLib_    = pSalData->GetLib();
517cdf0e10cSrcweir     m_nDefaultScreen = DefaultScreen( pDisp_ );
518cdf0e10cSrcweir 
519cdf0e10cSrcweir }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
~SalDisplay()522cdf0e10cSrcweir SalDisplay::~SalDisplay( )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
525cdf0e10cSrcweir     fprintf( stderr, "SalDisplay::~SalDisplay()\n" );
526cdf0e10cSrcweir #endif
527cdf0e10cSrcweir     if( pDisp_ )
528cdf0e10cSrcweir     {
529cdf0e10cSrcweir         doDestruct();
530cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
531cdf0e10cSrcweir         fprintf( stderr, "display %p closed\n", pDisp_ );
532cdf0e10cSrcweir #endif
533cdf0e10cSrcweir         pDisp_ = NULL;
534cdf0e10cSrcweir     }
535cdf0e10cSrcweir     // don't do this in doDestruct since RandR extension adds hooks into Display
536cdf0e10cSrcweir     // that is XCloseDisplay still needs the RandR library if it was used
537cdf0e10cSrcweir     DeInitRandR();
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
doDestruct()540cdf0e10cSrcweir void SalDisplay::doDestruct()
541cdf0e10cSrcweir {
542cdf0e10cSrcweir     X11SalData *pSalData = GetX11SalData();
543cdf0e10cSrcweir 
544cdf0e10cSrcweir     delete m_pWMAdaptor;
545cdf0e10cSrcweir     m_pWMAdaptor = NULL;
546cdf0e10cSrcweir     delete m_pDtIntegrator;
547cdf0e10cSrcweir     m_pDtIntegrator = NULL;
548cdf0e10cSrcweir 	X11SalBitmap::ImplDestroyCache();
549cdf0e10cSrcweir     X11SalGraphics::releaseGlyphPeer();
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     if( IsDisplay() )
552cdf0e10cSrcweir     {
553cdf0e10cSrcweir 		delete mpInputMethod, mpInputMethod = (SalI18N_InputMethod*)ILLEGAL_POINTER;
554cdf0e10cSrcweir 		delete mpKbdExtension, mpKbdExtension = (SalI18N_KeyboardExtension*)ILLEGAL_POINTER;
555cdf0e10cSrcweir 
556cdf0e10cSrcweir         // do not call anything that could implicitly call back into
557cdf0e10cSrcweir         // this object after this point
558cdf0e10cSrcweir         osl_destroyMutex( hEventGuard_ );
559cdf0e10cSrcweir 
560cdf0e10cSrcweir         for( unsigned int i = 0; i < m_aScreens.size(); i++ )
561cdf0e10cSrcweir         {
562cdf0e10cSrcweir             ScreenData& rData = m_aScreens[i];
563cdf0e10cSrcweir             if( rData.m_bInit )
564cdf0e10cSrcweir             {
565cdf0e10cSrcweir                 if( rData.m_aMonoGC != rData.m_aCopyGC )
566cdf0e10cSrcweir                     XFreeGC( pDisp_, rData.m_aMonoGC );
567cdf0e10cSrcweir                 XFreeGC( pDisp_, rData.m_aCopyGC );
568cdf0e10cSrcweir                 XFreeGC( pDisp_, rData.m_aAndInvertedGC );
569cdf0e10cSrcweir                 XFreeGC( pDisp_, rData.m_aAndGC );
570cdf0e10cSrcweir                 XFreeGC( pDisp_, rData.m_aOrGC );
571cdf0e10cSrcweir                 XFreeGC( pDisp_, rData.m_aStippleGC );
572cdf0e10cSrcweir                 XFreePixmap( pDisp_, rData.m_hInvert50 );
573cdf0e10cSrcweir                 XDestroyWindow( pDisp_, rData.m_aRefWindow );
574cdf0e10cSrcweir                 Colormap aColMap = rData.m_aColormap.GetXColormap();
575cdf0e10cSrcweir                 if( aColMap != None && aColMap != DefaultColormap( pDisp_, i ) )
576cdf0e10cSrcweir                     XFreeColormap( pDisp_, aColMap );
577cdf0e10cSrcweir             }
578cdf0e10cSrcweir         }
579cdf0e10cSrcweir 
580cdf0e10cSrcweir         hEventGuard_            = (oslMutex)ILLEGAL_POINTER;
581cdf0e10cSrcweir 
582cdf0e10cSrcweir         for( size_t i = 0; i < POINTER_COUNT; i++ )
583cdf0e10cSrcweir         {
584cdf0e10cSrcweir             if( aPointerCache_[i] )
585cdf0e10cSrcweir                 XFreeCursor( pDisp_, aPointerCache_[i] );
586cdf0e10cSrcweir         }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir         pXLib_->Remove( ConnectionNumber( pDisp_ ) );
589cdf0e10cSrcweir     }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     if( pSalData->GetDisplay() == this )
592cdf0e10cSrcweir         pSalData->SetSalDisplay( NULL );
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
DisplayHasEvent(int fd,SalX11Display * pDisplay)595cdf0e10cSrcweir static int DisplayHasEvent( int
596cdf0e10cSrcweir #ifdef DBG_UTIL
597cdf0e10cSrcweir fd
598cdf0e10cSrcweir #endif
599cdf0e10cSrcweir , SalX11Display *pDisplay  )
600cdf0e10cSrcweir {
601cdf0e10cSrcweir   DBG_ASSERT( ConnectionNumber( pDisplay->GetDisplay() ) == fd,
602cdf0e10cSrcweir               "wrong fd in DisplayHasEvent" );
603cdf0e10cSrcweir   if( ! pDisplay->IsDisplay() )
604cdf0e10cSrcweir       return 0;
605cdf0e10cSrcweir 
606cdf0e10cSrcweir   vos::IMutex* pSalInstYieldMutex	=
607cdf0e10cSrcweir       GetSalData()->m_pInstance->GetYieldMutex();
608cdf0e10cSrcweir   ::vos::OGuard aGuard( *pSalInstYieldMutex );
609cdf0e10cSrcweir   return pDisplay->IsEvent();
610cdf0e10cSrcweir }
DisplayQueue(int fd,SalX11Display * pDisplay)611cdf0e10cSrcweir static int DisplayQueue( int
612cdf0e10cSrcweir #ifdef DBG_UTIL
613cdf0e10cSrcweir fd
614cdf0e10cSrcweir #endif
615cdf0e10cSrcweir , SalX11Display *pDisplay )
616cdf0e10cSrcweir {
617cdf0e10cSrcweir   DBG_ASSERT( ConnectionNumber( pDisplay->GetDisplay() ) == fd,
618cdf0e10cSrcweir               "wrong fd in DisplayHasEvent" );
619cdf0e10cSrcweir   vos::IMutex* pSalInstYieldMutex	=
620cdf0e10cSrcweir       GetSalData()->m_pInstance->GetYieldMutex();
621cdf0e10cSrcweir   ::vos::OGuard aGuard( *pSalInstYieldMutex );
622cdf0e10cSrcweir   return XEventsQueued( pDisplay->GetDisplay(),
623cdf0e10cSrcweir                         QueuedAfterReading );
624cdf0e10cSrcweir }
DisplayYield(int fd,SalX11Display * pDisplay)625cdf0e10cSrcweir static int DisplayYield( int
626cdf0e10cSrcweir #ifdef DBG_UTIL
627cdf0e10cSrcweir fd
628cdf0e10cSrcweir #endif
629cdf0e10cSrcweir , SalX11Display *pDisplay )
630cdf0e10cSrcweir {
631cdf0e10cSrcweir   DBG_ASSERT( ConnectionNumber( pDisplay->GetDisplay() ) == fd,
632cdf0e10cSrcweir               "wrong fd in DisplayHasEvent" );
633cdf0e10cSrcweir   vos::IMutex* pSalInstYieldMutex	=
634cdf0e10cSrcweir       GetSalData()->m_pInstance->GetYieldMutex();
635cdf0e10cSrcweir   ::vos::OGuard aGuard( *pSalInstYieldMutex );
636cdf0e10cSrcweir   pDisplay->Yield();
637cdf0e10cSrcweir   return sal_True;
638cdf0e10cSrcweir }
639cdf0e10cSrcweir 
SalX11Display(Display * display)640cdf0e10cSrcweir SalX11Display::SalX11Display( Display *display )
641cdf0e10cSrcweir 		: SalDisplay( display )
642cdf0e10cSrcweir {
643cdf0e10cSrcweir     Init();
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 	pXLib_->Insert( ConnectionNumber( pDisp_ ),
646cdf0e10cSrcweir 					this,
647cdf0e10cSrcweir 					(YieldFunc) DisplayHasEvent,
648cdf0e10cSrcweir 					(YieldFunc) DisplayQueue,
649cdf0e10cSrcweir 					(YieldFunc) DisplayYield );
650cdf0e10cSrcweir }
651cdf0e10cSrcweir 
~SalX11Display()652cdf0e10cSrcweir SalX11Display::~SalX11Display()
653cdf0e10cSrcweir {
654cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
655cdf0e10cSrcweir     fprintf( stderr, "SalX11Display::~SalX11Display()\n" );
656cdf0e10cSrcweir #endif
657cdf0e10cSrcweir 	if( pDisp_ )
658cdf0e10cSrcweir 	{
659cdf0e10cSrcweir 		doDestruct();
660cdf0e10cSrcweir 		XCloseDisplay( pDisp_ );
661cdf0e10cSrcweir 		pDisp_ = NULL;
662cdf0e10cSrcweir 	}
663cdf0e10cSrcweir }
664cdf0e10cSrcweir 
initScreen(int nScreen) const665cdf0e10cSrcweir void SalDisplay::initScreen( int nScreen ) const
666cdf0e10cSrcweir {
667cdf0e10cSrcweir     if( nScreen < 0 || nScreen >= static_cast<int>(m_aScreens.size()) )
668cdf0e10cSrcweir         nScreen = m_nDefaultScreen;
669cdf0e10cSrcweir     ScreenData& rSD = const_cast<ScreenData&>(m_aScreens[nScreen]);
670cdf0e10cSrcweir     if( rSD.m_bInit )
671cdf0e10cSrcweir         return;
672cdf0e10cSrcweir     rSD.m_bInit = true;
673cdf0e10cSrcweir 
674cdf0e10cSrcweir     XVisualInfo aVI;
675cdf0e10cSrcweir     Colormap	aColMap;
676cdf0e10cSrcweir 
677cdf0e10cSrcweir     if( SalDisplay::BestVisual( pDisp_, nScreen, aVI ) ) // DefaultVisual
678cdf0e10cSrcweir         aColMap = DefaultColormap( pDisp_, nScreen );
679cdf0e10cSrcweir     else
680cdf0e10cSrcweir         aColMap = XCreateColormap( pDisp_,
681cdf0e10cSrcweir                                    RootWindow( pDisp_, nScreen ),
682cdf0e10cSrcweir                                    aVI.visual,
683cdf0e10cSrcweir                                    AllocNone );
684cdf0e10cSrcweir 
685cdf0e10cSrcweir     Screen* pScreen = ScreenOfDisplay( pDisp_, nScreen );
686cdf0e10cSrcweir 
687cdf0e10cSrcweir     rSD.m_aSize = Size( WidthOfScreen( pScreen ), HeightOfScreen( pScreen ) );
688cdf0e10cSrcweir     rSD.m_aRoot = RootWindow( pDisp_, nScreen );
689cdf0e10cSrcweir     rSD.m_aVisual = SalVisual( &aVI );
690cdf0e10cSrcweir     rSD.m_aColormap = SalColormap( this, aColMap, nScreen );
691cdf0e10cSrcweir 
692cdf0e10cSrcweir     // we're interested in configure notification of root windows
693cdf0e10cSrcweir     InitRandR( rSD.m_aRoot );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir     // - - - - - - - - - - Reference Window/Default Drawable - -
696cdf0e10cSrcweir     XSetWindowAttributes aXWAttributes;
697cdf0e10cSrcweir     aXWAttributes.border_pixel      = 0;
698cdf0e10cSrcweir     aXWAttributes.background_pixel  = 0;
699cdf0e10cSrcweir     aXWAttributes.colormap          = aColMap;
700cdf0e10cSrcweir     rSD.m_aRefWindow     = XCreateWindow( pDisp_,
701cdf0e10cSrcweir                                           rSD.m_aRoot,
702cdf0e10cSrcweir                                           0,0, 16,16, 0,
703cdf0e10cSrcweir                                           rSD.m_aVisual.GetDepth(),
704cdf0e10cSrcweir                                           InputOutput,
705cdf0e10cSrcweir                                           rSD.m_aVisual.GetVisual(),
706cdf0e10cSrcweir                                           CWBorderPixel|CWBackPixel|CWColormap,
707cdf0e10cSrcweir                                           &aXWAttributes );
708cdf0e10cSrcweir 
709cdf0e10cSrcweir     // set client leader (session id gets set when session is started)
710cdf0e10cSrcweir     if( rSD.m_aRefWindow )
711cdf0e10cSrcweir     {
712cdf0e10cSrcweir         // client leader must have WM_CLIENT_LEADER pointing to itself
713cdf0e10cSrcweir         XChangeProperty( pDisp_,
714cdf0e10cSrcweir                          rSD.m_aRefWindow,
715cdf0e10cSrcweir                          XInternAtom( pDisp_, "WM_CLIENT_LEADER", False ),
716cdf0e10cSrcweir                          XA_WINDOW,
717cdf0e10cSrcweir                          32,
718cdf0e10cSrcweir                          PropModeReplace,
719cdf0e10cSrcweir                          (unsigned char*)&rSD.m_aRefWindow,
720cdf0e10cSrcweir                          1
721cdf0e10cSrcweir                          );
722cdf0e10cSrcweir 
723cdf0e10cSrcweir         ByteString aExec( SessionManagerClient::getExecName(), osl_getThreadTextEncoding() );
724cdf0e10cSrcweir         const char* argv[2];
725cdf0e10cSrcweir         argv[0] = "/bin/sh";
726cdf0e10cSrcweir         argv[1] = aExec.GetBuffer();
727cdf0e10cSrcweir         XSetCommand( pDisp_, rSD.m_aRefWindow, const_cast<char**>(argv), 2 );
728cdf0e10cSrcweir         XSelectInput( pDisp_, rSD.m_aRefWindow, PropertyChangeMask );
729cdf0e10cSrcweir 
730cdf0e10cSrcweir         // - - - - - - - - - - GCs - - - - - - - - - - - - - - - - -
731cdf0e10cSrcweir         XGCValues values;
732cdf0e10cSrcweir         values.graphics_exposures   = False;
733cdf0e10cSrcweir         values.fill_style           = FillOpaqueStippled;
734cdf0e10cSrcweir         values.background       	= (1<<rSD.m_aVisual.GetDepth())-1;
735cdf0e10cSrcweir         values.foreground       	= 0;
736cdf0e10cSrcweir 
737cdf0e10cSrcweir         rSD.m_aCopyGC       = XCreateGC( pDisp_,
738cdf0e10cSrcweir                                          rSD.m_aRefWindow,
739cdf0e10cSrcweir                                          GCGraphicsExposures
740cdf0e10cSrcweir                                          | GCForeground
741cdf0e10cSrcweir                                          | GCBackground,
742cdf0e10cSrcweir                                          &values );
743cdf0e10cSrcweir         rSD.m_aAndInvertedGC= XCreateGC( pDisp_,
744cdf0e10cSrcweir                                          rSD.m_aRefWindow,
745cdf0e10cSrcweir                                          GCGraphicsExposures
746cdf0e10cSrcweir                                          | GCForeground
747cdf0e10cSrcweir                                          | GCBackground,
748cdf0e10cSrcweir                                          &values );
749cdf0e10cSrcweir         rSD.m_aAndGC        = XCreateGC( pDisp_,
750cdf0e10cSrcweir                                          rSD.m_aRefWindow,
751cdf0e10cSrcweir                                          GCGraphicsExposures
752cdf0e10cSrcweir                                          | GCForeground
753cdf0e10cSrcweir                                          | GCBackground,
754cdf0e10cSrcweir                                          &values );
755cdf0e10cSrcweir         rSD.m_aOrGC         = XCreateGC( pDisp_,
756cdf0e10cSrcweir                                          rSD.m_aRefWindow,
757cdf0e10cSrcweir                                          GCGraphicsExposures
758cdf0e10cSrcweir                                          | GCForeground
759cdf0e10cSrcweir                                          | GCBackground,
760cdf0e10cSrcweir                                          &values    );
761cdf0e10cSrcweir         rSD.m_aStippleGC    = XCreateGC( pDisp_,
762cdf0e10cSrcweir                                          rSD.m_aRefWindow,
763cdf0e10cSrcweir                                          GCGraphicsExposures
764cdf0e10cSrcweir                                          | GCFillStyle
765cdf0e10cSrcweir                                          | GCForeground
766cdf0e10cSrcweir                                          | GCBackground,
767cdf0e10cSrcweir                                          &values );
768cdf0e10cSrcweir 
769cdf0e10cSrcweir         XSetFunction( pDisp_, rSD.m_aAndInvertedGC,  GXandInverted );
770cdf0e10cSrcweir         XSetFunction( pDisp_, rSD.m_aAndGC,          GXand );
771cdf0e10cSrcweir         // #44556# PowerPC Solaris 2.5 (XSun 3500) Bug: GXor = GXnop
772cdf0e10cSrcweir         //XSetFunction( pDisp_, pOrGC_,         GXor );
773cdf0e10cSrcweir         XSetFunction( pDisp_, rSD.m_aOrGC,           GXxor );
774cdf0e10cSrcweir 
775cdf0e10cSrcweir         if( 1 == rSD.m_aVisual.GetDepth() )
776cdf0e10cSrcweir         {
777cdf0e10cSrcweir             XSetFunction( pDisp_, rSD.m_aCopyGC, GXcopyInverted );
778cdf0e10cSrcweir             rSD.m_aMonoGC = rSD.m_aCopyGC;
779cdf0e10cSrcweir         }
780cdf0e10cSrcweir         else
781cdf0e10cSrcweir         {
782cdf0e10cSrcweir             Pixmap hPixmap = XCreatePixmap( pDisp_, rSD.m_aRefWindow, 1, 1, 1 );
783cdf0e10cSrcweir             rSD.m_aMonoGC = XCreateGC( pDisp_,
784cdf0e10cSrcweir                                        hPixmap,
785cdf0e10cSrcweir                                        GCGraphicsExposures,
786cdf0e10cSrcweir                                        &values );
787cdf0e10cSrcweir             XFreePixmap( pDisp_, hPixmap );
788cdf0e10cSrcweir         }
789cdf0e10cSrcweir         rSD.m_hInvert50 = XCreateBitmapFromData( pDisp_,
790cdf0e10cSrcweir                                                  rSD.m_aRefWindow,
79130c1b1efSHerbert Dürr                                                  (const char*)invert50_bits,
792cdf0e10cSrcweir                                                  invert50_width,
793cdf0e10cSrcweir                                                  invert50_height );
794cdf0e10cSrcweir     }
795cdf0e10cSrcweir }
796cdf0e10cSrcweir 
797cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Init()798cdf0e10cSrcweir void SalDisplay::Init()
799cdf0e10cSrcweir {
800cdf0e10cSrcweir     for( size_t i = 0; i < POINTER_COUNT; i++ )
801cdf0e10cSrcweir         aPointerCache_[i] = None;
802cdf0e10cSrcweir 
803cdf0e10cSrcweir     eWindowManager_     = otherwm;
804cdf0e10cSrcweir     nProperties_        = PROPERTY_DEFAULT;
805cdf0e10cSrcweir     hEventGuard_        = NULL;
806cdf0e10cSrcweir 	mpFactory  			= (AttributeProvider*)NULL;
807cdf0e10cSrcweir     m_pCapture			= NULL;
808cdf0e10cSrcweir     m_bXinerama			= false;
809cdf0e10cSrcweir 
810cdf0e10cSrcweir     int nDisplayScreens = ScreenCount( pDisp_ );
811cdf0e10cSrcweir     m_aScreens = std::vector<ScreenData>(nDisplayScreens);
812cdf0e10cSrcweir 
813cdf0e10cSrcweir     mbExactResolution = false;
814cdf0e10cSrcweir     /*  #i15507#
815cdf0e10cSrcweir      *  Xft resolution should take precedence since
816cdf0e10cSrcweir      *  it is what modern desktops use.
817cdf0e10cSrcweir      */
818cdf0e10cSrcweir     const char* pValStr = XGetDefault( pDisp_, "Xft", "dpi" );
819cdf0e10cSrcweir     if( pValStr != NULL )
820cdf0e10cSrcweir     {
821cdf0e10cSrcweir         const rtl::OString aValStr( pValStr );
822cdf0e10cSrcweir         const long nDPI = (long) aValStr.toDouble();
823cdf0e10cSrcweir         // guard against insane resolution
824cdf0e10cSrcweir         if( (nDPI >= 50) && (nDPI <= 500) )
825cdf0e10cSrcweir         {
826cdf0e10cSrcweir             aResolution_ = Pair( nDPI, nDPI );
827cdf0e10cSrcweir             mbExactResolution = true;
828cdf0e10cSrcweir         }
829cdf0e10cSrcweir     }
830cdf0e10cSrcweir     if( mbExactResolution == false )
831cdf0e10cSrcweir     {
832cdf0e10cSrcweir         aResolution_     =
833cdf0e10cSrcweir             Pair( DPI( WidthOfScreen( DefaultScreenOfDisplay( pDisp_ ) ), DisplayWidthMM ( pDisp_, m_nDefaultScreen ) ),
834cdf0e10cSrcweir                   DPI( HeightOfScreen( DefaultScreenOfDisplay( pDisp_ ) ), DisplayHeightMM( pDisp_, m_nDefaultScreen ) ) );
835cdf0e10cSrcweir     }
836cdf0e10cSrcweir 
837cdf0e10cSrcweir     nMaxRequestSize_    = XExtendedMaxRequestSize( pDisp_ ) * 4;
838cdf0e10cSrcweir     if( !nMaxRequestSize_ )
839cdf0e10cSrcweir         nMaxRequestSize_ = XMaxRequestSize( pDisp_ ) * 4;
840cdf0e10cSrcweir 
841cdf0e10cSrcweir 	SetServerVendor();
842cdf0e10cSrcweir 	X11SalBitmap::ImplCreateCache();
843cdf0e10cSrcweir 
844cdf0e10cSrcweir     hEventGuard_    = osl_createMutex();
845cdf0e10cSrcweir     bLocal_ 		= sal_False; /* dont care, initialize later by
846cdf0e10cSrcweir                                 calling SalDisplay::IsLocal() */
847cdf0e10cSrcweir     mbLocalIsValid 	= sal_False; /* bLocal_ is not yet initialized */
848cdf0e10cSrcweir 
849cdf0e10cSrcweir     // - - - - - - - - - - Synchronize - - - - - - - - - - - - -
850cdf0e10cSrcweir     if( getenv( "SAL_SYNCHRONIZE" ) )
851cdf0e10cSrcweir         XSynchronize( pDisp_, True );
852cdf0e10cSrcweir 
853cdf0e10cSrcweir     // - - - - - - - - - - Keyboardmapping - - - - - - - - - - -
854cdf0e10cSrcweir     ModifierMapping();
855cdf0e10cSrcweir 
856cdf0e10cSrcweir     // - - - - - - - - - - Window Manager  - - - - - - - - - - -
857cdf0e10cSrcweir     m_pWMAdaptor = ::vcl_sal::WMAdaptor::createWMAdaptor( this );
858cdf0e10cSrcweir     const char *pWM = getenv( "SAL_WM" );
859cdf0e10cSrcweir     if( pWM )
860cdf0e10cSrcweir     {
861cdf0e10cSrcweir         long int nWM = 0;
862cdf0e10cSrcweir         sscanf( pWM, "%li", &nWM );
863cdf0e10cSrcweir         eWindowManager_ = SalWM(nWM);
864cdf0e10cSrcweir     }
865cdf0e10cSrcweir     else if( XInternAtom( pDisp_, "_SGI_TELL_WM", True ) )
866cdf0e10cSrcweir         eWindowManager_ = FourDwm;
867cdf0e10cSrcweir     else if( XInternAtom( pDisp_, "KWM_RUNNING", True ) )
868cdf0e10cSrcweir         eWindowManager_ = mwm; // naja, eigentlich kwm ...
869cdf0e10cSrcweir     else if( XInternAtom( pDisp_, "_OL_WIN_ATTR", True ) )
870cdf0e10cSrcweir         eWindowManager_ = olwm;
871cdf0e10cSrcweir     else if( m_pWMAdaptor->getWindowManagerName().EqualsAscii( "Dtwm" ) )
872cdf0e10cSrcweir         eWindowManager_ = dtwm;
873cdf0e10cSrcweir 
874cdf0e10cSrcweir     // - - - - - - - - - - Properties  - - - - - - - - - - - - -
875cdf0e10cSrcweir     const char *pProperties = getenv( "SAL_PROPERTIES" );
876cdf0e10cSrcweir     if( pProperties )
877cdf0e10cSrcweir         sscanf( pProperties, "%li", &nProperties_ );
878cdf0e10cSrcweir     else
879cdf0e10cSrcweir     {
880cdf0e10cSrcweir #if defined DBG_UTIL || defined SUN || defined LINUX || defined FREEBSD
881cdf0e10cSrcweir         nProperties_ |= PROPERTY_FEATURE_Maximize;
882cdf0e10cSrcweir #endif
883cdf0e10cSrcweir         // Server Bugs & Properties
884cdf0e10cSrcweir         if( GetServerVendor() == vendor_excursion )
885cdf0e10cSrcweir         {
886cdf0e10cSrcweir             nProperties_ |= PROPERTY_BUG_Stipple;
887cdf0e10cSrcweir             nProperties_ |= PROPERTY_BUG_DrawLine;
888cdf0e10cSrcweir             nProperties_ &= ~PROPERTY_SUPPORT_XSetClipMask;
889cdf0e10cSrcweir         }
890cdf0e10cSrcweir         else
891cdf0e10cSrcweir         if( GetServerVendor() == vendor_attachmate )
892cdf0e10cSrcweir         {
893cdf0e10cSrcweir             nProperties_ |= PROPERTY_BUG_CopyPlane_RevertBWPixel;
894cdf0e10cSrcweir         }
895cdf0e10cSrcweir         else
896cdf0e10cSrcweir         if( GetServerVendor() == vendor_ibm )
897cdf0e10cSrcweir         {
898cdf0e10cSrcweir             nProperties_ |= PROPERTY_BUG_XA_FAMILY_NAME_nil;
899cdf0e10cSrcweir 
900cdf0e10cSrcweir             if( otherwm == eWindowManager_ ) eWindowManager_ = mwm;
901cdf0e10cSrcweir         }
902cdf0e10cSrcweir         else
903cdf0e10cSrcweir         if( GetServerVendor() == vendor_xfree )
904cdf0e10cSrcweir         {
905cdf0e10cSrcweir             nProperties_ |= PROPERTY_BUG_XCopyArea_GXxor;
906cdf0e10cSrcweir #if defined LINUX || defined FREEBSD
907cdf0e10cSrcweir             // otherwm and olwm are a kind of default, which are not detected
908cdf0e10cSrcweir             // carefully. if we are running linux (i.e. not netbsd) on an xfree
909cdf0e10cSrcweir             // display, fvwm is most probable the wm to choose, confusing with mwm
910cdf0e10cSrcweir             // doesn't harm. #57791# start maximized if possible
911cdf0e10cSrcweir                     if(    (otherwm == eWindowManager_)
912cdf0e10cSrcweir                 || (olwm    == eWindowManager_ ))
913cdf0e10cSrcweir             {
914cdf0e10cSrcweir                 eWindowManager_ = fvwm; // ???
915cdf0e10cSrcweir                 nProperties_ |= PROPERTY_FEATURE_Maximize;
916cdf0e10cSrcweir             }
917cdf0e10cSrcweir #else
918cdf0e10cSrcweir             if( otherwm == eWindowManager_ ) eWindowManager_ = winmgr;
919cdf0e10cSrcweir #endif
920cdf0e10cSrcweir #if defined SOLARIS && defined SPARC
921cdf0e10cSrcweir             nProperties_ |= PROPERTY_BUG_Bitmap_Bit_Order;
922cdf0e10cSrcweir             // solaris xlib seems to have problems with putting images
923cdf0e10cSrcweir             // in correct bit order to xfree 8 bit displays
924cdf0e10cSrcweir #endif
925cdf0e10cSrcweir         }
926cdf0e10cSrcweir         else
927cdf0e10cSrcweir         if( GetServerVendor() == vendor_sun )
928cdf0e10cSrcweir         {
929cdf0e10cSrcweir             // nicht alle! (bekannt: nur Sparc II CG3, CG6?)
930cdf0e10cSrcweir             nProperties_ &= ~PROPERTY_SUPPORT_XSetClipMask;
931cdf0e10cSrcweir 
932cdf0e10cSrcweir             // trusted solaris doesn't allow to change properties on the
933cdf0e10cSrcweir             // wm decoration window
934cdf0e10cSrcweir             if (sal_IsTrustedSolaris (pDisp_))
935cdf0e10cSrcweir                 nProperties_ |= PROPERTY_FEATURE_TrustedSolaris;
936cdf0e10cSrcweir 
937cdf0e10cSrcweir             // Fehler im Sun-Solaris X86 Server !
938cdf0e10cSrcweir             if (ImageByteOrder(GetDisplay()) == LSBFirst)
939cdf0e10cSrcweir             {
940cdf0e10cSrcweir                 nProperties_ |= PROPERTY_BUG_Tile;
941cdf0e10cSrcweir                 nProperties_ |= PROPERTY_SUPPORT_3ButtonMouse;
942cdf0e10cSrcweir             }
943cdf0e10cSrcweir             else // MSBFirst Sun-Solaris Sparc Server
944cdf0e10cSrcweir             {
945cdf0e10cSrcweir                 // XCopyPlane reverts black and white for 1bit bitmaps
946cdf0e10cSrcweir                 // only sun, only 8bit pseudocolor target
947cdf0e10cSrcweir                 if (   (GetVisual(m_nDefaultScreen).GetDepth() == 8)
948cdf0e10cSrcweir                     && (GetVisual(m_nDefaultScreen).GetClass() == PseudoColor))
949cdf0e10cSrcweir                     nProperties_ |= PROPERTY_BUG_CopyPlane_RevertBWPixel;
950cdf0e10cSrcweir                 // Fehler in Solaris 2.5.1
951cdf0e10cSrcweir                 if (VendorRelease ( GetDisplay() ) < 3600)
952cdf0e10cSrcweir                     nProperties_ |= PROPERTY_BUG_FillPolygon_Tile;
953cdf0e10cSrcweir             }
954cdf0e10cSrcweir 
955cdf0e10cSrcweir             if( otherwm == eWindowManager_ )
956cdf0e10cSrcweir                 eWindowManager_ = olwm;
957cdf0e10cSrcweir         }
958cdf0e10cSrcweir         else
959cdf0e10cSrcweir         if( GetServerVendor() == vendor_sco )
960cdf0e10cSrcweir         {
961cdf0e10cSrcweir             if( otherwm == eWindowManager_ ) eWindowManager_ = pmwm;
962cdf0e10cSrcweir         }
963cdf0e10cSrcweir         else
964cdf0e10cSrcweir         if( GetServerVendor() == vendor_sgi )
965cdf0e10cSrcweir         {
966cdf0e10cSrcweir             if( GetVisual( m_nDefaultScreen ).GetDepth() > 8 && GetVisual( m_nDefaultScreen ).GetDepth() <= 16 )
967cdf0e10cSrcweir                 nProperties_ |= PROPERTY_BUG_XCopyArea_GXxor;
968cdf0e10cSrcweir             nProperties_ |= PROPERTY_SUPPORT_XSetClipMask;
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 			if( otherwm == eWindowManager_ )
971cdf0e10cSrcweir 				eWindowManager_ = FourDwm;
972cdf0e10cSrcweir         }
973cdf0e10cSrcweir         else
974cdf0e10cSrcweir         if( GetServerVendor() == vendor_hp )
975cdf0e10cSrcweir         {
976cdf0e10cSrcweir             if( otherwm == eWindowManager_ ) eWindowManager_ = dtwm;
977cdf0e10cSrcweir         }
978cdf0e10cSrcweir         else
979cdf0e10cSrcweir         if( GetServerVendor() == vendor_hummingbird )
980cdf0e10cSrcweir         {
981cdf0e10cSrcweir             if (GetVisual(m_nDefaultScreen).GetDepth() == 24)
982cdf0e10cSrcweir                 nProperties_ |= PROPERTY_BUG_CopyArea_OnlySmallSlices;
983cdf0e10cSrcweir         }
984cdf0e10cSrcweir 
985cdf0e10cSrcweir         if( otherwm == eWindowManager_ )
986cdf0e10cSrcweir         {
987cdf0e10cSrcweir             if( !XInternAtom( pDisp_, "_MOTIF_WM_INFO", True ) )
988cdf0e10cSrcweir                 eWindowManager_ = olwm;
989cdf0e10cSrcweir             // ???
990cdf0e10cSrcweir         }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir         if( winmgr == eWindowManager_ )
993cdf0e10cSrcweir         {
994cdf0e10cSrcweir             nProperties_ &= ~PROPERTY_SUPPORT_WM_SetPos;
995cdf0e10cSrcweir             nProperties_ &= ~PROPERTY_SUPPORT_WM_Screen;
996cdf0e10cSrcweir             nProperties_ |= PROPERTY_FEATURE_Maximize;
997cdf0e10cSrcweir         }
998cdf0e10cSrcweir         else if( dtwm == eWindowManager_ )
999cdf0e10cSrcweir         {
1000cdf0e10cSrcweir             nProperties_ &= ~PROPERTY_SUPPORT_WM_ClientPos;
1001cdf0e10cSrcweir         }
1002cdf0e10cSrcweir         else if( pmwm == eWindowManager_ )
1003cdf0e10cSrcweir         {
1004cdf0e10cSrcweir             nProperties_ &= ~PROPERTY_SUPPORT_WM_ClientPos;
1005cdf0e10cSrcweir         }
1006cdf0e10cSrcweir     }
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir     InitXinerama();
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir     // initialize system settings update
1011cdf0e10cSrcweir     m_pDtIntegrator = DtIntegrator::CreateDtIntegrator();
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir #ifdef DBG_UTIL
1014cdf0e10cSrcweir     PrintInfo();
1015cdf0e10cSrcweir #endif
1016cdf0e10cSrcweir }
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir // Sound
1019cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Beep() const1020cdf0e10cSrcweir void SalDisplay::Beep() const
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir     XBell( pDisp_, 0 );
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir // Keyboard
1026cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GetKeyNameFromKeySym(KeySym nKeySym) const1027cdf0e10cSrcweir String SalDisplay::GetKeyNameFromKeySym( KeySym nKeySym ) const
1028cdf0e10cSrcweir {
1029cdf0e10cSrcweir 	String aRet;
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir     // return an empty string for keysyms that are not bound to
1032cdf0e10cSrcweir     // any key code
1033cdf0e10cSrcweir     XLIB_KeyCode aKeyCode = XKeysymToKeycode( GetDisplay(), nKeySym );
1034cdf0e10cSrcweir     if( aKeyCode != 0 && aKeyCode != NoSymbol )
1035cdf0e10cSrcweir     {
1036cdf0e10cSrcweir         if( !nKeySym )
1037cdf0e10cSrcweir             aRet = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "???" ) );
1038cdf0e10cSrcweir         else
1039cdf0e10cSrcweir         {
1040cdf0e10cSrcweir             aRet = ::vcl_sal::getKeysymReplacementName( const_cast<SalDisplay*>(this)->GetKeyboardName(), nKeySym );
1041cdf0e10cSrcweir             if( ! aRet.Len() )
1042cdf0e10cSrcweir             {
1043cdf0e10cSrcweir                 const char *pString = XKeysymToString( nKeySym );
1044cdf0e10cSrcweir                 int n = strlen( pString );
1045cdf0e10cSrcweir                 if( n > 2 && pString[n-2] == '_' )
1046cdf0e10cSrcweir                     aRet = String( pString, n-2, RTL_TEXTENCODING_ISO_8859_1 );
1047cdf0e10cSrcweir                 else
1048cdf0e10cSrcweir                     aRet = String( pString, n, RTL_TEXTENCODING_ISO_8859_1 );
1049cdf0e10cSrcweir             }
1050cdf0e10cSrcweir         }
1051cdf0e10cSrcweir     }
1052cdf0e10cSrcweir 	return aRet;
1053cdf0e10cSrcweir }
1054cdf0e10cSrcweir 
sal_XModifier2Keysym(Display * pDisplay,XModifierKeymap * pXModMap,int n)1055cdf0e10cSrcweir inline KeySym sal_XModifier2Keysym( Display         *pDisplay,
1056cdf0e10cSrcweir                                     XModifierKeymap *pXModMap,
1057cdf0e10cSrcweir                                     int              n )
1058cdf0e10cSrcweir {
1059*85372600SHerbert Dürr     return XkbKeycodeToKeysym( pDisplay,
1060cdf0e10cSrcweir                              pXModMap->modifiermap[n*pXModMap->max_keypermod],
1061*85372600SHerbert Dürr                              0, 0 );
1062cdf0e10cSrcweir }
1063cdf0e10cSrcweir 
ModifierMapping()1064cdf0e10cSrcweir void SalDisplay::ModifierMapping()
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir     XModifierKeymap *pXModMap = XGetModifierMapping( pDisp_ );
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir     bNumLockFromXS_ = True;
1069cdf0e10cSrcweir     nShiftKeySym_   = sal_XModifier2Keysym( pDisp_, pXModMap, ShiftMapIndex );
1070cdf0e10cSrcweir     nCtrlKeySym_    = sal_XModifier2Keysym( pDisp_, pXModMap, ControlMapIndex );
1071cdf0e10cSrcweir     nMod1KeySym_    = sal_XModifier2Keysym( pDisp_, pXModMap, Mod1MapIndex );
1072cdf0e10cSrcweir     // Auf Sun-Servern und SCO-Severn beruecksichtigt XLookupString
1073cdf0e10cSrcweir     // nicht den NumLock Modifier.
1074cdf0e10cSrcweir     if( 	(GetServerVendor() == vendor_sun)
1075cdf0e10cSrcweir 		||  (GetServerVendor() == vendor_sco) )
1076cdf0e10cSrcweir     {
1077cdf0e10cSrcweir         XLIB_KeyCode aNumLock = XKeysymToKeycode( pDisp_, XK_Num_Lock );
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir         if( aNumLock ) for( int i = ShiftMapIndex; i <= Mod5MapIndex; i++ )
1080cdf0e10cSrcweir         {
1081cdf0e10cSrcweir             if( pXModMap->modifiermap[i*pXModMap->max_keypermod] == aNumLock )
1082cdf0e10cSrcweir             {
1083cdf0e10cSrcweir                 bNumLockFromXS_ = False;
1084cdf0e10cSrcweir                 nNumLockIndex_  = i;
1085cdf0e10cSrcweir                 nNumLockMask_   = 1<<i;
1086cdf0e10cSrcweir                 break;
1087cdf0e10cSrcweir             }
1088cdf0e10cSrcweir         }
1089cdf0e10cSrcweir     }
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir     XFreeModifiermap( pXModMap );
1092cdf0e10cSrcweir }
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GetKeyName(sal_uInt16 nKeyCode) const1095cdf0e10cSrcweir XubString SalDisplay::GetKeyName( sal_uInt16 nKeyCode ) const
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir     String aStrMap;
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir 	if( nKeyCode & KEY_MOD1 )
1100cdf0e10cSrcweir         aStrMap += GetKeyNameFromKeySym( nCtrlKeySym_ );
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir     if( nKeyCode & KEY_MOD2 )
1103cdf0e10cSrcweir     {
1104cdf0e10cSrcweir         if( aStrMap.Len() )
1105cdf0e10cSrcweir             aStrMap += '+';
1106cdf0e10cSrcweir         aStrMap += GetKeyNameFromKeySym( nMod1KeySym_ );
1107cdf0e10cSrcweir     }
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir     if( nKeyCode & KEY_SHIFT )
1110cdf0e10cSrcweir     {
1111cdf0e10cSrcweir         if( aStrMap.Len() )
1112cdf0e10cSrcweir             aStrMap += '+';
1113cdf0e10cSrcweir         aStrMap += GetKeyNameFromKeySym( nShiftKeySym_ );
1114cdf0e10cSrcweir     }
1115cdf0e10cSrcweir     nKeyCode &= 0x0FFF;
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir     KeySym nKeySym = 0;
1118cdf0e10cSrcweir 
1119cdf0e10cSrcweir     if( KEY_0 <= nKeyCode && nKeyCode <= KEY_9 )
1120cdf0e10cSrcweir         nKeySym = XK_0 + (nKeyCode - KEY_0);
1121cdf0e10cSrcweir     else if( KEY_A <= nKeyCode && nKeyCode <= KEY_Z )
1122cdf0e10cSrcweir         nKeySym = XK_A + (nKeyCode - KEY_A);
1123cdf0e10cSrcweir     else if( KEY_F1 <= nKeyCode && nKeyCode <= KEY_F26 ) // Existiert die Taste
1124cdf0e10cSrcweir         nKeySym = XK_F1 + (nKeyCode - KEY_F1);
1125cdf0e10cSrcweir     else switch( nKeyCode )
1126cdf0e10cSrcweir     {
1127cdf0e10cSrcweir         case KEY_DOWN:
1128cdf0e10cSrcweir             nKeySym = XK_Down;
1129cdf0e10cSrcweir             break;
1130cdf0e10cSrcweir         case KEY_UP:
1131cdf0e10cSrcweir             nKeySym = XK_Up;
1132cdf0e10cSrcweir             break;
1133cdf0e10cSrcweir         case KEY_LEFT:
1134cdf0e10cSrcweir             nKeySym = XK_Left;
1135cdf0e10cSrcweir             break;
1136cdf0e10cSrcweir         case KEY_RIGHT:
1137cdf0e10cSrcweir             nKeySym = XK_Right;
1138cdf0e10cSrcweir             break;
1139cdf0e10cSrcweir         case KEY_HOME:
1140cdf0e10cSrcweir             nKeySym = XK_Home;
1141cdf0e10cSrcweir             break;
1142cdf0e10cSrcweir         case KEY_END:
1143cdf0e10cSrcweir             nKeySym = XK_End;
1144cdf0e10cSrcweir             break;
1145cdf0e10cSrcweir         case KEY_PAGEUP:
1146cdf0e10cSrcweir             nKeySym = XK_Prior;
1147cdf0e10cSrcweir             break;
1148cdf0e10cSrcweir         case KEY_PAGEDOWN:
1149cdf0e10cSrcweir             nKeySym = XK_Next;
1150cdf0e10cSrcweir             break;
1151cdf0e10cSrcweir         case KEY_RETURN:
1152cdf0e10cSrcweir             nKeySym = XK_Return;
1153cdf0e10cSrcweir             break;
1154cdf0e10cSrcweir         case KEY_ESCAPE:
1155cdf0e10cSrcweir             nKeySym = XK_Escape;
1156cdf0e10cSrcweir             break;
1157cdf0e10cSrcweir         case KEY_TAB:
1158cdf0e10cSrcweir             nKeySym = XK_Tab;
1159cdf0e10cSrcweir             break;
1160cdf0e10cSrcweir         case KEY_BACKSPACE:
1161cdf0e10cSrcweir             nKeySym = XK_BackSpace;
1162cdf0e10cSrcweir             break;
1163cdf0e10cSrcweir         case KEY_SPACE:
1164cdf0e10cSrcweir             nKeySym = XK_space;
1165cdf0e10cSrcweir             break;
1166cdf0e10cSrcweir         case KEY_INSERT:
1167cdf0e10cSrcweir             nKeySym = XK_Insert;
1168cdf0e10cSrcweir             break;
1169cdf0e10cSrcweir         case KEY_DELETE:
1170cdf0e10cSrcweir             nKeySym = XK_Delete;
1171cdf0e10cSrcweir             break;
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir         #if !defined (SunXK_Undo)
1174cdf0e10cSrcweir             #define SunXK_Stop		0x0000FF69	// XK_Cancel
1175cdf0e10cSrcweir             #define SunXK_Props		0x1005FF70
1176cdf0e10cSrcweir             #define SunXK_Front		0x1005FF71
1177cdf0e10cSrcweir             #define SunXK_Copy		0x1005FF72
1178cdf0e10cSrcweir             #define SunXK_Open		0x1005FF73
1179cdf0e10cSrcweir             #define SunXK_Paste		0x1005FF74
1180cdf0e10cSrcweir             #define SunXK_Cut		0x1005FF75
1181cdf0e10cSrcweir         #endif
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir         case KEY_REPEAT:
1184cdf0e10cSrcweir 			nKeySym = XK_Redo;
1185cdf0e10cSrcweir             break;
1186cdf0e10cSrcweir         case KEY_PROPERTIES:
1187cdf0e10cSrcweir             nKeySym = SunXK_Props;
1188cdf0e10cSrcweir             break;
1189cdf0e10cSrcweir         case KEY_UNDO:
1190cdf0e10cSrcweir             nKeySym = XK_Undo;
1191cdf0e10cSrcweir             break;
1192cdf0e10cSrcweir         case KEY_FRONT:
1193cdf0e10cSrcweir             nKeySym = SunXK_Front;
1194cdf0e10cSrcweir             break;
1195cdf0e10cSrcweir         case KEY_COPY:
1196cdf0e10cSrcweir             nKeySym = SunXK_Copy;
1197cdf0e10cSrcweir             break;
1198cdf0e10cSrcweir         case KEY_OPEN:
1199cdf0e10cSrcweir             nKeySym = SunXK_Open;
1200cdf0e10cSrcweir             break;
1201cdf0e10cSrcweir         case KEY_PASTE:
1202cdf0e10cSrcweir             nKeySym = SunXK_Paste;
1203cdf0e10cSrcweir             break;
1204cdf0e10cSrcweir         case KEY_FIND:
1205cdf0e10cSrcweir             nKeySym = XK_Find;
1206cdf0e10cSrcweir             break;
1207cdf0e10cSrcweir         case KEY_CUT:
1208cdf0e10cSrcweir             nKeySym = GetServerVendor() == vendor_sun ? SunXK_Cut   : XK_L10;
1209cdf0e10cSrcweir             break;
1210cdf0e10cSrcweir         case KEY_ADD:
1211cdf0e10cSrcweir             nKeySym = XK_plus;
1212cdf0e10cSrcweir             break;
1213cdf0e10cSrcweir         case KEY_SUBTRACT:
1214cdf0e10cSrcweir             nKeySym = XK_minus;
1215cdf0e10cSrcweir             break;
1216cdf0e10cSrcweir         case KEY_MULTIPLY:
1217cdf0e10cSrcweir             nKeySym = XK_asterisk;
1218cdf0e10cSrcweir             break;
1219cdf0e10cSrcweir         case KEY_DIVIDE:
1220cdf0e10cSrcweir             nKeySym = XK_slash;
1221cdf0e10cSrcweir             break;
1222cdf0e10cSrcweir         case KEY_POINT:
1223cdf0e10cSrcweir             nKeySym = XK_period;
1224cdf0e10cSrcweir             break;
1225cdf0e10cSrcweir         case KEY_COMMA:
1226cdf0e10cSrcweir             nKeySym = XK_comma;
1227cdf0e10cSrcweir             break;
1228cdf0e10cSrcweir         case KEY_LESS:
1229cdf0e10cSrcweir             nKeySym = XK_less;
1230cdf0e10cSrcweir             break;
1231cdf0e10cSrcweir         case KEY_GREATER:
1232cdf0e10cSrcweir             nKeySym = XK_greater;
1233cdf0e10cSrcweir             break;
1234cdf0e10cSrcweir         case KEY_EQUAL:
1235cdf0e10cSrcweir             nKeySym = XK_equal;
1236cdf0e10cSrcweir             break;
1237cdf0e10cSrcweir         case KEY_HELP:
1238cdf0e10cSrcweir             nKeySym = XK_Help;
1239cdf0e10cSrcweir             break;
1240cdf0e10cSrcweir         case KEY_HANGUL_HANJA:
1241cdf0e10cSrcweir             nKeySym = XK_Hangul_Hanja;
1242cdf0e10cSrcweir             break;
1243cdf0e10cSrcweir         case KEY_TILDE:
1244cdf0e10cSrcweir             nKeySym = XK_asciitilde;
1245cdf0e10cSrcweir             break;
1246cdf0e10cSrcweir         case KEY_QUOTELEFT:
1247cdf0e10cSrcweir             nKeySym = XK_grave;
1248cdf0e10cSrcweir             break;
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir         default:
1251cdf0e10cSrcweir             nKeySym = 0;
1252cdf0e10cSrcweir             break;
1253cdf0e10cSrcweir     }
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir     if( nKeySym )
1256cdf0e10cSrcweir     {
1257cdf0e10cSrcweir         String aKeyName = GetKeyNameFromKeySym( nKeySym );
1258cdf0e10cSrcweir         if( aKeyName.Len() )
1259cdf0e10cSrcweir         {
1260cdf0e10cSrcweir             if( aStrMap.Len() )
1261cdf0e10cSrcweir                 aStrMap += '+';
1262cdf0e10cSrcweir             aStrMap += aKeyName;
1263cdf0e10cSrcweir         }
1264cdf0e10cSrcweir         else
1265cdf0e10cSrcweir             aStrMap.Erase();
1266cdf0e10cSrcweir     }
1267cdf0e10cSrcweir     else
1268cdf0e10cSrcweir         aStrMap.Erase();
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir     return aStrMap;
1271cdf0e10cSrcweir }
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1274cdf0e10cSrcweir #ifndef IsISOKey
1275cdf0e10cSrcweir #define IsISOKey( n ) (0x0000FE00==((n)&0xFFFFFF00))
1276cdf0e10cSrcweir #endif
1277cdf0e10cSrcweir 
GetKeyCode(KeySym keysym,char * pcPrintable) const1278cdf0e10cSrcweir sal_uInt16 SalDisplay::GetKeyCode( KeySym keysym, char*pcPrintable ) const
1279cdf0e10cSrcweir {
1280cdf0e10cSrcweir     sal_uInt16 nKey = 0;
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir     if( XK_a <= keysym && XK_z >= keysym )
1283cdf0e10cSrcweir         nKey = (sal_uInt16)(KEY_A + (keysym - XK_a));
1284cdf0e10cSrcweir     else if( XK_A <= keysym && XK_Z >= keysym )
1285cdf0e10cSrcweir         nKey = (sal_uInt16)(KEY_A + (keysym - XK_A));
1286cdf0e10cSrcweir     else if( XK_0 <= keysym && XK_9 >= keysym )
1287cdf0e10cSrcweir         nKey = (sal_uInt16)(KEY_0 + (keysym - XK_0));
1288cdf0e10cSrcweir     else if( IsModifierKey( keysym ) )
1289cdf0e10cSrcweir         ;
1290cdf0e10cSrcweir     else if( IsKeypadKey( keysym ) )
1291cdf0e10cSrcweir     {
1292cdf0e10cSrcweir         if( (keysym >= XK_KP_0) && (keysym <= XK_KP_9) )
1293cdf0e10cSrcweir         {
1294cdf0e10cSrcweir             nKey = (sal_uInt16)(KEY_0 + (keysym - XK_KP_0));
1295cdf0e10cSrcweir             *pcPrintable = '0' + nKey - KEY_0;
1296cdf0e10cSrcweir         }
1297cdf0e10cSrcweir         else if( IsPFKey( keysym ) )
1298cdf0e10cSrcweir             nKey = (sal_uInt16)(KEY_F1 + (keysym - XK_KP_F1));
1299cdf0e10cSrcweir         else switch( keysym )
1300cdf0e10cSrcweir         {
1301cdf0e10cSrcweir             case XK_KP_Space:
1302cdf0e10cSrcweir                 nKey = KEY_SPACE;
1303cdf0e10cSrcweir                 *pcPrintable = ' ';
1304cdf0e10cSrcweir                 break;
1305cdf0e10cSrcweir             case XK_KP_Tab:
1306cdf0e10cSrcweir                 nKey = KEY_TAB;
1307cdf0e10cSrcweir                 break;
1308cdf0e10cSrcweir             case XK_KP_Enter:
1309cdf0e10cSrcweir                 nKey = KEY_RETURN;
1310cdf0e10cSrcweir                 break;
1311cdf0e10cSrcweir             case XK_KP_Begin:
1312cdf0e10cSrcweir             case XK_KP_Home:
1313cdf0e10cSrcweir                 nKey = KEY_HOME;
1314cdf0e10cSrcweir                 break;
1315cdf0e10cSrcweir             case XK_KP_Left:
1316cdf0e10cSrcweir                 nKey = KEY_LEFT;
1317cdf0e10cSrcweir                 break;
1318cdf0e10cSrcweir             case XK_KP_Up:
1319cdf0e10cSrcweir                 nKey = KEY_UP;
1320cdf0e10cSrcweir                 break;
1321cdf0e10cSrcweir             case XK_KP_Right:
1322cdf0e10cSrcweir                 nKey = KEY_RIGHT;
1323cdf0e10cSrcweir                 break;
1324cdf0e10cSrcweir             case XK_KP_Down:
1325cdf0e10cSrcweir                 nKey = KEY_DOWN;
1326cdf0e10cSrcweir                 break;
1327cdf0e10cSrcweir             case XK_KP_Prior: // XK_KP_Page_Up
1328cdf0e10cSrcweir                 nKey = KEY_PAGEUP;
1329cdf0e10cSrcweir                 break;
1330cdf0e10cSrcweir             case XK_KP_Next: // XK_KP_Page_Down
1331cdf0e10cSrcweir                 nKey = KEY_PAGEDOWN;
1332cdf0e10cSrcweir                 break;
1333cdf0e10cSrcweir             case XK_KP_End:
1334cdf0e10cSrcweir                 nKey = KEY_END;
1335cdf0e10cSrcweir                 break;
1336cdf0e10cSrcweir             case XK_KP_Insert:
1337cdf0e10cSrcweir                 nKey = KEY_INSERT;
1338cdf0e10cSrcweir                 break;
1339cdf0e10cSrcweir             case XK_KP_Delete:
1340cdf0e10cSrcweir                 nKey = KEY_DELETE;
1341cdf0e10cSrcweir                 break;
1342cdf0e10cSrcweir             case XK_KP_Equal:
1343cdf0e10cSrcweir                 nKey = KEY_EQUAL;
1344cdf0e10cSrcweir                 *pcPrintable = '=';
1345cdf0e10cSrcweir                 break;
1346cdf0e10cSrcweir             case XK_KP_Multiply:
1347cdf0e10cSrcweir                 nKey = KEY_MULTIPLY;
1348cdf0e10cSrcweir                 *pcPrintable = '*';
1349cdf0e10cSrcweir                 break;
1350cdf0e10cSrcweir             case XK_KP_Add:
1351cdf0e10cSrcweir                 nKey = KEY_ADD;
1352cdf0e10cSrcweir                 *pcPrintable = '+';
1353cdf0e10cSrcweir                 break;
1354cdf0e10cSrcweir             case XK_KP_Separator:
1355cdf0e10cSrcweir                 nKey = KEY_DECIMAL;
1356cdf0e10cSrcweir                 *pcPrintable = ',';
1357cdf0e10cSrcweir                 break;
1358cdf0e10cSrcweir             case XK_KP_Subtract:
1359cdf0e10cSrcweir                 nKey = KEY_SUBTRACT;
1360cdf0e10cSrcweir                 *pcPrintable = '-';
1361cdf0e10cSrcweir                 break;
1362cdf0e10cSrcweir             case XK_KP_Decimal:
1363cdf0e10cSrcweir                 nKey = KEY_DECIMAL;
1364cdf0e10cSrcweir                 *pcPrintable = '.';
1365cdf0e10cSrcweir                 break;
1366cdf0e10cSrcweir             case XK_KP_Divide:
1367cdf0e10cSrcweir                 nKey = KEY_DIVIDE;
1368cdf0e10cSrcweir                 *pcPrintable = '/';
1369cdf0e10cSrcweir                 break;
1370cdf0e10cSrcweir         }
1371cdf0e10cSrcweir     }
1372cdf0e10cSrcweir     else if( IsFunctionKey( keysym ) )
1373cdf0e10cSrcweir     {
1374cdf0e10cSrcweir         if( bNumLockFromXS_ )
1375cdf0e10cSrcweir         {
1376cdf0e10cSrcweir             if( keysym >= XK_F1 && keysym <= XK_F26 )
1377cdf0e10cSrcweir                 nKey = (sal_uInt16)(KEY_F1 + keysym - XK_F1);
1378cdf0e10cSrcweir         }
1379cdf0e10cSrcweir         else switch( keysym )
1380cdf0e10cSrcweir         {
1381cdf0e10cSrcweir             // - - - - - Sun X-Server Tastatur ohne Cursorblock ??? - - -
1382cdf0e10cSrcweir             case XK_R7: // XK_F27:
1383cdf0e10cSrcweir                 nKey = KEY_HOME;
1384cdf0e10cSrcweir                 break;
1385cdf0e10cSrcweir             case XK_R8: // XK_F28:
1386cdf0e10cSrcweir                 nKey = KEY_UP;
1387cdf0e10cSrcweir                 break;
1388cdf0e10cSrcweir             case XK_R9: // XK_F29:
1389cdf0e10cSrcweir                 nKey = KEY_PAGEUP;
1390cdf0e10cSrcweir                 break;
1391cdf0e10cSrcweir             case XK_R10: // XK_F30:
1392cdf0e10cSrcweir                 nKey = KEY_LEFT;
1393cdf0e10cSrcweir                 break;
1394cdf0e10cSrcweir             case XK_R11: // XK_F31:
1395cdf0e10cSrcweir                 nKey = 0; // KEY_F31
1396cdf0e10cSrcweir                 break;
1397cdf0e10cSrcweir             case XK_R12: // XK_F32:
1398cdf0e10cSrcweir                 nKey = KEY_RIGHT;
1399cdf0e10cSrcweir                 break;
1400cdf0e10cSrcweir             case XK_R13: // XK_F33:
1401cdf0e10cSrcweir                 nKey = KEY_END;
1402cdf0e10cSrcweir                 break;
1403cdf0e10cSrcweir             case XK_R14: // XK_F34:
1404cdf0e10cSrcweir                 nKey = KEY_DOWN;
1405cdf0e10cSrcweir                 break;
1406cdf0e10cSrcweir             case XK_R15: // XK_F35:
1407cdf0e10cSrcweir                 nKey = KEY_PAGEDOWN;
1408cdf0e10cSrcweir                 break;
1409cdf0e10cSrcweir             // - - - - - Sun X-Server Tastatur ??? - - - - - - - - - - - -
1410cdf0e10cSrcweir             case XK_L1: // XK_F11:
1411cdf0e10cSrcweir                 nKey = KEY_F11; // on a sun keyboard this actually is usally SunXK_Stop,
1412cdf0e10cSrcweir                 // but VCL doesn't have a key defintion for that
1413cdf0e10cSrcweir                 break;
1414cdf0e10cSrcweir             case XK_L2: // XK_F12:
1415cdf0e10cSrcweir 				if ( GetServerVendor() == vendor_sun )
1416cdf0e10cSrcweir 					nKey = KEY_REPEAT;
1417cdf0e10cSrcweir 				else
1418cdf0e10cSrcweir 					nKey = KEY_F12;
1419cdf0e10cSrcweir                 break;
1420cdf0e10cSrcweir             case XK_L3: // XK_F13:
1421cdf0e10cSrcweir                 nKey = KEY_PROPERTIES; // KEY_F13
1422cdf0e10cSrcweir                 break;
1423cdf0e10cSrcweir             case XK_L4: // XK_F14:
1424cdf0e10cSrcweir                 nKey = KEY_UNDO; // KEY_F14
1425cdf0e10cSrcweir                 break;
1426cdf0e10cSrcweir             case XK_L5: // XK_F15:
1427cdf0e10cSrcweir                 nKey = KEY_F15; // KEY_FRONT
1428cdf0e10cSrcweir                 break;
1429cdf0e10cSrcweir             case XK_L6: // XK_F16:
1430cdf0e10cSrcweir                 nKey = KEY_COPY; // KEY_F16
1431cdf0e10cSrcweir                 break;
1432cdf0e10cSrcweir             case XK_L7: // XK_F17:
1433cdf0e10cSrcweir                 nKey = KEY_F17; // KEY_OPEN
1434cdf0e10cSrcweir                 break;
1435cdf0e10cSrcweir             case XK_L8: // XK_F18:
1436cdf0e10cSrcweir                 nKey = KEY_PASTE; // KEY_F18
1437cdf0e10cSrcweir                 break;
1438cdf0e10cSrcweir             case XK_L9: // XK_F19:
1439cdf0e10cSrcweir                 nKey = KEY_F19; // KEY_FIND
1440cdf0e10cSrcweir                 break;
1441cdf0e10cSrcweir             case XK_L10: // XK_F20:
1442cdf0e10cSrcweir                 nKey = KEY_CUT; // KEY_F20
1443cdf0e10cSrcweir                 break;
1444cdf0e10cSrcweir             default:
1445cdf0e10cSrcweir                 if( keysym >= XK_F1 && keysym <= XK_F26 )
1446cdf0e10cSrcweir                     nKey = (sal_uInt16)(KEY_F1 + keysym - XK_F1);
1447cdf0e10cSrcweir                 break;
1448cdf0e10cSrcweir         }
1449cdf0e10cSrcweir     }
1450cdf0e10cSrcweir     else if( IsCursorKey( keysym ) )
1451cdf0e10cSrcweir     {
1452cdf0e10cSrcweir         switch( keysym )
1453cdf0e10cSrcweir         {
1454cdf0e10cSrcweir             case XK_Begin:
1455cdf0e10cSrcweir             case XK_Home:
1456cdf0e10cSrcweir                 nKey = KEY_HOME;
1457cdf0e10cSrcweir                 break;
1458cdf0e10cSrcweir             case XK_Left:
1459cdf0e10cSrcweir                 nKey = KEY_LEFT;
1460cdf0e10cSrcweir                 break;
1461cdf0e10cSrcweir             case XK_Up:
1462cdf0e10cSrcweir                 nKey = KEY_UP;
1463cdf0e10cSrcweir                 break;
1464cdf0e10cSrcweir             case XK_Right:
1465cdf0e10cSrcweir                 nKey = KEY_RIGHT;
1466cdf0e10cSrcweir                 break;
1467cdf0e10cSrcweir             case XK_Down:
1468cdf0e10cSrcweir                 nKey = KEY_DOWN;
1469cdf0e10cSrcweir                 break;
1470cdf0e10cSrcweir             case XK_Prior: // XK_Page_Up
1471cdf0e10cSrcweir                 nKey = KEY_PAGEUP;
1472cdf0e10cSrcweir                 break;
1473cdf0e10cSrcweir             case XK_Next: // XK_Page_Down
1474cdf0e10cSrcweir                 nKey = KEY_PAGEDOWN;
1475cdf0e10cSrcweir                 break;
1476cdf0e10cSrcweir             case XK_End:
1477cdf0e10cSrcweir                 nKey = KEY_END;
1478cdf0e10cSrcweir                 break;
1479cdf0e10cSrcweir         }
1480cdf0e10cSrcweir     }
1481cdf0e10cSrcweir     else if( IsMiscFunctionKey( keysym ) )
1482cdf0e10cSrcweir     {
1483cdf0e10cSrcweir         switch( keysym )
1484cdf0e10cSrcweir         {
1485cdf0e10cSrcweir             case XK_Insert:
1486cdf0e10cSrcweir                 nKey = KEY_INSERT;
1487cdf0e10cSrcweir                 break;
1488cdf0e10cSrcweir             case XK_Redo:
1489cdf0e10cSrcweir                 nKey = KEY_REPEAT;
1490cdf0e10cSrcweir                 break;
1491cdf0e10cSrcweir             case XK_Undo:
1492cdf0e10cSrcweir                 nKey = KEY_UNDO;
1493cdf0e10cSrcweir                 break;
1494cdf0e10cSrcweir             case XK_Find:
1495cdf0e10cSrcweir                 nKey = KEY_FIND;
1496cdf0e10cSrcweir                 break;
1497cdf0e10cSrcweir             case XK_Help:
1498cdf0e10cSrcweir                 nKey = KEY_HELP;
1499cdf0e10cSrcweir                 break;
1500cdf0e10cSrcweir             case XK_Menu:
1501cdf0e10cSrcweir                 nKey = KEY_CONTEXTMENU;
1502cdf0e10cSrcweir                 break;
1503cdf0e10cSrcweir /*
1504cdf0e10cSrcweir             case XK_Break:
1505cdf0e10cSrcweir             case XK_Select:
1506cdf0e10cSrcweir             case XK_Execute:
1507cdf0e10cSrcweir             case XK_Print:
1508cdf0e10cSrcweir             case XK_Cancel:
1509cdf0e10cSrcweir */
1510cdf0e10cSrcweir         }
1511cdf0e10cSrcweir     }
1512cdf0e10cSrcweir     else if( IsISOKey( keysym ) )  // XK_ISO_
1513cdf0e10cSrcweir     {
1514cdf0e10cSrcweir         switch( keysym )
1515cdf0e10cSrcweir         {
1516cdf0e10cSrcweir             case 0xFE20: // XK_ISO_Left_Tab:
1517cdf0e10cSrcweir                 nKey = KEY_TAB;
1518cdf0e10cSrcweir                 break;
1519cdf0e10cSrcweir         }
1520cdf0e10cSrcweir     }
1521cdf0e10cSrcweir     else switch( keysym )
1522cdf0e10cSrcweir     {
1523cdf0e10cSrcweir         case XK_Return:
1524cdf0e10cSrcweir             nKey = KEY_RETURN;
1525cdf0e10cSrcweir             break;
1526cdf0e10cSrcweir         case XK_BackSpace:
1527cdf0e10cSrcweir             nKey = KEY_BACKSPACE;
1528cdf0e10cSrcweir             break;
1529cdf0e10cSrcweir         case XK_Delete:
1530cdf0e10cSrcweir             nKey = KEY_DELETE;
1531cdf0e10cSrcweir             break;
1532cdf0e10cSrcweir         case XK_space:
1533cdf0e10cSrcweir             nKey = KEY_SPACE;
1534cdf0e10cSrcweir             break;
1535cdf0e10cSrcweir         case XK_Tab:
1536cdf0e10cSrcweir             nKey = KEY_TAB;
1537cdf0e10cSrcweir             break;
1538cdf0e10cSrcweir         case XK_Escape:
1539cdf0e10cSrcweir             nKey = KEY_ESCAPE;
1540cdf0e10cSrcweir             break;
1541cdf0e10cSrcweir         case XK_plus:
1542cdf0e10cSrcweir             nKey = KEY_ADD;
1543cdf0e10cSrcweir             break;
1544cdf0e10cSrcweir         case XK_minus:
1545cdf0e10cSrcweir             nKey = KEY_SUBTRACT;
1546cdf0e10cSrcweir             break;
1547cdf0e10cSrcweir         case XK_asterisk:
1548cdf0e10cSrcweir             nKey = KEY_MULTIPLY;
1549cdf0e10cSrcweir             break;
1550cdf0e10cSrcweir         case XK_slash:
1551cdf0e10cSrcweir             nKey = KEY_DIVIDE;
1552cdf0e10cSrcweir             break;
1553cdf0e10cSrcweir         case XK_period:
1554cdf0e10cSrcweir             nKey = KEY_POINT;
1555cdf0e10cSrcweir             break;
1556cdf0e10cSrcweir         case XK_comma:
1557cdf0e10cSrcweir             nKey = KEY_COMMA;
1558cdf0e10cSrcweir             break;
1559cdf0e10cSrcweir         case XK_less:
1560cdf0e10cSrcweir             nKey = KEY_LESS;
1561cdf0e10cSrcweir             break;
1562cdf0e10cSrcweir         case XK_greater:
1563cdf0e10cSrcweir             nKey = KEY_GREATER;
1564cdf0e10cSrcweir             break;
1565cdf0e10cSrcweir         case XK_equal:
1566cdf0e10cSrcweir             nKey = KEY_EQUAL;
1567cdf0e10cSrcweir             break;
1568cdf0e10cSrcweir         case XK_Hangul_Hanja:
1569cdf0e10cSrcweir             nKey = KEY_HANGUL_HANJA;
1570cdf0e10cSrcweir             break;
1571cdf0e10cSrcweir         case XK_asciitilde:
1572cdf0e10cSrcweir             nKey = KEY_TILDE;
1573cdf0e10cSrcweir             *pcPrintable = '~';
1574cdf0e10cSrcweir             break;
1575cdf0e10cSrcweir         case XK_grave:
1576cdf0e10cSrcweir             nKey = KEY_QUOTELEFT;
1577cdf0e10cSrcweir             *pcPrintable = '`';
1578cdf0e10cSrcweir             break;
1579cdf0e10cSrcweir //      case XK_Linefeed:
1580cdf0e10cSrcweir //          *pcPrintable = '\n';
1581cdf0e10cSrcweir //          break;
1582cdf0e10cSrcweir         // - - - - - - - - - - - - -  Apollo - - - - - - - - - - - - - 0x1000
1583cdf0e10cSrcweir         case 0x1000FF02: // apXK_Copy
1584cdf0e10cSrcweir             nKey = KEY_COPY;
1585cdf0e10cSrcweir             break;
1586cdf0e10cSrcweir         case 0x1000FF03: // apXK_Cut
1587cdf0e10cSrcweir             nKey = KEY_CUT;
1588cdf0e10cSrcweir             break;
1589cdf0e10cSrcweir         case 0x1000FF04: // apXK_Paste
1590cdf0e10cSrcweir             nKey = KEY_PASTE;
1591cdf0e10cSrcweir             break;
1592cdf0e10cSrcweir         case 0x1000FF14: // apXK_Repeat
1593cdf0e10cSrcweir             nKey = KEY_REPEAT;
1594cdf0e10cSrcweir             break;
1595cdf0e10cSrcweir         // Exit, Save
1596cdf0e10cSrcweir         // - - - - - - - - - - - - - - D E C - - - - - - - - - - - - - 0x1000
1597cdf0e10cSrcweir         case 0x1000FF00:
1598cdf0e10cSrcweir             nKey = KEY_DELETE;
1599cdf0e10cSrcweir             break;
1600cdf0e10cSrcweir         // - - - - - - - - - - - - - -  H P  - - - - - - - - - - - - - 0x1000
1601cdf0e10cSrcweir         case 0x1000FF73: // hpXK_DeleteChar
1602cdf0e10cSrcweir             nKey = KEY_DELETE;
1603cdf0e10cSrcweir             break;
1604cdf0e10cSrcweir         case 0x1000FF74: // hpXK_BackTab
1605cdf0e10cSrcweir         case 0x1000FF75: // hpXK_KP_BackTab
1606cdf0e10cSrcweir             nKey = KEY_TAB;
1607cdf0e10cSrcweir             break;
1608cdf0e10cSrcweir         // - - - - - - - - - - - - - - I B M - - - - - - - - - - - - -
1609cdf0e10cSrcweir         // - - - - - - - - - - - - - - O S F - - - - - - - - - - - - - 0x1004
1610cdf0e10cSrcweir         case 0x1004FF02: // osfXK_Copy
1611cdf0e10cSrcweir             nKey = KEY_COPY;
1612cdf0e10cSrcweir             break;
1613cdf0e10cSrcweir         case 0x1004FF03: // osfXK_Cut
1614cdf0e10cSrcweir             nKey = KEY_CUT;
1615cdf0e10cSrcweir             break;
1616cdf0e10cSrcweir         case 0x1004FF04: // osfXK_Paste
1617cdf0e10cSrcweir             nKey = KEY_PASTE;
1618cdf0e10cSrcweir             break;
1619cdf0e10cSrcweir         case 0x1004FF07: // osfXK_BackTab
1620cdf0e10cSrcweir             nKey = KEY_TAB;
1621cdf0e10cSrcweir             break;
1622cdf0e10cSrcweir         case 0x1004FF08: // osfXK_BackSpace
1623cdf0e10cSrcweir             nKey = KEY_BACKSPACE;
1624cdf0e10cSrcweir             break;
1625cdf0e10cSrcweir         case 0x1004FF1B: // osfXK_Escape
1626cdf0e10cSrcweir             nKey = KEY_ESCAPE;
1627cdf0e10cSrcweir             break;
1628cdf0e10cSrcweir         // Up, Down, Left, Right, PageUp, PageDown
1629cdf0e10cSrcweir         // - - - - - - - - - - - - - - S C O - - - - - - - - - - - - -
1630cdf0e10cSrcweir         // - - - - - - - - - - - - - - S G I - - - - - - - - - - - - - 0x1007
1631cdf0e10cSrcweir         // - - - - - - - - - - - - - - S N I - - - - - - - - - - - - -
1632cdf0e10cSrcweir         // - - - - - - - - - - - - - - S U N - - - - - - - - - - - - - 0x1005
1633cdf0e10cSrcweir         case 0x1005FF10: // SunXK_F36
1634cdf0e10cSrcweir             nKey = KEY_F11;
1635cdf0e10cSrcweir             break;
1636cdf0e10cSrcweir         case 0x1005FF11: // SunXK_F37
1637cdf0e10cSrcweir 			nKey = KEY_F12;
1638cdf0e10cSrcweir             break;
1639cdf0e10cSrcweir         case 0x1005FF70: // SunXK_Props
1640cdf0e10cSrcweir             nKey = KEY_PROPERTIES;
1641cdf0e10cSrcweir             break;
1642cdf0e10cSrcweir         case 0x1005FF71: // SunXK_Front
1643cdf0e10cSrcweir             nKey = KEY_FRONT;
1644cdf0e10cSrcweir             break;
1645cdf0e10cSrcweir         case 0x1005FF72: // SunXK_Copy
1646cdf0e10cSrcweir             nKey = KEY_COPY;
1647cdf0e10cSrcweir             break;
1648cdf0e10cSrcweir         case 0x1005FF73: // SunXK_Open
1649cdf0e10cSrcweir             nKey = KEY_OPEN;
1650cdf0e10cSrcweir             break;
1651cdf0e10cSrcweir         case 0x1005FF74: // SunXK_Paste
1652cdf0e10cSrcweir             nKey = KEY_PASTE;
1653cdf0e10cSrcweir             break;
1654cdf0e10cSrcweir         case 0x1005FF75: // SunXK_Cut
1655cdf0e10cSrcweir             nKey = KEY_CUT;
1656cdf0e10cSrcweir             break;
1657cdf0e10cSrcweir     }
1658cdf0e10cSrcweir     return nKey;
1659cdf0e10cSrcweir }
1660cdf0e10cSrcweir 
1661cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GetKeySym(XKeyEvent * pEvent,unsigned char * pPrintable,int * pLen,KeySym * pUnmodifiedKeySym,Status * pStatusReturn,XIC aInputContext) const1662cdf0e10cSrcweir KeySym SalDisplay::GetKeySym( XKeyEvent        *pEvent,
1663cdf0e10cSrcweir                                     unsigned char    *pPrintable,
1664cdf0e10cSrcweir                                     int              *pLen,
1665cdf0e10cSrcweir                                     KeySym           *pUnmodifiedKeySym,
1666cdf0e10cSrcweir 									Status			 *pStatusReturn,
1667cdf0e10cSrcweir 									XIC 			 aInputContext ) const
1668cdf0e10cSrcweir {
1669cdf0e10cSrcweir     KeySym nKeySym = 0;
1670cdf0e10cSrcweir 	memset( pPrintable, 0, *pLen );
1671cdf0e10cSrcweir     *pStatusReturn = 0;
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir     // first get the printable of the possibly modified KeySym
1674cdf0e10cSrcweir 	if (   (aInputContext == 0)
1675cdf0e10cSrcweir         || (pEvent->type == KeyRelease)
1676cdf0e10cSrcweir         || (mpInputMethod != NULL && mpInputMethod->PosixLocale()) )
1677cdf0e10cSrcweir 	{
1678cdf0e10cSrcweir         // XmbLookupString must not be called for KeyRelease events
1679cdf0e10cSrcweir         // Cannot enter space in c locale problem #89616# #88978# btraq #4478197
1680cdf0e10cSrcweir 		*pLen = XLookupString( pEvent, (char*)pPrintable, 1, &nKeySym, NULL );
1681cdf0e10cSrcweir 	}
1682cdf0e10cSrcweir     else
1683cdf0e10cSrcweir     {
1684cdf0e10cSrcweir         *pLen = XmbLookupString( aInputContext,
1685cdf0e10cSrcweir                         pEvent, (char*)pPrintable, *pLen - 1, &nKeySym, pStatusReturn );
1686cdf0e10cSrcweir 
1687cdf0e10cSrcweir 		// Lookup the string again, now with appropriate size
1688cdf0e10cSrcweir 		if ( *pStatusReturn == XBufferOverflow )
1689cdf0e10cSrcweir 		{
1690cdf0e10cSrcweir 			pPrintable[ 0 ] = (char)0;
1691cdf0e10cSrcweir 			return 0;
1692cdf0e10cSrcweir 		}
1693cdf0e10cSrcweir 
1694cdf0e10cSrcweir 		switch ( *pStatusReturn )
1695cdf0e10cSrcweir 		{
1696cdf0e10cSrcweir 			case XBufferOverflow:
1697cdf0e10cSrcweir 				/* unhandled error */
1698cdf0e10cSrcweir 				break;
1699cdf0e10cSrcweir 			case XLookupNone:
1700cdf0e10cSrcweir 				/* unhandled error */
1701cdf0e10cSrcweir 				break;
1702cdf0e10cSrcweir 			case XLookupKeySym:
1703cdf0e10cSrcweir 				/* #72223# this is a strange one: on exceed sometimes
1704cdf0e10cSrcweir 				 * no printable is returned for the first char entered,
1705cdf0e10cSrcweir 				 * just to retry lookup solves the problem. The problem
1706cdf0e10cSrcweir 				 * is not yet fully understood, so restrict 2nd lookup
1707cdf0e10cSrcweir 				 * to 7bit ascii chars */
1708cdf0e10cSrcweir 				if ( (XK_space <= nKeySym) && (XK_asciitilde >= nKeySym) )
1709cdf0e10cSrcweir 				{
1710cdf0e10cSrcweir 					*pLen = 1;
1711cdf0e10cSrcweir 					pPrintable[ 0 ] = (char)nKeySym;
1712cdf0e10cSrcweir 				}
1713cdf0e10cSrcweir 				break;
1714cdf0e10cSrcweir 			case XLookupBoth:
1715cdf0e10cSrcweir 			case XLookupChars:
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir 				/* nothing to, char allready in pPrintable */
1718cdf0e10cSrcweir 				break;
1719cdf0e10cSrcweir 		}
1720cdf0e10cSrcweir 	}
1721cdf0e10cSrcweir 
1722cdf0e10cSrcweir     if( !bNumLockFromXS_
1723cdf0e10cSrcweir         && (IsCursorKey(nKeySym)
1724cdf0e10cSrcweir             || IsFunctionKey(nKeySym)
1725cdf0e10cSrcweir             || IsKeypadKey(nKeySym)
1726cdf0e10cSrcweir             || XK_Delete == nKeySym ) )
1727cdf0e10cSrcweir     {
1728cdf0e10cSrcweir         // Bei einigen X-Servern muss man bei den Keypadtasten
1729cdf0e10cSrcweir         // schon sehr genau hinschauen. ZB. Solaris XServer:
1730cdf0e10cSrcweir         // 2, 4, 6, 8 werden als Cursorkeys klassifiziert (Up, Down, Left, Right
1731cdf0e10cSrcweir         // 1, 3, 5, 9 werden als Functionkeys klassifiziert (F27,F29,F33,F35)
1732cdf0e10cSrcweir         // 0 als Keypadkey und der Dezimalpunkt gar nicht (KP_Insert)
1733cdf0e10cSrcweir         KeySym nNewKeySym = XLookupKeysym( pEvent, nNumLockIndex_ );
1734cdf0e10cSrcweir         if( nNewKeySym != NoSymbol )
1735cdf0e10cSrcweir             nKeySym = nNewKeySym;
1736cdf0e10cSrcweir     }
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir     // Now get the unmodified KeySym for KeyCode retrieval
1739cdf0e10cSrcweir     // try to strip off modifiers, e.g. Ctrl-$ becomes Ctrl-Shift-4
1740*85372600SHerbert Dürr     *pUnmodifiedKeySym = XkbKeycodeToKeysym( GetDisplay(), pEvent->keycode, 0, 0 );
1741cdf0e10cSrcweir 
1742cdf0e10cSrcweir     return nKeySym;
1743cdf0e10cSrcweir }
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir // Pointer
1746cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1747cdf0e10cSrcweir #define MAKE_BITMAP( name ) \
1748cdf0e10cSrcweir     XCreateBitmapFromData( pDisp_, \
1749cdf0e10cSrcweir                            DefaultRootWindow( pDisp_ ), \
175030c1b1efSHerbert Dürr                            (const char*)name##_bits, \
1751cdf0e10cSrcweir                            name##_width, \
1752cdf0e10cSrcweir                            name##_height )
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir #define MAKE_CURSOR( name ) \
1755cdf0e10cSrcweir     aCursBitmap = MAKE_BITMAP( name##curs ); \
1756cdf0e10cSrcweir     aMaskBitmap = MAKE_BITMAP( name##mask ); \
1757cdf0e10cSrcweir     nXHot = name##curs_x_hot; \
1758cdf0e10cSrcweir     nYHot = name##curs_y_hot
1759cdf0e10cSrcweir 
GetPointer(int ePointerStyle)1760cdf0e10cSrcweir XLIB_Cursor SalDisplay::GetPointer( int ePointerStyle )
1761cdf0e10cSrcweir {
1762cdf0e10cSrcweir     if( ePointerStyle >= POINTER_COUNT )
1763cdf0e10cSrcweir         return 0;
1764cdf0e10cSrcweir 
1765cdf0e10cSrcweir     XLIB_Cursor &aCur = aPointerCache_[ePointerStyle];
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir     if( aCur != None )
1768cdf0e10cSrcweir         return aCur;
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir     Pixmap          aCursBitmap = None, aMaskBitmap = None;
1771cdf0e10cSrcweir     unsigned int    nXHot = 0, nYHot = 0;
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir     switch( ePointerStyle )
1774cdf0e10cSrcweir     {
1775cdf0e10cSrcweir 		case POINTER_NULL:
1776cdf0e10cSrcweir 			MAKE_CURSOR( null );
1777cdf0e10cSrcweir 			break;
1778cdf0e10cSrcweir         case POINTER_ARROW:
1779cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_left_ptr );
1780cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1781cdf0e10cSrcweir             break;
1782cdf0e10cSrcweir         case POINTER_WAIT:
1783cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_watch );
1784cdf0e10cSrcweir             break;
1785cdf0e10cSrcweir         case POINTER_TEXT:          // Mouse Pointer ist ein "I" Beam
1786cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_xterm );
1787cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1788cdf0e10cSrcweir             break;
1789cdf0e10cSrcweir         case POINTER_HELP:
1790cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_question_arrow );
1791cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1792cdf0e10cSrcweir             break;
1793cdf0e10cSrcweir         case POINTER_CROSS:         // Mouse Pointer ist ein Kreuz
1794cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_crosshair );
1795cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1796cdf0e10cSrcweir             break;
1797cdf0e10cSrcweir         case POINTER_NSIZE:
1798cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_sb_v_double_arrow );
1799cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1800cdf0e10cSrcweir             break;
1801cdf0e10cSrcweir         case POINTER_SSIZE:
1802cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_sb_v_double_arrow );
1803cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1804cdf0e10cSrcweir             break;
1805cdf0e10cSrcweir         case POINTER_WSIZE:
1806cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_sb_h_double_arrow );
1807cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1808cdf0e10cSrcweir             break;
1809cdf0e10cSrcweir         case POINTER_ESIZE:
1810cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_sb_h_double_arrow );
1811cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1812cdf0e10cSrcweir             break;
1813cdf0e10cSrcweir         case POINTER_WINDOW_NSIZE:
1814cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_top_side );
1815cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1816cdf0e10cSrcweir             break;
1817cdf0e10cSrcweir         case POINTER_WINDOW_SSIZE:
1818cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_bottom_side );
1819cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1820cdf0e10cSrcweir             break;
1821cdf0e10cSrcweir         case POINTER_WINDOW_WSIZE:
1822cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_left_side );
1823cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1824cdf0e10cSrcweir             break;
1825cdf0e10cSrcweir         case POINTER_WINDOW_ESIZE:
1826cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_right_side );
1827cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1828cdf0e10cSrcweir             break;
1829cdf0e10cSrcweir         case POINTER_NWSIZE:
1830cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_top_left_corner );
1831cdf0e10cSrcweir             break;
1832cdf0e10cSrcweir         case POINTER_NESIZE:
1833cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_top_right_corner );
1834cdf0e10cSrcweir             break;
1835cdf0e10cSrcweir         case POINTER_SWSIZE:
1836cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_bottom_left_corner );
1837cdf0e10cSrcweir             break;
1838cdf0e10cSrcweir         case POINTER_SESIZE:
1839cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_bottom_right_corner );
1840cdf0e10cSrcweir             break;
1841cdf0e10cSrcweir         case POINTER_WINDOW_NWSIZE:
1842cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_top_left_corner );
1843cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1844cdf0e10cSrcweir             break;
1845cdf0e10cSrcweir         case POINTER_WINDOW_NESIZE:
1846cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_top_right_corner );
1847cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1848cdf0e10cSrcweir             break;
1849cdf0e10cSrcweir         case POINTER_WINDOW_SWSIZE:
1850cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_bottom_left_corner );
1851cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1852cdf0e10cSrcweir             break;
1853cdf0e10cSrcweir         case POINTER_WINDOW_SESIZE:
1854cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_bottom_right_corner );
1855cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1856cdf0e10cSrcweir             break;
1857cdf0e10cSrcweir         case POINTER_HSPLIT:
1858cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_sb_h_double_arrow );
1859cdf0e10cSrcweir             break;
1860cdf0e10cSrcweir         case POINTER_VSPLIT:
1861cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_sb_v_double_arrow );
1862cdf0e10cSrcweir             break;
1863cdf0e10cSrcweir         case POINTER_HSIZEBAR:
1864cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_sb_h_double_arrow ); // ???
1865cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1866cdf0e10cSrcweir             break;
1867cdf0e10cSrcweir         case POINTER_VSIZEBAR:
1868cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_sb_v_double_arrow ); // ???
1869cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1870cdf0e10cSrcweir             break;
1871cdf0e10cSrcweir         case POINTER_REFHAND:
1872cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_hand1 );
1873cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1874cdf0e10cSrcweir             break;
1875cdf0e10cSrcweir         case POINTER_HAND:
1876cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_hand2 );
1877cdf0e10cSrcweir             break;
1878cdf0e10cSrcweir         case POINTER_MAGNIFY:
1879cdf0e10cSrcweir             MAKE_CURSOR( magnify_ );
1880cdf0e10cSrcweir             break;
1881cdf0e10cSrcweir         case POINTER_FILL:
1882cdf0e10cSrcweir             MAKE_CURSOR( fill_ );
1883cdf0e10cSrcweir             break;
1884cdf0e10cSrcweir         case POINTER_MOVE:
1885cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_fleur );
1886cdf0e10cSrcweir             break;
1887cdf0e10cSrcweir         case POINTER_MOVEDATA:
1888cdf0e10cSrcweir             MAKE_CURSOR( movedata_ );
1889cdf0e10cSrcweir             break;
1890cdf0e10cSrcweir         case POINTER_COPYDATA:
1891cdf0e10cSrcweir             MAKE_CURSOR( copydata_ );
1892cdf0e10cSrcweir             break;
1893cdf0e10cSrcweir         case POINTER_MOVEFILE:
1894cdf0e10cSrcweir             MAKE_CURSOR( movefile_ );
1895cdf0e10cSrcweir             break;
1896cdf0e10cSrcweir         case POINTER_COPYFILE:
1897cdf0e10cSrcweir             MAKE_CURSOR( copyfile_ );
1898cdf0e10cSrcweir             break;
1899cdf0e10cSrcweir         case POINTER_MOVEFILES:
1900cdf0e10cSrcweir             MAKE_CURSOR( movefiles_ );
1901cdf0e10cSrcweir             break;
1902cdf0e10cSrcweir         case POINTER_COPYFILES:
1903cdf0e10cSrcweir             MAKE_CURSOR( copyfiles_ );
1904cdf0e10cSrcweir             break;
1905cdf0e10cSrcweir         case POINTER_NOTALLOWED:
1906cdf0e10cSrcweir             MAKE_CURSOR( nodrop_ );
1907cdf0e10cSrcweir             break;
1908cdf0e10cSrcweir         case POINTER_ROTATE:
1909cdf0e10cSrcweir             MAKE_CURSOR( rotate_ );
1910cdf0e10cSrcweir             break;
1911cdf0e10cSrcweir         case POINTER_HSHEAR:
1912cdf0e10cSrcweir             MAKE_CURSOR( hshear_ );
1913cdf0e10cSrcweir             break;
1914cdf0e10cSrcweir         case POINTER_VSHEAR:
1915cdf0e10cSrcweir             MAKE_CURSOR( vshear_ );
1916cdf0e10cSrcweir             break;
1917cdf0e10cSrcweir         case POINTER_DRAW_LINE:
1918cdf0e10cSrcweir             MAKE_CURSOR( drawline_ );
1919cdf0e10cSrcweir             break;
1920cdf0e10cSrcweir         case POINTER_DRAW_RECT:
1921cdf0e10cSrcweir             MAKE_CURSOR( drawrect_ );
1922cdf0e10cSrcweir             break;
1923cdf0e10cSrcweir         case POINTER_DRAW_POLYGON:
1924cdf0e10cSrcweir             MAKE_CURSOR( drawpolygon_ );
1925cdf0e10cSrcweir             break;
1926cdf0e10cSrcweir         case POINTER_DRAW_BEZIER:
1927cdf0e10cSrcweir             MAKE_CURSOR( drawbezier_ );
1928cdf0e10cSrcweir             break;
1929cdf0e10cSrcweir         case POINTER_DRAW_ARC:
1930cdf0e10cSrcweir             MAKE_CURSOR( drawarc_ );
1931cdf0e10cSrcweir             break;
1932cdf0e10cSrcweir         case POINTER_DRAW_PIE:
1933cdf0e10cSrcweir             MAKE_CURSOR( drawpie_ );
1934cdf0e10cSrcweir             break;
1935cdf0e10cSrcweir         case POINTER_DRAW_CIRCLECUT:
1936cdf0e10cSrcweir             MAKE_CURSOR( drawcirclecut_ );
1937cdf0e10cSrcweir             break;
1938cdf0e10cSrcweir         case POINTER_DRAW_ELLIPSE:
1939cdf0e10cSrcweir             MAKE_CURSOR( drawellipse_ );
1940cdf0e10cSrcweir             break;
1941cdf0e10cSrcweir         case POINTER_DRAW_CONNECT:
1942cdf0e10cSrcweir             MAKE_CURSOR( drawconnect_ );
1943cdf0e10cSrcweir             break;
1944cdf0e10cSrcweir         case POINTER_DRAW_TEXT:
1945cdf0e10cSrcweir             MAKE_CURSOR( drawtext_ );
1946cdf0e10cSrcweir             break;
1947cdf0e10cSrcweir         case POINTER_MIRROR:
1948cdf0e10cSrcweir             MAKE_CURSOR( mirror_ );
1949cdf0e10cSrcweir             break;
1950cdf0e10cSrcweir         case POINTER_CROOK:
1951cdf0e10cSrcweir             MAKE_CURSOR( crook_ );
1952cdf0e10cSrcweir             break;
1953cdf0e10cSrcweir         case POINTER_CROP:
1954cdf0e10cSrcweir             MAKE_CURSOR( crop_ );
1955cdf0e10cSrcweir             break;
1956cdf0e10cSrcweir         case POINTER_MOVEPOINT:
1957cdf0e10cSrcweir             MAKE_CURSOR( movepoint_ );
1958cdf0e10cSrcweir             break;
1959cdf0e10cSrcweir         case POINTER_MOVEBEZIERWEIGHT:
1960cdf0e10cSrcweir             MAKE_CURSOR( movebezierweight_ );
1961cdf0e10cSrcweir             break;
1962cdf0e10cSrcweir         case POINTER_DRAW_FREEHAND:
1963cdf0e10cSrcweir             MAKE_CURSOR( drawfreehand_ );
1964cdf0e10cSrcweir             break;
1965cdf0e10cSrcweir         case POINTER_DRAW_CAPTION:
1966cdf0e10cSrcweir             MAKE_CURSOR( drawcaption_ );
1967cdf0e10cSrcweir             break;
1968cdf0e10cSrcweir         case POINTER_PEN:       // Mouse Pointer ist ein Stift
1969cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_pencil );
1970cdf0e10cSrcweir             DBG_ASSERT( aCur != None, "GetPointer: Could not define cursor" );
1971cdf0e10cSrcweir             break;
1972cdf0e10cSrcweir         case POINTER_LINKDATA:
1973cdf0e10cSrcweir             MAKE_CURSOR( linkdata_ );
1974cdf0e10cSrcweir             break;
1975cdf0e10cSrcweir         case POINTER_MOVEDATALINK:
1976cdf0e10cSrcweir             MAKE_CURSOR( movedlnk_ );
1977cdf0e10cSrcweir             break;
1978cdf0e10cSrcweir         case POINTER_COPYDATALINK:
1979cdf0e10cSrcweir             MAKE_CURSOR( copydlnk_ );
1980cdf0e10cSrcweir             break;
1981cdf0e10cSrcweir         case POINTER_LINKFILE:
1982cdf0e10cSrcweir             MAKE_CURSOR( linkfile_ );
1983cdf0e10cSrcweir             break;
1984cdf0e10cSrcweir         case POINTER_MOVEFILELINK:
1985cdf0e10cSrcweir             MAKE_CURSOR( moveflnk_ );
1986cdf0e10cSrcweir             break;
1987cdf0e10cSrcweir         case POINTER_COPYFILELINK:
1988cdf0e10cSrcweir             MAKE_CURSOR( copyflnk_ );
1989cdf0e10cSrcweir             break;
1990cdf0e10cSrcweir         case POINTER_CHART:
1991cdf0e10cSrcweir             MAKE_CURSOR( chart_ );
1992cdf0e10cSrcweir             break;
1993cdf0e10cSrcweir         case POINTER_DETECTIVE:
1994cdf0e10cSrcweir             MAKE_CURSOR( detective_ );
1995cdf0e10cSrcweir             break;
1996cdf0e10cSrcweir         case POINTER_PIVOT_COL:
1997cdf0e10cSrcweir             MAKE_CURSOR( pivotcol_ );
1998cdf0e10cSrcweir             break;
1999cdf0e10cSrcweir         case POINTER_PIVOT_ROW:
2000cdf0e10cSrcweir             MAKE_CURSOR( pivotrow_ );
2001cdf0e10cSrcweir             break;
2002cdf0e10cSrcweir         case POINTER_PIVOT_FIELD:
2003cdf0e10cSrcweir             MAKE_CURSOR( pivotfld_ );
2004cdf0e10cSrcweir             break;
2005cdf0e10cSrcweir         case POINTER_PIVOT_DELETE:
2006cdf0e10cSrcweir             MAKE_CURSOR( pivotdel_ );
2007cdf0e10cSrcweir             break;
2008cdf0e10cSrcweir         case POINTER_CHAIN:
2009cdf0e10cSrcweir             MAKE_CURSOR( chain_ );
2010cdf0e10cSrcweir             break;
2011cdf0e10cSrcweir         case POINTER_CHAIN_NOTALLOWED:
2012cdf0e10cSrcweir             MAKE_CURSOR( chainnot_ );
2013cdf0e10cSrcweir             break;
2014cdf0e10cSrcweir         case POINTER_TIMEEVENT_MOVE:
2015cdf0e10cSrcweir             MAKE_CURSOR( timemove_ );
2016cdf0e10cSrcweir             break;
2017cdf0e10cSrcweir         case POINTER_TIMEEVENT_SIZE:
2018cdf0e10cSrcweir             MAKE_CURSOR( timesize_ );
2019cdf0e10cSrcweir             break;
2020cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_N:
2021cdf0e10cSrcweir             MAKE_CURSOR(asn_ );
2022cdf0e10cSrcweir             break;
2023cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_S:
2024cdf0e10cSrcweir             MAKE_CURSOR( ass_ );
2025cdf0e10cSrcweir             break;
2026cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_W:
2027cdf0e10cSrcweir             MAKE_CURSOR( asw_ );
2028cdf0e10cSrcweir             break;
2029cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_E:
2030cdf0e10cSrcweir             MAKE_CURSOR( ase_ );
2031cdf0e10cSrcweir             break;
2032cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_NW:
2033cdf0e10cSrcweir             MAKE_CURSOR( asnw_ );
2034cdf0e10cSrcweir             break;
2035cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_NE:
2036cdf0e10cSrcweir             MAKE_CURSOR( asne_ );
2037cdf0e10cSrcweir             break;
2038cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_SW:
2039cdf0e10cSrcweir             MAKE_CURSOR( assw_ );
2040cdf0e10cSrcweir             break;
2041cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_SE:
2042cdf0e10cSrcweir             MAKE_CURSOR( asse_ );
2043cdf0e10cSrcweir             break;
2044cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_NS:
2045cdf0e10cSrcweir             MAKE_CURSOR( asns_ );
2046cdf0e10cSrcweir             break;
2047cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_WE:
2048cdf0e10cSrcweir             MAKE_CURSOR( aswe_ );
2049cdf0e10cSrcweir             break;
2050cdf0e10cSrcweir 		case POINTER_AUTOSCROLL_NSWE:
2051cdf0e10cSrcweir             MAKE_CURSOR( asnswe_ );
2052cdf0e10cSrcweir             break;
2053cdf0e10cSrcweir 		case POINTER_AIRBRUSH:
2054cdf0e10cSrcweir 			MAKE_CURSOR( airbrush_ );
2055cdf0e10cSrcweir 			break;
2056cdf0e10cSrcweir 		case POINTER_TEXT_VERTICAL:
2057cdf0e10cSrcweir 			MAKE_CURSOR( vertcurs_ );
2058cdf0e10cSrcweir 			break;
2059cdf0e10cSrcweir 
2060cdf0e10cSrcweir         // --> FME 2004-07-30 #i32329# Enhanced table selection
2061cdf0e10cSrcweir         case POINTER_TAB_SELECT_S:
2062cdf0e10cSrcweir             MAKE_CURSOR( tblsels_ );
2063cdf0e10cSrcweir             break;
2064cdf0e10cSrcweir         case POINTER_TAB_SELECT_E:
2065cdf0e10cSrcweir             MAKE_CURSOR( tblsele_ );
2066cdf0e10cSrcweir             break;
2067cdf0e10cSrcweir         case POINTER_TAB_SELECT_SE:
2068cdf0e10cSrcweir             MAKE_CURSOR( tblselse_ );
2069cdf0e10cSrcweir             break;
2070cdf0e10cSrcweir         case POINTER_TAB_SELECT_W:
2071cdf0e10cSrcweir             MAKE_CURSOR( tblselw_ );
2072cdf0e10cSrcweir             break;
2073cdf0e10cSrcweir         case POINTER_TAB_SELECT_SW:
2074cdf0e10cSrcweir             MAKE_CURSOR( tblselsw_ );
2075cdf0e10cSrcweir             break;
2076cdf0e10cSrcweir         // <--
2077cdf0e10cSrcweir 
2078cdf0e10cSrcweir         // --> FME 2004-08-16 #i20119# Paintbrush tool
2079cdf0e10cSrcweir         case POINTER_PAINTBRUSH :
2080cdf0e10cSrcweir             MAKE_CURSOR( paintbrush_ );
2081cdf0e10cSrcweir             break;
2082cdf0e10cSrcweir         // <--
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir         default:
2085cdf0e10cSrcweir             DBG_ERROR("pointer not implemented");
2086cdf0e10cSrcweir             aCur = XCreateFontCursor( pDisp_, XC_arrow );
2087cdf0e10cSrcweir             break;
2088cdf0e10cSrcweir     }
2089cdf0e10cSrcweir 
2090cdf0e10cSrcweir     if( None == aCur )
2091cdf0e10cSrcweir     {
2092cdf0e10cSrcweir         XColor      aBlack, aWhite, aDummy;
2093cdf0e10cSrcweir         Colormap    hColormap = GetColormap(m_nDefaultScreen).GetXColormap();
2094cdf0e10cSrcweir 
2095cdf0e10cSrcweir         XAllocNamedColor( pDisp_, hColormap, "black", &aBlack, &aDummy );
2096cdf0e10cSrcweir         XAllocNamedColor( pDisp_, hColormap, "white", &aWhite, &aDummy );
2097cdf0e10cSrcweir 
2098cdf0e10cSrcweir         aCur = XCreatePixmapCursor( pDisp_,
2099cdf0e10cSrcweir                                     aCursBitmap, aMaskBitmap,
2100cdf0e10cSrcweir                                     &aBlack, &aWhite,
2101cdf0e10cSrcweir                                     nXHot, nYHot );
2102cdf0e10cSrcweir 
2103cdf0e10cSrcweir         XFreePixmap( pDisp_, aCursBitmap );
2104cdf0e10cSrcweir         XFreePixmap( pDisp_, aMaskBitmap );
2105cdf0e10cSrcweir     }
2106cdf0e10cSrcweir 
2107cdf0e10cSrcweir     return aCur;
2108cdf0e10cSrcweir }
2109cdf0e10cSrcweir 
CaptureMouse(SalFrame * pCapture)2110cdf0e10cSrcweir int SalDisplay::CaptureMouse( SalFrame *pCapture )
2111cdf0e10cSrcweir {
2112cdf0e10cSrcweir     if( !pCapture )
2113cdf0e10cSrcweir     {
2114cdf0e10cSrcweir         m_pCapture = NULL;
2115cdf0e10cSrcweir         XUngrabPointer( GetDisplay(), CurrentTime );
2116cdf0e10cSrcweir 		XFlush( GetDisplay() );
2117cdf0e10cSrcweir         return 0;
2118cdf0e10cSrcweir     }
2119cdf0e10cSrcweir 
2120cdf0e10cSrcweir     m_pCapture = NULL;
2121cdf0e10cSrcweir 
2122cdf0e10cSrcweir     // FIXME: get rid of X11SalFrame
2123cdf0e10cSrcweir     const SystemEnvData* pEnvData = pCapture->GetSystemData();
2124cdf0e10cSrcweir     int ret = XGrabPointer( GetDisplay(),
2125cdf0e10cSrcweir                             (XLIB_Window)pEnvData->aWindow,
2126cdf0e10cSrcweir                             False,
2127cdf0e10cSrcweir                             PointerMotionMask| ButtonPressMask|ButtonReleaseMask,
2128cdf0e10cSrcweir                             GrabModeAsync,
2129cdf0e10cSrcweir                             GrabModeAsync,
2130cdf0e10cSrcweir                             None,
2131cdf0e10cSrcweir                             static_cast<X11SalFrame*>(pCapture)->GetCursor(),
2132cdf0e10cSrcweir                             CurrentTime );
2133cdf0e10cSrcweir 
2134cdf0e10cSrcweir     if( ret != GrabSuccess )
2135cdf0e10cSrcweir     {
2136cdf0e10cSrcweir         DBG_ASSERT( 1, "SalDisplay::CaptureMouse could not grab pointer\n");
2137cdf0e10cSrcweir         return -1;
2138cdf0e10cSrcweir     }
2139cdf0e10cSrcweir 
2140cdf0e10cSrcweir     m_pCapture = pCapture;
2141cdf0e10cSrcweir     return 1;
2142cdf0e10cSrcweir }
2143cdf0e10cSrcweir 
2144cdf0e10cSrcweir // Events
2145cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2146cdf0e10cSrcweir 
SendInternalEvent(SalFrame * pFrame,void * pData,sal_uInt16 nEvent)2147cdf0e10cSrcweir void SalDisplay::SendInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
2148cdf0e10cSrcweir {
2149cdf0e10cSrcweir 	if( osl_acquireMutex( hEventGuard_ ) )
2150cdf0e10cSrcweir     {
2151cdf0e10cSrcweir         m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
2152cdf0e10cSrcweir 
2153cdf0e10cSrcweir 		// Notify SalXLib::Yield() of a pending event.
2154cdf0e10cSrcweir 		pXLib_->PostUserEvent();
2155cdf0e10cSrcweir 
2156cdf0e10cSrcweir         osl_releaseMutex( hEventGuard_ );
2157cdf0e10cSrcweir     }
2158cdf0e10cSrcweir     else {
2159cdf0e10cSrcweir         DBG_ASSERT( 1, "SalDisplay::SendInternalEvent !acquireMutex\n" );
2160cdf0e10cSrcweir     }
2161cdf0e10cSrcweir }
2162cdf0e10cSrcweir 
CancelInternalEvent(SalFrame * pFrame,void * pData,sal_uInt16 nEvent)2163cdf0e10cSrcweir void SalDisplay::CancelInternalEvent( SalFrame* pFrame, void* pData, sal_uInt16 nEvent )
2164cdf0e10cSrcweir {
2165cdf0e10cSrcweir 	if( osl_acquireMutex( hEventGuard_ ) )
2166cdf0e10cSrcweir     {
2167cdf0e10cSrcweir         if( ! m_aUserEvents.empty() )
2168cdf0e10cSrcweir         {
2169cdf0e10cSrcweir             std::list< SalUserEvent >::iterator it, next;
2170cdf0e10cSrcweir             next = m_aUserEvents.begin();
2171cdf0e10cSrcweir             do
2172cdf0e10cSrcweir             {
2173cdf0e10cSrcweir                 it = next++;
2174cdf0e10cSrcweir                 if( it->m_pFrame    == pFrame   &&
2175cdf0e10cSrcweir                     it->m_pData     == pData    &&
2176cdf0e10cSrcweir                     it->m_nEvent    == nEvent )
2177cdf0e10cSrcweir                 {
2178cdf0e10cSrcweir                     m_aUserEvents.erase( it );
2179cdf0e10cSrcweir                 }
2180cdf0e10cSrcweir             } while( next != m_aUserEvents.end() );
2181cdf0e10cSrcweir         }
2182cdf0e10cSrcweir 
2183cdf0e10cSrcweir         osl_releaseMutex( hEventGuard_ );
2184cdf0e10cSrcweir     }
2185cdf0e10cSrcweir     else {
2186cdf0e10cSrcweir         DBG_ASSERT( 1, "SalDisplay::CancelInternalEvent !acquireMutex\n" );
2187cdf0e10cSrcweir     }
2188cdf0e10cSrcweir }
2189cdf0e10cSrcweir 
IsEvent()2190cdf0e10cSrcweir sal_Bool SalX11Display::IsEvent()
2191cdf0e10cSrcweir {
2192cdf0e10cSrcweir     sal_Bool bRet = sal_False;
2193cdf0e10cSrcweir 
2194cdf0e10cSrcweir     if( osl_acquireMutex( hEventGuard_ ) )
2195cdf0e10cSrcweir     {
2196cdf0e10cSrcweir         if( m_aUserEvents.begin() != m_aUserEvents.end() )
2197cdf0e10cSrcweir             bRet = sal_True;
2198cdf0e10cSrcweir         osl_releaseMutex( hEventGuard_ );
2199cdf0e10cSrcweir     }
2200cdf0e10cSrcweir 
2201cdf0e10cSrcweir     if( bRet || XEventsQueued( pDisp_, QueuedAlready ) )
2202cdf0e10cSrcweir         return sal_True;
2203cdf0e10cSrcweir 
2204cdf0e10cSrcweir     XFlush( pDisp_ );
2205cdf0e10cSrcweir     return sal_False;
2206cdf0e10cSrcweir }
2207cdf0e10cSrcweir 
DispatchInternalEvent()2208cdf0e10cSrcweir bool SalDisplay::DispatchInternalEvent()
2209cdf0e10cSrcweir {
2210cdf0e10cSrcweir     SalFrame* pFrame = NULL;
2211cdf0e10cSrcweir     void* pData = NULL;
2212cdf0e10cSrcweir     sal_uInt16 nEvent = 0;
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir     if( osl_acquireMutex( hEventGuard_ ) )
2215cdf0e10cSrcweir     {
2216cdf0e10cSrcweir         if( m_aUserEvents.begin() != m_aUserEvents.end() )
2217cdf0e10cSrcweir         {
2218cdf0e10cSrcweir             pFrame	= m_aUserEvents.front().m_pFrame;
2219cdf0e10cSrcweir             pData	= m_aUserEvents.front().m_pData;
2220cdf0e10cSrcweir             nEvent	= m_aUserEvents.front().m_nEvent;
2221cdf0e10cSrcweir 
2222cdf0e10cSrcweir             m_aUserEvents.pop_front();
2223cdf0e10cSrcweir         }
2224cdf0e10cSrcweir         osl_releaseMutex( hEventGuard_ );
2225cdf0e10cSrcweir     }
2226cdf0e10cSrcweir     else {
2227cdf0e10cSrcweir         DBG_ASSERT( 1, "SalDisplay::Yield !acquireMutex\n" );
2228cdf0e10cSrcweir     }
2229cdf0e10cSrcweir 
2230cdf0e10cSrcweir     if( pFrame )
2231cdf0e10cSrcweir         pFrame->CallCallback( nEvent, pData );
2232cdf0e10cSrcweir 
2233cdf0e10cSrcweir     return pFrame != NULL;
2234cdf0e10cSrcweir }
2235cdf0e10cSrcweir 
2236cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2237cdf0e10cSrcweir 
Yield()2238cdf0e10cSrcweir void SalX11Display::Yield()
2239cdf0e10cSrcweir {
2240cdf0e10cSrcweir     if( DispatchInternalEvent() )
2241cdf0e10cSrcweir         return;
2242cdf0e10cSrcweir 
2243cdf0e10cSrcweir     XEvent aEvent;
2244cdf0e10cSrcweir     DBG_ASSERT( static_cast<SalYieldMutex*>(GetSalData()->m_pInstance->GetYieldMutex())->GetThreadId() ==
2245cdf0e10cSrcweir                 vos::OThread::getCurrentIdentifier(),
2246cdf0e10cSrcweir                 "will crash soon since solar mutex not locked in SalDisplay::Yield" );
2247cdf0e10cSrcweir 
2248cdf0e10cSrcweir     XNextEvent( pDisp_, &aEvent );
2249cdf0e10cSrcweir 
2250cdf0e10cSrcweir     Dispatch( &aEvent );
2251cdf0e10cSrcweir 
2252cdf0e10cSrcweir #ifdef DBG_UTIL
2253cdf0e10cSrcweir     if( pXLib_->HasXErrorOccured() )
2254cdf0e10cSrcweir     {
2255cdf0e10cSrcweir         XFlush( pDisp_ );
2256cdf0e10cSrcweir         PrintEvent( "SalDisplay::Yield (WasXError)", &aEvent );
2257cdf0e10cSrcweir     }
2258cdf0e10cSrcweir #endif
2259cdf0e10cSrcweir     pXLib_->ResetXErrorOccured();
2260cdf0e10cSrcweir }
2261cdf0e10cSrcweir 
Dispatch(XEvent * pEvent)2262cdf0e10cSrcweir long SalX11Display::Dispatch( XEvent *pEvent )
2263cdf0e10cSrcweir {
2264cdf0e10cSrcweir 	if( pEvent->type == XLIB_KeyPress || pEvent->type == KeyRelease )
2265cdf0e10cSrcweir     {
2266cdf0e10cSrcweir 	    XLIB_Window aWindow = pEvent->xkey.window;
2267cdf0e10cSrcweir 
2268cdf0e10cSrcweir         std::list< SalFrame* >::const_iterator it;
2269cdf0e10cSrcweir         for( it = m_aFrames.begin(); it != m_aFrames.end(); ++it )
2270cdf0e10cSrcweir         {
2271cdf0e10cSrcweir             const X11SalFrame* pFrame = static_cast< const X11SalFrame* >(*it);
2272cdf0e10cSrcweir             if( pFrame->GetWindow() == aWindow || pFrame->GetShellWindow() == aWindow )
2273cdf0e10cSrcweir             {
2274cdf0e10cSrcweir                 aWindow = pFrame->GetWindow();
2275cdf0e10cSrcweir                 break;
2276cdf0e10cSrcweir             }
2277cdf0e10cSrcweir         }
2278cdf0e10cSrcweir 	    if( it != m_aFrames.end() )
2279cdf0e10cSrcweir         {
2280cdf0e10cSrcweir             if ( mpInputMethod->FilterEvent( pEvent , aWindow ) )
2281cdf0e10cSrcweir                 return 0;
2282cdf0e10cSrcweir 	    }
2283cdf0e10cSrcweir     }
2284cdf0e10cSrcweir 	else
2285cdf0e10cSrcweir         if ( mpInputMethod->FilterEvent( pEvent, None ) )
2286cdf0e10cSrcweir             return 0;
2287cdf0e10cSrcweir 
2288cdf0e10cSrcweir 	SalInstance* pInstance = GetSalData()->m_pInstance;
2289cdf0e10cSrcweir 	pInstance->CallEventCallback( pEvent, sizeof( XEvent ) );
2290cdf0e10cSrcweir 
2291cdf0e10cSrcweir     switch( pEvent->type )
2292cdf0e10cSrcweir     {
2293cdf0e10cSrcweir         case MotionNotify:
2294cdf0e10cSrcweir             while( XCheckWindowEvent( pEvent->xany.display,
2295cdf0e10cSrcweir                                       pEvent->xany.window,
2296cdf0e10cSrcweir                                       ButtonMotionMask,
2297cdf0e10cSrcweir                                       pEvent ) )
2298cdf0e10cSrcweir                 ;
2299cdf0e10cSrcweir             m_nLastUserEventTime = pEvent->xmotion.time;
2300cdf0e10cSrcweir             break;
2301cdf0e10cSrcweir         case PropertyNotify:
2302cdf0e10cSrcweir             if( pEvent->xproperty.atom == getWMAdaptor()->getAtom( WMAdaptor::VCL_SYSTEM_SETTINGS ) )
2303cdf0e10cSrcweir             {
2304cdf0e10cSrcweir                 for( unsigned int i = 0; i < m_aScreens.size(); i++ )
2305cdf0e10cSrcweir                 {
2306cdf0e10cSrcweir                     if( pEvent->xproperty.window == m_aScreens[i].m_aRefWindow )
2307cdf0e10cSrcweir                     {
2308cdf0e10cSrcweir                         std::list< SalFrame* >::const_iterator it;
2309cdf0e10cSrcweir                         for( it = m_aFrames.begin(); it != m_aFrames.end(); ++it )
2310cdf0e10cSrcweir                             (*it)->CallCallback( SALEVENT_SETTINGSCHANGED, NULL );
2311cdf0e10cSrcweir                         return 0;
2312cdf0e10cSrcweir                     }
2313cdf0e10cSrcweir                 }
2314cdf0e10cSrcweir             }
2315cdf0e10cSrcweir             break;
2316cdf0e10cSrcweir         case MappingNotify:
2317cdf0e10cSrcweir             if( MappingKeyboard == pEvent->xmapping.request ||
2318cdf0e10cSrcweir                 MappingModifier == pEvent->xmapping.request )
2319cdf0e10cSrcweir             {
2320cdf0e10cSrcweir                 XRefreshKeyboardMapping( &pEvent->xmapping );
2321cdf0e10cSrcweir                 if( MappingModifier == pEvent->xmapping.request )
2322cdf0e10cSrcweir                     ModifierMapping();
2323cdf0e10cSrcweir                 if( MappingKeyboard == pEvent->xmapping.request ) // refresh mapping
2324cdf0e10cSrcweir                     GetKeyboardName( sal_True );
2325cdf0e10cSrcweir             }
2326cdf0e10cSrcweir             break;
2327cdf0e10cSrcweir         case ButtonPress:
2328cdf0e10cSrcweir         case ButtonRelease:
2329cdf0e10cSrcweir             m_nLastUserEventTime = pEvent->xbutton.time;
2330cdf0e10cSrcweir             break;
2331cdf0e10cSrcweir         case XLIB_KeyPress:
2332cdf0e10cSrcweir         case KeyRelease:
2333cdf0e10cSrcweir             m_nLastUserEventTime = pEvent->xkey.time;
2334cdf0e10cSrcweir             break;
2335cdf0e10cSrcweir 		default:
2336cdf0e10cSrcweir 
2337cdf0e10cSrcweir 			if (   GetKbdExtension()->UseExtension()
2338cdf0e10cSrcweir 				&& GetKbdExtension()->GetEventBase() == pEvent->type )
2339cdf0e10cSrcweir 			{
2340cdf0e10cSrcweir 				GetKbdExtension()->Dispatch( pEvent );
2341cdf0e10cSrcweir 				return 1;
2342cdf0e10cSrcweir 			}
2343cdf0e10cSrcweir             break;
2344cdf0e10cSrcweir     }
2345cdf0e10cSrcweir 
2346cdf0e10cSrcweir     std::list< SalFrame* >::iterator it;
2347cdf0e10cSrcweir     for( it = m_aFrames.begin(); it != m_aFrames.end(); ++it )
2348cdf0e10cSrcweir     {
2349cdf0e10cSrcweir         X11SalFrame* pFrame = static_cast< X11SalFrame* >(*it);
2350cdf0e10cSrcweir         XLIB_Window aDispatchWindow = pEvent->xany.window;
2351cdf0e10cSrcweir         if( pFrame->GetWindow() == aDispatchWindow
2352cdf0e10cSrcweir             || pFrame->GetShellWindow() == aDispatchWindow
2353cdf0e10cSrcweir             || pFrame->GetForeignParent() == aDispatchWindow
2354cdf0e10cSrcweir 			)
2355cdf0e10cSrcweir 		{
2356cdf0e10cSrcweir 			return pFrame->Dispatch( pEvent );
2357cdf0e10cSrcweir 		}
2358cdf0e10cSrcweir 		if( pEvent->type == ConfigureNotify && pEvent->xconfigure.window == pFrame->GetStackingWindow() )
2359cdf0e10cSrcweir 		{
2360cdf0e10cSrcweir 			return pFrame->Dispatch( pEvent );
2361cdf0e10cSrcweir 		}
2362cdf0e10cSrcweir     }
2363cdf0e10cSrcweir 
2364cdf0e10cSrcweir 	// dispatch to salobjects
2365cdf0e10cSrcweir 	X11SalObject::Dispatch( pEvent );
2366cdf0e10cSrcweir 
2367cdf0e10cSrcweir     // is this perhaps a root window that changed size ?
2368cdf0e10cSrcweir     processRandREvent( pEvent );
2369cdf0e10cSrcweir 
2370cdf0e10cSrcweir     return 0;
2371cdf0e10cSrcweir }
2372cdf0e10cSrcweir 
2373cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PrintEvent(const ByteString & rComment,XEvent * pEvent) const2374cdf0e10cSrcweir void SalDisplay::PrintEvent( const ByteString &rComment,
2375cdf0e10cSrcweir                                    XEvent       *pEvent ) const
2376cdf0e10cSrcweir {
2377cdf0e10cSrcweir     if( pEvent->type <= MappingNotify )
2378cdf0e10cSrcweir     {
2379cdf0e10cSrcweir         fprintf( stderr, "[%s] %s s=%d w=%ld\n",
2380cdf0e10cSrcweir                  rComment.GetBuffer(),
2381cdf0e10cSrcweir                  EventNames[pEvent->type],
2382cdf0e10cSrcweir                  pEvent->xany.send_event,
2383cdf0e10cSrcweir                  pEvent->xany.window );
2384cdf0e10cSrcweir 
2385cdf0e10cSrcweir         switch( pEvent->type )
2386cdf0e10cSrcweir         {
2387cdf0e10cSrcweir             case XLIB_KeyPress:
2388cdf0e10cSrcweir             case KeyRelease:
2389cdf0e10cSrcweir                 fprintf( stderr, "\t\ts=%d c=%d\n",
2390cdf0e10cSrcweir                          pEvent->xkey.state,
2391cdf0e10cSrcweir                          pEvent->xkey.keycode );
2392cdf0e10cSrcweir                 break;
2393cdf0e10cSrcweir 
2394cdf0e10cSrcweir             case ButtonPress:
2395cdf0e10cSrcweir             case ButtonRelease:
2396cdf0e10cSrcweir                 fprintf( stderr, "\t\ts=%d b=%d x=%d y=%d rx=%d ry=%d\n",
2397cdf0e10cSrcweir                          pEvent->xbutton.state,
2398cdf0e10cSrcweir                          pEvent->xbutton.button,
2399cdf0e10cSrcweir                          pEvent->xbutton.x,
2400cdf0e10cSrcweir                          pEvent->xbutton.y,
2401cdf0e10cSrcweir                          pEvent->xbutton.x_root,
2402cdf0e10cSrcweir                          pEvent->xbutton.y_root );
2403cdf0e10cSrcweir                 break;
2404cdf0e10cSrcweir 
2405cdf0e10cSrcweir             case MotionNotify:
2406cdf0e10cSrcweir                 fprintf( stderr, "\t\ts=%d x=%d y=%d\n",
2407cdf0e10cSrcweir                          pEvent->xmotion.state,
2408cdf0e10cSrcweir                          pEvent->xmotion.x,
2409cdf0e10cSrcweir                          pEvent->xmotion.y );
2410cdf0e10cSrcweir                 break;
2411cdf0e10cSrcweir 
2412cdf0e10cSrcweir             case EnterNotify:
2413cdf0e10cSrcweir             case LeaveNotify:
2414cdf0e10cSrcweir                 fprintf( stderr, "\t\tm=%d f=%d x=%d y=%d\n",
2415cdf0e10cSrcweir                          pEvent->xcrossing.mode,
2416cdf0e10cSrcweir                          pEvent->xcrossing.focus,
2417cdf0e10cSrcweir                          pEvent->xcrossing.x,
2418cdf0e10cSrcweir                          pEvent->xcrossing.y );
2419cdf0e10cSrcweir                 break;
2420cdf0e10cSrcweir 
2421cdf0e10cSrcweir             case FocusIn:
2422cdf0e10cSrcweir             case FocusOut:
2423cdf0e10cSrcweir                 fprintf( stderr, "\t\tm=%d d=%d\n",
2424cdf0e10cSrcweir                          pEvent->xfocus.mode,
2425cdf0e10cSrcweir                          pEvent->xfocus.detail );
2426cdf0e10cSrcweir                 break;
2427cdf0e10cSrcweir 
2428cdf0e10cSrcweir             case Expose:
2429cdf0e10cSrcweir             case GraphicsExpose:
2430cdf0e10cSrcweir                 fprintf( stderr, "\t\tc=%d %d*%d %d+%d\n",
2431cdf0e10cSrcweir                          pEvent->xexpose.count,
2432cdf0e10cSrcweir                          pEvent->xexpose.width,
2433cdf0e10cSrcweir                          pEvent->xexpose.height,
2434cdf0e10cSrcweir                          pEvent->xexpose.x,
2435cdf0e10cSrcweir                          pEvent->xexpose.y );
2436cdf0e10cSrcweir                 break;
2437cdf0e10cSrcweir 
2438cdf0e10cSrcweir             case VisibilityNotify:
2439cdf0e10cSrcweir                 fprintf( stderr, "\t\ts=%d\n",
2440cdf0e10cSrcweir                          pEvent->xvisibility.state );
2441cdf0e10cSrcweir                 break;
2442cdf0e10cSrcweir 
2443cdf0e10cSrcweir             case CreateNotify:
2444cdf0e10cSrcweir             case DestroyNotify:
2445cdf0e10cSrcweir                 break;
2446cdf0e10cSrcweir 
2447cdf0e10cSrcweir             case MapNotify:
2448cdf0e10cSrcweir             case UnmapNotify:
2449cdf0e10cSrcweir                 break;
2450cdf0e10cSrcweir 
2451cdf0e10cSrcweir             case ReparentNotify:
2452cdf0e10cSrcweir                 fprintf( stderr, "\t\tp=%d x=%d y=%d\n",
2453cdf0e10cSrcweir                          sal::static_int_cast< int >(pEvent->xreparent.parent),
2454cdf0e10cSrcweir                          pEvent->xreparent.x,
2455cdf0e10cSrcweir                          pEvent->xreparent.y );
2456cdf0e10cSrcweir                 break;
2457cdf0e10cSrcweir 
2458cdf0e10cSrcweir             case ConfigureNotify:
2459cdf0e10cSrcweir                 fprintf( stderr, "\t\tb=%d %d*%d %d+%d\n",
2460cdf0e10cSrcweir                          pEvent->xconfigure.border_width,
2461cdf0e10cSrcweir                          pEvent->xconfigure.width,
2462cdf0e10cSrcweir                          pEvent->xconfigure.height,
2463cdf0e10cSrcweir                          pEvent->xconfigure.x,
2464cdf0e10cSrcweir                          pEvent->xconfigure.y );
2465cdf0e10cSrcweir                 break;
2466cdf0e10cSrcweir 
2467cdf0e10cSrcweir             case PropertyNotify:
2468cdf0e10cSrcweir                 fprintf( stderr, "\t\ta=%s (0x%X)\n",
2469cdf0e10cSrcweir                          GetAtomName( pDisp_, pEvent->xproperty.atom ),
2470cdf0e10cSrcweir                          sal::static_int_cast< unsigned int >(
2471cdf0e10cSrcweir                              pEvent->xproperty.atom) );
2472cdf0e10cSrcweir                 break;
2473cdf0e10cSrcweir 
2474cdf0e10cSrcweir             case ColormapNotify:
2475cdf0e10cSrcweir                 fprintf( stderr, "\t\tc=%ld n=%d s=%d\n",
2476cdf0e10cSrcweir                          pEvent->xcolormap.colormap,
2477cdf0e10cSrcweir                          pEvent->xcolormap.c_new,
2478cdf0e10cSrcweir                          pEvent->xcolormap.state );
2479cdf0e10cSrcweir                 break;
2480cdf0e10cSrcweir 
2481cdf0e10cSrcweir             case ClientMessage:
2482cdf0e10cSrcweir                 fprintf( stderr, "\t\ta=%s (0x%X) f=%i [0x%lX,0x%lX,0x%lX,0x%lX,0x%lX])\n",
2483cdf0e10cSrcweir                          GetAtomName( pDisp_, pEvent->xclient.message_type ),
2484cdf0e10cSrcweir                          sal::static_int_cast< unsigned int >(
2485cdf0e10cSrcweir                              pEvent->xclient.message_type),
2486cdf0e10cSrcweir                          pEvent->xclient.format,
2487cdf0e10cSrcweir                          pEvent->xclient.data.l[0],
2488cdf0e10cSrcweir                          pEvent->xclient.data.l[1],
2489cdf0e10cSrcweir                          pEvent->xclient.data.l[2],
2490cdf0e10cSrcweir                          pEvent->xclient.data.l[3],
2491cdf0e10cSrcweir                          pEvent->xclient.data.l[4] );
2492cdf0e10cSrcweir                 break;
2493cdf0e10cSrcweir 
2494cdf0e10cSrcweir             case MappingNotify:
2495cdf0e10cSrcweir                 fprintf( stderr, "\t\tr=%sd\n",
2496cdf0e10cSrcweir                          MappingModifier == pEvent->xmapping.request
2497cdf0e10cSrcweir                          ? "MappingModifier"
2498cdf0e10cSrcweir                          : MappingKeyboard == pEvent->xmapping.request
2499cdf0e10cSrcweir                            ? "MappingKeyboard"
2500cdf0e10cSrcweir                            : "MappingPointer" );
2501cdf0e10cSrcweir 
2502cdf0e10cSrcweir                 break;
2503cdf0e10cSrcweir         }
2504cdf0e10cSrcweir     }
2505cdf0e10cSrcweir     else
2506cdf0e10cSrcweir         fprintf( stderr, "[%s] %d s=%d w=%ld\n",
2507cdf0e10cSrcweir                  rComment.GetBuffer(),
2508cdf0e10cSrcweir                  pEvent->type,
2509cdf0e10cSrcweir                  pEvent->xany.send_event,
2510cdf0e10cSrcweir                  pEvent->xany.window );
2511cdf0e10cSrcweir }
2512cdf0e10cSrcweir 
2513cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PrintInfo() const2514cdf0e10cSrcweir void SalDisplay::PrintInfo() const
2515cdf0e10cSrcweir {
2516cdf0e10cSrcweir     if( IsDisplay() )
2517cdf0e10cSrcweir     {
2518cdf0e10cSrcweir         fprintf( stderr, "\n" );
2519cdf0e10cSrcweir         fprintf( stderr, "Environment\n" );
2520cdf0e10cSrcweir         fprintf( stderr, "\t$XENVIRONMENT     \t\"%s\"\n",
2521cdf0e10cSrcweir                  GetEnv( "XENVIRONMENT" ) );
2522cdf0e10cSrcweir         fprintf( stderr, "\t$DISPLAY          \t\"%s\"\n",
2523cdf0e10cSrcweir                  GetEnv( "DISPLAY" ) );
2524cdf0e10cSrcweir         fprintf( stderr, "\t$SAL_VISUAL       \t\"%s\"\n",
2525cdf0e10cSrcweir                  GetEnv( "SAL_VISUAL" ) );
2526cdf0e10cSrcweir         fprintf( stderr, "\t$SAL_FONTPATH     \t\"%s\"\n",
2527cdf0e10cSrcweir                  GetEnv( "SAL_FONTPATH" ) );
2528cdf0e10cSrcweir         fprintf( stderr, "\t$SAL_NOSEGV       \t\"%s\"\n",
2529cdf0e10cSrcweir                  GetEnv( "SAL_NOSEGV" ) );
2530cdf0e10cSrcweir         fprintf( stderr, "\t$SAL_IGNOREXERRORS\t\"%s\"\n",
2531cdf0e10cSrcweir                  GetEnv( "SAL_IGNOREXERRORS" ) );
2532cdf0e10cSrcweir         fprintf( stderr, "\t$SAL_PROPERTIES   \t\"%s\"\n",
2533cdf0e10cSrcweir                  GetEnv( "SAL_PROPERTIES" ) );
2534cdf0e10cSrcweir         fprintf( stderr, "\t$SAL_WM           \t\"%s\"\n",
2535cdf0e10cSrcweir                  GetEnv( "SAL_WM" ) );
2536cdf0e10cSrcweir         fprintf( stderr, "\t$SAL_SYNCHRONIZE  \t\"%s\"\n",
2537cdf0e10cSrcweir                  GetEnv( "SAL_SYNCHRONIZE" ) );
2538cdf0e10cSrcweir 
2539cdf0e10cSrcweir         char sHostname[ 120 ];
2540cdf0e10cSrcweir         gethostname (sHostname, 120 );
2541cdf0e10cSrcweir         fprintf( stderr, "Client\n" );
2542cdf0e10cSrcweir         fprintf( stderr, "\tHost              \t\"%s\"\n",
2543cdf0e10cSrcweir                  sHostname );
2544cdf0e10cSrcweir 
2545cdf0e10cSrcweir         fprintf( stderr, "Display\n" );
2546cdf0e10cSrcweir         fprintf( stderr, "\tHost              \t\"%s\"\n",
2547cdf0e10cSrcweir                  DisplayString(pDisp_) );
2548cdf0e10cSrcweir         fprintf( stderr, "\tVendor (Release)  \t\"%s (%d)\"\n",
2549cdf0e10cSrcweir                  ServerVendor(pDisp_), VendorRelease(pDisp_) );
2550cdf0e10cSrcweir         fprintf( stderr, "\tProtocol          \t%d.%d\n",
2551cdf0e10cSrcweir                  ProtocolVersion(pDisp_), ProtocolRevision(pDisp_) );
2552cdf0e10cSrcweir         fprintf( stderr, "\tScreen (count,def)\t%d (%d,%d)\n",
2553cdf0e10cSrcweir                  m_nDefaultScreen, ScreenCount(pDisp_), DefaultScreen(pDisp_) );
2554cdf0e10cSrcweir         fprintf( stderr, "\tshift ctrl alt    \t%s (0x%X) %s (0x%X) %s (0x%X)\n",
2555cdf0e10cSrcweir                  KeyStr( nShiftKeySym_ ), sal::static_int_cast< unsigned int >(nShiftKeySym_),
2556cdf0e10cSrcweir                  KeyStr( nCtrlKeySym_ ),  sal::static_int_cast< unsigned int >(nCtrlKeySym_),
2557cdf0e10cSrcweir                  KeyStr( nMod1KeySym_ ),  sal::static_int_cast< unsigned int >(nMod1KeySym_) );
2558cdf0e10cSrcweir         if( XExtendedMaxRequestSize(pDisp_) * 4 )
2559cdf0e10cSrcweir             fprintf( stderr, "\tXMaxRequestSize   \t%ld %ld [bytes]\n",
2560cdf0e10cSrcweir                      XMaxRequestSize(pDisp_) * 4, XExtendedMaxRequestSize(pDisp_) * 4 );
2561cdf0e10cSrcweir         if( GetProperties() != PROPERTY_DEFAULT )
2562cdf0e10cSrcweir             fprintf( stderr, "\tProperties        \t0x%lX\n", GetProperties() );
2563cdf0e10cSrcweir         if( eWindowManager_ != otherwm )
2564cdf0e10cSrcweir             fprintf( stderr, "\tWindowmanager     \t%d\n", eWindowManager_ );
2565cdf0e10cSrcweir         fprintf( stderr, "\tWMName            \t%s\n", rtl::OUStringToOString( getWMAdaptor()->getWindowManagerName(), osl_getThreadTextEncoding() ).getStr() );
2566cdf0e10cSrcweir     }
2567cdf0e10cSrcweir     fprintf( stderr, "Screen\n" );
2568cdf0e10cSrcweir     fprintf( stderr, "\tResolution/Size   \t%ld*%ld %ld*%ld %.1lf\"\n",
2569cdf0e10cSrcweir              aResolution_.A(), aResolution_.B(),
2570cdf0e10cSrcweir              m_aScreens[m_nDefaultScreen].m_aSize.Width(), m_aScreens[m_nDefaultScreen].m_aSize.Height(),
2571cdf0e10cSrcweir              Hypothenuse( DisplayWidthMM ( pDisp_, m_nDefaultScreen ),
2572cdf0e10cSrcweir                           DisplayHeightMM( pDisp_, m_nDefaultScreen ) ) / 25.4 );
2573cdf0e10cSrcweir     fprintf( stderr, "\tBlack&White       \t%lu %lu\n",
2574cdf0e10cSrcweir              GetColormap(m_nDefaultScreen).GetBlackPixel(), GetColormap(m_nDefaultScreen).GetWhitePixel() );
2575cdf0e10cSrcweir     fprintf( stderr, "\tRGB               \t0x%lx 0x%lx 0x%lx\n",
2576cdf0e10cSrcweir              GetVisual(m_nDefaultScreen).red_mask, GetVisual(m_nDefaultScreen).green_mask, GetVisual(m_nDefaultScreen).blue_mask );
2577cdf0e10cSrcweir     fprintf( stderr, "\tVisual            \t%d-bit %s ID=0x%x\n",
2578cdf0e10cSrcweir              GetVisual(m_nDefaultScreen).GetDepth(),
2579cdf0e10cSrcweir              VisualClassName[ GetVisual(m_nDefaultScreen).GetClass() ],
2580cdf0e10cSrcweir              sal::static_int_cast< unsigned int >(GetVisual(m_nDefaultScreen).GetVisualId()) );
2581cdf0e10cSrcweir }
2582cdf0e10cSrcweir 
addXineramaScreenUnique(long i_nX,long i_nY,long i_nWidth,long i_nHeight)2583cdf0e10cSrcweir int SalDisplay::addXineramaScreenUnique( long i_nX, long i_nY, long i_nWidth, long i_nHeight )
2584cdf0e10cSrcweir {
2585cdf0e10cSrcweir     // see if any frame buffers are at the same coordinates
2586cdf0e10cSrcweir     // this can happen with weird configuration e.g. on
2587cdf0e10cSrcweir     // XFree86 and Clone displays
2588cdf0e10cSrcweir     const size_t nScreens = m_aXineramaScreens.size();
2589cdf0e10cSrcweir     for( size_t n = 0; n < nScreens; n++ )
2590cdf0e10cSrcweir     {
2591cdf0e10cSrcweir         if( m_aXineramaScreens[n].Left() == i_nX &&
2592cdf0e10cSrcweir             m_aXineramaScreens[n].Top() == i_nY )
2593cdf0e10cSrcweir         {
2594cdf0e10cSrcweir             if( m_aXineramaScreens[n].GetWidth() < i_nWidth ||
2595cdf0e10cSrcweir                 m_aXineramaScreens[n].GetHeight() < i_nHeight )
2596cdf0e10cSrcweir             {
2597cdf0e10cSrcweir                 m_aXineramaScreens[n].SetSize( Size( i_nWidth, i_nHeight ) );
2598cdf0e10cSrcweir             }
2599cdf0e10cSrcweir             return (int)n;
2600cdf0e10cSrcweir         }
2601cdf0e10cSrcweir     }
2602cdf0e10cSrcweir     m_aXineramaScreens.push_back( Rectangle( Point( i_nX, i_nY ), Size( i_nWidth, i_nHeight ) ) );
2603cdf0e10cSrcweir     return (int)m_aXineramaScreens.size()-1;
2604cdf0e10cSrcweir }
2605cdf0e10cSrcweir 
InitXinerama()2606cdf0e10cSrcweir void SalDisplay::InitXinerama()
2607cdf0e10cSrcweir {
2608cdf0e10cSrcweir     if( m_aScreens.size() > 1 )
2609cdf0e10cSrcweir     {
2610cdf0e10cSrcweir         m_bXinerama = false;
2611cdf0e10cSrcweir         return; // multiple screens mean no xinerama
2612cdf0e10cSrcweir     }
2613cdf0e10cSrcweir #ifdef USE_XINERAMA
2614cdf0e10cSrcweir #if defined(USE_XINERAMA_XSUN)
2615cdf0e10cSrcweir     int nFramebuffers = 1;
2616cdf0e10cSrcweir     if( XineramaGetState( pDisp_, m_nDefaultScreen ) )
2617cdf0e10cSrcweir     {
2618cdf0e10cSrcweir         XRectangle pFramebuffers[MAXFRAMEBUFFERS];
2619cdf0e10cSrcweir         unsigned char hints[MAXFRAMEBUFFERS];
2620cdf0e10cSrcweir         int result = XineramaGetInfo( pDisp_,
2621cdf0e10cSrcweir                                       m_nDefaultScreen,
2622cdf0e10cSrcweir                                       pFramebuffers,
2623cdf0e10cSrcweir                                       hints,
2624cdf0e10cSrcweir                                       &nFramebuffers );
2625cdf0e10cSrcweir         if( result > 0 && nFramebuffers > 1 )
2626cdf0e10cSrcweir         {
2627cdf0e10cSrcweir             m_bXinerama = true;
2628cdf0e10cSrcweir             m_aXineramaScreens = std::vector<Rectangle>();
2629cdf0e10cSrcweir             for( int i = 0; i < nFramebuffers; i++ )
2630cdf0e10cSrcweir                 addXineramaScreenUnique( pFramebuffers[i].x,
2631cdf0e10cSrcweir                                          pFramebuffers[i].y,
2632cdf0e10cSrcweir                                          pFramebuffers[i].width,
2633cdf0e10cSrcweir                                          pFramebuffers[i].height );
2634cdf0e10cSrcweir         }
2635cdf0e10cSrcweir     }
2636cdf0e10cSrcweir #elif defined(USE_XINERAMA_XORG)
2637cdf0e10cSrcweir if( XineramaIsActive( pDisp_ ) )
2638cdf0e10cSrcweir {
2639cdf0e10cSrcweir     int nFramebuffers = 1;
2640cdf0e10cSrcweir     XineramaScreenInfo* pScreens = XineramaQueryScreens( pDisp_, &nFramebuffers );
2641cdf0e10cSrcweir     if( pScreens )
2642cdf0e10cSrcweir     {
2643cdf0e10cSrcweir         if( nFramebuffers > 1 )
2644cdf0e10cSrcweir         {
2645cdf0e10cSrcweir             m_aXineramaScreens = std::vector<Rectangle>();
2646cdf0e10cSrcweir             for( int i = 0; i < nFramebuffers; i++ )
2647cdf0e10cSrcweir             {
2648cdf0e10cSrcweir                 addXineramaScreenUnique( pScreens[i].x_org,
2649cdf0e10cSrcweir                                          pScreens[i].y_org,
2650cdf0e10cSrcweir                                          pScreens[i].width,
2651cdf0e10cSrcweir                                          pScreens[i].height );
2652cdf0e10cSrcweir             }
2653cdf0e10cSrcweir             m_bXinerama = m_aXineramaScreens.size() > 1;
2654cdf0e10cSrcweir         }
2655cdf0e10cSrcweir         XFree( pScreens );
2656cdf0e10cSrcweir     }
2657cdf0e10cSrcweir }
2658cdf0e10cSrcweir #endif
2659cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
2660cdf0e10cSrcweir     if( m_bXinerama )
2661cdf0e10cSrcweir     {
2662cdf0e10cSrcweir         for( std::vector< Rectangle >::const_iterator it = m_aXineramaScreens.begin(); it != m_aXineramaScreens.end(); ++it )
2663cdf0e10cSrcweir             fprintf( stderr, "Xinerama screen: %ldx%ld+%ld+%ld\n", it->GetWidth(), it->GetHeight(), it->Left(), it->Top() );
2664cdf0e10cSrcweir     }
2665cdf0e10cSrcweir #endif
2666cdf0e10cSrcweir #endif // USE_XINERAMA
2667cdf0e10cSrcweir }
2668cdf0e10cSrcweir 
registerFrame(SalFrame * pFrame)2669cdf0e10cSrcweir void SalDisplay::registerFrame( SalFrame* pFrame )
2670cdf0e10cSrcweir {
2671cdf0e10cSrcweir     m_aFrames.push_front( pFrame );
2672cdf0e10cSrcweir }
2673cdf0e10cSrcweir 
deregisterFrame(SalFrame * pFrame)2674cdf0e10cSrcweir void SalDisplay::deregisterFrame( SalFrame* pFrame )
2675cdf0e10cSrcweir {
2676cdf0e10cSrcweir     if( osl_acquireMutex( hEventGuard_ ) )
2677cdf0e10cSrcweir     {
2678cdf0e10cSrcweir         std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
2679cdf0e10cSrcweir         while ( it != m_aUserEvents.end() )
2680cdf0e10cSrcweir         {
2681cdf0e10cSrcweir             if( it->m_pFrame == pFrame )
2682cdf0e10cSrcweir                 it = m_aUserEvents.erase( it );
2683cdf0e10cSrcweir             else
2684cdf0e10cSrcweir                 ++it;
2685cdf0e10cSrcweir         }
2686cdf0e10cSrcweir         osl_releaseMutex( hEventGuard_ );
2687cdf0e10cSrcweir     }
2688cdf0e10cSrcweir     else {
2689cdf0e10cSrcweir         DBG_ERROR( "SalDisplay::deregisterFrame !acquireMutex\n" );
2690cdf0e10cSrcweir     }
2691cdf0e10cSrcweir 
2692cdf0e10cSrcweir     m_aFrames.remove( pFrame );
2693cdf0e10cSrcweir }
2694cdf0e10cSrcweir 
2695cdf0e10cSrcweir 
2696cdf0e10cSrcweir extern "C"
2697cdf0e10cSrcweir {
timestamp_predicate(Display *,XEvent * i_pEvent,XPointer i_pArg)2698cdf0e10cSrcweir     static Bool timestamp_predicate( Display*, XEvent* i_pEvent, XPointer i_pArg )
2699cdf0e10cSrcweir     {
2700cdf0e10cSrcweir         SalDisplay* pSalDisplay = reinterpret_cast<SalDisplay*>(i_pArg);
2701cdf0e10cSrcweir         if( i_pEvent->type == PropertyNotify &&
2702cdf0e10cSrcweir             i_pEvent->xproperty.window == pSalDisplay->GetDrawable( pSalDisplay->GetDefaultScreenNumber() ) &&
2703cdf0e10cSrcweir             i_pEvent->xproperty.atom == pSalDisplay->getWMAdaptor()->getAtom( WMAdaptor::SAL_GETTIMEEVENT )
2704cdf0e10cSrcweir             )
2705cdf0e10cSrcweir         return True;
2706cdf0e10cSrcweir 
2707cdf0e10cSrcweir         return False;
2708cdf0e10cSrcweir     }
2709cdf0e10cSrcweir }
2710cdf0e10cSrcweir 
GetLastUserEventTime(bool i_bAlwaysReget) const2711cdf0e10cSrcweir XLIB_Time SalDisplay::GetLastUserEventTime( bool i_bAlwaysReget ) const
2712cdf0e10cSrcweir {
2713cdf0e10cSrcweir     if( m_nLastUserEventTime == CurrentTime || i_bAlwaysReget )
2714cdf0e10cSrcweir     {
2715cdf0e10cSrcweir         // get current server time
2716cdf0e10cSrcweir         unsigned char c = 0;
2717cdf0e10cSrcweir         XEvent aEvent;
2718cdf0e10cSrcweir         Atom nAtom = getWMAdaptor()->getAtom( WMAdaptor::SAL_GETTIMEEVENT );
2719cdf0e10cSrcweir         XChangeProperty( GetDisplay(), GetDrawable( GetDefaultScreenNumber() ),
2720cdf0e10cSrcweir                          nAtom, nAtom, 8, PropModeReplace, &c, 1 );
2721cdf0e10cSrcweir         XFlush( GetDisplay() );
2722cdf0e10cSrcweir 
2723cdf0e10cSrcweir         if( ! XIfEventWithTimeout( &aEvent, (XPointer)this, timestamp_predicate ) )
2724cdf0e10cSrcweir         {
2725cdf0e10cSrcweir             // this should not happen at all; still sometimes it happens
2726cdf0e10cSrcweir             aEvent.xproperty.time = CurrentTime;
2727cdf0e10cSrcweir         }
2728cdf0e10cSrcweir 
2729cdf0e10cSrcweir         m_nLastUserEventTime = aEvent.xproperty.time;
2730cdf0e10cSrcweir     }
2731cdf0e10cSrcweir     return m_nLastUserEventTime;
2732cdf0e10cSrcweir }
2733cdf0e10cSrcweir 
XIfEventWithTimeout(XEvent * o_pEvent,XPointer i_pPredicateData,X_if_predicate i_pPredicate,long i_nTimeout) const2734cdf0e10cSrcweir bool SalDisplay::XIfEventWithTimeout( XEvent* o_pEvent, XPointer i_pPredicateData,
2735cdf0e10cSrcweir                                       X_if_predicate i_pPredicate, long i_nTimeout ) const
2736cdf0e10cSrcweir {
2737cdf0e10cSrcweir     /* #i99360# ugly workaround an X11 library bug
2738cdf0e10cSrcweir        this replaces the following call:
2739cdf0e10cSrcweir        XIfEvent( GetDisplay(), o_pEvent, i_pPredicate, i_pPredicateData );
2740cdf0e10cSrcweir     */
2741cdf0e10cSrcweir     bool bRet = true;
2742cdf0e10cSrcweir 
2743cdf0e10cSrcweir     if( ! XCheckIfEvent( GetDisplay(), o_pEvent, i_pPredicate, i_pPredicateData ) )
2744cdf0e10cSrcweir     {
2745cdf0e10cSrcweir         // wait for some event to arrive
2746cdf0e10cSrcweir         struct pollfd aFD;
2747cdf0e10cSrcweir         aFD.fd = ConnectionNumber(GetDisplay());
2748cdf0e10cSrcweir         aFD.events = POLLIN;
2749cdf0e10cSrcweir         aFD.revents = 0;
2750cdf0e10cSrcweir         poll( &aFD, 1, i_nTimeout );
2751cdf0e10cSrcweir         if( ! XCheckIfEvent( GetDisplay(), o_pEvent, i_pPredicate, i_pPredicateData ) )
2752cdf0e10cSrcweir         {
2753cdf0e10cSrcweir             poll( &aFD, 1, i_nTimeout ); // try once more for a packet of events from the Xserver
2754cdf0e10cSrcweir             if( ! XCheckIfEvent( GetDisplay(), o_pEvent, i_pPredicate, i_pPredicateData ) )
2755cdf0e10cSrcweir             {
2756cdf0e10cSrcweir                 bRet = false;
2757cdf0e10cSrcweir             }
2758cdf0e10cSrcweir         }
2759cdf0e10cSrcweir     }
2760cdf0e10cSrcweir     return bRet;
2761cdf0e10cSrcweir }
2762cdf0e10cSrcweir 
2763cdf0e10cSrcweir // -=-= SalVisual -=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2764cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SalVisual()2765cdf0e10cSrcweir SalVisual::SalVisual()
2766cdf0e10cSrcweir {
2767cdf0e10cSrcweir     rtl_zeroMemory( this, sizeof( SalVisual ) );
2768cdf0e10cSrcweir }
2769cdf0e10cSrcweir 
SalVisual(const XVisualInfo * pXVI)2770cdf0e10cSrcweir SalVisual::SalVisual( const XVisualInfo* pXVI )
2771cdf0e10cSrcweir {
2772cdf0e10cSrcweir 	*(XVisualInfo*)this = *pXVI;
2773cdf0e10cSrcweir     if( GetClass() == TrueColor )
2774cdf0e10cSrcweir     {
2775cdf0e10cSrcweir         nRedShift_      = sal_Shift( red_mask );
2776cdf0e10cSrcweir         nGreenShift_    = sal_Shift( green_mask );
2777cdf0e10cSrcweir         nBlueShift_     = sal_Shift( blue_mask );
2778cdf0e10cSrcweir 
2779cdf0e10cSrcweir         nRedBits_		= sal_significantBits( red_mask );
2780cdf0e10cSrcweir         nGreenBits_		= sal_significantBits( green_mask );
2781cdf0e10cSrcweir         nBlueBits_		= sal_significantBits( blue_mask );
2782cdf0e10cSrcweir 
2783cdf0e10cSrcweir         if( GetDepth() == 24 )
2784cdf0e10cSrcweir             if( red_mask == 0xFF0000 )
2785cdf0e10cSrcweir                 if( green_mask == 0xFF00 )
2786cdf0e10cSrcweir                     if( blue_mask  == 0xFF )
2787cdf0e10cSrcweir                         eRGBMode_ = RGB;
2788cdf0e10cSrcweir                     else
2789cdf0e10cSrcweir                         eRGBMode_ = otherSalRGB;
2790cdf0e10cSrcweir                 else if( blue_mask  == 0xFF00 )
2791cdf0e10cSrcweir                     if( green_mask == 0xFF )
2792cdf0e10cSrcweir                         eRGBMode_ = RBG;
2793cdf0e10cSrcweir                     else
2794cdf0e10cSrcweir                         eRGBMode_ = otherSalRGB;
2795cdf0e10cSrcweir                 else
2796cdf0e10cSrcweir                     eRGBMode_ = otherSalRGB;
2797cdf0e10cSrcweir             else if( green_mask == 0xFF0000 )
2798cdf0e10cSrcweir                 if( red_mask == 0xFF00 )
2799cdf0e10cSrcweir                     if( blue_mask  == 0xFF )
2800cdf0e10cSrcweir                         eRGBMode_ = GRB;
2801cdf0e10cSrcweir                     else
2802cdf0e10cSrcweir                         eRGBMode_ = otherSalRGB;
2803cdf0e10cSrcweir                 else if( blue_mask == 0xFF00 )
2804cdf0e10cSrcweir                     if( red_mask  == 0xFF )
2805cdf0e10cSrcweir                         eRGBMode_ = GBR;
2806cdf0e10cSrcweir                     else
2807cdf0e10cSrcweir                         eRGBMode_ = otherSalRGB;
2808cdf0e10cSrcweir                 else
2809cdf0e10cSrcweir                     eRGBMode_ = otherSalRGB;
2810cdf0e10cSrcweir             else if( blue_mask == 0xFF0000 )
2811cdf0e10cSrcweir                 if( red_mask == 0xFF00 )
2812cdf0e10cSrcweir                     if( green_mask  == 0xFF )
2813cdf0e10cSrcweir                         eRGBMode_ = BRG;
2814cdf0e10cSrcweir                     else
2815cdf0e10cSrcweir                         eRGBMode_ = otherSalRGB;
2816cdf0e10cSrcweir                 else if( green_mask == 0xFF00 )
2817cdf0e10cSrcweir                     if( red_mask == 0xFF )
2818cdf0e10cSrcweir                         eRGBMode_ = BGR;
2819cdf0e10cSrcweir                     else
2820cdf0e10cSrcweir                         eRGBMode_ = otherSalRGB;
2821cdf0e10cSrcweir                 else
2822cdf0e10cSrcweir                     eRGBMode_ = otherSalRGB;
2823cdf0e10cSrcweir             else
2824cdf0e10cSrcweir                 eRGBMode_ = otherSalRGB;
2825cdf0e10cSrcweir         else
2826cdf0e10cSrcweir             eRGBMode_ = otherSalRGB;
2827cdf0e10cSrcweir     }
2828cdf0e10cSrcweir }
2829cdf0e10cSrcweir 
2830cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
~SalVisual()2831cdf0e10cSrcweir SalVisual::~SalVisual()
2832cdf0e10cSrcweir {
2833cdf0e10cSrcweir     if( -1 == screen && VisualID(-1) == visualid ) delete visual;
2834cdf0e10cSrcweir }
2835cdf0e10cSrcweir 
2836cdf0e10cSrcweir // Konvertiert die Reihenfolge der Bytes eines Pixel in Bytes eines SalColors
2837cdf0e10cSrcweir // fuer die 6 XXXA ist das nicht reversibel
2838cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2839cdf0e10cSrcweir // SalColor is RGB (ABGR) a=0xFF000000, r=0xFF0000, g=0xFF00, b=0xFF
2840cdf0e10cSrcweir 
2841cdf0e10cSrcweir #define SALCOLOR        RGB
2842cdf0e10cSrcweir #define SALCOLORREVERSE BGR
2843cdf0e10cSrcweir 
Convert(int & n0,int & n1,int & n2,int & n3)2844cdf0e10cSrcweir sal_Bool SalVisual::Convert( int &n0, int &n1, int &n2, int &n3 )
2845cdf0e10cSrcweir {
2846cdf0e10cSrcweir     int n;
2847cdf0e10cSrcweir 
2848cdf0e10cSrcweir     switch( GetMode() )
2849cdf0e10cSrcweir     {
2850cdf0e10cSrcweir         case otherSalRGB:
2851cdf0e10cSrcweir             return sal_False;
2852cdf0e10cSrcweir         case SALCOLOR:
2853cdf0e10cSrcweir             break;
2854cdf0e10cSrcweir         case SALCOLORREVERSE:
2855cdf0e10cSrcweir         case RBG:
2856cdf0e10cSrcweir         case BRG:
2857cdf0e10cSrcweir         case GBR:
2858cdf0e10cSrcweir         case GRB:
2859cdf0e10cSrcweir             return Convert( n0, n1, n2 );
2860cdf0e10cSrcweir         case RGBA:
2861cdf0e10cSrcweir             n  = n0;
2862cdf0e10cSrcweir             n0 = n1;
2863cdf0e10cSrcweir             n1 = n2;
2864cdf0e10cSrcweir             n2 = n3;
2865cdf0e10cSrcweir             n3 = n;
2866cdf0e10cSrcweir             break;
2867cdf0e10cSrcweir         case BGRA:
2868cdf0e10cSrcweir         case RBGA:
2869cdf0e10cSrcweir         case BRGA:
2870cdf0e10cSrcweir         case GBRA:
2871cdf0e10cSrcweir         case GRBA:
2872cdf0e10cSrcweir         default:
2873cdf0e10cSrcweir             fprintf( stderr, "SalVisual::Convert %d\n", GetMode() );
2874cdf0e10cSrcweir             abort();
2875cdf0e10cSrcweir     }
2876cdf0e10cSrcweir     return sal_True;
2877cdf0e10cSrcweir }
2878cdf0e10cSrcweir 
Convert(int & n0,int & n1,int & n2)2879cdf0e10cSrcweir sal_Bool SalVisual::Convert( int &n0, int &n1, int &n2 )
2880cdf0e10cSrcweir {
2881cdf0e10cSrcweir     int n;
2882cdf0e10cSrcweir 
2883cdf0e10cSrcweir     switch( GetMode() )
2884cdf0e10cSrcweir     {
2885cdf0e10cSrcweir         case otherSalRGB:
2886cdf0e10cSrcweir             return sal_False;
2887cdf0e10cSrcweir         case SALCOLOR:
2888cdf0e10cSrcweir             break;
2889cdf0e10cSrcweir         case RBG:
2890cdf0e10cSrcweir             n  = n0;
2891cdf0e10cSrcweir             n0 = n1;
2892cdf0e10cSrcweir             n1 = n;
2893cdf0e10cSrcweir             break;
2894cdf0e10cSrcweir         case GRB:
2895cdf0e10cSrcweir             n  = n1;
2896cdf0e10cSrcweir             n1 = n2;
2897cdf0e10cSrcweir             n2 = n;
2898cdf0e10cSrcweir             break;
2899cdf0e10cSrcweir         case SALCOLORREVERSE:
2900cdf0e10cSrcweir             n  = n0;
2901cdf0e10cSrcweir             n0 = n2;
2902cdf0e10cSrcweir             n2 = n;
2903cdf0e10cSrcweir             break;
2904cdf0e10cSrcweir         case BRG:
2905cdf0e10cSrcweir             n  = n0;
2906cdf0e10cSrcweir             n0 = n1;
2907cdf0e10cSrcweir             n1 = n2;
2908cdf0e10cSrcweir             n2 = n;
2909cdf0e10cSrcweir             break;
2910cdf0e10cSrcweir         case GBR:
2911cdf0e10cSrcweir             n  = n2;
2912cdf0e10cSrcweir             n2 = n1;
2913cdf0e10cSrcweir             n1 = n0;
2914cdf0e10cSrcweir             n0 = n;
2915cdf0e10cSrcweir             break;
2916cdf0e10cSrcweir         default:
2917cdf0e10cSrcweir             fprintf( stderr, "SalVisual::Convert %d\n", GetMode() );
2918cdf0e10cSrcweir             abort();
2919cdf0e10cSrcweir     }
2920cdf0e10cSrcweir     return sal_True;
2921cdf0e10cSrcweir }
2922cdf0e10cSrcweir 
2923cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GetTCColor(Pixel nPixel) const2924cdf0e10cSrcweir SalColor SalVisual::GetTCColor( Pixel nPixel ) const
2925cdf0e10cSrcweir {
2926cdf0e10cSrcweir     if( SALCOLOR == eRGBMode_ )
2927cdf0e10cSrcweir         return (SalColor)nPixel;
2928cdf0e10cSrcweir 
2929cdf0e10cSrcweir     if( SALCOLORREVERSE == eRGBMode_ )
2930cdf0e10cSrcweir         return MAKE_SALCOLOR( (nPixel & 0x0000FF),
2931cdf0e10cSrcweir                               (nPixel & 0x00FF00) >>  8,
2932cdf0e10cSrcweir                               (nPixel & 0xFF0000) >> 16);
2933cdf0e10cSrcweir 
2934cdf0e10cSrcweir     Pixel r = nPixel & red_mask;
2935cdf0e10cSrcweir     Pixel g = nPixel & green_mask;
2936cdf0e10cSrcweir     Pixel b = nPixel & blue_mask;
2937cdf0e10cSrcweir 
2938cdf0e10cSrcweir     if( otherSalRGB != eRGBMode_ ) // 8+8+8=24
2939cdf0e10cSrcweir         return MAKE_SALCOLOR( r >> nRedShift_,
2940cdf0e10cSrcweir                               g >> nGreenShift_,
2941cdf0e10cSrcweir                               b >> nBlueShift_ );
2942cdf0e10cSrcweir 
2943cdf0e10cSrcweir     if( nRedShift_ > 0 )   r >>= nRedShift_;   else r <<= -nRedShift_;
2944cdf0e10cSrcweir     if( nGreenShift_ > 0 ) g >>= nGreenShift_; else g <<= -nGreenShift_;
2945cdf0e10cSrcweir     if( nBlueShift_ > 0 )  b >>= nBlueShift_;  else b <<= -nBlueShift_;
2946cdf0e10cSrcweir 
2947cdf0e10cSrcweir     if( nRedBits_ != 8 )
2948cdf0e10cSrcweir         r |= (r & 0xff) >> (8-nRedBits_);
2949cdf0e10cSrcweir     if( nGreenBits_ != 8 )
2950cdf0e10cSrcweir         g |= (g & 0xff) >> (8-nGreenBits_);
2951cdf0e10cSrcweir     if( nBlueBits_ != 8 )
2952cdf0e10cSrcweir         b |= (b & 0xff) >> (8-nBlueBits_);
2953cdf0e10cSrcweir 
2954cdf0e10cSrcweir     return MAKE_SALCOLOR( r, g, b );
2955cdf0e10cSrcweir }
2956cdf0e10cSrcweir 
GetTCPixel(SalColor nSalColor) const2957cdf0e10cSrcweir Pixel SalVisual::GetTCPixel( SalColor nSalColor ) const
2958cdf0e10cSrcweir {
2959cdf0e10cSrcweir     if( SALCOLOR == eRGBMode_ )
2960cdf0e10cSrcweir         return (Pixel)nSalColor;
2961cdf0e10cSrcweir 
2962cdf0e10cSrcweir     Pixel r = (Pixel)SALCOLOR_RED( nSalColor );
2963cdf0e10cSrcweir     Pixel g = (Pixel)SALCOLOR_GREEN( nSalColor );
2964cdf0e10cSrcweir     Pixel b = (Pixel)SALCOLOR_BLUE( nSalColor );
2965cdf0e10cSrcweir 
2966cdf0e10cSrcweir     if( SALCOLORREVERSE == eRGBMode_ )
2967cdf0e10cSrcweir         return (b << 16) | (g << 8) | (r);
2968cdf0e10cSrcweir 
2969cdf0e10cSrcweir     if( otherSalRGB != eRGBMode_ ) // 8+8+8=24
2970cdf0e10cSrcweir         return (r << nRedShift_) | (g << nGreenShift_) | (b << nBlueShift_);
2971cdf0e10cSrcweir 
2972cdf0e10cSrcweir     if( nRedShift_ > 0 )   r <<= nRedShift_;   else r >>= -nRedShift_;
2973cdf0e10cSrcweir     if( nGreenShift_ > 0 ) g <<= nGreenShift_; else g >>= -nGreenShift_;
2974cdf0e10cSrcweir     if( nBlueShift_ > 0 )  b <<= nBlueShift_;  else b >>= -nBlueShift_;
2975cdf0e10cSrcweir 
2976cdf0e10cSrcweir     return (r&red_mask) | (g&green_mask) | (b&blue_mask);
2977cdf0e10cSrcweir }
2978cdf0e10cSrcweir 
2979cdf0e10cSrcweir // -=-= SalColormap -=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2980cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SalColormap(const SalDisplay * pDisplay,Colormap hColormap,int nScreen)2981cdf0e10cSrcweir SalColormap::SalColormap( const SalDisplay *pDisplay, Colormap hColormap, int nScreen )
2982cdf0e10cSrcweir     : m_pDisplay( pDisplay ),
2983cdf0e10cSrcweir       m_hColormap( hColormap ),
2984cdf0e10cSrcweir       m_nScreen( nScreen )
2985cdf0e10cSrcweir {
2986cdf0e10cSrcweir     m_aVisual = m_pDisplay->GetVisual( m_nScreen );
2987cdf0e10cSrcweir 
2988cdf0e10cSrcweir     XColor aColor;
2989cdf0e10cSrcweir 
2990cdf0e10cSrcweir     GetXPixel( aColor, 0x00, 0x00, 0x00 );
2991cdf0e10cSrcweir     m_nBlackPixel = aColor.pixel;
2992cdf0e10cSrcweir 
2993cdf0e10cSrcweir     GetXPixel( aColor, 0xFF, 0xFF, 0xFF );
2994cdf0e10cSrcweir     m_nWhitePixel = aColor.pixel;
2995cdf0e10cSrcweir 
2996cdf0e10cSrcweir     m_nUsed = 1 << m_aVisual.GetDepth();
2997cdf0e10cSrcweir 
2998cdf0e10cSrcweir     if( m_aVisual.GetClass() == PseudoColor )
2999cdf0e10cSrcweir     {
3000cdf0e10cSrcweir         int r, g, b;
3001cdf0e10cSrcweir 
3002cdf0e10cSrcweir         // black, white, gray, ~gray = 4
3003cdf0e10cSrcweir         GetXPixels( aColor, 0xC0, 0xC0, 0xC0 );
3004cdf0e10cSrcweir 
3005cdf0e10cSrcweir         // light colors: 3 * 2 = 6
3006cdf0e10cSrcweir //      GetXPixels( aColor, 0x00, 0x00, 0x00 );
3007cdf0e10cSrcweir         GetXPixels( aColor, 0x00, 0x00, 0xFF );
3008cdf0e10cSrcweir         GetXPixels( aColor, 0x00, 0xFF, 0x00 );
3009cdf0e10cSrcweir         GetXPixels( aColor, 0x00, 0xFF, 0xFF );
3010cdf0e10cSrcweir //      GetXPixels( aColor, 0xFF, 0x00, 0x00 );
3011cdf0e10cSrcweir //      GetXPixels( aColor, 0xFF, 0x00, 0xFF );
3012cdf0e10cSrcweir //      GetXPixels( aColor, 0xFF, 0xFF, 0x00 );
3013cdf0e10cSrcweir //      GetXPixels( aColor, 0xFF, 0xFF, 0xFF );
3014cdf0e10cSrcweir 
3015cdf0e10cSrcweir         // standard colors: 7 * 2 = 14
3016cdf0e10cSrcweir //      GetXPixels( aColor, 0x00, 0x00, 0x00 );
3017cdf0e10cSrcweir         GetXPixels( aColor, 0x00, 0x00, 0x80 );
3018cdf0e10cSrcweir         GetXPixels( aColor, 0x00, 0x80, 0x00 );
3019cdf0e10cSrcweir         GetXPixels( aColor, 0x00, 0x80, 0x80 );
3020cdf0e10cSrcweir         GetXPixels( aColor, 0x80, 0x00, 0x00 );
3021cdf0e10cSrcweir         GetXPixels( aColor, 0x80, 0x00, 0x80 );
3022cdf0e10cSrcweir         GetXPixels( aColor, 0x80, 0x80, 0x00 );
3023cdf0e10cSrcweir         GetXPixels( aColor, 0x80, 0x80, 0x80 );
3024cdf0e10cSrcweir 		GetXPixels( aColor, 0x00, 0xB8, 0xFF ); // Blau 7
3025cdf0e10cSrcweir 
3026cdf0e10cSrcweir         // cube: 6*6*6 - 8 = 208
3027cdf0e10cSrcweir         for( r = 0; r < 0x100; r += 0x33 ) // 0x33, 0x66, 0x99, 0xCC, 0xFF
3028cdf0e10cSrcweir             for( g = 0; g < 0x100; g += 0x33 )
3029cdf0e10cSrcweir                 for( b = 0; b < 0x100; b += 0x33 )
3030cdf0e10cSrcweir                     GetXPixels( aColor, r, g, b );
3031cdf0e10cSrcweir 
3032cdf0e10cSrcweir         // gray: 16 - 6 = 10
3033cdf0e10cSrcweir         for( g = 0x11; g < 0xFF; g += 0x11 )
3034cdf0e10cSrcweir             GetXPixels( aColor, g, g, g );
3035cdf0e10cSrcweir 
3036cdf0e10cSrcweir         // green: 16 - 6 = 10
3037cdf0e10cSrcweir         for( g = 0x11; g < 0xFF; g += 0x11 )
3038cdf0e10cSrcweir             GetXPixels( aColor, 0, g, 0 );
3039cdf0e10cSrcweir 
3040cdf0e10cSrcweir         // red: 16 - 6 = 10
3041cdf0e10cSrcweir         for( r = 0x11; r < 0xFF; r += 0x11 )
3042cdf0e10cSrcweir             GetXPixels( aColor, r, 0, 0 );
3043cdf0e10cSrcweir 
3044cdf0e10cSrcweir         // blue: 16 - 6 = 10
3045cdf0e10cSrcweir         for( b = 0x11; b < 0xFF; b += 0x11 )
3046cdf0e10cSrcweir             GetXPixels( aColor, 0, 0, b );
3047cdf0e10cSrcweir     }
3048cdf0e10cSrcweir }
3049cdf0e10cSrcweir 
3050cdf0e10cSrcweir // PseudoColor
SalColormap(const BitmapPalette & rPalette)3051cdf0e10cSrcweir SalColormap::SalColormap( const BitmapPalette &rPalette )
3052cdf0e10cSrcweir     : m_pDisplay( GetX11SalData()->GetDisplay() ),
3053cdf0e10cSrcweir       m_hColormap( None ),
3054cdf0e10cSrcweir       m_nWhitePixel( SALCOLOR_NONE ),
3055cdf0e10cSrcweir       m_nBlackPixel( SALCOLOR_NONE ),
3056cdf0e10cSrcweir       m_nUsed( rPalette.GetEntryCount() ),
3057cdf0e10cSrcweir       m_nScreen( GetX11SalData()->GetDisplay()->GetDefaultScreenNumber() )
3058cdf0e10cSrcweir {
3059cdf0e10cSrcweir     m_aPalette = std::vector<SalColor>(m_nUsed);
3060cdf0e10cSrcweir 
3061cdf0e10cSrcweir     for( unsigned int i = 0; i < m_nUsed; i++ )
3062cdf0e10cSrcweir     {
3063cdf0e10cSrcweir         const BitmapColor &rColor = rPalette[i];
3064cdf0e10cSrcweir         m_aPalette[i] = MAKE_SALCOLOR( rColor.GetRed(),
3065cdf0e10cSrcweir                                        rColor.GetGreen(),
3066cdf0e10cSrcweir                                        rColor.GetBlue() );
3067cdf0e10cSrcweir         if( (m_nBlackPixel == SALCOLOR_NONE) && (SALCOLOR_BLACK == m_aPalette[i]) )
3068cdf0e10cSrcweir             m_nBlackPixel = i;
3069cdf0e10cSrcweir         else if( (m_nWhitePixel == SALCOLOR_NONE) && (SALCOLOR_WHITE == m_aPalette[i]) )
3070cdf0e10cSrcweir             m_nWhitePixel = i;
3071cdf0e10cSrcweir     }
3072cdf0e10cSrcweir }
3073cdf0e10cSrcweir 
3074cdf0e10cSrcweir // MonoChrome
SalColormap()3075cdf0e10cSrcweir SalColormap::SalColormap()
3076cdf0e10cSrcweir     : m_pDisplay( GetX11SalData()->GetDisplay() ),
3077cdf0e10cSrcweir       m_hColormap( None ),
3078cdf0e10cSrcweir       m_nWhitePixel( 1 ),
3079cdf0e10cSrcweir       m_nBlackPixel( 0 ),
3080cdf0e10cSrcweir       m_nUsed( 2 ),
3081cdf0e10cSrcweir       m_nScreen( 0 )
3082cdf0e10cSrcweir {
3083cdf0e10cSrcweir     if( m_pDisplay )
3084cdf0e10cSrcweir         m_nScreen = m_pDisplay->GetDefaultScreenNumber();
3085cdf0e10cSrcweir     m_aPalette = std::vector<SalColor>(m_nUsed);
3086cdf0e10cSrcweir 
3087cdf0e10cSrcweir     m_aPalette[m_nBlackPixel] = SALCOLOR_BLACK;
3088cdf0e10cSrcweir     m_aPalette[m_nWhitePixel] = SALCOLOR_WHITE;
3089cdf0e10cSrcweir }
3090cdf0e10cSrcweir 
3091cdf0e10cSrcweir // TrueColor
SalColormap(sal_uInt16 nDepth)3092cdf0e10cSrcweir SalColormap::SalColormap( sal_uInt16 nDepth )
3093cdf0e10cSrcweir     : m_pDisplay( GetX11SalData()->GetDisplay() ),
3094cdf0e10cSrcweir       m_hColormap( None ),
3095cdf0e10cSrcweir       m_nWhitePixel( (1 << nDepth) - 1 ),
3096cdf0e10cSrcweir       m_nBlackPixel( 0x00000000 ),
3097cdf0e10cSrcweir       m_nUsed( 1 << nDepth ),
3098cdf0e10cSrcweir       m_nScreen( GetX11SalData()->GetDisplay()->GetDefaultScreenNumber() )
3099cdf0e10cSrcweir {
3100cdf0e10cSrcweir     const SalVisual *pVisual  = &m_pDisplay->GetVisual( m_nScreen );
3101cdf0e10cSrcweir 
3102cdf0e10cSrcweir     if( pVisual->GetClass() == TrueColor && pVisual->GetDepth() == nDepth )
3103cdf0e10cSrcweir         m_aVisual = *pVisual;
3104cdf0e10cSrcweir     else
3105cdf0e10cSrcweir     {
3106cdf0e10cSrcweir         XVisualInfo aVI;
3107cdf0e10cSrcweir 
3108cdf0e10cSrcweir         if( !XMatchVisualInfo( m_pDisplay->GetDisplay(),
3109cdf0e10cSrcweir                                m_pDisplay->GetDefaultScreenNumber(),
3110cdf0e10cSrcweir                                nDepth,
3111cdf0e10cSrcweir                                TrueColor,
3112cdf0e10cSrcweir                                &aVI ) )
3113cdf0e10cSrcweir         {
3114cdf0e10cSrcweir             aVI.visual          = new Visual();
3115cdf0e10cSrcweir             aVI.visualid        = (VisualID)0; // beware of temporary destructor below
3116cdf0e10cSrcweir             aVI.screen          = 0;
3117cdf0e10cSrcweir             aVI.depth           = nDepth;
3118cdf0e10cSrcweir             aVI.c_class         = TrueColor;
3119cdf0e10cSrcweir             if( 24 == nDepth ) // 888
3120cdf0e10cSrcweir             {
3121cdf0e10cSrcweir                 aVI.red_mask        = 0xFF0000;
3122cdf0e10cSrcweir                 aVI.green_mask      = 0x00FF00;
3123cdf0e10cSrcweir                 aVI.blue_mask       = 0x0000FF;
3124cdf0e10cSrcweir             }
3125cdf0e10cSrcweir             else if( 16 == nDepth ) // 565
3126cdf0e10cSrcweir             {
3127cdf0e10cSrcweir                 aVI.red_mask        = 0x00F800;
3128cdf0e10cSrcweir                 aVI.green_mask      = 0x0007E0;
3129cdf0e10cSrcweir                 aVI.blue_mask       = 0x00001F;
3130cdf0e10cSrcweir             }
3131cdf0e10cSrcweir             else if( 15 == nDepth ) // 555
3132cdf0e10cSrcweir             {
3133cdf0e10cSrcweir                 aVI.red_mask        = 0x007C00;
3134cdf0e10cSrcweir                 aVI.green_mask      = 0x0003E0;
3135cdf0e10cSrcweir                 aVI.blue_mask       = 0x00001F;
3136cdf0e10cSrcweir             }
3137cdf0e10cSrcweir             else if( 12 == nDepth ) // 444
3138cdf0e10cSrcweir             {
3139cdf0e10cSrcweir                 aVI.red_mask        = 0x000F00;
3140cdf0e10cSrcweir                 aVI.green_mask      = 0x0000F0;
3141cdf0e10cSrcweir                 aVI.blue_mask       = 0x00000F;
3142cdf0e10cSrcweir             }
3143cdf0e10cSrcweir             else if( 8 == nDepth ) // 332
3144cdf0e10cSrcweir             {
3145cdf0e10cSrcweir                 aVI.red_mask        = 0x0000E0;
3146cdf0e10cSrcweir                 aVI.green_mask      = 0x00001C;
3147cdf0e10cSrcweir                 aVI.blue_mask       = 0x000003;
3148cdf0e10cSrcweir             }
3149cdf0e10cSrcweir             else
3150cdf0e10cSrcweir             {
3151cdf0e10cSrcweir                 aVI.red_mask        = 0x000000;
3152cdf0e10cSrcweir                 aVI.green_mask      = 0x000000;
3153cdf0e10cSrcweir                 aVI.blue_mask       = 0x000000;
3154cdf0e10cSrcweir             }
3155cdf0e10cSrcweir             aVI.colormap_size   = 0;
3156cdf0e10cSrcweir             aVI.bits_per_rgb    = 8;
3157cdf0e10cSrcweir 
3158cdf0e10cSrcweir             aVI.visual->ext_data        = NULL;
3159cdf0e10cSrcweir             aVI.visual->visualid        = aVI.visualid;
3160cdf0e10cSrcweir             aVI.visual->c_class         = aVI.c_class;
3161cdf0e10cSrcweir             aVI.visual->red_mask        = aVI.red_mask;
3162cdf0e10cSrcweir             aVI.visual->green_mask      = aVI.green_mask;
3163cdf0e10cSrcweir             aVI.visual->blue_mask       = aVI.blue_mask;
3164cdf0e10cSrcweir             aVI.visual->bits_per_rgb    = aVI.bits_per_rgb;
3165cdf0e10cSrcweir             aVI.visual->map_entries     = aVI.colormap_size;
3166cdf0e10cSrcweir 
3167cdf0e10cSrcweir             m_aVisual = SalVisual( &aVI );
3168cdf0e10cSrcweir             // give ownership of constructed Visual() to m_aVisual
3169cdf0e10cSrcweir             // see SalVisual destructor
3170cdf0e10cSrcweir             m_aVisual.visualid        = (VisualID)-1;
3171cdf0e10cSrcweir             m_aVisual.screen          = -1;
3172cdf0e10cSrcweir         }
3173cdf0e10cSrcweir         else
3174cdf0e10cSrcweir             m_aVisual = SalVisual( &aVI );
3175cdf0e10cSrcweir     }
3176cdf0e10cSrcweir }
3177cdf0e10cSrcweir 
~SalColormap()3178cdf0e10cSrcweir SalColormap::~SalColormap()
3179cdf0e10cSrcweir {
3180cdf0e10cSrcweir #ifdef DBG_UTIL
3181cdf0e10cSrcweir     m_hColormap      = (Colormap)ILLEGAL_POINTER;
3182cdf0e10cSrcweir     m_pDisplay       = (SalDisplay*)ILLEGAL_POINTER;
3183cdf0e10cSrcweir #endif
3184cdf0e10cSrcweir }
3185cdf0e10cSrcweir 
3186cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SetPalette(const BitmapPalette & rPalette)3187cdf0e10cSrcweir void SalColormap::SetPalette( const BitmapPalette &rPalette )
3188cdf0e10cSrcweir {
3189cdf0e10cSrcweir 	if( this != &GetX11SalData()->GetDisplay()->GetColormap(m_nScreen) )
3190cdf0e10cSrcweir 	{
3191cdf0e10cSrcweir 	    m_nBlackPixel = SALCOLOR_NONE;
3192cdf0e10cSrcweir 	    m_nWhitePixel = SALCOLOR_NONE;
3193cdf0e10cSrcweir 	}
3194cdf0e10cSrcweir 
3195cdf0e10cSrcweir     if( rPalette.GetEntryCount() > m_nUsed )
3196cdf0e10cSrcweir     {
3197cdf0e10cSrcweir         m_nBlackPixel = SALCOLOR_NONE;
3198cdf0e10cSrcweir         m_nWhitePixel = SALCOLOR_NONE;
3199cdf0e10cSrcweir         m_nUsed = rPalette.GetEntryCount();
3200cdf0e10cSrcweir         m_aPalette = std::vector<SalColor>(m_nUsed);
3201cdf0e10cSrcweir     }
3202cdf0e10cSrcweir 
3203cdf0e10cSrcweir     for( int i = 0; i < rPalette.GetEntryCount(); i++ )
3204cdf0e10cSrcweir     {
3205cdf0e10cSrcweir         const BitmapColor &rColor = rPalette[i];
3206cdf0e10cSrcweir         m_aPalette[i] = MAKE_SALCOLOR( rColor.GetRed(),
3207cdf0e10cSrcweir                                        rColor.GetGreen(),
3208cdf0e10cSrcweir                                        rColor.GetBlue() );
3209cdf0e10cSrcweir         if( (m_nBlackPixel == SALCOLOR_NONE) && (SALCOLOR_BLACK == m_aPalette[i]) )
3210cdf0e10cSrcweir             m_nBlackPixel = i;
3211cdf0e10cSrcweir         else if( (m_nWhitePixel == SALCOLOR_NONE) && (SALCOLOR_WHITE == m_aPalette[i]) )
3212cdf0e10cSrcweir             m_nWhitePixel = i;
3213cdf0e10cSrcweir     }
3214cdf0e10cSrcweir }
3215cdf0e10cSrcweir 
GetPalette()3216cdf0e10cSrcweir void SalColormap::GetPalette()
3217cdf0e10cSrcweir {
3218cdf0e10cSrcweir     Pixel i;
3219cdf0e10cSrcweir     m_aPalette = std::vector<SalColor>(m_nUsed);
3220cdf0e10cSrcweir 
3221cdf0e10cSrcweir     XColor *aColor = new XColor[m_nUsed];
3222cdf0e10cSrcweir 
3223cdf0e10cSrcweir     for( i = 0; i < m_nUsed; i++ )
3224cdf0e10cSrcweir     {
3225cdf0e10cSrcweir         aColor[i].red = aColor[i].green = aColor[i].blue = 0;
3226cdf0e10cSrcweir         aColor[i].pixel = i;
3227cdf0e10cSrcweir     }
3228cdf0e10cSrcweir 
3229cdf0e10cSrcweir     XQueryColors( m_pDisplay->GetDisplay(), m_hColormap, aColor, m_nUsed );
3230cdf0e10cSrcweir 
3231cdf0e10cSrcweir     for( i = 0; i < m_nUsed; i++ )
3232cdf0e10cSrcweir     {
3233cdf0e10cSrcweir         m_aPalette[i] = MAKE_SALCOLOR( aColor[i].red   >> 8,
3234cdf0e10cSrcweir                                        aColor[i].green >> 8,
3235cdf0e10cSrcweir                                        aColor[i].blue  >> 8 );
3236cdf0e10cSrcweir     }
3237cdf0e10cSrcweir 
3238cdf0e10cSrcweir     delete [] aColor;
3239cdf0e10cSrcweir }
3240cdf0e10cSrcweir 
3241cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
sal_Lookup(const std::vector<SalColor> & rPalette,int r,int g,int b,Pixel nUsed)3242cdf0e10cSrcweir static sal_uInt16 sal_Lookup( const std::vector<SalColor>& rPalette,
3243cdf0e10cSrcweir                                 int r, int g, int b,
3244cdf0e10cSrcweir                                 Pixel nUsed )
3245cdf0e10cSrcweir {
3246cdf0e10cSrcweir     sal_uInt16 nPixel = 0;
3247cdf0e10cSrcweir     int    nBest  = ColorDiff( rPalette[0], r, g, b );
3248cdf0e10cSrcweir 
3249cdf0e10cSrcweir     for( sal_uInt16 i = 1; i < nUsed; i++ )
3250cdf0e10cSrcweir     {
3251cdf0e10cSrcweir         int n = ColorDiff( rPalette[i], r, g, b );
3252cdf0e10cSrcweir 
3253cdf0e10cSrcweir         if( n < nBest )
3254cdf0e10cSrcweir         {
3255cdf0e10cSrcweir             if( !n )
3256cdf0e10cSrcweir                 return i;
3257cdf0e10cSrcweir 
3258cdf0e10cSrcweir             nPixel = i;
3259cdf0e10cSrcweir             nBest  = n;
3260cdf0e10cSrcweir         }
3261cdf0e10cSrcweir     }
3262cdf0e10cSrcweir     return nPixel;
3263cdf0e10cSrcweir }
3264cdf0e10cSrcweir 
GetLookupTable()3265cdf0e10cSrcweir void SalColormap::GetLookupTable()
3266cdf0e10cSrcweir {
3267cdf0e10cSrcweir     m_aLookupTable = std::vector<sal_uInt16>(16*16*16);
3268cdf0e10cSrcweir 
3269cdf0e10cSrcweir     int i = 0;
3270cdf0e10cSrcweir     for( int r = 0; r < 256; r += 17 )
3271cdf0e10cSrcweir         for( int g = 0; g < 256; g += 17 )
3272cdf0e10cSrcweir             for( int b = 0; b < 256; b += 17 )
3273cdf0e10cSrcweir                 m_aLookupTable[i++] = sal_Lookup( m_aPalette, r, g, b, m_nUsed );
3274cdf0e10cSrcweir }
3275cdf0e10cSrcweir 
3276cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
GetColor(Pixel nPixel) const3277cdf0e10cSrcweir SalColor SalColormap::GetColor( Pixel nPixel ) const
3278cdf0e10cSrcweir {
3279cdf0e10cSrcweir     if( m_nBlackPixel == nPixel ) return SALCOLOR_BLACK;
3280cdf0e10cSrcweir     if( m_nWhitePixel == nPixel ) return SALCOLOR_WHITE;
3281cdf0e10cSrcweir 
3282cdf0e10cSrcweir     if( m_aVisual.GetVisual() )
3283cdf0e10cSrcweir     {
3284cdf0e10cSrcweir         if( m_aVisual.GetClass() == TrueColor )
3285cdf0e10cSrcweir             return m_aVisual.GetTCColor( nPixel );
3286cdf0e10cSrcweir 
3287cdf0e10cSrcweir         if( m_aPalette.empty()
3288cdf0e10cSrcweir 			&& m_hColormap
3289cdf0e10cSrcweir #ifdef PSEUDOCOLOR12
3290cdf0e10cSrcweir             && m_aVisual.GetDepth() <= 12
3291cdf0e10cSrcweir #else
3292cdf0e10cSrcweir             && m_aVisual.GetDepth() <= 8
3293cdf0e10cSrcweir #endif
3294cdf0e10cSrcweir             && m_aVisual.GetClass() == PseudoColor )
3295cdf0e10cSrcweir             ((SalColormap*)this)->GetPalette();
3296cdf0e10cSrcweir     }
3297cdf0e10cSrcweir 
3298cdf0e10cSrcweir     if( !m_aPalette.empty() && nPixel < m_nUsed )
3299cdf0e10cSrcweir         return m_aPalette[nPixel];
3300cdf0e10cSrcweir 
3301cdf0e10cSrcweir     if( m_hColormap )
3302cdf0e10cSrcweir     {
3303cdf0e10cSrcweir         DBG_ASSERT( 1, "SalColormap::GetColor() !hColormap_\n" );
3304cdf0e10cSrcweir         return nPixel;
3305cdf0e10cSrcweir     }
3306cdf0e10cSrcweir 
3307cdf0e10cSrcweir     // DirectColor, StaticColor, StaticGray, GrayScale
3308cdf0e10cSrcweir     XColor aColor;
3309cdf0e10cSrcweir 
3310cdf0e10cSrcweir     aColor.pixel = nPixel;
3311cdf0e10cSrcweir 
3312cdf0e10cSrcweir     XQueryColor( m_pDisplay->GetDisplay(), m_hColormap, &aColor );
3313cdf0e10cSrcweir 
3314cdf0e10cSrcweir     return MAKE_SALCOLOR( aColor.red>>8, aColor.green>>8, aColor.blue>>8 );
3315cdf0e10cSrcweir }
3316cdf0e10cSrcweir 
GetXPixel(XColor & rColor,int r,int g,int b) const3317cdf0e10cSrcweir inline sal_Bool SalColormap::GetXPixel( XColor &rColor,
3318cdf0e10cSrcweir                                           int     r,
3319cdf0e10cSrcweir                                           int     g,
3320cdf0e10cSrcweir                                           int     b ) const
3321cdf0e10cSrcweir {
3322cdf0e10cSrcweir     rColor.red      = r * 257;
3323cdf0e10cSrcweir     rColor.green    = g * 257;
3324cdf0e10cSrcweir     rColor.blue     = b * 257;
3325cdf0e10cSrcweir     return XAllocColor( GetXDisplay(), m_hColormap, &rColor );
3326cdf0e10cSrcweir }
3327cdf0e10cSrcweir 
GetXPixels(XColor & rColor,int r,int g,int b) const3328cdf0e10cSrcweir sal_Bool SalColormap::GetXPixels( XColor &rColor,
3329cdf0e10cSrcweir                                     int     r,
3330cdf0e10cSrcweir                                     int     g,
3331cdf0e10cSrcweir                                     int     b ) const
3332cdf0e10cSrcweir {
3333cdf0e10cSrcweir     if( !GetXPixel( rColor, r, g, b ) )
3334cdf0e10cSrcweir         return sal_False;
3335cdf0e10cSrcweir     if( rColor.pixel & 1 )
3336cdf0e10cSrcweir         return sal_True;
3337cdf0e10cSrcweir     return GetXPixel( rColor, r^0xFF, g^0xFF, b^0xFF );
3338cdf0e10cSrcweir }
3339cdf0e10cSrcweir 
GetPixel(SalColor nSalColor) const3340cdf0e10cSrcweir Pixel SalColormap::GetPixel( SalColor nSalColor ) const
3341cdf0e10cSrcweir {
3342cdf0e10cSrcweir     if( SALCOLOR_NONE == nSalColor )  return 0;
3343cdf0e10cSrcweir     if( SALCOLOR_BLACK == nSalColor ) return m_nBlackPixel;
3344cdf0e10cSrcweir     if( SALCOLOR_WHITE == nSalColor ) return m_nWhitePixel;
3345cdf0e10cSrcweir 
3346cdf0e10cSrcweir     if( m_aVisual.GetClass() == TrueColor )
3347cdf0e10cSrcweir         return m_aVisual.GetTCPixel( nSalColor );
3348cdf0e10cSrcweir 
3349cdf0e10cSrcweir     if( m_aLookupTable.empty() )
3350cdf0e10cSrcweir     {
3351cdf0e10cSrcweir         if( m_aPalette.empty()
3352cdf0e10cSrcweir 			&& m_hColormap
3353cdf0e10cSrcweir #ifdef PSEUDOCOLOR12
3354cdf0e10cSrcweir             && m_aVisual.GetDepth() <= 12
3355cdf0e10cSrcweir #else
3356cdf0e10cSrcweir             && m_aVisual.GetDepth() <= 8
3357cdf0e10cSrcweir #endif
3358cdf0e10cSrcweir             && m_aVisual.GetClass() == PseudoColor ) // what else ???
3359cdf0e10cSrcweir             ((SalColormap*)this)->GetPalette();
3360cdf0e10cSrcweir 
3361cdf0e10cSrcweir         if( !m_aPalette.empty() )
3362cdf0e10cSrcweir             for( Pixel i = 0; i < m_nUsed; i++ )
3363cdf0e10cSrcweir                 if( m_aPalette[i] == nSalColor )
3364cdf0e10cSrcweir                     return i;
3365cdf0e10cSrcweir 
3366cdf0e10cSrcweir 		if( m_hColormap )
3367cdf0e10cSrcweir         {
3368cdf0e10cSrcweir             // DirectColor, StaticColor, StaticGray, GrayScale (PseudoColor)
3369cdf0e10cSrcweir             XColor aColor;
3370cdf0e10cSrcweir 
3371cdf0e10cSrcweir             if( GetXPixel( aColor,
3372cdf0e10cSrcweir                            SALCOLOR_RED  ( nSalColor ),
3373cdf0e10cSrcweir                            SALCOLOR_GREEN( nSalColor ),
3374cdf0e10cSrcweir                            SALCOLOR_BLUE ( nSalColor ) ) )
3375cdf0e10cSrcweir             {
3376cdf0e10cSrcweir                 if( !m_aPalette.empty() && !m_aPalette[aColor.pixel] )
3377cdf0e10cSrcweir                 {
3378cdf0e10cSrcweir                     const_cast<SalColormap*>(this)->m_aPalette[aColor.pixel] = nSalColor;
3379cdf0e10cSrcweir 
3380cdf0e10cSrcweir                     if( !(aColor.pixel & 1) && !m_aPalette[aColor.pixel+1] )
3381cdf0e10cSrcweir                     {
3382cdf0e10cSrcweir                         XColor aInversColor;
3383cdf0e10cSrcweir 
3384cdf0e10cSrcweir                         SalColor nInversColor = nSalColor ^ 0xFFFFFF;
3385cdf0e10cSrcweir 
3386cdf0e10cSrcweir                         GetXPixel( aInversColor,
3387cdf0e10cSrcweir                                    SALCOLOR_RED  ( nInversColor ),
3388cdf0e10cSrcweir                                    SALCOLOR_GREEN( nInversColor ),
3389cdf0e10cSrcweir                                    SALCOLOR_BLUE ( nInversColor ) );
3390cdf0e10cSrcweir 
3391cdf0e10cSrcweir                         if( !m_aPalette[aInversColor.pixel] )
3392cdf0e10cSrcweir                             const_cast<SalColormap*>(this)->m_aPalette[aInversColor.pixel] = nInversColor;
3393cdf0e10cSrcweir #ifdef DBG_UTIL
3394cdf0e10cSrcweir                         else
3395cdf0e10cSrcweir                             fprintf( stderr, "SalColormap::GetPixel() 0x%06lx=%lu 0x%06lx=%lu\n",
3396cdf0e10cSrcweir                                      static_cast< unsigned long >(nSalColor), aColor.pixel,
3397cdf0e10cSrcweir                                      static_cast< unsigned long >(nInversColor), aInversColor.pixel);
3398cdf0e10cSrcweir #endif
3399cdf0e10cSrcweir                     }
3400cdf0e10cSrcweir                 }
3401cdf0e10cSrcweir 
3402cdf0e10cSrcweir                 return aColor.pixel;
3403cdf0e10cSrcweir             }
3404cdf0e10cSrcweir 
3405cdf0e10cSrcweir #ifdef DBG_UTIL
3406cdf0e10cSrcweir             fprintf( stderr, "SalColormap::GetPixel() !XAllocColor %lx\n",
3407cdf0e10cSrcweir                      static_cast< unsigned long >(nSalColor) );
3408cdf0e10cSrcweir #endif
3409cdf0e10cSrcweir         }
3410cdf0e10cSrcweir 
3411cdf0e10cSrcweir         if( m_aPalette.empty() )
3412cdf0e10cSrcweir         {
3413cdf0e10cSrcweir #ifdef DBG_UTIL
3414cdf0e10cSrcweir             fprintf( stderr, "SalColormap::GetPixel() Palette empty %lx\n",
3415cdf0e10cSrcweir                      static_cast< unsigned long >(nSalColor));
3416cdf0e10cSrcweir #endif
3417cdf0e10cSrcweir             return nSalColor;
3418cdf0e10cSrcweir         }
3419cdf0e10cSrcweir 
3420cdf0e10cSrcweir         ((SalColormap*)this)->GetLookupTable();
3421cdf0e10cSrcweir     }
3422cdf0e10cSrcweir 
3423cdf0e10cSrcweir     // Colormatching ueber Palette
3424cdf0e10cSrcweir     sal_uInt16 r = SALCOLOR_RED  ( nSalColor );
3425cdf0e10cSrcweir     sal_uInt16 g = SALCOLOR_GREEN( nSalColor );
3426cdf0e10cSrcweir     sal_uInt16 b = SALCOLOR_BLUE ( nSalColor );
3427cdf0e10cSrcweir     return m_aLookupTable[ (((r+8)/17) << 8)
3428cdf0e10cSrcweir                          + (((g+8)/17) << 4)
3429cdf0e10cSrcweir                          +  ((b+8)/17) ];
3430cdf0e10cSrcweir }
3431cdf0e10cSrcweir 
3432