mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-26 20:04:00 +02:00
gtk: use more generic code to set menuitem shortcuts and caption, redo SetLabelCaption for gtk2
git-svn-id: trunk@20027 -
This commit is contained in:
parent
ed614cee3c
commit
8ed7281c00
@ -74,6 +74,10 @@ type
|
||||
function GetDeviceContextClass: TGtkDeviceContextClass; override;
|
||||
public
|
||||
procedure SetWidgetFont(const AWidget: PGtkWidget; const AFont: TFont); override;
|
||||
procedure SetLabelCaption(const ALabel: PGtkLabel; const ACaption: String;
|
||||
const AComponent: TComponent = nil;
|
||||
const ASignalWidget: PGTKWidget = nil;
|
||||
const ASignal: PChar = nil); override;
|
||||
end;
|
||||
|
||||
var
|
||||
|
@ -54,3 +54,25 @@ begin
|
||||
windowstyle^.font := Pointer(FontGdiObject^.GdiFontObject);
|
||||
gtk_widget_set_style(aWidget, windowStyle);
|
||||
end;
|
||||
|
||||
procedure TGtk1WidgetSet.SetLabelCaption(const ALabel: PGtkLabel; const ACaption: String;
|
||||
const AComponent: TComponent = nil; const ASignalWidget: PGTKWidget = nil;
|
||||
const ASignal: PChar = nil);
|
||||
var
|
||||
Caption, Pattern: String;
|
||||
AccelKey: Char;
|
||||
begin
|
||||
Caption := ACaption;
|
||||
LabelFromAmpersands(Caption, Pattern, AccelKey);
|
||||
gtk_label_set_text(ALabel, PChar(Caption));
|
||||
gtk_label_set_pattern(ALabel, PChar(Pattern));
|
||||
|
||||
if AComponent = nil then Exit;
|
||||
if ASignalWidget = nil then Exit;
|
||||
if ASignal = '' then Exit;
|
||||
|
||||
// update the Accelerator
|
||||
if AccelKey = #0
|
||||
then Accelerate(AComponent, ASignalWidget, GDK_VOIDSYMBOL, 0, ASignal)
|
||||
else Accelerate(AComponent, ASignalWidget, Ord(AccelKey), 0, ASignal);
|
||||
end;
|
||||
|
@ -233,9 +233,9 @@ type
|
||||
// for gtk specific components:
|
||||
procedure SetLabelCaption(const ALabel: PGtkLabel; const ACaption: String
|
||||
{$IFDEF Gtk1}
|
||||
; const AComponent: TComponent;
|
||||
const ASignalWidget: PGTKWidget;
|
||||
const ASignal: PChar{$ENDIF}); virtual;
|
||||
; const AComponent: TComponent = nil;
|
||||
const ASignalWidget: PGTKWidget = nil;
|
||||
const ASignal: PChar = nil{$ENDIF}); virtual; abstract;
|
||||
procedure SetWidgetColor(const AWidget : PGtkWidget;
|
||||
const FGColor,BGColor : TColor;
|
||||
const Mask : tGtkStateEnum);
|
||||
|
@ -5861,39 +5861,12 @@ var
|
||||
procedure SetMenuItemLabelText(LCLMenuItem: TMenuItem;
|
||||
MenuItemWidget: PGtkWidget);
|
||||
var
|
||||
s: string;
|
||||
LabelWidget: PGtkLabel;
|
||||
ShortCutPos: Integer;
|
||||
{$ifdef gtk1}
|
||||
pattern: String;
|
||||
{$endif}
|
||||
begin
|
||||
if (MenuItemWidget = nil) or (LCLMenuItem = nil) then
|
||||
Exit;
|
||||
LabelWidget := gtk_object_get_data(PGtkObject(MenuItemWidget), 'LCLLabel');
|
||||
s := LCLMenuItem.Caption;
|
||||
//Check for a shortcut key
|
||||
ShortCutPos := pos('&', s);
|
||||
if ShortCutPos > 0 then
|
||||
begin
|
||||
{$ifdef gtk1}
|
||||
System.Delete(s, ShortCutPos, 1);
|
||||
gtk_label_set_text(LabelWidget, PChar(s));
|
||||
pattern := StringOfChar(' ', ShortCutPos - 1) + '_';
|
||||
gtk_label_set_pattern(LabelWidget, PChar(pattern));
|
||||
{$else}
|
||||
// replace all _ with __ to correctly set mnemonic
|
||||
s := StringReplace(s, '_', '__', [rfReplaceAll]);
|
||||
// replace & with _ => this is how gtk understand mnemonic
|
||||
s := StringReplace(s, '&', '_', []);
|
||||
gtk_label_set_text_with_mnemonic(LabelWidget, PChar(s));
|
||||
{$endif}
|
||||
end
|
||||
else
|
||||
begin
|
||||
gtk_label_set_text(LabelWidget, PChar(s));
|
||||
gtk_label_set_pattern(LabelWidget, #0); // Ensure any underlines removed
|
||||
end;
|
||||
GtkWidgetset.SetLabelCaption(LabelWidget, LCLMenuItem.Caption);
|
||||
end;
|
||||
|
||||
procedure UpdateShortCutLabel;
|
||||
|
@ -785,7 +785,7 @@ implementation
|
||||
|
||||
uses
|
||||
{$IFDEF StaticXinerama} Xinerama, {$ENDIF}
|
||||
dynlibs, GtkWSPrivate, URIParser;
|
||||
dynlibs, GtkWSPrivate, URIParser, GtkInt;
|
||||
|
||||
const
|
||||
KCINFO_FLAG_SHIFT = $01;
|
||||
|
@ -998,45 +998,6 @@ begin
|
||||
SendCachedGtkResizeNotifications;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TGtkWidgetSet.SetLabelCaption
|
||||
Params: ALabel: The label to set the caption for
|
||||
ACaption: The caption to set
|
||||
AComponent: The component the label belongs to
|
||||
ASignalWidget: A widget to connect the accelerator to
|
||||
ASignal: The signal to connect
|
||||
Returns: Nothing
|
||||
|
||||
Sets the Caption of a gtklabel. If a accelerator is present, it is connected.
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TGtkWidgetSet.SetLabelCaption(const ALabel: PGtkLabel;
|
||||
const ACaption: String
|
||||
{$IFDEF Gtk1}
|
||||
; const AComponent: TComponent;
|
||||
const ASignalWidget: PGTKWidget; const ASignal: PChar
|
||||
{$ENDIF});
|
||||
var
|
||||
Caption, Pattern: String;
|
||||
AccelKey: Char;
|
||||
begin
|
||||
Caption := ACaption;
|
||||
LabelFromAmpersands(Caption, Pattern, AccelKey);
|
||||
//DebugLn(['TGtkWidgetSet.SetLabelCaption ',GetWidgetDebugReport(PGtkWIdget(ALabel)),' Caption=',dbgstr(Caption),' Pattern=',dbgstr(Pattern),' aCaption=',dbgstr(aCaption)]);
|
||||
gtk_label_set_text(ALabel, PChar(Caption));
|
||||
gtk_label_set_pattern(ALabel, PChar(Pattern));
|
||||
|
||||
{$IFDEF Gtk1}
|
||||
if AComponent = nil then Exit;
|
||||
if ASignalWidget = nil then Exit;
|
||||
if ASignal = '' then Exit;
|
||||
|
||||
// update the Accelerator
|
||||
if AccelKey = #0
|
||||
then Accelerate(AComponent, ASignalWidget, GDK_VOIDSYMBOL, 0, ASignal)
|
||||
else Accelerate(AComponent, ASignalWidget, Ord(AccelKey), 0, ASignal);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{
|
||||
Changes some colors of the widget style
|
||||
|
||||
|
@ -67,6 +67,7 @@ type
|
||||
function AppHandle: THandle; override;
|
||||
|
||||
procedure SetCallbackEx(const AMsg: LongInt; const AGTKObject: PGTKObject; const ALCLObject: TObject; Direct: boolean);override;
|
||||
procedure SetLabelCaption(const ALabel: PGtkLabel; const ACaption: String); override;
|
||||
procedure SetSelectionMode(Sender: TObject; Widget: PGtkWidget;
|
||||
MultiSelect, ExtendedSelect: boolean); override;
|
||||
procedure SetWidgetFont(const AWidget: PGtkWidget; const AFont: TFont); override;
|
||||
|
@ -418,6 +418,34 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TGtk2WidgetSet.SetLabelCaption(const ALabel: PGtkLabel;
|
||||
const ACaption: String);
|
||||
var
|
||||
s: String;
|
||||
i: Integer;
|
||||
begin
|
||||
s := '';
|
||||
i := 1;
|
||||
while i <= Length(ACaption) do
|
||||
begin
|
||||
case ACaption[i] of
|
||||
'_': s := s + '__';
|
||||
'&':
|
||||
if (i < Length(ACaption)) and (ACaption[i + 1] = '&') then
|
||||
begin
|
||||
s := s + '&';
|
||||
inc(i);
|
||||
end
|
||||
else
|
||||
s := s + '_';
|
||||
else
|
||||
s := s + ACaption[i];
|
||||
end;
|
||||
inc(i);
|
||||
end;
|
||||
gtk_label_set_text_with_mnemonic(ALabel, PChar(s));
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
procedure TGtk2WidgetSet.SetSelectionMode(Sender: TObject; Widget: PGtkWidget;
|
||||
MultiSelect, ExtendedSelect: boolean);
|
||||
|
Loading…
Reference in New Issue
Block a user