]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/image.cpp
wxMkdir() has 2nd param under Unix
[wxWidgets.git] / src / common / image.cpp
index 0b4956dad2f4b30195f3574e6521a8c13732043f..151ba3b73e7d6406da08e775005c0ea00c7125f8 100644 (file)
@@ -34,6 +34,10 @@ extern "C" {
 #include "wx/filefn.h"
 #include "wx/wfstream.h"
 #include "wx/intl.h"
+#include "wx/module.h"
+
+// For memcpy
+#include <string.h>
 
 #ifdef __SALFORDC__
 #ifdef FAR
@@ -255,9 +259,11 @@ char unsigned *wxImage::GetData() const
     return M_IMGDATA->m_data;
 }
 
-void wxImage::SetData( char unsigned *WXUNUSED(data) )
+void wxImage::SetData( char unsigned *data )
 {
     wxCHECK_RET( Ok(), "invalid image" );
+
+    memcpy(M_IMGDATA->m_data, data, M_IMGDATA->m_width * M_IMGDATA->m_height * 3);
 }
 
 void wxImage::SetMaskColour( unsigned char r, unsigned char g, unsigned char b )
@@ -1957,7 +1963,7 @@ wxBitmap wxImage::ConvertToBitmap() const
     wxBitmap bitmap;
     
     wxCHECK_MSG( Ok(), bitmap, "invalid image" );
-    
+
     int width = GetWidth();
     int height = GetHeight();
     
@@ -1971,10 +1977,10 @@ wxBitmap wxImage::ConvertToBitmap() const
     // Create image
     
     XImage *data_image = XCreateImage( dpy, vis, bpp, ZPixmap, 0, 0, width, height, 32, 0 );
-    data_image->data = new char[ data_image->bytes_per_line * data_image->height ];
+    data_image->data = (char*) malloc( data_image->bytes_per_line * data_image->height );
     
     bitmap.Create( width, height, bpp );
-    
+
     /*
     // Create mask
     
@@ -2012,7 +2018,7 @@ wxBitmap wxImage::ConvertToBitmap() const
     }
     
     XFree( vi );
-    
+
     if ((bpp == 16) && (vi->red_mask != 0xf800)) bpp = 15;
     if (bpp < 8) bpp = 8;
     
@@ -2278,3 +2284,19 @@ wxImage::wxImage( const wxBitmap &bitmap )
     */
 }
 #endif
+
+// A module to allow wxImage initialization/cleanup
+// without calling these functions from app.cpp or from
+// the user's application.
+
+class wxImageModule: public wxModule
+{
+DECLARE_DYNAMIC_CLASS(wxImageModule)
+public:
+    wxImageModule() {}
+    bool OnInit() { wxImage::InitStandardHandlers(); return TRUE; };
+    void OnExit() { wxImage::CleanUpHandlers(); };
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule)
+