{$I OVC.INC}

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

{$IFNDEF Win32}
{$G+} {286 Instructions}
{$N+} {Numeric Coprocessor}
{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
{$ENDIF}

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

unit OvcDbTbl;
  {data-aware table}

interface

uses
  {$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  Buttons, Classes, Controls, DB, DBTables, Forms, Graphics,
  Menus, Messages, SysUtils, StdCtrls,
  OvcBase, OvcCmd, OvcConst, OvcData, OvcExcpt, OvcMisc,
  OvcTCBEF, OvcTCell, OvcTBClr, OvcTBCls, OvcTCmmn, OvcTGPns,
  STDate;

const
  {field types where editing is supported}
  SupportedFieldTypes : set of TFieldType = [ftString, ftSmallInt,
    ftInteger, ftWord, ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate,
    ftTime, ftDateTime];

type
  {data-aware table options}
  TOvcDbTableOptions = (dtoCellsPaintText, dtoAllowColumnMove,
    dtoAllowColumnSize, dtoAlwaysEditing, dtoHighlightActiveRow,
    dtoIntegralHeight, dtoEnterToTab, dtoPageScroll,
    dtoShowIndicators, dtoShowPictures, dtoStretch, dtoWantTabs,
    dtoWrapAtEnds);
  TOvcDbTableOptionSet = set of TOvcDbTableOptions;

  {header options}
  TOvcHeaderOptions = (hoShowHeader, hoUseHeaderCell, hoUseLetters, hoUseStrings);
  TOvcHeaderOptionSet = set of TOvcHeaderOptions;

  {date or time edit options for datetime fields}
  TDateOrTime = (dtUseDate, dtUseTime);

const
  DefColorUnused        = clWindow;
  DefColumnCount        = 1;
  DefDateOrTime         = dtUseDate;
  DefDefaultMargin      = 4;
  DefHeaderHeight       = 21;
  DefHeaderOptions      = [hoShowHeader];
  DefHitMargin          = 4;
  DefIndicatorWidth     = 11;
  DefLeftColumn         = 0;
  DefMapSize            = 16;
  DefOptions            = [dtoShowIndicators];
  DefParentColor        = False;
  DefRowHeight          = 21;
  DefTabStop            = True;
  DefTextStyle          = tsFlat;
  DefWantTabs           = False;

type
  TOvcCustomDbTable = class;

  {.Z+}
  TOvcDbTableDataLink = class(TDataLink)
  protected {private }
    {property variables}
    FFieldCount   : Integer;
    FFieldMap     : Pointer;
    FFieldMapSize : Integer;
    FInUpdateData : Boolean;
    FMapBuilt     : Boolean;
    FModified     : Boolean;
    FTable        : TOvcCustomDbTable;

    {property methods}
    function GetDefaultFields : Boolean;
    function GetFields(Index : Integer) : TField;

  protected
    procedure ActiveChanged;
      override;
    procedure DataSetChanged;
      override;
    procedure DataSetScrolled(Distance : Integer);
      override;
    procedure EditingChanged;
      override;
    procedure LayoutChanged;
      override;
    procedure RecordChanged(Field : TField);
      override;
    procedure UpdateData;
      override;

  public
    constructor Create(ATable : TOvcCustomDbTable);
    destructor Destroy;
      override;

    function AddMapping(const FieldName : string) : Boolean;
    procedure ClearFieldMappings;
    procedure Modified;
    procedure Reset;

    {properties}
    property DefaultFields : Boolean
      read GetDefaultFields;
    property FieldCount : Integer
      read FFieldCount;
    property Fields[Index : Integer] : TField
      read GetFields;
  end;
  {.Z-}


  TOvcDbTableColumn = class(TOvcTableColumn)
  {.Z+}
  protected {private}
    {properties}
    FDataField    : string;      {database field name}
    FDateOrTime   : TDateOrTime; {which part of DateTime fields to edit}
    FField        : TField;      {database field object}
    FOffset       : Integer;     {X-Offset to left edge}

    {property methods}
    function GetField : TField;
    function GetTable : TOvcCustomDbTable;
    procedure SetDataField(const Value : string);
    procedure SetDateOrTime(Value : TDateOrTime);
    procedure SetField(Value : TField);

  protected
  {.Z-}

  public
    procedure Assign(Source : TPersistent);
      override;
    constructor Create(ATable : TOvcTableAncestor);
      override;

    {properties}
    property Field : TField
      read GetField
      write SetField;

    property Offset : Integer
      read FOffset
      write FOffset;

    property Table : TOvcCustomDbTable
      read GetTable;

  published
    property DataField : string
      read FDataField
      write SetDataField;

    property DateOrTime : TDateOrTime
      read FDateOrTime
      write SetDateOrTime
      default DefDateOrTime;
  end;


  {.Z+}
  TOvcVisibleColumns = class(TObject)
  protected {private}
    {property variables}
    FList      : TList;             {mapping of visible column numbers}
    FRightEdge : Integer;           {right edge of last visible column}
    FTable     : TOvcCustomDbTable; {owning table}

    {property methods}
    function GetColumn(Index : Integer) : TOvcDbTableColumn;
    function GetCount : Integer;

  public
    constructor Create(ATable : TOvcCustomDbTable);
    destructor Destroy;
      override;

    procedure Add(ColNum : Integer);
    procedure Clear;
    procedure Delete(Index : Integer);
    procedure Exchange(Index1, Index2 : Integer);
    function IndexOf(ColNum : Integer) : Integer;
    procedure Insert(Index, ColNum : Integer);
    procedure Move(Index1, Index2 : Integer);

    property Column[Index : Integer] : TOvcDbTableColumn
      read GetColumn;
      default;

    property Count : Integer
      read GetCount;

    property RightEdge : Integer
      read FRightEdge
      write FRightEdge;
  end;
  {.Z-}


  TOvcCustomDbTable = class(TOvcTableAncestor)
  {.Z+}
  protected {private}
    {property variables}
    FAccess              : TOvcTblAccess;       {default access mode for the table}
    FActiveColumn        : Integer;             {active table column}
    FActiveRow           : Integer;             {active table row}
    FAdjust              : TOvcTblAdjust;       {default adjustment for the table}
    FBorderStyle         : TBorderStyle;        {border type around table}
    FColors              : TOvcTableColors;     {table cell colors}
    FColorUnused         : TColor;              {color of unused area}
    FColumns             : TOvcTableColumns;    {table column definitions}
    FDataLink            : TOvcDbTableDataLink; {link to db data fields}
    FDefaultMargin       : Integer;             {default cell margin}
    FGridPenSet          : TOvcGridPenSet;      {set of grid pens}
    FHeaderCell          : TOvcBaseTableCell;   {cell for column headings}
    FHeaderHeight        : Integer;             {height of the header row}
    FHeaderOptions       : TOvcHeaderOptionSet; {options for the header}
    FIndicatorWidth      : Integer;             {width of row indicators}
    FLeftColumn          : Integer;             {leftmost column}
    FLockedColumns       : Integer;             {number of fixed columns}
    FOptions             : TOvcDbTableOptionSet;{data-aware table options}
    FRowHeight           : Integer;             {height of table rows}
    FScrollBars          : TScrollStyle;        {scroll bar presence}
    FTextStyle           : TOvcTextStyle;       {default text style}
    FVisibleColumns      : TOvcVisibleColumns;  {list of visible columns}
    FVisibleRowCount     : Integer;             {count of visible rows}

    {event variables}
    FOnActiveCellChanged : TCellNotifyEvent;    {active cell changed event}
    FOnIndicatorClick    : TCellNotifyEvent;    {a mouse click on the indicators}
    FOnLockedCellClick   : TCellNotifyEvent;    {locked cell clicked event}
    FOnPaintUnusedArea   : TNotifyEvent;        {unused bit needs painting event}
    FOnUnusedAreaClick   : TCellNotifyEvent;    {unused area clicked event}
    FOnUserCommand       : TUserCommandEvent;   {user command event}

    {internal variables}
    tbActiveCell         : TOvcBaseTableCell;   {the active cell object}
    tbCellAttrFont       : TFont;               {cached font for painting cells}
    tbCmdTable           : string;              {the command table name for the grid}
    tbColMoveCursor      : hCursor;             {cursor for column moves}
    tbDataSource         : TDataSource;         {copy of our datasource}
    tbHasHSBar           : Boolean;             {true if horiz scroll bar present}
    tbHasVSBar           : Boolean;             {true if vert scroll bar present}
    tbIndicators         : TImageList;          {list of indicators}
    tbIndicatorWidth     : Integer;             {width of indicator column or 0 if not displayed}
    tbLastLeftCol        : Integer;             {the last column number that can be leftmost}
    tbMoveIndex          : Integer;             {the index of the column being moved}
    tbMoveToIndex        : Integer;             {the index of the column being targeted by move}
    tbMovingCol          : Integer;             {column that is being moved}
    tbPainting           : Boolean;             {true during painting operation}
    tbRebuilding         : Boolean;             {true when rebuilding columns}
    tbScrolling          : Boolean;             {true if db is scrolling us}
    tbSelectingNewCell   : Boolean;             {true when selecting a new cell}
    tbSizeOffset         : Integer;             {the offset of the sizing line}
    tbSizeIndex          : Integer;             {the index of the sized row/col}
    tbState              : TOvcTblStates;       {the state of the table}

    {property read methods}
    function GetColumnCount : Integer;
    function GetDataSource : TDataSource;
    function GetFieldCount : Integer;
    function GetFields(Index : Integer) : TField;
    function GetSelectedField : TField;
    function GetVisibleColumnCount : Integer;

    {property write methods}
    procedure SetAccess(Value : TOvcTblAccess);
    procedure SetActiveColumn(Value : Integer);
    procedure SetActiveRow(Value : Integer);
    procedure SetAdjust(Value : TOvcTblAdjust);
    procedure SetBorderStyle(Value : TBorderStyle);
    procedure SetColumnCount(Value : Integer);
    procedure SetColors(Value : TOvcTableColors);
    procedure SetColorUnused(Value : TColor);
    procedure SetColumns(Value : TOvcTableColumns);
    procedure SetDataSource(Value : TDataSource);
    procedure SetDefaultMargin(Value : Integer);
    procedure SetHeaderCell(Value : TOvcBaseTableCell);
    procedure SetHeaderHeight(Value : Integer);
    procedure SetHeaderOptions(Value : TOvcHeaderOptionSet);
    procedure SetIndicatorWidth(Value : Integer);
    procedure SetLeftColumn(Value : Integer);
    procedure SetLockedColumns(Value : Integer);
    procedure SetOptions(Value : TOvcDbTableOptionSet);
    procedure SetRowHeight(Value : Integer);
    procedure SetScrollBars(Value : TScrollStyle);
    procedure SetSelectedField(Value : TField);
    procedure SetTextStyle(Value : TOvcTextStyle);

    {cell-table messages}
    procedure ctimKillFocus(var Msg : TMessage);
      message ctim_KillFocus;
    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 ctimSetFocus(var Msg : TMessage);
      message ctim_SetFocus;
    procedure ctimStartEdit(var Msg : TMessage);
      message ctim_StartEdit;
    procedure ctimStartEditMouse(var Msg : TWMMouse);
      message ctim_StartEditMouse;
    procedure ctimStartEditKey(var Msg : TWMKey);
      message ctim_StartEditKey;

    {Window message methods}
    procedure WMCancelMode(var Msg : TMessage);
      message WM_CANCELMODE;
    procedure WMCommand(var Msg : TMessage);
      message WM_COMMAND;
    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 WMSize(var Msg : TWMSize);
      message WM_SIZE;
    procedure WMVScroll(var Msg : TWMVScroll);
      message WM_VSCROLL;

    {VCL message methods}
    procedure CMColorChanged(var Msg : TMessage);
      message CM_COLORCHANGED;
    procedure CMDesignHitTest(var Msg : TCMDesignHitTest);
      message CM_DESIGNHITTEST;
    procedure CMFontChanged(var Msg : TMessage);
      message CM_FONTCHANGED;

    {datalink notification routines}
    procedure tbDataChanged;
    procedure tbEditingChanged;
    procedure tbLayoutChanged;
    procedure tbRecordChanged(Field : TField);

    {assorted internal methods}
    function tbAdjustIntegralHeight : Boolean;
      {-adjust for integral height if enabled}
    function tbCalcActiveCellRect(var ACR : TRect) : Boolean;
      {-calculate the bounds of the active cell}
    function tbCalcCellRect(RowNum, ColNum : Integer) : TRect;
      {-return the bounds of the specified cell}
    function tbCalcColumnRect(ColNum : Integer) : TRect;
      {-return the bounds of the specified column}
    procedure tbCalcColumnsOnLastPage;
      {-determine the number of columns that fit on the last page}
    function tbCalcRowRect(RowNum : Integer) : TRect;
      {-return the bounds of the specified row}
    function tbCalcRowTop(RowNum : Integer) : Integer;
      {-return the top pixel position for RowNum. -1 if invalid}
    function tbCalcRowBottom(RowNum : Integer) : Integer;
      {-return the bottom pixel position for RowNum. -1 if invalid}
    procedure tbCalcRowColData(NewLeftCol : Integer);
      {-calculate the row and column information for the new column}
    procedure tbCalcVisibleRows;
      {-number of rows that fit within the client height - not counting the header}
    function tbCanModify : Boolean;
      {-enter db edit mode and return True if in edit mode}
    procedure tbCellChanged(Sender : TObject);
      override;
      {-notification of a cell change}
    function tbCellModified(Cell : TOvcBaseTableCell) : Boolean;
      {-return True if cell was modified}
    procedure tbColorsChanged(Sender : TObject);
      {-notification of a color change}
    function tbColumnAtRight : Integer;
      {-return the index of the column at the right edge of the table}
    procedure tbColumnChanged(Sender : TObject; C1, C2 : Integer; Action : TOvcTblActions);
      {-notification of a column change}
    procedure tbDefineFieldMap;
      {-define mapping between columns and field names}
    procedure tbDrawActiveCell(CellAttr : TOvcCellAttributes);
      {-draw the active cell}
    procedure tbDrawMoveLine;
      {-draw the column move line}
    procedure tbDrawSizeLine;
      {-draw the column size line}
    procedure tbDrawUnusedBit;
      {-paint the area below and to the right of the used grid}
    function tbEditCellHasFocus(FocusHandle : hWnd) : Boolean;
      {-return True if the edit cell has the focus}
    function tbFindCell(ColNum : Integer) : TOvcBaseTableCell;
      {-return the cell object for ColNum}
    function tbGetDataSize(ACell : TOvcBaseTableCell) : Integer;
      {-return the size of Cell's data requirements}
    function tbGetFieldColumn(AField : TField) : Integer;
      {-return this fields column}
    procedure tbGetFieldValue(AField : TField; ACell : TOvcBaseTableCell;
              Data : Pointer; Size : Integer);
      {-get the value from the db field}
    procedure tbGridPenChanged(Sender : TObject);
      {-notification of a grid pen change change}
    function tbIsDbActive : Boolean;
      {-return True is the datasource is active}
    function tbIsInMoveArea(MouseX, MouseY : Integer) : Boolean;
      {-return true if mouse is over the sizing area of the header}
    function tbIsOnGridLine(MouseX, MouseY : Integer) : Boolean;
      {-return True if mouse is over a grid line}
    procedure tbMoveActCellPageLeft;
      {-move the active cell one page left}
    procedure tbMoveActCellPageRight;
      {-move the active cell one page right}
    function tbPaintBitmapCell(ACanvas : TCanvas; PaintRect : TRect;
      CellAttr : TOvcCellAttributes; AField : TField;
      ACell : TOvcBaseTableCell; Active : Boolean) : Boolean;
      {-paint the bitmap data using the bitmap cell}
    procedure tbPaintString(const CellRect : TRect;
      const CellAttr : TOvcCellAttributes; Margin : Integer;
      WordWrap : Boolean; const S : string);
      {-paint the data for this cell}
    procedure tbQueryColData(ColNum : Integer; var W : Integer;
      var A : TOvcTblAccess; var H : Boolean);
      {-return column data for ColNum}
    procedure tbReadColData(Reader : TReader);
      {-read column data from the stream}
    procedure tbRebuildColumns;
      {-rebuild and relink coulmns with the data fields}
    procedure tbScrollBarPageLeft;
      {-scroll visible columns left one page}
    procedure tbScrollBarPageRight;
      {-scroll visible columns right one page}
    procedure tbScrollNotification(Delta : Integer);
      {-respond to a db scroll action}
    procedure tbScrollTableLeft(NewLeftCol : Integer);
      {-scroll left to new left column}
    procedure tbScrollTableRight(NewLeftCol : Integer);
      {-scroll right to new left column}
    procedure tbSetFieldValue(AField : TField; ACell : TOvcBaseTableCell;
              Data : Pointer; Size : Integer);
      {-set the db field value}
    procedure tbSetFocus(AHandle : hWnd);
      {-call window's SetFocus routine}
    procedure tbUpdateActive;
      {-update the table's active row}
    procedure tbUpdateHScrollBar;
      {-update the horizontal scrollbar range and position}
    procedure tbUpdateBufferLimit;
      {-update the data link's buffer size}
    procedure tbUpdateVScrollBar;
      {-update the vertical scrollbar range and position}
    procedure tbWriteColData(Writer : TWriter);
      {-write column data to stream}

  protected
    procedure ChangeScale(M, D : Integer);
      override;
    procedure CreateParams(var Params : TCreateParams);
      override;
    procedure CreateWnd;
      override;
    procedure DefineProperties(Filer : TFiler);
      override;
    procedure Loaded;
      override;
    procedure Notification(AComponent : TComponent; Operation : TOperation);
      override;
    procedure Paint;
      override;
    procedure SetBounds(ALeft, ATop, AWidth, AHeight : Integer);
      override;

    procedure SetLinkActive(Value : Boolean);
      {-notify of the active state of data link}
    procedure UpdateData;
      {-post changes in the active cell to the datasource}

    {event wrapper routines}
    procedure DoOnActiveCellChanged(RowNum, ColNum : Integer);
      dynamic;
    procedure DoOnIndicatorClick(RowNum, ColNum : Integer);
      dynamic;
    procedure DoOnLockedCellClick(RowNum, ColNum : Integer);
      dynamic;
    procedure DoOnPaintUnusedArea;
      virtual;
    procedure DoOnUnusedAreaClick(RowNum, ColNum : Integer);
      dynamic;
    procedure DoOnUserCommand(Cmd : Word);
      dynamic;

    {internal properties}
    property DataLink : TOvcDbTableDataLink
      read FDataLink;

    property VisibleColumns : TOvcVisibleColumns
      read FVisibleColumns;
  {.Z-}

    {protected properties - some may be published in descendants}
    property Access : TOvcTblAccess
      read FAccess
      write SetAccess
      default DefAccess;

    property Adjust : TOvcTblAdjust
      read FAdjust
      write SetAdjust
      default DefAdjust;

    property BorderStyle : TBorderStyle
      read FBorderStyle
      write SetBorderStyle
      default DefBorderStyle;

    property ColumnCount : Integer
      read GetColumnCount;

    property Colors : TOvcTableColors
      read FColors
      write SetColors;

    property ColorUnused : TColor
      read FColorUnused
      write SetColorUnused
      default DefColorUnused;

    property Columns : TOvcTableColumns
      read FColumns
      write SetColumns;

    property DataSource : TDataSource
      read GetDataSource
      write SetDataSource;

    property DefaultMargin : Integer
      read FDefaultMargin
      write SetDefaultMargin
      default DefDefaultMargin;

    property GridPenSet : TOvcGridPenSet
      read FGridPenSet
      write FGridPenSet;

    property HeaderCell : TOvcBaseTableCell
      read FHeaderCell
      write SetHeaderCell;

    property HeaderHeight : Integer
      read FHeaderHeight
      write SetHeaderHeight
      default DefHeaderHeight;

    property HeaderOptions : TOvcHeaderOptionSet
      read FHeaderOptions
      write SetHeaderOptions
      default DefHeaderOptions;

    property IndicatorWidth : Integer
      read FIndicatorWidth
      write SetIndicatorWidth
      default DefIndicatorWidth;

    property LockedColumns : Integer
      read FLockedColumns
      write SetLockedColumns
      default 0;

    property Options : TOvcdbTableOptionSet
      read FOptions
      write SetOptions
      default DefOptions;

    property RowHeight : Integer
      read FRowHeight
      write SetRowHeight
      default DefRowHeight;

    property ScrollBars : TScrollStyle
      read FScrollBars
      write SetScrollBars
      default DefScrollBars;

    property TextStyle : TOvcTextStyle
      read FTextStyle
      write SetTextStyle
      default DefTextStyle;

    {events}
    property OnActiveCellChanged : TCellNotifyEvent
      read FOnActiveCellChanged
      write FOnActiveCellChanged;

    property OnIndicatorClick : TCellNotifyEvent
      read FOnIndicatorClick
      write FOnIndicatorClick;

    property OnLockedCellClick : TCellNotifyEvent
      read FOnLockedCellClick
      write FOnLockedCellClick;

    property OnPaintUnusedArea : TNotifyEvent
      read FOnPaintUnusedArea
      write FOnPaintUnusedArea;

    property OnUnusedAreaClick : TCellNotifyEvent
      read FOnUnusedAreaClick
      write FOnUnusedAreaClick;

    property OnUserCommand : TUserCommandEvent
      read FOnUserCommand
      write FOnUserCommand;

  public
    constructor Create(AOwner: TComponent);
      override;
    destructor Destroy;
      override;

    {public methods}
    function CalcRowCol(X, Y : Integer; var RowNum, ColNum : Integer) : TOvcTblRegion;
      {-return the row and column where x,y land and the region code}
    function FilterKey(var Msg : TWMKey) : TOvcTblKeyNeeds;
      override;
      {-filter/translate entered keys}
    {.Z+}
    function IncCol(ColNum, Delta : Integer) : Integer;
      {-increase/decrease the column number and verify}
    function IncRow(RowNum, Delta : Integer) : Integer;
      {-increase/decrease the row number and verify}
    {.Z-}
    function InEditingState : Boolean;
      {-return True if the cell is in edit mode}
    procedure InvalidateCell(RowNum, ColNum : Integer);
      {-invalidate the specified cell}
    procedure InvalidateColumn(ColNum : Integer);
      {-invalidate the specified column}
    procedure InvalidateHeader;
      {-invalidate the header row}
    procedure InvalidateRow(RowNum : Integer);
      {-invalidate the specified row}
    procedure InvalidateIndicators;
      {-invalidate the row indicators}
    procedure MakeColumnVisible(ColNum : Integer);
      {-insure that ColNum is visible}
    procedure MoveActiveCell(Command : Word);
      {-move cell based on the passed Command}
    {.Z+}
    procedure ResolveCellAttributes(RowNum : TRowNum; ColNum : TColNum;
                                    var CellAttr : TOvcCellAttributes);
      override;
      {-obtain cell attributes}
    {.Z-}
    function SaveEditedData : Boolean;
      {-save data to attached db field}
    procedure Scroll(Delta : Integer);
      {-scroll the table by Distance (signed) by moving the active row}
    procedure SetActiveCell(RowNum, ColNum : Integer);
      {-change the active cell to the specified row and column}
    {.Z+}
    function SetCellProperties(AField : TField; ACell : TOvcBaseTableCell) : Boolean;
      {-set the cell properties to match the field data type}
    {.Z-}
    function StartEditing : Boolean;
      {begin editing mode}
    function StopEditing(SaveValue : Boolean) : Boolean;
      {-end edit mode and optionally save the edited value}

    {public properties}
    property ActiveColumn : Integer
      read FActiveColumn
      write SetActiveColumn;

    property ActiveRow : Integer
      read FActiveRow
      write SetActiveRow;

    property FieldCount : Integer
      read GetFieldCount;

    property Canvas;

    property SelectedField : TField
      read GetSelectedField
      write SetSelectedField;

    property Fields[Index : Integer] : TField
      read GetFields;

    property LeftColumn : Integer
      read FLeftColumn
      write SetLeftColumn
      default DefLeftColumn;

    property VisibleColumnCount : Integer
      read GetVisibleColumnCount;

    property VisibleRowCount : Integer
      read FVisibleRowCount;
  published
  end;


  TOvcDbTable = class(TOvcCustomDbTable)
  published
    {properties}
    property LockedColumns;
    property Access;
    property Adjust;
    property Align;
    property BorderStyle;
    property ColumnCount stored False;
    property Color default DefTableColor;
    property ColorUnused;
    property Colors;
    property Columns;
    property Controller;
    property Ctl3D;
    property DataSource;
    property DefaultMargin;
    property DragCursor;
    property Enabled;
    property Font;
    property GridPenSet;
    property HeaderCell;
    property HeaderHeight;
    property HeaderOptions;
    property IndicatorWidth;
    property Options;
    property ParentColor default DefParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property RowHeight;
    property ScrollBars;
    property ShowHint;
    property TabOrder;
    property TabStop default DefTabStop;
    property TextStyle;
    property Visible;

    {events}
    property OnActiveCellChanged;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnIndicatorClick;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnLockedCellClick;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnPaintUnusedArea;
    {$IFDEF Win32}
    property OnStartDrag;
    {$ENDIF}
    property OnUnusedAreaClick;
    property OnUserCommand;
  end;


implementation
