home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 April / Chip_2002-04_cd1.bin / zkuste / delphi / kolekce / d3456 / PBEDIT.ZIP / PBMaskEdit.pas < prev    next >
Pascal/Delphi Source File  |  2002-01-19  |  4KB  |  168 lines

  1. {Author:    Poul Bak}
  2. {}
  3. {Copyright ⌐ 1999 - 2002 : BakSoft-Denmark (Poul Bak). All rights reserved.}
  4. {}
  5. {http://home11.inet.tele.dk/BakSoft/}
  6. {Mailto: baksoft-denmark@dk2net.dk}
  7. {}
  8. {Component Version: 6.00.00.00}
  9. {}
  10. {PBMaskEdit is a standard Delphi Edit component with Alignment and
  11. mouse-AutoSelect-all.}
  12. {Can replace standard component without any disadvantages.}
  13.  
  14. {Supports Windows 95, 98 and NT.}
  15. {Supports Default-Button click.}
  16. {Supports Cancel-button click.}
  17.  
  18. unit PBMaskEdit;
  19.  
  20. interface
  21.  
  22. uses
  23.     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  24.     StdCtrls, Mask;
  25.  
  26. type
  27. {Author:    Poul Bak}
  28. {}
  29. {Copyright ⌐ 1999 - 2002 : BakSoft-Denmark (Poul Bak). All rights reserved.}
  30. {}
  31. {http://home11.inet.tele.dk/BakSoft/}
  32. {Mailto: baksoft-denmark@dk2net.dk}
  33. {}
  34. {Component Version: 6.00.00.00}
  35. {}
  36. {PBMaskEdit is a standard Delphi Edit component with Alignment and
  37. mouse-AutoSelect-all.}
  38. {Can replace standard component without any disadvantages.}
  39.  
  40. {Supports Windows 95, 98 and NT.}
  41. {Supports Default-Button click.}
  42. {Supports Cancel-button click.}
  43.     TPBMaskEdit = class(TMaskEdit)
  44.     private
  45.         { Private declarations }
  46.         FAlignment : TAlignment;
  47.         FEnter : Boolean;
  48.         FVersion : string;
  49.         procedure SetAlignment(Value: TAlignment);
  50.         procedure SetVersion(Value: String);
  51.         procedure WMGetDlgCode(var Msg : TWMGetDlgCode); message WM_GETDLGCODE;
  52.     protected
  53.         { Protected declarations }
  54.         procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  55.         procedure DoEnter; override;
  56.         procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  57.         procedure KeyPress(var Key: Char); override;
  58.     public
  59.         { Public declarations }
  60.         constructor Create(AOwner: TComponent); override;
  61.         procedure CreateParams(var Params: TCreateParams); override;
  62.     published
  63. {Set Alignment to: taLeftJustify, taCenter or taRightJustify.}
  64. {Default : taLeftJustify.}
  65. {Supports Windows 95, 98 and NT.}
  66.         property Alignment: TAlignment read FAlignment write SetAlignment;
  67. {Default: True.}
  68. {Set AutoSelect to True to select all text when you set focus:}
  69. {Notice that when you set focus using the mouse, all text is also selected -
  70. unlike standard Delphi components that only selects all when setting focus with <tab>.}
  71. {When a form has a defaultbutton and you press <enter>, the click event
  72. triggers and focus is returned to the edit control which autoselect all.}
  73.         property AutoSelect;
  74. {Read only. }
  75.         property Version: String read FVersion write SetVersion stored False;
  76. end;
  77.  
  78. procedure Register;
  79.  
  80. implementation
  81.  
  82. constructor TPBMaskEdit.Create(AOwner: TComponent);
  83. begin
  84.     inherited Create(AOwner);
  85.     Width := 100;
  86.     FAlignment := taLeftJustify;
  87.     FVersion := '6.00.00.00';
  88.     Text := '';
  89.     FEnter := False;
  90. end;
  91.  
  92. procedure TPBMaskEdit.CreateParams(var Params: TCreateParams);
  93. const
  94.     Alignments: array[TAlignment] of Word = (ES_LEFT, ES_RIGHT, ES_CENTER);
  95. begin
  96.     inherited CreateParams(Params);
  97.     Params.Style := Params.Style or ES_MULTILINE or Alignments[FAlignment];
  98. end;
  99.  
  100. procedure TPBMaskEdit.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  101. begin
  102.     if (Button = mbLeft) or (ssLeft in Shift) then
  103.     begin
  104.         if FEnter = True then
  105.         begin
  106.             FEnter := False;
  107.             if AutoSelect then SelectAll;
  108.         end;
  109.     end;
  110.     inherited MouseDown(Button, Shift, X, Y);
  111. end;
  112.  
  113. procedure TPBMaskEdit.DoEnter;
  114. begin
  115.     inherited DoEnter;
  116.     if csLButtonDown in ControlState then FEnter := True;
  117.     if AutoSelect then SelectAll;
  118. end;
  119.  
  120. procedure TPBMaskEdit.KeyDown(var Key: Word; Shift: TShiftState);
  121. begin
  122.     inherited KeyDown(Key, Shift);
  123.     FEnter := False;
  124. end;
  125.  
  126. procedure TPBMaskEdit.KeyPress(var Key: Char);
  127. begin
  128.     if (Key in [#13, #27]) then
  129.     begin
  130.         Key := #0;
  131.         MessageBeep(0);
  132.     end
  133.     else inherited;
  134. end;
  135.  
  136. procedure TPBMaskEdit.SetAlignment(Value: TAlignment);
  137. var
  138.     SelSt, SelLe : integer;
  139. begin
  140.     if FAlignment <> Value then
  141.     begin
  142.         SelSt := SelStart;
  143.         SelLe := SelLength;
  144.         FAlignment := Value;
  145.         RecreateWnd;
  146.         SelStart := SelSt;
  147.         SelLength := SelLe;
  148.     end;
  149. end;
  150.  
  151. procedure TPBMaskEdit.SetVersion(Value: String);
  152. begin
  153.     { Read only! }
  154. end;
  155.  
  156. procedure TPBMaskEdit.WMGetDlgCode(var Msg: TWMGetDlgCode);
  157. begin
  158.     Msg.Result := DLGC_WANTCHARS or DLGC_WANTARROWS;
  159. end;
  160.  
  161. procedure Register;
  162. begin
  163.     RegisterComponents('PB', [TPBMaskEdit]);
  164. end;
  165.  
  166. end.
  167.  
  168.