📄 wwimagecombo.pas
字号:
FImageIndex:= Value;
// TwwComboExItems(Collection).SetItem(Index);
end;
procedure TwwComboExItem.SetIndex(Value: Integer);
begin
inherited SetIndex(Value);
// TwwComboExItems(Collection).SetItem(Value);
end;
function TwwComboExItem.GetDisplayName: string;
begin
if DisplayedText<>'' then result:= DisplayedText
else result:= inherited GetDisplayName;
end;
{
procedure TwwComboExItem.SetOverlayImageIndex(const Value: TImageIndex);
begin
FOverlayImageIndex := Value;
// TwwComboExItems(Collection).SetItem(Index);
end;
}
procedure TwwComboExItem.SetSelectedImageIndex(const Value: TImageIndex);
begin
FSelectedImageIndex := Value;
// TwwComboExItems(Collection).SetItem(Index);
end;
function TwwImageCombo.CreateListBox: TwwPopupListBox;
begin
result:= TwwPopupImageListBox.create(self);
end;
procedure TwwImageCombo.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then
begin
if AComponent = Images then Images := nil;
end;
end;
procedure TwwImageCombo.DropDown;
begin
// (Listbox as TwwPopupImageListBox).Style:= lbOwnerDrawFixed;
inherited DropDown;
end;
procedure TwwImageCombo.ApplyList;
var i:integer;
begin
ListBoxNeeded; { 8/16/96 - Listbox needed before applying list }
(Listbox.Items).clear;
if Listbox.sorted and (not Sorted) then Listbox.sorted:= False;
if ItemsEx.SortType<>icstNone then
self.ItemsEx.Sort;
for i:= 0 to FItemsEx.count-1 do
begin
ListBox.AddItem(FItemsEx[i].DisplayedText, FItemsEx[i]);
end;
end;
procedure TwwImageCombo.SetImages(Value: TCustomImageList);
begin
if Images <> value then
begin
FImages:=value;
SetEditRect;
Invalidate;
end;
end;
Function TwwImageCombo.CustomDraw: boolean;
begin
result:= true;
end;
function TwwImageCombo.GetImageRect: TRect;
var imageRect: TRect;
begin
imageRect:= ClientRect;
if Frame.IsFrameEffective then
begin
imageRect.Left:= imageRect.Left +2;
imageRect.Top:= imageRect.Top + 2;
end;
imageRect.Left:= imageRect.Left + 1;
imageRect.Right:= imageRect.Left + Images.Width;
result:= imageRect;
end;
procedure TwwImageCombo.Paint; // Paint called for control part
var imageRect: TRect;
comboItem: TwwComboExItem;
begin
if (images<>nil) then
begin
if self.ItemIndex>=0 then
begin
comboItem:= ItemsEx.Items[ItemIndex] as TwwComboExItem;
imageRect:= GetImageRect;
Images.Draw(ControlCanvas, imageRect.left,
imageRect.Top + (imageRect.Bottom-imageRect.Top-TImageList(Images).Height) div 2, comboItem.ImageIndex)
end;
end;
end;
procedure TwwImageCombo.DrawFocusRect(ACanvas: TCanvas; ARect: TRect);
begin
ACanvas.Pen.Color:= clHighlight;
if Images<>nil then
// ARect.Left:= ARect.Left + Images.Width + 2;
// ARect.Right:= ARect.Right;
if not (self.IsVistaComboNonEditable) then
begin
ACanvas.FrameRect(ARect);
SetTextColor(ACanvas.Handle, clBlack);
SetBkColor(ACanvas.Handle, clWhite);
end
else begin
SetTextColor(ACanvas.Handle, clBlack);
SetBkColor(ACanvas.Handle, clWhite);
end;
ACanvas.DrawFocusRect(ARect);
end;
Procedure TwwImageCombo.ShowText(ACanvas: TCanvas;
ARect: TRect; indentLeft, indentTop: integer; AText: string; transparent: boolean = false);
var FCanvas: TCanvas;
textRect, imageRect: TRect;
caption: string;
imageIndex: integer;
comboItem: TwwComboExItem;
WriteOptions: TwwWriteTextOptions;
tempItemIndex: integer;
// IPStudioREg: TRegIniFile;
// path: string;
begin
FCanvas:= ACanvas;
if isDroppedDown then begin
FCanvas.Brush.Color:= Color;
FCanvas.Font.Color:= Font.Color;
end;
ARect:= ClientRect;
textRect:= ARect;
if Images<>nil then
textRect.Left:= textRect.Left + Images.Width + 4;
textRect.Top:= textRect.Top + 1;
if Frame.IsFrameEffective then begin
textRect.Left:= textRect.Left +2;
textRect.Top:= textRect.Top + 1;
end;
caption:= '';
imageIndex:=-1;
if csPaintCopy in ControlState then
begin
caption:= AText;
tempItemIndex:= GetItemIndexFromText(AText);
if tempItemIndex>=0 then
begin
imageIndex:= ItemsEx.Items[tempItemIndex].ImageIndex;
end;
end
else begin
if ItemIndex>=0 then
begin
comboItem:= ItemsEx.Items[ItemIndex] as TwwComboExItem;
caption:= comboItem.DisplayedText;
imageIndex:= comboItem.ImageIndex;
end
else begin
// comboItem:= nil;
caption:= NullTextDisplay;
end;
end;
WriteOptions:= [];
if transparent then WriteOptions:= WriteOptions + [wtoTransparent];
if UseRightToLeftAlignment and (GetEffectiveAlignment = taLeftJustify) then
wwWriteTextLinesT(FCanvas, textRect, 1, 1,
pchar(caption), taRightJustify, WriteOptions)
else
wwWriteTextLinesT(FCanvas, textRect, 1, 1, //TempLeft-1, TempIndent-1,
pchar(caption), GetEffectiveAlignment, WriteOptions);
if (imageIndex>=0) then
begin
imageRect:= GetImageRect;
if Images<>nil then
Images.Draw(FCanvas, imageRect.left,
imageRect.Top + (imageRect.Bottom-imageRect.Top-TImageList(Images).Height) div 2, ImageIndex)
end;
end;
function TwwImageCombo.GetValue: string;
begin
// result:= inherited Text;
result:= FValue;
end;
procedure TwwImageCombo.RefreshDisplay;
var
i: Integer;
found: boolean;
begin
found:= false;
for i := 0 to ItemsEx.Count - 1 do
begin
if not MapList then
begin
if ItemsEx[i].DisplayedText = Value then
begin
ItemIndex:= i;
found:=true;
break;
end;
end
else begin
if ItemsEx[i].StoredText = Value then
begin
ItemIndex:= i;
found:=true;
break;
end;
end;
end;
if not found then ItemIndex:=-1;
end;
procedure TwwImageCombo.SetValue(value: string);
begin
EnableEdit;
// ListBoxItemsNeeded;
FValue:= value;
RefreshDisplay;
end;
Procedure TwwImageCombo.Loaded;
begin
inherited Loaded;
end;
procedure TwwImageCombo.CloseUp(Accept: Boolean);
var comboItem: TwwComboExItem;
begin
if IsDroppedDown and Accept then
begin
inherited CloseUp(Accept);
if ListBox.ItemIndex>=0 then
begin
comboItem:= TwwComboExItem(ListBox.Items.Objects[ListBox.ItemIndex]);
if MapList then
Value:= comboItem.StoredText
else
Value:= comboItem.DisplayedText;
end;
end;
end;
function TwwImageCombo.GetItemIndexFromText(DisplayedText: string): integer;
var i: integer;
begin
for i := 0 to ItemsEx.Count - 1 do
begin
if not MapList then
begin
if ItemsEx[i].DisplayedText = DisplayedText then
begin
result:= i;
exit;
end;
end
else begin
if ItemsEx[i].DisplayedText = DisplayedText then
begin
result:= i;
exit;
end;
end;
end;
result:= -1;
end;
procedure TwwImageCombo.SetItemIndex(val: integer);
var comboItem: TwwComboExItem;
begin
inherited SetItemIndex(val);
if (itemIndex<0) then
begin
FValue:= '';
// Text:= '';
exit;
end;
comboItem:= TwwComboExItem(ListBox.Items.Objects[ItemIndex]);
if (comboItem=nil) then exit;
if MapList then
FValue:= comboItem.StoredText
else
FValue:= comboItem.DisplayedText;
Text:= comboItem.DisplayedText;
end;
procedure TwwImageCombo.SetEditRect;
var
Loc: TRect;
begin
Loc.Bottom :=ClientHeight+1; {+1 is workaround for windows paint bug}
if ShowButton then Loc.Right := BtnControl.Left - 2
else Loc.Right:= ClientWidth - 2;
if (Frame.IsFrameEffective) then
begin
Frame.GetEditRectForFrame(Loc);
Loc.Top:= Loc.Top +1;
Loc.Left:= Loc.Left +1;
end
else if (BorderStyle = bsNone) and
(IsInwwObjectView(self)) then begin
Loc.Top := 1;
Loc.Left := 1;
end
else if (BorderStyle = bsNone) then begin
Loc.Top := 2;
Loc.Left := 2;
end
else begin
Loc.Top := 0;
Loc.Left := 0;
end;
if Images<>nil then
begin
Loc.Left:= Loc.Left + Images.Width + 4;
end;
SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@Loc));
end;
function TwwImageCombo.CalcItemHeight: integer;
begin
result:= Listbox.Canvas.TextHeight('A') + 3;
if Images<>nil then
result:= wwMax(Images.Height+2, result);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -