]> git.saurik.com Git - wxWidgets.git/commitdiff
remember the last type used for loading or saving the image and return it from GetTyp...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 11 Jun 2008 00:28:23 +0000 (00:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 11 Jun 2008 00:28:23 +0000 (00:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54086 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/image.h
interface/image.h
src/common/image.cpp

index 0f9625d9632c4fa7697fa161747b158fde24cf82..dd87546c1cdd3e6086f69062424ac72a2a9eb39d 100644 (file)
@@ -364,6 +364,7 @@ All (GUI):
 - Fix appending items to sorted wxComboCtrl after creation (Jaakko Salli)
 - Don't blit area larger than necessary in wxBufferedDC::UnMask (Liang Jian)
 - Fixed wxPixelData<wxImage> compilation (Leonardo Fernandes).
+- Added wxImage::GetType() (troelsk).
 
 wxGTK:
 
index 07fe116d72a1d97a3e6b88c3925a1186f9abe384..60aff69ce65c842f756782edbc6253b6f492fd5a 100644 (file)
@@ -352,6 +352,9 @@ public:
     int GetWidth() const;
     int GetHeight() const;
 
+    // Gets the type of image found by LoadFile or specified with SaveFile
+    wxBitmapType GetType() const;
+
     // these functions provide fastest access to wxImage data but should be
     // used carefully as no checks are done
     unsigned char *GetData() const;
@@ -440,6 +443,16 @@ protected:
 private:
     friend class WXDLLIMPEXP_FWD_CORE wxImageHandler;
 
+#if wxUSE_STREAMS
+    // read the image from the specified stream updating image type if
+    // successful
+    bool DoLoad(wxImageHandler& handler, wxInputStream& stream, int index);
+
+    // write the image to the specified stream and also update the image type
+    // if successful
+    bool DoSave(wxImageHandler& handler, wxOutputStream& stream) const;
+#endif // wxUSE_STREAMS
+
     DECLARE_DYNAMIC_CLASS(wxImage)
 };
 
index fd1fbc20819f5869899903863f7fe74063e89da2..ef66408ff0f3542516d9a66bab54c2ec8626b9ad 100644 (file)
@@ -626,6 +626,12 @@ public:
     */
     wxImage GetSubImage(const wxRect& rect) const;
 
+    /**
+        Gets the type of image found by LoadFile or specified with SaveFile
+        @since 2.9.0
+    */
+    wxBitmapType GetType() const;
+
     /**
         Gets the width of the image in pixels.
 
index b29070e431acaea91191113b7a87b394bbaf6c85..b41fee58f655546f95f6a5d70e59b1cda7c3ab2c 100644 (file)
@@ -64,6 +64,7 @@ public:
 
     int             m_width;
     int             m_height;
+    wxBitmapType    m_type;
     unsigned char  *m_data;
 
     bool            m_hasMask;
@@ -94,6 +95,7 @@ wxImageRefData::wxImageRefData()
 {
     m_width = 0;
     m_height = 0;
+    m_type = wxBITMAP_TYPE_INVALID;
     m_data =
     m_alpha = (unsigned char *) NULL;
 
@@ -1459,6 +1461,13 @@ int wxImage::GetHeight() const
     return M_IMGDATA->m_height;
 }
 
+wxBitmapType wxImage::GetType() const
+{
+    wxCHECK_MSG( IsOk(), wxBITMAP_TYPE_INVALID, wxT("invalid image") );
+
+    return M_IMGDATA->m_type;
+}
+
 long wxImage::XYToIndex(int x, int y) const
 {
     if ( Ok() &&
@@ -2196,6 +2205,15 @@ int wxImage::GetImageCount( wxInputStream &stream, wxBitmapType type )
     }
 }
 
+bool wxImage::DoLoad(wxImageHandler& handler, wxInputStream& stream, int index)
+{
+    if ( !handler.LoadFile(this, stream, true/*verbose*/, index) )
+        return false;
+
+    M_IMGDATA->m_type = handler.GetType();
+    return true;
+}
+
 bool wxImage::LoadFile( wxInputStream& stream, wxBitmapType type, int index )
 {
     UnRef();
@@ -2212,12 +2230,8 @@ bool wxImage::LoadFile( wxInputStream& stream, wxBitmapType type, int index )
               node = node->GetNext() )
         {
              handler = (wxImageHandler*)node->GetData();
-             if ( handler->CanRead(stream) &&
-                    handler->LoadFile(this, stream, true/*verbose*/, index) )
-             {
+             if ( handler->CanRead(stream) && DoLoad(*handler, stream, index) )
                  return true;
-             }
-
         }
 
         wxLogWarning( _("No handler found for image type.") );
@@ -2239,7 +2253,7 @@ bool wxImage::LoadFile( wxInputStream& stream, wxBitmapType type, int index )
         return false;
     }
 
-    return handler->LoadFile(this, stream, true/*verbose*/, index);
+    return DoLoad(*handler, stream, index);
 }
 
 bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int index )
@@ -2262,7 +2276,17 @@ bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int ind
         return false;
     }
 
-    return handler->LoadFile( this, stream, true/*verbose*/, index );
+    return DoLoad(*handler, stream, index);
+}
+
+bool wxImage::DoSave(wxImageHandler& handler, wxOutputStream& stream) const
+{
+    wxImage * const self = wx_const_cast(wxImage *, this);
+    if ( !handler.SaveFile(self, stream) )
+        return false;
+
+    M_IMGDATA->m_type = handler.GetType();
+    return true;
 }
 
 bool wxImage::SaveFile( wxOutputStream& stream, wxBitmapType type ) const
@@ -2276,7 +2300,7 @@ bool wxImage::SaveFile( wxOutputStream& stream, wxBitmapType type ) const
         return false;
     }
 
-    return handler->SaveFile( (wxImage*)this, stream );
+    return DoSave(*handler, stream);
 }
 
 bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const
@@ -2289,7 +2313,7 @@ bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const
         wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
     }
 
-    return handler->SaveFile( (wxImage*)this, stream );
+    return DoSave(*handler, stream);
 }
 
 #endif // wxUSE_STREAMS