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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * FIXME: only some of these functions obey the GM_ADVANCED
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
44 #define ABS(x) ((x)<0?(-(x)):(x))
46 /* ROP code to GC function conversion */
47 const int X11DRV_XROPfunction[16] =
49 GXclear, /* R2_BLACK */
50 GXnor, /* R2_NOTMERGEPEN */
51 GXandInverted, /* R2_MASKNOTPEN */
52 GXcopyInverted, /* R2_NOTCOPYPEN */
53 GXandReverse, /* R2_MASKPENNOT */
54 GXinvert, /* R2_NOT */
55 GXxor, /* R2_XORPEN */
56 GXnand, /* R2_NOTMASKPEN */
57 GXand, /* R2_MASKPEN */
58 GXequiv, /* R2_NOTXORPEN */
60 GXorInverted, /* R2_MERGENOTPEN */
61 GXcopy, /* R2_COPYPEN */
62 GXorReverse, /* R2_MERGEPENNOT */
63 GXor, /* R2_MERGEPEN */
68 /***********************************************************************
69 * X11DRV_SetupGCForPatBlt
71 * Setup the GC for a PatBlt operation using current brush.
72 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
73 * Return FALSE if brush is BS_NULL, TRUE otherwise.
75 BOOL X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE *physDev, GC gc, BOOL fMapColors )
82 if (physDev->brush.style == BS_NULL) return FALSE;
83 if (physDev->brush.pixel == -1)
85 /* Special case used for monochrome pattern brushes.
86 * We need to swap foreground and background because
87 * Windows does it the wrong way...
89 val.foreground = physDev->backgroundPixel;
90 val.background = physDev->textPixel;
94 val.foreground = physDev->brush.pixel;
95 val.background = physDev->backgroundPixel;
97 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
99 val.foreground = X11DRV_PALETTE_XPixelToPalette[val.foreground];
100 val.background = X11DRV_PALETTE_XPixelToPalette[val.background];
103 val.function = X11DRV_XROPfunction[GetROP2(physDev->hdc)-1];
105 ** Let's replace GXinvert by GXxor with (black xor white)
106 ** This solves the selection color and leak problems in excel
107 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
109 if (val.function == GXinvert)
111 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
112 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
113 val.function = GXxor;
115 val.fill_style = physDev->brush.fillStyle;
116 switch(val.fill_style)
119 case FillOpaqueStippled:
120 if (GetBkMode(physDev->hdc)==OPAQUE) val.fill_style = FillOpaqueStippled;
121 val.stipple = physDev->brush.pixmap;
126 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
131 pixmap = XCreatePixmap( gdi_display, root_window, 8, 8, screen_depth );
132 image = XGetImage( gdi_display, physDev->brush.pixmap, 0, 0, 8, 8,
133 AllPlanes, ZPixmap );
134 for (y = 0; y < 8; y++)
135 for (x = 0; x < 8; x++)
136 XPutPixel( image, x, y,
137 X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, x, y)] );
138 XPutImage( gdi_display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
139 XDestroyImage( image );
143 else val.tile = physDev->brush.pixmap;
151 GetBrushOrgEx( physDev->hdc, &pt );
152 val.ts_x_origin = physDev->org.x + pt.x;
153 val.ts_y_origin = physDev->org.y + pt.y;
154 val.fill_rule = (GetPolyFillMode(physDev->hdc) == WINDING) ? WindingRule : EvenOddRule;
156 XChangeGC( gdi_display, gc,
157 GCFunction | GCForeground | GCBackground | GCFillStyle |
158 GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
160 if (pixmap) XFreePixmap( gdi_display, pixmap );
166 /***********************************************************************
167 * X11DRV_SetupGCForBrush
169 * Setup physDev->gc for drawing operations using current brush.
170 * Return FALSE if brush is BS_NULL, TRUE otherwise.
172 BOOL X11DRV_SetupGCForBrush( X11DRV_PDEVICE *physDev )
174 return X11DRV_SetupGCForPatBlt( physDev, physDev->gc, FALSE );
178 /***********************************************************************
179 * X11DRV_SetupGCForPen
181 * Setup physDev->gc for drawing operations using current pen.
182 * Return FALSE if pen is PS_NULL, TRUE otherwise.
184 BOOL X11DRV_SetupGCForPen( X11DRV_PDEVICE *physDev )
187 UINT rop2 = GetROP2(physDev->hdc);
189 if (physDev->pen.style == PS_NULL) return FALSE;
194 val.foreground = BlackPixel( gdi_display, DefaultScreen(gdi_display) );
195 val.function = GXcopy;
198 val.foreground = WhitePixel( gdi_display, DefaultScreen(gdi_display) );
199 val.function = GXcopy;
202 val.foreground = physDev->pen.pixel;
203 /* It is very unlikely someone wants to XOR with 0 */
204 /* This fixes the rubber-drawings in paintbrush */
205 if (val.foreground == 0)
206 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
207 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
208 val.function = GXxor;
211 val.foreground = physDev->pen.pixel;
212 val.function = X11DRV_XROPfunction[rop2-1];
214 val.background = physDev->backgroundPixel;
215 val.fill_style = FillSolid;
216 val.line_width = physDev->pen.width;
217 if (val.line_width <= 1) {
218 val.cap_style = CapNotLast;
220 switch (physDev->pen.endcap)
222 case PS_ENDCAP_SQUARE:
223 val.cap_style = CapProjecting;
226 val.cap_style = CapButt;
228 case PS_ENDCAP_ROUND:
230 val.cap_style = CapRound;
233 switch (physDev->pen.linejoin)
236 val.join_style = JoinBevel;
239 val.join_style = JoinMiter;
243 val.join_style = JoinRound;
246 if ((physDev->pen.width <= 1) &&
247 (physDev->pen.style != PS_SOLID) &&
248 (physDev->pen.style != PS_INSIDEFRAME))
250 XSetDashes( gdi_display, physDev->gc, 0, physDev->pen.dashes, physDev->pen.dash_len );
251 val.line_style = (GetBkMode(physDev->hdc) == OPAQUE) ? LineDoubleDash : LineOnOffDash;
253 else val.line_style = LineSolid;
255 XChangeGC( gdi_display, physDev->gc,
256 GCFunction | GCForeground | GCBackground | GCLineWidth |
257 GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
263 /***********************************************************************
264 * X11DRV_SetupGCForText
266 * Setup physDev->gc for text drawing operations.
267 * Return FALSE if the font is null, TRUE otherwise.
269 BOOL X11DRV_SetupGCForText( X11DRV_PDEVICE *physDev )
271 XFontStruct* xfs = XFONT_GetFontStruct( physDev->font );
277 val.function = GXcopy; /* Text is always GXcopy */
278 val.foreground = physDev->textPixel;
279 val.background = physDev->backgroundPixel;
280 val.fill_style = FillSolid;
284 XChangeGC( gdi_display, physDev->gc,
285 GCFunction | GCForeground | GCBackground | GCFillStyle |
290 WARN("Physical font failure\n" );
294 /***********************************************************************
297 * Performs a world-to-viewport transformation on the specified width.
299 INT X11DRV_XWStoDS( X11DRV_PDEVICE *physDev, INT width )
307 LPtoDP( physDev->hdc, pt, 2 );
308 return pt[1].x - pt[0].x;
311 /***********************************************************************
314 * Performs a world-to-viewport transformation on the specified height.
316 INT X11DRV_YWStoDS( X11DRV_PDEVICE *physDev, INT height )
324 LPtoDP( physDev->hdc, pt, 2 );
325 return pt[1].y - pt[0].y;
328 /***********************************************************************
332 X11DRV_LineTo( X11DRV_PDEVICE *physDev, INT x, INT y )
336 if (X11DRV_SetupGCForPen( physDev )) {
337 /* Update the pixmap from the DIB section */
338 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
340 GetCurrentPositionEx( physDev->hdc, &pt[0] );
343 LPtoDP( physDev->hdc, pt, 2 );
346 XDrawLine(gdi_display, physDev->drawable, physDev->gc,
347 physDev->org.x + pt[0].x, physDev->org.y + pt[0].y,
348 physDev->org.x + pt[1].x, physDev->org.y + pt[1].y );
351 /* Update the DIBSection from the pixmap */
352 X11DRV_UnlockDIBSection(physDev, TRUE);
359 /***********************************************************************
362 * Helper functions for Arc(), Chord() and Pie().
363 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
367 X11DRV_DrawArc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
368 INT bottom, INT xstart, INT ystart,
369 INT xend, INT yend, INT lines )
371 INT xcenter, ycenter, istart_angle, idiff_angle;
373 double start_angle, end_angle;
379 SetRect(&rc, left, top, right, bottom);
384 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
385 LPtoDP(physDev->hdc, &start, 1);
386 LPtoDP(physDev->hdc, &end, 1);
388 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
389 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
390 if ((rc.left == rc.right) || (rc.top == rc.bottom)
391 ||(lines && ((rc.right-rc.left==1)||(rc.bottom-rc.top==1)))) return TRUE;
393 if (GetArcDirection( physDev->hdc ) == AD_CLOCKWISE)
394 { POINT tmp = start; start = end; end = tmp; }
396 oldwidth = width = physDev->pen.width;
397 if (!width) width = 1;
398 if(physDev->pen.style == PS_NULL) width = 0;
400 if ((physDev->pen.style == PS_INSIDEFRAME))
402 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
403 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
404 rc.left += width / 2;
405 rc.right -= (width - 1) / 2;
407 rc.bottom -= (width - 1) / 2;
409 if(width == 0) width = 1; /* more accurate */
410 physDev->pen.width = width;
412 xcenter = (rc.right + rc.left) / 2;
413 ycenter = (rc.bottom + rc.top) / 2;
414 start_angle = atan2( (double)(ycenter-start.y)*(rc.right-rc.left),
415 (double)(start.x-xcenter)*(rc.bottom-rc.top) );
416 end_angle = atan2( (double)(ycenter-end.y)*(rc.right-rc.left),
417 (double)(end.x-xcenter)*(rc.bottom-rc.top) );
418 if ((start.x==end.x)&&(start.y==end.y))
419 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
423 else /* notorious cases */
424 if ((start_angle == PI)&&( end_angle <0))
427 if ((end_angle == PI)&&( start_angle <0))
429 istart_angle = (INT)(start_angle * 180 * 64 / PI + 0.5);
430 idiff_angle = (INT)((end_angle - start_angle) * 180 * 64 / PI + 0.5);
431 if (idiff_angle <= 0) idiff_angle += 360 * 64;
433 /* Update the pixmap from the DIB section */
434 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
436 /* Fill arc with brush if Chord() or Pie() */
438 if ((lines > 0) && X11DRV_SetupGCForBrush( physDev )) {
440 XSetArcMode( gdi_display, physDev->gc, (lines==1) ? ArcChord : ArcPieSlice);
441 XFillArc( gdi_display, physDev->drawable, physDev->gc,
442 physDev->org.x + rc.left, physDev->org.y + rc.top,
443 rc.right-rc.left-1, rc.bottom-rc.top-1, istart_angle, idiff_angle );
448 /* Draw arc and lines */
450 if (X11DRV_SetupGCForPen( physDev ))
453 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
454 physDev->org.x + rc.left, physDev->org.y + rc.top,
455 rc.right-rc.left-1, rc.bottom-rc.top-1, istart_angle, idiff_angle );
457 /* use the truncated values */
458 start_angle=(double)istart_angle*PI/64./180.;
459 end_angle=(double)(istart_angle+idiff_angle)*PI/64./180.;
460 /* calculate the endpoints and round correctly */
461 points[0].x = (int) floor(physDev->org.x + (rc.right+rc.left)/2.0 +
462 cos(start_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
463 points[0].y = (int) floor(physDev->org.y + (rc.top+rc.bottom)/2.0 -
464 sin(start_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
465 points[1].x = (int) floor(physDev->org.x + (rc.right+rc.left)/2.0 +
466 cos(end_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
467 points[1].y = (int) floor(physDev->org.y + (rc.top+rc.bottom)/2.0 -
468 sin(end_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
470 /* OK, this stuff is optimized for Xfree86
471 * which is probably the server most used by
472 * wine users. Other X servers will not
473 * display correctly. (eXceed for instance)
474 * so if you feel you must make changes, make sure that
475 * you either use Xfree86 or separate your changes
476 * from these (compile switch or whatever)
480 points[3] = points[1];
481 points[1].x = physDev->org.x + xcenter;
482 points[1].y = physDev->org.y + ycenter;
483 points[2] = points[1];
484 dx1=points[1].x-points[0].x;
485 dy1=points[1].y-points[0].y;
486 if(((rc.top-rc.bottom) | -2) == -2)
487 if(dy1>0) points[1].y--;
489 if (((-dx1)*64)<=ABS(dy1)*37) points[0].x--;
490 if(((-dx1*9))<(dy1*16)) points[0].y--;
491 if( dy1<0 && ((dx1*9)) < (dy1*16)) points[0].y--;
493 if(dy1 < 0) points[0].y--;
494 if(((rc.right-rc.left) | -2) == -2) points[1].x--;
496 dx1=points[3].x-points[2].x;
497 dy1=points[3].y-points[2].y;
498 if(((rc.top-rc.bottom) | -2 ) == -2)
499 if(dy1 < 0) points[2].y--;
501 if( dy1>0) points[3].y--;
502 if(((rc.right-rc.left) | -2) == -2 ) points[2].x--;
505 if( dx1 * 64 < dy1 * -37 ) points[3].x--;
509 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
510 points, lines+1, CoordModeOrigin );
516 /* Update the DIBSection of the pixmap */
517 X11DRV_UnlockDIBSection(physDev, update);
519 physDev->pen.width = oldwidth;
524 /***********************************************************************
528 X11DRV_Arc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
529 INT xstart, INT ystart, INT xend, INT yend )
531 return X11DRV_DrawArc( physDev, left, top, right, bottom,
532 xstart, ystart, xend, yend, 0 );
536 /***********************************************************************
540 X11DRV_Pie( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
541 INT xstart, INT ystart, INT xend, INT yend )
543 return X11DRV_DrawArc( physDev, left, top, right, bottom,
544 xstart, ystart, xend, yend, 2 );
547 /***********************************************************************
551 X11DRV_Chord( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
552 INT xstart, INT ystart, INT xend, INT yend )
554 return X11DRV_DrawArc( physDev, left, top, right, bottom,
555 xstart, ystart, xend, yend, 1 );
559 /***********************************************************************
563 X11DRV_Ellipse( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom )
569 SetRect(&rc, left, top, right, bottom);
570 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
572 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
574 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
575 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
577 oldwidth = width = physDev->pen.width;
578 if (!width) width = 1;
579 if(physDev->pen.style == PS_NULL) width = 0;
581 if ((physDev->pen.style == PS_INSIDEFRAME))
583 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
584 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
585 rc.left += width / 2;
586 rc.right -= (width - 1) / 2;
588 rc.bottom -= (width - 1) / 2;
590 if(width == 0) width = 1; /* more accurate */
591 physDev->pen.width = width;
593 /* Update the pixmap from the DIB section */
594 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
596 if (X11DRV_SetupGCForBrush( physDev ))
599 XFillArc( gdi_display, physDev->drawable, physDev->gc,
600 physDev->org.x + rc.left, physDev->org.y + rc.top,
601 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
605 if (X11DRV_SetupGCForPen( physDev ))
608 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
609 physDev->org.x + rc.left, physDev->org.y + rc.top,
610 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
615 /* Update the DIBSection from the pixmap */
616 X11DRV_UnlockDIBSection(physDev, update);
618 physDev->pen.width = oldwidth;
623 /***********************************************************************
627 X11DRV_Rectangle(X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
629 INT width, oldwidth, oldjoinstyle;
633 TRACE("(%d %d %d %d)\n", left, top, right, bottom);
635 SetRect(&rc, left, top, right, bottom);
636 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
638 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
640 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
641 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
643 oldwidth = width = physDev->pen.width;
644 if (!width) width = 1;
645 if(physDev->pen.style == PS_NULL) width = 0;
647 if ((physDev->pen.style == PS_INSIDEFRAME))
649 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
650 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
651 rc.left += width / 2;
652 rc.right -= (width - 1) / 2;
654 rc.bottom -= (width - 1) / 2;
656 if(width == 1) width = 0;
657 physDev->pen.width = width;
658 oldjoinstyle = physDev->pen.linejoin;
659 if(physDev->pen.type != PS_GEOMETRIC)
660 physDev->pen.linejoin = PS_JOIN_MITER;
662 /* Update the pixmap from the DIB section */
663 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
665 if ((rc.right > rc.left + width) && (rc.bottom > rc.top + width))
667 if (X11DRV_SetupGCForBrush( physDev ))
670 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
671 physDev->org.x + rc.left + (width + 1) / 2,
672 physDev->org.y + rc.top + (width + 1) / 2,
673 rc.right-rc.left-width-1, rc.bottom-rc.top-width-1);
678 if (X11DRV_SetupGCForPen( physDev ))
681 XDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
682 physDev->org.x + rc.left, physDev->org.y + rc.top,
683 rc.right-rc.left-1, rc.bottom-rc.top-1 );
688 /* Update the DIBSection from the pixmap */
689 X11DRV_UnlockDIBSection(physDev, update);
691 physDev->pen.width = oldwidth;
692 physDev->pen.linejoin = oldjoinstyle;
696 /***********************************************************************
700 X11DRV_RoundRect( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
701 INT bottom, INT ell_width, INT ell_height )
703 INT width, oldwidth, oldendcap;
708 TRACE("(%d %d %d %d %d %d\n",
709 left, top, right, bottom, ell_width, ell_height);
711 SetRect(&rc, left, top, right, bottom);
712 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
714 if ((rc.left == rc.right) || (rc.top == rc.bottom))
717 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
718 called with width/height < 0 */
719 pts[0].x = pts[0].y = 0;
720 pts[1].x = ell_width;
721 pts[1].y = ell_height;
722 LPtoDP(physDev->hdc, pts, 2);
723 ell_width = max(abs( pts[1].x - pts[0].x ), 1);
724 ell_height = max(abs( pts[1].y - pts[0].y ), 1);
726 /* Fix the coordinates */
728 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
729 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
731 oldwidth = width = physDev->pen.width;
732 oldendcap = physDev->pen.endcap;
733 if (!width) width = 1;
734 if(physDev->pen.style == PS_NULL) width = 0;
736 if ((physDev->pen.style == PS_INSIDEFRAME))
738 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
739 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
740 rc.left += width / 2;
741 rc.right -= (width - 1) / 2;
743 rc.bottom -= (width - 1) / 2;
745 if(width == 0) width = 1;
746 physDev->pen.width = width;
747 physDev->pen.endcap = PS_ENDCAP_SQUARE;
749 /* Update the pixmap from the DIB section */
750 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
753 if (X11DRV_SetupGCForBrush( physDev ))
755 if (ell_width > (rc.right-rc.left) )
756 if (ell_height > (rc.bottom-rc.top) )
757 XFillArc( gdi_display, physDev->drawable, physDev->gc,
758 physDev->org.x + rc.left, physDev->org.y + rc.top,
759 rc.right - rc.left - 1, rc.bottom - rc.top - 1,
762 XFillArc( gdi_display, physDev->drawable, physDev->gc,
763 physDev->org.x + rc.left, physDev->org.y + rc.top,
764 rc.right - rc.left - 1, ell_height, 0, 180 * 64 );
765 XFillArc( gdi_display, physDev->drawable, physDev->gc,
766 physDev->org.x + rc.left,
767 physDev->org.y + rc.bottom - ell_height - 1,
768 rc.right - rc.left - 1, ell_height, 180 * 64,
771 else if (ell_height > (rc.bottom-rc.top) ){
772 XFillArc( gdi_display, physDev->drawable, physDev->gc,
773 physDev->org.x + rc.left, physDev->org.y + rc.top,
774 ell_width, rc.bottom - rc.top - 1, 90 * 64, 180 * 64 );
775 XFillArc( gdi_display, physDev->drawable, physDev->gc,
776 physDev->org.x + rc.right - ell_width - 1, physDev->org.y + rc.top,
777 ell_width, rc.bottom - rc.top - 1, 270 * 64, 180 * 64 );
779 XFillArc( gdi_display, physDev->drawable, physDev->gc,
780 physDev->org.x + rc.left, physDev->org.y + rc.top,
781 ell_width, ell_height, 90 * 64, 90 * 64 );
782 XFillArc( gdi_display, physDev->drawable, physDev->gc,
783 physDev->org.x + rc.left,
784 physDev->org.y + rc.bottom - ell_height - 1,
785 ell_width, ell_height, 180 * 64, 90 * 64 );
786 XFillArc( gdi_display, physDev->drawable, physDev->gc,
787 physDev->org.x + rc.right - ell_width - 1,
788 physDev->org.y + rc.bottom - ell_height - 1,
789 ell_width, ell_height, 270 * 64, 90 * 64 );
790 XFillArc( gdi_display, physDev->drawable, physDev->gc,
791 physDev->org.x + rc.right - ell_width - 1,
792 physDev->org.y + rc.top,
793 ell_width, ell_height, 0, 90 * 64 );
795 if (ell_width < rc.right - rc.left)
797 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
798 physDev->org.x + rc.left + (ell_width + 1) / 2,
799 physDev->org.y + rc.top + 1,
800 rc.right - rc.left - ell_width - 1,
801 (ell_height + 1) / 2 - 1);
802 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
803 physDev->org.x + rc.left + (ell_width + 1) / 2,
804 physDev->org.y + rc.bottom - (ell_height) / 2 - 1,
805 rc.right - rc.left - ell_width - 1,
808 if (ell_height < rc.bottom - rc.top)
810 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
811 physDev->org.x + rc.left + 1,
812 physDev->org.y + rc.top + (ell_height + 1) / 2,
813 rc.right - rc.left - 2,
814 rc.bottom - rc.top - ell_height - 1);
818 /* FIXME: this could be done with on X call
819 * more efficient and probably more correct
820 * on any X server: XDrawArcs will draw
821 * straight horizontal and vertical lines
822 * if width or height are zero.
824 * BTW this stuff is optimized for an Xfree86 server
825 * read the comments inside the X11DRV_DrawArc function
827 if (X11DRV_SetupGCForPen( physDev ))
829 if (ell_width > (rc.right-rc.left) )
830 if (ell_height > (rc.bottom-rc.top) )
831 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
832 physDev->org.x + rc.left, physDev->org.y + rc.top,
833 rc.right - rc.left - 1, rc.bottom - rc.top - 1, 0 , 360 * 64 );
835 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
836 physDev->org.x + rc.left, physDev->org.y + rc.top,
837 rc.right - rc.left - 1, ell_height - 1, 0 , 180 * 64 );
838 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
839 physDev->org.x + rc.left,
840 physDev->org.y + rc.bottom - ell_height,
841 rc.right - rc.left - 1, ell_height - 1, 180 * 64 , 180 * 64 );
843 else if (ell_height > (rc.bottom-rc.top) ){
844 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
845 physDev->org.x + rc.left, physDev->org.y + rc.top,
846 ell_width - 1 , rc.bottom - rc.top - 1, 90 * 64 , 180 * 64 );
847 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
848 physDev->org.x + rc.right - ell_width,
849 physDev->org.y + rc.top,
850 ell_width - 1 , rc.bottom - rc.top - 1, 270 * 64 , 180 * 64 );
852 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
853 physDev->org.x + rc.left, physDev->org.y + rc.top,
854 ell_width - 1, ell_height - 1, 90 * 64, 90 * 64 );
855 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
856 physDev->org.x + rc.left, physDev->org.y + rc.bottom - ell_height,
857 ell_width - 1, ell_height - 1, 180 * 64, 90 * 64 );
858 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
859 physDev->org.x + rc.right - ell_width,
860 physDev->org.y + rc.bottom - ell_height,
861 ell_width - 1, ell_height - 1, 270 * 64, 90 * 64 );
862 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
863 physDev->org.x + rc.right - ell_width, physDev->org.y + rc.top,
864 ell_width - 1, ell_height - 1, 0, 90 * 64 );
866 if (ell_width < rc.right - rc.left)
868 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
869 physDev->org.x + rc.left + ell_width / 2,
870 physDev->org.y + rc.top,
871 physDev->org.x + rc.right - (ell_width+1) / 2,
872 physDev->org.y + rc.top);
873 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
874 physDev->org.x + rc.left + ell_width / 2 ,
875 physDev->org.y + rc.bottom - 1,
876 physDev->org.x + rc.right - (ell_width+1)/ 2,
877 physDev->org.y + rc.bottom - 1);
879 if (ell_height < rc.bottom - rc.top)
881 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
882 physDev->org.x + rc.right - 1,
883 physDev->org.y + rc.top + ell_height / 2,
884 physDev->org.x + rc.right - 1,
885 physDev->org.y + rc.bottom - (ell_height+1) / 2);
886 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
887 physDev->org.x + rc.left,
888 physDev->org.y + rc.top + ell_height / 2,
889 physDev->org.x + rc.left,
890 physDev->org.y + rc.bottom - (ell_height+1) / 2);
895 /* Update the DIBSection from the pixmap */
896 X11DRV_UnlockDIBSection(physDev, update);
898 physDev->pen.width = oldwidth;
899 physDev->pen.endcap = oldendcap;
904 /***********************************************************************
908 X11DRV_SetPixel( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
915 LPtoDP( physDev->hdc, &pt, 1 );
916 pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
918 /* Update the pixmap from the DIB section */
919 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
921 /* inefficient but simple... */
923 XSetForeground( gdi_display, physDev->gc, pixel );
924 XSetFunction( gdi_display, physDev->gc, GXcopy );
925 XDrawPoint( gdi_display, physDev->drawable, physDev->gc,
926 physDev->org.x + pt.x, physDev->org.y + pt.y );
929 /* Update the DIBSection from the pixmap */
930 X11DRV_UnlockDIBSection(physDev, TRUE);
932 return X11DRV_PALETTE_ToLogical(pixel);
936 /***********************************************************************
940 X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y )
942 static Pixmap pixmap = 0;
946 BOOL memdc = (GetObjectType(physDev->hdc) == OBJ_MEMDC);
950 LPtoDP( physDev->hdc, &pt, 1 );
952 /* Update the pixmap from the DIB section */
953 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
958 image = XGetImage( gdi_display, physDev->drawable,
959 physDev->org.x + pt.x, physDev->org.y + pt.y,
960 1, 1, AllPlanes, ZPixmap );
964 /* If we are reading from the screen, use a temporary copy */
965 /* to avoid a BadMatch error */
966 if (!pixmap) pixmap = XCreatePixmap( gdi_display, root_window,
967 1, 1, physDev->depth );
968 XCopyArea( gdi_display, physDev->drawable, pixmap, BITMAP_colorGC,
969 physDev->org.x + pt.x, physDev->org.y + pt.y, 1, 1, 0, 0 );
970 image = XGetImage( gdi_display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
972 pixel = XGetPixel( image, 0, 0 );
973 XDestroyImage( image );
976 /* Update the DIBSection from the pixmap */
977 X11DRV_UnlockDIBSection(physDev, FALSE);
979 return X11DRV_PALETTE_ToLogical(pixel);
983 /***********************************************************************
987 X11DRV_PaintRgn( X11DRV_PDEVICE *physDev, HRGN hrgn )
989 if (X11DRV_SetupGCForBrush( physDev ))
993 RGNDATA *data = X11DRV_GetRegionData( hrgn, physDev->hdc );
995 if (!data) return FALSE;
996 rect = (XRectangle *)data->Buffer;
997 for (i = 0; i < data->rdh.nCount; i++)
999 rect[i].x += physDev->org.x;
1000 rect[i].y += physDev->org.y;
1003 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1005 XFillRectangles( gdi_display, physDev->drawable, physDev->gc, rect, data->rdh.nCount );
1006 wine_tsx11_unlock();
1007 X11DRV_UnlockDIBSection(physDev, TRUE);
1008 HeapFree( GetProcessHeap(), 0, data );
1013 /**********************************************************************
1017 X11DRV_Polyline( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1022 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * count )))
1024 WARN("No memory to convert POINTs to XPoints!\n");
1027 for (i = 0; i < count; i++)
1030 LPtoDP(physDev->hdc, &tmp, 1);
1031 points[i].x = physDev->org.x + tmp.x;
1032 points[i].y = physDev->org.y + tmp.y;
1035 if (X11DRV_SetupGCForPen ( physDev ))
1037 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1039 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1040 points, count, CoordModeOrigin );
1041 wine_tsx11_unlock();
1042 X11DRV_UnlockDIBSection(physDev, TRUE);
1045 HeapFree( GetProcessHeap(), 0, points );
1050 /**********************************************************************
1054 X11DRV_Polygon( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1058 BOOL update = FALSE;
1060 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) )))
1062 WARN("No memory to convert POINTs to XPoints!\n");
1065 for (i = 0; i < count; i++)
1068 LPtoDP(physDev->hdc, &tmp, 1);
1069 points[i].x = physDev->org.x + tmp.x;
1070 points[i].y = physDev->org.y + tmp.y;
1072 points[count] = points[0];
1074 /* Update the pixmap from the DIB section */
1075 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1077 if (X11DRV_SetupGCForBrush( physDev ))
1080 XFillPolygon( gdi_display, physDev->drawable, physDev->gc,
1081 points, count+1, Complex, CoordModeOrigin);
1082 wine_tsx11_unlock();
1085 if (X11DRV_SetupGCForPen ( physDev ))
1088 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1089 points, count+1, CoordModeOrigin );
1090 wine_tsx11_unlock();
1094 /* Update the DIBSection from the pixmap */
1095 X11DRV_UnlockDIBSection(physDev, update);
1097 HeapFree( GetProcessHeap(), 0, points );
1102 /**********************************************************************
1103 * X11DRV_PolyPolygon
1106 X11DRV_PolyPolygon( X11DRV_PDEVICE *physDev, const POINT* pt, const INT* counts, UINT polygons)
1110 /* FIXME: The points should be converted to device coords before */
1111 /* creating the region. */
1113 hrgn = CreatePolyPolygonRgn( pt, counts, polygons, GetPolyFillMode( physDev->hdc ) );
1114 X11DRV_PaintRgn( physDev, hrgn );
1115 DeleteObject( hrgn );
1117 /* Draw the outline of the polygons */
1119 if (X11DRV_SetupGCForPen ( physDev ))
1125 /* Update the pixmap from the DIB section */
1126 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1128 for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
1129 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) )))
1131 WARN("No memory to convert POINTs to XPoints!\n");
1134 for (i = 0; i < polygons; i++)
1136 for (j = 0; j < counts[i]; j++)
1139 LPtoDP(physDev->hdc, &tmp, 1);
1140 points[j].x = physDev->org.x + tmp.x;
1141 points[j].y = physDev->org.y + tmp.y;
1144 points[j] = points[0];
1146 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1147 points, j + 1, CoordModeOrigin );
1148 wine_tsx11_unlock();
1151 /* Update the DIBSection of the dc's bitmap */
1152 X11DRV_UnlockDIBSection(physDev, TRUE);
1154 HeapFree( GetProcessHeap(), 0, points );
1160 /**********************************************************************
1161 * X11DRV_PolyPolyline
1164 X11DRV_PolyPolyline( X11DRV_PDEVICE *physDev, const POINT* pt, const DWORD* counts, DWORD polylines )
1166 if (X11DRV_SetupGCForPen ( physDev ))
1168 unsigned int i, j, max = 0;
1171 /* Update the pixmap from the DIB section */
1172 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1174 for (i = 0; i < polylines; i++) if (counts[i] > max) max = counts[i];
1175 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * max )))
1177 WARN("No memory to convert POINTs to XPoints!\n");
1180 for (i = 0; i < polylines; i++)
1182 for (j = 0; j < counts[i]; j++)
1185 LPtoDP(physDev->hdc, &tmp, 1);
1186 points[j].x = physDev->org.x + tmp.x;
1187 points[j].y = physDev->org.y + tmp.y;
1191 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1192 points, j, CoordModeOrigin );
1193 wine_tsx11_unlock();
1196 /* Update the DIBSection of the dc's bitmap */
1197 X11DRV_UnlockDIBSection(physDev, TRUE);
1199 HeapFree( GetProcessHeap(), 0, points );
1205 /**********************************************************************
1206 * X11DRV_InternalFloodFill
1208 * Internal helper function for flood fill.
1209 * (xorg,yorg) is the origin of the X image relative to the drawable.
1210 * (x,y) is relative to the origin of the X image.
1212 static void X11DRV_InternalFloodFill(XImage *image, X11DRV_PDEVICE *physDev,
1215 unsigned long pixel, WORD fillType )
1219 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1220 (XGetPixel(image,x,y) != pixel) : \
1221 (XGetPixel(image,x,y) == pixel))
1223 if (!TO_FLOOD(x,y)) return;
1225 /* Find left and right boundaries */
1228 while ((left > 0) && TO_FLOOD( left-1, y )) left--;
1229 while ((right < image->width) && TO_FLOOD( right, y )) right++;
1230 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1231 xOrg + left, yOrg + y, right-left, 1 );
1233 /* Set the pixels of this line so we don't fill it again */
1235 for (x = left; x < right; x++)
1237 if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
1238 else XPutPixel( image, x, y, ~pixel );
1241 /* Fill the line above */
1248 while ((x < right) && !TO_FLOOD(x,y)) x++;
1249 if (x >= right) break;
1250 while ((x < right) && TO_FLOOD(x,y)) x++;
1251 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1252 xOrg, yOrg, pixel, fillType );
1256 /* Fill the line below */
1258 if ((y += 2) < image->height)
1263 while ((x < right) && !TO_FLOOD(x,y)) x++;
1264 if (x >= right) break;
1265 while ((x < right) && TO_FLOOD(x,y)) x++;
1266 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1267 xOrg, yOrg, pixel, fillType );
1274 static int ExtFloodFillXGetImageErrorHandler( Display *dpy, XErrorEvent *event, void *arg )
1276 return (event->request_code == X_GetImage && event->error_code == BadMatch);
1279 /**********************************************************************
1280 * X11DRV_ExtFloodFill
1283 X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color,
1290 TRACE("X11DRV_ExtFloodFill %d,%d %06lx %d\n", x, y, color, fillType );
1294 LPtoDP( physDev->hdc, &pt, 1 );
1295 if (!PtInRegion( physDev->region, pt.x, pt.y )) return FALSE;
1296 GetRgnBox( physDev->region, &rect );
1299 X11DRV_expect_error( gdi_display, ExtFloodFillXGetImageErrorHandler, NULL );
1300 image = XGetImage( gdi_display, physDev->drawable,
1301 physDev->org.x + rect.left, physDev->org.y + rect.top,
1302 rect.right - rect.left, rect.bottom - rect.top,
1303 AllPlanes, ZPixmap );
1304 if(X11DRV_check_error()) image = NULL;
1305 wine_tsx11_unlock();
1306 if (!image) return FALSE;
1308 if (X11DRV_SetupGCForBrush( physDev ))
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 */
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 ),
1322 wine_tsx11_unlock();
1323 /* Update the DIBSection of the dc's bitmap */
1324 X11DRV_UnlockDIBSection(physDev, TRUE);
1328 XDestroyImage( image );
1329 wine_tsx11_unlock();
1333 /**********************************************************************
1337 X11DRV_SetBkColor( X11DRV_PDEVICE *physDev, COLORREF color )
1339 physDev->backgroundPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1343 /**********************************************************************
1344 * X11DRV_SetTextColor
1347 X11DRV_SetTextColor( X11DRV_PDEVICE *physDev, COLORREF color )
1349 physDev->textPixel = X11DRV_PALETTE_ToPhysical( physDev, 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;
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;