cxcheckcombobox.pas

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

PAS
1,557
字号
end;

procedure TcxCustomCheckComboBoxProperties.SetShowEmptyText(Value: Boolean);
begin
  if FShowEmptyText <> Value then
  begin
    FShowEmptyText := Value;
    Changed;
  end;
end;

procedure TcxCustomCheckComboBoxProperties.SetItems(const Value: TcxCheckComboBoxItems);
begin
  FItems.Assign(Value);
  Changed;
end;

procedure TcxCustomCheckComboBoxProperties.CalculateCheckStatesByEditValue(
  Sender: TObject; const AEditValue: TcxEditValue; var ACheckStates: TcxCheckStates);
begin
  if Assigned(OnEditValueToStates) then
  begin
    SetLength(ACheckStates, Items.Count);
    OnEditValueToStates(Sender, AEditValue, ACheckStates)
  end
  else
    cxCheckBox.CalculateCheckStates(AEditValue, Items, EditValueFormat,
      ACheckStates);
end;

function TcxCustomCheckComboBoxProperties.CalculateDisplayValueByCheckStates(
  const ACheckStates: TcxCheckStates): string;
var
  I: Integer;
begin
  Result := '';
  for I := 0 to Items.Count - 1 do
  begin
    if ACheckStates[I] <> cbsChecked then
      Continue;
    if Result <> '' then
        Result := Result + FDelimiter;
    Result := Result + Items[I].GetDisplayDescription;
  end;
  if (Result = '') and ShowEmptyText then
    Result := EmptySelectionText;
end;

function TcxCustomCheckComboBoxProperties.CalculateEditValueByCheckStates(
  Sender: TObject; const ACheckStates: TcxCheckStates): TcxEditValue;
begin
  if Assigned(OnStatesToEditValue) then
    OnStatesToEditValue(Sender, ACheckStates, Result)
  else
    Result := cxCheckBox.CalculateCheckStatesValue(ACheckStates, Items,
      EditValueFormat);
end;

function TcxCustomCheckComboBoxProperties.IsEditValueValid(var EditValue: TcxEditValue;
  AEditFocused: Boolean): Boolean;
begin
  Result := True;
end;

procedure TcxCustomCheckComboBoxProperties.PrepareDisplayValue(
  const AEditValue: TcxEditValue; var DisplayValue: TcxEditValue; AEditFocused: Boolean);
begin
  CalculateCheckStatesByEditValue(nil, AEditValue, CheckStates);
  DisplayValue := CalculateDisplayValueByCheckStates(CheckStates);
end;

{ TcxCustomCheckComboBox }

class function TcxCustomCheckComboBox.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  Result := TcxCustomCheckComboBoxProperties;
end;

function TcxCustomCheckComboBox.GetItemState(AIndex: Integer): TcxCheckBoxState;
begin
  Result := FStates[AIndex];
end;

procedure TcxCustomCheckComboBox.SetItemState(AIndex: Integer; AState: TcxCheckBoxState);
begin
  if AState = cbsGrayed then Exit;
  if FStates[AIndex] <> AState then
  begin
    FStates[AIndex] := AState;
    SynchronizeEditValue;
  end;
end;

function TcxCustomCheckComboBox.ClickCheck(AItemIndex: Integer): Boolean;
begin
  Result := CanModify and DoClickCheck(AItemIndex) and DoEditing;
end;

function TcxCustomCheckComboBox.DoClickCheck(AItemIndex: Integer): Boolean;

  function InternalDoClickCheck(AProperties: TcxCustomCheckComboBoxProperties;
    AItemIndex: Integer): Boolean;
  begin
    Result := True;
    if Assigned(AProperties.OnClickCheck) then
      AProperties.OnClickCheck(Self, AItemIndex, Result);
  end;

var
  AAllowToggle1, AAllowToggle2: Boolean;
begin
  AAllowToggle1 := InternalDoClickCheck(Properties, AItemIndex);
  if RepositoryItem <> nil then
    AAllowToggle2 := InternalDoClickCheck(
      TcxCustomCheckComboBoxProperties(RepositoryItem.Properties), AItemIndex)
  else
    AAllowToggle2 := True;
  Result := AAllowToggle1 and AAllowToggle2;
end;

function TcxCustomCheckComboBox.GetEditingValue: TcxEditValue;
begin
  Result := EditValue;
end;

procedure TcxCustomCheckComboBox.HandleSelectItem(Sender: TObject);
begin
end;

procedure TcxCustomCheckComboBox.Initialize;
begin
  inherited Initialize;
  FEditValue := 0;
  ControlStyle := ControlStyle - [csClickEvents];
  CalculateDrawCheckParams;
end;

