cximagecombobox.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,337 行 · 第 1/3 页
PAS
1,337 行
{ TcxCustomImageComboBoxProperties }
constructor TcxCustomImageComboBoxProperties.Create(AOwner: TPersistent);
begin
inherited Create(AOwner);
FShowDescriptions := True;
FDefaultImageIndex := -1;
FImageAlign := iaLeft;
FItems := TcxImageComboBoxItems.Create(Self);
DropDownListStyle := lsFixedList;
FImagesChangeLink := TChangeLink.Create;
FImagesChangeLink.OnChange := ImagesChange;
FLargeImagesChangeLink := TChangeLink.Create;
FLargeImagesChangeLink.OnChange := LargeImagesChange;
end;
destructor TcxCustomImageComboBoxProperties.Destroy;
begin
FImagesChangeLink.Free;
FLargeImagesChangeLink.Free;
FItems.Free;
inherited Destroy;
end;
procedure TcxCustomImageComboBoxProperties.ImagesChange(Sender: TObject);
begin
Changed;
end;
procedure TcxCustomImageComboBoxProperties.LargeImagesChange(Sender: TObject);
begin
Changed;
end;
procedure TcxCustomImageComboBoxProperties.SetDefaultDescription(
const Value: string);
begin
if FDefaultDescription <> Value then
begin
FDefaultDescription := Value;
Changed;
end;
end;
procedure TcxCustomImageComboBoxProperties.SetDefaultImageIndex(
const Value: TImageIndex);
begin
if FDefaultImageIndex <> Value then
begin
FDefaultImageIndex := Value;
Changed;
end;
end;
procedure TcxCustomImageComboBoxProperties.SetImageAlign(
const Value: TcxImageAlign);
begin
if FImageAlign <> Value then
begin
FImageAlign := Value;
Changed;
end;
end;
procedure TcxCustomImageComboBoxProperties.SetImages(Value: TCustomImageList);
begin
cxSetImageList(Value, FImages, FImagesChangeLink, FreeNotificator);
end;
procedure TcxCustomImageComboBoxProperties.SetLargeImages(Value: TCustomImageList);
begin
cxSetImageList(Value, FLargeImages, FLargeImagesChangeLink, FreeNotificator);
end;
procedure TcxCustomImageComboBoxProperties.SetItems(
const Value: TcxImageComboBoxItems);
begin
FItems.Assign(Value);
Changed;
end;
procedure TcxCustomImageComboBoxProperties.SetMultiLineText(
const Value: Boolean);
begin
if FMultiLineText <> Value then
begin
FMultiLineText := Value;
Changed;
end;
end;
procedure TcxCustomImageComboBoxProperties.SetShowDescriptions(
const Value: Boolean);
begin
if FShowDescriptions <> Value then
begin
FShowDescriptions := Value;
Changed;
end;
end;
function TcxCustomImageComboBoxProperties.FindItemByText(const AText: string):
TcxImageComboBoxItem;
var
I: Integer;
begin
Result := nil;
if ShowDescriptions then
for I := 0 to Items.Count - 1 do
if InternalCompareString(Items[I].Description, AText, False) then
begin
Result := Items[I];
Break;
end;
end;
function TcxCustomImageComboBoxProperties.FindLookupText(const AText: string): Boolean;
begin
Result := FindItemByText(AText) <> nil;
end;
procedure TcxCustomImageComboBoxProperties.FreeNotification(Sender: TComponent);
begin
inherited FreeNotification(Sender);
if Sender = FImages then
FImages := nil;
if Sender = FLargeImages then
FLargeImages := nil;
end;
function TcxCustomImageComboBoxProperties.GetDisplayFormatOptions: TcxEditDisplayFormatOptions;
begin
Result := [];
end;
class function TcxCustomImageComboBoxProperties.GetLookupDataClass: TcxInterfacedPersistentClass;
begin
Result := TcxImageComboBoxLookupData;
end;
class function TcxCustomImageComboBoxProperties.GetViewDataClass: TcxCustomEditViewDataClass;
begin
Result := TcxImageComboBoxViewData;
end;
function TcxCustomImageComboBoxProperties.HasDisplayValue: Boolean;
begin
Result := False;
end;
procedure TcxCustomImageComboBoxProperties.InternalGetImageComboBoxDisplayValue(
AItem: TcxImageComboBoxItem; out AText: TCaption; out AImageIndex: TImageIndex;
AAlwaysShowDescription: Boolean = False);
begin
if AAlwaysShowDescription or ShowDescriptions then
if AItem = nil then
AText := DefaultDescription
else
AText := AItem.Description
else
AText := '';
if AItem = nil then
AImageIndex := DefaultImageIndex
else
AImageIndex := AItem.ImageIndex;
end;
procedure TcxCustomImageComboBoxProperties.Assign(Source: TPersistent);
begin
if Source is TcxCustomImageComboBoxProperties then
begin
BeginUpdate;
try
inherited Assign(Source);
with TcxCustomImageComboBoxProperties(Source) do
begin
Self.DefaultDescription := DefaultDescription;
Self.DefaultImageIndex := DefaultImageIndex;
Self.ImageAlign := ImageAlign;
Self.Images := Images;
Self.Items.Assign(Items);
Self.LargeImages := LargeImages;
Self.MultiLineText := MultiLineText;
Self.ShowDescriptions := ShowDescriptions;
end;
finally
EndUpdate
end
end
else
inherited Assign(Source);
end;
function TcxCustomImageComboBoxProperties.CompareDisplayValues(
const AEditValue1, AEditValue2: TcxEditValue): Boolean;
var
AImageIndex1, AImageIndex2: TImageIndex;
AText1, AText2: TCaption;
begin
GetImageComboBoxDisplayValue(AEditValue1, AText1, AImageIndex1);
GetImageComboBoxDisplayValue(AEditValue2, AText2, AImageIndex2);
Result := InternalCompareString(AText1, AText2, True) and ((Images = nil) or
(AImageIndex1 = AImageIndex2));
end;
function TcxCustomImageComboBoxProperties.FindItemByValue(
const AValue: Variant): TcxImageComboBoxItem;
var
I: Integer;
begin
Result := nil;
for I := 0 to Items.Count - 1 do
with Items[I] do
if VarEqualsExact(AValue, Value) then
begin
Result := Items[I];
Break;
end;
end;
class function TcxCustomImageComboBoxProperties.GetContainerClass: TcxContainerClass;
begin
Result := TcxImageComboBox;
end;
function TcxCustomImageComboBoxProperties.GetDisplayText(
const AEditValue: TcxEditValue; AFullText: Boolean = False;
AIsInplace: Boolean = True): WideString;
var
ADisplayValue: TcxEditValue;
begin
PrepareDisplayValue(AEditValue, ADisplayValue, False);
Result := ADisplayValue;
end;
function TcxCustomImageComboBoxProperties.GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource;
begin
Result := evsValue;
end;
procedure TcxCustomImageComboBoxProperties.GetImageComboBoxDisplayValue(
const AEditValue: TcxEditValue; out AText: TCaption;
out AImageIndex: TImageIndex);
begin
InternalGetImageComboBoxDisplayValue(FindItemByValue(AEditValue), AText,
AImageIndex);
end;
function TcxCustomImageComboBoxProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
Result := [esoEditing, esoFiltering, esoHorzAlignment, esoSorting,
esoSortingByDisplayText];
if Buttons.Count > 0 then
Include(Result, esoHotTrack);
if ShowDescriptions then
Include(Result, esoIncSearch);
end;
class function TcxCustomImageComboBoxProperties.GetViewInfoClass: TcxContainerViewInfoClass;
begin
Result := TcxImageComboBoxViewInfo;
end;
function TcxCustomImageComboBoxProperties.IsEditValueValid(
var AEditValue: TcxEditValue; AEditFocused: Boolean): Boolean;
begin
Result := True;
end;
procedure TcxCustomImageComboBoxProperties.PrepareDisplayValue(
const AEditValue: TcxEditValue; var DisplayValue: TcxEditValue;
AEditFocused: Boolean);
var
AImageIndex: TImageIndex;
AText: TCaption;
begin
InternalGetImageComboBoxDisplayValue(FindItemByValue(AEditValue), AText,
AImageIndex, True);
DisplayValue := AText;
end;
{ TcxCustomImageComboBox }
function TcxCustomImageComboBox.GetProperties: TcxCustomImageComboBoxProperties;
begin
Result := TcxCustomImageComboBoxProperties(FProperties);
end;
function TcxCustomImageComboBox.GetActiveProperties: TcxCustomImageComboBoxProperties;
begin
Result := TcxCustomImageComboBoxProperties(InternalGetActiveProperties);
end;
function TcxCustomImageComboBox.GetLookupData: TcxImageComboBoxLookupData;
begin
Result := TcxImageComboBoxLookupData(inherited LookupData);
end;
procedure TcxCustomImageComboBox.SetProperties(const Value: TcxCustomImageComboBoxProperties);
begin
FProperties.Assign(Value);
end;
function TcxCustomImageComboBox.IsValidChar(AChar: Char): Boolean;
begin
Result := IsTextChar(AChar);
end;
function TcxCustomImageComboBox.GetItemObject: TObject;
begin
Result := nil;
end;
function TcxCustomImageComboBox.GetPopupWindowClientPreferredSize: TSize;
begin
Result := inherited GetPopupWindowClientPreferredSize;
if not ActiveProperties.MultiLineText then
begin
if (LookupData.ActiveControl <> nil) and (LookupData.ActiveControl is TcxImageComboBoxListBox) then
with TcxImageComboBoxListBox(LookupData.ActiveControl) do
Result.cx := Max(GetMaxItemWidth, Result.cx);
end
else
begin
Result.cx := 0;
if LookupData <> nil then
LookupData.List.RecreateWindow;
end;
end;
function TcxCustomImageComboBox.InternalGetEditingValue: TcxEditValue;
begin
PrepareEditValue(Null, Result, True);
end;
function TcxCustomImageComboBox.LookupKeyToEditValue(const AKey: TcxEditValue): TcxEditValue;
begin
if not VarEqualsExact(AKey, -1) then
Result := ActiveProperties.Items[AKey].Value
else
Result := Null;
end;
procedure TcxCustomImageComboBox.SynchronizeDisplayValue;
var
APrevLookupKey: TcxEditValue;
begin
SaveModified;
try
APrevLookupKey := ILookupData.CurrentKey;
LockClick(True);
try
ILookupData.TextChanged;
finally
LockClick(False);
if (*ModifiedAfterEnter and *)not VarEqualsExact(APrevLookupKey, ILookupData.CurrentKey) then
DoClick;
end;
finally
RestoreModified;
ResetOnNewDisplayValue;
UpdateDrawValue;
end;
end;
procedure TcxCustomImageComboBox.UpdateDrawValue;
begin
inherited UpdateDrawValue;
SetInternalDisplayValue(ViewInfo.Text);
end;
class function TcxCustomImageComboBox.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
Result := TcxCustomImageComboBoxProperties;
end;
procedure TcxCustomImageComboBox.PrepareEditValue(
const ADisplayValue: TcxEditValue; out EditValue: TcxEditValue;
AEditFocused: Boolean);
begin
if VarEqualsExact(LookupData.CurrentKey, -1) then
EditValue := Null
else
EditValue := ActiveProperties.Items[LookupData.CurrentKey].Value;
end;
{ TcxImageComboBox }
class function TcxImageComboBox.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
Result := TcxImageComboBoxProperties;
end;
function TcxImageComboBox.GetActiveProperties: TcxImageComboBoxProperties;
begin
Result := TcxImageComboBoxProperties(InternalGetActiveProperties);
end;
function TcxImageComboBox.GetProperties: TcxImageComboBoxProperties;
begin
Result := TcxImageComboBoxProperties(FProperties);
end;
procedure TcxImageComboBox.SetProperties(Value: TcxImageComboBoxProperties);
begin
FProperties.Assign(Value);
end;
{ TcxFilterImageComboBoxHelper }
class function TcxFilterImageComboBoxHelper.GetFilterEditClass: TcxCustomEditClass;
begin
Result := TcxImageComboBox;
end;
class function TcxFilterImageComboBoxHelper.GetSupportedFilterOperators(
AProperties: TcxCustomEditProperties;
AValueTypeClass: TcxValueTypeClass;
AExtendedSet: Boolean = False): TcxFilterControlOperators;
begin
Result := [fcoEqual, fcoNotEqual, fcoBlanks, fcoNonBlanks];
if AExtendedSet then
Result := Result + [fcoInList, fcoNotInList];
end;
class procedure TcxFilterImageComboBoxHelper.InitializeProperties(AProperties,
AEditProperties: TcxCustomEditProperties; AHasButtons: Boolean);
begin
inherited InitializeProperties(AProperties, AEditProperties, AHasButtons);
TcxImageComboBoxProperties(AProperties).DropDownListStyle := lsFixedList;
TcxImageComboBoxProperties(AProperties).ImmediateDropDown := True;
TcxImageComboBoxProperties(AProperties).ShowDescriptions := True;
end;
initialization
GetRegisteredEditProperties.Register(TcxImageComboBoxProperties, scxSEditRepositoryImageComboBoxItem);
FilterEditsController.Register(TcxImageComboBoxProperties, TcxFilterImageComboBoxHelper);
finalization
FilterEditsController.Unregister(TcxImageComboBoxProperties, TcxFilterImageComboBoxHelper);
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?