Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Make menu icons "transparent" during initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
foudfou committed Sep 14, 2014
1 parent e51be81 commit 7a8c15f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 9 deletions.
Binary file modified src/chrome/skin/icons/winnt/application-exit.bmp
Binary file not shown.
Binary file modified src/chrome/skin/icons/winnt/document-new.bmp
Binary file not shown.
Binary file modified src/chrome/skin/icons/winnt/gtk-apply.bmp
Binary file not shown.
Binary file modified src/chrome/skin/icons/winnt/gtk-edit.bmp
Binary file not shown.
Binary file modified src/chrome/skin/icons/winnt/gtk-preferences.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions src/modules/ctypes/winnt/gdi32.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function gdi32_defines(lib) {
this.NOMIRRORBITMAP = win32.DWORD(0x80000000); /* Do not Mirror the bitmap in this call */
this.CAPTUREBLT = win32.DWORD(0x40000000); /* Include layered windows */
lib.lazy_bind("CreateCompatibleBitmap", win32.HBITMAP, win32.HDC, ctypes.int, ctypes.int);
lib.lazy_bind("CreateBitmap", win32.HBITMAP, ctypes.int, ctypes.int, win32.UINT, win32.UINT, ctypes.voidptr_t);
lib.lazy_bind("CreateBitmapIndirect", win32.HBITMAP, win32.BITMAP.ptr);
lib.lazy_bind("GetObjectW", ctypes.int, win32.HGDIOBJ, ctypes.int, win32.LPVOID);
lib.lazy_bind("GetCurrentObject", win32.HGDIOBJ, win32.HDC, win32.UINT);
Expand Down Expand Up @@ -177,6 +178,9 @@ function gdi32_defines(lib) {
this.PBITMAPINFO = this.BITMAPINFO.ptr;
lib.lazy_bind("SetDIBits", ctypes.int, win32.HDC, win32.HBITMAP, win32.UINT, win32.UINT, ctypes.voidptr_t, this.BITMAPINFO.ptr, win32.UINT);

lib.lazy_bind("GetPixel", win32.COLORREF, win32.HDC, ctypes.int, ctypes.int);
lib.lazy_bind("SetPixel", win32.COLORREF, win32.HDC, ctypes.int, ctypes.int, win32.COLORREF);

}

new ctypes_library(GDI32_LIBNAME, GDI32_ABIS, gdi32_defines, this);
3 changes: 3 additions & 0 deletions src/modules/ctypes/winnt/user32.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ function user32_defines(lib) {
this.SWP_DEFERERASE = 0x2000;
this.SWP_ASYNCWINDOWPOS = 0x4000;

lib.lazy_bind("GetSysColor", win32.DWORD, ctypes.int);
this.COLOR_MENU = 4;

}

new ctypes_library(USER32_LIBNAME, USER32_ABIS, user32_defines, this);
52 changes: 43 additions & 9 deletions src/modules/winnt/FiretrayStatusIcon.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ if ("undefined" == typeof(firetray.Handler))

const ICON_CHROME_PATH = "chrome://firetray/skin/icons/winnt";
const ICON_CHROME_FILES = {
'blank-icon': ICON_CHROME_PATH+"/blank-icon.bmp",
'mail-unread': ICON_CHROME_PATH+"/mail-unread.ico",
// these are for the popup menu:
'prefs': ICON_CHROME_PATH+"/gtk-preferences.bmp",
'quit': ICON_CHROME_PATH+"/application-exit.bmp",
'new-wnd': ICON_CHROME_PATH+"/document-new.bmp",
'new-msg': ICON_CHROME_PATH+"/gtk-edit.bmp",
'reset': ICON_CHROME_PATH+"/gtk-apply.bmp"
'blank-icon': { use:'tray', path:ICON_CHROME_PATH+"/blank-icon.bmp" },
'mail-unread': { use:'tray', path:ICON_CHROME_PATH+"/mail-unread.ico" },
'prefs': { use:'menu', path:ICON_CHROME_PATH+"/gtk-preferences.bmp" },
'quit': { use:'menu', path:ICON_CHROME_PATH+"/application-exit.bmp" },
'new-wnd': { use:'menu', path:ICON_CHROME_PATH+"/document-new.bmp" },
'new-msg': { use:'menu', path:ICON_CHROME_PATH+"/gtk-edit.bmp" },
'reset': { use:'menu', path:ICON_CHROME_PATH+"/gtk-apply.bmp" },
};


Expand Down Expand Up @@ -97,8 +96,13 @@ firetray.StatusIcon = {
/* we'll take the first icon in the .ico file. To get the icon count in the
file, pass ctypes.cast(ctypes.int(-1), win32.UINT); */
for (let imgName in ICON_CHROME_FILES) {
let path = firetray.Utils.chromeToPath(ICON_CHROME_FILES[imgName]);
let path = firetray.Utils.chromeToPath(ICON_CHROME_FILES[imgName].path);
let img = this.loadImageFromFile(path);
if (img && ICON_CHROME_FILES[imgName].use == 'menu')
/* Ideally we should rebuild the menu each time it is shown as the menu
color may change. But, let's just consider it's not worth it for
now. */
img.himg = this.makeBitMapTransparent(img.himg);
if (img)
this[this.IMG_TYPES[img['type']]['map']].insert(imgName, img['himg']);
}
Expand Down Expand Up @@ -418,6 +422,36 @@ firetray.StatusIcon = {
log.error("icon '"+name+"' not defined.");
}
return hicon;
},

// http://www.dreamincode.net/forums/topic/281612-how-to-make-bitmaps-on-menus-transparent-in-c-win32/
makeBitMapTransparent: function(hbmSrc) {
log.debug("hbmSrc="+hbmSrc);
let hdcSrc = gdi32.CreateCompatibleDC(null);
let hdcDst = gdi32.CreateCompatibleDC(null);
if (!hdcSrc || !hdcSrc) return null;

let bm = new win32.BITMAP();
let err = gdi32.GetObjectW(hbmSrc, win32.BITMAP.size, bm.address());
let hbmOld = ctypes.cast(gdi32.SelectObject(hdcSrc, hbmSrc), win32.HBITMAP);
let width = bm.bmWidth, height = bm.bmHeight;
let hbmNew = gdi32.CreateBitmap(width, height, bm.bmPlanes, bm.bmBitsPixel, null);
gdi32.SelectObject(hdcDst, hbmNew);

gdi32.BitBlt(hdcDst,0,0,width, height,hdcSrc,0,0,gdi32.SRCCOPY);

let clrTP = gdi32.GetPixel(hdcDst, 0, 0); // color of first pixel
let clrBK = user32.GetSysColor(user32.COLOR_MENU); // current background color

for (let nRow=0, len=height; nRow<len; ++nRow)
for (let nCol=0, len=width; nCol<len; ++nCol)
if (firetray.js.strEquals(gdi32.GetPixel(hdcDst, nCol, nRow), clrTP))
gdi32.SetPixel(hdcDst, nCol, nRow, clrBK);

gdi32.DeleteDC(hdcDst);
gdi32.DeleteDC(hdcSrc);

return hbmNew;
}

}; // firetray.StatusIcon
Expand Down

0 comments on commit 7a8c15f

Please # to comment.