Patch from Yury Sidorov. Adds native ballonhint to trayicon in win32/64

git-svn-id: trunk@18239 -
This commit is contained in:
sekelsenmat 2009-01-10 18:12:28 +00:00
parent 9d4efb4e83
commit 8d7d304d4c
6 changed files with 73 additions and 26 deletions

View File

@ -1,4 +1,4 @@
#The following people contributed to Lazarus:
#The following people contributed to Lazarus:
A. J. Venter
Aleksey Lagunov
@ -133,6 +133,7 @@ Vincent Snijders
Wanderlan Santos dos Anjos
Wojciech Malinowski
Yuriy Yeroshkin
Yury Sidorov
Zaenal Mutaqin
Zaher Dirkey
Zeljan Rikalo

View File

@ -202,7 +202,7 @@ var
UsePopUpNotifier: Boolean;
Pt: TPoint;
begin
UsePopUpNotifier := TWSCustomTrayIconClass(WidgetSetClass).ShowBalloonHint(Self);
UsePopUpNotifier := not TWSCustomTrayIconClass(WidgetSetClass).ShowBalloonHint(Self);
if UsePopUpNotifier then
begin

View File

@ -273,7 +273,7 @@ end;
class function TCarbonWSCustomTrayIcon.ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean;
begin
Result := True;
Result := False;
end;
class function TCarbonWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint;

View File

@ -94,7 +94,7 @@ end;
class function TCocoaWSCustomTrayIcon.ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean;
begin
Result := True;
Result := False;
end;
class function TCocoaWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint;

View File

