Add possibility to create a wxImage from
static data (or data on the stack) without using the heap. Tried to fix the crash-all-apps problem reported in the list. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7359 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -89,6 +89,7 @@ class WXDLLEXPORT wxImage: public wxObject
|
|||||||
public:
|
public:
|
||||||
wxImage();
|
wxImage();
|
||||||
wxImage( int width, int height );
|
wxImage( int width, int height );
|
||||||
|
wxImage( int width, int height, unsigned char* data, bool static_data = FALSE );
|
||||||
wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
|
wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
|
||||||
wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
|
wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
|
||||||
wxImage( const wxString& name, const wxString& mimetype );
|
wxImage( const wxString& name, const wxString& mimetype );
|
||||||
@@ -106,6 +107,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Create( int width, int height );
|
void Create( int width, int height );
|
||||||
|
void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
// return the new image with size width*height
|
// return the new image with size width*height
|
||||||
@@ -156,7 +158,8 @@ public:
|
|||||||
|
|
||||||
char unsigned *GetData() const;
|
char unsigned *GetData() const;
|
||||||
void SetData( char unsigned *data );
|
void SetData( char unsigned *data );
|
||||||
|
void SetData( char unsigned *data, int new_width, int new_height );
|
||||||
|
|
||||||
void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
|
void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
|
||||||
unsigned char GetMaskRed() const;
|
unsigned char GetMaskRed() const;
|
||||||
unsigned char GetMaskGreen() const;
|
unsigned char GetMaskGreen() const;
|
||||||
|
@@ -56,6 +56,7 @@ public:
|
|||||||
bool m_hasMask;
|
bool m_hasMask;
|
||||||
unsigned char m_maskRed,m_maskGreen,m_maskBlue;
|
unsigned char m_maskRed,m_maskGreen,m_maskBlue;
|
||||||
bool m_ok;
|
bool m_ok;
|
||||||
|
bool m_static;
|
||||||
};
|
};
|
||||||
|
|
||||||
wxImageRefData::wxImageRefData()
|
wxImageRefData::wxImageRefData()
|
||||||
@@ -68,11 +69,12 @@ wxImageRefData::wxImageRefData()
|
|||||||
m_maskGreen = 0;
|
m_maskGreen = 0;
|
||||||
m_maskBlue = 0;
|
m_maskBlue = 0;
|
||||||
m_hasMask = FALSE;
|
m_hasMask = FALSE;
|
||||||
|
m_static = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxImageRefData::~wxImageRefData()
|
wxImageRefData::~wxImageRefData()
|
||||||
{
|
{
|
||||||
if (m_data)
|
if (m_data && !m_static)
|
||||||
free( m_data );
|
free( m_data );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +95,11 @@ wxImage::wxImage( int width, int height )
|
|||||||
Create( width, height );
|
Create( width, height );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxImage::wxImage( int width, int height, unsigned char* data, bool static_data )
|
||||||
|
{
|
||||||
|
Create( width, height, data, static_data );
|
||||||
|
}
|
||||||
|
|
||||||
wxImage::wxImage( const wxString& name, long type )
|
wxImage::wxImage( const wxString& name, long type )
|
||||||
{
|
{
|
||||||
LoadFile( name, type );
|
LoadFile( name, type );
|
||||||
@@ -146,6 +153,26 @@ void wxImage::Create( int width, int height )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxImage::Create( int width, int height, unsigned char* data, bool static_data )
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
m_refData = new wxImageRefData();
|
||||||
|
|
||||||
|
M_IMGDATA->m_data = data;
|
||||||
|
if (M_IMGDATA->m_data)
|
||||||
|
{
|
||||||
|
M_IMGDATA->m_width = width;
|
||||||
|
M_IMGDATA->m_height = height;
|
||||||
|
M_IMGDATA->m_ok = TRUE;
|
||||||
|
M_IMGDATA->m_static = static_data;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxImage::Destroy()
|
void wxImage::Destroy()
|
||||||
{
|
{
|
||||||
UnRef();
|
UnRef();
|
||||||
@@ -340,6 +367,34 @@ void wxImage::SetData( char unsigned *data )
|
|||||||
m_refData = newRefData;
|
m_refData = newRefData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxImage::SetData( char unsigned *data, int new_width, int new_height )
|
||||||
|
{
|
||||||
|
wxImageRefData *newRefData = new wxImageRefData();
|
||||||
|
|
||||||
|
if (m_refData)
|
||||||
|
{
|
||||||
|
newRefData->m_width = new_width;
|
||||||
|
newRefData->m_height = new_height;
|
||||||
|
newRefData->m_data = data;
|
||||||
|
newRefData->m_ok = TRUE;
|
||||||
|
newRefData->m_maskRed = M_IMGDATA->m_maskRed;
|
||||||
|
newRefData->m_maskGreen = M_IMGDATA->m_maskGreen;
|
||||||
|
newRefData->m_maskBlue = M_IMGDATA->m_maskBlue;
|
||||||
|
newRefData->m_hasMask = M_IMGDATA->m_hasMask;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newRefData->m_width = new_width;
|
||||||
|
newRefData->m_height = new_height;
|
||||||
|
newRefData->m_data = data;
|
||||||
|
newRefData->m_ok = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
m_refData = newRefData;
|
||||||
|
}
|
||||||
|
|
||||||
void wxImage::SetMaskColour( unsigned char r, unsigned char g, unsigned char b )
|
void wxImage::SetMaskColour( unsigned char r, unsigned char g, unsigned char b )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( Ok(), wxT("invalid image") );
|
wxCHECK_RET( Ok(), wxT("invalid image") );
|
||||||
|
@@ -2579,9 +2579,15 @@ void wxWindow::OnInternalIdle()
|
|||||||
|
|
||||||
bool child_already_resized = FALSE;
|
bool child_already_resized = FALSE;
|
||||||
if (IsTopLevel() && !m_isFrame)
|
if (IsTopLevel() && !m_isFrame)
|
||||||
child_already_resized = gtk_pizza_child_resized( GTK_PIZZA(m_wxwindow->parent), m_wxwindow );
|
{
|
||||||
|
child_already_resized = ((m_wxwindow->parent) &&
|
||||||
|
(gtk_pizza_child_resized( GTK_PIZZA(m_wxwindow->parent), m_wxwindow )));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
child_already_resized = gtk_pizza_child_resized( GTK_PIZZA(m_widget->parent), m_widget );
|
{
|
||||||
|
child_already_resized = ((m_widget->parent) &&
|
||||||
|
(gtk_pizza_child_resized( GTK_PIZZA(m_widget->parent), m_widget )));
|
||||||
|
}
|
||||||
|
|
||||||
if (child_already_resized)
|
if (child_already_resized)
|
||||||
{
|
{
|
||||||
|
@@ -2579,9 +2579,15 @@ void wxWindow::OnInternalIdle()
|
|||||||
|
|
||||||
bool child_already_resized = FALSE;
|
bool child_already_resized = FALSE;
|
||||||
if (IsTopLevel() && !m_isFrame)
|
if (IsTopLevel() && !m_isFrame)
|
||||||
child_already_resized = gtk_pizza_child_resized( GTK_PIZZA(m_wxwindow->parent), m_wxwindow );
|
{
|
||||||
|
child_already_resized = ((m_wxwindow->parent) &&
|
||||||
|
(gtk_pizza_child_resized( GTK_PIZZA(m_wxwindow->parent), m_wxwindow )));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
child_already_resized = gtk_pizza_child_resized( GTK_PIZZA(m_widget->parent), m_widget );
|
{
|
||||||
|
child_already_resized = ((m_widget->parent) &&
|
||||||
|
(gtk_pizza_child_resized( GTK_PIZZA(m_widget->parent), m_widget )));
|
||||||
|
}
|
||||||
|
|
||||||
if (child_already_resized)
|
if (child_already_resized)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user