📄 ksskindbgrids.pas
字号:
if Focused then
ThemeState := integer(ETS_SELECTED)
else
ThemeState := integer(ETS_NORMAL);
DrawThemeBackground(Theme, Canvas.Handle, Part, ThemeState, ARect, nil);
CloseThemeData(Theme);
end
else
begin
DrawEdge(Canvas, ARect, clBtnShadow, clBtnHighlight);
InflateRect(ARect, -1, -1);
DrawEdge(Canvas, ARect, cl3DDkShadow, clBtnFace);
FillRect(Canvas, Rect(ARect.Right - 20, ARect.Bottom - 20, ARect.Right, ARect.Bottom), clBtnFace);
end;
end;
end;
procedure TSeSkinDBGrid.WMInvalidateSkinObject(var Msg: TMessage);
begin
Invalidate;
end;
procedure TSeSkinDBGrid.WMBeforeChange(var Msg: TMessage);
begin
if Pointer(Msg.LParam) = nil then Exit;
if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;
if FSkinGrid <> nil then FSkinGrid.Free;
FSkinGrid := nil;
end;
procedure TSeSkinDBGrid.WMSkinChange(var Msg: TMessage);
begin
if Pointer(Msg.LParam) = nil then Exit;
if TSeSkinEngine(Msg.LParam) <> FSkinEngine then Exit;
SkinEngine := FSkinEngine;
end;
function TSeSkinDBGrid.GetVersion: TSeSkinVersion;
begin
Result := sSeSkinVersion;
end;
procedure TSeSkinDBGrid.MyDrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var
FrameOffs: Byte;
function RowIsMultiSelected: Boolean;
var
Index: Integer;
begin
Result := (dgMultiSelect in Options) and Datalink.Active and
SelectedRows.Find(Datalink.Datasource.Dataset.Bookmark, Index);
end;
procedure DrawTitleCell(ACol, ARow: Integer; Column: TColumn; var AState: TGridDrawState);
const
ScrollArrows: array [Boolean, Boolean] of Integer =
((DFCS_SCROLLRIGHT, DFCS_SCROLLLEFT), (DFCS_SCROLLLEFT, DFCS_SCROLLRIGHT));
var
MasterCol: TColumn;
TitleRect, TextRect, ButtonRect: TRect;
I: Integer;
InBiDiMode: Boolean;
begin
TitleRect := CalcTitleRect(Column, ARow, MasterCol);
if MasterCol = nil then
begin
Exit;
end;
Canvas.Brush.Style := bsClear;
if [dgRowLines, dgColLines] * Options = [dgRowLines, dgColLines] then
InflateRect(TitleRect, -1, -1);
TextRect := TitleRect;
I := GetSystemMetrics(SM_CXHSCROLL);
if ((TextRect.Right - TextRect.Left) > I) and MasterCol.Expandable then
begin
Dec(TextRect.Right, I);
ButtonRect := TitleRect;
ButtonRect.Left := TextRect.Right;
I := SaveDC(Canvas.Handle);
try
Canvas.FillRect(ButtonRect);
InflateRect(ButtonRect, -1, -1);
IntersectClipRect(Canvas.Handle, ButtonRect.Left,
ButtonRect.Top, ButtonRect.Right, ButtonRect.Bottom);
InflateRect(ButtonRect, 1, 1);
{ DrawFrameControl doesn't draw properly when orienatation has changed.
It draws as ExtTextOut does. }
InBiDiMode := Canvas.CanvasOrientation = coRightToLeft;
if InBiDiMode then { stretch the arrows box }
Inc(ButtonRect.Right, GetSystemMetrics(SM_CXHSCROLL) + 4);
DrawFrameControl(Canvas.Handle, ButtonRect, DFC_SCROLL,
ScrollArrows[InBiDiMode, MasterCol.Expanded] or DFCS_FLAT);
finally
RestoreDC(Canvas.Handle, I);
end;
end;
with MasterCol.Title do
WriteText(Canvas, TextRect, FrameOffs, FrameOffs, Caption, Alignment,
IsRightToLeft);
AState := AState - [gdFixed]; // prevent box drawing later
end;
var
OldActive: Integer;
Indicator: Integer;
Highlight: Boolean;
Value: string;
DrawColumn: TColumn;
MultiSelected: Boolean;
ALeft: Integer;
begin
if csLoading in ComponentState then
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(ARect);
Exit;
end;
Dec(ARow, FTitleOffset);
Dec(ACol, IndicatorOffset);
if (gdFixed in AState) and ([dgRowLines, dgColLines] * Options =
[dgRowLines, dgColLines]) then
begin
InflateRect(ARect, -1, -1);
FrameOffs := 1;
end
else
FrameOffs := 2;
if (gdFixed in AState) and (ACol < 0) then
begin
if Assigned(DataLink) and DataLink.Active then
begin
MultiSelected := False;
if ARow >= 0 then
begin
OldActive := DataLink.ActiveRecord;
try
Datalink.ActiveRecord := ARow;
MultiSelected := RowIsMultiselected;
finally
Datalink.ActiveRecord := OldActive;
end;
end;
if (ARow = DataLink.ActiveRecord) or MultiSelected then
begin
Indicator := 0;
if DataLink.DataSet <> nil then
case DataLink.DataSet.State of
dsEdit: Indicator := 1;
dsInsert: Indicator := 2;
dsBrowse:
if MultiSelected then
if (ARow <> Datalink.ActiveRecord) then
Indicator := 3
else
Indicator := 4; // multiselected and current row
end;
FIndicators.BkColor := FixedColor;
FIndicators.DrawingStyle := dsTransparent;
ALeft := ARect.Right - FIndicators.Width - FrameOffs;
if Canvas.CanvasOrientation = coRightToLeft then Inc(ALeft);
FIndicators.Draw(Canvas, ALeft,
(ARect.Top + ARect.Bottom - FIndicators.Height) shr 1, Indicator, True);
if ARow = Datalink.ActiveRecord then
FSelRow := ARow + FTitleOffset;
end;
end;
end
else
with Canvas do
begin
DrawColumn := Columns[ACol];
if not DrawColumn.Showing then Exit;
if ARow < 0 then
DrawTitleCell(ACol, ARow + FTitleOffset, DrawColumn, AState)
else
if (DataLink = nil) or not DataLink.Active then
{FillRect(ARect)}
else
begin
Value := '';
OldActive := DataLink.ActiveRecord;
try
DataLink.ActiveRecord := ARow;
if Assigned(DrawColumn.Field) then
Value := DrawColumn.Field.DisplayText;
Highlight := HighlightCell(ACol, ARow, Value, AState);
{ Draw text }
Brush.Style := bsClear;
WriteText(Canvas, ARect, 2, 2, Value, DrawColumn.Alignment,
UseRightToLeftAlignmentForField(DrawColumn.Field, DrawColumn.Alignment));
if Columns.State = csDefault then
DrawDataCell(ARect, DrawColumn.Field, AState);
DrawColumnCell(ARect, ACol, DrawColumn, AState);
finally
DataLink.ActiveRecord := OldActive;
end;
end;
end;
end;
procedure TSeSkinDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
var
TempRect: TRect;
DrawState: TSeState;
SkinObject: TSeSkinObject;
begin
if UseSkin then
begin
{ }
DrawState := ssNormal;
if not Enabled then
DrawState := ssDisabled
else
if gdFocused in AState then
DrawState := ssFocused
else
if gdSelected in AState then
DrawState := ssHot;
if gdFixed in AState then
SkinObject := FSkinGrid.FindObjectByName('Fixed')
else
SkinObject := FSkinGrid.FindObjectByName('Cell');
if SkinObject = nil then
SkinObject := FSkinGrid;
SkinObject.State := DrawState;
SkinObject.BoundsRect := ARect;
SkinObject.Draw(Canvas);
Canvas.Font := SkinObject.Font;
MyDrawCell(ACol, ARow, ARect, AState);
end
else
inherited ;
end;
procedure TSeSkinDBGrid.SetSkinEngine(const Value: TSeSkinEngine);
begin
FSkinEngine := Value;
if (FSkinEngine <> nil) and (FSkinEngine.SkinSource <> nil) and
(not FSkinEngine.SkinSource.IsChanging) and
(FSkinEngine.SkinSource.Count > 0) then
begin
if FSkinGrid <> nil then FSkinGrid.Free;
FSkinGrid := nil;
if FSkinEngine.SkinSource.GetObjectByName(FSkinObject) <> nil then
FSkinGrid := FSkinEngine.SkinSource.GetObjectByName(FSkinObject).CreateCopy(nil);
if FSkinGrid <> nil then
begin
DefaultDrawing := false;
FSkinGrid.ParentControl := Self;
Color := FSkinGrid.Color;
end;
end
else
begin
DefaultDrawing := true;
if FSkinGrid <> nil then FSkinGrid.Free;
FSkinGrid := nil;
end;
if SubScrollBars <> nil then
begin
TSeSkinScrollBar(SubScrollBars.HScrollBar.ScrollBar).SkinEngine := Value;
TSeSkinScrollBar(SubScrollBars.VScrollBar.ScrollBar).SkinEngine := Value;
end;
Invalidate;
end;
procedure TSeSkinDBGrid.SetVersion(const Value: TSeSkinVersion);
begin
end;
procedure TSeSkinDBGrid.SetSkinObject(const Value: string);
begin
FSkinObject := Value;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -