| 493 | } |
| 494 | |
| 495 | void GuiTextEditCtrl::onPaste() |
| 496 | { |
| 497 | //first, make sure there's something in the clipboard to copy... |
| 498 | const UTF8 *clipboard = Platform::getClipboard(); |
| 499 | if(dStrlen(clipboard) <= 0) |
| 500 | return; |
| 501 | |
| 502 | //save the current state |
| 503 | saveUndoState(); |
| 504 | |
| 505 | //delete anything hilited |
| 506 | if (mBlockEnd > 0) |
| 507 | { |
| 508 | mTextBuffer.cut(mBlockStart, mBlockEnd - mBlockStart); |
| 509 | mCursorPos = mBlockStart; |
| 510 | mBlockStart = 0; |
| 511 | mBlockEnd = 0; |
| 512 | } |
| 513 | |
| 514 | // We'll be converting to UTF16, and maybe trimming the string, |
| 515 | // so let's use a StringBuffer, for convinience. |
| 516 | StringBuffer pasteText(clipboard); |
| 517 | |
| 518 | // Space left after we remove the highlighted text |
| 519 | S32 stringLen = mTextBuffer.length(); |
| 520 | |
| 521 | // Trim down to fit in a buffer of size mMaxStrLen |
| 522 | S32 pasteLen = pasteText.length(); |
| 523 | |
| 524 | if(stringLen + pasteLen > mMaxStrLen) |
| 525 | { |
| 526 | pasteLen = mMaxStrLen - stringLen; |
| 527 | |
| 528 | pasteText.cut(pasteLen, pasteText.length() - pasteLen); |
| 529 | } |
| 530 | |
| 531 | if (mCursorPos == stringLen) |
| 532 | { |
| 533 | mTextBuffer.append(pasteText); |
| 534 | } |
| 535 | else |
| 536 | { |
| 537 | mTextBuffer.insert(mCursorPos, pasteText); |
| 538 | } |
| 539 | |
| 540 | mCursorPos += pasteLen; |
| 541 | } |
| 542 | |
| 543 | void GuiTextEditCtrl::onUndo() |
| 544 | { |