📄 rxgrids.pas
字号:
procedure TRxInplaceEdit.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if (Button = mbLeft) and (FEditStyle <> esSimple) and
PtInRect(Rect(Width - FButtonWidth, 0, Width, Height), Point(X,Y)) then
begin
if FListVisible then CloseUp(False)
else begin
MouseCapture := True;
FTracking := True;
TrackButton(X, Y);
if Assigned(FActiveList) then DropDown;
end;
end;
inherited MouseDown(Button, Shift, X, Y);
end;
procedure TRxInplaceEdit.MouseMove(Shift: TShiftState; X, Y: Integer);
var
ListPos: TPoint;
MousePos: TSmallPoint;
begin
if FTracking then begin
TrackButton(X, Y);
if FListVisible then begin
ListPos := FActiveList.ScreenToClient(ClientToScreen(Point(X, Y)));
if PtInRect(FActiveList.ClientRect, ListPos) then begin
StopTracking;
MousePos := PointToSmallPoint(ListPos);
SendMessage(FActiveList.Handle, WM_LBUTTONDOWN, 0, Integer(MousePos));
Exit;
end;
end;
end;
inherited MouseMove(Shift, X, Y);
end;
procedure TRxInplaceEdit.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
WasPressed: Boolean;
begin
WasPressed := FPressed;
StopTracking;
if (Button = mbLeft) and (FEditStyle = esEllipsis) and WasPressed then
TRxDrawGrid(Grid).EditButtonClick;
inherited MouseUp(Button, Shift, X, Y);
end;
procedure TRxInplaceEdit.PaintWindow(DC: HDC);
const
LeftOffs = 3;
var
R: TRect;
Flags: Integer;
W, G, I: Integer;
begin
if FEditStyle <> esSimple then begin
SetRect(R, Width - FButtonWidth, 0, Width, Height);
Flags := 0;
if FEditStyle in [esPickList] then begin
if FActiveList = nil then Flags := DFCS_INACTIVE
else if FPressed then Flags := DFCS_FLAT or DFCS_PUSHED;
DrawFrameControl(DC, R, DFC_SCROLL, Flags or DFCS_SCROLLCOMBOBOX);
end
else begin { esEllipsis }
if FPressed then Flags := BF_FLAT;
DrawEdge(DC, R, EDGE_RAISED, BF_RECT or BF_MIDDLE or Flags);
W := 2;
G := (FButtonWidth - LeftOffs * 2 - 3 * W) div 2;
if G <= 0 then G := 1;
if G > 3 then G := 3;
Flags := R.Left + (FButtonWidth - 3 * W - 2 * G) div 2 + Ord(FPressed);
I := R.Top + (ClientHeight - W) div 2 {+ Ord(FPressed)};
PatBlt(DC, Flags, I, W, W, BLACKNESS);
PatBlt(DC, Flags + G + W, I, W, W, BLACKNESS);
PatBlt(DC, Flags + 2 * G + 2 * W, I, W, W, BLACKNESS);
end;
ExcludeClipRect(DC, R.Left, R.Top, R.Right, R.Bottom);
end;
inherited PaintWindow(DC);
end;
procedure TRxInplaceEdit.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then begin
FAlignment := Value;
RecreateWnd;
end;
end;
procedure TRxInplaceEdit.SetEditStyle(Value: TInplaceEditStyle);
begin
if Value = FEditStyle then Exit;
FEditStyle := Value;
case Value of
esPickList:
begin
if FPickList = nil then begin
FPickList := TPopupListbox.Create(Self);
FPickList.Visible := False;
FPickList.Parent := Self;
FPickList.OnMouseUp := ListMouseUp;
FPickList.IntegralHeight := True;
FPickList.ItemHeight := 11;
end;
FActiveList := FPickList;
end;
else FActiveList := nil;
end;
Repaint;
end;
procedure TRxInplaceEdit.StopTracking;
begin
if FTracking then begin
TrackButton(-1, -1);
FTracking := False;
MouseCapture := False;
end;
end;
procedure TRxInplaceEdit.TrackButton(X,Y: Integer);
var
NewState: Boolean;
R: TRect;
begin
SetRect(R, ClientWidth - FButtonWidth, 0, ClientWidth, ClientHeight);
NewState := PtInRect(R, Point(X, Y));
if FPressed <> NewState then begin
FPressed := NewState;
InvalidateRect(Handle, @R, False);
end;
end;
procedure TRxInplaceEdit.UpdateContents;
var
SaveChanged: TNotifyEvent;
begin
with TRxDrawGrid(Grid) do begin
Self.Alignment := GetEditAlignment(Col, Row);
EditStyle := GetEditStyle(Col, Row);
end;
SaveChanged := Self.OnChange;
try
Self.OnChange := nil;
inherited UpdateContents;
finally
Self.OnChange := SaveChanged;
end;
end;
procedure TRxInplaceEdit.CMCancelMode(var Message: TCMCancelMode);
begin
if (Message.Sender <> Self) and (Message.Sender <> FActiveList) then
CloseUp(False);
end;
procedure TRxInplaceEdit.WMCancelMode(var Message: TMessage);
begin
StopTracking;
inherited;
end;
procedure TRxInplaceEdit.WMKillFocus(var Message: TMessage);
begin
{$IFDEF RX_D3}
if not SysLocale.FarEast then inherited
else begin
ImeName := Screen.DefaultIme;
ImeMode := imDontCare;
inherited;
if THandle(Message.WParam) <> TRxDrawGrid(Grid).Handle then
ActivateKeyboardLayout(Screen.DefaultKbLayout, KLF_ACTIVATE);
end;
{$ELSE}
inherited;
{$ENDIF}
CloseUp(False);
end;
procedure TRxInplaceEdit.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
with Message do
if (FEditStyle <> esSimple) and PtInRect(Rect(Width - FButtonWidth, 0,
Width, Height), Point(XPos, YPos)) then Exit;
inherited;
end;
procedure TRxInplaceEdit.WMPaint(var Message: TWMPaint);
begin
PaintHandler(Message);
end;
procedure TRxInplaceEdit.WMSetCursor(var Message: TWMSetCursor);
var
P: TPoint;
begin
GetCursorPos(P);
if (FEditStyle <> esSimple) and
PtInRect(Rect(Width - FButtonWidth, 0, Width, Height), ScreenToClient(P)) then
Windows.SetCursor(LoadCursor(0, IDC_ARROW))
else inherited;
end;
procedure TRxInplaceEdit.WndProc(var Message: TMessage);
begin
case Message.Msg of
WM_KEYDOWN, WM_SYSKEYDOWN, WM_CHAR:
if EditStyle in [esPickList] then
with TWMKey(Message) do begin
DoDropDownKeys(CharCode, KeyDataToShiftState(KeyData));
if (CharCode <> 0) and FListVisible then begin
with TMessage(Message) do
SendMessage(FActiveList.Handle, Msg, WParam, LParam);
Exit;
end;
end;
end;
inherited;
end;
{$ELSE}
type
TRxInplaceEdit = class(TInplaceEdit);
{$ENDIF WIN32}
{ TRxDrawGrid }
constructor TRxDrawGrid.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
DefaultRowHeight := 18;
Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
goDrawFocusSelected, goColSizing];
FIniLink := TIniLink.Create;
FIniLink.OnSave := IniSave;
FIniLink.OnLoad := IniLoad;
FPressedCell.X := -1;
FPressedCell.Y := -1;
end;
destructor TRxDrawGrid.Destroy;
begin
FOnChangeFocus := nil;
FIniLink.Free;
inherited Destroy;
end;
function TRxDrawGrid.GetStorage: TFormPlacement;
begin
Result := FIniLink.Storage;
end;
procedure TRxDrawGrid.SetStorage(Value: TFormPlacement);
begin
FIniLink.Storage := Value;
end;
procedure TRxDrawGrid.IniSave(Sender: TObject);
begin
if (Name <> '') and (FIniLink.IniObject <> nil) then
InternalSaveGridLayout(Self, FIniLink.IniObject, FIniLink.RootSection +
GetDefaultSection(Self));
end;
procedure TRxDrawGrid.IniLoad(Sender: TObject);
begin
if (Name <> '') and (FIniLink.IniObject <> nil) then
InternalRestoreGridLayout(Self, FIniLink.IniObject, FIniLink.RootSection +
GetDefaultSection(Self));
end;
function TRxDrawGrid.CanEditAcceptKey(Key: Char): Boolean;
begin
if Assigned(FOnAcceptEditKey) then Result := FOnAcceptEditKey(Self, Key)
else Result := inherited CanEditAcceptKey(Key);
end;
function TRxDrawGrid.CanEditShow: Boolean;
begin
Result := inherited CanEditShow;
if Result and Assigned(FOnShowEditor) then begin
FOnShowEditor(Self, Col, Row, Result);
if not Result then EditorMode := False;
end;
end;
procedure TRxDrawGrid.DrawPicture(ARect: TRect; Graphic: TGraphic);
begin
DrawCellBitmap(Self, 0, 0, Graphic, ARect);
end;
procedure TRxDrawGrid.DrawMasked(ARect: TRect; Graphic: TBitmap);
var
X, Y: Integer;
begin
X := (ARect.Right + ARect.Left - Graphic.Width) div 2;
Y := (ARect.Bottom + ARect.Top - Graphic.Height) div 2;
DrawBitmapTransparent(Canvas, X, Y, Graphic, Graphic.TransparentColor
and not PaletteMask);
end;
procedure TRxDrawGrid.DrawStr(ARect: TRect; const S: string;
Align: TAlignment);
begin
DrawCellTextEx(Self, 0, 0, S, ARect, Align, vaCenter, False
{$IFDEF RX_D4}, IsRightToLeft {$ENDIF});
end;
procedure TRxDrawGrid.DrawMultiline(ARect: TRect; const S: string;
Align: TAlignment);
begin
DrawCellTextEx(Self, 0, 0, S, ARect, Align, vaTopJustify, True
{$IFDEF RX_D4}, IsRightToLeft {$ENDIF});
end;
procedure TRxDrawGrid.InvalidateCell(ACol, ARow: Longint);
begin
inherited InvalidateCell(ACol, ARow);
end;
procedure TRxDrawGrid.InvalidateCol(ACol: Longint);
{$IFNDEF WIN32}
var
I: Longint;
{$ENDIF}
begin
{$IFDEF WIN32}
inherited InvalidateCol(ACol);
{$ELSE}
for I := 0 to RowCount - 1 do inherited InvalidateCell(ACol, I);
{$ENDIF}
end;
procedure TRxDrawGrid.InvalidateRow(ARow: Longint);
var
I: Longint;
begin
for I := 0 to ColCount - 1 do inherited InvalidateCell(I, ARow);
end;
procedure TRxDrawGrid.KeyDown(var Key: Word; Shift: TShiftState);
begin
if not CanGridAcceptKey(Key, Shift) then Exit;
if not (ssCtrl in Shift) and (Key = VK_ESCAPE) and EditorMode and
(InplaceEditor <> nil) and InplaceEditor.Visible and
not (goAlwaysShowEditor in Options) then
begin
FNoUpdateData := True;
try
HideEditor;
if Assigned(FOnCancelEdit) then FOnCancelEdit(Self);
finally
FNoUpdateData := False;
end;
end
else inherited KeyDown(Key, Shift);
end;
procedure TRxDrawGrid.WMCommand(var Message: TWMCommand);
begin
if (Message.NotifyCode = EN_CHANGE) and
not (goAlwaysShowEditor in Options) then
begin
if (InplaceEditor <> nil) and InplaceEditor.HandleAllocated and
InplaceEditor.Visible then TRxInplaceEdit(InplaceEditor).Change;
Message.NotifyCode := 0;
end;
inherited;
end;
procedure TRxDrawGrid.EditChanged(Sender: TObject);
begin
if Assigned(FOnEditChange) then FOnEditChange(Self);
end;
function TRxDrawGrid.GetEditLimit: Integer;
begin
Result := inherited GetEditLimit;
if Assigned(FOnGetEditLimit) then FOnGetEditLimit(Self, Result);
end;
procedure TRxDrawGrid.SetEditText(ACol, ARow: Longint; const Value: string);
begin
if not FNoUpdateData then inherited SetEditText(ACol, ARow, Value);
end;
procedure TRxDrawGrid.SetFixedButtons(Value: Boolean);
begin
if FFixedCellsButtons <> Value then begin
FFixedCellsButtons := Value;
Invalidate;
end;
end;
procedure TRxDrawGrid.DoFixedCellClick(ACol, ARow: Longint);
begin
if Assigned(FOnFixedCellClick) then FOnFixedCellClick(Self, ACol, ARow);
end;
procedure TRxDrawGrid.CheckFixedCellButton(ACol, ARow: Longint; var Enabled: Boolean);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -