Ignore:
Timestamp:
Mar 22, 2011, 11:32:28 AM (13 years ago)
Author:
george
Message:
  • Fixed: If control docked to panel owned by main form then it was possible to redock main form to conjoin form.
  • Modified: Header title is now painted to canvas instead of use of TLabel. This will be necessary to draw rotated text later.
  • Added: Length of header title is now reduced to not overlap to header buttons area.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Docking/CoolDocking/UCDManager.pas

    r216 r217  
    77uses
    88  Classes, SysUtils, UCDCommon, Controls, Contnrs, Dialogs,
    9   UCDPopupMenu, LCLType, LMessages, Graphics, Buttons,
     9  UCDPopupMenu, LCLType, LCLIntf, LMessages, Graphics, Buttons,
    1010  UCDConjoinForm, Menus, StdCtrls, ExtCtrls, Forms;
    1111
     
    3030  TCDHeader = class(TPanel)
    3131  private
     32    MyFont: hFont;
    3233    procedure CloseButtonClick(Sender: TObject);
    3334    procedure PaintExecute(Sender: TObject);
     
    3536  public
    3637    Buttons: TObjectList; // TList<TCDHeaderButton>
    37     Title: TLabel;
    3838    Icon: TImage;
    3939    ManagerItem: TCDManagerItem;
     
    6767    procedure SetHideType(const AValue: TCDHideType);
    6868  public
    69     Control: TControl;
     69    Control: TWinControl;
    7070    Manager: TCDManager;
    7171    procedure DockPanelMouseDown(Sender: TObject; Button: TMouseButton;
     
    139139  end;
    140140
    141 function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
    142 
    143141
    144142implementation
     
    148146  UCDResource;
    149147
    150 function HeaderPosToTabPos(HeaderPos: THeaderPos): TTabPosition;
    151 begin
    152   case HeaderPos of
    153     hpBottom: Result := tpBottom;
    154     hpLeft: Result := tpLeft;
    155     hpTop: Result := tpTop;
    156     hpRight: Result := tpRight;
    157     hpAuto: Result := tpTop;
    158   end;
     148function CreateRotatedFont(F: TFont; Angle: Integer): Integer;
     149var
     150  LF: TLogFont;
     151begin
     152  FillChar(LF, SizeOf(LF), #0);
     153  with LF do begin
     154    lfHeight := F.Height;
     155    lfWidth := 0;
     156    lfEscapement := Angle * 10;
     157    lfOrientation := 0;
     158    if fsBold in F.Style then
     159      lfWeight := FW_BOLD
     160    else
     161      lfWeight := FW_NORMAL;
     162    lfItalic := Byte(fsItalic in F.Style);
     163    lfUnderline := Byte(fsUnderline in F.Style);
     164    lfStrikeOut := Byte(fsStrikeOut in F.Style);
     165    lfCharSet := DEFAULT_CHARSET;
     166    StrPCopy(lfFaceName, F.Name);
     167    lfQuality := DEFAULT_QUALITY;
     168    {everything else as default}
     169    lfOutPrecision := OUT_DEFAULT_PRECIS;
     170    lfClipPrecision := CLIP_DEFAULT_PRECIS;
     171    case F.Pitch of
     172      fpVariable: lfPitchAndFamily := VARIABLE_PITCH;
     173      fpFixed: lfPitchAndFamily := FIXED_PITCH;
     174    else
     175      lfPitchAndFamily := DEFAULT_PITCH;
     176    end;
     177  end;
     178  Result := CreateFontIndirect(LF);
    159179end;
    160180
     
    179199  if FHeaderPos=AValue then exit;
    180200  FHeaderPos:=AValue;
     201
    181202  //Paint(Self);
    182203end;
     
    580601  inherited Create(TheOwner);
    581602  OnPaint := PaintExecute;
    582 
    583   Title := TLabel.Create(Self);
    584   with Title do begin
    585     Parent := Self;
    586     Visible := True;
    587     Top := 4;
    588     Left := 6;
    589     BevelInner := bvNone;
    590     BevelOuter := bvNone;
    591   end;
     603  //MyFont := CreateRotatedFont(Canvas.Font, 90);
     604
    592605  Buttons := TObjectList.Create;
    593606
     
    642655var
    643656  Points: array of TPoint;
    644 begin
     657  TitleLeft: Integer;
     658  TitleWidth: Integer;
     659  TitleMaxWidth: Integer;
     660  I: Integer;
     661  Title: string;
     662  R: TRect;
     663begin
     664  with TCDManager(TWinControl(ManagerItem.Control).DockManager) do
     665  case HeaderPos of
     666    hpLeft: begin
     667      Align := alLeft;
     668      Width := GrabberSize;
     669    end;
     670    hpTop, hpAuto: begin
     671      Align := alTop;
     672      Height := GrabberSize;
     673    end;
     674    hpRight: begin
     675      Align := alRight;
     676      Width := GrabberSize;
     677    end;
     678    hpBottom: begin
     679      Align := alBottom;
     680      Height := GrabberSize;
     681    end;
     682  end;
     683
    645684  if (ManagerItem.Control as TWinControl).Focused then
    646   Title.Font.Style := Font.Style + [fsBold]
    647   else Title.Font.Style := Font.Style - [fsBold];
    648 
    649   if Icon.Picture.Width > 0 then Title.Left := 8 + Icon.Picture.Width
    650     else Title.Left := 6;
    651   Title.Caption := ManagerItem.Control.Caption;
     685  Canvas.Font.Style := Canvas.Font.Style + [fsBold]
     686  else Canvas.Font.Style := Canvas.Font.Style - [fsBold];
     687
    652688  RearrangeButtons;
    653689
     
    689725    Pen.Color := BorderColor;
    690726    Polyline(Points);
     727
     728    Canvas.Brush.Style := bsClear;
     729    TitleMaxWidth := Self.Width - 6;
     730    for I := 0 to Buttons.Count - 1 do
     731      if TCDHeaderButton(Buttons[I]).Visible then
     732        Dec(TitleMaxWidth, TCDHeaderButton(Buttons[I]).Icon.Width + 2);
     733    if Icon.Picture.Width > 0 then begin
     734      TitleLeft := 8 + Icon.Picture.Width;
     735      Dec(TitleMaxWidth, Icon.Picture.Width + 2)
     736    end else TitleLeft := 6;
     737
     738    //SelectObject(Canvas.Handle, MyFont);
     739    Title := ManagerItem.Control.Caption;
     740    if (TextWidth(Title) > TitleMaxWidth) then begin
     741      while (Length(Title) > 0) and (TextWidth(Title + '...') > TitleMaxWidth) do begin
     742        Delete(Title, Length(Title), 1);
     743      end;
     744      Title := Title + '...';
     745    end;
     746
     747    R := Rect(TitleLeft, 4, TitleLeft + TitleMaxWidth, 4 + TextHeight(Title));
     748    TextRect(R, TitleLeft, 4, Title);
    691749  end;
    692750end;
Note: See TracChangeset for help on using the changeset viewer.