TDockMgr is a component wrapper for TLazDockingMananger.

An application can now be easily extended to support docking, by merely 
placing TDockMgr on any one form, and capturing others by calling this:

        DockMgr1.Capture;

and then clicking/selecting the form to be captured, or like this:

        DockMgr1.Capture(Form2);

to capture form2 specifically, or like this:

        DockMgr1.Capture(Self);

to capture self only.

The captured form then gets an extended PopUpMenu item 'Docking', which 
displays the TLazControlDocker form for docking options.

Many Bugs like:

        Forms with menus are not handled correctly.
        Layout alClient is not implemented.

Todo:
        Fix bugs.
        Convince non-application forms to be docked.

Your comments/fixes/improvements are most welcome!

Thanks!

--
Al




unit DockMgr; 

{$mode objfpc}{$H+}

interface

uses
  Classes, Forms, Menus, ExtCtrls, LDockCtrl;

type

  { TDockMgr }

  TDockMgr = class(TComponent)
  private
    FCapture: TForm;
    FOnCaptured: TNotifyEvent;
    FTimer: TTimer;
    Fdkm: TLazDockingManager;
    procedure DoCapture(Sender: TObject);
  public
    procedure Capture(Sender: TForm = nil);
  published
    property OnCaptured: TNotifyEvent read FOnCaptured write FOnCaptured;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [TDockMgr]);
end;


{ TDockMgr }

procedure TDockMgr.DoCapture(Sender: TObject);
begin
  if Fcapture <> forms.Screen.ActiveForm  then begin

    if Sender = FTimer
    then FCapture := forms.Screen.ActiveForm
    else FCapture := TForm(Sender);

    FTimer.Enabled:=false;

    if not Assigned(Fdkm.FindDockerByControl(FCapture,nil)) then begin

      if not Assigned(FCapture.PopupMenu)
      then FCapture.PopupMenu:=TPopUpMenu.Create(FCapture);

      TLazControlDocker.Create(FCapture).manager:=Fdkm;

    end;

    if Assigned(FOnCaptured) then FOnCaptured(FCapture);

  end;
end;

procedure TDockMgr.Capture(Sender: TForm);
begin

  if not Assigned(Fdkm) then begin
    Fdkm:=TLazDockingManager.Create(self);
    FTimer:=TTimer.Create(Self);
    FTimer.Enabled:=false;
    FTimer.OnTimer:[EMAIL PROTECTED];
  end;

  if Assigned(Sender) then begin
    FCapture:=nil;
    DoCapture(Sender);
  end else begin
    FCapture:=forms.Screen.ActiveForm;
    FTimer.Enabled:=not FTimer.Enabled;
  end;

end;

initialization

end.

Reply via email to