]> git.saurik.com Git - wxWidgets.git/commitdiff
add support for multiple extensions to wxImage handlers (closes #10570)
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 9 Mar 2009 23:13:34 +0000 (23:13 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 9 Mar 2009 23:13:34 +0000 (23:13 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59461 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/image.h
include/wx/imagjpeg.h
include/wx/imagpnm.h
include/wx/imagtga.h
interface/wx/image.h
src/common/image.cpp
src/common/imagtiff.cpp

index 089db7270afff2200563adf34281be543f4cf424..ed23baec671be3b5ef21ff0b7723ca0b0a2c5713 100644 (file)
@@ -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):
 
index e0a6760eb3f8b29c088a9de121d232596ed9c6ff..bc9ce0bfca72545efdd45b7fb14e5fb7264c7b09 100644 (file)
@@ -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;
 
index 976e3585766290302ccb6caaea607cde1c410f6c..873942e00ad07716a3df9327d56b68c92bfaad04 100644 (file)
@@ -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");
     }
index 8cd3f9f8840d7180a9fbad5151e8476a26aeb30f..89df0d08071abeb06ea12e477783bde64744060f 100644 (file)
@@ -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");
     }
index f17dcf7cff036f2b1047cba9a67504fd53a40e88..e5fd30f9be5512f3acfceb225f583848d7d47f0f 100644 (file)
@@ -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");
     }
index 681609be666bebfab9350a9490a1feb4d86a5a0a..fe812454820b6cd57f87a50fc7c69ce6adab2868 100644 (file)
@@ -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.
 
index 433e013d05893fe48f8c72a98bd1e7cd90e54ce2..a913240be53fb1d6397f41164bf6586743970c7c 100644 (file)
@@ -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(";");
     }
index 799d8749b68f8d43ae654804e0b832115fcccb4a..91b70afbae6ff882f50e4f2d2d86a59d22073cd1 100644 (file)
@@ -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);