📄 rxlookup.pas
字号:
{*******************************************************}
{ }
{ Delphi VCL Extensions (RX) }
{ }
{ Copyright (c) 1995,1997 Borland International }
{ Portions copyright (c) 1995, 1996 AO ROSNO }
{ Portions copyright (c) 1997, 1998 Master-Bank }
{ }
{*******************************************************}
unit RxLookup;
interface
{$I RX.INC}
uses SysUtils, Windows, DBCtrls, VDBConsts, Variants, Messages, Classes, Controls, Forms, Graphics, Menus, DB, Mask,
{$IFNDEF RX_D3} DBTables, {$ENDIF} Buttons, StdCtrls, DBUtils, ToolEdit;
const
DefFieldsDelim = ',';
type
{ TRxLookupControl }
TLookupListStyle = (lsFixed, lsDelimited);
TRxLookupControl = class;
TGetImageEvent = procedure (Sender: TObject; IsEmpty: Boolean;
var Graphic: TGraphic; var TextMargin: Integer) of object;
TDataSourceLink = class(TDataLink)
private
FDataControl: TRxLookupControl;
protected
procedure ActiveChanged; override;
procedure LayoutChanged; override;
procedure FocusControl(Field: TFieldRef); override;
procedure RecordChanged(Field: TField); override;
end;
TLookupSourceLink = class(TDataLink)
private
FDataControl: TRxLookupControl;
protected
procedure ActiveChanged; override;
procedure LayoutChanged; override;
procedure DataSetChanged; override;
end;
TRxLookupControl = class(TCustomControl)
private
FLookupSource: TDataSource;
FDataLink: TDataSourceLink;
FLookupLink: TLookupSourceLink;
FDataFieldName: string;
FLookupFieldName: string;
FLookupDisplay: string;
FDisplayIndex: Integer;
FDataField: TField;
FMasterField: TField;
FKeyField: TField;
FDisplayField: TField;
FListFields: TList;
FValue: string;
FDisplayValue: string;
FDisplayEmpty: string;
FSearchText: string;
FEmptyValue: string;
FEmptyItemColor: TColor;
FListActive: Boolean;
FPopup: Boolean;
FFocused: Boolean;
FLocate: TLocateObject;
FIndexSwitch: Boolean;
FIgnoreCase: Boolean;
FItemHeight: Integer;
FFieldsDelim: Char;
FListStyle: TLookupListStyle;
FOnChange: TNotifyEvent;
FOnGetImage: TGetImageEvent;
{$IFDEF WIN32}
FLookupMode: Boolean;
procedure CheckNotFixed;
procedure SetLookupMode(Value: Boolean);
function GetKeyValue: Variant;
procedure SetKeyValue(const Value: Variant);
{$ENDIF}
function CanModify: Boolean;
procedure CheckNotCircular;
procedure DataLinkActiveChanged;
procedure CheckDataLinkActiveChanged;
procedure DataLinkRecordChanged(Field: TField);
function GetBorderSize: Integer;
function GetField: TField;
function GetDataSource: TDataSource;
function GetLookupField: string;
function GetLookupSource: TDataSource;
function GetReadOnly: Boolean;
function GetTextHeight: Integer;
function DefaultTextHeight: Integer;
function GetItemHeight: Integer;
function LocateKey: Boolean;
function LocateDisplay: Boolean;
function ValueIsEmpty(const S: string): Boolean;
function StoreEmpty: Boolean;
procedure ProcessSearchKey(Key: Char);
procedure UpdateKeyValue;
procedure SelectKeyValue(const Value: string);
procedure SetDataFieldName(const Value: string);
procedure SetDataSource(Value: TDataSource);
procedure SetDisplayEmpty(const Value: string);
procedure SetEmptyValue(const Value: string);
procedure SetEmptyItemColor(Value: TColor);
procedure SetLookupField(const Value: string);
procedure SetValueKey(const Value: string);
procedure SetValue(const Value: string);
procedure SetDisplayValue(const Value: string);
procedure SetListStyle(Value: TLookupListStyle); virtual;
procedure SetFieldsDelim(Value: Char); virtual;
procedure SetLookupDisplay(const Value: string);
procedure SetLookupSource(Value: TDataSource);
procedure SetReadOnly(Value: Boolean);
procedure SetItemHeight(Value: Integer);
function ItemHeightStored: Boolean;
procedure DrawPicture(Canvas: TCanvas; Rect: TRect; Image: TGraphic);
procedure UpdateDisplayValue;
function EmptyRowVisible: Boolean;
procedure WMGetDlgCode(var Message: TMessage); message WM_GETDLGCODE;
procedure WMKillFocus(var Message: TMessage); message WM_KILLFOCUS;
procedure WMSetFocus(var Message: TMessage); message WM_SETFOCUS;
protected
procedure Change; dynamic;
procedure KeyValueChanged; virtual;
procedure DisplayValueChanged; virtual;
procedure ListLinkActiveChanged; virtual;
procedure ListLinkDataChanged; virtual;
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
function GetPicture(Current, Empty: Boolean; var TextMargin: Integer): TGraphic; virtual;
procedure UpdateDisplayEmpty(const Value: string); virtual;
function SearchText(var AValue: string): Boolean;
function GetWindowWidth: Integer;
property DataField: string read FDataFieldName write SetDataFieldName;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property DisplayEmpty: string read FDisplayEmpty write SetDisplayEmpty;
property EmptyValue: string read FEmptyValue write SetEmptyValue stored StoreEmpty;
property EmptyItemColor: TColor read FEmptyItemColor write SetEmptyItemColor default clWindow;
property IgnoreCase: Boolean read FIgnoreCase write FIgnoreCase default True;
property IndexSwitch: Boolean read FIndexSwitch write FIndexSwitch default True;
property ItemHeight: Integer read GetItemHeight write SetItemHeight
stored ItemHeightStored;
property ListStyle: TLookupListStyle read FListStyle write SetListStyle default lsFixed;
property FieldsDelimiter: Char read FFieldsDelim write SetFieldsDelim default DefFieldsDelim;
property LookupDisplay: string read FLookupDisplay write SetLookupDisplay;
property LookupDisplayIndex: Integer read FDisplayIndex write FDisplayIndex default 0;
property LookupField: string read GetLookupField write SetLookupField;
property LookupSource: TDataSource read GetLookupSource write SetLookupSource;
property ParentColor default False;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
property TabStop default True;
property Value: string read FValue write SetValue stored False;
property DisplayValue: string read FDisplayValue write SetDisplayValue stored False;
{$IFDEF WIN32}
property KeyValue: Variant read GetKeyValue write SetKeyValue stored False;
{$ENDIF}
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnGetImage: TGetImageEvent read FOnGetImage write FOnGetImage;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ClearValue;
function Locate(const SearchField: TField; const AValue: string;
Exact: Boolean): Boolean;
procedure ResetField; virtual;
{$IFDEF RX_D4}
function ExecuteAction(Action: TBasicAction): Boolean; override;
function UpdateAction(Action: TBasicAction): Boolean; override;
function UseRightToLeftAlignment: Boolean; override;
{$ENDIF}
property Field: TField read GetField;
end;
{ TRxDBLookupList }
TRxDBLookupList = class(TRxLookupControl)
private
FRecordIndex: Integer;
FRecordCount: Integer;
FRowCount: Integer;
FBorderStyle: TBorderStyle;
FKeySelected: Boolean;
FTracking: Boolean;
FTimerActive: Boolean;
FLockPosition: Boolean;
FSelectEmpty: Boolean;
FMousePos: Integer;
function GetKeyIndex: Integer;
procedure ListDataChanged;
procedure SelectCurrent;
procedure SelectItemAt(X, Y: Integer);
procedure SetBorderStyle(Value: TBorderStyle);
procedure SetRowCount(Value: Integer);
procedure StopTimer;
procedure StopTracking;
procedure TimerScroll;
procedure UpdateScrollBar;
procedure UpdateBufferCount(Rows: Integer);
procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure WMCancelMode(var Message: TMessage); message WM_CANCELMODE;
procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
procedure WMTimer(var Message: TMessage); message WM_TIMER;
procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure KeyValueChanged; override;
procedure DisplayValueChanged; override;
procedure ListLinkActiveChanged; override;
procedure ListLinkDataChanged; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure Loaded; override;
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 Paint; override;
procedure UpdateDisplayEmpty(const Value: string); override;
{$IFDEF RX_D4}
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
{$ENDIF}
public
constructor Create(AOwner: TComponent); override;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
procedure DrawItemText(Canvas: TCanvas; Rect: TRect;
Selected, IsEmpty: Boolean); virtual;
property RowCount: Integer read FRowCount write SetRowCount stored False;
property DisplayValue;
property Value;
{$IFDEF WIN32}
property KeyValue;
{$ENDIF}
published
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
property Align;
property Color;
property Ctl3D;
property DataField;
property DataSource;
property DisplayEmpty;
property DragCursor;
property DragMode;
property EmptyItemColor;
property EmptyValue;
property Enabled;
property FieldsDelimiter;
property Font;
property IgnoreCase;
{$IFDEF RX_D4}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
{$ENDIF}
{$IFDEF WIN32}
{$IFNDEF VER90}
property ImeMode;
property ImeName;
{$ENDIF}
{$ENDIF}
property IndexSwitch;
property ItemHeight;
property ListStyle;
property LookupField;
property LookupDisplay;
property LookupDisplayIndex;
property LookupSource;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetImage;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
{$IFDEF WIN32}
property OnStartDrag;
{$ENDIF}
{$IFDEF RX_D5}
property OnContextPopup;
{$ENDIF}
{$IFDEF RX_D4}
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
{ TRxDBLookupCombo }
TRxPopupDataList = class(TRxDBLookupList)
private
FCombo: TRxLookupControl;
procedure WMMouseActivate(var Message: TMessage); message WM_MOUSEACTIVATE;
protected
procedure Click; override;
procedure CreateParams(var Params: TCreateParams); override;
{$IFNDEF WIN32}
procedure CreateWnd; override;
{$ENDIF}
procedure KeyPress(var Key: Char); override;
public
constructor Create(AOwner: TComponent); override;
end;
{$IFNDEF WIN32}
TDropDownAlign = (daLeft, daRight, daCenter);
{$ENDIF}
TRxDBLookupCombo = class(TRxLookupControl)
private
FDataList: TRxPopupDataList;
FButtonWidth: Integer;
FDropDownCount: Integer;
FDropDownWidth: Integer;
FDropDownAlign: TDropDownAlign;
FEscapeClear: Boolean;
FListVisible: Boolean;
FPressed: Boolean;
FTracking: Boolean;
FAlignment: TAlignment;
FSelImage: TPicture;
FSelMargin: Integer;
FDisplayValues: TStrings;
FDisplayAll: Boolean;
{$IFNDEF WIN32}
FBtnGlyph: TBitmap;
FBtnDisabled: TBitmap;
{$ENDIF}
FOnDropDown: TNotifyEvent;
FOnCloseUp: TNotifyEvent;
procedure ListMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure StopTracking;
procedure TrackButton(X, Y: Integer);
function GetMinHeight: Integer;
function GetText: string;
procedure InvalidateText;
procedure UpdateCurrentImage;
procedure PaintDisplayValues(Canvas: TCanvas; R: TRect; ALeft: Integer);
procedure SetFieldsDelim(Value: Char); override;
procedure SetListStyle(Value: TLookupListStyle); override;
function GetDisplayAll: Boolean;
procedure SetDisplayAll(Value: Boolean);
function GetDisplayValues(Index: Integer): string;
procedure CMCancelMode(var Message: TCMCancelMode); message CM_CANCELMODE;
{$IFDEF WIN32}
procedure CNKeyDown(var Message: TWMKeyDown); message CN_KEYDOWN;
procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;
{$ENDIF}
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure WMCancelMode(var Message: TMessage); message WM_CANCELMODE;
procedure WMGetDlgCode(var Message: TMessage); message WM_GETDLGCODE;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMSetCursor(var Message: TWMSetCursor); message WM_SETCURSOR;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
{$IFDEF RX_D4}
procedure CMBiDiModeChanged(var Message: TMessage); message CM_BIDIMODECHANGED;
{$ENDIF}
protected
procedure Click; override;
procedure CreateParams(var Params: TCreateParams); override;
function GetPicture(Current, Empty: Boolean; var TextMargin: Integer): TGraphic; override;
procedure UpdateFieldText;
procedure KeyValueChanged; override;
procedure DisplayValueChanged; override;
procedure ListLinkActiveChanged; override;
procedure ListLinkDataChanged; override;
procedure Paint; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
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 UpdateDisplayEmpty(const Value: string); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure CloseUp(Accept: Boolean); dynamic;
procedure DropDown; virtual;
procedure ResetField; override;
property IsDropDown: Boolean read FListVisible;
property ListVisible: Boolean read FListVisible;
property Text: string read GetText;
property DisplayValue;
property DisplayValues[Index: Integer]: string read GetDisplayValues;
property Value;
{$IFDEF WIN32}
property KeyValue;
{$ENDIF}
published
property DropDownAlign: TDropDownAlign read FDropDownAlign write FDropDownAlign default daLeft;
property DropDownCount: Integer read FDropDownCount write FDropDownCount default 7;
property DropDownWidth: Integer read FDropDownWidth write FDropDownWidth default 0;
property EscapeClear: Boolean read FEscapeClear write FEscapeClear default True;
property DisplayAllFields: Boolean read GetDisplayAll write SetDisplayAll default False;
property Color;
property Ctl3D;
property DataField;
property DataSource;
property DisplayEmpty;
property DragCursor;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -