+// finds empty borders and return non-empty area of image:
+static wxImage CutEmptyBorders(const wxImage& img)
+{
+ unsigned char mr = img.GetMaskRed(),
+ mg = img.GetMaskGreen(),
+ mb = img.GetMaskBlue();
+ unsigned char *dt = img.GetData(), *dttmp;
+ unsigned w = img.GetWidth(), h = img.GetHeight();
+
+ unsigned top, bottom, left, right, i;
+ bool empt;
+
+#define MK_DTTMP(x,y) dttmp = dt + ((x + y * w) * 3)
+#define NOEMPTY_PIX(empt) if (dttmp[0] != mr || dttmp[1] != mg || dttmp[2] != mb) {empt = FALSE; break;}
+
+ for (empt = TRUE, top = 0; empt && top < h; top++)
+ {
+ MK_DTTMP(0, top);
+ for (i = 0; i < w; i++, dttmp+=3)
+ NOEMPTY_PIX(empt)
+ }
+ for (empt = TRUE, bottom = h-1; empt && bottom > top; bottom--)
+ {
+ MK_DTTMP(0, bottom);
+ for (i = 0; i < w; i++, dttmp+=3)
+ NOEMPTY_PIX(empt)
+ }
+ for (empt = TRUE, left = 0; empt && left < w; left++)
+ {
+ MK_DTTMP(left, 0);
+ for (i = 0; i < h; i++, dttmp+=3*w)
+ NOEMPTY_PIX(empt)
+ }
+ for (empt = TRUE, right = w-1; empt && right > left; right--)
+ {
+ MK_DTTMP(right, 0);
+ for (i = 0; i < h; i++, dttmp+=3*w)
+ NOEMPTY_PIX(empt)
+ }
+ top--, left--, bottom++, right++;
+
+ return img.GetSubImage(wxRect(left, top, right - left + 1, bottom - top + 1));
+}
+
+
+
+int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime)
+{
+ if (!extension.IsEmpty())
+ {
+ wxFileIconEntry *entry = (wxFileIconEntry*) m_HashTable.Get(extension);
+ if (entry) return (entry -> id);
+ }
+
+ wxFileType *ft = (mime.IsEmpty()) ?
+ wxTheMimeTypesManager -> GetFileTypeFromExtension(extension) :
+ wxTheMimeTypesManager -> GetFileTypeFromMimeType(mime);
+ wxIcon ic;
+ if (ft == NULL || (!ft -> GetIcon(&ic)) || (!ic.Ok()))
+ {
+ int newid = FI_UNKNOWN;
+ m_HashTable.Put(extension, new wxFileIconEntry(newid));
+ return newid;
+ }
+ wxImage img(ic);
+ delete ft;
+
+ int id = m_ImageList.GetImageCount();
+ if (img.GetWidth() == 16 && img.GetHeight() == 16)
+ m_ImageList.Add(img.ConvertToBitmap());
+ else
+ {
+ if (img.GetWidth() != 32 || img.GetHeight() != 32)
+ m_ImageList.Add(CreateAntialiasedBitmap(CutEmptyBorders(img).Rescale(32, 32)));
+ else
+ m_ImageList.Add(CreateAntialiasedBitmap(img));
+ }
+ m_HashTable.Put(extension, new wxFileIconEntry(id));
+ return id;
+}
+
+
+
+// ----------------------------------------------------------------------------
+// private functions
+// ----------------------------------------------------------------------------
+
+static
+int ListCompare( long data1, long data2, long WXUNUSED(data) )
+{
+ wxFileData *fd1 = (wxFileData*)data1 ;
+ wxFileData *fd2 = (wxFileData*)data2 ;
+ if (fd1->GetName() == wxT("..")) return -1;
+ if (fd2->GetName() == wxT("..")) return 1;
+ if (fd1->IsDir() && !fd2->IsDir()) return -1;
+ if (fd2->IsDir() && !fd1->IsDir()) return 1;
+ return wxStrcmp( fd1->GetName(), fd2->GetName() );
+}