Altered WM_MOUSEHOVER so the lParam and wParam fields are set
[wine/multimedia.git] / objects / dc.c
blob9000922d273969b79249c339b2b68c959f2ed165
1 /*
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
21 #include "config.h"
23 #include <stdlib.h>
24 #include <string.h>
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "winerror.h"
28 #include "wownt32.h"
29 #include "wine/winuser16.h"
30 #include "gdi.h"
31 #include "heap.h"
32 #include "font.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dc);
37 /* ### start build ### */
38 extern WORD CALLBACK GDI_CallTo16_word_wwll(FARPROC16,WORD,WORD,LONG,LONG);
39 /* ### stop build ### */
41 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj );
43 static const struct gdi_obj_funcs dc_funcs =
45 NULL, /* pSelectObject */
46 NULL, /* pGetObject16 */
47 NULL, /* pGetObjectA */
48 NULL, /* pGetObjectW */
49 NULL, /* pUnrealizeObject */
50 DC_DeleteObject /* pDeleteObject */
53 /***********************************************************************
54 * DC_AllocDC
56 DC *DC_AllocDC( const DC_FUNCTIONS *funcs )
58 HDC hdc;
59 DC *dc;
61 if (!(dc = GDI_AllocObject( sizeof(*dc), DC_MAGIC, (HGDIOBJ*)&hdc, &dc_funcs ))) return NULL;
63 dc->hSelf = hdc;
64 dc->funcs = funcs;
65 dc->physDev = NULL;
66 dc->saveLevel = 0;
67 dc->dwHookData = 0;
68 dc->hookProc = NULL;
69 dc->hookThunk = NULL;
70 dc->wndOrgX = 0;
71 dc->wndOrgY = 0;
72 dc->wndExtX = 1;
73 dc->wndExtY = 1;
74 dc->vportOrgX = 0;
75 dc->vportOrgY = 0;
76 dc->vportExtX = 1;
77 dc->vportExtY = 1;
78 dc->flags = 0;
79 dc->hClipRgn = 0;
80 dc->hVisRgn = 0;
81 dc->hGCClipRgn = 0;
82 dc->hPen = GetStockObject( BLACK_PEN );
83 dc->hBrush = GetStockObject( WHITE_BRUSH );
84 dc->hFont = GetStockObject( SYSTEM_FONT );
85 dc->hBitmap = 0;
86 dc->hDevice = 0;
87 dc->hPalette = GetStockObject( DEFAULT_PALETTE );
88 dc->gdiFont = 0;
89 dc->ROPmode = R2_COPYPEN;
90 dc->polyFillMode = ALTERNATE;
91 dc->stretchBltMode = BLACKONWHITE;
92 dc->relAbsMode = ABSOLUTE;
93 dc->backgroundMode = OPAQUE;
94 dc->backgroundColor = RGB( 255, 255, 255 );
95 dc->textColor = RGB( 0, 0, 0 );
96 dc->brushOrgX = 0;
97 dc->brushOrgY = 0;
98 dc->textAlign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
99 dc->charExtra = 0;
100 dc->breakTotalExtra = 0;
101 dc->breakCount = 0;
102 dc->breakExtra = 0;
103 dc->breakRem = 0;
104 dc->totalExtent.left = 0;
105 dc->totalExtent.top = 0;
106 dc->totalExtent.right = 0;
107 dc->totalExtent.bottom = 0;
108 dc->bitsPerPixel = 1;
109 dc->MapMode = MM_TEXT;
110 dc->GraphicsMode = GM_COMPATIBLE;
111 dc->pAbortProc = NULL;
112 dc->CursPosX = 0;
113 dc->CursPosY = 0;
114 dc->ArcDirection = AD_COUNTERCLOCKWISE;
115 dc->xformWorld2Wnd.eM11 = 1.0f;
116 dc->xformWorld2Wnd.eM12 = 0.0f;
117 dc->xformWorld2Wnd.eM21 = 0.0f;
118 dc->xformWorld2Wnd.eM22 = 1.0f;
119 dc->xformWorld2Wnd.eDx = 0.0f;
120 dc->xformWorld2Wnd.eDy = 0.0f;
121 dc->xformWorld2Vport = dc->xformWorld2Wnd;
122 dc->xformVport2World = dc->xformWorld2Wnd;
123 dc->vport2WorldValid = TRUE;
124 PATH_InitGdiPath(&dc->path);
125 return dc;
130 /***********************************************************************
131 * DC_GetDCPtr
133 DC *DC_GetDCPtr( HDC hdc )
135 GDIOBJHDR *ptr = GDI_GetObjPtr( hdc, MAGIC_DONTCARE );
136 if (!ptr) return NULL;
137 if ((GDIMAGIC(ptr->wMagic) == DC_MAGIC) ||
138 (GDIMAGIC(ptr->wMagic) == METAFILE_DC_MAGIC) ||
139 (GDIMAGIC(ptr->wMagic) == ENHMETAFILE_DC_MAGIC))
140 return (DC *)ptr;
141 GDI_ReleaseObj( hdc );
142 SetLastError( ERROR_INVALID_HANDLE );
143 return NULL;
146 /***********************************************************************
147 * DC_GetDCUpdate
149 * Retrieve a DC ptr while making sure the visRgn is updated.
150 * This function may call up to USER so the GDI lock should _not_
151 * be held when calling it.
153 DC *DC_GetDCUpdate( HDC hdc )
155 DC *dc = DC_GetDCPtr( hdc );
156 if (!dc) return NULL;
157 while (dc->flags & DC_DIRTY)
159 dc->flags &= ~DC_DIRTY;
160 if (!(dc->flags & (DC_SAVED | DC_MEMORY)))
162 DCHOOKPROC proc = dc->hookThunk;
163 if (proc)
165 DWORD data = dc->dwHookData;
166 GDI_ReleaseObj( hdc );
167 proc( HDC_16(hdc), DCHC_INVALIDVISRGN, data, 0 );
168 if (!(dc = DC_GetDCPtr( hdc ))) break;
169 /* otherwise restart the loop in case it became dirty again in the meantime */
173 return dc;
177 /***********************************************************************
178 * DC_DeleteObject
180 static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj )
182 GDI_ReleaseObj( handle );
183 return DeleteDC( handle );
187 /***********************************************************************
188 * DC_InitDC
190 * Setup device-specific DC values for a newly created DC.
192 void DC_InitDC( DC* dc )
194 if (dc->funcs->pRealizeDefaultPalette) dc->funcs->pRealizeDefaultPalette( dc->physDev );
195 SetTextColor( dc->hSelf, dc->textColor );
196 SetBkColor( dc->hSelf, dc->backgroundColor );
197 SelectObject( dc->hSelf, dc->hPen );
198 SelectObject( dc->hSelf, dc->hBrush );
199 SelectObject( dc->hSelf, dc->hFont );
200 CLIPPING_UpdateGCRegion( dc );
204 /***********************************************************************
205 * DC_InvertXform
207 * Computes the inverse of the transformation xformSrc and stores it to
208 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
209 * is singular.
211 static BOOL DC_InvertXform( const XFORM *xformSrc, XFORM *xformDest )
213 FLOAT determinant;
215 determinant = xformSrc->eM11*xformSrc->eM22 -
216 xformSrc->eM12*xformSrc->eM21;
217 if (determinant > -1e-12 && determinant < 1e-12)
218 return FALSE;
220 xformDest->eM11 = xformSrc->eM22 / determinant;
221 xformDest->eM12 = -xformSrc->eM12 / determinant;
222 xformDest->eM21 = -xformSrc->eM21 / determinant;
223 xformDest->eM22 = xformSrc->eM11 / determinant;
224 xformDest->eDx = -xformSrc->eDx * xformDest->eM11 -
225 xformSrc->eDy * xformDest->eM21;
226 xformDest->eDy = -xformSrc->eDx * xformDest->eM12 -
227 xformSrc->eDy * xformDest->eM22;
229 return TRUE;
233 /***********************************************************************
234 * DC_UpdateXforms
236 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
237 * fields of the specified DC by creating a transformation that
238 * represents the current mapping mode and combining it with the DC's
239 * world transform. This function should be called whenever the
240 * parameters associated with the mapping mode (window and viewport
241 * extents and origins) or the world transform change.
243 void DC_UpdateXforms( DC *dc )
245 XFORM xformWnd2Vport;
246 FLOAT scaleX, scaleY;
248 /* Construct a transformation to do the window-to-viewport conversion */
249 scaleX = (FLOAT)dc->vportExtX / (FLOAT)dc->wndExtX;
250 scaleY = (FLOAT)dc->vportExtY / (FLOAT)dc->wndExtY;
251 xformWnd2Vport.eM11 = scaleX;
252 xformWnd2Vport.eM12 = 0.0;
253 xformWnd2Vport.eM21 = 0.0;
254 xformWnd2Vport.eM22 = scaleY;
255 xformWnd2Vport.eDx = (FLOAT)dc->vportOrgX -
256 scaleX * (FLOAT)dc->wndOrgX;
257 xformWnd2Vport.eDy = (FLOAT)dc->vportOrgY -
258 scaleY * (FLOAT)dc->wndOrgY;
260 /* Combine with the world transformation */
261 CombineTransform( &dc->xformWorld2Vport, &dc->xformWorld2Wnd,
262 &xformWnd2Vport );
264 /* Create inverse of world-to-viewport transformation */
265 dc->vport2WorldValid = DC_InvertXform( &dc->xformWorld2Vport,
266 &dc->xformVport2World );
270 /***********************************************************************
271 * GetDCState (Not a Windows API)
273 HDC WINAPI GetDCState( HDC hdc )
275 DC * newdc, * dc;
276 HGDIOBJ handle;
278 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
279 if (!(newdc = GDI_AllocObject( sizeof(DC), DC_MAGIC, &handle, &dc_funcs )))
281 GDI_ReleaseObj( hdc );
282 return 0;
284 TRACE("(%p): returning %p\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;
335 newdc->hookProc = 0;
337 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
339 newdc->hGCClipRgn = newdc->hVisRgn = 0;
340 if (dc->hClipRgn)
342 newdc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
343 CombineRgn( newdc->hClipRgn, dc->hClipRgn, 0, RGN_COPY );
345 else
346 newdc->hClipRgn = 0;
348 if(dc->gdiFont) {
349 newdc->gdiFont = dc->gdiFont;
350 } else
351 newdc->gdiFont = 0;
353 GDI_ReleaseObj( handle );
354 GDI_ReleaseObj( hdc );
355 return handle;
359 /***********************************************************************
360 * SetDCState (Not a Windows API)
362 void WINAPI SetDCState( HDC hdc, HDC hdcs )
364 DC *dc, *dcs;
366 if (!(dc = DC_GetDCUpdate( hdc ))) return;
367 if (!(dcs = DC_GetDCPtr( hdcs )))
369 GDI_ReleaseObj( hdc );
370 return;
372 if (!dcs->flags & DC_SAVED)
374 GDI_ReleaseObj( hdc );
375 GDI_ReleaseObj( hdcs );
376 return;
378 TRACE("%p %p\n", hdc, hdcs );
380 dc->flags = dcs->flags & ~(DC_SAVED | DC_DIRTY);
381 dc->hDevice = dcs->hDevice;
382 dc->totalExtent = dcs->totalExtent;
383 dc->ROPmode = dcs->ROPmode;
384 dc->polyFillMode = dcs->polyFillMode;
385 dc->stretchBltMode = dcs->stretchBltMode;
386 dc->relAbsMode = dcs->relAbsMode;
387 dc->backgroundMode = dcs->backgroundMode;
388 dc->backgroundColor = dcs->backgroundColor;
389 dc->textColor = dcs->textColor;
390 dc->brushOrgX = dcs->brushOrgX;
391 dc->brushOrgY = dcs->brushOrgY;
392 dc->textAlign = dcs->textAlign;
393 dc->charExtra = dcs->charExtra;
394 dc->breakTotalExtra = dcs->breakTotalExtra;
395 dc->breakCount = dcs->breakCount;
396 dc->breakExtra = dcs->breakExtra;
397 dc->breakRem = dcs->breakRem;
398 dc->MapMode = dcs->MapMode;
399 dc->GraphicsMode = dcs->GraphicsMode;
400 dc->CursPosX = dcs->CursPosX;
401 dc->CursPosY = dcs->CursPosY;
402 dc->ArcDirection = dcs->ArcDirection;
403 dc->xformWorld2Wnd = dcs->xformWorld2Wnd;
404 dc->xformWorld2Vport = dcs->xformWorld2Vport;
405 dc->xformVport2World = dcs->xformVport2World;
406 dc->vport2WorldValid = dcs->vport2WorldValid;
408 dc->wndOrgX = dcs->wndOrgX;
409 dc->wndOrgY = dcs->wndOrgY;
410 dc->wndExtX = dcs->wndExtX;
411 dc->wndExtY = dcs->wndExtY;
412 dc->vportOrgX = dcs->vportOrgX;
413 dc->vportOrgY = dcs->vportOrgY;
414 dc->vportExtX = dcs->vportExtX;
415 dc->vportExtY = dcs->vportExtY;
417 if (!(dc->flags & DC_MEMORY)) dc->bitsPerPixel = dcs->bitsPerPixel;
419 if (dcs->hClipRgn)
421 if (!dc->hClipRgn) dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
422 CombineRgn( dc->hClipRgn, dcs->hClipRgn, 0, RGN_COPY );
424 else
426 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
427 dc->hClipRgn = 0;
429 CLIPPING_UpdateGCRegion( dc );
431 SelectObject( hdc, dcs->hBitmap );
432 SelectObject( hdc, dcs->hBrush );
433 SelectObject( hdc, dcs->hFont );
434 SelectObject( hdc, dcs->hPen );
435 SetBkColor( hdc, dcs->backgroundColor);
436 SetTextColor( hdc, dcs->textColor);
437 GDISelectPalette( hdc, dcs->hPalette, FALSE );
438 GDI_ReleaseObj( hdcs );
439 GDI_ReleaseObj( hdc );
443 /***********************************************************************
444 * GetDCState (GDI.179)
446 HDC16 WINAPI GetDCState16( HDC16 hdc )
448 return HDC_16( GetDCState( HDC_32(hdc) ));
452 /***********************************************************************
453 * SetDCState (GDI.180)
455 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
457 SetDCState( HDC_32(hdc), HDC_32(hdcs) );
461 /***********************************************************************
462 * SaveDC (GDI32.@)
464 INT WINAPI SaveDC( HDC hdc )
466 HDC hdcs;
467 DC * dc, * dcs;
468 INT ret;
470 dc = DC_GetDCPtr( hdc );
471 if (!dc) return 0;
473 if(dc->funcs->pSaveDC)
475 ret = dc->funcs->pSaveDC( dc->physDev );
476 GDI_ReleaseObj( hdc );
477 return ret;
480 if (!(hdcs = GetDCState( hdc )))
482 GDI_ReleaseObj( hdc );
483 return 0;
485 dcs = DC_GetDCPtr( hdcs );
487 /* Copy path. The reason why path saving / restoring is in SaveDC/
488 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
489 * functions are only in Win16 (which doesn't have paths) and that
490 * SetDCState doesn't allow us to signal an error (which can happen
491 * when copying paths).
493 if (!PATH_AssignGdiPath( &dcs->path, &dc->path ))
495 GDI_ReleaseObj( hdc );
496 GDI_ReleaseObj( hdcs );
497 DeleteDC( hdcs );
498 return 0;
501 dcs->header.hNext = dc->header.hNext;
502 dc->header.hNext = HDC_16(hdcs);
503 TRACE("(%p): returning %d\n", hdc, dc->saveLevel+1 );
504 ret = ++dc->saveLevel;
505 GDI_ReleaseObj( hdcs );
506 GDI_ReleaseObj( hdc );
507 return ret;
511 /***********************************************************************
512 * RestoreDC (GDI32.@)
514 BOOL WINAPI RestoreDC( HDC hdc, INT level )
516 DC * dc, * dcs;
517 BOOL success;
519 TRACE("%p %d\n", hdc, level );
520 dc = DC_GetDCUpdate( hdc );
521 if(!dc) return FALSE;
522 if(dc->funcs->pRestoreDC)
524 success = dc->funcs->pRestoreDC( dc->physDev, level );
525 GDI_ReleaseObj( hdc );
526 return success;
529 if (level == -1) level = dc->saveLevel;
530 if ((level < 1)
531 /* This pair of checks disagrees with MSDN "Platform SDK:
532 Windows GDI" July 2000 which says all negative values
533 for level will be interpreted as an instance relative
534 to the current state. Restricting it to just -1 does
535 not satisfy this */
536 || (level > dc->saveLevel))
538 GDI_ReleaseObj( hdc );
539 return FALSE;
542 success=TRUE;
543 while (dc->saveLevel >= level)
545 HDC hdcs = HDC_32(dc->header.hNext);
546 if (!(dcs = DC_GetDCPtr( hdcs )))
548 GDI_ReleaseObj( hdc );
549 return FALSE;
551 dc->header.hNext = dcs->header.hNext;
552 if (--dc->saveLevel < level)
554 SetDCState( hdc, hdcs );
555 if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
556 /* FIXME: This might not be quite right, since we're
557 * returning FALSE but still destroying the saved DC state */
558 success=FALSE;
560 GDI_ReleaseObj( hdcs );
561 GDI_ReleaseObj( hdc );
562 DeleteDC( hdcs );
563 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
565 GDI_ReleaseObj( hdc );
566 return success;
570 /***********************************************************************
571 * CreateDCA (GDI32.@)
573 HDC WINAPI CreateDCA( LPCSTR driver, LPCSTR device, LPCSTR output,
574 const DEVMODEA *initData )
576 HDC hdc;
577 DC * dc;
578 const DC_FUNCTIONS *funcs;
579 char buf[300];
581 GDI_CheckNotLock();
583 if (!device || !DRIVER_GetDriverName( device, buf, sizeof(buf) ))
585 if (!driver) return 0;
586 strcpy(buf, driver);
589 if (!(funcs = DRIVER_load_driver( buf )))
591 ERR( "no driver found for %s\n", buf );
592 return 0;
594 if (!(dc = DC_AllocDC( funcs )))
596 DRIVER_release_driver( funcs );
597 return 0;
600 dc->flags = 0;
602 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
603 debugstr_a(driver), debugstr_a(device), debugstr_a(output), dc->hSelf );
605 if (dc->funcs->pCreateDC &&
606 !dc->funcs->pCreateDC( dc, &dc->physDev, buf, device, output, initData ))
608 WARN("creation aborted by device\n" );
609 GDI_FreeObject( dc->hSelf, dc );
610 DRIVER_release_driver( funcs );
611 return 0;
614 dc->totalExtent.left = 0;
615 dc->totalExtent.top = 0;
616 dc->totalExtent.right = GetDeviceCaps( dc->hSelf, HORZRES );
617 dc->totalExtent.bottom = GetDeviceCaps( dc->hSelf, VERTRES );
618 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
620 DC_InitDC( dc );
621 hdc = dc->hSelf;
622 GDI_ReleaseObj( hdc );
623 return hdc;
627 /***********************************************************************
628 * CreateDCW (GDI32.@)
630 HDC WINAPI CreateDCW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
631 const DEVMODEW *initData )
633 LPSTR driverA = HEAP_strdupWtoA( GetProcessHeap(), 0, driver );
634 LPSTR deviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, device );
635 LPSTR outputA = HEAP_strdupWtoA( GetProcessHeap(), 0, output );
636 HDC res = CreateDCA( driverA, deviceA, outputA,
637 (const DEVMODEA *)initData /*FIXME*/ );
638 HeapFree( GetProcessHeap(), 0, driverA );
639 HeapFree( GetProcessHeap(), 0, deviceA );
640 HeapFree( GetProcessHeap(), 0, outputA );
641 return res;
645 /***********************************************************************
646 * CreateICA (GDI32.@)
648 HDC WINAPI CreateICA( LPCSTR driver, LPCSTR device, LPCSTR output,
649 const DEVMODEA* initData )
651 /* Nothing special yet for ICs */
652 return CreateDCA( driver, device, output, initData );
656 /***********************************************************************
657 * CreateICW (GDI32.@)
659 HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output,
660 const DEVMODEW* initData )
662 /* Nothing special yet for ICs */
663 return CreateDCW( driver, device, output, initData );
667 /***********************************************************************
668 * CreateCompatibleDC (GDI32.@)
670 HDC WINAPI CreateCompatibleDC( HDC hdc )
672 DC *dc, *origDC;
673 const DC_FUNCTIONS *funcs;
675 GDI_CheckNotLock();
677 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC )))
679 funcs = origDC->funcs;
680 GDI_ReleaseObj( hdc ); /* can't hold the lock while loading the driver */
681 funcs = DRIVER_get_driver( funcs );
683 else funcs = DRIVER_load_driver( "DISPLAY" );
685 if (!funcs) return 0;
687 if (!(dc = DC_AllocDC( funcs )))
689 DRIVER_release_driver( funcs );
690 return 0;
693 TRACE("(%p): returning %p\n", hdc, dc->hSelf );
695 dc->flags = DC_MEMORY;
696 dc->bitsPerPixel = 1;
697 dc->hBitmap = GetStockObject( DEFAULT_BITMAP );
699 /* Copy the driver-specific physical device info into
700 * the new DC. The driver may use this read-only info
701 * while creating the compatible DC below. */
702 if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC ))) dc->physDev = origDC->physDev;
704 if (dc->funcs->pCreateDC &&
705 !dc->funcs->pCreateDC( dc, &dc->physDev, NULL, NULL, NULL, NULL ))
707 WARN("creation aborted by device\n");
708 GDI_FreeObject( dc->hSelf, dc );
709 if (origDC) GDI_ReleaseObj( hdc );
710 DRIVER_release_driver( funcs );
711 return 0;
714 dc->totalExtent.left = 0;
715 dc->totalExtent.top = 0;
716 dc->totalExtent.right = 1; /* default bitmap is 1x1 */
717 dc->totalExtent.bottom = 1;
718 dc->hVisRgn = CreateRectRgnIndirect( &dc->totalExtent );
720 DC_InitDC( dc );
721 GDI_ReleaseObj( dc->hSelf );
722 if (origDC) GDI_ReleaseObj( hdc );
723 return dc->hSelf;
727 /***********************************************************************
728 * DeleteDC (GDI32.@)
730 BOOL WINAPI DeleteDC( HDC hdc )
732 const DC_FUNCTIONS *funcs = NULL;
733 DC * dc;
735 TRACE("%p\n", hdc );
737 GDI_CheckNotLock();
739 if (!(dc = GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
741 /* Call hook procedure to check whether is it OK to delete this DC */
742 if (dc->hookThunk && !(dc->flags & (DC_SAVED | DC_MEMORY)))
744 DCHOOKPROC proc = dc->hookThunk;
745 if (proc)
747 DWORD data = dc->dwHookData;
748 GDI_ReleaseObj( hdc );
749 if (!proc( HDC_16(hdc), DCHC_DELETEDC, data, 0 )) return FALSE;
750 if (!(dc = DC_GetDCPtr( hdc ))) return TRUE; /* deleted by the hook */
754 while (dc->saveLevel)
756 DC * dcs;
757 HDC hdcs = HDC_32(dc->header.hNext);
758 if (!(dcs = DC_GetDCPtr( hdcs ))) break;
759 dc->header.hNext = dcs->header.hNext;
760 dc->saveLevel--;
761 if (dcs->hClipRgn) DeleteObject( dcs->hClipRgn );
762 if (dcs->hVisRgn) DeleteObject( dcs->hVisRgn );
763 if (dcs->hGCClipRgn) DeleteObject( dcs->hGCClipRgn );
764 PATH_DestroyGdiPath(&dcs->path);
765 GDI_FreeObject( hdcs, dcs );
768 if (!(dc->flags & DC_SAVED))
770 SelectObject( hdc, GetStockObject(BLACK_PEN) );
771 SelectObject( hdc, GetStockObject(WHITE_BRUSH) );
772 SelectObject( hdc, GetStockObject(SYSTEM_FONT) );
773 SelectObject( hdc, GetStockObject(DEFAULT_BITMAP) );
774 funcs = dc->funcs;
775 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc->physDev);
776 dc->physDev = NULL;
779 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
780 if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
781 if (dc->hGCClipRgn) DeleteObject( dc->hGCClipRgn );
782 PATH_DestroyGdiPath(&dc->path);
784 GDI_FreeObject( hdc, dc );
785 if (funcs) DRIVER_release_driver( funcs ); /* do that after releasing the GDI lock */
786 return TRUE;
790 /***********************************************************************
791 * ResetDCA (GDI32.@)
793 HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode )
795 DC *dc;
796 HDC ret = hdc;
798 if ((dc = DC_GetDCPtr( hdc )))
800 if (dc->funcs->pResetDC) ret = dc->funcs->pResetDC( dc->physDev, devmode );
801 GDI_ReleaseObj( hdc );
803 return ret;
807 /***********************************************************************
808 * ResetDCW (GDI32.@)
810 HDC WINAPI ResetDCW( HDC hdc, const DEVMODEW *devmode )
812 return ResetDCA(hdc, (const DEVMODEA*)devmode); /* FIXME */
816 /***********************************************************************
817 * GetDeviceCaps (GDI32.@)
819 INT WINAPI GetDeviceCaps( HDC hdc, INT cap )
821 DC *dc;
822 INT ret = 0;
824 if ((dc = DC_GetDCPtr( hdc )))
826 if (dc->funcs->pGetDeviceCaps) ret = dc->funcs->pGetDeviceCaps( dc->physDev, cap );
827 GDI_ReleaseObj( hdc );
829 return ret;
833 /***********************************************************************
834 * SetBkColor (GDI32.@)
836 COLORREF WINAPI SetBkColor( HDC hdc, COLORREF color )
838 COLORREF oldColor;
839 DC * dc = DC_GetDCPtr( hdc );
841 if (!dc) return CLR_INVALID;
842 oldColor = dc->backgroundColor;
843 if (dc->funcs->pSetBkColor)
845 color = dc->funcs->pSetBkColor(dc->physDev, color);
846 if (color == CLR_INVALID) /* don't change it */
848 color = oldColor;
849 oldColor = CLR_INVALID;
852 dc->backgroundColor = color;
853 GDI_ReleaseObj( hdc );
854 return oldColor;
858 /***********************************************************************
859 * SetTextColor (GDI32.@)
861 COLORREF WINAPI SetTextColor( HDC hdc, COLORREF color )
863 COLORREF oldColor;
864 DC * dc = DC_GetDCPtr( hdc );
866 if (!dc) return CLR_INVALID;
867 oldColor = dc->textColor;
868 if (dc->funcs->pSetTextColor)
870 color = dc->funcs->pSetTextColor(dc->physDev, color);
871 if (color == CLR_INVALID) /* don't change it */
873 color = oldColor;
874 oldColor = CLR_INVALID;
877 dc->textColor = color;
878 GDI_ReleaseObj( hdc );
879 return oldColor;
883 /***********************************************************************
884 * SetTextAlign (GDI32.@)
886 UINT WINAPI SetTextAlign( HDC hdc, UINT align )
888 UINT prevAlign;
889 DC *dc = DC_GetDCPtr( hdc );
890 if (!dc) return 0x0;
891 if (dc->funcs->pSetTextAlign)
892 prevAlign = dc->funcs->pSetTextAlign(dc->physDev, align);
893 else {
894 prevAlign = dc->textAlign;
895 dc->textAlign = align;
897 GDI_ReleaseObj( hdc );
898 return prevAlign;
901 /***********************************************************************
902 * GetDCOrgEx (GDI32.@)
904 BOOL WINAPI GetDCOrgEx( HDC hDC, LPPOINT lpp )
906 DC * dc;
908 if (!lpp) return FALSE;
909 if (!(dc = DC_GetDCPtr( hDC ))) return FALSE;
911 lpp->x = lpp->y = 0;
912 if (dc->funcs->pGetDCOrgEx) dc->funcs->pGetDCOrgEx( dc->physDev, lpp );
913 GDI_ReleaseObj( hDC );
914 return TRUE;
918 /***********************************************************************
919 * SetDCOrg (GDI.117)
921 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
923 DWORD prevOrg = 0;
924 HDC hdc = HDC_32( hdc16 );
925 DC *dc = DC_GetDCPtr( hdc );
926 if (!dc) return 0;
927 if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
928 GDI_ReleaseObj( hdc );
929 return prevOrg;
933 /***********************************************************************
934 * SetGraphicsMode (GDI32.@)
936 INT WINAPI SetGraphicsMode( HDC hdc, INT mode )
938 INT ret = 0;
939 DC *dc = DC_GetDCPtr( hdc );
941 /* One would think that setting the graphics mode to GM_COMPATIBLE
942 * would also reset the world transformation matrix to the unity
943 * matrix. However, in Windows, this is not the case. This doesn't
944 * make a lot of sense to me, but that's the way it is.
946 if (!dc) return 0;
947 if ((mode > 0) || (mode <= GM_LAST))
949 ret = dc->GraphicsMode;
950 dc->GraphicsMode = mode;
952 GDI_ReleaseObj( hdc );
953 return ret;
957 /***********************************************************************
958 * SetArcDirection (GDI32.@)
960 INT WINAPI SetArcDirection( HDC hdc, INT nDirection )
962 DC * dc;
963 INT nOldDirection = 0;
965 if (nDirection!=AD_COUNTERCLOCKWISE && nDirection!=AD_CLOCKWISE)
967 SetLastError(ERROR_INVALID_PARAMETER);
968 return 0;
971 if ((dc = DC_GetDCPtr( hdc )))
973 nOldDirection = dc->ArcDirection;
974 dc->ArcDirection = nDirection;
975 GDI_ReleaseObj( hdc );
977 return nOldDirection;
981 /***********************************************************************
982 * GetWorldTransform (GDI32.@)
984 BOOL WINAPI GetWorldTransform( HDC hdc, LPXFORM xform )
986 DC * dc;
987 if (!xform) return FALSE;
988 if (!(dc = DC_GetDCPtr( hdc ))) return FALSE;
989 *xform = dc->xformWorld2Wnd;
990 GDI_ReleaseObj( hdc );
991 return TRUE;
995 /***********************************************************************
996 * SetWorldTransform (GDI32.@)
998 BOOL WINAPI SetWorldTransform( HDC hdc, const XFORM *xform )
1000 BOOL ret = FALSE;
1001 DC *dc = DC_GetDCPtr( hdc );
1003 if (!dc) return FALSE;
1004 if (!xform) goto done;
1006 /* Check that graphics mode is GM_ADVANCED */
1007 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1009 dc->xformWorld2Wnd = *xform;
1010 DC_UpdateXforms( dc );
1011 ret = TRUE;
1012 done:
1013 GDI_ReleaseObj( hdc );
1014 return ret;
1018 /****************************************************************************
1019 * ModifyWorldTransform [GDI32.@]
1020 * Modifies the world transformation for a device context.
1022 * PARAMS
1023 * hdc [I] Handle to device context
1024 * xform [I] XFORM structure that will be used to modify the world
1025 * transformation
1026 * iMode [I] Specifies in what way to modify the world transformation
1027 * Possible values:
1028 * MWT_IDENTITY
1029 * Resets the world transformation to the identity matrix.
1030 * The parameter xform is ignored.
1031 * MWT_LEFTMULTIPLY
1032 * Multiplies xform into the world transformation matrix from
1033 * the left.
1034 * MWT_RIGHTMULTIPLY
1035 * Multiplies xform into the world transformation matrix from
1036 * the right.
1038 * RETURNS STD
1040 BOOL WINAPI ModifyWorldTransform( HDC hdc, const XFORM *xform,
1041 DWORD iMode )
1043 BOOL ret = FALSE;
1044 DC *dc = DC_GetDCPtr( hdc );
1046 /* Check for illegal parameters */
1047 if (!dc) return FALSE;
1048 if (!xform) goto done;
1050 /* Check that graphics mode is GM_ADVANCED */
1051 if (dc->GraphicsMode!=GM_ADVANCED) goto done;
1053 switch (iMode)
1055 case MWT_IDENTITY:
1056 dc->xformWorld2Wnd.eM11 = 1.0f;
1057 dc->xformWorld2Wnd.eM12 = 0.0f;
1058 dc->xformWorld2Wnd.eM21 = 0.0f;
1059 dc->xformWorld2Wnd.eM22 = 1.0f;
1060 dc->xformWorld2Wnd.eDx = 0.0f;
1061 dc->xformWorld2Wnd.eDy = 0.0f;
1062 break;
1063 case MWT_LEFTMULTIPLY:
1064 CombineTransform( &dc->xformWorld2Wnd, xform,
1065 &dc->xformWorld2Wnd );
1066 break;
1067 case MWT_RIGHTMULTIPLY:
1068 CombineTransform( &dc->xformWorld2Wnd, &dc->xformWorld2Wnd,
1069 xform );
1070 break;
1071 default:
1072 goto done;
1075 DC_UpdateXforms( dc );
1076 ret = TRUE;
1077 done:
1078 GDI_ReleaseObj( hdc );
1079 return ret;
1083 /****************************************************************************
1084 * CombineTransform [GDI32.@]
1085 * Combines two transformation matrices.
1087 * PARAMS
1088 * xformResult [O] Stores the result of combining the two matrices
1089 * xform1 [I] Specifies the first matrix to apply
1090 * xform2 [I] Specifies the second matrix to apply
1092 * REMARKS
1093 * The same matrix can be passed in for more than one of the parameters.
1095 * RETURNS STD
1097 BOOL WINAPI CombineTransform( LPXFORM xformResult, const XFORM *xform1,
1098 const XFORM *xform2 )
1100 XFORM xformTemp;
1102 /* Check for illegal parameters */
1103 if (!xformResult || !xform1 || !xform2)
1104 return FALSE;
1106 /* Create the result in a temporary XFORM, since xformResult may be
1107 * equal to xform1 or xform2 */
1108 xformTemp.eM11 = xform1->eM11 * xform2->eM11 +
1109 xform1->eM12 * xform2->eM21;
1110 xformTemp.eM12 = xform1->eM11 * xform2->eM12 +
1111 xform1->eM12 * xform2->eM22;
1112 xformTemp.eM21 = xform1->eM21 * xform2->eM11 +
1113 xform1->eM22 * xform2->eM21;
1114 xformTemp.eM22 = xform1->eM21 * xform2->eM12 +
1115 xform1->eM22 * xform2->eM22;
1116 xformTemp.eDx = xform1->eDx * xform2->eM11 +
1117 xform1->eDy * xform2->eM21 +
1118 xform2->eDx;
1119 xformTemp.eDy = xform1->eDx * xform2->eM12 +
1120 xform1->eDy * xform2->eM22 +
1121 xform2->eDy;
1123 /* Copy the result to xformResult */
1124 *xformResult = xformTemp;
1126 return TRUE;
1130 /***********************************************************************
1131 * SetDCHook (GDI32.@)
1133 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1135 BOOL WINAPI SetDCHook( HDC hdc, DCHOOKPROC hookProc, DWORD dwHookData )
1137 DC *dc = DC_GetDCPtr( hdc );
1139 if (!dc) return FALSE;
1140 dc->dwHookData = dwHookData;
1141 dc->hookThunk = hookProc;
1142 GDI_ReleaseObj( hdc );
1143 return TRUE;
1147 /* relay function to call the 16-bit DC hook proc */
1148 static BOOL16 WINAPI call_dc_hook16( HDC16 hdc16, WORD code, DWORD data, LPARAM lParam )
1150 FARPROC16 proc = NULL;
1151 HDC hdc = HDC_32( hdc16 );
1152 DC *dc = DC_GetDCPtr( hdc );
1153 if (!dc) return FALSE;
1154 proc = dc->hookProc;
1155 GDI_ReleaseObj( hdc );
1156 if (!proc) return FALSE;
1157 return GDI_CallTo16_word_wwll( proc, hdc16, code, data, lParam );
1160 /***********************************************************************
1161 * SetDCHook (GDI.190)
1163 BOOL16 WINAPI SetDCHook16( HDC16 hdc16, FARPROC16 hookProc, DWORD dwHookData )
1165 HDC hdc = HDC_32( hdc16 );
1166 DC *dc = DC_GetDCPtr( hdc );
1167 if (!dc) return FALSE;
1169 dc->hookProc = hookProc;
1170 GDI_ReleaseObj( hdc );
1171 return SetDCHook( hdc, call_dc_hook16, dwHookData );
1175 /***********************************************************************
1176 * GetDCHook (GDI.191)
1178 DWORD WINAPI GetDCHook16( HDC16 hdc16, FARPROC16 *phookProc )
1180 HDC hdc = HDC_32( hdc16 );
1181 DC *dc = DC_GetDCPtr( hdc );
1182 DWORD ret;
1184 if (!dc) return 0;
1185 *phookProc = dc->hookProc;
1186 ret = dc->dwHookData;
1187 GDI_ReleaseObj( hdc );
1188 return ret;
1192 /***********************************************************************
1193 * SetHookFlags (GDI.192)
1195 WORD WINAPI SetHookFlags16(HDC16 hdc16, WORD flags)
1197 HDC hdc = HDC_32( hdc16 );
1198 DC *dc = DC_GetDCPtr( hdc );
1200 if( dc )
1202 WORD wRet = dc->flags & DC_DIRTY;
1204 /* "Undocumented Windows" info is slightly confusing.
1207 TRACE("hDC %p, flags %04x\n",hdc,flags);
1209 if( flags & DCHF_INVALIDATEVISRGN )
1210 dc->flags |= DC_DIRTY;
1211 else if( flags & DCHF_VALIDATEVISRGN || !flags )
1212 dc->flags &= ~DC_DIRTY;
1213 GDI_ReleaseObj( hdc );
1214 return wRet;
1216 return 0;
1219 /***********************************************************************
1220 * SetICMMode (GDI32.@)
1222 INT WINAPI SetICMMode(HDC hdc, INT iEnableICM)
1224 /*FIXME Asuming that ICM is always off, and cannot be turned on */
1225 if (iEnableICM == ICM_OFF) return ICM_OFF;
1226 if (iEnableICM == ICM_ON) return 0;
1227 if (iEnableICM == ICM_QUERY) return ICM_OFF;
1228 return 0;
1231 /***********************************************************************
1232 * GetDeviceGammaRamp (GDI32.@)
1234 BOOL WINAPI GetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1236 BOOL ret = FALSE;
1237 DC *dc = DC_GetDCPtr( hDC );
1239 if( dc )
1241 if (dc->funcs->pGetDeviceGammaRamp)
1242 ret = dc->funcs->pGetDeviceGammaRamp(dc->physDev, ptr);
1243 GDI_ReleaseObj( hDC );
1245 return ret;
1248 /***********************************************************************
1249 * SetDeviceGammaRamp (GDI32.@)
1251 BOOL WINAPI SetDeviceGammaRamp(HDC hDC, LPVOID ptr)
1253 BOOL ret = FALSE;
1254 DC *dc = DC_GetDCPtr( hDC );
1256 if( dc )
1258 if (dc->funcs->pSetDeviceGammaRamp)
1259 ret = dc->funcs->pSetDeviceGammaRamp(dc->physDev, ptr);
1260 GDI_ReleaseObj( hDC );
1262 return ret;
1265 /***********************************************************************
1266 * GetColorSpace (GDI32.@)
1268 HCOLORSPACE WINAPI GetColorSpace(HDC hdc)
1270 /*FIXME Need to to whatever GetColorSpace actually does */
1271 return 0;
1274 /***********************************************************************
1275 * CreateColorSpaceA (GDI32.@)
1277 HCOLORSPACE WINAPI CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace )
1279 FIXME( "stub\n" );
1280 return 0;
1283 /***********************************************************************
1284 * CreateColorSpaceW (GDI32.@)
1286 HCOLORSPACE WINAPI CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace )
1288 FIXME( "stub\n" );
1289 return 0;
1292 /***********************************************************************
1293 * DeleteColorSpace (GDI32.@)
1295 BOOL WINAPI DeleteColorSpace( HCOLORSPACE hColorSpace )
1297 FIXME( "stub\n" );
1299 return TRUE;
1302 /***********************************************************************
1303 * SetColorSpace (GDI32.@)
1305 HCOLORSPACE WINAPI SetColorSpace( HDC hDC, HCOLORSPACE hColorSpace )
1307 FIXME( "stub\n" );
1309 return hColorSpace;
1312 /***********************************************************************
1313 * GetBoundsRect (GDI.194)
1315 UINT16 WINAPI GetBoundsRect16(HDC16 hdc, LPRECT16 rect, UINT16 flags)
1317 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1320 /***********************************************************************
1321 * GetBoundsRect (GDI32.@)
1323 UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
1325 FIXME("(): stub\n");
1326 return DCB_RESET; /* bounding rectangle always empty */
1329 /***********************************************************************
1330 * SetBoundsRect (GDI.193)
1332 UINT16 WINAPI SetBoundsRect16(HDC16 hdc, const RECT16* rect, UINT16 flags)
1334 if ( (flags & DCB_ACCUMULATE) || (flags & DCB_ENABLE) )
1335 FIXME("(%04x, %p, %04x): stub\n", hdc, rect, flags );
1337 return DCB_RESET | DCB_DISABLE; /* bounding rectangle always empty and disabled*/
1340 /***********************************************************************
1341 * SetBoundsRect (GDI32.@)
1343 UINT WINAPI SetBoundsRect(HDC hdc, const RECT* rect, UINT flags)
1345 FIXME("(): stub\n");
1346 return DCB_DISABLE; /* bounding rectangle always empty */
1350 /***********************************************************************
1351 * GetRelAbs (GDI32.@)
1353 INT WINAPI GetRelAbs( HDC hdc, DWORD dwIgnore )
1355 INT ret = 0;
1356 DC *dc = DC_GetDCPtr( hdc );
1357 if (dc) ret = dc->relAbsMode;
1358 GDI_ReleaseObj( hdc );
1359 return ret;
1362 /***********************************************************************
1363 * GetLayout (GDI32.@)
1365 * Gets left->right or right->left text layout flags of a dc.
1366 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1369 DWORD WINAPI GetLayout(HDC hdc)
1371 FIXME("(%p): stub\n", hdc);
1372 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1373 return 0;
1376 /***********************************************************************
1377 * SetLayout (GDI32.@)
1379 * Sets left->right or right->left text layout flags of a dc.
1380 * win98 just returns 0 and sets ERROR_CALL_NOT_IMPLEMENTED so we do the same
1383 DWORD WINAPI SetLayout(HDC hdc, DWORD layout)
1385 FIXME("(%p,%08lx): stub\n", hdc, layout);
1386 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1387 return 0;
1390 /***********************************************************************
1391 * SetDCBrushColor (GDI32.@)
1393 * Sets the current device context (DC) brush color to the specified
1394 * color value. If the device cannot represent the specified color
1395 * value, the color is set to the nearest physical color.
1398 COLORREF WINAPI SetDCBrushColor(HDC hdc, COLORREF crColor)
1400 FIXME("(%p, %08lx): stub\n", hdc, crColor);
1401 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1402 return CLR_INVALID;