home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 April / Chip_2002-04_cd1.bin / zkuste / delphi / kolekce / d3456 / PBEDIT.ZIP / PBSpinEdit.pas < prev    next >
Pascal/Delphi Source File  |  2002-01-19  |  5KB  |  185 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. {PBSpinEdit is a standard Delphi Edit component with Alignment and
  11. mouse-AutoSelect-all.}
  12. {Can replace standard components without any disadvantages.}
  13.  
  14. {Supports Windows 95, 98 and NT.}
  15. {Supports Default-Button click. (Standard SpinEdit does not).}
  16. {Supports Cancel-button click.}
  17.  
  18. unit PBSpinEdit;
  19.  
  20. interface
  21.  
  22. uses
  23.     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  24.     StdCtrls, Spin;
  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. {PBSpinEdit is a standard Delphi Edit component with Alignment and
  37. mouse-AutoSelect-all.}
  38. {Can replace standard components without any disadvantages.}
  39.  
  40. {Supports Windows 95, 98 and NT.}
  41. {Supports Default-Button click. (Standard SpinEdit does not).}
  42. {Supports Cancel-button click.}
  43.     TPBSpinEdit = class(TSpinEdit)
  44.     private
  45.         { Private declarations }
  46.         FAlignment : TAlignment;
  47.         FEnter : Boolean;
  48.         FVersion : string;
  49.         function GetCursor : TCursor;
  50.         procedure SetAlignment(Value: TAlignment);
  51.         procedure SetCursor(Value : TCursor);
  52.         procedure SetVersion(Value: String);
  53.         procedure WMGetDlgCode(var Msg : TWMGetDlgCode); message WM_GETDLGCODE;
  54.     protected
  55.         { Protected declarations }
  56.         procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  57.         procedure DoEnter; override;
  58.         procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  59.         procedure KeyPress(var Key: Char); override;
  60.     public
  61.         { Public declarations }
  62.         constructor Create(AOwner: TComponent); override;
  63.         procedure CreateParams(var Params: TCreateParams); override;
  64.     published
  65. {Set Alignment to: taLeftJustify, taCenter or taRightJustify.}
  66. {Default : taLeftJustify.}
  67. {Supports Windows 95, 98 and NT.}
  68.         property Alignment: TAlignment read FAlignment write SetAlignment;
  69. {Default: True.}
  70. {Set AutoSelect to True to select all text when you set focus:}
  71. {Notice that when you set focus using the mouse, all text is also selected -
  72. unlike standard Delphi components that only selects all when setting focus with <tab>.}
  73. {When a form has a defaultbutton and you press <enter>, the click event
  74. triggers and focus is returned to the edit control which autoselect all.}
  75.         property AutoSelect;
  76.         property Cursor : TCursor read GetCursor write SetCursor;
  77. {Read only. }
  78.         property Version: String read FVersion write SetVersion stored False;
  79. end;
  80.  
  81. procedure Register;
  82.  
  83. implementation
  84.  
  85. constructor TPBSpinEdit.Create(AOwner: TComponent);
  86. begin
  87.     inherited Create(AOwner);
  88.     Width := 100;
  89.     FAlignment := taLeftJustify;
  90.     FVersion := '6.00.00.00';
  91.     Text := '';
  92.     FEnter := False;
  93. end;
  94.  
  95. procedure TPBSpinEdit.CreateParams(var Params: TCreateParams);
  96. const
  97.     Alignments: array[TAlignment] of Word = (ES_LEFT, ES_RIGHT, ES_CENTER);
  98. begin
  99.     inherited CreateParams(Params);
  100.     Params.Style := Params.Style or ES_MULTILINE or Alignments[FAlignment];
  101. end;
  102.  
  103. procedure TPBSpinEdit.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  104. begin
  105.     if (Button = mbLeft) or (ssLeft in Shift) then
  106.     begin
  107.         if FEnter = True then
  108.         begin
  109.             FEnter := False;
  110.             if AutoSelect then SelectAll;
  111.         end;
  112.     end;
  113.     inherited MouseDown(Button, Shift, X, Y);
  114. end;
  115.  
  116. procedure TPBSpinEdit.DoEnter;
  117. begin
  118.     inherited DoEnter;
  119.     if csLButtonDown in ControlState then FEnter := True;
  120.     if AutoSelect then SelectAll;
  121. end;
  122.  
  123. procedure TPBSpinEdit.KeyDown(var Key: Word; Shift: TShiftState);
  124. begin
  125.     inherited KeyDown(Key, Shift);
  126.     FEnter := False;
  127. end;
  128.  
  129. procedure TPBSpinEdit.KeyPress(var Key: Char);
  130. begin
  131.     if (Key in [#13, #27]) then
  132.     begin
  133.         Key := #0;
  134.         MessageBeep(0);
  135.     end
  136.     else inherited;
  137. end;
  138.  
  139. procedure TPBSpinEdit.SetAlignment(Value: TAlignment);
  140. var
  141.     SelSt, SelLe : integer;
  142. begin
  143.     if FAlignment <> Value then
  144.     begin
  145.         SelSt := SelStart;
  146.         SelLe := SelLength;
  147.         FAlignment := Value;
  148.         RecreateWnd;
  149.         SelStart := SelSt;
  150.         SelLength := SelLe;
  151.     end;
  152. end;
  153.  
  154. procedure TPBSpinEdit.SetVersion(Value: String);
  155. begin
  156.     { Read only! }
  157. end;
  158.  
  159. function TPBSpinEdit.GetCursor : TCursor;
  160. begin
  161.     Result := inherited Cursor;
  162. end;
  163.  
  164. procedure TPBSpinEdit.SetCursor(Value : TCursor);
  165. begin
  166.     if inherited Cursor <> Value then
  167.     begin
  168.         inherited Cursor := Value;
  169.         Button.Cursor := Value;
  170.     end;
  171. end;
  172.  
  173. procedure TPBSpinEdit.WMGetDlgCode(var Msg: TWMGetDlgCode);
  174. begin
  175.     Msg.Result := DLGC_WANTCHARS or DLGC_WANTARROWS;
  176. end;
  177.  
  178. procedure Register;
  179. begin
  180.     RegisterComponents('PB', [TPBSpinEdit]);
  181. end;
  182.  
  183. end.
  184.  
  185.