+
+#if wxUSE_DIRDLG || wxUSE_FILEDLG
+
+// ----------------------------------------------------------------------------
+// wxFileIconsTable icons
+// ----------------------------------------------------------------------------
+
+#ifndef __WXGTK20__
+/* Computer (c) Julian Smart */
+static const char* const file_icons_tbl_computer_xpm[] = {
+/* columns rows colors chars-per-pixel */
+"16 16 42 1",
+"r c #4E7FD0",
+"$ c #7198D9",
+"; c #DCE6F6",
+"q c #FFFFFF",
+"u c #4A7CCE",
+"# c #779DDB",
+"w c #95B2E3",
+"y c #7FA2DD",
+"f c #3263B4",
+"= c #EAF0FA",
+"< c #B1C7EB",
+"% c #6992D7",
+"9 c #D9E4F5",
+"o c #9BB7E5",
+"6 c #F7F9FD",
+", c #BED0EE",
+"3 c #F0F5FC",
+"1 c #A8C0E8",
+" c None",
+"0 c #FDFEFF",
+"4 c #C4D5F0",
+"@ c #81A4DD",
+"e c #4377CD",
+"- c #E2EAF8",
+"i c #9FB9E5",
+"> c #CCDAF2",
+"+ c #89A9DF",
+"s c #5584D1",
+"t c #5D89D3",
+": c #D2DFF4",
+"5 c #FAFCFE",
+"2 c #F5F8FD",
+"8 c #DFE8F7",
+"& c #5E8AD4",
+"X c #638ED5",
+"a c #CEDCF2",
+"p c #90AFE2",
+"d c #2F5DA9",
+"* c #5282D0",
+"7 c #E5EDF9",
+". c #A2BCE6",
+"O c #8CACE0",
+/* pixels */
+" ",
+" .XXXXXXXXXXX ",
+" oXO++@#$%&*X ",
+" oX=-;:>,<1%X ",
+" oX23=-;:4,$X ",
+" oX5633789:@X ",
+" oX05623=78+X ",
+" oXqq05623=OX ",
+" oX,,,,,<<<$X ",
+" wXXXXXXXXXXe ",
+" XrtX%$$y@+O,, ",
+" uyiiiiiiiii@< ",
+" ouiiiiiiiiiip<a",
+" rustX%$$y@+Ow,,",
+" dfffffffffffffd",
+" "
+};
+#endif // !GTK+ 2
+
+// ----------------------------------------------------------------------------
+// wxFileIconsTable & friends
+// ----------------------------------------------------------------------------
+
+// global instance of a wxFileIconsTable
+wxFileIconsTable* wxTheFileIconsTable = NULL;
+
+// A module to allow icons table cleanup
+
+class wxFileIconsTableModule: public wxModule
+{
+DECLARE_DYNAMIC_CLASS(wxFileIconsTableModule)
+public:
+ wxFileIconsTableModule() {}
+ bool OnInit() { wxTheFileIconsTable = new wxFileIconsTable; return true; }
+ void OnExit()
+ {
+ wxDELETE(wxTheFileIconsTable);
+ }
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxFileIconsTableModule, wxModule)
+
+class wxFileIconEntry : public wxObject
+{
+public:
+ wxFileIconEntry(int i) { iconid = i; }
+
+ int iconid;
+};
+
+wxFileIconsTable::wxFileIconsTable()
+{
+ m_HashTable = NULL;
+ m_smallImageList = NULL;
+}
+
+wxFileIconsTable::~wxFileIconsTable()
+{
+ if (m_HashTable)
+ {
+ WX_CLEAR_HASH_TABLE(*m_HashTable);
+ delete m_HashTable;
+ }
+ if (m_smallImageList) delete m_smallImageList;
+}
+
+// delayed initialization - wait until first use (wxArtProv not created yet)
+void wxFileIconsTable::Create()
+{
+ wxCHECK_RET(!m_smallImageList && !m_HashTable, wxT("creating icons twice"));
+ m_HashTable = new wxHashTable(wxKEY_STRING);
+ m_smallImageList = new wxImageList(16, 16);
+
+ // folder:
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_FOLDER,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+ // folder_open
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_FOLDER_OPEN,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+ // computer
+#ifdef __WXGTK20__
+ // GTK24 uses this icon in the file open dialog
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_HARDDISK,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+#else
+ m_smallImageList->Add(wxIcon(file_icons_tbl_computer_xpm));
+#endif
+ // drive
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_HARDDISK,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+ // cdrom
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_CDROM,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+ // floppy
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_FLOPPY,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+ // removeable
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_REMOVABLE,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+ // file
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_NORMAL_FILE,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+ // executable
+ if (GetIconID(wxEmptyString, wxT("application/x-executable")) == file)
+ {
+ m_smallImageList->Add(wxArtProvider::GetBitmap(wxART_EXECUTABLE_FILE,
+ wxART_CMN_DIALOG,
+ wxSize(16, 16)));
+ delete m_HashTable->Get(wxT("exe"));
+ m_HashTable->Delete(wxT("exe"));
+ m_HashTable->Put(wxT("exe"), new wxFileIconEntry(executable));
+ }
+ /* else put into list by GetIconID
+ (KDE defines application/x-executable for *.exe and has nice icon)
+ */
+}
+
+wxImageList *wxFileIconsTable::GetSmallImageList()
+{
+ if (!m_smallImageList)
+ Create();
+
+ return m_smallImageList;
+}
+
+#if wxUSE_MIMETYPE && wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
+// VS: we don't need this function w/o wxMimeTypesManager because we'll only have
+// one icon and we won't resize it
+
+static wxBitmap CreateAntialiasedBitmap(const wxImage& img)
+{
+ const unsigned int size = 16;
+
+ wxImage smallimg (size, size);
+ unsigned char *p1, *p2, *ps;
+ unsigned char mr = img.GetMaskRed(),
+ mg = img.GetMaskGreen(),
+ mb = img.GetMaskBlue();
+
+ unsigned x, y;
+ unsigned sr, sg, sb, smask;
+
+ p1 = img.GetData(), p2 = img.GetData() + 3 * size*2, ps = smallimg.GetData();
+ smallimg.SetMaskColour(mr, mr, mr);
+
+ for (y = 0; y < size; y++)
+ {
+ for (x = 0; x < size; x++)
+ {
+ sr = sg = sb = smask = 0;
+ if (p1[0] != mr || p1[1] != mg || p1[2] != mb)
+ sr += p1[0], sg += p1[1], sb += p1[2];
+ else smask++;
+ p1 += 3;
+ if (p1[0] != mr || p1[1] != mg || p1[2] != mb)
+ sr += p1[0], sg += p1[1], sb += p1[2];
+ else smask++;
+ p1 += 3;
+ if (p2[0] != mr || p2[1] != mg || p2[2] != mb)
+ sr += p2[0], sg += p2[1], sb += p2[2];
+ else smask++;
+ p2 += 3;
+ if (p2[0] != mr || p2[1] != mg || p2[2] != mb)
+ sr += p2[0], sg += p2[1], sb += p2[2];
+ else smask++;
+ p2 += 3;
+
+ if (smask > 2)
+ ps[0] = ps[1] = ps[2] = mr;
+ else
+ {
+ ps[0] = (unsigned char)(sr >> 2);
+ ps[1] = (unsigned char)(sg >> 2);
+ ps[2] = (unsigned char)(sb >> 2);
+ }
+ ps += 3;
+ }
+ p1 += size*2 * 3, p2 += size*2 * 3;
+ }
+
+ return wxBitmap(smallimg);
+}
+
+// This function is currently not unused anymore
+#if 0
+// 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));
+}
+#endif // #if 0
+
+#endif // wxUSE_MIMETYPE
+
+int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime)
+{
+ if (!m_smallImageList)
+ Create();
+
+#if wxUSE_MIMETYPE
+ if (!extension.empty())
+ {
+ wxFileIconEntry *entry = (wxFileIconEntry*) m_HashTable->Get(extension);
+ if (entry) return (entry -> iconid);
+ }
+
+ wxFileType *ft = (mime.empty()) ?
+ wxTheMimeTypesManager -> GetFileTypeFromExtension(extension) :
+ wxTheMimeTypesManager -> GetFileTypeFromMimeType(mime);
+
+ wxIconLocation iconLoc;
+ wxIcon ic;
+
+ {
+ wxLogNull logNull;
+ if ( ft && ft->GetIcon(&iconLoc) )
+ {
+ ic = wxIcon( iconLoc );
+ }
+ }
+
+ delete ft;
+
+ if ( !ic.Ok() )
+ {
+ int newid = file;
+ m_HashTable->Put(extension, new wxFileIconEntry(newid));
+ return newid;
+ }
+
+ wxBitmap bmp;
+ bmp.CopyFromIcon(ic);
+
+ if ( !bmp.Ok() )
+ {
+ int newid = file;
+ m_HashTable->Put(extension, new wxFileIconEntry(newid));
+ return newid;
+ }
+
+ const unsigned int size = 16;
+
+ int treeid = m_smallImageList->GetImageCount();
+ if ((bmp.GetWidth() == (int) size) && (bmp.GetHeight() == (int) size))
+ {
+ m_smallImageList->Add(bmp);
+ }
+#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
+ else
+ {
+ wxImage img = bmp.ConvertToImage();
+
+ if ((img.GetWidth() != size*2) || (img.GetHeight() != size*2))
+// m_smallImageList->Add(CreateAntialiasedBitmap(CutEmptyBorders(img).Rescale(size*2, size*2)));
+ m_smallImageList->Add(CreateAntialiasedBitmap(img.Rescale(size*2, size*2)));
+ else
+ m_smallImageList->Add(CreateAntialiasedBitmap(img));
+ }
+#endif // wxUSE_IMAGE
+
+ m_HashTable->Put(extension, new wxFileIconEntry(treeid));
+ return treeid;
+
+#else // !wxUSE_MIMETYPE
+
+ wxUnusedVar(mime);
+ if (extension == wxT("exe"))
+ return executable;
+ else
+ return file;
+#endif // wxUSE_MIMETYPE/!wxUSE_MIMETYPE
+}
+
+#endif // wxUSE_DIRDLG || wxUSE_FILEDLG