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

📄 bmplbox.pas

📁 一个能够置放 BMP 图档的加强版 TListBox 及 TComboBox 构件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Bmplbox;

{
  TBmpListBox & TBmpComboBox components
  *************************************

  Freeware by MainSoft sarl.
  Uploaded by Patrick Philippot, CIS: 72561,3532

  This unit contains two components implementing an owner-draw Listbox and
  an owner-draw combobox that are able to display a bitmap (glyph) along
  with the item string. They work exactly the same way, so we'll explain
  TBmpListBox only. As you'll see, the code for both component is
  identical, so there's room for optimization by sharing a few routines.
  We didn't make this choice because sharing routines implied passing
  a great number of parameters which would have made the code unclear.
  So, we have merely duplicated the code.

  This is a "let's see what we can do with Delphi" package. We may have
  missed some possibilities of optimizing the code. Feel free to enhance
  it and to re-upload. Although the code is rather simple and significantly
  shorter than its BP7 and VC++ counterparts, it took more time to develop,
  due to the lack of a good documentation. In our opinion, Delphi deserves
  a better documentation.

  This code is based on information found in TI2793.ASC (a technical note
  from Borland). However, it takes a more sophisticated approach.

  The two components have the xxOwnerDrawVariable style which was actually
  not necessary but for an unknown reason, the MeasureItem method is not
  called when we use the xxOwnerDrawFixed style (in that case, the
  WM_MEASUREITEM message is sent only once but it is sent). Since we do
  not have received the VCL source code yet, we can't tell you whether it's
  a bug in the library.

  *********************

  TBmpListBox derives from TListBox and adds the capability of displaying
  a bitmap on the left of the item string. Each item in the listbox can have
  a different bitmap (glyph). Both the bitmap and the text string are
  automatically centered vertically. So they can be of any height (within a
  reasonable range).

  In order to limit system resource consumption, TBmpListBox assumes that
  all glyphs are contained within a single bitmap strip and that they all have
  the same width. This way, each glyph can be indexed. The bitmap strip is a
  property of TBmpListBox and is initially empty.

  The index of the glyph associated with a particular listbox item is stored
  in the HiWord of Items.Object[item_index]. The LoWord can be used by the
  application. The best way to make this association is to use the AddObject
  method and to do some typecasting. See sample program.

  This approach has a drawback regarding the general philosophy of developing
  Delphi Components. Since there's no way for TBmpListBox to determine the
  width of a single glyph in the bitmap strip, no bitmap will be displayed
  until the user defines a positive value for the BmpItemWidth property.
  Also, there is no "default bitmap".

  If no TBitmap has been assigned to BitmapStrip or if BmpItemWidth is null or
  if the assigned bitmap is empty, TBmpListBox will behave as a standard
  listbox.

  New properties:
  _______________

  All these properties can be changed dynamically at run time (although
  this will happen very rarely).


  BitmapStrip	     A TBitmap that must be supplied by the application.
		     BitmapStrip defaults to nil (none).

		     Once you have assigned a TBitmap to BitmapStrip, you
		     can Destroy the source bitmap. SetBitmapStrip uses the
		     Assign method to copy the bitmap data.

  BmpItemWidth	     The width, in pixels, of one single glyph in the bitmap
		     strip. Both BitmapStrip and BmpItemWidth must be valid
		     in order to display an associated bitmap with each item.
		     BmpItemWidth defaults to 0.

  Leftmargin	     The space in pixels left between the left side of the
		     listbox and the left side of the glyph AND between the
		     right side of the glyph and the beginning of the text
		     string. This value is ignored if BmpItemWidth and/or
		     BitmapStrip are not valid. Leftmargin defaults to 4.

  TopAndBottomMargin The additional space in pixels left at the bottom AND
		     at the top of the item rectangle. TopAndBottomMargin
		     defaults to 3.

  TransparentColor   This TColor defines which color in the glyph will be
		     made transparent when displaying the glyph on the
		     item's rectangle background. TransparentColor defaults
		     to clGray.

  *********************

  You are granted the right to use and peruse this code in your applications
  without notifying MainSoft. However, this code can't be published without
  written permission of MainSoft.

  Have fun!


  A few words about MainSoft:
  ***************************

  MainSoft sarl is a french company created by Patrick Philippot, a
  former IBM engineer. MainSoft specializes in training (VB, VC++,
  OLE2, ODBC, ...), consulting and development for Windows and Windows
  NT. We also have a good experience in software localization. Our
  flagship product is a shareware programming editor: E! for Windows.

  E! is the most powerful shareware editor available. Syntax Highlighting
  for any language (user configurable), function tagging and many other
  original features make this product unique. It is as powerful as (or even
  more powerful than) many shrink-wrapped text editors but at a fraction of
  the price.

 *************************************************************************
  As it supports the Borland Pascal compiler, E! also fully supports the
  Delphi command line compiler. You can transparently compile and jump to
  the syntax errors in the source file without even seeing DCC.EXE running.
 *************************************************************************

  You can download E! from many Compuserve libraries (PCAPP, WINSHARE,
  WINSDK, WUGNET,...). Look for EWARC2.EXE. Available patches are
  always uploaded as EWPxxx.ZIP.

  Feel free to drop a message to Patrick Philippot [72561,3532] if you
  need any information.

     MainSoft sarl
     15, avenue des Pres Pierre
     91210 Draveil
     France
     tel/fax: +33 1 69 40 94 85
     CIS: 72561,3532
     INTERNET: 72561.3532@compuserve.com

  Currently, the distribution of E! is managed in the USA and Canada by

       HomeBrew Software
       807 Davis Street
       Suite E
       Vacaville, CA 95687
       (707) 451-9653  Voice
       (707) 451-2500  FAX

  and by Juergen Egeling Computer (for other countries with exception
  of France)

       Juergen Egeling Computer
       Werderstr. 41, 76137 Karlsruhe, Germany.
       Tel: +49 (0721) 373832 / Fax: +49 (0721) 373842
       email: fft@jecalpha.ka.sub.org


  Draveil, France, 06-07-95
}

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type

  TBmpListBox = class(TListBox)
  private
    { Private declarations }
    FBitmapStrip	: TBitmap;
    FBmpItemWidth	: integer;
    FLeftMargin 	: integer;
    FTopAndBottomMargin : integer;
    FTransparentColor	: TColor;
    bOkToDraw		: boolean;
    yBmpOffset		: integer;

  protected
    { Protected declarations }
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
    procedure MeasureItem(Index: Integer; var Height: Integer); override;

  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;
    destructor	Destroy; override;
    procedure	SetBitmapStrip(ABitmapStrip : TBitmap);
    procedure	SetBmpItemWidth(NewWidth : integer);
    procedure	SetLeftMargin(NewMargin : integer);
    procedure	SetTopAndBottomMargin(NewMargin : integer);
    procedure	SetTransparentColor(NewColor : TColor);
    procedure	CheckContext;

  published
    { Published declarations }
    property BitmapStrip : TBitmap read FBitmapStrip write SetBitmapStrip;
    property BmpItemWidth : integer read FBmpItemWidth write SetBmpItemWidth default 0;
    property LeftMargin : integer read FLeftMargin write SetLeftMargin default 4;
    property TopAndBottomMargin : integer read FTopAndBottomMargin write SetTopAndBottomMargin default 3;
    property TransparentColor : TColor read FTransparentColor write SetTransparentColor default clGray;
  end;

  TBmpComboBox = class(TComboBox)
  private
    { Private declarations }
    FBitmapStrip	: TBitmap;
    FBmpItemWidth	: integer;
    FLeftMargin 	: integer;
    FTopAndBottomMargin : integer;
    FTransparentColor	: TColor;
    bOkToDraw		: boolean;
    yBmpOffset		: integer;

  protected
    { Protected declarations }
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
    procedure MeasureItem(Index: Integer; var Height: Integer); override;

  public
    { Public declarations }
    constructor Create(AOwner : TComponent); override;
    destructor	Destroy; override;
    procedure	SetBitmapStrip(ABitmapStrip : TBitmap);
    procedure	SetBmpItemWidth(NewWidth : integer);
    procedure	SetLeftMargin(NewMargin : integer);
    procedure	SetTopAndBottomMargin(NewMargin : integer);
    procedure	SetTransparentColor(NewColor : TColor);
    procedure	CheckContext;

  published
    { Published declarations }
    property BitmapStrip : TBitmap read FBitmapStrip write SetBitmapStrip;
    property BmpItemWidth : integer read FBmpItemWidth write SetBmpItemWidth default 0;

⌨️ 快捷键说明

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