Skip to content

Commit 1d74f37

Browse files
committed
Fix dragging header
1 parent b3745ba commit 1d74f37

File tree

1 file changed

+86
-81
lines changed

1 file changed

+86
-81
lines changed

Source/VirtualTrees.pas

Lines changed: 86 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -10307,18 +10307,19 @@ function TVTHeader.HandleHeaderMouseMove(var Message: TLMMouseMove): Boolean;
1030710307
HandleHeaderMouseMove := True;
1030810308
Result := 0;
1030910309
end
10310-
else if hsHeightTrackPending in FStates then
10311-
begin
10312-
FStates := FStates - [hsHeightTrackPending] + [hsHeightTracking];
10313-
HandleHeaderMouseMove := True;
10314-
Result := 0;
10315-
end
1031610310
else
10317-
if hsColumnWidthTracking in FStates then
10311+
if hsHeightTrackPending in FStates then
1031810312
begin
10319-
if DoColumnWidthTracking(FColumns.FTrackIndex, GetShiftState, FTrackPoint, P) then
10313+
FStates := FStates - [hsHeightTrackPending] + [hsHeightTracking];
10314+
HandleHeaderMouseMove := True;
10315+
Result := 0;
10316+
end
10317+
else
10318+
if hsColumnWidthTracking in FStates then
10319+
begin
10320+
if DoColumnWidthTracking(FColumns.FTrackIndex, GetShiftState, FTrackPoint, P) then
1032010321
begin
10321-
if Treeview.UseRightToLeftAlignment then
10322+
if Treeview.UseRightToLeftAlignment then
1032210323
begin
1032310324
NewWidth := FTrackPoint.X - XPos;
1032410325
NextColumn := FColumns.GetPreviousVisibleColumn(FColumns.FTrackIndex);
@@ -10337,56 +10338,57 @@ function TVTHeader.HandleHeaderMouseMove(var Message: TLMMouseMove): Boolean;
1033710338
(FColumns[FColumns.FTrackIndex].FMaxWidth > NewWidth) then
1033810339
FColumns[NextColumn].Width := FColumns[NextColumn].Width - NewWidth
1033910340
+ FColumns[FColumns.FTrackIndex].Width
10340-
else
10341-
FColumns[FColumns.FTrackIndex].Width := NewWidth; // 1 EListError seen here (List index out of bounds (-1)) since 10/2013
10342-
HandleHeaderMouseMove := True;
10343-
Result := 0;
10344-
end
10345-
else if hsHeightTracking in FStates then
10346-
begin
10347-
//lclheader
10348-
//fixes setting height
10349-
Dec(P.Y, FHeight);
10350-
if DoHeightTracking(P, GetShiftState) then
10351-
SetHeight(Integer(FHeight) + P.Y);
10352-
HandleHeaderMouseMove := True;
10353-
Result := 0;
10354-
end
10355-
else
10356-
begin
10357-
if hsDragPending in FStates then
10358-
begin
10359-
P := Treeview.ClientToScreen(P);
10360-
// start actual dragging if allowed
10361-
if (hoDrag in FOptions) and Treeview.DoHeaderDragging(FColumns.FDownIndex) then
10362-
begin
10363-
if ((Abs(FDragStart.X - P.X) > DragManager.DragThreshold) or
10364-
(Abs(FDragStart.Y - P.Y) > DragManager.DragThreshold)) then
10365-
begin
10366-
{$ifdef DEBUG_VTV}Logger.Send([lcDrag], 'HandleHeaderMouseMove - DragIndex: %d - DownIndex: %d',
10367-
[FColumns.FDragIndex, FColumns.FDownIndex]);{$endif}
10368-
I := FColumns.FDownIndex;
10369-
FColumns.FDownIndex := NoColumn;
10370-
FColumns.FHoverIndex := NoColumn;
10371-
if I > NoColumn then
10372-
Invalidate(FColumns[I]);
10373-
//todo: implement drag image under gtk
10374-
PrepareDrag(P, FDragStart);
10375-
FStates := FStates - [hsDragPending] + [hsDragging];
10376-
HandleHeaderMouseMove := True;
10377-
Result := 0;
10378-
end;
10341+
else
10342+
FColumns[FColumns.FTrackIndex].Width := NewWidth; // 1 EListError seen here (List index out of bounds (-1)) since 10/2013
1037910343
end;
10344+
HandleHeaderMouseMove := True;
10345+
Result := 0;
1038010346
end
1038110347
else
10382-
if hsDragging in FStates then
10348+
if hsHeightTracking in FStates then
1038310349
begin
10384-
DragTo(Treeview.ClientToScreen(P));
10350+
//lclheader
10351+
//fixes setting height
10352+
Dec(P.Y, FHeight);
10353+
if DoHeightTracking(P, GetShiftState) then
10354+
SetHeight(Integer(FHeight) + P.Y);
1038510355
HandleHeaderMouseMove := True;
1038610356
Result := 0;
10357+
end
10358+
else
10359+
begin
10360+
if hsDragPending in FStates then
10361+
begin
10362+
P := Treeview.ClientToScreen(P);
10363+
// start actual dragging if allowed
10364+
if (hoDrag in FOptions) and Treeview.DoHeaderDragging(FColumns.FDownIndex) then
10365+
begin
10366+
if ((Abs(FDragStart.X - P.X) > DragManager.DragThreshold) or
10367+
(Abs(FDragStart.Y - P.Y) > DragManager.DragThreshold)) then
10368+
begin
10369+
{$ifdef DEBUG_VTV}Logger.Send([lcDrag], 'HandleHeaderMouseMove - DragIndex: %d - DownIndex: %d',
10370+
[FColumns.FDragIndex, FColumns.FDownIndex]);{$endif}
10371+
I := FColumns.FDownIndex;
10372+
FColumns.FDownIndex := NoColumn;
10373+
FColumns.FHoverIndex := NoColumn;
10374+
if I > NoColumn then
10375+
Invalidate(FColumns[I]);
10376+
//todo: implement drag image under gtk
10377+
PrepareDrag(P, FDragStart);
10378+
FStates := FStates - [hsDragPending] + [hsDragging];
10379+
HandleHeaderMouseMove := True;
10380+
Result := 0;
10381+
end;
10382+
end;
10383+
end
10384+
else
10385+
if hsDragging in FStates then
10386+
begin
10387+
DragTo(Treeview.ClientToScreen(P));
10388+
HandleHeaderMouseMove := True;
10389+
Result := 0;
10390+
end;
1038710391
end;
10388-
end;
10389-
end;
1039010392
end;
1039110393
end;
1039210394

