mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 00:39:10 +02:00
LCL-GTK2: Fix a crash due to postponed actions after a widget loses focus. Issue #28840.
(cherry picked from commit 9dccbc008f
)
This commit is contained in:
parent
579c3ed607
commit
18f1d06255
@ -984,35 +984,13 @@ begin
|
|||||||
Result:=CallBackDefaultReturn;
|
Result:=CallBackDefaultReturn;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GtkEntryDelayClearCursorPos(AGtkWidget: Pointer): GBoolean; cdecl;
|
|
||||||
var
|
|
||||||
Info: PWidgetInfo;
|
|
||||||
p: Pgchar;
|
|
||||||
AStart,AEnd: gint;
|
|
||||||
begin
|
|
||||||
Result := (AGtkWidget <> nil) and (GTK_IS_WIDGET(AGtkWidget));
|
|
||||||
if Result then
|
|
||||||
begin
|
|
||||||
g_idle_remove_by_data(AGtkWidget);
|
|
||||||
Info := GetWidgetInfo(AGtkWidget);
|
|
||||||
if Info <> nil then
|
|
||||||
begin
|
|
||||||
gtk_editable_get_selection_bounds(PGtkEditable(AGtkWidget),@AStart, @AEnd);
|
|
||||||
p := gtk_editable_get_chars(PGtkEditable(AGtkWidget), AStart, AEnd);
|
|
||||||
if (AStart <> AEnd) then
|
|
||||||
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), p, -1);
|
|
||||||
gtk_editable_select_region(PGtkEditable(AGtkWidget), 0, 0);
|
|
||||||
g_free(p);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function GTKKillFocusCBAfter({%H-}widget: PGtkWidget; {%H-}event:PGdkEventFocus;
|
function GTKKillFocusCBAfter({%H-}widget: PGtkWidget; {%H-}event:PGdkEventFocus;
|
||||||
data: gPointer) : GBoolean; cdecl;
|
data: gPointer) : GBoolean; cdecl;
|
||||||
var
|
var
|
||||||
Mess: TLMessage;
|
Mess: TLMessage;
|
||||||
Info: PWidgetInfo;
|
Info: PWidgetInfo;
|
||||||
AStart, AEnd: gint;
|
AStart, AEnd: gint;
|
||||||
|
p: Pgchar;
|
||||||
AForm: TCustomForm;
|
AForm: TCustomForm;
|
||||||
{$IFDEF VerboseFocus}
|
{$IFDEF VerboseFocus}
|
||||||
LCLObject: TObject;
|
LCLObject: TObject;
|
||||||
@ -1071,9 +1049,8 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
g_idle_add(@GtkEntryDelayClearCursorPos, Widget);
|
|
||||||
//save now CursorPos and SelStart in WidgetInfo
|
//save now CursorPos and SelStart in WidgetInfo
|
||||||
if (Widget <> nil) then
|
if Widget <> nil then
|
||||||
begin
|
begin
|
||||||
Info := GetWidgetInfo(Widget);
|
Info := GetWidgetInfo(Widget);
|
||||||
if Info <> nil then
|
if Info <> nil then
|
||||||
@ -1083,6 +1060,13 @@ begin
|
|||||||
gtk_editable_get_selection_bounds(PGtkEditable(Widget),@AStart, @AEnd);
|
gtk_editable_get_selection_bounds(PGtkEditable(Widget),@AStart, @AEnd);
|
||||||
Info^.CursorPos := Min(AStart, AEnd);
|
Info^.CursorPos := Min(AStart, AEnd);
|
||||||
Info^.SelLength := Abs(AEnd - AStart);
|
Info^.SelLength := Abs(AEnd - AStart);
|
||||||
|
// Copy text to X-clipboard (paste = middle mouse button).
|
||||||
|
p := gtk_editable_get_chars(PGtkEditable(Widget), AStart, AEnd);
|
||||||
|
if AStart <> AEnd then
|
||||||
|
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), p, -1);
|
||||||
|
g_free(p);
|
||||||
|
// Show the text properly when tabbing between controls.
|
||||||
|
gtk_editable_select_region(PGtkEditable(Widget), 0, 0);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user