cxcheckbox.pas

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

PAS
1,873
字号
  ACheckBoxViewInfo.IsEditClass := GetIsEditClass;
  ACheckBoxViewInfo.DrawSelectionBar := False;
  ACheckBoxViewInfo.HasPopupWindow := False;
  ACheckBoxViewInfo.DrawTextFlags := GetDrawTextFlags;
  CalculateCheckBoxViewInfo(Self, ACheckBoxViewInfo, AIsMouseEvent);
  if Edit <> nil then
//    ACheckBoxViewInfo.Text := ''
//  else
    ACheckBoxViewInfo.Text := TcxCustomCheckBox(Edit).Caption;
  if IsInplace and not (Properties.IsEmbeddedEdit or
    Properties.UseAlignmentWhenInplace or (ACheckBoxViewInfo.Text <> '')) then
      ACheckBoxViewInfo.Alignment := taCenter
  else
    ACheckBoxViewInfo.Alignment := Properties.Alignment;
  ACheckBoxViewInfo.CheckBoxBorderStyle := GetCheckBoxBorderStyle(AViewInfo.HotState);
  ACheckBoxViewInfo.CheckBoxGlyph := Properties.Glyph;
  ACheckBoxViewInfo.CheckBoxGlyphCount := Properties.GlyphCount;
  ACheckBoxViewInfo.NullValueShowingStyle := Properties.NullStyle;
  ACheckBoxViewInfo.HasGlyph := IsGlyphValid(Properties.Glyph, Properties.GlyphCount);
  ACheckBoxViewInfo.CheckBorderOffset :=
    GetEditCheckBorderOffset(ACheckBoxViewInfo.CheckBoxBorderStyle, NativeStyle,
    ACheckBoxViewInfo.HasGlyph, ACheckBoxViewInfo.Painter);
  CalculateCheckRects(GetEditCheckSize(ACanvas, NativeStyle, Properties.Glyph,
    Properties.GlyphCount, AViewInfo.Painter));
  if not Enabled then
    ACheckBoxViewInfo.CheckBoxState := ecsDisabled
  else
    if IsCheckPressed then
      ACheckBoxViewInfo.CheckBoxState := ecsPressed
    else
      if not IsDesigning and PtInRect(ACheckBoxViewInfo.BorderRect, P) then
        if Shift = [] then
          ACheckBoxViewInfo.CheckBoxState := ecsHot
        else if (Shift = [ssLeft]) and ((Button = cxmbLeft) or (ACheckBoxViewInfo.CheckBoxState = ecsPressed)) then
          ACheckBoxViewInfo.CheckBoxState := ecsPressed
        else
          ACheckBoxViewInfo.CheckBoxState := ecsNormal
      else
        ACheckBoxViewInfo.CheckBoxState := ecsNormal;

  CalculateCustomCheckBoxViewInfo(ACanvas, Self, ACheckBoxViewInfo);

  if IsInplace and (ACheckBoxViewInfo.CheckBoxBorderStyle = ebsSingle) then
    if (ACheckBoxViewInfo.CheckBoxState = ecsHot) or (IsDesigning and (ACheckBoxViewInfo.CheckBoxState <> ecsDisabled)) then
      ACheckBoxViewInfo.BorderColor := clHighlight
    else
      ACheckBoxViewInfo.BorderColor := clBtnShadow;

  ACheckBoxViewInfo.IsTextColorAssigned := Style.IsValueAssigned(svTextColor) or
    ((ACheckBoxViewInfo.Painter <> nil) and
    (ACheckBoxViewInfo.Painter.DefaultEditorTextColor(True) <> clDefault));
end;

procedure TcxCustomCheckBoxViewData.EditValueToDrawValue(ACanvas: TcxCanvas;
  const AEditValue: TcxEditValue; AViewInfo: TcxCustomEditViewInfo);
begin
  if PreviewMode then
    TcxCustomCheckBoxViewInfo(AViewInfo).State := cbsChecked
  else
    TcxCustomCheckBoxViewInfo(AViewInfo).State := Properties.GetState(AEditValue);
  if IsInplace and not Properties.IsEmbeddedEdit then
    TcxCustomCheckBoxViewInfo(AViewInfo).Text := '';
  CalculateCustomCheckBoxViewInfo(ACanvas, Self, TcxCustomCheckBoxViewInfo(AViewInfo));
end;

function TcxCustomCheckBoxViewData.GetBorderStyle: TcxEditBorderStyle;
begin
  Result := ebsNone;
end;

function TcxCustomCheckBoxViewData.InternalGetEditConstantPartSize(ACanvas: TcxCanvas;
  AIsInplace: Boolean; AEditSizeProperties: TcxEditSizeProperties;
  var MinContentSize: TSize; AViewInfo: TcxCustomEditViewInfo): TSize;
var
  ACheckBoxViewInfo: TcxCustomCheckBoxViewInfo;
  ASize1, ASize2: TSize;
  AText: string;
begin
  Result := inherited InternalGetEditConstantPartSize(ACanvas, AIsInplace,
    AEditSizeProperties, MinContentSize, AViewInfo);
  ACheckBoxViewInfo := TcxCustomCheckBoxViewInfo(AViewInfo);
  with ACheckBoxViewInfo.CheckBoxRect do
    ASize1 := Size(Right - Left, Bottom - Top);

  if IsInplace then
    if (ACheckBoxViewInfo.Alignment <> taCenter) and (ACheckBoxViewInfo.Text <> '') then
    begin
      ACanvas.Font := Style.GetVisibleFont;
      ASize1.cx := ACheckBoxViewInfo.TextRect.Left - ACheckBoxViewInfo.Bounds.Left +
        ACanvas.TextWidth(RemoveAccelChars(ACheckBoxViewInfo.Text)) +
        (ACheckBoxViewInfo.Bounds.Right - ACheckBoxViewInfo.TextRect.Right);
    end
    else
      ASize1.cx := ASize1.cx + 2 * 2;

  if IsInplace then
    ASize1.cy := ASize1.cy + (1 - ACheckBoxViewInfo.CheckBorderOffset) * 2
  else
    ASize1.cy := ASize1.cy + 2 * 2;
  if (Properties.Alignment = taCenter) or IsInplace then
    AText := 'Gg'
  else
    AText := RemoveAccelChars(TcxCustomCheckBox(Edit).Caption);
  if not Enabled and not IsNativeStyle(Style.LookAndFeel) then
    Dec(AEditSizeProperties.Width);
  ASize2 := GetTextEditContentSize(ACanvas, Self, AText,
    DrawTextFlagsTocxTextOutFlags(GetDrawTextFlags) or CXTO_SINGLELINE or CXTO_CHARBREAK,
    AEditSizeProperties, 0, False);
  if ASize1.cy < ASize2.cy then
    ASize1.cy := ASize2.cy;

  Result.cx := Result.cx + ASize1.cx;
  Result.cy := Result.cy + ASize1.cy;
end;

function TcxCustomCheckBoxViewData.GetDrawTextFlags: Integer;
const
  AHorzAlignmentFlags: array [TcxEditHorzAlignment] of Integer = (
    cxAlignLeft, cxAlignLeft, cxAlignHCenter
  );
begin
  with Properties.InternalAlignment do
  begin
    Result := AHorzAlignmentFlags[Horz];
    Result := Result or cxSingleLine;
  end;
  Result := Result or cxShowPrefix;
  if Properties.MultiLine then
  begin
    Result := Result and (not cxSingleLine);
    Result := Result or cxDontClip;
    Result := Result or cxWordBreak;
  end;

  if IsInplace or not Properties.MultiLine then
    Result := Result or cxAlignVCenter
  else
    Result := Result or cxAlignTop;
end;

function TcxCustomCheckBoxViewData.GetIsEditClass: Boolean;
begin
  Result := True;
end;

function TcxCustomCheckBoxViewData.IsCheckPressed: Boolean;
begin
  Result := (Edit <> nil) and TcxCustomCheckBox(Edit).FIsCheckPressed;
end;

function TcxCustomCheckBoxViewData.GetProperties: TcxCustomCheckBoxProperties;
begin
  Result := TcxCustomCheckBoxProperties(FProperties);
end;

{ TcxCheckBoxStyle }

function TcxCheckBoxStyle.HasBorder: Boolean;
begin
  Result := False;
end;

{ TcxCustomCheckBoxProperties }

constructor TcxCustomCheckBoxProperties.Create(AOwner: TPersistent);
begin
  inherited Create(AOwner);
  FDisplayChecked := cxGetResourceString(@cxSEditCheckBoxChecked);
  FDisplayUnchecked := cxGetResourceString(@cxSEditCheckBoxUnchecked);
  FDisplayGrayed := cxGetResourceString(@cxSEditCheckBoxGrayed);

  FGlyphCount := 6;
  FNullStyle := nssGrayedChecked;
  FValueChecked := True;
  FValueGrayed := Null;
  FValueUnchecked := False;
end;

destructor TcxCustomCheckBoxProperties.Destroy;
begin
  if FGlyph <> nil then
    FreeAndNil(FGlyph);
  inherited Destroy;
end;

procedure TcxCustomCheckBoxProperties.Assign(Source: TPersistent);
begin
  if Source is TcxCustomCheckBoxProperties then
  begin
    BeginUpdate;
    try
      inherited Assign(Source);
      with Source as TcxCustomCheckBoxProperties do
      begin
        Self.AllowGrayed := AllowGrayed;
        Self.DisplayChecked := DisplayChecked;
        Self.DisplayGrayed := DisplayGrayed;
        Self.DisplayUnchecked := DisplayUnchecked;
        Self.FullFocusRect := FullFocusRect;
        Self.Glyph := Glyph;
        Self.GlyphCount := GlyphCount;
        Self.MultiLine := MultiLine;
        Self.NullStyle := NullStyle;
        Self.UseAlignmentWhenInplace := UseAlignmentWhenInplace;
        Self.SetStateValues(ValueChecked, ValueGrayed, ValueUnchecked);
      end;
    finally
      EndUpdate;
    end
  end
  else
    inherited Assign(Source);
end;

function TcxCustomCheckBoxProperties.CanCompareEditValue: Boolean;
begin
  Result := True;
end;

function TcxCustomCheckBoxProperties.CompareDisplayValues(
  const AEditValue1, AEditValue2: TcxEditValue): Boolean;
begin
  Result := GetState(AEditValue1) = GetState(AEditValue2);
end;

class function TcxCustomCheckBoxProperties.GetContainerClass: TcxContainerClass;
begin
  Result := TcxCheckBox;
end;

function TcxCustomCheckBoxProperties.GetDisplayText(const AEditValue: TcxEditValue;
  AFullText: Boolean = False; AIsInplace: Boolean = True): WideString;
begin
  case GetState(AEditValue) of
    cbsChecked:
      Result := FDisplayChecked;
    cbsUnchecked:
      Result := FDisplayUnchecked;
    cbsGrayed:
      Result := FDisplayGrayed;
  end;
end;

class function TcxCustomCheckBoxProperties.GetStyleClass: TcxCustomEditStyleClass;
begin
  Result := TcxCheckBoxStyle;
end;

function TcxCustomCheckBoxProperties.GetSpecialFeatures: TcxEditSpecialFeatures;
begin
  Result := inherited GetSpecialFeatures + [esfNoContentPart];
end;

function TcxCustomCheckBoxProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
  Result := [esoAlwaysHotTrack, esoEditing, esoFiltering, esoHotTrack,
    esoShowingCaption, esoSorting, esoTransparency];
end;

class function TcxCustomCheckBoxProperties.GetViewInfoClass: TcxContainerViewInfoClass;
begin
  Result := TcxCustomCheckBoxViewInfo;
end;

function TcxCustomCheckBoxProperties.IsActivationKey(AKey: Char): Boolean;
begin
  Result := AKey = ' ';
end;

function TcxCustomCheckBoxProperties.IsEditValueValid(var EditValue: TcxEditValue; AEditFocused: Boolean): Boolean;
begin
  Result := inherited IsEditValueValid(EditValue, AEditFocused);
  if Result then
    Result := not CheckValue(EditValue);
end;

function TcxCustomCheckBoxProperties.IsResetEditClass: Boolean;
begin
  Result := True;
end;

procedure TcxCustomCheckBoxProperties.PrepareDisplayValue(const AEditValue:
  TcxEditValue; var DisplayValue: TcxEditValue; AEditFocused: Boolean);
begin
  if VarEqualsExact(AEditValue, FValueChecked) then
    DisplayValue := Integer(cbsChecked)
  else
    if VarEqualsExact(AEditValue, FValueUnchecked) then
      DisplayValue := Integer(cbsUnchecked)
    else
      DisplayValue := Integer(cbsGrayed);
end;

function TcxCustomCheckBoxProperties.CanValidate: Boolean;
begin
  Result := True;
end;

procedure TcxCustomCheckBoxProperties.DefineProperties(Filer: TFiler);
begin
  inherited DefineProperties(Filer);
  Filer.DefineProperty('Caption', ReadCaption, nil, False);
end;

class function TcxCustomCheckBoxProperties.GetViewDataClass: TcxCustomEditViewDataClass;
begin
  Result := TcxCustomCheckBoxViewData;
end;

function TcxCustomCheckBoxProperties.HasDisplayValue: Boolean;
begin
  Result := True;
end;

function TcxCustomCheckBoxProperties.CheckValue(const AValue: TcxEditValue): Boolean;
begin
  Result := not(InternalVarEqualsExact(AValue, FValueChecked) or InternalVarEqualsExact(AValue,
    FValueGrayed) or InternalVarEqualsExact(AValue, FValueUnchecked));
end;

function TcxCustomCheckBoxProperties.GetState(
  const AEditValue: TcxEditValue): TcxCheckBoxState;
var
  ADisplayValue: TcxEditValue;
begin
  PrepareDisplayValue(AEditValue, ADisplayValue, False);
  Result := TcxCheckBoxState(Integer(ADisplayValue));
end;

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

function TcxCustomCheckBoxProperties.IsEmbeddedEdit: Boolean;
begin
  Result := False;
end;

function TcxCustomCheckBoxProperties.GetAlignment: TAlignment;
begin
  Result := inherited Alignment.Horz;
end;

function TcxCustomCheckBoxProperties.GetGlyph: TBitmap;
begin
  Result := InternalGetGlyph;
end;

function TcxCustomCheckBoxProperties.GetInternalAlignment: TcxEditAlignment;
begin
  Result := inherited Alignment;
end;

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

function TcxCustomCheckBoxProperties.IsAlignmentStored: Boolean;
begin
  Result := inherited Alignment.IsHorzStored;
end;

function TcxCustomCheckBoxProperties.IsDisplayCheckedStored: Boolean;
begin
  Result := not InternalCompareString(FDisplayChecked,
    cxGetResourceString(@cxSEditCheckBoxC

⌨️ 快捷键说明

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