Add GWIN List multi-select support
This commit is contained in:
parent
b0b3539639
commit
312e759124
@ -20,7 +20,7 @@ static void createWidgets(void) {
|
|||||||
wi.text = "List Name";
|
wi.text = "List Name";
|
||||||
|
|
||||||
// Create the actual list
|
// Create the actual list
|
||||||
ghList1 = gwinListCreate(NULL, &wi);
|
ghList1 = gwinListCreate(NULL, &wi, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
@ -76,7 +76,7 @@ static GHandle ghCheckbox1, ghCheckbox2, ghCheckDisableAll;
|
|||||||
static GHandle ghLabel1;
|
static GHandle ghLabel1;
|
||||||
static GHandle ghRadio1, ghRadio2;
|
static GHandle ghRadio1, ghRadio2;
|
||||||
static GHandle ghRadioBlack, ghRadioWhite, ghRadioYellow;
|
static GHandle ghRadioBlack, ghRadioWhite, ghRadioYellow;
|
||||||
static GHandle ghList1;
|
static GHandle ghList1, ghList2;
|
||||||
static GHandle ghImage1;
|
static GHandle ghImage1;
|
||||||
|
|
||||||
/* Some useful macros */
|
/* Some useful macros */
|
||||||
@ -163,21 +163,22 @@ static void createWidgets(void) {
|
|||||||
// Lists
|
// Lists
|
||||||
wi.g.show = FALSE; wi.customDraw = 0;
|
wi.g.show = FALSE; wi.customDraw = 0;
|
||||||
wi.g.width = LIST_WIDTH; wi.g.height = LIST_HEIGHT; wi.g.y = TAB_HEIGHT+5;
|
wi.g.width = LIST_WIDTH; wi.g.height = LIST_HEIGHT; wi.g.y = TAB_HEIGHT+5;
|
||||||
wi.g.x = 0+0*(LIST_WIDTH+1); wi.text = "L1"; ghList1 = gwinListCreate(NULL, &wi);
|
wi.g.x = 0+0*(LIST_WIDTH+1); wi.text = "L1"; ghList1 = gwinListCreate(NULL, &wi, FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 0", FALSE);
|
gwinListAddItem(ghList1, "Item 0", FALSE); gwinListAddItem(ghList1, "Item 1", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 1", FALSE);
|
gwinListAddItem(ghList1, "Item 2", FALSE); gwinListAddItem(ghList1, "Item 3", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 2", FALSE);
|
gwinListAddItem(ghList1, "Item 4", FALSE); gwinListAddItem(ghList1, "Item 5", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 3", FALSE);
|
gwinListAddItem(ghList1, "Item 6", FALSE); gwinListAddItem(ghList1, "Item 7", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 4", FALSE);
|
gwinListAddItem(ghList1, "Item 8", FALSE); gwinListAddItem(ghList1, "Item 9", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 5", FALSE);
|
gwinListAddItem(ghList1, "Item 10", FALSE); gwinListAddItem(ghList1, "Item 11", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 6", FALSE);
|
gwinListAddItem(ghList1, "Item 12", FALSE); gwinListAddItem(ghList1, "Item 13", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 7", FALSE);
|
wi.g.x = 0+1*(LIST_WIDTH+1); wi.text = "L2"; ghList2 = gwinListCreate(NULL, &wi, TRUE);
|
||||||
gwinListAddItem(ghList1, "Item 8", FALSE);
|
gwinListAddItem(ghList2, "Item 0", FALSE); gwinListAddItem(ghList2, "Item 1", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 9", FALSE);
|
gwinListAddItem(ghList2, "Item 2", FALSE); gwinListAddItem(ghList2, "Item 3", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 10", FALSE);
|
gwinListAddItem(ghList2, "Item 4", FALSE); gwinListAddItem(ghList2, "Item 5", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 11", FALSE);
|
gwinListAddItem(ghList2, "Item 6", FALSE); gwinListAddItem(ghList2, "Item 7", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 12", FALSE);
|
gwinListAddItem(ghList2, "Item 8", FALSE); gwinListAddItem(ghList2, "Item 9", FALSE);
|
||||||
gwinListAddItem(ghList1, "Item 13", FALSE);
|
gwinListAddItem(ghList2, "Item 10", FALSE); gwinListAddItem(ghList2, "Item 11", FALSE);
|
||||||
|
gwinListAddItem(ghList2, "Item 12", FALSE); gwinListAddItem(ghList2, "Item 13", FALSE);
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
wi.g.x = ScrWidth-210; wi.g.y = TAB_HEIGHT + 10; wi.g.width = 200; wi.g.height = 200;
|
wi.g.x = ScrWidth-210; wi.g.y = TAB_HEIGHT + 10; wi.g.width = 200; wi.g.height = 200;
|
||||||
@ -206,7 +207,7 @@ static void setTab(GHandle tab) {
|
|||||||
gwinSetVisible(ghLabel1, FALSE);
|
gwinSetVisible(ghLabel1, FALSE);
|
||||||
gwinSetVisible(ghRadio1, FALSE); gwinSetVisible(ghRadio2, FALSE);
|
gwinSetVisible(ghRadio1, FALSE); gwinSetVisible(ghRadio2, FALSE);
|
||||||
gwinSetVisible(ghRadioWhite, FALSE);gwinSetVisible(ghRadioBlack, FALSE);gwinSetVisible(ghRadioYellow, FALSE);
|
gwinSetVisible(ghRadioWhite, FALSE);gwinSetVisible(ghRadioBlack, FALSE);gwinSetVisible(ghRadioYellow, FALSE);
|
||||||
gwinSetVisible(ghList1, FALSE);
|
gwinSetVisible(ghList1, FALSE); gwinSetVisible(ghList2, FALSE);
|
||||||
gwinSetVisible(ghImage1, FALSE);
|
gwinSetVisible(ghImage1, FALSE);
|
||||||
|
|
||||||
/* Turn on widgets depending on the tab selected */
|
/* Turn on widgets depending on the tab selected */
|
||||||
@ -224,7 +225,7 @@ static void setTab(GHandle tab) {
|
|||||||
gwinSetVisible(ghRadio1, TRUE); gwinSetVisible(ghRadio2, TRUE);
|
gwinSetVisible(ghRadio1, TRUE); gwinSetVisible(ghRadio2, TRUE);
|
||||||
gwinSetVisible(ghRadioWhite, TRUE); gwinSetVisible(ghRadioBlack, TRUE); gwinSetVisible(ghRadioYellow, TRUE);
|
gwinSetVisible(ghRadioWhite, TRUE); gwinSetVisible(ghRadioBlack, TRUE); gwinSetVisible(ghRadioYellow, TRUE);
|
||||||
} else if (tab == ghTabLists) {
|
} else if (tab == ghTabLists) {
|
||||||
gwinSetVisible(ghList1, TRUE);
|
gwinSetVisible(ghList1, TRUE); gwinSetVisible(ghList2, TRUE);
|
||||||
} else if (tab == ghTabImages) {
|
} else if (tab == ghTabImages) {
|
||||||
gwinSetVisible(ghImage1, TRUE);
|
gwinSetVisible(ghImage1, TRUE);
|
||||||
}
|
}
|
||||||
@ -241,6 +242,7 @@ static void setEnabled(bool_t ena) {
|
|||||||
gwinSetEnabled(ghCheckbox1, ena); gwinSetEnabled(ghCheckbox2, ena); //gwinSetEnabled(ghCheckDisableAll, TRUE);
|
gwinSetEnabled(ghCheckbox1, ena); gwinSetEnabled(ghCheckbox2, ena); //gwinSetEnabled(ghCheckDisableAll, TRUE);
|
||||||
gwinSetEnabled(ghLabel1, ena);
|
gwinSetEnabled(ghLabel1, ena);
|
||||||
gwinSetEnabled(ghRadio1, ena); gwinSetEnabled(ghRadio2, ena);
|
gwinSetEnabled(ghRadio1, ena); gwinSetEnabled(ghRadio2, ena);
|
||||||
|
gwinSetEnabled(ghList1, ena); gwinSetEnabled(ghList2, ena);
|
||||||
gwinSetEnabled(ghRadioWhite, ena); gwinSetEnabled(ghRadioBlack, ena); gwinSetEnabled(ghRadioYellow, ena);
|
gwinSetEnabled(ghRadioWhite, ena); gwinSetEnabled(ghRadioBlack, ena); gwinSetEnabled(ghRadioYellow, ena);
|
||||||
gwinSetEnabled(ghImage1, ena);
|
gwinSetEnabled(ghImage1, ena);
|
||||||
}
|
}
|
||||||
@ -309,7 +311,8 @@ int main(void) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case GEVENT_GWIN_LIST:
|
case GEVENT_GWIN_LIST:
|
||||||
gwinPrintf(ghConsole, "List %s Item %d\n", gwinGetText(((GEventGWinList *)pe)->list), ((GEventGWinList *)pe)->item);
|
gwinPrintf(ghConsole, "List %s Item %d %s\n", gwinGetText(((GEventGWinList *)pe)->list), ((GEventGWinList *)pe)->item,
|
||||||
|
gwinListItemIsSelected(((GEventGWinList *)pe)->list, ((GEventGWinList *)pe)->item) ? "Selected" : "Unselected");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GEVENT_GWIN_RADIO:
|
case GEVENT_GWIN_RADIO:
|
||||||
|
@ -79,12 +79,13 @@ extern "C" {
|
|||||||
*
|
*
|
||||||
* @param[in] widget The GListObject structure to initialize. If this is NULL, the structure is dynamically allocated.
|
* @param[in] widget The GListObject structure to initialize. If this is NULL, the structure is dynamically allocated.
|
||||||
* @param[in] pInit The initialization parameters to use
|
* @param[in] pInit The initialization parameters to use
|
||||||
|
* @param[in] multiselect If TRUE the list is multi-select instead of single-select.
|
||||||
*
|
*
|
||||||
* @return NULL if there is no resulting drawing area, otherwise a window handle.
|
* @return NULL if there is no resulting drawing area, otherwise a window handle.
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
GHandle gwinListCreate(GListObject *widget, GWidgetInit *pInit);
|
GHandle gwinListCreate(GListObject *widget, GWidgetInit *pInit, bool_t multiselect);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add an item to the list
|
* @brief Add an item to the list
|
||||||
|
@ -172,11 +172,18 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for(qi = gfxQueueASyncPeek(&gw2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
for(qi = gfxQueueASyncPeek(&gw2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
|
if ((gw->g.flags & GLIST_FLG_MULTISELECT)) {
|
||||||
|
if (item == i) {
|
||||||
|
qi2li->flags ^= GLIST_FLG_SELECTED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (item == i)
|
if (item == i)
|
||||||
qi2li->flags |= GLIST_FLG_SELECTED;
|
qi2li->flags |= GLIST_FLG_SELECTED;
|
||||||
else
|
else
|
||||||
qi2li->flags &=~ GLIST_FLG_SELECTED;
|
qi2li->flags &=~ GLIST_FLG_SELECTED;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_gwidgetRedraw(&gw->g);
|
_gwidgetRedraw(&gw->g);
|
||||||
sendListEvent(gw, item);
|
sendListEvent(gw, item);
|
||||||
@ -281,7 +288,7 @@ static const gwidgetVMT listVMT = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
GHandle gwinListCreate(GListObject* gobj, GWidgetInit* pInit) {
|
GHandle gwinListCreate(GListObject* gobj, GWidgetInit* pInit, bool_t multiselect) {
|
||||||
if (!(gobj = (GListObject *)_gwidgetCreate(&gobj->w, pInit, &listVMT)))
|
if (!(gobj = (GListObject *)_gwidgetCreate(&gobj->w, pInit, &listVMT)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -289,6 +296,8 @@ GHandle gwinListCreate(GListObject* gobj, GWidgetInit* pInit) {
|
|||||||
gfxQueueASyncInit(&gobj->list_head);
|
gfxQueueASyncInit(&gobj->list_head);
|
||||||
gobj->cnt = 0;
|
gobj->cnt = 0;
|
||||||
gobj->top = 0;
|
gobj->top = 0;
|
||||||
|
if (multiselect)
|
||||||
|
gobj->w.g.flags |= GLIST_FLG_MULTISELECT;
|
||||||
|
|
||||||
gwinSetVisible(&gobj->w.g, pInit->g.show);
|
gwinSetVisible(&gobj->w.g, pInit->g.show);
|
||||||
|
|
||||||
@ -315,7 +324,7 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) {
|
|||||||
newItem->text = item_name;
|
newItem->text = item_name;
|
||||||
|
|
||||||
// select the item if it's the first in the list
|
// select the item if it's the first in the list
|
||||||
if (gh2obj->cnt == 0)
|
if (gh2obj->cnt == 0 && !(gh->flags & GLIST_FLG_MULTISELECT))
|
||||||
newItem->flags |= GLIST_FLG_SELECTED;
|
newItem->flags |= GLIST_FLG_SELECTED;
|
||||||
|
|
||||||
// add the new item to the list
|
// add the new item to the list
|
||||||
@ -377,6 +386,10 @@ int gwinListGetSelected(GHandle gh) {
|
|||||||
if (gh->vmt != (gwinVMT *)&listVMT)
|
if (gh->vmt != (gwinVMT *)&listVMT)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
// Multi-select always returns -1. Use gwinListItemIsSelected() instead
|
||||||
|
if ((gh->flags & GLIST_FLG_MULTISELECT))
|
||||||
|
return -1;
|
||||||
|
|
||||||
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) {
|
||||||
if (qi2li->flags & GLIST_FLG_SELECTED)
|
if (qi2li->flags & GLIST_FLG_SELECTED)
|
||||||
return i;
|
return i;
|
||||||
|
Loading…
Reference in New Issue
Block a user