Implement bitmap mask copying in wxX11.

Copy the mask pixmap properly in wxX11, otherwise copying masks resulted in
freeing the same pixmap twice and an X error.

This fixes the bitmap unit test for wxX11.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66097 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-11-10 13:53:08 +00:00
parent 5f480c0bf1
commit 04a8da5f57
2 changed files with 26 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ class WXDLLIMPEXP_CORE wxMask: public wxObject
{ {
public: public:
wxMask(); wxMask();
wxMask(const wxMask& mask);
wxMask( const wxBitmap& bitmap, const wxColour& colour ); wxMask( const wxBitmap& bitmap, const wxColour& colour );
wxMask( const wxBitmap& bitmap, int paletteIndex ); wxMask( const wxBitmap& bitmap, int paletteIndex );
wxMask( const wxBitmap& bitmap ); wxMask( const wxBitmap& bitmap );
@@ -53,6 +54,7 @@ public:
private: private:
WXPixmap m_bitmap; WXPixmap m_bitmap;
WXDisplay *m_display; WXDisplay *m_display;
wxSize m_size;
private: private:
DECLARE_DYNAMIC_CLASS(wxMask) DECLARE_DYNAMIC_CLASS(wxMask)

View File

@@ -34,6 +34,10 @@
bool wxGetImageFromDrawable(GR_DRAW_ID drawable, int srcX, int srcY, int width, int height, wxImage& image); bool wxGetImageFromDrawable(GR_DRAW_ID drawable, int srcX, int srcY, int width, int height, wxImage& image);
#endif #endif
static WXPixmap wxGetSubPixmap( WXDisplay* xdisplay, WXPixmap xpixmap,
int x, int y, int width, int height,
int depth );
#if wxUSE_XPM #if wxUSE_XPM
#if wxHAVE_LIB_XPM #if wxHAVE_LIB_XPM
#include <X11/xpm.h> #include <X11/xpm.h>
@@ -55,6 +59,24 @@ wxMask::wxMask()
m_display = NULL; m_display = NULL;
} }
wxMask::wxMask(const wxMask& mask)
{
m_display = mask.m_display;
if ( !mask.m_bitmap )
{
m_bitmap = NULL;
return;
}
m_size = mask.m_size;
// Duplicate the mask bitmap using the existing wxGetSubPixmap() function.
// There are probably/surely better ways to do it.
m_bitmap = wxGetSubPixmap(m_display, mask.m_bitmap,
0, 0, m_size.x, m_size.y,
1);
}
wxMask::wxMask( const wxBitmap& bitmap, const wxColour& colour ) wxMask::wxMask( const wxBitmap& bitmap, const wxColour& colour )
{ {
m_bitmap = NULL; m_bitmap = NULL;
@@ -82,6 +104,8 @@ wxMask::~wxMask()
bool wxMask::Create( const wxBitmap& bitmap, bool wxMask::Create( const wxBitmap& bitmap,
const wxColour& colour ) const wxColour& colour )
{ {
m_size = bitmap.GetSize();
#if !wxUSE_NANOX #if !wxUSE_NANOX
if (m_bitmap) if (m_bitmap)
{ {