Release 960705
[wine] / include / gdi.h
1 /*
2  * GDI definitions
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #ifndef GDI_H
8 #define GDI_H
9
10 #include <X11/Xlib.h>
11 #include <X11/Xutil.h>
12
13 #include "windows.h"
14 #include "ldt.h"
15 #include "local.h"
16
17   /* GDI objects magic numbers */
18 #define PEN_MAGIC             0x4f47
19 #define BRUSH_MAGIC           0x4f48
20 #define FONT_MAGIC            0x4f49
21 #define PALETTE_MAGIC         0x4f4a
22 #define BITMAP_MAGIC          0x4f4b
23 #define REGION_MAGIC          0x4f4c
24 #define DC_MAGIC              0x4f4d
25 #define DISABLED_DC_MAGIC     0x4f4e
26 #define META_DC_MAGIC         0x4f4f
27 #define METAFILE_MAGIC        0x4f50
28 #define METAFILE_DC_MAGIC     0x4f51
29 #define MAGIC_DONTCARE        0xffff
30
31 #ifndef WINELIB
32 #pragma pack(1)
33 #endif
34
35 typedef struct tagGDIOBJHDR
36 {
37     HANDLE16    hNext;
38     WORD        wMagic;
39     DWORD       dwCount;
40     WORD        wMetaList;
41 } GDIOBJHDR;
42
43
44 typedef struct
45 {
46     WORD   version;       /*   0: driver version */
47     WORD   technology;    /*   2: device technology */
48     WORD   horzSize;      /*   4: width of display in mm */
49     WORD   vertSize;      /*   6: height of display in mm */
50     WORD   horzRes;       /*   8: width of display in pixels */
51     WORD   vertRes;       /*  10: width of display in pixels */
52     WORD   bitsPixel;     /*  12: bits per pixel */
53     WORD   planes;        /*  14: color planes */
54     WORD   numBrushes;    /*  16: device-specific brushes */
55     WORD   numPens;       /*  18: device-specific pens */
56     WORD   numMarkers;    /*  20: device-specific markers */
57     WORD   numFonts;      /*  22: device-specific fonts */
58     WORD   numColors;     /*  24: size of color table */
59     WORD   pdeviceSize;   /*  26: size of PDEVICE structure */
60     WORD   curveCaps;     /*  28: curve capabilities */
61     WORD   lineCaps;      /*  30: line capabilities */
62     WORD   polygonalCaps; /*  32: polygon capabilities */
63     WORD   textCaps;      /*  34: text capabilities */
64     WORD   clipCaps;      /*  36: clipping capabilities */
65     WORD   rasterCaps;    /*  38: raster capabilities */
66     WORD   aspectX;       /*  40: relative width of device pixel */
67     WORD   aspectY;       /*  42: relative height of device pixel */
68     WORD   aspectXY;      /*  44: relative diagonal width of device pixel */
69     WORD   pad1[21];      /*  46-86: reserved */
70     WORD   logPixelsX;    /*  88: pixels / logical X inch */
71     WORD   logPixelsY;    /*  90: pixels / logical Y inch */
72     WORD   pad2[6];       /*  92-102: reserved */
73     WORD   sizePalette;   /* 104: entries in system palette */
74     WORD   numReserved;   /* 106: reserved entries */
75     WORD   colorRes;      /* 108: color resolution */    
76 } DeviceCaps;
77
78 #ifndef WINELIB
79 #pragma pack(4)
80 #endif
81
82
83   /* Device independent DC information */
84 typedef struct
85 {
86     int           flags;
87     DeviceCaps   *devCaps;
88
89     HANDLE16      hMetaFile;
90     HRGN16        hClipRgn;     /* Clip region (may be 0) */
91     HRGN16        hVisRgn;      /* Visible region (must never be 0) */
92     HRGN16        hGCClipRgn;   /* GC clip region (ClipRgn AND VisRgn) */
93     HPEN16        hPen;
94     HBRUSH16      hBrush;
95     HFONT16       hFont;
96     HBITMAP16     hBitmap;
97     HBITMAP16     hFirstBitmap; /* Bitmap selected at creation of the DC */
98     HANDLE16      hDevice;
99     HPALETTE16    hPalette;
100
101     WORD          ROPmode;
102     WORD          polyFillMode;
103     WORD          stretchBltMode;
104     WORD          relAbsMode;
105     WORD          backgroundMode;
106     COLORREF      backgroundColor;
107     COLORREF      textColor;
108     int           backgroundPixel;
109     int           textPixel;
110     short         brushOrgX;
111     short         brushOrgY;
112
113     WORD          textAlign;         /* Text alignment from SetTextAlign() */
114     short         charExtra;         /* Spacing from SetTextCharacterExtra() */
115     short         breakTotalExtra;   /* Total extra space for justification */
116     short         breakCount;        /* Break char. count */
117     short         breakExtra;        /* breakTotalExtra / breakCount */
118     short         breakRem;          /* breakTotalExtra % breakCount */
119
120     BYTE          bitsPerPixel;
121
122     WORD          MapMode;
123     short         DCOrgX;            /* DC origin */
124     short         DCOrgY;
125     short         CursPosX;          /* Current position */
126     short         CursPosY;
127     short         WndOrgX;
128     short         WndOrgY;
129     short         WndExtX;
130     short         WndExtY;
131     short         VportOrgX;
132     short         VportOrgY;
133     short         VportExtX;
134     short         VportExtY;
135 } WIN_DC_INFO;
136
137
138   /* X physical pen */
139 typedef struct
140 {
141     int          style;
142     int          pixel;
143     int          width;
144     char *       dashes;
145     int          dash_len;
146 } X_PHYSPEN;
147
148   /* X physical brush */
149 typedef struct
150 {
151     int          style;
152     int          fillStyle;
153     int          pixel;
154     Pixmap       pixmap;
155 } X_PHYSBRUSH;
156
157   /* X physical font */
158 typedef struct
159 {
160     XFontStruct * fstruct;
161     TEXTMETRIC16  metrics;
162 } X_PHYSFONT;
163
164   /* X physical palette information */
165 typedef struct
166 {
167     HANDLE16  hMapping;     /* Color mapping table (or 0 for identity) */
168     HANDLE16  hRevMapping;  /* Reverse color mapping table */
169     WORD      mappingSize;
170 } X_PHYSPALETTE;
171
172   /* X-specific DC information */
173 typedef struct
174 {
175     GC            gc;          /* X Window GC */
176     Drawable      drawable;
177     X_PHYSFONT    font;
178     X_PHYSPEN     pen;
179     X_PHYSBRUSH   brush;
180     X_PHYSPALETTE pal;
181 } X_DC_INFO;
182
183
184 typedef struct tagDC
185 {
186     GDIOBJHDR     header;
187     WORD          saveLevel;
188     DWORD         dwHookData;
189     FARPROC16     hookProc;
190     HDC16         hSelf;
191     WIN_DC_INFO   w;
192     union
193     {
194         X_DC_INFO x;
195         /* other devices (e.g. printer) */
196     } u;
197 } DC;
198
199   /* DC hook codes */
200 #define DCHC_INVALIDVISRGN      0x0001
201 #define DCHC_DELETEDC           0x0002
202
203 #define DCHF_INVALIDATEVISRGN   0x0001
204 #define DCHF_VALIDATEVISRGN     0x0002
205
206   /* DC flags */
207 #define DC_MEMORY     0x0001   /* It is a memory DC */
208 #define DC_SAVED      0x0002   /* It is a saved DC */
209 #define DC_DIRTY      0x0004   /* hVisRgn has to be updated */
210 #define DC_THUNKHOOK  0x0008   /* DC hook is in the 16-bit code */ 
211
212   /* Last 32 bytes are reserved for stock object handles */
213 #define GDI_HEAP_SIZE               0xffe0
214
215   /* First handle possible for stock objects (must be >= GDI_HEAP_SIZE) */
216 #define FIRST_STOCK_HANDLE          GDI_HEAP_SIZE
217
218   /* Stock objects handles */
219
220 #define NB_STOCK_OBJECTS          (SYSTEM_FIXED_FONT + 1)
221
222 #define STOCK_WHITE_BRUSH         ((HBRUSH)(FIRST_STOCK_HANDLE+WHITE_BRUSH))
223 #define STOCK_LTGRAY_BRUSH        ((HBRUSH)(FIRST_STOCK_HANDLE+LTGRAY_BRUSH))
224 #define STOCK_GRAY_BRUSH          ((HBRUSH)(FIRST_STOCK_HANDLE+GRAY_BRUSH))
225 #define STOCK_DKGRAY_BRUSH        ((HBRUSH)(FIRST_STOCK_HANDLE+DKGRAY_BRUSH))
226 #define STOCK_BLACK_BRUSH         ((HBRUSH)(FIRST_STOCK_HANDLE+BLACK_BRUSH))
227 #define STOCK_NULL_BRUSH          ((HBRUSH)(FIRST_STOCK_HANDLE+NULL_BRUSH))
228 #define STOCK_HOLLOW_BRUSH        ((HBRUSH)(FIRST_STOCK_HANDLE+HOLLOW_BRUSH))
229 #define STOCK_WHITE_PEN           ((HPEN16)(FIRST_STOCK_HANDLE+WHITE_PEN))
230 #define STOCK_BLACK_PEN           ((HPEN16)(FIRST_STOCK_HANDLE+BLACK_PEN))
231 #define STOCK_NULL_PEN            ((HPEN16)(FIRST_STOCK_HANDLE+NULL_PEN))
232 #define STOCK_OEM_FIXED_FONT      ((HFONT)(FIRST_STOCK_HANDLE+OEM_FIXED_FONT))
233 #define STOCK_ANSI_FIXED_FONT     ((HFONT)(FIRST_STOCK_HANDLE+ANSI_FIXED_FONT))
234 #define STOCK_ANSI_VAR_FONT       ((HFONT)(FIRST_STOCK_HANDLE+ANSI_VAR_FONT))
235 #define STOCK_SYSTEM_FONT         ((HFONT)(FIRST_STOCK_HANDLE+SYSTEM_FONT))
236 #define STOCK_DEVICE_DEFAULT_FONT ((HFONT)(FIRST_STOCK_HANDLE+DEVICE_DEFAULT_FONT))
237 #define STOCK_DEFAULT_PALETTE     ((HPALETTE16)(FIRST_STOCK_HANDLE+DEFAULT_PALETTE))
238 #define STOCK_SYSTEM_FIXED_FONT   ((HFONT)(FIRST_STOCK_HANDLE+SYSTEM_FIXED_FONT))
239
240 #define FIRST_STOCK_FONT          STOCK_OEM_FIXED_FONT
241 #define LAST_STOCK_FONT           STOCK_SYSTEM_FIXED_FONT
242
243 #define LAST_STOCK_HANDLE         ((DWORD)STOCK_SYSTEM_FIXED_FONT)
244
245   /* Device <-> logical coords conversion */
246
247 #define XDPTOLP(dc,x) \
248 (((x)-(dc)->w.VportOrgX) * (dc)->w.WndExtX / (dc)->w.VportExtX+(dc)->w.WndOrgX)
249 #define YDPTOLP(dc,y) \
250 (((y)-(dc)->w.VportOrgY) * (dc)->w.WndExtY / (dc)->w.VportExtY+(dc)->w.WndOrgY)
251 #define XLPTODP(dc,x) \
252 (((x)-(dc)->w.WndOrgX) * (dc)->w.VportExtX / (dc)->w.WndExtX+(dc)->w.VportOrgX)
253 #define YLPTODP(dc,y) \
254 (((y)-(dc)->w.WndOrgY) * (dc)->w.VportExtY / (dc)->w.WndExtY+(dc)->w.VportOrgY)
255
256
257   /* GDI local heap */
258
259 extern WORD GDI_HeapSel;
260
261 #define GDI_HEAP_ALLOC(size) \
262             LOCAL_Alloc( GDI_HeapSel, LMEM_FIXED, (size) )
263 #define GDI_HEAP_REALLOC(handle,size) \
264             LOCAL_ReAlloc( GDI_HeapSel, (handle), (size), LMEM_FIXED )
265 #define GDI_HEAP_FREE(handle) \
266             LOCAL_Free( GDI_HeapSel, (handle) )
267 #define GDI_HEAP_LIN_ADDR(handle)  \
268             ((handle) ? PTR_SEG_OFF_TO_LIN(GDI_HeapSel, (handle)) : NULL)
269
270 #ifdef WINELIB
271 #define GDI_HEAP_SEG_ADDR(handle) ((SEGPTR)GDI_HEAP_LIN_ADDR(handle))
272 #else
273 #define GDI_HEAP_SEG_ADDR(handle)  \
274             ((handle) ? MAKELONG((handle), GDI_HeapSel) : 0)
275
276 #endif  /* WINELIB */
277
278 extern BOOL32 GDI_Init(void);
279 extern HANDLE16 GDI_AllocObject( WORD, WORD );
280 extern BOOL32 GDI_FreeObject( HANDLE16 );
281 extern GDIOBJHDR * GDI_GetObjPtr( HANDLE16, WORD );
282 extern FARPROC16 GDI_GetDefDCHook(void);
283
284 extern Display * display;
285 extern Screen * screen;
286 extern Window rootWindow;
287 extern int screenWidth, screenHeight, screenDepth;
288 extern int desktopX, desktopY;   /* misc/main.c */
289
290 #endif  /* GDI_H */