cxlookupedit.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,186 行 · 第 1/3 页
PAS
1,186 行
begin
if ACircular and DataController.IsBOF then
DataController.GotoLast
else
if ADirection = egdPrev then
DataController.GotoPrev
else
DataController.MoveBy(-Properties.DropDownRows);
end;
end;
finally
Properties.UnlockDataChanged;
end;
DoSetCurrentKey(DataController.GetFocusedRecordIndex);
DoSetKeySelection(DataController.GetFocusedRecordIndex <> -1);
DoSelectItem;
finally
EnableChanging;
end;
end;
procedure TcxCustomLookupEditLookupData.Initialize(AVisualControlsParent: TWinControl);
begin
if Properties.GetLookupGridControl <> nil then
Properties.GetLookupGridControl.Parent := AVisualControlsParent;
end;
function TcxCustomLookupEditLookupData.IsEmpty: Boolean;
begin
Result := (GetListIndex = -1) or (DataController = nil) or
(DataController.RecordCount = 0);
end;
function TcxCustomLookupEditLookupData.IsMouseOverList(const P: TPoint): Boolean;
var
APoint: TPoint;
begin
if Properties.GetLookupGridControl <> nil then
begin
APoint := Properties.GetLookupGridControl.ScreenToClient(P);
Result := Properties.IsLookupGridMouseOverList(APoint);
end
else
Result := False;
end;
function TcxCustomLookupEditLookupData.Locate(var AText, ATail: string; ANext: Boolean): Boolean;
function SetGridFilter(AItemIndex: Integer; const AText: string): Integer;
var
APrevIncrementalFilterText: string;
begin
if AText = '' then
begin
ResetIncrementalFilter;
Result := Properties.FindByText(AItemIndex, AText, True);
end
else
begin
APrevIncrementalFilterText := DataController.GetIncrementalFilterText;
Result := DataController.SetIncrementalFilter(AItemIndex, AText);
if DataController.FilteredRecordCount = 0 then
begin
if Properties.DropDownListStyle <> lsEditList then
DataController.SetIncrementalFilter(AItemIndex, APrevIncrementalFilterText);
Result := -1;
end;
end;
UpdateDropDownCount;
end;
var
AItemIndex, ARecordIndex: Integer;
S: string;
begin
Result := False;
DisableChanging;
try
AItemIndex := GetListIndex;
if (AItemIndex <> -1) and (DataController <> nil) then
begin
// TODO: Next
if FVisible and Properties.GetIncrementalFiltering {and (Properties.DropDownListStyle <> lsFixedList)} then
ARecordIndex := SetGridFilter(AItemIndex, AText)
else
ARecordIndex := Properties.FindByText(AItemIndex, AText, True);
if ARecordIndex <> -1 then
begin
DataController.ChangeFocusedRecordIndex(ARecordIndex);
DoSetCurrentKey(ARecordIndex);
Result := True;
S := DataController.DisplayTexts[ARecordIndex, AItemIndex];
AText := Copy(S, 1, Length(AText));
ATail := Copy(S, Length(AText) + 1, Length(S));
DoSetKeySelection(True);
end
else
DoSetKeySelection(False);
end;
finally
EnableChanging;
end;
end;
procedure TcxCustomLookupEditLookupData.PositionVisualArea(const AClientRect: TRect);
begin
if Properties.GetLookupGridControl <> nil then
begin
with AClientRect do
Properties.GetLookupGridControl.SetBounds(Left, Top, Right - Left, Bottom - Top);
Properties.GetLookupGridControl.HandleNeeded;
Properties.LookupGridMakeFocusedRowVisible;
end;
end;
procedure TcxCustomLookupEditLookupData.PropertiesChanged;
begin
end;
procedure TcxCustomLookupEditLookupData.SelectItem;
begin
if IsKeySelected then
begin
DoSetCurrentKey(FocusedRecordIndex);
DoSelectItem;
end;
end;
procedure TcxCustomLookupEditLookupData.SetCurrentKey(const AKey: TcxEditValue);
begin
FCurrentKey := AKey;
SyncGrid;
end;
procedure TcxCustomLookupEditLookupData.SetOnCurrentKeyChanged(Value: TNotifyEvent);
begin
FOnCurrentKeyChanged := Value;
end;
procedure TcxCustomLookupEditLookupData.SetOnSelectItem(Value: TNotifyEvent);
begin
FOnSelectItem := Value;
end;
procedure TcxCustomLookupEditLookupData.TextChanged;
begin
if Edit.CanSynchronizeLookupData then
begin
DisableChanging;
try
SyncSelected;
finally
EnableChanging;
end;
end;
end;
// end IcxTextEditLookupData
procedure TcxCustomLookupEditLookupData.DoCurrentKeyChanged;
begin
if Assigned(FOnCurrentKeyChanged) then
FOnCurrentKeyChanged(Self);
end;
procedure TcxCustomLookupEditLookupData.DoSelectItem;
begin
if Assigned(FOnSelectItem) then
FOnSelectItem(Self);
end;
procedure TcxCustomLookupEditLookupData.DoSetCurrentKey(ARecordIndex: Integer);
begin
FCurrentKey := ARecordIndex;
end;
procedure TcxCustomLookupEditLookupData.DoSetKeySelection(AKeySelected: Boolean);
begin
if DataController <> nil then
DataController.SyncSelected(AKeySelected);
end;
procedure TcxCustomLookupEditLookupData.DoSyncGrid;
begin
if DataController <> nil then
DataController.ChangeFocusedRecordIndex(Integer(GetCurrentKey));
end;
procedure TcxCustomLookupEditLookupData.GridClick(Sender: TObject);
begin
SelectItem;
end;
procedure TcxCustomLookupEditLookupData.GridCloseUp(Sender: TObject; AAccept: Boolean);
begin
if AAccept then
Edit.CloseUp(crEnter)
else
Edit.CloseUp(crCancel)
end;
procedure TcxCustomLookupEditLookupData.GridFocusedRowChanged(Sender: TObject);
begin
// TODO: ImmediateUpdateText
end;
function TcxCustomLookupEditLookupData.IsKeySelected: Boolean;
begin
Result := (DataController <> nil) and (DataController.GetSelectedCount = 1) and
(DataController.GetFocusedRowIndex = DataController.GetSelectedRowIndex(0));
end;
function TcxCustomLookupEditLookupData.LocateText(const AText: string): Boolean;
var
AItemIndex, ARecordIndex: Integer;
begin
Result := False;
AItemIndex := GetListIndex;
if (AItemIndex <> -1) and (DataController <> nil) then
begin
// Result := InternalCompareString(AText, GetDisplayText(FCurrentKey), False);
// if Result then
// Exit;
// TODO: Search
ARecordIndex := Properties.FindByText(AItemIndex, AText, False);
if ARecordIndex <> -1 then
begin
DataController.ChangeFocusedRecordIndex(ARecordIndex);
DoSetCurrentKey(ARecordIndex);
Result := True;
DoSetKeySelection(True);
end
else
DoSetKeySelection(False);
end;
end;
procedure TcxCustomLookupEditLookupData.ResetIncrementalFilter;
begin
if DataController <> nil then
DataController.ResetIncrementalFilter;
end;
procedure TcxCustomLookupEditLookupData.SyncGrid;
begin
DoSyncGrid;
Properties.LookupGridMakeFocusedRowVisible;
end;
procedure TcxCustomLookupEditLookupData.SyncSelected;
var
ASelected: Boolean;
AItemIndex: Integer;
ARecordIndex: Integer;
S: string;
begin
if Properties.FInGridDataChanged then Exit;
if FVisible and Properties.GetIncrementalFiltering then
begin
if (DataController <> nil) and DataController.ChangeIncrementalFilterText(Edit.Text) then
UpdateDropDownCount;
end;
ASelected := False;
AItemIndex := GetListIndex;
if (DataController <> nil) and (AItemIndex <> -1) then
begin
ARecordIndex := FocusedRecordIndex;
if ARecordIndex <> -1 then
begin
S := DataController.DisplayTexts[ARecordIndex, AItemIndex];
ASelected := DataCompareText(S, Edit.Text, False);
end;
if not ASelected or not FVisible then // Properties.EditingStyle in [esEditList, esFixedList]
begin
ARecordIndex := Properties.FindByText(AItemIndex, Edit.Text, False);
if ARecordIndex <> -1 then
begin
ASelected := True;
DataController.ChangeFocusedRecordIndex(ARecordIndex);
DoSetCurrentKey(ARecordIndex);
end;
end;
end;
DoSetKeySelection(ASelected);
end;
procedure TcxCustomLookupEditLookupData.UpdateDropDownCount;
var
AGridRowCount, ARowCount, AHeight: Integer;
begin
if not FVisible then Exit;
if Edit.PopupWindow.IsVisible and (DataController <> nil) then
begin
AGridRowCount := DataController.GetRowCount;
ARowCount := Properties.DropDownRows;
if AGridRowCount > ARowCount then
AGridRowCount := ARowCount;
if AGridRowCount < 1 then
AGridRowCount := 1;
AHeight := Properties.GetLookupGridPopupHeight(AGridRowCount);
if (Properties.GetLookupGridControl <> nil) and
(Properties.GetLookupGridControl.ClientHeight <> AHeight) then
begin
if not Edit.PopupSizeChanged then
Edit.ResetPopupHeight;
Edit.SetupPopupWindow;
end;
end;
end;
function TcxCustomLookupEditLookupData.GetDataController: TcxCustomDataController;
begin
Result := Properties.DataController;
end;
function TcxCustomLookupEditLookupData.GetEdit: TcxCustomLookupEdit;
begin
Result := TcxCustomLookupEdit(FOwner);
end;
function TcxCustomLookupEditLookupData.GetFocusedRecordIndex: Integer;
begin
if DataController <> nil then
Result := DataController.GetFocusedRecordIndex
else
Result := -1;
end;
function TcxCustomLookupEditLookupData.GetListIndex: Integer;
begin
Result := Properties.GetListIndex;
end;
function TcxCustomLookupEditLookupData.GetProperties: TcxCustomLookupEditProperties;
begin
Result := Edit.ActiveProperties;
end;
{ TcxCustomLookupEditProperties }
constructor TcxCustomLookupEditProperties.Create(AOwner: TPersistent);
begin
inherited Create(AOwner);
FIncrementalFiltering := True;
DropDownHeight := 0;
DropDownWidth := 0;
DropDownListStyle := lsEditFixedList;
DropDownAutoSize := False;
DropDownSizeable := False;
end;
procedure TcxCustomLookupEditProperties.Assign(Source: TPersistent);
begin
if Source is TcxCustomLookupEditProperties then
begin
BeginUpdate;
try
inherited Assign(Source);
if not IsDefinedByLookup then
DisplayColumnIndex := TcxCustomLookupEditProperties(Source).DisplayColumnIndex;
ImmediateUpdateText := TcxCustomLookupEditProperties(Source).ImmediateUpdateText;
IncrementalFiltering := TcxCustomLookupEditProperties(Source).IncrementalFiltering;
finally
EndUpdate;
end;
end
else
inherited Assign(Source);
end;
class function TcxCustomLookupEditProperties.GetContainerClass: TcxContainerClass;
begin
Result := TcxCustomLookupEdit;
end;
function TcxCustomLookupEditProperties.GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource;
begin
if IsPickMode then
Result := evsText
else
Result := evsValue;
end;
function TcxCustomLookupEditProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
Result := inherited GetSupportedOperations;
if GetEditValueSource(False) = evsValue then
Include(Result, esoSortingByDisplayText);
end;
function TcxCustomLookupEditProperties.IsDefinedByLookup: Boolean;
begin
Result := IsLookupField;
end;
function TcxCustomLookupEditProperties.IsEditValueValid(var EditValue: TcxEditValue;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?