static wxBitmap CreateAntialiasedBitmap(const wxImage& img)
{
- wxImage smallimg (16, 16);
+ const unsigned int size = 16;
+
+ wxImage smallimg (size, size);
unsigned char *p1, *p2, *ps;
unsigned char mr = img.GetMaskRed(),
mg = img.GetMaskGreen(),
unsigned x, y;
unsigned sr, sg, sb, smask;
- p1 = img.GetData(), p2 = img.GetData() + 3 * 32, ps = smallimg.GetData();
+ p1 = img.GetData(), p2 = img.GetData() + 3 * size*2, ps = smallimg.GetData();
smallimg.SetMaskColour(mr, mr, mr);
- for (y = 0; y < 16; y++)
+ for (y = 0; y < size; y++)
{
- for (x = 0; x < 16; x++)
+ for (x = 0; x < size; x++)
{
sr = sg = sb = smask = 0;
if (p1[0] != mr || p1[1] != mg || p1[2] != mb)
ps[0] = sr >> 2, ps[1] = sg >> 2, ps[2] = sb >> 2;
ps += 3;
}
- p1 += 32 * 3, p2 += 32 * 3;
+ p1 += size*2 * 3, p2 += size*2 * 3;
}
-
+
return wxBitmap(smallimg);
}
wxLogNull logNull;
if ( ft && ft->GetIcon(&iconLoc) )
{
- ic = wxIcon(iconLoc);
+ ic = wxIcon( iconLoc.GetFileName() );
}
}
-
+
delete ft;
if ( !ic.Ok() )
return newid;
}
+ const unsigned int size = 16;
+
int id = m_smallImageList->GetImageCount();
- if ((bmp.GetWidth() == 16) && (bmp.GetHeight() == 16))
+ if ((bmp.GetWidth() == size) && (bmp.GetHeight() == size))
+ {
m_smallImageList->Add(bmp);
+ }
else
{
wxImage img = bmp.ConvertToImage();
- if ((img.GetWidth() != 32) || (img.GetHeight() != 32))
- m_smallImageList->Add(CreateAntialiasedBitmap(CutEmptyBorders(img).Rescale(32, 32)));
+ 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));
}
+
m_HashTable->Put(extension, new wxFileIconEntry(id));
return id;
#include "wx/utils.h"
#include "wx/tokenzr.h"
#include "wx/iconloc.h"
+#include "wx/filename.h"
+#include "wx/fileconf.h"
#include "wx/unix/mimetype.h"
else if (sTmp.Contains( wxT("icon_filename=") ) )
{
curIconFile = sTmp.AfterFirst(wxT('='));
+
if (!wxFileExists(curIconFile))
{
size_t nDirs = dirs.GetCount();
for (size_t nDir = 0; nDir < nDirs; nDir++)
{
- wxString newFile;
- newFile.Printf(wxT("%s/pixmaps/document-icons/%s.png"),
- dirs[nDir].c_str(),
- curIconFile.c_str());
- if (wxFileExists(newFile))
- curIconFile = newFile;
+ wxFileName newFile( curIconFile );
+ newFile.SetPath( dirs[nDir] );
+ newFile.AppendDir( wxT("pixmaps") );
+ newFile.AppendDir( wxT("document-icons") );
+ newFile.SetExt( wxT("png") );
+ if (newFile.FileExists())
+ curIconFile = newFile.GetFullPath();
}
}
}
// ignore blank lines
nLine ++;
} // end of while, save any data
+
if (! curMimeType.empty())
- {
AddToMimeData ( curMimeType, curIconFile, entry, strExtensions, strDesc);
- }
-
}
wxLogTrace(TRACE_MIME,
wxT("--- At end of Gnome file finding mimetype %s ---"),
curMimeType.c_str());
-
+
AddMimeTypeInfo(curMimeType, curExtList, wxEmptyString);
}
wxString dirname = dirbase;
dirname << wxT("/mime-info");
-
+
if ( !wxDir::Exists(dirname) )
return;
dirname += wxT('/');
wxString filename;
- bool cont = dir.GetFirst(&filename, _T("*.mime"), wxDIR_FILES);
+ bool cont;
+ cont = dir.GetFirst(&filename, _T("*.mime"), wxDIR_FILES);
while ( cont )
{
LoadGnomeMimeTypesFromMimeFile(dirname + filename);
cont = dir.GetNext(&filename);
}
-}
+ // Hack alert: We scan all icons and deduce the
+ // mime-type from the file name.
+ dirname = dirbase;
+ dirname << wxT("/pixmaps/document-icons");
+
+ // these are always empty in this file
+ wxArrayString strExtensions;
+ wxString strDesc;
+
+ if ( !wxDir::Exists(dirname) )
+ return;
+ wxDir dir2( dirname );
+ cont = dir2.GetFirst(&filename, wxT("gnome-*.png"), wxDIR_FILES);
+ while ( cont )
+ {
+ wxString mimeType = filename;
+ mimeType.Remove( 0, 6 ); // remove "gnome-"
+ mimeType.Remove( mimeType.Len()-4, 4 ); // remove ".png"
+ int pos = mimeType.Find( wxT("-") );
+ if (pos != wxNOT_FOUND)
+ {
+ mimeType.SetChar( pos, wxT('/') );
+ wxString iconFile = dirname;
+ iconFile << wxT("/");
+ iconFile << filename;
+ AddToMimeData ( mimeType, iconFile, NULL, strExtensions, strDesc, TRUE );
+ }
+
+ cont = dir2.GetNext(&filename);
+ }
+}
void wxMimeTypesManagerImpl::GetGnomeMimeInfo(const wxString& sExtraDir)
{
wxArrayString dirs;
+ dirs.Add(wxT("/opt/gnome/share"));
dirs.Add(wxT("/usr/share"));
dirs.Add(wxT("/usr/local/share"));
strIcon = file.GetCmd(nIndex);
wxLogTrace(TRACE_MIME, wxT(" icon %s"), strIcon.c_str());
//it could be the real path, but more often a short name
+
+
if (!wxFileExists(strIcon))
{
// icon is just the short name
// in many locations, at least ~/.kde and $KDEDIR
size_t nDir, nDirs = icondirs.GetCount();
for ( nDir = 0; nDir < nDirs; nDir++ )
- if (wxFileExists(icondirs[nDir] + strIcon))
+ {
+ wxFileName fname( icondirs[nDir], strIcon );
+ fname.SetExt( wxT("png") );
+ if (fname.FileExists())
{
- strIcon.Prepend(icondirs[nDir]);
+ strIcon = fname.GetFullPath();
wxLogTrace(TRACE_MIME, wxT(" iconfile %s"), strIcon.c_str());
break;
}
+ }
}
}
}
{
wxArrayString dirs;
wxArrayString icondirs;
+
+ // the variable KDEDIR is set when KDE is running
+ const wxChar *kdedir = wxGetenv( wxT("KDEDIR") );
+
+ if (kdedir)
+ {
+ wxFileName configFile( kdedir, wxEmptyString );
+ configFile.AppendDir( wxT("share") );
+#if 0
+ configFile.AppendDir( wxT("config") );
+ configFile.SetName( wxT("kdeglobals") );
+
+ wxFileConfig config( wxEmptyString, wxEmptyString, configFile.GetFullPath() );
+ wxString theme;
+ config.SetPath( wxT("Icons") );
+ config.Read( wxT("Theme"), theme );
+
+ configFile.RemoveDir( configFile.GetDirCount()-1 );
+ configFile.AppendDir( wxT("icons") );
+ configFile.AppendDir( theme );
+#else
+ configFile.AppendDir( wxT("icons") );
+ configFile.AppendDir( wxT("crystalsvg") );
+#endif
+
+ if (!wxDir::Exists(configFile.GetPath()))
+ {
+ configFile.RemoveDir( configFile.GetDirCount()-1 );
+ configFile.AppendDir( wxT("crystal") );
+ }
+
+ if (!wxDir::Exists(configFile.GetPath()))
+ {
+ configFile.RemoveDir( configFile.GetDirCount()-1 );
+ configFile.AppendDir( wxT("default.kde") );
+ }
+
+ if (wxDir::Exists(configFile.GetPath()))
+ {
+ configFile.AppendDir( wxT("32x32") );
+ configFile.AppendDir( wxT("mimetypes") );
+ icondirs.Add( configFile.GetFullPath() );
+ }
+ }
// settings in ~/.kde have maximal priority
dirs.Add(wxGetHomeDir() + wxT("/.kde/share"));
icondirs.Add(wxGetHomeDir() + wxT("/.kde/share/icons/"));
- // the variable KDEDIR is set when KDE is running
- const wxChar *kdedir = wxGetenv( wxT("KDEDIR") );
if ( kdedir )
{
dirs.Add( wxString(kdedir) + wxT("/share") );
m_mailcapStylesInited = 0;
}
+void wxMimeTypesManagerImpl::InitIfNeeded()
+{
+ if ( !m_initialized )
+ {
+ // set the flag first to prevent recursion
+ m_initialized = TRUE;
+
+#if 0
+ wxString wm = wxGetenv( wxT("WINDOWMANAGER") );
+
+ if (wm.Find( wxT("kde") ) != wxNOT_FOUND)
+ Initialize( wxMAILCAP_KDE|wxMAILCAP_STANDARD );
+ else if (wm.Find( wxT("gnome") ) != wxNOT_FOUND)
+ Initialize( wxMAILCAP_GNOME|wxMAILCAP_STANDARD );
+ else
+#endif
+ Initialize();
+ }
+}
+
// read system and user mailcaps and other files
void wxMimeTypesManagerImpl::Initialize(int mailcapStyles,
const wxString& sExtraDir)
GetMimeInfo(sExtraDir);
// read GNOME tables
- if ( mailcapStyles & wxMAILCAP_GNOME)
+ if (mailcapStyles & wxMAILCAP_GNOME)
GetGnomeMimeInfo(sExtraDir);
// read KDE tables
- if ( mailcapStyles & wxMAILCAP_KDE)
+ if (mailcapStyles & wxMAILCAP_KDE)
GetKDEMimeInfo(sExtraDir);
m_mailcapStylesInited |= mailcapStyles;