mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
CtrlCore, CtrlLib: Cocoa FileSel icons
git-svn-id: svn://ultimatepp.org/upp/trunk@12694 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
b749962976
commit
a2db9d4579
5 changed files with 72 additions and 4 deletions
|
|
@ -145,6 +145,8 @@ struct DrawDragRectInfo {
|
|||
void DrawDragRect(SystemDraw& w, const Rect& rect1, const Rect& rect2, const Rect& clip, int n,
|
||||
Color color, uint64 pattern);
|
||||
|
||||
Image GetIconForFileExt(const char *ext);
|
||||
|
||||
#ifndef PLATFORM_WIN32
|
||||
#include <CtrlCore/stdids.h>
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -330,6 +330,27 @@ ImageDraw::operator Image()
|
|||
return Image(ib);
|
||||
}
|
||||
|
||||
Image GetIconForFileExt(const char *ext)
|
||||
{
|
||||
ImageDraw iw(DPI(16, 16));
|
||||
|
||||
CGContextRef cg = (CGContextRef) iw.GetCGHandle();
|
||||
|
||||
CFRef<CFStringRef> fext = CFStringCreateWithCString(NULL, ext, kCFStringEncodingUTF8);
|
||||
CFRef<CFStringRef> fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fext, NULL);
|
||||
|
||||
NSImage *image = *ext == '*' ? [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)]
|
||||
: [[NSWorkspace sharedWorkspace]iconForFileType:(__bridge NSString *)~fileUTI];
|
||||
|
||||
NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:cg flipped:YES];
|
||||
NSGraphicsContext* cgc = [NSGraphicsContext currentContext];
|
||||
[NSGraphicsContext setCurrentContext:gc];
|
||||
[image drawInRect:NSMakeRect(0, 0, DPI(16), DPI(16))];
|
||||
[NSGraphicsContext setCurrentContext:cgc];
|
||||
|
||||
return iw;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
void Coco_ThemePaint(void *cgcontext, const Upp::Rect& r, int type, int value, int state, bool focus)
|
||||
{
|
||||
auto cg = (CGContextRef) cgcontext;
|
||||
auto cg = (CGContextRef) cgcontext ;
|
||||
if(Upp::IsUHDMode())
|
||||
CGContextScaleCTM(cg, 2, 2);
|
||||
CGRect cr = CGRectMake(r.left, r.top, r.Width(), r.Height());
|
||||
|
|
|
|||
|
|
@ -394,6 +394,42 @@ Image GetFileIcon(const String& folder, const String& filename, bool isdir, bool
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_COCOA
|
||||
struct FileIconMaker : ImageMaker {
|
||||
String file;
|
||||
bool exe;
|
||||
bool dir;
|
||||
bool large;
|
||||
|
||||
virtual String Key() const {
|
||||
return file + (exe ? "1" : "0") + (dir ? "1" : "0");
|
||||
}
|
||||
|
||||
virtual Image Make() const {
|
||||
String ext = GetFileExt(file);
|
||||
if(*ext == '.')
|
||||
ext = ext.Mid(1);
|
||||
if(exe)
|
||||
ext = "app";
|
||||
if(dir && ext != "app")
|
||||
return GetIconForFileExt("*");
|
||||
return GetIconForFileExt(ext);
|
||||
}
|
||||
};
|
||||
|
||||
#define GETFILEICON_DEFINED
|
||||
|
||||
Image GetFileIcon(const char *path, bool dir, bool exe, bool large, bool quick = false)
|
||||
{
|
||||
FileIconMaker m;
|
||||
m.exe = exe;
|
||||
m.dir = dir;
|
||||
m.file = path;
|
||||
m.large = large;
|
||||
return MakeImage(m);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef GETFILEICON_DEFINED
|
||||
Image PosixGetDriveImage(String dir, bool)
|
||||
{
|
||||
|
|
@ -432,9 +468,13 @@ Image NativePathIcon0(const char *path, bool folder, bool large)
|
|||
String p = path;
|
||||
bool isdrive = folder && ((p == "/media") || (p == "/mnt"));
|
||||
FindFile ff(path);
|
||||
#ifdef PLATFORM_COCOA
|
||||
return GetFileIcon(path, folder, ff.GetMode() & 0111, large);
|
||||
#else
|
||||
return isdrive ? PosixGetDriveImage(GetFileName(path), large)
|
||||
: GetFileIcon(path, GetFileName(path), folder, ff.GetMode() & 0111, large);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
Image NativePathIcon(const char *path, bool folder)
|
||||
|
|
@ -508,9 +548,13 @@ bool Load(FileList& list, const String& dir, const char *patterns, bool dirs,
|
|||
MatchSearch(fi.filename, search) && show) {
|
||||
Image img;
|
||||
#ifdef PLATFORM_POSIX
|
||||
#ifdef PLATFORM_COCOA
|
||||
img = GetFileIcon(AppendFileName(dir, fi.filename), fi.is_directory, fi.unix_mode & 0111, false, lazyicons);
|
||||
#else
|
||||
img = isdrive ? PosixGetDriveImage(fi.filename, false)
|
||||
: GetFileIcon(dir, fi.filename, fi.is_directory, fi.unix_mode & 0111, false);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef GUI_WIN
|
||||
img = GetFileIcon(AppendFileName(dir, fi.filename), fi.is_directory, false, false, lazyicons);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -224,9 +224,10 @@ void SyncUHDMode();
|
|||
Image DPI(const Image& m);
|
||||
Image DPI(const Image& img, int expected);
|
||||
|
||||
inline int DPI(int a) { return IsUHDMode() ? 2 * a : a; }
|
||||
inline double DPI(double a) { return IsUHDMode() ? 2 * a : a; }
|
||||
inline Size DPI(Size sz) { return IsUHDMode() ? 2 * sz : sz; }
|
||||
inline int DPI(int a) { return IsUHDMode() ? 2 * a : a; }
|
||||
inline double DPI(double a) { return IsUHDMode() ? 2 * a : a; }
|
||||
inline Size DPI(Size sz) { return IsUHDMode() ? 2 * sz : sz; }
|
||||
inline Size DPI(int cx, int cy) { return Size(DPI(cx), DPI(cy)); }
|
||||
|
||||
inline Image DPI(const Image& a, const Image& b) { return IsUHDMode() ? b : a; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue