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:
|
||||
wxImage();
|
||||
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( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
|
||||
wxImage( const wxString& name, const wxString& mimetype );
|
||||
@@ -106,6 +107,7 @@ public:
|
||||
#endif
|
||||
|
||||
void Create( int width, int height );
|
||||
void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
|
||||
void Destroy();
|
||||
|
||||
// return the new image with size width*height
|
||||
@@ -156,6 +158,7 @@ public:
|
||||
|
||||
char unsigned *GetData() const;
|
||||
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 );
|
||||
unsigned char GetMaskRed() const;
|
||||
|
@@ -56,6 +56,7 @@ public:
|
||||
bool m_hasMask;
|
||||
unsigned char m_maskRed,m_maskGreen,m_maskBlue;
|
||||
bool m_ok;
|
||||
bool m_static;
|
||||
};
|
||||
|
||||
wxImageRefData::wxImageRefData()
|
||||
@@ -68,11 +69,12 @@ wxImageRefData::wxImageRefData()
|
||||
m_maskGreen = 0;
|
||||
m_maskBlue = 0;
|
||||
m_hasMask = FALSE;
|
||||
m_static = FALSE;
|
||||
}
|
||||
|
||||
wxImageRefData::~wxImageRefData()
|
||||
{
|
||||
if (m_data)
|
||||
if (m_data && !m_static)
|
||||
free( m_data );
|
||||
}
|
||||
|
||||
@@ -93,6 +95,11 @@ wxImage::wxImage( int width, int 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 )
|
||||
{
|
||||
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()
|
||||
{
|
||||
UnRef();
|
||||
@@ -340,6 +367,34 @@ void wxImage::SetData( char unsigned *data )
|
||||
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 )
|
||||
{
|
||||
wxCHECK_RET( Ok(), wxT("invalid image") );
|
||||
|
@@ -2579,9 +2579,15 @@ void wxWindow::OnInternalIdle()
|
||||
|
||||
bool child_already_resized = FALSE;
|
||||
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
|
||||
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)
|
||||
{
|
||||
|
@@ -2579,9 +2579,15 @@ void wxWindow::OnInternalIdle()
|
||||
|
||||
bool child_already_resized = FALSE;
|
||||
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
|
||||
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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user