From ba4800d3aeb254dd00277ff0a71df9321ca692dc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Mar 2009 23:13:34 +0000 Subject: [PATCH] add support for multiple extensions to wxImage handlers (closes #10570) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59461 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/image.h | 3 +++ include/wx/imagjpeg.h | 2 ++ include/wx/imagpnm.h | 3 +++ include/wx/imagtga.h | 1 + interface/wx/image.h | 31 ++++++++++++++++++++++++++++--- src/common/image.cpp | 10 +++++++--- src/common/imagtiff.cpp | 1 + 8 files changed, 46 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 089db7270a..ed23baec67 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -375,6 +375,7 @@ All: - Added wxXmlResource::GetResourceNode(). - Optimize wxString::Replace() to use an O(N) algorithm (Kuang-che Wu). - Added support of %l format specifier to wxDateTime::ParseFormat(). +- wxImage handlers can now support multiple extensions (Ivan Krestinin). All (Unix): diff --git a/include/wx/image.h b/include/wx/image.h index e0a6760eb3..bc9ce0bfca 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -108,10 +108,12 @@ public: void SetName(const wxString& name) { m_name = name; } void SetExtension(const wxString& ext) { m_extension = ext; } + void SetAlExtensions(const wxArrayString& exts) { m_altExtensions = exts; } void SetType(wxBitmapType type) { m_type = type; } void SetMimeType(const wxString& type) { m_mime = type; } const wxString& GetName() const { return m_name; } const wxString& GetExtension() const { return m_extension; } + const wxArrayString& GetAltExtensions() const { return m_altExtensions; } wxBitmapType GetType() const { return m_type; } const wxString& GetMimeType() const { return m_mime; } @@ -138,6 +140,7 @@ protected: wxString m_name; wxString m_extension; + wxArrayString m_altExtensions; wxString m_mime; wxBitmapType m_type; diff --git a/include/wx/imagjpeg.h b/include/wx/imagjpeg.h index 976e358576..873942e00a 100644 --- a/include/wx/imagjpeg.h +++ b/include/wx/imagjpeg.h @@ -27,6 +27,8 @@ public: { m_name = wxT("JPEG file"); m_extension = wxT("jpg"); + m_altExtensions.Add(wxT("jpeg")); + m_altExtensions.Add(wxT("jpe")); m_type = wxBITMAP_TYPE_JPEG; m_mime = wxT("image/jpeg"); } diff --git a/include/wx/imagpnm.h b/include/wx/imagpnm.h index 8cd3f9f884..89df0d0807 100644 --- a/include/wx/imagpnm.h +++ b/include/wx/imagpnm.h @@ -24,6 +24,9 @@ public: { m_name = wxT("PNM file"); m_extension = wxT("pnm"); + m_altExtensions.Add(wxT("ppm")); + m_altExtensions.Add(wxT("pgm")); + m_altExtensions.Add(wxT("pbm")); m_type = wxBITMAP_TYPE_PNM; m_mime = wxT("image/pnm"); } diff --git a/include/wx/imagtga.h b/include/wx/imagtga.h index f17dcf7cff..e5fd30f9be 100644 --- a/include/wx/imagtga.h +++ b/include/wx/imagtga.h @@ -25,6 +25,7 @@ public: { m_name = wxT("TGA file"); m_extension = wxT("tga"); + m_altExtensions.Add(wxT("tpic")); m_type = wxBITMAP_TYPE_TGA; m_mime = wxT("image/tga"); } diff --git a/interface/wx/image.h b/interface/wx/image.h index 681609be66..fe81245482 100644 --- a/interface/wx/image.h +++ b/interface/wx/image.h @@ -84,10 +84,21 @@ public: virtual ~wxImageHandler(); /** - Gets the file extension associated with this handler. + Gets the preferred file extension associated with this handler. + + @see GetAltExtensions() */ const wxString& GetExtension() const; + /** + Returns the other file extensions associated with this handler. + + The preferred extension for this handler is returned by GetExtension(). + + @since 2.9.0 + */ + const wxArrayString& GetAltExtensions() const; + /** If the image file contains more than one image and the image handler is capable of retrieving these individually, this function will return the number of @@ -160,13 +171,27 @@ public: bool verbose = true); /** - Sets the handler extension. + Sets the preferred file extension associated with this handler. @param extension - Handler extension. + File extension without leading dot. + + @see SetAltExtensions() */ void SetExtension(const wxString& extension); + /** + Sets the alternative file extensions associated with this handler. + + @param extensions + Array of file extensions. + + @see SetExtension() + + @since 2.9.0 + */ + void SetAltExtensions(const wxArrayString& extensions); + /** Sets the handler MIME type. diff --git a/src/common/image.cpp b/src/common/image.cpp index 433e013d05..a913240be5 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -2438,10 +2438,12 @@ wxImageHandler *wxImage::FindHandler( const wxString& extension, wxBitmapType bi while (node) { wxImageHandler *handler = (wxImageHandler*)node->GetData(); - if ( (handler->GetExtension().Cmp(extension) == 0) && - ( (bitmapType == wxBITMAP_TYPE_ANY) || (handler->GetType() == bitmapType)) ) + if ((bitmapType == wxBITMAP_TYPE_ANY) || (handler->GetType() == bitmapType)) { - return handler; + if (handler->GetExtension() == extension) + return handler; + if (handler->GetAltExtensions().Index(extension, false) != wxNOT_FOUND) + return handler; } node = node->GetNext(); } @@ -2503,6 +2505,8 @@ wxString wxImage::GetImageExtWildcard() { wxImageHandler* Handler = (wxImageHandler*)Node->GetData(); fmts += wxT("*.") + Handler->GetExtension(); + for (size_t i = 0; i < Handler->GetAltExtensions().size(); i++) + fmts += wxT(";*.") + Handler->GetAltExtensions()[i]; Node = Node->GetNext(); if ( Node ) fmts += wxT(";"); } diff --git a/src/common/imagtiff.cpp b/src/common/imagtiff.cpp index 799d8749b6..91b70afbae 100644 --- a/src/common/imagtiff.cpp +++ b/src/common/imagtiff.cpp @@ -108,6 +108,7 @@ wxTIFFHandler::wxTIFFHandler() { m_name = wxT("TIFF file"); m_extension = wxT("tif"); + m_altExtensions.Add(wxT("tiff")); m_type = wxBITMAP_TYPE_TIF; m_mime = wxT("image/tiff"); TIFFSetWarningHandler((TIFFErrorHandler) TIFFwxWarningHandler); -- 2.45.2