Ignore:
Timestamp:
Mar 11, 2011, 1:00:06 PM (14 years ago)
Author:
george
Message:
  • Removed: UCDClientPanel replaced by TCDManagerItem and it's descendend.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Docking/CoolDocking/UCDManager.pas

    r193 r194  
    11unit UCDManager;
    22
    3 {$mode objfpc}{$H+}
     3{$mode Delphi}{$H+}
    44
    55interface
    66
    77uses
    8   Classes, SysUtils, UCDCommon, Controls, Contnrs, UCDClientPanel,
    9   UCDPopupMenu, LCLType, LMessages, Graphics,
     8  Classes, SysUtils, UCDCommon, Controls, Contnrs,
     9  UCDPopupMenu, LCLType, LMessages, Graphics, Buttons,
    1010  UCDConjoinForm, Menus, StdCtrls, ExtCtrls, Forms;
    1111
     12const
     13  GrabberSize = 22;
     14
    1215type
    13   { TCoolDockPanels }
    14 
    15   // TCoolDockPanels = TObjectList<TCDClientPanel>
    16   TCDPanels = class(TObjectList)
     16  THeaderPos = (hpAuto, hpLeft, hpTop, hpRight, hpBottom);
     17
     18  TCDManager = class;
     19  TCDManagerItem = class;
     20
     21  TCDHeader = class(TPanel)
     22  private
     23    procedure CloseButtonClick(Sender: TObject);
     24    procedure DrawGrabber(Canvas: TCanvas; AControl: TControl);
     25  public
     26    CloseButton: TSpeedButton;
     27    Title: TLabel;
     28    Icon: TImage;
     29    ManagerItem: TCDManagerItem;
     30    Shape: TShape;
     31    constructor Create(TheOwner: TComponent); override;
    1732    destructor Destroy; override;
     33  end;
     34
     35  { TCDManagerItem }
     36
     37  TCDManagerItem = class
     38  private
     39    FHeaderPos: THeaderPos;
     40    FShowHeader: Boolean;
     41    procedure DockPanelMouseDown(Sender: TObject; Button: TMouseButton;
     42      Shift: TShiftState; X, Y: Integer);
     43    procedure ResizeExecute(Sender: TObject);
     44    procedure SetHeaderPos(const AValue: THeaderPos);
     45  public
     46    Header: TCDHeader;
     47    Control: TControl;
     48    Manager: TCDManager;
     49    procedure Paint(Sender: TObject); virtual;
     50    procedure VisibleChange(Sender: TObject); virtual;
     51    constructor Create;
     52    destructor Destroy; override;
     53    property ShowHeader: Boolean read FShowHeader write FShowHeader;
     54    property HeaderPos: THeaderPos read FHeaderPos write SetHeaderPos;
    1855  end;
    1956
     
    2360  private
    2461    FDockSite: TWinControl;
    25     FDockPanels: TCDPanels;
    2662    function GetDockSite: TWinControl;
    2763    function GetHeaderPos: THeaderPos;
     
    65101    function AutoFreeByControl: Boolean; override;
    66102
    67     function FindControlInPanels(Control: TControl): TCDClientPanel;
     103    function FindControlInPanels(Control: TControl): TCDManagerItem; virtual;
    68104    function CreateContainer(InsertAt: TAlign): TCDConjoinForm;
    69     property DockPanels: TCDPanels read FDockPanels write FDockPanels;
    70105    property DockStyle: TCDStyleType read FDockStyle write SetDockStyle;
    71106    property MoveDuration: Integer read GetMoveDuration write SetMoveDuration;
     
    81116  UCDManagerRegions, UCDManagerTabs, UCDManagerRegionsPopup, UCDManagerTabsPopup;
    82117
     118{ TCDManagerItem }
     119
     120procedure TCDManagerItem.SetHeaderPos(const AValue: THeaderPos);
     121begin
     122  if FHeaderPos=AValue then exit;
     123  FHeaderPos:=AValue;
     124  Paint(Self);
     125end;
     126
     127procedure TCDManagerItem.Paint(Sender: TObject);
     128var
     129  I: Integer;
     130  R: TRect;
     131begin
     132(*  if not (csDesigning in ComponentState) then
     133  if Assigned(Control) then begin
     134    R := Control.ClientRect;
     135    Canvas.FillRect(R);
     136    Header.Visible := ShowHeader;
     137    if ShowHeader then begin
     138      if ClientAreaPanel.DockClientCount = 0 then
     139        Header.DrawGrabber(Canvas, Control) else
     140      Header.DrawGrabber(Canvas, ClientAreaPanel);
     141    end;
     142  end;*)
     143end;
     144
     145constructor TCDManagerItem.Create;
     146begin
     147  //Paint.OnPaint := Paint;
     148  Header.Shape.OnMouseDown := DockPanelMouseDown;
     149  Header.Title.OnMouseDown := DockPanelMouseDown;
     150  //OnResize := ResizeExecute;
     151  //BevelInner := bvNone;
     152  //BevelOuter := bvNone;
     153  HeaderPos := hpTop;
     154
     155  ShowHeader := True;
     156  Header := TCDHeader.Create(nil);
     157  with Header do begin
     158    Parent := nil;
     159    Visible := ShowHeader;
     160    Align := alTop;
     161    Height := GrabberSize;
     162    ManagerItem := Self;
     163  end;
     164end;
     165
     166procedure TCDManagerItem.ResizeExecute(Sender: TObject);
     167begin
     168(*  if Assigned(Control) then begin
     169    Control.Top := GrabberSize;
     170    Control.Left := 0;
     171    Control.Width := Width;
     172    Control.Height := Height - GrabberSize;
     173    //Control.SetBounds(0, GrabberSize, Width - Control.Left,
     174    //  Height - Control.Top);
     175  end;*)
     176end;
     177
     178procedure TCDManagerItem.DockPanelMouseDown(Sender: TObject;
     179  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
     180begin
     181  if Control is TForm then begin
     182    //TForm(Control).SetFocus;
     183    Paint(Self);
     184  end;
     185  if (Button = mbLeft) then begin
     186    //(Control as TWinControl).DockSite := False;
     187    //ClientAreaPanel.DockSite := False;
     188    //(Control as TWinControl).BeginDrag(False, 10);
     189    //DragManager.DragStart(Control, False, 1);
     190  end;
     191end;
     192
     193destructor TCDManagerItem.Destroy;
     194begin
     195  if Assigned(Control) then
     196    Control.RemoveHandlerOnVisibleChanged(VisibleChange);
     197  inherited Destroy;
     198end;
     199
     200procedure TCDManagerItem.VisibleChange(Sender: TObject);
     201var
     202  ControlVisible: Boolean;
     203  Temp: TControl;
     204  Temp2: TControl;
     205begin
     206{  Temp := TControl(Sender);
     207  if Assigned(Control) then
     208  begin
     209    ControlVisible := TControl(Sender).Visible;
     210    (*if Assigned(ClientAreaPanel) then
     211      ClientAreaPanel.Visible := ControlVisible;
     212    if Assigned(Splitter) then
     213      Splitter.Visible := ControlVisible;
     214      *)
     215//    if Assigned(TCDManager(OwnerDockManager).DockStyleHandler) then
     216    if Assigned(Manager) then
     217    with TCDManager(Manager) do
     218    begin
     219      //UpdateClientSize;
     220      if ControlVisible then
     221        Switch(DockItems.IndexOf(FindControlInPanels(TControl(Sender))));
     222      if not (Control is TWinControl) then raise Exception.Create('Not TWinControl');
     223      if not Assigned(Control) then raise Exception.Create('Control not assigned');
     224      ChangeVisible(TWinControl(Control), ControlVisible);
     225      // Show parent control
     226      Temp := TControl(Sender).HostDockSite;
     227
     228      if ControlVisible then
     229        TControl(Sender).HostDockSite.Visible := ControlVisible;
     230    end;
     231    if csDestroying in Control.ComponentState then Control := nil;
     232  end;}
     233end;
     234
    83235{ TCDManager }
    84236
    85237function TCDManager.FindControlInPanels(Control: TControl
    86   ): TCDClientPanel;
    87 var
    88   I: Integer;
    89 begin
    90   I := 0;
    91   while (I < FDockPanels.Count) and
    92     (TCDClientPanel(FDockPanels[I]).Control <> Control) do Inc(I);
    93   if I < FDockPanels.Count then Result := TCDClientPanel(FDockPanels[I])
    94     else Result := nil;
     238  ): TCDManagerItem;
     239begin
     240  Result := nil;
    95241end;
    96242
     
    118264
    119265  FDockSite := ADockSite;
    120   FDockPanels := TCDPanels.Create;
    121266
    122267  FDockStyle := dsList; // dsNone
     
    128273begin
    129274  PopupMenu.Free;
    130   FDockPanels.Free;
    131275  inherited Destroy;
    132276end;
     
    171315var
    172316  NewSplitter: TSplitter;
    173   NewDockPanel: TCDClientPanel;
     317  NewDockPanel: TCDManagerItem;
    174318  NewPanel: TPanel;
    175319  I: Integer;
     
    193337    end;
    194338  end else
    195   if (FDockSite is TCDConjoinForm) or (FDockSite is TPanel) or (FDockSite is TCDClientPanel) then begin
     339  if (FDockSite is TCDConjoinForm) or (FDockSite is TPanel) then begin
    196340    InsertControlPanel(Control, InsertAt, DropCtl);
    197341  end;
     
    206350
    207351procedure TCDManager.PaintSite(DC: HDC);
    208 var
    209   Canvas: TControlCanvas;
    210   Control: TControl;
    211   I: Integer;
    212   R: TRect;
    213 begin
    214   for I := 0 to FDockPanels.Count - 1 do
    215     with TCDClientPanel(FDockPanels[I]) do begin
    216       Invalidate;
    217     end;
     352begin
    218353end;
    219354
     
    254389
    255390procedure TCDManager.RemoveControl(Control: TControl);
    256 var
    257   ClientPanel: TCDClientPanel;
     391//var
     392//  ClientPanel: TCDClientPanel;
    258393begin
    259394  //DockStyleHandler.RemoveControl(Control);
     
    322457    if AValue = dsTabs then begin
    323458      NewManager := TCDManagerTabs.Create(FDockSite);
    324       TCDManagerTabs(Self).TabControlChange(Self);
     459      //TCDManagerTabs(Self).TabControlChange(Self);
    325460    end else
    326461    if AValue = dsList then begin
     
    328463    end else
    329464    if AValue = dsPopupList then begin
    330       NewManager := TCDStylePopupRegions.Create(FDockSite);
     465      NewManager := TCDManagerPopupRegions.Create(FDockSite);
    331466    end else
    332467    if AValue = dsPopupTabs then begin
     
    336471      NewManager.Assign(TCDManager(DockSite.DockManager));
    337472    DockSite.DockManager := NewManager;
    338   end;
    339   UpdateClientSize;
     473    NewManager.UpdateClientSize;
     474  end;
    340475end;
    341476
     
    379514end;
    380515
    381 { TCDPanels }
    382 
    383 destructor TCDPanels.Destroy;
    384 var
    385   Temp: Integer;
    386 begin
    387   Temp := Count;
     516{ TCDHeader }
     517
     518constructor TCDHeader.Create(TheOwner: TComponent);
     519begin
     520  inherited Create(TheOwner);
     521  Shape := TShape.Create(Self);
     522  with Shape do begin
     523    Parent := Self;
     524    Anchors := [akRight, akBottom, akLeft, akTop];
     525    Left := 1;
     526    Top := 1;
     527    Width := Self.Width - 2;
     528    Height := Self.Height - 2;
     529    Brush.Style := bsClear;
     530  end;
     531  Title := TLabel.Create(Self);
     532  with Title do begin
     533    Parent := Self;
     534    Visible := True;
     535    Top := 4;
     536    Left := 6;
     537    BevelInner := bvNone;
     538    BevelOuter := bvNone;
     539  end;
     540  CloseButton := TSpeedButton.Create(Self);
     541  with CloseButton do begin
     542    Parent := Self;
     543    Caption := 'X';
     544    Font.Size := 6;
     545    Width := GrabberSize - 8;
     546    Height := GrabberSize - 8;
     547    Anchors := [akRight, akTop];
     548    Left := Self.Width - Width - 4;
     549    Top := 4;
     550    Visible := True;
     551    OnClick := CloseButtonClick;
     552  end;
     553  Icon := TImage.Create(Self);
     554  with Icon do begin
     555    Parent := Self;
     556    Left := 4;
     557    Top := 2;
     558    Visible := True;
     559  end;
     560end;
     561
     562destructor TCDHeader.Destroy;
     563begin
    388564  inherited Destroy;
    389565end;
    390566
     567procedure TCDHeader.DrawGrabber(Canvas: TCanvas; AControl: TControl);
     568begin
     569  with Canvas do begin
     570    Brush.Color := clBtnFace;
     571    Pen.Color := clBlack;
     572    //FillRect(0, 0, AControl.Width, GrabberSize);
     573
     574    if (AControl as TWinControl).Focused then
     575      Title.Font.Style := Font.Style + [fsBold]
     576      else Title.Font.Style := Font.Style - [fsBold];
     577    Rectangle(1, 1, AControl.Width - 1, GrabberSize - 1);
     578    if Icon.Picture.Width > 0 then Title.Left := 8 + Icon.Picture.Width
     579      else Title.Left := 6;
     580    Title.Caption := AControl.Caption;
     581  end;
     582end;
     583
     584procedure TCDHeader.CloseButtonClick(Sender: TObject);
     585begin
     586  ManagerItem.Control.Hide;
     587end;
     588
    391589
    392590
Note: See TracChangeset for help on using the changeset viewer.