Working on widget focus (not finished yet)

ugfx_release_2.6
Joel Bodenmann 2015-08-12 23:28:59 +02:00
parent f1ede211fb
commit 765b1df8c5
1 changed files with 37 additions and 14 deletions

View File

@ -18,10 +18,13 @@
#include "gwin_class.h" #include "gwin_class.h"
/* Our listener for events for widgets */ // Our listener for events for widgets
static GListener gl; static GListener gl;
/* Our default style - a white background theme */ // The widget that is currently in focus. May be NULL.
static GHandle widgetInFocus;
// Our default style - a white background theme
const GWidgetStyle WhiteWidgetStyle = { const GWidgetStyle WhiteWidgetStyle = {
HTML2COLOR(0xFFFFFF), // window background HTML2COLOR(0xFFFFFF), // window background
@ -81,11 +84,11 @@ const GWidgetStyle BlackWidgetStyle = {
static const GWidgetStyle * defaultStyle = &BlackWidgetStyle; static const GWidgetStyle * defaultStyle = &BlackWidgetStyle;
/* We use these everywhere in this file */ // We use these everywhere in this file
#define gw ((GWidgetObject *)gh) #define gw ((GWidgetObject *)gh)
#define wvmt ((gwidgetVMT *)gh->vmt) #define wvmt ((gwidgetVMT *)gh->vmt)
/* Process an event */ // Process an event
static void gwidgetEvent(void *param, GEvent *pe) { static void gwidgetEvent(void *param, GEvent *pe) {
#define pme ((GEventMouse *)pe) #define pme ((GEventMouse *)pe)
#define pke ((GEventKeyboard *)pe) #define pke ((GEventKeyboard *)pe)
@ -106,7 +109,7 @@ static void gwidgetEvent(void *param, GEvent *pe) {
case GEVENT_MOUSE: case GEVENT_MOUSE:
case GEVENT_TOUCH: case GEVENT_TOUCH:
// Cycle through all windows // Cycle through all windows
for(gh = 0, h = gwinGetNextWindow(0); h; h = gwinGetNextWindow(h)) { for (gh = 0, h = gwinGetNextWindow(0); h; h = gwinGetNextWindow(h)) {
// The window must be on this display and visible to be relevant // The window must be on this display and visible to be relevant
if (h->display != pme->display || !(h->flags & GWIN_FLG_SYSVISIBLE)) if (h->display != pme->display || !(h->flags & GWIN_FLG_SYSVISIBLE))
@ -145,18 +148,36 @@ static void gwidgetEvent(void *param, GEvent *pe) {
#if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD #if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD
case GEVENT_KEYBOARD: case GEVENT_KEYBOARD:
// Cycle through all windows // If Tab key pressed then set focus to next widget
for (gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) { if (pke->bytecount == 1 && pke->c[0] == GKEY_TAB) {
widgetInFocus = gwinGetNextWindow(widgetInFocus);
// If it was the last widget begin with the first one again
if (widgetInFocus == 0) {
widgetInFocus = gwinGetNextWindow(0);
}
break;
}
// Check whether the widget is enabled and visible // Otherise, send keyboard events only to widget in focus
if ((gh->flags & (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED|GWIN_FLG_SYSVISIBLE)) != (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED|GWIN_FLG_SYSVISIBLE)) { if (widgetInFocus != 0) {
continue; // Make sure that it is a widget
if (!(widgetInFocus->flags & GWIN_FLG_WIDGET)) {
break;
} }
// Pass the information // Make sure that the widget is enabled and visible
wvmt->KeyboardEvent(gw, pke); if (!(widgetInFocus->flags & GWIN_FLG_SYSVISIBLE) || !(widgetInFocus->flags & GWIN_FLG_ENABLED)) {
break;
}
// Check whether this widget provides a method for handling keyboard events
if (((gwidgetVMT*)widgetInFocus->vmt)->KeyboardEvent == 0) {
break;
}
// If we got this far we can finally pass the event
((gwidgetVMT*)widgetInFocus->vmt)->KeyboardEvent((GWidgetObject*)widgetInFocus, pke);
} }
break;
#endif #endif
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
@ -249,6 +270,8 @@ static void gwidgetEvent(void *param, GEvent *pe) {
void _gwidgetInit(void) void _gwidgetInit(void)
{ {
widgetInFocus = 0;
geventListenerInit(&gl); geventListenerInit(&gl);
geventRegisterCallback(&gl, gwidgetEvent, 0); geventRegisterCallback(&gl, gwidgetEvent, 0);
geventAttachSource(&gl, ginputGetMouse(GMOUSE_ALL_INSTANCES), GLISTEN_MOUSEMETA|GLISTEN_MOUSEDOWNMOVES); geventAttachSource(&gl, ginputGetMouse(GMOUSE_ALL_INSTANCES), GLISTEN_MOUSEMETA|GLISTEN_MOUSEDOWNMOVES);