procedure TcxCustomCheckComboBox.InitializePopupWindow;
begin
  inherited InitializePopupWindow;
  (PopupWindow as TcxCheckComboBoxPopupWindow).SysPanelStyle := ActiveProperties.PopupSizeable;
end;

function TcxCustomCheckComboBox.InternalGetText: string;
begin
  if IsDestroying then
    Result := ''
  else
    Result := ViewInfo.Text;
end;

function TcxCustomCheckComboBox.InternalSetText(const Value: string): Boolean;
begin
  Result := False;
end;

procedure TcxCustomCheckComboBox.InternalValidateDisplayValue(const ADisplayValue: TcxEditValue);
begin
end;

function TcxCustomCheckComboBox.IsEditValueStored: Boolean;
begin
  Result := (ActiveProperties.EditValueFormat = cvfInteger) and (EditValue <> 0) or
    (ActiveProperties.EditValueFormat <> cvfInteger) and (VarToStr(EditValue) <> ''); 
end;

procedure TcxCustomCheckComboBox.KeyPress(var Key: Char);
begin
  if (Key = Char(VK_SPACE)) and HasPopupWindow then
  begin
    if Assigned(OnKeyPress) then
      OnKeyPress(Self, Key);
    (LookupData.ActiveControl as TcxCustomCheckComboBoxListBox).KeyPress(Key)
  end
  else
    inherited KeyPress(Key);
end;

procedure TcxCustomCheckComboBox.CloseUp(AReason: TcxEditCloseUpReason);
begin
  if HasPopupWindow then
  begin
    FCloseUpReason := AReason;  
    PopupWindow.CloseUp;
    if not ActiveProperties.AlwaysPostEditValue and ActiveProperties.ImmediatePost and
        CanPostEditValue and ValidateEdit(True) then
      InternalPostEditValue;
  end;
end;

function TcxCustomCheckComboBox.GetProperties: TcxCustomCheckComboBoxProperties;
begin
  Result := TcxCustomCheckComboBoxProperties(FProperties);
end;

function TcxCustomCheckComboBox.GetActiveProperties: TcxCustomCheckComboBoxProperties;
begin
  Result := TcxCustomCheckComboBoxProperties(InternalGetActiveProperties);
end;

function TcxCustomCheckComboBox.GetLookupData: TcxCheckComboBoxLookupData;
begin
  Result := TcxCheckComboBoxLookupData(FLookupData);
end;

procedure TcxCustomCheckComboBox.SetProperties(Value: TcxCustomCheckComboBoxProperties);
begin
  FProperties.Assign(Value);
end;

procedure TcxCustomCheckComboBox.CalculateDrawCheckParams;
const
  ABorderStyleMap: array[TcxLookAndFeelKind] of TcxEditCheckBoxBorderStyle =
    (ebsFlat, ebs3D, ebsUltraFlat, ebsOffice11);
begin
  with PopupControlsLookAndFeel do
  begin
    FNativeStyle := NativeStyle and AreVisualStylesAvailable([totButton, totComboBox]);
    if not FNativeStyle then
      FCheckBorderStyle := ABorderStyleMap[Kind];
  end;
end;

function TcxCustomCheckComboBox.GetValue: Variant;
begin
  Result := EditValue;
end;

procedure TcxCustomCheckComboBox.PopupControlsLookAndFeelChanged(
  Sender: TcxLookAndFeel; AChangedValues: TcxLookAndFeelValues);
begin
  inherited PopupControlsLookAndFeelChanged(Sender, AChangedValues);
  if not IsDestroying then
    CalculateDrawCheckParams;
end;

procedure TcxCustomCheckComboBox.PopupWindowShowed(Sender: TObject);
begin
  inherited PopupWindowShowed(Sender);
  TcxCustomCheckComboBoxListBox(ILookupData.ActiveControl).CheckHotTrack;
end;

procedure TcxCustomCheckComboBox.PropertiesChanged(Sender: TObject);
begin
  with ActiveProperties.Items do
    if ItemChanged and (ChangedItemOperation = copDelete) and (ChangedItemIndex < Length(FStates) - 1) then
      Move(FStates[ChangedItemIndex + 1], FStates[ChangedItemIndex],
        (ActiveProperties.Items.Count - 1 - ChangedItemIndex) * SizeOf(TcxCheckBoxState));
  SetLength(FStates, ActiveProperties.Items.Count);

  inherited PropertiesChanged(Sender);

  if ModifiedAfterEnter then
    UpdateDrawValue
  else
    if IsDBEdit then
      SynchronizeDisplayValue
    else
      EditValue := ActiveProperties.CalculateEditValueByCheckStates(
        GetStandaloneEventSender(Self), FStates);