@@ -10440,15 +10442,16 @@ function TVTHeader.HandleMessage(var Message: TLMessage): Boolean;
1044010442
begin
1044110443
if not (tsWindowCreating in FOwner.FStates) then
1044210444
if (hoAutoResize in FOptions) and not (hsAutoSizing in FStates) then
10443-
begin
10444-
FColumns.AdjustAutoSize(InvalidColumn);
10445-
Invalidate(nil);
10446-
end
10447-
else if not (hsScaling in FStates) then
1044810445
begin
10449-
RescaleHeader;
10446+
FColumns.AdjustAutoSize(InvalidColumn);
1045010447
Invalidate(nil);
10451-
end;
10448+
end
10449+
else
10450+
if not (hsScaling in FStates) then
10451+
begin
10452+
RescaleHeader;
10453+
Invalidate(nil);
10454+
end;
1045210455
end;
1045310456
CM_PARENTFONTCHANGED:
1045410457
if FParentFont then
@@ -10497,31 +10500,33 @@ function TVTHeader.HandleMessage(var Message: TLMessage): Boolean;
1049710500
SetHeight(FMinHeight);
1049810501
Result := True;
1049910502
end
10500-
else if HSplitterHit and (Message.Msg = LM_LBUTTONDBLCLK) and
10501-
(hoDblClickResize in FOptions) and (FColumns.FTrackIndex > NoColumn) then
10502-
begin
10503-
// If the click was on a splitter then resize column to smallest width.
10504-
if DoColumnWidthDblClickResize(FColumns.FTrackIndex, P, GetShiftState) then
10503+
else
10504+
if HSplitterHit and (Message.Msg = LM_LBUTTONDBLCLK) and
10505+
(hoDblClickResize in FOptions) and (FColumns.FTrackIndex > NoColumn) then
10506+
begin
10507+
// If the click was on a splitter then resize column to smallest width.
10508+
if DoColumnWidthDblClickResize(FColumns.FTrackIndex, P, GetShiftState) then
1050510509
AutoFitColumns(True, smaUseColumnOption, FColumns[FColumns.FTrackIndex].FPosition,
1050610510
FColumns[FColumns.FTrackIndex].FPosition);
10507-
Message.Result := 0;
10508-
Result := True;
10509-
end
10510-
else if IsInHeader and (Message.Msg <> LM_LBUTTONDBLCLK) then
10511-
begin
10512-
case Message.Msg of
10513-
LM_MBUTTONDBLCLK:
10514-
Button := mbMiddle;
10515-
LM_RBUTTONDBLCLK:
10516-
Button := mbRight;
10511+
Message.Result := 0;
10512+
Result := True;
10513+
end
1051710514
else
10518-
// WM_NCLBUTTONDBLCLK
10519-
Button := mbLeft;
10520-
end;
10521-
if Button = mbLeft then
10522-
Columns.AdjustDownColumn(P);
10523-
FColumns.HandleClick(P, Button, True, True);
10524-
end;
10515+
if IsInHeader and (Message.Msg <> LM_LBUTTONDBLCLK) then
10516+
begin
10517+
case Message.Msg of
10518+
LM_MBUTTONDBLCLK:
10519+
Button := mbMiddle;
10520+
LM_RBUTTONDBLCLK:
10521+
Button := mbRight;
10522+
else
10523+
// WM_NCLBUTTONDBLCLK
10524+
Button := mbLeft;
10525+
end;
10526+
if Button = mbLeft then
10527+
Columns.AdjustDownColumn(P);
10528+
FColumns.HandleClick(P, Button, True, True);
10529+
end;
1052510530
end;
1052610531
// The "hot" area of the headers horizontal splitter is partly within the client area of the the tree, so we need
1052710532
// to handle WM_LBUTTONDOWN here, too.

0 commit comments

Comments
 (0)