diff options
author | George Hazan <george.hazan@gmail.com> | 2024-09-13 22:28:47 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-09-13 22:28:47 +0300 |
commit | 6379adc8ad721692e934589bf0d1532ef82a8139 (patch) | |
tree | 895a0ffd3a628b596e62e54046f6e168b4e49adc /plugins/NewStory | |
parent | ccc539fdfad925e21361baf36ae0af5eb81b85b4 (diff) |
fixes #4657 (NewStory: не отображается предпросмотр)
Diffstat (limited to 'plugins/NewStory')
-rw-r--r-- | plugins/NewStory/src/history_control.h | 6 | ||||
-rw-r--r-- | plugins/NewStory/src/history_svc.cpp | 1 | ||||
-rw-r--r-- | plugins/NewStory/src/templates.cpp | 2 | ||||
-rw-r--r-- | plugins/NewStory/src/webpage.cpp | 59 |
4 files changed, 63 insertions, 5 deletions
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index afdaa7e67e..db03cde2ee 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -87,7 +87,9 @@ public: COLORREF clText = -1, clBack = -1;
Bitmap* find_image(const wchar_t *pwszUrl);
- Bitmap* load_image(const wchar_t *pwszUrl);
+ Bitmap* load_image(const wchar_t *pwszUrl, ItemData *pItem);
+
+ void draw();
};
struct NewstoryListData : public MZeroedObject
@@ -188,4 +190,6 @@ struct NewstoryListData : public MZeroedObject void InitNewstoryControl();
+INT_PTR SvcFileReady(WPARAM wParam, LPARAM);
+
#endif // __history_control_h__
diff --git a/plugins/NewStory/src/history_svc.cpp b/plugins/NewStory/src/history_svc.cpp index 3010db5a81..a3d5dc2381 100644 --- a/plugins/NewStory/src/history_svc.cpp +++ b/plugins/NewStory/src/history_svc.cpp @@ -57,6 +57,7 @@ static INT_PTR SvcGetSelection(WPARAM wParam, LPARAM lParam) void InitServices()
{
CreateServiceFunction("NewStory/GetSrmm", &SvcGetSrmm);
+ CreateServiceFunction("NewStory/FileReady", &SvcFileReady);
CreateServiceFunction("NewStory/GetCurrent", &SvcGetCurrent);
CreateServiceFunction("NewStory/GetSelection", &SvcGetSelection);
}
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index 23e5f9dcd4..7c3e091057 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -49,7 +49,7 @@ static void AppendImage(CMStringW &buf, const CMStringW &wszUrl, const CMStringW {
if (g_plugin.bShowPreview) {
int iHeight = uMaxHeight;
- pItem->pOwner->webPage.load_image(wszUrl);
+ pItem->pOwner->webPage.load_image(wszUrl, pItem);
if (Bitmap *pImage = pItem->pOwner->webPage.find_image(wszUrl))
if (pImage->GetHeight() < uMaxHeight)
iHeight = pImage->GetHeight();
diff --git a/plugins/NewStory/src/webpage.cpp b/plugins/NewStory/src/webpage.cpp index dbf2ba22b4..f4f8d7cd69 100644 --- a/plugins/NewStory/src/webpage.cpp +++ b/plugins/NewStory/src/webpage.cpp @@ -18,6 +18,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" +struct NSWebCache +{ + NSWebCache(NSWebPage *_1, const wchar_t *_2, ItemData *_3) : + pPage(_1), + pItem(_3), + wszPath(_2) + {} + + ItemData *pItem; + NSWebPage *pPage; + CMStringW wszPath; +}; + +static int CompareFiles(const NSWebCache *p1, const NSWebCache *p2) +{ + return mir_wstrcmp(p1->wszPath, p2->wszPath); +} + +static mir_cs g_csMissingFiles; +static OBJLIST<NSWebCache> g_arMissingFiles(10, CompareFiles); + +INT_PTR SvcFileReady(WPARAM wParam, LPARAM) +{ + NSWebCache tmp(0, (const wchar_t *)wParam, 0); + + mir_cslock lck(g_csMissingFiles); + if (auto *pCache = g_arMissingFiles.find(&tmp)) { + pCache->pPage->load_image(tmp.wszPath, pCache->pItem); + pCache->pItem->m_doc = 0; + pCache->pItem->savedHeight = -1; + pCache->pItem->setText(); + g_arMissingFiles.remove(pCache); + } + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// // Litehtml interface @@ -100,13 +136,24 @@ NSWebPage::~NSWebPage() { clear_images(); GdiplusShutdown(m_gdiplusToken); + { + mir_cslock lck(g_csMissingFiles); + for (auto &it : g_arMissingFiles.rev_iter()) + if (it->pPage == this) + g_arMissingFiles.remove(g_arMissingFiles.indexOf(&it)); + } - if (m_hClipRgn) { + if (m_hClipRgn) DeleteObject(m_hClipRgn); - } + ReleaseDC(NULL, m_tmp_hdc); } +void NSWebPage::draw() +{ + ctrl.ScheduleDraw(); +} + ///////////////////////////////////////////////////////////////////////////////////////// // former win32_container @@ -287,7 +334,7 @@ void NSWebPage::make_url_utf8(const char *url, const char *basepath, std::wstrin make_url(Utf2T(url), Utf2T(basepath), out); } -Bitmap* NSWebPage::load_image(const wchar_t *pwszUrl) +Bitmap* NSWebPage::load_image(const wchar_t *pwszUrl, ItemData *pItem) { mir_cslockfull lck(m_csImages); auto img = m_images.find(pwszUrl); @@ -298,6 +345,12 @@ Bitmap* NSWebPage::load_image(const wchar_t *pwszUrl) add_image(pwszUrl, newImg); return (Bitmap *)newImg; } + + NSWebCache tmp(this, pwszUrl, pItem); + mir_cslock lck2(g_csMissingFiles); + if (!g_arMissingFiles.find(&tmp)) + g_arMissingFiles.insert(new NSWebCache(tmp)); + return 0; } |