home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 December / Chip_2002-12_cd1.bin / zkuste / delphi / kompon / d234567 / MAGNET.ZIP / Int / FormMagnet.int
Encoding:
Text File  |  2002-09-23  |  4.8 KB  |  149 lines

  1. {*******************************************************************************
  2.  
  3.   FILE: FormMagnet.pas - FormMagnet component.
  4.  
  5.   Copyright (c) 1998-2001 UtilMind Solutions
  6.   All rights reserved.
  7.   E-Mail: info@utilmind.com
  8.   WWW: http://www.utilmind.com, http://www.appcontrols.com
  9.  
  10.   The entire contents of this file is protected by International Copyright
  11. Laws. Unauthorized reproduction, reverse-engineering, and distribution of all
  12. or any portion of the code contained in this file is strictly prohibited and
  13. may result in severe civil and criminal penalties and will be prosecuted to
  14. the maximum extent possible under the law.
  15.  
  16.   Restrictions
  17.  
  18.   The source code contained within this file and all related files or any
  19. portion of its contents shall at no time be copied, transferred, sold,
  20. distributed, or otherwise made available to other individuals without express
  21. written consent and permission from the UtilMind Solutions.
  22.  
  23.   Consult the End User License Agreement (EULA) for information on additional
  24. restrictions.
  25.  
  26. *******************************************************************************}
  27.  
  28.  
  29. unit FormMagnet;
  30.  
  31. interface
  32.  
  33. uses
  34.   Windows, Messages, Classes, Forms;
  35.  
  36. type
  37.   TFormMagnet = class;
  38.  
  39. { *** AppControls classes *** }
  40.   TMagnetFormHookComponent = class(TComponent)
  41.   private
  42.     Hooked: Boolean;
  43.     FParentForm: TForm;
  44.     FParentHandle: THandle;
  45.     FOldWndProc, FNewWndProc: Pointer;
  46.  
  47.     procedure HookWndProc(var Message: TMessage);
  48.   protected
  49.     procedure MessageBefore(var Message: TMessage; var Handled: Boolean); virtual;
  50.     procedure MessageAfter(var Message: TMessage); virtual;
  51.     procedure FormRecreate; virtual;
  52.     
  53.     function  GetParentHandle: THandle; virtual;
  54.   public
  55.     constructor Create(aOwner: TComponent); override;
  56.     destructor Destroy; override;
  57.  
  58.     property ParentForm: TForm read FParentForm;
  59.     property ParentHandle: THandle read FParentHandle;
  60.     property OldWndProc: Pointer read FOldWndProc;
  61.   end;
  62. { *** *** *** *** *** *** *** }
  63.  
  64.   TScreenArea = (saFullScreen, saWorkArea);
  65.   TScreenMagnet = class(TPersistent)
  66.   private
  67.     FArea: TScreenArea;
  68.     FDesktopPower: Byte;
  69.     FTop, FBottom, FLeft, FRight: Boolean;
  70.   public
  71.     constructor Create;
  72.   published
  73.     property Area: TScreenArea read FArea write FArea;
  74.     property DesktopPower: Byte read FDesktopPower write FDesktopPower;
  75.     property Top: Boolean read FTop write FTop;
  76.     property Bottom: Boolean read FBottom write FBottom;
  77.     property Left: Boolean read FLeft write FLeft;
  78.     property Right: Boolean read FRight write FRight;
  79.   end;
  80.  
  81.   TGluedObject = class(TObject)
  82.   private
  83.     Magnet: TFormMagnet;
  84.     Position: TPoint;
  85.   public
  86.     constructor Create(aMagnet: TFormMagnet; aLeft, aTop: Integer);
  87.   end;
  88.  
  89.   TGlueList = class(TList)
  90.   public
  91.     function IsGluedTo(Magnet: TFormMagnet): Boolean;
  92.     function GetFormPositionByMagnet(Magnet: TFormMagnet): TPoint;
  93.   end;
  94.  
  95.   TOnGlue = procedure(Sender: TObject; AnotherForm: TForm; var AllowGlue: Boolean) of object;
  96.   TOnMagnet = procedure(Sender: TObject; AnotherForm: TForm; var AllowMagnet: Boolean) of object;
  97.   TMagnetType = (mkOnMoving, mkAfterMoving);
  98.   TFormMagnet = class(TMagnetFormHookComponent)
  99.   private
  100.     FActive: Boolean;
  101.     FGlue: Boolean;
  102.     FFormDragable: Boolean;
  103.     FMagnetType: TMagnetType;
  104.     FPower: Byte;
  105.     FScreenMagnet: TScreenMagnet;
  106.  
  107.     FOnGlue: TOnGlue;
  108.     FOnMagnet: TOnMagnet;
  109.     FOnDragMove: TNotifyEvent;    
  110.  
  111.     { internal variables }
  112.     Suspended: Boolean;
  113.     GluedTo: TGlueList;
  114.     Moving: Boolean;
  115.     BeginMovingPos: TPoint;
  116.  
  117.     procedure SetActive(Value: Boolean);
  118.  
  119.     function AllowGlueTo(AnotherMagnet: TFormMagnet): Boolean;
  120.     function AllowMagnetTo(AnotherMagnet: TFormMagnet): Boolean;
  121.  
  122.     procedure RecalculateGluing;
  123.     procedure MagnetByDraggingRect(var DraggingRect: TRect; CalculateRelativePlacement, GlueOnly: Boolean);
  124.   protected
  125.     procedure MessageBefore(var Message: TMessage; var Handled: Boolean); override;
  126.     procedure MessageAfter(var Message: TMessage); override;
  127.  
  128.   public
  129.     constructor Create(aOwner: TComponent); override;
  130.     destructor Destroy; override;
  131.  
  132.     procedure DoMagnet;
  133.   published
  134.     property Active: Boolean read FActive write SetActive;
  135.     property Glue: Boolean read FGlue write FGlue;
  136.     property FormDragable: Boolean read FFormDragable write FFormDragable;
  137.     property MagnetType: TMagnetType read FMagnetType write FMagnetType;
  138.     property Power: Byte read FPower write FPower;
  139.     property ScreenMagnet: TScreenMagnet read FScreenMagnet write FScreenMagnet;
  140.  
  141.     property OnGlue: TOnGlue read FOnGlue write FOnGlue;
  142.     property OnMagnet: TOnMagnet read FOnMagnet write FOnMagnet;
  143.     property OnDragMove: TNotifyEvent read FOnDragMove write FOnDragMove;    
  144.   end;
  145.  
  146. procedure Register;
  147.  
  148. implementation
  149.