cxmclistbox.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,787 行 · 第 1/4 页
PAS
1,787 行
Result := FInnerHeaderSectionRectsWithScrollbar[AIndex]
else
Result := FInnerHeaderSectionRectsWithoutScrollbar[AIndex];
end;
function TcxMCListBox.GetHeaderSections: TcxHeaderSections;
begin
Result := FInnerHeader.Sections;
end;
procedure TcxMCListBox.SetHeaderSections(Value: TcxHeaderSections);
begin
FInnerHeader.Sections := Value;
end;
procedure TcxMCListBox.SetAlignment(Value: TAlignment);
var
I: Integer;
begin
if FAlignment <> Value then
begin
FAlignment := Value;
for I := 0 to Pred(HeaderSections.Count) do
HeaderSections[I].Alignment := FAlignment;
FullRepaint;
end;
end;
procedure TcxMCListBox.SetMultiLines(Value: Boolean);
begin
if FMultiLines <> Value then
begin
FMultiLines := Value;
FullRepaint;
end;
end;
procedure TcxMCListBox.SetShowEndEllipsis(Value: Boolean);
begin
if FShowEndEllipsis <> Value then
begin
FShowEndEllipsis := Value;
FullRepaint;
end;
end;
procedure TcxMCListBox.SetDelimiter(Value: Char);
begin
if FDelimiter <> Value then
begin
FDelimiter := Value;
FullRepaint;
end;
end;
function TcxMCListBox.GetHeaderDragReorder: Boolean;
begin
Result := FInnerHeader.DragReorder;
end;
procedure TcxMCListBox.SetHeaderDragReorder(Value: Boolean);
begin
FInnerHeader.DragReorder := Value;
end;
procedure TcxMCListBox.SetShowColumnLines(Value: Boolean);
begin
if FShowColumnLines <> Value then
begin
FShowColumnLines := Value;
FullRepaint;
end;
end;
procedure TcxMCListBox.SetShowHeader(Value: Boolean);
begin
if Value <> FShowHeader then
begin
FShowHeader := Value;
FInnerHeader.UpdateHeight;
end;
end;
procedure TcxMCListBox.SetColumnLineColor(Value: TColor);
begin
if FColumnLineColor <> Value then
begin
FColumnLineColor := Value;
FullRepaint;
end;
end;
procedure TcxMCListBox.SetOverflowEmptyColumn(Value: Boolean);
begin
if FOverflowEmptyColumn <> Value then
begin
FOverflowEmptyColumn := Value;
FullRepaint;
end;
end;
procedure TcxMCListBox.SectionEndResizeHandler(HeaderControl: TcxCustomHeader;
Section: TcxHeaderSection);
begin
FullRepaint;
end;
procedure TcxMCListBox.SectionsChangeHandler(Sender: TObject);
begin
FullRepaint;
end;
procedure TcxMCListBox.HScrollHandler(Sender: TObject; ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin
if Assigned(FSavedHScroll) then FSavedHScroll(Sender, ScrollCode, ScrollPos);
end;
procedure TcxMCListBox.SectionEndDragHandler(Sender: TObject);
begin
FInnerListBox.Invalidate;
end;
procedure TcxMCListBox.SectionTrackHandler(HeaderControl: TcxCustomHeader;
Section: TcxHeaderSection; Width: Integer; State: TcxSectionTrackState);
begin
if (State = tsTrackEnd) then
FullRepaint;
end;
procedure TcxMCListBox.FullRepaint;
begin
Canvas.Canvas.Lock;
try
if Count = 0 then
FInnerListBox.FullRepaint
else
begin
FSavedIndex := ItemIndex;
FInternalPaint := True;
FInnerListBox.RecalcItemRects;
FInnerListBox.FullRepaint;
FInnerListBox.ItemIndex := FSavedIndex;
end;
finally
FInternalPaint := False;
Canvas.Canvas.Unlock;
end;
end;
procedure TcxMCListBox.SectionSortChangedHandler(Sender: TObject;
const Section: TcxHeaderSection; const ASortOrder: TcxHeaderSortOrder);
var
TmpList: TMCStringList;
begin
if ASortOrder = soNone then
Exit;
TmpList := TMCStringList.Create;
try
Items.BeginUpdate;
try
TmpList.Assign(Items);
try
TmpList.Delimiter := FDelimiter;
TmpList.SortOrder := ASortOrder;
if ASortOrder = soNone then
TmpList.SortColumn := -1
else
TmpList.SortColumn := Succ(Section.DataIndex);
TmpList.Sort;
finally
Items.Assign(TmpList);
end;
finally
Items.EndUpdate;
end;
finally
TmpList.Free;
end;
end;
function TcxMCListBox.GetTextPart(AItemIndex, AColumnIndex: Integer): string;
var
APartIndex: Integer;
begin
APartIndex := HeaderSections[AColumnIndex].DataIndex;
if APartIndex < 0 then
Result := ''
else
Result := GetWord(APartIndex + 1, Items[AItemIndex], FDelimiter);
end;
procedure TcxMCListBox.DrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure AdjustCanvasColors;
var
ABackgroundColor, ATextColor: TColor;
begin
if (not FInternalPaint and (odSelected in State)) or
(FInternalPaint and (FSavedIndex = Index)) then
begin
ABackgroundColor := clHighlight;
ATextColor := clHighlightText;
end else
begin
ABackgroundColor := ActiveStyle.Color;
ATextColor := ActiveStyle.GetVisibleFont.Color;
end;
FInnerListBox.Canvas.Brush.Color := ABackgroundColor;
FInnerListBox.Canvas.Font.Color := ATextColor;
end;
procedure DrawColumnSectionText(AColumnIndex: Integer);
var
ATextRect: TRect;
begin
ATextRect := GetCellRect(Index, AColumnIndex, ARect.Top, ARect.Bottom,
InnerListBox.VScrollBarVisible);
DrawCellText(ATextRect, Index, AColumnIndex);
FInnerListBox.Canvas.ExcludeClipRect(ATextRect);
end;
procedure DrawColumnSectionLine(AColumnIndex: Integer);
begin
FInnerListBox.Canvas.Pen.Color := ColumnLineColor;
FInnerListBox.Canvas.Pen.Width := 1;
FInnerListBox.Canvas.MoveTo(GetHeaderSectionRect(AColumnIndex, InnerListBox.VScrollBarVisible).Right, ARect.Top);
FInnerListBox.Canvas.LineTo(GetHeaderSectionRect(AColumnIndex, InnerListBox.VScrollBarVisible).Right, ARect.Bottom);
end;
var
I: Integer;
begin
AdjustCanvasColors;
FInnerListBox.Canvas.FillRect(ARect);
for I := 0 to HeaderSections.Count - 1 do
begin
DrawColumnSectionText(I);
if ShowColumnLines then
DrawColumnSectionLine(I);
end;
end;
procedure TcxMCListBox.MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
begin
Height := CalcItemHeight(Index, InnerListBox.VScrollBarVisible);
end;
procedure TcxMCListBox.CalcHeaderSectionRects;
procedure InternalCalcHeaderSectionRects(AHeaderWidth: Integer;
out ASectionRects: TcxHeaderSectionRects);
var
ASectionWidths: TcxHeaderSectionWidths;
I: Integer;
begin
InnerHeader.CalcSectionWidths(AHeaderWidth, ASectionWidths);
SetLength(ASectionRects, InnerHeader.Sections.Count);
for I := 0 to InnerHeader.Sections.Count - 1 do
ASectionRects[I] := InnerHeader.GetSectionRectBySectionWidths(AHeaderWidth, ASectionWidths, I);
end;
begin
InternalCalcHeaderSectionRects(FInnerPanel.ClientWidth, FInnerHeaderSectionRectsWithoutScrollbar);
InternalCalcHeaderSectionRects(FInnerPanel.ClientWidth - GetScrollBarSize.cx, FInnerHeaderSectionRectsWithScrollbar);
end;
function TcxMCListBox.CalcItemHeight(AIndex: Integer; AVScrollBarVisible: Boolean): Integer;
var
I, ATextHeight: Integer;
ACalcRect: TRect;
begin
Result := GetItemHeight;
ATextHeight := FInnerListBox.Canvas.TextHeight('Wq');
if ATextHeight > Result then
Result := ATextHeight;
for I := 0 to HeaderSections.Count - 1 do
begin
ACalcRect := GetCellTextRect(AIndex, I, 0, Result, AVScrollBarVisible);
if RectHeight(ACalcRect) > Result then
Result := RectHeight(ACalcRect);
end;
end;
function TcxMCListBox.GetCount: Integer;
begin
Result := FInnerListBox.Items.Count;
end;
function TcxMCListBox.GetExtendedSelect: Boolean;
begin
Result := FInnerListBox.ExtendedSelect;
end;
function TcxMCListBox.GetItemHeight: Integer;
begin
Result := FInnerListBox.ItemHeight;
end;
function TcxMCListBox.GetItemIndex: Integer;
begin
Result := FInnerListBox.ItemIndex;
end;
function TcxMCListBox.GetItems: TStrings;
begin
Result := FInnerListBox.Items;
end;
function TcxMCListBox.GetMultiSelect: Boolean;
begin
Result := FInnerListBox.MultiSelect;
end;
function TcxMCListBox.GetReadOnly: Boolean;
begin
Result := DataBinding.ReadOnly;
end;
function TcxMCListBox.GetSelCount: Integer;
begin
Result := FInnerListBox.SelCount;
end;
function TcxMCListBox.GetSelected(Index: Integer): Boolean;
begin
Result := FInnerListBox.Selected[Index];
end;
function TcxMCListBox.GetSorted: Boolean;
begin
Result := FInnerListBox.Sorted;
end;
function TcxMCListBox.GetTopIndex: Integer;
begin
Result := FInnerListBox.TopIndex;
end;
procedure TcxMCListBox.SetExtendedSelect(Value: Boolean);
begin
FInnerListBox.ExtendedSelect := Value;
end;
procedure TcxMCListBox.SetItemHeight(Value: Integer);
begin
FInnerListBox.ItemHeight := Value;
FullRepaint;
end;
procedure TcxMCListBox.SetItemIndex(Value: Integer);
begin
FInnerListBox.ItemIndex := Value;
end;
procedure TcxMCListBox.SetItems(Value: TStrings);
begin
FInnerListBox.Items.Assign(Value);
DataChange;
end;
procedure TcxMCListBox.SetMultiSelect(Value: Boolean);
begin
FInnerListBox.MultiSelect := Value;
end;
procedure TcxMCListBox.SetReadOnly(Value: Boolean);
begin
DataBinding.ReadOnly := Value;
end;
procedure TcxMCListBox.SetSelected(Index: Integer; Value: Boolean);
begin
FInnerListBox.Selected[Index] := Value;
end;
procedure TcxMCListBox.SetSorted(Value: Boolean);
begin
FInnerListBox.Sorted := Value;
end;
procedure TcxMCListBox.SetTopIndex(Value: Integer);
begin
FInnerListBox.TopIndex := Value;
end;
function TcxMCListBox.GetAutoComplete: Boolean;
begin
Result := FInnerListBox.AutoComplete;
end;
function TcxMCListBox.GetAutoCompleteDelay: Cardinal;
begin
Result := FInnerListBox.AutoCompleteDelay;
end;
procedure TcxMCListBox.SetAutoComplete(Value: Boolean);
begin
FInnerListBox.AutoComplete := Value;
end;
procedure TcxMCListBox.SetAutoCompleteDelay(Value: Cardinal);
begin
FInnerListBox.AutoCompleteDelay := Value;
end;
function TcxMCListBox.GetScrollWidth: Integer;
begin
Result := FInnerListBox.ScrollWidth;
end;
function TcxMCListBox.GetTabWidth: Integer;
begin
Result := FInnerListBox.TabWidth;
end;
procedure TcxMCListBox.SetIntegralHeight(Value: Boolean);
begin
if Value <> FIntegralHeight then
begin
FIntegralHeight := Value;
SetSize;
end;
end;
procedure TcxMCListBox.SetScrollWidth(Value: Integer);
begin
FInnerListBox.ScrollWidth := Value;
end;
procedure TcxMCListBox.SetTabWidth(Value: Integer);
begin
FInnerListBox.Items.BeginUpdate;
try
FInnerListBox.TabWidth := Value;
finally
FInnerListBox.Items.EndUpdate;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?