cxfiltercontrol.pas

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

PAS
2,067
字号
  AItemLink: TObject): Integer;
var
  I: Integer;
begin
  Result := -1;
  for I := 0 to Control.FilterLink.Count - 1 do
    if Control.FilterLink.ItemLinks[I] = AItemLink then
    begin
      Result := Control.FilterLink.ItemLinkIDs[I];
      Break;
    end;
end;

function TcxFilterControlCriteria.GetItemClass: TcxFilterCriteriaItemClass;
begin
  Result := TcxFilterControlCriteriaItem;
end;

function TcxFilterControlCriteria.GetItemLinkByID(AID: Integer): TObject;
var
  I: Integer;
begin
  Result := nil;
  for I := 0 to Control.FilterLink.Count - 1 do
    if Control.FilterLink.ItemLinkIDs[I] = AID then
    begin
      Result := Control.FilterLink.ItemLinks[I];
      Break;
    end;
end;

function TcxFilterControlCriteria.GetNameByItemLink(AItemLink: TObject): string;
var
  I: Integer;
begin
  Result := '';
  for I := 0 to Control.FilterLink.Count - 1 do
    if Control.FilterLink.ItemLinks[I] = AItemLink then
    begin
      Result := Control.FilterLink.ItemLinkNames[I];
      Break;
    end;
end;

function TcxFilterControlCriteria.GetItemLinkByName(const AName: string): TObject;
var
  I: Integer;
begin
  Result := nil;
  for I := 0 to Control.FilterLink.Count - 1 do
    if SameText(Control.FilterLink.ItemLinkNames[I], AName) then
    begin
      Result := Control.FilterLink.ItemLinks[I];
      Break;
    end;
end;

{ TcxCustomRowViewInfo }

constructor TcxCustomRowViewInfo.Create(AControl: TcxCustomFilterControl;
  AParent: TcxCustomRowViewInfo; ACriteriaItem: TcxCustomFilterCriteriaItem);
begin
  inherited Create;
  FControl := AControl;
  FParent := AParent;
  FCriteriaItem := ACriteriaItem;
  FButtonState := cxbsNormal;
  if AParent <> nil then AParent.Group.Add(Self);
end;

destructor TcxCustomRowViewInfo.Destroy;
begin
  if Parent <> nil then Parent.Group.Remove(Self);
  inherited Destroy;
end;

procedure TcxCustomRowViewInfo.Calc(const ARowRect: TRect);
var
  AWidth: Integer;
begin
  FRowRect := ARowRect;
  GetInternal;
  with Control do
  begin
    Canvas.Font.Assign(Font);
    if FRoot = Self then
      AWidth := Canvas.TextWidth(FButtonText + '00')
    else
      AWidth := Canvas.TextWidth('0') * Length(FButtonText);
    FButtonRect := Classes.Bounds(ARowRect.Left + 4 + Indent, 0, AWidth,
      HeightOf(ARowRect) - 4);
    if not ViewInfo.Enabled then
      FButtonState := cxbsDisabled
    else
      if (FocusedRow = Self) and (FFocusedInfo.HitTest = fhtButton) then
        FButtonState := cxbsDefault
      else
        if HasHotTrack and (FHotTrack.Row = Self) and (FHotTrack.HitTest = fhtButton) then
          FButtonState := cxbsHot
        else
          FButtonState := cxbsNormal;
  end;
  CenterRectVert(FRowRect, FButtonRect);
end;

procedure TcxCustomRowViewInfo.GetHitTestInfo(const P: TPoint;
  var HitInfo: TcxFilterControlHitTestInfo);
begin
  if PtInRect(ButtonRect, P) then
    HitInfo.HitTest := fhtButton
end;

function TcxCustomRowViewInfo.Ready: Boolean;
begin
  Result := True;
end;

function TcxCustomRowViewInfo.GetWidth: Integer;
begin
  Result := FIndent + WidthOf(FButtonRect) + 5;
end;

function TcxCustomRowViewInfo.IsLast: Boolean;
begin
  Result := (FParent = nil) or
   (FParent.Group.GetRow(FParent.Group.GetRowCount - 1) = Self);
end;

function TcxCustomRowViewInfo.GetCondition: TcxConditionViewInfo;
begin
  Result := Self as TcxConditionViewInfo;
end;

function TcxCustomRowViewInfo.GetFocused: Boolean;
begin
  Result := Control.FocusedRow = Self;
end;

function TcxCustomRowViewInfo.GetGroup: TcxGroupViewInfo;
begin
  Result := Self as TcxGroupViewInfo;
end;

procedure TcxCustomRowViewInfo.GetInternal;
var
  AParent: TcxCustomRowViewInfo;
