📄 tntjvdblookup.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvLookup.PAS, released on 2002-07-04.
The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.
Contributor(s):
Polaris Software
Copyright (c) 1995,1997 Borland International
Portions copyright (c) 1995, 1996 AO ROSNO
Portions copyright (c) 1997, 1998 Master-Bank
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvDBLookup.pas,v 1.55 2005/09/09 10:04:38 obones Exp $
unit TntJvDBLookup;
{$I jvcl.inc}
{$I TntCompilers.inc}
{$D-}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF VCL}
Windows, Messages,
{$ENDIF VCL}
Classes, Graphics, Controls, Forms, DB, DBCtrls,
JvDBUtils, JvToolEdit, JvComponent, JvExControls, TntJvExControls,
TntClasses, TntJvToolEdit, TntJvDBUtils;
const
// (rom) renamed
DefFieldsDelimiter = ',';
type
TLookupListStyle = (lsFixed, lsDelimited);
TTntJvLookupControl = class;
TGetImageEvent = procedure(Sender: TObject; IsEmpty: Boolean;
var Graphic: TGraphic; var TextMargin: Integer) of object;
TJvDataSourceLink = class(TDataLink)
private
FDataControl: TTntJvLookupControl;
protected
procedure ActiveChanged; override;
procedure LayoutChanged; override;
procedure FocusControl(Field: TFieldRef); override;
procedure RecordChanged(Field: TField); override;
end;
TTntLookupSourceLink = class(TDataLink)
private
FDataControl: TTntJvLookupControl;
protected
procedure ActiveChanged; override;
procedure LayoutChanged; override;
procedure DataSetChanged; override;
end;
TTntJvLookupControl = class(TTntJvExCustomControl)
private
FLookupSource: TDataSource;
FDataLink: TJvDataSourceLink;
FLookupLink: TTntLookupSourceLink;
FDataFieldName: string;
FLookupFieldName: string;
FLookupDisplay: string;
FDisplayIndex: Integer;
FDataField: TField;
FMasterField: TField;
FKeyField: TField;
FDisplayField: TField;
FListFields: TList;
FValue: WideString;
FDisplayValue: WideString;
FDisplayEmpty: WideString;
FSearchText: WideString;
FEmptyValue: WideString;
FEmptyStrIsNull: Boolean; // Polaris
FEmptyItemColor: TColor;
FListActive: Boolean;
FPopup: Boolean;
FFocused: Boolean;
FLocate: TTntJvLocateObject;
FIndexSwitch: Boolean;
FIgnoreCase: Boolean;
FItemHeight: Integer;
FFieldsDelimiter: Char;
FListStyle: TLookupListStyle;
FLookupFormat: WideString;
FOnChange: TNotifyEvent;
FOnGetImage: TGetImageEvent;
FLookupMode: Boolean;
procedure CheckNotFixed;
procedure SetLookupMode(Value: Boolean);
function GetKeyValue: Variant;
procedure SetKeyValue(const Value: Variant);
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 GetTextHeight: Integer;
function DefaultTextHeight: Integer;
function GetItemHeight: Integer;
function LocateKey: Boolean;
function LocateDisplay: Boolean;
function ValueIsEmpty(const S: WideString): Boolean;
function StoreEmpty: Boolean;
procedure ProcessSearchKey(Key: WideChar);
procedure UpdateKeyValue;
procedure SelectKeyValue(const Value: WideString);
procedure SetDataFieldName(const Value: string);
procedure SetDataSource(Value: TDataSource);
procedure SetDisplayEmpty(const Value: WideString);
procedure SetEmptyValue(const Value: WideString);
procedure SetEmptyStrIsNull(const Value: Boolean); // Polaris
procedure SetEmptyItemColor(Value: TColor);
procedure SetLookupField(const Value: string);
procedure SetValueKey(const Value: WideString);
procedure SetValue(const Value: WideString);
procedure SetDisplayValue(const Value: WideString);
procedure SetListStyle(Value: TLookupListStyle); virtual;
procedure SetFieldsDelimiter(Value: Char); virtual;
procedure SetLookupDisplay(const Value: string);
procedure SetLookupFormat(const Value: WideString);
procedure SetLookupSource(Value: TDataSource);
procedure SetItemHeight(Value: Integer);
function ItemHeightStored: Boolean;
procedure DrawPicture(Canvas: TCanvas; Rect: TRect; Image: TGraphic);
procedure UpdateDisplayValue;
function EmptyRowVisible: Boolean;
protected
procedure FocusKilled(NextWnd: THandle); override;
procedure FocusSet(PrevWnd: THandle); override;
procedure GetDlgCode(var Code: TDlgCodes); override;
function GetReadOnly: Boolean;virtual;
procedure SetReadOnly(Value: Boolean);virtual;
procedure Change; dynamic;
procedure CreateWindowHandle(const Params: TCreateParams); override;
procedure DefineProperties(Filer: TFiler); override;
procedure KeyValueChanged; virtual;
procedure DisplayValueChanged; virtual;
function DoFormatLine: WideString;
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: WideString); virtual;
function SearchText(var AValue: WideString): Boolean;
function GetWindowWidth: Integer;
property DataField: string read FDataFieldName write SetDataFieldName;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property DisplayEmpty: WideString read FDisplayEmpty write SetDisplayEmpty;
property EmptyValue: WideString read FEmptyValue write SetEmptyValue stored StoreEmpty;
property EmptyStrIsNull: Boolean read FEmptyStrIsNull write SetEmptyStrIsNull default True; // Polaris
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 FFieldsDelimiter write SetFieldsDelimiter default DefFieldsDelimiter;
property LookupDisplay: string read FLookupDisplay write SetLookupDisplay;
property LookupDisplayIndex: Integer read FDisplayIndex write FDisplayIndex default 0;
property LookupField: string read GetLookupField write SetLookupField;
property LookupFormat: WideString read FLookupFormat write SetLookupFormat;
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: WideString read FValue write SetValue stored False;
property DisplayValue: WideString read FDisplayValue write SetDisplayValue stored False;
property KeyValue: Variant read GetKeyValue write SetKeyValue stored False;
procedure SetFieldValue(Field: TField; const Value: WideString); // Polaris
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: WideString;
Exact: Boolean): Boolean;
procedure ResetField; virtual;
function ExecuteAction(Action: TBasicAction): Boolean; override;
function UpdateAction(Action: TBasicAction): Boolean; override;
function UseRightToLeftAlignment: Boolean; override;
property Field: TField read GetField;
end;
TTntJvDBLookupList = class(TTntJvLookupControl)
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 Msg: TMessage); message CM_CTL3DCHANGED;
procedure WMCancelMode(var Msg: TMessage); message WM_CANCELMODE;
procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
procedure WMTimer(var Msg: TMessage); message WM_TIMER;
procedure WMVScroll(var Msg: TWMVScroll); message WM_VSCROLL;
protected
procedure FontChanged; override;
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: WideString); override;
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
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;
property KeyValue;
published
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
property Align;
property Color;
property DataField;
property DataSource;
property DisplayEmpty;
property DragCursor;
property DragMode;
property EmptyItemColor;
property EmptyValue;
property EmptyStrIsNull; // Polaris
property Enabled;
property FieldsDelimiter;
property Font;
property IgnoreCase;
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
property ImeMode;
property ImeName;
property IndexSwitch;
property ItemHeight;
property ListStyle;
property LookupField;
property LookupDisplay;
property LookupDisplayIndex;
property LookupFormat;
property LookupSource;
property ParentColor;
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;
property OnStartDrag;
property OnContextPopup;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnEndDock;
property OnStartDock;
end;
TTntJvPopupDataList = class(TTntJvDBLookupList)
private
FCombo: TTntJvLookupControl;
procedure WMMouseActivate(var Msg: TMessage); message WM_MOUSEACTIVATE;
protected
procedure Click; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure KeyPress(var Key: Char); override;
public
constructor Create(AOwner: TComponent); override;
end;
TTntJvDBLookupCombo = class(TTntJvLookupControl)
private
FDataList: TTntJvPopupDataList;
FButtonWidth: Integer;
FDropDownCount: Integer;
FDropDownWidth: Integer;
FDropDownAlign: TDropDownAlign;
FEscapeClear: Boolean;
FListVisible: Boolean;
FPressed: Boolean;
FTracking: Boolean;
FAlignment: TAlignment;
FSelImage: TPicture;
FSelMargin: Integer;
FDisplayValues: TTntStrings;
FDisplayAllFields: Boolean;
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;
procedure InvalidateText;
procedure UpdateCurrentImage;
procedure PaintDisplayValues(Canvas: TCanvas; R: TRect; ALeft: Integer);
procedure SetFieldsDelimiter(Value: Char); override;
procedure SetListStyle(Value: TLookupListStyle); override;
function GetDisplayAllFields: Boolean;
procedure SetDisplayAllFields(Value: Boolean);
function GetDisplayValues(Index: Integer): WideString;
procedure CMCancelMode(var Msg: TCMCancelMode); message CM_CANCELMODE;
procedure CNKeyDown(var Msg: TWMKeyDown); message CN_KEYDOWN;
procedure CMCtl3DChanged(var Msg: TMessage); message CM_CTL3DCHANGED;
procedure CMGetDataLink(var Msg: TMessage); message CM_GETDATALINK;
procedure WMCancelMode(var Msg: TMessage); message WM_CANCELMODE;
procedure WMSetCursor(var Msg: TWMSetCursor); message WM_SETCURSOR;
procedure CMBiDiModeChanged(var Msg: TMessage); message CM_BIDIMODECHANGED;
protected
procedure FocusKilled(NextWnd: THandle); override;
procedure BoundsChanged; override;
procedure GetDlgCode(var Code: TDlgCodes); override;
procedure EnabledChanged; override;
procedure FontChanged; override;
{$IFDEF JVCLThemesEnabled}
procedure MouseEnter(Control: TControl); override;
procedure MouseLeave(Control: TControl); override;
{$ENDIF JVCLThemesEnabled}
procedure Click; override;
procedure CreateParams(var Params: TCreateParams); override;
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; 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: WideString); 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: WideString read GetText;
property DisplayValue;
property DisplayValues[Index: Integer]: WideString read GetDisplayValues;
property Value;
property KeyValue;
published
property Align; // Polaris
property DropDownAlign: TDropDownAlign read FDropDownAlign write FDropDownAlign default daLeft;
property DropDownCount: Integer read FDropDownCount write FDropDownCount default 8;
property DropDownWidth: Integer read FDropDownWidth write FDropDownWidth default 0;
property EscapeClear: Boolean read FEscapeClear write FEscapeClear default True;
property DisplayAllFields: Boolean read GetDisplayAllFields write SetDisplayAllFields default False;
property Color;
property DataField;
property DataSource;
property DisplayEmpty;
property DragCursor;
property DragMode;
property EmptyValue;
property EmptyStrIsNull; // Polaris
property EmptyItemColor;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -