Clean up editBoxCreate and widgAddEditBox:

* Make editBoxCreate and widgAddEditBox take their psInit parameters as const
 * Make editBoxCreate return the button it created or NULL on failure


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4198 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-03-21 14:22:30 +00:00
parent 6ea7968f46
commit 86ca2b5f06
4 changed files with 38 additions and 38 deletions

View File

@ -55,64 +55,67 @@
static void fitStringStart(char *pBuffer, UDWORD boxWidth, UWORD *pCount, UWORD *pCharWidth);
/* Create an edit box widget data structure */
BOOL editBoxCreate(W_EDITBOX **ppsWidget, W_EDBINIT *psInit)
W_EDITBOX* editBoxCreate(const W_EDBINIT* psInit)
{
W_EDITBOX* psWidget;
if (psInit->style & ~(WEDB_PLAIN | WIDG_HIDDEN | WEDB_DISABLED))
{
ASSERT( FALSE, "Unknown edit box style" );
return FALSE;
return NULL;
}
/* Allocate the required memory */
*ppsWidget = (W_EDITBOX *)malloc(sizeof(W_EDITBOX));
if (*ppsWidget == NULL)
psWidget = (W_EDITBOX *)malloc(sizeof(W_EDITBOX));
if (psWidget == NULL)
{
ASSERT( FALSE, "Out of memory" );
return FALSE;
debug(LOG_ERROR, "editBoxCreate: Out of memory");
abort();
return NULL;
}
/* Initialise the structure */
(*ppsWidget)->type = WIDG_EDITBOX;
(*ppsWidget)->id = psInit->id;
(*ppsWidget)->formID = psInit->formID;
(*ppsWidget)->style = psInit->style;
(*ppsWidget)->x = psInit->x;
(*ppsWidget)->y = psInit->y;
(*ppsWidget)->width = psInit->width;
(*ppsWidget)->height = psInit->height;
(*ppsWidget)->FontID = psInit->FontID;
psWidget->type = WIDG_EDITBOX;
psWidget->id = psInit->id;
psWidget->formID = psInit->formID;
psWidget->style = psInit->style;
psWidget->x = psInit->x;
psWidget->y = psInit->y;
psWidget->width = psInit->width;
psWidget->height = psInit->height;
psWidget->FontID = psInit->FontID;
if (psInit->pDisplay)
{
(*ppsWidget)->display = psInit->pDisplay;
psWidget->display = psInit->pDisplay;
}
else
{
(*ppsWidget)->display = editBoxDisplay;
psWidget->display = editBoxDisplay;
}
(*ppsWidget)->callback = psInit->pCallback;
(*ppsWidget)->pUserData = psInit->pUserData;
(*ppsWidget)->UserData = psInit->UserData;
(*ppsWidget)->pBoxDisplay = psInit->pBoxDisplay;
(*ppsWidget)->pFontDisplay = psInit->pFontDisplay;
psWidget->callback = psInit->pCallback;
psWidget->pUserData = psInit->pUserData;
psWidget->UserData = psInit->UserData;
psWidget->pBoxDisplay = psInit->pBoxDisplay;
psWidget->pFontDisplay = psInit->pFontDisplay;
(*ppsWidget)->AudioCallback = WidgGetAudioCallback();
(*ppsWidget)->HilightAudioID = WidgGetHilightAudioID();
(*ppsWidget)->ClickedAudioID = WidgGetClickedAudioID();
psWidget->AudioCallback = WidgGetAudioCallback();
psWidget->HilightAudioID = WidgGetHilightAudioID();
psWidget->ClickedAudioID = WidgGetClickedAudioID();
if (psInit->pText)
{
strlcpy((*ppsWidget)->aText, psInit->pText, sizeof((*ppsWidget)->aText));
strlcpy(psWidget->aText, psInit->pText, sizeof(psWidget->aText));
}
else
{
(*ppsWidget)->aText[0] = '\0';
psWidget->aText[0] = '\0';
}
editBoxInitialise(*ppsWidget);
editBoxInitialise(psWidget);
init_scrap();
return TRUE;
return psWidget;
}

View File

@ -53,7 +53,7 @@ typedef struct _w_editbox
} W_EDITBOX;
/* Create an edit box widget data structure */
extern BOOL editBoxCreate(W_EDITBOX **ppsWidget, W_EDBINIT *psInit);
extern W_EDITBOX* editBoxCreate(const W_EDBINIT* psInit);
/* Free the memory used by an edit box */
extern void editBoxFree(W_EDITBOX *psWidget);

View File

@ -393,7 +393,7 @@ BOOL widgAddButton(W_SCREEN *psScreen, const W_BUTINIT* psInit)
/* Add an edit box to the widget screen */
BOOL widgAddEditBox(W_SCREEN *psScreen, W_EDBINIT *psInit)
BOOL widgAddEditBox(W_SCREEN *psScreen, const W_EDBINIT* psInit)
{
W_EDITBOX *psEdBox;
W_FORM *psForm;
@ -424,13 +424,10 @@ BOOL widgAddEditBox(W_SCREEN *psScreen, W_EDBINIT *psInit)
}
/* Create the edit box structure */
if (!editBoxCreate(&psEdBox, psInit))
{
return FALSE;
}
psEdBox = editBoxCreate(psInit);
if (psEdBox == NULL
/* Add it to the form */
if (!formAddWidget(psForm, (WIDGET *)psEdBox, (W_INIT *)psInit))
|| !formAddWidget(psForm, (WIDGET *)psEdBox, (W_INIT *)psInit))
{
return FALSE;
}

View File

@ -302,7 +302,7 @@ extern BOOL widgAddLabel(W_SCREEN *psScreen, const W_LABINIT* psInit);
extern BOOL widgAddButton(W_SCREEN *psScreen, const W_BUTINIT* psInit);
/* Add an edit box to a form */
extern BOOL widgAddEditBox(W_SCREEN *psScreen, W_EDBINIT *psInit);
extern BOOL widgAddEditBox(W_SCREEN *psScreen, const W_EDBINIT* psInit);
/* Add a bar graph to a form */
extern BOOL widgAddBarGraph(W_SCREEN *psScreen, const W_BARINIT* psInit);