1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
{%MainUnit ../controls.pp}
{******************************************************************************
TDragObject
******************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
type
{ TDockImageWindow - used if widgetset supports hints with alphablend }
TDockImageWindow = class(THintWindow)
public
constructor Create(AOwner: TComponent); override;
end;
constructor TDockImageWindow.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Color := clHighlight;
Width := 100;
Height := 100;
AlphaBlend := True;
AlphaBlendValue := 100;
end;
var
DockImageWindow: TDockImageWindow;
procedure HintDockImage(Sender: TObject; AOldRect, ANewRect: TRect;
AOperation: TDockImageOperation);
begin
if DockImageWindow = nil then
DockImageWindow := TDockImageWindow.Create(Application);
DockImageWindow.BoundsRect := ANewRect;
if AOperation = disShow then
DockImageWindow.Show
else if AOperation = disHide then
DockImageWindow.Hide;
end;
{ TDragObject }
constructor TDragObject.Create(AControl : TControl);
begin
FControl := AControl;
end;
constructor TDragObject.AutoCreate(AControl: TControl);
begin
Create(AControl);
FAutoCreated := True;
FAutoFree := True;
end;
procedure TDragObject.EndDrag(Target: TObject; X, Y: Integer);
begin
if FControl <> nil then
FControl.DoEndDrag(Target, X, Y);
end;
function TDragObject.GetDragImages: TDragImageList;
begin
Result := nil;
end;
function TDragObject.GetDragCursor(Accepted: Boolean; X, Y: Integer): TCursor;
begin
if Accepted then
Result := crDrag
else
Result := crNoDrop;
end;
procedure TDragObject.HideDragImage;
begin
if GetDragImages <> nil then
GetDragImages.HideDragImage;
end;
procedure TDragObject.ShowDragImage;
begin
if GetDragImages <> nil then
GetDragImages.ShowDragImage;
end;
{ TDragObjectEx }
constructor TDragObjectEx.Create(AControl: TControl);
begin
inherited Create(AControl);
FAutoFree := True;
end;
{ TDragControlObject }
function TDragControlObject.GetDragCursor(Accepted: Boolean; X, Y: Integer): TCursor;
begin
if Accepted then
Result := Control.DragCursor
else
Result := crNoDrop;
end;
function TDragControlObject.GetDragImages: TDragImageList;
begin
Result := Control.GetDragImages;
end;
{ TDragControlObjectEx }
constructor TDragControlObjectEx.Create(AControl: TControl);
begin
inherited Create(AControl);
FAutoFree := True;
end;
{ TDragDockObject }
procedure TDragDockObject.AdjustDockRect(ARect: TRect);
begin
with DockOffset do
Types.OffsetRect(FDockRect, -X, -Y);
end;
function TDragDockObject.GetDragCursor(Accepted: Boolean; X, Y: Integer): TCursor;
begin
Result := crDefault;
end;
procedure TDragDockObject.EndDrag(Target: TObject; X, Y: Integer);
begin
if FControl <> nil then
FControl.DoEndDock(Target, X, Y);
end;
procedure TDragDockObject.InitDock(APosition: TPoint);
begin
// Determine hotspot scale for adjusting the undocked rectangle.
// Since the undocked extent of the control doesn't change, we fix the hotspot offset.
// Usage: OffsetRect(DockRect, FDockOffset);
DragPos := APosition; //should have been done before
Control.CalculateDockSizes;
// mouse click offset from control TopLeft in screen coordinates
with FDockRect do
begin
TopLeft := Control.ClientToScreen(Point(0, 0));
Right := Left + Control.Width;
Bottom := Top + Control.Height;
end;
if Control.Width > 0 then
FDockOffset.x := Round((APosition.x - FDockRect.Left) / Control.Width * Control.UndockWidth)
else
FDockOffset.X := 0;
if Control.Height > 0 then
FDockOffset.Y := Round((APosition.y - FDockRect.Top) / Control.Height * Control.UndockHeight)
else
FDockOffset.Y := 0;
FEraseDockRect := Rect(MaxInt, 0, MaxInt, 0);
end;
procedure TDragDockObject.ShowDockImage;
begin
if HasOnDrawImage then
OnDrawDockImage(Self, EraseDockRect, DockRect, disShow)
else
WidgetSet.DrawDefaultDockImage(EraseDockRect, DockRect, disShow);
EraseDockRect := DockRect;
end;
procedure TDragDockObject.HideDockImage;
begin
if FEraseDockRect.Left<MaxInt then
if HasOnDrawImage then
OnDrawDockImage(Self, EraseDockRect, DockRect, disHide)
else
WidgetSet.DrawDefaultDockImage(EraseDockRect, DockRect, disHide);
FEraseDockRect := Rect(MaxInt, 0, MaxInt, 0);
end;
procedure TDragDockObject.MoveDockImage;
begin
//Draw the form outlines when the position has changed
if not SameRect(@DockRect, @EraseDockRect) then
begin
if HasOnDrawImage then
OnDrawDockImage(Self, EraseDockRect, DockRect, disMove)
else
WidgetSet.DrawDefaultDockImage(EraseDockRect, DockRect, disMove);
EraseDockRect := DockRect;
end;
end;
function TDragDockObject.HasOnDrawImage: boolean;
begin
if Assigned(OnDrawDockImage) then
exit(true);
if WidgetSet.GetSystemMetrics(SM_LCLHasFormAlphaBlend)=0 then
exit(false);
OnDrawDockImage := @HintDockImage;
Result:=true;
end;
{ TDragDockObjectEx }
constructor TDragDockObjectEx.Create(AControl: TControl);
begin
inherited Create(AControl);
FAutoFree := True;
end;
// included by controls.pp
|