1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383:
                   |                                       TCustomPanel = class(TCustomControl)   private     FAutoSizeDocking: Boolean;     FBevelInner: TPanelBevel;     FBevelOuter: TPanelBevel;     FBevelWidth: TBevelWidth;     FBorderWidth: TBorderWidth;     FBorderStyle: TBorderStyle;     FFullRepaint: Boolean;     FLocked: Boolean;     FParentBackgroundSet: Boolean;     FAlignment: TAlignment;     FVerticalAlignment: TVerticalAlignment;     procedure CMBorderChanged(var Message: TMessage); message CM_BORDERCHANGED;     procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;     procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;     procedure CMIsToolControl(var Message: TMessage); message CM_ISTOOLCONTROL;     procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;     procedure SetAlignment(Value: TAlignment);     procedure SetBevelInner(Value: TPanelBevel);     procedure SetBevelOuter(Value: TPanelBevel);     procedure SetBevelWidth(Value: TBevelWidth);     procedure SetBorderWidth(Value: TBorderWidth);     procedure SetBorderStyle(Value: TBorderStyle);     procedure CMDockClient(var Message: TCMDockClient); message CM_DOCKCLIENT;     procedure SetVerticalAlignment(const Value: TVerticalAlignment);   protected     procedure CreateParams(var Params: TCreateParams); override;     procedure AdjustClientRect(var Rect: TRect); override;     function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;     procedure Paint; override;     property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;     property BevelInner: TPanelBevel read FBevelInner write SetBevelInner default bvNone;     property BevelOuter: TPanelBevel read FBevelOuter write SetBevelOuter default bvRaised;     property BevelWidth: TBevelWidth read FBevelWidth write SetBevelWidth default 1;     property BorderWidth: TBorderWidth read FBorderWidth write SetBorderWidth default 0;     property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsNone;     property Color default clBtnFace;     property FullRepaint: Boolean read FFullRepaint write FFullRepaint default True;     property Locked: Boolean read FLocked write FLocked default False;     property ParentColor default False;     property VerticalAlignment: TVerticalAlignment read FVerticalAlignment write SetVerticalAlignment default taVerticalCenter;     procedure SetParentBackground(Value: Boolean); override;   public     property ParentBackground stored FParentBackgroundSet default True;     constructor Create(AOwner: TComponent); override;     function GetControlsAlignment: TAlignment; override;   end;
    TPanel = class(TCustomPanel)   public     property DockManager;   published     property Align;     property Alignment;     property Anchors;     property AutoSize;     property BevelEdges;     property BevelInner;     property BevelKind;     property BevelOuter;     property BevelWidth;     property BiDiMode;     property BorderWidth;     property BorderStyle;     property Caption;     property Color;     property Constraints;     property Ctl3D;     property UseDockManager default True;     property DockSite;     property DragCursor;     property DragKind;     property DragMode;     property Enabled;     property FullRepaint;     property Font;     property Locked;     property ParentBiDiMode;     property ParentBackground;     property ParentColor;     property ParentCtl3D;     property ParentFont;     property ParentShowHint;     property PopupMenu;     property ShowHint;     property TabOrder;     property TabStop;     property VerticalAlignment;     property Visible;     property OnAlignInsertBefore;     property OnAlignPosition;     property OnCanResize;     property OnClick;     property OnConstrainedResize;     property OnContextPopup;     property OnDockDrop;     property OnDockOver;     property OnDblClick;     property OnDragDrop;     property OnDragOver;     property OnEndDock;     property OnEndDrag;     property OnEnter;     property OnExit;     property OnGetSiteInfo;     property OnMouseActivate;     property OnMouseDown;     property OnMouseMove;     property OnMouseUp;     property OnResize;     property OnStartDock;     property OnStartDrag;     property OnUnDock;   end;
 
 
 
 
  constructor TCustomPanel.Create(AOwner: TComponent); begin   inherited Create(AOwner);   ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,     csSetCaption, csOpaque, csDoubleClicks, csReplicatable];      if ThemeServices.ThemesEnabled then     ControlStyle := ControlStyle + [csParentBackground] - [csOpaque];   Width := 185;   Height := 41;   FAlignment := taCenter;   FVerticalAlignment := taVerticalCenter;   BevelOuter := bvRaised;   BevelWidth := 1;   FBorderStyle := bsNone;   Color := clBtnFace;   FFullRepaint := True;   UseDockManager := True;   ParentBackground := True; end;
  procedure TCustomPanel.CreateParams(var Params: TCreateParams); const   BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER); begin   inherited CreateParams(Params);   with Params do   begin     Style := Style or BorderStyles[FBorderStyle];     if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then     begin       Style := Style and not WS_BORDER;       ExStyle := ExStyle or WS_EX_CLIENTEDGE;     end;     WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);   end; end;
  procedure TCustomPanel.CMBorderChanged(var Message: TMessage); begin   inherited;   Invalidate; end;
  procedure TCustomPanel.CMTextChanged(var Message: TMessage); begin   Invalidate; end;
  procedure TCustomPanel.CMCtl3DChanged(var Message: TMessage); begin   if NewStyleControls and (FBorderStyle = bsSingle) then RecreateWnd;   inherited; end;
  procedure TCustomPanel.CMIsToolControl(var Message: TMessage); begin   if not FLocked then Message.Result := 1; end;
  procedure TCustomPanel.WMWindowPosChanged(var Message: TWMWindowPosChanged); var   BevelPixels: Integer;   Rect: TRect; begin   if FullRepaint or (Caption <> '') then     Invalidate   else   begin     BevelPixels := BorderWidth;     if BevelInner <> bvNone then Inc(BevelPixels, BevelWidth);     if BevelOuter <> bvNone then Inc(BevelPixels, BevelWidth);     if BevelPixels > 0 then     begin       Rect.Right := Width;       Rect.Bottom := Height;       if Message.WindowPos^.cx <> Rect.Right then       begin         Rect.Top := 0;         Rect.Left := Rect.Right - BevelPixels - 1;         InvalidateRect(Handle, @Rect, True);       end;       if Message.WindowPos^.cy <> Rect.Bottom then       begin         Rect.Left := 0;         Rect.Top := Rect.Bottom - BevelPixels - 1;         InvalidateRect(Handle, @Rect, True);       end;     end;   end;   inherited; end;
  procedure TCustomPanel.Paint; const   Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);   VerticalAlignments: array[TVerticalAlignment] of Longint = (DT_TOP, DT_BOTTOM, DT_VCENTER); var   Rect: TRect;   TopColor, BottomColor: TColor;   Flags: Longint;
    procedure AdjustColors(Bevel: TPanelBevel);   begin     TopColor := clBtnHighlight;     if Bevel = bvLowered then TopColor := clBtnShadow;     BottomColor := clBtnShadow;     if Bevel = bvLowered then BottomColor := clBtnHighlight;   end;
  begin   Rect := GetClientRect;   if BevelOuter <> bvNone then   begin     AdjustColors(BevelOuter);     Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);   end;   if not (ThemeServices.ThemesEnabled and (csParentBackground in ControlStyle)) then     Frame3D(Canvas, Rect, Color, Color, BorderWidth);   if BevelInner <> bvNone then   begin     AdjustColors(BevelInner);     Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);   end;   with Canvas do   begin     if not ThemeServices.ThemesEnabled or not ParentBackground then     begin       Brush.Color := Color;       FillRect(Rect);     end;     Brush.Style := bsClear;     Font := Self.Font;
      Flags := DT_EXPANDTABS or DT_SINGLELINE or       VerticalAlignments[FVerticalAlignment] or Alignments[FAlignment];     Flags := DrawTextBiDiModeFlags(Flags);     DrawText(Handle, PChar(Caption), -1, Rect, Flags);   end; end;
  procedure TCustomPanel.SetAlignment(Value: TAlignment); begin   FAlignment := Value;   Invalidate; end;
  procedure TCustomPanel.SetBevelInner(Value: TPanelBevel); begin   FBevelInner := Value;   Realign;   Invalidate; end;
  procedure TCustomPanel.SetBevelOuter(Value: TPanelBevel); begin   FBevelOuter := Value;   Realign;   Invalidate; end;
  procedure TCustomPanel.SetBevelWidth(Value: TBevelWidth); begin   FBevelWidth := Value;   Realign;   Invalidate; end;
  procedure TCustomPanel.SetBorderWidth(Value: TBorderWidth); begin   FBorderWidth := Value;   Realign;   Invalidate; end;
  procedure TCustomPanel.SetBorderStyle(Value: TBorderStyle); begin   if FBorderStyle <> Value then   begin     FBorderStyle := Value;     RecreateWnd;   end; end;
  function TCustomPanel.GetControlsAlignment: TAlignment; begin   Result := FAlignment; end;
  procedure TCustomPanel.AdjustClientRect(var Rect: TRect); var   BevelSize: Integer; begin   inherited AdjustClientRect(Rect);   InflateRect(Rect, -BorderWidth, -BorderWidth);   BevelSize := 0;   if BevelOuter <> bvNone then Inc(BevelSize, BevelWidth);   if BevelInner <> bvNone then Inc(BevelSize, BevelWidth);   InflateRect(Rect, -BevelSize, -BevelSize); end;
  procedure TCustomPanel.CMDockClient(var Message: TCMDockClient); var   R: TRect;   Dim: Integer; begin   if AutoSize then   begin     FAutoSizeDocking := True;     try       R := Message.DockSource.DockRect;       case Align of         alLeft: if Width = 0 then Width := R.Right - R.Left;         alRight: if Width = 0 then           begin             Dim := R.Right - R.Left;             SetBounds(Left - Dim, Top, Dim, Height);           end;         alTop: if Height = 0 then Height := R.Bottom - R.Top;         alBottom: if Height = 0 then           begin             Dim := R.Bottom - R.Top;             SetBounds(Left, Top - Dim, Width, Dim);           end;       end;       inherited;       Exit;     finally       FAutoSizeDocking := False;     end;   end;   inherited; end;
  function TCustomPanel.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; begin   Result := (not FAutoSizeDocking) and inherited CanAutoSize(NewWidth, NewHeight); end;
  procedure TCustomPanel.SetParentBackground(Value: Boolean); begin      if Value then     ControlStyle := ControlStyle - [csOpaque]   else     ControlStyle := ControlStyle + [csOpaque];   FParentBackgroundSet := True;   inherited; end;
  procedure TCustomPanel.SetVerticalAlignment(const Value: TVerticalAlignment); begin   FVerticalAlignment := Value;   Invalidate; end;                                      |