summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/NewStory/res/no-image-ico.pngbin0 -> 678 bytes
-rw-r--r--plugins/NewStory/res/resource.rc1
-rw-r--r--plugins/NewStory/src/history_control.h6
-rw-r--r--plugins/NewStory/src/main.cpp6
-rw-r--r--plugins/NewStory/src/resource.h1
-rw-r--r--plugins/NewStory/src/stdafx.h3
-rw-r--r--plugins/NewStory/src/templates.cpp13
-rw-r--r--plugins/NewStory/src/utils.cpp31
-rw-r--r--plugins/NewStory/src/utils.h2
-rw-r--r--plugins/NewStory/src/webpage.cpp50
10 files changed, 65 insertions, 48 deletions
diff --git a/plugins/NewStory/res/no-image-ico.png b/plugins/NewStory/res/no-image-ico.png
new file mode 100644
index 0000000000..e352146f0b
--- /dev/null
+++ b/plugins/NewStory/res/no-image-ico.png
Binary files differ
diff --git a/plugins/NewStory/res/resource.rc b/plugins/NewStory/res/resource.rc
index e204790c5f..79975d36e0 100644
--- a/plugins/NewStory/res/resource.rc
+++ b/plugins/NewStory/res/resource.rc
@@ -74,6 +74,7 @@ IDI_USERS ICON "users.ico"
IDI_REPLY ICON "reply.ico"
+IDI_NO_IMAGE PNG "no-image-ico.png"
/////////////////////////////////////////////////////////////////////////////
//
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index 8b95ed2e1b..3db27132d4 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -9,8 +9,6 @@ class NSWebPage : public document_container
{
typedef std::map<std::wstring, uint_ptr> images_map;
- ULONG_PTR m_gdiplusToken;
-
mir_cs m_csImages;
images_map m_images;
@@ -23,7 +21,6 @@ class NSWebPage : public document_container
std::string resolve_color(const string &color) const;
uint_ptr get_image(LPCWSTR url_or_path, bool redraw_on_ready);
- void make_url(LPCWSTR url, LPCWSTR basepath, std::wstring &out);
void get_client_rect(position &client) const override;
void import_css(string &text, const string &url, string &baseurl) override;
@@ -34,7 +31,6 @@ class NSWebPage : public document_container
void draw_image(uint_ptr hdc, const background_layer &layer, const std::string &url, const std::string &base_url) override;
void get_img_size(uint_ptr img, size &sz);
- void free_image(uint_ptr img);
// document_container members
uint_ptr create_font(const char *faceName, int size, int weight, font_style italic, unsigned int decoration, font_metrics *fm) override;
@@ -74,8 +70,6 @@ class NSWebPage : public document_container
void release_clip(HDC hdc);
void set_clip(const position &pos, const border_radiuses &bdr_radius) override;
- void make_url_utf8(const char *url, const char *basepath, std::wstring &out);
-
void clear_images();
static int CALLBACK EnumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData);
diff --git a/plugins/NewStory/src/main.cpp b/plugins/NewStory/src/main.cpp
index 5e8a4c1bb5..3271b9fe48 100644
--- a/plugins/NewStory/src/main.cpp
+++ b/plugins/NewStory/src/main.cpp
@@ -185,6 +185,10 @@ int CMPlugin::Load()
{
registerIcon(MODULETITLE, icons);
+ GdiplusStartupInput gdiplusStartupInput;
+ GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
+
+ m_pNoImage = LoadImageFromResource(getInst(), IDI_NO_IMAGE, L"PNG");
LoadOptions();
m_log = RegisterSrmmLog(this, MODULETITLE, _T(MODULENAME), NewStory_Stub);
@@ -211,6 +215,8 @@ int CMPlugin::Unload()
WindowList_Destroy(g_hNewstoryLogs);
WindowList_Destroy(g_hNewstoryWindows);
+ GdiplusShutdown(m_gdiplusToken);
+
UnregisterSrmmLog(m_log);
UnregisterClass(_T(NEWSTORYLIST_CLASS), g_plugin.getInst());
DestroyFonts();
diff --git a/plugins/NewStory/src/resource.h b/plugins/NewStory/src/resource.h
index 2684ee58d0..f6312dcc6a 100644
--- a/plugins/NewStory/src/resource.h
+++ b/plugins/NewStory/src/resource.h
@@ -21,6 +21,7 @@
#define IDI_MSGOUT 117
#define IDI_SIGNIN 118
#define IDI_OK 119
+#define IDI_NO_IMAGE 120
#define IDI_UNKNOWN 121
#define IDI_FINDPREV 122
#define IDI_FINDNEXT 123
diff --git a/plugins/NewStory/src/stdafx.h b/plugins/NewStory/src/stdafx.h
index f89220c3ca..324b17befc 100644
--- a/plugins/NewStory/src/stdafx.h
+++ b/plugins/NewStory/src/stdafx.h
@@ -107,6 +107,9 @@ struct CMPlugin : public PLUGIN<CMPlugin>
HANDLE m_log;
HBRUSH hBackBrush;
+ Bitmap *m_pNoImage;
+ ULONG_PTR m_gdiplusToken;
+
CMOption<bool> bOptVScroll, bSortAscending;
// thesw options are a copy of static CMOption to keep performance high
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp
index bb3c4ecfca..2c9ac5c222 100644
--- a/plugins/NewStory/src/templates.cpp
+++ b/plugins/NewStory/src/templates.cpp
@@ -48,14 +48,17 @@ static wchar_t* font2html(LOGFONTA &lf, wchar_t *dest)
static void AppendImage(CMStringW &buf, const CMStringW &wszUrl, const CMStringW &wszDescr, ItemData *pItem, UINT uMaxHeight = 300)
{
if (g_plugin.bShowPreview) {
- int iHeight = uMaxHeight;
pItem->pOwner->webPage.load_image(wszUrl, pItem);
- if (Bitmap *pImage = pItem->pOwner->webPage.find_image(wszUrl))
+
+ int iHeight = uMaxHeight;
+ if (auto *pImage = pItem->pOwner->webPage.find_image(wszUrl)) {
if (pImage->GetHeight() < uMaxHeight)
iHeight = pImage->GetHeight();
-
- buf.AppendFormat(L"<img style=\"height: %d;\" src=\"%s\" title=\"%s\" alt=\"%s\"/><br>",
- iHeight, wszUrl.c_str(), wszDescr.c_str(), wszDescr.c_str());
+
+ buf.AppendFormat(L"<img style=\"height: %d;\" src=\"%s\" title=\"%s\" alt=\"%s\"/><br>",
+ iHeight, wszUrl.c_str(), wszDescr.c_str(), wszDescr.c_str());
+ }
+ else buf.AppendFormat(L"<img src=\"%s\" title=\"%s\" alt=\"%s\"/><br>", wszUrl.c_str(), wszUrl.c_str(), wszUrl.c_str());
}
else buf.AppendFormat(L"<a class=\"link\" href=\"%s\">%s</a>", wszUrl.c_str(), wszDescr.c_str());
}
diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp
index a02d6aa393..5f990fa337 100644
--- a/plugins/NewStory/src/utils.cpp
+++ b/plugins/NewStory/src/utils.cpp
@@ -18,6 +18,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
+#include <msapi/comptr.h>
+
+Bitmap* LoadImageFromResource(HINSTANCE hInst, int resourceId, const wchar_t *pwszType)
+{
+ if (HRSRC hrsrc = FindResourceW(hInst, MAKEINTRESOURCE(resourceId), pwszType)) {
+ if (DWORD dwSize = SizeofResource(hInst, hrsrc)) {
+ if (HGLOBAL hRes = LoadResource(hInst, hrsrc)) {
+ void *pImage = LockResource(hRes);
+
+ if (HGLOBAL hGlobal = ::GlobalAlloc(GHND, dwSize)) {
+ void *pBuffer = ::GlobalLock(hGlobal);
+ if (pBuffer) {
+ memcpy(pBuffer, pImage, dwSize);
+
+ CComPtr<IStream> pStream;
+ HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
+ if (SUCCEEDED(hr))
+ return new Gdiplus::Bitmap(pStream);
+ }
+
+ GlobalFree(hGlobal); // free memory only if the function fails
+ }
+ }
+ }
+ }
+
+ return nullptr;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
uint32_t toggleBit(uint32_t dw, uint32_t bit)
{
if (dw & bit)
diff --git a/plugins/NewStory/src/utils.h b/plugins/NewStory/src/utils.h
index d9fb352546..d6bfb0ad2f 100644
--- a/plugins/NewStory/src/utils.h
+++ b/plugins/NewStory/src/utils.h
@@ -11,3 +11,5 @@ int GetFontHeight(const LOGFONTA &lf);
void UrlAutodetect(CMStringW &str);
void RemoveBbcodes(CMStringW &pwszText);
+
+Bitmap* LoadImageFromResource(HINSTANCE, int, const wchar_t *);
diff --git a/plugins/NewStory/src/webpage.cpp b/plugins/NewStory/src/webpage.cpp
index f4f8d7cd69..7ce346a17c 100644
--- a/plugins/NewStory/src/webpage.cpp
+++ b/plugins/NewStory/src/webpage.cpp
@@ -121,9 +121,6 @@ NSWebPage::NSWebPage(NewstoryListData &_1) :
m_hClipRgn = NULL;
m_tmp_hdc = GetDC(NULL);
- GdiplusStartupInput gdiplusStartupInput;
- GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
-
EnumFonts(m_tmp_hdc, NULL, EnumFontsProc, (LPARAM)this);
m_installed_fonts.insert(L"monospace");
m_installed_fonts.insert(L"serif");
@@ -135,7 +132,6 @@ NSWebPage::NSWebPage(NewstoryListData &_1) :
NSWebPage::~NSWebPage()
{
clear_images();
- GdiplusShutdown(m_gdiplusToken);
{
mir_cslock lck(g_csMissingFiles);
for (auto &it : g_arMissingFiles.rev_iter())
@@ -329,11 +325,6 @@ void NSWebPage::draw_list_marker(uint_ptr hdc, const list_marker &marker)
release_clip((HDC)hdc);
}
-void NSWebPage::make_url_utf8(const char *url, const char *basepath, std::wstring &out)
-{
- make_url(Utf2T(url), Utf2T(basepath), out);
-}
-
Bitmap* NSWebPage::load_image(const wchar_t *pwszUrl, ItemData *pItem)
{
mir_cslockfull lck(m_csImages);
@@ -351,13 +342,12 @@ Bitmap* NSWebPage::load_image(const wchar_t *pwszUrl, ItemData *pItem)
if (!g_arMissingFiles.find(&tmp))
g_arMissingFiles.insert(new NSWebCache(tmp));
- return 0;
+ return g_plugin.m_pNoImage;
}
-void NSWebPage::load_image(const char *src, const char *baseurl, bool redraw_on_ready)
+void NSWebPage::load_image(const char *src, const char */*baseurl*/, bool redraw_on_ready)
{
- std::wstring url;
- make_url_utf8(src, baseurl, url);
+ std::wstring url = Utf2T(src);
mir_cslockfull lck(m_csImages);
if (m_images.count(url) == 0) {
@@ -384,27 +374,25 @@ Bitmap* NSWebPage::find_image(const wchar_t *pwszUrl)
return nullptr;
}
-void NSWebPage::get_image_size(const char *src, const char *baseurl, size &sz)
+void NSWebPage::get_image_size(const char *src, const char * /*baseurl*/, size &sz)
{
- std::wstring url;
- make_url_utf8(src, baseurl, url);
+ std::wstring url = Utf2T(src);
mir_cslock lck(m_csImages);
images_map::iterator img = m_images.find(url);
if (img != m_images.end() && img->second)
get_img_size(img->second, sz);
else
- sz.width = sz.height = 0;
+ sz.width = sz.height = 48;
}
void NSWebPage::clear_images()
{
mir_cslock lck(m_csImages);
- for (auto &img : m_images) {
- if (img.second) {
- free_image(img.second);
- }
- }
+ for (auto &img : m_images)
+ if (img.second)
+ delete (Bitmap *)img.second;
+
m_images.clear();
}
@@ -543,23 +531,16 @@ void NSWebPage::get_img_size(uint_ptr img, size &sz)
}
}
-void NSWebPage::free_image(uint_ptr img)
-{
- Bitmap *bmp = (Bitmap *)img;
- delete bmp;
-}
-
-void NSWebPage::draw_image(uint_ptr _hdc, const background_layer &bg, const std::string &src, const std::string &base_url)
+void NSWebPage::draw_image(uint_ptr _hdc, const background_layer &bg, const std::string &src, const std::string& /*base_url*/)
{
if (src.empty() || (!bg.clip_box.width && !bg.clip_box.height))
return;
- std::wstring url;
- make_url_utf8(src.c_str(), base_url.c_str(), url);
+ std::wstring url = Utf2T(src.c_str());
Bitmap *bgbmp = find_image(url.c_str());
if (!bgbmp)
- return;
+ bgbmp = g_plugin.m_pNoImage;
Graphics graphics((HDC)_hdc);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
@@ -739,11 +720,6 @@ void NSWebPage::import_css(std::string &, const std::string &, std::string &)
{
}
-void NSWebPage::make_url(LPCWSTR url, LPCWSTR, std::wstring &out)
-{
- out = url;
-}
-
void NSWebPage::on_anchor_click(const char *pszUtl, const element::ptr &)
{
Utf2T wszUrl(pszUtl);