diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index 050ae2c3cc..82a7ef87c6 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -2916,7 +2916,7 @@ var Len, MaxLen: integer; PhysicalStartPos, PhysicalEndPos: integer; p: PChar; - FG, BG: TColor; + FG, BG, FC: TColor; Style: TFontStyles; end; dc: HDC; @@ -3135,6 +3135,7 @@ var with fTextDrawer do begin SetBackColor(TokenAccu.BG); SetForeColor(TokenAccu.FG); + SetFrameColor(TokenAccu.FC); SetStyle(TokenAccu.Style); end; // Paint the chars @@ -3188,7 +3189,7 @@ var procedure AddHighlightToken( Token: PChar; TokenLen, PhysicalStartPos, PhysicalEndPos: integer; - Foreground, Background: TColor; + Foreground, Background, FrameColor: TColor; Style: TFontStyles); var bCanAppend: boolean; @@ -3267,6 +3268,7 @@ var TokenAccu.PhysicalEndPos := PhysicalEndPos; TokenAccu.FG := Foreground; TokenAccu.BG := Background; + TokenAccu.FC := FrameColor; TokenAccu.Style := Style; end; {debugln('AddHighlightToken END bCanAppend=',dbgs(bCanAppend), @@ -3279,9 +3281,9 @@ var procedure DrawHiLightMarkupToken(attr: TSynHighlighterAttributes; sToken: PChar; nTokenByteLen: integer); var - DefaultFGCol, DefaultBGCol: TColor; + DefaultFGCol, DefaultBGCol, DefaultFCCol: TColor; DefaultStyle: TFontStyles; - BG, FG : TColor; + BG, FG, FC : TColor; Style: TFontStyles; PhysicalStartPos: integer; PhysicalEndPos: integer; @@ -3324,16 +3326,20 @@ var end; end; - if Assigned(attr) then begin - DefaultFGCol:=attr.Foreground; - DefaultBGCol:=attr.Background; - DefaultStyle:=attr.Style; + if Assigned(attr) then + begin + DefaultFGCol := attr.Foreground; + DefaultBGCol := attr.Background; + DefaultFCCol := attr.FrameColor; + DefaultStyle := attr.Style; if DefaultBGCol = clNone then DefaultBGCol := colEditorBG; if DefaultFGCol = clNone then DefaultFGCol := Font.Color; - end else begin - DefaultFGCol:=Font.Color; - DefaultBGCol:=colEditorBG; - DefaultStyle:=Font.Style; + end else + begin + DefaultFGCol := Font.Color; + DefaultBGCol := colEditorBG; + DefaultFCCol := clNone; + DefaultStyle := Font.Style; end; {TODO: cache NextPhysPos, and MarkupInfo between 2 calls } @@ -3360,10 +3366,11 @@ var // Calculate Markup BG := DefaultBGCol; FG := DefaultFGCol; + FC := DefaultFCCol; Style := DefaultStyle; MarkupInfo := fMarkupManager.GetMarkupAttributeAtRowCol(fTextView.TextIndex[CurLine]+1, PhysicalStartPos); if assigned(MarkupInfo) - then MarkupInfo.ModifyColors(FG, BG, Style); + then MarkupInfo.ModifyColors(FG, BG, FC, Style); // Deal with equal colors if (BG = FG) then begin // or if diff(gb,fg) < x if BG = DefaultBGCol @@ -3373,7 +3380,7 @@ var // Add to TokenAccu AddHighlightToken(sToken, SubTokenByteLen, - PhysicalStartPos, PhysicalEndPos, FG, BG, Style); + PhysicalStartPos, PhysicalEndPos, FG, BG, FC, Style); PhysicalStartPos:=PhysicalEndPos + 1; dec(nTokenByteLen,SubTokenByteLen); diff --git a/components/synedit/synedithighlighter.pp b/components/synedit/synedithighlighter.pp index 5777cf8185..ed595bb848 100644 --- a/components/synedit/synedithighlighter.pp +++ b/components/synedit/synedithighlighter.pp @@ -70,6 +70,8 @@ type fBackgroundDefault: TColor; //mh 2000-10-08 fForeground: TColor; fForegroundDefault: TColor; //mh 2000-10-08 + FFrameColor: TColor; + FFrameColorDefault: TColor; fName: string; fStyle: TFontStyles; fStyleDefault: TFontStyles; //mh 2000-10-08 @@ -83,9 +85,11 @@ type function GetBackgroundColorStored: boolean; function GetFontStyleMaskStored : boolean; function GetForegroundColorStored: boolean; + function GetFrameColorStored: boolean; {end} //mh 2000-10-08 procedure SetBackground(Value: TColor); procedure SetForeground(Value: TColor); + procedure SetFrameColor(const AValue: TColor); procedure SetStyle(Value: TFontStyles); function GetStyleFromInt: integer; procedure SetStyleFromInt(const Value: integer); @@ -117,6 +121,8 @@ type stored GetBackgroundColorStored; //mh 2000-10-08 property Foreground: TColor read fForeground write SetForeground stored GetForegroundColorStored; //mh 2000-10-08 + property FrameColor: TColor read FFrameColor write SetFrameColor + stored GetFrameColorStored; property Style: TFontStyles read fStyle write SetStyle //default []; stored GetFontStyleStored; //mh 2000-10-08 {$IFDEF SYN_LAZARUS} @@ -521,6 +527,10 @@ begin fForeground := src.fForeground; bChanged := TRUE; end; + if FFrameColor <> src.FFrameColor then begin + FFrameColor := src.FFrameColor; + bChanged := True; + end; if fStyle <> src.fStyle then begin fStyle := src.fStyle; bChanged := TRUE; @@ -548,6 +558,7 @@ begin inherited Create; Background := clNone; Foreground := clNone; + FFrameColor := clNone; fName := attribName; end; @@ -566,6 +577,11 @@ begin Result := fForeground <> fForegroundDefault; end; +function TSynHighlighterAttributes.GetFrameColorStored: boolean; +begin + Result := FFrameColor <> FFrameColorDefault; +end; + function TSynHighlighterAttributes.GetFontStyleStored: boolean; begin Result := fStyle <> fStyleDefault; @@ -771,6 +787,15 @@ begin end; end; +procedure TSynHighlighterAttributes.SetFrameColor(const AValue: TColor); +begin + if FFrameColor <> AValue then + begin + FFrameColor := AValue; + Changed; + end; +end; + procedure TSynHighlighterAttributes.SetStyle(Value: TFontStyles); begin if fStyle <> Value then begin diff --git a/components/synedit/syneditmarkup.pp b/components/synedit/syneditmarkup.pp index 425e81f6bf..c140fa3552 100644 --- a/components/synedit/syneditmarkup.pp +++ b/components/synedit/syneditmarkup.pp @@ -46,9 +46,11 @@ type function GetBGColor : TColor; function GetFGColor : TColor; + function GetFrameColor: TColor; function GetStyle : TFontStyles; procedure SetBGColor(const AValue : TColor); procedure SetFGColor(const AValue : TColor); + procedure SetFrameColor(const AValue : TColor); procedure SetStyle(const AValue : TFontStyles); procedure MarkupChanged(AMarkup: TObject); @@ -83,6 +85,7 @@ type property MarkupInfo : TSynSelectedColor read fMarkupInfo; property FGColor : TColor read GetFGColor; property BGColor : TColor read GetBGColor; + property FrameColor: TColor read GetFrameColor; property Style : TFontStyles read GetStyle; property Lines : TSynEditStrings read fLines write SetLines; property Caret : TPoint read fCaret write SetCaret; @@ -133,9 +136,14 @@ begin result := fMarkupInfo.Foreground; end; +function TSynEditMarkup.GetFrameColor: TColor; +begin + Result := fMarkupInfo.FrameColor; +end; + function TSynEditMarkup.GetStyle : TFontStyles; begin - result := fMarkupInfo.Style; + Result := fMarkupInfo.Style; end; procedure TSynEditMarkup.SetBGColor(const AValue : TColor); @@ -150,6 +158,12 @@ begin fMarkupInfo.Foreground := AValue; end; +procedure TSynEditMarkup.SetFrameColor(const AValue: TColor); +begin + if fMarkupInfo.FrameColor = AValue then exit; + fMarkupInfo.FrameColor := AValue; +end; + procedure TSynEditMarkup.SetStyle(const AValue : TFontStyles); begin if fMarkupInfo.Style = AValue then exit; @@ -335,6 +349,7 @@ begin end else begin if c.Background <> clNone then Result.Background := c.Background; if c.Foreground <> clNone then Result.Foreground := c.Foreground; + if c.FrameColor <> clNone then Result.FrameColor := c.FrameColor; sMask := c.StyleMask + (fsNot(c.StyleMask) * c.Style); // Styles to be taken from c Result.Style:= (Result.Style * fsNot(sMask)) + (c.Style * sMask); Result.StyleMask:= (Result.StyleMask * fsNot(sMask)) + (c.StyleMask * sMask); diff --git a/components/synedit/syneditmiscclasses.pp b/components/synedit/syneditmiscclasses.pp index 8231b5c73e..e3d449eda7 100644 --- a/components/synedit/syneditmiscclasses.pp +++ b/components/synedit/syneditmiscclasses.pp @@ -59,35 +59,31 @@ type TSynSelectedColor = class(TPersistent) private - fBG: TColor; - fFG: TColor; - fStyle: TFontStyles; - {$IFDEF SYN_LAZARUS} + FBG: TColor; + FFG: TColor; + FFrameColor: TColor; + FStyle: TFontStyles; // StyleMask = 1 => Copy Style Bits // StyleMask = 0 => Invert where Style Bit = 1 - fStyleMask: TFontStyles; - {$ENDIF} - fOnChange: TNotifyEvent; + FStyleMask: TFontStyles; + FOnChange: TNotifyEvent; procedure SetBG(Value: TColor); procedure SetFG(Value: TColor); + procedure SetFrameColor(const AValue: TColor); procedure SetStyle(const AValue : TFontStyles); - {$IFDEF SYN_LAZARUS} procedure SetStyleMask(const AValue : TFontStyles); - {$ENDIF} + procedure DoChange; public constructor Create; procedure Assign(aSource: TPersistent); override; published - {$IFDEF SYN_LAZARUS} function GetModifiedStyle(aStyle : TFontStyles): TFontStyles; - procedure ModifyColors(var aForeground, aBackground: TColor; var aStyle: TFontStyles); - {$ENDIF} - property Background: TColor read fBG write SetBG default clHighLight; - property Foreground: TColor read fFG write SetFG default clHighLightText; - property Style: TFontStyles read fStyle write SetStyle default []; - {$IFDEF SYN_LAZARUS} + procedure ModifyColors(var AForeground, ABackground, AFrameColor: TColor; var AStyle: TFontStyles); + property Background: TColor read FBG write SetBG default clHighLight; + property Foreground: TColor read FFG write SetFG default clHighLightText; + property FrameColor: TColor read FFrameColor write SetFrameColor default clNone; + property Style: TFontStyles read FStyle write SetStyle default []; property StyleMask: TFontStyles read fStyleMask write SetStyleMask default []; - {$ENDIF} property OnChange: TNotifyEvent read fOnChange write fOnChange; end; @@ -195,8 +191,6 @@ type property Options: TSynSearchOptions write SetOptions; end; - {$IFDEF SYN_LAZARUS} - { TSynEditCaret } TSynEditCaret = class @@ -217,7 +211,6 @@ type property CharPos : Integer read fCharPos write setCharPos; property LineCharPos : TPoint read GetLineCharPos write SetLineCharPos; end; - {$ENDIF} implementation @@ -231,69 +224,88 @@ begin inherited Create; fBG := clHighLight; fFG := clHighLightText; + FFrameColor:= clNone; end; -{$IFDEF SYN_LAZARUS} function TSynSelectedColor.GetModifiedStyle(aStyle : TFontStyles) : TFontStyles; begin - Result := fsXor(aStyle, fStyle * fsNot(fStyleMask)) // Invert Styles - + (fStyle*fStyleMask) // Set Styles - - (fsNot(fStyle)*fStyleMask); // Remove Styles + Result := fsXor(aStyle, FStyle * fsNot(FStyleMask)) // Invert Styles + + (FStyle*FStyleMask) // Set Styles + - (fsNot(FStyle)*FStyleMask); // Remove Styles end; -procedure TSynSelectedColor.ModifyColors(var aForeground, aBackground : TColor; var aStyle : TFontStyles); +procedure TSynSelectedColor.ModifyColors(var AForeground, ABackground, AFrameColor: TColor; var AStyle: TFontStyles); begin - if Foreground <> clNone then aForeground := Foreground; - if Background <> clNone then aBackground := Background; - aStyle := GetModifiedStyle(aStyle); + if Foreground <> clNone then AForeground := Foreground; + if Background <> clNone then ABackground := Background; + if FrameColor <> clNone then AFrameColor := FrameColor; + AStyle := GetModifiedStyle(AStyle); end; -{$ENDIF} procedure TSynSelectedColor.SetBG(Value: TColor); begin - if (fBG <> Value) then begin - fBG := Value; - if Assigned(fOnChange) then fOnChange(Self); + if (FBG <> Value) then + begin + FBG := Value; + DoChange; end; end; procedure TSynSelectedColor.SetFG(Value: TColor); begin - if (fFG <> Value) then begin - fFG := Value; - if Assigned(fOnChange) then fOnChange(Self); + if (FFG <> Value) then + begin + FFG := Value; + DoChange; + end; +end; + +procedure TSynSelectedColor.SetFrameColor(const AValue: TColor); +begin + if FFrameColor <> AValue then + begin + FFrameColor := AValue; + DoChange; end; end; procedure TSynSelectedColor.SetStyle(const AValue : TFontStyles); begin - if (fStyle <> AValue) then begin - fStyle := AValue; - if Assigned(fOnChange) then fOnChange(Self); + if (FStyle <> AValue) then + begin + FStyle := AValue; + DoChange; end; end; -{$IFDEF SYN_LAZARUS} procedure TSynSelectedColor.SetStyleMask(const AValue : TFontStyles); begin - if (fStyleMask <> AValue) then begin - fStyleMask := AValue; - if Assigned(fOnChange) then fOnChange(Self); + if (FStyleMask <> AValue) then + begin + FStyleMask := AValue; + DoChange; end; end; -{$ENDIF} + +procedure TSynSelectedColor.DoChange; +begin + if Assigned(FOnChange) then + OnChange(Self); +end; procedure TSynSelectedColor.Assign(aSource : TPersistent); var Source : TSynSelectedColor; begin - if Assigned(aSource) and (aSource is TSynSelectedColor) then begin + if Assigned(aSource) and (aSource is TSynSelectedColor) then + begin Source := TSynSelectedColor(aSource); - fBG := Source.fBG; - fFG := Source.fFG; - fStyle := Source.fStyle; - fStyleMask := Source.fStyleMask; - if Assigned(fOnChange) then fOnChange(Self); {TODO: only if really changed} + FBG := Source.FBG; + FFG := Source.FFG; + FFrameColor := Source.FFrameColor; + FStyle := Source.FStyle; + FStyleMask := Source.FStyleMask; + DoChange; {TODO: only if really changed} end; end; @@ -542,8 +554,6 @@ end; { TSynEditCaret } -{$IFDEF SYN_LAZARUS} - function TSynEditCaret.GetLineCharPos : TPoint; begin Result := Point(fCharPos, fLinePos); @@ -593,7 +603,6 @@ procedure TSynEditCaret.RemoveChangeHandler(AHandler : TNotifyEvent); begin fOnChangeList.Remove(TMethod(AHandler)); end; -{$ENDIF} end. diff --git a/components/synedit/syntextdrawer.pp b/components/synedit/syntextdrawer.pp index 4ba4bac8af..15397849de 100644 --- a/components/synedit/syntextdrawer.pp +++ b/components/synedit/syntextdrawer.pp @@ -194,6 +194,8 @@ type FSaveDC: Integer; {$IFDEF SYN_LAZARUS} FSavedFont: HFont; + FCrntPen: HPen; + FSavedPen: HPen; {$ENDIF} // Font information @@ -210,6 +212,7 @@ type // current font attributes FColor: TColor; FBkColor: TColor; + FFrameColor: TColor; FCharExtra: Integer; // Begin/EndDrawing calling count @@ -244,6 +247,7 @@ type procedure SetStyle(Value: TFontStyles); virtual; procedure SetForeColor(Value: TColor); virtual; procedure SetBackColor(Value: TColor); virtual; + procedure SetFrameColor(AValue: TColor); virtual; procedure SetCharExtra(Value: Integer); virtual; procedure ReleaseTemporaryResources; virtual; property CharWidth: Integer read GetCharWidth; @@ -252,6 +256,7 @@ type property BaseStyle: TFontStyles write SetBaseStyle; property ForeColor: TColor write SetForeColor; property BackColor: TColor write SetBackColor; + property FrameColor: TColor write SetFrameColor; property Style: TFontStyles write SetStyle; property CharExtra: Integer read FCharExtra write SetCharExtra; {$IFDEF SYN_LAZARUS} @@ -962,6 +967,10 @@ begin SetBaseFont(ABaseFont); FColor := clWindowText; FBkColor := clWindow; + FFrameColor := clNone; + + FSavedPen := 0; + FCrntPen := 0; end; destructor TheTextDrawer.Destroy; @@ -1014,6 +1023,10 @@ begin DoSetCharExtra(FCharExtra); {$ELSE} FSavedFont := SelectObject(DC, FCrntFont); + if FCrntPen <> 0 then + FSavedPen := SelectObject(DC, FCrntPen) + else + FSavedPen := 0; LCLIntf.SetTextColor(DC, FColor); LCLIntf.SetBkColor(DC, FBkColor); {$ENDIF} @@ -1027,10 +1040,17 @@ begin Dec(FDrawingCount); if FDrawingCount <= 0 then begin - if FDC <> 0 then begin + if FDC <> 0 then + begin {$IFDEF SYN_LAZARUS} if FSavedFont <> 0 then - SelectObject(FDC,FSavedFont); + SelectObject(FDC, FSavedFont); + if FSavedPen <> 0 then + begin + DeleteObject(SelectObject(FDC, FSavedPen)); + FSavedPen := 0; + FCrntPen := 0; + end; {$ENDIF} RestoreDC(FDC, FSaveDC); end; @@ -1128,6 +1148,27 @@ begin end; end; +procedure TheTextDrawer.SetFrameColor(AValue: TColor); +var + lp: TLogPen; +begin + if FFrameColor <> AValue then + begin + FFrameColor := AValue; + lp.lopnColor := ColorToRGB(FFrameColor); + lp.lopnWidth := Point(1, 0); + lp.lopnStyle := PS_SOLID; + + FCrntPen := CreatePenIndirect(lp); + if FDC <> 0 then + begin + if FSavedPen <> 0 then + DeleteObject(SelectObject(FDC, FSavedPen)); + FSavedPen := SelectObject(FDC, FCrntPen); + end; + end; +end; + procedure TheTextDrawer.SetCharExtra(Value: Integer); begin if FCharExtra <> Value then @@ -1190,6 +1231,7 @@ procedure TheTextDrawer.ExtTextOut(X, Y: Integer; fuOptions: UINT; var NeedDistArray: Boolean; DistArray: PInteger; + Points: array[0..4] of TPoint; begin {$IFDEF SYN_LAZARUS} NeedDistArray:= (FCharExtra > 0) or not MonoSpace; @@ -1204,13 +1246,26 @@ begin if UseUTF8 then LCLIntf.ExtUTF8Out(FDC, X, Y, fuOptions, @ARect, Text, Length, DistArray) else - LCLIntf.ExtTextOut(FDC, X, Y, fuOptions, @ARect, Text, Length, DistArray) + LCLIntf.ExtTextOut(FDC, X, Y, fuOptions, @ARect, Text, Length, DistArray); {$ELSE} if FETOSizeInChar < Length then InitETODist(GetCharWidth); Windows.ExtTextOut(FDC, X, Y, fuOptions, @ARect, Text, Length, PInteger(FETODist)); {$ENDIF} + if FFrameColor <> clNone then + begin + with ARect do + begin + Points[0] := TopLeft; + Points[1] := Point(Right - 1, Top); + Points[2] := Point(Right - 1, Bottom - 1); + Points[3] := Point(Left, Bottom - 1); + Points[4] := TopLeft; + end; + + Polyline(FDC, @Points, 5); + end; end; procedure TheTextDrawer.ReleaseTemporaryResources;