From 10190078530bbb11f3c658b0137a215a560cbc87 Mon Sep 17 00:00:00 2001 From: Abou Al Montacir Date: Sun, 21 Jan 2024 19:29:45 +0100 Subject: [PATCH] GTK3: Fixed selected item text returned by ComboBox Text property. We need to use `GtkEntry` for comboboxes with `has_entry = True` and set the `column_id` property. Closes #40706 --- lcl/interfaces/gtk3/gtk3widgets.pas | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lcl/interfaces/gtk3/gtk3widgets.pas b/lcl/interfaces/gtk3/gtk3widgets.pas index ed64870c84..d0a138216b 100644 --- a/lcl/interfaces/gtk3/gtk3widgets.pas +++ b/lcl/interfaces/gtk3/gtk3widgets.pas @@ -6754,7 +6754,7 @@ begin // PGtkEventBox(Result)^.set_visible_window(True); end; g_object_unref(ListStore); - + PGtkComboBox(Result)^.set_id_column(0); end; function TGtk3ComboBox.EatArrowKeys(const AKey: Word): Boolean; @@ -6764,15 +6764,29 @@ end; function TGtk3ComboBox.getText: String; begin - Result := inherited getText; - if Gtk3IsComboBox(GetContainerWidget) then - Result := StrPas(PGtkComboBox(GetContainerWidget)^.get_title); + Result := ''; + if Gtk3IsComboBox(GetContainerWidget) then begin + with PGtkComboBox(GetContainerWidget)^ do begin + if has_entry then begin + Result := StrPas(PGtkEntry(get_child)^.Text); + end else begin + Result := active_id; + end; + end; + end; end; procedure TGtk3ComboBox.setText(const AValue: String); begin - if Gtk3IsComboBox(FWidget) then - PGtkComboBox(GetContainerWidget)^.set_title(PgChar(AValue)); + if Gtk3IsComboBox(GetContainerWidget) then begin + with PGtkComboBox(GetContainerWidget)^ do begin + if has_entry then begin + PGtkEntry(get_child)^.Text := Pgchar(AValue); + end else begin + //active_id := Pgchar(AValue); TODO: Wait until property becomes writeble + end; + end; + end; end; procedure TGtk3ComboBox.DumpPrivateStructValues(const ADbgEvent: String);