From 761644653302b09e65fabff51eea5e30ae0ebf35 Mon Sep 17 00:00:00 2001 From: pouillot Date: Mon, 7 Feb 2011 09:35:37 +0000 Subject: [PATCH] Re #333 (D26 : New / enhanced menu controls) Added GfuiComboboxGetNumberOfChoices + cleaned up the combobox code git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3334 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: d43e042a3a934bc74cede329b65e526e100b65a2 Former-commit-id: d2897d7a96131ce406370c6d13550cd2b0ec991e --- src/libs/tgfclient/guicombobox.cpp | 225 ++++++++++------------------- src/libs/tgfclient/tgfclient.h | 1 + 2 files changed, 77 insertions(+), 149 deletions(-) diff --git a/src/libs/tgfclient/guicombobox.cpp b/src/libs/tgfclient/guicombobox.cpp index c09243b49..3f147b184 100644 --- a/src/libs/tgfclient/guicombobox.cpp +++ b/src/libs/tgfclient/guicombobox.cpp @@ -202,29 +202,38 @@ gfuiDrawCombobox(tGfuiObject *obj) //Do nothing because children already draw themselves } +static tGfuiCombobox* +gfuiGetCombobox(void *scr, int id) +{ + tGfuiScreen *screen = (tGfuiScreen*)scr; + tGfuiObject* curObject = screen->objects; + + if (curObject) + { + do + { + curObject = curObject->next; + if (curObject->id == id && curObject->widget == GFUI_COMBOBOX) + return &(curObject->u.combobox); + } + while (curObject != screen->objects); + } + + return 0; +} + unsigned int GfuiComboboxAddText(void *scr, int id, const char *text) { - tGfuiObject *curObject; - tGfuiScreen *screen = (tGfuiScreen*)scr; unsigned int index = 0; - - curObject = screen->objects; - if (curObject != NULL) { - do { - curObject = curObject->next; - if (curObject->id == id) { - if (curObject->widget == GFUI_COMBOBOX) - { - tGfuiCombobox *combo = &(curObject->u.combobox); - combo->pInfo->vecChoices.push_back(text); - index = combo->pInfo->vecChoices.size(); - GfuiLabelSetText(combo->scr, combo->labelId, - combo->pInfo->vecChoices[combo->pInfo->nPos].c_str()); - } - return index; - } - } while (curObject != screen->objects); + tGfuiCombobox* combo = gfuiGetCombobox(scr, id); + + if (combo) + { + combo->pInfo->vecChoices.push_back(text); + index = combo->pInfo->vecChoices.size(); + GfuiLabelSetText(combo->scr, combo->labelId, + combo->pInfo->vecChoices[combo->pInfo->nPos].c_str()); } return index; @@ -233,53 +242,23 @@ GfuiComboboxAddText(void *scr, int id, const char *text) void GfuiComboboxSetSelectedIndex(void *scr, int id, unsigned int index) { - tGfuiObject *curObject; - tGfuiScreen *screen = (tGfuiScreen*)scr; - - curObject = screen->objects; - if (curObject != NULL) { - do { - curObject = curObject->next; - if (curObject->id == id) { - if (curObject->widget == GFUI_COMBOBOX) - { - tGfuiCombobox *combo = &(curObject->u.combobox); - if (combo->pInfo->vecChoices.size()<= index) - return; - - combo->pInfo->nPos = index; - GfuiLabelSetText(combo->scr, combo->labelId, - combo->pInfo->vecChoices[combo->pInfo->nPos].c_str()); - } - return; - } - } while (curObject != screen->objects); - } - + tGfuiCombobox* combo = gfuiGetCombobox(scr, id); + + if (combo && index < combo->pInfo->vecChoices.size()) + { + combo->pInfo->nPos = index; + GfuiLabelSetText(combo->scr, combo->labelId, + combo->pInfo->vecChoices[combo->pInfo->nPos].c_str()); + } } void GfuiComboboxSetTextColor(void *scr, int id, const Color& color) { - tGfuiObject *curObject; - tGfuiScreen *screen = (tGfuiScreen*)scr; - - curObject = screen->objects; - if (curObject != NULL) { - do { - curObject = curObject->next; - if (curObject->id == id) { - if (curObject->widget == GFUI_COMBOBOX) - { - tGfuiCombobox *combo = &(curObject->u.combobox); - GfuiLabelSetColor(combo->scr, combo->labelId, color.GetPtr()); - } - return; - } - } while (curObject != screen->objects); - } - - return; + tGfuiCombobox* combo = gfuiGetCombobox(scr, id); + + if (combo) + GfuiLabelSetColor(combo->scr, combo->labelId, color.GetPtr()); } @@ -287,120 +266,68 @@ GfuiComboboxSetTextColor(void *scr, int id, const Color& color) void GfuiComboboxSetPosition(void *scr, int id, unsigned int pos) { - tGfuiObject *curObject; - tGfuiScreen *screen = (tGfuiScreen*)scr; - unsigned int index = 0; - - curObject = screen->objects; - if (curObject != NULL) - { - do { - curObject = curObject->next; - if (curObject->id == id) - { - if (curObject->widget == GFUI_COMBOBOX) - { - tGfuiCombobox *combo = &(curObject->u.combobox); - combo->pInfo->nPos = pos; - } - return; - } - } while (curObject != screen->objects); - } - + tGfuiCombobox* combo = gfuiGetCombobox(scr, id); + + if (combo) + combo->pInfo->nPos = pos; } unsigned int GfuiComboboxGetPosition(void *scr, int id) { - tGfuiObject *curObject; - tGfuiScreen *screen = (tGfuiScreen*)scr; unsigned int index = 0; - curObject = screen->objects; - if (curObject != NULL) - { - do - { - curObject = curObject->next; - if (curObject->id == id) - { - if (curObject->widget == GFUI_COMBOBOX) - { - tGfuiCombobox *combo = &(curObject->u.combobox); - return combo->pInfo->nPos; - } - return 0; - } - } while (curObject != screen->objects); - } + tGfuiCombobox* combo = gfuiGetCombobox(scr, id); + + if (combo) + index = combo->pInfo->nPos; - return 0; + return index; } const char* GfuiComboboxGetText(void *scr, int id) { - tGfuiObject *curObject; - tGfuiScreen *screen = (tGfuiScreen*)scr; - char* pszText = 0; + const char* pszText = 0; - curObject = screen->objects; - if (curObject != NULL) - { - do - { - curObject = curObject->next; - if (curObject->id == id) - { - if (curObject->widget == GFUI_COMBOBOX) - { - tGfuiCombobox *combo = &(curObject->u.combobox); - if (combo->pInfo->nPos >= 0 - && combo->pInfo->nPos < combo->pInfo->vecChoices.size()) - return combo->pInfo->vecChoices[combo->pInfo->nPos].c_str(); - } - return 0; - } - } while (curObject != screen->objects); - } + tGfuiCombobox* combo = gfuiGetCombobox(scr, id); + + if (combo && combo->pInfo->nPos >= 0 && combo->pInfo->nPos < combo->pInfo->vecChoices.size()) + pszText = combo->pInfo->vecChoices[combo->pInfo->nPos].c_str(); return pszText; } +unsigned +GfuiComboboxGetNumberOfChoices(void *scr, int id) +{ + unsigned nChoices = 0; + + tGfuiCombobox* combo = gfuiGetCombobox(scr, id); + + if (combo) + nChoices = combo->pInfo->vecChoices.size(); + + return nChoices; +} + + void GfuiComboboxClear(void *scr, int id) { - tGfuiObject *curObject; - tGfuiScreen *screen = (tGfuiScreen*)scr; - - curObject = screen->objects; - if (curObject != NULL) + tGfuiCombobox* combo = gfuiGetCombobox(scr, id); + + if (combo) { - do - { - curObject = curObject->next; - if (curObject->id == id) - { - if (curObject->widget == GFUI_COMBOBOX) - { - tGfuiCombobox *combo = &(curObject->u.combobox); - combo->pInfo->nPos = 0; - combo->pInfo->vecChoices.clear(); - GfuiLabelSetText(combo->scr, combo->labelId, ""); - } - break; - } - } while (curObject != screen->objects); - } + combo->pInfo->nPos = 0; + combo->pInfo->vecChoices.clear(); + GfuiLabelSetText(combo->scr, combo->labelId, ""); + } } void gfuiReleaseCombobox(tGfuiObject *obj) { - tGfuiCombobox *combobox; - - combobox = &(obj->u.combobox); - delete combobox->pInfo; + delete obj->u.combobox.pInfo; free(obj); } diff --git a/src/libs/tgfclient/tgfclient.h b/src/libs/tgfclient/tgfclient.h index bce3259b2..ad6c71fae 100644 --- a/src/libs/tgfclient/tgfclient.h +++ b/src/libs/tgfclient/tgfclient.h @@ -397,6 +397,7 @@ TGFCLIENT_API void GfuiComboboxSetPosition(void *scr, int id, unsigned int pos); TGFCLIENT_API unsigned int GfuiComboboxGetPosition(void *scr, int id); TGFCLIENT_API const char* GfuiComboboxGetText(void *scr, int id); TGFCLIENT_API void GfuiComboboxClear(void *scr, int id); +TGFCLIENT_API unsigned GfuiComboboxGetNumberOfChoices(void *scr, int id); TGFCLIENT_API int GfuiProgressbarCreate(void *scr, int x, int y, int w, int h, const char *pszProgressbackImg, const char *progressbarimg,