📄 jvdblookuptreeview.pas
字号:
Alignment: TAlignment;
Selected: Boolean;
R: TRect;
{added by zelen}
{$IFDEF JVCLThemesEnabled}
State: TThemedComboBox;
Details: TThemedElementDetails;
{$ENDIF JVCLThemesEnabled}
{/added by zelen}
begin
Canvas.Font := Font;
Canvas.Brush.Color := Color;
Selected := FFocused and not FListVisible and not (csPaintCopy in ControlState);
if Selected then
begin
Canvas.Font.Color := clHighlightText;
Canvas.Brush.Color := clHighlight;
end
{added by zelen}
else
if not Enabled and NewStyleControls then
Canvas.Font.Color := clGrayText;
{/added by zelen}
if (csPaintCopy in ControlState) and (FDataField <> nil) then
begin
Text := FDataField.DisplayText;
Alignment := FDataField.Alignment;
end
else
begin
Text := FText;
Alignment := FAlignment;
end;
W := ClientWidth - FButtonWidth;
X := 2;
case Alignment of
taRightJustify: X := W - Canvas.TextWidth(Text) - 3;
taCenter: X := (W - Canvas.TextWidth(Text)) div 2;
end;
SetRect(R, 1, 1, W - 1, ClientHeight - 1);
Canvas.TextRect(R, X, 2, Text);
if Selected then
Canvas.DrawFocusRect(R);
SetRect(R, W, 0, ClientWidth, ClientHeight);
{added by zelen}
{$IFDEF JVCLThemesEnabled}
if ThemeServices.ThemesEnabled then
begin
if (not FListActive) or (not Enabled) or ReadOnly then
State := tcDropDownButtonDisabled
else
if FPressed then
State := tcDropDownButtonPressed
else
if MouseOver and not FListVisible then
State := tcDropDownButtonHot
else
State := tcDropDownButtonNormal;
Details := ThemeServices.GetElementDetails(State);
ThemeServices.DrawElement(Canvas.Handle, Details, R);
end
else
{$ENDIF JVCLThemesEnabled}
{/added by zelen}
begin
if not FListActive or not Enabled or ReadOnly then
Flags := DFCS_SCROLLCOMBOBOX or DFCS_INACTIVE
else
if FPressed then
Flags := DFCS_SCROLLCOMBOBOX or DFCS_FLAT or DFCS_PUSHED
else
Flags := DFCS_SCROLLCOMBOBOX;
DrawFrameControl(Canvas.Handle, R, DFC_SCROLL, Flags);
end;
end;
procedure TJvDBLookupTreeViewCombo.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, GetTextHeight + GetBorderSize + 4);
end;
procedure TJvDBLookupTreeViewCombo.KeyValueChanged;
begin
if FLookupMode then
begin
FText := FDataField.DisplayText;
FAlignment := FDataField.Alignment;
end
else
if FListActive and LocateKey then
begin
FText := FListField.DisplayText;
FAlignment := FListField.Alignment;
end
else
begin
FText := '';
FAlignment := taLeftJustify;
end;
Invalidate;
end;
procedure TJvDBLookupTreeViewCombo.ListLinkActiveChanged;
begin
inherited ListLinkActiveChanged;
KeyValueChanged;
end;
procedure TJvDBLookupTreeViewCombo.CloseUp(Accept: Boolean);
var
ListValue: Variant;
begin
if FListVisible then
begin
if GetCapture <> 0 then
SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
ListValue := FDataList.GetValue;
SetFocus;
FDataList.Hide;
{ SetWindowPos(FDataList.Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or
SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW); }
FListVisible := False;
// FDataList.ListSource := nil;
FDataList.FTree.DataSource := nil;
Invalidate;
FSearchText := '';
if Accept and CanModify then
SelectKeyValue(ListValue);
if Assigned(FOnCloseUp) then
FOnCloseUp(Self);
FPressed := False;
Repaint;
end;
end;
procedure TJvDBLookupTreeViewCombo.DropDown;
var
P: TPoint;
{I,}Y: Integer;
{S: string;}
OldLong: Longword;
begin
if not FListVisible and FListActive then
begin
if Assigned(FOnDropDown) then
FOnDropDown(Self);
FDataList.Color := Color;
FDataList.Font := Font;
if FDropDownWidth > 0 then
FDataList.Width := FDropDownWidth
else
FDataList.Width := Width;
FDataList.Height := FDropDownHeight;
// FDataList.RowCount := FDropDownRows;
// FDataList.KeyField := FKeyFieldName;
FDataList.FTree.MasterField := FKeyFieldName;
FDataList.FTree.DetailField := FDetailField;
FDataList.FTree.IconField := FIconField;
FDataList.FTree.MasterField := FMasterField;
FDataList.FTree.StartMasterValue := FStartMasterValue;
FDataList.FTree.UseFilter := FUseFilter;
{Source added by Oussama Al-Rifai}
OldLong := GetWindowLong(FDataList.FTree.Handle, GWL_EXSTYLE);
if BiDiMode <> bdLeftToRight then
begin
FDataList.FTree.BiDiMode := bdLeftToRight;
SetWindowLong(FDataList.FTree.Handle, GWL_EXSTYLE, OldLong or $00400000);
end
else
SetWindowLong(FDataList.FTree.Handle, GWL_EXSTYLE, OldLong and not $00400000);
{End of source added by Oussama Al-Rifai}
FDataList.FTree.AutoExpand := FAutoExpand;
FDataList.FTree.ChangeDelay := FChangeDelay;
FDataList.FTree.HotTrack := FHotTrack;
FDataList.FTree.RowSelect := FRowSelect;
FDataList.FTree.ToolTips := FToolTips;
FDataList.FTree.OnCustomDraw := FOnCustomDraw;
FDataList.FTree.OnCustomDrawItem := FOnCustomDrawItem;
FDataList.FTree.OnGetImageIndex := FOnGetImageIndex;
FDataList.FTree.ReadOnly := not FDataLink.ReadOnly;
{ for I := 0 to FListFields.Count - 1 do
S := S + TField(FListFields[I]).FieldName + ';';
FDataList.ListField := S;}
FDataList.FTree.ItemField := ListField;
// FDataList.ListFieldIndex := FListFields.IndexOf(FListField);
// FDataList.ListSource := FListLink.DataSource;
FDataList.FTree.DataSource := FListLink.DataSource;
{ FDataList.FTree.FullExpand;
FDataList.FTree.FullCollapse;
FDataList.FTree.DataChanged; }
FDataList.SetValue(FListLink.DataSet.Lookup(FKeyFieldName, FKeyValue, FMasterField));
// FDataList.KeyValue := KeyValue;
P := Parent.ClientToScreen(Point(Left, Top));
Y := P.Y + Height;
if Y + FDataList.Height > Screen.Height then
Y := P.Y - FDataList.Height;
case FDropDownAlign of
daRight: Dec(P.X, FDataList.Width - Width);
daCenter: Dec(P.X, (FDataList.Width - Width) div 2);
end;
// FDataList.Left := P.X;
// FDataList.Top := P.Y;
P.Y := Y;
FListVisible := True;
FDataList.Show(P);
// FDataList.Visible := True;
// SetWindowPos(FDataList.Handle, HWND_TOP, P.X, Y, 0, 0,
// SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
if FullExpand then
FDataList.FTree.FullExpand;
Repaint;
end;
end;
procedure TJvDBLookupTreeViewCombo.KeyDown(var Key: Word; Shift: TShiftState);
var
Delta: Integer;
begin
inherited KeyDown(Key, Shift);
if FListActive and ((Key = VK_UP) or (Key = VK_DOWN)) then
if ssAlt in Shift then
begin
if FListVisible then
CloseUp(True)
else
DropDown;
Key := 0;
end
else
if not FListVisible then
begin
if not LocateKey then
FListLink.DataSet.First
else
begin
if Key = VK_UP then
Delta := -1
else
Delta := 1;
FListLink.DataSet.MoveBy(Delta);
end;
SelectKeyValue(FKeyField.Value);
Key := 0;
end;
if (Key <> 0) and FListVisible then
// FDataList.KeyDown(Key, Shift);
SendMessage(FDataList.FTree.Handle, WM_KEYDOWN, Key, 0);
end;
procedure TJvDBLookupTreeViewCombo.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if FListVisible then
if Word(Key) in [VK_RETURN, VK_ESCAPE] then
CloseUp(Word(Key) = VK_RETURN)
else
FDataList.KeyPress(Key)
else
ProcessSearchKey(Key);
end;
procedure TJvDBLookupTreeViewCombo.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if Button = mbLeft then
begin
SetFocus;
if not FFocused then
Exit;
if FListVisible then
CloseUp(False)
else
if FListActive then
begin
MouseCapture := True;
FTracking := True;
TrackButton(X, Y);
DropDown;
end;
end;
inherited MouseDown(Button, Shift, X, Y);
end;
procedure TJvDBLookupTreeViewCombo.MouseMove(Shift: TShiftState; X, Y: Integer);
var
ListPos: TPoint;
MousePos: TSmallPoint;
begin
if FTracking then
begin
TrackButton(X, Y);
if FListVisible then
begin
ListPos := FDataList.ScreenToClient(ClientToScreen(Point(X, Y)));
if PtInRect(FDataList.ClientRect, ListPos) then
begin
StopTracking;
MousePos := PointToSmallPoint(ListPos);
SendMessage(FDataList.FTree.Handle, WM_LBUTTONDOWN, 0, Integer(MousePos));
Exit;
end;
end;
end;
inherited MouseMove(Shift, X, Y);
end;
procedure TJvDBLookupTreeViewCombo.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
StopTracking;
inherited MouseUp(Button, Shift, X, Y);
end;
procedure TJvDBLookupTreeViewCombo.StopTracking;
begin
if FTracking then
begin
TrackButton(-1, -1);
FTracking := False;
MouseCapture := False;
end;
end;
procedure TJvDBLookupTreeViewCombo.TrackButton(X, Y: Integer);
var
NewState: Boolean;
begin
Repaint;
NewState := PtInRect(Rect(ClientWidth - FButtonWidth, 0, ClientWidth,
ClientHeight), Point(X, Y));
if FPressed <> NewState then
begin
FPressed := NewState;
Repaint;
end;
end;
procedure TJvDBLookupTreeViewCombo.CMCtl3DChanged(var Msg: TMessage);
begin
if NewStyleControls then
begin
RecreateWnd;
Height := 0;
end;
inherited;
end;
procedure TJvDBLookupTreeViewCombo.FontChanged;
begin
inherited FontChanged;
Height := 0;
end;
procedure TJvDBLookupTreeViewCombo.CMGetDataLink(var Msg: TMessage);
begin
Msg.Result := Integer(FDataLink);
end;
procedure TJvDBLookupTreeViewCombo.WMCancelMode(var Msg: TMessage);
begin
StopTracking;
inherited;
end;
procedure TJvDBLookupTreeViewCombo.CMCancelMode(var Msg: TCMCancelMode);
begin
if (Msg.Sender <> Self) and (Msg.Sender <> FDataList) and
((FDataList <> nil) and
not FDataList.ContainsControl(Msg.Sender)) then
PopupCloseUp(FDataList, False);
end;
procedure TJvDBLookupTreeViewCombo.PopupCloseUp(Sender: TObject;
Accept: Boolean);
var
AValue: Variant;
begin
if (FDataList <> nil) and FListVisible then
begin
if GetCapture <> 0 then
SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
AValue := FDataList.GetValue;
FDataList.Hide;
try
try
if CanFocus then
SetFocus;
except
{ ignore exceptions }
end;
// SetDirectInput(DirectInput);
Invalidate;
finally
FListVisible := False;
end;
end;
end;
//=== { TJvTreePopupDataList } ===============================================
constructor TJvTreePopupDataList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// ControlStyle := ControlStyle + [csNoDesignVisible, csReplicatable];
// TabStop := False;
FTree := TJvPopupTree.Create(Self);
FTree.Parent := Self;
FTree.Align := alClient;
FTree.ReadOnly := True;
FTree.BorderStyle := bsNone;
FTree.HideSelection := False;
FTree.TabStop := False;
// FTree.OnDblClick := OnDblClick2;
end;
destructor TJvTreePopupDataList.Destroy;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -