mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 17:39:20 +02:00
lcl: a bit reformat treeview paint code, draw vert line from expand sign (not from the top)
git-svn-id: trunk@17100 -
This commit is contained in:
parent
c32d7d3fa6
commit
ba28bc39c9
@ -4078,44 +4078,65 @@ var
|
|||||||
Result := clHighlightText;
|
Result := clHighlightText;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure DrawVertLine(X, Y1, Y2: Integer);
|
||||||
|
begin
|
||||||
|
Canvas.MoveTo(X, Y1);
|
||||||
|
Canvas.LineTo(X, Y2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure DrawHorzLine(Y, X1, X2: Integer);
|
||||||
|
begin
|
||||||
|
Canvas.MoveTo(X1, Y);
|
||||||
|
Canvas.LineTo(X2, Y);
|
||||||
|
end;
|
||||||
|
|
||||||
function DrawTreeLines(CurNode: TTreeNode): integer;
|
function DrawTreeLines(CurNode: TTreeNode): integer;
|
||||||
// paints tree lines, returns indent
|
// paints tree lines, returns indent
|
||||||
var CurMid: integer;
|
var
|
||||||
|
CurMid: integer;
|
||||||
|
begin
|
||||||
|
if CurNode <> nil then
|
||||||
|
begin
|
||||||
|
Result := DrawTreeLines(CurNode.Parent);
|
||||||
|
if ShowLines then
|
||||||
|
begin
|
||||||
|
CurMid := Result + (Indent shr 1);
|
||||||
|
if CurNode = Node then
|
||||||
begin
|
begin
|
||||||
if CurNode<>nil then begin
|
|
||||||
Result:=DrawTreeLines(CurNode.Parent);
|
|
||||||
if ShowLines then begin
|
|
||||||
CurMid:=Result+(Indent shr 1);
|
|
||||||
if CurNode=Node then begin
|
|
||||||
// draw horizontal line
|
// draw horizontal line
|
||||||
Canvas.MoveTo(CurMid,VertMid);
|
DrawHorzLine(VertMid, CurMid, Result + Indent);
|
||||||
Canvas.LineTo(Result+Indent,VertMid);
|
|
||||||
end;
|
end;
|
||||||
if (CurNode.GetNextSibling<>nil) then begin
|
|
||||||
|
if (CurNode.GetNextSibling <> nil) then
|
||||||
|
begin
|
||||||
// draw vertical line to next brother
|
// draw vertical line to next brother
|
||||||
Canvas.MoveTo(CurMid,NodeRect.Top);
|
if Node.HasChildren then
|
||||||
Canvas.LineTo(CurMid,NodeRect.Bottom);
|
DrawVertLine(CurMid, VertMid + fExpandSignSize shr 1, NodeRect.Bottom)
|
||||||
end else if CurNode=Node then begin
|
|
||||||
// draw vertical line from top to horizontal line
|
|
||||||
Canvas.MoveTo(CurMid,NodeRect.Top);
|
|
||||||
if ((InsertMarkNode=Node) and (InsertMarkType=tvimAsNextSibling)) then
|
|
||||||
Canvas.LineTo(CurMid,NodeRect.Bottom-1)
|
|
||||||
else
|
else
|
||||||
Canvas.LineTo(CurMid,VertMid);
|
DrawVertLine(CurMid, NodeRect.Top, NodeRect.Bottom);
|
||||||
|
end else
|
||||||
|
if (CurNode = Node) then
|
||||||
|
begin
|
||||||
|
// draw vertical line from top to horizontal line
|
||||||
|
if ((InsertMarkNode = Node) and (InsertMarkType=tvimAsNextSibling)) then
|
||||||
|
DrawVertLine(CurMid, NodeRect.Top, NodeRect.Bottom-1)
|
||||||
|
else
|
||||||
|
DrawVertLine(CurMid, NodeRect.Top, VertMid);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
inc(Result,Indent);
|
inc(Result, Indent);
|
||||||
end else begin
|
end else
|
||||||
Result:=BorderWidth-FScrolledLeft;
|
Result := BorderWidth - FScrolledLeft;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure DrawExpandSign(MidX,MidY: integer; CollapseSign: boolean);
|
procedure DrawExpandSign(MidX,MidY: integer; CollapseSign: boolean);
|
||||||
var HalfSize, ALeft, ATop, ARight, ABottom: integer;
|
var
|
||||||
|
HalfSize, ALeft, ATop, ARight, ABottom: integer;
|
||||||
Points: PPoint;
|
Points: PPoint;
|
||||||
begin
|
begin
|
||||||
if not ShowButtons then exit;
|
if not ShowButtons then exit;
|
||||||
with Canvas do begin
|
with Canvas do
|
||||||
|
begin
|
||||||
Brush.Color:=BackgroundColor;
|
Brush.Color:=BackgroundColor;
|
||||||
Pen.Color:=FExpandSignColor;
|
Pen.Color:=FExpandSignColor;
|
||||||
Pen.Style:=psSolid;
|
Pen.Style:=psSolid;
|
||||||
@ -4132,7 +4153,8 @@ var
|
|||||||
Rectangle(ALeft, ATop, ARight+1, ABottom+1);
|
Rectangle(ALeft, ATop, ARight+1, ABottom+1);
|
||||||
MoveTo(ALeft+2,MidY);
|
MoveTo(ALeft+2,MidY);
|
||||||
LineTo(ARight-2+1,MidY);
|
LineTo(ARight-2+1,MidY);
|
||||||
if not CollapseSign then begin
|
if not CollapseSign then
|
||||||
|
begin
|
||||||
MoveTo(MidX,ATop+2);
|
MoveTo(MidX,ATop+2);
|
||||||
LineTo(MidX,ABottom-2+1);
|
LineTo(MidX,ABottom-2+1);
|
||||||
end;
|
end;
|
||||||
@ -4141,12 +4163,14 @@ var
|
|||||||
begin
|
begin
|
||||||
// draw an arrow. down for collapse and right for expand
|
// draw an arrow. down for collapse and right for expand
|
||||||
GetMem(Points,SizeOf(TPoint)*3);
|
GetMem(Points,SizeOf(TPoint)*3);
|
||||||
if CollapseSign then begin
|
if CollapseSign then
|
||||||
|
begin
|
||||||
// draw an arrow down
|
// draw an arrow down
|
||||||
Points[0]:=Point(ALeft,MidY);
|
Points[0]:=Point(ALeft,MidY);
|
||||||
Points[1]:=Point(ARight,MidY);
|
Points[1]:=Point(ARight,MidY);
|
||||||
Points[2]:=Point(MidX,ABottom);
|
Points[2]:=Point(MidX,ABottom);
|
||||||
end else begin
|
end else
|
||||||
|
begin
|
||||||
// draw an arrow right
|
// draw an arrow right
|
||||||
Points[0]:=Point(MidX-1,ATop);
|
Points[0]:=Point(MidX-1,ATop);
|
||||||
Points[1]:=Point(ARight-1,MidY);
|
Points[1]:=Point(ARight-1,MidY);
|
||||||
@ -4237,18 +4261,20 @@ var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var x, ImgIndex: integer;
|
var
|
||||||
|
x, ImgIndex: integer;
|
||||||
CurBackgroundColor, OldFontColor: TColor;
|
CurBackgroundColor, OldFontColor: TColor;
|
||||||
CurTextRect: TRect;
|
CurTextRect: TRect;
|
||||||
DrawState: TCustomDrawState;
|
DrawState: TCustomDrawState;
|
||||||
PaintImages: boolean;
|
PaintImages: boolean;
|
||||||
TextY: Integer;
|
TextY: Integer;
|
||||||
begin
|
begin
|
||||||
NodeRect:=Node.DisplayRect(false);
|
NodeRect := Node.DisplayRect(false);
|
||||||
if (NodeRect.Bottom<0) or (NodeRect.Top>=(ClientHeight-ScrollBarWidth)) then
|
if (NodeRect.Bottom<0) or (NodeRect.Top>=(ClientHeight-ScrollBarWidth)) then
|
||||||
exit;
|
exit;
|
||||||
NodeSelected:=(Node.Selected) or (Node.MultiSelected);
|
NodeSelected:=(Node.Selected) or (Node.MultiSelected);
|
||||||
if Assigned(OnCustomDrawItem) or Assigned(FOnAdvancedCustomDrawItem) then begin
|
if Assigned(OnCustomDrawItem) or Assigned(FOnAdvancedCustomDrawItem) then
|
||||||
|
begin
|
||||||
DrawState:=[];
|
DrawState:=[];
|
||||||
if NodeSelected then
|
if NodeSelected then
|
||||||
Include(DrawState,cdsSelected);
|
Include(DrawState,cdsSelected);
|
||||||
@ -4257,32 +4283,38 @@ begin
|
|||||||
if Node.MultiSelected then
|
if Node.MultiSelected then
|
||||||
Include(DrawState,cdsMarked);
|
Include(DrawState,cdsMarked);
|
||||||
if not CustomDrawItem(Node,DrawState,cdPrePaint,PaintImages) then exit;
|
if not CustomDrawItem(Node,DrawState,cdPrePaint,PaintImages) then exit;
|
||||||
end else begin
|
end
|
||||||
|
else
|
||||||
PaintImages:=true;
|
PaintImages:=true;
|
||||||
end;
|
|
||||||
VertMid:=(NodeRect.Top+NodeRect.Bottom) div 2;
|
VertMid:=(NodeRect.Top + NodeRect.Bottom) div 2;
|
||||||
//DebugLn(['[TCustomTreeView.DoPaintNode] Node=',DbgS(Node),' Node.Text=',Node.Text,' NodeRect=',NodeRect.Left,',',NodeRect.Top,',',NodeRect.Right,',',NodeRect.Bottom,' VertMid=',VertMid]);
|
//DebugLn(['[TCustomTreeView.DoPaintNode] Node=',DbgS(Node),' Node.Text=',Node.Text,' NodeRect=',NodeRect.Left,',',NodeRect.Top,',',NodeRect.Right,',',NodeRect.Bottom,' VertMid=',VertMid]);
|
||||||
with Canvas do begin
|
with Canvas do
|
||||||
|
begin
|
||||||
// draw background
|
// draw background
|
||||||
if (tvoRowSelect in FOptions) and NodeSelected then
|
if (tvoRowSelect in FOptions) and NodeSelected then
|
||||||
CurBackgroundColor:=FSelectedColor
|
CurBackgroundColor:=FSelectedColor
|
||||||
else
|
else
|
||||||
CurBackgroundColor:=FBackgroundColor;
|
CurBackgroundColor:=FBackgroundColor;
|
||||||
if CurBackgroundColor<>clNone then begin
|
if CurBackgroundColor<>clNone then
|
||||||
|
begin
|
||||||
Brush.Color:=CurBackgroundColor;
|
Brush.Color:=CurBackgroundColor;
|
||||||
FillRect(NodeRect);
|
FillRect(NodeRect);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// draw tree lines
|
// draw tree lines
|
||||||
Pen.Color:=TreeLineColor;
|
Pen.Color:=TreeLineColor;
|
||||||
Pen.Style:=TreeLinePenStyle;
|
Pen.Style:=TreeLinePenStyle;
|
||||||
x:=DrawTreeLines(Node);
|
x:=DrawTreeLines(Node);
|
||||||
Pen.Style:=psSolid;
|
Pen.Style:=psSolid;
|
||||||
|
|
||||||
// draw expand sign
|
// draw expand sign
|
||||||
if Node.HasChildren then begin
|
if Node.HasChildren then
|
||||||
DrawExpandSign(x-Indent+(Indent shr 1),VertMid,Node.Expanded);
|
DrawExpandSign(x - Indent + (Indent shr 1), VertMid, Node.Expanded);
|
||||||
end;
|
|
||||||
// draw icon
|
// draw icon
|
||||||
if (Images<>nil) and PaintImages then begin
|
if (Images<>nil) and PaintImages then
|
||||||
|
begin
|
||||||
if FSelectedNode<>Node then
|
if FSelectedNode<>Node then
|
||||||
ImgIndex:=Node.ImageIndex
|
ImgIndex:=Node.ImageIndex
|
||||||
else
|
else
|
||||||
@ -4291,14 +4323,18 @@ begin
|
|||||||
Images.Draw(Canvas,x+1,NodeRect.Top,ImgIndex,true);
|
Images.Draw(Canvas,x+1,NodeRect.Top,ImgIndex,true);
|
||||||
inc(x,Images.Width+2);
|
inc(x,Images.Width+2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// draw state icon
|
// draw state icon
|
||||||
if (StateImages<>nil) and PaintImages then begin
|
if (StateImages<>nil) and PaintImages then
|
||||||
|
begin
|
||||||
if (Node.StateIndex>=0) and (Node.StateIndex<StateImages.Count) then
|
if (Node.StateIndex>=0) and (Node.StateIndex<StateImages.Count) then
|
||||||
StateImages.Draw(Canvas,x+1,NodeRect.Top,Node.StateIndex,true);
|
StateImages.Draw(Canvas,x+1,NodeRect.Top,Node.StateIndex,true);
|
||||||
inc(x,StateImages.Width+2);
|
inc(x,StateImages.Width+2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
if Node.Text<>'' then begin
|
if Node.Text <> '' then
|
||||||
|
begin
|
||||||
TextY:=NodeRect.Top+
|
TextY:=NodeRect.Top+
|
||||||
((NodeRect.Bottom-NodeRect.Top-TextHeight(Node.Text)) div 2);
|
((NodeRect.Bottom-NodeRect.Top-TextHeight(Node.Text)) div 2);
|
||||||
if NodeSelected and (FSelectedColor<>clNone) then begin
|
if NodeSelected and (FSelectedColor<>clNone) then begin
|
||||||
@ -4311,16 +4347,19 @@ begin
|
|||||||
FillRect(CurTextRect);
|
FillRect(CurTextRect);
|
||||||
TextOut(x,TextY,Node.Text);
|
TextOut(x,TextY,Node.Text);
|
||||||
Font.Color:=OldFontColor;
|
Font.Color:=OldFontColor;
|
||||||
end else begin
|
end
|
||||||
|
else
|
||||||
TextOut(x,TextY,Node.Text);
|
TextOut(x,TextY,Node.Text);
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
// draw separator
|
// draw separator
|
||||||
if (tvoShowSeparators in FOptions) then begin
|
if (tvoShowSeparators in FOptions) then
|
||||||
|
begin
|
||||||
Pen.Color:=SeparatorColor;
|
Pen.Color:=SeparatorColor;
|
||||||
MoveTo(NodeRect.Left,NodeRect.Bottom-1);
|
MoveTo(NodeRect.Left,NodeRect.Bottom-1);
|
||||||
LineTo(NodeRect.Right,NodeRect.Bottom-1);
|
LineTo(NodeRect.Right,NodeRect.Bottom-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// draw insert mark
|
// draw insert mark
|
||||||
DrawInsertMark;
|
DrawInsertMark;
|
||||||
end;
|
end;
|
||||||
@ -4334,9 +4373,9 @@ begin
|
|||||||
if Node.MultiSelected then
|
if Node.MultiSelected then
|
||||||
Include(DrawState,cdsMarked);
|
Include(DrawState,cdsMarked);
|
||||||
if not CustomDrawItem(Node,DrawState,cdPostPaint,PaintImages) then exit;
|
if not CustomDrawItem(Node,DrawState,cdPostPaint,PaintImages) then exit;
|
||||||
end else begin
|
end
|
||||||
PaintImages:=true;
|
else
|
||||||
end;
|
PaintImages := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomTreeView.GetImageIndex(Node: TTreeNode);
|
procedure TCustomTreeView.GetImageIndex(Node: TTreeNode);
|
||||||
|
Loading…
Reference in New Issue
Block a user