Release 960506
[wine/multimedia.git] / objects / dc.c
blob8094756ecc0dca6fa84455388033d19028222ea9
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 static DeviceCaps * displayDevCaps = NULL;
21 extern void CLIPPING_UpdateGCRegion( DC * dc ); /* objects/clipping.c */
23 /* Default DC values */
24 static const WIN_DC_INFO DC_defaultValues =
26 0, /* flags */
27 NULL, /* devCaps */
28 0, /* hMetaFile */
29 0, /* hClipRgn */
30 0, /* hVisRgn */
31 0, /* hGCClipRgn */
32 STOCK_BLACK_PEN, /* hPen */
33 STOCK_WHITE_BRUSH, /* hBrush */
34 STOCK_SYSTEM_FONT, /* hFont */
35 0, /* hBitmap */
36 0, /* hFirstBitmap */
37 0, /* hDevice */
38 STOCK_DEFAULT_PALETTE, /* hPalette */
39 R2_COPYPEN, /* ROPmode */
40 ALTERNATE, /* polyFillMode */
41 BLACKONWHITE, /* stretchBltMode */
42 ABSOLUTE, /* relAbsMode */
43 OPAQUE, /* backgroundMode */
44 RGB( 255, 255, 255 ), /* backgroundColor */
45 RGB( 0, 0, 0 ), /* textColor */
46 0, /* backgroundPixel */
47 0, /* textPixel */
48 0, /* brushOrgX */
49 0, /* brushOrgY */
50 TA_LEFT | TA_TOP | TA_NOUPDATECP, /* textAlign */
51 0, /* charExtra */
52 0, /* breakTotalExtra */
53 0, /* breakCount */
54 0, /* breakExtra */
55 0, /* breakRem */
56 1, /* bitsPerPixel */
57 MM_TEXT, /* MapMode */
58 0, /* DCOrgX */
59 0, /* DCOrgY */
60 0, /* CursPosX */
61 0, /* CursPosY */
62 0, /* WndOrgX */
63 0, /* WndOrgY */
64 1, /* WndExtX */
65 1, /* WndExtY */
66 0, /* VportOrgX */
67 0, /* VportOrgY */
68 1, /* VportExtX */
69 1 /* VportExtY */
72 /* ROP code to GC function conversion */
73 const int DC_XROPfunction[16] =
75 GXclear, /* R2_BLACK */
76 GXnor, /* R2_NOTMERGEPEN */
77 GXandInverted, /* R2_MASKNOTPEN */
78 GXcopyInverted, /* R2_NOTCOPYPEN */
79 GXandReverse, /* R2_MASKPENNOT */
80 GXinvert, /* R2_NOT */
81 GXxor, /* R2_XORPEN */
82 GXnand, /* R2_NOTMASKPEN */
83 GXand, /* R2_MASKPEN */
84 GXequiv, /* R2_NOTXORPEN */
85 GXnoop, /* R2_NOP */
86 GXorInverted, /* R2_MERGENOTPEN */
87 GXcopy, /* R2_COPYPEN */
88 GXorReverse, /* R2_MERGEPENNOT */
89 GXor, /* R2_MERGEPEN */
90 GXset /* R2_WHITE */
94 /***********************************************************************
95 * DC_FillDevCaps
97 * Fill the device caps structure.
99 void DC_FillDevCaps( DeviceCaps * caps )
101 caps->version = 0x300;
102 caps->technology = DT_RASDISPLAY;
103 caps->horzSize = WidthMMOfScreen(screen) * screenWidth / WidthOfScreen(screen);
104 caps->vertSize = HeightMMOfScreen(screen) * screenHeight / HeightOfScreen(screen);
105 caps->horzRes = screenWidth;
106 caps->vertRes = screenHeight;
107 caps->bitsPixel = screenDepth;
108 caps->planes = 1;
109 caps->numBrushes = 16+6; /* 16 solid + 6 hatched brushes */
110 caps->numPens = 16; /* 16 solid pens */
111 caps->numMarkers = 0;
112 caps->numFonts = 0;
113 caps->numColors = 1 << caps->bitsPixel;
114 caps->pdeviceSize = 0;
115 caps->curveCaps = CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
116 CC_WIDE | CC_STYLED | CC_WIDESTYLED |
117 CC_INTERIORS | CC_ROUNDRECT;
118 caps->lineCaps = LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
119 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS;
120 caps->polygonalCaps = PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
121 PC_SCANLINE | PC_WIDE | PC_STYLED |
122 PC_WIDESTYLED | PC_INTERIORS;
123 caps->textCaps = TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
124 TC_IA_ABLE | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE;
125 caps->clipCaps = CP_REGION;
126 caps->rasterCaps = RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
127 RC_DI_BITMAP | RC_PALETTE | RC_DIBTODEV | RC_BIGFONT|
128 RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS;
129 caps->aspectX = 36; /* ?? */
130 caps->aspectY = 36; /* ?? */
131 caps->aspectXY = 51;
132 caps->logPixelsX = (int)(caps->horzRes * 25.4 / caps->horzSize);
133 caps->logPixelsY = (int)(caps->vertRes * 25.4 / caps->vertSize);
134 caps->sizePalette = DefaultVisual(display,DefaultScreen(display))->map_entries;
135 caps->numReserved = 0;
136 caps->colorRes = 0;
140 /***********************************************************************
141 * DC_InitDC
143 * Setup device-specific DC values for a newly created DC.
145 void DC_InitDC( HDC hdc )
147 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
148 RealizeDefaultPalette( hdc );
149 SetTextColor( hdc, dc->w.textColor );
150 SetBkColor( hdc, dc->w.backgroundColor );
151 SelectObject( hdc, dc->w.hPen );
152 SelectObject( hdc, dc->w.hBrush );
153 SelectObject( hdc, dc->w.hFont );
154 XSetGraphicsExposures( display, dc->u.x.gc, False );
155 XSetSubwindowMode( display, dc->u.x.gc, IncludeInferiors );
156 CLIPPING_UpdateGCRegion( dc );
160 /***********************************************************************
161 * DC_SetupGCForPatBlt
163 * Setup the GC for a PatBlt operation using current brush.
164 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
165 * Return FALSE if brush is BS_NULL, TRUE otherwise.
167 BOOL DC_SetupGCForPatBlt( DC * dc, GC gc, BOOL fMapColors )
169 XGCValues val;
170 unsigned long mask;
171 Pixmap pixmap = 0;
173 if (dc->u.x.brush.style == BS_NULL) return FALSE;
174 if (dc->u.x.brush.pixel == -1)
176 /* Special case used for monochrome pattern brushes.
177 * We need to swap foreground and background because
178 * Windows does it the wrong way...
180 val.foreground = dc->w.backgroundPixel;
181 val.background = dc->w.textPixel;
183 else
185 val.foreground = dc->u.x.brush.pixel;
186 val.background = dc->w.backgroundPixel;
188 if (fMapColors && COLOR_PixelToPalette)
190 val.foreground = COLOR_PixelToPalette[val.foreground];
191 val.background = COLOR_PixelToPalette[val.background];
194 val.function = DC_XROPfunction[dc->w.ROPmode-1];
195 val.fill_style = dc->u.x.brush.fillStyle;
196 switch(val.fill_style)
198 case FillStippled:
199 case FillOpaqueStippled:
200 if (dc->w.backgroundMode==OPAQUE) val.fill_style = FillOpaqueStippled;
201 val.stipple = dc->u.x.brush.pixmap;
202 mask = GCStipple;
203 break;
205 case FillTiled:
206 if (fMapColors && COLOR_PixelToPalette)
208 register int x, y;
209 XImage *image;
210 pixmap = XCreatePixmap( display, rootWindow, 8, 8, screenDepth );
211 image = XGetImage( display, dc->u.x.brush.pixmap, 0, 0, 8, 8,
212 AllPlanes, ZPixmap );
213 for (y = 0; y < 8; y++)
214 for (x = 0; x < 8; x++)
215 XPutPixel( image, x, y,
216 COLOR_PixelToPalette[XGetPixel( image, x, y)] );
217 XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
218 XDestroyImage( image );
219 val.tile = pixmap;
221 else val.tile = dc->u.x.brush.pixmap;
222 mask = GCTile;
223 break;
225 default:
226 mask = 0;
227 break;
229 val.ts_x_origin = dc->w.DCOrgX + dc->w.brushOrgX;
230 val.ts_y_origin = dc->w.DCOrgY + dc->w.brushOrgY;
231 val.fill_rule = (dc->w.polyFillMode==WINDING) ? WindingRule : EvenOddRule;
232 XChangeGC( display, gc,
233 GCFunction | GCForeground | GCBackground | GCFillStyle |
234 GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
235 &val );
236 if (pixmap) XFreePixmap( display, pixmap );
237 return TRUE;
241 /***********************************************************************
242 * DC_SetupGCForBrush
244 * Setup dc->u.x.gc for drawing operations using current brush.
245 * Return FALSE if brush is BS_NULL, TRUE otherwise.
247 BOOL DC_SetupGCForBrush( DC * dc )
249 return DC_SetupGCForPatBlt( dc, dc->u.x.gc, FALSE );
253 /***********************************************************************
254 * DC_SetupGCForPen
256 * Setup dc->u.x.gc for drawing operations using current pen.
257 * Return FALSE if pen is PS_NULL, TRUE otherwise.
259 BOOL DC_SetupGCForPen( DC * dc )
261 XGCValues val;
263 if (dc->u.x.pen.style == PS_NULL) return FALSE;
265 if ((screenDepth <= 8) && /* FIXME: Should check for palette instead */
266 ((dc->w.ROPmode == R2_BLACK) || (dc->w.ROPmode == R2_WHITE)))
268 val.function = GXcopy;
269 val.foreground = COLOR_ToPhysical( NULL, (dc->w.ROPmode == R2_BLACK) ?
270 RGB(0,0,0) : RGB(255,255,255) );
272 else
274 val.function = DC_XROPfunction[dc->w.ROPmode-1];
275 val.foreground = dc->u.x.pen.pixel;
277 val.background = dc->w.backgroundPixel;
278 val.fill_style = FillSolid;
279 if ((dc->u.x.pen.style!=PS_SOLID) && (dc->u.x.pen.style!=PS_INSIDEFRAME))
281 XSetDashes( display, dc->u.x.gc, 0,
282 dc->u.x.pen.dashes, dc->u.x.pen.dash_len );
283 val.line_style = (dc->w.backgroundMode == OPAQUE) ?
284 LineDoubleDash : LineOnOffDash;
286 else val.line_style = LineSolid;
287 val.line_width = dc->u.x.pen.width;
288 val.cap_style = CapRound;
289 val.join_style = JoinBevel;
290 XChangeGC( display, dc->u.x.gc,
291 GCFunction | GCForeground | GCBackground | GCLineWidth |
292 GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
293 return TRUE;
297 /***********************************************************************
298 * DC_SetupGCForText
300 * Setup dc->u.x.gc for text drawing operations.
301 * Return FALSE if the font is null, TRUE otherwise.
303 BOOL DC_SetupGCForText( DC * dc )
305 XGCValues val;
307 if (!dc->u.x.font.fstruct)
309 fprintf( stderr, "DC_SetupGCForText: fstruct is NULL. Please report this\n" );
310 return FALSE;
312 val.function = GXcopy; /* Text is always GXcopy */
313 val.foreground = dc->w.textPixel;
314 val.background = dc->w.backgroundPixel;
315 val.fill_style = FillSolid;
316 val.font = dc->u.x.font.fstruct->fid;
317 XChangeGC( display, dc->u.x.gc,
318 GCFunction | GCForeground | GCBackground | GCFillStyle |
319 GCFont, &val );
320 return TRUE;
324 /***********************************************************************
325 * GetDCState (GDI.179)
327 HDC GetDCState( HDC hdc )
329 DC * newdc, * dc;
330 HANDLE handle;
332 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
333 if (!(handle = GDI_AllocObject( sizeof(DC), DC_MAGIC ))) return 0;
334 newdc = (DC *) GDI_HEAP_LIN_ADDR( handle );
336 dprintf_dc(stddeb, "GetDCState(%04x): returning %04x\n", hdc, handle );
338 memset( &newdc->u.x, 0, sizeof(newdc->u.x) );
339 memcpy( &newdc->w, &dc->w, sizeof(dc->w) );
340 memcpy( &newdc->u.x.pen, &dc->u.x.pen, sizeof(dc->u.x.pen) );
341 newdc->saveLevel = 0;
342 newdc->w.flags |= DC_SAVED;
344 newdc->w.hGCClipRgn = 0;
345 newdc->w.hVisRgn = CreateRectRgn( 0, 0, 0, 0 );
346 CombineRgn( newdc->w.hVisRgn, dc->w.hVisRgn, 0, RGN_COPY );
347 if (dc->w.hClipRgn)
349 newdc->w.hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
350 CombineRgn( newdc->w.hClipRgn, dc->w.hClipRgn, 0, RGN_COPY );
352 COLOR_SetMapping( newdc, dc->u.x.pal.hMapping,
353 dc->u.x.pal.hRevMapping, dc->u.x.pal.mappingSize );
354 return handle;
358 /***********************************************************************
359 * SetDCState (GDI.180)
361 void SetDCState( HDC hdc, HDC hdcs )
363 DC * dc, * dcs;
364 HRGN hVisRgn, hClipRgn, hGCClipRgn;
365 HFONT hfont;
366 HBRUSH hbrush;
368 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
369 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return;
370 if (!dcs->w.flags & DC_SAVED) return;
371 dprintf_dc(stddeb, "SetDCState: %04x %04x\n", hdc, hdcs );
373 /* Save the regions, font & brush before overwriting everything */
374 hVisRgn = dc->w.hVisRgn;
375 hClipRgn = dc->w.hClipRgn;
376 hGCClipRgn = dc->w.hGCClipRgn;
377 hfont = dc->w.hFont;
378 hbrush = dc->w.hBrush;
379 memcpy( &dc->w, &dcs->w, sizeof(dc->w) );
380 memcpy( &dc->u.x.pen, &dcs->u.x.pen, sizeof(dc->u.x.pen) );
381 dc->w.flags &= ~DC_SAVED;
383 /* Restore the regions */
384 dc->w.hVisRgn = hVisRgn;
385 dc->w.hClipRgn = hClipRgn;
386 dc->w.hGCClipRgn = hGCClipRgn;
387 dc->w.hFont = hfont;
388 dc->w.hBrush = hbrush;
389 CombineRgn( dc->w.hVisRgn, dcs->w.hVisRgn, 0, RGN_COPY );
390 SelectClipRgn( hdc, dcs->w.hClipRgn );
392 SelectObject( hdc, dcs->w.hBrush );
393 SelectObject( hdc, dcs->w.hFont );
394 COLOR_SetMapping( dc, dcs->u.x.pal.hMapping,
395 dcs->u.x.pal.hRevMapping, dcs->u.x.pal.mappingSize );
399 /***********************************************************************
400 * SaveDC (GDI.30)
402 int SaveDC( HDC hdc )
404 HDC hdcs;
405 DC * dc, * dcs;
407 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
408 if (!dc)
410 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
411 if (!dc) return 0;
412 MF_MetaParam0(dc, META_SAVEDC);
413 return 1; /* ?? */
415 if (!(hdcs = GetDCState( hdc ))) return 0;
416 dcs = (DC *) GDI_HEAP_LIN_ADDR( hdcs );
417 dcs->header.hNext = dc->header.hNext;
418 dc->header.hNext = hdcs;
419 dprintf_dc(stddeb, "SaveDC(%04x): returning %d\n", hdc, dc->saveLevel+1 );
420 return ++dc->saveLevel;
424 /***********************************************************************
425 * RestoreDC (GDI.39)
427 BOOL RestoreDC( HDC hdc, short level )
429 DC * dc, * dcs;
431 dprintf_dc(stddeb, "RestoreDC: %04x %d\n", hdc, level );
432 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
433 if (!dc)
435 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
436 if (!dc) return FALSE;
437 if (level != -1) return FALSE;
438 MF_MetaParam1(dc, META_RESTOREDC, level);
439 return TRUE;
441 if (level == -1) level = dc->saveLevel;
442 if ((level < 1) || (level > (short)dc->saveLevel)) return FALSE;
444 while ((short)dc->saveLevel >= level)
446 HDC hdcs = dc->header.hNext;
447 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return FALSE;
448 dc->header.hNext = dcs->header.hNext;
449 if ((short)--dc->saveLevel < level) SetDCState( hdc, hdcs );
450 DeleteDC( hdcs );
452 return TRUE;
456 /***********************************************************************
457 * CreateDC (GDI.53)
459 HDC CreateDC( LPCSTR driver, LPCSTR device, LPCSTR output, const DEVMODE* initData )
461 DC * dc;
462 HANDLE handle;
464 handle = GDI_AllocObject( sizeof(DC), DC_MAGIC );
465 if (!handle) return 0;
466 dc = (DC *) GDI_HEAP_LIN_ADDR( handle );
468 dprintf_dc(stddeb, "CreateDC(%s %s %s): returning %04x\n",
469 driver, device, output, handle );
471 if (!displayDevCaps)
473 displayDevCaps = (DeviceCaps *) xmalloc( sizeof(DeviceCaps) );
474 DC_FillDevCaps( displayDevCaps );
477 dc->saveLevel = 0;
478 memcpy( &dc->w, &DC_defaultValues, sizeof(DC_defaultValues) );
479 memset( &dc->u.x, 0, sizeof(dc->u.x) );
481 dc->u.x.drawable = rootWindow;
482 dc->u.x.gc = XCreateGC( display, dc->u.x.drawable, 0, NULL );
483 dc->w.flags = 0;
484 dc->w.devCaps = displayDevCaps;
485 dc->w.bitsPerPixel = displayDevCaps->bitsPixel;
486 dc->w.hVisRgn = CreateRectRgn( 0, 0, displayDevCaps->horzRes,
487 displayDevCaps->vertRes );
488 if (!dc->w.hVisRgn)
490 GDI_HEAP_FREE( handle );
491 return 0;
494 DC_InitDC( handle );
496 return handle;
500 /***********************************************************************
501 * CreateIC (GDI.153)
503 HDC CreateIC( LPCSTR driver, LPCSTR device, LPCSTR output, const DEVMODE* initData )
505 /* Nothing special yet for ICs */
506 return CreateDC( driver, device, output, initData );
510 /***********************************************************************
511 * CreateCompatibleDC (GDI.52)
513 HDC CreateCompatibleDC( HDC hdc )
515 DC * dc;
516 HANDLE handle;
517 HBITMAP hbitmap;
518 BITMAPOBJ *bmp;
520 handle = GDI_AllocObject( sizeof(DC), DC_MAGIC );
521 if (!handle) return 0;
522 dc = (DC *) GDI_HEAP_LIN_ADDR( handle );
524 dprintf_dc(stddeb, "CreateCompatibleDC(%04x): returning %04x\n", hdc, handle );
526 /* Create default bitmap */
527 if (!(hbitmap = CreateBitmap( 1, 1, 1, 1, NULL )))
529 GDI_HEAP_FREE( handle );
530 return 0;
532 bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
534 dc->saveLevel = 0;
535 memcpy( &dc->w, &DC_defaultValues, sizeof(DC_defaultValues) );
536 memset( &dc->u.x, 0, sizeof(dc->u.x) );
538 dc->u.x.drawable = bmp->pixmap;
539 dc->u.x.gc = XCreateGC( display, dc->u.x.drawable, 0, NULL );
540 dc->w.flags = DC_MEMORY;
541 dc->w.bitsPerPixel = 1;
542 dc->w.devCaps = displayDevCaps;
543 dc->w.hBitmap = hbitmap;
544 dc->w.hFirstBitmap = hbitmap;
545 dc->w.hVisRgn = CreateRectRgn( 0, 0, 1, 1 );
547 if (!dc->w.hVisRgn)
549 DeleteObject( hbitmap );
550 GDI_HEAP_FREE( handle );
551 return 0;
554 DC_InitDC( handle );
556 return handle;
560 /***********************************************************************
561 * DeleteDC (GDI.68)
563 BOOL DeleteDC( HDC hdc )
565 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
566 if (!dc) return FALSE;
568 dprintf_dc(stddeb, "DeleteDC: %04x\n", hdc );
570 while (dc->saveLevel)
572 DC * dcs;
573 HDC hdcs = dc->header.hNext;
574 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) break;
575 dc->header.hNext = dcs->header.hNext;
576 dc->saveLevel--;
577 DeleteDC( hdcs );
580 if (!(dc->w.flags & DC_SAVED))
582 SelectObject( hdc, STOCK_BLACK_PEN );
583 SelectObject( hdc, STOCK_WHITE_BRUSH );
584 SelectObject( hdc, STOCK_SYSTEM_FONT );
585 XFreeGC( display, dc->u.x.gc );
588 if (dc->w.flags & DC_MEMORY) DeleteObject( dc->w.hFirstBitmap );
589 if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
590 if (dc->w.hVisRgn) DeleteObject( dc->w.hVisRgn );
591 if (dc->w.hGCClipRgn) DeleteObject( dc->w.hGCClipRgn );
593 return GDI_FreeObject( hdc );
597 /***********************************************************************
598 * ResetDC (GDI.376)
600 HDC ResetDC( HDC hdc, /* DEVMODE */ void *devmode )
602 fprintf( stderr, "ResetDC: empty stub!\n" );
603 return hdc;
607 /***********************************************************************
608 * GetDeviceCaps (GDI.80)
610 int GetDeviceCaps( HDC hdc, WORD cap )
612 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
613 if (!dc) return 0;
615 if (cap > sizeof(DeviceCaps)-sizeof(WORD)) return 0;
617 dprintf_dc(stddeb, "GetDeviceCaps(%04x,%d): returning %d\n",
618 hdc, cap, *(WORD *)(((char *)dc->w.devCaps) + cap) );
619 return *(WORD *)(((char *)dc->w.devCaps) + cap);
623 /***********************************************************************
624 * SetBkColor (GDI.1)
626 COLORREF SetBkColor( HDC hdc, COLORREF color )
628 COLORREF oldColor;
629 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
630 if (!dc)
632 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
633 if (!dc) return 0x80000000;
634 MF_MetaParam2(dc, META_SETBKCOLOR, HIWORD(color), LOWORD(color));
635 return 0; /* ?? */
638 oldColor = dc->w.backgroundColor;
639 dc->w.backgroundColor = color;
640 dc->w.backgroundPixel = COLOR_ToPhysical( dc, color );
641 return oldColor;
645 /***********************************************************************
646 * SetTextColor (GDI.9)
648 COLORREF SetTextColor( HDC hdc, COLORREF color )
650 COLORREF oldColor;
651 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
652 if (!dc)
654 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
655 if (!dc) return 0x80000000;
656 MF_MetaParam2(dc, META_SETTEXTCOLOR, HIWORD(color), LOWORD(color));
657 return 0; /* ?? */
660 oldColor = dc->w.textColor;
661 dc->w.textColor = color;
662 dc->w.textPixel = COLOR_ToPhysical( dc, color );
663 return oldColor;
667 /***********************************************************************
668 * SetTextAlign (GDI.346)
670 WORD SetTextAlign( HDC hdc, WORD textAlign )
672 WORD prevAlign;
673 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
674 if (!dc)
676 if (!(dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC ))) return 0;
677 MF_MetaParam1( dc, META_SETTEXTALIGN, textAlign );
678 return 1;
680 prevAlign = dc->w.textAlign;
681 dc->w.textAlign = textAlign;
682 return prevAlign;
686 /***********************************************************************
687 * GetDCOrg (GDI.79)
689 DWORD GetDCOrg( HDC hdc )
691 Window root;
692 int x, y, w, h, border, depth;
694 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
695 if (!dc) return 0;
696 if (dc->w.flags & DC_MEMORY) return 0;
697 XGetGeometry( display, dc->u.x.drawable, &root,
698 &x, &y, &w, &h, &border, &depth );
699 return MAKELONG( dc->w.DCOrgX + (WORD)x, dc->w.DCOrgY + (WORD)y );
703 /***********************************************************************
704 * SetDCOrg (GDI.117)
706 DWORD SetDCOrg( HDC hdc, short x, short y )
708 DWORD prevOrg;
709 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
710 if (!dc) return 0;
711 prevOrg = dc->w.DCOrgX | (dc->w.DCOrgY << 16);
712 dc->w.DCOrgX = x;
713 dc->w.DCOrgY = y;
714 return prevOrg;