#include "wx/dcmemory.h"
#include "wx/image.h"
#include "wx/module.h"
+#include "wx/log.h"
#include "wx/gtk/win_gtk.h"
static GdkPixmap *hatches[num_hatches];
static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL;
-extern GtkWidget *wxRootWindow;
+extern GtkWidget *wxGetRootWindow();
//-----------------------------------------------------------------------------
// constants
#include "gdk/gdkprivate.h"
-void gdk_wx_draw_bitmap (GdkDrawable *drawable,
- GdkGC *gc,
- GdkDrawable *src,
- gint xsrc,
- gint ysrc,
- gint xdest,
- gint ydest,
- gint width,
- gint height)
+void gdk_wx_draw_bitmap(GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkDrawable *src,
+ gint xsrc,
+ gint ysrc,
+ gint xdest,
+ gint ydest,
+ gint width,
+ gint height)
{
gint src_width, src_height;
#ifndef __WXGTK20__
wxWindowDC::wxWindowDC( wxWindow *window )
{
+ wxASSERT_MSG( window, wxT("DC needs a window") );
+
m_penGC = (GdkGC *) NULL;
m_brushGC = (GdkGC *) NULL;
m_textGC = (GdkGC *) NULL;
m_isScreenDC = FALSE;
m_font = window->GetFont();
- wxASSERT_MSG( window, wxT("DC needs a window") );
-
GtkWidget *widget = window->m_wxwindow;
// some controls don't have m_wxwindow - like wxStaticBox, but the user
m_owner->GetSize(width, height);
}
-void wxWindowDC::DoFloodFill( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
- const wxColour &WXUNUSED(col), int WXUNUSED(style) )
+extern void wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
+ const wxColour & col, int style);
+
+void wxWindowDC::DoFloodFill(wxCoord x, wxCoord y,
+ const wxColour& col, int style)
{
- wxFAIL_MSG( wxT("wxWindowDC::DoFloodFill not implemented") );
+ wxDoFloodFill(this, x, y, col, style);
}
bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const
memdc.SelectObject(bitmap);
memdc.Blit(0, 0, 1, 1, (wxDC*) this, x1, y1);
memdc.SelectObject(wxNullBitmap);
-
- wxImage image(bitmap);
+
+ wxImage image = bitmap.ConvertToImage();
col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0));
return TRUE;
}
gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 );
}
- CalcBoundingBox( x - width, y - height );
+ CalcBoundingBox( x, y );
CalcBoundingBox( x + width, y + height );
}
wxBitmap use_bitmap;
if ((w != ww) || (h != hh))
{
- wxImage image( bitmap );
+ wxImage image = bitmap.ConvertToImage();
image.Rescale( ww, hh );
if (is_mono)
- use_bitmap = image.ConvertToMonoBitmap(255,255,255);
+ use_bitmap = wxBitmap(image.ConvertToMono(255,255,255), 1);
else
- use_bitmap = image.ConvertToBitmap();
+ use_bitmap = wxBitmap(image);
}
else
{
use_bitmap = bitmap;
}
-
+
/* apply mask if any */
GdkBitmap *mask = (GdkBitmap *) NULL;
if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap();
if (useMask && mask)
{
GdkBitmap *new_mask = (GdkBitmap*) NULL;
+#ifndef __WXGTK20__ // TODO fix crash
if (!m_currentClippingRegion.IsNull())
{
GdkColor col;
- new_mask = gdk_pixmap_new( wxRootWindow->window, ww, hh, 1 );
+ 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 );
gdk_gc_unref( gc );
}
-
+#endif
if (is_mono)
{
if (new_mask)
gdk_gc_set_clip_mask( m_penGC, mask );
gdk_gc_set_clip_origin( m_penGC, xx, yy );
}
+
if (new_mask)
gdk_bitmap_unref( new_mask );
}
}
}
-bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
- wxDC *source, wxCoord xsrc, wxCoord ysrc,
- int logical_func, bool useMask )
+bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
+ wxCoord width, wxCoord height,
+ 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
work. it now completely ignores the scaling or translation
if (!m_window) return FALSE;
+#if 1
+ // transform the source DC coords to the device ones
+ xsrc = source->XLOG2DEV(xsrc);
+ ysrc = source->YLOG2DEV(ysrc);
+#endif
+
wxClientDC *srcDC = (wxClientDC*)source;
wxMemoryDC *memDC = (wxMemoryDC*)source;
bool use_bitmap_method = FALSE;
bool is_mono = FALSE;
+ /* TODO: use the mask origin when drawing transparently */
+ if (xsrcMask == -1 && ysrcMask == -1)
+ {
+ xsrcMask = xsrc; ysrcMask = ysrc;
+ }
+
if (srcDC->m_isMemDC)
{
if (!memDC->m_selected.Ok()) return FALSE;
if ((bm_width != bm_ww) || (bm_height != bm_hh))
{
- wxImage image( memDC->m_selected );
+ wxImage image = memDC->m_selected.ConvertToImage();
image = image.Scale( bm_ww, bm_hh );
if (is_mono)
- use_bitmap = image.ConvertToMonoBitmap(255,255,255);
+ use_bitmap = wxBitmap(image.ConvertToMono(255,255,255), 1);
else
- use_bitmap = image.ConvertToBitmap();
+ use_bitmap = wxBitmap(image);
}
else
{
if (useMask && mask)
{
GdkBitmap *new_mask = (GdkBitmap*) NULL;
+#ifndef __WXGTK20__ // TODO fix crash
if (!m_currentClippingRegion.IsNull())
{
GdkColor col;
- new_mask = gdk_pixmap_new( wxRootWindow->window, bm_ww, bm_hh, 1 );
+ new_mask = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_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, bm_ww, bm_hh );
gdk_gc_unref( gc );
}
-
+#endif
if (is_mono)
{
if (new_mask)
gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
/* scale image */
- wxImage image( bitmap );
+ wxImage image = bitmap.ConvertToImage();
image = image.Scale( ww, hh );
/* convert to bitmap */
- bitmap = image.ConvertToBitmap();
+ bitmap = wxBitmap(image);
/* draw scaled bitmap */
gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
y = YLOG2DEV(y);
#if defined(__WXGTK20__) && wxUSE_WCHAR_T
- /* FIXME: the layout engine should probably be abstracted at a higher level in wxDC... */
+ // TODO: the layout engine should be abstracted at a higher level!
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
{
- wxWX2MBbuf data = text.mb_str(wxConvUTF8);
+ const wxWX2MBbuf data = text.mb_str(wxConvUTF8);
pango_layout_set_text(layout, data, strlen(data));
}
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
wxCoord width = rect.width;
wxCoord height = rect.height;
gdk_draw_layout( m_window, m_textGC, x, y, layout );
-#else
+#else // GTK+ 1.x
wxCoord width = gdk_string_width( font, text.mbc_str() );
wxCoord height = font->ascent + font->descent;
- /* CMB 21/5/98: draw text background if mode is wxSOLID */
- if (m_backgroundMode == wxSOLID)
+
+ if ( m_backgroundMode == wxSOLID )
{
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() );
}
gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
-#endif
+#endif // GTK+ 2.0/1.x
/* CMB 17/7/98: simple underline: ignores scaling and underlying
X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
dc.SetBrush(*wxBLACK_BRUSH);
dc.Clear();
dc.DrawText(text, 0, 0);
- dc.SetFont(wxNullFont);
dc.SelectObject(wxNullBitmap);
// Calculate the size of the rotated bounding box.
minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
// prepare to blit-with-rotate the bitmap to the DC
- wxImage image(src);
+ wxImage image = src.ConvertToImage();
GdkColor *colText = m_textForegroundColour.GetColor(),
*colBack = m_textBackgroundColour.GetColor();
void wxWindowDC::SetFont( const wxFont &font )
{
+ wxCHECK_RET( font.Ok(), _T("invalid font in wxWindowDC::SetFont") );
+
m_font = font;
#ifdef __WXGTK20__
// fix fontdesc?
{
wxCHECK_RET( Ok(), wxT("invalid window dc") );
- if (m_textForegroundColour == col) return;
+ // don't set m_textForegroundColour to an invalid colour as we'd crash
+ // later then (we use m_textForegroundColour.GetColor() without checking
+ // in a few places)
+ if ( !col.Ok() || (m_textForegroundColour == col) )
+ return;
m_textForegroundColour = col;
- if (!m_textForegroundColour.Ok()) return;
- if (!m_window) return;
-
- m_textForegroundColour.CalcPixel( m_cmap );
- gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
+ if ( m_window )
+ {
+ m_textForegroundColour.CalcPixel( m_cmap );
+ gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
+ }
}
void wxWindowDC::SetTextBackground( const wxColour &col )
{
wxCHECK_RET( Ok(), wxT("invalid window dc") );
- if (m_textBackgroundColour == col) return;
+ // same as above
+ if ( !col.Ok() || (m_textBackgroundColour == col) )
+ return;
m_textBackgroundColour = col;
- if (!m_textBackgroundColour.Ok()) return;
- if (!m_window) return;
-
- m_textBackgroundColour.CalcPixel( m_cmap );
- gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
+ if ( m_window )
+ {
+ m_textBackgroundColour.CalcPixel( m_cmap );
+ gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() );
+ }
}
void wxWindowDC::SetBackgroundMode( int mode )
GdkRegion *region = m_paintClippingRegion.GetRegion();
if ( region )
{
- m_currentClippingRegion.Union( m_paintClippingRegion );
+ m_paintClippingRegion = win->GetUpdateRegion();
+ GdkRegion *region = m_paintClippingRegion.GetRegion();
+ if ( region )
+ {
+ m_currentClippingRegion.Union( m_paintClippingRegion );
- gdk_gc_set_clip_region( m_penGC, region );
- gdk_gc_set_clip_region( m_brushGC, region );
- gdk_gc_set_clip_region( m_textGC, region );
- gdk_gc_set_clip_region( m_bgGC, region );
+ gdk_gc_set_clip_region( m_penGC, region );
+ gdk_gc_set_clip_region( m_brushGC, region );
+ gdk_gc_set_clip_region( m_textGC, region );
+ gdk_gc_set_clip_region( m_bgGC, region );
+ }
}
-#endif
+#endif // USE_PAINT_REGION
}
//-----------------------------------------------------------------------------
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