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

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

unit OvcTCCBx;
  {-Orpheus Table Cell - combo box type}

interface

uses
  {$IFDEF Win32}
  Windows,
  {$ELSE}
  WinTypes, WinProcs,
  {$ENDIF}
  SysUtils, Messages,
  Graphics, Classes, Controls, Forms, StdCtrls, Menus,
  OvcData, OvcConst, OvcBase,
  OvcTCmmn, OvcTCell, OvcTGPns, OvcTable, OvcTCStr;

type
  TOvcTCComboBoxState = (otlbsUp, otlbsDown);

type
  TOvcTCComboBoxEdit = class(TCustomComboBox)
    protected {private}
      {.Z+}
      FCell     : TOvcBaseTableCell;

      EditField : HWnd;
      PrevEditWndProc : pointer;
      NewEditWndProc  : pointer;
      {.Z-}

    protected
      {.Z+}
      procedure EditWindowProc(var Msg : TMessage);
      function  FilterWMKEYDOWN(var Msg : TWMKey) : boolean;

      procedure WMChar(var Msg : TWMKey); message WM_CHAR;
      procedure WMGetDlgCode(var Msg : TMessage); message WM_GETDLGCODE;
      procedure WMKeyDown(var Msg : TWMKey); message WM_KEYDOWN;
      procedure WMKillFocus(var Msg : TWMKillFocus); message WM_KILLFOCUS;
      procedure WMSetFocus(var Msg : TWMSetFocus); message WM_SETFOCUS;
      {.Z-}

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

      property CellOwner : TOvcBaseTableCell
         read FCell write FCell;
  end;


  TOvcTCCustomComboBox = class(TOvcTCBaseString)
    protected {private}
      {.Z+}
      {property fields - even size}
      FDropDownCount : Integer;
      FEdit          : TOvcTCComboBoxEdit;
      FItems         : TStrings;
      FMaxLength     : word;

      {property fields - odd size}
      FStyle         : TComboBoxStyle;
      FAutoAdvanceChar      : boolean;
      FAutoAdvanceLeftRight : boolean;
      FSaveStringValue : boolean;
      FSorted        : boolean;
      FShowButton    : boolean;
      FUseRunTimeItems : boolean;

      {events}
      FOnChange      : TNotifyEvent;
      FOnDropDown    : TNotifyEvent;
      FOnDrawItem    : TDrawItemEvent;
      FOnMeasureItem : TMeasureItemEvent;
      {.Z-}

    protected
      {.Z+}
      function GetCellEditor : TControl; override;

      procedure SetItems(I : TStrings);
      procedure SetShowButton(SB : boolean);
      procedure SetSorted(S : boolean);

      procedure DrawArrow(Canvas   : TCanvas;
                    const CellRect : TRect;
                    const CellAttr : TOvcCellAttributes);
      procedure DrawButton(Canvas   : TCanvas;
                     const CellRect : TRect);

      procedure tcPaint(TableCanvas : TCanvas;
                  const CellRect    : TRect;
                        RowNum      : TRowNum;
                        ColNum      : TColNum;
                  const CellAttr    : TOvcCellAttributes;
                        Data        : pointer); override;
      {.Z-}

      {properties}
      property AutoAdvanceChar : boolean
         read FAutoAdvanceChar write FAutoAdvanceChar;

      property AutoAdvanceLeftRight : boolean
         read FAutoAdvanceLeftRight write FAutoAdvanceLeftRight;

      property DropDownCount : Integer
         read FDropDownCount write FDropDownCount;

      property Items : TStrings
         read FItems write SetItems;

      property MaxLength : word
         read FMaxLength write FMaxLength;

      property SaveStringValue : boolean
         read FSaveStringValue write FSaveStringValue;

      property Sorted : boolean
         read FSorted write SetSorted;

      property ShowButton : boolean
         read FShowButton write SetShowButton
         default true;

      property Style : TComboBoxStyle
         read FStyle write FStyle;

      property UseRunTimeItems : boolean
         read FUseRunTimeItems write FUseRunTimeItems;

      {events}
      property OnChange : TNotifyEvent
         read FOnChange write FOnChange;

      property OnDropDown: TNotifyEvent
         read FOnDropDown write FOnDropDown;

      property OnDrawItem: TDrawItemEvent
         read FOnDrawItem write FOnDrawItem;

      property OnMeasureItem: TMeasureItemEvent
         read FOnMeasureItem write FOnMeasureItem;

    public
      constructor Create(AOwner : TComponent); override;
      destructor Destroy; override;
      function CreateEditControl : TOvcTCComboBoxEdit; virtual;

      function  EditHandle : THandle; override;
      procedure EditHide; override;
      procedure EditMove(CellRect : TRect); override;

      procedure SaveEditedData(Data : pointer); override;
      procedure StartEditing(RowNum : TRowNum; ColNum : TColNum;
                             CellRect : TRect;
                       const CellAttr : TOvcCellAttributes;
                             CellStyle: TOvcTblEditorStyle;
                             Data : pointer); override;
      procedure StopEditing(SaveValue : boolean;
                            Data : pointer); override;
  end;

  TOvcTCComboBox = class(TOvcTCCustomComboBox)
    published
      property AcceptActivationClick;
      property Access;
      property Adjust;
      property AutoAdvanceChar;
      property AutoAdvanceLeftRight;
      property Color;
      property DropDownCount default 8;
      property Font;
      property Hint;
      property Items;
      property ShowHint;
      property Margin;
      property MaxLength;
      property SaveStringValue;
      property Sorted default false;
      property ShowButton;
      property Style;
      property Table;
      property TableColor;
      property TableFont;
      property TextHiColor;
      property TextStyle;
      property UseRunTimeItems;

      {events inherited from custom ancestor}
      property OnChange;
      property OnClick;
      property OnDblClick;
      property OnDragDrop;
      property OnDragOver;
      property OnDrawItem;
      property OnDropDown;
      property OnEndDrag;
      property OnEnter;
      property OnExit;
      property OnKeyDown;
      property OnKeyPress;
      property OnKeyUp;
      property OnMeasureItem;
      property OnMouseDown;
      property OnMouseMove;
      property OnMouseUp;
      property OnOwnerDraw;
  end;

implementation
