From cc904db72f2eeae0780389534815c3d03a87720a Mon Sep 17 00:00:00 2001 From: livius2 Date: Tue, 18 Oct 2022 17:26:05 +0200 Subject: [PATCH] [FMX port]Dotted brush parameters 1. Renamed FDottedBrush to DottedBrushTreeLines 2. Introduced DottedBrushGridLines. On VCL it is an "alias" for DottedBrushTreeLines. On FMX separate brush. --- Source/VirtualTrees.AncestorFMX.pas | 6 +-- Source/VirtualTrees.BaseAncestorFMX.pas | 17 +++--- Source/VirtualTrees.BaseAncestorVcl.pas | 15 +++++- Source/VirtualTrees.BaseTree.pas | 72 +++++++++++++------------ 4 files changed, 66 insertions(+), 44 deletions(-) diff --git a/Source/VirtualTrees.AncestorFMX.pas b/Source/VirtualTrees.AncestorFMX.pas index b6a0bc0b6..315cb6434 100644 --- a/Source/VirtualTrees.AncestorFMX.pas +++ b/Source/VirtualTrees.AncestorFMX.pas @@ -127,7 +127,7 @@ function TVTAncestorFMX.PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Poi //and recreate it every time when color is changing CurrentDottedBrush.Free; - FDottedBrushGrid.Free; + FDottedBrushGridLines.Free; Result := nil; for i_bmp:= 1 to 2 do @@ -167,8 +167,8 @@ function TVTAncestorFMX.PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Poi Result.Bitmap.Bitmap.Assign(PatternBitmap); end else begin - FDottedBrushGrid := TStrokeBrush.Create(TBrushKind.Bitmap, clWhite); - FDottedBrushGrid.Bitmap.Bitmap.Assign(PatternBitmap); + FDottedBrushGridLines := TStrokeBrush.Create(TBrushKind.Bitmap, clWhite); + FDottedBrushGridLines.Bitmap.Bitmap.Assign(PatternBitmap); end; FreeAndNil(PatternBitmap); end; diff --git a/Source/VirtualTrees.BaseAncestorFMX.pas b/Source/VirtualTrees.BaseAncestorFMX.pas index bc0ee5204..3b30e10d7 100644 --- a/Source/VirtualTrees.BaseAncestorFMX.pas +++ b/Source/VirtualTrees.BaseAncestorFMX.pas @@ -20,11 +20,12 @@ TVTBaseAncestorFMX = class abstract(TRectangle) FFont: TFont; procedure SetFont(const Value: TFont); private + FDottedBrushTreeLines: TStrokeBrush; // used to paint dotted lines without special pens + FDottedBrushGridLines: TStrokeBrush; // used to paint dotted lines without special pens + function GetFillColor: TAlphaColor; procedure SetFillColor(const Value: TAlphaColor); protected - FDottedBrushGrid: TStrokeBrush; // used to paint dotted lines without special pens - FBevelEdges: TBevelEdges; FBevelInner: TBevelCut; FBevelOuter: TBevelCut; @@ -59,6 +60,9 @@ TVTBaseAncestorFMX = class abstract(TRectangle) procedure ChangeScale(M, D: Integer{$if CompilerVersion >= 31}; isDpiChange: Boolean{$ifend}); virtual; abstract; function GetControlsAlignment: TAlignment; virtual; abstract; function PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Pointer; const BitsLinesCount: Word): TBrush; virtual; abstract; + protected //properties + property DottedBrushTreeLines: TStrokeBrush read FDottedBrushTreeLines write FDottedBrushTreeLines; + property DottedBrushGridLines: TStrokeBrush read FDottedBrushGridLines write FDottedBrushGridLines; public //methods constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -92,6 +96,7 @@ TVTBaseAncestorFMX = class abstract(TRectangle) procedure Invalidate(); inline; function InvalidateRect(lpRect: PRect; bErase: BOOL): BOOL; inline; function UpdateWindow(): BOOL; inline; + //jeszcze RedrawWindow i SendMessage public //properties property Font: TFont read FFont write SetFont; property ClientRect: TRect read GetClientRect; @@ -239,10 +244,10 @@ destructor TVTBaseAncestorFMX.Destroy(); begin inherited; - if FDottedBrush <> nil then - FreeAndNil(FDottedBrush); - if FDottedBrushGrid <> nil then - FreeAndNil(FDottedBrushGrid); + if FDottedBrushTreeLines <> nil then + FreeAndNil(FDottedBrushTreeLines); + if FDottedBrushGridLines <> nil then + FreeAndNil(FDottedBrushGridLines); FreeAndNil(FFont); end; diff --git a/Source/VirtualTrees.BaseAncestorVcl.pas b/Source/VirtualTrees.BaseAncestorVcl.pas index a10856998..382a90c06 100644 --- a/Source/VirtualTrees.BaseAncestorVcl.pas +++ b/Source/VirtualTrees.BaseAncestorVcl.pas @@ -27,11 +27,17 @@ TVTBaseAncestorVcl = class abstract(TCustomControl) FAccessible: IAccessible; // The IAccessible interface to the window itself. FAccessibleItem: IAccessible; // The IAccessible to the item that currently has focus. FAccessibleName: string; // The name the window is given for screen readers. - protected + FDottedBrushTreeLines: TBrush; // used to paint dotted lines without special pens + + function GetDottedBrushGridLines: TBrush; + protected // methods function DoRenderOLEData(const FormatEtcIn: TFormatEtc; out Medium: TStgMedium; ForClipboard: Boolean): HRESULT; virtual; abstract; function RenderOLEData(const FormatEtcIn: TFormatEtc; out Medium: TStgMedium; ForClipboard: Boolean): HResult; virtual; abstract; procedure NotifyAccessibilityCollapsed(); virtual; abstract; function PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Pointer; const BitsLinesCount: Word): TBrush; virtual; + protected //properties + property DottedBrushTreeLines: TBrush read FDottedBrushTreeLines write FDottedBrushTreeLines; + property DottedBrushGridLines: TBrush read GetDottedBrushGridLines; public // methods procedure CopyToClipboard; virtual; abstract; procedure CutToClipboard; virtual; abstract; @@ -97,6 +103,13 @@ function TVTBaseAncestorVcl.SetScrollInfo(Bar: Integer; const ScrollInfo: TScrol //---------------------------------------------------------------------------------------------------------------------- +function TVTBaseAncestorVcl.GetDottedBrushGridLines: TBrush; +begin + Result:= FDottedBrushTreeLines; +end; + +//---------------------------------------------------------------------------------------------------------------------- + function TVTBaseAncestorVcl.GetScrollInfo(Bar: Integer; var ScrollInfo: TScrollInfo): Boolean; begin Result:= WinApi.Windows.GetScrollInfo(Handle, Bar, ScrollInfo); diff --git a/Source/VirtualTrees.BaseTree.pas b/Source/VirtualTrees.BaseTree.pas index ae27f97b6..85452f88e 100644 --- a/Source/VirtualTrees.BaseTree.pas +++ b/Source/VirtualTrees.BaseTree.pas @@ -1044,7 +1044,6 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor) FButtonFillMode: TVTButtonFillMode; // for rectangular tree buttons only: how to fill them FLineStyle: TVTLineStyle; // style of the tree lines FLineMode: TVTLineMode; // tree lines or bands etc. - FDottedBrush: TBrush; // used to paint dotted lines without special pens FSelectionCurveRadius: Cardinal; // radius for rounded selection rectangles FSelectionBlendFactor: Byte; // Determines the factor by which the selection rectangle is to be // faded if enabled. @@ -1282,7 +1281,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor) NewRect: TRect): Boolean; procedure ClearNodeBackground(const PaintInfo: TVTPaintInfo; UseBackground, Floating: Boolean; R: TRect); function CompareNodePositions(Node1, Node2: PVirtualNode; ConsiderChildrenAbove: Boolean = False): Integer; - procedure DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H, VAlign: TDimension; Style: TVTLineType; Reverse: Boolean); + procedure DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H, VAlign: TDimension; Style: TVTLineType; Reverse: Boolean; dottedBrush: TBrush); function FindInPositionCache(Node: PVirtualNode; var CurrentPos: TDimension): PVirtualNode; overload; function FindInPositionCache(Position: TDimension; var CurrentPos: TDimension): PVirtualNode; overload; procedure FixupTotalCount(Node: PVirtualNode); @@ -1603,8 +1602,8 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor) procedure DragLeave; virtual; function DragOver(Source: TObject; KeyState: Integer; DragState: TDragState; Pt: TPoint; var Effect: Integer): HResult; reintroduce; virtual; - procedure DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension); virtual; - procedure DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; UseSelectedBkColor: Boolean = False); virtual; + procedure DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension; dottedBrush: TBrush); virtual; + procedure DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; dottedBrush: TBrush; UseSelectedBkColor: Boolean = False); virtual; procedure EndOperation(OperationKind: TVTOperationKind); procedure EnsureNodeFocused(); virtual; function FindNodeInSelection(P: PVirtualNode; var Index: Integer; LowBound, HighBound: Integer): Boolean; virtual; @@ -3238,10 +3237,11 @@ destructor TBaseVirtualTree.Destroy(); DestroyWindowHandle; // Release FDottedBrush in case WM_NCDESTROY hasn't been triggered. - if Assigned(FDottedBrush) then + if Assigned(DottedBrushTreeLines) then begin - FDottedBrush.Bitmap.Free(); - FreeAndNil(FDottedBrush); + DottedBrushTreeLines.Bitmap.Free(); + DottedBrushTreeLines.Free; + DottedBrushTreeLines:= nil; end; FHeader.Free; @@ -4024,7 +4024,7 @@ function TBaseVirtualTree.CompareNodePositions(Node1, Node2: PVirtualNode; Consi //---------------------------------------------------------------------------------------------------------------------- procedure TBaseVirtualTree.DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H, VAlign: TDimension; Style: TVTLineType; - Reverse: Boolean); + Reverse: Boolean; dottedBrush: TBrush); // Draws (depending on Style) one of the 5 line types of the tree. // If Reverse is True then a right-to-left column is being drawn, hence horizontal lines must be mirrored. @@ -4046,38 +4046,38 @@ procedure TBaseVirtualTree.DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H, case Style of ltBottomRight: begin - DrawDottedVLine(PaintInfo, Y + VAlign, Y + H, X + HalfWidth); - DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign); + DrawDottedVLine(PaintInfo, Y + VAlign, Y + H, X + HalfWidth, dottedBrush); + DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign, dottedBrush); end; ltTopDown: - DrawDottedVLine(PaintInfo, Y, Y + H, X + HalfWidth); + DrawDottedVLine(PaintInfo, Y, Y + H, X + HalfWidth, dottedBrush); ltTopDownRight: begin - DrawDottedVLine(PaintInfo, Y, Y + H, X + HalfWidth); - DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign); + DrawDottedVLine(PaintInfo, Y, Y + H, X + HalfWidth, dottedBrush); + DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign, dottedBrush); end; ltRight: - DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign); + DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign, dottedBrush); ltTopRight: begin - DrawDottedVLine(PaintInfo, Y, Y + VAlign, X + HalfWidth); - DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign); + DrawDottedVLine(PaintInfo, Y, Y + VAlign, X + HalfWidth, dottedBrush); + DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign, dottedBrush); end; ltLeft: // left can also mean right for RTL context if Reverse then - DrawDottedVLine(PaintInfo, Y, Y + H, X + FIndent) + DrawDottedVLine(PaintInfo, Y, Y + H, X + FIndent, dottedBrush) else - DrawDottedVLine(PaintInfo, Y, Y + H, X); + DrawDottedVLine(PaintInfo, Y, Y + H, X, dottedBrush); ltLeftBottom: if Reverse then begin - DrawDottedVLine(PaintInfo, Y, Y + H, X + FIndent); - DrawDottedHLine(PaintInfo, X, X + FIndent, Y + H); + DrawDottedVLine(PaintInfo, Y, Y + H, X + FIndent, dottedBrush); + DrawDottedHLine(PaintInfo, X, X + FIndent, Y + H, dottedBrush); end else begin - DrawDottedVLine(PaintInfo, Y, Y + H, X); - DrawDottedHLine(PaintInfo, X, X + FIndent, Y + H); + DrawDottedVLine(PaintInfo, Y, Y + H, X, dottedBrush); + DrawDottedHLine(PaintInfo, X, X + FIndent, Y + H, dottedBrush); end; end; end; @@ -5290,7 +5290,7 @@ procedure TBaseVirtualTree.PrepareBitmaps(NeedButtons, NeedLines: Boolean); DoGetLineStyle(Bits); BitsLinesCount:= Length(LineBitsDotted); end; - FDottedBrush:= PrepareDottedBrush(FDottedBrush, Bits, BitsLinesCount); + DottedBrushTreeLines:= PrepareDottedBrush(DottedBrushTreeLines, Bits, BitsLinesCount); end; end; @@ -8628,6 +8628,7 @@ procedure TBaseVirtualTree.WMNCDestroy(var Message: TWMNCDestroy); if not (csDesigning in ComponentState) and (toAcceptOLEDrop in FOptions.MiscOptions) then RevokeDragDrop(Handle); + inherited; end; @@ -11899,6 +11900,7 @@ procedure TBaseVirtualTree.DoShowScrollBar(Bar: Integer; Show: Boolean); begin ShowScrollBar(Bar, Show); + if Assigned(FOnShowScrollBar) then FOnShowScrollBar(Self, Bar, Show); end; @@ -12400,6 +12402,7 @@ procedure TBaseVirtualTree.DragLeave; InvalidateNode(FDropTargetNode); FDropTargetNode := nil; end; + UpdateWindow(); Effect := 0; @@ -12606,7 +12609,7 @@ function TBaseVirtualTree.DragOver(Source: TObject; KeyState: Integer; DragState //---------------------------------------------------------------------------------------------------------------------- -procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension); +procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension; dottedBrush: TBrush); // Draws a horizontal line with alternating pixels (this style is not supported for pens under Win9x). @@ -12618,13 +12621,13 @@ procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, begin Brush.Color := FColors.BackGroundColor; R := Rect(Min(Left, Right), Top, Max(Left, Right) + 1, Top + 1); - Winapi.Windows.FillRect(Handle, R, FDottedBrush.Handle); + Winapi.Windows.FillRect(Handle, R, dottedBrush.Handle); end; end; //---------------------------------------------------------------------------------------------------------------------- -procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; UseSelectedBkColor: Boolean = False); +procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; dottedBrush: TBrush; UseSelectedBkColor: Boolean = False); // Draws a horizontal line with alternating pixels (this style is not supported for pens under Win9x). @@ -12644,7 +12647,7 @@ procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, B else Brush.Color := FColors.BackGroundColor; R := Rect(Left, Min(Top, Bottom), Left + 1, Max(Top, Bottom) + 1); - Winapi.Windows.FillRect(Handle, R, FDottedBrush.Handle); + Winapi.Windows.FillRect(Handle, R, dottedBrush.Handle); end; end; @@ -15305,7 +15308,7 @@ procedure TBaseVirtualTree.PaintTreeLines(const PaintInfo: TVTPaintInfo; IndentS begin DoBeforeDrawLineImage(PaintInfo.Node, I + Ord(not (toShowRoot in TreeOptions.PaintOptions)), XPos); DrawLineImage(PaintInfo, XPos, CellRect.Top, NodeHeight[Node] - 1, VAlign - 1, NewStyles[I], - BidiMode <> bdLeftToRight); + BidiMode <> bdLeftToRight, DottedBrushTreeLines); Inc(XPos, Offset); end; end; @@ -15315,7 +15318,7 @@ procedure TBaseVirtualTree.PaintTreeLines(const PaintInfo: TVTPaintInfo; IndentS begin DoBeforeDrawLineImage(PaintInfo.Node, I + Ord(not (toShowRoot in TreeOptions.PaintOptions)), XPos); DrawLineImage(PaintInfo, XPos, CellRect.Top, NodeHeight[Node], VAlign - 1, LineImage[I], - BidiMode <> bdLeftToRight); + BidiMode <> bdLeftToRight, DottedBrushTreeLines); Inc(XPos, Offset); end; end; @@ -21679,15 +21682,15 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe begin if BidiMode = bdLeftToRight then begin - DrawDottedHLine(PaintInfo, CellRect.Left + PaintInfo.Offsets[ofsCheckBox] - fImagesMargin, CellRect.Right - 1, CellRect.Bottom - 1); + DrawDottedHLine(PaintInfo, CellRect.Left + PaintInfo.Offsets[ofsCheckBox] - fImagesMargin, CellRect.Right - 1, CellRect.Bottom - 1, DottedBrushGridLines); end else begin - DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right - IfThen(toFixedIndent in FOptions.PaintOptions, 1, IndentSize) * Integer(FIndent) - 1, CellRect.Bottom - 1); + DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right - IfThen(toFixedIndent in FOptions.PaintOptions, 1, IndentSize) * Integer(FIndent) - 1, CellRect.Bottom - 1, DottedBrushGridLines); end; end else - DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right, CellRect.Bottom - 1); + DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right, CellRect.Bottom - 1, DottedBrushGridLines); Dec(CellRect.Bottom); Dec(ContentRect.Bottom); @@ -21721,7 +21724,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe lUseSelectedBkColor := (poDrawSelection in PaintOptions) and (toFullRowSelect in FOptions.SelectionOptions) and (vsSelected in Node.States) and not (toUseBlendedSelection in FOptions.PaintOptions) and not (tsUseExplorerTheme in FStates); - DrawDottedVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - 1, lUseSelectedBkColor); + DrawDottedVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - 1, DottedBrushGridLines, lUseSelectedBkColor); end; Dec(CellRect.Right); @@ -21917,7 +21920,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe (toShowVertGridLines in FOptions.PaintOptions) and (not (hoAutoResize in FHeader.Options) or (Cardinal(FirstColumn) < TColumnPosition(Count - 1))) then begin - DrawDottedVLine(PaintInfo, R.Top, R.Bottom, R.Right - 1); + DrawDottedVLine(PaintInfo, R.Top, R.Bottom, R.Right - 1, DottedBrushGridLines); Dec(R.Right); end; @@ -23328,6 +23331,7 @@ procedure TBaseVirtualTree.ToggleNode(Node: PVirtualNode); if tsHint in Self.FStates then Application.CancelHint; UpdateWindow(); + // animated expanding with ToggleData do begin