Fix wrong icon size in menus

import/tags/kmeleon75
boisso 7 years ago
parent 155e1212a8
commit b587e34eb9
  1. 100
      k-meleon/FavIconList.cpp
  2. 11
      k-meleon/FavIconList.h
  3. 28
      k-meleon/Plugins.cpp
  4. 2
      k-meleon/ie_favorites/ie_plugin.cpp
  5. 1
      k-meleon/kmeleon_plugin.h
  6. 2
      k-meleon/ns_bookmarks/ns_bookmarks.cpp
  7. 2
      k-meleon/op_hotlist/op_plugin.cpp

@ -101,6 +101,9 @@ CFavIconList::CFavIconList()
{
m_iDefaultIcon = 0;
m_iOffset = 0;
int width = ::GetSystemMetrics(SM_CXSMICON);
int height = ::GetSystemMetrics(SM_CYSMICON);
mSized.Create(width, height, ILC_COLOR32, 25, 10);
//mIconObserver = new IconObserver(this);
}
@ -113,6 +116,7 @@ BOOL CFavIconList::LoadCache()
{
CFile iconCache;
CImageList imgList;
CImageList imgListSized;
if (!iconCache.Open(theApp.GetFolder(ProfileFolder) + _T("\\") FAVICON_CACHE_FILE, CFile::modeRead))
return FALSE;
@ -130,6 +134,13 @@ BOOL CFavIconList::LoadCache()
return FALSE;
}
END_CATCH
TRY
imgListSized.Read(&ar);
CATCH (CArchiveException, e) {
}
END_CATCH
}
if (!imgList.m_hImageList)
@ -137,7 +148,13 @@ BOOL CFavIconList::LoadCache()
for (int i=0; i < imgList.GetImageCount(); i++) {
HICON tmp = imgList.ExtractIcon(i);
int idx = Add(tmp);
Add(tmp);
if (imgListSized.GetSafeHandle()) {
HICON stmp = imgListSized.ExtractIcon(i);
mSized.Add(stmp);
DestroyIcon(stmp);
} else
mSized.Add(tmp);
DestroyIcon(tmp);
}
@ -152,18 +169,23 @@ BOOL CFavIconList::WriteCache()
if (!theApp.preferences.GetBool("kmeleon.favicons.cached", TRUE))
return FALSE;
CImageList imgList;
CImageList imgList, imgListSized;
imgList.Create(this);
imgListSized.Create(&mSized);
for (int i=0; i < m_iOffset; i++)
for (int i=0; i < m_iOffset; i++) {
imgList.Remove(0);
imgListSized.Remove(0);
}
CFile iconCache;
if (iconCache.Open(theApp.GetFolder(ProfileFolder) + _T("\\") FAVICON_CACHE_FILE, CFile::modeCreate | CFile::modeWrite))
{
CArchive ar(&iconCache, CArchive::store);
if (imgList.Write(&ar))
if (imgList.Write(&ar)) {
m_urlMap.Serialize(ar);
imgListSized.Write(&ar);
}
}
return TRUE;
}
@ -178,7 +200,7 @@ void CFavIconList::LoadDefaultIcon()
// Add can return 0 even if it fails...
if (GetImageCount()==0)
m_iDefaultIcon = Add(theApp.GetDefaultIcon());
HICON loadingIcon = theApp.skin.GetIconLoading();
if (loadingIcon) {
m_iLoadingIcon = Add(loadingIcon);
@ -195,6 +217,8 @@ void CFavIconList::LoadDefaultIcon()
if (defaultIcon)
DestroyIcon(defaultIcon);
mSized.Add(theApp.GetDefaultIcon());
mSized.Add(theApp.GetDefaultIcon());
m_iOffset = GetImageCount();
}
@ -242,7 +266,7 @@ void CFavIconList::AddMap(const char *uri, int index, const char* pageUri)
// to mess with synchronisation.
theApp.BroadcastMessage(UWM_NEWSITEICON, (WPARAM)0, index);
}
/*
int CFavIconList::AddIcon(const char* uri, CBitmap* icon, COLORREF cr, const char* pageUri)
{
int index = Add(icon, cr);
@ -254,6 +278,47 @@ int CFavIconList::AddIcon(const char* uri, CBitmap* icon, CBitmap* mask, const c
{
int index = Add(icon, mask);
AddMap(uri, index, pageUri);
return index;
}*/
int CFavIconList::AddIcon(const char* uri, HBITMAP hBitmap, const char* pageUri)
{
BITMAP info;
::GetObject(hBitmap, sizeof(BITMAP), &info);
int w,h;
ImageList_GetIconSize(GetSafeHandle(), &w, &h);
HBITMAP hbmSized = NULL;
if (info.bmWidth!=w && info.bmHeight!=h) {
HDC hDC = GetDC(NULL);
HBITMAP hbmSized = ResizeIcon32(hDC, hBitmap, w, h);
if (!hbmSized) hbmSized = ResizeIcon(hDC, hBitmap, w, h);
ReleaseDC(NULL, hDC);
}
if (!hbmSized) hbmSized = hBitmap;
CBitmap bitmap;
bitmap.Attach(hbmSized);
int index = Add(&bitmap, (CBitmap*)NULL);
AddMap(uri, index, pageUri);
HBITMAP hbmSized2 = NULL;
ImageList_GetIconSize(mSized.GetSafeHandle(), &w, &h);
if (info.bmWidth!=w && info.bmHeight!=h) {
HDC hDC = GetDC(NULL);
HBITMAP hbmSized2 = ResizeIcon32(hDC, hBitmap, w, h);
if (!hbmSized) hbmSized2 = ResizeIcon(hDC, hBitmap, w, h);
ReleaseDC(NULL, hDC);
}
if (!hbmSized) hbmSized = hBitmap;
bitmap.Attach(hbmSized);
int index2 = mSized.Add(&bitmap, (CBitmap*)NULL);
ASSERT(index == index2);
if (hbmSized != hBitmap) DeleteObject(hbmSized);
if (hbmSized2 != hBitmap) DeleteObject(hbmSized2);
DeleteObject(hBitmap);
return index;
}
@ -331,6 +396,7 @@ void CFavIconList::RefreshIcon(nsIURI* aURI)
return;
Remove(index + m_iOffset);
mSized.Remove(index + m_iOffset);
// We have to remove all url with this icon.
POSITION pos = m_urlMap.GetStartPosition();
@ -352,6 +418,7 @@ void CFavIconList::RefreshIcon(nsIURI* aURI)
void CFavIconList::ResetCache()
{
while (GetImageCount()) Remove(0);
while (mSized.GetImageCount()) mSized.Remove(0);
m_urlMap.RemoveAll();
LoadDefaultIcon();
theApp.BroadcastMessage(UWM_NEWSITEICON, 0, -1);
@ -365,30 +432,11 @@ public:
void ImageLoaded(HBITMAP hBitmap)
{
BITMAP info;
::GetObject(hBitmap, sizeof(BITMAP), &info);
int w,h;
ImageList_GetIconSize(mFavList->GetSafeHandle(), &w, &h);
if (info.bmWidth!=w && info.bmHeight!=h) {
HDC hDC = GetDC(NULL);
HBITMAP hbmSized = ResizeIcon32(hDC, hBitmap, w, h);
if (!hbmSized) hbmSized = ResizeIcon(hDC, hBitmap, w, h);
if (hbmSized) {
DeleteObject(hBitmap);
hBitmap = hbmSized;
}
ReleaseDC(NULL, hDC);
}
CBitmap bitmap;
bitmap.Attach(hBitmap);
nsCString nsuri;
mIconURI->GetSpec(nsuri);
nsCString nsPageuri;
if (mPageURI) mPageURI->GetSpec(nsPageuri);
mFavList->AddIcon(nsuri.get(),&bitmap, (CBitmap*)NULL, nsPageuri.get());
mFavList->AddIcon(nsuri.get(), hBitmap, nsPageuri.get());
}
protected:

@ -37,21 +37,22 @@ private:
void AddMap(const char *uri, int index, const char* pageUri = nullptr);
int AddDownloadedIcon(char* uri, TCHAR* file, nsresult aStatus);
BOOL LoadCache();
CImageList mSized;
public:
CFavIconList();
virtual ~CFavIconList();
BOOL WriteCache();
int AddIcon(const char* uri, CBitmap*, CBitmap*, const char* pageUri = nullptr);
int AddIcon(const char* uri, CBitmap*, COLORREF, const char* pageUri = nullptr);
int AddIcon(const char* uri, HICON icon, const char* pageUri = nullptr);
//int AddIcon(const char* uri, CBitmap*, CBitmap*, const char* pageUri = nullptr);
//int AddIcon(const char* uri, CBitmap*, COLORREF, const char* pageUri = nullptr);
//int AddIcon(const char* uri, HICON icon, const char* pageUri = nullptr);
int AddIcon(const char* uri, HBITMAP, const char* pageUri = nullptr);
int GetHostIcon(const TCHAR* aUri);
int GetIcon(const TCHAR* uri);
int GetIcon(nsIURI* aUri, nsIURI* aPageURI = NULL, BOOL download = FALSE);
CImageList* GetSizedList() {return &mSized;}
void RefreshIcon(nsIURI* aURI);
void ResetCache();
void LoadDefaultIcon();

@ -420,6 +420,15 @@ HIMAGELIST GetIconList()
#endif
}
HIMAGELIST GetDefSizeIconList()
{
#ifdef INTERNAL_SITEICONS
return theApp.favicons.GetSizedList()->GetSafeHandle();
#else
return NULL;
#endif
}
long GetPreference(enum PREFTYPE type, const char *preference, void *ret, void *defVal)
{
long result = 0;
@ -540,13 +549,14 @@ int SetMozillaSessionHistory (HWND hWnd, const char **titles, const char **urls,
if (frame->IsKindOf(RUNTIME_CLASS(CBrowserFrmTab)) && theApp.preferences.GetBool("browser.sessionstore.restore_on_demand", false)) {
if (index>=count) index = count - 1;
if (index<0) index = 0;
view->GetBrowserGlue()->SetBrowserTitle(NSUTF8StringToCString(nsDependentCString(titles[index])));
nsCOMPtr<nsIURI> uri;
NewURI(getter_AddRefs(uri), nsDependentCString(urls[index]));
view->GetBrowserGlue()->UpdateCurrentURI(uri);
view->GetBrowserGlue()->mPendingLocation = urls[index];
view->GetBrowserGlue()->mHIndex = index;
view->GetBrowserGlue()->mIcon = theApp.favicons.GetHostIcon(A2CW(urls[index]));
view->GetBrowserGlue()->SetBrowserTitle(NSUTF8StringToCString(nsDependentCString(titles[index])));
uri->SetPath(NS_LITERAL_CSTRING(""));
nsCString host;
uri->GetHost(host);
@ -1139,6 +1149,16 @@ UINT GetWindowVarUTF8(HWND hWnd, WindowVarType type, void* ret)
return 1;
}
case Window_Tab_Index: {
if (!ret) return 1;
if (frame->IsKindOf(RUNTIME_CLASS(CBrowserFrmTab)))
//*(int*)ret = ((CBrowserFrmTab*)frame)->GetActiveTab()->m_iIndex;
*(int*)ret = ((CBrowserFrmTab*)frame)->GetTabBar()->FindByData((DWORD_PTR)(CBrowserTab*)view);
else
*(int*)ret = 0;
return 1;
}
case Window_Icon: {
if (ret) *(int*)ret = theApp.favicons.GetIcon(view->GetBrowserGlue()->mIconURI);
return 1;
@ -2103,7 +2123,8 @@ kmeleonFunctions kmelFuncsUTF8 = {
AddPermission,
ShowMenu,
GetCurrent,
RunCommand
RunCommand,
GetDefSizeIconList
};
kmeleonFunctions kmelFuncs = {
@ -2182,7 +2203,8 @@ kmeleonFunctions kmelFuncs = {
AddPermission,
ShowMenu,
GetCurrent,
RunCommand
RunCommand,
GetDefSizeIconList
};
BOOL CPlugins::TestLoad(LPCTSTR file, const char *description)

@ -621,7 +621,7 @@ extern "C" {
if (i > 0) {
idx = i;
hList = kPlugin.kFuncs->GetIconList();
hList = kPlugin.kFuncs->GetDefSizeIconList();
}
ImageList_Draw(hList, idx, dis->hDC, dis->rcItem.left+2, top, flags);

@ -389,6 +389,7 @@ typedef struct {
UINT (*ShowMenu)(HWND hWnd, const char* name, bool sendCommand);
HWND (*GetCurrent)(HWND hWnd);
bool (*RunCommand)(HWND hWnd, const char* command);
HIMAGELIST (*GetDefSizeIconList)();
} kmeleonFunctions;
/*

@ -466,7 +466,7 @@ extern "C" {
UINT i = GetSiteIcon(node);
if (i > 0) {
idx = i;
hList = kPlugin.kFuncs->GetIconList();
hList = kPlugin.kFuncs->GetDefSizeIconList();
}
ImageList_Draw(hList, idx, dis->hDC, dis->rcItem.left+2, top, flags);

@ -745,7 +745,7 @@ extern "C" {
UINT i = GetSiteIcon((char*)node->url.c_str());
if (i > 0) {
idx = i;
hList = kPlugin.kFuncs->GetIconList();
hList = kPlugin.kFuncs->GetDefSizeIconList();
}
ImageList_Draw(hList, idx, dis->hDC, dis->rcItem.left+2, top, flags);

Loading…
Cancel
Save