+ /**
+ * Handle posted command events.
+ *
+ * @param command command event
+ */
+ @Override
+ public void onCommand(final TCommandEvent command) {
+ if (command.equals(cmCut)) {
+ // Copy text to clipboard, and then remove it.
+
+ // TODO
+
+ deleteSelection();
+ return;
+ }
+
+ if (command.equals(cmCopy)) {
+ // Copy text to clipboard.
+
+ // TODO
+
+ return;
+ }
+
+ if (command.equals(cmPaste)) {
+ // Delete selected text, then paste text from clipboard.
+ deleteSelection();
+
+ String text = getClipboard().pasteText();
+ if (text != null) {
+ for (int i = 0; i < text.length(); ) {
+ int ch = text.codePointAt(i);
+ onKeypress(new TKeypressEvent(false, 0, ch, false, false,
+ false));
+ i += Character.charCount(ch);
+ }
+ }
+ return;
+ }
+
+ if (command.equals(cmClear)) {
+ // Remove text.
+ deleteSelection();
+ return;
+ }
+
+ }
+
+ // ------------------------------------------------------------------------
+ // TWidget ----------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Draw the text box.
+ */
+ @Override
+ public void draw() {
+ for (int i = 0; i < getHeight(); i++) {
+ // Background line
+ getScreen().hLineXY(0, i, getWidth(), ' ', defaultColor);
+
+ // Now draw document's line
+ if (topLine + i < document.getLineCount()) {
+ Line line = document.getLine(topLine + i);
+ int x = 0;
+ for (Word word: line.getWords()) {
+ // For now, we are cheating: draw outside the left region
+ // if needed and let screen do the clipping.
+ getScreen().putStringXY(x - leftColumn, i, word.getText(),
+ word.getColor());
+ x += word.getDisplayLength();
+ if (x - leftColumn > getWidth()) {
+ break;
+ }
+ }
+ }
+
+ // TODO: highlight selected region
+ }
+ }
+