1 /////////////////////////////////////////////////////////////////////////////
2 // Name: x11/dcclient.cpp
3 // Purpose: wxClientDC class
4 // Author: Julian Smart, Robert Roebling
8 // Copyright: (c) Julian Smart, Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/dcclient.h"
13 #include "wx/dcmemory.h"
14 #include "wx/window.h"
17 #include "wx/module.h"
18 #include "wx/fontutil.h"
20 #include "wx/x11/private.h"
26 #include "pango/pangox.h"
28 #include "pango/pangoxft.h"
31 #include "pango_x.cpp"
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 #define USE_PAINT_REGION 1
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
52 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
53 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
55 static Pixmap hatches
[num_hatches
];
56 static Pixmap
*hatch_bitmap
= (Pixmap
*) NULL
;
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
62 const double RAD2DEG
= 180.0 / M_PI
;
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
69 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
71 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
73 //-----------------------------------------------------------------------------
74 // Implement Pool of Graphic contexts. Creating them takes too much time.
75 //-----------------------------------------------------------------------------
77 #define GC_POOL_SIZE 200
103 static wxGC wxGCPool
[GC_POOL_SIZE
];
105 static void wxInitGCPool()
107 memset( wxGCPool
, 0, GC_POOL_SIZE
*sizeof(wxGC
) );
110 static void wxCleanUpGCPool()
112 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
114 if (wxGCPool
[i
].m_gc
)
115 XFreeGC( wxGlobalDisplay(), wxGCPool
[i
].m_gc
);
119 static GC
wxGetPoolGC( Window window
, wxPoolGCType type
)
121 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
123 if (!wxGCPool
[i
].m_gc
)
125 wxGCPool
[i
].m_gc
= XCreateGC( wxGlobalDisplay(), window
, 0, NULL
);
126 XSetGraphicsExposures( wxGlobalDisplay(), wxGCPool
[i
].m_gc
, FALSE
);
127 wxGCPool
[i
].m_type
= type
;
128 wxGCPool
[i
].m_used
= false;
130 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
132 wxGCPool
[i
].m_used
= true;
133 return wxGCPool
[i
].m_gc
;
137 wxFAIL_MSG( wxT("No GC available") );
142 static void wxFreePoolGC( GC gc
)
144 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
146 if (wxGCPool
[i
].m_gc
== gc
)
148 wxGCPool
[i
].m_used
= false;
153 wxFAIL_MSG( wxT("Wrong GC") );
156 // ----------------------------------------------------------------------------
158 // ----------------------------------------------------------------------------
160 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
162 wxWindowDC::wxWindowDC()
164 m_display
= (WXDisplay
*) NULL
;
165 m_penGC
= (WXGC
*) NULL
;
166 m_brushGC
= (WXGC
*) NULL
;
167 m_textGC
= (WXGC
*) NULL
;
168 m_bgGC
= (WXGC
*) NULL
;
169 m_cmap
= (WXColormap
*) NULL
;
171 m_isScreenDC
= false;
172 m_owner
= (wxWindow
*)NULL
;
175 m_context
= (PangoContext
*)NULL
;
176 m_fontdesc
= (PangoFontDescription
*)NULL
;
180 wxWindowDC::wxWindowDC( wxWindow
*window
)
182 wxASSERT_MSG( window
, wxT("DC needs a window") );
184 m_display
= (WXDisplay
*) NULL
;
185 m_penGC
= (WXGC
*) NULL
;
186 m_brushGC
= (WXGC
*) NULL
;
187 m_textGC
= (WXGC
*) NULL
;
188 m_bgGC
= (WXGC
*) NULL
;
189 m_cmap
= (WXColormap
*) NULL
;
190 m_owner
= (wxWindow
*)NULL
;
192 m_isScreenDC
= false;
193 m_font
= window
->GetFont();
195 m_window
= (WXWindow
*) window
->GetMainWindow();
200 // don't report problems
206 m_display
= (WXDisplay
*) wxGlobalDisplay();
209 m_context
= wxTheApp
->GetPangoContext();
210 m_fontdesc
= window
->GetFont().GetNativeFontInfo()->description
;
213 int screen
= DefaultScreen( (Display
*) m_display
);
214 m_cmap
= (WXColormap
) DefaultColormap( (Display
*) m_display
, screen
);
218 /* this must be done after SetUpDC, bacause SetUpDC calls the
219 repective SetBrush, SetPen, SetBackground etc functions
220 to set up the DC. SetBackground call m_owner->SetBackground
221 and this might not be desired as the standard dc background
222 is white whereas a window might assume gray to be the
223 standard (as e.g. wxStatusBar) */
228 wxWindowDC::~wxWindowDC()
233 void wxWindowDC::SetUpDC()
237 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
241 m_penGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxPEN_SCREEN
);
242 m_brushGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBRUSH_SCREEN
);
243 m_textGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxTEXT_SCREEN
);
244 m_bgGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBG_SCREEN
);
247 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
249 m_penGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxPEN_MONO
);
250 m_brushGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBRUSH_MONO
);
251 m_textGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxTEXT_MONO
);
252 m_bgGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBG_MONO
);
256 m_penGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxPEN_COLOUR
);
257 m_brushGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBRUSH_COLOUR
);
258 m_textGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxTEXT_COLOUR
);
259 m_bgGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBG_COLOUR
);
262 /* background colour */
263 m_backgroundBrush
= *wxWHITE_BRUSH
;
264 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
265 unsigned long bg_col
= m_backgroundBrush
.GetColour().GetPixel();
267 m_textForegroundColour
= *wxBLACK
;
268 m_textBackgroundColour
= *wxWHITE
;
271 m_textForegroundColour
.CalcPixel( m_cmap
);
272 XSetForeground( (Display
*) m_display
, (GC
) m_textGC
, m_textForegroundColour
.GetPixel() );
274 m_textBackgroundColour
.CalcPixel( m_cmap
);
275 XSetBackground( (Display
*) m_display
, (GC
) m_textGC
, m_textBackgroundColour
.GetPixel() );
277 XSetFillStyle( (Display
*) m_display
, (GC
) m_textGC
, FillSolid
);
280 // By default, draw transparently
281 GrSetGCUseBackground((GC
) m_textGC
, FALSE
);
285 m_pen
.GetColour().CalcPixel( m_cmap
);
286 XSetForeground( (Display
*) m_display
, (GC
) m_penGC
, m_pen
.GetColour().GetPixel() );
287 XSetBackground( (Display
*) m_display
, (GC
) m_penGC
, bg_col
);
289 XSetLineAttributes( (Display
*) m_display
, (GC
) m_penGC
, 0, LineSolid
, CapNotLast
, JoinRound
);
292 m_brush
.GetColour().CalcPixel( m_cmap
);
293 XSetForeground( (Display
*) m_display
, (GC
) m_brushGC
, m_brush
.GetColour().GetPixel() );
294 XSetBackground( (Display
*) m_display
, (GC
) m_brushGC
, bg_col
);
296 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillSolid
);
299 XSetForeground( (Display
*) m_display
, (GC
) m_bgGC
, bg_col
);
300 XSetBackground( (Display
*) m_display
, (GC
) m_bgGC
, bg_col
);
302 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillSolid
);
305 XSetFunction( (Display
*) m_display
, (GC
) m_textGC
, GXcopy
);
306 XSetFunction( (Display
*) m_display
, (GC
) m_brushGC
, GXcopy
);
307 XSetFunction( (Display
*) m_display
, (GC
)m_penGC
, GXcopy
);
310 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, None
);
311 XSetClipMask( (Display
*) m_display
, (GC
) m_brushGC
, None
);
312 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, None
);
313 XSetClipMask( (Display
*) m_display
, (GC
) m_bgGC
, None
);
317 int xscreen
= DefaultScreen( (Display
*) m_display
);
318 Window xroot
= RootWindow( (Display
*) m_display
, xscreen
);
320 hatch_bitmap
= hatches
;
321 hatch_bitmap
[0] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, bdiag_bits
, bdiag_width
, bdiag_height
);
322 hatch_bitmap
[1] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, cdiag_bits
, cdiag_width
, cdiag_height
);
323 hatch_bitmap
[2] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, fdiag_bits
, fdiag_width
, fdiag_height
);
324 hatch_bitmap
[3] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, cross_bits
, cross_width
, cross_height
);
325 hatch_bitmap
[4] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, horiz_bits
, horiz_width
, horiz_height
);
326 hatch_bitmap
[5] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, verti_bits
, verti_width
, verti_height
);
330 void wxWindowDC::DoGetSize( int* width
, int* height
) const
332 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
334 m_owner
->GetSize(width
, height
);
337 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
338 const wxColour
& col
, int style
);
340 bool wxWindowDC::DoFloodFill(wxCoord x
, wxCoord y
,
341 const wxColour
& col
, int style
)
343 return wxDoFloodFill(this, x
, y
, col
, style
);
346 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
348 // Generic (and therefore rather inefficient) method.
349 // Could be improved.
351 wxBitmap
bitmap(1, 1);
352 memdc
.SelectObject(bitmap
);
353 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
354 memdc
.SelectObject(wxNullBitmap
);
355 wxImage
image(bitmap
.ConvertToImage());
356 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
360 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
362 wxCHECK_RET( Ok(), wxT("invalid window dc") );
364 if (m_pen
.GetStyle() != wxTRANSPARENT
)
368 // This hack is for the iPaq: XDrawLine draws
369 // nothing, whereas XDrawLines works...
375 DrawLines( 2, points
, 0, 0 );
377 // XDrawLine( (Display*) m_display, (Window) m_window,
378 // (GC) m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) );
381 CalcBoundingBox(x1
, y1
);
382 CalcBoundingBox(x2
, y2
);
386 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
388 wxCHECK_RET( Ok(), wxT("invalid window dc") );
390 if (m_pen
.GetStyle() != wxTRANSPARENT
)
395 wxCoord xx
= XLOG2DEV(x
);
396 wxCoord yy
= YLOG2DEV(y
);
399 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
400 (GC
) m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
401 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
402 (GC
) m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
407 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
409 wxCHECK_RET( Ok(), wxT("invalid window dc") );
411 wxCoord xx1
= XLOG2DEV(x1
);
412 wxCoord yy1
= YLOG2DEV(y1
);
413 wxCoord xx2
= XLOG2DEV(x2
);
414 wxCoord yy2
= YLOG2DEV(y2
);
415 wxCoord xxc
= XLOG2DEV(xc
);
416 wxCoord yyc
= YLOG2DEV(yc
);
417 double dx
= xx1
- xxc
;
418 double dy
= yy1
- yyc
;
419 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
420 wxCoord r
= (wxCoord
)radius
;
421 double radius1
, radius2
;
423 if (xx1
== xx2
&& yy1
== yy2
)
431 radius1
= radius2
= 0.0;
435 radius1
= (xx1
- xxc
== 0) ?
436 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
437 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
438 radius2
= (xx2
- xxc
== 0) ?
439 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
440 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
442 wxCoord alpha1
= wxCoord(radius1
* 64.0);
443 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
444 while (alpha2
<= 0) alpha2
+= 360*64;
445 while (alpha1
> 360*64) alpha1
-= 360*64;
449 if (m_brush
.GetStyle() != wxTRANSPARENT
)
451 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
453 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
454 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
455 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
457 XFillArc( (Display
*) m_display
, (Window
) m_window
,
458 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
460 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
462 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
464 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
465 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
467 XFillArc( (Display
*) m_display
, (Window
) m_window
,
468 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
470 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
472 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
474 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
475 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
477 XFillArc( (Display
*) m_display
, (Window
) m_window
,
478 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
480 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
482 if (m_brush
.GetStyle() == wxSTIPPLE
)
484 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
485 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
486 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
488 XFillArc( (Display
*) m_display
, (Window
) m_window
,
489 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
491 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
495 XFillArc( (Display
*) m_display
, (Window
) m_window
,
496 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
500 if (m_pen
.GetStyle() != wxTRANSPARENT
)
502 XDrawArc( (Display
*) m_display
, (Window
) m_window
,
503 (GC
) m_penGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
505 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
506 (GC
) m_penGC
, xx1
, yy1
, xxc
, yyc
);
508 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
509 (GC
) m_penGC
, xxc
, yyc
, xx2
, yy2
);
513 CalcBoundingBox (x1
, y1
);
514 CalcBoundingBox (x2
, y2
);
517 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
519 wxCHECK_RET( Ok(), wxT("invalid window dc") );
521 wxCoord xx
= XLOG2DEV(x
);
522 wxCoord yy
= YLOG2DEV(y
);
523 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
524 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
526 // CMB: handle -ve width and/or height
527 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
528 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
532 wxCoord start
= wxCoord(sa
* 64.0);
533 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
535 if (m_brush
.GetStyle() != wxTRANSPARENT
)
537 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
539 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
540 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
541 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
543 XFillArc( (Display
*) m_display
, (Window
) m_window
,
544 (GC
) m_textGC
, xx
, yy
, ww
, hh
, start
, end
);
546 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
548 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
550 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
551 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
553 XFillArc( (Display
*) m_display
, (Window
) m_window
,
554 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, start
, end
);
556 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
558 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
560 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
561 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
563 XFillArc( (Display
*) m_display
, (Window
) m_window
,
564 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, start
, end
);
566 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
568 if (m_brush
.GetStyle() == wxSTIPPLE
)
570 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
571 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
572 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
574 XFillArc( (Display
*) m_display
, (Window
) m_window
,
575 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, start
, end
);
577 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
581 XFillArc( (Display
*) m_display
, (Window
) m_window
,
582 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, start
, end
);
586 if (m_pen
.GetStyle() != wxTRANSPARENT
)
588 XDrawArc( (Display
*) m_display
, (Window
) m_window
,
589 (GC
) m_penGC
, xx
, yy
, ww
, hh
, start
, end
);
593 CalcBoundingBox (x
, y
);
594 CalcBoundingBox (x
+ width
, y
+ height
);
597 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
599 wxCHECK_RET( Ok(), wxT("invalid window dc") );
601 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
602 XDrawPoint( (Display
*) m_display
, (Window
) m_window
,
603 (GC
) m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
605 CalcBoundingBox (x
, y
);
608 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
610 wxCHECK_RET( Ok(), wxT("invalid window dc") );
612 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
615 XPoint
*xpoints
= new XPoint
[n
];
616 for (int i
= 0; i
< n
; i
++)
618 xpoints
[i
].x
= XLOG2DEV (points
[i
].x
+ xoffset
);
619 xpoints
[i
].y
= YLOG2DEV (points
[i
].y
+ yoffset
);
621 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
623 XDrawLines( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xpoints
, n
, 0 );
628 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[],
629 wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
631 wxCHECK_RET( Ok(), wxT("invalid window dc") );
635 XPoint
*xpoints
= new XPoint
[n
+ 1];
637 for (i
= 0; i
< n
; i
++)
639 xpoints
[i
].x
= XLOG2DEV (points
[i
].x
+ xoffset
);
640 xpoints
[i
].y
= YLOG2DEV (points
[i
].y
+ yoffset
);
642 CalcBoundingBox (points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
647 if (m_brush
.GetStyle() != wxTRANSPARENT
)
650 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
652 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
653 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
654 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
656 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
657 (GC
) m_textGC
, xpoints
, n
, Complex
, 0);
659 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
661 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
663 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
664 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
666 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
667 (GC
) m_brushGC
, xpoints
, n
, Complex
, 0);
669 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
671 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
673 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
674 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
676 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
677 (GC
) m_brushGC
, xpoints
, n
, Complex
, 0);
679 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
681 if (m_brush
.GetStyle() == wxSTIPPLE
)
683 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
684 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
685 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
687 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
688 (GC
) m_brushGC
, xpoints
, n
, Complex
, 0);
690 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
694 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
695 (GC
) m_brushGC
, xpoints
, n
, Complex
, 0);
699 if (m_pen
.GetStyle () != wxTRANSPARENT
)
701 // Close figure for XDrawLines
702 xpoints
[i
].x
= xpoints
[0].x
;
703 xpoints
[i
].y
= xpoints
[0].y
;
705 XDrawLines( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xpoints
, n
+ 1, 0);
712 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
714 wxCHECK_RET( Ok(), wxT("invalid window dc") );
716 wxCoord xx
= XLOG2DEV(x
);
717 wxCoord yy
= YLOG2DEV(y
);
718 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
719 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
721 // CMB: draw nothing if transformed w or h is 0
722 if (ww
== 0 || hh
== 0) return;
724 // CMB: handle -ve width and/or height
725 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
726 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
730 if (m_brush
.GetStyle() != wxTRANSPARENT
)
732 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
734 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
735 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
736 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
738 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
739 (GC
) m_textGC
, xx
, yy
, ww
, hh
);
741 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
743 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
745 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
746 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
748 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
749 (GC
) m_brushGC
, xx
, yy
, ww
, hh
);
751 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
753 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
755 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
756 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
758 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
759 (GC
) m_brushGC
, xx
, yy
, ww
, hh
);
761 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
763 if (m_brush
.GetStyle() == wxSTIPPLE
)
765 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
766 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
767 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
769 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
770 (GC
) m_brushGC
, xx
, yy
, ww
, hh
);
772 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
776 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
777 (GC
) m_brushGC
, xx
, yy
, ww
, hh
);
781 if (m_pen
.GetStyle () != wxTRANSPARENT
)
783 XDrawRectangle( (Display
*) m_display
, (Window
) m_window
,
784 (GC
) m_penGC
, xx
, yy
, ww
-1, hh
-1 );
788 CalcBoundingBox( x
, y
);
789 CalcBoundingBox( x
+ width
, y
+ height
);
792 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
794 wxCHECK_RET( Ok(), wxT("invalid window dc") );
796 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
798 wxCoord xx
= XLOG2DEV(x
);
799 wxCoord yy
= YLOG2DEV(y
);
800 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
801 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
802 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
804 // CMB: handle -ve width and/or height
805 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
806 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
808 // CMB: if radius is zero use DrawRectangle() instead to avoid
809 // X drawing errors with small radii
812 XDrawRectangle( (Display
*) m_display
, (Window
) m_window
,
813 (GC
) m_penGC
, x
, y
, width
, height
);
817 // CMB: draw nothing if transformed w or h is 0
818 if (ww
== 0 || hh
== 0) return;
820 // CMB: adjust size if outline is drawn otherwise the result is
821 // 1 pixel too wide and high
822 if (m_pen
.GetStyle() != wxTRANSPARENT
)
830 // CMB: ensure dd is not larger than rectangle otherwise we
831 // get an hour glass shape
833 if (dd
> ww
) dd
= ww
;
834 if (dd
> hh
) dd
= hh
;
837 if (m_brush
.GetStyle() != wxTRANSPARENT
)
839 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
841 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
842 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
843 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
844 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_textGC
, xx
+rr
, yy
, ww
-dd
+1, hh
);
845 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_textGC
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
846 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_textGC
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
847 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_textGC
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
848 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_textGC
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
849 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_textGC
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
850 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0);
852 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
854 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
855 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+rr
, yy
, ww
-dd
+1, hh
);
856 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
857 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
858 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
859 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
860 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
861 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0);
863 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
865 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
866 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+rr
, yy
, ww
-dd
+1, hh
);
867 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
868 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
869 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
870 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
871 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
872 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0);
874 if (m_brush
.GetStyle() == wxSTIPPLE
)
876 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
877 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
878 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
879 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+rr
, yy
, ww
-dd
+1, hh
);
880 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
881 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
882 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
883 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
884 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
885 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0);
889 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+rr
, yy
, ww
-dd
+1, hh
);
890 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
891 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
892 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
893 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
894 XFillArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_brushGC
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
897 if (m_pen
.GetStyle() != wxTRANSPARENT
)
899 XDrawLine( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
900 XDrawLine( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xx
+rr
+1, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
901 XDrawLine( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xx
, yy
+rr
+1, xx
, yy
+hh
-rr
);
902 XDrawLine( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
903 XDrawArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
904 XDrawArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
905 XDrawArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
906 XDrawArc( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
910 // this ignores the radius
911 CalcBoundingBox( x
, y
);
912 CalcBoundingBox( x
+ width
, y
+ height
);
915 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
917 wxCHECK_RET( Ok(), wxT("invalid window dc") );
919 wxCoord xx
= XLOG2DEV(x
);
920 wxCoord yy
= YLOG2DEV(y
);
921 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
922 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
924 // CMB: handle -ve width and/or height
925 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
926 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
930 if (m_brush
.GetStyle() != wxTRANSPARENT
)
932 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
934 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
935 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
936 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
938 XFillArc( (Display
*) m_display
, (Window
) m_window
,
939 (GC
) m_textGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
941 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
943 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
945 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
946 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
948 XFillArc( (Display
*) m_display
, (Window
) m_window
,
949 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
951 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
953 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
955 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
956 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
958 XFillArc( (Display
*) m_display
, (Window
) m_window
,
959 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
961 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
963 if (m_brush
.GetStyle() == wxSTIPPLE
)
965 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
966 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
967 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
969 XFillArc( (Display
*) m_display
, (Window
) m_window
,
970 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
972 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
976 XFillArc( (Display
*) m_display
, (Window
) m_window
,
977 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
981 if (m_pen
.GetStyle () != wxTRANSPARENT
)
983 XDrawArc( (Display
*) m_display
, (Window
) m_window
,
984 (GC
) m_penGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
988 CalcBoundingBox( x
, y
);
989 CalcBoundingBox( x
+ width
, y
+ height
);
992 void wxWindowDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
994 DoDrawBitmap(icon
, x
, y
, true);
998 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
999 wxCoord x
, wxCoord y
,
1002 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1004 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
1006 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
1008 /* scale/translate size and position */
1009 int xx
= XLOG2DEV(x
);
1010 int yy
= YLOG2DEV(y
);
1012 int w
= bitmap
.GetWidth();
1013 int h
= bitmap
.GetHeight();
1015 CalcBoundingBox( x
, y
);
1016 CalcBoundingBox( x
+ w
, y
+ h
);
1018 if (!m_window
) return;
1020 int ww
= XLOG2DEVREL(w
);
1021 int hh
= YLOG2DEVREL(h
);
1023 /* compare to current clipping region */
1024 if (!m_currentClippingRegion
.IsNull())
1026 wxRegion
tmp( xx
,yy
,ww
,hh
);
1027 tmp
.Intersect( m_currentClippingRegion
);
1032 /* scale bitmap if required */
1033 wxBitmap use_bitmap
;
1034 if ((w
!= ww
) || (h
!= hh
))
1036 wxImage
image( bitmap
.ConvertToImage() );
1037 image
.Rescale( ww
, hh
);
1040 use_bitmap
= image
.ConvertToMonoBitmap(255,255,255);
1047 use_bitmap
= bitmap
;
1050 /* apply mask if any */
1051 WXPixmap mask
= NULL
;
1052 if (use_bitmap
.GetMask())
1053 mask
= use_bitmap
.GetMask()->GetBitmap();
1055 if (useMask
&& mask
)
1057 Pixmap pixmap
= (Pixmap
) use_bitmap
.GetPixmap() ;
1058 Pixmap maskPixmap
= (Pixmap
) use_bitmap
.GetMask()->GetBitmap() ;
1059 Pixmap bufPixmap
= GrNewPixmap(w
, h
, 0);
1061 GrSetGCUseBackground(gc
, FALSE
);
1062 GrSetGCMode(gc
, GR_MODE_COPY
);
1064 // This code assumes that background and foreground
1065 // colours are used in ROPs, like in MSW.
1066 // Not sure if this is true.
1068 // Copy destination to buffer.
1069 // In DoBlit, we need this step because Blit has
1070 // a ROP argument. Here, we don't need it.
1071 // In DoBlit, we may be able to eliminate this step
1072 // if we check if the rop = copy
1074 GrCopyArea(bufPixmap
, gc
, 0, 0, w
, h
, (Window
) m_window
,
1075 0, 0, GR_MODE_COPY
);
1078 // Copy src to buffer using selected raster op (none selected
1079 // in DrawBitmap, so just use Gxcopy)
1080 GrCopyArea(bufPixmap
, gc
, 0, 0, w
, h
, pixmap
,
1081 0, 0, GR_MODE_COPY
);
1083 // Set masked area in buffer to BLACK (pixel value 0)
1084 GrSetGCBackground(gc
, WHITE
);
1085 GrSetGCForeground(gc
, BLACK
);
1086 GrCopyArea(bufPixmap
, gc
, 0, 0, w
, h
, maskPixmap
,
1089 // set unmasked area in dest to BLACK
1090 GrSetGCBackground(gc
, BLACK
);
1091 GrSetGCForeground(gc
, WHITE
);
1092 GrCopyArea((Window
) m_window
, gc
, xx
, yy
, w
, h
, maskPixmap
,
1095 // OR buffer to dest
1096 GrCopyArea((Window
) m_window
, gc
, xx
, yy
, w
, h
, bufPixmap
,
1100 GrDestroyWindow(bufPixmap
);
1103 XCopyArea( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetPixmap(), (Window
) m_window
,
1104 (GC
) m_penGC
, 0, 0, w
, h
, xx
, yy
);
1106 /* remove mask again if any */
1107 if (useMask
&& mask
)
1109 if (!m_currentClippingRegion
.IsNull())
1110 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1117 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
1118 wxCoord x
, wxCoord y
,
1121 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1123 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
1125 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
1127 // scale/translate size and position
1128 int xx
= XLOG2DEV(x
);
1129 int yy
= YLOG2DEV(y
);
1131 int w
= bitmap
.GetWidth();
1132 int h
= bitmap
.GetHeight();
1134 CalcBoundingBox( x
, y
);
1135 CalcBoundingBox( x
+ w
, y
+ h
);
1137 if (!m_window
) return;
1139 int ww
= XLOG2DEVREL(w
);
1140 int hh
= YLOG2DEVREL(h
);
1142 // compare to current clipping region
1143 if (!m_currentClippingRegion
.IsNull())
1145 wxRegion
tmp( xx
,yy
,ww
,hh
);
1146 tmp
.Intersect( m_currentClippingRegion
);
1151 // scale bitmap if required
1152 wxBitmap use_bitmap
;
1153 if ((w
!= ww
) || (h
!= hh
))
1155 wxImage
image( bitmap
.ConvertToImage() );
1156 image
.Rescale( ww
, hh
);
1159 use_bitmap
= image
.ConvertToMonoBitmap(255,255,255);
1166 use_bitmap
= bitmap
;
1169 // apply mask if any
1170 WXPixmap mask
= NULL
;
1171 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1173 bool setClipMask
= false;
1175 if (!m_currentClippingRegion
.IsNull() || (useMask
&& mask
))
1177 // XSetClipMask() call is necessary (because of clip region and/or transparent mask)
1179 Pixmap new_pixmap
= 0;
1181 if (!m_currentClippingRegion
.IsNull())
1183 // clipping necessary => create new_pixmap
1184 Display
*xdisplay
= (Display
*) m_display
;
1185 int xscreen
= DefaultScreen( xdisplay
);
1186 Window xroot
= RootWindow( xdisplay
, xscreen
);
1188 new_pixmap
= XCreatePixmap( xdisplay
, xroot
, ww
, hh
, 1 );
1189 GC gc
= XCreateGC( xdisplay
, new_pixmap
, 0, NULL
);
1191 int bpp
= wxTheApp
->GetVisualInfo(m_display
)->m_visualDepth
;
1193 XSetForeground( xdisplay
, gc
, WhitePixel(xdisplay
,xscreen
) );
1195 XSetForeground( xdisplay
, gc
, BlackPixel(xdisplay
,xscreen
) );
1197 XSetFillStyle( xdisplay
, gc
, FillSolid
);
1198 XFillRectangle( xdisplay
, new_pixmap
, gc
, 0, 0, ww
, hh
);
1201 XSetForeground( xdisplay
, gc
, BlackPixel(xdisplay
,xscreen
) );
1203 XSetForeground( xdisplay
, gc
, WhitePixel(xdisplay
,xscreen
) );
1205 if (useMask
&& mask
)
1207 // transparent mask => call XSetStipple
1208 XSetFillStyle( xdisplay
, gc
, FillStippled
);
1209 XSetTSOrigin( xdisplay
, gc
, 0, 0);
1210 XSetStipple( xdisplay
, gc
, (Pixmap
) mask
);
1213 wxCoord clip_x
, clip_y
, clip_w
, clip_h
;
1214 m_currentClippingRegion
.GetBox(clip_x
, clip_y
, clip_w
, clip_h
);
1215 XFillRectangle( xdisplay
, new_pixmap
, gc
, clip_x
-xx
, clip_y
-yy
, clip_w
, clip_h
);
1217 XFreeGC( xdisplay
, gc
);
1223 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, new_pixmap
);
1225 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) mask
);
1226 XSetClipOrigin( (Display
*) m_display
, (GC
) m_textGC
, xx
, yy
);
1231 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, new_pixmap
);
1233 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, (Pixmap
) mask
);
1234 XSetClipOrigin( (Display
*) m_display
, (GC
) m_penGC
, xx
, yy
);
1238 XFreePixmap( (Display
*) m_display
, new_pixmap
);
1241 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1242 // drawing a mono-bitmap (XBitmap) we use the current text GC
1244 XCopyPlane( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetBitmap(), (Window
) m_window
,
1245 (GC
) m_textGC
, 0, 0, ww
, hh
, xx
, yy
, 1 );
1247 XCopyArea( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetPixmap(), (Window
) m_window
,
1248 (GC
) m_penGC
, 0, 0, ww
, hh
, xx
, yy
);
1250 // remove mask again if any
1255 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, None
);
1256 XSetClipOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
1257 if (!m_currentClippingRegion
.IsNull())
1258 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1262 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, None
);
1263 XSetClipOrigin( (Display
*) m_display
, (GC
) m_penGC
, 0, 0 );
1264 if (!m_currentClippingRegion
.IsNull())
1265 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1270 // wxUSE_NANOX/!wxUSE_NANOX
1272 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1273 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1274 wxCoord xsrcMask
, wxCoord ysrcMask
)
1276 /* this is the nth try to get this utterly useless function to
1277 work. it now completely ignores the scaling or translation
1278 of the source dc, but scales correctly on the target dc and
1279 knows about possible mask information in a memory dc. */
1281 wxCHECK_MSG( Ok(), false, wxT("invalid window dc") );
1283 wxCHECK_MSG( source
, false, wxT("invalid source dc") );
1285 if (!m_window
) return false;
1287 // transform the source DC coords to the device ones
1288 xsrc
= source
->XLOG2DEV(xsrc
);
1289 ysrc
= source
->YLOG2DEV(ysrc
);
1291 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1292 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
1294 bool use_bitmap_method
= false;
1295 bool is_mono
= false;
1297 // TODO: use the mask origin when drawing transparently
1298 if (xsrcMask
== -1 && ysrcMask
== -1)
1304 if (srcDC
->m_isMemDC
)
1306 if (!memDC
->m_selected
.Ok()) return false;
1308 /* we use the "XCopyArea" way to copy a memory dc into
1309 y different window if the memory dc BOTH
1310 a) doesn't have any mask or its mask isn't used
1314 if (useMask
&& (memDC
->m_selected
.GetMask()))
1316 /* we HAVE TO use the direct way for memory dcs
1317 that have mask since the XCopyArea doesn't know
1319 use_bitmap_method
= true;
1321 else if (memDC
->m_selected
.GetDepth() == 1)
1323 /* we HAVE TO use the direct way for memory dcs
1324 that are bitmaps because XCopyArea doesn't cope
1325 with different bit depths */
1327 use_bitmap_method
= true;
1329 else if ((xsrc
== 0) && (ysrc
== 0) &&
1330 (width
== memDC
->m_selected
.GetWidth()) &&
1331 (height
== memDC
->m_selected
.GetHeight()))
1333 /* we SHOULD use the direct way if all of the bitmap
1334 in the memory dc is copied in which case XCopyArea
1335 wouldn't be able able to boost performace by reducing
1336 the area to be scaled */
1337 use_bitmap_method
= true;
1341 use_bitmap_method
= false;
1345 CalcBoundingBox( xdest
, ydest
);
1346 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1348 // scale/translate size and position
1349 wxCoord xx
= XLOG2DEV(xdest
);
1350 wxCoord yy
= YLOG2DEV(ydest
);
1352 wxCoord ww
= XLOG2DEVREL(width
);
1353 wxCoord hh
= YLOG2DEVREL(height
);
1355 // compare to current clipping region
1356 if (!m_currentClippingRegion
.IsNull())
1358 wxRegion
tmp( xx
,yy
,ww
,hh
);
1359 tmp
.Intersect( m_currentClippingRegion
);
1364 int old_logical_func
= m_logicalFunction
;
1365 SetLogicalFunction( logical_func
);
1367 if (use_bitmap_method
)
1369 // scale/translate bitmap size
1370 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1371 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1373 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1374 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1376 // scale bitmap if required
1377 wxBitmap use_bitmap
;
1379 if ((bm_width
!= bm_ww
) || (bm_height
!= bm_hh
))
1381 wxImage
image( memDC
->m_selected
.ConvertToImage() );
1382 image
= image
.Scale( bm_ww
, bm_hh
);
1386 use_bitmap
= image
.ConvertToMonoBitmap(255,255,255);
1393 use_bitmap
= memDC
->m_selected
;
1396 // apply mask if any
1397 WXPixmap mask
= NULL
;
1398 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1400 if (useMask
&& mask
)
1402 WXPixmap new_mask
= NULL
;
1404 if (!m_currentClippingRegion
.IsNull())
1407 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1408 GdkGC
*gc
= gdk_gc_new( new_mask
);
1410 gdk_gc_set_foreground( gc
, &col
);
1411 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1413 gdk_gc_set_background( gc
, &col
);
1415 gdk_gc_set_foreground( gc
, &col
);
1416 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1417 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1418 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1419 gdk_gc_set_stipple( gc
, mask
);
1420 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1427 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) new_mask
);
1429 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) mask
);
1430 XSetClipOrigin( (Display
*) m_display
, (GC
) m_textGC
, xx
, yy
);
1435 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, (Pixmap
) new_mask
);
1437 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, (Pixmap
) mask
);
1438 XSetClipOrigin( (Display
*) m_display
, (GC
) m_penGC
, xx
, yy
);
1442 XFreePixmap( (Display
*) m_display
, (Pixmap
) new_mask
);
1445 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1446 // drawing a mono-bitmap (XBitmap) we use the current text GC
1449 XCopyPlane( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetBitmap(), (Window
) m_window
,
1450 (GC
) m_textGC
, xsrc
, ysrc
, width
, height
, xx
, yy
, 1 );
1452 XCopyArea( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetPixmap(), (Window
) m_window
,
1453 (GC
) m_penGC
, xsrc
, ysrc
, width
, height
, xx
, yy
);
1455 // remove mask again if any
1456 if (useMask
&& mask
)
1460 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, None
);
1461 XSetClipOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
1462 if (!m_currentClippingRegion
.IsNull())
1463 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1467 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, None
);
1468 XSetClipOrigin( (Display
*) m_display
, (GC
) m_penGC
, 0, 0 );
1469 if (!m_currentClippingRegion
.IsNull())
1470 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1474 else // use_bitmap_method
1476 if ((width
!= ww
) || (height
!= hh
))
1478 /* Draw source window into a bitmap as we cannot scale
1479 a window in contrast to a bitmap. this would actually
1480 work with memory dcs as well, but we'd lose the mask
1481 information and waste one step in this process since
1482 a memory already has a bitmap. all this is slightly
1483 inefficient as we could take an XImage directly from
1484 an X window, but we'd then also have to care that
1485 the window is not outside the screen (in which case
1486 we'd get a BadMatch or what not).
1487 Is a double XGetImage and combined XGetPixel and
1488 XPutPixel really faster? I'm not sure. look at wxXt
1489 for a different implementation of the same problem. */
1491 wxBitmap
bitmap( width
, height
);
1493 // copy including child window contents
1494 XSetSubwindowMode( (Display
*) m_display
, (GC
) m_penGC
, IncludeInferiors
);
1495 XCopyArea( (Display
*) m_display
, (Window
) srcDC
->GetWindow(), (Window
) bitmap
.GetPixmap(),
1496 (GC
) m_penGC
, xsrc
, ysrc
, width
, height
, 0, 0 );
1497 XSetSubwindowMode( (Display
*) m_display
, (GC
) m_penGC
, ClipByChildren
);
1500 wxImage
image( bitmap
.ConvertToImage() );
1501 image
= image
.Scale( ww
, hh
);
1503 // convert to bitmap
1506 // draw scaled bitmap
1507 XCopyArea( (Display
*) m_display
, (Window
) bitmap
.GetPixmap(), (Window
) m_window
,
1508 (GC
) m_penGC
, 0, 0, width
, height
, xx
, yy
);
1512 // No scaling and not a memory dc with a mask either
1514 // copy including child window contents
1515 XSetSubwindowMode( (Display
*) m_display
, (GC
) m_penGC
, IncludeInferiors
);
1516 XCopyArea( (Display
*) m_display
, (Window
) srcDC
->GetWindow(), (Window
) m_window
,
1517 (GC
) m_penGC
, xsrc
, ysrc
, width
, height
, xx
, yy
);
1518 XSetSubwindowMode( (Display
*) m_display
, (GC
) m_penGC
, ClipByChildren
);
1522 SetLogicalFunction( old_logical_func
);
1527 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1529 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1531 if (!m_window
) return;
1537 PangoLayout
*layout
= pango_layout_new(m_context
);
1538 pango_layout_set_font_description(layout
, m_fontdesc
);
1540 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( text
);
1541 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1545 pango_layout_get_pixel_size(layout
, &w
, &h
);
1550 x11_draw_layout( (Drawable
) m_window
, (GC
) m_textGC
, x
, y
, layout
, m_textForegroundColour
);
1552 g_object_unref( G_OBJECT( layout
) );
1554 CalcBoundingBox (x
+ width
, y
+ height
);
1555 CalcBoundingBox (x
, y
);
1557 XFontStruct
*xfont
= (XFontStruct
*) m_font
.GetFontStruct( m_scaleY
, m_display
);
1559 wxCHECK_RET( xfont
, wxT("invalid font") );
1561 // First draw a rectangle representing the text background, if a text
1562 // background is specified
1563 if (m_textBackgroundColour
.Ok () && (m_backgroundMode
!= wxTRANSPARENT
))
1565 // Since X draws from the baseline of the text, must add the text height
1570 int direction
, descent
;
1572 slen
= strlen(text
);
1573 XCharStruct overall_return
;
1575 (void)XTextExtents(xfont
, (char*) text
.c_str(), slen
, &direction
,
1576 &ascent
, &descent
, &overall_return
);
1578 cx
= overall_return
.width
;
1579 cy
= ascent
+ descent
;
1580 m_textBackgroundColour
.CalcPixel(m_cmap
);
1581 m_textForegroundColour
.CalcPixel(m_cmap
);
1582 XSetForeground ((Display
*) m_display
, (GC
) m_textGC
, m_textBackgroundColour
.GetPixel());
1583 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
1584 (GC
) m_textGC
, x
, y
, cx
, cy
);
1585 XSetForeground ((Display
*) m_display
, (GC
) m_textGC
, m_textForegroundColour
.GetPixel());
1589 XSetFont( (Display
*) m_display
, (GC
) m_textGC
, xfont
->fid
);
1591 // This may be a test for whether the font is 16-bit, but it also
1592 // seems to fail for valid 8-bit fonts too.
1593 if (1) // (xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
1596 XDrawString( (Display
*) m_display
, (Window
) m_window
,
1597 (GC
) m_textGC
, x
, y
+ XFontStructGetAscent(xfont
), text
.c_str(), text
.Len() );
1601 if (m_font
.GetUnderlined())
1603 wxCoord ul_y
= y
+ XFontStructGetAscent(font
);
1604 if (font
->descent
> 0) ul_y
++;
1605 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
1608 width
= wxCoord(width
/ m_scaleX
);
1609 height
= wxCoord(height
/ m_scaleY
);
1611 CalcBoundingBox (x
+ width
, y
+ height
);
1612 CalcBoundingBox (x
, y
);
1617 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1622 void wxWindowDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1623 wxCoord
*descent
, wxCoord
*externalLeading
,
1624 wxFont
*font
) const
1626 wxCHECK_RET( Ok(), wxT("invalid dc") );
1630 if (width
) (*width
) = 0;
1631 if (height
) (*height
) = 0;
1636 PangoLayout
*layout
= pango_layout_new( m_context
);
1639 pango_layout_set_font_description( layout
, font
->GetNativeFontInfo()->description
);
1641 pango_layout_set_font_description(layout
, m_fontdesc
);
1643 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1644 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1648 pango_layout_get_pixel_size(layout
, &w
, &h
);
1650 if (width
) (*width
) = (wxCoord
) w
;
1651 if (height
) (*height
) = (wxCoord
) h
;
1654 // Do something about metrics here. TODO.
1657 if (externalLeading
) (*externalLeading
) = 0; // ??
1659 g_object_unref( G_OBJECT( layout
) );
1661 wxFont fontToUse
= m_font
;
1662 if (font
) fontToUse
= *font
;
1664 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1666 XFontStruct
*xfont
= (XFontStruct
*) fontToUse
.GetFontStruct( m_scaleY
, m_display
);
1668 wxCHECK_RET( xfont
, wxT("invalid font") );
1670 int direction
, ascent
, descent2
;
1671 XCharStruct overall
;
1673 XTextExtents( xfont
, (char*) string
.c_str(), string
.Len(), &direction
,
1674 &ascent
, &descent2
, &overall
);
1677 *width
= (wxCoord
)( overall
.width
/ m_scaleX
);
1679 *height
= (wxCoord
)((ascent
+ descent2
) / m_scaleY
);
1681 *descent
= (wxCoord
)(descent2
/ m_scaleY
);
1682 if (externalLeading
)
1683 *externalLeading
= 0; // ??
1687 wxCoord
wxWindowDC::GetCharWidth() const
1689 wxCHECK_MSG( Ok(), 0, wxT("invalid dc") );
1692 PangoLayout
*layout
= pango_layout_new( m_context
);
1695 pango_layout_set_font_description(layout
, m_fontdesc
);
1697 pango_layout_set_font_description(layout
, this->GetFont().GetNativeFontInfo()->description
);
1699 pango_layout_set_text(layout
, "H", 1 );
1701 pango_layout_get_pixel_size(layout
, &w
, &h
);
1702 g_object_unref( G_OBJECT( layout
) );
1706 wxCHECK_MSG( m_font
.Ok(), 0, wxT("invalid font") );
1708 XFontStruct
*xfont
= (XFontStruct
*) m_font
.GetFontStruct( m_scaleY
, m_display
);
1710 wxCHECK_MSG( xfont
, 0, wxT("invalid font") );
1712 int direction
, ascent
, descent
;
1713 XCharStruct overall
;
1715 XTextExtents( xfont
, "H", 1, &direction
, &ascent
, &descent
, &overall
);
1717 return (wxCoord
)(overall
.width
/ m_scaleX
);
1721 wxCoord
wxWindowDC::GetCharHeight() const
1723 wxCHECK_MSG( Ok(), 0, wxT("invalid dc") );
1726 PangoLayout
*layout
= pango_layout_new( m_context
);
1729 pango_layout_set_font_description(layout
, m_fontdesc
);
1731 pango_layout_set_font_description(layout
, this->GetFont().GetNativeFontInfo()->description
);
1733 pango_layout_set_text(layout
, "H", 1 );
1735 pango_layout_get_pixel_size(layout
, &w
, &h
);
1736 g_object_unref( G_OBJECT( layout
) );
1740 wxCHECK_MSG( m_font
.Ok(), 0, wxT("invalid font") );
1742 XFontStruct
*xfont
= (XFontStruct
*) m_font
.GetFontStruct( m_scaleY
, m_display
);
1744 wxCHECK_MSG( xfont
, 0, wxT("invalid font") );
1746 int direction
, ascent
, descent
;
1747 XCharStruct overall
;
1749 XTextExtents( xfont
, "H", 1, &direction
, &ascent
, &descent
, &overall
);
1751 return (wxCoord
)((ascent
+descent
) / m_scaleY
);
1755 void wxWindowDC::Clear()
1757 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1759 if (!m_window
) return;
1761 /* - we either are a memory dc or have a window as the
1762 owner. anything else shouldn't happen.
1763 - we don't use gdk_window_clear() as we don't set
1764 the window's background colour anymore. it is too
1765 much pain to keep the DC's and the window's back-
1766 ground colour in synch. */
1771 m_owner
->GetSize( &width
, &height
);
1772 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_bgGC
, 0, 0, width
, height
);
1779 GetSize( &width
, &height
);
1780 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_bgGC
, 0, 0, width
, height
);
1785 void wxWindowDC::SetFont( const wxFont
&font
)
1787 wxCHECK_RET( Ok(), wxT("invalid dc") );
1794 m_fontdesc
= font
.GetNativeFontInfo()->description
;
1798 void wxWindowDC::SetPen( const wxPen
&pen
)
1800 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1802 if (m_pen
== pen
) return;
1806 if (!m_pen
.Ok()) return;
1808 if (!m_window
) return;
1810 int width
= m_pen
.GetWidth();
1813 // CMB: if width is non-zero scale it with the dc
1818 // X doesn't allow different width in x and y and so we take
1821 ( fabs((double) XLOG2DEVREL(width
)) +
1822 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1826 static const wxX11Dash dotted
[] = {1, 1};
1827 static const wxX11Dash short_dashed
[] = {2, 2};
1828 static const wxX11Dash long_dashed
[] = {2, 4};
1829 static const wxX11Dash dotted_dashed
[] = {3, 3, 1, 3};
1831 // We express dash pattern in pen width unit, so we are
1832 // independent of zoom factor and so on...
1834 const wxX11Dash
*req_dash
;
1836 int lineStyle
= LineSolid
;
1837 switch (m_pen
.GetStyle())
1841 lineStyle
= LineOnOffDash
;
1842 req_nb_dash
= m_pen
.GetDashCount();
1843 req_dash
= (wxX11Dash
*)m_pen
.GetDash();
1848 lineStyle
= LineOnOffDash
;
1855 lineStyle
= LineOnOffDash
;
1857 req_dash
= long_dashed
;
1862 lineStyle
= LineOnOffDash
;
1864 req_dash
= short_dashed
;
1869 // lineStyle = LineDoubleDash;
1870 lineStyle
= LineOnOffDash
;
1872 req_dash
= dotted_dashed
;
1877 case wxSTIPPLE_MASK_OPAQUE
:
1882 lineStyle
= LineSolid
;
1883 req_dash
= (wxX11Dash
*)NULL
;
1889 int capStyle
= CapRound
;
1890 switch (m_pen
.GetCap())
1892 case wxCAP_PROJECTING
: { capStyle
= CapProjecting
; break; }
1893 case wxCAP_BUTT
: { capStyle
= CapButt
; break; }
1900 capStyle
= CapNotLast
;
1904 capStyle
= CapRound
;
1910 int joinStyle
= JoinRound
;
1911 switch (m_pen
.GetJoin())
1913 case wxJOIN_BEVEL
: { joinStyle
= JoinBevel
; break; }
1914 case wxJOIN_MITER
: { joinStyle
= JoinMiter
; break; }
1916 default: { joinStyle
= JoinRound
; break; }
1919 XSetLineAttributes( (Display
*) m_display
, (GC
) m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1921 m_pen
.GetColour().CalcPixel( m_cmap
);
1922 XSetForeground( (Display
*) m_display
, (GC
) m_penGC
, m_pen
.GetColour().GetPixel() );
1925 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1927 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1929 if (m_brush
== brush
) return;
1933 if (!m_brush
.Ok()) return;
1935 if (!m_window
) return;
1937 m_brush
.GetColour().CalcPixel( m_cmap
);
1938 XSetForeground( (Display
*) m_display
, (GC
) m_brushGC
, m_brush
.GetColour().GetPixel() );
1940 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillSolid
);
1942 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
1944 if (m_brush
.GetStipple()->GetPixmap())
1946 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillTiled
);
1947 XSetTile( (Display
*) m_display
, (GC
) m_brushGC
, (Pixmap
) m_brush
.GetStipple()->GetPixmap() );
1951 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillStippled
);
1952 XSetStipple( (Display
*) m_display
, (GC
) m_brushGC
, (Pixmap
) m_brush
.GetStipple()->GetBitmap() );
1956 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1958 XSetFillStyle( (Display
*) m_display
, (GC
) m_textGC
, FillOpaqueStippled
);
1959 XSetStipple( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) m_brush
.GetStipple()->GetMask()->GetBitmap() );
1962 if (m_brush
.IsHatch())
1964 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillStippled
);
1965 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
1966 XSetStipple( (Display
*) m_display
, (GC
) m_brushGC
, hatches
[num
] );
1970 void wxWindowDC::SetBackground( const wxBrush
&brush
)
1972 /* CMB 21/7/98: Added SetBackground. Sets background brush
1973 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1975 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1977 if (m_backgroundBrush
== brush
) return;
1979 m_backgroundBrush
= brush
;
1981 if (!m_backgroundBrush
.Ok()) return;
1983 if (!m_window
) return;
1985 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
1986 XSetBackground( (Display
*) m_display
, (GC
) m_brushGC
, m_backgroundBrush
.GetColour().GetPixel() );
1987 XSetBackground( (Display
*) m_display
, (GC
) m_penGC
, m_backgroundBrush
.GetColour().GetPixel() );
1988 XSetBackground( (Display
*) m_display
, (GC
) m_bgGC
, m_backgroundBrush
.GetColour().GetPixel() );
1989 XSetForeground( (Display
*) m_display
, (GC
) m_bgGC
, m_backgroundBrush
.GetColour().GetPixel() );
1991 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillSolid
);
1993 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
1995 if (m_backgroundBrush
.GetStipple()->GetPixmap())
1997 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillTiled
);
1998 XSetTile( (Display
*) m_display
, (GC
) m_bgGC
, (Pixmap
) m_backgroundBrush
.GetStipple()->GetPixmap() );
2002 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillStippled
);
2003 XSetStipple( (Display
*) m_display
, (GC
) m_bgGC
, (Pixmap
) m_backgroundBrush
.GetStipple()->GetBitmap() );
2007 if (m_backgroundBrush
.IsHatch())
2009 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillStippled
);
2010 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
2011 XSetStipple( (Display
*) m_display
, (GC
) m_bgGC
, hatches
[num
] );
2015 void wxWindowDC::SetLogicalFunction( int function
)
2017 wxCHECK_RET( Ok(), wxT("invalid dc") );
2021 if (m_logicalFunction
== function
)
2024 // VZ: shouldn't this be a CHECK?
2031 x_function
= GXclear
;
2037 x_function
= GXinvert
;
2040 x_function
= GXorReverse
;
2043 x_function
= GXandReverse
;
2052 x_function
= GXandInverted
;
2055 x_function
= GXnoop
;
2061 x_function
= GXequiv
;
2064 x_function
= GXcopyInverted
;
2067 x_function
= GXorInverted
;
2070 x_function
= GXnand
;
2077 x_function
= GXcopy
;
2081 XSetFunction( (Display
*) m_display
, (GC
) m_penGC
, x_function
);
2082 XSetFunction( (Display
*) m_display
, (GC
) m_brushGC
, x_function
);
2084 // to stay compatible with wxMSW, we don't apply ROPs to the text
2085 // operations (i.e. DrawText/DrawRotatedText).
2086 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
2087 XSetFunction( (Display
*) m_display
, (GC
) m_textGC
, x_function
);
2089 m_logicalFunction
= function
;
2092 void wxWindowDC::SetTextForeground( const wxColour
&col
)
2094 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2096 // don't set m_textForegroundColour to an invalid colour as we'd crash
2097 // later then (we use m_textForegroundColour.GetColor() without checking
2099 if ( !col
.Ok() || (m_textForegroundColour
== col
) )
2102 m_textForegroundColour
= col
;
2106 m_textForegroundColour
.CalcPixel( m_cmap
);
2107 XSetForeground( (Display
*) m_display
, (GC
) m_textGC
, m_textForegroundColour
.GetPixel() );
2111 void wxWindowDC::SetTextBackground( const wxColour
&col
)
2113 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2116 if ( !col
.Ok() || (m_textBackgroundColour
== col
) )
2119 m_textBackgroundColour
= col
;
2123 m_textBackgroundColour
.CalcPixel( m_cmap
);
2124 XSetBackground( (Display
*) m_display
, (GC
) m_textGC
, m_textBackgroundColour
.GetPixel() );
2128 void wxWindowDC::SetBackgroundMode( int mode
)
2130 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2132 m_backgroundMode
= mode
;
2135 GrSetGCUseBackground((GC
) m_textGC
, mode
== wxTRANSPARENT
? FALSE
: TRUE
);
2138 if (!m_window
) return;
2140 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
2141 // transparent/solid background mode
2143 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
2145 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
,
2146 (m_backgroundMode
== wxTRANSPARENT
) ? FillStippled
: FillOpaqueStippled
);
2150 void wxWindowDC::SetPalette( const wxPalette
& palette
)
2156 /* Use GetXColormap */
2157 XSetWindowColormap ((Display
*) m_display
, (Window
) m_window
->GetXWindow(),
2158 (Colormap
) palette
.GetXColormap());
2160 /* Use wxGetMainColormap */
2161 XSetWindowColormap ((Display
*) m_display
, (Window
) m_window
->GetXWindow(),
2162 (Colormap
) wxTheApp
->GetMainColormap(m_display
));
2167 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
2169 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2171 if (!m_window
) return;
2174 rect
.x
= XLOG2DEV(x
);
2175 rect
.y
= YLOG2DEV(y
);
2176 rect
.width
= XLOG2DEVREL(width
);
2177 rect
.height
= YLOG2DEVREL(height
);
2179 if (!m_currentClippingRegion
.IsNull())
2180 m_currentClippingRegion
.Intersect( rect
);
2182 m_currentClippingRegion
.Union( rect
);
2184 #if USE_PAINT_REGION
2185 if (!m_paintClippingRegion
.IsNull())
2186 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2189 wxCoord xx
, yy
, ww
, hh
;
2190 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2191 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2193 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2194 XSetRegion( (Display
*) m_display
, (GC
) m_brushGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2195 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2196 XSetRegion( (Display
*) m_display
, (GC
) m_bgGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2199 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
& region
)
2201 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2205 DestroyClippingRegion();
2209 if (!m_window
) return;
2211 if (!m_currentClippingRegion
.IsNull())
2212 m_currentClippingRegion
.Intersect( region
);
2214 m_currentClippingRegion
.Union( region
);
2216 #if USE_PAINT_REGION
2217 if (!m_paintClippingRegion
.IsNull())
2218 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
2221 wxCoord xx
, yy
, ww
, hh
;
2222 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
2223 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
2225 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2226 XSetRegion( (Display
*) m_display
, (GC
) m_brushGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2227 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2228 XSetRegion( (Display
*) m_display
, (GC
) m_bgGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2231 void wxWindowDC::DestroyClippingRegion()
2233 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2235 wxDC::DestroyClippingRegion();
2237 m_currentClippingRegion
.Clear();
2239 #if USE_PAINT_REGION
2240 if (!m_paintClippingRegion
.IsEmpty())
2241 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2244 if (!m_window
) return;
2246 if (m_currentClippingRegion
.IsEmpty())
2248 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, None
);
2249 XSetClipMask( (Display
*) m_display
, (GC
) m_brushGC
, None
);
2250 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, None
);
2251 XSetClipMask( (Display
*) m_display
, (GC
) m_bgGC
, None
);
2255 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2256 XSetRegion( (Display
*) m_display
, (GC
) m_brushGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2257 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2258 XSetRegion( (Display
*) m_display
, (GC
) m_bgGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
2262 void wxWindowDC::Destroy()
2264 if (m_penGC
) wxFreePoolGC( (GC
) m_penGC
);
2266 if (m_brushGC
) wxFreePoolGC( (GC
) m_brushGC
);
2268 if (m_textGC
) wxFreePoolGC( (GC
) m_textGC
);
2270 if (m_bgGC
) wxFreePoolGC( (GC
) m_bgGC
);
2274 void wxWindowDC::ComputeScaleAndOrigin()
2276 /* CMB: copy scale to see if it changes */
2277 double origScaleX
= m_scaleX
;
2278 double origScaleY
= m_scaleY
;
2280 wxDC::ComputeScaleAndOrigin();
2282 /* CMB: if scale has changed call SetPen to recalulate the line width */
2283 if ((m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
) &&
2286 /* this is a bit artificial, but we need to force wxDC to think
2287 the pen has changed */
2294 wxSize
wxWindowDC::GetPPI() const
2296 return wxSize(100, 100);
2299 int wxWindowDC::GetDepth() const
2301 wxFAIL_MSG(wxT("not implemented"));
2306 //-----------------------------------------------------------------------------
2308 //-----------------------------------------------------------------------------
2310 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
2312 wxClientDC::wxClientDC( wxWindow
*window
)
2313 : wxWindowDC( window
)
2315 wxCHECK_RET( window
, _T("NULL window in wxClientDC::wxClientDC") );
2317 m_window
= (WXWindow
*) window
->GetClientAreaWindow();
2319 // Adjust the client area when the wxWindow is not using 2 X11 windows.
2320 if (m_window
== (WXWindow
*) window
->GetMainWindow())
2322 wxPoint ptOrigin
= window
->GetClientAreaOrigin();
2323 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2324 wxSize size
= window
->GetClientSize();
2325 SetClippingRegion(wxPoint(0, 0), size
);
2329 void wxClientDC::DoGetSize(int *width
, int *height
) const
2331 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
2333 m_owner
->GetClientSize( width
, height
);
2336 // ----------------------------------------------------------------------------
2338 // ----------------------------------------------------------------------------
2340 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxClientDC
)
2342 wxPaintDC::wxPaintDC(wxWindow
* window
)
2343 : wxClientDC(window
)
2345 #if USE_PAINT_REGION
2346 if (!window
->GetClipPaintRegion())
2349 m_paintClippingRegion
= window
->GetUpdateRegion();
2350 Region region
= (Region
) m_paintClippingRegion
.GetX11Region();
2353 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2355 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, region
);
2356 XSetRegion( (Display
*) m_display
, (GC
) m_brushGC
, region
);
2357 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, region
);
2358 XSetRegion( (Display
*) m_display
, (GC
) m_bgGC
, region
);
2360 #endif // USE_PAINT_REGION
2363 // ----------------------------------------------------------------------------
2365 // ----------------------------------------------------------------------------
2367 class wxDCModule
: public wxModule
2374 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2377 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2379 bool wxDCModule::OnInit()
2385 void wxDCModule::OnExit()