📄 tntdbctrls2.pas
字号:
{*****************************************************************************}
{ }
{ Tnt Delphi Unicode Controls }
{ http://www.tntware.com/delphicontrols/unicode/ }
{ Version: 2.1.19 }
{ }
{ Copyleft (c) 2006, adapted from Troy Wolbrink Tnt delphi controls }
{ by Jordi March (jmarch@comg.es) }
{ }
{*****************************************************************************}
{ TTntDBEdit2 adds a OnKeyPressW: TTntKeyPressEvent, where
TTntKeyPressEvent = procedure(Sender: TObject; var Key: WideChar) of object;
08/22/2006 version:
moved TntDBComboBox_WMPaint from TntLookupComboBoxEx}
unit TntDBCtrls2;
interface
{ $I jvcl.inc}
{$I HintEditor.inc}
uses
Classes, Controls, StdCtrls, TntDBCtrls, Messages, Types, Windows, SysUtils,
TntVer, TntClasses2, TntControls2;
procedure TntDBComboBox_WMPaint(DC: HDC; PaintControl: TTntPaintControl;
Style: TComboBoxStyle; const S: WideString; InList: Boolean = False);
type
TTntDBTextA = class(TTntDBText)
private
FAbout: TAboutInfo;
published
property About: TAboutInfo read FAbout write FAbout stored False;
end;
TTntDBEditA = class(TTntDBEdit)
private
FAbout: TAboutInfo;
published
property About: TAboutInfo read FAbout write FAbout stored False;
end;
TTntDBEdit2 = class(TTntDBEditA)
private
FAlignment: TAlignment;
FOnKeyPressW: TTntKeyPressEvent;
{$IFDEF WithHintEditor}
FHintEditor: TUnicodeLinesEditor;
{$ENDIF}
procedure WMChar(var Message: TWMChar); message WM_CHAR;
procedure SetAlignment(Value: TAlignment);
{$IFDEF WithHintEditor}
function GetHintEditor: TUnicodeLinesEditor;
procedure SetHintEditor(const Value: TUnicodeLinesEditor);
{$ENDIF}
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure KeyPressW(var Key: WideChar); dynamic;
function DoKeyPressW(var Message: TWMKey): Boolean;
property OnKeyPressW: TTntKeyPressEvent read FOnKeyPressW write FOnKeyPressW;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
published
{$IFDEF WithHintEditor}
property HintEditor: TUnicodeLinesEditor read GetHintEditor write SetHintEditor stored False;
{$ENDIF}
end;
implementation
uses
TntSysUtils;
{--------------------------------------}
procedure TntDBComboBox_WMPaint(DC: HDC; PaintControl: TTntPaintControl;
Style: TComboBoxStyle; const S: WideString; InList: Boolean);
var
R: TRect;
P: TPoint;
Child: HWND;
begin
if Style = csDropDown then
begin
if Win32PlatformIsUnicode then
SendMessageW(PaintControl.Handle, WM_SETTEXT, 0, Longint(PWideChar(S)))
else
SendMessage(PaintControl.Handle, WM_SETTEXT, 0, Longint(PChar(AnsiString(S))));
SendMessage(PaintControl.Handle, WM_PAINT, DC, 0);
Child := GetWindow(PaintControl.Handle, GW_CHILD);
if Child <> 0 then
begin
Windows.GetClientRect(Child, R);
Windows.MapWindowPoints(Child, PaintControl.Handle, R.TopLeft, 2);
GetWindowOrgEx(DC, P);
SetWindowOrgEx(DC, P.X - R.Left, P.Y - R.Top, nil);
IntersectClipRect(DC, 0, 0, R.Right - R.Left, R.Bottom - R.Top);
SendMessage(Child, WM_PAINT, DC, 0);
end;
end else
begin
SendMessage(PaintControl.Handle, CB_RESETCONTENT, 0, 0);
if InList then
begin
if Win32PlatformIsUnicode then
SendMessageW(PaintControl.Handle, CB_ADDSTRING, 0, Longint(PWideChar(S)))
else
SendMessage(PaintControl.Handle, CB_ADDSTRING, 0, Longint(PChar(AnsiString(S))));
SendMessage(PaintControl.Handle, CB_SETCURSEL, 0, 0);
end;
SendMessage(PaintControl.Handle, WM_PAINT, DC, 0);
end;
end;
{--------------------------------------}
{-PRIVATE----------}
procedure TTntDBEdit2.WMChar(var Message: TWMChar);
begin
if not (Assigned(FOnKeyPressW)) and not (Assigned(OnKeyPress)) then begin
if not DoKeyPress(Message) then inherited;
end
else if
(Assigned(FOnKeyPressW) and (not DoKeyPressW(Message))) or
(Assigned(OnKeyPress) and (not DoKeyPress(Message))) then inherited;
end;
procedure TTntDBEdit2.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
{$IFDEF VCL}
RecreateWnd;
{$ENDIF VCL}
{$IFDEF VisualCLX}
inherited Alignment := FAlignment;
Invalidate;
{$ENDIF VisualCLX}
end;
end;
{$IFDEF WithHintEditor}
function TTntDBEdit2.GetHintEditor: TUnicodeLinesEditor;
begin
Result := FHintEditor;
FHintEditor.SetText (Hint);
end;
procedure TTntDBEdit2.SetHintEditor(
const Value: TUnicodeLinesEditor);
begin
FHintEditor.Assign (Value);
Hint := FHintEditor.GetText;
end;
{$ENDIF}
{-PROTECTED--------}
procedure TTntDBEdit2.CreateParams(var Params: TCreateParams);
const
{$IFDEF JVCLThemesEnabled}
Passwords: array [Boolean] of DWORD = (0, ES_PASSWORD);
{$ENDIF JVCLThemesEnabled}
Styles: array [TAlignment] of DWORD = (ES_LEFT, ES_RIGHT, ES_CENTER);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or Styles[FAlignment];
{$IFDEF JVCLThemesEnabled}
Params.Style := Params.Style or Passwords[ThemedPassword];
{$ENDIF JVCLThemesEnabled}
if (FAlignment <> taLeftJustify) and (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
(Win32MajorVersion = 4) and (Win32MinorVersion = 0) then
Params.Style := Params.Style or ES_MULTILINE; // needed for Win95
end;
function TTntDBEdit2.DoKeyPressW(var Message: TWMKey): Boolean;
var
Ch: WideChar;
W: Word;
begin
Result := True;
if not (csNoStdEvents in ControlStyle) then
with Message do
begin
if Unused = 0
then Ch := WideChar (CharCode)
else Ch := WideChar (Unused);
KeyPressW(Ch);
W := Word(Ch);
if W > 255 then begin
CharCode := 255;
Unused := W;
end
else begin
CharCode := W;
Unused := 0;
end;
if Char(CharCode) = #0 then Exit;
end;
Result := False;
end;
procedure TTntDBEdit2.KeyPressW(var Key: WideChar);
begin
if Assigned(FOnKeyPressW) then FOnKeyPressW(Self, Key);
end;
{-PUBLIC-----------}
constructor TTntDBEdit2.Create(AOwner: TComponent);
begin
inherited;
FAlignment := taLeftJustify;
{$IFDEF WithHintEditor}
if csDesigning in ComponentState then begin
FHintEditor := TUnicodeLinesEditor.Create;
end;
{$ENDIF}
end;
destructor TTntDBEdit2.Destroy;
begin
{$IFDEF WithHintEditor}
if csDesigning in ComponentState then begin
FreeAndNil(FHintEditor);
end;
{$ENDIF}
inherited;
end;
{--------------------------------------}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -