Skip to content

Commit

Permalink
add GetFileStateIcon()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Aug 11, 2024
1 parent 2fc9383 commit ec241c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions do/settings_gen_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ var (
"thumbnails are saved as PNG files in sumatrapdfcache directory").setInternal(),
mkField("Index", &Type{"", "size_t"}, "0",
"temporary value needed for FileHistory::cmpOpenCount").setInternal(),
mkField("Himl", &Type{"", "HIMAGELIST"}, "NULL", "").setInternal(),
mkField("IconIdx", Int, -1, "").setInternal(),
}

// list of fields which aren't serialized when UseDefaultState is set
Expand Down
20 changes: 14 additions & 6 deletions src/HomePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,18 @@ void LayoutHomePage(HomePageLayout& l) {
win->staticLinks.Append(sl);
}

static void GetFileStateIcon(FileState* fs) {
if (fs->himl) {
return;
}
SHFILEINFO sfi{};
sfi.iIcon = -1;
uint flags = SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES;
WCHAR* filePathW = ToWStrTemp(fs->filePath);
fs->himl = (HIMAGELIST)SHGetFileInfoW(filePathW, 0, &sfi, sizeof(sfi), flags);
fs->iconIdx = sfi.iIcon;
}

static void DrawHomePageLayout(const HomePageLayout& l) {
bool isRtl = IsUIRtl();
auto hdc = l.hdc;
Expand Down Expand Up @@ -821,13 +833,9 @@ static void DrawHomePageLayout(const HomePageLayout& l) {
UINT fmt = DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX | (isRtl ? DT_RIGHT : DT_LEFT);
HdcDrawText(hdc, fileName, rect, fmt, fontText);

// TODO: cache this on FileState
SHFILEINFO sfi{};
uint flags = SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES;
WCHAR* filePathW = ToWStrTemp(path);
HIMAGELIST himl = (HIMAGELIST)SHGetFileInfoW(filePathW, 0, &sfi, sizeof(sfi), flags);
GetFileStateIcon(fs);
int x = isRtl ? page.x + page.dx - DpiScale(hdc, 16) : page.x;
ImageList_Draw(himl, sfi.iIcon, hdc, x, rect.y, ILD_TRANSPARENT);
ImageList_Draw(fs->himl, fs->iconIdx, hdc, x, rect.y, ILD_TRANSPARENT);
}

color = ThemeWindowLinkColor();
Expand Down
4 changes: 4 additions & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ struct FileState {
RenderedBitmap* thumbnail;
// temporary value needed for FileHistory::cmpOpenCount
size_t index;
//
HIMAGELIST himl;
//
int iconIdx;
};

// a subset of FileState required for restoring the state of a single
Expand Down

0 comments on commit ec241c2

Please sign in to comment.