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
46 #include "wine/debug.h"
47 #include "wine/unicode.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(graphics
);
51 #define ABS(x) ((x)<0?(-(x)):(x))
53 /* ROP code to GC function conversion */
54 const int X11DRV_XROPfunction
[16] =
56 GXclear
, /* R2_BLACK */
57 GXnor
, /* R2_NOTMERGEPEN */
58 GXandInverted
, /* R2_MASKNOTPEN */
59 GXcopyInverted
, /* R2_NOTCOPYPEN */
60 GXandReverse
, /* R2_MASKPENNOT */
61 GXinvert
, /* R2_NOT */
62 GXxor
, /* R2_XORPEN */
63 GXnand
, /* R2_NOTMASKPEN */
64 GXand
, /* R2_MASKPEN */
65 GXequiv
, /* R2_NOTXORPEN */
67 GXorInverted
, /* R2_MERGENOTPEN */
68 GXcopy
, /* R2_COPYPEN */
69 GXorReverse
, /* R2_MERGEPENNOT */
70 GXor
, /* R2_MERGEPEN */
75 /***********************************************************************
76 * X11DRV_GetRegionData
78 * Calls GetRegionData on the given region and converts the rectangle
79 * array to XRectangle format. The returned buffer must be freed by
80 * caller using HeapFree(GetProcessHeap(),...).
81 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
83 RGNDATA
*X11DRV_GetRegionData( HRGN hrgn
, HDC hdc_lptodp
)
91 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return NULL
;
92 if (sizeof(XRectangle
) > sizeof(RECT
))
94 /* add extra size for XRectangle array */
95 int count
= (size
- sizeof(RGNDATAHEADER
)) / sizeof(RECT
);
96 size
+= count
* (sizeof(XRectangle
) - sizeof(RECT
));
98 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return NULL
;
99 if (!GetRegionData( hrgn
, size
, data
))
101 HeapFree( GetProcessHeap(), 0, data
);
105 rect
= (RECT
*)data
->Buffer
;
106 xrect
= (XRectangle
*)data
->Buffer
;
107 if (hdc_lptodp
) /* map to device coordinates */
109 LPtoDP( hdc_lptodp
, (POINT
*)rect
, data
->rdh
.nCount
* 2 );
110 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
112 if (rect
[i
].right
< rect
[i
].left
)
114 INT tmp
= rect
[i
].right
;
115 rect
[i
].right
= rect
[i
].left
;
118 if (rect
[i
].bottom
< rect
[i
].top
)
120 INT tmp
= rect
[i
].bottom
;
121 rect
[i
].bottom
= rect
[i
].top
;
127 if (sizeof(XRectangle
) > sizeof(RECT
))
130 /* need to start from the end */
131 for (j
= data
->rdh
.nCount
-1; j
>= 0; j
--)
134 xrect
[j
].x
= tmp
.left
;
135 xrect
[j
].y
= tmp
.top
;
136 xrect
[j
].width
= tmp
.right
- tmp
.left
;
137 xrect
[j
].height
= tmp
.bottom
- tmp
.top
;
142 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
145 xrect
[i
].x
= tmp
.left
;
146 xrect
[i
].y
= tmp
.top
;
147 xrect
[i
].width
= tmp
.right
- tmp
.left
;
148 xrect
[i
].height
= tmp
.bottom
- tmp
.top
;
155 /***********************************************************************
156 * X11DRV_SetDeviceClipping
158 void CDECL
X11DRV_SetDeviceClipping( X11DRV_PDEVICE
*physDev
, HRGN vis_rgn
, HRGN clip_rgn
)
162 CombineRgn( physDev
->region
, vis_rgn
, clip_rgn
, clip_rgn
? RGN_AND
: RGN_COPY
);
163 if (!(data
= X11DRV_GetRegionData( physDev
->region
, 0 ))) return;
166 XSetClipRectangles( gdi_display
, physDev
->gc
, physDev
->dc_rect
.left
, physDev
->dc_rect
.top
,
167 (XRectangle
*)data
->Buffer
, data
->rdh
.nCount
, YXBanded
);
169 HeapFree( GetProcessHeap(), 0, data
);
173 /***********************************************************************
174 * X11DRV_SetupGCForPatBlt
176 * Setup the GC for a PatBlt operation using current brush.
177 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
178 * Return FALSE if brush is BS_NULL, TRUE otherwise.
180 BOOL
X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE
*physDev
, GC gc
, BOOL fMapColors
)
187 if (physDev
->brush
.style
== BS_NULL
) return FALSE
;
188 if (physDev
->brush
.pixel
== -1)
190 /* Special case used for monochrome pattern brushes.
191 * We need to swap foreground and background because
192 * Windows does it the wrong way...
194 val
.foreground
= physDev
->backgroundPixel
;
195 val
.background
= physDev
->textPixel
;
199 val
.foreground
= physDev
->brush
.pixel
;
200 val
.background
= physDev
->backgroundPixel
;
202 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
204 val
.foreground
= X11DRV_PALETTE_XPixelToPalette
[val
.foreground
];
205 val
.background
= X11DRV_PALETTE_XPixelToPalette
[val
.background
];
208 val
.function
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
)-1];
210 ** Let's replace GXinvert by GXxor with (black xor white)
211 ** This solves the selection color and leak problems in excel
212 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
214 if (val
.function
== GXinvert
)
216 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
217 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
218 val
.function
= GXxor
;
220 val
.fill_style
= physDev
->brush
.fillStyle
;
221 switch(val
.fill_style
)
224 case FillOpaqueStippled
:
225 if (GetBkMode(physDev
->hdc
)==OPAQUE
) val
.fill_style
= FillOpaqueStippled
;
226 val
.stipple
= physDev
->brush
.pixmap
;
231 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
236 pixmap
= XCreatePixmap( gdi_display
, root_window
, 8, 8, screen_depth
);
237 image
= XGetImage( gdi_display
, physDev
->brush
.pixmap
, 0, 0, 8, 8,
238 AllPlanes
, ZPixmap
);
239 for (y
= 0; y
< 8; y
++)
240 for (x
= 0; x
< 8; x
++)
241 XPutPixel( image
, x
, y
,
242 X11DRV_PALETTE_XPixelToPalette
[XGetPixel( image
, x
, y
)] );
243 XPutImage( gdi_display
, pixmap
, gc
, image
, 0, 0, 0, 0, 8, 8 );
244 XDestroyImage( image
);
248 else val
.tile
= physDev
->brush
.pixmap
;
256 GetBrushOrgEx( physDev
->hdc
, &pt
);
257 val
.ts_x_origin
= physDev
->dc_rect
.left
+ pt
.x
;
258 val
.ts_y_origin
= physDev
->dc_rect
.top
+ pt
.y
;
259 val
.fill_rule
= (GetPolyFillMode(physDev
->hdc
) == WINDING
) ? WindingRule
: EvenOddRule
;
261 XChangeGC( gdi_display
, gc
,
262 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
263 GCFillRule
| GCTileStipXOrigin
| GCTileStipYOrigin
| mask
,
265 if (pixmap
) XFreePixmap( gdi_display
, pixmap
);
271 /***********************************************************************
272 * X11DRV_SetupGCForBrush
274 * Setup physDev->gc for drawing operations using current brush.
275 * Return FALSE if brush is BS_NULL, TRUE otherwise.
277 BOOL
X11DRV_SetupGCForBrush( X11DRV_PDEVICE
*physDev
)
279 return X11DRV_SetupGCForPatBlt( physDev
, physDev
->gc
, FALSE
);
283 /***********************************************************************
284 * X11DRV_SetupGCForPen
286 * Setup physDev->gc for drawing operations using current pen.
287 * Return FALSE if pen is PS_NULL, TRUE otherwise.
289 static BOOL
X11DRV_SetupGCForPen( X11DRV_PDEVICE
*physDev
)
292 UINT rop2
= GetROP2(physDev
->hdc
);
294 if (physDev
->pen
.style
== PS_NULL
) return FALSE
;
299 val
.foreground
= BlackPixel( gdi_display
, DefaultScreen(gdi_display
) );
300 val
.function
= GXcopy
;
303 val
.foreground
= WhitePixel( gdi_display
, DefaultScreen(gdi_display
) );
304 val
.function
= GXcopy
;
307 val
.foreground
= physDev
->pen
.pixel
;
308 /* It is very unlikely someone wants to XOR with 0 */
309 /* This fixes the rubber-drawings in paintbrush */
310 if (val
.foreground
== 0)
311 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
312 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
313 val
.function
= GXxor
;
316 val
.foreground
= physDev
->pen
.pixel
;
317 val
.function
= X11DRV_XROPfunction
[rop2
-1];
319 val
.background
= physDev
->backgroundPixel
;
320 val
.fill_style
= FillSolid
;
321 val
.line_width
= physDev
->pen
.width
;
322 if (val
.line_width
<= 1) {
323 val
.cap_style
= CapNotLast
;
325 switch (physDev
->pen
.endcap
)
327 case PS_ENDCAP_SQUARE
:
328 val
.cap_style
= CapProjecting
;
331 val
.cap_style
= CapButt
;
333 case PS_ENDCAP_ROUND
:
335 val
.cap_style
= CapRound
;
338 switch (physDev
->pen
.linejoin
)
341 val
.join_style
= JoinBevel
;
344 val
.join_style
= JoinMiter
;
348 val
.join_style
= JoinRound
;
351 if (physDev
->pen
.dash_len
)
352 val
.line_style
= ((GetBkMode(physDev
->hdc
) == OPAQUE
) && (!physDev
->pen
.ext
))
353 ? LineDoubleDash
: LineOnOffDash
;
355 val
.line_style
= LineSolid
;
358 if (physDev
->pen
.dash_len
)
359 XSetDashes( gdi_display
, physDev
->gc
, 0, physDev
->pen
.dashes
, physDev
->pen
.dash_len
);
360 XChangeGC( gdi_display
, physDev
->gc
,
361 GCFunction
| GCForeground
| GCBackground
| GCLineWidth
|
362 GCLineStyle
| GCCapStyle
| GCJoinStyle
| GCFillStyle
, &val
);
368 /***********************************************************************
369 * X11DRV_SetupGCForText
371 * Setup physDev->gc for text drawing operations.
372 * Return FALSE if the font is null, TRUE otherwise.
374 BOOL
X11DRV_SetupGCForText( X11DRV_PDEVICE
*physDev
)
376 XFontStruct
* xfs
= XFONT_GetFontStruct( physDev
->font
);
382 val
.function
= GXcopy
; /* Text is always GXcopy */
383 val
.foreground
= physDev
->textPixel
;
384 val
.background
= physDev
->backgroundPixel
;
385 val
.fill_style
= FillSolid
;
389 XChangeGC( gdi_display
, physDev
->gc
,
390 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
395 WARN("Physical font failure\n" );
399 /***********************************************************************
402 * Performs a world-to-viewport transformation on the specified width.
404 INT
X11DRV_XWStoDS( X11DRV_PDEVICE
*physDev
, INT width
)
412 LPtoDP( physDev
->hdc
, pt
, 2 );
413 return pt
[1].x
- pt
[0].x
;
416 /***********************************************************************
419 * Performs a world-to-viewport transformation on the specified height.
421 INT
X11DRV_YWStoDS( X11DRV_PDEVICE
*physDev
, INT height
)
429 LPtoDP( physDev
->hdc
, pt
, 2 );
430 return pt
[1].y
- pt
[0].y
;
433 /***********************************************************************
437 X11DRV_LineTo( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
441 if (X11DRV_SetupGCForPen( physDev
)) {
442 /* Update the pixmap from the DIB section */
443 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
445 GetCurrentPositionEx( physDev
->hdc
, &pt
[0] );
448 LPtoDP( physDev
->hdc
, pt
, 2 );
451 XDrawLine(gdi_display
, physDev
->drawable
, physDev
->gc
,
452 physDev
->dc_rect
.left
+ pt
[0].x
, physDev
->dc_rect
.top
+ pt
[0].y
,
453 physDev
->dc_rect
.left
+ pt
[1].x
, physDev
->dc_rect
.top
+ pt
[1].y
);
456 /* Update the DIBSection from the pixmap */
457 X11DRV_UnlockDIBSection(physDev
, TRUE
);
464 /***********************************************************************
467 * Helper functions for Arc(), Chord() and Pie().
468 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
472 X11DRV_DrawArc( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
,
473 INT bottom
, INT xstart
, INT ystart
,
474 INT xend
, INT yend
, INT lines
)
476 INT xcenter
, ycenter
, istart_angle
, idiff_angle
;
478 double start_angle
, end_angle
;
484 SetRect(&rc
, left
, top
, right
, bottom
);
489 LPtoDP(physDev
->hdc
, (POINT
*)&rc
, 2);
490 LPtoDP(physDev
->hdc
, &start
, 1);
491 LPtoDP(physDev
->hdc
, &end
, 1);
493 if (rc
.right
< rc
.left
) { INT tmp
= rc
.right
; rc
.right
= rc
.left
; rc
.left
= tmp
; }
494 if (rc
.bottom
< rc
.top
) { INT tmp
= rc
.bottom
; rc
.bottom
= rc
.top
; rc
.top
= tmp
; }
495 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)
496 ||(lines
&& ((rc
.right
-rc
.left
==1)||(rc
.bottom
-rc
.top
==1)))) return TRUE
;
498 if (GetArcDirection( physDev
->hdc
) == AD_CLOCKWISE
)
499 { POINT tmp
= start
; start
= end
; end
= tmp
; }
501 oldwidth
= width
= physDev
->pen
.width
;
502 if (!width
) width
= 1;
503 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
505 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
507 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
508 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
509 rc
.left
+= width
/ 2;
510 rc
.right
-= (width
- 1) / 2;
512 rc
.bottom
-= (width
- 1) / 2;
514 if(width
== 0) width
= 1; /* more accurate */
515 physDev
->pen
.width
= width
;
517 xcenter
= (rc
.right
+ rc
.left
) / 2;
518 ycenter
= (rc
.bottom
+ rc
.top
) / 2;
519 start_angle
= atan2( (double)(ycenter
-start
.y
)*(rc
.right
-rc
.left
),
520 (double)(start
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
521 end_angle
= atan2( (double)(ycenter
-end
.y
)*(rc
.right
-rc
.left
),
522 (double)(end
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
523 if ((start
.x
==end
.x
)&&(start
.y
==end
.y
))
524 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
528 else /* notorious cases */
529 if ((start_angle
== PI
)&&( end_angle
<0))
532 if ((end_angle
== PI
)&&( start_angle
<0))
534 istart_angle
= (INT
)(start_angle
* 180 * 64 / PI
+ 0.5);
535 idiff_angle
= (INT
)((end_angle
- start_angle
) * 180 * 64 / PI
+ 0.5);
536 if (idiff_angle
<= 0) idiff_angle
+= 360 * 64;
538 /* Update the pixmap from the DIB section */
539 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
541 /* Fill arc with brush if Chord() or Pie() */
543 if ((lines
> 0) && X11DRV_SetupGCForBrush( physDev
)) {
545 XSetArcMode( gdi_display
, physDev
->gc
, (lines
==1) ? ArcChord
: ArcPieSlice
);
546 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
547 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
548 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
553 /* Draw arc and lines */
555 if (X11DRV_SetupGCForPen( physDev
))
558 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
559 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
560 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
562 /* use the truncated values */
563 start_angle
=(double)istart_angle
*PI
/64./180.;
564 end_angle
=(double)(istart_angle
+idiff_angle
)*PI
/64./180.;
565 /* calculate the endpoints and round correctly */
566 points
[0].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
567 cos(start_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
568 points
[0].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
569 sin(start_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
570 points
[1].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
571 cos(end_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
572 points
[1].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
573 sin(end_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
575 /* OK, this stuff is optimized for Xfree86
576 * which is probably the server most used by
577 * wine users. Other X servers will not
578 * display correctly. (eXceed for instance)
579 * so if you feel you must make changes, make sure that
580 * you either use Xfree86 or separate your changes
581 * from these (compile switch or whatever)
585 points
[3] = points
[1];
586 points
[1].x
= physDev
->dc_rect
.left
+ xcenter
;
587 points
[1].y
= physDev
->dc_rect
.top
+ ycenter
;
588 points
[2] = points
[1];
589 dx1
=points
[1].x
-points
[0].x
;
590 dy1
=points
[1].y
-points
[0].y
;
591 if(((rc
.top
-rc
.bottom
) | -2) == -2)
592 if(dy1
>0) points
[1].y
--;
594 if (((-dx1
)*64)<=ABS(dy1
)*37) points
[0].x
--;
595 if(((-dx1
*9))<(dy1
*16)) points
[0].y
--;
596 if( dy1
<0 && ((dx1
*9)) < (dy1
*16)) points
[0].y
--;
598 if(dy1
< 0) points
[0].y
--;
599 if(((rc
.right
-rc
.left
) | -2) == -2) points
[1].x
--;
601 dx1
=points
[3].x
-points
[2].x
;
602 dy1
=points
[3].y
-points
[2].y
;
603 if(((rc
.top
-rc
.bottom
) | -2 ) == -2)
604 if(dy1
< 0) points
[2].y
--;
606 if( dy1
>0) points
[3].y
--;
607 if(((rc
.right
-rc
.left
) | -2) == -2 ) points
[2].x
--;
610 if( dx1
* 64 < dy1
* -37 ) points
[3].x
--;
614 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
615 points
, lines
+1, CoordModeOrigin
);
621 /* Update the DIBSection of the pixmap */
622 X11DRV_UnlockDIBSection(physDev
, update
);
624 physDev
->pen
.width
= oldwidth
;
629 /***********************************************************************
633 X11DRV_Arc( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
634 INT xstart
, INT ystart
, INT xend
, INT yend
)
636 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
637 xstart
, ystart
, xend
, yend
, 0 );
641 /***********************************************************************
645 X11DRV_Pie( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
646 INT xstart
, INT ystart
, INT xend
, INT yend
)
648 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
649 xstart
, ystart
, xend
, yend
, 2 );
652 /***********************************************************************
656 X11DRV_Chord( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
657 INT xstart
, INT ystart
, INT xend
, INT yend
)
659 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
660 xstart
, ystart
, xend
, yend
, 1 );
664 /***********************************************************************
668 X11DRV_Ellipse( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
674 SetRect(&rc
, left
, top
, right
, bottom
);
675 LPtoDP(physDev
->hdc
, (POINT
*)&rc
, 2);
677 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
679 if (rc
.right
< rc
.left
) { INT tmp
= rc
.right
; rc
.right
= rc
.left
; rc
.left
= tmp
; }
680 if (rc
.bottom
< rc
.top
) { INT tmp
= rc
.bottom
; rc
.bottom
= rc
.top
; rc
.top
= tmp
; }
682 oldwidth
= width
= physDev
->pen
.width
;
683 if (!width
) width
= 1;
684 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
686 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
688 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
689 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
690 rc
.left
+= width
/ 2;
691 rc
.right
-= (width
- 1) / 2;
693 rc
.bottom
-= (width
- 1) / 2;
695 if(width
== 0) width
= 1; /* more accurate */
696 physDev
->pen
.width
= width
;
698 /* Update the pixmap from the DIB section */
699 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
701 if (X11DRV_SetupGCForBrush( physDev
))
704 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
705 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
706 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
710 if (X11DRV_SetupGCForPen( physDev
))
713 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
714 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
715 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
720 /* Update the DIBSection from the pixmap */
721 X11DRV_UnlockDIBSection(physDev
, update
);
723 physDev
->pen
.width
= oldwidth
;
728 /***********************************************************************
732 X11DRV_Rectangle(X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
734 INT width
, oldwidth
, oldjoinstyle
;
738 TRACE("(%d %d %d %d)\n", left
, top
, right
, bottom
);
740 SetRect(&rc
, left
, top
, right
, bottom
);
741 LPtoDP(physDev
->hdc
, (POINT
*)&rc
, 2);
743 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
745 if (rc
.right
< rc
.left
) { INT tmp
= rc
.right
; rc
.right
= rc
.left
; rc
.left
= tmp
; }
746 if (rc
.bottom
< rc
.top
) { INT tmp
= rc
.bottom
; rc
.bottom
= rc
.top
; rc
.top
= tmp
; }
748 oldwidth
= width
= physDev
->pen
.width
;
749 if (!width
) width
= 1;
750 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
752 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
754 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
755 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
756 rc
.left
+= width
/ 2;
757 rc
.right
-= (width
- 1) / 2;
759 rc
.bottom
-= (width
- 1) / 2;
761 if(width
== 1) width
= 0;
762 physDev
->pen
.width
= width
;
763 oldjoinstyle
= physDev
->pen
.linejoin
;
764 if(physDev
->pen
.type
!= PS_GEOMETRIC
)
765 physDev
->pen
.linejoin
= PS_JOIN_MITER
;
767 /* Update the pixmap from the DIB section */
768 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
770 if ((rc
.right
> rc
.left
+ width
) && (rc
.bottom
> rc
.top
+ width
))
772 if (X11DRV_SetupGCForBrush( physDev
))
775 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
776 physDev
->dc_rect
.left
+ rc
.left
+ (width
+ 1) / 2,
777 physDev
->dc_rect
.top
+ rc
.top
+ (width
+ 1) / 2,
778 rc
.right
-rc
.left
-width
-1, rc
.bottom
-rc
.top
-width
-1);
783 if (X11DRV_SetupGCForPen( physDev
))
786 XDrawRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
787 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
788 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1 );
793 /* Update the DIBSection from the pixmap */
794 X11DRV_UnlockDIBSection(physDev
, update
);
796 physDev
->pen
.width
= oldwidth
;
797 physDev
->pen
.linejoin
= oldjoinstyle
;
801 /***********************************************************************
805 X11DRV_RoundRect( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
,
806 INT bottom
, INT ell_width
, INT ell_height
)
808 INT width
, oldwidth
, oldendcap
;
813 TRACE("(%d %d %d %d %d %d\n",
814 left
, top
, right
, bottom
, ell_width
, ell_height
);
816 SetRect(&rc
, left
, top
, right
, bottom
);
817 LPtoDP(physDev
->hdc
, (POINT
*)&rc
, 2);
819 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
))
822 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
823 called with width/height < 0 */
824 pts
[0].x
= pts
[0].y
= 0;
825 pts
[1].x
= ell_width
;
826 pts
[1].y
= ell_height
;
827 LPtoDP(physDev
->hdc
, pts
, 2);
828 ell_width
= max(abs( pts
[1].x
- pts
[0].x
), 1);
829 ell_height
= max(abs( pts
[1].y
- pts
[0].y
), 1);
831 /* Fix the coordinates */
833 if (rc
.right
< rc
.left
) { INT tmp
= rc
.right
; rc
.right
= rc
.left
; rc
.left
= tmp
; }
834 if (rc
.bottom
< rc
.top
) { INT tmp
= rc
.bottom
; rc
.bottom
= rc
.top
; rc
.top
= tmp
; }
836 oldwidth
= width
= physDev
->pen
.width
;
837 oldendcap
= physDev
->pen
.endcap
;
838 if (!width
) width
= 1;
839 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
841 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
843 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
844 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
845 rc
.left
+= width
/ 2;
846 rc
.right
-= (width
- 1) / 2;
848 rc
.bottom
-= (width
- 1) / 2;
850 if(width
== 0) width
= 1;
851 physDev
->pen
.width
= width
;
852 physDev
->pen
.endcap
= PS_ENDCAP_SQUARE
;
854 /* Update the pixmap from the DIB section */
855 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
857 if (X11DRV_SetupGCForBrush( physDev
))
860 if (ell_width
> (rc
.right
-rc
.left
) )
861 if (ell_height
> (rc
.bottom
-rc
.top
) )
862 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
863 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
864 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1,
867 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
868 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
869 rc
.right
- rc
.left
- 1, ell_height
, 0, 180 * 64 );
870 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
871 physDev
->dc_rect
.left
+ rc
.left
,
872 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
873 rc
.right
- rc
.left
- 1, ell_height
, 180 * 64,
876 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
877 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
878 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
879 ell_width
, rc
.bottom
- rc
.top
- 1, 90 * 64, 180 * 64 );
880 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
881 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1, physDev
->dc_rect
.top
+ rc
.top
,
882 ell_width
, rc
.bottom
- rc
.top
- 1, 270 * 64, 180 * 64 );
884 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
885 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
886 ell_width
, ell_height
, 90 * 64, 90 * 64 );
887 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
888 physDev
->dc_rect
.left
+ rc
.left
,
889 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
890 ell_width
, ell_height
, 180 * 64, 90 * 64 );
891 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
892 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
893 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
894 ell_width
, ell_height
, 270 * 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
.top
,
898 ell_width
, ell_height
, 0, 90 * 64 );
900 if (ell_width
< rc
.right
- rc
.left
)
902 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
903 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
904 physDev
->dc_rect
.top
+ rc
.top
+ 1,
905 rc
.right
- rc
.left
- ell_width
- 1,
906 (ell_height
+ 1) / 2 - 1);
907 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
908 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
909 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
) / 2 - 1,
910 rc
.right
- rc
.left
- ell_width
- 1,
913 if (ell_height
< rc
.bottom
- rc
.top
)
915 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
916 physDev
->dc_rect
.left
+ rc
.left
+ 1,
917 physDev
->dc_rect
.top
+ rc
.top
+ (ell_height
+ 1) / 2,
918 rc
.right
- rc
.left
- 2,
919 rc
.bottom
- rc
.top
- ell_height
- 1);
924 /* FIXME: this could be done with on X call
925 * more efficient and probably more correct
926 * on any X server: XDrawArcs will draw
927 * straight horizontal and vertical lines
928 * if width or height are zero.
930 * BTW this stuff is optimized for an Xfree86 server
931 * read the comments inside the X11DRV_DrawArc function
933 if (X11DRV_SetupGCForPen( physDev
))
936 if (ell_width
> (rc
.right
-rc
.left
) )
937 if (ell_height
> (rc
.bottom
-rc
.top
) )
938 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
939 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
940 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1, 0 , 360 * 64 );
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, ell_height
- 1, 0 , 180 * 64 );
945 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
946 physDev
->dc_rect
.left
+ rc
.left
,
947 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
948 rc
.right
- rc
.left
- 1, ell_height
- 1, 180 * 64 , 180 * 64 );
950 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
951 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
952 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
953 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 90 * 64 , 180 * 64 );
954 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
955 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
956 physDev
->dc_rect
.top
+ rc
.top
,
957 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 270 * 64 , 180 * 64 );
959 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
960 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
961 ell_width
- 1, ell_height
- 1, 90 * 64, 90 * 64 );
962 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
963 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
964 ell_width
- 1, ell_height
- 1, 180 * 64, 90 * 64 );
965 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
966 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
967 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
968 ell_width
- 1, ell_height
- 1, 270 * 64, 90 * 64 );
969 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
970 physDev
->dc_rect
.left
+ rc
.right
- ell_width
, physDev
->dc_rect
.top
+ rc
.top
,
971 ell_width
- 1, ell_height
- 1, 0, 90 * 64 );
973 if (ell_width
< rc
.right
- rc
.left
)
975 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
976 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2,
977 physDev
->dc_rect
.top
+ rc
.top
,
978 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1) / 2,
979 physDev
->dc_rect
.top
+ rc
.top
);
980 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
981 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2 ,
982 physDev
->dc_rect
.top
+ rc
.bottom
- 1,
983 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1)/ 2,
984 physDev
->dc_rect
.top
+ rc
.bottom
- 1);
986 if (ell_height
< rc
.bottom
- rc
.top
)
988 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
989 physDev
->dc_rect
.left
+ rc
.right
- 1,
990 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
991 physDev
->dc_rect
.left
+ rc
.right
- 1,
992 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
993 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
994 physDev
->dc_rect
.left
+ rc
.left
,
995 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
996 physDev
->dc_rect
.left
+ rc
.left
,
997 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
1002 /* Update the DIBSection from the pixmap */
1003 X11DRV_UnlockDIBSection(physDev
, update
);
1005 physDev
->pen
.width
= oldwidth
;
1006 physDev
->pen
.endcap
= oldendcap
;
1011 /***********************************************************************
1015 X11DRV_SetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
)
1017 unsigned long pixel
;
1022 LPtoDP( physDev
->hdc
, &pt
, 1 );
1023 pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1025 /* Update the pixmap from the DIB section */
1026 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1028 /* inefficient but simple... */
1030 XSetForeground( gdi_display
, physDev
->gc
, pixel
);
1031 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1032 XDrawPoint( gdi_display
, physDev
->drawable
, physDev
->gc
,
1033 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
);
1034 wine_tsx11_unlock();
1036 /* Update the DIBSection from the pixmap */
1037 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1039 return X11DRV_PALETTE_ToLogical(pixel
);
1043 /***********************************************************************
1047 X11DRV_GetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
1049 static Pixmap pixmap
= 0;
1053 BOOL memdc
= (GetObjectType(physDev
->hdc
) == OBJ_MEMDC
);
1057 LPtoDP( physDev
->hdc
, &pt
, 1 );
1059 /* Update the pixmap from the DIB section */
1060 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1065 image
= XGetImage( gdi_display
, physDev
->drawable
,
1066 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
,
1067 1, 1, AllPlanes
, ZPixmap
);
1071 /* If we are reading from the screen, use a temporary copy */
1072 /* to avoid a BadMatch error */
1073 if (!pixmap
) pixmap
= XCreatePixmap( gdi_display
, root_window
,
1074 1, 1, physDev
->depth
);
1075 XCopyArea( gdi_display
, physDev
->drawable
, pixmap
, BITMAP_colorGC
,
1076 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
, 1, 1, 0, 0 );
1077 image
= XGetImage( gdi_display
, pixmap
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
1079 pixel
= XGetPixel( image
, 0, 0 );
1080 XDestroyImage( image
);
1081 wine_tsx11_unlock();
1083 /* Update the DIBSection from the pixmap */
1084 X11DRV_UnlockDIBSection(physDev
, FALSE
);
1086 return X11DRV_PALETTE_ToLogical(pixel
);
1090 /***********************************************************************
1094 X11DRV_PaintRgn( X11DRV_PDEVICE
*physDev
, HRGN hrgn
)
1096 if (X11DRV_SetupGCForBrush( physDev
))
1100 RGNDATA
*data
= X11DRV_GetRegionData( hrgn
, physDev
->hdc
);
1102 if (!data
) return FALSE
;
1103 rect
= (XRectangle
*)data
->Buffer
;
1104 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
1106 rect
[i
].x
+= physDev
->dc_rect
.left
;
1107 rect
[i
].y
+= physDev
->dc_rect
.top
;
1110 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1112 XFillRectangles( gdi_display
, physDev
->drawable
, physDev
->gc
, rect
, data
->rdh
.nCount
);
1113 wine_tsx11_unlock();
1114 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1115 HeapFree( GetProcessHeap(), 0, data
);
1120 /**********************************************************************
1124 X11DRV_Polyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1129 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * count
)))
1131 WARN("No memory to convert POINTs to XPoints!\n");
1134 for (i
= 0; i
< count
; i
++)
1137 LPtoDP(physDev
->hdc
, &tmp
, 1);
1138 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1139 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1142 if (X11DRV_SetupGCForPen ( physDev
))
1144 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1146 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1147 points
, count
, CoordModeOrigin
);
1148 wine_tsx11_unlock();
1149 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1152 HeapFree( GetProcessHeap(), 0, points
);
1157 /**********************************************************************
1161 X11DRV_Polygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1165 BOOL update
= FALSE
;
1167 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (count
+1) )))
1169 WARN("No memory to convert POINTs to XPoints!\n");
1172 for (i
= 0; i
< count
; i
++)
1175 LPtoDP(physDev
->hdc
, &tmp
, 1);
1176 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1177 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1179 points
[count
] = points
[0];
1181 /* Update the pixmap from the DIB section */
1182 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1184 if (X11DRV_SetupGCForBrush( physDev
))
1187 XFillPolygon( gdi_display
, physDev
->drawable
, physDev
->gc
,
1188 points
, count
+1, Complex
, CoordModeOrigin
);
1189 wine_tsx11_unlock();
1192 if (X11DRV_SetupGCForPen ( physDev
))
1195 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1196 points
, count
+1, CoordModeOrigin
);
1197 wine_tsx11_unlock();
1201 /* Update the DIBSection from the pixmap */
1202 X11DRV_UnlockDIBSection(physDev
, update
);
1204 HeapFree( GetProcessHeap(), 0, points
);
1209 /**********************************************************************
1210 * X11DRV_PolyPolygon
1213 X11DRV_PolyPolygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
1217 /* FIXME: The points should be converted to device coords before */
1218 /* creating the region. */
1220 hrgn
= CreatePolyPolygonRgn( pt
, counts
, polygons
, GetPolyFillMode( physDev
->hdc
) );
1221 X11DRV_PaintRgn( physDev
, hrgn
);
1222 DeleteObject( hrgn
);
1224 /* Draw the outline of the polygons */
1226 if (X11DRV_SetupGCForPen ( physDev
))
1232 /* Update the pixmap from the DIB section */
1233 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1235 for (i
= 0; i
< polygons
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1236 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (max
+1) )))
1238 WARN("No memory to convert POINTs to XPoints!\n");
1241 for (i
= 0; i
< polygons
; i
++)
1243 for (j
= 0; j
< counts
[i
]; j
++)
1246 LPtoDP(physDev
->hdc
, &tmp
, 1);
1247 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1248 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1251 points
[j
] = points
[0];
1253 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1254 points
, j
+ 1, CoordModeOrigin
);
1255 wine_tsx11_unlock();
1258 /* Update the DIBSection of the dc's bitmap */
1259 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1261 HeapFree( GetProcessHeap(), 0, points
);
1267 /**********************************************************************
1268 * X11DRV_PolyPolyline
1271 X11DRV_PolyPolyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const DWORD
* counts
, DWORD polylines
)
1273 if (X11DRV_SetupGCForPen ( physDev
))
1275 unsigned int i
, j
, max
= 0;
1278 /* Update the pixmap from the DIB section */
1279 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1281 for (i
= 0; i
< polylines
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1282 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * max
)))
1284 WARN("No memory to convert POINTs to XPoints!\n");
1287 for (i
= 0; i
< polylines
; i
++)
1289 for (j
= 0; j
< counts
[i
]; j
++)
1292 LPtoDP(physDev
->hdc
, &tmp
, 1);
1293 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1294 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1298 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1299 points
, j
, CoordModeOrigin
);
1300 wine_tsx11_unlock();
1303 /* Update the DIBSection of the dc's bitmap */
1304 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1306 HeapFree( GetProcessHeap(), 0, points
);
1312 /**********************************************************************
1313 * X11DRV_InternalFloodFill
1315 * Internal helper function for flood fill.
1316 * (xorg,yorg) is the origin of the X image relative to the drawable.
1317 * (x,y) is relative to the origin of the X image.
1319 static void X11DRV_InternalFloodFill(XImage
*image
, X11DRV_PDEVICE
*physDev
,
1322 unsigned long pixel
, WORD fillType
)
1326 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1327 (XGetPixel(image,x,y) != pixel) : \
1328 (XGetPixel(image,x,y) == pixel))
1330 if (!TO_FLOOD(x
,y
)) return;
1332 /* Find left and right boundaries */
1335 while ((left
> 0) && TO_FLOOD( left
-1, y
)) left
--;
1336 while ((right
< image
->width
) && TO_FLOOD( right
, y
)) right
++;
1337 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
1338 xOrg
+ left
, yOrg
+ y
, right
-left
, 1 );
1340 /* Set the pixels of this line so we don't fill it again */
1342 for (x
= left
; x
< right
; x
++)
1344 if (fillType
== FLOODFILLBORDER
) XPutPixel( image
, x
, y
, pixel
);
1345 else XPutPixel( image
, x
, y
, ~pixel
);
1348 /* Fill the line above */
1355 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1356 if (x
>= right
) break;
1357 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1358 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1359 xOrg
, yOrg
, pixel
, fillType
);
1363 /* Fill the line below */
1365 if ((y
+= 2) < image
->height
)
1370 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1371 if (x
>= right
) break;
1372 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1373 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1374 xOrg
, yOrg
, pixel
, fillType
);
1381 static int ExtFloodFillXGetImageErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
1383 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
1386 /**********************************************************************
1387 * X11DRV_ExtFloodFill
1390 X11DRV_ExtFloodFill( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
,
1397 TRACE("X11DRV_ExtFloodFill %d,%d %06x %d\n", x
, y
, color
, fillType
);
1401 LPtoDP( physDev
->hdc
, &pt
, 1 );
1402 if (!PtInRegion( physDev
->region
, pt
.x
, pt
.y
)) return FALSE
;
1403 GetRgnBox( physDev
->region
, &rect
);
1405 X11DRV_expect_error( gdi_display
, ExtFloodFillXGetImageErrorHandler
, NULL
);
1406 image
= XGetImage( gdi_display
, physDev
->drawable
,
1407 physDev
->dc_rect
.left
+ rect
.left
, physDev
->dc_rect
.top
+ rect
.top
,
1408 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1409 AllPlanes
, ZPixmap
);
1410 if(X11DRV_check_error()) image
= NULL
;
1411 if (!image
) return FALSE
;
1413 if (X11DRV_SetupGCForBrush( physDev
))
1415 unsigned long pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1417 /* Update the pixmap from the DIB section */
1418 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1420 /* ROP mode is always GXcopy for flood-fill */
1422 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1423 X11DRV_InternalFloodFill(image
, physDev
,
1426 physDev
->dc_rect
.left
+ rect
.left
,
1427 physDev
->dc_rect
.top
+ rect
.top
,
1429 wine_tsx11_unlock();
1430 /* Update the DIBSection of the dc's bitmap */
1431 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1435 XDestroyImage( image
);
1436 wine_tsx11_unlock();
1440 /**********************************************************************
1444 X11DRV_SetBkColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1446 physDev
->backgroundPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1450 /**********************************************************************
1451 * X11DRV_SetTextColor
1454 X11DRV_SetTextColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1456 physDev
->textPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1460 /***********************************************************************
1461 * GetDCOrgEx (X11DRV.@)
1463 BOOL CDECL
X11DRV_GetDCOrgEx( X11DRV_PDEVICE
*physDev
, LPPOINT lpp
)
1465 lpp
->x
= physDev
->dc_rect
.left
+ physDev
->drawable_rect
.left
;
1466 lpp
->y
= physDev
->dc_rect
.top
+ physDev
->drawable_rect
.top
;
1471 /***********************************************************************
1472 * SetDCOrg (X11DRV.@)
1474 DWORD CDECL
X11DRV_SetDCOrg( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
1476 DWORD ret
= MAKELONG( physDev
->dc_rect
.left
+ physDev
->drawable_rect
.left
,
1477 physDev
->dc_rect
.top
+ physDev
->drawable_rect
.top
);
1478 physDev
->dc_rect
.left
= x
- physDev
->drawable_rect
.left
;
1479 physDev
->dc_rect
.top
= y
- physDev
->drawable_rect
.top
;
1483 static unsigned char *get_icm_profile( unsigned long *size
)
1487 unsigned long count
, remaining
;
1488 unsigned char *profile
, *ret
= NULL
;
1491 XGetWindowProperty( gdi_display
, DefaultRootWindow(gdi_display
),
1492 x11drv_atom(_ICC_PROFILE
), 0, ~0UL, False
, AnyPropertyType
,
1493 &type
, &format
, &count
, &remaining
, &profile
);
1494 *size
= get_property_size( format
, count
);
1495 if (format
&& count
)
1497 if ((ret
= HeapAlloc( GetProcessHeap(), 0, *size
))) memcpy( ret
, profile
, *size
);
1500 wine_tsx11_unlock();
1506 unsigned int unknown
[6];
1507 unsigned int state
[5];
1508 unsigned int count
[2];
1509 unsigned char buffer
[64];
1512 extern void WINAPI
A_SHAInit( sha_ctx
* );
1513 extern void WINAPI
A_SHAUpdate( sha_ctx
*, const unsigned char *, unsigned int );
1514 extern void WINAPI
A_SHAFinal( sha_ctx
*, unsigned char * );
1516 /***********************************************************************
1517 * GetICMProfile (X11DRV.@)
1519 BOOL CDECL
X11DRV_GetICMProfile( X11DRV_PDEVICE
*physDev
, LPDWORD size
, LPWSTR filename
)
1521 static const WCHAR path
[] =
1522 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s',
1523 '\\','c','o','l','o','r','\\',0};
1524 static const WCHAR srgb
[] =
1525 {'s','R','G','B',' ','C','o','l','o','r',' ','S','p','a','c','e',' ',
1526 'P','r','o','f','i','l','e','.','i','c','m',0};
1527 static const WCHAR mntr
[] =
1528 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1529 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t',
1530 'V','e','r','s','i','o','n','\\','I','C','M','\\','m','n','t','r',0};
1533 DWORD required
, len
;
1534 WCHAR profile
[MAX_PATH
], fullname
[2*MAX_PATH
+ sizeof(path
)/sizeof(WCHAR
)];
1535 unsigned char *buffer
;
1536 unsigned long buflen
;
1538 if (!size
) return FALSE
;
1540 GetSystemDirectoryW( fullname
, MAX_PATH
);
1541 strcatW( fullname
, path
);
1543 len
= sizeof(profile
)/sizeof(WCHAR
);
1544 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE
, mntr
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
) &&
1545 !RegEnumValueW( hkey
, 0, profile
, &len
, NULL
, NULL
, NULL
, NULL
)) /* FIXME handle multiple values */
1547 strcatW( fullname
, profile
);
1548 RegCloseKey( hkey
);
1550 else if ((buffer
= get_icm_profile( &buflen
)))
1552 static const WCHAR fmt
[] = {'%','0','2','x',0};
1553 static const WCHAR icm
[] = {'.','i','c','m',0};
1555 unsigned char sha1sum
[20];
1561 A_SHAUpdate( &ctx
, buffer
, buflen
);
1562 A_SHAFinal( &ctx
, sha1sum
);
1564 for (i
= 0; i
< sizeof(sha1sum
); i
++) sprintfW( &profile
[i
* 2], fmt
, sha1sum
[i
] );
1565 memcpy( &profile
[i
* 2], icm
, sizeof(icm
) );
1567 strcatW( fullname
, profile
);
1568 file
= CreateFileW( fullname
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, 0 );
1569 if (file
!= INVALID_HANDLE_VALUE
)
1573 if (!WriteFile( file
, buffer
, buflen
, &written
, NULL
) || written
!= buflen
)
1574 ERR( "Unable to write color profile\n" );
1575 CloseHandle( file
);
1577 HeapFree( GetProcessHeap(), 0, buffer
);
1579 else strcatW( fullname
, srgb
);
1581 required
= strlenW( fullname
) + 1;
1582 if (*size
< required
)
1585 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1590 strcpyW( filename
, fullname
);
1591 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1592 WARN( "color profile not found\n" );