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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dcclient.h"
16 #include "wx/dcclient.h"
17 #include "wx/dcmemory.h"
18 #include "wx/window.h"
21 #include "wx/module.h"
23 #include "wx/x11/private.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 #define USE_PAINT_REGION 1
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
45 #define IS_15_PIX_HATCH(s) ((s)==wxCROSSDIAG_HATCH || (s)==wxHORIZONTAL_HATCH || (s)==wxVERTICAL_HATCH)
46 #define IS_16_PIX_HATCH(s) ((s)!=wxCROSSDIAG_HATCH && (s)!=wxHORIZONTAL_HATCH && (s)!=wxVERTICAL_HATCH)
48 static Pixmap hatches
[num_hatches
];
49 static Pixmap
*hatch_bitmap
= (Pixmap
*) NULL
;
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 const double RAD2DEG
= 180.0 / M_PI
;
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 static inline double dmax(double a
, double b
) { return a
> b
? a
: b
; }
62 static inline double dmin(double a
, double b
) { return a
< b
? a
: b
; }
64 static inline double DegToRad(double deg
) { return (deg
* M_PI
) / 180.0; }
66 //-----------------------------------------------------------------------------
67 // Implement Pool of Graphic contexts. Creating them takes too much time.
68 //-----------------------------------------------------------------------------
70 #define GC_POOL_SIZE 200
96 static wxGC wxGCPool
[GC_POOL_SIZE
];
98 static void wxInitGCPool()
100 memset( wxGCPool
, 0, GC_POOL_SIZE
*sizeof(wxGC
) );
103 static void wxCleanUpGCPool()
105 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
107 if (wxGCPool
[i
].m_gc
)
108 XFreeGC( wxGlobalDisplay(), wxGCPool
[i
].m_gc
);
112 static GC
wxGetPoolGC( Window window
, wxPoolGCType type
)
114 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
116 if (!wxGCPool
[i
].m_gc
)
118 wxGCPool
[i
].m_gc
= XCreateGC( wxGlobalDisplay(), window
, 0, NULL
);
119 XSetGraphicsExposures( wxGlobalDisplay(), wxGCPool
[i
].m_gc
, FALSE
);
120 wxGCPool
[i
].m_type
= type
;
121 wxGCPool
[i
].m_used
= FALSE
;
123 if ((!wxGCPool
[i
].m_used
) && (wxGCPool
[i
].m_type
== type
))
125 wxGCPool
[i
].m_used
= TRUE
;
126 return wxGCPool
[i
].m_gc
;
130 wxFAIL_MSG( wxT("No GC available") );
135 static void wxFreePoolGC( GC gc
)
137 for (int i
= 0; i
< GC_POOL_SIZE
; i
++)
139 if (wxGCPool
[i
].m_gc
== gc
)
141 wxGCPool
[i
].m_used
= FALSE
;
146 wxFAIL_MSG( wxT("Wrong GC") );
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC
, wxDC
)
155 wxWindowDC::wxWindowDC()
157 m_display
= (WXDisplay
*) NULL
;
158 m_penGC
= (WXGC
*) NULL
;
159 m_brushGC
= (WXGC
*) NULL
;
160 m_textGC
= (WXGC
*) NULL
;
161 m_bgGC
= (WXGC
*) NULL
;
162 m_cmap
= (WXColormap
*) NULL
;
164 m_isScreenDC
= FALSE
;
165 m_owner
= (wxWindow
*)NULL
;
168 wxWindowDC::wxWindowDC( wxWindow
*window
)
170 wxASSERT_MSG( window
, wxT("DC needs a window") );
172 m_display
= (WXDisplay
*) NULL
;
173 m_penGC
= (WXGC
*) NULL
;
174 m_brushGC
= (WXGC
*) NULL
;
175 m_textGC
= (WXGC
*) NULL
;
176 m_bgGC
= (WXGC
*) NULL
;
177 m_cmap
= (WXColormap
*) NULL
;
178 m_owner
= (wxWindow
*)NULL
;
180 m_isScreenDC
= FALSE
;
181 m_font
= window
->GetFont();
183 m_window
= (WXWindow
*) window
->GetMainWindow();
188 // don't report problems
194 m_display
= (WXDisplay
*) wxGlobalDisplay();
196 int screen
= DefaultScreen( (Display
*) m_display
);
197 m_cmap
= (WXColormap
) DefaultColormap( (Display
*) m_display
, screen
);
201 /* this must be done after SetUpDC, bacause SetUpDC calls the
202 repective SetBrush, SetPen, SetBackground etc functions
203 to set up the DC. SetBackground call m_owner->SetBackground
204 and this might not be desired as the standard dc background
205 is white whereas a window might assume gray to be the
206 standard (as e.g. wxStatusBar) */
211 wxWindowDC::~wxWindowDC()
216 void wxWindowDC::SetUpDC()
220 wxASSERT_MSG( !m_penGC
, wxT("GCs already created") );
224 m_penGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxPEN_SCREEN
);
225 m_brushGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBRUSH_SCREEN
);
226 m_textGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxTEXT_SCREEN
);
227 m_bgGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBG_SCREEN
);
230 if (m_isMemDC
&& (((wxMemoryDC
*)this)->m_selected
.GetDepth() == 1))
232 m_penGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxPEN_MONO
);
233 m_brushGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBRUSH_MONO
);
234 m_textGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxTEXT_MONO
);
235 m_bgGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBG_MONO
);
239 m_penGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxPEN_COLOUR
);
240 m_brushGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBRUSH_COLOUR
);
241 m_textGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxTEXT_COLOUR
);
242 m_bgGC
= (WXGC
*) wxGetPoolGC( (Window
) m_window
, wxBG_COLOUR
);
245 /* background colour */
246 m_backgroundBrush
= *wxWHITE_BRUSH
;
247 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
248 unsigned long bg_col
= m_backgroundBrush
.GetColour().GetPixel();
251 m_textForegroundColour
.CalcPixel( m_cmap
);
252 XSetForeground( (Display
*) m_display
, (GC
) m_textGC
, m_textForegroundColour
.GetPixel() );
254 m_textBackgroundColour
.CalcPixel( m_cmap
);
255 XSetBackground( (Display
*) m_display
, (GC
) m_textGC
, m_textBackgroundColour
.GetPixel() );
257 XSetFillStyle( (Display
*) m_display
, (GC
) m_textGC
, FillSolid
);
260 // By default, draw transparently
261 GrSetGCUseBackground((GC
) m_textGC
, FALSE
);
265 m_pen
.GetColour().CalcPixel( m_cmap
);
266 XSetForeground( (Display
*) m_display
, (GC
) m_penGC
, m_pen
.GetColour().GetPixel() );
267 XSetBackground( (Display
*) m_display
, (GC
) m_penGC
, bg_col
);
269 XSetLineAttributes( (Display
*) m_display
, (GC
) m_penGC
, 0, LineSolid
, CapNotLast
, JoinRound
);
272 m_brush
.GetColour().CalcPixel( m_cmap
);
273 XSetForeground( (Display
*) m_display
, (GC
) m_brushGC
, m_brush
.GetColour().GetPixel() );
274 XSetBackground( (Display
*) m_display
, (GC
) m_brushGC
, bg_col
);
276 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillSolid
);
279 XSetForeground( (Display
*) m_display
, (GC
) m_bgGC
, bg_col
);
280 XSetBackground( (Display
*) m_display
, (GC
) m_bgGC
, bg_col
);
282 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillSolid
);
285 XSetFunction( (Display
*) m_display
, (GC
) m_textGC
, GXcopy
);
286 XSetFunction( (Display
*) m_display
, (GC
) m_brushGC
, GXcopy
);
287 XSetFunction( (Display
*) m_display
, (GC
)m_penGC
, GXcopy
);
290 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, None
);
291 XSetClipMask( (Display
*) m_display
, (GC
) m_brushGC
, None
);
292 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, None
);
293 XSetClipMask( (Display
*) m_display
, (GC
) m_bgGC
, None
);
297 int xscreen
= DefaultScreen( (Display
*) m_display
);
298 Window xroot
= RootWindow( (Display
*) m_display
, xscreen
);
300 hatch_bitmap
= hatches
;
301 hatch_bitmap
[0] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, bdiag_bits
, bdiag_width
, bdiag_height
);
302 hatch_bitmap
[1] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, cdiag_bits
, cdiag_width
, cdiag_height
);
303 hatch_bitmap
[2] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, fdiag_bits
, fdiag_width
, fdiag_height
);
304 hatch_bitmap
[3] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, cross_bits
, cross_width
, cross_height
);
305 hatch_bitmap
[4] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, horiz_bits
, horiz_width
, horiz_height
);
306 hatch_bitmap
[5] = XCreateBitmapFromData( (Display
*) m_display
, xroot
, verti_bits
, verti_width
, verti_height
);
310 void wxWindowDC::DoGetSize( int* width
, int* height
) const
312 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
314 m_owner
->GetSize(width
, height
);
317 extern bool wxDoFloodFill(wxDC
*dc
, wxCoord x
, wxCoord y
,
318 const wxColour
& col
, int style
);
320 bool wxWindowDC::DoFloodFill(wxCoord x
, wxCoord y
,
321 const wxColour
& col
, int style
)
323 return wxDoFloodFill(this, x
, y
, col
, style
);
326 bool wxWindowDC::DoGetPixel( wxCoord x1
, wxCoord y1
, wxColour
*col
) const
328 // Generic (and therefore rather inefficient) method.
329 // Could be improved.
331 wxBitmap
bitmap(1, 1);
332 memdc
.SelectObject(bitmap
);
333 memdc
.Blit(0, 0, 1, 1, (wxDC
*) this, x1
, y1
);
334 memdc
.SelectObject(wxNullBitmap
);
335 wxImage
image(bitmap
);
336 col
->Set(image
.GetRed(0, 0), image
.GetGreen(0, 0), image
.GetBlue(0, 0));
340 void wxWindowDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
342 wxCHECK_RET( Ok(), wxT("invalid window dc") );
344 if (m_pen
.GetStyle() != wxTRANSPARENT
)
347 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
348 (GC
) m_penGC
, XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
350 CalcBoundingBox(x1
, y1
);
351 CalcBoundingBox(x2
, y2
);
355 void wxWindowDC::DoCrossHair( wxCoord x
, wxCoord y
)
357 wxCHECK_RET( Ok(), wxT("invalid window dc") );
359 if (m_pen
.GetStyle() != wxTRANSPARENT
)
364 wxCoord xx
= XLOG2DEV(x
);
365 wxCoord yy
= YLOG2DEV(y
);
368 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
369 (GC
) m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
370 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
371 (GC
) m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
376 void wxWindowDC::DoDrawArc( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
, wxCoord xc
, wxCoord yc
)
378 wxCHECK_RET( Ok(), wxT("invalid window dc") );
380 wxCoord xx1
= XLOG2DEV(x1
);
381 wxCoord yy1
= YLOG2DEV(y1
);
382 wxCoord xx2
= XLOG2DEV(x2
);
383 wxCoord yy2
= YLOG2DEV(y2
);
384 wxCoord xxc
= XLOG2DEV(xc
);
385 wxCoord yyc
= YLOG2DEV(yc
);
386 double dx
= xx1
- xxc
;
387 double dy
= yy1
- yyc
;
388 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
389 wxCoord r
= (wxCoord
)radius
;
390 double radius1
, radius2
;
392 if (xx1
== xx2
&& yy1
== yy2
)
400 radius1
= radius2
= 0.0;
404 radius1
= (xx1
- xxc
== 0) ?
405 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
406 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
407 radius2
= (xx2
- xxc
== 0) ?
408 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
409 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
411 wxCoord alpha1
= wxCoord(radius1
* 64.0);
412 wxCoord alpha2
= wxCoord((radius2
- radius1
) * 64.0);
413 while (alpha2
<= 0) alpha2
+= 360*64;
414 while (alpha1
> 360*64) alpha1
-= 360*64;
418 if (m_brush
.GetStyle() != wxTRANSPARENT
)
420 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
422 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
423 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
424 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
426 XFillArc( (Display
*) m_display
, (Window
) m_window
,
427 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
429 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
431 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
433 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
434 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
436 XFillArc( (Display
*) m_display
, (Window
) m_window
,
437 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
439 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
441 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
443 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
444 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
446 XFillArc( (Display
*) m_display
, (Window
) m_window
,
447 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
449 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
451 if (m_brush
.GetStyle() == wxSTIPPLE
)
453 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
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_brushGC
, 0, 0 );
464 XFillArc( (Display
*) m_display
, (Window
) m_window
,
465 (GC
) m_brushGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
469 if (m_pen
.GetStyle() != wxTRANSPARENT
)
471 XDrawArc( (Display
*) m_display
, (Window
) m_window
,
472 (GC
) m_penGC
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
474 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
475 (GC
) m_penGC
, xx1
, yy1
, xxc
, yyc
);
477 XDrawLine( (Display
*) m_display
, (Window
) m_window
,
478 (GC
) m_penGC
, xxc
, yyc
, xx2
, yy2
);
482 CalcBoundingBox (x1
, y1
);
483 CalcBoundingBox (x2
, y2
);
486 void wxWindowDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double sa
, double ea
)
488 wxCHECK_RET( Ok(), wxT("invalid window dc") );
490 wxCoord xx
= XLOG2DEV(x
);
491 wxCoord yy
= YLOG2DEV(y
);
492 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
493 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
495 // CMB: handle -ve width and/or height
496 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
497 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
501 wxCoord start
= wxCoord(sa
* 64.0);
502 wxCoord end
= wxCoord((ea
-sa
) * 64.0);
504 if (m_brush
.GetStyle() != wxTRANSPARENT
)
506 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
508 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
509 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
510 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
512 XFillArc( (Display
*) m_display
, (Window
) m_window
,
513 (GC
) m_textGC
, xx
, yy
, ww
, hh
, start
, end
);
515 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
517 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
519 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
520 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
522 XFillArc( (Display
*) m_display
, (Window
) m_window
,
523 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, start
, end
);
525 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
527 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
529 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
530 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
532 XFillArc( (Display
*) m_display
, (Window
) m_window
,
533 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, start
, end
);
535 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
537 if (m_brush
.GetStyle() == wxSTIPPLE
)
539 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
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_brushGC
, xx
, yy
, ww
, hh
, start
, end
);
546 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
550 XFillArc( (Display
*) m_display
, (Window
) m_window
,
551 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, start
, end
);
555 if (m_pen
.GetStyle() != wxTRANSPARENT
)
557 XDrawArc( (Display
*) m_display
, (Window
) m_window
,
558 (GC
) m_penGC
, xx
, yy
, ww
, hh
, start
, end
);
562 CalcBoundingBox (x
, y
);
563 CalcBoundingBox (x
+ width
, y
+ height
);
566 void wxWindowDC::DoDrawPoint( wxCoord x
, wxCoord y
)
568 wxCHECK_RET( Ok(), wxT("invalid window dc") );
570 if ((m_pen
.GetStyle() != wxTRANSPARENT
) && m_window
)
571 XDrawPoint( (Display
*) m_display
, (Window
) m_window
,
572 (GC
) m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
574 CalcBoundingBox (x
, y
);
577 void wxWindowDC::DoDrawLines( int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
579 wxCHECK_RET( Ok(), wxT("invalid window dc") );
581 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
584 XPoint
*xpoints
= new XPoint
[n
];
585 for (int i
= 0; i
< n
; i
++)
587 xpoints
[i
].x
= XLOG2DEV (points
[i
].x
+ xoffset
);
588 xpoints
[i
].y
= YLOG2DEV (points
[i
].y
+ yoffset
);
590 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
592 XDrawLines( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xpoints
, n
, 0 );
597 void wxWindowDC::DoDrawPolygon( int n
, wxPoint points
[],
598 wxCoord xoffset
, wxCoord yoffset
, int fillStyle
)
600 wxCHECK_RET( Ok(), wxT("invalid window dc") );
604 XPoint
*xpoints
= new XPoint
[n
+ 1];
606 for (i
= 0; i
< n
; i
++)
608 xpoints
[i
].x
= XLOG2DEV (points
[i
].x
+ xoffset
);
609 xpoints
[i
].y
= YLOG2DEV (points
[i
].y
+ yoffset
);
611 CalcBoundingBox (points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
616 if (m_brush
.GetStyle() != wxTRANSPARENT
)
619 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
621 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
622 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
623 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
625 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
626 (GC
) m_textGC
, xpoints
, n
, Complex
, 0);
628 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
630 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
632 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
633 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
635 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
636 (GC
) m_brushGC
, xpoints
, n
, Complex
, 0);
638 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
640 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
642 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
643 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
645 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
646 (GC
) m_brushGC
, xpoints
, n
, Complex
, 0);
648 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
650 if (m_brush
.GetStyle() == wxSTIPPLE
)
652 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
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_brushGC
, xpoints
, n
, Complex
, 0);
659 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
663 XFillPolygon( (Display
*) m_display
, (Window
) m_window
,
664 (GC
) m_brushGC
, xpoints
, n
, Complex
, 0);
668 if (m_pen
.GetStyle () != wxTRANSPARENT
)
670 // Close figure for XDrawLines
671 xpoints
[i
].x
= xpoints
[0].x
;
672 xpoints
[i
].y
= xpoints
[0].y
;
674 XDrawLines( (Display
*) m_display
, (Window
) m_window
, (GC
) m_penGC
, xpoints
, n
+ 1, 0);
681 void wxWindowDC::DoDrawRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
683 wxCHECK_RET( Ok(), wxT("invalid window dc") );
685 wxCoord xx
= XLOG2DEV(x
);
686 wxCoord yy
= YLOG2DEV(y
);
687 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
688 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
690 // CMB: draw nothing if transformed w or h is 0
691 if (ww
== 0 || hh
== 0) return;
693 // CMB: handle -ve width and/or height
694 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
695 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
699 if (m_brush
.GetStyle() != wxTRANSPARENT
)
701 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
703 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
704 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
705 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
707 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
708 (GC
) m_textGC
, xx
, yy
, ww
, hh
);
710 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
712 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
714 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
715 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
717 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
718 (GC
) m_brushGC
, xx
, yy
, ww
, hh
);
720 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
722 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
724 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
725 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
727 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
728 (GC
) m_brushGC
, xx
, yy
, ww
, hh
);
730 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
732 if (m_brush
.GetStyle() == wxSTIPPLE
)
734 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
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_brushGC
, xx
, yy
, ww
, hh
);
741 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
745 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
746 (GC
) m_brushGC
, xx
, yy
, ww
, hh
);
750 if (m_pen
.GetStyle () != wxTRANSPARENT
)
752 XDrawRectangle( (Display
*) m_display
, (Window
) m_window
,
753 (GC
) m_penGC
, xx
, yy
, ww
-1, hh
-1 );
757 CalcBoundingBox( x
, y
);
758 CalcBoundingBox( x
+ width
, y
+ height
);
761 void wxWindowDC::DoDrawRoundedRectangle( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
766 void wxWindowDC::DoDrawEllipse( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
768 wxCHECK_RET( Ok(), wxT("invalid window dc") );
770 wxCoord xx
= XLOG2DEV(x
);
771 wxCoord yy
= YLOG2DEV(y
);
772 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
773 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
775 // CMB: handle -ve width and/or height
776 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
777 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
781 if (m_brush
.GetStyle() != wxTRANSPARENT
)
783 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
785 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
,
786 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
787 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
789 XFillArc( (Display
*) m_display
, (Window
) m_window
,
790 (GC
) m_textGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
792 XSetTSOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
794 if (IS_15_PIX_HATCH(m_brush
.GetStyle()))
796 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
797 m_deviceOriginX
% 15, m_deviceOriginY
% 15 );
799 XFillArc( (Display
*) m_display
, (Window
) m_window
,
800 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
802 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
804 if (IS_16_PIX_HATCH(m_brush
.GetStyle()))
806 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
807 m_deviceOriginX
% 16, m_deviceOriginY
% 16 );
809 XFillArc( (Display
*) m_display
, (Window
) m_window
,
810 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
812 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
814 if (m_brush
.GetStyle() == wxSTIPPLE
)
816 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
,
817 m_deviceOriginX
% m_brush
.GetStipple()->GetWidth(),
818 m_deviceOriginY
% m_brush
.GetStipple()->GetHeight() );
820 XFillArc( (Display
*) m_display
, (Window
) m_window
,
821 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
823 XSetTSOrigin( (Display
*) m_display
, (GC
) m_brushGC
, 0, 0 );
827 XFillArc( (Display
*) m_display
, (Window
) m_window
,
828 (GC
) m_brushGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
832 if (m_pen
.GetStyle () != wxTRANSPARENT
)
834 XDrawArc( (Display
*) m_display
, (Window
) m_window
,
835 (GC
) m_penGC
, xx
, yy
, ww
, hh
, 0, 360*64 );
839 CalcBoundingBox( x
, y
);
840 CalcBoundingBox( x
+ width
, y
+ height
);
843 void wxWindowDC::DoDrawIcon( const wxIcon
&icon
, wxCoord x
, wxCoord y
)
845 DoDrawBitmap(icon
, x
, y
, TRUE
);
849 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
850 wxCoord x
, wxCoord y
,
853 wxCHECK_RET( Ok(), wxT("invalid window dc") );
855 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
857 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
859 /* scale/translate size and position */
860 int xx
= XLOG2DEV(x
);
861 int yy
= YLOG2DEV(y
);
863 int w
= bitmap
.GetWidth();
864 int h
= bitmap
.GetHeight();
866 CalcBoundingBox( x
, y
);
867 CalcBoundingBox( x
+ w
, y
+ h
);
869 if (!m_window
) return;
871 int ww
= XLOG2DEVREL(w
);
872 int hh
= YLOG2DEVREL(h
);
874 /* compare to current clipping region */
875 if (!m_currentClippingRegion
.IsNull())
877 wxRegion
tmp( xx
,yy
,ww
,hh
);
878 tmp
.Intersect( m_currentClippingRegion
);
883 /* scale bitmap if required */
885 if ((w
!= ww
) || (h
!= hh
))
887 wxImage
image( bitmap
);
888 image
.Rescale( ww
, hh
);
891 use_bitmap
= image
.ConvertToMonoBitmap(255,255,255);
894 use_bitmap
= image
.ConvertToBitmap();
901 /* apply mask if any */
902 WXPixmap mask
= NULL
;
903 if (use_bitmap
.GetMask())
904 mask
= use_bitmap
.GetMask()->GetBitmap();
908 Pixmap pixmap
= (Pixmap
) use_bitmap
.GetPixmap() ;
909 Pixmap maskPixmap
= (Pixmap
) use_bitmap
.GetMask()->GetBitmap() ;
910 Pixmap bufPixmap
= GrNewPixmap(w
, h
, 0);
912 GrSetGCUseBackground(gc
, FALSE
);
913 GrSetGCMode(gc
, GR_MODE_COPY
);
915 // This code assumes that background and foreground
916 // colours are used in ROPs, like in MSW.
917 // Not sure if this is true.
919 // Copy destination to buffer.
920 // In DoBlit, we need this step because Blit has
921 // a ROP argument. Here, we don't need it.
922 // In DoBlit, we may be able to eliminate this step
923 // if we check if the rop = copy
925 GrCopyArea(bufPixmap
, gc
, 0, 0, w
, h
, (Window
) m_window
,
929 // Copy src to buffer using selected raster op (none selected
930 // in DrawBitmap, so just use Gxcopy)
931 GrCopyArea(bufPixmap
, gc
, 0, 0, w
, h
, pixmap
,
934 // Set masked area in buffer to BLACK (pixel value 0)
935 GrSetGCBackground(gc
, WHITE
);
936 GrSetGCForeground(gc
, BLACK
);
937 GrCopyArea(bufPixmap
, gc
, 0, 0, w
, h
, maskPixmap
,
940 // set unmasked area in dest to BLACK
941 GrSetGCBackground(gc
, BLACK
);
942 GrSetGCForeground(gc
, WHITE
);
943 GrCopyArea((Window
) m_window
, gc
, xx
, yy
, w
, h
, maskPixmap
,
947 GrCopyArea((Window
) m_window
, gc
, xx
, yy
, w
, h
, bufPixmap
,
951 GrDestroyWindow(bufPixmap
);
954 XCopyArea( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetPixmap(), (Window
) m_window
,
955 (GC
) m_penGC
, 0, 0, w
, h
, xx
, yy
);
957 /* remove mask again if any */
960 if (!m_currentClippingRegion
.IsNull())
961 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
968 void wxWindowDC::DoDrawBitmap( const wxBitmap
&bitmap
,
969 wxCoord x
, wxCoord y
,
972 wxCHECK_RET( Ok(), wxT("invalid window dc") );
974 wxCHECK_RET( bitmap
.Ok(), wxT("invalid bitmap") );
976 bool is_mono
= (bitmap
.GetBitmap() != NULL
);
978 // scale/translate size and position
979 int xx
= XLOG2DEV(x
);
980 int yy
= YLOG2DEV(y
);
982 int w
= bitmap
.GetWidth();
983 int h
= bitmap
.GetHeight();
985 CalcBoundingBox( x
, y
);
986 CalcBoundingBox( x
+ w
, y
+ h
);
988 if (!m_window
) return;
990 int ww
= XLOG2DEVREL(w
);
991 int hh
= YLOG2DEVREL(h
);
993 // compare to current clipping region
994 if (!m_currentClippingRegion
.IsNull())
996 wxRegion
tmp( xx
,yy
,ww
,hh
);
997 tmp
.Intersect( m_currentClippingRegion
);
1002 // scale bitmap if required
1003 wxBitmap use_bitmap
;
1004 if ((w
!= ww
) || (h
!= hh
))
1006 wxImage
image( bitmap
);
1007 image
.Rescale( ww
, hh
);
1010 use_bitmap
= image
.ConvertToMonoBitmap(255,255,255);
1013 use_bitmap
= image
.ConvertToBitmap();
1017 use_bitmap
= bitmap
;
1020 // apply mask if any
1021 WXPixmap mask
= NULL
;
1022 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1024 if (useMask
&& mask
)
1026 WXPixmap new_mask
= NULL
;
1028 if (!m_currentClippingRegion
.IsNull())
1031 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, ww
, hh
, 1 );
1032 GdkGC
*gc
= gdk_gc_new( new_mask
);
1034 gdk_gc_set_foreground( gc
, &col
);
1035 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1037 gdk_gc_set_background( gc
, &col
);
1039 gdk_gc_set_foreground( gc
, &col
);
1040 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1041 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1042 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1043 gdk_gc_set_stipple( gc
, mask
);
1044 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, ww
, hh
);
1051 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) new_mask
);
1053 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) mask
);
1054 XSetClipOrigin( (Display
*) m_display
, (GC
) m_textGC
, xx
, yy
);
1059 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, (Pixmap
) new_mask
);
1061 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, (Pixmap
) mask
);
1062 XSetClipOrigin( (Display
*) m_display
, (GC
) m_penGC
, xx
, yy
);
1066 XFreePixmap( (Display
*) m_display
, (Pixmap
) new_mask
);
1069 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1070 // drawing a mono-bitmap (XBitmap) we use the current text GC
1072 XCopyPlane( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetBitmap(), (Window
) m_window
,
1073 (GC
) m_textGC
, 0, 0, w
, h
, xx
, yy
, 1 );
1075 XCopyArea( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetPixmap(), (Window
) m_window
,
1076 (GC
) m_penGC
, 0, 0, w
, h
, xx
, yy
);
1078 // remove mask again if any
1079 if (useMask
&& mask
)
1083 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, None
);
1084 XSetClipOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
1085 if (!m_currentClippingRegion
.IsNull())
1086 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1090 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, None
);
1091 XSetClipOrigin( (Display
*) m_display
, (GC
) m_penGC
, 0, 0 );
1092 if (!m_currentClippingRegion
.IsNull())
1093 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1098 // wxUSE_NANOX/!wxUSE_NANOX
1100 bool wxWindowDC::DoBlit( wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
1101 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func
, bool useMask
,
1102 wxCoord xsrcMask
, wxCoord ysrcMask
)
1104 /* this is the nth try to get this utterly useless function to
1105 work. it now completely ignores the scaling or translation
1106 of the source dc, but scales correctly on the target dc and
1107 knows about possible mask information in a memory dc. */
1109 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid window dc") );
1111 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1113 if (!m_window
) return FALSE
;
1115 // transform the source DC coords to the device ones
1116 xsrc
= source
->XLOG2DEV(xsrc
);
1117 ysrc
= source
->YLOG2DEV(ysrc
);
1119 wxClientDC
*srcDC
= (wxClientDC
*)source
;
1120 wxMemoryDC
*memDC
= (wxMemoryDC
*)source
;
1122 bool use_bitmap_method
= FALSE
;
1123 bool is_mono
= FALSE
;
1125 // TODO: use the mask origin when drawing transparently
1126 if (xsrcMask
== -1 && ysrcMask
== -1)
1132 if (srcDC
->m_isMemDC
)
1134 if (!memDC
->m_selected
.Ok()) return FALSE
;
1136 /* we use the "XCopyArea" way to copy a memory dc into
1137 y different window if the memory dc BOTH
1138 a) doesn't have any mask or its mask isn't used
1142 if (useMask
&& (memDC
->m_selected
.GetMask()))
1144 /* we HAVE TO use the direct way for memory dcs
1145 that have mask since the XCopyArea doesn't know
1147 use_bitmap_method
= TRUE
;
1149 else if (memDC
->m_selected
.GetDepth() == 1)
1151 /* we HAVE TO use the direct way for memory dcs
1152 that are bitmaps because XCopyArea doesn't cope
1153 with different bit depths */
1155 use_bitmap_method
= TRUE
;
1157 else if ((xsrc
== 0) && (ysrc
== 0) &&
1158 (width
== memDC
->m_selected
.GetWidth()) &&
1159 (height
== memDC
->m_selected
.GetHeight()))
1161 /* we SHOULD use the direct way if all of the bitmap
1162 in the memory dc is copied in which case XCopyArea
1163 wouldn't be able able to boost performace by reducing
1164 the area to be scaled */
1165 use_bitmap_method
= TRUE
;
1169 use_bitmap_method
= FALSE
;
1173 CalcBoundingBox( xdest
, ydest
);
1174 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
1176 // scale/translate size and position
1177 wxCoord xx
= XLOG2DEV(xdest
);
1178 wxCoord yy
= YLOG2DEV(ydest
);
1180 wxCoord ww
= XLOG2DEVREL(width
);
1181 wxCoord hh
= YLOG2DEVREL(height
);
1183 // compare to current clipping region
1184 if (!m_currentClippingRegion
.IsNull())
1186 wxRegion
tmp( xx
,yy
,ww
,hh
);
1187 tmp
.Intersect( m_currentClippingRegion
);
1192 int old_logical_func
= m_logicalFunction
;
1193 SetLogicalFunction( logical_func
);
1195 if (use_bitmap_method
)
1197 // scale/translate bitmap size
1198 wxCoord bm_width
= memDC
->m_selected
.GetWidth();
1199 wxCoord bm_height
= memDC
->m_selected
.GetHeight();
1201 wxCoord bm_ww
= XLOG2DEVREL( bm_width
);
1202 wxCoord bm_hh
= YLOG2DEVREL( bm_height
);
1204 // scale bitmap if required
1205 wxBitmap use_bitmap
;
1207 if ((bm_width
!= bm_ww
) || (bm_height
!= bm_hh
))
1209 wxImage
image( memDC
->m_selected
);
1210 image
= image
.Scale( bm_ww
, bm_hh
);
1214 use_bitmap
= image
.ConvertToMonoBitmap(255,255,255);
1217 use_bitmap
= image
.ConvertToBitmap();
1221 use_bitmap
= memDC
->m_selected
;
1224 // apply mask if any
1225 WXPixmap mask
= NULL
;
1226 if (use_bitmap
.GetMask()) mask
= use_bitmap
.GetMask()->GetBitmap();
1228 if (useMask
&& mask
)
1230 WXPixmap new_mask
= NULL
;
1232 if (!m_currentClippingRegion
.IsNull())
1235 new_mask
= gdk_pixmap_new( wxGetRootWindow()->window
, bm_ww
, bm_hh
, 1 );
1236 GdkGC
*gc
= gdk_gc_new( new_mask
);
1238 gdk_gc_set_foreground( gc
, &col
);
1239 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1241 gdk_gc_set_background( gc
, &col
);
1243 gdk_gc_set_foreground( gc
, &col
);
1244 gdk_gc_set_clip_region( gc
, m_currentClippingRegion
.GetRegion() );
1245 gdk_gc_set_clip_origin( gc
, -xx
, -yy
);
1246 gdk_gc_set_fill( gc
, GDK_OPAQUE_STIPPLED
);
1247 gdk_gc_set_stipple( gc
, mask
);
1248 gdk_draw_rectangle( new_mask
, gc
, TRUE
, 0, 0, bm_ww
, bm_hh
);
1255 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) new_mask
);
1257 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) mask
);
1258 XSetClipOrigin( (Display
*) m_display
, (GC
) m_textGC
, xx
, yy
);
1263 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, (Pixmap
) new_mask
);
1265 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, (Pixmap
) mask
);
1266 XSetClipOrigin( (Display
*) m_display
, (GC
) m_penGC
, xx
, yy
);
1270 XFreePixmap( (Display
*) m_display
, (Pixmap
) new_mask
);
1273 // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For
1274 // drawing a mono-bitmap (XBitmap) we use the current text GC
1277 XCopyPlane( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetBitmap(), (Window
) m_window
,
1278 (GC
) m_textGC
, xsrc
, ysrc
, width
, height
, xx
, yy
, 1 );
1280 XCopyArea( (Display
*) m_display
, (Pixmap
) use_bitmap
.GetPixmap(), (Window
) m_window
,
1281 (GC
) m_penGC
, xsrc
, ysrc
, width
, height
, xx
, yy
);
1283 // remove mask again if any
1284 if (useMask
&& mask
)
1288 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, None
);
1289 XSetClipOrigin( (Display
*) m_display
, (GC
) m_textGC
, 0, 0 );
1290 if (!m_currentClippingRegion
.IsNull())
1291 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1295 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, None
);
1296 XSetClipOrigin( (Display
*) m_display
, (GC
) m_penGC
, 0, 0 );
1297 if (!m_currentClippingRegion
.IsNull())
1298 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1302 else // use_bitmap_method
1304 if ((width
!= ww
) || (height
!= hh
))
1306 /* Draw source window into a bitmap as we cannot scale
1307 a window in contrast to a bitmap. this would actually
1308 work with memory dcs as well, but we'd lose the mask
1309 information and waste one step in this process since
1310 a memory already has a bitmap. all this is slightly
1311 inefficient as we could take an XImage directly from
1312 an X window, but we'd then also have to care that
1313 the window is not outside the screen (in which case
1314 we'd get a BadMatch or what not).
1315 Is a double XGetImage and combined XGetPixel and
1316 XPutPixel really faster? I'm not sure. look at wxXt
1317 for a different implementation of the same problem. */
1319 wxBitmap
bitmap( width
, height
);
1321 // copy including child window contents
1322 XSetSubwindowMode( (Display
*) m_display
, (GC
) m_penGC
, IncludeInferiors
);
1323 XCopyArea( (Display
*) m_display
, (Window
) srcDC
->GetWindow(), (Window
) bitmap
.GetPixmap(),
1324 (GC
) m_penGC
, xsrc
, ysrc
, width
, height
, 0, 0 );
1325 XSetSubwindowMode( (Display
*) m_display
, (GC
) m_penGC
, ClipByChildren
);
1328 wxImage
image( bitmap
);
1329 image
= image
.Scale( ww
, hh
);
1331 // convert to bitmap
1332 bitmap
= image
.ConvertToBitmap();
1334 // draw scaled bitmap
1335 XCopyArea( (Display
*) m_display
, (Window
) bitmap
.GetPixmap(), (Window
) m_window
,
1336 (GC
) m_penGC
, 0, 0, width
, height
, xx
, yy
);
1340 // No scaling and not a memory dc with a mask either
1342 // copy including child window contents
1343 XSetSubwindowMode( (Display
*) m_display
, (GC
) m_penGC
, IncludeInferiors
);
1344 XCopyArea( (Display
*) m_display
, (Window
) srcDC
->GetWindow(), (Window
) m_window
,
1345 (GC
) m_penGC
, xsrc
, ysrc
, width
, height
, xx
, yy
);
1346 XSetSubwindowMode( (Display
*) m_display
, (GC
) m_penGC
, ClipByChildren
);
1350 SetLogicalFunction( old_logical_func
);
1355 void wxWindowDC::DoDrawText( const wxString
&text
, wxCoord x
, wxCoord y
)
1357 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1359 if (!m_window
) return;
1361 XFontStruct
*xfont
= (XFontStruct
*) m_font
.GetFontStruct( m_scaleY
, m_display
);
1363 wxCHECK_RET( xfont
, wxT("invalid font") );
1368 // First draw a rectangle representing the text background, if a text
1369 // background is specified
1370 if (m_textBackgroundColour
.Ok () && (m_backgroundMode
!= wxTRANSPARENT
))
1372 // Since X draws from the baseline of the text, must add the text height
1377 int direction
, descent
;
1379 slen
= strlen(text
);
1380 XCharStruct overall_return
;
1382 (void)XTextExtents(xfont
, (char*) text
.c_str(), slen
, &direction
,
1383 &ascent
, &descent
, &overall_return
);
1385 cx
= overall_return
.width
;
1386 cy
= ascent
+ descent
;
1387 m_textBackgroundColour
.CalcPixel(m_cmap
);
1388 XSetForeground ((Display
*) m_display
, (GC
) m_textGC
, m_textBackgroundColour
.GetPixel());
1389 XFillRectangle( (Display
*) m_display
, (Window
) m_window
,
1390 (GC
) m_textGC
, x
, y
, cx
, cy
);
1391 XSetForeground ((Display
*) m_display
, (GC
) m_textGC
, m_textForegroundColour
.GetPixel());
1395 XSetFont( (Display
*) m_display
, (GC
) m_textGC
, xfont
->fid
);
1397 if ((xfont
->min_byte1
== 0) && (xfont
->max_byte1
== 0))
1400 XDrawString( (Display
*) m_display
, (Window
) m_window
,
1401 (GC
) m_textGC
, x
, y
+ XFontStructGetAscent(xfont
), text
.c_str(), text
.Len() );
1405 if (m_font
.GetUnderlined())
1407 wxCoord ul_y
= y
+ XFontStructGetAscent(font
);
1408 if (font
->descent
> 0) ul_y
++;
1409 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
1412 width
= wxCoord(width
/ m_scaleX
);
1413 height
= wxCoord(height
/ m_scaleY
);
1415 CalcBoundingBox (x
+ width
, y
+ height
);
1416 CalcBoundingBox (x
, y
);
1420 void wxWindowDC::DoDrawRotatedText( const wxString
&text
, wxCoord x
, wxCoord y
, double angle
)
1425 void wxWindowDC::DoGetTextExtent( const wxString
&string
, wxCoord
*width
, wxCoord
*height
,
1426 wxCoord
*descent
, wxCoord
*externalLeading
,
1427 wxFont
*font
) const
1429 wxCHECK_RET( Ok(), "invalid dc" );
1431 wxFont fontToUse
= m_font
;
1432 if (font
) fontToUse
= *font
;
1434 wxCHECK_RET( fontToUse
.Ok(), "invalid font" );
1436 XFontStruct
*xfont
= (XFontStruct
*) fontToUse
.GetFontStruct( m_scaleY
, m_display
);
1438 wxCHECK_RET( xfont
, wxT("invalid font") );
1440 int direction
, ascent
, descent2
;
1441 XCharStruct overall
;
1443 XTextExtents( xfont
, (char*) string
.c_str(), string
.Len(), &direction
,
1444 &ascent
, &descent2
, &overall
);
1447 *width
= (wxCoord
)( overall
.width
/ m_scaleX
);
1449 *height
= (wxCoord
)((ascent
+ descent2
) / m_scaleY
);
1451 *descent
= (wxCoord
)(descent2
/ m_scaleY
);
1452 if (externalLeading
)
1453 *externalLeading
= 0; // ??
1456 wxCoord
wxWindowDC::GetCharWidth() const
1458 wxCHECK_MSG( Ok(), 0, "invalid dc" );
1460 wxCHECK_MSG( m_font
.Ok(), 0, "invalid font" );
1462 XFontStruct
*xfont
= (XFontStruct
*) m_font
.GetFontStruct( m_scaleY
, m_display
);
1464 wxCHECK_MSG( xfont
, 0, wxT("invalid font") );
1466 int direction
, ascent
, descent
;
1467 XCharStruct overall
;
1469 XTextExtents( xfont
, "H", 1, &direction
, &ascent
, &descent
, &overall
);
1471 return (wxCoord
)(overall
.width
/ m_scaleX
);
1474 wxCoord
wxWindowDC::GetCharHeight() const
1476 wxCHECK_MSG( Ok(), 0, "invalid dc" );
1478 wxCHECK_MSG( m_font
.Ok(), 0, "invalid font" );
1480 XFontStruct
*xfont
= (XFontStruct
*) m_font
.GetFontStruct( m_scaleY
, m_display
);
1482 wxCHECK_MSG( xfont
, 0, wxT("invalid font") );
1484 int direction
, ascent
, descent
;
1485 XCharStruct overall
;
1487 XTextExtents( xfont
, "H", 1, &direction
, &ascent
, &descent
, &overall
);
1489 return (wxCoord
)((ascent
+descent
) / m_scaleY
);
1492 void wxWindowDC::Clear()
1494 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1496 if (!m_window
) return;
1498 /* - we either are a memory dc or have a window as the
1499 owner. anything else shouldn't happen.
1500 - we don't use gdk_window_clear() as we don't set
1501 the window's background colour anymore. it is too
1502 much pain to keep the DC's and the window's back-
1503 ground colour in synch. */
1508 m_owner
->GetSize( &width
, &height
);
1509 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_bgGC
, 0, 0, width
, height
);
1516 GetSize( &width
, &height
);
1517 XFillRectangle( (Display
*) m_display
, (Window
) m_window
, (GC
) m_bgGC
, 0, 0, width
, height
);
1522 void wxWindowDC::SetFont( const wxFont
&font
)
1524 wxCHECK_RET( Ok(), "invalid dc" );
1529 void wxWindowDC::SetPen( const wxPen
&pen
)
1531 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1533 if (m_pen
== pen
) return;
1537 if (!m_pen
.Ok()) return;
1539 if (!m_window
) return;
1541 int width
= m_pen
.GetWidth();
1544 // CMB: if width is non-zero scale it with the dc
1549 // X doesn't allow different width in x and y and so we take
1552 ( fabs((double) XLOG2DEVREL(width
)) +
1553 fabs((double) YLOG2DEVREL(width
)) ) / 2.0;
1557 static const wxX11Dash dotted
[] = {1, 1};
1558 static const wxX11Dash short_dashed
[] = {2, 2};
1559 static const wxX11Dash long_dashed
[] = {2, 4};
1560 static const wxX11Dash dotted_dashed
[] = {3, 3, 1, 3};
1562 // We express dash pattern in pen width unit, so we are
1563 // independent of zoom factor and so on...
1565 const wxX11Dash
*req_dash
;
1567 int lineStyle
= LineSolid
;
1568 switch (m_pen
.GetStyle())
1572 lineStyle
= LineOnOffDash
;
1573 req_nb_dash
= m_pen
.GetDashCount();
1574 req_dash
= (wxX11Dash
*)m_pen
.GetDash();
1579 lineStyle
= LineOnOffDash
;
1586 lineStyle
= LineOnOffDash
;
1588 req_dash
= long_dashed
;
1593 lineStyle
= LineOnOffDash
;
1595 req_dash
= short_dashed
;
1600 // lineStyle = LineDoubleDash;
1601 lineStyle
= LineOnOffDash
;
1603 req_dash
= dotted_dashed
;
1608 case wxSTIPPLE_MASK_OPAQUE
:
1613 lineStyle
= LineSolid
;
1614 req_dash
= (wxX11Dash
*)NULL
;
1620 int capStyle
= CapRound
;
1621 switch (m_pen
.GetCap())
1623 case wxCAP_PROJECTING
: { capStyle
= CapProjecting
; break; }
1624 case wxCAP_BUTT
: { capStyle
= CapButt
; break; }
1631 capStyle
= CapNotLast
;
1635 capStyle
= CapRound
;
1641 int joinStyle
= JoinRound
;
1642 switch (m_pen
.GetJoin())
1644 case wxJOIN_BEVEL
: { joinStyle
= JoinBevel
; break; }
1645 case wxJOIN_MITER
: { joinStyle
= JoinMiter
; break; }
1647 default: { joinStyle
= JoinRound
; break; }
1650 XSetLineAttributes( (Display
*) m_display
, (GC
) m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
1652 m_pen
.GetColour().CalcPixel( m_cmap
);
1653 XSetForeground( (Display
*) m_display
, (GC
) m_penGC
, m_pen
.GetColour().GetPixel() );
1656 void wxWindowDC::SetBrush( const wxBrush
&brush
)
1658 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1660 if (m_brush
== brush
) return;
1664 if (!m_brush
.Ok()) return;
1666 if (!m_window
) return;
1668 m_brush
.GetColour().CalcPixel( m_cmap
);
1669 XSetForeground( (Display
*) m_display
, (GC
) m_brushGC
, m_brush
.GetColour().GetPixel() );
1671 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillSolid
);
1673 if ((m_brush
.GetStyle() == wxSTIPPLE
) && (m_brush
.GetStipple()->Ok()))
1675 if (m_brush
.GetStipple()->GetPixmap())
1677 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillTiled
);
1678 XSetTile( (Display
*) m_display
, (GC
) m_brushGC
, (Pixmap
) m_brush
.GetStipple()->GetPixmap() );
1682 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillStippled
);
1683 XSetStipple( (Display
*) m_display
, (GC
) m_brushGC
, (Pixmap
) m_brush
.GetStipple()->GetBitmap() );
1687 if ((m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
) && (m_brush
.GetStipple()->GetMask()))
1689 XSetFillStyle( (Display
*) m_display
, (GC
) m_textGC
, FillOpaqueStippled
);
1690 XSetStipple( (Display
*) m_display
, (GC
) m_textGC
, (Pixmap
) m_brush
.GetStipple()->GetMask()->GetBitmap() );
1693 if (IS_HATCH(m_brush
.GetStyle()))
1695 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
, FillStippled
);
1696 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
1697 XSetStipple( (Display
*) m_display
, (GC
) m_brushGC
, hatches
[num
] );
1701 void wxWindowDC::SetBackground( const wxBrush
&brush
)
1703 /* CMB 21/7/98: Added SetBackground. Sets background brush
1704 * for Clear() and bg colour for shapes filled with cross-hatch brush */
1706 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1708 if (m_backgroundBrush
== brush
) return;
1710 m_backgroundBrush
= brush
;
1712 if (!m_backgroundBrush
.Ok()) return;
1714 if (!m_window
) return;
1716 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
1717 XSetBackground( (Display
*) m_display
, (GC
) m_brushGC
, m_backgroundBrush
.GetColour().GetPixel() );
1718 XSetBackground( (Display
*) m_display
, (GC
) m_penGC
, m_backgroundBrush
.GetColour().GetPixel() );
1719 XSetBackground( (Display
*) m_display
, (GC
) m_bgGC
, m_backgroundBrush
.GetColour().GetPixel() );
1720 XSetForeground( (Display
*) m_display
, (GC
) m_bgGC
, m_backgroundBrush
.GetColour().GetPixel() );
1722 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillSolid
);
1724 if ((m_backgroundBrush
.GetStyle() == wxSTIPPLE
) && (m_backgroundBrush
.GetStipple()->Ok()))
1726 if (m_backgroundBrush
.GetStipple()->GetPixmap())
1728 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillTiled
);
1729 XSetTile( (Display
*) m_display
, (GC
) m_bgGC
, (Pixmap
) m_backgroundBrush
.GetStipple()->GetPixmap() );
1733 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillStippled
);
1734 XSetStipple( (Display
*) m_display
, (GC
) m_bgGC
, (Pixmap
) m_backgroundBrush
.GetStipple()->GetBitmap() );
1738 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
1740 XSetFillStyle( (Display
*) m_display
, (GC
) m_bgGC
, FillStippled
);
1741 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
1742 XSetStipple( (Display
*) m_display
, (GC
) m_bgGC
, hatches
[num
] );
1746 void wxWindowDC::SetLogicalFunction( int function
)
1748 wxCHECK_RET( Ok(), "invalid dc" );
1752 if (m_logicalFunction
== function
)
1755 // VZ: shouldn't this be a CHECK?
1762 x_function
= GXclear
;
1768 x_function
= GXinvert
;
1771 x_function
= GXorReverse
;
1774 x_function
= GXandReverse
;
1783 x_function
= GXandInverted
;
1786 x_function
= GXnoop
;
1792 x_function
= GXequiv
;
1795 x_function
= GXcopyInverted
;
1798 x_function
= GXorInverted
;
1801 x_function
= GXnand
;
1808 x_function
= GXcopy
;
1812 XSetFunction( (Display
*) m_display
, (GC
) m_penGC
, x_function
);
1813 XSetFunction( (Display
*) m_display
, (GC
) m_brushGC
, x_function
);
1815 // to stay compatible with wxMSW, we don't apply ROPs to the text
1816 // operations (i.e. DrawText/DrawRotatedText).
1817 // True, but mono-bitmaps use the m_textGC and they use ROPs as well.
1818 XSetFunction( (Display
*) m_display
, (GC
) m_textGC
, x_function
);
1820 m_logicalFunction
= function
;
1823 void wxWindowDC::SetTextForeground( const wxColour
&col
)
1825 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1827 // don't set m_textForegroundColour to an invalid colour as we'd crash
1828 // later then (we use m_textForegroundColour.GetColor() without checking
1830 if ( !col
.Ok() || (m_textForegroundColour
== col
) )
1833 m_textForegroundColour
= col
;
1837 m_textForegroundColour
.CalcPixel( m_cmap
);
1838 XSetForeground( (Display
*) m_display
, (GC
) m_textGC
, m_textForegroundColour
.GetPixel() );
1842 void wxWindowDC::SetTextBackground( const wxColour
&col
)
1844 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1847 if ( !col
.Ok() || (m_textBackgroundColour
== col
) )
1850 m_textBackgroundColour
= col
;
1854 m_textBackgroundColour
.CalcPixel( m_cmap
);
1855 XSetBackground( (Display
*) m_display
, (GC
) m_textGC
, m_textBackgroundColour
.GetPixel() );
1859 void wxWindowDC::SetBackgroundMode( int mode
)
1861 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1863 m_backgroundMode
= mode
;
1866 GrSetGCUseBackground((GC
) m_textGC
, mode
== wxTRANSPARENT
? FALSE
: TRUE
);
1869 if (!m_window
) return;
1871 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
1872 // transparent/solid background mode
1874 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
1876 XSetFillStyle( (Display
*) m_display
, (GC
) m_brushGC
,
1877 (m_backgroundMode
== wxTRANSPARENT
) ? FillStippled
: FillOpaqueStippled
);
1881 void wxWindowDC::SetPalette( const wxPalette
& palette
)
1887 /* Use GetXColormap */
1888 XSetWindowColormap ((Display
*) m_display
, (Window
) m_window
->GetXWindow(),
1889 (Colormap
) palette
.GetXColormap());
1891 /* Use wxGetMainColormap */
1892 XSetWindowColormap ((Display
*) m_display
, (Window
) m_window
->GetXWindow(),
1893 (Colormap
) wxTheApp
->GetMainColormap(m_display
));
1898 void wxWindowDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
1900 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1902 if (!m_window
) return;
1905 rect
.x
= XLOG2DEV(x
);
1906 rect
.y
= YLOG2DEV(y
);
1907 rect
.width
= XLOG2DEVREL(width
);
1908 rect
.height
= YLOG2DEVREL(height
);
1910 if (!m_currentClippingRegion
.IsNull())
1911 m_currentClippingRegion
.Intersect( rect
);
1913 m_currentClippingRegion
.Union( rect
);
1915 #if USE_PAINT_REGION
1916 if (!m_paintClippingRegion
.IsNull())
1917 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1920 wxCoord xx
, yy
, ww
, hh
;
1921 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1922 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1924 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1925 XSetRegion( (Display
*) m_display
, (GC
) m_brushGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1926 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1927 XSetRegion( (Display
*) m_display
, (GC
) m_bgGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1930 void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion
& region
)
1932 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1936 DestroyClippingRegion();
1940 if (!m_window
) return;
1942 if (!m_currentClippingRegion
.IsNull())
1943 m_currentClippingRegion
.Intersect( region
);
1945 m_currentClippingRegion
.Union( region
);
1947 #if USE_PAINT_REGION
1948 if (!m_paintClippingRegion
.IsNull())
1949 m_currentClippingRegion
.Intersect( m_paintClippingRegion
);
1952 wxCoord xx
, yy
, ww
, hh
;
1953 m_currentClippingRegion
.GetBox( xx
, yy
, ww
, hh
);
1954 wxDC::DoSetClippingRegion( xx
, yy
, ww
, hh
);
1956 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1957 XSetRegion( (Display
*) m_display
, (GC
) m_brushGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1958 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1959 XSetRegion( (Display
*) m_display
, (GC
) m_bgGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1962 void wxWindowDC::DestroyClippingRegion()
1964 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1966 wxDC::DestroyClippingRegion();
1968 m_currentClippingRegion
.Clear();
1970 #if USE_PAINT_REGION
1971 if (!m_paintClippingRegion
.IsEmpty())
1972 m_currentClippingRegion
.Union( m_paintClippingRegion
);
1975 if (!m_window
) return;
1977 if (m_currentClippingRegion
.IsEmpty())
1979 XSetClipMask( (Display
*) m_display
, (GC
) m_penGC
, None
);
1980 XSetClipMask( (Display
*) m_display
, (GC
) m_brushGC
, None
);
1981 XSetClipMask( (Display
*) m_display
, (GC
) m_textGC
, None
);
1982 XSetClipMask( (Display
*) m_display
, (GC
) m_bgGC
, None
);
1986 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1987 XSetRegion( (Display
*) m_display
, (GC
) m_brushGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1988 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1989 XSetRegion( (Display
*) m_display
, (GC
) m_bgGC
, (Region
) m_currentClippingRegion
.GetX11Region() );
1993 void wxWindowDC::Destroy()
1995 if (m_penGC
) wxFreePoolGC( (GC
) m_penGC
);
1997 if (m_brushGC
) wxFreePoolGC( (GC
) m_brushGC
);
1999 if (m_textGC
) wxFreePoolGC( (GC
) m_textGC
);
2001 if (m_bgGC
) wxFreePoolGC( (GC
) m_bgGC
);
2005 void wxWindowDC::ComputeScaleAndOrigin()
2007 /* CMB: copy scale to see if it changes */
2008 double origScaleX
= m_scaleX
;
2009 double origScaleY
= m_scaleY
;
2011 wxDC::ComputeScaleAndOrigin();
2013 /* CMB: if scale has changed call SetPen to recalulate the line width */
2014 if ((m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
) &&
2017 /* this is a bit artificial, but we need to force wxDC to think
2018 the pen has changed */
2025 wxSize
wxWindowDC::GetPPI() const
2027 return wxSize(100, 100);
2030 int wxWindowDC::GetDepth() const
2032 wxFAIL_MSG(wxT("not implemented"));
2037 //-----------------------------------------------------------------------------
2039 //-----------------------------------------------------------------------------
2041 IMPLEMENT_DYNAMIC_CLASS(wxClientDC
, wxWindowDC
)
2043 wxClientDC::wxClientDC( wxWindow
*window
)
2044 : wxWindowDC( window
)
2046 wxCHECK_RET( window
, _T("NULL window in wxClientDC::wxClientDC") );
2048 m_window
= (WXWindow
*) window
->GetClientAreaWindow();
2050 // Adjust the client area when the wxWindow is not using 2 X windows.
2051 if (m_window
== (WXWindow
*) window
->GetMainWindow())
2053 wxPoint ptOrigin
= window
->GetClientAreaOrigin();
2054 SetDeviceOrigin(ptOrigin
.x
, ptOrigin
.y
);
2055 wxSize size
= window
->GetClientSize();
2056 SetClippingRegion(wxPoint(0, 0), size
);
2060 void wxClientDC::DoGetSize(int *width
, int *height
) const
2062 wxCHECK_RET( m_owner
, _T("GetSize() doesn't work without window") );
2064 m_owner
->GetClientSize( width
, height
);
2067 // ----------------------------------------------------------------------------
2069 // ----------------------------------------------------------------------------
2071 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
, wxClientDC
)
2073 wxPaintDC::wxPaintDC(wxWindow
* window
)
2074 : wxClientDC(window
)
2076 #if USE_PAINT_REGION
2077 if (!window
->GetClipPaintRegion())
2080 m_paintClippingRegion
= window
->GetUpdateRegion();
2081 Region region
= (Region
) m_paintClippingRegion
.GetX11Region();
2084 m_currentClippingRegion
.Union( m_paintClippingRegion
);
2086 XSetRegion( (Display
*) m_display
, (GC
) m_penGC
, region
);
2087 XSetRegion( (Display
*) m_display
, (GC
) m_brushGC
, region
);
2088 XSetRegion( (Display
*) m_display
, (GC
) m_textGC
, region
);
2089 XSetRegion( (Display
*) m_display
, (GC
) m_bgGC
, region
);
2091 #endif // USE_PAINT_REGION
2094 // ----------------------------------------------------------------------------
2096 // ----------------------------------------------------------------------------
2098 class wxDCModule
: public wxModule
2105 DECLARE_DYNAMIC_CLASS(wxDCModule
)
2108 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
2110 bool wxDCModule::OnInit()
2116 void wxDCModule::OnExit()