2 * X11 graphics driver graphics functions
4 * Copyright 1993,1994 Alexandre Julliard
5 * Copyright 1998 Huw Davies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * FIXME: only some of these functions obey the GM_ADVANCED
47 #include "wine/debug.h"
48 #include "wine/unicode.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_GetRegionData
79 * Calls GetRegionData on the given region and converts the rectangle
80 * array to XRectangle format. The returned buffer must be freed by
81 * caller using HeapFree(GetProcessHeap(),...).
82 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
84 RGNDATA
*X11DRV_GetRegionData( HRGN hrgn
, HDC hdc_lptodp
)
92 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return NULL
;
93 if (sizeof(XRectangle
) > sizeof(RECT
))
95 /* add extra size for XRectangle array */
96 int count
= (size
- sizeof(RGNDATAHEADER
)) / sizeof(RECT
);
97 size
+= count
* (sizeof(XRectangle
) - sizeof(RECT
));
99 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return NULL
;
100 if (!GetRegionData( hrgn
, size
, data
))
102 HeapFree( GetProcessHeap(), 0, data
);
106 rect
= (RECT
*)data
->Buffer
;
107 xrect
= (XRectangle
*)data
->Buffer
;
108 if (hdc_lptodp
) /* map to device coordinates */
110 LPtoDP( hdc_lptodp
, (POINT
*)rect
, data
->rdh
.nCount
* 2 );
111 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
113 if (rect
[i
].right
< rect
[i
].left
)
115 INT tmp
= rect
[i
].right
;
116 rect
[i
].right
= rect
[i
].left
;
119 if (rect
[i
].bottom
< rect
[i
].top
)
121 INT tmp
= rect
[i
].bottom
;
122 rect
[i
].bottom
= rect
[i
].top
;
128 if (sizeof(XRectangle
) > sizeof(RECT
))
131 /* need to start from the end */
132 for (j
= data
->rdh
.nCount
-1; j
>= 0; j
--)
135 xrect
[j
].x
= max( min( tmp
.left
, SHRT_MAX
), SHRT_MIN
);
136 xrect
[j
].y
= max( min( tmp
.top
, SHRT_MAX
), SHRT_MIN
);
137 xrect
[j
].width
= max( min( tmp
.right
- xrect
[j
].x
, USHRT_MAX
), 0);
138 xrect
[j
].height
= max( min( tmp
.bottom
- xrect
[j
].y
, USHRT_MAX
), 0);
143 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
146 xrect
[i
].x
= max( min( tmp
.left
, SHRT_MAX
), SHRT_MIN
);
147 xrect
[i
].y
= max( min( tmp
.top
, SHRT_MAX
), SHRT_MIN
);
148 xrect
[i
].width
= max( min( tmp
.right
- xrect
[i
].x
, USHRT_MAX
), 0);
149 xrect
[i
].height
= max( min( tmp
.bottom
- xrect
[i
].y
, USHRT_MAX
), 0);
156 /***********************************************************************
157 * X11DRV_SetDeviceClipping
159 void CDECL
X11DRV_SetDeviceClipping( X11DRV_PDEVICE
*physDev
, HRGN vis_rgn
, HRGN clip_rgn
)
163 CombineRgn( physDev
->region
, vis_rgn
, clip_rgn
, clip_rgn
? RGN_AND
: RGN_COPY
);
164 if (!(data
= X11DRV_GetRegionData( physDev
->region
, 0 ))) return;
167 XSetClipRectangles( gdi_display
, physDev
->gc
, physDev
->dc_rect
.left
, physDev
->dc_rect
.top
,
168 (XRectangle
*)data
->Buffer
, data
->rdh
.nCount
, YXBanded
);
171 if (physDev
->xrender
) X11DRV_XRender_SetDeviceClipping(physDev
, data
);
173 HeapFree( GetProcessHeap(), 0, data
);
177 /***********************************************************************
178 * X11DRV_SetupGCForPatBlt
180 * Setup the GC for a PatBlt operation using current brush.
181 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
182 * Return FALSE if brush is BS_NULL, TRUE otherwise.
184 BOOL
X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE
*physDev
, GC gc
, BOOL fMapColors
)
191 if (physDev
->brush
.style
== BS_NULL
) return FALSE
;
192 if (physDev
->brush
.pixel
== -1)
194 /* Special case used for monochrome pattern brushes.
195 * We need to swap foreground and background because
196 * Windows does it the wrong way...
198 val
.foreground
= physDev
->backgroundPixel
;
199 val
.background
= physDev
->textPixel
;
203 val
.foreground
= physDev
->brush
.pixel
;
204 val
.background
= physDev
->backgroundPixel
;
206 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
208 val
.foreground
= X11DRV_PALETTE_XPixelToPalette
[val
.foreground
];
209 val
.background
= X11DRV_PALETTE_XPixelToPalette
[val
.background
];
212 val
.function
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
)-1];
214 ** Let's replace GXinvert by GXxor with (black xor white)
215 ** This solves the selection color and leak problems in excel
216 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
218 if (val
.function
== GXinvert
)
220 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
221 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
222 val
.function
= GXxor
;
224 val
.fill_style
= physDev
->brush
.fillStyle
;
225 switch(val
.fill_style
)
228 case FillOpaqueStippled
:
229 if (GetBkMode(physDev
->hdc
)==OPAQUE
) val
.fill_style
= FillOpaqueStippled
;
230 val
.stipple
= physDev
->brush
.pixmap
;
235 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
240 pixmap
= XCreatePixmap( gdi_display
, root_window
, 8, 8, physDev
->depth
);
241 image
= XGetImage( gdi_display
, physDev
->brush
.pixmap
, 0, 0, 8, 8,
242 AllPlanes
, ZPixmap
);
243 for (y
= 0; y
< 8; y
++)
244 for (x
= 0; x
< 8; x
++)
245 XPutPixel( image
, x
, y
,
246 X11DRV_PALETTE_XPixelToPalette
[XGetPixel( image
, x
, y
)] );
247 XPutImage( gdi_display
, pixmap
, gc
, image
, 0, 0, 0, 0, 8, 8 );
248 XDestroyImage( image
);
252 else val
.tile
= physDev
->brush
.pixmap
;
260 GetBrushOrgEx( physDev
->hdc
, &pt
);
261 val
.ts_x_origin
= physDev
->dc_rect
.left
+ pt
.x
;
262 val
.ts_y_origin
= physDev
->dc_rect
.top
+ pt
.y
;
263 val
.fill_rule
= (GetPolyFillMode(physDev
->hdc
) == WINDING
) ? WindingRule
: EvenOddRule
;
265 XChangeGC( gdi_display
, gc
,
266 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
267 GCFillRule
| GCTileStipXOrigin
| GCTileStipYOrigin
| mask
,
269 if (pixmap
) XFreePixmap( gdi_display
, pixmap
);
275 /***********************************************************************
276 * X11DRV_SetupGCForBrush
278 * Setup physDev->gc for drawing operations using current brush.
279 * Return FALSE if brush is BS_NULL, TRUE otherwise.
281 BOOL
X11DRV_SetupGCForBrush( X11DRV_PDEVICE
*physDev
)
283 return X11DRV_SetupGCForPatBlt( physDev
, physDev
->gc
, FALSE
);
287 /***********************************************************************
288 * X11DRV_SetupGCForPen
290 * Setup physDev->gc for drawing operations using current pen.
291 * Return FALSE if pen is PS_NULL, TRUE otherwise.
293 static BOOL
X11DRV_SetupGCForPen( X11DRV_PDEVICE
*physDev
)
296 UINT rop2
= GetROP2(physDev
->hdc
);
298 if (physDev
->pen
.style
== PS_NULL
) return FALSE
;
303 val
.foreground
= BlackPixel( gdi_display
, DefaultScreen(gdi_display
) );
304 val
.function
= GXcopy
;
307 val
.foreground
= WhitePixel( gdi_display
, DefaultScreen(gdi_display
) );
308 val
.function
= GXcopy
;
311 val
.foreground
= physDev
->pen
.pixel
;
312 /* It is very unlikely someone wants to XOR with 0 */
313 /* This fixes the rubber-drawings in paintbrush */
314 if (val
.foreground
== 0)
315 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
316 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
317 val
.function
= GXxor
;
320 val
.foreground
= physDev
->pen
.pixel
;
321 val
.function
= X11DRV_XROPfunction
[rop2
-1];
323 val
.background
= physDev
->backgroundPixel
;
324 val
.fill_style
= FillSolid
;
325 val
.line_width
= physDev
->pen
.width
;
326 if (val
.line_width
<= 1) {
327 val
.cap_style
= CapNotLast
;
329 switch (physDev
->pen
.endcap
)
331 case PS_ENDCAP_SQUARE
:
332 val
.cap_style
= CapProjecting
;
335 val
.cap_style
= CapButt
;
337 case PS_ENDCAP_ROUND
:
339 val
.cap_style
= CapRound
;
342 switch (physDev
->pen
.linejoin
)
345 val
.join_style
= JoinBevel
;
348 val
.join_style
= JoinMiter
;
352 val
.join_style
= JoinRound
;
355 if (physDev
->pen
.dash_len
)
356 val
.line_style
= ((GetBkMode(physDev
->hdc
) == OPAQUE
) && (!physDev
->pen
.ext
))
357 ? LineDoubleDash
: LineOnOffDash
;
359 val
.line_style
= LineSolid
;
362 if (physDev
->pen
.dash_len
)
363 XSetDashes( gdi_display
, physDev
->gc
, 0, physDev
->pen
.dashes
, physDev
->pen
.dash_len
);
364 XChangeGC( gdi_display
, physDev
->gc
,
365 GCFunction
| GCForeground
| GCBackground
| GCLineWidth
|
366 GCLineStyle
| GCCapStyle
| GCJoinStyle
| GCFillStyle
, &val
);
372 /***********************************************************************
373 * X11DRV_SetupGCForText
375 * Setup physDev->gc for text drawing operations.
376 * Return FALSE if the font is null, TRUE otherwise.
378 BOOL
X11DRV_SetupGCForText( X11DRV_PDEVICE
*physDev
)
380 XFontStruct
* xfs
= XFONT_GetFontStruct( physDev
->font
);
386 val
.function
= GXcopy
; /* Text is always GXcopy */
387 val
.foreground
= physDev
->textPixel
;
388 val
.background
= physDev
->backgroundPixel
;
389 val
.fill_style
= FillSolid
;
393 XChangeGC( gdi_display
, physDev
->gc
,
394 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
399 WARN("Physical font failure\n" );
403 /***********************************************************************
406 * Performs a world-to-viewport transformation on the specified width.
408 INT
X11DRV_XWStoDS( X11DRV_PDEVICE
*physDev
, INT width
)
416 LPtoDP( physDev
->hdc
, pt
, 2 );
417 return pt
[1].x
- pt
[0].x
;
420 /***********************************************************************
423 * Performs a world-to-viewport transformation on the specified height.
425 INT
X11DRV_YWStoDS( X11DRV_PDEVICE
*physDev
, INT height
)
433 LPtoDP( physDev
->hdc
, pt
, 2 );
434 return pt
[1].y
- pt
[0].y
;
437 /***********************************************************************
441 X11DRV_LineTo( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
445 if (X11DRV_SetupGCForPen( physDev
)) {
446 /* Update the pixmap from the DIB section */
447 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
449 GetCurrentPositionEx( physDev
->hdc
, &pt
[0] );
452 LPtoDP( physDev
->hdc
, pt
, 2 );
455 XDrawLine(gdi_display
, physDev
->drawable
, physDev
->gc
,
456 physDev
->dc_rect
.left
+ pt
[0].x
, physDev
->dc_rect
.top
+ pt
[0].y
,
457 physDev
->dc_rect
.left
+ pt
[1].x
, physDev
->dc_rect
.top
+ pt
[1].y
);
460 /* Update the DIBSection from the pixmap */
461 X11DRV_UnlockDIBSection(physDev
, TRUE
);
468 /***********************************************************************
471 * Helper functions for Arc(), Chord() and Pie().
472 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
476 X11DRV_DrawArc( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
,
477 INT bottom
, INT xstart
, INT ystart
,
478 INT xend
, INT yend
, INT lines
)
480 INT xcenter
, ycenter
, istart_angle
, idiff_angle
;
482 double start_angle
, end_angle
;
488 SetRect(&rc
, left
, top
, right
, bottom
);
493 LPtoDP(physDev
->hdc
, (POINT
*)&rc
, 2);
494 LPtoDP(physDev
->hdc
, &start
, 1);
495 LPtoDP(physDev
->hdc
, &end
, 1);
497 if (rc
.right
< rc
.left
) { INT tmp
= rc
.right
; rc
.right
= rc
.left
; rc
.left
= tmp
; }
498 if (rc
.bottom
< rc
.top
) { INT tmp
= rc
.bottom
; rc
.bottom
= rc
.top
; rc
.top
= tmp
; }
499 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)
500 ||(lines
&& ((rc
.right
-rc
.left
==1)||(rc
.bottom
-rc
.top
==1)))) return TRUE
;
502 if (GetArcDirection( physDev
->hdc
) == AD_CLOCKWISE
)
503 { POINT tmp
= start
; start
= end
; end
= tmp
; }
505 oldwidth
= width
= physDev
->pen
.width
;
506 if (!width
) width
= 1;
507 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
509 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
511 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
512 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
513 rc
.left
+= width
/ 2;
514 rc
.right
-= (width
- 1) / 2;
516 rc
.bottom
-= (width
- 1) / 2;
518 if(width
== 0) width
= 1; /* more accurate */
519 physDev
->pen
.width
= width
;
521 xcenter
= (rc
.right
+ rc
.left
) / 2;
522 ycenter
= (rc
.bottom
+ rc
.top
) / 2;
523 start_angle
= atan2( (double)(ycenter
-start
.y
)*(rc
.right
-rc
.left
),
524 (double)(start
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
525 end_angle
= atan2( (double)(ycenter
-end
.y
)*(rc
.right
-rc
.left
),
526 (double)(end
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
527 if ((start
.x
==end
.x
)&&(start
.y
==end
.y
))
528 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
532 else /* notorious cases */
533 if ((start_angle
== PI
)&&( end_angle
<0))
536 if ((end_angle
== PI
)&&( start_angle
<0))
538 istart_angle
= (INT
)(start_angle
* 180 * 64 / PI
+ 0.5);
539 idiff_angle
= (INT
)((end_angle
- start_angle
) * 180 * 64 / PI
+ 0.5);
540 if (idiff_angle
<= 0) idiff_angle
+= 360 * 64;
542 /* Update the pixmap from the DIB section */
543 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
545 /* Fill arc with brush if Chord() or Pie() */
547 if ((lines
> 0) && X11DRV_SetupGCForBrush( physDev
)) {
549 XSetArcMode( gdi_display
, physDev
->gc
, (lines
==1) ? ArcChord
: ArcPieSlice
);
550 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
551 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
552 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
557 /* Draw arc and lines */
559 if (X11DRV_SetupGCForPen( physDev
))
562 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
563 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
564 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
566 /* use the truncated values */
567 start_angle
=(double)istart_angle
*PI
/64./180.;
568 end_angle
=(double)(istart_angle
+idiff_angle
)*PI
/64./180.;
569 /* calculate the endpoints and round correctly */
570 points
[0].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
571 cos(start_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
572 points
[0].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
573 sin(start_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
574 points
[1].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
575 cos(end_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
576 points
[1].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
577 sin(end_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
579 /* OK, this stuff is optimized for Xfree86
580 * which is probably the server most used by
581 * wine users. Other X servers will not
582 * display correctly. (eXceed for instance)
583 * so if you feel you must make changes, make sure that
584 * you either use Xfree86 or separate your changes
585 * from these (compile switch or whatever)
589 points
[3] = points
[1];
590 points
[1].x
= physDev
->dc_rect
.left
+ xcenter
;
591 points
[1].y
= physDev
->dc_rect
.top
+ ycenter
;
592 points
[2] = points
[1];
593 dx1
=points
[1].x
-points
[0].x
;
594 dy1
=points
[1].y
-points
[0].y
;
595 if(((rc
.top
-rc
.bottom
) | -2) == -2)
596 if(dy1
>0) points
[1].y
--;
598 if (((-dx1
)*64)<=ABS(dy1
)*37) points
[0].x
--;
599 if(((-dx1
*9))<(dy1
*16)) points
[0].y
--;
600 if( dy1
<0 && ((dx1
*9)) < (dy1
*16)) points
[0].y
--;
602 if(dy1
< 0) points
[0].y
--;
603 if(((rc
.right
-rc
.left
) | -2) == -2) points
[1].x
--;
605 dx1
=points
[3].x
-points
[2].x
;
606 dy1
=points
[3].y
-points
[2].y
;
607 if(((rc
.top
-rc
.bottom
) | -2 ) == -2)
608 if(dy1
< 0) points
[2].y
--;
610 if( dy1
>0) points
[3].y
--;
611 if(((rc
.right
-rc
.left
) | -2) == -2 ) points
[2].x
--;
614 if( dx1
* 64 < dy1
* -37 ) points
[3].x
--;
618 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
619 points
, lines
+1, CoordModeOrigin
);
625 /* Update the DIBSection of the pixmap */
626 X11DRV_UnlockDIBSection(physDev
, update
);
628 physDev
->pen
.width
= oldwidth
;
633 /***********************************************************************
637 X11DRV_Arc( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
638 INT xstart
, INT ystart
, INT xend
, INT yend
)
640 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
641 xstart
, ystart
, xend
, yend
, 0 );
645 /***********************************************************************
649 X11DRV_Pie( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
650 INT xstart
, INT ystart
, INT xend
, INT yend
)
652 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
653 xstart
, ystart
, xend
, yend
, 2 );
656 /***********************************************************************
660 X11DRV_Chord( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
661 INT xstart
, INT ystart
, INT xend
, INT yend
)
663 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
664 xstart
, ystart
, xend
, yend
, 1 );
668 /***********************************************************************
672 X11DRV_Ellipse( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
678 SetRect(&rc
, left
, top
, right
, bottom
);
679 LPtoDP(physDev
->hdc
, (POINT
*)&rc
, 2);
681 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
683 if (rc
.right
< rc
.left
) { INT tmp
= rc
.right
; rc
.right
= rc
.left
; rc
.left
= tmp
; }
684 if (rc
.bottom
< rc
.top
) { INT tmp
= rc
.bottom
; rc
.bottom
= rc
.top
; rc
.top
= tmp
; }
686 oldwidth
= width
= physDev
->pen
.width
;
687 if (!width
) width
= 1;
688 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
690 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
692 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
693 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
694 rc
.left
+= width
/ 2;
695 rc
.right
-= (width
- 1) / 2;
697 rc
.bottom
-= (width
- 1) / 2;
699 if(width
== 0) width
= 1; /* more accurate */
700 physDev
->pen
.width
= width
;
702 /* Update the pixmap from the DIB section */
703 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
705 if (X11DRV_SetupGCForBrush( physDev
))
708 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
709 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
710 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
714 if (X11DRV_SetupGCForPen( physDev
))
717 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
718 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
719 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
724 /* Update the DIBSection from the pixmap */
725 X11DRV_UnlockDIBSection(physDev
, update
);
727 physDev
->pen
.width
= oldwidth
;
732 /***********************************************************************
736 X11DRV_Rectangle(X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
738 INT width
, oldwidth
, oldjoinstyle
;
742 TRACE("(%d %d %d %d)\n", left
, top
, right
, bottom
);
744 SetRect(&rc
, left
, top
, right
, bottom
);
745 LPtoDP(physDev
->hdc
, (POINT
*)&rc
, 2);
747 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
749 if (rc
.right
< rc
.left
) { INT tmp
= rc
.right
; rc
.right
= rc
.left
; rc
.left
= tmp
; }
750 if (rc
.bottom
< rc
.top
) { INT tmp
= rc
.bottom
; rc
.bottom
= rc
.top
; rc
.top
= tmp
; }
752 oldwidth
= width
= physDev
->pen
.width
;
753 if (!width
) width
= 1;
754 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
756 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
758 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
759 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
760 rc
.left
+= width
/ 2;
761 rc
.right
-= (width
- 1) / 2;
763 rc
.bottom
-= (width
- 1) / 2;
765 if(width
== 1) width
= 0;
766 physDev
->pen
.width
= width
;
767 oldjoinstyle
= physDev
->pen
.linejoin
;
768 if(physDev
->pen
.type
!= PS_GEOMETRIC
)
769 physDev
->pen
.linejoin
= PS_JOIN_MITER
;
771 /* Update the pixmap from the DIB section */
772 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
774 if ((rc
.right
> rc
.left
+ width
) && (rc
.bottom
> rc
.top
+ width
))
776 if (X11DRV_SetupGCForBrush( physDev
))
779 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
780 physDev
->dc_rect
.left
+ rc
.left
+ (width
+ 1) / 2,
781 physDev
->dc_rect
.top
+ rc
.top
+ (width
+ 1) / 2,
782 rc
.right
-rc
.left
-width
-1, rc
.bottom
-rc
.top
-width
-1);
787 if (X11DRV_SetupGCForPen( physDev
))
790 XDrawRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
791 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
792 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1 );
797 /* Update the DIBSection from the pixmap */
798 X11DRV_UnlockDIBSection(physDev
, update
);
800 physDev
->pen
.width
= oldwidth
;
801 physDev
->pen
.linejoin
= oldjoinstyle
;
805 /***********************************************************************
809 X11DRV_RoundRect( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
,
810 INT bottom
, INT ell_width
, INT ell_height
)
812 INT width
, oldwidth
, oldendcap
;
817 TRACE("(%d %d %d %d %d %d\n",
818 left
, top
, right
, bottom
, ell_width
, ell_height
);
820 SetRect(&rc
, left
, top
, right
, bottom
);
821 LPtoDP(physDev
->hdc
, (POINT
*)&rc
, 2);
823 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
))
826 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
827 called with width/height < 0 */
828 pts
[0].x
= pts
[0].y
= 0;
829 pts
[1].x
= ell_width
;
830 pts
[1].y
= ell_height
;
831 LPtoDP(physDev
->hdc
, pts
, 2);
832 ell_width
= max(abs( pts
[1].x
- pts
[0].x
), 1);
833 ell_height
= max(abs( pts
[1].y
- pts
[0].y
), 1);
835 /* Fix the coordinates */
837 if (rc
.right
< rc
.left
) { INT tmp
= rc
.right
; rc
.right
= rc
.left
; rc
.left
= tmp
; }
838 if (rc
.bottom
< rc
.top
) { INT tmp
= rc
.bottom
; rc
.bottom
= rc
.top
; rc
.top
= tmp
; }
840 oldwidth
= width
= physDev
->pen
.width
;
841 oldendcap
= physDev
->pen
.endcap
;
842 if (!width
) width
= 1;
843 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
845 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
847 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
848 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
849 rc
.left
+= width
/ 2;
850 rc
.right
-= (width
- 1) / 2;
852 rc
.bottom
-= (width
- 1) / 2;
854 if(width
== 0) width
= 1;
855 physDev
->pen
.width
= width
;
856 physDev
->pen
.endcap
= PS_ENDCAP_SQUARE
;
858 /* Update the pixmap from the DIB section */
859 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
861 if (X11DRV_SetupGCForBrush( physDev
))
864 if (ell_width
> (rc
.right
-rc
.left
) )
865 if (ell_height
> (rc
.bottom
-rc
.top
) )
866 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
867 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
868 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1,
871 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
872 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
873 rc
.right
- rc
.left
- 1, ell_height
, 0, 180 * 64 );
874 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
875 physDev
->dc_rect
.left
+ rc
.left
,
876 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
877 rc
.right
- rc
.left
- 1, ell_height
, 180 * 64,
880 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
881 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
882 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
883 ell_width
, rc
.bottom
- rc
.top
- 1, 90 * 64, 180 * 64 );
884 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
885 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1, physDev
->dc_rect
.top
+ rc
.top
,
886 ell_width
, rc
.bottom
- rc
.top
- 1, 270 * 64, 180 * 64 );
888 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
889 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
890 ell_width
, ell_height
, 90 * 64, 90 * 64 );
891 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
892 physDev
->dc_rect
.left
+ rc
.left
,
893 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
894 ell_width
, ell_height
, 180 * 64, 90 * 64 );
895 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
896 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
897 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
898 ell_width
, ell_height
, 270 * 64, 90 * 64 );
899 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
900 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
901 physDev
->dc_rect
.top
+ rc
.top
,
902 ell_width
, ell_height
, 0, 90 * 64 );
904 if (ell_width
< rc
.right
- rc
.left
)
906 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
907 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
908 physDev
->dc_rect
.top
+ rc
.top
+ 1,
909 rc
.right
- rc
.left
- ell_width
- 1,
910 (ell_height
+ 1) / 2 - 1);
911 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
912 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
913 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
) / 2 - 1,
914 rc
.right
- rc
.left
- ell_width
- 1,
917 if (ell_height
< rc
.bottom
- rc
.top
)
919 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
920 physDev
->dc_rect
.left
+ rc
.left
+ 1,
921 physDev
->dc_rect
.top
+ rc
.top
+ (ell_height
+ 1) / 2,
922 rc
.right
- rc
.left
- 2,
923 rc
.bottom
- rc
.top
- ell_height
- 1);
928 /* FIXME: this could be done with on X call
929 * more efficient and probably more correct
930 * on any X server: XDrawArcs will draw
931 * straight horizontal and vertical lines
932 * if width or height are zero.
934 * BTW this stuff is optimized for an Xfree86 server
935 * read the comments inside the X11DRV_DrawArc function
937 if (X11DRV_SetupGCForPen( physDev
))
940 if (ell_width
> (rc
.right
-rc
.left
) )
941 if (ell_height
> (rc
.bottom
-rc
.top
) )
942 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
943 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
944 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1, 0 , 360 * 64 );
946 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
947 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
948 rc
.right
- rc
.left
- 1, ell_height
- 1, 0 , 180 * 64 );
949 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
950 physDev
->dc_rect
.left
+ rc
.left
,
951 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
952 rc
.right
- rc
.left
- 1, ell_height
- 1, 180 * 64 , 180 * 64 );
954 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
955 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
956 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
957 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 90 * 64 , 180 * 64 );
958 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
959 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
960 physDev
->dc_rect
.top
+ rc
.top
,
961 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 270 * 64 , 180 * 64 );
963 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
964 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
965 ell_width
- 1, ell_height
- 1, 90 * 64, 90 * 64 );
966 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
967 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
968 ell_width
- 1, ell_height
- 1, 180 * 64, 90 * 64 );
969 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
970 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
971 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
972 ell_width
- 1, ell_height
- 1, 270 * 64, 90 * 64 );
973 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
974 physDev
->dc_rect
.left
+ rc
.right
- ell_width
, physDev
->dc_rect
.top
+ rc
.top
,
975 ell_width
- 1, ell_height
- 1, 0, 90 * 64 );
977 if (ell_width
< rc
.right
- rc
.left
)
979 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
980 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2,
981 physDev
->dc_rect
.top
+ rc
.top
,
982 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1) / 2,
983 physDev
->dc_rect
.top
+ rc
.top
);
984 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
985 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2 ,
986 physDev
->dc_rect
.top
+ rc
.bottom
- 1,
987 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1)/ 2,
988 physDev
->dc_rect
.top
+ rc
.bottom
- 1);
990 if (ell_height
< rc
.bottom
- rc
.top
)
992 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
993 physDev
->dc_rect
.left
+ rc
.right
- 1,
994 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
995 physDev
->dc_rect
.left
+ rc
.right
- 1,
996 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
997 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
998 physDev
->dc_rect
.left
+ rc
.left
,
999 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
1000 physDev
->dc_rect
.left
+ rc
.left
,
1001 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
1003 wine_tsx11_unlock();
1006 /* Update the DIBSection from the pixmap */
1007 X11DRV_UnlockDIBSection(physDev
, update
);
1009 physDev
->pen
.width
= oldwidth
;
1010 physDev
->pen
.endcap
= oldendcap
;
1015 /***********************************************************************
1019 X11DRV_SetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
)
1021 unsigned long pixel
;
1026 LPtoDP( physDev
->hdc
, &pt
, 1 );
1027 pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1029 /* Update the pixmap from the DIB section */
1030 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1032 /* inefficient but simple... */
1034 XSetForeground( gdi_display
, physDev
->gc
, pixel
);
1035 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1036 XDrawPoint( gdi_display
, physDev
->drawable
, physDev
->gc
,
1037 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
);
1038 wine_tsx11_unlock();
1040 /* Update the DIBSection from the pixmap */
1041 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1043 return X11DRV_PALETTE_ToLogical(physDev
, pixel
);
1047 /***********************************************************************
1051 X11DRV_GetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
1053 static Pixmap pixmap
= 0;
1057 BOOL memdc
= (GetObjectType(physDev
->hdc
) == OBJ_MEMDC
);
1061 LPtoDP( physDev
->hdc
, &pt
, 1 );
1063 /* Update the pixmap from the DIB section */
1064 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1069 image
= XGetImage( gdi_display
, physDev
->drawable
,
1070 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
,
1071 1, 1, AllPlanes
, ZPixmap
);
1075 /* If we are reading from the screen, use a temporary copy */
1076 /* to avoid a BadMatch error */
1077 if (!pixmap
) pixmap
= XCreatePixmap( gdi_display
, root_window
,
1078 1, 1, physDev
->depth
);
1079 XCopyArea( gdi_display
, physDev
->drawable
, pixmap
, get_bitmap_gc(physDev
->depth
),
1080 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
, 1, 1, 0, 0 );
1081 image
= XGetImage( gdi_display
, pixmap
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
1083 pixel
= XGetPixel( image
, 0, 0 );
1084 XDestroyImage( image
);
1085 wine_tsx11_unlock();
1087 /* Update the DIBSection from the pixmap */
1088 X11DRV_UnlockDIBSection(physDev
, FALSE
);
1089 if( physDev
->depth
> 1)
1090 pixel
= X11DRV_PALETTE_ToLogical(physDev
, pixel
);
1092 /* monochrome bitmaps return black or white */
1093 if( pixel
) pixel
= 0xffffff;
1099 /***********************************************************************
1103 X11DRV_PaintRgn( X11DRV_PDEVICE
*physDev
, HRGN hrgn
)
1105 if (X11DRV_SetupGCForBrush( physDev
))
1109 RGNDATA
*data
= X11DRV_GetRegionData( hrgn
, physDev
->hdc
);
1111 if (!data
) return FALSE
;
1112 rect
= (XRectangle
*)data
->Buffer
;
1113 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
1115 rect
[i
].x
+= physDev
->dc_rect
.left
;
1116 rect
[i
].y
+= physDev
->dc_rect
.top
;
1119 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1121 XFillRectangles( gdi_display
, physDev
->drawable
, physDev
->gc
, rect
, data
->rdh
.nCount
);
1122 wine_tsx11_unlock();
1123 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1124 HeapFree( GetProcessHeap(), 0, data
);
1129 /**********************************************************************
1133 X11DRV_Polyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1138 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * count
)))
1140 WARN("No memory to convert POINTs to XPoints!\n");
1143 for (i
= 0; i
< count
; i
++)
1146 LPtoDP(physDev
->hdc
, &tmp
, 1);
1147 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1148 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1151 if (X11DRV_SetupGCForPen ( physDev
))
1153 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1155 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1156 points
, count
, CoordModeOrigin
);
1157 wine_tsx11_unlock();
1158 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1161 HeapFree( GetProcessHeap(), 0, points
);
1166 /**********************************************************************
1170 X11DRV_Polygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1174 BOOL update
= FALSE
;
1176 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (count
+1) )))
1178 WARN("No memory to convert POINTs to XPoints!\n");
1181 for (i
= 0; i
< count
; i
++)
1184 LPtoDP(physDev
->hdc
, &tmp
, 1);
1185 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1186 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1188 points
[count
] = points
[0];
1190 /* Update the pixmap from the DIB section */
1191 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1193 if (X11DRV_SetupGCForBrush( physDev
))
1196 XFillPolygon( gdi_display
, physDev
->drawable
, physDev
->gc
,
1197 points
, count
+1, Complex
, CoordModeOrigin
);
1198 wine_tsx11_unlock();
1201 if (X11DRV_SetupGCForPen ( physDev
))
1204 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1205 points
, count
+1, CoordModeOrigin
);
1206 wine_tsx11_unlock();
1210 /* Update the DIBSection from the pixmap */
1211 X11DRV_UnlockDIBSection(physDev
, update
);
1213 HeapFree( GetProcessHeap(), 0, points
);
1218 /**********************************************************************
1219 * X11DRV_PolyPolygon
1222 X11DRV_PolyPolygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
1226 /* FIXME: The points should be converted to device coords before */
1227 /* creating the region. */
1229 hrgn
= CreatePolyPolygonRgn( pt
, counts
, polygons
, GetPolyFillMode( physDev
->hdc
) );
1230 X11DRV_PaintRgn( physDev
, hrgn
);
1231 DeleteObject( hrgn
);
1233 /* Draw the outline of the polygons */
1235 if (X11DRV_SetupGCForPen ( physDev
))
1241 /* Update the pixmap from the DIB section */
1242 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1244 for (i
= 0; i
< polygons
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1245 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (max
+1) )))
1247 WARN("No memory to convert POINTs to XPoints!\n");
1250 for (i
= 0; i
< polygons
; i
++)
1252 for (j
= 0; j
< counts
[i
]; j
++)
1255 LPtoDP(physDev
->hdc
, &tmp
, 1);
1256 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1257 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1260 points
[j
] = points
[0];
1262 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1263 points
, j
+ 1, CoordModeOrigin
);
1264 wine_tsx11_unlock();
1267 /* Update the DIBSection of the dc's bitmap */
1268 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1270 HeapFree( GetProcessHeap(), 0, points
);
1276 /**********************************************************************
1277 * X11DRV_PolyPolyline
1280 X11DRV_PolyPolyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const DWORD
* counts
, DWORD polylines
)
1282 if (X11DRV_SetupGCForPen ( physDev
))
1284 unsigned int i
, j
, max
= 0;
1287 /* Update the pixmap from the DIB section */
1288 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1290 for (i
= 0; i
< polylines
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1291 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * max
)))
1293 WARN("No memory to convert POINTs to XPoints!\n");
1296 for (i
= 0; i
< polylines
; i
++)
1298 for (j
= 0; j
< counts
[i
]; j
++)
1301 LPtoDP(physDev
->hdc
, &tmp
, 1);
1302 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1303 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1307 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1308 points
, j
, CoordModeOrigin
);
1309 wine_tsx11_unlock();
1312 /* Update the DIBSection of the dc's bitmap */
1313 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1315 HeapFree( GetProcessHeap(), 0, points
);
1321 /**********************************************************************
1322 * X11DRV_InternalFloodFill
1324 * Internal helper function for flood fill.
1325 * (xorg,yorg) is the origin of the X image relative to the drawable.
1326 * (x,y) is relative to the origin of the X image.
1328 static void X11DRV_InternalFloodFill(XImage
*image
, X11DRV_PDEVICE
*physDev
,
1331 unsigned long pixel
, WORD fillType
)
1335 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1336 (XGetPixel(image,x,y) != pixel) : \
1337 (XGetPixel(image,x,y) == pixel))
1339 if (!TO_FLOOD(x
,y
)) return;
1341 /* Find left and right boundaries */
1344 while ((left
> 0) && TO_FLOOD( left
-1, y
)) left
--;
1345 while ((right
< image
->width
) && TO_FLOOD( right
, y
)) right
++;
1346 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
1347 xOrg
+ left
, yOrg
+ y
, right
-left
, 1 );
1349 /* Set the pixels of this line so we don't fill it again */
1351 for (x
= left
; x
< right
; x
++)
1353 if (fillType
== FLOODFILLBORDER
) XPutPixel( image
, x
, y
, pixel
);
1354 else XPutPixel( image
, x
, y
, ~pixel
);
1357 /* Fill the line above */
1364 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1365 if (x
>= right
) break;
1366 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1367 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1368 xOrg
, yOrg
, pixel
, fillType
);
1372 /* Fill the line below */
1374 if ((y
+= 2) < image
->height
)
1379 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1380 if (x
>= right
) break;
1381 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1382 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1383 xOrg
, yOrg
, pixel
, fillType
);
1390 static int ExtFloodFillXGetImageErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
1392 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
1395 /**********************************************************************
1396 * X11DRV_ExtFloodFill
1399 X11DRV_ExtFloodFill( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
,
1406 TRACE("X11DRV_ExtFloodFill %d,%d %06x %d\n", x
, y
, color
, fillType
);
1410 LPtoDP( physDev
->hdc
, &pt
, 1 );
1411 if (!PtInRegion( physDev
->region
, pt
.x
, pt
.y
)) return FALSE
;
1412 GetRgnBox( physDev
->region
, &rect
);
1414 X11DRV_expect_error( gdi_display
, ExtFloodFillXGetImageErrorHandler
, NULL
);
1415 image
= XGetImage( gdi_display
, physDev
->drawable
,
1416 physDev
->dc_rect
.left
+ rect
.left
, physDev
->dc_rect
.top
+ rect
.top
,
1417 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1418 AllPlanes
, ZPixmap
);
1419 if(X11DRV_check_error()) image
= NULL
;
1420 if (!image
) return FALSE
;
1422 if (X11DRV_SetupGCForBrush( physDev
))
1424 unsigned long pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1426 /* Update the pixmap from the DIB section */
1427 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1429 /* ROP mode is always GXcopy for flood-fill */
1431 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1432 X11DRV_InternalFloodFill(image
, physDev
,
1435 physDev
->dc_rect
.left
+ rect
.left
,
1436 physDev
->dc_rect
.top
+ rect
.top
,
1438 wine_tsx11_unlock();
1439 /* Update the DIBSection of the dc's bitmap */
1440 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1444 XDestroyImage( image
);
1445 wine_tsx11_unlock();
1449 /**********************************************************************
1453 X11DRV_SetBkColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1455 physDev
->backgroundPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1459 /**********************************************************************
1460 * X11DRV_SetTextColor
1463 X11DRV_SetTextColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1465 physDev
->textPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1469 /***********************************************************************
1470 * GetDCOrgEx (X11DRV.@)
1472 BOOL CDECL
X11DRV_GetDCOrgEx( X11DRV_PDEVICE
*physDev
, LPPOINT lpp
)
1474 lpp
->x
= physDev
->dc_rect
.left
+ physDev
->drawable_rect
.left
;
1475 lpp
->y
= physDev
->dc_rect
.top
+ physDev
->drawable_rect
.top
;
1480 static unsigned char *get_icm_profile( unsigned long *size
)
1484 unsigned long count
, remaining
;
1485 unsigned char *profile
, *ret
= NULL
;
1488 XGetWindowProperty( gdi_display
, DefaultRootWindow(gdi_display
),
1489 x11drv_atom(_ICC_PROFILE
), 0, ~0UL, False
, AnyPropertyType
,
1490 &type
, &format
, &count
, &remaining
, &profile
);
1491 *size
= get_property_size( format
, count
);
1492 if (format
&& count
)
1494 if ((ret
= HeapAlloc( GetProcessHeap(), 0, *size
))) memcpy( ret
, profile
, *size
);
1497 wine_tsx11_unlock();
1503 unsigned int unknown
[6];
1504 unsigned int state
[5];
1505 unsigned int count
[2];
1506 unsigned char buffer
[64];
1509 extern void WINAPI
A_SHAInit( sha_ctx
* );
1510 extern void WINAPI
A_SHAUpdate( sha_ctx
*, const unsigned char *, unsigned int );
1511 extern void WINAPI
A_SHAFinal( sha_ctx
*, unsigned char * );
1513 /***********************************************************************
1514 * GetICMProfile (X11DRV.@)
1516 BOOL CDECL
X11DRV_GetICMProfile( X11DRV_PDEVICE
*physDev
, LPDWORD size
, LPWSTR filename
)
1518 static const WCHAR path
[] =
1519 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s',
1520 '\\','c','o','l','o','r','\\',0};
1521 static const WCHAR srgb
[] =
1522 {'s','R','G','B',' ','C','o','l','o','r',' ','S','p','a','c','e',' ',
1523 'P','r','o','f','i','l','e','.','i','c','m',0};
1524 static const WCHAR mntr
[] =
1525 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1526 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t',
1527 'V','e','r','s','i','o','n','\\','I','C','M','\\','m','n','t','r',0};
1530 DWORD required
, len
;
1531 WCHAR profile
[MAX_PATH
], fullname
[2*MAX_PATH
+ sizeof(path
)/sizeof(WCHAR
)];
1532 unsigned char *buffer
;
1533 unsigned long buflen
;
1535 if (!size
) return FALSE
;
1537 GetSystemDirectoryW( fullname
, MAX_PATH
);
1538 strcatW( fullname
, path
);
1540 len
= sizeof(profile
)/sizeof(WCHAR
);
1541 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE
, mntr
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
) &&
1542 !RegEnumValueW( hkey
, 0, profile
, &len
, NULL
, NULL
, NULL
, NULL
)) /* FIXME handle multiple values */
1544 strcatW( fullname
, profile
);
1545 RegCloseKey( hkey
);
1547 else if ((buffer
= get_icm_profile( &buflen
)))
1549 static const WCHAR fmt
[] = {'%','0','2','x',0};
1550 static const WCHAR icm
[] = {'.','i','c','m',0};
1552 unsigned char sha1sum
[20];
1558 A_SHAUpdate( &ctx
, buffer
, buflen
);
1559 A_SHAFinal( &ctx
, sha1sum
);
1561 for (i
= 0; i
< sizeof(sha1sum
); i
++) sprintfW( &profile
[i
* 2], fmt
, sha1sum
[i
] );
1562 memcpy( &profile
[i
* 2], icm
, sizeof(icm
) );
1564 strcatW( fullname
, profile
);
1565 file
= CreateFileW( fullname
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, 0 );
1566 if (file
!= INVALID_HANDLE_VALUE
)
1570 if (!WriteFile( file
, buffer
, buflen
, &written
, NULL
) || written
!= buflen
)
1571 ERR( "Unable to write color profile\n" );
1572 CloseHandle( file
);
1574 HeapFree( GetProcessHeap(), 0, buffer
);
1576 else strcatW( fullname
, srgb
);
1578 required
= strlenW( fullname
) + 1;
1579 if (*size
< required
)
1582 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1587 strcpyW( filename
, fullname
);
1588 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1589 WARN( "color profile not found\n" );