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
master
Giel van Schijndel 2008-03-21 15:40:09 +00:00
parent b1b2859ea3
commit de2b3ba61d
10 changed files with 55 additions and 56 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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)
{

View File

@ -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

View File

@ -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 */

View File

@ -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);

View File

@ -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);