cxcolorcombobox.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,962 行 · 第 1/5 页

PAS
1,962
字号
        if Assigned(FOnDeletedMRUColor) then FOnDeletedMRUColor(Self);
      end
      else
        Break;
    end;
  finally
    EndUpdate;
  end;
end;

function TcxCustomColorComboBoxProperties.DoConvertNaming(AIndex: Integer): string;
var
  FItem: TcxColorComboBoxItem;
begin
  FItem := ColorItemByIndex(AIndex);
  if FItem = nil then
    Result := ''
  else
    Result := ConvertColorName(FItem.Color, FItem.Description,
      NamingConvention, ColorValueFormat);
  if Assigned(OnNamingConvention) then
  begin
    if FItem = nil then
      OnNamingConvention(Self, DefaultColor, Result)
    else
      OnNamingConvention(Self, FItem.Color, Result);
  end;
end;

function TcxCustomColorComboBoxProperties.GetItems: TcxColorComboBoxItems;
begin
  Result := FItems;
end;

procedure TcxCustomColorComboBoxProperties.InternalGetColorComboBoxDisplayValue(
  AItemIndex: Integer; const AEditValue: TcxEditValue; out AColor: TColor;
  out ADescription: string; out AColorFound: Boolean);
begin
  AColorFound := AItemIndex <> -1;
  ADescription := GetDescriptionByIndex(AItemIndex);
  if not AColorFound and (ColorComboStyle = cxccsComboList) and
    not IsVarEmpty(AEditValue) then
      AColor := DefaultColor
  else
  begin
    if AItemIndex <> -1 then
      AColor := GetColorByIndex(AItemIndex)
    else
      TranslateValues(AEditValue, AColor, ADescription);
  end;
end;

procedure TcxCustomColorComboBoxProperties.InternalPrepareColorList(APrepareList: TcxColorPrepareList);
begin
  case APrepareList of
    cxplDelphi: InternalPrepareColorList(cxDelphiColorValues, cxDelphiColorNames);
    cxplHTML4: InternalPrepareColorList(cxHTML4ColorValues, cxHTML4ColorNames);
    cxplX11: InternalPrepareColorList(cxX11ColorValues, cxX11ColorNames);
    cxplX11Ordered: InternalPrepareColorList(cxX11OrderedColorValues, cxX11OrderedColorNames);
  end;
end;

procedure TcxCustomColorComboBoxProperties.InternalPrepareColorList(
  AColorValues: array of TColor; AColorNames: array of string);
var
  I: Integer;
  AItem: TcxColorComboBoxItem;
begin
  Items.BeginUpdate;
  try
    for I:= Low(AColorValues) to High(AColorValues) do
    begin
      AItem := Items.AddColor(AColorValues[I], AColorNames[I]);
      if AItem <> nil then
        AItem.FIsCustomColor := False;
    end;
  finally
    Items.EndUpdate;
  end;
end;

function TcxCustomColorComboBoxProperties.IsDefaultDescriptionStored: Boolean;
begin
  Result := DefaultDescription <>
    cxGetResourceString(@cxSColorComboBoxDefaultDescription);
end;

procedure TcxCustomColorComboBoxProperties.ReadCustomColors(Reader: TReader);
begin
  Reader.ReadValue;
  Reader.ReadCollection(FCustomColors);
end;

procedure TcxCustomColorComboBoxProperties.ReadPrepareInfo(Reader: TReader);
begin
  Reader.ReadString;
end;

procedure TcxCustomColorComboBoxProperties.SetAllowSelectColor(Value: Boolean);
begin
  if FAllowSelectColor <> Value then
  try
    FAllowSelectColor := Value;
    BeginUpdate;
    Buttons[1].Visible := Value;
    if Value then
      GlyphButtonIndex := 1
    else
      GlyphButtonIndex := 0;
  finally
    EndUpdate;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetColorBoxAlign(Value : TcxColorBoxAlign);
begin
  if FColorBoxAlign <> Value then
  begin
    FColorBoxAlign := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetColorBoxFrameColor(Value: TColor);
begin
  if FColorBoxFrameColor <> Value then
  begin
    FColorBoxFrameColor := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetColorBoxWidth(Value: Integer);
begin
  if FColorBoxWidth <> Value then
  begin
    if Value < 0 then Value := 0;
    FColorBoxWidth := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetColorComboStyle(Value: TcxColorComboStyle);
begin
  if FColorComboStyle <> Value then
  begin
    FColorComboStyle := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetColorValueFormat(Value: TcxColorValueFormat);
begin
  if FColorValueFormat <> Value then
  begin
    FColorValueFormat := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetDefaultColor(Value: TColor);
begin
  if FDefaultColor <> Value then
  begin
    FDefaultColor := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetDefaultDescription(Value: string);
begin
  if FDefaultDescription <> Value then
  begin
    FDefaultDescription := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetDefaultColorStyle(Value: TcxDefaultColorStyle);
begin
  if FDefaultColorStyle <> Value then
  begin
    FDefaultColorStyle := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetCustomColors(Value: TcxColorComboBoxItems);
begin
  FCustomColors.Assign(Value);
end;

procedure TcxCustomColorComboBoxProperties.SetItems(const Value: TcxColorComboBoxItems);
begin
  FItems.Assign(Value);
end;

