mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-03 23:40:22 +02:00
Fixes showing the popup menu on gtk1 trayicon (bug #10700)
git-svn-id: trunk@14037 -
This commit is contained in:
parent
952291e8bc
commit
7d16c56822
@ -28,12 +28,6 @@ type
|
|||||||
|
|
||||||
TGtk1TrayIconHandle = class(TObject)
|
TGtk1TrayIconHandle = class(TObject)
|
||||||
private
|
private
|
||||||
function GetCanvas: TCanvas;
|
|
||||||
function NotifyExpose(Event: PGdkEventExpose; Widget: PGtkWidget): Boolean; cdecl;
|
|
||||||
function NotifyMouseMove(Event: PGdkEventMotion; Widget: PGtkWidget): Boolean; cdecl;
|
|
||||||
function NotifyMouseDown(Event: PGdkEventButton; Widget: PGtkWidget): Boolean; cdecl;
|
|
||||||
function NotifyMouseUp(Event: PGdkEventButton; Widget: PGtkWidget): Boolean; cdecl;
|
|
||||||
public
|
|
||||||
plug: PGtkWidget;
|
plug: PGtkWidget;
|
||||||
drawingarea: PGtkWidget;
|
drawingarea: PGtkWidget;
|
||||||
fDisplay: PDisplay;
|
fDisplay: PDisplay;
|
||||||
@ -45,14 +39,22 @@ type
|
|||||||
fEmbedded: Boolean;
|
fEmbedded: Boolean;
|
||||||
fMsgCount: Integer;
|
fMsgCount: Integer;
|
||||||
fTrayIcon: TCustomTrayIcon;
|
fTrayIcon: TCustomTrayIcon;
|
||||||
function Send_Message(window: TWindow; msg: Integer;data1, data2,data3: Integer): boolean;
|
function GetCanvas: TCanvas;
|
||||||
function TrayParent(UseCachedValue: Boolean = True): TWindow;
|
function NotifyExpose(Event: PGdkEventExpose; Widget: PGtkWidget): Boolean; cdecl;
|
||||||
destructor Destroy; override;
|
function NotifyMouseMove(Event: PGdkEventMotion; Widget: PGtkWidget): Boolean; cdecl;
|
||||||
procedure SetEmbedded;
|
function NotifyMouseDown(Event: PGdkEventButton; Widget: PGtkWidget): Boolean; cdecl;
|
||||||
procedure Hide;
|
function NotifyMouseUp(Event: PGdkEventButton; Widget: PGtkWidget): Boolean; cdecl;
|
||||||
procedure CreateForm(id: Integer);
|
|
||||||
procedure SetMinSize(AWidth, AHeight: Integer);
|
|
||||||
procedure PaintForm(Sender: TObject);
|
procedure PaintForm(Sender: TObject);
|
||||||
|
function Send_Message(window: TWindow; msg: Integer;data1, data2,data3: Integer): boolean;
|
||||||
|
public
|
||||||
|
destructor Destroy; override;
|
||||||
|
procedure CreateForm(id: Integer);
|
||||||
|
function GetPosition: TPoint;
|
||||||
|
procedure Hide;
|
||||||
|
procedure SetEmbedded;
|
||||||
|
procedure SetMinSize(AWidth, AHeight: Integer);
|
||||||
|
function TrayParent(UseCachedValue: Boolean = True): TWindow;
|
||||||
|
public
|
||||||
property Canvas: TCanvas read GetCanvas;
|
property Canvas: TCanvas read GetCanvas;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -70,8 +72,8 @@ end;
|
|||||||
|
|
||||||
function TGtk1TrayIconHandle.GetCanvas: TCanvas;
|
function TGtk1TrayIconHandle.GetCanvas: TCanvas;
|
||||||
begin
|
begin
|
||||||
if Assigned(FCanvas) then
|
if Assigned(FCanvas) then Exit(FCanvas);
|
||||||
Exit(FCanvas);
|
|
||||||
Result := TCanvas.Create;
|
Result := TCanvas.Create;
|
||||||
Result.Handle:= GetDC(HWND(drawingarea));
|
Result.Handle:= GetDC(HWND(drawingarea));
|
||||||
FCanvas := Result;
|
FCanvas := Result;
|
||||||
@ -80,14 +82,16 @@ end;
|
|||||||
function TGtk1TrayIconHandle.NotifyExpose(Event: PGdkEventExpose;
|
function TGtk1TrayIconHandle.NotifyExpose(Event: PGdkEventExpose;
|
||||||
Widget: PGtkWidget): Boolean; cdecl;
|
Widget: PGtkWidget): Boolean; cdecl;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result := False;
|
||||||
|
|
||||||
PaintForm(fTrayIcon);
|
PaintForm(fTrayIcon);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TGtk1TrayIconHandle.NotifyMouseMove(Event: PGdkEventMotion;
|
function TGtk1TrayIconHandle.NotifyMouseMove(Event: PGdkEventMotion;
|
||||||
Widget: PGtkWidget): Boolean; cdecl;
|
Widget: PGtkWidget): Boolean; cdecl;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result := False;
|
||||||
|
|
||||||
if Assigned(fTrayIcon.OnMouseMove) then
|
if Assigned(fTrayIcon.OnMouseMove) then
|
||||||
fTrayIcon.OnMouseMove(fTrayIcon, [], Trunc(Event^.x), Trunc(Event^.y));
|
fTrayIcon.OnMouseMove(fTrayIcon, [], Trunc(Event^.x), Trunc(Event^.y));
|
||||||
end;
|
end;
|
||||||
@ -97,7 +101,8 @@ function TGtk1TrayIconHandle.NotifyMouseDown(Event: PGdkEventButton;
|
|||||||
var
|
var
|
||||||
Button: TMouseButton;
|
Button: TMouseButton;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result := False;
|
||||||
|
|
||||||
case Event^.button of
|
case Event^.button of
|
||||||
GDK_RIGHTBUTTON: Button := mbRight;
|
GDK_RIGHTBUTTON: Button := mbRight;
|
||||||
GDK_MIDDLEBUTTON: Button := mbMiddle;
|
GDK_MIDDLEBUTTON: Button := mbMiddle;
|
||||||
@ -113,7 +118,8 @@ function TGtk1TrayIconHandle.NotifyMouseUp(Event: PGdkEventButton;
|
|||||||
var
|
var
|
||||||
Button: TMouseButton;
|
Button: TMouseButton;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result := False;
|
||||||
|
|
||||||
case Event^.button of
|
case Event^.button of
|
||||||
3: Button := mbRight;
|
3: Button := mbRight;
|
||||||
2: Button := mbMiddle;
|
2: Button := mbMiddle;
|
||||||
@ -130,13 +136,15 @@ begin
|
|||||||
fTrayIcon.OnDblClick(fTrayIcon);
|
fTrayIcon.OnDblClick(fTrayIcon);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ Just using GetPosition to get the screen position and then add
|
||||||
|
Event^.x and Event^.y to it won't work. It seams that this will
|
||||||
|
cause a small difference with Mouse.CursorPos, and using
|
||||||
|
TPopupMenu.PopUp will result in a wrong position for the menu }
|
||||||
if (Button = mbRight) and (fTrayIcon.PopUpMenu <> nil) then
|
if (Button = mbRight) and (fTrayIcon.PopUpMenu <> nil) then
|
||||||
fTrayIcon.PopUpMenu.PopUp(-1,-1);
|
fTrayIcon.PopUpMenu.PopUp(Mouse.CursorPos.X, Mouse.CursorPos.Y);
|
||||||
|
|
||||||
if Assigned(fTrayIcon.OnMouseUp) then
|
if Assigned(fTrayIcon.OnMouseUp) then
|
||||||
fTrayIcon.OnMouseUp(fTrayIcon, Button, [], Trunc(Event^.x), Trunc(Event^.y));
|
fTrayIcon.OnMouseUp(fTrayIcon, Button, [], Trunc(Event^.x), Trunc(Event^.y));
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{*******************************************************************
|
{*******************************************************************
|
||||||
@ -144,10 +152,6 @@ end;
|
|||||||
*
|
*
|
||||||
* DESCRIPTION: Sends a message to the X client
|
* DESCRIPTION: Sends a message to the X client
|
||||||
*
|
*
|
||||||
* PARAMETERS: None
|
|
||||||
*
|
|
||||||
* RETURNS: Nothing
|
|
||||||
*
|
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
function TGtk1TrayIconHandle.Send_Message(window: TWindow; msg: Integer;data1, data2,data3: Integer): boolean;
|
function TGtk1TrayIconHandle.Send_Message(window: TWindow; msg: Integer;data1, data2,data3: Integer): boolean;
|
||||||
var
|
var
|
||||||
@ -215,10 +219,6 @@ end;
|
|||||||
*
|
*
|
||||||
* DESCRIPTION:
|
* DESCRIPTION:
|
||||||
*
|
*
|
||||||
* PARAMETERS: None
|
|
||||||
*
|
|
||||||
* RETURNS: Nothing
|
|
||||||
*
|
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
procedure TGtk1TrayIconHandle.SetEmbedded;
|
procedure TGtk1TrayIconHandle.SetEmbedded;
|
||||||
var
|
var
|
||||||
@ -264,10 +264,6 @@ end;
|
|||||||
*
|
*
|
||||||
* DESCRIPTION:
|
* DESCRIPTION:
|
||||||
*
|
*
|
||||||
* PARAMETERS: None
|
|
||||||
*
|
|
||||||
* RETURNS: Nothing
|
|
||||||
*
|
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
procedure TGtk1TrayIconHandle.CreateForm(id: Integer);
|
procedure TGtk1TrayIconHandle.CreateForm(id: Integer);
|
||||||
begin
|
begin
|
||||||
@ -288,15 +284,32 @@ begin
|
|||||||
GetCanvas;
|
GetCanvas;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{*******************************************************************
|
||||||
|
* TGtk1TrayIconHandle.GetPosition ()
|
||||||
|
*
|
||||||
|
* DESCRIPTION: Returns the (x, y) position of the icon on the screen
|
||||||
|
*
|
||||||
|
*******************************************************************}
|
||||||
|
function TGtk1TrayIconHandle.GetPosition: TPoint;
|
||||||
|
var
|
||||||
|
WindowHandle: PGDKWindow;
|
||||||
|
begin
|
||||||
|
Result := Point(0, 0);
|
||||||
|
|
||||||
|
if not Assigned(plug) then Exit;
|
||||||
|
|
||||||
|
WindowHandle := plug^.window;
|
||||||
|
|
||||||
|
if not Assigned(WindowHandle) then Exit;
|
||||||
|
|
||||||
|
gdk_window_get_origin(WindowHandle, @Result.X, @Result.Y);
|
||||||
|
end;
|
||||||
|
|
||||||
{*******************************************************************
|
{*******************************************************************
|
||||||
* TGtk1TrayIconHandle.SetMinSize ()
|
* TGtk1TrayIconHandle.SetMinSize ()
|
||||||
*
|
*
|
||||||
* DESCRIPTION: Attemps to avoid problems on Gnome
|
* DESCRIPTION: Attemps to avoid problems on Gnome
|
||||||
*
|
*
|
||||||
* PARAMETERS:
|
|
||||||
*
|
|
||||||
* RETURNS: Nothing
|
|
||||||
*
|
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
procedure TGtk1TrayIconHandle.SetMinSize(AWidth, AHeight: Integer);
|
procedure TGtk1TrayIconHandle.SetMinSize(AWidth, AHeight: Integer);
|
||||||
begin
|
begin
|
||||||
@ -308,10 +321,6 @@ end;
|
|||||||
*
|
*
|
||||||
* DESCRIPTION: Paint method of the Icon Window
|
* DESCRIPTION: Paint method of the Icon Window
|
||||||
*
|
*
|
||||||
* PARAMETERS: Sender of the event
|
|
||||||
*
|
|
||||||
* RETURNS: Nothing
|
|
||||||
*
|
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
procedure TGtk1TrayIconHandle.PaintForm(Sender: TObject);
|
procedure TGtk1TrayIconHandle.PaintForm(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
@ -378,10 +387,6 @@ end;
|
|||||||
* DESCRIPTION: Makes modifications to the Icon while running
|
* DESCRIPTION: Makes modifications to the Icon while running
|
||||||
* i.e. without hiding it and showing again
|
* i.e. without hiding it and showing again
|
||||||
*
|
*
|
||||||
* PARAMETERS: None
|
|
||||||
*
|
|
||||||
* RETURNS: Nothing
|
|
||||||
*
|
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
class procedure TGtkWSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTrayIcon);
|
class procedure TGtkWSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTrayIcon);
|
||||||
var
|
var
|
||||||
@ -390,9 +395,6 @@ begin
|
|||||||
TrayIconHandle := TGtk1TrayIconHandle(ATrayIcon.Handle);
|
TrayIconHandle := TGtk1TrayIconHandle(ATrayIcon.Handle);
|
||||||
|
|
||||||
if not Assigned(TrayIconHandle) then Exit;
|
if not Assigned(TrayIconHandle) then Exit;
|
||||||
|
|
||||||
//if Assigned(TrayIconHandle.GtkForm) then
|
|
||||||
// TrayIconHandle.GtkForm.PopupMenu := ATrayIcon.PopUpMenu;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{*******************************************************************
|
{*******************************************************************
|
||||||
@ -402,19 +404,21 @@ end;
|
|||||||
* This function is utilized to show message boxes near
|
* This function is utilized to show message boxes near
|
||||||
* the icon
|
* the icon
|
||||||
*
|
*
|
||||||
* PARAMETERS: None
|
|
||||||
*
|
|
||||||
* RETURNS: Nothing
|
|
||||||
*
|
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
class function TGtkWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint;
|
class function TGtkWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint;
|
||||||
|
var
|
||||||
|
TrayIconHandle: TGtk1TrayIconHandle;
|
||||||
begin
|
begin
|
||||||
Result.X := 0;
|
Result := Point(0, 0);
|
||||||
Result.Y := 0;
|
|
||||||
|
TrayIconHandle := TGtk1TrayIconHandle(ATrayIcon.Handle);
|
||||||
|
|
||||||
|
if not Assigned(TrayIconHandle) then Exit;
|
||||||
|
|
||||||
|
Result := TrayIconHandle.GetPosition;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TGtkWSCustomTrayIcon.GetCanvas(const ATrayIcon: TCustomTrayIcon
|
class function TGtkWSCustomTrayIcon.GetCanvas(const ATrayIcon: TCustomTrayIcon): TCanvas;
|
||||||
): TCanvas;
|
|
||||||
var
|
var
|
||||||
TrayIconHandle: TGtk1TrayIconHandle;
|
TrayIconHandle: TGtk1TrayIconHandle;
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user