Release 961023
[wine/multimedia.git] / objects / dc.c
blob215bc50f04c7a6d3d92df6a935d9222d1d97ba81
1 /*
2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 */
8 #include <stdlib.h>
9 #include <string.h>
10 #include "gdi.h"
11 #include "bitmap.h"
12 #include "metafile.h"
13 #include "stddebug.h"
14 #include "color.h"
15 #include "debug.h"
16 #include "font.h"
17 #include "xmalloc.h"
19 extern void CLIPPING_UpdateGCRegion( DC * dc ); /* objects/clipping.c */
21 /* Default DC values */
22 static const WIN_DC_INFO DC_defaultValues =
24 0, /* flags */
25 NULL, /* devCaps */
26 0, /* hClipRgn */
27 0, /* hVisRgn */
28 0, /* hGCClipRgn */
29 STOCK_BLACK_PEN, /* hPen */
30 STOCK_WHITE_BRUSH, /* hBrush */
31 STOCK_SYSTEM_FONT, /* hFont */
32 0, /* hBitmap */
33 0, /* hFirstBitmap */
34 0, /* hDevice */
35 STOCK_DEFAULT_PALETTE, /* hPalette */
36 R2_COPYPEN, /* ROPmode */
37 ALTERNATE, /* polyFillMode */
38 BLACKONWHITE, /* stretchBltMode */
39 ABSOLUTE, /* relAbsMode */
40 OPAQUE, /* backgroundMode */
41 RGB( 255, 255, 255 ), /* backgroundColor */
42 RGB( 0, 0, 0 ), /* textColor */
43 0, /* backgroundPixel */
44 0, /* textPixel */
45 0, /* brushOrgX */
46 0, /* brushOrgY */
47 TA_LEFT | TA_TOP | TA_NOUPDATECP, /* textAlign */
48 0, /* charExtra */
49 0, /* breakTotalExtra */
50 0, /* breakCount */
51 0, /* breakExtra */
52 0, /* breakRem */
53 1, /* bitsPerPixel */
54 MM_TEXT, /* MapMode */
55 0, /* DCOrgX */
56 0, /* DCOrgY */
57 0, /* CursPosX */
58 0, /* CursPosY */
59 0, /* WndOrgX */
60 0, /* WndOrgY */
61 1, /* WndExtX */
62 1, /* WndExtY */
63 0, /* VportOrgX */
64 0, /* VportOrgY */
65 1, /* VportExtX */
66 1 /* VportExtY */
69 /* ROP code to GC function conversion */
70 const int DC_XROPfunction[16] =
72 GXclear, /* R2_BLACK */
73 GXnor, /* R2_NOTMERGEPEN */
74 GXandInverted, /* R2_MASKNOTPEN */
75 GXcopyInverted, /* R2_NOTCOPYPEN */
76 GXandReverse, /* R2_MASKPENNOT */
77 GXinvert, /* R2_NOT */
78 GXxor, /* R2_XORPEN */
79 GXnand, /* R2_NOTMASKPEN */
80 GXand, /* R2_MASKPEN */
81 GXequiv, /* R2_NOTXORPEN */
82 GXnoop, /* R2_NOP */
83 GXorInverted, /* R2_MERGENOTPEN */
84 GXcopy, /* R2_COPYPEN */
85 GXorReverse, /* R2_MERGEPENNOT */
86 GXor, /* R2_MERGEPEN */
87 GXset /* R2_WHITE */
91 /***********************************************************************
92 * DC_FillDevCaps
94 * Fill the device caps structure.
96 void DC_FillDevCaps( DeviceCaps * caps )
98 caps->version = 0x300;
99 caps->technology = DT_RASDISPLAY;
100 caps->horzSize = WidthMMOfScreen(screen) * screenWidth / WidthOfScreen(screen);
101 caps->vertSize = HeightMMOfScreen(screen) * screenHeight / HeightOfScreen(screen);
102 caps->horzRes = screenWidth;
103 caps->vertRes = screenHeight;
104 caps->bitsPixel = screenDepth;
105 caps->planes = 1;
106 caps->numBrushes = 16+6; /* 16 solid + 6 hatched brushes */
107 caps->numPens = 16; /* 16 solid pens */
108 caps->numMarkers = 0;
109 caps->numFonts = 0;
110 caps->numColors = 100;
111 caps->pdeviceSize = 0;
112 caps->curveCaps = CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
113 CC_WIDE | CC_STYLED | CC_WIDESTYLED |
114 CC_INTERIORS | CC_ROUNDRECT;
115 caps->lineCaps = LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
116 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS;
117 caps->polygonalCaps = PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
118 PC_SCANLINE | PC_WIDE | PC_STYLED |
119 PC_WIDESTYLED | PC_INTERIORS;
120 caps->textCaps = TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
121 TC_IA_ABLE | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE;
122 caps->clipCaps = CP_REGION;
123 caps->rasterCaps = RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
124 RC_DI_BITMAP | RC_DIBTODEV | RC_BIGFONT|
125 RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS;
127 if( !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
128 caps->rasterCaps |= RC_PALETTE;
130 caps->aspectX = 36; /* ?? */
131 caps->aspectY = 36; /* ?? */
132 caps->aspectXY = 51;
133 caps->logPixelsX = (int)(caps->horzRes * 25.4 / caps->horzSize);
134 caps->logPixelsY = (int)(caps->vertRes * 25.4 / caps->vertSize);
135 caps->sizePalette = (caps->rasterCaps & RC_PALETTE)
136 ? DefaultVisual(display,DefaultScreen(display))->map_entries
137 : 0;
138 caps->numReserved = 0;
139 caps->colorRes = 0;
143 /***********************************************************************
144 * DC_AllocDC
146 DC *DC_AllocDC( const DC_FUNCTIONS *funcs )
148 HDC16 hdc;
149 DC *dc;
151 if (!(hdc = GDI_AllocObject( sizeof(DC), DC_MAGIC ))) return NULL;
152 dc = (DC *) GDI_HEAP_LIN_ADDR( hdc );
154 dc->hSelf = hdc;
155 dc->funcs = funcs;
156 dc->physDev = NULL;
157 dc->saveLevel = 0;
158 dc->dwHookData = 0L;
159 dc->hookProc = NULL;
161 memcpy( &dc->w, &DC_defaultValues, sizeof(DC_defaultValues) );
162 return dc;
166 /***********************************************************************
167 * DC_GetDCPtr
169 DC *DC_GetDCPtr( HDC32 hdc )
171 GDIOBJHDR *ptr = (GDIOBJHDR *)GDI_HEAP_LIN_ADDR( hdc );
172 if ((ptr->wMagic == DC_MAGIC) || (ptr->wMagic == METAFILE_DC_MAGIC))
173 return (DC *)ptr;
174 return NULL;
178 /***********************************************************************
179 * DC_InitDC
181 * Setup device-specific DC values for a newly created DC.
183 void DC_InitDC( DC* dc )
185 RealizeDefaultPalette( dc->hSelf );
186 SetTextColor( dc->hSelf, dc->w.textColor );
187 SetBkColor( dc->hSelf, dc->w.backgroundColor );
188 SelectObject( dc->hSelf, dc->w.hPen );
189 SelectObject( dc->hSelf, dc->w.hBrush );
190 SelectObject( 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 )
204 XGCValues val;
205 unsigned long mask;
206 Pixmap pixmap = 0;
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;
218 else
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)
235 case FillStippled:
236 case FillOpaqueStippled:
237 if (dc->w.backgroundMode==OPAQUE) val.fill_style = FillOpaqueStippled;
238 val.stipple = dc->u.x.brush.pixmap;
239 mask = GCStipple;
240 break;
242 case FillTiled:
243 if (fMapColors && COLOR_PixelToPalette)
245 register int x, y;
246 XImage *image;
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 );
256 val.tile = pixmap;
258 else val.tile = dc->u.x.brush.pixmap;
259 mask = GCTile;
260 break;
262 default:
263 mask = 0;
264 break;
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,
272 &val );
273 if (pixmap) XFreePixmap( display, pixmap );
274 return TRUE;
278 /***********************************************************************
279 * DC_SetupGCForBrush
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 /***********************************************************************
291 * DC_SetupGCForPen
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 )
298 XGCValues val;
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) );
311 else
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 );
332 return TRUE;
336 /***********************************************************************
337 * DC_SetupGCForText
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 )
344 XGCValues val;
346 if (!dc->u.x.font.fstruct)
348 fprintf( stderr, "DC_SetupGCForText: fstruct is NULL. Please report this\n" );
349 return FALSE;
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 |
361 GCFont, &val );
362 return TRUE;
366 /***********************************************************************
367 * GetDCState (GDI.179)
369 HDC16 GetDCState( HDC16 hdc )
371 DC * newdc, * dc;
372 HGDIOBJ16 handle;
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 memcpy( &newdc->w, &dc->w, sizeof(dc->w) );
382 memcpy( &newdc->u.x.pen, &dc->u.x.pen, sizeof(dc->u.x.pen) );
384 newdc->hSelf = (HDC32)handle;
385 newdc->saveLevel = 0;
386 newdc->w.flags |= DC_SAVED;
388 newdc->w.hGCClipRgn = 0;
389 newdc->w.hVisRgn = CreateRectRgn( 0, 0, 0, 0 );
390 CombineRgn( newdc->w.hVisRgn, dc->w.hVisRgn, 0, RGN_COPY );
391 if (dc->w.hClipRgn)
393 newdc->w.hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
394 CombineRgn( newdc->w.hClipRgn, dc->w.hClipRgn, 0, RGN_COPY );
396 return handle;
400 /***********************************************************************
401 * SetDCState (GDI.180)
403 void SetDCState( HDC16 hdc, HDC16 hdcs )
405 DC * dc, * dcs;
406 HRGN32 hVisRgn, hClipRgn, hGCClipRgn;
407 HFONT16 hfont;
408 HBRUSH16 hbrush;
410 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
411 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return;
412 if (!dcs->w.flags & DC_SAVED) return;
413 dprintf_dc(stddeb, "SetDCState: %04x %04x\n", hdc, hdcs );
415 /* Save the regions, font & brush before overwriting everything */
416 hVisRgn = dc->w.hVisRgn;
417 hClipRgn = dc->w.hClipRgn;
418 hGCClipRgn = dc->w.hGCClipRgn;
419 hfont = dc->w.hFont;
420 hbrush = dc->w.hBrush;
421 memcpy( &dc->w, &dcs->w, sizeof(dc->w) );
422 memcpy( &dc->u.x.pen, &dcs->u.x.pen, sizeof(dc->u.x.pen) );
423 dc->w.flags &= ~DC_SAVED;
425 /* Restore the regions */
426 dc->w.hVisRgn = hVisRgn;
427 dc->w.hClipRgn = hClipRgn;
428 dc->w.hGCClipRgn = hGCClipRgn;
429 dc->w.hFont = hfont;
430 dc->w.hBrush = hbrush;
431 CombineRgn( dc->w.hVisRgn, dcs->w.hVisRgn, 0, RGN_COPY );
432 SelectClipRgn( hdc, dcs->w.hClipRgn );
434 SelectObject( hdc, dcs->w.hBrush );
435 SelectObject( hdc, dcs->w.hFont );
439 /***********************************************************************
440 * SaveDC (GDI.30)
442 int SaveDC( HDC16 hdc )
444 HDC16 hdcs;
445 DC * dc, * dcs;
447 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
448 if (!dc)
450 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
451 if (!dc) return 0;
452 MF_MetaParam0(dc, META_SAVEDC);
453 return 1; /* ?? */
455 if (!(hdcs = GetDCState( hdc ))) return 0;
456 dcs = (DC *) GDI_HEAP_LIN_ADDR( hdcs );
457 dcs->header.hNext = dc->header.hNext;
458 dc->header.hNext = hdcs;
459 dprintf_dc(stddeb, "SaveDC(%04x): returning %d\n", hdc, dc->saveLevel+1 );
460 return ++dc->saveLevel;
464 /***********************************************************************
465 * RestoreDC (GDI.39)
467 BOOL RestoreDC( HDC16 hdc, short level )
469 DC * dc, * dcs;
471 dprintf_dc(stddeb, "RestoreDC: %04x %d\n", hdc, level );
472 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
473 if (!dc)
475 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
476 if (!dc) return FALSE;
477 if (level != -1) return FALSE;
478 MF_MetaParam1(dc, META_RESTOREDC, level);
479 return TRUE;
481 if (level == -1) level = dc->saveLevel;
482 if ((level < 1) || (level > (short)dc->saveLevel)) return FALSE;
484 while ((short)dc->saveLevel >= level)
486 HDC16 hdcs = dc->header.hNext;
487 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return FALSE;
488 dc->header.hNext = dcs->header.hNext;
489 if ((short)--dc->saveLevel < level) SetDCState( hdc, hdcs );
490 DeleteDC( hdcs );
492 return TRUE;
496 /***********************************************************************
497 * CreateDC (GDI.53)
499 HDC16 CreateDC( LPCSTR driver, LPCSTR device, LPCSTR output, const DEVMODE* initData )
501 DC * dc;
502 const DC_FUNCTIONS *funcs;
504 if (!(funcs = DRIVER_FindDriver( driver ))) return 0;
505 if (!(dc = DC_AllocDC( funcs ))) return 0;
506 dc->w.flags = 0;
508 dprintf_dc(stddeb, "CreateDC(%s %s %s): returning %04x\n",
509 driver, device, output, dc->hSelf );
511 if (dc->funcs->pCreateDC &&
512 !dc->funcs->pCreateDC( dc, driver, device, output, initData ))
514 dprintf_dc( stddeb, "CreateDC: creation aborted by device\n" );
515 GDI_HEAP_FREE( dc->hSelf );
516 return 0;
519 DC_InitDC( dc );
520 return dc->hSelf;
524 /***********************************************************************
525 * CreateIC (GDI.153)
527 HDC16 CreateIC( LPCSTR driver, LPCSTR device, LPCSTR output, const DEVMODE* initData )
529 /* Nothing special yet for ICs */
530 return CreateDC( driver, device, output, initData );
534 /***********************************************************************
535 * CreateCompatibleDC (GDI.52)
537 HDC16 CreateCompatibleDC( HDC16 hdc )
539 DC *dc, *origDC;
540 HBITMAP16 hbitmap;
541 const DC_FUNCTIONS *funcs;
543 if ((origDC = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC ))) funcs = origDC->funcs;
544 else funcs = DRIVER_FindDriver( "DISPLAY" );
545 if (!funcs) return 0;
547 if (!(dc = DC_AllocDC( funcs ))) return 0;
549 dprintf_dc(stddeb, "CreateCompatibleDC(%04x): returning %04x\n",
550 hdc, dc->hSelf );
552 /* Create default bitmap */
553 if (!(hbitmap = CreateBitmap( 1, 1, 1, 1, NULL )))
555 GDI_HEAP_FREE( dc->hSelf );
556 return 0;
558 dc->w.flags = DC_MEMORY;
559 dc->w.bitsPerPixel = 1;
560 dc->w.hBitmap = hbitmap;
561 dc->w.hFirstBitmap = hbitmap;
563 if (dc->funcs->pCreateDC &&
564 !dc->funcs->pCreateDC( dc, NULL, NULL, NULL, NULL ))
566 dprintf_dc( stddeb, "CreateDC: creation aborted by device\n" );
567 DeleteObject( hbitmap );
568 GDI_HEAP_FREE( dc->hSelf );
569 return 0;
572 DC_InitDC( dc );
573 return dc->hSelf;
577 /***********************************************************************
578 * DeleteDC (GDI.68)
580 BOOL DeleteDC( HDC16 hdc )
582 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
583 if (!dc) return FALSE;
585 dprintf_dc(stddeb, "DeleteDC: %04x\n", hdc );
587 while (dc->saveLevel)
589 DC * dcs;
590 HDC16 hdcs = dc->header.hNext;
591 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) break;
592 dc->header.hNext = dcs->header.hNext;
593 dc->saveLevel--;
594 DeleteDC( hdcs );
597 if (!(dc->w.flags & DC_SAVED))
599 SelectObject( hdc, STOCK_BLACK_PEN );
600 SelectObject( hdc, STOCK_WHITE_BRUSH );
601 SelectObject( hdc, STOCK_SYSTEM_FONT );
602 if (dc->w.flags & DC_MEMORY) DeleteObject( dc->w.hFirstBitmap );
603 if (dc->funcs->pDeleteDC) dc->funcs->pDeleteDC(dc);
606 if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
607 if (dc->w.hVisRgn) DeleteObject( dc->w.hVisRgn );
608 if (dc->w.hGCClipRgn) DeleteObject( dc->w.hGCClipRgn );
610 return GDI_FreeObject( hdc );
614 /***********************************************************************
615 * ResetDC (GDI.376)
617 HDC16 ResetDC( HDC16 hdc, /* DEVMODE */ void *devmode )
619 fprintf( stderr, "ResetDC: empty stub!\n" );
620 return hdc;
624 /***********************************************************************
625 * GetDeviceCaps (GDI.80)
627 int GetDeviceCaps( HDC16 hdc, WORD cap )
629 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
630 if (!dc) return 0;
632 if (cap > sizeof(DeviceCaps)-sizeof(WORD)) return 0;
634 dprintf_dc(stddeb, "GetDeviceCaps(%04x,%d): returning %d\n",
635 hdc, cap, *(WORD *)(((char *)dc->w.devCaps) + cap) );
636 return *(WORD *)(((char *)dc->w.devCaps) + cap);
640 /***********************************************************************
641 * SetBkColor (GDI.1) (GDI32.305)
643 COLORREF SetBkColor( HDC32 hdc, COLORREF color )
645 COLORREF oldColor;
646 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
647 if (!dc)
649 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
650 if (!dc) return 0x80000000;
651 MF_MetaParam2(dc, META_SETBKCOLOR, HIWORD(color), LOWORD(color));
652 return 0; /* ?? */
655 oldColor = dc->w.backgroundColor;
656 dc->w.backgroundColor = color;
657 dc->w.backgroundPixel = COLOR_ToPhysical( dc, color );
658 return oldColor;
662 /***********************************************************************
663 * SetTextColor (GDI.9) (GDI32.338)
665 COLORREF SetTextColor( HDC32 hdc, COLORREF color )
667 COLORREF oldColor;
668 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
669 if (!dc)
671 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
672 if (!dc) return 0x80000000;
673 MF_MetaParam2(dc, META_SETTEXTCOLOR, HIWORD(color), LOWORD(color));
674 return 0; /* ?? */
677 oldColor = dc->w.textColor;
678 dc->w.textColor = color;
679 dc->w.textPixel = COLOR_ToPhysical( dc, color );
680 return oldColor;
684 /***********************************************************************
685 * SetTextAlign (GDI.346)
687 WORD SetTextAlign( HDC16 hdc, WORD textAlign )
689 WORD prevAlign;
690 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
691 if (!dc)
693 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC ))) return 0;
694 MF_MetaParam1( dc, META_SETTEXTALIGN, textAlign );
695 return 1;
697 prevAlign = dc->w.textAlign;
698 dc->w.textAlign = textAlign;
699 return prevAlign;
703 /***********************************************************************
704 * GetDCOrg (GDI.79)
706 DWORD GetDCOrg( HDC16 hdc )
708 Window root;
709 int x, y, w, h, border, depth;
711 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
712 if (!dc) return 0;
713 if (dc->w.flags & DC_MEMORY) return 0;
714 XGetGeometry( display, dc->u.x.drawable, &root,
715 &x, &y, &w, &h, &border, &depth );
716 return MAKELONG( dc->w.DCOrgX + (WORD)x, dc->w.DCOrgY + (WORD)y );
720 /***********************************************************************
721 * SetDCOrg (GDI.117)
723 DWORD SetDCOrg( HDC16 hdc, short x, short y )
725 DWORD prevOrg;
726 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
727 if (!dc) return 0;
728 prevOrg = dc->w.DCOrgX | (dc->w.DCOrgY << 16);
729 dc->w.DCOrgX = x;
730 dc->w.DCOrgY = y;
731 return prevOrg;
735 /***********************************************************************
736 * SetDCHook (GDI.190)
738 BOOL16 SetDCHook( HDC16 hdc, FARPROC16 hookProc, DWORD dwHookData )
740 DC *dc = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC );
742 dprintf_dc( stddeb, "SetDCHook: hookProc %08x, default is %08x\n",
743 (UINT32)hookProc, (UINT32)DCHook );
745 if (!dc) return FALSE;
746 dc->hookProc = hookProc;
747 dc->dwHookData = dwHookData;
748 return TRUE;
752 /***********************************************************************
753 * GetDCHook (GDI.191)
755 DWORD GetDCHook( HDC16 hdc, FARPROC16 *phookProc )
757 DC *dc = (DC *)GDI_GetObjPtr( hdc, DC_MAGIC );
758 if (!dc) return 0;
759 *phookProc = dc->hookProc;
760 return dc->dwHookData;
764 /***********************************************************************
765 * SetHookFlags (GDI.192)
767 WORD SetHookFlags(HDC16 hDC, WORD flags)
769 DC* dc = (DC*)GDI_GetObjPtr( hDC, DC_MAGIC );
771 if( dc )
773 WORD wRet = dc->w.flags & DC_DIRTY;
775 /* "Undocumented Windows" info is slightly
776 * confusing
779 dprintf_dc(stddeb,"SetHookFlags: hDC %04x, flags %04x\n",hDC,flags);
781 if( flags & DCHF_INVALIDATEVISRGN )
782 dc->w.flags |= DC_DIRTY;
783 else if( flags & DCHF_VALIDATEVISRGN || !flags )
784 dc->w.flags &= ~DC_DIRTY;
785 return wRet;
787 return 0;