cxlabel.pas

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

PAS
1,364
字号
    RestoreCanvasFont(ACanvas, APrevLogFont);
  end;
end;

function TcxCustomLabelViewData.GetDrawTextFlags: Integer;
var
  ARealAngle: Integer;
begin
  ARealAngle := (Properties.Angle mod 360 + 360) mod 360;
  Result := DrawTextFlagsTocxTextOutFlags(
    PrepareTextFlag(0, Properties.Alignment.Horz,
      TcxAlignmentVert(Ord(Properties.Alignment.Vert)),
      epoShowEndEllipsis in PaintOptions,
      Properties.WordWrap and (ARealAngle = 0), 0, False));
end;

function TcxCustomLabelViewData.GetIsEditClass: Boolean;
begin
  Result := False;
end;

function TcxCustomLabelViewData.InternalEditValueToDisplayText(
  AEditValue: TcxEditValue): string;
begin
  Result := VarToStr(AEditValue);
end;

function TcxCustomLabelViewData.GetProperties: TcxCustomLabelProperties;
begin
  Result := TcxCustomLabelProperties(FProperties);
end;

{ TcxCustomLabelProperties }

constructor TcxCustomLabelProperties.Create(AOwner: TPersistent);
begin
  inherited Create(AOwner);
  FLabelEffect := cxleNormal;
  FLabelStyle := cxlsNormal;
  FOrientation := cxoRightBottom;
  FDepth := 0;
  FShadowedColor := clGrayText;
  FShowAccelChar := True;
  FAngle := 0;
  FPenWidth := 1;
  FWordWrap := False;
end;

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

procedure TcxCustomLabelProperties.Assign(Source: TPersistent);
begin
  if Source is TcxCustomLabelProperties then
  begin
    BeginUpdate;
    try
      inherited Assign(Source);
      with Source as TcxCustomLabelProperties do
      begin
        Self.LabelEffect := LabelEffect;
        Self.LabelStyle := LabelStyle;
        Self.Orientation := Orientation;
        Self.Depth := Depth;
        Self.ShadowedColor := ShadowedColor;
        Self.Angle := Angle;
        Self.PenWidth := PenWidth;
        Self.Glyph := Glyph;
        Self.ShowAccelChar := ShowAccelChar;
        Self.WordWrap := WordWrap;
      end;
    finally
      EndUpdate;
    end
  end
  else
    inherited Assign(Source);
end;

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

class function TcxCustomLabelProperties.GetContainerClass: TcxContainerClass;
begin
  Result := TcxLabel;
end;

class function TcxCustomLabelProperties.GetStyleClass: TcxCustomEditStyleClass;
begin
  Result := TcxLabelEditStyle;
end;

function TcxCustomLabelProperties.GetDisplayText(const AEditValue: TcxEditValue;
  AFullText: Boolean = False; AIsInplace: Boolean = True): WideString;
var
  ADisplayValue: TcxEditValue;
begin
  PrepareDisplayValue(AEditValue, ADisplayValue, False);
  Result := ADisplayValue;
end;

function TcxCustomLabelProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
  Result := [esoAutoHeight, esoFiltering, esoShowingCaption, esoSorting,
    esoTransparency];
end;

class function TcxCustomLabelProperties.GetViewInfoClass: TcxContainerViewInfoClass;
begin
  Result := TcxCustomLabelViewInfo;
end;

function TcxCustomLabelProperties.IsEditValueValid(var EditValue: TcxEditValue; AEditFocused: Boolean): Boolean;
begin
  Result := inherited IsEditValueValid(EditValue, AEditFocused);
end;

procedure TcxCustomLabelProperties.PrepareDisplayValue(const AEditValue:
  TcxEditValue; var DisplayValue: TcxEditValue; AEditFocused: Boolean);
begin
  DisplayValue := VarToStr(AEditValue);
end;

class function TcxCustomLabelProperties.GetViewDataClass: TcxCustomEditViewDataClass;
begin
  Result := TcxCustomLabelViewData;
