mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-23 08:39:35 +02:00
dockmanager example: notebook page selection
git-svn-id: trunk@26319 -
This commit is contained in:
parent
2787b3b9f6
commit
5720fa2392
@ -32,6 +32,8 @@ unit RegisterEasyDockMgr;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
{.$DEFINE DockMaster} //must match IDE setting
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
@ -42,9 +44,14 @@ uses
|
||||
const
|
||||
DefaultConfigFileName = 'easydocklayout.lyt';
|
||||
type
|
||||
TDockSides = set of TAlign;
|
||||
|
||||
{ TIDEEasyDockMaster }
|
||||
|
||||
{$IFDEF DockMaster}
|
||||
{$ELSE}
|
||||
TIDEDockMaster = TIDELayout;
|
||||
{$ENDIF}
|
||||
TIDEEasyDockMaster = class(TIDEDockMaster)
|
||||
private
|
||||
function DockMasterRestore(const CtrlName: string; ASite: TWinControl
|
||||
@ -53,9 +60,15 @@ type
|
||||
procedure GetDefaultBounds(AForm: TCustomForm; out Creator: TIDEWindowCreator;
|
||||
out NewBounds: TRect; out DockSiblingName: string; out DockAlign: TAlign);
|
||||
public
|
||||
{$IFDEF DockMaster}
|
||||
constructor Create;
|
||||
{$ELSE}
|
||||
constructor Create; override;
|
||||
function AddableInWindowMenu(AForm: TCustomForm): boolean; override;
|
||||
procedure RestoreIDEWindows; override;
|
||||
{$ENDIF}
|
||||
destructor Destroy; override;
|
||||
procedure MakeIDEWindowDockSite(AForm: TCustomForm); override;
|
||||
procedure MakeIDEWindowDockSite(AForm: TCustomForm; ASides: TDockSides = [alBottom]); override;
|
||||
procedure MakeIDEWindowDockable(AControl: TWinControl); override;
|
||||
function IsDockSite(AForm: TCustomForm): boolean;
|
||||
function IsDockable(AForm: TCustomForm): boolean;
|
||||
@ -77,8 +90,13 @@ implementation
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
//required?
|
||||
{$IFDEF DockMaster}
|
||||
LazarusIDE.AddHandlerOnIDERestoreWindows(@IDEEasyDockMaster.OnIDERestoreWindows);
|
||||
LazarusIDE.AddHandlerOnIDEClose(@IDEEasyDockMaster.OnIDEClose);
|
||||
{$ELSE}
|
||||
//should not be required
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{ TIDEEasyDockMaster }
|
||||
@ -125,13 +143,27 @@ begin
|
||||
DockMaster.OnSave:=@DockMasterSave;
|
||||
end;
|
||||
|
||||
{$IFDEF DockMaster}
|
||||
{$ELSE}
|
||||
function TIDEEasyDockMaster.AddableInWindowMenu(AForm: TCustomForm): boolean;
|
||||
begin
|
||||
Result:=inherited AddableInWindowMenu(AForm);
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.RestoreIDEWindows;
|
||||
begin
|
||||
inherited RestoreIDEWindows; //required?
|
||||
LoadDefaultLayout;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
destructor TIDEEasyDockMaster.Destroy;
|
||||
begin
|
||||
IDEEasyDockMaster:=nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.MakeIDEWindowDockSite(AForm: TCustomForm);
|
||||
procedure TIDEEasyDockMaster.MakeIDEWindowDockSite(AForm: TCustomForm; ASides: TDockSides);
|
||||
var
|
||||
Creator: TIDEWindowCreator;
|
||||
NewBounds: TRect;
|
||||
@ -142,7 +174,7 @@ begin
|
||||
GetDefaultBounds(AForm,Creator,NewBounds,DockSiblingName,DockAlign);
|
||||
if Creator<>nil then
|
||||
AForm.BoundsRect:=NewBounds;
|
||||
DockMaster.AddElasticSites(AForm, [alBottom]);
|
||||
DockMaster.AddElasticSites(AForm, ASides);
|
||||
debugln(['TIDEEasyDockMaster.MakeIDEWindowDockSite AFTER ',DbgSName(AForm),' ',dbgs(AForm.BoundsRect)]);
|
||||
end;
|
||||
|
||||
@ -257,10 +289,14 @@ begin
|
||||
AControl:=AForm;
|
||||
while AControl<>nil do begin
|
||||
// ToDo: if this is a page switch pageindex of parent
|
||||
{$IFDEF old}
|
||||
if AControl is TCustomForm then
|
||||
TCustomForm(AControl).Show
|
||||
else
|
||||
AControl.Visible:=true;
|
||||
{$ELSE}
|
||||
AControl.Visible := True;
|
||||
{$ENDIF}
|
||||
AControl:=AControl.Parent;
|
||||
end;
|
||||
AForm.EnableAlign;
|
||||
@ -276,6 +312,7 @@ end;
|
||||
|
||||
procedure TIDEEasyDockMaster.CloseAll;
|
||||
begin
|
||||
SaveDefaultLayout;
|
||||
inherited CloseAll;
|
||||
end;
|
||||
|
||||
@ -293,10 +330,19 @@ initialization
|
||||
// create the dockmaster in the initialization section, so that it is ready
|
||||
// when the Register procedures of the packages are called.
|
||||
TDockMaster.Create(nil);
|
||||
{$IFDEF DockMaster}
|
||||
IDEDockMaster:=TIDEEasyDockMaster.Create;
|
||||
{$ELSE}
|
||||
if IDELayout = nil then
|
||||
IDELayout := TIDEEasyDockMaster.Create;
|
||||
{$ENDIF}
|
||||
|
||||
finalization
|
||||
{$IFDEF DockMaster}
|
||||
FreeAndNil(IDEDockMaster);
|
||||
{$ELSE}
|
||||
FreeAndNil(IDELayout);
|
||||
{$ENDIF}
|
||||
FreeAndNil(DockMaster);
|
||||
|
||||
end.
|
||||
|
@ -262,6 +262,7 @@ type
|
||||
public
|
||||
StayDocked: boolean; //here???
|
||||
class function ReloadSite(AName: string; AOwner: TComponent): TCustomDockSite;
|
||||
procedure ShowForm(AForm: TControl); virtual;
|
||||
function SaveSite: string; virtual;
|
||||
procedure LoadFromStream(strm: TStream); virtual;
|
||||
procedure SaveToStream(strm: TStream); virtual;
|
||||
@ -2200,6 +2201,13 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomDockSite.ShowForm(AForm: TControl);
|
||||
begin
|
||||
(* Notebooks activate this control
|
||||
*)
|
||||
AForm.Visible := True;
|
||||
end;
|
||||
|
||||
function TCustomDockSite.SaveSite: string;
|
||||
var
|
||||
ss: TStringStream;
|
||||
|
@ -65,8 +65,8 @@ uses
|
||||
type
|
||||
TTabButton = class(TToolButton)
|
||||
protected
|
||||
function GetDefaultDockCaption: String; override;
|
||||
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
||||
|
||||
public
|
||||
Control: TControl;
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
@ -111,6 +111,8 @@ type
|
||||
destructor Destroy; override;
|
||||
{$ENDIF}
|
||||
procedure Clear; virtual;
|
||||
procedure ShowForm(AForm: TControl); override;
|
||||
procedure ShowPage(ATab: TTabButton);
|
||||
procedure LoadFromStream(strm: TStream); override;
|
||||
procedure SaveToStream(strm: TStream); override;
|
||||
end;
|
||||
@ -128,6 +130,10 @@ begin
|
||||
//RegisterComponents('Common Controls', [TEasyDockBook]);
|
||||
end;
|
||||
|
||||
type
|
||||
TControlAccess = class(TControl)
|
||||
end;
|
||||
|
||||
{ TEasyDockBook }
|
||||
|
||||
{$IFDEF undockFix}
|
||||
@ -197,6 +203,32 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TEasyDockBook.ShowForm(AForm: TControl);
|
||||
var
|
||||
btn: TTabButton;
|
||||
begin
|
||||
//activate page of this control
|
||||
btn := GetControlTab(AForm);
|
||||
if btn = nil then
|
||||
inherited ShowForm(AForm)
|
||||
else
|
||||
ShowPage(btn);
|
||||
end;
|
||||
|
||||
procedure TEasyDockBook.ShowPage(ATab: TTabButton);
|
||||
begin
|
||||
(* Show the (clicked) page
|
||||
*)
|
||||
if (ATab = nil) or (ATab = CurTab) then
|
||||
exit; //nothing to change
|
||||
|
||||
if CurTab <> nil then
|
||||
CurTab.Control.Visible := false;
|
||||
if ATab.Control <> nil then
|
||||
ATab.Control.Visible := True;
|
||||
CurTab := ATab;
|
||||
end;
|
||||
|
||||
|
||||
procedure TEasyDockBook.FormClose(Sender: TObject;
|
||||
var CloseAction: TCloseAction);
|
||||
@ -385,15 +417,21 @@ end;
|
||||
function TEasyDockBook.GetDefaultDockCaption: string;
|
||||
var
|
||||
i: integer;
|
||||
pg: TToolButton;
|
||||
btn: TToolButton;
|
||||
pg: TTabButton absolute btn;
|
||||
begin
|
||||
(* Update button captions?
|
||||
If 1 control docked: get full caption?
|
||||
*)
|
||||
Result := '';
|
||||
for i := 0 to Tabs.ButtonCount - 1 do begin
|
||||
pg := Tabs.Buttons[i];
|
||||
if Result = '' then
|
||||
Result := pg.Caption
|
||||
btn := Tabs.Buttons[i];
|
||||
if Result <> '' then
|
||||
Result := Result + ', ' + pg.GetDefaultDockCaption
|
||||
else if tabs.ButtonCount = 1 then
|
||||
Result := pg.Control.Caption //full Caption of single client
|
||||
else
|
||||
Result := Result + ', ' + pg.Caption;
|
||||
Result := pg.GetDefaultDockCaption;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -444,12 +482,7 @@ procedure TEasyDockBook.ToolButton1Click(Sender: TObject);
|
||||
var
|
||||
btn: TTabButton absolute Sender;
|
||||
begin
|
||||
if CurTab <> nil then begin
|
||||
CurTab.Control.Visible := false;
|
||||
end;
|
||||
if btn.Control <> nil then
|
||||
btn.Control.Visible := True;
|
||||
CurTab := btn;
|
||||
ShowPage(btn);
|
||||
end;
|
||||
|
||||
{ TTabButton }
|
||||
@ -465,28 +498,26 @@ begin
|
||||
Grouped := True;
|
||||
end;
|
||||
|
||||
function TTabButton.GetDefaultDockCaption: String;
|
||||
begin
|
||||
(* Also update button caption, to reflect an eventually changed control caption.
|
||||
*)
|
||||
if Control = nil then
|
||||
Result:=inherited GetDefaultDockCaption
|
||||
else begin
|
||||
Result := TControlAccess(Control).GetDefaultDockCaption;
|
||||
Caption := Result;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTabButton.MouseMove(Shift: TShiftState; X, Y: Integer);
|
||||
//var AControl: TControl;
|
||||
begin
|
||||
(* Implement dragging of the associated page.
|
||||
*)
|
||||
inherited MouseMove(Shift, X, Y);
|
||||
if (ssLeft in Shift) and not DragManager.IsDragging then begin
|
||||
if Control <> nil then begin
|
||||
{ Problems with TWinControls - must be wrapped into forms :-(
|
||||
//DebugLn('---undock "', Control.GetDefaultDockCaption, '"');
|
||||
DebugLn('---undock "', Control.ClassName, '"');
|
||||
if False and (Control is TWinControl) then begin
|
||||
AControl := Control; //will change when undocked?
|
||||
AControl.ManualDock(nil);
|
||||
if AControl.HostDockSite <> nil then
|
||||
AControl.HostDockSite.BeginDrag(True);
|
||||
end else
|
||||
}
|
||||
//both immediate and delayed drag start seem to work
|
||||
//Control.BeginDrag(False); //delayed docking
|
||||
Control.BeginDrag(True); //immediate drag
|
||||
end;
|
||||
if Control <> nil then
|
||||
Control.BeginDrag(True); //immediate drag
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user