How dows wxGenericDirCtrl decide which image is used for an item (file)?
Some of the files display in my ctrl got the system-specified (WinXP) icons and others (for example image files like bmp, gif, jpg) got other icons that are not specified by my system.
Can I change this behavior? Can I say the ctrl should only use system-icons or should use only own icons?
What is about the directory icons? Is it possible to say that should be system-icons?
[wxGenericDirCtrl] use of item-icons? Topic is solved
-
- Earned a small fee
- Posts: 22
- Joined: Sat May 20, 2006 2:45 am
wxGenericDirCtrl gets its icons using the GetIconID function (part of wxFileIconsTable class in dirctrlg.h) in dirctrlg.cpp:
the headerfile can be found in includes/wx/generic/dirctrlg.h
the cpp file is in the src folder somewher,e i jsut did a search for it.
the headerfile can be found in includes/wx/generic/dirctrlg.h
the cpp file is in the src folder somewher,e i jsut did a search for it.
Code: Select all
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 -> id);
}
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 id = 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(id));
return id;
#else // !wxUSE_MIMETYPE
wxUnusedVar(mime);
if (extension == wxT("exe"))
return executable;
else
return file;
#endif // wxUSE_MIMETYPE/!wxUSE_MIMETYPE
}
Ok, but why does this code sometimes work and sometimes not?xskater11x wrote:Code: Select all
#if wxUSE_MIMETYPE if (!extension.empty()) { wxFileIconEntry *entry = (wxFileIconEntry*) m_HashTable->Get(extension); if (entry) return (entry -> id); }