Implements the calculator's standard arithmetic, keyboard input, memory, and undo/redo behavior.
Definition
Namespace:Telerik.WinControls.UI.Calculator
Assembly:Telerik.WinControls.UI.dll
Syntax:
public class StandardCalculatorCalculationBehavior
Inheritance: objectStandardCalculatorCalculationBehavior
Constructors
Creates the standard calculation state and its built-in operation collection for a calculator host.
public StandardCalculatorCalculationBehavior(ICalculatorElement calculatorElement)
The host that supplies culture information and receives display and memory updates.
Fields
Error text used when a calculation operation divides by zero.
public static string ErrorMessageCannotDivideByZero
Error text used for invalid-operation, range, or arithmetic failures during calculation.
public static string ErrorMessageInvalidOperation
Properties
Gets or sets the displayed value.
public virtual string DisplayedValue { get; set; }
Gets or sets the currently displayed error message.
public virtual string ErrorMessage { get; set; }
Gets or sets the input value.
public virtual decimal InputValue { get; set; }
Gets or sets a value indicating whether the input is updated.
public virtual bool IsInputUpdated { get; set; }
Gets or sets a value indicating whether the memory is updated.
public virtual bool IsMemoryUpdated { get; set; }
Gets or sets a value indicating whether an operation is executed.
public virtual bool IsOperationExecuted { get; set; }
Gets or sets the memory value.
public virtual decimal? MemoryValue { get; set; }
Gets or sets the available mathematical operations.
public virtual OperationsSource Operations { get; set; }
Gets or sets the pending operation.
public virtual Operation PendingOperation { get; set; }
RedoStack
Stack<StatusItem>
Gets or sets the redo stack.
public Stack<StatusItem> RedoStack { get; set; }
UndoStack
Stack<StatusItem>
Gets or sets the undo stack.
public Stack<StatusItem> UndoStack { get; set; }
Methods
Completes an unexecuted pending operation when necessary, then records the supplied operation for the next operand.
protected virtual void AddPendingBinaryOperation(Operation parameter)
The binary operation to make pending.
Resets the calculation values, pending operation, error, and input state; history and memory are not cleared here.
public virtual void ClearEverything()
Resets the displayed entry and clears the active operand or value without clearing memory or history.
protected virtual void ClearInput()
Clears both undo/redo stacks and the displayed calculation history.
public virtual void ClearStacksAndHistory()
Removes the final character from an actively edited entry, or resets that entry to zero, then updates its numeric value.
protected virtual void Delete()
Invokes a binary operation as a preflight check and stores calculator error text for supported arithmetic failures.
protected virtual void EnsureBinaryOpeartion(Func<decimal, decimal, decimal> operationBody, decimal firstArgument, decimal secondArgument)
The operation to validate.
firstArgumentdecimalThe first operand.
secondArgumentdecimalThe second operand.
Invokes a unary operation as a preflight check and stores calculator error text for supported arithmetic failures.
Executes the pending binary operation and clears the undo/redo history.
protected virtual void ExecuteBinaryOperation()
Maps a calculator button action to its calculation, entry, command, or memory operation.
protected virtual void ExecuteButtonAction(CalculatorAction calculatorAction)
The action to execute.
Executed once Ctrl modifier key and a key from the keyboard are pressed.
Executed once a key from the keyboard is pressed.
Executed once Shift modifier key and a key from the keyboard are pressed.
Converts a top-row or numeric-keypad digit key, or the decimal key, into calculator input.
protected virtual void ExecuteNumericKeyCommands(Keys keyCode)
The numeric key to process.
For a non-null binary operation, applies it to the current value and input; stores and displays the result on success, or displays the error message otherwise. Clears the input-edited state even when no operation is supplied.
protected virtual void ExecuteOperationLogic(Operation executedOperation)
The pending binary operation, if any.
Branches on pending-operation and execution state: one path records a zero value, while the other applies the supplied delegate to the input and value. Both paths update the display and history.
protected virtual void ExecutePercentOperation(Operation executedOperation)
The percentage operation to apply.
For a non-null unary operation, applies it to the active value or input; successful execution records history, while an error message is displayed instead of the result.
protected virtual void ExecuteUnaryOperation(Operation executedOperation)
The unary operation to apply.
Formats and pushes the new history entry, then restores the calculator state represented by it.
protected virtual void FormatStatus(Operation executedOperation, StatusItem currentStatusItem, bool isExecuted)
The operation represented by the entry.
currentStatusItemStatusItemThe status entry to format and push.
isExecutedbooltrue when the operation has already been executed.
Clears the stored memory value and hides its indicator through the host callback.
public virtual void MemoryClear()
Subtracts the displayed numeric value from memory, treating empty memory as zero.
protected virtual void MemoryMinus()
Adds the displayed numeric value to memory, using it as the initial memory value when memory is empty.
protected virtual void MemoryPlus()
Loads the stored memory value into the active operand, or loads zero when memory is empty.
protected virtual void MemoryRecall()
Stores the displayed value in memory when it parses using the calculator culture.
protected virtual void MemoryStore()
Formats a calculated value with the calculator culture and removes trailing fractional zeros.
Executed when a key down event is fired.
Executed when a key press event is fired.
Executed when a button is mouse up event is fired.
public virtual void OnButtonMouseUp(CalculatorButtonType buttonType, CalculatorAction buttonAction, MouseEventArgs e)
Dispatches a key according to whether Control, Shift, or no supported modifier is pressed.
Provides an override hook for state changes; the base implementation does not raise a notification.
protected virtual void OnPropertyChanged(string propertyName)
The name of the state property that changed.
Routes a key-down event to the calculator's key and modifier handling.
protected virtual void ProcessKeyDown(KeyEventArgs e)
The key and modifier data for the pressed key.
Provides a no-op key-press hook for derived behaviors that need to process character input.
protected virtual void ProcessKeyPress(KeyPressEventArgs e)
The character data for the pressed key.
Moves the latest redo entry back to the undo stack and restores its calculator state.
protected virtual void Redo()
Moves the latest undo entry to the redo stack and restores the preceding entry when one remains.
protected virtual void Undo()
Restores history and display, then restores operands according to the entry type; binary entries also restore the value and pending operation.
protected virtual void UpdateCurrentCalculatorStatus(StatusItem statusItem)
The status entry to restore.
Starts or extends the display entry, ignoring a duplicate decimal separator and limiting appended entries to 12 digits.
protected virtual void UpdateDisplayValueOnInput(string commandParameter)
The digit or decimal separator to display.
Routes incoming text to the active operand and clears prior history when starting a fresh value.
protected virtual void UpdateInput(string parameter)
The digit or decimal separator to enter.
Appends input to the pending-operation operand and updates it when the display parses using the calculator culture.
protected virtual void UpdateInputValueOnInputCommand(string commandParameter)
The digit or decimal separator to append.
Appends input to the current value and updates it when the display parses using the calculator culture.
protected virtual void UpdateValueOnInputCommand(string commandParameter)
The digit or decimal separator to append.