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