end;

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

procedure TcxCustomLabelProperties.SetLabelEffect(Value : TcxLabelEffect);
begin
  if FLabelEffect <> Value then
  begin
    FLabelEffect := Value;
    Changed;
  end;
end;

procedure TcxCustomLabelProperties.SetLabelStyle(Value : TcxLabelStyle);
begin
  if FLabelStyle <> Value then
  begin
    FLabelStyle := Value;
    Changed;
  end;
end;

procedure TcxCustomLabelProperties.SetOrientation(Value : TcxLabelOrientation);
begin
  if FOrientation <> Value then
  begin
    FOrientation := Value;
    Changed;
  end;
end;

procedure TcxCustomLabelProperties.SetDepth(Value : Word);
begin
  if FDepth <> Value then
  begin
    FDepth := Value;
    Changed;
  end;
end;

procedure TcxCustomLabelProperties.SetShadowedColor(Value : TColor);
begin
  if FShadowedColor <> Value then
  begin
    FShadowedColor := Value;
    Changed;
  end;
end;

procedure TcxCustomLabelProperties.SetAngle(Value: Integer);
begin
  if FAngle <> Value then
  begin
    FAngle := Value;
    Changed;
  end;
end;

procedure TcxCustomLabelProperties.SetPenWidth(Value: Integer);
begin
  if FPenWidth <> Value then
  begin
    FPenWidth := Value;
    Changed;
  end;
end;

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

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

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

procedure TcxCustomLabelProperties.SetShowAccelChar(Value: Boolean);
begin
  if FShowAccelChar <> Value then
  begin
    FShowAccelChar := Value;
    Changed;
  end;
end;

procedure TcxCustomLabelProperties.SetWordWrap(Value: Boolean);
begin
  if FWordWrap <> Value then
  begin
    FWordWrap := Value;
    Changed;
  end;
end;

function TcxCustomLabelProperties.CalculateDepthDelta: TSize;
begin
  Result.cx := 0;
  Result.cy := 0;
  if LabelEffect = cxleNormal then Exit;
  case FOrientation of
    cxoLeft, cxoRight: Result.cx := FDepth;
    cxoTop, cxoBottom: Result.cy := FDepth;
    cxoLeftTop, cxoLeftBottom, cxoRightTop, cxoRightBottom:
    begin
      Result.cx := FDepth;
      Result.cy := FDepth;
    end;
  end;
end;

function TcxCustomLabelProperties.GetDisplayFormatOptions: TcxEditDisplayFormatOptions;
begin
  Result := [];
end;

function TcxCustomLabelProperties.GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource;
begin
  Result := evsText;
end;

{ TcxCustomLabel }

destructor TcxCustomLabel.Destroy;
begin
  FFocusControl := nil;
  inherited Destroy;
end;

