Skip to content

Commit a1577e8

Browse files
Merge pull request #1135 from livius2/DottedBrush-parameters
[FMX port]Dotted brush parameters
2 parents 23891eb + cc904db commit a1577e8

File tree

4 files changed

+66
-44
lines changed

4 files changed

+66
-44
lines changed

Source/VirtualTrees.AncestorFMX.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function TVTAncestorFMX.PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Poi
127127
//and recreate it every time when color is changing
128128

129129
CurrentDottedBrush.Free;
130-
FDottedBrushGrid.Free;
130+
FDottedBrushGridLines.Free;
131131

132132
Result := nil;
133133
for i_bmp:= 1 to 2 do
@@ -167,8 +167,8 @@ function TVTAncestorFMX.PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Poi
167167
Result.Bitmap.Bitmap.Assign(PatternBitmap);
168168
end else
169169
begin
170-
FDottedBrushGrid := TStrokeBrush.Create(TBrushKind.Bitmap, clWhite);
171-
FDottedBrushGrid.Bitmap.Bitmap.Assign(PatternBitmap);
170+
FDottedBrushGridLines := TStrokeBrush.Create(TBrushKind.Bitmap, clWhite);
171+
FDottedBrushGridLines.Bitmap.Bitmap.Assign(PatternBitmap);
172172
end;
173173
FreeAndNil(PatternBitmap);
174174
end;

Source/VirtualTrees.BaseAncestorFMX.pas

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ TVTBaseAncestorFMX = class abstract(TRectangle)
2020
FFont: TFont;
2121
procedure SetFont(const Value: TFont);
2222
private
23+
FDottedBrushTreeLines: TStrokeBrush; // used to paint dotted lines without special pens
24+
FDottedBrushGridLines: TStrokeBrush; // used to paint dotted lines without special pens
25+
2326
function GetFillColor: TAlphaColor;
2427
procedure SetFillColor(const Value: TAlphaColor);
2528
protected
26-
FDottedBrushGrid: TStrokeBrush; // used to paint dotted lines without special pens
27-
2829
FBevelEdges: TBevelEdges;
2930
FBevelInner: TBevelCut;
3031
FBevelOuter: TBevelCut;
@@ -59,6 +60,9 @@ TVTBaseAncestorFMX = class abstract(TRectangle)
5960
procedure ChangeScale(M, D: Integer{$if CompilerVersion >= 31}; isDpiChange: Boolean{$ifend}); virtual; abstract;
6061
function GetControlsAlignment: TAlignment; virtual; abstract;
6162
function PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Pointer; const BitsLinesCount: Word): TBrush; virtual; abstract;
63+
protected //properties
64+
property DottedBrushTreeLines: TStrokeBrush read FDottedBrushTreeLines write FDottedBrushTreeLines;
65+
property DottedBrushGridLines: TStrokeBrush read FDottedBrushGridLines write FDottedBrushGridLines;
6266
public //methods
6367
constructor Create(AOwner: TComponent); override;
6468
destructor Destroy; override;
@@ -92,6 +96,7 @@ TVTBaseAncestorFMX = class abstract(TRectangle)
9296
procedure Invalidate(); inline;
9397
function InvalidateRect(lpRect: PRect; bErase: BOOL): BOOL; inline;
9498
function UpdateWindow(): BOOL; inline;
99+
//jeszcze RedrawWindow i SendMessage
95100
public //properties
96101
property Font: TFont read FFont write SetFont;
97102
property ClientRect: TRect read GetClientRect;
@@ -239,10 +244,10 @@ destructor TVTBaseAncestorFMX.Destroy();
239244
begin
240245
inherited;
241246

242-
if FDottedBrush <> nil then
243-
FreeAndNil(FDottedBrush);
244-
if FDottedBrushGrid <> nil then
245-
FreeAndNil(FDottedBrushGrid);
247+
if FDottedBrushTreeLines <> nil then
248+
FreeAndNil(FDottedBrushTreeLines);
249+
if FDottedBrushGridLines <> nil then
250+
FreeAndNil(FDottedBrushGridLines);
246251
FreeAndNil(FFont);
247252
end;
248253

Source/VirtualTrees.BaseAncestorVcl.pas

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ TVTBaseAncestorVcl = class abstract(TCustomControl)
2727
FAccessible: IAccessible; // The IAccessible interface to the window itself.
2828
FAccessibleItem: IAccessible; // The IAccessible to the item that currently has focus.
2929
FAccessibleName: string; // The name the window is given for screen readers.
30-
protected
30+
FDottedBrushTreeLines: TBrush; // used to paint dotted lines without special pens
31+
32+
function GetDottedBrushGridLines: TBrush;
33+
protected // methods
3134
function DoRenderOLEData(const FormatEtcIn: TFormatEtc; out Medium: TStgMedium; ForClipboard: Boolean): HRESULT; virtual; abstract;
3235
function RenderOLEData(const FormatEtcIn: TFormatEtc; out Medium: TStgMedium; ForClipboard: Boolean): HResult; virtual; abstract;
3336
procedure NotifyAccessibilityCollapsed(); virtual; abstract;
3437
function PrepareDottedBrush(CurrentDottedBrush: TBrush; Bits: Pointer; const BitsLinesCount: Word): TBrush; virtual;
38+
protected //properties
39+
property DottedBrushTreeLines: TBrush read FDottedBrushTreeLines write FDottedBrushTreeLines;
40+
property DottedBrushGridLines: TBrush read GetDottedBrushGridLines;
3541
public // methods
3642
procedure CopyToClipboard; virtual; abstract;
3743
procedure CutToClipboard; virtual; abstract;
@@ -97,6 +103,13 @@ function TVTBaseAncestorVcl.SetScrollInfo(Bar: Integer; const ScrollInfo: TScrol
97103

98104
//----------------------------------------------------------------------------------------------------------------------
99105

106+
function TVTBaseAncestorVcl.GetDottedBrushGridLines: TBrush;
107+
begin
108+
Result:= FDottedBrushTreeLines;
109+
end;
110+
111+
//----------------------------------------------------------------------------------------------------------------------
112+
100113
function TVTBaseAncestorVcl.GetScrollInfo(Bar: Integer; var ScrollInfo: TScrollInfo): Boolean;
101114
begin
102115
Result:= WinApi.Windows.GetScrollInfo(Handle, Bar, ScrollInfo);

Source/VirtualTrees.BaseTree.pas

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
10441044
FButtonFillMode: TVTButtonFillMode; // for rectangular tree buttons only: how to fill them
10451045
FLineStyle: TVTLineStyle; // style of the tree lines
10461046
FLineMode: TVTLineMode; // tree lines or bands etc.
1047-
FDottedBrush: TBrush; // used to paint dotted lines without special pens
10481047
FSelectionCurveRadius: Cardinal; // radius for rounded selection rectangles
10491048
FSelectionBlendFactor: Byte; // Determines the factor by which the selection rectangle is to be
10501049
// faded if enabled.
@@ -1282,7 +1281,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
12821281
NewRect: TRect): Boolean;
12831282
procedure ClearNodeBackground(const PaintInfo: TVTPaintInfo; UseBackground, Floating: Boolean; R: TRect);
12841283
function CompareNodePositions(Node1, Node2: PVirtualNode; ConsiderChildrenAbove: Boolean = False): Integer;
1285-
procedure DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H, VAlign: TDimension; Style: TVTLineType; Reverse: Boolean);
1284+
procedure DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H, VAlign: TDimension; Style: TVTLineType; Reverse: Boolean; dottedBrush: TBrush);
12861285
function FindInPositionCache(Node: PVirtualNode; var CurrentPos: TDimension): PVirtualNode; overload;
12871286
function FindInPositionCache(Position: TDimension; var CurrentPos: TDimension): PVirtualNode; overload;
12881287
procedure FixupTotalCount(Node: PVirtualNode);
@@ -1603,8 +1602,8 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
16031602
procedure DragLeave; virtual;
16041603
function DragOver(Source: TObject; KeyState: Integer; DragState: TDragState; Pt: TPoint;
16051604
var Effect: Integer): HResult; reintroduce; virtual;
1606-
procedure DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension); virtual;
1607-
procedure DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; UseSelectedBkColor: Boolean = False); virtual;
1605+
procedure DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension; dottedBrush: TBrush); virtual;
1606+
procedure DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; dottedBrush: TBrush; UseSelectedBkColor: Boolean = False); virtual;
16081607
procedure EndOperation(OperationKind: TVTOperationKind);
16091608
procedure EnsureNodeFocused(); virtual;
16101609
function FindNodeInSelection(P: PVirtualNode; var Index: Integer; LowBound, HighBound: Integer): Boolean; virtual;
@@ -3238,10 +3237,11 @@ destructor TBaseVirtualTree.Destroy();
32383237
DestroyWindowHandle;
32393238

32403239
// Release FDottedBrush in case WM_NCDESTROY hasn't been triggered.
3241-
if Assigned(FDottedBrush) then
3240+
if Assigned(DottedBrushTreeLines) then
32423241
begin
3243-
FDottedBrush.Bitmap.Free();
3244-
FreeAndNil(FDottedBrush);
3242+
DottedBrushTreeLines.Bitmap.Free();
3243+
DottedBrushTreeLines.Free;
3244+
DottedBrushTreeLines:= nil;
32453245
end;
32463246

32473247
FHeader.Free;
@@ -4024,7 +4024,7 @@ function TBaseVirtualTree.CompareNodePositions(Node1, Node2: PVirtualNode; Consi
40244024
//----------------------------------------------------------------------------------------------------------------------
40254025

40264026
procedure TBaseVirtualTree.DrawLineImage(const PaintInfo: TVTPaintInfo; X, Y, H, VAlign: TDimension; Style: TVTLineType;
4027-
Reverse: Boolean);
4027+
Reverse: Boolean; dottedBrush: TBrush);
40284028

40294029
// Draws (depending on Style) one of the 5 line types of the tree.
40304030
// 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,
40464046
case Style of
40474047
ltBottomRight:
40484048
begin
4049-
DrawDottedVLine(PaintInfo, Y + VAlign, Y + H, X + HalfWidth);
4050-
DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign);
4049+
DrawDottedVLine(PaintInfo, Y + VAlign, Y + H, X + HalfWidth, dottedBrush);
4050+
DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign, dottedBrush);
40514051
end;
40524052
ltTopDown:
4053-
DrawDottedVLine(PaintInfo, Y, Y + H, X + HalfWidth);
4053+
DrawDottedVLine(PaintInfo, Y, Y + H, X + HalfWidth, dottedBrush);
40544054
ltTopDownRight:
40554055
begin
4056-
DrawDottedVLine(PaintInfo, Y, Y + H, X + HalfWidth);
4057-
DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign);
4056+
DrawDottedVLine(PaintInfo, Y, Y + H, X + HalfWidth, dottedBrush);
4057+
DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign, dottedBrush);
40584058
end;
40594059
ltRight:
4060-
DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign);
4060+
DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign, dottedBrush);
40614061
ltTopRight:
40624062
begin
4063-
DrawDottedVLine(PaintInfo, Y, Y + VAlign, X + HalfWidth);
4064-
DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign);
4063+
DrawDottedVLine(PaintInfo, Y, Y + VAlign, X + HalfWidth, dottedBrush);
4064+
DrawDottedHLine(PaintInfo, X + HalfWidth, X + TargetX, Y + VAlign, dottedBrush);
40654065
end;
40664066
ltLeft: // left can also mean right for RTL context
40674067
if Reverse then
4068-
DrawDottedVLine(PaintInfo, Y, Y + H, X + FIndent)
4068+
DrawDottedVLine(PaintInfo, Y, Y + H, X + FIndent, dottedBrush)
40694069
else
4070-
DrawDottedVLine(PaintInfo, Y, Y + H, X);
4070+
DrawDottedVLine(PaintInfo, Y, Y + H, X, dottedBrush);
40714071
ltLeftBottom:
40724072
if Reverse then
40734073
begin
4074-
DrawDottedVLine(PaintInfo, Y, Y + H, X + FIndent);
4075-
DrawDottedHLine(PaintInfo, X, X + FIndent, Y + H);
4074+
DrawDottedVLine(PaintInfo, Y, Y + H, X + FIndent, dottedBrush);
4075+
DrawDottedHLine(PaintInfo, X, X + FIndent, Y + H, dottedBrush);
40764076
end
40774077
else
40784078
begin
4079-
DrawDottedVLine(PaintInfo, Y, Y + H, X);
4080-
DrawDottedHLine(PaintInfo, X, X + FIndent, Y + H);
4079+
DrawDottedVLine(PaintInfo, Y, Y + H, X, dottedBrush);
4080+
DrawDottedHLine(PaintInfo, X, X + FIndent, Y + H, dottedBrush);
40814081
end;
40824082
end;
40834083
end;
@@ -5290,7 +5290,7 @@ procedure TBaseVirtualTree.PrepareBitmaps(NeedButtons, NeedLines: Boolean);
52905290
DoGetLineStyle(Bits);
52915291
BitsLinesCount:= Length(LineBitsDotted);
52925292
end;
5293-
FDottedBrush:= PrepareDottedBrush(FDottedBrush, Bits, BitsLinesCount);
5293+
DottedBrushTreeLines:= PrepareDottedBrush(DottedBrushTreeLines, Bits, BitsLinesCount);
52945294
end;
52955295
end;
52965296

@@ -8628,6 +8628,7 @@ procedure TBaseVirtualTree.WMNCDestroy(var Message: TWMNCDestroy);
86288628

86298629
if not (csDesigning in ComponentState) and (toAcceptOLEDrop in FOptions.MiscOptions) then
86308630
RevokeDragDrop(Handle);
8631+
86318632
inherited;
86328633
end;
86338634

@@ -11899,6 +11900,7 @@ procedure TBaseVirtualTree.DoShowScrollBar(Bar: Integer; Show: Boolean);
1189911900

1190011901
begin
1190111902
ShowScrollBar(Bar, Show);
11903+
1190211904
if Assigned(FOnShowScrollBar) then
1190311905
FOnShowScrollBar(Self, Bar, Show);
1190411906
end;
@@ -12400,6 +12402,7 @@ procedure TBaseVirtualTree.DragLeave;
1240012402
InvalidateNode(FDropTargetNode);
1240112403
FDropTargetNode := nil;
1240212404
end;
12405+
1240312406
UpdateWindow();
1240412407

1240512408
Effect := 0;
@@ -12606,7 +12609,7 @@ function TBaseVirtualTree.DragOver(Source: TObject; KeyState: Integer; DragState
1260612609

1260712610
//----------------------------------------------------------------------------------------------------------------------
1260812611

12609-
procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension);
12612+
procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension; dottedBrush: TBrush);
1261012613

1261112614
// Draws a horizontal line with alternating pixels (this style is not supported for pens under Win9x).
1261212615

@@ -12618,13 +12621,13 @@ procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left,
1261812621
begin
1261912622
Brush.Color := FColors.BackGroundColor;
1262012623
R := Rect(Min(Left, Right), Top, Max(Left, Right) + 1, Top + 1);
12621-
Winapi.Windows.FillRect(Handle, R, FDottedBrush.Handle);
12624+
Winapi.Windows.FillRect(Handle, R, dottedBrush.Handle);
1262212625
end;
1262312626
end;
1262412627

1262512628
//----------------------------------------------------------------------------------------------------------------------
1262612629

12627-
procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; UseSelectedBkColor: Boolean = False);
12630+
procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; dottedBrush: TBrush; UseSelectedBkColor: Boolean = False);
1262812631

1262912632
// Draws a horizontal line with alternating pixels (this style is not supported for pens under Win9x).
1263012633

@@ -12644,7 +12647,7 @@ procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, B
1264412647
else
1264512648
Brush.Color := FColors.BackGroundColor;
1264612649
R := Rect(Left, Min(Top, Bottom), Left + 1, Max(Top, Bottom) + 1);
12647-
Winapi.Windows.FillRect(Handle, R, FDottedBrush.Handle);
12650+
Winapi.Windows.FillRect(Handle, R, dottedBrush.Handle);
1264812651
end;
1264912652
end;
1265012653

@@ -15305,7 +15308,7 @@ procedure TBaseVirtualTree.PaintTreeLines(const PaintInfo: TVTPaintInfo; IndentS
1530515308
begin
1530615309
DoBeforeDrawLineImage(PaintInfo.Node, I + Ord(not (toShowRoot in TreeOptions.PaintOptions)), XPos);
1530715310
DrawLineImage(PaintInfo, XPos, CellRect.Top, NodeHeight[Node] - 1, VAlign - 1, NewStyles[I],
15308-
BidiMode <> bdLeftToRight);
15311+
BidiMode <> bdLeftToRight, DottedBrushTreeLines);
1530915312
Inc(XPos, Offset);
1531015313
end;
1531115314
end;
@@ -15315,7 +15318,7 @@ procedure TBaseVirtualTree.PaintTreeLines(const PaintInfo: TVTPaintInfo; IndentS
1531515318
begin
1531615319
DoBeforeDrawLineImage(PaintInfo.Node, I + Ord(not (toShowRoot in TreeOptions.PaintOptions)), XPos);
1531715320
DrawLineImage(PaintInfo, XPos, CellRect.Top, NodeHeight[Node], VAlign - 1, LineImage[I],
15318-
BidiMode <> bdLeftToRight);
15321+
BidiMode <> bdLeftToRight, DottedBrushTreeLines);
1531915322
Inc(XPos, Offset);
1532015323
end;
1532115324
end;
@@ -21679,15 +21682,15 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
2167921682
begin
2168021683
if BidiMode = bdLeftToRight then
2168121684
begin
21682-
DrawDottedHLine(PaintInfo, CellRect.Left + PaintInfo.Offsets[ofsCheckBox] - fImagesMargin, CellRect.Right - 1, CellRect.Bottom - 1);
21685+
DrawDottedHLine(PaintInfo, CellRect.Left + PaintInfo.Offsets[ofsCheckBox] - fImagesMargin, CellRect.Right - 1, CellRect.Bottom - 1, DottedBrushGridLines);
2168321686
end
2168421687
else
2168521688
begin
21686-
DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right - IfThen(toFixedIndent in FOptions.PaintOptions, 1, IndentSize) * Integer(FIndent) - 1, CellRect.Bottom - 1);
21689+
DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right - IfThen(toFixedIndent in FOptions.PaintOptions, 1, IndentSize) * Integer(FIndent) - 1, CellRect.Bottom - 1, DottedBrushGridLines);
2168721690
end;
2168821691
end
2168921692
else
21690-
DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right, CellRect.Bottom - 1);
21693+
DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right, CellRect.Bottom - 1, DottedBrushGridLines);
2169121694

2169221695
Dec(CellRect.Bottom);
2169321696
Dec(ContentRect.Bottom);
@@ -21721,7 +21724,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
2172121724
lUseSelectedBkColor := (poDrawSelection in PaintOptions) and (toFullRowSelect in FOptions.SelectionOptions) and
2172221725
(vsSelected in Node.States) and not (toUseBlendedSelection in FOptions.PaintOptions) and not
2172321726
(tsUseExplorerTheme in FStates);
21724-
DrawDottedVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - 1, lUseSelectedBkColor);
21727+
DrawDottedVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - 1, DottedBrushGridLines, lUseSelectedBkColor);
2172521728
end;
2172621729

2172721730
Dec(CellRect.Right);
@@ -21917,7 +21920,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
2191721920
(toShowVertGridLines in FOptions.PaintOptions) and
2191821921
(not (hoAutoResize in FHeader.Options) or (Cardinal(FirstColumn) < TColumnPosition(Count - 1))) then
2191921922
begin
21920-
DrawDottedVLine(PaintInfo, R.Top, R.Bottom, R.Right - 1);
21923+
DrawDottedVLine(PaintInfo, R.Top, R.Bottom, R.Right - 1, DottedBrushGridLines);
2192121924
Dec(R.Right);
2192221925
end;
2192321926

@@ -23328,6 +23331,7 @@ procedure TBaseVirtualTree.ToggleNode(Node: PVirtualNode);
2332823331
if tsHint in Self.FStates then
2332923332
Application.CancelHint;
2333023333
UpdateWindow();
23334+
2333123335
// animated expanding
2333223336
with ToggleData do
2333323337
begin

0 commit comments

Comments
 (0)