From 0c5c85ec572b45836a249d1fd10f887e78c90905 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Sat, 16 Feb 2008 07:35:34 +0000 Subject: [PATCH] Fixes changing the hint at run-time. git-svn-id: trunk@14156 - --- lcl/extctrls.pp | 7 ++-- lcl/include/customtrayicon.inc | 19 +++++++---- lcl/interfaces/win32/win32trayicon.inc | 46 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/lcl/extctrls.pp b/lcl/extctrls.pp index 49c4a99217..c3acea8221 100644 --- a/lcl/extctrls.pp +++ b/lcl/extctrls.pp @@ -1102,7 +1102,8 @@ type FOnPaint, FOnClick, FOnDblClick: TNotifyEvent; FOnMouseDown, FOnMouseUp: TMouseEvent; FOnMouseMove: TMouseMoveEvent; - function GetCanvas: TCanvas; + function GetCanvas: TCanvas; + procedure SetHint(const AValue: string); procedure SetVisible(Value: Boolean); procedure HandleNotifierClose(Sender: TObject; var CloseAction: TCloseAction); procedure HandleNotifierTimeout(Sender: TObject); @@ -1122,8 +1123,8 @@ type property BalloonTitle: string read FBalloonTitle write FBalloonTitle; property Canvas: TCanvas read GetCanvas; property PopUpMenu: TPopupMenu read FPopUpMenu write FPopUpMenu; - property Icon: TIcon read FIcon write FIcon; - property Hint: string read FHint write FHint; + property Icon: TIcon read FIcon; + property Hint: string read FHint write SetHint; property ShowIcon: Boolean read FShowIcon write FShowIcon default True; property Visible: Boolean read FVisible write SetVisible; { Events } diff --git a/lcl/include/customtrayicon.inc b/lcl/include/customtrayicon.inc index 12e16ce8a2..f6158f6e52 100644 --- a/lcl/include/customtrayicon.inc +++ b/lcl/include/customtrayicon.inc @@ -90,8 +90,6 @@ begin FVisible := False; -// InternalUpdate; - Result := TWSCustomTrayIconClass(WidgetSetClass).Hide(Self); end; @@ -111,8 +109,6 @@ begin FVisible := True; - InternalUpdate; - Result := TWSCustomTrayIconClass(WidgetSetClass).Show(Self); end; @@ -160,9 +156,13 @@ end; * DESCRIPTION: Makes modifications to the Icon while running * i.e. without hiding it and showing again * -* PARAMETERS: None +* Currently only the following parameters use this: * -* RETURNS: Nothing +* - Hint +* +* For event parameters (PopUpMenu, OnMouseMove, etc) +* this isn't necessary because they are handled +* througth callbacks that can always call the last value. * *******************************************************************} procedure TCustomTrayIcon.InternalUpdate; @@ -232,4 +232,11 @@ begin Result := TWSCustomTrayIconClass(WidgetSetClass).GetCanvas(Self); end; +procedure TCustomTrayIcon.SetHint(const AValue: string); +begin + FHint := AValue; + + if FVisible then InternalUpdate; +end; + // included by extctrls.pp diff --git a/lcl/interfaces/win32/win32trayicon.inc b/lcl/interfaces/win32/win32trayicon.inc index b663928aa8..0cc604bbb8 100644 --- a/lcl/interfaces/win32/win32trayicon.inc +++ b/lcl/interfaces/win32/win32trayicon.inc @@ -238,8 +238,54 @@ end; * *******************************************************************} class procedure TWin32WSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTrayIcon); +var + tnida: TNotifyIconDataA; + tnidw: TNotifyIconDataW; + AnsiBuffer: ansistring; + WideBuffer: widestring; begin + {$ifdef WindowsUnicodeSupport} + if UnicodeEnabledOS then + begin + // Fill TNotifyIconDataW + FillChar(tnidw, SizeOf(tnidw), 0); + tnidw.cbSize := SizeOf(TNotifyIconDataW); + tnidw.hWnd := ATrayIcon.Handle; + tnidw.uID := uIDTrayIcon; + tnidw.uFlags := NIF_TIP; + WideBuffer := UTF8Decode(ATrayIcon.Hint); + WideStrLCopy(@tnidw.szTip, PWideChar(WideBuffer), 127); + + Shell_NotifyIconW(NIM_MODIFY, @tnidw) + end + else + begin + // Fill TNotifyIconDataA + FillChar(tnida, SizeOf(tnida), 0); + tnida.cbSize := SizeOf(TNotifyIconDataA); + tnida.hWnd := ATrayIcon.Handle; + tnida.uID := uIDTrayIcon; + tnida.uFlags := NIF_TIP; + + AnsiBuffer := UTF8ToAnsi(ATrayIcon.Hint); + StrLCopy(@tnida.szTip, PChar(AnsiBuffer), 127); + + Shell_NotifyIconA(NIM_MODIFY, @tnida); + end; + {$else} + // Fill TNotifyIconDataA + FillChar(tnida, SizeOf(tnida), 0); + tnida.cbSize := SizeOf(TNotifyIconDataA); + tnida.hWnd := ATrayIcon.Handle; + tnida.uID := uIDTrayIcon; + tnida.uFlags := NIF_TIP; + + StrLCopy(@tnida.szTip, PChar(ATrayIcon.Hint), 127); + + // Create Taskbar icon + Shell_NotifyIconA(NIM_MODIFY, @tnida); + {$endif} end; {*******************************************************************