diff --git a/do/settings_gen_def.go b/do/settings_gen_def.go index 50c5a69444e1..2af38769d02e 100644 --- a/do/settings_gen_def.go +++ b/do/settings_gen_def.go @@ -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 diff --git a/src/HomePage.cpp b/src/HomePage.cpp index bccfecd322ae..5ba9201899cf 100644 --- a/src/HomePage.cpp +++ b/src/HomePage.cpp @@ -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; @@ -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(); diff --git a/src/Settings.h b/src/Settings.h index 66f611b2fe2f..9b3eea9a4a42 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -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