Moved scrollbar tracking code to scroll.c.
[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 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     int           exposures;   /* count of graphics exposures operations */
71     XVisualInfo  *visuals[MAX_PIXELFORMATS];
72     int           used_visuals;
73     int           current_pf;
74 } X11DRV_PDEVICE;
75
76
77   /* GCs used for B&W and color bitmap operations */
78 extern GC BITMAP_monoGC, BITMAP_colorGC;
79
80 #define BITMAP_GC(bmp) \
81   (((bmp)->bitmap.bmBitsPixel == 1) ? BITMAP_monoGC : BITMAP_colorGC)
82
83 extern unsigned int X11DRV_server_startticks;
84
85 /* Wine driver X11 functions */
86
87 extern BOOL X11DRV_BitBlt( struct tagDC *dcDst, INT xDst, INT yDst,
88                              INT width, INT height, struct tagDC *dcSrc,
89                              INT xSrc, INT ySrc, DWORD rop );
90 extern BOOL X11DRV_EnumDeviceFonts( HDC hdc, LPLOGFONTW plf,
91                                     DEVICEFONTENUMPROC dfeproc, LPARAM lp );
92 extern BOOL X11DRV_GetCharWidth( struct tagDC *dc, UINT firstChar,
93                                    UINT lastChar, LPINT buffer );
94 extern BOOL X11DRV_GetDCOrgEx( struct tagDC *dc, LPPOINT lpp );
95 extern BOOL X11DRV_GetTextExtentPoint( struct tagDC *dc, LPCWSTR str,
96                                          INT count, LPSIZE size );
97 extern BOOL X11DRV_GetTextMetrics(struct tagDC *dc, TEXTMETRICW *metrics);
98 extern BOOL X11DRV_PatBlt( struct tagDC *dc, INT left, INT top,
99                              INT width, INT height, DWORD rop );
100 extern VOID   X11DRV_SetDeviceClipping(struct tagDC *dc);
101 extern BOOL X11DRV_StretchBlt( struct tagDC *dcDst, INT xDst, INT yDst,
102                                  INT widthDst, INT heightDst,
103                                  struct tagDC *dcSrc, INT xSrc, INT ySrc,
104                                  INT widthSrc, INT heightSrc, DWORD rop );
105 extern BOOL X11DRV_LineTo( struct tagDC *dc, INT x, INT y);
106 extern BOOL X11DRV_Arc( struct tagDC *dc, INT left, INT top, INT right,
107                           INT bottom, INT xstart, INT ystart, INT xend,
108                           INT yend );
109 extern BOOL X11DRV_Pie( 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_Chord( struct tagDC *dc, INT left, INT top,
113                             INT right, INT bottom, INT xstart,
114                             INT ystart, INT xend, INT yend );
115 extern BOOL X11DRV_Ellipse( struct tagDC *dc, INT left, INT top,
116                               INT right, INT bottom );
117 extern BOOL X11DRV_Rectangle(struct tagDC *dc, INT left, INT top,
118                               INT right, INT bottom);
119 extern BOOL X11DRV_RoundRect( struct tagDC *dc, INT left, INT top,
120                                 INT right, INT bottom, INT ell_width,
121                                 INT ell_height );
122 extern COLORREF X11DRV_SetPixel( struct tagDC *dc, INT x, INT y,
123                                  COLORREF color );
124 extern COLORREF X11DRV_GetPixel( struct tagDC *dc, INT x, INT y);
125 extern BOOL X11DRV_PaintRgn( struct tagDC *dc, HRGN hrgn );
126 extern BOOL X11DRV_Polyline( struct tagDC *dc,const POINT* pt,INT count);
127 extern BOOL X11DRV_Polygon( struct tagDC *dc, const POINT* pt, INT count );
128 extern BOOL X11DRV_PolyPolygon( struct tagDC *dc, const POINT* pt, 
129                                   const INT* counts, UINT polygons);
130 extern BOOL X11DRV_PolyPolyline( struct tagDC *dc, const POINT* pt, 
131                                   const DWORD* counts, DWORD polylines);
132
133 extern HGDIOBJ X11DRV_SelectObject( struct tagDC *dc, HGDIOBJ handle );
134
135 extern COLORREF X11DRV_SetBkColor( struct tagDC *dc, COLORREF color );
136 extern COLORREF X11DRV_SetTextColor( struct tagDC *dc, COLORREF color );
137 extern BOOL X11DRV_ExtFloodFill( struct tagDC *dc, INT x, INT y,
138                                    COLORREF color, UINT fillType );
139 extern BOOL X11DRV_ExtTextOut( struct tagDC *dc, INT x, INT y,
140                                  UINT flags, const RECT *lprect,
141                                  LPCWSTR str, UINT count, const INT *lpDx );
142 extern BOOL X11DRV_CreateBitmap( HBITMAP hbitmap );
143 extern BOOL X11DRV_DeleteObject( HGDIOBJ handle );
144 extern LONG X11DRV_BitmapBits( HBITMAP hbitmap, void *bits, LONG count,
145                                WORD flags );
146 extern INT X11DRV_SetDIBitsToDevice( struct tagDC *dc, INT xDest,
147                                        INT yDest, DWORD cx, DWORD cy,
148                                        INT xSrc, INT ySrc,
149                                        UINT startscan, UINT lines,
150                                        LPCVOID bits, const BITMAPINFO *info,
151                                        UINT coloruse );
152 extern INT X11DRV_DeviceBitmapBits( struct tagDC *dc, HBITMAP hbitmap,
153                                       WORD fGet, UINT startscan,
154                                       UINT lines, LPSTR bits,
155                                       LPBITMAPINFO info, UINT coloruse );
156 extern BOOL X11DRV_GetDeviceGammaRamp( struct tagDC *dc, LPVOID ramp );
157 extern BOOL X11DRV_SetDeviceGammaRamp( struct tagDC *dc, LPVOID ramp );
158
159 /* OpenGL / X11 driver functions */
160 extern int X11DRV_ChoosePixelFormat(DC *dc, const PIXELFORMATDESCRIPTOR *pppfd) ;
161 extern int X11DRV_DescribePixelFormat(DC *dc, int iPixelFormat, UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd) ;
162 extern int X11DRV_GetPixelFormat(DC *dc) ;
163 extern BOOL X11DRV_SetPixelFormat(DC *dc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd) ;
164 extern BOOL X11DRV_SwapBuffers(DC *dc) ;
165
166 /* X11 driver internal functions */
167
168 extern BOOL X11DRV_BITMAP_Init(void);
169 extern int X11DRV_FONT_Init( int *log_pixels_x, int *log_pixels_y );
170 extern BOOL X11DRV_OBM_Init(void);
171 extern HBRUSH X11DRV_BRUSH_SelectObject( DC * dc, HBRUSH hbrush );
172 extern HFONT X11DRV_FONT_SelectObject( DC * dc, HFONT hfont );
173 extern HPEN X11DRV_PEN_SelectObject( DC * dc, HPEN hpen );
174 extern HBITMAP X11DRV_BITMAP_SelectObject( DC * dc, HBITMAP hbitmap );
175 extern BOOL X11DRV_BITMAP_DeleteObject( HBITMAP hbitmap );
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 #ifdef HAVE_LIBXXSHM
218     /* Shared memory segment info */
219     XShmSegmentInfo shminfo;
220 #endif
221
222     /* Aux buffer access function */
223     void (*copy_aux)(void*ctx, int req);
224     void *aux_ctx;
225
226     /* GDI access lock */
227     CRITICAL_SECTION lock;
228
229 } X11DRV_DIBSECTION;
230
231 extern int *X11DRV_DIB_BuildColorMap( struct tagDC *dc, WORD coloruse,
232                                       WORD depth, const BITMAPINFO *info,
233                                       int *nColors );
234 extern INT X11DRV_CoerceDIBSection(struct tagDC *dc,INT,BOOL);
235 extern INT X11DRV_LockDIBSection(struct tagDC *dc,INT,BOOL);
236 extern void X11DRV_UnlockDIBSection(struct tagDC *dc,BOOL);
237 extern INT X11DRV_CoerceDIBSection2(HBITMAP bmp,INT,BOOL);
238 extern INT X11DRV_LockDIBSection2(HBITMAP bmp,INT,BOOL);
239 extern void X11DRV_UnlockDIBSection2(HBITMAP bmp,BOOL);
240
241 extern HBITMAP X11DRV_DIB_CreateDIBSection(struct tagDC *dc, BITMAPINFO *bmi, UINT usage,
242                                            LPVOID *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 struct _DCICMD;
263 extern INT X11DRV_DCICommand(INT cbInput, const struct _DCICMD *lpCmd, 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 int 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;  /* recursion count for event processing */
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 extern Atom wmProtocols;
331 extern Atom wmDeleteWindow;
332 extern Atom wmTakeFocus;
333 extern Atom dndProtocol;
334 extern Atom dndSelection;
335 extern Atom wmChangeState;
336 extern Atom kwmDockWindow;
337 extern Atom _kde_net_wm_system_tray_window_for;
338
339 /* X11 clipboard driver */
340
341 extern void X11DRV_CLIPBOARD_FreeResources( Atom property );
342 extern BOOL X11DRV_CLIPBOARD_RegisterPixmapResource( Atom property, Pixmap pixmap );
343 extern BOOL X11DRV_CLIPBOARD_IsNativeProperty(Atom prop);
344 extern UINT X11DRV_CLIPBOARD_MapPropertyToFormat(char *itemFmtName);
345 extern Atom X11DRV_CLIPBOARD_MapFormatToProperty(UINT id);
346 extern void X11DRV_CLIPBOARD_ReleaseSelection(Atom selType, Window w, HWND hwnd);
347 extern BOOL X11DRV_IsSelectionOwner(void);
348 extern BOOL X11DRV_GetClipboardData(UINT wFormat);
349
350 /* X11 event driver */
351
352 extern WORD X11DRV_EVENT_XStateToKeyState( int state ) ;
353
354 typedef enum {
355   X11DRV_INPUT_RELATIVE,
356   X11DRV_INPUT_ABSOLUTE
357 } INPUT_TYPE;
358 extern INPUT_TYPE X11DRV_EVENT_SetInputMethod(INPUT_TYPE type);
359
360 #ifdef HAVE_LIBXXF86DGA2
361 void X11DRV_EVENT_SetDGAStatus(HWND hwnd, int event_base) ;
362 #endif
363
364
365 /* X11 keyboard driver */
366
367 extern void X11DRV_InitKeyboard(void);
368 extern WORD X11DRV_VkKeyScan(CHAR cChar);
369 extern UINT16 X11DRV_MapVirtualKey(UINT16 wCode, UINT16 wMapType);
370 extern INT16 X11DRV_GetKeyNameText(LONG lParam, LPSTR lpBuffer, INT16 nSize);
371 extern BOOL X11DRV_GetDIState(DWORD len, LPVOID ptr);
372 extern BOOL X11DRV_GetDIData(BYTE *keystate, DWORD dodsize, struct DIDEVICEOBJECTDATA *dod, LPDWORD entries, DWORD flags);
373
374 /* X11 mouse driver */
375
376 extern void X11DRV_InitMouse(LPMOUSE_EVENT_PROC);
377 extern void X11DRV_SetCursor(struct tagCURSORICONINFO *lpCursor);
378 extern void X11DRV_MoveCursor(WORD wAbsX, WORD wAbsY);
379 extern void X11DRV_SendEvent( DWORD mouseStatus, DWORD posX, DWORD posY,
380                               WORD keyState, DWORD data, DWORD time, HWND hWnd );
381
382 /* x11drv private window data */
383 struct x11drv_win_data
384 {
385     Window  whole_window;   /* X window for the complete window */
386     Window  client_window;  /* X window for the client area */
387     Window  icon_window;    /* X window for the icon */
388     RECT    whole_rect;     /* X window rectangle for the whole window relative to parent */
389     RECT    client_rect;    /* client area relative to whole window */
390     HBITMAP hWMIconBitmap;
391     HBITMAP hWMIconMask;
392 };
393
394 typedef struct x11drv_win_data X11DRV_WND_DATA;
395
396 extern Window X11DRV_get_client_window( HWND hwnd );
397 extern Window X11DRV_get_whole_window( HWND hwnd );
398
399 inline static Window get_client_window( WND *wnd )
400 {
401     struct x11drv_win_data *data = wnd->pDriverData;
402     return data->client_window;
403 }
404
405 inline static Window get_whole_window( WND *wnd )
406 {
407     struct x11drv_win_data *data = wnd->pDriverData;
408     return data->whole_window;
409 }
410
411 extern void X11DRV_SetFocus( HWND hwnd );
412 extern Cursor X11DRV_GetCursor( Display *display, struct tagCURSORICONINFO *ptr );
413
414 extern void X11DRV_expect_error( unsigned char request, unsigned char error, XID id );
415 extern int X11DRV_check_error(void);
416 extern void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data );
417 extern void X11DRV_set_iconic_state( WND *win );
418 extern void X11DRV_window_to_X_rect( WND *win, RECT *rect );
419 extern void X11DRV_X_to_window_rect( WND *win, RECT *rect );
420 extern void X11DRV_create_desktop_thread(void);
421 extern Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry );
422 extern int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder );
423 extern int X11DRV_sync_client_window_position( Display *display, WND *win );
424
425 #endif  /* __WINE_X11DRV_H */