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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
unit fMain;
(* EasyDockSite dock test form by DoDi.
Demonstrates docking of various controls, and related bugs in the LCL.
Beware: writing to e.g. the StatusBar from dock event handlers
can cause relicts of a docking rectangle in the changed text.
*)
(* A dock site should contain no other (not docked) controls.
Delphi docks all controls in a dock site, when a docking manager is assigned.
This does not (yet) work with the LCL :-(
When a docking manager is replaced, the controls should be undocked again?
(depends on the lists, where docked and undocked controls reside in the dock site)
*)
//some defines, to demonstrate LCL flaws
{$DEFINE Docker} //using control (undef: entire form) as dock site
{$DEFINE easy} //using EasyDockSite (undef: default LDockTree)
{.$DEFINE dragForm} //create a form from the draggable images (or drag images)
//dragging forms is not supported on all platforms!
interface
uses
SysUtils, Classes, Graphics, Controls, Forms,
{$IFDEF easy}
//use EasyDockSite
{$ELSE}
LDockTree,
{$ENDIF}
StdCtrls, ComCtrls, ExtCtrls;
type
{ TEasyDockMain }
TEasyDockMain = class(TForm)
buManDock: TButton;
buDockEdit: TButton;
swCaptions: TCheckBox;
pnlDocker: TPanel;
edDock: TEdit;
lbDock: TLabel;
sb: TStatusBar;
ToolBar1: TToolBar;
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
buDump: TButton;
procedure buDockEditClick(Sender: TObject);
procedure buDockEditMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure buManDockClick(Sender: TObject);
procedure DockerUnDock(Sender: TObject; Client: TControl;
NewTarget: TWinControl; var Allow: Boolean);
procedure Shape1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure DockerDockDrop(Sender: TObject; Source: TDragDockObject; X,
Y: Integer);
procedure DockerMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure DockerDockOver(Sender: TObject; Source: TDragDockObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
procedure buDumpClick(Sender: TObject);
procedure swCaptionsChange(Sender: TObject);
private
Docker: TWinControl;
ShapeCount: integer;
public
end;
var
EasyDockMain: TEasyDockMain;
implementation
{$R *.lfm}
uses
fDockable,
{$IFDEF easy}
EasyDockSite,
{$ELSE}
{$ENDIF}
fTree;
procedure TEasyDockMain.Shape1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
df: TDockable;
shp: TShape;
c: TColor;
ctl: TShape;
r: TRect;
begin
(* Clone the clicked shape and make it floating.
*)
if sender is TShape then begin
shp := Sender as TShape;
{$IFDEF dragForm}
df := TDockable.Create(self);
df.Name := 'test' + IntToStr(ShapeCount);
inc(ShapeCount);
sb.SimpleText := df.Name;
c := shp.Brush.Color;
//df.Color := c; - not all widgetsets support TForm.Color!?
df.Shape1.Brush.Color := c;
{ TODO -cdocking : form is not dockable with some widgetsets? }
// all this doesn't help
df.DragKind := dkDock;
df.DragMode := dmAutomatic;
//df.ManualFloat(df.BoundsRect);
df.Visible := True;
if WidgetSet.GetLCLCapability(lcDragDockStartOnTitleClick) <> 0 then begin
sb.SimpleText := 'should dock'
end else begin
sb.SimpleText := 'cannot dock'
end;
{$ELSE}
ctl := TShape.Create(self);
//ctl.Assign(shp);
ctl.Name := 'test' + IntToStr(ShapeCount);
inc(ShapeCount);
ctl.Brush.Color := shp.Brush.Color;
ctl.DragMode := dmAutomatic;
ctl.DragKind := dkDock;
//position the floating control near the clicked shape
r.TopLeft := self.BoundsRect.TopLeft;
r.Right := r.Left + 100;
r.Bottom := r.Top + 100;
ctl.ManualFloat(r);
{$ENDIF}
end;
end;
procedure TEasyDockMain.swCaptionsChange(Sender: TObject);
{$IFDEF easy}
var
fStyle: TEasyHeaderStyle;
begin
if swCaptions.Checked then
fStyle := hsForm
else
fStyle := hsMinimal;
TEasyTree(Docker.DockManager).SetStyle(fStyle);
end;
{$ELSE}
begin
end;
{$ENDIF}
procedure TEasyDockMain.FormCreate(Sender: TObject);
begin
{$IFDEF docker}
pnlDocker.Visible := True;
Docker := pnlDocker;
{$ELSE}
pnlDocker.Visible := False;
Docker := self;
{$ENDIF}
{$IFDEF easy}
Docker.DockManager := TEasyTree.Create(Docker);
swCaptions.Visible := True;
{$ELSE}
//use default dockmanager
swCaptions.Visible := False;
{$ENDIF}
Docker.DockSite := True;
Docker.UseDockManager := True;
Docker.OnDockOver:=@self.DockerDockOver;
Docker.OnDockDrop := @self.DockerDockDrop;
Mouse.DragImmediate := False; //appropriate at least for docking
end;
procedure TEasyDockMain.DockerDockDrop(Sender: TObject;
Source: TDragDockObject; X, Y: Integer);
begin
sb.SimpleText := 'drop!';
end;
procedure TEasyDockMain.DockerMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
//sb.SimpleText := 'move';
//Docker.DockManager.
end;
procedure TEasyDockMain.DockerUnDock(Sender: TObject; Client: TControl;
NewTarget: TWinControl; var Allow: Boolean);
var
s, n: string;
r: TRect;
begin
(* problem: DockObj seems to be invalid - here? how?
*)
{ debug only - problem with exception handling!
DebugLn('--- UnDock ---');
try
if DockObj <> nil then begin
r := DockObj.DockRect;
if DockObj.DropOnControl = nil then
n := '<none>'
else
n := '...'; // DockObj.DropOnControl.Name;
s := Format('drop onto %s[%d,%d - %d,%d] %s', [
n, r.Top, r.Left, r.Bottom, r.Right, AlignNames[DockObj.DropAlign]]);
sb.SimpleText := s;
if DockObj.DropOnControl = DockObj.Control then begin
sb.SimpleText := 'NO undock to self';
Allow := False;
end;
end;
except
sb.SimpleText := '<invalid undock obj>';
end;
}
end;
procedure TEasyDockMain.DockerDockOver(Sender: TObject;
Source: TDragDockObject; X, Y: Integer; State: TDragState;
var Accept: Boolean);
var
s: string;
DropOn: TControl;
r: TRect;
begin
{$IFDEF easy}
//if DropOn = nil then
if Source.DragTarget = nil then
sb.SimpleText := '<drop nowhere>'
else begin
DropOn := Source.DropOnControl;
if DropOn = nil then
DropOn := Source.DragTarget;
r := Source.DockRect;
s := Format('drop onto %s[%d,%d - %d,%d] %s', [
DropOn.Name, r.Top, r.Left, r.Bottom, r.Right, AlignNames[Source.DropAlign]]);
sb.SimpleText := s;
end;
{$ELSE}
{$ENDIF}
{ we cannot prevent undocking right now :-(
if Source.DropOnControl = Source.Control then
Accept := False;
}
end;
procedure TEasyDockMain.buDockEditClick(Sender: TObject);
begin
(* A Click event seems not to work - because the mouse button is already up?
*)
edDock.BeginDrag(True);
end;
procedure TEasyDockMain.buDockEditMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
edDock.BeginDrag(True);
end;
procedure TEasyDockMain.buDumpClick(Sender: TObject);
var
s: TStringStream;
begin
if not (Docker.DockManager is TEasyTree) then
exit;
s := TStringStream.Create('');
try
TEasyTree(Docker.DockManager).DumpToStream(s);
DumpBox.Memo1.Text := s.DataString;
finally
s.Free;
end;
DumpBox.Visible := True;
sb.SimpleText := lbDock.Name;
end;
procedure TEasyDockMain.buManDockClick(Sender: TObject);
begin
if buManDock.HostDockSite = nil then
buManDock.ManualDock(Docker);
end;
end.
|