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