procedure TcxCustomLabel.Notification(ACOmponent: TComponent; Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (FFocusControl <> nil) and
    (AComponent = FFocusControl) then FFocusControl := nil;
end;

class function TcxCustomLabel.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  Result := TcxCustomLabelProperties;
end;

procedure TcxCustomLabel.SetStyle(Value: TcxLabelEditStyle);
begin
  FStyles.Style := Value;
end;

procedure TcxCustomLabel.Initialize;
begin
  inherited Initialize;
  ControlStyle := ControlStyle - [csCaptureMouse];
  Width := 121;
  Height := 21;
end;

procedure TcxCustomLabel.SetFocusControl(Value: TWinControl);
begin
  if (FFocusControl <> Value) and (Value <> Self) then
    FFocusControl := Value;
end;

procedure TcxCustomLabel.InternalSetEditValue(const Value: TcxEditValue;
  AValidateEditValue: Boolean);
begin
  inherited InternalSetEditValue(Value, AValidateEditValue);
  if not FLockCaption then
    Caption := VarToStr(Value);
  SetInternalDisplayValue(Caption);
end;

function TcxCustomLabel.IsRightBoundFixed: Boolean;
var
  AAlignment: TAlignment;
begin
  Result := not (csReading in ComponentState);
  if Result then
  begin
    AAlignment := ActiveProperties.Alignment.Horz;
    if UseRightToLeftAlignment then
      ChangeBiDiModeAlignment(AAlignment);
    Result := AAlignment = taRightJustify;
  end;
end;

procedure TcxCustomLabel.Loaded;
begin
  if CanAllocateHandle(Self) then
    HandleNeeded;
  inherited Loaded;
end;

procedure TcxCustomLabel.SetInternalDisplayValue(Value: TcxEditValue);
begin
  ViewInfo.Text := VarToStr(Value);
  ShortRefreshContainer(False);
end;

procedure TcxCustomLabel.TextChanged;
begin
  inherited TextChanged;
  FLockCaption := True;
  try
    InternalEditValue := Caption;
  finally
    FLockCaption := False;
  end;
end;

function TcxCustomLabel.CanFocus: Boolean;
begin
  Result := IsInplace;
end;

{$IFDEF DELPHI10}
function TcxCustomLabel.GetTextBaseLine: Integer;
begin
  Result := ViewInfo.GetTextBaseLine;
end;

function TcxCustomLabel.HasTextBaseLine: Boolean;
begin
  Result := ActiveProperties.Angle = 0;
end;
{$ENDIF}

function TcxCustomLabel.CanAutoWidth: Boolean;
begin
  Result := not ActiveProperties.WordWrap;
end;

function TcxCustomLabel.CanFocusOnClick: Boolean;
begin
  Result := inherited CanFocusOnClick and IsInplace;
end;

function TcxCustomLabel.DefaultParentColor: Boolean;
begin
  Result := True;
end;

procedure TcxCustomLabel.CMDialogChar(var Message: TCMDialogChar);
begin
  if (FFocusControl <> nil) and Enabled and Properties.ShowAccelChar and
    IsAccel(Message.CharCode, Caption) and FFocusControl.CanFocus then
  begin
    FFocusControl.SetFocus;
    Message.Result := 1;
  end;
end;

function TcxCustomLabel.GetProperties: TcxCustomLabelProperties;
begin
  Result := TcxCustomLabelProperties(FProperties);
end;

function TcxCustomLabel.GetActiveProperties: TcxCustomLabelProperties;
begin
  Result := TcxCustomLabelProperties(InternalGetActiveProperties);
end;

function TcxCustomLabel.GetStyle: TcxLabelEditStyle;
begin
  Result := TcxLabelEditStyle(FStyles.Style);
end;

function TcxCustomLabel.GetViewInfo: TcxCustomLabelViewInfo;
begin
  Result := TcxCustomLabelViewInfo(FViewInfo);
end;

procedure TcxCustomLabel.SetProperties(Value: TcxCustomLabelProperties);
begin
  FProperties.Assign(Value);
end;

{ TcxLabel }

class function TcxLabel.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  Result := TcxLabelProperties;
end;

function TcxLabel.GetActiveProperties: TcxLabelProperties;
begin
  Result := TcxLabelProperties(InternalGetActiveProperties);
end;

function TcxLabel.GetProperties: TcxLabelProperties;
begin
  Result := TcxLabelProperties(FProperties);
end;

procedure TcxLabel.SetProperties(Value: TcxLabelProperties);
begin
  FProperties.Assign(Value);
end;

initialization
  GetRegisteredEditProperties.Register(TcxLabelProperties, scxSEditRepositoryLabelItem);
  FilterEditsController.Register(TcxLabelProperties, TcxFilterTextEditHelper);

finalization
  FilterEditsController.Unregister(TcxLabelProperties, TcxFilterTextEditHelper);
  GetRegisteredEditProperties.Unregister(TcxLabelProperties);
  
end.

⌨️ 快捷键说明

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