mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 05:18:00 +02:00
Qt,Qt5: fixed broken TTrayIcon popup menu after recreating popup menu handle. issue #38849
This commit is contained in:
parent
4aaf8d270c
commit
7f0e0cd0bd
@ -21,7 +21,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, types, Controls, ExtCtrls, Graphics, Forms, LCLType, LCLProc, LazUTF8,
|
||||
qtobjects, qt4, qtproc, qtint;
|
||||
qtobjects, qt4, qtint;
|
||||
|
||||
type
|
||||
TSysTrayIconPaintData = record
|
||||
@ -36,11 +36,13 @@ type
|
||||
TQtSystemTrayIcon = class(TQtObject)
|
||||
private
|
||||
FSysTrayHook: QObject_hookH;
|
||||
FDestroyedMenuHook: QObject_hookH;
|
||||
FHook: QSystemTrayIcon_hookH;
|
||||
FSysTrayWidget: QWidgetH;
|
||||
FCanvas: TCanvas;
|
||||
function BeginPaintInternal(var APaintData: TSysTrayIconPaintData): hdc;
|
||||
procedure EndPaintInternal(var APaintData: TSysTrayIconPaintData);
|
||||
procedure DestroyedMenu; cdecl;
|
||||
public
|
||||
FTrayIcon: TCustomTrayIcon;
|
||||
public
|
||||
@ -110,6 +112,11 @@ begin
|
||||
QSystemTrayIcon_hook_destroy(FHook);
|
||||
FHook := nil;
|
||||
end;
|
||||
if Assigned(FDestroyedMenuHook) then
|
||||
begin
|
||||
QObject_hook_Destroy(FDestroyedMenuHook);
|
||||
FDestroyedMenuHook := nil;
|
||||
end;
|
||||
inherited DetachEvents;
|
||||
end;
|
||||
|
||||
@ -169,6 +176,13 @@ begin
|
||||
APaintData.Context := nil;
|
||||
end;
|
||||
|
||||
procedure TQtSystemTrayIcon.DestroyedMenu; cdecl;
|
||||
begin
|
||||
setContextMenu(nil);
|
||||
if not (csDestroying in FTrayIcon.ComponentState) then
|
||||
FTrayIcon.InternalUpdate;
|
||||
end;
|
||||
|
||||
function TQtSystemTrayIcon.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
|
||||
var
|
||||
X, Y: Integer;
|
||||
@ -244,6 +258,16 @@ end;
|
||||
|
||||
procedure TQtSystemTrayIcon.setContextMenu(menu: QMenuH);
|
||||
begin
|
||||
if menu <> nil then
|
||||
begin
|
||||
if Assigned(FDestroyedMenuHook) then
|
||||
begin
|
||||
QObject_hook_destroy(FDestroyedMenuHook);
|
||||
FDestroyedMenuHook := nil;
|
||||
end;
|
||||
FDestroyedMenuHook := QObject_hook_create(menu);
|
||||
QObject_hook_hook_destroyed(FDestroyedMenuHook, @DestroyedMenu);
|
||||
end;
|
||||
QSystemTrayIcon_setContextMenu(QSystemTrayIconH(TheObject), menu);
|
||||
end;
|
||||
|
||||
|
@ -36,11 +36,13 @@ type
|
||||
TQtSystemTrayIcon = class(TQtObject)
|
||||
private
|
||||
FSysTrayHook: QObject_hookH;
|
||||
FDestroyedMenuHook: QObject_hookH;
|
||||
FHook: QSystemTrayIcon_hookH;
|
||||
FSysTrayWidget: QWidgetH;
|
||||
FCanvas: TCanvas;
|
||||
function BeginPaintInternal(var APaintData: TSysTrayIconPaintData): hdc;
|
||||
procedure EndPaintInternal(var APaintData: TSysTrayIconPaintData);
|
||||
procedure DestroyedMenu; cdecl;
|
||||
public
|
||||
FTrayIcon: TCustomTrayIcon;
|
||||
public
|
||||
@ -110,6 +112,11 @@ begin
|
||||
QSystemTrayIcon_hook_destroy(FHook);
|
||||
FHook := nil;
|
||||
end;
|
||||
if Assigned(FDestroyedMenuHook) then
|
||||
begin
|
||||
QObject_hook_Destroy(FDestroyedMenuHook);
|
||||
FDestroyedMenuHook := nil;
|
||||
end;
|
||||
inherited DetachEvents;
|
||||
end;
|
||||
|
||||
@ -168,6 +175,13 @@ begin
|
||||
APaintData.Context := nil;
|
||||
end;
|
||||
|
||||
procedure TQtSystemTrayIcon.DestroyedMenu; cdecl;
|
||||
begin
|
||||
setContextMenu(nil);
|
||||
if not (csDestroying in FTrayIcon.ComponentState) then
|
||||
FTrayIcon.InternalUpdate;
|
||||
end;
|
||||
|
||||
function TQtSystemTrayIcon.EventFilter(Sender: QObjectH; Event: QEventH
|
||||
): Boolean; cdecl;
|
||||
var
|
||||
@ -246,6 +260,16 @@ end;
|
||||
|
||||
procedure TQtSystemTrayIcon.setContextMenu(menu: QMenuH);
|
||||
begin
|
||||
if menu <> nil then
|
||||
begin
|
||||
if Assigned(FDestroyedMenuHook) then
|
||||
begin
|
||||
QObject_hook_destroy(FDestroyedMenuHook);
|
||||
FDestroyedMenuHook := nil;
|
||||
end;
|
||||
FDestroyedMenuHook := QObject_hook_create(menu);
|
||||
QObject_hook_hook_destroyed(FDestroyedMenuHook, @DestroyedMenu);
|
||||
end;
|
||||
QSystemTrayIcon_setContextMenu(QSystemTrayIconH(TheObject), menu);
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user