Ignore:
Timestamp:
Nov 4, 2010, 7:14:07 AM (14 years ago)
Author:
george
Message:
  • Modified: Tabs auto hide function moved to separated class TCoolDockAutoHide.
  • Added: Empty dock style units.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Docking/CoolDocking/UCoolDocking.pas

    r64 r89  
    1515const
    1616  GrabberSize = 22;
     17  AutoHideStepCount = 20;
    1718
    1819type
     
    5253  end;
    5354
     55  TCoolDockStyle = class
     56  end;
     57
    5458  { TCoolDockClientPanel }
    5559
     
    5963    FHeaderPos: THeaderPos;
    6064    FShowHeader: Boolean;
     65    function GetAutoHideEnabled: Boolean;
    6166    procedure SetAutoHide(const AValue: Boolean);
     67    procedure SetAutoHideEnabled(const AValue: Boolean);
    6268    procedure SetHeaderPos(const AValue: THeaderPos);
    6369    procedure SetShowHeader(const AValue: Boolean);
     
    7682    procedure ResizeExecute(Sender: TObject);
    7783    property ShowHeader: Boolean read FShowHeader write SetShowHeader;
    78     property AutoHide: Boolean read FAutoHide write SetAutoHide;
     84    property AutoHideEnabled: Boolean read GetAutoHideEnabled
     85      write SetAutoHideEnabled;
    7986    property HeaderPos: THeaderPos read FHeaderPos write SetHeaderPos;
     87  end;
     88
     89  { TCoolDockAutoHide }
     90
     91  TCoolDockAutoHide = class
     92  private
     93    FDuration: Real;
     94    FStepCount: Integer;
     95    StartBounds: TRect;
     96    procedure SetDuration(const AValue: Real);
     97    procedure SetStepCount(const AValue: Integer);
     98    procedure UpdateBounds;
     99    procedure UpdateTimerInterval;
     100  public
     101    Position: Real;
     102    Direction: Integer;
     103    TabPosition: TTabPosition;
     104    Enable: Boolean;
     105    Timer: TTimer;
     106    Control: TControl;
     107    ControlVisible: Boolean;
     108    procedure Hide;
     109    procedure Show;
     110    constructor Create;
     111    destructor Destroy; override;
     112    procedure TimerExecute(Sender: TObject);
     113    property Duration: Real read FDuration write SetDuration;
     114    property StepCount: Integer read FStepCount write SetStepCount;
    80115  end;
    81116
     
    88123    MouseDownSkip: Boolean;
    89124    FMaster: TCoolDockMaster;
    90     FMoveDuration: Integer;
    91125    FTabsPos: THeaderPos;
    92     Timer1: TTimer;
    93126    PopupMenuTabs: TPopupMenu;
    94127    PopupMenuHeader: TPopupMenu;
     
    98131    FDockDirection: TDockDirection;
    99132    FDockSite: TWinControl;
    100     FDockPanels: TObjectList; // of TCoolDockClientPanel
     133    FDockPanels: TObjectList; // TObjectList<TCoolDockClientPanel>
     134    AutoHide: TCoolDockAutoHide;
    101135    function FindControlInPanels(Control: TControl): TCoolDockClientPanel;
    102136    function GetDockSite: TWinControl;
     137    function GetMoveDuration: Integer;
    103138    procedure InsertControlPanel(Control: TControl; InsertAt: TAlign;
    104139      DropCtl: TControl);
     
    126161    procedure PopupMenuUndockClick(Sender: TObject);
    127162    procedure PopupMenuCustomizeClick(Sender: TObject);
    128     procedure Timer1Timer(Sender: TObject);
    129163  public
    130164    constructor Create(ADockSite: TWinControl); override;
     
    154188    function CreateContainer(InsertAt: TAlign): TCoolDockConjoinForm;
    155189    property DockStyle: TDockStyle read FDockStyle write SetDockStyle;
    156     property MoveDuration: Integer read FMoveDuration write SetMoveDuration;
     190    property MoveDuration: Integer read GetMoveDuration write SetMoveDuration;
    157191    property TabsPos: THeaderPos read FTabsPos write SetTabsPos;
    158192    property Master: TCoolDockMaster read FMaster write SetMaster;
     
    166200    FCoolDockCustomize: TCoolDockCustomize;
    167201    FDefaultHeaderPos: THeaderPos;
     202    FDefaultMoveSpeed: Integer;
    168203    FDefaultTabsPos: THeaderPos;
    169204    FShowIcons: Boolean;
     
    190225    property DefaultHeaderPos: THeaderPos read FDefaultHeaderPos
    191226      write FDefaultHeaderPos;
     227    property DefaultMoveSpeed: Integer read FDefaultMoveSpeed
     228      write FDefaultMoveSpeed;
    192229    property Customize: TCoolDockCustomize read FCoolDockCustomize
    193230      write SetCustomize;
     
    250287implementation
    251288
     289uses
     290  UCoolDockStyleTabs;
     291
    252292resourcestring
    253293  SDockStyle = 'Style';
     
    296336end;
    297337
     338function TCoolDockManager.GetMoveDuration: Integer;
     339begin
     340
     341end;
     342
    298343procedure TCoolDockManager.TabControlMouseLeave(Sender: TObject);
    299344begin
     
    315360  FDockPanels := TObjectList.Create;
    316361
    317   Timer1 := TTimer.Create(nil);
    318   Timer1.Enabled := False;
    319   Timer1.OnTimer := Timer1Timer;
     362  AutoHide := TCoolDockAutoHide.Create;
    320363
    321364  // Tabs popup
     
    476519destructor TCoolDockManager.Destroy;
    477520begin
    478   Timer1.Free;
    479521  FDockPanels.Free;
    480522  inherited Destroy;
     
    716758  I: Integer;
    717759begin
    718   FDockStyle := AValue;
    719   if AValue = dsTabs then begin
    720     TabControl.Visible := True;
    721     TabControl.Tabs.Clear;
    722     TabImageList.Clear;
    723     for I := 0 to FDockPanels.Count - 1 do begin
    724       TabControl.Tabs.Add(TCoolDockClientPanel(FDockPanels[I]).Control.Caption);
    725       TabImageList.Add(TCoolDockClientPanel(FDockPanels[I]).Header.Icon.Picture.Bitmap, nil);
    726       if Assigned(TCoolDockClientPanel(FDockPanels[I]).Splitter) then
    727         TCoolDockClientPanel(FDockPanels[I]).Splitter.Visible := False;
    728       TCoolDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False;
    729       TCoolDockClientPanel(FDockPanels[I]).Visible := False;
    730     end;
    731     TabControlChange(Self);
    732   end else
    733   if AValue = dsList then begin
    734     TabControl.Visible := False;
    735     TabControl.Tabs.Clear;
    736     for I := 0 to FDockPanels.Count - 1 do begin
    737       if Assigned(TCoolDockClientPanel(FDockPanels[I]).Splitter) then
     760  if FDockStyle <> AValue then begin
     761    FDockStyle := AValue;
     762    if AValue = dsTabs then begin
     763      TabControl.Visible := True;
     764      TabControl.Tabs.Clear;
     765      TabImageList.Clear;
     766      for I := 0 to FDockPanels.Count - 1 do begin
     767        TabControl.Tabs.Add(TCoolDockClientPanel(FDockPanels[I]).Control.Caption);
     768        TabImageList.Add(TCoolDockClientPanel(FDockPanels[I]).Header.Icon.Picture.Bitmap, nil);
     769        if Assigned(TCoolDockClientPanel(FDockPanels[I]).Splitter) then
     770          TCoolDockClientPanel(FDockPanels[I]).Splitter.Visible := False;
     771        TCoolDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False;
     772        TCoolDockClientPanel(FDockPanels[I]).Visible := False;
     773      end;
     774      TabControlChange(Self);
     775    end else
     776    if AValue = dsList then begin
     777      TabControl.Visible := False;
     778      TabControl.Tabs.Clear;
     779      for I := 0 to FDockPanels.Count - 1 do begin
     780        if Assigned(TCoolDockClientPanel(FDockPanels[I]).Splitter) then
    738781        TCoolDockClientPanel(FDockPanels[I]).Splitter.Visible := True;
    739       TCoolDockClientPanel(FDockPanels[I]).Visible := True;
    740       TCoolDockClientPanel(FDockPanels[I]).ClientAreaPanel.Parent := TCoolDockClientPanel(FDockPanels[I]);
    741       TCoolDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := True;
    742       TCoolDockClientPanel(FDockPanels[I]).Control.Visible := True;
     782        TCoolDockClientPanel(FDockPanels[I]).Visible := True;
     783        TCoolDockClientPanel(FDockPanels[I]).ClientAreaPanel.Parent := TCoolDockClientPanel(FDockPanels[I]);
     784        TCoolDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := True;
     785        TCoolDockClientPanel(FDockPanels[I]).Control.Visible := True;
     786      end;
    743787    end;
    744788  end;
     
    755799procedure TCoolDockManager.SetMoveDuration(const AValue: Integer);
    756800begin
    757   if FMoveDuration=AValue then exit;
    758   FMoveDuration := AValue;
    759   //Timer1.Interval := AValue;
    760801end;
    761802
    762803procedure TCoolDockManager.SetTabsPos(const AValue: THeaderPos);
    763804begin
    764   if FTabsPos=AValue then exit;
     805  if FTabsPos = AValue then Exit;
    765806  FTabsPos := AValue;
    766807  with TabControl do
     
    816857  I: Integer;
    817858begin
     859  // Hide all clients
    818860  for I := 0 to FDockPanels.Count - 1 do begin
    819861    TCoolDockClientPanel(FDockPanels[I]).ClientAreaPanel.Visible := False;
     862    TCoolDockClientPanel(FDockPanels[I]).ClientAreaPanel.Parent := FDockSite;
     863    TCoolDockClientPanel(FDockPanels[I]).Control.Align := alClient;
    820864    TCoolDockClientPanel(FDockPanels[I]).Control.Visible := False;
    821865  end;
     
    823867    with TCoolDockClientPanel(FDockPanels[TabControl.TabIndex]), ClientAreaPanel do begin
    824868      Control.Show;
    825       if AutoHide then begin
    826         Parent := nil;
     869      AutoHide.Enable := True;
     870      if AutoHide.Enable then begin
     871        //Parent := nil;
    827872        Visible := True;
    828         Width := 0;
    829         //TimerMoveForm :=
    830         //TimerIncrement := 1;
    831         Timer1.Interval := MoveDuration div 10;
    832         Timer1.Enabled := True;
     873        if AutoHide.ControlVisible then begin
     874          AutoHide.Hide;
     875        end;
     876        AutoHide.Control := Control;
     877        AutoHide.Show;
    833878      end else begin
    834879        Parent := FDockSite;
     
    912957end;
    913958
    914 procedure TCoolDockManager.Timer1Timer(Sender: TObject);
    915 begin
    916 //  TimerMoveForm.Width := TimerMoveForm.Width
    917 end;
    918 
    919959procedure TCoolDockManager.TabControlMouseDown(Sender: TObject; Button: TMouseButton;
    920960  Shift: TShiftState; X, Y: Integer);
     
    942982procedure TCoolDockClientPanel.SetShowHeader(const AValue: Boolean);
    943983begin
    944   if FShowHeader=AValue then exit;
     984  if FShowHeader = AValue then Exit;
    945985  FShowHeader := AValue;
    946986  DockPanelPaint(Self);
     
    9631003procedure TCoolDockClientPanel.SetAutoHide(const AValue: Boolean);
    9641004begin
    965   if FAutoHide=AValue then exit;
    966   FAutoHide:=AValue;
     1005  if FAutoHide = AValue then Exit;
     1006  FAutoHide := AValue;
     1007end;
     1008
     1009function TCoolDockClientPanel.GetAutoHideEnabled: Boolean;
     1010begin
     1011end;
     1012
     1013procedure TCoolDockClientPanel.SetAutoHideEnabled(const AValue: Boolean);
     1014begin
     1015
    9671016end;
    9681017
     
    10051054  BevelInner := bvNone;
    10061055  BevelOuter := bvNone;
    1007   AutoHide := False;
     1056  AutoHideEnabled := True;
    10081057  HeaderPos := hpTop;
    10091058end;
     
    10821131procedure TCoolDockMaster.SetTabsEnabled(const AValue: Boolean);
    10831132begin
    1084   if FTabsEnabled=AValue then exit;
    1085   FTabsEnabled:=AValue;
     1133  if FTabsEnabled = AValue then Exit;
     1134  FTabsEnabled := AValue;
    10861135end;
    10871136
     
    13431392begin
    13441393  Form := TCoolDockCustomizeForm.Create(Self);
     1394  if Assigned(Master) then begin
     1395    Form.SpinEdit1.Value := Master.DefaultMoveSpeed;
     1396    Form.ComboBox1.ItemIndex := Integer(Master.DefaultTabsPos);
     1397    Form.ComboBox2.ItemIndex := Integer(Master.DefaultHeaderPos);
     1398  end;
    13451399  Form.ShowModal;
     1400  if Assigned(Master) then begin
     1401    Master.DefaultMoveSpeed := Form.SpinEdit1.Value;
     1402    Master.DefaultTabsPos := THeaderPos(Form.ComboBox1.ItemIndex);
     1403    Master.DefaultHeaderPos := THeaderPos(Form.ComboBox2.ItemIndex);
     1404  end;
    13461405  Form.Free;
    13471406  Result := True;
     
    14641523end;
    14651524
     1525{ TCoolDockAutoHide }
     1526
     1527procedure TCoolDockAutoHide.UpdateBounds;
     1528begin
     1529  case TabPosition of
     1530    tpBottom: begin
     1531      Control.Height := Round((StartBounds.Bottom - StartBounds.Top) * Position);
     1532      Control.Top := StartBounds.Bottom - Control.Height;
     1533    end;
     1534    tpTop: begin
     1535      Control.Height := Round((StartBounds.Bottom - StartBounds.Top) * Position);
     1536    end;
     1537    tpRight: begin
     1538      Control.Width := Round((StartBounds.Right - StartBounds.Left) * Position);
     1539    end;
     1540    tpLeft: begin
     1541      Control.Width := Round((StartBounds.Right - StartBounds.Left) * Position);
     1542      Control.Left := StartBounds.Right - Control.Width;
     1543    end;
     1544  end;
     1545end;
     1546
     1547procedure TCoolDockAutoHide.UpdateTimerInterval;
     1548begin
     1549  Timer.Interval := Round(FDuration * 1000 / FStepCount);
     1550end;
     1551
     1552procedure TCoolDockAutoHide.SetDuration(const AValue: Real);
     1553begin
     1554  if FDuration = AValue then Exit;
     1555  FDuration := AValue;
     1556  UpdateTimerInterval;
     1557end;
     1558
     1559procedure TCoolDockAutoHide.SetStepCount(const AValue: Integer);
     1560begin
     1561  if FStepCount = AValue then Exit;
     1562  FStepCount := AValue;
     1563  UpdateTimerInterval;
     1564end;
     1565
     1566procedure TCoolDockAutoHide.Hide;
     1567begin
     1568  StartBounds := Control.BoundsRect;
     1569  Direction := -1;
     1570  Position := 1;
     1571  Timer.Enabled := True;
     1572  UpdateBounds;
     1573end;
     1574
     1575procedure TCoolDockAutoHide.Show;
     1576begin
     1577  StartBounds := Control.BoundsRect;
     1578  Control.Align := alCustom;
     1579  Direction := 1;
     1580  Position := 0;
     1581  Timer.Enabled := True;
     1582  UpdateBounds;
     1583end;
     1584
     1585constructor TCoolDockAutoHide.Create;
     1586begin
     1587  Timer := TTimer.Create(nil);
     1588  Timer.Enabled := False;
     1589  Timer.OnTimer := TimerExecute;
     1590  StepCount := AutoHideStepCount;
     1591  Duration := 0.5;
     1592end;
     1593
     1594destructor TCoolDockAutoHide.Destroy;
     1595begin
     1596  Timer.Free;
     1597  inherited Destroy;
     1598end;
     1599
     1600procedure TCoolDockAutoHide.TimerExecute(Sender: TObject);
     1601begin
     1602  if Direction = 1 then begin
     1603    Position := Position + 1 / StepCount;
     1604    if Position > 1 then begin
     1605      Position := 1;
     1606      Timer.Enabled := False;
     1607      ControlVisible := True;
     1608    end;
     1609  end else
     1610  if Direction = -1 then begin
     1611    Position := Position - 1 / StepCount;
     1612    if Position < 1 then begin
     1613      Position := 0;
     1614      Timer.Enabled := False;
     1615      ControlVisible := False;
     1616    end;
     1617  end;
     1618  UpdateBounds;
     1619end;
     1620
    14661621end.
    14671622
Note: See TracChangeset for help on using the changeset viewer.