Release 960114
[wine/gsoc-2012-control.git] / objects / dc.c
blob68e7ff3bc20782a2fe2d54e0774b005ceb5ba801
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_SetupDCForPatBlt
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_SetupDCForBrush
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_SetupDCForPen
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("NPFMT"): returning "NPFMT"\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;
366 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
367 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return;
368 if (!dcs->w.flags & DC_SAVED) return;
369 dprintf_dc(stddeb, "SetDCState: "NPFMT" "NPFMT"\n", hdc, hdcs );
371 /* Save the regions before overwriting everything */
372 hVisRgn = dc->w.hVisRgn;
373 hClipRgn = dc->w.hClipRgn;
374 hGCClipRgn = dc->w.hGCClipRgn;
375 memcpy( &dc->w, &dcs->w, sizeof(dc->w) );
376 memcpy( &dc->u.x.pen, &dcs->u.x.pen, sizeof(dc->u.x.pen) );
377 dc->w.flags &= ~DC_SAVED;
379 /* Restore the regions */
380 dc->w.hVisRgn = hVisRgn;
381 dc->w.hClipRgn = hClipRgn;
382 dc->w.hGCClipRgn = hGCClipRgn;
383 CombineRgn( dc->w.hVisRgn, dcs->w.hVisRgn, 0, RGN_COPY );
384 SelectClipRgn( hdc, dcs->w.hClipRgn );
386 SelectObject( hdc, dcs->w.hBrush );
387 SelectObject( hdc, dcs->w.hFont );
388 COLOR_SetMapping( dc, dcs->u.x.pal.hMapping,
389 dcs->u.x.pal.hRevMapping, dcs->u.x.pal.mappingSize );
393 /***********************************************************************
394 * SaveDC (GDI.30)
396 int SaveDC( HDC hdc )
398 HDC hdcs;
399 DC * dc, * dcs;
401 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
402 if (!dc)
404 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
405 if (!dc) return 0;
406 MF_MetaParam0(dc, META_SAVEDC);
407 return 1; /* ?? */
409 if (!(hdcs = GetDCState( hdc ))) return 0;
410 dcs = (DC *) GDI_HEAP_LIN_ADDR( hdcs );
411 dcs->header.hNext = dc->header.hNext;
412 dc->header.hNext = hdcs;
413 dprintf_dc(stddeb, "SaveDC("NPFMT"): returning %d\n", hdc, dc->saveLevel+1 );
414 return ++dc->saveLevel;
418 /***********************************************************************
419 * RestoreDC (GDI.39)
421 BOOL RestoreDC( HDC hdc, short level )
423 DC * dc, * dcs;
425 dprintf_dc(stddeb, "RestoreDC: "NPFMT" %d\n", hdc, level );
426 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
427 if (!dc)
429 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
430 if (!dc) return FALSE;
431 if (level != -1) return FALSE;
432 MF_MetaParam1(dc, META_RESTOREDC, level);
433 return TRUE;
435 if (level == -1) level = dc->saveLevel;
436 if ((level < 1) || (level > (short)dc->saveLevel)) return FALSE;
438 while ((short)dc->saveLevel >= level)
440 HDC hdcs = dc->header.hNext;
441 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) return FALSE;
442 dc->header.hNext = dcs->header.hNext;
443 if ((short)--dc->saveLevel < level) SetDCState( hdc, hdcs );
444 DeleteDC( hdcs );
446 return TRUE;
450 /***********************************************************************
451 * CreateDC (GDI.53)
453 HDC CreateDC( LPSTR driver, LPSTR device, LPSTR output, LPSTR initData )
455 DC * dc;
456 HANDLE handle;
458 handle = GDI_AllocObject( sizeof(DC), DC_MAGIC );
459 if (!handle) return 0;
460 dc = (DC *) GDI_HEAP_LIN_ADDR( handle );
462 dprintf_dc(stddeb, "CreateDC(%s %s %s): returning "NPFMT"\n",
463 driver, device, output, handle );
465 if (!displayDevCaps)
467 displayDevCaps = (DeviceCaps *) xmalloc( sizeof(DeviceCaps) );
468 DC_FillDevCaps( displayDevCaps );
471 dc->saveLevel = 0;
472 memcpy( &dc->w, &DC_defaultValues, sizeof(DC_defaultValues) );
473 memset( &dc->u.x, 0, sizeof(dc->u.x) );
475 dc->u.x.drawable = rootWindow;
476 dc->u.x.gc = XCreateGC( display, dc->u.x.drawable, 0, NULL );
477 dc->w.flags = 0;
478 dc->w.devCaps = displayDevCaps;
479 dc->w.bitsPerPixel = displayDevCaps->bitsPixel;
480 dc->w.hVisRgn = CreateRectRgn( 0, 0, displayDevCaps->horzRes,
481 displayDevCaps->vertRes );
482 if (!dc->w.hVisRgn)
484 GDI_HEAP_FREE( handle );
485 return 0;
488 DC_InitDC( handle );
490 return handle;
494 /***********************************************************************
495 * CreateIC (GDI.153)
497 HDC CreateIC( LPSTR driver, LPSTR device, LPSTR output, LPSTR initData )
499 /* Nothing special yet for ICs */
500 return CreateDC( driver, device, output, initData );
504 /***********************************************************************
505 * CreateCompatibleDC (GDI.52)
507 HDC CreateCompatibleDC( HDC hdc )
509 DC * dc;
510 HANDLE handle;
511 HBITMAP hbitmap;
512 BITMAPOBJ *bmp;
514 handle = GDI_AllocObject( sizeof(DC), DC_MAGIC );
515 if (!handle) return 0;
516 dc = (DC *) GDI_HEAP_LIN_ADDR( handle );
518 dprintf_dc(stddeb, "CreateCompatibleDC("NPFMT"): returning "NPFMT"\n", hdc, handle );
520 /* Create default bitmap */
521 if (!(hbitmap = CreateBitmap( 1, 1, 1, 1, NULL )))
523 GDI_HEAP_FREE( handle );
524 return 0;
526 bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
528 dc->saveLevel = 0;
529 memcpy( &dc->w, &DC_defaultValues, sizeof(DC_defaultValues) );
530 memset( &dc->u.x, 0, sizeof(dc->u.x) );
532 dc->u.x.drawable = bmp->pixmap;
533 dc->u.x.gc = XCreateGC( display, dc->u.x.drawable, 0, NULL );
534 dc->w.flags = DC_MEMORY;
535 dc->w.bitsPerPixel = 1;
536 dc->w.devCaps = displayDevCaps;
537 dc->w.hBitmap = hbitmap;
538 dc->w.hFirstBitmap = hbitmap;
539 dc->w.hVisRgn = CreateRectRgn( 0, 0, 1, 1 );
541 if (!dc->w.hVisRgn)
543 DeleteObject( hbitmap );
544 GDI_HEAP_FREE( handle );
545 return 0;
548 DC_InitDC( handle );
550 return handle;
554 /***********************************************************************
555 * DeleteDC (GDI.68)
557 BOOL DeleteDC( HDC hdc )
559 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
560 if (!dc) return FALSE;
562 dprintf_dc(stddeb, "DeleteDC: "NPFMT"\n", hdc );
564 while (dc->saveLevel)
566 DC * dcs;
567 HDC hdcs = dc->header.hNext;
568 if (!(dcs = (DC *) GDI_GetObjPtr( hdcs, DC_MAGIC ))) break;
569 dc->header.hNext = dcs->header.hNext;
570 dc->saveLevel--;
571 DeleteDC( hdcs );
574 if (!(dc->w.flags & DC_SAVED))
576 SelectObject( hdc, STOCK_BLACK_PEN );
577 SelectObject( hdc, STOCK_WHITE_BRUSH );
578 SelectObject( hdc, STOCK_SYSTEM_FONT );
579 XFreeGC( display, dc->u.x.gc );
582 if (dc->w.flags & DC_MEMORY) DeleteObject( dc->w.hFirstBitmap );
583 if (dc->w.hClipRgn) DeleteObject( dc->w.hClipRgn );
584 if (dc->w.hVisRgn) DeleteObject( dc->w.hVisRgn );
585 if (dc->w.hGCClipRgn) DeleteObject( dc->w.hGCClipRgn );
587 return GDI_FreeObject( hdc );
591 /***********************************************************************
592 * ResetDC (GDI.376)
594 HDC ResetDC( HDC hdc, /* DEVMODE */ void *devmode )
596 fprintf( stderr, "ResetDC: empty stub!\n" );
597 return hdc;
601 /***********************************************************************
602 * GetDeviceCaps (GDI.80)
604 int GetDeviceCaps( HDC hdc, WORD cap )
606 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
607 if (!dc) return 0;
609 if (cap > sizeof(DeviceCaps)-sizeof(WORD)) return 0;
611 dprintf_dc(stddeb, "GetDeviceCaps("NPFMT",%d): returning %d\n",
612 hdc, cap, *(WORD *)(((char *)dc->w.devCaps) + cap) );
613 return *(WORD *)(((char *)dc->w.devCaps) + cap);
617 /***********************************************************************
618 * SetBkColor (GDI.1)
620 COLORREF SetBkColor( HDC hdc, COLORREF color )
622 COLORREF oldColor;
623 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
624 if (!dc)
626 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
627 if (!dc) return 0x80000000;
628 MF_MetaParam2(dc, META_SETBKCOLOR, HIWORD(color), LOWORD(color));
629 return 0; /* ?? */
632 oldColor = dc->w.backgroundColor;
633 dc->w.backgroundColor = color;
634 dc->w.backgroundPixel = COLOR_ToPhysical( dc, color );
635 return oldColor;
639 /***********************************************************************
640 * SetTextColor (GDI.9)
642 COLORREF SetTextColor( HDC hdc, COLORREF color )
644 COLORREF oldColor;
645 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
646 if (!dc)
648 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
649 if (!dc) return 0x80000000;
650 MF_MetaParam2(dc, META_SETTEXTCOLOR, HIWORD(color), LOWORD(color));
651 return 0; /* ?? */
654 oldColor = dc->w.textColor;
655 dc->w.textColor = color;
656 dc->w.textPixel = COLOR_ToPhysical( dc, color );
657 return oldColor;
661 /***********************************************************************
662 * GetDCOrg (GDI.79)
664 DWORD GetDCOrg( HDC hdc )
666 Window root;
667 int x, y, w, h, border, depth;
669 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
670 if (!dc) return 0;
671 if (dc->w.flags & DC_MEMORY) return 0;
672 XGetGeometry( display, dc->u.x.drawable, &root,
673 &x, &y, &w, &h, &border, &depth );
674 return MAKELONG( dc->w.DCOrgX + (WORD)x, dc->w.DCOrgY + (WORD)y );
678 /***********************************************************************
679 * SetDCOrg (GDI.117)
681 DWORD SetDCOrg( HDC hdc, short x, short y )
683 DWORD prevOrg;
684 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
685 if (!dc) return 0;
686 prevOrg = dc->w.DCOrgX | (dc->w.DCOrgY << 16);
687 dc->w.DCOrgX = x;
688 dc->w.DCOrgY = y;
689 return prevOrg;