in src/CalcManager/UnitConverter.cpp [393:532]
void UnitConverter::SendCommand(Command command)
{
if (!CheckLoad())
{
return;
}
// TODO: Localization of characters
bool clearFront = false;
bool clearBack = false;
if (command != Command::Negate && m_switchedActive)
{
ClearValues();
m_switchedActive = false;
clearFront = true;
clearBack = false;
}
else
{
clearFront = (m_currentDisplay == L"0");
clearBack =
((m_currentHasDecimal && m_currentDisplay.size() - 1 >= MAXIMUMDIGITSALLOWED)
|| (!m_currentHasDecimal && m_currentDisplay.size() >= MAXIMUMDIGITSALLOWED));
}
switch (command)
{
case Command::Zero:
m_currentDisplay += L'0';
break;
case Command::One:
m_currentDisplay += L'1';
break;
case Command::Two:
m_currentDisplay += L'2';
break;
case Command::Three:
m_currentDisplay += L'3';
break;
case Command::Four:
m_currentDisplay += L'4';
break;
case Command::Five:
m_currentDisplay += L'5';
break;
case Command::Six:
m_currentDisplay += L'6';
break;
case Command::Seven:
m_currentDisplay += L'7';
break;
case Command::Eight:
m_currentDisplay += L'8';
break;
case Command::Nine:
m_currentDisplay += L'9';
break;
case Command::Decimal:
clearFront = false;
clearBack = false;
if (!m_currentHasDecimal)
{
m_currentDisplay += L'.';
m_currentHasDecimal = true;
}
break;
case Command::Backspace:
clearFront = false;
clearBack = false;
if ((m_currentDisplay.front() != L'-' && m_currentDisplay.size() > 1) || m_currentDisplay.size() > 2)
{
if (m_currentDisplay.back() == L'.')
{
m_currentHasDecimal = false;
}
m_currentDisplay.pop_back();
}
else
{
m_currentDisplay = L"0";
m_currentHasDecimal = false;
}
break;
case Command::Negate:
clearFront = false;
clearBack = false;
if (m_currentCategory.supportsNegative)
{
if (m_currentDisplay.front() == L'-')
{
m_currentDisplay.erase(0, 1);
}
else
{
m_currentDisplay.insert(0, 1, L'-');
}
}
break;
case Command::Clear:
clearFront = false;
clearBack = false;
ClearValues();
break;
case Command::Reset:
clearFront = false;
clearBack = false;
ClearValues();
ResetCategoriesAndRatios();
break;
default:
break;
}
if (clearFront)
{
m_currentDisplay.erase(0, 1);
}
if (clearBack)
{
m_currentDisplay.pop_back();
m_vmCallback->MaxDigitsReached();
}
Calculate();
}