Rewrite Fl_get_key.cxx under the driver model.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11545 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-04-06 20:30:28 +00:00
parent a2eeca92f0
commit f3462a2abe
9 changed files with 38 additions and 26 deletions

View File

@ -93,7 +93,6 @@ set (CPPFILES
Fl_arg.cxx
Fl_compose.cxx
Fl_display.cxx
Fl_get_key.cxx
Fl_get_system_colors.cxx
Fl_grab.cxx
Fl_lock.cxx
@ -187,6 +186,7 @@ if (USE_X11)
fl_dnd_x.cxx
Fl_Native_File_Chooser_FLTK.cxx
Fl_Native_File_Chooser_GTK.cxx
Fl_get_key.cxx
)
if (USE_XFT)
set (DRIVER_FILES ${DRIVER_FILES}
@ -252,6 +252,7 @@ elseif (APPLE)
drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
drivers/Darwin/Fl_Darwin_System_Driver.cxx
Fl_get_key_mac.cxx
)
set (DRIVER_HEADER_FILES
drivers/Darwin/Fl_Darwin_System_Driver.H
@ -283,6 +284,7 @@ else ()
Fl_win32.cxx
fl_dnd_win32.cxx
Fl_Native_File_Chooser_WIN32.cxx
Fl_get_key_win32.cxx
)
set (DRIVER_HEADER_FILES
drivers/WinAPI/Fl_WinAPI_System_Driver.H

View File

@ -1896,6 +1896,14 @@ void Fl::insertion_point_location(int x, int y, int height) { // sets window coo
Fl::screen_driver()->insertion_point_location(x, y, height);
}
int Fl::event_key(int k) {
return system_driver()->event_key(k);
}
int Fl::get_key(int k) {
return system_driver()->get_key(k);
}
//
// End of "$Id$".
//

View File

@ -16,24 +16,17 @@
// http://www.fltk.org/str.php
//
#ifdef WIN32
# include "Fl_get_key_win32.cxx"
#elif defined(__APPLE__) // PORTME: Fl_Screen_Driver - platform keyboard stuff
# include "Fl_get_key_mac.cxx"
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: implement keyboard reading and interpretation in its own file"
#else
// Return the current state of a key. This is the X version. I identify
// keys (mostly) by the X keysym. So this turns the keysym into a keycode
// and looks it up in the X key bit vector, which Fl_x.cxx keeps track of.
# include <FL/Fl.H>
# include <FL/x.H>
#include <FL/Fl.H>
#include "drivers/Posix/Fl_Posix_System_Driver.H"
#include <FL/x.H> // for fl_display
extern char fl_key_vector[32]; // in Fl_x.cxx
int Fl::event_key(int k) {
int Fl_Posix_System_Driver::event_key(int k) {
if (k > FL_Button && k <= FL_Button+8)
return Fl::event_state(8<<(k-FL_Button));
int i;
@ -49,14 +42,12 @@ int Fl::event_key(int k) {
return fl_key_vector[i/8] & (1 << (i%8));
}
int Fl::get_key(int k) {
int Fl_Posix_System_Driver::get_key(int k) {
fl_open_display();
XQueryKeymap(fl_display, fl_key_vector);
return event_key(k);
}
#endif
//
// End of "$Id$".
//

View File

@ -237,12 +237,12 @@ static int fltk2mac(int fltk) {
}
//: returns true, if that key was pressed during the last event
int Fl::event_key(int k) {
int Fl_Darwin_System_Driver::event_key(int k) {
return get_key(k);
}
//: returns true, if that key is pressed right now
int Fl::get_key(int k) {
int Fl_Darwin_System_Driver::get_key(int k) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if (&CGEventSourceKeyState != NULL) {
return (int)CGEventSourceKeyState(kCGEventSourceStateCombinedSessionState, fltk2mac(k) );

View File

@ -20,7 +20,7 @@
// which are actually X keysyms. So this has to translate to MSWindows
// VK_x symbols.
#include <FL/Fl.H>
#include "drivers/WinAPI//Fl_WinAPI_System_Driver.H"
#include <FL/x.H>
// convert an Fltk (X) keysym to a MSWindows VK symbol:
@ -115,11 +115,11 @@ static int fltk2ms(int fltk) {
return 0;
}
int Fl::event_key(int k) {
int Fl_WinAPI_System_Driver::event_key(int k) {
return GetKeyState(fltk2ms(k))&~1;
}
int Fl::get_key(int k) {
int Fl_WinAPI_System_Driver::get_key(int k) {
uchar foo[256];
GetKeyboardState(foo);
return foo[fltk2ms(k)]&~1;

View File

@ -112,7 +112,6 @@ CPPFILES = \
Fl_arg.cxx \
Fl_compose.cxx \
Fl_display.cxx \
Fl_get_key.cxx \
Fl_get_system_colors.cxx \
Fl_grab.cxx \
Fl_lock.cxx \
@ -231,7 +230,8 @@ QUARTZCPPFILES = \
drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx \
drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx \
drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx \
drivers/Darwin/Fl_Darwin_System_Driver.cxx
drivers/Darwin/Fl_Darwin_System_Driver.cxx \
Fl_get_key_mac.cxx
# These C++ files are used under condition: BUILD_X11
XLIBCPPFILES = \
@ -252,7 +252,8 @@ XLIBCPPFILES = \
Fl_x.cxx \
fl_dnd_x.cxx \
Fl_Native_File_Chooser_FLTK.cxx \
Fl_Native_File_Chooser_GTK.cxx
Fl_Native_File_Chooser_GTK.cxx \
Fl_get_key.cxx
# This C file is used under condition: BUILD_X11
XLIBCFILES = \
@ -290,7 +291,8 @@ GDICPPFILES = \
drivers/WinAPI/Fl_WinAPI_Printer_Driver.cxx \
Fl_win32.cxx \
fl_dnd_win32.cxx \
Fl_Native_File_Chooser_WIN32.cxx
Fl_Native_File_Chooser_WIN32.cxx \
Fl_get_key_win32.cxx
PSCPPFILES = \
drivers/PostScript/Fl_PostScript.cxx \
@ -591,7 +593,8 @@ include makedepend
# they are part of the WIN32 and MacOS code base...
# Please add only non-Linux/Unix files or such that are optional
# (like "*xft*") here:
Fl_get_key.o: Fl_get_key_mac.cxx Fl_get_key_win32.cxx
Fl_get_key_mac.o: Fl_get_key_mac.cxx
Fl_get_key_win32.o: Fl_get_key_win32.cxx
Fl_Native_File_Chooser_WIN32.o : Fl_Native_File_Chooser_WIN32.cxx
Fl_Native_File_Chooser_MAC.o: Fl_Native_File_Chooser_MAC.mm
Fl_Native_File_Chooser_FLTK.o: Fl_Native_File_Chooser_FLTK.cxx
@ -616,7 +619,6 @@ fl_encoding_latin1.o: ../FL/mac.H ../FL/win32.H
fl_encoding_mac_roman.o: ../FL/mac.H ../FL/win32.H
Fl_File_Chooser2.o: ../FL/mac.H ../FL/win32.H
fl_font.o: ../FL/mac.H ../FL/win32.H
Fl_get_key.o: ../FL/mac.H ../FL/win32.H
Fl_get_system_colors.o: ../FL/mac.H ../FL/win32.H
Fl_Gl_Choice.o: ../FL/mac.H ../FL/win32.H
Fl_Gl_Overlay.o: ../FL/mac.H ../FL/win32.H

View File

@ -65,6 +65,9 @@ public:
virtual int clocale_printf(FILE *output, const char *format, va_list args);
static void *get_carbon_function(const char *name);
static int calc_mac_os_version(); // computes the fl_mac_os_version global variable
// these 2 are in Fl_get_key_mac.cxx
virtual int event_key(int k);
virtual int get_key(int k);
};
#endif // FL_DARWIN_SYSTEM_DRIVER_H

View File

@ -62,6 +62,9 @@ public:
virtual int rmdir(const char* f) {return ::rmdir(f);}
virtual int rename(const char* f, const char *n) {return ::rename(f, n);}
virtual int clocale_printf(FILE *output, const char *format, va_list args);
// these 2 are in Fl_get_key.cxx
virtual int event_key(int k);
virtual int get_key(int k);
};
#endif // FL_POSIX_SYSTEM_DRIVER_H

View File

@ -65,6 +65,9 @@ public:
virtual unsigned utf8to_mb(const char* src, unsigned srclen, char* dst, unsigned dstlen);
virtual unsigned utf8from_mb(char* dst, unsigned dstlen, const char* src, unsigned srclen);
virtual int clocale_printf(FILE *output, const char *format, va_list args);
// these 2 are in Fl_get_key_win32.cxx
virtual int event_key(int k);
virtual int get_key(int k);
};
#endif // FL_WINAPI_SYSTEM_DRIVER_H