{$I OVC.INC}

{$B-} {Short-circuit 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}

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

unit OvcCaret;
  {-Caret handling class}

interface

uses
  {$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  Graphics, Classes, Controls, Forms,
  OvcMisc, OvcExcpt;

type
  TOvcCaretShape = (                 {Predefined caret shapes..}
                    csBlock,         {..block over whole cell}
                    csHalfBlock,     {..block over bottom part of cell}
                    csVertLine,      {..vertical line to left of cell}
                    csHorzLine,      {..horizontal line on bottom of cell}
                    csCustom,        {..custom width/height}
                    csBitmap);       {..bitmap caret, custom width/height}

  TOvcCaretAlign = (                 {Alignment of caret in cell..}
                    caLeft,          {..left side, centered vertically}
                    caTop,           {..top side, centered horizontally}
                    caRight,         {..right side, centered vertically}
                    caBottom,        {..bottom side, centered horizontally}
                    caCenter);       {..centered vertically and horizontally}

const
  {Default values for TOvcCaretTypes, TOvcCarets and TOvcCaretPairs}
  DefAlign     = caLeft;
  DefBlinkTime = 0;
  DefCaretWd   = 2;
  DefCaretHt   = 10;
  DefInsMode   = True;
  DefIsGray    = False;
  DefShape     = csVertLine;

type
  {Class defining a caret shape}
  TOvcCaret = class(TPersistent)
    {.Z+}
    protected
      {property fields}
      FAlign     : TOvcCaretAlign;      {Caret alignment in cell}
      FBitmap    : TBitmap;             {Bitmap for a bitmapped caret}
      FBitmapX   : Integer;             {Bitmap's hotspot X}
      FBitmapY   : Integer;             {Bitmap's hotspot Y}
      FBlinkTime : word;                {Blink time}
      FCaretHt   : Integer;             {Height: autosized for some shapes}
      FCaretWd   : Integer;             {Width: autosized for some shapes}
      FIsGray    : boolean;             {True if a 'gray' caret}
      FShape     : TOvcCaretShape;      {Shape}

      FOnChange  : TNotifyEvent;        {Owner's change notification}

      {internal fields}
      RefCount      : word;             {Reference count}

      {property access methods}
      procedure SetAlign(A : TOvcCaretAlign);
      procedure SetBitmap(BM : TBitMap);
      procedure SetBitmapX(X : Integer);
      procedure SetBitmapY(Y : Integer);
      procedure SetBlinkTime(BT : word);
      procedure SetCaretHeight(CH : Integer);
      procedure SetCaretWidth(CW : Integer);
      procedure SetIsGray(IG : boolean);
      procedure SetShape(S : TOvcCaretShape);

      {general methods}
      procedure NotifyChange;
    {.Z-}

    public
      {VCL methods}
      constructor Create;
      destructor Destroy; override;

    {.Z+}
      {other methods}
      procedure Register;
      procedure Deregister;

      {properties}
      property OnChange : TNotifyEvent
         read FOnChange
         write FOnChange;
    {.Z-}

    published
      {properties}
      property Bitmap : TBitmap
         read FBitmap
         write SetBitmap;

      property BitmapHotSpotX : Integer
         read FBitmapX
         write SetBitmapX
         default 0;

      property BitmapHotSpotY : Integer
         read FBitmapY
         write SetBitmapY
         default 0;

      property Shape : TOvcCaretShape
         read FShape
         write SetShape
         default DefShape;

      property Align : TOvcCaretAlign
         read FAlign
         write SetAlign
         default DefAlign;

      property BlinkTime : word
         read FBlinkTime
         write SetBlinkTime
         default DefBlinkTime;

      property CaretHeight : Integer
         read FCaretHt
         write SetCaretHeight
         default DefCaretHt;

      property CaretWidth : Integer
         read FCaretWd
         write SetCaretWidth
         default DefCaretWd;

      property IsGray : boolean
         read FIsGray
         write SetIsGray
         default DefIsGray;
  end;

{.Z+}
type
  TOvcSingleCaret = class(TPersistent)
    {Class defining a Single caret}
    protected
      {property fields}
      FCaretType : TOvcCaret;           {Current caret type}
      FHeight    : Integer;             {Cell height}
      FLinked    : boolean;             {True if linked to owner}
      FPos       : TPoint;              {Position within owner}
      FVisible   : boolean;             {True if visible}
      FWidth     : Integer;             {Cell width}

      {other fields}
      OrigBlinkTime : word;             {Blink time before linking}
      Owner   : TWinControl;            {Owning control}
      XOffset : Integer;                {X Offset of caret in cell}
      YOffset : Integer;                {Y Offset of caret in cell}

      {property access methods}
      procedure SetCaretType(CT : TOvcCaret);
      procedure SetCellHeight(CH : Integer);
      procedure SetCellWidth(CW : Integer);
      procedure SetLinked(L : boolean);
      procedure SetPos(P : TPoint);
      procedure SetVisible(V : boolean);

      {general methods}
      procedure MakeShape;
      procedure Reinit;
      procedure ResetPos;

    public
      {VCL methods}
      constructor Create(AOwner : TWinControl);
      destructor Destroy; override;

      {properties}
      property CaretType : TOvcCaret
         read FCaretType
         write SetCaretType;

      property CellHeight : Integer
         read FHeight
         write SetCellHeight;

      property CellWidth : Integer
         read FWidth
         write SetCellWidth;

      property Linked : boolean
         read FLinked
         write SetLinked
         stored false;

      property Position : TPoint
         read FPos
         write SetPos;

      property Visible : boolean
         read FVisible
         write SetVisible;

    published
      {general methods}
      procedure CaretTypeHasChanged(Sender : TObject);

      {no properties are published}
  end;

type
  TOvcCaretPair = class(TOvcSingleCaret)
    {Class defining a pair of carets, one each for insert/overwrite modes}
    protected
      {property fields}
      FInsMode  : boolean;
      FInsCaretType : TOvcCaret;
      FOvrCaretType : TOvcCaret;

      {property access methods}
      procedure SetInsMode(IM : boolean);
      procedure SetInsCaretType(ICT : TOvcCaret);
      procedure SetOvrCaretType(OCT : TOvcCaret);

    public
      {VCL methods}
      constructor Create(AOwner : TWinControl);
      destructor Destroy; override;

      {properties}
      property InsertMode : boolean
         read FInsMode
         write SetInsMode
         default DefInsMode;

      property InsCaretType : TOvcCaret
         read FInsCaretType
         write SetInsCaretType;

      property OvrCaretType : TOvcCaret
         read FOvrCaretType
         write SetOvrCaretType;

    published
      {nothing is published}
  end;
{.Z-}


implementation
