From 86ca2b5f066a032cb6cb521384769c5fd0e5cec3 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 21 Mar 2008 14:22:30 +0000 Subject: [PATCH] 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 --- lib/widget/editbox.c | 61 +++++++++++++++++++++++--------------------- lib/widget/editbox.h | 2 +- lib/widget/widget.c | 11 +++----- lib/widget/widget.h | 2 +- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/widget/editbox.c b/lib/widget/editbox.c index 97d3e2231..18f35b794 100644 --- a/lib/widget/editbox.c +++ b/lib/widget/editbox.c @@ -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; } diff --git a/lib/widget/editbox.h b/lib/widget/editbox.h index 8c86d771f..7453c7a70 100644 --- a/lib/widget/editbox.h +++ b/lib/widget/editbox.h @@ -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); diff --git a/lib/widget/widget.c b/lib/widget/widget.c index 5f42b9d96..10722bb6b 100644 --- a/lib/widget/widget.c +++ b/lib/widget/widget.c @@ -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; } diff --git a/lib/widget/widget.h b/lib/widget/widget.h index 138a303ed..bca4aa007 100644 --- a/lib/widget/widget.h +++ b/lib/widget/widget.h @@ -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);