mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-03 20:07:25 +01:00
cocoa: apply font color to NSControl and NSText objects
git-svn-id: trunk@34489 -
This commit is contained in:
parent
d3d7d7c4f0
commit
19e37fd59e
@ -484,10 +484,10 @@ class procedure TCocoaWSWinControl.SetText(const AWinControl: TWinControl; const
|
||||
var
|
||||
obj: NSObject;
|
||||
begin
|
||||
// sanity check
|
||||
if not AWinControl.HandleAllocated then
|
||||
Exit;
|
||||
obj := NSObject(AWinControl.Handle);
|
||||
if not Assigned(obj) or not obj.isKindOfClass_(NSControl) then Exit;
|
||||
|
||||
if obj.isKindOfClass_(NSControl) then
|
||||
SetNSControlValue(NSControl(obj), AText);
|
||||
end;
|
||||
|
||||
@ -495,15 +495,13 @@ class function TCocoaWSWinControl.GetText(const AWinControl: TWinControl; var AT
|
||||
var
|
||||
obj: NSObject;
|
||||
begin
|
||||
Result:=false;
|
||||
|
||||
// sanity check
|
||||
Result := AWinControl.HandleAllocated;
|
||||
if not Result then
|
||||
Exit;
|
||||
obj := NSObject(AWinControl.Handle);
|
||||
Result:=Assigned(obj) and obj.isKindOfClass_(NSControl);
|
||||
if not Result then Exit;
|
||||
|
||||
Result := obj.isKindOfClass_(NSControl);
|
||||
if Result then
|
||||
AText := GetNSControlValue(NSControl(obj));
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
class function TCocoaWSWinControl.GetTextLen(const AWinControl: TWinControl; var ALength: Integer): Boolean;
|
||||
@ -511,16 +509,19 @@ var
|
||||
obj: NSObject;
|
||||
s: NSString;
|
||||
begin
|
||||
Result:=false;
|
||||
Result := AWinControl.HandleAllocated;
|
||||
if not Result then
|
||||
Exit;
|
||||
|
||||
// sanity check
|
||||
obj := NSObject(AWinControl.Handle);
|
||||
Result:= Assigned(obj) and obj.isKindOfClass_(NSControl);
|
||||
Result := obj.isKindOfClass_(NSControl);
|
||||
if not Result then Exit;
|
||||
|
||||
s := NSControl(obj).stringValue;
|
||||
if Assigned(s) then ALength:=s.length
|
||||
else ALength:=0
|
||||
if Assigned(s) then
|
||||
ALength := s.length
|
||||
else
|
||||
ALength := 0
|
||||
end;
|
||||
|
||||
class function TCocoaWSWinControl.GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean;
|
||||
@ -584,12 +585,45 @@ end;
|
||||
class procedure TCocoaWSWinControl.SetFont(const AWinControl: TWinControl; const AFont: TFont);
|
||||
var
|
||||
Obj: NSObject;
|
||||
Cell: NSCell;
|
||||
Str: NSAttributedString;
|
||||
NewStr: NSMutableAttributedString;
|
||||
Dict: NSDictionary;
|
||||
Range: NSRange;
|
||||
begin
|
||||
if (AWinControl.Handle <> 0) then
|
||||
if (AWinControl.HandleAllocated) then
|
||||
begin
|
||||
Obj := NSObject(AWinControl.Handle);
|
||||
if Obj.isKindOfClass(NSScrollView) then
|
||||
Obj := NSScrollView(Obj).documentView;
|
||||
if Obj.isKindOfClass(NSControl) then
|
||||
NSCell(NSControl(Obj).cell).setFont(TCocoaFont(AFont.Reference.Handle).Font);
|
||||
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);
|
||||
if AFont.Color = clDefault then
|
||||
NSText(Obj).setTextColor(nil)
|
||||
else
|
||||
NSText(Obj).setTextColor(ColorToNSColor(ColorToRGB(AFont.Color)));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user