end;

function TcxCustomCheckComboBox.RefreshContainer(const P: TPoint;
  Button: TcxMouseButton; Shift: TShiftState; AIsMouseEvent: Boolean): Boolean;
begin
  Result := inherited RefreshContainer(P, Button, Shift, AIsMouseEvent);
  ActiveProperties.FCheckPaintHelper.Style.Assign(ActiveStyle);
end;

procedure TcxCustomCheckComboBox.SetItemIndex(Value: Integer);
begin
  LookupData.InternalSetCurrentKey(Value);
end;

procedure TcxCustomCheckComboBox.SetValue(const AValue: Variant);
begin
  InternalEditValue := AValue;
end;

procedure TcxCustomCheckComboBox.SynchronizeDisplayValue;
begin
  ActiveProperties.CalculateCheckStatesByEditValue(
    GetStandaloneEventSender(Self), EditValue, FStates);
  UpdateDrawValue;
end;

procedure TcxCustomCheckComboBox.SynchronizeEditValue;
begin
  InternalEditValue := ActiveProperties.CalculateEditValueByCheckStates(
    GetStandaloneEventSender(Self), FStates);
end;

procedure TcxCustomCheckComboBox.UpdateDrawValue;
begin
  TcxCustomTextEditViewInfo(ViewInfo).SelLength := 0;
  TcxCustomTextEditViewInfo(ViewInfo).Text :=
    ActiveProperties.CalculateDisplayValueByCheckStates(FStates);
  with TcxCustomTextEditViewInfo(ViewInfo) do
    Self.ActiveProperties.DisplayValueToDisplayText(Text);
  with TcxCustomTextEditViewInfo(ViewInfo) do
    TextOutData.Initialized := False;
  InvalidateRect(TcxCustomTextEditViewInfo(ViewInfo).ClientRect, False);
end;

{ TcxFilterChecksHelper }

class function TcxFilterChecksHelper.GetFilterEditClass: TcxCustomEditClass;
begin
  Result := TcxCheckComboBox;
end;

class function TcxFilterChecksHelper.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 TcxFilterChecksHelper.InitializeProperties(AProperties,
  AEditProperties: TcxCustomEditProperties; AHasButtons: Boolean);
begin
  inherited InitializeProperties(AProperties, AEditProperties, AHasButtons);
  TcxCustomCheckComboBoxProperties(AProperties).EditValueFormat :=
    GetEditValueFormat(AEditProperties);
  with TcxCustomCheckComboBoxProperties(AProperties) do
  begin
    Items.Clear;
    Buttons.Clear;
    Buttons.Add;
    Buttons[0].Kind := bkDown;
    DropDownListStyle := lsFixedList;
  end;
  InitializeItems(AProperties, AEditProperties);
end;

class function TcxFilterChecksHelper.GetEditValueFormat(
  AEditProperties: TcxCustomEditProperties): TcxCheckStatesValueFormat;
begin
  Result := cvfCaptions;
end;

class function TcxFilterChecksHelper.GetItems(
  AEditProperties: TcxCustomEditProperties): IcxCheckItems;
begin
  Result := nil;
end;

class procedure TcxFilterChecksHelper.InitializeItems(AProperties,
  AEditProperties: TcxCustomEditProperties);
var
  AItems: IcxCheckItems;
  I: Integer;
begin
  AItems := GetItems(AEditProperties);
  if AItems = nil then
    Exit;
  for I := 0 to AItems.Count - 1 do
    TcxCustomCheckComboBoxProperties(AProperties).Items.Add.Description :=
      AItems.Captions[I];
end;

{ TcxFilterCheckComboBoxHelper }

class function TcxFilterCheckComboBoxHelper.GetEditValueFormat(
  AEditProperties: TcxCustomEditProperties): TcxCheckStatesValueFormat;
begin
  Result := TcxCustomCheckComboBoxProperties(AEditProperties).EditValueFormat
end;

class function TcxFilterCheckComboBoxHelper.GetItems(
  AEditProperties: TcxCustomEditProperties): IcxCheckItems;
begin
  Result := TcxCustomCheckComboBoxProperties(AEditProperties).Items;
end;

initialization
  GetRegisteredEditProperties.Register(TcxCheckComboBoxProperties, scxSEditRepositoryCheckComboBox);
  FilterEditsController.Register(TcxCheckComboBoxProperties, TcxFilterCheckComboBoxHelper);

finalization
  FilterEditsController.Unregister(TcxCheckComboBoxProperties, TcxFilterCheckComboBoxHelper);
  GetRegisteredEditProperties.Unregister(TcxCheckComboBoxProperties);

end.

⌨️ 快捷键说明

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