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

📄 tntjvchecklistbox.pas

📁 TntExUpdate 是 流行的 TntUnicodeControls控件的扩展包.包括很难找到的 TntJVCL 也在里面. TntSysUtils2.pas/TntSysUtilsEx.pa
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: JvCheckListBox.PAS, released on 2001-02-28.

The Initial Developer of the Original Code is Sébastien Buysse [sbuysse att buypin dott com]
Portions created by Sébastien Buysse are Copyright (C) 2001 Sébastien Buysse.
All Rights Reserved.

This is a merging of the code in the original JvCheckListBox.pas and JvFixedCheckListBox.pas
Merging done 2002-06-05 by Peter Thornqvist [peter3 at sourceforge dot net]

Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
Peter Below <100113 dott 1101 att compuserve dott com>

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvCheckListBox.pas,v 1.24 2005/10/28 07:37:55 obones Exp $

unit TntJvCheckListBox;

{$I jvcl.inc}

interface

uses
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  {$IFDEF CLR}
  System.Runtime.InteropServices,
  {$ENDIF CLR}
  Windows, Messages, SysUtils, TntSysUtils, Classes, TntClasses, Controls, TntGraphics,
  TntJvExCheckLst;

type
  TTntJvCheckListBox = class(TTntJvExCheckListBox)
  {$IFDEF VCL}
  private
    FHotTrack: Boolean;
    FOnSelectCancel: TNotifyEvent;
    FMaxWidth: Integer;
    FScroll: Boolean;
    FOnHScroll: TNotifyEvent;
    FOnVScroll: TNotifyEvent;
    procedure SetHScroll(const Value: Boolean);
    procedure WMHScroll(var Msg: TWMHScroll); message WM_HSCROLL;
    procedure WMVScroll(var Msg: TWMVScroll); message WM_VSCROLL;
    procedure CNDrawItem(var Msg: TWMDrawItem); message CN_DRAWITEM;
    procedure LBNSelCancel(var Msg: TMessage); message LBN_SELCANCEL;
    procedure RefreshH;
    procedure SetHotTrack(const Value: Boolean);
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure WndProc(var Msg: TMessage); override;
    procedure MouseEnter(Control: TControl); override;
    procedure MouseLeave(Control: TControl); override;
  {$ENDIF VCL}
  {$IFDEF COMPILER5}
  private
    FHeaders: TList;
    FHeaderColor: TColor;
    FHeaderBackgroundColor: TColor;
    function GetHeader(Index: Integer): Boolean;
    procedure SetHeader(Index: Integer; const Value: Boolean);
    procedure SetHeaderColor(Value: TColor);
    procedure SetHeaderBackgroundColor(Value: TColor);
  protected
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
  public
    property Header[Index: Integer]: Boolean read GetHeader write SetHeader;
  published
    property HeaderColor: TColor read FHeaderColor write SetHeaderColor default clInfoText;
    property HeaderBackgroundColor: TColor read FHeaderBackgroundColor write SetHeaderBackgroundColor default clInfoBk;
    destructor Destroy; override;
  {$ENDIF COMPILER5}
  public
    constructor Create(AOwner: TComponent); override;
    function SearchExactString(Value: WideString; CaseSensitive: Boolean = True): Integer;
    function SearchPrefix(Value: WideString; CaseSensitive: Boolean = True): Integer;
    function SearchSubString(Value: WideString; CaseSensitive: Boolean = True): Integer;
    function DeleteExactString(Value: WideString; All: Boolean;
      CaseSensitive: Boolean = True): Integer;
    procedure SelectAll; {$IFDEF VCL}{$IFDEF COMPILER6_UP} override; {$ENDIF}{$ENDIF}
    procedure UnselectAll;
    procedure InvertSelection;
    procedure CheckAll;
    procedure UnCheckAll;
    procedure InvertCheck;
    function GetChecked: TTntStringList;
    function GetUnChecked: TTntStringList;
    procedure DeleteSelected; {$IFDEF VCL}{$IFDEF COMPILER6_UP} override; {$ENDIF}{$ENDIF}
    procedure SaveToFile(FileName: TWideFileName);
    procedure LoadFromFile(FileName: TWideFileName);
    procedure LoadFromStream(Stream: TStream);
    procedure SaveToStream(Stream: TStream);
  published
    property MultiSelect;
    property HintColor;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnParentColorChange;
    {$IFDEF VCL}
    property HotTrack: Boolean read FHotTrack write SetHotTrack default False;
    property HorScrollbar: Boolean read FScroll write SetHScroll default True;
    property OnSelectCancel: TNotifyEvent read FOnSelectCancel write FOnSelectCancel;
    property OnVerticalScroll: TNotifyEvent read FOnVScroll write FOnVScroll;
    property OnHorizontalScroll: TNotifyEvent read FOnHScroll write FOnHScroll;
    {$ENDIF VCL}
  end;

