CHexCalculator fixes + back out change to CNxtkWindow

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4761 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-05-22 21:01:42 +00:00
parent 654aadaed8
commit 8a19aea00b
4 changed files with 22 additions and 18 deletions

View File

@ -142,3 +142,5 @@
minimized. minimized.
* NxWM::CHexCalculator: Add a hexadecimal/decimal calculator * NxWM::CHexCalculator: Add a hexadecimal/decimal calculator
example. example.
* NXWidgets::CNxTkWindow: Back out height adjustment in the getSize()
method. The code was correct as it was before.

View File

@ -298,15 +298,9 @@ bool CNxTkWindow::getPosition(FAR struct nxgl_point_s *pos)
bool CNxTkWindow::getSize(FAR struct nxgl_size_s *size) bool CNxTkWindow::getSize(FAR struct nxgl_size_s *size)
{ {
// Get the size of the NXTK window (this will exclude the thickness of // Get the size of the NXTK window (this will exclude the thickness of
// the frame). // the frame and the height of the toolbar, if any).
bool ret = m_widgetControl->getWindowSize(size); return m_widgetControl->getWindowSize(size);
// Subtract the height of the toolbar (if any) to get the size of the
// drawable region in the window.
size->h -= m_toolbarHeight;
return ret;
} }
/** /**

View File

@ -87,9 +87,9 @@ namespace NxWM
struct nxgl_size_s m_textSize; /**< The size of the calculator textbox */ struct nxgl_size_s m_textSize; /**< The size of the calculator textbox */
struct nxgl_point_s m_keypadPos; /**< The position the calculator keypad */ struct nxgl_point_s m_keypadPos; /**< The position the calculator keypad */
struct nxgl_point_s m_textPos; /**< The position of the calculator textbox */ struct nxgl_point_s m_textPos; /**< The position of the calculator textbox */
uint64_t m_operand; /**< Previously entered operand */ int64_t m_operand; /**< Previously entered operand */
uint64_t m_accum; /**< The current accumulated value */ int64_t m_accum; /**< The current accumulated value */
uint64_t m_memory; /**< The current value in memory */ int64_t m_memory; /**< The current value in memory */
uint8_t m_pending; /**< The pending operation */ uint8_t m_pending; /**< The pending operation */
bool m_hexMode; /**< True if in hex mode */ bool m_hexMode; /**< True if in hex mode */

View File

@ -455,7 +455,7 @@ void CHexCalculator::setGeometry(void)
// Get the size of the text box. Same width as the m_keypad // Get the size of the text box. Same width as the m_keypad
m_textSize.w = m_keypadSize.w; m_textSize.w = m_keypadSize.w;
m_textSize.h = m_windowSize.h - NXWM_HEXCALCULATOR_NROWS * m_buttonSize.h; m_textSize.h = m_windowSize.h - m_keypadSize.h;
// Limit the height of the text box to twice the height of a button. // Limit the height of the text box to twice the height of a button.
@ -594,11 +594,11 @@ void CHexCalculator::updateText(void)
if (m_hexMode) if (m_hexMode)
{ {
snprintf(buffer, 24, "%16lx", m_accum); std::snprintf(buffer, 24, "%16llx", m_accum);
} }
else else
{ {
snprintf(buffer, 24, "%ld", m_accum); std::snprintf(buffer, 24, "%lld", m_accum);
} }
// setText will perform the redraw as well // setText will perform the redraw as well
@ -661,9 +661,17 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
// Values: {0-9, A-F} // Values: {0-9, A-F}
case KEY_VALUE: // Key is a value case KEY_VALUE: // Key is a value
{
if (m_hexMode)
{ {
m_accum <<= 4; m_accum <<= 4;
m_accum |= (uint64_t)g_keyDesc[index].value; m_accum |= (uint64_t)g_keyDesc[index].value;
}
else
{
m_accum *= 10;
m_accum += (uint64_t)g_keyDesc[index].value;
}
updateText(); updateText();
} }
break; break;
@ -766,7 +774,7 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
{ {
m_hexMode = false; m_hexMode = false;
labelKeypad(); labelKeypad();
m_keypad->redraw(); updateText();
} }
} }
break; break;
@ -777,7 +785,7 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
{ {
m_hexMode = true; m_hexMode = true;
labelKeypad(); labelKeypad();
m_keypad->redraw(); updateText();
} }
} }
break; break;