📄 dbgrideh.pas
字号:
{*******************************************************}
{ }
{ EhLib v3.0 }
{ TDBGridEh component }
{ }
{ Copyright (c) 1998-2003 by Dmitry V. Bolshakov }
{ }
{*******************************************************}
{$I EhLib.Inc}
{$IFDEF EH_LIB_VCL}
unit DBGridEh;
{$ELSE}
unit QDBGridEh;
{$ENDIF}
{$R-}
interface
{$IFDEF EH_LIB_VCL}
uses Windows, SysUtils, Messages, Classes, Controls, Forms, StdCtrls,
{$IFDEF EH_LIB_6} Variants, {$ENDIF}
Graphics, Grids, DBCtrls, Db, Menus, DBGrids, Registry, DBSumLst,
IniFiles, ToolCtrlsEh, ImgList, StdActns, PropFilerEh //The PropStorage
{,dbugintf};
{$ELSE}
uses SysUtils, Classes, Types, QControls, QForms, QStdCtrls,
Variants, QGraphics, QGrids, QDBCtrls, Db, QMenus, QDBGrids, QDBSumLst,
IniFiles, QToolCtrlsEh, QImgList, QStdActns, Qt;
{$ENDIF}
type
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);
TColumnEhValues = set of TColumnEhValue;
TColumnFooterEhValue = (cvFooterAlignment, cvFooterFont, cvFooterColor);
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
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;
{ 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;
{ ILookupGridOwner interface }
ILookupGridOwner = interface
['{2A1F4552-15C3-4359-ADAB-F2F6719FAA97}']
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;
FValue: String;
FValueType: TFooterValueType;
FWordWrap: Boolean;
function GetAlignment: TAlignment;
function GetColor: TColor;
function GetFont: TFont;
function IsAlignmentStored: Boolean;
function IsColorStored: Boolean;
function IsFontStored: 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 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;
procedure Assign(Source: TPersistent); override;
procedure EnsureSumValue;
procedure RestoreDefaults; virtual;
property AssignedValues: TColumnFooterValues read FAssignedValues;
property Column: TColumnEh read FColumn;
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 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);
TColumnTitleDefValuesEhValues = set of TColumnTitleDefValuesEhValue;
TColumnTitleDefValuesEh = class(TPersistent)
private
FAlignment: TAlignment;
FAssignedValues: TColumnTitleDefValuesEhValues;
FColor: TColor;
FColumnDefValues: TColumnDefValuesEh;
FEndEllipsis: Boolean;
FOrientation: TTextOrientationEh;
FTitleButton: Boolean;
FToolTips: Boolean;
function DefaultAlignment: TAlignment;
function DefaultColor: TColor;
function GetAlignment: TAlignment;
function GetColor: TColor;
function IsAlignmentStored: Boolean;
function IsColorStored: Boolean;
procedure SetAlignment(const Value: TAlignment);
procedure SetColor(const Value: TColor);
procedure SetEndEllipsis(const Value: Boolean);
procedure SetOrientation(const Value: TTextOrientationEh);
public
procedure Assign(Source: TPersistent); override;
property AssignedValues: TColumnTitleDefValuesEhValues read FAssignedValues;
published
constructor Create(ColumnDefValues: TColumnDefValuesEh);
property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
property Color: TColor read GetColor write SetColor stored IsColorStored;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -