1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/dcclient.cpp
3 // Purpose: wxClientDC class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 About pens, brushes, and the m_autoSetting flag:
15 Under X, pens and brushes control some of the same X drawing
16 parameters. Therefore, it is impossible to independently maintain
17 the current pen and the current brush. Also, some settings depend on
18 the current logical function. The m_currentFill, etc. instance
19 variables remember state across the brush and pen.
21 Since pens are used more than brushes, the m_autoSetting flag is used to
22 indicate that a brush was recently used, and SetPen must be called to
23 reinstall the current pen's parameters. If m_autoSetting includes 0x2, then the
24 pens color may need to be set based on XOR.
26 There is, unfortunately, some confusion between setting the current pen/brush
27 and actually installing the brush/pen parameters. Both functionalies are
28 perform by SetPen and SetBrush. C'est la vie.
31 // ============================================================================
33 // ============================================================================
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // For compilers that support precompilation, includes "wx.h".
40 #include "wx/wxprec.h"
42 #include "wx/dcclient.h"
47 #include "wx/window.h"
48 #include "wx/dcmemory.h"
54 #pragma message disable nosimpint
58 #pragma message enable nosimpint
61 #include "wx/motif/private.h"
64 #include <float.h> // for M_PI
74 static Pixmap bdiag
, cdiag
, fdiag
, cross
, horiz
, verti
;
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 // Fudge factor (VZ: what??)
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
88 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxWindowDC
)
89 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
92 // IS_HATCH exists for WXWIN_COMPATIBILITY_2_4 only
93 // but wxMotif needs it for its internals here
94 #define IS_HATCH(s) ((s)>=wxFIRST_HATCH && (s)<=wxLAST_HATCH)
97 // FIXME: left over after removal of wxDC::GetOptimization()
98 #define GET_OPTIMIZATION false
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 static void XCopyRemote(Display
*src_display
, Display
*dest_display
,
105 Drawable src
, Drawable dest
,
108 unsigned int w
, unsigned int h
,
109 int destx
, int desty
,
110 bool more
, XImage
**cache
);
112 // ============================================================================
114 // ============================================================================
117 * compare two doubles and return the larger rounded
120 static int roundmax(double a
, double b
)
122 return (int)((a
> b
? a
: b
) + 0.5);
126 * compare two doubles and return the smaller rounded
129 static int roundmin(double a
, double b
)
131 return (int)((a
< b
? a
: b
) - 0.5);
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 void wxWindowDC::Init()
142 m_gcBacking
= (WXGC
) 0;
144 m_backgroundPixel
= -1;
145 m_currentPenWidth
= 1;
146 m_currentPenJoin
= -1;
147 m_currentPenDashCount
= -1;
148 m_currentPenDash
= (wxX11Dash
*) NULL
;
151 m_colour
= wxColourDisplay();
152 m_display
= (WXDisplay
*) NULL
;
153 m_pixmap
= (WXPixmap
) 0;
156 m_clipRegion
= (WXRegion
) 0;
159 wxWindowDC::wxWindowDC()
164 wxWindowDC::wxWindowDC( wxWindow
*window
)
166 wxASSERT_MSG( (window
!= (wxWindow
*) NULL
), "You must pass a valid wxWindow to wxWindowDC/wxClientDC/wxPaintDC constructor." );
171 m_font
= window
->GetFont();
174 m_display
= window
->GetXDisplay();
175 m_pixmap
= window
->GetXWindow();
176 Display
* display
= (Display
*) m_display
;
178 XSetWindowColormap (display
, (Pixmap
) m_pixmap
, (Colormap
) wxTheApp
->GetMainColormap(m_display
));
181 gcvalues
.foreground
= BlackPixel (display
, DefaultScreen (display
));
182 gcvalues
.background
= WhitePixel (display
, DefaultScreen (display
));
183 gcvalues
.graphics_exposures
= False
;
184 gcvalues
.subwindow_mode
= IncludeInferiors
;
185 gcvalues
.line_width
= 1;
186 m_gc
= (WXGC
) XCreateGC (display
, RootWindow (display
, DefaultScreen (display
)),
187 GCForeground
| GCBackground
| GCGraphicsExposures
| GCLineWidth
| GCSubwindowMode
,
190 if (m_window
->GetBackingPixmap())
192 m_gcBacking
= (WXGC
) XCreateGC (display
, RootWindow (display
,
193 DefaultScreen (display
)),
194 GCForeground
| GCBackground
| GCGraphicsExposures
| GCLineWidth
| GCSubwindowMode
,
198 m_backgroundPixel
= gcvalues
.background
;
200 SetBackground(wxBrush(m_window
->GetBackgroundColour(), wxSOLID
));
203 wxWindowDC::~wxWindowDC()
206 XFreeGC ((Display
*) m_display
, (GC
) m_gc
);
210 XFreeGC ((Display
*) m_display
, (GC
) m_gcBacking
);
211 m_gcBacking
= (WXGC
) 0;
214 XDestroyRegion ((Region
) m_clipRegion
);
215 m_clipRegion
= (WXRegion
) 0;
218 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
219 const wxColour
& col
, int style
);
221 bool wxWindowDC::DoFloodFill(wxCoord x
, wxCoord y
,
222 const wxColour
& col
, int style
)
224 return wxDoFloodFill(this, x
, y
, col
, style
);
227 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
229 // Generic (and therefore rather inefficient) method.
230 // Could be improved.
232 wxBitmap
bitmap(1, 1);
233 memdc
.SelectObject(bitmap
);
234 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
235 memdc
.SelectObject(wxNullBitmap
);
236 wxImage image
= bitmap
.ConvertToImage();
237 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
241 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
243 wxCHECK_RET( Ok(), "invalid dc" );
245 int x1d
, y1d
, x2d
, y2d
;
255 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, x1d
, y1d
, x2d
, y2d
);
257 if (m_window
&& m_window
->GetBackingPixmap())
258 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
259 XLOG2DEV_2(x1
), YLOG2DEV_2(y1
),
260 XLOG2DEV_2(x2
), YLOG2DEV_2(y2
));
262 CalcBoundingBox(x1
, y1
);
263 CalcBoundingBox(x2
, y2
);
266 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
268 wxCHECK_RET( Ok(), "invalid dc" );
273 int xx
= XLOG2DEV (x
);
274 int yy
= YLOG2DEV (y
);
276 wxDisplaySize (&ww
, &hh
);
277 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, 0, yy
,
279 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xx
, 0,
282 if (m_window
&& m_window
->GetBackingPixmap())
286 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
289 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
295 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
297 wxCHECK_RET( Ok(), "invalid dc" );
299 int xx1
= XLOG2DEV (x1
);
300 int yy1
= YLOG2DEV (y1
);
301 int xx2
= XLOG2DEV (x2
);
302 int yy2
= YLOG2DEV (y2
);
303 int xxc
= XLOG2DEV (xc
);
304 int yyc
= YLOG2DEV (yc
);
305 int xxc_2
= XLOG2DEV_2 (xc
);
306 int yyc_2
= YLOG2DEV_2 (yc
);
308 wxCoord dx
= xx1
- xxc
;
309 wxCoord dy
= yy1
- yyc
;
310 double radius
= sqrt ((double)(dx
* dx
+ dy
* dy
));
311 wxCoord r
= (wxCoord
) radius
;
313 double radius1
, radius2
;
315 if (xx1
== xx2
&& yy1
== yy2
)
320 else if (radius
== 0.0)
321 radius1
= radius2
= 0.0;
330 radius1
= -atan2 ((double) (yy1
- yyc
), (double) (xx1
- xxc
)) * 360.0 / (2 * M_PI
);
338 radius2
= -atan2 ((double) (yy2
- yyc
), (double) (xx2
- xxc
)) * 360.0 / (2 * M_PI
);
342 int alpha1
= (int) radius1
;
343 int alpha2
= (int) (radius2
- radius1
);
346 while (alpha2
> 360 * 64)
349 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
352 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) (GC
) m_gc
,
353 xxc
- r
, yyc
- r
, 2 * r
, 2 * r
, alpha1
, alpha2
);
355 if (m_window
&& m_window
->GetBackingPixmap())
356 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
357 xxc_2
- r
, yyc_2
- r
, 2 * r
, 2 * r
, alpha1
, alpha2
);
361 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
365 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
366 xxc
- r
, yyc
- r
, 2 * r
, 2 * r
, alpha1
, alpha2
);
368 if (m_window
&& m_window
->GetBackingPixmap())
369 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
370 xxc_2
- r
, yyc_2
- r
, 2 * r
, 2 * r
, alpha1
, alpha2
);
372 CalcBoundingBox (x1
, y1
);
373 CalcBoundingBox (x2
, y2
);
376 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
378 wxCHECK_RET( Ok(), "invalid dc" );
384 wd
= XLOG2DEVREL(width
);
385 hd
= YLOG2DEVREL(height
);
387 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
388 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
389 int start
= int(sa
*64);
390 int end
= int(ea
*64);
391 if (start
<0) start
+=360*64;
392 if (end
<0) end
+=360*64;
393 if (end
>start
) end
-=start
;
394 else end
+=360*64-start
;
396 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
398 m_autoSetting
= true; // must be reset
401 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
, start
, end
);
403 if (m_window
&& m_window
->GetBackingPixmap())
404 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
405 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),wd
,hd
,start
,end
);
408 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
412 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
, start
,end
);
413 if (m_window
&& m_window
->GetBackingPixmap())
414 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
415 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),wd
,hd
,start
,end
);
417 CalcBoundingBox (x
, y
);
418 CalcBoundingBox (x
+ width
, y
+ height
);
421 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
423 wxCHECK_RET( Ok(), "invalid dc" );
425 if (m_pen
.Ok() && m_autoSetting
)
428 XDrawPoint ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
));
429 if (m_window
&& m_window
->GetBackingPixmap())
430 XDrawPoint ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
, XLOG2DEV_2 (x
), YLOG2DEV_2 (y
));
432 CalcBoundingBox (x
, y
);
435 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
437 wxCHECK_RET( Ok(), "invalid dc" );
439 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
444 XPoint
*xpoints
= new XPoint
[n
];
447 for (i
= 0; i
< n
; i
++)
449 xpoints
[i
].x
= (short)XLOG2DEV (points
[i
].x
+ xoffset
);
450 xpoints
[i
].y
= (short)YLOG2DEV (points
[i
].y
+ yoffset
);
452 XDrawLines ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xpoints
, n
, 0);
454 if (m_window
&& m_window
->GetBackingPixmap())
456 for (i
= 0; i
< n
; i
++)
458 xpoints
[i
].x
= (short)XLOG2DEV_2 (points
[i
].x
+ xoffset
);
459 xpoints
[i
].y
= (short)YLOG2DEV_2 (points
[i
].y
+ yoffset
);
461 XDrawLines ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
, xpoints
, n
, 0);
467 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[],
468 wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
470 wxCHECK_RET( Ok(), "invalid dc" );
472 XPoint
*xpoints1
= new XPoint
[n
+ 1];
473 XPoint
*xpoints2
= new XPoint
[n
+ 1];
475 for (i
= 0; i
< n
; i
++)
477 xpoints1
[i
].x
= (short)XLOG2DEV (points
[i
].x
+ xoffset
);
478 xpoints1
[i
].y
= (short)YLOG2DEV (points
[i
].y
+ yoffset
);
479 xpoints2
[i
].x
= (short)XLOG2DEV_2 (points
[i
].x
+ xoffset
);
480 xpoints2
[i
].y
= (short)YLOG2DEV_2 (points
[i
].y
+ yoffset
);
481 CalcBoundingBox (points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
484 // Close figure for XDrawLines (not needed for XFillPolygon)
485 xpoints1
[i
].x
= xpoints1
[0].x
;
486 xpoints1
[i
].y
= xpoints1
[0].y
;
487 xpoints2
[i
].x
= xpoints2
[0].x
;
488 xpoints2
[i
].y
= xpoints2
[0].y
;
490 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
493 XSetFillRule ((Display
*) m_display
, (GC
) m_gc
, fillStyle
== wxODDEVEN_RULE
? EvenOddRule
: WindingRule
);
494 XFillPolygon ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xpoints1
, n
, Complex
, 0);
495 XSetFillRule ((Display
*) m_display
, (GC
) m_gc
, EvenOddRule
); // default mode
496 if (m_window
&& m_window
->GetBackingPixmap())
498 XSetFillRule ((Display
*) m_display
,(GC
) m_gcBacking
,
499 fillStyle
== wxODDEVEN_RULE
? EvenOddRule
: WindingRule
);
500 XFillPolygon ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
, xpoints2
, n
, Complex
, 0);
501 XSetFillRule ((Display
*) m_display
,(GC
) m_gcBacking
, EvenOddRule
); // default mode
505 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
509 XDrawLines ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xpoints1
, n
+ 1, 0);
511 if (m_window
&& m_window
->GetBackingPixmap())
512 XDrawLines ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
, xpoints2
, n
+ 1, 0);
519 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
521 wxCHECK_RET( Ok(), "invalid dc" );
523 int xd
, yd
, wfd
, hfd
, wd
, hd
;
527 wfd
= XLOG2DEVREL(width
);
529 hfd
= YLOG2DEVREL(height
);
532 if (wfd
== 0 || hfd
== 0) return;
533 if (wd
< 0) { wd
= - wd
; xd
= xd
- wd
; }
534 if (hd
< 0) { hd
= - hd
; yd
= yd
- hd
; }
536 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
539 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wfd
, hfd
);
541 if (m_window
&& m_window
->GetBackingPixmap())
542 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
543 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),
547 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
551 XDrawRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
);
553 if (m_window
&& m_window
->GetBackingPixmap())
554 XDrawRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
555 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),
558 CalcBoundingBox (x
, y
);
559 CalcBoundingBox (x
+ width
, y
+ height
);
562 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
564 wxCHECK_RET( Ok(), "invalid dc" );
566 // If radius is negative, it's a proportion of the smaller dimension.
568 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
570 int xd
= XLOG2DEV (x
);
571 int yd
= YLOG2DEV (y
);
572 int rd
= XLOG2DEVREL ((long) radius
);
573 int wd
= XLOG2DEVREL (width
) - WX_GC_CF
;
574 int hd
= YLOG2DEVREL (height
) - WX_GC_CF
;
579 // If radius is zero use DrawRectangle() instead to avoid
580 // X drawing errors with small radii
583 DrawRectangle( x
, y
, width
, height
);
587 // Draw nothing if transformed w or h is 0
588 if (wd
== 0 || hd
== 0) return;
590 // CMB: adjust size if outline is drawn otherwise the result is
591 // 1 pixel too wide and high
592 if (m_pen
.GetStyle() != wxTRANSPARENT
)
598 // CMB: ensure dd is not larger than rectangle otherwise we
599 // get an hour glass shape
600 if (rw_d
> wd
) rw_d
= wd
;
601 if (rw_d
> hd
) rw_d
= hd
;
604 // For backing pixmap
605 int xd2
= XLOG2DEV_2 (x
);
606 int yd2
= YLOG2DEV_2 (y
);
607 int rd2
= XLOG2DEVREL ((long) radius
);
608 int wd2
= XLOG2DEVREL (width
) ;
609 int hd2
= YLOG2DEVREL (height
) ;
614 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
618 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ rd
, yd
,
620 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
+ rd
,
623 // Arcs start from 3 o'clock, positive angles anticlockwise
625 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
,
626 rw_d
, rh_d
, 90 * 64, 90 * 64);
628 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
- rw_d
, yd
,
629 // rw_d, rh_d, 0, 90 * 64);
630 rw_d
, rh_d
, 0, 91 * 64);
632 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
- rw_d
,
634 // rw_d, rh_d, 270 * 64, 90 * 64);
635 rw_d
, rh_d
, 269 * 64, 92 * 64);
637 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
+ hd
- rh_d
,
638 rw_d
, rh_d
, 180 * 64, 90 * 64);
640 if (m_window
&& m_window
->GetBackingPixmap())
642 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
643 xd2
+ rd2
, yd2
, wd2
- rw_d2
, hd2
);
644 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
645 xd2
, yd2
+ rd2
, wd2
, hd2
- rh_d2
);
647 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
648 xd2
, yd2
, rw_d2
, rh_d2
, 90 * 64, 90 * 64);
649 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
650 xd2
+ wd2
- rw_d2
, yd2
,
651 // rw_d2, rh_d2, 0, 90 * 64);
652 rw_d2
, rh_d2
, 0, 91 * 64);
653 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
656 // rw_d2, rh_d2, 270 * 64, 90 * 64);
657 rw_d2
, rh_d2
, 269 * 64, 92 * 64);
658 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
659 xd2
, yd2
+ hd2
- rh_d2
,
660 rw_d2
, rh_d2
, 180 * 64, 90 * 64);
664 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
667 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ rd
, yd
,
668 xd
+ wd
- rd
+ 1, yd
);
669 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ rd
, yd
+ hd
,
670 xd
+ wd
- rd
, yd
+ hd
);
672 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
+ rd
,
674 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
, yd
+ rd
,
675 xd
+ wd
, yd
+ hd
- rd
+ 1);
676 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
,
677 rw_d
, rh_d
, 90 * 64, 90 * 64);
678 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
- rw_d
, yd
,
679 // rw_d, rh_d, 0, 90 * 64);
680 rw_d
, rh_d
, 0, 91 * 64);
681 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
- rw_d
,
683 rw_d
, rh_d
, 269 * 64, 92 * 64);
684 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
+ hd
- rh_d
,
685 rw_d
, rh_d
, 180 * 64, 90 * 64);
687 if (m_window
&& m_window
->GetBackingPixmap())
689 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
691 xd2
+ wd2
- rd2
+ 1, yd2
);
692 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
693 xd2
+ rd2
, yd2
+ hd2
,
694 xd2
+ wd2
- rd2
, yd2
+ hd2
);
696 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
698 xd2
, yd2
+ hd2
- rd2
);
699 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
700 xd2
+ wd2
, yd2
+ rd2
,
701 xd2
+ wd2
, yd2
+ hd2
- rd2
+ 1);
702 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
704 rw_d2
, rh_d2
, 90 * 64, 90 * 64);
705 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
706 xd2
+ wd2
- rw_d2
, yd2
,
707 // rw_d2, rh_d2, 0, 90 * 64);
708 rw_d2
, rh_d2
, 0, 91 * 64);
709 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
712 rw_d2
, rh_d2
, 269 * 64, 92 * 64);
713 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
714 xd2
, yd2
+ hd2
- rh_d2
,
715 rw_d2
, rh_d2
, 180 * 64, 90 * 64);
718 CalcBoundingBox (x
, y
);
719 CalcBoundingBox (x
+ width
, y
+ height
);
722 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
724 wxCHECK_RET( Ok(), "invalid dc" );
726 // Check for negative width and height
739 static const int angle
= 23040;
745 wd
= XLOG2DEVREL(width
) ;
746 hd
= YLOG2DEVREL(height
) ;
748 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
751 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
, 0, angle
);
752 if (m_window
&& m_window
->GetBackingPixmap())
753 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
754 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),
755 XLOG2DEVREL (width
) - WX_GC_CF
,
756 YLOG2DEVREL (height
) - WX_GC_CF
, 0, angle
);
759 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
763 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
, 0, angle
);
764 if (m_window
&& m_window
->GetBackingPixmap())
765 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
766 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),
767 XLOG2DEVREL (width
) - WX_GC_CF
,
768 YLOG2DEVREL (height
) - WX_GC_CF
, 0, angle
);
770 CalcBoundingBox (x
, y
);
771 CalcBoundingBox (x
+ width
, y
+ height
);
775 bool wxWindowDC::CanDrawBitmap() const
777 wxCHECK_MSG( Ok(), false, "invalid dc" );
782 // TODO: use scaled Blit e.g. as per John Price's implementation
783 // in Contrib/Utilities
784 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
785 wxCoord width
, wxCoord height
,
786 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
787 int rop
, bool useMask
,
788 wxCoord xsrcMask
, wxCoord ysrcMask
)
790 wxCHECK_MSG( Ok(), false, "invalid dc" );
792 wxWindowDC
* sourceDC
= wxDynamicCast(source
, wxWindowDC
);
794 wxASSERT_MSG( sourceDC
, "Blit source DC must be wxWindowDC or derived class." );
796 // Be sure that foreground pixels (1) of the Icon will be painted with
797 // foreground colour. [m_textForegroundColour] Background pixels (0)
798 // will be painted with backgound colour (m_textBackgroundColour)
799 // Using ::SetPen is horribly slow, so avoid doing it
800 WXPixel oldBackgroundPixel
= -1;
801 WXPixel oldForegroundPixel
= -1;
803 if (m_textBackgroundColour
.Ok())
805 oldBackgroundPixel
= m_backgroundPixel
;
806 WXPixel pixel
= m_textBackgroundColour
.AllocColour(m_display
);
808 XSetBackground ((Display
*) m_display
, (GC
) m_gc
, pixel
);
809 if (m_window
&& m_window
->GetBackingPixmap())
810 XSetBackground ((Display
*) m_display
,(GC
) m_gcBacking
,
813 if (m_textForegroundColour
.Ok())
815 oldForegroundPixel
= m_currentColour
.GetPixel();
817 if( m_textForegroundColour
.GetPixel() <= -1 )
818 CalculatePixel( m_textForegroundColour
,
819 m_textForegroundColour
, true);
821 WXPixel pixel
= m_textForegroundColour
.GetPixel();
823 SetForegroundPixelWithLogicalFunction(pixel
);
826 // Do bitmap scaling if necessary
828 wxBitmap
*scaledBitmap
= (wxBitmap
*) NULL
;
829 Pixmap sourcePixmap
= (Pixmap
) NULL
;
830 double scaleX
, scaleY
;
831 GetUserScale(& scaleX
, & scaleY
);
834 /* TODO: use the mask origin when drawing transparently */
835 if (xsrcMask
== -1 && ysrcMask
== -1)
837 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
840 // Sorry, can't scale masks just yet
841 if (!useMask
&& (scaleX
!= 1.0 || scaleY
!= 1.0) && sourceDC
->IsKindOf(CLASSINFO(wxMemoryDC
)))
843 wxMemoryDC
* memDC
= (wxMemoryDC
*) sourceDC
;
844 wxBitmap
& bitmap
= memDC
->GetBitmap();
846 wxASSERT_MSG( (bitmap
.Ok()), "Bad source bitmap in wxWindowDC::Blit");
848 wxImage image
= bitmap
.ConvertToImage();
851 sourcePixmap
= (Pixmap
) bitmap
.GetDrawable();
855 int scaledW
= (int) (bitmap
.GetWidth() * scaleX
);
856 int scaledH
= (int) (bitmap
.GetHeight() * scaleY
);
858 image
= image
.Scale(scaledW
, scaledH
);
859 scaledBitmap
= new wxBitmap(image
);
860 sourcePixmap
= (Pixmap
) scaledBitmap
->GetDrawable();
864 sourcePixmap
= (Pixmap
) sourceDC
->m_pixmap
;
866 if (m_pixmap
&& sourcePixmap
)
869 int orig
= m_logicalFunction
;
871 SetLogicalFunction (rop
);
873 if (m_display
!= sourceDC
->m_display
)
875 XImage
*cache
= NULL
;
877 if (m_window
&& m_window
->GetBackingPixmap())
878 XCopyRemote((Display
*) sourceDC
->m_display
, (Display
*) m_display
,
879 (Pixmap
) sourcePixmap
, (Pixmap
) m_window
->GetBackingPixmap(),
881 source
->LogicalToDeviceX (xsrc
),
882 source
->LogicalToDeviceY (ysrc
),
883 source
->LogicalToDeviceXRel(width
),
884 source
->LogicalToDeviceYRel(height
),
885 XLOG2DEV_2 (xdest
), YLOG2DEV_2 (ydest
),
888 if ( useMask
&& source
->IsKindOf(CLASSINFO(wxMemoryDC
)) )
890 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
891 wxBitmap
& sel
= memDC
->GetBitmap();
892 if ( sel
.Ok() && sel
.GetMask() && sel
.GetMask()->GetBitmap() )
894 XSetClipMask ((Display
*) m_display
, (GC
) m_gc
, (Pixmap
) sel
.GetMask()->GetBitmap());
895 XSetClipOrigin ((Display
*) m_display
, (GC
) m_gc
, XLOG2DEV (xdest
), YLOG2DEV (ydest
));
899 XCopyRemote((Display
*) sourceDC
->m_display
, (Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
900 source
->LogicalToDeviceX (xsrc
),
901 source
->LogicalToDeviceY (ysrc
),
902 source
->LogicalToDeviceXRel(width
),
903 source
->LogicalToDeviceYRel(height
),
904 XLOG2DEV (xdest
), YLOG2DEV (ydest
),
910 XSetRegion ((Display
*) m_display
, (GC
) m_gc
,
911 (Region
) m_clipRegion
);
913 XSetClipMask ((Display
*) m_display
, (GC
) m_gc
, None
);
915 XSetClipOrigin ((Display
*) m_display
, (GC
) m_gc
, 0, 0);
919 { //XGCValues values;
920 //XGetGCValues((Display*)m_display, (GC)m_gc, GCForeground, &values);
922 if (m_window
&& m_window
->GetBackingPixmap())
924 // +++ MARKUS (mho@comnets.rwth-aachen): error on blitting bitmaps with depth 1
925 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)) && ((wxMemoryDC
*) source
)->GetBitmap().GetDepth() == 1)
927 XCopyPlane ((Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
928 source
->LogicalToDeviceX (xsrc
),
929 source
->LogicalToDeviceY (ysrc
),
930 source
->LogicalToDeviceXRel(width
),
931 source
->LogicalToDeviceYRel(height
),
932 XLOG2DEV_2 (xdest
), YLOG2DEV_2 (ydest
), 1);
936 XCopyArea ((Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
937 source
->LogicalToDeviceX (xsrc
),
938 source
->LogicalToDeviceY (ysrc
),
939 source
->LogicalToDeviceXRel(width
),
940 source
->LogicalToDeviceYRel(height
),
941 XLOG2DEV_2 (xdest
), YLOG2DEV_2 (ydest
));
944 if ( useMask
&& source
->IsKindOf(CLASSINFO(wxMemoryDC
)) )
946 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
947 wxBitmap
& sel
= memDC
->GetBitmap();
948 if ( sel
.Ok() && sel
.GetMask() && sel
.GetMask()->GetBitmap() )
950 XSetClipMask ((Display
*) m_display
, (GC
) m_gc
, (Pixmap
) sel
.GetMask()->GetBitmap());
951 XSetClipOrigin ((Display
*) m_display
, (GC
) m_gc
, XLOG2DEV (xdest
), YLOG2DEV (ydest
));
955 // Check if we're copying from a mono bitmap
956 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)) &&
957 ((wxMemoryDC
*)source
)->GetBitmap().Ok() && (((wxMemoryDC
*)source
)->GetBitmap().GetDepth () == 1))
959 XCopyPlane ((Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
960 source
->LogicalToDeviceX (xsrc
),
961 source
->LogicalToDeviceY (ysrc
),
962 source
->LogicalToDeviceXRel(width
),
963 source
->LogicalToDeviceYRel(height
),
964 XLOG2DEV (xdest
), YLOG2DEV (ydest
), 1);
968 XCopyArea ((Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
969 source
->LogicalToDeviceX (xsrc
),
970 source
->LogicalToDeviceY (ysrc
),
971 source
->LogicalToDeviceXRel(width
),
972 source
->LogicalToDeviceYRel(height
),
973 XLOG2DEV (xdest
), YLOG2DEV (ydest
));
979 XSetRegion ((Display
*) m_display
, (GC
) m_gc
,
980 (Region
) m_clipRegion
);
982 XSetClipMask ((Display
*) m_display
, (GC
) m_gc
, None
);
984 XSetClipOrigin ((Display
*) m_display
, (GC
) m_gc
, 0, 0);
987 } /* Remote/local (Display*) m_display */
988 CalcBoundingBox (xdest
, ydest
);
989 CalcBoundingBox (xdest
+ width
, ydest
+ height
);
991 SetLogicalFunction(orig
);
995 if (scaledBitmap
) delete scaledBitmap
;
997 if (oldBackgroundPixel
> -1)
999 XSetBackground ((Display
*) m_display
, (GC
) m_gc
, oldBackgroundPixel
);
1000 if (m_window
&& m_window
->GetBackingPixmap())
1001 XSetBackground ((Display
*) m_display
,(GC
) m_gcBacking
,
1002 oldBackgroundPixel
);
1004 if (oldForegroundPixel
> -1)
1006 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, oldForegroundPixel
);
1007 if (m_window
&& m_window
->GetBackingPixmap())
1008 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
,
1009 oldForegroundPixel
);
1015 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1017 wxCHECK_RET( Ok(), "invalid dc" );
1019 // Since X draws from the baseline of the text, must add the text height
1023 int slen
= text
.length();
1025 // Set FillStyle, otherwise X will use current stipple!
1026 XGCValues gcV
, gcBackingV
;
1028 XGetGCValues ((Display
*) m_display
, (GC
)m_gc
, GCFillStyle
, &gcV
);
1029 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, FillSolid
);
1030 if (m_window
&& m_window
->GetBackingPixmap())
1032 XGetGCValues ((Display
*) m_display
, (GC
)m_gcBacking
, GCFillStyle
,
1034 XSetFillStyle ((Display
*) m_display
, (GC
) m_gcBacking
, FillSolid
);
1038 wxGetTextExtent (m_display
, m_font
, m_userScaleY
* m_logicalScaleY
,
1039 text
, &cx
, &cy
, &ascent
, NULL
);
1041 // First draw a rectangle representing the text background, if a text
1042 // background is specified
1043 if (m_textBackgroundColour
.Ok () && (m_backgroundMode
!= wxTRANSPARENT
))
1045 wxColour oldPenColour
= m_currentColour
;
1046 m_currentColour
= m_textBackgroundColour
;
1047 bool sameColour
= (oldPenColour
.Ok () && m_textBackgroundColour
.Ok () &&
1048 (oldPenColour
.Red () == m_textBackgroundColour
.Red ()) &&
1049 (oldPenColour
.Blue () == m_textBackgroundColour
.Blue ()) &&
1050 (oldPenColour
.Green () == m_textBackgroundColour
.Green ()));
1052 // This separation of the big && test required for gcc2.7/HP UX 9.02
1053 // or pixel value can be corrupted!
1054 sameColour
= (sameColour
&&
1055 (oldPenColour
.GetPixel() == m_textBackgroundColour
.GetPixel()));
1057 if (!sameColour
|| !GET_OPTIMIZATION
)
1059 WXPixel pixel
= m_textBackgroundColour
.AllocColour(m_display
);
1060 m_currentColour
= m_textBackgroundColour
;
1062 // Set the GC to the required colour
1065 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, pixel
);
1066 if (m_window
&& m_window
->GetBackingPixmap())
1067 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
, pixel
);
1071 m_textBackgroundColour
= oldPenColour
;
1073 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
), cx
, cy
);
1074 if (m_window
&& m_window
->GetBackingPixmap())
1075 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
1076 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
), cx
, cy
);
1079 // Now set the text foreground and draw the text
1080 if (m_textForegroundColour
.Ok ())
1082 wxColour oldPenColour
= m_currentColour
;
1083 m_currentColour
= m_textForegroundColour
;
1084 bool sameColour
= (oldPenColour
.Ok () && m_currentColour
.Ok () &&
1085 (oldPenColour
.Red () == m_currentColour
.Red ()) &&
1086 (oldPenColour
.Blue () == m_currentColour
.Blue ()) &&
1087 (oldPenColour
.Green () == m_currentColour
.Green ()) &&
1088 (oldPenColour
.GetPixel() == m_currentColour
.GetPixel()));
1090 if (!sameColour
|| !GET_OPTIMIZATION
)
1092 WXPixel pixel
= CalculatePixel(m_textForegroundColour
,
1093 m_currentColour
, false);
1095 // Set the GC to the required colour
1098 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, pixel
);
1099 if (m_window
&& m_window
->GetBackingPixmap())
1100 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
, pixel
);
1104 m_textForegroundColour
= oldPenColour
;
1107 // We need to add the ascent, not the whole height, since X draws at the
1108 // point above the descender.
1111 XDrawString16((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
) + ascent
,
1112 (XChar2b
*)(char*) (const char*) text
, slen
);
1115 #if wxMOTIF_NEW_FONT_HANDLING
1116 XFontSet fset
= (XFontSet
) m_font
.GetFontSet (m_userScaleY
* m_logicalScaleY
, m_display
);
1117 XmbDrawString((Display
*) m_display
, (Pixmap
) m_pixmap
, fset
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
) + ascent
, text
, slen
);
1119 XDrawString((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
) + ascent
, text
, slen
);
1122 if (m_window
&& m_window
->GetBackingPixmap()) {
1125 XDrawString16((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
1126 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
) + ascent
,
1127 (XChar2b
*)(char*) (const char*) text
, slen
);
1130 #if wxMOTIF_NEW_FONT_HANDLING
1131 XmbDrawString((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), fset
, (GC
) m_gcBacking
,
1132 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
) + ascent
,
1133 wxConstCast(text
.c_str(), char), slen
);
1135 XDrawString((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
1136 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
) + ascent
,
1137 wxConstCast(text
.c_str(), char), slen
);
1141 // restore fill style
1142 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, gcV
.fill_style
);
1143 if (m_window
&& m_window
->GetBackingPixmap())
1144 XSetFillStyle ((Display
*) m_display
, (GC
) m_gcBacking
,
1145 gcBackingV
.fill_style
);
1148 GetTextExtent (text
, &w
, &h
);
1149 CalcBoundingBox (x
+ w
, y
+ h
);
1150 CalcBoundingBox (x
, y
);
1153 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
,
1158 DrawText(text
, x
, y
);
1162 wxCHECK_RET( Ok(), "invalid dc" );
1164 WXPixel oldBackgroundPixel
= -1;
1165 WXPixel oldForegroundPixel
= -1;
1166 WXPixel foregroundPixel
= -1;
1167 WXPixel backgroundPixel
= -1;
1169 if (m_textBackgroundColour
.Ok())
1171 oldBackgroundPixel
= m_backgroundPixel
;
1172 backgroundPixel
= m_textBackgroundColour
.AllocColour(m_display
);
1174 if (m_textForegroundColour
.Ok())
1176 oldForegroundPixel
= m_currentColour
.GetPixel();
1178 if( m_textForegroundColour
.GetPixel() <= -1 )
1179 CalculatePixel( m_textForegroundColour
,
1180 m_textForegroundColour
, true);
1182 foregroundPixel
= m_textForegroundColour
.GetPixel();
1185 // Since X draws from the baseline of the text, must add the text height
1191 wxGetTextExtent (m_display
, m_font
, m_userScaleY
* m_logicalScaleY
,
1192 text
, &cx
, &cy
, &ascent
, NULL
);
1194 wxBitmap
src(cx
, cy
);
1196 dc
.SelectObject(src
);
1197 dc
.SetFont(GetFont());
1198 dc
.SetBackground(*wxWHITE_BRUSH
);
1199 dc
.SetBrush(*wxBLACK_BRUSH
);
1201 dc
.DrawText(text
, 0, 0);
1202 dc
.SetFont(wxNullFont
);
1204 // Calculate the size of the rotated bounding box.
1205 double dx
= cos(angle
/ 180.0 * M_PI
);
1206 double dy
= sin(angle
/ 180.0 * M_PI
);
1207 double x4
= cy
* dy
;
1208 double y4
= cy
* dx
;
1209 double x3
= cx
* dx
;
1210 double y3
= -cx
* dy
;
1211 double x2
= x3
+ x4
;
1212 double y2
= y3
+ y4
;
1216 // Create image from the source bitmap after writing the text into it.
1217 wxImage image
= src
.ConvertToImage();
1219 int minx
= roundmin(0, roundmin(x4
, roundmin(x2
, x3
)));
1220 int miny
= roundmin(0, roundmin(y4
, roundmin(y2
, y3
)));
1221 int maxx
= roundmax(0, roundmax(x4
, roundmax(x2
, x3
)));
1222 int maxy
= roundmax(0, roundmax(y4
, roundmax(y2
, y3
)));
1224 bool lastFore
= false, lastBack
= false;
1226 // This rotates counterclockwise around the top left corner.
1227 for (int rx
= minx
; rx
< maxx
; rx
++)
1229 for (int ry
= miny
; ry
< maxy
; ry
++)
1231 // transform dest coords to source coords
1232 int sx
= (int) (rx
* dx
- ry
* dy
+ 0.5);
1233 int sy
= - (int) (-ry
* dx
- rx
* dy
+ 0.5);
1234 if (sx
>= 0 && sx
< cx
&& sy
>= 0 && sy
< cy
)
1236 bool textPixel
= image
.GetRed(sx
, sy
) == 0;
1238 if (!textPixel
&& m_backgroundMode
!= wxSOLID
)
1241 wxCoord ox
= (wxCoord
) (x1
+ rx
),
1242 oy
= (wxCoord
) (y1
+ ry
);
1243 // draw black pixels, ignore white ones (i.e. transparent b/g)
1244 if (textPixel
&& !lastFore
)
1246 XSetForeground ((Display
*) m_display
, (GC
) m_gc
,
1251 else if (!textPixel
&& !lastBack
)
1253 XSetForeground ((Display
*) m_display
, (GC
) m_gc
,
1259 XDrawPoint ((Display
*) m_display
, (Pixmap
) m_pixmap
,
1260 (GC
) m_gc
, XLOG2DEV (ox
), YLOG2DEV (oy
));
1261 if (m_window
&& m_window
->GetBackingPixmap())
1262 XDrawPoint ((Display
*) m_display
,
1263 (Pixmap
) m_window
->GetBackingPixmap(),
1265 XLOG2DEV_2 (ox
), YLOG2DEV_2 (oy
));
1270 if (oldBackgroundPixel
> -1)
1272 XSetBackground ((Display
*) m_display
, (GC
) m_gc
, oldBackgroundPixel
);
1273 if (m_window
&& m_window
->GetBackingPixmap())
1274 XSetBackground ((Display
*) m_display
,(GC
) m_gcBacking
,
1275 oldBackgroundPixel
);
1277 if (oldForegroundPixel
> -1)
1279 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, oldForegroundPixel
);
1280 if (m_window
&& m_window
->GetBackingPixmap())
1281 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
,
1282 oldForegroundPixel
);
1285 CalcBoundingBox (minx
, miny
);
1286 CalcBoundingBox (maxx
, maxy
);
1289 bool wxWindowDC::CanGetTextExtent() const
1294 void wxWindowDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1295 wxCoord
*descent
, wxCoord
*externalLeading
,
1296 wxFont
*font
) const
1298 wxCHECK_RET( Ok(), "invalid dc" );
1300 const wxFont
* theFont
= font
? font
: &m_font
;
1304 // TODO: this should be an error log function
1305 wxFAIL_MSG("set a valid font before calling GetTextExtent!");
1307 if (width
) *width
= -1;
1308 if (height
) *height
= -1;
1312 wxGetTextExtent(m_display
, *theFont
, m_userScaleY
* m_logicalScaleY
,
1313 string
, width
, height
, NULL
, descent
);
1315 if (width
) *width
= XDEV2LOGREL (*width
);
1316 if (height
) *height
= YDEV2LOGREL (*height
);
1317 if (externalLeading
)
1318 *externalLeading
= 0;
1321 wxCoord
wxWindowDC::GetCharWidth() const
1323 wxCHECK_MSG( Ok(), 0, "invalid dc" );
1324 wxCHECK_MSG( m_font
.Ok(), 0, "invalid font" );
1328 wxGetTextExtent (m_display
, m_font
, m_userScaleY
* m_logicalScaleY
,
1329 "x", &width
, NULL
, NULL
, NULL
);
1331 return XDEV2LOGREL(width
);
1334 wxCoord
wxWindowDC::GetCharHeight() const
1336 wxCHECK_MSG( Ok(), 0, "invalid dc" );
1337 wxCHECK_MSG( m_font
.Ok(), 0, "invalid font" );
1341 wxGetTextExtent (m_display
, m_font
, m_userScaleY
* m_logicalScaleY
,
1342 "x", NULL
, &height
, NULL
, NULL
);
1344 return XDEV2LOGREL(height
);
1347 void wxWindowDC::DoGetSize( int *width
, int *height
) const
1353 if( m_window
->GetBackingPixmap() )
1355 w
= m_window
->GetPixmapWidth();
1356 h
= m_window
->GetPixmapHeight();
1359 m_window
->GetSize( &w
, &h
);
1362 if( width
) *width
= w
;
1363 if( height
) *height
= h
;
1366 void wxWindowDC::Clear()
1368 wxCHECK_RET( Ok(), "invalid dc" );
1370 wxRect
rect( GetSize() );
1374 void wxWindowDC::Clear(const wxRect
& rect
)
1376 wxCHECK_RET( Ok(), "invalid dc" );
1378 int x
= rect
.x
; int y
= rect
.y
;
1379 int w
= rect
.width
; int h
= rect
.height
;
1381 wxBrush saveBrush
= m_brush
;
1382 SetBrush (m_backgroundBrush
);
1384 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
1387 if (m_window
&& m_window
->GetBackingPixmap())
1388 XFillRectangle ((Display
*) m_display
,
1389 (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
1392 m_brush
= saveBrush
;
1395 void wxWindowDC::SetFont( const wxFont
&font
)
1397 wxCHECK_RET( Ok(), "invalid dc" );
1406 #if !wxMOTIF_NEW_FONT_HANDLING
1407 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(m_userScaleY
*m_logicalScaleY
, m_display
);
1409 Font fontId
= ((XFontStruct
*)pFontStruct
)->fid
;
1410 XSetFont ((Display
*) m_display
, (GC
) m_gc
, fontId
);
1412 if (m_window
&& m_window
->GetBackingPixmap())
1413 XSetFont ((Display
*) m_display
,(GC
) m_gcBacking
, fontId
);
1417 void wxWindowDC::SetForegroundPixelWithLogicalFunction(WXPixel pixel
)
1419 if (m_logicalFunction
== wxXOR
)
1422 XGetGCValues ((Display
*) m_display
, (GC
) m_gc
, GCBackground
, &values
);
1423 XSetForeground ((Display
*) m_display
, (GC
) m_gc
,
1424 pixel
^ values
.background
);
1425 if (m_window
&& m_window
->GetBackingPixmap())
1426 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
,
1427 pixel
^ values
.background
);
1431 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, pixel
);
1432 if (m_window
&& m_window
->GetBackingPixmap())
1433 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
, pixel
);
1437 WXPixel
wxWindowDC::CalculatePixel(wxColour
& colour
, wxColour
& curCol
,
1438 bool roundToWhite
) const
1440 const unsigned char wp
= (unsigned char)255;
1443 if(!m_colour
) // Mono display
1445 unsigned char red
= colour
.Red ();
1446 unsigned char blue
= colour
.Blue ();
1447 unsigned char green
= colour
.Green ();
1449 if((red
== wp
&& blue
== wp
&& green
== wp
) ||
1450 // not black and roundToWhite was specified
1451 ((red
!= 0 || blue
!= 0 || green
!= 0) && roundToWhite
))
1454 pixel
= WhitePixel((Display
*) m_display
,
1455 DefaultScreen((Display
*) m_display
));
1456 curCol
.SetPixel(pixel
);
1457 colour
.SetPixel(pixel
);
1462 pixel
= BlackPixel((Display
*) m_display
,
1463 DefaultScreen((Display
*) m_display
));
1464 curCol
.SetPixel(pixel
);
1465 colour
.SetPixel(pixel
);
1471 pixel
= colour
.AllocColour((Display
*) m_display
);
1472 curCol
.SetPixel(pixel
);
1478 void wxWindowDC::SetPen( const wxPen
&pen
)
1480 wxCHECK_RET( Ok(), "invalid dc" );
1486 wxBitmap oldStipple
= m_currentStipple
;
1487 int oldStyle
= m_currentStyle
;
1488 int oldFill
= m_currentFill
;
1489 int old_pen_width
= m_currentPenWidth
;
1490 int old_pen_join
= m_currentPenJoin
;
1491 int old_pen_cap
= m_currentPenCap
;
1492 int old_pen_nb_dash
= m_currentPenDashCount
;
1493 wxX11Dash
*old_pen_dash
= m_currentPenDash
;
1495 wxColour oldPenColour
= m_currentColour
;
1496 m_currentColour
= m_pen
.GetColour ();
1497 m_currentStyle
= m_pen
.GetStyle ();
1498 m_currentFill
= m_pen
.GetStyle (); // TODO?
1499 m_currentPenWidth
= m_pen
.GetWidth ();
1500 m_currentPenJoin
= m_pen
.GetJoin ();
1501 m_currentPenCap
= m_pen
.GetCap ();
1502 m_currentPenDashCount
= m_pen
.GetDashCount();
1503 m_currentPenDash
= (wxX11Dash
*)m_pen
.GetDash();
1505 if (m_currentStyle
== wxSTIPPLE
)
1506 m_currentStipple
= * m_pen
.GetStipple ();
1508 bool sameStyle
= (oldStyle
== m_currentStyle
&&
1509 oldFill
== m_currentFill
&&
1510 old_pen_join
== m_currentPenJoin
&&
1511 old_pen_cap
== m_currentPenCap
&&
1512 old_pen_nb_dash
== m_currentPenDashCount
&&
1513 old_pen_dash
== m_currentPenDash
&&
1514 old_pen_width
== m_currentPenWidth
);
1516 bool sameColour
= (oldPenColour
.Ok () &&
1517 (oldPenColour
.Red () == m_currentColour
.Red ()) &&
1518 (oldPenColour
.Blue () == m_currentColour
.Blue ()) &&
1519 (oldPenColour
.Green () == m_currentColour
.Green ()) &&
1520 (oldPenColour
.GetPixel() == m_currentColour
.GetPixel()));
1522 if (!sameStyle
|| !GET_OPTIMIZATION
)
1524 int scaled_width
= (int) XLOG2DEVREL (m_pen
.GetWidth ());
1525 if (scaled_width
< 0)
1531 static const wxX11Dash dotted
[] = {2, 5};
1532 static const wxX11Dash short_dashed
[] = {4, 4};
1533 static const wxX11Dash long_dashed
[] = {4, 8};
1534 static const wxX11Dash dotted_dashed
[] = {6, 6, 2, 6};
1536 // We express dash pattern in pen width unit, so we are
1537 // independent of zoom factor and so on...
1539 const wxX11Dash
*req_dash
;
1541 switch (m_pen
.GetStyle ())
1544 req_nb_dash
= m_currentPenDashCount
;
1545 req_dash
= m_currentPenDash
;
1546 style
= LineOnOffDash
;
1551 style
= LineOnOffDash
;
1555 req_dash
= short_dashed
;
1556 style
= LineOnOffDash
;
1560 req_dash
= long_dashed
;
1561 style
= LineOnOffDash
;
1565 req_dash
= dotted_dashed
;
1566 style
= LineOnOffDash
;
1573 req_dash
= (wxX11Dash
*)NULL
;
1577 if (req_dash
&& req_nb_dash
)
1579 wxX11Dash
*real_req_dash
= new wxX11Dash
[req_nb_dash
];
1582 int factor
= scaled_width
== 0 ? 1 : scaled_width
;
1583 for (int i
= 0; i
< req_nb_dash
; i
++)
1584 real_req_dash
[i
] = (wxX11Dash
)(req_dash
[i
] * factor
);
1585 XSetDashes ((Display
*) m_display
, (GC
) m_gc
, 0, real_req_dash
, req_nb_dash
);
1587 if (m_window
&& m_window
->GetBackingPixmap())
1588 XSetDashes ((Display
*) m_display
,(GC
) m_gcBacking
, 0, real_req_dash
, req_nb_dash
);
1589 delete[]real_req_dash
;
1593 // No Memory. We use non-scaled dash pattern...
1594 XSetDashes ((Display
*) m_display
, (GC
) m_gc
, 0, req_dash
, req_nb_dash
);
1596 if (m_window
&& m_window
->GetBackingPixmap())
1597 XSetDashes ((Display
*) m_display
,(GC
) m_gcBacking
, 0, req_dash
, req_nb_dash
);
1601 switch (m_pen
.GetCap ())
1603 case wxCAP_PROJECTING
:
1604 cap
= CapProjecting
;
1611 cap
= (scaled_width
<= 1) ? CapNotLast
: CapRound
;
1615 switch (m_pen
.GetJoin ())
1629 XSetLineAttributes ((Display
*) m_display
, (GC
) m_gc
, scaled_width
, style
, cap
, join
);
1631 if (m_window
&& m_window
->GetBackingPixmap())
1632 XSetLineAttributes ((Display
*) m_display
,(GC
) m_gcBacking
, scaled_width
, style
, cap
, join
);
1635 if (IS_HATCH(m_currentFill
) && ((m_currentFill
!= oldFill
) || !GET_OPTIMIZATION
))
1639 oldStipple
= wxNullBitmap
; // For later reset!!
1641 switch (m_currentFill
)
1643 case wxBDIAGONAL_HATCH
:
1644 if (bdiag
== (Pixmap
) 0)
1645 bdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1646 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1647 bdiag_bits
, bdiag_width
, bdiag_height
);
1650 case wxFDIAGONAL_HATCH
:
1651 if (fdiag
== (Pixmap
) 0)
1652 fdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1653 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1654 fdiag_bits
, fdiag_width
, fdiag_height
);
1658 if (cross
== (Pixmap
) 0)
1659 cross
= XCreateBitmapFromData ((Display
*) m_display
,
1660 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1661 cross_bits
, cross_width
, cross_height
);
1664 case wxHORIZONTAL_HATCH
:
1665 if (horiz
== (Pixmap
) 0)
1666 horiz
= XCreateBitmapFromData ((Display
*) m_display
,
1667 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1668 horiz_bits
, horiz_width
, horiz_height
);
1671 case wxVERTICAL_HATCH
:
1672 if (verti
== (Pixmap
) 0)
1673 verti
= XCreateBitmapFromData ((Display
*) m_display
,
1674 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1675 verti_bits
, verti_width
, verti_height
);
1678 case wxCROSSDIAG_HATCH
:
1680 if (cdiag
== (Pixmap
) 0)
1681 cdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1682 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1683 cdiag_bits
, cdiag_width
, cdiag_height
);
1687 XSetStipple ((Display
*) m_display
, (GC
) m_gc
, myStipple
);
1689 if (m_window
&& m_window
->GetBackingPixmap())
1690 XSetStipple ((Display
*) m_display
,(GC
) m_gcBacking
, myStipple
);
1692 else if (m_currentStipple
.Ok()
1693 && ((!m_currentStipple
.IsSameAs(oldStipple
)) || !GET_OPTIMIZATION
))
1695 XSetStipple ((Display
*) m_display
, (GC
) m_gc
, (Pixmap
) m_currentStipple
.GetDrawable());
1697 if (m_window
&& m_window
->GetBackingPixmap())
1698 XSetStipple ((Display
*) m_display
,(GC
) m_gcBacking
, (Pixmap
) m_currentStipple
.GetDrawable());
1701 if ((m_currentFill
!= oldFill
) || !GET_OPTIMIZATION
)
1705 if (m_currentFill
== wxSTIPPLE
)
1706 fill_style
= FillStippled
;
1707 else if (IS_HATCH (m_currentFill
))
1708 fill_style
= FillStippled
;
1710 fill_style
= FillSolid
;
1711 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, fill_style
);
1712 if (m_window
&& m_window
->GetBackingPixmap())
1713 XSetFillStyle ((Display
*) m_display
,(GC
) m_gcBacking
, fill_style
);
1716 // must test m_logicalFunction, because it involves background!
1717 if (!sameColour
|| !GET_OPTIMIZATION
1718 || ((m_logicalFunction
== wxXOR
) || (m_autoSetting
& 0x2)))
1721 if (m_pen
.GetStyle () == wxTRANSPARENT
)
1722 pixel
= m_backgroundPixel
;
1725 pixel
= CalculatePixel(m_pen
.GetColour(), m_currentColour
, false);
1728 // Finally, set the GC to the required colour
1730 SetForegroundPixelWithLogicalFunction(pixel
);
1733 m_pen
.GetColour().SetPixel(oldPenColour
.GetPixel());
1738 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1740 wxCHECK_RET( Ok(), "invalid dc" );
1744 if (!m_brush
.Ok() || m_brush
.GetStyle () == wxTRANSPARENT
)
1747 int oldFill
= m_currentFill
;
1748 wxBitmap oldStipple
= m_currentStipple
;
1750 m_autoSetting
|= 0x1;
1752 m_currentFill
= m_brush
.GetStyle ();
1753 if (m_currentFill
== wxSTIPPLE
)
1754 m_currentStipple
= * m_brush
.GetStipple ();
1756 wxColour
oldBrushColour(m_currentColour
);
1757 m_currentColour
= m_brush
.GetColour ();
1759 bool sameColour
= (oldBrushColour
.Ok () &&
1760 (oldBrushColour
.Red () == m_currentColour
.Red ()) &&
1761 (oldBrushColour
.Blue () == m_currentColour
.Blue ()) &&
1762 (oldBrushColour
.Green () == m_currentColour
.Green ()) &&
1763 (oldBrushColour
.GetPixel() == m_currentColour
.GetPixel()));
1765 int stippleDepth
= -1;
1767 if ((oldFill
!= m_brush
.GetStyle ()) || !GET_OPTIMIZATION
)
1769 switch (brush
.GetStyle ())
1774 stippleDepth
= m_currentStipple
.GetDepth();
1776 case wxBDIAGONAL_HATCH
:
1777 case wxCROSSDIAG_HATCH
:
1778 case wxFDIAGONAL_HATCH
:
1780 case wxHORIZONTAL_HATCH
:
1781 case wxVERTICAL_HATCH
:
1783 if (stippleDepth
== -1) stippleDepth
= 1;
1785 // Chris Breeze 23/07/97: use background mode to
1786 // determine whether fill style should be solid or
1788 int style
= stippleDepth
== 1 ?
1789 (m_backgroundMode
== wxSOLID
?
1790 FillOpaqueStippled
: FillStippled
) :
1792 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, style
);
1793 if (m_window
&& m_window
->GetBackingPixmap())
1794 XSetFillStyle ((Display
*) m_display
,(GC
) m_gcBacking
, style
);
1799 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, FillSolid
);
1800 if (m_window
&& m_window
->GetBackingPixmap())
1801 XSetFillStyle ((Display
*) m_display
,(GC
) m_gcBacking
,
1806 if (IS_HATCH(m_currentFill
) && ((m_currentFill
!= oldFill
) || !GET_OPTIMIZATION
))
1810 switch (m_currentFill
)
1812 case wxBDIAGONAL_HATCH
:
1813 if (bdiag
== (Pixmap
) 0)
1814 bdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1815 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1816 bdiag_bits
, bdiag_width
, bdiag_height
);
1819 case wxFDIAGONAL_HATCH
:
1820 if (fdiag
== (Pixmap
) 0)
1821 fdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1822 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1823 fdiag_bits
, fdiag_width
, fdiag_height
);
1827 if (cross
== (Pixmap
) 0)
1828 cross
= XCreateBitmapFromData ((Display
*) m_display
,
1829 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1830 cross_bits
, cross_width
, cross_height
);
1833 case wxHORIZONTAL_HATCH
:
1834 if (horiz
== (Pixmap
) 0)
1835 horiz
= XCreateBitmapFromData ((Display
*) m_display
,
1836 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1837 horiz_bits
, horiz_width
, horiz_height
);
1840 case wxVERTICAL_HATCH
:
1841 if (verti
== (Pixmap
) 0)
1842 verti
= XCreateBitmapFromData ((Display
*) m_display
,
1843 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1844 verti_bits
, verti_width
, verti_height
);
1847 case wxCROSSDIAG_HATCH
:
1849 if (cdiag
== (Pixmap
) 0)
1850 cdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1851 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1852 cdiag_bits
, cdiag_width
, cdiag_height
);
1856 XSetStipple ((Display
*) m_display
, (GC
) m_gc
, myStipple
);
1858 if (m_window
&& m_window
->GetBackingPixmap())
1859 XSetStipple ((Display
*) m_display
,(GC
) m_gcBacking
, myStipple
);
1861 // X can forget the stipple value when resizing a window (apparently)
1862 // so always set the stipple.
1863 else if (m_currentFill
!= wxSOLID
&& m_currentFill
!= wxTRANSPARENT
&&
1864 m_currentStipple
.Ok()) // && m_currentStipple != oldStipple)
1866 if (m_currentStipple
.GetDepth() == 1)
1868 XSetStipple ((Display
*) m_display
, (GC
) m_gc
,
1869 (Pixmap
) m_currentStipple
.GetDrawable());
1870 if (m_window
&& m_window
->GetBackingPixmap())
1871 XSetStipple ((Display
*) m_display
,(GC
) m_gcBacking
,
1872 (Pixmap
) m_currentStipple
.GetDrawable());
1876 XSetTile ((Display
*) m_display
, (GC
) m_gc
,
1877 (Pixmap
) m_currentStipple
.GetDrawable());
1878 if (m_window
&& m_window
->GetBackingPixmap())
1879 XSetTile ((Display
*) m_display
,(GC
) m_gcBacking
,
1880 (Pixmap
) m_currentStipple
.GetDrawable());
1884 // must test m_logicalFunction, because it involves background!
1885 if (!sameColour
|| !GET_OPTIMIZATION
|| m_logicalFunction
== wxXOR
)
1887 WXPixel pixel
= CalculatePixel(m_brush
.GetColour(), m_currentColour
, true);
1890 SetForegroundPixelWithLogicalFunction(pixel
);
1893 m_brush
.GetColour().SetPixel(oldBrushColour
.GetPixel());
1896 void wxWindowDC::SetBackground( const wxBrush
&brush
)
1898 wxCHECK_RET( Ok(), "invalid dc" );
1900 m_backgroundBrush
= brush
;
1902 if (!m_backgroundBrush
.Ok())
1905 m_backgroundPixel
= m_backgroundBrush
.GetColour().AllocColour(m_display
);
1907 // Necessary for ::DrawIcon, which use fg/bg pixel or the GC.
1908 // And Blit,... (Any fct that use XCopyPlane, in fact.)
1909 XSetBackground ((Display
*) m_display
, (GC
) m_gc
, m_backgroundPixel
);
1910 if (m_window
&& m_window
->GetBackingPixmap())
1911 XSetBackground ((Display
*) m_display
,(GC
) m_gcBacking
,
1915 void wxWindowDC::SetLogicalFunction( int function
)
1917 wxCHECK_RET( Ok(), "invalid dc" );
1922 if (m_logicalFunction
== function
)
1928 x_function
= GXclear
;
1934 x_function
= GXinvert
;
1937 x_function
= GXorReverse
;
1940 x_function
= GXandReverse
;
1949 x_function
= GXandInverted
;
1952 x_function
= GXnoop
;
1958 x_function
= GXequiv
;
1961 x_function
= GXcopyInverted
;
1964 x_function
= GXorInverted
;
1967 x_function
= GXnand
;
1974 x_function
= GXcopy
;
1978 XSetFunction((Display
*) m_display
, (GC
) m_gc
, x_function
);
1979 if (m_window
&& m_window
->GetBackingPixmap())
1980 XSetFunction((Display
*) m_display
, (GC
) m_gcBacking
, x_function
);
1982 if ((m_logicalFunction
== wxXOR
) != (function
== wxXOR
))
1983 /* MATTHEW: [9] Need to redo pen simply */
1984 m_autoSetting
|= 0x2;
1986 m_logicalFunction
= function
;
1990 void wxWindowDC::SetTextForeground( const wxColour
&col
)
1992 wxCHECK_RET( Ok(), "invalid dc" );
1994 m_textForegroundColour
= col
;
1997 void wxWindowDC::SetTextBackground( const wxColour
&col
)
1999 wxCHECK_RET( Ok(), "invalid dc" );
2001 m_textBackgroundColour
= col
;
2004 void wxWindowDC::SetBackgroundMode( int mode
)
2006 m_backgroundMode
= mode
;
2009 void wxWindowDC::SetPalette( const wxPalette
& palette
)
2014 /* Use GetXColormap */
2015 XSetWindowColormap ((Display
*) m_display
, (Window
) m_window
->GetXWindow(),
2016 (Colormap
) palette
.GetXColormap());
2018 /* Use wxGetMainColormap */
2019 XSetWindowColormap ((Display
*) m_display
, (Window
) m_window
->GetXWindow(),
2020 (Colormap
) wxTheApp
->GetMainColormap(m_display
));
2024 static void wxCopyRegion( WXRegion src
, WXRegion
& dst
)
2027 dst
= XCreateRegion();
2028 XUnionRegion( (Region
)src
, (Region
)src
, (Region
)dst
);
2031 // Helper function; userRegion is the region set by calling SetClippingRegion
2032 void wxWindowDC::SetDCClipping( WXRegion userRegion
)
2034 bool hasUpdateRegion
= m_window
&& m_window
->GetUpdateRegion().Ok();
2035 // this means that we should start the clip region from scratch,
2036 // or from the update region, if any
2040 XDestroyRegion( (Region
)m_clipRegion
);
2041 m_clipRegion
= (WXRegion
)NULL
;
2043 if( hasUpdateRegion
)
2044 wxCopyRegion( m_window
->GetUpdateRegion().GetX11Region(),
2047 // intersect the user region, if any, with the
2048 // exisiting clip region
2049 else // if( userRegion )
2052 wxCopyRegion( userRegion
, m_clipRegion
);
2054 XIntersectRegion( (Region
)m_clipRegion
,
2055 (Region
)userRegion
, (Region
)m_clipRegion
);
2059 XSetRegion( (Display
*)m_display
, (GC
)m_gc
, (Region
)m_clipRegion
);
2061 XSetClipMask( (Display
*)m_display
, (GC
)m_gc
, None
);
2064 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
,
2065 wxCoord width
, wxCoord height
)
2067 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
2069 wxRegion
temp(XLOG2DEV(x
), YLOG2DEV(y
),
2070 XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2072 SetDCClipping(temp
.GetX11Region());
2074 // Needs to work differently for Pixmap: without this,
2075 // there's a nasty (Display*) m_display bug. 8/12/94
2076 if (m_window
&& m_window
->GetBackingPixmap())
2078 XRectangle rects
[1];
2079 rects
[0].x
= (short)XLOG2DEV_2(x
);
2080 rects
[0].y
= (short)YLOG2DEV_2(y
);
2081 rects
[0].width
= (unsigned short)XLOG2DEVREL(width
);
2082 rects
[0].height
= (unsigned short)YLOG2DEVREL(height
);
2083 XSetClipRectangles((Display
*) m_display
, (GC
) m_gcBacking
,
2084 0, 0, rects
, 1, Unsorted
);
2088 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
& region
)
2090 SetDCClipping(region
.GetX11Region());
2092 // Needs to work differently for Pixmap: without this,
2093 // there's a nasty (Display*) m_display bug. 8/12/94
2094 if (m_window
&& m_window
->GetBackingPixmap())
2096 wxRect box
= region
.GetBox();
2098 XRectangle rects
[1];
2099 rects
[0].x
= (short)XLOG2DEV_2(box
.x
);
2100 rects
[0].y
= (short)YLOG2DEV_2(box
.y
);
2101 rects
[0].width
= (unsigned short)XLOG2DEVREL(box
.width
);
2102 rects
[0].height
= (unsigned short)YLOG2DEVREL(box
.height
);
2103 XSetClipRectangles((Display
*) m_display
, (GC
) m_gcBacking
,
2104 0, 0, rects
, 1, Unsorted
);
2109 void wxWindowDC::DestroyClippingRegion()
2111 wxDC::DestroyClippingRegion();
2113 SetDCClipping(NULL
);
2115 if (m_window
&& m_window
->GetBackingPixmap())
2116 XSetClipMask ((Display
*) m_display
, (GC
) m_gcBacking
, None
);
2119 // Resolution in pixels per logical inch
2120 wxSize
wxWindowDC::GetPPI() const
2123 return wxSize(100, 100);
2126 int wxWindowDC::GetDepth() const
2135 // ----------------------------------------------------------------------------
2137 // ----------------------------------------------------------------------------
2139 wxPaintDC::wxPaintDC(wxWindow
* win
) : wxWindowDC(win
)
2141 // Set the clipping region.to the update region
2142 SetDCClipping((WXRegion
)NULL
);
2145 wxPaintDC::~wxPaintDC()
2148 m_window
->ClearUpdateRegion();
2149 SetDCClipping((WXRegion
)NULL
);
2152 // ----------------------------------------------------------------------------
2153 // private functions
2154 // ----------------------------------------------------------------------------
2157 Used when copying between drawables on different (Display*) m_displays. Not
2158 very fast, but better than giving up.
2161 static void XCopyRemote(Display
*src_display
, Display
*dest_display
,
2162 Drawable src
, Drawable dest
,
2165 unsigned int w
, unsigned int h
,
2166 int destx
, int desty
,
2167 bool more
, XImage
**cache
)
2169 XImage
*image
, *destimage
;
2170 Colormap destcm
, srccm
;
2171 static const int CACHE_SIZE
= 256;
2174 Pixel cachesrc
[CACHE_SIZE
], cachedest
[CACHE_SIZE
];
2175 int k
, cache_pos
, all_cache
;
2177 if (!cache
|| !*cache
)
2178 image
= XGetImage(src_display
, src
, srcx
, srcy
, w
, h
, AllPlanes
, ZPixmap
);
2182 destimage
= XGetImage(dest_display
, dest
, destx
, desty
, w
, h
, AllPlanes
, ZPixmap
);
2184 srccm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) src_display
);
2185 destcm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dest_display
);
2190 for (i
= 0; i
< w
; i
++)
2191 for (j
= 0; j
< h
; j
++) {
2195 pixel
= XGetPixel(image
, i
, j
);
2196 for (k
= cache_pos
; k
--; )
2197 if (cachesrc
[k
] == pixel
) {
2198 pixel
= cachedest
[k
];
2202 for (k
= CACHE_SIZE
; k
-- > cache_pos
; )
2203 if (cachesrc
[k
] == pixel
) {
2204 pixel
= cachedest
[k
];
2208 cachesrc
[cache_pos
] = xcol
.pixel
= pixel
;
2209 XQueryColor(src_display
, srccm
, &xcol
);
2210 if (!XAllocColor(dest_display
, destcm
, &xcol
))
2212 cachedest
[cache_pos
] = pixel
= xcol
.pixel
;
2214 if (++cache_pos
>= CACHE_SIZE
) {
2220 XPutPixel(destimage
, i
, j
, pixel
);
2223 XPutImage(dest_display
, dest
, destgc
, destimage
, 0, 0, destx
, desty
, w
, h
);
2224 XDestroyImage(destimage
);
2229 XDestroyImage(image
);
2234 /* Helper function for 16-bit fonts */
2235 static int str16len(const char *s
)
2239 while (s
[0] && s
[1]) {