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
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 */
66 GXorInverted
, /* R2_MERGENOTPEN */
67 GXcopy
, /* R2_COPYPEN */
68 GXorReverse
, /* R2_MERGEPENNOT */
69 GXor
, /* R2_MERGEPEN */
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
)
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
;
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
)
125 case FillOpaqueStippled
:
126 if (GetBkMode(physDev
->hdc
)==OPAQUE
) val
.fill_style
= FillOpaqueStippled
;
127 val
.stipple
= physDev
->brush
.pixmap
;
132 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
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
);
149 else val
.tile
= physDev
->brush
.pixmap
;
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
;
162 XChangeGC( gdi_display
, gc
,
163 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
164 GCFillRule
| GCTileStipXOrigin
| GCTileStipYOrigin
| mask
,
166 if (pixmap
) XFreePixmap( gdi_display
, pixmap
);
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
)
193 UINT rop2
= GetROP2(physDev
->hdc
);
195 if (physDev
->pen
.style
== PS_NULL
) return FALSE
;
200 val
.foreground
= BlackPixel( gdi_display
, DefaultScreen(gdi_display
) );
201 val
.function
= GXcopy
;
204 val
.foreground
= WhitePixel( gdi_display
, DefaultScreen(gdi_display
) );
205 val
.function
= GXcopy
;
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
;
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
;
226 switch (physDev
->pen
.endcap
)
228 case PS_ENDCAP_SQUARE
:
229 val
.cap_style
= CapProjecting
;
232 val
.cap_style
= CapButt
;
234 case PS_ENDCAP_ROUND
:
236 val
.cap_style
= CapRound
;
239 switch (physDev
->pen
.linejoin
)
242 val
.join_style
= JoinBevel
;
245 val
.join_style
= JoinMiter
;
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
;
256 val
.line_style
= LineSolid
;
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
);
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
);
283 val
.function
= GXcopy
; /* Text is always GXcopy */
284 val
.foreground
= physDev
->textPixel
;
285 val
.background
= physDev
->backgroundPixel
;
286 val
.fill_style
= FillSolid
;
290 XChangeGC( gdi_display
, physDev
->gc
,
291 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
296 WARN("Physical font failure\n" );
300 /***********************************************************************
303 * Performs a world-to-viewport transformation on the specified width.
305 INT
X11DRV_XWStoDS( X11DRV_PDEVICE
*physDev
, INT width
)
313 LPtoDP( physDev
->hdc
, pt
, 2 );
314 return pt
[1].x
- pt
[0].x
;
317 /***********************************************************************
320 * Performs a world-to-viewport transformation on the specified height.
322 INT
X11DRV_YWStoDS( X11DRV_PDEVICE
*physDev
, INT height
)
330 LPtoDP( physDev
->hdc
, pt
, 2 );
331 return pt
[1].y
- pt
[0].y
;
334 /***********************************************************************
338 X11DRV_LineTo( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
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] );
349 LPtoDP( physDev
->hdc
, pt
, 2 );
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
);
357 /* Update the DIBSection from the pixmap */
358 X11DRV_UnlockDIBSection(physDev
, TRUE
);
365 /***********************************************************************
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.
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
;
379 double start_angle
, end_angle
;
385 SetRect(&rc
, left
, top
, right
, bottom
);
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;
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) */
429 else /* notorious cases */
430 if ((start_angle
== PI
)&&( end_angle
<0))
433 if ((end_angle
== PI
)&&( start_angle
<0))
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
)) {
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
);
454 /* Draw arc and lines */
456 if (X11DRV_SetupGCForPen( physDev
))
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
);
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)
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
--;
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
--;
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
--;
507 if( dy1
>0) points
[3].y
--;
508 if(((rc
.right
-rc
.left
) | -2) == -2 ) points
[2].x
--;
511 if( dx1
* 64 < dy1
* -37 ) points
[3].x
--;
515 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
516 points
, lines
+1, CoordModeOrigin
);
522 /* Update the DIBSection of the pixmap */
523 X11DRV_UnlockDIBSection(physDev
, update
);
525 physDev
->pen
.width
= oldwidth
;
530 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
569 X11DRV_Ellipse( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
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;
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
))
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 );
611 if (X11DRV_SetupGCForPen( physDev
))
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 );
621 /* Update the DIBSection from the pixmap */
622 X11DRV_UnlockDIBSection(physDev
, update
);
624 physDev
->pen
.width
= oldwidth
;
629 /***********************************************************************
633 X11DRV_Rectangle(X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
635 INT width
, oldwidth
, oldjoinstyle
;
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;
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
))
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);
684 if (X11DRV_SetupGCForPen( physDev
))
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 );
694 /* Update the DIBSection from the pixmap */
695 X11DRV_UnlockDIBSection(physDev
, update
);
697 physDev
->pen
.width
= oldwidth
;
698 physDev
->pen
.linejoin
= oldjoinstyle
;
702 /***********************************************************************
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
;
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
))
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;
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
))
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,
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,
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 );
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,
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);
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
))
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 );
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 );
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);
903 /* Update the DIBSection from the pixmap */
904 X11DRV_UnlockDIBSection(physDev
, update
);
906 physDev
->pen
.width
= oldwidth
;
907 physDev
->pen
.endcap
= oldendcap
;
912 /***********************************************************************
916 X11DRV_SetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
)
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... */
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
);
937 /* Update the DIBSection from the pixmap */
938 X11DRV_UnlockDIBSection(physDev
, TRUE
);
940 return X11DRV_PALETTE_ToLogical(pixel
);
944 /***********************************************************************
948 X11DRV_GetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
950 static Pixmap pixmap
= 0;
954 BOOL memdc
= (GetObjectType(physDev
->hdc
) == OBJ_MEMDC
);
958 LPtoDP( physDev
->hdc
, &pt
, 1 );
960 /* Update the pixmap from the DIB section */
961 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
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
);
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
);
984 /* Update the DIBSection from the pixmap */
985 X11DRV_UnlockDIBSection(physDev
, FALSE
);
987 return X11DRV_PALETTE_ToLogical(pixel
);
991 /***********************************************************************
995 X11DRV_PaintRgn( X11DRV_PDEVICE
*physDev
, HRGN hrgn
)
997 if (X11DRV_SetupGCForBrush( physDev
))
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
);
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
);
1021 /**********************************************************************
1025 X11DRV_Polyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1030 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * count
)))
1032 WARN("No memory to convert POINTs to XPoints!\n");
1035 for (i
= 0; i
< count
; 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
);
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
);
1058 /**********************************************************************
1062 X11DRV_Polygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1066 BOOL update
= FALSE
;
1068 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (count
+1) )))
1070 WARN("No memory to convert POINTs to XPoints!\n");
1073 for (i
= 0; i
< count
; 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
))
1088 XFillPolygon( gdi_display
, physDev
->drawable
, physDev
->gc
,
1089 points
, count
+1, Complex
, CoordModeOrigin
);
1090 wine_tsx11_unlock();
1093 if (X11DRV_SetupGCForPen ( physDev
))
1096 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1097 points
, count
+1, CoordModeOrigin
);
1098 wine_tsx11_unlock();
1102 /* Update the DIBSection from the pixmap */
1103 X11DRV_UnlockDIBSection(physDev
, update
);
1105 HeapFree( GetProcessHeap(), 0, points
);
1110 /**********************************************************************
1111 * X11DRV_PolyPolygon
1114 X11DRV_PolyPolygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
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
))
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");
1142 for (i
= 0; i
< polygons
; i
++)
1144 for (j
= 0; j
< counts
[i
]; j
++)
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
;
1152 points
[j
] = points
[0];
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
);
1168 /**********************************************************************
1169 * X11DRV_PolyPolyline
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;
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");
1188 for (i
= 0; i
< polylines
; i
++)
1190 for (j
= 0; j
< counts
[i
]; j
++)
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
;
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
);
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
,
1223 unsigned long pixel
, WORD fillType
)
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 */
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 */
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
)
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
);
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
1291 X11DRV_ExtFloodFill( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
,
1298 TRACE("X11DRV_ExtFloodFill %d,%d %06x %d\n", x
, y
, color
, fillType
);
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 */
1323 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1324 X11DRV_InternalFloodFill(image
, physDev
,
1327 physDev
->dc_rect
.left
+ rect
.left
,
1328 physDev
->dc_rect
.top
+ rect
.top
,
1330 wine_tsx11_unlock();
1331 /* Update the DIBSection of the dc's bitmap */
1332 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1336 XDestroyImage( image
);
1337 wine_tsx11_unlock();
1341 /**********************************************************************
1345 X11DRV_SetBkColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1347 physDev
->backgroundPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1351 /**********************************************************************
1352 * X11DRV_SetTextColor
1355 X11DRV_SetTextColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1357 physDev
->textPixel
= X11DRV_PALETTE_ToPhysical( physDev
, 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
;
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
;
1384 static unsigned char *get_icm_profile( unsigned long *size
)
1388 unsigned long count
, remaining
;
1389 unsigned char *profile
, *ret
= NULL
;
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
= count
* (format
/ 8);
1398 if ((ret
= HeapAlloc( GetProcessHeap(), 0, *size
))) memcpy( ret
, profile
, *size
);
1401 wine_tsx11_unlock();
1407 unsigned int unknown
[6];
1408 unsigned int state
[5];
1409 unsigned int count
[2];
1410 unsigned char buffer
[64];
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};
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];
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
)
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
)
1486 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1491 strcpyW( filename
, fullname
);
1492 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1493 WARN( "color profile not found\n" );