X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c978d36124197b5612a2cabefed7591ad0eea6e2..e777924b358ae352f30881249f681ebb7a3ce089:/src/x11/dcclient.cpp diff --git a/src/x11/dcclient.cpp b/src/x11/dcclient.cpp index 04c54e565e..13cfe8ad9a 100644 --- a/src/x11/dcclient.cpp +++ b/src/x11/dcclient.cpp @@ -313,10 +313,37 @@ void wxWindowDC::DoGetSize( int* width, int* height ) const m_owner->GetSize(width, height); } -void wxWindowDC::DoFloodFill( wxCoord WXUNUSED(x1), wxCoord WXUNUSED(y1), - const wxColour& WXUNUSED(col), int WXUNUSED(style) ) +void wxWindowDC::DoFloodFill( wxCoord x, wxCoord y, + const wxColour & col, int style ) { - wxFAIL_MSG("not implemented"); + if (GetBrush().GetStyle() == wxTRANSPARENT) + { + wxLogDebug(wxT("In FloodFill, current brush is transparent, no filling done")); + return ; + } + int height = 0; + int width = 0; + this->GetSize(&width, &height); + //it would be nice to fail if we don't get a sensible size... + if (width < 1 || height < 1) + { + wxLogError(wxT("In FloodFill, dc.GetSize routine failed, method not supported by this DC")); + return ; + } + + //this is much faster than doing the individual pixels + wxMemoryDC memdc; + wxBitmap bitmap(width, height); + memdc.SelectObject(bitmap); + memdc.Blit(0, 0, width, height, (wxDC*) this, 0, 0); + memdc.SelectObject(wxNullBitmap); + + wxImage image(bitmap); + image.DoFloodFill (x,y, GetBrush(), col, style, GetLogicalFunction()); + bitmap = wxBitmap(image); + memdc.SelectObject(bitmap); + this->Blit(0, 0, width, height, &memdc, 0, 0); + memdc.SelectObject(wxNullBitmap); } bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const @@ -838,6 +865,7 @@ void wxWindowDC::DoDrawEllipse( wxCoord x, wxCoord y, wxCoord width, wxCoord hei void wxWindowDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y) { + DoDrawBitmap(icon, x, y, TRUE); } #if wxUSE_NANOX @@ -970,7 +998,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, bool is_mono = (bitmap.GetBitmap() != NULL); - /* scale/translate size and position */ + // scale/translate size and position int xx = XLOG2DEV(x); int yy = YLOG2DEV(y); @@ -985,7 +1013,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, int ww = XLOG2DEVREL(w); int hh = YLOG2DEVREL(h); - /* compare to current clipping region */ + // compare to current clipping region if (!m_currentClippingRegion.IsNull()) { wxRegion tmp( xx,yy,ww,hh ); @@ -994,7 +1022,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, return; } - /* scale bitmap if required */ + // scale bitmap if required wxBitmap use_bitmap; if ((w != ww) || (h != hh)) { @@ -1012,10 +1040,10 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, use_bitmap = bitmap; } - /* apply mask if any */ + // apply mask if any WXPixmap mask = NULL; if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap(); - { + if (useMask && mask) { WXPixmap new_mask = NULL; @@ -1060,10 +1088,9 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if (new_mask) XFreePixmap( (Display*) m_display, (Pixmap) new_mask ); } - } - /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For - drawing a mono-bitmap (XBitmap) we use the current text GC */ + // 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 ); @@ -1071,7 +1098,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, XCopyArea( (Display*) m_display, (Pixmap) use_bitmap.GetPixmap(), (Window) m_window, (GC) m_penGC, 0, 0, w, h, xx, yy ); - /* remove mask again if any */ + // remove mask again if any if (useMask && mask) { if (is_mono) @@ -1094,7 +1121,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, // wxUSE_NANOX/!wxUSE_NANOX bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, - wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask, + wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask ) { /* this is the nth try to get this utterly useless function to @@ -1118,13 +1145,13 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he bool use_bitmap_method = FALSE; bool is_mono = FALSE; - /* TODO: use the mask origin when drawing transparently */ + // TODO: use the mask origin when drawing transparently if (xsrcMask == -1 && ysrcMask == -1) { - xsrcMask = xsrc; ysrcMask = ysrc; + xsrcMask = xsrc; + ysrcMask = ysrc; } -#if 0 if (srcDC->m_isMemDC) { if (!memDC->m_selected.Ok()) return FALSE; @@ -1169,14 +1196,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he CalcBoundingBox( xdest, ydest ); CalcBoundingBox( xdest + width, ydest + height ); - /* scale/translate size and position */ + // scale/translate size and position wxCoord xx = XLOG2DEV(xdest); wxCoord yy = YLOG2DEV(ydest); wxCoord ww = XLOG2DEVREL(width); wxCoord hh = YLOG2DEVREL(height); - /* compare to current clipping region */ + // compare to current clipping region if (!m_currentClippingRegion.IsNull()) { wxRegion tmp( xx,yy,ww,hh ); @@ -1190,14 +1217,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he if (use_bitmap_method) { - /* scale/translate bitmap size */ + // scale/translate bitmap size wxCoord bm_width = memDC->m_selected.GetWidth(); wxCoord bm_height = memDC->m_selected.GetHeight(); wxCoord bm_ww = XLOG2DEVREL( bm_width ); wxCoord bm_hh = YLOG2DEVREL( bm_height ); - /* scale bitmap if required */ + // scale bitmap if required wxBitmap use_bitmap; if ((bm_width != bm_ww) || (bm_height != bm_hh)) @@ -1205,9 +1232,11 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxImage image( memDC->m_selected ); image = image.Scale( bm_ww, bm_hh ); +#if 0 if (is_mono) use_bitmap = image.ConvertToMonoBitmap(255,255,255); else +#endif use_bitmap = image.ConvertToBitmap(); } else @@ -1215,13 +1244,14 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he use_bitmap = memDC->m_selected; } - /* apply mask if any */ - GdkBitmap *mask = (GdkBitmap *) NULL; + // apply mask if any + WXPixmap mask = NULL; if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap(); if (useMask && mask) { - GdkBitmap *new_mask = (GdkBitmap*) NULL; + WXPixmap new_mask = NULL; +#if 0 if (!m_currentClippingRegion.IsNull()) { GdkColor col; @@ -1241,59 +1271,62 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he gdk_draw_rectangle( new_mask, gc, TRUE, 0, 0, bm_ww, bm_hh ); gdk_gc_unref( gc ); } - +#endif if (is_mono) { if (new_mask) - gdk_gc_set_clip_mask( m_textGC, new_mask ); + XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) new_mask ); else - gdk_gc_set_clip_mask( m_textGC, mask ); - gdk_gc_set_clip_origin( m_textGC, xx, yy ); + XSetClipMask( (Display*) m_display, (GC) m_textGC, (Pixmap) mask ); + XSetClipOrigin( (Display*) m_display, (GC) m_textGC, xx, yy ); } else { if (new_mask) - gdk_gc_set_clip_mask( m_penGC, new_mask ); + XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) new_mask ); else - gdk_gc_set_clip_mask( m_penGC, mask ); - gdk_gc_set_clip_origin( m_penGC, xx, yy ); + XSetClipMask( (Display*) m_display, (GC) m_penGC, (Pixmap) mask ); + XSetClipOrigin( (Display*) m_display, (GC) m_penGC, xx, yy ); } + if (new_mask) - gdk_bitmap_unref( new_mask ); + XFreePixmap( (Display*) m_display, (Pixmap) new_mask ); } - /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For - drawing a mono-bitmap (XBitmap) we use the current text GC */ + // 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) - gdk_wx_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh ); + XCopyPlane( (Display*) m_display, (Pixmap) use_bitmap.GetBitmap(), (Window) m_window, + (GC) m_textGC, xsrc, ysrc, width, height, xx, yy, 1 ); else - gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh ); + XCopyArea( (Display*) m_display, (Pixmap) use_bitmap.GetPixmap(), (Window) m_window, + (GC) m_penGC, xsrc, ysrc, width, height, xx, yy ); - /* remove mask again if any */ + // remove mask again if any if (useMask && mask) { if (is_mono) { - gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); - gdk_gc_set_clip_origin( m_textGC, 0, 0 ); + XSetClipMask( (Display*) m_display, (GC) m_textGC, None ); + XSetClipOrigin( (Display*) m_display, (GC) m_textGC, 0, 0 ); if (!m_currentClippingRegion.IsNull()) - gdk_gc_set_clip_region( m_textGC, m_currentClippingRegion.GetRegion() ); + XSetRegion( (Display*) m_display, (GC) m_textGC, (Region) m_currentClippingRegion.GetX11Region() ); } else { - gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); - gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + XSetClipMask( (Display*) m_display, (GC) m_penGC, None ); + XSetClipOrigin( (Display*) m_display, (GC) m_penGC, 0, 0 ); if (!m_currentClippingRegion.IsNull()) - gdk_gc_set_clip_region( m_penGC, m_currentClippingRegion.GetRegion() ); + XSetRegion( (Display*) m_display, (GC) m_penGC, (Region) m_currentClippingRegion.GetX11Region() ); } } } - else /* use_bitmap_method */ + else // use_bitmap_method { if ((width != ww) || (height != hh)) { - /* draw source window into a bitmap as we cannot scale + /* Draw source window into a bitmap as we cannot scale a window in contrast to a bitmap. this would actually work with memory dcs as well, but we'd lose the mask information and waste one step in this process since @@ -1308,42 +1341,38 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxBitmap bitmap( width, height ); - /* copy including child window contents */ - gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); - gdk_window_copy_area( bitmap.GetPixmap(), m_penGC, 0, 0, - srcDC->GetWindow(), - xsrc, ysrc, width, height ); - gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN ); + // copy including child window contents + XSetSubwindowMode( (Display*) m_display, (GC) m_penGC, IncludeInferiors ); + XCopyArea( (Display*) m_display, (Window) srcDC->GetWindow(), (Window) bitmap.GetPixmap(), + (GC) m_penGC, xsrc, ysrc, width, height, 0, 0 ); + XSetSubwindowMode( (Display*) m_display, (GC) m_penGC, ClipByChildren ); - /* scale image */ + // scale image wxImage image( bitmap ); image = image.Scale( ww, hh ); - /* convert to bitmap */ + // convert to bitmap bitmap = image.ConvertToBitmap(); - /* draw scaled bitmap */ - gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 ); - + // draw scaled bitmap + XCopyArea( (Display*) m_display, (Window) bitmap.GetPixmap(), (Window) m_window, + (GC) m_penGC, 0, 0, width, height, xx, yy ); } else { - /* No scaling and not a memory dc with a mask either */ - - /* copy including child window contents */ - gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS ); - gdk_window_copy_area( m_window, m_penGC, xx, yy, - srcDC->GetWindow(), - xsrc, ysrc, width, height ); - gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN ); + // No scaling and not a memory dc with a mask either + + // copy including child window contents + XSetSubwindowMode( (Display*) m_display, (GC) m_penGC, IncludeInferiors ); + XCopyArea( (Display*) m_display, (Window) srcDC->GetWindow(), (Window) m_window, + (GC) m_penGC, xsrc, ysrc, width, height, xx, yy ); + XSetSubwindowMode( (Display*) m_display, (GC) m_penGC, ClipByChildren ); } } SetLogicalFunction( old_logical_func ); + return TRUE; -#endif - - return FALSE; } void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) @@ -1359,17 +1388,32 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) x = XLOG2DEV(x); y = YLOG2DEV(y); -#if 0 - wxCoord width = gdk_string_width( font, text.mbc_str() ); - wxCoord height = font->ascent + font->descent; - - if ( m_backgroundMode == wxSOLID ) + // First draw a rectangle representing the text background, if a text + // background is specified + if (m_textBackgroundColour.Ok () && (m_backgroundMode != wxTRANSPARENT)) { - gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() ); - gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height ); - gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); + // Since X draws from the baseline of the text, must add the text height + int cx = 0; + int cy = 0; + int ascent = 0; + int slen; + int direction, descent; + + slen = strlen(text); + XCharStruct overall_return; + + (void)XTextExtents(xfont, (char*) text.c_str(), slen, &direction, + &ascent, &descent, &overall_return); + + cx = overall_return.width; + cy = ascent + descent; + m_textBackgroundColour.CalcPixel(m_cmap); + XSetForeground ((Display*) m_display, (GC) m_textGC, m_textBackgroundColour.GetPixel()); + XFillRectangle( (Display*) m_display, (Window) m_window, + (GC) m_textGC, x, y, cx, cy ); + XSetForeground ((Display*) m_display, (GC) m_textGC, m_textForegroundColour.GetPixel()); + } -#endif XSetFont( (Display*) m_display, (GC) m_textGC, xfont->fid ); #if !wxUSE_NANOX @@ -2013,64 +2057,62 @@ int wxWindowDC::GetDepth() const return -1; } +//----------------------------------------------------------------------------- +// wxClientDC +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) + +wxClientDC::wxClientDC( wxWindow *window ) + : wxWindowDC( window ) +{ + wxCHECK_RET( window, _T("NULL window in wxClientDC::wxClientDC") ); + + m_window = (WXWindow*) window->GetClientWindow(); + +#if wxUSE_TWO_WINDOWS +#else + wxPoint ptOrigin = window->GetClientAreaOrigin(); + SetDeviceOrigin(ptOrigin.x, ptOrigin.y); + wxSize size = window->GetClientSize(); + SetClippingRegion(wxPoint(0, 0), size); +#endif +} + +void wxClientDC::DoGetSize(int *width, int *height) const +{ + wxCHECK_RET( m_owner, _T("GetSize() doesn't work without window") ); + + m_owner->GetClientSize( width, height ); +} + // ---------------------------------------------------------------------------- // wxPaintDC // ---------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxClientDC) -wxPaintDC::wxPaintDC(wxWindow* win) - : wxClientDC(win) +wxPaintDC::wxPaintDC(wxWindow* window) + : wxClientDC(window) { #if USE_PAINT_REGION - if (!win->GetClipPaintRegion()) + if (!window->GetClipPaintRegion()) return; - m_paintClippingRegion = win->GetUpdateRegion(); + m_paintClippingRegion = window->GetUpdateRegion(); Region region = (Region) m_paintClippingRegion.GetX11Region(); if (region) { - m_paintClippingRegion = win->GetUpdateRegion(); - Region region2 = (Region) m_paintClippingRegion.GetX11Region(); - if (region2) - { m_currentClippingRegion.Union( m_paintClippingRegion ); - XSetRegion( (Display*) m_display, (GC) m_penGC, region2 ); - XSetRegion( (Display*) m_display, (GC) m_brushGC, region2 ); - XSetRegion( (Display*) m_display, (GC) m_textGC, region2 ); - XSetRegion( (Display*) m_display, (GC) m_bgGC, region2 ); - } + XSetRegion( (Display*) m_display, (GC) m_penGC, region ); + XSetRegion( (Display*) m_display, (GC) m_brushGC, region ); + XSetRegion( (Display*) m_display, (GC) m_textGC, region ); + XSetRegion( (Display*) m_display, (GC) m_bgGC, region ); } #endif // USE_PAINT_REGION } -//----------------------------------------------------------------------------- -// wxClientDC -//----------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) - -wxClientDC::wxClientDC( wxWindow *win ) - : wxWindowDC( win ) -{ - wxCHECK_RET( win, _T("NULL window in wxClientDC::wxClientDC") ); - -#ifdef __WXUNIVERSAL__ - wxPoint ptOrigin = win->GetClientAreaOrigin(); - SetDeviceOrigin(ptOrigin.x, ptOrigin.y); - wxSize size = win->GetClientSize(); - SetClippingRegion(wxPoint(0, 0), size); -#endif // __WXUNIVERSAL__ -} - -void wxClientDC::DoGetSize(int *width, int *height) const -{ - wxCHECK_RET( m_owner, _T("GetSize() doesn't work without window") ); - - m_owner->GetClientSize( width, height ); -} - // ---------------------------------------------------------------------------- // wxDCModule // ----------------------------------------------------------------------------