home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kolekce / d345 / JWTOOL.ZIP / jwtool / Jwfshpn.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-29  |  10.4 KB  |  382 lines

  1. unit Jwfshpn;
  2.  
  3. {
  4.         **   VERSION History   **
  5.    Version     Date     Notes
  6.     v1.00  - 01APR99    Original Release
  7. }
  8.  
  9. {
  10.      Three stage buttons:
  11.            The idea is that you want one "look" in an "unfocused" state, another
  12.      when you are in a "mouseover" state, and a third when you are clicking.  This
  13.      idea is taken in the FlashClick, FlashPanel, and PopButton.
  14.  
  15.           The FlashClick shares a lot of code with the flash panel.  The difference is
  16.      that the FlashClick is inherited from a TLabel, and therefore does not have a
  17.      canvas of it's own, which can save on memory.  Since there isn't a default MouseExit
  18.      and MouseEnter events (I got use to those programming in XWindows...) I had to make
  19.      my own.  But in essence, you now have a lowmemory Web-like button.
  20.  
  21. }
  22.  
  23. //  Created By:
  24. //    Joseph Wilcock
  25. //    Coockoo@hotmail.com
  26. //    http://msnhomepages.talkcity.com/RedmondAve/coockoo/
  27.  
  28. interface
  29.  
  30. uses {$IFDEF WIN32} Windows, {$ELSE} WinProcs, WinTypes, {$ENDIF}
  31.      Messages, SysUtils, Classes, Controls, Forms, Graphics,
  32.      Stdctrls, extctrls;
  33.  
  34. type
  35. {Windows Messaging is rather nasty.  Since I want to add user-defined methods to
  36. something that delphi hasn't already defined, namely OnMouseExit and OnMouseEnter,
  37. I will have to do it myself.  First, I need to redefine the message record.  In
  38. this case I literally took it from the TWMMouse message, repeated twice under two
  39. names.  (I Might want to change that later).}
  40.  
  41.   TWMMouseExit = record
  42.     Msg: Cardinal;
  43.     Keys: Longint;
  44.     case Integer of
  45.       0: (
  46.         XPos: Smallint;
  47.         YPos: Smallint);
  48.       1: (
  49.         Pos: TSmallPoint;
  50.         Result: Longint);
  51.   end;
  52.  
  53.   TWMMouseEnter = record
  54.     Msg: Cardinal;
  55.     Keys: Longint;
  56.     case Integer of
  57.       0: (
  58.         XPos: Smallint;
  59.         YPos: Smallint);
  60.       1: (
  61.         Pos: TSmallPoint;
  62.         Result: Longint);
  63.   end;
  64.  
  65.  
  66.   {The next thing to do is define a new custom "TNotify" event.  Once again,
  67.   even though I am repeating myself, I'm going to use the same thing twice
  68.   just in case I want to change things.}
  69.   TMouseExit = procedure(Sender: TObject; Button: TMouseButton;
  70.     Shift: TShiftState; X, Y: Integer) of object;
  71.   TMouseEnter = procedure(Sender: TObject; Button: TMouseButton;
  72.     Shift: TShiftState; X, Y: Integer) of object;
  73.  
  74.   TJwFlashPanel = class(TPanel)
  75.     private
  76.       { Private fields of TJwFlashClick }
  77.  
  78.         {The TNotifyEvent objects to use on the specific events}
  79.         FOnEnter: TMouseEnter;
  80.         FOnExit: TMouseExit;
  81.  
  82.         procedure WMSize(var Message: TWMSize); message WM_SIZE;
  83.         procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
  84.         procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
  85.  
  86.         {FINALLY.. we have a 3-stage event.  The CMMouseEnter and CMMouseLeave are the functions
  87.         that actually look for the CM_MOUSEENTER and CM_MOUSELEAVE in the WinMain command loop.
  88.         Once it hits, it will call the corresponding "Do" method which will call the "Mouse..."
  89.         and that will call the TNotfy event if it is assigned.}
  90.         procedure CMMouseEnter({var msg: TMessage}var Message: TWMMouseEnter); message CM_MOUSEENTER;
  91.         procedure CMMouseLeave({var msg: TMessage}var Message: TWMMouseExit); message CM_MOUSELEAVE;
  92.         procedure MouseEnter(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  93.         procedure DoMouseEnter(var Message: TWMMouseEnter; Button: TMouseButton;
  94.                     Shift: TShiftState);
  95.         procedure DoMouseExit(var Message: TWMMouseExit; Button: TMouseButton;
  96.                     Shift: TShiftState);
  97.         procedure MouseExit(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  98.  
  99.         Procedure SetFlareFont( Value: TFont );
  100.         Procedure SetBaseFont( Value: TFont );
  101.         Procedure SetClickFont( Value: TFont );
  102.         Procedure SetCommonFont( Value: TFont );
  103.     protected
  104.         FCheckEffect: Boolean;
  105.         FFlareMode: Byte;
  106.         FBaseFont: TFont;
  107.         FFlareFont: TFont;
  108.         FClickFont: TFont;
  109.  
  110.       { Protected methods of TJwFlashClick }
  111.         procedure Click; override;
  112.         procedure Loaded; override;
  113.         procedure Paint; override;
  114.  
  115.         Procedure SetCheckedValue( Value: Boolean );
  116.         Function GetCheckValue: Boolean;
  117.  
  118.     public
  119.       { Public fields and properties of TJwFlashClick }
  120.  
  121.       { Public methods of TJwFlashClick }
  122.         constructor Create(AOwner: TComponent); override;
  123.         destructor Destroy; override;
  124.  
  125.     published
  126.       { Published properties of TJwFlashClick }
  127.         Property BaseFont: TFont Read FBaseFont Write SetBaseFont;
  128.         Property FlareFont: TFont Read FFlareFont Write SetFlareFont;
  129.         Property ClickFont: TFont Read FClickFont Write SetClickFont;
  130.         Property CommonFont: TFont Read FBaseFont Write SetCommonFont;
  131.  
  132.         Property CheckEffect: Boolean Read FCheckEffect Write FCheckEffect;
  133.         Property Anchors;
  134.         Property Alignment;
  135.         Property Align;
  136.         Property BevelInner;
  137.         Property BevelOuter;
  138.         Property BevelWidth;
  139.         Property BorderStyle;
  140.         {$IFDEF WIN32}
  141.         Property FullRepaint;
  142.         Property Locked;
  143.         {$ENDIF}
  144.         Property Ctl3D;
  145.         Property Color;
  146.         Property Cursor;
  147.         Property Height;
  148.         Property Hint;
  149.         Property Left;
  150.         Property Name;
  151.         Property ParentColor;
  152.         Property ShowHint;
  153.         Property Top;
  154.         Property Visible;
  155.         Property Width;
  156.         Property Caption;
  157.         Property Tag;
  158.  
  159.         Property OnEnter: TMouseEnter Read FOnEnter Write FOnEnter;
  160.         Property OnExit: TMouseExit Read FOnExit Write FOnExit;
  161.  
  162.         property OnClick;
  163.         property OnDblClick;
  164.         property OnDragDrop;
  165.         property OnMouseDown;
  166.         property OnMouseMove;
  167.         property OnMouseUp;
  168.         property OnResize;
  169.  
  170.   end;
  171.  
  172. procedure Register;
  173.  
  174. implementation
  175.  
  176. procedure Register;
  177. begin
  178.      { Register TJwFlashClick with Standard as its
  179.        default page on the Delphi component palette }
  180.      RegisterComponents('JwTools', [TJwFlashPanel]);
  181. end;
  182.  
  183. Procedure TJwFlashPanel.SetCheckedValue( Value: Boolean );
  184. begin
  185.   if ( FCheckEffect ) then
  186.     begin
  187.       if Value then
  188.         FFlareMode := 3
  189.       else
  190.         FFlareMode := 0;
  191.       InValidate;
  192.     end;
  193. end;
  194.  
  195. Function TJwFlashPanel.GetCheckValue: Boolean;
  196. begin
  197.   Result := ( FFlareMode = 3 );
  198. end;
  199.  
  200. Procedure TJwFlashPanel.SetCommonFont( Value: TFont );
  201. begin
  202.   {if Value <> FClickFont then
  203.     begin}
  204.       FClickFont.Assign( Value );
  205.       FBaseFont.Assign( Value );
  206.       FFlareFont.Assign( Value );
  207.       Invalidate;
  208.     {end;}
  209. end;
  210.  
  211. Procedure TJwFlashPanel.SetClickFont( Value: TFont );
  212. begin
  213.   {if Value <> FClickFont then
  214.     begin}
  215.       FClickFont.Assign( Value );
  216.       Invalidate;
  217.     {end;}
  218. end;
  219.  
  220. Procedure TJwFlashPanel.SetBaseFont( Value: TFont );
  221. begin
  222.   {if Value <> FBaseFont then
  223.     begin}
  224.       FBaseFont.Assign( Value );
  225.       Invalidate;
  226.     {end;}
  227. end;
  228.  
  229. Procedure TJwFlashPanel.SetFlareFont( Value: TFont );
  230. begin
  231.   {if Value <> FFlareFont then
  232.     begin}
  233.       FFlareFont.Assign( Value );
  234.       Invalidate;
  235.     {end;}
  236. end;
  237.  
  238. { Override OnClick handler from TLabel }
  239. procedure TJwFlashPanel.Click;
  240. begin
  241.      inherited Click;
  242.  
  243. end;
  244.  
  245.  
  246. constructor TJwFlashPanel.Create(AOwner: TComponent);
  247. begin
  248.      { Call the Create method of the parent class }
  249.   inherited Create(AOwner);
  250.  
  251.   FBaseFont := TFont.Create;
  252.   FFlareFont := TFont.Create;
  253.   FClickFont := TFont.Create;
  254.  
  255.   FFlareMode := 0;
  256.   FBaseFont.Assign( Self.Font );
  257.   FBaseFont.Color := clWhite;
  258.   FFlareFont.Assign( Self.Font );
  259.   FFlareFont.Size := FFlareFont.Size + 2;
  260.   FFlareFont.Color := clYellow;
  261.   FClickFont.Assign( Self.Font );
  262.   FClickFont.Size := ClickFont.Size + 2;
  263.   FClickFont.Color := clRed;
  264. end;
  265.  
  266. destructor TJwFlashPanel.Destroy;
  267. begin
  268.   FBaseFont.Free;
  269.   FFlareFont.Free;
  270.   FClickFont.Free;
  271.   inherited Destroy;
  272. end;
  273.  
  274. procedure TJwFlashPanel.Loaded;
  275. begin
  276.      inherited Loaded;
  277. end;
  278.  
  279. procedure TJwFlashPanel.Paint;
  280. begin
  281.      case FFlareMode of
  282.        0: begin
  283.             Self.Font := FBaseFont;
  284.           end;
  285.        1: begin
  286.             Self.Font := FFlareFont;
  287.           end;
  288.      2,3: begin
  289.             Self.Font := FClickFont;
  290.           end;
  291.      else
  292.        Self.Font := FBaseFont;
  293.      end;
  294.  
  295.      inherited Paint;
  296. end;
  297.  
  298. procedure TJwFlashPanel.WMSize(var Message: TWMSize);
  299. var
  300.      W, H: Integer;
  301. begin
  302.      inherited;
  303.  
  304.      W := Width;
  305.      H := Height;
  306.  
  307.      if (W <> Width) or (H <> Height) then
  308.         inherited SetBounds(Left, Top, W, H);
  309.  
  310.      Message.Result := 0;
  311. end;
  312.  
  313. procedure TJwFlashPanel.CMMouseEnter(var Message: TWMMouseEnter);
  314. begin
  315.   if ( FFlareMode <> 3 ) then
  316.     begin
  317.       FFlareMode := 1;
  318.       Invalidate;
  319.     end;
  320.   Inherited;
  321.   DoMouseEnter(Message, mbLeft, []);
  322. end;
  323.  
  324. procedure TJwFlashPanel.CMMouseLeave(var Message: TWMMouseExit);
  325. begin
  326.   if ( FFlareMode <> 3 ) then
  327.     begin
  328.       FFlareMode := 0;
  329.       Invalidate;
  330.     end;
  331.   Inherited;
  332.   DoMouseExit(Message, mbLeft, []);
  333. end;
  334.  
  335. procedure TJwFlashPanel.WMLButtonDown(var Message: TWMLButtonDown);
  336. begin
  337.   if ( FCheckEffect ) and ( FFlareMode <> 3 ) then
  338.     FFlareMode := 3
  339.   else
  340.     FFlareMode := 2;
  341.   Invalidate;
  342.   Inherited;
  343. end;
  344.  
  345. procedure TJwFlashPanel.WMLButtonUp(var Message: TWMLButtonUp);
  346. begin
  347.   if ( FFlareMode <> 3 ) then
  348.     begin
  349.       FFlareMode := 1;
  350.       Invalidate;
  351.     end;
  352.   Inherited;
  353. end;
  354.  
  355. procedure TJwFlashPanel.DoMouseEnter(var Message: TWMMouseEnter; Button: TMouseButton;
  356.   Shift: TShiftState);
  357. begin
  358.   with Message do
  359.     MouseEnter(Button, KeysToShiftState(Keys) + Shift, XPos, YPos);
  360. end;
  361.  
  362. procedure TJwFlashPanel.MouseEnter(Button: TMouseButton;
  363.   Shift: TShiftState; X, Y: Integer);
  364. begin
  365.   if Assigned(FOnEnter) then FOnEnter(Self, Button, Shift, X, Y);
  366. end;
  367.  
  368. procedure TJwFlashPanel.DoMouseExit(var Message: TWMMouseExit; Button: TMouseButton;
  369.   Shift: TShiftState);
  370. begin
  371.   with Message do
  372.     MouseExit(Button, KeysToShiftState(Keys) + Shift, XPos, YPos);
  373. end;
  374.  
  375. procedure TJwFlashPanel.MouseExit(Button: TMouseButton;
  376.   Shift: TShiftState; X, Y: Integer);
  377. begin
  378.   if Assigned(FOnExit) then FOnExit(Self, Button, Shift, X, Y);
  379. end;
  380.  
  381. end.
  382.