⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cxbaredititem.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 5 页
字号:
begin
  AHandled := Item.UseBarPaintingStyle;
  if AHandled then
  begin
   AUseParentCanvas := ACanvas.Handle = Canvas.Handle;
   ARect := FParts[ccpDropButton];
    if (Edit <> nil) and Edit.HandleAllocated and not AUseParentCanvas then
      MapWindowRect(Parent.Handle, Edit.Handle, ARect);
    BeforeDrawBackground(Edit, Parent, ACanvas.Handle, ARect, APrevWindowOrg);
    try
      AOriginalCanvas := FDrawParams.Canvas;
      try
        FDrawParams.Canvas := ACanvas;
        Painter.ComboControlDrawArrowButton(DrawParams, ARect, True);
      finally
        FDrawParams.Canvas := AOriginalCanvas
      end;
    finally
      AfterDrawBackground(ACanvas.Handle, APrevWindowOrg);
    end;
    if Painter.EditButtonAllowCompositeFrame and not AUseParentCanvas then
      Painter.ComboControlDrawArrowButton(DrawParams, FParts[ccpDropButton], False);
  end;
end;

procedure TcxBarEditItemControl.DoDrawEditButtonBackground(
  Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas; const ARect: TRect;
  AButtonVisibleIndex: Integer; var AHandled: Boolean);
var
  APrevWindowOrg: TPoint;
  AOriginalCanvas: TcxCanvas;
  AButtonState: Integer;
  ABackgroundRect: TRect;
begin
  AButtonState := GetEditButtonState(Sender.ButtonsInfo[AButtonVisibleIndex]);
  AHandled := Painter.EditButtonIsCustomBackground(AButtonState);

  if AHandled and (ACanvas <> nil) then
  begin
    ABackgroundRect := ARect;
    BeforeDrawBackground(Edit, Parent, ACanvas.Handle, ABackgroundRect, APrevWindowOrg);
    try
      AOriginalCanvas := FDrawParams.Canvas;
      try
        FDrawParams.Canvas := ACanvas;
        Painter.EditButtonDrawBackground(DrawParams, AButtonState,
          ABackgroundRect, GetSolidBrush(Sender.BackgroundColor));
      finally
        FDrawParams.Canvas := AOriginalCanvas
      end;
    finally
      AfterDrawBackground(ACanvas.Handle, APrevWindowOrg);
    end;
  end;
end;

procedure TcxBarEditItemControl.DoDrawEditButtonBorder(Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas; AButtonVisibleIndex: Integer;
  out ABackgroundRect, AContentRect: TRect; var AHandled: Boolean);
var
  APrevWindowOrg: TPoint;
  AOriginalCanvas: TcxCanvas;
  AOffset: TPoint;
begin
  AHandled := Painter.EditButtonIsCustomBorder;
  if (ACanvas <> nil) and AHandled then
  begin
    ABackgroundRect := Sender.ButtonsInfo[AButtonVisibleIndex].Bounds;
    AOffset := BeforeDrawBackground(Edit, Parent, ACanvas.Handle, ABackgroundRect, APrevWindowOrg);
    try
      AOriginalCanvas := FDrawParams.Canvas;
      try
        FDrawParams.Canvas := ACanvas;
        Painter.EditButtonDrawBorder(FDrawParams, GetEditButtonState(Sender.ButtonsInfo[AButtonVisibleIndex]), ABackgroundRect, AContentRect);
      finally
        FDrawParams.Canvas := AOriginalCanvas
      end;
    finally
      AfterDrawBackground(ACanvas.Handle, APrevWindowOrg);
    end;
    ABackgroundRect := cxRectOffset(ABackgroundRect, cxPointInvert(AOffset));
    AContentRect := cxRectOffset(AContentRect, cxPointInvert(AOffset));
  end;
end;

procedure TcxBarEditItemControl.DoEditPaint(Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas);
begin
  CalcDrawParams;
end;