@ -19,6 +19,28 @@
{ TWin32WSCustomTrayIcon }
type
// IE 5+ version of TNotifyIconDataW
TNotifyIconDataW2 = record
cbSize: DWORD;
hWnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array [0..127] of WideChar;
dwState: DWORD;
dwStateMask: DWORD;
szInfo: array [0..255] of WideChar;
u: record
case longint of
0 : ( uTimeout : UINT );
1 : ( uVersion : UINT );
end;
szInfoTitle: array[0..63] of WideChar;
dwInfoFlags: DWORD;
end;
const
szClassName = 'TTrayIconClass';
szAppTitle = 'apptitle';
@ -141,7 +163,7 @@ class function TWin32WSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Bo
var
tnida: TNotifyIconDataA;
{$ifdef WindowsUnicodeSupport}
tnidw: TNotifyIconDataW;
tnidw: TNotifyIconDataW2;
AnsiBuffer: ansistring;
WideBuffer: widestring;
{$endif}
@ -184,7 +206,7 @@ begin
begin
// Fill TNotifyIconDataW
FillChar(tnidw, SizeOf(tnidw), 0);
tnidw.cbSize := SizeOf(TNotifyIconDataW);
tnidw.cbSize := SizeOf(tnidw);
tnidw.hWnd := ATrayIcon.Handle;
tnidw.uID := uIDTrayIcon;
tnidw.uFlags := NIF_MESSAGE or NIF_ICON;
@ -195,7 +217,14 @@ begin
WideBuffer := UTF8Decode(ATrayIcon.Hint);
WideStrLCopy(@tnidw.szTip, PWideChar(WideBuffer), 127);
Result := Shell_NotifyIconW(NIM_ADD, @tnidw)
Result := Shell_NotifyIconW(NIM_ADD, @tnidw);
if not Result then
begin
// Try old version of TNotifyIconDataW
tnidw.cbSize := SizeOf(TNotifyIconDataW);
WideStrLCopy(@tnidw.szTip, PWideChar(WideBuffer), 63);
Result := Shell_NotifyIconW(NIM_MODIFY, @tnidw);
end;
end
else
begin
@ -243,7 +272,7 @@ class procedure TWin32WSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTr
var
tnida: TNotifyIconDataA;
{$ifdef WindowsUnicodeSupport}
tnidw: TNotifyIconDataW;
tnidw: TNotifyIconDataW2;
AnsiBuffer: ansistring;
WideBuffer: widestring;
{$endif}
@ -253,7 +282,7 @@ begin
begin
// Fill TNotifyIconDataW
FillChar(tnidw, SizeOf(tnidw), 0);
tnidw.cbSize := SizeOf(TNotifyIconDataW);
tnidw.cbSize := SizeOf(tnidw);
tnidw.hWnd := ATrayIcon.Handle;
tnidw.uID := uIDTrayIcon;
tnidw.hIcon := ATrayIcon.Icon.Handle;
@ -262,7 +291,13 @@ begin
WideBuffer := UTF8Decode(ATrayIcon.Hint);
WideStrLCopy(@tnidw.szTip, PWideChar(WideBuffer), 127);
Shell_NotifyIconW(NIM_MODIFY, @tnidw)
if not Shell_NotifyIconW(NIM_MODIFY, @tnidw) then
begin
// Try old version of TNotifyIconDataW
tnidw.cbSize := SizeOf(TNotifyIconDataW);
WideStrLCopy(@tnidw.szTip, PWideChar(WideBuffer), 63);
Shell_NotifyIconW(NIM_MODIFY, @tnidw);
end;
end
else
begin
@ -299,23 +334,32 @@ end;
*
* DESCRIPTION: Shows a small message balloon near the tray icon
*
* RETURNS: False if the default cross-platform hint should be used
* True if a platform-specific hint will be used
*
*******************************************************************}
class function TWin32WSCustomTrayIcon.ShowBalloonHint(
const ATrayIcon: TCustomTrayIcon): Boolean;
{var
NotifyData: TNotifyIconDataEx:}
class function TWin32WSCustomTrayIcon.ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean;
const
FlagsMap: array[TBalloonFlags] of dword = (NIIF_NONE, NIIF_INFO, NIIF_WARNING, NIIF_ERROR);
var
NotifyData: TNotifyIconDataW2;
w: WideString;
begin
Result := True;
{ NotifyData.szInfo : array[0..255] of CHAR;
DUMMYUNIONNAME : record
case longint of
0 : ( uTimeout : UINT );
1 : ( uVersion : UINT );
end;
szInfoTitle : array[0..63] of CHAR;
dwInfoFlags : DWORD;
Result := UnicodeEnabledOS;
if not Result then exit;
Shell_NotifyIconA():}
NotifyData.cbSize:=SizeOf(NotifyData);
NotifyData.hWnd := ATrayIcon.Handle;
NotifyData.uID := uIDTrayIcon;
NotifyData.uFlags:=NIF_INFO;
NotifyData.u.uTimeout:=ATrayIcon.BalloonTimeout;
w:=UTF8Decode(ATrayIcon.BalloonHint);
WideStrLCopy(@NotifyData.szInfo, PWideChar(w), High(NotifyData.szInfo));
w:=UTF8Decode(ATrayIcon.BalloonTitle);
WideStrLCopy(@NotifyData.szInfoTitle, PWideChar(w), High(NotifyData.szInfoTitle));
NotifyData.dwInfoFlags:=FlagsMap[ATrayIcon.BalloonFlags];
Result:= Shell_NotifyIconW(NIM_MODIFY, @NotifyData);
end;
{*******************************************************************
@ -375,3 +419,4 @@ begin
Result.Y := TaskbarRect.Top;
end;

View File

@ -337,12 +337,13 @@ end;
{*******************************************************************
* TWSCustomTrayIcon.ShowBalloonHint ()
*
* RETURNS: If we should use the popupnotifier to implement this method
* RETURNS: False if we should use the popupnotifier to implement this method
* True if a platform-specific baloon is implemented
*
*******************************************************************}
class function TWSCustomTrayIcon.ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean;
begin
Result := True;
Result := False;
end;
class function TWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint;