Hi there, I have derived my own class cMenuEditIpNumItem from cMenuEditItem. It displays 4 segments, seperated by dots.
My Problem is _SOMETIMES_ if kOk is pressed, the item remains in insert mode. If so, pressing kLeft, kRight release this behaviour.
Explanation: Edit mode are indicated with brakets:
"My IP Address 192.[168].10.3
int pos segment counter, range 0-4, greater than 0 means edit mode int digit digit of actual segment. unsinged char val[5] container for IP values. actuall 4 segments 1-4 are used. val[0] is not used. --- unsinged char will be used as unsigned int 0 -255.
char *value the actuall string displayed in menu item.
I have no Idea where the Problem coud be. Of course, the "ProccesKey"-Funktion gets the correct key code.
for the hole class see attachment.
------------------------------- Schnipp -------------------------------------------------------
OSState cMenuEditIpNumItem::ProcessKey(eKeys Key) {
eOSState state = cMenuEditItem::ProcessKey(Key);
Key = NORMALKEY(Key);
switch (Key) { case kBack: if (pos != 0) pos = 0; else return cMenuEditItem::ProcessKey(Key); break;
case kLeft: { if (pos > 1) pos--; if (pos == 0) pos = 4;
digit = 0; } break; case kRight: { if (pos < 4) pos++;
digit = 0; } break; case kUp: if (pos != 0) { val[pos]++; digit = 0; } else return cMenuEditItem::ProcessKey(Key); break; case kDown: if (pos != 0) { val[pos]--; digit = 0; } else return cMenuEditItem::ProcessKey(Key);
break; case k0 ... k9: { //dsyslog(DBG_PREFIX "k0 ... k9 digit %d val[%d] ", digit, pos); if (pos != 0) { if (digit > 2) // ??? { digit = 0; if (pos < 4) pos++; }
if (digit == 0) val[pos] = 0;
char tmp[4]; snprintf(tmp,4, "%d",val[pos]); //XXX ??? tmp[digit] = Key - k0 + '0'; digit++; tmp[digit] = '\0';
#if 0 dsyslog(DBG_PREFIX "digit %d val[%d] ", digit, pos); dsyslog(DBG_PREFIX "val %d tmp %s", val[pos], tmp); #endif
val[pos] = Validate(tmp);
#if 0 int len = strlen(tmp); dsyslog(DBG_PREFIX "key: k%d, val[pos]:%d, digit: %d pos %d, len:%d ", Key - k0, val[pos], digit, pos, len); dsyslog(DBG_PREFIX ">>> tmp %s ",tmp); #endif } Set(); } break;
case kOk: //if (pos < 1 ) //return cMenuEditItem::ProcessKey(kNone); pos = 0; digit = 0; return cMenuEditItem::ProcessKey(kNone); //break;
default: return cMenuEditItem::ProcessKey(kNone); }
Set(); return osContinue;
}
------------------------------- Schnapp -------------------------------------------------------
Thanx for Help Markus
Markus Hahn wrote:
Hi there, I have derived my own class cMenuEditIpNumItem from cMenuEditItem. It displays 4 segments, seperated by dots.
My Problem is _SOMETIMES_ if kOk is pressed, the item remains in insert mode. If so, pressing kLeft, kRight release this behaviour. ... case kOk: //if (pos < 1 ) //return cMenuEditItem::ProcessKey(kNone); pos = 0; digit = 0; return cMenuEditItem::ProcessKey(kNone); //break;
default: return cMenuEditItem::ProcessKey(kNone);
}
Set(); return osContinue;
}
You may want to try calling Set() after the modifications in 'case kOk', as in:
case kOk: //if (pos < 1 ) //return cMenuEditItem::ProcessKey(kNone); pos = 0; digit = 0; Set(); // <<<<<<<<<========== add this line return cMenuEditItem::ProcessKey(kNone); //break;
default: return cMenuEditItem::ProcessKey(kNone); }
Set(); return osContinue; }
(original code re-indented for readability ;-).
Klaus