lcl: gtk2: send LM_ContextMenu to designer after mouse release

This commit is contained in:
mattias 2022-05-07 07:05:01 +02:00
parent b3be9dea57
commit b2be620760
3 changed files with 62 additions and 61 deletions

View File

@ -797,7 +797,8 @@ begin
{$ENDIF}
end;
function GTKKeyPress(Widget: PGtkWidget; Event: PGdkEventKey; Data: gPointer) : GBoolean; cdecl;
function GTKKeyPress(Widget: PGtkWidget; Event: pgdkeventkey; Data: gPointer
): GBoolean; cdecl;
begin
Result := HandleGtkKeyUpDown(Widget,Event,Data,true,True,'key-press-event');
end;
@ -807,7 +808,8 @@ begin
Result := HandleGtkKeyUpDown(Widget,Event,Data,false,True,'key-press-event');
end;
function GTKKeyRelease(Widget: PGtkWidget; Event: PGdkEventKey; Data: gPointer) : GBoolean; cdecl;
function GTKKeyRelease(Widget: PGtkWidget; Event: pgdkeventkey; Data: gPointer
): GBoolean; cdecl;
begin
Result := HandleGtkKeyUpDown(Widget,Event,Data,true,False,'key-release-event');
end;
@ -1799,40 +1801,6 @@ function gtkMouseBtnPress(widget: PGtkWidget; event: pgdkEventButton; data: gPoi
Include(Info^.Flags, wwiTabWidgetFocusCheck);
end;
function SendContextMenu: gboolean;
var
x, y: gint;
W: PGtkWidget;
Info: PWidgetInfo;
Old: TObject;
Msg: TLMContextMenu;
begin
Result:=CallBackDefaultReturn;
W := Widget;
gdk_display_get_pointer(gtk_widget_get_display(Widget), nil, @x, @y, nil);
Old := nil;
while W <> nil do
begin
Info := GetWidgetInfo(W);
if (Info <> nil) and (Info^.LCLObject <> Old) then
begin
Old := Info^.LCLObject;
FillChar(Msg{%H-}, SizeOf(Msg), #0);
Msg.Msg := LM_CONTEXTMENU;
Msg.hWnd := {%H-}HWND(W);
Msg.XPos := x;
Msg.YPos := y;
Result := DeliverMessage(Old, Msg) <> 0;
if Result then break;
end;
// check if widget has a standard popup menu
if (W = widget) and Assigned(GTK_WIDGET_GET_CLASS(W)^.popup_menu) then
break;
W := gtk_widget_get_parent(W);
end;
end;
var
DesignOnlySignal, StopSignal: boolean;
Path: PGtkTreePath;
@ -1896,7 +1864,7 @@ begin
// if LCL process LM_CONTEXTMENU then stop the event propagation
if (Event^.button = 3) then
begin
Result:=SendContextMenu;
Result:=DeliverContextMenuMessage(widget,true);
{emit selection change when right mouse button pressed
otherwise LCL is not updated since ChangeLock = 1 in case
@ -1928,11 +1896,6 @@ begin
//DebugLn(['gtkMouseBtnPress stop signal']);
StopSignal:=true;
end;
if (Event^.button = 3) then
begin
Result:=SendContextMenu;
end;
end;
if StopSignal then
g_signal_stop_emission_by_name(PGTKObject(Widget), 'button-press-event');
@ -2145,6 +2108,41 @@ begin
end;
end;
function DeliverContextMenuMessage(Widget: PGtkWidget;
CheckGtkPopupMenu: boolean): gboolean;
var
x, y: gint;
W: PGtkWidget;
Info: PWidgetInfo;
Old: TObject;
Msg: TLMContextMenu;
begin
Result:=CallBackDefaultReturn;
W := Widget;
gdk_display_get_pointer(gtk_widget_get_display(Widget), nil, @x, @y, nil);
Old := nil;
while W <> nil do
begin
Info := GetWidgetInfo(W);
if (Info <> nil) and (Info^.LCLObject <> Old) then
begin
Old := Info^.LCLObject;
FillByte(Msg{%H-}, SizeOf(Msg), 0);
Msg.Msg := LM_CONTEXTMENU;
Msg.hWnd := {%H-}HWND(W);
Msg.XPos := x;
Msg.YPos := y;
Result := DeliverMessage(Old, Msg) <> 0;
if Result then break;
end;
// check if widget has a standard popup menu
if (W = widget) and CheckGtkPopupMenu and Assigned(GTK_WIDGET_GET_CLASS(W)^.popup_menu) then
break;
W := gtk_widget_get_parent(W);
end;
end;
{-------------------------------------------------------------------------------
gtkMouseBtnPressAfter
Params: widget: PGTKWidget; event: PGDKEventMotion; data: gPointer
@ -2361,6 +2359,14 @@ begin
end;
end else
ReleaseMouseCapture;
if (csDesigning in TComponent(Data).ComponentState) then
begin
if (Event^.button = 3) then
begin
Result:=DeliverContextMenuMessage(widget,false);
end;
end;
end;
{-------------------------------------------------------------------------------
@ -2388,10 +2394,10 @@ begin
ResetDefaultIMContext;
if (csDesigning in TComponent(Data).ComponentState) then exit;
if ControlGetsMouseUpBefore(TControl(Data)) then exit;
DeliverMouseUpMessage(Widget,Event,TWinControl(Data));
if (csDesigning in TComponent(Data).ComponentState) then
else if ControlGetsMouseUpBefore(TControl(Data)) then
else
DeliverMouseUpMessage(Widget,Event,TWinControl(Data));
end;
function gtkMouseWheelCB(widget: PGtkWidget; event: PGdkEventScroll;
@ -3720,13 +3726,9 @@ end;
//DRAG CALLBACK FUNCTIONS
function edit_drag_data_received({%H-}widget : pgtkWidget;
Context : pGdkDragContext;
{%H-}X, {%H-}Y : Integer;
SelData : pGtkSelectionData;
{%H-}info : Integer;
time : Integer;
data : pointer) : GBoolean; cdecl;
function edit_drag_data_received(widget: pgtkWidget; Context: pGdkDragContext;
X: Integer; Y: Integer; seldata: pGtkSelectionData; info: Integer;
time: Integer; data: pointer): GBoolean; cdecl;
Var
Texts : String;
Begin
@ -3778,8 +3780,8 @@ Begin
end;
function Edit_source_drag_data_delete ({%H-}Widget: pGtkWidget;
{%H-}Context: pGdkDragContext; {%H-}Data: gpointer): gBoolean ; cdecl;
function Edit_source_drag_data_delete(widget: pGtkWidget;
context: pGdkDragContext; data: gpointer): gBoolean; cdecl;
begin
//DebugLn('Trace:***************');
//DebugLn('Trace:DELETE THE DATA');

View File

@ -180,9 +180,8 @@ begin
GDK2.gdk_region_xor(result, source2);
end;
Procedure gdk_text_extents(TheFont: TGtkIntfFont;
Str: PChar; StrLength: integer;
lbearing, rbearing, width, ascent, descent: Pgint);
procedure gdk_text_extents(TheFont: TGtkIntfFont; Str: PChar;
StrLength: integer; lbearing, rbearing, width, ascent, descent: Pgint);
var
Layout : PPangoLayout;
Extents : TPangoRectangle;
@ -1490,7 +1489,7 @@ begin
{$ENDIF}
end;
Procedure FreeGDIColor(GDIColor: PGDIColor);
procedure FreeGDIColor(GDIColor: PGDIColor);
begin
if (cfColorAllocated in GDIColor^.ColorFlags) then begin
if (GDIColor^.Colormap <> nil) then begin

View File

@ -139,16 +139,16 @@ function gtkdeleteCB({%H-}widget: PGtkWidget; {%H-}event: PGdkEvent;
data: gPointer): GBoolean; cdecl;
function gtkresizeCB({%H-}widget: PGtkWidget; {%H-}data: gPointer): GBoolean; cdecl;
function gtkMonthChanged({%H-}Widget: PGtkWidget; data: gPointer): GBoolean; cdecl;
procedure DeliverMouseMoveMessage({%H-}Widget:PGTKWidget; Event: PGDKEventMotion;
AWinControl: TWinControl);
function gtkMotionNotify(Widget:PGTKWidget; Event: PGDKEventMotion;
Data: gPointer): GBoolean; cdecl;
function GTKMotionNotifyAfter(widget:PGTKWidget; event: PGDKEventMotion;
data: gPointer): GBoolean; cdecl;
function DeliverMouseDownMessage({%H-}widget: PGtkWidget; event: pgdkEventButton;
AWinControl: TWinControl): PtrInt;
function DeliverContextMenuMessage(Widget: PGtkWidget; CheckGtkPopupMenu: boolean): gboolean;
function gtk2ScrollBarMouseBtnPress({%H-}widget: PGtkWidget; {%H-}event: pgdkEventButton;
{%H-}data: gPointer): GBoolean; cdecl;