Author: jerome
Date: 2009-07-27 12:24:53 +0200 (Mon, 27 Jul 2009)
New Revision: 5173

Modified:
   
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.dcu
   
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.pas
Log:
* Added balloon notification area when user try to quit TuxBox 2.0
* Modified the way to display the tray icon.

Modified: 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.dcu
===================================================================
(Binary files differ)

Modified: 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.pas
===================================================================
--- 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.pas
 2009-07-26 11:41:30 UTC (rev 5172)
+++ 
software_suite_v3/software/tool/tux_droid_browser/windows/trunk/tux_droid_browser/Unit1.pas
 2009-07-27 10:24:53 UTC (rev 5173)
@@ -29,10 +29,64 @@
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, OleCtrls, SHDocVw_EWB, EwbCore, EmbeddedWB, Menus, ImgList, 
IEDownload,
   ExtCtrls, EwbControlComponent, AppEvnts, StdCtrls, ComCtrls, ShellAPI, 
TuxUtils,
-  Registry, CommCtrl;
+  Registry;
 
+
+const
+  NIF_INFO = $10;
+  NIF_MESSAGE = 1;
+  NIF_ICON = 2;
+  NOTIFYICON_VERSION = 3;
+  NIF_TIP = 4;
+  NIM_SETVERSION = $00000004;
+  NIM_SETFOCUS = $00000003;
+  NIIF_INFO = $00000001;
+  NIIF_WARNING = $00000002;
+  NIIF_ERROR = $00000003;
+
+  NIN_BALLOONSHOW = WM_USER + 2;
+  NIN_BALLOONHIDE = WM_USER + 3;
+  NIN_BALLOONTIMEOUT = WM_USER + 4;
+  NIN_BALLOONUSERCLICK = WM_USER + 5;
+  NIN_SELECT = WM_USER + 0;
+  NINF_KEY = $1;
+  NIN_KEYSELECT = NIN_SELECT or NINF_KEY;
+
+  {other constants can be found in vs.net---vc7's dir: 
PlatformSDK\Include\ShellAPI.h}
+
+  {define the callback message}
+  TRAY_CALLBACK = WM_USER + $7258;
+
+  {new NotifyIconData structure definition}
+type
+  PNewNotifyIconData = ^TNewNotifyIconData;
+  TDUMMYUNIONNAME    = record
+    case Integer of
+      0: (uTimeout: UINT);
+      1: (uVersion: UINT);
+  end;
+
+  TNewNotifyIconData = record
+    cbSize: DWORD;
+    Wnd: HWND;
+    uID: UINT;
+    uFlags: UINT;
+    uCallbackMessage: UINT;
+    hIcon: HICON;
+    //Version 5.0 is 128 chars, old ver is 64 chars
+    szTip: array [0..127] of Char;
+    dwState: DWORD; //Version 5.0
+    dwStateMask: DWORD; //Version 5.0
+    szInfo: array [0..255] of Char; //Version 5.0
+    DUMMYUNIONNAME: TDUMMYUNIONNAME;
+    szInfoTitle: array [0..63] of Char; //Version 5.0
+    dwInfoFlags: DWORD;   //Version 5.0
+  end;
+
+
 const wm_AppelMessage = wm_user + 1;
 
+
 type
   TForm1 = class(TForm)
     EmbeddedWB1: TEmbeddedWB;
@@ -56,9 +110,15 @@
     procedure EmbeddedWB1DocumentComplete(ASender: TObject;
       const pDisp: IDispatch; var URL: OleVariant);
     procedure ConnectionCheckerTimer(Sender: TObject);
-                         
+    procedure AddSysTrayIcon;
+    procedure ShowBalloonTips(mess : string);
+    procedure DeleteSysTrayIcon;
+    procedure HideBalloonTips();
+
+
   private
     { D�clarations priv�es }
+    IconData: TNewNotifyIconData;
     procedure WMAppelMessage(var msg : TMessage); message wm_AppelMessage;
 
     procedure OpenUrl(const url : String);
@@ -67,12 +127,14 @@
     { D�clarations publiques }
   end;
 
+
 var
   Form1         : TForm1;
   url           : String;
   Tray          : TNotifyIconData;
   AppIcon       : TIcon;
   started       : boolean;
+  balloonShowed : boolean;
 
 implementation
 
@@ -87,38 +149,29 @@
 procedure TForm1.FormCreate(Sender: TObject);
 begin
   url := 'http://127.0.0.1:270/user/';
-
   started := false;
 
-  //Tray icon initialization.
-  Tray.cbSize := SizeOf(Tray);
-  Tray.wnd := Handle;
-  Tray.uID := 1;
-  Tray.UCallbackMessage := wm_AppelMessage;
-
+  //Setting app icon.
   AppIcon := TIcon.Create;
   ImageList1.GetIcon(0, AppIcon);
   Application.Icon := AppIcon;
   Form1.Icon := AppIcon;
 
-  Tray.hIcon := Application.Icon.handle;
-  Tray.szTip := 'Show / Hide TuxBox 2.0';
-  Tray.uFlags := nif_message or nif_icon or nif_tip;
+  balloonShowed := false;
+  Form1.AddSysTrayIcon;
 
-  //Adding tray icon to the system tray.
-  Shell_NotifyIcon(Nim_ADD, @Tray);
-
   //states initialization
   TuxUtils.initKnowedVars();
   //Starting status pooling.
   EmbeddedWB1.Go(url);
-
 end;
 
 
 //Avoiding close action.
 procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
 begin
+  Form1.ShowBalloonTips('TuxBox 2.0 is now hidden in the tray icon' + 
slinebreak +
+                        'To open it again, please double-click the tray 
icon.');
   CanClose := False;
   Form1.Hide;
 end;
@@ -195,8 +248,8 @@
 begin
   if TuxUtils.stopServer() then
     begin
-      Shell_NotifyIcon(Nim_DELETE,@tray);
       AppIcon.Free;
+      Form1.DeleteSysTrayIcon;
       EmbeddedWB1.Free;
       Application.Terminate;
     end
@@ -268,8 +321,30 @@
     GetCursorPos(Cursor);
     PopupMenu1.Popup(Cursor.X, Cursor.Y);
     PostMessage(Handle, WM_NULL, 0, 0);
-  end;
+  end
 
+
+  else if msg.LParam = NIN_BALLOONSHOW then
+    begin
+       //Sent when the balloon is shown
+    end
+
+  else if msg.LParam = NIN_BALLOONHIDE then
+    begin
+      //Sent when the balloon disappears
+    end
+
+  else if msg.LParam = NIN_BALLOONTIMEOUT then
+    begin
+      //Sent when the balloon is dismissed because of a timeout.
+
+    end
+
+  else if msg.LParam = NIN_BALLOONUSERCLICK then
+    begin
+      //Sent when the balloon is dismissed because the user clicked the mouse.
+    end
+
 end;
 
 
@@ -338,9 +413,12 @@
   if connection and sound and ( not activity ) and ( ( TuxUtils.knowed_mute
      and ( not TuxUtils.knowed_activity )) <> ( sound and (not activity) )) 
then
     begin
+      if balloonShowed then
+        Form1.HideBalloonTips();
+
       ImageList1.GetIcon(0, AppIcon);
-      Tray.hIcon := AppIcon.Handle;
-      Shell_NotifyIcon(Nim_Modify, @tray);
+      IconData.hIcon := AppIcon.Handle;
+      Shell_NotifyIcon(Nim_Modify, @IconData);
     end
 
   //Changing tray icon 'mute' only if last registered values <> new sound and
@@ -349,26 +427,35 @@
           ( ( ( not sound ) and ( not activity ) ) <> ( ( not 
TuxUtils.knowed_mute )
           and ( not TuxUtils.knowed_activity ) ) )then
     begin
+      if balloonShowed then
+        Form1.HideBalloonTips();
+
       ImageList1.GetIcon(4, AppIcon);
-      Tray.hIcon := AppIcon.Handle;
-      Shell_NotifyIcon(Nim_Modify, @tray);
+      IconData.hIcon := AppIcon.Handle;
+      Shell_NotifyIcon(Nim_Modify, @IconData);
     end
 
   else if connection and activity and sound and ( ( sound and activity ) <>
          ( TuxUtils.knowed_mute and TuxUtils.knowed_activity ) ) then
     begin
+      if balloonShowed then
+        Form1.HideBalloonTips();
+
       ImageList1.GetIcon(3, AppIcon);
-      Tray.hIcon := AppIcon.Handle;
-      Shell_NotifyIcon(Nim_Modify, @tray);
+      IconData.hIcon := AppIcon.Handle;
+      Shell_NotifyIcon(Nim_Modify, @IconData);
     end
 
   //Changing icon only if last state <> new state.
   else if connection <> ( TuxUtils.knowed_server and TuxUtils.knowed_radio and 
TuxUtils.knowed_dongle)
           or ( not started ) then
     begin
+      if balloonShowed then
+        Form1.HideBalloonTips();
+
       ImageList1.GetIcon(1, AppIcon);
-      Tray.hIcon := AppIcon.Handle;
-      Shell_NotifyIcon(Nim_Modify, @tray);
+      IconData.hIcon := AppIcon.Handle;
+      Shell_NotifyIcon(Nim_Modify, @IconData);
     end;
 
   if sound then
@@ -376,7 +463,7 @@
     Mute1.ImageIndex := -1
   else
     //Updating tick from popup menu ( sound off ).
-    Mute1.ImageIndex := 5;
+    Mute1.ImageIndex := 5; 
 
   //Registering new values.
   TuxUtils.knowed_mute := sound;
@@ -389,8 +476,66 @@
     started := true;
 
   Application.ProcessMessages;
-  
+
 end;
 
+
+{AddSysTrayIcon procedure add an icon to notification area}
+procedure TForm1.AddSysTrayIcon();
+begin
+  balloonShowed := false;
+  IconData.cbSize := SizeOf(IconData);
+  IconData.Wnd := AllocateHWnd(WMAppelMessage);
+  {SysTrayIconMsgHandler is then callback message' handler}
+  IconData.uID := 0;
+  IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
+  IconData.uCallbackMessage := TRAY_CALLBACK;
+  IconData.hIcon := Application.Icon.Handle;    //an Icon's Handle
+  IconData.szTip := 'TuxBox 2.0 Show / Hide';
+  if not Shell_NotifyIcon(NIM_ADD, @IconData) then
+    Application.Terminate;
+end;
+
+
+{ShowBalloonTips procedure carry out the new feature: Balloon Tips}
+procedure TForm1.ShowBalloonTips(mess : string);
+var
+  TipInfo, TipTitle: string;
+begin
+  balloonShowed := true;
+  IconData.cbSize := SizeOf(IconData);
+  IconData.uFlags := NIF_INFO;
+  TipInfo := mess;
+  strPLCopy(IconData.szInfo, TipInfo, SizeOf(IconData.szInfo) - 1);
+  IconData.DUMMYUNIONNAME.uTimeout := 2000;
+  TipTitle := 'TuxBox 2.0 Warning';
+  strPLCopy(IconData.szInfoTitle, TipTitle, SizeOf(IconData.szInfoTitle) - 1);
+  IconData.dwInfoFlags := NIIF_INFO;     //NIIF_ERROR;  //NIIF_WARNING;
+  Shell_NotifyIcon(NIM_MODIFY, @IconData);
+  {in my testing, the following code has no use}
+  IconData.DUMMYUNIONNAME.uVersion := NOTIFYICON_VERSION;
+  Shell_NotifyIcon(NIM_SETVERSION, @IconData);
+end;
+
+
+{Hide the balloon}
+Procedure TForm1.HideBalloonTips();
+begin
+  balloonShowed := false;
+  IconData.cbSize := SizeOf(IconData);
+  IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
+  IconData.szTip := 'TuxBox 2.0 Show / Hide';
+  Shell_NotifyIcon(NIM_MODIFY, @IconData)
+end;
+
+
+{here's the deletion procedure}
+procedure TForm1.DeleteSysTrayIcon;
+begin
+  DeallocateHWnd(IconData.Wnd);
+  if not Shell_NotifyIcon(NIM_DELETE, @IconData) then
+    ShowMessage('Tray icon deletion failed');
+end;
+
 end.
 


------------------------------------------------------------------------------
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to