View Issue Details

IDProjectCategoryView StatusLast Update
0036313LazarusWidgetsetpublic2019-12-05 23:08
ReporterTKAssigned ToDmitry Boyarintsev 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.1 (SVN)Product Build 
Target VersionFixed in Version 
Summary0036313: TEdit - cannot change text (font) color
DescriptionThere is still no support for TEdit.Font.Color in Cocoa (I could only set this at design time but not reflected at runtime, etc.).
Probably because that color is not bound to the NSFont itself (or device context as in Windows) but rather to the NSText control.
I made a simple patch that adds this support.
Not tested with TMemo etc., just TEdit.
TagsNo tags attached.
Fixed in Revision62251
LazTarget-
WidgetsetCocoa
Attached Files
  • cocoa_tedit_text_color.diff (2,883 bytes)
    Index: lcl/include/customedit.inc
    ===================================================================
    --- lcl/include/customedit.inc	(revision 62230)
    +++ lcl/include/customedit.inc	(working copy)
    @@ -50,6 +50,7 @@
       TWSCustomEditClass(WidgetSetClass).SetCaretPos(Self, fCaretPos);
       TWSCustomEditClass(WidgetSetClass).SetSelStart(Self, FSelStart);
       TWSCustomEditClass(WidgetSetClass).SetSelLength(Self, FSelLength);
    +  TWSCustomEditClass(WidgetSetClass).SetTextColor(Self, Font.Color);
       if WidgetSet.GetLCLCapability(lcTextHint) = LCL_CAPABILITY_YES then
         TWSCustomEditClass(WidgetSetClass).SetTextHint(Self, FTextHint)
       else
    @@ -679,6 +680,7 @@
     var
       HintFont: TObject;
     begin
    +  TWSCustomEditClass(WidgetSetClass).SetTextColor(Self, Font.Color);
       if (FEmulatedTextHintStatus=thsHidden) then
         inherited FontChanged(Sender)
       else
    Index: lcl/interfaces/cocoa/cocoawsstdctrls.pas
    ===================================================================
    --- lcl/interfaces/cocoa/cocoawsstdctrls.pas	(revision 62230)
    +++ lcl/interfaces/cocoa/cocoawsstdctrls.pas	(working copy)
    @@ -156,6 +156,7 @@
         class procedure Undo(const ACustomEdit: TCustomEdit); override;
     
         class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
    +    class procedure SetTextColor(const ACustomEdit: TCustomEdit; const ATextColor: TColor); override;
       end;
       
       { TCocoaMemoStrings }
    @@ -1145,6 +1146,16 @@
       end;
     end;
     
    +class procedure TCocoaWSCustomEdit.SetTextColor(const ACustomEdit: TCustomEdit; const ATextColor: TColor);
    +var
    +  lHandle: TCocoaTextField;
    +begin
    +  lHandle := GetTextField(ACustomEdit);
    +  if not Assigned(lHandle) then Exit;
    +
    +  lHandle.setTextColor(ColorToNSColor(ColorToRGB(ATextColor)));
    +end;
    +
     { TCocoaMemoStrings }
     
     function LineBreaksToUnix(const src: string): string;
    Index: lcl/widgetset/wsstdctrls.pp
    ===================================================================
    --- lcl/widgetset/wsstdctrls.pp	(revision 62230)
    +++ lcl/widgetset/wsstdctrls.pp	(working copy)
    @@ -160,6 +160,7 @@
         class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); virtual;
         class procedure SetSelText(const ACustomEdit: TCustomEdit; const NewSelText: string); virtual;
         class procedure SetTextHint(const ACustomEdit: TCustomEdit; const ATextHint: string); virtual;
    +    class procedure SetTextColor(const ACustomEdit: TCustomEdit; const ATextColor: TColor); virtual;
         class function CreateEmulatedTextHintFont(const ACustomEdit: TCustomEdit): TFont; virtual;
     
         class procedure Cut(const ACustomEdit: TCustomEdit); virtual;
    @@ -567,6 +568,10 @@
     begin
     end;
     
    +class procedure TWSCustomEdit.SetTextColor(const ACustomEdit: TCustomEdit; const ATextColor: TColor);
    +begin
    +end;
    +
     class procedure TWSCustomEdit.SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer);
     begin
     end;
    

Activities

TK

2019-11-13 21:04

reporter  

cocoa_tedit_text_color.diff (2,883 bytes)
Index: lcl/include/customedit.inc
===================================================================
--- lcl/include/customedit.inc	(revision 62230)
+++ lcl/include/customedit.inc	(working copy)
@@ -50,6 +50,7 @@
   TWSCustomEditClass(WidgetSetClass).SetCaretPos(Self, fCaretPos);
   TWSCustomEditClass(WidgetSetClass).SetSelStart(Self, FSelStart);
   TWSCustomEditClass(WidgetSetClass).SetSelLength(Self, FSelLength);
+  TWSCustomEditClass(WidgetSetClass).SetTextColor(Self, Font.Color);
   if WidgetSet.GetLCLCapability(lcTextHint) = LCL_CAPABILITY_YES then
     TWSCustomEditClass(WidgetSetClass).SetTextHint(Self, FTextHint)
   else
@@ -679,6 +680,7 @@
 var
   HintFont: TObject;
 begin
+  TWSCustomEditClass(WidgetSetClass).SetTextColor(Self, Font.Color);
   if (FEmulatedTextHintStatus=thsHidden) then
     inherited FontChanged(Sender)
   else
Index: lcl/interfaces/cocoa/cocoawsstdctrls.pas
===================================================================
--- lcl/interfaces/cocoa/cocoawsstdctrls.pas	(revision 62230)
+++ lcl/interfaces/cocoa/cocoawsstdctrls.pas	(working copy)
@@ -156,6 +156,7 @@
     class procedure Undo(const ACustomEdit: TCustomEdit); override;
 
     class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
+    class procedure SetTextColor(const ACustomEdit: TCustomEdit; const ATextColor: TColor); override;
   end;
   
   { TCocoaMemoStrings }
@@ -1145,6 +1146,16 @@
   end;
 end;
 
+class procedure TCocoaWSCustomEdit.SetTextColor(const ACustomEdit: TCustomEdit; const ATextColor: TColor);
+var
+  lHandle: TCocoaTextField;
+begin
+  lHandle := GetTextField(ACustomEdit);
+  if not Assigned(lHandle) then Exit;
+
+  lHandle.setTextColor(ColorToNSColor(ColorToRGB(ATextColor)));
+end;
+
 { TCocoaMemoStrings }
 
 function LineBreaksToUnix(const src: string): string;
Index: lcl/widgetset/wsstdctrls.pp
===================================================================
--- lcl/widgetset/wsstdctrls.pp	(revision 62230)
+++ lcl/widgetset/wsstdctrls.pp	(working copy)
@@ -160,6 +160,7 @@
     class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); virtual;
     class procedure SetSelText(const ACustomEdit: TCustomEdit; const NewSelText: string); virtual;
     class procedure SetTextHint(const ACustomEdit: TCustomEdit; const ATextHint: string); virtual;
+    class procedure SetTextColor(const ACustomEdit: TCustomEdit; const ATextColor: TColor); virtual;
     class function CreateEmulatedTextHintFont(const ACustomEdit: TCustomEdit): TFont; virtual;
 
     class procedure Cut(const ACustomEdit: TCustomEdit); virtual;
@@ -567,6 +568,10 @@
 begin
 end;
 
+class procedure TWSCustomEdit.SetTextColor(const ACustomEdit: TCustomEdit; const ATextColor: TColor);
+begin
+end;
+
 class procedure TWSCustomEdit.SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer);
 begin
 end;

Dmitry Boyarintsev

2019-11-17 05:05

developer   ~0119350

please test and close if ok

Issue History

Date Modified Username Field Change
2019-11-13 21:04 TK New Issue
2019-11-13 21:04 TK File Added: cocoa_tedit_text_color.diff
2019-11-13 22:11 Bart Broersma Category LCL => Widgetset
2019-11-13 22:11 Bart Broersma LazTarget => -
2019-11-13 22:11 Bart Broersma Widgetset Cocoa => Cocoa
2019-11-17 05:05 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2019-11-17 05:05 Dmitry Boyarintsev Status new => resolved
2019-11-17 05:05 Dmitry Boyarintsev Resolution open => fixed
2019-11-17 05:05 Dmitry Boyarintsev Fixed in Revision => 62251
2019-11-17 05:05 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2019-11-17 05:05 Dmitry Boyarintsev Note Added: 0119350
2019-12-05 23:08 TK Status resolved => closed