int previousWord(wchar_t * CommandLine, unsigned int *cursorLocation) { /* Passing through characters to jump... */ while (*cursorLocation && isAWideCharToJump(CommandLine[*cursorLocation - 1])) { gotoLeft(CommandLine, cursorLocation); } /* ... then going to the beginning of the word */ while (*cursorLocation && !isAWideCharToJump(CommandLine[*cursorLocation - 1])) { gotoLeft(CommandLine, cursorLocation); } return *cursorLocation; }
/* Move cursor to the beginning of a line */ int begLine(wchar_t * CommandLine, unsigned int *cursorLocation) { /* While the index is not zero (meaning it's the beginning of th line) */ while (*cursorLocation) { gotoLeft(CommandLine, cursorLocation); } return *cursorLocation; }
//================================================================== void KCharSelectTable::keyPressEvent( QKeyEvent *e ) { switch ( e->key() ) { case Key_Left: gotoLeft(); break; case Key_Right: gotoRight(); break; case Key_Up: gotoUp(); break; case Key_Down: gotoDown(); break; case Key_Next: emit tableDown(); break; case Key_Prior: emit tableUp(); break; case Key_Space: emit activated( ' ' ); emit activated(); emit highlighted( ' ' ); emit highlighted(); break; case Key_Enter: case Key_Return: { const QPoint oldPos = vPos; vPos = focusPos; vChr = focusItem; repaintCell( oldPos.y(), oldPos.x(), true ); repaintCell( vPos.y(), vPos.x(), true ); emit activated( vChr ); emit activated(); emit highlighted( vChr ); emit highlighted(); } break; } }
/* Delete a character in the command line */ int rmChar(wchar_t * CommandLine, int key, unsigned int *cursorLocation) { unsigned int indexToMoveChar; unsigned int sizeOfCmd = 0; sizeOfCmd = wcslen(CommandLine); /* * Case Backspace is pressed -> cursor must not be at the beginning of the command line * Case Delete is pressed -> cursor must not be at the end of line */ if ((*cursorLocation && key == SCI_BACKSPACE) || ((sizeOfCmd != *cursorLocation) && key == SCI_DELETE)) { if (key == SCI_BACKSPACE) { gotoLeft(CommandLine, cursorLocation); } indexToMoveChar = *cursorLocation; /* Save cursor position where it must be placed */ setStringCapacities("sc"); while (indexToMoveChar < sizeOfCmd) { /* move each character to the previous place and print it */ CommandLine[indexToMoveChar] = CommandLine[indexToMoveChar + 1]; indexToMoveChar++; } CommandLine[indexToMoveChar] = L'\0'; /* Delete sreen from cursor to the end */ setStringCapacities("cd"); /* write the new string */ printf("%ls", &CommandLine[*cursorLocation]); /* Put cursor to the previously saved position */ setStringCapacities("rc"); } return 0; }