home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / Essentials / SETUP.EXE / %MAINDIR% / EsRollUp.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-11-28  |  8.7 KB  |  353 lines

  1. {*********************************************************}
  2. {*                  ESROLLUP.PAS 1.05                    *}
  3. {*      Copyright (c) 1997-98 TurboPower Software Co     *}
  4. {*                 All rights reserved.                  *}
  5. {*********************************************************}
  6.  
  7. {$I ES.INC}
  8.  
  9. {$B-} {Complete Boolean Evaluation}
  10. {$I+} {Input/Output-Checking}
  11. {$P+} {Open Parameters}
  12. {$T-} {Typed @ Operator}
  13. {$W-} {Windows Stack Frame}
  14. {$X+} {Extended Syntax}
  15.  
  16. {$IFNDEF Win32}
  17. {$G+} {286 Instructions}
  18. {$N+} {Numeric Coprocessor}
  19.  
  20. {$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
  21. {$ENDIF}
  22.  
  23. unit EsRollUp;
  24.  
  25. interface
  26.  
  27. uses
  28.   {$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  29.   Classes, Forms, Messages, MMSystem,
  30.   EsConst, EsData;
  31.  
  32. const
  33.   ruDefAnimate      = True;
  34.   ruDefAnimateSpeed = 8;
  35.  
  36. type
  37.   TEsAnimateSpeed = 0..10;
  38.  
  39.   TEsCustomRollUp = class(TComponent)
  40.   protected {private}
  41.     {.Z+}
  42.     {property variables}
  43.     FAnimate      : Boolean;
  44.     FAnimateSpeed : TEsAnimateSpeed;
  45.     FHookForm     : Boolean;
  46.     FMinHeight    : Integer;
  47.  
  48.     {event variables}
  49.     FOnRollDown: TNotifyEvent;
  50.     FOnRollUp  : TNotifyEvent;
  51.  
  52.     {internal variables}
  53.     ruNewWndProc  : TFarProc;
  54.     ruOldHeight   : Integer;
  55.     ruPrevWndProc : TFarProc;
  56.  
  57.     {property methods}
  58.     function GetRolledUp : Boolean;
  59.     function GetVersion : string;
  60.     procedure SetAnimateSpeed(Value : TEsAnimateSpeed);
  61.     procedure SetHookForm(Value : Boolean);
  62.     procedure SetMinHeight(Value : Integer);
  63.     procedure SetRolledUp(Value : Boolean);
  64.     procedure SetVersion(const Value : string);
  65.  
  66.     {internal methods}
  67.     procedure ruWndProc(var Msg : TMessage);
  68.     {.Z-}
  69.  
  70.   protected
  71.     {.Z+}
  72.     procedure DoOnRollDown;
  73.       dynamic;
  74.     procedure DoOnRollUp;
  75.       dynamic;
  76.     {.Z-}
  77.  
  78.     {properties}
  79.     property Animate : Boolean
  80.       read FAnimate
  81.       write FAnimate
  82.       default ruDefAnimate;
  83.  
  84.     property AnimateSpeed : TEsAnimateSpeed
  85.       read FAnimateSpeed
  86.       write FAnimateSpeed
  87.       default ruDefAnimateSpeed;
  88.  
  89.     property HookForm : Boolean
  90.       read FHookForm
  91.       write SetHookForm
  92.       default False;
  93.  
  94.     property MinHeight : Integer
  95.       read FMinHeight
  96.       write SetMinHeight;
  97.  
  98.     property RolledUp : Boolean
  99.       read GetRolledUp
  100.       write SetRolledUp
  101.       stored False;
  102.  
  103.     property Version : string
  104.       read GetVersion
  105.       write SetVersion
  106.       stored False;
  107.  
  108.     {events}
  109.     property OnRollDown : TNotifyEvent
  110.       read FOnRollDown
  111.       write FOnRollDown;
  112.  
  113.     property OnRollUp : TNotifyEvent
  114.       read FOnRollUp
  115.       write FOnRollUp;
  116.  
  117.   public
  118.     {.Z+}
  119.     constructor Create(AOwner : TComponent);
  120.       override;
  121.     destructor Destroy;
  122.       override;
  123.     {.Z-}
  124.   end;
  125.  
  126.   TEsRollUp = class(TEsCustomRollUp)
  127.   published
  128.     {properties}
  129.     property Animate;
  130.     property AnimateSpeed;
  131.     property HookForm;
  132.     property MinHeight;
  133.     property RolledUp;
  134.     property Version;
  135.  
  136.     {events}
  137.     property OnRollDown;
  138.     property OnRollUp;
  139.   end;
  140.  
  141.  
  142. implementation
  143.  
  144.  
  145. {$IFDEF TRIALRUN}
  146. uses
  147.   EsTrial;
  148. {$I ESTRIALF.INC}
  149. {$ENDIF}
  150.  
  151.  
  152. constructor TEsCustomRollUp.Create(AOwner : TComponent);
  153. {$IFDEF TRIALRUN}
  154. var
  155.   X : Integer;
  156. {$ENDIF}
  157. begin
  158.   inherited Create(AOwner);
  159.  
  160.   {create instance of our window procedure}
  161.   ruNewWndProc := MakeObjectInstance(ruWndProc);
  162.  
  163.   FAnimate      := ruDefAnimate;
  164.   FAnimateSpeed := ruDefAnimateSpeed;
  165.   FHookForm     := False;
  166.   FMinHeight    := 0;
  167.  
  168. {$IFDEF TRIALRUN}
  169.   X := _CC_;
  170.   if (X < ccRangeLow) or (X > ccRangeHigh) then Halt;
  171.   X := _VC_;
  172.   if (X < ccRangeLow) or (X > ccRangeHigh) then Halt;
  173. {$ENDIF}
  174. end;
  175.  
  176. destructor TEsCustomRollUp.Destroy;
  177. begin
  178.   {restore old wnd proc}
  179.   SetHookForm(False);
  180.  
  181.   FreeObjectInstance(ruNewWndProc);
  182.  
  183.   inherited Destroy;
  184. end;
  185.  
  186. procedure TEsCustomRollUp.DoOnRollDown;
  187. begin
  188.   if Assigned(FOnRollDown) then
  189.     FOnRollDown(Self);
  190. end;
  191.  
  192. procedure TEsCustomRollUp.DoOnRollUp;
  193. begin
  194.   if Assigned(FOnRollUp) then
  195.     FOnRollUp(Self);
  196. end;
  197.  
  198. function TEsCustomRollUp.GetRolledUp : Boolean;
  199. begin
  200.   Result := (Owner is TForm) and (FMinHeight >= TForm(Owner).ClientHeight);
  201. end;
  202.  
  203. function TEsCustomRollUp.GetVersion : string;
  204. begin
  205.   Result := EsVersionStr;
  206. end;
  207.  
  208. procedure TEsCustomRollUp.ruWndProc(var Msg : TMessage);
  209. begin
  210.   with Msg do begin
  211.     if (Msg = WM_SYSCOMMAND) and (wParam = SC_MINIMIZE) then begin
  212.       if not IsIconic(TForm(Owner).Handle) and not RolledUp then begin
  213.         {click on minimize button}
  214.         try
  215.           SetRolledUp(True);
  216.         except
  217.           Application.HandleException(Self);
  218.         end;
  219.       end else
  220.         if Assigned(ruPrevWndProc) then
  221.           Result := CallWindowProc(ruPrevWndProc, TForm(Owner).Handle, Msg, wParam, lParam);
  222.     end else if (Msg = WM_SYSCOMMAND) and (wParam = SC_MAXIMIZE) then begin
  223.       if not IsZoomed(TForm(Owner).Handle) and RolledUp then begin
  224.         {click on maximize button}
  225.         try
  226.           SetRolledUp(False);
  227.         except
  228.           Application.HandleException(Self);
  229.         end;
  230.       end else
  231.         if Assigned(ruPrevWndProc) then
  232.           Result := CallWindowProc(ruPrevWndProc, TForm(Owner).Handle, Msg, wParam, lParam);
  233.     end else
  234.       if Assigned(ruPrevWndProc) then
  235.         Result := CallWindowProc(ruPrevWndProc, TForm(Owner).Handle, Msg, wParam, lParam);
  236.   end;
  237. end;
  238.  
  239. procedure TEsCustomRollUp.SetAnimateSpeed(Value : TEsAnimateSpeed);
  240. begin
  241.   if (Value <> FAnimateSpeed) then
  242.     FAnimateSpeed := Value;
  243. end;
  244.  
  245. procedure TEsCustomRollUp.SetHookForm(Value : Boolean);
  246. begin
  247.   if (Owner is TForm) and (Value <> FHookForm) then begin
  248.     FHookForm := Value;
  249.     if not (csDesigning in ComponentState) then begin
  250.       if Value then begin
  251.         ruPrevWndProc:= Pointer(
  252.           SetWindowLong(TForm(Owner).Handle, GWL_WNDPROC, LongInt(ruNewWndProc)))
  253.       end else if Assigned(ruPrevWndProc) then begin
  254.         SetWindowLong(TForm(Owner).Handle, GWL_WNDPROC, LongInt(ruPrevWndProc));
  255.         ruPrevWndProc := nil;
  256.       end;
  257.     end;
  258.   end;
  259. end;
  260.  
  261. procedure TEsCustomRollUp.SetMinHeight(Value : Integer);
  262. var
  263.   WasRolledUp : Boolean;
  264. begin
  265.   if (Value >= 0) and (Value <> FMinHeight) then begin
  266.     WasRolledUp := RolledUp;
  267.     FMinHeight := Value;
  268.     if WasRolledUp then
  269.       RolledUp := True;
  270.   end;
  271. end;
  272.  
  273. procedure TEsCustomRollUp.SetRolledUp(Value : Boolean);
  274. const
  275.   TMult = 5;
  276. var
  277.   I           : Integer;
  278.   Form        : TForm;
  279.   SC          : Boolean;
  280.   Step        : Integer;
  281.   SpeedFactor : Integer;
  282.   T           : DWord;                                                 {!!.05}
  283. begin
  284.   if (Owner is TForm) then begin
  285.     Form := TForm(Owner);
  286.     SpeedFactor := High(FAnimateSpeed) - FAnimateSpeed + 1;
  287.     if Value then begin
  288.       ruOldHeight := Form.ClientHeight;
  289.       SC := Form.AutoScroll;
  290.       Form.AutoScroll := False;
  291.       try
  292.         if FAnimate then begin
  293.           Step := ruOldHeight div (SpeedFactor * 3);
  294.           if Step < 2 then Step := 2;
  295.           I := ruOldHeight+Step;
  296.           while I > FMinHeight do begin
  297.             Dec(I, Step);
  298.             if I < FMinHeight then
  299.               I := FMinHeight;
  300.             Form.ClientHeight := I;
  301.             Application.ProcessMessages;
  302.             if FAnimateSpeed <> High(FAnimateSpeed) then begin
  303.               T := timeGetTime;
  304.               while Abs(timeGetTime - T) < (SpeedFactor * TMult) do {wait};
  305.             end;
  306.           end;
  307.         end else
  308.           Form.ClientHeight := FMinHeight;
  309.       finally
  310.         Form.AutoScroll := SC;
  311.       end;
  312.  
  313.       FMinHeight := Form.ClientHeight;
  314.       DoOnRollUp;
  315.     end else begin
  316.       if (ruOldHeight < FMinHeight) then
  317.         ruOldHeight := FMinHeight;
  318.  
  319.       SC := Form.AutoScroll;
  320.       Form.AutoScroll := False;
  321.       try
  322.         if FAnimate then begin
  323.           Step := ruOldHeight div (SpeedFactor * 3);
  324.           if Step < 2 then Step := 2;
  325.           I := FMinHeight-Step;
  326.           while I < ruOldHeight do begin
  327.             Inc(I, Step);
  328.             if I > ruOldHeight then
  329.               I := ruOldHeight;
  330.             Form.ClientHeight := I;
  331.             Application.ProcessMessages;
  332.             if FAnimateSpeed <> High(FAnimateSpeed) then begin
  333.               T := timeGetTime;
  334.               while Abs(timeGetTime - T) < (SpeedFactor * TMult) do {wait};
  335.             end;
  336.           end;
  337.         end else
  338.           Form.ClientHeight := ruOldHeight;
  339.       finally
  340.         Form.AutoScroll := SC;
  341.       end;
  342.  
  343.       DoOnRollDown;
  344.     end;
  345.   end;
  346. end;
  347.  
  348. procedure TEsCustomRollup.SetVersion(const Value : string);
  349. begin
  350. end;
  351.  
  352. end.
  353.