{$I OVC.INC}

{$B-} {Complete Boolean Evaluation}
{$I+} {Input/Output-Checking}
{$P+} {Open Parameters}
{$T-} {Typed @ Operator}
{$W-} {Windows Stack Frame}
{$X+} {Extended Syntax}

{$IFNDEF Win32}
{$G+} {286 Instructions}
{$N+} {Numeric Coprocessor}

{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
{$ENDIF}

{*********************************************************}
{*                  OVCTABLE.PAS 2.00                    *}
{*       Copyright (c) TurboPower Software Co 1995       *}
{*                 All rights reserved.                  *}
{*********************************************************}

{$IFDEF Win32}
  {$R OVCTABLE.R32} {Glyphs for cells; cursors for table}
{$ELSE}
  {$R OVCTABLE.R16} {Glyphs for cells; cursors for table}
{$ENDIF}

unit OvcTable;
  {Orpheus table definitions}

interface

uses
  {$IFDEF Win32}
  Windows,
  {$ELSE}
  WinTypes, WinProcs,
  {$ENDIF}
  SysUtils, Messages,
  Graphics, Classes, Controls, Forms, StdCtrls, Menus,     DIALOGS,
  OvcMisc, OvcData, OvcConst, OvcBase, OvcCmd,
  OvcTCmmn, OvcSpAry, OvcTCAry, OvcTSelL, OvcTCell, OvcTCHdr,
  OvcTGRes, OvcTGPns, OvcTbClr, OvcTbRws, OvcTbCls;

const
  loadmessage = $3434;


type
  TOvcCustomTable = class(TOvcTableAncestor)
    {-The custom class for tables}
    protected {private}
      {.Z+}
      {property fields - even size}
      FActiveCol      : TColNum;             {column of active cell}
      FActiveRow      : TRowNum;             {row of active cell}
      FBlockColBegin  : TColNum;             {start column for settings}
      FBlockColEnd    : TColNum;             {end column for settings}
      FBlockRowBegin  : TRowNum;             {start row for settings}
      FBlockRowEnd    : TRowNum;             {end row for settings}
      FCells          : TOvcTableCells;      {independent cells}
      FColors         : TOvcTableColors;     {table cell colors}
      FCols           : TOvcTableColumns;    {table column definitions}
      FGridPenSet     : TOvcGridPenSet;      {set of grid pens}
      FLeftCol        : TColNum;             {leftmost column}
      FLockedCols     : TColNum;             {number of locked columns}
      FLockedRows     : TRowNum;             {number of locked rows}
      FLockedRowsCell : TOvcBaseTableCell;   {cell for column headings}
      FRows           : TOvcTableRows;       {table row definitions}
      FSelAnchorCol   : TColNum;             {selection: anchor column}
      FSelAnchorRow   : TRowNum;             {selection: anchor row}
      FTopRow         : TRowNum;             {topmost row}
      FColorUnused    : TColor;              {color of unused area}

      {property fields - odd size}
      FAccess      : TOvcTblAccess;          {default access mode for the table}
      FAdjust      : TOvcTblAdjust;          {default adjustment for the table}
      FBorderStyle : TBorderStyle;           {border type around table}
      FOptions     : TOvcTblOptionSet;       {set of table options}
      FScrollBars  : TScrollStyle;           {scroll bar presence}
      Filler       : byte;

      {property event fields}
      FActiveCellChanged  : TCellNotifyEvent;       {active cell changed event}
      FActiveCellMoving   : TCellMoveNotifyEvent;   {active cell moving event}
      FBeginEdit          : TCellBeginEditNotifyEvent;{active cell about to be edited}
      FClipboardCopy      : TNotifyEvent;           {copy to clipboard requested}
      FClipboardCut       : TNotifyEvent;           {cut to clipboard requested}
      FClipboardPaste     : TNotifyEvent;           {paste from clipboard requested}
      FColumnsChanged     : TColChangeNotifyEvent;  {column insert/delete/exchange}
      FDoneEdit           : TCellNotifyEvent;       {active cell has been edited}
      FEndEdit            : TCellEndEditNotifyEvent;{active cell about to be stopped being edited}
      FEnteringColumn     : TColNotifyEvent;        {entering column event}
      FEnteringRow        : TRowNotifyEvent;        {entering row event}
      FGetCellData        : TCellDataNotifyEvent;   {get cell data event}
      FGetCellAttributes  : TCellAttrNotifyEvent;   {get cell attributes event}
      FLeavingColumn      : TColNotifyEvent;        {leaving column event}
      FLeavingRow         : TRowNotifyEvent;        {leaving row event}
      FLockedCellClick    : TCellNotifyEvent;       {locked cell clicked event}
      FPaintUnusedArea    : TNotifyEvent;           {unused bit needs painting event}
      FRowsChanged        : TRowChangeNotifyEvent;  {row insert/delete/exchange}
      FSizeCellEditor     : TSizeCellEditorNotifyEvent;{sizing of cell editor}
      FTopLeftCellChanged : TCellNotifyEvent;       {top left cell change event}
      FTopLeftCellChanging: TCellChangeNotifyEvent; {top left cell moving event}
      FUserCommand        : TUserCommandEvent;      {user command event}

      {other fields - even size}
      tbColNums : POvcTblDisplayArray;  {displayed column numbers}
      tbRowNums : POvcTblDisplayArray;  {displayed row numbers}
      tbRowsOnLastPage : TRowNum;       {number of complete rows on last page}
      tbLastTopRow : TRowNum;           {the last row number that can be top}
      tbColsOnLastPage : TRowNum;       {num of complete columns on rightmost page}
      tbLastLeftCol : TRowNum;          {the last column number that can be leftmost}
      tbLockCount : integer;            {the lock display count}
      tbCmdTable : PString;             {the command table name for the grid}
      tbState : TOvcTblStates;          {the state of the table}
      tbSizeOffset : integer;           {the offset of the sizing line}
      tbSizeIndex  : integer;           {the index of the sized row/col}
      tbMoveIndex : integer;            {the index of the column being moved}
      tbMoveIndexTo : integer;          {the index of the column being targeted by move}
      tbLastEntRow : TRowNum;           {last row that was entered}
      tbLastEntCol : TColNum;           {last column that was entered}
      tbActCell : TOvcBaseTableCell;    {the active cell object}
      tbInvCells : TOvcCellArray;       {cells that need repainting}
      tbSelList : TOvcSelectionList;    {list of selected cells}
      tbCellAttrFont : TFont;           {cached font for painting cells}
      tbColMoveCursor : HCursor;        {cursor for column moves}
      tbRowMoveCursor : HCursor;        {cursor for row moves}
      tbHSBarPosCount : integer;        {number of positions for horz scrollbar}

      {other fields - odd size}
      tbHasHSBar : boolean;             {true if horiz scroll bar present}
      tbHasVSBar : boolean;             {true if vert scroll bar present}
      tbUpdateSBs : boolean;            {true if the scroll bars must be updated}
      tbIsSelecting : boolean;          {is in mouse selection mode}
      tbIsDeselecting : boolean;        {is in mouse deselection mode}
      tbIsKeySelecting : boolean;       {is in key selection mode}
      tbMustUpdate : boolean;           {scrolling has left an invalid region}
      tbMustFinishLoading : boolean;    {finish loading data in CreateWnd}
      {.Z-}

    protected
      {.Z+}
      {property read routines}
      function GetAllowRedraw : boolean;
      function GetColCount : TColNum;
      function GetColOffset(ColNum : TColNum) : integer;
      function GetRowLimit : TRowNum;
      function GetRowOffset(RowNum : TRowNum) : integer;

      {property write routines}
      procedure SetAccess(A : TOvcTblAccess);
      procedure SetActiveCol(ColNum : TColNum);
      procedure SetActiveRow(RowNum : TRowNum);
      procedure SetAdjust(A : TOvcTblAdjust);
      procedure SetAllowRedraw(AR : boolean);
      procedure SetBorderStyle(const BS : TBorderStyle);
      procedure SetBlockAccess(A : TOvcTblAccess);
      procedure SetBlockAdjust(A : TOvcTblAdjust);
      procedure SetBlockCell(C : TOvcBaseTableCell);
      procedure SetBlockColBegin(ColNum : TColNum);
      procedure SetBlockColEnd(ColNum : TColNum);
      procedure SetBlockColor(C : TColor);
      procedure SetBlockFont(F : TFont);
      procedure SetBlockRowBegin(RowNum : TRowNum);
      procedure SetBlockRowEnd(RowNum : TRowNum);
      procedure SetColors(C : TOvcTableColors);
      procedure SetColCount(CC : integer);
      procedure SetCols(CS : TOvcTableColumns);
      procedure SetLeftCol(ColNum : TColNum);
      procedure SetLockedCols(ColNum : TColNum);
      procedure SetLockedRows(RowNum : TRowNum);
      procedure SetLockedRowsCell(C : TOvcBaseTableCell);
      procedure SetOptions(O : TOvcTblOptionSet);
      procedure SetPaintUnusedArea(PUA : TNotifyEvent);
      procedure SetRowLimit(RowNum : TRowNum);
      procedure SetRows(RS : TOvcTableRows);
      procedure SetScrollBars(const SB : TScrollStyle);
      procedure SetTopRow(RowNum : TRowNum);
      procedure SetColorUnused(CU : TColor);

      {overridden Delphi VCL methods}
      procedure ChangeScale(M, D : integer); override;
      procedure Notification(AComponent: TComponent; Operation: TOperation); override;

      {general methods}
      function  tbCalcActiveCellRect(var ACR : TRect) : boolean;
      function  tbCalcCellsFromRect(const UR : TRect; var GR : TRect) : integer;
      procedure tbCalcColData(var CD : POvcTblDisplayArray; NewLeftCol : TColNum);
      procedure tbCalcColsOnLastPage;
      procedure tbCalcRowData(var RD : POvcTblDisplayArray; NewTopRow : TRowNum);
      procedure tbCalcRowsOnLastPage;
      procedure tbCalcHSBarPosCount;

      procedure tbDrawActiveCell;
      procedure tbDrawCells(RowInxStart, RowInxEnd : integer;
                            ColInxStart, ColInxEnd : integer);
      procedure tbDrawInvalidCells(InvCells : TOvcCellArray);
      procedure tbDrawMoveLine;
      procedure tbDrawRow(RowInx : integer; ColInxStart, ColInxEnd : integer);
      procedure tbDrawSizeLine;
      procedure tbDrawUnusedBit;

      function  tbEditCellHasFocus(FocusHandle : HWND) : boolean;
      procedure tbEnsureColumnIsVisible(ColNum : TColNum);
      procedure tbEnsureRowIsVisible(RowNum : TRowNum);

      function  tbFindCell(RowNum : TRowNum;
                           ColNum : TColNum) : TOvcBaseTableCell;
      function  tbFindColInx(ColNum : TColNum) : integer;
      function  tbFindRowInx(RowNum : TRowNum) : integer;

      function  tbIsOnGridLine(MouseX, MouseY : integer;
                               var VerticalGrid : boolean) : boolean;
      function  tbIsInMoveArea(MouseX, MouseY : integer;
                           var IsColMove : boolean) : boolean;
      procedure tbSetActiveCellPrim(RowNum : TRowNum; ColNum : TColNum);

      {selection methods}
      procedure tbDeselectAll(CA : TOvcCellArray);
      function tbDeselectAllIterator(RowNum1 : TRowNum; ColNum1 : TColNum;
                                     RowNum2 : TRowNum; ColNum2 : TColNum;
                                     ExtraData : pointer) : boolean;
      procedure tbSelectCol(ColNum : TColNum);
      procedure tbSelectRow(RowNum : TRowNum);
      procedure tbSelectTable;
      procedure tbSetAnchorCell(RowNum : TRowNum; ColNum : TColNum;
                                Action : TOvcTblSelectionType);
      procedure tbUpdateSelection(RowNum : TRowNum; ColNum : TColNum;
                                  Action : TOvcTblSelectionType);

      {notification procedures}
      procedure DoActiveCellChanged(RowNum : TRowNum; ColNum : TColNum);
        virtual;
      procedure DoActiveCellMoving(Command : word; var RowNum : TRowNum;
                                   var ColNum : TColNum); virtual;
      procedure DoBeginEdit(RowNum : TRowNum; ColNum : TColNum;
                            var AllowIt : boolean); virtual;
      procedure DoClipboardCopy; virtual;
      procedure DoClipboardCut; virtual;
      procedure DoClipboardPaste; virtual;
      procedure DoColumnsChanged(ColNum1, ColNum2 : TColNum;
                                 Action : TOvcTblActions); virtual;
      procedure DoDoneEdit(RowNum : TRowNum; ColNum : TColNum); virtual;
      procedure DoEndEdit(Cell : TOvcBaseTableCell;
                          RowNum : TRowNum; ColNum : TColNum;
                          var AllowIt : boolean); virtual;
      procedure DoEnteringColumn(ColNum : TColNum); virtual;
      procedure DoEnteringRow(RowNum : TRowNum); virtual;
      procedure DoGetCellAttributes(RowNum : TRowNum; ColNum : TColNum;
                                    var CellAttr : TOvcCellAttributes); virtual;
      procedure DoGetCellData(RowNum : TRowNum; ColNum : TColNum;
                              var Data : pointer;
                              Purpose : TOvcCellDataPurpose); virtual;
      procedure DoLeavingColumn(ColNum : TColNum); virtual;
      procedure DoLeavingRow(RowNum : TRowNum); virtual;
      procedure DoLockedCellClick(RowNum : TRowNum; ColNum : TColNum); virtual;
      procedure DoPaintUnusedArea; virtual;
      procedure DoRowsChanged(RowNum1, RowNum2 : TRowNum;
                              Action : TOvcTblActions); virtual;
      procedure DoSizeCellEditor(RowNum   : TRowNum;
                                 ColNum   : TColNum;
                             var CellRect : TRect;
                             var CellStyle: TOvcTblEditorStyle); virtual;
      procedure DoTopLeftCellChanged(RowNum : TRowNum; ColNum : TColNum); virtual;
      procedure DoTopLeftCellChanging(var RowNum : TRowNum;
                                      var ColNum : TColNum); virtual;
      procedure DoUserCommand(Cmd : word); virtual;

      {row/col data retrieval}
      function tbIsColHidden(ColNum : TColNum) : boolean;
      function tbIsRowHidden(RowNum : TRowNum) : boolean;
      procedure tbQueryColData(ColNum : TColNum;
                           var W : integer;
                           var A : TOvcTblAccess;
                           var H : boolean);
      procedure tbQueryRowData(RowNum : TRowNum;
                           var Ht: integer;
                           var H : boolean);

      {invalidation}
      procedure tbInvalidateColHdgPrim(ColNum : TColNum; InvCells : TOvcCellArray);
      procedure tbInvalidateRowHdgPrim(RowNum : TRowNum; InvCells : TOvcCellArray);

      {scrollbar stuff}
      procedure tbSetScrollPos(SB : TOvcScrollBar);
      procedure tbSetScrollRange(SB : TOvcScrollBar);

      {active cell movement}
      procedure tbMoveActCellBotOfPage;
      procedure tbMoveActCellBotRight;
      procedure tbMoveActCellDown;
      procedure tbMoveActCellFirstCol;
      procedure tbMoveActCellFirstRow;
      procedure tbMoveActCellLastCol;
      procedure tbMoveActCellLastRow;
      procedure tbMoveActCellLeft;
      procedure tbMoveActCellPageDown;
      procedure tbMoveActCellPageLeft;
      procedure tbMoveActCellPageRight;
      procedure tbMoveActCellPageUp;
      procedure tbMoveActCellRight;
      procedure tbMoveActCellTopLeft;
      procedure tbMoveActCellTopOfPage;
      procedure tbMoveActCellUp;

      {scrollbar scrolling routine}
      procedure tbScrollBarDown;
      procedure tbScrollBarLeft;
      procedure tbScrollBarPageDown;
      procedure tbScrollBarPageLeft;
      procedure tbScrollBarPageRight;
      procedure tbScrollBarPageUp;
      procedure tbScrollBarRight;
      procedure tbScrollBarUp;

      {table scrolling routines}
      procedure tbScrollTableLeft(NewLeftCol : TColNum);
      procedure tbScrollTableRight(NewLeftCol : TColNum);
      procedure tbScrollTableUp(NewTopRow : TRowNum);
      procedure tbScrollTableDown(NewTopRow : TRowNum);

      {notifications}
      procedure tbCellChanged(Sender : TObject); override;
      procedure tbColChanged(Sender : TObject; ColNum1, ColNum2 : TColNum;
                             Action : TOvcTblActions);
      procedure tbGridPenChanged(Sender : TObject);
      procedure tbRowChanged(Sender : TObject; RowNum1, RowNum2 : TRowNum;
                             Action : TOvcTblActions);
      procedure tbColorsChanged(Sender : TObject);

      {streaming routines}
      procedure DefineProperties(Filer : TFiler); override;
      procedure tbFinishLoadingDefaultCells;
      procedure tbReadColData(Reader : TReader);
      procedure tbReadRowData(Reader : TReader);
      procedure tbWriteColData(Writer : TWriter);
      procedure tbWriteRowData(Writer : TWriter);

      {Cell-Table interaction messages}
      {$IFDEF Win32}
      procedure ctimLoadDefaultCells(var Msg : TMessage); message ctim_LoadDefaultCells;
      {$ENDIF}
      procedure ctimQueryOptions(var Msg : TMessage); message ctim_QueryOptions;
      procedure ctimQueryColor(var Msg : TMessage); message ctim_QueryColor;
      procedure ctimQueryFont(var Msg : TMessage); message ctim_QueryFont;
      procedure ctimQueryLockedCols(var Msg : TMessage); message ctim_QueryLockedCols;
      procedure ctimQueryLockedRows(var Msg : TMessage); message ctim_QueryLockedRows;
      procedure ctimQueryActiveCol(var Msg : TMessage); message ctim_QueryActiveCol;
      procedure ctimQueryActiveRow(var Msg : TMessage); message ctim_QueryActiveRow;
      procedure ctimRemoveCell(var Msg : TMessage); message ctim_RemoveCell;
      procedure ctimStartEdit(var Msg : TMessage); message ctim_StartEdit;
      procedure ctimStartEditMouse(var Msg : TWMMouse); message ctim_StartEditMouse;
      procedure ctimStartEditKey(var Msg : TWMKey); message ctim_StartEditKey;

      {Delphi component messages}
      procedure CMColorChanged(var Msg : TMessage); message CM_COLORCHANGED;
      procedure CMDesignHitTest(var Msg : TCMDesignHitTest); message CM_DESIGNHITTEST;
      procedure CMFontChanged(var Msg : TMessage); message CM_FONTCHANGED;

      {Windows messages}
      procedure WMCancelMode(var Msg : TMessage); message WM_CANCELMODE;
      procedure WMEraseBkGnd(var Msg : TWMEraseBkGnd); message WM_ERASEBKGND;
      procedure WMGetDlgCode(var Msg : TMessage); message WM_GETDLGCODE;
      procedure WMHScroll(var Msg : TWMScroll); message WM_HSCROLL;
      procedure WMKeyDown(var Msg : TWMKey); message WM_KEYDOWN;
      procedure WMKillFocus(var Msg : TWMKillFocus); message WM_KILLFOCUS;
      procedure WMLButtonDblClk(var Msg : TWMMouse); message WM_LBUTTONDBLCLK;
      procedure WMLButtonDown(var Msg : TWMMouse); message WM_LBUTTONDOWN;
      procedure WMLButtonUp(var Msg : TWMMouse); message WM_LBUTTONUP;
      procedure WMMouseMove(var Msg : TWMMouse); message WM_MOUSEMOVE;
      procedure WMNCHitTest(var Msg : TMessage); message WM_NCHITTEST;
      procedure WMSetCursor(var Msg : TWMSetCursor); message WM_SETCURSOR;
      procedure WMSetFocus(var Msg : TWMSetFocus); message WM_SETFOCUS;
      procedure WMVScroll(var Msg : TWMScroll); message WM_VSCROLL;
      {.Z-}

      {unpublishable or should not be published properties}
      property AllowRedraw : boolean
         read GetAllowRedraw write SetAllowRedraw
         stored false;

      property BlockAccess : TOvcTblAccess
         write SetBlockAccess;

      property BlockAdjust : TOvcTblAdjust
         write SetBlockAdjust;

      property BlockColBegin : TColNum
         read FBlockColBegin write SetBlockColBegin;

      property BlockColEnd : TColNum
         read FBlockColEnd write SetBlockColEnd;

      property BlockColor : TColor
         write SetBlockColor;

      property BlockCell : TOvcBaseTableCell
         write SetBlockCell;

      property BlockFont : TFont
         write SetBlockFont;

      property BlockRowBegin : TRowNum
         read FBlockRowBegin write SetBlockRowBegin;

      property BlockRowEnd : TRowNum
         read FBlockRowEnd write SetBlockRowEnd;

      property ColOffset [ColNum : TColNum] : integer
         read GetColOffset;

      property RowOffset [RowNum : TRowNum] : integer
         read GetRowOffset;

      property TableState : TOvcTblStates
         read tbState;

      {publishable properties}
      property Access : TOvcTblAccess
         read FAccess write SetAccess
         default DefAccess;

      property ActiveCol : TColNum
         read FActiveCol write SetActiveCol
         default DefLockedCols;

      property ActiveRow : TRowNum
         read FActiveRow write SetActiveRow
         default DefLockedRows;

      property Adjust : TOvcTblAdjust
         read FAdjust write SetAdjust
         default DefAdjust;

      property BorderStyle : TBorderStyle
         read FBorderStyle write SetBorderStyle
         default DefBorderStyle;

      property ColCount : TColNum
         read GetColCount write SetColCount;

      property Colors : TOvcTableColors
         read FColors write SetColors;

      property ColorUnused : TColor
         read FColorUnused write SetColorUnused
         default clWindow;

      property Columns : TOvcTableColumns
         read FCols write SetCols;

      property GridPenSet : TOvcGridPenSet
         read FGridPenSet write FGridPenSet;

      property LeftCol : TColNum
         read FLeftCol write SetLeftCol
         default DefLockedCols;

      property LockedCols : TColNum
         read FLockedCols write SetLockedCols
         default DefLockedCols;

      property LockedRows : TRowNum
         read FLockedRows write SetLockedRows
         default DefLockedRows;

      property LockedRowsCell : TOvcBaseTableCell
         read FLockedRowsCell write SetLockedRowsCell;

      property Options : TOvcTblOptionSet
         read FOptions write SetOptions;

      property RowLimit : TRowNum
         read GetRowLimit write SetRowLimit;

      property Rows : TOvcTableRows
         read FRows write SetRows;

      property ScrollBars : TScrollStyle
         read FScrollBars write SetScrollBars
         default DefScrollBars;

      property TopRow : TRowNum
         read FTopRow write SetTopRow
         default DefLockedRows;

      {New events}
      property OnActiveCellChanged : TCellNotifyEvent
         read FActiveCellChanged write FActiveCellChanged;

      property OnActiveCellMoving : TCellMoveNotifyEvent
         read FActiveCellMoving write FActiveCellMoving;

      property OnBeginEdit : TCellBeginEditNotifyEvent
         read FBeginEdit write FBeginEdit;

      property OnClipboardCopy : TNotifyEvent
         read FClipboardCopy write FClipboardCopy;

      property OnClipboardCut : TNotifyEvent
         read FClipboardCut write FClipboardCut;

      property OnClipboardPaste : TNotifyEvent
         read FClipboardPaste write FClipboardPaste;

      property OnColumnsChanged : TColChangeNotifyEvent
         read FColumnsChanged write FColumnsChanged;

      property OnDoneEdit : TCellNotifyEvent
         read FDoneEdit write FDoneEdit;

      property OnEndEdit : TCellEndEditNotifyEvent
         read FEndEdit write FEndEdit;

      property OnEnteringColumn : TColNotifyEvent
         read FEnteringColumn write FEnteringColumn;

      property OnEnteringRow : TRowNotifyEvent
         read FEnteringRow write FEnteringRow;

      property OnGetCellData : TCellDataNotifyEvent
         read FGetCellData write FGetCellData;

      property OnGetCellAttributes : TCellAttrNotifyEvent
         read FGetCellAttributes write FGetCellAttributes;

      property OnLeavingColumn : TColNotifyEvent
         read FLeavingColumn write FLeavingColumn;

      property OnLeavingRow : TRowNotifyEvent
         read FLeavingRow write FLeavingRow;

      property OnLockedCellClick : TCellNotifyEvent
         read FLockedCellClick write FLockedCellClick;

      property OnPaintUnusedArea : TNotifyEvent
         read FPaintUnusedArea write SetPaintUnusedArea;

      property OnRowsChanged : TRowChangeNotifyEvent
         read FRowsChanged write FRowsChanged;

      property OnSizeCellEditor : TSizeCellEditorNotifyEvent
         read FSizeCellEditor write FSizeCellEditor;

      property OnTopLeftCellChanged : TCellNotifyEvent
         read FTopLeftCellChanged write FTopLeftCellChanged;

      property OnTopLeftCellChanging : TCellChangeNotifyEvent
         read FTopLeftCellChanging write FTopLeftCellChanging;

      property OnUserCommand : TUserCommandEvent
         read FUserCommand write FUserCommand;

    public
      {overridden methods}
      constructor Create(AOwner : TComponent); override;
      destructor Destroy; override;
      procedure CreateParams(var Params : TCreateParams); override;
      procedure CreateWnd; override;
      procedure Loaded; override;
      procedure Paint; override;
      procedure SetBounds(ALeft, ATop, AWidth, AHeight: integer); override;

      {new public methods}
      function CalcRowColFromXY(X, Y : integer;
                                var RowNum : TRowNum;
                                var ColNum : TColNum) : TOvcTblRegion;
      function FilterKey(var Msg : TWMKey) : TOvcTblKeyNeeds; override;
      procedure GetDisplayedColNums(var NA : TOvcTableNumberArray);
      procedure GetDisplayedRowNums(var NA : TOvcTableNumberArray);
      procedure ResolveCellAttributes(RowNum : TRowNum; ColNum : TColNum;
                                      var CellAttr : TOvcCellAttributes); override;

      {methods for setting cells, faster than setting row/col properties}
      procedure SetActiveCell(RowNum : TRowNum; ColNum : TColNum);
      procedure SetTopLeftCell(RowNum : TRowNum; ColNum : TColNum);

      {methods for calculating next/prev row/col numbers for main area}
      function IncCol(ColNum : TColNum; Direction : integer) : TColNum;
      function IncRow(RowNum : TRowNum; Direction : integer) : TRowNum;

      {methods for invalidating cells to force a redraw}
      procedure InvalidateCell(RowNum : TRowNum; ColNum : TColNum);
      procedure InvalidateColumn(ColNum : TColNum);
      procedure InvalidateRow(RowNum : TRowNum);
      procedure InvalidateTable;
      {.Z+}
      procedure InvalidateCellsInRect(const R : TRect);
      procedure InvalidateColumnHeading(ColNum : TColNum);
      procedure InvalidateRowHeading(RowNum : TRowNum);
      procedure InvalidateTableNotLockedCols;
      procedure InvalidateTableNotLockedRows;
      {.Z-}

      {selection methods}
      function HaveSelection : boolean;
      function InSelection(RowNum : TRowNum; ColNum : TColNum) : boolean;
      procedure IterateSelections(SI : TSelectionIterator; ExtraData : pointer);

      {editing state method}
      function InEditingState : boolean;
      function SaveEditedData : boolean;
      function StartEditingState : boolean;
      function StopEditingState(SaveValue : boolean) : boolean;

      {scrollbar scrolling routine}
      procedure ProcessScrollBarClick(ScrollBar : TOvcScrollBar;
                                      ScrollCode : TScrollCode); virtual;

      {active cell movement routine}
      procedure MoveActiveCell(Command : word); virtual;

      {public property}
      property Cells : TOvcTableCells
         read FCells;


    end;

  TOvcTable = class(TOvcCustomTable)
    public
      property AllowRedraw;
      property BlockAccess;
      property BlockAdjust;
      property BlockColBegin;
      property BlockColEnd;
      property BlockColor;
      property BlockCell;
      property BlockFont;
      property BlockRowBegin;
      property BlockRowEnd;
      property Canvas;
      property ColOffset;
      property RowOffset;
      property TableState;
    published
      {Properties}
      property RowLimit;
      property LockedRows;
      property TopRow;
      property ActiveRow;

      property LockedCols;
      property LeftCol;
      property ActiveCol;

      property Access;
      property Adjust;
      property Align;
      property BorderStyle;
      property ColCount stored false; {it's stored elsewhere}
      property Color default DefTableColor;
      property ColorUnused;
      property Colors;
      property Columns;
      property Controller;
      property Ctl3D;
      property DragCursor;
      property DragMode;
      property Enabled;
      property Font;
      property GridPenSet;
      property LockedRowsCell;
      property Options;
      property ParentColor default false;
      property ParentCtl3D;
      property ParentFont;
      property ParentShowHint;
      property PopupMenu;
      property Rows;
      property ScrollBars;
      property ShowHint;
      property TabOrder;
      property TabStop default true;
      property Visible;

      {Events}
      property OnActiveCellChanged;
      property OnActiveCellMoving;
      property OnBeginEdit;
      property OnClipboardCopy;
      property OnClipboardCut;
      property OnClipboardPaste;
      property OnColumnsChanged;
      property OnDblClick;
      property OnDoneEdit;
      property OnDragDrop;
      property OnDragOver;
      property OnEndDrag;
      property OnEndEdit;
      property OnEnter;
      property OnEnteringColumn;
      property OnEnteringRow;
      property OnExit;
      property OnGetCellData;
      property OnGetCellAttributes;
      property OnKeyDown;
      property OnKeyPress;
      property OnKeyUp;
      property OnLeavingColumn;
      property OnLeavingRow;
      property OnLockedCellClick;
      property OnMouseDown;
      property OnMouseMove;
      property OnMouseUp;
      property OnPaintUnusedArea;
      property OnRowsChanged;
      property OnSizeCellEditor;
      property OnTopLeftCellChanged;
      property OnTopLeftCellChanging;
      property OnUserCommand;
    end;

implementation
