From 0558c2b8fa066b3452663481926c0e63d0fec2b9 Mon Sep 17 00:00:00 2001 From: marc Date: Tue, 16 Jan 2007 23:56:44 +0000 Subject: [PATCH] * Drag drop cursor patch from Paul Ishenin git-svn-id: trunk@10459 - --- lcl/include/dragdock.inc | 17 +++++++++++++++-- lcl/include/dragobject.inc | 5 ++++- lcl/interfaces/win32/win32callback.inc | 19 +++++++++++++------ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lcl/include/dragdock.inc b/lcl/include/dragdock.inc index 2ec0d52e9b..a653382808 100644 --- a/lcl/include/dragdock.inc +++ b/lcl/include/dragdock.inc @@ -21,6 +21,7 @@ var DragStartPos: TPoint; // mouse position at start of drag ActiveDrag: TDragOperation;// current phase of drag operation DragThreshold: Integer;// treshold before the drag becomes activated + DragStartCursor: hCursor; // cursor that was before dragging Procedure DragTo(const Position: TPoint); forward; @@ -162,6 +163,14 @@ begin DragObject.DragTarget := nil; GetCursorPos(DragStartPos); DragObject.DragPos := DragStartPos; + + // get current cursor + // But this would not be work if control sets its cursor via WM_SETCURSOR + // to handle such situaltions we must call here: WidgetSet.GetCursor + if Screen.Cursor = crDefault then + DragStartCursor := Screen.Cursors[Control.Cursor] else + DragStartCursor := Screen.Cursors[Screen.Cursor]; + //DragCapture := DragObject.Capture; DragThreshold := Threshold; @@ -237,6 +246,7 @@ end; Procedure DragTo(const Position: TPoint); var TargetControl: TControl; + ADragCursor: TCursor; Begin {$IFDEF VerboseDrag} DebugLn('DragTo P=',Position.X,',',Position.Y); @@ -268,10 +278,12 @@ Begin DragObject.DragPos := Position; SendDragOver(dmDragEnter); if DragObject = nil then Exit; - end else begin + end else + begin // same target => send dmDragMove DragObject.DragPos := Position; - SendDragOver(dmDragMove); + ADragCursor := DragObject.GetDragCursor(SendDragOver(dmDragMove), Position.X, Position.Y); + WidgetSet.SetCursor(Screen.Cursors[ADragCursor]); if DragObject = nil then Exit; end; @@ -335,6 +347,7 @@ Begin // erase global variables (dragging stopped) DragControl := nil; DragObject := nil; + WidgetSet.SetCursor(DragStartCursor); // drop if (OldDragObject<>nil) and (OldDragObject.DragTarget <> nil) then diff --git a/lcl/include/dragobject.inc b/lcl/include/dragobject.inc index 9e484cf812..d8034a4097 100644 --- a/lcl/include/dragobject.inc +++ b/lcl/include/dragobject.inc @@ -132,7 +132,10 @@ end; function TDragControlObject.GetDragCursor(Accepted: Boolean; X, Y: Integer ): TCursor; begin - Result:=inherited GetDragCursor(Accepted, X, Y); + //Result := inherited GetDragCursor(Accepted, X, Y); + if Accepted then + Result := Control.DragCursor else + Result := crNoDrop; end; function TDragControlObject.GetDragImages: TDragImageList; diff --git a/lcl/interfaces/win32/win32callback.inc b/lcl/interfaces/win32/win32callback.inc index d569dda946..b8bccd3684 100644 --- a/lcl/interfaces/win32/win32callback.inc +++ b/lcl/interfaces/win32/win32callback.inc @@ -674,6 +674,7 @@ Var var lControl: TControl; BoundsOffset: TRect; + ACursor: TCursor; begin if (lWinControl <> nil) and not (csDesigning in lWinControl.ComponentState) and (LOWORD(LParam) = HTCLIENT) then @@ -685,13 +686,19 @@ Var Dec(P.X, BoundsOffset.Left); Dec(P.Y, BoundsOffset.Top); end; - // statictext controls do not get WM_SETCURSOR messages... - lControl := lWinControl.ControlAtPos(P, false, true); - if lControl = nil then - lControl := lWinControl; - if lControl.Cursor <> crDefault then + ACursor := Screen.Cursor; + if ACursor = crDefault then begin - Windows.SetCursor(Screen.Cursors[lControl.Cursor]); + // statictext controls do not get WM_SETCURSOR messages... + lControl := lWinControl.ControlAtPos(P, false, true); + if lControl = nil then + lControl := lWinControl; + if lControl.Cursor <> crDefault then + ACursor := lControl.Cursor; + end; + if ACursor <> crDefault then + begin + Windows.SetCursor(Screen.Cursors[ACursor]); LMessage.Result := 1; end; end;