Ignore:
Timestamp:
Sep 17, 2010, 3:34:31 PM (14 years ago)
Author:
george
Message:
  • Přidáno: Balíček Lazarusu pro snadnější instalaci. Součástí je také komponenta globálního správce ukotvení.
  • Přidáno: Kontextové menu pro doplňující volby ukotvení oken. Nyní možnost přepínat mezi zobrazením seznamu a záložek.
Location:
DockManager/Lazarus
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • DockManager/Lazarus

    • Property svn:ignore set to
      lib
  • DockManager/Lazarus/UCustomDockManager.pas

    r47 r48  
    22
    33{$mode delphi}{$H+}
     4
     5// Date: 2010-09-17
    46
    57interface
     
    79uses
    810  Classes, SysUtils, Controls, LCLType, LMessages, Graphics, StdCtrls,
    9   Buttons, ExtCtrls, Contnrs, Forms, ComCtrls, Dialogs;
     11  Buttons, ExtCtrls, Contnrs, Forms, ComCtrls, Dialogs, Menus, FileUtil;
    1012
    1113const
    12   GrabberSize = 18;
     14  GrabberSize = 22;
    1315
    1416type
    1517  TDockDirection = (ddNone, ddHorizontal, ddVertical);
     18  THeaderPos = (hpAuto, hpLeft, hpTop, hpRight, hpBottom);
    1619
    1720  TCustomDockManager = class;
     
    5356  TCustomDockManager = class(TDockManager)
    5457  private
     58    PopupMenu1: TPopupMenu;
    5559    FDockStyle: TDockStyle;
    5660    TabControl: TTabControl;
     
    6468    procedure UpdateClientSize;
    6569    procedure TabControlChange(Sender: TObject);
     70    procedure PopupMenuListClick(Sender: TObject);
     71    procedure PopupMenuTabsClick(Sender: TObject);
    6672  public
    6773    constructor Create(ADockSite: TWinControl); override;
     
    8793    function AutoFreeByControl: Boolean; override;
    8894
    89     function CreateContainer: TConjoinDockForm;
     95    function CreateContainer(InsertAt: TAlign): TConjoinDockForm;
    9096    property DockStyle: TDockStyle read FDockStyle write SetDockStyle;
    9197  end;
    9298
     99  { TCustomDockMaster }
     100
     101  TCustomDockMaster = class(TComponent)
     102  private
     103    FDefaultHeaderPos: THeaderPos;
     104    FTabsEnabled: Boolean;
     105    procedure SetTabsEnabled(const AValue: Boolean);
     106  public
     107    procedure SaveLayoutToStream(Stream: TStream);
     108    procedure LoadLayoutFromStream(Stream: TStream);
     109    procedure SaveLayoutToFile(FileName: string);
     110    procedure LoadLayoutFromFile(FileName: string);
     111  published
     112    property TabsEnabled: Boolean read FTabsEnabled write SetTabsEnabled;
     113    property DefaultHeaderPos: THeaderPos read FDefaultHeaderPos
     114      write FDefaultHeaderPos;
     115  end;
     116
     117procedure Register;
     118
    93119implementation
     120
     121procedure Register;
     122begin
     123  RegisterComponents('CustomDocking', [TCustomDockMaster]);
     124end;
     125
    94126
    95127{ TCustomDockManager }
     
    108140
    109141constructor TCustomDockManager.Create(ADockSite: TWinControl);
    110 begin
     142var
     143  NewMenuItem: TMenuItem;
     144begin
     145  inherited Create(ADockSite);
    111146  FDockSite := ADockSite;
    112147  FDockPanels := TObjectList.Create;
     148  PopupMenu1 := TPopupMenu.Create(FDockSite);
     149  NewMenuItem := TMenuItem.Create(PopupMenu1);
     150  NewMenuItem.Caption := 'List';
     151  PopupMenu1.Items.Add(NewMenuItem);
     152  NewMenuItem.OnClick := PopupMenuListClick;
     153  NewMenuItem := TMenuItem.Create(PopupMenu1);
     154  NewMenuItem.Caption := 'Tabs';
     155  NewMenuItem.OnClick := PopupMenuTabsClick;
     156  PopupMenu1.Items.Add(NewMenuItem);
    113157  TabControl := TTabControl.Create(FDockSite);
    114158  with TabControl do begin
     
    118162    Height := 24;
    119163    OnChange := TabControlChange;
    120   end;
    121   inherited Create(ADockSite);
     164    PopupMenu := PopupMenu1;
     165  end;
    122166end;
    123167
     
    156200  DropCtl: TControl);
    157201var
    158   NewSplitter: TSplitter;
    159202  NewPanel: TDockClientPanel;
    160203  I: Integer;
     
    171214    //end;
    172215    if FDockSite.DockClientCount > 1 then begin
    173       NewSplitter := TSplitter.Create(nil);
    174       NewSplitter.Parent := FDockSite;
    175       NewSplitter.Visible := True;
    176       NewSplitter.Color := clRed;
    177       with NewSplitter do
    178       if FDockDirection = ddVertical then begin
    179         Align := alTop;
    180         Top := FDockSite.Height;
    181       end else
    182       if FDockDirection = ddHorizontal then begin
    183         Align := alLeft;
    184         Left := FDockSite.Width;
     216      with TDockClientPanel(FDockPanels.Last).Splitter do begin
     217        Parent := FDockSite;
     218        Visible := True;
     219        if FDockDirection = ddVertical then begin
     220          Align := alTop;
     221          Top := FDockSite.Height;
     222        end else
     223        if FDockDirection = ddHorizontal then begin
     224          Align := alLeft;
     225          Left := FDockSite.Width;
     226        end;
    185227      end;
    186228
     
    194236    NewPanel := TDockClientPanel.Create(nil);
    195237    with NewPanel do begin
    196       Splitter := NewSplitter;
    197238      Parent := FDockSite;
    198239      OwnerDockManager := Self;
    199240      if DockStyle = dsList then Visible := True;
    200241      Align := alClient;
     242      PopupMenu := PopupMenu1;
    201243    end;
    202244
    203245    if DockStyle = dsTabs then begin
    204       TabControl.Tabs.Add(Control.Name);
     246      TabControl.Tabs.Add(Control.Caption);
    205247      TabControlChange(Self);
    206248    end;
     
    342384end;
    343385
    344 function TCustomDockManager.CreateContainer: TConjoinDockForm;
     386function TCustomDockManager.CreateContainer(InsertAt: TAlign): TConjoinDockForm;
    345387var
    346388  NewDockSite: TWinControl;
     
    354396  NewDockSite := FDockSite.HostDockSite;
    355397  //      FDockSite.ManualFloat(FDockSite.BoundsRect);
    356   NewConjoinDockForm.ManualDock(NewDockSite);
     398  NewConjoinDockForm.ManualDock(NewDockSite, nil, InsertAt);
    357399  Result := NewConjoinDockForm;
    358400end;
     
    367409    TabControl.Tabs.Clear;
    368410    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;
     411      TabControl.Tabs.Add(TDockClientPanel(FDockPanels[I]).Control.Caption);
     412      if Assigned(TDockClientPanel(FDockPanels[I]).Splitter) then
     413        TDockClientPanel(FDockPanels[I]).Splitter.Visible := False;
    371414      TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False;
    372415      TDockClientPanel(FDockPanels[I]).Visible := False;
     
    378421    TabControl.Tabs.Clear;
    379422    for I := 0 to FDockPanels.Count - 1 do begin
    380       TDockClientPanel(FDockPanels[I]).Splitter.Visible := True;
     423      if Assigned(TDockClientPanel(FDockPanels[I]).Splitter) then
     424        TDockClientPanel(FDockPanels[I]).Splitter.Visible := True;
    381425      TDockClientPanel(FDockPanels[I]).Visible := True;
    382426      TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Parent := TDockClientPanel(FDockPanels[I]);
     427      TDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := True;
    383428    end;
    384429  end;
     
    416461  end;
    417462  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;
     463    with TDockClientPanel(FDockPanels[TabControl.TabIndex]).ClientAreaPanel do begin
     464      Parent := FDockSite;
     465      Visible := True;
     466      UpdateClientSize;
     467    end;
    420468//  TDockClientPanel(FDockPanels[TabControl.TabIndex]).Visible := True;
    421469  end;
     470end;
     471
     472procedure TCustomDockManager.PopupMenuTabsClick(Sender: TObject);
     473begin
     474  DockStyle := dsTabs;
     475end;
     476
     477procedure TCustomDockManager.PopupMenuListClick(Sender: TObject);
     478begin
     479  DockStyle := dsList;
    422480end;
    423481
     
    439497    Caption := 'X';
    440498    Font.Size := 6;
    441     Width := 14;
    442     Height := 14;
     499    Width := GrabberSize - 4;
     500    Height := GrabberSize - 4;
    443501    Visible := False;
    444502    OnClick := CloseButtonClick;
     
    459517    //Color := clGreen;
    460518  end;
     519  Splitter := TSplitter.Create(Self);
     520  with Splitter do begin
     521    //Color := clRed;
     522  end;
    461523  OnPaint := DockPanelPaint;
    462524  OnMouseDown := DockPanelMouseDown;
     
    483545      else Font.Style := Font.Style - [fsBold];
    484546    Rectangle(1, 1, AControl.Width - 1, GrabberSize - 1);
    485     TextOut(6, 2, AControl.Caption);
     547    TextOut(6, 4, AControl.Caption);
    486548
    487549    CloseButton.Left := AControl.Width - CloseButton.Width - 2;
     
    526588begin
    527589  if Control is TForm then begin
    528     TForm(Control).SetFocus;
     590    //TForm(Control).SetFocus;
    529591    DockPanelPaint(Self);
    530592  end;
     
    545607    UseDockManager := True;
    546608    Align := alClient;
     609  //  Color := clYellow;
    547610  end;
    548611  DragKind := dkDock;
     
    550613end;
    551614
     615{ TCustomDockMaster }
     616
     617procedure TCustomDockMaster.SetTabsEnabled(const AValue: Boolean);
     618begin
     619  if FTabsEnabled=AValue then exit;
     620  FTabsEnabled:=AValue;
     621end;
     622
     623procedure TCustomDockMaster.SaveLayoutToStream(Stream: TStream);
     624begin
     625
     626end;
     627
     628procedure TCustomDockMaster.LoadLayoutFromStream(Stream: TStream);
     629begin
     630
     631end;
     632
     633procedure TCustomDockMaster.SaveLayoutToFile(FileName: string);
     634var
     635  LayoutFile: TFileStream;
     636begin
     637  if FileExistsUTF8(FileName) then
     638  LayoutFile := TFileStream.Create(FileName, fmOpenReadWrite)
     639  else LayoutFile := TFileStream.Create(FileName, fmCreate);
     640  try
     641    SaveLayoutToStream(LayoutFile);
     642  finally
     643    Free;
     644  end;
     645end;
     646
     647procedure TCustomDockMaster.LoadLayoutFromFile(FileName: string);
     648var
     649  LayoutFile: TFileStream;
     650begin
     651  LayoutFile := TFileStream.Create(FileName, fmOpenRead);
     652  try
     653    LoadLayoutFromStream(LayoutFile);
     654  finally
     655    Free;
     656  end;
     657end;
     658
    552659initialization
    553660  DefaultDockManagerClass := TCustomDockManager;
Note: See TracChangeset for help on using the changeset viewer.