begin
  FLevel := 0;
  AParent := Parent;
  if AParent <> nil then
  begin
    FButtonText := '...';
    while AParent <> nil do
    begin
      AParent := AParent.Parent;
      Inc(FLevel);
    end
  end
  else FButtonText := cxGetResourceString(@cxSFilterRootButtonCaption);
  FIndent := FLevel * HeightOf(RowRect);
end;

{ TcxGroupViewInfo }

constructor TcxGroupViewInfo.Create(AControl: TcxCustomFilterControl;
  AParent: TcxCustomRowViewInfo; ACriteriaItem: TcxCustomFilterCriteriaItem);
begin
  inherited;
  FRows := TList.Create;
  FCaption := cxGetResourceString(@cxSFilterGroupCaption);
  if ACriteriaItem <> nil then
    FBoolOperator := TcxFilterCriteriaItemList(ACriteriaItem).BoolOperatorKind
  else
    FBoolOperator := fboAnd;
end;

destructor TcxGroupViewInfo.Destroy;
begin
  while RowCount > 0 do Rows[0].Free;
  FreeAndNil(FRows);
  inherited Destroy;
end;

procedure TcxGroupViewInfo.Add(ARow: TcxCustomRowViewInfo);
begin
  FRows.Add(ARow);
end;

procedure TcxGroupViewInfo.Remove(ARow: TcxCustomRowViewInfo);
begin
  FRows.Remove(ARow);
end;

procedure TcxGroupViewInfo.Calc(const ARowRect: TRect);
var
  ASize: TSize;
begin
  inherited Calc(ARowRect);
  with Control.Canvas do
  begin
    Font.Assign(Control.FontBoolOperator);
    FBoolOperatorText := cxBoolOperatorText[BoolOperator];
    ASize := TextExtent(FBoolOperatorText);
    FBoolOperatorRect := Bounds(ButtonRect.Right + 8, 0, ASize.cx + 2, ASize.cy + 2);
    CenterRectVert(FRowRect, FBoolOperatorRect);
    Font.Assign(Control.Font);
    ASize := TextExtent(FCaption);
    FCaptionRect := Bounds(FBoolOperatorRect.Right + 8, 0, ASize.cx + 2, ASize.cy + 2);
    CenterRectVert(FRowRect, FCaptionRect);
  end;
end;

procedure TcxGroupViewInfo.GetHitTestInfo(const P: TPoint;
  var HitInfo: TcxFilterControlHitTestInfo);
begin
  inherited;
  if HitInfo.HitTest = fhtNone then
    if PtInRect(FBoolOperatorRect, P) then HitInfo.HitTest := fhtBoolOperator;
end;

function TcxGroupViewInfo.GetWidth: Integer;
begin
  Result := inherited GetWidth + WidthOf(FBoolOperatorRect) +
    WidthOf(FCaptionRect) + 16;
end;

function TcxGroupViewInfo.GetRow(Index: Integer): TcxCustomRowViewInfo;
begin
  Result := TcxCustomRowViewInfo(FRows[Index]);
end;

function TcxGroupViewInfo.GetRowCount: Integer;
begin
  Result := FRows.Count;
end;

procedure TcxGroupViewInfo.SetRow(Index: Integer;
  const Value: TcxCustomRowViewInfo);
begin
  FRows[Index] := Value;
end;

{ TcxValueInfo }

constructor TcxValueInfo.Create;
begin
  inherited Create;
  FValue := Null;
  FValueText := '';
  FValueRect := EmptyRect;
end;

destructor TcxValueInfo.Destroy;
begin
  FreeAndNil(FValueViewInfo);
  inherited Destroy;
end;

procedure TcxValueInfo.SetValueViewInfo(
  const Value: TcxCustomEditViewInfo);
begin
  FValueViewInfo.Free;
  FValueViewInfo := Value;
end;

{ TcxValuesViewInfo }

constructor TcxValuesViewInfo.Create(ACondition: TcxConditionViewInfo);
begin
  inherited Create;
  FCondition := ACondition;
  FList := TList.Create;
end;

destructor TcxValuesViewInfo.Destroy;
begin
  Clear;
  FreeAndNil(FList);
  inherited Destroy;
end;

procedure TcxValuesViewInfo.AddValue;
var
  V: TcxValueInfo;
begin
  V := TcxValueInfo.Create;
  V.ValueViewInfo :=
    TcxCustomEditViewInfo(Condition.GetProperties.GetViewInfoClass.Create);
  FList.Add(V);
end;

procedure TcxValuesViewInfo.Calc;
const
  AButtonTransparency: array[Boolean] of TcxEditButtonTransparency =
    (ebtHideInactive, ebtNone);
var
  AHightlited, AHotTrack, AUseDisplayValue: Boolean;
  AProperties: TcxCustomEditProperties;
  AProvider: IcxEditDefaultValuesProvider;
  ASize: TSize;
  ASizeProperties: TcxEditSizeProperties;
  ATopLeft, AMouse: TPoint;
  AValue: TcxEditValue;
  AViewData: TcxCustomEditViewData;
  I, AExtraSize: Integer;
begin
  if not Condition.HasDisplayValues then
  begin
    for I := 0 to Count - 1 do Values[I].FValueRect := EmptyRect;
    Exit;
  end
  else
  begin
    ATopLeft := Point(Condition.OperatorRect.Right + 8, 0);
    if Condition.Operator in [fcoBetween, fcoNotBetween] then
      FSeparator := cxGetResourceString(@cxSFilterAndCaption)
    else
      if Condition.Operator in [fcoInList, fcoNotInList] then
      begin
        Control.Canvas.Font.Assign(Control.FontValue);
        Inc(ATopLeft.X, Control.Canvas.TextWidth('('));
        FSeparator := ', ';
      end;
  end;
  AHotTrack := Control.HasHotTrack;
  AUseDisplayValue := (Condition.EditorHelper <> nil) and
    (Condition.EditorHelper.UseDisplayValue);
  for I := 0 to Count - 1 do
  with Values[I] do
  begin
    if VarIsNull(Value) then
    begin
      AProperties := Control.GetDefaultProperties;
      AValue := Control.NullString;
    end
    else
    begin
      AProperties := Condition.EditorProperties;
      if AUseDisplayValue then AValue := ValueText else AValue := Value;
    end;
    with AProperties do
    begin
      LockUpdate(True);
      AProvider := IDefaultValuesProvider;
      IDefaultValuesProvider := nil;
    end;
    try
      ValueViewInfo := TcxCustomEditViewInfo(AProperties.GetViewInfoClass.Create);
      with AProperties, Control do
      begin
        AHightlited := AHotTrack and
          (((FHotTrack.Row = Condition) and (FHotTrack.HitTest = fhtValue) and
           (FHotTrack.ValueIndex = I) and (State = fcsNormal)) or
          (HasFocus and (FocusedRow = Condition) and
           (FFocusedInfo.HitTest = fhtValue) and (FFocusedInfo.ValueIndex = I)));
        UpdateEditorStyle(FValueEditorStyle, AHightlited, ViewInfo.Enabled);
        AViewData := CreateViewData(FValueEditorStyle, True);
        AViewData.Enabled := ViewInfo.Enabled;
        try
          // calculate ValueRect
          FValueRect.TopLeft := ATopLeft;
          ASizeProperties.MaxLineCount := 1;
          ASizeProperties.Width := -1;
          ASizeProperties.Height := -1;
          ASize := AViewData.GetEditSize(Canvas, AValue, ASizeProperties);
          if AHightlited and (ASize.cx < ViewInfo.MinValueWidth) then
            ASize.cx := ViewInfo.MinValueWidth;
          with FValueRect do
          begin
            Right := Left + ASize.cx;
            Bottom := Top + ASize.cy;
          end;
          CenterRectVert(Condition.RowRect, FValueRect);
          // calculate
          if not FilterEditsController.FindHelper(AProperties.ClassType).EditPropertiesHasButtons then
            AViewData.ButtonVisibleCount := 0;
          AViewData.EditValueToDrawValue(Canvas, AValue, ValueViewInfo);
          AViewData.Calculate(Canvas, ValueRect, AMouse, cxmbNone, [],
            ValueViewInfo, True);
        finally
          FreeAndNil(AViewData);
        end;
        AExtraSize := 4;
        if Condition.Operator in [fcoBetween, fcoNotBetween, fcoInList, fcoNotInList] then
        begin
          Canvas.Font.Assign(FontValue);
          Inc(AExtraSize, Canvas.TextWidth(FSeparator) + 4);
        end;
        Inc(ATopLeft.X, WidthOf(ValueRect) + AExtraSize);
      end;
    finally
      with AProperties do
      begin
        IDefaultValuesProvider := AProvider;
        LockUpdate(False);
      end;
    end;
  end;
  if Condition.Operator in [fcoInList, fcoNotInList] then
  begin
    Control.Canvas.Font.Assign(Control.FontValue);
    FAddButtonRect := Bounds(Values[Count - 1].ValueRect.Right +
      Control.Canvas.TextWidth(')0'), 0, Control.Canvas.TextWidth('000'),
      HeightOf(Condition.RowRect) - 4);
    CenterRectVert(Condition.RowRect, FAddButtonRect);
    // get ButtonState
    if not Control.ViewInfo.Enabled then
      FAddButtonState := cxbsDisabled
    else
      with Control.FFocusedInfo do
        if (Row = Condition) and (HitTest = fhtAddValue) then
          FAddButtonState := cxbsDefault
        else
          with Control.FHotTrack do

⌨️ 快捷键说明

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