home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - NUMBER.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_win.hpp"
- #include <mem.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- int NUM_STATE::operator == (NUM_STATE& rightOperand)
- {
- return (memcmp(this, &rightOperand, sizeof(NUM_STATE)) == 0);
- }
-
- int NUM_STATE::operator != (NUM_STATE& rightOperand)
- {
- return (memcmp(this, &rightOperand, sizeof(NUM_STATE)) != 0);
- }
-
- UIW_NUMBER::~UIW_NUMBER()
- {
- if (!FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
- delete value;
- if (range)
- delete range;
- }
-
- void UIW_NUMBER::BackspaceKey()
- {
- if (state.cursor > 0)
- {
- state.cursor--;
- DeleteChar();
- }
- }
-
- int UIW_NUMBER::CalcLeading(int width, char *dText)
- {
- int maxWidth = Min(maxTextLen - 1, width - 1);
- int textLen = strlen(dText);
- int leading = 0;
- if (woFlags & WOF_JUSTIFY_CENTER)
- leading = Min((maxWidth - textLen) / 2, width);
- else if (woFlags & WOF_JUSTIFY_RIGHT)
- leading = Min(maxWidth - textLen, width);
- if (leading < 0)
- leading = 0;
- return leading;
- }
-
- void UIW_NUMBER::Constructor(void *a_value, int width, USHORT flags,
- char *a_range, void (UIW_NUMBER::*a_BinaryToAscii)(),
- void (UIW_NUMBER::*a_AsciiToBinary)(),
- int (UIW_NUMBER::*a_ValidNumber)(),
- int (*a_Validate)(void *object, int ccode))
- {
- windowID[0] = ID_NUMBER;
- windowID[1] = ID_STRING;
- search.type = ID_NUMBER;
-
- if (type < NUM_FLOAT)
- flags &= ~NMF_SCIENTIFIC; // Scientific not allowed for whole nums.
- if ( FlagSet(flags, NMF_SCIENTIFIC) )
- {
- flags |= NMF_DECIMAL_FLOAT; // Fixed-point not allowed w/scientific.
- flags &= ~NMF_COMMAS; // Nor are commas.
- }
- BinaryToAscii = a_BinaryToAscii;
- AsciiToBinary = a_AsciiToBinary;
- ValidNumber = a_ValidNumber;
- Validate = a_Validate;
- if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
- value = a_value;
- else
- {
- value = new double; // NOTE: This doesn't suck floating point code.
- if (a_value)
- memcpy(value, a_value, sizeof(double));
- else
- woStatus |= WOS_UNANSWERED;
- }
- ui_getcountryinfo(); // Insure we have country info.
- insertMode = TRUE;
- decimal = flags & NMF_DECIMAL_FLAGS;
- if ((type >= NUM_FLOAT && decimal == 0) || decimal == NMF_DECIMAL_FLAGS)
- decimal = 0xFF;
- else if (decimal)
- decimal--;
- // Disallow floating decimal point with whole number types.
- if (type < NUM_FLOAT && decimal == 0xFF)
- decimal = 0;
- nmFlags = flags;
- range = (a_range) ? ui_strdup(a_range) : 0;
- state.isMarked = FALSE;
- maxTextLen = Min(width + 1, NUM_MAX_TEXT_LEN);
- }
-
- void UIW_NUMBER::CopyBlock()
- {
- char dText[40];
- int cursorColumn;
-
- Expand(dText, &cursorColumn);
-
- pasteLength = strlen(dText);
- if (pasteBuffer)
- delete pasteBuffer;
- pasteBuffer = new char[pasteLength];
- memcpy(pasteBuffer, dText, pasteLength);
-
- state.isMarked = FALSE;
- }
-
- void UIW_NUMBER::CutBlock()
- {
- pasteLength = ui_strlen(state.text);
- if (pasteBuffer)
- delete pasteBuffer;
- pasteBuffer = new char[pasteLength];
- memcpy(pasteBuffer, state.text, pasteLength);
-
- woStatus |= (WOS_CHANGED | WOS_NO_AUTO_CLEAR);
- CopyBlock();
- state.text[0] = '\0';
- state.cursor = 0;
- }
-
- void UIW_NUMBER::DataSet(void *newValue)
- {
- if (newValue)
- {
- if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
- value = newValue;
- else
- memcpy(value, newValue, sizeof(double));
- }
- UI_WINDOW_OBJECT::Redisplay(FALSE);
- }
-
- void UIW_NUMBER::DeleteChar()
- {
- woStatus |= (WOS_CHANGED | WOS_NO_AUTO_CLEAR);
- if (state.text[state.cursor] == 'E') // Delete exponent.
- state.text[state.cursor] = '\0';
- else
- memmove(state.text + state.cursor, state.text + state.cursor + 1,
- strlen(state.text + state.cursor) );
- }
-
- int UIW_NUMBER::Event(const UI_EVENT &event)
- {
- int viewOnly = (FlagSet(woFlags, WOF_VIEW_ONLY) ||
- FlagSet(woAdvancedStatus, WOAS_TOO_SMALL)) ? TRUE : FALSE;
- int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_STRING);
- if (ccode == S_CREATE)
- {
- UI_WINDOW_OBJECT::Event(event);
- int width = (relative.right + 1 - relative.left) / display->cellWidth;
- if (FlagSet(woFlags, WOF_BORDER))
- if (display->isText)
- width -= 2;
- else
- width -= 1;
- maxTextLen = Min(width + 1, NUM_MAX_TEXT_LEN);
-
- FormatNumber();
- }
- short cellWidth = display->cellWidth;
- UI_REGION region;
- UI_WINDOW_OBJECT::Border(0, region, 0);
- short width = (region.right + 1 - region.left) / cellWidth;
- USHORT key;
- NUM_STATE oldStateInfo = state;
- UCHAR forceDisplay = FALSE;
- UI_PALETTE *palette;
- int isCurrent = woStatus & WOS_CURRENT;
- UCHAR reDisplay = TRUE;
- UCHAR displayCheckRegion = FALSE;
- int needValidate = NeedsValidation();
-
- if (!isCurrent)
- state.isMarked = FALSE;
- switch (ccode)
- {
- case E_KEY:
- key = event.rawCode & 0xFF;
- if ((key == '\b' || key >= ' ') && !viewOnly)
- {
- if (key == '\b')
- BackspaceKey();
- else
- RegularKey(key);
- }
- else
- {
- reDisplay = FALSE;
- ccode = S_UNKNOWN;
- }
- break;
-
- case L_LEFT:
- if (state.cursor > 0)
- {
- state.cursor--;
- woStatus |= WOS_NO_AUTO_CLEAR;
- }
- else
- ccode = S_UNKNOWN;
- break;
-
- case L_RIGHT:
- if (state.text[state.cursor])
- {
- state.cursor++;
- woStatus |= WOS_NO_AUTO_CLEAR;
- }
- else
- ccode = S_UNKNOWN;
- break;
-
- case L_BOL:
- state.cursor = 0;
- woStatus |= WOS_NO_AUTO_CLEAR;
- break;
-
- case L_EOL:
- state.cursor = ui_strlen(state.text);
- woStatus |= WOS_NO_AUTO_CLEAR;
- break;
-
- case L_DELETE:
- if (!viewOnly)
- {
- if (state.isMarked)
- CutBlock();
- else if (state.text[state.cursor])
- DeleteChar();
- }
- break;
-
- case L_INSERT_TOGGLE:
- insertMode = !insertMode;
- woStatus |= WOS_NO_AUTO_CLEAR;
- forceDisplay = TRUE;
- break;
-
- case L_MARK:
- state.isMarked = !state.isMarked;
- break;
-
- case L_VIEW:
- eventManager->DeviceState(event.type, DM_EDIT);
- break;
-
- case L_CUT:
- if (!viewOnly)
- {
- if (state.isMarked)
- CutBlock();
- else
- reDisplay = FALSE;
- break;
- }
- // Continue to L_COPY_MARK if view only field.
-
- case L_COPY_MARK:
- if (state.isMarked)
- CopyBlock();
- else
- reDisplay = FALSE;
- break;
-
- case L_CUT_PASTE:
- if (state.isMarked)
- {
- if (viewOnly)
- CopyBlock();
- else
- CutBlock();
- break;
- }
- // Continue to L_PASTE.
-
- case L_PASTE:
- if (!viewOnly)
- {
- if (event.type != E_KEY)
- SetCursor((event.position.column - region.left) / cellWidth, width);
- PasteBlock();
- }
- break;
-
- case L_CONTINUE_MARK:
- if (markColumn != (event.position.column - region.left) / cellWidth)
- state.isMarked = TRUE;
- break;
-
- case L_BEGIN_MARK:
- state.isMarked = FALSE;
- markColumn = (event.position.column - region.left) / cellWidth;
- SetCursor(markColumn, width);
- forceDisplay = TRUE; // Force cursor to get updated.
- break;
-
- case S_CURRENT:
- switchedToReplaceMode = FALSE;
- if (needValidate)
- (*Validate)(this, ccode);
-
- // Clear the WOS_UNANSWERED and WOS_NO_AUTO_CLEAR bits
- woStatus &= ~(WOS_UNANSWERED | WOS_NO_AUTO_CLEAR);
- isCurrent = TRUE;
- palette = UI_WINDOW_OBJECT::LogicalPalette(ccode);
- displayCheckRegion = TRUE;
- state.cursor = 0;
- break;
-
- case S_DISPLAY_ACTIVE:
- palette = UI_WINDOW_OBJECT::LogicalPalette(ccode);
- displayCheckRegion = TRUE;
- break;
-
- case S_NON_CURRENT:
- if (!FlagSet(woStatus, WOS_UNANSWERED))
- {
- if ((this->*ValidNumber)())
- (this->*AsciiToBinary)();
- else
- ccode = S_ERROR;
- if (ccode == S_ERROR ||
- (needValidate && (*Validate)(this, ccode) != 0))
- {
- ccode = S_ERROR;
- woStatus |= WOS_INVALID;
- reDisplay = FALSE;
- break;
- }
- }
- FormatNumber(); // Re-format from the binary.
- woStatus &= ~WOS_INVALID;
- // Continue to S_DISPLAY_INACTIVE.
-
- case S_DISPLAY_INACTIVE:
- state.isMarked = FALSE;
- palette = UI_WINDOW_OBJECT::LogicalPalette(ccode);
- displayCheckRegion = TRUE;
- break;
-
- case S_ERROR_RESPONSE:
- forceDisplay = TRUE;
- woStatus |= event.rawCode;
- if (event.rawCode == WOS_UNANSWERED)
- FormatNumber();
- break;
-
- default:
- ccode = UI_WINDOW_OBJECT::Event(event);
- reDisplay = FALSE;
- break;
- }
-
- if (displayCheckRegion)
- {
- forceDisplay = TRUE;
- if (!UI_WINDOW_OBJECT::NeedsUpdate(event, ccode) &&
- oldStateInfo == state)
- reDisplay = FALSE;
- else
- UI_WINDOW_OBJECT::Border(ccode, region, palette);
- }
-
- char dText[40];
- int cursorColumn;
- if (reDisplay)
- {
- FixText();
- Expand(dText, &cursorColumn);
- int maxWidth = Min(maxTextLen - 1, width - 1);
- if (strlen(dText) > maxWidth &&
- (oldStateInfo != state || ccode == E_KEY))
- _errorSystem->Beep();
- if (forceDisplay || oldStateInfo != state)
- {
- Redisplay(region, width, dText);
- UpdateCursor(region, width, dText, cursorColumn);
- }
- }
- else if (ccode == S_CURRENT)
- {
- Expand(dText, &cursorColumn);
- UpdateCursor(region, width, dText, cursorColumn);
- }
-
- // Return the control code.
- return (ccode);
- }
-
- void UIW_NUMBER::Expand(char *expText, int *cursorColumn)
- {
- char *currencyFmt;
- char newText[40];
-
- newText[0] = '\0';
- if (FlagSet(nmFlags, NMF_CURRENCY))
- {
- currencyFmt = (_countryInfo.co_currstyle < 2 ? "%s%s" : "%s %s");
- if ( _countryInfo.co_currstyle == 0 ||
- _countryInfo.co_currstyle == 2 )
- sprintf(newText, currencyFmt, _countryInfo.co_curr, state.text);
- else
- sprintf(newText, currencyFmt, state.text, _countryInfo.co_curr);
- }
- else
- strcpy(newText, state.text);
- if (FlagSet(nmFlags, NMF_PERCENT))
- strcat(newText, "%");
- UIW_NUMBER::PlaceDecimal(newText, decimal);
- if (FlagSet(nmFlags, NMF_COMMAS))
- UIW_NUMBER::PlaceCommas(newText);
- if (state.isNegative)
- UIW_NUMBER::FixNegative(newText, nmFlags & NMF_CREDIT);
- strcpy(expText, newText);
- int match = 0;
- for (int index = 0; index <= state.cursor && newText[match]; index++)
- {
- while (newText[match] != state.text[index] && newText[match] &&
- newText[match] != '%' && newText[match] != ')')
- match++;
- if (index < state.cursor && newText[match] == state.text[index])
- match++;
- }
- *cursorColumn = match;
- }
-
- void UIW_NUMBER::FixNegative(char *buff, int credit)
- {
- memmove(buff + 1, buff, strlen(buff) + 1);
- *buff = credit ? '(' : '-';
- if (credit)
- strcat(buff, ")");
- }
-
- void UIW_NUMBER::FixText()
- {
- char *text = state.text;
- if (text[0] == '\0')
- {
- strcpy(text, "0");
- state.cursor = 1;
- }
- if (decimal && decimal != 0xFF)
- {
- while (strlen(text) <= decimal)
- {
- memmove(text + 1, text, strlen(text) + 1);
- state.cursor++;
- text[0] = '0';
- }
- }
- // Strip leading zeroes, but only if we have enough decimal places.
- while (text[0] == '0' && isdigit(text[1]) )
- {
- if (decimal && decimal != 0xFF && strlen(text) <= decimal + 1)
- break;
- memmove(text, text + 1, strlen(text));
- if (state.cursor)
- state.cursor--;
- }
- }
-
- void UIW_NUMBER::FormatNumber()
- {
- (this->*BinaryToAscii)();
- if (state.text[0] == '-')
- {
- strcpy(state.text, state.text + 1);
- state.isNegative = TRUE;
- }
- else
- state.isNegative = FALSE;
- state.cursor = 0; // Default to cursor at beginning.
- FixText();
- }
-
- void UIW_NUMBER::PasteBlock()
- {
- char *src = pasteBuffer;
- int src_len = pasteLength;
-
- if (pasteBuffer && !state.isMarked)
- {
- woStatus |= (WOS_CHANGED | WOS_NO_AUTO_CLEAR);
- state.cursor = 0;
- while (state.cursor < maxTextLen - 1 && src_len)
- {
- if (UIW_NUMBER::ValidNumChar(*src, decimal))
- state.text[state.cursor++] = *src;
- src++;
- src_len--;
- }
- state.text[state.cursor] = '\0';
- state.cursor = 0;
- }
- }
-
- void UIW_NUMBER::PlaceCommas(char *buff)
- {
- char tempBuff[40];
- char *tempPtr = tempBuff;
- char *buffPtr = buff;
- int digits;
-
- while (*buffPtr)
- {
- if (*buffPtr != _countryInfo.co_thsep[0])
- *tempPtr++ = *buffPtr;
- buffPtr++;
- }
- *tempPtr = '\0';
- tempPtr = strrchr(tempBuff, _countryInfo.co_desep[0]);
- if (!tempPtr)
- tempPtr = strchr(tempBuff, '\0');
- while (tempPtr > &tempBuff[0] && !isdigit(*(tempPtr - 1)))
- tempPtr--;
- digits = 0;
- while (tempPtr > &tempBuff[0] && isdigit(*(tempPtr - 1)))
- {
- digits++;
- tempPtr--;
- if (digits % 3 == 0 && tempPtr > &tempBuff[0] &&
- isdigit(*(tempPtr - 1)))
- {
- memmove(tempPtr + 1, tempPtr, strlen(tempPtr) + 1);
- *tempPtr = _countryInfo.co_thsep[0];
- }
- }
- tempPtr = strrchr(tempBuff, _countryInfo.co_desep[0]);
- if (tempPtr && _countryInfo.co_thsep[0] != ',')
- {
- tempPtr++;
- digits = 0;
- while (isdigit(*tempPtr))
- {
- digits++;
- tempPtr++;
- if ( digits % 3 == 0 && isdigit(*(tempPtr + 1)) )
- {
- memmove(tempPtr + 1, tempPtr, strlen(tempPtr) + 1);
- *tempPtr++ = _countryInfo.co_thsep[0];
- }
- }
- }
- strcpy(buff, tempBuff);
- }
-
- void UIW_NUMBER::PlaceDecimal(char *buff, int decimal)
- {
- char tempBuff[40];
- char *tempPtr = tempBuff;
- char *buffPtr = buff;
-
- if (decimal != 0xFF)
- {
- while (*buffPtr)
- {
- if (*buffPtr != _countryInfo.co_desep[0])
- *tempPtr++ = *buffPtr;
- buffPtr++;
- }
- *tempPtr = '\0';
- if (decimal)
- {
- while (tempPtr > &tempBuff[0] && !isdigit(*(tempPtr - 1)))
- tempPtr--;
- while (tempPtr > &tempBuff[0] && decimal)
- {
- if (isdigit(*(tempPtr - 1)))
- decimal--;
- else if (*(tempPtr - 1) != _countryInfo.co_thsep[0])
- break;
- tempPtr--;
- }
- if (decimal || tempPtr == &tempBuff[0] ||
- (tempPtr > &tempBuff[0] && !isdigit(*(tempPtr - 1))))
- {
- memmove(tempPtr + decimal + 2, tempPtr, strlen(tempPtr) + 1);
- *tempPtr = '0';
- *(tempPtr + 1) = _countryInfo.co_desep[0];
- if (decimal)
- memset(tempPtr + 2, '0', decimal);
- }
- else
- {
- memmove(tempPtr + 1, tempPtr, strlen(tempPtr) + 1);
- *tempPtr = _countryInfo.co_desep[0];
- }
- }
- strcpy(buff, tempBuff);
- }
- }
-
- void UIW_NUMBER::Redisplay(UI_REGION ®ion, int width, char *dText)
- {
- UI_PALETTE *palette = lastPalette;
- // Pre-fill for graphics or unanswered field.
- if (!display->isText || (woStatus & WOS_UNANSWERED))
- display->Rectangle(screenID, region, palette, 0, TRUE);
- int textLen = strlen(dText);
- int leading = CalcLeading(width, dText);
- textLen = Min(textLen, width - leading);
- int trailing = width - textLen - leading;
- int textHeight = display->TextHeight("W");
- int bottom = region.top + textHeight - 1;
- if (bottom <= region.bottom && (woStatus & WOS_UNANSWERED) == 0)
- {
- if (!display->isText) // Center text vertically.
- {
- int vertRoom = region.bottom + 1 - region.top - textHeight;
- region.top += (vertRoom + 1) / 2;
- region.bottom += (vertRoom + 1) / 2;
- }
- if (leading && display->isText)
- display->Rectangle(screenID, region.left, region.top,
- region.left + leading - 1, region.bottom, palette, 0, TRUE);
- display->Text(screenID, region.left + leading * display->cellWidth,
- region.top, dText, palette, textLen, FALSE);
- if (trailing && display->isText)
- display->Rectangle(screenID, region.left + leading + textLen,
- region.top, region.left + leading + textLen + trailing - 1,
- region.bottom, palette, 0, TRUE);
- if (state.isMarked)
- display->Text(screenID, region.left, region.top, NULL,
- _xorPalette, width, TRUE, TRUE);
- }
- }
-
- void UIW_NUMBER::RegularChar(USHORT key)
- {
- int autoClear = FALSE;
- if (FlagSet(woFlags, WOF_AUTO_CLEAR) &&
- !FlagSet(woStatus, WOS_NO_AUTO_CLEAR))
- {
- autoClear = TRUE;
- int index = state.cursor;
- while (index)
- {
- index--;
- if (state.text[index] != '0')
- autoClear = FALSE;
- }
- }
- if (autoClear)
- {
- state.text[0] = key;
- state.text[1] = '\0';
- state.cursor = 1;
- }
- else
- {
- if (!insertMode && state.text[state.cursor])
- DeleteChar(); // Replace mode - delete and then insert.
- if (ui_strlen(state.text) < maxTextLen - 1)
- {
- memmove(state.text + state.cursor + 1, state.text + state.cursor,
- strlen(state.text + state.cursor) + 1);
- state.text[state.cursor++] = key;
- }
- if (state.text[state.cursor] == '\0' && switchedToReplaceMode)
- {
- insertMode = TRUE;
- switchedToReplaceMode = FALSE;
- }
- }
- }
-
- void UIW_NUMBER::RegularKey(USHORT key)
- {
- char valid_list[80];
-
- sprintf(valid_list, "0123456789%c",
- decimal ? _countryInfo.co_desep[0] : '\0');
- if (!FlagSet(nmFlags, NMF_UNSIGNED))
- strcat(valid_list, "-+");
- if (FlagSet(nmFlags, NMF_SCIENTIFIC))
- strcat(valid_list, "Ee");
- if (strchr(valid_list, key))
- {
- if (key == _countryInfo.co_desep[0])
- {
- if (decimal == 0xFF) // Floating decimal - replace the point.
- {
- char *exp = strchr(state.text, 'E');
- if (!exp || exp >= state.text + state.cursor)
- { // Don't allow decimal inside the exponent.
- char *dec = strchr(state.text, _countryInfo.co_desep[0]);
- if (dec && (insertMode || state.text[state.cursor] != *dec))
- {
- memmove(dec, dec + 1, strlen(dec));
- if (state.text + state.cursor > dec)
- state.cursor--;
- }
- RegularChar(key);
- }
- }
- else // Fixed decimal.
- {
- int nullPos = ui_strlen(state.text);
- int position = (int)(nullPos - state.cursor);
- if (position < decimal)
- {
- int extra = decimal - position;
- memset(state.text + nullPos, '0', extra);
- state.text[nullPos + extra] = '\0';
- }
- else if (position > decimal)
- {
- int clip = position - decimal;
- state.text[nullPos - clip] = '\0';
- }
- if (insertMode)
- {
- insertMode = FALSE;
- switchedToReplaceMode = TRUE;
- }
- }
- }
- else if (key == '-' || key == '+')
- {
- char *exp;
- if (FlagSet(nmFlags, NMF_SCIENTIFIC) &&
- (exp = strchr(state.text, 'E')) &&
- state.text + state.cursor >= exp)
- {
- exp++; // Point just after the 'E'.
- if (*exp == '-')
- {
- memmove(exp, exp + 1, strlen(exp));
- if (state.text + state.cursor >= exp + 1)
- state.cursor--;
- }
- else if (key == '-')
- {
- memmove(exp + 1, exp, strlen(exp) + 1);
- *exp = '-';
- if (state.text + state.cursor >= exp)
- state.cursor++;
- }
- }
- else
- state.isNegative = key == '+' ? FALSE : !state.isNegative;
- }
- else if (toupper(key) == 'E')
- {
- char *exp = strchr(state.text, 'E');
- if (exp)
- {
- state.cursor = (UCHAR)(exp + 1 - state.text);
- if (state.text[state.cursor] == '-')
- state.cursor++;
- }
- else
- {
- state.cursor = ui_strlen(state.text);
- RegularChar('E');
- }
- }
- else // digit
- RegularChar(key);
- woStatus |= (WOS_CHANGED | WOS_NO_AUTO_CLEAR);
- }
- }
-
- void UIW_NUMBER::SetCursor(int column, int width)
- {
- char expandedText[40];
- int cursorColumn;
- int maxWidth = Min(maxTextLen - 1, width - 1);
-
- Expand(expandedText, &cursorColumn);
- int textLen = strlen(expandedText);
- int leading = 0;
- if (FlagSet(woFlags, WOF_JUSTIFY_CENTER))
- leading = Min((maxWidth - textLen) / 2, width);
- else if (FlagSet(woFlags, WOF_JUSTIFY_RIGHT))
- leading = Min(maxWidth - textLen, width);
- if (leading < 0)
- leading = 0;
- char *screen_cursor = expandedText + column - leading;
- char *expNull = strchr(expandedText, '\0');
- if (screen_cursor > expNull)
- screen_cursor = expNull;
- int match = 0;
- for (char *cp = expandedText; cp < screen_cursor && state.text[match]; cp++)
- if (strchr(state.text, *cp))
- match++;
- state.cursor = match;
- }
-
- void UIW_NUMBER::UpdateCursor(UI_REGION ®ion, int width, char *dText,
- int cursorColumn)
- {
- int leading = CalcLeading(width, dText);
- if (FlagSet(woStatus, WOS_CURRENT) && (leading + cursorColumn < width))
- {
- int trueColumn =
- region.left + (leading + cursorColumn) * display->cellWidth;
- if (!FlagSet(woFlags, WOF_VIEW_ONLY) &&
- !FlagSet(woAdvancedStatus, WOAS_TOO_SMALL) && trueColumn >= 0 &&
- trueColumn < display->columns && region.top >= 0 &&
- region.top < display->lines)
- {
- eventManager->DevicePosition(E_CURSOR, trueColumn, region.top);
- eventManager->DeviceState(E_CURSOR, ((insertMode) ? DC_INSERT : DC_OVERTYPE));
- }
- }
- }
-
- int UIW_NUMBER::ValidNumChar(char val, int decimalPoint)
- {
- if (isdigit(val) ||
- (decimalPoint == 0xFF && val == _countryInfo.co_desep[0]))
- return (TRUE);
- return (FALSE);
- }
-
-