{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvCheckListBox.pas,v $';
    Revision: '$Revision: 1.24 $';
    Date: '$Date: 2005/10/28 07:37:55 $';
    LogPath: 'JVCL'run'
  );
{$ENDIF UNITVERSIONING}

implementation

uses
  TntJvItemsSearchs, TntWideStrUtils;

type
  // Used for the load/save methods

  TCheckListRecord = record
    Checked: Boolean;
    StringSize: Integer;
  end;

//=== { TTntJvCheckListBox } ====================================================

constructor TTntJvCheckListBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  {$IFDEF COMPILER5}
  FHeaders := TList.Create;
  FHeaderColor := clInfoText;
  FHeaderBackgroundColor := clInfoBk;
  {$ENDIF COMPILER5}
  {$IFDEF VCL}
  FHotTrack := False;
  FMaxWidth := 0;
  FScroll := True;
  {$ENDIF VCL}
  // ControlStyle := ControlStyle + [csAcceptsControls];
end;

{$IFDEF COMPILER5}
destructor TJvCheckListBox.Destroy;
begin
  FHeaders.Free;
  inherited Destroy;
end;

procedure TJvCheckListBox.SetHeaderColor(Value: TColor);
begin
  if Value <> FHeaderColor then
  begin
    FHeaderColor := Value;
    Invalidate;
  end;
end;

procedure TJvCheckListBox.SetHeaderBackgroundColor(Value: TColor);
begin
  if Value <> FHeaderBackgroundColor then
  begin
    FHeaderBackgroundColor := Value;
    Invalidate;
  end;
end;

procedure TJvCheckListBox.SetHeader(Index: Integer; const Value: Boolean);
var
  Idx: Integer;
begin
  Idx := FHeaders.IndexOf(Pointer(Index));
  if Idx < 0 then
  begin
    if Value then
      FHeaders.Add(Pointer(Index));
  end
  else
    if not Value then
      FHeaders.Delete(Idx);
end;

function TJvCheckListBox.GetHeader(Index: Integer): Boolean;
begin
  Result := FHeaders.IndexOf(Pointer(Index)) >= 0;
end;

procedure TJvCheckListBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  if Header[Index] then
  begin
    Canvas.Font.Color := HeaderColor;
    Canvas.Brush.Color := HeaderBackgroundColor;
  end;
  inherited DrawItem(Index, Rect, State);
end;
{$ENDIF COMPILER5}

procedure TTntJvCheckListBox.CheckAll;
var
  I: Integer;
begin
  for I := 0 to Items.Count - 1 do
    Checked[I] := True;
end;

{$IFDEF VCL}
procedure TTntJvCheckListBox.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
    if FScroll then
      Style := Style or WS_HSCROLL
    else
      Style := Style xor WS_HSCROLL;
end;
{$ENDIF VCL}

function TTntJvCheckListBox.DeleteExactString(Value: WideString; All: Boolean;
  CaseSensitive: Boolean): Integer;
begin
  Result := TTntJvItemsSearchs.DeleteExactString(Items, Value, CaseSensitive);
end;

procedure TTntJvCheckListBox.DeleteSelected;
var
  I: Integer;
begin
  if MultiSelect then
  begin
    for I := Items.Count - 1 downto 0 do
      if Selected[I] then
        Items.Delete(I);
  end
  else
  if ItemIndex <> -1 then
  begin
    I := ItemIndex;
    Items.Delete(I);
    if I > 0 then
      Dec(I);
    if Items.Count > 0 then
      ItemIndex := I;
  end;
end;

function TTntJvCheckListBox.GetChecked: TTntStringList;
var
  I: Integer;
begin
  Result := TTntStringList.Create;
  for I := 0 to Items.Count - 1 do
    if Checked[I] then
      Result.AddObject(Items[I], Items.Objects[I]);
end;

function TTntJvCheckListBox.GetUnChecked: TTntStringList;
var
  I: Integer;
begin
  Result := TTntStringList.Create;
  for I := 0 to Items.Count - 1 do
    if not Checked[I] then
      Result.AddObject(Items[I], Items.Objects[I]);
end;

procedure TTntJvCheckListBox.InvertCheck;
var
  I: Integer;
begin
  for I := 0 to Items.Count - 1 do
    Checked[I] := not Checked[I];
end;

procedure TTntJvCheckListBox.InvertSelection;
var

⌨️ 快捷键说明

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