DOSFS_ToDosFCBFormat: fail if extension longer than 3 characters.
[wine/gsoc-2012-control.git] / graphics / x11drv / init.c
blob548d9e4d97d981cc31dba800e5b9253bc0a72b72
1 /*
2 * X11 graphics driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include "config.h"
9 #ifndef X_DISPLAY_MISSING
11 #include "ts_xlib.h"
13 #include <string.h>
15 #include "bitmap.h"
16 #include "color.h"
17 #include "debugtools.h"
18 #include "ldt.h"
19 #include "local.h"
20 #include "monitor.h"
21 #include "winnt.h"
22 #include "x11drv.h"
24 DEFAULT_DEBUG_CHANNEL(x11drv)
26 static BOOL X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
27 LPCSTR output, const DEVMODEA* initData );
28 static BOOL X11DRV_DeleteDC( DC *dc );
30 static INT X11DRV_Escape( DC *dc, INT nEscape, INT cbInput,
31 SEGPTR lpInData, SEGPTR lpOutData );
33 static const DC_FUNCTIONS X11DRV_Funcs =
35 NULL, /* pAbortDoc */
36 NULL, /* pAbortPath */
37 NULL, /* pAngleArc */
38 X11DRV_Arc, /* pArc */
39 NULL, /* pArcTo */
40 NULL, /* pBeginPath */
41 X11DRV_BitBlt, /* pBitBlt */
42 X11DRV_BitmapBits, /* pBitmapBits */
43 X11DRV_Chord, /* pChord */
44 NULL, /* pCloseFigure */
45 X11DRV_CreateBitmap, /* pCreateBitmap */
46 X11DRV_CreateDC, /* pCreateDC */
47 X11DRV_DIB_CreateDIBSection, /* pCreateDIBSection */
48 X11DRV_DIB_CreateDIBSection16, /* pCreateDIBSection16 */
49 X11DRV_DeleteDC, /* pDeleteDC */
50 X11DRV_DeleteObject, /* pDeleteObject */
51 NULL, /* pDeviceCapabilities */
52 X11DRV_Ellipse, /* pEllipse */
53 NULL, /* pEndDoc */
54 NULL, /* pEndPage */
55 NULL, /* pEndPath */
56 X11DRV_EnumDeviceFonts, /* pEnumDeviceFonts */
57 X11DRV_Escape, /* pEscape */
58 NULL, /* pExcludeClipRect */
59 NULL, /* pExtDeviceMode */
60 X11DRV_ExtFloodFill, /* pExtFloodFill */
61 X11DRV_ExtTextOut, /* pExtTextOut */
62 NULL, /* pFillPath */
63 NULL, /* pFillRgn */
64 NULL, /* pFlattenPath */
65 NULL, /* pFrameRgn */
66 X11DRV_GetCharWidth, /* pGetCharWidth */
67 X11DRV_GetDCOrgEx, /* pGetDCOrgEx */
68 X11DRV_GetPixel, /* pGetPixel */
69 X11DRV_GetTextExtentPoint, /* pGetTextExtentPoint */
70 X11DRV_GetTextMetrics, /* pGetTextMetrics */
71 NULL, /* pIntersectClipRect */
72 NULL, /* pInvertRgn */
73 X11DRV_LineTo, /* pLineTo */
74 X11DRV_LoadOEMResource, /* pLoadOEMResource */
75 NULL, /* pMoveToEx */
76 NULL, /* pOffsetClipRgn */
77 NULL, /* pOffsetViewportOrg (optional) */
78 NULL, /* pOffsetWindowOrg (optional) */
79 X11DRV_PaintRgn, /* pPaintRgn */
80 X11DRV_PatBlt, /* pPatBlt */
81 X11DRV_Pie, /* pPie */
82 NULL, /* pPolyBezier */
83 NULL, /* pPolyBezierTo */
84 NULL, /* pPolyDraw */
85 X11DRV_PolyPolygon, /* pPolyPolygon */
86 X11DRV_PolyPolyline, /* pPolyPolyline */
87 X11DRV_Polygon, /* pPolygon */
88 X11DRV_Polyline, /* pPolyline */
89 NULL, /* pPolylineTo */
90 NULL, /* pRealizePalette */
91 X11DRV_Rectangle, /* pRectangle */
92 NULL, /* pRestoreDC */
93 X11DRV_RoundRect, /* pRoundRect */
94 NULL, /* pSaveDC */
95 NULL, /* pScaleViewportExt (optional) */
96 NULL, /* pScaleWindowExt (optional) */
97 NULL, /* pSelectClipPath */
98 NULL, /* pSelectClipRgn */
99 X11DRV_SelectObject, /* pSelectObject */
100 NULL, /* pSelectPalette */
101 X11DRV_SetBkColor, /* pSetBkColor */
102 NULL, /* pSetBkMode */
103 X11DRV_SetDeviceClipping, /* pSetDeviceClipping */
104 X11DRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */
105 NULL, /* pSetMapMode (optional) */
106 NULL, /* pSetMapperFlags */
107 X11DRV_SetPixel, /* pSetPixel */
108 NULL, /* pSetPolyFillMode */
109 NULL, /* pSetROP2 */
110 NULL, /* pSetRelAbs */
111 NULL, /* pSetStretchBltMode */
112 NULL, /* pSetTextAlign */
113 NULL, /* pSetTextCharacterExtra */
114 X11DRV_SetTextColor, /* pSetTextColor */
115 NULL, /* pSetTextJustification */
116 NULL, /* pSetViewportExt (optional) */
117 NULL, /* pSetViewportOrg (optional) */
118 NULL, /* pSetWindowExt (optional) */
119 NULL, /* pSetWindowOrg (optional) */
120 NULL, /* pStartDoc */
121 NULL, /* pStartPage */
122 X11DRV_StretchBlt, /* pStretchBlt */
123 NULL, /* pStretchDIBits */
124 NULL, /* pStrokeAndFillPath */
125 NULL, /* pStrokePath */
126 NULL /* pWidenPath */
129 BITMAP_DRIVER X11DRV_BITMAP_Driver =
131 X11DRV_DIB_SetDIBits,
132 X11DRV_DIB_GetDIBits,
133 X11DRV_DIB_DeleteDIBSection
136 PALETTE_DRIVER X11DRV_PALETTE_Driver =
138 X11DRV_PALETTE_SetMapping,
139 X11DRV_PALETTE_UpdateMapping,
140 X11DRV_PALETTE_IsDark
143 DeviceCaps X11DRV_DevCaps = {
144 /* version */ 0,
145 /* technology */ DT_RASDISPLAY,
146 /* size, resolution */ 0, 0, 0, 0, 0,
147 /* device objects */ 1, 16 + 6, 16, 0, 0, 100, 0,
148 /* curve caps */ CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
149 CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT,
150 /* line caps */ LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
151 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS,
152 /* polygon caps */ PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
153 PC_SCANLINE | PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS,
154 /* text caps */ 0,
155 /* regions */ CP_REGION,
156 /* raster caps */ RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
157 RC_DI_BITMAP | RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS,
158 /* aspects */ 36, 36, 51,
159 /* pad1 */ { 0 },
160 /* log pixels */ 0, 0,
161 /* pad2 */ { 0 },
162 /* palette size */ 0,
163 /* ..etc */ 0, 0 };
165 /**********************************************************************
166 * X11DRV_GDI_Initialize
168 BOOL X11DRV_GDI_Initialize(void)
170 BITMAP_Driver = &X11DRV_BITMAP_Driver;
171 PALETTE_Driver = &X11DRV_PALETTE_Driver;
173 /* FIXME: colormap management should be merged with the X11DRV */
175 if( !X11DRV_DIB_Init() ) return FALSE;
177 if( !X11DRV_PALETTE_Init() ) return FALSE;
179 if( !X11DRV_OBM_Init() ) return FALSE;
181 /* Finish up device caps */
183 #if 0
184 TRACE("Height = %-4i pxl, %-4i mm, Width = %-4i pxl, %-4i mm\n",
185 HeightOfScreen(X11DRV_GetXScreen()), HeightMMOfScreen(X11DRV_GetXScreen()),
186 WidthOfScreen(X11DRV_GetXScreen()), WidthMMOfScreen(X11DRV_GetXScreen()) );
187 #endif
189 X11DRV_DevCaps.version = 0x300;
190 X11DRV_DevCaps.horzSize = WidthMMOfScreen(X11DRV_GetXScreen()) * MONITOR_GetWidth(&MONITOR_PrimaryMonitor) / WidthOfScreen(X11DRV_GetXScreen());
191 X11DRV_DevCaps.vertSize = HeightMMOfScreen(X11DRV_GetXScreen()) * MONITOR_GetHeight(&MONITOR_PrimaryMonitor) / HeightOfScreen(X11DRV_GetXScreen());
192 X11DRV_DevCaps.horzRes = MONITOR_GetWidth(&MONITOR_PrimaryMonitor);
193 X11DRV_DevCaps.vertRes = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
194 X11DRV_DevCaps.bitsPixel = X11DRV_GetDepth();
196 /* Resolution will be adjusted during the font init */
198 X11DRV_DevCaps.logPixelsX = (int)(X11DRV_DevCaps.horzRes * 25.4 / X11DRV_DevCaps.horzSize);
199 X11DRV_DevCaps.logPixelsY = (int)(X11DRV_DevCaps.vertRes * 25.4 / X11DRV_DevCaps.vertSize);
201 /* Create default bitmap */
203 if (!X11DRV_BITMAP_Init()) return FALSE;
205 /* Initialize brush dithering */
207 if (!X11DRV_BRUSH_Init()) return FALSE;
209 /* Initialize fonts and text caps */
211 if (!X11DRV_FONT_Init( &X11DRV_DevCaps )) return FALSE;
213 return DRIVER_RegisterDriver( "DISPLAY", &X11DRV_Funcs );
216 /**********************************************************************
217 * X11DRV_GDI_Finalize
219 void X11DRV_GDI_Finalize(void)
221 X11DRV_PALETTE_Cleanup();
224 /**********************************************************************
225 * X11DRV_CreateDC
227 static BOOL X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
228 LPCSTR output, const DEVMODEA* initData )
230 X11DRV_PDEVICE *physDev;
232 dc->physDev = physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
233 sizeof(*physDev) );
234 if(!physDev) {
235 ERR("Can't allocate physDev\n");
236 return FALSE;
239 dc->w.devCaps = &X11DRV_DevCaps;
240 if (dc->w.flags & DC_MEMORY)
242 X11DRV_PHYSBITMAP *pbitmap;
243 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( dc->w.hBitmap,
244 BITMAP_MAGIC );
245 X11DRV_CreateBitmap( dc->w.hBitmap );
246 pbitmap = bmp->DDBitmap->physBitmap;
247 physDev->drawable = pbitmap->pixmap;
248 physDev->gc = TSXCreateGC(display, physDev->drawable, 0, NULL);
249 dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel;
251 dc->w.totalExtent.left = 0;
252 dc->w.totalExtent.top = 0;
253 dc->w.totalExtent.right = bmp->bitmap.bmWidth;
254 dc->w.totalExtent.bottom = bmp->bitmap.bmHeight;
255 dc->w.hVisRgn = CreateRectRgnIndirect( &dc->w.totalExtent );
257 GDI_HEAP_UNLOCK( dc->w.hBitmap );
259 else
261 physDev->drawable = X11DRV_GetXRootWindow();
262 physDev->gc = TSXCreateGC( display, physDev->drawable, 0, NULL );
263 dc->w.bitsPerPixel = X11DRV_GetDepth();
265 dc->w.totalExtent.left = 0;
266 dc->w.totalExtent.top = 0;
267 dc->w.totalExtent.right = MONITOR_GetWidth(&MONITOR_PrimaryMonitor);
268 dc->w.totalExtent.bottom = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
269 dc->w.hVisRgn = CreateRectRgnIndirect( &dc->w.totalExtent );
272 if (!dc->w.hVisRgn)
274 TSXFreeGC( display, physDev->gc );
275 return FALSE;
278 TSXSetGraphicsExposures( display, physDev->gc, False );
279 TSXSetSubwindowMode( display, physDev->gc, IncludeInferiors );
281 return TRUE;
285 /**********************************************************************
286 * X11DRV_DeleteDC
288 static BOOL X11DRV_DeleteDC( DC *dc )
290 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
291 TSXFreeGC( display, physDev->gc );
292 HeapFree( GetProcessHeap(), 0, physDev );
293 dc->physDev = NULL;
294 return TRUE;
297 /**********************************************************************
298 * X11DRV_Escape
300 static INT X11DRV_Escape( DC *dc, INT nEscape, INT cbInput,
301 SEGPTR lpInData, SEGPTR lpOutData )
303 switch( nEscape )
305 case GETSCALINGFACTOR:
306 if( lpOutData )
308 LPPOINT16 lppt = (LPPOINT16)PTR_SEG_TO_LIN(lpOutData);
309 lppt->x = lppt->y = 0; /* no device scaling */
310 return 1;
312 break;
314 return 0;
317 #endif /* !defined(X_DISPLAY_MISSING) */