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