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 |
|
koldo
Messages: 3394 Registered: August 2008
|
Senior 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").
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 1001 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 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced 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()),
And it's WIN32 specific :/ ... but nice change.
|
|
|
|
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 |
|
koldo
Messages: 3394 Registered: August 2008
|
Senior 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 |
|
mirek
Messages: 14039 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
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 22:07:57 CEST 2024
Total time taken to generate the page: 0.03425 seconds
|