📄 jvdblookuptreeview.pas
字号:
begin
FTree.Free;
inherited Destroy;
end;
function TJvTreePopupDataList.GetPopupText: string;
begin
Result := GetValue;
end;
function TJvTreePopupDataList.GetValue: Variant;
begin
if FTree.Selected <> nil then
// Result := (FTree.Selected as TJvDBTreeNode).MasterValue
Result := FTree.DataSource.DataSet.Lookup(FTree.MasterField,
(FTree.Selected as TJvDBTreeNode).MasterValue, (Owner as TJvDBLookupControl).KeyField)
else
Result := Null;
end;
procedure TJvTreePopupDataList.SetValue(const Value: Variant);
begin
FTree.SelectNode(Value);
end;
//=== { TJvPopupTree } =======================================================
{******* from ComCtl98 unit}
// Jean-Luc Mattei
// jlucm dott club-internet att fr
const
NM_CUSTOMDRAW = (NM_FIRST - 12);
CDDS_PREPAINT = $000000001;
CDRF_NOTIFYITEMDRAW = $00000020;
CDDS_ITEM = $000010000;
CDDS_ITEMPREPAINT = (CDDS_ITEM or CDDS_PREPAINT);
CDIS_SELECTED = $0001;
type
PNMCustomDrawInfo = ^TNMCustomDrawInfo;
TNMCustomDrawInfo = packed record
hdr: TNMHdr;
dwDrawStage: Longint;
hdc: HDC;
rc: TRect;
dwItemSpec: Longint; // this is control specific, but it's how to specify an item. valid only with CDDS_ITEM bit set
uItemState: Cardinal;
lItemlParam: Longint;
end;
{####### from ComCtl98 unit}
procedure TJvPopupTree.CNNotify(var Msg: TWMNotify);
begin
with Msg.NMHdr^ do
case code of
NM_CUSTOMDRAW:
begin
with PNMCustomDrawInfo(Pointer(Msg.NMHdr))^ do
begin
if (dwDrawStage and CDDS_PREPAINT) = CDDS_PREPAINT then
Msg.Result := CDRF_NOTIFYITEMDRAW;
if (dwDrawStage and CDDS_ITEMPREPAINT) = CDDS_ITEMPREPAINT then
begin
if (uItemState and CDIS_SELECTED) <> 0 then
begin
SetTextColor(hdc, ColorToRGB(clHighlightText));
SetBkColor(hdc, ColorToRGB(clHighlight));
end;
Msg.Result := CDRF_NOTIFYITEMDRAW;
end;
end;
end;
else
inherited;
end;
end;
procedure TJvPopupTree.FocusSet(PrevWnd: HWND);
begin
inherited FocusSet(PrevWnd);
(Owner.Owner as TJvDBLookupTreeViewCombo).SetFocus;
end;
procedure TJvPopupTree.DblClick;
begin
(Owner.Owner as TJvDBLookupTreeViewCombo).CloseUp(True);
end;
//=== { TJvDBLookupTreeView } ================================================
type
TJvDBLookupTreeViewTree = class(TJvDBTreeView)
private
procedure DataScrolled; override;
procedure DataChanged; override;
procedure Change2(Node: TTreeNode); override;
procedure DefaultHandler(var Message); override;
end;
constructor TJvDBLookupTreeView.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBorderStyle := bsSingle;
FTree := TJvDBLookupTreeViewTree.Create(Self);
FTree.Parent := Self;
Width := FTree.Width;
Height := FTree.Height;
FTree.Align := alClient;
FTree.ReadOnly := True;
FTree.BorderStyle := bsNone;
FTree.HideSelection := False;
// FTree.TabStop := False;
end;
destructor TJvDBLookupTreeView.Destroy;
begin
FTree.Free;
inherited Destroy;
end;
procedure TJvDBLookupTreeView.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
if FBorderStyle = bsSingle then
if NewStyleControls and Ctl3D then
ExStyle := ExStyle or WS_EX_CLIENTEDGE
else
Style := Style or WS_BORDER;
end;
procedure TJvDBLookupTreeView.SetBorderStyle(Value: TBorderStyle);
begin
if FBorderStyle <> Value then
begin
FBorderStyle := Value;
RecreateWnd;
end;
end;
function TJvDBLookupTreeView.GetMasterField: string;
begin
Result := FTree.MasterField;
end;
procedure TJvDBLookupTreeView.SetMasterField(Value: string);
begin
FTree.MasterField := Value;
end;
function TJvDBLookupTreeView.GetDetailField: string;
begin
Result := FTree.DetailField;
end;
procedure TJvDBLookupTreeView.SetDetailField(Value: string);
begin
FTree.DetailField := Value;
end;
function TJvDBLookupTreeView.GetIconField: string;
begin
Result := FTree.IconField;
end;
procedure TJvDBLookupTreeView.SetIconField(const Value: string);
begin
FTree.IconField := Value;
end;
function TJvDBLookupTreeView.GetStartMasterValue: string;
begin
Result := FTree.StartMasterValue;
end;
procedure TJvDBLookupTreeView.SetStartMasterValue(Value: string);
begin
FTree.StartMasterValue := Value;
end;
procedure TJvDBLookupTreeView.ListLinkActiveChanged;
begin
inherited ListLinkActiveChanged;
FTree.DataSource := ListSource;
FTree.ItemField := ListField;
end;
procedure TJvDBLookupTreeView.KeyValueChanged;
begin
InKeyValueChanged := True;
try
TJvDBLookupTreeViewTree(FTree).SelectNode(FKeyValue);
finally
InKeyValueChanged := False;
end;
end;
procedure TJvDBLookupTreeView.FocusSet(PrevWnd: HWND);
begin
FTree.SetFocus;
end;
{** Tree}
function TJvDBLookupTreeView.GetShowButtons: Boolean;
begin
Result := FTree.ShowButtons;
end;
function TJvDBLookupTreeView.GetShowLines: Boolean;
begin
Result := FTree.ShowLines;
end;
function TJvDBLookupTreeView.GetShowRoot: Boolean;
begin
Result := FTree.ShowRoot;
end;
function TJvDBLookupTreeView.GetReadOnly: Boolean;
begin
Result := FTree.ReadOnly;
end;
function TJvDBLookupTreeView.GetRightClickSelect: Boolean;
begin
Result := FTree.RightClickSelect;
end;
function TJvDBLookupTreeView.GetHideSelection: Boolean;
begin
Result := FTree.HideSelection;
end;
function TJvDBLookupTreeView.GetIndent: Integer;
begin
Result := FTree.Indent;
end;
procedure TJvDBLookupTreeView.SetShowButtons(Value: Boolean);
begin
FTree.ShowButtons := Value;
end;
procedure TJvDBLookupTreeView.SetShowLines(Value: Boolean);
begin
FTree.ShowLines := Value;
end;
procedure TJvDBLookupTreeView.SetShowRoot(Value: Boolean);
begin
FTree.ShowRoot := Value;
end;
procedure TJvDBLookupTreeView.SetReadOnly(Value: Boolean);
begin
FTree.ReadOnly := Value;
end;
procedure TJvDBLookupTreeView.SetRightClickSelect(Value: Boolean);
begin
FTree.RightClickSelect := Value;
end;
procedure TJvDBLookupTreeView.SetHideSelection(Value: Boolean);
begin
FTree.HideSelection := Value;
end;
procedure TJvDBLookupTreeView.SetIndent(Value: Integer);
begin
FTree.Indent := Value;
end;
{ Translate properties }
function TJvDBLookupTreeView.GetAutoExpand: Boolean;
begin
Result := FTree.AutoExpand;
end;
function TJvDBLookupTreeView.GetChangeDelay: Integer;
begin
Result := FTree.ChangeDelay;
end;
function TJvDBLookupTreeView.GetHotTrack: Boolean;
begin
Result := FTree.HotTrack;
end;
function TJvDBLookupTreeView.GetOnCustomDraw: TTVCustomDrawEvent;
begin
Result := FTree.OnCustomDraw;
end;
function TJvDBLookupTreeView.GetOnCustomDrawItem: TTVCustomDrawItemEvent;
begin
Result := FTree.OnCustomDrawItem;
end;
function TJvDBLookupTreeView.GetOnGetImageIndex: TTVExpandedEvent;
begin
Result := FTree.OnGetImageIndex;
end;
function TJvDBLookupTreeView.GetRowSelect: Boolean;
begin
Result := FTree.RowSelect;
end;
function TJvDBLookupTreeView.GetToolTips: Boolean;
begin
Result := FTree.ToolTips;
end;
procedure TJvDBLookupTreeView.SetAutoExpand(const Value: Boolean);
begin
FTree.AutoExpand := Value;
end;
procedure TJvDBLookupTreeView.SetChangeDelay(const Value: Integer);
begin
FTree.ChangeDelay := Value;
end;
procedure TJvDBLookupTreeView.SetHotTrack(const Value: Boolean);
begin
FTree.HotTrack := Value;
end;
procedure TJvDBLookupTreeView.SetOnCustomDraw(const Value: TTVCustomDrawEvent);
begin
FTree.OnCustomDraw := Value;
end;
procedure TJvDBLookupTreeView.SetOnCustomDrawItem(const Value: TTVCustomDrawItemEvent);
begin
FTree.OnCustomDrawItem := Value;
end;
procedure TJvDBLookupTreeView.SetOnGetImageIndex(const Value: TTVExpandedEvent);
begin
FTree.OnGetImageIndex := Value;
end;
procedure TJvDBLookupTreeView.SetRowSelect(const Value: Boolean);
begin
FTree.RowSelect := Value;
end;
procedure TJvDBLookupTreeView.SetToolTips(const Value: Boolean);
begin
FTree.ToolTips := Value;
end;
{# Translate properties }
//=== { TJvDBLookupTreeViewTree } ============================================
procedure TJvDBLookupTreeViewTree.DataScrolled;
begin
end;
procedure TJvDBLookupTreeViewTree.DataChanged;
begin
inherited DataChanged;
end;
procedure TJvDBLookupTreeViewTree.Change2(Node: TTreeNode);
begin
with Owner as TJvDBLookupTreeView do
if not InKeyValueChanged then
begin
FListLink.DataSet.Locate(MasterField, (Node as TJvDBTreeNode).MasterValue, []);
SelectKeyValue(FKeyField.Value);
KeyValueChanged;
end;
end;
procedure TJvDBLookupTreeViewTree.DefaultHandler(var Message);
begin
inherited DefaultHandler(Message);
with TMessage(Message) do
case Msg of
WM_KEYDOWN, WM_KEYUP, WM_CHAR, WM_LBUTTONDOWN, WM_LBUTTONUP,
WM_RBUTTONDOWN, WM_RBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP,
WM_MOUSEMOVE:
PostMessage((Owner as TWinControl).Handle, Msg, WParam, LParam);
end;
end;
procedure TJvDBLookupTreeViewCombo.FocusKilled(NextWnd: HWND);
begin
if (Handle <> NextWnd) and (FDataList.Handle <> NextWnd) and
(FDataList.FTree.Handle <> NextWnd) then
CloseUp(False);
end;
{added by zelen}
{$IFDEF JVCLThemesEnabled}
procedure TJvDBLookupTreeViewCombo.MouseEnter(Control: TControl);
begin
if csDesigning in ComponentState then
Exit;
inherited MouseEnter(Control);
{Windows XP themes use hot track states, hence we have to update the drop down button.}
if ThemeServices.ThemesEnabled and not MouseOver and not (csDesigning in ComponentState) then
Invalidate;
end;
procedure TJvDBLookupTreeViewCombo.MouseLeave(Control: TControl);
begin
if csDesigning in ComponentState then
Exit;
if ThemeServices.ThemesEnabled and MouseOver then
Invalidate;
inherited MouseLeave(Control);
end;
{$ENDIF JVCLThemesEnabled}
{/added by zelen}
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -