Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FMX port]Dotted brush parameters #1135

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/VirtualTrees.AncestorFMX.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions Source/VirtualTrees.BaseAncestorFMX.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
15 changes: 14 additions & 1 deletion Source/VirtualTrees.BaseAncestorVcl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
72 changes: 38 additions & 34 deletions Source/VirtualTrees.BaseTree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

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

begin
ShowScrollBar(Bar, Show);

if Assigned(FOnShowScrollBar) then
FOnShowScrollBar(Self, Bar, Show);
end;
Expand Down Expand Up @@ -12400,6 +12402,7 @@ procedure TBaseVirtualTree.DragLeave;
InvalidateNode(FDropTargetNode);
FDropTargetNode := nil;
end;

UpdateWindow();

Effect := 0;
Expand Down Expand Up @@ -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).

Expand All @@ -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).

Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -23328,6 +23331,7 @@ procedure TBaseVirtualTree.ToggleNode(Node: PVirtualNode);
if tsHint in Self.FStates then
Application.CancelHint;
UpdateWindow();

// animated expanding
with ToggleData do
begin
Expand Down