📄 jvqlistcomb.pas
字号:
begin
FWidth := FImageList.Width;
FHeight := FImageList.Height;
end
else
begin
FWidth := 0;
FHeight := 0;
end;}
ResetItemHeight;
end;
end;
procedure TJvImageListBox.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
ResetItemHeight;
end;
end;
procedure TJvImageListBox.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FImageList) then
FImageList := nil;
end;
procedure TJvImageListBox.SetColorHighlight(Value: TColor);
begin
if FColorHighlight <> Value then
begin
FColorHighlight := Value;
Invalidate;
end;
end;
procedure TJvImageListBox.SetColorHighlightText(Value: TColor);
begin
if FColorHighlightText <> Value then
begin
FColorHighlightText := Value;
Invalidate;
end;
end;
function TJvImageListBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState): Boolean;
var
SavedColor: TColor;
begin
Result := True;
if csDestroying in ComponentState then
Exit;
if odSelected in State then
begin
Canvas.Brush.Color := Items[Index].ColorHighlight;
Canvas.Font.Color := Items[Index].ColorHighlightText;
end;
SavedColor := Canvas.Font.Color;
Canvas.Font.Assign(Items[Index].Font);
if State <> [] then
Canvas.Font.Color := SavedColor;
case FAlignment of
taLeftJustify:
DrawLeftGlyph(Index, Rect, State);
taRightJustify:
DrawRightGlyph(Index, Rect, State);
taCenter:
DrawCenteredGlyph(Index, Rect, State);
end;
end;
procedure TJvImageListBox.DrawCenteredGlyph(Index: Integer; R: TRect; State: TOwnerDrawState);
var
Tmp, Tmp2: 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
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;
FImageList.Draw(Canvas, R.Left + Tmp, R.Top + 2, Tmp2);
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;
FImageList.Draw(Canvas, R.Left + 2, R.Top + Offset, Tmp);
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;
FImageList.Draw(Canvas, R.Right - (GetImageWidth(Index) + 2), R.Top + Offset, Tmp);
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;
procedure TJvImageListBox.MeasureItem(Control: TWinControl; Item: QClxListBoxItemH;
var Height, Width: Integer);
begin
Height := Max(GetItemHeight(Font) + 4, FImageList.Height + Ord(ButtonFrame) * 4);
end;
procedure TJvImageListBox.SetParent(const AParent: TWidgetControl);
begin
inherited SetParent(AParent);
ResetItemHeight;
end;
procedure TJvImageListBox.FontChanged;
begin
inherited FontChanged;
ResetItemHeight;
end;
procedure TJvImageListBox.ResetItemHeight;
var
MaxImageHeight: Integer;
I: Integer;
begin
if (csRecreating in ControlState) then
Exit;
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;
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}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQListComb.pas,v $';
Revision: '$Revision: 1.10 $';
Date: '$Date: 2005/02/06 14:06:14 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -