2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
18 extern void CLIPPING_UpdateGCRegion( DC
* dc
); /* objects/clipping.c */
20 /* Default DC values */
21 static const WIN_DC_INFO DC_defaultValues
=
28 STOCK_BLACK_PEN
, /* hPen */
29 STOCK_WHITE_BRUSH
, /* hBrush */
30 STOCK_SYSTEM_FONT
, /* hFont */
34 STOCK_DEFAULT_PALETTE
, /* hPalette */
35 R2_COPYPEN
, /* ROPmode */
36 ALTERNATE
, /* polyFillMode */
37 BLACKONWHITE
, /* stretchBltMode */
38 ABSOLUTE
, /* relAbsMode */
39 OPAQUE
, /* backgroundMode */
40 RGB( 255, 255, 255 ), /* backgroundColor */
41 RGB( 0, 0, 0 ), /* textColor */
42 0, /* backgroundPixel */
46 TA_LEFT
| TA_TOP
| TA_NOUPDATECP
, /* textAlign */
48 0, /* breakTotalExtra */
53 MM_TEXT
, /* MapMode */
60 /* ROP code to GC function conversion */
61 const int DC_XROPfunction
[16] =
63 GXclear
, /* R2_BLACK */
64 GXnor
, /* R2_NOTMERGEPEN */
65 GXandInverted
, /* R2_MASKNOTPEN */
66 GXcopyInverted
, /* R2_NOTCOPYPEN */
67 GXandReverse
, /* R2_MASKPENNOT */
68 GXinvert
, /* R2_NOT */
69 GXxor
, /* R2_XORPEN */
70 GXnand
, /* R2_NOTMASKPEN */
71 GXand
, /* R2_MASKPEN */
72 GXequiv
, /* R2_NOTXORPEN */
74 GXorInverted
, /* R2_MERGENOTPEN */
75 GXcopy
, /* R2_COPYPEN */
76 GXorReverse
, /* R2_MERGEPENNOT */
77 GXor
, /* R2_MERGEPEN */
82 /***********************************************************************
85 * Fill the device caps structure.
87 void DC_FillDevCaps( DeviceCaps
* caps
)
89 caps
->version
= 0x300;
90 caps
->technology
= DT_RASDISPLAY
;
91 caps
->horzSize
= WidthMMOfScreen(screen
) * screenWidth
/ WidthOfScreen(screen
);
92 caps
->vertSize
= HeightMMOfScreen(screen
) * screenHeight
/ HeightOfScreen(screen
);
93 caps
->horzRes
= screenWidth
;
94 caps
->vertRes
= screenHeight
;
95 caps
->bitsPixel
= screenDepth
;
97 caps
->numBrushes
= 16+6; /* 16 solid + 6 hatched brushes */
98 caps
->numPens
= 16; /* 16 solid pens */
101 caps
->numColors
= 100;
102 caps
->pdeviceSize
= 0;
103 caps
->curveCaps
= CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
|
104 CC_WIDE
| CC_STYLED
| CC_WIDESTYLED
|
105 CC_INTERIORS
| CC_ROUNDRECT
;
106 caps
->lineCaps
= LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
107 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
;
108 caps
->polygonalCaps
= PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
|
109 PC_SCANLINE
| PC_WIDE
| PC_STYLED
|
110 PC_WIDESTYLED
| PC_INTERIORS
;
111 caps
->textCaps
= TC_OP_CHARACTER
| TC_OP_STROKE
| TC_CP_STROKE
|
112 TC_IA_ABLE
| TC_UA_ABLE
| TC_SO_ABLE
| TC_RA_ABLE
;
113 caps
->clipCaps
= CP_REGION
;
114 caps
->rasterCaps
= RC_BITBLT
| RC_BANDING
| RC_SCALING
| RC_BITMAP64
|
115 RC_DI_BITMAP
| RC_DIBTODEV
| RC_BIGFONT
|
116 RC_STRETCHBLT
| RC_STRETCHDIB
| RC_DEVBITS
;
118 if( !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL
) )
119 caps
->rasterCaps
|= RC_PALETTE
;
121 caps
->aspectX
= 36; /* ?? */
122 caps
->aspectY
= 36; /* ?? */
124 caps
->logPixelsX
= (int)(caps
->horzRes
* 25.4 / caps
->horzSize
);
125 caps
->logPixelsY
= (int)(caps
->vertRes
* 25.4 / caps
->vertSize
);
126 caps
->sizePalette
= (caps
->rasterCaps
& RC_PALETTE
)
127 ? DefaultVisual(display
,DefaultScreen(display
))->map_entries
129 caps
->numReserved
= 0;
134 /***********************************************************************
137 DC
*DC_AllocDC( const DC_FUNCTIONS
*funcs
)
142 if (!(hdc
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
))) return NULL
;
143 dc
= (DC
*) GDI_HEAP_LIN_ADDR( hdc
);
160 memcpy( &dc
->w
, &DC_defaultValues
, sizeof(DC_defaultValues
) );
165 /***********************************************************************
168 DC
*DC_GetDCPtr( HDC32 hdc
)
170 GDIOBJHDR
*ptr
= (GDIOBJHDR
*)GDI_HEAP_LIN_ADDR( hdc
);
171 if (!ptr
) return NULL
;
172 if ((ptr
->wMagic
== DC_MAGIC
) || (ptr
->wMagic
== METAFILE_DC_MAGIC
))
178 /***********************************************************************
181 * Setup device-specific DC values for a newly created DC.
183 void DC_InitDC( DC
* dc
)
185 RealizeDefaultPalette( dc
->hSelf
);
186 SetTextColor32( dc
->hSelf
, dc
->w
.textColor
);
187 SetBkColor32( dc
->hSelf
, dc
->w
.backgroundColor
);
188 SelectObject32( dc
->hSelf
, dc
->w
.hPen
);
189 SelectObject32( dc
->hSelf
, dc
->w
.hBrush
);
190 SelectObject32( dc
->hSelf
, dc
->w
.hFont
);
191 CLIPPING_UpdateGCRegion( dc
);
195 /***********************************************************************
196 * DC_SetupGCForPatBlt
198 * Setup the GC for a PatBlt operation using current brush.
199 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
200 * Return FALSE if brush is BS_NULL, TRUE otherwise.
202 BOOL32
DC_SetupGCForPatBlt( DC
* dc
, GC gc
, BOOL32 fMapColors
)
208 if (dc
->u
.x
.brush
.style
== BS_NULL
) return FALSE
;
209 if (dc
->u
.x
.brush
.pixel
== -1)
211 /* Special case used for monochrome pattern brushes.
212 * We need to swap foreground and background because
213 * Windows does it the wrong way...
215 val
.foreground
= dc
->w
.backgroundPixel
;
216 val
.background
= dc
->w
.textPixel
;
220 val
.foreground
= dc
->u
.x
.brush
.pixel
;
221 val
.background
= dc
->w
.backgroundPixel
;
223 if (fMapColors
&& COLOR_PixelToPalette
)
225 val
.foreground
= COLOR_PixelToPalette
[val
.foreground
];
226 val
.background
= COLOR_PixelToPalette
[val
.background
];
229 if (dc
->w
.flags
& DC_DIRTY
) CLIPPING_UpdateGCRegion(dc
);
231 val
.function
= DC_XROPfunction
[dc
->w
.ROPmode
-1];
232 val
.fill_style
= dc
->u
.x
.brush
.fillStyle
;
233 switch(val
.fill_style
)
236 case FillOpaqueStippled
:
237 if (dc
->w
.backgroundMode
==OPAQUE
) val
.fill_style
= FillOpaqueStippled
;
238 val
.stipple
= dc
->u
.x
.brush
.pixmap
;
243 if (fMapColors
&& COLOR_PixelToPalette
)
247 pixmap
= XCreatePixmap( display
, rootWindow
, 8, 8, screenDepth
);
248 image
= XGetImage( display
, dc
->u
.x
.brush
.pixmap
, 0, 0, 8, 8,
249 AllPlanes
, ZPixmap
);
250 for (y
= 0; y
< 8; y
++)
251 for (x
= 0; x
< 8; x
++)
252 XPutPixel( image
, x
, y
,
253 COLOR_PixelToPalette
[XGetPixel( image
, x
, y
)] );
254 XPutImage( display
, pixmap
, gc
, image
, 0, 0, 0, 0, 8, 8 );
255 XDestroyImage( image
);
258 else val
.tile
= dc
->u
.x
.brush
.pixmap
;
266 val
.ts_x_origin
= dc
->w
.DCOrgX
+ dc
->w
.brushOrgX
;
267 val
.ts_y_origin
= dc
->w
.DCOrgY
+ dc
->w
.brushOrgY
;
268 val
.fill_rule
= (dc
->w
.polyFillMode
==WINDING
) ? WindingRule
: EvenOddRule
;
269 XChangeGC( display
, gc
,
270 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
271 GCFillRule
| GCTileStipXOrigin
| GCTileStipYOrigin
| mask
,
273 if (pixmap
) XFreePixmap( display
, pixmap
);
278 /***********************************************************************
281 * Setup dc->u.x.gc for drawing operations using current brush.
282 * Return FALSE if brush is BS_NULL, TRUE otherwise.
284 BOOL32
DC_SetupGCForBrush( DC
* dc
)
286 return DC_SetupGCForPatBlt( dc
, dc
->u
.x
.gc
, FALSE
);
290 /***********************************************************************
293 * Setup dc->u.x.gc for drawing operations using current pen.
294 * Return FALSE if pen is PS_NULL, TRUE otherwise.
296 BOOL32
DC_SetupGCForPen( DC
* dc
)
300 if (dc
->u
.x
.pen
.style
== PS_NULL
) return FALSE
;
302 if (dc
->w
.flags
& DC_DIRTY
) CLIPPING_UpdateGCRegion(dc
);
304 if ((screenDepth
<= 8) && /* FIXME: Should check for palette instead */
305 ((dc
->w
.ROPmode
== R2_BLACK
) || (dc
->w
.ROPmode
== R2_WHITE
)))
307 val
.function
= GXcopy
;
308 val
.foreground
= COLOR_ToPhysical( NULL
, (dc
->w
.ROPmode
== R2_BLACK
) ?
309 RGB(0,0,0) : RGB(255,255,255) );
313 val
.function
= DC_XROPfunction
[dc
->w
.ROPmode
-1];
314 val
.foreground
= dc
->u
.x
.pen
.pixel
;
316 val
.background
= dc
->w
.backgroundPixel
;
317 val
.fill_style
= FillSolid
;
318 if ((dc
->u
.x
.pen
.style
!=PS_SOLID
) && (dc
->u
.x
.pen
.style
!=PS_INSIDEFRAME
))
320 XSetDashes( display
, dc
->u
.x
.gc
, 0,
321 dc
->u
.x
.pen
.dashes
, dc
->u
.x
.pen
.dash_len
);
322 val
.line_style
= (dc
->w
.backgroundMode
== OPAQUE
) ?
323 LineDoubleDash
: LineOnOffDash
;
325 else val
.line_style
= LineSolid
;
326 val
.line_width
= dc
->u
.x
.pen
.width
;
327 val
.cap_style
= CapRound
;
328 val
.join_style
= JoinMiter
;
329 XChangeGC( display
, dc
->u
.x
.gc
,
330 GCFunction
| GCForeground
| GCBackground
| GCLineWidth
|
331 GCLineStyle
| GCCapStyle
| GCJoinStyle
| GCFillStyle
, &val
);
336 /***********************************************************************
339 * Setup dc->u.x.gc for text drawing operations.
340 * Return FALSE if the font is null, TRUE otherwise.
342 BOOL32
DC_SetupGCForText( DC
* dc
)
346 if (!dc
->u
.x
.font
.fstruct
)
348 fprintf( stderr
, "DC_SetupGCForText: fstruct is NULL. Please report this\n" );
352 if (dc
->w
.flags
& DC_DIRTY
) CLIPPING_UpdateGCRegion(dc
);
354 val
.function
= GXcopy
; /* Text is always GXcopy */
355 val
.foreground
= dc
->w
.textPixel
;
356 val
.background
= dc
->w
.backgroundPixel
;
357 val
.fill_style
= FillSolid
;
358 val
.font
= dc
->u
.x
.font
.fstruct
->fid
;
359 XChangeGC( display
, dc
->u
.x
.gc
,
360 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
366 /***********************************************************************
367 * GetDCState (GDI.179)
369 HDC16
GetDCState( HDC16 hdc
)
374 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
375 if (!(handle
= GDI_AllocObject( sizeof(DC
), DC_MAGIC
))) return 0;
376 newdc
= (DC
*) GDI_HEAP_LIN_ADDR( handle
);
378 dprintf_dc(stddeb
, "GetDCState(%04x): returning %04x\n", hdc
, handle
);
380 memset( &newdc
->u
.x
, 0, sizeof(newdc
->u
.x
) );
381 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
382 newdc
->w
.devCaps
= dc
->w
.devCaps
;
383 newdc
->w
.hPen
= dc
->w
.hPen
;
384 newdc
->w
.hBrush
= dc
->w
.hBrush
;
385 newdc
->w
.hFont
= dc
->w
.hFont
;
386 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
387 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
388 newdc
->w
.hDevice
= dc
->w
.hDevice
;
389 newdc
->w
.hPalette
= dc
->w
.hPalette
;
390 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
391 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
392 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
393 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
394 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
395 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
396 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
397 newdc
->w
.textColor
= dc
->w
.textColor
;
398 newdc
->w
.backgroundPixel
= dc
->w
.backgroundPixel
;
399 newdc
->w
.textPixel
= dc
->w
.textPixel
;
400 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
401 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
402 newdc
->w
.textAlign
= dc
->w
.textAlign
;
403 newdc
->w
.charExtra
= dc
->w
.charExtra
;
404 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
405 newdc
->w
.breakCount
= dc
->w
.breakCount
;
406 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
407 newdc
->w
.breakRem
= dc
->w
.breakRem
;
408 newdc
->w
.MapMode
= dc
->w
.MapMode
;
409 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
410 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
411 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
412 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
413 newdc
->wndOrgX
= dc
->wndOrgX
;
414 newdc
->wndOrgY
= dc
->wndOrgY
;
415 newdc
->wndExtX
= dc
->wndExtX
;
416 newdc
->wndExtY
= dc
->wndExtY
;
417 newdc
->vportOrgX
= dc
->vportOrgX
;
418 newdc
->vportOrgY
= dc
->vportOrgY
;
419 newdc
->vportExtX
= dc
->vportExtX
;
420 newdc
->vportExtY
= dc
->vportExtY
;
422 newdc
->hSelf
= (HDC32
)handle
;
423 newdc
->saveLevel
= 0;
425 newdc
->w
.hGCClipRgn
= 0;
426 newdc
->w
.hVisRgn
= CreateRectRgn32( 0, 0, 0, 0 );
427 CombineRgn32( newdc
->w
.hVisRgn
, dc
->w
.hVisRgn
, 0, RGN_COPY
);
430 newdc
->w
.hClipRgn
= CreateRectRgn32( 0, 0, 0, 0 );
431 CombineRgn32( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
434 newdc
->w
.hClipRgn
= 0;
439 /***********************************************************************
440 * SetDCState (GDI.180)
442 void SetDCState( HDC16 hdc
, HDC16 hdcs
)
446 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return;
447 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) return;
448 if (!dcs
->w
.flags
& DC_SAVED
) return;
449 dprintf_dc(stddeb
, "SetDCState: %04x %04x\n", hdc
, hdcs
);
451 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
452 dc
->w
.devCaps
= dcs
->w
.devCaps
;
453 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
454 dc
->w
.hDevice
= dcs
->w
.hDevice
;
455 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
456 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
457 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
458 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
459 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
460 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
461 dc
->w
.textColor
= dcs
->w
.textColor
;
462 dc
->w
.backgroundPixel
= dcs
->w
.backgroundPixel
;
463 dc
->w
.textPixel
= dcs
->w
.textPixel
;
464 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
465 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
466 dc
->w
.textAlign
= dcs
->w
.textAlign
;
467 dc
->w
.charExtra
= dcs
->w
.charExtra
;
468 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
469 dc
->w
.breakCount
= dcs
->w
.breakCount
;
470 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
471 dc
->w
.breakRem
= dcs
->w
.breakRem
;
472 dc
->w
.MapMode
= dcs
->w
.MapMode
;
473 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
474 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
475 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
476 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
478 dc
->wndOrgX
= dcs
->wndOrgX
;
479 dc
->wndOrgY
= dcs
->wndOrgY
;
480 dc
->wndExtX
= dcs
->wndExtX
;
481 dc
->wndExtY
= dcs
->wndExtY
;
482 dc
->vportOrgX
= dcs
->vportOrgX
;
483 dc
->vportOrgY
= dcs
->vportOrgY
;
484 dc
->vportExtX
= dcs
->vportExtX
;
485 dc
->vportExtY
= dcs
->vportExtY
;
487 if (!(dc
->w
.flags
& DC_MEMORY
)) dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
488 CombineRgn32( dc
->w
.hVisRgn
, dcs
->w
.hVisRgn
, 0, RGN_COPY
);
489 SelectClipRgn32( hdc
, dcs
->w
.hClipRgn
);
490 SelectObject32( hdc
, dcs
->w
.hBitmap
);
491 SelectObject32( hdc
, dcs
->w
.hBrush
);
492 SelectObject32( hdc
, dcs
->w
.hFont
);
493 SelectObject32( hdc
, dcs
->w
.hPen
);
494 GDISelectPalette( hdc
, dcs
->w
.hPalette
, FALSE
);
498 /***********************************************************************
501 INT16
SaveDC16( HDC16 hdc
)
503 return (INT16
)SaveDC32( hdc
);
507 /***********************************************************************
508 * SaveDC32 (GDI32.292)
510 INT32
SaveDC32( HDC32 hdc
)
515 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
518 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
520 MF_MetaParam0(dc
, META_SAVEDC
);
523 if (!(hdcs
= GetDCState( hdc
))) return 0;
524 dcs
= (DC
*) GDI_HEAP_LIN_ADDR( hdcs
);
525 dcs
->header
.hNext
= dc
->header
.hNext
;
526 dc
->header
.hNext
= hdcs
;
527 dprintf_dc(stddeb
, "SaveDC(%04x): returning %d\n", hdc
, dc
->saveLevel
+1 );
528 return ++dc
->saveLevel
;
532 /***********************************************************************
533 * RestoreDC16 (GDI.39)
535 BOOL16
RestoreDC16( HDC16 hdc
, INT16 level
)
537 return RestoreDC32( hdc
, level
);
541 /***********************************************************************
542 * RestoreDC32 (GDI32.290)
544 BOOL32
RestoreDC32( HDC32 hdc
, INT32 level
)
548 dprintf_dc(stddeb
, "RestoreDC: %04x %d\n", hdc
, level
);
549 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
552 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
553 if (!dc
) return FALSE
;
554 if (level
!= -1) return FALSE
;
555 MF_MetaParam1(dc
, META_RESTOREDC
, level
);
558 if (level
== -1) level
= dc
->saveLevel
;
559 if ((level
< 1) || (level
> dc
->saveLevel
)) return FALSE
;
561 while (dc
->saveLevel
>= level
)
563 HDC16 hdcs
= dc
->header
.hNext
;
564 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) return FALSE
;
565 dc
->header
.hNext
= dcs
->header
.hNext
;
566 if (--dc
->saveLevel
< level
) SetDCState( hdc
, hdcs
);
573 /***********************************************************************
574 * CreateDC16 (GDI.53)
576 HDC16
CreateDC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
577 const DEVMODE16
*initData
)
580 const DC_FUNCTIONS
*funcs
;
582 if (!(funcs
= DRIVER_FindDriver( driver
))) return 0;
583 if (!(dc
= DC_AllocDC( funcs
))) return 0;
586 dprintf_dc(stddeb
, "CreateDC(%s %s %s): returning %04x\n",
587 driver
, device
, output
, dc
->hSelf
);
589 if (dc
->funcs
->pCreateDC
&&
590 !dc
->funcs
->pCreateDC( dc
, driver
, device
, output
, initData
))
592 dprintf_dc( stddeb
, "CreateDC: creation aborted by device\n" );
593 GDI_HEAP_FREE( dc
->hSelf
);
602 /***********************************************************************
603 * CreateDC32A (GDI32.)
605 HDC32
CreateDC32A( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
606 const DEVMODE32A
*initData
)
608 return CreateDC16( driver
, device
, output
, (const DEVMODE16
*)initData
);
612 /***********************************************************************
613 * CreateDC32W (GDI32.)
615 HDC32
CreateDC32W( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
616 const DEVMODE32W
*initData
)
618 LPSTR driverA
= HEAP_strdupWtoA( GetProcessHeap(), 0, driver
);
619 LPSTR deviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, device
);
620 LPSTR outputA
= HEAP_strdupWtoA( GetProcessHeap(), 0, output
);
621 HDC32 res
= CreateDC16( driverA
, deviceA
, outputA
,
622 (const DEVMODE16
*)initData
/*FIXME*/ );
623 HeapFree( GetProcessHeap(), 0, driverA
);
624 HeapFree( GetProcessHeap(), 0, deviceA
);
625 HeapFree( GetProcessHeap(), 0, outputA
);
630 /***********************************************************************
631 * CreateIC16 (GDI.153)
633 HDC16
CreateIC16( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
634 const DEVMODE16
* initData
)
636 /* Nothing special yet for ICs */
637 return CreateDC16( driver
, device
, output
, initData
);
641 /***********************************************************************
642 * CreateIC32A (GDI32.49)
644 HDC32
CreateIC32A( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
645 const DEVMODE32A
* initData
)
647 /* Nothing special yet for ICs */
648 return CreateDC32A( driver
, device
, output
, initData
);
652 /***********************************************************************
653 * CreateIC32W (GDI32.50)
655 HDC32
CreateIC32W( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
656 const DEVMODE32W
* initData
)
658 /* Nothing special yet for ICs */
659 return CreateDC32W( driver
, device
, output
, initData
);
663 /***********************************************************************
664 * CreateCompatibleDC16 (GDI.52)
666 HDC16
CreateCompatibleDC16( HDC16 hdc
)
668 return (HDC16
)CreateCompatibleDC32( hdc
);
672 /***********************************************************************
673 * CreateCompatibleDC32 (GDI32.31)
675 HDC32
CreateCompatibleDC32( HDC32 hdc
)
679 const DC_FUNCTIONS
*funcs
;
681 if ((origDC
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
))) funcs
= origDC
->funcs
;
682 else funcs
= DRIVER_FindDriver( "DISPLAY" );
683 if (!funcs
) return 0;
685 if (!(dc
= DC_AllocDC( funcs
))) return 0;
687 dprintf_dc(stddeb
, "CreateCompatibleDC(%04x): returning %04x\n",
690 /* Create default bitmap */
691 if (!(hbitmap
= CreateBitmap32( 1, 1, 1, 1, NULL
)))
693 GDI_HEAP_FREE( dc
->hSelf
);
696 dc
->w
.flags
= DC_MEMORY
;
697 dc
->w
.bitsPerPixel
= 1;
698 dc
->w
.hBitmap
= hbitmap
;
699 dc
->w
.hFirstBitmap
= hbitmap
;
701 if (dc
->funcs
->pCreateDC
&&
702 !dc
->funcs
->pCreateDC( dc
, NULL
, NULL
, NULL
, NULL
))
704 dprintf_dc(stddeb
, "CreateCompatibleDC: creation aborted by device\n");
705 DeleteObject32( hbitmap
);
706 GDI_HEAP_FREE( dc
->hSelf
);
715 /***********************************************************************
716 * DeleteDC16 (GDI.68)
718 BOOL16
DeleteDC16( HDC16 hdc
)
720 return DeleteDC32( hdc
);
724 /***********************************************************************
725 * DeleteDC32 (GDI32.67)
727 BOOL32
DeleteDC32( HDC32 hdc
)
729 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
730 if (!dc
) return FALSE
;
732 dprintf_dc(stddeb
, "DeleteDC: %04x\n", hdc
);
734 while (dc
->saveLevel
)
737 HDC16 hdcs
= dc
->header
.hNext
;
738 if (!(dcs
= (DC
*) GDI_GetObjPtr( hdcs
, DC_MAGIC
))) break;
739 dc
->header
.hNext
= dcs
->header
.hNext
;
744 if (!(dc
->w
.flags
& DC_SAVED
))
746 SelectObject32( hdc
, STOCK_BLACK_PEN
);
747 SelectObject32( hdc
, STOCK_WHITE_BRUSH
);
748 SelectObject32( hdc
, STOCK_SYSTEM_FONT
);
749 if (dc
->w
.flags
& DC_MEMORY
) DeleteObject32( dc
->w
.hFirstBitmap
);
750 if (dc
->funcs
->pDeleteDC
) dc
->funcs
->pDeleteDC(dc
);
753 if (dc
->w
.hClipRgn
) DeleteObject32( dc
->w
.hClipRgn
);
754 if (dc
->w
.hVisRgn
) DeleteObject32( dc
->w
.hVisRgn
);
755 if (dc
->w
.hGCClipRgn
) DeleteObject32( dc
->w
.hGCClipRgn
);
757 return GDI_FreeObject( hdc
);
761 /***********************************************************************
762 * ResetDC16 (GDI.376)
764 HDC16
ResetDC16( HDC16 hdc
, const DEVMODE16
*devmode
)
766 fprintf( stderr
, "ResetDC16: empty stub!\n" );
771 /***********************************************************************
772 * ResetDC32A (GDI32.287)
774 HDC32
ResetDC32A( HDC32 hdc
, const DEVMODE32A
*devmode
)
776 fprintf( stderr
, "ResetDC32A: empty stub!\n" );
781 /***********************************************************************
782 * ResetDC32W (GDI32.288)
784 HDC32
ResetDC32W( HDC32 hdc
, const DEVMODE32W
*devmode
)
786 fprintf( stderr
, "ResetDC32A: empty stub!\n" );
791 /***********************************************************************
792 * GetDeviceCaps16 (GDI.80)
794 INT16
GetDeviceCaps16( HDC16 hdc
, INT16 cap
)
796 return GetDeviceCaps32( hdc
, cap
);
800 /***********************************************************************
801 * GetDeviceCaps32 (GDI32.171)
803 INT32
GetDeviceCaps32( HDC32 hdc
, INT32 cap
)
805 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
808 if ((cap
< 0) || (cap
> sizeof(DeviceCaps
)-sizeof(WORD
))) return 0;
810 dprintf_dc(stddeb
, "GetDeviceCaps(%04x,%d): returning %d\n",
811 hdc
, cap
, *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
) );
812 return *(WORD
*)(((char *)dc
->w
.devCaps
) + cap
);
816 /***********************************************************************
817 * SetBkColor16 (GDI.1)
819 COLORREF
SetBkColor16( HDC16 hdc
, COLORREF color
)
821 return SetBkColor32( hdc
, color
);
825 /***********************************************************************
826 * SetBkColor32 (GDI32.305)
828 COLORREF
SetBkColor32( HDC32 hdc
, COLORREF color
)
831 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
834 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
835 if (!dc
) return 0x80000000;
836 MF_MetaParam2(dc
, META_SETBKCOLOR
, HIWORD(color
), LOWORD(color
));
840 oldColor
= dc
->w
.backgroundColor
;
841 dc
->w
.backgroundColor
= color
;
842 dc
->w
.backgroundPixel
= COLOR_ToPhysical( dc
, color
);
847 /***********************************************************************
848 * SetTextColor16 (GDI.9)
850 COLORREF
SetTextColor16( HDC16 hdc
, COLORREF color
)
852 return SetTextColor32( hdc
, color
);
856 /***********************************************************************
857 * SetTextColor32 (GDI32.338)
859 COLORREF
SetTextColor32( HDC32 hdc
, COLORREF color
)
862 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
865 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
866 if (!dc
) return 0x80000000;
867 MF_MetaParam2(dc
, META_SETTEXTCOLOR
, HIWORD(color
), LOWORD(color
));
871 oldColor
= dc
->w
.textColor
;
872 dc
->w
.textColor
= color
;
873 dc
->w
.textPixel
= COLOR_ToPhysical( dc
, color
);
878 /***********************************************************************
879 * SetTextAlign16 (GDI.346)
881 UINT16
SetTextAlign16( HDC16 hdc
, UINT16 textAlign
)
883 return SetTextAlign32( hdc
, textAlign
);
887 /***********************************************************************
888 * SetTextAlign32 (GDI32.336)
890 UINT32
SetTextAlign32( HDC32 hdc
, UINT32 textAlign
)
893 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
896 if (!(dc
= (DC
*)GDI_GetObjPtr( hdc
, METAFILE_DC_MAGIC
))) return 0;
897 MF_MetaParam1( dc
, META_SETTEXTALIGN
, textAlign
);
900 prevAlign
= dc
->w
.textAlign
;
901 dc
->w
.textAlign
= textAlign
;
906 /***********************************************************************
907 * GetDCOrgEx (GDI32.168)
909 BOOL32
GetDCOrgEx( HDC32 hDC
, LPPOINT32 lpp
)
911 DC
* dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
);
912 if (!dc
|| !lpp
) return FALSE
;
914 if (!(dc
->w
.flags
& DC_MEMORY
))
917 int w
, h
, border
, depth
;
918 /* FIXME: this is not correct for managed windows */
919 XGetGeometry( display
, dc
->u
.x
.drawable
, &root
,
920 &lpp
->x
, &lpp
->y
, &w
, &h
, &border
, &depth
);
922 else lpp
->x
= lpp
->y
= 0;
923 lpp
->x
+= dc
->w
.DCOrgX
; lpp
->y
+= dc
->w
.DCOrgY
;
928 /***********************************************************************
931 DWORD
GetDCOrg( HDC16 hdc
)
934 if( GetDCOrgEx( hdc
, &pt
) )
935 return MAKELONG( (WORD
)pt
.x
, (WORD
)pt
.y
);
940 /***********************************************************************
943 DWORD
SetDCOrg( HDC16 hdc
, INT16 x
, INT16 y
)
946 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
948 prevOrg
= dc
->w
.DCOrgX
| (dc
->w
.DCOrgY
<< 16);
955 /***********************************************************************
956 * SetDCHook (GDI.190)
958 BOOL16
SetDCHook( HDC16 hdc
, FARPROC16 hookProc
, DWORD dwHookData
)
960 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
962 dprintf_dc( stddeb
, "SetDCHook: hookProc %08x, default is %08x\n",
963 (UINT32
)hookProc
, (UINT32
)DCHook
);
965 if (!dc
) return FALSE
;
966 dc
->hookProc
= hookProc
;
967 dc
->dwHookData
= dwHookData
;
972 /***********************************************************************
973 * GetDCHook (GDI.191)
975 DWORD
GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
977 DC
*dc
= (DC
*)GDI_GetObjPtr( hdc
, DC_MAGIC
);
979 *phookProc
= dc
->hookProc
;
980 return dc
->dwHookData
;
984 /***********************************************************************
985 * SetHookFlags (GDI.192)
987 WORD
SetHookFlags(HDC16 hDC
, WORD flags
)
989 DC
* dc
= (DC
*)GDI_GetObjPtr( hDC
, DC_MAGIC
);
993 WORD wRet
= dc
->w
.flags
& DC_DIRTY
;
995 /* "Undocumented Windows" info is slightly
999 dprintf_dc(stddeb
,"SetHookFlags: hDC %04x, flags %04x\n",hDC
,flags
);
1001 if( flags
& DCHF_INVALIDATEVISRGN
)
1002 dc
->w
.flags
|= DC_DIRTY
;
1003 else if( flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1004 dc
->w
.flags
&= ~DC_DIRTY
;