winhelp: Also store the relative offsets of a page in the history and back informatio...
[wine/dcerpc.git] / dlls / winex11.drv / graphics.c
blobaf623ac17ec42004c8ebaf91dec422036e2e8ca1
1 /*
2 * X11 graphics driver graphics functions
4 * Copyright 1993,1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * FIXME: only some of these functions obey the GM_ADVANCED
23 * graphics mode
26 #include "config.h"
28 #include <stdarg.h>
29 #include <math.h>
30 #ifdef HAVE_FLOAT_H
31 # include <float.h>
32 #endif
33 #include <stdlib.h>
34 #ifndef PI
35 #define PI M_PI
36 #endif
37 #include <string.h>
39 #include "windef.h"
40 #include "winbase.h"
41 #include "winreg.h"
43 #include "x11drv.h"
44 #include "x11font.h"
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
50 #define ABS(x) ((x)<0?(-(x)):(x))
52 /* ROP code to GC function conversion */
53 const int X11DRV_XROPfunction[16] =
55 GXclear, /* R2_BLACK */
56 GXnor, /* R2_NOTMERGEPEN */
57 GXandInverted, /* R2_MASKNOTPEN */
58 GXcopyInverted, /* R2_NOTCOPYPEN */
59 GXandReverse, /* R2_MASKPENNOT */
60 GXinvert, /* R2_NOT */
61 GXxor, /* R2_XORPEN */
62 GXnand, /* R2_NOTMASKPEN */
63 GXand, /* R2_MASKPEN */
64 GXequiv, /* R2_NOTXORPEN */
65 GXnoop, /* R2_NOP */
66 GXorInverted, /* R2_MERGENOTPEN */
67 GXcopy, /* R2_COPYPEN */
68 GXorReverse, /* R2_MERGEPENNOT */
69 GXor, /* R2_MERGEPEN */
70 GXset /* R2_WHITE */
74 /***********************************************************************
75 * X11DRV_SetupGCForPatBlt
77 * Setup the GC for a PatBlt operation using current brush.
78 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
79 * Return FALSE if brush is BS_NULL, TRUE otherwise.
81 BOOL X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE *physDev, GC gc, BOOL fMapColors )
83 XGCValues val;
84 unsigned long mask;
85 Pixmap pixmap = 0;
86 POINT pt;
88 if (physDev->brush.style == BS_NULL) return FALSE;
89 if (physDev->brush.pixel == -1)
91 /* Special case used for monochrome pattern brushes.
92 * We need to swap foreground and background because
93 * Windows does it the wrong way...
95 val.foreground = physDev->backgroundPixel;
96 val.background = physDev->textPixel;
98 else
100 val.foreground = physDev->brush.pixel;
101 val.background = physDev->backgroundPixel;
103 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
105 val.foreground = X11DRV_PALETTE_XPixelToPalette[val.foreground];
106 val.background = X11DRV_PALETTE_XPixelToPalette[val.background];
109 val.function = X11DRV_XROPfunction[GetROP2(physDev->hdc)-1];
111 ** Let's replace GXinvert by GXxor with (black xor white)
112 ** This solves the selection color and leak problems in excel
113 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
115 if (val.function == GXinvert)
117 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
118 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
119 val.function = GXxor;
121 val.fill_style = physDev->brush.fillStyle;
122 switch(val.fill_style)
124 case FillStippled:
125 case FillOpaqueStippled:
126 if (GetBkMode(physDev->hdc)==OPAQUE) val.fill_style = FillOpaqueStippled;
127 val.stipple = physDev->brush.pixmap;
128 mask = GCStipple;
129 break;
131 case FillTiled:
132 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
134 register int x, y;
135 XImage *image;
136 wine_tsx11_lock();
137 pixmap = XCreatePixmap( gdi_display, root_window, 8, 8, screen_depth );
138 image = XGetImage( gdi_display, physDev->brush.pixmap, 0, 0, 8, 8,
139 AllPlanes, ZPixmap );
140 for (y = 0; y < 8; y++)
141 for (x = 0; x < 8; x++)
142 XPutPixel( image, x, y,
143 X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, x, y)] );
144 XPutImage( gdi_display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
145 XDestroyImage( image );
146 wine_tsx11_unlock();
147 val.tile = pixmap;
149 else val.tile = physDev->brush.pixmap;
150 mask = GCTile;
151 break;
153 default:
154 mask = 0;
155 break;
157 GetBrushOrgEx( physDev->hdc, &pt );
158 val.ts_x_origin = physDev->dc_rect.left + pt.x;
159 val.ts_y_origin = physDev->dc_rect.top + pt.y;
160 val.fill_rule = (GetPolyFillMode(physDev->hdc) == WINDING) ? WindingRule : EvenOddRule;
161 wine_tsx11_lock();
162 XChangeGC( gdi_display, gc,
163 GCFunction | GCForeground | GCBackground | GCFillStyle |
164 GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
165 &val );
166 if (pixmap) XFreePixmap( gdi_display, pixmap );
167 wine_tsx11_unlock();
168 return TRUE;
172 /***********************************************************************
173 * X11DRV_SetupGCForBrush
175 * Setup physDev->gc for drawing operations using current brush.
176 * Return FALSE if brush is BS_NULL, TRUE otherwise.
178 BOOL X11DRV_SetupGCForBrush( X11DRV_PDEVICE *physDev )
180 return X11DRV_SetupGCForPatBlt( physDev, physDev->gc, FALSE );
184 /***********************************************************************
185 * X11DRV_SetupGCForPen
187 * Setup physDev->gc for drawing operations using current pen.
188 * Return FALSE if pen is PS_NULL, TRUE otherwise.
190 BOOL X11DRV_SetupGCForPen( X11DRV_PDEVICE *physDev )
192 XGCValues val;
193 UINT rop2 = GetROP2(physDev->hdc);
195 if (physDev->pen.style == PS_NULL) return FALSE;
197 switch (rop2)
199 case R2_BLACK :
200 val.foreground = BlackPixel( gdi_display, DefaultScreen(gdi_display) );
201 val.function = GXcopy;
202 break;
203 case R2_WHITE :
204 val.foreground = WhitePixel( gdi_display, DefaultScreen(gdi_display) );
205 val.function = GXcopy;
206 break;
207 case R2_XORPEN :
208 val.foreground = physDev->pen.pixel;
209 /* It is very unlikely someone wants to XOR with 0 */
210 /* This fixes the rubber-drawings in paintbrush */
211 if (val.foreground == 0)
212 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
213 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
214 val.function = GXxor;
215 break;
216 default :
217 val.foreground = physDev->pen.pixel;
218 val.function = X11DRV_XROPfunction[rop2-1];
220 val.background = physDev->backgroundPixel;
221 val.fill_style = FillSolid;
222 val.line_width = physDev->pen.width;
223 if (val.line_width <= 1) {
224 val.cap_style = CapNotLast;
225 } else {
226 switch (physDev->pen.endcap)
228 case PS_ENDCAP_SQUARE:
229 val.cap_style = CapProjecting;
230 break;
231 case PS_ENDCAP_FLAT:
232 val.cap_style = CapButt;
233 break;
234 case PS_ENDCAP_ROUND:
235 default:
236 val.cap_style = CapRound;
239 switch (physDev->pen.linejoin)
241 case PS_JOIN_BEVEL:
242 val.join_style = JoinBevel;
243 break;
244 case PS_JOIN_MITER:
245 val.join_style = JoinMiter;
246 break;
247 case PS_JOIN_ROUND:
248 default:
249 val.join_style = JoinRound;
252 if (physDev->pen.dash_len)
253 val.line_style = ((GetBkMode(physDev->hdc) == OPAQUE) && (!physDev->pen.ext))
254 ? LineDoubleDash : LineOnOffDash;
255 else
256 val.line_style = LineSolid;
258 wine_tsx11_lock();
259 if (physDev->pen.dash_len)
260 XSetDashes( gdi_display, physDev->gc, 0, physDev->pen.dashes, physDev->pen.dash_len );
261 XChangeGC( gdi_display, physDev->gc,
262 GCFunction | GCForeground | GCBackground | GCLineWidth |
263 GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
264 wine_tsx11_unlock();
265 return TRUE;
269 /***********************************************************************
270 * X11DRV_SetupGCForText
272 * Setup physDev->gc for text drawing operations.
273 * Return FALSE if the font is null, TRUE otherwise.
275 BOOL X11DRV_SetupGCForText( X11DRV_PDEVICE *physDev )
277 XFontStruct* xfs = XFONT_GetFontStruct( physDev->font );
279 if( xfs )
281 XGCValues val;
283 val.function = GXcopy; /* Text is always GXcopy */
284 val.foreground = physDev->textPixel;
285 val.background = physDev->backgroundPixel;
286 val.fill_style = FillSolid;
287 val.font = xfs->fid;
289 wine_tsx11_lock();
290 XChangeGC( gdi_display, physDev->gc,
291 GCFunction | GCForeground | GCBackground | GCFillStyle |
292 GCFont, &val );
293 wine_tsx11_unlock();
294 return TRUE;
296 WARN("Physical font failure\n" );
297 return FALSE;
300 /***********************************************************************
301 * X11DRV_XWStoDS
303 * Performs a world-to-viewport transformation on the specified width.
305 INT X11DRV_XWStoDS( X11DRV_PDEVICE *physDev, INT width )
307 POINT pt[2];
309 pt[0].x = 0;
310 pt[0].y = 0;
311 pt[1].x = width;
312 pt[1].y = 0;
313 LPtoDP( physDev->hdc, pt, 2 );
314 return pt[1].x - pt[0].x;
317 /***********************************************************************
318 * X11DRV_YWStoDS
320 * Performs a world-to-viewport transformation on the specified height.
322 INT X11DRV_YWStoDS( X11DRV_PDEVICE *physDev, INT height )
324 POINT pt[2];
326 pt[0].x = 0;
327 pt[0].y = 0;
328 pt[1].x = 0;
329 pt[1].y = height;
330 LPtoDP( physDev->hdc, pt, 2 );
331 return pt[1].y - pt[0].y;
334 /***********************************************************************
335 * X11DRV_LineTo
337 BOOL
338 X11DRV_LineTo( X11DRV_PDEVICE *physDev, INT x, INT y )
340 POINT pt[2];
342 if (X11DRV_SetupGCForPen( physDev )) {
343 /* Update the pixmap from the DIB section */
344 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
346 GetCurrentPositionEx( physDev->hdc, &pt[0] );
347 pt[1].x = x;
348 pt[1].y = y;
349 LPtoDP( physDev->hdc, pt, 2 );
351 wine_tsx11_lock();
352 XDrawLine(gdi_display, physDev->drawable, physDev->gc,
353 physDev->dc_rect.left + pt[0].x, physDev->dc_rect.top + pt[0].y,
354 physDev->dc_rect.left + pt[1].x, physDev->dc_rect.top + pt[1].y );
355 wine_tsx11_unlock();
357 /* Update the DIBSection from the pixmap */
358 X11DRV_UnlockDIBSection(physDev, TRUE);
360 return TRUE;
365 /***********************************************************************
366 * X11DRV_DrawArc
368 * Helper functions for Arc(), Chord() and Pie().
369 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
372 static BOOL
373 X11DRV_DrawArc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
374 INT bottom, INT xstart, INT ystart,
375 INT xend, INT yend, INT lines )
377 INT xcenter, ycenter, istart_angle, idiff_angle;
378 INT width, oldwidth;
379 double start_angle, end_angle;
380 XPoint points[4];
381 BOOL update = FALSE;
382 POINT start, end;
383 RECT rc;
385 SetRect(&rc, left, top, right, bottom);
386 start.x = xstart;
387 start.y = ystart;
388 end.x = xend;
389 end.y = yend;
390 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
391 LPtoDP(physDev->hdc, &start, 1);
392 LPtoDP(physDev->hdc, &end, 1);
394 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
395 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
396 if ((rc.left == rc.right) || (rc.top == rc.bottom)
397 ||(lines && ((rc.right-rc.left==1)||(rc.bottom-rc.top==1)))) return TRUE;
399 if (GetArcDirection( physDev->hdc ) == AD_CLOCKWISE)
400 { POINT tmp = start; start = end; end = tmp; }
402 oldwidth = width = physDev->pen.width;
403 if (!width) width = 1;
404 if(physDev->pen.style == PS_NULL) width = 0;
406 if ((physDev->pen.style == PS_INSIDEFRAME))
408 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
409 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
410 rc.left += width / 2;
411 rc.right -= (width - 1) / 2;
412 rc.top += width / 2;
413 rc.bottom -= (width - 1) / 2;
415 if(width == 0) width = 1; /* more accurate */
416 physDev->pen.width = width;
418 xcenter = (rc.right + rc.left) / 2;
419 ycenter = (rc.bottom + rc.top) / 2;
420 start_angle = atan2( (double)(ycenter-start.y)*(rc.right-rc.left),
421 (double)(start.x-xcenter)*(rc.bottom-rc.top) );
422 end_angle = atan2( (double)(ycenter-end.y)*(rc.right-rc.left),
423 (double)(end.x-xcenter)*(rc.bottom-rc.top) );
424 if ((start.x==end.x)&&(start.y==end.y))
425 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
426 start_angle = 0;
427 end_angle = 2* PI;
429 else /* notorious cases */
430 if ((start_angle == PI)&&( end_angle <0))
431 start_angle = - PI;
432 else
433 if ((end_angle == PI)&&( start_angle <0))
434 end_angle = - PI;
435 istart_angle = (INT)(start_angle * 180 * 64 / PI + 0.5);
436 idiff_angle = (INT)((end_angle - start_angle) * 180 * 64 / PI + 0.5);
437 if (idiff_angle <= 0) idiff_angle += 360 * 64;
439 /* Update the pixmap from the DIB section */
440 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
442 /* Fill arc with brush if Chord() or Pie() */
444 if ((lines > 0) && X11DRV_SetupGCForBrush( physDev )) {
445 wine_tsx11_lock();
446 XSetArcMode( gdi_display, physDev->gc, (lines==1) ? ArcChord : ArcPieSlice);
447 XFillArc( gdi_display, physDev->drawable, physDev->gc,
448 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
449 rc.right-rc.left-1, rc.bottom-rc.top-1, istart_angle, idiff_angle );
450 wine_tsx11_unlock();
451 update = TRUE;
454 /* Draw arc and lines */
456 if (X11DRV_SetupGCForPen( physDev ))
458 wine_tsx11_lock();
459 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
460 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
461 rc.right-rc.left-1, rc.bottom-rc.top-1, istart_angle, idiff_angle );
462 if (lines) {
463 /* use the truncated values */
464 start_angle=(double)istart_angle*PI/64./180.;
465 end_angle=(double)(istart_angle+idiff_angle)*PI/64./180.;
466 /* calculate the endpoints and round correctly */
467 points[0].x = (int) floor(physDev->dc_rect.left + (rc.right+rc.left)/2.0 +
468 cos(start_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
469 points[0].y = (int) floor(physDev->dc_rect.top + (rc.top+rc.bottom)/2.0 -
470 sin(start_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
471 points[1].x = (int) floor(physDev->dc_rect.left + (rc.right+rc.left)/2.0 +
472 cos(end_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
473 points[1].y = (int) floor(physDev->dc_rect.top + (rc.top+rc.bottom)/2.0 -
474 sin(end_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
476 /* OK, this stuff is optimized for Xfree86
477 * which is probably the server most used by
478 * wine users. Other X servers will not
479 * display correctly. (eXceed for instance)
480 * so if you feel you must make changes, make sure that
481 * you either use Xfree86 or separate your changes
482 * from these (compile switch or whatever)
484 if (lines == 2) {
485 INT dx1,dy1;
486 points[3] = points[1];
487 points[1].x = physDev->dc_rect.left + xcenter;
488 points[1].y = physDev->dc_rect.top + ycenter;
489 points[2] = points[1];
490 dx1=points[1].x-points[0].x;
491 dy1=points[1].y-points[0].y;
492 if(((rc.top-rc.bottom) | -2) == -2)
493 if(dy1>0) points[1].y--;
494 if(dx1<0) {
495 if (((-dx1)*64)<=ABS(dy1)*37) points[0].x--;
496 if(((-dx1*9))<(dy1*16)) points[0].y--;
497 if( dy1<0 && ((dx1*9)) < (dy1*16)) points[0].y--;
498 } else {
499 if(dy1 < 0) points[0].y--;
500 if(((rc.right-rc.left) | -2) == -2) points[1].x--;
502 dx1=points[3].x-points[2].x;
503 dy1=points[3].y-points[2].y;
504 if(((rc.top-rc.bottom) | -2 ) == -2)
505 if(dy1 < 0) points[2].y--;
506 if( dx1<0){
507 if( dy1>0) points[3].y--;
508 if(((rc.right-rc.left) | -2) == -2 ) points[2].x--;
509 }else {
510 points[3].y--;
511 if( dx1 * 64 < dy1 * -37 ) points[3].x--;
513 lines++;
515 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
516 points, lines+1, CoordModeOrigin );
518 wine_tsx11_unlock();
519 update = TRUE;
522 /* Update the DIBSection of the pixmap */
523 X11DRV_UnlockDIBSection(physDev, update);
525 physDev->pen.width = oldwidth;
526 return TRUE;
530 /***********************************************************************
531 * X11DRV_Arc
533 BOOL
534 X11DRV_Arc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
535 INT xstart, INT ystart, INT xend, INT yend )
537 return X11DRV_DrawArc( physDev, left, top, right, bottom,
538 xstart, ystart, xend, yend, 0 );
542 /***********************************************************************
543 * X11DRV_Pie
545 BOOL
546 X11DRV_Pie( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
547 INT xstart, INT ystart, INT xend, INT yend )
549 return X11DRV_DrawArc( physDev, left, top, right, bottom,
550 xstart, ystart, xend, yend, 2 );
553 /***********************************************************************
554 * X11DRV_Chord
556 BOOL
557 X11DRV_Chord( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
558 INT xstart, INT ystart, INT xend, INT yend )
560 return X11DRV_DrawArc( physDev, left, top, right, bottom,
561 xstart, ystart, xend, yend, 1 );
565 /***********************************************************************
566 * X11DRV_Ellipse
568 BOOL
569 X11DRV_Ellipse( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom )
571 INT width, oldwidth;
572 BOOL update = FALSE;
573 RECT rc;
575 SetRect(&rc, left, top, right, bottom);
576 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
578 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
580 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
581 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
583 oldwidth = width = physDev->pen.width;
584 if (!width) width = 1;
585 if(physDev->pen.style == PS_NULL) width = 0;
587 if ((physDev->pen.style == PS_INSIDEFRAME))
589 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
590 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
591 rc.left += width / 2;
592 rc.right -= (width - 1) / 2;
593 rc.top += width / 2;
594 rc.bottom -= (width - 1) / 2;
596 if(width == 0) width = 1; /* more accurate */
597 physDev->pen.width = width;
599 /* Update the pixmap from the DIB section */
600 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
602 if (X11DRV_SetupGCForBrush( physDev ))
604 wine_tsx11_lock();
605 XFillArc( gdi_display, physDev->drawable, physDev->gc,
606 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
607 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
608 wine_tsx11_unlock();
609 update = TRUE;
611 if (X11DRV_SetupGCForPen( physDev ))
613 wine_tsx11_lock();
614 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
615 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
616 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
617 wine_tsx11_unlock();
618 update = TRUE;
621 /* Update the DIBSection from the pixmap */
622 X11DRV_UnlockDIBSection(physDev, update);
624 physDev->pen.width = oldwidth;
625 return TRUE;
629 /***********************************************************************
630 * X11DRV_Rectangle
632 BOOL
633 X11DRV_Rectangle(X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
635 INT width, oldwidth, oldjoinstyle;
636 BOOL update = FALSE;
637 RECT rc;
639 TRACE("(%d %d %d %d)\n", left, top, right, bottom);
641 SetRect(&rc, left, top, right, bottom);
642 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
644 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
646 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
647 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
649 oldwidth = width = physDev->pen.width;
650 if (!width) width = 1;
651 if(physDev->pen.style == PS_NULL) width = 0;
653 if ((physDev->pen.style == PS_INSIDEFRAME))
655 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
656 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
657 rc.left += width / 2;
658 rc.right -= (width - 1) / 2;
659 rc.top += width / 2;
660 rc.bottom -= (width - 1) / 2;
662 if(width == 1) width = 0;
663 physDev->pen.width = width;
664 oldjoinstyle = physDev->pen.linejoin;
665 if(physDev->pen.type != PS_GEOMETRIC)
666 physDev->pen.linejoin = PS_JOIN_MITER;
668 /* Update the pixmap from the DIB section */
669 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
671 if ((rc.right > rc.left + width) && (rc.bottom > rc.top + width))
673 if (X11DRV_SetupGCForBrush( physDev ))
675 wine_tsx11_lock();
676 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
677 physDev->dc_rect.left + rc.left + (width + 1) / 2,
678 physDev->dc_rect.top + rc.top + (width + 1) / 2,
679 rc.right-rc.left-width-1, rc.bottom-rc.top-width-1);
680 wine_tsx11_unlock();
681 update = TRUE;
684 if (X11DRV_SetupGCForPen( physDev ))
686 wine_tsx11_lock();
687 XDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
688 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
689 rc.right-rc.left-1, rc.bottom-rc.top-1 );
690 wine_tsx11_unlock();
691 update = TRUE;
694 /* Update the DIBSection from the pixmap */
695 X11DRV_UnlockDIBSection(physDev, update);
697 physDev->pen.width = oldwidth;
698 physDev->pen.linejoin = oldjoinstyle;
699 return TRUE;
702 /***********************************************************************
703 * X11DRV_RoundRect
705 BOOL
706 X11DRV_RoundRect( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
707 INT bottom, INT ell_width, INT ell_height )
709 INT width, oldwidth, oldendcap;
710 BOOL update = FALSE;
711 RECT rc;
712 POINT pts[2];
714 TRACE("(%d %d %d %d %d %d\n",
715 left, top, right, bottom, ell_width, ell_height);
717 SetRect(&rc, left, top, right, bottom);
718 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
720 if ((rc.left == rc.right) || (rc.top == rc.bottom))
721 return TRUE;
723 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
724 called with width/height < 0 */
725 pts[0].x = pts[0].y = 0;
726 pts[1].x = ell_width;
727 pts[1].y = ell_height;
728 LPtoDP(physDev->hdc, pts, 2);
729 ell_width = max(abs( pts[1].x - pts[0].x ), 1);
730 ell_height = max(abs( pts[1].y - pts[0].y ), 1);
732 /* Fix the coordinates */
734 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
735 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
737 oldwidth = width = physDev->pen.width;
738 oldendcap = physDev->pen.endcap;
739 if (!width) width = 1;
740 if(physDev->pen.style == PS_NULL) width = 0;
742 if ((physDev->pen.style == PS_INSIDEFRAME))
744 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
745 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
746 rc.left += width / 2;
747 rc.right -= (width - 1) / 2;
748 rc.top += width / 2;
749 rc.bottom -= (width - 1) / 2;
751 if(width == 0) width = 1;
752 physDev->pen.width = width;
753 physDev->pen.endcap = PS_ENDCAP_SQUARE;
755 /* Update the pixmap from the DIB section */
756 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
758 if (X11DRV_SetupGCForBrush( physDev ))
760 wine_tsx11_lock();
761 if (ell_width > (rc.right-rc.left) )
762 if (ell_height > (rc.bottom-rc.top) )
763 XFillArc( gdi_display, physDev->drawable, physDev->gc,
764 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
765 rc.right - rc.left - 1, rc.bottom - rc.top - 1,
766 0, 360 * 64 );
767 else{
768 XFillArc( gdi_display, physDev->drawable, physDev->gc,
769 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
770 rc.right - rc.left - 1, ell_height, 0, 180 * 64 );
771 XFillArc( gdi_display, physDev->drawable, physDev->gc,
772 physDev->dc_rect.left + rc.left,
773 physDev->dc_rect.top + rc.bottom - ell_height - 1,
774 rc.right - rc.left - 1, ell_height, 180 * 64,
775 180 * 64 );
777 else if (ell_height > (rc.bottom-rc.top) ){
778 XFillArc( gdi_display, physDev->drawable, physDev->gc,
779 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
780 ell_width, rc.bottom - rc.top - 1, 90 * 64, 180 * 64 );
781 XFillArc( gdi_display, physDev->drawable, physDev->gc,
782 physDev->dc_rect.left + rc.right - ell_width - 1, physDev->dc_rect.top + rc.top,
783 ell_width, rc.bottom - rc.top - 1, 270 * 64, 180 * 64 );
784 }else{
785 XFillArc( gdi_display, physDev->drawable, physDev->gc,
786 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
787 ell_width, ell_height, 90 * 64, 90 * 64 );
788 XFillArc( gdi_display, physDev->drawable, physDev->gc,
789 physDev->dc_rect.left + rc.left,
790 physDev->dc_rect.top + rc.bottom - ell_height - 1,
791 ell_width, ell_height, 180 * 64, 90 * 64 );
792 XFillArc( gdi_display, physDev->drawable, physDev->gc,
793 physDev->dc_rect.left + rc.right - ell_width - 1,
794 physDev->dc_rect.top + rc.bottom - ell_height - 1,
795 ell_width, ell_height, 270 * 64, 90 * 64 );
796 XFillArc( gdi_display, physDev->drawable, physDev->gc,
797 physDev->dc_rect.left + rc.right - ell_width - 1,
798 physDev->dc_rect.top + rc.top,
799 ell_width, ell_height, 0, 90 * 64 );
801 if (ell_width < rc.right - rc.left)
803 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
804 physDev->dc_rect.left + rc.left + (ell_width + 1) / 2,
805 physDev->dc_rect.top + rc.top + 1,
806 rc.right - rc.left - ell_width - 1,
807 (ell_height + 1) / 2 - 1);
808 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
809 physDev->dc_rect.left + rc.left + (ell_width + 1) / 2,
810 physDev->dc_rect.top + rc.bottom - (ell_height) / 2 - 1,
811 rc.right - rc.left - ell_width - 1,
812 (ell_height) / 2 );
814 if (ell_height < rc.bottom - rc.top)
816 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
817 physDev->dc_rect.left + rc.left + 1,
818 physDev->dc_rect.top + rc.top + (ell_height + 1) / 2,
819 rc.right - rc.left - 2,
820 rc.bottom - rc.top - ell_height - 1);
822 wine_tsx11_unlock();
823 update = TRUE;
825 /* FIXME: this could be done with on X call
826 * more efficient and probably more correct
827 * on any X server: XDrawArcs will draw
828 * straight horizontal and vertical lines
829 * if width or height are zero.
831 * BTW this stuff is optimized for an Xfree86 server
832 * read the comments inside the X11DRV_DrawArc function
834 if (X11DRV_SetupGCForPen( physDev ))
836 wine_tsx11_lock();
837 if (ell_width > (rc.right-rc.left) )
838 if (ell_height > (rc.bottom-rc.top) )
839 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
840 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
841 rc.right - rc.left - 1, rc.bottom - rc.top - 1, 0 , 360 * 64 );
842 else{
843 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
844 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
845 rc.right - rc.left - 1, ell_height - 1, 0 , 180 * 64 );
846 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
847 physDev->dc_rect.left + rc.left,
848 physDev->dc_rect.top + rc.bottom - ell_height,
849 rc.right - rc.left - 1, ell_height - 1, 180 * 64 , 180 * 64 );
851 else if (ell_height > (rc.bottom-rc.top) ){
852 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
853 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
854 ell_width - 1 , rc.bottom - rc.top - 1, 90 * 64 , 180 * 64 );
855 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
856 physDev->dc_rect.left + rc.right - ell_width,
857 physDev->dc_rect.top + rc.top,
858 ell_width - 1 , rc.bottom - rc.top - 1, 270 * 64 , 180 * 64 );
859 }else{
860 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
861 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
862 ell_width - 1, ell_height - 1, 90 * 64, 90 * 64 );
863 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
864 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.bottom - ell_height,
865 ell_width - 1, ell_height - 1, 180 * 64, 90 * 64 );
866 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
867 physDev->dc_rect.left + rc.right - ell_width,
868 physDev->dc_rect.top + rc.bottom - ell_height,
869 ell_width - 1, ell_height - 1, 270 * 64, 90 * 64 );
870 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
871 physDev->dc_rect.left + rc.right - ell_width, physDev->dc_rect.top + rc.top,
872 ell_width - 1, ell_height - 1, 0, 90 * 64 );
874 if (ell_width < rc.right - rc.left)
876 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
877 physDev->dc_rect.left + rc.left + ell_width / 2,
878 physDev->dc_rect.top + rc.top,
879 physDev->dc_rect.left + rc.right - (ell_width+1) / 2,
880 physDev->dc_rect.top + rc.top);
881 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
882 physDev->dc_rect.left + rc.left + ell_width / 2 ,
883 physDev->dc_rect.top + rc.bottom - 1,
884 physDev->dc_rect.left + rc.right - (ell_width+1)/ 2,
885 physDev->dc_rect.top + rc.bottom - 1);
887 if (ell_height < rc.bottom - rc.top)
889 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
890 physDev->dc_rect.left + rc.right - 1,
891 physDev->dc_rect.top + rc.top + ell_height / 2,
892 physDev->dc_rect.left + rc.right - 1,
893 physDev->dc_rect.top + rc.bottom - (ell_height+1) / 2);
894 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
895 physDev->dc_rect.left + rc.left,
896 physDev->dc_rect.top + rc.top + ell_height / 2,
897 physDev->dc_rect.left + rc.left,
898 physDev->dc_rect.top + rc.bottom - (ell_height+1) / 2);
900 wine_tsx11_unlock();
901 update = TRUE;
903 /* Update the DIBSection from the pixmap */
904 X11DRV_UnlockDIBSection(physDev, update);
906 physDev->pen.width = oldwidth;
907 physDev->pen.endcap = oldendcap;
908 return TRUE;
912 /***********************************************************************
913 * X11DRV_SetPixel
915 COLORREF
916 X11DRV_SetPixel( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
918 unsigned long pixel;
919 POINT pt;
921 pt.x = x;
922 pt.y = y;
923 LPtoDP( physDev->hdc, &pt, 1 );
924 pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
926 /* Update the pixmap from the DIB section */
927 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
929 /* inefficient but simple... */
930 wine_tsx11_lock();
931 XSetForeground( gdi_display, physDev->gc, pixel );
932 XSetFunction( gdi_display, physDev->gc, GXcopy );
933 XDrawPoint( gdi_display, physDev->drawable, physDev->gc,
934 physDev->dc_rect.left + pt.x, physDev->dc_rect.top + pt.y );
935 wine_tsx11_unlock();
937 /* Update the DIBSection from the pixmap */
938 X11DRV_UnlockDIBSection(physDev, TRUE);
940 return X11DRV_PALETTE_ToLogical(pixel);
944 /***********************************************************************
945 * X11DRV_GetPixel
947 COLORREF
948 X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y )
950 static Pixmap pixmap = 0;
951 XImage * image;
952 int pixel;
953 POINT pt;
954 BOOL memdc = (GetObjectType(physDev->hdc) == OBJ_MEMDC);
956 pt.x = x;
957 pt.y = y;
958 LPtoDP( physDev->hdc, &pt, 1 );
960 /* Update the pixmap from the DIB section */
961 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
963 wine_tsx11_lock();
964 if (memdc)
966 image = XGetImage( gdi_display, physDev->drawable,
967 physDev->dc_rect.left + pt.x, physDev->dc_rect.top + pt.y,
968 1, 1, AllPlanes, ZPixmap );
970 else
972 /* If we are reading from the screen, use a temporary copy */
973 /* to avoid a BadMatch error */
974 if (!pixmap) pixmap = XCreatePixmap( gdi_display, root_window,
975 1, 1, physDev->depth );
976 XCopyArea( gdi_display, physDev->drawable, pixmap, BITMAP_colorGC,
977 physDev->dc_rect.left + pt.x, physDev->dc_rect.top + pt.y, 1, 1, 0, 0 );
978 image = XGetImage( gdi_display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
980 pixel = XGetPixel( image, 0, 0 );
981 XDestroyImage( image );
982 wine_tsx11_unlock();
984 /* Update the DIBSection from the pixmap */
985 X11DRV_UnlockDIBSection(physDev, FALSE);
987 return X11DRV_PALETTE_ToLogical(pixel);
991 /***********************************************************************
992 * X11DRV_PaintRgn
994 BOOL
995 X11DRV_PaintRgn( X11DRV_PDEVICE *physDev, HRGN hrgn )
997 if (X11DRV_SetupGCForBrush( physDev ))
999 unsigned int i;
1000 XRectangle *rect;
1001 RGNDATA *data = X11DRV_GetRegionData( hrgn, physDev->hdc );
1003 if (!data) return FALSE;
1004 rect = (XRectangle *)data->Buffer;
1005 for (i = 0; i < data->rdh.nCount; i++)
1007 rect[i].x += physDev->dc_rect.left;
1008 rect[i].y += physDev->dc_rect.top;
1011 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1012 wine_tsx11_lock();
1013 XFillRectangles( gdi_display, physDev->drawable, physDev->gc, rect, data->rdh.nCount );
1014 wine_tsx11_unlock();
1015 X11DRV_UnlockDIBSection(physDev, TRUE);
1016 HeapFree( GetProcessHeap(), 0, data );
1018 return TRUE;
1021 /**********************************************************************
1022 * X11DRV_Polyline
1024 BOOL
1025 X11DRV_Polyline( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1027 int i;
1028 XPoint *points;
1030 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * count )))
1032 WARN("No memory to convert POINTs to XPoints!\n");
1033 return FALSE;
1035 for (i = 0; i < count; i++)
1037 POINT tmp = pt[i];
1038 LPtoDP(physDev->hdc, &tmp, 1);
1039 points[i].x = physDev->dc_rect.left + tmp.x;
1040 points[i].y = physDev->dc_rect.top + tmp.y;
1043 if (X11DRV_SetupGCForPen ( physDev ))
1045 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1046 wine_tsx11_lock();
1047 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1048 points, count, CoordModeOrigin );
1049 wine_tsx11_unlock();
1050 X11DRV_UnlockDIBSection(physDev, TRUE);
1053 HeapFree( GetProcessHeap(), 0, points );
1054 return TRUE;
1058 /**********************************************************************
1059 * X11DRV_Polygon
1061 BOOL
1062 X11DRV_Polygon( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1064 register int i;
1065 XPoint *points;
1066 BOOL update = FALSE;
1068 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) )))
1070 WARN("No memory to convert POINTs to XPoints!\n");
1071 return FALSE;
1073 for (i = 0; i < count; i++)
1075 POINT tmp = pt[i];
1076 LPtoDP(physDev->hdc, &tmp, 1);
1077 points[i].x = physDev->dc_rect.left + tmp.x;
1078 points[i].y = physDev->dc_rect.top + tmp.y;
1080 points[count] = points[0];
1082 /* Update the pixmap from the DIB section */
1083 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1085 if (X11DRV_SetupGCForBrush( physDev ))
1087 wine_tsx11_lock();
1088 XFillPolygon( gdi_display, physDev->drawable, physDev->gc,
1089 points, count+1, Complex, CoordModeOrigin);
1090 wine_tsx11_unlock();
1091 update = TRUE;
1093 if (X11DRV_SetupGCForPen ( physDev ))
1095 wine_tsx11_lock();
1096 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1097 points, count+1, CoordModeOrigin );
1098 wine_tsx11_unlock();
1099 update = TRUE;
1102 /* Update the DIBSection from the pixmap */
1103 X11DRV_UnlockDIBSection(physDev, update);
1105 HeapFree( GetProcessHeap(), 0, points );
1106 return TRUE;
1110 /**********************************************************************
1111 * X11DRV_PolyPolygon
1113 BOOL
1114 X11DRV_PolyPolygon( X11DRV_PDEVICE *physDev, const POINT* pt, const INT* counts, UINT polygons)
1116 HRGN hrgn;
1118 /* FIXME: The points should be converted to device coords before */
1119 /* creating the region. */
1121 hrgn = CreatePolyPolygonRgn( pt, counts, polygons, GetPolyFillMode( physDev->hdc ) );
1122 X11DRV_PaintRgn( physDev, hrgn );
1123 DeleteObject( hrgn );
1125 /* Draw the outline of the polygons */
1127 if (X11DRV_SetupGCForPen ( physDev ))
1129 unsigned int i;
1130 int j, max = 0;
1131 XPoint *points;
1133 /* Update the pixmap from the DIB section */
1134 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1136 for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
1137 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) )))
1139 WARN("No memory to convert POINTs to XPoints!\n");
1140 return FALSE;
1142 for (i = 0; i < polygons; i++)
1144 for (j = 0; j < counts[i]; j++)
1146 POINT tmp = *pt;
1147 LPtoDP(physDev->hdc, &tmp, 1);
1148 points[j].x = physDev->dc_rect.left + tmp.x;
1149 points[j].y = physDev->dc_rect.top + tmp.y;
1150 pt++;
1152 points[j] = points[0];
1153 wine_tsx11_lock();
1154 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1155 points, j + 1, CoordModeOrigin );
1156 wine_tsx11_unlock();
1159 /* Update the DIBSection of the dc's bitmap */
1160 X11DRV_UnlockDIBSection(physDev, TRUE);
1162 HeapFree( GetProcessHeap(), 0, points );
1164 return TRUE;
1168 /**********************************************************************
1169 * X11DRV_PolyPolyline
1171 BOOL
1172 X11DRV_PolyPolyline( X11DRV_PDEVICE *physDev, const POINT* pt, const DWORD* counts, DWORD polylines )
1174 if (X11DRV_SetupGCForPen ( physDev ))
1176 unsigned int i, j, max = 0;
1177 XPoint *points;
1179 /* Update the pixmap from the DIB section */
1180 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1182 for (i = 0; i < polylines; i++) if (counts[i] > max) max = counts[i];
1183 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * max )))
1185 WARN("No memory to convert POINTs to XPoints!\n");
1186 return FALSE;
1188 for (i = 0; i < polylines; i++)
1190 for (j = 0; j < counts[i]; j++)
1192 POINT tmp = *pt;
1193 LPtoDP(physDev->hdc, &tmp, 1);
1194 points[j].x = physDev->dc_rect.left + tmp.x;
1195 points[j].y = physDev->dc_rect.top + tmp.y;
1196 pt++;
1198 wine_tsx11_lock();
1199 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1200 points, j, CoordModeOrigin );
1201 wine_tsx11_unlock();
1204 /* Update the DIBSection of the dc's bitmap */
1205 X11DRV_UnlockDIBSection(physDev, TRUE);
1207 HeapFree( GetProcessHeap(), 0, points );
1209 return TRUE;
1213 /**********************************************************************
1214 * X11DRV_InternalFloodFill
1216 * Internal helper function for flood fill.
1217 * (xorg,yorg) is the origin of the X image relative to the drawable.
1218 * (x,y) is relative to the origin of the X image.
1220 static void X11DRV_InternalFloodFill(XImage *image, X11DRV_PDEVICE *physDev,
1221 int x, int y,
1222 int xOrg, int yOrg,
1223 unsigned long pixel, WORD fillType )
1225 int left, right;
1227 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1228 (XGetPixel(image,x,y) != pixel) : \
1229 (XGetPixel(image,x,y) == pixel))
1231 if (!TO_FLOOD(x,y)) return;
1233 /* Find left and right boundaries */
1235 left = right = x;
1236 while ((left > 0) && TO_FLOOD( left-1, y )) left--;
1237 while ((right < image->width) && TO_FLOOD( right, y )) right++;
1238 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1239 xOrg + left, yOrg + y, right-left, 1 );
1241 /* Set the pixels of this line so we don't fill it again */
1243 for (x = left; x < right; x++)
1245 if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
1246 else XPutPixel( image, x, y, ~pixel );
1249 /* Fill the line above */
1251 if (--y >= 0)
1253 x = left;
1254 while (x < right)
1256 while ((x < right) && !TO_FLOOD(x,y)) x++;
1257 if (x >= right) break;
1258 while ((x < right) && TO_FLOOD(x,y)) x++;
1259 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1260 xOrg, yOrg, pixel, fillType );
1264 /* Fill the line below */
1266 if ((y += 2) < image->height)
1268 x = left;
1269 while (x < right)
1271 while ((x < right) && !TO_FLOOD(x,y)) x++;
1272 if (x >= right) break;
1273 while ((x < right) && TO_FLOOD(x,y)) x++;
1274 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1275 xOrg, yOrg, pixel, fillType );
1278 #undef TO_FLOOD
1282 static int ExtFloodFillXGetImageErrorHandler( Display *dpy, XErrorEvent *event, void *arg )
1284 return (event->request_code == X_GetImage && event->error_code == BadMatch);
1287 /**********************************************************************
1288 * X11DRV_ExtFloodFill
1290 BOOL
1291 X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color,
1292 UINT fillType )
1294 XImage *image;
1295 RECT rect;
1296 POINT pt;
1298 TRACE("X11DRV_ExtFloodFill %d,%d %06x %d\n", x, y, color, fillType );
1300 pt.x = x;
1301 pt.y = y;
1302 LPtoDP( physDev->hdc, &pt, 1 );
1303 if (!PtInRegion( physDev->region, pt.x, pt.y )) return FALSE;
1304 GetRgnBox( physDev->region, &rect );
1306 X11DRV_expect_error( gdi_display, ExtFloodFillXGetImageErrorHandler, NULL );
1307 image = XGetImage( gdi_display, physDev->drawable,
1308 physDev->dc_rect.left + rect.left, physDev->dc_rect.top + rect.top,
1309 rect.right - rect.left, rect.bottom - rect.top,
1310 AllPlanes, ZPixmap );
1311 if(X11DRV_check_error()) image = NULL;
1312 if (!image) return FALSE;
1314 if (X11DRV_SetupGCForBrush( physDev ))
1316 unsigned long pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1318 /* Update the pixmap from the DIB section */
1319 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1321 /* ROP mode is always GXcopy for flood-fill */
1322 wine_tsx11_lock();
1323 XSetFunction( gdi_display, physDev->gc, GXcopy );
1324 X11DRV_InternalFloodFill(image, physDev,
1325 pt.x - rect.left,
1326 pt.y - rect.top,
1327 physDev->dc_rect.left + rect.left,
1328 physDev->dc_rect.top + rect.top,
1329 pixel, fillType );
1330 wine_tsx11_unlock();
1331 /* Update the DIBSection of the dc's bitmap */
1332 X11DRV_UnlockDIBSection(physDev, TRUE);
1335 wine_tsx11_lock();
1336 XDestroyImage( image );
1337 wine_tsx11_unlock();
1338 return TRUE;
1341 /**********************************************************************
1342 * X11DRV_SetBkColor
1344 COLORREF
1345 X11DRV_SetBkColor( X11DRV_PDEVICE *physDev, COLORREF color )
1347 physDev->backgroundPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1348 return color;
1351 /**********************************************************************
1352 * X11DRV_SetTextColor
1354 COLORREF
1355 X11DRV_SetTextColor( X11DRV_PDEVICE *physDev, COLORREF color )
1357 physDev->textPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1358 return color;
1361 /***********************************************************************
1362 * GetDCOrgEx (X11DRV.@)
1364 BOOL X11DRV_GetDCOrgEx( X11DRV_PDEVICE *physDev, LPPOINT lpp )
1366 lpp->x = physDev->dc_rect.left + physDev->drawable_rect.left;
1367 lpp->y = physDev->dc_rect.top + physDev->drawable_rect.top;
1368 return TRUE;
1372 /***********************************************************************
1373 * SetDCOrg (X11DRV.@)
1375 DWORD X11DRV_SetDCOrg( X11DRV_PDEVICE *physDev, INT x, INT y )
1377 DWORD ret = MAKELONG( physDev->dc_rect.left + physDev->drawable_rect.left,
1378 physDev->dc_rect.top + physDev->drawable_rect.top );
1379 physDev->dc_rect.left = x - physDev->drawable_rect.left;
1380 physDev->dc_rect.top = y - physDev->drawable_rect.top;
1381 return ret;
1384 static unsigned char *get_icm_profile( unsigned long *size )
1386 Atom type;
1387 int format;
1388 unsigned long count, remaining;
1389 unsigned char *profile, *ret = NULL;
1391 wine_tsx11_lock();
1392 XGetWindowProperty( gdi_display, DefaultRootWindow(gdi_display),
1393 x11drv_atom(_ICC_PROFILE), 0, ~0UL, False, AnyPropertyType,
1394 &type, &format, &count, &remaining, &profile );
1395 if (format && count)
1397 *size = get_property_size( format, count );
1398 if ((ret = HeapAlloc( GetProcessHeap(), 0, *size ))) memcpy( ret, profile, *size );
1399 XFree( profile );
1401 wine_tsx11_unlock();
1402 return ret;
1405 typedef struct
1407 unsigned int unknown[6];
1408 unsigned int state[5];
1409 unsigned int count[2];
1410 unsigned char buffer[64];
1411 } sha_ctx;
1413 extern void WINAPI A_SHAInit( sha_ctx * );
1414 extern void WINAPI A_SHAUpdate( sha_ctx *, const unsigned char *, unsigned int );
1415 extern void WINAPI A_SHAFinal( sha_ctx *, unsigned char * );
1417 /***********************************************************************
1418 * GetICMProfile (X11DRV.@)
1420 BOOL X11DRV_GetICMProfile( X11DRV_PDEVICE *physDev, LPDWORD size, LPWSTR filename )
1422 static const WCHAR path[] =
1423 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s',
1424 '\\','c','o','l','o','r','\\',0};
1425 static const WCHAR srgb[] =
1426 {'s','R','G','B',' ','C','o','l','o','r',' ','S','p','a','c','e',' ',
1427 'P','r','o','f','i','l','e','.','i','c','m',0};
1428 static const WCHAR mntr[] =
1429 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1430 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t',
1431 'V','e','r','s','i','o','n','\\','I','C','M','\\','m','n','t','r',0};
1433 HKEY hkey;
1434 DWORD required, len;
1435 WCHAR profile[MAX_PATH], fullname[2*MAX_PATH + sizeof(path)/sizeof(WCHAR)];
1436 unsigned char *buffer;
1437 unsigned long buflen;
1439 if (!size) return FALSE;
1441 GetSystemDirectoryW( fullname, MAX_PATH );
1442 strcatW( fullname, path );
1444 len = sizeof(profile)/sizeof(WCHAR);
1445 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE, mntr, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL ) &&
1446 !RegEnumValueW( hkey, 0, profile, &len, NULL, NULL, NULL, NULL )) /* FIXME handle multiple values */
1448 strcatW( fullname, profile );
1449 RegCloseKey( hkey );
1451 else if ((buffer = get_icm_profile( &buflen )))
1453 static const WCHAR fmt[] = {'%','0','2','x',0};
1454 static const WCHAR icm[] = {'.','i','c','m',0};
1456 unsigned char sha1sum[20];
1457 unsigned int i;
1458 sha_ctx ctx;
1459 HANDLE file;
1461 A_SHAInit( &ctx );
1462 A_SHAUpdate( &ctx, buffer, buflen );
1463 A_SHAFinal( &ctx, sha1sum );
1465 for (i = 0; i < sizeof(sha1sum); i++) sprintfW( &profile[i * 2], fmt, sha1sum[i] );
1466 memcpy( &profile[i * 2], icm, sizeof(icm) );
1468 strcatW( fullname, profile );
1469 file = CreateFileW( fullname, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0 );
1470 if (file != INVALID_HANDLE_VALUE)
1472 DWORD written;
1474 if (!WriteFile( file, buffer, buflen, &written, NULL ) || written != buflen)
1475 ERR( "Unable to write color profile\n" );
1476 CloseHandle( file );
1478 HeapFree( GetProcessHeap(), 0, buffer );
1480 else strcatW( fullname, srgb );
1482 required = strlenW( fullname ) + 1;
1483 if (*size < required)
1485 *size = required;
1486 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1487 return FALSE;
1489 if (filename)
1491 strcpyW( filename, fullname );
1492 if (GetFileAttributesW( filename ) == INVALID_FILE_ATTRIBUTES)
1493 WARN( "color profile not found\n" );
1495 *size = required;
1496 return TRUE;