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
28 #include <X11/Intrinsic.h>
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
52 #define ABS(x) ((x)<0?(-(x)):(x))
54 /* ROP code to GC function conversion */
55 const int X11DRV_XROPfunction[16] =
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 */
68 GXorInverted, /* R2_MERGENOTPEN */
69 GXcopy, /* R2_COPYPEN */
70 GXorReverse, /* R2_MERGEPENNOT */
71 GXor, /* R2_MERGEPEN */
76 /***********************************************************************
77 * X11DRV_SetupGCForPatBlt
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.
83 BOOL X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE *physDev, GC gc, BOOL fMapColors )
90 if (physDev->brush.style == BS_NULL) return FALSE;
91 if (physDev->brush.pixel == -1)
93 /* Special case used for monochrome pattern brushes.
94 * We need to swap foreground and background because
95 * Windows does it the wrong way...
97 val.foreground = physDev->backgroundPixel;
98 val.background = physDev->textPixel;
102 val.foreground = physDev->brush.pixel;
103 val.background = physDev->backgroundPixel;
105 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
107 val.foreground = X11DRV_PALETTE_XPixelToPalette[val.foreground];
108 val.background = X11DRV_PALETTE_XPixelToPalette[val.background];
111 val.function = X11DRV_XROPfunction[GetROP2(physDev->hdc)-1];
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
117 if (val.function == GXinvert)
119 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
120 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
121 val.function = GXxor;
123 val.fill_style = physDev->brush.fillStyle;
124 switch(val.fill_style)
127 case FillOpaqueStippled:
128 if (GetBkMode(physDev->hdc)==OPAQUE) val.fill_style = FillOpaqueStippled;
129 val.stipple = physDev->brush.pixmap;
134 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
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 );
151 else val.tile = physDev->brush.pixmap;
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;
164 XChangeGC( gdi_display, gc,
165 GCFunction | GCForeground | GCBackground | GCFillStyle |
166 GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
168 if (pixmap) XFreePixmap( gdi_display, pixmap );
174 /***********************************************************************
175 * X11DRV_SetupGCForBrush
177 * Setup physDev->gc for drawing operations using current brush.
178 * Return FALSE if brush is BS_NULL, TRUE otherwise.
180 BOOL X11DRV_SetupGCForBrush( X11DRV_PDEVICE *physDev )
182 return X11DRV_SetupGCForPatBlt( physDev, physDev->gc, FALSE );
186 /***********************************************************************
187 * X11DRV_SetupGCForPen
189 * Setup physDev->gc for drawing operations using current pen.
190 * Return FALSE if pen is PS_NULL, TRUE otherwise.
192 BOOL X11DRV_SetupGCForPen( X11DRV_PDEVICE *physDev )
195 UINT rop2 = GetROP2(physDev->hdc);
197 if (physDev->pen.style == PS_NULL) return FALSE;
202 val.foreground = BlackPixel( gdi_display, DefaultScreen(gdi_display) );
203 val.function = GXcopy;
206 val.foreground = WhitePixel( gdi_display, DefaultScreen(gdi_display) );
207 val.function = GXcopy;
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;
219 val.foreground = physDev->pen.pixel;
220 val.function = X11DRV_XROPfunction[rop2-1];
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))
228 TSXSetDashes( gdi_display, physDev->gc, 0, physDev->pen.dashes, physDev->pen.dash_len );
229 val.line_style = (GetBkMode(physDev->hdc) == OPAQUE) ? LineDoubleDash : LineOnOffDash;
231 else val.line_style = LineSolid;
232 val.line_width = physDev->pen.width;
233 if (val.line_width <= 1) {
234 val.cap_style = CapNotLast;
236 switch (physDev->pen.endcap)
238 case PS_ENDCAP_SQUARE:
239 val.cap_style = CapProjecting;
242 val.cap_style = CapButt;
244 case PS_ENDCAP_ROUND:
246 val.cap_style = CapRound;
249 switch (physDev->pen.linejoin)
252 val.join_style = JoinBevel;
255 val.join_style = JoinMiter;
259 val.join_style = JoinRound;
261 TSXChangeGC( gdi_display, physDev->gc,
262 GCFunction | GCForeground | GCBackground | GCLineWidth |
263 GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
268 /***********************************************************************
269 * X11DRV_SetupGCForText
271 * Setup physDev->gc for text drawing operations.
272 * Return FALSE if the font is null, TRUE otherwise.
274 BOOL X11DRV_SetupGCForText( X11DRV_PDEVICE *physDev )
276 XFontStruct* xfs = XFONT_GetFontStruct( physDev->font );
282 val.function = GXcopy; /* Text is always GXcopy */
283 val.foreground = physDev->textPixel;
284 val.background = physDev->backgroundPixel;
285 val.fill_style = FillSolid;
288 TSXChangeGC( gdi_display, physDev->gc,
289 GCFunction | GCForeground | GCBackground | GCFillStyle |
293 WARN("Physical font failure\n" );
297 /***********************************************************************
301 X11DRV_LineTo( X11DRV_PDEVICE *physDev, INT x, INT y )
305 if (X11DRV_SetupGCForPen( physDev )) {
306 /* Update the pixmap from the DIB section */
307 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
309 GetCurrentPositionEx( physDev->hdc, &pt[0] );
312 LPtoDP( physDev->hdc, pt, 2 );
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 );
318 /* Update the DIBSection from the pixmap */
319 X11DRV_UnlockDIBSection(physDev, TRUE);
326 /***********************************************************************
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.
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 )
338 INT xcenter, ycenter, istart_angle, idiff_angle;
339 INT width, oldwidth, oldendcap;
340 double start_angle, end_angle;
342 DC *dc = physDev->dc;
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 );
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;
359 if( dc->ArcDirection == AD_CLOCKWISE )
360 { INT tmp = xstart; xstart = xend; xend = tmp;
361 tmp = ystart; ystart = yend; yend = tmp; }
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;
368 if ((physDev->pen.style == PS_INSIDEFRAME))
370 if (2*width > (right-left)) width=(right-left + 1)/2;
371 if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
373 right -= (width - 1) / 2;
375 bottom -= (width - 1) / 2;
377 if(width == 0) width = 1; /* more accurate */
378 physDev->pen.width = width;
379 physDev->pen.endcap = PS_ENDCAP_SQUARE;
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) */
392 else /* notorious cases */
393 if ((start_angle == PI)&&( end_angle <0))
396 if ((end_angle == PI)&&( start_angle <0))
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;
402 /* Update the pixmap from the DIB section */
403 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
405 /* Fill arc with brush if Chord() or Pie() */
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 );
415 /* Draw arc and lines */
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 );
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);
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)
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--;
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--;
458 if(dy1 < 0) points[0].y--;
459 if(((right-left) | -2) == -2) points[1].x--;
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--;
466 if( dy1>0) points[3].y--;
467 if(((right-left) | -2) == -2 ) points[2].x--;
470 if( dx1 * 64 < dy1 * -37 ) points[3].x--;
474 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
475 points, lines+1, CoordModeOrigin );
480 /* Update the DIBSection of the pixmap */
481 X11DRV_UnlockDIBSection(physDev, update);
483 physDev->pen.width = oldwidth;
484 physDev->pen.endcap = oldendcap;
489 /***********************************************************************
493 X11DRV_Arc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
494 INT xstart, INT ystart, INT xend, INT yend )
496 return X11DRV_DrawArc( physDev, left, top, right, bottom,
497 xstart, ystart, xend, yend, 0 );
501 /***********************************************************************
505 X11DRV_Pie( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
506 INT xstart, INT ystart, INT xend, INT yend )
508 return X11DRV_DrawArc( physDev, left, top, right, bottom,
509 xstart, ystart, xend, yend, 2 );
512 /***********************************************************************
516 X11DRV_Chord( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
517 INT xstart, INT ystart, INT xend, INT yend )
519 return X11DRV_DrawArc( physDev, left, top, right, bottom,
520 xstart, ystart, xend, yend, 1 );
524 /***********************************************************************
528 X11DRV_Ellipse( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom )
531 DC *dc = physDev->dc;
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;
540 if (right < left) { INT tmp = right; right = left; left = tmp; }
541 if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
543 oldwidth = width = physDev->pen.width;
544 if (!width) width = 1;
545 if(physDev->pen.style == PS_NULL) width = 0;
547 if ((physDev->pen.style == PS_INSIDEFRAME))
549 if (2*width > (right-left)) width=(right-left + 1)/2;
550 if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
552 right -= (width - 1) / 2;
554 bottom -= (width - 1) / 2;
556 if(width == 0) width = 1; /* more accurate */
557 physDev->pen.width = width;
559 /* Update the pixmap from the DIB section */
560 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
562 if (X11DRV_SetupGCForBrush( physDev ))
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 );
569 if (X11DRV_SetupGCForPen( physDev ))
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 );
577 /* Update the DIBSection from the pixmap */
578 X11DRV_UnlockDIBSection(physDev, update);
580 physDev->pen.width = oldwidth;
585 /***********************************************************************
589 X11DRV_Rectangle(X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
591 INT width, oldwidth, oldjoinstyle;
592 DC *dc = physDev->dc;
595 TRACE("(%d %d %d %d)\n",
596 left, top, right, bottom);
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 );
603 if ((left == right) || (top == bottom)) return TRUE;
605 if (right < left) { INT tmp = right; right = left; left = tmp; }
606 if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
608 oldwidth = width = physDev->pen.width;
609 if (!width) width = 1;
610 if(physDev->pen.style == PS_NULL) width = 0;
612 if ((physDev->pen.style == PS_INSIDEFRAME))
614 if (2*width > (right-left)) width=(right-left + 1)/2;
615 if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
617 right -= (width - 1) / 2;
619 bottom -= (width - 1) / 2;
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;
627 /* Update the pixmap from the DIB section */
628 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
630 if ((right > left + width) && (bottom > top + width))
631 if (X11DRV_SetupGCForBrush( physDev ))
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);
639 if (X11DRV_SetupGCForPen( physDev ))
641 TSXDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
642 physDev->org.x + left, physDev->org.y + top,
643 right-left-1, bottom-top-1 );
647 /* Update the DIBSection from the pixmap */
648 X11DRV_UnlockDIBSection(physDev, update);
650 physDev->pen.width = oldwidth;
651 physDev->pen.linejoin = oldjoinstyle;
655 /***********************************************************************
659 X11DRV_RoundRect( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
660 INT bottom, INT ell_width, INT ell_height )
662 INT width, oldwidth, oldendcap;
663 DC *dc = physDev->dc;
666 TRACE("(%d %d %d %d %d %d\n",
667 left, top, right, bottom, ell_width, ell_height);
669 left = XLPTODP( dc, left );
670 top = YLPTODP( dc, top );
671 right = XLPTODP( dc, right );
672 bottom = YLPTODP( dc, bottom );
674 if ((left == right) || (top == bottom))
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);
682 /* Fix the coordinates */
684 if (right < left) { INT tmp = right; right = left; left = tmp; }
685 if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
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;
692 if ((physDev->pen.style == PS_INSIDEFRAME))
694 if (2*width > (right-left)) width=(right-left + 1)/2;
695 if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
697 right -= (width - 1) / 2;
699 bottom -= (width - 1) / 2;
701 if(width == 0) width = 1;
702 physDev->pen.width = width;
703 physDev->pen.endcap = PS_ENDCAP_SQUARE;
705 /* Update the pixmap from the DIB section */
706 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
709 if (X11DRV_SetupGCForBrush( physDev ))
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,
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,
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 );
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 );
751 if (ell_width < right - left)
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,
764 if (ell_height < bottom - top)
766 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
767 physDev->org.x + left + 1,
768 physDev->org.y + top + (ell_height + 1) / 2,
770 bottom - top - ell_height - 1);
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.
780 * BTW this stuff is optimized for an Xfree86 server
781 * read the comments inside the X11DRV_DrawArc function
783 if (X11DRV_SetupGCForPen( physDev ))
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 );
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 );
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 );
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 );
822 if (ell_width < right - left)
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);
835 if (ell_height < bottom - top)
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);
851 /* Update the DIBSection from the pixmap */
852 X11DRV_UnlockDIBSection(physDev, update);
854 physDev->pen.width = oldwidth;
855 physDev->pen.endcap = oldendcap;
860 /***********************************************************************
864 X11DRV_SetPixel( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
871 LPtoDP( physDev->hdc, &pt, 1 );
872 pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
874 /* Update the pixmap from the DIB section */
875 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
877 /* inefficient but simple... */
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 );
885 /* Update the DIBSection from the pixmap */
886 X11DRV_UnlockDIBSection(physDev, TRUE);
888 return X11DRV_PALETTE_ToLogical(pixel);
892 /***********************************************************************
896 X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y )
898 static Pixmap pixmap = 0;
902 DC *dc = physDev->dc;
906 LPtoDP( physDev->hdc, &pt, 1 );
908 /* Update the pixmap from the DIB section */
909 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
912 if (dc->flags & DC_MEMORY)
914 image = XGetImage( gdi_display, physDev->drawable,
915 physDev->org.x + pt.x, physDev->org.y + pt.y,
916 1, 1, AllPlanes, ZPixmap );
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 );
928 pixel = XGetPixel( image, 0, 0 );
929 XDestroyImage( image );
932 /* Update the DIBSection from the pixmap */
933 X11DRV_UnlockDIBSection(physDev, FALSE);
935 return X11DRV_PALETTE_ToLogical(pixel);
939 /***********************************************************************
943 X11DRV_PaintRgn( X11DRV_PDEVICE *physDev, HRGN hrgn )
945 if (X11DRV_SetupGCForBrush( physDev ))
949 RGNDATA *data = X11DRV_GetRegionData( hrgn, physDev->hdc );
951 if (!data) return FALSE;
952 rect = (XRectangle *)data->Buffer;
953 for (i = 0; i < data->rdh.nCount; i++)
955 rect[i].x += physDev->org.x;
956 rect[i].y += physDev->org.y;
959 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
961 XFillRectangles( gdi_display, physDev->drawable, physDev->gc, rect, data->rdh.nCount );
963 X11DRV_UnlockDIBSection(physDev, TRUE);
964 HeapFree( GetProcessHeap(), 0, data );
969 /**********************************************************************
973 X11DRV_Polyline( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
978 DC *dc = physDev->dc;
980 if((oldwidth = physDev->pen.width) == 0) physDev->pen.width = 1;
982 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * count )))
984 WARN("No memory to convert POINTs to XPoints!\n");
987 for (i = 0; i < count; i++)
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 );
993 if (X11DRV_SetupGCForPen ( physDev ))
995 /* Update the pixmap from the DIB section */
996 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
998 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
999 points, count, CoordModeOrigin );
1001 /* Update the DIBSection from the pixmap */
1002 X11DRV_UnlockDIBSection(physDev, TRUE);
1005 HeapFree( GetProcessHeap(), 0, points );
1006 physDev->pen.width = oldwidth;
1011 /**********************************************************************
1015 X11DRV_Polygon( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1019 DC *dc = physDev->dc;
1020 BOOL update = FALSE;
1022 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) )))
1024 WARN("No memory to convert POINTs to XPoints!\n");
1027 for (i = 0; i < count; i++)
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 );
1032 points[count] = points[0];
1034 /* Update the pixmap from the DIB section */
1035 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1037 if (X11DRV_SetupGCForBrush( physDev ))
1039 TSXFillPolygon( gdi_display, physDev->drawable, physDev->gc,
1040 points, count+1, Complex, CoordModeOrigin);
1043 if (X11DRV_SetupGCForPen ( physDev ))
1045 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1046 points, count+1, CoordModeOrigin );
1050 /* Update the DIBSection from the pixmap */
1051 X11DRV_UnlockDIBSection(physDev, update);
1053 HeapFree( GetProcessHeap(), 0, points );
1058 /**********************************************************************
1059 * X11DRV_PolyPolygon
1062 X11DRV_PolyPolygon( X11DRV_PDEVICE *physDev, const POINT* pt, const INT* counts, UINT polygons)
1065 DC *dc = physDev->dc;
1067 /* FIXME: The points should be converted to device coords before */
1068 /* creating the region. */
1070 hrgn = CreatePolyPolygonRgn( pt, counts, polygons, GetPolyFillMode( physDev->hdc ) );
1071 X11DRV_PaintRgn( physDev, hrgn );
1072 DeleteObject( hrgn );
1074 /* Draw the outline of the polygons */
1076 if (X11DRV_SetupGCForPen ( physDev ))
1081 /* Update the pixmap from the DIB section */
1082 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1084 for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
1085 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) )))
1087 WARN("No memory to convert POINTs to XPoints!\n");
1090 for (i = 0; i < polygons; i++)
1092 for (j = 0; j < counts[i]; j++)
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 );
1098 points[j] = points[0];
1099 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1100 points, j + 1, CoordModeOrigin );
1103 /* Update the DIBSection of the dc's bitmap */
1104 X11DRV_UnlockDIBSection(physDev, TRUE);
1106 HeapFree( GetProcessHeap(), 0, points );
1112 /**********************************************************************
1113 * X11DRV_PolyPolyline
1116 X11DRV_PolyPolyline( X11DRV_PDEVICE *physDev, const POINT* pt, const DWORD* counts, DWORD polylines )
1118 DC *dc = physDev->dc;
1120 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 < polylines; i++) if (counts[i] > max) max = counts[i];
1129 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * max )))
1131 WARN("No memory to convert POINTs to XPoints!\n");
1134 for (i = 0; i < polylines; i++)
1136 for (j = 0; j < counts[i]; j++)
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 );
1142 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1143 points, j, CoordModeOrigin );
1146 /* Update the DIBSection of the dc's bitmap */
1147 X11DRV_UnlockDIBSection(physDev, TRUE);
1149 HeapFree( GetProcessHeap(), 0, points );
1155 /**********************************************************************
1156 * X11DRV_InternalFloodFill
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.
1162 static void X11DRV_InternalFloodFill(XImage *image, X11DRV_PDEVICE *physDev,
1165 Pixel pixel, WORD fillType )
1169 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1170 (XGetPixel(image,x,y) != pixel) : \
1171 (XGetPixel(image,x,y) == pixel))
1173 if (!TO_FLOOD(x,y)) return;
1175 /* Find left and right boundaries */
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 );
1183 /* Set the pixels of this line so we don't fill it again */
1185 for (x = left; x < right; x++)
1187 if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
1188 else XPutPixel( image, x, y, ~pixel );
1191 /* Fill the line above */
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 );
1206 /* Fill the line below */
1208 if ((y += 2) < image->height)
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 );
1224 /**********************************************************************
1225 * X11DRV_ExtFloodFill
1228 X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color,
1233 DC *dc = physDev->dc;
1235 TRACE("X11DRV_ExtFloodFill %d,%d %06lx %d\n", x, y, color, fillType );
1237 if (!PtVisible( dc->hSelf, x, y )) return FALSE;
1238 if (GetRgnBox( dc->hGCClipRgn, &rect ) == ERROR) return FALSE;
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;
1247 if (X11DRV_SetupGCForBrush( physDev ))
1249 /* Update the pixmap from the DIB section */
1250 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1252 /* ROP mode is always GXcopy for flood-fill */
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 ),
1261 wine_tsx11_unlock();
1262 /* Update the DIBSection of the dc's bitmap */
1263 X11DRV_UnlockDIBSection(physDev, TRUE);
1266 TSXDestroyImage( image );
1270 /**********************************************************************
1274 X11DRV_SetBkColor( X11DRV_PDEVICE *physDev, COLORREF color )
1276 physDev->backgroundPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1280 /**********************************************************************
1281 * X11DRV_SetTextColor
1284 X11DRV_SetTextColor( X11DRV_PDEVICE *physDev, COLORREF color )
1286 physDev->textPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1290 /***********************************************************************
1291 * GetDCOrgEx (X11DRV.@)
1293 BOOL X11DRV_GetDCOrgEx( X11DRV_PDEVICE *physDev, LPPOINT lpp )
1295 lpp->x = physDev->org.x + physDev->drawable_org.x;
1296 lpp->y = physDev->org.y + physDev->drawable_org.y;
1301 /***********************************************************************
1302 * SetDCOrg (X11DRV.@)
1304 DWORD X11DRV_SetDCOrg( X11DRV_PDEVICE *physDev, INT x, INT y )
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;