[Pkg-mozext-commits] [firetray] 23/84: display new mail ico (first steps)

David Prévot taffit at moszumanska.debian.org
Sun Jul 20 01:42:42 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository firetray.

commit 408116489e4b9d211f8c69d645282124da126e2a
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Sat Feb 8 15:04:16 2014 +0100

    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(-)

diff --git a/src/chrome/skin/winnt/mail-unread.ico b/src/chrome/skin/winnt/mail-unread.ico
new file mode 100644
index 0000000..25817e1
Binary files /dev/null and b/src/chrome/skin/winnt/mail-unread.ico differ
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 @@
     <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>
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<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;
diff --git a/src/modules/winnt/FiretrayWindow.jsm b/src/modules/winnt/FiretrayWindow.jsm
index 3e6a6ed..3076ea9 100644
--- a/src/modules/winnt/FiretrayWindow.jsm
+++ b/src/modules/winnt/FiretrayWindow.jsm
@@ -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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git



More information about the Pkg-mozext-commits mailing list