JvIpBox.pas
上传用户:henghua
上传日期:2009-12-11
资源大小:9486k
文件大小:7k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {-----------------------------------------------------------------------------
  2. The contents of this file are subject to the Mozilla Public License
  3. Version 1.1 (the "License"); you may not use this file except in compliance
  4. with the License. You may obtain a copy of the License at
  5. http://www.mozilla.org/MPL/MPL-1.1.html
  6. Software distributed under the License is distributed on an "AS IS" basis,
  7. WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
  8. the specific language governing rights and limitations under the License.
  9. The Original Code is: JvIpBox.PAS, released on 2001-02-28.
  10. The Initial Developer of the Original Code is S閎astien Buysse [sbuysse@buypin.com]
  11. Portions created by S閎astien Buysse are Copyright (C) 2001 S閎astien Buysse.
  12. All Rights Reserved.
  13. Contributor(s): Michael Beck [mbeck@bigfoot.com].
  14. Last Modified: 2000-02-28
  15. You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
  16. located at http://jvcl.sourceforge.net
  17. Known Issues:
  18. -----------------------------------------------------------------------------}
  19. {$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
  20. {$I JEDI.INC}
  21. unit JvIpBox;
  22. {*******************************************************}
  23. {  Modifications:                                       }
  24. {    1/11/2000  Corrected an exception on design time   }
  25. {*******************************************************}
  26. {$OBJEXPORTALL On}
  27. interface
  28. uses
  29.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Mask, Dialogs, JvTypes, JVCLVer;
  30. type
  31.   TJvIpBox = class(TCustomMaskEdit)
  32.   private
  33.     FOnMouseEnter: TNotifyEvent;
  34.     FOnMouseLeave: TNotifyEvent;
  35.     FOnParentColorChanged: TNotifyEvent;
  36.     FOnCtl3DChanged: TNotiFyEvent;
  37.     FSaved: TColor;
  38.     FColor: TColor;
  39.     FOver: Boolean;
  40.     FEffect: Boolean;
  41.     FAboutJVCL: TJVCLAboutInfo;
  42.     procedure MouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
  43.     procedure MouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
  44.     procedure CMCtl3DChanged(var Msg: TMessage); message CM_CTL3DCHANGED;
  45.     procedure CMParentColorChanged(var Msg: TMessage); message CM_PARENTCOLORCHANGED;
  46.     procedure SetCtl3d(Value: Boolean);
  47.   protected
  48.     procedure KeyPress(var Key: Char); override;
  49.   public
  50.     constructor Create(AOwner: TComponent); override;
  51.     procedure ValidateEdit; override;
  52.     function SaveToInt: Cardinal;
  53.     procedure LoadFromInt(Value: Cardinal);
  54.   published
  55.     property AboutJVCL: TJVCLAboutInfo read FAboutJVCL write FAboutJVCL stored False;
  56.     property Anchors;
  57.     property AutoSelect;
  58.     property AutoSize;
  59.     property BiDiMode;
  60.     property Borderstyle;
  61.     property CharCase;
  62.     property Color;
  63.     property Constraints;
  64.     property Ctl3D;
  65.     property Cursor;
  66.     property DragCursor;
  67.     property DragKind;
  68.     property Enabled;
  69.     property Font;
  70.     property Height;
  71.     property HelpContext;
  72.     property Hint;
  73.     property ImeMode;
  74.     property ImeName;
  75.     property Left;
  76.     property MaxLength;
  77.     property Name;
  78.     property ParentBiDiMode;
  79.     property ParentCtl3d;
  80.     property ParentFont;
  81.     property PopupMenu;
  82.     property ReadOnly;
  83.     property ShowHint;
  84.     property TabOrder;
  85.     property TabStop;
  86.     property Tag;
  87.     property Text;
  88.     property Top;
  89.     property Visible;
  90.     property Width;
  91.     property OnChange;
  92.     property OnClick;
  93.     property OnDblClick;
  94.     property OnDragDrop;
  95.     property OnDragOver;
  96.     property OnEndDock;
  97.     property OnEndDrag;
  98.     property OnEnter;
  99.     property OnExit;
  100.     property OnKeyDown;
  101.     property OnKeyPress;
  102.     property OnKeyUp;
  103.     property OnMouseDown;
  104.     property OnMouseMove;
  105.     property OnMouseUp;
  106.     property OnStartDock;
  107.     property OnStartDrag;
  108.     property HintColor: TColor read FColor write FColor default clInfoBk;
  109.     property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
  110.     property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  111.     property OnCtl3DChanged: TNotifyEvent read FOnCtl3DChanged write FOnCtl3DChanged;
  112.     property OnParentColorChange: TNotifyEvent read FOnParentColorChanged write FOnParentColorChanged;
  113.     property HotTrack: Boolean read FEffect write SetCtl3d default False;
  114.   end;
  115. implementation
  116. type
  117.   TIpBytes = record
  118.     case Byte of
  119.       0:
  120.       (IpAsInt: Cardinal);
  121.       1:
  122.       (Part1: Byte;
  123.         Part2: Byte;
  124.         Part3: Byte;
  125.         Part4: Byte);
  126.   end;
  127.   {***********************************************}
  128. constructor TJvIpBox.Create(AOwner: TComponent);
  129. begin
  130.   inherited;
  131.   FEffect := False;
  132.   FColor := clInfoBk;
  133.   FOver := False;
  134.   EditMask := '!990.990.990.990;1;0';
  135. end;
  136. {***********************************************}
  137. procedure TJvIpBox.CMCtl3DChanged(var Msg: TMessage);
  138. begin
  139.   inherited;
  140.   if Assigned(FOnCtl3DChanged) then
  141.     FOnCtl3DChanged(Self);
  142. end;
  143. {**************************************************}
  144. procedure TJvIpBox.CMParentColorChanged(var Msg: TMessage);
  145. begin
  146.   inherited;
  147.   if Assigned(FOnParentColorChanged) then
  148.     FOnParentColorChanged(Self);
  149. end;
  150. {**************************************************}
  151. procedure TJvIpBox.MouseEnter(var Msg: TMessage);
  152. begin
  153.   FOver := True;
  154.   FSaved := Application.HintColor;
  155.   Application.HintColor := FColor;
  156.   if FEffect then
  157.     Ctl3d := True;
  158.   if Assigned(FOnMouseEnter) then
  159.     FOnMouseEnter(Self);
  160. end;
  161. {**************************************************}
  162. procedure TJvIpBox.MouseLeave(var Msg: TMessage);
  163. begin
  164.   Application.HintColor := FSaved;
  165.   FOver := False;
  166.   if FEffect then
  167.     Ctl3d := False;
  168.   if Assigned(FOnMouseLeave) then
  169.     FOnMouseLeave(Self);
  170. end;
  171. {**************************************************}
  172. procedure TJvIpBox.SetCtl3d(Value: Boolean);
  173. begin
  174.   FEffect := Value;
  175.   if Value then
  176.     Ctl3d := False;
  177. end;
  178. {**************************************************}
  179. procedure TJvIpBox.KeyPress(var Key: Char);
  180. begin
  181.   case SelStart of
  182.     0, 4, 8, 12:
  183.       if Key in ['3'..'9'] then
  184.       begin
  185.         Key := #0;
  186.         Beep;
  187.       end
  188.       else
  189.         inherited;
  190.     1, 5, 9, 13:
  191.       if (Text[SelStart] = '2') and (Key in ['6'..'9']) then
  192.       begin
  193.         Key := #0;
  194.         Beep;
  195.       end
  196.       else
  197.         inherited;
  198.     2, 6, 10, 14:
  199.       if (Text[SelStart - 1] = '2') and (Text[SelStart] = '5') and (Key in ['6'..'9']) then
  200.       begin
  201.         Key := #0;
  202.         Beep;
  203.       end
  204.       else
  205.         inherited;
  206.   else
  207.     inherited;
  208.   end;
  209. end;
  210. {**************************************************}
  211. procedure TJvIpBox.ValidateEdit;
  212. begin
  213.   //To avoid some problems !
  214.   //Do not inherit this one !
  215. end;
  216. {**************************************************}
  217. procedure TJvIpBox.LoadFromInt(Value: Cardinal);
  218. var
  219.   IpBytes: TIpBytes;
  220. begin
  221.   IpBytes.IpAsInt := Value;
  222.   Text := Format('%3d.%3d.%3d.%3d', [IpBytes.Part4, IpBytes.Part3, IpBytes.Part2,
  223.     IpBytes.Part1]);
  224. end;
  225. {**************************************************}
  226. function TJvIpBox.SaveToInt: Cardinal;
  227. var
  228.   IpBytes: TIpBytes;
  229. begin
  230.   IpBytes.Part4 := StrToInt(Copy(EditText, 1, 3));
  231.   IpBytes.Part3 := StrToInt(Copy(EditText, 5, 3));
  232.   IpBytes.Part2 := StrToInt(Copy(EditText, 9, 3));
  233.   IpBytes.Part1 := StrToInt(Copy(EditText, 13, 3));
  234.   Result := IpBytes.IpAsInt;
  235. end;
  236. end.