home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / delphi / kolekce / d6 / rxlibsetup.exe / {app} / units / rxgrids.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-02-19  |  36.7 KB  |  1,212 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {         Delphi VCL Extensions (RX)                    }
  4. {                                                       }
  5. {         Copyright (c) 2001,2002 SGB Software          }
  6. {         Copyright (c) 1997, 1998 Fedor Koshevnikov,   }
  7. {                        Igor Pavluk and Serge Korolev  }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit RXGrids;
  12.  
  13. {$I RX.INC}
  14. {$W-,T-}
  15.  
  16. interface
  17.  
  18. uses {$IFDEF WIN32} Windows, Registry, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  19.   Messages, Classes, Controls, Graphics, StdCtrls, ExtCtrls, Forms, Menus,
  20.   Grids, RxConst, IniFiles, Placemnt;
  21.  
  22. { TRxDrawGrid }
  23.  
  24. type
  25.   TAcceptKeyEvent = function (Sender: TObject; var Key: Char): Boolean of object;
  26.   TEditLimitEvent = procedure (Sender: TObject; var MaxLength: Integer) of object;
  27.   TEditShowEvent = procedure (Sender: TObject; ACol, ARow: Longint;
  28.     var AllowEdit: Boolean) of object;
  29.   TFixedCellClickEvent = procedure (Sender: TObject; ACol, ARow: Longint) of object;
  30.   TFixedCellCheckEvent = procedure (Sender: TObject; ACol, ARow: Longint;
  31.     var Enabled: Boolean) of object;
  32. {$IFDEF WIN32}
  33.   TInplaceEditStyle = TEditStyle; //(ieSimple, ieEllipsis, iePickList);
  34.   TEditAlignEvent = procedure (Sender: TObject; ACol, ARow: Longint;
  35.     var Alignment: TAlignment) of object;
  36.   TPicklistEvent = procedure (Sender: TObject; ACol, ARow: Longint;
  37.     PickList: TStrings) of object;
  38.   TEditStyleEvent = procedure (Sender: TObject; ACol, ARow: Longint;
  39.     var Style: TInplaceEditStyle) of object;
  40. {$ENDIF}
  41.  
  42.   TRxDrawGrid = class(TDrawGrid)
  43.   private
  44.     FNoUpdateData: Boolean;
  45.     FFixedCellsButtons: Boolean;
  46.     FPressedCell: TGridCoord;
  47.     FPressed: Boolean;
  48.     FTracking: Boolean;
  49.     FSwapButtons: Boolean;
  50.     FDefaultDrawing: Boolean;
  51.     FIniLink: TIniLink;
  52.     FOnColumnSized: TNotifyEvent;
  53.     FOnRowSized: TNotifyEvent;
  54.     FOnAcceptEditKey: TAcceptKeyEvent;
  55.     FOnGetEditLimit: TEditLimitEvent;
  56.     FOnEditChange: TNotifyEvent;
  57.     FOnShowEditor: TEditShowEvent;
  58.     FOnCancelEdit: TNotifyEvent;
  59.     FOnFixedCellClick: TFixedCellClickEvent;
  60.     FOnCheckButton: TFixedCellCheckEvent;
  61.     FOnChangeFocus: TNotifyEvent;
  62. {$IFDEF WIN32}
  63.     FOnGetEditAlign: TEditAlignEvent;
  64.     FOnEditButtonClick: TNotifyEvent;
  65.     FOnGetPicklist: TPicklistEvent;
  66.     FOnGetEditStyle: TEditStyleEvent;
  67. {$ENDIF}
  68.     function GetStorage: TFormPlacement;
  69.     procedure SetStorage(Value: TFormPlacement);
  70.     procedure IniSave(Sender: TObject);
  71.     procedure IniLoad(Sender: TObject);
  72.     procedure SetFixedButtons(Value: Boolean);
  73.     procedure StopTracking;
  74.     procedure TrackButton(X, Y: Integer);
  75.     function IsActiveControl: Boolean;
  76.     procedure WMCommand(var Message: TWMCommand); message WM_COMMAND;
  77.     procedure WMCancelMode(var Message: TMessage); message WM_CANCELMODE;
  78.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
  79.     procedure WMKillFocus(var Msg: TWMKillFocus); message WM_KILLFOCUS;
  80.     procedure WMSetFocus(var Msg: TWMSetFocus); message WM_SETFOCUS;
  81. {$IFDEF WIN32}
  82.     procedure WMRButtonUp(var Message: TWMMouse); message WM_RBUTTONUP;
  83. {$ENDIF}
  84.   protected
  85.     function CanEditAcceptKey(Key: Char): Boolean; override;
  86.     function CanEditShow: Boolean; override;
  87.     function GetEditLimit: Integer; override;
  88.     procedure TopLeftChanged; override;
  89.     procedure ColWidthsChanged; override;
  90.     procedure RowHeightsChanged; override;
  91.     procedure CallDrawCellEvent(ACol, ARow: Longint; ARect: TRect;
  92.       AState: TGridDrawState);
  93.     procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
  94.       AState: TGridDrawState); override;
  95.     procedure DoDrawCell(ACol, ARow: Longint; ARect: TRect;
  96.       AState: TGridDrawState); virtual;
  97.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  98.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  99.       X, Y: Integer); override;
  100.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  101.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
  102.       X, Y: Integer); override;
  103.     procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
  104.     function CreateEditor: TInplaceEdit; override;
  105.     procedure Paint; override;
  106.     procedure EditChanged(Sender: TObject); dynamic;
  107.     procedure DoFixedCellClick(ACol, ARow: Longint); dynamic;
  108.     procedure CheckFixedCellButton(ACol, ARow: Longint;
  109.       var Enabled: Boolean); dynamic;
  110. {$IFDEF WIN32}
  111.     procedure EditButtonClick; dynamic;
  112.     function GetEditAlignment(ACol, ARow: Longint): TAlignment; dynamic;
  113.     function GetEditStyle(ACol, ARow: Longint): TInplaceEditStyle; override;
  114.     procedure GetPicklist(ACol, ARow: Longint; Picklist: TStrings); dynamic;
  115. {$ENDIF}
  116.   public
  117.     constructor Create(AOwner: TComponent); override;
  118.     destructor Destroy; override;
  119.     procedure DrawStr(ARect: TRect; const S: string; Align: TAlignment);
  120.     procedure DrawMultiline(ARect: TRect; const S: string; Align: TAlignment);
  121.     procedure DrawPicture(ARect: TRect; Graphic: TGraphic);
  122.     procedure DrawMasked(ARect: TRect; Graphic: TBitmap);
  123.     procedure InvalidateCell(ACol, ARow: Longint);
  124.     procedure InvalidateCol(ACol: Longint);
  125.     procedure InvalidateRow(ARow: Longint);
  126.     property InplaceEditor;
  127.   published
  128.     property DefaultRowHeight default 18;
  129.     property Options default [goFixedVertLine, goFixedHorzLine, goVertLine,
  130.       goHorzLine, goDrawFocusSelected, goColSizing];
  131.     property IniStorage: TFormPlacement read GetStorage write SetStorage;
  132.     property FixedButtons: Boolean read FFixedCellsButtons write SetFixedButtons
  133.       default False;
  134.     property OnAcceptEditKey: TAcceptKeyEvent read FOnAcceptEditKey
  135.       write FOnAcceptEditKey;
  136.     property OnCancelEdit: TNotifyEvent read FOnCancelEdit write FOnCancelEdit;
  137.     property OnCheckButton: TFixedCellCheckEvent read FOnCheckButton
  138.       write FOnCheckButton;
  139.     property OnChangeFocus: TNotifyEvent read FOnChangeFocus write FOnChangeFocus;
  140.     property OnFixedCellClick: TFixedCellClickEvent read FOnFixedCellClick
  141.       write FOnFixedCellClick;
  142.     property OnColumnSized: TNotifyEvent read FOnColumnSized
  143.       write FOnColumnSized;
  144.     property OnRowSized: TNotifyEvent read FOnRowSized write FOnRowSized;
  145.     property OnGetEditLimit: TEditLimitEvent read FOnGetEditLimit write FOnGetEditLimit;
  146.     property OnEditChange: TNotifyEvent read FOnEditChange write FOnEditChange;
  147.     property OnShowEditor: TEditShowEvent read FOnShowEditor write FOnShowEditor;
  148. {$IFDEF WIN32}
  149.     property OnGetEditAlign: TEditAlignEvent read FOnGetEditAlign write FOnGetEditAlign;
  150.     property OnGetEditStyle: TEditStyleEvent read FOnGetEditStyle write FOnGetEditStyle;
  151.     property OnGetPicklist: TPicklistEvent read FOnGetPicklist write FOnGetPicklist;
  152.     property OnEditButtonClick: TNotifyEvent read FOnEditButtonClick write FOnEditButtonClick;
  153. {$ENDIF}
  154.   end;
  155.  
  156. implementation
  157.  
  158. uses SysUtils, VCLUtils, MaxMin, Consts, AppUtils;
  159.  
  160. const
  161. {$IFDEF WIN32}
  162.   MaxCustomExtents = MaxListSize;
  163. {$ELSE}
  164.   MaxCustomExtents = 65520 div SizeOf(Integer);
  165. {$ENDIF}
  166.   MaxShortInt = High(ShortInt);
  167.  
  168. type
  169.   PIntArray = ^TIntArray;
  170.   TIntArray = array[0..MaxCustomExtents] of Integer;
  171.  
  172. {$IFDEF WIN32}
  173.  
  174. { TRxInplaceEdit }
  175.  
  176. type
  177.   TPopupListbox = class;
  178.  
  179.   TRxInplaceEdit = class(TInplaceEdit)
  180.   private
  181.     FAlignment: TAlignment;
  182.     FButtonWidth: Integer;
  183.     FPickList: TPopupListbox;
  184.     FActiveList: TWinControl;
  185.     FEditStyle: TInplaceEditStyle;
  186.     FListVisible: Boolean;
  187.     FTracking: Boolean;
  188.     FPressed: Boolean;
  189.     procedure ListMouseUp(Sender: TObject; Button: TMouseButton;
  190.       Shift: TShiftState; X, Y: Integer);
  191.     procedure SetAlignment(Value: TAlignment);
  192.     procedure SetEditStyle(Value: TInplaceEditStyle);
  193.     procedure StopTracking;
  194.     procedure TrackButton(X,Y: Integer);
  195.     procedure CMCancelMode(var Message: TCMCancelMode); message CM_CANCELMODE;
  196.     procedure WMCancelMode(var Message: TMessage); message WM_CANCELMODE;
  197.     procedure WMKillFocus(var Message: TMessage); message WM_KILLFOCUS;
  198.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
  199.     procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  200.     procedure WMSetCursor(var Message: TWMSetCursor); message WM_SETCURSOR;
  201.   protected
  202.     procedure CreateParams(var Params: TCreateParams); override;
  203.     procedure BoundsChanged; override;
  204.     procedure CloseUp(Accept: Boolean);
  205.     procedure DoDropDownKeys(var Key: Word; Shift: TShiftState);
  206.     procedure DropDown;
  207.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  208.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  209.       X, Y: Integer); override;
  210.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  211.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
  212.       X, Y: Integer); override;
  213.     procedure PaintWindow(DC: HDC); override;
  214.     procedure UpdateContents; override;
  215.     procedure WndProc(var Message: TMessage); override;
  216.     property ActiveList: TWinControl read FActiveList write FActiveList;
  217.     property PickList: TPopupListbox read FPickList;
  218.   public
  219.     constructor Create(Owner: TComponent); override;
  220.     property Alignment: TAlignment read FAlignment write SetAlignment;
  221.     property EditStyle: TInplaceEditStyle read FEditStyle write SetEditStyle;
  222.   end;
  223.  
  224. { TPopupListbox }
  225.  
  226.   TPopupListbox = class(TCustomListbox)
  227.   private
  228.     FSearchText: string;
  229.     FSearchTickCount: Longint;
  230.   protected
  231.     procedure CreateParams(var Params: TCreateParams); override;
  232.     procedure CreateWnd; override;
  233.     procedure KeyPress(var Key: Char); override;
  234.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  235.   end;
  236.  
  237. procedure TPopupListBox.CreateParams(var Params: TCreateParams);
  238. begin
  239.   inherited CreateParams(Params);
  240.   with Params do begin
  241.     Style := Style or WS_BORDER;
  242.     ExStyle := WS_EX_TOOLWINDOW or WS_EX_TOPMOST;
  243. {$IFDEF RX_D4}
  244.     AddBiDiModeExStyle(ExStyle);
  245. {$ENDIF}
  246.     WindowClass.Style := CS_SAVEBITS;
  247.   end;
  248. end;
  249.  
  250. procedure TPopupListbox.CreateWnd;
  251. begin
  252.   inherited CreateWnd;
  253.   Windows.SetParent(Handle, 0);
  254.   CallWindowProc(DefWndProc, Handle, WM_SETFOCUS, 0, 0);
  255. end;
  256.  
  257. procedure TPopupListbox.KeyPress(var Key: Char);
  258. var
  259.   TickCount: Integer;
  260. begin
  261.   case Key of
  262.     #8, #27: FSearchText := '';
  263.     #32..#255:
  264.       begin
  265.         TickCount := GetTickCount;
  266.         if TickCount - FSearchTickCount > 4000 then FSearchText := '';
  267.         FSearchTickCount := TickCount;
  268.         if Length(FSearchText) < 32 then FSearchText := FSearchText + Key;
  269.         SendMessage(Handle, LB_SELECTSTRING, WORD(-1),
  270.           Longint(PChar(FSearchText)));
  271.         Key := #0;
  272.       end;
  273.   end;
  274.   inherited KeyPress(Key);
  275. end;
  276.  
  277. procedure TPopupListbox.MouseUp(Button: TMouseButton; Shift: TShiftState;
  278.   X, Y: Integer);
  279. begin
  280.   inherited MouseUp(Button, Shift, X, Y);
  281.   TRxInplaceEdit(Owner).CloseUp((X >= 0) and (Y >= 0) and (X < Width) and
  282.     (Y < Height));
  283. end;
  284.  
  285. { TRxInplaceEdit }
  286.  
  287. constructor TRxInplaceEdit.Create(Owner: TComponent);
  288. begin
  289.   inherited Create(Owner);
  290.   FButtonWidth := GetSystemMetrics(SM_CXVSCROLL);
  291.   FEditStyle := esSimple;
  292. end;
  293.  
  294. procedure TRxInplaceEdit.CreateParams(var Params: TCreateParams);
  295. const
  296.   Alignments: array[TAlignment] of {$IFDEF RX_D4}DWORD{$ELSE}Longint{$ENDIF} =
  297.     (ES_LEFT, ES_RIGHT, ES_CENTER);
  298. begin
  299.   inherited CreateParams(Params);
  300.   with Params do Style := Style or Alignments[FAlignment];
  301. end;
  302.  
  303. procedure TRxInplaceEdit.BoundsChanged;
  304. var
  305.   R: TRect;
  306. begin
  307.   SetRect(R, 2, 2, Width - 2, Height);
  308.   if FEditStyle <> esSimple then Dec(R.Right, FButtonWidth);
  309.   SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@R));
  310.   SendMessage(Handle, EM_SCROLLCARET, 0, 0);
  311. {$IFDEF RX_D3}
  312.   if SysLocale.FarEast then
  313.     SetImeCompositionWindow(Font, R.Left, R.Top);
  314. {$ENDIF}
  315. end;
  316.  
  317. procedure TRxInplaceEdit.CloseUp(Accept: Boolean);
  318. var
  319.   ListValue: string;
  320. begin
  321.   if FListVisible then begin
  322.     if GetCapture <> 0 then SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
  323.     if FPickList.ItemIndex > -1 then
  324.       ListValue := FPickList.Items[FPicklist.ItemIndex];
  325.     SetWindowPos(FActiveList.Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or
  326.       SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
  327.     FListVisible := False;
  328.     Invalidate;
  329.     if Accept and EditCanModify then Text := ListValue;
  330.   end;
  331. end;
  332.  
  333. procedure TRxInplaceEdit.DoDropDownKeys(var Key: Word; Shift: TShiftState);
  334. begin
  335.   case Key of
  336.     VK_UP, VK_DOWN:
  337.       if ssAlt in Shift then begin
  338.         if FListVisible then CloseUp(True) else DropDown;
  339.         Key := 0;
  340.       end;
  341.     VK_RETURN, VK_ESCAPE:
  342.       if FListVisible and not (ssAlt in Shift) then begin
  343.         CloseUp(Key = VK_RETURN);
  344.         Key := 0;
  345.       end;
  346.   end;
  347. end;
  348.  
  349. procedure TRxInplaceEdit.DropDown;
  350. const
  351.   MaxListCount = 8;
  352. var
  353.   P: TPoint;
  354.   Y, J, I: Integer;
  355. begin
  356.   if not FListVisible and Assigned(FActiveList) then begin
  357.     FPickList.Width := Width;
  358.     FPickList.Color := Color;
  359.     FPickList.Font := Font;
  360.     FPickList.Items.Clear;
  361.     with TRxDrawGrid(Grid) do 
  362.       GetPickList(Col, Row, FPickList.Items);
  363.     FPickList.Height := Min(FPickList.Items.Count, MaxListCount) *
  364.       FPickList.ItemHeight + 4;
  365.     FPickList.ItemIndex := FPickList.Items.IndexOf(Text);
  366.     J := FPickList.ClientWidth;
  367.     for I := 0 to FPickList.Items.Count - 1 do begin
  368.       Y := FPickList.Canvas.TextWidth(FPickList.Items[I]);
  369.       if Y > J then J := Y;
  370.     end;
  371.     if FPickList.Items.Count > MaxListCount then
  372.       Inc(J, GetSystemMetrics(SM_CXVSCROLL));
  373.     FPickList.ClientWidth := J;
  374.     P := Parent.ClientToScreen(Point(Left, Top));
  375.     Y := P.Y + Height;
  376.     if Y + FActiveList.Height > Screen.Height then
  377.       Y := P.Y - FActiveList.Height;
  378.     SetWindowPos(FActiveList.Handle, HWND_TOP, P.X, Y, 0, 0,
  379.       SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
  380.     FListVisible := True;
  381.     Invalidate;
  382.     Windows.SetFocus(Handle);
  383.   end;
  384. end;
  385.  
  386. type
  387.   TWinControlCracker = class(TWinControl);
  388.  
  389. procedure TRxInplaceEdit.KeyDown(var Key: Word; Shift: TShiftState);
  390. begin
  391.   if (EditStyle = esEllipsis) and (Key = VK_RETURN) and (Shift = [ssCtrl]) then
  392.   begin
  393.     TRxDrawGrid(Grid).EditButtonClick;
  394.     KillMessage(Handle, WM_CHAR);
  395.   end
  396.   else inherited KeyDown(Key, Shift);
  397. end;
  398.  
  399. procedure TRxInplaceEdit.ListMouseUp(Sender: TObject; Button: TMouseButton;
  400.   Shift: TShiftState; X, Y: Integer);
  401. begin
  402.   if Button = mbLeft then
  403.     CloseUp(PtInRect(FActiveList.ClientRect, Point(X, Y)));
  404. end;
  405.  
  406. procedure TRxInplaceEdit.MouseDown(Button: TMouseButton; Shift: TShiftState;
  407.   X, Y: Integer);
  408. begin
  409.   if (Button = mbLeft) and (FEditStyle <> esSimple) and
  410.     PtInRect(Rect(Width - FButtonWidth, 0, Width, Height), Point(X,Y)) then
  411.   begin
  412.     if FListVisible then CloseUp(False)
  413.     else begin
  414.       MouseCapture := True;
  415.       FTracking := True;
  416.       TrackButton(X, Y);
  417.       if Assigned(FActiveList) then DropDown;
  418.     end;
  419.   end;
  420.   inherited MouseDown(Button, Shift, X, Y);
  421. end;
  422.  
  423. procedure TRxInplaceEdit.MouseMove(Shift: TShiftState; X, Y: Integer);
  424. var
  425.   ListPos: TPoint;
  426.   MousePos: TSmallPoint;
  427. begin
  428.   if FTracking then begin
  429.     TrackButton(X, Y);
  430.     if FListVisible then begin
  431.       ListPos := FActiveList.ScreenToClient(ClientToScreen(Point(X, Y)));
  432.       if PtInRect(FActiveList.ClientRect, ListPos) then begin
  433.         StopTracking;
  434.         MousePos := PointToSmallPoint(ListPos);
  435.         SendMessage(FActiveList.Handle, WM_LBUTTONDOWN, 0, Integer(MousePos));
  436.         Exit;
  437.       end;
  438.     end;
  439.   end;
  440.   inherited MouseMove(Shift, X, Y);
  441. end;
  442.  
  443. procedure TRxInplaceEdit.MouseUp(Button: TMouseButton; Shift: TShiftState;
  444.   X, Y: Integer);
  445. var
  446.   WasPressed: Boolean;
  447. begin
  448.   WasPressed := FPressed;
  449.   StopTracking;
  450.   if (Button = mbLeft) and (FEditStyle = esEllipsis) and WasPressed then
  451.     TRxDrawGrid(Grid).EditButtonClick;
  452.   inherited MouseUp(Button, Shift, X, Y);
  453. end;
  454.  
  455. procedure TRxInplaceEdit.PaintWindow(DC: HDC);
  456. const
  457.   LeftOffs = 3;
  458. var
  459.   R: TRect;
  460.   Flags: Integer;
  461.   W, G, I: Integer;
  462. begin
  463.   if FEditStyle <> esSimple then begin
  464.     SetRect(R, Width - FButtonWidth, 0, Width, Height);
  465.     Flags := 0;
  466.     if FEditStyle in [esPickList] then begin
  467.       if FActiveList = nil then Flags := DFCS_INACTIVE
  468.       else if FPressed then Flags := DFCS_FLAT or DFCS_PUSHED;
  469.       DrawFrameControl(DC, R, DFC_SCROLL, Flags or DFCS_SCROLLCOMBOBOX);
  470.     end
  471.     else begin { esEllipsis }
  472.       if FPressed then Flags := BF_FLAT;
  473.       DrawEdge(DC, R, EDGE_RAISED, BF_RECT or BF_MIDDLE or Flags);
  474.       W := 2;
  475.       G := (FButtonWidth - LeftOffs * 2 - 3 * W) div 2;
  476.       if G <= 0 then G := 1;
  477.       if G > 3 then G := 3;
  478.       Flags := R.Left + (FButtonWidth - 3 * W - 2 * G) div 2 + Ord(FPressed);
  479.       I := R.Top + (ClientHeight - W) div 2 {+ Ord(FPressed)};
  480.       PatBlt(DC, Flags, I, W, W, BLACKNESS);
  481.       PatBlt(DC, Flags + G + W, I, W, W, BLACKNESS);
  482.       PatBlt(DC, Flags + 2 * G + 2 * W, I, W, W, BLACKNESS);
  483.     end;
  484.     ExcludeClipRect(DC, R.Left, R.Top, R.Right, R.Bottom);
  485.   end;
  486.   inherited PaintWindow(DC);
  487. end;
  488.  
  489. procedure TRxInplaceEdit.SetAlignment(Value: TAlignment);
  490. begin
  491.   if FAlignment <> Value then begin
  492.     FAlignment := Value;
  493.     RecreateWnd;
  494.   end;
  495. end;
  496.  
  497. procedure TRxInplaceEdit.SetEditStyle(Value: TInplaceEditStyle);
  498. begin
  499.   if Value = FEditStyle then Exit;
  500.   FEditStyle := Value;
  501.   case Value of
  502.     esPickList:
  503.       begin
  504.         if FPickList = nil then begin
  505.           FPickList := TPopupListbox.Create(Self);
  506.           FPickList.Visible := False;
  507.           FPickList.Parent := Self;
  508.           FPickList.OnMouseUp := ListMouseUp;
  509.           FPickList.IntegralHeight := True;
  510.           FPickList.ItemHeight := 11;
  511.         end;
  512.         FActiveList := FPickList;
  513.       end;
  514.     else FActiveList := nil;
  515.   end;
  516.   Repaint;
  517. end;
  518.  
  519. procedure TRxInplaceEdit.StopTracking;
  520. begin
  521.   if FTracking then begin
  522.     TrackButton(-1, -1);
  523.     FTracking := False;
  524.     MouseCapture := False;
  525.   end;
  526. end;
  527.  
  528. procedure TRxInplaceEdit.TrackButton(X,Y: Integer);
  529. var
  530.   NewState: Boolean;
  531.   R: TRect;
  532. begin
  533.   SetRect(R, ClientWidth - FButtonWidth, 0, ClientWidth, ClientHeight);
  534.   NewState := PtInRect(R, Point(X, Y));
  535.   if FPressed <> NewState then begin
  536.     FPressed := NewState;
  537.     InvalidateRect(Handle, @R, False);
  538.   end;
  539. end;
  540.  
  541. procedure TRxInplaceEdit.UpdateContents;
  542. var
  543.   SaveChanged: TNotifyEvent;
  544. begin
  545.   with TRxDrawGrid(Grid) do begin
  546.     Self.Alignment := GetEditAlignment(Col, Row);
  547.     EditStyle := GetEditStyle(Col, Row);
  548.   end;
  549.   SaveChanged := Self.OnChange;
  550.   try
  551.     Self.OnChange := nil;
  552.     inherited UpdateContents;
  553.   finally
  554.     Self.OnChange := SaveChanged;
  555.   end;
  556. end;
  557.  
  558. procedure TRxInplaceEdit.CMCancelMode(var Message: TCMCancelMode);
  559. begin
  560.   if (Message.Sender <> Self) and (Message.Sender <> FActiveList) then
  561.     CloseUp(False);
  562. end;
  563.  
  564. procedure TRxInplaceEdit.WMCancelMode(var Message: TMessage);
  565. begin
  566.   StopTracking;
  567.   inherited;
  568. end;
  569.  
  570. procedure TRxInplaceEdit.WMKillFocus(var Message: TMessage);
  571. begin
  572. {$IFDEF RX_D3}
  573.   if not SysLocale.FarEast then inherited
  574.   else begin
  575.     ImeName := Screen.DefaultIme;
  576.     ImeMode := imDontCare;
  577.     inherited;
  578.     if THandle(Message.WParam) <> TRxDrawGrid(Grid).Handle then
  579.       ActivateKeyboardLayout(Screen.DefaultKbLayout, KLF_ACTIVATE);
  580.   end;
  581. {$ELSE}
  582.   inherited;
  583. {$ENDIF}
  584.   CloseUp(False);
  585. end;
  586.  
  587. procedure TRxInplaceEdit.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  588. begin
  589.   with Message do
  590.     if (FEditStyle <> esSimple) and PtInRect(Rect(Width - FButtonWidth, 0,
  591.       Width, Height), Point(XPos, YPos)) then Exit;
  592.   inherited;
  593. end;
  594.  
  595. procedure TRxInplaceEdit.WMPaint(var Message: TWMPaint);
  596. begin
  597.   PaintHandler(Message);
  598. end;
  599.  
  600. procedure TRxInplaceEdit.WMSetCursor(var Message: TWMSetCursor);
  601. var
  602.   P: TPoint;
  603. begin
  604.   GetCursorPos(P);
  605.   if (FEditStyle <> esSimple) and
  606.     PtInRect(Rect(Width - FButtonWidth, 0, Width, Height), ScreenToClient(P)) then
  607.     Windows.SetCursor(LoadCursor(0, IDC_ARROW))
  608.   else inherited;
  609. end;
  610.  
  611. procedure TRxInplaceEdit.WndProc(var Message: TMessage);
  612. begin
  613.   case Message.Msg of
  614.     WM_KEYDOWN, WM_SYSKEYDOWN, WM_CHAR:
  615.       if EditStyle in [esPickList] then
  616.         with TWMKey(Message) do begin
  617.           DoDropDownKeys(CharCode, KeyDataToShiftState(KeyData));
  618.           if (CharCode <> 0) and FListVisible then begin
  619.             with TMessage(Message) do
  620.               SendMessage(FActiveList.Handle, Msg, WParam, LParam);
  621.             Exit;
  622.           end;
  623.         end;
  624.   end;
  625.   inherited;
  626. end;
  627.  
  628. {$ELSE}
  629.  
  630. type
  631.   TRxInplaceEdit = class(TInplaceEdit);
  632.  
  633. {$ENDIF WIN32}
  634.  
  635. { TRxDrawGrid }
  636.  
  637. constructor TRxDrawGrid.Create(AOwner: TComponent);
  638. begin
  639.   inherited Create(AOwner);
  640.   DefaultRowHeight := 18;
  641.   Options := [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
  642.     goDrawFocusSelected, goColSizing];
  643.   FIniLink := TIniLink.Create;
  644.   FIniLink.OnSave := IniSave;
  645.   FIniLink.OnLoad := IniLoad;
  646.   FPressedCell.X := -1;
  647.   FPressedCell.Y := -1;
  648. end;
  649.  
  650. destructor TRxDrawGrid.Destroy;
  651. begin
  652.   FOnChangeFocus := nil;
  653.   FIniLink.Free;
  654.   inherited Destroy;
  655. end;
  656.  
  657. function TRxDrawGrid.GetStorage: TFormPlacement;
  658. begin
  659.   Result := FIniLink.Storage;
  660. end;
  661.  
  662. procedure TRxDrawGrid.SetStorage(Value: TFormPlacement);
  663. begin
  664.   FIniLink.Storage := Value;
  665. end;
  666.  
  667. procedure TRxDrawGrid.IniSave(Sender: TObject);
  668. begin
  669.   if (Name <> '') and (FIniLink.IniObject <> nil) then
  670.     InternalSaveGridLayout(Self, FIniLink.IniObject, FIniLink.RootSection +
  671.       GetDefaultSection(Self));
  672. end;
  673.  
  674. procedure TRxDrawGrid.IniLoad(Sender: TObject);
  675. begin
  676.   if (Name <> '') and (FIniLink.IniObject <> nil) then
  677.     InternalRestoreGridLayout(Self, FIniLink.IniObject, FIniLink.RootSection +
  678.       GetDefaultSection(Self));
  679. end;
  680.  
  681. function TRxDrawGrid.CanEditAcceptKey(Key: Char): Boolean;
  682. begin
  683.   if Assigned(FOnAcceptEditKey) then Result := FOnAcceptEditKey(Self, Key)
  684.   else Result := inherited CanEditAcceptKey(Key);
  685. end;
  686.  
  687. function TRxDrawGrid.CanEditShow: Boolean;
  688. begin
  689.   Result := inherited CanEditShow;
  690.   if Result and Assigned(FOnShowEditor) then begin
  691.     FOnShowEditor(Self, Col, Row, Result);
  692.     if not Result then EditorMode := False;
  693.   end;
  694. end;
  695.  
  696. procedure TRxDrawGrid.DrawPicture(ARect: TRect; Graphic: TGraphic);
  697. begin
  698.   DrawCellBitmap(Self, 0, 0, Graphic, ARect);
  699. end;
  700.  
  701. procedure TRxDrawGrid.DrawMasked(ARect: TRect; Graphic: TBitmap);
  702. var
  703.   X, Y: Integer;
  704. begin
  705.   X := (ARect.Right + ARect.Left - Graphic.Width) div 2;
  706.   Y := (ARect.Bottom + ARect.Top - Graphic.Height) div 2;
  707.   DrawBitmapTransparent(Canvas, X, Y, Graphic, Graphic.TransparentColor
  708.     and not PaletteMask);
  709. end;
  710.  
  711. procedure TRxDrawGrid.DrawStr(ARect: TRect; const S: string;
  712.   Align: TAlignment);
  713. begin
  714.   DrawCellTextEx(Self, 0, 0, S, ARect, Align, vaCenter, False
  715.     {$IFDEF RX_D4}, IsRightToLeft {$ENDIF});
  716. end;
  717.  
  718. procedure TRxDrawGrid.DrawMultiline(ARect: TRect; const S: string;
  719.   Align: TAlignment);
  720. begin
  721.   DrawCellTextEx(Self, 0, 0, S, ARect, Align, vaTopJustify, True
  722.     {$IFDEF RX_D4}, IsRightToLeft {$ENDIF});
  723. end;
  724.  
  725. procedure TRxDrawGrid.InvalidateCell(ACol, ARow: Longint);
  726. begin
  727.   inherited InvalidateCell(ACol, ARow);
  728. end;
  729.  
  730. procedure TRxDrawGrid.InvalidateCol(ACol: Longint);
  731. {$IFNDEF WIN32}
  732. var
  733.   I: Longint;
  734. {$ENDIF}
  735. begin
  736. {$IFDEF WIN32}
  737.   inherited InvalidateCol(ACol);
  738. {$ELSE}
  739.   for I := 0 to RowCount - 1 do inherited InvalidateCell(ACol, I);
  740. {$ENDIF}
  741. end;
  742.  
  743. procedure TRxDrawGrid.InvalidateRow(ARow: Longint);
  744. var
  745.   I: Longint;
  746. begin
  747.   for I := 0 to ColCount - 1 do inherited InvalidateCell(I, ARow);
  748. end;
  749.  
  750. procedure TRxDrawGrid.KeyDown(var Key: Word; Shift: TShiftState);
  751. begin
  752.   if not CanGridAcceptKey(Key, Shift) then Exit;
  753.   if not (ssCtrl in Shift) and (Key = VK_ESCAPE) and EditorMode and
  754.     (InplaceEditor <> nil) and InplaceEditor.Visible and
  755.     not (goAlwaysShowEditor in Options) then
  756.   begin
  757.     FNoUpdateData := True;
  758.     try
  759.       HideEditor;
  760.       if Assigned(FOnCancelEdit) then FOnCancelEdit(Self);
  761.     finally
  762.       FNoUpdateData := False;
  763.     end;
  764.   end
  765.   else inherited KeyDown(Key, Shift);
  766. end;
  767.  
  768. procedure TRxDrawGrid.WMCommand(var Message: TWMCommand);
  769. begin
  770.   if (Message.NotifyCode = EN_CHANGE) and
  771.     not (goAlwaysShowEditor in Options) then
  772.   begin
  773.     if (InplaceEditor <> nil) and InplaceEditor.HandleAllocated and
  774.       InplaceEditor.Visible then TRxInplaceEdit(InplaceEditor).Change;
  775.     Message.NotifyCode := 0;
  776.   end;
  777.   inherited;
  778. end;
  779.  
  780. procedure TRxDrawGrid.EditChanged(Sender: TObject);
  781. begin
  782.   if Assigned(FOnEditChange) then FOnEditChange(Self);
  783. end;
  784.  
  785. function TRxDrawGrid.GetEditLimit: Integer;
  786. begin
  787.   Result := inherited GetEditLimit;
  788.   if Assigned(FOnGetEditLimit) then FOnGetEditLimit(Self, Result);
  789. end;
  790.  
  791. procedure TRxDrawGrid.SetEditText(ACol, ARow: Longint; const Value: string);
  792. begin
  793.   if not FNoUpdateData then inherited SetEditText(ACol, ARow, Value);
  794. end;
  795.  
  796. procedure TRxDrawGrid.SetFixedButtons(Value: Boolean);
  797. begin
  798.   if FFixedCellsButtons <> Value then begin
  799.     FFixedCellsButtons := Value;
  800.     Invalidate;
  801.   end;
  802. end;
  803.  
  804. procedure TRxDrawGrid.DoFixedCellClick(ACol, ARow: Longint);
  805. begin
  806.   if Assigned(FOnFixedCellClick) then FOnFixedCellClick(Self, ACol, ARow);
  807. end;
  808.  
  809. procedure TRxDrawGrid.CheckFixedCellButton(ACol, ARow: Longint; var Enabled: Boolean);
  810. begin
  811.   if (ACol >= 0) and (ARow >= 0) and ((ACol < FixedCols) or (ARow < FixedRows)) then
  812.   begin
  813.     if Assigned(FOnCheckButton) then FOnCheckButton(Self, ACol, ARow, Enabled);
  814.   end
  815.   else Enabled := False;
  816. end;
  817.  
  818. procedure TRxDrawGrid.TopLeftChanged;
  819. begin
  820.   if (goRowSelect in Options) and DefaultDrawing then
  821.     InvalidateRow(Self.Row);
  822.   inherited TopLeftChanged;
  823.   if FTracking then StopTracking;
  824. end;
  825.  
  826. procedure TRxDrawGrid.ColWidthsChanged;
  827. begin
  828.   inherited ColWidthsChanged;
  829.   if FTracking then StopTracking;
  830.   if Assigned(FOnColumnSized) then FOnColumnSized(Self);
  831. end;
  832.  
  833. procedure TRxDrawGrid.RowHeightsChanged;
  834. begin
  835.   inherited RowHeightsChanged;
  836.   if FTracking then StopTracking;
  837.   if Assigned(FOnRowSized) then FOnRowSized(Self);
  838. end;
  839.  
  840. procedure TRxDrawGrid.StopTracking;
  841. begin
  842.   if FTracking then begin
  843.     TrackButton(-1, -1);
  844.     FTracking := False;
  845.     MouseCapture := False;
  846.   end;
  847. end;
  848.  
  849. procedure TRxDrawGrid.TrackButton(X, Y: Integer);
  850. var
  851.   Cell: TGridCoord;
  852.   NewPressed: Boolean;
  853. begin
  854.   Cell := MouseCoord(X, Y);
  855.   NewPressed := PtInRect(Rect(0, 0, ClientWidth, ClientHeight), Point(X, Y))
  856.     and (FPressedCell.X = Cell.X) and (FPressedCell.Y = Cell.Y);
  857.   if FPressed <> NewPressed then begin
  858.     FPressed := NewPressed;
  859.     InvalidateCell(Cell.X, Cell.Y);
  860.     InvalidateCell(FPressedCell.X, FPressedCell.Y);
  861.   end;
  862. end;
  863.  
  864. function TRxDrawGrid.IsActiveControl: Boolean;
  865. var
  866.   H: Hwnd;
  867.   ParentForm: TCustomForm;
  868. begin
  869.   Result := False;
  870.   ParentForm := GetParentForm(Self);
  871.   if Assigned(ParentForm) then begin
  872.     if (ParentForm.ActiveControl = Self) then
  873.       Result := True;
  874.   end
  875.   else begin
  876.     H := GetFocus;
  877.     while IsWindow(H) and (Result = False) do begin
  878.       if H = WindowHandle then Result := True
  879.       else H := GetParent(H);
  880.     end;
  881.   end;
  882. end;
  883.  
  884. procedure TRxDrawGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
  885.   X, Y: Integer);
  886. var
  887.   Cell: TGridCoord;
  888.   EnableClick, Fixed: Boolean;
  889. begin
  890.   HideEditor;
  891.   if not (csDesigning in ComponentState) and (CanFocus or
  892.     (GetParentForm(Self) = nil)) then
  893.   begin
  894.     SetFocus;
  895.     if not IsActiveControl then begin
  896.       MouseCapture := False;
  897.       Exit;
  898.     end;
  899.   end;
  900.   if (Button = mbLeft) and (ssDouble in Shift) then begin
  901.     if FFixedCellsButtons then begin
  902.       Cell := MouseCoord(X, Y);
  903.       if not ((Cell.X >= 0) and (Cell.X < FixedCols)) and not
  904.         ((Cell.Y >= 0) and (Cell.Y < FixedRows)) then
  905.       begin
  906.         DblClick;
  907.         Exit;
  908.       end;
  909.     end
  910.     else begin
  911.       DblClick;
  912.       Exit;
  913.     end;
  914.   end;
  915.   if Sizing(X, Y) then
  916.     inherited MouseDown(Button, Shift, X, Y)
  917.   else begin
  918.     Cell := MouseCoord(X, Y);
  919.     Fixed := ((Cell.X >= 0) and (Cell.X < FixedCols)) or
  920.       ((Cell.Y >= 0) and (Cell.Y < FixedRows));
  921.     if FFixedCellsButtons and Fixed and not (csDesigning in ComponentState) then
  922.     begin
  923.       if ([goRowMoving, goColMoving] * Options <> []) and
  924.         (Button = mbRight) then
  925.       begin
  926.         Button := mbLeft;
  927.         FSwapButtons := True;
  928.         MouseCapture := True;
  929.       end
  930.       else if (Button = mbLeft) then begin
  931.         EnableClick := True;
  932.         CheckFixedCellButton(Cell.X, Cell.Y, EnableClick);
  933.         if EnableClick then begin
  934.           MouseCapture := True;
  935.           FTracking := True;
  936.           FPressedCell := Cell;
  937.           TrackButton(X, Y);
  938.         end else Beep;
  939.         Exit;
  940.       end;
  941.     end;
  942.     inherited MouseDown(Button, Shift, X, Y);
  943.   end;
  944. end;
  945.  
  946. procedure TRxDrawGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
  947. begin
  948.   if FTracking then TrackButton(X, Y);
  949.   inherited MouseMove(Shift, X, Y);
  950. end;
  951.  
  952. procedure TRxDrawGrid.MouseUp(Button: TMouseButton; Shift: TShiftState;
  953.   X, Y: Integer);
  954. var
  955.   Cell: TGridCoord;
  956.   ACol, ARow: Longint;
  957.   DoClick: Boolean;
  958. begin
  959.   if FTracking and (FPressedCell.Y >= 0) and (FPressedCell.X >= 0) then
  960.   begin
  961.     Cell := MouseCoord(X, Y);
  962.     DoClick := PtInRect(Rect(0, 0, ClientWidth, ClientHeight), Point(X, Y))
  963.       and (Cell.Y = FPressedCell.Y) and (Cell.X = FPressedCell.X);
  964.     StopTracking;
  965.     if DoClick then begin
  966.       ACol := Cell.X;
  967.       ARow := Cell.Y;
  968.       if (ARow < RowCount) and (ACol < ColCount) then
  969.         DoFixedCellClick(ACol, ARow);
  970.     end;
  971.   end
  972.   else if FSwapButtons then begin
  973.     FSwapButtons := False;
  974.     MouseCapture := False;
  975.     if Button = mbRight then Button := mbLeft;
  976.   end;
  977.   inherited MouseUp(Button, Shift, X, Y);
  978. end;
  979.  
  980. procedure TRxDrawGrid.Paint;
  981. var
  982.   R: TRect;
  983. begin
  984.   FDefaultDrawing := inherited DefaultDrawing;
  985.   inherited DefaultDrawing := False;
  986.   try
  987.     inherited Paint;
  988.   finally
  989.     inherited DefaultDrawing := FDefaultDrawing;
  990.   end;
  991.   if not (csDesigning in ComponentState) and DefaultDrawing and Focused and
  992.     ([goRowSelect, goRangeSelect] * Options = [goRowSelect]) then
  993.   begin
  994.     with Canvas do begin
  995.       Font.Color := Self.Font.Color;
  996.       Brush.Color := Self.Color;
  997.     end;
  998.     if Row >= FixedRows then begin
  999.       R := BoxRect(FixedCols, Row, ColCount - 1, Row);
  1000.       if not (goHorzLine in Options) then Inc(R.Bottom, GridLineWidth);
  1001.       DrawFocusRect(Canvas.Handle, R);
  1002.     end;
  1003.   end;
  1004. end;
  1005.  
  1006. procedure TRxDrawGrid.CallDrawCellEvent(ACol, ARow: Longint; ARect: TRect;
  1007.   AState: TGridDrawState);
  1008. begin
  1009.   inherited DrawCell(ACol, ARow, ARect, AState);
  1010. end;
  1011.  
  1012. procedure TRxDrawGrid.DoDrawCell(ACol, ARow: Longint; ARect: TRect;
  1013.   AState: TGridDrawState);
  1014. begin
  1015.   CallDrawCellEvent(ACol, ARow, ARect, AState);
  1016. end;
  1017.  
  1018. procedure TRxDrawGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
  1019.   AState: TGridDrawState);
  1020. var
  1021.   Down: Boolean;
  1022. {$IFDEF WIN32}
  1023.   TempRect: TRect;
  1024.   FrameFlags1, FrameFlags2: DWORD;
  1025. const
  1026.   EdgeFlag: array[Boolean] of UINT = (BDR_RAISEDINNER, BDR_SUNKENINNER);
  1027. {$ENDIF}
  1028. begin
  1029.   if FDefaultDrawing or (csDesigning in ComponentState) then
  1030.     with Canvas do begin
  1031.       Font := Self.Font;
  1032.       if ([goRowSelect, goVertLine] * Options = [goRowSelect]) and
  1033.         not (gdFixed in AState) then Inc(ARect.Right, GridLineWidth);
  1034.       if ([goRowSelect, goHorzLine] * Options = [goRowSelect]) and
  1035.         not (gdFixed in AState) then Inc(ARect.Bottom, GridLineWidth);
  1036.       if (gdSelected in AState) and (not (gdFocused in AState) or
  1037.         ([goDrawFocusSelected, goRowSelect] * Options <> [])) then
  1038.       begin
  1039.         Brush.Color := clHighlight;
  1040.         Font.Color := clHighlightText;
  1041.       end
  1042.       else begin
  1043.         if gdFixed in AState then Brush.Color := FixedColor
  1044.         else Brush.Color := Color;
  1045.       end;
  1046.       FillRect(ARect);
  1047.     end;
  1048.   Down := FFixedCellsButtons and (gdFixed in AState) and Ctl3D and
  1049.     not (csLoading in ComponentState) and FPressed and FDefaultDrawing and
  1050.     (FPressedCell.X = ACol) and (FPressedCell.Y = ARow);
  1051.   inherited DefaultDrawing := FDefaultDrawing;
  1052.   if Down then begin
  1053.     Inc(ARect.Left, GridLineWidth);
  1054.     Inc(ARect.Top, GridLineWidth);
  1055.   end;
  1056.   try
  1057.     DoDrawCell(ACol, ARow, ARect, AState);
  1058.   finally
  1059.     inherited DefaultDrawing := False;
  1060.     if Down then begin
  1061.       Dec(ARect.Left, GridLineWidth);
  1062.       Dec(ARect.Top, GridLineWidth);
  1063.     end;
  1064.   end;
  1065.   if FDefaultDrawing and (gdFixed in AState) and Ctl3D then begin
  1066. {$IFDEF WIN32}
  1067.     FrameFlags1 := 0;
  1068.     FrameFlags2 := 0;
  1069.     if goFixedVertLine in Options then begin
  1070.       FrameFlags1 := BF_RIGHT;
  1071.       FrameFlags2 := BF_LEFT;
  1072.     end;
  1073.     if goFixedHorzLine in Options then begin
  1074.       FrameFlags1 := FrameFlags1 or BF_BOTTOM;
  1075.       FrameFlags2 := FrameFlags2 or BF_TOP;
  1076.     end;
  1077.     if (FrameFlags1 or FrameFlags2) <> 0 then begin
  1078.       TempRect := ARect;
  1079.       if ((FrameFlags1 and BF_RIGHT) = 0) and
  1080.         (goFixedVertLine in Options) then
  1081.         Inc(TempRect.Right, GridLineWidth)
  1082.       else if ((FrameFlags1 and BF_BOTTOM) = 0) and
  1083.         (goFixedVertLine in Options) then
  1084.         Inc(TempRect.Bottom, GridLineWidth);
  1085.       DrawEdge(Canvas.Handle, TempRect, EdgeFlag[Down], FrameFlags1);
  1086.       DrawEdge(Canvas.Handle, TempRect, EdgeFlag[Down], FrameFlags2);
  1087.     end;
  1088. {$ELSE}
  1089.     with Canvas do begin
  1090.       Pen.Color := clBtnHighlight;
  1091.       if FFixedCellsButtons then begin
  1092.         if Down then begin
  1093.           Pen.Color := clBtnShadow;
  1094.           with ARect do begin
  1095.             PolyLine([Point(Left, Bottom - 1), Point(Left, Top),
  1096.               Point(Right, Top)]);
  1097.             Inc(Left, 2); Inc(Top, 2);
  1098.           end;
  1099.         end
  1100.         else Frame3D(Canvas, ARect, clBtnHighlight, clBtnShadow, 1);
  1101.       end
  1102.       else begin
  1103.         Polyline([Point(ARect.Left, ARect.Bottom - 1), ARect.TopLeft,
  1104.           Point(ARect.Right, ARect.Top)]);
  1105.       end;
  1106.     end;
  1107. {$ENDIF WIN32}
  1108.   end;
  1109.   if FDefaultDrawing and not (csDesigning in ComponentState) and
  1110.     (gdFocused in AState) and
  1111.     ([goEditing, goAlwaysShowEditor] * Options <>
  1112.     [goEditing, goAlwaysShowEditor])
  1113.     and not (goRowSelect in Options) then
  1114.     DrawFocusRect(Canvas.Handle, ARect);
  1115. end;
  1116.  
  1117. {$IFDEF WIN32}
  1118. procedure TRxDrawGrid.WMRButtonUp(var Message: TWMMouse);
  1119. begin
  1120.   if not (FGridState in [gsColMoving, gsRowMoving]) then
  1121.     inherited
  1122.   else if not (csNoStdEvents in ControlStyle) then
  1123.     with Message do MouseUp(mbRight, KeysToShiftState(Keys), XPos, YPos);
  1124. end;
  1125. {$ENDIF}
  1126.  
  1127. procedure TRxDrawGrid.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  1128. var
  1129.   Cell: TGridCoord;
  1130. {$IFNDEF WIN32}
  1131.   Form: TForm;
  1132. {$ENDIF}
  1133. begin
  1134.   if FFixedCellsButtons then begin
  1135.     with Message do
  1136.       Cell := MouseCoord(XPos, YPos);
  1137.     if ((Cell.X >= 0) and (Cell.X < FixedCols)) or
  1138.       ((Cell.Y >= 0) and (Cell.Y < FixedRows)) then
  1139.     begin
  1140. {$IFDEF WIN32}
  1141.       SendCancelMode(Self);
  1142. {$ELSE}
  1143.       Form := GetParentForm(Self);
  1144.       if Form <> nil then Form.SendCancelMode(Self);
  1145. {$ENDIF}
  1146.       if csCaptureMouse in ControlStyle then MouseCapture := True;
  1147. {$IFDEF WIN32}
  1148.       if not (csNoStdEvents in ControlStyle) then
  1149. {$ENDIF}
  1150.         with Message do
  1151.           MouseDown(mbLeft, KeysToShiftState(Keys) - [ssDouble], XPos, YPos);
  1152.       Exit;
  1153.     end;
  1154.   end;
  1155.   inherited;
  1156. end;
  1157.  
  1158. procedure TRxDrawGrid.WMKillFocus(var Msg: TWMKillFocus);
  1159. begin
  1160.   inherited;
  1161.   if Assigned(FOnChangeFocus) then FOnChangeFocus(Self);
  1162. end;
  1163.  
  1164. procedure TRxDrawGrid.WMSetFocus(var Msg: TWMSetFocus);
  1165. begin
  1166.   inherited;
  1167.   if Assigned(FOnChangeFocus) then FOnChangeFocus(Self);
  1168. end;
  1169.  
  1170. procedure TRxDrawGrid.WMCancelMode(var Message: TMessage);
  1171. begin
  1172.   StopTracking;
  1173.   inherited;
  1174. end;
  1175.  
  1176. function TRxDrawGrid.CreateEditor: TInplaceEdit;
  1177. begin
  1178. {$IFDEF WIN32}
  1179.   Result := TRxInplaceEdit.Create(Self);
  1180. {$ELSE}
  1181.   Result := inherited CreateEditor;
  1182. {$ENDIF}
  1183.   TEdit(Result).OnChange := EditChanged;
  1184. end;
  1185.  
  1186. {$IFDEF WIN32}
  1187.  
  1188. function TRxDrawGrid.GetEditAlignment(ACol, ARow: Longint): TAlignment;
  1189. begin
  1190.   Result := taLeftJustify;
  1191.   if Assigned(FOnGetEditAlign) then FOnGetEditAlign(Self, ACol, ARow, Result);
  1192. end;
  1193.  
  1194. function TRxDrawGrid.GetEditStyle(ACol, ARow: Longint): TInplaceEditStyle;
  1195. begin
  1196.   Result := esSimple;
  1197.   if Assigned(FOnGetEditStyle) then FOnGetEditStyle(Self, ACol, ARow, Result);
  1198. end;
  1199.  
  1200. procedure TRxDrawGrid.GetPicklist(ACol, ARow: Longint; PickList: TStrings);
  1201. begin
  1202.   if Assigned(FOnGetPicklist) then FOnGetPicklist(Self, ACol, ARow, PickList);
  1203. end;
  1204.  
  1205. procedure TRxDrawGrid.EditButtonClick;
  1206. begin
  1207.   if Assigned(FOnEditButtonClick) then FOnEditButtonClick(Self);
  1208. end;
  1209.  
  1210. {$ENDIF}
  1211.  
  1212. end.