{$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}

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

unit OvcDbCal;
  {-Data-Aware Calendar component}

interface

uses
  Classes, Controls, Db, DbTables, Forms, Graphics, Menus, Messages,
  OvcBase, OvcCal, OvcConst, OvcCmd, OvcData, OvcExcpt, STDate;

const
  {field types supported}
  SupportedFieldTypes : set of  TFieldType = [ftDate, ftDateTime];
  DefAutoUpdate       = False;

type
  TOvcDbCalendar = class(TOvcCustomCalendar)
  {.Z+}
  protected {private}
    {property variables}
    FAutoUpdate  : Boolean;
    FDataLink    : TFieldDataLink;

    {property methods}
    function GetDataField : string;
    function GetDataSource : TDataSource;
    function GetField : TField;
    procedure SetDataField(const Value : string);
    procedure SetDataSource(Value : TDataSource);

    {internal methods}
    procedure calDataChange(Sender : TObject);
    procedure calUpdateData(Sender : TObject);

    {windows message methods}
    procedure WMKeyDown(var Msg : TWMKeyDown);
      message WM_KEYDOWN;
    procedure WMLButtonDown(var Msg : TWMLButtonDown);
      message WM_LBUTTONDOWN;

    {vcl methods}
    procedure CMExit(var Msg : TMessage);
      message CM_EXIT;
    {$IFDEF Win32}
    procedure CMGetDataLink(var Msg : TMessage);
      message CM_GETDATALINK;
    {$ENDIF}

  protected
    procedure Notification(AComponent : TComponent; Operation : TOperation);
      override;

    {dynamic event wrappers}
    procedure DoOnChange;
      override;
    function IsReadOnly : Boolean;
      override;
    procedure SetCalendarDate(Value : TStDate);
      override;
  {.Z-}

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

    property Field : TField
      read GetField;

  published
    property AutoUpdate : Boolean
      read FAutoUpdate
      write FAutoUpdate
      default DefAutoUpdate;

    property DataField : string
      read GetDataField
      write SetDataField;

    property DataSource : TDataSource
      read GetDataSource
      write SetDataSource;

    property BorderStyle;
    property Colors;
    property DayNameLen;
    property DrawGridLines;
    property DrawHeader;
    property HeaderHeight;
    property LineColor;
    property ReadOnly;
    property ShortNames;
    property WantDblClicks;
    property WeekStarts;

    property OnChange;
    property OnDrawHeader;
    property OnDrawItem;
    property OnUserCommand;

    {inherited properties}
    property Align;
    property Controller;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Font;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop
      default DefTabStop;
    property Visible;

    {inherited events}
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    {$IFDEF Win32}
    property OnStartDrag;
    {$ENDIF}
  end;


implementation
