Browse Source

Fixing toolbars icons

master
boisso 7 years ago
parent
commit
8f248ce418
  1. 4
      k-meleon/JSBridge/jscomp.cpp
  2. 2
      k-meleon/JSBridge/nsIJSBridge.idl
  3. 2
      k-meleon/KMeleonConst.h
  4. 79
      k-meleon/KmImage.cpp
  5. 2
      k-meleon/KmImage.h
  6. 24
      k-meleon/KmSkin.cpp
  7. 134
      k-meleon/KmToolbar.cpp
  8. 5
      k-meleon/KmToolbar.h
  9. 22
      k-meleon/Plugins.cpp
  10. 81
      k-meleon/ToolBarEx.cpp
  11. 4
      k-meleon/ToolBarEx.h
  12. 56
      k-meleon/bmp_menu/bmp_menu.cpp
  13. 3
      k-meleon/kmeleon_plugin.h
  14. 29
      k-meleon/macros2/functions.h
  15. 19
      k-meleon/toolbars/toolbars.cpp

4
k-meleon/JSBridge/jscomp.cpp

@ -313,9 +313,9 @@ NS_IMETHODIMP CJSBridge::SetCmdIcon(const char * name, JS::HandleValue icon, JSC
return NS_OK;
}
NS_IMETHODIMP CJSBridge::AddButton(const char * name, const char * command, const char * menu)
NS_IMETHODIMP CJSBridge::AddButton(const char * name, const char * command, const char * menu, const char* tooltip)
{
kPlugin.kFuncs->AddButton(name, command, menu);
kPlugin.kFuncs->AddButton(name, command, menu, tooltip);
return NS_OK;
}

2
k-meleon/JSBridge/nsIJSBridge.idl

@ -61,7 +61,7 @@ interface nsIJSBridge : nsISupports
kmIButton CreateButton(in string cmd, [optional] in string menu, [optional] in string tooltip, [optional] in string label);
kmIButton CreateCallbackButton(in kmICommandFunction command, [optional] in string menu, [optional] in string tooltip, [optional] in string label);
//void AddButton(in string toolbar, in kmIButton button);
void AddButton(in string toolbar, in string command, [optional] in string menu);
void AddButton(in string toolbar, in string command, [optional] in string menu, [optional] in string tooltip);
void RemoveButton(in string toolbar, in string command);
void id(in nsIDOMWindow window, in string id);

2
k-meleon/KMeleonConst.h

@ -17,7 +17,7 @@
*/
#define KMELEON_VERSION 0x02010001
#define KMELEON_VERSION 0x02010004
#define MOZILLA_BUILDID 20140105
#define KMELEON_BUILDID 7500
#define KMELEON_UVERSION 75.0

79
k-meleon/KmImage.cpp

@ -230,7 +230,7 @@ HBITMAP nsImageObserver::CreateDIB(imgIRequest *aRequest)
#ifdef _DEBUG
// There is a problem with the linking in debug
// Use a dummy image instead
return (HBITMAP)::LoadImage(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_TOOLBAR_CLOSE), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
return (HBITMAP)::LoadImage(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
//return NULL;
#endif
@ -309,15 +309,40 @@ bool KmImage::LoadIndexedFromSkin(LPCTSTR name, UINT w, UINT h)
return true;
}
bool KmImage::LoadFromSkin(LPCTSTR name, const LPRECT rect)
bool KmImage::LoadFromSkin(LPCTSTR name, const LPRECT prect, bool single)
{
CRect rect;
if (prect) rect = *prect;
CString imgPath(name);
int index = -1;
int pos = imgPath.Find(_T('['));
if (pos != -1) {
int pos2 = imgPath.Find(_T(']'));
index = _ttoi(imgPath.Mid(pos+1, pos2-pos).GetBuffer());
imgPath.Truncate(pos);
int startPos = imgPath.Find(_T('['));
if (startPos != -1) {
int endPos = imgPath.Find(_T(']'), startPos);
if (endPos == -1) return false;
CString param = imgPath.Mid(startPos+1, endPos-startPos-1);
int pos = param.Find(_T(','));
if (pos == -1) {
index = _ttoi(param.GetBuffer());
} else {
int pos2 = param.Find(_T(','), pos+1);
if (pos2 == -1) {
rect.right = _ttoi(param.Mid(0, pos-1).GetBuffer());
rect.bottom = _ttoi(param.Mid(pos+1).GetBuffer());
} else {
int pos3 = param.Find(_T(','), pos2+1);
if (pos3 == -1) {
index = _ttoi(param.Mid(0, pos).GetBuffer());
rect.right = _ttoi(param.Mid(pos+1, pos2-pos-1).GetBuffer());
rect.bottom = _ttoi(param.Mid(pos2+1).GetBuffer());
} else {
rect.top = _ttoi(param.Mid(0, pos).GetBuffer());
rect.right = _ttoi(param.Mid(pos+1, pos2-pos-1).GetBuffer());
rect.bottom = _ttoi(param.Mid(pos2+1, pos3-pos2-1).GetBuffer());
rect.left = _ttoi(param.Mid(pos3+1).GetBuffer());
}
}
}
imgPath.Truncate(startPos);
}
CString path;
@ -327,12 +352,12 @@ bool KmImage::LoadFromSkin(LPCTSTR name, const LPRECT rect)
return false;
}
ASSERT(index==-1 || rect);
ASSERT(index==-1 || !rect.IsRectNull());
if (index>=0 && rect) {
Crop(rect->right-rect->left, GetHeight(), index);
} else if (rect) {
Clip(*rect);
if (index>=0 && !rect.IsRectNull()) {
Crop(rect.right-rect.left, single ? rect.bottom-rect.top : GetHeight(), index);
} else if (!rect.IsRectNull()) {
Clip(rect);
}
return true;
@ -470,6 +495,7 @@ UINT KmImage::GetHeight() const
#define round(x) (UINT)((x)+0.5)
bool KmImage::Scale(float f)
{
if (f == 1.0) return true;
ASSERT(mGdiBitmap || mBitmap.GetSafeHandle());
return Resize(round(GetWidth()*f), round(GetHeight()*f));
//return Resize(round(mImage.GetWidth()*f), round(mImage.GetHeight()*f));
@ -562,8 +588,7 @@ bool KmImage::CropLine(UINT h, UINT line, KmImage& kImg) const
bool KmImage::Clip(const RECT& r)
{
ASSERT(mGdiBitmap);
ASSERT(GetWidth() >= r.right);
ASSERT(GetHeight() >= r.bottom);
ASSERT(GetWidth() >= r.right && GetHeight() >= r.bottom);
LONG w = r.right-r.left;
LONG h = r.bottom-r.top;
Gdiplus::Bitmap* newBitmap = new Gdiplus::Bitmap(w, h, mGdiBitmap->GetPixelFormat());
@ -587,7 +612,7 @@ bool KmImage::Crop(UINT w, UINT h, UINT index)
UINT nCol = ((w*index) % sw) / w;
UINT nLine = (w*index)/sw;
return Clip(CRect(nCol*w, nLine*h, nCol*w+w, nLine*h+h));
if (!mGdiBitmap) {
} else {
@ -669,9 +694,25 @@ int KmImage::AddToImageList(CImageList& list, int index)
Gdiplus::Color color;
mGdiBitmap->GetPixel(0,0,&color);
if (!IsComCtl6())
if (index < 0) {
if (IsComCtl6())
return list.Add(&mBitmap, nullptr);
return list.Add(&mBitmap, color.ToCOLORREF());
if (index == -1)
return list.Add(&mBitmap, nullptr);
return list.Replace(index, &mBitmap, nullptr) ? index : -1;
}
if (IsComCtl6())
return list.Replace(index, &mBitmap, nullptr) ? index : -1;
CDC hdcButton;
hdcButton.CreateCompatibleDC(NULL);
hdcButton.SelectObject(mBitmap);
CDC hdcMask;
hdcMask.CreateCompatibleDC(&hdcButton);
CBitmap hMask;
hMask.CreateBitmap(GetWidth(), GetHeight(), 1, 1, NULL);
HGDIOBJ oldObject = hdcMask.SelectObject(hMask);
hdcButton.SetBkColor(color.ToCOLORREF());
hdcMask.BitBlt(0, 0, GetWidth(), GetHeight(), &hdcButton, 0, 0, SRCCOPY);
hdcMask.SelectObject(oldObject);
return list.Replace(index, &mBitmap, &hMask) ? index : -1;
}

2
k-meleon/KmImage.h

@ -99,7 +99,7 @@ public:
bool DrawItem(HDC dc, POINT pt, UINT index, UINT line, UINT, UINT);
bool LoadIndexedFromSkin(LPCTSTR name, UINT w, UINT h);
bool LoadFromSkin(LPCTSTR name, LPRECT rect = nullptr);
bool LoadFromSkin(LPCTSTR name, LPRECT rect = nullptr, bool single = false);
bool LoadFromBitmap(HBITMAP hbmp, bool reverse = false);
int AddToImageList(CImageList& list, int index = -1);
~KmImage() {

24
k-meleon/KmSkin.cpp

@ -390,21 +390,21 @@ int KmIconList::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImg
} else {
KmImage img, hotImg, deadImg;
if (!img.LoadFromSkin(coldImgPath, region))
return -1;
LONG w = img.GetWidth();
LONG h = img.GetHeight();
// If hot image specified, then 1 image for each state
if (hotImgPath && *hotImgPath) {
if (!hotImg.LoadFromSkin(hotImgPath, region))
hotImg.LoadFromSkin(coldImgPath, region);
if (!deadImgPath || !deadImg.LoadFromSkin(deadImgPath, region))
deadImg.LoadFromSkin(coldImgPath, region);
if (!img.LoadFromSkin(coldImgPath, region, true))
return -1;
if (!hotImg.LoadFromSkin(hotImgPath, region, true))
hotImg.LoadFromSkin(coldImgPath, region, true);
if (!deadImgPath || !*deadImgPath || !deadImg.LoadFromSkin(deadImgPath, region, true))
deadImg.LoadFromSkin(coldImgPath, region, true);
return AddIcon(img, hotImg, deadImg, id);
}
if (!img.LoadFromSkin(coldImgPath, region))
return -1;
LONG w = img.GetWidth();
LONG h = img.GetHeight();
// Single image with all states
int pos = AddIcons(img, w, h, id);
return pos;
@ -413,6 +413,8 @@ int KmIconList::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImg
int KmSkin::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id, const LPRECT region)
{
return mImages->AddIcon(coldImgPath, hotImgPath, deadImgPath, id, region);
int res = mImages->AddIcon(coldImgPath, hotImgPath, deadImgPath, id, region);
if (res>0) theApp.toolbars.Refresh();
return res;
}

134
k-meleon/KmToolbar.cpp

@ -55,6 +55,88 @@ bool KmToolbar::RemoveItem(UINT id)
return res;
}
KmButton* KmToolbar::AddItem(LPCTSTR name, UINT id, int before)
{
KmButton* pbutton = new KmButton();
pbutton->mName = name;
return pbutton;
}
int KmToolbar::AddImage(LPCTSTR cold, UINT w, UINT h, LPCTSTR hot, LPCTSTR dead, int oldIndex)
{
KmImage img;
int index = -1;
RECT r = {0,0,w,h};
if (cold && img.LoadFromSkin(cold, &r)) {
if (!mHot.m_hImageList) {
mHot.Create(mWidth, mHeight, ILC_MASK|ILC_COLOR32, 0, 10);
mCold.Create(mWidth, mHeight, ILC_MASK|ILC_COLOR32, 0, 10);
mDead.Create(mWidth, mHeight, ILC_MASK|ILC_COLOR32, 0, 10);
}
img.Scale((1.0*mWidth)/img.GetWidth());
if (hot && _tcslen(hot)) {
index = img.AddToImageList(mCold, oldIndex);
img.LoadFromSkin(hot, &r);
img.Scale((1.0*mWidth)/img.GetWidth());
int i = img.AddToImageList(mHot, oldIndex);
ASSERT(i == index);
if (dead && _tcslen(dead)) {
img.LoadFromSkin(dead, &r);
img.Scale((1.0*mWidth)/img.GetWidth());
}
i = img.AddToImageList(mDead, oldIndex);
ASSERT(i == index);
} else {
KmImage tmpImg;
if (!img.CropLine(mHeight, 0, tmpImg))
return index;
index = tmpImg.AddToImageList(mCold, oldIndex);
img.CropLine(mHeight, 1, tmpImg);
int i = tmpImg.AddToImageList(mHot, oldIndex);
ASSERT(index == i);
img.CropLine(mHeight, 2, tmpImg);
i = tmpImg.AddToImageList(mDead, oldIndex);
ASSERT(index == i);
}
} else {
ASSERT(oldIndex>=0);
if (oldIndex < 0) return -1;
if (hot && _tcslen(hot)) {
img.LoadFromSkin(hot, &r);
img.Scale((1.0*mWidth)/img.GetWidth());
index = img.AddToImageList(mHot, oldIndex);
ASSERT(index == oldIndex);
}
if (dead && _tcslen(dead)) {
img.LoadFromSkin(dead, &r);
img.Scale((1.0*mWidth)/img.GetWidth());
index = img.AddToImageList(mHot, oldIndex);
ASSERT(index == oldIndex);
}
}
return index;
}
int KmToolbar::SetImage(UINT id, LPCTSTR cold, LPCTSTR hot, LPCTSTR dead)
{
KmButton* b = GetButton(id);
if (!b) return -1;
int w = mWidth ? mWidth : theApp.skin.GetUserWidth();
int h = mHeight ? mHeight : theApp.skin.GetUserHeight();
b->mImageIndex = AddImage(cold, w, h, hot, dead, b->mImageIndex);
Refresh();
return b->mImageIndex;
}
void KmToolbar::AddItem(KmButton& button, int before, UINT w, UINT h)
{
KmButton* pbutton = new KmButton();
@ -63,8 +145,8 @@ void KmToolbar::AddItem(KmButton& button, int before, UINT w, UINT h)
pbutton->mID = theApp.commands.GetId(pbutton->mAction);
if (!pbutton->mID) return;
}
pbutton->mImageIndex = theApp.skin.GetIconIndex(pbutton->mID);
if (pbutton->mImageIndex == I_IMAGENONE && button.mColdImage.GetLength()) {
int imageIndex = theApp.skin.GetIconIndex(pbutton->mID);
if (imageIndex == I_IMAGENONE && button.mColdImage.GetLength()) {
/*if (button.mColdImage.Left(6).Compare(L"chrome") == 0) {
@ -79,8 +161,19 @@ void KmToolbar::AddItem(KmButton& button, int before, UINT w, UINT h)
} else {*/
if (!w) w = theApp.skin.GetUserWidth();
if (!h) h = theApp.skin.GetUserHeight();
if (!w) w = mWidth ? mWidth : theApp.skin.GetUserWidth();
if (!h) h = mHeight ? mHeight : theApp.skin.GetUserHeight();
if (!mWidth) {
mWidth = w;
mHeight = h;
}
pbutton->mImageIndex = AddImage(
button.mColdImage, w, h,
button.mHotImage,
button.mDeadImage
);
// If possible add the icon to the shared list
/*if (theApp.skin.mImages && (!mWidth || (
@ -91,38 +184,11 @@ void KmToolbar::AddItem(KmButton& button, int before, UINT w, UINT h)
} else */{
KmImage img;
if (img.LoadIndexedFromSkin(button.mColdImage, w, h)) {
if (!mWidth) {
mWidth = w;
mHeight = h;
}
if (!mHot.m_hImageList) {
mHot.Create(mWidth, mHeight, ILC_MASK|ILC_COLOR32, 0, 10);
mCold.Create(mWidth, mHeight, ILC_MASK|ILC_COLOR32, 0, 10);
mDead.Create(mWidth, mHeight, ILC_MASK|ILC_COLOR32, 0, 10);
}
pbutton->mImageIndex = img.AddToImageList(mCold);
if (button.mHotImage.GetLength()) {
img.LoadIndexedFromSkin(button.mHotImage, w, h);
int i = img.AddToImageList(mHot);
ASSERT(i == pbutton->mImageIndex);
}
if (button.mDeadImage.GetLength()) {
if (img.LoadIndexedFromSkin(button.mDeadImage, w, h)) {
int i = img.AddToImageList(mDead);
ASSERT(i == pbutton->mImageIndex);
}
}
}
}
//}
}
} else
pbutton->mImageIndex = I_IMAGECALLBACK;
mButtons.AddTail(pbutton);
POSITION pos = mToolbars.GetHeadPosition();
while (pos) {

5
k-meleon/KmToolbar.h

@ -27,7 +27,7 @@ class KmImage;
class KmButton
{
public:
KmButton() : mEnabled(true), mChecked(false), mID(0) {}
KmButton() : mEnabled(true), mChecked(false), mID(0),mImageIndex(I_IMAGENONE) {}
CString mName;
CString mLabel;
CString mTooltip;
@ -55,6 +55,9 @@ public:
}
};
int AddImage(LPCTSTR cold, UINT w = 0, UINT h = 0, LPCTSTR hot = NULL, LPCTSTR dead = NULL, int oldIndex = -1);
int SetImage(UINT id, LPCTSTR cold, LPCTSTR hot = NULL, LPCTSTR dead = NULL);
KmButton* AddItem(LPCTSTR name, UINT id, int before = -1);
void AddItem(KmButton& button, int before = -1, UINT w = 0, UINT h = 0);
bool RemoveItem(UINT id);

22
k-meleon/Plugins.cpp

@ -1693,8 +1693,8 @@ int GetWindowsList(HWND* list, unsigned size)
while (pos) {
CFrameWnd* frame = (CFrameWnd*)theApp.m_FrameWndLst.GetNext(pos);
*(list+i) = frame->GetSafeHwnd();
if (--size == 0) break;
i++;
if (--size == 0) break;
}
return i;
@ -1799,7 +1799,7 @@ bool RemoveButton(const char* name, const char* command)
return t->RemoveItem(theApp.commands.GetId(command));
}
bool AddButton(const char* name, const char* cmd, const char* menu)
bool AddButton(const char* name, const char* cmd, const char* menu, const char* tooltip)
{
USES_CONVERSION;
KmToolbar* t = theApp.toolbars.GetKToolbar(A2CT(name));
@ -1808,6 +1808,11 @@ bool AddButton(const char* name, const char* cmd, const char* menu)
KmButton button;
if (cmd) button.mAction = A2CT(cmd);
if (menu) button.mMenuName = A2CT(menu);
if (tooltip) {
wchar_t *t = WDecodeUTF8(tooltip);
button.mTooltip = t;
free(t);
}
button.mEnabled = true;
button.mChecked = false;
t->AddItem(button);
@ -1917,11 +1922,18 @@ int SetCmdIcon(const char* name, const char* icon, const LPRECT region, const ch
UINT id = theApp.commands.GetId(name);
if (!id) return -1;
USES_CONVERSION;
int res = theApp.skin.mImages->AddIcon(A2CT(icon), A2CT(hot), A2CT(dead), id, region);
theApp.toolbars.Refresh();
int res = theApp.skin.AddIcon(A2CT(icon), A2CT(hot), A2CT(dead), id, region);
return res;
}
int SetButtonIcon(const char* toolbar, UINT id, const char* icon, const LPRECT region, const char* hot, const LPRECT hotregion, const char* dead, const LPRECT deadregion)
{
USES_CONVERSION;
KmToolbar* t = theApp.toolbars.GetKToolbar(A2CT(toolbar));
if (!t) return -1;
return t->SetImage(id, A2CT(icon), A2CT(hot), A2CT(dead));
}
#include "nsIPermissionManager.h"
bool AddPermission(const char* url, const char* type, const char* perm, bool sessionOnly)
{
@ -2014,6 +2026,7 @@ kmeleonFunctions kmelFuncsUTF8 = {
RemoveButton,
AddButton,
SetCmdIcon,
SetButtonIcon,
AddPermission
};
@ -2089,6 +2102,7 @@ kmeleonFunctions kmelFuncs = {
RemoveButton,
AddButton,
SetCmdIcon,
SetButtonIcon,
AddPermission
};

81
k-meleon/ToolBarEx.cpp

@ -59,9 +59,10 @@ BEGIN_MESSAGE_MAP(CToolBarEx, CToolBar)
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONDBLCLK()
ON_WM_TIMER()
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xffff, OnTbnGetDispInfo)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xffff, OnTtnGetDispInfo)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
//}}AFX_MSG_MAP
ON_NOTIFY_REFLECT(TBN_GETDISPINFO, &CToolBarEx::OnTbnGetDispInfo)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
@ -149,12 +150,28 @@ void CToolBarEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
UINT textFlag = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_HIDEPREFIX | DT_WORD_ELLIPSIS;
CString text;
KmButton* kmbutton = kmtoolbar->GetButton(pNMCD->nmcd.dwItemSpec);
if (kmbutton) text = kmbutton->mLabel;
int image = I_IMAGENONE;
if (!kmtoolbar->mCold.m_hImageList) {
image = theApp.skin.GetIconIndex(pNMCD->nmcd.dwItemSpec);
CImageList* imageList = nullptr;
KmButton* kmbutton = kmtoolbar->GetButton(pNMCD->nmcd.dwItemSpec);
if (kmbutton) {
text = kmbutton->mLabel;
if (kmbutton->mImageIndex>=0) {
image = kmbutton->mImageIndex;
} else {
image = theApp.skin.GetIconIndex(pNMCD->nmcd.dwItemSpec);
if (pNMCD->nmcd.uItemState & CDIS_DISABLED)
imageList = &theApp.skin.mImages->mDead;
else if (pNMCD->nmcd.uItemState & CDIS_SELECTED)
imageList = &theApp.skin.mImages->mHot;
else if(pNMCD->nmcd.uItemState & CDIS_HOT && pNMCD->nmcd.uItemState & CDIS_CHECKED)
imageList = &theApp.skin.mImages->mHot;
else if (pNMCD->nmcd.uItemState & CDIS_CHECKED)
imageList = &theApp.skin.mImages->mHot;
else if (pNMCD->nmcd.uItemState & CDIS_HOT)
imageList = &theApp.skin.mImages->mHot;
else
imageList = &theApp.skin.mImages->mCold;
}
} else {
TBBUTTONINFO bi;
bi.cbSize = sizeof(TBBUTTONINFO);
@ -163,19 +180,20 @@ void CToolBarEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
image = bi.iImage;
}
CImageList* imageList;
if (pNMCD->nmcd.uItemState & CDIS_DISABLED)
imageList = GetToolBarCtrl().GetDisabledImageList();
else if (pNMCD->nmcd.uItemState & CDIS_SELECTED)
imageList = GetToolBarCtrl().GetHotImageList();
else if(pNMCD->nmcd.uItemState & CDIS_HOT && pNMCD->nmcd.uItemState & CDIS_CHECKED)
imageList = GetToolBarCtrl().GetHotImageList();
else if (pNMCD->nmcd.uItemState & CDIS_CHECKED)
imageList = GetToolBarCtrl().GetHotImageList();
else if (pNMCD->nmcd.uItemState & CDIS_HOT)
imageList = GetToolBarCtrl().GetHotImageList();
else
imageList = GetToolBarCtrl().GetImageList();
if (!imageList) {
if (pNMCD->nmcd.uItemState & CDIS_DISABLED)
imageList = GetToolBarCtrl().GetDisabledImageList();
else if (pNMCD->nmcd.uItemState & CDIS_SELECTED)
imageList = GetToolBarCtrl().GetHotImageList();
else if(pNMCD->nmcd.uItemState & CDIS_HOT && pNMCD->nmcd.uItemState & CDIS_CHECKED)
imageList = GetToolBarCtrl().GetHotImageList();
else if (pNMCD->nmcd.uItemState & CDIS_CHECKED)
imageList = GetToolBarCtrl().GetHotImageList();
else if (pNMCD->nmcd.uItemState & CDIS_HOT)
imageList = GetToolBarCtrl().GetHotImageList();
else
imageList = GetToolBarCtrl().GetImageList();
}
CPoint imagePoint;
CRect textRect;
@ -194,14 +212,12 @@ void CToolBarEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
ii.rcImage = CRect(0, 0, 16, 16);
if (imageList)
{
imageList->GetImageInfo(image, &ii);
if (ii.hbmMask) DeleteObject(ii.hbmMask);
if (ii.hbmImage) DeleteObject(ii.hbmImage);
imagePoint.y = contentRect.top + (contentRect.Height() - ii.rcImage.bottom + ii.rcImage.top)/2;
int w = 16, h = 16;
ImageList_GetIconSize(imageList->GetSafeHandle(), &w, &h);
imagePoint.y = contentRect.top + (contentRect.Height() - h)/2;
imagePoint.x = hp + contentRect.left;
imageList->Draw(pDC, image, imagePoint, ILD_TRANSPARENT);
contentRect.left += 2*hp + ii.rcImage.right - ii.rcImage.left;
contentRect.left += 2*hp + w;
}
if (text.GetLength()) {
@ -222,11 +238,11 @@ void CToolBarEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
break;
}
}
if (theApp.preferences.GetBool("kmeleon.display.toolbars_alt", 0));
if (!theApp.preferences.GetBool("kmeleon.display.toolbars_alt", 0))
*pResult |= CDRF_NOTIFYITEMDRAW;
}
BOOL CToolBarEx::OnTbnGetDispInfo(UINT, NMHDR * pNotifyStruct, LRESULT* pResult)
BOOL CToolBarEx::OnTtnGetDispInfo(UINT, NMHDR * pNotifyStruct, LRESULT* pResult)
{
static CString text;
*pResult = 0;
@ -429,3 +445,14 @@ void CToolBarEx::OnTimer(UINT nIDEvent) {
CToolBar::OnTimer(nIDEvent);
}
void CToolBarEx::OnTbnGetDispInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTBDISPINFO pNMTBDispInfo = reinterpret_cast<LPNMTBDISPINFO>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
KmToolbar* toolbar = (KmToolbar*)GetProp(GetSafeHwnd(), _T("kmToolbar"));
if (!toolbar) return;
pNMTBDispInfo->iImage = theApp.skin.GetIconIndex(pNMTBDispInfo->idCommand);
}

4
k-meleon/ToolBarEx.h

@ -42,9 +42,11 @@ protected:
afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg int GetButtonIDFromPoint(CPoint *point);
afx_msg BOOL OnTbnGetDispInfo(UINT, NMHDR * pNotifyStruct , LRESULT* pResult);
afx_msg BOOL OnTtnGetDispInfo(UINT, NMHDR * pNotifyStruct , LRESULT* pResult);
afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnTbnGetDispInfo(NMHDR *pNMHDR, LRESULT *pResult);
};

56
k-meleon/bmp_menu/bmp_menu.cpp

@ -369,8 +369,9 @@ int Init() {
HIMAGELIST hList = kPlugin.kFuncs->GetCmdIconList();
if (hList) {
ImageList_GetIconSize(hList, &gBmpWidth, &gBmpHeight);
gMarginLeft = gBmpWidth + BMP_PADDING_LEFT + BMP_PADDING_RIGHT;
int w,h;
ImageList_GetIconSize(hList, &w, &h);
gMarginLeft = max(gMarginLeft, w + BMP_PADDING_LEFT + BMP_PADDING_RIGHT);
}
gMarginLeft = max(gMarginLeft, GetSystemMetrics(SM_CXMENUCHECK)+ BMP_PADDING_LEFT + BMP_PADDING_RIGHT);
@ -525,30 +526,20 @@ void DoMenu(HMENU menu, char *param){
int DrawBitmap(DRAWITEMSTRUCT *dis) {
BmpMapT::iterator bmpMapIt;
bmpMapIt = bmpMap.find(dis->itemID);
HIMAGELIST hImgList = hImageList;
int bmpIdx = bmpMapIt != bmpMap.end() ? bmpMapIt->second : -1;
HIMAGELIST hImgList = kPlugin.kFuncs->GetCmdIconList();
if (!hImgList)
hImgList = hImageList;
else
bmpIdx = kPlugin.kFuncs->GetCmdIcon(dis->itemID);
// Load the corresponding bitmap
if (bmpIdx >= 0){
int top = (dis->rcItem.bottom - dis->rcItem.top - gBmpHeight) / 2;
top += dis->rcItem.top;
if (dis->itemState & ODS_GRAYED)
ImageList_DrawEx(hImgList, bmpIdx, dis->hDC, dis->rcItem.left+BMP_PADDING_LEFT, top, 0, 0, CLR_NONE, GetSysColor(COLOR_MENU), ILD_BLEND | ILD_TRANSPARENT);
else if (dis->itemState & ODS_SELECTED)
ImageList_Draw(hImgList, bmpIdx, dis->hDC, dis->rcItem.left+BMP_PADDING_LEFT, top, ILD_TRANSPARENT);
else
ImageList_Draw(hImgList, bmpIdx, dis->hDC, dis->rcItem.left+BMP_PADDING_LEFT, top, ILD_TRANSPARENT);
return gBmpWidth;
HIMAGELIST sImgList = kPlugin.kFuncs->GetCmdIconList();
if (sImgList) {
int idx = kPlugin.kFuncs->GetCmdIcon(dis->itemID);
if (idx>=0) {
hImgList = sImgList;
bmpIdx = idx;
}
}
else if (dis->itemState & ODS_CHECKED) {
if (dis->itemState & ODS_CHECKED) {
// The checkmark doesn't have a fixed size !!!
HDC hdcMem = CreateCompatibleDC(dis->hDC);
@ -596,6 +587,23 @@ int DrawBitmap(DRAWITEMSTRUCT *dis) {
DrawCheckMark(dis->hDC, dis->rcItem.left+BMP_PADDING_LEFT+4, dis->rcItem.top+5, GetSysColor(COLOR_MENUTEXT));
return BMP_WIDTH;*/
}
// Load the corresponding bitmap
else if (bmpIdx >= 0){
int top = (dis->rcItem.bottom - dis->rcItem.top - gBmpHeight) / 2;
top += dis->rcItem.top;
if (dis->itemState & ODS_GRAYED)
ImageList_DrawEx(hImgList, bmpIdx, dis->hDC, dis->rcItem.left+BMP_PADDING_LEFT, top, 0, 0, CLR_NONE, GetSysColor(COLOR_MENU), ILD_BLEND | ILD_TRANSPARENT);
else if (dis->itemState & ODS_SELECTED)
ImageList_Draw(hImgList, bmpIdx, dis->hDC, dis->rcItem.left+BMP_PADDING_LEFT, top, ILD_TRANSPARENT);
else
ImageList_Draw(hImgList, bmpIdx, dis->hDC, dis->rcItem.left+BMP_PADDING_LEFT, top, ILD_TRANSPARENT);
return gBmpWidth;
}
return 0;
}

3
k-meleon/kmeleon_plugin.h

@ -377,8 +377,9 @@ typedef struct {
bool (*FindSkinFile)(const wchar_t* name, wchar_t* result, unsigned size);
void (*GotoHistoryIndex)(HWND hWnd, UINT index);
bool (*RemoveButton)(const char* name, const char* command);
bool (*AddButton)(const char* name, const char* command, const char* menu);
bool (*AddButton)(const char* name, const char* command, const char* menu, const char* tooltip);
int (*SetCmdIcon)(const char* name, const char* icon, const LPRECT region, const char* hot, const LPRECT hotregion, const char* dead, const LPRECT deadregion);
int (*SetButtonIcon)(const char* toolbar, UINT id, const char* icon, const LPRECT region, const char* hot, const LPRECT hotregion, const char* dead, const LPRECT deadregion);
bool (*AddPermission)(const char* url, const char* type, const char* perm, bool sessionOnly);
} kmeleonFunctions;

29
k-meleon/macros2/functions.h

@ -1478,8 +1478,8 @@
Value addbutton(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 2,3);
return kPlugin.kFuncs->AddButton(data->getstr(1), data->getstr(2), data->getstr(3));
checkArgs(__FUNCTION__, data, 2,4);
return kPlugin.kFuncs->AddButton(data->getstr(1), data->getstr(2), data->getstr(3), data->getstr(4));
}
Value removebutton(FunctionData* data)
@ -1493,17 +1493,34 @@
checkArgs(__FUNCTION__, data, 2,6);
MString name = data->getstr(1);
MString icon = data->getstr(2);
MString hot = data->getstr(5);
MString dead = data->getstr(6);
MString hot = data->getstr(3);
MString dead = data->getstr(4);
RECT r = {0,0,data->getint(3),data->getint(4)};
LPRECT pr = r.right && r.bottom ? &r : nullptr;
//RECT r = {0,0,data->getint(3),data->getint(4)};
LPRECT pr = nullptr;
return kPlugin.kFuncs->SetCmdIcon(
name, icon, pr, hot, pr, dead, pr
);
return Value();
}
Value setbuttonicon(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 2,6);
MString name = data->getstr(1);
int id = kPlugin.kFuncs->GetID(data->getstr(2));
MString icon = data->getstr(3);
MString hot = data->getstr(4);
MString dead = data->getstr(5);
//RECT r = {0,0,data->getint(3),data->getint(4)};
LPRECT pr = nullptr;
return kPlugin.kFuncs->SetButtonIcon(
name, id, icon, pr, hot, pr, dead, pr
);
return Value();
}
// toolbar, name, command, menu, label, tooltip, cold, hot, dead, w, h
Value addbuttonex(FunctionData* data)
{

19
k-meleon/toolbars/toolbars.cpp

@ -896,7 +896,7 @@ void EndButton(s_toolbar *toolbar, s_button *button, int state) {
cmd ? cmd : "",
button->menu,
button->hotImage,
button->coldImage ? button->coldImage : button->hotImage,
button->coldImage,
button->deadImage,
true,
false,
@ -1277,12 +1277,12 @@ int AddButtonMsg(char *sParams) {
if (cold) {
AddImageToList(pToolbar, pButton, COLD, cold);
pButton->hotImage = strdup(cold);
pButton->coldImage = strdup(cold);
}
if (dead) {
AddImageToList(pToolbar, pButton, DEAD, dead);
pButton->hotImage = strdup(dead);
pButton->deadImage = strdup(dead);
}
EndButton(pToolbar, pButton, !cold? COLD : DEAD);
@ -1380,17 +1380,14 @@ void SetButtonImage(char *sParams) {//WORD iToolbar, WORD iButton, char *sImage)
char *sImage = SkipWhiteSpace(c+1);
if (!gbLegacy) {
kmeleonButton b = {0};
b.checked = -1;
b.enabled = -1;
b.hotimage = b.deadimage = b.coldimage = nullptr;
char* hotimage = nullptr, *deadimage = nullptr, *coldimage = nullptr;
switch(iImagelist) {
case IMAGELIST_HOT:b.hotimage = sImage; break;
case IMAGELIST_COLD:b.coldimage = sImage; break;
case IMAGELIST_DEAD:b.deadimage = sImage; break;
case IMAGELIST_HOT:hotimage = sImage; break;
case IMAGELIST_COLD:coldimage = sImage; break;
case IMAGELIST_DEAD:deadimage = sImage; break;
}
kPlugin.kFuncs->SetButton(name, iButton, &b);
kPlugin.kFuncs->SetButtonIcon(name, iButton, coldimage, nullptr, hotimage, nullptr, deadimage, nullptr);
}
*d = ','; // replace comma

Loading…
Cancel
Save