mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-03 21:07:35 +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
@ -351,16 +351,16 @@ end;
|
|||||||
|
|
||||||
function NSStringToString(ns: NSString): String;
|
function NSStringToString(ns: NSString): String;
|
||||||
begin
|
begin
|
||||||
Result:=CFStringToStr(CFStringRef(ns));
|
Result := CFStringToStr(CFStringRef(ns));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetNSText(text: NSText; const s: String); inline;
|
procedure SetNSText(text: NSText; const s: String); inline;
|
||||||
var
|
var
|
||||||
ns : NSString;
|
ns: NSString;
|
||||||
begin
|
begin
|
||||||
if Assigned(text) then
|
if Assigned(text) then
|
||||||
begin
|
begin
|
||||||
ns:=NSStringUTF8(s);
|
ns := NSStringUTF8(s);
|
||||||
text.setString(ns);
|
text.setString(ns);
|
||||||
ns.release;
|
ns.release;
|
||||||
end;
|
end;
|
||||||
@ -371,16 +371,16 @@ begin
|
|||||||
if Assigned(text) then
|
if Assigned(text) then
|
||||||
Result := NSStringToString(text.string_)
|
Result := NSStringToString(text.string_)
|
||||||
else
|
else
|
||||||
Result:='';
|
Result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetNSControlValue(c: NSControl; const S: String); inline;
|
procedure SetNSControlValue(c: NSControl; const S: String); inline;
|
||||||
var
|
var
|
||||||
ns : NSString;
|
ns: NSString;
|
||||||
begin
|
begin
|
||||||
if Assigned(c) then
|
if Assigned(c) then
|
||||||
begin
|
begin
|
||||||
ns:=NSStringUtf8(S);
|
ns := NSStringUtf8(S);
|
||||||
c.setStringValue(ns);
|
c.setStringValue(ns);
|
||||||
ns.release;
|
ns.release;
|
||||||
end;
|
end;
|
||||||
@ -389,9 +389,9 @@ end;
|
|||||||
function GetNSControlValue(c: NSControl): String; inline;
|
function GetNSControlValue(c: NSControl): String; inline;
|
||||||
begin
|
begin
|
||||||
if Assigned(c) then
|
if Assigned(c) then
|
||||||
Result:=NSStringToString(c.stringValue)
|
Result := NSStringToString(c.stringValue)
|
||||||
else
|
else
|
||||||
Result:='';
|
Result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -399,7 +399,7 @@ end;
|
|||||||
|
|
||||||
function NSLCLDebugExtension.lclClassName: shortstring;
|
function NSLCLDebugExtension.lclClassName: shortstring;
|
||||||
begin
|
begin
|
||||||
Result:=NSStringToString(self.className);
|
Result := NSStringToString(self.className);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
|||||||
@ -477,50 +477,51 @@ end;
|
|||||||
class function TCocoaWSWinControl.CreateHandle(const AWinControl: TWinControl;
|
class function TCocoaWSWinControl.CreateHandle(const AWinControl: TWinControl;
|
||||||
const AParams: TCreateParams): TLCLIntfHandle;
|
const AParams: TCreateParams): TLCLIntfHandle;
|
||||||
begin
|
begin
|
||||||
Result:=TCocoaWSCustomControl.CreateHandle(AWinControl, AParams);
|
Result := TCocoaWSCustomControl.CreateHandle(AWinControl, AParams);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCocoaWSWinControl.SetText(const AWinControl: TWinControl; const AText: String);
|
class procedure TCocoaWSWinControl.SetText(const AWinControl: TWinControl; const AText: String);
|
||||||
var
|
var
|
||||||
obj : NSObject;
|
obj: NSObject;
|
||||||
begin
|
begin
|
||||||
// sanity check
|
if not AWinControl.HandleAllocated then
|
||||||
obj:=NSObject(AWinControl.Handle);
|
Exit;
|
||||||
if not Assigned(obj) or not obj.isKindOfClass_(NSControl) then Exit;
|
obj := NSObject(AWinControl.Handle);
|
||||||
|
if obj.isKindOfClass_(NSControl) then
|
||||||
SetNSControlValue(NSControl(obj), AText);
|
SetNSControlValue(NSControl(obj), AText);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaWSWinControl.GetText(const AWinControl: TWinControl; var AText: String): Boolean;
|
class function TCocoaWSWinControl.GetText(const AWinControl: TWinControl; var AText: String): Boolean;
|
||||||
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;
|
||||||
var
|
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 := obj.isKindOfClass_(NSControl);
|
||||||
Result:= Assigned(obj) and 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