2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
10 #ifndef X_DISPLAY_MISSING
13 #endif /* !defined(X_DISPLAY_MISSING) */
20 #include "debugtools.h"
26 #include "wine/winuser16.h"
28 DEFAULT_DEBUG_CHANNEL(dc)
30 /***********************************************************************
33 * Fill the WIN_DC_INFO structure.
35 static void DC_Init_DC_INFO( WIN_DC_INFO *win_dc_info )
37 win_dc_info->flags = 0;
38 win_dc_info->devCaps = NULL;
39 win_dc_info->hClipRgn = 0;
40 win_dc_info->hVisRgn = 0;
41 win_dc_info->hGCClipRgn = 0;
42 win_dc_info->hPen = STOCK_BLACK_PEN;
43 win_dc_info->hBrush = STOCK_WHITE_BRUSH;
44 win_dc_info->hFont = STOCK_SYSTEM_FONT;
45 win_dc_info->hBitmap = 0;
46 win_dc_info->hDevice = 0;
47 win_dc_info->hPalette = STOCK_DEFAULT_PALETTE;
48 win_dc_info->ROPmode = R2_COPYPEN;
49 win_dc_info->polyFillMode = ALTERNATE;
50 win_dc_info->stretchBltMode = BLACKONWHITE;
51 win_dc_info->relAbsMode = ABSOLUTE;
52 win_dc_info->backgroundMode = OPAQUE;
53 win_dc_info->backgroundColor = RGB( 255, 255, 255 );
54 win_dc_info->textColor = RGB( 0, 0, 0 );
55 win_dc_info->brushOrgX = 0;
56 win_dc_info->brushOrgY = 0;
57 win_dc_info->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
58 win_dc_info->charExtra = 0;
59 win_dc_info->breakTotalExtra = 0;
60 win_dc_info->breakCount = 0;
61 win_dc_info->breakExtra = 0;
62 win_dc_info->breakRem = 0;
63 win_dc_info->bitsPerPixel = 1;
64 win_dc_info->MapMode = MM_TEXT;
65 win_dc_info->GraphicsMode = GM_COMPATIBLE;
66 win_dc_info->DCOrgX = 0;
67 win_dc_info->DCOrgY = 0;
68 win_dc_info->pAbortProc = NULL;
69 win_dc_info->CursPosX = 0;
70 win_dc_info->CursPosY = 0;
71 win_dc_info->ArcDirection = AD_COUNTERCLOCKWISE;
72 win_dc_info->xformWorld2Wnd.eM11 = 1.0f;
73 win_dc_info->xformWorld2Wnd.eM12 = 0.0f;
74 win_dc_info->xformWorld2Wnd.eM21 = 0.0f;
75 win_dc_info->xformWorld2Wnd.eM22 = 1.0f;
76 win_dc_info->xformWorld2Wnd.eDx = 0.0f;
77 win_dc_info->xformWorld2Wnd.eDy = 0.0f;
78 win_dc_info->xformWorld2Vport = win_dc_info->xformWorld2Wnd;
79 win_dc_info->xformVport2World = win_dc_info->xformWorld2Wnd;
80 win_dc_info->vport2WorldValid = TRUE;
82 PATH_InitGdiPath(&win_dc_info->path);
86 /***********************************************************************
89 DC *DC_AllocDC( const DC_FUNCTIONS *funcs )
94 if (!(hdc = GDI_AllocObject( sizeof(DC), DC_MAGIC ))) return NULL;
95 dc = (DC *) GDI_HEAP_LOCK( hdc );
103 dc->hookThunk = NULL;
113 DC_Init_DC_INFO( &dc->w );
120 /***********************************************************************
123 DC *DC_GetDCPtr( HDC hdc )
125 GDIOBJHDR *ptr = (GDIOBJHDR *)GDI_HEAP_LOCK( hdc );
126 if (!ptr) return NULL;
127 if ((ptr->wMagic == DC_MAGIC) || (ptr->wMagic == METAFILE_DC_MAGIC) ||
128 (ptr->wMagic == ENHMETAFILE_DC_MAGIC))
130 GDI_HEAP_UNLOCK( hdc );
135 /***********************************************************************
138 * Setup device-specific DC values for a newly created DC.
140 void DC_InitDC( DC* dc )
142 RealizeDefaultPalette16( dc->hSelf );
143 SetTextColor( dc->hSelf, dc->w.textColor );
144 SetBkColor( dc->hSelf, dc->w.backgroundColor );
145 SelectObject( dc->hSelf, dc->w.hPen );
146 SelectObject( dc->hSelf, dc->w.hBrush );
147 SelectObject( dc->hSelf, dc->w.hFont );
148 CLIPPING_UpdateGCRegion( dc );
152 /***********************************************************************
155 * Computes the inverse of the transformation xformSrc and stores it to
156 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
159 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
163 determinant = xformSrc->eM11*xformSrc->eM22 -
164 xformSrc->eM12*xformSrc->eM21;
165 if (determinant > -1e-12 && determinant < 1e-12)
168 xformDest->eM11 = xformSrc->eM22 / determinant;
169 xformDest->eM12 = -xformSrc->eM12 / determinant;
170 xformDest->eM21 = -xformSrc->eM21 / determinant;
171 xformDest->eM22 = xformSrc->eM11 / determinant;
172 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
173 xformSrc->eDy * xformDest->eM21;
174 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
175 xformSrc->eDy * xformDest->eM22;
181 /***********************************************************************
184 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
185 * fields of the specified DC by creating a transformation that
186 * represents the current mapping mode and combining it with the DC's
187 * world transform. This function should be called whenever the
188 * parameters associated with the mapping mode (window and viewport
189 * extents and origins) or the world transform change.
191 void DC_UpdateXforms( DC *dc )
193 XFORM xformWnd2Vport;
194 FLOAT scaleX, scaleY;
196 /* Construct a transformation to do the window-to-viewport conversion */
197 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
198 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
199 xformWnd2Vport.eM11 = scaleX;
200 xformWnd2Vport.eM12 = 0.0;
201 xformWnd2Vport.eM21 = 0.0;
202 xformWnd2Vport.eM22 = scaleY;
203 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
204 scaleX * (FLOAT)dc->wndOrgX;
205 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
206 scaleY * (FLOAT)dc->wndOrgY;
208 /* Combine with the world transformation */
209 CombineTransform( &dc->w.xformWorld2Vport, &dc->w.xformWorld2Wnd,
212 /* Create inverse of world-to-viewport transformation */
213 dc->w.vport2WorldValid = DC_InvertXform( &dc->w.xformWorld2Vport,
214 &dc->w.xformVport2World );
218 /***********************************************************************
219 * GetDCState (GDI.179)
221 HDC16 WINAPI GetDCState16( HDC16 hdc )
226 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
227 if (!(handle = GDI_AllocObject( sizeof(DC), DC_MAGIC )))
229 GDI_HEAP_UNLOCK( hdc );
232 newdc = (DC *) GDI_HEAP_LOCK( handle );
234 TRACE("(%04x): returning %04x\n", hdc, handle );
236 newdc->w.flags = dc->w.flags | DC_SAVED;
237 newdc->w.devCaps = dc->w.devCaps;
238 newdc->w.hPen = dc->w.hPen;
239 newdc->w.hBrush = dc->w.hBrush;
240 newdc->w.hFont = dc->w.hFont;
241 newdc->w.hBitmap = dc->w.hBitmap;
242 newdc->w.hDevice = dc->w.hDevice;
243 newdc->w.hPalette = dc->w.hPalette;
244 newdc->w.totalExtent = dc->w.totalExtent;
245 newdc->w.bitsPerPixel = dc->w.bitsPerPixel;
246 newdc->w.ROPmode = dc->w.ROPmode;
247 newdc->w.polyFillMode = dc->w.polyFillMode;
248 newdc->w.stretchBltMode = dc->w.stretchBltMode;
249 newdc->w.relAbsMode = dc->w.relAbsMode;
250 newdc->w.backgroundMode = dc->w.backgroundMode;
251 newdc->w.backgroundColor = dc->w.backgroundColor;
252 newdc->w.textColor = dc->w.textColor;
253 newdc->w.brushOrgX = dc->w.brushOrgX;
254 newdc->w.brushOrgY = dc->w.brushOrgY;
255 newdc->w.textAlign = dc->w.textAlign;
256 newdc->w.charExtra = dc->w.charExtra;
257 newdc->w.breakTotalExtra = dc->w.breakTotalExtra;
258 newdc->w.breakCount = dc->w.breakCount;
259 newdc->w.breakExtra = dc->w.breakExtra;
260 newdc->w.breakRem = dc->w.breakRem;
261 newdc->w.MapMode = dc->w.MapMode;
262 newdc->w.GraphicsMode = dc->w.GraphicsMode;
264 /* Apparently, the DC origin is not changed by [GS]etDCState */
265 newdc->w.DCOrgX = dc->w.DCOrgX;
266 newdc->w.DCOrgY = dc->w.DCOrgY;
268 newdc->w.CursPosX = dc->w.CursPosX;
269 newdc->w.CursPosY = dc->w.CursPosY;
270 newdc->w.ArcDirection = dc->w.ArcDirection;
271 newdc->w.xformWorld2Wnd = dc->w.xformWorld2Wnd;
272 newdc->w.xformWorld2Vport = dc->w.xformWorld2Vport;
273 newdc->w.xformVport2World = dc->w.xformVport2World;
274 newdc->w.vport2WorldValid = dc->w.vport2WorldValid;
275 newdc->wndOrgX = dc->wndOrgX;
276 newdc->wndOrgY = dc->wndOrgY;
277 newdc->wndExtX = dc->wndExtX;
278 newdc->wndExtY = dc->wndExtY;
279 newdc->vportOrgX = dc->vportOrgX;
280 newdc->vportOrgY = dc->vportOrgY;
281 newdc->vportExtX = dc->vportExtX;
282 newdc->vportExtY = dc->vportExtY;
284 newdc->hSelf = (HDC)handle;
285 newdc->saveLevel = 0;
287 PATH_InitGdiPath( &newdc->w.path );
289 newdc->w.pAbortProc = NULL;
291 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
293 newdc->w.hGCClipRgn = newdc->w.hVisRgn = 0;
296 newdc->w.hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
297 CombineRgn( newdc->w.hClipRgn, dc->w.hClipRgn, 0, RGN_COPY );
300 newdc->w.hClipRgn = 0;
301 GDI_HEAP_UNLOCK( handle );
302 GDI_HEAP_UNLOCK( hdc );
307 /***********************************************************************
308 * SetDCState (GDI.180)
310 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
314 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
315 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC )))
317 GDI_HEAP_UNLOCK( hdc );
320 if (!dcs->w.flags & DC_SAVED)
322 GDI_HEAP_UNLOCK( hdc );
323 GDI_HEAP_UNLOCK( hdcs );
326 TRACE("%04x %04x\n", hdc, hdcs );
328 dc->w.flags = dcs->w.flags & ~DC_SAVED;
329 dc->w.devCaps = dcs->w.devCaps;
330 dc->w.hDevice = dcs->w.hDevice;
331 dc->w.totalExtent = dcs->w.totalExtent;
332 dc->w.ROPmode = dcs->w.ROPmode;
333 dc->w.polyFillMode = dcs->w.polyFillMode;
334 dc->w.stretchBltMode = dcs->w.stretchBltMode;
335 dc->w.relAbsMode = dcs->w.relAbsMode;
336 dc->w.backgroundMode = dcs->w.backgroundMode;
337 dc->w.backgroundColor = dcs->w.backgroundColor;
338 dc->w.textColor = dcs->w.textColor;
339 dc->w.brushOrgX = dcs->w.brushOrgX;
340 dc->w.brushOrgY = dcs->w.brushOrgY;
341 dc->w.textAlign = dcs->w.textAlign;
342 dc->w.charExtra = dcs->w.charExtra;
343 dc->w.breakTotalExtra = dcs->w.breakTotalExtra;
344 dc->w.breakCount = dcs->w.breakCount;
345 dc->w.breakExtra = dcs->w.breakExtra;
346 dc->w.breakRem = dcs->w.breakRem;
347 dc->w.MapMode = dcs->w.MapMode;
348 dc->w.GraphicsMode = dcs->w.GraphicsMode;
350 /* Apparently, the DC origin is not changed by [GS]etDCState */
351 dc->w.DCOrgX = dcs->w.DCOrgX;
352 dc->w.DCOrgY = dcs->w.DCOrgY;
354 dc->w.CursPosX = dcs->w.CursPosX;
355 dc->w.CursPosY = dcs->w.CursPosY;
356 dc->w.ArcDirection = dcs->w.ArcDirection;
357 dc->w.xformWorld2Wnd = dcs->w.xformWorld2Wnd;
358 dc->w.xformWorld2Vport = dcs->w.xformWorld2Vport;
359 dc->w.xformVport2World = dcs->w.xformVport2World;
360 dc->w.vport2WorldValid = dcs->w.vport2WorldValid;
362 dc->wndOrgX = dcs->wndOrgX;
363 dc->wndOrgY = dcs->wndOrgY;
364 dc->wndExtX = dcs->wndExtX;
365 dc->wndExtY = dcs->wndExtY;
366 dc->vportOrgX = dcs->vportOrgX;
367 dc->vportOrgY = dcs->vportOrgY;
368 dc->vportExtX = dcs->vportExtX;
369 dc->vportExtY = dcs->vportExtY;
371 if (!(dc->w.flags & DC_MEMORY)) dc->w.bitsPerPixel = dcs->w.bitsPerPixel;
375 if (!dc->w.hClipRgn) dc->w.hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
376 CombineRgn( dc->w.hClipRgn, dcs->w.hClipRgn, 0, RGN_COPY );
380 if (dc->w.hClipRgn) DeleteObject16( dc->w.hClipRgn );
383 CLIPPING_UpdateGCRegion( dc );
385 SelectObject( hdc, dcs->w.hBitmap );
386 SelectObject( hdc, dcs->w.hBrush );
387 SelectObject( hdc, dcs->w.hFont );
388 SelectObject( hdc, dcs->w.hPen );
389 SetBkColor( hdc, dcs->w.backgroundColor);
390 SetTextColor( hdc, dcs->w.textColor);
391 GDISelectPalette16( hdc, dcs->w.hPalette, FALSE );
392 GDI_HEAP_UNLOCK( hdc );
393 GDI_HEAP_UNLOCK( hdcs );
397 /***********************************************************************
400 INT16 WINAPI SaveDC16( HDC16 hdc )
402 return (INT16)SaveDC( hdc );
406 /***********************************************************************
407 * SaveDC32 (GDI32.292)
409 INT WINAPI SaveDC( HDC hdc )
415 dc = DC_GetDCPtr( hdc );
418 if(dc->funcs->pSaveDC)
419 return dc->funcs->pSaveDC( dc );
421 if (!(hdcs = GetDCState16( hdc )))
423 GDI_HEAP_UNLOCK( hdc );
426 dcs = (DC *) GDI_HEAP_LOCK( hdcs );
428 /* Copy path. The reason why path saving / restoring is in SaveDC/
429 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
430 * functions are only in Win16 (which doesn't have paths) and that
431 * SetDCState doesn't allow us to signal an error (which can happen
432 * when copying paths).
434 if (!PATH_AssignGdiPath( &dcs->w.path, &dc->w.path ))
436 GDI_HEAP_UNLOCK( hdc );
437 GDI_HEAP_UNLOCK( hdcs );
442 dcs->header.hNext = dc->header.hNext;
443 dc->header.hNext = hdcs;
444 TRACE("(%04x): returning %d\n", hdc, dc->saveLevel+1 );
445 ret = ++dc->saveLevel;
446 GDI_HEAP_UNLOCK( hdcs );
447 GDI_HEAP_UNLOCK( hdc );
452 /***********************************************************************
453 * RestoreDC16 (GDI.39)
455 BOOL16 WINAPI RestoreDC16( HDC16 hdc, INT16 level )
457 return RestoreDC( hdc, level );
461 /***********************************************************************
462 * RestoreDC32 (GDI32.290)
464 BOOL WINAPI RestoreDC( HDC hdc, INT level )
469 TRACE("%04x %d\n", hdc, level );
470 dc = DC_GetDCPtr( hdc );
471 if(!dc) return FALSE;
472 if(dc->funcs->pRestoreDC)
473 return dc->funcs->pRestoreDC( dc, level );
475 if (level == -1) level = dc->saveLevel;
476 if ((level < 1) || (level > dc->saveLevel))
478 GDI_HEAP_UNLOCK( hdc );
483 while (dc->saveLevel >= level)
485 HDC16 hdcs = dc->header.hNext;
486 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC )))
488 GDI_HEAP_UNLOCK( hdc );
491 dc->header.hNext = dcs->header.hNext;
492 if (--dc->saveLevel < level)
494 SetDCState16( hdc, hdcs );
495 if (!PATH_AssignGdiPath( &dc->w.path, &dcs->w.path ))
496 /* FIXME: This might not be quite right, since we're
497 * returning FALSE but still destroying the saved DC state */
502 GDI_HEAP_UNLOCK( hdc );
507 /***********************************************************************
508 * CreateDC16 (GDI.53)
510 HDC16 WINAPI CreateDC16( LPCSTR driver, LPCSTR device, LPCSTR output,
511 const DEVMODEA *initData )
514 const DC_FUNCTIONS *funcs;
518 if(!DRIVER_GetDriverName( device, buf, sizeof(buf) )) return 0;
522 if (!(funcs = DRIVER_FindDriver( buf ))) return 0;
523 if (!(dc = DC_AllocDC( funcs ))) return 0;
526 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
527 debugstr_a(driver), debugstr_a(device), debugstr_a(output), dc->hSelf );
529 if (dc->funcs->pCreateDC &&
530 !dc->funcs->pCreateDC( dc, buf, device, output, initData ))
532 WARN("creation aborted by device\n" );
533 GDI_HEAP_FREE( dc->hSelf );
538 GDI_HEAP_UNLOCK( dc->hSelf );
543 /***********************************************************************
544 * CreateDC32A (GDI32.)
546 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
547 const DEVMODEA *initData )
549 return CreateDC16( driver, device, output, (const DEVMODEA *)initData );
553 /***********************************************************************
554 * CreateDC32W (GDI32.)
556 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
557 const DEVMODEW *initData )
559 LPSTR driverA = HEAP_strdupWtoA( GetProcessHeap(), 0, driver );
560 LPSTR deviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, device );
561 LPSTR outputA = HEAP_strdupWtoA( GetProcessHeap(), 0, output );
562 HDC res = CreateDC16( driverA, deviceA, outputA,
563 (const DEVMODEA *)initData /*FIXME*/ );
564 HeapFree( GetProcessHeap(), 0, driverA );
565 HeapFree( GetProcessHeap(), 0, deviceA );
566 HeapFree( GetProcessHeap(), 0, outputA );
571 /***********************************************************************
572 * CreateIC16 (GDI.153)
574 HDC16 WINAPI CreateIC16( LPCSTR driver, LPCSTR device, LPCSTR output,
575 const DEVMODEA* initData )
577 /* Nothing special yet for ICs */
578 return CreateDC16( driver, device, output, initData );
582 /***********************************************************************
583 * CreateIC32A (GDI32.49)
585 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
586 const DEVMODEA* initData )
588 /* Nothing special yet for ICs */
589 return CreateDCA( driver, device, output, initData );
593 /***********************************************************************
594 * CreateIC32W (GDI32.50)
596 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
597 const DEVMODEW* initData )
599 /* Nothing special yet for ICs */
600 return CreateDCW( driver, device, output, initData );
604 /***********************************************************************
605 * CreateCompatibleDC16 (GDI.52)
607 HDC16 WINAPI CreateCompatibleDC16( HDC16 hdc )
609 return (HDC16)CreateCompatibleDC( hdc );
613 /***********************************************************************
614 * CreateCompatibleDC32 (GDI32.31)
616 HDC WINAPI CreateCompatibleDC( HDC hdc )
619 const DC_FUNCTIONS *funcs;
621 if ((origDC = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC ))) funcs = origDC->funcs;
622 else funcs = DRIVER_FindDriver( "DISPLAY" );
623 if (!funcs) return 0;
625 if (!(dc = DC_AllocDC( funcs ))) return 0;
627 TRACE("(%04x): returning %04x\n",
630 dc->w.flags = DC_MEMORY;
631 dc->w.bitsPerPixel = 1;
632 dc->w.hBitmap = hPseudoStockBitmap;
634 /* Copy the driver-specific physical device info into
635 * the new DC. The driver may use this read-only info
636 * while creating the compatible DC below. */
638 dc->physDev = origDC->physDev;
640 if (dc->funcs->pCreateDC &&
641 !dc->funcs->pCreateDC( dc, NULL, NULL, NULL, NULL ))
643 WARN("creation aborted by device\n");
644 GDI_HEAP_FREE( dc->hSelf );
649 GDI_HEAP_UNLOCK( dc->hSelf );
654 /***********************************************************************
655 * DeleteDC16 (GDI.68)
657 BOOL16 WINAPI DeleteDC16( HDC16 hdc )
659 return DeleteDC( hdc );
663 /***********************************************************************
664 * DeleteDC32 (GDI32.67)
666 BOOL WINAPI DeleteDC( HDC hdc )
668 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
669 if (!dc) return FALSE;
671 TRACE("%04x\n", hdc );
673 /* Call hook procedure to check whether is it OK to delete this DC */
674 if ( dc->hookThunk && !(dc->w.flags & (DC_SAVED | DC_MEMORY))
675 && dc->hookThunk( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ) == FALSE )
677 GDI_HEAP_UNLOCK( hdc );
681 while (dc->saveLevel)
684 HDC16 hdcs = dc->header.hNext;
685 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) break;
686 dc->header.hNext = dcs->header.hNext;
691 if (!(dc->w.flags & DC_SAVED))
693 SelectObject( hdc, STOCK_BLACK_PEN );
694 SelectObject( hdc, STOCK_WHITE_BRUSH );
695 SelectObject( hdc, STOCK_SYSTEM_FONT );
696 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc);
699 if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
700 if (dc->w.hVisRgn) DeleteObject( dc->w.hVisRgn );
701 if (dc->w.hGCClipRgn) DeleteObject( dc->w.hGCClipRgn );
702 if (dc->w.pAbortProc) THUNK_Free( (FARPROC)dc->w.pAbortProc );
703 if (dc->hookThunk) THUNK_Free( (FARPROC)dc->hookThunk );
704 PATH_DestroyGdiPath(&dc->w.path);
706 return GDI_FreeObject( hdc );
710 /***********************************************************************
711 * ResetDC16 (GDI.376)
713 HDC16 WINAPI ResetDC16( HDC16 hdc, const DEVMODEA *devmode )
720 /***********************************************************************
721 * ResetDC32A (GDI32.287)
723 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
730 /***********************************************************************
731 * ResetDC32W (GDI32.288)
733 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
740 /***********************************************************************
741 * GetDeviceCaps16 (GDI.80)
743 INT16 WINAPI GetDeviceCaps16( HDC16 hdc, INT16 cap )
745 return GetDeviceCaps( hdc, cap );
749 /***********************************************************************
750 * GetDeviceCaps32 (GDI32.171)
752 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
754 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
760 /* Device capabilities for the printer */
764 if(Escape(hdc, GETPHYSPAGESIZE, 0, NULL, (LPVOID)&pt) > 0)
767 if(Escape(hdc, GETPHYSPAGESIZE, 0, NULL, (LPVOID)&pt) > 0)
769 case PHYSICALOFFSETX:
770 if(Escape(hdc, GETPRINTINGOFFSET, 0, NULL, (LPVOID)&pt) > 0)
772 case PHYSICALOFFSETY:
773 if(Escape(hdc, GETPRINTINGOFFSET, 0, NULL, (LPVOID)&pt) > 0)
776 if(Escape(hdc, GETSCALINGFACTOR, 0, NULL, (LPVOID)&pt) > 0)
779 if(Escape(hdc, GETSCALINGFACTOR, 0, NULL, (LPVOID)&pt) > 0)
783 if ((cap < 0) || (cap > sizeof(DeviceCaps)-sizeof(WORD)))
785 GDI_HEAP_UNLOCK( hdc );
789 if (((cap>=46) && (cap<88)) || ((cap>=92) && (cap<104)))
790 FIXME("(%04x,%d): unsupported DeviceCaps capability, will yield 0!\n",
793 TRACE("(%04x,%d): returning %d\n",
794 hdc, cap, *(WORD *)(((char *)dc->w.devCaps) + cap) );
795 ret = *(WORD *)(((char *)dc->w.devCaps) + cap);
796 GDI_HEAP_UNLOCK( hdc );
801 /***********************************************************************
802 * SetBkColor16 (GDI.1)
804 COLORREF WINAPI SetBkColor16( HDC16 hdc, COLORREF color )
806 return SetBkColor( hdc, color );
810 /***********************************************************************
811 * SetBkColor32 (GDI32.305)
813 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
816 DC * dc = DC_GetDCPtr( hdc );
818 if (!dc) return 0x80000000;
819 if (dc->funcs->pSetBkColor)
820 oldColor = dc->funcs->pSetBkColor(dc, color);
822 oldColor = dc->w.backgroundColor;
823 dc->w.backgroundColor = color;
825 GDI_HEAP_UNLOCK( hdc );
830 /***********************************************************************
831 * SetTextColor16 (GDI.9)
833 COLORREF WINAPI SetTextColor16( HDC16 hdc, COLORREF color )
835 return SetTextColor( hdc, color );
839 /***********************************************************************
840 * SetTextColor32 (GDI32.338)
842 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
845 DC * dc = DC_GetDCPtr( hdc );
847 if (!dc) return 0x80000000;
848 if (dc->funcs->pSetTextColor)
849 oldColor = dc->funcs->pSetTextColor(dc, color);
851 oldColor = dc->w.textColor;
852 dc->w.textColor = color;
854 GDI_HEAP_UNLOCK( hdc );
858 /***********************************************************************
859 * SetTextAlign16 (GDI.346)
861 UINT16 WINAPI SetTextAlign16( HDC16 hdc, UINT16 align )
863 return SetTextAlign( hdc, align );
867 /***********************************************************************
868 * SetTextAlign (GDI32.336)
870 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
873 DC *dc = DC_GetDCPtr( hdc );
875 if (dc->funcs->pSetTextAlign)
876 prevAlign = dc->funcs->pSetTextAlign(dc, align);
878 prevAlign = dc->w.textAlign;
879 dc->w.textAlign = align;
881 GDI_HEAP_UNLOCK( hdc );
885 /***********************************************************************
886 * GetDCOrgEx (GDI32.168)
888 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
892 if (!lpp) return FALSE;
893 if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return FALSE;
895 #ifndef X_DISPLAY_MISSING
896 if (!(dc->w.flags & DC_MEMORY))
898 X11DRV_PDEVICE *physDev;
900 int w, h, border, depth;
902 physDev = (X11DRV_PDEVICE *) dc->physDev;
904 /* FIXME: this is not correct for managed windows */
905 TSXGetGeometry( display, physDev->drawable, &root,
906 (int*)&lpp->x, (int*)&lpp->y, &w, &h, &border, &depth );
909 #endif /* !defined(X_DISPLAY_MISSING) */
912 lpp->x += dc->w.DCOrgX; lpp->y += dc->w.DCOrgY;
913 GDI_HEAP_UNLOCK( hDC );
918 /***********************************************************************
921 DWORD WINAPI GetDCOrg16( HDC16 hdc )
924 if( GetDCOrgEx( hdc, &pt) )
925 return MAKELONG( (WORD)pt.x, (WORD)pt.y );
930 /***********************************************************************
933 DWORD WINAPI SetDCOrg16( HDC16 hdc, INT16 x, INT16 y )
936 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
938 prevOrg = dc->w.DCOrgX | (dc->w.DCOrgY << 16);
941 GDI_HEAP_UNLOCK( hdc );
946 /***********************************************************************
947 * GetGraphicsMode (GDI32.188)
949 INT WINAPI GetGraphicsMode( HDC hdc )
951 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
953 return dc->w.GraphicsMode;
957 /***********************************************************************
958 * SetGraphicsMode (GDI32.317)
960 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
963 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
965 /* One would think that setting the graphics mode to GM_COMPATIBLE
966 * would also reset the world transformation matrix to the unity
967 * matrix. However, in Windows, this is not the case. This doesn't
968 * make a lot of sense to me, but that's the way it is.
972 if ((mode <= 0) || (mode > GM_LAST)) return 0;
973 ret = dc->w.GraphicsMode;
974 dc->w.GraphicsMode = mode;
979 /***********************************************************************
980 * GetArcDirection16 (GDI.524)
982 INT16 WINAPI GetArcDirection16( HDC16 hdc )
984 return GetArcDirection( (HDC)hdc );
988 /***********************************************************************
989 * GetArcDirection32 (GDI32.141)
991 INT WINAPI GetArcDirection( HDC hdc )
993 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
998 return dc->w.ArcDirection;
1002 /***********************************************************************
1003 * SetArcDirection16 (GDI.525)
1005 INT16 WINAPI SetArcDirection16( HDC16 hdc, INT16 nDirection )
1007 return SetArcDirection( (HDC)hdc, (INT)nDirection );
1011 /***********************************************************************
1012 * SetArcDirection32 (GDI32.302)
1014 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1016 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1022 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1024 SetLastError(ERROR_INVALID_PARAMETER);
1028 nOldDirection = dc->w.ArcDirection;
1029 dc->w.ArcDirection = nDirection;
1031 return nOldDirection;
1035 /***********************************************************************
1036 * GetWorldTransform (GDI32.244)
1038 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1040 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1047 *xform = dc->w.xformWorld2Wnd;
1053 /***********************************************************************
1054 * SetWorldTransform (GDI32.346)
1056 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1058 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1062 SetLastError( ERROR_INVALID_HANDLE );
1069 /* Check that graphics mode is GM_ADVANCED */
1070 if (dc->w.GraphicsMode!=GM_ADVANCED)
1073 dc->w.xformWorld2Wnd = *xform;
1075 DC_UpdateXforms( dc );
1081 /****************************************************************************
1082 * ModifyWorldTransform [GDI32.253]
1083 * Modifies the world transformation for a device context.
1086 * hdc [I] Handle to device context
1087 * xform [I] XFORM structure that will be used to modify the world
1089 * iMode [I] Specifies in what way to modify the world transformation
1092 * Resets the world transformation to the identity matrix.
1093 * The parameter xform is ignored.
1095 * Multiplies xform into the world transformation matrix from
1098 * Multiplies xform into the world transformation matrix from
1103 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1106 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1108 /* Check for illegal parameters */
1111 SetLastError( ERROR_INVALID_HANDLE );
1117 /* Check that graphics mode is GM_ADVANCED */
1118 if (dc->w.GraphicsMode!=GM_ADVANCED)
1124 dc->w.xformWorld2Wnd.eM11 = 1.0f;
1125 dc->w.xformWorld2Wnd.eM12 = 0.0f;
1126 dc->w.xformWorld2Wnd.eM21 = 0.0f;
1127 dc->w.xformWorld2Wnd.eM22 = 1.0f;
1128 dc->w.xformWorld2Wnd.eDx = 0.0f;
1129 dc->w.xformWorld2Wnd.eDy = 0.0f;
1131 case MWT_LEFTMULTIPLY:
1132 CombineTransform( &dc->w.xformWorld2Wnd, xform,
1133 &dc->w.xformWorld2Wnd );
1135 case MWT_RIGHTMULTIPLY:
1136 CombineTransform( &dc->w.xformWorld2Wnd, &dc->w.xformWorld2Wnd,
1143 DC_UpdateXforms( dc );
1149 /****************************************************************************
1150 * CombineTransform [GDI32.20]
1151 * Combines two transformation matrices.
1154 * xformResult [O] Stores the result of combining the two matrices
1155 * xform1 [I] Specifies the first matrix to apply
1156 * xform2 [I] Specifies the second matrix to apply
1159 * The same matrix can be passed in for more than one of the parameters.
1163 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1164 const XFORM *xform2 )
1168 /* Check for illegal parameters */
1169 if (!xformResult || !xform1 || !xform2)
1172 /* Create the result in a temporary XFORM, since xformResult may be
1173 * equal to xform1 or xform2 */
1174 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1175 xform1->eM12 * xform2->eM21;
1176 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1177 xform1->eM12 * xform2->eM22;
1178 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1179 xform1->eM22 * xform2->eM21;
1180 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1181 xform1->eM22 * xform2->eM22;
1182 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1183 xform1->eDy * xform2->eM21 +
1185 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1186 xform1->eDy * xform2->eM22 +
1189 /* Copy the result to xformResult */
1190 *xformResult = xformTemp;
1196 /***********************************************************************
1197 * SetDCHook (GDI.190)
1199 /* ### start build ### */
1200 extern WORD CALLBACK GDI_CallTo16_word_wwll(FARPROC16,WORD,WORD,LONG,LONG);
1201 /* ### stop build ### */
1202 BOOL16 WINAPI SetDCHook( HDC16 hdc, FARPROC16 hookProc, DWORD dwHookData )
1204 DC *dc = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC );
1205 if (!dc) return FALSE;
1208 * Note: We store the original SEGPTR 'hookProc' as we need to be
1209 * able to return it verbatim in GetDCHook,
1211 * On the other hand, we still call THUNK_Alloc and store the
1212 * 32-bit thunk into another DC member, because THUNK_Alloc
1213 * recognizes the (typical) case that the 'hookProc' is indeed
1214 * the 16-bit API entry point of a built-in routine (e.g. DCHook16)
1216 * We could perform that test every time the hook is about to
1217 * be called (or else we could live with the 32->16->32 detour),
1218 * but this way is the most efficient ...
1221 dc->hookProc = hookProc;
1222 dc->dwHookData = dwHookData;
1224 THUNK_Free( (FARPROC)dc->hookThunk );
1225 dc->hookThunk = (DCHOOKPROC)
1226 THUNK_Alloc( hookProc, (RELAY)GDI_CallTo16_word_wwll );
1228 GDI_HEAP_UNLOCK( hdc );
1233 /***********************************************************************
1234 * GetDCHook (GDI.191)
1236 DWORD WINAPI GetDCHook( HDC16 hdc, FARPROC16 *phookProc )
1238 DC *dc = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC );
1240 *phookProc = dc->hookProc;
1241 GDI_HEAP_UNLOCK( hdc );
1242 return dc->dwHookData;
1246 /***********************************************************************
1247 * SetHookFlags (GDI.192)
1249 WORD WINAPI SetHookFlags16(HDC16 hDC, WORD flags)
1251 DC* dc = (DC*)GDI_GetObjPtr( hDC, DC_MAGIC );
1255 WORD wRet = dc->w.flags & DC_DIRTY;
1257 /* "Undocumented Windows" info is slightly confusing.
1260 TRACE("hDC %04x, flags %04x\n",hDC,flags);
1262 if( flags & DCHF_INVALIDATEVISRGN )
1263 dc->w.flags |= DC_DIRTY;
1264 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1265 dc->w.flags &= ~DC_DIRTY;
1266 GDI_HEAP_UNLOCK( hDC );
1272 /***********************************************************************
1273 * SetICMMode (GDI32.318)
1275 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1277 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1278 if (iEnableICM == ICM_OFF) return ICM_OFF;
1279 if (iEnableICM == ICM_ON) return 0;
1280 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1285 /***********************************************************************
1286 * GetColorSpace (GDI32.165)
1288 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1290 /*FIXME Need to to whatever GetColorSpace actually does */
1294 /***********************************************************************
1295 * CreateColorSpaceA (GDI32.???)
1297 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1303 /***********************************************************************
1304 * CreateColorSpaceW (GDI32.???)
1306 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1312 /***********************************************************************
1313 * DeleteColorSpace (GDI32.???)
1315 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1322 /***********************************************************************
1323 * SetColorSpace (GDI32.???)
1325 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1332 /***********************************************************************
1333 * GetBoundsRect16 (GDI.194)
1335 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1337 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1340 /***********************************************************************
1341 * GetBoundsRect32 (GDI32.147)
1343 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1345 FIXME("(): stub\n");
1346 return DCB_RESET; /* bounding rectangle always empty */
1349 /***********************************************************************
1350 * SetBoundsRect16 (GDI.193)
1352 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1354 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1355 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1357 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1360 /***********************************************************************
1361 * SetBoundsRect32 (GDI32.307)
1363 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1365 FIXME("(): stub\n");
1366 return DCB_DISABLE; /* bounding rectangle always empty */
1369 /***********************************************************************
1372 * Disables GDI, switches back to text mode.
1373 * We don't have to do anything here,
1374 * just let console support handle everything
1376 void WINAPI Death16(HDC16 hDC)
1378 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC);
1381 /***********************************************************************
1382 * Resurrection (GDI.122)
1384 * Restores GDI functionality
1386 void WINAPI Resurrection16(HDC16 hDC,
1387 WORD w1, WORD w2, WORD w3, WORD w4, WORD w5, WORD w6)
1389 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC, w1, w2, w3, w4, w5, w6);
1392 /***********************************************************************
1393 * GetLayout (GDI32.321)
1395 * Gets left->right or right->left text layout flags of a dc.
1396 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1399 DWORD WINAPI GetLayout(HDC hdc)
1401 FIXME("(%08x): stub\n", hdc);
1402 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1406 /***********************************************************************
1407 * SetLayout (GDI32.450)
1409 * Sets left->right or right->left text layout flags of a dc.
1410 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1413 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1415 FIXME("(%08x,%08lx): stub\n", hdc, layout);
1416 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);