📄 suilistview.pas
字号:
W := R.Right - R.Left - 6;
if (imgList <> nil) and (Cur.ImageIndex > -1) then
begin
Left := W - Canvas.TextWidth(Cur.Caption) - imgList.Width - 2;
if Left < 4 then
Left := 4;
Left := R.Left + Left;
imgList.Draw(Canvas, Left, Top, Cur.ImageIndex);
Inc(Left, imgList.Width + 2);
end
else
begin
Left := W - Canvas.TextWidth(Cur.Caption) - 2;
if Left < 4 then
Left := 4;
Left := R.Left + Left;
end;
end
else
begin
W := R.Right - R.Left - 6;
if (imgList <> nil) and (Cur.ImageIndex > -1) then
begin
Left := (W - Canvas.TextWidth(Cur.Caption) - imgList.Width - 2) div 2;
if Left < 4 then
Left := 4;
Left := R.Left + Left;
imgList.Draw(Canvas, Left, Top, Cur.ImageIndex);
Inc(Left, imgList.Width + 2);
end
else
begin
Left := (W - Canvas.TextWidth(Cur.Caption) - 2) div 2;
if Left < 4 then
Left := 4;
Left := R.Left + Left;
end;
end;
W := R.Right - Left - 2;
Cap := FormatStringWithWidth(Canvas, Cur.Caption, W);
TR := Rect(Left, R.Top, R.Right - 2, R.Bottom);
DrawText(Canvas.Handle, PChar(Cap), -1, TR, DT_LEFT or DT_SINGLELINE or DT_VCENTER);
// draw separate line
Canvas.Pen.Color := m_BorderColor;
if R.Right = L + 1 then
begin
Canvas.MoveTo(R.Right - 2, R.Top);
Canvas.LineTo(R.Right - 2, R.Bottom);
end;
L := R.Right - 1;
Canvas.MoveTo(L, R.Top);
Canvas.LineTo(L, R.Bottom);
end;
if R.Right < HR.Right then
begin
Canvas.Brush.Color := m_HeaderColor;
R.Left := R.Right;
R.Right := HR.Right;
Canvas.FillRect(R);
end;
Canvas.MoveTo(HR.Left, HR.Bottom - 1);
Canvas.LineTo(R.Right, HR.Bottom - 1);
ReleaseDC(m_Header, Canvas.Handle);
Canvas.Free();
end;
procedure TsuiListView.SetBorderColor(const Value: TColor);
begin
m_BorderColor := Value;
Repaint();
end;
procedure TsuiListView.SetFileTheme(const Value: TsuiFileTheme);
begin
m_FileTheme := Value;
SetUIStyle(m_UIStyle);
end;
procedure TsuiListView.SetHScrollBar(const Value: TsuiScrollBar);
begin
if m_HScrollBar = Value then
Exit;
if m_HScrollBar <> nil then
begin
m_HScrollBar.OnChange := nil;
m_HScrollBar.LineButton := 0;
m_HScrollBar.Max := 100;
m_HScrollBar.Enabled := true;
end;
m_HScrollBar := Value;
if m_HScrollBar = nil then
Exit;
m_HScrollBar.SmallChange := 5;
m_HScrollBar.Orientation := suiHorizontal;
m_HScrollBar.OnChange := OnHScrollBArChange;
m_HScrollBar.BringToFront();
UpdateScrollBarsPos();
end;
procedure TsuiListView.SetUIStyle(const Value: TsuiUIStyle);
var
OutUIStyle : TsuiUIStyle;
begin
m_UIStyle := Value;
if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
begin
m_BorderColor := m_FileTheme.GetColor(SKIN2_CONTROLBORDERCOLOR);
m_HeaderFontColor := m_FileTheme.GetColor(SKIN2_CONTROLFONTCOLOR);
m_HeaderColor := m_FileTheme.GetColor(SKIN2_FORMCOLOR);
end
else
begin
m_BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BORDER_COLOR);
m_HeaderFontColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_FONT_COLOR);
m_HeaderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_FORM_BACKGROUND_COLOR);
end;
if m_VScrollBar <> nil then
m_VScrollBar.UIStyle := OutUIStyle;
if m_HScrollBar <> nil then
m_HScrollBar.UIStyle := OutUIStyle;
Repaint();
end;
procedure TsuiListView.SetVScrollBar(const Value: TsuiScrollBar);
begin
if m_VScrollBar = Value then
Exit;
if m_VScrollBar <> nil then
begin
m_VScrollBar.OnChange := nil;
m_VScrollBar.LineButton := 0;
m_VScrollBar.Max := 100;
m_VScrollBar.Enabled := true;
end;
m_VScrollBar := Value;
if m_VScrollBar = nil then
Exit;
m_VScrollBar.SmallChange := 5;
m_VScrollBar.Orientation := suiVertical;
m_VScrollBar.OnChange := OnVScrollBArChange;
m_VScrollBar.BringToFront();
UpdateScrollBarsPos();
end;
procedure TsuiListView.UpdateScrollBars;
var
info : tagScrollInfo;
barinfo : tagScrollBarInfo;
R : Boolean;
begin
if csLoading in ComponentState then
Exit;
m_SelfChanging := true;
if m_VScrollBar <> nil then
begin
barinfo.cbSize := SizeOf(barinfo);
R := SUIGetScrollBarInfo(Handle, Integer(OBJID_VSCROLL), barinfo);
if (barinfo.rgstate[0] = STATE_SYSTEM_INVISIBLE) or
(barinfo.rgstate[0] = STATE_SYSTEM_UNAVAILABLE) or
(not R) then
begin
m_VScrollBar.LineButton := 0;
m_VScrollBar.Enabled := false;
m_VScrollBar.Visible := false;
end
else if not Enabled then
m_VScrollBar.Enabled := false
else
begin
m_VScrollBar.LineButton := abs(barinfo.xyThumbBottom - barinfo.xyThumbTop);
m_VScrollBar.Enabled := true;
m_VScrollBar.Visible := true;
end;
info.cbSize := SizeOf(info);
info.fMask := SIF_ALL;
GetScrollInfo(Handle, SB_VERT, info);
m_VScrollBar.Max := info.nMax - Integer(info.nPage) + 1;
m_VScrollBar.Min := info.nMin;
m_VScrollBar.Position := info.nPos;
end;
if m_HScrollBar <> nil then
begin
barinfo.cbSize := SizeOf(barinfo);
R := SUIGetScrollBarInfo(Handle, Integer(OBJID_HSCROLL), barinfo);
if (barinfo.rgstate[0] = STATE_SYSTEM_INVISIBLE) or
(barinfo.rgstate[0] = STATE_SYSTEM_UNAVAILABLE) or
(not R) then
begin
m_HScrollBar.LineButton := 0;
m_HScrollBar.Enabled := false;
m_HScrollBar.Visible := false;
end
else if not Enabled then
m_HScrollBar.Enabled := false
else
begin
m_HScrollBar.LineButton := abs(barinfo.xyThumbBottom - barinfo.xyThumbTop);
m_HScrollBar.Enabled := true;
m_HScrollBar.Visible := true;
end;
info.cbSize := SizeOf(info);
info.fMask := SIF_ALL;
GetScrollInfo(Handle, SB_HORZ, info);
m_HScrollBar.Max := info.nMax - Integer(info.nPage) + 1;
m_HScrollBar.Min := info.nMin;
m_HScrollBar.Position := info.nPos;
end;
m_SelfChanging := false;
end;
procedure TsuiListView.UpdateScrollBarsPos;
var
L2R : Boolean;
begin
inherited;
if csLoading in ComponentState then
Exit;
L2R := ((BidiMode = bdLeftToRight) or (BidiMode = bdRightToLeftReadingOnly)) or (not SysLocale.MiddleEast);
if m_HScrollBar <> nil then
begin
if m_HScrollBar.Height > Height then
m_HScrollBar.Top := Top
else
begin
if L2R then
begin
m_HScrollBar.Left := Left + 1;
m_HScrollBar.Top := Top + Height - m_HScrollBar.Height - 2;
if m_VScrollBar <> nil then
begin
if m_VScrollBar.Visible then
m_HScrollBar.Width := Width - 2 - m_VScrollBar.Width
else
m_HScrollBar.Width := Width - 2
end
else
m_HScrollBar.Width := Width - 2
end
else
begin
m_HScrollBar.Top := Top + Height - m_HScrollBar.Height - 2;
if m_VScrollBar <> nil then
begin
m_HScrollBar.Left := Left + m_VScrollBar.Width + 1;
if m_VScrollBar.Visible then
m_HScrollBar.Width := Width - 2 - m_VScrollBar.Width
else
m_HScrollBar.Width := Width - 2
end
else
begin
m_HScrollBar.Left := Left + 1;
m_HScrollBar.Width := Width - 2;
end;
end;
end;
end;
if m_VScrollBar <> nil then
begin
if m_VScrollBar.Width > Width then
m_VScrollBar.Left := Left
else
begin
if L2R then
begin
m_VScrollBar.Left := Left + Width - m_VScrollBar.Width - 2;
m_VScrollBar.Top := Top + 1;
if m_HScrollBar <> nil then
begin
if m_HScrollBar.Visible then
m_VScrollBar.Height := Height - 2 - m_HScrollBar.Height
else
m_VScrollBar.Height := Height - 2;
end
else
m_VScrollBar.Height := Height - 2;
end
else
begin
m_VScrollBar.Left := Left + 2;
m_VScrollBar.Top := Top + 1;
if m_HScrollBar <> nil then
begin
if m_HScrollBar.Visible then
m_VScrollBar.Height := Height - 2 - m_HScrollBar.Height
else
m_VScrollBar.Height := Height - 2;
end
else
m_VScrollBar.Height := Height - 2;
end;
end;
end;
UpdateScrollBars();
end;
procedure TsuiListView.WMDELETEITEM(var Msg: TMessage);
begin
inherited;
UpdateScrollBars();
end;
procedure TsuiListView.WMEARSEBKGND(var Msg: TMessage);
begin
inherited;
DrawControlBorder(self, m_BorderColor, Color);
end;
procedure TsuiListView.WMHSCROLL(var Message: TWMHScroll);
begin
inherited;
UpdateScrollBars();
end;
procedure TsuiListView.WMKeyDown(var Message: TWMKeyDown);
begin
inherited;
UpdateScrollBars();
end;
procedure TsuiListView.WMLBUTTONDOWN(var Message: TMessage);
begin
inherited;
m_MouseDown := true;
UpdateScrollBars();
end;
procedure TsuiListView.WMLButtonUp(var Message: TMessage);
begin
inherited;
m_MouseDown := false;
end;
procedure TsuiListView.WMMOUSEMOVE(var Message: TMessage);
begin
inherited;
if m_MouseDown then UpdateScrollBars();
end;
procedure TsuiListView.WMMOUSEWHEEL(var Message: TMessage);
begin
inherited;
UpdateScrollBars();
end;
procedure TsuiListView.WMMOVE(var Msg: TMessage);
begin
inherited;
UpdateScrollBarsPos();
end;
procedure TsuiListView.WMPAINT(var Msg: TMessage);
begin
inherited;
DrawControlBorder(self, m_BorderColor, Color);
end;
procedure TsuiListView.WMSETREDRAW(var Msg: TMessage);
begin
inherited;
if Boolean(Msg.WParam) and (Items.Count = 0) then
AlphaSort();
end;
procedure TsuiListView.WMSIZE(var Msg: TMessage);
begin
UpdateScrollBarsPos();
inherited;
UpdateScrollBarsPos();
end;
procedure TsuiListView.WMVSCROLL(var Message: TWMVScroll);
begin
inherited;
UpdateScrollBars();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -