2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
14 #include "debugtools.h"
20 #include "wine/winuser16.h"
22 DEFAULT_DEBUG_CHANNEL(dc);
25 /***********************************************************************
28 DC *DC_AllocDC( const DC_FUNCTIONS *funcs )
33 if (!(dc = GDI_AllocObject( sizeof(*dc), DC_MAGIC, &hdc ))) return NULL;
55 dc->hPen = GetStockObject( BLACK_PEN );
56 dc->hBrush = GetStockObject( WHITE_BRUSH );
57 dc->hFont = GetStockObject( SYSTEM_FONT );
60 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
61 dc->ROPmode = R2_COPYPEN;
62 dc->polyFillMode = ALTERNATE;
63 dc->stretchBltMode = BLACKONWHITE;
64 dc->relAbsMode = ABSOLUTE;
65 dc->backgroundMode = OPAQUE;
66 dc->backgroundColor = RGB( 255, 255, 255 );
67 dc->textColor = RGB( 0, 0, 0 );
70 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
72 dc->breakTotalExtra = 0;
76 dc->totalExtent.left = 0;
77 dc->totalExtent.top = 0;
78 dc->totalExtent.right = 0;
79 dc->totalExtent.bottom = 0;
81 dc->MapMode = MM_TEXT;
82 dc->GraphicsMode = GM_COMPATIBLE;
85 dc->pAbortProc = NULL;
88 dc->ArcDirection = AD_COUNTERCLOCKWISE;
89 dc->xformWorld2Wnd.eM11 = 1.0f;
90 dc->xformWorld2Wnd.eM12 = 0.0f;
91 dc->xformWorld2Wnd.eM21 = 0.0f;
92 dc->xformWorld2Wnd.eM22 = 1.0f;
93 dc->xformWorld2Wnd.eDx = 0.0f;
94 dc->xformWorld2Wnd.eDy = 0.0f;
95 dc->xformWorld2Vport = dc->xformWorld2Wnd;
96 dc->xformVport2World = dc->xformWorld2Wnd;
97 dc->vport2WorldValid = TRUE;
98 PATH_InitGdiPath(&dc->path);
104 /***********************************************************************
107 DC *DC_GetDCPtr( HDC hdc )
109 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
110 if (!ptr) return NULL;
111 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
112 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
113 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
115 GDI_ReleaseObj( hdc );
116 SetLastError( ERROR_INVALID_HANDLE );
120 /***********************************************************************
123 * Retrieve a DC ptr while making sure the visRgn is updated.
124 * This function may call up to USER so the GDI lock should _not_
125 * be held when calling it.
127 DC *DC_GetDCUpdate( HDC hdc )
129 DC *dc = DC_GetDCPtr( hdc );
130 if (!dc) return NULL;
131 while (dc->flags & DC_DIRTY)
133 dc->flags &= ~DC_DIRTY;
134 if (!(dc->flags & (DC_SAVED | DC_MEMORY)))
136 DCHOOKPROC proc = dc->hookThunk;
139 DWORD data = dc->dwHookData;
140 GDI_ReleaseObj( hdc );
141 proc( hdc, DCHC_INVALIDVISRGN, data, 0 );
142 if (!(dc = DC_GetDCPtr( hdc ))) break;
143 /* otherwise restart the loop in case it became dirty again in the meantime */
150 /***********************************************************************
153 * Setup device-specific DC values for a newly created DC.
155 void DC_InitDC( DC* dc )
157 RealizeDefaultPalette16( dc->hSelf );
158 SetTextColor( dc->hSelf, dc->textColor );
159 SetBkColor( dc->hSelf, dc->backgroundColor );
160 SelectObject( dc->hSelf, dc->hPen );
161 SelectObject( dc->hSelf, dc->hBrush );
162 SelectObject( dc->hSelf, dc->hFont );
163 CLIPPING_UpdateGCRegion( dc );
167 /***********************************************************************
170 * Computes the inverse of the transformation xformSrc and stores it to
171 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
174 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
178 determinant = xformSrc->eM11*xformSrc->eM22 -
179 xformSrc->eM12*xformSrc->eM21;
180 if (determinant > -1e-12 && determinant < 1e-12)
183 xformDest->eM11 = xformSrc->eM22 / determinant;
184 xformDest->eM12 = -xformSrc->eM12 / determinant;
185 xformDest->eM21 = -xformSrc->eM21 / determinant;
186 xformDest->eM22 = xformSrc->eM11 / determinant;
187 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
188 xformSrc->eDy * xformDest->eM21;
189 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
190 xformSrc->eDy * xformDest->eM22;
196 /***********************************************************************
199 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
200 * fields of the specified DC by creating a transformation that
201 * represents the current mapping mode and combining it with the DC's
202 * world transform. This function should be called whenever the
203 * parameters associated with the mapping mode (window and viewport
204 * extents and origins) or the world transform change.
206 void DC_UpdateXforms( DC *dc )
208 XFORM xformWnd2Vport;
209 FLOAT scaleX, scaleY;
211 /* Construct a transformation to do the window-to-viewport conversion */
212 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
213 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
214 xformWnd2Vport.eM11 = scaleX;
215 xformWnd2Vport.eM12 = 0.0;
216 xformWnd2Vport.eM21 = 0.0;
217 xformWnd2Vport.eM22 = scaleY;
218 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
219 scaleX * (FLOAT)dc->wndOrgX;
220 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
221 scaleY * (FLOAT)dc->wndOrgY;
223 /* Combine with the world transformation */
224 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
227 /* Create inverse of world-to-viewport transformation */
228 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
229 &dc->xformVport2World );
233 /***********************************************************************
234 * GetDCState (GDI.179)
236 HDC16 WINAPI GetDCState16( HDC16 hdc )
241 if (!(dc = DC_GetDCUpdate( hdc ))) return 0;
242 if (!(newdc = GDI_AllocObject( sizeof(DC), DC_MAGIC, &handle )))
244 GDI_ReleaseObj( hdc );
247 TRACE("(%04x): returning %04x\n", hdc, handle );
249 newdc->flags = dc->flags | DC_SAVED;
250 newdc->devCaps = dc->devCaps;
251 newdc->hPen = dc->hPen;
252 newdc->hBrush = dc->hBrush;
253 newdc->hFont = dc->hFont;
254 newdc->hBitmap = dc->hBitmap;
255 newdc->hDevice = dc->hDevice;
256 newdc->hPalette = dc->hPalette;
257 newdc->totalExtent = dc->totalExtent;
258 newdc->bitsPerPixel = dc->bitsPerPixel;
259 newdc->ROPmode = dc->ROPmode;
260 newdc->polyFillMode = dc->polyFillMode;
261 newdc->stretchBltMode = dc->stretchBltMode;
262 newdc->relAbsMode = dc->relAbsMode;
263 newdc->backgroundMode = dc->backgroundMode;
264 newdc->backgroundColor = dc->backgroundColor;
265 newdc->textColor = dc->textColor;
266 newdc->brushOrgX = dc->brushOrgX;
267 newdc->brushOrgY = dc->brushOrgY;
268 newdc->textAlign = dc->textAlign;
269 newdc->charExtra = dc->charExtra;
270 newdc->breakTotalExtra = dc->breakTotalExtra;
271 newdc->breakCount = dc->breakCount;
272 newdc->breakExtra = dc->breakExtra;
273 newdc->breakRem = dc->breakRem;
274 newdc->MapMode = dc->MapMode;
275 newdc->GraphicsMode = dc->GraphicsMode;
277 /* Apparently, the DC origin is not changed by [GS]etDCState */
278 newdc->DCOrgX = dc->DCOrgX;
279 newdc->DCOrgY = dc->DCOrgY;
281 newdc->CursPosX = dc->CursPosX;
282 newdc->CursPosY = dc->CursPosY;
283 newdc->ArcDirection = dc->ArcDirection;
284 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
285 newdc->xformWorld2Vport = dc->xformWorld2Vport;
286 newdc->xformVport2World = dc->xformVport2World;
287 newdc->vport2WorldValid = dc->vport2WorldValid;
288 newdc->wndOrgX = dc->wndOrgX;
289 newdc->wndOrgY = dc->wndOrgY;
290 newdc->wndExtX = dc->wndExtX;
291 newdc->wndExtY = dc->wndExtY;
292 newdc->vportOrgX = dc->vportOrgX;
293 newdc->vportOrgY = dc->vportOrgY;
294 newdc->vportExtX = dc->vportExtX;
295 newdc->vportExtY = dc->vportExtY;
297 newdc->hSelf = (HDC)handle;
298 newdc->saveLevel = 0;
300 PATH_InitGdiPath( &newdc->path );
302 newdc->pAbortProc = NULL;
303 newdc->hookThunk = NULL;
306 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
308 newdc->hGCClipRgn = newdc->hVisRgn = 0;
311 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
312 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
316 GDI_ReleaseObj( handle );
317 GDI_ReleaseObj( hdc );
322 /***********************************************************************
323 * SetDCState (GDI.180)
325 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
329 if (!(dc = GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
330 if (!(dcs = GDI_GetObjPtr( hdcs, DC_MAGIC )))
332 GDI_ReleaseObj( hdc );
335 if (!dcs->flags & DC_SAVED)
337 GDI_ReleaseObj( hdc );
338 GDI_ReleaseObj( hdcs );
341 TRACE("%04x %04x\n", hdc, hdcs );
343 dc->flags = dcs->flags & ~DC_SAVED;
344 dc->devCaps = dcs->devCaps;
345 dc->hDevice = dcs->hDevice;
346 dc->totalExtent = dcs->totalExtent;
347 dc->ROPmode = dcs->ROPmode;
348 dc->polyFillMode = dcs->polyFillMode;
349 dc->stretchBltMode = dcs->stretchBltMode;
350 dc->relAbsMode = dcs->relAbsMode;
351 dc->backgroundMode = dcs->backgroundMode;
352 dc->backgroundColor = dcs->backgroundColor;
353 dc->textColor = dcs->textColor;
354 dc->brushOrgX = dcs->brushOrgX;
355 dc->brushOrgY = dcs->brushOrgY;
356 dc->textAlign = dcs->textAlign;
357 dc->charExtra = dcs->charExtra;
358 dc->breakTotalExtra = dcs->breakTotalExtra;
359 dc->breakCount = dcs->breakCount;
360 dc->breakExtra = dcs->breakExtra;
361 dc->breakRem = dcs->breakRem;
362 dc->MapMode = dcs->MapMode;
363 dc->GraphicsMode = dcs->GraphicsMode;
365 /* Apparently, the DC origin is not changed by [GS]etDCState */
366 dc->DCOrgX = dcs->DCOrgX;
367 dc->DCOrgY = dcs->DCOrgY;
369 dc->CursPosX = dcs->CursPosX;
370 dc->CursPosY = dcs->CursPosY;
371 dc->ArcDirection = dcs->ArcDirection;
372 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
373 dc->xformWorld2Vport = dcs->xformWorld2Vport;
374 dc->xformVport2World = dcs->xformVport2World;
375 dc->vport2WorldValid = dcs->vport2WorldValid;
377 dc->wndOrgX = dcs->wndOrgX;
378 dc->wndOrgY = dcs->wndOrgY;
379 dc->wndExtX = dcs->wndExtX;
380 dc->wndExtY = dcs->wndExtY;
381 dc->vportOrgX = dcs->vportOrgX;
382 dc->vportOrgY = dcs->vportOrgY;
383 dc->vportExtX = dcs->vportExtX;
384 dc->vportExtY = dcs->vportExtY;
386 if (!(dc->flags & DC_MEMORY)) dc->bitsPerPixel = dcs->bitsPerPixel;
390 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
391 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
395 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
398 CLIPPING_UpdateGCRegion( dc );
400 SelectObject( hdc, dcs->hBitmap );
401 SelectObject( hdc, dcs->hBrush );
402 SelectObject( hdc, dcs->hFont );
403 SelectObject( hdc, dcs->hPen );
404 SetBkColor( hdc, dcs->backgroundColor);
405 SetTextColor( hdc, dcs->textColor);
406 GDISelectPalette16( hdc, dcs->hPalette, FALSE );
407 GDI_ReleaseObj( hdcs );
408 GDI_ReleaseObj( hdc );
412 /***********************************************************************
415 INT16 WINAPI SaveDC16( HDC16 hdc )
417 return (INT16)SaveDC( hdc );
421 /***********************************************************************
424 INT WINAPI SaveDC( HDC hdc )
430 dc = DC_GetDCUpdate( hdc );
433 if(dc->funcs->pSaveDC)
435 ret = dc->funcs->pSaveDC( dc );
436 GDI_ReleaseObj( hdc );
440 if (!(hdcs = GetDCState16( hdc )))
442 GDI_ReleaseObj( hdc );
445 dcs = GDI_GetObjPtr( hdcs, DC_MAGIC );
447 /* Copy path. The reason why path saving / restoring is in SaveDC/
448 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
449 * functions are only in Win16 (which doesn't have paths) and that
450 * SetDCState doesn't allow us to signal an error (which can happen
451 * when copying paths).
453 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
455 GDI_ReleaseObj( hdc );
456 GDI_ReleaseObj( hdcs );
461 dcs->header.hNext = dc->header.hNext;
462 dc->header.hNext = hdcs;
463 TRACE("(%04x): returning %d\n", hdc, dc->saveLevel+1 );
464 ret = ++dc->saveLevel;
465 GDI_ReleaseObj( hdcs );
466 GDI_ReleaseObj( hdc );
471 /***********************************************************************
474 BOOL16 WINAPI RestoreDC16( HDC16 hdc, INT16 level )
476 return RestoreDC( hdc, level );
480 /***********************************************************************
481 * RestoreDC (GDI32.@)
483 BOOL WINAPI RestoreDC( HDC hdc, INT level )
488 TRACE("%04x %d\n", hdc, level );
489 dc = DC_GetDCPtr( hdc );
490 if(!dc) return FALSE;
491 if(dc->funcs->pRestoreDC)
493 success = dc->funcs->pRestoreDC( dc, level );
494 GDI_ReleaseObj( hdc );
498 if (level == -1) level = dc->saveLevel;
500 /* This pair of checks disagrees with MSDN "Platform SDK:
501 Windows GDI" July 2000 which says all negative values
502 for level will be interpreted as an instance relative
503 to the current state. Restricting it to just -1 does
505 || (level > dc->saveLevel))
507 GDI_ReleaseObj( hdc );
512 while (dc->saveLevel >= level)
514 HDC16 hdcs = dc->header.hNext;
515 if (!(dcs = GDI_GetObjPtr( hdcs, DC_MAGIC )))
517 GDI_ReleaseObj( hdc );
520 dc->header.hNext = dcs->header.hNext;
521 if (--dc->saveLevel < level)
523 SetDCState16( hdc, hdcs );
524 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
525 /* FIXME: This might not be quite right, since we're
526 * returning FALSE but still destroying the saved DC state */
529 GDI_ReleaseObj( hdcs );
532 GDI_ReleaseObj( hdc );
537 /***********************************************************************
540 HDC16 WINAPI CreateDC16( LPCSTR driver, LPCSTR device, LPCSTR output,
541 const DEVMODEA *initData )
543 return CreateDCA( driver, device, output, initData );
546 /***********************************************************************
547 * CreateDCA (GDI32.@)
549 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
550 const DEVMODEA *initData )
554 const DC_FUNCTIONS *funcs;
557 if (!device || !DRIVER_GetDriverName( device, buf, sizeof(buf) ))
560 if (!(funcs = DRIVER_FindDriver( buf ))) return 0;
561 if (!(dc = DC_AllocDC( funcs ))) return 0;
564 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
565 debugstr_a(driver), debugstr_a(device), debugstr_a(output), dc->hSelf );
567 if (dc->funcs->pCreateDC &&
568 !dc->funcs->pCreateDC( dc, buf, device, output, initData ))
570 WARN("creation aborted by device\n" );
571 GDI_FreeObject( dc->hSelf, dc );
577 GDI_ReleaseObj( hdc );
582 /***********************************************************************
583 * CreateDCW (GDI32.@)
585 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
586 const DEVMODEW *initData )
588 LPSTR driverA = HEAP_strdupWtoA( GetProcessHeap(), 0, driver );
589 LPSTR deviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, device );
590 LPSTR outputA = HEAP_strdupWtoA( GetProcessHeap(), 0, output );
591 HDC res = CreateDCA( driverA, deviceA, outputA,
592 (const DEVMODEA *)initData /*FIXME*/ );
593 HeapFree( GetProcessHeap(), 0, driverA );
594 HeapFree( GetProcessHeap(), 0, deviceA );
595 HeapFree( GetProcessHeap(), 0, outputA );
600 /***********************************************************************
603 HDC16 WINAPI CreateIC16( LPCSTR driver, LPCSTR device, LPCSTR output,
604 const DEVMODEA* initData )
606 /* Nothing special yet for ICs */
607 return CreateDC16( driver, device, output, initData );
611 /***********************************************************************
612 * CreateICA (GDI32.@)
614 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
615 const DEVMODEA* initData )
617 /* Nothing special yet for ICs */
618 return CreateDCA( driver, device, output, initData );
622 /***********************************************************************
623 * CreateICW (GDI32.@)
625 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
626 const DEVMODEW* initData )
628 /* Nothing special yet for ICs */
629 return CreateDCW( driver, device, output, initData );
633 /***********************************************************************
634 * CreateCompatibleDC (GDI.52)
636 HDC16 WINAPI CreateCompatibleDC16( HDC16 hdc )
638 return (HDC16)CreateCompatibleDC( hdc );
642 /***********************************************************************
643 * CreateCompatibleDC (GDI32.@)
645 HDC WINAPI CreateCompatibleDC( HDC hdc )
648 const DC_FUNCTIONS *funcs;
650 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC ))) funcs = origDC->funcs;
651 else funcs = DRIVER_FindDriver( "DISPLAY" );
653 if (!funcs || !(dc = DC_AllocDC( funcs )))
655 if (origDC) GDI_ReleaseObj( hdc );
659 TRACE("(%04x): returning %04x\n",
662 dc->flags = DC_MEMORY;
663 dc->bitsPerPixel = 1;
664 dc->hBitmap = hPseudoStockBitmap;
666 /* Copy the driver-specific physical device info into
667 * the new DC. The driver may use this read-only info
668 * while creating the compatible DC below. */
670 dc->physDev = origDC->physDev;
672 if (dc->funcs->pCreateDC &&
673 !dc->funcs->pCreateDC( dc, NULL, NULL, NULL, NULL ))
675 WARN("creation aborted by device\n");
676 GDI_FreeObject( dc->hSelf, dc );
677 if (origDC) GDI_ReleaseObj( hdc );
682 GDI_ReleaseObj( dc->hSelf );
683 if (origDC) GDI_ReleaseObj( hdc );
688 /***********************************************************************
691 BOOL16 WINAPI DeleteDC16( HDC16 hdc )
693 return DeleteDC( hdc );
697 /***********************************************************************
700 BOOL WINAPI DeleteDC( HDC hdc )
702 DC * dc = GDI_GetObjPtr( hdc, DC_MAGIC );
703 if (!dc) return FALSE;
705 TRACE("%04x\n", hdc );
707 /* Call hook procedure to check whether is it OK to delete this DC */
708 if (dc->hookThunk && !(dc->flags & (DC_SAVED | DC_MEMORY)))
710 DCHOOKPROC proc = dc->hookThunk;
713 DWORD data = dc->dwHookData;
714 GDI_ReleaseObj( hdc );
715 if (!proc( hdc, DCHC_DELETEDC, data, 0 )) return FALSE;
716 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
720 while (dc->saveLevel)
723 HDC16 hdcs = dc->header.hNext;
724 if (!(dcs = GDI_GetObjPtr( hdcs, DC_MAGIC ))) break;
725 dc->header.hNext = dcs->header.hNext;
727 GDI_ReleaseObj( hdcs );
731 if (!(dc->flags & DC_SAVED))
733 SelectObject( hdc, GetStockObject(BLACK_PEN) );
734 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
735 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
736 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc);
739 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
740 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
741 if (dc->hGCClipRgn) DeleteObject( dc->hGCClipRgn );
742 if (dc->pAbortProc) THUNK_Free( (FARPROC)dc->pAbortProc );
743 if (dc->hookThunk) THUNK_Free( (FARPROC)dc->hookThunk );
744 PATH_DestroyGdiPath(&dc->path);
746 return GDI_FreeObject( hdc, dc );
750 /***********************************************************************
753 HDC16 WINAPI ResetDC16( HDC16 hdc, const DEVMODEA *devmode )
760 /***********************************************************************
763 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
770 /***********************************************************************
773 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
780 /***********************************************************************
781 * GetDeviceCaps (GDI.80)
783 INT16 WINAPI GetDeviceCaps16( HDC16 hdc, INT16 cap )
785 INT16 ret = GetDeviceCaps( hdc, cap );
786 /* some apps don't expect -1 and think it's a B&W screen */
787 if ((cap == NUMCOLORS) && (ret == -1)) ret = 2048;
792 /***********************************************************************
793 * GetDeviceCaps (GDI32.@)
795 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
801 /* Device capabilities for the printer */
805 if(Escape(hdc, GETPHYSPAGESIZE, 0, NULL, (LPVOID)&pt) > 0) ret = pt.x;
808 if(Escape(hdc, GETPHYSPAGESIZE, 0, NULL, (LPVOID)&pt) > 0) ret = pt.y;
810 case PHYSICALOFFSETX:
811 if(Escape(hdc, GETPRINTINGOFFSET, 0, NULL, (LPVOID)&pt) > 0) ret = pt.x;
813 case PHYSICALOFFSETY:
814 if(Escape(hdc, GETPRINTINGOFFSET, 0, NULL, (LPVOID)&pt) > 0) ret = pt.y;
817 if(Escape(hdc, GETSCALINGFACTOR, 0, NULL, (LPVOID)&pt) > 0) ret = pt.x;
820 if(Escape(hdc, GETSCALINGFACTOR, 0, NULL, (LPVOID)&pt) > 0) ret = pt.y;
823 FIXME("(%04x,%d): DeviceCaps param CAPS1 is UNIMPLEMENTED, will yield 0!\n",
826 /* please see wingdi.h for the possible bit-flag values that need
830 http://msdn.microsoft.com/library/ddkdoc/win95ddk/graphcnt_1m0p.htm
832 the fall-through to 'default' is on purpose */
836 if ((cap < 0) || (cap > sizeof(DeviceCaps)-sizeof(WORD))) break;
838 if (((cap>=46) && (cap<88)) || ((cap>=92) && (cap<104)))
839 FIXME("(%04x,%d): unsupported DeviceCaps capability, will yield 0!\n",
841 if ((dc = DC_GetDCPtr( hdc )))
845 ret = *(WORD *)(((char *)dc->devCaps) + cap);
846 if ((cap == NUMCOLORS) && (ret == 0xffff)) ret = -1;
848 GDI_ReleaseObj( hdc );
853 TRACE("(%04x,%d): returning %d\n", hdc, cap, ret );
858 /***********************************************************************
861 COLORREF WINAPI SetBkColor16( HDC16 hdc, COLORREF color )
863 return SetBkColor( hdc, color );
867 /***********************************************************************
868 * SetBkColor (GDI32.@)
870 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
873 DC * dc = DC_GetDCPtr( hdc );
875 if (!dc) return 0x80000000;
876 if (dc->funcs->pSetBkColor)
877 oldColor = dc->funcs->pSetBkColor(dc, color);
879 oldColor = dc->backgroundColor;
880 dc->backgroundColor = color;
882 GDI_ReleaseObj( hdc );
887 /***********************************************************************
888 * SetTextColor (GDI.9)
890 COLORREF WINAPI SetTextColor16( HDC16 hdc, COLORREF color )
892 return SetTextColor( hdc, color );
896 /***********************************************************************
897 * SetTextColor (GDI32.@)
899 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
902 DC * dc = DC_GetDCPtr( hdc );
904 if (!dc) return 0x80000000;
905 if (dc->funcs->pSetTextColor)
906 oldColor = dc->funcs->pSetTextColor(dc, color);
908 oldColor = dc->textColor;
909 dc->textColor = color;
911 GDI_ReleaseObj( hdc );
915 /***********************************************************************
916 * SetTextAlign (GDI.346)
918 UINT16 WINAPI SetTextAlign16( HDC16 hdc, UINT16 align )
920 return SetTextAlign( hdc, align );
924 /***********************************************************************
925 * SetTextAlign (GDI32.@)
927 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
930 DC *dc = DC_GetDCPtr( hdc );
932 if (dc->funcs->pSetTextAlign)
933 prevAlign = dc->funcs->pSetTextAlign(dc, align);
935 prevAlign = dc->textAlign;
936 dc->textAlign = align;
938 GDI_ReleaseObj( hdc );
942 /***********************************************************************
943 * GetDCOrgEx (GDI32.@)
945 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
949 if (!lpp) return FALSE;
950 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
953 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc, lpp );
954 lpp->x += dc->DCOrgX;
955 lpp->y += dc->DCOrgY;
956 GDI_ReleaseObj( hDC );
961 /***********************************************************************
964 DWORD WINAPI GetDCOrg16( HDC16 hdc )
967 if( GetDCOrgEx( hdc, &pt) )
968 return MAKELONG( (WORD)pt.x, (WORD)pt.y );
973 /***********************************************************************
976 DWORD WINAPI SetDCOrg16( HDC16 hdc, INT16 x, INT16 y )
979 DC *dc = DC_GetDCPtr( hdc );
981 prevOrg = dc->DCOrgX | (dc->DCOrgY << 16);
984 GDI_ReleaseObj( hdc );
989 /***********************************************************************
990 * SetGraphicsMode (GDI32.@)
992 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
995 DC *dc = DC_GetDCPtr( hdc );
997 /* One would think that setting the graphics mode to GM_COMPATIBLE
998 * would also reset the world transformation matrix to the unity
999 * matrix. However, in Windows, this is not the case. This doesn't
1000 * make a lot of sense to me, but that's the way it is.
1003 if ((mode > 0) || (mode <= GM_LAST))
1005 ret = dc->GraphicsMode;
1006 dc->GraphicsMode = mode;
1008 GDI_ReleaseObj( hdc );
1013 /***********************************************************************
1014 * SetArcDirection (GDI.525)
1016 INT16 WINAPI SetArcDirection16( HDC16 hdc, INT16 nDirection )
1018 return SetArcDirection( (HDC)hdc, (INT)nDirection );
1022 /***********************************************************************
1023 * SetArcDirection (GDI32.@)
1025 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1028 INT nOldDirection = 0;
1030 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1032 SetLastError(ERROR_INVALID_PARAMETER);
1036 if ((dc = DC_GetDCPtr( hdc )))
1038 nOldDirection = dc->ArcDirection;
1039 dc->ArcDirection = nDirection;
1040 GDI_ReleaseObj( hdc );
1042 return nOldDirection;
1046 /***********************************************************************
1047 * GetWorldTransform (GDI32.@)
1049 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1052 if (!xform) return FALSE;
1053 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
1054 *xform = dc->xformWorld2Wnd;
1055 GDI_ReleaseObj( hdc );
1060 /***********************************************************************
1061 * SetWorldTransform (GDI32.@)
1063 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1066 DC *dc = DC_GetDCPtr( hdc );
1068 if (!dc) return FALSE;
1069 if (!xform) goto done;
1071 /* Check that graphics mode is GM_ADVANCED */
1072 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1074 dc->xformWorld2Wnd = *xform;
1075 DC_UpdateXforms( dc );
1078 GDI_ReleaseObj( hdc );
1083 /****************************************************************************
1084 * ModifyWorldTransform [GDI32.@]
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,
1109 DC *dc = DC_GetDCPtr( hdc );
1111 /* Check for illegal parameters */
1112 if (!dc) return FALSE;
1113 if (!xform) goto done;
1115 /* Check that graphics mode is GM_ADVANCED */
1116 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1121 dc->xformWorld2Wnd.eM11 = 1.0f;
1122 dc->xformWorld2Wnd.eM12 = 0.0f;
1123 dc->xformWorld2Wnd.eM21 = 0.0f;
1124 dc->xformWorld2Wnd.eM22 = 1.0f;
1125 dc->xformWorld2Wnd.eDx = 0.0f;
1126 dc->xformWorld2Wnd.eDy = 0.0f;
1128 case MWT_LEFTMULTIPLY:
1129 CombineTransform( &dc->xformWorld2Wnd, xform,
1130 &dc->xformWorld2Wnd );
1132 case MWT_RIGHTMULTIPLY:
1133 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1140 DC_UpdateXforms( dc );
1143 GDI_ReleaseObj( hdc );
1148 /****************************************************************************
1149 * CombineTransform [GDI32.@]
1150 * Combines two transformation matrices.
1153 * xformResult [O] Stores the result of combining the two matrices
1154 * xform1 [I] Specifies the first matrix to apply
1155 * xform2 [I] Specifies the second matrix to apply
1158 * The same matrix can be passed in for more than one of the parameters.
1162 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1163 const XFORM *xform2 )
1167 /* Check for illegal parameters */
1168 if (!xformResult || !xform1 || !xform2)
1171 /* Create the result in a temporary XFORM, since xformResult may be
1172 * equal to xform1 or xform2 */
1173 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1174 xform1->eM12 * xform2->eM21;
1175 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1176 xform1->eM12 * xform2->eM22;
1177 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1178 xform1->eM22 * xform2->eM21;
1179 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1180 xform1->eM22 * xform2->eM22;
1181 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1182 xform1->eDy * xform2->eM21 +
1184 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1185 xform1->eDy * xform2->eM22 +
1188 /* Copy the result to xformResult */
1189 *xformResult = xformTemp;
1195 /***********************************************************************
1196 * SetDCHook (GDI.190)
1199 /* ### start build ### */
1200 extern WORD CALLBACK GDI_CallTo16_word_wwll(FARPROC16,WORD,WORD,LONG,LONG);
1201 /* ### stop build ### */
1203 /**********************************************************************/
1205 BOOL16 WINAPI SetDCHook( HDC16 hdc, FARPROC16 hookProc, DWORD dwHookData )
1207 DC *dc = DC_GetDCPtr( hdc );
1208 if (!dc) return FALSE;
1211 * Note: We store the original SEGPTR 'hookProc' as we need to be
1212 * able to return it verbatim in GetDCHook,
1214 * On the other hand, we still call THUNK_Alloc and store the
1215 * 32-bit thunk into another DC member, because THUNK_Alloc
1216 * recognizes the (typical) case that the 'hookProc' is indeed
1217 * the 16-bit API entry point of a built-in routine (e.g. DCHook16)
1219 * We could perform that test every time the hook is about to
1220 * be called (or else we could live with the 32->16->32 detour),
1221 * but this way is the most efficient ...
1224 dc->hookProc = hookProc;
1225 dc->dwHookData = dwHookData;
1227 THUNK_Free( (FARPROC)dc->hookThunk );
1228 dc->hookThunk = (DCHOOKPROC)
1229 THUNK_Alloc( hookProc, (RELAY)GDI_CallTo16_word_wwll );
1231 GDI_ReleaseObj( hdc );
1236 /***********************************************************************
1237 * GetDCHook (GDI.191)
1239 DWORD WINAPI GetDCHook( HDC16 hdc, FARPROC16 *phookProc )
1241 DC *dc = DC_GetDCPtr( hdc );
1243 *phookProc = dc->hookProc;
1244 GDI_ReleaseObj( hdc );
1245 return dc->dwHookData;
1249 /***********************************************************************
1250 * SetHookFlags (GDI.192)
1252 WORD WINAPI SetHookFlags16(HDC16 hDC, WORD flags)
1254 DC *dc = DC_GetDCPtr( hDC );
1258 WORD wRet = dc->flags & DC_DIRTY;
1260 /* "Undocumented Windows" info is slightly confusing.
1263 TRACE("hDC %04x, flags %04x\n",hDC,flags);
1265 if( flags & DCHF_INVALIDATEVISRGN )
1266 dc->flags |= DC_DIRTY;
1267 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1268 dc->flags &= ~DC_DIRTY;
1269 GDI_ReleaseObj( hDC );
1275 /***********************************************************************
1276 * SetICMMode (GDI32.@)
1278 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1280 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1281 if (iEnableICM == ICM_OFF) return ICM_OFF;
1282 if (iEnableICM == ICM_ON) return 0;
1283 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1287 /***********************************************************************
1288 * GetDeviceGammaRamp (GDI32.@)
1290 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1293 DC *dc = DC_GetDCPtr( hDC );
1297 if (dc->funcs->pGetDeviceGammaRamp)
1298 ret = dc->funcs->pGetDeviceGammaRamp(dc, ptr);
1299 GDI_ReleaseObj( hDC );
1304 /***********************************************************************
1305 * SetDeviceGammaRamp (GDI32.@)
1307 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1310 DC *dc = DC_GetDCPtr( hDC );
1314 if (dc->funcs->pSetDeviceGammaRamp)
1315 ret = dc->funcs->pSetDeviceGammaRamp(dc, ptr);
1316 GDI_ReleaseObj( hDC );
1321 /***********************************************************************
1322 * GetColorSpace (GDI32.@)
1324 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1326 /*FIXME Need to to whatever GetColorSpace actually does */
1330 /***********************************************************************
1331 * CreateColorSpaceA (GDI32.@)
1333 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1339 /***********************************************************************
1340 * CreateColorSpaceW (GDI32.@)
1342 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1348 /***********************************************************************
1349 * DeleteColorSpace (GDI32.@)
1351 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1358 /***********************************************************************
1359 * SetColorSpace (GDI32.@)
1361 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1368 /***********************************************************************
1369 * GetBoundsRect (GDI.194)
1371 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1373 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1376 /***********************************************************************
1377 * GetBoundsRect (GDI32.@)
1379 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1381 FIXME("(): stub\n");
1382 return DCB_RESET; /* bounding rectangle always empty */
1385 /***********************************************************************
1386 * SetBoundsRect (GDI.193)
1388 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1390 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1391 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1393 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1396 /***********************************************************************
1397 * SetBoundsRect (GDI32.@)
1399 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1401 FIXME("(): stub\n");
1402 return DCB_DISABLE; /* bounding rectangle always empty */
1406 /***********************************************************************
1407 * GetRelAbs (GDI32.@)
1409 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1412 DC *dc = DC_GetDCPtr( hdc );
1413 if (dc) ret = dc->relAbsMode;
1414 GDI_ReleaseObj( hdc );
1418 /***********************************************************************
1421 * Disables GDI, switches back to text mode.
1422 * We don't have to do anything here,
1423 * just let console support handle everything
1425 void WINAPI Death16(HDC16 hDC)
1427 MESSAGE("Death(%04x) called. Application enters text mode...\n", hDC);
1430 /***********************************************************************
1431 * Resurrection (GDI.122)
1433 * Restores GDI functionality
1435 void WINAPI Resurrection16(HDC16 hDC,
1436 WORD w1, WORD w2, WORD w3, WORD w4, WORD w5, WORD w6)
1438 MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n", hDC, w1, w2, w3, w4, w5, w6);
1441 /***********************************************************************
1442 * GetLayout (GDI32.@)
1444 * Gets left->right or right->left text layout flags of a dc.
1445 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1448 DWORD WINAPI GetLayout(HDC hdc)
1450 FIXME("(%08x): stub\n", hdc);
1451 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1455 /***********************************************************************
1456 * SetLayout (GDI32.@)
1458 * Sets left->right or right->left text layout flags of a dc.
1459 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1462 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1464 FIXME("(%08x,%08lx): stub\n", hdc, layout);
1465 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);