2002-03-17 01:34:06 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/dcbuffer.h
|
|
|
|
// Purpose: wxBufferedDC class
|
|
|
|
// Author: Ron Lee <ron@debian.org>
|
2004-02-07 11:16:36 -05:00
|
|
|
// Modified by: Vadim Zeitlin (refactored, added bg preservation)
|
2002-03-17 01:34:06 -05:00
|
|
|
// Created: 16/03/02
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Ron Lee
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2002-03-17 01:34:06 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_DCBUFFER_H_
|
|
|
|
#define _WX_DCBUFFER_H_
|
|
|
|
|
|
|
|
#include "wx/dcmemory.h"
|
2003-07-21 14:57:04 -04:00
|
|
|
#include "wx/dcclient.h"
|
2005-01-07 13:24:54 -05:00
|
|
|
#include "wx/window.h"
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2006-10-09 12:39:34 -04:00
|
|
|
// Split platforms into two groups - those which have well-working
|
|
|
|
// double-buffering by default, and those which do not.
|
2006-10-18 18:36:36 -04:00
|
|
|
#if defined(__WXMAC__) || defined(__WXGTK20__) || defined(__WXDFB__)
|
2006-10-09 12:39:34 -04:00
|
|
|
#define wxALWAYS_NATIVE_DOUBLE_BUFFER 1
|
|
|
|
#else
|
|
|
|
#define wxALWAYS_NATIVE_DOUBLE_BUFFER 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Double buffering helper.
|
|
|
|
// ----------------------------------------------------------------------------
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2005-03-03 01:56:15 -05:00
|
|
|
// Assumes the buffer bitmap covers the entire scrolled window,
|
|
|
|
// and prepares the window DC accordingly
|
|
|
|
#define wxBUFFER_VIRTUAL_AREA 0x01
|
|
|
|
|
|
|
|
// Assumes the buffer bitmap only covers the client area;
|
|
|
|
// does not prepare the window DC
|
|
|
|
#define wxBUFFER_CLIENT_AREA 0x02
|
|
|
|
|
2007-03-10 13:09:38 -05:00
|
|
|
// Set when not using specific buffer bitmap. Note that this
|
|
|
|
// is private style and not returned by GetStyle.
|
|
|
|
#define wxBUFFER_USES_SHARED_BUFFER 0x04
|
|
|
|
|
2007-11-30 08:48:22 -05:00
|
|
|
class WXDLLIMPEXP_CORE wxBufferedDC : public wxMemoryDC
|
2004-02-07 11:16:36 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Default ctor, must subsequently call Init for two stage construction.
|
2006-10-22 09:00:58 -04:00
|
|
|
wxBufferedDC()
|
|
|
|
: m_dc(NULL),
|
2006-10-31 21:07:36 -05:00
|
|
|
m_buffer(NULL),
|
2006-10-22 09:00:58 -04:00
|
|
|
m_style(0)
|
2004-02-07 11:16:36 -05:00
|
|
|
{
|
|
|
|
}
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// Construct a wxBufferedDC using a user supplied buffer.
|
2005-03-07 19:38:53 -05:00
|
|
|
wxBufferedDC(wxDC *dc,
|
2006-10-31 21:07:36 -05:00
|
|
|
wxBitmap& buffer = wxNullBitmap,
|
2005-03-07 19:38:53 -05:00
|
|
|
int style = wxBUFFER_CLIENT_AREA)
|
2006-10-31 21:07:36 -05:00
|
|
|
: m_dc(NULL), m_buffer(NULL)
|
2004-02-19 01:23:01 -05:00
|
|
|
{
|
2006-10-22 09:04:28 -04:00
|
|
|
Init(dc, buffer, style);
|
2004-02-19 01:23:01 -05:00
|
|
|
}
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// Construct a wxBufferedDC with an internal buffer of 'area'
|
|
|
|
// (where area is usually something like the size of the window
|
|
|
|
// being buffered)
|
2006-10-22 09:04:28 -04:00
|
|
|
wxBufferedDC(wxDC *dc, const wxSize& area, int style = wxBUFFER_CLIENT_AREA)
|
2006-10-31 21:07:36 -05:00
|
|
|
: m_dc(NULL), m_buffer(NULL)
|
2004-02-19 01:23:01 -05:00
|
|
|
{
|
2006-10-22 09:04:28 -04:00
|
|
|
Init(dc, area, style);
|
2004-02-19 01:23:01 -05:00
|
|
|
}
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// The usually desired action in the dtor is to blit the buffer.
|
2004-02-19 01:23:01 -05:00
|
|
|
virtual ~wxBufferedDC()
|
|
|
|
{
|
2006-10-22 09:00:58 -04:00
|
|
|
if ( m_dc )
|
|
|
|
UnMask();
|
2004-02-19 01:23:01 -05:00
|
|
|
}
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2006-10-22 09:04:28 -04:00
|
|
|
// These reimplement the actions of the ctors for two stage creation
|
2005-03-07 19:38:53 -05:00
|
|
|
void Init(wxDC *dc,
|
2006-10-31 21:07:36 -05:00
|
|
|
wxBitmap& buffer = wxNullBitmap,
|
2005-03-07 19:38:53 -05:00
|
|
|
int style = wxBUFFER_CLIENT_AREA)
|
2004-02-19 01:23:01 -05:00
|
|
|
{
|
2006-10-22 09:00:58 -04:00
|
|
|
InitCommon(dc, style);
|
|
|
|
|
2006-10-31 21:07:36 -05:00
|
|
|
m_buffer = &buffer;
|
2006-10-22 09:00:58 -04:00
|
|
|
|
2004-02-19 01:23:01 -05:00
|
|
|
UseBuffer();
|
|
|
|
}
|
|
|
|
|
2006-10-13 15:14:21 -04:00
|
|
|
void Init(wxDC *dc, const wxSize &area, int style = wxBUFFER_CLIENT_AREA)
|
2004-02-19 01:23:01 -05:00
|
|
|
{
|
2006-10-22 09:00:58 -04:00
|
|
|
InitCommon(dc, style);
|
|
|
|
|
2006-10-18 18:36:36 -04:00
|
|
|
UseBuffer(area.x, area.y);
|
2004-02-19 01:23:01 -05:00
|
|
|
}
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// Blits the buffer to the dc, and detaches the dc from the buffer (so it
|
|
|
|
// can be effectively used once only).
|
|
|
|
//
|
|
|
|
// Usually called in the dtor or by the dtor of derived classes if the
|
|
|
|
// BufferedDC must blit before the derived class (which may own the dc it's
|
|
|
|
// blitting to) is destroyed.
|
2007-03-10 13:09:38 -05:00
|
|
|
void UnMask();
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2005-03-03 01:56:15 -05:00
|
|
|
// Set and get the style
|
|
|
|
void SetStyle(int style) { m_style = style; }
|
2007-03-10 13:09:38 -05:00
|
|
|
int GetStyle() const { return m_style & ~wxBUFFER_USES_SHARED_BUFFER; }
|
2005-03-03 01:56:15 -05:00
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
private:
|
2006-10-22 09:00:58 -04:00
|
|
|
// common part of Init()s
|
|
|
|
void InitCommon(wxDC *dc, int style)
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxASSERT_MSG( !m_dc, wxT("wxBufferedDC already initialised") );
|
2006-10-22 09:00:58 -04:00
|
|
|
|
|
|
|
m_dc = dc;
|
|
|
|
m_style = style;
|
|
|
|
}
|
|
|
|
|
2006-10-13 15:14:21 -04:00
|
|
|
// check that the bitmap is valid and use it
|
2006-10-18 18:36:36 -04:00
|
|
|
void UseBuffer(wxCoord w = -1, wxCoord h = -1);
|
2004-02-07 11:16:36 -05:00
|
|
|
|
2006-10-13 15:14:21 -04:00
|
|
|
// the underlying DC to which we copy everything drawn on this one in
|
|
|
|
// UnMask()
|
2004-02-08 13:54:04 -05:00
|
|
|
//
|
|
|
|
// NB: Without the existence of a wxNullDC, this must be a pointer, else it
|
|
|
|
// could probably be a reference.
|
2006-10-13 15:14:21 -04:00
|
|
|
wxDC *m_dc;
|
2002-03-17 01:34:06 -05:00
|
|
|
|
2006-10-23 18:06:01 -04:00
|
|
|
// the buffer (selected in this DC), initially invalid
|
2006-10-31 21:07:36 -05:00
|
|
|
wxBitmap *m_buffer;
|
2003-01-02 18:38:11 -05:00
|
|
|
|
2005-03-03 01:56:15 -05:00
|
|
|
// the buffering style
|
2006-10-13 15:14:21 -04:00
|
|
|
int m_style;
|
2005-03-03 01:56:15 -05:00
|
|
|
|
2006-10-15 11:45:13 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxBufferedDC)
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxBufferedDC);
|
2002-03-17 01:34:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Double buffered PaintDC.
|
|
|
|
// ----------------------------------------------------------------------------
|
2002-03-17 01:34:06 -05:00
|
|
|
|
|
|
|
// Creates a double buffered wxPaintDC, optionally allowing the
|
|
|
|
// user to specify their own buffer to use.
|
2007-11-30 08:48:22 -05:00
|
|
|
class WXDLLIMPEXP_CORE wxBufferedPaintDC : public wxBufferedDC
|
2002-03-17 01:34:06 -05:00
|
|
|
{
|
|
|
|
public:
|
2005-03-03 01:56:15 -05:00
|
|
|
// If no bitmap is supplied by the user, a temporary one will be created.
|
2006-10-31 21:07:36 -05:00
|
|
|
wxBufferedPaintDC(wxWindow *window, wxBitmap& buffer, int style = wxBUFFER_CLIENT_AREA)
|
2004-02-07 16:50:39 -05:00
|
|
|
: m_paintdc(window)
|
2004-02-07 11:16:36 -05:00
|
|
|
{
|
2005-03-03 01:56:15 -05:00
|
|
|
// If we're buffering the virtual window, scale the paint DC as well
|
|
|
|
if (style & wxBUFFER_VIRTUAL_AREA)
|
|
|
|
window->PrepareDC( m_paintdc );
|
|
|
|
|
2006-10-30 14:26:48 -05:00
|
|
|
if( buffer.IsOk() )
|
2005-03-03 01:56:15 -05:00
|
|
|
Init(&m_paintdc, buffer, style);
|
2004-02-19 01:23:01 -05:00
|
|
|
else
|
2007-03-05 03:54:13 -05:00
|
|
|
Init(&m_paintdc, GetBufferedSize(window, style), style);
|
2005-03-03 01:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// If no bitmap is supplied by the user, a temporary one will be created.
|
|
|
|
wxBufferedPaintDC(wxWindow *window, int style = wxBUFFER_CLIENT_AREA)
|
|
|
|
: m_paintdc(window)
|
|
|
|
{
|
|
|
|
// If we're using the virtual window, scale the paint DC as well
|
|
|
|
if (style & wxBUFFER_VIRTUAL_AREA)
|
|
|
|
window->PrepareDC( m_paintdc );
|
|
|
|
|
2007-03-05 03:54:13 -05:00
|
|
|
Init(&m_paintdc, GetBufferedSize(window, style), style);
|
2004-02-07 11:16:36 -05:00
|
|
|
}
|
2002-03-17 01:34:06 -05:00
|
|
|
|
|
|
|
// default copy ctor ok.
|
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
virtual ~wxBufferedPaintDC()
|
|
|
|
{
|
|
|
|
// We must UnMask here, else by the time the base class
|
|
|
|
// does it, the PaintDC will have already been destroyed.
|
|
|
|
UnMask();
|
|
|
|
}
|
|
|
|
|
2007-03-05 03:54:13 -05:00
|
|
|
protected:
|
|
|
|
// return the size needed by the buffer: this depends on whether we're
|
|
|
|
// buffering just the currently shown part or the total (scrolled) window
|
|
|
|
static wxSize GetBufferedSize(wxWindow *window, int style)
|
|
|
|
{
|
|
|
|
return style & wxBUFFER_VIRTUAL_AREA ? window->GetVirtualSize()
|
|
|
|
: window->GetClientSize();
|
|
|
|
}
|
|
|
|
|
2004-02-07 11:16:36 -05:00
|
|
|
private:
|
|
|
|
wxPaintDC m_paintdc;
|
2003-07-21 20:24:07 -04:00
|
|
|
|
2006-10-15 11:45:13 -04:00
|
|
|
DECLARE_ABSTRACT_CLASS(wxBufferedPaintDC)
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxBufferedPaintDC);
|
2002-03-17 01:34:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-10-09 12:39:34 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// wxAutoBufferedPaintDC is a wxPaintDC in toolkits which have double-
|
|
|
|
// buffering by default. Otherwise it is a wxBufferedPaintDC. Thus,
|
|
|
|
// you can only expect it work with a simple constructor that
|
|
|
|
// accepts single wxWindow* argument.
|
|
|
|
//
|
|
|
|
#if wxALWAYS_NATIVE_DOUBLE_BUFFER
|
|
|
|
#define wxAutoBufferedPaintDCBase wxPaintDC
|
|
|
|
#else
|
|
|
|
#define wxAutoBufferedPaintDCBase wxBufferedPaintDC
|
|
|
|
#endif
|
|
|
|
|
2007-11-30 08:48:22 -05:00
|
|
|
class WXDLLIMPEXP_CORE wxAutoBufferedPaintDC : public wxAutoBufferedPaintDCBase
|
2006-10-09 12:39:34 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
wxAutoBufferedPaintDC(wxWindow* win)
|
|
|
|
: wxAutoBufferedPaintDCBase(win)
|
|
|
|
{
|
2009-06-16 19:04:42 -04:00
|
|
|
wxASSERT_MSG( win->GetBackgroundStyle() == wxBG_STYLE_PAINT,
|
|
|
|
"You need to call SetBackgroundStyle(wxBG_STYLE_PAINT) in ctor, "
|
2009-03-21 19:36:37 -04:00
|
|
|
"and also, if needed, paint the background in wxEVT_PAINT handler."
|
|
|
|
);
|
2006-10-09 12:39:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~wxAutoBufferedPaintDC() { }
|
|
|
|
|
|
|
|
private:
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxAutoBufferedPaintDC);
|
2006-10-09 12:39:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-10-13 15:14:21 -04:00
|
|
|
// Check if the window is natively double buffered and will return a wxPaintDC
|
|
|
|
// if it is, a wxBufferedPaintDC otherwise. It is the caller's responsibility
|
|
|
|
// to delete the wxDC pointer when finished with it.
|
|
|
|
inline wxDC* wxAutoBufferedPaintDCFactory(wxWindow* window)
|
|
|
|
{
|
|
|
|
if ( window->IsDoubleBuffered() )
|
|
|
|
return new wxPaintDC(window);
|
|
|
|
else
|
|
|
|
return new wxBufferedPaintDC(window);
|
|
|
|
}
|
|
|
|
|
2006-10-09 12:39:34 -04:00
|
|
|
#endif // _WX_DCBUFFER_H_
|