UtlBoolean NameValueTokenizer::getSubField(const char* textField, ssize_t textFieldLength, ssize_t subFieldIndex, const char* subFieldSeparators, const char*& subFieldPtr, ssize_t& subFieldLength, ssize_t* lastCharIndex, bool validateChars) { UtlBoolean found = FALSE; if(textField) { #if 0 printf("NameValueTokenizer::getSubField textField = '%s', textFieldLength = %zu, subFieldIndex = %zu, subFieldSeparators = '%s'\n", textField, textFieldLength, subFieldIndex, subFieldSeparators); #endif ssize_t subFieldI = -1; ssize_t subFieldBegin = 0; ssize_t separatorIndex = -1; size_t numSeparators = strlen(subFieldSeparators); for(ssize_t charIndex = 0; subFieldI < subFieldIndex; charIndex++) { if((textFieldLength >= 0 && charIndex >= textFieldLength) || textField[charIndex] == '\0') { subFieldI++; subFieldBegin = separatorIndex + 1; separatorIndex = charIndex; break; } else if (validateChars && !isPrintableChar(textField[charIndex])) { subFieldPtr = NULL; subFieldLength = 0; if(lastCharIndex) *lastCharIndex = 0; return FALSE; } // If we found a separator character // 1 separator check it directly, it is much faster else if((numSeparators == 1 && subFieldSeparators[0] == textField[charIndex]) || // 2 separator characters, check both: (numSeparators == 2 && (subFieldSeparators[0] == textField[charIndex] || subFieldSeparators[1] == textField[charIndex])) || // 3 or more separator characters, do it the slow way: (numSeparators > 2 && strchr(subFieldSeparators, textField[charIndex]))) { subFieldBegin = separatorIndex + 1; separatorIndex = charIndex; // Ignore empty subfields (i.e. they do not count if(subFieldBegin != separatorIndex) { subFieldI++; } } } if(subFieldI == subFieldIndex) { found = TRUE; //subfieldText->append(&(textField[subfieldBegin]), // separatorIndex - subfieldBegin); //subfieldText->replace(0, separatorIndex - subfieldBegin, // &(textField[subfieldBegin]), separatorIndex - subfieldBegin); //subfieldText->remove(separatorIndex - subfieldBegin); subFieldPtr = &(textField[subFieldBegin]); subFieldLength = separatorIndex - subFieldBegin; #if 0 printf("NameValueTokenizer::getSubField subField = '%.*s'\n", subFieldLength, subFieldPtr); #endif if(lastCharIndex) *lastCharIndex = separatorIndex; } } if(!found) { subFieldPtr = NULL; subFieldLength = 0; if(lastCharIndex) *lastCharIndex = 0; } return(found); }
void SelectElement::defaultEventHandler(SelectElementData& data, Element* element, Event* event, HTMLFormElement* htmlForm) { if (!element->renderer()) return; if (data.usesMenuList()) menuListDefaultEventHandler(data, element, event, htmlForm); else listBoxDefaultEventHandler(data, element, event, htmlForm); if (event->defaultHandled()) return; if (event->type() == eventNames().keypressEvent && event->isKeyboardEvent()) { KeyboardEvent* keyboardEvent = static_cast<KeyboardEvent*>(event); if (!keyboardEvent->ctrlKey() && !keyboardEvent->altKey() && !keyboardEvent->metaKey() && isPrintableChar(keyboardEvent->charCode())) { typeAheadFind(data, element, keyboardEvent); event->setDefaultHandled(); return; } } }
void TextDomArea::keyTyped(KeyEventDetails* const details) { DocumentElementAttribute temp; _CurrentCaretBlinkElps=0; _DrawCaret = true; switch(details->getKey()) { case KeyEventDetails::KEY_UP: getLayoutManager()->moveTheCaret(UP,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)); break; case KeyEventDetails::KEY_DOWN: getLayoutManager()->moveTheCaret(DOWN,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)); break; case KeyEventDetails::KEY_LEFT: getLayoutManager()->moveTheCaret(LEFT,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)); break; case KeyEventDetails::KEY_RIGHT: getLayoutManager()->moveTheCaret(RIGHT,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)); break; case KeyEventDetails::KEY_PAGE_UP: getLayoutManager()->moveTheCaret(PAGEUP,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)); break; case KeyEventDetails::KEY_PAGE_DOWN: getLayoutManager()->moveTheCaret(PAGEDOWN,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)); break; case KeyEventDetails::KEY_BACK_SPACE: if(getLayoutManager()->isSomethingSelected()) { deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected(); } else { if(getLayoutManager()->getCaretLine()!=0 || getLayoutManager()->getCaretIndex()!=0) { getLayoutManager()->moveTheCaret(LEFT,false,false); deleteCharacterUsingCommandManager();//getDocumentModel()->deleteCharacter(getLayoutManager()->getCaretLine(),getLayoutManager()->getCaretIndex()); } } break; case KeyEventDetails::KEY_DELETE: if(getLayoutManager()->isSomethingSelected()) { deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected(); } else { deleteCharacterUsingCommandManager();//getDocumentModel()->deleteCharacter(getLayoutManager()->getCaretLine(),getLayoutManager()->getCaretIndex()); } break; case KeyEventDetails::KEY_ENTER: if(getLayoutManager()->isSomethingSelected()) { deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected(); } insertCharacterUsingCommandManager('\n',-1,-1); break; case KeyEventDetails::KEY_HOME: getLayoutManager()->moveTheCaret(HOME,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)); break; case KeyEventDetails::KEY_END: getLayoutManager()->moveTheCaret(END,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)); break; case KeyEventDetails::KEY_TAB: tabHandler(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT); break; default: if(isPrintableChar(details->getKeyChar()) || details->getKey() == KeyEventDetails::KEY_SPACE) { if(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL) { switch(details->getKey()) { case KeyEventDetails::KEY_A: getLayoutManager()->selectAll(); break; case KeyEventDetails::KEY_C: { std::string stringToTheClipboard = getHighlightedString(); getParentWindow()->getParentDrawingSurface()->getEventProducer()->putClipboard(stringToTheClipboard); break; } case KeyEventDetails::KEY_V: { std::string theClipboard = getParentWindow()->getParentDrawingSurface()->getEventProducer()->getClipboard(); handlePastingAString(theClipboard); break; } case KeyEventDetails::KEY_Z: if(_TheUndoManager->canUndo()) { _TheUndoManager->undo(); } break; case KeyEventDetails::KEY_Y: if(_TheUndoManager->canRedo()) { _TheUndoManager->redo(); } break; } } else { if(getLayoutManager()->isSomethingSelected()) { deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected(); } if(getLayoutManager()->isStartingBraces(details->getKeyChar())) { getLayoutManager()->removeBracesHighlightIndices(); getLayoutManager()->setStartingBraces(details->getKeyChar(),getLayoutManager()->getCaretIndex(),getLayoutManager()->getCaretLine()); } else if(getLayoutManager()->isEndingBraces(details->getKeyChar())) { getLayoutManager()->removeBracesHighlightIndices(); getLayoutManager()->setEndingBraces(details->getKeyChar(),getLayoutManager()->getCaretIndex(),getLayoutManager()->getCaretLine()); } insertCharacterUsingCommandManager(details->getKeyChar(),-1,-1); /*getDocumentModel()->insertCharacter(getLayoutManager()->getCaretIndex(),getLayoutManager()->getCaretLine(),details->getKeyChar(),temp); getLayoutManager()->moveTheCaret(RIGHT,false,false); getLayoutManager()->DoIfLineLongerThanPreferredSize();*/ } } break; } }