summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FL/Fl_Input.H2
-rw-r--r--FL/Fl_Screen_Driver.H4
-rw-r--r--src/Fl_Input.cxx151
-rw-r--r--src/Fl_Screen_Driver.cxx69
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H2
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx76
6 files changed, 158 insertions, 146 deletions
diff --git a/FL/Fl_Input.H b/FL/Fl_Input.H
index d8fabb561..4c5ff17d4 100644
--- a/FL/Fl_Input.H
+++ b/FL/Fl_Input.H
@@ -219,6 +219,8 @@
</TD></TR></TABLE>
*/
class FL_EXPORT Fl_Input : public Fl_Input_ {
+ friend class Fl_Screen_Driver;
+ friend class Fl_Cocoa_Screen_Driver; // Not ideal, but probably no other platform will use it
int handle_key();
int shift_position(int p);
int shift_up_down_position(int p);
diff --git a/FL/Fl_Screen_Driver.H b/FL/Fl_Screen_Driver.H
index d13dbaafe..22eda6095 100644
--- a/FL/Fl_Screen_Driver.H
+++ b/FL/Fl_Screen_Driver.H
@@ -39,6 +39,7 @@
class Fl_Window;
class Fl_RGB_Image;
class Fl_Group;
+class Fl_Input;
class FL_EXPORT Fl_Screen_Driver {
@@ -129,6 +130,9 @@ public:
static void write_image_inside(Fl_RGB_Image *to, Fl_RGB_Image *from, int to_x, int to_y);
static Fl_RGB_Image *traverse_to_gl_subwindows(Fl_Group *g, uchar *p, int x, int y, int w, int h, int alpha,
Fl_RGB_Image *full_img);
+ // optional platform-specific key handling for Fl_Input widget
+ // the default implementation may be enough
+ virtual int input_widget_handle_key(int key, unsigned mods, unsigned shift, Fl_Input *input);
};
diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx
index 87f9df764..d6b8b3886 100644
--- a/src/Fl_Input.cxx
+++ b/src/Fl_Input.cxx
@@ -22,13 +22,6 @@
// In theory you can replace this code with another subclass to change
// the keybindings.
-#if defined(WIN32) || defined(__APPLE__) // PORTME: platform text editor look and feel
-#elif defined(FL_PORTING)
-# pragma message "FL_PORTING: implement text input specifics here"
- // current custom code is for OS X keybaord specifics only
-#else
-#endif
-
#include <stdio.h>
#include <stdlib.h>
#include <FL/Fl.H>
@@ -389,6 +382,11 @@ int Fl_Input::handle_key() {
//
// Example: (NP,WP,!WO) means supported in notepad + wordpad, but NOT word.
//
+
+ // handle keypresses that can have a platform-dependent processing
+ int retval = Fl::screen_driver()->input_widget_handle_key(Fl::event_key(), mods, shift, this);
+ if (retval >= 0) return retval;
+
switch (Fl::event_key()) {
case FL_Insert:
@@ -400,143 +398,6 @@ int Fl_Input::handle_key() {
if (mods==FL_CTRL) return kf_copy(); // Ctrl-Insert (WP,NP,WOW,GE,KE,OF)
return 0; // ignore other combos, pass to parent
- case FL_Delete: {
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_delete_char_right(); // Delete (OSX-HIG,TE,SA,WOX)
- if (mods==FL_CTRL) return kf_delete_char_right(); // Ctrl-Delete (??? TE,!SA,!WOX)
- if (mods==FL_ALT) return kf_delete_word_right(); // Alt-Delete (OSX-HIG,TE,SA)
- return 0; // ignore other combos, pass to parent
-#else
- int selected = (position() != mark()) ? 1 : 0;
- if (mods==0 && shift && selected)
- return kf_copy_cut(); // Shift-Delete with selection (WP,NP,WOW,GE,KE,OF)
- if (mods==0 && shift && !selected)
- return kf_delete_char_right(); // Shift-Delete no selection (WP,NP,WOW,GE,KE,!OF)
- if (mods==0) return kf_delete_char_right(); // Delete (Standard)
- if (mods==FL_CTRL) return kf_delete_word_right(); // Ctrl-Delete (WP,!NP,WOW,GE,KE,!OF)
- return 0; // ignore other combos, pass to parent
-#endif
- }
-
- case FL_Left:
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_move_char_left(); // Left (OSX-HIG)
- if (mods==FL_ALT) return kf_move_word_left(); // Alt-Left (OSX-HIG)
- if (mods==FL_META) return kf_move_sol(); // Meta-Left (OSX-HIG)
- if (mods==FL_CTRL) return kf_move_sol(); // Ctrl-Left (TE/SA)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_move_char_left(); // Left (WP,NP,WOW,GE,KE,OF)
- if (mods==FL_CTRL) return kf_move_word_left(); // Ctrl-Left (WP,NP,WOW,GE,KE,!OF)
- if (mods==FL_META) return kf_move_char_left(); // Meta-Left (WP,NP,?WOW,GE,KE)
- return 0; // ignore other combos, pass to parent
-#endif
-
- case FL_Right:
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_move_char_right(); // Right (OSX-HIG)
- if (mods==FL_ALT) return kf_move_word_right(); // Alt-Right (OSX-HIG)
- if (mods==FL_META) return kf_move_eol(); // Meta-Right (OSX-HIG)
- if (mods==FL_CTRL) return kf_move_eol(); // Ctrl-Right (TE/SA)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_move_char_right(); // Right (WP,NP,WOW,GE,KE,OF)
- if (mods==FL_CTRL) return kf_move_word_right(); // Ctrl-Right (WP,NP,WOW,GE,KE,!OF)
- if (mods==FL_META) return kf_move_char_right(); // Meta-Right (WP,NP,?WOW,GE,KE,!OF)
- return 0; // ignore other combos, pass to parent
-#endif
-
- case FL_Up:
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_lines_up(1); // Up (OSX-HIG)
- if (mods==FL_CTRL) return kf_page_up(); // Ctrl-Up (TE !HIG)
- if (mods==FL_ALT) return kf_move_up_and_sol(); // Alt-Up (OSX-HIG)
- if (mods==FL_META) return kf_top(); // Meta-Up (OSX-HIG)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_lines_up(1); // Up (WP,NP,WOW,GE,KE,OF)
- if (mods==FL_CTRL) return kf_move_up_and_sol(); // Ctrl-Up (WP,!NP,WOW,GE,!KE,OF)
- return 0; // ignore other combos, pass to parent
-#endif
-
- case FL_Down:
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_lines_down(1); // Dn (OSX-HIG)
- if (mods==FL_CTRL) return kf_page_down(); // Ctrl-Dn (TE !HIG)
- if (mods==FL_ALT) return kf_move_down_and_eol(); // Alt-Dn (OSX-HIG)
- if (mods==FL_META) return kf_bottom(); // Meta-Dn (OSX-HIG)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_lines_down(1); // Dn (WP,NP,WOW,GE,KE,OF)
- if (mods==FL_CTRL) return kf_move_down_and_eol(); // Ctrl-Down (WP,!NP,WOW,GE,!KE,OF)
- return 0; // ignore other combos, pass to parent
-#endif
-
- case FL_Page_Up:
- // Fl_Input has no scroll control, so instead we move the cursor by one page
- // OSX-HIG recommends Alt increase one semantic unit, Meta next higher..
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_page_up(); // PgUp (OSX-HIG)
- if (mods==FL_ALT) return kf_page_up(); // Alt-PageUp (OSX-HIG)
- if (mods==FL_META) return kf_top(); // Meta-PageUp (OSX-HIG,!TE)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_page_up(); // PageUp (WP,NP,WOW,GE,KE)
- if (mods==FL_CTRL) return kf_page_up(); // Ctrl-PageUp (!WP,!NP,!WOW,!GE,KE,OF)
- if (mods==FL_ALT) return kf_page_up(); // Alt-PageUp (!WP,!NP,!WOW,!GE,KE,OF)
- return 0; // ignore other combos, pass to parent
-#endif
-
- case FL_Page_Down:
-#ifdef __APPLE__ // platform text editor look and feel
- // Fl_Input has no scroll control, so instead we move the cursor by one page
- // OSX-HIG recommends Alt increase one semantic unit, Meta next higher..
- if (mods==0) return kf_page_down(); // PgDn (OSX-HIG)
- if (mods==FL_ALT) return kf_page_down(); // Alt-PageDn (OSX-HIG)
- if (mods==FL_META) return kf_bottom(); // Meta-PageDn (OSX-HIG,!TE)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_page_down(); // PageDn (WP,NP,WOW,GE,KE)
- if (mods==FL_CTRL) return kf_page_down(); // Ctrl-PageDn (!WP,!NP,!WOW,!GE,KE,OF)
- if (mods==FL_ALT) return kf_page_down(); // Alt-PageDn (!WP,!NP,!WOW,!GE,KE,OF)
- return 0; // ignore other combos, pass to parent
-#endif
-
- case FL_Home:
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_top(); // Home (OSX-HIG)
- if (mods==FL_ALT) return kf_top(); // Alt-Home (???)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_move_sol(); // Home (WP,NP,WOW,GE,KE,OF)
- if (mods==FL_CTRL) return kf_top(); // Ctrl-Home (WP,NP,WOW,GE,KE,OF)
- return 0; // ignore other combos, pass to parent
-#endif
-
- case FL_End:
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_bottom(); // End (OSX-HIG)
- if (mods==FL_ALT) return kf_bottom(); // Alt-End (???)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_move_eol(); // End (WP,NP,WOW,GE,KE,OF)
- if (mods==FL_CTRL) return kf_bottom(); // Ctrl-End (WP,NP,WOW,GE,KE,OF)
- return 0; // ignore other combos, pass to parent
-#endif
-
- case FL_BackSpace:
-#ifdef __APPLE__ // platform text editor look and feel
- if (mods==0) return kf_delete_char_left(); // Backspace (OSX-HIG)
- if (mods==FL_CTRL) return kf_delete_char_left(); // Ctrl-Backspace (TE/SA)
- if (mods==FL_ALT) return kf_delete_word_left(); // Alt-Backspace (OSX-HIG)
- if (mods==FL_META) return kf_delete_sol(); // Meta-Backspace (OSX-HIG,!TE)
- return 0; // ignore other combos, pass to parent
-#else
- if (mods==0) return kf_delete_char_left(); // Backspace (WP,NP,WOW,GE,KE,OF)
- if (mods==FL_CTRL) return kf_delete_word_left(); // Ctrl-Backspace (WP,!NP,WOW,GE,KE,!OF)
- return 0; // ignore other combos, pass to parent
-#endif
-
case FL_Enter:
case FL_KP_Enter:
if (when() & FL_WHEN_ENTER_KEY) {
@@ -748,9 +609,7 @@ int Fl_Input::handle(int event) {
Fl::focus(dnd_save_focus);
handle(FL_UNFOCUS);
}
-#if !(defined(__APPLE__) || defined(WIN32)) // PORTME: cursor
Fl::first_window()->cursor(FL_CURSOR_MOVE);
-#endif
dnd_save_focus = NULL;
return 1;
diff --git a/src/Fl_Screen_Driver.cxx b/src/Fl_Screen_Driver.cxx
index a444e293f..bba7d8cf7 100644
--- a/src/Fl_Screen_Driver.cxx
+++ b/src/Fl_Screen_Driver.cxx
@@ -23,6 +23,7 @@
#include <FL/Fl_Plugin.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Window.H>
+#include <FL/Fl_Input.H>
char Fl_Screen_Driver::bg_set = 0;
char Fl_Screen_Driver::bg2_set = 0;
@@ -269,6 +270,74 @@ Fl_RGB_Image *Fl_Screen_Driver::traverse_to_gl_subwindows(Fl_Group *g, uchar *p,
}
+int Fl_Screen_Driver::input_widget_handle_key(int key, unsigned mods, unsigned shift, Fl_Input *input)
+{
+ switch (key) {
+ case FL_Delete: {
+ int selected = (input->position() != input->mark()) ? 1 : 0;
+ if (mods==0 && shift && selected)
+ return input->kf_copy_cut(); // Shift-Delete with selection (WP,NP,WOW,GE,KE,OF)
+ if (mods==0 && shift && !selected)
+ return input->kf_delete_char_right(); // Shift-Delete no selection (WP,NP,WOW,GE,KE,!OF)
+ if (mods==0) return input->kf_delete_char_right(); // Delete (Standard)
+ if (mods==FL_CTRL) return input->kf_delete_word_right(); // Ctrl-Delete (WP,!NP,WOW,GE,KE,!OF)
+ return 0; // ignore other combos, pass to parent
+ }
+
+ case FL_Left:
+ if (mods==0) return input->kf_move_char_left(); // Left (WP,NP,WOW,GE,KE,OF)
+ if (mods==FL_CTRL) return input->kf_move_word_left(); // Ctrl-Left (WP,NP,WOW,GE,KE,!OF)
+ if (mods==FL_META) return input->kf_move_char_left(); // Meta-Left (WP,NP,?WOW,GE,KE)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Right:
+ if (mods==0) return input->kf_move_char_right(); // Right (WP,NP,WOW,GE,KE,OF)
+ if (mods==FL_CTRL) return input->kf_move_word_right(); // Ctrl-Right (WP,NP,WOW,GE,KE,!OF)
+ if (mods==FL_META) return input->kf_move_char_right(); // Meta-Right (WP,NP,?WOW,GE,KE,!OF)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Up:
+ if (mods==0) return input->kf_lines_up(1); // Up (WP,NP,WOW,GE,KE,OF)
+ if (mods==FL_CTRL) return input->kf_move_up_and_sol(); // Ctrl-Up (WP,!NP,WOW,GE,!KE,OF)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Down:
+ if (mods==0) return input->kf_lines_down(1); // Dn (WP,NP,WOW,GE,KE,OF)
+ if (mods==FL_CTRL) return input->kf_move_down_and_eol(); // Ctrl-Down (WP,!NP,WOW,GE,!KE,OF)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Page_Up:
+ // Fl_Input has no scroll control, so instead we move the cursor by one page
+ if (mods==0) return input->kf_page_up(); // PageUp (WP,NP,WOW,GE,KE)
+ if (mods==FL_CTRL) return input->kf_page_up(); // Ctrl-PageUp (!WP,!NP,!WOW,!GE,KE,OF)
+ if (mods==FL_ALT) return input->kf_page_up(); // Alt-PageUp (!WP,!NP,!WOW,!GE,KE,OF)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Page_Down:
+ if (mods==0) return input->kf_page_down(); // PageDn (WP,NP,WOW,GE,KE)
+ if (mods==FL_CTRL) return input->kf_page_down(); // Ctrl-PageDn (!WP,!NP,!WOW,!GE,KE,OF)
+ if (mods==FL_ALT) return input->kf_page_down(); // Alt-PageDn (!WP,!NP,!WOW,!GE,KE,OF)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Home:
+ if (mods==0) return input->kf_move_sol(); // Home (WP,NP,WOW,GE,KE,OF)
+ if (mods==FL_CTRL) return input->kf_top(); // Ctrl-Home (WP,NP,WOW,GE,KE,OF)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_End:
+ if (mods==0) return input->kf_move_eol(); // End (WP,NP,WOW,GE,KE,OF)
+ if (mods==FL_CTRL) return input->kf_bottom(); // Ctrl-End (WP,NP,WOW,GE,KE,OF)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_BackSpace:
+ if (mods==0) return input->kf_delete_char_left(); // Backspace (WP,NP,WOW,GE,KE,OF)
+ if (mods==FL_CTRL) return input->kf_delete_word_left(); // Ctrl-Backspace (WP,!NP,WOW,GE,KE,!OF)
+ return 0;
+ // ignore other combos, pass to parent
+ }
+ return -1;
+}
+
//
// End of "$Id$".
//
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
index 3f475a637..afcaad924 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
+++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
@@ -39,6 +39,7 @@
class Fl_Window;
+class Fl_Input;
class FL_EXPORT Fl_Cocoa_Screen_Driver : public Fl_Screen_Driver
{
@@ -87,6 +88,7 @@ public:
virtual int dnd(int use_selection);
virtual int compose(int &del);
virtual uchar *read_image(uchar *p, int x, int y, int w, int h, int alpha);
+ virtual int input_widget_handle_key(int key, unsigned mods, unsigned shift, Fl_Input *input);
};
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
index c23046e30..786bbde12 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
@@ -23,6 +23,7 @@
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Graphics_Driver.H>
+#include <FL/Fl_Input.H>
#include <FL/fl_ask.H>
#include <stdio.h>
@@ -370,6 +371,81 @@ Fl_Cocoa_Screen_Driver::read_image(uchar *p, // I - Pixel buffer or NULL to all
return p;
}
+
+int Fl_Cocoa_Screen_Driver::input_widget_handle_key(int key, unsigned mods, unsigned shift, Fl_Input *input)
+{
+ switch (key) {
+ case FL_Delete: {
+ if (mods==0) return input->kf_delete_char_right(); // Delete (OSX-HIG,TE,SA,WOX)
+ if (mods==FL_CTRL) return input->kf_delete_char_right(); // Ctrl-Delete (??? TE,!SA,!WOX)
+ if (mods==FL_ALT) return input->kf_delete_word_right(); // Alt-Delete (OSX-HIG,TE,SA)
+ return 0; // ignore other combos, pass to parent
+ }
+
+ case FL_Left:
+ if (mods==0) return input->kf_move_char_left(); // Left (OSX-HIG)
+ if (mods==FL_ALT) return input->kf_move_word_left(); // Alt-Left (OSX-HIG)
+ if (mods==FL_META) return input->kf_move_sol(); // Meta-Left (OSX-HIG)
+ if (mods==FL_CTRL) return input->kf_move_sol(); // Ctrl-Left (TE/SA)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Right:
+ if (mods==0) return input->kf_move_char_right(); // Right (OSX-HIG)
+ if (mods==FL_ALT) return input->kf_move_word_right(); // Alt-Right (OSX-HIG)
+ if (mods==FL_META) return input->kf_move_eol(); // Meta-Right (OSX-HIG)
+ if (mods==FL_CTRL) return input->kf_move_eol(); // Ctrl-Right (TE/SA)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Up:
+ if (mods==0) return input->kf_lines_up(1); // Up (OSX-HIG)
+ if (mods==FL_CTRL) return input->kf_page_up(); // Ctrl-Up (TE !HIG)
+ if (mods==FL_ALT) return input->kf_move_up_and_sol(); // Alt-Up (OSX-HIG)
+ if (mods==FL_META) return input->kf_top(); // Meta-Up (OSX-HIG)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Down:
+ if (mods==0) return input->kf_lines_down(1); // Dn (OSX-HIG)
+ if (mods==FL_CTRL) return input->kf_page_down(); // Ctrl-Dn (TE !HIG)
+ if (mods==FL_ALT) return input->kf_move_down_and_eol(); // Alt-Dn (OSX-HIG)
+ if (mods==FL_META) return input->kf_bottom(); // Meta-Dn (OSX-HIG)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Page_Up:
+ // Fl_Input has no scroll control, so instead we move the cursor by one page
+ // OSX-HIG recommends Alt increase one semantic unit, Meta next higher..
+ if (mods==0) return input->kf_page_up(); // PgUp (OSX-HIG)
+ if (mods==FL_ALT) return input->kf_page_up(); // Alt-PageUp (OSX-HIG)
+ if (mods==FL_META) return input->kf_top(); // Meta-PageUp (OSX-HIG,!TE)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Page_Down:
+ // Fl_Input has no scroll control, so instead we move the cursor by one page
+ // OSX-HIG recommends Alt increase one semantic unit, Meta next higher..
+ if (mods==0) return input->kf_page_down(); // PgDn (OSX-HIG)
+ if (mods==FL_ALT) return input->kf_page_down(); // Alt-PageDn (OSX-HIG)
+ if (mods==FL_META) return input->kf_bottom(); // Meta-PageDn (OSX-HIG,!TE)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_Home:
+ if (mods==0) return input->kf_top(); // Home (OSX-HIG)
+ if (mods==FL_ALT) return input->kf_top(); // Alt-Home (???)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_End:
+ if (mods==0) return input->kf_bottom(); // End (OSX-HIG)
+ if (mods==FL_ALT) return input->kf_bottom(); // Alt-End (???)
+ return 0; // ignore other combos, pass to parent
+
+ case FL_BackSpace:
+ if (mods==0) return input->kf_delete_char_left(); // Backspace (OSX-HIG)
+ if (mods==FL_CTRL) return input->kf_delete_char_left(); // Ctrl-Backspace (TE/SA)
+ if (mods==FL_ALT) return input->kf_delete_word_left(); // Alt-Backspace (OSX-HIG)
+ if (mods==FL_META) return input->kf_delete_sol(); // Meta-Backspace (OSX-HIG,!TE)
+ return 0; // ignore other combos, pass to parent
+ }
+ return -1;
+}
+
//
// End of "$Id$".
//