Add some keyboard widget support
This commit is contained in:
parent
058a873e9e
commit
3fea023248
17 changed files with 73 additions and 38 deletions
|
@ -63,7 +63,10 @@
|
||||||
|
|
||||||
/* Features for the GINPUT subsystem. */
|
/* Features for the GINPUT subsystem. */
|
||||||
#define GINPUT_NEED_MOUSE TRUE
|
#define GINPUT_NEED_MOUSE TRUE
|
||||||
|
|
||||||
|
/* One or both of these */
|
||||||
#define GINPUT_NEED_KEYBOARD TRUE
|
#define GINPUT_NEED_KEYBOARD TRUE
|
||||||
|
#define GWIN_NEED_KEYBOARD TRUE
|
||||||
|
|
||||||
/* Features for the GQUEUE subsystem. */
|
/* Features for the GQUEUE subsystem. */
|
||||||
#define GFX_USE_GQUEUE TRUE
|
#define GFX_USE_GQUEUE TRUE
|
||||||
|
|
|
@ -34,6 +34,9 @@ static GHandle ghTextedit1;
|
||||||
static GHandle ghTextedit2;
|
static GHandle ghTextedit2;
|
||||||
static GHandle ghTextedit3;
|
static GHandle ghTextedit3;
|
||||||
static GListener gl;
|
static GListener gl;
|
||||||
|
#if GWIN_NEED_KEYBOARD
|
||||||
|
static GHandle ghKeyboard;
|
||||||
|
#endif
|
||||||
|
|
||||||
static void guiCreate(void)
|
static void guiCreate(void)
|
||||||
{
|
{
|
||||||
|
@ -80,6 +83,17 @@ static void guiCreate(void)
|
||||||
wi.text = "the different widgets";
|
wi.text = "the different widgets";
|
||||||
ghTextedit3 = gwinTexteditCreate(0, &wi, 100);
|
ghTextedit3 = gwinTexteditCreate(0, &wi, 100);
|
||||||
//gwinTexteditSetBorder(ghTextedit3, TRUE);
|
//gwinTexteditSetBorder(ghTextedit3, TRUE);
|
||||||
|
|
||||||
|
// Virtual keyboard
|
||||||
|
#if GWIN_NEED_KEYBOARD
|
||||||
|
wi.g.show = TRUE;
|
||||||
|
wi.g.x = 0;
|
||||||
|
wi.g.y = gdispGetHeight()*3/4;
|
||||||
|
wi.g.width = gdispGetWidth();
|
||||||
|
wi.g.height = gdispGetHeight()/4;
|
||||||
|
ghKeyboard = gwinKeyboardCreate(0, &wi);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
|
@ -164,13 +164,11 @@ typedef struct GEventKeyboard_t {
|
||||||
#define GLISTEN_KEYTRANSITIONS 0x0008 // Return transitions to the key state
|
#define GLISTEN_KEYTRANSITIONS 0x0008 // Return transitions to the key state
|
||||||
#define GLISTEN_KEYRAW 0x0010 // Return raw scan-codes. This turns off normal character processing.
|
#define GLISTEN_KEYRAW 0x0010 // Return raw scan-codes. This turns off normal character processing.
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if GINPUT_NEED_KEYBOARD || defined(__DOXYGEN__)
|
|
||||||
|
|
||||||
// All keyboards
|
// All keyboards
|
||||||
#define GKEYBOARD_ALL_INSTANCES ((unsigned)-1)
|
#define GKEYBOARD_ALL_INSTANCES ((unsigned)-1)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -188,6 +186,8 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
GSourceHandle ginputGetKeyboard(unsigned instance);
|
GSourceHandle ginputGetKeyboard(unsigned instance);
|
||||||
|
|
||||||
|
#if GINPUT_NEED_KEYBOARD || defined(__DOXYGEN__)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the current keyboard status
|
* @brief Get the current keyboard status
|
||||||
*
|
*
|
||||||
|
@ -209,12 +209,11 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
bool_t ginputSetKeyboardLayout(unsigned instance, const void *pLayout);
|
bool_t ginputSetKeyboardLayout(unsigned instance, const void *pLayout);
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* GINPUT_NEED_KEYBOARD */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* GINPUT_NEED_KEYBOARD */
|
|
||||||
|
|
||||||
#endif /* _GINPUT_KEYBOARD_H */
|
#endif /* _GINPUT_KEYBOARD_H */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
static void ButtonKeyboard(GWidgetObject* gw, GEventKeyboard* pke)
|
static void ButtonKeyboard(GWidgetObject* gw, GEventKeyboard* pke)
|
||||||
{
|
{
|
||||||
// ENTER and SPACE keys to press the button
|
// ENTER and SPACE keys to press the button
|
||||||
|
@ -113,7 +113,7 @@ static const gwidgetVMT buttonVMT = {
|
||||||
0, // Process mouse move events (NOT USED)
|
0, // Process mouse move events (NOT USED)
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
ButtonKeyboard // Process keyboard events
|
ButtonKeyboard // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -55,7 +55,7 @@ static void SendCheckboxEvent(GWidgetObject *gw) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
static void CheckboxKeyboard(GWidgetObject* gw, GEventKeyboard* pke)
|
static void CheckboxKeyboard(GWidgetObject* gw, GEventKeyboard* pke)
|
||||||
{
|
{
|
||||||
// Only react on KEYDOWN events. Ignore KEYUP events.
|
// Only react on KEYDOWN events. Ignore KEYUP events.
|
||||||
|
@ -108,7 +108,7 @@ static const gwidgetVMT checkboxVMT = {
|
||||||
0, // Process mouse move events (NOT USED)
|
0, // Process mouse move events (NOT USED)
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
CheckboxKeyboard // Process keyboard events
|
CheckboxKeyboard // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -96,7 +96,7 @@ typedef struct gwinVMT {
|
||||||
void (*MouseMove) (GWidgetObject *gw, coord_t x, coord_t y); /**< Process mouse move events (optional) */
|
void (*MouseMove) (GWidgetObject *gw, coord_t x, coord_t y); /**< Process mouse move events (optional) */
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
struct {
|
struct {
|
||||||
void (*KeyboardEvent) (GWidgetObject *gw, GEventKeyboard *pke); /**< Process keyboard events (optional) */
|
void (*KeyboardEvent) (GWidgetObject *gw, GEventKeyboard *pke); /**< Process keyboard events (optional) */
|
||||||
};
|
};
|
||||||
|
|
|
@ -110,7 +110,7 @@ static const gcontainerVMT containerVMT = {
|
||||||
0, 0, 0, // No mouse
|
0, 0, 0, // No mouse
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard events
|
0 // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -178,7 +178,7 @@ static const gcontainerVMT frameVMT = {
|
||||||
0, // Process mouse move events
|
0, // Process mouse move events
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard events
|
0 // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,6 +30,8 @@ typedef uint32_t utf32;
|
||||||
// A character code - note this is not UTF-32 but a representation of the UTF-8 code stream for a single character.
|
// A character code - note this is not UTF-32 but a representation of the UTF-8 code stream for a single character.
|
||||||
typedef uint32_t ucode;
|
typedef uint32_t ucode;
|
||||||
|
|
||||||
|
static GSourceHandle AllKeyboards;
|
||||||
|
|
||||||
// Get the length of a UTF-8 string
|
// Get the length of a UTF-8 string
|
||||||
static int UTF8StrLen(const utf8 *s) {
|
static int UTF8StrLen(const utf8 *s) {
|
||||||
int len;
|
int len;
|
||||||
|
@ -164,6 +166,11 @@ static void SendKeyboardEventToListener(GSourceListener *psl, GKeyboardObject *g
|
||||||
static void SendKeyboardEvent(GKeyboardObject *gk) {
|
static void SendKeyboardEvent(GKeyboardObject *gk) {
|
||||||
GSourceListener *psl;
|
GSourceListener *psl;
|
||||||
|
|
||||||
|
// Send to the "All Keyboards" source listeners
|
||||||
|
psl = 0;
|
||||||
|
while ((psl = geventGetSourceListener(AllKeyboards, psl)))
|
||||||
|
SendKeyboardEventToListener(psl, gk);
|
||||||
|
|
||||||
// Send to the keyboard specific source listeners
|
// Send to the keyboard specific source listeners
|
||||||
psl = 0;
|
psl = 0;
|
||||||
while ((psl = geventGetSourceListener((GSourceHandle)gk, psl)))
|
while ((psl = geventGetSourceListener((GSourceHandle)gk, psl)))
|
||||||
|
@ -313,7 +320,7 @@ static const gwidgetVMT keyboardVMT = {
|
||||||
KeyMouseMove, // Process mouse move events
|
KeyMouseMove, // Process mouse move events
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard events
|
0 // Process keyboard events
|
||||||
},
|
},
|
||||||
|
@ -344,6 +351,10 @@ GHandle gwinGKeyboardCreate(GDisplay *g, GKeyboardObject *gk, const GWidgetInit
|
||||||
gk->keytable = &GWIN_KEYBOARD_DEFAULT_LAYOUT;
|
gk->keytable = &GWIN_KEYBOARD_DEFAULT_LAYOUT;
|
||||||
gk->keyset = gk->keytable->ksets[0];
|
gk->keyset = gk->keytable->ksets[0];
|
||||||
gk->lastkeyrow = gk->lastkeycol = gk->keyrow = gk->keycol = GKEY_BAD_ROWCOL;
|
gk->lastkeyrow = gk->lastkeycol = gk->keyrow = gk->keycol = GKEY_BAD_ROWCOL;
|
||||||
|
|
||||||
|
if (!AllKeyboards)
|
||||||
|
AllKeyboards = ginputGetKeyboard(GKEYBOARD_ALL_INSTANCES);
|
||||||
|
|
||||||
gwinSetVisible((GHandle)gk, pInit->g.show);
|
gwinSetVisible((GHandle)gk, pInit->g.show);
|
||||||
return (GHandle)gk;
|
return (GHandle)gk;
|
||||||
}
|
}
|
||||||
|
@ -473,4 +484,12 @@ void gwinKeyboardDraw_Normal(GWidgetObject *gw, void *param) {
|
||||||
#undef gk
|
#undef gk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !(GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD)
|
||||||
|
GSourceHandle ginputGetKeyboard(unsigned instance) {
|
||||||
|
if (instance == GKEYBOARD_ALL_INSTANCES)
|
||||||
|
return (GSourceHandle)&AllKeyboards;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* GFX_USE_GWIN && GWIN_NEED_KEYBOARD */
|
#endif /* GFX_USE_GWIN && GWIN_NEED_KEYBOARD */
|
||||||
|
|
|
@ -58,7 +58,7 @@ static const gwidgetVMT labelVMT = {
|
||||||
0, // Process mouse move events (NOT USED)
|
0, // Process mouse move events (NOT USED)
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard key down events
|
0 // Process keyboard key down events
|
||||||
},
|
},
|
||||||
|
|
|
@ -279,7 +279,7 @@ static const gwidgetVMT listVMT = {
|
||||||
ListMouseMove,
|
ListMouseMove,
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard events
|
0 // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -51,7 +51,7 @@ static const gwidgetVMT progressbarVMT = {
|
||||||
0, // Process mouse move events
|
0, // Process mouse move events
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard events
|
0 // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -92,7 +92,7 @@ static const gwidgetVMT radioVMT = {
|
||||||
0, // Process mouse move events (NOT USED)
|
0, // Process mouse move events (NOT USED)
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard events
|
0 // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -127,8 +127,8 @@
|
||||||
#if !GDISP_NEED_TEXT
|
#if !GDISP_NEED_TEXT
|
||||||
#error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_TEXTEDIT is TRUE."
|
#error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_TEXTEDIT is TRUE."
|
||||||
#endif
|
#endif
|
||||||
#if !GINPUT_NEED_KEYBOARD
|
#if !(GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD)
|
||||||
#error "GWIN: GINPUT_NEED_KEYBOARD is required if GWIN_NEED_TEXTEDIT is TRUE."
|
#error "GWIN: GINPUT_NEED_KEYBOARD or GWIN_NEED_KEYBOARD is required if GWIN_NEED_TEXTEDIT is TRUE."
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -250,7 +250,7 @@ static const gwidgetVMT sliderVMT = {
|
||||||
SliderMouseMove, // Process mouse move events
|
SliderMouseMove, // Process mouse move events
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard events
|
0 // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -77,7 +77,7 @@ static const gcontainerVMT tabpageVMT = {
|
||||||
0, // Process mouse move events
|
0, // Process mouse move events
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
0 // Process keyboard events
|
0 // Process keyboard events
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,7 +61,7 @@ static void _shiftTextRight(char* buffer, size_t maxSize, size_t index, char fil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
static void TextEditKeyboard(GWidgetObject* gw, GEventKeyboard* pke)
|
static void TextEditKeyboard(GWidgetObject* gw, GEventKeyboard* pke)
|
||||||
{
|
{
|
||||||
// Only react on KEYDOWN events. Ignore KEYUP events.
|
// Only react on KEYDOWN events. Ignore KEYUP events.
|
||||||
|
@ -146,7 +146,7 @@ static const gwidgetVMT texteditVMT = {
|
||||||
0, // Process mouse move events (NOT USED)
|
0, // Process mouse move events (NOT USED)
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if GINPUT_NEED_KEYBOARD
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
||||||
{
|
{
|
||||||
TextEditKeyboard // Process keyboard key down events
|
TextEditKeyboard // Process keyboard key down events
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue