dockmanager example: changed default dock sources to forms, including notebook.

Problems with undocking TControls must be fixed in the LCL first.

git-svn-id: trunk@20042 -
This commit is contained in:
dodi 2009-05-19 08:03:56 +00:00
parent 2add8fb02d
commit 1233ad9781
5 changed files with 84 additions and 8 deletions

View File

@ -33,7 +33,7 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="6">
<Units Count="7">
<Unit0>
<Filename Value="easydocking.lpr"/>
<IsPartOfProject Value="True"/>
@ -72,6 +72,13 @@
<Filename Value="BUGS.txt"/>
<IsPartOfProject Value="True"/>
</Unit5>
<Unit6>
<Filename Value="fdockbook.pas"/>
<ComponentName Value="DockBook"/>
<IsPartOfProject Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="fdockbook"/>
</Unit6>
</Units>
</ProjectOptions>
<CompilerOptions>

View File

@ -10,7 +10,7 @@ uses
fMain in 'fmain.pas' {EasyDockMain},
fDockable in 'fdockable.pas' {Dockable},
EasyDockSite in 'easydocksite.pas',
fTree in 'ftree.pas';
fTree in 'ftree.pas', fdockbook;
{.$R *.res}

View File

@ -52,6 +52,7 @@ done? (unclear whether this is really fixed in the trunk)
{.$DEFINE NoDrop} //patched dragobject?
{.$DEFINE visibility} //handling of invisible clients deserves dock manager notification!
{.$DEFINE restore} //restore button?
{$DEFINE bookform} //using notebook within form?
interface
@ -199,6 +200,9 @@ type
procedure PaintSite(DC: HDC); override;
end;
{$IFDEF bookform}
//use a notebook in it's own form
{$ELSE}
(* Notebook for alCustom docking.
Added behaviour: free self on undock of the last client/page.
The behaviour of TPageControl sucks :-(
@ -211,6 +215,7 @@ type
public
constructor Create(TheOwner: TComponent); override;
end;
{$ENDIF}
const
AlignNames: array[TAlign] of string = (
@ -227,6 +232,10 @@ uses
SysUtils, Types,
math,
Themes, LResources,
{$IFDEF bookform}
fDockBook,
{$ELSE}
{$ENDIF}
LCLproc; //debugging
const
@ -401,7 +410,11 @@ procedure TEasyTree.InsertControl(Control: TControl; InsertAt: TAlign;
var
DropZone, OldZone, NewZone, OldParent, NewParent: TEasyZone;
r: TRect;
{$IFDEF bookform}
NoteBook: TDockBook;
{$ELSE}
NoteBook: TPageControl;
{$ENDIF}
(* special cases:
1) first child in top zone - no orientation
2) second child in top zone - determines orientation
@ -446,18 +459,26 @@ begin
*)
if (InsertAt = alCustom) and (FTopZone.FirstChild <> nil) then begin
//dock into book
if not (DropCtl is TPageControl) then begin
{$IFnDEF bookform}
if (DropCtl is TPageControl) then begin
NoteBook := DropCtl as TPageControl;
end else begin
//create new book
NoteBook := TEasyBook.Create(FDockSite);
{$IFDEF old}
NoteBook.Align := alNone;
NoteBook.DragKind := dkDock;
NoteBook.DragMode := dmAutomatic;
{$ELSE}
NoteBook.ManualDock(nil, nil);
{$ENDIF}
//hack: manually dock the notebook
FReplacingControl := NoteBook; //ignore insert (see above)
NoteBook.ManualDock(FDockSite); //move into DockClients[]
DropZone.ChildControl := NoteBook; //put into the zone
{ TODO -cdocking : make the notebook take the desired position }
r := DropZone.GetPartRect(zpClient);
{$IFDEF debug}
DebugLn('NoteBook as (%d,%d)-(%d,%d)', [r.Top, r.Left, r.Bottom, r.Right]);
NoteBook.BoundsRect := r;
r := NoteBook.BoundsRect;
@ -467,9 +488,55 @@ begin
DropCtl := NoteBook; //put further controls into the notebook
ResetBounds(True); //for some reason only setting the size doesn't work
NoteBook.Update;
{$ELSE}
NoteBook.BoundsRect := r;
r := NoteBook.BoundsRect;
DropCtl.ManualDock(NoteBook); //put the original control into the notebook
//DropCtl := NoteBook; //put further controls into the notebook
{$ENDIF}
end; //else use existing control
Control.ManualDock(TPageControl(DropCtl));
FDockSite.Invalidate;
Control.ManualDock(NoteBook);
NoteBook.ActivePageIndex:=NoteBook.PageCount - 1;
//FDockSite.Invalidate;
{$ELSE}
if (DropCtl is TDockBook) then begin
//will this ever happen?
NoteBook := DropCtl as TDockBook;
end else begin
//create new book
NoteBook := TDockBook.Create(FDockSite);
{$IFDEF old}
NoteBook.Align := alNone;
NoteBook.DragKind := dkDock;
NoteBook.DragMode := dmAutomatic;
{$ELSE}
NoteBook.ManualDock(nil, nil);
{$ENDIF}
//hack: manually dock the notebook
FReplacingControl := NoteBook; //ignore insert (see above)
NoteBook.ManualDock(FDockSite); //move into DockClients[]
DropZone.ChildControl := NoteBook; //put into the zone
{ TODO -cdocking : make the notebook take the desired position }
r := DropZone.GetPartRect(zpClient);
{$IFDEF debug}
DebugLn('NoteBook as (%d,%d)-(%d,%d)', [r.Top, r.Left, r.Bottom, r.Right]);
NoteBook.BoundsRect := r;
r := NoteBook.BoundsRect;
DebugLn('NoteBook is (%d,%d)-(%d,%d)', [r.Top, r.Left, r.Bottom, r.Right]);
DropCtl.ManualDock(NoteBook); //put the original control into the notebook
DropCtl := NoteBook; //put further controls into the notebook
ResetBounds(True); //for some reason only setting the size doesn't work
NoteBook.Update;
{$ELSE}
NoteBook.BoundsRect := r;
DropCtl.ManualDock(NoteBook.Pages); //put the original control into the notebook
//DropCtl := NoteBook; //put further controls into the notebook
{$ENDIF}
end; //else use existing control
Control.ManualDock(NoteBook.Pages);
NoteBook.Pages.ActivePageIndex:=NoteBook.Pages.PageCount - 1;
{$ENDIF}
exit;
end;
@ -1338,6 +1405,9 @@ begin
end; //else empty root zone?
end;
{$IFDEF bookform}
//notebook is a form
{$ELSE}
{ TEasyBook }
constructor TEasyBook.Create(TheOwner: TComponent);
@ -1383,6 +1453,7 @@ begin
Result := Result + ' ' + pg.Caption;
end;
end;
{$ENDIF}
//implement various headers
{$I zoneheader.inc}

View File

@ -1,5 +1,3 @@
{ Das ist eine automatisch erzeugte Lazarus-Ressourcendatei }
LazarusResources.Add('TEasyDockMain','FORMDATA',[
'TPF0'#13'TEasyDockMain'#12'EasyDockMain'#4'Left'#3#168#2#6'Height'#3#29#1#3
+'Top'#2'}'#5'Width'#3#205#1#13'ActiveControl'#7#6'buDump'#7'Caption'#6#12'Ea'

View File

@ -15,7 +15,7 @@ unit fMain;
//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)
{$DEFINE dragForm} //create a form from the draggable images (or drag images)
//dragging forms is not supported on all platforms!