mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 20:19:24 +02:00
LCL-Gtk3: Convert ampersands to underscores and back in captions as needed. Hints from Anton Kavalenka, issue #41220.
This commit is contained in:
parent
c97c2774da
commit
b35ba030b3
@ -304,6 +304,7 @@ function Gtk3DefaultContext: TGtk3DeviceContext;
|
|||||||
function Gtk3ScreenContext: TGtk3DeviceContext;
|
function Gtk3ScreenContext: TGtk3DeviceContext;
|
||||||
|
|
||||||
function ReplaceAmpersandsWithUnderscores(const S: string): string; inline;
|
function ReplaceAmpersandsWithUnderscores(const S: string): string; inline;
|
||||||
|
function ReplaceUnderscoresWithAmpersands(const S: string): string; inline;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -2409,12 +2410,50 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
//various routines for text , copied from gtk2.
|
//various routines for text
|
||||||
|
|
||||||
|
// LCL denotes accelerator keys by '&', while Gtk denotes them with '_'.
|
||||||
|
// LCL allows to show literal '&' by escaping (doubling) it.
|
||||||
|
// Gtk allows to show literal '_' by escaping (doubling) it.
|
||||||
|
// As the situation for LCL and Gtk is symmetric, conversion is made by generic function.
|
||||||
|
function TransformAmpersandsAndUnderscores(const S: string; const FromChar, ToChar: char): string;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
i := 1;
|
||||||
|
while i <= Length(S) do
|
||||||
|
begin
|
||||||
|
if S[i] = ToChar then
|
||||||
|
Result := Result + ToChar + ToChar
|
||||||
|
else
|
||||||
|
if S[i] = FromChar then
|
||||||
|
if i < Length(S) then
|
||||||
|
begin
|
||||||
|
if S[i + 1] = FromChar then
|
||||||
|
begin
|
||||||
|
Result := Result + FromChar;
|
||||||
|
inc(i);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := Result + ToChar;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := Result + FromChar
|
||||||
|
else
|
||||||
|
Result := Result + S[i];
|
||||||
|
inc(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function ReplaceAmpersandsWithUnderscores(const S: string): string; inline;
|
function ReplaceAmpersandsWithUnderscores(const S: string): string; inline;
|
||||||
begin
|
begin
|
||||||
Result := StringReplace(S, '_', '__', [rfReplaceAll]);
|
Result := TransformAmpersandsAndUnderscores(S, '&', '_');
|
||||||
Result := StringReplace(Result, '&', '_', [rfReplaceAll]);
|
end;
|
||||||
|
|
||||||
|
function ReplaceUnderscoresWithAmpersands(const S: string): string; inline;
|
||||||
|
begin
|
||||||
|
Result := TransformAmpersandsAndUnderscores(S, '_', '&');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{-------------------------------------------------------------------------------
|
{-------------------------------------------------------------------------------
|
||||||
|
@ -3423,7 +3423,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
if PGtkFrame(Widget)^.get_label_widget = nil then
|
if PGtkFrame(Widget)^.get_label_widget = nil then
|
||||||
exit;
|
exit;
|
||||||
Result := PGtkFrame(Widget)^.get_label;
|
Result := ReplaceUnderscoresWithAmpersands(PGtkFrame(Widget)^.get_label);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3438,7 +3438,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
if PGtkFrame(Widget)^.get_label_widget = nil then
|
if PGtkFrame(Widget)^.get_label_widget = nil then
|
||||||
PGtkFrame(Widget)^.set_label_widget(TGtkLabel.new(''));
|
PGtkFrame(Widget)^.set_label_widget(TGtkLabel.new(''));
|
||||||
PGtkFrame(Widget)^.set_label(PgChar(AValue));
|
PGtkFrame(Widget)^.set_label(PgChar(ReplaceAmpersandsWithUnderscores(AValue)));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -7029,7 +7029,7 @@ end;
|
|||||||
function TGtk3Button.getText: String;
|
function TGtk3Button.getText: String;
|
||||||
begin
|
begin
|
||||||
if IsWidgetOK then
|
if IsWidgetOK then
|
||||||
Result := PGtkButton(FWidget)^.get_label
|
Result := ReplaceUnderscoresWithAmpersands(PGtkButton(FWidget)^.get_label())
|
||||||
else
|
else
|
||||||
Result := '';
|
Result := '';
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user