1 jls.loader.provide('jls.win32.ShellNotifyIconElement');
  2 
  3 jls.loader.require('jls.win32.WindowElement');
  4 jls.loader.require('jls.win32.ShellNotifyIcon');
  5 
  6 jls.win32.ShellNotifyIconElement = jls.lang.Class.create(jls.win32.WindowElement,
  7 {
  8     initialize : function($super, parameters, parent) {
  9         this._notifIcon = null;
 10         this._tip = null;
 11         if (typeof parent != 'undefined') {
 12             throw new jls.lang.Exception('ShellNotifyIconElement takes no parent');
 13         }
 14         $super(parameters, parent);
 15     },
 16     onCreate : function() {
 17         this._window = new jls.win32.Window(jls.win32.ShellNotifyIconElement.CLASSNAME, undefined, 0);
 18         this._notifIcon = new jls.win32.ShellNotifyIcon(this._window, 1 /* id */,
 19             jls.win32.ShellNotifyIcon.NIF_ICON | jls.win32.ShellNotifyIcon.NIF_MESSAGE | jls.win32.ShellNotifyIcon.NIF_TIP,
 20             jls.win32.Window.WM_USER);
 21         this._notifIcon.notify(jls.win32.ShellNotifyIcon.NIM_ADD);
 22         jls.logger.trace('Add icon');
 23         if (this._tip) {
 24             this.setTip(this._tip);
 25         }
 26     },
 27     onWindowMessage: function($super, message, wParam, lParam) {
 28     	$super(message, wParam, lParam);
 29         switch(message) {
 30         case jls.win32.Window.WM_USER:
 31             switch(lParam) {
 32             case jls.win32.Window.WM_LBUTTONDOWN:
 33                 // TODO Use jls.win32.WindowElement.createMouseEvent
 34                 this.dispatch(jls.gui.Event.createMouseEvent('mousedown', this, jls.gui.Event.MOUSE_BUTTON_LEFT, 0, 0, 0, 0));
 35                 break;
 36             case jls.win32.Window.WM_LBUTTONUP:
 37                 this.dispatch(jls.gui.Event.createMouseEvent('mouseup', this, jls.gui.Event.MOUSE_BUTTON_LEFT, 0, 0, 0, 0));
 38                 this.dispatch(jls.gui.Event.createMouseEvent('click', this, jls.gui.Event.MOUSE_BUTTON_LEFT, 0, 0, 0, 0));
 39                 break;
 40             case jls.win32.Window.WM_LBUTTONDBLCLK:
 41                 this.dispatch(jls.gui.Event.createMouseEvent('dblclick', this, jls.gui.Event.MOUSE_BUTTON_LEFT, 0, 0, 0, 0));
 42                 break;
 43             case jls.win32.Window.WM_MBUTTONDOWN:
 44                 this.dispatch(jls.gui.Event.createMouseEvent('mousedown', this, jls.gui.Event.MOUSE_BUTTON_MIDDLE, 0, 0, 0, 0));
 45                 break;
 46             case jls.win32.Window.WM_MBUTTONUP:
 47                 this.dispatch(jls.gui.Event.createMouseEvent('mouseup', this, jls.gui.Event.MOUSE_BUTTON_MIDDLE, 0, 0, 0, 0));
 48                 this.dispatch(jls.gui.Event.createMouseEvent('click', this, jls.gui.Event.MOUSE_BUTTON_MIDDLE, 0, 0, 0, 0));
 49                 break;
 50             case jls.win32.Window.WM_MBUTTONDBLCLK:
 51                 this.dispatch(jls.gui.Event.createMouseEvent('dblclick', this, jls.gui.Event.MOUSE_BUTTON_MIDDLE, 0, 0, 0, 0));
 52                 break;
 53             case jls.win32.Window.WM_RBUTTONDOWN:
 54                 this.dispatch(jls.gui.Event.createMouseEvent('mousedown', this, jls.gui.Event.MOUSE_BUTTON_RIGHT, 0, 0, 0, 0));
 55                 break;
 56             case jls.win32.Window.WM_RBUTTONUP:
 57                 this.dispatch(jls.gui.Event.createMouseEvent('mouseup', this, jls.gui.Event.MOUSE_BUTTON_RIGHT, 0, 0, 0, 0));
 58                 this.dispatch(jls.gui.Event.createMouseEvent('click', this, jls.gui.Event.MOUSE_BUTTON_RIGHT, 0, 0, 0, 0));
 59                 break;
 60             case jls.win32.Window.WM_RBUTTONDBLCLK:
 61                 this.dispatch(jls.gui.Event.createMouseEvent('dblclick', this, jls.gui.Event.MOUSE_BUTTON_RIGHT, 0, 0, 0, 0));
 62                 break;
 63             case jls.win32.Window.WM_MOUSEMOVE:
 64                 this.dispatch(jls.gui.Event.createMouseEvent('mousemove', this, -1, 0, 0, 0, 0));
 65                 break;
 66             }
 67             break;
 68         }
 69     },
 70     onDestroy : function($super) {
 71         $super();
 72         this._notifIcon.notify(jls.win32.ShellNotifyIcon.NIM_DELETE);
 73         return this;
 74     },
 75     /*setIcon : function(icon) {
 76         this._notifIcon.setIcon(icon);
 77         return this;
 78     },*/
 79     setIcon : function(name) {
 80         var icon = jls.win32.WindowElement.getIcon(name);
 81         if (icon) {
 82             this._icon = name;
 83             if (this._notifIcon) {
 84                 jls.logger.trace('Set icon: "' + name + '"');
 85                 this._notifIcon.setIcon(icon);
 86                 this.update();
 87             }
 88         }
 89         return this;
 90     },
 91     setTip : function(tip) {
 92         this._tip = tip;
 93         if (this._notifIcon) {
 94             this._notifIcon.setTip(tip);
 95             this.update();
 96         }
 97         return this;
 98     },
 99     update : function() {
100         this._notifIcon.notify(jls.win32.ShellNotifyIcon.NIM_MODIFY);
101         return this;
102     }
103 });
104 
105 Object.extend(jls.win32.ShellNotifyIconElement,
106 {
107     CLASSNAME : 'ShellNotifyIconClass'
108 });
109 
110 jls.win32.Window.registerClass(jls.win32.ShellNotifyIconElement.CLASSNAME);
111