📄 jvlistcomb.pas
字号:
Tmp := ((R.Right - R.Left) - GetImageWidth(Index)) div 2;
Draw(R.Left + Tmp, R.Top + 2, Items[Index].Glyph);
if FButtonFrame then
begin
TmpR := Rect(R.Left + Tmp - 2, R.Top + 2, R.Left + Tmp + FImageList.Width + 2, R.Top + FImageList.Height + 2);
DrawBtnFrame(Canvas, FButtonStyle, Color, not (odSelected in State), TmpR);
end;
InflateRect(R, 1, -4);
end
else
if Assigned(FImageList) then
begin
Tmp := ((R.Right - R.Left) - GetImageWidth(Index)) div 2;
Tmp2 := Items[Index].ImageIndex;
{$IFDEF VCL}
// PRY 2002.06.04
//FImageList.Draw(FCanvas, R.Left + Tmp, R.Top + 2, Tmp2, dsTransparent, itImage);
{$IFDEF COMPILER6_UP}
FImageList.Draw(Canvas, R.Left + Tmp, R.Top + 2, Tmp2, dsTransparent, itImage);
{$ELSE}
FImageList.Draw(Canvas, R.Left + Tmp, R.Top + 2, Tmp2);
{$ENDIF COMPILER6_UP}
// PRY END
{$ENDIF VCL}
{$IFDEF VisualCLX}
FImageList.Draw(Canvas, R.Left + Tmp, R.Top + 2, Tmp2);
{$ENDIF VisualCLX}
if FButtonFrame then
begin
TmpR := Rect(R.Left + Tmp - 2, R.Top + 2, R.Left + Tmp + FImageList.Width + 2, R.Top + FImageList.Height + 2);
DrawBtnFrame(Canvas, FButtonStyle, Color, not ((Tmp2 in [0..FImageList.Count - 1]) and (odSelected in State)), TmpR);
end;
InflateRect(R, 1, -4);
end;
R.Left := ((R.Right - R.Left) - TextWidth(Items[Index].Text)) div 2 - 1;
R.Right := R.Left + TextWidth(Items[Index].Text) + 1;
R.Top := R.Bottom - TextHeight(Items[Index].Text) - 1;
if Length(Items[Index].Text) > 0 then
begin
FillRect(R);
DrawText(Canvas, Items[Index].Text, Length(Items[Index].Text), R,
DT_SINGLELINE or DT_NOPREFIX or DT_CENTER or DT_BOTTOM);
if (odSelected in State) and (Color <> FColorHighlight) then
DrawFocusRect(R);
end
else
begin
FillRect(OrigR);
if (odSelected in State) and (Color <> FColorHighlight) then
DrawFocusRect(OrigR);
end;
end;
end;
procedure TJvImageListBox.DrawLeftGlyph(Index: Integer; R: TRect; State: TOwnerDrawState);
var
Offset, Tmp: Integer;
TmpCol: TColor;
TmpR, OrigR: TRect;
begin
if csDestroying in ComponentState then
Exit;
OrigR := R;
with Canvas do
begin
TmpCol := Brush.Color;
Brush.Color := Color;
FillRect(R);
Brush.Color := TmpCol;
if not Items[Index].Glyph.Empty then
begin
Offset := ((R.Bottom - R.Top) - GetImageHeight(Index)) div 2;
Draw(R.Left + 2, R.Top + Offset, Items[Index].Glyph);
if FButtonFrame then
begin
TmpR := Rect(R.Left, R.Top, R.Left + FImageList.Width + 4, R.Top + FImageList.Height + 4);
DrawBtnFrame(Canvas, FButtonStyle, Color, not (odSelected in State), TmpR);
end;
Inc(R.Left, GetImageWidth(Index) + 8);
OrigR.Left := R.Left;
end
else
if Assigned(FImageList) then
begin
Offset := ((R.Bottom - R.Top) - GetImageHeight(Index)) div 2;
Tmp := Items[Index].ImageIndex;
{$IFDEF VCL}
// PRY 2002.06.04
//FImageList.Draw(FCanvas, R.Left + 2, R.Top + Offset, Tmp, dsTransparent, itImage);
{$IFDEF COMPILER6_UP}
FImageList.Draw(Canvas, R.Left + 2, R.Top + Offset, Tmp, dsTransparent, itImage);
{$ELSE}
FImageList.Draw(Canvas, R.Left + 2, R.Top + Offset, Tmp);
{$ENDIF COMPILER6_UP}
// PRY END
{$ENDIF VCL}
{$IFDEF VisualCLX}
FImageList.Draw(Canvas, R.Left + 2, R.Top + Offset, Tmp);
{$ENDIF VisualCLX}
if FButtonFrame then
begin
TmpR := Rect(R.Left, R.Top, R.Left + FImageList.Width + 4, R.Top + FImageList.Height + 4);
DrawBtnFrame(Canvas, FButtonStyle, Color, not ((Tmp in [0..FImageList.Count - 1]) and (odSelected in State)), TmpR);
end;
Inc(R.Left, GetImageWidth(Index) + 8);
OrigR.Left := R.Left;
end;
R.Right := R.Left + TextWidth(Items[Index].Text);
InflateRect(R, 2, -1);
if Length(Items[Index].Text) > 0 then
begin
Inc(R.Right, 2);
FillRect(R);
Inc(R.Left, 2);
DrawText(Canvas, Items[Index].Text, Length(Items[Index].Text), R,
DT_SINGLELINE or DT_NOPREFIX or DT_VCENTER);
Dec(R.Left, 2);
if (odSelected in State) and (Color <> FColorHighlight) then
DrawFocusRect(R);
end
else
begin
FillRect(OrigR);
if (odSelected in State) and (Color <> FColorHighlight) then
DrawFocusRect(OrigR);
end;
end;
end;
procedure TJvImageListBox.DrawRightGlyph(Index: Integer; R: TRect; State: TOwnerDrawState);
var
Offset, Tmp: Integer;
TmpCol: TColor;
TmpR, OrigR: TRect;
begin
if csDestroying in ComponentState then
Exit;
OrigR := R;
with Canvas do
begin
TmpCol := Brush.Color;
Brush.Color := Color;
FillRect(R);
Brush.Color := TmpCol;
if not Items[Index].Glyph.Empty then
begin
Offset := ((R.Bottom - R.Top) - GetImageHeight(Index)) div 2;
Draw(R.Right - (GetImageWidth(Index) + 2), R.Top + Offset, Items[Index].Glyph);
if FButtonFrame then
begin
TmpR := Rect(R.Right - (FImageList.Width + 2) - 2, R.Top + Offset - 2, R.Right - 2, R.Top + Offset + FImageList.Height + 2);
DrawBtnFrame(Canvas, FButtonStyle, Color, not (odSelected in State), TmpR);
end;
Dec(R.Right, FImageList.Width + 4);
OrigR.Right := R.Right;
end
else
if Assigned(FImageList) then
begin
Tmp := Items[Index].ImageIndex;
Offset := ((R.Bottom - R.Top) - GetImageHeight(Index)) div 2;
{$IFDEF VCL}
// PRY 2002.06.04
//FImageList.Draw(FCanvas, R.Right - (FWidth + 2), R.Top + Offset, Tmp, dsTransparent, itImage);
{$IFDEF COMPILER6_UP}
FImageList.Draw(Canvas, R.Right - (GetImageWidth(Index) + 2), R.Top + Offset, Tmp, dsTransparent, itImage);
{$ELSE}
FImageList.Draw(Canvas, R.Right - (GetImageWidth(Index) + 2), R.Top + Offset, Tmp);
{$ENDIF COMPILER6_UP}
// PRY END
{$ENDIF VCL}
{$IFDEF VisualCLX}
FImageList.Draw(Canvas, R.Right - (GetImageWidth(Index) + 2), R.Top + Offset, Tmp);
{$ENDIF VisualCLX}
if FButtonFrame then
begin
TmpR := Rect(R.Right - (FImageList.Width + 2) - 2, R.Top + Offset - 2, R.Right - 2, R.Top + Offset + FImageList.Height + 2);
DrawBtnFrame(Canvas, FButtonStyle, Color, not ((Tmp in [0..FImageList.Count - 1]) and (odSelected in State)), TmpR);
end;
Dec(R.Right, FImageList.Width + 4);
OrigR.Right := R.Right;
end;
R.Left := R.Right - TextWidth(Items[Index].Text);
// R.Right := R.Left + TextWidth(Items[Index].Text);
InflateRect(R, 2, -1);
if Length(Items[Index].Text) > 0 then
begin
Dec(R.Right, 2);
FillRect(R);
DrawText(Canvas, Items[Index].Text, Length(Items[Index].Text), R,
DT_SINGLELINE or DT_NOPREFIX or DT_VCENTER or DT_RIGHT);
Inc(R.Right, 2);
if (odSelected in State) and (Color <> FColorHighlight) then
DrawFocusRect(R);
end
else
begin
FillRect(OrigR);
if (odSelected in State) and (Color <> FColorHighlight) then
DrawFocusRect(OrigR);
end;
end;
end;
{$IFDEF VCL}
procedure TJvImageListBox.MeasureItem(Index: Integer; var Height: Integer);
begin
Height := Max(GetItemHeight(Font) + 4, GetImageHeight(Index) + Ord(ButtonFrame) * 4);
end;
{$ENDIF VCL}
{$IFDEF VisualCLX}
procedure TJvImageListBox.MeasureItem(Control: TWinControl; Item: QClxListBoxItemH;
var Height, Width: Integer);
begin
Height := Max(GetItemHeight(Font) + 4, GetImageHeight(Index) + Ord(ButtonFrame) * 4);
end;
procedure TJvImageListBox.SetParent(const AParent: TWidgetControl);
begin
inherited SetParent(AParent);
ResetItemHeight;
end;
{$ENDIF VisualCLX}
procedure TJvImageListBox.FontChanged;
begin
inherited FontChanged;
ResetItemHeight;
{$IFDEF VCL}
RecreateWnd;
{$ENDIF VCL}
{$IFDEF VisualCLX}
RecreateWidget;
{$ENDIF VisualCLX}
end;
procedure TJvImageListBox.ResetItemHeight;
var
MaxImageHeight: Integer;
I: Integer;
begin
MaxImageHeight := GetImageHeight(-1);
for I := 0 to FItems.Count - 1 do
begin
if GetImageHeight(I) > MaxImageHeight then
MaxImageHeight := GetImageHeight(I);
end;
case FAlignment of
taLeftJustify, taRightJustify:
ItemHeight := Max(ItemHeight, Max(GetItemHeight(Font) + 4, MaxImageHeight + Ord(ButtonFrame) * 4));
taCenter:
ItemHeight := Max(ItemHeight, Max(GetItemHeight(Font) + 4, MaxImageHeight + Ord(ButtonFrame) * 8));
end;
Invalidate;
end;
{$IFDEF VCL}
procedure TJvImageListBox.CNCommand(var Msg: TWMCommand);
begin
inherited;
case Msg.NotifyCode of
LBN_SELCHANGE:
begin
inherited Changed;
Click;
end;
end;
end;
{$ENDIF VCL}
procedure TJvImageListBox.Resize;
begin
inherited Resize;
Invalidate;
end;
procedure TJvImageListBox.SetItems(const Value: TJvImageItems);
begin
FItems.Assign(Value);
FItems.Update(nil);
end;
function TJvImageListBox.GetImageWidth(Index: Integer): Integer;
begin
if (Index > -1) and not Items[Index].Glyph.Empty then
Result := Items[Index].Glyph.Width
else
if Assigned(FImageList) then
Result := FImageList.Width
else
Result := FImageWidth;
end;
function TJvImageListBox.GetImageHeight(Index: Integer): Integer;
begin
if (Index > -1) and not Items[Index].Glyph.Empty then
Result := Items[Index].Glyph.Height
else
if Assigned(FImageList) then
Result := FImageList.Height
else
Result := FImageHeight;
end;
procedure TJvImageItem.SetFont(const Value: TFont);
begin
if not (puFont in FListPropertiesUsed) then
Font.Assign(Value);
end;
function TJvImageItem.GetFont: TFont;
begin
if puFont in FListPropertiesUsed then
begin
Result := TWinControlAccessProtected(GetWinControl).Font
end
else
begin
if not Assigned(FFont) then
begin
FFont := TFont.Create;
FFont.OnChange := FontChange;
FFont.Assign(TWinControlAccessProtected(GetWinControl).Font);
end;
Result := FFont;
end;
end;
function TJvImageItem.GetGlyph: TBitmap;
begin
Result := FGlyph;
end;
procedure TJvImageItem.SetGlyph(const Value: TBitmap);
begin
FGlyph.Assign(Value);
if FOwner <> nil then
GetWinControl.Invalidate;
end;
procedure TJvImageItem.FontChange(Sender: TObject);
begin
if not (puFont in FListPropertiesUsed) then
if FOwner <> nil then
GetWinControl.Invalidate;
end;
function TJvImageItems.GetObjects(Index: Integer): TObject;
begin
Result := Items[Index].LinkedObject;
end;
procedure TJvImageItems.SetObjects(Index: Integer; const Value: TObject);
begin
Items[Index].LinkedObject := Value;
end;
function TJvImageItem.GetWinControl: TWinControl;
begin
Result := TWinControl(TJvImageItems(Collection).GetOwner);
end;
function TJvImageItem.GetColorHighlight: TColor;
begin
if (puColorHighlight in FListPropertiesUsed) and (FOwner <> nil) then
begin
if GetWinControl is TJvImageListBox then
Result := TJvImageListBox(GetWinControl).ColorHighlight
else
Result := TJvImageComboBox(GetWinControl).ColorHighlight;
end
else
Result := FColorHighlight;
end;
function TJvImageItem.GetColorHighlightText: TColor;
begin
if (puColorHighlightText in FListPropertiesUsed) and (FOwner <> nil) then
begin
if GetWinControl is TJvImageListBox then
Result := TJvImageListBox(GetWinControl).ColorHighlightText
else
Result := TJvImageComboBox(GetWinControl).ColorHighlightText;
end
else
Result := FColorHighlightText;
end;
procedure TJvImageItem.SetColorHighlight(const Value: TColor);
begin
if (puColorHighlight in FListPropertiesUsed) and (FOwner <> nil) then
begin
if GetWinControl is TJvImageListBox then
TJvImageListBox(GetWinControl).ColorHighlight := Value
else
TJvImageComboBox(GetWinControl).ColorHighlight := Value;
end
else
FColorHighlight := Value;
end;
procedure TJvImageItem.SetColorHighlightText(const Value: TColor);
begin
if (puColorHighlightText in FListPropertiesUsed) and (FOwner <> nil) then
begin
if GetWinControl is TJvImageListBox then
TJvImageListBox(GetWinControl).ColorHighlightText := Value
else
TJvImageComboBox(GetWinControl).ColorHighlightText := Value
end
else
FColorHighlightText := Value;
end;
function TJvImageItem.IsColorHighlightTextStored: Boolean;
begin
Result := not (puColorHighlightText in FListPropertiesUsed);
end;
function TJvImageItem.IsFontStored: Boolean;
begin
Result := not (puFont in FListPropertiesUsed);
end;
function TJvImageItem.IsColorHighlightStored: Boolean;
begin
Result := not (puColorHighlight in FListPropertiesUsed);
end;
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -