cxcolorcombobox.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,962 行 · 第 1/5 页
PAS
1,962 行
Self.ColorDialogType := ColorDialogType;
Self.DefaultColor := DefaultColor;
Self.DefaultDescription := DefaultDescription;
Self.DefaultColorStyle := DefaultColorStyle;
Self.ShowDescriptions := ShowDescriptions;
Self.AllowSelectColor := AllowSelectColor;
Self.ColorComboStyle := ColorComboStyle;
Self.MaxMRUColors := MaxMRUColors;
Self.NamingConvention := NamingConvention;
Self.PrepareList := PrepareList;
Self.ColorValueFormat := ColorValueFormat;
Self.OnSelectCustomColor := OnSelectCustomColor;
Self.OnNamingConvention := OnNamingConvention;
Self.OnGetDefaultColor := OnGetDefaultColor;
Self.OnAddedMRUColor := OnAddedMRUColor;
Self.OnDeletedMRUColor := OnDeletedMRUColor;
Self.Items.Assign(Items);
Self.MRUColors.Assign(MRUColors);
end;
finally
EndUpdate;
end
end
else
inherited Assign(Source);
end;
procedure TcxCustomColorComboBoxProperties.Changed;
begin
if FInternalUpdate then Exit;
inherited;
end;
function TcxCustomColorComboBoxProperties.CompareDisplayValues(
const AEditValue1, AEditValue2: TcxEditValue): Boolean;
var
AColor1, AColor2: TColor;
AColorFound1, AColorFound2: Boolean;
ADescription1, ADescription2: string;
begin
GetColorComboBoxDisplayValue(AEditValue1, AColor1, ADescription1, AColorFound1);
GetColorComboBoxDisplayValue(AEditValue2, AColor2, ADescription2, AColorFound2);
Result := ShowColorBox(AColorFound1) = ShowColorBox(AColorFound2);
if Result then
if ShowColorBox(AColorFound1) then
Result := (AColor1 = AColor2) and (not ShowDescriptions or InternalCompareString(ADescription1, ADescription2, True))
else
Result := not ShowDescriptions or InternalCompareString(ADescription1, ADescription2, True);
// Result := (AColorFound1 = AColorFound2) and (not AColorFound1 or
// (AColor1 = AColor2) and (not ShowDescriptions or InternalCompareString(ADescription1, ADescription2, True)));
end;
class function TcxCustomColorComboBoxProperties.GetContainerClass: TcxContainerClass;
begin
Result := TcxColorComboBox;
end;
class function TcxCustomColorComboBoxProperties.GetViewInfoClass: TcxContainerViewInfoClass;
begin
Result := TcxCustomColorComboBoxViewInfo;
end;
function TcxCustomColorComboBoxProperties.GetEditValueSource(AEditFocused: Boolean):
TcxDataEditValueSource;
begin
Result := evsValue;
end;
function TcxCustomColorComboBoxProperties.IsDisplayValueValid(
var DisplayValue: TcxEditValue; AEditFocused: Boolean): Boolean;
begin
Result := True;
end;
procedure TcxCustomColorComboBoxProperties.PrepareDisplayValue(
const AEditValue: TcxEditValue; var DisplayValue: TcxEditValue; AEditFocused: Boolean);
var
FValue: TColor;
FValueText: string;
begin
TranslateValues(AEditValue, FValue, FValueText);
DisplayValue := FValueText;
end;
function TcxCustomColorComboBoxProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
Result := [esoEditing, esoFiltering, esoHorzAlignment, esoSorting,
esoSortingByDisplayText];
if Buttons.Count > 0 then
Include(Result, esoHotTrack);
if ShowDescriptions then
Include(Result, esoIncSearch);
end;
function TcxCustomColorComboBoxProperties.GetDisplayText(const AEditValue: TcxEditValue;
AFullText: Boolean = False; AIsInplace: Boolean = True): WideString;
var
AColor: TColor;
ADescription: string;
begin
TranslateValues(AEditValue, AColor, ADescription, True);
Result := ADescription;
end;
procedure TcxCustomColorComboBoxProperties.Update(AProperties: TcxCustomEditProperties);
begin
if AProperties is TcxCustomColorComboBoxProperties then
with TcxCustomColorComboBoxProperties(AProperties) do
begin
Items.Assign(Self.Items);
MRUColors.Assign(Self.MRUColors);
end;
end;
procedure TcxCustomColorComboBoxProperties.GetColorComboBoxDisplayValue(
const AEditValue: TcxEditValue; out AColor: TColor;
out ADescription: string; out AColorFound: Boolean);
begin
InternalGetColorComboBoxDisplayValue(IndexByValue(AEditValue), AEditValue,
AColor, ADescription, AColorFound);
end;
procedure TcxCustomColorComboBoxProperties.PrepareColorList(
APrepareList: TcxColorPrepareList; ASaveCustom, ASaveMRU: Boolean);
begin
LockUpdate(True);
try
if not ASaveCustom then
Items.Clear
else
Items.ClearNonCustom;
if not ASaveMRU then
ClearMRUColors;
InternalPrepareColorList(APrepareList);
if ASaveMRU then
ValidateMRUColors;
SynchronizeCustomColors;
if Assigned(FOnLoadColorList) then
FOnLoadColorList(Self);
finally
LockUpdate(False);
end;
end;
procedure TcxCustomColorComboBoxProperties.PrepareDelphiColorList(
const ASaveCustom, ASaveMRU: Boolean);
begin
PrepareColorList(cxplDelphi, ASaveCustom, ASaveMRU);
end;
procedure TcxCustomColorComboBoxProperties.PrepareHTML4ColorList(
const ASaveCustom, ASaveMRU: Boolean);
begin
PrepareColorList(cxplHTML4, ASaveCustom, ASaveMRU);
end;
procedure TcxCustomColorComboBoxProperties.PrepareX11ColorList(
const ASaveCustom, ASaveMRU: Boolean);
begin
PrepareColorList(cxplX11, ASaveCustom, ASaveMRU);
end;
procedure TcxCustomColorComboBoxProperties.PrepareX11OrderedColorList(
const ASaveCustom, ASaveMRU: Boolean);
begin
PrepareColorList(cxplX11Ordered, ASaveCustom, ASaveMRU);
end;
procedure TcxCustomColorComboBoxProperties.DefineProperties(Filer: TFiler);
begin
Filer.DefineProperty('Items', ReadCustomColors, nil, False);
Filer.DefineProperty('PrepareInfo', ReadPrepareInfo, nil, False);
end;
function TcxCustomColorComboBoxProperties.ShowColorBox(AColorFound: Boolean): Boolean;
begin
Result := not (not AColorFound and (DefaultColorStyle = cxdcText));
end;
class function TcxCustomColorComboBoxProperties.GetLookupDataClass: TcxInterfacedPersistentClass;
begin
Result := TcxColorComboBoxLookupData;
end;
class function TcxCustomColorComboBoxProperties.GetPopupWindowClass: TcxCustomEditPopupWindowClass;
begin
Result := TcxColorComboBoxPopupWindow;
end;
class function TcxCustomColorComboBoxProperties.GetViewDataClass: TcxCustomEditViewDataClass;
begin
Result := TcxCustomColorComboBoxViewData;
end;
function TcxCustomColorComboBoxProperties.HasDisplayValue: Boolean;
begin
Result := False;
end;
function TcxCustomColorComboBoxProperties.IsEditValueNumeric: Boolean;
begin
Result := True;
end;
function TcxCustomColorComboBoxProperties.GetColorByIndex(AIndex: Integer): TColor;
begin
if AIndex <= (MRUColors.Count - 1) then
Result := MRUColors.GetColorByIndex(AIndex, DefaultColor)
else
Result := Items.GetColorByIndex(AIndex - MRUColors.Count, DefaultColor);
end;
function TcxCustomColorComboBoxProperties.GetIndexByColor(AColor: TColor): Integer;
begin
Result := MRUColors.GetIndexByColor(AColor);
if Result = -1 then
begin
Result := Items.GetIndexByColor(AColor);
if Result <> -1 then
Result := Result + MRUColors.Count;
end;
end;
function TcxCustomColorComboBoxProperties.GetDescriptionByIndex(AIndex: Integer): string;
begin
if not ShowDescriptions then
Result := ''
else
begin
if AIndex = -1 then
Result := DefaultDescription
else
Result := DoConvertNaming(AIndex);
end;
end;
function TcxCustomColorComboBoxProperties.IndexByValue(const AValue: TcxEditValue): Integer;
var
AColor: TColor;
AIsValueValid: Boolean;
I: Integer;
begin
Result := -1;
if IsVarEmpty(AValue) then
Exit;
AIsValueValid := cxStrToColor(VarToStr(AValue), AColor);
if not AIsValueValid then
Exit;
for I := 0 to MRUColors.Count - 1 do
if AColor = MRUColors[I].Color then
begin
Result := I;
Break;
end;
if Result = -1 then
for I := 0 to Items.Count - 1 do
if AColor = Items[I].Color then
begin
Result := I + MRUColors.Count;
Break;
end;
end;
function TcxCustomColorComboBoxProperties.IsDisplayValueNumeric: Boolean;
begin
Result := False;
end;
function TcxCustomColorComboBoxProperties.AddMRUColor(const AColor: TColor): TcxMRUColorAction;
var
FIndex: Integer;
begin
Result := mcaNone;
if MaxMRUColors = 0 then Exit;
FIndex := FMRUColors.GetIndexByColor(AColor);
if FIndex <> -1 then
begin
if (FIndex > 0) and (FIndex < FMRUColors.Count) then
begin
Result := mcaMoved;
FMRUColors.Move(FIndex, 0);
if Assigned(FOnAddedMRUColor) then FOnAddedMRUColor(Self);
end
else
Result := mcaNone;
end
else
Result := mcaAdded;
if Result = mcaAdded then
begin
FIndex := Items.GetIndexByColor(AColor);
if FIndex > -1 then
begin
FInternalUpdate := True;
try
FMRUColors.InsertColor(0, AColor, Items[FIndex].Description);
DeleteOverMRUColors;
finally
FInternalUpdate := False;
end;
if Assigned(FOnAddedMRUColor) then FOnAddedMRUColor(Self);
end
else
Result := mcaNone;
end;
end;
function TcxCustomColorComboBoxProperties.DelMRUColor(const AColor: TColor): TcxMRUColorAction;
var
FIndex: Integer;
begin
Result := mcaNone;
{Check for right Color}
FIndex := Items.GetIndexByColor(AColor);
if FIndex < 0 then Exit;
if FMRUColors.FindColorItem(AColor) <> nil then
begin
{$IFDEF DELPHI5}
FMRUColors.Delete(FIndex);
{$ELSE}
TcxColorComboBoxItem(FMRUColors.Items[FIndex]).Free;
{$ENDIF}
Result := mcaDeleted;
if Assigned(FOnDeletedMRUColor) then FOnDeletedMRUColor(Self);
end;
end;
procedure TcxCustomColorComboBoxProperties.ClearMRUColors;
begin
FMRUColors.Clear;
Changed;
end;
procedure TcxCustomColorComboBoxProperties.DoGetDefaultColor(var AColor: TColor);
begin
if Assigned(FOnGetDefaultColor) then FOnGetDefaultColor(Self, AColor);
end;
procedure TcxCustomColorComboBoxProperties.TranslateValues(const AEditValue: TcxEditValue;
var AColor: TColor; var ADescription: string; ANeedDescription: Boolean = False);
var
FFoundIndex: Integer;
FValid: Boolean;
S: string;
begin
FFoundIndex := IndexByValue(AEditValue);
if ((FFoundIndex <> -1) and (not ANeedDescription or ShowDescriptions) or
((FFoundIndex = -1) and (ColorComboStyle = cxccsComboList))) and
not IsVarEmpty(AEditValue) then
ADescription := GetDescriptionByIndex(FFoundIndex)
else
begin
FValid := cxStrToColor(VarToStr(AEditValue), AColor);
if FValid then
begin
S := ConvertColorName(AColor, '', NamingConvention, ColorValueFormat);
if Assigned(OnNamingConvention) then
OnNamingConvention(Self, AColor, S);
ADescription := S;
end
else
begin
AColor := DefaultColor;
ADescription := DefaultDescription;
end;
end;
end;
function TcxCustomColorComboBoxProperties.ColorItemByIndex(AIndex: Integer): TcxColorComboBoxItem;
begin
if AIndex = -1 then
Result := nil
else
begin
if AIndex <= (MRUColors.Count - 1) then
Result := MRUColors.Items[AIndex]
else
Result := Items[AIndex - MRUColors.Count];
end;
end;
procedure TcxCustomColorComboBoxProperties.DeleteOverMRUColors;
var
I: Integer;
begin
BeginUpdate;
try
for I := FMRUColors.Count - 1 downto 0 do
begin
if I >= FMaxMRUColors then
begin
FMRUColors.Delete(I);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?