cxspinbutton.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 561 行 · 第 1/2 页
PAS
561 行
Result := TcxSpinButton;
end;
class function TcxCustomSpinButtonProperties.GetViewDataClass: TcxCustomEditViewDataClass;
begin
Result := TcxSpinButtonViewData;
end;
function TcxCustomSpinButtonProperties.IsDisplayValueNumeric: Boolean;
begin
Result := True;
end;
function TcxCustomSpinButtonProperties.IsEditValueNumeric: Boolean;
begin
Result := True;
end;
function TcxCustomSpinButtonProperties.PreserveSelection: Boolean;
begin
Result := False;
end;
{ TcxCustomSpinButton }
destructor TcxCustomSpinButton.Destroy;
begin
FSpinButtonControlHook.Free;
inherited Destroy;
end;
class function TcxCustomSpinButton.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
Result := TcxCustomSpinButtonProperties;
end;
function TcxCustomSpinButton.GetValue: Variant;
const
AVarTypeMap: array [TcxSpinEditValueType] of TVarType = (varInteger, varDouble);
begin
PrepareEditValue(Text, Result, InternalFocused);
if not VarIsNumeric(Result) then
Result := VarAsType(ActiveProperties.MinValue, AVarTypeMap[ActiveProperties.ValueType]);
end;
procedure TcxCustomSpinButton.InternalSetDisplayValue(const Value: TcxEditValue);
begin
if IsDestroying then
Exit;
inherited InternalSetDisplayValue(Value);
SetAssociateText(Value);
end;
procedure TcxCustomSpinButton.InternalSetEditValue(const Value: TcxEditValue; AValidateEditValue: Boolean);
begin
if IsDestroying then
Exit;
inherited InternalSetEditValue(Value, AValidateEditValue);
SetAssociateText(Value);
end;
procedure TcxCustomSpinButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FAssociate) then
Associate := nil;
end;
function TcxCustomSpinButton.CanFocusOnClick: Boolean;
begin
Result := False;
end;
function TcxCustomSpinButton.Increment(AButton: TcxSpinEditButton): Boolean;
begin
if Assigned(Associate) then SynchronizeEditValueFromAssociate;
Result := inherited Increment(AButton);
if not Result then
Exit;
KeyboardAction := True;
try
SynchronizeEditValue;
SetAssociateText(EditValue);
finally
KeyboardAction := False;
end;
end;
procedure TcxCustomSpinButton.SynchronizeEditValueFromAssociate;
var
FAssociateValue: TcxEditValue;
begin
if not((FAssociate is TCustomEdit) or (FAssociate is TcxCustomTextEdit)) then
Exit;
if ActiveProperties.ValueType = vtInt then
begin
if FAssociate is TcxCustomTextEdit then
FAssociateValue := cxStrToInt(TcxCustomTextEdit(FAssociate).Text, True)
else
FAssociateValue := cxStrToInt(TCustomEdit(FAssociate).Text, True);
end
else
begin
if FAssociate is TcxCustomTextEdit then
FAssociateValue := cxStrToFloat(TcxCustomTextEdit(FAssociate).Text, True)
else
FAssociateValue := cxStrToFloat(TCustomEdit(FAssociate).Text, True);
end;
if FAssociateValue <> Value then
Value := FAssociateValue;
end;
procedure TcxCustomSpinButton.SetSize;
var
AWidth: Integer;
begin
inherited SetSize;
if not AutoWidth then
Exit;
with ViewInfo do
begin
AWidth := (BorderRect.Right - BorderRect.Left) - (TextRect.Right - TextRect.Left);
if Painter <> nil then
Dec(AWidth)
else
if Length(ButtonsInfo) > 0 then
if not ButtonsInfo[0].Data.NativeStyle then
begin
AWidth := Succ(AWidth);
if Shadow then
AWidth := AWidth + cxContainerShadowWidth;
end;
end;
Width := AWidth;
end;
procedure TcxCustomSpinButton.Initialize;
begin
inherited Initialize;
FAutoWidth := True;
FSpinButtonControlHook := TcxSpinButtonControlHook.Create;
FSpinButtonControlHook.FParent := Self;
AutoSize := False;
TabStop := False;
end;
function TcxCustomSpinButton.InternalDoEditing: Boolean;
begin
Result := True;
end;
function TcxCustomSpinButton.GetActiveProperties: TcxCustomSpinButtonProperties;
begin
Result := TcxCustomSpinButtonProperties(InternalGetActiveProperties);
end;
function TcxCustomSpinButton.GetProperties: TcxCustomSpinButtonProperties;
begin
Result := TcxCustomSpinButtonProperties(FProperties);
end;
procedure TcxCustomSpinButton.SetAssociate(AValue: TWinControl);
var
I: Integer;
FCompoundControl: IcxCompoundControl;
function IsClass(ClassType: TClass; const Name: string): Boolean;
begin
Result := True;
while ClassType <> nil do
begin
if ClassType.ClassNameIs(Name) then Exit;
ClassType := ClassType.ClassParent;
end;
Result := False;
end;
begin
if AValue <> nil then
for I := 0 to Parent.ControlCount - 1 do {Is control already associated ?}
if (Parent.Controls[I] is TcxCustomSpinButton) and (Parent.Controls[I] <> Self) then
if TcxCustomSpinButton(Parent.Controls[I]).Associate = AValue then
raise EcxEditError.Create(AValue.Name +
cxGetResourceString(@scxUDAssociated) + Parent.Controls[I].Name);
if FAssociate <> nil then
begin
FSpinButtonControlHook.WinControl := nil;
FAssociate := nil;
end;
if (AValue <> nil) and (AValue.Parent = Self.Parent) and
not (AValue is TcxCustomSpinButton) and
not IsClass(AValue.ClassType, 'TcxDBTextEdit') and
not IsClass(AValue.ClassType, 'TcxDBMemo') and
not IsClass(AValue.ClassType, 'TDBTextEdit') and
not IsClass(AValue.ClassType, 'TDBMemo') then
begin
FAssociate := AValue;
if Supports(FAssociate, IcxCompoundControl, FCompoundControl) then
FSpinButtonControlHook.WinControl := FCompoundControl.ActiveControl
else
FSpinButtonControlHook.WinControl := FAssociate;
JoinToAssociate;
SetAssociateText(Value);
end;
end;
procedure TcxCustomSpinButton.SetAutoWidth(Value: Boolean);
begin
if FAutoWidth <> Value then
begin
FAutoWidth := Value;
if Value then
begin
CheckHandle;
ActiveProperties.ViewStyle := vsNormal;
end
else
ActiveProperties.ViewStyle := vsButtonsOnly;
if Value then
begin
SetSize;
ShortRefreshContainer(False);
end;
end;
end;
procedure TcxCustomSpinButton.SetProperties(Value: TcxCustomSpinButtonProperties);
begin
FProperties.Assign(Value);
end;
procedure TcxCustomSpinButton.JoinToAssociate;
begin
if FAssociate is TcxCustomEdit then
Font := TcxCustomEdit(FAssociate).Style.Font
else
Font := TWinControlAccess(FAssociate).Font;
Top := FAssociate.Top;
Left := FAssociate.Left + FAssociate.Width;
Height := FAssociate.Height;
end;
procedure TcxCustomSpinButton.SetAssociateText(const AValue: Variant);
begin
if (FAssociate = nil) or ((not (FAssociate is TcxCustomTextEdit)) and
(not (FAssociate is TCustomEdit))) then Exit;
if (FAssociate is TcxCustomTextEdit) then
TcxCustomTextEdit(FAssociate).Text := VarToStr(AValue)
else
if (FAssociate is TCustomEdit) then
TCustomEdit(FAssociate).Text := VarToStr(AValue);
end;
{ TcxSpinButton }
class function TcxSpinButton.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
Result := TcxSpinButtonProperties;
end;
function TcxSpinButton.GetActiveProperties: TcxSpinButtonProperties;
begin
Result := TcxSpinButtonProperties(InternalGetActiveProperties);
end;
function TcxSpinButton.GetProperties: TcxSpinButtonProperties;
begin
Result := TcxSpinButtonProperties(FProperties);
end;
procedure TcxSpinButton.SetProperties(Value: TcxSpinButtonProperties);
begin
FProperties.Assign(Value);
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?