cxmclistbox.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,787 行 · 第 1/4 页
PAS
1,787 行
end;
procedure TcxMCListBoxStrings.Exchange(Index1, Index2: Integer);
begin
Storage.Exchange(Index1, Index2);
end;
function TcxMCListBoxStrings.IndexOf(const S: string): Integer;
begin
Result := Storage.IndexOf(S);
end;
procedure TcxMCListBoxStrings.Insert(Index: Integer; const S: string);
begin
Storage.Insert(Index, S);
Changed(Index, Count - 1);
end;
procedure TcxMCListBoxStrings.Move(CurIndex, NewIndex: Integer);
begin
Storage.Move(CurIndex, NewIndex);
end;
function TcxMCListBoxStrings.Get(Index: Integer): string;
begin
Result := Storage[Index];
end;
function TcxMCListBoxStrings.GetCount: Integer;
begin
Result := Storage.Count;
end;
function TcxMCListBoxStrings.GetObject(Index: Integer): TObject;
begin
Result := Storage.Objects[Index];
end;
procedure TcxMCListBoxStrings.Put(Index: Integer; const S: string);
begin
Storage[Index] := S;
end;
procedure TcxMCListBoxStrings.PutObject(Index: Integer; AObject: TObject);
begin
Storage.Objects[Index] := AObject;
end;
procedure TcxMCListBoxStrings.SetUpdateState(Updating: Boolean);
begin
FUpdating := Updating;
if Updating then
Storage.BeginUpdate
else
Storage.EndUpdate;
if not Updating then
Changed;
end;
procedure TcxMCListBoxStrings.Changed(AStartIndex: Integer = -1;
AEndIndex: Integer = -1);
begin
if not FUpdating and Assigned(FOnChange) then
FOnChange(Self, AStartIndex, AEndIndex);
end;
{ TcxMCInnerListBox }
constructor TcxMCInnerListBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FItems := TcxMCListBoxStrings.Create(inherited Items);
TcxMCListBoxStrings(FItems).OnChange := ItemsChanged;
end;
destructor TcxMCInnerListBox.Destroy;
begin
FreeAndNil(FItems);
inherited Destroy;
end;
function TcxMCInnerListBox.CanFocus: Boolean;
begin
Result := Container.CanFocus;
end;
function TcxMCInnerListBox.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or
Container.FDataBinding.ExecuteAction(Action);
end;
function TcxMCInnerListBox.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or
Container.FDataBinding.UpdateAction(Action);
end;
procedure TcxMCInnerListBox.Click;
begin
if Container.DataBinding.SetEditMode then
inherited Click;
end;
procedure TcxMCInnerListBox.FullRepaint;
begin
InternalInvalidateRect(Self, GetControlRect(Self), True);
end;
procedure TcxMCInnerListBox.SetItems(Value: TStrings);
begin
FItems.Assign(Value);
end;
procedure TcxMCInnerListBox.WMPaint(var Message: TWMPaint);
begin
inherited;
if Container.ShowColumnLines then
DrawLines;
end;
procedure TcxMCInnerListBox.CMFontChanged(var Message: TMessage);
begin
inherited;
RecalcItemRects;
end;
procedure TcxMCInnerListBox.RecalcItemRects(AStartIndex: Integer = -1;
AEndIndex: Integer = -1);
var
AIsWindowRecreationNeeded: Boolean;
AItemHeight, ANewItemHeight, I: Integer;
AVScrollBarVisibilityChanged: Boolean;
begin
Container.CalcHeaderSectionRects;
if (AStartIndex = -1) and (AEndIndex = -1) then
begin
AStartIndex := 0;
AEndIndex := Items.Count - 1;
end;
AIsWindowRecreationNeeded := False;
AVScrollBarVisibilityChanged := FVScrollBarVisible <> IsVScrollBarVisible;
if AVScrollBarVisibilityChanged then
begin
FVScrollBarVisible := not FVScrollBarVisible;
(Parent as TcxMCInnerPanel).AdjustChildsPosition;
end;
for I := AStartIndex to AEndIndex do
begin
AItemHeight := Perform(LB_GETITEMHEIGHT, I, 0);
ANewItemHeight := Container.CalcItemHeight(I, FVScrollBarVisible);
if ANewItemHeight <> AItemHeight then
begin
AIsWindowRecreationNeeded := True;
Break;
end;
end;
if AIsWindowRecreationNeeded and HandleAllocated then
begin
RecreateWnd;
Update;
end;
end;
function TcxMCInnerListBox.GetContainer: TcxMCListBox;
begin
Result := TcxMCListBox(FContainer);
end;
function TcxMCInnerListBox.IsVScrollBarVisible: Boolean;
var
AItemsHeight: Integer;
I: Integer;
begin
AItemsHeight := 0;
for I := 0 to Items.Count - 1 do
begin
Inc(AItemsHeight, Container.CalcItemHeight(I, False));
if AItemsHeight > Height then
Break;
end;
Result := AItemsHeight > Height;
end;
procedure TcxMCInnerListBox.ItemsChanged(Sender: TStrings;
AStartIndex, AEndIndex: Integer);
begin
RecalcItemRects(AStartIndex, AEndIndex);
end;
procedure TcxMCInnerListBox.SetContainer(Value: TcxMCListBox);
begin
FContainer := Value;
end;
procedure TcxMCInnerListBox.DrawLines;
var
AColumnLineTop, I: Integer;
ALastItemRect: TRect;
begin
if Items.Count > 0 then
begin
ALastItemRect := ItemRect(Items.Count - 1);
if ALastItemRect.Bottom > Height then
Exit
else
AColumnLineTop := ALastItemRect.Bottom;
end
else
AColumnLineTop := 0;
Canvas.Pen.Color := Container.ColumnLineColor;
Canvas.Pen.Width := 1;
for I := 0 to Container.HeaderSections.Count - 1 do
begin
Canvas.MoveTo(Container.HeaderSections[I].Right, AColumnLineTop);
Canvas.LineTo(Container.HeaderSections[I].Right, Height);
end;
end;
{ TcxMCInnerHeader }
constructor TcxMCInnerHeader.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csNoDesignVisible];
TabStop := False;
end;
function TcxMCInnerHeader.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or
Container.FDataBinding.ExecuteAction(Action);
end;
function TcxMCInnerHeader.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or
Container.FDataBinding.UpdateAction(Action);
end;
procedure TcxMCInnerHeader.AdjustSize;
begin
inherited AdjustSize;
FitToClientWidth;
end;
procedure TcxMCInnerHeader.Click;
begin
if Container.DataBinding.SetEditMode then
inherited Click;
end;
//procedure TcxMCInnerHeader.DoSectionEndResizeEvent(Section: TcxHeaderSection);
//begin
// inherited DoSectionEndResizeEvent(Section);
// AdjustScrollWidth;
//end;
function TcxMCInnerHeader.IsInnerControl: Boolean;
begin
Result := True;
end;
procedure TcxMCInnerHeader.LookAndFeelChanged(Sender: TcxLookAndFeel;
AChangedValues: TcxLookAndFeelValues);
begin
inherited LookAndFeelChanged(Sender, AChangedValues);
if HandleAllocated then
UpdateHeight;
end;
procedure TcxMCInnerHeader.Notification(AComponent: TComponent;
Operation: TOperation);
var
AHeightCalculatingNeeded: Boolean;
begin
AHeightCalculatingNeeded := (Operation = opRemove) and (AComponent = Images);
inherited Notification(AComponent, Operation);
if AHeightCalculatingNeeded then
UpdateHeight;
end;
procedure TcxMCInnerHeader.UpdateHeight;
var
APrevHeight: Integer;
begin
APrevHeight := Height;
if Container.ShowHeader then
Height := GetAutoHeight
else
Height := 0;
if Height <> APrevHeight then
begin
(Parent as TcxMCInnerPanel).AdjustChildsPosition;
Container.InnerListBox.RecalcItemRects;
end;
end;
//procedure TcxMCInnerHeader.AdjustScrollWidth;
//var
// AScrollWidth, I: Integer;
//begin
// AScrollWidth := 0;
// for I := 0 to Sections.Count - 1 do
// Inc(AScrollWidth, Sections[I].Width);
// if AScrollWidth < Width then
// AScrollWidth := Width;
// Container.InnerListBox.ScrollWidth := AScrollWidth;
//end;
function TcxMCInnerHeader.GetControlContainer: TcxContainer;
begin
Result := FContainer;
end;
function TcxMCInnerHeader.GetControl: TWinControl;
begin
Result := Self;
end;
function TcxMCInnerHeader.GetContainer: TcxMCListBox;
begin
Result := TcxMCListBox(FContainer);
end;
procedure TcxMCInnerHeader.CMFontChanged(var Message: TMessage);
begin
inherited;
UpdateHeight;
end;
procedure TcxMCInnerHeader.WMSetFocus(var Message: TWMSetFocus);
begin
Container.InnerListBox.SetFocus;
end;
{ TcxMCInnerPanel }
constructor TcxMCInnerPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csAcceptsControls];
TabStop := False;
end;
procedure TcxMCInnerPanel.AdjustChildsPosition;
function GetInnerHeaderWidth: Integer;
begin
Result := ClientWidth;
if MCListBox.InnerListBox.VScrollBarVisible then
Dec(Result, GetScrollBarSize.cx);
end;
begin
MCListBox.InnerHeader.SetBounds(0, 0, GetInnerHeaderWidth,
MCListBox.InnerHeader.Height);
MCListBox.InnerListBox.SetBounds(0, MCListBox.InnerHeader.Height, ClientWidth,
ClientHeight - MCListBox.InnerHeader.Height);
end;
procedure TcxMCInnerPanel.BoundsChanged;
begin
inherited BoundsChanged;
AdjustChildsPosition;
MCListBox.InnerListBox.RecalcItemRects;
end;
procedure TcxMCInnerPanel.LookAndFeelChanged(Sender: TcxLookAndFeel;
AChangedValues: TcxLookAndFeelValues);
begin
inherited LookAndFeelChanged(Sender, AChangedValues);
Invalidate;
end;
procedure TcxMCInnerPanel.Paint;
var
R: TRect;
begin
inherited Paint;
R := Rect(MCListBox.InnerHeader.Width, 0, ClientWidth, MCListBox.InnerHeader.Height);
InflateRect(R, 10, 0);
LookAndFeel.Painter.DrawHeaderControlSection(Canvas, R, cxEmptyRect, [],
[bTop, bBottom], cxbsNormal, taLeftJustify, vaTop, False, False, '', Canvas.Font,
clNone, clBtnFace);
end;
function TcxMCInnerPanel.GetMCListBox: TcxMCListBox;
begin
Result := Parent as TcxMCListBox;
end;
procedure TcxMCInnerPanel.WMSetFocus(var Message: TWMSetFocus);
var
AInnerListBox: TcxMCInnerListBox;
begin
AInnerListBox := TcxMCListBox(Parent).InnerListBox;
if AInnerListBox.CanFocus then
AInnerListBox.SetFocus;
end;
{ TcxMCListBox }
constructor TcxMCListBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAlignment := taLeftJustify;
FMultiLines := False;
FShowEndEllipsis := True;
FDelimiter := ';';
FOverflowEmptyColumn := True;
FShowColumnLines := True;
FColumnLineColor := clBtnShadow;
FInternalPaint := False;
FInternalFlagCreatedHeader := False;
FSavedIndex := -1;
FShowHeader := True;
Width := 121;
Height := 97;
FOverLoadList := TStringList.Create;
FDataBinding := GetDataBindingClass.Create(Self, Self);
FDataBinding.OnDataChange := Self.DataChange;
FDataBinding.OnDataSetChange := Self.DataSetChange;
FDataBinding.OnUpdateData := Self.UpdateData;
FInnerPanel := TcxMCInnerPanel.Create(Self);
FInnerPanel.Parent := Self;
FInnerPanel.Align := alClient;
FInnerPanel.LookAndFeel.MasterLookAndFeel := Style.LookAndFeel;
FInnerHeader := TcxMCInnerHeader.Create(FInnerPanel);
InnerControl := FInnerPanel;
FInnerHeader.Color := clBtnFace;
FInnerHeader.ParentFont := True;
FInnerHeader.Parent := FInnerPanel;
FInnerHeader.FContainer := Self;
FInnerHeader.LookAndFeel.MasterLookAndFeel := Style.LookAndFeel;
FInnerHeader.OnSectionEndResize := SectionEndResizeHandler;
FInnerHeader.OnSectionTrack := SectionTrackHandler;
FInnerHeader.OnSectionsChange := SectionsChangeHandler;
FInnerHeader.OnSectionChangedSortOrder := SectionSortChangedHandler;
FInnerHeader.OnSectionEndDrag := SectionEndDragHandler;
FInnerHeader.AllowSort := True;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?