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
Small Upp gems. Native icons in TreeCtrl [message #18448] Wed, 01 October 2008 18:33 Go to next message
koldo is currently offline  koldo
Messages: 2980
Registered: August 2008
Veteran
Dear all

When I want a new possibility from Upp, it is Upp the main source of solutions. One example: Sample TreeCtrl looks not very good as the icons are too simple, but with a little change you get fine native icons (see "Before" and "After").

index.php?t=getfile&id=1406&private=0

How to do it?. Very simple. Go to main.cpp and in OpenDir() function change this:
tree1.Add(id, ff.IsFolder() ? CtrlImg::error() : CtrlImg::File(),

with this:
tree1.Add(id, ff.IsFolder() ? GetFileIcon(n, true, false) : GetFileIcon(n, false, false),

To use function "Image GetFileIcon(const char *path, bool dir, bool force)" you have to go to declare it in, for example, FileSel.h and go to FileSel.cpp and in the definition change:

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

by

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

Thats all. Thank you Upp developers!
  • Attachment: Screen.JPG
    (Size: 48.42KB, Downloaded 734 times)


Best regards
Iñaki
Re: Small Upp gems. Native icons in TreeCtrl [message #18451 is a reply to message #18448] Wed, 01 October 2008 19:31 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 797
Registered: November 2005
Location: Czech Republic - Praha
Contributor

tree1.Add(id, ff.IsFolder() ? GetFileIcon(n, true, false) : GetFileIcon(n, false, false),

I would write as:
tree1.Add(id, GetFileIcon(n, ff.IsFolder()),

Wink

And it's WIN32 specific :/ ... but nice change. Smile
Re: Small Upp gems. Native icons in TreeCtrl [message #18456 is a reply to message #18451] Wed, 01 October 2008 22:44 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2980
Registered: August 2008
Veteran
Hi Mr_ped

I cannot get it now but there is a promising

---> Image GetFileIcon(const String& folder, const String& filename, bool isdir, bool isexe);

between #ifdef PLATFORM_X11 #ifdef flagNOGTK

As this is the function that FileSel uses in Gtk ... it will work!.

Perhaps I will do a little bit more in few days and I propose you a unified function for Linux and Windows.

Sorry for not waiting some days to check it in Linux. I was so happy that I could not wait.

And I am checking new gems from Upp very useful to show you in few days ...

Best regards
Koldo


Best regards
Iñaki
Re: Small Upp gems. Native icons in TreeCtrl. (Now Linux&Win) [message #18502 is a reply to message #18448] Sat, 04 October 2008 14:39 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2980
Registered: August 2008
Veteran
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


Best regards
Iñaki
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 next message
mirek is currently offline  mirek
Messages: 11991
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
Re: Small Upp gems. Native icons in TreeCtrl. (Now Linux&Win) [message #18728 is a reply to message #18721] Sat, 18 October 2008 20:56 Go to previous message
koldo is currently offline  koldo
Messages: 2980
Registered: August 2008
Veteran
Hello luzr

Thank you for considering this!

I have used FindFile because of the ff.GetMode() & 0111. Please do not forget to go to FileSel.cpp and in the definition remove "= false" from:

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

Also I would like you to consider the fix in FileSel.cpp in http://www.ultimatepp.org/forum/index.php?t=msg&goto=185 42&#msg_18542

Best regards
Koldo


Best regards
Iñaki

[Updated on: Sat, 18 October 2008 20:57]

Report message to a moderator

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


Current Time: Tue Aug 20 16:24:38 CEST 2019

Total time taken to generate the page: 0.01041 seconds