From df6de286e7421062372c468b6dca426c254ef379 Mon Sep 17 00:00:00 2001
From: Greg Ercolano
Date: Mon, 20 Dec 2010 06:42:38 +0000
Subject: Removed emacs shortcuts from Fl_Input, conformed Fl_Input keystrokes
to native environment (much research went into this, citations included).
Tested editing functions on all three platforms. Doxygen docs updated.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8067 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
---
FL/Fl_Input.H | 258 +++++++++++++++++----
src/Fl_Input.cxx | 676 +++++++++++++++++++++++++++++++------------------------
2 files changed, 596 insertions(+), 338 deletions(-)
diff --git a/FL/Fl_Input.H b/FL/Fl_Input.H
index 10b0882df..9e5550cbb 100644
--- a/FL/Fl_Input.H
+++ b/FL/Fl_Input.H
@@ -44,57 +44,225 @@
Characters can be input using the keyboard or the character palette/map.
Character composition is done using dead keys and/or a compose
key as defined by the operating system.
-
-
-
+ Fl_Input keyboard and mouse bindings.
+ |
+ Mouse button 1
+ |
+ Moves the cursor to this point.
+ Drag selects characters.
+ Double click selects words.
+ Triple click selects all text.
+ Shift+click extends the selection.
+ When you select text it is automatically copied to the clipboard.
+ |
|
+ Mouse button 2
+ |
+ Insert the clipboard at the point clicked.
+ You can also select a region and replace it with the clipboard
+ by selecting the region with mouse button 2.
+ |
|
+ Mouse button 3
+ |
+ Currently acts like button 1.
+ |
|
+ Backspace
+ |
+ Deletes one character to the left, or deletes the selected region.
+ |
|
+ Delete
+ |
+ Deletes one character to the right, or deletes the selected region.
+ Combine with Shift for equivalent of ^X (copy+cut).
+ |
|
+ Enter
+ |
+ May cause the callback, see when().
+ |
+
+
+ Fl_Input platform specific keyboard bindings.
+
+ | Windows/Linux |
+ Mac |
+ Function |
+
+
+ | ^A |
+ Command-A |
+
+ Selects all text in the widget.
+
+ |
+ | ^C |
+ Command-C |
+
+ Copy the current selection to the clipboard.
+
+ |
+ | ^I |
+ ^I |
+
+ Insert a tab.
+
+ |
+ | ^J |
+ ^J |
+
+ Insert a Line Feed.
+ (Similar to literal 'Enter' character)
+
+ |
+ | ^L |
+ ^L |
+
+ Insert a Form Feed.
+
+ |
+ | ^M |
+ ^M |
+
+ Insert a Carriage Return.
+
+ |
+ ^V, Shift-Insert |
+ Command-V |
+
+ Paste the clipboard.
+ (Macs keyboards don't have "Insert" keys,
+ but if they did, Shift-Insert would work)
+
+ |
+ ^X, Shift-Delete |
+ Command-X, Shift-Delete |
+
+ Cut.
+ Copy the selection to the clipboard and delete it.
+ (If there's no selection, Shift-Delete acts like Delete)
+
+ |
+ | ^Z |
+ Command-Z |
+
+ Undo.
+ This is a single-level undo mechanism, but all adjacent
+ deletions and insertions are concatenated into a single "undo".
+ Often this will undo a lot more than you expected.
+
+ |
+ | Shift-^Z |
+ Shift-Command-Z |
+
+ Redo.
+ Currently same behavior as ^Z.
+ Reserved for future multilevel undo/redo.
+
+ |
+ | Arrow Keys |
+ Arrow Keys |
+
+ Standard cursor movement.
+ Can be combined with Shift to extend selection.
+
+ |
+ | Home |
+ Command-Up, Command-Left |
+
+ Move to start of line.
+ Can be combined with Shift to extend selection.
+
+ |
+ | End |
+ Command-Down, Command-Right |
+
+ Move to end of line.
+ Can be combined with Shift to extend selection.
+
+ |
+ | Ctrl-Home |
+ Command-Up, Command-PgUp, Ctrl-Left |
+
+ Move to top of document/field.
+ In single line input, moves to start of line.
+ In multiline input, moves to start of top line.
+ Can be combined with Shift to extend selection.
+
+ |
+ | Ctrl-End |
+ Command-End, Command-PgDn, Ctrl-Right |
+
+ Move to bottom of document/field.
+ In single line input, moves to end of line.
+ In multiline input, moves to end of last line.
+ Can be combined with Shift to extend selection.
+
+ |
+ | Ctrl-Left |
+ Alt-Left |
+
+ Word left.
+ Can be combined with Shift to extend selection.
+
+ |
+ | Ctrl-Right |
+ Alt-Right |
+
+ Word right.
+ Can be combined with Shift to extend selection.
+
+ |
+ | Ctrl-Backspace |
+ Alt-Delete, Alt-Backspace |
+
+ Delete word left.
+
+ |
+ | Ctrl-Delete |
+ Alt-Delete |
+
+ Delete word right.
+
+ |
*/
class FL_EXPORT Fl_Input : public Fl_Input_ {
int handle_key();
int shift_position(int p);
int shift_up_down_position(int p);
void handle_mouse(int keepmark=0);
+
+ // Private keyboard functions
+ int kf_lines_up(int repeat_num);
+ int kf_lines_down(int repeat_num);
+ int kf_page_up();
+ int kf_page_down();
+ int kf_insert_toggle();
+ int kf_delete_word_right();
+ int kf_delete_word_left();
+ int kf_delete_sol();
+ int kf_delete_eol();
+ int kf_delete_char_right();
+ int kf_delete_char_left();
+ int kf_move_sol();
+ int kf_move_eol();
+ int kf_clear_eol();
+ int kf_move_char_left();
+ int kf_move_char_right();
+ int kf_move_word_left();
+ int kf_move_word_right();
+ int kf_move_up_and_sol();
+ int kf_move_down_and_eol();
+ int kf_top();
+ int kf_bottom();
+ int kf_select_all();
+ int kf_undo();
+ int kf_redo();
+ int kf_copy();
+ int kf_paste();
+ int kf_copy_cut();
+
protected:
void draw();
public:
diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx
index aee5f0510..b0d656e2c 100644
--- a/src/Fl_Input.cxx
+++ b/src/Fl_Input.cxx
@@ -90,12 +90,220 @@ static const char *legal_fp_chars = 0L;
static const char *legal_fp_chars = ".eE+-";
#endif
+// Move cursor up specified #lines
+// If OPTION_ARROW_FOCUS is disabled, return 1 to prevent focus navigation.
+//
+int Fl_Input::kf_lines_up(int repeat_num) {
+ int i = position();
+ if (!line_start(i)) {
+ //UNNEEDED if (input_type()==FL_MULTILINE_INPUT && !Fl::option(Fl::OPTION_ARROW_FOCUS)) return 1;
+ return NORMAL_INPUT_MOVE;
+ }
+ while(repeat_num--) {
+ i = line_start(i);
+ if (!i) break;
+ i--;
+ }
+ shift_up_down_position(line_start(i));
+ return 1;
+}
+
+// Move cursor down specified #lines
+// If OPTION_ARROW_FOCUS is disabled, return 1 to prevent focus navigation.
+//
+int Fl_Input::kf_lines_down(int repeat_num) {
+ int i = position();
+ if (line_end(i) >= size()) {
+ //UNNEEDED if (input_type()==FL_MULTILINE_INPUT && !Fl::option(Fl::OPTION_ARROW_FOCUS)) return 1;
+ return NORMAL_INPUT_MOVE;
+ }
+ while (repeat_num--) {
+ i = line_end(i);
+ if (i >= size()) break;
+ i++;
+ }
+ shift_up_down_position(i);
+ return 1;
+}
+
+// Move up a page
+int Fl_Input::kf_page_up() {
+ return kf_lines_up(linesPerPage());
+}
+
+// Move down a page
+int Fl_Input::kf_page_down() {
+ return kf_lines_down(linesPerPage());
+}
+
+// Toggle insert mode
+int Fl_Input::kf_insert_toggle() {
+ return 1; // \todo: needs insert mode
+}
+
+// Delete word right
+int Fl_Input::kf_delete_word_right() {
+ if (readonly()) { fl_beep(); return 1; }
+ if (mark() != position()) return cut();
+ cut(position(), word_end(position()));
+ return 1;
+}
+
+// Delete word left
+int Fl_Input::kf_delete_word_left() {
+ if (readonly()) { fl_beep(); return 1; }
+ if (mark() != position()) return cut();
+ cut(word_start(position()), position());
+ return 1;
+}
+
+// Delete to start of line
+int Fl_Input::kf_delete_sol() {
+ if (mark() != position()) return cut();
+ cut(line_start(position()), position());
+ return 1;
+}
+
+// Delete to end of line
+int Fl_Input::kf_delete_eol() {
+ if (readonly()) { fl_beep(); return 1; }
+ if (mark() != position()) return cut();
+ cut(position(), line_end(position()));
+ return 1;
+}
+
+int Fl_Input::kf_delete_char_right() {
+ if (readonly()) { fl_beep(); return 1; }
+ if (mark() != position()) return cut();
+ else return cut(1);
+}
+
+int Fl_Input::kf_delete_char_left() {
+ if (readonly()) { fl_beep(); return 1; }
+ if (mark() != position()) cut();
+ else cut(-1);
+ return 1;
+}
+
+// Move cursor to start of line
+int Fl_Input::kf_move_sol() {
+ return shift_position(line_start(position())) + NORMAL_INPUT_MOVE;
+}
+
+// Move cursor to end of line
+int Fl_Input::kf_move_eol() {
+ return shift_position(line_end(position())) + NORMAL_INPUT_MOVE;
+}
+
+// Clear to end of line
+int Fl_Input::kf_clear_eol() {
+ if (readonly()) { fl_beep(); return 1; }
+ if (position()>=size()) return 0;
+ int i = line_end(position());
+ if (i == position() && i < size()) i++;
+ cut(position(), i);
+ return copy_cuts();
+}
+
+// Move cursor one character to the left
+// If OPTION_ARROW_FOCUS is disabled, return 1 to prevent focus navigation.
+//
+int Fl_Input::kf_move_char_left() {
+ int i = shift_position(position()-1) + NORMAL_INPUT_MOVE;
+ return Fl::option(Fl::OPTION_ARROW_FOCUS) ? i : 1;
+}
+
+// Move cursor one character to the right
+// If OPTION_ARROW_FOCUS is disabled, return 1 to prevent focus navigation.
+//
+int Fl_Input::kf_move_char_right() {
+ int i = shift_position(position()+1) + NORMAL_INPUT_MOVE;
+ return Fl::option(Fl::OPTION_ARROW_FOCUS) ? i : 1;
+}
+
+// Move cursor word-left
+int Fl_Input::kf_move_word_left() {
+ shift_position(word_start(position()));
+ return 1;
+}
+
+// Move cursor word-right
+int Fl_Input::kf_move_word_right() {
+ shift_position(word_end(position()));
+ return 1;
+}
+
+// Move cursor up one line and to the start of line (paragraph up)
+int Fl_Input::kf_move_up_and_sol() {
+ if (line_start(position())==position() && position()>0)
+ return shift_position(line_start(position()-1)) + NORMAL_INPUT_MOVE;
+ else
+ return shift_position(line_start(position())) + NORMAL_INPUT_MOVE;
+}
+
+// Move cursor down one line and to the end of line (paragraph down)
+int Fl_Input::kf_move_down_and_eol() {
+ if (line_end(position())==position() && position()