⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tntstdctrls2.pas

📁 TntExUpdate 是 流行的 TntUnicodeControls控件的扩展包.包括很难找到的 TntJVCL 也在里面. TntSysUtils2.pas/TntSysUtilsEx.pa
💻 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)                                          }
{                                                                             }
{*****************************************************************************}

{ TTntEdit2 adds a OnKeyPressW: TTntKeyPressEvent, where
  TTntKeyPressEvent = procedure(Sender: TObject; var Key: WideChar) of object; }
{ with TTntLabel2 you can easily add several lines in design time }

{ 03/10/2006:
  bug: $I jvcl.inc, disabled!
  TTntCustomEdit2.SetAlignment is Changed
  is deleted:
    if FAlignment <> Value then
    begin
  sometimes Alignment is changed by keyboard, not for program,
  then is better re Alignment

  10/28/2006
  bug: TTntCustomEdit2.WMChar solved
}

unit TntStdCtrls2;

interface

{$I jvcl.inc}
{$I TntCompilers.inc}
{$I HintEditor.inc}

uses
  Messages, Controls, Classes, TntClasses,
  TntVer, StdCtrls, TntStdCtrls, TntControls2, TntClasses2;

type
  TTntCustomComboBoxStrings = class(TTntStrings)
  private
    FComboBox: TCustomComboBox{TNT-ALLOW TCustomComboBox};
  protected
    function GetCount: Integer; override;
    function Get(Index: Integer): WideString; override;
    function GetObject(Index: Integer): TObject; override;
    procedure PutObject(Index: Integer; AObject: TObject); override;
    procedure SetUpdateState(Updating: Boolean); override;
    property ComboBox: TCustomComboBox read FComboBox write FComboBox;
  public
    procedure Clear; override;
    procedure Delete(Index: Integer); override;
    function IndexOf(const S: WideString): Integer; override;
  end;

  TTntCustomComboBoxStringsClass = class of TTntCustomComboBoxStrings;

  TTntCustomEditA = class(TTntCustomEdit)
  private
    FAbout: TAboutInfo;
  published
    property About: TAboutInfo read FAbout write FAbout stored False;
  end;

  TTntCustomEdit2 = class(TTntCustomEditA)
  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;
    property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
   {$IFDEF WithHintEditor}
    property HintEditor: TUnicodeLinesEditor read GetHintEditor write SetHintEditor stored False;
   {$ENDIF}
  end;

  TTntEdit2 = class(TTntCustomEdit2)
  published
    property Alignment;
    property Anchors;
    property AutoSelect;
    property AutoSize;
    property BevelEdges;
    property BevelInner;
    property BevelKind default bkNone;
    property BevelOuter;
    property BiDiMode;
    property BorderStyle;
    property CharCase;
    property Color;
    property Constraints;
    property Ctl3D;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property HideSelection;
    property ImeMode;
    property ImeName;
    property MaxLength;
    property OEMConvert;
    property ParentBiDiMode;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PasswordChar;
    property PopupMenu;
    property ReadOnly;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Text;
    property Visible;
    property OnChange;
    property OnClick;
    property OnContextPopup;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyPressW;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

  TTntCustomLabel2 = class(TTntCustomLabel)
  private
    FAbout: TAboutInfo;
    FCaptionEditor: TUnicodeLinesEditor;
   {$IFDEF WithHintEditor}
    FHintEditor: TUnicodeLinesEditor;
   {$ENDIF}
    function GetCaptionEditor: TUnicodeLinesEditor;
    procedure SetCaptionEditor(const Value: TUnicodeLinesEditor);
   {$IFDEF WithHintEditor}
    function GetHintEditor: TUnicodeLinesEditor;
    procedure SetHintEditor(const Value: TUnicodeLinesEditor);
   {$ENDIF}
  protected
    property CaptionEditor: TUnicodeLinesEditor read GetCaptionEditor write SetCaptionEditor stored False;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property About: TAboutInfo read FAbout write FAbout stored False;
   {$IFDEF WithHintEditor}
    property HintEditor: TUnicodeLinesEditor read GetHintEditor write SetHintEditor stored False;
   {$ENDIF}
  end;

  TTntLabel2 = class(TTntCustomLabel2)
  published
    property Align;
    property Alignment;
    property Anchors;
    property AutoSize;
    property BiDiMode;
    property Caption;
    property CaptionEditor;
    property Color {$IFDEF COMPILER_7_UP} nodefault {$ENDIF};
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property FocusControl;
    property Font;
    property ParentBiDiMode;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowAccelChar;
    property ShowHint;
    property Transparent;
    property Layout;
    property Visible;
    property WordWrap;
    property OnClick;
    property OnContextPopup;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnStartDock;
    property OnStartDrag;
  end;

  TTntComboBoxA = class (TTntComboBox)
  private
    FAbout: TAboutInfo;
  published
    property About: TAboutInfo read FAbout write FAbout stored False;
  end;

implementation

uses
  JvEdit,
  {$IFDEF JVCLThemesEnabled}
  {$IFDEF COMPILER7_UP}
  Themes,
  {$ELSE}
  ThemeSrv,
  {$ENDIF COMPILER7_UP}
  {$ENDIF JVCLThemesEnabled}
  SysUtils, Windows, TntControls;

{--------------------------------------}

type TAccessStrings = class(TStrings{TNT-ALLOW TStrings});

{--------------------------------------}

function TTntCustomComboBoxStrings.GetCount: Integer;
begin
  Result := ComboBox.Items.Count;
end;

function TTntCustomComboBoxStrings.Get(Index: Integer): WideString;
var
  Len: Integer;
