Ignore:
Timestamp:
Mar 16, 2011, 7:47:27 AM (14 years ago)
Author:
george
Message:
  • Modified: Docked client header redone to delphi visual style.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Docking/CoolDocking/UCDManager.pas

    r195 r197  
    66
    77uses
    8   Classes, SysUtils, UCDCommon, Controls, Contnrs,
     8  Classes, SysUtils, UCDCommon, Controls, Contnrs, Dialogs,
    99  UCDPopupMenu, LCLType, LMessages, Graphics, Buttons,
    1010  UCDConjoinForm, Menus, StdCtrls, ExtCtrls, Forms;
     
    1818  TCDManager = class;
    1919  TCDManagerItem = class;
     20
     21  { TCDHeaderButton }
     22
     23  TCDHeaderButton = class
     24    Icon: TImage;
     25    constructor Create;
     26    destructor Destroy; override;
     27  end;
     28
     29  { TCDHeader }
    2030
    2131  TCDHeader = class(TPanel)
     
    2333    procedure CloseButtonClick(Sender: TObject);
    2434    procedure DrawGrabber(Canvas: TCanvas; AControl: TControl);
     35    procedure PaintExecute(Sender: TObject);
     36    procedure RearrangeButtons;
    2537  public
    26     CloseButton: TSpeedButton;
     38    Buttons: TObjectList; // TList<TCDHeaderButton>
    2739    Title: TLabel;
    2840    Icon: TImage;
    2941    ManagerItem: TCDManagerItem;
    30     Shape: TShape;
    3142    constructor Create(TheOwner: TComponent); override;
    3243    destructor Destroy; override;
     
    5364  TCDManagerItem = class
    5465  private
    55     procedure DockPanelMouseDown(Sender: TObject; Button: TMouseButton;
    56       Shift: TShiftState; X, Y: Integer);
    5766    procedure ResizeExecute(Sender: TObject);
    5867  public
    5968    Control: TControl;
    6069    Manager: TCDManager;
     70    procedure DockPanelMouseDown(Sender: TObject; Button: TMouseButton;
     71      Shift: TShiftState; X, Y: Integer);
    6172    procedure Paint(Sender: TObject); virtual;
    6273    procedure VisibleChange(Sender: TObject); virtual;
     
    124135
    125136uses
    126   UCDManagerRegions, UCDManagerTabs, UCDManagerRegionsPopup, UCDManagerTabsPopup;
     137  UCDManagerRegions, UCDManagerTabs, UCDManagerRegionsPopup, UCDManagerTabsPopup,
     138  UCDResource;
     139
     140{ TCDHeaderButton }
     141
     142constructor TCDHeaderButton.Create;
     143begin
     144  inherited;
     145  Icon := TImage.Create(nil);
     146end;
     147
     148destructor TCDHeaderButton.Destroy;
     149begin
     150  Icon.Free;
     151  inherited Destroy;
     152end;
    127153
    128154{ TCDPanelHeader }
     
    142168//  Header.Title.OnMouseDown := DockPanelMouseDown;
    143169  HeaderPos := hpTop;
     170  Constraints.MinHeight := GrabberSize;
     171  Align := alClient;
    144172
    145173  ShowHeader := True;
     
    164192  end;
    165193  //OnResize := ResizeExecute;
    166   BevelInner := bvNone;
    167   BevelOuter := bvNone;
     194  //BevelInner := bvNone;
     195  //BevelOuter := bvNone;
    168196end;
    169197
     
    195223constructor TCDManagerItem.Create;
    196224begin
     225
    197226end;
    198227
     
    213242begin
    214243  if Control is TForm then begin
    215     //TForm(Control).SetFocus;
     244    TForm(Control).SetFocus;
    216245    Paint(Self);
    217246  end;
     
    219248    //(Control as TWinControl).DockSite := False;
    220249    //ClientAreaPanel.DockSite := False;
    221     //(Control as TWinControl).BeginDrag(False, 10);
    222     //DragManager.DragStart(Control, False, 1);
     250    (Control as TWinControl).BeginDrag(False, 10);
     251    DragManager.DragStart(Control, False, 1);
    223252  end;
    224253end;
     
    549578
    550579constructor TCDHeader.Create(TheOwner: TComponent);
     580var
     581  NewButton: TCDHeaderButton;
    551582begin
    552583  inherited Create(TheOwner);
    553   Shape := TShape.Create(Self);
    554   with Shape do begin
    555     Parent := Self;
    556     Anchors := [akRight, akBottom, akLeft, akTop];
    557     Left := 1;
    558     Top := 1;
    559     Width := Self.Width - 2;
    560     Height := Self.Height - 2;
    561     Brush.Style := bsClear;
    562   end;
     584  OnPaint := PaintExecute;
     585
    563586  Title := TLabel.Create(Self);
    564587  with Title do begin
     
    570593    BevelOuter := bvNone;
    571594  end;
    572   CloseButton := TSpeedButton.Create(Self);
    573   with CloseButton do begin
    574     Parent := Self;
    575     Caption := 'X';
    576     Font.Size := 6;
    577     Width := GrabberSize - 8;
    578     Height := GrabberSize - 8;
    579     Anchors := [akRight, akTop];
    580     Left := Self.Width - Width - 4;
    581     Top := 4;
    582     Visible := True;
    583     OnClick := CloseButtonClick;
    584   end;
     595  Buttons := TObjectList.Create;
     596
     597  NewButton := TCDHeaderButton.Create;
     598  with NewButton do begin
     599    DataModule2.ImageList1.GetBitmap(0, Icon.Picture.Bitmap);
     600    Icon.Parent := Self;
     601    Icon.OnClick := CloseButtonClick;
     602  end;
     603  Buttons.Add(NewButton);
     604  NewButton := TCDHeaderButton.Create;
     605  with NewButton do begin
     606    DataModule2.ImageList1.GetBitmap(1, Icon.Picture.Bitmap);
     607    Icon.Parent := Self;
     608    Icon.OnClick := CloseButtonClick;
     609  end;
     610  Buttons.Add(NewButton);
     611  RearrangeButtons;
     612
    585613  Icon := TImage.Create(Self);
    586614  with Icon do begin
     
    594622destructor TCDHeader.Destroy;
    595623begin
     624  Buttons.Free;
    596625  inherited Destroy;
    597626end;
     
    614643end;
    615644
     645procedure TCDHeader.PaintExecute(Sender: TObject);
     646const
     647  Corner: Integer = 2;
     648  Border: Integer = 1;
     649  BorderColor: TColor = $B9C3C6;
     650  TopColor: TColor = $CFD6D9;
     651  BottomColor: TColor = $DAE0E1;
     652var
     653  Points: array of TPoint;
     654begin
     655  with Canvas do begin
     656    GradientFill(Rect(Border, Border, Width - Border,
     657      Height - Border), TopColor, BottomColor, gdVertical);
     658    Brush.Color := clBtnFace;
     659    Brush.Style := bsSolid;
     660    Pen.Color := clBtnFace;
     661    Pen.Style := psSolid;
     662    SetLength(Points, 3);
     663    Points[0] := Point(Border, Border);
     664    Points[1] := Point(Border, Border + Corner);
     665    Points[2] := Point(Border + Corner, Border);
     666    Polygon(Points);
     667    Points[0] := Point(Width - 1 - Border, Border);
     668    Points[1] := Point(Width - 1 - Border, Border + Corner);
     669    Points[2] := Point(Width - 1 - Border - Corner, Border);
     670    Polygon(Points);
     671    Points[0] := Point(Border, Height - 1 - Border);
     672    Points[1] := Point(Border, Height - 1 - Border - Corner);
     673    Points[2] := Point(Border + Corner, Height - 1 - Border);
     674    Polygon(Points);
     675    Points[0] := Point(Width - 1 - Border, Height - 1 - Border);
     676    Points[1] := Point(Width - 1 - Border, Height - 1 - Border - Corner);
     677    Points[2] := Point(Width - 1 - Border - Corner, Height - 1 - Border);
     678    Polygon(Points);
     679
     680    SetLength(Points, 9);
     681    Points[0] := Point(Border, Border + Corner);
     682    Points[1] := Point(Border + Corner, Border);
     683    Points[2] := Point(Width - 1 - Border - Corner, Border);
     684    Points[3] := Point(Width - 1 - Border, Border + Corner);
     685    Points[4] := Point(Width - 1 - Border, Height - 1 - Border - Corner);
     686    Points[5] := Point(Width - 1 - Border - Corner, Height - 1 - Border);
     687    Points[6] := Point(Border + Corner, Height - 1 - Border);
     688    Points[7] := Point(Border, Height - 1 - Border - Corner);
     689    Points[8] := Point(Border, Border + Corner);
     690    Pen.Color := BorderColor;
     691    Polyline(Points);
     692  end;
     693end;
     694
     695procedure TCDHeader.RearrangeButtons;
     696const
     697  Separation: Integer = 4;
     698var
     699  LeftPos: Integer;
     700  I: Integer;
     701begin
     702  LeftPos := Self.Width;
     703  for I := 0 to Buttons.Count - 1 do
     704  with TCDHeaderButton(Buttons[I]), Icon do begin
     705    Anchors := [akRight, akTop];
     706    //Icon.Picture.Bitmap.SetSize(16, 16);
     707    Icon.Width := Icon.Picture.Bitmap.Width;
     708    Icon.Height := Icon.Picture.Bitmap.Height;
     709    LeftPos := LeftPos - Icon.Width - Separation;
     710    Icon.Left := LeftPos;
     711    Icon.Top := (GrabberSize - Icon.Height) div 2;
     712
     713    //ShowMessage(IntToStr(Icon.Width) + ' ' +  InttoStr(Icon.Height));
     714    Visible := True;
     715  end;
     716end;
     717
    616718procedure TCDHeader.CloseButtonClick(Sender: TObject);
    617719begin
Note: See TracChangeset for help on using the changeset viewer.