From de2b3ba61d7132dfac0e7cdea016c3394282546b Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 21 Mar 2008 15:40:09 +0000 Subject: [PATCH] Move psRetWidget into the W_SCREEN structure (instead of it being a global variable) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4205 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/widget/button.c | 4 +-- lib/widget/button.h | 4 ++- lib/widget/editbox.c | 6 ++-- lib/widget/editbox.h | 4 ++- lib/widget/form.c | 6 ++-- lib/widget/slider.c | 2 +- lib/widget/slider.h | 2 ++ lib/widget/widgbase.h | 7 +++-- lib/widget/widget.c | 69 +++++++++++++++++++------------------------ lib/widget/widgint.h | 7 ++--- 10 files changed, 55 insertions(+), 56 deletions(-) diff --git a/lib/widget/button.c b/lib/widget/button.c index fede64be8..c5abb539f 100644 --- a/lib/widget/button.c +++ b/lib/widget/button.c @@ -250,7 +250,7 @@ void buttonClicked(W_BUTTON *psWidget, UDWORD key) } /* Respond to a mouse button up */ -void buttonReleased(W_BUTTON *psWidget, UDWORD key) +void buttonReleased(W_SCREEN* psScreen, W_BUTTON* psWidget, UDWORD key) { if (psWidget->state & WBUTS_DOWN) { @@ -258,7 +258,7 @@ void buttonReleased(W_BUTTON *psWidget, UDWORD key) if ((!(psWidget->style & WBUT_NOPRIMARY) && key == WKEY_PRIMARY) || ((psWidget->style & WBUT_SECONDARY) && key == WKEY_SECONDARY)) { - widgSetReturn((WIDGET *)psWidget); + widgSetReturn(psScreen, (WIDGET *)psWidget); psWidget->state &= ~WBUTS_DOWN; } } diff --git a/lib/widget/button.h b/lib/widget/button.h index 5c150270a..f9dbfb8be 100644 --- a/lib/widget/button.h +++ b/lib/widget/button.h @@ -25,6 +25,8 @@ #ifndef _button_h #define _button_h +#include "widgbase.h" + /* Button states */ #define WBUTS_NORMAL 0x0000 #define WBUTS_DOWN 0x0001 // Button is down @@ -68,7 +70,7 @@ extern void buttonRun(W_BUTTON *psWidget); extern void buttonClicked(W_BUTTON *psWidget, UDWORD key); /* Respond to a mouse button up */ -extern void buttonReleased(W_BUTTON *psWidget, UDWORD key); +extern void buttonReleased(W_SCREEN* psScreen, W_BUTTON *psWidget, UDWORD key); /* Respond to a mouse moving over a button */ extern void buttonHiLite(W_BUTTON *psWidget, W_CONTEXT *psContext); diff --git a/lib/widget/editbox.c b/lib/widget/editbox.c index 18f35b794..0a8aa3662 100644 --- a/lib/widget/editbox.c +++ b/lib/widget/editbox.c @@ -519,7 +519,7 @@ void editBoxRun(W_EDITBOX *psWidget, W_CONTEXT *psContext) break; case INPBUF_CR : /* Finish editing */ - editBoxFocusLost(psWidget); + editBoxFocusLost(psContext->psScreen, psWidget); screenClearFocus(psContext->psScreen); return; break; @@ -627,7 +627,7 @@ void editBoxClicked(W_EDITBOX *psWidget, W_CONTEXT *psContext) /* Respond to loss of focus */ -void editBoxFocusLost(W_EDITBOX *psWidget) +void editBoxFocusLost(W_SCREEN* psScreen, W_EDITBOX *psWidget) { ASSERT( !(psWidget->state & WEDBS_DISABLE), "editBoxFocusLost: disabled edit box" ); @@ -638,7 +638,7 @@ void editBoxFocusLost(W_EDITBOX *psWidget) fitStringStart(psWidget->aText,psWidget->width, &psWidget->printChars, &psWidget->printWidth); - widgSetReturn((WIDGET *)psWidget); + widgSetReturn(psScreen, (WIDGET *)psWidget); } diff --git a/lib/widget/editbox.h b/lib/widget/editbox.h index 7453c7a70..a4f1e8b02 100644 --- a/lib/widget/editbox.h +++ b/lib/widget/editbox.h @@ -25,6 +25,8 @@ #ifndef _editbox_h #define _editbox_h +#include "widgbase.h" + /* Edit Box states */ #define WEDBS_FIXED 0x0001 // No editing is going on #define WEDBS_INSERT 0x0002 // Insertion editing @@ -65,7 +67,7 @@ extern void editBoxInitialise(W_EDITBOX *psWidget); extern void editBoxSetString(W_EDITBOX *psWidget, const char *pText); /* Respond to loss of focus */ -extern void editBoxFocusLost(W_EDITBOX *psWidget); +extern void editBoxFocusLost(W_SCREEN* psScreen, W_EDITBOX *psWidget); /* Run an edit box widget */ extern void editBoxRun(W_EDITBOX *psWidget, W_CONTEXT *psContext); diff --git a/lib/widget/form.c b/lib/widget/form.c index c076aeae7..161c71d99 100644 --- a/lib/widget/form.c +++ b/lib/widget/form.c @@ -1192,7 +1192,7 @@ void formReleased(W_FORM *psWidget, UDWORD key, W_CONTEXT *psContext) /* Clicked on a minor tab */ psTabForm->minorT = (UWORD)(sTabPos.index - psTabForm->numMajor); psTabForm->asMajor[psTabForm->majorT].lastMinor = psTabForm->minorT; - widgSetReturn((WIDGET *)psWidget); + widgSetReturn(psContext->psScreen, (WIDGET *)psWidget); } else { @@ -1201,7 +1201,7 @@ void formReleased(W_FORM *psWidget, UDWORD key, W_CONTEXT *psContext) "formReleased: invalid major id %u >= max %u", sTabPos.index, psTabForm->numMajor); psTabForm->majorT = (UWORD)sTabPos.index; psTabForm->minorT = psTabForm->asMajor[sTabPos.index].lastMinor; - widgSetReturn((WIDGET *)psWidget); + widgSetReturn(psContext->psScreen, (WIDGET *)psWidget); } } } @@ -1214,7 +1214,7 @@ void formReleased(W_FORM *psWidget, UDWORD key, W_CONTEXT *psContext) if ((!(psWidget->style & WFORM_NOPRIMARY) && key == WKEY_PRIMARY) || ((psWidget->style & WFORM_SECONDARY) && key == WKEY_SECONDARY)) { - widgSetReturn((WIDGET *)psClickForm); + widgSetReturn(psContext->psScreen, (WIDGET *)psClickForm); psClickForm->state &= ~WCLICK_DOWN; } } diff --git a/lib/widget/slider.c b/lib/widget/slider.c index 1455a0e7d..4c7168b69 100644 --- a/lib/widget/slider.c +++ b/lib/widget/slider.c @@ -234,7 +234,7 @@ void sliderRun(W_SLIDER *psWidget, W_CONTEXT *psContext) if ((psWidget->state & SLD_DRAG) && !mouseDown(MOUSE_LMB)) { psWidget->state &= ~SLD_DRAG; - widgSetReturn((WIDGET *)psWidget); + widgSetReturn(psContext->psScreen, (WIDGET *)psWidget); } else if (psWidget->state & SLD_DRAG) { diff --git a/lib/widget/slider.h b/lib/widget/slider.h index 68814ae0b..c88dfd093 100644 --- a/lib/widget/slider.h +++ b/lib/widget/slider.h @@ -25,6 +25,8 @@ #ifndef _slider_h #define _slider_h +#include "widgbase.h" + /* Slider state */ #define SLD_DRAG 0x0001 // Slider is being dragged #define SLD_HILITE 0x0002 // Slider is hilited diff --git a/lib/widget/widgbase.h b/lib/widget/widgbase.h index c8a426024..d8c7ef36c 100644 --- a/lib/widget/widgbase.h +++ b/lib/widget/widgbase.h @@ -87,9 +87,10 @@ typedef struct _widget /* The screen structure which stores all info for a widget screen */ typedef struct _w_screen { - WIDGET *psForm; // The root form of the screen - WIDGET *psFocus; // The widget that has keyboard focus - int TipFontID; // ID of the IVIS font to use for tool tips. + WIDGET* psForm; ///< The root form of the screen + WIDGET* psFocus; ///< The widget that has keyboard focus + int TipFontID; ///< ID of the IVIS font to use for tool tips. + WIDGET* psRetWidget; ///< The widget to be returned by widgRunScreen } W_SCREEN; /* Context information to pass into the widget functions */ diff --git a/lib/widget/widget.c b/lib/widget/widget.c index 9b1cf2406..cd7229379 100644 --- a/lib/widget/widget.c +++ b/lib/widget/widget.c @@ -37,9 +37,6 @@ #include "slider.h" #include "tip.h" -/* the widget to be returned by widgRunScreen */ -static WIDGET *psRetWidget; - static BOOL bWidgetsActive = TRUE; /* The widget the mouse is over this update */ @@ -910,14 +907,11 @@ void widgSetUserData2(W_SCREEN *psScreen, UDWORD id,UDWORD UserData) /* Return the user data for the returned widget */ void *widgGetLastUserData(W_SCREEN *psScreen) { - /* Don't actually need the screen parameter at the moment - but it might be - handy if psRetWidget needs to stop being a static and moves into - the screen structure */ - (void)psScreen; + assert(psScreen != NULL); - if (psRetWidget) + if (psScreen->psRetWidget) { - return psRetWidget->pUserData; + return psScreen->psRetWidget->pUserData; } return NULL; @@ -1436,7 +1430,7 @@ UDWORD widgRunScreen(W_SCREEN *psScreen) { W_CONTEXT sContext; - psRetWidget = NULL; + psScreen->psRetWidget = NULL; // Note which keys have been pressed pressed = WKEY_NONE; @@ -1477,14 +1471,14 @@ UDWORD widgRunScreen(W_SCREEN *psScreen) widgProcessCallbacks(&sContext); /* Return the ID of a pressed button or finished edit box if any */ - return psRetWidget ? psRetWidget->id : 0; + return psScreen->psRetWidget ? psScreen->psRetWidget->id : 0; } /* Set the id number for widgRunScreen to return */ -void widgSetReturn(WIDGET *psWidget) +void widgSetReturn(W_SCREEN* psScreen, WIDGET *psWidget) { - psRetWidget = psWidget; + psScreen->psRetWidget = psWidget; } @@ -1552,30 +1546,8 @@ void widgDisplayScreen(W_SCREEN *psScreen) tipDisplay(); } - -/* Set the keyboard focus for the screen */ -void screenSetFocus(W_SCREEN *psScreen, WIDGET *psWidget) -{ - if (psScreen->psFocus != NULL) - { - widgFocusLost(psScreen->psFocus); - } - psScreen->psFocus = psWidget; -} - - -/* Clear the keyboard focus */ -void screenClearFocus(W_SCREEN *psScreen) -{ - if (psScreen->psFocus != NULL) - { - widgFocusLost(psScreen->psFocus); - psScreen->psFocus = NULL; - } -} - /* Call the correct function for loss of focus */ -void widgFocusLost(WIDGET *psWidget) +static void widgFocusLost(W_SCREEN* psScreen, WIDGET *psWidget) { switch (psWidget->type) { @@ -1586,7 +1558,7 @@ void widgFocusLost(WIDGET *psWidget) case WIDG_BUTTON: break; case WIDG_EDITBOX: - editBoxFocusLost((W_EDITBOX *)psWidget); + editBoxFocusLost(psScreen, (W_EDITBOX *)psWidget); break; case WIDG_BARGRAPH: break; @@ -1598,6 +1570,27 @@ void widgFocusLost(WIDGET *psWidget) } } +/* Set the keyboard focus for the screen */ +void screenSetFocus(W_SCREEN *psScreen, WIDGET *psWidget) +{ + if (psScreen->psFocus != NULL) + { + widgFocusLost(psScreen, psScreen->psFocus); + } + psScreen->psFocus = psWidget; +} + + +/* Clear the keyboard focus */ +void screenClearFocus(W_SCREEN *psScreen) +{ + if (psScreen->psFocus != NULL) + { + widgFocusLost(psScreen, psScreen->psFocus); + psScreen->psFocus = NULL; + } +} + /* Call the correct function for mouse over */ void widgHiLite(WIDGET *psWidget, W_CONTEXT *psContext) { @@ -1698,7 +1691,7 @@ static void widgReleased(WIDGET *psWidget, UDWORD key, W_CONTEXT *psContext) case WIDG_LABEL: break; case WIDG_BUTTON: - buttonReleased((W_BUTTON *)psWidget, key); + buttonReleased(psContext->psScreen, (W_BUTTON *)psWidget, key); break; case WIDG_EDITBOX: editBoxReleased((W_EDITBOX *)psWidget); diff --git a/lib/widget/widgint.h b/lib/widget/widgint.h index b8c470dae..da5b059dd 100644 --- a/lib/widget/widgint.h +++ b/lib/widget/widgint.h @@ -22,13 +22,15 @@ * * Internal widget library definitions */ + #ifndef _widgint_h #define _widgint_h #include "lib/framework/input.h" +#include "widgbase.h" /* Set the id number for widgRunScreen to return */ -extern void widgSetReturn(WIDGET *psWidget); +extern void widgSetReturn(W_SCREEN* psScreen, WIDGET *psWidget); /* Find a widget in a screen from its ID number */ extern WIDGET *widgGetFromID(W_SCREEN *psScreen, UDWORD id); @@ -42,9 +44,6 @@ extern void widgHiLite(WIDGET *psWidget, W_CONTEXT *psContext); /* Call the correct function for mouse moving off */ extern void widgHiLiteLost(WIDGET *psWidget, W_CONTEXT *psContext); -/* Call the correct function for loss of focus */ -extern void widgFocusLost(WIDGET *psWidget); - /* Set the keyboard focus for the screen */ extern void screenSetFocus(W_SCREEN *psScreen, WIDGET *psWidget);