procedure TcxCustomColorComboBoxProperties.SetMaxMRUColors(Value: Byte);
var
  FOldMaxMRUColors: Byte;
begin
  if FMaxMRUColors <> Value then
  begin
    FOldMaxMRUColors := FMaxMRUColors;
    FMaxMRUColors := Value;
    if FOldMaxMRUColors > Value then
      DeleteOverMRUColors;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetNamingConvention(Value: TcxColorNamingConvention);
begin
  if FNamingConvention <> Value then
  begin
    FNamingConvention := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetPrepareList(Value: TcxColorPrepareList);
begin
  if FPrepareList <> Value then
  begin
    FPrepareList := Value;
    PrepareColorList(FPrepareList, True, True);
  end;
end;

procedure TcxCustomColorComboBoxProperties.SetShowDescriptions(const Value: Boolean);
begin
  if FShowDescriptions <> Value then
  begin
    FShowDescriptions := Value;
    Changed;
  end;
end;

procedure TcxCustomColorComboBoxProperties.SynchronizeCustomColors;
var
  I: Integer;
begin
  Items.BeginUpdate;
  try
    Items.ClearCustom;
    for I := CustomColors.Count - 1 downto 0 do
      Items.InsertColor(0, CustomColors[I].Color, CustomColors[I].Description);
  finally
    Items.EndUpdate;
  end;
end;

procedure TcxCustomColorComboBoxProperties.CustomColorChanged(ASender: TObject);
begin
  SynchronizeCustomColors;
end;

procedure TcxCustomColorComboBoxProperties.ValidateMRUColors;
var
  I: Integer;
begin
  for I := (MRUColors.Count - 1) downto 0 do
    if Items.GetIndexByColor(MRUColors[I].Color) = -1 then
      MRUColors.Delete(I);
end;

{ TcxCustomColorComboBox }

destructor TcxCustomColorComboBox.Destroy;
begin
  FreeAndNil(FColorDialog);
  inherited Destroy;
end;

function TcxCustomColorComboBox.Deactivate: Boolean;
begin
  Result := inherited Deactivate;
  UpdateMRUList;
end;

function TcxCustomColorComboBox.Focused: Boolean;
begin
  Result := FIsDialogShowed or inherited Focused;
end;

class function TcxCustomColorComboBox.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  Result := TcxCustomColorComboBoxProperties;
end;

function TcxCustomColorComboBox.IsChildWindow(AWnd: THandle): Boolean;
begin
  Result := inherited IsChildWindow(AWnd) or
    (FIsDialogShowed and ((ColorDialog.Handle = HWND(AWnd)) or (IsChild(ColorDialog.Handle, AWnd))));
end;

procedure TcxCustomColorComboBox.PrepareEditValue(const ADisplayValue: TcxEditValue;
  out EditValue: TcxEditValue; AEditFocused: Boolean);
begin
  EditValue := LookupKeyToEditValue(ILookupData.CurrentKey);
end;

procedure TcxCustomColorComboBox.AfterPosting;
begin
  inherited AfterPosting;
  if IsInplace and FNeedsUpdateMRUList then
    FDontCheckModifiedWhenUpdatingMRUList := True;
end;

procedure TcxCustomColorComboBox.ContainerStyleChanged(Sender: TObject);
begin
  inherited ContainerStyleChanged(Sender);
end;

procedure TcxCustomColorComboBox.PropertiesChanged(Sender: TObject);
begin
  if FPropertiesUpdate then Exit;
  FPropertiesUpdate := True;
  try
    with ActiveProperties do
      if AllowSelectColor then
        if ButtonGlyph.Empty then
          Buttons[1].Kind := bkEllipsis
        else
          Buttons[1].Kind := bkGlyph
      else
        if ButtonGlyph.Empty then
          Buttons[0].Kind := bkDown
        else
          Buttons[0].Kind := bkGlyph;
    inherited PropertiesChanged(Sender);
  finally
    FPropertiesUpdate := False;
  end;
end;

function TcxCustomColorComboBox.GetColorDialog: TColorDialog;
begin
  if FColorDialog = nil then
    FColorDialog := TColorDialog.Create(Self);
  Result := FColorDialog;
end;

function TcxCustomColorComboBox.GetColorValue: TColor;
begin
  Result := TcxCustomColorComboBoxViewInfo(ViewInfo).ColorBoxColor;
end;

function TcxCustomColorComboBox.IsColorValueStored: Boolean;
begin
  Result := ColorValue <> ActiveProperties.DefaultColor;
end;

procedure TcxCustomColorComboBox.SetColorValue(Value: TColor);
begin
  if ColorValue <> Value then
  begin
    LockClick(True);
    try
      InternalEditValue := Value;
    finally
      LockClick(False);
    end;
  end;
end;

procedure TcxCustomColorComboBox.DblClick;
begin
  inherited DblClick;
end;

procedure TcxCustomColorComboBox.DoButtonClick(AButtonVisibleIndex: Integer);
begin
  if AButtonVisibleIndex = 1 then
    DoSelectCustomColor(Self);
end;

procedure TcxCustomColorComboBox.DoSelectCustomColor(Sender: TObject);
var
  AColorProvided: TColor;
  AColorDescription: string;
  AAddToList: Boolean;
  AIndex: Integer;
begin
  AColorProvided := clNone;
  AColorDescription := '';
  AAddToList := True;

  if ActiveProperties.ColorDialogType = cxcdtDefault then
  begin
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?