Browse Source

Add clip by region

Add shared folder in skin (old default)
Refresh toolbar size when adding button, and update display when updating icon
master
boisso 7 years ago
parent
commit
c6288c78f7
  1. 60
      k-meleon/KmImage.cpp
  2. 5
      k-meleon/KmImage.h
  3. 78
      k-meleon/KmSkin.cpp
  4. 5
      k-meleon/KmSkin.h
  5. 25
      k-meleon/KmToolbar.cpp
  6. 1
      k-meleon/KmToolbar.h
  7. 6
      k-meleon/Plugins.cpp
  8. 13
      k-meleon/ReBarEx.cpp
  9. 3
      k-meleon/ReBarEx.h
  10. 2
      k-meleon/kmeleon_plugin.h

60
k-meleon/KmImage.cpp

@ -309,14 +309,36 @@ bool KmImage::LoadIndexedFromSkin(LPCTSTR name, UINT w, UINT h)
return true;
}
bool KmImage::LoadFromSkin(LPCTSTR name)
bool KmImage::LoadFromSkin(LPCTSTR name, const LPRECT rect)
{
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);
}
CString path;
theApp.skin.FindSkinFile(path, name);
return Load(path);
theApp.skin.FindSkinFile(path, imgPath);
if (!Load(path)) {
ASSERT(0);
return false;
}
ASSERT(index==-1 || rect);
if (index>=0 && rect) {
Crop(rect->right-rect->left, GetHeight(), index);
} else if (rect) {
Clip(*rect);
}
return true;
}
bool KmImage::LoadFromBitmap(HBITMAP hbmp)
bool KmImage::LoadFromBitmap(HBITMAP hbmp, bool reverse)
{
ASSERT(hbmp);
Clean();
@ -339,7 +361,7 @@ bool KmImage::LoadFromBitmap(HBITMAP hbmp)
byte* destBytes = (byte*)(bmd.Scan0);
for (int y = 0; y < bm.bmHeight; y++)
{
memcpy(destBytes + (y * lineSize), (byte*)bits + ((bm.bmHeight - y - 1) * lineSize), lineSize);
memcpy(destBytes + (y * lineSize), (byte*)bits + ((reverse?(bm.bmHeight - y - 1):y) * lineSize), lineSize);
}
mGdiBitmap->UnlockBits(&bmd);
if (!bm.bmBits) delete bits;
@ -389,7 +411,7 @@ bool KmImage::Load(LPCTSTR path)
if (CString(path).Find(_T(".bmp"))) {
// 32 bbp bitmap does not work well with gdi+
HBITMAP bmp = (HBITMAP)LoadImage(NULL, path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if (bmp) return LoadFromBitmap(bmp);
if (bmp) return LoadFromBitmap(bmp, true);
}
mGdiBitmap = Gdiplus::Bitmap::FromFile(path);
@ -415,7 +437,7 @@ bool KmImage::Load(LPCTSTR path)
int resx = GetDeviceCaps(dc, LOGPIXELSX);
mGdiBitmap->SetResolution(Gdiplus::REAL(resx),Gdiplus::REAL(resy)); // Prevent gdi+ to scale the image
*/
if (!Gdiplus::IsAlphaPixelFormat(mGdiBitmap->GetPixelFormat()))
if (!Gdiplus::IsAlphaPixelFormat(mGdiBitmap->GetPixelFormat() && IsComCtl6()))
MakeTransparent(mTrColor);
return mGdiBitmap != nullptr;
@ -537,6 +559,24 @@ bool KmImage::CropLine(UINT h, UINT line, KmImage& kImg) const
return true;
}
bool KmImage::Clip(const RECT& r)
{
ASSERT(mGdiBitmap);
ASSERT(GetWidth() >= r.right);
ASSERT(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());
Gdiplus::Graphics graphics(newBitmap);
if (graphics.DrawImage(mGdiBitmap, Gdiplus::Rect(0, 0, w, h), r.left, r.top, w, h, Gdiplus::UnitPixel) != Gdiplus::Ok) {
delete newBitmap;
return false;
}
Clean();
mGdiBitmap = newBitmap;
return true;
}
bool KmImage::Crop(UINT w, UINT h, UINT index)
{
ASSERT(mGdiBitmap);
@ -596,7 +636,7 @@ HBITMAP KmImage::GetHBitmap()
bmi.bmiHeader.biBitCount = USHORT( 32 );
bmi.bmiHeader.biCompression = BI_RGB;
hbmp = ::CreateDIBSection( NULL, &bmi, DIB_RGB_COLORS, &bits, NULL, 0 );
Gdiplus::Bitmap bmDest( GetWidth(), GetHeight(), GetWidth()*4, PixelFormat32bppARGB, static_cast< BYTE* >( bits ) );
Gdiplus::Bitmap bmDest( GetWidth(), GetHeight(), GetWidth()*4, IsComCtl6()?PixelFormat32bppARGB:PixelFormat32bppRGB, static_cast< BYTE* >( bits ) );
Gdiplus::Graphics gDest( &bmDest );
if (gDest.DrawImage( mGdiBitmap, 0, 0 ) != Gdiplus::Ok) {
DeleteObject(hbmp);
@ -631,5 +671,7 @@ int KmImage::AddToImageList(CImageList& list, int index)
if (!IsComCtl6())
return list.Add(&mBitmap, color.ToCOLORREF());
return index == -1 ? list.Add(&mBitmap, nullptr) : list.Replace(index, &mBitmap, nullptr);
if (index == -1)
return list.Add(&mBitmap, nullptr);
return list.Replace(index, &mBitmap, nullptr) ? index : -1;
}

5
k-meleon/KmImage.h

@ -87,6 +87,7 @@ public:
bool Load(LPCTSTR path);
bool Crop(UINT w, UINT h, UINT index);
bool Clip(const RECT& r);
bool CropLine(UINT h, UINT line, KmImage& img) const;
bool Resize(UINT w, UINT h);
bool Resize(UINT w, UINT h, KmImage& img) const;
@ -98,8 +99,8 @@ 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);
bool LoadFromBitmap(HBITMAP hbmp);
bool LoadFromSkin(LPCTSTR name, LPRECT rect = nullptr);
bool LoadFromBitmap(HBITMAP hbmp, bool reverse = false);
int AddToImageList(CImageList& list, int index = -1);
~KmImage() {
Clean();

78
k-meleon/KmSkin.cpp

@ -59,6 +59,10 @@ int KmIconList::AddIcon(KmImage& img, UINT id)
int KmIconList::AddIcons(KmImage& img, UINT imgWidth, UINT imgHeight, UINT id)
{
int idx = -1;
int index = -1;
if (id) mCmdList.Lookup(id, index);
KmImage tmpImg;
if (mHasDifferentSize) {
int cx, cy;
@ -67,11 +71,11 @@ int KmIconList::AddIcons(KmImage& img, UINT imgWidth, UINT imgHeight, UINT id)
KmImage sizedImg;
img.Scale((1.0*cx)/imgWidth, sizedImg);
if (sizedImg.CropLine(cy, 0, tmpImg)) {
tmpImg.AddToImageList(mSized);
idx = tmpImg.AddToImageList(mSized, index);
}
} else {
if (img.CropLine(cy, 0, tmpImg)) {
tmpImg.AddToImageList(mSized);
idx = tmpImg.AddToImageList(mSized, index);
}
}
}
@ -82,14 +86,12 @@ int KmIconList::AddIcons(KmImage& img, UINT imgWidth, UINT imgHeight, UINT id)
if (!img.CropLine(mHeight, 0, tmpImg))
return -1;
int index = -1;
if (id) mCmdList.Lookup(id, index);
int pos = tmpImg.AddToImageList(mCold, index);
if (pos == -1) return -1;
ASSERT(idx == -1 || idx == pos);
img.CropLine(mHeight, 1, tmpImg);
int idx = tmpImg.AddToImageList(mHot, index);
idx = tmpImg.AddToImageList(mHot, index);
ASSERT(pos == idx);
img.CropLine(mHeight, 2, tmpImg);
@ -202,15 +204,23 @@ bool KmSkin::FindSkinFile( CString& szSkinFile, LPCTSTR filename, LPCTSTR skin,
tmp = tmp.Left( tmp.GetLength()-2 );
}*/
// Fallback to default
// Fallback to shared
if (searchUser) {
file = theApp.GetFolder(SkinsFolder) + _T("\\default\\") + filename;
file = theApp.GetFolder(SkinsFolder) + _T("\\shared\\") + filename;
hFile = FindFirstFile(file, &FindData);
if(hFile != INVALID_HANDLE_VALUE) {
FindClose(hFile);
szSkinFile = file;
return true;
}
file = theApp.GetFolder(SkinsFolder) + _T("\\default\\") + filename;
hFile = FindFirstFile(file, &FindData);
if(hFile != INVALID_HANDLE_VALUE) {
FindClose(hFile);
szSkinFile = file;
return true;
}
}
return false;
@ -221,6 +231,7 @@ bool KmSkin::Init(LPCTSTR skinName)
{
using namespace rapidjson;
bool first = false;
if (!mImages) {
mDefWidth = GetDefWidth();
mDefHeight = GetDefHeight();
@ -231,18 +242,22 @@ bool KmSkin::Init(LPCTSTR skinName)
mDefHeight = userSize;
}
mSkinName = skinName;
mImages = new KmIconList(mDefWidth, mDefHeight);
first = true;
}
else
mImages->Reset();
mBackImg.DeleteObject();
CString filename;
if (!FindSkinFile(filename, _T("skin.cfg"), skinName, false))
return false;
bool oldSkin = !FindSkinFile(filename, _T("skin.cfg"), skinName, false);
if (!first) {
if (mOldSkin || oldSkin) return false;
mImages->Reset();
mBackImg.DeleteObject();
}
mOldSkin = oldSkin;
mSkinName = skinName;
CFile file;
if (!file.Open(filename, CFile::modeRead, NULL))
return false;
@ -331,8 +346,11 @@ bool KmSkin::Init(LPCTSTR skinName)
class iconSkinObserver: public IImageObserver {
UINT mID;
RECT mRegion;
public:
iconSkinObserver(UINT id): mID (id) {}
iconSkinObserver(UINT id): mID (id), mRegion(CRect(0,0,0,0)) {}
iconSkinObserver(UINT id, RECT r): mID (id), mRegion(r) {}
~iconSkinObserver() {}
void ImageLoaded(HBITMAP hBitmap)
{
@ -342,9 +360,12 @@ public:
KmImage img;
img.LoadFromBitmap(hBitmap);
if (mRegion.bottom != 0 || mRegion.right != 0)
img.Clip(mRegion);
img.Resize(w, h);
theApp.skin.mImages->AddIcon(img, mID);
DeleteObject(hBitmap);
theApp.toolbars.Refresh();
}
protected:
@ -352,11 +373,11 @@ protected:
};
#include "MozUtils.h"
int KmIconList::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id, UINT w, UINT h)
int KmIconList::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id, const LPRECT region)
{
if (CString(coldImgPath).Left(6).Compare(L"chrome") == 0) {
iconSkinObserver* io = new iconSkinObserver(id);
iconSkinObserver* io = new iconSkinObserver(id, region?*region:CRect(0,0,0,0));
nsCOMPtr<nsIURI> uri;
NewURI(getter_AddRefs(uri), CStringToNSString(coldImgPath));
@ -367,19 +388,20 @@ int KmIconList::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImg
return 0;
} else {
if (!w) w = theApp.skin.GetUserWidth();
if (!h) h = theApp.skin.GetUserHeight();
KmImage img, hotImg, deadImg;
if (!img.LoadIndexedFromSkin(coldImgPath, w, h))
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.LoadIndexedFromSkin(hotImgPath, w, h))
hotImg.LoadIndexedFromSkin(coldImgPath, w, h);
if (!deadImgPath || !deadImg.LoadIndexedFromSkin(deadImgPath, w, h))
deadImg.LoadIndexedFromSkin(coldImgPath, w, h);
if (!hotImg.LoadFromSkin(hotImgPath, region))
hotImg.LoadFromSkin(coldImgPath, region);
if (!deadImgPath || !deadImg.LoadFromSkin(deadImgPath, region))
deadImg.LoadFromSkin(coldImgPath, region);
return AddIcon(img, hotImg, deadImg, id);
}
@ -389,8 +411,8 @@ int KmIconList::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImg
}
}
int KmSkin::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id, UINT w, UINT h)
int KmSkin::AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id, const LPRECT region)
{
return mImages->AddIcon(coldImgPath, hotImgPath, deadImgPath, id, w, h);
return mImages->AddIcon(coldImgPath, hotImgPath, deadImgPath, id, region);
}

5
k-meleon/KmSkin.h

@ -65,7 +65,7 @@ public:
int AddIcons(KmImage& img, UINT w, UINT h, UINT id = 0);
int AddIcon(KmImage& img, UINT id = 0);
int AddIcon(KmImage& img, KmImage& hotImg, KmImage& deadImg, UINT id = 0);
int AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id = 0, UINT w = 0, UINT h = 0);
int AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id = 0, const LPRECT r = nullptr);
HIMAGELIST GetIconList() {
return mHasDifferentSize ? mSized.GetSafeHandle() : mCold.GetSafeHandle();
@ -104,6 +104,7 @@ protected:
CGdiObject miLoading;
CGdiObject miDefault;
CGdiObject miMain;
bool mOldSkin;
HICON LoadSkinIcon(LPCTSTR aSkinFile, UINT resID, CGdiObject& obj, UINT w = 16, UINT h = 16)
{
@ -207,6 +208,6 @@ public:
}
bool FindSkinFile( CString& szSkinFile, LPCTSTR filename, LPCTSTR skin = NULL, bool searchUser = true);
int AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id = 0, UINT w = 0, UINT h = 0);
int AddIcon(LPCTSTR coldImgPath, LPCTSTR hotImgPath, LPCTSTR deadImgPath, UINT id = 0, const LPRECT r = nullptr);
};

25
k-meleon/KmToolbar.cpp

@ -26,7 +26,6 @@
bool KmToolbar::RemoveItem(UINT id)
{
return FALSE;
bool res = false;
POSITION pos = mButtons.GetHeadPosition();
while (pos) {
@ -42,11 +41,15 @@ bool KmToolbar::RemoveItem(UINT id)
pos = mToolbars.GetHeadPosition();
while (pos) {
CToolBarEx* toolbar = mToolbars.GetNext(pos);
for (int i=0;i<toolbar->GetCount();i++) {
for (int i=0;i<toolbar->GetToolBarCtrl().GetButtonCount();i++) {
UINT bid, style;
int iimage;
toolbar->GetButtonInfo(i, bid, style, iimage);
if (id == bid) toolbar->GetToolBarCtrl().DeleteButton(i);
if (id == bid) {
toolbar->GetToolBarCtrl().DeleteButton(i);
CBrowserFrame* frm = DYNAMIC_DOWNCAST(CBrowserFrame,toolbar->GetParentFrame());
frm->m_wndReBar.RecalcMinSize(toolbar);
}
}
}
return res;
@ -80,13 +83,13 @@ void KmToolbar::AddItem(KmButton& button, int before, UINT w, UINT h)
if (!h) h = theApp.skin.GetUserHeight();
// If possible add the icon to the shared list
if (theApp.skin.mImages && (!mWidth || (
/*if (theApp.skin.mImages && (!mWidth || (
mWidth == theApp.skin.GetUserWidth() &&
mHeight == theApp.skin.GetUserHeight()))) {
theApp.skin.mImages->AddIcon(button.mColdImage, button.mHotImage, button.mDeadImage, pbutton->mID);
} else {
} else */{
KmImage img;
if (img.LoadIndexedFromSkin(button.mColdImage, w, h)) {
@ -126,6 +129,8 @@ void KmToolbar::AddItem(KmButton& button, int before, UINT w, UINT h)
CToolBarEx* toolbar = mToolbars.GetNext(pos);
TBBUTTON b = InitButton(pbutton, toolbar);
toolbar->GetToolBarCtrl().InsertButton(-1, &b);
CBrowserFrame* frm = DYNAMIC_DOWNCAST(CBrowserFrame,toolbar->GetParentFrame());
frm->m_wndReBar.RecalcMinSize(toolbar);
}
}
@ -284,4 +289,14 @@ BOOL KmToolbarService::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLE
((CCmdUI*)pExtra)->m_bEnableChanged = TRUE;
return TRUE;
}
void KmToolbarService::Refresh()
{
CBrowserFrame* pBrowserFrame = NULL;
POSITION pos = theApp.m_FrameWndLst.GetHeadPosition();
while( pos != NULL ) {
pBrowserFrame = (CBrowserFrame *) theApp.m_FrameWndLst.GetNext(pos);
pBrowserFrame->m_wndReBar.RedrawWindow(0, 0, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);
}
}

1
k-meleon/KmToolbar.h

@ -134,6 +134,7 @@ public:
BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
UINT GetDefaultWidth() { return mDefWidth; }
UINT GetDefaultHeight() { return mDefHeight; }
void Refresh();
protected:
CMap<CString, LPCTSTR, KmToolbar*, KmToolbar*> mToolbars;

6
k-meleon/Plugins.cpp

@ -1911,13 +1911,15 @@ bool FindSkinFile(const wchar_t* name, wchar_t* filename, unsigned size)
return true;
}
int SetCmdIcon(const char* name, const char* icon, UINT w, UINT h, const char* hot, const char* cold)
int SetCmdIcon(const char* name, const char* icon, const LPRECT region, const char* hot, const LPRECT hotregion, const char* dead, const LPRECT deadregion)
{
if (!theApp.skin.mImages) return -1;
UINT id = theApp.commands.GetId(name);
if (!id) return -1;
USES_CONVERSION;
return theApp.skin.mImages->AddIcon(A2CT(icon), A2CT(hot), A2CT(cold), id, w, h);
int res = theApp.skin.mImages->AddIcon(A2CT(icon), A2CT(hot), A2CT(dead), id, region);
theApp.toolbars.Refresh();
return res;
}
#include "nsIPermissionManager.h"

13
k-meleon/ReBarEx.cpp

@ -474,6 +474,19 @@ void CReBarEx::SaveBandSizes() {
}
}
void CReBarEx::RecalcMinSize(CControlBar* bar)
{
REBARBANDINFO rbbi;
int index = FindByChild(bar->m_hWnd);
ASSERT(index != -1);
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_STYLE;
GetReBarCtrl().GetBandInfo(index, &rbbi);
CSize size = bar->CalcFixedLayout(FALSE, m_dwStyle & CBRS_ORIENT_HORZ);
rbbi.cxMinChild = size.cx;
GetReBarCtrl().SetBandInfo(index, &rbbi);
}
void CReBarEx::RestoreBandSizes() {
int x;
REBARBANDINFO rbbi;

3
k-meleon/ReBarEx.h

@ -37,13 +37,14 @@ public:
public:
HMENU m_menu;
int FindByName(const TCHAR *name);
void ShowBand(int index, BOOL visibility);
int count() { return m_iCount; }
void lineup();
void SetNeedSeparator(bool);
bool GetNeedSeparator();
void RecalcMinSize(CControlBar* bar);
private:
int FindByChild (HWND hWnd);
int FindByIndex (int index);

2
k-meleon/kmeleon_plugin.h

@ -378,7 +378,7 @@ typedef struct {
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);
int (*SetCmdIcon)(const char* name, const char* icon, UINT w, UINT h, const char* hot, const char* cold);
int (*SetCmdIcon)(const char* name, 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;

Loading…
Cancel
Save