From 16d213d4ed14add60e286246ad6dc563761b9689 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 12 Aug 2015 17:32:38 +0200 Subject: Passing keyboard events to widgets (not finished yet) --- src/gwin/gwin_widget.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index bfc5a48f..666987ac 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -88,6 +88,7 @@ static const GWidgetStyle * defaultStyle = &BlackWidgetStyle; /* Process an event */ static void gwidgetEvent(void *param, GEvent *pe) { #define pme ((GEventMouse *)pe) + #define pke ((GEventKeyboard *)pe) #define pte ((GEventToggle *)pe) #define pde ((GEventDial *)pe) @@ -142,6 +143,22 @@ static void gwidgetEvent(void *param, GEvent *pe) { break; #endif + #if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD + case GEVENT_KEYBOARD: + // Cycle through all windows + for (gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) { + + // Check whether the widget is enabled and visible + if ((gh->flags & (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED|GWIN_FLG_SYSVISIBLE)) != (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED|GWIN_FLG_SYSVISIBLE)) { + continue; + } + + // Pass the information + wvmt->KeyboardEvent(gw, pke); + } + break; + #endif + #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE case GEVENT_TOGGLE: // Cycle through all windows @@ -235,6 +252,10 @@ void _gwidgetInit(void) geventListenerInit(&gl); geventRegisterCallback(&gl, gwidgetEvent, 0); geventAttachSource(&gl, ginputGetMouse(GMOUSE_ALL_INSTANCES), GLISTEN_MOUSEMETA|GLISTEN_MOUSEDOWNMOVES); + + #if GINPUT_NEED_KEYBOARD + geventAttachSource(&gl, ginputGetKeyboard(GKEYBOARD_ALL_INSTANCES), 0); + #endif } void _gwidgetDeinit(void) -- cgit v1.2.3 From 213013e68e64a655e0c6cb56875ea9a7977fe2f6 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 12 Aug 2015 19:35:44 +0200 Subject: Codingstyle --- src/gwin/gwin_widget.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 666987ac..6002ffa9 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -382,10 +382,10 @@ const GWidgetStyle *gwinGetDefaultStyle(void) { return defaultStyle; } - void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) { - if (!(gh->flags & GWIN_FLG_WIDGET)) + if (!(gh->flags & GWIN_FLG_WIDGET)) { return; + } // Dispose of the old string if ((gh->flags & GWIN_FLG_ALLOCTXT)) { @@ -397,9 +397,9 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) { } // Alloc the new text if required - if (!text || !*text) + if (!text || !*text) { gw->text = ""; - else if (useAlloc) { + } else if (useAlloc) { char *str; if ((str = gfxAlloc(strlen(text)+1))) { @@ -407,8 +407,10 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) { strcpy(str, text); } gw->text = (const char *)str; - } else + } else { gw->text = text; + } + _gwinUpdate(gh); } -- cgit v1.2.3 From 765b1df8c54e3e405561a0529671c0b6f150136a Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 12 Aug 2015 23:28:59 +0200 Subject: Working on widget focus (not finished yet) --- src/gwin/gwin_widget.c | 51 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 6002ffa9..09cc91d8 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -18,10 +18,13 @@ #include "gwin_class.h" -/* Our listener for events for widgets */ -static GListener gl; +// Our listener for events for widgets +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 = { HTML2COLOR(0xFFFFFF), // window background @@ -81,11 +84,11 @@ const GWidgetStyle 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 wvmt ((gwidgetVMT *)gh->vmt) -/* Process an event */ +// Process an event static void gwidgetEvent(void *param, GEvent *pe) { #define pme ((GEventMouse *)pe) #define pke ((GEventKeyboard *)pe) @@ -106,7 +109,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { case GEVENT_MOUSE: case GEVENT_TOUCH: // 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 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 case GEVENT_KEYBOARD: - // Cycle through all windows - for (gh = gwinGetNextWindow(0); gh; gh = gwinGetNextWindow(gh)) { + // If Tab key pressed then set focus to next widget + 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 - if ((gh->flags & (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED|GWIN_FLG_SYSVISIBLE)) != (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED|GWIN_FLG_SYSVISIBLE)) { - continue; + // Otherise, send keyboard events only to widget in focus + if (widgetInFocus != 0) { + // Make sure that it is a widget + if (!(widgetInFocus->flags & GWIN_FLG_WIDGET)) { + break; + } + + // Make sure that the widget is enabled and visible + if (!(widgetInFocus->flags & GWIN_FLG_SYSVISIBLE) || !(widgetInFocus->flags & GWIN_FLG_ENABLED)) { + break; } - // Pass the information - wvmt->KeyboardEvent(gw, pke); + // 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 #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE @@ -249,6 +270,8 @@ static void gwidgetEvent(void *param, GEvent *pe) { void _gwidgetInit(void) { + widgetInFocus = 0; + geventListenerInit(&gl); geventRegisterCallback(&gl, gwidgetEvent, 0); geventAttachSource(&gl, ginputGetMouse(GMOUSE_ALL_INSTANCES), GLISTEN_MOUSEMETA|GLISTEN_MOUSEDOWNMOVES); -- cgit v1.2.3 From e7e4f813e1dcbc608d54e30183ccee0a036e7eb8 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 13 Aug 2015 10:36:56 +0200 Subject: Adding gwinIsWidget() --- src/gwin/gwin_widget.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 09cc91d8..da816cb5 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -21,9 +21,6 @@ // Our listener for events for widgets static GListener gl; -// The widget that is currently in focus. May be NULL. -static GHandle widgetInFocus; - // Our default style - a white background theme const GWidgetStyle WhiteWidgetStyle = { HTML2COLOR(0xFFFFFF), // window background @@ -101,7 +98,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { uint16_t role; #endif (void) param; - +//static GHandle widgetInFocus = 0; // Process various events switch (pe->type) { @@ -127,6 +124,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { // There is only ever one captured mouse. Prevent normal mouse processing if there is a captured mouse gh = 0; + break; } @@ -150,14 +148,35 @@ static void gwidgetEvent(void *param, GEvent *pe) { case GEVENT_KEYBOARD: // If Tab key pressed then set focus to next widget if (pke->bytecount == 1 && pke->c[0] == GKEY_TAB) { - widgetInFocus = gwinGetNextWindow(widgetInFocus); + GHandle nextWidgetInFocus = 0; + bool_t loopCompleted = FALSE; + do { + nextWidgetInFocus = gwinGetNextWindow(gwinGetFocus()); + printf("0x%X\r\n", nextWidgetInFocus); + // We only look out for widgets + if (!gwinIsWidget(nextWidgetInFocus)) { + continue; + } + + if (nextWidgetInFocus == 0) { + loopCompleted = TRUE; + // Restart with the first widget + nextWidgetInFocus = gwinGetNextWindow(gwinGetFocus()); + } + } while (nextWidgetInFocus == 0 && loopCompleted == FALSE); + printf("0x%X\r\n", nextWidgetInFocus); + gwinSetFocus(nextWidgetInFocus); + + /* // If it was the last widget begin with the first one again if (widgetInFocus == 0) { widgetInFocus = gwinGetNextWindow(0); } + */ + //printf("Got now: %s\n", gwinGetClassName(gwinGetFocus())); break; } - +/* // Otherise, send keyboard events only to widget in focus if (widgetInFocus != 0) { // Make sure that it is a widget @@ -178,6 +197,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { // If we got this far we can finally pass the event ((gwidgetVMT*)widgetInFocus->vmt)->KeyboardEvent((GWidgetObject*)widgetInFocus, pke); } +*/ #endif #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE @@ -270,8 +290,6 @@ static void gwidgetEvent(void *param, GEvent *pe) { void _gwidgetInit(void) { - widgetInFocus = 0; - geventListenerInit(&gl); geventRegisterCallback(&gl, gwidgetEvent, 0); geventAttachSource(&gl, ginputGetMouse(GMOUSE_ALL_INSTANCES), GLISTEN_MOUSEMETA|GLISTEN_MOUSEDOWNMOVES); @@ -444,12 +462,22 @@ const char *gwinGetText(GHandle gh) { return gw->text; } +bool_t gwinIsWidget(GHandle gh) { + if (gh->flags & GWIN_FLG_WIDGET) { + return TRUE; + } + + return FALSE; +} + void gwinSetStyle(GHandle gh, const GWidgetStyle *pstyle) { if (!(gh->flags & GWIN_FLG_WIDGET)) return; + gw->pstyle = pstyle ? pstyle : defaultStyle; gh->bgcolor = pstyle->background; gh->color = pstyle->enabled.text; + _gwinUpdate(gh); } -- cgit v1.2.3 From 9f5e19c15106fee1dec5725602b7559c73b29a08 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 14 Aug 2015 14:11:03 +0200 Subject: First implementation of widget focus changing using the TAB key --- src/gwin/gwin_widget.c | 66 +++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index da816cb5..3ba04bde 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -148,39 +148,55 @@ static void gwidgetEvent(void *param, GEvent *pe) { case GEVENT_KEYBOARD: // If Tab key pressed then set focus to next widget if (pke->bytecount == 1 && pke->c[0] == GKEY_TAB) { - GHandle nextWidgetInFocus = 0; - bool_t loopCompleted = FALSE; + + // Get the next widget + bool_t foundWidget = FALSE; + bool_t endOfListDetected = FALSE; + GHandle nextWidget = gwinGetFocus(); do { - nextWidgetInFocus = gwinGetNextWindow(gwinGetFocus()); - printf("0x%X\r\n", nextWidgetInFocus); - // We only look out for widgets - if (!gwinIsWidget(nextWidgetInFocus)) { + nextWidget = gwinGetNextWindow(nextWidget); + foundWidget = TRUE; + + // Begin with the first one if this is the last one + if (nextWidget == 0) { + foundWidget = FALSE; + // We go through the list twice - just to be sure + if (endOfListDetected) { + break; + } + endOfListDetected = TRUE; + continue; + } + + // Check whether this is a window or a widget + if (!gwinIsWidget(nextWidget)) { + foundWidget = FALSE; continue; } - - if (nextWidgetInFocus == 0) { - loopCompleted = TRUE; - // Restart with the first widget - nextWidgetInFocus = gwinGetNextWindow(gwinGetFocus()); + + // Only focus on a widget that is visible and enabled + if (!(nextWidget->flags & GWIN_FLG_SYSVISIBLE) || !(nextWidget->flags & GWIN_FLG_ENABLED)) { + foundWidget = FALSE; + continue; } - } while (nextWidgetInFocus == 0 && loopCompleted == FALSE); - printf("0x%X\r\n", nextWidgetInFocus); - gwinSetFocus(nextWidgetInFocus); - - /* - // If it was the last widget begin with the first one again - if (widgetInFocus == 0) { - widgetInFocus = gwinGetNextWindow(0); - } - */ - //printf("Got now: %s\n", gwinGetClassName(gwinGetFocus())); + + // When using the TAB key we only focus on widgets that process keyboard events + if (((gwidgetVMT*)nextWidget->vmt)->KeyboardEvent == 0) { + foundWidget = FALSE; + continue; + } + + } while (foundWidget == FALSE); + gwinSetFocus(nextWidget); + break; } -/* + // Otherise, send keyboard events only to widget in focus + GHandle widgetInFocus = gwinGetFocus(); if (widgetInFocus != 0) { // Make sure that it is a widget - if (!(widgetInFocus->flags & GWIN_FLG_WIDGET)) { + if (!gwinIsWidget(widgetInFocus)) { break; } @@ -197,7 +213,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { // If we got this far we can finally pass the event ((gwidgetVMT*)widgetInFocus->vmt)->KeyboardEvent((GWidgetObject*)widgetInFocus, pke); } -*/ + #endif #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE -- cgit v1.2.3 From 95d34760e82fa4ce5f13f6d0f25a0a7ce28c2862 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 14 Aug 2015 14:12:51 +0200 Subject: Cleanup --- src/gwin/gwin_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 3ba04bde..1d270a5f 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -98,7 +98,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { uint16_t role; #endif (void) param; -//static GHandle widgetInFocus = 0; + // Process various events switch (pe->type) { -- cgit v1.2.3 From f7075e25ed9bcd701395745161f9ee086c025e21 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 14 Aug 2015 20:48:41 +0200 Subject: More work on the TextEdit --- src/gwin/gwin_widget.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 1d270a5f..9dc4d0d8 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -153,6 +153,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { bool_t foundWidget = FALSE; bool_t endOfListDetected = FALSE; GHandle nextWidget = gwinGetFocus(); + GHandle prevWidget = gwinGetFocus(); do { nextWidget = gwinGetNextWindow(nextWidget); foundWidget = TRUE; @@ -189,6 +190,15 @@ static void gwidgetEvent(void *param, GEvent *pe) { } while (foundWidget == FALSE); gwinSetFocus(nextWidget); + // Redraw the new and the previous focused widget because they usually render differently when + // they are not focused anymore (eg. no blinking cursor) + if (prevWidget != 0) { + gwinRedraw(prevWidget); + } + if (nextWidget != 0) { + gwinRedraw(nextWidget); + } + break; } -- cgit v1.2.3 From 755b7a45ab517a303510b728a9c54e48f9216557 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 14 Aug 2015 23:42:49 +0200 Subject: Adding missing break statement --- src/gwin/gwin_widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 9dc4d0d8..c536b88a 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -223,7 +223,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { // If we got this far we can finally pass the event ((gwidgetVMT*)widgetInFocus->vmt)->KeyboardEvent((GWidgetObject*)widgetInFocus, pke); } - + break; #endif #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE -- cgit v1.2.3 From 668b161f0eead1b9687305281eb59be0e0713bbe Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 14 Aug 2015 23:51:28 +0200 Subject: Adding color to widget style for focused widgets --- src/gwin/gwin_widget.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index c536b88a..f135b306 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -24,13 +24,14 @@ static GListener gl; // Our default style - a white background theme const GWidgetStyle WhiteWidgetStyle = { HTML2COLOR(0xFFFFFF), // window background + HTML2COLOR(0x2A8FCD), // focused // enabled color set { HTML2COLOR(0x000000), // text HTML2COLOR(0x404040), // edge HTML2COLOR(0xE0E0E0), // fill - HTML2COLOR(0xE0E0E0), // progress - inactive area + HTML2COLOR(0xE0E0E0) // progress - inactive area }, // disabled color set @@ -38,7 +39,7 @@ const GWidgetStyle WhiteWidgetStyle = { HTML2COLOR(0xC0C0C0), // text HTML2COLOR(0x808080), // edge HTML2COLOR(0xE0E0E0), // fill - HTML2COLOR(0xC0E0C0), // progress - active area + HTML2COLOR(0xC0E0C0) // progress - active area }, // pressed color set @@ -46,20 +47,21 @@ const GWidgetStyle WhiteWidgetStyle = { HTML2COLOR(0x404040), // text HTML2COLOR(0x404040), // edge HTML2COLOR(0x808080), // fill - HTML2COLOR(0x00E000), // progress - active area - }, + HTML2COLOR(0x00E000) // progress - active area + } }; /* Our black style */ const GWidgetStyle BlackWidgetStyle = { HTML2COLOR(0x000000), // window background + HTML2COLOR(0x2A8FCD), // focused // enabled color set { HTML2COLOR(0xC0C0C0), // text HTML2COLOR(0xC0C0C0), // edge HTML2COLOR(0x606060), // fill - HTML2COLOR(0x404040), // progress - inactive area + HTML2COLOR(0x404040) // progress - inactive area }, // disabled color set @@ -67,7 +69,7 @@ const GWidgetStyle BlackWidgetStyle = { HTML2COLOR(0x808080), // text HTML2COLOR(0x404040), // edge HTML2COLOR(0x404040), // fill - HTML2COLOR(0x004000), // progress - active area + HTML2COLOR(0x004000) // progress - active area }, // pressed color set @@ -75,8 +77,8 @@ const GWidgetStyle BlackWidgetStyle = { HTML2COLOR(0xFFFFFF), // text HTML2COLOR(0xC0C0C0), // edge HTML2COLOR(0xE0E0E0), // fill - HTML2COLOR(0x008000), // progress - active area - }, + HTML2COLOR(0x008000) // progress - active area + } }; static const GWidgetStyle * defaultStyle = &BlackWidgetStyle; -- cgit v1.2.3 From 63c5e4949f63470bd20d2bc35a9fcc0b50795910 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 16 Aug 2015 01:35:46 +0200 Subject: Adding KEYUP events --- src/gwin/gwin_widget.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index f135b306..84168b09 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -151,6 +151,11 @@ static void gwidgetEvent(void *param, GEvent *pe) { // If Tab key pressed then set focus to next widget if (pke->bytecount == 1 && pke->c[0] == GKEY_TAB) { + // Only react on KEYDOWN events. Ignore KEYUP events. + if (pke->keystate & GKEYSTATE_KEYUP) { + break; + } + // Get the next widget bool_t foundWidget = FALSE; bool_t endOfListDetected = FALSE; @@ -323,7 +328,7 @@ void _gwidgetInit(void) geventAttachSource(&gl, ginputGetMouse(GMOUSE_ALL_INSTANCES), GLISTEN_MOUSEMETA|GLISTEN_MOUSEDOWNMOVES); #if GINPUT_NEED_KEYBOARD - geventAttachSource(&gl, ginputGetKeyboard(GKEYBOARD_ALL_INSTANCES), 0); + geventAttachSource(&gl, ginputGetKeyboard(GKEYBOARD_ALL_INSTANCES), GLISTEN_KEYUP); #endif } -- cgit v1.2.3 From 377fe644d1233e955dfd05e40fa9d335447de325 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 16 Aug 2015 14:30:25 +1000 Subject: Coding style, comments, duplicate symbols and other minor fixes --- src/gwin/gwin_widget.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 84168b09..47e60e82 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -152,9 +152,8 @@ static void gwidgetEvent(void *param, GEvent *pe) { if (pke->bytecount == 1 && pke->c[0] == GKEY_TAB) { // Only react on KEYDOWN events. Ignore KEYUP events. - if (pke->keystate & GKEYSTATE_KEYUP) { + if (pke->keystate & GKEYSTATE_KEYUP) break; - } // Get the next widget bool_t foundWidget = FALSE; @@ -169,9 +168,8 @@ static void gwidgetEvent(void *param, GEvent *pe) { if (nextWidget == 0) { foundWidget = FALSE; // We go through the list twice - just to be sure - if (endOfListDetected) { + if (endOfListDetected) break; - } endOfListDetected = TRUE; continue; } @@ -199,12 +197,10 @@ static void gwidgetEvent(void *param, GEvent *pe) { // Redraw the new and the previous focused widget because they usually render differently when // they are not focused anymore (eg. no blinking cursor) - if (prevWidget != 0) { + if (prevWidget != 0) gwinRedraw(prevWidget); - } - if (nextWidget != 0) { + if (nextWidget != 0) gwinRedraw(nextWidget); - } break; } @@ -213,19 +209,16 @@ static void gwidgetEvent(void *param, GEvent *pe) { GHandle widgetInFocus = gwinGetFocus(); if (widgetInFocus != 0) { // Make sure that it is a widget - if (!gwinIsWidget(widgetInFocus)) { + if (!gwinIsWidget(widgetInFocus)) break; - } // Make sure that the widget is enabled and visible - if (!(widgetInFocus->flags & GWIN_FLG_SYSVISIBLE) || !(widgetInFocus->flags & GWIN_FLG_ENABLED)) { + 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) { + 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); @@ -457,9 +450,8 @@ const GWidgetStyle *gwinGetDefaultStyle(void) { } void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) { - if (!(gh->flags & GWIN_FLG_WIDGET)) { + if (!(gh->flags & GWIN_FLG_WIDGET)) return; - } // Dispose of the old string if ((gh->flags & GWIN_FLG_ALLOCTXT)) { @@ -471,9 +463,9 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) { } // Alloc the new text if required - if (!text || !*text) { + if (!text || !*text) gw->text = ""; - } else if (useAlloc) { + else if (useAlloc) { char *str; if ((str = gfxAlloc(strlen(text)+1))) { @@ -481,10 +473,8 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) { strcpy(str, text); } gw->text = (const char *)str; - } else { + } else gw->text = text; - } - _gwinUpdate(gh); } -- cgit v1.2.3 From 15e7342fd7b21b76a565561a3caafee394e70c88 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 16 Aug 2015 21:53:47 +1000 Subject: Updates to focus. --- src/gwin/gwin_widget.c | 182 ++++++++++++++++++++++++++++++------------------- 1 file changed, 112 insertions(+), 70 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 47e60e82..6ef148a6 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -21,6 +21,11 @@ // Our listener for events for widgets static GListener gl; +#if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD + // Our current focus window + static GHandle _widgetInFocus; +#endif + // Our default style - a white background theme const GWidgetStyle WhiteWidgetStyle = { HTML2COLOR(0xFFFFFF), // window background @@ -139,6 +144,14 @@ static void gwidgetEvent(void *param, GEvent *pe) { if (gh && (gh->flags & (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED)) == (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED)) { if ((pme->buttons & GMETA_MOUSE_DOWN)) { gh->flags |= GWIN_FLG_MOUSECAPTURE; + + #if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD + // We should try and capture the focus on this window. + // If we can't no window should have the focus + if (!gwinSetFocus(gh)) + gwinSetFocus(0); + #endif + if (wvmt->MouseDown) wvmt->MouseDown(gw, pme->x - gh->x, pme->y - gh->y); } @@ -150,79 +163,14 @@ static void gwidgetEvent(void *param, GEvent *pe) { case GEVENT_KEYBOARD: // If Tab key pressed then set focus to next widget if (pke->bytecount == 1 && pke->c[0] == GKEY_TAB) { - - // Only react on KEYDOWN events. Ignore KEYUP events. - if (pke->keystate & GKEYSTATE_KEYUP) - break; - - // Get the next widget - bool_t foundWidget = FALSE; - bool_t endOfListDetected = FALSE; - GHandle nextWidget = gwinGetFocus(); - GHandle prevWidget = gwinGetFocus(); - do { - nextWidget = gwinGetNextWindow(nextWidget); - foundWidget = TRUE; - - // Begin with the first one if this is the last one - if (nextWidget == 0) { - foundWidget = FALSE; - // We go through the list twice - just to be sure - if (endOfListDetected) - break; - endOfListDetected = TRUE; - continue; - } - - // Check whether this is a window or a widget - if (!gwinIsWidget(nextWidget)) { - foundWidget = FALSE; - continue; - } - - // Only focus on a widget that is visible and enabled - if (!(nextWidget->flags & GWIN_FLG_SYSVISIBLE) || !(nextWidget->flags & GWIN_FLG_ENABLED)) { - foundWidget = FALSE; - continue; - } - - // When using the TAB key we only focus on widgets that process keyboard events - if (((gwidgetVMT*)nextWidget->vmt)->KeyboardEvent == 0) { - foundWidget = FALSE; - continue; - } - - } while (foundWidget == FALSE); - gwinSetFocus(nextWidget); - - // Redraw the new and the previous focused widget because they usually render differently when - // they are not focused anymore (eg. no blinking cursor) - if (prevWidget != 0) - gwinRedraw(prevWidget); - if (nextWidget != 0) - gwinRedraw(nextWidget); - + if (!(pke->keystate & GKEYSTATE_KEYUP)) + _gwinMoveFocus(); break; } - // Otherise, send keyboard events only to widget in focus - GHandle widgetInFocus = gwinGetFocus(); - if (widgetInFocus != 0) { - // Make sure that it is a widget - if (!gwinIsWidget(widgetInFocus)) - break; - - // Make sure that the widget is enabled and visible - 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); - } + // Otherwise, send keyboard events only to widget in focus + if (_widgetInFocus) + ((gwidgetVMT*)_widgetInFocus->vmt)->KeyboardEvent((GWidgetObject*)_widgetInFocus, pke); break; #endif @@ -278,6 +226,96 @@ static void gwidgetEvent(void *param, GEvent *pe) { #undef pde } +#if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD + GHandle gwinGetFocus(void) { + return _widgetInFocus; + } + + bool_t gwinSetFocus(GHandle gh) { + GHandle oldFocus; + + // Do we already have the focus? + if (gh == _widgetInFocus) + return TRUE; + + // The new window must be NULLL or a visible enabled widget with a keyboard handler + if (!gh || ((gh->flags & (GWIN_FLG_WIDGET|GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED|GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE)) == (GWIN_FLG_WIDGET|GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED|GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE) + && ((gwidgetVMT*)gh->vmt)->KeyboardEvent)) { + // Move the current focus + oldFocus = _widgetInFocus; + _widgetInFocus = gh; + if (oldFocus) _gwinUpdate(oldFocus); + if (gh) _gwinUpdate(gh); + return TRUE; + } + return FALSE; + } + + void _gwinMoveFocus(void) { + GHandle gh; + + // Find a new focus window (one may or may not exist). + for(gh = gwinGetNextWindow(_widgetInFocus); gh && gh != _widgetInFocus; gh = gwinGetNextWindow(gh)) { + if (gwinSetFocus(gh)) + return; + } + gwinSetFocus(0); + } + + void _gwinFixFocus(GHandle gh) { + GHandle oldFocus; + + if ((gh->flags & (GWIN_FLG_WIDGET|GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED|GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE)) == (GWIN_FLG_WIDGET|GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED|GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE) + && ((gwidgetVMT*)gh->vmt)->KeyboardEvent) { + + // We are a candidate to be able to claim the focus + + // Claim the focus if no-one else has + if (!_widgetInFocus) + _widgetInFocus = gh; + + return; + } + + // We have lost any right to the focus + + // Did we have the focus + if (gh != _widgetInFocus) + return; + + // We did - we need to find a new focus window + oldFocus = _widgetInFocus; + for(gh = gwinGetNextWindow(oldFocus); gh && gh != oldFocus; gh = gwinGetNextWindow(gh)) { + + // Must be a visible enabled widget with a keyboard handler + if ((gh->flags & (GWIN_FLG_WIDGET|GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED|GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE)) == (GWIN_FLG_WIDGET|GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED|GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE) + && ((gwidgetVMT*)gh->vmt)->KeyboardEvent) { + + // Grab the focus for the new window + _widgetInFocus = gh; + + // This new window still needs to be marked for redraw (but don't actually do it yet). + gh->flags |= GWIN_FLG_NEEDREDRAW; + RedrawPending |= DOREDRAW_VISIBLES; + return; + } + } + + // No-one has the right to the focus + _widgetInFocus = 0; + } + + void _gwidgetDrawFocusRect(GWidgetObject *gw, coord_t x, coord_t y, coord_t cx, coord_t cy) { + // Don't do anything if we don't have the focus + if (&gw->g != _widgetInFocus) + return; + + // Use the very simplest possible focus rectangle for now. + gdispGDrawBox(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, gw->pstyle.focus); + } + +#endif + #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE static GHandle FindToggleUser(uint16_t instance) { GHandle gh; @@ -355,6 +393,10 @@ void _gwidgetDestroy(GHandle gh) { uint16_t role, instance; #endif + // Make the window is invisible so it is not eligible for focus + gh->flags &= ~GWIN_FLG_VISIBLE; + _gwinFixFocus(gh); + // Deallocate the text (if necessary) if ((gh->flags & GWIN_FLG_ALLOCTXT)) { gh->flags &= ~GWIN_FLG_ALLOCTXT; -- cgit v1.2.3 From af76c04767f3e5d1cc6f39ba907a7d4afdb43200 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 16 Aug 2015 22:05:32 +1000 Subject: Compile fixes --- src/gwin/gwin_widget.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 6ef148a6..fceb65c8 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -223,6 +223,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { #undef pme #undef pte + #undef pke #undef pde } @@ -296,7 +297,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { // This new window still needs to be marked for redraw (but don't actually do it yet). gh->flags |= GWIN_FLG_NEEDREDRAW; - RedrawPending |= DOREDRAW_VISIBLES; + // RedrawPending |= DOREDRAW_VISIBLES; - FIX LATER return; } } @@ -305,13 +306,13 @@ static void gwidgetEvent(void *param, GEvent *pe) { _widgetInFocus = 0; } - void _gwidgetDrawFocusRect(GWidgetObject *gw, coord_t x, coord_t y, coord_t cx, coord_t cy) { + void _gwidgetDrawFocusRect(GWidgetObject *gx, coord_t x, coord_t y, coord_t cx, coord_t cy) { // Don't do anything if we don't have the focus - if (&gw->g != _widgetInFocus) + if (&gx->g != _widgetInFocus) return; // Use the very simplest possible focus rectangle for now. - gdispGDrawBox(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, gw->pstyle.focus); + gdispGDrawBox(gx->g.display, gx->g.x+x, gx->g.y+y, cx, cy, gx->pstyle->focus); } #endif -- cgit v1.2.3 From 058a873e9e425207db8b99be083e87cf956b9827 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 16 Aug 2015 14:37:12 +0200 Subject: Adding GWIN_FOCUS_HIGHLIGHT_WIDTH --- src/gwin/gwin_widget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index fceb65c8..162d41e3 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -311,8 +311,11 @@ static void gwidgetEvent(void *param, GEvent *pe) { if (&gx->g != _widgetInFocus) return; - // Use the very simplest possible focus rectangle for now. - gdispGDrawBox(gx->g.display, gx->g.x+x, gx->g.y+y, cx, cy, gx->pstyle->focus); + // Use the very simplest possible focus rectangle for now + uint16_t i = 0; + for (i = 0; i < GWIN_FOCUS_HIGHLIGHT_WIDTH; i++) { + gdispGDrawBox(gx->g.display, gx->g.x+x+i, gx->g.y+y+i, cx-2*i, cy-2*i, gx->pstyle->focus); + } } #endif -- cgit v1.2.3 From 5e8e0b7744a59c5bbf918a5133b55c3d1beef12f Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 13 Oct 2015 00:58:31 +1000 Subject: Working TextEdit with on-screen keyboard (and real keyboard) --- src/gwin/gwin_widget.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/gwin/gwin_widget.c') diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index 162d41e3..1bf91b11 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -145,11 +145,10 @@ static void gwidgetEvent(void *param, GEvent *pe) { if ((pme->buttons & GMETA_MOUSE_DOWN)) { gh->flags |= GWIN_FLG_MOUSECAPTURE; - #if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD + #if (GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD) || GWIN_NEED_KEYBOARD // We should try and capture the focus on this window. - // If we can't no window should have the focus - if (!gwinSetFocus(gh)) - gwinSetFocus(0); + // If we can't then we don't change the focus + gwinSetFocus(gh); #endif if (wvmt->MouseDown) @@ -159,7 +158,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { break; #endif - #if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD + #if (GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD) || GWIN_NEED_KEYBOARD case GEVENT_KEYBOARD: // If Tab key pressed then set focus to next widget if (pke->bytecount == 1 && pke->c[0] == GKEY_TAB) { @@ -227,7 +226,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { #undef pde } -#if GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD +#if (GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD) || GWIN_NEED_KEYBOARD GHandle gwinGetFocus(void) { return _widgetInFocus; } @@ -254,13 +253,18 @@ static void gwidgetEvent(void *param, GEvent *pe) { void _gwinMoveFocus(void) { GHandle gh; + bool_t looponce; // Find a new focus window (one may or may not exist). - for(gh = gwinGetNextWindow(_widgetInFocus); gh && gh != _widgetInFocus; gh = gwinGetNextWindow(gh)) { + looponce = FALSE; + for(gh = gwinGetNextWindow(_widgetInFocus); ; gh = gwinGetNextWindow(gh)) { + if (!gh && !looponce) { + looponce = TRUE; + gh = gwinGetNextWindow(0); + } if (gwinSetFocus(gh)) - return; + break; } - gwinSetFocus(0); } void _gwinFixFocus(GHandle gh) { -- cgit v1.2.3