X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ab9d0a8ca3d306898d92960ecfaefb8c1191b18a..81bfc17cc63bde7034da16df0c9cb246a8738337:/src/x11/dcclient.cpp diff --git a/src/x11/dcclient.cpp b/src/x11/dcclient.cpp index 286a7018ca..c799f1fbed 100644 --- a/src/x11/dcclient.cpp +++ b/src/x11/dcclient.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: x11/dcclient.cpp +// Name: src/x11/dcclient.cpp // Purpose: wxClientDC class // Author: Julian Smart, Robert Roebling // Modified by: @@ -9,26 +9,30 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "dcclient.h" -#endif +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" #include "wx/dcclient.h" -#include "wx/dcmemory.h" -#include "wx/window.h" -#include "wx/app.h" -#include "wx/image.h" -#include "wx/module.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/window.h" + #include "wx/dcmemory.h" + #include "wx/math.h" + #include "wx/image.h" + #include "wx/module.h" +#endif + #include "wx/fontutil.h" #include "wx/x11/private.h" -#include - #if wxUSE_UNICODE #include "glib.h" #include "pango/pangox.h" -#include "pango/pangoxft.h" +#ifdef HAVE_PANGO_XFT + #include "pango/pangoxft.h" +#endif #include "pango_x.cpp" #endif @@ -1172,62 +1176,78 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, WXPixmap mask = NULL; if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap(); - if (useMask && mask) + bool setClipMask = false; + + if (!m_currentClippingRegion.IsNull() || (useMask && mask)) + { + // XSetClipMask() call is necessary (because of clip region and/or transparent mask) + setClipMask = true; + Pixmap new_pixmap = 0; + + if (!m_currentClippingRegion.IsNull()) { - WXPixmap new_mask = NULL; -#if 0 - if (!m_currentClippingRegion.IsNull()) - { - GdkColor col; - new_mask = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, 1 ); - GdkGC *gc = gdk_gc_new( new_mask ); - col.pixel = 0; - gdk_gc_set_foreground( gc, &col ); - gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh ); - col.pixel = 0; - gdk_gc_set_background( gc, &col ); - col.pixel = 1; - gdk_gc_set_foreground( gc, &col ); - gdk_gc_set_clip_region( gc, m_currentClippingRegion.GetRegion() ); - gdk_gc_set_clip_origin( gc, -xx, -yy ); - gdk_gc_set_fill( gc, GDK_OPAQUE_STIPPLED ); - gdk_gc_set_stipple( gc, mask ); - gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, ww, hh ); - gdk_gc_unref( gc ); - } -#endif - if (is_mono) + // clipping necessary => create new_pixmap + Display *xdisplay = (Display*) m_display; + int xscreen = DefaultScreen( xdisplay ); + Window xroot = RootWindow( xdisplay, xscreen ); + + new_pixmap = XCreatePixmap( xdisplay, xroot, ww, hh, 1 ); + GC gc = XCreateGC( xdisplay, new_pixmap, 0, NULL ); + + XSetForeground( xdisplay, gc, BlackPixel(xdisplay,xscreen) ); + + XSetFillStyle( xdisplay, gc, FillSolid ); + XFillRectangle( xdisplay, new_pixmap, gc, 0, 0, ww, hh ); + + XSetForeground( xdisplay, gc, WhitePixel(xdisplay,xscreen) ); + + if (useMask && mask) { - if (new_mask) - XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) new_mask ); - else - XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) mask ); - XSetClipOrigin( (Display*) m_display, (GC) m_textGC, xx, yy ); - } - else - { - if (new_mask) - XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) new_mask ); - else - XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) mask ); - XSetClipOrigin( (Display*) m_display, (GC) m_penGC, xx, yy ); + // transparent mask => call XSetStipple + XSetFillStyle( xdisplay, gc, FillStippled ); + XSetTSOrigin( xdisplay, gc, 0, 0); + XSetStipple( xdisplay, gc, (Pixmap) mask); } - if (new_mask) - XFreePixmap( (Display*) m_display, (Pixmap) new_mask ); + wxCoord clip_x, clip_y, clip_w, clip_h; + m_currentClippingRegion.GetBox(clip_x, clip_y, clip_w, clip_h); + XFillRectangle( xdisplay, new_pixmap, gc, clip_x-xx, clip_y-yy, clip_w, clip_h ); + + XFreeGC( xdisplay, gc ); + } + + if (is_mono) + { + if (new_pixmap) + XSetClipMask( (Display*) m_display, (GC) m_textGC, new_pixmap ); + else + XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) mask ); + XSetClipOrigin( (Display*) m_display, (GC) m_textGC, xx, yy ); + } + else + { + if (new_pixmap) + XSetClipMask( (Display*) m_display, (GC) m_penGC, new_pixmap ); + else + XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) mask ); + XSetClipOrigin( (Display*) m_display, (GC) m_penGC, xx, yy ); } + if (new_pixmap) + XFreePixmap( (Display*) m_display, new_pixmap ); + } + // Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For // drawing a mono-bitmap (XBitmap) we use the current text GC if (is_mono) XCopyPlane( (Display*) m_display, (Pixmap) use_bitmap.GetBitmap(), (Window) m_window, - (GC) m_textGC, 0, 0, w, h, xx, yy, 1 ); + (GC) m_textGC, 0, 0, ww, hh, xx, yy, 1 ); else XCopyArea( (Display*) m_display, (Pixmap) use_bitmap.GetPixmap(), (Window) m_window, - (GC) m_penGC, 0, 0, w, h, xx, yy ); + (GC) m_penGC, 0, 0, ww, hh, xx, yy ); // remove mask again if any - if (useMask && mask) + if (setClipMask) { if (is_mono) { @@ -1567,11 +1587,13 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) XSetFont( (Display*) m_display, (GC) m_textGC, xfont->fid ); #if !wxUSE_NANOX - if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) + // This may be a test for whether the font is 16-bit, but it also + // seems to fail for valid 8-bit fonts too. + if (1) // (xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) #endif { XDrawString( (Display*) m_display, (Window) m_window, - (GC) m_textGC, x, y + XFontStructGetAscent(xfont), text.c_str(), text.Len() ); + (GC) m_textGC, x, y + XFontStructGetAscent(xfont), text.c_str(), text.length() ); } #if 0 @@ -1647,7 +1669,7 @@ void wxWindowDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoor int direction, ascent, descent2; XCharStruct overall; - XTextExtents( xfont, (char*) string.c_str(), string.Len(), &direction, + XTextExtents( xfont, (char*) string.c_str(), string.length(), &direction, &ascent, &descent2, &overall); if (width) @@ -1668,13 +1690,11 @@ wxCoord wxWindowDC::GetCharWidth() const #if wxUSE_UNICODE PangoLayout *layout = pango_layout_new( m_context ); - if (!m_fontdesc) - { - char *crash = NULL; - *crash = 0; - } + if (m_fontdesc) + pango_layout_set_font_description(layout, m_fontdesc); + else + pango_layout_set_font_description(layout, this->GetFont().GetNativeFontInfo()->description); - pango_layout_set_font_description(layout, m_fontdesc); pango_layout_set_text(layout, "H", 1 ); int w,h; pango_layout_get_pixel_size(layout, &w, &h); @@ -1704,13 +1724,10 @@ wxCoord wxWindowDC::GetCharHeight() const #if wxUSE_UNICODE PangoLayout *layout = pango_layout_new( m_context ); - if (!m_fontdesc) - { - char *crash = NULL; - *crash = 0; - } - - pango_layout_set_font_description(layout, m_fontdesc); + if (m_fontdesc) + pango_layout_set_font_description(layout, m_fontdesc); + else + pango_layout_set_font_description(layout, this->GetFont().GetNativeFontInfo()->description); pango_layout_set_text(layout, "H", 1 ); int w,h; @@ -1769,6 +1786,12 @@ void wxWindowDC::SetFont( const wxFont &font ) wxCHECK_RET( Ok(), wxT("invalid dc") ); m_font = font; + + return; + +#if wxUSE_UNICODE + m_fontdesc = font.GetNativeFontInfo()->description; +#endif } void wxWindowDC::SetPen( const wxPen &pen ) @@ -2343,8 +2366,15 @@ wxPaintDC::wxPaintDC(wxWindow* window) class wxDCModule : public wxModule { public: - bool OnInit(); - void OnExit(); + // we must be cleaned up before wxDisplayModule which closes the global + // display + wxDCModule() + { + AddDependency(wxClassInfo::FindClass(_T("wxX11DisplayModule"))); + } + + bool OnInit() { wxInitGCPool(); return true; } + void OnExit() { wxCleanUpGCPool(); } private: DECLARE_DYNAMIC_CLASS(wxDCModule) @@ -2352,13 +2382,3 @@ private: IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule) -bool wxDCModule::OnInit() -{ - wxInitGCPool(); - return true; -} - -void wxDCModule::OnExit() -{ - wxCleanUpGCPool(); -}