function TMyListBox.DrawItemHeight( AObject : TInfoObject; ACanvas : TCanvas; ARect : TRect; AState : TItemDrawState; GetHeight : Boolean ) : Integer;
var
BM1, BM2 : Graphics.TBitmap;
Text1, Text2 :
string;
H1, H2 : Integer;
MaxWidth, IcoWidth, IcoHeight : Integer;
function TextHeigh( ACanvas : TCanvas; AText :
string; ARect : TRect; CanDraw : Boolean = False ) : Integer;
const
DrawOrNot :
array[ Boolean ]
of LongWord = ( DT_CALCRECT, 0 );
var
Flags : LongInt;
begin // TextHeigh
ARect.Bottom := 1;
Flags := DrawTextBiDiModeFlags( DT_LEFT
or DT_TOP
or DT_NOPREFIX
or
DT_NOCLIP
or DT_WORDBREAK
or DT_END_ELLIPSIS
or DrawOrNot[ CanDraw ] );
Result := DrawText( ACanvas.Handle, PChar( AText ), Length( AText ),
ARect, Flags );
end;
// TextHeigh
{======================================================================}
begin // TMyListBox.DrawItemHeight
MaxWidth := Abs( ARect.Right - ARect.Left );
IcoWidth := 0;
IcoHeight := 0;
if AObject.Title <> '
'
then
Text1 := AObject.Title
// 1st string line in the List the above ONE
else
Text1 := '
';
Text2 := AObject.Text;
// 2nd String line in the List the bellow One
if ( AObject.Icon <>
nil )
and not AObject.Icon.Empty
then
begin
IcoWidth := AObject.Icon.Width;
IcoHeight := AObject.Icon.Height;
end;
// if ( AObject.Icon <> nil ) and not AObject.Icon.Empty
BM1 := Graphics.TBitmap.Create;
BM1.Width := Abs( MaxWidth - IcoWidth - FSpacer );
BM1.Height := 16;
BM2 := Graphics.TBitmap.Create;
BM2.Width := MaxWidth;
BM2.Height := 16;
with BM1.Canvas
do
begin
Font.Assign( FTitleFont );
if ( AState = idSelected )
or ( AState = idSelFocused )
then
Font.Assign( FTitleSelected );
H1 := TextHeigh( BM1.Canvas, Text1, Rect( 0, 0, BM1.Width - 4, 0 ), True );
end;
// with BM1.Canvas
if Text2 <> '
'
then
with BM2.Canvas
do
begin
Font.Assign( FTextFont );
if ( AState = idSelected )
or ( AState = idSelFocused )
then
Font.Assign( FTextFontSelected );
H2 := TextHeigh( BM2.Canvas, Text2, Rect( 2, 0, BM2.Width - 2, 0 ), True );
end // with BM2.Canvas
else
H2 := 0;
if not GetHeight
then
begin
with ACanvas
do
begin
Lock;
SetBkMode(
Handle, Transparent );
if ( IcoWidth > 0 )
and ( IcoHeight > 0 )
then
begin
if IcoHeight > H1
then
begin
Draw( 2, 2, AObject.Icon );
Font.Assign( FTitleFont );
if ( AState = idSelected )
or ( AState = idSelFocused )
then
Font.Assign( FTitleFontSelected );
TextHeigh( ACanvas, Text1, Rect( 2 + IcoWidth + FSpacer,
2 +( IcoHeight - H1 )
div 2,
IcoWidth + BM1.Width - FSpacer - 6, 0 ), True );
end // if IcoHeight > H1
else
begin
Draw( 2, 2 +( H1 - IcoHeight )
div 2, AObject.Icon );
Font.Assign( FTitleFont );
if ( AState = idSelected )
or ( AState = idSelFocused )
then
Font.Assign( FTitleFontSelected );
TextHeigh( ACanvas, Text1, Rect( 2 + IcoWidth + FSpacer, 2,
IcoWidth + BM1.Width - FSpacer - 6, 0 ), True );
end;
// else of if IcoHeight > H1
end // if ( IcoWidth > 0 ) and ( IcoHeight > 0 )
else
begin
Font.Assign( FTitleFont );
if ( AState = idSelected )
or ( AState = idSelFocused )
then
Font.Assign( FTitleFontSelected );
TextHeigh( ACanvas, Text1, Rect( 2, 2, BM1.Width - 2, 0 ), True );
end;
// else of if ( IcoWidth > 0 ) and ( IcoHeight > 0 )
if ( AObject.Text <> '
' )
and FText
then
begin
Font.Assign( FTextFont );
if ( AState = idSelected )
or ( AState = idSelFocused )
then
Font.Assign( FTextFontSelected );
if IcoHeight > H1
then
TextHeigh( ACanvas, Text2, Rect( 0, 2 + IcoHeight, BM2.Width, 0 ),
True )
else
TextHeigh( ACanvas, Text2, Rect( 0, 2 + H1, BM2.Width, 0 ), True );
end;
// if ( AObject.Text <> '' ) and FText
SetBkMode(
Handle, OPAQUE );
Unlock;
end;
// with ACanvas
end;
// if not GetHeight
if FText
then
begin
if IcoHeight > H1
then
Result := IcoHeight + H2 + 4
else
Result := H1 + H2 + 4;
end // if FText
else
if IcoHeight > H1
then
Result := IcoHeight + 4
else
Result := H1 + 4;
BM1.FreeImage;
BM1.Free;
BM2.FreeImage;
BM2.Free;
end;
// TMyListBox.DrawItemHeight