procedure TcxBarEditItemControl.DoEditClosePopup(Sender: TcxControl;
  AReason: TcxEditCloseUpReason);
begin
  if Assigned(FSavedEditEvents.OnClosePopup) then
    FSavedEditEvents.OnClosePopup(Sender, AReason);

  case AReason of
    crCancel: DoEscape;
    crEnter: DoEnter;
    crTab: DoNavigation;
  end;
end;

procedure TcxBarEditItemControl.DoEditPropertiesChange(Sender: TObject);
begin
  if Assigned(FSavedEditEvents.OnChange) then
    FSavedEditEvents.OnChange(Sender);
  Item.CurChange;
end;

procedure TcxBarEditItemControl.DoGetEditButtonState(Sender: TcxCustomEditViewInfo;
  AButtonVisibleIndex: Integer; var AState: TcxEditButtonState);
begin
  if Item.UseBarPaintingStyle and (Focused or DrawSelected) and (AState = ebsNormal) then
    AState := ebsSelected;
end;

procedure TcxBarEditItemControl.DoGetEditDefaultButtonWidth(
  Sender: TcxCustomEditViewData; AIndex: Integer; var ADefaultWidth: Integer);
begin
  ADefaultWidth := GetDefaultEditButtonWidth(AIndex);
end;

procedure TcxBarEditItemControl.DoFocusChanged(Sender: TObject);
begin
  if Assigned(FSavedEditEvents.OnFocusChanged) then
    FSavedEditEvents.OnFocusChanged(Sender);

  if Focused and not Edit.Focused and not Edit.IsChildWindow(GetFocus) then
    Parent.HideAll;
end;

procedure TcxBarEditItemControl.DoInitPopup(Sender: TObject);
begin
  if Assigned(FSavedEditEvents.OnInitPopup) then
    FSavedEditEvents.OnInitPopup(Sender);
  if IsPopupSideward then
  begin
    DropDownEdit.Properties.PopupDirection := pdHorizontal;
    DropDownEdit.Properties.PopupVertAlignment := pavTop;
    DropDownEdit.Properties.PopupHorzAlignment := pahRight;
  end;
end;

procedure TcxBarEditItemControl.DoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if Assigned(FSavedEditEvents.OnKeyDown) then
    FSavedEditEvents.OnKeyDown(Sender, Key, Shift);
  KeyDown(Key, Shift);
end;

procedure TcxBarEditItemControl.DoKeyPress(Sender: TObject; var Key: Char);
begin
  if Assigned(FSavedEditEvents.OnKeyPress) then
    FSavedEditEvents.OnKeyPress(Sender, Key);
  KeyPress(Key);
end;

procedure TcxBarEditItemControl.DoKeyUp(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if Assigned(FSavedEditEvents.OnKeyUp) then
    FSavedEditEvents.OnKeyUp(Sender, Key, Shift);
  KeyUp(Key, Shift);
end;

procedure TcxBarEditItemControl.DoPostEditValue(Sender: TObject);
begin
  Item.EditValue := Edit.EditValue;
end;

procedure TcxBarEditItemControl.DoValidate(Sender: TObject; var DisplayValue: TcxEditValue;
  var ErrorText: TCaption; var Error: Boolean);
begin
  ErrorText := cxGetResourceString(@scxMaskEditInvalidEditValue);
  if Assigned(FSavedEditEvents.OnValidate) then
    FSavedEditEvents.OnValidate(Sender, DisplayValue, ErrorText, Error);
end;

function TcxBarEditItemControl.GetEditButtonState(AButtonViewInfo: TcxEditButtonViewInfo): Integer;
begin
  case AButtonViewInfo.Data.State of
    ebsDisabled: Result := DXBAR_DISABLED;
    ebsPressed: Result := DXBAR_DROPPEDDOWN;
    ebsSelected: Result := DXBAR_HOT
  else
    if FHotPartIndex = ecpEdit then
      Result := DXBAR_ACTIVE
    else
      Result := DXBAR_NORMAL
  end;
end;

procedure TcxBarEditItemControl.AssignViewInfoEvents(
  AViewInfo: TcxCustomEditViewInfo);
begin
  AViewInfo.OnDrawBackground := DoDrawEditBackground;
  AViewInfo.OnDrawButton := DoDrawEditButton;
  AViewInfo.OnDrawButtonBackground := DoDrawEditButtonBackground;
  AViewInfo.OnDrawButtonBorder := DoDrawEditButtonBorder;
  AViewInfo.OnGetButtonState := DoGetEditButtonState;
  AViewInfo.OnPaint := DoEditPaint;
end;

procedure TcxBarEditItemControl.ClearViewInfoEvents(
  AViewInfo: TcxCustomEditViewInfo);
begin
  AViewInfo.OnDrawBackground := nil;
  AViewInfo.OnDrawButton := nil;
  AViewInfo.OnDrawButtonBackground := nil;
  AViewInfo.OnDrawButtonBorder := nil;
  AViewInfo.OnGetButtonState := nil;
  AViewInfo.OnPaint := nil;
end;

procedure TcxBarEditItemControl.DrawEditBackground(ACanvas: TcxCanvas;
  ARect: TRect; AColor: TColor);
var
  APrevWindowOrg: TPoint;
begin
  BeforeDrawBackground(Edit, Parent, ACanvas.Handle, ARect, APrevWindowOrg);
  try
    Painter.DrawItemBackground(Self, ACanvas, ARect, GetSolidBrush(AColor));
  finally
    AfterDrawBackground(ACanvas.Handle, APrevWindowOrg);
  end;
end;

function TcxBarEditItemControl.GetBoundsRect: TRect;
begin
  Result := Painter.EditControlGetContentRect(GetPaintType, GetEditRect);
end;

function TcxBarEditItemControl.GetCurEditValue: TcxEditValue;
begin
  if Edit <> nil then
    Result := Edit.EditingValue
  else
    Result := Item.EditValue;
end;

function TcxBarEditItemControl.GetDefaultEditButtonWidth(AIndex: Integer): Integer;
begin
  if Item.UseBarPaintingStyle then
  begin
    Result := Parent.ComboBoxArrowWidth;
    Painter.EditButtonCorrectDefaultWidth(Result);
  end
  else
    Result := 0;
end;

function TcxBarEditItemControl.GetDropDownEdit: TcxCustomDropDownEdit;
begin
  Result := TcxCustomDropDownEdit(Edit);
end;

function TcxBarEditItemControl.GetEditSize: TSize;
var
  ABorderOffsets: TRect;
  AConstantPartSize, AMinContentSize: TSize;
  AEditViewInfo: TcxCustomEditViewInfo;
  AViewData: TcxCustomEditViewData;
begin
  AEditViewInfo := nil;
  AViewData := nil;
  try
    AEditViewInfo := CreateEditViewInfo;
    AViewData := CreateEditViewData(False);
    CalculateEditViewInfo(Rect(0, 0, MaxInt, MaxInt), Point(-1, -1), False, AEditViewInfo, False);
    BarCanvas.BeginPaint(Canvas.Canvas);
    try
      AConstantPartSize := AViewData.GetEditConstantPartSize(BarCanvas,
        DefaultcxEditSizeProperties, AMinContentSize, AEditViewInfo);
      ABorderOffsets := Painter.EditControlBorderOffsets(GetPaintType);
      Inc(AConstantPartSize.cx, ABorderOffsets.Left + ABorderOffsets.Right);
      Inc(AConstantPartSize.cy, ABorderOffsets.Top + ABorderOffsets.Bottom);
      if Item.CaptionIsEditValue then
        Result := AViewData.GetEditContentSize(BarCanvas, Caption, DefaultcxEditSizeProperties)
      else
        Result := Size(0, 0);
    finally
      BarCanvas.EndPaint;
    end;

    CheckSize(Result, AMinContentSize);
    if not (esfNoContentPart in Properties.GetSpecialFeatures) and (Result.cx < MinContentWidth) then
      Result.cx := MinContentWidth;
    Inc(Result.cx, AConstantPartSize.cx);
    Inc(Result.cy, AConstantPartSize.cy);
  finally
    FreeAndNil(AEditViewInfo);
    FreeAndNil(AViewData);
  end;
end;

function TcxBarEditItemControl.GetEditStyle: TcxEditStyle;
var
  ABackgroundColor, ATextColor: COLORREF;
begin
  CalcDrawParams;
  Painter.EditGetColors(Self, ATextColor, ABackgroundColor);
  if IsEditTransparent then
    ABackgroundColor := cxGetBrushData(Parent.BkBrush).lbColor;
    Result := InternalGetEditStyle(Properties, BarManager, Painter,
      EditFont, ABackgroundColor, ATextColor, DrawSelected);
end;

function TcxBarEditItemControl.GetEditViewInfo: TcxCustomEditViewInfo;
begin
  if (FEditViewInfo <> nil) and (FEditViewInfo.ClassType <> Properties.GetViewInfoClass) then
    FreeAndNil(FEditViewInfo);
  if FEditViewInfo = nil then
    FEditViewInfo := CreateEditViewInfo;
  Result := FEditViewInfo;
end;

function TcxBarEditItemControl.GetItem: TcxCustomBarEditItem;
begin
  Result := TcxCustomBarEditItem(ItemLink.Item);
end;

function TcxBarEditItemControl.GetProperties: TcxCustomEditProperties;
begin
  Result := Item.GetProperties;
end;

procedure TcxBarEditItemControl.InitEditContentParams(
  var AParams: TcxEditContentParams);
var
  ABorderOffsets: TRect;
begin
  AParams.ExternalBorderBounds := GetEditRect;
  OffsetRect(AParams.ExternalBorderBounds, -AParams.ExternalBorderBounds.Left,
    -AParams.ExternalBorderBounds.Top);
  if IsPopupSideward then
    Dec(AParams.ExternalBorderBounds.Left, GetEditOffset);
  ABorderOffsets := Painter.EditControlBorderOffsets(GetPaintType);
  OffsetRect(AParams.ExternalBorderBounds, -ABorderOffsets.Left,
    -ABorderOffsets.Top);

  if NeedEditShowCaption then
  begin
    AParams.Offsets := Painter.GetCaptionOffsets;
    AParams.SizeCorrection.cy := 0;
  end
  else
    Painter.GetEditTextParams(AParams.Offsets, AParams.SizeCorrection.cy);
  AParams.SizeCorrection.cx := 0;

  AParams.Options := [];
  if Painter.EditButtonAllowOffsetContent then
    Include(AParams.Options, ecoOffsetButtonContent);
//  if Focused then
//    AParams.Options := [ecoShowFocusRectWhenInplace];
end;

function TcxBarEditItemControl.IsDropDownEdit: Boolean;
begin
  Result := Edit is TcxCustomDropDownEdit;
end;

function TcxBarEditItemControl.IsPopupSideward: Boolean;
begin
  Result := (Parent.Kind = bkSubMenu) or Parent.IsRealVertical
end;

function TcxBarEditItemControl.NeedEditShowCaption: Boolean;
begin
  Result := Item.CaptionIsEditValue or inherited GetShowCaption and not GetShowCaption;
end;

initialization
  dxBarRegisterItem(TcxBarEditItem, TcxBarEditItemControl, True);
  BarDesignController.RegisterBarControlEditor(TcxItemsEditorEx);

finalization
  FreeAndNil(FFakeWinControl); //#!!!

  BarDesignController.UnregisterBarControlEditor(TcxItemsEditorEx);
  dxBarUnregisterItem(TcxBarEditItem);  

  FreeAndNil(FDefaultRepositoryItem);
  FreeAndNil(FEditList);
  FreeAndNil(FEditorParentForm);
  FreeAndNil(FEditStyle);

end.

⌨️ 快捷键说明

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