From 93f05421b2b340a13bec3e77edf3203e49b8c768 Mon Sep 17 00:00:00 2001 From: Abou Al Montacir Date: Wed, 31 Jan 2024 11:19:26 +0100 Subject: [PATCH] GTK3: Enable showing hot key in page control widgets caption. We store the raw caption in the `Text` field and convert ampersands (`&`) to underscores (`_`) before using `set_markup_with_mnemonic` to update the label text while honoring the hot key definition. NB: The underscore will be drawn only if user hits `alt` key which is a Gnome/Gtk3 feature. This fix is related to #40713. --- lcl/interfaces/gtk3/gtk3widgets.pas | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lcl/interfaces/gtk3/gtk3widgets.pas b/lcl/interfaces/gtk3/gtk3widgets.pas index d0a138216b..6cce5e3f91 100644 --- a/lcl/interfaces/gtk3/gtk3widgets.pas +++ b/lcl/interfaces/gtk3/gtk3widgets.pas @@ -373,7 +373,6 @@ type FPageLabel: PGtkLabel; protected procedure setText(const AValue: String); override; - function getText: String; override; function CreateWidget(const Params: TCreateParams):PGtkWidget; override; procedure DestroyWidget; override; public @@ -4501,21 +4500,14 @@ procedure TGtk3Page.setText(const AValue: String); var bs:string; begin + inherited; if Assigned(FPageLabel) then begin bs:=ReplaceAmpersandsWithUnderscores(Avalue); - FPageLabel^.set_text(PChar(bs)); + FPageLabel^.set_markup_with_mnemonic(PChar(bs)); end; end; -function TGtk3Page.getText: String; -begin - if Assigned(FPageLabel) then - Result := FPageLabel^.get_text - else - Result := ''; -end; - function TGtk3Page.CreateWidget(const Params: TCreateParams): PGtkWidget; begin FWidgetType := FWidgetType + [wtContainer]; @@ -7588,6 +7580,7 @@ begin FWidgetType := [wtWidget, wtLayout, wtScrollingWin, wtCustomControl] end; Result^.set_size_request(Params.Width, Params.Height); + Text := Params.Caption; FBox := TGtkVBox.new(GTK_ORIENTATION_VERTICAL, 0);