Ejemplo n.º 1
0
void UiNumericDisplay::removeChar1(){
	if(_l1str.Length() == 1){
		setText1(L"0");
		_isEmpty = true;
		return;
	}
	_l1str = _l1str.SubStr(0,_l1str.Length() - 1);
}
Ejemplo n.º 2
0
void UiNumericDisplay::addChar1(wchar_t chCharCode){
	//only accept 0-9,dot,-
	int inputlen = _l1str.Length();
	//排除连续输入0的问题
	if(inputlen == 1 && _l1str == L"0" && chCharCode == '0') return;
	//排除在输入运算符后输入dot的问题
	if(_isEmpty && chCharCode == '.'){
		_isEmpty = false;
		_l1str = L"0.";
		_dotPos = 2;
		return;
	}
	//only 2 digital after dot
	if(chCharCode != 0x08 && _dotPos != 0 && (inputlen - _dotPos > 1)) return;
	//only 8 digital before dot
	if(chCharCode != 0x08 &&  chCharCode != '.' && _dotPos == 0 && inputlen > 8) return;


	if(chCharCode < '0' || chCharCode > '9'){
		if(chCharCode != '.' && chCharCode != '-' && chCharCode != 0x08){
			return;
		}
		if(chCharCode == '-'){
			if(_isEmpty) return;
			if(_l1str.C_Str()[0] == '-'){
				_l1str = _l1str.SubStr(1,_l1str.Length() - 1);
			}else{
				CMzString Ssign = L"-";
				_l1str = Ssign + _l1str;
			}
			return;
		}
		if(chCharCode == '.'){
			if(_dotPos != 0){
				return;
			}else{
				_dotPos = inputlen + 1;
				chCharCode = '.';
			}
		}
		if(chCharCode == 0x08){ //backspace
			if(inputlen == _dotPos){
				_dotPos = 0;
			}
			removeChar1();
			return;
		}
	}
	addChar(chCharCode,_l1str);
	if(_isEmpty) _isEmpty = false;
}