📄 wzgrid.pas
字号:
if RestoreCanvas then begin
ReleaseDC(0,Canvas.Handle);
Canvas.Handle := 0;
end;
end;
UpdateRowCount;
//SetColumnAttributes;
Invalidate;
end;
procedure TWzGrid.SetOptions(Value: TDBGridOptions);
const
LayoutOptions = [dgEditing, dgAlwaysShowEditor, dgTitles, dgIndicator,
dgColLines, dgRowLines, dgRowSelect, dgAlwaysShowSelection];
var
NewGridOptions: TGridOptions;
ChangedOptions: TDBGridOptions;
begin
if FOptions <> Value then
begin
NewGridOptions := [];
if dgColLines in Value then
NewGridOptions := NewGridOptions + [goFixedVertLine, goVertLine];
if dgRowLines in Value then
NewGridOptions := NewGridOptions + [goFixedHorzLine, goHorzLine];
if dgColumnResize in Value then
NewGridOptions := NewGridOptions + [goColSizing];
if dgTabs in Value then Include(NewGridOptions, goTabs);
if dgColumnMove in Value then
NewGridOptions := NewGridOptions + [goColMoving];
if dgRowMove in Value then
NewGridOptions := NewGridOptions + [goRowMoving];
if dgRowSelect in Value then
begin
Include(NewGridOptions, goRowSelect);
Exclude(Value, dgAlwaysShowEditor);
Exclude(Value, dgEditing);
end;
if dgEditing in Value then Include(NewGridOptions, goEditing);
if dgAlwaysShowEditor in Value then Include(NewGridOptions, goAlwaysShowEditor);
inherited Options := NewGridOptions;
ChangedOptions := (FOptions + Value) - (FOptions * Value);
FOptions := Value;
if ChangedOptions * LayoutOptions <> [] then LayoutChanged;
end;
end;
procedure TWzGrid.SetColumnAttributes;
var
I : integer;
W,OldW : Integer;
begin
BeginLayOut;
try
for I := 0 to FColumns.Count-1 do begin
with FColumns[I] do begin
TabStops[I+FIndicatorOffset] := not ReadOnly;
Canvas.Font := Font;
W := Width * Canvas.TextWidth( '0' ) + 4;
ColWidths[I+FIndicatorOffset] := W;
end;
end;
if (dgIndicator in Options) then begin
{ if FMesaiGrid then begin
if not FLineNub then ColWidths[0] := IndicatorWidth;
else begin}
W := Canvas.TextWidth( IntToStr( RowCount-FTitleOffset+1 ) ) + 8;
ColWidths[0] := W;
{ end;
end else begin}
{ OldW := 0;
for I := 0 to FLineName.Count-1 do begin
W := Canvas.TextWidth(FLineName.Strings[i]) + 5;
if W > OldW then OldW := W;
end;
ColWidths[0] := OldW;}
// end;
end;
finally
EndLayOut;
end;
end;
procedure TWzGrid.UpdateRowCount;
var
i : integer;
begin
{ RowCount := RecordCount + FTitleOffset;
if RowCount <= FTitleOffset then RowCount := FTitleOffset+1;
FixedRows := FTitleOffset;}
end;
function TWzGrid.DataToRawColumn(ACol: Integer): Integer;
begin
Result := ACol + FIndicatorOffset;
end;
function TWzGrid.AcquireLayoutLock: Boolean;
begin
Result := (FUpdateLock = 0) and (FLayoutLock = 0);
if Result then BeginLayout;
end;
procedure TWzGrid.Loaded;
begin
inherited Loaded;
if FColumns.Count > 0 then
ColCount := FColumns.Count;// + FIndicatorOffset;
LayoutChanged;
end;
procedure TWzGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var
OldActive: Integer;
Highlight: Boolean;
Value: string;
DrawColumn: TColumn;
FrameOffs: Byte;
OldRow,OldCol: Longint;
begin
if csLoading in ComponentState then begin
Canvas.Brush.Color := Color;
Canvas.FillRect(ARect);
Exit;
end;
OldRow := ARow;
OldCol := ACol;
Dec(ARow, FTitleOffset);
Dec(ACol, FIndicatorOffset);
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
Canvas.Brush.Color := FixedColor;
Canvas.FillRect(ARect);
//Canvas.Font := TitleFont;
// if ARow < 0 then Canvas.Font.Color := TitleFont.Color else Canvas.Font.Color := FVTitleColor;
Canvas.Font.Size := Font.Size;
// if FMesaiGrid then begin
// if not FLineNub then begin
// if (ARow = SelectedRow) and ( not (csDesigning in ComponentState) ) then begin
// FIndicators.BkColor := FixedColor;
// FIndicators.Draw(Canvas, ARect.Right - FIndicators.Width - FrameOffs,
// (ARect.Top + ARect.Bottom - FIndicators.Height) shr 1, 0 );
// end;
//FSelRow := ARow + FTitleOffset;
// end else begin
if ( ARow >= 0 ) then begin
WriteText(Canvas, ARect, FrameOffs, FrameOffs,
IntToStr(ARow+1), taRightJustify{ taLeftJustify} )
end;
// end;
// end else begin
{ if ( FLineName.Count <> 0 )
and ( ( ARow + FTitleOffset ) <= FLineName.Count-1 ) then begin
if ARow + FTitleOffset = 0 then begin
WriteText(Canvas, ARect, FrameOffs, FrameOffs,
FLineName.strings[ARow + FTitleOffset], taCenter )
end else
WriteText(Canvas, ARect, FrameOffs, FrameOffs,
FLineName.strings[ARow + FTitleOffset], taLeftJustify );
end;}
// end;
end else begin
with Canvas do begin
DrawColumn := Columns[ACol];
if gdFixed in AState then begin
// Font := DrawColumn.Title.Font;
Brush.Color := DrawColumn.Title.Color;
end else begin
// Font := DrawColumn.Font;
Brush.Color := DrawColumn.Color;
end;
if ARow < 0 then
with DrawColumn.Title do
WriteText(Canvas, ARect, FrameOffs, FrameOffs, Caption, Alignment)
else begin
Value := '';
Value := Cells[OldCol,OldRow];
if Assigned( OnSetData ) then
OnSetData( Self,DrawColumn.OrgIndex,ARow,Value );
Highlight := HighlightCell(ACol, ARow, Value, AState);
{ Highlight := False;
// Highlight := True;}
if Highlight then begin
Brush.Color := clHighlight;
Font.Color := clHighlightText;
{ if DrawColumn.AutoSelect then
ShowEditor
else begin
EditorMode := TRUE;
InplaceEditor.SelStart := 0;
InplaceEditor.SelLength:= 1;
end;}
end;
if FDefaultDrawing then
// WriteText(Canvas, ARect, 2, 2, Value, DrawColumn.Alignment);
DefaultDrawColumnCell(ARect, Value, DrawColumn, AState);
{if Columns.State = csDefault then
DrawDataCell(ARect, DrawColumn.Field, AState);}
// DrawColumnCell(ARect, ACol, DrawColumn, AState);
if FDefaultDrawing
and ( gdSelected in AState )
and ( (dgAlwaysShowSelection in Options) or Focused )
and not (csDesigning in ComponentState)
and not (dgRowSelect in Options)
and (UpdateLock = 0)
and (ValidParentForm(Self).ActiveControl = Self) then
Windows.DrawFocusRect(Handle, ARect);
end;
end;
end;
if (gdFixed in AState) and ([dgRowLines, dgColLines] * Options =
[dgRowLines, dgColLines]) then begin
InflateRect(ARect, 1, 1);
DrawEdge(Canvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
DrawEdge(Canvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
end;
// inherited DrawCell(OldCol, OldRow, ARect, AState);
end;
function TWzGrid.HighlightCell(DataCol, DataRow: Integer;
const Value: string; AState: TGridDrawState): Boolean;
begin
Result := False;
if not Result then
Result := (gdSelected in AState)
and ((dgAlwaysShowSelection in Options) or Focused)
and ((UpdateLock = 0) or (dgRowSelect in Options));
//Result := True;
end;
procedure WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: Integer;
const Text: string; Alignment: TAlignment);
const
AlignFlags : array [TAlignment] of Integer =
( DT_LEFT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX,
DT_RIGHT or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX,
DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX );
var
B, R: TRect;
I, Left: Integer;
begin
I := ColorToRGB(ACanvas.Brush.Color);
if GetNearestColor(ACanvas.Handle, I) = I then begin
case Alignment of
taLeftJustify : Left := ARect.Left + DX;
taRightJustify : Left := ARect.Right - ACanvas.TextWidth(Text) - 3;
else
Left := ARect.Left + (ARect.Right - ARect.Left) shr 1
- (ACanvas.TextWidth(Text) shr 1);
end;
ExtTextOut(ACanvas.Handle, Left, ARect.Top + DY, ETO_OPAQUE or
ETO_CLIPPED, @ARect, PChar(Text), Length(Text), nil);
end else begin
{ with DrawBitmap, ARect do begin
Width := Max(Width, Right - Left);
Height := Max(Height, Bottom - Top);
R := Rect(DX, DY, Right - Left - 1, Bottom - Top - 1);
B := Rect(0, 0, Right - Left, Bottom - Top);
end;
with DrawBitmap.Canvas do begin
Font := ACanvas.Font;
Font.Color := ACanvas.Font.Color;
Brush := ACanvas.Brush;
Brush.Style := bsSolid;
FillRect(B);
SetBkMode(Handle, TRANSPARENT);
DrawText(Handle, PChar(Text), Length(Text), R, AlignFlags[Alignment]);
end;
ACanvas.CopyRect(ARect, DrawBitmap.Canvas, B);}
end;
end;
//
//
//
constructor TColumnTitle.Create(Column: TColumn);
begin
inherited Create;
FColumn := Column;
end;
destructor TColumnTitle.Destroy;
begin
inherited Destroy;
end;
function TColumnTitle.GetCaption: string;
begin
if cvTitleCaption in FColumn.FAssignedValues then
Result := FCaption
else
Result := DefaultCaption;
end;
procedure TColumnTitle.SetCaption(const Value: string);
begin
if (cvTitleCaption in FColumn.FAssignedValues) and (Value = FCaption) then Exit;
FCaption := Value;
Include(Column.FAssignedValues, cvTitleCaption);
Column.Changed(False);
end;
function TColumnTitle.IsCaptionStored: Boolean;
begin
Result := (cvTitleCaption in FColumn.FAssignedValues) and (FCaption <> DefaultCaption);
end;
procedure TColumnTitle.restoredefaults;
var
FontAssigned: Boolean;
begin
FontAssigned := cvTitleFont in FColumn.FAssignedValues;
FColumn.FAssignedValues := FColumn.FAssignedValues - ColumnTitleValues;
FCaption := '';
// RefreshDefaultFont;
FColumn.Changed(FontAssigned);
end;
procedure TColumnTitle.Assign(Source: TPersistent);
begin
if Source is TColumnTitle then
begin
if cvTitleAlignment in TColumnTitle(Source).FColumn.FAssignedValues then
Alignment := TColumnTitle(Source).Alignment;
{ if cvTitleColor in TColumnTitle(Source).FColumn.FAssignedValues then
Color := TColumnTitle(Source).Color;
} if cvTitleCaption in TColumnTitle(Source).FColumn.FAssignedValues then
Caption := TColumnTitle(Source).Caption;
{ if cvTitleFont in TColumnTitle(Source).FColumn.FAssignedValues then
Font := TColumnTitle(Source).Font;
} end
else
inherited Assign(Source);
end;
function TColumnTitle.DefaultCaption: string;
begin
Result := FColumn.FieldName;
end;
function TColumnTitle.DefaultAlignment: TAlignment;
begin
Result := taLeftJustify;
end;
function TColumnTitle.DefaultColor: TColor;
var
Grid: TWzGrid;
begin
Grid := FColumn.GetGrid;
if Assigned(Grid) then
Result := Grid.FixedColor
else
Result := clBtnFace;
end;
function TColumnTitle.GetColor: TColor;
begin
if cvTitleColor in FColumn.FAssignedValues then
Result := FColor
else
Result := DefaultColor;
end;
function TColumnTitle.GetAlignment: TAlignment;
begin
if cvTitleAlignment in FColumn.FAssignedValues then
Result := FAlignment
else
Result := DefaultAlignment;
end;
function TColumnTitle.IsAlignmentStored: Boolean;
begin
Result := (cvTitleAlignment in FColumn.FAssignedValues) and (FAlignment <> DefaultAlignment);
end;
function TColumnTitle.IsColorStored: Boolean;
begin
Result := (cvTitleColor in FColumn.FAssignedValues) and
(FColor <> DefaultColor);
end;
procedure TColumnTitle.SetColor(Value: TColor);
begin
if (cvTitleColor in FColumn.FAssignedValues) and (Value = FColor) then Exit;
FColor := Value;
Include(FColumn.FAssignedValues, cvTitleColor);
FColumn.Changed(False);
end;
procedure TColumnTitle.SetAlignment(Value: TAlignment);
begin
if (cvTitleAlignment in FColumn.FAssignedValues) and (Value = FAlignment) then Exit;
FAlignment := Value;
Include(FColumn.FAssignedValues, cvTitleAlignment);
FColumn.Changed(False);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -