Ignore:
Timestamp:
Sep 20, 2010, 8:07:01 AM (14 years ago)
Author:
george
Message:
  • Upraveno: Titulková lišta ukotvených oken přepracována s využitím klasických prvků jako TPanel, TShape, TLabel a TSpeedButton. Zjednodušení kódu díky automatické obsluze velikosti a rozmístění.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • DockManager/Lazarus/UCustomDockManager.pas

    r49 r50  
    1919
    2020  TCustomDockManager = class;
     21  TDockClientPanel = class;
    2122
    2223  { TConjoinDockForm }
     
    2829
    2930  TDockStyle = (dsList, dsTabs);
     31
     32  { TDockHeader }
     33
     34  TDockHeader = class(TPanel)
     35    CloseButton: TSpeedButton;
     36    Title: TLabel;
     37    Icon: TIcon;
     38    ParentClientPanel: TDockClientPanel;
     39    Shape: TShape;
     40    constructor Create(TheOwner: TComponent); override;
     41    destructor Destroy; override;
     42  private
     43    procedure CloseButtonClick(Sender: TObject);
     44    procedure DrawGrabber(Canvas: TCanvas; AControl: TControl);
     45  end;
    3046
    3147  { TDockClientPanel }
     
    4056    procedure SetShowHeader(const AValue: Boolean);
    4157  public
     58    Header: TDockHeader;
    4259    OwnerDockManager: TCustomDockManager;
    43     CloseButton: TSpeedButton;
    4460    Control: TControl;
    4561    Splitter: TSplitter;
     
    5066    procedure DockPanelMouseDown(Sender: TObject; Button: TMouseButton;
    5167      Shift: TShiftState; X, Y: Integer);
    52     procedure DrawGrabber(Canvas: TCanvas; AControl: TControl);
    53     procedure CloseButtonClick(Sender: TObject);
    5468    procedure ResizeExecute(Sender: TObject);
    5569    property ShowHeader: Boolean read FShowHeader write SetShowHeader;
     
    8397    procedure PopupMenuCloseClick(Sender: TObject);
    8498    procedure PopupMenuRenameClick(Sender: TObject);
     99    procedure PopupMenuPositionAutoClick(Sender: TObject);
     100    procedure PopupMenuPositionLeftClick(Sender: TObject);
     101    procedure PopupMenuPositionRightClick(Sender: TObject);
     102    procedure PopupMenuPositionTopClick(Sender: TObject);
     103    procedure PopupMenuPositionBottomClick(Sender: TObject);
    85104    procedure Timer1Timer(Sender: TObject);
    86105  public
    87106    constructor Create(ADockSite: TWinControl); override;
    88107    destructor Destroy; override;
     108
     109    // Inherited from TDockManager
    89110    procedure BeginUpdate; override;
    90111    procedure EndUpdate; override;
     
    141162  SCloseForm = 'Close';
    142163  SRenameForm = 'Rename';
    143 
     164  SPosition = 'Position';
     165  SPositionAuto = 'Auto';
     166  SPositionTop = 'Top';
     167  SPositionLeft = 'Left';
     168  SPositionRight = 'Right';
     169  SPositionBottom = 'Bottom';
    144170
    145171procedure Register;
     
    189215  NewMenuItem2.Caption := SDockTabs;
    190216  NewMenuItem2.OnClick := PopupMenuTabsClick;
     217  NewMenuItem.Add(NewMenuItem2);
     218
     219  NewMenuItem := TMenuItem.Create(PopupMenu1);
     220  NewMenuItem.Caption := SPosition;
     221  PopupMenu1.Items.Add(NewMenuItem);
     222
     223  NewMenuItem2 := TMenuItem.Create(NewMenuItem);
     224  NewMenuItem2.Caption := SPositionAuto;
     225  NewMenuItem2.OnClick := PopupMenuPositionAutoClick;
     226  NewMenuItem.Add(NewMenuItem2);
     227
     228  NewMenuItem2 := TMenuItem.Create(NewMenuItem);
     229  NewMenuItem2.Caption := SPositionTop;
     230  NewMenuItem2.OnClick := PopupMenuPositionTopClick;
     231  NewMenuItem.Add(NewMenuItem2);
     232
     233  NewMenuItem2 := TMenuItem.Create(NewMenuItem);
     234  NewMenuItem2.Caption := SPositionLeft;
     235  NewMenuItem2.OnClick := PopupMenuPositionLeftClick;
     236  NewMenuItem.Add(NewMenuItem2);
     237
     238  NewMenuItem2 := TMenuItem.Create(NewMenuItem);
     239  NewMenuItem2.Caption := SPositionBottom;
     240  NewMenuItem2.OnClick := PopupMenuPositionBottomClick;
     241  NewMenuItem.Add(NewMenuItem2);
     242
     243  NewMenuItem2 := TMenuItem.Create(NewMenuItem);
     244  NewMenuItem2.Caption := SPositionRight;
     245  NewMenuItem2.OnClick := PopupMenuPositionRightClick;
    191246  NewMenuItem.Add(NewMenuItem2);
    192247
     
    580635end;
    581636
     637procedure TCustomDockManager.PopupMenuPositionAutoClick(Sender: TObject);
     638begin
     639  TabsPos := hpAuto;
     640end;
     641
     642procedure TCustomDockManager.PopupMenuPositionLeftClick(Sender: TObject);
     643begin
     644  TabsPos := hpLeft;
     645end;
     646
     647procedure TCustomDockManager.PopupMenuPositionRightClick(Sender: TObject);
     648begin
     649  TabsPos := hpRight;
     650end;
     651
     652procedure TCustomDockManager.PopupMenuPositionTopClick(Sender: TObject);
     653begin
     654  TabsPos := hpTop;
     655end;
     656
     657procedure TCustomDockManager.PopupMenuPositionBottomClick(Sender: TObject);
     658begin
     659  TabsPos := hpBottom;
     660end;
     661
    582662procedure TCustomDockManager.Timer1Timer(Sender: TObject);
    583663begin
     
    614694begin
    615695  inherited;
    616   CloseButton := TSpeedButton.Create(Self);
    617   with CloseButton do begin
     696  Header := TDockHeader.Create(Self);
     697  with Header do begin
    618698    Parent := Self;
    619     Caption := 'X';
    620     Font.Size := 6;
    621     Width := GrabberSize - 4;
    622     Height := GrabberSize - 4;
    623     Visible := False;
    624     OnClick := CloseButtonClick;
     699    Visible := ShowHeader;
     700    Align := alTop;
     701    Height := GrabberSize;
    625702  end;
    626703  ClientAreaPanel := TPanel.Create(Self);
     
    630707    DockSite := True;
    631708    UseDockManager := True;
    632     Left := 0;
    633     Top := GrabberSize;
    634     Width := Self.Width;
    635     Height := Self.Height - GrabberSize;
    636     Anchors := [akTop, akBottom, akLeft, akRight];
     709    Align := alClient;
    637710    BevelInner := bvNone;
    638711    BevelOuter := bvNone;
     
    658731end;
    659732
    660 procedure TDockClientPanel.DrawGrabber(Canvas: TCanvas; AControl: TControl);
    661 begin
    662   with Canvas do begin
    663     Brush.Color := clBtnFace;
    664     Pen.Color := clBlack;
    665     FillRect(0, 0, AControl.Width, GrabberSize);
    666 
    667     if (AControl as TWinControl).Focused then
    668       Font.Style := Font.Style + [fsBold]
    669       else Font.Style := Font.Style - [fsBold];
    670     Rectangle(1, 1, AControl.Width - 1, GrabberSize - 1);
    671     TextOut(6, 4, AControl.Caption);
    672 
    673     CloseButton.Left := AControl.Width - CloseButton.Width - 2;
    674     CloseButton.Top := 2;
    675   end;
    676 end;
    677 
    678 procedure TDockClientPanel.CloseButtonClick(Sender: TObject);
    679 begin
    680   Control.Hide;
    681 end;
    682 
    683733procedure TDockClientPanel.ResizeExecute(Sender: TObject);
    684734begin
     
    699749    R := Control.ClientRect;
    700750    Canvas.FillRect(R);
    701     CloseButton.Visible := ShowHeader;
     751    Header.Visible := ShowHeader;
    702752    if ShowHeader then begin
    703753      if ClientAreaPanel.DockClientCount = 0 then
    704         DrawGrabber(Canvas, Control) else
    705       DrawGrabber(Canvas, ClientAreaPanel);
     754        Header.DrawGrabber(Canvas, Control) else
     755      Header.DrawGrabber(Canvas, ClientAreaPanel);
    706756    end;
    707757  end;
     
    731781    UseDockManager := True;
    732782    Align := alClient;
     783    BevelOuter := bvNone;
     784    BevelInner := bvNone;
    733785  //  Color := clYellow;
    734786  end;
     
    781833end;
    782834
     835{ TDockHeader }
     836
     837constructor TDockHeader.Create(TheOwner: TComponent);
     838begin
     839  inherited Create(TheOwner);
     840  Shape := TShape.Create(Self);
     841  with Shape do begin
     842    Parent := Self;
     843    Anchors := [akRight, akBottom, akLeft, akTop];
     844    Left := 1;
     845    Top := 1;
     846    Width := Self.Width - 2;
     847    Height := Self.Height - 2;
     848    Brush.Style := bsClear;
     849  end;
     850  CloseButton := TSpeedButton.Create(Self);
     851  with CloseButton do begin
     852    Parent := Self;
     853    Caption := 'X';
     854    Font.Size := 6;
     855    Width := GrabberSize - 8;
     856    Height := GrabberSize - 8;
     857    Anchors := [akRight, akTop];
     858    Left := Self.Width - Width - 4;
     859    Top := 4;
     860    Visible := True;
     861    OnClick := CloseButtonClick;
     862  end;
     863  Title := TLabel.Create(Self);
     864  with Title do begin
     865    Parent := Self;
     866    Visible := True;
     867    Top := 4;
     868    Left := 6;
     869    BevelInner := bvNone;
     870    BevelOuter := bvNone;
     871  end;
     872end;
     873
     874destructor TDockHeader.Destroy;
     875begin
     876  inherited Destroy;
     877end;
     878
     879procedure TDockHeader.DrawGrabber(Canvas: TCanvas; AControl: TControl);
     880begin
     881  with Canvas do begin
     882    Brush.Color := clBtnFace;
     883    Pen.Color := clBlack;
     884    //FillRect(0, 0, AControl.Width, GrabberSize);
     885
     886    if (AControl as TWinControl).Focused then
     887      Title.Font.Style := Font.Style + [fsBold]
     888      else Title.Font.Style := Font.Style - [fsBold];
     889    Rectangle(1, 1, AControl.Width - 1, GrabberSize - 1);
     890    Title.Caption := AControl.Caption;
     891  end;
     892end;
     893
     894procedure TDockHeader.CloseButtonClick(Sender: TObject);
     895begin
     896//  Control.Hide;
     897end;
     898
    783899initialization
    784900  DefaultDockManagerClass := TCustomDockManager;
Note: See TracChangeset for help on using the changeset viewer.