cxlistbox.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 873 行 · 第 1/2 页
PAS
873 行
raise;
end;
inherited DoExit;
finally
FIsExitProcessing := False;
end;
end;
procedure TcxListBox.FontChanged;
begin
inherited FontChanged;
SetSize;
TWinControlAccess(InnerListBox).RecreateWnd;
end;
function TcxListBox.IsInternalControl(AControl: TControl): Boolean;
begin
if FInnerListBox = nil then
Result := True
else
Result := (AControl = FInnerListBox.HScrollBar) or (AControl = FInnerListBox.VScrollBar);
Result := Result or inherited IsInternalControl(AControl);
end;
function TcxListBox.IsReadOnly: Boolean;
begin
Result := DataBinding.IsControlReadOnly;
end;
procedure TcxListBox.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
case Key of
VK_PRIOR, VK_NEXT, VK_END, VK_HOME, VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN:
if not DataBinding.SetEditMode then
Key := 0;
end;
end;
procedure TcxListBox.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if IsTextChar(Key) then
begin
if not DataBinding.SetEditMode then
Key := #0;
end
else
if Key = #27 then
DataBinding.Reset;
end;
procedure TcxListBox.UpdateData;
begin
if ItemIndex >= 0 then
DataBinding.SetStoredValue(evsText, Items[ItemIndex])
else
DataBinding.SetStoredValue(evsText, '');
end;
function TcxListBox.CanResize(var NewWidth, NewHeight: Integer): Boolean;
begin
Result := inherited CanResize(NewWidth, NewHeight);
if not Result or not IntegralHeight or IsLoading then
Exit;
if Align in [alLeft, alRight, alClient] then
Exit;
GetOptimalHeight(NewHeight);
end;
procedure TcxListBox.SetSize;
var
ANewHeight: Integer;
APrevBoundsRect: TRect;
begin
if IsLoading then
Exit;
APrevBoundsRect := FInnerListBox.BoundsRect;
try
if not IntegralHeight or (Align in [alLeft, alRight, alClient]) then
begin
inherited SetSize;
Exit;
end;
ANewHeight := Height;
GetOptimalHeight(ANewHeight);
Height := ANewHeight;
inherited SetSize;
finally
if not EqualRect(APrevBoundsRect, FInnerListBox.BoundsRect) and FInnerListBox.HandleAllocated then
KillMessages(FInnerListBox.Handle, WM_MOUSEMOVE, WM_MOUSEMOVE);
end;
end;
procedure TcxListBox.WndProc(var Message: TMessage);
begin
if FInnerListBox <> nil then
case Message.Msg of
LB_ADDSTRING..LB_MSGMAX:
begin
with TMessage(Message) do
Result := SendMessage(FInnerListBox.Handle, Msg, WParam, LParam);
Exit;
end;
end;
inherited WndProc(Message);
if (FInnerListBox <> nil) and (Message.Msg = WM_COMMAND) and (Message.WParamHi = LBN_SELCHANGE) then
FInnerListBox.SetExternalScrollBarsParameters;
end;
function TcxListBox.DrawItem(ACanvas: TcxCanvas; AIndex: Integer;
const ARect: TRect; AState: TOwnerDrawState): Boolean;
begin
Result := Assigned(FOnDrawItem);
if Result then
FOnDrawItem(Self, ACanvas, AIndex, ARect, AState);
end;
function TcxListBox.GetDataBindingClass: TcxCustomDataBindingClass;
begin
Result := TcxDataBinding;
end;
function TcxListBox.GetInnerListBoxClass: TcxInnerListBoxClass;
begin
Result := TcxInnerListBox;
end;
procedure TcxListBox.GetOptimalHeight(var ANewHeight: Integer);
function GetItemHeight(AIndex: Integer): Integer;
begin
case ListStyle of
lbStandard{$IFDEF DELPHI6}, lbVirtual{$ENDIF}:
Result := Canvas.FontHeight(Font);
lbOwnerDrawFixed{$IFDEF DELPHI6}, lbVirtualOwnerDraw{$ENDIF}:
Result := ItemHeight;
lbOwnerDrawVariable:
begin
Result := ItemHeight;
if (AIndex < Count) and Assigned(FInnerListBox.OnMeasureItem) then
FInnerListBox.OnMeasureItem(Self, AIndex, Result);
end;
end;
end;
var
I: Integer;
ABorderExtent: TRect;
AItemHeight: Integer;
AListClientSize, AListSize, AScrollBarSize: TSize;
AScrollWidth: Integer;
AVScrollBar: Boolean;
begin
ABorderExtent := GetBorderExtent;
AListClientSize.cy := ABorderExtent.Top + ABorderExtent.Bottom;
AScrollBarSize := GetScrollBarSize;
AScrollWidth := ScrollWidth;
if AScrollWidth > 0 then
Inc(AScrollWidth, 4);
I := 0;
repeat
AItemHeight := GetItemHeight(I);
AListClientSize.cy := AListClientSize.cy + AItemHeight;
AListSize.cy := AListClientSize.cy;
AListClientSize.cx := Width - (ABorderExtent.Left + ABorderExtent.Right);
AVScrollBar := I + 1 < Count;
if AVScrollBar then
AListClientSize.cx := AListClientSize.cx - AScrollBarSize.cx;
if AListClientSize.cx < AScrollWidth then
AListSize.cy := AListSize.cy + AScrollBarSize.cy;
if AListSize.cy = ANewHeight then
Break;
if AListSize.cy > ANewHeight then
begin
if I > 0 then
begin
AListClientSize.cy := AListClientSize.cy - AItemHeight;
AListSize.cy := AListClientSize.cy;
AListClientSize.cx := Width - (ABorderExtent.Left + ABorderExtent.Right);
AVScrollBar := I < Count;
if AVScrollBar then
AListClientSize.cx := AListClientSize.cx - AScrollBarSize.cx;
if AListClientSize.cx < AScrollWidth then
AListSize.cy := AListSize.cy + AScrollBarSize.cy;
end;
Break;
end;
Inc(I);
until False;
ANewHeight := AListSize.cy;
end;
procedure TcxListBox.DoMeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
FOnMeasureItem(Self, Index, Height);
end;
function TcxListBox.GetAutoComplete: Boolean;
begin
Result := FInnerListBox.AutoComplete;
end;
function TcxListBox.GetAutoCompleteDelay: Cardinal;
begin
Result := FInnerListBox.AutoCompleteDelay;
end;
function TcxListBox.GetColumns: Integer;
begin
Result := FInnerListBox.Columns;
end;
function TcxListBox.GetCount: Integer;
begin
Result := FInnerListBox.Items.Count;
end;
function TcxListBox.GetExtendedSelect: Boolean;
begin
Result := FInnerListBox.ExtendedSelect;
end;
function TcxListBox.GetInnerListBox: TListBox;
begin
Result := FInnerListBox;
end;
function TcxListBox.GetItemHeight: Integer;
begin
Result := FInnerListBox.ItemHeight;
end;
function TcxListBox.GetItemIndex: Integer;
begin
Result := FInnerListBox.ItemIndex;
end;
function TcxListBox.GetItemObject: TObject;
begin
if ItemIndex <> -1 then
Result := Items.Objects[ItemIndex]
else
Result := nil;
end;
function TcxListBox.GetItems: TStrings;
begin
Result := FInnerListBox.Items;
end;
function TcxListBox.GetListStyle: TListBoxStyle;
begin
Result := FInnerListBox.Style;
end;
function TcxListBox.GetMultiSelect: Boolean;
begin
Result := FInnerListBox.MultiSelect;
end;
function TcxListBox.GetReadOnly: Boolean;
begin
Result := DataBinding.ReadOnly;
end;
function TcxListBox.GetSelCount: Integer;
begin
Result := FInnerListBox.SelCount;
end;
function TcxListBox.GetSelected(Index: Integer): Boolean;
begin
Result := FInnerListBox.Selected[Index];
end;
function TcxListBox.GetSorted: Boolean;
begin
Result := FInnerListBox.Sorted;
end;
function TcxListBox.GetTopIndex: Integer;
begin
Result := FInnerListBox.TopIndex;
end;
procedure TcxListBox.SetAutoComplete(Value: Boolean);
begin
FInnerListBox.AutoComplete := Value;
end;
procedure TcxListBox.SetAutoCompleteDelay(Value: Cardinal);
begin
FInnerListBox.AutoCompleteDelay := Value;
end;
procedure TcxListBox.SetColumns(Value: Integer);
begin
FInnerListBox.Columns := Value;
FInnerListBox.SetExternalScrollBarsParameters;
end;
procedure TcxListBox.SetExtendedSelect(Value: Boolean);
begin
FInnerListBox.ExtendedSelect := Value;
end;
procedure TcxListBox.SetItemHeight(Value: Integer);
begin
FInnerListBox.ItemHeight := Value;
end;
procedure TcxListBox.SetItemIndex(Value: Integer);
begin
FInnerListBox.ItemIndex := Value;
end;
procedure TcxListBox.SetItemObject(Value: TObject);
begin
ItemIndex := Items.IndexOfObject(Value);
end;
procedure TcxListBox.SetItems(Value: TStrings);
begin
FInnerListBox.Items := Value;
DataChange;
end;
procedure TcxListBox.SetListStyle(Value: TListBoxStyle);
begin
FInnerListBox.Style := Value;
end;
procedure TcxListBox.SetMultiSelect(Value: Boolean);
begin
FInnerListBox.MultiSelect := Value;
end;
procedure TcxListBox.SetOnMeasureItem(Value: TcxListBoxMeasureItemEvent);
begin
FOnMeasureItem := Value;
if Assigned(FOnMeasureItem) then
FInnerListBox.OnMeasureItem := DoMeasureItem
else
FInnerListBox.OnMeasureItem := nil;
end;
procedure TcxListBox.SetReadOnly(Value: Boolean);
begin
DataBinding.ReadOnly := Value;
end;
procedure TcxListBox.SetSelected(Index: Integer; Value: Boolean);
begin
FInnerListBox.Selected[Index] := Value;
end;
procedure TcxListBox.SetSorted(Value: Boolean);
begin
FInnerListBox.Sorted := Value;
end;
procedure TcxListBox.SetTopIndex(Value: Integer);
begin
FInnerListBox.TopIndex := Value;
end;
{$IFDEF DELPHI6}
function TcxListBox.GetOnData: TLBGetDataEvent;
begin
Result := FInnerListBox.OnData;
end;
function TcxListBox.GetOnDataFind: TLBFindDataEvent;
begin
Result := FInnerListBox.OnDataFind;
end;
function TcxListBox.GetOnDataObject: TLBGetDataObjectEvent;
begin
Result := FInnerListBox.OnDataObject;
end;
procedure TcxListBox.SetCount(Value: Integer);
begin
FInnerListBox.Count := Value;
end;
procedure TcxListBox.SetOnData(Value: TLBGetDataEvent);
begin
FInnerListBox.OnData := Value;
end;
procedure TcxListBox.SetOnDataFind(Value: TLBFindDataEvent);
begin
FInnerListBox.OnDataFind := Value;
end;
procedure TcxListBox.SetOnDataObject(Value: TLBGetDataObjectEvent);
begin
FInnerListBox.OnDataObject := Value;
end;
{$ENDIF}
function TcxListBox.GetScrollWidth: Integer;
begin
Result := FInnerListBox.ScrollWidth;
end;
function TcxListBox.GetTabWidth: Integer;
begin
Result := FInnerListBox.TabWidth;
end;
procedure TcxListBox.SetIntegralHeight(Value: Boolean);
begin
if Value <> FIntegralHeight then
begin
FIntegralHeight := Value;
SetSize;
end;
end;
procedure TcxListBox.SetScrollWidth(Value: Integer);
begin
FInnerListBox.ScrollWidth := Value;
end;
procedure TcxListBox.SetTabWidth(Value: Integer);
begin
FInnerListBox.TabWidth := Value;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?