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"
23 #include "wine/winuser16.h"
25 DEFAULT_DEBUG_CHANNEL(dc)
27 /***********************************************************************
30 * Fill the WIN_DC_INFO structure.
32 static void DC_Init_DC_INFO( WIN_DC_INFO *win_dc_info )
34 win_dc_info->flags = 0;
35 win_dc_info->devCaps = NULL;
36 win_dc_info->hClipRgn = 0;
37 win_dc_info->hVisRgn = 0;
38 win_dc_info->hGCClipRgn = 0;
39 win_dc_info->hPen = STOCK_BLACK_PEN;
40 win_dc_info->hBrush = STOCK_WHITE_BRUSH;
41 win_dc_info->hFont = STOCK_SYSTEM_FONT;
42 win_dc_info->hBitmap = 0;
43 win_dc_info->hFirstBitmap = 0;
44 win_dc_info->hDevice = 0;
45 win_dc_info->hPalette = STOCK_DEFAULT_PALETTE;
46 win_dc_info->ROPmode = R2_COPYPEN;
47 win_dc_info->polyFillMode = ALTERNATE;
48 win_dc_info->stretchBltMode = BLACKONWHITE;
49 win_dc_info->relAbsMode = ABSOLUTE;
50 win_dc_info->backgroundMode = OPAQUE;
51 win_dc_info->backgroundColor = RGB( 255, 255, 255 );
52 win_dc_info->textColor = RGB( 0, 0, 0 );
53 win_dc_info->brushOrgX = 0;
54 win_dc_info->brushOrgY = 0;
55 win_dc_info->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
56 win_dc_info->charExtra = 0;
57 win_dc_info->breakTotalExtra = 0;
58 win_dc_info->breakCount = 0;
59 win_dc_info->breakExtra = 0;
60 win_dc_info->breakRem = 0;
61 win_dc_info->bitsPerPixel = 1;
62 win_dc_info->MapMode = MM_TEXT;
63 win_dc_info->GraphicsMode = GM_COMPATIBLE;
64 win_dc_info->DCOrgX = 0;
65 win_dc_info->DCOrgY = 0;
66 win_dc_info->lpfnPrint = NULL;
67 win_dc_info->CursPosX = 0;
68 win_dc_info->CursPosY = 0;
69 win_dc_info->ArcDirection = AD_COUNTERCLOCKWISE;
70 win_dc_info->xformWorld2Wnd.eM11 = 1.0f;
71 win_dc_info->xformWorld2Wnd.eM12 = 0.0f;
72 win_dc_info->xformWorld2Wnd.eM21 = 0.0f;
73 win_dc_info->xformWorld2Wnd.eM22 = 1.0f;
74 win_dc_info->xformWorld2Wnd.eDx = 0.0f;
75 win_dc_info->xformWorld2Wnd.eDy = 0.0f;
76 win_dc_info->xformWorld2Vport = win_dc_info->xformWorld2Wnd;
77 win_dc_info->xformVport2World = win_dc_info->xformWorld2Wnd;
78 win_dc_info->vport2WorldValid = TRUE;
80 PATH_InitGdiPath(&win_dc_info->path);
84 /***********************************************************************
87 DC *DC_AllocDC( const DC_FUNCTIONS *funcs )
92 if (!(hdc = GDI_AllocObject( sizeof(DC), DC_MAGIC ))) return NULL;
93 dc = (DC *) GDI_HEAP_LOCK( hdc );
110 DC_Init_DC_INFO( &dc->w );
117 /***********************************************************************
120 DC *DC_GetDCPtr( HDC hdc )
122 GDIOBJHDR *ptr = (GDIOBJHDR *)GDI_HEAP_LOCK( hdc );
123 if (!ptr) return NULL;
124 if ((ptr->wMagic == DC_MAGIC) || (ptr->wMagic == METAFILE_DC_MAGIC) ||
125 (ptr->wMagic == ENHMETAFILE_DC_MAGIC))
127 GDI_HEAP_UNLOCK( hdc );
132 /***********************************************************************
135 * Setup device-specific DC values for a newly created DC.
137 void DC_InitDC( DC* dc )
139 RealizeDefaultPalette16( dc->hSelf );
140 SetTextColor( dc->hSelf, dc->w.textColor );
141 SetBkColor( dc->hSelf, dc->w.backgroundColor );
142 SelectObject( dc->hSelf, dc->w.hPen );
143 SelectObject( dc->hSelf, dc->w.hBrush );
144 SelectObject( dc->hSelf, dc->w.hFont );
145 CLIPPING_UpdateGCRegion( dc );
149 /***********************************************************************
152 * Computes the inverse of the transformation xformSrc and stores it to
153 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
156 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
160 determinant = xformSrc->eM11*xformSrc->eM22 -
161 xformSrc->eM12*xformSrc->eM21;
162 if (determinant > -1e-12 && determinant < 1e-12)
165 xformDest->eM11 = xformSrc->eM22 / determinant;
166 xformDest->eM12 = -xformSrc->eM12 / determinant;
167 xformDest->eM21 = -xformSrc->eM21 / determinant;
168 xformDest->eM22 = xformSrc->eM11 / determinant;
169 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
170 xformSrc->eDy * xformDest->eM21;
171 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
172 xformSrc->eDy * xformDest->eM22;
178 /***********************************************************************
181 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
182 * fields of the specified DC by creating a transformation that
183 * represents the current mapping mode and combining it with the DC's
184 * world transform. This function should be called whenever the
185 * parameters associated with the mapping mode (window and viewport
186 * extents and origins) or the world transform change.
188 void DC_UpdateXforms( DC *dc )
190 XFORM xformWnd2Vport;
191 FLOAT scaleX, scaleY;
193 /* Construct a transformation to do the window-to-viewport conversion */
194 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
195 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
196 xformWnd2Vport.eM11 = scaleX;
197 xformWnd2Vport.eM12 = 0.0;
198 xformWnd2Vport.eM21 = 0.0;
199 xformWnd2Vport.eM22 = scaleY;
200 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
201 scaleX * (FLOAT)dc->wndOrgX;
202 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
203 scaleY * (FLOAT)dc->wndOrgY;
205 /* Combine with the world transformation */
206 CombineTransform( &dc->w.xformWorld2Vport, &dc->w.xformWorld2Wnd,
209 /* Create inverse of world-to-viewport transformation */
210 dc->w.vport2WorldValid = DC_InvertXform( &dc->w.xformWorld2Vport,
211 &dc->w.xformVport2World );
215 /***********************************************************************
216 * GetDCState (GDI.179)
218 HDC16 WINAPI GetDCState16( HDC16 hdc )
223 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
224 if (!(handle = GDI_AllocObject( sizeof(DC), DC_MAGIC )))
226 GDI_HEAP_UNLOCK( hdc );
229 newdc = (DC *) GDI_HEAP_LOCK( handle );
231 TRACE("(%04x): returning %04x\n", hdc, handle );
233 newdc->w.flags = dc->w.flags | DC_SAVED;
234 newdc->w.devCaps = dc->w.devCaps;
235 newdc->w.hPen = dc->w.hPen;
236 newdc->w.hBrush = dc->w.hBrush;
237 newdc->w.hFont = dc->w.hFont;
238 newdc->w.hBitmap = dc->w.hBitmap;
239 newdc->w.hFirstBitmap = dc->w.hFirstBitmap;
240 newdc->w.hDevice = dc->w.hDevice;
241 newdc->w.hPalette = dc->w.hPalette;
242 newdc->w.totalExtent = dc->w.totalExtent;
243 newdc->w.bitsPerPixel = dc->w.bitsPerPixel;
244 newdc->w.ROPmode = dc->w.ROPmode;
245 newdc->w.polyFillMode = dc->w.polyFillMode;
246 newdc->w.stretchBltMode = dc->w.stretchBltMode;
247 newdc->w.relAbsMode = dc->w.relAbsMode;
248 newdc->w.backgroundMode = dc->w.backgroundMode;
249 newdc->w.backgroundColor = dc->w.backgroundColor;
250 newdc->w.textColor = dc->w.textColor;
251 newdc->w.brushOrgX = dc->w.brushOrgX;
252 newdc->w.brushOrgY = dc->w.brushOrgY;
253 newdc->w.textAlign = dc->w.textAlign;
254 newdc->w.charExtra = dc->w.charExtra;
255 newdc->w.breakTotalExtra = dc->w.breakTotalExtra;
256 newdc->w.breakCount = dc->w.breakCount;
257 newdc->w.breakExtra = dc->w.breakExtra;
258 newdc->w.breakRem = dc->w.breakRem;
259 newdc->w.MapMode = dc->w.MapMode;
260 newdc->w.GraphicsMode = dc->w.GraphicsMode;
262 /* Apparently, the DC origin is not changed by [GS]etDCState */
263 newdc->w.DCOrgX = dc->w.DCOrgX;
264 newdc->w.DCOrgY = dc->w.DCOrgY;
266 newdc->w.CursPosX = dc->w.CursPosX;
267 newdc->w.CursPosY = dc->w.CursPosY;
268 newdc->w.ArcDirection = dc->w.ArcDirection;
269 newdc->w.xformWorld2Wnd = dc->w.xformWorld2Wnd;
270 newdc->w.xformWorld2Vport = dc->w.xformWorld2Vport;
271 newdc->w.xformVport2World = dc->w.xformVport2World;
272 newdc->w.vport2WorldValid = dc->w.vport2WorldValid;
273 newdc->wndOrgX = dc->wndOrgX;
274 newdc->wndOrgY = dc->wndOrgY;
275 newdc->wndExtX = dc->wndExtX;
276 newdc->wndExtY = dc->wndExtY;
277 newdc->vportOrgX = dc->vportOrgX;
278 newdc->vportOrgY = dc->vportOrgY;
279 newdc->vportExtX = dc->vportExtX;
280 newdc->vportExtY = dc->vportExtY;
282 newdc->hSelf = (HDC)handle;
283 newdc->saveLevel = 0;
285 PATH_InitGdiPath( &newdc->w.path );
287 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
289 newdc->w.hGCClipRgn = newdc->w.hVisRgn = 0;
292 newdc->w.hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
293 CombineRgn( newdc->w.hClipRgn, dc->w.hClipRgn, 0, RGN_COPY );
296 newdc->w.hClipRgn = 0;
297 GDI_HEAP_UNLOCK( handle );
298 GDI_HEAP_UNLOCK( hdc );
303 /***********************************************************************
304 * SetDCState (GDI.180)
306 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
310 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
311 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC )))
313 GDI_HEAP_UNLOCK( hdc );
316 if (!dcs->w.flags & DC_SAVED)
318 GDI_HEAP_UNLOCK( hdc );
319 GDI_HEAP_UNLOCK( hdcs );
322 TRACE("%04x %04x\n", hdc, hdcs );
324 dc->w.flags = dcs->w.flags & ~DC_SAVED;
325 dc->w.devCaps = dcs->w.devCaps;
326 dc->w.hFirstBitmap = dcs->w.hFirstBitmap;
327 dc->w.hDevice = dcs->w.hDevice;
328 dc->w.totalExtent = dcs->w.totalExtent;
329 dc->w.ROPmode = dcs->w.ROPmode;
330 dc->w.polyFillMode = dcs->w.polyFillMode;
331 dc->w.stretchBltMode = dcs->w.stretchBltMode;
332 dc->w.relAbsMode = dcs->w.relAbsMode;
333 dc->w.backgroundMode = dcs->w.backgroundMode;
334 dc->w.backgroundColor = dcs->w.backgroundColor;
335 dc->w.textColor = dcs->w.textColor;
336 dc->w.brushOrgX = dcs->w.brushOrgX;
337 dc->w.brushOrgY = dcs->w.brushOrgY;
338 dc->w.textAlign = dcs->w.textAlign;
339 dc->w.charExtra = dcs->w.charExtra;
340 dc->w.breakTotalExtra = dcs->w.breakTotalExtra;
341 dc->w.breakCount = dcs->w.breakCount;
342 dc->w.breakExtra = dcs->w.breakExtra;
343 dc->w.breakRem = dcs->w.breakRem;
344 dc->w.MapMode = dcs->w.MapMode;
345 dc->w.GraphicsMode = dcs->w.GraphicsMode;
347 /* Apparently, the DC origin is not changed by [GS]etDCState */
348 dc->w.DCOrgX = dcs->w.DCOrgX;
349 dc->w.DCOrgY = dcs->w.DCOrgY;
351 dc->w.CursPosX = dcs->w.CursPosX;
352 dc->w.CursPosY = dcs->w.CursPosY;
353 dc->w.ArcDirection = dcs->w.ArcDirection;
354 dc->w.xformWorld2Wnd = dcs->w.xformWorld2Wnd;
355 dc->w.xformWorld2Vport = dcs->w.xformWorld2Vport;
356 dc->w.xformVport2World = dcs->w.xformVport2World;
357 dc->w.vport2WorldValid = dcs->w.vport2WorldValid;
359 dc->wndOrgX = dcs->wndOrgX;
360 dc->wndOrgY = dcs->wndOrgY;
361 dc->wndExtX = dcs->wndExtX;
362 dc->wndExtY = dcs->wndExtY;
363 dc->vportOrgX = dcs->vportOrgX;
364 dc->vportOrgY = dcs->vportOrgY;
365 dc->vportExtX = dcs->vportExtX;
366 dc->vportExtY = dcs->vportExtY;
368 if (!(dc->w.flags & DC_MEMORY)) dc->w.bitsPerPixel = dcs->w.bitsPerPixel;
372 if (!dc->w.hClipRgn) dc->w.hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
373 CombineRgn( dc->w.hClipRgn, dcs->w.hClipRgn, 0, RGN_COPY );
377 if (dc->w.hClipRgn) DeleteObject16( dc->w.hClipRgn );
380 CLIPPING_UpdateGCRegion( dc );
382 SelectObject( hdc, dcs->w.hBitmap );
383 SelectObject( hdc, dcs->w.hBrush );
384 SelectObject( hdc, dcs->w.hFont );
385 SelectObject( hdc, dcs->w.hPen );
386 SetBkColor( hdc, dcs->w.backgroundColor);
387 SetTextColor( hdc, dcs->w.textColor);
388 GDISelectPalette16( hdc, dcs->w.hPalette, FALSE );
389 GDI_HEAP_UNLOCK( hdc );
390 GDI_HEAP_UNLOCK( hdcs );
394 /***********************************************************************
397 INT16 WINAPI SaveDC16( HDC16 hdc )
399 return (INT16)SaveDC( hdc );
403 /***********************************************************************
404 * SaveDC32 (GDI32.292)
406 INT WINAPI SaveDC( HDC hdc )
412 dc = DC_GetDCPtr( hdc );
415 if(dc->funcs->pSaveDC)
416 return dc->funcs->pSaveDC( dc );
418 if (!(hdcs = GetDCState16( hdc )))
420 GDI_HEAP_UNLOCK( hdc );
423 dcs = (DC *) GDI_HEAP_LOCK( hdcs );
425 /* Copy path. The reason why path saving / restoring is in SaveDC/
426 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
427 * functions are only in Win16 (which doesn't have paths) and that
428 * SetDCState doesn't allow us to signal an error (which can happen
429 * when copying paths).
431 if (!PATH_AssignGdiPath( &dcs->w.path, &dc->w.path ))
433 GDI_HEAP_UNLOCK( hdc );
434 GDI_HEAP_UNLOCK( hdcs );
439 dcs->header.hNext = dc->header.hNext;
440 dc->header.hNext = hdcs;
441 TRACE("(%04x): returning %d\n", hdc, dc->saveLevel+1 );
442 ret = ++dc->saveLevel;
443 GDI_HEAP_UNLOCK( hdcs );
444 GDI_HEAP_UNLOCK( hdc );
449 /***********************************************************************
450 * RestoreDC16 (GDI.39)
452 BOOL16 WINAPI RestoreDC16( HDC16 hdc, INT16 level )
454 return RestoreDC( hdc, level );
458 /***********************************************************************
459 * RestoreDC32 (GDI32.290)
461 BOOL WINAPI RestoreDC( HDC hdc, INT level )
466 TRACE("%04x %d\n", hdc, level );
467 dc = DC_GetDCPtr( hdc );
468 if(!dc) return FALSE;
469 if(dc->funcs->pRestoreDC)
470 return dc->funcs->pRestoreDC( dc, level );
472 if (level == -1) level = dc->saveLevel;
473 if ((level < 1) || (level > dc->saveLevel))
475 GDI_HEAP_UNLOCK( hdc );
480 while (dc->saveLevel >= level)
482 HDC16 hdcs = dc->header.hNext;
483 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC )))
485 GDI_HEAP_UNLOCK( hdc );
488 dc->header.hNext = dcs->header.hNext;
489 if (--dc->saveLevel < level)
491 SetDCState16( hdc, hdcs );
492 if (!PATH_AssignGdiPath( &dc->w.path, &dcs->w.path ))
493 /* FIXME: This might not be quite right, since we're
494 * returning FALSE but still destroying the saved DC state */
499 GDI_HEAP_UNLOCK( hdc );
504 /***********************************************************************
505 * CreateDC16 (GDI.53)
507 HDC16 WINAPI CreateDC16( LPCSTR driver, LPCSTR device, LPCSTR output,
508 const DEVMODEA *initData )
511 const DC_FUNCTIONS *funcs;
515 if(!DRIVER_GetDriverName( device, buf, sizeof(buf) )) return 0;
519 if (!(funcs = DRIVER_FindDriver( buf ))) return 0;
520 if (!(dc = DC_AllocDC( funcs ))) return 0;
523 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
524 debugstr_a(driver), debugstr_a(device), debugstr_a(output), dc->hSelf );
526 if (dc->funcs->pCreateDC &&
527 !dc->funcs->pCreateDC( dc, driver, device, output, initData ))
529 WARN("creation aborted by device\n" );
530 GDI_HEAP_FREE( dc->hSelf );
535 GDI_HEAP_UNLOCK( dc->hSelf );
540 /***********************************************************************
541 * CreateDC32A (GDI32.)
543 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
544 const DEVMODEA *initData )
546 return CreateDC16( driver, device, output, (const DEVMODEA *)initData );
550 /***********************************************************************
551 * CreateDC32W (GDI32.)
553 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
554 const DEVMODEW *initData )
556 LPSTR driverA = HEAP_strdupWtoA( GetProcessHeap(), 0, driver );
557 LPSTR deviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, device );
558 LPSTR outputA = HEAP_strdupWtoA( GetProcessHeap(), 0, output );
559 HDC res = CreateDC16( driverA, deviceA, outputA,
560 (const DEVMODEA *)initData /*FIXME*/ );
561 HeapFree( GetProcessHeap(), 0, driverA );
562 HeapFree( GetProcessHeap(), 0, deviceA );
563 HeapFree( GetProcessHeap(), 0, outputA );
568 /***********************************************************************
569 * CreateIC16 (GDI.153)
571 HDC16 WINAPI CreateIC16( LPCSTR driver, LPCSTR device, LPCSTR output,
572 const DEVMODEA* initData )
574 /* Nothing special yet for ICs */
575 return CreateDC16( driver, device, output, initData );
579 /***********************************************************************
580 * CreateIC32A (GDI32.49)
582 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
583 const DEVMODEA* initData )
585 /* Nothing special yet for ICs */
586 return CreateDCA( driver, device, output, initData );
590 /***********************************************************************
591 * CreateIC32W (GDI32.50)
593 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
594 const DEVMODEW* initData )
596 /* Nothing special yet for ICs */
597 return CreateDCW( driver, device, output, initData );
601 /***********************************************************************
602 * CreateCompatibleDC16 (GDI.52)
604 HDC16 WINAPI CreateCompatibleDC16( HDC16 hdc )
606 return (HDC16)CreateCompatibleDC( hdc );
610 /***********************************************************************
611 * CreateCompatibleDC32 (GDI32.31)
613 HDC WINAPI CreateCompatibleDC( HDC hdc )
617 const DC_FUNCTIONS *funcs;
619 if ((origDC = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC ))) funcs = origDC->funcs;
620 else funcs = DRIVER_FindDriver( "DISPLAY" );
621 if (!funcs) return 0;
623 if (!(dc = DC_AllocDC( funcs ))) return 0;
625 TRACE("(%04x): returning %04x\n",
628 /* Create default bitmap */
629 if (!(hbitmap = CreateBitmap( 1, 1, 1, 1, NULL )))
631 GDI_HEAP_FREE( dc->hSelf );
634 dc->w.flags = DC_MEMORY;
635 dc->w.bitsPerPixel = 1;
636 dc->w.hBitmap = hbitmap;
637 dc->w.hFirstBitmap = hbitmap;
639 /* Copy the driver-specific physical device info into
640 * the new DC. The driver may use this read-only info
641 * while creating the compatible DC below. */
643 dc->physDev = origDC->physDev;
645 if (dc->funcs->pCreateDC &&
646 !dc->funcs->pCreateDC( dc, NULL, NULL, NULL, NULL ))
648 WARN("creation aborted by device\n");
649 DeleteObject( hbitmap );
650 GDI_HEAP_FREE( dc->hSelf );
655 GDI_HEAP_UNLOCK( dc->hSelf );
660 /***********************************************************************
661 * DeleteDC16 (GDI.68)
663 BOOL16 WINAPI DeleteDC16( HDC16 hdc )
665 return DeleteDC( hdc );
669 /***********************************************************************
670 * DeleteDC32 (GDI32.67)
672 BOOL WINAPI DeleteDC( HDC hdc )
674 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
675 if (!dc) return FALSE;
677 TRACE("%04x\n", hdc );
679 /* Call hook procedure to check whether is it OK to delete this DC */
680 if ( dc->hookProc && !(dc->w.flags & (DC_SAVED | DC_MEMORY))
681 && dc->hookProc( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ) == FALSE )
683 GDI_HEAP_UNLOCK( hdc );
687 while (dc->saveLevel)
690 HDC16 hdcs = dc->header.hNext;
691 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) break;
692 dc->header.hNext = dcs->header.hNext;
697 if (!(dc->w.flags & DC_SAVED))
699 SelectObject( hdc, STOCK_BLACK_PEN );
700 SelectObject( hdc, STOCK_WHITE_BRUSH );
701 SelectObject( hdc, STOCK_SYSTEM_FONT );
702 if (dc->w.flags & DC_MEMORY) DeleteObject( dc->w.hFirstBitmap );
703 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc);
706 if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
707 if (dc->w.hVisRgn) DeleteObject( dc->w.hVisRgn );
708 if (dc->w.hGCClipRgn) DeleteObject( dc->w.hGCClipRgn );
710 PATH_DestroyGdiPath(&dc->w.path);
712 return GDI_FreeObject( hdc );
716 /***********************************************************************
717 * ResetDC16 (GDI.376)
719 HDC16 WINAPI ResetDC16( HDC16 hdc, const DEVMODEA *devmode )
726 /***********************************************************************
727 * ResetDC32A (GDI32.287)
729 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
736 /***********************************************************************
737 * ResetDC32W (GDI32.288)
739 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
746 /***********************************************************************
747 * GetDeviceCaps16 (GDI.80)
749 INT16 WINAPI GetDeviceCaps16( HDC16 hdc, INT16 cap )
751 return GetDeviceCaps( hdc, cap );
755 /***********************************************************************
756 * GetDeviceCaps32 (GDI32.171)
758 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
760 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
766 /* Device capabilities for the printer */
770 if(Escape(hdc, GETPHYSPAGESIZE, 0, NULL, (LPVOID)&pt) > 0)
773 if(Escape(hdc, GETPHYSPAGESIZE, 0, NULL, (LPVOID)&pt) > 0)
775 case PHYSICALOFFSETX:
776 if(Escape(hdc, GETPRINTINGOFFSET, 0, NULL, (LPVOID)&pt) > 0)
778 case PHYSICALOFFSETY:
779 if(Escape(hdc, GETPRINTINGOFFSET, 0, NULL, (LPVOID)&pt) > 0)
782 if(Escape(hdc, GETSCALINGFACTOR, 0, NULL, (LPVOID)&pt) > 0)
785 if(Escape(hdc, GETSCALINGFACTOR, 0, NULL, (LPVOID)&pt) > 0)
789 if ((cap < 0) || (cap > sizeof(DeviceCaps)-sizeof(WORD)))
791 GDI_HEAP_UNLOCK( hdc );
795 TRACE("(%04x,%d): returning %d\n",
796 hdc, cap, *(WORD *)(((char *)dc->w.devCaps) + cap) );
797 ret = *(WORD *)(((char *)dc->w.devCaps) + cap);
798 GDI_HEAP_UNLOCK( hdc );
803 /***********************************************************************
804 * SetBkColor16 (GDI.1)
806 COLORREF WINAPI SetBkColor16( HDC16 hdc, COLORREF color )
808 return SetBkColor( hdc, color );
812 /***********************************************************************
813 * SetBkColor32 (GDI32.305)
815 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
818 DC * dc = DC_GetDCPtr( hdc );
820 if (!dc) return 0x80000000;
821 if (dc->funcs->pSetBkColor)
822 oldColor = dc->funcs->pSetBkColor(dc, color);
824 oldColor = dc->w.backgroundColor;
825 dc->w.backgroundColor = color;
827 GDI_HEAP_UNLOCK( hdc );
832 /***********************************************************************
833 * SetTextColor16 (GDI.9)
835 COLORREF WINAPI SetTextColor16( HDC16 hdc, COLORREF color )
837 return SetTextColor( hdc, color );
841 /***********************************************************************
842 * SetTextColor32 (GDI32.338)
844 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
847 DC * dc = DC_GetDCPtr( hdc );
849 if (!dc) return 0x80000000;
850 if (dc->funcs->pSetTextColor)
851 oldColor = dc->funcs->pSetTextColor(dc, color);
853 oldColor = dc->w.textColor;
854 dc->w.textColor = color;
856 GDI_HEAP_UNLOCK( hdc );
860 /***********************************************************************
861 * SetTextAlign16 (GDI.346)
863 UINT16 WINAPI SetTextAlign16( HDC16 hdc, UINT16 align )
865 return SetTextAlign( hdc, align );
869 /***********************************************************************
870 * SetTextAlign (GDI32.336)
872 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
875 DC *dc = DC_GetDCPtr( hdc );
877 if (dc->funcs->pSetTextAlign)
878 prevAlign = dc->funcs->pSetTextAlign(dc, align);
880 prevAlign = dc->w.textAlign;
881 dc->w.textAlign = align;
883 GDI_HEAP_UNLOCK( hdc );
887 /***********************************************************************
888 * GetDCOrgEx (GDI32.168)
890 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
894 if (!lpp) return FALSE;
895 if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return FALSE;
897 #ifndef X_DISPLAY_MISSING
898 if (!(dc->w.flags & DC_MEMORY))
900 X11DRV_PDEVICE *physDev;
902 int w, h, border, depth;
904 physDev = (X11DRV_PDEVICE *) dc->physDev;
906 /* FIXME: this is not correct for managed windows */
907 TSXGetGeometry( display, physDev->drawable, &root,
908 (int*)&lpp->x, (int*)&lpp->y, &w, &h, &border, &depth );
911 #endif /* !defined(X_DISPLAY_MISSING) */
914 lpp->x += dc->w.DCOrgX; lpp->y += dc->w.DCOrgY;
915 GDI_HEAP_UNLOCK( hDC );
920 /***********************************************************************
923 DWORD WINAPI GetDCOrg16( HDC16 hdc )
926 if( GetDCOrgEx( hdc, &pt) )
927 return MAKELONG( (WORD)pt.x, (WORD)pt.y );
932 /***********************************************************************
935 DWORD WINAPI SetDCOrg16( HDC16 hdc, INT16 x, INT16 y )
938 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
940 prevOrg = dc->w.DCOrgX | (dc->w.DCOrgY << 16);
943 GDI_HEAP_UNLOCK( hdc );
948 /***********************************************************************
949 * GetGraphicsMode (GDI32.188)
951 INT WINAPI GetGraphicsMode( HDC hdc )
953 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
955 return dc->w.GraphicsMode;
959 /***********************************************************************
960 * SetGraphicsMode (GDI32.317)
962 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
965 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
967 /* One would think that setting the graphics mode to GM_COMPATIBLE
968 * would also reset the world transformation matrix to the unity
969 * matrix. However, in Windows, this is not the case. This doesn't
970 * make a lot of sense to me, but that's the way it is.
974 if ((mode <= 0) || (mode > GM_LAST)) return 0;
975 ret = dc->w.GraphicsMode;
976 dc->w.GraphicsMode = mode;
981 /***********************************************************************
982 * GetArcDirection16 (GDI.524)
984 INT16 WINAPI GetArcDirection16( HDC16 hdc )
986 return GetArcDirection( (HDC)hdc );
990 /***********************************************************************
991 * GetArcDirection32 (GDI32.141)
993 INT WINAPI GetArcDirection( HDC hdc )
995 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1000 return dc->w.ArcDirection;
1004 /***********************************************************************
1005 * SetArcDirection16 (GDI.525)
1007 INT16 WINAPI SetArcDirection16( HDC16 hdc, INT16 nDirection )
1009 return SetArcDirection( (HDC)hdc, (INT)nDirection );
1013 /***********************************************************************
1014 * SetArcDirection32 (GDI32.302)
1016 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1018 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1024 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1026 SetLastError(ERROR_INVALID_PARAMETER);
1030 nOldDirection = dc->w.ArcDirection;
1031 dc->w.ArcDirection = nDirection;
1033 return nOldDirection;
1037 /***********************************************************************
1038 * GetWorldTransform (GDI32.244)
1040 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1042 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1049 *xform = dc->w.xformWorld2Wnd;
1055 /***********************************************************************
1056 * SetWorldTransform (GDI32.346)
1058 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1060 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1064 SetLastError( ERROR_INVALID_HANDLE );
1071 /* Check that graphics mode is GM_ADVANCED */
1072 if (dc->w.GraphicsMode!=GM_ADVANCED)
1075 dc->w.xformWorld2Wnd = *xform;
1077 DC_UpdateXforms( dc );
1083 /****************************************************************************
1084 * ModifyWorldTransform [GDI32.253]
1085 * Modifies the world transformation for a device context.
1088 * hdc [I] Handle to device context
1089 * xform [I] XFORM structure that will be used to modify the world
1091 * iMode [I] Specifies in what way to modify the world transformation
1094 * Resets the world transformation to the identity matrix.
1095 * The parameter xform is ignored.
1097 * Multiplies xform into the world transformation matrix from
1100 * Multiplies xform into the world transformation matrix from
1105 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1108 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1110 /* Check for illegal parameters */
1113 SetLastError( ERROR_INVALID_HANDLE );
1119 /* Check that graphics mode is GM_ADVANCED */
1120 if (dc->w.GraphicsMode!=GM_ADVANCED)
1126 dc->w.xformWorld2Wnd.eM11 = 1.0f;
1127 dc->w.xformWorld2Wnd.eM12 = 0.0f;
1128 dc->w.xformWorld2Wnd.eM21 = 0.0f;
1129 dc->w.xformWorld2Wnd.eM22 = 1.0f;
1130 dc->w.xformWorld2Wnd.eDx = 0.0f;
1131 dc->w.xformWorld2Wnd.eDy = 0.0f;
1133 case MWT_LEFTMULTIPLY:
1134 CombineTransform( &dc->w.xformWorld2Wnd, xform,
1135 &dc->w.xformWorld2Wnd );
1137 case MWT_RIGHTMULTIPLY:
1138 CombineTransform( &dc->w.xformWorld2Wnd, &dc->w.xformWorld2Wnd,
1145 DC_UpdateXforms( dc );
1151 /****************************************************************************
1152 * CombineTransform [GDI32.20]
1153 * Combines two transformation matrices.
1156 * xformResult [O] Stores the result of combining the two matrices
1157 * xform1 [I] Specifies the first matrix to apply
1158 * xform2 [I] Specifies the second matrix to apply
1161 * The same matrix can be passed in for more than one of the parameters.
1165 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1166 const XFORM *xform2 )
1170 /* Check for illegal parameters */
1171 if (!xformResult || !xform1 || !xform2)
1174 /* Create the result in a temporary XFORM, since xformResult may be
1175 * equal to xform1 or xform2 */
1176 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1177 xform1->eM12 * xform2->eM21;
1178 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1179 xform1->eM12 * xform2->eM22;
1180 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1181 xform1->eM22 * xform2->eM21;
1182 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1183 xform1->eM22 * xform2->eM22;
1184 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1185 xform1->eDy * xform2->eM21 +
1187 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1188 xform1->eDy * xform2->eM22 +
1191 /* Copy the result to xformResult */
1192 *xformResult = xformTemp;
1198 /***********************************************************************
1199 * SetDCHook (GDI.190)
1201 BOOL16 WINAPI SetDCHook( HDC16 hdc, FARPROC16 hookProc, DWORD dwHookData )
1203 DC *dc = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC );
1205 TRACE("hookProc %08x, default is %08x\n",
1206 (UINT)hookProc, (UINT)DCHook16 );
1208 if (!dc) return FALSE;
1209 dc->hookProc = hookProc;
1210 dc->dwHookData = dwHookData;
1211 GDI_HEAP_UNLOCK( hdc );
1216 /***********************************************************************
1217 * GetDCHook (GDI.191)
1219 DWORD WINAPI GetDCHook( HDC16 hdc, FARPROC16 *phookProc )
1221 DC *dc = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC );
1223 *phookProc = dc->hookProc;
1224 GDI_HEAP_UNLOCK( hdc );
1225 return dc->dwHookData;
1229 /***********************************************************************
1230 * SetHookFlags (GDI.192)
1232 WORD WINAPI SetHookFlags16(HDC16 hDC, WORD flags)
1234 DC* dc = (DC*)GDI_GetObjPtr( hDC, DC_MAGIC );
1238 WORD wRet = dc->w.flags & DC_DIRTY;
1240 /* "Undocumented Windows" info is slightly confusing.
1243 TRACE("hDC %04x, flags %04x\n",hDC,flags);
1245 if( flags & DCHF_INVALIDATEVISRGN )
1246 dc->w.flags |= DC_DIRTY;
1247 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1248 dc->w.flags &= ~DC_DIRTY;
1249 GDI_HEAP_UNLOCK( hDC );
1255 /***********************************************************************
1256 * SetICMMode (GDI32.318)
1258 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1260 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1261 if (iEnableICM == ICM_OFF) return ICM_OFF;
1262 if (iEnableICM == ICM_ON) return 0;
1263 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1268 /***********************************************************************
1269 * GetColorSpace (GDI32.165)
1271 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1273 /*FIXME Need to to whatever GetColorSpace actually does */
1277 /***********************************************************************
1278 * GetBoundsRect16 (GDI.194)
1280 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1282 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1285 /***********************************************************************
1286 * GetBoundsRect32 (GDI32.147)
1288 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1290 FIXME("(): stub\n");
1291 return DCB_RESET; /* bounding rectangle always empty */
1294 /***********************************************************************
1295 * SetBoundsRect16 (GDI.193)
1297 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1299 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1300 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1302 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1305 /***********************************************************************
1306 * SetBoundsRect32 (GDI32.307)
1308 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1310 FIXME("(): stub\n");
1311 return DCB_DISABLE; /* bounding rectangle always empty */
1314 /***********************************************************************
1317 * Disables GDI, switches back to text mode.
1318 * We don't have to do anything here,
1319 * just let console support handle everything
1321 void WINAPI Death16(HDC16 hDC)
1323 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC);
1326 /***********************************************************************
1327 * Resurrection (GDI.122)
1329 * Restores GDI functionality
1331 void WINAPI Resurrection16(HDC16 hDC,
1332 WORD w1, WORD w2, WORD w3, WORD w4, WORD w5, WORD w6)
1334 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC, w1, w2, w3, w4, w5, w6);