?? dbgrideh.pas
字號:
{*******************************************************}
{ }
{ EhLib v4.2 }
{ }
{ TDBGridEh component }
{ with support of IMemTableEh }
{ Build 4.2.39 }
{ }
{ Copyright (c) 1998-2006 by Dmitry V. Bolshakov }
{ }
{*******************************************************}
{$I EhLib.Inc}
{$IFDEF EH_LIB_VCL}
unit DBGridEh {$IFDEF CIL} platform{$ENDIF};
{$ELSE}
unit QDBGridEh;
{$ENDIF}
//{$R-}
interface
{$IFDEF EH_LIB_VCL}
uses Windows, SysUtils, Messages, Classes, Controls, Forms, StdCtrls,
{$IFDEF EH_LIB_5} Contnrs, {$ENDIF}
{$IFDEF EH_LIB_6} Variants, Types, {$ENDIF}
{$IFDEF CIL}
EhLibVCLNET,
WinUtils,
{$ELSE}
EhLibVCL,
{$ENDIF}
Graphics, GridsEh, DBCtrls, Db, Menus, Registry, DBSumLst, DBCtrlsEh,
IniFiles, ToolCtrlsEh, ImgList, StdActns, PropFilerEh, ActnList
//The PropStorage
{,dbugintf};
{$ELSE}
uses SysUtils, Classes, Types, QControls, QForms, QStdCtrls,
Variants, QGraphics, QGrids, QDBCtrls, Db, QMenus, QDBGrids, QDBSumLst, QDBCtrlsEh,
IniFiles, QToolCtrlsEh, QImgList, QStdActns, Qt;
{$ENDIF}
type
TDBGridColumnsState = (csDefault, csCustomized);
TDrawDataCellEvent = procedure (Sender: TObject; const Rect: TRect; Field: TField;
State: TGridDrawState) of object;
TDBGridOption = (dgEditing, dgAlwaysShowEditor, dgTitles, dgIndicator,
dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect,
dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgMultiSelect);
TDBGridOptions = set of TDBGridOption;
TColumnEhValue = (cvColor, cvWidth, cvFont, cvAlignment, cvReadOnly, cvTitleColor,
cvTitleCaption, cvTitleAlignment, cvTitleFont, cvTitleButton, cvTitleEndEllipsis,
cvTitleToolTips, cvTitleOrientation, cvImeMode, cvImeName, cvWordWrap,
cvLookupDisplayFields, cvCheckboxes, cvAlwaysShowEditButton, cvEndEllipsis,
cvAutoDropDown, cvDblClickNextVal, cvToolTips, cvDropDownSizing,
cvDropDownShowTitles, cvLayout, cvHighlightRequired, cvBiDiMode);
TColumnEhValues = set of TColumnEhValue;
TColumnFooterEhValue = (cvFooterAlignment, cvFooterFont, cvFooterColor, cvFooterToolTips);
TColumnFooterValues = set of TColumnFooterEhValue;
TColumnEhRestoreParam = (crpColIndexEh, crpColWidthsEh, crpSortMarkerEh, crpColVisibleEh,
crpDropDownRowsEh, crpDropDownWidthEh);
TColumnEhRestoreParams = set of TColumnEhRestoreParam;
TDBGridEhRestoreParam = (grpColIndexEh, grpColWidthsEh, grpSortMarkerEh, grpColVisibleEh,
grpRowHeightEh, grpDropDownRowsEh, grpDropDownWidthEh);
TDBGridEhRestoreParams = set of TDBGridEhRestoreParam;
const
cm_DeferLayout = WM_USER + 100;
IndicatorWidth = 11;
ColumnEhTitleValues = [cvTitleColor..cvTitleOrientation];
ColumnEhFooterValues = [cvFooterAlignment..cvFooterColor];
(* cm_DeferLayout = WM_USER + 100; *)
{ TColumnEh defines internal storage for column attributes. If IsStored is
True, values assigned to properties are stored in this object, the grid-
or field-based default sources are not modified. Values read from
properties are the previously assigned value, if any, or the grid- or
field-based default values if nothing has been assigned to that property.
This class also publishes the column attribute properties for persistent
storage.
If IsStored is True, the column does not maintain local storage of
property values. Assignments to column properties are passed through to
the underlying grid- or field-based default sources. }
type
TColumnEh = class;
TCustomDBGridEh = class;
TColumnDropDownBoxEh = class;
TDBGridEhStyle = class;
TDBGridEhCenter = class;
{ for lookup drop-down grid }
TDBLookupGridEhOption = (dlgColumnResizeEh, dlgColLinesEh, dlgRowLinesEh,
dlgAutoSortMarkingEh, dlgMultiSortMarkingEh);
TDBLookupGridEhOptions = set of TDBLookupGridEhOption;
TCheckTitleEhBtnEvent = procedure(Sender: TObject; ACol: Longint;
Column: TColumnEh; var Enabled: Boolean) of object;
TDrawColumnEhCellEvent = procedure(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumnEh; State: TGridDrawState) of object;
TGetCellEhParamsEvent = procedure(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState) of object;
TTitleEhClickEvent = procedure(Sender: TObject; ACol: Longint;
Column: TColumnEh) of object;
TOnColumnCheckDrawRequiredStateEventEh = procedure(Sender: TObject;
Text: String; var DrawState: Boolean) of object;
TGridMoveRecordsEventEh = function(Sender: TObject; BookmarkList: TStrings;
ToRecNo: Longint; TreeLevel: Integer; CheckOnly: Boolean): Boolean of object;
TDBGridEhBuildIndicatorTitleMenu = procedure (Grid: TCustomDBGridEh;
var PopupMenu: TPopupMenu) of object;
{ ILookupGridOwner interface }
ILookupGridOwner = interface
['{2A1F4552-15C3-4359-ADAB-F2F6719FAA97}']
procedure SetListSource(AListSource: TDataSource);
function GetLookupGrid: TCustomDBGridEh;
function GetOptions: TDBLookupGridEhOptions;
procedure SetOptions(Value: TDBLookupGridEhOptions);
property Options: TDBLookupGridEhOptions read GetOptions write SetOptions;
end;
TSortMarkerEh = (smNoneEh, smDownEh, smUpEh);
TTextOrientationEh = (tohHorizontal, tohVertical);
{ TColumnTitleEh }
TColumnTitleEh = class(TPersistent)
private
FAlignment: TAlignment;
FCaption: string;
FColor: TColor;
FColumn: TColumnEh;
FEndEllipsis: Boolean;
FFont: TFont;
FHint: string;
FImageIndex: Integer;
FOrientation: TTextOrientationEh;
FSortIndex: Integer;
FToolTips: Boolean;
function GetAlignment: TAlignment;
function GetCaption: string;
function GetColor: TColor;
function GetEndEllipsis: Boolean;
function GetFont: TFont;
function GetOrientation: TTextOrientationEh;
function GetTitleButton: Boolean;
function GetToolTips: Boolean;
function IsAlignmentStored: Boolean;
function IsCaptionStored: Boolean;
function IsColorStored: Boolean;
function IsEndEllipsisStored: Boolean;
function IsFontStored: Boolean;
function IsOrientationStored: Boolean;
function IsTitleButtonStored: Boolean;
function IsToolTipsStored: Boolean;
procedure FontChanged(Sender: TObject);
procedure SetAlignment(Value: TAlignment);
procedure SetCaption(const Value: string); virtual;
procedure SetColor(Value: TColor);
procedure SetEndEllipsis(const Value: Boolean);
procedure SetFont(Value: TFont);
procedure SetImageIndex(const Value: Integer);
procedure SetOrientation(const Value: TTextOrientationEh);
procedure SetSortIndex(Value: Integer);
procedure SetToolTips(const Value: Boolean);
protected
FSortMarker: TSortMarkerEh;
FTitleButton: Boolean;
function GetSortMarkingWidth: Integer;
procedure RefreshDefaultFont;
procedure SetSortMarker(Value: TSortMarkerEh);
procedure SetTitleButton(Value: Boolean);
public
constructor Create(Column: TColumnEh);
destructor Destroy; override;
function DefaultAlignment: TAlignment;
function DefaultCaption: string;
function DefaultColor: TColor;
function DefaultEndEllipsis: Boolean;
function DefaultFont: TFont;
function DefaultOrientation: TTextOrientationEh;
function DefaultTitleButton: Boolean;
function DefaultToolTips: Boolean;
procedure Assign(Source: TPersistent); override;
procedure RestoreDefaults; virtual;
procedure SetNextSortMarkerValue(KeepMulti: Boolean);
property Column: TColumnEh read FColumn;
published
property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
property Caption: string read GetCaption write SetCaption stored IsCaptionStored;
property Color: TColor read GetColor write SetColor stored IsColorStored;
property EndEllipsis: Boolean read GetEndEllipsis write SetEndEllipsis stored IsEndEllipsisStored;
property Font: TFont read GetFont write SetFont stored IsFontStored;
property Hint: string read FHint write FHint;
property ImageIndex: Integer read FImageIndex write SetImageIndex default -1;
property Orientation: TTextOrientationEh read GetOrientation write SetOrientation stored IsOrientationStored;
property SortIndex: Integer read FSortIndex write SetSortIndex default 0;
property SortMarker: TSortMarkerEh read FSortMarker write SetSortMarker default smNoneEh;
property TitleButton: Boolean read GetTitleButton write SetTitleButton stored IsTitleButtonStored;
property ToolTips: Boolean read GetToolTips write SetToolTips stored IsToolTipsStored;
end;
{ TColumnFooterEh }
TFooterValueType = (fvtNon, fvtSum, fvtAvg, fvtCount, fvtFieldValue, fvtStaticText);
TColumnFooterEh = class(TCollectionItem)
private
FAlignment: TAlignment;
FAssignedValues: TColumnFooterValues;
FColor: TColor;
FColumn: TColumnEh;
FDisplayFormat: String;
FEndEllipsis: Boolean;
FFieldName: string;
FFont: TFont;
FToolTips: Boolean;
FValue: String;
FValueType: TFooterValueType;
FWordWrap: Boolean;
function GetAlignment: TAlignment;
function GetColor: TColor;
function GetFont: TFont;
function GetSumValue: Variant;
function GetToolTips: Boolean;
function IsAlignmentStored: Boolean;
function IsColorStored: Boolean;
function IsFontStored: Boolean;
function IsToolTipsStored: Boolean;
procedure FontChanged(Sender: TObject);
procedure SetAlignment(Value: TAlignment);
procedure SetColor(Value: TColor);
procedure SetDisplayFormat(const Value: String);
procedure SetEndEllipsis(const Value: Boolean);
procedure SetFieldName(const Value: String);
procedure SetFont(Value: TFont);
procedure SetToolTips(const Value: Boolean);
procedure SetValue(const Value: String);
procedure SetValueType(const Value: TFooterValueType);
procedure SetWordWrap(const Value: Boolean);
protected
FDBSum: TDBSum;
procedure RefreshDefaultFont;
public
constructor Create(Collection: TCollection); override;
constructor CreateApart(Column: TColumnEh);
destructor Destroy; override;
function DefaultAlignment: TAlignment;
function DefaultColor: TColor;
function DefaultFont: TFont;
function DefaultToolTips: Boolean;
procedure Assign(Source: TPersistent); override;
procedure EnsureSumValue;
procedure RestoreDefaults; virtual;
property AssignedValues: TColumnFooterValues read FAssignedValues;
property Column: TColumnEh read FColumn;
property SumValue: Variant read GetSumValue;
published
property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
property Color: TColor read GetColor write SetColor stored IsColorStored;
property DisplayFormat: String read FDisplayFormat write SetDisplayFormat;
property EndEllipsis: Boolean read FEndEllipsis write SetEndEllipsis default False;
property FieldName: String read FFieldName write SetFieldName;
property Font: TFont read GetFont write SetFont stored IsFontStored;
property ToolTips: Boolean read GetToolTips write SetToolTips stored IsToolTipsStored;
property Value: String read FValue write SetValue;
property ValueType: TFooterValueType read FValueType write SetValueType default fvtNon;
property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
end;
TColumnFooterEhClass = class of TColumnFooterEh;
{ TColumnFootersEh }
TColumnFootersEh = class(TCollection)
private
FColumn: TColumnEh;
function GetFooter(Index: Integer): TColumnFooterEh;
procedure SetFooter(Index: Integer; Value: TColumnFooterEh);
protected
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
public
constructor Create(Column: TColumnEh; FooterClass: TColumnFooterEhClass);
function Add: TColumnFooterEh;
property Column: TColumnEh read FColumn;
property Items[Index: Integer]: TColumnFooterEh read GetFooter write SetFooter; default;
end;
TColumnEhType = (ctCommon, ctPickList, ctLookupField, ctKeyPickList, ctKeyImageList,
ctCheckboxes);
TColumnButtonStyleEh = (cbsAuto, cbsEllipsis, cbsNone, cbsUpDown, cbsDropDown);
{ TColumnTitleDefValuesEh }
TColumnDefValuesEh = class;
TColumnTitleDefValuesEhValue = (cvdpTitleColorEh, cvdpTitleAlignmentEh);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -