Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Small Upp gems. Native icons in TreeCtrl
Re: Small Upp gems. Native icons in TreeCtrl. (Now Linux&Win) [message #18721 is a reply to message #18502] Sat, 18 October 2008 19:26 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14261
Registered: November 2005
Ultimate Member
koldo wrote on Sat, 04 October 2008 08:39

Dear all

Thank you for waiting... Now it works also in Linux.
The function is:

Image NativeFileIcon(const char *path, bool folder)
{
#if defined(PLATFORM_WIN32)
	if (folder)
		return GetFileIcon(path, true, true);
	else
		return GetFileIcon(path, false);
#endif
#ifdef PLATFORM_POSIX
	bool isdrive = folder && ((path == "/media") || (path == "/mnt"));
	FindFile ff(path);
	return isdrive ? PosixGetDriveImage(ff.GetName())
				   : GetFileIcon(path, ff.GetName(), folder, ff.GetMode() & 0111);
#endif
}

It is also necessary to add this in FileSel.h

#if defined(PLATFORM_WIN32)
	Image GetFileIcon(const char *path, bool dir, bool force = false)
#endif
#ifdef PLATFORM_POSIX
	Image GetFileIcon(const String& folder, const String& filename, bool isdir, bool isexe);
	Image PosixGetDriveImage(String dir);
#endif

And as I have explained in the first post, go to FileSel.cpp and in the definition remove "= false" from:

Image GetFileIcon(const char *path, bool dir, bool force = false)

This is only a simple patch I have found useful. But it would be great if the FileSel developer could integrate this inside the code. Thank you very much to him/her.

Best regards
Koldo


Adopted as

Image NativePathIcon(const char *path, bool folder)
{
#if defined(PLATFORM_WIN32)
	if (folder)
		return GetFileIcon(path, true, true);
	else
		return GetFileIcon(path, false);
#endif
#ifdef PLATFORM_POSIX
	bool isdrive = folder && ((path == "/media") || (path == "/mnt"));
	return isdrive ? PosixGetDriveImage(GetFileName(path))
				   : GetFileIcon(path, GetFileName(path), folder, ff.GetMode() & 0111);
#endif
}

Image NativePathIcon(const char *path)
{
	FindFile ff(path);
	return NativePathIcon(path, ff.IsFolder());
}


(BTW, is my simplified GetFileName solution corrent or was there any other idea why have you used FindFile?).

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: More small gems
Next Topic: Sample CUPS driver for PDF files generation
Goto Forum:
  


Current Time: Sat Jun 07 16:54:22 CEST 2025

Total time taken to generate the page: 0.04216 seconds