From 408116489e4b9d211f8c69d645282124da126e2a Mon Sep 17 00:00:00 2001 From: foudfou Date: Sat, 8 Feb 2014 15:04:16 +0100 Subject: [PATCH] display new mail ico (first steps) --- src/chrome/skin/winnt/mail-unread.ico | Bin 0 -> 2086 bytes src/install.rdf | 2 +- src/modules/ctypes/ctypesMap.jsm | 4 ++ src/modules/ctypes/winnt/shell32.jsm | 2 + src/modules/ctypes/winnt/user32.jsm | 30 ++++++++++---- src/modules/winnt/FiretrayStatusIcon.jsm | 50 +++++++++++++++++++++-- src/modules/winnt/FiretrayWindow.jsm | 4 +- 7 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 src/chrome/skin/winnt/mail-unread.ico diff --git a/src/chrome/skin/winnt/mail-unread.ico b/src/chrome/skin/winnt/mail-unread.ico new file mode 100644 index 0000000000000000000000000000000000000000..25817e12da46b879de9c9db248110ef5dac01cfe GIT binary patch literal 2086 zcmdUwe`p*<6vtO+_oAd})7FdiM;p|N5~Wlt{$Ud7U%i}CsTB3kiikxh*0hL1N=hXl zfl6r!9HNw>gySTH{1FUCDDgPXqa15Ek99eg<6K>qVObWI<2bg7U*DT#grsQ^`8|mAA;8UuBsMR7x zQX$o0v{@nbttp^diG4jGFqj^>t=7&lwuqN6F7YsoS`|yTO1N1rk_uQX6_772$?=8a zO)L}^@gr$|DKEu7+4)&HAG1_0`Muq4qgW|pesO`#AbbIe!R{*xSbB!StuE0Wann2eGml1sY@AD&yudxZJe_k_?Yx9`HaoYVuoTb(E2!s zo4K911KVl9ZZ=RhD){>Q8;M92Y7Yj3%qdcDxS(@@Y3=!hQkO0g#w1EHN0(E z_@=guR{KtF9LI2lC*^o97Ae;kCdTpZ*yp%FIXW4&@JbNjpdX^QSVC{bKp(~4-*j-O z(Zn&^MuzrybG)mot80532Cy3qT>tJmPMsgcm+cOY3m*gIuVpQ%ge$O}q}m5v4+D;a z6G4c>Zyw*UZ_MpbzIeZ~xhzhfJBwT=#wkC*VaJsWPK-}>idUs^F5K=T_RC~@V009F zs`kJlv_%^edn{YflM%?7&BzBrDOL6&3O=qX23-4ixxaTQf zgT!XPL-fvbZ&h-XKel;<=70F|SLiWYHh*(N^c}l&2Dq><>lW?T7@dKm#ABcKU6^Vf zw%JGfki2?rwa1JMz9abF8BV7++&f3oDLnK3dy;vkW+I|B+^ft`49wn{F9$nnt;_08 zQ+I{>ws%+KUv`;ov%4Ps&h|=Ev<_A3G?(h<`awJR;~_iDb=koIvf1+gq6^rr2f_Y? z5NW;XrF2((MEaTigY}&7JDuY{xnFn04c+lR(>?DP``(Sq{o5?7M|a)l^rm=S`nV!P zoH-Sv?s`9Qo4A>^asMs7+1!0ErW#AQZj#wDZdZIrj4|EwC%c81;##(;Uyl3!6Uy)3 y)G}_$i7vzuUZ?I-T(19)tf@`R7ujYbYlZT=qW+%$bIpXmv~3!+ZVeY7*Zv0eu$GMg literal 0 HcmV?d00001 diff --git a/src/install.rdf b/src/install.rdf index f308294..2fb257d 100644 --- a/src/install.rdf +++ b/src/install.rdf @@ -28,7 +28,7 @@ {3550f703-e582-4d05-9a08-453d09bdfdc6} - 27.0 + 24.0 30.0 diff --git a/src/modules/ctypes/ctypesMap.jsm b/src/modules/ctypes/ctypesMap.jsm index aabdd0b..54bd6f2 100644 --- a/src/modules/ctypes/ctypesMap.jsm +++ b/src/modules/ctypes/ctypesMap.jsm @@ -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"); diff --git a/src/modules/ctypes/winnt/shell32.jsm b/src/modules/ctypes/winnt/shell32.jsm index 7d97cad..83fb805 100644 --- a/src/modules/ctypes/winnt/shell32.jsm +++ b/src/modules/ctypes/winnt/shell32.jsm @@ -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); diff --git a/src/modules/ctypes/winnt/user32.jsm b/src/modules/ctypes/winnt/user32.jsm index cf4f1f5..3022040 100644 --- a/src/modules/ctypes/winnt/user32.jsm +++ b/src/modules/ctypes/winnt/user32.jsm @@ -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, diff --git a/src/modules/winnt/FiretrayStatusIcon.jsm b/src/modules/winnt/FiretrayStatusIcon.jsm index 312117b..a0bf959 100644 --- a/src/modules/winnt/FiretrayStatusIcon.jsm +++ b/src/modules/winnt/FiretrayStatusIcon.jsm @@ -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