unit Panels_Shared;

interface

Uses
  Windows, Extctrls, Classes, Messages, ComCtrls, Controls;

procedure MDown(Sender: TObject; X, Y: integer);
procedure MMove(Sender: TObject; X, Y: integer);

const
  BORDERMARGIN = 4;
  sc_DragMove = $f012;
  sc_LeftSize = $f001;
  sc_RightSize = $f002;
  sc_UpSize = $f003;
  sc_UpLeftSize = $f004;
  sc_DnRightSize = $f005;
  sc_DnSize = $f006;
  sc_DnLeftSize = $f007;
  sc_UpRightSize = $f008;

implementation

procedure MDown(Sender: TObject; X, Y: integer);
var
  resizeaction: integer;
begin
  Resizeaction := 0;
  ReleaseCapture;
  case (Sender as TCustomControl).Cursor of
    crSizeWE: if X < BORDERMARGIN then resizeaction := sc_LeftSize
                else resizeaction := sc_RightSize;
    crSizeNS: if Y < BORDERMARGIN then resizeaction := sc_UpSize
                else resizeaction := sc_DnSize;
    crSizeNWSE: if X < BORDERMARGIN then resizeaction := sc_UpLeftSize
                  else resizeaction := sc_UpRightSize;
    crSizeNESW: if X < BORDERMARGIN then resizeaction := sc_DnLeftSize
                  else resizeaction := sc_DnRightSize;
    crDefault: resizeaction := sc_DragMove;
  end;
  if resizeaction > 0 then (Sender as TCustomControl).Perform(wm_SysCommand, resizeaction, 0);
end;

procedure MMove(Sender: TObject; X, Y: integer);
var
  c: tCursor;
  lm,rm,tm,bm: boolean;
begin
  tm := (Y < BORDERMARGIN);
  lm := (X < BORDERMARGIN);
  rm := ((Sender as TCustomControl).Width - X <= BORDERMARGIN);
  bm := ((Sender as TCustomControl).Height - Y <= BORDERMARGIN);
  c := crDefault;
  if (bm or tm) then c := crSizeNS;
  if (lm or rm) then c := crSizeWE;
  if ((lm and tm) or (rm and bm)) then c := crSizeNWSE;
  if ((rm and tm) or (lm and bm)) then c := crSizeNESW;
  if (Sender as TCustomControl).Cursor <> c then (Sender as TCustomControl).Cursor := c;
end;

end.
