Fix the VarXxxFromCy conversions.
[wine] / include / x11drv.h
1 /*
2  * X11 driver definitions
3  */
4
5 #ifndef __WINE_X11DRV_H
6 #define __WINE_X11DRV_H
7
8 #include "config.h"
9
10 #include <X11/Xlib.h>
11 #include <X11/Xresource.h>
12 #include <X11/Xutil.h>
13 #include <X11/Xatom.h>
14 #ifdef HAVE_LIBXXSHM
15 # include <X11/extensions/XShm.h>
16 #endif /* defined(HAVE_LIBXXSHM) */
17
18 #include "windef.h"
19 #include "winbase.h"
20 #include "gdi.h"
21 #include "user.h"
22 #include "thread.h"
23
24 #define MAX_PIXELFORMATS 8
25
26 struct tagBITMAPOBJ;
27 struct tagCURSORICONINFO;
28 struct tagDC;
29 struct tagDeviceCaps;
30 struct tagPALETTEOBJ;
31 struct tagWND;
32 struct tagWINDOWPOS;
33 struct DIDEVICEOBJECTDATA;
34
35   /* X physical pen */
36 typedef struct
37 {
38     int          style;
39     int          endcap;
40     int          linejoin;
41     int          pixel;
42     int          width;
43     char *       dashes;
44     int          dash_len;
45     int          type;          /* GEOMETRIC || COSMETIC */
46 } X_PHYSPEN;
47
48   /* X physical brush */
49 typedef struct
50 {
51     int          style;
52     int          fillStyle;
53     int          pixel;
54     Pixmap       pixmap;
55 } X_PHYSBRUSH;
56
57   /* X physical font */
58 typedef UINT     X_PHYSFONT;
59
60   /* X physical device */
61 typedef struct
62 {
63     GC            gc;          /* X Window GC */
64     Drawable      drawable;
65     X_PHYSFONT    font;
66     X_PHYSPEN     pen;
67     X_PHYSBRUSH   brush;
68     int           backgroundPixel;
69     int           textPixel;
70     XVisualInfo  *visuals[MAX_PIXELFORMATS];
71     int           used_visuals;
72     int           current_pf;
73 } X11DRV_PDEVICE;
74
75
76   /* GCs used for B&W and color bitmap operations */
77 extern GC BITMAP_monoGC, BITMAP_colorGC;
78
79 #define BITMAP_GC(bmp) \
80   (((bmp)->bitmap.bmBitsPixel == 1) ? BITMAP_monoGC : BITMAP_colorGC)
81
82 extern DeviceCaps X11DRV_DevCaps;
83
84 extern unsigned int X11DRV_server_startticks;
85
86 /* Wine driver X11 functions */
87
88 extern const DC_FUNCTIONS X11DRV_DC_Funcs;
89
90 extern BOOL X11DRV_BitBlt( struct tagDC *dcDst, INT xDst, INT yDst,
91                              INT width, INT height, struct tagDC *dcSrc,
92                              INT xSrc, INT ySrc, DWORD rop );
93 extern BOOL X11DRV_EnumDeviceFonts( HDC hdc, LPLOGFONTW plf,
94                                     DEVICEFONTENUMPROC dfeproc, LPARAM lp );
95 extern BOOL X11DRV_GetCharWidth( struct tagDC *dc, UINT firstChar,
96                                    UINT lastChar, LPINT buffer );
97 extern BOOL X11DRV_GetDCOrgEx( struct tagDC *dc, LPPOINT lpp );
98 extern BOOL X11DRV_GetTextExtentPoint( struct tagDC *dc, LPCWSTR str,
99                                          INT count, LPSIZE size );
100 extern BOOL X11DRV_GetTextMetrics(struct tagDC *dc, TEXTMETRICW *metrics);
101 extern BOOL X11DRV_PatBlt( struct tagDC *dc, INT left, INT top,
102                              INT width, INT height, DWORD rop );
103 extern VOID   X11DRV_SetDeviceClipping(struct tagDC *dc);
104 extern BOOL X11DRV_StretchBlt( struct tagDC *dcDst, INT xDst, INT yDst,
105                                  INT widthDst, INT heightDst,
106                                  struct tagDC *dcSrc, INT xSrc, INT ySrc,
107                                  INT widthSrc, INT heightSrc, DWORD rop );
108 extern BOOL X11DRV_LineTo( struct tagDC *dc, INT x, INT y);
109 extern BOOL X11DRV_Arc( struct tagDC *dc, INT left, INT top, INT right,
110                           INT bottom, INT xstart, INT ystart, INT xend,
111                           INT yend );
112 extern BOOL X11DRV_Pie( struct tagDC *dc, INT left, INT top, INT right,
113                           INT bottom, INT xstart, INT ystart, INT xend,
114                           INT yend );
115 extern BOOL X11DRV_Chord( struct tagDC *dc, INT left, INT top,
116                             INT right, INT bottom, INT xstart,
117                             INT ystart, INT xend, INT yend );
118 extern BOOL X11DRV_Ellipse( struct tagDC *dc, INT left, INT top,
119                               INT right, INT bottom );
120 extern BOOL X11DRV_Rectangle(struct tagDC *dc, INT left, INT top,
121                               INT right, INT bottom);
122 extern BOOL X11DRV_RoundRect( struct tagDC *dc, INT left, INT top,
123                                 INT right, INT bottom, INT ell_width,
124                                 INT ell_height );
125 extern COLORREF X11DRV_SetPixel( struct tagDC *dc, INT x, INT y,
126                                  COLORREF color );
127 extern COLORREF X11DRV_GetPixel( struct tagDC *dc, INT x, INT y);
128 extern BOOL X11DRV_PaintRgn( struct tagDC *dc, HRGN hrgn );
129 extern BOOL X11DRV_Polyline( struct tagDC *dc,const POINT* pt,INT count);
130 extern BOOL X11DRV_Polygon( struct tagDC *dc, const POINT* pt, INT count );
131 extern BOOL X11DRV_PolyPolygon( struct tagDC *dc, const POINT* pt, 
132                                   const INT* counts, UINT polygons);
133 extern BOOL X11DRV_PolyPolyline( struct tagDC *dc, const POINT* pt, 
134                                   const DWORD* counts, DWORD polylines);
135
136 extern HGDIOBJ X11DRV_SelectObject( struct tagDC *dc, HGDIOBJ handle );
137
138 extern COLORREF X11DRV_SetBkColor( struct tagDC *dc, COLORREF color );
139 extern COLORREF X11DRV_SetTextColor( struct tagDC *dc, COLORREF color );
140 extern BOOL X11DRV_ExtFloodFill( struct tagDC *dc, INT x, INT y,
141                                    COLORREF color, UINT fillType );
142 extern BOOL X11DRV_ExtTextOut( struct tagDC *dc, INT x, INT y,
143                                  UINT flags, const RECT *lprect,
144                                  LPCWSTR str, UINT count, const INT *lpDx );
145 extern BOOL X11DRV_CreateBitmap( HBITMAP hbitmap );
146 extern BOOL X11DRV_DeleteObject( HGDIOBJ handle );
147 extern LONG X11DRV_BitmapBits( HBITMAP hbitmap, void *bits, LONG count,
148                                WORD flags );
149 extern INT X11DRV_SetDIBitsToDevice( struct tagDC *dc, INT xDest,
150                                        INT yDest, DWORD cx, DWORD cy,
151                                        INT xSrc, INT ySrc,
152                                        UINT startscan, UINT lines,
153                                        LPCVOID bits, const BITMAPINFO *info,
154                                        UINT coloruse );
155 extern INT X11DRV_DeviceBitmapBits( struct tagDC *dc, HBITMAP hbitmap,
156                                       WORD fGet, UINT startscan,
157                                       UINT lines, LPSTR bits,
158                                       LPBITMAPINFO info, UINT coloruse );
159 extern BOOL X11DRV_GetDeviceGammaRamp( struct tagDC *dc, LPVOID ramp );
160 extern BOOL X11DRV_SetDeviceGammaRamp( struct tagDC *dc, LPVOID ramp );
161
162 /* OpenGL / X11 driver functions */
163 extern int X11DRV_ChoosePixelFormat(DC *dc, const PIXELFORMATDESCRIPTOR *pppfd) ;
164 extern int X11DRV_DescribePixelFormat(DC *dc, int iPixelFormat, UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd) ;
165 extern int X11DRV_GetPixelFormat(DC *dc) ;
166 extern BOOL X11DRV_SetPixelFormat(DC *dc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd) ;
167 extern BOOL X11DRV_SwapBuffers(DC *dc) ;
168
169 /* X11 driver internal functions */
170
171 extern BOOL X11DRV_BITMAP_Init(void);
172 extern BOOL X11DRV_FONT_Init( struct tagDeviceCaps* );
173 extern BOOL X11DRV_OBM_Init(void);
174
175 struct tagBITMAPOBJ;
176 extern XImage *X11DRV_BITMAP_GetXImage( const struct tagBITMAPOBJ *bmp );
177 extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth );
178 extern HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(Pixmap pixmap);
179 extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixmap);
180 extern HBITMAP X11DRV_BITMAP_CreateBitmapFromPixmap(Pixmap pixmap, BOOL bDeletePixmap);
181 extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc );
182 extern Pixmap X11DRV_BITMAP_CreatePixmapFromBitmap( HBITMAP hBmp, HDC hdc );
183
184 extern BOOL X11DRV_SetupGCForPatBlt( struct tagDC *dc, GC gc,
185                                        BOOL fMapColors );
186 extern BOOL X11DRV_SetupGCForBrush( struct tagDC *dc );
187 extern BOOL X11DRV_SetupGCForPen( struct tagDC *dc );
188 extern BOOL X11DRV_SetupGCForText( struct tagDC *dc );
189
190 extern const int X11DRV_XROPfunction[];
191
192 extern void _XInitImageFuncPtrs(XImage *);
193
194 /* exported dib functions for now */
195
196 /* Additional info for DIB section objects */
197 typedef struct
198 {
199     /* Windows DIB section */
200     DIBSECTION  dibSection;
201
202     /* Mapping status */
203     int         status, p_status;
204
205     /* Color map info */
206     int         nColorMap;
207     int        *colorMap;
208
209     /* Cached XImage */
210     XImage     *image;
211
212     /* Selector for 16-bit access to bits */
213     WORD selector;
214
215 #ifdef HAVE_LIBXXSHM
216     /* Shared memory segment info */
217     XShmSegmentInfo shminfo;
218 #endif
219
220     /* Aux buffer access function */
221     void (*copy_aux)(void*ctx, int req);
222     void *aux_ctx;
223
224     /* GDI access lock */
225     CRITICAL_SECTION lock;
226
227 } X11DRV_DIBSECTION;
228
229 extern int *X11DRV_DIB_BuildColorMap( struct tagDC *dc, WORD coloruse,
230                                       WORD depth, const BITMAPINFO *info,
231                                       int *nColors );
232 extern INT X11DRV_CoerceDIBSection(struct tagDC *dc,INT,BOOL);
233 extern INT X11DRV_LockDIBSection(struct tagDC *dc,INT,BOOL);
234 extern void X11DRV_UnlockDIBSection(struct tagDC *dc,BOOL);
235 extern INT X11DRV_CoerceDIBSection2(HBITMAP bmp,INT,BOOL);
236 extern INT X11DRV_LockDIBSection2(HBITMAP bmp,INT,BOOL);
237 extern void X11DRV_UnlockDIBSection2(HBITMAP bmp,BOOL);
238
239 extern HBITMAP X11DRV_DIB_CreateDIBSection(struct tagDC *dc, BITMAPINFO *bmi, UINT usage,
240                                            LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
241 extern HBITMAP16 X11DRV_DIB_CreateDIBSection16(struct tagDC *dc, BITMAPINFO *bmi, UINT16 usage,
242                                                SEGPTR *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
243
244 extern struct tagBITMAP_DRIVER X11DRV_BITMAP_Driver;
245
246 extern INT X11DRV_DIB_SetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan,
247                                 UINT lines, LPCVOID bits, const BITMAPINFO *info,
248                                 UINT coloruse, HBITMAP hbitmap);
249 extern INT X11DRV_DIB_GetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan,
250                                 UINT lines, LPVOID bits, BITMAPINFO *info,
251                                 UINT coloruse, HBITMAP hbitmap);
252 extern void X11DRV_DIB_DeleteDIBSection(struct tagBITMAPOBJ *bmp);
253 extern UINT X11DRV_DIB_SetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC*,UINT,UINT,const RGBQUAD *);
254 extern UINT X11DRV_DIB_GetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC*,UINT,UINT,RGBQUAD *);
255 extern INT X11DRV_DIB_Coerce(struct tagBITMAPOBJ *,INT,BOOL);
256 extern INT X11DRV_DIB_Lock(struct tagBITMAPOBJ *,INT,BOOL);
257 extern void X11DRV_DIB_Unlock(struct tagBITMAPOBJ *,BOOL);
258 void X11DRV_DIB_CopyDIBSection(DC *dcSrc, DC *dcDst,     
259                                DWORD xSrc, DWORD ySrc,   
260                                DWORD xDest, DWORD yDest, 
261                                DWORD width, DWORD height);
262
263 extern INT X11DRV_DCICommand(INT cbInput, LPVOID lpInData, LPVOID lpOutData);
264
265 /**************************************************************************
266  * X11 GDI driver
267  */
268
269 BOOL X11DRV_GDI_Initialize( Display *display );
270 void X11DRV_GDI_Finalize(void);
271
272 extern Display *gdi_display;  /* display to use for all GDI functions */
273
274 /* X11 GDI palette driver */
275
276 #define X11DRV_PALETTE_FIXED    0x0001 /* read-only colormap - have to use XAllocColor (if not virtual) */
277 #define X11DRV_PALETTE_VIRTUAL  0x0002 /* no mapping needed - pixel == pixel color */
278
279 #define X11DRV_PALETTE_PRIVATE  0x1000 /* private colormap, identity mapping */
280 #define X11DRV_PALETTE_WHITESET 0x2000
281
282 extern Colormap X11DRV_PALETTE_PaletteXColormap;
283 extern UINT16 X11DRV_PALETTE_PaletteFlags;
284
285 extern int *X11DRV_PALETTE_PaletteToXPixel;
286 extern int *X11DRV_PALETTE_XPixelToPalette;
287
288 extern int X11DRV_PALETTE_mapEGAPixel[16];
289
290 extern BOOL X11DRV_PALETTE_Init(void);
291 extern void X11DRV_PALETTE_Cleanup(void);
292
293 extern COLORREF X11DRV_PALETTE_ToLogical(int pixel);
294 extern int X11DRV_PALETTE_ToPhysical(struct tagDC *dc, COLORREF color);
295
296 extern struct tagPALETTE_DRIVER X11DRV_PALETTE_Driver;
297
298 extern int X11DRV_PALETTE_SetMapping(struct tagPALETTEOBJ *palPtr, UINT uStart, UINT uNum, BOOL mapOnly);
299 extern int X11DRV_PALETTE_UpdateMapping(struct tagPALETTEOBJ *palPtr);
300 extern BOOL X11DRV_PALETTE_IsDark(int pixel);
301
302 /**************************************************************************
303  * X11 USER driver
304  */
305
306 struct x11drv_thread_data
307 {
308     Display *display;
309     HANDLE   display_fd;
310     int      process_event_count;
311 };
312
313 extern struct x11drv_thread_data *x11drv_init_thread_data(void);
314
315 inline static struct x11drv_thread_data *x11drv_thread_data(void)
316 {
317     struct x11drv_thread_data *data = NtCurrentTeb()->driver_data;
318     if (!data) data = x11drv_init_thread_data();
319     return data;
320 }
321
322 inline static Display *thread_display(void) { return x11drv_thread_data()->display; }
323
324 extern Visual *visual;
325 extern Window root_window;
326 extern unsigned int screen_width;
327 extern unsigned int screen_height;
328 extern unsigned int screen_depth;
329
330 static inline Visual *X11DRV_GetVisual(void)     { return visual; }
331 static inline Window X11DRV_GetXRootWindow(void) { return root_window; }
332
333 /* X11 clipboard driver */
334
335 extern void X11DRV_CLIPBOARD_FreeResources( Atom property );
336 extern BOOL X11DRV_CLIPBOARD_RegisterPixmapResource( Atom property, Pixmap pixmap );
337 extern BOOL X11DRV_CLIPBOARD_IsNativeProperty(Atom prop);
338 extern UINT X11DRV_CLIPBOARD_MapPropertyToFormat(char *itemFmtName);
339 extern Atom X11DRV_CLIPBOARD_MapFormatToProperty(UINT id);
340 extern void X11DRV_CLIPBOARD_ReleaseSelection(Atom selType, Window w, HWND hwnd);
341 extern BOOL X11DRV_IsSelectionOwner(void);
342 extern BOOL X11DRV_GetClipboardData(UINT wFormat);
343
344 /* X11 event driver */
345
346 extern WORD X11DRV_EVENT_XStateToKeyState( int state ) ;
347
348 extern void X11DRV_Synchronize( void );
349
350 typedef enum {
351   X11DRV_INPUT_RELATIVE,
352   X11DRV_INPUT_ABSOLUTE
353 } INPUT_TYPE;
354 extern INPUT_TYPE X11DRV_EVENT_SetInputMethod(INPUT_TYPE type);
355
356 #ifdef HAVE_LIBXXF86DGA2
357 void X11DRV_EVENT_SetDGAStatus(HWND hwnd, int event_base) ;
358 #endif
359
360
361 /* X11 keyboard driver */
362
363 extern void X11DRV_InitKeyboard(void);
364 extern WORD X11DRV_VkKeyScan(CHAR cChar);
365 extern UINT16 X11DRV_MapVirtualKey(UINT16 wCode, UINT16 wMapType);
366 extern INT16 X11DRV_GetKeyNameText(LONG lParam, LPSTR lpBuffer, INT16 nSize);
367 extern BOOL X11DRV_GetDIState(DWORD len, LPVOID ptr);
368 extern BOOL X11DRV_GetDIData(BYTE *keystate, DWORD dodsize, struct DIDEVICEOBJECTDATA *dod, LPDWORD entries, DWORD flags);
369
370 extern void X11DRV_HandleEvent(struct tagWND *pWnd, XKeyEvent *event);
371
372 /* X11 mouse driver */
373
374 extern void X11DRV_InitMouse(LPMOUSE_EVENT_PROC);
375 extern void X11DRV_SetCursor(struct tagCURSORICONINFO *lpCursor);
376 extern void X11DRV_MoveCursor(WORD wAbsX, WORD wAbsY);
377 extern void X11DRV_SendEvent( DWORD mouseStatus, DWORD posX, DWORD posY,
378                                     DWORD keyState, DWORD time, HWND hWnd );
379
380 /* X11 windows driver */
381
382 extern struct tagWND_DRIVER X11DRV_WND_Driver;
383
384 typedef struct _X11DRV_WND_DATA {
385   Window window;
386   HBITMAP hWMIconBitmap;
387   HBITMAP hWMIconMask;
388   int bit_gravity;
389 } X11DRV_WND_DATA;
390
391 extern Window X11DRV_WND_GetXWindow(struct tagWND *wndPtr);
392 extern Window X11DRV_WND_FindXWindow(struct tagWND *wndPtr);
393
394 extern void X11DRV_WND_ForceWindowRaise(struct tagWND *pWnd);
395 extern void X11DRV_WND_SetWindowPos(struct tagWND *wndPtr, const struct tagWINDOWPOS *winpos, BOOL bSMC_SETXPOS);
396 extern void X11DRV_WND_SetText(struct tagWND *wndPtr, LPCWSTR text);
397 extern void X11DRV_WND_SurfaceCopy(struct tagWND *wndPtr, HDC hdc, INT dx, INT dy, const RECT *clipRect, BOOL bUpdate);
398 extern void X11DRV_WND_SetGravity(struct tagWND* wndPtr, int value );
399 extern BOOL X11DRV_WND_SetHostAttr(struct tagWND *wndPtr, INT haKey, INT value);
400
401 extern void X11DRV_SetFocus( HWND hwnd );
402 extern Cursor X11DRV_GetCursor( Display *display, struct tagCURSORICONINFO *ptr );
403
404 extern void X11DRV_register_window( Display *display, HWND hwnd, Window win );
405 extern void X11DRV_create_desktop_thread(void);
406 extern Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry );
407
408 #endif  /* __WINE_X11DRV_H */