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;
346 SetRect(&rc, left, top, right, bottom);
351 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
352 LPtoDP(physDev->hdc, &start, 1);
353 LPtoDP(physDev->hdc, &end, 1);
355 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
356 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
357 if ((rc.left == rc.right) || (rc.top == rc.bottom)
358 ||(lines && ((rc.right-rc.left==1)||(rc.bottom-rc.top==1)))) return TRUE;
360 if (GetArcDirection( physDev->hdc ) == AD_CLOCKWISE)
361 { POINT tmp = start; start = end; end = 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 > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
371 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
372 rc.left += width / 2;
373 rc.right -= (width - 1) / 2;
375 rc.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 = (rc.right + rc.left) / 2;
382 ycenter = (rc.bottom + rc.top) / 2;
383 start_angle = atan2( (double)(ycenter-start.y)*(rc.right-rc.left),
384 (double)(start.x-xcenter)*(rc.bottom-rc.top) );
385 end_angle = atan2( (double)(ycenter-end.y)*(rc.right-rc.left),
386 (double)(end.x-xcenter)*(rc.bottom-rc.top) );
387 if ((start.x==end.x)&&(start.y==end.y))
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 + rc.left, physDev->org.y + rc.top,
411 rc.right-rc.left-1, rc.bottom-rc.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 + rc.left, physDev->org.y + rc.top,
420 rc.right-rc.left-1, rc.bottom-rc.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 + (rc.right+rc.left)/2.0 +
427 cos(start_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
428 points[0].y = (int) floor(physDev->org.y + (rc.top+rc.bottom)/2.0 -
429 sin(start_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
430 points[1].x = (int) floor(physDev->org.x + (rc.right+rc.left)/2.0 +
431 cos(end_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
432 points[1].y = (int) floor(physDev->org.y + (rc.top+rc.bottom)/2.0 -
433 sin(end_angle) * (rc.bottom-rc.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(((rc.top-rc.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(((rc.right-rc.left) | -2) == -2) points[1].x--;
461 dx1=points[3].x-points[2].x;
462 dy1=points[3].y-points[2].y;
463 if(((rc.top-rc.bottom) | -2 ) == -2)
464 if(dy1 < 0) points[2].y--;
466 if( dy1>0) points[3].y--;
467 if(((rc.right-rc.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 )
534 SetRect(&rc, left, top, right, bottom);
535 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
537 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
539 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
540 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
542 oldwidth = width = physDev->pen.width;
543 if (!width) width = 1;
544 if(physDev->pen.style == PS_NULL) width = 0;
546 if ((physDev->pen.style == PS_INSIDEFRAME))
548 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
549 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
550 rc.left += width / 2;
551 rc.right -= (width - 1) / 2;
553 rc.bottom -= (width - 1) / 2;
555 if(width == 0) width = 1; /* more accurate */
556 physDev->pen.width = width;
558 /* Update the pixmap from the DIB section */
559 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
561 if (X11DRV_SetupGCForBrush( physDev ))
563 TSXFillArc( gdi_display, physDev->drawable, physDev->gc,
564 physDev->org.x + rc.left, physDev->org.y + rc.top,
565 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
568 if (X11DRV_SetupGCForPen( physDev ))
570 TSXDrawArc( gdi_display, physDev->drawable, physDev->gc,
571 physDev->org.x + rc.left, physDev->org.y + rc.top,
572 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
576 /* Update the DIBSection from the pixmap */
577 X11DRV_UnlockDIBSection(physDev, update);
579 physDev->pen.width = oldwidth;
584 /***********************************************************************
588 X11DRV_Rectangle(X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
590 INT width, oldwidth, oldjoinstyle;
594 TRACE("(%d %d %d %d)\n", left, top, right, bottom);
596 SetRect(&rc, left, top, right, bottom);
597 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
599 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
601 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
602 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
604 oldwidth = width = physDev->pen.width;
605 if (!width) width = 1;
606 if(physDev->pen.style == PS_NULL) width = 0;
608 if ((physDev->pen.style == PS_INSIDEFRAME))
610 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
611 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
612 rc.left += width / 2;
613 rc.right -= (width - 1) / 2;
615 rc.bottom -= (width - 1) / 2;
617 if(width == 1) width = 0;
618 physDev->pen.width = width;
619 oldjoinstyle = physDev->pen.linejoin;
620 if(physDev->pen.type != PS_GEOMETRIC)
621 physDev->pen.linejoin = PS_JOIN_MITER;
623 /* Update the pixmap from the DIB section */
624 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
626 if ((rc.right > rc.left + width) && (rc.bottom > rc.top + width))
628 if (X11DRV_SetupGCForBrush( physDev ))
630 TSXFillRectangle( gdi_display, physDev->drawable, physDev->gc,
631 physDev->org.x + rc.left + (width + 1) / 2,
632 physDev->org.y + rc.top + (width + 1) / 2,
633 rc.right-rc.left-width-1, rc.bottom-rc.top-width-1);
637 if (X11DRV_SetupGCForPen( physDev ))
639 TSXDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
640 physDev->org.x + rc.left, physDev->org.y + rc.top,
641 rc.right-rc.left-1, rc.bottom-rc.top-1 );
645 /* Update the DIBSection from the pixmap */
646 X11DRV_UnlockDIBSection(physDev, update);
648 physDev->pen.width = oldwidth;
649 physDev->pen.linejoin = oldjoinstyle;
653 /***********************************************************************
657 X11DRV_RoundRect( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
658 INT bottom, INT ell_width, INT ell_height )
660 INT width, oldwidth, oldendcap;
665 TRACE("(%d %d %d %d %d %d\n",
666 left, top, right, bottom, ell_width, ell_height);
668 SetRect(&rc, left, top, right, bottom);
669 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
671 if ((rc.left == rc.right) || (rc.top == rc.bottom))
674 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
675 called with width/height < 0 */
676 pts[0].x = pts[0].y = 0;
677 pts[1].x = ell_width;
678 pts[1].y = ell_height;
679 LPtoDP(physDev->hdc, pts, 2);
680 ell_width = max(abs( pts[1].x - pts[0].x ), 1);
681 ell_height = max(abs( pts[1].y - pts[0].y ), 1);
683 /* Fix the coordinates */
685 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
686 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
688 oldwidth = width = physDev->pen.width;
689 oldendcap = physDev->pen.endcap;
690 if (!width) width = 1;
691 if(physDev->pen.style == PS_NULL) width = 0;
693 if ((physDev->pen.style == PS_INSIDEFRAME))
695 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
696 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
697 rc.left += width / 2;
698 rc.right -= (width - 1) / 2;
700 rc.bottom -= (width - 1) / 2;
702 if(width == 0) width = 1;
703 physDev->pen.width = width;
704 physDev->pen.endcap = PS_ENDCAP_SQUARE;
706 /* Update the pixmap from the DIB section */
707 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
710 if (X11DRV_SetupGCForBrush( physDev ))
712 if (ell_width > (rc.right-rc.left) )
713 if (ell_height > (rc.bottom-rc.top) )
714 XFillArc( gdi_display, physDev->drawable, physDev->gc,
715 physDev->org.x + rc.left, physDev->org.y + rc.top,
716 rc.right - rc.left - 1, rc.bottom - rc.top - 1,
719 XFillArc( gdi_display, physDev->drawable, physDev->gc,
720 physDev->org.x + rc.left, physDev->org.y + rc.top,
721 rc.right - rc.left - 1, ell_height, 0, 180 * 64 );
722 XFillArc( gdi_display, physDev->drawable, physDev->gc,
723 physDev->org.x + rc.left,
724 physDev->org.y + rc.bottom - ell_height - 1,
725 rc.right - rc.left - 1, ell_height, 180 * 64,
728 else if (ell_height > (rc.bottom-rc.top) ){
729 XFillArc( gdi_display, physDev->drawable, physDev->gc,
730 physDev->org.x + rc.left, physDev->org.y + rc.top,
731 ell_width, rc.bottom - rc.top - 1, 90 * 64, 180 * 64 );
732 XFillArc( gdi_display, physDev->drawable, physDev->gc,
733 physDev->org.x + rc.right - ell_width - 1, physDev->org.y + rc.top,
734 ell_width, rc.bottom - rc.top - 1, 270 * 64, 180 * 64 );
736 XFillArc( gdi_display, physDev->drawable, physDev->gc,
737 physDev->org.x + rc.left, physDev->org.y + rc.top,
738 ell_width, ell_height, 90 * 64, 90 * 64 );
739 XFillArc( gdi_display, physDev->drawable, physDev->gc,
740 physDev->org.x + rc.left,
741 physDev->org.y + rc.bottom - ell_height - 1,
742 ell_width, ell_height, 180 * 64, 90 * 64 );
743 XFillArc( gdi_display, physDev->drawable, physDev->gc,
744 physDev->org.x + rc.right - ell_width - 1,
745 physDev->org.y + rc.bottom - ell_height - 1,
746 ell_width, ell_height, 270 * 64, 90 * 64 );
747 XFillArc( gdi_display, physDev->drawable, physDev->gc,
748 physDev->org.x + rc.right - ell_width - 1,
749 physDev->org.y + rc.top,
750 ell_width, ell_height, 0, 90 * 64 );
752 if (ell_width < rc.right - rc.left)
754 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
755 physDev->org.x + rc.left + (ell_width + 1) / 2,
756 physDev->org.y + rc.top + 1,
757 rc.right - rc.left - ell_width - 1,
758 (ell_height + 1) / 2 - 1);
759 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
760 physDev->org.x + rc.left + (ell_width + 1) / 2,
761 physDev->org.y + rc.bottom - (ell_height) / 2 - 1,
762 rc.right - rc.left - ell_width - 1,
765 if (ell_height < rc.bottom - rc.top)
767 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
768 physDev->org.x + rc.left + 1,
769 physDev->org.y + rc.top + (ell_height + 1) / 2,
770 rc.right - rc.left - 2,
771 rc.bottom - rc.top - ell_height - 1);
775 /* FIXME: this could be done with on X call
776 * more efficient and probably more correct
777 * on any X server: XDrawArcs will draw
778 * straight horizontal and vertical lines
779 * if width or height are zero.
781 * BTW this stuff is optimized for an Xfree86 server
782 * read the comments inside the X11DRV_DrawArc function
784 if (X11DRV_SetupGCForPen( physDev ))
786 if (ell_width > (rc.right-rc.left) )
787 if (ell_height > (rc.bottom-rc.top) )
788 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
789 physDev->org.x + rc.left, physDev->org.y + rc.top,
790 rc.right - rc.left - 1, rc.bottom - rc.top - 1, 0 , 360 * 64 );
792 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
793 physDev->org.x + rc.left, physDev->org.y + rc.top,
794 rc.right - rc.left - 1, ell_height - 1, 0 , 180 * 64 );
795 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
796 physDev->org.x + rc.left,
797 physDev->org.y + rc.bottom - ell_height,
798 rc.right - rc.left - 1, ell_height - 1, 180 * 64 , 180 * 64 );
800 else if (ell_height > (rc.bottom-rc.top) ){
801 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
802 physDev->org.x + rc.left, physDev->org.y + rc.top,
803 ell_width - 1 , rc.bottom - rc.top - 1, 90 * 64 , 180 * 64 );
804 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
805 physDev->org.x + rc.right - ell_width,
806 physDev->org.y + rc.top,
807 ell_width - 1 , rc.bottom - rc.top - 1, 270 * 64 , 180 * 64 );
809 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
810 physDev->org.x + rc.left, physDev->org.y + rc.top,
811 ell_width - 1, ell_height - 1, 90 * 64, 90 * 64 );
812 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
813 physDev->org.x + rc.left, physDev->org.y + rc.bottom - ell_height,
814 ell_width - 1, ell_height - 1, 180 * 64, 90 * 64 );
815 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
816 physDev->org.x + rc.right - ell_width,
817 physDev->org.y + rc.bottom - ell_height,
818 ell_width - 1, ell_height - 1, 270 * 64, 90 * 64 );
819 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
820 physDev->org.x + rc.right - ell_width, physDev->org.y + rc.top,
821 ell_width - 1, ell_height - 1, 0, 90 * 64 );
823 if (ell_width < rc.right - rc.left)
825 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
826 physDev->org.x + rc.left + ell_width / 2,
827 physDev->org.y + rc.top,
828 physDev->org.x + rc.right - (ell_width+1) / 2,
829 physDev->org.y + rc.top);
830 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
831 physDev->org.x + rc.left + ell_width / 2 ,
832 physDev->org.y + rc.bottom - 1,
833 physDev->org.x + rc.right - (ell_width+1)/ 2,
834 physDev->org.y + rc.bottom - 1);
836 if (ell_height < rc.bottom - rc.top)
838 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
839 physDev->org.x + rc.right - 1,
840 physDev->org.y + rc.top + ell_height / 2,
841 physDev->org.x + rc.right - 1,
842 physDev->org.y + rc.bottom - (ell_height+1) / 2);
843 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
844 physDev->org.x + rc.left,
845 physDev->org.y + rc.top + ell_height / 2,
846 physDev->org.x + rc.left,
847 physDev->org.y + rc.bottom - (ell_height+1) / 2);
852 /* Update the DIBSection from the pixmap */
853 X11DRV_UnlockDIBSection(physDev, update);
855 physDev->pen.width = oldwidth;
856 physDev->pen.endcap = oldendcap;
861 /***********************************************************************
865 X11DRV_SetPixel( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
872 LPtoDP( physDev->hdc, &pt, 1 );
873 pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
875 /* Update the pixmap from the DIB section */
876 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
878 /* inefficient but simple... */
880 XSetForeground( gdi_display, physDev->gc, pixel );
881 XSetFunction( gdi_display, physDev->gc, GXcopy );
882 XDrawPoint( gdi_display, physDev->drawable, physDev->gc,
883 physDev->org.x + pt.x, physDev->org.y + pt.y );
886 /* Update the DIBSection from the pixmap */
887 X11DRV_UnlockDIBSection(physDev, TRUE);
889 return X11DRV_PALETTE_ToLogical(pixel);
893 /***********************************************************************
897 X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y )
899 static Pixmap pixmap = 0;
903 DC *dc = physDev->dc;
907 LPtoDP( physDev->hdc, &pt, 1 );
909 /* Update the pixmap from the DIB section */
910 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
913 if (dc->flags & DC_MEMORY)
915 image = XGetImage( gdi_display, physDev->drawable,
916 physDev->org.x + pt.x, physDev->org.y + pt.y,
917 1, 1, AllPlanes, ZPixmap );
921 /* If we are reading from the screen, use a temporary copy */
922 /* to avoid a BadMatch error */
923 if (!pixmap) pixmap = XCreatePixmap( gdi_display, root_window,
924 1, 1, dc->bitsPerPixel );
925 XCopyArea( gdi_display, physDev->drawable, pixmap, BITMAP_colorGC,
926 physDev->org.x + pt.x, physDev->org.y + pt.y, 1, 1, 0, 0 );
927 image = XGetImage( gdi_display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
929 pixel = XGetPixel( image, 0, 0 );
930 XDestroyImage( image );
933 /* Update the DIBSection from the pixmap */
934 X11DRV_UnlockDIBSection(physDev, FALSE);
936 return X11DRV_PALETTE_ToLogical(pixel);
940 /***********************************************************************
944 X11DRV_PaintRgn( X11DRV_PDEVICE *physDev, HRGN hrgn )
946 if (X11DRV_SetupGCForBrush( physDev ))
950 RGNDATA *data = X11DRV_GetRegionData( hrgn, physDev->hdc );
952 if (!data) return FALSE;
953 rect = (XRectangle *)data->Buffer;
954 for (i = 0; i < data->rdh.nCount; i++)
956 rect[i].x += physDev->org.x;
957 rect[i].y += physDev->org.y;
960 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
962 XFillRectangles( gdi_display, physDev->drawable, physDev->gc, rect, data->rdh.nCount );
964 X11DRV_UnlockDIBSection(physDev, TRUE);
965 HeapFree( GetProcessHeap(), 0, data );
970 /**********************************************************************
974 X11DRV_Polyline( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
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++)
990 LPtoDP(physDev->hdc, &tmp, 1);
991 points[i].x = physDev->org.x + tmp.x;
992 points[i].y = physDev->org.y + tmp.y;
995 if (X11DRV_SetupGCForPen ( physDev ))
997 /* Update the pixmap from the DIB section */
998 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1000 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1001 points, count, CoordModeOrigin );
1003 /* Update the DIBSection from the pixmap */
1004 X11DRV_UnlockDIBSection(physDev, TRUE);
1007 HeapFree( GetProcessHeap(), 0, points );
1008 physDev->pen.width = oldwidth;
1013 /**********************************************************************
1017 X11DRV_Polygon( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1021 BOOL update = FALSE;
1023 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) )))
1025 WARN("No memory to convert POINTs to XPoints!\n");
1028 for (i = 0; i < count; i++)
1031 LPtoDP(physDev->hdc, &tmp, 1);
1032 points[i].x = physDev->org.x + tmp.x;
1033 points[i].y = physDev->org.y + tmp.y;
1035 points[count] = points[0];
1037 /* Update the pixmap from the DIB section */
1038 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1040 if (X11DRV_SetupGCForBrush( physDev ))
1042 TSXFillPolygon( gdi_display, physDev->drawable, physDev->gc,
1043 points, count+1, Complex, CoordModeOrigin);
1046 if (X11DRV_SetupGCForPen ( physDev ))
1048 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1049 points, count+1, CoordModeOrigin );
1053 /* Update the DIBSection from the pixmap */
1054 X11DRV_UnlockDIBSection(physDev, update);
1056 HeapFree( GetProcessHeap(), 0, points );
1061 /**********************************************************************
1062 * X11DRV_PolyPolygon
1065 X11DRV_PolyPolygon( X11DRV_PDEVICE *physDev, const POINT* pt, const INT* counts, UINT polygons)
1069 /* FIXME: The points should be converted to device coords before */
1070 /* creating the region. */
1072 hrgn = CreatePolyPolygonRgn( pt, counts, polygons, GetPolyFillMode( physDev->hdc ) );
1073 X11DRV_PaintRgn( physDev, hrgn );
1074 DeleteObject( hrgn );
1076 /* Draw the outline of the polygons */
1078 if (X11DRV_SetupGCForPen ( physDev ))
1083 /* Update the pixmap from the DIB section */
1084 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1086 for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
1087 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) )))
1089 WARN("No memory to convert POINTs to XPoints!\n");
1092 for (i = 0; i < polygons; i++)
1094 for (j = 0; j < counts[i]; j++)
1097 LPtoDP(physDev->hdc, &tmp, 1);
1098 points[j].x = physDev->org.x + tmp.x;
1099 points[j].y = physDev->org.y + tmp.y;
1102 points[j] = points[0];
1103 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1104 points, j + 1, CoordModeOrigin );
1107 /* Update the DIBSection of the dc's bitmap */
1108 X11DRV_UnlockDIBSection(physDev, TRUE);
1110 HeapFree( GetProcessHeap(), 0, points );
1116 /**********************************************************************
1117 * X11DRV_PolyPolyline
1120 X11DRV_PolyPolyline( X11DRV_PDEVICE *physDev, const POINT* pt, const DWORD* counts, DWORD polylines )
1122 if (X11DRV_SetupGCForPen ( physDev ))
1127 /* Update the pixmap from the DIB section */
1128 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1130 for (i = 0; i < polylines; i++) if (counts[i] > max) max = counts[i];
1131 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * max )))
1133 WARN("No memory to convert POINTs to XPoints!\n");
1136 for (i = 0; i < polylines; i++)
1138 for (j = 0; j < counts[i]; j++)
1141 LPtoDP(physDev->hdc, &tmp, 1);
1142 points[j].x = physDev->org.x + tmp.x;
1143 points[j].y = physDev->org.y + tmp.y;
1146 TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
1147 points, j, CoordModeOrigin );
1150 /* Update the DIBSection of the dc's bitmap */
1151 X11DRV_UnlockDIBSection(physDev, TRUE);
1153 HeapFree( GetProcessHeap(), 0, points );
1159 /**********************************************************************
1160 * X11DRV_InternalFloodFill
1162 * Internal helper function for flood fill.
1163 * (xorg,yorg) is the origin of the X image relative to the drawable.
1164 * (x,y) is relative to the origin of the X image.
1166 static void X11DRV_InternalFloodFill(XImage *image, X11DRV_PDEVICE *physDev,
1169 Pixel pixel, WORD fillType )
1173 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1174 (XGetPixel(image,x,y) != pixel) : \
1175 (XGetPixel(image,x,y) == pixel))
1177 if (!TO_FLOOD(x,y)) return;
1179 /* Find left and right boundaries */
1182 while ((left > 0) && TO_FLOOD( left-1, y )) left--;
1183 while ((right < image->width) && TO_FLOOD( right, y )) right++;
1184 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1185 xOrg + left, yOrg + y, right-left, 1 );
1187 /* Set the pixels of this line so we don't fill it again */
1189 for (x = left; x < right; x++)
1191 if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
1192 else XPutPixel( image, x, y, ~pixel );
1195 /* Fill the line above */
1202 while ((x < right) && !TO_FLOOD(x,y)) x++;
1203 if (x >= right) break;
1204 while ((x < right) && TO_FLOOD(x,y)) x++;
1205 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1206 xOrg, yOrg, pixel, fillType );
1210 /* Fill the line below */
1212 if ((y += 2) < image->height)
1217 while ((x < right) && !TO_FLOOD(x,y)) x++;
1218 if (x >= right) break;
1219 while ((x < right) && TO_FLOOD(x,y)) x++;
1220 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1221 xOrg, yOrg, pixel, fillType );
1228 /**********************************************************************
1229 * X11DRV_ExtFloodFill
1232 X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color,
1237 DC *dc = physDev->dc;
1239 TRACE("X11DRV_ExtFloodFill %d,%d %06lx %d\n", x, y, color, fillType );
1241 if (!PtVisible( physDev->hdc, x, y )) return FALSE;
1242 if (GetRgnBox( dc->hGCClipRgn, &rect ) == ERROR) return FALSE;
1244 if (!(image = TSXGetImage( gdi_display, physDev->drawable,
1245 physDev->org.x + rect.left,
1246 physDev->org.y + rect.top,
1247 rect.right - rect.left,
1248 rect.bottom - rect.top,
1249 AllPlanes, ZPixmap ))) return FALSE;
1251 if (X11DRV_SetupGCForBrush( physDev ))
1256 LPtoDP(physDev->hdc, &pt, 1);
1257 /* Update the pixmap from the DIB section */
1258 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod, FALSE);
1260 /* ROP mode is always GXcopy for flood-fill */
1262 XSetFunction( gdi_display, physDev->gc, GXcopy );
1263 X11DRV_InternalFloodFill(image, physDev,
1264 physDev->org.x + pt.x - rect.left,
1265 physDev->org.y + pt.y - rect.top,
1266 rect.left, rect.top,
1267 X11DRV_PALETTE_ToPhysical( physDev, color ),
1269 wine_tsx11_unlock();
1270 /* Update the DIBSection of the dc's bitmap */
1271 X11DRV_UnlockDIBSection(physDev, TRUE);
1274 TSXDestroyImage( image );
1278 /**********************************************************************
1282 X11DRV_SetBkColor( X11DRV_PDEVICE *physDev, COLORREF color )
1284 physDev->backgroundPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1288 /**********************************************************************
1289 * X11DRV_SetTextColor
1292 X11DRV_SetTextColor( X11DRV_PDEVICE *physDev, COLORREF color )
1294 physDev->textPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1298 /***********************************************************************
1299 * GetDCOrgEx (X11DRV.@)
1301 BOOL X11DRV_GetDCOrgEx( X11DRV_PDEVICE *physDev, LPPOINT lpp )
1303 lpp->x = physDev->org.x + physDev->drawable_org.x;
1304 lpp->y = physDev->org.y + physDev->drawable_org.y;
1309 /***********************************************************************
1310 * SetDCOrg (X11DRV.@)
1312 DWORD X11DRV_SetDCOrg( X11DRV_PDEVICE *physDev, INT x, INT y )
1314 DWORD ret = MAKELONG( physDev->org.x + physDev->drawable_org.x,
1315 physDev->org.y + physDev->drawable_org.y );
1316 physDev->org.x = x - physDev->drawable_org.x;
1317 physDev->org.y = y - physDev->drawable_org.y;