From 9e8b38ba943b339b966b1011bab899720d6305fc Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:25:31 +1000 Subject: Add gwinClearInit() and gwinWidgetClearInit() to clear gwin initialisation structures. Incorporate into demo's --- src/gwin/gwidget.c | 8 ++++++++ src/gwin/gwidget.h | 16 ++++++++++++++++ src/gwin/gwin.c | 8 ++++++++ src/gwin/sys_defs.h | 18 +++++++++++++++++- 4 files changed, 49 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index 181b7425..c46520ea 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -297,6 +297,14 @@ void _gwidgetRedraw(GHandle gh) { gw->fnDraw(gw, gw->fnParam); } +void gwinWidgetClearInit(GWidgetInit *pwi) { + char *p; + unsigned len; + + for(p = (char *)pwi, len = sizeof(GWidgetInit); len; len--) + *p++ = 0; +} + void gwinSetDefaultStyle(const GWidgetStyle *pstyle, bool_t updateAll) { if (!pstyle) pstyle = &BlackWidgetStyle; diff --git a/src/gwin/gwidget.h b/src/gwin/gwidget.h index 96832fe3..8373e2d0 100644 --- a/src/gwin/gwidget.h +++ b/src/gwin/gwidget.h @@ -78,6 +78,10 @@ typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param); * @brief The structure to initialise a widget. * * @note Some widgets may have extra parameters. + * @note If you create this structure on the stack, you should always memset + * it to all zero's first in case a future version of the software + * add's extra fields. Alternatively you can use @p gwinWidgetClearInit() + * to clear it. * @note The text element must be static string (not stack allocated). If you want to use * a dynamic string (eg a stack allocated string) use NULL for this member and then call * @p gwinSetText() with useAlloc set to TRUE. @@ -126,6 +130,18 @@ typedef struct GWidgetObject { extern "C" { #endif +/** + * @brief Clear a GWidgetInit structure to all zero's + * @note This function is provided just to prevent problems + * on operating systems where using memset() causes issues + * in the users application. + * + * @param[in] pwi The GWidgetInit structure to clear + * + * @api + */ +void gwinWidgetClearInit(GWidgetInit *pwi); + /** * @brief Set the default style for widgets created hereafter. * diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 54f42077..93c17f3a 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -149,6 +149,14 @@ GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit * Routines that affect all windows *-----------------------------------------------*/ +void gwinClearInit(GWindowInit *pwi) { + char *p; + unsigned len; + + for(p = (char *)pwi, len = sizeof(GWindowInit); len; len--) + *p++ = 0; +} + void gwinSetDefaultColor(color_t clr) { defaultFgColor = clr; } diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index f4e1c2f7..fa5084a3 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -34,7 +34,7 @@ */ typedef struct GWindowObject { #if GWIN_NEED_WINDOWMANAGER - // This MUST be the first member of the struct + // This MUST be the first member of the structure gfxQueueASyncItem wmq; // @< The next window (for the window manager) #endif const struct gwinVMT *vmt; // @< The VMT for this GWIN @@ -54,6 +54,10 @@ typedef struct GWindowObject { * * @note Some gwin's will need extra parameters. * @note The dimensions and position may be changed to fit on the real screen. + * @note If you create this structure on the stack, you should always memset + * it to all zero's first in case a future version of the software + * add's extra fields. Alternatively you can use @p gwinClearInit() + * to clear it. * * @{ */ @@ -102,6 +106,18 @@ extern "C" { * Functions that affect all windows *-------------------------------------------------*/ + /** + * @brief Clear a GWindowInit structure to all zero's + * @note This function is provided just to prevent problems + * on operating systems where using memset() causes issues + * in the users application. + * + * @param[in] pwi The GWindowInit structure to clear + * + * @api + */ + void gwinClearInit(GWindowInit *pwi); + /** * @brief Set the default foreground color for all new GWIN windows * -- cgit v1.2.3