/* Initialise an edit box widget */ void W_EDITBOX::initialise() { state = WEDBS_FIXED; printStart = 0; iV_SetFont(FontID); fitStringStart(); }
void W_EDITBOX::initialise() { state = WEDBS_FIXED; printStart = 0; maxStringSize = EB_MAX_STRINGSIZE; fitStringStart(); }
/* Respond to loss of focus */ void W_EDITBOX::focusLost(W_SCREEN *psScreen) { ASSERT(!(state & WEDBS_DISABLE), "editBoxFocusLost: disabled edit box" ); /* Stop editing the widget */ state = WEDBS_FIXED; printStart = 0; fitStringStart(); widgSetReturn(psScreen, this); }
/* Respond to loss of focus */ void W_EDITBOX::focusLost() { ASSERT(!(state & WEDBS_DISABLE), "editBoxFocusLost: disabled edit box"); /* Stop editing the widget */ state = WEDBS_FIXED; printStart = 0; fitStringStart(); screenPointer->setReturn(this); dirty = true; }
void W_EDITBOX::run(W_CONTEXT *psContext) { /* Note the edit state */ unsigned editState = state & WEDBS_MASK; /* Only have anything to do if the widget is being edited */ if ((editState & WEDBS_MASK) == WEDBS_FIXED) { return; } /* If there is a mouse click outside of the edit box - stop editing */ int mx = psContext->mx; int my = psContext->my; if (mousePressed(MOUSE_LMB) && (mx < x || mx > x + width || my < y || my > y + height)) { screenClearFocus(psContext->psScreen); return; } /* note the widget state */ iV_SetFont(FontID); /* Loop through the characters in the input buffer */ bool done = false; utf_32_char unicode; for (unsigned key = inputGetKey(&unicode); key != 0 && !done; key = inputGetKey(&unicode)) { // Don't blink while typing. blinkOffset = wzGetTicks(); int len = 0; /* Deal with all the control keys, assume anything else is a printable character */ switch (key) { case INPBUF_LEFT : /* Move the cursor left */ insPos = MAX(insPos - 1, 0); /* If the cursor has gone off the left of the edit box, * need to update the printable text. */ if (insPos < printStart) { printStart = MAX(printStart - WEDB_CHARJUMP, 0); fitStringStart(); } debug(LOG_INPUT, "EditBox cursor left"); break; case INPBUF_RIGHT : /* Move the cursor right */ len = aText.length(); insPos = MIN(insPos + 1, len); /* If the cursor has gone off the right of the edit box, * need to update the printable text. */ if (insPos > printStart + printChars) { printStart = MIN(printStart + WEDB_CHARJUMP, len - 1); fitStringStart(); } debug(LOG_INPUT, "EditBox cursor right"); break; case INPBUF_UP : debug(LOG_INPUT, "EditBox cursor up"); break; case INPBUF_DOWN : debug(LOG_INPUT, "EditBox cursor down"); break; case INPBUF_HOME : /* Move the cursor to the start of the buffer */ insPos = 0; printStart = 0; fitStringStart(); debug(LOG_INPUT, "EditBox cursor home"); break; case INPBUF_END : /* Move the cursor to the end of the buffer */ insPos = aText.length(); if (insPos != printStart + printChars) { fitStringEnd(); } debug(LOG_INPUT, "EditBox cursor end"); break; case INPBUF_INS : if (editState == WEDBS_INSERT) { editState = WEDBS_OVER; } else { editState = WEDBS_INSERT; } debug(LOG_INPUT, "EditBox cursor insert"); break; case INPBUF_DEL : delCharRight(); /* Update the printable text */ fitStringStart(); debug(LOG_INPUT, "EditBox cursor delete"); break; case INPBUF_PGUP : debug(LOG_INPUT, "EditBox cursor page up"); break; case INPBUF_PGDN : debug(LOG_INPUT, "EditBox cursor page down"); break; case INPBUF_BKSPACE : /* Delete the character to the left of the cursor */ delCharLeft(); /* Update the printable text */ if (insPos <= printStart) { printStart = MAX(printStart - WEDB_CHARJUMP, 0); } fitStringStart(); debug(LOG_INPUT, "EditBox cursor backspace"); break; case INPBUF_TAB : debug(LOG_INPUT, "EditBox cursor tab"); break; case INPBUF_CR : case KEY_KPENTER: // either normal return key || keypad enter /* Finish editing */ focusLost(psContext->psScreen); screenClearFocus(psContext->psScreen); debug(LOG_INPUT, "EditBox cursor return"); return; break; case INPBUF_ESC : debug(LOG_INPUT, "EditBox cursor escape"); break; default: if (keyDown(KEY_LCTRL) || keyDown(KEY_RCTRL)) { switch (key) { case KEY_V: aText = wzGetSelection(); insPos = aText.length(); /* Update the printable text */ fitStringEnd(); debug(LOG_INPUT, "EditBox paste"); break; default: break; } break; } /* Dealt with everything else this must be a printable character */ if (editState == WEDBS_INSERT) { insertChar(unicode); } else { overwriteChar(unicode); } len = aText.length(); /* Update the printable chars */ if (insPos == len) { fitStringEnd(); } else { fitStringStart(); if (insPos > printStart + printChars) { printStart = MIN(printStart + WEDB_CHARJUMP, len - 1); if (printStart >= len) { fitStringStart(); } } } break; } } /* Store the current widget state */ state = (state & ~WEDBS_MASK) | editState; }