begin
  if (not IsWindowUnicode(ComboBox.Handle)) then
    Result := ComboBox.Items[Index]
  else begin
    Len := SendMessageW(ComboBox.Handle, CB_GETLBTEXTLEN, Index, 0);
    if Len = CB_ERR then
      Result := ''
    else begin
      SetLength(Result, Len + 1);
      Len := SendMessageW(ComboBox.Handle, CB_GETLBTEXT, Index, Longint(PWideChar(Result)));
      if Len = CB_ERR then
        Result := ''
       else
        Result := PWideChar(Result);
    end;
  end;
end;

function TTntCustomComboBoxStrings.GetObject(Index: Integer): TObject;
begin
  Result := ComboBox.Items.Objects[Index];
end;

procedure TTntCustomComboBoxStrings.PutObject(Index: Integer; AObject: TObject);
begin
  ComboBox.Items.Objects[Index] := AObject;
end;

procedure TTntCustomComboBoxStrings.Delete(Index: Integer);
begin
  ComboBox.Items.Delete(Index);
end;

procedure TTntCustomComboBoxStrings.Clear;
var
  S: WideString;
begin
  S := TntControl_GetText(ComboBox);
  SendMessage(ComboBox.Handle, CB_RESETCONTENT, 0, 0);
  TntControl_SetText(ComboBox, S);
  ComboBox.Update;
end;

procedure TTntCustomComboBoxStrings.SetUpdateState(Updating: Boolean);
begin
  TAccessStrings(ComboBox.Items).SetUpdateState(Updating);
end;

function TTntCustomComboBoxStrings.IndexOf(const S: WideString): Integer;
begin
  if (not IsWindowUnicode(ComboBox.Handle)) then
    Result := ComboBox.Items.IndexOf(S)
  else
    Result := SendMessageW(ComboBox.Handle, CB_FINDSTRINGEXACT, -1, LongInt(PWideChar(S)));
end;

{--------------------------------------}
{-PRIVATE----------}

procedure TTntCustomEdit2.WMChar(var Message: TWMChar);
begin
  if  not (Assigned(FOnKeyPressW)) and not (Assigned(OnKeyPress))  then  begin
    if  not DoKeyPressW(Message)  then  inherited;
  end
  else if
    (Assigned(FOnKeyPressW) and (not DoKeyPressW(Message))) or
     (Assigned(OnKeyPress) and (not DoKeyPress(Message))) then inherited;
end;

procedure TTntCustomEdit2.SetAlignment(Value: TAlignment);
begin
  {
  if FAlignment <> Value then
  begin
  sometimes Alignment is changed by keyboard, not for program,
  then is better re Alignment
  }
    FAlignment := Value;
    {$IFDEF VCL}
    RecreateWnd;
    {$ENDIF VCL}
    {$IFDEF VisualCLX}
    inherited Alignment := FAlignment;
    Invalidate;
    {$ENDIF VisualCLX}
  //end;
end;

{$IFDEF WithHintEditor}
function TTntCustomEdit2.GetHintEditor: TUnicodeLinesEditor;
begin
  Result := FHintEditor;
  FHintEditor.SetText (Hint);
end;

procedure TTntCustomEdit2.SetHintEditor(
  const Value: TUnicodeLinesEditor);
begin
  FHintEditor.Assign (Value);
  Hint := FHintEditor.GetText;
end;
{$ENDIF}

{-PROTECTED--------}

procedure TTntCustomEdit2.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;

procedure TTntCustomEdit2.KeyPressW(var Key: WideChar);
begin
  if Assigned(FOnKeyPressW) then FOnKeyPressW(Self, Key);
end;

function TTntCustomEdit2.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;

{-PUBLIC-----------}

constructor TTntCustomEdit2.Create(AOwner: TComponent);
begin
  inherited;
  FAlignment := taLeftJustify;
 {$IFDEF WithHintEditor}
  if  csDesigning in ComponentState  then  begin
    FHintEditor := TUnicodeLinesEditor.Create;
  end;
 {$ENDIF}
end;

destructor TTntCustomEdit2.Destroy;
begin
 {$IFDEF WithHintEditor}
  if  csDesigning in ComponentState  then  begin
    FreeAndNil(FHintEditor);
  end;
 {$ENDIF}
  inherited;
end;

{--------------------------------------}
{-PRIVATE----------}

function TTntCustomLabel2.GetCaptionEditor: TUnicodeLinesEditor;
begin
  Result := FCaptionEditor;
  FCaptionEditor.SetText (Caption);
end;

procedure TTntCustomLabel2.SetCaptionEditor(
  const Value: TUnicodeLinesEditor);
begin
  FCaptionEditor.Assign (Value);
  Caption := FCaptionEditor.GetText;
end;

{$IFDEF WithHintEditor}
function TTntCustomLabel2.GetHintEditor: TUnicodeLinesEditor;
begin
  Result := FHintEditor;
  FHintEditor.SetText (Hint);
end;

procedure TTntCustomLabel2.SetHintEditor(
  const Value: TUnicodeLinesEditor);
begin
  FHintEditor.Assign (Value);
  Hint := FHintEditor.GetText;
end;
{$ENDIF}

{-PUBLIC-----------}

constructor TTntCustomLabel2.Create(AOwner: TComponent);
begin
  inherited;
  if  csDesigning in ComponentState  then  begin
    FCaptionEditor := TUnicodeLinesEditor.Create;
   {$IFDEF WithHintEditor}
    FHintEditor := TUnicodeLinesEditor.Create;
   {$ENDIF}
  end;
end;

destructor TTntCustomLabel2.Destroy;
begin
  if  csDesigning in ComponentState  then  begin
    FreeAndNil(FCaptionEditor);
   {$IFDEF WithHintEditor}
    FreeAndNil(FHintEditor);
   {$ENDIF}
  end;
  inherited;
end;

{--------------------------------------}

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -