mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-30 06:42:49 +02:00
trayicon: patch from Felipe (#7644)
- General clean up and much improved support for Qt. - Updated the example to contain a popup menu. git-svn-id: trunk@10107 -
This commit is contained in:
parent
bad4333bda
commit
497bf7b015
@ -1,44 +1,56 @@
|
||||
object Form1: TForm1
|
||||
Left = 290
|
||||
Height = 300
|
||||
Top = 175
|
||||
Width = 400
|
||||
HorzScrollBar.Page = 399
|
||||
VertScrollBar.Page = 299
|
||||
ActiveControl = Button1
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 300
|
||||
ClientWidth = 400
|
||||
OnCreate = FormCreate
|
||||
PixelsPerInch = 78
|
||||
HorzScrollBar.Page = 399
|
||||
VertScrollBar.Page = 299
|
||||
Left = 290
|
||||
Height = 300
|
||||
Top = 175
|
||||
Width = 400
|
||||
object Button1: TButton
|
||||
|
||||
Caption = 'Show'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 0
|
||||
Left = 56
|
||||
Height = 33
|
||||
Top = 56
|
||||
Width = 94
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Caption = 'Show'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 0
|
||||
end
|
||||
object Button2: TButton
|
||||
|
||||
Caption = 'Hide'
|
||||
OnClick = Button2Click
|
||||
TabOrder = 1
|
||||
Left = 56
|
||||
Height = 33
|
||||
Top = 112
|
||||
Width = 94
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Caption = 'Hide'
|
||||
OnClick = Button2Click
|
||||
TabOrder = 1
|
||||
end
|
||||
object Button3: TButton
|
||||
|
||||
Caption = 'Paint Test'
|
||||
OnClick = Button3Click
|
||||
TabOrder = 2
|
||||
Left = 224
|
||||
Height = 33
|
||||
Top = 56
|
||||
Width = 94
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Caption = 'Paint Test'
|
||||
OnClick = Button3Click
|
||||
TabOrder = 2
|
||||
end
|
||||
object PopupMenu: TPopupMenu
|
||||
left = 180
|
||||
top = 260
|
||||
object MenuItem1: TMenuItem
|
||||
Caption = 'New Item1'
|
||||
end
|
||||
object MenuItem3: TMenuItem
|
||||
Caption = 'New Item3'
|
||||
end
|
||||
object MenuItem2: TMenuItem
|
||||
Caption = 'New Item2'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,12 +1,19 @@
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#13'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'
|
||||
+#12'ClientHeight'#3','#1#11'ClientWidth'#3#144#1#8'OnCreate'#7#10'FormCreate'
|
||||
+#13'PixelsPerInch'#2'N'#18'HorzScrollBar.Page'#3#143#1#18'VertScrollBar.Page'
|
||||
+#3'+'#1#4'Left'#3'"'#1#6'Height'#3','#1#3'Top'#3#175#0#5'Width'#3#144#1#0#7
|
||||
+'TButton'#7'Button1'#7'Caption'#6#4'Show'#7'OnClick'#7#12'Button1Click'#8'Ta'
|
||||
+'bOrder'#2#0#4'Left'#2'8'#6'Height'#2'!'#3'Top'#2'8'#5'Width'#2'^'#0#0#7'TBu'
|
||||
+'tton'#7'Button2'#7'Caption'#6#4'Hide'#7'OnClick'#7#12'Button2Click'#8'TabOr'
|
||||
+'der'#2#1#4'Left'#2'8'#6'Height'#2'!'#3'Top'#2'p'#5'Width'#2'^'#0#0#7'TButto'
|
||||
+'n'#7'Button3'#7'Caption'#6#10'Paint Test'#7'OnClick'#7#12'Button3Click'#8'T'
|
||||
+'abOrder'#2#2#4'Left'#3#224#0#6'Height'#2'!'#3'Top'#2'8'#5'Width'#2'^'#0#0#0
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'"'#1#6'Height'#3','#1#3'Top'#3#175#0#5'Wi'
|
||||
+'dth'#3#144#1#18'HorzScrollBar.Page'#3#143#1#18'VertScrollBar.Page'#3'+'#1#13
|
||||
+'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'#12'ClientHeight'#3','#1#11
|
||||
+'ClientWidth'#3#144#1#8'OnCreate'#7#10'FormCreate'#0#7'TButton'#7'Button1'#4
|
||||
+'Left'#2'8'#6'Height'#2'!'#3'Top'#2'8'#5'Width'#2'^'#25'BorderSpacing.InnerB'
|
||||
+'order'#2#4#7'Caption'#6#4'Show'#7'OnClick'#7#12'Button1Click'#8'TabOrder'#2
|
||||
+#0#0#0#7'TButton'#7'Button2'#4'Left'#2'8'#6'Height'#2'!'#3'Top'#2'p'#5'Width'
|
||||
+#2'^'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#4'Hide'#7'OnClick'#7#12
|
||||
+'Button2Click'#8'TabOrder'#2#1#0#0#7'TButton'#7'Button3'#4'Left'#3#224#0#6'H'
|
||||
+'eight'#2'!'#3'Top'#2'8'#5'Width'#2'^'#25'BorderSpacing.InnerBorder'#2#4#7'C'
|
||||
+'aption'#6#10'Paint Test'#7'OnClick'#7#12'Button3Click'#8'TabOrder'#2#2#0#0
|
||||
+#10'TPopupMenu'#9'PopupMenu'#4'left'#3#180#0#3'top'#3#4#1#0#9'TMenuItem'#9'M'
|
||||
+'enuItem1'#7'Caption'#6#9'New Item1'#0#0#9'TMenuItem'#9'MenuItem3'#7'Caption'
|
||||
+#6#9'New Item3'#0#0#9'TMenuItem'#9'MenuItem2'#7'Caption'#6#9'New Item2'#0#0#0
|
||||
+#0
|
||||
]);
|
||||
|
@ -27,7 +27,7 @@ uses
|
||||
{$ifdef fpc}
|
||||
LResources,
|
||||
{$endif}
|
||||
Forms, Controls, Graphics, Dialogs, Buttons, StdCtrls;
|
||||
Forms, Controls, Graphics, Dialogs, Buttons, StdCtrls, Menus, TrayIcon;
|
||||
|
||||
type
|
||||
|
||||
@ -37,6 +37,10 @@ type
|
||||
Button1: TButton;
|
||||
Button2: TButton;
|
||||
Button3: TButton;
|
||||
MenuItem1: TMenuItem;
|
||||
MenuItem2: TMenuItem;
|
||||
MenuItem3: TMenuItem;
|
||||
PopupMenu: TPopupMenu;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
procedure Button3Click(Sender: TObject);
|
||||
@ -58,11 +62,9 @@ var
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
{$ifdef MSWindows}
|
||||
Windows,
|
||||
{$ifdef Windows}
|
||||
uses Windows;
|
||||
{$endif}
|
||||
TrayIcon;
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
@ -98,7 +100,7 @@ const
|
||||
IDI_ICON1 = 101;
|
||||
IDI_ICON2 = 115;
|
||||
begin
|
||||
{$ifdef MSWindows}
|
||||
{$ifdef Windows}
|
||||
SystrayIcon.Icon.Handle := LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
|
||||
|
||||
// Loading from a file should also work
|
||||
@ -111,7 +113,10 @@ begin
|
||||
SystrayIcon.Hint := 'my tool tip';
|
||||
|
||||
SystrayIcon.OnClick := HandleClick;
|
||||
|
||||
// SystrayIcon.OnPaint := DoPaint;
|
||||
|
||||
SystrayIcon.PopUpMenu := PopupMenu;
|
||||
end;
|
||||
|
||||
procedure TForm1.HandleClick(Sender: TObject);
|
||||
|
@ -48,6 +48,7 @@ type
|
||||
vOnPaint, vOnClick, vOnDblClick: TNotifyEvent;
|
||||
vOnMouseDown, vOnMouseUp: TMouseEvent;
|
||||
vOnMouseMove: TMouseMoveEvent;
|
||||
vwsTrayIcon: TWSTrayIcon;
|
||||
function GetCanvas: TCanvas;
|
||||
procedure SetVisible(Value: Boolean);
|
||||
protected
|
||||
@ -102,6 +103,8 @@ begin
|
||||
vIcon := TIcon.Create;
|
||||
|
||||
vShowIcon := True;
|
||||
|
||||
vWSTrayIcon := TWSTrayIcon.Create;
|
||||
end;
|
||||
|
||||
{*******************************************************************
|
||||
@ -118,6 +121,8 @@ destructor TTrayIcon.Destroy;
|
||||
begin
|
||||
vIcon.Free;
|
||||
|
||||
vwsTrayIcon.Free;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -222,7 +227,7 @@ end;
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterComponents('Additional',[TTrayIcon]);
|
||||
RegisterComponents('Additional', [TTrayIcon]);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
@ -199,7 +199,11 @@ end;
|
||||
*******************************************************************}
|
||||
function button_release_cb(widget: PGtkWidget; event: PGdkEventButton;
|
||||
user_data: gpointer): gboolean; cdecl;
|
||||
var
|
||||
vwsTrayIcon: TWSTrayIcon;
|
||||
begin
|
||||
vwsTrayIcon := TWSTrayIcon(user_data);
|
||||
|
||||
Result := False;
|
||||
|
||||
case event^.button of
|
||||
@ -211,15 +215,10 @@ begin
|
||||
end;
|
||||
|
||||
2: if Assigned(vwsTrayIcon.OnMouseUp) then
|
||||
vwsTrayIcon.OnMouseUp(vwsTrayIcon, mbRight, [], Round(event^.X), Round(event^.Y));
|
||||
vwsTrayIcon.OnMouseUp(vwsTrayIcon, mbMiddle, [], Round(event^.X), Round(event^.Y));
|
||||
|
||||
3:
|
||||
begin
|
||||
if Assigned(vwsTrayIcon.OnMouseUp) then
|
||||
vwsTrayIcon.OnMouseUp(vwsTrayIcon, mbRight, [], Round(event^.X), Round(event^.Y));
|
||||
if Assigned(vwsTrayIcon.PopUpMenu) then
|
||||
vwsTrayIcon.PopUpMenu.PopUp(Mouse.CursorPos.X, Mouse.CursorPos.Y);
|
||||
end;
|
||||
3: if Assigned(vwsTrayIcon.OnMouseUp) then
|
||||
vwsTrayIcon.OnMouseUp(vwsTrayIcon, mbRight, [], Round(event^.X), Round(event^.Y));
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -235,7 +234,11 @@ end;
|
||||
*******************************************************************}
|
||||
function button_press_cb(widget: PGtkWidget; event: PGdkEventButton;
|
||||
user_data: gpointer): gboolean; cdecl;
|
||||
var
|
||||
vwsTrayIcon: TWSTrayIcon;
|
||||
begin
|
||||
vwsTrayIcon := TWSTrayIcon(user_data);
|
||||
|
||||
Result := False;
|
||||
|
||||
if (event^._type = GDK_2BUTTON_PRESS) and Assigned(vwsTrayIcon.OnDblClick) then
|
||||
@ -247,10 +250,15 @@ begin
|
||||
vwsTrayIcon.OnMouseDown(vwsTrayIcon, mbLeft, [], Round(event^.X), Round(event^.Y));
|
||||
|
||||
2: if Assigned(vwsTrayIcon.OnMouseUp) then
|
||||
vwsTrayIcon.OnMouseDown(vwsTrayIcon, mbRight, [], Round(event^.X), Round(event^.Y));
|
||||
vwsTrayIcon.OnMouseDown(vwsTrayIcon, mbMiddle, [], Round(event^.X), Round(event^.Y));
|
||||
|
||||
3: if Assigned(vwsTrayIcon.OnMouseUp) then
|
||||
vwsTrayIcon.OnMouseDown(vwsTrayIcon, mbRight, [], Round(event^.X), Round(event^.Y));
|
||||
3:
|
||||
begin
|
||||
if Assigned(vwsTrayIcon.OnMouseUp) then
|
||||
vwsTrayIcon.OnMouseDown(vwsTrayIcon, mbRight, [], Round(event^.X), Round(event^.Y));
|
||||
if Assigned(vwsTrayIcon.PopUpMenu) then
|
||||
vwsTrayIcon.PopUpMenu.PopUp(Mouse.CursorPos.X, Mouse.CursorPos.Y);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -266,7 +274,11 @@ end;
|
||||
*
|
||||
*******************************************************************}
|
||||
function popup_cb(widget: PGtkWidget; user_data: gpointer): Boolean; cdecl;
|
||||
var
|
||||
vwsTrayIcon: TWSTrayIcon;
|
||||
begin
|
||||
vwsTrayIcon := TWSTrayIcon(user_data);
|
||||
|
||||
Result := True;
|
||||
|
||||
if Assigned(vwsTrayIcon.PopUpMenu) then
|
||||
@ -284,7 +296,11 @@ end;
|
||||
*
|
||||
*******************************************************************}
|
||||
function motion_cb(widget: PGtkWidget; event: PGdkEventMotion; user_data: gpointer): Boolean; cdecl;
|
||||
var
|
||||
vwsTrayIcon: TWSTrayIcon;
|
||||
begin
|
||||
vwsTrayIcon := TWSTrayIcon(user_data);
|
||||
|
||||
Result := False;
|
||||
|
||||
if Assigned(vwsTrayIcon.OnMouseMove) then
|
||||
@ -330,15 +346,15 @@ begin
|
||||
|
||||
gtk_widget_add_events(GtkForm, GDK_ALL_EVENTS_MASK);
|
||||
|
||||
g_signal_connect(GtkForm, 'realize', TGCallback(@realize_cb), nil);
|
||||
g_signal_connect(GtkForm, 'realize', TGCallback(@realize_cb), Self);
|
||||
|
||||
g_signal_connect(GtkForm, 'popup-menu', TGCallback(@popup_cb), nil);
|
||||
g_signal_connect(GtkForm, 'popup-menu', TGCallback(@popup_cb), Self);
|
||||
|
||||
g_signal_connect(GtkForm, 'motion-notify-event', TGCallback(@motion_cb), nil);
|
||||
g_signal_connect(GtkForm, 'motion-notify-event', TGCallback(@motion_cb), Self);
|
||||
|
||||
g_signal_connect(GtkForm, 'button-press-event', TGCallback(@button_press_cb), nil);
|
||||
g_signal_connect(GtkForm, 'button-press-event', TGCallback(@button_press_cb), Self);
|
||||
|
||||
g_signal_connect(GtkForm, 'button-release-event', TGCallback(@button_release_cb), nil);
|
||||
g_signal_connect(GtkForm, 'button-release-event', TGCallback(@button_release_cb), Self);
|
||||
|
||||
{*******************************************************************
|
||||
* Draws the icon
|
||||
|
@ -48,20 +48,28 @@ uses
|
||||
{$endif}
|
||||
{$ifdef UNIX}
|
||||
|
||||
{$ifdef LCLGtk}
|
||||
wsgtktrayicon,
|
||||
{$endif}
|
||||
{$ifdef DARWIN}
|
||||
|
||||
wscarbontrayicon,
|
||||
|
||||
{$else}
|
||||
|
||||
{$ifdef LCLGnome}
|
||||
wsgtktrayicon,
|
||||
{$endif}
|
||||
{$ifdef LCLGtk}
|
||||
wsgtktrayicon,
|
||||
{$endif}
|
||||
|
||||
{$ifdef LCLGtk2}
|
||||
wsgtk2trayicon,
|
||||
{$endif}
|
||||
{$ifdef LCLGnome}
|
||||
wsgtktrayicon,
|
||||
{$endif}
|
||||
|
||||
{$ifdef LCLQt}
|
||||
wsx11trayicon,
|
||||
{$ifdef LCLGtk2}
|
||||
wsgtk2trayicon,
|
||||
{$endif}
|
||||
|
||||
{$ifdef LCLQt}
|
||||
wsx11trayicon,
|
||||
{$endif}
|
||||
|
||||
{$endif}
|
||||
|
||||
{$endif}
|
||||
@ -79,22 +87,8 @@ type
|
||||
published
|
||||
end;
|
||||
|
||||
var
|
||||
vwsTrayIcon: TWidgetTrayIcon;
|
||||
vwsTrayIconCreated: Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
initialization
|
||||
|
||||
vwsTrayIconCreated := False;
|
||||
vwsTrayIcon := TWidgetTrayIcon.Create;
|
||||
vwsTrayIconCreated := True;
|
||||
|
||||
finalization
|
||||
|
||||
vwsTrayIcon.Free;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
|
@ -48,32 +48,21 @@ type
|
||||
fDrawable: TWindow;
|
||||
fWindowID: TWindow;
|
||||
fVisual: PVisual;
|
||||
fDepth: Integer;
|
||||
fDepth, fWidth, fHeight: Integer;
|
||||
fRootWindow: TWindow;
|
||||
gc: Xlib.TGC;
|
||||
{ fIcon: TIcon;
|
||||
fEmbedded: Boolean;
|
||||
fMenu: TPopupMenu;
|
||||
fMouseEnter: TNotifyEvent;
|
||||
fMouseLeave: TNotifyEvent;
|
||||
fMouseDown: TMouseEvent;
|
||||
fMouseUp: TMouseEvent;
|
||||
fMouseMove: TMouseMoveEvent;
|
||||
fClick: TNotifyEvent;
|
||||
fTrayParent: TWindow;
|
||||
fWidth, fHeight: Integer;
|
||||
fIconWidth,
|
||||
fIconHeight: Integer;
|
||||
fImage: xlib.PXImage;
|
||||
|
||||
fTimer: TTimer;
|
||||
Image: xlib.PXImage;
|
||||
fMsgCount: Integer;
|
||||
WindowHandle: Cardinal;}
|
||||
|
||||
procedure SetEmbedded;
|
||||
procedure InitWM;
|
||||
procedure SetMinSize(AWidth, AHeight: Integer);
|
||||
function Send_Message(window: TWindow; msg: Integer;data1, data2,data3: Integer): boolean;
|
||||
function AttachIcon: TWindow;
|
||||
function GetCanvas: TCanvas;
|
||||
procedure OnEventTimer(Sender: TObject);
|
||||
procedure RePaint;
|
||||
protected
|
||||
public
|
||||
hIcon, hSmallIcon: Cardinal;
|
||||
@ -94,11 +83,19 @@ const
|
||||
|
||||
implementation
|
||||
|
||||
uses WSTrayIcon;
|
||||
|
||||
// Temp ErrorHandler
|
||||
function TempX11ErrorHandler(Display:PDisplay; ErrorEv:PXErrorEvent):longint;cdecl;
|
||||
function TempX11ErrorHandler(Display:PDisplay; ErrorEv:PXErrorEvent): longint; cdecl;
|
||||
begin
|
||||
WriteLn('Error: ' + IntToStr(ErrorEv^.error_code));
|
||||
Result:=0;
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
// Processes X11 events
|
||||
function ProcessEvent(display:PDisplay; event:PXEvent; p : TXPointer): TBool; cdecl;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{ TWidgetTrayIcon }
|
||||
@ -179,6 +176,16 @@ begin
|
||||
Result := false;//(untrap_errors() = 0);
|
||||
end;
|
||||
|
||||
{*******************************************************************
|
||||
* TWidgetTrayIcon.InitWM ()
|
||||
*
|
||||
* DESCRIPTION: Initializes the Window Manager hints
|
||||
*
|
||||
* PARAMETERS:
|
||||
*
|
||||
* RETURNS: Nothing
|
||||
*
|
||||
*******************************************************************}
|
||||
procedure TWidgetTrayIcon.InitWM;
|
||||
var
|
||||
// set the class hint
|
||||
@ -230,17 +237,27 @@ begin
|
||||
XSetStandardProperties(fDisplay, fWindow, nil, nil, None, nil, 0, @size_hints);
|
||||
end;
|
||||
|
||||
{*******************************************************************
|
||||
* TWidgetTrayIcon.AttachIcon ()
|
||||
*
|
||||
* DESCRIPTION: Attachs a icon to the Tray
|
||||
*
|
||||
* PARAMETERS:
|
||||
*
|
||||
* RETURNS: Nothing
|
||||
*
|
||||
*******************************************************************}
|
||||
function TWidgetTrayIcon.AttachIcon: TWindow;
|
||||
var
|
||||
buf: array [0..32] of char;
|
||||
selection_atom : TAtom;
|
||||
Manager_Window: TWindow;
|
||||
old_error: TXErrorHandler;
|
||||
data: array [0..3] of longint;
|
||||
buf: array [0..32] of char;
|
||||
selection_atom : TAtom;
|
||||
Manager_Window: TWindow;
|
||||
old_error: TXErrorHandler;
|
||||
data: array [0..3] of longint;
|
||||
begin
|
||||
old_error := XSetErrorHandler(@TempX11ErrorHandler);
|
||||
initWM;
|
||||
//SetMinSize(fIconWidth, fIconHeight);
|
||||
|
||||
fScreenID := XScreenNumberOfScreen(fScreen);
|
||||
buf := PChar('_NET_SYSTEM_TRAY_S' + IntToStr(fScreenID));
|
||||
|
||||
@ -262,12 +279,11 @@ begin
|
||||
|
||||
if ( manager_window <> None ) then
|
||||
send_message(Manager_Window, SYSTEM_TRAY_REQUEST_DOCK, fWindowID, 0, 0);
|
||||
SetMinSize(Icon.Width,Icon.Height);
|
||||
SetMinSize(Icon.Width, Icon.Height);
|
||||
XChangeProperty(fDisplay, fWindowID, XInternAtom( fdisplay, '_NET_WM_ICON_GEOMETRY',False),
|
||||
TAtom(6), 32, PropModeReplace, @data, 4);
|
||||
// XResizeWindow(fDisplay, fWindowID, 22, 22);
|
||||
// XResizeWindow(fDisplay, fWindowID, 22, 22);
|
||||
XSetErrorHandler(old_error);
|
||||
//fTimer.Enabled := True;
|
||||
end;
|
||||
|
||||
{*******************************************************************
|
||||
@ -285,6 +301,187 @@ begin
|
||||
Result := Icon.Canvas;
|
||||
end;
|
||||
|
||||
{*******************************************************************
|
||||
* TWidgetTrayIcon.OnEventTimer ()
|
||||
*
|
||||
* DESCRIPTION: Processes X messages
|
||||
*
|
||||
* PARAMETERS: None
|
||||
*
|
||||
* RETURNS: Nothing
|
||||
*
|
||||
*******************************************************************}
|
||||
procedure TWidgetTrayIcon.OnEventTimer(Sender: TObject);
|
||||
var
|
||||
ev: TXEvent;
|
||||
sShift: TShiftState;
|
||||
Btn: TMouseButton;
|
||||
BtnPressEv: PXButtonPressedEvent;
|
||||
BtnReleaseEv : PXButtonReleasedEvent;
|
||||
MouseMotionEv: PXMotionEvent;
|
||||
ResizeEv : PXResizeRequestEvent;
|
||||
ClientEv: PXClientMessageEvent;
|
||||
begin
|
||||
if (fDisplay = nil) then Exit;
|
||||
|
||||
while XCheckIfEvent(fDisplay, @ev, @ProcessEvent, nil) do
|
||||
begin
|
||||
sShift := [];
|
||||
|
||||
case ev._type of
|
||||
ButtonRelease:
|
||||
begin
|
||||
BtnReleaseEv := PXButtonReleasedEvent(@ev);
|
||||
case BtnReleaseEv^.button of
|
||||
1:
|
||||
begin
|
||||
if Assigned(OnClick) then OnClick(Self);
|
||||
if Assigned(OnMouseUp) then
|
||||
OnMouseUp(Self, mbLeft, [], Round(BtnReleaseEv^.X), Round(BtnReleaseEv^.Y));
|
||||
end;
|
||||
|
||||
2: if Assigned(OnMouseUp) then
|
||||
OnMouseUp(Self, mbMiddle, [], Round(BtnReleaseEv^.X), Round(BtnReleaseEv^.Y));
|
||||
|
||||
3:
|
||||
begin
|
||||
if Assigned(OnMouseUp) then
|
||||
OnMouseUp(Self, mbRight, [], Round(BtnReleaseEv^.X), Round(BtnReleaseEv^.Y));
|
||||
if Assigned(PopUpMenu) then
|
||||
PopUpMenu.PopUp(Mouse.CursorPos.X, Mouse.CursorPos.Y);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
ButtonPress:
|
||||
begin
|
||||
BtnPressEv := PXButtonPressedEvent(@ev);
|
||||
case BtnPressEv^.button of
|
||||
1: if Assigned(OnMouseUp) then
|
||||
OnMouseDown(Self, mbLeft, [], Round(BtnPressEv^.X), Round(BtnPressEv^.Y));
|
||||
|
||||
2: if Assigned(OnMouseUp) then
|
||||
OnMouseDown(Self, mbMiddle, [], Round(BtnPressEv^.X), Round(BtnPressEv^.Y));
|
||||
|
||||
3:
|
||||
begin
|
||||
if Assigned(OnMouseUp) then
|
||||
OnMouseDown(Self, mbRight, [], Round(BtnPressEv^.X), Round(BtnPressEv^.Y));
|
||||
if Assigned(PopUpMenu) then
|
||||
PopUpMenu.PopUp(BtnPressEv^.x_root, BtnPressEv^.y_root);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
Expose, GraphicsExpose, VisibilityNotify, VisibilityUnobscured, VisibilityPartiallyObscured:
|
||||
begin
|
||||
Repaint;
|
||||
end;
|
||||
{ EnterNotify:
|
||||
begin
|
||||
if Assigned(MouseEnter) then MouseEnter(Self);
|
||||
end;
|
||||
LeaveNotify:
|
||||
begin
|
||||
if Assigned(MouseLeave) then MouseLeave(Self);
|
||||
end;}
|
||||
MotionNotify:
|
||||
begin
|
||||
MouseMotionEv := PXMotionEvent(@ev);
|
||||
|
||||
if Button1Mask in [MouseMotionEv^.state] then sShift += [ssLeft];
|
||||
if Button2Mask in [MouseMotionEv^.state] then sShift += [ssMiddle];
|
||||
if Button3Mask in [MouseMotionEv^.state] then sShift += [ssRight];
|
||||
|
||||
if Assigned(OnMouseMove) then
|
||||
OnMouseMove(Self, sShift, Round(MouseMotionEv^.X), Round(MouseMotionEv^.Y));
|
||||
end;
|
||||
ResizeRequest:
|
||||
begin
|
||||
ResizeEv := PXResizeRequestEvent(@ev);
|
||||
fWidth := ResizeEv^.width;
|
||||
fHeight := ResizeEv^.height;
|
||||
|
||||
if fImage <> nil then
|
||||
begin
|
||||
XClearWindow(fDisplay,fWindowID);
|
||||
XFree(fImage);
|
||||
fImage := nil;
|
||||
end;
|
||||
|
||||
if vVisible then Repaint;
|
||||
end;
|
||||
CLientMessage:
|
||||
begin
|
||||
ClientEv := PXClientMessageEvent(@Ev);
|
||||
end;
|
||||
else
|
||||
// Writeln('Unprocessed X11 event for the tray icon: ', ev._type);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{*******************************************************************
|
||||
* TWidgetTrayIcon.RePaint ()
|
||||
*
|
||||
* DESCRIPTION: Paints the icon
|
||||
*
|
||||
* PARAMETERS: None
|
||||
*
|
||||
* RETURNS: Nothing
|
||||
*
|
||||
*******************************************************************}
|
||||
procedure TWidgetTrayIcon.RePaint;
|
||||
|
||||
function SwapColor(Color: TColor): TColor;
|
||||
var
|
||||
fcolor: Array [0..3] of byte;
|
||||
tmp: byte;
|
||||
begin
|
||||
move(color, fcolor, sizeof(fcolor));
|
||||
tmp := fcolor[0];
|
||||
fcolor[0] := fcolor[2];
|
||||
fcolor[2] := tmp;
|
||||
result := TColor(fColor);
|
||||
end;
|
||||
|
||||
var
|
||||
bitmap_pad: integer;
|
||||
Pixel: TColor;
|
||||
x,y: Integer;
|
||||
fTop, fLeft: Integer;
|
||||
begin
|
||||
if (fImage = nil) then
|
||||
begin
|
||||
if fDepth > 16 then bitmap_pad := 32
|
||||
else if fDepth > 8 then bitmap_pad := 16
|
||||
else bitmap_pad := 8;
|
||||
fImage := XCreateImage(fDisplay, fVisual, fDepth, ZPixmap, 0, nil,
|
||||
34, 34, bitmap_pad, 0);
|
||||
fImage^.data := AllocMem(fImage^.bytes_per_line * fHeight * 4);
|
||||
fleft := 0;
|
||||
ftop := 0;
|
||||
if fWidth > Icon.Width then fLeft := (fWidth - Icon.Width) div 2;
|
||||
if fHeight > Icon.Height then fTop := (fHeight- Icon.Height) div 2;
|
||||
for Y := 0 to fHeight do
|
||||
begin
|
||||
for X := 0 to fwidth do
|
||||
begin
|
||||
// Causes an error in gdk_colormap_get_visual
|
||||
if (y-ftop > Icon.Height)
|
||||
or (x-fleft > Icon.Width)
|
||||
or (X < fLeft) or (X > fLeft + fWidth)
|
||||
or (Y < fTop) or (Y > fTop + fHeight)
|
||||
then
|
||||
pixel := SwapColor(Icon.TransparentColor)
|
||||
else
|
||||
pixel := SwapColor(Icon.Canvas.Pixels[x-fLeft, y-fTop]);
|
||||
|
||||
XPutPixel(fImage, X, Y, (pixel));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
XPutImage(fDisplay, fDrawable, gc, fImage, 0, 0, 0, 0, fWidth, fHeight);
|
||||
end;
|
||||
|
||||
{*******************************************************************
|
||||
* TWidgetTrayIcon.Hide ()
|
||||
*
|
||||
@ -301,6 +498,13 @@ begin
|
||||
|
||||
if not vVisible then Exit;
|
||||
|
||||
fTimer.OnTimer := nil;
|
||||
fTimer.Enabled := False;
|
||||
fTimer.Free;
|
||||
|
||||
XFree(fImage);
|
||||
fImage := nil;
|
||||
|
||||
if fWindowID <> 0 then XDestroyWindow(fDisplay, fWindowID);
|
||||
fWindowID := 0;
|
||||
XFreeGC(fDisplay, gc);
|
||||
@ -327,25 +531,27 @@ begin
|
||||
Result := False;
|
||||
|
||||
if vVisible then Exit;
|
||||
|
||||
{ Timer to process messages }
|
||||
|
||||
// CreateForm(0);
|
||||
fTimer := TTimer.Create(fOwner);
|
||||
fTimer.Interval := 10;
|
||||
fTimer.OnTimer := @OnEventTimer;
|
||||
fTimer.Enabled := True;
|
||||
|
||||
{ Painting code }
|
||||
|
||||
fWidth := 24;
|
||||
fHeight := 24;
|
||||
fImage := nil;
|
||||
|
||||
{ Creates the tray window }
|
||||
|
||||
SetEmbedded;
|
||||
|
||||
{ GTK_WIDGET_SET_FLAGS(PGtkWidget(GtkForm.Handle),GTK_VISIBLE);
|
||||
GTK_WIDGET_SET_FLAGS(PGtkWidget(GtkForm.Handle),GTK_MAPPED);
|
||||
|
||||
GtkForm.Width := 22; //needed for gnome
|
||||
GtkForm.Height := 22;
|
||||
SetMinSize(Icon.Width, Icon.Height);
|
||||
|
||||
GtkForm.OnMouseDown := Self.OnMouseDown;
|
||||
GtkForm.OnMouseMove := Self.OnMouseMove;
|
||||
GtkForm.OnMouseUp := Self.OnMouseUp;
|
||||
GtkForm.OnClick := Self.OnClick;
|
||||
GtkForm.OnPaint := PaintForm;
|
||||
GtkForm.PopupMenu := Self.PopUpMenu;
|
||||
GtkForm.Hint := Self.Hint;}
|
||||
|
||||
{ needed for gnome }
|
||||
|
||||
// SetMinSize(22, 22);
|
||||
|
||||
fEmbedded := True;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user