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 A. J. Venter
Aleksey Lagunov Aleksey Lagunov
@ -133,6 +133,7 @@ Vincent Snijders
Wanderlan Santos dos Anjos Wanderlan Santos dos Anjos
Wojciech Malinowski Wojciech Malinowski
Yuriy Yeroshkin Yuriy Yeroshkin
Yury Sidorov
Zaenal Mutaqin Zaenal Mutaqin
Zaher Dirkey Zaher Dirkey
Zeljan Rikalo Zeljan Rikalo

View File

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

View File

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

View File

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

View File

@ -19,6 +19,28 @@
{ TWin32WSCustomTrayIcon } { 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 const
szClassName = 'TTrayIconClass'; szClassName = 'TTrayIconClass';
szAppTitle = 'apptitle'; szAppTitle = 'apptitle';
@ -141,7 +163,7 @@ class function TWin32WSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Bo
var var
tnida: TNotifyIconDataA; tnida: TNotifyIconDataA;
{$ifdef WindowsUnicodeSupport} {$ifdef WindowsUnicodeSupport}
tnidw: TNotifyIconDataW; tnidw: TNotifyIconDataW2;
AnsiBuffer: ansistring; AnsiBuffer: ansistring;
WideBuffer: widestring; WideBuffer: widestring;
{$endif} {$endif}
@ -184,7 +206,7 @@ begin
begin begin
// Fill TNotifyIconDataW // Fill TNotifyIconDataW
FillChar(tnidw, SizeOf(tnidw), 0); FillChar(tnidw, SizeOf(tnidw), 0);
tnidw.cbSize := SizeOf(TNotifyIconDataW); tnidw.cbSize := SizeOf(tnidw);
tnidw.hWnd := ATrayIcon.Handle; tnidw.hWnd := ATrayIcon.Handle;
tnidw.uID := uIDTrayIcon; tnidw.uID := uIDTrayIcon;
tnidw.uFlags := NIF_MESSAGE or NIF_ICON; tnidw.uFlags := NIF_MESSAGE or NIF_ICON;
@ -195,7 +217,14 @@ begin
WideBuffer := UTF8Decode(ATrayIcon.Hint); WideBuffer := UTF8Decode(ATrayIcon.Hint);
WideStrLCopy(@tnidw.szTip, PWideChar(WideBuffer), 127); 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 end
else else
begin begin
@ -243,7 +272,7 @@ class procedure TWin32WSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTr
var var
tnida: TNotifyIconDataA; tnida: TNotifyIconDataA;
{$ifdef WindowsUnicodeSupport} {$ifdef WindowsUnicodeSupport}
tnidw: TNotifyIconDataW; tnidw: TNotifyIconDataW2;
AnsiBuffer: ansistring; AnsiBuffer: ansistring;
WideBuffer: widestring; WideBuffer: widestring;
{$endif} {$endif}
@ -253,7 +282,7 @@ begin
begin begin
// Fill TNotifyIconDataW // Fill TNotifyIconDataW
FillChar(tnidw, SizeOf(tnidw), 0); FillChar(tnidw, SizeOf(tnidw), 0);
tnidw.cbSize := SizeOf(TNotifyIconDataW); tnidw.cbSize := SizeOf(tnidw);
tnidw.hWnd := ATrayIcon.Handle; tnidw.hWnd := ATrayIcon.Handle;
tnidw.uID := uIDTrayIcon; tnidw.uID := uIDTrayIcon;
tnidw.hIcon := ATrayIcon.Icon.Handle; tnidw.hIcon := ATrayIcon.Icon.Handle;
@ -262,7 +291,13 @@ begin
WideBuffer := UTF8Decode(ATrayIcon.Hint); WideBuffer := UTF8Decode(ATrayIcon.Hint);
WideStrLCopy(@tnidw.szTip, PWideChar(WideBuffer), 127); 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 end
else else
begin begin
@ -299,23 +334,32 @@ end;
* *
* DESCRIPTION: Shows a small message balloon near the tray icon * 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( class function TWin32WSCustomTrayIcon.ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean;
const ATrayIcon: TCustomTrayIcon): Boolean; const
{var FlagsMap: array[TBalloonFlags] of dword = (NIIF_NONE, NIIF_INFO, NIIF_WARNING, NIIF_ERROR);
NotifyData: TNotifyIconDataEx:} var
NotifyData: TNotifyIconDataW2;
w: WideString;
begin begin
Result := True; Result := UnicodeEnabledOS;
{ NotifyData.szInfo : array[0..255] of CHAR; if not Result then exit;
DUMMYUNIONNAME : record
case longint of
0 : ( uTimeout : UINT );
1 : ( uVersion : UINT );
end;
szInfoTitle : array[0..63] of CHAR;
dwInfoFlags : DWORD;
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; end;
{******************************************************************* {*******************************************************************
@ -375,3 +419,4 @@ begin
Result.Y := TaskbarRect.Top; Result.Y := TaskbarRect.Top;
end; end;

View File

@ -337,12 +337,13 @@ end;
{******************************************************************* {*******************************************************************
* TWSCustomTrayIcon.ShowBalloonHint () * 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; class function TWSCustomTrayIcon.ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean;
begin begin
Result := True; Result := False;
end; end;
class function TWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint; class function TWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint;