cocoa: update change text edit font color. bug #36313

git-svn-id: trunk@62251 -
This commit is contained in:
dmitry 2019-11-17 04:04:57 +00:00
parent e4c13cf957
commit 968577d0f0
2 changed files with 35 additions and 29 deletions

View File

@ -1693,41 +1693,29 @@ var
Cell: NSCell;
Str: NSAttributedString;
NewStr: NSMutableAttributedString;
Dict: NSDictionary;
Range: NSRange;
begin
if (AWinControl.HandleAllocated) then
if not (AWinControl.HandleAllocated) then Exit;
Obj := NSObject(AWinControl.Handle).lclContentView;
if Obj.isKindOfClass(NSControl) then
begin
Obj := NSObject(AWinControl.Handle);
if Obj.isKindOfClass(NSScrollView) then
Obj := NSScrollView(Obj).documentView;
if Obj.isKindOfClass(NSControl) then
Cell := NSCell(NSControl(Obj).cell);
Cell.setFont(TCocoaFont(AFont.Reference.Handle).Font);
// try to assign foreground color?
Str := Cell.attributedStringValue;
if Assigned(Str) then
begin
Cell := NSCell(NSControl(Obj).cell);
Cell.setFont(TCocoaFont(AFont.Reference.Handle).Font);
// try to assign foreground color?
Str := Cell.attributedStringValue;
if Assigned(Str) then
begin
NewStr := NSMutableAttributedString.alloc.initWithAttributedString(Str);
Range.location := 0;
Range.length := NewStr.length;
if AFont.Color = clDefault then
NewStr.removeAttribute_range(NSForegroundColorAttributeName, Range)
else
NewStr.addAttribute_value_range(NSForegroundColorAttributeName, ColorToNSColor(ColorToRGB(AFont.Color)), Range);
Cell.setAttributedStringValue(NewStr);
NewStr.release;
end;
end
else
if Obj.isKindOfClass(NSText) then
begin
NSText(Obj).setFont(TCocoaFont(AFont.Reference.Handle).Font);
NewStr := NSMutableAttributedString.alloc.initWithAttributedString(Str);
Range.location := 0;
Range.length := NewStr.length;
if AFont.Color = clDefault then
NSText(Obj).setTextColor(nil)
NewStr.removeAttribute_range(NSForegroundColorAttributeName, Range)
else
NSText(Obj).setTextColor(ColorToNSColor(ColorToRGB(AFont.Color)));
NewStr.addAttribute_value_range(NSForegroundColorAttributeName, ColorToNSColor(ColorToRGB(AFont.Color)), Range);
Cell.setAttributedStringValue(NewStr);
NewStr.release;
end;
end;
end;

View File

@ -135,6 +135,7 @@ type
// WSControl functions
class procedure SetColor(const AWinControl: TWinControl); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
// WSEdit functions
@ -958,6 +959,23 @@ begin
field.setBackgroundColor( ColorToNSColor(ColorToRGB(AWinControl.Color)));
end;
class procedure TCocoaWSCustomEdit.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
var
field: TCocoaTextField;
begin
if not AWinControl.HandleAllocated or not Assigned(AFont) then Exit;
TCocoaWSWinControl.SetFont(AWinControl, AFont);
field := GetTextField(AWinControl);
if not Assigned(field) then Exit;
if AFont.Color = clDefault then
field.setTextColor(nil)
else
field.setTextColor(ColorToNSColor(ColorToRGB(AFont.Color)));
end;
class procedure TCocoaWSCustomEdit.SetBorderStyle(
const AWinControl: TWinControl; const ABorderStyle: TBorderStyle);
var