Get rid of the global INTERNAL_[XY]WSTODS macros.
[wine/hacks.git] / dlls / x11drv / graphics.c
blob4fbba3dd8b8b0589e69e64845ef6b777806839d1
1 /*
2 * X11 graphics driver graphics functions
4 * Copyright 1993,1994 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
22 * FIXME: only some of these functions obey the GM_ADVANCED
23 * graphics mode
26 #include "config.h"
28 #include <math.h>
29 #ifdef HAVE_FLOAT_H
30 # include <float.h>
31 #endif
32 #include <stdlib.h>
33 #ifndef PI
34 #define PI M_PI
35 #endif
36 #include <string.h>
37 #include <X11/Intrinsic.h>
39 #include "x11drv.h"
40 #include "x11font.h"
41 #include "gdi.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
46 #define ABS(x) ((x)<0?(-(x)):(x))
48 /* ROP code to GC function conversion */
49 const int X11DRV_XROPfunction[16] =
51 GXclear, /* R2_BLACK */
52 GXnor, /* R2_NOTMERGEPEN */
53 GXandInverted, /* R2_MASKNOTPEN */
54 GXcopyInverted, /* R2_NOTCOPYPEN */
55 GXandReverse, /* R2_MASKPENNOT */
56 GXinvert, /* R2_NOT */
57 GXxor, /* R2_XORPEN */
58 GXnand, /* R2_NOTMASKPEN */
59 GXand, /* R2_MASKPEN */
60 GXequiv, /* R2_NOTXORPEN */
61 GXnoop, /* R2_NOP */
62 GXorInverted, /* R2_MERGENOTPEN */
63 GXcopy, /* R2_COPYPEN */
64 GXorReverse, /* R2_MERGEPENNOT */
65 GXor, /* R2_MERGEPEN */
66 GXset /* R2_WHITE */
70 /***********************************************************************
71 * X11DRV_SetupGCForPatBlt
73 * Setup the GC for a PatBlt operation using current brush.
74 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
75 * Return FALSE if brush is BS_NULL, TRUE otherwise.
77 BOOL X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE *physDev, GC gc, BOOL fMapColors )
79 XGCValues val;
80 unsigned long mask;
81 Pixmap pixmap = 0;
82 POINT pt;
84 if (physDev->brush.style == BS_NULL) return FALSE;
85 if (physDev->brush.pixel == -1)
87 /* Special case used for monochrome pattern brushes.
88 * We need to swap foreground and background because
89 * Windows does it the wrong way...
91 val.foreground = physDev->backgroundPixel;
92 val.background = physDev->textPixel;
94 else
96 val.foreground = physDev->brush.pixel;
97 val.background = physDev->backgroundPixel;
99 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
101 val.foreground = X11DRV_PALETTE_XPixelToPalette[val.foreground];
102 val.background = X11DRV_PALETTE_XPixelToPalette[val.background];
105 val.function = X11DRV_XROPfunction[GetROP2(physDev->hdc)-1];
107 ** Let's replace GXinvert by GXxor with (black xor white)
108 ** This solves the selection color and leak problems in excel
109 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
111 if (val.function == GXinvert)
113 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
114 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
115 val.function = GXxor;
117 val.fill_style = physDev->brush.fillStyle;
118 switch(val.fill_style)
120 case FillStippled:
121 case FillOpaqueStippled:
122 if (GetBkMode(physDev->hdc)==OPAQUE) val.fill_style = FillOpaqueStippled;
123 val.stipple = physDev->brush.pixmap;
124 mask = GCStipple;
125 break;
127 case FillTiled:
128 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
130 register int x, y;
131 XImage *image;
132 wine_tsx11_lock();
133 pixmap = XCreatePixmap( gdi_display, root_window, 8, 8, screen_depth );
134 image = XGetImage( gdi_display, physDev->brush.pixmap, 0, 0, 8, 8,
135 AllPlanes, ZPixmap );
136 for (y = 0; y < 8; y++)
137 for (x = 0; x < 8; x++)
138 XPutPixel( image, x, y,
139 X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, x, y)] );
140 XPutImage( gdi_display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
141 XDestroyImage( image );
142 wine_tsx11_unlock();
143 val.tile = pixmap;
145 else val.tile = physDev->brush.pixmap;
146 mask = GCTile;
147 break;
149 default:
150 mask = 0;
151 break;
153 GetBrushOrgEx( physDev->hdc, &pt );
154 val.ts_x_origin = physDev->org.x + pt.x;
155 val.ts_y_origin = physDev->org.y + pt.y;
156 val.fill_rule = (GetPolyFillMode(physDev->hdc) == WINDING) ? WindingRule : EvenOddRule;
157 wine_tsx11_lock();
158 XChangeGC( gdi_display, gc,
159 GCFunction | GCForeground | GCBackground | GCFillStyle |
160 GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
161 &val );
162 if (pixmap) XFreePixmap( gdi_display, pixmap );
163 wine_tsx11_unlock();
164 return TRUE;
168 /***********************************************************************
169 * X11DRV_SetupGCForBrush
171 * Setup physDev->gc for drawing operations using current brush.
172 * Return FALSE if brush is BS_NULL, TRUE otherwise.
174 BOOL X11DRV_SetupGCForBrush( X11DRV_PDEVICE *physDev )
176 return X11DRV_SetupGCForPatBlt( physDev, physDev->gc, FALSE );
180 /***********************************************************************
181 * X11DRV_SetupGCForPen
183 * Setup physDev->gc for drawing operations using current pen.
184 * Return FALSE if pen is PS_NULL, TRUE otherwise.
186 BOOL X11DRV_SetupGCForPen( X11DRV_PDEVICE *physDev )
188 XGCValues val;
189 UINT rop2 = GetROP2(physDev->hdc);
191 if (physDev->pen.style == PS_NULL) return FALSE;
193 switch (rop2)
195 case R2_BLACK :
196 val.foreground = BlackPixel( gdi_display, DefaultScreen(gdi_display) );
197 val.function = GXcopy;
198 break;
199 case R2_WHITE :
200 val.foreground = WhitePixel( gdi_display, DefaultScreen(gdi_display) );
201 val.function = GXcopy;
202 break;
203 case R2_XORPEN :
204 val.foreground = physDev->pen.pixel;
205 /* It is very unlikely someone wants to XOR with 0 */
206 /* This fixes the rubber-drawings in paintbrush */
207 if (val.foreground == 0)
208 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
209 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
210 val.function = GXxor;
211 break;
212 default :
213 val.foreground = physDev->pen.pixel;
214 val.function = X11DRV_XROPfunction[rop2-1];
216 val.background = physDev->backgroundPixel;
217 val.fill_style = FillSolid;
218 val.line_width = physDev->pen.width;
219 if (val.line_width <= 1) {
220 val.cap_style = CapNotLast;
221 } else {
222 switch (physDev->pen.endcap)
224 case PS_ENDCAP_SQUARE:
225 val.cap_style = CapProjecting;
226 break;
227 case PS_ENDCAP_FLAT:
228 val.cap_style = CapButt;
229 break;
230 case PS_ENDCAP_ROUND:
231 default:
232 val.cap_style = CapRound;
235 switch (physDev->pen.linejoin)
237 case PS_JOIN_BEVEL:
238 val.join_style = JoinBevel;
239 break;
240 case PS_JOIN_MITER:
241 val.join_style = JoinMiter;
242 break;
243 case PS_JOIN_ROUND:
244 default:
245 val.join_style = JoinRound;
247 wine_tsx11_lock();
248 if ((physDev->pen.width <= 1) &&
249 (physDev->pen.style != PS_SOLID) &&
250 (physDev->pen.style != PS_INSIDEFRAME))
252 XSetDashes( gdi_display, physDev->gc, 0, physDev->pen.dashes, physDev->pen.dash_len );
253 val.line_style = (GetBkMode(physDev->hdc) == OPAQUE) ? LineDoubleDash : LineOnOffDash;
255 else val.line_style = LineSolid;
257 XChangeGC( gdi_display, physDev->gc,
258 GCFunction | GCForeground | GCBackground | GCLineWidth |
259 GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
260 wine_tsx11_unlock();
261 return TRUE;
265 /***********************************************************************
266 * X11DRV_SetupGCForText
268 * Setup physDev->gc for text drawing operations.
269 * Return FALSE if the font is null, TRUE otherwise.
271 BOOL X11DRV_SetupGCForText( X11DRV_PDEVICE *physDev )
273 XFontStruct* xfs = XFONT_GetFontStruct( physDev->font );
275 if( xfs )
277 XGCValues val;
279 val.function = GXcopy; /* Text is always GXcopy */
280 val.foreground = physDev->textPixel;
281 val.background = physDev->backgroundPixel;
282 val.fill_style = FillSolid;
283 val.font = xfs->fid;
285 wine_tsx11_lock();
286 XChangeGC( gdi_display, physDev->gc,
287 GCFunction | GCForeground | GCBackground | GCFillStyle |
288 GCFont, &val );
289 wine_tsx11_unlock();
290 return TRUE;
292 WARN("Physical font failure\n" );
293 return FALSE;
296 /***********************************************************************
297 * X11DRV_XWStoDS
299 * Performs a world-to-viewport transformation on the specified width.
301 INT X11DRV_XWStoDS( X11DRV_PDEVICE *physDev, INT width )
303 POINT pt[2];
305 pt[0].x = 0;
306 pt[0].y = 0;
307 pt[1].x = width;
308 pt[1].y = 0;
309 LPtoDP( physDev->hdc, pt, 2 );
310 return pt[1].x - pt[0].x;
313 /***********************************************************************
314 * X11DRV_YWStoDS
316 * Performs a world-to-viewport transformation on the specified height.
318 INT X11DRV_YWStoDS( X11DRV_PDEVICE *physDev, INT height )
320 POINT pt[2];
322 pt[0].x = 0;
323 pt[0].y = 0;
324 pt[1].x = 0;
325 pt[1].y = height;
326 LPtoDP( physDev->hdc, pt, 2 );
327 return pt[1].y - pt[0].y;
330 /***********************************************************************
331 * X11DRV_LineTo
333 BOOL
334 X11DRV_LineTo( X11DRV_PDEVICE *physDev, INT x, INT y )
336 POINT pt[2];
338 if (X11DRV_SetupGCForPen( physDev )) {
339 /* Update the pixmap from the DIB section */
340 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
342 GetCurrentPositionEx( physDev->hdc, &pt[0] );
343 pt[1].x = x;
344 pt[1].y = y;
345 LPtoDP( physDev->hdc, pt, 2 );
347 wine_tsx11_lock();
348 XDrawLine(gdi_display, physDev->drawable, physDev->gc,
349 physDev->org.x + pt[0].x, physDev->org.y + pt[0].y,
350 physDev->org.x + pt[1].x, physDev->org.y + pt[1].y );
351 wine_tsx11_unlock();
353 /* Update the DIBSection from the pixmap */
354 X11DRV_UnlockDIBSection(physDev, TRUE);
356 return TRUE;
361 /***********************************************************************
362 * X11DRV_DrawArc
364 * Helper functions for Arc(), Chord() and Pie().
365 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
368 static BOOL
369 X11DRV_DrawArc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
370 INT bottom, INT xstart, INT ystart,
371 INT xend, INT yend, INT lines )
373 INT xcenter, ycenter, istart_angle, idiff_angle;
374 INT width, oldwidth;
375 double start_angle, end_angle;
376 XPoint points[4];
377 BOOL update = FALSE;
378 POINT start, end;
379 RECT rc;
381 SetRect(&rc, left, top, right, bottom);
382 start.x = xstart;
383 start.y = ystart;
384 end.x = xend;
385 end.y = yend;
386 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
387 LPtoDP(physDev->hdc, &start, 1);
388 LPtoDP(physDev->hdc, &end, 1);
390 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
391 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
392 if ((rc.left == rc.right) || (rc.top == rc.bottom)
393 ||(lines && ((rc.right-rc.left==1)||(rc.bottom-rc.top==1)))) return TRUE;
395 if (GetArcDirection( physDev->hdc ) == AD_CLOCKWISE)
396 { POINT tmp = start; start = end; end = tmp; }
398 oldwidth = width = physDev->pen.width;
399 if (!width) width = 1;
400 if(physDev->pen.style == PS_NULL) width = 0;
402 if ((physDev->pen.style == PS_INSIDEFRAME))
404 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
405 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
406 rc.left += width / 2;
407 rc.right -= (width - 1) / 2;
408 rc.top += width / 2;
409 rc.bottom -= (width - 1) / 2;
411 if(width == 0) width = 1; /* more accurate */
412 physDev->pen.width = width;
414 xcenter = (rc.right + rc.left) / 2;
415 ycenter = (rc.bottom + rc.top) / 2;
416 start_angle = atan2( (double)(ycenter-start.y)*(rc.right-rc.left),
417 (double)(start.x-xcenter)*(rc.bottom-rc.top) );
418 end_angle = atan2( (double)(ycenter-end.y)*(rc.right-rc.left),
419 (double)(end.x-xcenter)*(rc.bottom-rc.top) );
420 if ((start.x==end.x)&&(start.y==end.y))
421 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
422 start_angle = 0;
423 end_angle = 2* PI;
425 else /* notorious cases */
426 if ((start_angle == PI)&&( end_angle <0))
427 start_angle = - PI;
428 else
429 if ((end_angle == PI)&&( start_angle <0))
430 end_angle = - PI;
431 istart_angle = (INT)(start_angle * 180 * 64 / PI + 0.5);
432 idiff_angle = (INT)((end_angle - start_angle) * 180 * 64 / PI + 0.5);
433 if (idiff_angle <= 0) idiff_angle += 360 * 64;
435 /* Update the pixmap from the DIB section */
436 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
438 /* Fill arc with brush if Chord() or Pie() */
440 if ((lines > 0) && X11DRV_SetupGCForBrush( physDev )) {
441 wine_tsx11_lock();
442 XSetArcMode( gdi_display, physDev->gc, (lines==1) ? ArcChord : ArcPieSlice);
443 XFillArc( gdi_display, physDev->drawable, physDev->gc,
444 physDev->org.x + rc.left, physDev->org.y + rc.top,
445 rc.right-rc.left-1, rc.bottom-rc.top-1, istart_angle, idiff_angle );
446 wine_tsx11_unlock();
447 update = TRUE;
450 /* Draw arc and lines */
452 if (X11DRV_SetupGCForPen( physDev ))
454 wine_tsx11_lock();
455 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
456 physDev->org.x + rc.left, physDev->org.y + rc.top,
457 rc.right-rc.left-1, rc.bottom-rc.top-1, istart_angle, idiff_angle );
458 if (lines) {
459 /* use the truncated values */
460 start_angle=(double)istart_angle*PI/64./180.;
461 end_angle=(double)(istart_angle+idiff_angle)*PI/64./180.;
462 /* calculate the endpoints and round correctly */
463 points[0].x = (int) floor(physDev->org.x + (rc.right+rc.left)/2.0 +
464 cos(start_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
465 points[0].y = (int) floor(physDev->org.y + (rc.top+rc.bottom)/2.0 -
466 sin(start_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
467 points[1].x = (int) floor(physDev->org.x + (rc.right+rc.left)/2.0 +
468 cos(end_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
469 points[1].y = (int) floor(physDev->org.y + (rc.top+rc.bottom)/2.0 -
470 sin(end_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
472 /* OK, this stuff is optimized for Xfree86
473 * which is probably the server most used by
474 * wine users. Other X servers will not
475 * display correctly. (eXceed for instance)
476 * so if you feel you must make changes, make sure that
477 * you either use Xfree86 or separate your changes
478 * from these (compile switch or whatever)
480 if (lines == 2) {
481 INT dx1,dy1;
482 points[3] = points[1];
483 points[1].x = physDev->org.x + xcenter;
484 points[1].y = physDev->org.y + ycenter;
485 points[2] = points[1];
486 dx1=points[1].x-points[0].x;
487 dy1=points[1].y-points[0].y;
488 if(((rc.top-rc.bottom) | -2) == -2)
489 if(dy1>0) points[1].y--;
490 if(dx1<0) {
491 if (((-dx1)*64)<=ABS(dy1)*37) points[0].x--;
492 if(((-dx1*9))<(dy1*16)) points[0].y--;
493 if( dy1<0 && ((dx1*9)) < (dy1*16)) points[0].y--;
494 } else {
495 if(dy1 < 0) points[0].y--;
496 if(((rc.right-rc.left) | -2) == -2) points[1].x--;
498 dx1=points[3].x-points[2].x;
499 dy1=points[3].y-points[2].y;
500 if(((rc.top-rc.bottom) | -2 ) == -2)
501 if(dy1 < 0) points[2].y--;
502 if( dx1<0){
503 if( dy1>0) points[3].y--;
504 if(((rc.right-rc.left) | -2) == -2 ) points[2].x--;
505 }else {
506 points[3].y--;
507 if( dx1 * 64 < dy1 * -37 ) points[3].x--;
509 lines++;
511 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
512 points, lines+1, CoordModeOrigin );
514 wine_tsx11_unlock();
515 update = TRUE;
518 /* Update the DIBSection of the pixmap */
519 X11DRV_UnlockDIBSection(physDev, update);
521 physDev->pen.width = oldwidth;
522 return TRUE;
526 /***********************************************************************
527 * X11DRV_Arc
529 BOOL
530 X11DRV_Arc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
531 INT xstart, INT ystart, INT xend, INT yend )
533 return X11DRV_DrawArc( physDev, left, top, right, bottom,
534 xstart, ystart, xend, yend, 0 );
538 /***********************************************************************
539 * X11DRV_Pie
541 BOOL
542 X11DRV_Pie( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
543 INT xstart, INT ystart, INT xend, INT yend )
545 return X11DRV_DrawArc( physDev, left, top, right, bottom,
546 xstart, ystart, xend, yend, 2 );
549 /***********************************************************************
550 * X11DRV_Chord
552 BOOL
553 X11DRV_Chord( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
554 INT xstart, INT ystart, INT xend, INT yend )
556 return X11DRV_DrawArc( physDev, left, top, right, bottom,
557 xstart, ystart, xend, yend, 1 );
561 /***********************************************************************
562 * X11DRV_Ellipse
564 BOOL
565 X11DRV_Ellipse( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom )
567 INT width, oldwidth;
568 BOOL update = FALSE;
569 RECT rc;
571 SetRect(&rc, left, top, right, bottom);
572 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
574 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
576 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
577 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
579 oldwidth = width = physDev->pen.width;
580 if (!width) width = 1;
581 if(physDev->pen.style == PS_NULL) width = 0;
583 if ((physDev->pen.style == PS_INSIDEFRAME))
585 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
586 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
587 rc.left += width / 2;
588 rc.right -= (width - 1) / 2;
589 rc.top += width / 2;
590 rc.bottom -= (width - 1) / 2;
592 if(width == 0) width = 1; /* more accurate */
593 physDev->pen.width = width;
595 /* Update the pixmap from the DIB section */
596 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
598 if (X11DRV_SetupGCForBrush( physDev ))
600 wine_tsx11_lock();
601 XFillArc( gdi_display, physDev->drawable, physDev->gc,
602 physDev->org.x + rc.left, physDev->org.y + rc.top,
603 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
604 wine_tsx11_unlock();
605 update = TRUE;
607 if (X11DRV_SetupGCForPen( physDev ))
609 wine_tsx11_lock();
610 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
611 physDev->org.x + rc.left, physDev->org.y + rc.top,
612 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
613 wine_tsx11_unlock();
614 update = TRUE;
617 /* Update the DIBSection from the pixmap */
618 X11DRV_UnlockDIBSection(physDev, update);
620 physDev->pen.width = oldwidth;
621 return TRUE;
625 /***********************************************************************
626 * X11DRV_Rectangle
628 BOOL
629 X11DRV_Rectangle(X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
631 INT width, oldwidth, oldjoinstyle;
632 BOOL update = FALSE;
633 RECT rc;
635 TRACE("(%d %d %d %d)\n", left, top, right, bottom);
637 SetRect(&rc, left, top, right, bottom);
638 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
640 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
642 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
643 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
645 oldwidth = width = physDev->pen.width;
646 if (!width) width = 1;
647 if(physDev->pen.style == PS_NULL) width = 0;
649 if ((physDev->pen.style == PS_INSIDEFRAME))
651 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
652 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
653 rc.left += width / 2;
654 rc.right -= (width - 1) / 2;
655 rc.top += width / 2;
656 rc.bottom -= (width - 1) / 2;
658 if(width == 1) width = 0;
659 physDev->pen.width = width;
660 oldjoinstyle = physDev->pen.linejoin;
661 if(physDev->pen.type != PS_GEOMETRIC)
662 physDev->pen.linejoin = PS_JOIN_MITER;
664 /* Update the pixmap from the DIB section */
665 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
667 if ((rc.right > rc.left + width) && (rc.bottom > rc.top + width))
669 if (X11DRV_SetupGCForBrush( physDev ))
671 wine_tsx11_lock();
672 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
673 physDev->org.x + rc.left + (width + 1) / 2,
674 physDev->org.y + rc.top + (width + 1) / 2,
675 rc.right-rc.left-width-1, rc.bottom-rc.top-width-1);
676 wine_tsx11_unlock();
677 update = TRUE;
680 if (X11DRV_SetupGCForPen( physDev ))
682 wine_tsx11_lock();
683 XDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
684 physDev->org.x + rc.left, physDev->org.y + rc.top,
685 rc.right-rc.left-1, rc.bottom-rc.top-1 );
686 wine_tsx11_unlock();
687 update = TRUE;
690 /* Update the DIBSection from the pixmap */
691 X11DRV_UnlockDIBSection(physDev, update);
693 physDev->pen.width = oldwidth;
694 physDev->pen.linejoin = oldjoinstyle;
695 return TRUE;
698 /***********************************************************************
699 * X11DRV_RoundRect
701 BOOL
702 X11DRV_RoundRect( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
703 INT bottom, INT ell_width, INT ell_height )
705 INT width, oldwidth, oldendcap;
706 BOOL update = FALSE;
707 RECT rc;
708 POINT pts[2];
710 TRACE("(%d %d %d %d %d %d\n",
711 left, top, right, bottom, ell_width, ell_height);
713 SetRect(&rc, left, top, right, bottom);
714 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
716 if ((rc.left == rc.right) || (rc.top == rc.bottom))
717 return TRUE;
719 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
720 called with width/height < 0 */
721 pts[0].x = pts[0].y = 0;
722 pts[1].x = ell_width;
723 pts[1].y = ell_height;
724 LPtoDP(physDev->hdc, pts, 2);
725 ell_width = max(abs( pts[1].x - pts[0].x ), 1);
726 ell_height = max(abs( pts[1].y - pts[0].y ), 1);
728 /* Fix the coordinates */
730 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
731 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
733 oldwidth = width = physDev->pen.width;
734 oldendcap = physDev->pen.endcap;
735 if (!width) width = 1;
736 if(physDev->pen.style == PS_NULL) width = 0;
738 if ((physDev->pen.style == PS_INSIDEFRAME))
740 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
741 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
742 rc.left += width / 2;
743 rc.right -= (width - 1) / 2;
744 rc.top += width / 2;
745 rc.bottom -= (width - 1) / 2;
747 if(width == 0) width = 1;
748 physDev->pen.width = width;
749 physDev->pen.endcap = PS_ENDCAP_SQUARE;
751 /* Update the pixmap from the DIB section */
752 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
754 wine_tsx11_lock();
755 if (X11DRV_SetupGCForBrush( physDev ))
757 if (ell_width > (rc.right-rc.left) )
758 if (ell_height > (rc.bottom-rc.top) )
759 XFillArc( gdi_display, physDev->drawable, physDev->gc,
760 physDev->org.x + rc.left, physDev->org.y + rc.top,
761 rc.right - rc.left - 1, rc.bottom - rc.top - 1,
762 0, 360 * 64 );
763 else{
764 XFillArc( gdi_display, physDev->drawable, physDev->gc,
765 physDev->org.x + rc.left, physDev->org.y + rc.top,
766 rc.right - rc.left - 1, ell_height, 0, 180 * 64 );
767 XFillArc( gdi_display, physDev->drawable, physDev->gc,
768 physDev->org.x + rc.left,
769 physDev->org.y + rc.bottom - ell_height - 1,
770 rc.right - rc.left - 1, ell_height, 180 * 64,
771 180 * 64 );
773 else if (ell_height > (rc.bottom-rc.top) ){
774 XFillArc( gdi_display, physDev->drawable, physDev->gc,
775 physDev->org.x + rc.left, physDev->org.y + rc.top,
776 ell_width, rc.bottom - rc.top - 1, 90 * 64, 180 * 64 );
777 XFillArc( gdi_display, physDev->drawable, physDev->gc,
778 physDev->org.x + rc.right - ell_width - 1, physDev->org.y + rc.top,
779 ell_width, rc.bottom - rc.top - 1, 270 * 64, 180 * 64 );
780 }else{
781 XFillArc( gdi_display, physDev->drawable, physDev->gc,
782 physDev->org.x + rc.left, physDev->org.y + rc.top,
783 ell_width, ell_height, 90 * 64, 90 * 64 );
784 XFillArc( gdi_display, physDev->drawable, physDev->gc,
785 physDev->org.x + rc.left,
786 physDev->org.y + rc.bottom - ell_height - 1,
787 ell_width, ell_height, 180 * 64, 90 * 64 );
788 XFillArc( gdi_display, physDev->drawable, physDev->gc,
789 physDev->org.x + rc.right - ell_width - 1,
790 physDev->org.y + rc.bottom - ell_height - 1,
791 ell_width, ell_height, 270 * 64, 90 * 64 );
792 XFillArc( gdi_display, physDev->drawable, physDev->gc,
793 physDev->org.x + rc.right - ell_width - 1,
794 physDev->org.y + rc.top,
795 ell_width, ell_height, 0, 90 * 64 );
797 if (ell_width < rc.right - rc.left)
799 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
800 physDev->org.x + rc.left + (ell_width + 1) / 2,
801 physDev->org.y + rc.top + 1,
802 rc.right - rc.left - ell_width - 1,
803 (ell_height + 1) / 2 - 1);
804 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
805 physDev->org.x + rc.left + (ell_width + 1) / 2,
806 physDev->org.y + rc.bottom - (ell_height) / 2 - 1,
807 rc.right - rc.left - ell_width - 1,
808 (ell_height) / 2 );
810 if (ell_height < rc.bottom - rc.top)
812 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
813 physDev->org.x + rc.left + 1,
814 physDev->org.y + rc.top + (ell_height + 1) / 2,
815 rc.right - rc.left - 2,
816 rc.bottom - rc.top - ell_height - 1);
818 update = TRUE;
820 /* FIXME: this could be done with on X call
821 * more efficient and probably more correct
822 * on any X server: XDrawArcs will draw
823 * straight horizontal and vertical lines
824 * if width or height are zero.
826 * BTW this stuff is optimized for an Xfree86 server
827 * read the comments inside the X11DRV_DrawArc function
829 if (X11DRV_SetupGCForPen( physDev ))
831 if (ell_width > (rc.right-rc.left) )
832 if (ell_height > (rc.bottom-rc.top) )
833 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
834 physDev->org.x + rc.left, physDev->org.y + rc.top,
835 rc.right - rc.left - 1, rc.bottom - rc.top - 1, 0 , 360 * 64 );
836 else{
837 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
838 physDev->org.x + rc.left, physDev->org.y + rc.top,
839 rc.right - rc.left - 1, ell_height - 1, 0 , 180 * 64 );
840 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
841 physDev->org.x + rc.left,
842 physDev->org.y + rc.bottom - ell_height,
843 rc.right - rc.left - 1, ell_height - 1, 180 * 64 , 180 * 64 );
845 else if (ell_height > (rc.bottom-rc.top) ){
846 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
847 physDev->org.x + rc.left, physDev->org.y + rc.top,
848 ell_width - 1 , rc.bottom - rc.top - 1, 90 * 64 , 180 * 64 );
849 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
850 physDev->org.x + rc.right - ell_width,
851 physDev->org.y + rc.top,
852 ell_width - 1 , rc.bottom - rc.top - 1, 270 * 64 , 180 * 64 );
853 }else{
854 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
855 physDev->org.x + rc.left, physDev->org.y + rc.top,
856 ell_width - 1, ell_height - 1, 90 * 64, 90 * 64 );
857 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
858 physDev->org.x + rc.left, physDev->org.y + rc.bottom - ell_height,
859 ell_width - 1, ell_height - 1, 180 * 64, 90 * 64 );
860 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
861 physDev->org.x + rc.right - ell_width,
862 physDev->org.y + rc.bottom - ell_height,
863 ell_width - 1, ell_height - 1, 270 * 64, 90 * 64 );
864 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
865 physDev->org.x + rc.right - ell_width, physDev->org.y + rc.top,
866 ell_width - 1, ell_height - 1, 0, 90 * 64 );
868 if (ell_width < rc.right - rc.left)
870 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
871 physDev->org.x + rc.left + ell_width / 2,
872 physDev->org.y + rc.top,
873 physDev->org.x + rc.right - (ell_width+1) / 2,
874 physDev->org.y + rc.top);
875 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
876 physDev->org.x + rc.left + ell_width / 2 ,
877 physDev->org.y + rc.bottom - 1,
878 physDev->org.x + rc.right - (ell_width+1)/ 2,
879 physDev->org.y + rc.bottom - 1);
881 if (ell_height < rc.bottom - rc.top)
883 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
884 physDev->org.x + rc.right - 1,
885 physDev->org.y + rc.top + ell_height / 2,
886 physDev->org.x + rc.right - 1,
887 physDev->org.y + rc.bottom - (ell_height+1) / 2);
888 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
889 physDev->org.x + rc.left,
890 physDev->org.y + rc.top + ell_height / 2,
891 physDev->org.x + rc.left,
892 physDev->org.y + rc.bottom - (ell_height+1) / 2);
894 update = TRUE;
896 wine_tsx11_unlock();
897 /* Update the DIBSection from the pixmap */
898 X11DRV_UnlockDIBSection(physDev, update);
900 physDev->pen.width = oldwidth;
901 physDev->pen.endcap = oldendcap;
902 return TRUE;
906 /***********************************************************************
907 * X11DRV_SetPixel
909 COLORREF
910 X11DRV_SetPixel( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
912 Pixel pixel;
913 POINT pt;
915 pt.x = x;
916 pt.y = y;
917 LPtoDP( physDev->hdc, &pt, 1 );
918 pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
920 /* Update the pixmap from the DIB section */
921 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
923 /* inefficient but simple... */
924 wine_tsx11_lock();
925 XSetForeground( gdi_display, physDev->gc, pixel );
926 XSetFunction( gdi_display, physDev->gc, GXcopy );
927 XDrawPoint( gdi_display, physDev->drawable, physDev->gc,
928 physDev->org.x + pt.x, physDev->org.y + pt.y );
929 wine_tsx11_unlock();
931 /* Update the DIBSection from the pixmap */
932 X11DRV_UnlockDIBSection(physDev, TRUE);
934 return X11DRV_PALETTE_ToLogical(pixel);
938 /***********************************************************************
939 * X11DRV_GetPixel
941 COLORREF
942 X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y )
944 static Pixmap pixmap = 0;
945 XImage * image;
946 int pixel;
947 POINT pt;
948 BOOL memdc = (GetObjectType(physDev->hdc) == OBJ_MEMDC);
949 DC *dc = physDev->dc;
951 pt.x = x;
952 pt.y = y;
953 LPtoDP( physDev->hdc, &pt, 1 );
955 /* Update the pixmap from the DIB section */
956 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
958 wine_tsx11_lock();
959 if (memdc)
961 image = XGetImage( gdi_display, physDev->drawable,
962 physDev->org.x + pt.x, physDev->org.y + pt.y,
963 1, 1, AllPlanes, ZPixmap );
965 else
967 /* If we are reading from the screen, use a temporary copy */
968 /* to avoid a BadMatch error */
969 if (!pixmap) pixmap = XCreatePixmap( gdi_display, root_window,
970 1, 1, dc->bitsPerPixel );
971 XCopyArea( gdi_display, physDev->drawable, pixmap, BITMAP_colorGC,
972 physDev->org.x + pt.x, physDev->org.y + pt.y, 1, 1, 0, 0 );
973 image = XGetImage( gdi_display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
975 pixel = XGetPixel( image, 0, 0 );
976 XDestroyImage( image );
977 wine_tsx11_unlock();
979 /* Update the DIBSection from the pixmap */
980 X11DRV_UnlockDIBSection(physDev, FALSE);
982 return X11DRV_PALETTE_ToLogical(pixel);
986 /***********************************************************************
987 * X11DRV_PaintRgn
989 BOOL
990 X11DRV_PaintRgn( X11DRV_PDEVICE *physDev, HRGN hrgn )
992 if (X11DRV_SetupGCForBrush( physDev ))
994 int i;
995 XRectangle *rect;
996 RGNDATA *data = X11DRV_GetRegionData( hrgn, physDev->hdc );
998 if (!data) return FALSE;
999 rect = (XRectangle *)data->Buffer;
1000 for (i = 0; i < data->rdh.nCount; i++)
1002 rect[i].x += physDev->org.x;
1003 rect[i].y += physDev->org.y;
1006 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1007 wine_tsx11_lock();
1008 XFillRectangles( gdi_display, physDev->drawable, physDev->gc, rect, data->rdh.nCount );
1009 wine_tsx11_unlock();
1010 X11DRV_UnlockDIBSection(physDev, TRUE);
1011 HeapFree( GetProcessHeap(), 0, data );
1013 return TRUE;
1016 /**********************************************************************
1017 * X11DRV_Polyline
1019 BOOL
1020 X11DRV_Polyline( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1022 INT oldwidth;
1023 register int i;
1024 XPoint *points;
1026 if((oldwidth = physDev->pen.width) == 0) physDev->pen.width = 1;
1028 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * count )))
1030 WARN("No memory to convert POINTs to XPoints!\n");
1031 return FALSE;
1033 for (i = 0; i < count; i++)
1035 POINT tmp = pt[i];
1036 LPtoDP(physDev->hdc, &tmp, 1);
1037 points[i].x = physDev->org.x + tmp.x;
1038 points[i].y = physDev->org.y + tmp.y;
1041 if (X11DRV_SetupGCForPen ( physDev ))
1043 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1044 wine_tsx11_lock();
1045 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1046 points, count, CoordModeOrigin );
1047 wine_tsx11_unlock();
1048 X11DRV_UnlockDIBSection(physDev, TRUE);
1051 HeapFree( GetProcessHeap(), 0, points );
1052 physDev->pen.width = oldwidth;
1053 return TRUE;
1057 /**********************************************************************
1058 * X11DRV_Polygon
1060 BOOL
1061 X11DRV_Polygon( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1063 register int i;
1064 XPoint *points;
1065 BOOL update = FALSE;
1067 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) )))
1069 WARN("No memory to convert POINTs to XPoints!\n");
1070 return FALSE;
1072 for (i = 0; i < count; i++)
1074 POINT tmp = pt[i];
1075 LPtoDP(physDev->hdc, &tmp, 1);
1076 points[i].x = physDev->org.x + tmp.x;
1077 points[i].y = physDev->org.y + tmp.y;
1079 points[count] = points[0];
1081 /* Update the pixmap from the DIB section */
1082 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1084 if (X11DRV_SetupGCForBrush( physDev ))
1086 wine_tsx11_lock();
1087 XFillPolygon( gdi_display, physDev->drawable, physDev->gc,
1088 points, count+1, Complex, CoordModeOrigin);
1089 wine_tsx11_unlock();
1090 update = TRUE;
1092 if (X11DRV_SetupGCForPen ( physDev ))
1094 wine_tsx11_lock();
1095 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1096 points, count+1, CoordModeOrigin );
1097 wine_tsx11_unlock();
1098 update = TRUE;
1101 /* Update the DIBSection from the pixmap */
1102 X11DRV_UnlockDIBSection(physDev, update);
1104 HeapFree( GetProcessHeap(), 0, points );
1105 return TRUE;
1109 /**********************************************************************
1110 * X11DRV_PolyPolygon
1112 BOOL
1113 X11DRV_PolyPolygon( X11DRV_PDEVICE *physDev, const POINT* pt, const INT* counts, UINT polygons)
1115 HRGN hrgn;
1117 /* FIXME: The points should be converted to device coords before */
1118 /* creating the region. */
1120 hrgn = CreatePolyPolygonRgn( pt, counts, polygons, GetPolyFillMode( physDev->hdc ) );
1121 X11DRV_PaintRgn( physDev, hrgn );
1122 DeleteObject( hrgn );
1124 /* Draw the outline of the polygons */
1126 if (X11DRV_SetupGCForPen ( physDev ))
1128 int i, j, max = 0;
1129 XPoint *points;
1131 /* Update the pixmap from the DIB section */
1132 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1134 for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
1135 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) )))
1137 WARN("No memory to convert POINTs to XPoints!\n");
1138 return FALSE;
1140 for (i = 0; i < polygons; i++)
1142 for (j = 0; j < counts[i]; j++)
1144 POINT tmp = *pt;
1145 LPtoDP(physDev->hdc, &tmp, 1);
1146 points[j].x = physDev->org.x + tmp.x;
1147 points[j].y = physDev->org.y + tmp.y;
1148 pt++;
1150 points[j] = points[0];
1151 wine_tsx11_lock();
1152 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1153 points, j + 1, CoordModeOrigin );
1154 wine_tsx11_unlock();
1157 /* Update the DIBSection of the dc's bitmap */
1158 X11DRV_UnlockDIBSection(physDev, TRUE);
1160 HeapFree( GetProcessHeap(), 0, points );
1162 return TRUE;
1166 /**********************************************************************
1167 * X11DRV_PolyPolyline
1169 BOOL
1170 X11DRV_PolyPolyline( X11DRV_PDEVICE *physDev, const POINT* pt, const DWORD* counts, DWORD polylines )
1172 if (X11DRV_SetupGCForPen ( physDev ))
1174 int i, j, max = 0;
1175 XPoint *points;
1177 /* Update the pixmap from the DIB section */
1178 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1180 for (i = 0; i < polylines; i++) if (counts[i] > max) max = counts[i];
1181 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * max )))
1183 WARN("No memory to convert POINTs to XPoints!\n");
1184 return FALSE;
1186 for (i = 0; i < polylines; i++)
1188 for (j = 0; j < counts[i]; j++)
1190 POINT tmp = *pt;
1191 LPtoDP(physDev->hdc, &tmp, 1);
1192 points[j].x = physDev->org.x + tmp.x;
1193 points[j].y = physDev->org.y + tmp.y;
1194 pt++;
1196 wine_tsx11_lock();
1197 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1198 points, j, CoordModeOrigin );
1199 wine_tsx11_unlock();
1202 /* Update the DIBSection of the dc's bitmap */
1203 X11DRV_UnlockDIBSection(physDev, TRUE);
1205 HeapFree( GetProcessHeap(), 0, points );
1207 return TRUE;
1211 /**********************************************************************
1212 * X11DRV_InternalFloodFill
1214 * Internal helper function for flood fill.
1215 * (xorg,yorg) is the origin of the X image relative to the drawable.
1216 * (x,y) is relative to the origin of the X image.
1218 static void X11DRV_InternalFloodFill(XImage *image, X11DRV_PDEVICE *physDev,
1219 int x, int y,
1220 int xOrg, int yOrg,
1221 Pixel pixel, WORD fillType )
1223 int left, right;
1225 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1226 (XGetPixel(image,x,y) != pixel) : \
1227 (XGetPixel(image,x,y) == pixel))
1229 if (!TO_FLOOD(x,y)) return;
1231 /* Find left and right boundaries */
1233 left = right = x;
1234 while ((left > 0) && TO_FLOOD( left-1, y )) left--;
1235 while ((right < image->width) && TO_FLOOD( right, y )) right++;
1236 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1237 xOrg + left, yOrg + y, right-left, 1 );
1239 /* Set the pixels of this line so we don't fill it again */
1241 for (x = left; x < right; x++)
1243 if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
1244 else XPutPixel( image, x, y, ~pixel );
1247 /* Fill the line above */
1249 if (--y >= 0)
1251 x = left;
1252 while (x < right)
1254 while ((x < right) && !TO_FLOOD(x,y)) x++;
1255 if (x >= right) break;
1256 while ((x < right) && TO_FLOOD(x,y)) x++;
1257 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1258 xOrg, yOrg, pixel, fillType );
1262 /* Fill the line below */
1264 if ((y += 2) < image->height)
1266 x = left;
1267 while (x < right)
1269 while ((x < right) && !TO_FLOOD(x,y)) x++;
1270 if (x >= right) break;
1271 while ((x < right) && TO_FLOOD(x,y)) x++;
1272 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1273 xOrg, yOrg, pixel, fillType );
1276 #undef TO_FLOOD
1280 /**********************************************************************
1281 * X11DRV_ExtFloodFill
1283 BOOL
1284 X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color,
1285 UINT fillType )
1287 XImage *image;
1288 RECT rect;
1289 DC *dc = physDev->dc;
1291 TRACE("X11DRV_ExtFloodFill %d,%d %06lx %d\n", x, y, color, fillType );
1293 if (!PtVisible( physDev->hdc, x, y )) return FALSE;
1294 if (GetRgnBox( dc->hGCClipRgn, &rect ) == ERROR) return FALSE;
1296 wine_tsx11_lock();
1297 image = XGetImage( gdi_display, physDev->drawable,
1298 physDev->org.x + rect.left, physDev->org.y + rect.top,
1299 rect.right - rect.left, rect.bottom - rect.top,
1300 AllPlanes, ZPixmap );
1301 wine_tsx11_unlock();
1302 if (!image) return FALSE;
1304 if (X11DRV_SetupGCForBrush( physDev ))
1306 POINT pt;
1307 pt.x = x;
1308 pt.y = y;
1309 LPtoDP(physDev->hdc, &pt, 1);
1310 /* Update the pixmap from the DIB section */
1311 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1313 /* ROP mode is always GXcopy for flood-fill */
1314 wine_tsx11_lock();
1315 XSetFunction( gdi_display, physDev->gc, GXcopy );
1316 X11DRV_InternalFloodFill(image, physDev,
1317 physDev->org.x + pt.x - rect.left,
1318 physDev->org.y + pt.y - rect.top,
1319 rect.left, rect.top,
1320 X11DRV_PALETTE_ToPhysical( physDev, color ),
1321 fillType );
1322 wine_tsx11_unlock();
1323 /* Update the DIBSection of the dc's bitmap */
1324 X11DRV_UnlockDIBSection(physDev, TRUE);
1327 wine_tsx11_lock();
1328 XDestroyImage( image );
1329 wine_tsx11_unlock();
1330 return TRUE;
1333 /**********************************************************************
1334 * X11DRV_SetBkColor
1336 COLORREF
1337 X11DRV_SetBkColor( X11DRV_PDEVICE *physDev, COLORREF color )
1339 physDev->backgroundPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1340 return color;
1343 /**********************************************************************
1344 * X11DRV_SetTextColor
1346 COLORREF
1347 X11DRV_SetTextColor( X11DRV_PDEVICE *physDev, COLORREF color )
1349 physDev->textPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1350 return color;
1353 /***********************************************************************
1354 * GetDCOrgEx (X11DRV.@)
1356 BOOL X11DRV_GetDCOrgEx( X11DRV_PDEVICE *physDev, LPPOINT lpp )
1358 lpp->x = physDev->org.x + physDev->drawable_org.x;
1359 lpp->y = physDev->org.y + physDev->drawable_org.y;
1360 return TRUE;
1364 /***********************************************************************
1365 * SetDCOrg (X11DRV.@)
1367 DWORD X11DRV_SetDCOrg( X11DRV_PDEVICE *physDev, INT x, INT y )
1369 DWORD ret = MAKELONG( physDev->org.x + physDev->drawable_org.x,
1370 physDev->org.y + physDev->drawable_org.y );
1371 physDev->org.x = x - physDev->drawable_org.x;
1372 physDev->org.y = y - physDev->drawable_org.y;
1373 return ret;