
{*******************************************************}
{                                                       }
{       Borland Delphi Visual Component Library         }
{                                                       }
{       Copyright (c) 1997,98 Inprise Corporation       }
{                                                       }
{*******************************************************}

unit mxgrid;

interface

uses
 SysUtils, Windows, Dialogs, Controls, StdCtrls, Graphics, DB, Classes,
 Menus, Grids, Forms, mxarrays, mxConsts, MXDB, mxbutton, mxcommon, ImgList;

type

  TValueArray = class(TSmallIntArray);
  TDecisionGridOption = (cgGridLines, cgOutliner, cgPivotable);

  TDecisionGridOptions = set of TDecisionGridOption;

  TDecisionGridState = (csNormal, csPivoting);
  TDecisionDrawStates = (dsGroupStart, dsRowCaption, dsColCaption, dsSum,
  	 dsRowValue, dsColValue, dsData, dsOpenAfter, dsCloseAfter, dsCloseBefore, dsOpenBefore,
			dsRowIndicator, dsColIndicator, dsRowPlus, dsColPlus, dsNone);
  TDecisionPivotState = (psNone, psLeftPivot, psMiddlePivot, psRightPivot, psTopPivot);
  TDecisionDrawState = set of TDecisionDrawStates;

  TDecisionDrawCellEvent = procedure (Sender: TObject; Col, Row: Longint;
    var Value: string; var aFont: TFont; var aColor: TColor; AState: TGridDrawState; aDrawState: TDecisionDrawState) of Object;

  TDecisionExamineCellEvent = procedure (Sender: TObject; iCol, iRow: Longint; iSum: Integer; const ValueArray: TValueArray) of Object;

  TDecisionCellType = (ctNone, ctCaptionRow, ctCaptionCol, ctNewCaptionCol, //ctHeader,
  		 ctRowLabel, ctColLabel, ctData, ctRowPlus, ctColPlus, ctRowIndicator, ctColIndicator);

  TButtonPlace = (bpLeft, bpMiddle, bpRight);

  TCustomDecisionGrid = class;

  TDecisionGridDataLink = class(TDecisionDataLink)
  protected
		procedure	DecisionDataEvent(Event: TDecisionDataEvent); override;
  public
    constructor Create(AGrid: TCustomDecisionGrid);
    destructor Destroy; override;
  end;

	TDDNotifyType = (tdDisplay, tdSubTotals, TdMetaData);
	TDisplayDim = class(TCollectionItem)
    public
      constructor Create(Collection: TCollection); override;
      procedure assign(Value: TPersistent); override;
    published
      property DisplayName: string;
      property FieldName: string;
      property Color: TColor;
			property Format: String read FFormat write SetFormat;
			property Alignment: TAlignment read FAlignment write SetAlignment;
      property Subtotals: Boolean;
  end;

  TDisplayDimClass = class of TDisplayDim;

	TDisplayDims = class(TCollection)
		private
			bQuiet: boolean;
			function GetDisplayDim(Index: Integer): TDisplayDim;
      procedure SetDisplayDim(Index: Integer; Value: TDisplayDim);
      constructor Create(Grid: TCustomDecisionGrid; ItemClass: TDisplayDimClass);
		protected
      FGrid: TCustomDecisionGrid;
    function GetOwner: TPersistent; override;
			procedure NotifyOwner(aType: TDDNotifyType);
		public
      property Items[Index: Integer]:TDisplayDim; default;
	end;

  TCustomDecisionGrid = class(TCustomGrid)
  protected
    FGridStateX: TDecisionGridState;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
		function SelectCell(Arow, AColumn:LongInt): Boolean; override;
    procedure TopLeftChanged; override;
		procedure ColWidthsChanged; override;
		procedure	RowHeightsChanged; override;
		procedure Paint; override;
    property  Options: TDecisionGridOptions default [cgGridLines, cgOutLiner, cgPivotable];
		property	GridLineWidth: Integer read FGridLineWidth write SetGridLineWidth;
		property	GridLineColor: TColor read FGridLineColor write SetGridLineColor;
    property  CaptionFont: TFont;
    property  CaptionColor: TColor;
    property  DataFont: TFont;
    property  DataColor: TColor;
    property  DataSumColor: TColor;
    property  LabelFont: TFont;
    property  LabelColor: TColor;
		property	LabelSumColor: TColor read FLabelSumColor write SetLabelSumColor;
		property	Dimensions:	TDisplayDims read FDisplayDims write FDisplayDims;
		function  GetCells(ACol, ARow: Integer): String;
    property  FixedRows:integer;
    property  RowCount:integer;
    property  FixedCols:integer;
    property  ColCount:integer;
		property	DefaultColWidth: Integer read FColWidth write SetColWidth;
		property	DefaultRowHeight: Integer read FRowHeight write SetRowHeight;

  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
		property DecisionSource: TDecisionSource read GeTDecisionSource write SeTDecisionSource;
    function CellRect(ACol, ARow: Longint): TRect;
		function CellValueArray(ACol, ARow: Integer; var ValueArray: TValueArray): boolean;
		function CellDrawState(ACol, ARow: Integer;
						var Value: string; var DrawState: TDecisionDrawState): boolean;
    property Totals: boolean;

    property OnDecisionExamineCell: TDecisionExamineCellEvent;
    property OnDecisionDrawCell: TDecisionDrawCellEvent;
    property OnTopLeftChanged: TNotifyEvent;
    property Cells[ACol, ARow: Integer]: String;
    property ShowCubeEditor:boolean;  
  end;

  TDecisionGrid = class(TCustomDecisionGrid)
  public
    property  RowCount;
    property  ColCount;
    property  FixedRows;
    property  FixedCols;
	published
    property  Options;
		property 	DefaultColWidth;
		property	DefaultRowHeight;
    property  CaptionColor;
    property  CaptionFont;
    property  DataColor;
    property  DataSumColor;
    property  DataFont;
    property  LabelFont;
    property  LabelColor;
    property	LabelSumColor;
  	property 	DecisionSource;
		property 	Dimensions;
		property Totals;
    property ShowCubeEditor;
    //
//  Inherited properties and events

    property Align;
    property Anchors;
    property BorderStyle;
    property Color;
    property Constraints;
    property Ctl3D;
    property DefaultDrawing;
    property DragCursor;
    property DragMode;
    property Enabled;
    property GridLineWidth;
    property GridLineColor;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ScrollBars;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnClick;

    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnDecisionDrawCell;
    property OnDecisionExamineCell;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnStartDrag;
    property OnTopLeftChanged;
  end;

implementation
