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
)
91 #define IS_HATCH(s) ((s)>=wxFIRST_HATCH && (s)<=wxLAST_HATCH)
93 // FIXME: left over after removal of wxDC::GetOptimization()
94 #define GET_OPTIMIZATION false
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 static void XCopyRemote(Display
*src_display
, Display
*dest_display
,
101 Drawable src
, Drawable dest
,
104 unsigned int w
, unsigned int h
,
105 int destx
, int desty
,
106 bool more
, XImage
**cache
);
108 // ============================================================================
110 // ============================================================================
113 * compare two doubles and return the larger rounded
116 static int roundmax(double a
, double b
)
118 return (int)((a
> b
? a
: b
) + 0.5);
122 * compare two doubles and return the smaller rounded
125 static int roundmin(double a
, double b
)
127 return (int)((a
< b
? a
: b
) - 0.5);
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 void wxWindowDC::Init()
138 m_gcBacking
= (WXGC
) 0;
140 m_backgroundPixel
= -1;
141 m_currentPenWidth
= 1;
142 m_currentPenJoin
= -1;
143 m_currentPenDashCount
= -1;
144 m_currentPenDash
= (wxX11Dash
*) NULL
;
147 m_colour
= wxColourDisplay();
148 m_display
= (WXDisplay
*) NULL
;
149 m_pixmap
= (WXPixmap
) 0;
152 m_clipRegion
= (WXRegion
) 0;
155 wxWindowDC::wxWindowDC()
160 wxWindowDC::wxWindowDC( wxWindow
*window
)
162 wxASSERT_MSG( (window
!= (wxWindow
*) NULL
), "You must pass a valid wxWindow to wxWindowDC/wxClientDC/wxPaintDC constructor." );
167 m_font
= window
->GetFont();
170 m_display
= window
->GetXDisplay();
171 m_pixmap
= window
->GetXWindow();
172 Display
* display
= (Display
*) m_display
;
174 XSetWindowColormap (display
, (Pixmap
) m_pixmap
, (Colormap
) wxTheApp
->GetMainColormap(m_display
));
177 gcvalues
.foreground
= BlackPixel (display
, DefaultScreen (display
));
178 gcvalues
.background
= WhitePixel (display
, DefaultScreen (display
));
179 gcvalues
.graphics_exposures
= False
;
180 gcvalues
.subwindow_mode
= IncludeInferiors
;
181 gcvalues
.line_width
= 1;
182 #if !wxMOTIF_NEW_FONT_HANDLING
183 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(m_userScaleY
*m_logicalScaleY
, m_display
);
184 gcvalues
.font
= ((XFontStruct
*)pFontStruct
)->fid
;
186 m_gc
= (WXGC
) XCreateGC (display
, RootWindow (display
, DefaultScreen (display
)),
187 GCForeground
| GCBackground
| GCGraphicsExposures
| GCLineWidth
| GCSubwindowMode
188 #if !wxMOTIF_NEW_FONT_HANDLING
194 if (m_window
->GetBackingPixmap())
196 m_gcBacking
= (WXGC
) XCreateGC (display
, RootWindow (display
,
197 DefaultScreen (display
)),
198 GCForeground
| GCBackground
| GCGraphicsExposures
| GCLineWidth
| GCSubwindowMode
,
202 m_backgroundPixel
= gcvalues
.background
;
204 SetBackground(wxBrush(m_window
->GetBackgroundColour(), wxSOLID
));
207 wxWindowDC::~wxWindowDC()
210 XFreeGC ((Display
*) m_display
, (GC
) m_gc
);
214 XFreeGC ((Display
*) m_display
, (GC
) m_gcBacking
);
215 m_gcBacking
= (WXGC
) 0;
218 XDestroyRegion ((Region
) m_clipRegion
);
219 m_clipRegion
= (WXRegion
) 0;
222 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
223 const wxColour
& col
, int style
);
225 bool wxWindowDC::DoFloodFill(wxCoord x
, wxCoord y
,
226 const wxColour
& col
, int style
)
228 return wxDoFloodFill(this, x
, y
, col
, style
);
231 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
233 // Generic (and therefore rather inefficient) method.
234 // Could be improved.
236 wxBitmap
bitmap(1, 1);
237 memdc
.SelectObject(bitmap
);
238 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
239 memdc
.SelectObject(wxNullBitmap
);
240 wxImage image
= bitmap
.ConvertToImage();
241 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
245 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
247 wxCHECK_RET( Ok(), "invalid dc" );
249 int x1d
, y1d
, x2d
, y2d
;
259 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, x1d
, y1d
, x2d
, y2d
);
261 if (m_window
&& m_window
->GetBackingPixmap())
262 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
263 XLOG2DEV_2(x1
), YLOG2DEV_2(y1
),
264 XLOG2DEV_2(x2
), YLOG2DEV_2(y2
));
266 CalcBoundingBox(x1
, y1
);
267 CalcBoundingBox(x2
, y2
);
270 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
272 wxCHECK_RET( Ok(), "invalid dc" );
277 int xx
= XLOG2DEV (x
);
278 int yy
= YLOG2DEV (y
);
280 wxDisplaySize (&ww
, &hh
);
281 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, 0, yy
,
283 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xx
, 0,
286 if (m_window
&& m_window
->GetBackingPixmap())
290 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
293 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
299 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
301 wxCHECK_RET( Ok(), "invalid dc" );
303 int xx1
= XLOG2DEV (x1
);
304 int yy1
= YLOG2DEV (y1
);
305 int xx2
= XLOG2DEV (x2
);
306 int yy2
= YLOG2DEV (y2
);
307 int xxc
= XLOG2DEV (xc
);
308 int yyc
= YLOG2DEV (yc
);
309 int xxc_2
= XLOG2DEV_2 (xc
);
310 int yyc_2
= YLOG2DEV_2 (yc
);
312 wxCoord dx
= xx1
- xxc
;
313 wxCoord dy
= yy1
- yyc
;
314 double radius
= sqrt ((double)(dx
* dx
+ dy
* dy
));
315 wxCoord r
= (wxCoord
) radius
;
317 double radius1
, radius2
;
319 if (xx1
== xx2
&& yy1
== yy2
)
324 else if (radius
== 0.0)
325 radius1
= radius2
= 0.0;
334 radius1
= -atan2 ((double) (yy1
- yyc
), (double) (xx1
- xxc
)) * 360.0 / (2 * M_PI
);
342 radius2
= -atan2 ((double) (yy2
- yyc
), (double) (xx2
- xxc
)) * 360.0 / (2 * M_PI
);
346 int alpha1
= (int) radius1
;
347 int alpha2
= (int) (radius2
- radius1
);
350 while (alpha2
> 360 * 64)
353 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
356 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) (GC
) m_gc
,
357 xxc
- r
, yyc
- r
, 2 * r
, 2 * r
, alpha1
, alpha2
);
359 if (m_window
&& m_window
->GetBackingPixmap())
360 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
361 xxc_2
- r
, yyc_2
- r
, 2 * r
, 2 * r
, alpha1
, alpha2
);
365 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
369 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
370 xxc
- r
, yyc
- r
, 2 * r
, 2 * r
, alpha1
, alpha2
);
372 if (m_window
&& m_window
->GetBackingPixmap())
373 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
374 xxc_2
- r
, yyc_2
- r
, 2 * r
, 2 * r
, alpha1
, alpha2
);
376 CalcBoundingBox (x1
, y1
);
377 CalcBoundingBox (x2
, y2
);
380 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
382 wxCHECK_RET( Ok(), "invalid dc" );
388 wd
= XLOG2DEVREL(width
);
389 hd
= YLOG2DEVREL(height
);
391 if (sa
>=360 || sa
<=-360) sa
=sa
-int(sa
/360)*360;
392 if (ea
>=360 || ea
<=-360) ea
=ea
-int(ea
/360)*360;
393 int start
= int(sa
*64);
394 int end
= int(ea
*64);
395 if (start
<0) start
+=360*64;
396 if (end
<0) end
+=360*64;
397 if (end
>start
) end
-=start
;
398 else end
+=360*64-start
;
400 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
402 m_autoSetting
= true; // must be reset
405 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
, start
, end
);
407 if (m_window
&& m_window
->GetBackingPixmap())
408 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
409 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),wd
,hd
,start
,end
);
412 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
416 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
, start
,end
);
417 if (m_window
&& m_window
->GetBackingPixmap())
418 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
419 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),wd
,hd
,start
,end
);
421 CalcBoundingBox (x
, y
);
422 CalcBoundingBox (x
+ width
, y
+ height
);
425 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
427 wxCHECK_RET( Ok(), "invalid dc" );
429 if (m_pen
.Ok() && m_autoSetting
)
432 XDrawPoint ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
));
433 if (m_window
&& m_window
->GetBackingPixmap())
434 XDrawPoint ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
, XLOG2DEV_2 (x
), YLOG2DEV_2 (y
));
436 CalcBoundingBox (x
, y
);
439 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
441 wxCHECK_RET( Ok(), "invalid dc" );
443 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
448 XPoint
*xpoints
= new XPoint
[n
];
451 for (i
= 0; i
< n
; i
++)
453 xpoints
[i
].x
= (short)XLOG2DEV (points
[i
].x
+ xoffset
);
454 xpoints
[i
].y
= (short)YLOG2DEV (points
[i
].y
+ yoffset
);
456 XDrawLines ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xpoints
, n
, 0);
458 if (m_window
&& m_window
->GetBackingPixmap())
460 for (i
= 0; i
< n
; i
++)
462 xpoints
[i
].x
= (short)XLOG2DEV_2 (points
[i
].x
+ xoffset
);
463 xpoints
[i
].y
= (short)YLOG2DEV_2 (points
[i
].y
+ yoffset
);
465 XDrawLines ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
, xpoints
, n
, 0);
471 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[],
472 wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
474 wxCHECK_RET( Ok(), "invalid dc" );
476 XPoint
*xpoints1
= new XPoint
[n
+ 1];
477 XPoint
*xpoints2
= new XPoint
[n
+ 1];
479 for (i
= 0; i
< n
; i
++)
481 xpoints1
[i
].x
= (short)XLOG2DEV (points
[i
].x
+ xoffset
);
482 xpoints1
[i
].y
= (short)YLOG2DEV (points
[i
].y
+ yoffset
);
483 xpoints2
[i
].x
= (short)XLOG2DEV_2 (points
[i
].x
+ xoffset
);
484 xpoints2
[i
].y
= (short)YLOG2DEV_2 (points
[i
].y
+ yoffset
);
485 CalcBoundingBox (points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
488 // Close figure for XDrawLines (not needed for XFillPolygon)
489 xpoints1
[i
].x
= xpoints1
[0].x
;
490 xpoints1
[i
].y
= xpoints1
[0].y
;
491 xpoints2
[i
].x
= xpoints2
[0].x
;
492 xpoints2
[i
].y
= xpoints2
[0].y
;
494 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
497 XSetFillRule ((Display
*) m_display
, (GC
) m_gc
, fillStyle
== wxODDEVEN_RULE
? EvenOddRule
: WindingRule
);
498 XFillPolygon ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xpoints1
, n
, Complex
, 0);
499 XSetFillRule ((Display
*) m_display
, (GC
) m_gc
, EvenOddRule
); // default mode
500 if (m_window
&& m_window
->GetBackingPixmap())
502 XSetFillRule ((Display
*) m_display
,(GC
) m_gcBacking
,
503 fillStyle
== wxODDEVEN_RULE
? EvenOddRule
: WindingRule
);
504 XFillPolygon ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
, xpoints2
, n
, Complex
, 0);
505 XSetFillRule ((Display
*) m_display
,(GC
) m_gcBacking
, EvenOddRule
); // default mode
509 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
513 XDrawLines ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xpoints1
, n
+ 1, 0);
515 if (m_window
&& m_window
->GetBackingPixmap())
516 XDrawLines ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
, xpoints2
, n
+ 1, 0);
523 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
525 wxCHECK_RET( Ok(), "invalid dc" );
527 int xd
, yd
, wfd
, hfd
, wd
, hd
;
531 wfd
= XLOG2DEVREL(width
);
533 hfd
= YLOG2DEVREL(height
);
536 if (wfd
== 0 || hfd
== 0) return;
537 if (wd
< 0) { wd
= - wd
; xd
= xd
- wd
; }
538 if (hd
< 0) { hd
= - hd
; yd
= yd
- hd
; }
540 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
543 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wfd
, hfd
);
545 if (m_window
&& m_window
->GetBackingPixmap())
546 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
547 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),
551 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
555 XDrawRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
);
557 if (m_window
&& m_window
->GetBackingPixmap())
558 XDrawRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
559 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),
562 CalcBoundingBox (x
, y
);
563 CalcBoundingBox (x
+ width
, y
+ height
);
566 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
568 wxCHECK_RET( Ok(), "invalid dc" );
570 // If radius is negative, it's a proportion of the smaller dimension.
572 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
574 int xd
= XLOG2DEV (x
);
575 int yd
= YLOG2DEV (y
);
576 int rd
= XLOG2DEVREL ((long) radius
);
577 int wd
= XLOG2DEVREL (width
) - WX_GC_CF
;
578 int hd
= YLOG2DEVREL (height
) - WX_GC_CF
;
583 // If radius is zero use DrawRectangle() instead to avoid
584 // X drawing errors with small radii
587 DrawRectangle( x
, y
, width
, height
);
591 // Draw nothing if transformed w or h is 0
592 if (wd
== 0 || hd
== 0) return;
594 // CMB: adjust size if outline is drawn otherwise the result is
595 // 1 pixel too wide and high
596 if (m_pen
.GetStyle() != wxTRANSPARENT
)
602 // CMB: ensure dd is not larger than rectangle otherwise we
603 // get an hour glass shape
604 if (rw_d
> wd
) rw_d
= wd
;
605 if (rw_d
> hd
) rw_d
= hd
;
608 // For backing pixmap
609 int xd2
= XLOG2DEV_2 (x
);
610 int yd2
= YLOG2DEV_2 (y
);
611 int rd2
= XLOG2DEVREL ((long) radius
);
612 int wd2
= XLOG2DEVREL (width
) ;
613 int hd2
= YLOG2DEVREL (height
) ;
618 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
622 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ rd
, yd
,
624 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
+ rd
,
627 // Arcs start from 3 o'clock, positive angles anticlockwise
629 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
,
630 rw_d
, rh_d
, 90 * 64, 90 * 64);
632 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
- rw_d
, yd
,
633 // rw_d, rh_d, 0, 90 * 64);
634 rw_d
, rh_d
, 0, 91 * 64);
636 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
- rw_d
,
638 // rw_d, rh_d, 270 * 64, 90 * 64);
639 rw_d
, rh_d
, 269 * 64, 92 * 64);
641 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
+ hd
- rh_d
,
642 rw_d
, rh_d
, 180 * 64, 90 * 64);
644 if (m_window
&& m_window
->GetBackingPixmap())
646 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
647 xd2
+ rd2
, yd2
, wd2
- rw_d2
, hd2
);
648 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
649 xd2
, yd2
+ rd2
, wd2
, hd2
- rh_d2
);
651 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
652 xd2
, yd2
, rw_d2
, rh_d2
, 90 * 64, 90 * 64);
653 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
654 xd2
+ wd2
- rw_d2
, yd2
,
655 // rw_d2, rh_d2, 0, 90 * 64);
656 rw_d2
, rh_d2
, 0, 91 * 64);
657 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
660 // rw_d2, rh_d2, 270 * 64, 90 * 64);
661 rw_d2
, rh_d2
, 269 * 64, 92 * 64);
662 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
663 xd2
, yd2
+ hd2
- rh_d2
,
664 rw_d2
, rh_d2
, 180 * 64, 90 * 64);
668 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
671 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ rd
, yd
,
672 xd
+ wd
- rd
+ 1, yd
);
673 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ rd
, yd
+ hd
,
674 xd
+ wd
- rd
, yd
+ hd
);
676 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
+ rd
,
678 XDrawLine ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
, yd
+ rd
,
679 xd
+ wd
, yd
+ hd
- rd
+ 1);
680 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
,
681 rw_d
, rh_d
, 90 * 64, 90 * 64);
682 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
- rw_d
, yd
,
683 // rw_d, rh_d, 0, 90 * 64);
684 rw_d
, rh_d
, 0, 91 * 64);
685 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
+ wd
- rw_d
,
687 rw_d
, rh_d
, 269 * 64, 92 * 64);
688 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
+ hd
- rh_d
,
689 rw_d
, rh_d
, 180 * 64, 90 * 64);
691 if (m_window
&& m_window
->GetBackingPixmap())
693 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
695 xd2
+ wd2
- rd2
+ 1, yd2
);
696 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
697 xd2
+ rd2
, yd2
+ hd2
,
698 xd2
+ wd2
- rd2
, yd2
+ hd2
);
700 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
702 xd2
, yd2
+ hd2
- rd2
);
703 XDrawLine ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
704 xd2
+ wd2
, yd2
+ rd2
,
705 xd2
+ wd2
, yd2
+ hd2
- rd2
+ 1);
706 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
708 rw_d2
, rh_d2
, 90 * 64, 90 * 64);
709 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
710 xd2
+ wd2
- rw_d2
, yd2
,
711 // rw_d2, rh_d2, 0, 90 * 64);
712 rw_d2
, rh_d2
, 0, 91 * 64);
713 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
716 rw_d2
, rh_d2
, 269 * 64, 92 * 64);
717 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
718 xd2
, yd2
+ hd2
- rh_d2
,
719 rw_d2
, rh_d2
, 180 * 64, 90 * 64);
722 CalcBoundingBox (x
, y
);
723 CalcBoundingBox (x
+ width
, y
+ height
);
726 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
728 wxCHECK_RET( Ok(), "invalid dc" );
730 // Check for negative width and height
743 static const int angle
= 23040;
749 wd
= XLOG2DEVREL(width
) ;
750 hd
= YLOG2DEVREL(height
) ;
752 if (m_brush
.Ok() && m_brush
.GetStyle () != wxTRANSPARENT
)
755 XFillArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
, 0, angle
);
756 if (m_window
&& m_window
->GetBackingPixmap())
757 XFillArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
758 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),
759 XLOG2DEVREL (width
) - WX_GC_CF
,
760 YLOG2DEVREL (height
) - WX_GC_CF
, 0, angle
);
763 if (m_pen
.Ok() && m_pen
.GetStyle () != wxTRANSPARENT
)
767 XDrawArc ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, xd
, yd
, wd
, hd
, 0, angle
);
768 if (m_window
&& m_window
->GetBackingPixmap())
769 XDrawArc ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
770 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
),
771 XLOG2DEVREL (width
) - WX_GC_CF
,
772 YLOG2DEVREL (height
) - WX_GC_CF
, 0, angle
);
774 CalcBoundingBox (x
, y
);
775 CalcBoundingBox (x
+ width
, y
+ height
);
779 bool wxWindowDC::CanDrawBitmap() const
781 wxCHECK_MSG( Ok(), false, "invalid dc" );
786 // TODO: use scaled Blit e.g. as per John Price's implementation
787 // in Contrib/Utilities
788 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
,
789 wxCoord width
, wxCoord height
,
790 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
791 int rop
, bool useMask
,
792 wxCoord xsrcMask
, wxCoord ysrcMask
)
794 wxCHECK_MSG( Ok(), false, "invalid dc" );
796 wxWindowDC
* sourceDC
= wxDynamicCast(source
, wxWindowDC
);
798 wxASSERT_MSG( sourceDC
, "Blit source DC must be wxWindowDC or derived class." );
800 // Be sure that foreground pixels (1) of the Icon will be painted with
801 // foreground colour. [m_textForegroundColour] Background pixels (0)
802 // will be painted with backgound colour (m_textBackgroundColour)
803 // Using ::SetPen is horribly slow, so avoid doing it
804 WXPixel oldBackgroundPixel
= -1;
805 WXPixel oldForegroundPixel
= -1;
807 if (m_textBackgroundColour
.Ok())
809 oldBackgroundPixel
= m_backgroundPixel
;
810 WXPixel pixel
= m_textBackgroundColour
.AllocColour(m_display
);
812 XSetBackground ((Display
*) m_display
, (GC
) m_gc
, pixel
);
813 if (m_window
&& m_window
->GetBackingPixmap())
814 XSetBackground ((Display
*) m_display
,(GC
) m_gcBacking
,
817 if (m_textForegroundColour
.Ok())
819 oldForegroundPixel
= m_currentColour
.GetPixel();
821 if( m_textForegroundColour
.GetPixel() <= -1 )
822 CalculatePixel( m_textForegroundColour
,
823 m_textForegroundColour
, true);
825 WXPixel pixel
= m_textForegroundColour
.GetPixel();
827 SetForegroundPixelWithLogicalFunction(pixel
);
830 // Do bitmap scaling if necessary
832 wxBitmap
*scaledBitmap
= (wxBitmap
*) NULL
;
833 Pixmap sourcePixmap
= (Pixmap
) NULL
;
834 double scaleX
, scaleY
;
835 GetUserScale(& scaleX
, & scaleY
);
838 /* TODO: use the mask origin when drawing transparently */
839 if (xsrcMask
== -1 && ysrcMask
== -1)
841 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
844 // Sorry, can't scale masks just yet
845 if (!useMask
&& (scaleX
!= 1.0 || scaleY
!= 1.0) && sourceDC
->IsKindOf(CLASSINFO(wxMemoryDC
)))
847 wxMemoryDC
* memDC
= (wxMemoryDC
*) sourceDC
;
848 wxBitmap
& bitmap
= memDC
->GetBitmap();
850 wxASSERT_MSG( (bitmap
.Ok()), "Bad source bitmap in wxWindowDC::Blit");
852 wxImage image
= bitmap
.ConvertToImage();
855 sourcePixmap
= (Pixmap
) bitmap
.GetDrawable();
859 int scaledW
= (int) (bitmap
.GetWidth() * scaleX
);
860 int scaledH
= (int) (bitmap
.GetHeight() * scaleY
);
862 image
= image
.Scale(scaledW
, scaledH
);
863 scaledBitmap
= new wxBitmap(image
);
864 sourcePixmap
= (Pixmap
) scaledBitmap
->GetDrawable();
868 sourcePixmap
= (Pixmap
) sourceDC
->m_pixmap
;
870 if (m_pixmap
&& sourcePixmap
)
873 int orig
= m_logicalFunction
;
875 SetLogicalFunction (rop
);
877 if (m_display
!= sourceDC
->m_display
)
879 XImage
*cache
= NULL
;
881 if (m_window
&& m_window
->GetBackingPixmap())
882 XCopyRemote((Display
*) sourceDC
->m_display
, (Display
*) m_display
,
883 (Pixmap
) sourcePixmap
, (Pixmap
) m_window
->GetBackingPixmap(),
885 source
->LogicalToDeviceX (xsrc
),
886 source
->LogicalToDeviceY (ysrc
),
887 source
->LogicalToDeviceXRel(width
),
888 source
->LogicalToDeviceYRel(height
),
889 XLOG2DEV_2 (xdest
), YLOG2DEV_2 (ydest
),
892 if ( useMask
&& source
->IsKindOf(CLASSINFO(wxMemoryDC
)) )
894 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
895 wxBitmap
& sel
= memDC
->GetBitmap();
896 if ( sel
.Ok() && sel
.GetMask() && sel
.GetMask()->GetBitmap() )
898 XSetClipMask ((Display
*) m_display
, (GC
) m_gc
, (Pixmap
) sel
.GetMask()->GetBitmap());
899 XSetClipOrigin ((Display
*) m_display
, (GC
) m_gc
, XLOG2DEV (xdest
), YLOG2DEV (ydest
));
903 XCopyRemote((Display
*) sourceDC
->m_display
, (Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
904 source
->LogicalToDeviceX (xsrc
),
905 source
->LogicalToDeviceY (ysrc
),
906 source
->LogicalToDeviceXRel(width
),
907 source
->LogicalToDeviceYRel(height
),
908 XLOG2DEV (xdest
), YLOG2DEV (ydest
),
914 XSetRegion ((Display
*) m_display
, (GC
) m_gc
,
915 (Region
) m_clipRegion
);
917 XSetClipMask ((Display
*) m_display
, (GC
) m_gc
, None
);
919 XSetClipOrigin ((Display
*) m_display
, (GC
) m_gc
, 0, 0);
923 { //XGCValues values;
924 //XGetGCValues((Display*)m_display, (GC)m_gc, GCForeground, &values);
926 if (m_window
&& m_window
->GetBackingPixmap())
928 // +++ MARKUS (mho@comnets.rwth-aachen): error on blitting bitmaps with depth 1
929 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)) && ((wxMemoryDC
*) source
)->GetBitmap().GetDepth() == 1)
931 XCopyPlane ((Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
932 source
->LogicalToDeviceX (xsrc
),
933 source
->LogicalToDeviceY (ysrc
),
934 source
->LogicalToDeviceXRel(width
),
935 source
->LogicalToDeviceYRel(height
),
936 XLOG2DEV_2 (xdest
), YLOG2DEV_2 (ydest
), 1);
940 XCopyArea ((Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
941 source
->LogicalToDeviceX (xsrc
),
942 source
->LogicalToDeviceY (ysrc
),
943 source
->LogicalToDeviceXRel(width
),
944 source
->LogicalToDeviceYRel(height
),
945 XLOG2DEV_2 (xdest
), YLOG2DEV_2 (ydest
));
948 if ( useMask
&& source
->IsKindOf(CLASSINFO(wxMemoryDC
)) )
950 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
951 wxBitmap
& sel
= memDC
->GetBitmap();
952 if ( sel
.Ok() && sel
.GetMask() && sel
.GetMask()->GetBitmap() )
954 XSetClipMask ((Display
*) m_display
, (GC
) m_gc
, (Pixmap
) sel
.GetMask()->GetBitmap());
955 XSetClipOrigin ((Display
*) m_display
, (GC
) m_gc
, XLOG2DEV (xdest
), YLOG2DEV (ydest
));
959 // Check if we're copying from a mono bitmap
960 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)) &&
961 ((wxMemoryDC
*)source
)->GetBitmap().Ok() && (((wxMemoryDC
*)source
)->GetBitmap().GetDepth () == 1))
963 XCopyPlane ((Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
964 source
->LogicalToDeviceX (xsrc
),
965 source
->LogicalToDeviceY (ysrc
),
966 source
->LogicalToDeviceXRel(width
),
967 source
->LogicalToDeviceYRel(height
),
968 XLOG2DEV (xdest
), YLOG2DEV (ydest
), 1);
972 XCopyArea ((Display
*) m_display
, (Pixmap
) sourcePixmap
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
973 source
->LogicalToDeviceX (xsrc
),
974 source
->LogicalToDeviceY (ysrc
),
975 source
->LogicalToDeviceXRel(width
),
976 source
->LogicalToDeviceYRel(height
),
977 XLOG2DEV (xdest
), YLOG2DEV (ydest
));
983 XSetRegion ((Display
*) m_display
, (GC
) m_gc
,
984 (Region
) m_clipRegion
);
986 XSetClipMask ((Display
*) m_display
, (GC
) m_gc
, None
);
988 XSetClipOrigin ((Display
*) m_display
, (GC
) m_gc
, 0, 0);
991 } /* Remote/local (Display*) m_display */
992 CalcBoundingBox (xdest
, ydest
);
993 CalcBoundingBox (xdest
+ width
, ydest
+ height
);
995 SetLogicalFunction(orig
);
999 if (scaledBitmap
) delete scaledBitmap
;
1001 if (oldBackgroundPixel
> -1)
1003 XSetBackground ((Display
*) m_display
, (GC
) m_gc
, oldBackgroundPixel
);
1004 if (m_window
&& m_window
->GetBackingPixmap())
1005 XSetBackground ((Display
*) m_display
,(GC
) m_gcBacking
,
1006 oldBackgroundPixel
);
1008 if (oldForegroundPixel
> -1)
1010 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, oldForegroundPixel
);
1011 if (m_window
&& m_window
->GetBackingPixmap())
1012 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
,
1013 oldForegroundPixel
);
1019 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1021 wxCHECK_RET( Ok(), "invalid dc" );
1023 // Since X draws from the baseline of the text, must add the text height
1027 int slen
= text
.length();
1029 // Set FillStyle, otherwise X will use current stipple!
1030 XGCValues gcV
, gcBackingV
;
1032 XGetGCValues ((Display
*) m_display
, (GC
)m_gc
, GCFillStyle
, &gcV
);
1033 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, FillSolid
);
1034 if (m_window
&& m_window
->GetBackingPixmap())
1036 XGetGCValues ((Display
*) m_display
, (GC
)m_gcBacking
, GCFillStyle
,
1038 XSetFillStyle ((Display
*) m_display
, (GC
) m_gcBacking
, FillSolid
);
1042 wxGetTextExtent (m_display
, m_font
, m_userScaleY
* m_logicalScaleY
,
1043 text
, &cx
, &cy
, &ascent
, NULL
);
1045 // First draw a rectangle representing the text background, if a text
1046 // background is specified
1047 if (m_textBackgroundColour
.Ok () && (m_backgroundMode
!= wxTRANSPARENT
))
1049 wxColour oldPenColour
= m_currentColour
;
1050 m_currentColour
= m_textBackgroundColour
;
1051 bool sameColour
= (oldPenColour
.Ok () && m_textBackgroundColour
.Ok () &&
1052 (oldPenColour
.Red () == m_textBackgroundColour
.Red ()) &&
1053 (oldPenColour
.Blue () == m_textBackgroundColour
.Blue ()) &&
1054 (oldPenColour
.Green () == m_textBackgroundColour
.Green ()));
1056 // This separation of the big && test required for gcc2.7/HP UX 9.02
1057 // or pixel value can be corrupted!
1058 sameColour
= (sameColour
&&
1059 (oldPenColour
.GetPixel() == m_textBackgroundColour
.GetPixel()));
1061 if (!sameColour
|| !GET_OPTIMIZATION
)
1063 WXPixel pixel
= m_textBackgroundColour
.AllocColour(m_display
);
1064 m_currentColour
= m_textBackgroundColour
;
1066 // Set the GC to the required colour
1069 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, pixel
);
1070 if (m_window
&& m_window
->GetBackingPixmap())
1071 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
, pixel
);
1075 m_textBackgroundColour
= oldPenColour
;
1077 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
), cx
, cy
);
1078 if (m_window
&& m_window
->GetBackingPixmap())
1079 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
1080 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
), cx
, cy
);
1083 // Now set the text foreground and draw the text
1084 if (m_textForegroundColour
.Ok ())
1086 wxColour oldPenColour
= m_currentColour
;
1087 m_currentColour
= m_textForegroundColour
;
1088 bool sameColour
= (oldPenColour
.Ok () && m_currentColour
.Ok () &&
1089 (oldPenColour
.Red () == m_currentColour
.Red ()) &&
1090 (oldPenColour
.Blue () == m_currentColour
.Blue ()) &&
1091 (oldPenColour
.Green () == m_currentColour
.Green ()) &&
1092 (oldPenColour
.GetPixel() == m_currentColour
.GetPixel()));
1094 if (!sameColour
|| !GET_OPTIMIZATION
)
1096 WXPixel pixel
= CalculatePixel(m_textForegroundColour
,
1097 m_currentColour
, false);
1099 // Set the GC to the required colour
1102 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, pixel
);
1103 if (m_window
&& m_window
->GetBackingPixmap())
1104 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
, pixel
);
1108 m_textForegroundColour
= oldPenColour
;
1111 // We need to add the ascent, not the whole height, since X draws at the
1112 // point above the descender.
1115 XDrawString16((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
) + ascent
,
1116 (XChar2b
*)(char*) (const char*) text
, slen
);
1119 #if wxMOTIF_NEW_FONT_HANDLING
1120 XFontSet fset
= (XFontSet
) m_font
.GetFontSet (m_userScaleY
* m_logicalScaleY
, m_display
);
1121 XmbDrawString((Display
*) m_display
, (Pixmap
) m_pixmap
, fset
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
) + ascent
, text
, slen
);
1123 XDrawString((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
, XLOG2DEV (x
), YLOG2DEV (y
) + ascent
, text
, slen
);
1126 if (m_window
&& m_window
->GetBackingPixmap()) {
1129 XDrawString16((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
1130 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
) + ascent
,
1131 (XChar2b
*)(char*) (const char*) text
, slen
);
1134 #if wxMOTIF_NEW_FONT_HANDLING
1135 XmbDrawString((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), fset
, (GC
) m_gcBacking
,
1136 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
) + ascent
,
1137 wxConstCast(text
.mb_str(), char), slen
);
1139 XDrawString((Display
*) m_display
, (Pixmap
) m_window
->GetBackingPixmap(), (GC
) m_gcBacking
,
1140 XLOG2DEV_2 (x
), YLOG2DEV_2 (y
) + ascent
,
1141 wxConstCast(text
.mb_str(), char), slen
);
1145 // restore fill style
1146 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, gcV
.fill_style
);
1147 if (m_window
&& m_window
->GetBackingPixmap())
1148 XSetFillStyle ((Display
*) m_display
, (GC
) m_gcBacking
,
1149 gcBackingV
.fill_style
);
1152 GetTextExtent (text
, &w
, &h
);
1153 CalcBoundingBox (x
+ w
, y
+ h
);
1154 CalcBoundingBox (x
, y
);
1157 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
,
1162 DrawText(text
, x
, y
);
1166 wxCHECK_RET( Ok(), "invalid dc" );
1168 WXPixel oldBackgroundPixel
= -1;
1169 WXPixel oldForegroundPixel
= -1;
1170 WXPixel foregroundPixel
= -1;
1171 WXPixel backgroundPixel
= -1;
1173 if (m_textBackgroundColour
.Ok())
1175 oldBackgroundPixel
= m_backgroundPixel
;
1176 backgroundPixel
= m_textBackgroundColour
.AllocColour(m_display
);
1178 if (m_textForegroundColour
.Ok())
1180 oldForegroundPixel
= m_currentColour
.GetPixel();
1182 if( m_textForegroundColour
.GetPixel() <= -1 )
1183 CalculatePixel( m_textForegroundColour
,
1184 m_textForegroundColour
, true);
1186 foregroundPixel
= m_textForegroundColour
.GetPixel();
1189 // Since X draws from the baseline of the text, must add the text height
1195 wxGetTextExtent (m_display
, m_font
, m_userScaleY
* m_logicalScaleY
,
1196 text
, &cx
, &cy
, &ascent
, NULL
);
1198 wxBitmap
src(cx
, cy
);
1200 dc
.SelectObject(src
);
1201 dc
.SetFont(GetFont());
1202 dc
.SetBackground(*wxWHITE_BRUSH
);
1203 dc
.SetBrush(*wxBLACK_BRUSH
);
1205 dc
.DrawText(text
, 0, 0);
1206 dc
.SetFont(wxNullFont
);
1208 // Calculate the size of the rotated bounding box.
1209 double dx
= cos(angle
/ 180.0 * M_PI
);
1210 double dy
= sin(angle
/ 180.0 * M_PI
);
1211 double x4
= cy
* dy
;
1212 double y4
= cy
* dx
;
1213 double x3
= cx
* dx
;
1214 double y3
= -cx
* dy
;
1215 double x2
= x3
+ x4
;
1216 double y2
= y3
+ y4
;
1220 // Create image from the source bitmap after writing the text into it.
1221 wxImage image
= src
.ConvertToImage();
1223 int minx
= roundmin(0, roundmin(x4
, roundmin(x2
, x3
)));
1224 int miny
= roundmin(0, roundmin(y4
, roundmin(y2
, y3
)));
1225 int maxx
= roundmax(0, roundmax(x4
, roundmax(x2
, x3
)));
1226 int maxy
= roundmax(0, roundmax(y4
, roundmax(y2
, y3
)));
1228 bool lastFore
= false, lastBack
= false;
1230 // This rotates counterclockwise around the top left corner.
1231 for (int rx
= minx
; rx
< maxx
; rx
++)
1233 for (int ry
= miny
; ry
< maxy
; ry
++)
1235 // transform dest coords to source coords
1236 int sx
= (int) (rx
* dx
- ry
* dy
+ 0.5);
1237 int sy
= - (int) (-ry
* dx
- rx
* dy
+ 0.5);
1238 if (sx
>= 0 && sx
< cx
&& sy
>= 0 && sy
< cy
)
1240 bool textPixel
= image
.GetRed(sx
, sy
) == 0;
1242 if (!textPixel
&& m_backgroundMode
!= wxSOLID
)
1245 wxCoord ox
= (wxCoord
) (x1
+ rx
),
1246 oy
= (wxCoord
) (y1
+ ry
);
1247 // draw black pixels, ignore white ones (i.e. transparent b/g)
1248 if (textPixel
&& !lastFore
)
1250 XSetForeground ((Display
*) m_display
, (GC
) m_gc
,
1255 else if (!textPixel
&& !lastBack
)
1257 XSetForeground ((Display
*) m_display
, (GC
) m_gc
,
1263 XDrawPoint ((Display
*) m_display
, (Pixmap
) m_pixmap
,
1264 (GC
) m_gc
, XLOG2DEV (ox
), YLOG2DEV (oy
));
1265 if (m_window
&& m_window
->GetBackingPixmap())
1266 XDrawPoint ((Display
*) m_display
,
1267 (Pixmap
) m_window
->GetBackingPixmap(),
1269 XLOG2DEV_2 (ox
), YLOG2DEV_2 (oy
));
1274 if (oldBackgroundPixel
> -1)
1276 XSetBackground ((Display
*) m_display
, (GC
) m_gc
, oldBackgroundPixel
);
1277 if (m_window
&& m_window
->GetBackingPixmap())
1278 XSetBackground ((Display
*) m_display
,(GC
) m_gcBacking
,
1279 oldBackgroundPixel
);
1281 if (oldForegroundPixel
> -1)
1283 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, oldForegroundPixel
);
1284 if (m_window
&& m_window
->GetBackingPixmap())
1285 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
,
1286 oldForegroundPixel
);
1289 CalcBoundingBox (minx
, miny
);
1290 CalcBoundingBox (maxx
, maxy
);
1293 bool wxWindowDC::CanGetTextExtent() const
1298 void wxWindowDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1299 wxCoord
*descent
, wxCoord
*externalLeading
,
1300 const wxFont
*font
) const
1302 wxCHECK_RET( Ok(), "invalid dc" );
1304 const wxFont
* theFont
= font
? font
: &m_font
;
1308 // TODO: this should be an error log function
1309 wxFAIL_MSG("set a valid font before calling GetTextExtent!");
1311 if (width
) *width
= -1;
1312 if (height
) *height
= -1;
1316 wxGetTextExtent(m_display
, *theFont
, m_userScaleY
* m_logicalScaleY
,
1317 string
, width
, height
, NULL
, descent
);
1319 if (width
) *width
= XDEV2LOGREL (*width
);
1320 if (height
) *height
= YDEV2LOGREL (*height
);
1321 if (externalLeading
)
1322 *externalLeading
= 0;
1325 wxCoord
wxWindowDC::GetCharWidth() const
1327 wxCHECK_MSG( Ok(), 0, "invalid dc" );
1328 wxCHECK_MSG( m_font
.Ok(), 0, "invalid font" );
1332 wxGetTextExtent (m_display
, m_font
, m_userScaleY
* m_logicalScaleY
,
1333 "x", &width
, NULL
, NULL
, NULL
);
1335 return XDEV2LOGREL(width
);
1338 wxCoord
wxWindowDC::GetCharHeight() const
1340 wxCHECK_MSG( Ok(), 0, "invalid dc" );
1341 wxCHECK_MSG( m_font
.Ok(), 0, "invalid font" );
1345 wxGetTextExtent (m_display
, m_font
, m_userScaleY
* m_logicalScaleY
,
1346 "x", NULL
, &height
, NULL
, NULL
);
1348 return XDEV2LOGREL(height
);
1351 void wxWindowDC::DoGetSize( int *width
, int *height
) const
1357 if( m_window
->GetBackingPixmap() )
1359 w
= m_window
->GetPixmapWidth();
1360 h
= m_window
->GetPixmapHeight();
1363 m_window
->GetSize( &w
, &h
);
1366 if( width
) *width
= w
;
1367 if( height
) *height
= h
;
1370 void wxWindowDC::Clear()
1372 wxCHECK_RET( Ok(), "invalid dc" );
1374 wxRect
rect( GetSize() );
1378 void wxWindowDC::Clear(const wxRect
& rect
)
1380 wxCHECK_RET( Ok(), "invalid dc" );
1382 int x
= rect
.x
; int y
= rect
.y
;
1383 int w
= rect
.width
; int h
= rect
.height
;
1385 wxBrush saveBrush
= m_brush
;
1386 SetBrush (m_backgroundBrush
);
1388 XFillRectangle ((Display
*) m_display
, (Pixmap
) m_pixmap
, (GC
) m_gc
,
1391 if (m_window
&& m_window
->GetBackingPixmap())
1392 XFillRectangle ((Display
*) m_display
,
1393 (Pixmap
) m_window
->GetBackingPixmap(),(GC
) m_gcBacking
,
1396 m_brush
= saveBrush
;
1399 void wxWindowDC::SetFont( const wxFont
&font
)
1401 wxCHECK_RET( Ok(), "invalid dc" );
1410 #if !wxMOTIF_NEW_FONT_HANDLING
1411 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(m_userScaleY
*m_logicalScaleY
, m_display
);
1413 Font fontId
= ((XFontStruct
*)pFontStruct
)->fid
;
1414 XSetFont ((Display
*) m_display
, (GC
) m_gc
, fontId
);
1416 if (m_window
&& m_window
->GetBackingPixmap())
1417 XSetFont ((Display
*) m_display
,(GC
) m_gcBacking
, fontId
);
1421 void wxWindowDC::SetForegroundPixelWithLogicalFunction(WXPixel pixel
)
1423 if (m_logicalFunction
== wxXOR
)
1426 XGetGCValues ((Display
*) m_display
, (GC
) m_gc
, GCBackground
, &values
);
1427 XSetForeground ((Display
*) m_display
, (GC
) m_gc
,
1428 pixel
^ values
.background
);
1429 if (m_window
&& m_window
->GetBackingPixmap())
1430 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
,
1431 pixel
^ values
.background
);
1435 XSetForeground ((Display
*) m_display
, (GC
) m_gc
, pixel
);
1436 if (m_window
&& m_window
->GetBackingPixmap())
1437 XSetForeground ((Display
*) m_display
,(GC
) m_gcBacking
, pixel
);
1441 WXPixel
wxWindowDC::CalculatePixel(wxColour
& colour
, wxColour
& curCol
,
1442 bool roundToWhite
) const
1444 const unsigned char wp
= (unsigned char)255;
1447 if(!m_colour
) // Mono display
1449 unsigned char red
= colour
.Red ();
1450 unsigned char blue
= colour
.Blue ();
1451 unsigned char green
= colour
.Green ();
1453 if((red
== wp
&& blue
== wp
&& green
== wp
) ||
1454 // not black and roundToWhite was specified
1455 ((red
!= 0 || blue
!= 0 || green
!= 0) && roundToWhite
))
1458 pixel
= WhitePixel((Display
*) m_display
,
1459 DefaultScreen((Display
*) m_display
));
1460 curCol
.SetPixel(pixel
);
1461 colour
.SetPixel(pixel
);
1466 pixel
= BlackPixel((Display
*) m_display
,
1467 DefaultScreen((Display
*) m_display
));
1468 curCol
.SetPixel(pixel
);
1469 colour
.SetPixel(pixel
);
1475 pixel
= colour
.AllocColour((Display
*) m_display
);
1476 curCol
.SetPixel(pixel
);
1482 void wxWindowDC::SetPen( const wxPen
&pen
)
1484 wxCHECK_RET( Ok(), "invalid dc" );
1490 wxBitmap oldStipple
= m_currentStipple
;
1491 int oldStyle
= m_currentStyle
;
1492 int oldFill
= m_currentFill
;
1493 int old_pen_width
= m_currentPenWidth
;
1494 int old_pen_join
= m_currentPenJoin
;
1495 int old_pen_cap
= m_currentPenCap
;
1496 int old_pen_nb_dash
= m_currentPenDashCount
;
1497 wxX11Dash
*old_pen_dash
= m_currentPenDash
;
1499 wxColour oldPenColour
= m_currentColour
;
1500 m_currentColour
= m_pen
.GetColour ();
1501 m_currentStyle
= m_pen
.GetStyle ();
1502 m_currentFill
= m_pen
.GetStyle (); // TODO?
1503 m_currentPenWidth
= m_pen
.GetWidth ();
1504 m_currentPenJoin
= m_pen
.GetJoin ();
1505 m_currentPenCap
= m_pen
.GetCap ();
1506 m_currentPenDashCount
= m_pen
.GetDashCount();
1507 m_currentPenDash
= (wxX11Dash
*)m_pen
.GetDash();
1509 if (m_currentStyle
== wxSTIPPLE
)
1510 m_currentStipple
= * m_pen
.GetStipple ();
1512 bool sameStyle
= (oldStyle
== m_currentStyle
&&
1513 oldFill
== m_currentFill
&&
1514 old_pen_join
== m_currentPenJoin
&&
1515 old_pen_cap
== m_currentPenCap
&&
1516 old_pen_nb_dash
== m_currentPenDashCount
&&
1517 old_pen_dash
== m_currentPenDash
&&
1518 old_pen_width
== m_currentPenWidth
);
1520 bool sameColour
= (oldPenColour
.Ok () &&
1521 (oldPenColour
.Red () == m_currentColour
.Red ()) &&
1522 (oldPenColour
.Blue () == m_currentColour
.Blue ()) &&
1523 (oldPenColour
.Green () == m_currentColour
.Green ()) &&
1524 (oldPenColour
.GetPixel() == m_currentColour
.GetPixel()));
1526 if (!sameStyle
|| !GET_OPTIMIZATION
)
1528 int scaled_width
= (int) XLOG2DEVREL (m_pen
.GetWidth ());
1529 if (scaled_width
< 0)
1535 static const wxX11Dash dotted
[] = {2, 5};
1536 static const wxX11Dash short_dashed
[] = {4, 4};
1537 static const wxX11Dash long_dashed
[] = {4, 8};
1538 static const wxX11Dash dotted_dashed
[] = {6, 6, 2, 6};
1540 // We express dash pattern in pen width unit, so we are
1541 // independent of zoom factor and so on...
1543 const wxX11Dash
*req_dash
;
1545 switch (m_pen
.GetStyle ())
1548 req_nb_dash
= m_currentPenDashCount
;
1549 req_dash
= m_currentPenDash
;
1550 style
= LineOnOffDash
;
1555 style
= LineOnOffDash
;
1559 req_dash
= short_dashed
;
1560 style
= LineOnOffDash
;
1564 req_dash
= long_dashed
;
1565 style
= LineOnOffDash
;
1569 req_dash
= dotted_dashed
;
1570 style
= LineOnOffDash
;
1577 req_dash
= (wxX11Dash
*)NULL
;
1581 if (req_dash
&& req_nb_dash
)
1583 wxX11Dash
*real_req_dash
= new wxX11Dash
[req_nb_dash
];
1586 int factor
= scaled_width
== 0 ? 1 : scaled_width
;
1587 for (int i
= 0; i
< req_nb_dash
; i
++)
1588 real_req_dash
[i
] = (wxX11Dash
)(req_dash
[i
] * factor
);
1589 XSetDashes ((Display
*) m_display
, (GC
) m_gc
, 0, real_req_dash
, req_nb_dash
);
1591 if (m_window
&& m_window
->GetBackingPixmap())
1592 XSetDashes ((Display
*) m_display
,(GC
) m_gcBacking
, 0, real_req_dash
, req_nb_dash
);
1593 delete[]real_req_dash
;
1597 // No Memory. We use non-scaled dash pattern...
1598 XSetDashes ((Display
*) m_display
, (GC
) m_gc
, 0, req_dash
, req_nb_dash
);
1600 if (m_window
&& m_window
->GetBackingPixmap())
1601 XSetDashes ((Display
*) m_display
,(GC
) m_gcBacking
, 0, req_dash
, req_nb_dash
);
1605 switch (m_pen
.GetCap ())
1607 case wxCAP_PROJECTING
:
1608 cap
= CapProjecting
;
1615 cap
= (scaled_width
<= 1) ? CapNotLast
: CapRound
;
1619 switch (m_pen
.GetJoin ())
1633 XSetLineAttributes ((Display
*) m_display
, (GC
) m_gc
, scaled_width
, style
, cap
, join
);
1635 if (m_window
&& m_window
->GetBackingPixmap())
1636 XSetLineAttributes ((Display
*) m_display
,(GC
) m_gcBacking
, scaled_width
, style
, cap
, join
);
1639 if (IS_HATCH(m_currentFill
) && ((m_currentFill
!= oldFill
) || !GET_OPTIMIZATION
))
1643 oldStipple
= wxNullBitmap
; // For later reset!!
1645 switch (m_currentFill
)
1647 case wxBDIAGONAL_HATCH
:
1648 if (bdiag
== (Pixmap
) 0)
1649 bdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1650 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1651 bdiag_bits
, bdiag_width
, bdiag_height
);
1654 case wxFDIAGONAL_HATCH
:
1655 if (fdiag
== (Pixmap
) 0)
1656 fdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1657 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1658 fdiag_bits
, fdiag_width
, fdiag_height
);
1662 if (cross
== (Pixmap
) 0)
1663 cross
= XCreateBitmapFromData ((Display
*) m_display
,
1664 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1665 cross_bits
, cross_width
, cross_height
);
1668 case wxHORIZONTAL_HATCH
:
1669 if (horiz
== (Pixmap
) 0)
1670 horiz
= XCreateBitmapFromData ((Display
*) m_display
,
1671 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1672 horiz_bits
, horiz_width
, horiz_height
);
1675 case wxVERTICAL_HATCH
:
1676 if (verti
== (Pixmap
) 0)
1677 verti
= XCreateBitmapFromData ((Display
*) m_display
,
1678 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1679 verti_bits
, verti_width
, verti_height
);
1682 case wxCROSSDIAG_HATCH
:
1684 if (cdiag
== (Pixmap
) 0)
1685 cdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1686 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1687 cdiag_bits
, cdiag_width
, cdiag_height
);
1691 XSetStipple ((Display
*) m_display
, (GC
) m_gc
, myStipple
);
1693 if (m_window
&& m_window
->GetBackingPixmap())
1694 XSetStipple ((Display
*) m_display
,(GC
) m_gcBacking
, myStipple
);
1696 else if (m_currentStyle
== wxSTIPPLE
&& m_currentStipple
.Ok()
1697 && ((!m_currentStipple
.IsSameAs(oldStipple
)) || !GET_OPTIMIZATION
))
1699 XSetStipple ((Display
*) m_display
, (GC
) m_gc
, (Pixmap
) m_currentStipple
.GetDrawable());
1701 if (m_window
&& m_window
->GetBackingPixmap())
1702 XSetStipple ((Display
*) m_display
,(GC
) m_gcBacking
, (Pixmap
) m_currentStipple
.GetDrawable());
1705 if ((m_currentFill
!= oldFill
) || !GET_OPTIMIZATION
)
1709 if (m_currentFill
== wxSTIPPLE
)
1710 fill_style
= FillStippled
;
1711 else if (IS_HATCH (m_currentFill
))
1712 fill_style
= FillStippled
;
1714 fill_style
= FillSolid
;
1715 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, fill_style
);
1716 if (m_window
&& m_window
->GetBackingPixmap())
1717 XSetFillStyle ((Display
*) m_display
,(GC
) m_gcBacking
, fill_style
);
1720 // must test m_logicalFunction, because it involves background!
1721 if (!sameColour
|| !GET_OPTIMIZATION
1722 || ((m_logicalFunction
== wxXOR
) || (m_autoSetting
& 0x2)))
1725 if (m_pen
.GetStyle () == wxTRANSPARENT
)
1726 pixel
= m_backgroundPixel
;
1729 pixel
= CalculatePixel(m_pen
.GetColour(), m_currentColour
, false);
1732 // Finally, set the GC to the required colour
1734 SetForegroundPixelWithLogicalFunction(pixel
);
1737 m_pen
.GetColour().SetPixel(oldPenColour
.GetPixel());
1742 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1744 wxCHECK_RET( Ok(), "invalid dc" );
1748 if (!m_brush
.Ok() || m_brush
.GetStyle () == wxTRANSPARENT
)
1751 int oldFill
= m_currentFill
;
1752 wxBitmap oldStipple
= m_currentStipple
;
1754 m_autoSetting
|= 0x1;
1756 m_currentFill
= m_brush
.GetStyle ();
1757 if (m_currentFill
== wxSTIPPLE
)
1758 m_currentStipple
= * m_brush
.GetStipple ();
1760 wxColour
oldBrushColour(m_currentColour
);
1761 m_currentColour
= m_brush
.GetColour ();
1763 bool sameColour
= (oldBrushColour
.Ok () &&
1764 (oldBrushColour
.Red () == m_currentColour
.Red ()) &&
1765 (oldBrushColour
.Blue () == m_currentColour
.Blue ()) &&
1766 (oldBrushColour
.Green () == m_currentColour
.Green ()) &&
1767 (oldBrushColour
.GetPixel() == m_currentColour
.GetPixel()));
1769 int stippleDepth
= -1;
1771 if ((oldFill
!= m_brush
.GetStyle ()) || !GET_OPTIMIZATION
)
1773 switch (brush
.GetStyle ())
1778 stippleDepth
= m_currentStipple
.GetDepth();
1780 case wxBDIAGONAL_HATCH
:
1781 case wxCROSSDIAG_HATCH
:
1782 case wxFDIAGONAL_HATCH
:
1784 case wxHORIZONTAL_HATCH
:
1785 case wxVERTICAL_HATCH
:
1787 if (stippleDepth
== -1) stippleDepth
= 1;
1789 // Chris Breeze 23/07/97: use background mode to
1790 // determine whether fill style should be solid or
1792 int style
= stippleDepth
== 1 ?
1793 (m_backgroundMode
== wxSOLID
?
1794 FillOpaqueStippled
: FillStippled
) :
1796 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, style
);
1797 if (m_window
&& m_window
->GetBackingPixmap())
1798 XSetFillStyle ((Display
*) m_display
,(GC
) m_gcBacking
, style
);
1803 XSetFillStyle ((Display
*) m_display
, (GC
) m_gc
, FillSolid
);
1804 if (m_window
&& m_window
->GetBackingPixmap())
1805 XSetFillStyle ((Display
*) m_display
,(GC
) m_gcBacking
,
1810 if (IS_HATCH(m_currentFill
) && ((m_currentFill
!= oldFill
) || !GET_OPTIMIZATION
))
1814 switch (m_currentFill
)
1816 case wxBDIAGONAL_HATCH
:
1817 if (bdiag
== (Pixmap
) 0)
1818 bdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1819 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1820 bdiag_bits
, bdiag_width
, bdiag_height
);
1823 case wxFDIAGONAL_HATCH
:
1824 if (fdiag
== (Pixmap
) 0)
1825 fdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1826 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1827 fdiag_bits
, fdiag_width
, fdiag_height
);
1831 if (cross
== (Pixmap
) 0)
1832 cross
= XCreateBitmapFromData ((Display
*) m_display
,
1833 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1834 cross_bits
, cross_width
, cross_height
);
1837 case wxHORIZONTAL_HATCH
:
1838 if (horiz
== (Pixmap
) 0)
1839 horiz
= XCreateBitmapFromData ((Display
*) m_display
,
1840 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1841 horiz_bits
, horiz_width
, horiz_height
);
1844 case wxVERTICAL_HATCH
:
1845 if (verti
== (Pixmap
) 0)
1846 verti
= XCreateBitmapFromData ((Display
*) m_display
,
1847 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1848 verti_bits
, verti_width
, verti_height
);
1851 case wxCROSSDIAG_HATCH
:
1853 if (cdiag
== (Pixmap
) 0)
1854 cdiag
= XCreateBitmapFromData ((Display
*) m_display
,
1855 RootWindow ((Display
*) m_display
, DefaultScreen ((Display
*) m_display
)),
1856 cdiag_bits
, cdiag_width
, cdiag_height
);
1860 XSetStipple ((Display
*) m_display
, (GC
) m_gc
, myStipple
);
1862 if (m_window
&& m_window
->GetBackingPixmap())
1863 XSetStipple ((Display
*) m_display
,(GC
) m_gcBacking
, myStipple
);
1865 // X can forget the stipple value when resizing a window (apparently)
1866 // so always set the stipple.
1867 else if (m_currentFill
!= wxSOLID
&& m_currentFill
!= wxTRANSPARENT
&&
1868 m_currentStipple
.Ok()) // && m_currentStipple != oldStipple)
1870 if (m_currentStipple
.GetDepth() == 1)
1872 XSetStipple ((Display
*) m_display
, (GC
) m_gc
,
1873 (Pixmap
) m_currentStipple
.GetDrawable());
1874 if (m_window
&& m_window
->GetBackingPixmap())
1875 XSetStipple ((Display
*) m_display
,(GC
) m_gcBacking
,
1876 (Pixmap
) m_currentStipple
.GetDrawable());
1880 XSetTile ((Display
*) m_display
, (GC
) m_gc
,
1881 (Pixmap
) m_currentStipple
.GetDrawable());
1882 if (m_window
&& m_window
->GetBackingPixmap())
1883 XSetTile ((Display
*) m_display
,(GC
) m_gcBacking
,
1884 (Pixmap
) m_currentStipple
.GetDrawable());
1888 // must test m_logicalFunction, because it involves background!
1889 if (!sameColour
|| !GET_OPTIMIZATION
|| m_logicalFunction
== wxXOR
)
1891 WXPixel pixel
= CalculatePixel(m_brush
.GetColour(), m_currentColour
, true);
1894 SetForegroundPixelWithLogicalFunction(pixel
);
1897 m_brush
.GetColour().SetPixel(oldBrushColour
.GetPixel());
1900 void wxWindowDC::SetBackground( const wxBrush
&brush
)
1902 wxCHECK_RET( Ok(), "invalid dc" );
1904 m_backgroundBrush
= brush
;
1906 if (!m_backgroundBrush
.Ok())
1909 m_backgroundPixel
= m_backgroundBrush
.GetColour().AllocColour(m_display
);
1911 // Necessary for ::DrawIcon, which use fg/bg pixel or the GC.
1912 // And Blit,... (Any fct that use XCopyPlane, in fact.)
1913 XSetBackground ((Display
*) m_display
, (GC
) m_gc
, m_backgroundPixel
);
1914 if (m_window
&& m_window
->GetBackingPixmap())
1915 XSetBackground ((Display
*) m_display
,(GC
) m_gcBacking
,
1919 void wxWindowDC::SetLogicalFunction( int function
)
1921 wxCHECK_RET( Ok(), "invalid dc" );
1926 if (m_logicalFunction
== function
)
1932 x_function
= GXclear
;
1938 x_function
= GXinvert
;
1941 x_function
= GXorReverse
;
1944 x_function
= GXandReverse
;
1953 x_function
= GXandInverted
;
1956 x_function
= GXnoop
;
1962 x_function
= GXequiv
;
1965 x_function
= GXcopyInverted
;
1968 x_function
= GXorInverted
;
1971 x_function
= GXnand
;
1978 x_function
= GXcopy
;
1982 XSetFunction((Display
*) m_display
, (GC
) m_gc
, x_function
);
1983 if (m_window
&& m_window
->GetBackingPixmap())
1984 XSetFunction((Display
*) m_display
, (GC
) m_gcBacking
, x_function
);
1986 if ((m_logicalFunction
== wxXOR
) != (function
== wxXOR
))
1987 /* MATTHEW: [9] Need to redo pen simply */
1988 m_autoSetting
|= 0x2;
1990 m_logicalFunction
= function
;
1994 void wxWindowDC::SetTextForeground( const wxColour
&col
)
1996 wxCHECK_RET( Ok(), "invalid dc" );
1998 m_textForegroundColour
= col
;
2001 void wxWindowDC::SetTextBackground( const wxColour
&col
)
2003 wxCHECK_RET( Ok(), "invalid dc" );
2005 m_textBackgroundColour
= col
;
2008 void wxWindowDC::SetBackgroundMode( int mode
)
2010 m_backgroundMode
= mode
;
2013 void wxWindowDC::SetPalette( const wxPalette
& palette
)
2018 /* Use GetXColormap */
2019 XSetWindowColormap ((Display
*) m_display
, (Window
) m_window
->GetXWindow(),
2020 (Colormap
) palette
.GetXColormap());
2022 /* Use wxGetMainColormap */
2023 XSetWindowColormap ((Display
*) m_display
, (Window
) m_window
->GetXWindow(),
2024 (Colormap
) wxTheApp
->GetMainColormap(m_display
));
2028 static void wxCopyRegion( WXRegion src
, WXRegion
& dst
)
2031 dst
= XCreateRegion();
2032 XUnionRegion( (Region
)src
, (Region
)src
, (Region
)dst
);
2035 // Helper function; userRegion is the region set by calling SetClippingRegion
2036 void wxWindowDC::SetDCClipping( WXRegion userRegion
)
2038 bool hasUpdateRegion
= m_window
&& m_window
->GetUpdateRegion().Ok();
2039 // this means that we should start the clip region from scratch,
2040 // or from the update region, if any
2044 XDestroyRegion( (Region
)m_clipRegion
);
2045 m_clipRegion
= (WXRegion
)NULL
;
2047 if( hasUpdateRegion
)
2048 wxCopyRegion( m_window
->GetUpdateRegion().GetX11Region(),
2051 // intersect the user region, if any, with the
2052 // exisiting clip region
2053 else // if( userRegion )
2056 wxCopyRegion( userRegion
, m_clipRegion
);
2058 XIntersectRegion( (Region
)m_clipRegion
,
2059 (Region
)userRegion
, (Region
)m_clipRegion
);
2063 XSetRegion( (Display
*)m_display
, (GC
)m_gc
, (Region
)m_clipRegion
);
2065 XSetClipMask( (Display
*)m_display
, (GC
)m_gc
, None
);
2068 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
,
2069 wxCoord width
, wxCoord height
)
2071 wxDC::DoSetClippingRegion( x
, y
, width
, height
);
2073 wxRegion
temp(XLOG2DEV(x
), YLOG2DEV(y
),
2074 XLOG2DEVREL(width
), YLOG2DEVREL(height
));
2076 SetDCClipping(temp
.GetX11Region());
2078 // Needs to work differently for Pixmap: without this,
2079 // there's a nasty (Display*) m_display bug. 8/12/94
2080 if (m_window
&& m_window
->GetBackingPixmap())
2082 XRectangle rects
[1];
2083 rects
[0].x
= (short)XLOG2DEV_2(x
);
2084 rects
[0].y
= (short)YLOG2DEV_2(y
);
2085 rects
[0].width
= (unsigned short)XLOG2DEVREL(width
);
2086 rects
[0].height
= (unsigned short)YLOG2DEVREL(height
);
2087 XSetClipRectangles((Display
*) m_display
, (GC
) m_gcBacking
,
2088 0, 0, rects
, 1, Unsorted
);
2092 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
& region
)
2094 SetDCClipping(region
.GetX11Region());
2096 // Needs to work differently for Pixmap: without this,
2097 // there's a nasty (Display*) m_display bug. 8/12/94
2098 if (m_window
&& m_window
->GetBackingPixmap())
2100 wxRect box
= region
.GetBox();
2102 XRectangle rects
[1];
2103 rects
[0].x
= (short)XLOG2DEV_2(box
.x
);
2104 rects
[0].y
= (short)YLOG2DEV_2(box
.y
);
2105 rects
[0].width
= (unsigned short)XLOG2DEVREL(box
.width
);
2106 rects
[0].height
= (unsigned short)YLOG2DEVREL(box
.height
);
2107 XSetClipRectangles((Display
*) m_display
, (GC
) m_gcBacking
,
2108 0, 0, rects
, 1, Unsorted
);
2113 void wxWindowDC::DestroyClippingRegion()
2115 wxDC::DestroyClippingRegion();
2117 SetDCClipping(NULL
);
2119 if (m_window
&& m_window
->GetBackingPixmap())
2120 XSetClipMask ((Display
*) m_display
, (GC
) m_gcBacking
, None
);
2123 // Resolution in pixels per logical inch
2124 wxSize
wxWindowDC::GetPPI() const
2127 return wxSize(100, 100);
2130 int wxWindowDC::GetDepth() const
2139 // ----------------------------------------------------------------------------
2141 // ----------------------------------------------------------------------------
2143 wxPaintDC::wxPaintDC(wxWindow
* win
) : wxWindowDC(win
)
2145 // Set the clipping region.to the update region
2146 SetDCClipping((WXRegion
)NULL
);
2149 wxPaintDC::~wxPaintDC()
2152 m_window
->ClearUpdateRegion();
2153 SetDCClipping((WXRegion
)NULL
);
2156 // ----------------------------------------------------------------------------
2157 // private functions
2158 // ----------------------------------------------------------------------------
2161 Used when copying between drawables on different (Display*) m_displays. Not
2162 very fast, but better than giving up.
2165 static void XCopyRemote(Display
*src_display
, Display
*dest_display
,
2166 Drawable src
, Drawable dest
,
2169 unsigned int w
, unsigned int h
,
2170 int destx
, int desty
,
2171 bool more
, XImage
**cache
)
2173 XImage
*image
, *destimage
;
2174 Colormap destcm
, srccm
;
2175 static const int CACHE_SIZE
= 256;
2178 Pixel cachesrc
[CACHE_SIZE
], cachedest
[CACHE_SIZE
];
2179 int k
, cache_pos
, all_cache
;
2181 if (!cache
|| !*cache
)
2182 image
= XGetImage(src_display
, src
, srcx
, srcy
, w
, h
, AllPlanes
, ZPixmap
);
2186 destimage
= XGetImage(dest_display
, dest
, destx
, desty
, w
, h
, AllPlanes
, ZPixmap
);
2188 srccm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) src_display
);
2189 destcm
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dest_display
);
2194 for (i
= 0; i
< w
; i
++)
2195 for (j
= 0; j
< h
; j
++) {
2199 pixel
= XGetPixel(image
, i
, j
);
2200 for (k
= cache_pos
; k
--; )
2201 if (cachesrc
[k
] == pixel
) {
2202 pixel
= cachedest
[k
];
2206 for (k
= CACHE_SIZE
; k
-- > cache_pos
; )
2207 if (cachesrc
[k
] == pixel
) {
2208 pixel
= cachedest
[k
];
2212 cachesrc
[cache_pos
] = xcol
.pixel
= pixel
;
2213 XQueryColor(src_display
, srccm
, &xcol
);
2214 if (!XAllocColor(dest_display
, destcm
, &xcol
))
2216 cachedest
[cache_pos
] = pixel
= xcol
.pixel
;
2218 if (++cache_pos
>= CACHE_SIZE
) {
2224 XPutPixel(destimage
, i
, j
, pixel
);
2227 XPutImage(dest_display
, dest
, destgc
, destimage
, 0, 0, destx
, desty
, w
, h
);
2228 XDestroyImage(destimage
);
2233 XDestroyImage(image
);
2238 /* Helper function for 16-bit fonts */
2239 static int str16len(const char *s
)
2243 while (s
[0] && s
[1]) {