?? gridseh.pas
字號:
begin
inherited DefineProperties(Filer);
if FSaveCellExtents then
with Filer do
begin
DefineProperty('ColWidths', ReadColWidths, WriteColWidths, DoColWidths);
DefineProperty('RowHeights', ReadRowHeights, WriteRowHeights, DoRowHeights);
end;
end;
procedure TCustomGridEh.MoveColumn(FromIndex, ToIndex: Longint);
var
Rect: TGridRect;
InvalidRect: TRect;
DrawInfo: TGridDrawInfoEh;
begin
if FromIndex = ToIndex then Exit;
if Length(FColWidths) > 0 then
begin
MoveExtent(FColWidths, FromIndex + 1, ToIndex + 1);
MoveExtent(FTabStops, FromIndex + 1, ToIndex + 1);
end;
MoveAdjust(FCurrent.X, FromIndex, ToIndex);
MoveAdjust(FAnchor.X, FromIndex, ToIndex);
MoveAdjust(FInplaceCol, FromIndex, ToIndex);
Rect.Top := 0;
CalcDrawInfo(DrawInfo);
Rect.Bottom := DrawInfo.Vert.LastFullVisibleCell - TopRow + 1;//VisibleRowCount;
if FromIndex < ToIndex then
begin
Rect.Left := FromIndex;
Rect.Right := ToIndex;
end
else
begin
Rect.Left := ToIndex;
Rect.Right := FromIndex;
end;
//ddd InvalidateRect(Rect);
if HandleAllocated then
begin
GridRectToScreenRect(Rect, InvalidRect, True);
InvalidRect.Bottom := DrawInfo.Vert.FullGridExtent;
WindowsInvalidateRect(Handle, InvalidRect, False);
end;
ColumnMoved(FromIndex, ToIndex);
if Length(FColWidths) > 0 then
ColWidthsChanged;
UpdateEdit;
end;
procedure TCustomGridEh.ColumnMoved(FromIndex, ToIndex: Longint);
begin
end;
procedure TCustomGridEh.MoveRow(FromIndex, ToIndex: Longint);
var
Rect: TGridRect;
InvalidRect: TRect;
DrawInfo: TGridDrawInfoEh;
begin
if Length(FRowHeights) <> 0 then
MoveExtent(FRowHeights, FromIndex + 1, ToIndex + 1);
MoveAdjust(FCurrent.Y, FromIndex, ToIndex);
MoveAdjust(FAnchor.Y, FromIndex, ToIndex);
MoveAdjust(FInplaceRow, FromIndex, ToIndex);
Rect.Left := 0;
CalcDrawInfo(DrawInfo);
Rect.Right := DrawInfo.Horz.LastFullVisibleCell - LeftCol + 1;
if FromIndex < ToIndex then
begin
Rect.Top := FromIndex;
Rect.Bottom := ToIndex;
end
else
begin
Rect.Top := ToIndex;
Rect.Bottom := FromIndex;
end;
if HandleAllocated then
begin
GridRectToScreenRect(Rect, InvalidRect, True);
InvalidRect.Right := DrawInfo.Horz.FullGridExtent;
WindowsInvalidateRect(Handle, InvalidRect, False);
end;
RowMoved(FromIndex, ToIndex);
if Length(FRowHeights) <> 0 then
RowHeightsChanged;
UpdateEdit;
end;
procedure TCustomGridEh.RowMoved(FromIndex, ToIndex: Longint);
begin
end;
function TCustomGridEh.MouseCoord(X, Y: Integer): TGridCoord;
var
DrawInfo: TGridDrawInfoEh;
begin
CalcDrawInfo(DrawInfo);
Result := CalcCoordFromPoint(X, Y, DrawInfo);
if Result.X < 0 then Result.Y := -1
else if Result.Y < 0 then Result.X := -1;
end;
procedure TCustomGridEh.MoveColRow(ACol, ARow: Longint; MoveAnchor,
Show: Boolean);
begin
MoveCurrent(ACol, ARow, MoveAnchor, Show);
end;
function TCustomGridEh.SelectCell(ACol, ARow: Longint): Boolean;
begin
Result := True;
end;
procedure TCustomGridEh.SizeChanged(OldColCount, OldRowCount: Longint);
begin
end;
function TCustomGridEh.Sizing(X, Y: Integer): Boolean;
var
DrawInfo: TGridDrawInfoEh;
State: TGridState;
Index: Longint;
Pos, Ofs: Integer;
begin
State := FGridState;
if State = gsNormal then
begin
CalcDrawInfo(DrawInfo);
CalcSizingState(X, Y, State, Index, Pos, Ofs, DrawInfo);
end;
Result := State <> gsNormal;
end;
procedure TCustomGridEh.TopLeftChanged;
begin
if FEditorMode and (FInplaceEdit <> nil)
then FInplaceEdit.UpdateLoc(CellRect(Col, Row));
end;
(*
procedure FillDWord(var Dest; Count, Value: Integer); register;
asm
XCHG EDX, ECX
PUSH EDI
MOV EDI, EAX
MOV EAX, EDX
REP STOSD
POP EDI
end;
{ StackAlloc allocates a 'small' block of memory from the stack by
decrementing SP. This provides the allocation speed of a local variable,
but the runtime size flexibility of heap allocated memory. }
function StackAlloc(Size: Integer): Pointer; register;
asm
POP ECX { return address }
MOV EDX, ESP
ADD EAX, 3
AND EAX, not 3 // round up to keep ESP dword aligned
CMP EAX, 4092
JLE @@2
@@1:
SUB ESP, 4092
PUSH EAX { make sure we touch guard page, to grow stack }
SUB EAX, 4096
JNS @@1
ADD EAX, 4096
@@2:
SUB ESP, EAX
MOV EAX, ESP { function result = low memory address of block }
PUSH EDX { save original SP, for cleanup }
MOV EDX, ESP
SUB EDX, 4
PUSH EDX { save current SP, for sanity check (sp = [sp]) }
PUSH ECX { return to caller }
end;
{ StackFree pops the memory allocated by StackAlloc off the stack.
- Calling StackFree is optional - SP will be restored when the calling routine
exits, but it's a good idea to free the stack allocated memory ASAP anyway.
- StackFree must be called in the same stack context as StackAlloc - not in
a subroutine or finally block.
- Multiple StackFree calls must occur in reverse order of their corresponding
StackAlloc calls.
- Built-in sanity checks guarantee that an improper call to StackFree will not
corrupt the stack. Worst case is that the stack block is not released until
the calling routine exits. }
procedure StackFree(P: Pointer); register;
asm
POP ECX { return address }
MOV EDX, DWORD PTR [ESP]
SUB EAX, 8
CMP EDX, ESP { sanity check #1 (SP = [SP]) }
JNE @@1
CMP EDX, EAX { sanity check #2 (P = this stack block) }
JNE @@1
MOV ESP, DWORD PTR [ESP+4] { restore previous SP }
@@1:
PUSH ECX { return to caller }
end;
*)
procedure TCustomGridEh.DrawLines(DrawInfo: TGridDrawInfoEh; DoHorz, DoVert: Boolean;
Col, Row: Longint; const CellBounds: array of Integer; OnColor, OffColor: TColor;
Canvas: TCanvas; DrawLinesInfo: TDrawLinesInfoEh);
{ Cellbounds is 4 integers: StartX, StartY, StopX, StopY
Horizontal lines: MajorIndex = 0
Vertical lines: MajorIndex = 1 }
const
FlatPenStyle = PS_Geometric or PS_Solid or PS_EndCap_Flat or PS_Join_Miter;
procedure DrawAxisLines(const AxisInfo: TGridAxisDrawInfoEh;
Cell, MajorIndex: Integer; UseOnColor: Boolean; LastCell: Longint);
var
Line: Integer;
LogBrush: TLOGBRUSH;
Index: Integer;
Points: TPointArray;
StopMajor, StartMinor, StopMinor, StopIndex: Integer;
LineIncr: Integer;
begin
Points := nil;
with Canvas, AxisInfo do
begin
if EffectiveLineWidth <> 0 then
begin
Pen.Width := GridLineWidth;
if UseOnColor then
Pen.Color := OnColor
else
Pen.Color := OffColor;
if Pen.Width > 1 then
begin
LogBrush.lbStyle := BS_Solid;
LogBrush.lbColor := Pen.Color;
LogBrush.lbHatch := 0;
Pen.Handle := ExtCreatePen(FlatPenStyle, Pen.Width, LogBrush, 0, nil);
end;
Points := DrawLinesInfo.PointsList;
Line := CellBounds[MajorIndex] + EffectiveLineWidth shr 1 +
AxisInfo.GetExtent(Cell);
//!!! ??? Line needs to be incremented for RightToLeftAlignment ???
// Fix in DrawPolyPolyline if UseRightToLeftAlignment and (MajorIndex = 0) then Inc(Line);
StartMinor := CellBounds[MajorIndex xor 1];
StopMinor := CellBounds[2 + (MajorIndex xor 1)];
StopMajor := CellBounds[2 + MajorIndex] + EffectiveLineWidth;
StopIndex := DrawLinesInfo.MaxStroke * 2;
Index := 0;
repeat
if MajorIndex <> 0 then
begin
Points[Index].Y := Line;
Points[Index].X := StartMinor;
end else
begin
Points[Index].X := Line;
Points[Index].Y := StartMinor;
end;
Inc(Index);
if MajorIndex <> 0 then
begin
Points[Index].Y := Line;
Points[Index].X := StopMinor;
end else
begin
Points[Index].X := Line;
Points[Index].Y := StopMinor;
end;
Inc(Index);
// Skip hidden columns/rows. We don't have stroke slots for them
// A column/row with an extent of -EffectiveLineWidth is hidden
repeat
Inc(Cell);
LineIncr := AxisInfo.GetExtent(Cell) + EffectiveLineWidth;
until (LineIncr > 0) or (Cell > LastCell);
Inc(Line, LineIncr);
until (Line > StopMajor) or (Cell > LastCell) or (Index > StopIndex);
// until (Line > StopMajor) or (Cell > LastCell) or (Index > StopIndex);
{ 2 integers per point, 2 points per line -> Index div 4 }
(*{$IFDEF CIL}
PolyPolyLine(Canvas.Handle, Points, DrawLinesInfo.StrokeList, Index shr 1);
{$ELSE}
PolyPolyLine(Canvas.Handle, Pointer(Points)^, Pointer(DrawLinesInfo.StrokeList)^, Index shr 1);
{$ENDIF}*)
DrawPolyPolyline(Points, DrawLinesInfo.StrokeList, Index);
end;
end;
end;
begin
if (CellBounds[0] = CellBounds[2]) or (CellBounds[1] = CellBounds[3]) then
Exit;
if not DoHorz then
begin
DrawAxisLines(DrawInfo.Vert, Row, 1, DoHorz, DrawLinesInfo.LastRow);
DrawAxisLines(DrawInfo.Horz, Col, 0, DoVert, DrawLinesInfo.LastCol);
end
else
begin
DrawAxisLines(DrawInfo.Horz, Col, 0, DoVert, DrawLinesInfo.LastCol);
DrawAxisLines(DrawInfo.Vert, Row, 1, DoHorz, DrawLinesInfo.LastRow);
end;
end;
procedure TCustomGridEh.Paint;
var
// LineColor: TColor;
DrawInfo: TGridDrawInfoEh;
Sel: TGridRect;
UpdateRect: TRect;
AFocRect, FocRect: TRect;
PointsList: TPointArray;
StrokeList: TDWORDArray;
MaxStroke: Integer;
FrameFlags1, FrameFlags2: DWORD;
procedure DrawCells(ACol, ARow: Longint; StartX, StartY, StopX, StopY: Integer;
Color: TColor; IncludeDrawState: TGridDrawState);
var
CurCol, CurRow: Longint;
AWhere, Where, TempRect: TRect;
DrawState: TGridDrawState;
Focused: Boolean;
begin
CurRow := ARow;
Where.Top := StartY;
while (Where.Top < StopY) and (CurRow < RowCount) do
begin
CurCol := ACol;
Where.Left := StartX;
Where.Bottom := Where.Top + RowHeights[CurRow];
while (Where.Left < StopX) and (CurCol < ColCount) do
begin
Where.Right := Where.Left + ColWidths[CurCol];
if (Where.Right > Where.Left) and RectVisible(Canvas.Handle, Where) then
begin
DrawState := IncludeDrawState;
Focused := IsActiveControl;
if Focused and (CurRow = Row) and (CurCol = Col) then
Include(DrawState, gdFocused);
if PointInGridRect(CurCol, CurRow, Sel) then
Include(DrawState, gdSelected);
if not (gdFocused in DrawState) or not (goEditing in Options) or
not FEditorMode or (csDesigning in ComponentState) then
begin
if DefaultDrawing or (csDesigning in ComponentState) then
with Canvas do
begin
Font := Self.Font;
if (gdSelected in DrawState) and
(not (gdFocused in DrawState) or
([goDrawFocusSelected, goRowSelect] * Options <> [])) then
begin
Brush.Color := clHighlight;
Font.Color := clHighlightText;
end
else
Brush.Color := Color;
FillRect(Where);
end;
DrawCell(CurCol, CurRow, Where, DrawState);
if DefaultDrawing and (gdFixed in DrawState) and Ctl3D and
((FrameFlags1 or FrameFlags2) <> 0) then
begin
TempRect := Where;
if (FrameFlags1 and BF_RIGHT) = 0 then
Inc(TempRect.Right, DrawInfo.Horz.EffectiveLineWidth)
else if (FrameFlags1 and BF_BOTTOM) = 0 then
Inc(TempRect.Bottom, DrawInfo.Vert.EffectiveLineWidth);
DrawEdgeEh(Canvas, TempRect, False, False, True, True);
DrawEdgeEh(Canvas, TempRect, False, False, True, True);
end;
if DefaultDrawi
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -