display new mail ico (first steps)

This commit is contained in:
foudfou 2014-02-08 15:04:16 +01:00
parent 23f4bc3014
commit 408116489e
7 changed files with 78 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -28,7 +28,7 @@
<em:targetApplication> <!-- Thunderbird -->
<Description>
<em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
<em:minVersion>27.0</em:minVersion>
<em:minVersion>24.0</em:minVersion>
<em:maxVersion>30.0</em:maxVersion>
</Description>
</em:targetApplication>

View File

@ -32,6 +32,10 @@ ctypesMap.prototype.get = function(key) {
return this.array[this.map[key]];
};
Object.defineProperties(ctypesMap.prototype, {
"keys": { get: function(){return Object.keys(this.map);} }
});
ctypesMap.prototype.insert = function(key, item) {
if (this.map.hasOwnProperty(key)) {
log.debug("REPLACE");

View File

@ -89,6 +89,8 @@ function shell32_defines(lib) {
this.NIF_REALTIME = 0x00000040;
this.NIF_SHOWTIP = 0x00000080;
lib.lazy_bind("ExtractIconW", win32.HICON, win32.HINSTANCE, win32.LPCTSTR, win32.UINT);
lib.lazy_bind("ExtractIconExW", win32.UINT, win32.LPCTSTR, ctypes.int, win32.HICON.ptr, win32.HICON.ptr, win32.UINT);
}
new ctypes_library(SHELL32_LIBNAME, SHELL32_ABIS, shell32_defines, this);

View File

@ -34,6 +34,7 @@ function user32_defines(lib) {
lib.lazy_bind("SendMessageW", win32.LRESULT, win32.HWND, win32.UINT, win32.WPARAM, win32.LPARAM);
this.WM_GETICON = 0x007F;
this.WM_SETICON = 0x0080;
this.ICON_SMALL = 0;
this.ICON_BIG = 1;
this.ICON_SMALL2 = 2;
@ -44,8 +45,11 @@ function user32_defines(lib) {
this.GCLP_HICONSM = -34;
lib.lazy_bind("LoadIconW", win32.HICON, win32.HINSTANCE, win32.LPCTSTR); // superseeded by LoadImage
this.IDI_APPLICATION = 32512;
this.IDI_APPLICATION = win32.MAKEINTRESOURCE(32512);
this.IDI_HAND = win32.MAKEINTRESOURCE(32513);
this.IDI_QUESTION = win32.MAKEINTRESOURCE(32514);
this.IDI_EXCLAMATION = win32.MAKEINTRESOURCE(32515);
this.IDI_ASTERISK = win32.MAKEINTRESOURCE(32516);
lib.lazy_bind("LoadImageW", win32.HANDLE, win32.HINSTANCE, win32.LPCTSTR, win32.UINT, ctypes.int, ctypes.int, win32.UINT);
this.LR_CREATEDIBSECTION = 0x00002000;
this.LR_DEFAULTCOLOR = 0x00000000;
@ -56,6 +60,7 @@ function user32_defines(lib) {
this.LR_MONOCHROME = 0x00000001;
this.LR_SHARED = 0x00008000;
this.LR_VGACOLOR = 0x00000080;
lib.lazy_bind("DestroyIcon", win32.BOOL, win32.HICON);
lib.lazy_bind("GetPropW", win32.HANDLE, win32.HWND, win32.LPCTSTR);
lib.lazy_bind("SetPropW", win32.BOOL, win32.HWND, win32.LPCTSTR, win32.HANDLE);
@ -65,13 +70,22 @@ function user32_defines(lib) {
lib.lazy_bind("SetWindowLongW", win32.LONG_PTR , win32.HWND, ctypes.int, win32.LONG_PTR);
// SetWindowLongPtrW aliases SetWindowLongW with the correct signature thank
// win32.LONG_PTR
lib.lazy_bind("SetWindowLongW", win32.LONG_PTR , win32.HWND, ctypes.int, win32.LONG_PTR);
this.GWL_EXSTYLE = -20;
this.GWLP_WNDPROC = -4;
this.GWLP_HINSTANCE = -6;
this.GWLP_ID = -12;
this.GWL_STYLE = -16;
this.GWLP_USERDATA = -21;
this.GWLP_WNDPROC = -4;
this.GWLP_ID = -12;
this.GWL_STYLE = -16;
this.GWL_EXSTYLE = -20;
this.GWLP_USERDATA = -21;
lib.lazy_bind("SetClassLongW", win32.DWORD , win32.HWND, ctypes.int, win32.LONG); // superseeded by SetClassLongPtrW
this.GCL_MENUNAME = -8;
this.GCL_HBRBACKGROUND = -10;
this.GCL_HCURSOR = -12;
this.GCL_HICON = -14;
this.GCL_HMODULE = -16;
this.GCL_CBWNDEXTRA = -18;
this.GCL_CBCLSEXTRA = -20;
this.GCL_WNDPROC = -24;
this.GCL_HICONSM = -34;
this.WNDPROC = ctypes.FunctionType(
WinCbABI, win32.LRESULT,

View File

@ -12,6 +12,7 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://firetray/ctypes/ctypesMap.jsm");
Cu.import("resource://firetray/ctypes/winnt/win32.jsm");
Cu.import("resource://firetray/ctypes/winnt/kernel32.jsm");
Cu.import("resource://firetray/ctypes/winnt/shell32.jsm");
@ -25,20 +26,24 @@ let log = firetray.Logging.getLogger("firetray.StatusIcon");
if ("undefined" == typeof(firetray.Handler))
log.error("This module MUST be imported from/after FiretrayHandler !");
FIRETRAY_ICON_CHROME_PATHS = {
'mail-unread': "chrome://firetray/skin/winnt/mail-unread.ico",
};
firetray.StatusIcon = {
initialized: false,
callbacks: {}, // pointers to JS functions. MUST LIVE DURING ALL THE EXECUTION
notifyIconData: null,
hwndProxy: null,
icons: null,
iconsPaths: {},
WNDCLASS_NAME: "FireTrayHiddenWindowClass",
WNDCLASS_ATOM: null,
init: function() {
this.FILENAME_BLANK = firetray.Utils.chromeToPath(
"chrome://firetray/skin/blank-icon.png");
this.loadIcons();
this.create();
firetray.Handler.setIconImageNewMail(); // TESTING
this.initialized = true;
return true;
@ -48,10 +53,45 @@ firetray.StatusIcon = {
log.debug("Disabling StatusIcon");
this.destroy();
this.destroyIcons();
this.initialized = false;
},
loadIcons: function() {
this.icons = new ctypesMap(win32.HICON);
/* 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 ico_name in FIRETRAY_ICON_CHROME_PATHS) {
let path = firetray.Utils.chromeToPath(FIRETRAY_ICON_CHROME_PATHS[ico_name]);
this.iconsPaths[ico_name] = path;
let hicon = shell32.ExtractIconW(null, path, 0);
// ERROR_INVALID_HANDLE(6) ignored (_Reserved_ HINSTANCE hInst ?)
this.icons.insert(ico_name, hicon);
log.debug("icon '"+ico_name+"'="+this.icons.get(ico_name)+" winLastError="+ctypes.winLastError);
}
},
destroyIcons: function() {
let success = true, errors = [];
let keys = this.icons.keys;
for (let i=0, len=keys.length; i<len; ++i) {
let ico_name = keys[i];
let res = user32.DestroyIcon(this.icons.get(ico_name));
if (res)
this.icons.remove(ico_name);
else
errors.push(ctypes.winLastError);
success = success && res;
}
if (!success) {
log.error("Couldn't destroy all icons: "+errors);
} else {
log.debug("Icons destroyed");
}
},
create: function() {
let hwnd_hidden = this.createProxyWindow();
@ -190,6 +230,10 @@ firetray.Handler.setIconImageDefault = function() {
};
firetray.Handler.setIconImageNewMail = function() {
let nid = firetray.StatusIcon.notifyIconData;
nid.hIcon = firetray.StatusIcon.icons.get('mail-unread');
rv = shell32.Shell_NotifyIconW(shell32.NIM_MODIFY, nid.address());
log.debug("Shell_NotifyIcon MODIFY="+rv+" winLastError="+ctypes.winLastError);
};
// firetray.Handler.setIconImageFromFile = firetray.StatusIcon.setIconImageFromFile;

View File

@ -97,7 +97,7 @@ firetray.Window.attachWndProc = function(wid, hwnd) {
Cu.reportError(x);
}
}
}
};
firetray.Window.detachWndProc = function(wid) {
let procPrev = firetray.Handler.wndProcsOrig.get(wid);
@ -131,7 +131,7 @@ firetray.Handler.registerWindow = function(win) {
let baseWin = firetray.Handler.getWindowInterface(win, "nsIBaseWindow");
let nativeHandle = baseWin.nativeHandle;
let hwnd = nativeHandle ?
new win32.HWND(ctypes.UInt64(nativeHandle)) :
firetray.Win32.hexStrToHwnd(nativeHandle) :
user32.FindWindowW("MozillaWindowClass", win.document.title);
let wid = firetray.Win32.hwndToHexStr(hwnd);
log.debug("=== hwnd="+hwnd+" wid="+wid+" win.document.title: "+win.document.title);