mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 23:00:35 +02:00
Gtk2: postpone SetSelStart() since selStart can be changed in OnChange event. fixes #16678
git-svn-id: trunk@26253 -
This commit is contained in:
parent
98be23e127
commit
00475aa337
@ -410,6 +410,7 @@ var
|
||||
GStart, GEnd: gint;
|
||||
Info: PWidgetInfo;
|
||||
EntryText: PgChar;
|
||||
NeedCursorCheck: Boolean;
|
||||
begin
|
||||
Result := CallBackDefaultReturn;
|
||||
|
||||
@ -417,7 +418,7 @@ begin
|
||||
{$IFDEF EventTrace}
|
||||
EventTrace('changed_editbox', data);
|
||||
{$ENDIF}
|
||||
|
||||
NeedCursorCheck := False;
|
||||
if GTK_IS_ENTRY(Widget) then
|
||||
begin
|
||||
{cheat GtkEditable to update cursor pos in gtkEntry. issue #7243}
|
||||
@ -431,12 +432,22 @@ begin
|
||||
if wwiInvalidEvent in Info^.Flags then
|
||||
exclude(Info^.Flags, wwiInvalidEvent)
|
||||
else
|
||||
begin
|
||||
// if we change selstart in OnChange event new cursor pos need to
|
||||
// be postponed in TGtk2WSCustomEdit.SetSelStart
|
||||
NeedCursorCheck := True;
|
||||
gtk_editable_set_position(PGtkEditable(Widget), GStart + 1);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
if NeedCursorCheck then
|
||||
LockOnChange(PgtkObject(Widget), +1);
|
||||
FillByte(Mess,SizeOf(Mess),0);
|
||||
Mess.Msg := CM_TEXTCHANGED;
|
||||
DeliverMessage(Data, Mess);
|
||||
if NeedCursorCheck then
|
||||
LockOnChange(PgtkObject(Widget), -1);
|
||||
end;
|
||||
|
||||
function gtkchanged_spinbox(widget: PGtkWidget; data: gPointer): GBoolean; cdecl;
|
||||
|
@ -463,6 +463,7 @@ type
|
||||
ExStyle: Integer;
|
||||
EventMask: TGdkEventMask;
|
||||
DoubleBuffer: PGdkPixmap;
|
||||
CursorPos: integer; // needed for delayed SetSelStart
|
||||
ControlCursor: HCursor; // current widget cursor
|
||||
DefaultCursor: HCursor; // default widget cursor
|
||||
Flags: TWidgetInfoFlags;
|
||||
|
@ -1142,11 +1142,22 @@ begin
|
||||
gtk_editable_set_editable(PGtkEditable(Widget), not NewReadOnly);
|
||||
end;
|
||||
|
||||
function gtk2WSDelayedSelStart(Data: Pointer): gboolean; cdecl;
|
||||
var
|
||||
Entry: PGtkEntry;
|
||||
begin
|
||||
Result := False;
|
||||
Entry := PGtkEntry(PWidgetInfo(Data)^.CoreWidget);
|
||||
gtk_editable_set_position(PGtkEditable(Entry), PWidgetInfo(Data)^.CursorPos);
|
||||
g_idle_remove_by_data(Data);
|
||||
end;
|
||||
|
||||
class procedure TGtk2WSCustomEdit.SetSelStart(const ACustomEdit: TCustomEdit;
|
||||
NewStart: integer);
|
||||
var
|
||||
NewPos: Integer;
|
||||
Entry: PGtkEntry;
|
||||
WidgetInfo: PWidgetInfo;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ACustomEdit, 'SetSelStart') then
|
||||
Exit;
|
||||
@ -1157,7 +1168,14 @@ begin
|
||||
NewPos := Min(NewStart, Entry^.text_max_length)
|
||||
else
|
||||
NewPos := Min(NewStart, Entry^.text_length);
|
||||
gtk_entry_set_position(Entry, NewPos);
|
||||
if LockOnChange(PgtkObject(Entry),0) > 0 then
|
||||
begin
|
||||
WidgetInfo := GetWidgetInfo(Entry);
|
||||
WidgetInfo^.CursorPos := NewPos;
|
||||
// postpone
|
||||
g_idle_add(@gtk2WSDelayedSelStart, WidgetInfo);
|
||||
end else
|
||||
gtk_editable_set_position(PGtkEditable(Entry), NewPos);
|
||||
end;
|
||||
|
||||
class procedure TGtk2WSCustomEdit.SetSelLength(
|
||||
|
Loading…
Reference in New Issue
Block a user