Move platform specific shortcut code to platform drivers.

Tested on Windows and Linux (not tested on MacOS/Android).


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12951 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser
2018-06-20 15:52:58 +00:00
parent 0a6ebfea9d
commit ec0ac46aa8
6 changed files with 135 additions and 114 deletions
+8 -2
View File
@@ -46,12 +46,18 @@ class Fl_Widget;
*/
class FL_EXPORT Fl_System_Driver {
friend class Fl;
public:
struct Keyname {
unsigned int key;
const char* name;
};
protected:
// implement once for each platform
static Fl_System_Driver *newSystemDriver();
Fl_System_Driver();
struct Keyname {unsigned int key; const char* name;};
static Keyname table[];
// key_table and key_table_size are used in fl_shortcut to translate key names
Keyname *key_table;
int key_table_size;
public:
virtual ~Fl_System_Driver();
// These flags are useful after calling XParseGeometry(). They indicate which of its arguments
+45 -1
View File
@@ -36,12 +36,56 @@ const int Fl_System_Driver::fl_YValue = 0x0002;
const int Fl_System_Driver::fl_XNegative = 0x0010;
const int Fl_System_Driver::fl_YNegative = 0x0020;
// This default key table is used for all system drivers that don't define
// and/or use their own table. It is defined here "static" and assigned
// in the constructor to avoid static initialization race conditions.
//
// As of June 2018 these platforms are Windows and Android. X11 does not
// use a key table at all.
// Platforms that use their own key tables must assign them in their
// constructors (which overwrites the pointer and size).
static Fl_System_Driver::Keyname default_key_table[] = {
{' ', "Space"},
{FL_BackSpace, "Backspace"},
{FL_Tab, "Tab"},
{0xff0b/*XK_Clear*/, "Clear"},
{FL_Enter, "Enter"}, // X says "Enter"
{FL_Pause, "Pause"},
{FL_Scroll_Lock, "Scroll_Lock"},
{FL_Escape, "Escape"},
{FL_Home, "Home"},
{FL_Left, "Left"},
{FL_Up, "Up"},
{FL_Right, "Right"},
{FL_Down, "Down"},
{FL_Page_Up, "Page_Up"}, // X says "Prior"
{FL_Page_Down, "Page_Down"}, // X says "Next"
{FL_End, "End"},
{FL_Print, "Print"},
{FL_Insert, "Insert"},
{FL_Menu, "Menu"},
{FL_Num_Lock, "Num_Lock"},
{FL_KP_Enter, "KP_Enter"},
{FL_Shift_L, "Shift_L"},
{FL_Shift_R, "Shift_R"},
{FL_Control_L, "Control_L"},
{FL_Control_R, "Control_R"},
{FL_Caps_Lock, "Caps_Lock"},
{FL_Meta_L, "Meta_L"},
{FL_Meta_R, "Meta_R"},
{FL_Alt_L, "Alt_L"},
{FL_Alt_R, "Alt_R"},
{FL_Delete, "Delete"}
};
Fl_System_Driver::Fl_System_Driver()
{
// initialize default key table (used in fl_shortcut.cxx)
key_table = default_key_table;
key_table_size = sizeof(default_key_table)/sizeof(*default_key_table);
}
Fl_System_Driver::~Fl_System_Driver()
{
}
+47 -1
View File
@@ -16,8 +16,10 @@
// http://www.fltk.org/str.php
//
// *FIXME* Do we really need config_lib.h ? We should NOT!
// *FIXME* We should not even need config.h in this file. AlbrechtS.
// #include "../../config_lib.h"
#include "../../config_lib.h"
#include "Fl_Darwin_System_Driver.H"
#include <FL/platform.H>
#include <FL/Fl.H>
@@ -38,6 +40,47 @@
#include <sys/mount.h>
#include <sys/stat.h>
// This key table is used for the Darwin system driver. It is defined here
// "static" and assigned in the constructor to avoid static initialization
// race conditions. It is used in fl_shortcut.cxx.
//
// This table must be in numeric order by fltk (X) keysym number:
Fl_System_Driver::Keyname darwin_key_table[] = {
// v - this column may contain UTF-8 characters
{' ', "Space"},
{FL_BackSpace, "\xe2\x8c\xab"}, // erase to the left
{FL_Tab, "\xe2\x87\xa5"}, // rightwards arrow to bar
{0xff0b, "\xe2\x8c\xa6"}, // erase to the right
{FL_Enter, "\xe2\x86\xa9"}, // leftwards arrow with hook
{FL_Pause, "Pause"},
{FL_Scroll_Lock, "Scroll_Lock"},
{FL_Escape, "\xe2\x90\x9b"},
{FL_Home, "\xe2\x86\x96"}, // north west arrow
{FL_Left, "\xe2\x86\x90"}, // leftwards arrow
{FL_Up, "\xe2\x86\x91"}, // upwards arrow
{FL_Right, "\xe2\x86\x92"}, // rightwards arrow
{FL_Down, "\xe2\x86\x93"}, // downwards arrow
{FL_Page_Up, "\xe2\x87\x9e"}, // upwards arrow with double stroke
{FL_Page_Down, "\xe2\x87\x9f"}, // downwards arrow with double stroke
{FL_End, "\xe2\x86\x98"}, // south east arrow
{FL_Print, "Print"},
{FL_Insert, "Insert"},
{FL_Menu, "Menu"},
{FL_Num_Lock, "Num_Lock"},
{FL_KP_Enter, "\xe2\x8c\xa4"}, // up arrow head between two horizontal bars
{FL_Shift_L, "Shift_L"},
{FL_Shift_R, "Shift_R"},
{FL_Control_L, "Control_L"},
{FL_Control_R, "Control_R"},
{FL_Caps_Lock, "\xe2\x87\xaa"}, // upwards white arrow from bar
{FL_Meta_L, "Meta_L"},
{FL_Meta_R, "Meta_R"},
{FL_Alt_L, "Alt_L"},
{FL_Alt_R, "Alt_R"},
{FL_Delete, "\xe2\x8c\xa7"} // x in a rectangle box
};
const char *Fl_Darwin_System_Driver::shift_name() {
return "\\"; // "\xe2\x87\xa7\\"; // U+21E7 (upwards white arrow)
}
@@ -63,6 +106,9 @@ Fl_System_Driver *Fl_System_Driver::newSystemDriver()
Fl_Darwin_System_Driver::Fl_Darwin_System_Driver() : Fl_Posix_System_Driver() {
if (fl_mac_os_version == 0) fl_mac_os_version = calc_mac_os_version();
// initialize key table
key_table = darwin_key_table;
key_table_size = sizeof(darwin_key_table)/sizeof(*darwin_key_table);
}
int Fl_Darwin_System_Driver::single_arg(const char *arg) {
+6 -2
View File
@@ -4,7 +4,7 @@
// Definition of Posix system driver
// for the Fast Light Tool Kit (FLTK).
//
// Copyright 2010-2016 by Bill Spitzak and others.
// Copyright 2010-2018 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -24,7 +24,11 @@
class Fl_X11_System_Driver : public Fl_Posix_System_Driver {
public:
Fl_X11_System_Driver() : Fl_Posix_System_Driver() {}
Fl_X11_System_Driver() : Fl_Posix_System_Driver() {
// X11 system driver does not use a key table
key_table = NULL;
key_table_size = 0;
}
virtual void display_arg(const char *arg);
virtual int XParseGeometry(const char*, int*, int*, unsigned int*, unsigned int*);
virtual int clocale_printf(FILE *output, const char *format, va_list args);
+24
View File
@@ -517,6 +517,30 @@ int Fl_X11_System_Driver::utf8locale() {
return ret;
}
#if !defined(FL_DOXYGEN)
const char *Fl_X11_System_Driver::shortcut_add_key_name(unsigned key, char *p, char *buf, const char **eom)
{
const char* q;
if (key == FL_Enter || key == '\r') q = "Enter"; // don't use Xlib's "Return":
else if (key > 32 && key < 0x100) q = 0;
else q = XKeysymToString(key);
if (!q) {
p += fl_utf8encode(fl_toupper(key), p);
*p = 0;
return buf;
}
if (p > buf) {
strcpy(p,q);
return buf;
} else {
if (eom) *eom = q;
return q;
}
}
#endif // !defined(FL_DOXYGEN)
//
// End of "$Id$".
//
+5 -108
View File
@@ -32,7 +32,6 @@
// This allows punctuation shortcuts like "#" to work (rather than
// calling it "shift+3" on a US keyboard)
#include "config_lib.h"
#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Button.H>
@@ -373,108 +372,6 @@ int Fl_Widget::test_shortcut() {
return test_shortcut(label());
}
#if defined(FL_CFG_GFX_GDI) || defined(FL_PORTING) || defined(__ANDROID__)
// This table must be in numeric order by fltk (X) keysym number:
Fl_System_Driver::Keyname Fl_System_Driver::table[] = {
{' ', "Space"},
{FL_BackSpace, "Backspace"},
{FL_Tab, "Tab"},
{0xff0b/*XK_Clear*/, "Clear"},
{FL_Enter, "Enter"}, // X says "Enter"
{FL_Pause, "Pause"},
{FL_Scroll_Lock, "Scroll_Lock"},
{FL_Escape, "Escape"},
{FL_Home, "Home"},
{FL_Left, "Left"},
{FL_Up, "Up"},
{FL_Right, "Right"},
{FL_Down, "Down"},
{FL_Page_Up, "Page_Up"}, // X says "Prior"
{FL_Page_Down, "Page_Down"}, // X says "Next"
{FL_End, "End"},
{FL_Print, "Print"},
{FL_Insert, "Insert"},
{FL_Menu, "Menu"},
{FL_Num_Lock, "Num_Lock"},
{FL_KP_Enter, "KP_Enter"},
{FL_Shift_L, "Shift_L"},
{FL_Shift_R, "Shift_R"},
{FL_Control_L, "Control_L"},
{FL_Control_R, "Control_R"},
{FL_Caps_Lock, "Caps_Lock"},
{FL_Meta_L, "Meta_L"},
{FL_Meta_R, "Meta_R"},
{FL_Alt_L, "Alt_L"},
{FL_Alt_R, "Alt_R"},
{FL_Delete, "Delete"}
};
#endif
#if defined(FL_CFG_GFX_QUARTZ)
// This table must be in numeric order by fltk (X) keysym number:
Fl_System_Driver::Keyname Fl_System_Driver::table[] = {
// v - this column may contain UTF-8 characters
{' ', "Space"},
{FL_BackSpace, "\xe2\x8c\xab"}, // erase to the left
{FL_Tab, "\xe2\x87\xa5"}, // rightwards arrow to bar
{0xff0b, "\xe2\x8c\xa6"}, // erase to the right
{FL_Enter, "\xe2\x86\xa9"}, // leftwards arrow with hook
{FL_Pause, "Pause"},
{FL_Scroll_Lock, "Scroll_Lock"},
{FL_Escape, "\xe2\x90\x9b"},
{FL_Home, "\xe2\x86\x96"}, // north west arrow
{FL_Left, "\xe2\x86\x90"}, // leftwards arrow
{FL_Up, "\xe2\x86\x91"}, // upwards arrow
{FL_Right, "\xe2\x86\x92"}, // rightwards arrow
{FL_Down, "\xe2\x86\x93"}, // downwards arrow
{FL_Page_Up, "\xe2\x87\x9e"}, // upwards arrow with double stroke
{FL_Page_Down, "\xe2\x87\x9f"}, // downwards arrow with double stroke
{FL_End, "\xe2\x86\x98"}, // south east arrow
{FL_Print, "Print"},
{FL_Insert, "Insert"},
{FL_Menu, "Menu"},
{FL_Num_Lock, "Num_Lock"},
{FL_KP_Enter, "\xe2\x8c\xa4"}, // up arrow head between two horizontal bars
{FL_Shift_L, "Shift_L"},
{FL_Shift_R, "Shift_R"},
{FL_Control_L, "Control_L"},
{FL_Control_R, "Control_R"},
{FL_Caps_Lock, "\xe2\x87\xaa"}, // upwards white arrow from bar
{FL_Meta_L, "Meta_L"},
{FL_Meta_R, "Meta_R"},
{FL_Alt_L, "Alt_L"},
{FL_Alt_R, "Alt_R"},
{FL_Delete, "\xe2\x8c\xa7"} // x in a rectangle box
};
#endif
#if defined(FL_CFG_GFX_XLIB) && !defined(FL_DOXYGEN)
#include "drivers/X11/Fl_X11_System_Driver.H"
#include <X11/Xlib.h>
Fl_System_Driver::Keyname Fl_System_Driver::table[] = {};
const char *Fl_X11_System_Driver::shortcut_add_key_name(unsigned key, char *p, char *buf, const char **eom)
{
const char* q;
if (key == FL_Enter || key == '\r') q="Enter"; // don't use Xlib's "Return":
else if (key > 32 && key < 0x100) q = 0;
else q = XKeysymToString(key);
if (!q) {
p += fl_utf8encode(fl_toupper(key), p);
*p = 0;
return buf;
}
if (p > buf) {
strcpy(p,q);
return buf;
} else {
if (eom) *eom = q;
return q;
}
}
#endif
const char *Fl_System_Driver::shortcut_add_key_name(unsigned key, char *p, char *buf, const char **eom)
{
if (key >= FL_F && key <= FL_F_Last) {
@@ -484,20 +381,20 @@ const char *Fl_System_Driver::shortcut_add_key_name(unsigned key, char *p, char
} else {
// binary search the table for a match:
int a = 0;
int b = sizeof(table)/sizeof(*table);
int b = key_table_size;
while (a < b) {
int c = (a+b)/2;
if (table[c].key == key) {
if (key_table[c].key == key) {
if (p > buf) {
strcpy(p,table[c].name);
strcpy(p,key_table[c].name);
return buf;
} else {
const char *sp = table[c].name;
const char *sp = key_table[c].name;
if (eom) *eom = sp;
return sp;
}
}
if (table[c].key < key) a = c+1;
if (key_table[c].key < key) a = c+1;
else b = c;
}
if (key >= FL_KP && key <= FL_KP_Last) {