Ignore:
Timestamp:
Sep 17, 2010, 12:55:46 PM (14 years ago)
Author:
george
Message:
  • Přidáno: Zkušební podpora pro záložky.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • DockManager/Lazarus/UCustomDockManager.pas

    r46 r47  
    77uses
    88  Classes, SysUtils, Controls, LCLType, LMessages, Graphics, StdCtrls,
    9   Buttons, ExtCtrls, Contnrs, Forms;
     9  Buttons, ExtCtrls, Contnrs, Forms, ComCtrls, Dialogs;
    1010
    1111const
     
    2424  end;
    2525
     26  TDockStyle = (dsList, dsTabs);
     27
    2628  { TDockClientPanel }
    2729
    2830  TDockClientPanel = class(TPanel)
     31  private
     32    FShowHeader: Boolean;
     33    procedure SetShowHeader(const AValue: Boolean);
     34  public
    2935    OwnerDockManager: TCustomDockManager;
    3036    CloseButton: TSpeedButton;
     
    4046    procedure CloseButtonClick(Sender: TObject);
    4147    procedure ResizeExecute(Sender: TObject);
     48    property ShowHeader: Boolean read FShowHeader write SetShowHeader;
    4249  end;
    4350
     
    4653  TCustomDockManager = class(TDockManager)
    4754  private
     55    FDockStyle: TDockStyle;
     56    TabControl: TTabControl;
    4857    FDockDirection: TDockDirection;
    4958    FDockSite: TWinControl;
     
    5261    procedure InsertControlPanel(Control: TControl; InsertAt: TAlign;
    5362      DropCtl: TControl);
     63    procedure SetDockStyle(const AValue: TDockStyle);
     64    procedure UpdateClientSize;
     65    procedure TabControlChange(Sender: TObject);
    5466  public
    5567    constructor Create(ADockSite: TWinControl); override;
     
    7486    procedure SetReplacingControl(Control: TControl); override;
    7587    function AutoFreeByControl: Boolean; override;
     88
     89    function CreateContainer: TConjoinDockForm;
     90    property DockStyle: TDockStyle read FDockStyle write SetDockStyle;
    7691  end;
    7792
     
    96111  FDockSite := ADockSite;
    97112  FDockPanels := TObjectList.Create;
     113  TabControl := TTabControl.Create(FDockSite);
     114  with TabControl do begin
     115    Parent := FDockSite;
     116    Visible := False;
     117    Align := alTop;
     118    Height := 24;
     119    OnChange := TabControlChange;
     120  end;
    98121  inherited Create(ADockSite);
    99122end;
     
    174197      Parent := FDockSite;
    175198      OwnerDockManager := Self;
    176       Visible := True;
     199      if DockStyle = dsList then Visible := True;
    177200      Align := alClient;
     201    end;
     202
     203    if DockStyle = dsTabs then begin
     204      TabControl.Tabs.Add(Control.Name);
     205      TabControlChange(Self);
    178206    end;
    179207    NewPanel.Control := Control;
     
    181209    Control.Align := alClient;
    182210    FDockPanels.Add(NewPanel);
    183 
    184     for I := 0 to FDockPanels.Count - 1 do begin
    185       TDockClientPanel(FDockPanels[I]).Height := FDockSite.Height div
    186         FDockSite.DockClientCount;
    187       TDockClientPanel(FDockPanels[I]).Width := FDockSite.Width div
    188         FDockSite.DockClientCount;
    189     end;
     211    UpdateClientSize;
    190212end;
    191213
     
    198220  I: Integer;
    199221  NewConjoinDockForm: TConjoinDockForm;
     222  NewDockSite: TWinControl;
     223  NewForm: TForm;
    200224begin
    201225  if (FDockSite is TForm) then begin
     
    205229      NewConjoinDockForm.Visible := True;
    206230      NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect;
    207       Control.ManualDock(NewConjoinDockForm.Panel);
    208231      FDockSite.ManualDock(NewConjoinDockForm.Panel);
     232      Control.ManualDock(NewConjoinDockForm.Panel, nil, InsertAt);
    209233    end else begin
    210       Control.ManualDock(FDockSite.Parent);
     234      NewConjoinDockForm := TConjoinDockForm.Create(nil);
     235      NewConjoinDockForm.Visible := True;
     236      NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect;
     237      NewConjoinDockForm.DragMode := dmAutomatic;
     238      NewConjoinDockForm.DragKind := dkDock;
     239      NewDockSite := FDockSite.HostDockSite;
     240//      FDockSite.ManualFloat(FDockSite.BoundsRect);
     241      NewConjoinDockForm.ManualDock(NewDockSite);
     242      FDockSite.ManualDock(NewConjoinDockForm.Panel);
     243      Control.ManualDock(NewConjoinDockForm.Panel, nil, InsertAt);
    211244    end;
    212245  end else
     
    282315    if FDockSite.DockClientCount = 2 then FDockDirection := ddNone;
    283316    //FDockSite.Invalidate;
     317    //if (FDockSite is TConjoinDockForm) and (FDockSite.DockClientCount = 1) then
     318    //  FDockSite.Free;
    284319  end;
    285320end;
     
    307342end;
    308343
     344function TCustomDockManager.CreateContainer: TConjoinDockForm;
     345var
     346  NewDockSite: TWinControl;
     347  NewConjoinDockForm: TConjoinDockForm;
     348begin
     349  NewConjoinDockForm := TConjoinDockForm.Create(nil);
     350  NewConjoinDockForm.Visible := True;
     351  NewConjoinDockForm.BoundsRect := FDockSite.BoundsRect;
     352  NewConjoinDockForm.DragMode := dmAutomatic;
     353  NewConjoinDockForm.DragKind := dkDock;
     354  NewDockSite := FDockSite.HostDockSite;
     355  //      FDockSite.ManualFloat(FDockSite.BoundsRect);
     356  NewConjoinDockForm.ManualDock(NewDockSite);
     357  Result := NewConjoinDockForm;
     358end;
     359
     360procedure TCustomDockManager.SetDockStyle(const AValue: TDockStyle);
     361var
     362  I: Integer;
     363begin
     364  FDockStyle := AValue;
     365  if AValue = dsTabs then begin
     366    TabControl.Visible := True;
     367    TabControl.Tabs.Clear;
     368    for I := 0 to FDockPanels.Count - 1 do begin
     369      TabControl.Tabs.Add(TDockClientPanel(FDockPanels[I]).Control.Name);
     370      TDockClientPanel(FDockPanels[I]).Splitter.Visible := False;
     371      TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False;
     372      TDockClientPanel(FDockPanels[I]).Visible := False;
     373    end;
     374    TabControlChange(Self);
     375  end else
     376  if AValue = dsList then begin
     377    TabControl.Visible := False;
     378    TabControl.Tabs.Clear;
     379    for I := 0 to FDockPanels.Count - 1 do begin
     380      TDockClientPanel(FDockPanels[I]).Splitter.Visible := True;
     381      TDockClientPanel(FDockPanels[I]).Visible := True;
     382      TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Parent := TDockClientPanel(FDockPanels[I]);
     383    end;
     384  end;
     385  UpdateClientSize;
     386end;
     387
     388procedure TCustomDockManager.UpdateClientSize;
     389var
     390  I: Integer;
     391begin
     392  if DockStyle = dsList then begin
     393    for I := 0 to FDockPanels.Count - 1 do begin
     394      TDockClientPanel(FDockPanels[I]).Height := FDockSite.Height div
     395        FDockSite.DockClientCount;
     396      TDockClientPanel(FDockPanels[I]).Width := FDockSite.Width div
     397        FDockSite.DockClientCount;
     398      //TDockClientPanel(FDockPanels[I]).DockPanelPaint(Self);
     399    end;
     400  end else
     401  if DockStyle = dsTabs then begin
     402    for I := 0 to FDockPanels.Count - 1 do begin
     403      TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Width := FDockSite.Width;
     404      TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Height := FDockSite.Height - TabControl.Height;
     405      //TDockClientPanel(FDockPanels[I]).DockPanelPaint(Self);
     406    end;
     407  end;
     408end;
     409
     410procedure TCustomDockManager.TabControlChange(Sender: TObject);
     411var
     412  I: Integer;
     413begin
     414  for I := 0 to FDockPanels.Count - 1 do begin
     415    TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False;
     416  end;
     417  if (TabControl.TabIndex <> -1) and (FDockPanels.Count > TabControl.TabIndex) then begin
     418    TDockClientPanel(FDockPanels[TabControl.TabIndex]).ClientAreaPanel.Parent := FDockSite;
     419    TDockClientPanel(FDockPanels[TabControl.TabIndex]).ClientAreaPanel.Visible := True;
     420//  TDockClientPanel(FDockPanels[TabControl.TabIndex]).Visible := True;
     421  end;
     422end;
     423
    309424{ TDockClientPanel }
     425
     426procedure TDockClientPanel.SetShowHeader(const AValue: Boolean);
     427begin
     428  if FShowHeader=AValue then exit;
     429  FShowHeader := AValue;
     430  DockPanelPaint(Self);
     431end;
    310432
    311433constructor TDockClientPanel.Create(TheOwner: TComponent);
     
    319441    Width := 14;
    320442    Height := 14;
    321     Visible := True;
     443    Visible := False;
    322444    OnClick := CloseButtonClick;
    323445  end;
     
    331453    Top := GrabberSize;
    332454    Width := Self.Width;
    333     Height := Self.Height;
     455    Height := Self.Height - GrabberSize;
    334456    Anchors := [akTop, akBottom, akLeft, akRight];
    335457    BevelInner := bvNone;
    336458    BevelOuter := bvNone;
     459    //Color := clGreen;
    337460  end;
    338461  OnPaint := DockPanelPaint;
     
    341464  BevelInner := bvNone;
    342465  BevelOuter := bvNone;
     466  ShowHeader := True;
    343467end;
    344468
     
    386510  R: TRect;
    387511begin
    388   R := Control.ClientRect;
    389   Canvas.FillRect(R);
    390   DrawGrabber(Canvas, Control);
     512  if Assigned(Control) then begin
     513    R := Control.ClientRect;
     514    Canvas.FillRect(R);
     515    CloseButton.Visible := ShowHeader;
     516    if ShowHeader then begin
     517      if ClientAreaPanel.DockClientCount = 0 then
     518        DrawGrabber(Canvas, Control) else
     519      DrawGrabber(Canvas, ClientAreaPanel);
     520    end;
     521  end;
    391522end;
    392523
     
    394525  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    395526begin
    396   if (Button=mbLeft) then begin
     527  if Control is TForm then begin
     528    TForm(Control).SetFocus;
     529    DockPanelPaint(Self);
     530  end;
     531  if (Button = mbLeft) then begin
    397532    DragManager.DragStart(Control, False, 1);
    398533  end;
Note: See TracChangeset for help on using the changeset viewer.