cxcheckcombobox.pas

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

PAS
1,557
字号
  end;
end;

procedure TcxCustomCheckComboBoxListBox.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  AItemIndex: Integer;
  ANewHotCheckIndex, ANewPressedCheckIndex: Integer;
begin
  inherited MouseUp(Button, Shift, X, Y);
  ANewPressedCheckIndex := FPressedCheckIndex;
  if Button = mbLeft then
  begin
    SetCaptureControl(nil);
    AItemIndex := ItemAtPos(Point(X, Y), True);
    if (AItemIndex <> -1) and Edit.ActiveProperties.Items[ItemIndex].Enabled then
    begin
      Edit.LookupData.InternalSetCurrentKey(AItemIndex);
      if AItemIndex = FPressedCheckIndex then
        UpdateItemState(AItemIndex);
    end;
    ANewPressedCheckIndex := -1;
  end;
  if Shift = [] then
    ANewHotCheckIndex := GetCheckAt(X, Y)
  else
    ANewHotCheckIndex := -1;
  SynchronizeCheckStates(ANewHotCheckIndex, ANewPressedCheckIndex);
end;

procedure TcxCustomCheckComboBoxListBox.RecreateWindow;
begin
  with Edit do
  begin
    FCheckSize := GetEditCheckSize(Self.Canvas, PopupControlsLookAndFeel.NativeStyle,
      ActiveProperties.Glyph, ActiveProperties.GlyphCount, PopupControlsLookAndFeel.SkinPainter);
    FCheckBorderOffset := GetEditCheckBorderOffset(TcxContainerBorderStyle(FCheckBorderStyle),
      FNativeStyle, VerifyBitmap(ActiveProperties.Glyph) and (ActiveProperties.GlyphCount > 0),
      LookAndFeel.SkinPainter);
  end;
  FCheckSize.cx := FCheckSize.cx - FCheckBorderOffset * 2;
  FCheckSize.cy := FCheckSize.cy - FCheckBorderOffset * 2;

  ItemHeight := GetItemHeight;
  if Edit.IsOnMeasureItemEventAssigned then
    Style := lbOwnerDrawVariable
  else
    Style := lbOwnerDrawFixed;
end;

procedure TcxCustomCheckComboBoxListBox.SetItemIndex(const Value: Integer);
begin
  if not FInternalUpdate then
    inherited SetItemIndex(Value);
end;

procedure TcxCustomCheckComboBoxListBox.SynchronizeCheckStates(ANewHotCheckIndex,
  ANewPressedIndex: Integer);
begin
  if ANewHotCheckIndex <> FHotCheckIndex then
  begin
    InvalidateCheck(FHotCheckIndex);
    FHotCheckIndex := ANewHotCheckIndex;
    InvalidateCheck(FHotCheckIndex);
  end;
  if ANewPressedIndex <> FPressedCheckIndex then
  begin
    InvalidateCheck(FPressedCheckIndex);
    FPressedCheckIndex := ANewPressedIndex;
    InvalidateCheck(FPressedCheckIndex);
  end;
end;

procedure TcxCustomCheckComboBoxListBox.UpdateItemState(const AIndex: Integer);
var
  ACurrentState: TcxCheckBoxState;
begin
  if Edit.ClickCheck(AIndex) then
  begin
    with Edit.ActiveProperties do
    begin
      ACurrentState := Edit.FStates[AIndex];
      Edit.FStates[AIndex] :=
        FCheckPaintHelper.GetNextState(ACurrentState);
      Edit.SynchronizeEditValue;
      Edit.ModifiedAfterEnter := True;
    end;
    if Edit.ActiveProperties.ImmediatePost and Edit.CanPostEditValue then
      Edit.InternalPostEditValue;
    InvalidateCheck(AIndex);
  end;
end;

function TcxCustomCheckComboBoxListBox.GetEdit: TcxCustomCheckComboBox;
begin
  Result := TcxCustomCheckComboBox(inherited Edit);
end;

procedure TcxCustomCheckComboBoxListBox.LBGetTextLen(var Message: TMessage);
begin
  Message.Result := 0;
end;

procedure TcxCustomCheckComboBoxListBox.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  BeginMouseTracking(Self, GetControlRect(Self), Self);
end;

procedure TcxCustomCheckComboBoxListBox.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  InternalMouseMove([], -1, -1);
  EndMouseTracking(Self);
end;

{ TcxCheckComboBoxLookupData }

procedure TcxCheckComboBoxLookupData.TextChanged;
begin
end;

function TcxCheckComboBoxLookupData.GetListBoxClass: TcxCustomEditListBoxClass;
begin
  Result := TcxCustomCheckComboBoxListBox;
end;

function TcxCheckComboBoxLookupData.GetItem(Index: Integer): string;
begin
  with TcxCustomCheckComboBox(Edit).ActiveProperties do
    if (Index > -1) and (Index < Items.Count) then
      Result := Items[Index].Description
    else
      Result := ''
end;

function TcxCheckComboBoxLookupData.GetItemCount: Integer;
begin
  Result := TcxCustomCheckComboBox(Edit).ActiveProperties.Items.Count;
end;

{ TcxCheckComboBox }

class function TcxCheckComboBox.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  Result := TcxCheckComboBoxProperties;
end;

function TcxCheckComboBox.GetActiveProperties: TcxCheckComboBoxProperties;
begin
  Result := TcxCheckComboBoxProperties(InternalGetActiveProperties);
end;

function TcxCheckComboBox.GetProperties: TcxCheckComboBoxProperties;
begin
  Result := TcxCheckComboBoxProperties(FProperties);
end;

procedure TcxCheckComboBox.SetProperties(Value: TcxCheckComboBoxProperties);
begin
  FProperties.Assign(Value);
end;

{ TcxCheckPaintHelper }

constructor TcxCheckPaintHelper.Create(AOwner : TPersistent);
begin
  inherited;
  FStyle := TcxCustomEditStyle.Create(Self, False);
end;

destructor TcxCheckPaintHelper.Destroy;
begin
  FreeAndNil(FStyle);
  inherited Destroy;
end;

procedure TcxCheckPaintHelper.SetStyle(Value: TcxCustomEditStyle);
begin
  FStyle.Assign(Value);
end;

function TcxCheckPaintHelper.GetNextState(Value: TcxCheckBoxState): TcxCheckBoxState;
begin
  case Value of
    cbsChecked:
      Result := cbsUnchecked;
    cbsGrayed:
      Result := cbsUnchecked;
    else
      Result := cbsChecked;
  end;
end;

function TcxCheckPaintHelper.GetCheckWidth: Integer;
begin
  Result := 13;
end;

function TcxCheckPaintHelper.CalcTextRect(const ARect: TRect;
  const ACheckState: TcxCheckBoxState): TRect;
begin
  Result := ARect;
  Inc(Result.Left, RectHeight(ARect) + 2);
end;

function TcxCheckPaintHelper.CalcCheckPoint(const ARect: TRect;
  const ACheckState: TcxCheckBoxState): TPoint;
var
  FCenterPos : Integer;
begin
  FCenterPos := CalcCenterPosHeight(ARect, GetCheckWidth);
  Result.X := ARect.Left + FCenterPos;
  Result.Y := ARect.Top + FCenterPos;
end;

function TcxCheckPaintHelper.IsClickInCheck(const AItemRect: TRect;
  const ACheckState: TcxCheckBoxState; X, Y: Integer;
  const AUseRightToLeftAlignment: Boolean = False): Boolean;
var
  FCheckRect : TRect;
  FCenterPos : Integer;
begin
  FCenterPos := CalcCenterPosHeight(AItemRect, GetCheckWidth);
  if not AUseRightToLeftAlignment then
    FCheckRect := Bounds(AItemRect.Left + FCenterPos, AItemRect.Top + FCenterPos,
      GetCheckWidth, GetCheckWidth)
  else
    FCheckRect := Bounds(AItemRect.Right - (FCenterPos * 3), AItemRect.Top + FCenterPos,
      GetCheckWidth, GetCheckWidth);
  Result := (X >= FCheckRect.Left) and (X <= FCheckRect.Right) and
            (Y >= FCheckRect.Top) and (Y <= FCheckRect.Bottom);
end;

{ TcxCustomCheckComboBoxProperties }

constructor TcxCustomCheckComboBoxProperties.Create(AOwner: TPersistent);
begin
  inherited Create(AOwner);
  DropDownListStyle := lsFixedList;
  FDelimiter := cxCheckComboValuesDelimiter;
  FEditValueFormat := cvfInteger;
  FShowEmptyText := True;
  FEmptySelectionText := cxGetResourceString(@cxSCheckComboBoxEmptySelectionText);
  FCheckPaintHelper := TcxCheckPaintHelper.Create(nil);
  FItems := TcxCheckComboBoxItems.Create(Self, TcxCheckComboBoxItem);
  FGlyphCount := 6;
end;

destructor TcxCustomCheckComboBoxProperties.Destroy;
begin
  FreeAndNil(FItems);
  FreeAndNil(FCheckPaintHelper);
  if Assigned(FGlyph) then FreeAndNil(FGlyph);
  inherited;
end;

function TcxCustomCheckComboBoxProperties.GetGlyph: TBitmap;
begin
  if FGlyph = nil then
  begin
    FGlyph := TBitmap.Create;
    FGlyph.OnChange := GlyphChanged;
  end;
  Result := FGlyph;
end;

procedure TcxCustomCheckComboBoxProperties.GlyphChanged(Sender: TObject);
begin
  Changed;
end;

function TcxCustomCheckComboBoxProperties.IsDelimiterStored: Boolean;
begin
  Result := FDelimiter <> cxCheckComboValuesDelimiter;
end;

function TcxCustomCheckComboBoxProperties.IsEmptySelectionTextStored: Boolean;
begin
  Result := FEmptySelectionText <>
     cxGetResourceString(@cxSCheckComboBoxEmptySelectionText);
end;

procedure TcxCustomCheckComboBoxProperties.SetGlyph(Value: TBitmap);
begin
  if Value = nil then
    FreeAndNil(FGlyph)
  else
    Glyph.Assign(Value);
  Changed;
end;

procedure TcxCustomCheckComboBoxProperties.SetGlyphCount(Value: Integer);
begin
  if FGlyphCount <> Value then
  begin
    FGlyphCount := Value;
    if FGlyph <> nil then
      Changed;
  end;
end;

procedure TcxCustomCheckComboBoxProperties.Assign(Source: TPersistent);
begin
  if Source is TcxCustomCheckComboBoxProperties then
  begin
    BeginUpdate;
    try
      inherited Assign(Source);
      with TcxCustomCheckComboBoxProperties(Source) do
      begin
        Self.Delimiter := Delimiter;
        Self.EditValueFormat := EditValueFormat;
        Self.Glyph := Glyph;
        Self.GlyphCount := GlyphCount;
        Self.ShowEmptyText := ShowEmptyText;
        Self.EmptySelectionText := EmptySelectionText;
        Self.Items.Assign(Items);
        Self.OnClickCheck := OnClickCheck;
        Self.OnEditValueToStates := OnEditValueToStates;
        Self.OnStatesToEditValue := OnStatesToEditValue;
      end;
    finally
      EndUpdate;
    end
  end
  else
    inherited Assign(Source);
end;

class function TcxCustomCheckComboBoxProperties.GetContainerClass: TcxContainerClass;
begin
  Result := TcxCheckComboBox;
end;

function TcxCustomCheckComboBoxProperties.GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource;
begin
  Result := evsValue;
end;

function TcxCustomCheckComboBoxProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
  Result := inherited GetSupportedOperations;
  Include(Result, esoSortingByDisplayText);
end;

class function TcxCustomCheckComboBoxProperties.GetLookupDataClass: TcxInterfacedPersistentClass;
begin
  Result := TcxCheckComboBoxLookupData;
end;

class function TcxCustomCheckComboBoxProperties.GetPopupWindowClass: TcxCustomEditPopupWindowClass;
begin
  Result := TcxCheckComboBoxPopupWindow;
end;

class function TcxCustomCheckComboBoxProperties.GetViewDataClass: TcxCustomEditViewDataClass;
begin
  Result := TcxCustomCheckComboBoxViewData;
end;

function TcxCustomCheckComboBoxProperties.HasDisplayValue: Boolean;
begin
  Result := False;
end;

procedure TcxCustomCheckComboBoxProperties.SetDelimiter(Value: string);
begin
  if FDelimiter <> Value then
  begin
    FDelimiter := Value;
    Changed;
  end;
end;

procedure TcxCustomCheckComboBoxProperties.SetEditValueFormat(Value: TcxCheckStatesValueFormat);
begin
  if Value <> FEditValueFormat then
  begin
    FEditValueFormat := Value;
    Items.InternalNotify(nil, -1, copChanged);
  end;
end;

procedure TcxCustomCheckComboBoxProperties.SetEmptySelectionText(Value: string);
begin
  if FEmptySelectionText <> Value then
  begin
    FEmptySelectionText := Value;
    Changed;
  end;

⌨️ 快捷键说明

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