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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dc);
40 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
42 static BOOL DC_DeleteObject( HGDIOBJ handle );
44 static const struct gdi_obj_funcs dc_funcs =
46 NULL, /* pSelectObject */
47 NULL, /* pGetObjectA */
48 NULL, /* pGetObjectW */
49 NULL, /* pUnrealizeObject */
50 DC_DeleteObject /* pDeleteObject */
54 static inline DC *get_dc_obj( HDC hdc )
56 DC *dc = GDI_GetObjPtr( hdc, 0 );
59 if ((dc->header.type != OBJ_DC) &&
60 (dc->header.type != OBJ_MEMDC) &&
61 (dc->header.type != OBJ_METADC) &&
62 (dc->header.type != OBJ_ENHMETADC))
64 GDI_ReleaseObj( hdc );
65 SetLastError( ERROR_INVALID_HANDLE );
72 /***********************************************************************
75 DC *alloc_dc_ptr( const DC_FUNCTIONS *funcs, WORD magic )
79 if (!(dc = HeapAlloc( GetProcessHeap(), 0, sizeof(*dc) ))) return NULL;
83 dc->thread = GetCurrentThreadId();
99 dc->miterLimit = 10.0f; /* 10.0 is the default, from MSDN */
104 dc->hMetaClipRgn = 0;
106 dc->hPen = GDI_inc_ref_count( GetStockObject( BLACK_PEN ));
107 dc->hBrush = GDI_inc_ref_count( GetStockObject( WHITE_BRUSH ));
108 dc->hFont = GDI_inc_ref_count( GetStockObject( SYSTEM_FONT ));
111 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
113 dc->font_code_page = CP_ACP;
114 dc->ROPmode = R2_COPYPEN;
115 dc->polyFillMode = ALTERNATE;
116 dc->stretchBltMode = BLACKONWHITE;
117 dc->relAbsMode = ABSOLUTE;
118 dc->backgroundMode = OPAQUE;
119 dc->backgroundColor = RGB( 255, 255, 255 );
120 dc->dcBrushColor = RGB( 255, 255, 255 );
121 dc->dcPenColor = RGB( 0, 0, 0 );
122 dc->textColor = RGB( 0, 0, 0 );
125 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
129 dc->MapMode = MM_TEXT;
130 dc->GraphicsMode = GM_COMPATIBLE;
131 dc->pAbortProc = NULL;
134 dc->ArcDirection = AD_COUNTERCLOCKWISE;
135 dc->xformWorld2Wnd.eM11 = 1.0f;
136 dc->xformWorld2Wnd.eM12 = 0.0f;
137 dc->xformWorld2Wnd.eM21 = 0.0f;
138 dc->xformWorld2Wnd.eM22 = 1.0f;
139 dc->xformWorld2Wnd.eDx = 0.0f;
140 dc->xformWorld2Wnd.eDy = 0.0f;
141 dc->xformWorld2Vport = dc->xformWorld2Wnd;
142 dc->xformVport2World = dc->xformWorld2Wnd;
143 dc->vport2WorldValid = TRUE;
144 dc->BoundsRect.left = 0;
145 dc->BoundsRect.top = 0;
146 dc->BoundsRect.right = 0;
147 dc->BoundsRect.bottom = 0;
148 dc->saved_visrgn = NULL;
149 PATH_InitGdiPath(&dc->path);
151 if (!(dc->hSelf = alloc_gdi_handle( &dc->header, magic, &dc_funcs )))
153 HeapFree( GetProcessHeap(), 0, dc );
161 /***********************************************************************
164 BOOL free_dc_ptr( DC *dc )
166 assert( dc->refcount == 1 );
167 if (free_gdi_handle( dc->hSelf ) != dc) return FALSE; /* shouldn't happen */
168 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
169 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
170 if (dc->hMetaClipRgn) DeleteObject( dc->hMetaClipRgn );
171 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
172 PATH_DestroyGdiPath( &dc->path );
173 return HeapFree( GetProcessHeap(), 0, dc );
177 /***********************************************************************
180 * Retrieve a DC pointer but release the GDI lock.
182 DC *get_dc_ptr( HDC hdc )
184 DC *dc = get_dc_obj( hdc );
185 if (!dc) return NULL;
187 if (!InterlockedCompareExchange( &dc->refcount, 1, 0 ))
189 dc->thread = GetCurrentThreadId();
191 else if (dc->thread != GetCurrentThreadId())
193 WARN( "dc %p belongs to thread %04x\n", hdc, dc->thread );
194 GDI_ReleaseObj( hdc );
197 else InterlockedIncrement( &dc->refcount );
199 GDI_ReleaseObj( hdc );
204 /***********************************************************************
207 void release_dc_ptr( DC *dc )
212 ref = InterlockedDecrement( &dc->refcount );
214 if (ref) dc->thread = GetCurrentThreadId(); /* we still own it */
218 /***********************************************************************
221 * Make sure the DC vis region is up to date.
222 * This function may call up to USER so the GDI lock should _not_
223 * be held when calling it.
225 void update_dc( DC *dc )
227 if (InterlockedExchange( &dc->dirty, 0 ) && dc->hookThunk)
228 dc->hookThunk( dc->hSelf, DCHC_INVALIDVISRGN, dc->dwHookData, 0 );
232 /***********************************************************************
235 static BOOL DC_DeleteObject( HGDIOBJ handle )
237 return DeleteDC( handle );
241 /***********************************************************************
244 * Setup device-specific DC values for a newly created DC.
246 void DC_InitDC( DC* dc )
248 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
249 SetTextColor( dc->hSelf, dc->textColor );
250 SetBkColor( dc->hSelf, dc->backgroundColor );
251 SelectObject( dc->hSelf, dc->hPen );
252 SelectObject( dc->hSelf, dc->hBrush );
253 SelectObject( dc->hSelf, dc->hFont );
254 CLIPPING_UpdateGCRegion( dc );
255 SetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
259 /***********************************************************************
262 * Computes the inverse of the transformation xformSrc and stores it to
263 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
266 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
270 determinant = xformSrc->eM11*xformSrc->eM22 -
271 xformSrc->eM12*xformSrc->eM21;
272 if (determinant > -1e-12 && determinant < 1e-12)
275 xformDest->eM11 = xformSrc->eM22 / determinant;
276 xformDest->eM12 = -xformSrc->eM12 / determinant;
277 xformDest->eM21 = -xformSrc->eM21 / determinant;
278 xformDest->eM22 = xformSrc->eM11 / determinant;
279 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
280 xformSrc->eDy * xformDest->eM21;
281 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
282 xformSrc->eDy * xformDest->eM22;
287 /* Construct a transformation to do the window-to-viewport conversion */
288 static void construct_window_to_viewport(DC *dc, XFORM *xform)
290 double scaleX, scaleY;
291 scaleX = (double)dc->vportExtX / (double)dc->wndExtX;
292 scaleY = (double)dc->vportExtY / (double)dc->wndExtY;
294 xform->eM11 = scaleX;
297 xform->eM22 = scaleY;
298 xform->eDx = (double)dc->vportOrgX - scaleX * (double)dc->wndOrgX;
299 xform->eDy = (double)dc->vportOrgY - scaleY * (double)dc->wndOrgY;
302 /***********************************************************************
305 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
306 * fields of the specified DC by creating a transformation that
307 * represents the current mapping mode and combining it with the DC's
308 * world transform. This function should be called whenever the
309 * parameters associated with the mapping mode (window and viewport
310 * extents and origins) or the world transform change.
312 void DC_UpdateXforms( DC *dc )
314 XFORM xformWnd2Vport, oldworld2vport;
316 construct_window_to_viewport(dc, &xformWnd2Vport);
318 oldworld2vport = dc->xformWorld2Vport;
319 /* Combine with the world transformation */
320 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
323 /* Create inverse of world-to-viewport transformation */
324 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
325 &dc->xformVport2World );
327 /* Reselect the font and pen back into the dc so that the size
329 if (memcmp(&oldworld2vport, &dc->xformWorld2Vport, sizeof(oldworld2vport)) &&
330 !GdiIsMetaFileDC(dc->hSelf))
332 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_FONT));
333 SelectObject(dc->hSelf, GetCurrentObject(dc->hSelf, OBJ_PEN));
338 /***********************************************************************
341 INT save_dc_state( HDC hdc )
346 if (!(dc = get_dc_ptr( hdc ))) return 0;
347 if (!(newdc = HeapAlloc( GetProcessHeap(), 0, sizeof(*newdc ))))
349 release_dc_ptr( dc );
353 newdc->flags = dc->flags | DC_SAVED;
354 newdc->layout = dc->layout;
355 newdc->hPen = dc->hPen;
356 newdc->hBrush = dc->hBrush;
357 newdc->hFont = dc->hFont;
358 newdc->hBitmap = dc->hBitmap;
359 newdc->hDevice = dc->hDevice;
360 newdc->hPalette = dc->hPalette;
361 newdc->ROPmode = dc->ROPmode;
362 newdc->polyFillMode = dc->polyFillMode;
363 newdc->stretchBltMode = dc->stretchBltMode;
364 newdc->relAbsMode = dc->relAbsMode;
365 newdc->backgroundMode = dc->backgroundMode;
366 newdc->backgroundColor = dc->backgroundColor;
367 newdc->textColor = dc->textColor;
368 newdc->dcBrushColor = dc->dcBrushColor;
369 newdc->dcPenColor = dc->dcPenColor;
370 newdc->brushOrgX = dc->brushOrgX;
371 newdc->brushOrgY = dc->brushOrgY;
372 newdc->textAlign = dc->textAlign;
373 newdc->charExtra = dc->charExtra;
374 newdc->breakExtra = dc->breakExtra;
375 newdc->breakRem = dc->breakRem;
376 newdc->MapMode = dc->MapMode;
377 newdc->GraphicsMode = dc->GraphicsMode;
378 newdc->CursPosX = dc->CursPosX;
379 newdc->CursPosY = dc->CursPosY;
380 newdc->ArcDirection = dc->ArcDirection;
381 newdc->xformWorld2Wnd = dc->xformWorld2Wnd;
382 newdc->xformWorld2Vport = dc->xformWorld2Vport;
383 newdc->xformVport2World = dc->xformVport2World;
384 newdc->vport2WorldValid = dc->vport2WorldValid;
385 newdc->wndOrgX = dc->wndOrgX;
386 newdc->wndOrgY = dc->wndOrgY;
387 newdc->wndExtX = dc->wndExtX;
388 newdc->wndExtY = dc->wndExtY;
389 newdc->vportOrgX = dc->vportOrgX;
390 newdc->vportOrgY = dc->vportOrgY;
391 newdc->vportExtX = dc->vportExtX;
392 newdc->vportExtY = dc->vportExtY;
393 newdc->virtual_res = dc->virtual_res;
394 newdc->virtual_size = dc->virtual_size;
395 newdc->BoundsRect = dc->BoundsRect;
396 newdc->gdiFont = dc->gdiFont;
398 newdc->thread = GetCurrentThreadId();
400 newdc->saveLevel = 0;
403 PATH_InitGdiPath( &newdc->path );
405 newdc->pAbortProc = NULL;
406 newdc->hookThunk = NULL;
408 newdc->saved_visrgn = NULL;
410 if (!(newdc->hSelf = alloc_gdi_handle( &newdc->header, dc->header.type, &dc_funcs )))
412 HeapFree( GetProcessHeap(), 0, newdc );
413 release_dc_ptr( dc );
417 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
422 newdc->hMetaClipRgn = 0;
425 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
426 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
430 newdc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
431 CombineRgn( newdc->hMetaRgn, dc->hMetaRgn, 0, RGN_COPY );
433 /* don't bother recomputing hMetaClipRgn, we'll do that in SetDCState */
435 if (!PATH_AssignGdiPath( &newdc->path, &dc->path ))
437 release_dc_ptr( dc );
438 free_dc_ptr( newdc );
442 newdc->saved_dc = dc->saved_dc;
443 dc->saved_dc = newdc->hSelf;
444 ret = ++dc->saveLevel;
445 release_dc_ptr( newdc );
446 release_dc_ptr( dc );
451 /***********************************************************************
454 BOOL restore_dc_state( HDC hdc, INT level )
460 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
462 /* find the state level to restore */
464 if (abs(level) > dc->saveLevel || level == 0)
466 release_dc_ptr( dc );
469 if (level < 0) level = dc->saveLevel + level + 1;
470 first_dcs = dc->saved_dc;
471 for (hdcs = first_dcs, save_level = dc->saveLevel; save_level > level; save_level--)
473 if (!(dcs = get_dc_ptr( hdcs )))
475 release_dc_ptr( dc );
478 hdcs = dcs->saved_dc;
479 release_dc_ptr( dcs );
482 /* restore the state */
484 if (!(dcs = get_dc_ptr( hdcs )))
486 release_dc_ptr( dc );
489 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
491 release_dc_ptr( dcs );
492 release_dc_ptr( dc );
496 dc->flags = dcs->flags & ~DC_SAVED;
497 dc->layout = dcs->layout;
498 dc->hDevice = dcs->hDevice;
499 dc->ROPmode = dcs->ROPmode;
500 dc->polyFillMode = dcs->polyFillMode;
501 dc->stretchBltMode = dcs->stretchBltMode;
502 dc->relAbsMode = dcs->relAbsMode;
503 dc->backgroundMode = dcs->backgroundMode;
504 dc->backgroundColor = dcs->backgroundColor;
505 dc->textColor = dcs->textColor;
506 dc->dcBrushColor = dcs->dcBrushColor;
507 dc->dcPenColor = dcs->dcPenColor;
508 dc->brushOrgX = dcs->brushOrgX;
509 dc->brushOrgY = dcs->brushOrgY;
510 dc->textAlign = dcs->textAlign;
511 dc->charExtra = dcs->charExtra;
512 dc->breakExtra = dcs->breakExtra;
513 dc->breakRem = dcs->breakRem;
514 dc->MapMode = dcs->MapMode;
515 dc->GraphicsMode = dcs->GraphicsMode;
516 dc->CursPosX = dcs->CursPosX;
517 dc->CursPosY = dcs->CursPosY;
518 dc->ArcDirection = dcs->ArcDirection;
519 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
520 dc->xformWorld2Vport = dcs->xformWorld2Vport;
521 dc->xformVport2World = dcs->xformVport2World;
522 dc->vport2WorldValid = dcs->vport2WorldValid;
523 dc->BoundsRect = dcs->BoundsRect;
525 dc->wndOrgX = dcs->wndOrgX;
526 dc->wndOrgY = dcs->wndOrgY;
527 dc->wndExtX = dcs->wndExtX;
528 dc->wndExtY = dcs->wndExtY;
529 dc->vportOrgX = dcs->vportOrgX;
530 dc->vportOrgY = dcs->vportOrgY;
531 dc->vportExtX = dcs->vportExtX;
532 dc->vportExtY = dcs->vportExtY;
533 dc->virtual_res = dcs->virtual_res;
534 dc->virtual_size = dcs->virtual_size;
538 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
539 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
543 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
548 if (!dc->hMetaRgn) dc->hMetaRgn = CreateRectRgn( 0, 0, 0, 0 );
549 CombineRgn( dc->hMetaRgn, dcs->hMetaRgn, 0, RGN_COPY );
553 if (dc->hMetaRgn) DeleteObject( dc->hMetaRgn );
556 CLIPPING_UpdateGCRegion( dc );
558 SelectObject( hdc, dcs->hBitmap );
559 SelectObject( hdc, dcs->hBrush );
560 SelectObject( hdc, dcs->hFont );
561 SelectObject( hdc, dcs->hPen );
562 SetBkColor( hdc, dcs->backgroundColor);
563 SetTextColor( hdc, dcs->textColor);
564 GDISelectPalette( hdc, dcs->hPalette, FALSE );
566 dc->saved_dc = dcs->saved_dc;
568 dc->saveLevel = save_level - 1;
570 release_dc_ptr( dcs );
572 /* now destroy all the saved DCs */
576 if (!(dcs = get_dc_ptr( first_dcs ))) break;
577 hdcs = dcs->saved_dc;
581 release_dc_ptr( dc );
586 /***********************************************************************
589 INT WINAPI SaveDC( HDC hdc )
594 if (!(dc = get_dc_ptr( hdc ))) return 0;
596 if(dc->funcs->pSaveDC)
597 ret = dc->funcs->pSaveDC( dc->physDev );
599 ret = save_dc_state( hdc );
601 release_dc_ptr( dc );
606 /***********************************************************************
607 * RestoreDC (GDI32.@)
609 BOOL WINAPI RestoreDC( HDC hdc, INT level )
614 TRACE("%p %d\n", hdc, level );
615 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
618 if(dc->funcs->pRestoreDC)
619 success = dc->funcs->pRestoreDC( dc->physDev, level );
621 success = restore_dc_state( hdc, level );
623 release_dc_ptr( dc );
628 /***********************************************************************
629 * CreateDCW (GDI32.@)
631 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
632 const DEVMODEW *initData )
636 const DC_FUNCTIONS *funcs;
641 if (!device || !DRIVER_GetDriverName( device, buf, 300 ))
645 ERR( "no device found for %s\n", debugstr_w(device) );
648 strcpyW(buf, driver);
651 if (!(funcs = DRIVER_load_driver( buf )))
653 ERR( "no driver found for %s\n", debugstr_w(buf) );
656 if (!(dc = alloc_dc_ptr( funcs, OBJ_DC ))) goto error;
659 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
660 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error;
662 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
663 debugstr_w(driver), debugstr_w(device), debugstr_w(output), dc->hSelf );
665 if (dc->funcs->pCreateDC &&
666 !dc->funcs->pCreateDC( hdc, &dc->physDev, buf, device, output, initData ))
668 WARN("creation aborted by device\n" );
672 SetRectRgn( dc->hVisRgn, 0, 0,
673 GetDeviceCaps( hdc, DESKTOPHORZRES ), GetDeviceCaps( hdc, DESKTOPVERTRES ) );
676 release_dc_ptr( dc );
680 if (dc) free_dc_ptr( dc );
681 DRIVER_release_driver( funcs );
686 /***********************************************************************
687 * CreateDCA (GDI32.@)
689 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
690 const DEVMODEA *initData )
692 UNICODE_STRING driverW, deviceW, outputW;
696 if (driver) RtlCreateUnicodeStringFromAsciiz(&driverW, driver);
697 else driverW.Buffer = NULL;
699 if (device) RtlCreateUnicodeStringFromAsciiz(&deviceW, device);
700 else deviceW.Buffer = NULL;
702 if (output) RtlCreateUnicodeStringFromAsciiz(&outputW, output);
703 else outputW.Buffer = NULL;
708 /* don't convert initData for DISPLAY driver, it's not used */
709 if (!driverW.Buffer || strcmpiW( driverW.Buffer, displayW ))
710 initDataW = GdiConvertToDevmodeW(initData);
713 ret = CreateDCW( driverW.Buffer, deviceW.Buffer, outputW.Buffer, initDataW );
715 RtlFreeUnicodeString(&driverW);
716 RtlFreeUnicodeString(&deviceW);
717 RtlFreeUnicodeString(&outputW);
718 HeapFree(GetProcessHeap(), 0, initDataW);
723 /***********************************************************************
724 * CreateICA (GDI32.@)
726 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
727 const DEVMODEA* initData )
729 /* Nothing special yet for ICs */
730 return CreateDCA( driver, device, output, initData );
734 /***********************************************************************
735 * CreateICW (GDI32.@)
737 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
738 const DEVMODEW* initData )
740 /* Nothing special yet for ICs */
741 return CreateDCW( driver, device, output, initData );
745 /***********************************************************************
746 * CreateCompatibleDC (GDI32.@)
748 HDC WINAPI CreateCompatibleDC( HDC hdc )
752 const DC_FUNCTIONS *funcs = NULL;
753 PHYSDEV physDev = NULL;
757 if ((origDC = get_dc_ptr( hdc )))
759 if (GetObjectType( hdc ) == OBJ_DC)
761 funcs = origDC->funcs;
762 physDev = origDC->physDev;
764 release_dc_ptr( origDC );
765 if (funcs) funcs = DRIVER_get_driver( funcs );
767 else if (hdc) return 0;
769 if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0;
771 if (!(dc = alloc_dc_ptr( funcs, OBJ_MEMDC ))) goto error;
773 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
775 dc->hBitmap = GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP ));
776 if (!(dc->hVisRgn = CreateRectRgn( 0, 0, 1, 1 ))) goto error; /* default bitmap is 1x1 */
778 /* Copy the driver-specific physical device info into
779 * the new DC. The driver may use this read-only info
780 * while creating the compatible DC below. */
781 dc->physDev = physDev;
784 if (dc->funcs->pCreateDC &&
785 !dc->funcs->pCreateDC( dc->hSelf, &dc->physDev, NULL, NULL, NULL, NULL ))
787 WARN("creation aborted by device\n");
792 release_dc_ptr( dc );
796 if (dc) free_dc_ptr( dc );
797 DRIVER_release_driver( funcs );
802 /***********************************************************************
805 BOOL WINAPI DeleteDC( HDC hdc )
807 const DC_FUNCTIONS *funcs = NULL;
814 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
815 if (dc->refcount != 1)
817 FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
818 release_dc_ptr( dc );
822 /* Call hook procedure to check whether is it OK to delete this DC */
823 if (dc->hookThunk && !dc->hookThunk( hdc, DCHC_DELETEDC, dc->dwHookData, 0 ))
825 release_dc_ptr( dc );
829 while (dc->saveLevel)
832 HDC hdcs = dc->saved_dc;
833 if (!(dcs = get_dc_ptr( hdcs ))) break;
834 dc->saved_dc = dcs->saved_dc;
839 if (!(dc->flags & DC_SAVED))
841 SelectObject( hdc, GetStockObject(BLACK_PEN) );
842 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
843 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
844 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
846 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
850 while (dc->saved_visrgn)
852 struct saved_visrgn *next = dc->saved_visrgn->next;
853 DeleteObject( dc->saved_visrgn->hrgn );
854 HeapFree( GetProcessHeap(), 0, dc->saved_visrgn );
855 dc->saved_visrgn = next;
859 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
864 /***********************************************************************
867 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
872 if ((dc = get_dc_ptr( hdc )))
874 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
875 release_dc_ptr( dc );
881 /***********************************************************************
884 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
889 if (devmode) devmodeW = GdiConvertToDevmodeW(devmode);
890 else devmodeW = NULL;
892 ret = ResetDCW(hdc, devmodeW);
894 HeapFree(GetProcessHeap(), 0, devmodeW);
899 /***********************************************************************
900 * GetDeviceCaps (GDI32.@)
902 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
907 if ((dc = get_dc_ptr( hdc )))
909 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
910 else switch(cap) /* return meaningful values for some entries */
912 case HORZRES: ret = 640; break;
913 case VERTRES: ret = 480; break;
914 case BITSPIXEL: ret = 1; break;
915 case PLANES: ret = 1; break;
916 case NUMCOLORS: ret = 2; break;
917 case ASPECTX: ret = 36; break;
918 case ASPECTY: ret = 36; break;
919 case ASPECTXY: ret = 51; break;
920 case LOGPIXELSX: ret = 72; break;
921 case LOGPIXELSY: ret = 72; break;
922 case SIZEPALETTE: ret = 2; break;
924 release_dc_ptr( dc );
930 /***********************************************************************
931 * GetBkColor (GDI32.@)
933 COLORREF WINAPI GetBkColor( HDC hdc )
936 DC * dc = get_dc_ptr( hdc );
939 ret = dc->backgroundColor;
940 release_dc_ptr( dc );
946 /***********************************************************************
947 * SetBkColor (GDI32.@)
949 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
952 DC * dc = get_dc_ptr( hdc );
954 TRACE("hdc=%p color=0x%08x\n", hdc, color);
956 if (!dc) return CLR_INVALID;
957 oldColor = dc->backgroundColor;
958 if (dc->funcs->pSetBkColor)
960 color = dc->funcs->pSetBkColor(dc->physDev, color);
961 if (color == CLR_INVALID) /* don't change it */
964 oldColor = CLR_INVALID;
967 dc->backgroundColor = color;
968 release_dc_ptr( dc );
973 /***********************************************************************
974 * GetTextColor (GDI32.@)
976 COLORREF WINAPI GetTextColor( HDC hdc )
979 DC * dc = get_dc_ptr( hdc );
983 release_dc_ptr( dc );
989 /***********************************************************************
990 * SetTextColor (GDI32.@)
992 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
995 DC * dc = get_dc_ptr( hdc );
997 TRACE(" hdc=%p color=0x%08x\n", hdc, color);
999 if (!dc) return CLR_INVALID;
1000 oldColor = dc->textColor;
1001 if (dc->funcs->pSetTextColor)
1003 color = dc->funcs->pSetTextColor(dc->physDev, color);
1004 if (color == CLR_INVALID) /* don't change it */
1007 oldColor = CLR_INVALID;
1010 dc->textColor = color;
1011 release_dc_ptr( dc );
1016 /***********************************************************************
1017 * GetTextAlign (GDI32.@)
1019 UINT WINAPI GetTextAlign( HDC hdc )
1022 DC * dc = get_dc_ptr( hdc );
1025 ret = dc->textAlign;
1026 release_dc_ptr( dc );
1032 /***********************************************************************
1033 * SetTextAlign (GDI32.@)
1035 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
1038 DC *dc = get_dc_ptr( hdc );
1040 TRACE("hdc=%p align=%d\n", hdc, align);
1042 if (!dc) return 0x0;
1043 ret = dc->textAlign;
1044 if (dc->funcs->pSetTextAlign)
1045 if (!dc->funcs->pSetTextAlign(dc->physDev, align))
1047 if (ret != GDI_ERROR)
1048 dc->textAlign = align;
1049 release_dc_ptr( dc );
1053 /***********************************************************************
1054 * GetDCOrgEx (GDI32.@)
1056 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
1060 if (!lpp) return FALSE;
1061 if (!(dc = get_dc_ptr( hDC ))) return FALSE;
1063 lpp->x = lpp->y = 0;
1064 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
1065 release_dc_ptr( dc );
1070 /***********************************************************************
1071 * GetGraphicsMode (GDI32.@)
1073 INT WINAPI GetGraphicsMode( HDC hdc )
1076 DC * dc = get_dc_ptr( hdc );
1079 ret = dc->GraphicsMode;
1080 release_dc_ptr( dc );
1086 /***********************************************************************
1087 * SetGraphicsMode (GDI32.@)
1089 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
1092 DC *dc = get_dc_ptr( hdc );
1094 /* One would think that setting the graphics mode to GM_COMPATIBLE
1095 * would also reset the world transformation matrix to the unity
1096 * matrix. However, in Windows, this is not the case. This doesn't
1097 * make a lot of sense to me, but that's the way it is.
1100 if ((mode > 0) && (mode <= GM_LAST))
1102 ret = dc->GraphicsMode;
1103 dc->GraphicsMode = mode;
1105 release_dc_ptr( dc );
1110 /***********************************************************************
1111 * GetArcDirection (GDI32.@)
1113 INT WINAPI GetArcDirection( HDC hdc )
1116 DC * dc = get_dc_ptr( hdc );
1119 ret = dc->ArcDirection;
1120 release_dc_ptr( dc );
1126 /***********************************************************************
1127 * SetArcDirection (GDI32.@)
1129 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
1132 INT nOldDirection = 0;
1134 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
1136 SetLastError(ERROR_INVALID_PARAMETER);
1140 if ((dc = get_dc_ptr( hdc )))
1142 if (dc->funcs->pSetArcDirection)
1144 dc->funcs->pSetArcDirection(dc->physDev, nDirection);
1146 nOldDirection = dc->ArcDirection;
1147 dc->ArcDirection = nDirection;
1148 release_dc_ptr( dc );
1150 return nOldDirection;
1154 /***********************************************************************
1155 * GetWorldTransform (GDI32.@)
1157 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
1160 if (!xform) return FALSE;
1161 if (!(dc = get_dc_ptr( hdc ))) return FALSE;
1162 *xform = dc->xformWorld2Wnd;
1163 release_dc_ptr( dc );
1168 /***********************************************************************
1169 * GetTransform (GDI32.@)
1173 * Returns one of the co-ordinate space transforms
1176 * hdc [I] Device context.
1177 * which [I] Which xform to return:
1178 * 0x203 World -> Page transform (that set by SetWorldTransform).
1179 * 0x304 Page -> Device transform (the mapping mode transform).
1180 * 0x204 World -> Device transform (the combination of the above two).
1181 * 0x402 Device -> World transform (the inversion of the above).
1182 * xform [O] The xform.
1185 BOOL WINAPI GetTransform( HDC hdc, DWORD which, XFORM *xform )
1188 DC *dc = get_dc_ptr( hdc );
1189 if (!dc) return FALSE;
1194 *xform = dc->xformWorld2Wnd;
1198 construct_window_to_viewport(dc, xform);
1202 *xform = dc->xformWorld2Vport;
1206 *xform = dc->xformVport2World;
1210 FIXME("Unknown code %x\n", which);
1214 release_dc_ptr( dc );
1219 /***********************************************************************
1220 * SetWorldTransform (GDI32.@)
1222 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1227 if (!xform) return FALSE;
1229 dc = get_dc_ptr( hdc );
1230 if (!dc) return FALSE;
1232 /* Check that graphics mode is GM_ADVANCED */
1233 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1235 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
1236 xform->eM11, xform->eM12, xform->eM21, xform->eM22, xform->eDx, xform->eDy);
1238 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
1239 if (xform->eM11 * xform->eM22 == xform->eM12 * xform->eM21) goto done;
1241 if (dc->funcs->pSetWorldTransform)
1243 ret = dc->funcs->pSetWorldTransform(dc->physDev, xform);
1244 if (!ret) goto done;
1247 dc->xformWorld2Wnd = *xform;
1248 DC_UpdateXforms( dc );
1251 release_dc_ptr( dc );
1256 /****************************************************************************
1257 * ModifyWorldTransform [GDI32.@]
1258 * Modifies the world transformation for a device context.
1261 * hdc [I] Handle to device context
1262 * xform [I] XFORM structure that will be used to modify the world
1264 * iMode [I] Specifies in what way to modify the world transformation
1267 * Resets the world transformation to the identity matrix.
1268 * The parameter xform is ignored.
1270 * Multiplies xform into the world transformation matrix from
1273 * Multiplies xform into the world transformation matrix from
1278 * Failure: FALSE. Use GetLastError() to determine the cause.
1280 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1284 DC *dc = get_dc_ptr( hdc );
1286 /* Check for illegal parameters */
1287 if (!dc) return FALSE;
1288 if (!xform && iMode != MWT_IDENTITY) goto done;
1290 /* Check that graphics mode is GM_ADVANCED */
1291 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1293 if (dc->funcs->pModifyWorldTransform)
1295 ret = dc->funcs->pModifyWorldTransform(dc->physDev, xform, iMode);
1296 if (!ret) goto done;
1302 dc->xformWorld2Wnd.eM11 = 1.0f;
1303 dc->xformWorld2Wnd.eM12 = 0.0f;
1304 dc->xformWorld2Wnd.eM21 = 0.0f;
1305 dc->xformWorld2Wnd.eM22 = 1.0f;
1306 dc->xformWorld2Wnd.eDx = 0.0f;
1307 dc->xformWorld2Wnd.eDy = 0.0f;
1309 case MWT_LEFTMULTIPLY:
1310 CombineTransform( &dc->xformWorld2Wnd, xform,
1311 &dc->xformWorld2Wnd );
1313 case MWT_RIGHTMULTIPLY:
1314 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1321 DC_UpdateXforms( dc );
1324 release_dc_ptr( dc );
1329 /****************************************************************************
1330 * CombineTransform [GDI32.@]
1331 * Combines two transformation matrices.
1334 * xformResult [O] Stores the result of combining the two matrices
1335 * xform1 [I] Specifies the first matrix to apply
1336 * xform2 [I] Specifies the second matrix to apply
1339 * The same matrix can be passed in for more than one of the parameters.
1343 * Failure: FALSE. Use GetLastError() to determine the cause.
1345 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1346 const XFORM *xform2 )
1350 /* Check for illegal parameters */
1351 if (!xformResult || !xform1 || !xform2)
1354 /* Create the result in a temporary XFORM, since xformResult may be
1355 * equal to xform1 or xform2 */
1356 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1357 xform1->eM12 * xform2->eM21;
1358 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1359 xform1->eM12 * xform2->eM22;
1360 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1361 xform1->eM22 * xform2->eM21;
1362 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1363 xform1->eM22 * xform2->eM22;
1364 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1365 xform1->eDy * xform2->eM21 +
1367 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1368 xform1->eDy * xform2->eM22 +
1371 /* Copy the result to xformResult */
1372 *xformResult = xformTemp;
1378 /***********************************************************************
1379 * SetDCHook (GDI32.@)
1381 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1383 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD_PTR dwHookData )
1385 DC *dc = get_dc_ptr( hdc );
1387 if (!dc) return FALSE;
1389 if (!(dc->flags & DC_SAVED))
1391 dc->dwHookData = dwHookData;
1392 dc->hookThunk = hookProc;
1394 release_dc_ptr( dc );
1399 /***********************************************************************
1400 * GetDCHook (GDI32.@)
1402 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1404 DWORD_PTR WINAPI GetDCHook( HDC hdc, DCHOOKPROC *proc )
1406 DC *dc = get_dc_ptr( hdc );
1410 if (proc) *proc = dc->hookThunk;
1411 ret = dc->dwHookData;
1412 release_dc_ptr( dc );
1417 /* relay function to call the 16-bit DC hook proc */
1418 static BOOL WINAPI call_dc_hook16( HDC hdc, WORD code, DWORD_PTR data, LPARAM lParam )
1422 DC *dc = get_dc_ptr( hdc );
1424 if (!dc) return FALSE;
1427 args[5] = HDC_16(hdc);
1429 args[3] = HIWORD(data);
1430 args[2] = LOWORD(data);
1431 args[1] = HIWORD(lParam);
1432 args[0] = LOWORD(lParam);
1433 WOWCallback16Ex( (DWORD)dc->hookProc, WCB16_PASCAL, sizeof(args), args, &ret );
1435 release_dc_ptr( dc );
1439 /***********************************************************************
1440 * SetDCHook (GDI.190)
1442 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1444 DC *dc = get_dc_ptr( HDC_32(hdc16) );
1446 if (!dc) return FALSE;
1447 if (!(dc->flags & DC_SAVED))
1449 dc->dwHookData = dwHookData;
1450 dc->hookThunk = call_dc_hook16;
1451 dc->hookProc = hookProc;
1453 release_dc_ptr( dc );
1458 /***********************************************************************
1459 * GetDCHook (GDI.191)
1461 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1463 HDC hdc = HDC_32( hdc16 );
1464 DC *dc = get_dc_ptr( hdc );
1468 *phookProc = dc->hookProc;
1469 ret = dc->dwHookData;
1470 release_dc_ptr( dc );
1475 /***********************************************************************
1476 * SetHookFlags (GDI32.@)
1478 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1480 WORD WINAPI SetHookFlags( HDC hdc, WORD flags )
1482 DC *dc = get_dc_obj( hdc ); /* not get_dc_ptr, this needs to work from any thread */
1487 /* "Undocumented Windows" info is slightly confusing. */
1489 TRACE("hDC %p, flags %04x\n",hdc,flags);
1491 if (flags & DCHF_INVALIDATEVISRGN)
1492 ret = InterlockedExchange( &dc->dirty, 1 );
1493 else if (flags & DCHF_VALIDATEVISRGN || !flags)
1494 ret = InterlockedExchange( &dc->dirty, 0 );
1496 GDI_ReleaseObj( dc );
1500 /***********************************************************************
1501 * SetICMMode (GDI32.@)
1503 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1505 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1506 if (iEnableICM == ICM_OFF) return ICM_OFF;
1507 if (iEnableICM == ICM_ON) return 0;
1508 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1512 /***********************************************************************
1513 * GetDeviceGammaRamp (GDI32.@)
1515 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1518 DC *dc = get_dc_ptr( hDC );
1522 if (dc->funcs->pGetDeviceGammaRamp)
1523 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1524 release_dc_ptr( dc );
1529 /***********************************************************************
1530 * SetDeviceGammaRamp (GDI32.@)
1532 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1535 DC *dc = get_dc_ptr( hDC );
1539 if (dc->funcs->pSetDeviceGammaRamp)
1540 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1541 release_dc_ptr( dc );
1546 /***********************************************************************
1547 * GetColorSpace (GDI32.@)
1549 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1551 /*FIXME Need to to whatever GetColorSpace actually does */
1555 /***********************************************************************
1556 * CreateColorSpaceA (GDI32.@)
1558 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1564 /***********************************************************************
1565 * CreateColorSpaceW (GDI32.@)
1567 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1573 /***********************************************************************
1574 * DeleteColorSpace (GDI32.@)
1576 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1583 /***********************************************************************
1584 * SetColorSpace (GDI32.@)
1586 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1593 /***********************************************************************
1594 * GetBoundsRect (GDI32.@)
1596 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1599 DC *dc = get_dc_ptr( hdc );
1601 if ( !dc ) return 0;
1603 if (rect) *rect = dc->BoundsRect;
1605 ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1607 if (flags & DCB_RESET)
1609 dc->BoundsRect.left = 0;
1610 dc->BoundsRect.top = 0;
1611 dc->BoundsRect.right = 0;
1612 dc->BoundsRect.bottom = 0;
1613 dc->flags &= ~DC_BOUNDS_SET;
1615 release_dc_ptr( dc );
1620 /***********************************************************************
1621 * SetBoundsRect (GDI32.@)
1623 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1628 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
1629 if (!(dc = get_dc_ptr( hdc ))) return 0;
1631 ret = ((dc->flags & DC_BOUNDS_ENABLE) ? DCB_ENABLE : DCB_DISABLE) |
1632 ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
1634 if (flags & DCB_RESET)
1636 dc->BoundsRect.left = 0;
1637 dc->BoundsRect.top = 0;
1638 dc->BoundsRect.right = 0;
1639 dc->BoundsRect.bottom = 0;
1640 dc->flags &= ~DC_BOUNDS_SET;
1643 if ((flags & DCB_ACCUMULATE) && rect && rect->left < rect->right && rect->top < rect->bottom)
1645 if (dc->flags & DC_BOUNDS_SET)
1647 dc->BoundsRect.left = min( dc->BoundsRect.left, rect->left );
1648 dc->BoundsRect.top = min( dc->BoundsRect.top, rect->top );
1649 dc->BoundsRect.right = max( dc->BoundsRect.right, rect->right );
1650 dc->BoundsRect.bottom = max( dc->BoundsRect.bottom, rect->bottom );
1654 dc->BoundsRect = *rect;
1655 dc->flags |= DC_BOUNDS_SET;
1659 if (flags & DCB_ENABLE) dc->flags |= DC_BOUNDS_ENABLE;
1660 if (flags & DCB_DISABLE) dc->flags &= ~DC_BOUNDS_ENABLE;
1662 release_dc_ptr( dc );
1667 /***********************************************************************
1668 * GetRelAbs (GDI32.@)
1670 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1673 DC *dc = get_dc_ptr( hdc );
1676 ret = dc->relAbsMode;
1677 release_dc_ptr( dc );
1685 /***********************************************************************
1686 * GetBkMode (GDI32.@)
1688 INT WINAPI GetBkMode( HDC hdc )
1691 DC * dc = get_dc_ptr( hdc );
1694 ret = dc->backgroundMode;
1695 release_dc_ptr( dc );
1701 /***********************************************************************
1702 * SetBkMode (GDI32.@)
1704 INT WINAPI SetBkMode( HDC hdc, INT mode )
1708 if ((mode <= 0) || (mode > BKMODE_LAST))
1710 SetLastError(ERROR_INVALID_PARAMETER);
1713 if (!(dc = get_dc_ptr( hdc ))) return 0;
1715 ret = dc->backgroundMode;
1716 if (dc->funcs->pSetBkMode)
1717 if (!dc->funcs->pSetBkMode( dc->physDev, mode ))
1720 dc->backgroundMode = mode;
1721 release_dc_ptr( dc );
1726 /***********************************************************************
1729 INT WINAPI GetROP2( HDC hdc )
1732 DC * dc = get_dc_ptr( hdc );
1736 release_dc_ptr( dc );
1742 /***********************************************************************
1745 INT WINAPI SetROP2( HDC hdc, INT mode )
1749 if ((mode < R2_BLACK) || (mode > R2_WHITE))
1751 SetLastError(ERROR_INVALID_PARAMETER);
1754 if (!(dc = get_dc_ptr( hdc ))) return 0;
1756 if (dc->funcs->pSetROP2)
1757 if (!dc->funcs->pSetROP2( dc->physDev, mode ))
1761 release_dc_ptr( dc );
1766 /***********************************************************************
1767 * SetRelAbs (GDI32.@)
1769 INT WINAPI SetRelAbs( HDC hdc, INT mode )
1773 if ((mode != ABSOLUTE) && (mode != RELATIVE))
1775 SetLastError(ERROR_INVALID_PARAMETER);
1778 if (!(dc = get_dc_ptr( hdc ))) return 0;
1779 if (dc->funcs->pSetRelAbs)
1780 ret = dc->funcs->pSetRelAbs( dc->physDev, mode );
1783 ret = dc->relAbsMode;
1784 dc->relAbsMode = mode;
1786 release_dc_ptr( dc );
1791 /***********************************************************************
1792 * GetPolyFillMode (GDI32.@)
1794 INT WINAPI GetPolyFillMode( HDC hdc )
1797 DC * dc = get_dc_ptr( hdc );
1800 ret = dc->polyFillMode;
1801 release_dc_ptr( dc );
1807 /***********************************************************************
1808 * SetPolyFillMode (GDI32.@)
1810 INT WINAPI SetPolyFillMode( HDC hdc, INT mode )
1814 if ((mode <= 0) || (mode > POLYFILL_LAST))
1816 SetLastError(ERROR_INVALID_PARAMETER);
1819 if (!(dc = get_dc_ptr( hdc ))) return 0;
1820 ret = dc->polyFillMode;
1821 if (dc->funcs->pSetPolyFillMode)
1822 if (!dc->funcs->pSetPolyFillMode( dc->physDev, mode ))
1825 dc->polyFillMode = mode;
1826 release_dc_ptr( dc );
1831 /***********************************************************************
1832 * GetStretchBltMode (GDI32.@)
1834 INT WINAPI GetStretchBltMode( HDC hdc )
1837 DC * dc = get_dc_ptr( hdc );
1840 ret = dc->stretchBltMode;
1841 release_dc_ptr( dc );
1847 /***********************************************************************
1848 * SetStretchBltMode (GDI32.@)
1850 INT WINAPI SetStretchBltMode( HDC hdc, INT mode )
1854 if ((mode <= 0) || (mode > MAXSTRETCHBLTMODE))
1856 SetLastError(ERROR_INVALID_PARAMETER);
1859 if (!(dc = get_dc_ptr( hdc ))) return 0;
1860 ret = dc->stretchBltMode;
1861 if (dc->funcs->pSetStretchBltMode)
1862 if (!dc->funcs->pSetStretchBltMode( dc->physDev, mode ))
1865 dc->stretchBltMode = mode;
1866 release_dc_ptr( dc );
1871 /***********************************************************************
1872 * GetMapMode (GDI32.@)
1874 INT WINAPI GetMapMode( HDC hdc )
1877 DC * dc = get_dc_ptr( hdc );
1881 release_dc_ptr( dc );
1887 /***********************************************************************
1888 * GetBrushOrgEx (GDI32.@)
1890 BOOL WINAPI GetBrushOrgEx( HDC hdc, LPPOINT pt )
1892 DC * dc = get_dc_ptr( hdc );
1893 if (!dc) return FALSE;
1894 pt->x = dc->brushOrgX;
1895 pt->y = dc->brushOrgY;
1896 release_dc_ptr( dc );
1901 /***********************************************************************
1902 * GetCurrentPositionEx (GDI32.@)
1904 BOOL WINAPI GetCurrentPositionEx( HDC hdc, LPPOINT pt )
1906 DC * dc = get_dc_ptr( hdc );
1907 if (!dc) return FALSE;
1908 pt->x = dc->CursPosX;
1909 pt->y = dc->CursPosY;
1910 release_dc_ptr( dc );
1915 /***********************************************************************
1916 * GetViewportExtEx (GDI32.@)
1918 BOOL WINAPI GetViewportExtEx( HDC hdc, LPSIZE size )
1920 DC * dc = get_dc_ptr( hdc );
1921 if (!dc) return FALSE;
1922 size->cx = dc->vportExtX;
1923 size->cy = dc->vportExtY;
1924 release_dc_ptr( dc );
1929 /***********************************************************************
1930 * GetViewportOrgEx (GDI32.@)
1932 BOOL WINAPI GetViewportOrgEx( HDC hdc, LPPOINT pt )
1934 DC * dc = get_dc_ptr( hdc );
1935 if (!dc) return FALSE;
1936 pt->x = dc->vportOrgX;
1937 pt->y = dc->vportOrgY;
1938 release_dc_ptr( dc );
1943 /***********************************************************************
1944 * GetWindowExtEx (GDI32.@)
1946 BOOL WINAPI GetWindowExtEx( HDC hdc, LPSIZE size )
1948 DC * dc = get_dc_ptr( hdc );
1949 if (!dc) return FALSE;
1950 size->cx = dc->wndExtX;
1951 size->cy = dc->wndExtY;
1952 release_dc_ptr( dc );
1957 /***********************************************************************
1958 * GetWindowOrgEx (GDI32.@)
1960 BOOL WINAPI GetWindowOrgEx( HDC hdc, LPPOINT pt )
1962 DC * dc = get_dc_ptr( hdc );
1963 if (!dc) return FALSE;
1964 pt->x = dc->wndOrgX;
1965 pt->y = dc->wndOrgY;
1966 release_dc_ptr( dc );
1971 /***********************************************************************
1972 * GetLayout (GDI32.@)
1974 * Gets left->right or right->left text layout flags of a dc.
1977 DWORD WINAPI GetLayout(HDC hdc)
1979 DWORD layout = GDI_ERROR;
1981 DC * dc = get_dc_ptr( hdc );
1984 layout = dc->layout;
1985 release_dc_ptr( dc );
1988 TRACE("hdc : %p, layout : %08x\n", hdc, layout);
1993 /***********************************************************************
1994 * SetLayout (GDI32.@)
1996 * Sets left->right or right->left text layout flags of a dc.
1999 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
2001 DWORD oldlayout = GDI_ERROR;
2003 DC * dc = get_dc_ptr( hdc );
2006 oldlayout = dc->layout;
2007 dc->layout = layout;
2008 release_dc_ptr( dc );
2011 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc, oldlayout, layout);
2016 /***********************************************************************
2017 * GetDCBrushColor (GDI32.@)
2019 * Retrieves the current brush color for the specified device
2023 COLORREF WINAPI GetDCBrushColor(HDC hdc)
2026 COLORREF dcBrushColor = CLR_INVALID;
2028 TRACE("hdc(%p)\n", hdc);
2030 dc = get_dc_ptr( hdc );
2033 dcBrushColor = dc->dcBrushColor;
2034 release_dc_ptr( dc );
2037 return dcBrushColor;
2040 /***********************************************************************
2041 * SetDCBrushColor (GDI32.@)
2043 * Sets the current device context (DC) brush color to the specified
2044 * color value. If the device cannot represent the specified color
2045 * value, the color is set to the nearest physical color.
2048 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
2051 COLORREF oldClr = CLR_INVALID;
2053 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2055 dc = get_dc_ptr( hdc );
2058 if (dc->funcs->pSetDCBrushColor)
2059 crColor = dc->funcs->pSetDCBrushColor( dc->physDev, crColor );
2060 else if (dc->hBrush == GetStockObject( DC_BRUSH ))
2062 /* If DC_BRUSH is selected, update driver pen color */
2063 HBRUSH hBrush = CreateSolidBrush( crColor );
2064 dc->funcs->pSelectBrush( dc->physDev, hBrush );
2065 DeleteObject( hBrush );
2068 if (crColor != CLR_INVALID)
2070 oldClr = dc->dcBrushColor;
2071 dc->dcBrushColor = crColor;
2074 release_dc_ptr( dc );
2080 /***********************************************************************
2081 * GetDCPenColor (GDI32.@)
2083 * Retrieves the current pen color for the specified device
2087 COLORREF WINAPI GetDCPenColor(HDC hdc)
2090 COLORREF dcPenColor = CLR_INVALID;
2092 TRACE("hdc(%p)\n", hdc);
2094 dc = get_dc_ptr( hdc );
2097 dcPenColor = dc->dcPenColor;
2098 release_dc_ptr( dc );
2104 /***********************************************************************
2105 * SetDCPenColor (GDI32.@)
2107 * Sets the current device context (DC) pen color to the specified
2108 * color value. If the device cannot represent the specified color
2109 * value, the color is set to the nearest physical color.
2112 COLORREF WINAPI SetDCPenColor(HDC hdc, COLORREF crColor)
2115 COLORREF oldClr = CLR_INVALID;
2117 TRACE("hdc(%p) crColor(%08x)\n", hdc, crColor);
2119 dc = get_dc_ptr( hdc );
2122 if (dc->funcs->pSetDCPenColor)
2123 crColor = dc->funcs->pSetDCPenColor( dc->physDev, crColor );
2124 else if (dc->hPen == GetStockObject( DC_PEN ))
2126 /* If DC_PEN is selected, update the driver pen color */
2127 LOGPEN logpen = { PS_SOLID, { 0, 0 }, crColor };
2128 HPEN hPen = CreatePenIndirect( &logpen );
2129 dc->funcs->pSelectPen( dc->physDev, hPen );
2130 DeleteObject( hPen );
2133 if (crColor != CLR_INVALID)
2135 oldClr = dc->dcPenColor;
2136 dc->dcPenColor = crColor;
2139 release_dc_ptr( dc );
2145 /***********************************************************************
2146 * CancelDC (GDI32.@)
2148 BOOL WINAPI CancelDC(HDC hdc)
2154 /*******************************************************************
2155 * GetMiterLimit [GDI32.@]
2159 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
2164 TRACE("(%p,%p)\n", hdc, peLimit);
2166 dc = get_dc_ptr( hdc );
2170 *peLimit = dc->miterLimit;
2172 release_dc_ptr( dc );
2178 /*******************************************************************
2179 * SetMiterLimit [GDI32.@]
2183 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
2188 TRACE("(%p,%f,%p)\n", hdc, eNewLimit, peOldLimit);
2190 dc = get_dc_ptr( hdc );
2194 *peOldLimit = dc->miterLimit;
2195 dc->miterLimit = eNewLimit;
2196 release_dc_ptr( dc );
2202 /*******************************************************************
2203 * GdiIsMetaPrintDC [GDI32.@]
2205 BOOL WINAPI GdiIsMetaPrintDC(HDC hdc)
2211 /*******************************************************************
2212 * GdiIsMetaFileDC [GDI32.@]
2214 BOOL WINAPI GdiIsMetaFileDC(HDC hdc)
2218 switch( GetObjectType( hdc ) )
2227 /*******************************************************************
2228 * GdiIsPlayMetafileDC [GDI32.@]
2230 BOOL WINAPI GdiIsPlayMetafileDC(HDC hdc)