2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/debug.h"
32 #include "wine/winuser16.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(dc);
36 /* ### start build ### */
37 extern WORD CALLBACK GDI_CallTo16_word_wwll(FARPROC16,WORD,WORD,LONG,LONG);
38 /* ### stop build ### */
40 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
42 static const struct gdi_obj_funcs dc_funcs =
44 NULL, /* pSelectObject */
45 NULL, /* pGetObject16 */
46 NULL, /* pGetObjectA */
47 NULL, /* pGetObjectW */
48 NULL, /* pUnrealizeObject */
49 DC_DeleteObject /* pDeleteObject */
52 /***********************************************************************
55 DC *DC_AllocDC( const DC_FUNCTIONS *funcs )
60 if (!(dc = GDI_AllocObject( sizeof(*dc), DC_MAGIC, &hdc, &dc_funcs ))) return NULL;
81 dc->hPen = GetStockObject( BLACK_PEN );
82 dc->hBrush = GetStockObject( WHITE_BRUSH );
83 dc->hFont = GetStockObject( SYSTEM_FONT );
86 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
88 dc->ROPmode = R2_COPYPEN;
89 dc->polyFillMode = ALTERNATE;
90 dc->stretchBltMode = BLACKONWHITE;
91 dc->relAbsMode = ABSOLUTE;
92 dc->backgroundMode = OPAQUE;
93 dc->backgroundColor = RGB( 255, 255, 255 );
94 dc->textColor = RGB( 0, 0, 0 );
97 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
99 dc->breakTotalExtra = 0;
103 dc->totalExtent.left = 0;
104 dc->totalExtent.top = 0;
105 dc->totalExtent.right = 0;
106 dc->totalExtent.bottom = 0;
107 dc->bitsPerPixel = 1;
108 dc->MapMode = MM_TEXT;
109 dc->GraphicsMode = GM_COMPATIBLE;
110 dc->pAbortProc = NULL;
113 dc->ArcDirection = AD_COUNTERCLOCKWISE;
114 dc->xformWorld2Wnd.eM11 = 1.0f;
115 dc->xformWorld2Wnd.eM12 = 0.0f;
116 dc->xformWorld2Wnd.eM21 = 0.0f;
117 dc->xformWorld2Wnd.eM22 = 1.0f;
118 dc->xformWorld2Wnd.eDx = 0.0f;
119 dc->xformWorld2Wnd.eDy = 0.0f;
120 dc->xformWorld2Vport = dc->xformWorld2Wnd;
121 dc->xformVport2World = dc->xformWorld2Wnd;
122 dc->vport2WorldValid = TRUE;
123 PATH_InitGdiPath(&dc->path);
129 /***********************************************************************
132 DC *DC_GetDCPtr( HDC hdc )
134 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
135 if (!ptr) return NULL;
136 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
137 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
138 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
140 GDI_ReleaseObj( hdc );
141 SetLastError( ERROR_INVALID_HANDLE );
145 /***********************************************************************
148 * Retrieve a DC ptr while making sure the visRgn is updated.
149 * This function may call up to USER so the GDI lock should _not_
150 * be held when calling it.
152 DC *DC_GetDCUpdate( HDC hdc )
154 DC *dc = DC_GetDCPtr( hdc );
155 if (!dc) return NULL;
156 while (dc->flags & DC_DIRTY)
158 dc->flags &= ~DC_DIRTY;
159 if (!(dc->flags & (DC_SAVED | DC_MEMORY)))
161 DCHOOKPROC proc = dc->hookThunk;
164 DWORD data = dc->dwHookData;
165 GDI_ReleaseObj( hdc );
166 proc( hdc, DCHC_INVALIDVISRGN, data, 0 );
167 if (!(dc = DC_GetDCPtr( hdc ))) break;
168 /* otherwise restart the loop in case it became dirty again in the meantime */
176 /***********************************************************************
179 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
181 GDI_ReleaseObj( handle );
182 return DeleteDC( handle );
186 /***********************************************************************
189 * Setup device-specific DC values for a newly created DC.
191 void DC_InitDC( DC* dc )
193 RealizeDefaultPalette16( dc->hSelf );
194 SetTextColor( dc->hSelf, dc->textColor );
195 SetBkColor( dc->hSelf, dc->backgroundColor );
196 SelectObject( dc->hSelf, dc->hPen );
197 SelectObject( dc->hSelf, dc->hBrush );
198 SelectObject( dc->hSelf, dc->hFont );
199 CLIPPING_UpdateGCRegion( dc );
203 /***********************************************************************
206 * Computes the inverse of the transformation xformSrc and stores it to
207 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
210 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
214 determinant = xformSrc->eM11*xformSrc->eM22 -
215 xformSrc->eM12*xformSrc->eM21;
216 if (determinant > -1e-12 && determinant < 1e-12)
219 xformDest->eM11 = xformSrc->eM22 / determinant;
220 xformDest->eM12 = -xformSrc->eM12 / determinant;
221 xformDest->eM21 = -xformSrc->eM21 / determinant;
222 xformDest->eM22 = xformSrc->eM11 / determinant;
223 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
224 xformSrc->eDy * xformDest->eM21;
225 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
226 xformSrc->eDy * xformDest->eM22;
232 /***********************************************************************
235 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
236 * fields of the specified DC by creating a transformation that
237 * represents the current mapping mode and combining it with the DC's
238 * world transform. This function should be called whenever the
239 * parameters associated with the mapping mode (window and viewport
240 * extents and origins) or the world transform change.
242 void DC_UpdateXforms( DC *dc )
244 XFORM xformWnd2Vport;
245 FLOAT scaleX, scaleY;
247 /* Construct a transformation to do the window-to-viewport conversion */
248 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
249 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
250 xformWnd2Vport.eM11 = scaleX;
251 xformWnd2Vport.eM12 = 0.0;
252 xformWnd2Vport.eM21 = 0.0;
253 xformWnd2Vport.eM22 = scaleY;
254 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
255 scaleX * (FLOAT)dc->wndOrgX;
256 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
257 scaleY * (FLOAT)dc->wndOrgY;
259 /* Combine with the world transformation */
260 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
263 /* Create inverse of world-to-viewport transformation */
264 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
265 &dc->xformVport2World );
269 /***********************************************************************
270 * GetDCState (GDI.179)
271 * GetDCState16 (GDI32.@)
273 HDC16 WINAPI GetDCState16( HDC16 hdc )
278 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
279 if (!(newdc = GDI_AllocObject( sizeof(DC), DC_MAGIC, &handle, &dc_funcs )))
281 GDI_ReleaseObj( hdc );
284 TRACE("(%04x): returning %04x\n", hdc, handle );
286 newdc->flags = dc->flags | DC_SAVED;
287 newdc->hPen = dc->hPen;
288 newdc->hBrush = dc->hBrush;
289 newdc->hFont = dc->hFont;
290 newdc->hBitmap = dc->hBitmap;
291 newdc->hDevice = dc->hDevice;
292 newdc->hPalette = dc->hPalette;
293 newdc->totalExtent = dc->totalExtent;
294 newdc->bitsPerPixel = dc->bitsPerPixel;
295 newdc->ROPmode = dc->ROPmode;
296 newdc->polyFillMode = dc->polyFillMode;
297 newdc->stretchBltMode = dc->stretchBltMode;
298 newdc->relAbsMode = dc->relAbsMode;
299 newdc->backgroundMode = dc->backgroundMode;
300 newdc->backgroundColor = dc->backgroundColor;
301 newdc->textColor = dc->textColor;
302 newdc->brushOrgX = dc->brushOrgX;
303 newdc->brushOrgY = dc->brushOrgY;
304 newdc->textAlign = dc->textAlign;
305 newdc->charExtra = dc->charExtra;
306 newdc->breakTotalExtra = dc->breakTotalExtra;
307 newdc->breakCount = dc->breakCount;
308 newdc->breakExtra = dc->breakExtra;
309 newdc->breakRem = dc->breakRem;
310 newdc->MapMode = dc->MapMode;
311 newdc->GraphicsMode = dc->GraphicsMode;
312 newdc->CursPosX = dc->CursPosX;
313 newdc->CursPosY = dc->CursPosY;
314 newdc->ArcDirection = dc->ArcDirection;
315 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
316 newdc->xformWorld2Vport = dc->xformWorld2Vport;
317 newdc->xformVport2World = dc->xformVport2World;
318 newdc->vport2WorldValid = dc->vport2WorldValid;
319 newdc->wndOrgX = dc->wndOrgX;
320 newdc->wndOrgY = dc->wndOrgY;
321 newdc->wndExtX = dc->wndExtX;
322 newdc->wndExtY = dc->wndExtY;
323 newdc->vportOrgX = dc->vportOrgX;
324 newdc->vportOrgY = dc->vportOrgY;
325 newdc->vportExtX = dc->vportExtX;
326 newdc->vportExtY = dc->vportExtY;
328 newdc->hSelf = (HDC)handle;
329 newdc->saveLevel = 0;
331 PATH_InitGdiPath( &newdc->path );
333 newdc->pAbortProc = NULL;
334 newdc->hookThunk = NULL;
337 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
339 newdc->hGCClipRgn = newdc->hVisRgn = 0;
342 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
343 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
349 newdc->gdiFont = dc->gdiFont;
353 GDI_ReleaseObj( handle );
354 GDI_ReleaseObj( hdc );
359 /***********************************************************************
360 * SetDCState (GDI.180)
361 * SetDCState16 (GDI32.@)
363 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
367 if (!(dc = DC_GetDCUpdate( hdc ))) return;
368 if (!(dcs = DC_GetDCPtr( hdcs )))
370 GDI_ReleaseObj( hdc );
373 if (!dcs->flags & DC_SAVED)
375 GDI_ReleaseObj( hdc );
376 GDI_ReleaseObj( hdcs );
379 TRACE("%04x %04x\n", hdc, hdcs );
381 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
382 dc->hDevice = dcs->hDevice;
383 dc->totalExtent = dcs->totalExtent;
384 dc->ROPmode = dcs->ROPmode;
385 dc->polyFillMode = dcs->polyFillMode;
386 dc->stretchBltMode = dcs->stretchBltMode;
387 dc->relAbsMode = dcs->relAbsMode;
388 dc->backgroundMode = dcs->backgroundMode;
389 dc->backgroundColor = dcs->backgroundColor;
390 dc->textColor = dcs->textColor;
391 dc->brushOrgX = dcs->brushOrgX;
392 dc->brushOrgY = dcs->brushOrgY;
393 dc->textAlign = dcs->textAlign;
394 dc->charExtra = dcs->charExtra;
395 dc->breakTotalExtra = dcs->breakTotalExtra;
396 dc->breakCount = dcs->breakCount;
397 dc->breakExtra = dcs->breakExtra;
398 dc->breakRem = dcs->breakRem;
399 dc->MapMode = dcs->MapMode;
400 dc->GraphicsMode = dcs->GraphicsMode;
401 dc->CursPosX = dcs->CursPosX;
402 dc->CursPosY = dcs->CursPosY;
403 dc->ArcDirection = dcs->ArcDirection;
404 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
405 dc->xformWorld2Vport = dcs->xformWorld2Vport;
406 dc->xformVport2World = dcs->xformVport2World;
407 dc->vport2WorldValid = dcs->vport2WorldValid;
409 dc->wndOrgX = dcs->wndOrgX;
410 dc->wndOrgY = dcs->wndOrgY;
411 dc->wndExtX = dcs->wndExtX;
412 dc->wndExtY = dcs->wndExtY;
413 dc->vportOrgX = dcs->vportOrgX;
414 dc->vportOrgY = dcs->vportOrgY;
415 dc->vportExtX = dcs->vportExtX;
416 dc->vportExtY = dcs->vportExtY;
418 if (!(dc->flags & DC_MEMORY)) dc->bitsPerPixel = dcs->bitsPerPixel;
422 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
423 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
427 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
430 CLIPPING_UpdateGCRegion( dc );
432 SelectObject( hdc, dcs->hBitmap );
433 SelectObject( hdc, dcs->hBrush );
434 SelectObject( hdc, dcs->hFont );
435 SelectObject( hdc, dcs->hPen );
436 SetBkColor( hdc, dcs->backgroundColor);
437 SetTextColor( hdc, dcs->textColor);
438 GDISelectPalette( hdc, dcs->hPalette, FALSE );
439 GDI_ReleaseObj( hdcs );
440 GDI_ReleaseObj( hdc );
444 /***********************************************************************
447 INT WINAPI SaveDC( HDC hdc )
453 dc = DC_GetDCPtr( hdc );
456 if(dc->funcs->pSaveDC)
458 ret = dc->funcs->pSaveDC( dc->physDev );
459 GDI_ReleaseObj( hdc );
463 if (!(hdcs = GetDCState16( hdc )))
465 GDI_ReleaseObj( hdc );
468 dcs = DC_GetDCPtr( hdcs );
470 /* Copy path. The reason why path saving / restoring is in SaveDC/
471 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
472 * functions are only in Win16 (which doesn't have paths) and that
473 * SetDCState doesn't allow us to signal an error (which can happen
474 * when copying paths).
476 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
478 GDI_ReleaseObj( hdc );
479 GDI_ReleaseObj( hdcs );
484 dcs->header.hNext = dc->header.hNext;
485 dc->header.hNext = hdcs;
486 TRACE("(%04x): returning %d\n", hdc, dc->saveLevel+1 );
487 ret = ++dc->saveLevel;
488 GDI_ReleaseObj( hdcs );
489 GDI_ReleaseObj( hdc );
494 /***********************************************************************
495 * RestoreDC (GDI32.@)
497 BOOL WINAPI RestoreDC( HDC hdc, INT level )
502 TRACE("%04x %d\n", hdc, level );
503 dc = DC_GetDCUpdate( hdc );
504 if(!dc) return FALSE;
505 if(dc->funcs->pRestoreDC)
507 success = dc->funcs->pRestoreDC( dc->physDev, level );
508 GDI_ReleaseObj( hdc );
512 if (level == -1) level = dc->saveLevel;
514 /* This pair of checks disagrees with MSDN "Platform SDK:
515 Windows GDI" July 2000 which says all negative values
516 for level will be interpreted as an instance relative
517 to the current state. Restricting it to just -1 does
519 || (level > dc->saveLevel))
521 GDI_ReleaseObj( hdc );
526 while (dc->saveLevel >= level)
528 HDC16 hdcs = dc->header.hNext;
529 if (!(dcs = DC_GetDCPtr( hdcs )))
531 GDI_ReleaseObj( hdc );
534 dc->header.hNext = dcs->header.hNext;
535 if (--dc->saveLevel < level)
537 SetDCState16( hdc, hdcs );
538 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
539 /* FIXME: This might not be quite right, since we're
540 * returning FALSE but still destroying the saved DC state */
543 GDI_ReleaseObj( hdcs );
544 GDI_ReleaseObj( hdc );
546 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
548 GDI_ReleaseObj( hdc );
553 /***********************************************************************
554 * CreateDCA (GDI32.@)
556 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
557 const DEVMODEA *initData )
561 const DC_FUNCTIONS *funcs;
564 if ((!driver) && (!device))
569 if (!device || !DRIVER_GetDriverName( device, buf, sizeof(buf) ))
572 if (!(funcs = DRIVER_load_driver( buf )))
574 ERR( "no driver found for %s\n", buf );
577 if (!(dc = DC_AllocDC( funcs )))
579 DRIVER_release_driver( funcs );
585 TRACE("(driver=%s, device=%s, output=%s): returning %04x\n",
586 debugstr_a(driver), debugstr_a(device), debugstr_a(output), dc->hSelf );
588 if (dc->funcs->pCreateDC &&
589 !dc->funcs->pCreateDC( dc, &dc->physDev, buf, device, output, initData ))
591 WARN("creation aborted by device\n" );
592 GDI_FreeObject( dc->hSelf, dc );
593 DRIVER_release_driver( funcs );
597 dc->totalExtent.left = 0;
598 dc->totalExtent.top = 0;
599 dc->totalExtent.right = GetDeviceCaps( dc->hSelf, HORZRES );
600 dc->totalExtent.bottom = GetDeviceCaps( dc->hSelf, VERTRES );
601 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
605 GDI_ReleaseObj( hdc );
610 /***********************************************************************
611 * CreateDCW (GDI32.@)
613 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
614 const DEVMODEW *initData )
616 LPSTR driverA = HEAP_strdupWtoA( GetProcessHeap(), 0, driver );
617 LPSTR deviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, device );
618 LPSTR outputA = HEAP_strdupWtoA( GetProcessHeap(), 0, output );
619 HDC res = CreateDCA( driverA, deviceA, outputA,
620 (const DEVMODEA *)initData /*FIXME*/ );
621 HeapFree( GetProcessHeap(), 0, driverA );
622 HeapFree( GetProcessHeap(), 0, deviceA );
623 HeapFree( GetProcessHeap(), 0, outputA );
628 /***********************************************************************
629 * CreateICA (GDI32.@)
631 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
632 const DEVMODEA* initData )
634 /* Nothing special yet for ICs */
635 return CreateDCA( driver, device, output, initData );
639 /***********************************************************************
640 * CreateICW (GDI32.@)
642 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
643 const DEVMODEW* initData )
645 /* Nothing special yet for ICs */
646 return CreateDCW( driver, device, output, initData );
650 /***********************************************************************
651 * CreateCompatibleDC (GDI32.@)
653 HDC WINAPI CreateCompatibleDC( HDC hdc )
656 const DC_FUNCTIONS *funcs;
660 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
662 funcs = origDC->funcs;
663 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
664 funcs = DRIVER_get_driver( funcs );
666 else funcs = DRIVER_load_driver( "DISPLAY" );
668 if (!funcs) return 0;
670 if (!(dc = DC_AllocDC( funcs )))
672 DRIVER_release_driver( funcs );
676 TRACE("(%04x): returning %04x\n",
679 dc->flags = DC_MEMORY;
680 dc->bitsPerPixel = 1;
681 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
683 /* Copy the driver-specific physical device info into
684 * the new DC. The driver may use this read-only info
685 * while creating the compatible DC below. */
686 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC ))) dc->physDev = origDC->physDev;
688 if (dc->funcs->pCreateDC &&
689 !dc->funcs->pCreateDC( dc, &dc->physDev, NULL, NULL, NULL, NULL ))
691 WARN("creation aborted by device\n");
692 GDI_FreeObject( dc->hSelf, dc );
693 if (origDC) GDI_ReleaseObj( hdc );
694 DRIVER_release_driver( funcs );
698 dc->totalExtent.left = 0;
699 dc->totalExtent.top = 0;
700 dc->totalExtent.right = 1; /* default bitmap is 1x1 */
701 dc->totalExtent.bottom = 1;
702 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
705 GDI_ReleaseObj( dc->hSelf );
706 if (origDC) GDI_ReleaseObj( hdc );
711 /***********************************************************************
714 BOOL WINAPI DeleteDC( HDC hdc )
716 const DC_FUNCTIONS *funcs = NULL;
719 TRACE("%04x\n", hdc );
723 if (!(dc = GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
725 /* Call hook procedure to check whether is it OK to delete this DC */
726 if (dc->hookThunk && !(dc->flags & (DC_SAVED | DC_MEMORY)))
728 DCHOOKPROC proc = dc->hookThunk;
731 DWORD data = dc->dwHookData;
732 GDI_ReleaseObj( hdc );
733 if (!proc( hdc, DCHC_DELETEDC, data, 0 )) return FALSE;
734 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
738 while (dc->saveLevel)
741 HDC16 hdcs = dc->header.hNext;
742 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
743 dc->header.hNext = dcs->header.hNext;
745 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
746 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
747 if (dcs->hGCClipRgn) DeleteObject( dcs->hGCClipRgn );
748 PATH_DestroyGdiPath(&dcs->path);
749 GDI_FreeObject( hdcs, dcs );
752 if (!(dc->flags & DC_SAVED))
754 SelectObject( hdc, GetStockObject(BLACK_PEN) );
755 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
756 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
757 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
759 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
763 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
764 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
765 if (dc->hGCClipRgn) DeleteObject( dc->hGCClipRgn );
766 PATH_DestroyGdiPath(&dc->path);
768 GDI_FreeObject( hdc, dc );
769 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
774 /***********************************************************************
777 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
782 if ((dc = DC_GetDCPtr( hdc )))
784 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
785 GDI_ReleaseObj( hdc );
791 /***********************************************************************
794 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
796 return ResetDCA(hdc, (const DEVMODEA*)devmode); /* FIXME */
800 /***********************************************************************
801 * GetDeviceCaps (GDI32.@)
803 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
808 if ((dc = DC_GetDCPtr( hdc )))
810 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
811 GDI_ReleaseObj( hdc );
817 /***********************************************************************
818 * SetBkColor (GDI32.@)
820 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
823 DC * dc = DC_GetDCPtr( hdc );
825 if (!dc) return CLR_INVALID;
826 oldColor = dc->backgroundColor;
827 if (dc->funcs->pSetBkColor)
829 color = dc->funcs->pSetBkColor(dc->physDev, color);
830 if (color == CLR_INVALID) /* don't change it */
833 oldColor = CLR_INVALID;
836 dc->backgroundColor = color;
837 GDI_ReleaseObj( hdc );
842 /***********************************************************************
843 * SetTextColor (GDI32.@)
845 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
848 DC * dc = DC_GetDCPtr( hdc );
850 if (!dc) return CLR_INVALID;
851 oldColor = dc->textColor;
852 if (dc->funcs->pSetTextColor)
854 color = dc->funcs->pSetTextColor(dc->physDev, color);
855 if (color == CLR_INVALID) /* don't change it */
858 oldColor = CLR_INVALID;
861 dc->textColor = color;
862 GDI_ReleaseObj( hdc );
867 /***********************************************************************
868 * SetTextAlign (GDI32.@)
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->physDev, align);
878 prevAlign = dc->textAlign;
879 dc->textAlign = align;
881 GDI_ReleaseObj( hdc );
885 /***********************************************************************
886 * GetDCOrgEx (GDI32.@)
888 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
892 if (!lpp) return FALSE;
893 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
896 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
897 GDI_ReleaseObj( hDC );
902 /***********************************************************************
904 * SetDCOrg16 (GDI32.@)
906 DWORD WINAPI SetDCOrg16( HDC16 hdc, INT16 x, INT16 y )
909 DC *dc = DC_GetDCPtr( hdc );
911 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
912 GDI_ReleaseObj( hdc );
917 /***********************************************************************
918 * SetGraphicsMode (GDI32.@)
920 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
923 DC *dc = DC_GetDCPtr( hdc );
925 /* One would think that setting the graphics mode to GM_COMPATIBLE
926 * would also reset the world transformation matrix to the unity
927 * matrix. However, in Windows, this is not the case. This doesn't
928 * make a lot of sense to me, but that's the way it is.
931 if ((mode > 0) || (mode <= GM_LAST))
933 ret = dc->GraphicsMode;
934 dc->GraphicsMode = mode;
936 GDI_ReleaseObj( hdc );
941 /***********************************************************************
942 * SetArcDirection (GDI32.@)
944 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
947 INT nOldDirection = 0;
949 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
951 SetLastError(ERROR_INVALID_PARAMETER);
955 if ((dc = DC_GetDCPtr( hdc )))
957 nOldDirection = dc->ArcDirection;
958 dc->ArcDirection = nDirection;
959 GDI_ReleaseObj( hdc );
961 return nOldDirection;
965 /***********************************************************************
966 * GetWorldTransform (GDI32.@)
968 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
971 if (!xform) return FALSE;
972 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
973 *xform = dc->xformWorld2Wnd;
974 GDI_ReleaseObj( hdc );
979 /***********************************************************************
980 * SetWorldTransform (GDI32.@)
982 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
985 DC *dc = DC_GetDCPtr( hdc );
987 if (!dc) return FALSE;
988 if (!xform) goto done;
990 /* Check that graphics mode is GM_ADVANCED */
991 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
993 dc->xformWorld2Wnd = *xform;
994 DC_UpdateXforms( dc );
997 GDI_ReleaseObj( hdc );
1002 /****************************************************************************
1003 * ModifyWorldTransform [GDI32.@]
1004 * Modifies the world transformation for a device context.
1007 * hdc [I] Handle to device context
1008 * xform [I] XFORM structure that will be used to modify the world
1010 * iMode [I] Specifies in what way to modify the world transformation
1013 * Resets the world transformation to the identity matrix.
1014 * The parameter xform is ignored.
1016 * Multiplies xform into the world transformation matrix from
1019 * Multiplies xform into the world transformation matrix from
1024 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1028 DC *dc = DC_GetDCPtr( hdc );
1030 /* Check for illegal parameters */
1031 if (!dc) return FALSE;
1032 if (!xform) goto done;
1034 /* Check that graphics mode is GM_ADVANCED */
1035 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1040 dc->xformWorld2Wnd.eM11 = 1.0f;
1041 dc->xformWorld2Wnd.eM12 = 0.0f;
1042 dc->xformWorld2Wnd.eM21 = 0.0f;
1043 dc->xformWorld2Wnd.eM22 = 1.0f;
1044 dc->xformWorld2Wnd.eDx = 0.0f;
1045 dc->xformWorld2Wnd.eDy = 0.0f;
1047 case MWT_LEFTMULTIPLY:
1048 CombineTransform( &dc->xformWorld2Wnd, xform,
1049 &dc->xformWorld2Wnd );
1051 case MWT_RIGHTMULTIPLY:
1052 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1059 DC_UpdateXforms( dc );
1062 GDI_ReleaseObj( hdc );
1067 /****************************************************************************
1068 * CombineTransform [GDI32.@]
1069 * Combines two transformation matrices.
1072 * xformResult [O] Stores the result of combining the two matrices
1073 * xform1 [I] Specifies the first matrix to apply
1074 * xform2 [I] Specifies the second matrix to apply
1077 * The same matrix can be passed in for more than one of the parameters.
1081 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1082 const XFORM *xform2 )
1086 /* Check for illegal parameters */
1087 if (!xformResult || !xform1 || !xform2)
1090 /* Create the result in a temporary XFORM, since xformResult may be
1091 * equal to xform1 or xform2 */
1092 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1093 xform1->eM12 * xform2->eM21;
1094 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1095 xform1->eM12 * xform2->eM22;
1096 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1097 xform1->eM22 * xform2->eM21;
1098 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1099 xform1->eM22 * xform2->eM22;
1100 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1101 xform1->eDy * xform2->eM21 +
1103 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1104 xform1->eDy * xform2->eM22 +
1107 /* Copy the result to xformResult */
1108 *xformResult = xformTemp;
1114 /***********************************************************************
1115 * SetDCHook (GDI32.@)
1117 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1119 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1121 DC *dc = DC_GetDCPtr( hdc );
1123 if (!dc) return FALSE;
1124 dc->dwHookData = dwHookData;
1125 dc->hookThunk = hookProc;
1126 GDI_ReleaseObj( hdc );
1131 /* relay function to call the 16-bit DC hook proc */
1132 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc, WORD code, DWORD data, LPARAM lParam )
1134 FARPROC16 proc = NULL;
1135 DC *dc = DC_GetDCPtr( hdc );
1136 if (!dc) return FALSE;
1137 proc = dc->hookProc;
1138 GDI_ReleaseObj( hdc );
1139 if (!proc) return FALSE;
1140 return GDI_CallTo16_word_wwll( proc, hdc, code, data, lParam );
1143 /***********************************************************************
1144 * SetDCHook (GDI.190)
1146 BOOL16 WINAPI SetDCHook16( HDC16 hdc, FARPROC16 hookProc, DWORD dwHookData )
1148 DC *dc = DC_GetDCPtr( hdc );
1149 if (!dc) return FALSE;
1151 dc->hookProc = hookProc;
1152 GDI_ReleaseObj( hdc );
1153 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1157 /***********************************************************************
1158 * GetDCHook (GDI.191)
1160 DWORD WINAPI GetDCHook16( HDC16 hdc, FARPROC16 *phookProc )
1162 DC *dc = DC_GetDCPtr( hdc );
1164 *phookProc = dc->hookProc;
1165 GDI_ReleaseObj( hdc );
1166 return dc->dwHookData;
1170 /***********************************************************************
1171 * SetHookFlags (GDI.192)
1172 * SetHookFlags16 (GDI32.@)
1174 WORD WINAPI SetHookFlags16(HDC16 hDC, WORD flags)
1176 DC *dc = DC_GetDCPtr( hDC );
1180 WORD wRet = dc->flags & DC_DIRTY;
1182 /* "Undocumented Windows" info is slightly confusing.
1185 TRACE("hDC %04x, flags %04x\n",hDC,flags);
1187 if( flags & DCHF_INVALIDATEVISRGN )
1188 dc->flags |= DC_DIRTY;
1189 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1190 dc->flags &= ~DC_DIRTY;
1191 GDI_ReleaseObj( hDC );
1197 /***********************************************************************
1198 * SetICMMode (GDI32.@)
1200 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1202 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1203 if (iEnableICM == ICM_OFF) return ICM_OFF;
1204 if (iEnableICM == ICM_ON) return 0;
1205 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1209 /***********************************************************************
1210 * GetDeviceGammaRamp (GDI32.@)
1212 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1215 DC *dc = DC_GetDCPtr( hDC );
1219 if (dc->funcs->pGetDeviceGammaRamp)
1220 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1221 GDI_ReleaseObj( hDC );
1226 /***********************************************************************
1227 * SetDeviceGammaRamp (GDI32.@)
1229 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1232 DC *dc = DC_GetDCPtr( hDC );
1236 if (dc->funcs->pSetDeviceGammaRamp)
1237 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1238 GDI_ReleaseObj( hDC );
1243 /***********************************************************************
1244 * GetColorSpace (GDI32.@)
1246 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1248 /*FIXME Need to to whatever GetColorSpace actually does */
1252 /***********************************************************************
1253 * CreateColorSpaceA (GDI32.@)
1255 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1261 /***********************************************************************
1262 * CreateColorSpaceW (GDI32.@)
1264 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1270 /***********************************************************************
1271 * DeleteColorSpace (GDI32.@)
1273 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1280 /***********************************************************************
1281 * SetColorSpace (GDI32.@)
1283 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1290 /***********************************************************************
1291 * GetBoundsRect (GDI.194)
1293 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1295 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1298 /***********************************************************************
1299 * GetBoundsRect (GDI32.@)
1301 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1303 FIXME("(): stub\n");
1304 return DCB_RESET; /* bounding rectangle always empty */
1307 /***********************************************************************
1308 * SetBoundsRect (GDI.193)
1310 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1312 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1313 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1315 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1318 /***********************************************************************
1319 * SetBoundsRect (GDI32.@)
1321 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1323 FIXME("(): stub\n");
1324 return DCB_DISABLE; /* bounding rectangle always empty */
1328 /***********************************************************************
1329 * GetRelAbs (GDI32.@)
1331 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1334 DC *dc = DC_GetDCPtr( hdc );
1335 if (dc) ret = dc->relAbsMode;
1336 GDI_ReleaseObj( hdc );
1340 /***********************************************************************
1341 * GetLayout (GDI32.@)
1343 * Gets left->right or right->left text layout flags of a dc.
1344 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1347 DWORD WINAPI GetLayout(HDC hdc)
1349 FIXME("(%08x): stub\n", hdc);
1350 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1354 /***********************************************************************
1355 * SetLayout (GDI32.@)
1357 * Sets left->right or right->left text layout flags of a dc.
1358 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1361 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1363 FIXME("(%08x,%08lx): stub\n", hdc, layout);
1364 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);