Added regedit unit test, a couple minor changes to regedit.
[wine] / graphics / x11drv / graphics.c
1 /*
2  * X11 graphics driver graphics functions
3  *
4  * Copyright 1993,1994 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 /*
22  * FIXME: only some of these functions obey the GM_ADVANCED
23  * graphics mode
24  */
25
26 #include "config.h"
27
28 #include <X11/Intrinsic.h>
29
30 #include "ts_xlib.h"
31 #include "ts_xutil.h"
32
33 #include <math.h>
34 #ifdef HAVE_FLOAT_H
35 # include <float.h>
36 #endif
37 #include <stdlib.h>
38 #ifndef PI
39 #define PI M_PI
40 #endif
41 #include <string.h>
42
43 #include "x11drv.h"
44 #include "x11font.h"
45 #include "bitmap.h"
46 #include "gdi.h"
47 #include "palette.h"
48 #include "wine/debug.h"
49
50 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
51
52 #define ABS(x)    ((x)<0?(-(x)):(x))
53
54   /* ROP code to GC function conversion */
55 const int X11DRV_XROPfunction[16] =
56 {
57     GXclear,        /* R2_BLACK */
58     GXnor,          /* R2_NOTMERGEPEN */
59     GXandInverted,  /* R2_MASKNOTPEN */
60     GXcopyInverted, /* R2_NOTCOPYPEN */
61     GXandReverse,   /* R2_MASKPENNOT */
62     GXinvert,       /* R2_NOT */
63     GXxor,          /* R2_XORPEN */
64     GXnand,         /* R2_NOTMASKPEN */
65     GXand,          /* R2_MASKPEN */
66     GXequiv,        /* R2_NOTXORPEN */
67     GXnoop,         /* R2_NOP */
68     GXorInverted,   /* R2_MERGENOTPEN */
69     GXcopy,         /* R2_COPYPEN */
70     GXorReverse,    /* R2_MERGEPENNOT */
71     GXor,           /* R2_MERGEPEN */
72     GXset           /* R2_WHITE */
73 };
74
75
76 /***********************************************************************
77  *           X11DRV_SetupGCForPatBlt
78  *
79  * Setup the GC for a PatBlt operation using current brush.
80  * If fMapColors is TRUE, X pixels are mapped to Windows colors.
81  * Return FALSE if brush is BS_NULL, TRUE otherwise.
82  */
83 BOOL X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE *physDev, GC gc, BOOL fMapColors )
84 {
85     XGCValues val;
86     unsigned long mask;
87     Pixmap pixmap = 0;
88     POINT pt;
89
90     if (physDev->brush.style == BS_NULL) return FALSE;
91     if (physDev->brush.pixel == -1)
92     {
93         /* Special case used for monochrome pattern brushes.
94          * We need to swap foreground and background because
95          * Windows does it the wrong way...
96          */
97         val.foreground = physDev->backgroundPixel;
98         val.background = physDev->textPixel;
99     }
100     else
101     {
102         val.foreground = physDev->brush.pixel;
103         val.background = physDev->backgroundPixel;
104     }
105     if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
106     {
107         val.foreground = X11DRV_PALETTE_XPixelToPalette[val.foreground];
108         val.background = X11DRV_PALETTE_XPixelToPalette[val.background];
109     }
110
111     val.function = X11DRV_XROPfunction[GetROP2(physDev->hdc)-1];
112     /*
113     ** Let's replace GXinvert by GXxor with (black xor white)
114     ** This solves the selection color and leak problems in excel
115     ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
116     */
117     if (val.function == GXinvert)
118     {
119         val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
120                           BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
121         val.function = GXxor;
122     }
123     val.fill_style = physDev->brush.fillStyle;
124     switch(val.fill_style)
125     {
126     case FillStippled:
127     case FillOpaqueStippled:
128         if (GetBkMode(physDev->hdc)==OPAQUE) val.fill_style = FillOpaqueStippled;
129         val.stipple = physDev->brush.pixmap;
130         mask = GCStipple;
131         break;
132
133     case FillTiled:
134         if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
135         {
136             register int x, y;
137             XImage *image;
138             wine_tsx11_lock();
139             pixmap = XCreatePixmap( gdi_display, root_window, 8, 8, screen_depth );
140             image = XGetImage( gdi_display, physDev->brush.pixmap, 0, 0, 8, 8,
141                                AllPlanes, ZPixmap );
142             for (y = 0; y < 8; y++)
143                 for (x = 0; x < 8; x++)
144                     XPutPixel( image, x, y,
145                                X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, x, y)] );
146             XPutImage( gdi_display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
147             XDestroyImage( image );
148             wine_tsx11_unlock();
149             val.tile = pixmap;
150         }
151         else val.tile = physDev->brush.pixmap;
152         mask = GCTile;
153         break;
154
155     default:
156         mask = 0;
157         break;
158     }
159     GetBrushOrgEx( physDev->hdc, &pt );
160     val.ts_x_origin = physDev->org.x + pt.x;
161     val.ts_y_origin = physDev->org.y + pt.y;
162     val.fill_rule = (GetPolyFillMode(physDev->hdc) == WINDING) ? WindingRule : EvenOddRule;
163     wine_tsx11_lock();
164     XChangeGC( gdi_display, gc,
165                GCFunction | GCForeground | GCBackground | GCFillStyle |
166                GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
167                &val );
168     if (pixmap) XFreePixmap( gdi_display, pixmap );
169     wine_tsx11_unlock();
170     return TRUE;
171 }
172
173
174 /***********************************************************************
175  *           X11DRV_SetupGCForBrush
176  *
177  * Setup physDev->gc for drawing operations using current brush.
178  * Return FALSE if brush is BS_NULL, TRUE otherwise.
179  */
180 BOOL X11DRV_SetupGCForBrush( X11DRV_PDEVICE *physDev )
181 {
182     return X11DRV_SetupGCForPatBlt( physDev, physDev->gc, FALSE );
183 }
184
185
186 /***********************************************************************
187  *           X11DRV_SetupGCForPen
188  *
189  * Setup physDev->gc for drawing operations using current pen.
190  * Return FALSE if pen is PS_NULL, TRUE otherwise.
191  */
192 BOOL X11DRV_SetupGCForPen( X11DRV_PDEVICE *physDev )
193 {
194     XGCValues val;
195     UINT rop2 = GetROP2(physDev->hdc);
196
197     if (physDev->pen.style == PS_NULL) return FALSE;
198
199     switch (rop2)
200     {
201     case R2_BLACK :
202         val.foreground = BlackPixel( gdi_display, DefaultScreen(gdi_display) );
203         val.function = GXcopy;
204         break;
205     case R2_WHITE :
206         val.foreground = WhitePixel( gdi_display, DefaultScreen(gdi_display) );
207         val.function = GXcopy;
208         break;
209     case R2_XORPEN :
210         val.foreground = physDev->pen.pixel;
211         /* It is very unlikely someone wants to XOR with 0 */
212         /* This fixes the rubber-drawings in paintbrush */
213         if (val.foreground == 0)
214             val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
215                               BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
216         val.function = GXxor;
217         break;
218     default :
219         val.foreground = physDev->pen.pixel;
220         val.function   = X11DRV_XROPfunction[rop2-1];
221     }
222     val.background = physDev->backgroundPixel;
223     val.fill_style = FillSolid;
224     if ((physDev->pen.width <= 1) &&
225         (physDev->pen.style != PS_SOLID) &&
226         (physDev->pen.style != PS_INSIDEFRAME))
227     {
228         TSXSetDashes( gdi_display, physDev->gc, 0, physDev->pen.dashes, physDev->pen.dash_len );
229         val.line_style = (GetBkMode(physDev->hdc) == OPAQUE) ? LineDoubleDash : LineOnOffDash;
230     }
231     else val.line_style = LineSolid;
232     val.line_width = physDev->pen.width;
233     if (val.line_width <= 1) {
234         val.cap_style = CapNotLast;
235     } else {
236         switch (physDev->pen.endcap)
237         {
238         case PS_ENDCAP_SQUARE:
239             val.cap_style = CapProjecting;
240             break;
241         case PS_ENDCAP_FLAT:
242             val.cap_style = CapButt;
243             break;
244         case PS_ENDCAP_ROUND:
245         default:
246             val.cap_style = CapRound;
247         }
248     }
249     switch (physDev->pen.linejoin)
250     {
251     case PS_JOIN_BEVEL:
252         val.join_style = JoinBevel;
253         break;
254     case PS_JOIN_MITER:
255         val.join_style = JoinMiter;
256         break;
257     case PS_JOIN_ROUND:
258     default:
259         val.join_style = JoinRound;
260     }
261     TSXChangeGC( gdi_display, physDev->gc,
262                GCFunction | GCForeground | GCBackground | GCLineWidth |
263                GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
264     return TRUE;
265 }
266
267
268 /***********************************************************************
269  *           X11DRV_SetupGCForText
270  *
271  * Setup physDev->gc for text drawing operations.
272  * Return FALSE if the font is null, TRUE otherwise.
273  */
274 BOOL X11DRV_SetupGCForText( X11DRV_PDEVICE *physDev )
275 {
276     XFontStruct* xfs = XFONT_GetFontStruct( physDev->font );
277
278     if( xfs )
279     {
280         XGCValues val;
281
282         val.function   = GXcopy;  /* Text is always GXcopy */
283         val.foreground = physDev->textPixel;
284         val.background = physDev->backgroundPixel;
285         val.fill_style = FillSolid;
286         val.font       = xfs->fid;
287
288         TSXChangeGC( gdi_display, physDev->gc,
289                    GCFunction | GCForeground | GCBackground | GCFillStyle |
290                    GCFont, &val );
291         return TRUE;
292     }
293     WARN("Physical font failure\n" );
294     return FALSE;
295 }
296
297 /***********************************************************************
298  *           X11DRV_LineTo
299  */
300 BOOL
301 X11DRV_LineTo( X11DRV_PDEVICE *physDev, INT x, INT y )
302 {
303     POINT pt[2];
304
305     if (X11DRV_SetupGCForPen( physDev )) {
306         /* Update the pixmap from the DIB section */
307         X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
308
309         GetCurrentPositionEx( physDev->hdc, &pt[0] );
310         pt[1].x = x;
311         pt[1].y = y;
312         LPtoDP( physDev->hdc, pt, 2 );
313
314         TSXDrawLine(gdi_display, physDev->drawable, physDev->gc,
315                     physDev->org.x + pt[0].x, physDev->org.y + pt[0].y,
316                     physDev->org.x + pt[1].x, physDev->org.y + pt[1].y );
317
318         /* Update the DIBSection from the pixmap */
319         X11DRV_UnlockDIBSection(physDev, TRUE);
320     }
321     return TRUE;
322 }
323
324
325
326 /***********************************************************************
327  *           X11DRV_DrawArc
328  *
329  * Helper functions for Arc(), Chord() and Pie().
330  * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
331  *
332  */
333 static BOOL
334 X11DRV_DrawArc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
335                 INT bottom, INT xstart, INT ystart,
336                 INT xend, INT yend, INT lines )
337 {
338     INT xcenter, ycenter, istart_angle, idiff_angle;
339     INT width, oldwidth, oldendcap;
340     double start_angle, end_angle;
341     XPoint points[4];
342     DC *dc = physDev->dc;
343     BOOL update = FALSE;
344
345     left   = XLPTODP( dc, left );
346     top    = YLPTODP( dc, top );
347     right  = XLPTODP( dc, right );
348     bottom = YLPTODP( dc, bottom );
349     xstart = XLPTODP( dc, xstart );
350     ystart = YLPTODP( dc, ystart );
351     xend   = XLPTODP( dc, xend );
352     yend   = YLPTODP( dc, yend );
353
354     if (right < left) { INT tmp = right; right = left; left = tmp; }
355     if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
356     if ((left == right) || (top == bottom)
357             ||(lines && ((right-left==1)||(bottom-top==1)))) return TRUE;
358
359     if( dc->ArcDirection == AD_CLOCKWISE )
360         { INT tmp = xstart; xstart = xend; xend = tmp;
361           tmp = ystart; ystart = yend; yend = tmp; }
362
363     oldwidth = width = physDev->pen.width;
364     oldendcap = physDev->pen.endcap;
365     if (!width) width = 1;
366     if(physDev->pen.style == PS_NULL) width = 0;
367
368     if ((physDev->pen.style == PS_INSIDEFRAME))
369     {
370         if (2*width > (right-left)) width=(right-left + 1)/2;
371         if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
372         left   += width / 2;
373         right  -= (width - 1) / 2;
374         top    += width / 2;
375         bottom -= (width - 1) / 2;
376     }
377     if(width == 0) width = 1; /* more accurate */
378     physDev->pen.width = width;
379     physDev->pen.endcap = PS_ENDCAP_SQUARE;
380
381     xcenter = (right + left) / 2;
382     ycenter = (bottom + top) / 2;
383     start_angle = atan2( (double)(ycenter-ystart)*(right-left),
384                          (double)(xstart-xcenter)*(bottom-top) );
385     end_angle   = atan2( (double)(ycenter-yend)*(right-left),
386                          (double)(xend-xcenter)*(bottom-top) );
387     if ((xstart==xend)&&(ystart==yend))
388       { /* A lazy program delivers xstart=xend=ystart=yend=0) */
389         start_angle = 0;
390         end_angle = 2* PI;
391       }
392     else /* notorious cases */
393       if ((start_angle == PI)&&( end_angle <0))
394         start_angle = - PI;
395     else
396       if ((end_angle == PI)&&( start_angle <0))
397         end_angle = - PI;
398     istart_angle = (INT)(start_angle * 180 * 64 / PI + 0.5);
399     idiff_angle  = (INT)((end_angle - start_angle) * 180 * 64 / PI + 0.5);
400     if (idiff_angle <= 0) idiff_angle += 360 * 64;
401
402     /* Update the pixmap from the DIB section */
403     X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
404
405       /* Fill arc with brush if Chord() or Pie() */
406
407     if ((lines > 0) && X11DRV_SetupGCForBrush( physDev )) {
408         TSXSetArcMode( gdi_display, physDev->gc, (lines==1) ? ArcChord : ArcPieSlice);
409         TSXFillArc( gdi_display, physDev->drawable, physDev->gc,
410                     physDev->org.x + left, physDev->org.y + top,
411                     right-left-1, bottom-top-1, istart_angle, idiff_angle );
412         update = TRUE;
413     }
414
415       /* Draw arc and lines */
416
417     if (X11DRV_SetupGCForPen( physDev )){
418         TSXDrawArc( gdi_display, physDev->drawable, physDev->gc,
419                     physDev->org.x + left, physDev->org.y + top,
420                     right-left-1, bottom-top-1, istart_angle, idiff_angle );
421         if (lines) {
422             /* use the truncated values */
423             start_angle=(double)istart_angle*PI/64./180.;
424             end_angle=(double)(istart_angle+idiff_angle)*PI/64./180.;
425             /* calculate the endpoints and round correctly */
426             points[0].x = (int) floor(physDev->org.x + (right+left)/2.0 +
427                     cos(start_angle) * (right-left-width*2+2) / 2. + 0.5);
428             points[0].y = (int) floor(physDev->org.y + (top+bottom)/2.0 -
429                     sin(start_angle) * (bottom-top-width*2+2) / 2. + 0.5);
430             points[1].x = (int) floor(physDev->org.x + (right+left)/2.0 +
431                     cos(end_angle) * (right-left-width*2+2) / 2. + 0.5);
432             points[1].y = (int) floor(physDev->org.y + (top+bottom)/2.0 -
433                     sin(end_angle) * (bottom-top-width*2+2) / 2. + 0.5);
434
435             /* OK, this stuff is optimized for Xfree86
436              * which is probably the server most used by
437              * wine users. Other X servers will not
438              * display correctly. (eXceed for instance)
439              * so if you feel you must make changes, make sure that
440              * you either use Xfree86 or separate your changes
441              * from these (compile switch or whatever)
442              */
443             if (lines == 2) {
444                 INT dx1,dy1;
445                 points[3] = points[1];
446                 points[1].x = physDev->org.x + xcenter;
447                 points[1].y = physDev->org.y + ycenter;
448                 points[2] = points[1];
449                 dx1=points[1].x-points[0].x;
450                 dy1=points[1].y-points[0].y;
451                 if(((top-bottom) | -2) == -2)
452                     if(dy1>0) points[1].y--;
453                 if(dx1<0) {
454                     if (((-dx1)*64)<=ABS(dy1)*37) points[0].x--;
455                     if(((-dx1*9))<(dy1*16)) points[0].y--;
456                     if( dy1<0 && ((dx1*9)) < (dy1*16)) points[0].y--;
457                 } else {
458                     if(dy1 < 0)  points[0].y--;
459                     if(((right-left) | -2) == -2) points[1].x--;
460                 }
461                 dx1=points[3].x-points[2].x;
462                 dy1=points[3].y-points[2].y;
463                 if(((top-bottom) | -2 ) == -2)
464                     if(dy1 < 0) points[2].y--;
465                 if( dx1<0){
466                     if( dy1>0) points[3].y--;
467                     if(((right-left) | -2) == -2 ) points[2].x--;
468                 }else {
469                     points[3].y--;
470                     if( dx1 * 64 < dy1 * -37 ) points[3].x--;
471                 }
472                 lines++;
473             }
474             TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
475                           points, lines+1, CoordModeOrigin );
476         }
477         update = TRUE;
478     }
479
480     /* Update the DIBSection of the pixmap */
481     X11DRV_UnlockDIBSection(physDev, update);
482
483     physDev->pen.width = oldwidth;
484     physDev->pen.endcap = oldendcap;
485     return TRUE;
486 }
487
488
489 /***********************************************************************
490  *           X11DRV_Arc
491  */
492 BOOL
493 X11DRV_Arc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
494             INT xstart, INT ystart, INT xend, INT yend )
495 {
496     return X11DRV_DrawArc( physDev, left, top, right, bottom,
497                            xstart, ystart, xend, yend, 0 );
498 }
499
500
501 /***********************************************************************
502  *           X11DRV_Pie
503  */
504 BOOL
505 X11DRV_Pie( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
506             INT xstart, INT ystart, INT xend, INT yend )
507 {
508     return X11DRV_DrawArc( physDev, left, top, right, bottom,
509                            xstart, ystart, xend, yend, 2 );
510 }
511
512 /***********************************************************************
513  *           X11DRV_Chord
514  */
515 BOOL
516 X11DRV_Chord( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
517               INT xstart, INT ystart, INT xend, INT yend )
518 {
519     return X11DRV_DrawArc( physDev, left, top, right, bottom,
520                            xstart, ystart, xend, yend, 1 );
521 }
522
523
524 /***********************************************************************
525  *           X11DRV_Ellipse
526  */
527 BOOL
528 X11DRV_Ellipse( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom )
529 {
530     INT width, oldwidth;
531     DC *dc = physDev->dc;
532     BOOL update = FALSE;
533
534     left   = XLPTODP( dc, left );
535     top    = YLPTODP( dc, top );
536     right  = XLPTODP( dc, right );
537     bottom = YLPTODP( dc, bottom );
538     if ((left == right) || (top == bottom)) return TRUE;
539
540     if (right < left) { INT tmp = right; right = left; left = tmp; }
541     if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
542
543     oldwidth = width = physDev->pen.width;
544     if (!width) width = 1;
545     if(physDev->pen.style == PS_NULL) width = 0;
546
547     if ((physDev->pen.style == PS_INSIDEFRAME))
548     {
549         if (2*width > (right-left)) width=(right-left + 1)/2;
550         if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
551         left   += width / 2;
552         right  -= (width - 1) / 2;
553         top    += width / 2;
554         bottom -= (width - 1) / 2;
555     }
556     if(width == 0) width = 1; /* more accurate */
557     physDev->pen.width = width;
558
559     /* Update the pixmap from the DIB section */
560     X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
561
562     if (X11DRV_SetupGCForBrush( physDev ))
563     {
564         TSXFillArc( gdi_display, physDev->drawable, physDev->gc,
565                     physDev->org.x + left, physDev->org.y + top,
566                     right-left-1, bottom-top-1, 0, 360*64 );
567         update = TRUE;
568     }
569     if (X11DRV_SetupGCForPen( physDev ))
570     {
571         TSXDrawArc( gdi_display, physDev->drawable, physDev->gc,
572                     physDev->org.x + left, physDev->org.y + top,
573                     right-left-1, bottom-top-1, 0, 360*64 );
574         update = TRUE;
575     }
576
577     /* Update the DIBSection from the pixmap */
578     X11DRV_UnlockDIBSection(physDev, update);
579
580     physDev->pen.width = oldwidth;
581     return TRUE;
582 }
583
584
585 /***********************************************************************
586  *           X11DRV_Rectangle
587  */
588 BOOL
589 X11DRV_Rectangle(X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
590 {
591     INT width, oldwidth, oldjoinstyle;
592     DC *dc = physDev->dc;
593     BOOL update = FALSE;
594
595     TRACE("(%d %d %d %d)\n",
596         left, top, right, bottom);
597
598     left   = INTERNAL_XWPTODP( dc, left, top );
599     top    = INTERNAL_YWPTODP( dc, left, top );
600     right  = INTERNAL_XWPTODP( dc, right, bottom );
601     bottom = INTERNAL_YWPTODP( dc, right, bottom );
602
603     if ((left == right) || (top == bottom)) return TRUE;
604
605     if (right < left) { INT tmp = right; right = left; left = tmp; }
606     if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
607
608     oldwidth = width = physDev->pen.width;
609     if (!width) width = 1;
610     if(physDev->pen.style == PS_NULL) width = 0;
611
612     if ((physDev->pen.style == PS_INSIDEFRAME))
613     {
614         if (2*width > (right-left)) width=(right-left + 1)/2;
615         if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
616         left   += width / 2;
617         right  -= (width - 1) / 2;
618         top    += width / 2;
619         bottom -= (width - 1) / 2;
620     }
621     if(width == 1) width = 0;
622     physDev->pen.width = width;
623     oldjoinstyle = physDev->pen.linejoin;
624     if(physDev->pen.type != PS_GEOMETRIC)
625         physDev->pen.linejoin = PS_JOIN_MITER;
626
627     /* Update the pixmap from the DIB section */
628     X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
629
630     if ((right > left + width) && (bottom > top + width))
631         if (X11DRV_SetupGCForBrush( physDev ))
632         {
633             TSXFillRectangle( gdi_display, physDev->drawable, physDev->gc,
634                               physDev->org.x + left + (width + 1) / 2,
635                               physDev->org.y + top + (width + 1) / 2,
636                               right-left-width-1, bottom-top-width-1);
637             update = TRUE;
638         }
639     if (X11DRV_SetupGCForPen( physDev ))
640     {
641         TSXDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
642                           physDev->org.x + left, physDev->org.y + top,
643                           right-left-1, bottom-top-1 );
644         update = TRUE;
645     }
646
647     /* Update the DIBSection from the pixmap */
648     X11DRV_UnlockDIBSection(physDev, update);
649
650     physDev->pen.width = oldwidth;
651     physDev->pen.linejoin = oldjoinstyle;
652     return TRUE;
653 }
654
655 /***********************************************************************
656  *           X11DRV_RoundRect
657  */
658 BOOL
659 X11DRV_RoundRect( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
660                   INT bottom, INT ell_width, INT ell_height )
661 {
662     INT width, oldwidth, oldendcap;
663     DC *dc = physDev->dc;
664     BOOL update = FALSE;
665
666     TRACE("(%d %d %d %d  %d %d\n",
667         left, top, right, bottom, ell_width, ell_height);
668
669     left   = XLPTODP( dc, left );
670     top    = YLPTODP( dc, top );
671     right  = XLPTODP( dc, right );
672     bottom = YLPTODP( dc, bottom );
673
674     if ((left == right) || (top == bottom))
675         return TRUE;
676
677     /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
678        called with width/height < 0 */
679     ell_width  = max(abs( ell_width * dc->vportExtX / dc->wndExtX ), 1);
680     ell_height = max(abs( ell_height * dc->vportExtY / dc->wndExtY ), 1);
681
682     /* Fix the coordinates */
683
684     if (right < left) { INT tmp = right; right = left; left = tmp; }
685     if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
686
687     oldwidth = width = physDev->pen.width;
688     oldendcap = physDev->pen.endcap;
689     if (!width) width = 1;
690     if(physDev->pen.style == PS_NULL) width = 0;
691
692     if ((physDev->pen.style == PS_INSIDEFRAME))
693     {
694         if (2*width > (right-left)) width=(right-left + 1)/2;
695         if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
696         left   += width / 2;
697         right  -= (width - 1) / 2;
698         top    += width / 2;
699         bottom -= (width - 1) / 2;
700     }
701     if(width == 0) width = 1;
702     physDev->pen.width = width;
703     physDev->pen.endcap = PS_ENDCAP_SQUARE;
704
705     /* Update the pixmap from the DIB section */
706     X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
707
708     wine_tsx11_lock();
709     if (X11DRV_SetupGCForBrush( physDev ))
710     {
711         if (ell_width > (right-left) )
712             if (ell_height > (bottom-top) )
713                 XFillArc( gdi_display, physDev->drawable, physDev->gc,
714                           physDev->org.x + left, physDev->org.y + top,
715                           right - left - 1, bottom - top - 1,
716                           0, 360 * 64 );
717             else{
718                 XFillArc( gdi_display, physDev->drawable, physDev->gc,
719                           physDev->org.x + left, physDev->org.y + top,
720                           right - left - 1, ell_height, 0, 180 * 64 );
721                 XFillArc( gdi_display, physDev->drawable, physDev->gc,
722                           physDev->org.x + left,
723                           physDev->org.y + bottom - ell_height - 1,
724                           right - left - 1, ell_height, 180 * 64,
725                           180 * 64 );
726             }
727         else if (ell_height > (bottom-top) ){
728             XFillArc( gdi_display, physDev->drawable, physDev->gc,
729                       physDev->org.x + left, physDev->org.y + top,
730                       ell_width, bottom - top - 1, 90 * 64, 180 * 64 );
731             XFillArc( gdi_display, physDev->drawable, physDev->gc,
732                       physDev->org.x + right - ell_width -1, physDev->org.y + top,
733                       ell_width, bottom - top - 1, 270 * 64, 180 * 64 );
734         }else{
735             XFillArc( gdi_display, physDev->drawable, physDev->gc,
736                       physDev->org.x + left, physDev->org.y + top,
737                       ell_width, ell_height, 90 * 64, 90 * 64 );
738             XFillArc( gdi_display, physDev->drawable, physDev->gc,
739                       physDev->org.x + left,
740                       physDev->org.y + bottom - ell_height - 1,
741                       ell_width, ell_height, 180 * 64, 90 * 64 );
742             XFillArc( gdi_display, physDev->drawable, physDev->gc,
743                       physDev->org.x + right - ell_width - 1,
744                       physDev->org.y + bottom - ell_height - 1,
745                       ell_width, ell_height, 270 * 64, 90 * 64 );
746             XFillArc( gdi_display, physDev->drawable, physDev->gc,
747                       physDev->org.x + right - ell_width - 1,
748                       physDev->org.y + top,
749                       ell_width, ell_height, 0, 90 * 64 );
750         }
751         if (ell_width < right - left)
752         {
753             XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
754                             physDev->org.x + left + (ell_width + 1) / 2,
755                             physDev->org.y + top + 1,
756                             right - left - ell_width - 1,
757                             (ell_height + 1) / 2 - 1);
758             XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
759                             physDev->org.x + left + (ell_width + 1) / 2,
760                             physDev->org.y + bottom - (ell_height) / 2 - 1,
761                             right - left - ell_width - 1,
762                             (ell_height) / 2 );
763         }
764         if  (ell_height < bottom - top)
765         {
766             XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
767                             physDev->org.x + left + 1,
768                             physDev->org.y + top + (ell_height + 1) / 2,
769                             right - left - 2,
770                             bottom - top - ell_height - 1);
771         }
772         update = TRUE;
773     }
774     /* FIXME: this could be done with on X call
775      * more efficient and probably more correct
776      * on any X server: XDrawArcs will draw
777      * straight horizontal and vertical lines
778      * if width or height are zero.
779      *
780      * BTW this stuff is optimized for an Xfree86 server
781      * read the comments inside the X11DRV_DrawArc function
782      */
783     if (X11DRV_SetupGCForPen( physDev ))
784     {
785         if (ell_width > (right-left) )
786             if (ell_height > (bottom-top) )
787                 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
788                           physDev->org.x + left, physDev->org.y + top,
789                           right - left - 1, bottom -top - 1, 0 , 360 * 64 );
790             else{
791                 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
792                           physDev->org.x + left, physDev->org.y + top,
793                           right - left - 1, ell_height - 1, 0 , 180 * 64 );
794                 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
795                           physDev->org.x + left,
796                           physDev->org.y + bottom - ell_height,
797                           right - left - 1, ell_height - 1, 180 * 64 , 180 * 64 );
798             }
799         else if (ell_height > (bottom-top) ){
800             XDrawArc( gdi_display, physDev->drawable, physDev->gc,
801                       physDev->org.x + left, physDev->org.y + top,
802                       ell_width - 1 , bottom - top - 1, 90 * 64 , 180 * 64 );
803             XDrawArc( gdi_display, physDev->drawable, physDev->gc,
804                       physDev->org.x + right - ell_width,
805                       physDev->org.y + top,
806                       ell_width - 1 , bottom - top - 1, 270 * 64 , 180 * 64 );
807         }else{
808             XDrawArc( gdi_display, physDev->drawable, physDev->gc,
809                       physDev->org.x + left, physDev->org.y + top,
810                       ell_width - 1, ell_height - 1, 90 * 64, 90 * 64 );
811             XDrawArc( gdi_display, physDev->drawable, physDev->gc,
812                       physDev->org.x + left, physDev->org.y + bottom - ell_height,
813                       ell_width - 1, ell_height - 1, 180 * 64, 90 * 64 );
814             XDrawArc( gdi_display, physDev->drawable, physDev->gc,
815                       physDev->org.x + right - ell_width,
816                       physDev->org.y + bottom - ell_height,
817                       ell_width - 1, ell_height - 1, 270 * 64, 90 * 64 );
818             XDrawArc( gdi_display, physDev->drawable, physDev->gc,
819                       physDev->org.x + right - ell_width, physDev->org.y + top,
820                       ell_width - 1, ell_height - 1, 0, 90 * 64 );
821         }
822         if (ell_width < right - left)
823         {
824             XDrawLine( gdi_display, physDev->drawable, physDev->gc,
825                        physDev->org.x + left + ell_width / 2,
826                        physDev->org.y + top,
827                        physDev->org.x + right - (ell_width+1) / 2,
828                        physDev->org.y + top);
829             XDrawLine( gdi_display, physDev->drawable, physDev->gc,
830                        physDev->org.x + left + ell_width / 2 ,
831                        physDev->org.y + bottom - 1,
832                        physDev->org.x + right - (ell_width+1)/ 2,
833                        physDev->org.y + bottom - 1);
834         }
835         if (ell_height < bottom - top)
836         {
837             XDrawLine( gdi_display, physDev->drawable, physDev->gc,
838                        physDev->org.x + right - 1,
839                        physDev->org.y + top + ell_height / 2,
840                        physDev->org.x + right - 1,
841                        physDev->org.y + bottom - (ell_height+1) / 2);
842             XDrawLine( gdi_display, physDev->drawable, physDev->gc,
843                        physDev->org.x + left,
844                        physDev->org.y + top + ell_height / 2,
845                        physDev->org.x + left,
846                        physDev->org.y + bottom - (ell_height+1) / 2);
847         }
848         update = TRUE;
849     }
850     wine_tsx11_unlock();
851     /* Update the DIBSection from the pixmap */
852     X11DRV_UnlockDIBSection(physDev, update);
853
854     physDev->pen.width = oldwidth;
855     physDev->pen.endcap = oldendcap;
856     return TRUE;
857 }
858
859
860 /***********************************************************************
861  *           X11DRV_SetPixel
862  */
863 COLORREF
864 X11DRV_SetPixel( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
865 {
866     Pixel pixel;
867     POINT pt;
868
869     pt.x = x;
870     pt.y = y;
871     LPtoDP( physDev->hdc, &pt, 1 );
872     pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
873
874     /* Update the pixmap from the DIB section */
875     X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
876
877     /* inefficient but simple... */
878     wine_tsx11_lock();
879     XSetForeground( gdi_display, physDev->gc, pixel );
880     XSetFunction( gdi_display, physDev->gc, GXcopy );
881     XDrawPoint( gdi_display, physDev->drawable, physDev->gc,
882                 physDev->org.x + pt.x, physDev->org.y + y );
883     wine_tsx11_unlock();
884
885     /* Update the DIBSection from the pixmap */
886     X11DRV_UnlockDIBSection(physDev, TRUE);
887
888     return X11DRV_PALETTE_ToLogical(pixel);
889 }
890
891
892 /***********************************************************************
893  *           X11DRV_GetPixel
894  */
895 COLORREF
896 X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y )
897 {
898     static Pixmap pixmap = 0;
899     XImage * image;
900     int pixel;
901     POINT pt;
902     DC *dc = physDev->dc;
903
904     pt.x = x;
905     pt.y = y;
906     LPtoDP( physDev->hdc, &pt, 1 );
907
908     /* Update the pixmap from the DIB section */
909     X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
910
911     wine_tsx11_lock();
912     if (dc->flags & DC_MEMORY)
913     {
914         image = XGetImage( gdi_display, physDev->drawable,
915                            physDev->org.x + pt.x, physDev->org.y + pt.y,
916                            1, 1, AllPlanes, ZPixmap );
917     }
918     else
919     {
920         /* If we are reading from the screen, use a temporary copy */
921         /* to avoid a BadMatch error */
922         if (!pixmap) pixmap = XCreatePixmap( gdi_display, root_window,
923                                              1, 1, dc->bitsPerPixel );
924         XCopyArea( gdi_display, physDev->drawable, pixmap, BITMAP_colorGC,
925                    physDev->org.x + pt.x, physDev->org.y + pt.y, 1, 1, 0, 0 );
926         image = XGetImage( gdi_display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
927     }
928     pixel = XGetPixel( image, 0, 0 );
929     XDestroyImage( image );
930     wine_tsx11_unlock();
931
932     /* Update the DIBSection from the pixmap */
933     X11DRV_UnlockDIBSection(physDev, FALSE);
934
935     return X11DRV_PALETTE_ToLogical(pixel);
936 }
937
938
939 /***********************************************************************
940  *           X11DRV_PaintRgn
941  */
942 BOOL
943 X11DRV_PaintRgn( X11DRV_PDEVICE *physDev, HRGN hrgn )
944 {
945     if (X11DRV_SetupGCForBrush( physDev ))
946     {
947         int i;
948         XRectangle *rect;
949         RGNDATA *data = X11DRV_GetRegionData( hrgn, physDev->hdc );
950
951         if (!data) return FALSE;
952         rect = (XRectangle *)data->Buffer;
953         for (i = 0; i < data->rdh.nCount; i++)
954         {
955             rect[i].x += physDev->org.x;
956             rect[i].y += physDev->org.y;
957         }
958
959         X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
960         wine_tsx11_lock();
961         XFillRectangles( gdi_display, physDev->drawable, physDev->gc, rect, data->rdh.nCount );
962         wine_tsx11_unlock();
963         X11DRV_UnlockDIBSection(physDev, TRUE);
964         HeapFree( GetProcessHeap(), 0, data );
965     }
966     return TRUE;
967 }
968
969 /**********************************************************************
970  *          X11DRV_Polyline
971  */
972 BOOL
973 X11DRV_Polyline( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
974 {
975     INT oldwidth;
976     register int i;
977     XPoint *points;
978     DC *dc = physDev->dc;
979
980     if((oldwidth = physDev->pen.width) == 0) physDev->pen.width = 1;
981
982     if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * count )))
983     {
984         WARN("No memory to convert POINTs to XPoints!\n");
985         return FALSE;
986     }
987     for (i = 0; i < count; i++)
988     {
989         points[i].x = physDev->org.x + INTERNAL_XWPTODP( dc, pt[i].x, pt[i].y );
990         points[i].y = physDev->org.y + INTERNAL_YWPTODP( dc, pt[i].x, pt[i].y );
991     }
992
993     if (X11DRV_SetupGCForPen ( physDev ))
994     {
995         /* Update the pixmap from the DIB section */
996         X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
997
998         TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
999                       points, count, CoordModeOrigin );
1000
1001         /* Update the DIBSection from the pixmap */
1002         X11DRV_UnlockDIBSection(physDev, TRUE);
1003     }
1004
1005     HeapFree( GetProcessHeap(), 0, points );
1006     physDev->pen.width = oldwidth;
1007     return TRUE;
1008 }
1009
1010
1011 /**********************************************************************
1012  *          X11DRV_Polygon
1013  */
1014 BOOL
1015 X11DRV_Polygon( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1016 {
1017     register int i;
1018     XPoint *points;
1019     DC *dc = physDev->dc;
1020     BOOL update = FALSE;
1021
1022     if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) )))
1023     {
1024         WARN("No memory to convert POINTs to XPoints!\n");
1025         return FALSE;
1026     }
1027     for (i = 0; i < count; i++)
1028     {
1029         points[i].x = physDev->org.x + INTERNAL_XWPTODP( dc, pt[i].x, pt[i].y );
1030         points[i].y = physDev->org.y + INTERNAL_YWPTODP( dc, pt[i].x, pt[i].y );
1031     }
1032     points[count] = points[0];
1033
1034     /* Update the pixmap from the DIB section */
1035     X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1036
1037     if (X11DRV_SetupGCForBrush( physDev ))
1038     {
1039         TSXFillPolygon( gdi_display, physDev->drawable, physDev->gc,
1040                         points, count+1, Complex, CoordModeOrigin);
1041         update = TRUE;
1042     }
1043     if (X11DRV_SetupGCForPen ( physDev ))
1044     {
1045         TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1046                       points, count+1, CoordModeOrigin );
1047         update = TRUE;
1048     }
1049
1050     /* Update the DIBSection from the pixmap */
1051     X11DRV_UnlockDIBSection(physDev, update);
1052
1053     HeapFree( GetProcessHeap(), 0, points );
1054     return TRUE;
1055 }
1056
1057
1058 /**********************************************************************
1059  *          X11DRV_PolyPolygon
1060  */
1061 BOOL
1062 X11DRV_PolyPolygon( X11DRV_PDEVICE *physDev, const POINT* pt, const INT* counts, UINT polygons)
1063 {
1064     HRGN hrgn;
1065     DC *dc = physDev->dc;
1066
1067     /* FIXME: The points should be converted to device coords before */
1068     /* creating the region. */
1069
1070     hrgn = CreatePolyPolygonRgn( pt, counts, polygons, GetPolyFillMode( physDev->hdc ) );
1071     X11DRV_PaintRgn( physDev, hrgn );
1072     DeleteObject( hrgn );
1073
1074       /* Draw the outline of the polygons */
1075
1076     if (X11DRV_SetupGCForPen ( physDev ))
1077     {
1078         int i, j, max = 0;
1079         XPoint *points;
1080
1081         /* Update the pixmap from the DIB section */
1082         X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1083
1084         for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
1085         if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) )))
1086         {
1087             WARN("No memory to convert POINTs to XPoints!\n");
1088             return FALSE;
1089         }
1090         for (i = 0; i < polygons; i++)
1091         {
1092             for (j = 0; j < counts[i]; j++)
1093             {
1094                 points[j].x = physDev->org.x + INTERNAL_XWPTODP( dc, pt->x, pt->y );
1095                 points[j].y = physDev->org.y + INTERNAL_YWPTODP( dc, pt->x, pt->y );
1096                 pt++;
1097             }
1098             points[j] = points[0];
1099             TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1100                           points, j + 1, CoordModeOrigin );
1101         }
1102
1103         /* Update the DIBSection of the dc's bitmap */
1104         X11DRV_UnlockDIBSection(physDev, TRUE);
1105
1106         HeapFree( GetProcessHeap(), 0, points );
1107     }
1108     return TRUE;
1109 }
1110
1111
1112 /**********************************************************************
1113  *          X11DRV_PolyPolyline
1114  */
1115 BOOL
1116 X11DRV_PolyPolyline( X11DRV_PDEVICE *physDev, const POINT* pt, const DWORD* counts, DWORD polylines )
1117 {
1118     DC *dc = physDev->dc;
1119
1120     if (X11DRV_SetupGCForPen ( physDev ))
1121     {
1122         int i, j, max = 0;
1123         XPoint *points;
1124
1125         /* Update the pixmap from the DIB section */
1126         X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1127
1128         for (i = 0; i < polylines; i++) if (counts[i] > max) max = counts[i];
1129         if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * max )))
1130         {
1131             WARN("No memory to convert POINTs to XPoints!\n");
1132             return FALSE;
1133         }
1134         for (i = 0; i < polylines; i++)
1135         {
1136             for (j = 0; j < counts[i]; j++)
1137             {
1138                 points[j].x = physDev->org.x + INTERNAL_XWPTODP( dc, pt->x, pt->y );
1139                 points[j].y = physDev->org.y + INTERNAL_YWPTODP( dc, pt->x, pt->y );
1140                 pt++;
1141             }
1142             TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1143                           points, j, CoordModeOrigin );
1144         }
1145
1146         /* Update the DIBSection of the dc's bitmap */
1147         X11DRV_UnlockDIBSection(physDev, TRUE);
1148
1149         HeapFree( GetProcessHeap(), 0, points );
1150     }
1151     return TRUE;
1152 }
1153
1154
1155 /**********************************************************************
1156  *          X11DRV_InternalFloodFill
1157  *
1158  * Internal helper function for flood fill.
1159  * (xorg,yorg) is the origin of the X image relative to the drawable.
1160  * (x,y) is relative to the origin of the X image.
1161  */
1162 static void X11DRV_InternalFloodFill(XImage *image, X11DRV_PDEVICE *physDev,
1163                                      int x, int y,
1164                                      int xOrg, int yOrg,
1165                                      Pixel pixel, WORD fillType )
1166 {
1167     int left, right;
1168
1169 #define TO_FLOOD(x,y)  ((fillType == FLOODFILLBORDER) ? \
1170                         (XGetPixel(image,x,y) != pixel) : \
1171                         (XGetPixel(image,x,y) == pixel))
1172
1173     if (!TO_FLOOD(x,y)) return;
1174
1175       /* Find left and right boundaries */
1176
1177     left = right = x;
1178     while ((left > 0) && TO_FLOOD( left-1, y )) left--;
1179     while ((right < image->width) && TO_FLOOD( right, y )) right++;
1180     XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1181                     xOrg + left, yOrg + y, right-left, 1 );
1182
1183       /* Set the pixels of this line so we don't fill it again */
1184
1185     for (x = left; x < right; x++)
1186     {
1187         if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
1188         else XPutPixel( image, x, y, ~pixel );
1189     }
1190
1191       /* Fill the line above */
1192
1193     if (--y >= 0)
1194     {
1195         x = left;
1196         while (x < right)
1197         {
1198             while ((x < right) && !TO_FLOOD(x,y)) x++;
1199             if (x >= right) break;
1200             while ((x < right) && TO_FLOOD(x,y)) x++;
1201             X11DRV_InternalFloodFill(image, physDev, x-1, y,
1202                                      xOrg, yOrg, pixel, fillType );
1203         }
1204     }
1205
1206       /* Fill the line below */
1207
1208     if ((y += 2) < image->height)
1209     {
1210         x = left;
1211         while (x < right)
1212         {
1213             while ((x < right) && !TO_FLOOD(x,y)) x++;
1214             if (x >= right) break;
1215             while ((x < right) && TO_FLOOD(x,y)) x++;
1216             X11DRV_InternalFloodFill(image, physDev, x-1, y,
1217                                      xOrg, yOrg, pixel, fillType );
1218         }
1219     }
1220 #undef TO_FLOOD
1221 }
1222
1223
1224 /**********************************************************************
1225  *          X11DRV_ExtFloodFill
1226  */
1227 BOOL
1228 X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color,
1229                      UINT fillType )
1230 {
1231     XImage *image;
1232     RECT rect;
1233     DC *dc = physDev->dc;
1234
1235     TRACE("X11DRV_ExtFloodFill %d,%d %06lx %d\n", x, y, color, fillType );
1236
1237     if (!PtVisible( dc->hSelf, x, y )) return FALSE;
1238     if (GetRgnBox( dc->hGCClipRgn, &rect ) == ERROR) return FALSE;
1239
1240     if (!(image = TSXGetImage( gdi_display, physDev->drawable,
1241                                physDev->org.x + rect.left,
1242                                physDev->org.y + rect.top,
1243                                rect.right - rect.left,
1244                                rect.bottom - rect.top,
1245                                AllPlanes, ZPixmap ))) return FALSE;
1246
1247     if (X11DRV_SetupGCForBrush( physDev ))
1248     {
1249         /* Update the pixmap from the DIB section */
1250         X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1251
1252           /* ROP mode is always GXcopy for flood-fill */
1253         wine_tsx11_lock();
1254         XSetFunction( gdi_display, physDev->gc, GXcopy );
1255         X11DRV_InternalFloodFill(image, physDev,
1256                                  XLPTODP(dc,x) - rect.left,
1257                                  YLPTODP(dc,y) - rect.top,
1258                                  rect.left, rect.top,
1259                                  X11DRV_PALETTE_ToPhysical( physDev, color ),
1260                                  fillType );
1261         wine_tsx11_unlock();
1262         /* Update the DIBSection of the dc's bitmap */
1263         X11DRV_UnlockDIBSection(physDev, TRUE);
1264     }
1265
1266     TSXDestroyImage( image );
1267     return TRUE;
1268 }
1269
1270 /**********************************************************************
1271  *          X11DRV_SetBkColor
1272  */
1273 COLORREF
1274 X11DRV_SetBkColor( X11DRV_PDEVICE *physDev, COLORREF color )
1275 {
1276     physDev->backgroundPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1277     return color;
1278 }
1279
1280 /**********************************************************************
1281  *          X11DRV_SetTextColor
1282  */
1283 COLORREF
1284 X11DRV_SetTextColor( X11DRV_PDEVICE *physDev, COLORREF color )
1285 {
1286     physDev->textPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1287     return color;
1288 }
1289
1290 /***********************************************************************
1291  *           GetDCOrgEx   (X11DRV.@)
1292  */
1293 BOOL X11DRV_GetDCOrgEx( X11DRV_PDEVICE *physDev, LPPOINT lpp )
1294 {
1295     lpp->x = physDev->org.x + physDev->drawable_org.x;
1296     lpp->y = physDev->org.y + physDev->drawable_org.y;
1297     return TRUE;
1298 }
1299
1300
1301 /***********************************************************************
1302  *           SetDCOrg   (X11DRV.@)
1303  */
1304 DWORD X11DRV_SetDCOrg( X11DRV_PDEVICE *physDev, INT x, INT y )
1305 {
1306     DWORD ret = MAKELONG( physDev->org.x + physDev->drawable_org.x,
1307                           physDev->org.y + physDev->drawable_org.y );
1308     physDev->org.x = x - physDev->drawable_org.x;
1309     physDev->org.y = y - physDev->drawable_org.y;
1310     return ret;
1311 }