Replace jwidget_check_underscored with Widget::isScancodeMnemonic().

This commit is contained in:
David Capello 2012-04-15 15:43:07 -03:00
parent f2f6ba9fca
commit 8a1295c025
4 changed files with 30 additions and 37 deletions

View File

@ -103,9 +103,9 @@ bool ButtonBase::onProcessMessage(Message* msg)
return true;
}
}
/* the underscored letter with Alt */
// Check if the user pressed mnemonic.
if ((msg->any.shifts & KB_ALT_FLAG) &&
(jwidget_check_underscored(this, msg->key.scancode))) {
(isScancodeMnemonic(msg->key.scancode))) {
this->setSelected(true);
return true;
}
@ -130,7 +130,7 @@ bool ButtonBase::onProcessMessage(Message* msg)
if ((this->hasFocus() &&
(msg->key.scancode == KEY_SPACE)) ||
((msg->any.shifts & KB_ALT_FLAG) &&
(jwidget_check_underscored(this, msg->key.scancode)))) {
(isScancodeMnemonic(msg->key.scancode)))) {
if (m_behaviorType == JI_CHECK) {
// Swap the select status
this->setSelected(!this->isSelected());

View File

@ -1225,12 +1225,8 @@ static MenuItem* check_for_letter(Menu* menu, int ascii)
continue;
MenuItem* menuitem = static_cast<MenuItem*>(child);
if (menuitem->hasText())
for (int c=0; menuitem->getText()[c]; c++)
if ((menuitem->getText()[c] == '&') && (menuitem->getText()[c+1] != '&'))
if (tolower(ascii) == tolower(menuitem->getText()[c+1]))
return menuitem;
if (menuitem->getMnemonicChar() == tolower(ascii))
return menuitem;
}
return NULL;
}

View File

@ -216,12 +216,12 @@ void *jwidget_get_data(JWidget widget, int type)
/**********************************************************************/
/* main properties */
int Widget::getType()
int Widget::getType() const
{
return this->type;
}
const char *Widget::getName()
const char *Widget::getName() const
{
return this->name;
}
@ -1409,16 +1409,20 @@ bool Widget::hasCapture()
return (this->flags & JI_HASCAPTURE) ? true: false;
}
/**********************************************************************/
/* miscellaneous */
bool jwidget_check_underscored(JWidget widget, int scancode)
int Widget::getMnemonicChar() const
{
int c, ascii;
if (hasText()) {
const char* text = getText();
for (int c=0; text[c]; ++c)
if ((text[c] == '&') && (text[c+1] != '&'))
return tolower(text[c+1]);
}
return 0;
}
ASSERT_VALID_WIDGET(widget);
ascii = 0;
bool Widget::isScancodeMnemonic(int scancode) const
{
int ascii = 0;
if (scancode >= KEY_0 && scancode <= KEY_9)
ascii = '0' + (scancode - KEY_0);
else if (scancode >= KEY_A && scancode <= KEY_Z)
@ -1426,16 +1430,7 @@ bool jwidget_check_underscored(JWidget widget, int scancode)
else
return false;
if (widget->hasText()) {
const char* text = widget->getText();
for (c=0; text[c]; c++)
if ((text[c] == '&') && (text[c+1] != '&'))
if (ascii == tolower(text[c+1]))
return true;
}
return false;
return (getMnemonicChar() == ascii);
}
/**********************************************************************/

View File

@ -75,10 +75,6 @@ void jwidget_signal_off(JWidget widget);
bool jwidget_emit_signal(JWidget widget, int signal_num);
/* miscellaneous */
bool jwidget_check_underscored(JWidget widget, int scancode);
//////////////////////////////////////////////////////////////////////
class Widget : public Component
@ -137,8 +133,8 @@ public:
// main properties
int getType();
const char* getName();
int getType() const;
const char* getName() const;
int getAlign() const;
void setName(const char* name);
@ -146,7 +142,7 @@ public:
// text property
bool hasText() { return flags & JI_NOTEXT ? false: true; }
bool hasText() const { return flags & JI_NOTEXT ? false: true; }
const char* getText() const { return m_text.c_str(); }
int getTextInt() const;
@ -309,7 +305,7 @@ public:
void setPreferredSize(int fixedWidth, int fixedHeight);
// ===============================================================
// FOCUS & MOUSE
// MOUSE, FOCUS & KEYBOARD
// ===============================================================
void requestFocus();
@ -321,6 +317,12 @@ public:
bool hasMouseOver();
bool hasCapture();
// Returns lower-case letter that represet the mnemonic of the widget
// (the underscored character, i.e. the letter after & symbol).
int getMnemonicChar() const;
bool isScancodeMnemonic(int scancode) const;
protected:
// ===============================================================