mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-03 20:47:09 +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
|
var
|
||||||
obj: NSObject;
|
obj: NSObject;
|
||||||
begin
|
begin
|
||||||
// sanity check
|
if not AWinControl.HandleAllocated then
|
||||||
|
Exit;
|
||||||
obj := NSObject(AWinControl.Handle);
|
obj := NSObject(AWinControl.Handle);
|
||||||
if not Assigned(obj) or not obj.isKindOfClass_(NSControl) then Exit;
|
if obj.isKindOfClass_(NSControl) then
|
||||||
|
|
||||||
SetNSControlValue(NSControl(obj), AText);
|
SetNSControlValue(NSControl(obj), AText);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -495,15 +495,13 @@ class function TCocoaWSWinControl.GetText(const AWinControl: TWinControl; var AT
|
|||||||
var
|
var
|
||||||
obj: NSObject;
|
obj: NSObject;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result := AWinControl.HandleAllocated;
|
||||||
|
if not Result then
|
||||||
// sanity check
|
Exit;
|
||||||
obj := NSObject(AWinControl.Handle);
|
obj := NSObject(AWinControl.Handle);
|
||||||
Result:=Assigned(obj) and obj.isKindOfClass_(NSControl);
|
Result := obj.isKindOfClass_(NSControl);
|
||||||
if not Result then Exit;
|
if Result then
|
||||||
|
|
||||||
AText := GetNSControlValue(NSControl(obj));
|
AText := GetNSControlValue(NSControl(obj));
|
||||||
Result:=true;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaWSWinControl.GetTextLen(const AWinControl: TWinControl; var ALength: Integer): Boolean;
|
class function TCocoaWSWinControl.GetTextLen(const AWinControl: TWinControl; var ALength: Integer): Boolean;
|
||||||
@ -511,16 +509,19 @@ var
|
|||||||
obj: NSObject;
|
obj: NSObject;
|
||||||
s: NSString;
|
s: NSString;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result := AWinControl.HandleAllocated;
|
||||||
|
if not Result then
|
||||||
|
Exit;
|
||||||
|
|
||||||
// sanity check
|
|
||||||
obj := NSObject(AWinControl.Handle);
|
obj := NSObject(AWinControl.Handle);
|
||||||
Result:= Assigned(obj) and obj.isKindOfClass_(NSControl);
|
Result := obj.isKindOfClass_(NSControl);
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
|
|
||||||
s := NSControl(obj).stringValue;
|
s := NSControl(obj).stringValue;
|
||||||
if Assigned(s) then ALength:=s.length
|
if Assigned(s) then
|
||||||
else ALength:=0
|
ALength := s.length
|
||||||
|
else
|
||||||
|
ALength := 0
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaWSWinControl.GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean;
|
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);
|
class procedure TCocoaWSWinControl.SetFont(const AWinControl: TWinControl; const AFont: TFont);
|
||||||
var
|
var
|
||||||
Obj: NSObject;
|
Obj: NSObject;
|
||||||
|
Cell: NSCell;
|
||||||
|
Str: NSAttributedString;
|
||||||
|
NewStr: NSMutableAttributedString;
|
||||||
|
Dict: NSDictionary;
|
||||||
|
Range: NSRange;
|
||||||
begin
|
begin
|
||||||
if (AWinControl.Handle <> 0) then
|
if (AWinControl.HandleAllocated) then
|
||||||
begin
|
begin
|
||||||
Obj := NSObject(AWinControl.Handle);
|
Obj := NSObject(AWinControl.Handle);
|
||||||
|
if Obj.isKindOfClass(NSScrollView) then
|
||||||
|
Obj := NSScrollView(Obj).documentView;
|
||||||
if Obj.isKindOfClass(NSControl) then
|
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;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user