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.
This commit is contained in:
Abou Al Montacir 2024-01-31 11:19:26 +01:00
parent e45713b7f8
commit 93f05421b2

View File

@ -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);