From 3164be0b8b0d7f4bf357b2af4c271ca7ab17d365 Mon Sep 17 00:00:00 2001 From: ondrej Date: Wed, 17 Jan 2018 07:22:45 +0000 Subject: [PATCH] IDE: identifier completion window: use editor settings to (dis)allow font highlighting git-svn-id: trunk@57105 - --- ide/sourceeditor.pp | 11 +++++----- ide/sourceeditprocs.pas | 47 +++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index efeaa3b37a..d045985b01 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -2355,6 +2355,7 @@ var MaxX: Integer; t: TCompletionType; hl: TSynCustomHighlighter; + Colors: TPaintCompletionItemColors; begin with ACanvas do begin if (Editor<>nil) then @@ -2364,11 +2365,9 @@ begin Font.Name:=EditorOpts.EditorFont; end; Font.Style:=[]; - if not ItemSelected then - Font.Color := FActiveEditDefaultFGColor - else - Font.Color := FActiveEditSelectedFGColor; end; + Colors.FontColor := FActiveEditDefaultFGColor; + Colors.SelectedFontColor := FActiveEditSelectedFGColor; MaxX:=TheForm.ClientWidth; t:=CurrentCompletionType; if Manager.ActiveCompletionPlugin<>nil then @@ -2383,7 +2382,7 @@ begin hl := nil; if Editor <> nil then hl := Editor.Highlighter; - PaintCompletionItem(AKey, ACanvas, X, Y, MaxX, ItemSelected, Index, self, t, hl); + PaintCompletionItem(AKey, ACanvas, X, Y, MaxX, ItemSelected, Index, self, t, hl, @Colors); Result:=true; end; @@ -2418,7 +2417,7 @@ begin end; end; Result := PaintCompletionItem(AKey,ACanvas,0,0,MaxX,ItemSelected,Index, - self,t,nil,True); + self,t,nil,nil,True); Result.Y:=FontHeight; end; diff --git a/ide/sourceeditprocs.pas b/ide/sourceeditprocs.pas index 3d618b0214..28da934d80 100644 --- a/ide/sourceeditprocs.pas +++ b/ide/sourceeditprocs.pas @@ -97,11 +97,18 @@ type icvNone ); + TPaintCompletionItemColors = record + FontColor: TColor; + SelectedFontColor: TColor; + end; + PPaintCompletionItemColors = ^TPaintCompletionItemColors; + // completion form and functions function PaintCompletionItem(const AKey: string; ACanvas: TCanvas; X, Y, MaxX: integer; ItemSelected: boolean; Index: integer; {%H-}aCompletion : TSynCompletion; CurrentCompletionType: TCompletionType; - Highlighter: TSrcIDEHighlighter; MeasureOnly: Boolean = False): TPoint; + Highlighter: TSrcIDEHighlighter; Colors: PPaintCompletionItemColors; + MeasureOnly: Boolean = False): TPoint; function GetIdentCompletionValue(aCompletion : TSynCompletion; AddChar: TUTF8Char; @@ -124,10 +131,11 @@ begin FreeAndNil(TextConverterToolClasses); end; -function PaintCompletionItem(const AKey: string; ACanvas: TCanvas; - X, Y, MaxX: integer; ItemSelected: boolean; Index: integer; - aCompletion : TSynCompletion; CurrentCompletionType: TCompletionType; - Highlighter: TSrcIDEHighlighter; MeasureOnly: Boolean): TPoint; +function PaintCompletionItem(const AKey: string; ACanvas: TCanvas; X, Y, + MaxX: integer; ItemSelected: boolean; Index: integer; + aCompletion: TSynCompletion; CurrentCompletionType: TCompletionType; + Highlighter: TSrcIDEHighlighter; Colors: PPaintCompletionItemColors; + MeasureOnly: Boolean): TPoint; const HintModifierImage: array[TPascalHintModifier] of String = ( @@ -145,6 +153,7 @@ var TokenStart: Integer; BackgroundColor: TColorRef; ForegroundColor: TColorRef; + AllowFontColor: Boolean; procedure SetFontColor(NewColor: TColor); @@ -171,6 +180,9 @@ var GreenDiff: integer; BlueDiff: integer; begin + if not AllowFontColor then + Exit; + NewColor := TColor(ColorToRGB(NewColor)); FGRed:=(NewColor shr 16) and $ff; FGGreen:=(NewColor shr 8) and $ff; @@ -216,7 +228,7 @@ var Inc(Result.X,ACanvas.TextWidth(s)); exit; end; - if (Highlighter<>nil) and (not ItemSelected) then begin + if (Highlighter<>nil) and AllowFontColor then begin Highlighter.ResetRange; Highlighter.SetLine(s,0); while not Highlighter.GetEol do begin @@ -256,7 +268,28 @@ var HintModifier: TPascalHintModifier; HelperForNode: TCodeTreeNode; begin - ForegroundColor := ColorToRGB(ACanvas.Font.Color); + if (Colors<>nil) or MeasureOnly then + begin + if ItemSelected then + begin + ForegroundColor := Colors^.SelectedFontColor; + AllowFontColor := ForegroundColor=clNone; + if ForegroundColor=clNone then + ForegroundColor := Colors^.FontColor; + end else + begin + ForegroundColor := Colors^.FontColor; + AllowFontColor := True; + end; + end else + begin + ForegroundColor := clBlack; + AllowFontColor := True; + end; + + ForegroundColor := ColorToRGB(ForegroundColor); + ACanvas.Font.Color := ForegroundColor; + Result.X := 0; Result.Y := ACanvas.TextHeight('W'); if CurrentCompletionType=ctIdentCompletion then begin